41 #include <boost/algorithm/string.hpp>
56 "Reads Nektar rea file.");
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 boost::unordered_map<int,int> elMap;
93 vector<LibUtilities::ShapeType> elmOrder;
109 cout <<
"InputNek: Start reading file..." << endl;
115 for (i = 0; i < 4; ++i)
120 stringstream s(line);
123 for (i = 0; i < nParam; ++i)
136 for (i = 0; i < j; ++i)
146 for (i = 0; i < j; ++i)
154 bool foundMesh =
false;
158 if (line.find(
"MESH") != string::npos)
167 cerr <<
"Couldn't find MESH tag inside file." << endl;
173 s.clear(); s.str(line);
174 s >> nElements >>
m_mesh->m_expDim;
178 m_mesh->m_fields.push_back(
"u");
179 m_mesh->m_fields.push_back(
"v");
180 if (
m_mesh->m_spaceDim > 2)
182 m_mesh->m_fields.push_back(
"w");
184 m_mesh->m_fields.push_back(
"p");
187 for (i = 0; i < nElements; ++i)
191 if (
m_mesh->m_expDim == 2)
193 if (line.find(
"Qua") != string::npos ||
194 line.find(
"qua") != string::npos)
206 if (line.find(
"Tet") != string::npos ||
207 line.find(
"tet") != string::npos)
211 else if (line.find(
"Hex") != string::npos ||
212 line.find(
"hex") != string::npos)
216 else if (line.find(
"Prism") != string::npos ||
217 line.find(
"prism") != string::npos)
221 else if (line.find(
"Pyr") != string::npos ||
222 line.find(
"pyr") != string::npos)
224 cerr <<
"Pyramid elements not yet supported." << endl;
227 else if (line.find(
"Qua") != string::npos ||
228 line.find(
"qua") != string::npos)
242 for (j = 0; j <
m_mesh->m_expDim; ++j)
245 s.clear(); s.str(line);
246 for (k = 0; k < nNodes; ++k)
253 for (j =
m_mesh->m_expDim; j < 3; ++j)
255 for (k = 0; k < nNodes; ++k)
264 vector<NodeSharedPtr> nodeList;
265 for (k = 0; k < nNodes; ++k)
268 new Node(nodeCounter++, vertex[0][k],
269 vertex[1][k], vertex[2][k]));
270 nodeList.push_back(n);
273 elNodes[elType].push_back(nodeList);
274 elIds [elType].push_back(i);
280 for (i = 0; i < elmOrder.size(); ++i)
283 vector<vector<NodeSharedPtr> > &tmp = elNodes[elType];
285 for (j = 0; j < tmp.size(); ++j)
289 domainComposite.find(elType);
290 if (compIt == domainComposite.end())
292 tags.push_back(nComposite);
293 domainComposite[elType] = nComposite;
298 tags.push_back(compIt->second);
301 elMap[elIds[elType][j]] = reorderedId++;
303 vector<NodeSharedPtr> nodeList = tmp[j];
305 for (k = 0; k < nodeList.size(); ++k)
307 pair<NodeSet::iterator, bool> testIns =
308 m_mesh->m_vertexSet.insert(nodeList[k]);
312 nodeList[k] = *(testIns.first);
316 nodeList[k]->m_id = nodeCounter++;
323 CreateInstance(elType,conf,nodeList,tags);
324 m_mesh->m_element[E->GetDim()].push_back(E);
330 if (line.find(
"CURVE") == string::npos)
332 cerr <<
"Cannot find curved side data." << endl;
338 s.clear(); s.str(line);
345 for (i = 0; i < nCurves; ++i)
348 s.clear(); s.str(line);
355 s.clear(); s.str(line);
356 s >> word >> curveTag;
359 else if (word ==
"Recon")
363 s.clear(); s.str(line);
364 s >> word >> curveTag;
369 cerr <<
"Unsupported curve type " << word << endl;
381 if (line.find(
"side") == string::npos)
383 cerr <<
"Unable to read number of curved sides" << endl;
389 map<string,pair<NekCurve, string> >
::iterator it;
392 s.clear(); s.str(line);
397 for (i = 0; i < nCurvedSides; ++i)
400 s.clear(); s.str(line);
401 s >> faceId >> elId >> word;
403 elId = elMap[elId-1];
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)
488 vector<unsigned int> vertId(3);
489 s >> vertId[0] >> vertId[1] >> vertId[2];
495 if (hoIt ==
hoData[word].end())
497 cerr <<
"Unable to find high-order surface data "
498 <<
"for element id " << elId+1 << endl;
508 if (vertId[0] == surf->vertId[0])
510 if (vertId[1] == surf->vertId[1] ||
511 vertId[1] == surf->vertId[2])
513 if (vertId[1] == surf->vertId[2])
520 else if (vertId[0] == surf->vertId[1])
522 if (vertId[1] == surf->vertId[0] ||
523 vertId[1] == surf->vertId[2])
525 if (vertId[1] == surf->vertId[0])
535 else if (vertId[0] == surf->vertId[2])
537 if (vertId[1] == surf->vertId[0] ||
538 vertId[1] == surf->vertId[1])
540 if (vertId[1] == surf->vertId[1])
562 boost::shared_ptr<Prism> pr =
563 boost::static_pointer_cast<
Prism>(el);
564 if (pr->m_orientation == 1)
572 else if (pr->m_orientation == 2)
587 int Ntot = (*hoIt)->surfVerts.size();
588 int N = ((int)sqrt(8.0*Ntot+1.0)-1)/2;
593 vector<NodeSharedPtr> tmpVerts = (*hoIt)->surfVerts;
594 for (j = 0; j < tmpVerts.size(); ++j)
596 (*hoIt)->surfVerts[
hoMap[j]] = tmpVerts[j];
599 for (j = 0; j < tmpVerts.size(); ++j)
604 for (j = 0; j < f->m_edgeList.size(); ++j)
606 edge = f->m_edgeList[j];
611 if (edge->m_edgeNodes.size() > 0 && reverseSide == 2)
616 edge->m_edgeNodes.clear();
619 for (
int k = 0; k < N-2; ++k)
621 edge->m_edgeNodes.push_back(
622 (*hoIt)->surfVerts[3+j*(N-2)+k]);
626 if (j == reverseSide)
628 reverse(edge->m_edgeNodes.begin(),
629 edge->m_edgeNodes.end());
634 for (
int j = 3+3*(N-2); j < Ntot; ++j)
636 f->m_faceNodes.push_back((*hoIt)->surfVerts[j]);
648 map<int,vector<pair<int,LibUtilities::ShapeType> > > surfaceCompMap;
661 if (line.find(
"*") != string::npos ||
m_mshFile.eof() ||
670 s.clear(); s.str(line);
671 s >> bcType >> elId >> faceId;
673 elId = elMap[elId-1];
676 vector<ConditionType> type;
688 for (i = 0; i <
m_mesh->m_fields.size()-1; ++i)
704 for (i = 0; i <
m_mesh->m_fields.size()-1; ++i)
707 size_t p = line.find_first_of(
'=');
708 vals.push_back(boost::algorithm::trim_copy(
722 for (i = 0; i <
m_mesh->m_fields.size(); ++i)
742 cerr <<
"Unknown boundary condition type "
748 c->field =
m_mesh->m_fields;
757 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end(); ++it)
766 int compTag, conditionId;
774 if (elm->GetDim() == 3)
780 boost::shared_ptr<Prism> p =
781 boost::dynamic_pointer_cast<
Prism>(elm);
782 if (p->m_orientation == 1)
784 faceId = (faceId+2) % 6;
786 else if (p->m_orientation == 2)
788 faceId = (faceId+4) % 6;
793 boost::shared_ptr<Tetrahedron> t =
799 bool tri = f->m_vertexList.size() == 3;
801 vector<NodeSharedPtr> nodeList;
802 nodeList.insert(nodeList.begin(),
803 f->m_vertexList.begin(),
804 f->m_vertexList.end());
813 CreateInstance(seg,conf,nodeList,tags);
816 for (
int i = 0; i < f->m_vertexList.size(); ++i)
818 surfEl->GetEdge(i)->m_edgeNodes =
819 f->m_edgeList[i]->m_edgeNodes;
820 surfEl->GetEdge(i)->m_curveType =
821 f->m_edgeList[i]->m_curveType;
828 vector<NodeSharedPtr> nodeList;
829 nodeList.push_back(f->m_n1);
830 nodeList.push_back(f->m_n2);
845 conditionId =
m_mesh->m_condition.size();
846 compTag = nComposite;
847 c->m_composite.push_back(compTag);
848 m_mesh->m_condition[conditionId] = c;
850 surfaceCompMap[conditionId].push_back(
851 pair<int,LibUtilities::ShapeType>(nComposite,surfEl->GetConf().m_e));
858 map<int,vector<pair<int,LibUtilities::ShapeType> > >
::iterator it2;
859 it2 = surfaceCompMap.find(it->first);
862 if (it2 == surfaceCompMap.end())
865 cerr <<
"Unable to find condition!" << endl;
869 for (j = 0; j < it2->second.size(); ++j)
871 pair<int,LibUtilities::ShapeType> tmp = it2->second[j];
872 if (tmp.second == surfEl->GetConf().m_e)
886 it2->second.push_back(pair<int,LibUtilities::ShapeType>(
887 nComposite,surfEl->GetConf().m_e));
888 compTag = nComposite;
889 m_mesh->m_condition[it->first]->m_composite.push_back(compTag);
893 conditionId = it->first;
898 vector<int> existingTags = surfEl->GetTagList();
900 existingTags.insert(existingTags.begin(), compTag);
901 surfEl->SetTagList (existingTags);
902 surfEl->SetId (nSurfaces);
904 m_mesh->m_element[surfEl->GetDim()].push_back(surfEl);
922 map<string, pair<NekCurve, string> >
::iterator it;
923 int nodeId =
m_mesh->GetNumEntities();
928 string line, fileName = it->second.second;
932 if (it->second.first !=
eFile)
938 dot = fileName.find_last_of(
'.');
939 fileName = fileName.substr(0,dot);
943 hsf.open(fileName.c_str());
946 cerr <<
"Could not open surface file " << fileName << endl;
953 pos = line.find(
"=");
954 if (pos == string::npos)
956 cerr <<
"hsf header error: cannot read number of "
957 <<
"nodal points." << endl;
960 line = line.substr(pos+1);
961 stringstream ss(line);
964 pos = line.find(
"=");
965 if (pos == string::npos)
967 cerr <<
"hsf header error: cannot read number of "
971 line = line.substr(pos+1);
972 ss.clear(); ss.str(line);
975 int Ntot = N*(N+1)/2;
979 Array<OneD, NekDouble> r(Ntot), s(Ntot);
982 for (
int i = 0; i < 2; ++i)
987 ss.clear(); ss.str(line);
992 cerr <<
"hsf header error: cannot read in "
993 <<
"r/s points" << endl;
997 for (
int j = 0; j < Ntot; ++j)
999 ss >> (i == 0 ? r[j] : s[j]);
1005 Array<OneD, NekDouble> rp(Ntot), sp(Ntot);
1013 for (
int i = 0; i < Ntot; ++i)
1015 for (
int j = 0; j < Ntot; ++j)
1017 if (fabs(r[i]-rp[j]) < 1e-5 && fabs(s[i]-sp[j]) < 1e-5)
1029 map<unsigned int, vector<NodeSharedPtr> > faceMap;
1030 for (
int i = 0; i < Nface; ++i)
1033 vector<NodeSharedPtr> faceNodes(Ntot);
1034 for (
int j = 0; j < Ntot; ++j, ++nodeId)
1038 ss.clear(); ss.str(line);
1043 for (
int j = 0; j < (N-1)*(N-1); ++j)
1047 faceMap[i] = faceNodes;
1053 for (
int i = 0; i < Nface; ++i)
1057 vector<unsigned int> nodeIds(3);
1060 ss.clear(); ss.str(line);
1061 ss >> tmp >> fid >> nodeIds[0] >> nodeIds[1] >> nodeIds[2];
1065 cerr <<
"Unable to read hsf connectivity information."
1070 hoData[it->first].insert(
1086 switch(InputNekEntity)
1096 cerr <<
"unknown Nektar element type" << endl;
1110 if (p1->vertId.size() != p2->vertId.size())
1115 vector<unsigned int> ids1 = p1->vertId;
1116 vector<unsigned int> ids2 = p2->vertId;
1117 sort(ids1.begin(), ids1.end());
1118 sort(ids2.begin(), ids2.end());
1120 for (
int i = 0; i < ids1.size(); ++i)
1122 if (ids1[i] != ids2[i])
1138 int np = ((int)sqrt(8.0*
surfVerts.size()+1.0)-1)/2;
1142 for (n = 0; n < nrot; ++n)
1144 for (cnt = i = 0; i < np; ++i)
1146 for (j = 0; j < np-i; ++j, cnt++)
1151 for (cnt = i = 0; i < np; ++i)
1153 for (j = 0; j < np-i; ++j,cnt++)
1166 int np = ((int)sqrt(8.0*
surfVerts.size()+1.0)-1)/2;
1169 for (cnt = i = 0; i < np; ++i)
1171 for (j = 0; j < np-i; ++j,cnt++)
1177 for(cnt = i = 0; i < np; ++i)
1179 for(j = 0; j < np-i; ++j,cnt++)