36 #include "../MeshElements.h"
40 #include <boost/algorithm/string.hpp>
55 "Reads Nektar rea file.");
83 int nParam, nElements, nCurves;
84 int i, j, k, nodeCounter = 0;
88 map<LibUtilities::ShapeType,int> domainComposite;
89 map<LibUtilities::ShapeType,vector< vector<NodeSharedPtr> > > elNodes;
90 map<LibUtilities::ShapeType,vector<int> > elIds;
91 boost::unordered_map<int,int> elMap;
92 vector<LibUtilities::ShapeType> elmOrder;
108 cout <<
"InputNek: Start reading file..." << endl;
114 for (i = 0; i < 4; ++i)
119 stringstream s(line);
122 for (i = 0; i < nParam; ++i)
135 for (i = 0; i < j; ++i)
145 for (i = 0; i < j; ++i)
153 bool foundMesh =
false;
157 if (line.find(
"MESH") != string::npos)
166 cerr <<
"Couldn't find MESH tag inside file." << endl;
172 s.clear(); s.str(line);
173 s >> nElements >>
m_mesh->m_expDim;
177 m_mesh->m_fields.push_back(
"u");
178 m_mesh->m_fields.push_back(
"v");
179 if (
m_mesh->m_spaceDim > 2)
181 m_mesh->m_fields.push_back(
"w");
183 m_mesh->m_fields.push_back(
"p");
186 for (i = 0; i < nElements; ++i)
190 if (
m_mesh->m_expDim == 2)
192 if (line.find(
"Qua") != string::npos ||
193 line.find(
"qua") != string::npos)
205 if (line.find(
"Tet") != string::npos ||
206 line.find(
"tet") != string::npos)
210 else if (line.find(
"Hex") != string::npos ||
211 line.find(
"hex") != string::npos)
215 else if (line.find(
"Prism") != string::npos ||
216 line.find(
"prism") != string::npos)
220 else if (line.find(
"Pyr") != string::npos ||
221 line.find(
"pyr") != string::npos)
225 else if (line.find(
"Qua") != string::npos ||
226 line.find(
"qua") != string::npos)
240 for (j = 0; j <
m_mesh->m_expDim; ++j)
243 s.clear(); s.str(line);
244 for (k = 0; k < nNodes; ++k)
251 for (j =
m_mesh->m_expDim; j < 3; ++j)
253 for (k = 0; k < nNodes; ++k)
262 vector<NodeSharedPtr> nodeList;
263 for (k = 0; k < nNodes; ++k)
266 new Node(nodeCounter++, vertex[0][k],
267 vertex[1][k], vertex[2][k]));
268 nodeList.push_back(n);
271 elNodes[elType].push_back(nodeList);
272 elIds [elType].push_back(i);
278 for (i = 0; i < elmOrder.size(); ++i)
281 vector<vector<NodeSharedPtr> > &tmp = elNodes[elType];
283 for (j = 0; j < tmp.size(); ++j)
287 domainComposite.find(elType);
288 if (compIt == domainComposite.end())
290 tags.push_back(nComposite);
291 domainComposite[elType] = nComposite;
296 tags.push_back(compIt->second);
299 elMap[elIds[elType][j]] = reorderedId++;
301 vector<NodeSharedPtr> nodeList = tmp[j];
303 for (k = 0; k < nodeList.size(); ++k)
305 pair<NodeSet::iterator, bool> testIns =
306 m_mesh->m_vertexSet.insert(nodeList[k]);
310 nodeList[k] = *(testIns.first);
314 nodeList[k]->m_id = nodeCounter++;
321 CreateInstance(elType,conf,nodeList,tags);
322 m_mesh->m_element[E->GetDim()].push_back(E);
328 if (line.find(
"CURVE") == string::npos)
330 cerr <<
"Cannot find curved side data." << endl;
336 s.clear(); s.str(line);
343 for (i = 0; i < nCurves; ++i)
346 s.clear(); s.str(line);
353 s.clear(); s.str(line);
354 s >> word >> curveTag;
357 else if (word ==
"Recon")
361 s.clear(); s.str(line);
362 s >> word >> curveTag;
367 cerr <<
"Unsupported curve type " << word << endl;
379 if (line.find(
"side") == string::npos)
381 cerr <<
"Unable to read number of curved sides" << endl;
387 map<string,pair<NekCurve, string> >
::iterator it;
390 s.clear(); s.str(line);
395 for (i = 0; i < nCurvedSides; ++i)
398 s.clear(); s.str(line);
399 s >> faceId >> elId >> word;
401 elId = elMap[elId-1];
404 int origFaceId = faceId;
408 boost::shared_ptr<Prism> p =
409 boost::dynamic_pointer_cast<
Prism>(el);
410 if (p->m_orientation == 1)
412 faceId = (faceId+2) % 6;
414 else if (p->m_orientation == 2)
416 faceId = (faceId+4) % 6;
421 boost::shared_ptr<Tetrahedron> t =
429 cerr <<
"Unrecognised curve tag " << word
430 <<
" in curved lines" << endl;
434 if (it->second.first ==
eRecon)
437 vector<NodeSharedPtr> &tmp =
438 el->GetFace(faceId)->m_vertexList;
439 vector<Node> n(tmp.size());
444 offset = boost::dynamic_pointer_cast<
Prism>(
450 s.clear(); s.str(line);
451 for (j = 0; j < tmp.size(); ++j)
457 s.clear(); s.str(line);
458 for (j = 0; j < tmp.size(); ++j)
464 s.clear(); s.str(line);
465 for (j = 0; j < tmp.size(); ++j)
470 for (j = 0; j < tmp.size(); ++j)
472 int id = tmp[(j+offset) % tmp.size()]->m_id;
474 m_mesh->m_vertexNormals.find(
id);
476 if (vIt ==
m_mesh->m_vertexNormals.end())
478 m_mesh->m_vertexNormals[id] = n[j];
484 m_mesh->m_spherigonSurfs.insert(make_pair(elId, faceId));
486 else if (it->second.first ==
eFile)
489 static int tetFaceVerts[4][3] = {
490 {0,1,2},{0,1,3},{1,2,3},{0,2,3}};
492 vector<int> vertId(3);
493 s >> vertId[0] >> vertId[1] >> vertId[2];
500 boost::shared_ptr<Tetrahedron> tet =
502 vector<int> tmpVertId = vertId;
504 for (j = 0; j < 3; ++j)
508 tetFaceVerts[origFaceId][j]])->m_id;
510 for (k = 0; k < 3; ++k)
512 int w = f->m_vertexList[k]->m_id;
515 vertId[k] = tmpVertId[j];
523 boost::shared_ptr<Prism> pr =
524 boost::static_pointer_cast<
Prism>(el);
525 if (pr->m_orientation == 1)
527 swap(vertId[2], vertId[1]);
528 swap(vertId[0], vertId[1]);
530 else if (pr->m_orientation == 2)
532 swap(vertId[0], vertId[1]);
533 swap(vertId[2], vertId[1]);
541 if (hoIt ==
hoData[word].end())
543 cerr <<
"Unable to find high-order surface data "
544 <<
"for element id " << elId+1 << endl;
554 int Ntot = (*hoIt)->surfVerts.size();
555 int N = ((int)sqrt(8.0*Ntot+1.0)-1)/2;
560 vector<NodeSharedPtr> tmpVerts = (*hoIt)->surfVerts;
561 for (j = 0; j < tmpVerts.size(); ++j)
563 (*hoIt)->surfVerts[
hoMap[j]] = tmpVerts[j];
566 for (j = 0; j < tmpVerts.size(); ++j)
571 vector<int> faceVertIds(3);
572 faceVertIds[0] = f->m_vertexList[0]->m_id;
573 faceVertIds[1] = f->m_vertexList[1]->m_id;
574 faceVertIds[2] = f->m_vertexList[2]->m_id;
576 for (j = 0; j < f->m_edgeList.size(); ++j)
578 edge = f->m_edgeList[j];
582 if (edge->m_edgeNodes.size() > 0)
591 for (
int k = 0; k < N-2; ++k)
593 edge->m_edgeNodes.push_back(
594 (*hoIt)->surfVerts[3+j*(N-2)+k]);
600 if (edge->m_n1->m_id != faceVertIds[j])
602 reverse(edge->m_edgeNodes.begin(),
603 edge->m_edgeNodes.end());
609 for (
int j = 3+3*(N-2); j < Ntot; ++j)
611 f->m_faceNodes.push_back((*hoIt)->surfVerts[j]);
623 map<int,vector<pair<int,LibUtilities::ShapeType> > > surfaceCompMap;
636 if (line.find(
"*") != string::npos ||
m_mshFile.eof() ||
645 s.clear(); s.str(line);
646 s >> bcType >> elId >> faceId;
648 elId = elMap[elId-1];
651 vector<ConditionType> type;
663 for (i = 0; i <
m_mesh->m_fields.size()-1; ++i)
679 for (i = 0; i <
m_mesh->m_fields.size()-1; ++i)
682 size_t p = line.find_first_of(
'=');
683 vals.push_back(boost::algorithm::trim_copy(
697 for (i = 0; i <
m_mesh->m_fields.size(); ++i)
717 cerr <<
"Unknown boundary condition type "
723 c->field =
m_mesh->m_fields;
732 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end(); ++it)
741 int compTag, conditionId;
749 if (elm->GetDim() == 3)
755 boost::shared_ptr<Prism> p =
756 boost::dynamic_pointer_cast<
Prism>(elm);
757 if (p->m_orientation == 1)
759 faceId = (faceId+2) % 6;
761 else if (p->m_orientation == 2)
763 faceId = (faceId+4) % 6;
768 boost::shared_ptr<Tetrahedron> t =
774 bool tri = f->m_vertexList.size() == 3;
776 vector<NodeSharedPtr> nodeList;
777 nodeList.insert(nodeList.begin(),
778 f->m_vertexList.begin(),
779 f->m_vertexList.end());
788 CreateInstance(seg,conf,nodeList,tags);
791 for (
int i = 0; i < f->m_vertexList.size(); ++i)
793 surfEl->GetEdge(i)->m_edgeNodes =
794 f->m_edgeList[i]->m_edgeNodes;
795 surfEl->GetEdge(i)->m_curveType =
796 f->m_edgeList[i]->m_curveType;
803 vector<NodeSharedPtr> nodeList;
804 nodeList.push_back(f->m_n1);
805 nodeList.push_back(f->m_n2);
822 conditionId =
m_mesh->m_condition.size();
823 compTag = nComposite;
824 c->m_composite.push_back(compTag);
825 m_mesh->m_condition[conditionId] = c;
827 surfaceCompMap[conditionId].push_back(
828 pair<int,LibUtilities::ShapeType>(nComposite,surfElType));
835 map<int,vector<pair<int,LibUtilities::ShapeType> > >
::iterator it2;
836 it2 = surfaceCompMap.find(it->first);
839 if (it2 == surfaceCompMap.end())
842 cerr <<
"Unable to find condition!" << endl;
846 for (j = 0; j < it2->second.size(); ++j)
848 pair<int,LibUtilities::ShapeType> tmp = it2->second[j];
849 if (tmp.second == surfElType)
863 it2->second.push_back(pair<int,LibUtilities::ShapeType>(
864 nComposite,surfElType));
865 compTag = nComposite;
866 m_mesh->m_condition[it->first]->m_composite.push_back(compTag);
870 conditionId = it->first;
875 vector<int> existingTags = surfEl->GetTagList();
877 existingTags.insert(existingTags.begin(), compTag);
878 surfEl->SetTagList (existingTags);
879 surfEl->SetId (nSurfaces);
881 m_mesh->m_element[surfEl->GetDim()].push_back(surfEl);
899 map<string, pair<NekCurve, string> >
::iterator it;
900 int nodeId =
m_mesh->GetNumEntities();
905 string line, fileName = it->second.second;
909 if (it->second.first !=
eFile)
915 dot = fileName.find_last_of(
'.');
916 fileName = fileName.substr(0,dot);
920 hsf.open(fileName.c_str());
923 cerr <<
"Could not open surface file " << fileName << endl;
930 pos = line.find(
"=");
931 if (pos == string::npos)
933 cerr <<
"hsf header error: cannot read number of "
934 <<
"nodal points." << endl;
937 line = line.substr(pos+1);
938 stringstream ss(line);
941 pos = line.find(
"=");
942 if (pos == string::npos)
944 cerr <<
"hsf header error: cannot read number of "
948 line = line.substr(pos+1);
949 ss.clear(); ss.str(line);
952 int Ntot = N*(N+1)/2;
959 for (
int i = 0; i < 2; ++i)
964 ss.clear(); ss.str(line);
969 cerr <<
"hsf header error: cannot read in "
970 <<
"r/s points" << endl;
974 for (
int j = 0; j < Ntot; ++j)
976 ss >> (i == 0 ? r[j] : s[j]);
990 for (
int i = 0; i < Ntot; ++i)
992 for (
int j = 0; j < Ntot; ++j)
994 if (fabs(r[i]-rp[j]) < 1e-5 && fabs(s[i]-sp[j]) < 1e-5)
1006 map<int, vector<NodeSharedPtr> > faceMap;
1007 for (
int i = 0; i < Nface; ++i)
1010 vector<NodeSharedPtr> faceNodes(Ntot);
1011 for (
int j = 0; j < Ntot; ++j, ++nodeId)
1015 ss.clear(); ss.str(line);
1020 for (
int j = 0; j < (N-1)*(N-1); ++j)
1024 faceMap[i] = faceNodes;
1030 for (
int i = 0; i < Nface; ++i)
1034 vector<int> nodeIds(3);
1037 ss.clear(); ss.str(line);
1038 ss >> tmp >> fid >> nodeIds[0] >> nodeIds[1] >> nodeIds[2];
1042 cerr <<
"Unable to read hsf connectivity information."
1047 hoData[it->first].insert(
1063 switch(InputNekEntity)
1074 cerr <<
"unknown Nektar element type" << endl;
1088 if (p1->vertId.size() != p2->vertId.size())
1093 vector<int> ids1 = p1->vertId;
1094 vector<int> ids2 = p2->vertId;
1095 sort(ids1.begin(), ids1.end());
1096 sort(ids2.begin(), ids2.end());
1098 for (
int i = 0; i < ids1.size(); ++i)
1100 if (ids1[i] != ids2[i])
pair< ModuleType, string > ModuleKey
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< HOSurf > HOSurfSharedPtr
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
NodeSharedPtr GetVertex(unsigned int i) const
Access a vertex node.
boost::shared_ptr< Node > NodeSharedPtr
Shared pointer to a Node.
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::shared_ptr< Condition > ConditionSharedPtr
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer to an element.
A 3-dimensional five-faced element (2 triangles, 3 quadrilaterals).
virtual void ProcessElements()
Generate element IDs.
HOTriangle< NodeSharedPtr > HOSurf
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
PointsManagerT & PointsManager(void)
Defines a specification for a set of points.
Basic information about an element.
virtual void ProcessComposites()
Generate composites.
Represents a point in the domain.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
bool operator==(TriFaceIDs const &p1, TriFaceIDs const &p2)
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
A 3-dimensional four-faced element.
ElementFactory & GetElementFactory()
1D Gauss-Lobatto-Legendre quadrature points
2D Nodal Electrostatic Points on a Triangle
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.