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);
820 conditionId =
m_mesh->m_condition.size();
821 compTag = nComposite;
822 c->m_composite.push_back(compTag);
823 m_mesh->m_condition[conditionId] = c;
825 surfaceCompMap[conditionId].push_back(
826 pair<int,LibUtilities::ShapeType>(nComposite,surfEl->GetConf().m_e));
833 map<int,vector<pair<int,LibUtilities::ShapeType> > >
::iterator it2;
834 it2 = surfaceCompMap.find(it->first);
837 if (it2 == surfaceCompMap.end())
840 cerr <<
"Unable to find condition!" << endl;
844 for (j = 0; j < it2->second.size(); ++j)
846 pair<int,LibUtilities::ShapeType> tmp = it2->second[j];
847 if (tmp.second == surfEl->GetConf().m_e)
861 it2->second.push_back(pair<int,LibUtilities::ShapeType>(
862 nComposite,surfEl->GetConf().m_e));
863 compTag = nComposite;
864 m_mesh->m_condition[it->first]->m_composite.push_back(compTag);
868 conditionId = it->first;
873 vector<int> existingTags = surfEl->GetTagList();
875 existingTags.insert(existingTags.begin(), compTag);
876 surfEl->SetTagList (existingTags);
877 surfEl->SetId (nSurfaces);
879 m_mesh->m_element[surfEl->GetDim()].push_back(surfEl);
897 map<string, pair<NekCurve, string> >
::iterator it;
898 int nodeId =
m_mesh->GetNumEntities();
903 string line, fileName = it->second.second;
907 if (it->second.first !=
eFile)
913 dot = fileName.find_last_of(
'.');
914 fileName = fileName.substr(0,dot);
918 hsf.open(fileName.c_str());
921 cerr <<
"Could not open surface file " << fileName << endl;
928 pos = line.find(
"=");
929 if (pos == string::npos)
931 cerr <<
"hsf header error: cannot read number of "
932 <<
"nodal points." << endl;
935 line = line.substr(pos+1);
936 stringstream ss(line);
939 pos = line.find(
"=");
940 if (pos == string::npos)
942 cerr <<
"hsf header error: cannot read number of "
946 line = line.substr(pos+1);
947 ss.clear(); ss.str(line);
950 int Ntot = N*(N+1)/2;
954 Array<OneD, NekDouble> r(Ntot), s(Ntot);
957 for (
int i = 0; i < 2; ++i)
962 ss.clear(); ss.str(line);
967 cerr <<
"hsf header error: cannot read in "
968 <<
"r/s points" << endl;
972 for (
int j = 0; j < Ntot; ++j)
974 ss >> (i == 0 ? r[j] : s[j]);
980 Array<OneD, NekDouble> rp(Ntot), sp(Ntot);
988 for (
int i = 0; i < Ntot; ++i)
990 for (
int j = 0; j < Ntot; ++j)
992 if (fabs(r[i]-rp[j]) < 1e-5 && fabs(s[i]-sp[j]) < 1e-5)
1004 map<int, vector<NodeSharedPtr> > faceMap;
1005 for (
int i = 0; i < Nface; ++i)
1008 vector<NodeSharedPtr> faceNodes(Ntot);
1009 for (
int j = 0; j < Ntot; ++j, ++nodeId)
1013 ss.clear(); ss.str(line);
1018 for (
int j = 0; j < (N-1)*(N-1); ++j)
1022 faceMap[i] = faceNodes;
1028 for (
int i = 0; i < Nface; ++i)
1032 vector<int> nodeIds(3);
1035 ss.clear(); ss.str(line);
1036 ss >> tmp >> fid >> nodeIds[0] >> nodeIds[1] >> nodeIds[2];
1040 cerr <<
"Unable to read hsf connectivity information."
1045 hoData[it->first].insert(
1061 switch(InputNekEntity)
1072 cerr <<
"unknown Nektar element type" << endl;
1086 if (p1->vertId.size() != p2->vertId.size())
1091 vector<int> ids1 = p1->vertId;
1092 vector<int> ids2 = p2->vertId;
1093 sort(ids1.begin(), ids1.end());
1094 sort(ids2.begin(), ids2.end());
1096 for (
int i = 0; i < ids1.size(); ++i)
1098 if (ids1[i] != ids2[i])