// read number of particles from cgns file int cgns_read_nparts(void) { // Open cgns file and get cgns file index number fn char buf[FILE_NAME_SIZE]; sprintf(buf, "%s/%s/%s", SIM_ROOT_DIR, OUTPUT_DIR, partFiles[partFileMap[0]]); int fn; int ier = cg_open(buf, CG_MODE_READ, &fn); if (ier != 0 ) { printf("\nCGNS Error on file %s\n", buf); cg_error_exit(); } fflush(stdout); // Set base index nuber and zone index number (only one, so is 1) int bn = 1; int zn = 1; // Read zone to find cgsize_t *size, or nparts char zonename[FILE_NAME_SIZE] = ""; cgsize_t nparts = 0; ier = cg_zone_read(fn, bn, zn, zonename, &nparts); if (ier != 0 ) { printf("\nCGNS Error on file %s\n", buf); cg_error_exit(); } fflush(stdout); cg_close(fn); return nparts; }
void read_cgnsFlow(double *flowFileTime, int flowCount) { char fname[FILE_NAME_SIZE] = ""; int fn; int nbases; int B = 1; char Bn[FILE_NAME_SIZE] = "Base"; int cell_dim = 3; int phys_dim = 3; int Z = 1; char Zn[FILE_NAME_SIZE] = "Zone0"; int size; int S = 1; char Sn[FILE_NAME_SIZE] = "Solution"; // Loop over each file for (int ff = 0; ff < flowCount; ff++) { printf(fname, "%s/output/flow-%d.cgns", flowFileTime[ff]); cg_open(fname, CG_MODE_READ, &fn); // open file for reading //cg_nbases(fn, &nbases); // get number of bases (should be 1) //cg_base_read(fn, B, basename, cell_dim, phys_dim); // rea cg_zone_read(fn, B, Z, &Zn, &size); // size[0] = NVertexI; size[1] = NVertexJ; size[2] = NVertexK // size[3] = NCellI; size[4] = NCellJ; size[5] = NCellK // size[6]=NBoundVertexI; size[7]=NBoundVertexJ; size[8]=NBoundVertexK = 0 cg_field_read(fn, B, Z, S, "VelocityX", RealDouble, 0, NCellI?, solnarray); } }
// Read part_struct data void cgns_fill_parts(void) { // Open cgns file and get cgns file index number fn char buf[FILE_NAME_SIZE]; sprintf(buf, "%s/%s/%s", SIM_ROOT_DIR, OUTPUT_DIR, partFiles[partFileMap[tt]]); int fn; int ier = cg_open(buf, CG_MODE_READ, &fn); if (ier != 0 ) { printf("\nCGNS Error on file %s\n", buf); free_vars(); cg_close(fn); cg_error_exit(); } fflush(stdout); // Set base, zone, and solutions index numbers int bn = 1; int zn = 1; int sn = 1; // Read part coords double *x = malloc(nparts * sizeof(double)); double *y = malloc(nparts * sizeof(double)); double *z = malloc(nparts * sizeof(double)); for (int p = 0; p < nparts; p++) { x[p] = 0; y[p] = 0; z[p] = 0; } cgsize_t range_min = 1; cgsize_t range_max = nparts; cg_coord_read(fn,bn,zn, "CoordinateX", RealDouble, &range_min, &range_max, x); cg_coord_read(fn,bn,zn, "CoordinateY", RealDouble, &range_min, &range_max, y); cg_coord_read(fn,bn,zn, "CoordinateZ", RealDouble, &range_min, &range_max, z); for (int p = 0; p < nparts; p++) { parts[p].x = x[p]; parts[p].y = y[p]; parts[p].z = z[p]; } // Read part vel cg_field_read(fn,bn,zn,sn, "VelocityX", RealDouble, &range_min, &range_max, up); cg_field_read(fn,bn,zn,sn, "VelocityY", RealDouble, &range_min, &range_max, vp); cg_field_read(fn,bn,zn,sn, "VelocityZ", RealDouble, &range_min, &range_max, wp); // Calculate kinetic energy for (int p = 0; p < nparts; p++) { ke[p] = 0.5*(up[p]*up[p] + vp[p]*vp[p] + wp[p]*wp[p]); //ke[p] = 0.5*wp[p]*wp[p]; } free(x); free(y); free(z); cg_close(fn); }
int main() { int index_file,index_base,ndescriptors,n; char *text,name[33]; /* READ DESCRIPTOR 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; /* go to base node */ cg_goto(index_file,index_base,"end"); /* find out how many descriptors are here: */ cg_ndescriptors(&ndescriptors); for (n=1; n <= ndescriptors; n++) { /* read descriptor */ cg_descriptor_read(n,name,&text); printf("\nThe descriptor is:\n\n%s\n",text); } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read descriptors from file grid_c.cgns\n"); return 0; }
int main() { /* dimension statements (note that tri-dimensional arrays r and p must be dimensioned exactly as [N-1][17-1][21-1] (N>=9) for this particular case or else they will be read from the CGNS file incorrectly! Other options are to use 1-D arrays, use dynamic memory, or pass index values to a subroutine and dimension exactly there): */ double r[8][16][20],p[8][16][20]; cgsize_t isize[3][3],irmin[3],irmax[3]; int index_file,index_base,index_zone,index_flow; char zonename[33],solname[33]; GridLocation_t loc; /* READ FLOW SOLUTION FROM 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* we know there is only one FlowSolution_t (real working code would check!) */ index_flow=1; /* get zone size (and name - although not needed here) */ cg_zone_read(index_file,index_base,index_zone,zonename,isize[0]); /* lower range index */ irmin[0]=1; irmin[1]=1; irmin[2]=1; /* upper range index - use cell dimensions */ /* checking GridLocation first (real working code would check */ /* to make sure there are no Rind cells also!): */ cg_sol_info(index_file,index_base,index_zone,index_flow,solname,&loc); if (loc != CellCenter) { printf("\nError, GridLocation must be CellCenter! Currently: %s\n", GridLocationName[loc]); return 1; } irmax[0]=isize[1][0]; irmax[1]=isize[1][1]; irmax[2]=isize[1][2]; /* read flow solution */ cg_field_read(index_file,index_base,index_zone,index_flow,"Density", \ RealDouble,irmin,irmax,r[0][0]); cg_field_read(index_file,index_base,index_zone,index_flow,"Pressure", \ RealDouble,irmin,irmax,p[0][0]); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read flow solution from file grid_c.cgns\n"); printf(" For example, r,p[7][15][19]= %f, %f\n",r[7][15][19],p[7][15][19]); printf("\nProgram successful... ending now\n"); return 0; }
int main() { int index_file,index_base,index_zone,nbocos,ib; int normalindex[3],ndataset; int i,normallist; char boconame[33]; BCType_t ibocotype; PointSetType_t iptset; DataType_t normaldatatype; cgsize_t npts,normallistflag; cgsize_t ipnts[maxpnts][3]; /* READ BOUNDARY CONDITIONS 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* find out number of BCs that exist under this zone */ cg_nbocos(index_file,index_base,index_zone,&nbocos); /* do loop over the total number of BCs */ for (ib=1; ib <= nbocos; ib++) { /* get BC info */ cg_boco_info(index_file,index_base,index_zone,ib,boconame,&ibocotype, &iptset,&npts,normalindex,&normallistflag,&normaldatatype,&ndataset); if (iptset != PointList) { printf("\nError. For this program, BCs must be set up as PointList type %s\n", PointSetTypeName[iptset]); return 1; } printf("\nBC number: %i\n",ib); printf(" name= %s\n",boconame); printf(" type= %s\n",BCTypeName[ibocotype]); printf(" no of pts= %i\n",(int)npts); if (npts > maxpnts) { printf("\nError. Must increase maxpnts to at least %i\n",(int)npts); return 1; } /* read point list in here (nothing done with them in this program) */ cg_boco_read(index_file,index_base,index_zone,ib,ipnts[0],&normallist); printf(" (these points read here, but only some printed out:)\n"); for (i=0; i < 10; i++) { printf(" ipnts[%i][0], [%i][1], [%i][2]=%i,%i,%i\n", i,i,i,(int)ipnts[i][0],(int)ipnts[i][1],(int)ipnts[i][2]); } } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read BCs (PointList format) from file grid_c.cgns\n"); return 0; }
static int do_cg_open(const char *path, struct fuse_file_info *fi) { int (*cg_open)(const char *path, struct fuse_file_info *fi); char *error; dlerror(); /* Clear any existing error */ cg_open = (int (*)(const char *, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_open"); error = dlerror(); if (error != NULL) { fprintf(stderr, "cg_open: %s\n", error); return -1; } return cg_open(path, fi); }
int main() { double r[9*17*21],p[9*17*21]; int ni,nj,nk,i,j,k,index_file,index_base,index_zone,index_flow,index_field,iset; char solname[33]; printf("\nProgram write_flowvert_unst\n"); /* create fake flow solution AT CELL CENTERS for simple example: */ ni=21; nj=17; nk=9; iset=0; for (k=0; k < nk; k++) { for (j=0; j < nj; j++) { for (i=0; i < ni; i++) { r[iset]=(float)i; p[iset]=(float)j; iset=iset+1; } } } printf("\ncreated simple 3-D rho and p flow solution\n"); /* WRITE FLOW SOLUTION 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* define flow solution node name (user can give any name) */ strcpy(solname,"FlowSolution"); /* create flow solution node */ cg_sol_write(index_file,index_base,index_zone,solname,Vertex,&index_flow); /* write flow solution (user must use SIDS-standard names here) */ cg_field_write(index_file,index_base,index_zone,index_flow, RealDouble,"Density",r,&index_field); cg_field_write(index_file,index_base,index_zone,index_flow, RealDouble,"Pressure",p,&index_field); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully added Vertex flow solution data to file grid_c.cgns (unstructured)\n"); printf("\nNote: if the original CGNS file already had a FlowSolution_t node,"); printf("\n it has been overwritten\n"); return 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() { double data; int index_file,index_base,narrays,n,idim; char *state,arrayname[33]; DataClass_t id; DataType_t idata; cgsize_t idimvec; /* READ NONDIMENSIONAL INFO */ /* 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; /* read DataClass under Base */ cg_goto(index_file,index_base,"end"); cg_dataclass_read(&id); printf("\nDataClass = %s\n",DataClassName[id]); if (id != NormalizedByUnknownDimensional) { printf("\nError! Expecting NormalizedByUnknownDimensional\n"); return 1; } /* read ReferenceState under Base */ cg_state_read(&state); printf("\nReferenceState = %s\n",state); /* Go to ReferenceState node, read Mach array and its dataclass */ cg_goto(index_file,index_base,"ReferenceState_t",1,"end"); /* find out how many data arrays */ cg_narrays(&narrays); for (n=1; n <= narrays; n++) { cg_array_info(n,arrayname,&idata,&idim,&idimvec); if (idim != 1 || idimvec != 1) { printf("\nError! expecting idim,idimvec=1,1\n"); printf(" they are idim,idimvec= %i, %i\n",idim,(int)idimvec); return 1; } cg_array_read_as(n,RealDouble,&data); printf("Variable=%s\n",arrayname); printf(" data=%18.8f\n",data); } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read nondimensional info from file grid_c.cgns\n"); return 0; }
void file::open( const string& fname, openmode_t rw ) { if ( _valid ) close( "file::open" ); _openmode = rw; int m; switch( _openmode ) { case READONLY : m = MODE_READ; break; case READWRITE: m = MODE_MODIFY; break; case WRITE : m = MODE_WRITE; break; } int ier = cg_open( const_cast<char*>(fname.c_str()), m, &_fileindex ); check_error( "file::open", "cg_open", ier ); _valid = (ier==0); }
int main() { float cl[ntt]; int index_file,index_base,narrays,index_array,ndim; char arrayname[33]; DataType_t itype; cgsize_t idim; /* READ CONVERGENCE HISTORY 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; /* go to base node */ cg_goto(index_file,index_base,"end"); /* go to history node (we assume it exists and that there is only one - */ /* real working code would check!) */ cg_goto(index_file,index_base,"ConvergenceHistory_t",1,"end"); /* find out how many arrays are here (there should be only one!): */ cg_narrays(&narrays); index_array=narrays; /* some checks: */ if (narrays != 1) { printf("\nError! Expecting only one array, read %i\n",narrays); return 1; } cg_array_info(index_array,arrayname,&itype,&ndim,&idim); if (idim > ntt) { printf("\nError! must increase ntt to at least %i\n",(int)idim); return 1; } if (strcmp(arrayname,"CoefLift") != 0) { printf("\nError! expecting CoefLift, read %s\n",arrayname); return 1; } /* read lift coefficient array */ cg_array_read_as(index_array,RealSingle,cl); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read cl history from file grid_c.cgns\n"); printf(" values are: %f, %f, %f, %f, %f\n",cl[0],cl[1],cl[2],cl[3],cl[4]); printf(" %f, %f, %f, %f, %f\n",cl[5],cl[6],cl[7],cl[8],cl[9]); return 0; }
int main() { float r[9*17*21],p[9*17*21]; cgsize_t isize[3][1],irmin,irmax; int index_file,index_base,index_zone,index_flow; char zonename[33],solname[33]; GridLocation_t loc; /* READ FLOW SOLUTION FROM 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* we know there is only one FlowSolution_t (real working code would check!) */ index_flow=1; /* get zone size (and name - although not needed here) */ cg_zone_read(index_file,index_base,index_zone,zonename,isize[0]); /* lower range index */ irmin=1; /* upper range index - use vertex dimensions */ /* checking GridLocation first (real working code would check */ /* to make sure there are no Rind cells also!): */ cg_sol_info(index_file,index_base,index_zone,index_flow,solname,&loc); if (loc != Vertex) { printf("\nError, GridLocation must be Vertex! Currently: %s\n", GridLocationName[loc]); return 1; } irmax=isize[0][0]; /* read flow solution */ cg_field_read(index_file,index_base,index_zone,index_flow,"Density", \ RealSingle,&irmin,&irmax,r); cg_field_read(index_file,index_base,index_zone,index_flow,"Pressure", \ RealSingle,&irmin,&irmax,p); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read flow solution from file grid_c.cgns\n"); printf(" For example, r,p[379] = %f, %f\n",r[379],p[379]); printf(" r,p[3212]= %f, %f\n",r[3212],p[3212]); printf("\nProgram successful... ending now\n"); return 0; }
void read_cgnsPart(double *partFileTime, int partCount) { char fname[FILE_NAME_SIZE] = ""; int fn; int nbases; int B = 1; char basename[FILE_NAME_SIZE] = "Base"; int cell_dim = 3; int phys_dim = 3; int Z = 1; // Loop over each file for (int ff = 0; ff < partCount; ff++) { printf(fname, "%s/output/part-%d.cgns", partFileTime[ff]); cg_open(fname, CG_MODE_READ, &fn); // open file for reading //cg_nbases(fn, &nbases); // get number of bases (should be 1) //cg_base_read(fn, B, basename, cell_dim, phys_dim); // rea } }
// read number of particles from cgns file int cgns_read_nparts(void) { // Open cgns file and get cgns file index number fn char buf[FILE_NAME_SIZE]; sprintf(buf, "%s/%s/%s", ROOT_DIR, OUTPUT_DIR, partFiles[fileMap[0]]); int fn; cg_open(buf, CG_MODE_READ, &fn); // Set base index nuber and zone index number (only one, so is 1) int bn = 1; int zn = 1; // Read zone to find cgsize_t *size, or nparts char zonename[FILE_NAME_SIZE] = ""; cgsize_t nparts = 0; cg_zone_read(fn, bn, zn, zonename, &nparts); cg_close(fn); return nparts; }
// Read data void cgns_fill_input(void) { // Open cgns file and get cgns file index number fn char buf[FILE_NAME_SIZE]; sprintf(buf, "%s/data/%s", ANALYSIS_DIR, files[fileMap[tt]]); int fn; int ier = cg_open(buf, CG_MODE_READ, &fn); if (ier != 0 ) { printf("CGNS Error - double check grid.cgns exists in output\n"); cg_error_exit(); } fflush(stdout); // Set base, zone, and solutions index numbers int bn = 1; int zn = 1; int sn = 1; // Size of array to pull cgsize_t range_min[3]; range_min[0] = 1; range_min[1] = 1; range_min[2] = 1; cgsize_t range_max[3]; range_max[0] = dom.xn; range_max[1] = dom.yn; range_max[2] = dom.zn; // Read and fill cg_field_read(fn,bn,zn,sn, "Volume Fraction Real", RealDouble, range_min, range_max, volume_fraction); cg_close(fn); // Zero the averages for (int i = 0; i < dom.Gcc.s2; i++) { moving_avg[i] = 0.; stationary_avg[i] = 0.; } }
/*@C DMPlexCreateCGNS - Create a DMPlex mesh from a CGNS file. Collective on comm Input Parameters: + comm - The MPI communicator . filename - The name of the CGNS file - interpolate - Create faces and edges in the mesh Output Parameter: . dm - The DM object representing the mesh Note: http://www.grc.nasa.gov/WWW/cgns/CGNS_docs_current/index.html Level: beginner .keywords: mesh,CGNS .seealso: DMPlexCreate(), DMPlexCreateCGNS(), DMPlexCreateExodus() @*/ PetscErrorCode DMPlexCreateCGNSFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm) { PetscMPIInt rank; PetscErrorCode ierr; #if defined(PETSC_HAVE_CGNS) int cgid = -1; #endif PetscFunctionBegin; PetscValidCharPointer(filename, 2); ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); #if defined(PETSC_HAVE_CGNS) if (!rank) { ierr = cg_open(filename, CG_MODE_READ, &cgid);CHKERRQ(ierr); if (cgid <= 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "cg_open(\"%s\",...) did not return a valid file ID", filename); } ierr = DMPlexCreateCGNS(comm, cgid, interpolate, dm);CHKERRQ(ierr); if (!rank) {ierr = cg_close(cgid);CHKERRQ(ierr);} #else SETERRQ(comm, PETSC_ERR_SUP, "Loading meshes requires CGNS support. Reconfigure using --with-cgns-dir"); #endif PetscFunctionReturn(0); }
int main() { int i,index_file,index_base,nzone,index_zone,nconns,index_conn; char donorname[33],connectname[33]; GridLocation_t location; GridConnectivityType_t iconnect_type; PointSetType_t iptset_type,idonor_ptset_type; ZoneType_t idonor_zonetype; DataType_t idonor_datatype; cgsize_t npts,ndata_donor; cgsize_t ipnts[maxpnts][3],ipntsdonor[maxpnts][3]; /* READ GENERAL 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 general interfaces there are in this zone */ /* (for this program, there should only be one) */ cg_nconns(index_file,index_base,index_zone,&nconns); if (nconns != 1) { printf("\nError. Expecting one general interface. %i read\n",nconns); return 1; } index_conn=nconns; /* read general connectivity info */ cg_conn_info(index_file,index_base,index_zone,index_conn,connectname,&location, &iconnect_type,&iptset_type,&npts,donorname,&idonor_zonetype, &idonor_ptset_type,&idonor_datatype,&ndata_donor); if (npts > maxpnts) { printf("\nError. Must increase maxpnts to at least %i\n",(int)npts); return 1; } cg_conn_read(index_file,index_base,index_zone,index_conn,ipnts[0], idonor_datatype,ipntsdonor[0]); printf("\nIn zone %i:\n",index_zone); printf(" donor name=%s\n",donorname); printf(" number of connectivity pts=%i\n",(int)npts); printf(" grid location=%s\n",GridLocationName[location]); printf(" connectivity type=%s\n",GridConnectivityTypeName[iconnect_type]); printf(" pointset type=%s\n",PointSetTypeName[iptset_type]); printf(" donor zonetype=%s\n",ZoneTypeName[idonor_zonetype]); printf(" donor pointset type=%s\n",PointSetTypeName[idonor_ptset_type]); printf(" data type=%s\n",DataTypeName[idonor_datatype]); printf(" ipnts and ipntsdonor arrays read, only some written out here:\n"); for (i=0; i < 10; i++) { printf(" ipnts[%i][0], [%i][1], [%i][2]=%i,%i,%i", i,i,i,(int)ipnts[i][0],(int)ipnts[i][1],(int)ipnts[i][2]); printf(" ipntsdonor[%i][0], [%i][1], [%i][2]=%i,%i,%i\n", i,i,i,(int)ipntsdonor[i][0],(int)ipntsdonor[i][1],(int)ipntsdonor[i][2]); } } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read general 1-to-1 connectivity info from file grid_c.cgns\n"); return 0; }
int main() { int index_file,index_base,index_zone; int nelem_start,nelem_end,icount,index_bc,ibc,n; cgsize_t ipnts[maxcount]; /* WRITE BOUNDARY CONDITIONS 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* we know that for the unstructured zone, the following face elements */ /* have been defined as inflow (real working code would check!): */ nelem_start=2561; nelem_end=2688; icount=0; for (n=nelem_start; n <= nelem_end; n++) { ipnts[icount]=n; icount=icount+1; } if (icount > maxcount) { printf("\nError. Need to increase maxcount to at least %i\n",icount); return 1; } /* write boundary conditions for ilo face */ cg_boco_write(index_file,index_base,index_zone,"Ilo",BCTunnelInflow, PointList,icount,ipnts,&index_bc); /* we know that for the unstructured zone, the following face elements */ /* have been defined as outflow (real working code would check!): */ nelem_start=2689; nelem_end=2816; icount=0; for (n=nelem_start; n <= nelem_end; n++) { ipnts[icount]=n; icount=icount+1; } if (icount > maxcount) { printf("\nError. Need to increase maxcount to at least %i\n",icount); return 1; } /* write boundary conditions for ihi face */ cg_boco_write(index_file,index_base,index_zone,"Ihi",BCExtrapolate, PointList,icount,ipnts,&index_bc); /* we know that for the unstructured zone, the following face elements */ /* have been defined as walls (real working code would check!): */ nelem_start=2817; nelem_end=3776; icount=0; for (n=nelem_start; n <= nelem_end; n++) { ipnts[icount]=n; icount=icount+1; } if (icount > maxcount) { printf("\nError. Need to increase maxcount to at least %i\n",icount); return 1; } /* write boundary conditions for wall faces */ cg_boco_write(index_file,index_base,index_zone,"Walls",BCWallInviscid, PointList,icount,ipnts,&index_bc); /* the above are all face-center locations for the BCs - must indicate this, */ /* otherwise Vertices will be assumed! */ for (ibc=1; ibc <= index_bc; ibc++) { /* (the following call positions you in BC_t - it assumes there */ /* is only one Zone_t and one ZoneBC_t - real working code would check!) */ cg_goto(index_file,index_base,"Zone_t",1,"ZoneBC_t",1,"BC_t",ibc,"end"); cg_gridlocation_write(FaceCenter); } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully added FaceCenter BCs (PointList) to unstructured grid file grid_c.cgns\n"); return 0; }
int main (int argc, char *argv[]) { int j, n; cgsize_t ne; int fnum, bnum, znum, snum, cnum; cgsize_t size[3]; float exp[5]; char *outfile = "elemtest.cgns"; unlink (outfile); if (cg_open (outfile, CG_MODE_WRITE, &fnum) || cg_base_write (fnum, "Base", 3, 3, &bnum) || cg_goto(fnum, bnum, NULL) || cg_dataclass_write(CGNS_ENUMV(NormalizedByDimensional))) cg_error_exit (); for (n = 0; n < 5; n++) exp[n] = (float)0.0; exp[1] = (float)1.0; /* zone with linear elements */ size[0] = 11; size[1] = 12; size[2] = 0; if (cg_zone_write (fnum, bnum, "1:Linear", size, CGNS_ENUMV(Unstructured), &znum) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateX", xc, &cnum) || cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0, "CoordinateX", 0, NULL) || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateY", yc, &cnum) || cg_gopath(fnum, "../CoordinateY") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateZ", zc, &cnum) || cg_gopath(fnum, "../CoordinateZ") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp)) cg_error_exit (); ne = j = 0; /* NGON_n first so polyhedra face references are correct */ if (cg_section_write (fnum, bnum, znum, "NGON_n", CGNS_ENUMV(NGON_n), ne+1, ne+npoly, 0, poly, &snum)) cg_error_exit(); ne += npoly; /* NODE */ if (cg_section_write (fnum, bnum, znum, "NODE", CGNS_ENUMV(NODE), ne+1, ne+1, 0, node, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(NODE); elems[j++] = node[0]; /* BAR_2 */ if (cg_section_write (fnum, bnum, znum, "BAR_2", CGNS_ENUMV(BAR_2), ne+1, ne+1, 0, bar, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(BAR_2); for (n = 0; n < 2; n++) elems[j++] = bar[n]; /* TRI_3 */ if (cg_section_write (fnum, bnum, znum, "TRI_3", CGNS_ENUMV(TRI_3), ne+1, ne+1, 0, tri, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TRI_3); for (n = 0; n < 3; n++) elems[j++] = tri[n]; /* QUAD_4 */ if (cg_section_write (fnum, bnum, znum, "QUAD_4", CGNS_ENUMV(QUAD_4), ne+1, ne+1, 0, quad9, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(QUAD_4); for (n = 0; n < 4; n++) elems[j++] = quad9[n]; /* TETRA_4 */ if (cg_section_write (fnum, bnum, znum, "TETRA_4", CGNS_ENUMV(TETRA_4), ne+1, ne+1, 0, tetra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TETRA_4); for (n = 0; n < 4; n++) elems[j++] = tetra[n]; /* PYRA_5 */ if (cg_section_write (fnum, bnum, znum, "PYRA_5", CGNS_ENUMV(PYRA_5), ne+1, ne+1, 0, pyra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PYRA_5); for (n = 0; n < 5; n++) elems[j++] = pyra[n]; /* PENTA_6 */ if (cg_section_write (fnum, bnum, znum, "PENTA_6", CGNS_ENUMV(PENTA_6), ne+1, ne+1, 0, penta, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PENTA_6); for (n = 0; n < 6; n++) elems[j++] = penta[n]; /* HEXA_8 */ if (cg_section_write (fnum, bnum, znum, "HEXA_8", CGNS_ENUMV(HEXA_8), ne+1, ne+1, 0, hexa, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(HEXA_8); for (n = 0; n < 8; n++) elems[j++] = hexa[n]; /* MIXED */ if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED), ne+1, ne+8, 0, elems, &snum)) cg_error_exit (); ne += 8; /* NFACE_n */ if (cg_section_write (fnum, bnum, znum, "NFACE_n", CGNS_ENUMV(NFACE_n), ne+1, ne+nface, 0, face, &snum)) cg_error_exit (); /* zone with quadratic elements */ size[0] = 42; size[1] = 8; size[2] = 0; if (cg_zone_write (fnum, bnum, "2:Quadratic", size, CGNS_ENUMV(Unstructured), &znum) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateX", xc, &cnum) || cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0, "CoordinateX", 0, NULL) || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateY", yc, &cnum) || cg_gopath(fnum, "../CoordinateY") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateZ", zc, &cnum) || cg_gopath(fnum, "../CoordinateZ") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp)) cg_error_exit (); ne = j = 0; /* BAR_3 */ if (cg_section_write (fnum, bnum, znum, "BAR_3", CGNS_ENUMV(BAR_3), ne+1, ne+1, 0, bar, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(BAR_3); for (n = 0; n < 3; n++) elems[j++] = bar[n]; /* TRI_6 */ if (cg_section_write (fnum, bnum, znum, "TRI_6", CGNS_ENUMV(TRI_6), ne+1, ne+1, 0, tri, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TRI_6); for (n = 0; n < 6; n++) elems[j++] = tri[n]; /* QUAD_8 */ if (cg_section_write (fnum, bnum, znum, "QUAD_8", CGNS_ENUMV(QUAD_8), ne+1, ne+1, 0, quad9, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(QUAD_8); for (n = 0; n < 8; n++) elems[j++] = quad9[n]; /* TETRA_10 */ if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10), ne+1, ne+1, 0, tetra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TETRA_10); for (n = 0; n < 10; n++) elems[j++] = tetra[n]; /* PYRA_13 */ if (cg_section_write (fnum, bnum, znum, "PYRA_13", CGNS_ENUMV(PYRA_13), ne+1, ne+1, 0, pyra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PYRA_13); for (n = 0; n < 13; n++) elems[j++] = pyra[n]; /* PENTA_15 */ if (cg_section_write (fnum, bnum, znum, "PENTA_15", CGNS_ENUMV(PENTA_15), ne+1, ne+1, 0, penta, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PENTA_15); for (n = 0; n < 15; n++) elems[j++] = penta[n]; /* HEXA_20 */ if (cg_section_write (fnum, bnum, znum, "HEXA_20", CGNS_ENUMV(HEXA_20), ne+1, ne+1, 0, hexa, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(HEXA_20); for (n = 0; n < 20; n++) elems[j++] = hexa[n]; /* MIXED */ if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED), ne+1, ne+7, 0, elems, &snum)) cg_error_exit (); ne += 7; /* zone with quadratic elements with mid-nodes */ size[0] = 42; size[1] = 8; size[2] = 0; if (cg_zone_write (fnum, bnum, "3:Quadratic with mid-nodes", size, CGNS_ENUMV(Unstructured), &znum) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateX", xc, &cnum) || cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0, "CoordinateX", 0, NULL) || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateY", yc, &cnum) || cg_gopath(fnum, "../CoordinateY") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateZ", zc, &cnum) || cg_gopath(fnum, "../CoordinateZ") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp)) cg_error_exit (); ne = j = 0; /* QUAD_9 */ if (cg_section_write (fnum, bnum, znum, "QUAD_9", CGNS_ENUMV(QUAD_9), ne+1, ne+1, 0, quad9, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(QUAD_9); for (n = 0; n < 9; n++) elems[j++] = quad9[n]; /* TETRA_10 */ if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10), ne+1, ne+1, 0, tetra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TETRA_10); for (n = 0; n < 10; n++) elems[j++] = tetra[n]; /* PYRA_14 */ if (cg_section_write (fnum, bnum, znum, "PYRA_14", CGNS_ENUMV(PYRA_14), ne+1, ne+1, 0, pyra, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PYRA_14); for (n = 0; n < 14; n++) elems[j++] = pyra[n]; /* PENTA_18 */ if (cg_section_write (fnum, bnum, znum, "PENTA_18", CGNS_ENUMV(PENTA_18), ne+1, ne+1, 0, penta, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PENTA_18); for (n = 0; n < 18; n++) elems[j++] = penta[n]; /* HEXA_27 */ if (cg_section_write (fnum, bnum, znum, "HEXA_27", CGNS_ENUMV(HEXA_27), ne+1, ne+1, 0, hexa, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(HEXA_27); for (n = 0; n < 27; n++) elems[j++] = hexa[n]; /* MIXED */ if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED), ne+1, ne+5, 0, elems, &snum)) cg_error_exit (); ne += 5; /* zone with cubic elements */ size[0] = 55; size[1] = 8; size[2] = 0; if (cg_zone_write (fnum, bnum, "4:Cubic", size, CGNS_ENUMV(Unstructured), &znum) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateX", x3, &cnum) || cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0, "CoordinateX", 0, NULL) || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateY", y3, &cnum) || cg_gopath(fnum, "../CoordinateY") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp) || cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble), "CoordinateZ", zc, &cnum) || cg_gopath(fnum, "../CoordinateZ") || cg_exponents_write(CGNS_ENUMV(RealSingle), exp)) cg_error_exit (); ne = j = 0; /* BAR_4 */ if (cg_section_write (fnum, bnum, znum, "BAR_4", CGNS_ENUMV(BAR_4), ne+1, ne+1, 0, bar4, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(BAR_4); for (n = 0; n < 4; n++) elems[j++] = bar4[n]; /* TRI_9 */ if (cg_section_write (fnum, bnum, znum, "TRI_9", CGNS_ENUMV(TRI_9), ne+1, ne+1, 0, tri9, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TRI_9); for (n = 0; n < 9; n++) elems[j++] = tri9[n]; /* QUAD_12 */ if (cg_section_write (fnum, bnum, znum, "QUAD_12", CGNS_ENUMV(QUAD_12), ne+1, ne+1, 0, quad12, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(QUAD_12); for (n = 0; n < 12; n++) elems[j++] = quad12[n]; /* TETRA_16 */ if (cg_section_write (fnum, bnum, znum, "TETRA_16", CGNS_ENUMV(TETRA_16), ne+1, ne+1, 0, tetra16, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(TETRA_16); for (n = 0; n < 16; n++) elems[j++] = tetra16[n]; /* PYRA_21 */ if (cg_section_write (fnum, bnum, znum, "PYRA_21", CGNS_ENUMV(PYRA_21), ne+1, ne+1, 0, pyra21, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PYRA_21); for (n = 0; n < 21; n++) elems[j++] = pyra21[n]; /* PENTA_24 */ if (cg_section_write (fnum, bnum, znum, "PENTA_24", CGNS_ENUMV(PENTA_24), ne+1, ne+1, 0, penta24, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(PENTA_24); for (n = 0; n < 24; n++) elems[j++] = penta24[n]; /* HEXA_32 */ if (cg_section_write (fnum, bnum, znum, "HEXA_32", CGNS_ENUMV(HEXA_32), ne+1, ne+1, 0, hexa32, &snum)) cg_error_exit (); ne++; elems[j++] = (int)CGNS_ENUMV(HEXA_32); for (n = 0; n < 32; n++) elems[j++] = hexa32[n]; /* MIXED */ if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED), ne+1, ne+7, 0, elems, &snum)) cg_error_exit (); ne += 7; if (cg_close (fnum)) cg_error_exit (); return 0; }
unsigned short GetnDim(string val_mesh_filename, unsigned short val_format) { string text_line, Marker_Tag; ifstream mesh_file; short nDim = 3; unsigned short iLine, nLine = 10; char cstr[200]; string::size_type position; /*--- Open grid file ---*/ strcpy (cstr, val_mesh_filename.c_str()); mesh_file.open(cstr, ios::in); switch (val_format) { case SU2: /*--- Read SU2 mesh file ---*/ for (iLine = 0; iLine < nLine ; iLine++) { getline (mesh_file, text_line); /*--- Search for the "NDIM" keyword to see if there are multiple Zones ---*/ position = text_line.find ("NDIME=",0); if (position != string::npos) { text_line.erase (0,6); nDim = atoi(text_line.c_str()); } } break; case CGNS: #ifdef HAVE_CGNS /*--- Local variables which are needed when calling the CGNS mid-level API. ---*/ int fn, nbases = 0, nzones = 0, file_type; int cell_dim = 0, phys_dim = 0; char basename[CGNS_STRING_SIZE]; /*--- Check whether the supplied file is truly a CGNS file. ---*/ if ( cg_is_cgns(val_mesh_filename.c_str(), &file_type) != CG_OK ) { printf( "\n\n !!! Error !!!\n" ); printf( " %s is not a CGNS file.\n", val_mesh_filename.c_str()); printf( " Now exiting...\n\n"); exit(EXIT_FAILURE); } /*--- Open the CGNS file for reading. The value of fn returned is the specific index number for this file and will be repeatedly used in the function calls. ---*/ if (cg_open(val_mesh_filename.c_str(), CG_MODE_READ, &fn)) cg_error_exit(); /*--- Get the number of databases. This is the highest node in the CGNS heirarchy. ---*/ if (cg_nbases(fn, &nbases)) cg_error_exit(); /*--- Check if there is more than one database. Throw an error if there is because this reader can currently only handle one database. ---*/ if ( nbases > 1 ) { printf("\n\n !!! Error !!!\n" ); printf("CGNS reader currently incapable of handling more than 1 database."); printf("Now exiting...\n\n"); exit(EXIT_FAILURE); } /*--- Read the databases. Note that the indexing starts at 1. ---*/ for ( int i = 1; i <= nbases; i++ ) { if (cg_base_read(fn, i, basename, &cell_dim, &phys_dim)) cg_error_exit(); /*--- Get the number of zones for this base. ---*/ if (cg_nzones(fn, i, &nzones)) cg_error_exit(); } /*--- Set the problem dimension as read from the CGNS file ---*/ nDim = cell_dim; #endif break; } mesh_file.close(); return (unsigned short) nDim; }
int main() { /* dimension statements (note that tri-dimensional arrays r and p must be dimensioned exactly as [N-1][17-1+2][21-1+2] (N>=9) for this particular case or else they will be written to the CGNS file incorrectly! Other options are to use 1-D arrays, use dynamic memory, or pass index values to a subroutine and dimension exactly there): Rind cells are stored in array locations [k][0][i], [k][17][i], [k][j][0], [k][j][21] */ double r[8][18][22],p[8][18][22]; int ni,nj,nk,i,j,k,kk,index_file,index_base,index_zone,index_flow,index_field; int irinddata[6]; char solname[33]; /* create fake flow solution AT CELL CENTERS for simple example: */ ni=20; nj=16; nk=8; for (k=0; k < nk; k++) { for (j=0; j < nj; j++) { for (i=0; i < ni; i++) { r[k][j+1][i+1]=(float)i; p[k][j+1][i+1]=(float)j; } } } /* create rind cell data: */ for (k=0; k < nk; k++) { kk=k+1; for (j=0; j <= nj+1; j++) { r[k][j][0]=999.+(float)j+(5.*(float)kk); p[k][j][0]=999.+(float)j+(5.*(float)kk)+1.; r[k][j][ni+1]=-999.-(float)j-(5.*(float)kk); p[k][j][ni+1]=-999.-(float)j-(5.*(float)kk)-1.; } } for (k=0; k < nk; k++) { kk=k+1; for (i=0; i <= ni+1; i++) { r[k][0][i]=888.+(float)i+(5.*(float)kk); p[k][0][i]=888.+(float)i+(5.*(float)kk)+1.; r[k][nj+1][i]=-888.-(float)i-(5.*(float)kk); p[k][nj+1][i]=-888.-(float)i-(5.*(float)kk)-1.; } } printf("\ncreated simple 3-D rho and p flow solution with rind data\n"); /* WRITE FLOW SOLUTION 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; /* we know there is only one zone (real working code would check!) */ index_zone=1; /* define flow solution node name (user can give any name) */ strcpy(solname,"FlowSolution"); /* create flow solution node (NOTE USE OF CellCenter HERE) */ cg_sol_write(index_file,index_base,index_zone,solname,CellCenter,&index_flow); /* go to position within tree at FlowSolution_t node */ cg_goto(index_file,index_base,"Zone_t",index_zone,"FlowSolution_t",index_flow,"end"); /* write rind information under FlowSolution_t node (ilo,ihi,jlo,jhi,klo,khi) */ irinddata[0]=1; irinddata[1]=1; irinddata[2]=1; irinddata[3]=1; irinddata[4]=0; irinddata[5]=0; cg_rind_write(irinddata); /* write flow solution (user must use SIDS-standard names here) */ cg_field_write(index_file,index_base,index_zone,index_flow, RealDouble,"Density",r[0][0],&index_field); cg_field_write(index_file,index_base,index_zone,index_flow, RealDouble,"Pressure",p[0][0],&index_field); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully added flow solution data to file grid_c.cgns\n"); printf("\nNote: if the original CGNS file already had a FlowSolution_t node,"); printf("\n it has been overwritten\n"); return 0; }
int main (int argc, char **argv) { int n, nz, nzones = 50; double start, finish; char name[33], linkpath[33]; char fname[33], linkfile[33]; for (n = 0; n < 3; n++) { size[n] = NUM_SIDE; size[n+3] = NUM_SIDE - 1; size[n+6] = 0; } if (argc > 1) nzones = atoi (argv[1]); printf ("number of zones = %d\n", nzones); for (nz = 1; nz <= nzones; nz++) { sprintf (fname, "zone%d.cgns", nz); unlink (fname); } printf ("creating zones ..."); fflush (stdout); start = elapsed_time (); for (nz = 1; nz <= nzones; nz++) { sprintf (fname, "zone%d.cgns", nz); if (cg_open (fname, CG_MODE_WRITE, &cgfile) || cg_base_write (cgfile, "Base", 3, 3, &cgbase) || cg_zone_write (cgfile, cgbase, "Zone", size, Structured, &cgzone) || cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateX", coord, &cgcoord) || cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateY", coord, &cgcoord) || cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateZ", coord, &cgcoord)) cg_error_exit(); if (cg_close(cgfile)) cg_error_exit(); } finish = elapsed_time (); printf (" %g secs\n", finish - start); strcpy (fname, "links.cgns"); unlink (fname); strcpy (linkpath, "/Base/Zone"); printf ("creating link file ..."); fflush (stdout); start = elapsed_time (); if (cg_open (fname, CG_MODE_WRITE, &cgfile) || cg_base_write (cgfile, "Base", 3, 3, &cgbase)) cg_error_exit(); for (nz = 1; nz <= nzones; nz++) { sprintf (name, "Zone%d", nz); sprintf (linkfile, "zone%d.cgns", nz); if (cg_goto (cgfile, cgbase, "end") || cg_link_write (name, linkfile, linkpath)) cg_error_exit(); } cg_close (cgfile); finish = elapsed_time (); printf (" %g secs\n", finish - start); printf ("file size = %g Mb\n", file_size(fname)); printf ("opening link file ..."); fflush (stdout); start = elapsed_time (); if (cg_open (fname, CG_MODE_READ, &cgfile)) cg_error_exit(); finish = elapsed_time (); printf (" %g secs\n", finish - start); cg_close (cgfile); #if 0 printf ("opening link file ..."); fflush (stdout); start = elapsed_time (); if (cg_open (fname, CG_MODE_READ, &cgfile)) cg_error_exit(); finish = elapsed_time (); printf (" %g secs\n", finish - start); cg_close (cgfile); #endif 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; }
int main () { int n, nn, i, j, k, ni, nj, nk; int dims[3], grind[2], erind[2]; num_coord = NUM_I * NUM_J * NUM_K; num_element = (NUM_I - 1) * (NUM_J - 1) * (NUM_K - 1); xcoord = (float *) malloc(4 * num_coord * sizeof(float)); nmap = (int *) malloc((num_coord + 8 * num_element) * sizeof(int)); if (NULL == xcoord || NULL == nmap) { fprintf(stderr, "malloc failed for data\n"); exit(1); } ycoord = xcoord + num_coord; zcoord = ycoord + num_coord; solution = zcoord + num_coord; elements = nmap + num_coord; for (n = 0; n < num_coord; n++) solution[n] = (float)n; unlink("rind.cgns"); if (cg_open("rind.cgns", CG_MODE_WRITE, &cgfile)) cg_error_exit(); /*--- structured grid with rind ---*/ printf ("writing structured base with rind\n"); fflush (stdout); for (n = 0, k = 0; k < NUM_K; k++) { for (j = 0; j < NUM_J; j++) { for (i = 0; i < NUM_I; i++) { compute_coord(n++, i, j, k); } } } if (cg_base_write(cgfile, "Structured", CellDim, PhyDim, &cgbase) || cg_goto(cgfile, cgbase, "end") || cg_dataclass_write(NormalizedByUnknownDimensional) || cg_zone_write(cgfile, cgbase, "Zone", size, Structured, &cgzone)) cg_error_exit(); /* can't use cg_coord_write to write rind coordinates need to use cg_grid_write to create the node, cg_goto to set position at the node, then write rind and coordinates as an array */ dims[0] = NUM_I; dims[1] = NUM_J; dims[2] = NUM_K; if (cg_grid_write(cgfile, cgbase, cgzone, "GridCoordinates", &cggrid) || cg_goto(cgfile, cgbase, "Zone_t", cgzone, "GridCoordinates_t", cggrid, "end") || cg_rind_write(rind) || cg_array_write("CoordinateX", RealSingle, 3, dims, xcoord) || cg_array_write("CoordinateY", RealSingle, 3, dims, ycoord) || cg_array_write("CoordinateZ", RealSingle, 3, dims, zcoord)) cg_error_exit(); /* a similiar technique is used for the solution with rind, but we use cg_field_write instead of cg_array_write and the solution dimensions come from the zone sizes */ if (cg_sol_write(cgfile, cgbase, cgzone, "VertexSolution", Vertex, &cgsol) || cg_goto(cgfile, cgbase, "Zone_t", cgzone, "FlowSolution_t", cgsol, "end") || cg_rind_write(rind) || cg_field_write(cgfile, cgbase, cgzone, cgsol, RealSingle, "Density", solution, &cgfld)) cg_error_exit(); /*--- unstructured with rind ---*/ printf ("writing unstructured base with rind\n"); fflush (stdout); /* rind here has dimension rind[2], so need to put all the rind coordinates at the beginning and/or end of the array. Just for grins, I'll put some at both ends, although it's probably best to put the rind coordinates at the end. I'll use the nmap array for building elements */ ni = size[0] + rind[0]; nj = size[1] + rind[2]; nk = size[2] + rind[4]; for (n = 0, i = 0; i < rind[0]; i++) { for (k = 0; k < NUM_K; k++) { for (j = 0; j < NUM_J; j++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } for (j = 0; j < rind[2]; j++) { for (k = 0; k < NUM_K; k++) { for (i = rind[0]; i < ni; i++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } for (k = 0; k < rind[4]; k++) { for (j = rind[2]; j < nj; j++) { for (i = rind[0]; i < ni; i++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } grind[0] = n; for (k = rind[4]; k < nk; k++) { for (j = rind[2]; j < nj; j++) { for (i = rind[0]; i < ni; i++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } grind[1] = num_coord - n; for (i = ni; i < NUM_I; i++) { for (k = 0; k < NUM_K; k++) { for (j = 0; j < NUM_J; j++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } for (j = nj; j < NUM_J; j++) { for (k = 0; k < NUM_K; k++) { for (i = rind[0]; i < ni; i++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } for (k = nk; k < NUM_K; k++) { for (j = rind[2]; j < nj; j++) { for (i = rind[0]; i < ni; i++) { compute_coord (n, i, j, k); nn = INDEX(i, j, k); nmap[nn] = ++n; } } } /* rind elements are like the coordinates, they need to go at the beginning and/or end of the element array, although at the end is probably best */ for (n = 0, i = 0; i < rind[0]; i++) { for (k = 0; k < NUM_K - 1; k++) { for (j = 0; j < NUM_J - 1; j++) { compute_element(n++, i, j, k); } } } for (j = 0; j < rind[2]; j++) { for (k = 0; k < NUM_K - 1; k++) { for (i = rind[0]; i < ni - 1; i++) { compute_element(n++, i, j, k); } } } for (k = 0; k < rind[4]; k++) { for (j = rind[2]; j < nj - 1; j++) { for (i = rind[0]; i < ni - 1; i++) { compute_element(n++, i, j, k); } } } erind[0] = n; for (k = rind[4]; k < nk - 1; k++) { for (j = rind[2]; j < nj - 1; j++) { for (i = rind[0]; i < ni - 1; i++) { compute_element(n++, i, j, k); } } } erind[1] = num_element - n; for (i = ni - 1; i < NUM_I - 1; i++) { for (k = 0; k < NUM_K - 1; k++) { for (j = 0; j < NUM_J - 1; j++) { compute_element(n++, i, j, k); } } } for (j = nj - 1; j < NUM_J - 1; j++) { for (k = 0; k < NUM_K - 1; k++) { for (i = rind[0]; i < ni - 1; i++) { compute_element(n++, i, j, k); } } } for (k = nk - 1; k < NUM_K - 1; k++) { for (j = rind[2]; j < nj - 1; j++) { for (i = rind[0]; i < ni - 1; i++) { compute_element(n++, i, j, k); } } } /* create base, zone and write coordinates. As for the structured case, the rind coordinates and elements are not included in the zone totals */ dims[0] = num_coord - grind[0] - grind[1]; dims[1] = num_element - erind[0] - erind[1]; dims[2] = 0; if (cg_base_write(cgfile, "Unstructured", CellDim, PhyDim, &cgbase) || cg_goto(cgfile, cgbase, "end") || cg_dataclass_write(NormalizedByUnknownDimensional) || cg_zone_write(cgfile, cgbase, "Zone", dims, Unstructured, &cgzone) || cg_grid_write(cgfile, cgbase, cgzone, "GridCoordinates", &cggrid) || cg_goto(cgfile, cgbase, "Zone_t", cgzone, "GridCoordinates_t", cggrid, "end") || cg_rind_write(grind) || cg_array_write("CoordinateX", RealSingle, 1, &num_coord, xcoord) || cg_array_write("CoordinateY", RealSingle, 1, &num_coord, ycoord) || cg_array_write("CoordinateZ", RealSingle, 1, &num_coord, zcoord)) cg_error_exit(); /* to write the elements with rind elements, write all the elements, then use goto to add rind */ if (cg_section_write(cgfile, cgbase, cgzone, "Elements", HEXA_8, 1, num_element, 0, elements, &cgsect) || cg_goto(cgfile, cgbase, "Zone_t", cgzone, "Elements_t", cgsect, "end") || cg_rind_write(erind)) cg_error_exit(); /* write solution a vertices with rind */ if (cg_sol_write(cgfile, cgbase, cgzone, "VertexSolution", Vertex, &cgsol) || cg_goto(cgfile, cgbase, "Zone_t", cgzone, "FlowSolution_t", cgsol, "end") || cg_rind_write(grind) || cg_field_write(cgfile, cgbase, cgzone, cgsol, RealSingle, "Density", solution, &cgfld)) cg_error_exit(); cg_close(cgfile); return 0; }
void COutput::SetCGNS_Coordinates(CConfig *config, CGeometry *geometry, unsigned short iZone) { #ifdef HAVE_CGNS /*--- local CGNS variables ---*/ int cgns_file, cgns_coord, element_dims, physical_dims, cgns_err; unsigned long iExtIter = config->GetExtIter(); string base_file, buffer, elements_name; stringstream name, results_file; bool unsteady = config->GetUnsteady_Simulation(); cgsize_t isize[3][1]; /*--- Create CGNS base file name ---*/ base_file = config->GetFlow_FileName(); /*--- Add CGNS extension. ---*/ base_file = base_file.append(".cgns"); /*--- Create CGNS results file name ---*/ if (unsteady) { buffer = config->GetFlow_FileName(); results_file.str(string()); results_file << buffer; if (((int)iExtIter >= 0) && ((int)iExtIter < 10)) results_file << "_0000" << iExtIter; if (((int)iExtIter >= 10) && ((int)iExtIter < 100)) results_file << "_000" << iExtIter; if (((int)iExtIter >= 100) && ((int)iExtIter < 1000)) results_file << "_00" << iExtIter; if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000)) results_file << "_0" << iExtIter; if ((int)iExtIter >= 10000) results_file << iExtIter; results_file << ".cgns"; } /*--- Write base file if not already done ---*/ if (!wrote_base_file) { /*--- Write base file ---*/ cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file); if (cgns_err) cg_error_print(); element_dims = geometry->GetnDim(); // Currently (release 2.0) only all-2D or all-3D zones permitted physical_dims = element_dims; isize[0][0] = (cgsize_t)nGlobal_Poin; // vertex size isize[1][0] = (cgsize_t)nGlobal_Elem; // cell size isize[2][0] = 0; // boundary vertex size (zero if elements not sorted) cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"end"); if (cgns_err) cg_error_print(); // // cgns_err = cg_goto(cgns_file, cgns_base, cgns_zone,"end"); // if (cgns_err) cg_error_print(); /*--- write CGNS node coordinates ---*/ cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"x", Coords[0], &cgns_coord); if (cgns_err) cg_error_print(); cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"y", Coords[1], &cgns_coord); if (cgns_err) cg_error_print(); if (geometry->GetnDim() == 3) { cgns_err = cg_coord_write(cgns_file, cgns_base, cgns_zone, RealDouble,"z", Coords[2], &cgns_coord); if (cgns_err) cg_error_print(); } cgns_err = cg_close(cgns_file); if (cgns_err) cg_error_print(); wrote_base_file = true; } /*--- Set up results file for this time step if necessary ---*/ if (unsteady) { cgns_err = cg_open((char *)results_file.str().c_str(), CG_MODE_WRITE, &cgns_file); element_dims = geometry->GetnDim(); // Currently only all-2D or all-3D zones permitted physical_dims = element_dims; /*--- write CGNS base data (one base assumed currently) ---*/ cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base_results); if (cgns_err) cg_error_print(); isize[0][0] = (cgsize_t)geometry->GetGlobal_nPointDomain(); // vertex size isize[1][0] = (cgsize_t)nGlobal_Elem; // cell size isize[2][0] = 0; // boundary vertex size (zero if elements not sorted) /*--- write CGNS zone data ---*/ cgns_err = cg_zone_write(cgns_file, cgns_base_results,"SU2 Zone", isize[0],Unstructured, &cgns_zone_results); if (cgns_err) cg_error_print(); cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"end"); if (cgns_err) cg_error_print(); /*--- Write CGNS node coordinates, if appliciable ---*/ if (config->GetGrid_Movement()) { /*--- write CGNS node coordinates ---*/ cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"x", Coords[0], &cgns_coord); if (cgns_err) cg_error_print(); cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"y", Coords[1], &cgns_coord); if (cgns_err) cg_error_print(); if (geometry->GetnDim() == 3) { cgns_err = cg_coord_write(cgns_file, cgns_base_results, cgns_zone_results, RealDouble,"z", Coords[2], &cgns_coord); if (cgns_err) cg_error_print(); } } else { /*--- Write a CGNS link for the node coordinates ---*/ cgns_err = cg_link_write("GridCoordinates",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/GridCoordinates"); if (cgns_err) cg_error_print(); } /*--- Write a CGNS link for each element type connectivity ---*/ if (nGlobal_Tria > 0) cgns_err = cg_link_write("Triangle Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Triangle Elements"); if (nGlobal_Quad > 0) cgns_err = cg_link_write("Quadrilateral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Quadrilateral Elements"); if (nGlobal_Tetr > 0) cgns_err = cg_link_write("Tetrahedral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Tetrahedral Elements"); if (nGlobal_Hexa > 0) cgns_err = cg_link_write("Hexahedral Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Hexahedral Elements"); if (nGlobal_Pyra > 0) cgns_err = cg_link_write("Pyramid Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Pyramid Elements"); if (nGlobal_Pris > 0) cgns_err = cg_link_write("Prism Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Prism Elements"); if (nGlobal_Line > 0) cgns_err = cg_link_write("Line Elements",(char *)base_file.c_str(),"/SU2 Base/SU2 Zone/Line Elements"); if (cgns_err) cg_error_print(); /*--- Close CGNS file ---*/ cgns_err = cg_close(cgns_file); if (cgns_err) cg_error_print(); } #else // Not built with CGNS support cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; #endif }
void COutput::SetCGNS_Solution(CConfig *config, CGeometry *geometry, unsigned short iZone) { #ifdef HAVE_CGNS /*--- local CGNS variables ---*/ int cgns_file, cgns_flow, cgns_field, cgns_err; // int element_dims; unsigned long jVar, iVar, iExtIter = config->GetExtIter(); string base_file, buffer, elements_name; stringstream name, results_file; bool unsteady = config->GetUnsteady_Simulation(); bool compressible = (config->GetKind_Regime() == COMPRESSIBLE); /*--- Create CGNS base file name ---*/ base_file = config->GetFlow_FileName(); /*--- Add CGNS extension. ---*/ base_file = base_file.append(".cgns"); /*--- Create CGNS results file name ---*/ if (unsteady) { buffer = config->GetFlow_FileName(); results_file.str(string()); results_file << buffer; if (((int)iExtIter >= 0) && ((int)iExtIter < 10)) results_file << "_0000" << iExtIter; if (((int)iExtIter >= 10) && ((int)iExtIter < 100)) results_file << "_000" << iExtIter; if (((int)iExtIter >= 100) && ((int)iExtIter < 1000)) results_file << "_00" << iExtIter; if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000)) results_file << "_0" << iExtIter; if ((int)iExtIter >= 10000) results_file << iExtIter; results_file << ".cgns"; } if (!unsteady) { /*--- Write base file ---*/ cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file); if (cgns_err) cg_error_print(); // element_dims = geometry->GetnDim(); // Currently (release 2.0) only all-2D or all-3D zones permitted /*--- write CGNS descriptor data ---*/ cgns_err = cg_goto(cgns_file, cgns_base,"end"); if (cgns_err) cg_error_print(); /*--- Create a CGNS solution node ---*/ cgns_err = cg_sol_write(cgns_file, cgns_base, cgns_zone,"Solution", Vertex, &cgns_flow); if (cgns_err) cg_error_print(); cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"FlowSolution_t", cgns_flow,"end"); if (cgns_err) cg_error_print(); cgns_err = cg_gridlocation_write(Vertex); if (cgns_err) cg_error_print(); } //wrote_CGNS_base = true; else { /*--- Set up results file for this time step if necessary ---*/ cgns_err = cg_open((char *)results_file.str().c_str(), CG_MODE_MODIFY, &cgns_file); // element_dims = geometry->GetnDim(); // Currently (release 2.0) only all-2D or all-3D zones permitted // // /*--- write CGNS base data (one base assumed currently) ---*/ // cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base); // if (cgns_err) cg_error_print(); // /*--- write CGNS zone data ---*/ // cgns_err = cg_zone_write(cgns_file, cgns_base,"SU2 Zone", isize[0],Unstructured, &cgns_zone); // if (cgns_err) cg_error_print(); cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"end"); if (cgns_err) cg_error_print(); /*--- Write a CGNS solution node for this time step ---*/ cgns_err = cg_sol_write(cgns_file, cgns_base_results, cgns_zone_results,"Solution", Vertex, &cgns_flow); if (cgns_err) cg_error_print(); cgns_err = cg_goto(cgns_file, cgns_base_results,"Zone_t", cgns_zone_results,"FlowSolution_t", cgns_flow,"end"); if (cgns_err) cg_error_print(); cgns_err = cg_gridlocation_write(Vertex); if (cgns_err) cg_error_print(); cgns_base = cgns_base_results; cgns_zone = cgns_zone_results; } // else { // // /*--- Open CGNS file for soltuion writing ---*/ // cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_MODIFY, &cgns_file); // cgns_base = 1; cgns_zone = 1; cgns_flow = 1; // fix for multiple zones // // } /* Reference Note on solution variables: index 0 --> (nVar_Consv-1) = Conservative Variables nVar_Consv --> (2*nVar_Consv-1) = Conservative Variable Residuals (2*nVar_Consv-1)+ = Additional p, M, T, laminar, eddy depending on solver used */ /*--- Write conservative variables to CGNS file ---*/ for (iVar = 0; iVar < nVar_Consv; iVar++) { name.str(string()); name << "Conservative Variable " << iVar+1; cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field); if (cgns_err) cg_error_print(); } /*--- Write primitive variable residuals to CGNS file ---*/ if (config->GetWrt_Limiters()) { for (jVar = 0; jVar < nVar_Consv; jVar++) { name.str(string()); name << "Primitive Limiter " << jVar+1; cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); } } /*--- Write conservative variable residuals to CGNS file ---*/ if (config->GetWrt_Residuals()) { for (jVar = 0; jVar < nVar_Consv; jVar++) { name.str(string()); name << "Conservative Residual " << jVar+1; cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,(char *)name.str().c_str(), Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); } } /*--- Write grid velocities to CGNS file, if applicable ---*/ if (config->GetGrid_Movement()) { cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity X", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity Y", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); if (geometry->GetnDim() == 3) { cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Grid Velocity Z", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); } } if (compressible) { switch (config->GetKind_Solver()) { /*--- Write pressure and Mach data to CGNS file ---*/ case EULER: cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); break; /*--- Write temperature and laminar viscosity to CGNS file, if applicable ---*/ case NAVIER_STOKES: cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Temperature", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Viscosity", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); break; /*--- Write eddy viscosity to CGNS file, if applicable ---*/ case RANS: cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Pressure", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Mach", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Temperature", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Viscosity", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); cgns_err = cg_field_write(cgns_file, cgns_base, cgns_zone, cgns_flow, RealDouble,"Eddy Viscosity", Data[iVar], &cgns_field); iVar++; if (cgns_err) cg_error_print(); break; default: cout << "Error: Unrecognized equation type \n"; exit(EXIT_FAILURE); break; } } /*--- Close CGNS file ---*/ cgns_err = cg_close(cgns_file); if (cgns_err) cg_error_print(); #else // Not built with CGNS support cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; #endif }
void COutput::SetCGNS_Connectivity(CConfig *config, CGeometry *geometry, unsigned short iZone) { #ifdef HAVE_CGNS /*--- local CGNS variables ---*/ int cgns_file, element_dims, physical_dims, cgns_err; int cgns_section; unsigned long iExtIter = config->GetExtIter(); string base_file, buffer, elements_name; stringstream name, results_file; bool unsteady = config->GetUnsteady_Simulation(); cgsize_t isize[3][1], elem_start, elem_end; /*--- Create CGNS base file name ---*/ base_file = config->GetFlow_FileName(); /*--- Add CGNS extension. ---*/ base_file = base_file.append(".cgns"); /*--- Create CGNS results file name ---*/ if (unsteady) { buffer = config->GetFlow_FileName(); results_file.str(string()); results_file << buffer; if (((int)iExtIter >= 0) && ((int)iExtIter < 10)) results_file << "_0000" << iExtIter; if (((int)iExtIter >= 10) && ((int)iExtIter < 100)) results_file << "_000" << iExtIter; if (((int)iExtIter >= 100) && ((int)iExtIter < 1000)) results_file << "_00" << iExtIter; if (((int)iExtIter >= 1000) && ((int)iExtIter < 10000)) results_file << "_0" << iExtIter; if ((int)iExtIter >= 10000) results_file << iExtIter; results_file << ".cgns"; } /*--- Write base file if not already done ---*/ if (!wrote_base_file) { /*--- Write base file ---*/ cgns_err = cg_open((char *)base_file.c_str(), CG_MODE_WRITE, &cgns_file); if (cgns_err) cg_error_print(); element_dims = geometry->GetnDim(); // Currently only all-2D or all-3D zones permitted physical_dims = element_dims; /*--- write CGNS base data (one base assumed currently) ---*/ cgns_err = cg_base_write(cgns_file,"SU2 Base", element_dims, physical_dims, &cgns_base); if (cgns_err) cg_error_print(); /*--- write CGNS descriptor data ---*/ cgns_err = cg_goto(cgns_file, cgns_base,"end"); if (cgns_err) cg_error_print(); cgns_err = cg_equationset_write(physical_dims); if (cgns_err) cg_error_print(); /*--- Write governing equations to CGNS file ---*/ cgns_err = cg_goto(cgns_file, cgns_base,"FlowEquationSet_t",1,"end"); if (cgns_err) cg_error_print(); switch (config->GetKind_Solver()) { case EULER: cgns_err = cg_governing_write(Euler); break; case NAVIER_STOKES: cgns_err = cg_governing_write(NSLaminar); break; case RANS: cgns_err = cg_governing_write(NSTurbulent); break; default: break; // cgns_err = cg_governing_write(CG_UserDefined); } if (cgns_err) cg_error_print(); if (unsteady) cgns_err = cg_simulation_type_write(cgns_file, cgns_base, TimeAccurate); else cgns_err = cg_simulation_type_write(cgns_file, cgns_base, NonTimeAccurate); if (cgns_err) cg_error_print(); cgns_err = cg_descriptor_write("Solver Information","SU2"); if (cgns_err) cg_error_print(); isize[0][0] = (cgsize_t)geometry->GetGlobal_nPointDomain(); //; // vertex size isize[1][0] = (cgsize_t)nGlobal_Elem; // cell size isize[2][0] = 0; // boundary vertex size (zero if elements not sorted) /*--- write CGNS zone data ---*/ cgns_err = cg_zone_write(cgns_file, cgns_base,"SU2 Zone", isize[0],Unstructured, &cgns_zone); if (cgns_err) cg_error_print(); cgns_err = cg_goto(cgns_file, cgns_base,"Zone_t", cgns_zone,"end"); if (cgns_err) cg_error_print(); /*--- Reference Note: CGNS element type list: NODE, BAR_2, BAR_3, TRI_3, TRI_6, QUAD_4, QUAD_8, QUAD_9, TETRA_4, TETRA_10, PYRA_5, PYRA_14, PENTA_6, PENTA_15, PENTA_18, HEXA_8, HEXA_20, HEXA_27, MIXED, PYRA_13, NGON_n, NFACE_n ---*/ /*--- Write a CGNS section for each element type ---*/ // ier = cg_section_write(int fn, int B, int Z, char *ElementSectionName, ElementType_t type, // cgsize_t start, cgsize_t end, int nbndry, cgsize_t *Elements, int *S); if (nGlobal_Tria > 0) { elem_start = 1; elem_end = (int)nGlobal_Tria; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone, "Triangle Elements", TRI_3, elem_start, elem_end, 0,(cgsize_t *)Conn_Tria, &cgns_section); } if (nGlobal_Quad > 0) { elem_start = 1; elem_end = (int)nGlobal_Quad; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Quadrilateral Elements", QUAD_4, elem_start, elem_end,0,(cgsize_t *)Conn_Quad, &cgns_section); } if (nGlobal_Tetr > 0) { elem_start = 1; elem_end = (int)nGlobal_Tetr; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Tetrahedral Elements", TETRA_4, elem_start, elem_end,0,(cgsize_t *)Conn_Tetr, &cgns_section); } if (nGlobal_Hexa > 0) { elem_start = 1; elem_end = (int)nGlobal_Hexa; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Hexahedral Elements", HEXA_8, elem_start, elem_end,0,(cgsize_t *)Conn_Hexa, &cgns_section); } if (nGlobal_Pyra > 0) { elem_start = 1; elem_end = (int)nGlobal_Pyra; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Pyramid Elements", PYRA_5, elem_start, elem_end,0,(cgsize_t *)Conn_Pyra, &cgns_section); } if (nGlobal_Pris > 0) { elem_start = 1; elem_end = (int)nGlobal_Pris; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Prism Elements", PENTA_6, elem_start, elem_end,0,(cgsize_t *)Conn_Pris, &cgns_section); } if (nGlobal_Line > 0) { elem_start = 1; elem_end = (int)nGlobal_Line; cgns_err = cg_section_write(cgns_file, cgns_base, cgns_zone,"Line Elements", BAR_2, elem_start, elem_end,0,(cgsize_t *)Conn_Line, &cgns_section); } if (cgns_err) cg_error_print(); cgns_err = cg_close(cgns_file); if (cgns_err) cg_error_print(); } #else // Not built with CGNS support cout << "CGNS file requested but SU2 was built without CGNS support. No file written" << "\n"; #endif }
// Read part_struct data void cgns_fill_part_struct(void) { // Open cgns file and get cgns file index number fn char buf[FILE_NAME_SIZE]; sprintf(buf, "%s/%s/%s", ROOT_DIR, OUTPUT_DIR, partFiles[fileMap[tt]]); int fn; cg_open(buf, CG_MODE_READ, &fn); // Set base, zone, and solutions index numbers int bn = 1; int zn = 1; int sn = 1; // Read part coords double *x = malloc(nparts * sizeof(double)); double *y = malloc(nparts * sizeof(double)); double *z = malloc(nparts * sizeof(double)); for (int p = 0; p < nparts; p++) { x[p] = 0; y[p] = 0; z[p] = 0; } cgsize_t range_min = 1; cgsize_t range_max = nparts; cg_coord_read(fn,bn,zn, "CoordinateX", RealDouble, &range_min, &range_max, x); cg_coord_read(fn,bn,zn, "CoordinateY", RealDouble, &range_min, &range_max, y); cg_coord_read(fn,bn,zn, "CoordinateZ", RealDouble, &range_min, &range_max, z); for (int p = 0; p < nparts; p++) { parts[p].x = x[p]; parts[p].y = y[p]; parts[p].z = z[p]; } // Read part vel double *u = malloc(nparts * sizeof(double)); double *v = malloc(nparts * sizeof(double)); double *w = malloc(nparts * sizeof(double)); for (int p = 0; p < nparts; p++) { w[p] = 0; v[p] = 0; w[p] = 0; } cg_field_read(fn,bn,zn,sn, "VelocityX", RealDouble, &range_min, &range_max, u); cg_field_read(fn,bn,zn,sn, "VelocityY", RealDouble, &range_min, &range_max, v); cg_field_read(fn,bn,zn,sn, "VelocityZ", RealDouble, &range_min, &range_max, w); for (int p = 0; p < nparts; p++) { parts[p].u = u[p]; parts[p].v = v[p]; parts[p].w = w[p]; } // Read actual time cg_goto(fn, bn, "Zone_t", zn, "Etc", 0, "end"); cg_array_read(1, &simTime[tt]); free(x); free(y); free(z); free(u); free(v); free(w); cg_close(fn); }
int main (int argc, char **argv) { int n, i, j, k, nuser, dim = 1; int cgfile, cgbase, cgzone, cgcoord, cgdset; int size[9]; int ptlist[3] = {1, 2, 3}; int ptrange[6] = {1, 1, 1, 2, 2, 2}; int bcpoints[6], bcfaces[6]; static char *fname = "gotest.cgns"; char name[33]; float data1 = 1; float data2 = 2; float exponents[8], rate[3], center[3]; GridLocation_t gridloc; int ordinal, ndata, cgfam, cgbc, nunits, nexps; int elecflag, magnflag, condflag, dirichlet, neumann; PointSetType_t pttype; DataClass_t dclass; DataType_t dtype; BCType_t bctype; MassUnits_t mass; LengthUnits_t length; TimeUnits_t time; TemperatureUnits_t temp; AngleUnits_t angle; ElectricCurrentUnits_t current; SubstanceAmountUnits_t amount; LuminousIntensityUnits_t intensity; ModelType_t elecmodel; ModelType_t magnmodel; ModelType_t emconduct; /* errors and warnings go to error_exit */ cg_configure(CG_CONFIG_ERROR, (void *)error_exit); for (n = 0; n < 8; n++) exponents[n] = (float)n; for (n = 0; n < 3; n++) { rate[n] = (float)n; center[n] = (float)n; } for (n = 0; n < NUM_SIDE*NUM_SIDE*NUM_SIDE; n++) coord[n] = (float)n; unlink (fname); printf ("creating CGNS file %s\n", fname); cg_open (fname, CG_MODE_WRITE, &cgfile); cg_base_write (cgfile, "Base", 3, 3, &cgbase); /* write electomagnetics model under base */ puts ("writing electromagnetics"); cg_goto(cgfile, cgbase, NULL); cg_equationset_write (3); cg_goto(cgfile, cgbase, "FlowEquationSet_t", 1, NULL); cg_model_write("EMElectricFieldModel_t", Voltage); cg_model_write("EMMagneticFieldModel_t", Interpolated); cg_model_write("EMConductivityModel_t", Equilibrium_LinRessler); /* write rotating coordinates under family_t */ puts ("writing family/rotating"); cg_family_write(cgfile, cgbase, "Family", &cgfam); /* go to a named node */ cg_goto(cgfile, cgbase, "Family", 0, NULL); cg_rotating_write (rate, center); /* write BCDataSet under FamilyBC_t */ puts("writing FamilyBCDataSet"); cg_fambc_write(cgfile, cgbase, cgfam, "FamilyBC", BCWall, &cgbc); /* relative go to */ cg_gorel(cgfile, "FamilyBC_t", cgbc, NULL); cg_bcdataset_write ("FamilyBCDataSet", BCWallInviscid, Dirichlet); /* write user data under base */ puts("writing user defined data under base"); /* relative path */ cg_gopath (cgfile, "../.."); cg_user_data_write ("User"); /* absolute path */ cg_gopath (cgfile, "/Base/User"); cg_gridlocation_write (CellCenter); cg_famname_write ("Family"); cg_ordinal_write (0); cg_array_write ("Data1", RealSingle, 1, &dim, &data1); cg_array_write ("Data2", RealSingle, 1, &dim, &data2); for (n = 1; n <= 2; n++) { cg_goto (cgfile, cgbase, "User", 0, "DataArray_t", n, "end"); cg_dataclass_write (Dimensional); cg_units_write (Kilogram, Meter, Second, Kelvin, Radian); cg_exponents_write (RealSingle, exponents); } /* this should fail since ptset not allowed as child of user data, except below a zone_t node */ cg_configure(CG_CONFIG_ERROR, NULL); if (cg_ptset_write (PointList, 1, ptlist) == CG_OK) printf ("WHAT!! - ptset should not work under base/userdata\n"); cg_configure(CG_CONFIG_ERROR, (void *)error_exit); /* write zone */ puts("writing zone"); for (n = 0; n < 3; n++) { size[n] = NUM_SIDE; size[n+3] = NUM_SIDE - 1; size[n+6] = 0; } cg_zone_write (cgfile, cgbase, "Zone", size, Structured, &cgzone); cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateX", coord, &cgcoord); cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateY", coord, &cgcoord); cg_coord_write(cgfile, cgbase, cgzone, RealSingle, "CoordinateZ", coord, &cgcoord); /* create a BC node with point range and Dirichlet node*/ puts("writing Dirichlet BC with vertex range"); for (n = 0; n < 3; n++) { bcpoints[n] = 1; bcpoints[n+3] = NUM_SIDE; bcfaces[n] = 1; bcfaces[n+3] = NUM_SIDE - 1; } bcpoints[5] = bcfaces[5] = 1; cg_boco_write (cgfile, cgbase, cgzone, "BC", BCWall, PointList, 1, bcpoints, &cgbc); cg_dataset_write (cgfile, cgbase, cgzone, cgbc, "DataSet", BCWallViscous, &cgdset); cg_bcdata_write (cgbase, cgfile, cgzone, cgbc, cgdset, Dirichlet); /* create Dirichlet data at faces */ puts("writing Dirichlet data at faces"); cg_gopath (cgfile, "/Base/Zone/ZoneBC/BC/DataSet"); cg_gridlocation_write (KFaceCenter); cg_ptset_write (PointRange, 2, bcfaces); size[0] = (NUM_SIDE - 1) * (NUM_SIDE - 1); cg_gorel (cgfile, "BCData_t", Dirichlet, NULL); cg_array_write ("Data", RealSingle, 1, size, coord); /* write recursive user data */ puts("writing recursive user defined data under zone"); cg_goto(cgfile, cgbase, "Zone", 0, NULL); for (i = 1; i <= 4; i++) { sprintf (name, "User%d", i); cg_user_data_write (name); cg_gorel(cgfile, name, 0, NULL); cg_gridlocation_write (CellCenter); cg_famname_write ("Family"); cg_ordinal_write (i); cg_ptset_write (PointList, 1, ptlist); cg_array_write ("Data1", RealSingle, 1, &dim, &data1); cg_array_write ("Data2", RealSingle, 1, &dim, &data2); for (n = 1; n <= 2; n++) { cg_gorel (cgfile, "DataArray_t", n, "end"); cg_dataclass_write (Dimensional); cg_unitsfull_write (Kilogram, Meter, Second, Kelvin, Radian, Ampere, Mole, Candela); cg_expfull_write (RealSingle, exponents); cg_gopath (cgfile, ".."); } for (j = 1; j <= 3; j++) { sprintf (name, "User%d.%d", i, j); cg_user_data_write (name); cg_gopath (cgfile, name); cg_gridlocation_write (Vertex); cg_famname_write ("Family"); cg_ordinal_write (i + j); cg_ptset_write (PointRange, 2, ptrange); cg_array_write ("Data1", RealSingle, 1, &dim, &data1); cg_array_write ("Data2", RealSingle, 1, &dim, &data2); for (n = 1; n <= 2; n++) { cg_gorel (cgfile, "DataArray_t", n, "end"); cg_dataclass_write (Dimensional); cg_unitsfull_write (Kilogram, Meter, Second, Kelvin, Radian, Ampere, Mole, Candela); cg_expfull_write (RealSingle, exponents); cg_gorel (cgfile, "..", 0, NULL); } for (k = 1; k <= 2; k++) { sprintf (name, "User%d.%d.%d", i, j, k); cg_user_data_write (name); cg_gorel (cgfile, name, 0, NULL); cg_array_write ("Data1", RealSingle, 1, &dim, &data1); cg_array_write ("Data2", RealSingle, 1, &dim, &data2); for (n = 1; n <= 2; n++) { cg_gorel (cgfile, "DataArray_t", n, "end"); cg_dataclass_write (Dimensional); cg_unitsfull_write (Kilogram, Meter, Second, Kelvin, Radian, Ampere, Mole, Candela); cg_expfull_write (RealSingle, exponents); cg_gopath (cgfile, ".."); } for (n = 1; n <= 2; n++) { sprintf (name, "User%d.%d.%d.%d", i, j, k, n); cg_user_data_write (name); cg_gopath (cgfile, name); cg_array_write ("Data1", RealSingle, 1, &dim, &data1); cg_array_write ("Data2", RealSingle, 1, &dim, &data2); cg_gopath (cgfile, ".."); } cg_gopath (cgfile, ".."); } cg_gopath (cgfile, ".."); } cg_gopath (cgfile, ".."); } puts ("closing and reopening in read mode"); cg_close (cgfile); /* read file and check values */ cg_configure(CG_CONFIG_ERROR, NULL); if (cg_open (fname, CG_MODE_READ, &cgfile)) cg_error_exit (); cgbase = cgzone = 1; /* check electomagnetics model under base */ puts ("checking electromagnetics"); if (cg_goto(cgfile, cgbase, NULL) || cg_equationset_elecmagn_read(&elecflag, &magnflag, &condflag) || cg_goto(cgfile, cgbase, "FlowEquationSet_t", 1, NULL) || cg_model_read ("EMElectricFieldModel_t", &elecmodel) || cg_model_read ("EMMagneticFieldModel_t", &magnmodel) || cg_model_read ("EMConductivityModel_t", &emconduct)) cg_error_exit(); CHECK ("ElectricFieldFlag", elecflag == 1); CHECK ("ElectricFieldModel", elecmodel == Voltage); CHECK ("MagneticFieldFlag", magnflag == 1); CHECK ("MagneticFieldModel", magnmodel == Interpolated); CHECK ("EMConductivityFlag", condflag == 1); CHECK ("EMConductivityModel", emconduct == Equilibrium_LinRessler); /* check rotating coordinates under family_t */ puts ("checking family/rotating"); if (cg_goto(cgfile, cgbase, "Family_t", 1, NULL) || cg_rotating_read (rate, center)) cg_error_exit(); for (n = 0; n < 3; n++) { CHECK ("rotation rate", rate[n] == (float)n); CHECK ("rotation center", center[n] == (float)n); } /* check BCDataSet under FamilyBC_t */ puts("checking FamilyBCDataSet"); *name = 0; if (cg_goto(cgfile, cgbase, "Family_t", 1, "FamilyBC_t", 1, NULL) || cg_bcdataset_info(&ndata) || cg_bcdataset_read (1, name, &bctype, &dirichlet, &neumann)) cg_error_exit(); CHECK("bcdataset_info", ndata == 1); CHECK("bcdatset name", strcmp(name, "FamilyBCDataSet") == 0); CHECK("bcdatset type", bctype == BCWallInviscid); CHECK("bcdatset dirichlet", dirichlet == 1); CHECK("bcdatset neumann", neumann == 0); /* check BC data */ puts("checking BC data"); if (cg_boco_info (cgfile, cgbase, cgzone, 1, name, &bctype, &pttype, &n, size, &i, &dtype, &ndata)) cg_error_exit(); CHECK("BC_t name", strcmp(name, "BC") == 0); CHECK("BC_t type", bctype == BCWall); CHECK("BC_t pntset type", pttype == PointList); CHECK("BC_t npnts", n == 1); if (cg_dataset_read (cgfile, cgbase, cgzone, 1, 1, name, &bctype, &dirichlet, &neumann) || cg_goto (cgfile, cgbase, "Zone_t", 1, "ZoneBC_t", 1, "BC_t", 1, "BCDataSet_t", 1, NULL) || cg_gridlocation_read (&gridloc) || cg_ptset_info (&pttype, &n)) cg_error_exit(); CHECK("BCDataSet_t name", strcmp(name, "DataSet") == 0); CHECK("BCDataSet_t type", bctype == BCWallViscous); CHECK("BCDataSet_t location", gridloc == KFaceCenter); CHECK("BCDataSet_t pntset type", pttype == PointRange); CHECK("BC_t npnts", n == 2); CHECK("BCDataSet_t dirichlet", dirichlet == 1); CHECK("BCDataSet_t neumann", neumann == 0); /* check user defined data */ puts("checking user defined data"); *name = 0; if (cg_goto (cgfile, cgbase, "UserDefinedData_t", 1, "end") || cg_gridlocation_read (&gridloc) || cg_famname_read (name) || cg_ordinal_read (&ordinal) || cg_narrays (&ndata)) cg_error_exit (); CHECK ("gridlocation", gridloc == CellCenter); CHECK ("famname", strcmp (name, "Family") == 0); CHECK ("ordinal", ordinal == 0); CHECK ("narrays", ndata == 2); if (cg_goto (cgfile, cgbase, "Zone_t", cgzone, "end") || cg_nuser_data (&nuser)) cg_error_exit (); CHECK ("nuserdata", nuser == 4); for (i = 1; i <= 4; i++) { *name = 0; if (cg_goto (cgfile, cgbase, "Zone_t", cgzone, "UserDefinedData_t", i, "end") || cg_gridlocation_read (&gridloc) || cg_famname_read (name) || cg_ordinal_read (&ordinal) || cg_ptset_info (&pttype, &n) || cg_ptset_read (ptlist) || cg_narrays (&ndata) || cg_nuser_data (&nuser)) cg_error_exit (); CHECK ("gridlocation", gridloc == CellCenter); CHECK ("famname", strcmp (name, "Family") == 0); CHECK ("ordinal", ordinal == i); CHECK ("pointtype", pttype == PointList); CHECK ("npoints", n == 1); CHECK ("narrays", ndata == 2); CHECK ("nuserdata", nuser == 3); for (j = 1; j <= 3; j++) { *name = 0; if (cg_goto (cgfile, cgbase, "Zone_t", cgzone, "UserDefinedData_t", i, "UserDefinedData_t", j, "end") || cg_gridlocation_read (&gridloc) || cg_famname_read (name) || cg_ordinal_read (&ordinal) || cg_ptset_info (&pttype, &n) || cg_ptset_read (ptlist) || cg_narrays (&ndata) || cg_nuser_data (&nuser)) cg_error_exit (); CHECK ("gridlocation", gridloc == Vertex); CHECK ("famname", strcmp (name, "Family") == 0); CHECK ("ordinal", ordinal == (i + j)); CHECK ("pointtype", pttype == PointRange); CHECK ("npoints", n == 2); CHECK ("narrays", ndata == 2); CHECK ("nuserdata", nuser == 2); for (n = 1; n <= 2; n++) { if (cg_goto (cgfile, cgbase, "Zone_t", cgzone, "UserDefinedData_t", i, "UserDefinedData_t", j, "DataArray_t", n, "end") || cg_dataclass_read (&dclass) || cg_nunits (&nunits) || cg_unitsfull_read (&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity) || cg_nexponents (&nexps) || cg_expfull_read (exponents)) cg_error_exit (); CHECK ("dataclass", dclass == Dimensional); CHECK ("nunits", nunits == 8); CHECK ("massunits", mass == Kilogram); CHECK ("lengthunits", length == Meter); CHECK ("timeunits", time == Second); CHECK ("tempunits", temp == Kelvin); CHECK ("angleunits", angle == Radian); CHECK ("currentunits", current == Ampere); CHECK ("amountunits", amount == Mole); CHECK ("intensityunits", intensity == Candela); CHECK ("nexponents", nexps == 8); for (n = 0; n < 8; n++) CHECK ("exponents", exponents[n] == (float)n); } } } if (cg_goto (cgfile, cgbase, "Zone_t", cgzone, "UserDefinedData_t", 2, "UserDefinedData_t", 2, "UserDefinedData_t", 2, "UserDefinedData_t", 1, "end") || cg_narrays (&ndata) || cg_nuser_data (&nuser) || cg_array_info (2, name, &dtype, &n, &dim) || cg_array_read (1, &data1) || cg_array_read (2, &data2)) cg_error_exit (); CHECK ("narrays", ndata == 2); CHECK ("nuserdata", nuser == 0); CHECK ("arrayname", strcmp (name, "Data2") == 0); CHECK ("datatype", dtype == RealSingle); CHECK ("ndims", n == 1); CHECK ("dims", dim == 1); CHECK ("data1", data1 == 1.0); CHECK ("data2", data2 == 2.0); /* read partial units/exponents as full */ puts("checking units and exponents"); if (cg_goto(cgfile, cgbase, "UserDefinedData_t", 1, "DataArray_t", 1, NULL) || cg_nunits (&nunits) || cg_unitsfull_read (&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity) || cg_nexponents (&nexps) || cg_expfull_read (exponents)) cg_error_exit (); CHECK ("nunits", nunits == 5); CHECK ("massunits", mass == Kilogram); CHECK ("lengthunits", length == Meter); CHECK ("timeunits", time == Second); CHECK ("tempunits", temp == Kelvin); CHECK ("angleunits", angle == Radian); CHECK ("currentunits", current == 0); CHECK ("amountunits", amount == 0); CHECK ("intensityunits", intensity == 0); CHECK ("nexponents", nexps == 5); for (n = 0; n < 5; n++) CHECK ("exponents", exponents[n] == (float)n); for (n = 6; n < 8; n++) CHECK ("exponents", exponents[n] == (float)0.0); /* read full units/exponents as partial */ if (cg_goto(cgfile, cgbase, "Zone_t", 1, "UserDefinedData_t", 1, "DataArray_t", 1, NULL) || cg_nunits (&nunits) || cg_units_read (&mass, &length, &time, &temp, &angle) || cg_nexponents (&nexps) || cg_exponents_read (exponents)) cg_error_exit (); CHECK ("nunits", nunits == 8); CHECK ("massunits", mass == Kilogram); CHECK ("lengthunits", length == Meter); CHECK ("timeunits", time == Second); CHECK ("tempunits", temp == Kelvin); CHECK ("angleunits", angle == Radian); CHECK ("nexponents", nexps == 8); for (n = 0; n < 5; n++) CHECK ("exponents", exponents[n] == (float)n); puts ("closing file and reopening in modify mode"); cg_close (cgfile); /* delete userdata node */ if (cg_open (fname, CG_MODE_MODIFY, &cgfile)) cg_error_exit (); puts ("deleting user defined data and checking"); if (cg_goto (cgfile, 1, "Zone_t", 1, "UserDefinedData_t", 3, "UserDefinedData_t", 2, "UserDefinedData_t", 1, "end") || cg_nuser_data (&nuser)) cg_error_exit (); CHECK ("nuserdata", nuser == 2); if (cg_delete_node ("User3.2.1.1") || cg_nuser_data (&nuser)) cg_error_exit (); CHECK ("nuserdata", nuser == 1); /* don't compress file on close */ cg_configure(CG_CONFIG_COMPRESS, (void *)0); puts ("closing file"); cg_close (cgfile); return 0; }