45 MPI_Init( &argc, &argv);
48 cout <<
"Usage: " << argv[0]
49 <<
" <fname><niter>" << endl;
64 string fname(argv[1]);
65 int niter = atoi(argv[2]);
67 const int nameSize = 33;
76 SimulationType_t sType;
78 const char* _3DUnstructInfo[3] =
79 {
"NVertex",
"NCell3D",
"NBoundVertex"};
81 std::cout <<
"Opening file: " << fname.c_str() <<
"\n";
84 if(cg_open(fname.c_str(), MODE_MODIFY, &file_hdl))
88 if(cg_nbases(file_hdl,&nbases))
92 cout <<
"Error: .cgns files with multiple bases not supported.\n";
97 std::cout <<
"File opened successfully.\n";
101 if(cg_base_read(file_hdl, i, bName,&bCellDim, &bPhysDim))
104 std::cout <<
"Checking mesh format.\n";
107 cout <<
"Error: Only volume meshes are supported by this utility.\n";
112 if(cg_nzones(file_hdl, i, &nzones))
118 cout <<
"Error: .cgns files with multiple zones not supported by this utility.\n";
124 if(cg_zone_type(file_hdl, i, j, &zType))
127 if(zType != Unstructured){
128 cout <<
"Error: only structured meshes supported by this utility.\n";
132 if(cg_zone_read(file_hdl, i, j, zName, &sizes[0]))
135 for(
int k = 0;
k < 3; ++
k)
136 cout << _3DUnstructInfo[
k] <<
" = " << sizes[
k] <<
"\n";
138 if(zType == Structured){
139 cout <<
"Error: this utility does not supoort structured meshes.\n";
145 if(cg_ngrids(file_hdl, i, j, &nGrids))
149 cout <<
"Erorr: this utility only supports files with 1 grid\n";
154 if(cg_ncoords(file_hdl,i,j,&ncoords))
158 cout <<
"Error: this utility only supports meshes with 3 coordinate components\n";
162 int nnodes = sizes[0];
163 std::vector<double> coord_data(3*nnodes);
165 for(
int k=1;
k<=ncoords; ++
k){
168 char coordName[nameSize];
169 if(cg_coord_info(file_hdl, i, j,
k, &dataType, &coordName[0]))
172 if(dataType != RealDouble){
173 std::cout <<
"Error: this utility only supports mesh coordinates of CGNS type RealDouble\n";
177 int ranges[2] = {1,nnodes};
178 if(cg_coord_read(file_hdl,i,j,&coordName[0],dataType,&ranges[0],
179 &ranges[1],&coord_data[(
k-1)*nnodes]))
185 if(cg_nsections(file_hdl, i, j, &nConns))
188 char cName[nameSize];
190 int rmin_elems, rmax_elems, nbnrdy, parent_flag;
194 for(
int k=1;
k<nConns; ++
k){
196 if(cg_section_read(file_hdl, i, j,
k, &cName[0], &eType,
197 &rmin_elems, &rmax_elems, &nbnrdy, &parent_flag))
211 cout <<
"Error: the parent flag is set, and this utility does not "
212 <<
"support meshes with parent data.\n";
217 if(eType == TETRA_4){
231 if(cg_ElementDataSize(file_hdl, i, j,
k, &nElems))
237 std::vector<int> conn_data(nElems*nodes_pe,-1);
238 std::vector<int> temp_conn(nElems*nodes_pe,-2);
243 std::vector<int> cgns_to_roccom(nnodes,-1);
246 if(cg_elements_read(file_hdl, i, j,
k, &conn_data[0], &parent_data[0]))
249 cout <<
"Found a tetrahedral zone with " << nElems <<
" elements\n";
255 for(
int ii=0; ii< nElems; ++ii){
256 for(
int jj=0; jj< nodes_pe; ++jj){
257 int old_node_ind = conn_data[ii*nodes_pe + jj]-1;
258 if(cgns_to_roccom[old_node_ind] == -1)
259 cgns_to_roccom[old_node_ind] = used_nodes++;
260 temp_conn[ii*nodes_pe + jj] = cgns_to_roccom[old_node_ind]+1;
265 std::vector<int>().
swap(conn_data);
270 std::vector<double> temp_coords(used_nodes*3,-3);
271 std::vector<int> roccom_to_cgns(used_nodes,-4);
276 for(
int ii =0; ii<nnodes; ++ii){
277 if(cgns_to_roccom[ii] != -1){
278 int node_ind = cgns_to_roccom[ii];
279 temp_coords[node_ind*3] = coord_data[ii];
280 temp_coords[node_ind*3+1] = coord_data[ii+nnodes];
281 temp_coords[node_ind*3+2] = coord_data[ii+2*nnodes];
286 if(cg_close(file_hdl))
290 cout <<
"Initializing smoothing data structures\n";
307 cout <<
"Writing initial mesh configuration\n";
309 "unstr_temp",
"001");
313 double min_angle = 190, max_angle=0;
315 cout <<
"Initial dihedral angle range = ( " << min_angle <<
" , " << max_angle <<
" )\n";
316 cout <<
"Beginning mesh optimizaton\n";
318 cout << setiosflags(std::ios::left);
319 cout << std::setw(15) <<
"iteration" << std::setw(20) <<
"min dihedral "
320 << std::setw(20) <<
"max dihedral " << endl;
321 cout << std::setw(55) << std::setfill(
'-') <<
"" << endl;
322 cout << std::setfill(
' ');
329 for(
int ii =0; ii< niter; ++ii){
335 cout << std::setw(15) << ii+1 << std::setw(20) << min_angle
336 << std::setw(20) << max_angle <<
"\n";
342 cout <<
"Writing out smoothed configuration\n";
344 "unstr_temp",
"001");
350 for(
int ii =0; ii<nnodes; ++ii){
351 if(cgns_to_roccom[ii] != -1){
352 int node_ind = cgns_to_roccom[ii];
353 coord_data[ii] = temp_coords[node_ind*3];
354 coord_data[ii+nnodes] = temp_coords[node_ind*3+1];
355 coord_data[ii+2*nnodes] = temp_coords[node_ind*3+2];
360 if(cg_open(fname.c_str(), MODE_MODIFY, &file_hdl))
363 cout <<
"Writing updated coordinates to .cgns file\n";
364 for(
int ii= 1; ii<=3; ++ii){
369 if(cg_coord_info(file_hdl, i, j, ii, &dataType, &coordName[0]))
372 if(cg_coord_write(file_hdl,i,j,RealDouble,coordName,
373 &coord_data[(ii-1)*nnodes], &coord_ind))
376 assert(coord_ind == ii);
383 if(cg_close(file_hdl))
void swap(int &a, int &b)
void COM_set_size(const char *wa_str, int pane_id, int size, int ng=0)
Set sizes of for a specific attribute.
A Roccom mesh optimization module.
int COM_get_attribute_handle(const char *waname)
void COM_window_init_done(const char *w_str, int pane_changed=true)
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
void COM_call_function(const int wf, int argc,...)
void COM_set_array(const char *wa_str, int pane_id, void *addr, int strd=0, int cap=0)
Associates an array with an attribute for a specific pane.
void COM_init(int *argc, char ***argv)
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
int COM_get_function_handle(const char *wfname)