Exemplo n.º 1
0
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
  
}
Exemplo n.º 2
0
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
  
}