Пример #1
0
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()
{
/*
  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 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;
}
Пример #4
0
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
  
}
Пример #5
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;
	}