// ---------------------- deprecated -------------------- Zone_t Base_t::writeZone( const string& zonename, vector<int>& dims, ZoneType_t type ) { int index; Array<int> adims(dims); int ier = cg_zone_write( getFileID(), getID(), zonename.c_str(), adims, type, &index ); check_error( "Base_t::writeZone", "cg_zone_write", ier ); return Zone_t(push( "Zone_t", index )); }
/*! Writes a new Zone_t * \param zonename Name of the zone * \param nodesize Number of nodes in each direction in structured zones, total nb. of nodes for unstructured * \param cellsize Number of cells in each direction in structured zones, total nb. of cells for unstructured * \param bndrysize Number of boundary vertices in each direction in structured zone, total nb of boundary vertices for unstructured * \param type Type of zone (Structured or Unstructured) * \throw cgns_badargument When the various size vector do not make sense for the given type of zone */ Zone_t Base_t::writeZone( const string& zonename, const vector<int>& nodesize, const vector<int>& cellsize, const vector<int>& bndrysize, ZoneType_t type ) { int physdim = getPhysicalDimension(); //// HERE!!! _-_- We can't call this here file not opened for reading!!! int index, ier; if ( type == Structured ) { if ( nodesize.size() != physdim || cellsize.size() != physdim || bndrysize.size() > 0 ) throw cgns_badargument( "Base_t::writeZone", "Invalid zone sizes" ); Array<int> adims(physdim*3); for ( int i=0 ; i<physdim ; i++ ) { adims[i] = nodesize[i]; adims[i+physdim] = cellsize[i]; adims[i+2*physdim] = 0; } ier = cg_zone_write( getFileID(), getID(), zonename.c_str(), adims, type, &index ); } else { if ( nodesize.size() != 1 || cellsize.size() != 1 || bndrysize.size() > 1 ) throw cgns_badargument( "Base_t::writeZone", "Invalid zone sizes" ); Array<int> adims(3); adims[0] = nodesize[0]; adims[1] = cellsize[0]; adims[2] = (bndrysize.size()>0) ? bndrysize[0] : 0; ier = cg_zone_write( getFileID(), getID(), zonename.c_str(), adims, type, &index ); } check_error( "Base_t::writeZone", "cg_zone_write", ier ); structure_t s = push( "Zone_t", index ); s.set_attribute( "ZoneType", type ); return Zone_t(s); //return Zone_t(push( "Zone_t", index )); }
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; }
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 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_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 }
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; }
int main(int argc, char* argv[]) { int k; int F; int B; int *Z, *E, *S, *A; int *Cx, *Cy, *Cz; int *Fu, *Fv, *Fw; cgsize_t nijk[3]; cgsize_t min, max; double T0,T1; double Tw0,Tw1; double Tr0,Tr1; double t0,t1; initialize(&argc,&argv); Z = (int *)malloc(10*zc*sizeof(int)); E = Z + zc; S = E + zc; A = S + zc; Cx = A + zc; Cy = Cx + zc; Cz = Cy + zc; Fu = Cz + zc; Fv = Fu + zc; Fw = Fv + zc; if (cgp_open("thesis_benchmark.cgns", CG_MODE_WRITE, &F) || cg_base_write(F,"Base",3,3,&B)) cgp_error_exit(); nijk[0] = Nl*ppz; nijk[1] = Nl*ppz; nijk[2] = 0; for(k=0;k<zc;k++) { char zonename[100+1]; sprintf(zonename,"%s %d","Zone",k); if (cg_zone_write(F,B,zonename,nijk,CGNS_ENUMV(Unstructured),&(Z[k])) || cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateX",&(Cx[k])) || cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateY",&(Cy[k])) || cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateZ",&(Cz[k])) || cgp_section_write(F,B,Z[k],"Elements",CGNS_ENUMV(NODE),1,Nl*ppz,0,&(E[k])) || cg_sol_write(F,B,Z[k],"Solution",CGNS_ENUMV(Vertex),&S[k]) || cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumX",&(Fu[k])) || cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumY",&(Fv[k])) || cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumZ",&(Fw[k]))) cgp_error_exit(); if (cg_goto(F,B,zonename,0,NULL) || cg_user_data_write("User Data") || cg_gorel(F, "User Data", 0, NULL) || cgp_array_write("phi",CGNS_ENUMV(RealDouble),1,nijk,&A[k])) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); T0 = MPI_Wtime(); Tw0 = MPI_Wtime(); /* Writes */ MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_coord_write_data(F,B,Z[zones[k]],Cx[zones[k]],&min,&max,x) || cgp_coord_write_data(F,B,Z[zones[k]],Cy[zones[k]],&min,&max,y) || cgp_coord_write_data(F,B,Z[zones[k]],Cz[zones[k]],&min,&max,z)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Coords Write\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fu[zones[k]],&min,&max,u) || cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fv[zones[k]],&min,&max,v) || cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fw[zones[k]],&min,&max,w)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Solutions Write\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cg_goto(F,B,"Zone_t",Z[zones[k]], "UserDefinedData_t",1,NULL) || cgp_array_write_data(A[zones[k]],&min,&max,h)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Arrays Write\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_elements_write_data(F,B,Z[zones[k]],E[zones[k]],min,max,e)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Elements Write\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",((double) sizeof(int))/((double) sizeof(double))*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); Tw1 = MPI_Wtime(); if(comm_rank==0) { printf("Total Write Time=%lf\n",Tw1-Tw0); printf("Total Write Bandwidth=%lf\n",(6.0+((double) sizeof(int))/((double) sizeof(double)))*data_size/(Tw1-Tw0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); cgp_close(F); MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) printf("Close_Time=%lf\n",t1-t0); /*======= *=Reads= *=======*/ if (cgp_open("thesis_benchmark.cgns", CG_MODE_READ, &F)) cgp_error_exit(); MPI_Barrier(MPI_COMM_WORLD); Tr0 = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_coord_read_data(F,B,Z[zones[k]],Cx[zones[k]],&min,&max,x) || cgp_coord_read_data(F,B,Z[zones[k]],Cy[zones[k]],&min,&max,y) || cgp_coord_read_data(F,B,Z[zones[k]],Cz[zones[k]],&min,&max,z)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Coords Read\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fu[zones[k]],&min,&max,u) || cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fv[zones[k]],&min,&max,v) || cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fw[zones[k]],&min,&max,w)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Solutions Read\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cg_goto(F,B,"Zone_t",Z[zones[k]], "UserDefinedData_t",1,NULL) || cgp_array_read_data(A[zones[k]],&min,&max,h)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Arrays Read\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); for(k=0;k<zpp;k++) { min = subzones[k]*Nl+1; max = (subzones[k]+1)*Nl; if (cgp_elements_read_data(F,B,Z[zones[k]],E[zones[k]],min,max,e)) cgp_error_exit(); } MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) { printf("Elements Read\n"); printf("\tTime=%lf\n",t1-t0); printf("\tBandwidth=%lf\n",((double) sizeof(int))/((double) sizeof(double))*data_size/(t1-t0)); } MPI_Barrier(MPI_COMM_WORLD); Tr1 = MPI_Wtime(); if(comm_rank==0) { printf("Total Read Time=%lf\n",Tr1-Tr0); printf("Total Read Bandwidth=%lf\n",(6.0+((double) sizeof(int))/((double) sizeof(double)))*data_size/(Tr1-Tr0)); } MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); cgp_close(F); MPI_Barrier(MPI_COMM_WORLD); t1 = MPI_Wtime(); if(comm_rank==0) printf("Close_Time=%lf\n",t1-t0); MPI_Barrier(MPI_COMM_WORLD); T1 = MPI_Wtime(); if(comm_rank==0) { printf("Total Time=%lf\n",T1-T0); } finalize(); return 0; }
int main(int argc, char* argv[]) { /* Initialize varaibles */ initialize(&argc,&argv); /* Time the creation of a file */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_open\n",comm_rank)) if (cgp_open("benchmark.cgns", CG_MODE_WRITE, &fn)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("File Open", t1-t0); /* Time the creation of a base */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cg_base_write\n",comm_rank)) if (cg_base_write(fn, "Base 1", 3, 3, &B)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("Base Write", t1-t0); /* Time the creation of a zone */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cg_zone_write\n",comm_rank)) if (cg_zone_write(fn, B, "Zone 1", nijk, CGNS_ENUMV(Structured), &Z)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("Zone Write", t1-t0); /* Time the creation of coordinates X */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write X\n",comm_rank)) if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateX",&C)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("Coord X Write", t1-t0); /* Time the write speed of coordinates X */ MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write_data X\n",comm_rank)) if (cgp_coord_write_data(fn,B,Z,C,min,max,x)) cgp_error_exit(); t1 = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); ta = MPI_Wtime(); doTimer("Coord X Write Data", t1-t0); doBandwidth("Coord X Write Data", t1-t0); doBandwidthAgg("Coord X Write Data", ta-t0); /* Time the creation of coordinates Y */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write Y\n",comm_rank)) if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateY",&C)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("Coord Y Write", t1-t0); /* Time the write speed of coordinates Y */ MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write_data Y\n",comm_rank)) if (cgp_coord_write_data(fn,B,Z,C,min,max,y)) cgp_error_exit(); t1 = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); ta = MPI_Wtime(); doTimer("Coord Y Write Data", t1-t0); doBandwidth("Coord Y Write Data", t1-t0); doBandwidthAgg("Coord Y Write Data", ta-t0); /* Time the creation of coordinates Z */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write Z\n",comm_rank)) if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateZ",&C)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("Coord Z Write", t1-t0); /* Time the write speed of coordinates Z */ MPI_Barrier(MPI_COMM_WORLD); t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_coord_write_data Z\n",comm_rank)) if (cgp_coord_write_data(fn,B,Z,C,min,max,z)) cgp_error_exit(); t1 = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); ta = MPI_Wtime(); doTimer("Coord Z Write Data", t1-t0); doBandwidth("Coord Z Write Data", t1-t0); doBandwidthAgg("Coord Z Write Data", ta-t0); /* Time closing of the file */ t0 = MPI_Wtime(); DEBUG_PRINT(("[%d]cgp_close\n",comm_rank)) if (cgp_close(fn)) cgp_error_exit(); t1 = MPI_Wtime(); doTimer("File Close", t1-t0); finalize(); return 0; }
/* override compute function */ int writeToCgns::compute(const char *) { //declarations //---------------------------------------------------------------------------- char port[256]; int nElem; int nConn; int nCoords; int index_file; int ier; //input ports and casts const coDistributedObject* obj; const coDoUnstructuredGrid* inGrid; const coDoIntArr* inInletElementNodes; const coDoIntArr* inOutletElementNodes; const coDoIntArr* inShroudElementNodes; const coDoIntArr* inShroudExtElementNodes; const coDoIntArr* inFrictlessElementNodes; const coDoIntArr* inPsbladeElementNodes; const coDoIntArr* inSsbladeElementNodes; const coDoIntArr* inWallElementNodes; const coDoIntArr* inSsleperiodicElementNodes; const coDoIntArr* inPsleperiodicElementNodes; const coDoIntArr* inSsteperiodicElementNodes; const coDoIntArr* inPsteperiodicElementNodes; const coDoIntArr* inRrinletElementNodes; const coDoIntArr* inRroutletElementNodes; const coDoIntArr* inHubAllElementNodes; const coDoIntArr* inShroudAllElementNodes; const coDoSet* inBoundaryElementFaces; //grid attributes int* tList; int* elem; int* conn; cgsize_t* intHelper; float* xCoord; float* yCoord; float* zCoord; int nPoly; int nCorn; int* corn; int* poly; int ii; int base_i; int baseCFX_i; int zone_i; int zoneCFX_i; int coord_i; int section_i; int tmpCounter; int gElemCounter; int boco_i; cgsize_t* ptrToCgsize; cgsize_t cgsize[3][3]; int nNodesFace; int nElemInlet; int nElemOutlet; int nElemWall; int nElemFrictless; int nElemShroud; int nElemShroudExt; int nElemPsblade; int nElemSsblade; int nElemSsleperiodic; int nElemPsleperiodic; int nElemSsteperiodic; int nElemPsteperiodic; int nElemRrinlet; int nElemRroutlet; int nElemHubAll; int nElemShroudAll; int nNodesInlet; int nNodesOutlet; int nNodesWall; int nNodesFrictless; int nNodesShroud; int nNodesShroudExt; int nNodesPsblade; int nNodesSsblade; int nNodesSsleperiodic; int nNodesPsleperiodic; int nNodesSsteperiodic; int nNodesPsteperiodic; int nNodesRrinlet; int nNodesRroutlet; int nNodesHubAll; int nNodesShroudAll; int nNodesFaceInlet; int nNodesFaceOutlet; int nNodesFaceWall; int nNodesFaceFrictless; int nNodesFaceShroud; int nNodesFaceShroudExt; int nNodesFacePsblade; int nNodesFaceSsblade; int nNodesFaceSsleperiodic; int nNodesFacePsleperiodic; int nNodesFaceSsteperiodic; int nNodesFacePsteperiodic; int nNodesFaceRrinlet; int nNodesFaceRroutlet; int nNodesFaceHubAll; int nNodesFaceShroudAll; int nObjects; const coDistributedObject *const *objSet; //---------------------------------------------------------------------------- // initialize //---------------------------------------------------------------------------- gElemCounter = 0; //---------------------------------------------------------------------------- //get input port and do some type checks //---------------------------------------------------------------------------- //check ports and cast to expected types //grid obj = p_inputPort_grid->getCurrentObject(); if (!obj) { sendError("did not receive object at port %s", p_inputPort_grid->getName()); return FAILURE; } else { inGrid = dynamic_cast<const coDoUnstructuredGrid *>(obj); //check that cast was successful if (!inGrid){ sendError("received wrong object type at port %s", p_inputPort_grid->getName()); return FAILURE; } } //boundary element faces obj = p_inputPort_boundaryElementFaces->getCurrentObject(); if (!obj) { sendInfo("did not receive object at port %s", p_inputPort_boundaryElementFaces->getName()); } else { inBoundaryElementFaces = dynamic_cast<const coDoSet *>(obj); objSet = inBoundaryElementFaces->getAllElements(&nObjects); inInletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[0]); inOutletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[1]); inShroudElementNodes = dynamic_cast<const coDoIntArr *>(objSet[2]); inShroudExtElementNodes = dynamic_cast<const coDoIntArr *>(objSet[3]); inFrictlessElementNodes = dynamic_cast<const coDoIntArr *>(objSet[4]); inPsbladeElementNodes = dynamic_cast<const coDoIntArr *>(objSet[5]); inSsbladeElementNodes = dynamic_cast<const coDoIntArr *>(objSet[6]); inWallElementNodes = dynamic_cast<const coDoIntArr *>(objSet[7]); inSsleperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[8]); inPsleperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[9]); inSsteperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[10]); inPsteperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[11]); inRrinletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[12]); inRroutletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[13]); inHubAllElementNodes = dynamic_cast<const coDoIntArr *>(objSet[14]); inShroudAllElementNodes = dynamic_cast<const coDoIntArr *>(objSet[15]); nNodesInlet = inInletElementNodes->getDimension(1); nNodesOutlet = inOutletElementNodes->getDimension(1); nNodesWall = inWallElementNodes->getDimension(1); nNodesFrictless = inFrictlessElementNodes->getDimension(1); nNodesShroud = inShroudElementNodes->getDimension(1); nNodesShroudExt = inShroudExtElementNodes->getDimension(1); nNodesPsblade = inPsbladeElementNodes->getDimension(1); nNodesSsblade = inSsbladeElementNodes->getDimension(1); nNodesSsleperiodic = inSsleperiodicElementNodes->getDimension(1); nNodesPsleperiodic = inPsleperiodicElementNodes->getDimension(1); nNodesSsteperiodic = inSsteperiodicElementNodes->getDimension(1); nNodesPsteperiodic = inPsteperiodicElementNodes->getDimension(1); nNodesRrinlet = inRrinletElementNodes->getDimension(1); nNodesRroutlet = inRroutletElementNodes->getDimension(1); nNodesHubAll = inHubAllElementNodes->getDimension(1); nNodesShroudAll = inShroudAllElementNodes->getDimension(1); elem = inInletElementNodes->getAddress(); nNodesFaceInlet = *elem; elem = inOutletElementNodes->getAddress(); nNodesFaceOutlet = *elem; elem = inWallElementNodes->getAddress(); nNodesFaceWall = *elem; elem = inFrictlessElementNodes->getAddress(); nNodesFaceFrictless = *elem; elem = inShroudElementNodes->getAddress(); nNodesFaceShroud = *elem; elem = inShroudExtElementNodes->getAddress(); nNodesFaceShroudExt = *elem; elem = inPsbladeElementNodes->getAddress(); nNodesFacePsblade = *elem; elem = inSsbladeElementNodes->getAddress(); nNodesFaceSsblade = *elem; elem = inSsleperiodicElementNodes->getAddress(); nNodesFaceSsleperiodic = *elem; elem = inPsleperiodicElementNodes->getAddress(); nNodesFacePsleperiodic = *elem; elem = inSsteperiodicElementNodes->getAddress(); nNodesFaceSsteperiodic = *elem; elem = inPsteperiodicElementNodes->getAddress(); nNodesFacePsteperiodic = *elem; elem = inRrinletElementNodes->getAddress(); nNodesFaceRrinlet = *elem; elem = inRroutletElementNodes->getAddress(); nNodesFaceRroutlet = *elem; elem = inHubAllElementNodes->getAddress(); nNodesFaceHubAll = *elem; elem = inShroudAllElementNodes->getAddress(); nNodesFaceShroudAll = *elem; nElemInlet = nNodesInlet/nNodesFaceInlet; nElemOutlet = nNodesOutlet/nNodesFaceOutlet; nElemShroud = nNodesShroud/nNodesFaceShroud; nElemShroudExt = nNodesShroudExt/nNodesFaceShroudExt; nElemFrictless = nNodesFrictless/nNodesFaceFrictless; nElemPsblade = nNodesPsblade/nNodesFacePsblade; nElemSsblade = nNodesSsblade/nNodesFaceSsblade; nElemWall = nNodesWall/nNodesFaceWall; nElemSsleperiodic = nNodesSsleperiodic/nNodesFaceSsleperiodic; nElemPsleperiodic = nNodesPsleperiodic/nNodesFacePsleperiodic; nElemSsteperiodic = nNodesSsteperiodic/nNodesFaceSsteperiodic; nElemPsteperiodic = nNodesPsteperiodic/nNodesFacePsteperiodic; nElemRrinlet = nNodesRrinlet/nNodesFaceRrinlet; nElemRroutlet = nNodesRroutlet/nNodesFaceRroutlet; nElemHubAll = nNodesHubAll/nNodesFaceHubAll; nElemShroudAll = nNodesShroudAll/nNodesFaceShroudAll; //check that cast was successful if (!inBoundaryElementFaces){ sendError("received wrong object type at port %s", p_inputPort_boundaryElementFaces->getName()); return FAILURE; } } /* -------------------------------------------------------------------------*/ /* inGrid --> unstructured grid */ /* */ /* start to write inGrid into cgns file */ /* -------------------------------------------------------------------------*/ //write out short info about mesh inGrid->getGridSize(&nElem, &nConn, &nCoords); sendInfo("nElements = %i", nElem); sendInfo("nConnectivities = %i", nConn); sendInfo("nCoordinates = %i", nCoords); //get addresses and type list inGrid->getAddresses(&elem, &conn, &xCoord, &yCoord, &zCoord); if (inGrid->hasTypeList()) { inGrid->getTypeList(&tList); } /* debug output ///////////////////////////////////////////////////////////// */ // //write out type list // if (inGrid->hasTypeList()){ // inGrid->getTypeList(&tList); // for (ii=0;ii<nElem;ii++){ // cout << "tList[" << ii << "]" << "=(" << *(tList+ii) << endl; // } // } // //write out elements // for (ii=0;ii<nElem;ii++){ // cout << "elem[" << ii << "]" << "=(" << *(elem+ii) << endl; // } //write out coordinates // for (ii=0;ii<nCoords;ii++){ // cout << "coord[" << ii << "]" << "=(" << *(xCoord+ii) << "," << *(yCoord+ii) << "," << *(zCoord+ii) << ")" << endl; // } // //write out conectivities // for (ii=0;ii<nConn;ii++){ // cout << "conn[" << ii << "]" << "=(" << *(conn+ii) << endl; // } /* ////////////////////////////////////////////////////////////////////////// */ //write cgns file //---------------------------------------------------------------------------- //open cgns file************************************************************** ier = cg_open(cgns_filebrowser->getValue(), CG_MODE_WRITE, &index_file); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "cgns file opened ..." << endl; // // base // //write base****************************************************************** ier = cg_base_write(index_file, "base", 3, 3, &base_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "base written ..." << endl; // write zones**************************************************************** cgsize[0][0] = nCoords; cgsize[0][1] = nElem; cgsize[0][2] = 0; ptrToCgsize = &cgsize[0][0]; ier = cg_zone_write(index_file, base_i, "runner", ptrToCgsize, CGNS_ENUMV(Unstructured), &zone_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "runner written ..." << endl; // write grid coordinates***************************************************** ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateX", xCoord, &coord_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "coordinate x written ..." << endl; ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateY", yCoord, &coord_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "coordinate y written ..." << endl; ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateZ", zCoord, &coord_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "coordinate z written ..." << endl; //write connectivities for 8-node-hexa grid*********************************** intHelper = new cgsize_t[nConn]; for (ii=0;ii<nConn;ii++){ *(intHelper+ii) = *(conn+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "Elem", CGNS_ENUMV(HEXA_8), \ gElemCounter+1, nElem, 0, intHelper, §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } gElemCounter = gElemCounter + nElem; delete intHelper; cout << "Elem written ..." << endl; //write inlet***************************************************************** elem = inInletElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesInlet]; for (ii=0;ii<nNodesInlet;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "inlet", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemInlet, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemInlet; cout << "inlet written ... " << endl; //write outlet**************************************************************** elem = inOutletElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesOutlet]; for (ii=0;ii<nNodesOutlet;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "outlet", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemOutlet, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemOutlet; cout << "outlet written ... " << endl; //write wall****************************************************************** elem = inWallElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesWall]; for (ii=0;ii<nNodesWall;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "wall", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemWall, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemWall; cout << "wall written ... " << endl; //write frictless************************************************************* elem = inFrictlessElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesFrictless]; for (ii=0;ii<nNodesFrictless;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "frictless", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemFrictless, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemFrictless; cout << "frictless written ... " << endl; //write shroud**************************************************************** elem = inShroudElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesShroud]; for (ii=0;ii<nNodesShroud;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "shroud", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemShroud, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemShroud; cout << "shroud written ... " << endl; //write shroudExt************************************************************* elem = inShroudExtElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesShroudExt]; for (ii=0;ii<nNodesShroudExt;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "shroudExt", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemShroudExt, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemShroudExt; cout << "shroudExt written ... " << endl; //write psblade*************************************************************** elem = inPsbladeElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesPsblade]; for (ii=0;ii<nNodesPsblade;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "psblade", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemPsblade, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemPsblade; cout << "psblade written ... " << endl; //write ssblade*************************************************************** elem = inSsbladeElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesSsblade]; for (ii=0;ii<nNodesSsblade;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "ssblade", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemSsblade, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemSsblade; cout << "ssblade written ... " << endl; //write ssleperiodic********************************************************** elem = inSsleperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesSsleperiodic]; for (ii=0;ii<nNodesSsleperiodic;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "ssleperiodic", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemSsleperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemSsleperiodic; cout << "ssleperiodic written ... " << endl; //write psleperiodic********************************************************** elem = inPsleperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesPsleperiodic]; for (ii=0;ii<nNodesPsleperiodic;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "psleperiodic", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemPsleperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemPsleperiodic; cout << "psleperiodic written ... " << endl; //write ssteperiodic********************************************************** elem = inSsteperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesSsteperiodic]; for (ii=0;ii<nNodesSsteperiodic;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "ssteperiodic", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemSsteperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemSsteperiodic; cout << "ssteperiodic written ... " << endl; //write psteperiodic********************************************************** elem = inPsteperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesPsteperiodic]; for (ii=0;ii<nNodesPsteperiodic;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "psteperiodic", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemPsteperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemPsteperiodic; cout << "psteperiodic written ... " << endl; //write rrinlet*************************************************************** elem = inRrinletElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesRrinlet]; for (ii=0;ii<nNodesRrinlet;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "rrinlet", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemRrinlet, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemRrinlet; cout << "rrinlet written ... " << endl; //write rroutlet************************************************************** elem = inRroutletElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesRroutlet]; for (ii=0;ii<nNodesRroutlet;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "rroutlet", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemRroutlet, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemRroutlet; cout << "rroutlet written ... " << endl; //write hubAll**************************************************************** elem = inHubAllElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesHubAll]; for (ii=0;ii<nNodesHubAll;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "hubAll", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemHubAll, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemHubAll; cout << "hubAll written ... " << endl; //write shroudAll************************************************************* elem = inShroudAllElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesShroudAll]; for (ii=0;ii<nNodesShroudAll;ii++){ *(intHelper+ii) = *(elem+ii); *(intHelper+ii) = *(intHelper+ii)+1; } ier = cg_section_write(index_file, base_i, zone_i, "shroudAll", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemShroudAll, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemShroudAll; cout << "shroudAll written ... " << endl; //write periodic suction****************************************************** elem = inSsleperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesSsleperiodic+nNodesSsteperiodic]; tmpCounter = 0; for (ii=0;ii<nNodesSsleperiodic;ii++){ *(intHelper+tmpCounter) = *(elem+ii); *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1; tmpCounter = tmpCounter + 1; } elem = inSsteperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; for (ii=0;ii<nNodesSsteperiodic;ii++){ *(intHelper+tmpCounter) = *(elem+ii); *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1; tmpCounter = tmpCounter + 1; } ier = cg_section_write(index_file, base_i, zone_i, "periodic_suction", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemSsleperiodic+nElemSsteperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemSsleperiodic + nElemSsteperiodic; cout << "peridic_suction written ... " << endl; //write periodic pressure***************************************************** elem = inPsleperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; intHelper = new cgsize_t[nNodesPsleperiodic+nNodesPsteperiodic]; tmpCounter = 0; for (ii=0;ii<nNodesPsleperiodic;ii++){ *(intHelper+tmpCounter) = *(elem+ii); *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1; tmpCounter = tmpCounter + 1; } elem = inPsteperiodicElementNodes->getAddress(); //increment nodes elem = elem+1; for (ii=0;ii<nNodesPsteperiodic;ii++){ *(intHelper+tmpCounter) = *(elem+ii); *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1; tmpCounter = tmpCounter + 1; } ier = cg_section_write(index_file, base_i, zone_i, "periodic_pressure", CGNS_ENUMV(QUAD_4), \ gElemCounter+1, gElemCounter+nElemPsleperiodic+nElemPsteperiodic, 0, intHelper, \ §ion_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } delete intHelper; gElemCounter = gElemCounter + nElemPsleperiodic + nElemPsteperiodic; cout << "peridic pressure written ... " << endl; // // baseCFX // //write base****************************************************************** ier = cg_base_write(index_file, "baseCFX", 3, 3, &baseCFX_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "baseCFX written ..." << endl; // write zones**************************************************************** cgsize[0][0] = nCoords; cgsize[0][1] = nElem; cgsize[0][2] = 0; ptrToCgsize = &cgsize[0][0]; ier = cg_zone_write(index_file, baseCFX_i, "runner", ptrToCgsize, CGNS_ENUMV(Unstructured), &zone_i); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "runner written ..." << endl; ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("GridCoordinates", "", "/base/runner/GridCoordinates"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "coordinates linked ..." << endl; //connectivities ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("Elem", "", "/base/runner/Elem"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "Elem linked ..." << endl; //write inlet***************************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("inlet", "", "/base/runner/inlet"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "inlet linked ..." << endl; //write outlet**************************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("outlet", "", "/base/runner/outlet"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "outlet linked ..." << endl; //write psblade*************************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("blade_pressure", "", "/base/runner/psblade"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "psblade linked ..." << endl; //write ssblade*************************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("blade_suction", "", "/base/runner/ssblade"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "ssblade linked ..." << endl; //write hubAll**************************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("hub", "", "/base/runner/hubAll"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "hubAll linked ..." << endl; //write shroudAll************************************************************* ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("shroud", "", "/base/runner/shroudAll"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "shroudAll linked ..." << endl; //write periodic suction****************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("periodic_suction", "", "/base/runner/periodic_suction"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "periodic_suction linked ..." << endl; //write periodic pressure***************************************************** ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } ier = cg_link_write("periodic_pressure", "", "/base/runner/periodic_pressure"); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } cout << "periodic_pressure linked ..." << endl; //close cgns file************************************************************* ier = cg_close(index_file); if(ier) { sendError("%s", cg_get_error()); return FAILURE; } //---------------------------------------------------------------------------- sendInfo("grid successfully converted to cgns"); return SUCCESS; }
void COutput::SetCGNS_Connectivity(CConfig *config, CGeometry *geometry, unsigned short iZone) { #ifndef NO_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, N; bool compressible = (config->GetKind_Regime() == COMPRESSIBLE); bool incompressible = (config->GetKind_Regime() == INCOMPRESSIBLE); bool freesurface = (config->GetKind_Regime() == FREESURFACE); /*--- Create CGNS base file name ---*/ base_file = config->GetFlow_FileName(); #ifndef NO_MPI /*--- Remove the domain number from the CGNS filename ---*/ int nProcessor; #ifdef WINDOWS MPI_Comm_size(MPI_COMM_WORLD,&nProcessor); #else nProcessor = MPI::COMM_WORLD.Get_size(); #endif if (nProcessor > 1) base_file.erase (base_file.end()-2, base_file.end()); #endif /*--- Add CGNS extension. ---*/ base_file = base_file.append(".cgns"); /*--- Create CGNS results file name ---*/ if (unsteady) { buffer = config->GetFlow_FileName(); #ifndef NO_MPI /*--- Remove the domain number from the CGNS filename ---*/ if (nProcessor > 1) buffer.erase (buffer.end()-2, buffer.end()); #endif 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 (release 2.0) only all-2D or all-3D zones permitted physical_dims = element_dims; /*--- write CGNS base data (one base assumed as of version 3.1.0 "eagle") ---*/ cgns_err = cg_base_write(cgns_file,"SU^2 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(); if (compressible) { 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","SU^2 version 3.1.0 \"eagle\", Stanford University Aerospace Design Lab"); if (cgns_err) cg_error_print(); isize[0][0] = geometry->GetGlobal_nPointDomain(); //; // vertex size isize[1][0] = 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,"SU^2 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; N = (int)nGlobal_Tria*N_POINTS_TRIANGLE; 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; N = (int)nGlobal_Quad*N_POINTS_QUADRILATERAL; 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; N = (int)nGlobal_Tetr*N_POINTS_TETRAHEDRON; 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; N = (int)nGlobal_Hexa*N_POINTS_HEXAHEDRON; 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; N = (int)nGlobal_Pyra*N_POINTS_PYRAMID; 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_Wedg > 0) { elem_start = 1; elem_end = (int)nGlobal_Wedg; N = (int)nGlobal_Wedg*N_POINTS_WEDGE; cgns_err = cg_section_write(cgns_file,cgns_base,cgns_zone,"Wedge Elements",PENTA_6, elem_start,elem_end,0,(cgsize_t *)Conn_Wedg,&cgns_section); } if (nGlobal_Line > 0) { elem_start = 1; elem_end = (int)nGlobal_Line; N = (int)nGlobal_Line*N_POINTS_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 SU^2 was built without CGNS support. No file written" << "\n"; #endif }