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] = std::move(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));
1310 indx, spaceDimension, vertices,
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.get()));
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.get()));
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));
1555 indx, spaceDimension, vertices, it->second.get()));
1561 (std::string(
"Unable to read element data for segment: ") +
1566 segment = segment->NextSiblingElement(
"S");
1572 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
1575 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"ELEMENT");
1577 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1580 CurveMap::iterator it;
1585 TiXmlElement *element = field->FirstChildElement();
1589 std::string elementType(element->ValueStr());
1592 elementType ==
"Q" || elementType ==
"T",
1593 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
1597 int err = element->QueryIntAttribute(
"ID", &indx);
1598 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1600 it = curvedFaces.find(indx);
1603 TiXmlNode *elementChild = element->FirstChild();
1604 std::string elementStr;
1605 while (elementChild)
1607 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1609 elementStr += elementChild->ToText()->ValueStr();
1611 elementChild = elementChild->NextSibling();
1615 "Unable to read element description body.");
1619 if (elementType ==
"T")
1622 int edge1, edge2, edge3;
1623 std::istringstream elementDataStrm(elementStr.c_str());
1627 elementDataStrm >> edge1;
1628 elementDataStrm >> edge2;
1629 elementDataStrm >> edge3;
1632 !elementDataStrm.fail(),
1633 (std::string(
"Unable to read element data for TRIANGLE: ") +
1638 std::array<SegGeom *, TriGeom::kNedges> edges = {
1643 if (it == curvedFaces.end())
1653 indx, edges, it->second.get()));
1660 (std::string(
"Unable to read element data for TRIANGLE: ") +
1665 else if (elementType ==
"Q")
1668 int edge1, edge2, edge3, edge4;
1669 std::istringstream elementDataStrm(elementStr.c_str());
1673 elementDataStrm >> edge1;
1674 elementDataStrm >> edge2;
1675 elementDataStrm >> edge3;
1676 elementDataStrm >> edge4;
1679 !elementDataStrm.fail(),
1680 (std::string(
"Unable to read element data for QUAD: ") +
1685 std::array<SegGeom *, QuadGeom::kNedges> edges = {
1691 if (it == curvedFaces.end())
1701 indx, edges, it->second.get()));
1708 (std::string(
"Unable to read element data for QUAD: ") +
1714 element = element->NextSiblingElement();
1721 TiXmlElement *field =
m_xmlGeom->FirstChildElement(
"ELEMENT");
1723 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1728 TiXmlElement *element = field->FirstChildElement();
1732 std::string elementType(element->ValueStr());
1736 elementType ==
"A" || elementType ==
"P" || elementType ==
"R" ||
1738 (std::string(
"Unknown 3D element type: ") + elementType).c_str());
1742 int err = element->QueryIntAttribute(
"ID", &indx);
1743 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1746 TiXmlNode *elementChild = element->FirstChild();
1747 std::string elementStr;
1748 while (elementChild)
1750 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1752 elementStr += elementChild->ToText()->ValueStr();
1754 elementChild = elementChild->NextSibling();
1758 "Unable to read element description body.");
1760 std::istringstream elementDataStrm(elementStr.c_str());
1766 if (elementType ==
"A")
1774 std::array<TriGeom *, kNtfaces> tfaces;
1780 std::stringstream errorstring;
1781 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1782 <<
" triangle face(s), and " << kNqfaces
1783 <<
" quadrilateral face(s).";
1784 for (
int i = 0; i < kNfaces; i++)
1787 elementDataStrm >> faceID;
1789 if (face ==
nullptr ||
1793 std::stringstream errorstring;
1794 errorstring <<
"Element " << indx
1795 <<
" has invalid face: " << faceID;
1796 ASSERTL0(
false, errorstring.str().c_str());
1800 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1801 tfaces[Ntfaces++] =
static_cast<TriGeom *
>(face);
1806 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1814 "Unable to read element data for TETRAHEDRON: ") +
1817 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1818 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1822 m_meshGraph->PopulateFaceToElMap(tetGeom.get(), kNfaces);
1829 "Unable to read element data for TETRAHEDRON: ") +
1835 else if (elementType ==
"P")
1843 std::array<Geometry2D *, kNfaces> faces;
1850 std::stringstream errorstring;
1851 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1852 <<
" triangle face(s), and " << kNqfaces
1853 <<
" quadrilateral face(s).";
1854 for (
int i = 0; i < kNfaces; i++)
1857 elementDataStrm >> faceID;
1859 if (face ==
nullptr ||
1863 std::stringstream errorstring;
1864 errorstring <<
"Element " << indx
1865 <<
" has invalid face: " << faceID;
1866 ASSERTL0(
false, errorstring.str().c_str());
1870 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1871 faces[Nfaces++] =
static_cast<TriGeom *
>(face);
1877 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1878 faces[Nfaces++] =
static_cast<QuadGeom *
>(face);
1886 !elementDataStrm.fail(),
1887 (std::string(
"Unable to read element data for PYRAMID: ") +
1890 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1891 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1895 m_meshGraph->PopulateFaceToElMap(pyrGeom.get(), kNfaces);
1902 (std::string(
"Unable to read element data for PYRAMID: ") +
1908 else if (elementType ==
"R")
1916 std::array<Geometry2D *, kNfaces> faces;
1923 std::stringstream errorstring;
1924 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1925 <<
" triangle face(s), and " << kNqfaces
1926 <<
" quadrilateral face(s).";
1928 for (
int i = 0; i < kNfaces; i++)
1931 elementDataStrm >> faceID;
1933 if (face ==
nullptr ||
1937 std::stringstream errorstring;
1938 errorstring <<
"Element " << indx
1939 <<
" has invalid face: " << faceID;
1940 ASSERTL0(
false, errorstring.str().c_str());
1944 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1945 faces[Nfaces++] =
static_cast<TriGeom *
>(face);
1951 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1952 faces[Nfaces++] =
static_cast<QuadGeom *
>(face);
1960 !elementDataStrm.fail(),
1961 (std::string(
"Unable to read element data for PRISM: ") +
1964 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1965 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1969 m_meshGraph->PopulateFaceToElMap(prismGeom.get(), kNfaces);
1976 (std::string(
"Unable to read element data for PRISM: ") +
1982 else if (elementType ==
"H")
1991 std::array<QuadGeom *, kNqfaces> qfaces;
1997 std::stringstream errorstring;
1998 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1999 <<
" triangle face(s), and " << kNqfaces
2000 <<
" quadrilateral face(s).";
2001 for (
int i = 0; i < kNfaces; i++)
2004 elementDataStrm >> faceID;
2006 if (face ==
nullptr ||
2010 std::stringstream errorstring;
2011 errorstring <<
"Element " << indx
2012 <<
" has invalid face: " << faceID;
2013 ASSERTL0(
false, errorstring.str().c_str());
2017 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
2022 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
2023 qfaces[Nqfaces++] =
static_cast<QuadGeom *
>(face);
2031 "Unable to read element data for HEXAHEDRAL: ") +
2034 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
2035 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
2039 m_meshGraph->PopulateFaceToElMap(hexGeom.get(), kNfaces);
2046 "Unable to read element data for HEXAHEDRAL: ") +
2052 element = element->NextSiblingElement();
2058 auto &meshComposites =
m_meshGraph->GetComposites();
2059 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
2061 TiXmlElement *field =
nullptr;
2064 field =
m_xmlGeom->FirstChildElement(
"COMPOSITE");
2066 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
2068 TiXmlElement *node = field->FirstChildElement(
"C");
2071 int nextCompositeNumber = -1;
2078 nextCompositeNumber++;
2081 int err = node->QueryIntAttribute(
"ID", &indx);
2082 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
2086 TiXmlNode *compositeChild = node->FirstChild();
2091 while (compositeChild &&
2092 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
2094 compositeChild = compositeChild->NextSibling();
2097 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
2098 std::string compositeStr = compositeChild->ToText()->ValueStr();
2102 std::istringstream compositeDataStrm(compositeStr.c_str());
2107 std::string prevCompositeElementStr;
2109 while (!compositeDataStrm.fail())
2111 std::string compositeElementStr;
2112 compositeDataStrm >> compositeElementStr;
2114 if (!compositeDataStrm.fail())
2119 meshComposites[indx] =
2123 if (compositeElementStr.length() > 0)
2126 compositeElementStr,
2127 meshComposites[indx]);
2129 prevCompositeElementStr = compositeElementStr;
2137 (std::string(
"Unable to read COMPOSITE data for composite: ") +
2144 err = node->QueryStringAttribute(
"NAME", &name);
2145 if (err == TIXML_SUCCESS)
2147 compositesLabels[indx] = name;
2151 node = node->NextSiblingElement(
"C");
2155 "At least one composite must be specified.");
2159 const std::string &token,
2162 int meshDimension =
m_meshGraph->GetMeshDimension();
2164 switch (meshDimension)
2179 const std::string &token,
2184 std::istringstream tokenStream(token);
2185 std::istringstream prevTokenStream(prevToken);
2190 tokenStream >> type;
2192 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2193 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2197 (std::string(
"Error reading index definition:") + token).c_str());
2199 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2201 typedef std::vector<unsigned int> SeqVectorType;
2202 SeqVectorType seqVector;
2207 (std::string(
"Ill-formed sequence definition: ") + indxStr)
2211 prevTokenStream >> prevType;
2214 bool validSequence =
2215 (prevToken.empty() ||
2216 (type ==
'V' && prevType ==
'V') ||
2217 (type ==
'S' && prevType ==
'S'));
2220 std::string(
"Invalid combination of composite items: ") +
2221 type +
" and " + prevType +
".");
2226 for (SeqVectorType::iterator iter = seqVector.begin();
2227 iter != seqVector.end(); ++iter)
2229 composite->m_geomVec.push_back(
2235 for (SeqVectorType::iterator iter = seqVector.begin();
2236 iter != seqVector.end(); ++iter)
2238 composite->m_geomVec.push_back(
2245 "Unrecognized composite token: " + token);
2251 "Problem processing composite token: " + token);
2258 const std::string &token,
2263 std::istringstream tokenStream(token);
2264 std::istringstream prevTokenStream(prevToken);
2269 tokenStream >> type;
2271 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2272 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2276 (std::string(
"Error reading index definition:") + token).c_str());
2278 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2279 std::vector<unsigned int> seqVector;
2280 std::vector<unsigned int>::iterator seqIter;
2285 (std::string(
"Error reading composite elements: ") + indxStr)
2288 prevTokenStream >> prevType;
2291 bool validSequence =
2292 (prevToken.empty() ||
2293 (type ==
'V' && prevType ==
'V') ||
2294 (type ==
'E' && prevType ==
'E') ||
2295 ((type ==
'T' || type ==
'Q') &&
2296 (prevType ==
'T' || prevType ==
'Q')));
2299 std::string(
"Invalid combination of composite items: ") +
2300 type +
" and " + prevType +
".");
2306 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2309 composite->m_geomVec.push_back(
2317 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2323 composite->m_geomVec.push_back(tri);
2331 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2337 composite->m_geomVec.push_back(quad);
2345 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2348 composite->m_geomVec.push_back(
2356 "Unrecognized composite token: " + token);
2362 "Problem processing composite token: " + token);
2369 const std::string &token,
2374 std::istringstream tokenStream(token);
2375 std::istringstream prevTokenStream(prevToken);
2380 tokenStream >> type;
2382 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2383 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2386 "Error reading index definition: " + token);
2388 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2390 std::vector<unsigned int> seqVector;
2391 std::vector<unsigned int>::iterator seqIter;
2395 ASSERTL0(err,
"Error reading composite elements: " + indxStr);
2397 prevTokenStream >> prevType;
2401 std::map<char, int> typeMap;
2412 bool validSequence =
2413 (prevToken.empty() || (typeMap[type] == typeMap[prevType]));
2416 std::string(
"Invalid combination of composite items: ") +
2417 type +
" and " + prevType +
".");
2423 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2426 composite->m_geomVec.push_back(
2434 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2437 composite->m_geomVec.push_back(
2445 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2449 if (face ==
nullptr)
2452 "Unknown face index: " +
2453 std::to_string(*seqIter));
2459 composite->m_geomVec.push_back(face);
2468 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2475 composite->m_geomVec.push_back(geom);
2483 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2490 composite->m_geomVec.push_back(geom);
2499 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2506 composite->m_geomVec.push_back(geom);
2515 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2522 composite->m_geomVec.push_back(geom);
2531 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2538 composite->m_geomVec.push_back(geom);
2547 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2554 composite->m_geomVec.push_back(geom);
2562 "Unrecognized composite token: " + token);
2568 "Problem processing composite token: " + token);
2576 std::stringstream s;
2577 s << std::scientific << std::setprecision(8) << (*vert)(0) <<
" "
2578 << (*vert)(1) <<
" " << (*vert)(2);
2579 TiXmlElement *v =
new TiXmlElement(
"V");
2581 v->LinkEndChild(
new TiXmlText(s.str()));
2582 vertTag->LinkEndChild(v);
2586 std::vector<int> keysToWrite)
2588 TiXmlElement *vertTag =
new TiXmlElement(
"VERTEX");
2590 if (keysToWrite.empty())
2599 for (
int id : keysToWrite)
2605 geomTag->LinkEndChild(vertTag);
2611 std::stringstream s;
2613 TiXmlElement *e =
new TiXmlElement(tag);
2614 e->SetAttribute(
"ID", edgeID);
2615 e->LinkEndChild(
new TiXmlText(s.str()));
2616 edgeTag->LinkEndChild(e);
2620 std::vector<int> keysToWrite)
2622 int meshDimension =
m_meshGraph->GetMeshDimension();
2624 TiXmlElement *edgeTag =
2625 new TiXmlElement(meshDimension == 1 ?
"ELEMENT" :
"EDGE");
2626 std::string tag = meshDimension == 1 ?
"S" :
"E";
2628 if (keysToWrite.empty())
2637 for (
int id : keysToWrite)
2643 geomTag->LinkEndChild(edgeTag);
2648 std::stringstream s;
2650 TiXmlElement *t =
new TiXmlElement(tag);
2651 t->SetAttribute(
"ID", triID);
2652 t->LinkEndChild(
new TiXmlText(s.str()));
2653 faceTag->LinkEndChild(t);
2656 std::vector<int> keysToWrite)
2658 std::string tag =
"T";
2660 if (keysToWrite.empty())
2669 for (
int id : keysToWrite)
2679 std::stringstream s;
2681 <<
" " << quad->
GetEid(3);
2682 TiXmlElement *q =
new TiXmlElement(tag);
2683 q->SetAttribute(
"ID", quadID);
2684 q->LinkEndChild(
new TiXmlText(s.str()));
2685 faceTag->LinkEndChild(q);
2688 std::vector<int> keysToWrite)
2690 std::string tag =
"Q";
2692 if (keysToWrite.empty())
2701 for (
int id : keysToWrite)
2710 std::stringstream s;
2714 TiXmlElement *h =
new TiXmlElement(tag);
2715 h->SetAttribute(
"ID", hexID);
2716 h->LinkEndChild(
new TiXmlText(s.str()));
2717 elmtTag->LinkEndChild(h);
2720 std::vector<int> keysToWrite)
2722 std::string tag =
"H";
2724 if (keysToWrite.empty())
2733 for (
int id : keysToWrite)
2743 std::stringstream s;
2746 TiXmlElement *p =
new TiXmlElement(tag);
2747 p->SetAttribute(
"ID", priID);
2748 p->LinkEndChild(
new TiXmlText(s.str()));
2749 elmtTag->LinkEndChild(p);
2752 std::vector<int> keysToWrite)
2754 std::string tag =
"R";
2756 if (keysToWrite.empty())
2765 for (
int id : keysToWrite)
2774 std::stringstream s;
2777 TiXmlElement *p =
new TiXmlElement(tag);
2778 p->SetAttribute(
"ID", pyrID);
2779 p->LinkEndChild(
new TiXmlText(s.str()));
2780 elmtTag->LinkEndChild(p);
2783 std::vector<int> keysToWrite)
2785 std::string tag =
"P";
2787 if (keysToWrite.empty())
2796 for (
int id : keysToWrite)
2805 std::stringstream s;
2807 << tet->
GetFid(3) <<
" ";
2808 TiXmlElement *t =
new TiXmlElement(tag);
2809 t->SetAttribute(
"ID", tetID);
2810 t->LinkEndChild(
new TiXmlText(s.str()));
2811 elmtTag->LinkEndChild(t);
2814 std::vector<int> keysToWrite)
2816 std::string tag =
"A";
2818 if (keysToWrite.empty())
2827 for (
int id : keysToWrite)
2837 TiXmlElement *c =
new TiXmlElement(
"E");
2838 std::stringstream s;
2841 for (
int j = 0; j < curve->m_points.size(); ++j)
2844 s << std::scientific << (*p)(0) <<
" " << (*p)(1) <<
" " << (*p)(2)
2848 c->SetAttribute(
"ID", curveId++);
2849 c->SetAttribute(
"EDGEID", curve->m_curveID);
2850 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2852 c->LinkEndChild(
new TiXmlText(s.str()));
2853 curveTag->LinkEndChild(c);
2858 TiXmlElement *c =
new TiXmlElement(
"F");
2859 std::stringstream s;
2862 for (
int j = 0; j < curve->m_points.size(); ++j)
2865 s << std::scientific << (*p)(0) <<
" " << (*p)(1) <<
" " << (*p)(2)
2869 c->SetAttribute(
"ID", curveId++);
2870 c->SetAttribute(
"FACEID", curve->m_curveID);
2871 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2873 c->LinkEndChild(
new TiXmlText(s.str()));
2874 curveTag->LinkEndChild(c);
2878 std::vector<int> *keysToWriteEdges,
2879 std::vector<int> *keysToWriteFaces)
2881 TiXmlElement *curveTag =
new TiXmlElement(
"CURVED");
2884 if (keysToWriteEdges ==
nullptr)
2886 for (
auto &i : edges)
2893 for (
int key : *keysToWriteEdges)
2899 if (keysToWriteFaces ==
nullptr)
2901 for (
auto &i : faces)
2908 for (
int key : *keysToWriteFaces)
2914 geomTag->LinkEndChild(curveTag);
2918 std::map<int, std::string> &compLabels)
2920 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
2921 TiXmlElement *compTag =
new TiXmlElement(
"COMPOSITE");
2923 for (
auto &cIt : comps)
2925 if (cIt.second->m_geomVec.size() == 0)
2930 TiXmlElement *c =
new TiXmlElement(
"C");
2931 c->SetAttribute(
"ID", cIt.first);
2932 if (!compositesLabels[cIt.first].empty())
2934 c->SetAttribute(
"NAME", compLabels[cIt.first]);
2937 compTag->LinkEndChild(c);
2940 geomTag->LinkEndChild(compTag);
2944 std::map<int, CompositeMap> &domainMap)
2946 TiXmlElement *domTag =
new TiXmlElement(
"DOMAIN");
2948 std::vector<unsigned int> idxList;
2949 for (
auto &domain : domainMap)
2951 TiXmlElement *c =
new TiXmlElement(
"D");
2953 std::stringstream s;
2958 for (
const auto &elem : domain.second)
2960 idxList.push_back(elem.first);
2964 c->SetAttribute(
"ID", domain.first);
2965 c->LinkEndChild(
new TiXmlText(s.str()));
2966 domTag->LinkEndChild(c);
2969 geomTag->LinkEndChild(domTag);
2974 int meshDimension =
m_meshGraph->GetMeshDimension();
2975 auto &meshComposites =
m_meshGraph->GetComposites();
2977 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
2979 for (
auto it = meshComposites.begin(); it != meshComposites.end(); it++)
2981 if (it->second->m_geomVec[0]->GetShapeDim() == meshDimension)
2983 TiXmlElement *exp =
new TiXmlElement(
"E");
2984 exp->SetAttribute(
"COMPOSITE",
2985 "C[" + std::to_string(it->first) +
"]");
2986 exp->SetAttribute(
"NUMMODES", 4);
2987 exp->SetAttribute(
"TYPE",
"MODIFIED");
2988 exp->SetAttribute(
"FIELDS",
"u");
2990 expTag->LinkEndChild(exp);
2993 root->LinkEndChild(expTag);
3001 const std::string &outfilename,
bool defaultExp,
3004 int meshDimension =
m_meshGraph->GetMeshDimension();
3005 int spaceDimension =
m_meshGraph->GetSpaceDimension();
3009 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
3010 doc.LinkEndChild(decl);
3012 TiXmlElement *root =
new TiXmlElement(
"NEKTAR");
3013 doc.LinkEndChild(root);
3014 TiXmlElement *geomTag =
new TiXmlElement(
"GEOMETRY");
3015 root->LinkEndChild(geomTag);
3023 geomTag->SetAttribute(
"DIM", meshDimension);
3024 geomTag->SetAttribute(
"SPACE", spaceDimension);
3028 geomTag->SetAttribute(
"PARTITION",
m_session->GetComm()->GetRank());
3037 if (meshDimension > 1)
3039 TiXmlElement *faceTag =
3040 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
3044 geomTag->LinkEndChild(faceTag);
3046 if (meshDimension > 2)
3048 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3055 geomTag->LinkEndChild(elmtTag);
3071 movement->WriteMovement(root);
3075 doc.SaveFile(outfilename);
3079 std::string outname, std::vector<std::set<unsigned int>> elements,
3080 std::vector<unsigned int> partitions)
3091 std::string dirname = outname +
"_xml";
3092 fs::path pdirname(dirname);
3094 if (!fs::is_directory(dirname))
3096 fs::create_directory(dirname);
3099 ASSERTL0(elements.size() == partitions.size(),
3100 "error in partitioned information");
3102 for (
int i = 0; i < partitions.size(); i++)
3105 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
3106 doc.LinkEndChild(decl);
3108 TiXmlElement *root = doc.FirstChildElement(
"NEKTAR");
3109 TiXmlElement *geomTag;
3114 root =
new TiXmlElement(
"NEKTAR");
3115 doc.LinkEndChild(root);
3117 geomTag =
new TiXmlElement(
"GEOMETRY");
3118 root->LinkEndChild(geomTag);
3123 geomTag = root->FirstChildElement(
"GEOMETRY");
3127 geomTag =
new TiXmlElement(
"GEOMETRY");
3128 root->LinkEndChild(geomTag);
3132 int meshDimension =
m_meshGraph->GetMeshDimension();
3133 int spaceDimension =
m_meshGraph->GetSpaceDimension();
3135 geomTag->SetAttribute(
"DIM", meshDimension);
3136 geomTag->SetAttribute(
"SPACE", spaceDimension);
3137 geomTag->SetAttribute(
"PARTITION", partitions[i]);
3149 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
3150 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
3151 auto &meshComposites =
m_meshGraph->GetComposites();
3154 std::vector<int> localHexKeys;
3155 std::vector<int> localPyrKeys;
3156 std::vector<int> localPrismKeys;
3157 std::vector<int> localTetKeys;
3158 std::vector<int> localTriKeys;
3159 std::vector<int> localQuadKeys;
3160 std::vector<int> localEdgeKeys;
3161 std::vector<int> localVertKeys;
3162 std::vector<int> localCurveEdgeKeys;
3163 std::vector<int> localCurveFaceKeys;
3165 std::vector<std::set<unsigned int>> entityIds(4);
3166 entityIds[meshDimension] = elements[i];
3168 switch (meshDimension)
3172 for (
auto &j : entityIds[3])
3176 if (
auto it{hexGeoms.find(j)}; it != hexGeoms.end())
3179 localHexKeys.push_back(j);
3181 else if (
auto it{pyrGeoms.find(j)}; it != pyrGeoms.end())
3184 localPyrKeys.push_back(j);
3186 else if (
auto it{prismGeoms.find(j)};
3187 it != prismGeoms.end())
3190 localPrismKeys.push_back(j);
3192 else if (
auto it{tetGeoms.find(j)}; it != tetGeoms.end())
3195 localTetKeys.push_back(j);
3199 ASSERTL0(
false,
"element in partition not found");
3204 entityIds[2].insert(g->
GetFid(k));
3208 entityIds[1].insert(g->
GetEid(k));
3212 entityIds[0].insert(g->
GetVid(k));
3219 for (
auto &j : entityIds[2])
3222 if (
auto it{triGeoms.find(j)}; it != triGeoms.end())
3225 localTriKeys.push_back(j);
3227 else if (
auto it{quadGeoms.find(j)}; it != quadGeoms.end())
3230 localQuadKeys.push_back(j);
3234 ASSERTL0(
false,
"element in partition not found");
3239 entityIds[1].insert(g->
GetEid(k));
3243 entityIds[0].insert(g->
GetVid(k));
3250 for (
auto &j : entityIds[1])
3253 if (
auto it{segGeoms.find(j)}; it != segGeoms.end())
3256 localEdgeKeys.push_back(j);
3260 ASSERTL0(
false,
"element in partition not found");
3265 entityIds[0].insert(g->
GetVid(k));
3271 if (meshDimension > 2)
3273 for (
auto &j : entityIds[2])
3275 if (triGeoms.find(j) != triGeoms.end())
3277 localTriKeys.push_back(j);
3279 else if (quadGeoms.find(j) != quadGeoms.end())
3281 localQuadKeys.push_back(j);
3290 if (meshDimension > 1)
3292 for (
auto &j : entityIds[1])
3294 if (segGeoms.find(j) != segGeoms.end())
3296 localEdgeKeys.push_back(j);
3305 for (
auto &j : entityIds[0])
3307 if (vertSet.find(j) != vertSet.end())
3309 localVertKeys.push_back(j);
3317 if (!localVertKeys.empty())
3322 if (!localEdgeKeys.empty())
3327 if (meshDimension > 1)
3329 TiXmlElement *faceTag =
3330 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
3332 if (!localTriKeys.empty())
3337 if (!localQuadKeys.empty())
3342 geomTag->LinkEndChild(faceTag);
3344 if (meshDimension > 2)
3346 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3348 if (!localHexKeys.empty())
3352 if (!localPyrKeys.empty())
3356 if (!localPrismKeys.empty())
3360 if (!localTetKeys.empty())
3365 geomTag->LinkEndChild(elmtTag);
3368 for (
auto &j : localTriKeys)
3370 if (curvedFaces.count(j))
3372 localCurveFaceKeys.push_back(j);
3375 for (
auto &j : localQuadKeys)
3377 if (curvedFaces.count(j))
3379 localCurveFaceKeys.push_back(j);
3382 for (
auto &j : localEdgeKeys)
3384 if (curvedEdges.count(j))
3386 localCurveEdgeKeys.push_back(j);
3390 v_WriteCurves(geomTag, curvedEdges, curvedFaces, &localCurveEdgeKeys,
3391 &localCurveFaceKeys);
3394 std::map<int, std::string> localCompLabels;
3396 for (
auto &j : meshComposites)
3399 int dim = j.second->m_geomVec[0]->GetShapeDim();
3401 for (
int k = 0; k < j.second->m_geomVec.size(); k++)
3403 if (entityIds[dim].count(j.second->m_geomVec[k]->GetGlobalID()))
3405 comp->m_geomVec.push_back(j.second->m_geomVec[k]);
3409 if (comp->m_geomVec.size())
3411 localComp[j.first] = comp;
3412 auto compositesLabels =
m_meshGraph->GetCompositesLabels();
3413 if (!compositesLabels[j.first].empty())
3415 localCompLabels[j.first] = compositesLabels[j.first];
3422 std::map<int, CompositeMap> domain;
3423 for (
auto &j : localComp)
3425 for (
auto &dom : globalDomain)
3427 for (
auto &dIt : dom.second)
3429 if (j.first == dIt.first)
3431 domain[dom.first][j.first] = j.second;
3440 if (
m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
3442 std::set<int> vBndRegionIdList;
3443 TiXmlElement *vConditions =
3444 new TiXmlElement(*
m_session->GetElement(
"Nektar/Conditions"));
3445 TiXmlElement *vBndRegions =
3446 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
3449 TiXmlElement *vBndConditions =
3450 vConditions->FirstChildElement(
"BOUNDARYCONDITIONS");
3454 TiXmlElement *vItem;
3460 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3461 ->FirstChildElement(
"TIMELEVEL") !=
nullptr;
3463 TiXmlElement *vNewBndRegions =
3464 multiLevel ?
new TiXmlElement(
"TIMELEVEL")
3465 :
new TiXmlElement(
"BOUNDARYREGIONS");
3466 vItem = vBndRegions->FirstChildElement();
3467 auto graph_bndRegOrder =
m_meshGraph->GetBndRegionOrdering();
3470 std::string vSeqStr =
3471 vItem->FirstChild()->ToText()->Value();
3472 std::string::size_type indxBeg =
3473 vSeqStr.find_first_of(
'[') + 1;
3474 std::string::size_type indxEnd =
3475 vSeqStr.find_last_of(
']') - 1;
3476 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
3477 std::vector<unsigned int> vSeq;
3480 std::vector<unsigned int> idxList;
3482 for (
unsigned int i = 0; i < vSeq.size(); ++i)
3484 if (localComp.find(vSeq[i]) != localComp.end())
3486 idxList.push_back(vSeq[i]);
3489 int p = atoi(vItem->Attribute(
"ID"));
3491 std::string vListStr =
3494 if (vListStr.length() == 0)
3496 TiXmlElement *tmp = vItem;
3497 vItem = vItem->NextSiblingElement();
3498 vBndRegions->RemoveChild(tmp);
3502 vListStr =
"C[" + vListStr +
"]";
3503 TiXmlText *vList =
new TiXmlText(vListStr);
3504 TiXmlElement *vNewElement =
new TiXmlElement(
"B");
3505 vNewElement->SetAttribute(
"ID", p);
3506 vNewElement->LinkEndChild(vList);
3507 vNewBndRegions->LinkEndChild(vNewElement);
3508 vBndRegionIdList.insert(p);
3509 vItem = vItem->NextSiblingElement();
3514 graph_bndRegOrder[p] = vSeq;
3519 size_t timeLevel = 0;
3522 vNewBndRegions->SetAttribute(
"VALUE", timeLevel);
3523 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3524 ->ReplaceChild(vBndRegions, *vNewBndRegions);
3525 vBndRegions = vBndRegions->NextSiblingElement();
3531 vConditions->ReplaceChild(vBndRegions, *vNewBndRegions);
3537 vItem = vBndConditions->FirstChildElement();
3540 std::set<int>::iterator x;
3541 if ((x = vBndRegionIdList.find(atoi(vItem->Attribute(
3542 "REF")))) != vBndRegionIdList.end())
3544 vItem->SetAttribute(
"REF", *x);
3545 vItem = vItem->NextSiblingElement();
3549 TiXmlElement *tmp = vItem;
3550 vItem = vItem->NextSiblingElement();
3551 vBndConditions->RemoveChild(tmp);
3555 root->LinkEndChild(vConditions);
3559 TiXmlElement *vSrc =
3560 m_session->GetElement(
"Nektar")->FirstChildElement();
3563 std::string vName = boost::to_upper_copy(vSrc->ValueStr());
3564 if (vName !=
"GEOMETRY" && vName !=
"CONDITIONS")
3566 root->LinkEndChild(
new TiXmlElement(*vSrc));
3568 vSrc = vSrc->NextSiblingElement();
3573 boost::format pad(
"P%1$07d.xml");
3574 pad % partitions[i];
3575 fs::path pFilename(pad.str());
3577 fs::path fullpath = pdirname / pFilename;
3584 auto &meshComposites =
m_meshGraph->GetComposites();
3589 for (
auto &c : meshComposites)
3591 bool fillComp =
true;
3592 for (
auto &d : domain[0])
3594 if (c.second == d.second)
3601 std::vector<unsigned int> ids;
3602 for (
auto &elmt : c.second->m_geomVec)
3604 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()
virtual void v_WriteCurves(TiXmlElement *geomTag, CurveMap &edges, CurveMap &faces, std::vector< int > *keysToWriteEdges=nullptr, std::vector< int > *keysToWriteFaces=nullptr)
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 >())
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.
unique_ptr_objpool< Curve > CurveUniquePtr
std::map< int, std::vector< unsigned int > > CompositeOrdering
void WriteVert(PointGeom *vert, TiXmlElement *vertTag)
void WriteCurvedFace(CurveUniquePtr &curve, TiXmlElement *curveTag, int &curveId)
std::map< int, CurveUniquePtr > CurveMap
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
void WriteEdge(SegGeom *seg, TiXmlElement *edgeTag, std::string &tag, int edgeID)
void WriteCurvedEdge(CurveUniquePtr &curve, TiXmlElement *curveTag, int &curveId)
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