Exemple #1
0
int main()
{
    int itranfrm[3];
    int index_file,index_base,nzone,index_zone,n1to1,index_conn;
    char donorname[33],connectname[33];
    cgsize_t ipnts[2][3],ipntsdonor[2][3];

/* READ 1-TO-1 CONNECTIVITY INFORMATION FROM EXISTING CGNS FILE */
/* open CGNS file for read-only */
    if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* get number of zones (should be 2 for our case) */
    cg_nzones(index_file,index_base,&nzone);
    if (nzone != 2)
    {
      printf("\nError. This program expects 2 zones. %d read.\n",nzone);
      return 1;
    }
/* loop over zones */
    for (index_zone=1; index_zone <= nzone; ++index_zone)
    {
/* find out how many 1-to-1 interfaces there are in this zone */
/* (for this program, there should only be one) */
      cg_n1to1(index_file,index_base,index_zone,&n1to1);
      if (n1to1 != 1)
      {
        printf("\nError.  Expecting one 1-to-1 interface. %i read\n",n1to1);
        return 1;
      }
      index_conn=n1to1;
/* read 1-to-1 info */
      cg_1to1_read(index_file,index_base,index_zone,index_conn,connectname,donorname,
                   ipnts[0],ipntsdonor[0],itranfrm);
      printf("\nIn zone %i:\n",index_zone);
      printf("   donor name=%s\n",donorname);
      printf("   range (this zone)=%i,%i,%i,%i,%i,%i\n",(int)ipnts[0][0],
              (int)ipnts[0][1],(int)ipnts[0][2],(int)ipnts[1][0],
              (int)ipnts[1][1],(int)ipnts[1][2]);
      printf("   range (donor zone)=%i,%i,%i,%i,%i,%i\n",(int)ipntsdonor[0][0],
              (int)ipntsdonor[0][1],(int)ipntsdonor[0][2],(int)ipntsdonor[1][0],
              (int)ipntsdonor[1][1],(int)ipntsdonor[1][2]);
      printf("   transform=%i,%i,%i\n",itranfrm[0],itranfrm[1],itranfrm[2]);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully read 1-to-1 connectivity info from file grid_c.cgns\n");
    return 0;
}
int main()
{
    int ilo[2],ihi[2],jlo[2],jhi[2],klo[2],khi[2];
    int icount,j,k;
    int index_file,index_base,nzone,index_zone,nconns,n1to1,index_conn,iz;
    char donorname[33],zonename0[33],zonename1[33],zn[33];
    cgsize_t isize[3][3],ipnts[maxcount][3],ipntsdonor[maxcount][3];

/* WRITE GENERAL CONNECTIVITY INFORMATION TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* get number of zones (should be 2 for our case) */
    cg_nzones(index_file,index_base,&nzone);
    if (nzone != 2)
    {
      printf("\nError. This program expects 2 zones. %d read.\n",nzone);
      return 1;
    }

/* loop over zones to get zone sizes and names */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
      cg_zone_read(index_file,index_base,iz,zn,isize[0]);
      if (index_zone == 0)
      {
        strcpy(zonename0,zn);
      }
      else
      {
        strcpy(zonename1,zn);
      }
      ilo[index_zone]=1;
      ihi[index_zone]=isize[0][0];
      jlo[index_zone]=1;
      jhi[index_zone]=isize[0][1];
      klo[index_zone]=1;
      khi[index_zone]=isize[0][2];
    }
/* loop over zones again */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
/* for this program, there should be no existing connectivity info: */
      cg_nconns(index_file,index_base,iz,&nconns);
      if (nconns != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",nconns);
        return 1;
      }
      cg_n1to1(index_file,index_base,iz,&n1to1);
      if (n1to1 != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",n1to1);
        return 1;
      }
/* set up point lists */
      if (index_zone == 0)
      {
        strcpy(donorname,zonename1);
        icount=0;
        for (j=jlo[index_zone]; j <= jhi[index_zone]; j++)
        {
          for (k=klo[index_zone]; k <= khi[index_zone]; k++)
          {
            ipnts[icount][0]=ihi[0];
            ipnts[icount][1]=j;
            ipnts[icount][2]=k;
            ipntsdonor[icount][0]=ilo[1];
            ipntsdonor[icount][1]=j;
            ipntsdonor[icount][2]=k;
            icount=icount+1;
          }
        }
        if (icount > maxcount)
        {
          printf("\nError. Need to increase maxcount to at least %i\n",icount);
          return 1;
        }
      }
      else
      {
        strcpy(donorname,zonename0);
        icount=0;
        for (j=jlo[index_zone]; j <= jhi[index_zone]; j++)
        {
          for (k=klo[index_zone]; k <= khi[index_zone]; k++)
          {
            ipnts[icount][0]=ilo[1];
            ipnts[icount][1]=j;
            ipnts[icount][2]=k;
            ipntsdonor[icount][0]=ihi[0];
            ipntsdonor[icount][1]=j;
            ipntsdonor[icount][2]=k;
            icount=icount+1;
          }
        }
        if (icount > maxcount)
        {
          printf("\nError. Need to increase maxcount to at least %i\n",icount);
          return 1;
        }
      }
/* write integer connectivity info (user can give any name) */
      cg_conn_write(index_file,index_base,iz,"GenInterface",Vertex,Abutting1to1,
          PointList,icount,ipnts[0],donorname,Structured,
          PointListDonor,Integer,icount,ipntsdonor[0],&index_conn);
    }
/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added 1-to-1 connectivity info to file grid_c.cgns (using GENERAL method)\n"); 
    return 0;
}
Exemple #3
0
int main()
{
    int ilo[2],ihi[2],jlo[2],jhi[2],klo[2],khi[2];
    int itranfrm[3];
    int index_file,index_base,nzone,index_zone,nconns,n1to1,index_conn,iz;
    char donorname[33],zonename0[33],zonename1[33],zn[33];
    cgsize_t isize[3][3],ipnts[2][3],ipntsdonor[2][3];

    printf("\nProgram write_con2zn_str\n");

/* WRITE 1-TO-1 CONNECTIVITY INFORMATION TO EXISTING CGNS FILE */
/* open CGNS file for modify */
    if (cg_open("grid_c.cgns",CG_MODE_MODIFY,&index_file)) cg_error_exit();
/* we know there is only one base (real working code would check!) */
    index_base=1;
/* get number of zones (should be 2 for our case) */
    cg_nzones(index_file,index_base,&nzone);
    if (nzone != 2)
    {
      printf("\nError. This program expects 2 zones. %d read.\n",nzone);
      return 1;
    }

/* loop over zones to get zone sizes and names */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
      cg_zone_read(index_file,index_base,iz,zn,isize[0]);
      if (index_zone == 0)
      {
        strcpy(zonename0,zn);
      }
      else
      {
        strcpy(zonename1,zn);
      }
      ilo[index_zone]=1;
      ihi[index_zone]=isize[0][0];
      jlo[index_zone]=1;
      jhi[index_zone]=isize[0][1];
      klo[index_zone]=1;
      khi[index_zone]=isize[0][2];
    }
/* loop over zones again */
    for (index_zone=0; index_zone < nzone; ++index_zone)
    {
      iz=index_zone+1;
/* for this program, there should be no existing connectivity info: */
      cg_nconns(index_file,index_base,iz,&nconns);
      if (nconns != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",nconns);
        return 1;
      }
      cg_n1to1(index_file,index_base,iz,&n1to1);
      if (n1to1 != 0)
      {
        printf("\nError. This program expects no interfaces yet. %d read.\n",n1to1);
        return 1;
      }
/* set up index ranges */
      if (index_zone == 0)
      {
        strcpy(donorname,zonename1);
/* lower point of receiver range */
        ipnts[0][0]=ihi[0];
        ipnts[0][1]=jlo[0];
        ipnts[0][2]=klo[0];
/* upper point of receiver range */
        ipnts[1][0]=ihi[0];
        ipnts[1][1]=jhi[0];
        ipnts[1][2]=khi[0];
/* lower point of donor range */
        ipntsdonor[0][0]=ilo[1];
        ipntsdonor[0][1]=jlo[1];
        ipntsdonor[0][2]=klo[1];
/* upper point of donor range */
        ipntsdonor[1][0]=ilo[1];
        ipntsdonor[1][1]=jhi[1];
        ipntsdonor[1][2]=khi[1];
      }
      else
      {
        strcpy(donorname,zonename0);
/* lower point of receiver range */
        ipnts[0][0]=ilo[1];
        ipnts[0][1]=jlo[1];
        ipnts[0][2]=klo[1];
/* upper point of receiver range */
        ipnts[1][0]=ilo[1];
        ipnts[1][1]=jhi[1];
        ipnts[1][2]=khi[1];
/* lower point of donor range */
        ipntsdonor[0][0]=ihi[0];
        ipntsdonor[0][1]=jlo[0];
        ipntsdonor[0][2]=klo[0];
/* upper point of donor range */
        ipntsdonor[1][0]=ihi[0];
        ipntsdonor[1][1]=jhi[0];
        ipntsdonor[1][2]=khi[0];
      }

/* set up Transform */
      itranfrm[0]=1;
      itranfrm[1]=2;
      itranfrm[2]=3;
/* write 1-to-1 info (user can give any name) */
      cg_1to1_write(index_file,index_base,iz,"Interface",donorname,
          ipnts[0],ipntsdonor[0],itranfrm,&index_conn);
    }

/* close CGNS file */
    cg_close(index_file);
    printf("\nSuccessfully added 1-to-1 connectivity info to file grid_c.cgns\n");
    return 0;
}