46 #include <boost/format.hpp>
54 namespace SpatialDomains
57 std::string MeshGraphXml::className =
59 "Xml", MeshGraphXml::create,
"IO with Xml geometry");
61 void MeshGraphXml::PartitionMesh(
67 const bool isRoot = comm->TreatAsRankZero();
79 int isPartitioned = 0;
82 if (m_session->DefinesElement(
"Nektar/Geometry"))
84 if (m_session->GetElement(
"Nektar/Geometry")->Attribute(
"PARTITION"))
86 std::cout <<
"Using pre-partitioned mesh." << std::endl;
91 comm->Bcast(isPartitioned, 0);
99 m_session->InitSession();
106 string partitionerName =
"Metis";
109 partitionerName =
"Scotch";
111 if (session->DefinesCmdLineArgument(
"use-metis"))
113 partitionerName =
"Metis";
115 if (session->DefinesCmdLineArgument(
"use-scotch"))
117 partitionerName =
"Scotch";
123 if (session->DefinesCmdLineArgument(
"part-only")||
124 session->DefinesCmdLineArgument(
"part-only-overlapping"))
129 "The 'part-only' option should be used in serial.");
136 auto comp = CreateCompositeDescriptor();
140 partitionerName, session, session->GetComm(),
141 m_meshDimension, CreateMeshEntities(), comp);
143 if (session->DefinesCmdLineArgument(
"part-only"))
145 nParts = session->GetCmdLineArgument<
int>(
"part-only");
146 partitioner->PartitionMesh(nParts,
true);
150 nParts = session->GetCmdLineArgument<
int>(
"part-only-overlapping");
151 partitioner->PartitionMesh(nParts,
true,
true);
154 vector<set<unsigned int>> elmtIDs;
155 vector<unsigned int> parts(nParts);
156 for (
int i = 0; i < nParts; ++i)
158 vector<unsigned int> elIDs;
159 set<unsigned int> tmp;
160 partitioner->GetElementIDs(i, elIDs);
161 tmp.insert(elIDs.begin(), elIDs.end());
162 elmtIDs.push_back(tmp);
166 this->WriteXMLGeometry(m_session->GetSessionName(), elmtIDs, parts);
168 if (isRoot && session->DefinesCmdLineArgument(
"part-info"))
170 partitioner->PrintPartInfo(std::cout);
177 if (commMesh->GetSize() > 1)
179 int nParts = commMesh->GetSize();
181 if (session->GetSharedFilesystem())
183 vector<unsigned int> keys, vals;
192 m_compOrder = CreateCompositeOrdering();
193 auto comp = CreateCompositeDescriptor();
198 partitionerName, session, session->GetComm(),
199 m_meshDimension, CreateMeshEntities(), comp);
201 partitioner->PartitionMesh(nParts,
true);
203 vector<set<unsigned int>> elmtIDs;
204 vector<unsigned int> parts(nParts);
205 for (i = 0; i < nParts; ++i)
207 vector<unsigned int> elIDs;
208 set<unsigned int> tmp;
209 partitioner->GetElementIDs(i, elIDs);
210 tmp.insert(elIDs.begin(), elIDs.end());
211 elmtIDs.push_back(tmp);
217 this->WriteXMLGeometry(
218 m_session->GetSessionName(), elmtIDs, parts);
225 keys[0] = m_compOrder.size();
226 keys[1] = m_bndRegOrder.size();
227 comm->Bcast(keys, 0);
231 keys.resize(m_compOrder.size());
232 vals.resize(m_compOrder.size());
235 for (
auto &cIt : m_compOrder)
237 keys[i ] = cIt.first;
238 vals[i++] = cIt.second.size();
242 comm->Bcast(keys, 0);
243 comm->Bcast(vals, 0);
244 for (
auto &cIt : m_compOrder)
246 comm->Bcast(cIt.second, 0);
251 keys.resize(m_bndRegOrder.size());
252 vals.resize(m_bndRegOrder.size());
255 for (
auto &bIt : m_bndRegOrder)
257 keys[i ] = bIt.first;
258 vals[i++] = bIt.second.size();
264 comm->Bcast(keys, 0);
268 comm->Bcast(vals, 0);
270 for (
auto &bIt : m_bndRegOrder)
272 comm->Bcast(bIt.second, 0);
275 if (session->DefinesCmdLineArgument(
"part-info"))
277 partitioner->PrintPartInfo(std::cout);
283 comm->Bcast(keys, 0);
285 int cmpSize = keys[0];
286 int bndSize = keys[1];
288 keys.resize(cmpSize);
289 vals.resize(cmpSize);
290 comm->Bcast(keys, 0);
291 comm->Bcast(vals, 0);
293 for (
int i = 0; i < keys.size(); ++i)
295 vector<unsigned int> tmp(vals[i]);
297 m_compOrder[keys[i]] = tmp;
300 keys.resize(bndSize);
301 vals.resize(bndSize);
304 comm->Bcast(keys, 0);
308 comm->Bcast(vals, 0);
310 for (
int i = 0; i < keys.size(); ++i)
312 vector<unsigned int> tmp(vals[i]);
314 m_bndRegOrder[keys[i]] = tmp;
320 m_session->InitSession();
323 m_compOrder = CreateCompositeOrdering();
324 auto comp = CreateCompositeDescriptor();
331 partitionerName, session, session->GetComm(),
332 m_meshDimension, CreateMeshEntities(), comp);
334 partitioner->PartitionMesh(nParts,
false);
336 vector<unsigned int> parts(1), tmp;
337 parts[0] = commMesh->GetRank();
338 vector<set<unsigned int>> elIDs(1);
339 partitioner->GetElementIDs(parts[0], tmp);
340 elIDs[0].insert(tmp.begin(), tmp.end());
341 this->WriteXMLGeometry(session->GetSessionName(), elIDs, parts);
343 if (m_session->DefinesCmdLineArgument(
"part-info") && isRoot)
345 partitioner->PrintPartInfo(std::cout);
352 std::string dirname = m_session->GetSessionName() +
"_xml";
353 fs::path pdirname(dirname);
355 pad % comm->GetRowComm()->GetRank();
356 fs::path pFilename(pad.str());
357 fs::path fullpath = pdirname / pFilename;
359 std::vector<std::string> filenames = {
361 m_session->InitSession(filenames);
368 m_session->InitSession();
373 void MeshGraphXml::ReadGeometry(
379 m_curvedEdges.clear();
380 m_curvedFaces.clear();
386 m_prismGeoms.clear();
388 m_meshComposites.clear();
389 m_compositesLabels.clear();
391 m_expansionMapShPtrMap.clear();
393 m_faceToElMap.clear();
396 m_xmlGeom = m_session->GetElement(
"NEKTAR/GEOMETRY");
400 TiXmlAttribute *attr = m_xmlGeom->FirstAttribute();
405 m_meshPartitioned =
false;
407 m_spaceDimension = 3;
411 std::string attrName(attr->Name());
412 if (attrName ==
"DIM")
414 err = attr->QueryIntValue(&m_meshDimension);
415 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
417 else if (attrName ==
"SPACE")
419 err = attr->QueryIntValue(&m_spaceDimension);
420 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
422 else if (attrName ==
"PARTITION")
424 err = attr->QueryIntValue(&m_partition);
425 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read partition.");
426 m_meshPartitioned =
true;
430 std::string errstr(
"Unknown attribute: ");
439 ASSERTL0(m_meshDimension <= m_spaceDimension,
440 "Mesh dimension greater than space dimension");
444 if (m_meshDimension >= 2)
447 if (m_meshDimension == 3)
458 MeshGraph::FillGraph();
462 void MeshGraphXml::ReadVertices()
465 TiXmlElement *element = m_xmlGeom->FirstChildElement(
"VERTEX");
466 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
473 const char *xscal = element->Attribute(
"XSCALE");
480 std::string xscalstr = xscal;
482 xscale = expEvaluator.
Evaluate(expr_id);
485 const char *yscal = element->Attribute(
"YSCALE");
492 std::string yscalstr = yscal;
494 yscale = expEvaluator.
Evaluate(expr_id);
497 const char *zscal = element->Attribute(
"ZSCALE");
504 std::string zscalstr = zscal;
506 zscale = expEvaluator.
Evaluate(expr_id);
514 const char *xmov = element->Attribute(
"XMOVE");
521 std::string xmovstr = xmov;
523 xmove = expEvaluator.
Evaluate(expr_id);
526 const char *ymov = element->Attribute(
"YMOVE");
533 std::string ymovstr = ymov;
535 ymove = expEvaluator.
Evaluate(expr_id);
538 const char *zmov = element->Attribute(
"ZMOVE");
545 std::string zmovstr = zmov;
547 zmove = expEvaluator.
Evaluate(expr_id);
550 TiXmlElement *vertex = element->FirstChildElement(
"V");
553 int nextVertexNumber = -1;
559 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
560 std::string attrName(vertexAttr->Name());
563 (std::string(
"Unknown attribute name: ") + attrName).c_str());
565 int err = vertexAttr->QueryIntValue(&indx);
566 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
569 std::string vertexBodyStr;
571 TiXmlNode *vertexBody = vertex->FirstChild();
576 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
578 vertexBodyStr += vertexBody->ToText()->Value();
579 vertexBodyStr +=
" ";
582 vertexBody = vertexBody->NextSibling();
586 "Vertex definitions must contain vertex data.");
590 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
594 while (!vertexDataStrm.fail())
596 vertexDataStrm >> xval >> yval >> zval;
598 xval = xval * xscale + xmove;
599 yval = yval * yscale + ymove;
600 zval = zval * zscale + zmove;
605 if (!vertexDataStrm.fail())
609 m_spaceDimension, indx, xval, yval, zval));
610 m_vertSet[indx] = vert;
616 ASSERTL0(
false,
"Unable to read VERTEX data.");
619 vertex = vertex->NextSiblingElement(
"V");
623 void MeshGraphXml::ReadCurves()
627 TiXmlElement *element = m_xmlGeom->FirstChildElement(
"VERTEX");
628 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
633 const char *xscal = element->Attribute(
"XSCALE");
640 std::string xscalstr = xscal;
642 xscale = expEvaluator.
Evaluate(expr_id);
645 const char *yscal = element->Attribute(
"YSCALE");
652 std::string yscalstr = yscal;
654 yscale = expEvaluator.
Evaluate(expr_id);
657 const char *zscal = element->Attribute(
"ZSCALE");
664 std::string zscalstr = zscal;
666 zscale = expEvaluator.
Evaluate(expr_id);
674 const char *xmov = element->Attribute(
"XMOVE");
681 std::string xmovstr = xmov;
683 xmove = expEvaluator.
Evaluate(expr_id);
686 const char *ymov = element->Attribute(
"YMOVE");
693 std::string ymovstr = ymov;
695 ymove = expEvaluator.
Evaluate(expr_id);
698 const char *zmov = element->Attribute(
"ZMOVE");
705 std::string zmovstr = zmov;
707 zmove = expEvaluator.
Evaluate(expr_id);
713 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"CURVED");
724 TiXmlElement *edgelement = field->FirstChildElement(
"E");
726 int edgeindx, edgeid;
727 int nextEdgeNumber = -1;
734 std::string edge(edgelement->ValueStr());
736 (std::string(
"Unknown 3D curve type:") + edge).c_str());
739 err = edgelement->QueryIntAttribute(
"ID", &edgeindx);
740 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
743 err = edgelement->QueryIntAttribute(
"EDGEID", &edgeid);
745 "Unable to read curve attribute EDGEID.");
748 std::string elementStr;
749 TiXmlNode *elementChild = edgelement->FirstChild();
754 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
756 elementStr += elementChild->ToText()->ValueStr();
759 elementChild = elementChild->NextSibling();
762 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
770 std::string typeStr = edgelement->Attribute(
"TYPE");
771 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
772 "points definition");
776 const std::string *endStr =
778 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
780 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
784 err = edgelement->QueryIntAttribute(
"NUMPOINTS", &numPts);
786 "Unable to read curve attribute NUMPOINTS.");
792 std::istringstream elementDataStrm(elementStr.c_str());
795 while (!elementDataStrm.fail())
797 elementDataStrm >> xval >> yval >> zval;
799 xval = xval * xscale + xmove;
800 yval = yval * yscale + ymove;
801 zval = zval * zscale + zmove;
806 if (!elementDataStrm.fail())
810 m_meshDimension, edgeindx, xval, yval, zval));
812 curve->m_points.push_back(vert);
819 (std::string(
"Unable to read curve data for EDGE: ") +
824 ASSERTL0(curve->m_points.size() == numPts,
825 "Number of points specificed by attribute "
826 "NUMPOINTS is different from number of points "
827 "in list (edgeid = " +
828 boost::lexical_cast<string>(edgeid));
830 m_curvedEdges[edgeid] = curve;
832 edgelement = edgelement->NextSiblingElement(
"E");
838 TiXmlElement *facelement = field->FirstChildElement(
"F");
839 int faceindx, faceid;
843 std::string face(facelement->ValueStr());
845 (std::string(
"Unknown 3D curve type: ") + face).c_str());
848 err = facelement->QueryIntAttribute(
"ID", &faceindx);
849 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
852 err = facelement->QueryIntAttribute(
"FACEID", &faceid);
854 "Unable to read curve attribute FACEID.");
857 std::string elementStr;
858 TiXmlNode *elementChild = facelement->FirstChild();
863 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
865 elementStr += elementChild->ToText()->ValueStr();
868 elementChild = elementChild->NextSibling();
871 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
877 std::string typeStr = facelement->Attribute(
"TYPE");
878 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
879 "points definition");
882 const std::string *endStr =
884 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
886 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
889 std::string numptsStr = facelement->Attribute(
"NUMPOINTS");
891 "NUMPOINTS must be specified in points definition");
900 ASSERTL0(numPts >= 3,
"NUMPOINTS for face must be greater than 2");
904 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
909 std::istringstream elementDataStrm(elementStr.c_str());
912 while (!elementDataStrm.fail())
914 elementDataStrm >> xval >> yval >> zval;
920 if (!elementDataStrm.fail())
924 m_meshDimension, faceindx, xval, yval, zval));
925 curve->m_points.push_back(vert);
932 (std::string(
"Unable to read curve data for FACE: ") +
936 m_curvedFaces[faceid] = curve;
938 facelement = facelement->NextSiblingElement(
"F");
943 void MeshGraphXml::ReadDomain()
945 TiXmlElement *domain = NULL;
947 domain = m_xmlGeom->FirstChildElement(
"DOMAIN");
949 ASSERTL0(domain,
"Unable to find DOMAIN tag in file.");
953 TiXmlElement *multidomains = domain->FirstChildElement(
"D");
957 int nextDomainNumber = 0;
961 int err = multidomains->QueryIntAttribute(
"ID", &indx);
963 "Unable to read attribute ID in Domain.");
965 TiXmlNode *elementChild = multidomains->FirstChild();
966 while (elementChild &&
967 elementChild->Type() != TiXmlNode::TINYXML_TEXT)
969 elementChild = elementChild->NextSibling();
972 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
973 std::string elementStr = elementChild->ToText()->ValueStr();
975 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
977 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
978 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
979 std::string indxStr =
980 elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
984 "Unable to read domain's composite index (index missing?).");
988 map<int, CompositeSharedPtr> unrollDomain;
989 GetCompositeList(indxStr, unrollDomain);
990 m_domain.push_back(unrollDomain);
992 ASSERTL0(!m_domain[nextDomainNumber++].empty(),
994 "Unable to obtain domain's referenced composite: ") +
999 multidomains = multidomains->NextSiblingElement(
"D");
1006 TiXmlNode *elementChild = domain->FirstChild();
1007 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1009 elementChild = elementChild->NextSibling();
1012 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
1013 std::string elementStr = elementChild->ToText()->ValueStr();
1015 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
1017 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
1018 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
1019 std::string indxStr = elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1022 "Unable to read domain's composite index (index missing?).");
1026 map<int, CompositeSharedPtr> fullDomain;
1027 GetCompositeList(indxStr, fullDomain);
1028 m_domain.push_back(fullDomain);
1031 !m_domain[0].empty(),
1032 (std::string(
"Unable to obtain domain's referenced composite: ") +
1038 void MeshGraphXml::ReadEdges()
1040 CurveMap::iterator it;
1043 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"EDGE");
1045 ASSERTL0(field,
"Unable to find EDGE tag in file.");
1050 TiXmlElement *edge = field->FirstChildElement(
"E");
1058 std::string edgeStr;
1063 int err = edge->QueryIntAttribute(
"ID", &indx);
1064 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
1066 TiXmlNode *child = edge->FirstChild();
1068 if (child->Type() == TiXmlNode::TINYXML_TEXT)
1070 edgeStr += child->ToText()->ValueStr();
1074 int vertex1, vertex2;
1075 std::istringstream edgeDataStrm(edgeStr.c_str());
1079 while (!edgeDataStrm.fail())
1081 edgeDataStrm >> vertex1 >> vertex2;
1088 if (!edgeDataStrm.fail())
1091 GetVertex(vertex2)};
1093 it = m_curvedEdges.find(indx);
1095 if (it == m_curvedEdges.end())
1098 indx, m_spaceDimension, vertices);
1103 indx, m_spaceDimension, vertices, it->second);
1106 m_segGeoms[indx] = edge;
1114 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
1117 edge = edge->NextSiblingElement(
"E");
1121 void MeshGraphXml::ReadFaces()
1124 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"FACE");
1126 ASSERTL0(field,
"Unable to find FACE tag in file.");
1132 TiXmlElement *element = field->FirstChildElement();
1133 CurveMap::iterator it;
1137 std::string elementType(element->ValueStr());
1139 ASSERTL0(elementType ==
"Q" || elementType ==
"T",
1140 (std::string(
"Unknown 3D face type: ") + elementType).c_str());
1144 int err = element->QueryIntAttribute(
"ID", &indx);
1145 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read face attribute ID.");
1148 it = m_curvedFaces.find(indx);
1151 TiXmlNode *elementChild = element->FirstChild();
1152 std::string elementStr;
1153 while (elementChild)
1155 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1157 elementStr += elementChild->ToText()->ValueStr();
1159 elementChild = elementChild->NextSibling();
1162 ASSERTL0(!elementStr.empty(),
"Unable to read face description body.");
1166 if (elementType ==
"T")
1169 int edge1, edge2, edge3;
1170 std::istringstream elementDataStrm(elementStr.c_str());
1174 elementDataStrm >> edge1;
1175 elementDataStrm >> edge2;
1176 elementDataStrm >> edge3;
1179 !elementDataStrm.fail(),
1180 (std::string(
"Unable to read face data for TRIANGLE: ") +
1186 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3)};
1190 if (it == m_curvedFaces.end())
1198 indx, edges, it->second);
1201 trigeom->SetGlobalID(indx);
1203 m_triGeoms[indx] = trigeom;
1209 (std::string(
"Unable to read face data for TRIANGLE: ") +
1214 else if (elementType ==
"Q")
1217 int edge1, edge2, edge3, edge4;
1218 std::istringstream elementDataStrm(elementStr.c_str());
1222 elementDataStrm >> edge1;
1223 elementDataStrm >> edge2;
1224 elementDataStrm >> edge3;
1225 elementDataStrm >> edge4;
1228 (std::string(
"Unable to read face data for QUAD: ") +
1234 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3),
1239 if (it == m_curvedFaces.end())
1247 indx, edges, it->second);
1249 quadgeom->SetGlobalID(indx);
1251 m_quadGeoms[indx] = quadgeom;
1256 (std::string(
"Unable to read face data for QUAD: ") +
1262 element = element->NextSiblingElement();
1266 void MeshGraphXml::ReadElements()
1268 switch (m_meshDimension)
1282 void MeshGraphXml::ReadElements1D()
1284 TiXmlElement *field = NULL;
1287 field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1289 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1294 TiXmlElement *segment = field->FirstChildElement(
"S");
1295 CurveMap::iterator it;
1300 int err = segment->QueryIntAttribute(
"ID", &indx);
1301 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1303 TiXmlNode *elementChild = segment->FirstChild();
1304 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1306 elementChild = elementChild->NextSibling();
1309 ASSERTL0(elementChild,
"Unable to read element description body.");
1310 std::string elementStr = elementChild->ToText()->ValueStr();
1315 int vertex1, vertex2;
1316 std::istringstream elementDataStrm(elementStr.c_str());
1320 elementDataStrm >> vertex1;
1321 elementDataStrm >> vertex2;
1324 (std::string(
"Unable to read element data for SEGMENT: ") +
1329 GetVertex(vertex2)};
1331 it = m_curvedEdges.find(indx);
1333 if (it == m_curvedEdges.end())
1336 indx, m_spaceDimension, vertices);
1337 seg->SetGlobalID(indx);
1342 indx, m_spaceDimension, vertices, it->second);
1343 seg->SetGlobalID(indx);
1345 seg->SetGlobalID(indx);
1346 m_segGeoms[indx] = seg;
1351 (std::string(
"Unable to read element data for segment: ") +
1356 segment = segment->NextSiblingElement(
"S");
1360 void MeshGraphXml::ReadElements2D()
1363 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1365 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1368 CurveMap::iterator it;
1373 TiXmlElement *element = field->FirstChildElement();
1377 std::string elementType(element->ValueStr());
1380 elementType ==
"Q" || elementType ==
"T",
1381 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
1385 int err = element->QueryIntAttribute(
"ID", &indx);
1386 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1388 it = m_curvedFaces.find(indx);
1391 TiXmlNode *elementChild = element->FirstChild();
1392 std::string elementStr;
1393 while (elementChild)
1395 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1397 elementStr += elementChild->ToText()->ValueStr();
1399 elementChild = elementChild->NextSibling();
1403 "Unable to read element description body.");
1407 if (elementType ==
"T")
1410 int edge1, edge2, edge3;
1411 std::istringstream elementDataStrm(elementStr.c_str());
1415 elementDataStrm >> edge1;
1416 elementDataStrm >> edge2;
1417 elementDataStrm >> edge3;
1420 !elementDataStrm.fail(),
1421 (std::string(
"Unable to read element data for TRIANGLE: ") +
1427 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3)};
1430 if (it == m_curvedFaces.end())
1438 indx, edges, it->second);
1440 trigeom->SetGlobalID(indx);
1442 m_triGeoms[indx] = trigeom;
1448 (std::string(
"Unable to read element data for TRIANGLE: ") +
1453 else if (elementType ==
"Q")
1456 int edge1, edge2, edge3, edge4;
1457 std::istringstream elementDataStrm(elementStr.c_str());
1461 elementDataStrm >> edge1;
1462 elementDataStrm >> edge2;
1463 elementDataStrm >> edge3;
1464 elementDataStrm >> edge4;
1467 !elementDataStrm.fail(),
1468 (std::string(
"Unable to read element data for QUAD: ") +
1474 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3),
1478 if (it == m_curvedFaces.end())
1486 indx, edges, it->second);
1488 quadgeom->SetGlobalID(indx);
1490 m_quadGeoms[indx] = quadgeom;
1496 (std::string(
"Unable to read element data for QUAD: ") +
1502 element = element->NextSiblingElement();
1506 void MeshGraphXml::ReadElements3D()
1509 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1511 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1516 TiXmlElement *element = field->FirstChildElement();
1520 std::string elementType(element->ValueStr());
1524 elementType ==
"A" || elementType ==
"P" || elementType ==
"R" ||
1526 (std::string(
"Unknown 3D element type: ") + elementType).c_str());
1530 int err = element->QueryIntAttribute(
"ID", &indx);
1531 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1534 TiXmlNode *elementChild = element->FirstChild();
1535 std::string elementStr;
1536 while (elementChild)
1538 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1540 elementStr += elementChild->ToText()->ValueStr();
1542 elementChild = elementChild->NextSibling();
1546 "Unable to read element description body.");
1548 std::istringstream elementDataStrm(elementStr.c_str());
1554 if (elementType ==
"A")
1559 const int kNfaces = TetGeom::kNfaces;
1560 const int kNtfaces = TetGeom::kNtfaces;
1561 const int kNqfaces = TetGeom::kNqfaces;
1568 std::stringstream errorstring;
1569 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1570 <<
" triangle face(s), and " << kNqfaces
1571 <<
" quadrilateral face(s).";
1572 for (
int i = 0; i < kNfaces; i++)
1575 elementDataStrm >> faceID;
1581 std::stringstream errorstring;
1582 errorstring <<
"Element " << indx
1583 <<
" has invalid face: " << faceID;
1584 ASSERTL0(
false, errorstring.str().c_str());
1588 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1590 static_pointer_cast<TriGeom>(face);
1592 else if (face->GetShapeType() ==
1595 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1603 "Unable to read element data for TETRAHEDRON: ") +
1606 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1607 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1612 m_tetGeoms[indx] = tetgeom;
1613 PopulateFaceToElMap(tetgeom, kNfaces);
1619 "Unable to read element data for TETRAHEDRON: ") +
1625 else if (elementType ==
"P")
1630 const int kNfaces = PyrGeom::kNfaces;
1631 const int kNtfaces = PyrGeom::kNtfaces;
1632 const int kNqfaces = PyrGeom::kNqfaces;
1640 std::stringstream errorstring;
1641 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1642 <<
" triangle face(s), and " << kNqfaces
1643 <<
" quadrilateral face(s).";
1644 for (
int i = 0; i < kNfaces; i++)
1647 elementDataStrm >> faceID;
1653 std::stringstream errorstring;
1654 errorstring <<
"Element " << indx
1655 <<
" has invalid face: " << faceID;
1656 ASSERTL0(
false, errorstring.str().c_str());
1660 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1662 static_pointer_cast<TriGeom>(face);
1665 else if (face->GetShapeType() ==
1668 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1670 static_pointer_cast<QuadGeom>(face);
1678 !elementDataStrm.fail(),
1679 (std::string(
"Unable to read element data for PYRAMID: ") +
1682 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1683 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1688 m_pyrGeoms[indx] = pyrgeom;
1689 PopulateFaceToElMap(pyrgeom, kNfaces);
1695 (std::string(
"Unable to read element data for PYRAMID: ") +
1701 else if (elementType ==
"R")
1706 const int kNfaces = PrismGeom::kNfaces;
1707 const int kNtfaces = PrismGeom::kNtfaces;
1708 const int kNqfaces = PrismGeom::kNqfaces;
1716 std::stringstream errorstring;
1717 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1718 <<
" triangle face(s), and " << kNqfaces
1719 <<
" quadrilateral face(s).";
1721 for (
int i = 0; i < kNfaces; i++)
1724 elementDataStrm >> faceID;
1730 std::stringstream errorstring;
1731 errorstring <<
"Element " << indx
1732 <<
" has invalid face: " << faceID;
1733 ASSERTL0(
false, errorstring.str().c_str());
1737 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1739 std::static_pointer_cast<TriGeom>(face);
1742 else if (face->GetShapeType() ==
1745 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1747 std::static_pointer_cast<QuadGeom>(face);
1755 !elementDataStrm.fail(),
1756 (std::string(
"Unable to read element data for PRISM: ") +
1759 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1760 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1765 m_prismGeoms[indx] = prismgeom;
1766 PopulateFaceToElMap(prismgeom, kNfaces);
1772 (std::string(
"Unable to read element data for PRISM: ") +
1778 else if (elementType ==
"H")
1783 const int kNfaces = HexGeom::kNfaces;
1784 const int kNtfaces = HexGeom::kNtfaces;
1785 const int kNqfaces = HexGeom::kNqfaces;
1793 std::stringstream errorstring;
1794 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1795 <<
" triangle face(s), and " << kNqfaces
1796 <<
" quadrilateral face(s).";
1797 for (
int i = 0; i < kNfaces; i++)
1800 elementDataStrm >> faceID;
1806 std::stringstream errorstring;
1807 errorstring <<
"Element " << indx
1808 <<
" has invalid face: " << faceID;
1809 ASSERTL0(
false, errorstring.str().c_str());
1813 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1817 else if (face->GetShapeType() ==
1820 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1822 std::static_pointer_cast<QuadGeom>(face);
1830 "Unable to read element data for HEXAHEDRAL: ") +
1833 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1834 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1839 m_hexGeoms[indx] = hexgeom;
1840 PopulateFaceToElMap(hexgeom, kNfaces);
1846 "Unable to read element data for HEXAHEDRAL: ") +
1852 element = element->NextSiblingElement();
1856 void MeshGraphXml::ReadComposites()
1858 TiXmlElement *field = NULL;
1861 field = m_xmlGeom->FirstChildElement(
"COMPOSITE");
1863 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
1865 TiXmlElement *node = field->FirstChildElement(
"C");
1868 int nextCompositeNumber = -1;
1875 nextCompositeNumber++;
1878 int err = node->QueryIntAttribute(
"ID", &indx);
1879 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
1883 TiXmlNode *compositeChild = node->FirstChild();
1888 while (compositeChild &&
1889 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
1891 compositeChild = compositeChild->NextSibling();
1894 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
1895 std::string compositeStr = compositeChild->ToText()->ValueStr();
1899 std::istringstream compositeDataStrm(compositeStr.c_str());
1904 std::string prevCompositeElementStr;
1906 while (!compositeDataStrm.fail())
1908 std::string compositeElementStr;
1909 compositeDataStrm >> compositeElementStr;
1911 if (!compositeDataStrm.fail())
1919 m_meshComposites[indx] = curVector;
1922 if (compositeElementStr.length() > 0)
1924 ResolveGeomRef(prevCompositeElementStr,
1925 compositeElementStr,
1926 m_meshComposites[indx]);
1928 prevCompositeElementStr = compositeElementStr;
1936 (std::string(
"Unable to read COMPOSITE data for composite: ") +
1942 node = node->NextSiblingElement(
"C");
1946 "At least one composite must be specified.");
1949 void MeshGraphXml::ResolveGeomRef(
const std::string &prevToken,
1950 const std::string &token,
1953 switch (m_meshDimension)
1956 ResolveGeomRef1D(prevToken, token, composite);
1959 ResolveGeomRef2D(prevToken, token, composite);
1962 ResolveGeomRef3D(prevToken, token, composite);
1967 void MeshGraphXml::ResolveGeomRef1D(
const std::string &prevToken,
1968 const std::string &token,
1973 std::istringstream tokenStream(token);
1974 std::istringstream prevTokenStream(prevToken);
1979 tokenStream >> type;
1981 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
1982 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
1986 (std::string(
"Error reading index definition:") + token).c_str());
1988 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
1990 typedef vector<unsigned int> SeqVectorType;
1991 SeqVectorType seqVector;
1993 if (!ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector))
1996 (std::string(
"Ill-formed sequence definition: ") + indxStr)
2000 prevTokenStream >> prevType;
2003 bool validSequence =
2004 (prevToken.empty() ||
2005 (type ==
'V' && prevType ==
'V') ||
2006 (type ==
'S' && prevType ==
'S'));
2009 (std::string(
"Invalid combination of composite items: ") +
2010 type +
" and " + prevType +
".")
2016 for (SeqVectorType::iterator iter = seqVector.begin();
2017 iter != seqVector.end(); ++iter)
2019 if (m_vertSet.find(*iter) == m_vertSet.end())
2021 char errStr[16] =
"";
2022 ::sprintf(errStr,
"%d", *iter);
2024 ErrorUtil::ewarning,
2025 (std::string(
"Unknown vertex index: ") + errStr)
2030 composite->m_geomVec.push_back(m_vertSet[*iter]);
2036 for (SeqVectorType::iterator iter = seqVector.begin();
2037 iter != seqVector.end(); ++iter)
2039 if (m_segGeoms.find(*iter) == m_segGeoms.end())
2041 char errStr[16] =
"";
2042 ::sprintf(errStr,
"%d", *iter);
2044 ErrorUtil::ewarning,
2045 (std::string(
"Unknown segment index: ") + errStr)
2050 composite->m_geomVec.push_back(m_segGeoms[*iter]);
2057 (std::string(
"Unrecognized composite token: ") + token)
2064 (std::string(
"Problem processing composite token: ") + token)
2071 void MeshGraphXml::ResolveGeomRef2D(
const std::string &prevToken,
2072 const std::string &token,
2077 std::istringstream tokenStream(token);
2078 std::istringstream prevTokenStream(prevToken);
2083 tokenStream >> type;
2085 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2086 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2090 (std::string(
"Error reading index definition:") + token).c_str());
2092 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2093 std::vector<unsigned int> seqVector;
2094 std::vector<unsigned int>::iterator seqIter;
2096 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
2099 (std::string(
"Error reading composite elements: ") + indxStr)
2102 prevTokenStream >> prevType;
2105 bool validSequence =
2106 (prevToken.empty() ||
2107 (type ==
'V' && prevType ==
'V') ||
2108 (type ==
'E' && prevType ==
'E') ||
2109 ((type ==
'T' || type ==
'Q') &&
2110 (prevType ==
'T' || prevType ==
'Q')));
2113 (std::string(
"Invalid combination of composite items: ") +
2114 type +
" and " + prevType +
".")
2120 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2123 if (m_segGeoms.find(*seqIter) == m_segGeoms.end())
2125 char errStr[16] =
"";
2126 ::sprintf(errStr,
"%d", *seqIter);
2128 (std::string(
"Unknown edge index: ") + errStr)
2133 composite->m_geomVec.push_back(m_segGeoms[*seqIter]);
2140 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2143 if (m_triGeoms.count(*seqIter) == 0)
2145 char errStr[16] =
"";
2146 ::sprintf(errStr,
"%d", *seqIter);
2148 ErrorUtil::ewarning,
2149 (std::string(
"Unknown triangle index: ") + errStr)
2154 if (CheckRange(*m_triGeoms[*seqIter]))
2156 composite->m_geomVec.push_back(
2157 m_triGeoms[*seqIter]);
2166 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2169 if (m_quadGeoms.count(*seqIter) == 0)
2171 char errStr[16] =
"";
2172 ::sprintf(errStr,
"%d", *seqIter);
2174 (std::string(
"Unknown quad index: ") + errStr +
2175 std::string(
" in Composite section"))
2180 if (CheckRange(*m_quadGeoms[*seqIter]))
2182 composite->m_geomVec.push_back(
2183 m_quadGeoms[*seqIter]);
2191 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2194 if (*seqIter >= m_vertSet.size())
2196 char errStr[16] =
"";
2197 ::sprintf(errStr,
"%d", *seqIter);
2199 ErrorUtil::ewarning,
2200 (std::string(
"Unknown vertex index: ") + errStr)
2205 composite->m_geomVec.push_back(m_vertSet[*seqIter]);
2212 (std::string(
"Unrecognized composite token: ") + token)
2219 (std::string(
"Problem processing composite token: ") + token)
2226 void MeshGraphXml::ResolveGeomRef3D(
const std::string &prevToken,
2227 const std::string &token,
2232 std::istringstream tokenStream(token);
2233 std::istringstream prevTokenStream(prevToken);
2238 tokenStream >> type;
2240 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2241 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2245 (std::string(
"Error reading index definition:") + token).c_str());
2247 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2249 std::vector<unsigned int> seqVector;
2250 std::vector<unsigned int>::iterator seqIter;
2252 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
2255 (std::string(
"Error reading composite elements: ") + indxStr)
2258 prevTokenStream >> prevType;
2262 map<char, int> typeMap;
2273 bool validSequence =
2274 (prevToken.empty() || (typeMap[type] == typeMap[prevType]));
2277 (std::string(
"Invalid combination of composite items: ") +
2278 type +
" and " + prevType +
".")
2284 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2287 if (m_vertSet.find(*seqIter) == m_vertSet.end())
2289 char errStr[16] =
"";
2290 ::sprintf(errStr,
"%d", *seqIter);
2292 ErrorUtil::ewarning,
2293 (std::string(
"Unknown vertex index: ") + errStr)
2298 composite->m_geomVec.push_back(m_vertSet[*seqIter]);
2304 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2307 if (m_segGeoms.find(*seqIter) == m_segGeoms.end())
2309 char errStr[16] =
"";
2310 ::sprintf(errStr,
"%d", *seqIter);
2312 (std::string(
"Unknown edge index: ") + errStr)
2317 composite->m_geomVec.push_back(m_segGeoms[*seqIter]);
2323 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2329 char errStr[16] =
"";
2330 ::sprintf(errStr,
"%d", *seqIter);
2332 (std::string(
"Unknown face index: ") + errStr)
2337 if (CheckRange(*face))
2339 composite->m_geomVec.push_back(face);
2346 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2349 if (m_triGeoms.find(*seqIter) == m_triGeoms.end())
2351 char errStr[16] =
"";
2352 ::sprintf(errStr,
"%d", *seqIter);
2354 ErrorUtil::ewarning,
2355 (std::string(
"Unknown triangle index: ") + errStr)
2360 if (CheckRange(*m_triGeoms[*seqIter]))
2362 composite->m_geomVec.push_back(
2363 m_triGeoms[*seqIter]);
2370 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2373 if (m_quadGeoms.find(*seqIter) == m_quadGeoms.end())
2375 char errStr[16] =
"";
2376 ::sprintf(errStr,
"%d", *seqIter);
2378 (std::string(
"Unknown quad index: ") + errStr)
2383 if (CheckRange(*m_quadGeoms[*seqIter]))
2385 composite->m_geomVec.push_back(
2386 m_quadGeoms[*seqIter]);
2394 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2397 if (m_tetGeoms.find(*seqIter) == m_tetGeoms.end())
2399 char errStr[16] =
"";
2400 ::sprintf(errStr,
"%d", *seqIter);
2402 (std::string(
"Unknown tet index: ") + errStr)
2407 if (CheckRange(*m_tetGeoms[*seqIter]))
2409 composite->m_geomVec.push_back(
2410 m_tetGeoms[*seqIter]);
2418 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2421 if (m_pyrGeoms.find(*seqIter) == m_pyrGeoms.end())
2423 char errStr[16] =
"";
2424 ::sprintf(errStr,
"%d", *seqIter);
2426 ErrorUtil::ewarning,
2427 (std::string(
"Unknown pyramid index: ") + errStr)
2432 if (CheckRange(*m_pyrGeoms[*seqIter]))
2434 composite->m_geomVec.push_back(
2435 m_pyrGeoms[*seqIter]);
2443 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2446 if (m_prismGeoms.find(*seqIter) == m_prismGeoms.end())
2448 char errStr[16] =
"";
2449 ::sprintf(errStr,
"%d", *seqIter);
2451 (std::string(
"Unknown prism index: ") + errStr)
2456 if (CheckRange(*m_prismGeoms[*seqIter]))
2458 composite->m_geomVec.push_back(
2459 m_prismGeoms[*seqIter]);
2467 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2470 if (m_hexGeoms.find(*seqIter) == m_hexGeoms.end())
2472 char errStr[16] =
"";
2473 ::sprintf(errStr,
"%d", *seqIter);
2475 (std::string(
"Unknown hex index: ") + errStr)
2480 if (CheckRange(*m_hexGeoms[*seqIter]))
2482 composite->m_geomVec.push_back(
2483 m_hexGeoms[*seqIter]);
2491 (std::string(
"Unrecognized composite token: ") + token)
2498 (std::string(
"Problem processing composite token: ") + token)
2505 void MeshGraphXml::WriteVertices(TiXmlElement *geomTag,
PointGeomMap &verts)
2507 TiXmlElement *vertTag =
new TiXmlElement(
"VERTEX");
2509 for (
auto &i : verts)
2512 s << scientific << setprecision(8) << (*i.second)(0) <<
" "
2513 << (*i.second)(1) <<
" " << (*i.second)(2);
2514 TiXmlElement *v =
new TiXmlElement(
"V");
2515 v->SetAttribute(
"ID", i.second->GetGlobalID());
2516 v->LinkEndChild(
new TiXmlText(s.str()));
2517 vertTag->LinkEndChild(v);
2520 geomTag->LinkEndChild(vertTag);
2523 void MeshGraphXml::WriteEdges(TiXmlElement *geomTag,
SegGeomMap &edges)
2525 TiXmlElement *edgeTag =
2526 new TiXmlElement(m_meshDimension == 1 ?
"ELEMENT" :
"EDGE");
2527 string tag = m_meshDimension == 1 ?
"S" :
"E";
2529 for (
auto &i : edges)
2533 s << seg->GetVid(0) <<
" " << seg->GetVid(1);
2534 TiXmlElement *e =
new TiXmlElement(tag);
2535 e->SetAttribute(
"ID", i.first);
2536 e->LinkEndChild(
new TiXmlText(s.str()));
2537 edgeTag->LinkEndChild(e);
2540 geomTag->LinkEndChild(edgeTag);
2543 void MeshGraphXml::WriteTris(TiXmlElement *faceTag,
TriGeomMap &tris)
2547 for (
auto &i : tris)
2551 s << tri->GetEid(0) <<
" " << tri->GetEid(1) <<
" " << tri->GetEid(2);
2552 TiXmlElement *t =
new TiXmlElement(tag);
2553 t->SetAttribute(
"ID", i.first);
2554 t->LinkEndChild(
new TiXmlText(s.str()));
2555 faceTag->LinkEndChild(t);
2559 void MeshGraphXml::WriteQuads(TiXmlElement *faceTag,
QuadGeomMap &quads)
2563 for (
auto &i : quads)
2567 s << quad->GetEid(0) <<
" " << quad->GetEid(1) <<
" " << quad->GetEid(2)
2568 <<
" " << quad->GetEid(3);
2569 TiXmlElement *q =
new TiXmlElement(tag);
2570 q->SetAttribute(
"ID", i.first);
2571 q->LinkEndChild(
new TiXmlText(s.str()));
2572 faceTag->LinkEndChild(q);
2576 void MeshGraphXml::WriteHexs(TiXmlElement *elmtTag,
HexGeomMap &hexs)
2580 for (
auto &i : hexs)
2584 s << hex->GetFid(0) <<
" " << hex->GetFid(1) <<
" " << hex->GetFid(2)
2585 <<
" " << hex->GetFid(3) <<
" " << hex->GetFid(4) <<
" "
2586 << hex->GetFid(5) <<
" ";
2587 TiXmlElement *h =
new TiXmlElement(tag);
2588 h->SetAttribute(
"ID", i.first);
2589 h->LinkEndChild(
new TiXmlText(s.str()));
2590 elmtTag->LinkEndChild(h);
2598 for (
auto &i : pris)
2602 s << prism->GetFid(0) <<
" " << prism->GetFid(1) <<
" "
2603 << prism->GetFid(2) <<
" " << prism->GetFid(3) <<
" "
2604 << prism->GetFid(4) <<
" ";
2605 TiXmlElement *
p =
new TiXmlElement(tag);
2606 p->SetAttribute(
"ID", i.first);
2607 p->LinkEndChild(
new TiXmlText(s.str()));
2608 elmtTag->LinkEndChild(
p);
2612 void MeshGraphXml::WritePyrs(TiXmlElement *elmtTag,
PyrGeomMap &pyrs)
2616 for (
auto &i : pyrs)
2620 s << pyr->GetFid(0) <<
" " << pyr->GetFid(1) <<
" " << pyr->GetFid(2)
2621 <<
" " << pyr->GetFid(3) <<
" " << pyr->GetFid(4) <<
" ";
2622 TiXmlElement *
p =
new TiXmlElement(tag);
2623 p->SetAttribute(
"ID", i.first);
2624 p->LinkEndChild(
new TiXmlText(s.str()));
2625 elmtTag->LinkEndChild(
p);
2629 void MeshGraphXml::WriteTets(TiXmlElement *elmtTag,
TetGeomMap &tets)
2633 for (
auto &i : tets)
2637 s << tet->GetFid(0) <<
" " << tet->GetFid(1) <<
" " << tet->GetFid(2)
2638 <<
" " << tet->GetFid(3) <<
" ";
2639 TiXmlElement *t =
new TiXmlElement(tag);
2640 t->SetAttribute(
"ID", i.first);
2641 t->LinkEndChild(
new TiXmlText(s.str()));
2642 elmtTag->LinkEndChild(t);
2646 void MeshGraphXml::WriteCurves(TiXmlElement *geomTag,
CurveMap &edges,
2649 TiXmlElement *curveTag =
new TiXmlElement(
"CURVED");
2650 CurveMap::iterator curveIt;
2653 for (curveIt = edges.begin(); curveIt != edges.end(); ++curveIt)
2656 TiXmlElement *c =
new TiXmlElement(
"E");
2660 for (
int j = 0; j < curve->m_points.size(); ++j)
2663 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2667 c->SetAttribute(
"ID", curveId++);
2668 c->SetAttribute(
"EDGEID", curve->m_curveID);
2669 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2671 c->LinkEndChild(
new TiXmlText(s.str()));
2672 curveTag->LinkEndChild(c);
2675 for (curveIt = faces.begin(); curveIt != faces.end(); ++curveIt)
2678 TiXmlElement *c =
new TiXmlElement(
"F");
2682 for (
int j = 0; j < curve->m_points.size(); ++j)
2685 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2689 c->SetAttribute(
"ID", curveId++);
2690 c->SetAttribute(
"FACEID", curve->m_curveID);
2691 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2693 c->LinkEndChild(
new TiXmlText(s.str()));
2694 curveTag->LinkEndChild(c);
2697 geomTag->LinkEndChild(curveTag);
2700 void MeshGraphXml::WriteComposites(TiXmlElement *geomTag,
CompositeMap &comps)
2702 TiXmlElement *compTag =
new TiXmlElement(
"COMPOSITE");
2704 for (
auto &cIt : comps)
2706 if (cIt.second->m_geomVec.size() == 0)
2711 TiXmlElement *c =
new TiXmlElement(
"C");
2712 c->SetAttribute(
"ID", cIt.first);
2713 c->LinkEndChild(
new TiXmlText(GetCompositeString(cIt.second)));
2714 compTag->LinkEndChild(c);
2717 geomTag->LinkEndChild(compTag);
2720 void MeshGraphXml::WriteDomain(TiXmlElement *geomTag,
2721 vector<CompositeMap> &domain)
2723 TiXmlElement *domTag =
new TiXmlElement(
"DOMAIN");
2724 stringstream domString;
2727 vector<unsigned int> idxList;
2728 for (
auto cIt = domain[0].begin(); cIt != domain[0].end(); ++cIt)
2730 idxList.push_back(cIt->first);
2733 domString <<
" C[" << ParseUtils::GenerateSeqString(idxList) <<
"] ";
2734 domTag->LinkEndChild(
new TiXmlText(domString.str()));
2735 geomTag->LinkEndChild(domTag);
2738 void MeshGraphXml::WriteDefaultExpansion(TiXmlElement *root)
2740 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
2742 for (
auto it = m_meshComposites.begin(); it != m_meshComposites.end(); it++)
2744 if (it->second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
2746 TiXmlElement *exp =
new TiXmlElement(
"E");
2747 exp->SetAttribute(
"COMPOSITE",
2748 "C[" + boost::lexical_cast<string>(it->first) +
2750 exp->SetAttribute(
"NUMMODES", 4);
2751 exp->SetAttribute(
"TYPE",
"MODIFIED");
2752 exp->SetAttribute(
"FIELDS",
"u");
2754 expTag->LinkEndChild(exp);
2757 root->LinkEndChild(expTag);
2764 void MeshGraphXml::WriteGeometry(
2765 std::string &outfilename,
2771 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2772 doc.LinkEndChild(decl);
2774 TiXmlElement *root =
new TiXmlElement(
"NEKTAR");
2775 doc.LinkEndChild(root);
2776 TiXmlElement *geomTag =
new TiXmlElement(
"GEOMETRY");
2777 root->LinkEndChild(geomTag);
2780 LibUtilities::FieldIO::AddInfoTag(
2786 geomTag->SetAttribute(
"DIM", m_meshDimension);
2787 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
2793 WriteVertices(geomTag, m_vertSet);
2794 WriteEdges(geomTag, m_segGeoms);
2795 if (m_meshDimension > 1)
2797 TiXmlElement *faceTag =
2798 new TiXmlElement(m_meshDimension == 2 ?
"ELEMENT" :
"FACE");
2800 WriteTris(faceTag, m_triGeoms);
2801 WriteQuads(faceTag, m_quadGeoms);
2802 geomTag->LinkEndChild(faceTag);
2804 if (m_meshDimension > 2)
2806 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
2808 WriteHexs(elmtTag, m_hexGeoms);
2809 WritePyrs(elmtTag, m_pyrGeoms);
2810 WritePrisms(elmtTag, m_prismGeoms);
2811 WriteTets(elmtTag, m_tetGeoms);
2813 geomTag->LinkEndChild(elmtTag);
2815 WriteCurves(geomTag, m_curvedEdges, m_curvedFaces);
2816 WriteComposites(geomTag, m_meshComposites);
2817 WriteDomain(geomTag, m_domain);
2821 WriteDefaultExpansion(root);
2825 doc.SaveFile(outfilename);
2828 void MeshGraphXml::WriteXMLGeometry(std::string outname,
2829 vector<set<unsigned int>> elements,
2830 vector<unsigned int> partitions)
2841 string dirname = outname +
"_xml";
2842 boost::filesystem::path pdirname(dirname);
2844 if (!boost::filesystem::is_directory(dirname))
2846 boost::filesystem::create_directory(dirname);
2849 ASSERTL0(elements.size() == partitions.size(),
2850 "error in partitioned information");
2852 for (
int i = 0; i < partitions.size(); i++)
2855 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2856 doc.LinkEndChild(decl);
2858 TiXmlElement *root = doc.FirstChildElement(
"NEKTAR");
2859 TiXmlElement *geomTag;
2864 root =
new TiXmlElement(
"NEKTAR");
2865 doc.LinkEndChild(root);
2867 geomTag =
new TiXmlElement(
"GEOMETRY");
2868 root->LinkEndChild(geomTag);
2873 geomTag = root->FirstChildElement(
"GEOMETRY");
2877 geomTag =
new TiXmlElement(
"GEOMETRY");
2878 root->LinkEndChild(geomTag);
2882 geomTag->SetAttribute(
"DIM", m_meshDimension);
2883 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
2884 geomTag->SetAttribute(
"PARTITION", partitions[i]);
2899 vector<set<unsigned int>> entityIds(4);
2900 entityIds[m_meshDimension] = elements[i];
2902 switch (m_meshDimension)
2906 for (
auto &j : entityIds[3])
2909 if (m_hexGeoms.count(j))
2912 localHex[j] = m_hexGeoms[j];
2914 else if (m_pyrGeoms.count(j))
2917 localPyr[j] = m_pyrGeoms[j];
2919 else if (m_prismGeoms.count(j))
2921 g = m_prismGeoms[j];
2922 localPrism[j] = m_prismGeoms[j];
2924 else if (m_tetGeoms.count(j))
2927 localTet[j] = m_tetGeoms[j];
2931 ASSERTL0(
false,
"element in partition not found");
2934 for (
int k = 0; k < g->GetNumFaces(); k++)
2936 entityIds[2].insert(g->GetFid(k));
2938 for (
int k = 0; k < g->GetNumEdges(); k++)
2940 entityIds[1].insert(g->GetEid(k));
2942 for (
int k = 0; k < g->GetNumVerts(); k++)
2944 entityIds[0].insert(g->GetVid(k));
2951 for (
auto &j : entityIds[2])
2954 if (m_triGeoms.count(j))
2957 localTri[j] = m_triGeoms[j];
2959 else if (m_quadGeoms.count(j))
2962 localQuad[j] = m_quadGeoms[j];
2966 ASSERTL0(
false,
"element in partition not found");
2969 for (
int k = 0; k < g->GetNumEdges(); k++)
2971 entityIds[1].insert(g->GetEid(k));
2973 for (
int k = 0; k < g->GetNumVerts(); k++)
2975 entityIds[0].insert(g->GetVid(k));
2982 for (
auto &j : entityIds[1])
2985 if (m_segGeoms.count(j))
2988 localEdge[j] = m_segGeoms[j];
2992 ASSERTL0(
false,
"element in partition not found");
2995 for (
int k = 0; k < g->GetNumVerts(); k++)
2997 entityIds[0].insert(g->GetVid(k));
3003 if (m_meshDimension > 2)
3005 for (
auto &j : entityIds[2])
3007 if (m_triGeoms.count(j))
3009 localTri[j] = m_triGeoms[j];
3011 else if (m_quadGeoms.count(j))
3013 localQuad[j] = m_quadGeoms[j];
3022 if (m_meshDimension > 1)
3024 for (
auto &j : entityIds[1])
3026 if (m_segGeoms.count(j))
3028 localEdge[j] = m_segGeoms[j];
3037 for (
auto &j : entityIds[0])
3039 if (m_vertSet.count(j))
3041 localVert[j] = m_vertSet[j];
3049 WriteVertices(geomTag, localVert);
3050 WriteEdges(geomTag, localEdge);
3051 if (m_meshDimension > 1)
3053 TiXmlElement *faceTag =
3054 new TiXmlElement(m_meshDimension == 2 ?
"ELEMENT" :
"FACE");
3056 WriteTris(faceTag, localTri);
3057 WriteQuads(faceTag, localQuad);
3058 geomTag->LinkEndChild(faceTag);
3060 if (m_meshDimension > 2)
3062 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3064 WriteHexs(elmtTag, localHex);
3065 WritePyrs(elmtTag, localPyr);
3066 WritePrisms(elmtTag, localPrism);
3067 WriteTets(elmtTag, localTet);
3069 geomTag->LinkEndChild(elmtTag);
3072 for (
auto &j : localTri)
3074 if (m_curvedFaces.count(j.first))
3076 localCurveFace[j.first] = m_curvedFaces[j.first];
3079 for (
auto &j : localQuad)
3081 if (m_curvedFaces.count(j.first))
3083 localCurveFace[j.first] = m_curvedFaces[j.first];
3086 for (
auto &j : localEdge)
3088 if (m_curvedEdges.count(j.first))
3090 localCurveEdge[j.first] = m_curvedEdges[j.first];
3094 WriteCurves(geomTag, localCurveEdge, localCurveFace);
3098 for (
auto &j : m_meshComposites)
3101 int dim = j.second->m_geomVec[0]->GetShapeDim();
3103 for (
int k = 0; k < j.second->m_geomVec.size(); k++)
3105 if (entityIds[dim].count(j.second->m_geomVec[k]->GetGlobalID()))
3107 comp->m_geomVec.push_back(j.second->m_geomVec[k]);
3111 if (comp->m_geomVec.size())
3113 localComp[j.first] = comp;
3117 WriteComposites(geomTag, localComp);
3119 vector<CompositeMap> domain;
3121 for (
auto &j : localComp)
3123 if (j.second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
3125 domMap[j.first] = j.second;
3128 domain.push_back(domMap);
3130 WriteDomain(geomTag, domain);
3132 if (m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
3134 std::set<int> vBndRegionIdList;
3135 TiXmlElement *vConditions =
3136 new TiXmlElement(*m_session->GetElement(
"Nektar/Conditions"));
3137 TiXmlElement *vBndRegions =
3138 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
3139 TiXmlElement *vBndConditions =
3140 vConditions->FirstChildElement(
"BOUNDARYCONDITIONS");
3141 TiXmlElement *vItem;
3145 TiXmlElement *vNewBndRegions =
3146 new TiXmlElement(
"BOUNDARYREGIONS");
3147 vItem = vBndRegions->FirstChildElement();
3150 std::string vSeqStr =
3151 vItem->FirstChild()->ToText()->Value();
3152 std::string::size_type indxBeg =
3153 vSeqStr.find_first_of(
'[') + 1;
3154 std::string::size_type indxEnd =
3155 vSeqStr.find_last_of(
']') - 1;
3156 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
3157 std::vector<unsigned int> vSeq;
3158 ParseUtils::GenerateSeqVector(vSeqStr.c_str(), vSeq);
3160 vector<unsigned int> idxList;
3162 for (
unsigned int i = 0; i < vSeq.size(); ++i)
3164 if (localComp.find(vSeq[i]) != localComp.end())
3166 idxList.push_back(vSeq[i]);
3169 int p = atoi(vItem->Attribute(
"ID"));
3171 std::string vListStr =
3172 ParseUtils::GenerateSeqString(idxList);
3174 if (vListStr.length() == 0)
3176 TiXmlElement *tmp = vItem;
3177 vItem = vItem->NextSiblingElement();
3178 vBndRegions->RemoveChild(tmp);
3182 vListStr =
"C[" + vListStr +
"]";
3183 TiXmlText *vList =
new TiXmlText(vListStr);
3184 TiXmlElement *vNewElement =
new TiXmlElement(
"B");
3185 vNewElement->SetAttribute(
"ID",
p);
3186 vNewElement->LinkEndChild(vList);
3187 vNewBndRegions->LinkEndChild(vNewElement);
3188 vBndRegionIdList.insert(
p);
3189 vItem = vItem->NextSiblingElement();
3193 m_bndRegOrder[
p] = vSeq;
3195 vConditions->ReplaceChild(vBndRegions, *vNewBndRegions);
3200 vItem = vBndConditions->FirstChildElement();
3203 std::set<int>::iterator x;
3204 if ((x = vBndRegionIdList.find(atoi(vItem->Attribute(
3205 "REF")))) != vBndRegionIdList.end())
3207 vItem->SetAttribute(
"REF", *x);
3208 vItem = vItem->NextSiblingElement();
3212 TiXmlElement *tmp = vItem;
3213 vItem = vItem->NextSiblingElement();
3214 vBndConditions->RemoveChild(tmp);
3218 root->LinkEndChild(vConditions);
3222 TiXmlElement *vSrc =
3223 m_session->GetElement(
"Nektar")->FirstChildElement();
3226 std::string vName = boost::to_upper_copy(vSrc->ValueStr());
3227 if (vName !=
"GEOMETRY" && vName !=
"CONDITIONS")
3229 root->LinkEndChild(
new TiXmlElement(*vSrc));
3231 vSrc = vSrc->NextSiblingElement();
3237 pad % partitions[i];
3238 boost::filesystem::path pFilename(pad.str());
3240 boost::filesystem::path fullpath = pdirname / pFilename;
3249 for (
auto &c : m_meshComposites)
3251 std::vector<unsigned int> ids;
3252 for (
auto &elmt : c.second->m_geomVec)
3254 ids.push_back(elmt->GetGlobalID());
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Interpreter class for the evaluation of mathematical expressions.
int DefineFunction(const std::string &vlist, const std::string &expr)
Defines a function for the purposes of evaluation.
NekDouble Evaluate(const int id)
Evaluate a function which depends only on constants and/or parameters.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::map< std::string, std::string > FieldMetaDataMap
const std::string kPointsTypeStr[]
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
std::shared_ptr< XmlTagWriter > XmlTagWriterSharedPtr
static DomainRangeShPtr NullDomainRangeShPtr
@ SIZE_PointsType
Length of enum list.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, TriGeomSharedPtr > TriGeomMap
std::map< int, std::vector< unsigned int > > CompositeOrdering
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
std::map< int, PyrGeomSharedPtr > PyrGeomMap
std::map< int, QuadGeomSharedPtr > QuadGeomMap
std::shared_ptr< PrismGeom > PrismGeomSharedPtr
MeshPartitionFactory & GetMeshPartitionFactory()
std::map< int, SegGeomSharedPtr > SegGeomMap
std::shared_ptr< Curve > CurveSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
std::map< int, CompositeSharedPtr > CompositeMap
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::map< int, TetGeomSharedPtr > TetGeomMap
std::shared_ptr< PyrGeom > PyrGeomSharedPtr
std::shared_ptr< TetGeom > TetGeomSharedPtr
std::map< int, PrismGeomSharedPtr > PrismGeomMap
std::shared_ptr< HexGeom > HexGeomSharedPtr
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::shared_ptr< Geometry > GeometrySharedPtr
std::shared_ptr< TriGeom > TriGeomSharedPtr
MeshGraphFactory & GetMeshGraphFactory()
std::shared_ptr< Composite > CompositeSharedPtr
std::map< int, HexGeomSharedPtr > HexGeomMap
std::map< int, PointGeomSharedPtr > PointGeomMap
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
The above copyright notice and this permission notice shall be included.