47#include <boost/format.hpp>
64 const bool isRoot = comm->TreatAsRankZero();
78 int isPartitioned = 0;
81 if (
m_session->DefinesElement(
"Nektar/Geometry"))
83 if (
m_session->GetElement(
"Nektar/Geometry")
84 ->Attribute(
"PARTITION"))
86 std::cout <<
"Using pre-partitioned mesh." << std::endl;
90 ->QueryIntAttribute(
"DIM", &meshDimension);
93 comm->Bcast(isPartitioned, 0);
94 comm->Bcast(meshDimension, 0);
99 m_meshGraph->GetDomainRange()->m_compElmts = meshDimension;
119 std::string partitionerName =
"Scotch";
120 if (!haveScotch && haveMetis)
122 partitionerName =
"Metis";
126 if (session->DefinesCmdLineArgument(
"use-metis"))
128 partitionerName =
"Metis";
130 if (session->DefinesCmdLineArgument(
"use-scotch"))
132 partitionerName =
"Scotch";
138 if (session->DefinesCmdLineArgument(
"part-only") ||
139 session->DefinesCmdLineArgument(
"part-only-overlapping"))
144 "The 'part-only' option should be used in serial.");
155 partitionerName, session, session->GetComm(), meshDimension,
158 if (session->DefinesCmdLineArgument(
"part-only"))
160 nParts = session->GetCmdLineArgument<
int>(
"part-only");
161 partitioner->PartitionMesh(nParts,
true);
166 session->GetCmdLineArgument<
int>(
"part-only-overlapping");
167 partitioner->PartitionMesh(nParts,
true,
true);
170 std::vector<std::set<unsigned int>> elmtIDs;
171 std::vector<unsigned int> parts(nParts);
172 for (
int i = 0; i < nParts; ++i)
174 std::vector<unsigned int> elIDs;
175 std::set<unsigned int> tmp;
176 partitioner->GetElementIDs(i, elIDs);
177 tmp.insert(elIDs.begin(), elIDs.end());
178 elmtIDs.push_back(tmp);
184 if (isRoot && session->DefinesCmdLineArgument(
"part-info"))
186 partitioner->PrintPartInfo(std::cout);
193 if (commMesh->GetSize() > 1)
196 "Valid partitioner not found! Either Scotch or METIS "
199 int nParts = commMesh->GetSize();
201 if (session->GetSharedFilesystem())
203 std::vector<unsigned int> keys, vals;
219 partitionerName, session, session->GetComm(),
222 partitioner->PartitionMesh(nParts,
true);
224 std::vector<std::set<unsigned int>> elmtIDs;
225 std::vector<unsigned int> parts(nParts);
226 for (i = 0; i < nParts; ++i)
228 std::vector<unsigned int> elIDs;
229 std::set<unsigned int> tmp;
230 partitioner->GetElementIDs(i, elIDs);
231 tmp.insert(elIDs.begin(), elIDs.end());
232 elmtIDs.push_back(tmp);
248 comm->Bcast(keys, 0);
259 vals[i++] = cIt.second.size();
263 comm->Bcast(keys, 0);
264 comm->Bcast(vals, 0);
267 comm->Bcast(cIt.second, 0);
280 vals[i++] = bIt.second.size();
286 comm->Bcast(keys, 0);
290 comm->Bcast(vals, 0);
294 comm->Bcast(bIt.second, 0);
298 if (session->DefinesCmdLineArgument(
"part-info"))
300 partitioner->PrintPartInfo(std::cout);
306 comm->Bcast(keys, 0);
308 int cmpSize = keys[0];
309 int bndSize = keys[1];
311 keys.resize(cmpSize);
312 vals.resize(cmpSize);
313 comm->Bcast(keys, 0);
314 comm->Bcast(vals, 0);
316 for (
int i = 0; i < keys.size(); ++i)
318 std::vector<unsigned int> tmp(vals[i]);
324 keys.resize(bndSize);
325 vals.resize(bndSize);
328 comm->Bcast(keys, 0);
332 comm->Bcast(vals, 0);
334 for (
int i = 0; i < keys.size(); ++i)
336 std::vector<unsigned int> tmp(vals[i]);
357 partitionerName, session, session->GetComm(),
360 partitioner->PartitionMesh(nParts,
false);
362 std::vector<unsigned int> parts(1), tmp;
363 parts[0] = commMesh->GetRank();
364 std::vector<std::set<unsigned int>> elIDs(1);
365 partitioner->GetElementIDs(parts[0], tmp);
366 elIDs[0].insert(tmp.begin(), tmp.end());
375 if (
m_session->DefinesCmdLineArgument(
"part-info") && isRoot)
377 partitioner->PrintPartInfo(std::cout);
384 std::string dirname =
m_session->GetSessionName() +
"_xml";
385 fs::path pdirname(dirname);
386 boost::format pad(
"P%1$07d.xml");
387 pad % comm->GetRowComm()->GetRank();
388 fs::path pFilename(pad.str());
389 fs::path fullpath = pdirname / pFilename;
391 std::vector<std::string> filenames = {
410 const bool isRoot = comm->TreatAsRankZero();
412 if (!rng || rng->m_compElmts == 0)
417 TiXmlElement *field =
nullptr;
422 if (
m_session->DefinesElement(
"NEKTAR/GEOMETRY/COMPOSITE"))
425 field =
m_session->GetElement(
"NEKTAR/GEOMETRY/COMPOSITE");
432 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
434 TiXmlElement *node = field->FirstChildElement(
"C");
441 int err = node->QueryIntAttribute(
"ID", &indx);
442 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
444 if (rng->m_comps.count(indx))
447 TiXmlNode *compositeChild = node->FirstChild();
452 while (compositeChild &&
453 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
455 compositeChild = compositeChild->NextSibling();
459 "Unable to read composite definition body.");
460 std::string compositeStr = compositeChild->ToText()->ValueStr();
464 std::istringstream compositeDataStrm(compositeStr.c_str());
468 while (!compositeDataStrm.fail())
471 compositeDataStrm >> compStr;
473 if (compStr.length() > 0)
476 std::string::size_type indxBeg =
477 compStr.find_first_of(
'[') + 1;
478 std::string::size_type indxEnd =
479 compStr.find_last_of(
']') - 1;
483 "Error reading index definition:") +
487 std::string indxStr =
488 compStr.substr(indxBeg, indxEnd - indxBeg + 1);
489 std::vector<unsigned int> seqVector;
491 indxStr.c_str(), seqVector);
492 ASSERTL0(err,
"Error reading composite elements: " +
495 for (
auto it : seqVector)
497 rng->m_traceIDs.insert(it);
505 (std::string(
"Unable to read COMPOSITE data in "
506 "composite range setup: ") +
512 node = node->NextSiblingElement(
"C");
515 std::vector<unsigned> traceIDs;
516 unsigned nTraceIDs = rng->m_traceIDs.size();
518 comm->Bcast(nTraceIDs, 0);
520 for (
auto &It : rng->m_traceIDs)
522 traceIDs.push_back(It);
526 if (!traceIDs.empty())
528 comm->Bcast(traceIDs, 0);
534 comm->Bcast(nTraceIDs, 0);
536 std::vector<unsigned> traceIDs;
537 traceIDs.resize(nTraceIDs);
538 comm->Bcast(traceIDs, 0);
539 for (
auto &It : traceIDs)
541 rng->m_traceIDs.insert(It);
554 TiXmlAttribute *attr =
m_xmlGeom->FirstAttribute();
559 int meshDimension =
m_meshGraph->GetMeshDimension();
560 int spaceDimension =
m_meshGraph->GetSpaceDimension();
567 std::string attrName(attr->Name());
568 if (attrName ==
"DIM")
570 err = attr->QueryIntValue(&meshDimension);
571 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
573 else if (attrName ==
"SPACE")
575 err = attr->QueryIntValue(&spaceDimension);
576 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
578 else if (attrName ==
"PARTITION")
581 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read partition.");
587 std::string errstr(
"Unknown attribute: ");
599 ASSERTL0(meshDimension <= spaceDimension,
600 "Mesh dimension greater than space dimension");
604 if (meshDimension >= 2)
607 if (meshDimension == 3)
624 int spaceDimension =
m_meshGraph->GetSpaceDimension();
627 TiXmlElement *element =
m_xmlGeom->FirstChildElement(
"VERTEX");
628 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
635 const char *xscal = element->Attribute(
"XSCALE");
642 std::string xscalstr = xscal;
644 xscale = expEvaluator.
Evaluate(expr_id);
647 const char *yscal = element->Attribute(
"YSCALE");
654 std::string yscalstr = yscal;
656 yscale = expEvaluator.
Evaluate(expr_id);
659 const char *zscal = element->Attribute(
"ZSCALE");
666 std::string zscalstr = zscal;
668 zscale = expEvaluator.
Evaluate(expr_id);
676 const char *xmov = element->Attribute(
"XMOVE");
683 std::string xmovstr = xmov;
685 xmove = expEvaluator.
Evaluate(expr_id);
688 const char *ymov = element->Attribute(
"YMOVE");
695 std::string ymovstr = ymov;
697 ymove = expEvaluator.
Evaluate(expr_id);
700 const char *zmov = element->Attribute(
"ZMOVE");
707 std::string zmovstr = zmov;
709 zmove = expEvaluator.
Evaluate(expr_id);
714 const char *zrot = element->Attribute(
"ZROT");
721 std::string zrotstr = zrot;
723 zrotate = expEvaluator.
Evaluate(expr_id);
726 TiXmlElement *vertex = element->FirstChildElement(
"V");
732 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
733 std::string attrName(vertexAttr->Name());
736 (std::string(
"Unknown attribute name: ") + attrName).c_str());
738 int err = vertexAttr->QueryIntValue(&indx);
739 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
742 std::string vertexBodyStr;
744 TiXmlNode *vertexBody = vertex->FirstChild();
749 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
751 vertexBodyStr += vertexBody->ToText()->Value();
752 vertexBodyStr +=
" ";
755 vertexBody = vertexBody->NextSibling();
759 "Vertex definitions must contain vertex data.");
763 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
767 while (!vertexDataStrm.fail())
769 vertexDataStrm >> xval >> yval >> zval;
771 xval = xval * xscale + xmove;
772 yval = yval * yscale + ymove;
773 zval = zval * zscale + zmove;
778 xval * cos(zrotate) - yval * sin(zrotate);
779 yval = xval * sin(zrotate) + yval * cos(zrotate);
786 if (!vertexDataStrm.fail())
790 spaceDimension, indx, xval, yval, zval));
796 ASSERTL0(
false,
"Unable to read VERTEX data.");
799 vertex = vertex->NextSiblingElement(
"V");
807 auto &curveNodes =
m_meshGraph->GetAllCurveNodes();
808 int meshDimension =
m_meshGraph->GetMeshDimension();
812 TiXmlElement *element =
m_xmlGeom->FirstChildElement(
"VERTEX");
813 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
818 const char *xscal = element->Attribute(
"XSCALE");
825 std::string xscalstr = xscal;
827 xscale = expEvaluator.
Evaluate(expr_id);
830 const char *yscal = element->Attribute(
"YSCALE");
837 std::string yscalstr = yscal;
839 yscale = expEvaluator.
Evaluate(expr_id);
842 const char *zscal = element->Attribute(
"ZSCALE");
849 std::string zscalstr = zscal;
851 zscale = expEvaluator.
Evaluate(expr_id);
859 const char *xmov = element->Attribute(
"XMOVE");
866 std::string xmovstr = xmov;
868 xmove = expEvaluator.
Evaluate(expr_id);
871 const char *ymov = element->Attribute(
"YMOVE");
878 std::string ymovstr = ymov;
880 ymove = expEvaluator.
Evaluate(expr_id);
883 const char *zmov = element->Attribute(
"ZMOVE");
890 std::string zmovstr = zmov;
892 zmove = expEvaluator.
Evaluate(expr_id);
897 const char *zrot = element->Attribute(
"ZROT");
904 std::string zrotstr = zrot;
906 zrotate = expEvaluator.
Evaluate(expr_id);
912 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"CURVED");
923 TiXmlElement *edgelement = field->FirstChildElement(
"E");
925 int edgeindx, edgeid;
929 std::string edge(edgelement->ValueStr());
931 (std::string(
"Unknown 3D curve type:") + edge).c_str());
934 err = edgelement->QueryIntAttribute(
"ID", &edgeindx);
935 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
938 err = edgelement->QueryIntAttribute(
"EDGEID", &edgeid);
940 "Unable to read curve attribute EDGEID.");
943 std::string elementStr;
944 TiXmlNode *elementChild = edgelement->FirstChild();
949 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
951 elementStr += elementChild->ToText()->ValueStr();
954 elementChild = elementChild->NextSibling();
957 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
965 std::string typeStr = edgelement->Attribute(
"TYPE");
966 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
967 "points definition");
971 const std::string *endStr =
973 const std::string *ptsStr = std::find(begStr, endStr, typeStr);
975 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
979 err = edgelement->QueryIntAttribute(
"NUMPOINTS", &numPts);
981 "Unable to read curve attribute NUMPOINTS.");
987 std::istringstream elementDataStrm(elementStr.c_str());
990 while (!elementDataStrm.fail())
992 elementDataStrm >> xval >> yval >> zval;
994 xval = xval * xscale + xmove;
995 yval = yval * yscale + ymove;
996 zval = zval * zscale + zmove;
1001 xval * cos(zrotate) - yval * sin(zrotate);
1002 yval = xval * sin(zrotate) + yval * cos(zrotate);
1008 if (!elementDataStrm.fail())
1010 curveNodes.emplace_back(
1012 meshDimension, edgeindx, xval, yval, zval));
1013 curve->m_points.emplace_back(curveNodes.back().get());
1020 (std::string(
"Unable to read curve data for EDGE: ") +
1025 ASSERTL0(curve->m_points.size() == numPts,
1026 "Number of points specificed by attribute "
1027 "NUMPOINTS is different from number of points "
1028 "in list (edgeid = " +
1029 std::to_string(edgeid));
1031 curvedEdges[edgeid] = curve;
1033 edgelement = edgelement->NextSiblingElement(
"E");
1039 TiXmlElement *facelement = field->FirstChildElement(
"F");
1040 int faceindx, faceid;
1044 std::string face(facelement->ValueStr());
1046 (std::string(
"Unknown 3D curve type: ") + face).c_str());
1049 err = facelement->QueryIntAttribute(
"ID", &faceindx);
1050 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
1053 err = facelement->QueryIntAttribute(
"FACEID", &faceid);
1055 "Unable to read curve attribute FACEID.");
1058 std::string elementStr;
1059 TiXmlNode *elementChild = facelement->FirstChild();
1061 while (elementChild)
1064 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1066 elementStr += elementChild->ToText()->ValueStr();
1069 elementChild = elementChild->NextSibling();
1072 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
1078 std::string typeStr = facelement->Attribute(
"TYPE");
1079 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
1080 "points definition");
1083 const std::string *endStr =
1085 const std::string *ptsStr = std::find(begStr, endStr, typeStr);
1087 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
1090 std::string numptsStr = facelement->Attribute(
"NUMPOINTS");
1092 "NUMPOINTS must be specified in points definition");
1094 std::stringstream s;
1098 curvedFaces[faceid] =
1101 ASSERTL0(numPts >= 3,
"NUMPOINTS for face must be greater than 2");
1105 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
1110 std::istringstream elementDataStrm(elementStr.c_str());
1113 while (!elementDataStrm.fail())
1115 elementDataStrm >> xval >> yval >> zval;
1121 if (!elementDataStrm.fail())
1123 curveNodes.emplace_back(
1125 meshDimension, faceindx, xval, yval, zval));
1126 curvedFaces[faceid]->m_points.emplace_back(
1127 curveNodes.back().get());
1134 (std::string(
"Unable to read curve data for FACE: ") +
1139 facelement = facelement->NextSiblingElement(
"F");
1148 TiXmlElement *element =
nullptr;
1150 element =
m_xmlGeom->FirstChildElement(
"DOMAIN");
1152 ASSERTL0(element,
"Unable to find DOMAIN tag in file.");
1156 TiXmlElement *multidomains = element->FirstChildElement(
"D");
1160 while (multidomains)
1163 int err = multidomains->QueryIntAttribute(
"ID", &indx);
1165 "Unable to read attribute ID in Domain.");
1167 TiXmlNode *elementChild = multidomains->FirstChild();
1168 while (elementChild &&
1169 elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1171 elementChild = elementChild->NextSibling();
1174 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
1175 std::string elementStr = elementChild->ToText()->ValueStr();
1177 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
1179 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
1180 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
1181 std::string indxStr =
1182 elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1186 "Unable to read domain's composite index (index missing?).");
1190 std::map<int, CompositeSharedPtr> unrollDomain;
1191 m_meshGraph->GetCompositeList(indxStr, unrollDomain);
1192 domain[indx] = unrollDomain;
1196 "Unable to obtain domain's referenced composite: ") +
1201 multidomains = multidomains->NextSiblingElement(
"D");
1208 TiXmlNode *elementChild = element->FirstChild();
1209 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1211 elementChild = elementChild->NextSibling();
1214 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
1215 std::string elementStr = elementChild->ToText()->ValueStr();
1217 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
1219 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
1220 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
1221 std::string indxStr = elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1224 "Unable to read domain's composite index (index missing?).");
1228 std::map<int, CompositeSharedPtr> fullDomain;
1229 m_meshGraph->GetCompositeList(indxStr, fullDomain);
1230 domain[0] = fullDomain;
1234 (std::string(
"Unable to obtain domain's referenced composite: ") +
1242 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
1243 int spaceDimension =
m_meshGraph->GetSpaceDimension();
1245 CurveMap::iterator it;
1248 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"EDGE");
1250 ASSERTL0(field,
"Unable to find EDGE tag in file.");
1255 TiXmlElement *edgeElement = field->FirstChildElement(
"E");
1263 std::string edgeStr;
1268 int err = edgeElement->QueryIntAttribute(
"ID", &indx);
1269 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
1271 TiXmlNode *child = edgeElement->FirstChild();
1273 if (child->Type() == TiXmlNode::TINYXML_TEXT)
1275 edgeStr += child->ToText()->ValueStr();
1279 int vertex1, vertex2;
1280 std::istringstream edgeDataStrm(edgeStr.c_str());
1284 while (!edgeDataStrm.fail())
1286 edgeDataStrm >> vertex1 >> vertex2;
1293 if (!edgeDataStrm.fail())
1295 std::array<PointGeom *, 2> vertices = {
1298 it = curvedEdges.find(indx);
1300 if (it == curvedEdges.end())
1304 indx, spaceDimension, vertices));
1311 indx, spaceDimension, vertices, it->second));
1320 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
1323 edgeElement = edgeElement->NextSiblingElement(
"E");
1329 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
1332 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"FACE");
1334 ASSERTL0(field,
"Unable to find FACE tag in file.");
1340 TiXmlElement *element = field->FirstChildElement();
1341 CurveMap::iterator it;
1345 std::string elementType(element->ValueStr());
1347 ASSERTL0(elementType ==
"Q" || elementType ==
"T",
1348 (std::string(
"Unknown 3D face type: ") + elementType).c_str());
1352 int err = element->QueryIntAttribute(
"ID", &indx);
1353 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read face attribute ID.");
1356 it = curvedFaces.find(indx);
1359 TiXmlNode *elementChild = element->FirstChild();
1360 std::string elementStr;
1361 while (elementChild)
1363 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1365 elementStr += elementChild->ToText()->ValueStr();
1367 elementChild = elementChild->NextSibling();
1370 ASSERTL0(!elementStr.empty(),
"Unable to read face description body.");
1374 if (elementType ==
"T")
1377 int edge1, edge2, edge3;
1378 std::istringstream elementDataStrm(elementStr.c_str());
1382 elementDataStrm >> edge1;
1383 elementDataStrm >> edge2;
1384 elementDataStrm >> edge3;
1387 !elementDataStrm.fail(),
1388 (std::string(
"Unable to read face data for TRIANGLE: ") +
1393 std::array<SegGeom *, TriGeom::kNedges> edges = {
1398 if (it == curvedFaces.end())
1408 indx, edges, it->second));
1415 (std::string(
"Unable to read face data for TRIANGLE: ") +
1420 else if (elementType ==
"Q")
1423 int edge1, edge2, edge3, edge4;
1424 std::istringstream elementDataStrm(elementStr.c_str());
1428 elementDataStrm >> edge1;
1429 elementDataStrm >> edge2;
1430 elementDataStrm >> edge3;
1431 elementDataStrm >> edge4;
1434 (std::string(
"Unable to read face data for QUAD: ") +
1439 std::array<SegGeom *, QuadGeom::kNedges> edges = {
1445 if (it == curvedFaces.end())
1455 indx, edges, it->second));
1461 (std::string(
"Unable to read face data for QUAD: ") +
1467 element = element->NextSiblingElement();
1473 int meshDimension =
m_meshGraph->GetMeshDimension();
1475 switch (meshDimension)
1491 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
1492 int spaceDimension =
m_meshGraph->GetSpaceDimension();
1494 TiXmlElement *field =
nullptr;
1497 field =
m_xmlGeom->FirstChildElement(
"ELEMENT");
1499 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1504 TiXmlElement *segment = field->FirstChildElement(
"S");
1505 CurveMap::iterator it;
1510 int err = segment->QueryIntAttribute(
"ID", &indx);
1511 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1513 TiXmlNode *elementChild = segment->FirstChild();
1514 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1516 elementChild = elementChild->NextSibling();
1519 ASSERTL0(elementChild,
"Unable to read element description body.");
1520 std::string elementStr = elementChild->ToText()->ValueStr();
1525 int vertex1, vertex2;
1526 std::istringstream elementDataStrm(elementStr.c_str());
1530 elementDataStrm >> vertex1;
1531 elementDataStrm >> vertex2;
1534 (std::string(
"Unable to read element data for SEGMENT: ") +
1538 std::array<PointGeom *, 2> vertices = {
1542 it = curvedEdges.find(indx);
1544 if (it == curvedEdges.end())
1548 indx, spaceDimension, vertices));
1554 indx, spaceDimension, vertices, it->second));
1560 (std::string(
"Unable to read element data for segment: ") +
1565 segment = segment->NextSiblingElement(
"S");
1571 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
1574 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"ELEMENT");
1576 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1579 CurveMap::iterator it;
1584 TiXmlElement *element = field->FirstChildElement();
1588 std::string elementType(element->ValueStr());
1591 elementType ==
"Q" || elementType ==
"T",
1592 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
1596 int err = element->QueryIntAttribute(
"ID", &indx);
1597 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1599 it = curvedFaces.find(indx);
1602 TiXmlNode *elementChild = element->FirstChild();
1603 std::string elementStr;
1604 while (elementChild)
1606 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1608 elementStr += elementChild->ToText()->ValueStr();
1610 elementChild = elementChild->NextSibling();
1614 "Unable to read element description body.");
1618 if (elementType ==
"T")
1621 int edge1, edge2, edge3;
1622 std::istringstream elementDataStrm(elementStr.c_str());
1626 elementDataStrm >> edge1;
1627 elementDataStrm >> edge2;
1628 elementDataStrm >> edge3;
1631 !elementDataStrm.fail(),
1632 (std::string(
"Unable to read element data for TRIANGLE: ") +
1637 std::array<SegGeom *, TriGeom::kNedges> edges = {
1642 if (it == curvedFaces.end())
1652 indx, edges, it->second));
1659 (std::string(
"Unable to read element data for TRIANGLE: ") +
1664 else if (elementType ==
"Q")
1667 int edge1, edge2, edge3, edge4;
1668 std::istringstream elementDataStrm(elementStr.c_str());
1672 elementDataStrm >> edge1;
1673 elementDataStrm >> edge2;
1674 elementDataStrm >> edge3;
1675 elementDataStrm >> edge4;
1678 !elementDataStrm.fail(),
1679 (std::string(
"Unable to read element data for QUAD: ") +
1684 std::array<SegGeom *, QuadGeom::kNedges> edges = {
1690 if (it == curvedFaces.end())
1700 indx, edges, it->second));
1707 (std::string(
"Unable to read element data for QUAD: ") +
1713 element = element->NextSiblingElement();
1720 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"ELEMENT");
1722 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1727 TiXmlElement *element = field->FirstChildElement();
1731 std::string elementType(element->ValueStr());
1735 elementType ==
"A" || elementType ==
"P" || elementType ==
"R" ||
1737 (std::string(
"Unknown 3D element type: ") + elementType).c_str());
1741 int err = element->QueryIntAttribute(
"ID", &indx);
1742 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1745 TiXmlNode *elementChild = element->FirstChild();
1746 std::string elementStr;
1747 while (elementChild)
1749 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1751 elementStr += elementChild->ToText()->ValueStr();
1753 elementChild = elementChild->NextSibling();
1757 "Unable to read element description body.");
1759 std::istringstream elementDataStrm(elementStr.c_str());
1765 if (elementType ==
"A")
1773 std::array<TriGeom *, kNtfaces> tfaces;
1779 std::stringstream errorstring;
1780 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1781 <<
" triangle face(s), and " << kNqfaces
1782 <<
" quadrilateral face(s).";
1783 for (
int i = 0; i < kNfaces; i++)
1786 elementDataStrm >> faceID;
1788 if (face ==
nullptr ||
1792 std::stringstream errorstring;
1793 errorstring <<
"Element " << indx
1794 <<
" has invalid face: " << faceID;
1795 ASSERTL0(
false, errorstring.str().c_str());
1799 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1800 tfaces[Ntfaces++] =
static_cast<TriGeom *
>(face);
1805 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1813 "Unable to read element data for TETRAHEDRON: ") +
1816 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1817 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1821 m_meshGraph->PopulateFaceToElMap(tetGeom.get(), kNfaces);
1828 "Unable to read element data for TETRAHEDRON: ") +
1834 else if (elementType ==
"P")
1842 std::array<Geometry2D *, kNfaces> faces;
1849 std::stringstream errorstring;
1850 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1851 <<
" triangle face(s), and " << kNqfaces
1852 <<
" quadrilateral face(s).";
1853 for (
int i = 0; i < kNfaces; i++)
1856 elementDataStrm >> faceID;
1858 if (face ==
nullptr ||
1862 std::stringstream errorstring;
1863 errorstring <<
"Element " << indx
1864 <<
" has invalid face: " << faceID;
1865 ASSERTL0(
false, errorstring.str().c_str());
1869 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1870 faces[Nfaces++] =
static_cast<TriGeom *
>(face);
1876 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1877 faces[Nfaces++] =
static_cast<QuadGeom *
>(face);
1885 !elementDataStrm.fail(),
1886 (std::string(
"Unable to read element data for PYRAMID: ") +
1889 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1890 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1894 m_meshGraph->PopulateFaceToElMap(pyrGeom.get(), kNfaces);
1901 (std::string(
"Unable to read element data for PYRAMID: ") +
1907 else if (elementType ==
"R")
1915 std::array<Geometry2D *, kNfaces> faces;
1922 std::stringstream errorstring;
1923 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1924 <<
" triangle face(s), and " << kNqfaces
1925 <<
" quadrilateral face(s).";
1927 for (
int i = 0; i < kNfaces; i++)
1930 elementDataStrm >> faceID;
1932 if (face ==
nullptr ||
1936 std::stringstream errorstring;
1937 errorstring <<
"Element " << indx
1938 <<
" has invalid face: " << faceID;
1939 ASSERTL0(
false, errorstring.str().c_str());
1943 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1944 faces[Nfaces++] =
static_cast<TriGeom *
>(face);
1950 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1951 faces[Nfaces++] =
static_cast<QuadGeom *
>(face);
1959 !elementDataStrm.fail(),
1960 (std::string(
"Unable to read element data for PRISM: ") +
1963 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1964 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1968 m_meshGraph->PopulateFaceToElMap(prismGeom.get(), kNfaces);
1975 (std::string(
"Unable to read element data for PRISM: ") +
1981 else if (elementType ==
"H")
1990 std::array<QuadGeom *, kNqfaces> qfaces;
1996 std::stringstream errorstring;
1997 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1998 <<
" triangle face(s), and " << kNqfaces
1999 <<
" quadrilateral face(s).";
2000 for (
int i = 0; i < kNfaces; i++)
2003 elementDataStrm >> faceID;
2005 if (face ==
nullptr ||
2009 std::stringstream errorstring;
2010 errorstring <<
"Element " << indx
2011 <<
" has invalid face: " << faceID;
2012 ASSERTL0(
false, errorstring.str().c_str());
2016 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
2021 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
2022 qfaces[Nqfaces++] =
static_cast<QuadGeom *
>(face);
2030 "Unable to read element data for HEXAHEDRAL: ") +
2033 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
2034 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
2038 m_meshGraph->PopulateFaceToElMap(hexGeom.get(), kNfaces);
2045 "Unable to read element data for HEXAHEDRAL: ") +
2051 element = element->NextSiblingElement();
2057 auto &meshComposites =
m_meshGraph->GetComposites();
2058 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
2060 TiXmlElement *field =
nullptr;
2063 field =
m_xmlGeom->FirstChildElement(
"COMPOSITE");
2065 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
2067 TiXmlElement *node = field->FirstChildElement(
"C");
2070 int nextCompositeNumber = -1;
2077 nextCompositeNumber++;
2080 int err = node->QueryIntAttribute(
"ID", &indx);
2081 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
2085 TiXmlNode *compositeChild = node->FirstChild();
2090 while (compositeChild &&
2091 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
2093 compositeChild = compositeChild->NextSibling();
2096 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
2097 std::string compositeStr = compositeChild->ToText()->ValueStr();
2101 std::istringstream compositeDataStrm(compositeStr.c_str());
2106 std::string prevCompositeElementStr;
2108 while (!compositeDataStrm.fail())
2110 std::string compositeElementStr;
2111 compositeDataStrm >> compositeElementStr;
2113 if (!compositeDataStrm.fail())
2118 meshComposites[indx] =
2122 if (compositeElementStr.length() > 0)
2125 compositeElementStr,
2126 meshComposites[indx]);
2128 prevCompositeElementStr = compositeElementStr;
2136 (std::string(
"Unable to read COMPOSITE data for composite: ") +
2143 err = node->QueryStringAttribute(
"NAME", &name);
2144 if (err == TIXML_SUCCESS)
2146 compositesLabels[indx] = name;
2150 node = node->NextSiblingElement(
"C");
2154 "At least one composite must be specified.");
2158 const std::string &token,
2161 int meshDimension =
m_meshGraph->GetMeshDimension();
2163 switch (meshDimension)
2178 const std::string &token,
2183 std::istringstream tokenStream(token);
2184 std::istringstream prevTokenStream(prevToken);
2189 tokenStream >> type;
2191 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2192 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2196 (std::string(
"Error reading index definition:") + token).c_str());
2198 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2200 typedef std::vector<unsigned int> SeqVectorType;
2201 SeqVectorType seqVector;
2206 (std::string(
"Ill-formed sequence definition: ") + indxStr)
2210 prevTokenStream >> prevType;
2213 bool validSequence =
2214 (prevToken.empty() ||
2215 (type ==
'V' && prevType ==
'V') ||
2216 (type ==
'S' && prevType ==
'S'));
2219 std::string(
"Invalid combination of composite items: ") +
2220 type +
" and " + prevType +
".");
2225 for (SeqVectorType::iterator iter = seqVector.begin();
2226 iter != seqVector.end(); ++iter)
2228 composite->m_geomVec.push_back(
2234 for (SeqVectorType::iterator iter = seqVector.begin();
2235 iter != seqVector.end(); ++iter)
2237 composite->m_geomVec.push_back(
2244 "Unrecognized composite token: " + token);
2250 "Problem processing composite token: " + token);
2257 const std::string &token,
2262 std::istringstream tokenStream(token);
2263 std::istringstream prevTokenStream(prevToken);
2268 tokenStream >> type;
2270 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2271 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2275 (std::string(
"Error reading index definition:") + token).c_str());
2277 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2278 std::vector<unsigned int> seqVector;
2279 std::vector<unsigned int>::iterator seqIter;
2284 (std::string(
"Error reading composite elements: ") + indxStr)
2287 prevTokenStream >> prevType;
2290 bool validSequence =
2291 (prevToken.empty() ||
2292 (type ==
'V' && prevType ==
'V') ||
2293 (type ==
'E' && prevType ==
'E') ||
2294 ((type ==
'T' || type ==
'Q') &&
2295 (prevType ==
'T' || prevType ==
'Q')));
2298 std::string(
"Invalid combination of composite items: ") +
2299 type +
" and " + prevType +
".");
2305 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2308 composite->m_geomVec.push_back(
2316 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2322 composite->m_geomVec.push_back(tri);
2330 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2336 composite->m_geomVec.push_back(quad);
2344 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2347 composite->m_geomVec.push_back(
2355 "Unrecognized composite token: " + token);
2361 "Problem processing composite token: " + token);
2368 const std::string &token,
2373 std::istringstream tokenStream(token);
2374 std::istringstream prevTokenStream(prevToken);
2379 tokenStream >> type;
2381 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2382 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2385 "Error reading index definition: " + token);
2387 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2389 std::vector<unsigned int> seqVector;
2390 std::vector<unsigned int>::iterator seqIter;
2394 ASSERTL0(err,
"Error reading composite elements: " + indxStr);
2396 prevTokenStream >> prevType;
2400 std::map<char, int> typeMap;
2411 bool validSequence =
2412 (prevToken.empty() || (typeMap[type] == typeMap[prevType]));
2415 std::string(
"Invalid combination of composite items: ") +
2416 type +
" and " + prevType +
".");
2422 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2425 composite->m_geomVec.push_back(
2433 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2436 composite->m_geomVec.push_back(
2444 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2448 if (face ==
nullptr)
2451 "Unknown face index: " +
2452 std::to_string(*seqIter));
2458 composite->m_geomVec.push_back(face);
2467 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2474 composite->m_geomVec.push_back(geom);
2482 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2489 composite->m_geomVec.push_back(geom);
2498 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2505 composite->m_geomVec.push_back(geom);
2514 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2521 composite->m_geomVec.push_back(geom);
2530 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2537 composite->m_geomVec.push_back(geom);
2546 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2553 composite->m_geomVec.push_back(geom);
2561 "Unrecognized composite token: " + token);
2567 "Problem processing composite token: " + token);
2575 std::stringstream s;
2576 s << std::scientific << std::setprecision(8) << (*vert)(0) <<
" "
2577 << (*vert)(1) <<
" " << (*vert)(2);
2578 TiXmlElement *v =
new TiXmlElement(
"V");
2580 v->LinkEndChild(
new TiXmlText(s.str()));
2581 vertTag->LinkEndChild(v);
2585 std::vector<int> keysToWrite)
2587 TiXmlElement *vertTag =
new TiXmlElement(
"VERTEX");
2589 if (keysToWrite.empty())
2598 for (
int id : keysToWrite)
2604 geomTag->LinkEndChild(vertTag);
2610 std::stringstream s;
2612 TiXmlElement *e =
new TiXmlElement(tag);
2613 e->SetAttribute(
"ID", edgeID);
2614 e->LinkEndChild(
new TiXmlText(s.str()));
2615 edgeTag->LinkEndChild(e);
2619 std::vector<int> keysToWrite)
2621 int meshDimension =
m_meshGraph->GetMeshDimension();
2623 TiXmlElement *edgeTag =
2624 new TiXmlElement(meshDimension == 1 ?
"ELEMENT" :
"EDGE");
2625 std::string tag = meshDimension == 1 ?
"S" :
"E";
2627 if (keysToWrite.empty())
2636 for (
int id : keysToWrite)
2642 geomTag->LinkEndChild(edgeTag);
2647 std::stringstream s;
2649 TiXmlElement *t =
new TiXmlElement(tag);
2650 t->SetAttribute(
"ID", triID);
2651 t->LinkEndChild(
new TiXmlText(s.str()));
2652 faceTag->LinkEndChild(t);
2655 std::vector<int> keysToWrite)
2657 std::string tag =
"T";
2659 if (keysToWrite.empty())
2668 for (
int id : keysToWrite)
2678 std::stringstream s;
2680 <<
" " << quad->
GetEid(3);
2681 TiXmlElement *q =
new TiXmlElement(tag);
2682 q->SetAttribute(
"ID", quadID);
2683 q->LinkEndChild(
new TiXmlText(s.str()));
2684 faceTag->LinkEndChild(q);
2687 std::vector<int> keysToWrite)
2689 std::string tag =
"Q";
2691 if (keysToWrite.empty())
2700 for (
int id : keysToWrite)
2709 std::stringstream s;
2713 TiXmlElement *h =
new TiXmlElement(tag);
2714 h->SetAttribute(
"ID", hexID);
2715 h->LinkEndChild(
new TiXmlText(s.str()));
2716 elmtTag->LinkEndChild(h);
2719 std::vector<int> keysToWrite)
2721 std::string tag =
"H";
2723 if (keysToWrite.empty())
2732 for (
int id : keysToWrite)
2742 std::stringstream s;
2745 TiXmlElement *p =
new TiXmlElement(tag);
2746 p->SetAttribute(
"ID", priID);
2747 p->LinkEndChild(
new TiXmlText(s.str()));
2748 elmtTag->LinkEndChild(p);
2751 std::vector<int> keysToWrite)
2753 std::string tag =
"R";
2755 if (keysToWrite.empty())
2764 for (
int id : keysToWrite)
2773 std::stringstream s;
2776 TiXmlElement *p =
new TiXmlElement(tag);
2777 p->SetAttribute(
"ID", pyrID);
2778 p->LinkEndChild(
new TiXmlText(s.str()));
2779 elmtTag->LinkEndChild(p);
2782 std::vector<int> keysToWrite)
2784 std::string tag =
"P";
2786 if (keysToWrite.empty())
2795 for (
int id : keysToWrite)
2804 std::stringstream s;
2806 << tet->
GetFid(3) <<
" ";
2807 TiXmlElement *t =
new TiXmlElement(tag);
2808 t->SetAttribute(
"ID", tetID);
2809 t->LinkEndChild(
new TiXmlText(s.str()));
2810 elmtTag->LinkEndChild(t);
2813 std::vector<int> keysToWrite)
2815 std::string tag =
"A";
2817 if (keysToWrite.empty())
2826 for (
int id : keysToWrite)
2836 TiXmlElement *curveTag =
new TiXmlElement(
"CURVED");
2837 CurveMap::iterator curveIt;
2840 for (curveIt = edges.begin(); curveIt != edges.end(); ++curveIt)
2843 TiXmlElement *c =
new TiXmlElement(
"E");
2844 std::stringstream s;
2847 for (
int j = 0; j < curve->m_points.size(); ++j)
2850 s << std::scientific << (*p)(0) <<
" " << (*p)(1) <<
" " << (*p)(2)
2854 c->SetAttribute(
"ID", curveId++);
2855 c->SetAttribute(
"EDGEID", curve->m_curveID);
2856 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2858 c->LinkEndChild(
new TiXmlText(s.str()));
2859 curveTag->LinkEndChild(c);
2862 for (curveIt = faces.begin(); curveIt != faces.end(); ++curveIt)
2865 TiXmlElement *c =
new TiXmlElement(
"F");
2866 std::stringstream s;
2869 for (
int j = 0; j < curve->m_points.size(); ++j)
2872 s << std::scientific << (*p)(0) <<
" " << (*p)(1) <<
" " << (*p)(2)
2876 c->SetAttribute(
"ID", curveId++);
2877 c->SetAttribute(
"FACEID", curve->m_curveID);
2878 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2880 c->LinkEndChild(
new TiXmlText(s.str()));
2881 curveTag->LinkEndChild(c);
2884 geomTag->LinkEndChild(curveTag);
2888 std::map<int, std::string> &compLabels)
2890 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
2891 TiXmlElement *compTag =
new TiXmlElement(
"COMPOSITE");
2893 for (
auto &cIt : comps)
2895 if (cIt.second->m_geomVec.size() == 0)
2900 TiXmlElement *c =
new TiXmlElement(
"C");
2901 c->SetAttribute(
"ID", cIt.first);
2902 if (!compositesLabels[cIt.first].empty())
2904 c->SetAttribute(
"NAME", compLabels[cIt.first]);
2907 compTag->LinkEndChild(c);
2910 geomTag->LinkEndChild(compTag);
2914 std::map<int, CompositeMap> &domainMap)
2916 TiXmlElement *domTag =
new TiXmlElement(
"DOMAIN");
2918 std::vector<unsigned int> idxList;
2919 for (
auto &domain : domainMap)
2921 TiXmlElement *c =
new TiXmlElement(
"D");
2923 std::stringstream s;
2928 for (
const auto &elem : domain.second)
2930 idxList.push_back(elem.first);
2934 c->SetAttribute(
"ID", domain.first);
2935 c->LinkEndChild(
new TiXmlText(s.str()));
2936 domTag->LinkEndChild(c);
2939 geomTag->LinkEndChild(domTag);
2944 int meshDimension =
m_meshGraph->GetMeshDimension();
2945 auto &meshComposites =
m_meshGraph->GetComposites();
2947 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
2949 for (
auto it = meshComposites.begin(); it != meshComposites.end(); it++)
2951 if (it->second->m_geomVec[0]->GetShapeDim() == meshDimension)
2953 TiXmlElement *exp =
new TiXmlElement(
"E");
2954 exp->SetAttribute(
"COMPOSITE",
2955 "C[" + std::to_string(it->first) +
"]");
2956 exp->SetAttribute(
"NUMMODES", 4);
2957 exp->SetAttribute(
"TYPE",
"MODIFIED");
2958 exp->SetAttribute(
"FIELDS",
"u");
2960 expTag->LinkEndChild(exp);
2963 root->LinkEndChild(expTag);
2971 const std::string &outfilename,
bool defaultExp,
2974 int meshDimension =
m_meshGraph->GetMeshDimension();
2975 int spaceDimension =
m_meshGraph->GetSpaceDimension();
2979 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2980 doc.LinkEndChild(decl);
2982 TiXmlElement *root =
new TiXmlElement(
"NEKTAR");
2983 doc.LinkEndChild(root);
2984 TiXmlElement *geomTag =
new TiXmlElement(
"GEOMETRY");
2985 root->LinkEndChild(geomTag);
2993 geomTag->SetAttribute(
"DIM", meshDimension);
2994 geomTag->SetAttribute(
"SPACE", spaceDimension);
2998 geomTag->SetAttribute(
"PARTITION",
m_session->GetComm()->GetRank());
3007 if (meshDimension > 1)
3009 TiXmlElement *faceTag =
3010 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
3014 geomTag->LinkEndChild(faceTag);
3016 if (meshDimension > 2)
3018 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3025 geomTag->LinkEndChild(elmtTag);
3041 movement->WriteMovement(root);
3045 doc.SaveFile(outfilename);
3049 std::string outname, std::vector<std::set<unsigned int>> elements,
3050 std::vector<unsigned int> partitions)
3061 std::string dirname = outname +
"_xml";
3062 fs::path pdirname(dirname);
3064 if (!fs::is_directory(dirname))
3066 fs::create_directory(dirname);
3069 ASSERTL0(elements.size() == partitions.size(),
3070 "error in partitioned information");
3072 for (
int i = 0; i < partitions.size(); i++)
3075 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
3076 doc.LinkEndChild(decl);
3078 TiXmlElement *root = doc.FirstChildElement(
"NEKTAR");
3079 TiXmlElement *geomTag;
3084 root =
new TiXmlElement(
"NEKTAR");
3085 doc.LinkEndChild(root);
3087 geomTag =
new TiXmlElement(
"GEOMETRY");
3088 root->LinkEndChild(geomTag);
3093 geomTag = root->FirstChildElement(
"GEOMETRY");
3097 geomTag =
new TiXmlElement(
"GEOMETRY");
3098 root->LinkEndChild(geomTag);
3102 int meshDimension =
m_meshGraph->GetMeshDimension();
3103 int spaceDimension =
m_meshGraph->GetSpaceDimension();
3105 geomTag->SetAttribute(
"DIM", meshDimension);
3106 geomTag->SetAttribute(
"SPACE", spaceDimension);
3107 geomTag->SetAttribute(
"PARTITION", partitions[i]);
3119 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
3120 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
3121 auto &meshComposites =
m_meshGraph->GetComposites();
3124 std::vector<int> localHexKeys;
3125 std::vector<int> localPyrKeys;
3126 std::vector<int> localPrismKeys;
3127 std::vector<int> localTetKeys;
3128 std::vector<int> localTriKeys;
3129 std::vector<int> localQuadKeys;
3130 std::vector<int> localEdgeKeys;
3131 std::vector<int> localVertKeys;
3135 std::vector<std::set<unsigned int>> entityIds(4);
3136 entityIds[meshDimension] = elements[i];
3138 switch (meshDimension)
3142 for (
auto &j : entityIds[3])
3146 if (
auto it{hexGeoms.find(j)}; it != hexGeoms.end())
3149 localHexKeys.push_back(j);
3151 else if (
auto it{pyrGeoms.find(j)}; it != pyrGeoms.end())
3154 localPyrKeys.push_back(j);
3156 else if (
auto it{prismGeoms.find(j)};
3157 it != prismGeoms.end())
3160 localPrismKeys.push_back(j);
3162 else if (
auto it{tetGeoms.find(j)}; it != tetGeoms.end())
3165 localTetKeys.push_back(j);
3169 ASSERTL0(
false,
"element in partition not found");
3174 entityIds[2].insert(g->
GetFid(k));
3178 entityIds[1].insert(g->
GetEid(k));
3182 entityIds[0].insert(g->
GetVid(k));
3189 for (
auto &j : entityIds[2])
3192 if (
auto it{triGeoms.find(j)}; it != triGeoms.end())
3195 localTriKeys.push_back(j);
3197 else if (
auto it{quadGeoms.find(j)}; it != quadGeoms.end())
3200 localQuadKeys.push_back(j);
3204 ASSERTL0(
false,
"element in partition not found");
3209 entityIds[1].insert(g->
GetEid(k));
3213 entityIds[0].insert(g->
GetVid(k));
3220 for (
auto &j : entityIds[1])
3223 if (
auto it{segGeoms.find(j)}; it != segGeoms.end())
3226 localEdgeKeys.push_back(j);
3230 ASSERTL0(
false,
"element in partition not found");
3235 entityIds[0].insert(g->
GetVid(k));
3241 if (meshDimension > 2)
3243 for (
auto &j : entityIds[2])
3245 if (triGeoms.find(j) != triGeoms.end())
3247 localTriKeys.push_back(j);
3249 else if (quadGeoms.find(j) != quadGeoms.end())
3251 localQuadKeys.push_back(j);
3260 if (meshDimension > 1)
3262 for (
auto &j : entityIds[1])
3264 if (segGeoms.find(j) != segGeoms.end())
3266 localEdgeKeys.push_back(j);
3275 for (
auto &j : entityIds[0])
3277 if (vertSet.find(j) != vertSet.end())
3279 localVertKeys.push_back(j);
3287 if (!localVertKeys.empty())
3292 if (!localEdgeKeys.empty())
3297 if (meshDimension > 1)
3299 TiXmlElement *faceTag =
3300 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
3302 if (!localTriKeys.empty())
3307 if (!localQuadKeys.empty())
3312 geomTag->LinkEndChild(faceTag);
3314 if (meshDimension > 2)
3316 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3318 if (!localHexKeys.empty())
3322 if (!localPyrKeys.empty())
3326 if (!localPrismKeys.empty())
3330 if (!localTetKeys.empty())
3335 geomTag->LinkEndChild(elmtTag);
3338 for (
auto &j : localTriKeys)
3340 if (curvedFaces.count(j))
3342 localCurveFace[j] = curvedFaces[j];
3345 for (
auto &j : localQuadKeys)
3347 if (curvedFaces.count(j))
3349 localCurveFace[j] = curvedFaces[j];
3352 for (
auto &j : localEdgeKeys)
3354 if (curvedEdges.count(j))
3356 localCurveEdge[j] = curvedEdges[j];
3363 std::map<int, std::string> localCompLabels;
3365 for (
auto &j : meshComposites)
3368 int dim = j.second->m_geomVec[0]->GetShapeDim();
3370 for (
int k = 0; k < j.second->m_geomVec.size(); k++)
3372 if (entityIds[dim].count(j.second->m_geomVec[k]->GetGlobalID()))
3374 comp->m_geomVec.push_back(j.second->m_geomVec[k]);
3378 if (comp->m_geomVec.size())
3380 localComp[j.first] = comp;
3381 auto compositesLabels =
m_meshGraph->GetCompositesLabels();
3382 if (!compositesLabels[j.first].empty())
3384 localCompLabels[j.first] = compositesLabels[j.first];
3391 std::map<int, CompositeMap> domain;
3392 for (
auto &j : localComp)
3394 for (
auto &dom : globalDomain)
3396 for (
auto &dIt : dom.second)
3398 if (j.first == dIt.first)
3400 domain[dom.first][j.first] = j.second;
3409 if (
m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
3411 std::set<int> vBndRegionIdList;
3412 TiXmlElement *vConditions =
3413 new TiXmlElement(*
m_session->GetElement(
"Nektar/Conditions"));
3414 TiXmlElement *vBndRegions =
3415 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
3418 TiXmlElement *vBndConditions =
3419 vConditions->FirstChildElement(
"BOUNDARYCONDITIONS");
3423 TiXmlElement *vItem;
3429 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3430 ->FirstChildElement(
"TIMELEVEL") !=
nullptr;
3432 TiXmlElement *vNewBndRegions =
3433 multiLevel ?
new TiXmlElement(
"TIMELEVEL")
3434 :
new TiXmlElement(
"BOUNDARYREGIONS");
3435 vItem = vBndRegions->FirstChildElement();
3436 auto graph_bndRegOrder =
m_meshGraph->GetBndRegionOrdering();
3439 std::string vSeqStr =
3440 vItem->FirstChild()->ToText()->Value();
3441 std::string::size_type indxBeg =
3442 vSeqStr.find_first_of(
'[') + 1;
3443 std::string::size_type indxEnd =
3444 vSeqStr.find_last_of(
']') - 1;
3445 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
3446 std::vector<unsigned int> vSeq;
3449 std::vector<unsigned int> idxList;
3451 for (
unsigned int i = 0; i < vSeq.size(); ++i)
3453 if (localComp.find(vSeq[i]) != localComp.end())
3455 idxList.push_back(vSeq[i]);
3458 int p = atoi(vItem->Attribute(
"ID"));
3460 std::string vListStr =
3463 if (vListStr.length() == 0)
3465 TiXmlElement *tmp = vItem;
3466 vItem = vItem->NextSiblingElement();
3467 vBndRegions->RemoveChild(tmp);
3471 vListStr =
"C[" + vListStr +
"]";
3472 TiXmlText *vList =
new TiXmlText(vListStr);
3473 TiXmlElement *vNewElement =
new TiXmlElement(
"B");
3474 vNewElement->SetAttribute(
"ID", p);
3475 vNewElement->LinkEndChild(vList);
3476 vNewBndRegions->LinkEndChild(vNewElement);
3477 vBndRegionIdList.insert(p);
3478 vItem = vItem->NextSiblingElement();
3483 graph_bndRegOrder[p] = vSeq;
3488 size_t timeLevel = 0;
3491 vNewBndRegions->SetAttribute(
"VALUE", timeLevel);
3492 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3493 ->ReplaceChild(vBndRegions, *vNewBndRegions);
3494 vBndRegions = vBndRegions->NextSiblingElement();
3500 vConditions->ReplaceChild(vBndRegions, *vNewBndRegions);
3506 vItem = vBndConditions->FirstChildElement();
3509 std::set<int>::iterator x;
3510 if ((x = vBndRegionIdList.find(atoi(vItem->Attribute(
3511 "REF")))) != vBndRegionIdList.end())
3513 vItem->SetAttribute(
"REF", *x);
3514 vItem = vItem->NextSiblingElement();
3518 TiXmlElement *tmp = vItem;
3519 vItem = vItem->NextSiblingElement();
3520 vBndConditions->RemoveChild(tmp);
3524 root->LinkEndChild(vConditions);
3528 TiXmlElement *vSrc =
3529 m_session->GetElement(
"Nektar")->FirstChildElement();
3532 std::string vName = boost::to_upper_copy(vSrc->ValueStr());
3533 if (vName !=
"GEOMETRY" && vName !=
"CONDITIONS")
3535 root->LinkEndChild(
new TiXmlElement(*vSrc));
3537 vSrc = vSrc->NextSiblingElement();
3542 boost::format pad(
"P%1$07d.xml");
3543 pad % partitions[i];
3544 fs::path pFilename(pad.str());
3546 fs::path fullpath = pdirname / pFilename;
3553 auto &meshComposites =
m_meshGraph->GetComposites();
3558 for (
auto &c : meshComposites)
3560 bool fillComp =
true;
3561 for (
auto &d : domain[0])
3563 if (c.second == d.second)
3570 std::vector<unsigned int> ids;
3571 for (
auto &elmt : c.second->m_geomVec)
3573 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...
static void AddInfoTag(TagWriterSharedPtr root, const FieldMetaDataMap &fieldmetadatamap)
Add provenance information to the field metadata map.
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.
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
static void GetXMLElementTimeLevel(TiXmlElement *&element, const size_t timeLevel, const bool enableCheck=true)
Get XML elment time level (Parallel-in-Time)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Generic object pool allocator/deallocator.
static std::unique_ptr< DataType, UniquePtrDeleter > AllocateUniquePtr(const Args &...args)
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers.
static bool GenerateSeqVector(const std::string &str, std::vector< unsigned int > &out)
Takes a comma-separated compressed string and converts it to entries in a vector.
Base class for shape geometry information.
LibUtilities::ShapeType GetShapeType(void)
Get the geometric shape type of this object.
int GetNumFaces() const
Get the number of faces of this object.
int GetVid(int i) const
Returns global id of vertex i of this object.
int GetGlobalID(void) const
Get the ID of this object.
int GetFid(int i) const
Get the ID of face i of this object.
int GetNumEdges() const
Get the number of edges of this object.
int GetNumVerts() const
Get the number of vertices of this object.
int GetEid(int i) const
Get the ID of edge i of this object.
static const int kNqfaces
static const int kNtfaces
BndRegionOrdering m_bndRegOrder
LibUtilities::SessionReaderSharedPtr m_session
void ReadGeometry(bool fillGraph)
std::string GetCompositeString(CompositeSharedPtr comp)
Returns a string representation of a composite.
CompositeDescriptor CreateCompositeDescriptor()
MeshGraphSharedPtr m_meshGraph
CompositeOrdering m_compOrder
std::map< int, MeshEntity > CreateMeshEntities()
Create mesh entities for this graph.
virtual void v_ReadElements1D()
void ResolveGeomRef2D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
void ResolveGeomRef3D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
virtual void v_WritePrisms(TiXmlElement *elmtTag, std::vector< int > keysToWrite=std::vector< int >())
void v_WriteGeometry(const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap) override
Write out an XML file containing the GEOMETRY block representing this MeshGraph instance inside a NEK...
virtual void v_ReadElements3D()
virtual void v_WriteEdges(TiXmlElement *geomTag, std::vector< int > keysToWrite=std::vector< int >())
virtual void v_WriteCurves(TiXmlElement *geomTag, CurveMap &edges, CurveMap &faces)
void ResolveGeomRef(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
virtual void v_WritePyrs(TiXmlElement *elmtTag, std::vector< int > keysToWrite=std::vector< int >())
virtual void v_ReadEdges()
virtual void v_ReadFaces()
void v_PartitionMesh(LibUtilities::SessionReaderSharedPtr session) override
virtual void v_ReadCurves()
void WriteDefaultExpansion(TiXmlElement *root)
virtual void v_ReadElements2D()
void ResolveGeomRef1D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
virtual void v_WriteTris(TiXmlElement *faceTag, std::vector< int > keysToWrite=std::vector< int >())
virtual void v_WriteVertices(TiXmlElement *geomTag, std::vector< int > keysToWrite=std::vector< int >())
virtual void v_ReadVertices()
void v_ReadGeometry(bool fillGraph) override
virtual void v_WriteQuads(TiXmlElement *faceTag, std::vector< int > keysToWrite=std::vector< int >())
virtual void v_WriteHexs(TiXmlElement *elmtTag, std::vector< int > keysToWrite=std::vector< int >())
void WriteComposites(TiXmlElement *geomTag, CompositeMap &comps, std::map< int, std::string > &compLabels)
static std::string className
void SetupCompositeRange(LibUtilities::DomainRangeShPtr &rng)
void WriteXMLGeometry(std::string outname, std::vector< std::set< unsigned int > > elements, std::vector< unsigned int > partitions)
CompositeOrdering CreateCompositeOrdering()
virtual void v_WriteTets(TiXmlElement *elmtTag, std::vector< int > keysToWrite=std::vector< int >())
void WriteDomain(TiXmlElement *geomTag, std::map< int, CompositeMap > &domain)
static MeshGraphIOSharedPtr create()
static const int kNqfaces
static const int kNtfaces
static const int kNtfaces
static const int kNqfaces
static const int kNqfaces
static const int kNtfaces
std::map< std::string, std::string > FieldMetaDataMap
const std::string kPointsTypeStr[]
static std::string PortablePath(const fs::path &path)
create portable path on different platforms for std::filesystem path.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
std::shared_ptr< XmlTagWriter > XmlTagWriterSharedPtr
@ SIZE_PointsType
Length of enum list.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, std::vector< unsigned int > > CompositeOrdering
void WriteVert(PointGeom *vert, TiXmlElement *vertTag)
void WritePrism(PrismGeom *pri, TiXmlElement *elmtTag, std::string &tag, int priID)
void WriteTri(TriGeom *tri, TiXmlElement *faceTag, std::string &tag, int triID)
MeshPartitionFactory & GetMeshPartitionFactory()
std::shared_ptr< Composite > CompositeSharedPtr
std::shared_ptr< Curve > CurveSharedPtr
void WriteEdge(SegGeom *seg, TiXmlElement *edgeTag, std::string &tag, int edgeID)
std::unordered_map< int, CurveSharedPtr > CurveMap
void WriteQuad(QuadGeom *quad, TiXmlElement *faceTag, std::string &tag, int quadID)
void WriteHex(HexGeom *hex, TiXmlElement *elmtTag, std::string &tag, int hexID)
MeshGraphIOFactory & GetMeshGraphIOFactory()
void WritePyr(PyrGeom *pyr, TiXmlElement *elmtTag, std::string &tag, int pyrID)
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
void WriteTet(TetGeom *tet, TiXmlElement *elmtTag, std::string &tag, int tetID)
std::map< int, CompositeSharedPtr > CompositeMap