40 #include <boost/algorithm/string.hpp> 62 true,
"0",
"If defined then assume input rea is for scalar problem");
84 int nParam, nElements, nCurves;
85 int i, j, k, nodeCounter = 0;
89 map<LibUtilities::ShapeType, int> domainComposite;
90 map<LibUtilities::ShapeType, vector<vector<NodeSharedPtr> > > elNodes;
91 map<LibUtilities::ShapeType, vector<int> > elIds;
92 std::unordered_map<int, int> elMap;
93 vector<LibUtilities::ShapeType> elmOrder;
95 bool scalar =
m_config[
"scalar"].as<
bool>();
111 cout <<
"InputNek: Start reading file..." << endl;
117 for (i = 0; i < 4; ++i)
122 stringstream s(line);
125 for (i = 0; i < nParam; ++i)
138 for (i = 0; i < j; ++i)
148 for (i = 0; i < j; ++i)
156 bool foundMesh =
false;
160 if (line.find(
"MESH") != string::npos)
169 cerr <<
"Couldn't find MESH tag inside file." << endl;
177 s >> nElements >>
m_mesh->m_expDim;
181 m_mesh->m_fields.push_back(
"u");
185 m_mesh->m_fields.push_back(
"v");
186 if (
m_mesh->m_spaceDim > 2)
188 m_mesh->m_fields.push_back(
"w");
190 m_mesh->m_fields.push_back(
"p");
194 for (i = 0; i < nElements; ++i)
198 if (
m_mesh->m_expDim == 2)
200 if (line.find(
"Qua") != string::npos ||
201 line.find(
"qua") != string::npos)
213 if (line.find(
"Tet") != string::npos ||
214 line.find(
"tet") != string::npos)
218 else if (line.find(
"Hex") != string::npos ||
219 line.find(
"hex") != string::npos)
223 else if (line.find(
"Prism") != string::npos ||
224 line.find(
"prism") != string::npos)
228 else if (line.find(
"Pyr") != string::npos ||
229 line.find(
"pyr") != string::npos)
233 else if (line.find(
"Qua") != string::npos ||
234 line.find(
"qua") != string::npos)
248 for (j = 0; j <
m_mesh->m_expDim; ++j)
253 for (k = 0; k < nNodes; ++k)
260 for (j =
m_mesh->m_expDim; j < 3; ++j)
262 for (k = 0; k < nNodes; ++k)
271 vector<NodeSharedPtr> nodeList;
272 for (k = 0; k < nNodes; ++k)
275 nodeCounter++, vertex[0][k], vertex[1][k], vertex[2][k]));
276 nodeList.push_back(n);
279 elNodes[elType].push_back(nodeList);
280 elIds[elType].push_back(i);
286 for (i = 0; i < elmOrder.size(); ++i)
289 vector<vector<NodeSharedPtr> > &tmp = elNodes[elType];
291 for (j = 0; j < tmp.size(); ++j)
294 auto compIt = domainComposite.find(elType);
295 if (compIt == domainComposite.end())
297 tags.push_back(nComposite);
298 domainComposite[elType] = nComposite;
303 tags.push_back(compIt->second);
306 elMap[elIds[elType][j]] = reorderedId++;
308 vector<NodeSharedPtr> nodeList = tmp[j];
310 for (k = 0; k < nodeList.size(); ++k)
312 auto testIns =
m_mesh->m_vertexSet.insert(nodeList[k]);
316 nodeList[k] = *(testIns.first);
320 nodeList[k]->m_id = nodeCounter++;
327 elType, conf, nodeList, tags);
328 m_mesh->m_element[E->GetDim()].push_back(E);
334 if (line.find(
"CURVE") == string::npos)
336 cerr <<
"Cannot find curved side data." << endl;
350 for (i = 0; i < nCurves; ++i)
363 s >> word >> curveTag;
366 else if (word ==
"Recon")
372 s >> word >> curveTag;
377 cerr <<
"Unsupported curve type " << word << endl;
389 if (line.find(
"side") == string::npos)
391 cerr <<
"Unable to read number of curved sides" << endl;
404 for (i = 0; i < nCurvedSides; ++i)
409 s >> faceId >> elId >> word;
411 elId = elMap[elId - 1];
414 int origFaceId = faceId;
418 std::shared_ptr<Prism>
p =
419 std::dynamic_pointer_cast<
Prism>(el);
420 if (p->m_orientation == 1)
422 faceId = (faceId + 2) % 6;
424 else if (p->m_orientation == 2)
426 faceId = (faceId + 4) % 6;
431 std::shared_ptr<Tetrahedron> t =
439 cerr <<
"Unrecognised curve tag " << word <<
" in curved lines" 444 if (it->second.first ==
eRecon)
447 vector<NodeSharedPtr> &tmp = el->GetFace(faceId)->m_vertexList;
448 vector<Node> n(tmp.size());
455 std::dynamic_pointer_cast<
Prism>(el)->m_orientation;
462 for (j = 0; j < tmp.size(); ++j)
470 for (j = 0; j < tmp.size(); ++j)
478 for (j = 0; j < tmp.size(); ++j)
483 for (j = 0; j < tmp.size(); ++j)
485 int id = tmp[(j + offset) % tmp.size()]->m_id;
486 auto vIt =
m_mesh->m_vertexNormals.find(
id);
488 if (vIt ==
m_mesh->m_vertexNormals.end())
490 m_mesh->m_vertexNormals[id] = n[j];
496 m_mesh->m_spherigonSurfs.insert(make_pair(elId, faceId));
498 else if (it->second.first ==
eFile)
501 static int tetFaceVerts[4][3] = {
502 {0, 1, 2}, {0, 1, 3}, {1, 2, 3}, {0, 2, 3}};
504 vector<int> vertId(3);
505 s >> vertId[0] >> vertId[1] >> vertId[2];
512 std::shared_ptr<Tetrahedron> tet =
514 vector<int> tmpVertId = vertId;
516 for (j = 0; j < 3; ++j)
520 [tetFaceVerts[origFaceId][j]])
523 for (k = 0; k < 3; ++k)
525 int w = f->m_vertexList[k]->m_id;
528 vertId[k] = tmpVertId[j];
536 std::shared_ptr<Prism> pr =
537 std::static_pointer_cast<
Prism>(el);
538 if (pr->m_orientation == 1)
540 swap(vertId[2], vertId[1]);
541 swap(vertId[0], vertId[1]);
543 else if (pr->m_orientation == 2)
545 swap(vertId[0], vertId[1]);
546 swap(vertId[2], vertId[1]);
551 std::shared_ptr<HOSurf>(
new HOSurf(vertId));
553 auto hoIt =
hoData[word].find(hs);
555 if (hoIt ==
hoData[word].end())
557 cerr <<
"Unable to find high-order surface data " 558 <<
"for element id " << elId + 1 << endl;
568 int Ntot = (*hoIt)->surfVerts.size();
569 int N = ((int)sqrt(8.0 * Ntot + 1.0) - 1) / 2;
574 vector<NodeSharedPtr> tmpVerts = (*hoIt)->surfVerts;
575 for (j = 0; j < tmpVerts.size(); ++j)
577 (*hoIt)->surfVerts[
hoMap[j]] = tmpVerts[j];
580 for (j = 0; j < tmpVerts.size(); ++j)
585 vector<int> faceVertIds(3);
586 faceVertIds[0] = f->m_vertexList[0]->m_id;
587 faceVertIds[1] = f->m_vertexList[1]->m_id;
588 faceVertIds[2] = f->m_vertexList[2]->m_id;
590 for (j = 0; j < f->m_edgeList.size(); ++j)
592 edge = f->m_edgeList[j];
596 if (edge->m_edgeNodes.size() > 0)
604 for (
int k = 0; k < N - 2; ++k)
606 edge->m_edgeNodes.push_back(
607 (*hoIt)->surfVerts[3 + j * (N - 2) + k]);
613 if (edge->m_n1->m_id != faceVertIds[j])
615 reverse(edge->m_edgeNodes.begin(),
616 edge->m_edgeNodes.end());
622 for (
int j = 3 + 3 * (N - 2); j < Ntot; ++j)
624 f->m_faceNodes.push_back((*hoIt)->surfVerts[j]);
636 map<int, vector<pair<int, LibUtilities::ShapeType> > > surfaceCompMap;
649 if (line.find(
"*") != string::npos ||
m_mshFile.eof() ||
660 s >> bcType >> elId >> faceId;
662 elId = elMap[elId - 1];
665 vector<ConditionType> type;
671 if ((elm->GetDim() == 2 && faceId >= elm->GetEdgeCount()) ||
672 (elm->GetDim() == 3 && faceId >= elm->GetFaceCount()))
692 for (i = 0; i <
m_mesh->m_fields.size() - 1; ++i)
712 size_t p = line.find_first_of(
'=');
714 boost::algorithm::trim_copy(line.substr(p + 1)));
719 for (i = 0; i <
m_mesh->m_fields.size() - 1; ++i)
722 size_t p = line.find_first_of(
'=');
724 boost::algorithm::trim_copy(line.substr(p + 1)));
745 for (i = 0; i <
m_mesh->m_fields.size(); ++i)
766 cerr <<
"Unknown boundary condition type " << line[0] << endl;
771 c->field =
m_mesh->m_fields;
779 auto it =
m_mesh->m_condition.begin();
780 for (; it !=
m_mesh->m_condition.end(); ++it)
789 int compTag, conditionId;
796 if (elm->GetDim() == 3)
802 std::shared_ptr<Prism>
p =
803 std::dynamic_pointer_cast<
Prism>(elm);
804 if (p->m_orientation == 1)
806 faceId = (faceId + 2) % 6;
808 else if (p->m_orientation == 2)
810 faceId = (faceId + 4) % 6;
815 std::shared_ptr<Tetrahedron> t =
821 bool tri = f->m_vertexList.size() == 3;
823 vector<NodeSharedPtr> nodeList;
824 nodeList.insert(nodeList.begin(),
825 f->m_vertexList.begin(),
826 f->m_vertexList.end());
838 for (
int i = 0; i < f->m_vertexList.size(); ++i)
840 surfEl->GetEdge(i)->m_edgeNodes = f->m_edgeList[i]->m_edgeNodes;
841 surfEl->GetEdge(i)->m_curveType = f->m_edgeList[i]->m_curveType;
844 else if (faceId < elm->GetEdgeCount())
848 vector<NodeSharedPtr> nodeList;
849 nodeList.push_back(f->m_n1);
850 nodeList.push_back(f->m_n2);
876 conditionId =
m_mesh->m_condition.size();
877 compTag = nComposite;
878 c->m_composite.push_back(compTag);
879 m_mesh->m_condition[conditionId] = c;
881 surfaceCompMap[conditionId].push_back(
882 pair<int, LibUtilities::ShapeType>(nComposite, surfElType));
889 auto it2 = surfaceCompMap.find(it->first);
892 if (it2 == surfaceCompMap.end())
895 cerr <<
"Unable to find condition!" << endl;
899 for (j = 0; j < it2->second.size(); ++j)
901 pair<int, LibUtilities::ShapeType> tmp = it2->second[j];
902 if (tmp.second == surfElType)
916 it2->second.push_back(
917 pair<int, LibUtilities::ShapeType>(nComposite, surfElType));
918 compTag = nComposite;
919 m_mesh->m_condition[it->first]->m_composite.push_back(compTag);
923 conditionId = it->first;
928 vector<int> existingTags = surfEl->GetTagList();
930 existingTags.insert(existingTags.begin(), compTag);
931 surfEl->SetTagList(existingTags);
932 surfEl->SetId(nSurfaces);
934 m_mesh->m_element[surfEl->GetDim()].push_back(surfEl);
952 int nodeId =
m_mesh->GetNumEntities();
957 string line, fileName = it.second.second;
961 if (it.second.first !=
eFile)
967 dot = fileName.find_last_of(
'.');
968 fileName = fileName.substr(0, dot);
972 hsf.open(fileName.c_str());
975 cerr <<
"Could not open surface file " << fileName << endl;
982 pos = line.find(
"=");
983 if (pos == string::npos)
985 cerr <<
"hsf header error: cannot read number of " 986 <<
"nodal points." << endl;
989 line = line.substr(pos + 1);
990 stringstream ss(line);
993 pos = line.find(
"=");
994 if (pos == string::npos)
996 cerr <<
"hsf header error: cannot read number of " 1000 line = line.substr(pos + 1);
1005 int Ntot = N * (N + 1) / 2;
1012 for (
int i = 0; i < 2; ++i)
1023 cerr <<
"hsf header error: cannot read in " 1024 <<
"r/s points" << endl;
1028 for (
int j = 0; j < Ntot; ++j)
1030 ss >> (i == 0 ? r[j] : s[j]);
1044 for (
int i = 0; i < Ntot; ++i)
1046 for (
int j = 0; j < Ntot; ++j)
1048 if (fabs(r[i] - rp[j]) < 1e-5 && fabs(s[i] - sp[j]) < 1e-5)
1060 map<int, vector<NodeSharedPtr> > faceMap;
1061 for (
int i = 0; i < Nface; ++i)
1064 vector<NodeSharedPtr> faceNodes(Ntot);
1065 for (
int j = 0; j < Ntot; ++j, ++nodeId)
1075 for (
int j = 0; j < (N - 1) * (N - 1); ++j)
1079 faceMap[i] = faceNodes;
1085 for (
int i = 0; i < Nface; ++i)
1089 vector<int> nodeIds(3);
1094 ss >> tmp >> fid >> nodeIds[0] >> nodeIds[1] >> nodeIds[2];
1098 cerr <<
"Unable to read hsf connectivity information." << endl;
1118 switch (InputNekEntity)
1145 cerr <<
"unknown Nektar element type" << endl;
A 3-dimensional four-faced element.
Basic information about an element.
A 3-dimensional five-faced element (2 triangles, 3 quadrilaterals).
MeshSharedPtr m_mesh
Mesh object.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
ElementFactory & GetElementFactory()
std::shared_ptr< Node > NodeSharedPtr
std::shared_ptr< Face > FaceSharedPtr
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.
NEKMESHUTILS_EXPORT NodeSharedPtr GetVertex(unsigned int i) const
Access a vertex node.
std::shared_ptr< Element > ElementSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
Represents a command-line configuration option.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
Defines a specification for a set of points.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
std::shared_ptr< HOSurf > HOSurfSharedPtr
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
HOTriangle< NodeSharedPtr > HOSurf
std::shared_ptr< Condition > ConditionSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
1D Gauss-Lobatto-Legendre quadrature points
2D Nodal Electrostatic Points on a Triangle
ModuleFactory & GetModuleFactory()