38 #include <boost/thread.hpp> 39 #include <boost/algorithm/string.hpp> 55 "Reads mesh configuration and will generate the mesh file.");
70 vector<string> filename;
71 filename.push_back(nm);
73 char *prgname = (
char*)
"NekMesh";
76 pSession->InitSession();
78 auto comm = pSession->GetComm();
79 if (comm->GetType().find(
"MPI") != std::string::npos)
84 ASSERTL0(pSession->DefinesElement(
"NEKTAR/MESHING"),
"no meshing tag");
85 ASSERTL0(pSession->DefinesElement(
"NEKTAR/MESHING/INFORMATION"),
86 "no information tag");
87 ASSERTL0(pSession->DefinesElement(
"NEKTAR/MESHING/PARAMETERS"),
90 TiXmlElement *mcf = pSession->GetElement(
"NEKTAR/MESHING");
95 m_mesh->m_metadata[
"XML_NekMeshMCF"] = ss.str();
97 TiXmlElement *info = mcf->FirstChildElement(
"INFORMATION");
98 TiXmlElement *I = info->FirstChildElement(
"I");
99 map<string, string> information;
103 I->QueryStringAttribute(
"PROPERTY", &tmp1);
104 I->QueryStringAttribute(
"VALUE", &tmp2);
105 information[tmp1] = tmp2;
106 I = I->NextSiblingElement(
"I");
109 TiXmlElement *param = mcf->FirstChildElement(
"PARAMETERS");
110 TiXmlElement *
P = param->FirstChildElement(
"P");
111 map<string, string> parameters;
115 P->QueryStringAttribute(
"PARAM", &tmp1);
116 P->QueryStringAttribute(
"VALUE", &tmp2);
117 parameters[tmp1] = tmp2;
118 P = P->NextSiblingElement(
"P");
121 set<string> boolparameters;
123 if (pSession->DefinesElement(
"NEKTAR/MESHING/BOOLPARAMETERS"))
125 TiXmlElement *bparam = mcf->FirstChildElement(
"BOOLPARAMETERS");
126 TiXmlElement *BP = bparam->FirstChildElement(
"P");
131 BP->QueryStringAttribute(
"VALUE", &tmp);
132 boolparameters.insert(tmp);
133 BP = BP->NextSiblingElement(
"P");
137 set<string> refinement;
138 if (pSession->DefinesElement(
"NEKTAR/MESHING/REFINEMENT"))
140 TiXmlElement *refine = mcf->FirstChildElement(
"REFINEMENT");
141 TiXmlElement *
L = refine->FirstChildElement(
"LINE");
146 TiXmlElement *T = L->FirstChildElement(
"X1");
147 ss << T->GetText() <<
",";
148 T = L->FirstChildElement(
"Y1");
149 ss << T->GetText() <<
",";
150 T = L->FirstChildElement(
"Z1");
151 ss << T->GetText() <<
",";
152 T = L->FirstChildElement(
"X2");
153 ss << T->GetText() <<
",";
154 T = L->FirstChildElement(
"Y2");
155 ss << T->GetText() <<
",";
156 T = L->FirstChildElement(
"Z2");
157 ss << T->GetText() <<
",";
158 T = L->FirstChildElement(
"R");
159 ss << T->GetText() <<
",";
160 T = L->FirstChildElement(
"D");
163 refinement.insert(ss.str());
165 L = L->NextSiblingElement(
"LINE");
169 set<string> periodic;
170 if (pSession->DefinesElement(
"NEKTAR/MESHING/PERIODIC"))
172 TiXmlElement *per = mcf->FirstChildElement(
"PERIODIC");
173 TiXmlElement *pair = per->FirstChildElement(
"P");
178 pair->QueryStringAttribute(
"PAIR", &tmp);
179 periodic.insert(tmp);
180 pair = pair->NextSiblingElement(
"P");
184 auto it = information.find(
"CADFile");
185 ASSERTL0(it != information.end(),
"no cadfile defined");
188 it = information.find(
"MeshType");
189 ASSERTL0(it != information.end(),
"no meshtype defined");
192 m_makeBL = it->second ==
"3DBndLayer";
193 m_2D = it->second ==
"2D";
196 if (it->second ==
"2DBndLayer")
204 ASSERTL0(it->second ==
"3D",
"unsure on MeshType")
207 it = parameters.find(
"MinDelta");
208 ASSERTL0(it != parameters.end(),
"no mindelta defined");
211 it = parameters.find(
"MaxDelta");
212 ASSERTL0(it != parameters.end(),
"no maxdelta defined");
215 it = parameters.find(
"EPS");
216 ASSERTL0(it != parameters.end(),
"no eps defined");
219 it = parameters.find(
"Order");
220 ASSERTL0(it != parameters.end(),
"no order defined");
225 it = parameters.find(
"BndLayerSurfaces");
226 ASSERTL0(it != parameters.end(),
"no BndLayersurfs defined");
229 it = parameters.find(
"BndLayerThickness");
230 ASSERTL0(it != parameters.end(),
"no BndLayerthick defined");
233 it = parameters.find(
"BndLayerLayers");
238 it = parameters.find(
"BndLayerProgression");
239 m_blprog = it != parameters.end() ? it->second :
"2.0";
242 it = parameters.find(
"BndLayerAdjustment");
243 if (it != parameters.end())
253 it = parameters.find(
"SpaceOutBndLayer");
254 if (it != parameters.end())
259 it = parameters.find(
"NoSpaceOutSurf");
260 if (it != parameters.end())
276 if (
m_2D && m_cadfile.find(
'.') == std::string::npos)
281 it = parameters.find(
"Xmin");
282 ASSERTL0(it != parameters.end(),
"no xmin defined");
283 ss << it->second <<
",";
284 it = parameters.find(
"Ymin");
285 ASSERTL0(it != parameters.end(),
"no ymin defined");
286 ss << it->second <<
",";
287 it = parameters.find(
"Xmax");
288 ASSERTL0(it != parameters.end(),
"no xmax defined");
289 ss << it->second <<
",";
290 it = parameters.find(
"Ymax");
291 ASSERTL0(it != parameters.end(),
"no zmax defined");
292 ss << it->second <<
",";
293 it = parameters.find(
"AOA");
294 ASSERTL0(it != parameters.end(),
"no aoa defined");
300 auto sit = boolparameters.find(
"SurfaceOptimiser");
302 sit = boolparameters.find(
"WriteOctree");
303 m_woct = sit != boolparameters.end();
304 sit = boolparameters.find(
"VariationalOptimiser");
306 sit = boolparameters.find(
"BndLayerAdjustEverywhere");
308 sit = boolparameters.find(
"SmoothBndLayer");
315 for (sit = refinement.begin(); sit != refinement.end(); sit++)
324 if (periodic.size() > 0)
327 for (sit = periodic.begin(); sit != periodic.end(); ++sit)
350 module->RegisterConfig(
"filename",
m_cadfile);
353 module->RegisterConfig(
"verbose",
"");
357 module->RegisterConfig(
"2D",
"");
366 module->RegisterConfig(
"CFIMesh",
"");
369 module->SetDefaults();
379 module->RegisterConfig(
"eps",
m_eps);
386 module->RegisterConfig(
"writeoctree",
"");
389 module->SetDefaults();
403 module->RegisterConfig(
"blcurves",
m_blsurfs);
404 module->RegisterConfig(
"blthick",
m_blthick);
412 module->RegisterConfig(
"adjustblteverywhere",
"");
418 module->RegisterConfig(
"smoothbl",
"");
429 module->RegisterConfig(
"periodic",
m_periodic);
434 module->SetDefaults();
437 catch (runtime_error &e)
439 cout <<
"2D linear mesh generator failed with message:" << endl;
440 cout << e.what() << endl;
441 cout <<
"No mesh file has been created" << endl;
454 module->SetDefaults();
465 module->SetDefaults();
468 catch (runtime_error &e)
470 cout <<
"Surface meshing has failed with message:" << endl;
471 cout << e.what() << endl;
472 cout <<
"Any surfaces which were succsessfully meshed will be " 473 "dumped as a manifold mesh" 496 module->RegisterConfig(
"blsurfs",
m_blsurfs);
497 module->RegisterConfig(
"blthick",
m_blthick);
498 module->RegisterConfig(
"bllayers",
m_bllayers);
499 module->RegisterConfig(
"blprog",
m_blprog);
504 module->SetDefaults();
507 catch (runtime_error &e)
509 cout <<
"Volume meshing has failed with message:" << endl;
510 cout << e.what() << endl;
511 cout <<
"The linear surface mesh be dumped as a manifold " 515 m_mesh->m_element[3].clear();
532 module->RegisterConfig(
"opti",
"");
537 module->SetDefaults();
540 catch (runtime_error &e)
542 cout <<
"High-order surface meshing has failed with message:" << endl;
543 cout << e.what() << endl;
544 cout <<
"The mesh will be written as normal but the incomplete surface " 545 "will remain faceted" 553 unsigned int np = boost::thread::physical_concurrency();
556 cout <<
"Detecting 4 cores, will attempt to run in parrallel" 561 module->RegisterConfig(
"hyperelastic",
"");
562 module->RegisterConfig(
"maxiter",
"10");
563 module->RegisterConfig(
"numthreads", boost::lexical_cast<string>(np));
567 module->SetDefaults();
570 catch (runtime_error &e)
572 cout <<
"Variational optimisation has failed with message:" << endl;
573 cout << e.what() << endl;
574 cout <<
"The mesh will be written as is, it may be invalid" << endl;
585 module->RegisterConfig(
"surf",
m_blsurfs);
586 module->RegisterConfig(
"nq",
587 boost::lexical_cast<string>(
m_mesh->m_nummode));
588 module->RegisterConfig(
"r",
m_blprog);
592 module->SetDefaults();
595 catch (runtime_error &e)
597 cout <<
"Boundary layer splitting has failed with message:" << endl;
598 cout << e.what() << endl;
599 cout <<
"The mesh will be written as is, it may be invalid" << endl;
605 for (
auto &it :
m_mesh->m_composite)
610 string name = el->m_parentCAD->GetName();
613 m_mesh->m_faceLabels.insert(
614 make_pair(el->GetTagList()[0],
name));
623 vector<string> lines;
624 boost::split(lines,
m_periodic, boost::is_any_of(
":"));
626 for (
auto &il : lines)
631 vector<string> tmp(2);
632 boost::split(tmp, il, boost::is_any_of(
","));
633 module->RegisterConfig(
"surf1", tmp[0]);
634 module->RegisterConfig(
"surf2", tmp[1]);
636 module->SetDefaults();
#define ASSERTL0(condition, msg)
std::shared_ptr< Module > ModuleSharedPtr
MeshSharedPtr m_mesh
Mesh object.
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::pair< ModuleType, std::string > ModuleKey
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
std::shared_ptr< Element > ElementSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< SessionReader > SessionReaderSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
ModuleFactory & GetModuleFactory()