47#include <boost/format.hpp>
66 const bool isRoot = comm->TreatAsRankZero();
80 int isPartitioned = 0;
83 if (
m_session->DefinesElement(
"Nektar/Geometry"))
85 if (
m_session->GetElement(
"Nektar/Geometry")
86 ->Attribute(
"PARTITION"))
88 std::cout <<
"Using pre-partitioned mesh." << std::endl;
92 ->QueryIntAttribute(
"DIM", &meshDimension);
95 comm->Bcast(isPartitioned, 0);
96 comm->Bcast(meshDimension, 0);
113 string partitionerName =
"Scotch";
114 if (!haveScotch && haveMetis)
116 partitionerName =
"Metis";
120 if (session->DefinesCmdLineArgument(
"use-metis"))
122 partitionerName =
"Metis";
124 if (session->DefinesCmdLineArgument(
"use-scotch"))
126 partitionerName =
"Scotch";
132 if (session->DefinesCmdLineArgument(
"part-only") ||
133 session->DefinesCmdLineArgument(
"part-only-overlapping"))
138 "The 'part-only' option should be used in serial.");
149 partitionerName, session, session->GetComm(), meshDimension,
152 if (session->DefinesCmdLineArgument(
"part-only"))
154 nParts = session->GetCmdLineArgument<
int>(
"part-only");
155 partitioner->PartitionMesh(nParts,
true);
160 session->GetCmdLineArgument<
int>(
"part-only-overlapping");
161 partitioner->PartitionMesh(nParts,
true,
true);
164 vector<set<unsigned int>> elmtIDs;
165 vector<unsigned int> parts(nParts);
166 for (
int i = 0; i < nParts; ++i)
168 vector<unsigned int> elIDs;
169 set<unsigned int> tmp;
170 partitioner->GetElementIDs(i, elIDs);
171 tmp.insert(elIDs.begin(), elIDs.end());
172 elmtIDs.push_back(tmp);
178 if (isRoot && session->DefinesCmdLineArgument(
"part-info"))
180 partitioner->PrintPartInfo(std::cout);
187 if (commMesh->GetSize() > 1)
190 "Valid partitioner not found! Either Scotch or METIS "
193 int nParts = commMesh->GetSize();
195 if (session->GetSharedFilesystem())
197 vector<unsigned int> keys, vals;
213 partitionerName, session, session->GetComm(),
216 partitioner->PartitionMesh(nParts,
true);
218 vector<set<unsigned int>> elmtIDs;
219 vector<unsigned int> parts(nParts);
220 for (i = 0; i < nParts; ++i)
222 vector<unsigned int> elIDs;
223 set<unsigned int> tmp;
224 partitioner->GetElementIDs(i, elIDs);
225 tmp.insert(elIDs.begin(), elIDs.end());
226 elmtIDs.push_back(tmp);
242 comm->Bcast(keys, 0);
253 vals[i++] = cIt.second.size();
257 comm->Bcast(keys, 0);
258 comm->Bcast(vals, 0);
261 comm->Bcast(cIt.second, 0);
274 vals[i++] = bIt.second.size();
280 comm->Bcast(keys, 0);
284 comm->Bcast(vals, 0);
288 comm->Bcast(bIt.second, 0);
292 if (session->DefinesCmdLineArgument(
"part-info"))
294 partitioner->PrintPartInfo(std::cout);
300 comm->Bcast(keys, 0);
302 int cmpSize = keys[0];
303 int bndSize = keys[1];
305 keys.resize(cmpSize);
306 vals.resize(cmpSize);
307 comm->Bcast(keys, 0);
308 comm->Bcast(vals, 0);
310 for (
int i = 0; i < keys.size(); ++i)
312 vector<unsigned int> tmp(vals[i]);
318 keys.resize(bndSize);
319 vals.resize(bndSize);
322 comm->Bcast(keys, 0);
326 comm->Bcast(vals, 0);
328 for (
int i = 0; i < keys.size(); ++i)
330 vector<unsigned int> tmp(vals[i]);
351 partitionerName, session, session->GetComm(),
354 partitioner->PartitionMesh(nParts,
false);
356 vector<unsigned int> parts(1), tmp;
357 parts[0] = commMesh->GetRank();
358 vector<set<unsigned int>> elIDs(1);
359 partitioner->GetElementIDs(parts[0], tmp);
360 elIDs[0].insert(tmp.begin(), tmp.end());
369 if (
m_session->DefinesCmdLineArgument(
"part-info") && isRoot)
371 partitioner->PrintPartInfo(std::cout);
378 std::string dirname =
m_session->GetSessionName() +
"_xml";
379 fs::path pdirname(dirname);
381 pad % comm->GetRowComm()->GetRank();
382 fs::path pFilename(pad.str());
383 fs::path fullpath = pdirname / pFilename;
385 std::vector<std::string> filenames = {
410 TiXmlAttribute *attr =
m_xmlGeom->FirstAttribute();
415 int meshDimension =
m_meshGraph->GetMeshDimension();
416 int spaceDimension =
m_meshGraph->GetSpaceDimension();
423 std::string attrName(attr->Name());
424 if (attrName ==
"DIM")
426 err = attr->QueryIntValue(&meshDimension);
427 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
429 else if (attrName ==
"SPACE")
431 err = attr->QueryIntValue(&spaceDimension);
432 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
434 else if (attrName ==
"PARTITION")
437 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read partition.");
443 std::string errstr(
"Unknown attribute: ");
455 ASSERTL0(meshDimension <= spaceDimension,
456 "Mesh dimension greater than space dimension");
460 if (meshDimension >= 2)
463 if (meshDimension == 3)
481 int spaceDimension =
m_meshGraph->GetSpaceDimension();
484 TiXmlElement *element =
m_xmlGeom->FirstChildElement(
"VERTEX");
485 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
492 const char *xscal = element->Attribute(
"XSCALE");
499 std::string xscalstr = xscal;
501 xscale = expEvaluator.
Evaluate(expr_id);
504 const char *yscal = element->Attribute(
"YSCALE");
511 std::string yscalstr = yscal;
513 yscale = expEvaluator.
Evaluate(expr_id);
516 const char *zscal = element->Attribute(
"ZSCALE");
523 std::string zscalstr = zscal;
525 zscale = expEvaluator.
Evaluate(expr_id);
533 const char *xmov = element->Attribute(
"XMOVE");
540 std::string xmovstr = xmov;
542 xmove = expEvaluator.
Evaluate(expr_id);
545 const char *ymov = element->Attribute(
"YMOVE");
552 std::string ymovstr = ymov;
554 ymove = expEvaluator.
Evaluate(expr_id);
557 const char *zmov = element->Attribute(
"ZMOVE");
564 std::string zmovstr = zmov;
566 zmove = expEvaluator.
Evaluate(expr_id);
569 TiXmlElement *vertex = element->FirstChildElement(
"V");
575 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
576 std::string attrName(vertexAttr->Name());
579 (std::string(
"Unknown attribute name: ") + attrName).c_str());
581 int err = vertexAttr->QueryIntValue(&indx);
582 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
585 std::string vertexBodyStr;
587 TiXmlNode *vertexBody = vertex->FirstChild();
592 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
594 vertexBodyStr += vertexBody->ToText()->Value();
595 vertexBodyStr +=
" ";
598 vertexBody = vertexBody->NextSibling();
602 "Vertex definitions must contain vertex data.");
606 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
610 while (!vertexDataStrm.fail())
612 vertexDataStrm >> xval >> yval >> zval;
614 xval = xval * xscale + xmove;
615 yval = yval * yscale + ymove;
616 zval = zval * zscale + zmove;
621 if (!vertexDataStrm.fail())
625 spaceDimension, indx, xval, yval, zval));
626 vertSet[indx] = vert;
632 ASSERTL0(
false,
"Unable to read VERTEX data.");
635 vertex = vertex->NextSiblingElement(
"V");
643 int meshDimension =
m_meshGraph->GetMeshDimension();
647 TiXmlElement *element =
m_xmlGeom->FirstChildElement(
"VERTEX");
648 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
653 const char *xscal = element->Attribute(
"XSCALE");
660 std::string xscalstr = xscal;
662 xscale = expEvaluator.
Evaluate(expr_id);
665 const char *yscal = element->Attribute(
"YSCALE");
672 std::string yscalstr = yscal;
674 yscale = expEvaluator.
Evaluate(expr_id);
677 const char *zscal = element->Attribute(
"ZSCALE");
684 std::string zscalstr = zscal;
686 zscale = expEvaluator.
Evaluate(expr_id);
694 const char *xmov = element->Attribute(
"XMOVE");
701 std::string xmovstr = xmov;
703 xmove = expEvaluator.
Evaluate(expr_id);
706 const char *ymov = element->Attribute(
"YMOVE");
713 std::string ymovstr = ymov;
715 ymove = expEvaluator.
Evaluate(expr_id);
718 const char *zmov = element->Attribute(
"ZMOVE");
725 std::string zmovstr = zmov;
727 zmove = expEvaluator.
Evaluate(expr_id);
744 TiXmlElement *edgelement =
field->FirstChildElement(
"E");
746 int edgeindx, edgeid;
750 std::string edge(edgelement->ValueStr());
752 (std::string(
"Unknown 3D curve type:") + edge).c_str());
755 err = edgelement->QueryIntAttribute(
"ID", &edgeindx);
756 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
759 err = edgelement->QueryIntAttribute(
"EDGEID", &edgeid);
761 "Unable to read curve attribute EDGEID.");
764 std::string elementStr;
765 TiXmlNode *elementChild = edgelement->FirstChild();
770 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
772 elementStr += elementChild->ToText()->ValueStr();
775 elementChild = elementChild->NextSibling();
778 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
786 std::string typeStr = edgelement->Attribute(
"TYPE");
787 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
788 "points definition");
792 const std::string *endStr =
794 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
796 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
800 err = edgelement->QueryIntAttribute(
"NUMPOINTS", &numPts);
802 "Unable to read curve attribute NUMPOINTS.");
808 std::istringstream elementDataStrm(elementStr.c_str());
811 while (!elementDataStrm.fail())
813 elementDataStrm >> xval >> yval >> zval;
815 xval = xval * xscale + xmove;
816 yval = yval * yscale + ymove;
817 zval = zval * zscale + zmove;
822 if (!elementDataStrm.fail())
826 meshDimension, edgeindx, xval, yval, zval));
828 curve->m_points.push_back(vert);
835 (std::string(
"Unable to read curve data for EDGE: ") +
840 ASSERTL0(curve->m_points.size() == numPts,
841 "Number of points specificed by attribute "
842 "NUMPOINTS is different from number of points "
843 "in list (edgeid = " +
844 boost::lexical_cast<string>(edgeid));
846 curvedEdges[edgeid] = curve;
848 edgelement = edgelement->NextSiblingElement(
"E");
854 TiXmlElement *facelement =
field->FirstChildElement(
"F");
855 int faceindx, faceid;
859 std::string face(facelement->ValueStr());
861 (std::string(
"Unknown 3D curve type: ") + face).c_str());
864 err = facelement->QueryIntAttribute(
"ID", &faceindx);
865 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
868 err = facelement->QueryIntAttribute(
"FACEID", &faceid);
870 "Unable to read curve attribute FACEID.");
873 std::string elementStr;
874 TiXmlNode *elementChild = facelement->FirstChild();
879 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
881 elementStr += elementChild->ToText()->ValueStr();
884 elementChild = elementChild->NextSibling();
887 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
893 std::string typeStr = facelement->Attribute(
"TYPE");
894 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
895 "points definition");
898 const std::string *endStr =
900 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
902 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
905 std::string numptsStr = facelement->Attribute(
"NUMPOINTS");
907 "NUMPOINTS must be specified in points definition");
916 ASSERTL0(numPts >= 3,
"NUMPOINTS for face must be greater than 2");
920 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
925 std::istringstream elementDataStrm(elementStr.c_str());
928 while (!elementDataStrm.fail())
930 elementDataStrm >> xval >> yval >> zval;
936 if (!elementDataStrm.fail())
940 meshDimension, faceindx, xval, yval, zval));
941 curve->m_points.push_back(vert);
948 (std::string(
"Unable to read curve data for FACE: ") +
952 curvedFaces[faceid] = curve;
954 facelement = facelement->NextSiblingElement(
"F");
963 TiXmlElement *element =
nullptr;
965 element =
m_xmlGeom->FirstChildElement(
"DOMAIN");
967 ASSERTL0(element,
"Unable to find DOMAIN tag in file.");
971 TiXmlElement *multidomains = element->FirstChildElement(
"D");
978 int err = multidomains->QueryIntAttribute(
"ID", &indx);
980 "Unable to read attribute ID in Domain.");
982 TiXmlNode *elementChild = multidomains->FirstChild();
983 while (elementChild &&
984 elementChild->Type() != TiXmlNode::TINYXML_TEXT)
986 elementChild = elementChild->NextSibling();
989 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
990 std::string elementStr = elementChild->ToText()->ValueStr();
992 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
994 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
995 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
996 std::string indxStr =
997 elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1001 "Unable to read domain's composite index (index missing?).");
1005 map<int, CompositeSharedPtr> unrollDomain;
1006 m_meshGraph->GetCompositeList(indxStr, unrollDomain);
1007 domain[indx] = unrollDomain;
1011 "Unable to obtain domain's referenced composite: ") +
1016 multidomains = multidomains->NextSiblingElement(
"D");
1023 TiXmlNode *elementChild = element->FirstChild();
1024 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1026 elementChild = elementChild->NextSibling();
1029 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
1030 std::string elementStr = elementChild->ToText()->ValueStr();
1032 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
1034 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
1035 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
1036 std::string indxStr = elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1039 "Unable to read domain's composite index (index missing?).");
1043 map<int, CompositeSharedPtr> fullDomain;
1044 m_meshGraph->GetCompositeList(indxStr, fullDomain);
1045 domain[0] = fullDomain;
1049 (std::string(
"Unable to obtain domain's referenced composite: ") +
1058 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
1059 int spaceDimension =
m_meshGraph->GetSpaceDimension();
1061 CurveMap::iterator it;
1071 TiXmlElement *edgeElement =
field->FirstChildElement(
"E");
1079 std::string edgeStr;
1084 int err = edgeElement->QueryIntAttribute(
"ID", &indx);
1085 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
1087 TiXmlNode *child = edgeElement->FirstChild();
1089 if (child->Type() == TiXmlNode::TINYXML_TEXT)
1091 edgeStr += child->ToText()->ValueStr();
1095 int vertex1, vertex2;
1096 std::istringstream edgeDataStrm(edgeStr.c_str());
1100 while (!edgeDataStrm.fail())
1102 edgeDataStrm >> vertex1 >> vertex2;
1109 if (!edgeDataStrm.fail())
1114 it = curvedEdges.find(indx);
1116 if (it == curvedEdges.end())
1120 indx, spaceDimension, vertices);
1126 indx, spaceDimension, vertices, it->second);
1135 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
1138 edgeElement = edgeElement->NextSiblingElement(
"E");
1144 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
1157 TiXmlElement *element =
field->FirstChildElement();
1158 CurveMap::iterator it;
1162 std::string elementType(element->ValueStr());
1164 ASSERTL0(elementType ==
"Q" || elementType ==
"T",
1165 (std::string(
"Unknown 3D face type: ") + elementType).c_str());
1169 int err = element->QueryIntAttribute(
"ID", &indx);
1170 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read face attribute ID.");
1173 it = curvedFaces.find(indx);
1176 TiXmlNode *elementChild = element->FirstChild();
1177 std::string elementStr;
1178 while (elementChild)
1180 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1182 elementStr += elementChild->ToText()->ValueStr();
1184 elementChild = elementChild->NextSibling();
1187 ASSERTL0(!elementStr.empty(),
"Unable to read face description body.");
1191 if (elementType ==
"T")
1194 int edge1, edge2, edge3;
1195 std::istringstream elementDataStrm(elementStr.c_str());
1199 elementDataStrm >> edge1;
1200 elementDataStrm >> edge2;
1201 elementDataStrm >> edge3;
1204 !elementDataStrm.fail(),
1205 (std::string(
"Unable to read face data for TRIANGLE: ") +
1215 if (it == curvedFaces.end())
1223 indx, edges, it->second);
1225 triGeoms[indx]->SetGlobalID(indx);
1231 (std::string(
"Unable to read face data for TRIANGLE: ") +
1236 else if (elementType ==
"Q")
1239 int edge1, edge2, edge3, edge4;
1240 std::istringstream elementDataStrm(elementStr.c_str());
1244 elementDataStrm >> edge1;
1245 elementDataStrm >> edge2;
1246 elementDataStrm >> edge3;
1247 elementDataStrm >> edge4;
1250 (std::string(
"Unable to read face data for QUAD: ") +
1263 if (it == curvedFaces.end())
1274 quadGeoms[indx]->SetGlobalID(indx);
1279 (std::string(
"Unable to read face data for QUAD: ") +
1285 element = element->NextSiblingElement();
1291 int meshDimension =
m_meshGraph->GetMeshDimension();
1293 switch (meshDimension)
1309 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
1311 int spaceDimension =
m_meshGraph->GetSpaceDimension();
1313 TiXmlElement *
field =
nullptr;
1323 TiXmlElement *segment =
field->FirstChildElement(
"S");
1324 CurveMap::iterator it;
1329 int err = segment->QueryIntAttribute(
"ID", &indx);
1330 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1332 TiXmlNode *elementChild = segment->FirstChild();
1333 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1335 elementChild = elementChild->NextSibling();
1338 ASSERTL0(elementChild,
"Unable to read element description body.");
1339 std::string elementStr = elementChild->ToText()->ValueStr();
1344 int vertex1, vertex2;
1345 std::istringstream elementDataStrm(elementStr.c_str());
1349 elementDataStrm >> vertex1;
1350 elementDataStrm >> vertex2;
1353 (std::string(
"Unable to read element data for SEGMENT: ") +
1359 it = curvedEdges.find(indx);
1361 if (it == curvedEdges.end())
1364 indx, spaceDimension, vertices);
1369 indx, spaceDimension, vertices, it->second);
1371 segGeoms[indx]->SetGlobalID(indx);
1376 (std::string(
"Unable to read element data for segment: ") +
1381 segment = segment->NextSiblingElement(
"S");
1387 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
1397 CurveMap::iterator it;
1402 TiXmlElement *element =
field->FirstChildElement();
1406 std::string elementType(element->ValueStr());
1409 elementType ==
"Q" || elementType ==
"T",
1410 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
1414 int err = element->QueryIntAttribute(
"ID", &indx);
1415 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1417 it = curvedFaces.find(indx);
1420 TiXmlNode *elementChild = element->FirstChild();
1421 std::string elementStr;
1422 while (elementChild)
1424 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1426 elementStr += elementChild->ToText()->ValueStr();
1428 elementChild = elementChild->NextSibling();
1432 "Unable to read element description body.");
1436 if (elementType ==
"T")
1439 int edge1, edge2, edge3;
1440 std::istringstream elementDataStrm(elementStr.c_str());
1444 elementDataStrm >> edge1;
1445 elementDataStrm >> edge2;
1446 elementDataStrm >> edge3;
1449 !elementDataStrm.fail(),
1450 (std::string(
"Unable to read element data for TRIANGLE: ") +
1460 if (it == curvedFaces.end())
1468 indx, edges, it->second);
1470 triGeoms[indx]->SetGlobalID(indx);
1476 (std::string(
"Unable to read element data for TRIANGLE: ") +
1481 else if (elementType ==
"Q")
1484 int edge1, edge2, edge3, edge4;
1485 std::istringstream elementDataStrm(elementStr.c_str());
1489 elementDataStrm >> edge1;
1490 elementDataStrm >> edge2;
1491 elementDataStrm >> edge3;
1492 elementDataStrm >> edge4;
1495 !elementDataStrm.fail(),
1496 (std::string(
"Unable to read element data for QUAD: ") +
1508 if (it == curvedFaces.end())
1519 quadGeoms[indx]->SetGlobalID(indx);
1525 (std::string(
"Unable to read element data for QUAD: ") +
1531 element = element->NextSiblingElement();
1539 auto &prismGeoms =
m_meshGraph->GetAllPrismGeoms();
1550 TiXmlElement *element =
field->FirstChildElement();
1554 std::string elementType(element->ValueStr());
1558 elementType ==
"A" || elementType ==
"P" || elementType ==
"R" ||
1560 (std::string(
"Unknown 3D element type: ") + elementType).c_str());
1564 int err = element->QueryIntAttribute(
"ID", &indx);
1565 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1568 TiXmlNode *elementChild = element->FirstChild();
1569 std::string elementStr;
1570 while (elementChild)
1572 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1574 elementStr += elementChild->ToText()->ValueStr();
1576 elementChild = elementChild->NextSibling();
1580 "Unable to read element description body.");
1582 std::istringstream elementDataStrm(elementStr.c_str());
1588 if (elementType ==
"A")
1602 std::stringstream errorstring;
1603 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1604 <<
" triangle face(s), and " << kNqfaces
1605 <<
" quadrilateral face(s).";
1606 for (
int i = 0; i < kNfaces; i++)
1609 elementDataStrm >> faceID;
1616 std::stringstream errorstring;
1617 errorstring <<
"Element " << indx
1618 <<
" has invalid face: " << faceID;
1619 ASSERTL0(
false, errorstring.str().c_str());
1623 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1624 tfaces[Ntfaces++] = static_pointer_cast<TriGeom>(face);
1626 else if (face->GetShapeType() ==
1629 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1637 "Unable to read element data for TETRAHEDRON: ") +
1640 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1641 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1646 tetGeoms[indx] = tetgeom;
1647 m_meshGraph->PopulateFaceToElMap(tetgeom, kNfaces);
1653 "Unable to read element data for TETRAHEDRON: ") +
1659 else if (elementType ==
"P")
1674 std::stringstream errorstring;
1675 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1676 <<
" triangle face(s), and " << kNqfaces
1677 <<
" quadrilateral face(s).";
1678 for (
int i = 0; i < kNfaces; i++)
1681 elementDataStrm >> faceID;
1688 std::stringstream errorstring;
1689 errorstring <<
"Element " << indx
1690 <<
" has invalid face: " << faceID;
1691 ASSERTL0(
false, errorstring.str().c_str());
1695 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1696 faces[Nfaces++] = static_pointer_cast<TriGeom>(face);
1699 else if (face->GetShapeType() ==
1702 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1703 faces[Nfaces++] = static_pointer_cast<QuadGeom>(face);
1711 !elementDataStrm.fail(),
1712 (std::string(
"Unable to read element data for PYRAMID: ") +
1715 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1716 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1721 pyrGeoms[indx] = pyrgeom;
1722 m_meshGraph->PopulateFaceToElMap(pyrgeom, kNfaces);
1728 (std::string(
"Unable to read element data for PYRAMID: ") +
1734 else if (elementType ==
"R")
1749 std::stringstream errorstring;
1750 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1751 <<
" triangle face(s), and " << kNqfaces
1752 <<
" quadrilateral face(s).";
1754 for (
int i = 0; i < kNfaces; i++)
1757 elementDataStrm >> faceID;
1764 std::stringstream errorstring;
1765 errorstring <<
"Element " << indx
1766 <<
" has invalid face: " << faceID;
1767 ASSERTL0(
false, errorstring.str().c_str());
1771 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1773 std::static_pointer_cast<TriGeom>(face);
1776 else if (face->GetShapeType() ==
1779 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1781 std::static_pointer_cast<QuadGeom>(face);
1789 !elementDataStrm.fail(),
1790 (std::string(
"Unable to read element data for PRISM: ") +
1793 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1794 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1799 prismGeoms[indx] = prismgeom;
1800 m_meshGraph->PopulateFaceToElMap(prismgeom, kNfaces);
1806 (std::string(
"Unable to read element data for PRISM: ") +
1812 else if (elementType ==
"H")
1827 std::stringstream errorstring;
1828 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1829 <<
" triangle face(s), and " << kNqfaces
1830 <<
" quadrilateral face(s).";
1831 for (
int i = 0; i < kNfaces; i++)
1834 elementDataStrm >> faceID;
1841 std::stringstream errorstring;
1842 errorstring <<
"Element " << indx
1843 <<
" has invalid face: " << faceID;
1844 ASSERTL0(
false, errorstring.str().c_str());
1848 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1852 else if (face->GetShapeType() ==
1855 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1857 std::static_pointer_cast<QuadGeom>(face);
1865 "Unable to read element data for HEXAHEDRAL: ") +
1868 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1869 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1874 hexGeoms[indx] = hexgeom;
1875 m_meshGraph->PopulateFaceToElMap(hexgeom, kNfaces);
1881 "Unable to read element data for HEXAHEDRAL: ") +
1887 element = element->NextSiblingElement();
1893 auto &meshComposites =
m_meshGraph->GetComposites();
1894 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
1896 TiXmlElement *
field =
nullptr;
1903 TiXmlElement *node =
field->FirstChildElement(
"C");
1906 int nextCompositeNumber = -1;
1913 nextCompositeNumber++;
1916 int err = node->QueryIntAttribute(
"ID", &indx);
1917 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
1921 TiXmlNode *compositeChild = node->FirstChild();
1926 while (compositeChild &&
1927 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
1929 compositeChild = compositeChild->NextSibling();
1932 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
1933 std::string compositeStr = compositeChild->ToText()->ValueStr();
1937 std::istringstream compositeDataStrm(compositeStr.c_str());
1942 std::string prevCompositeElementStr;
1944 while (!compositeDataStrm.fail())
1946 std::string compositeElementStr;
1947 compositeDataStrm >> compositeElementStr;
1949 if (!compositeDataStrm.fail())
1954 meshComposites[indx] =
1958 if (compositeElementStr.length() > 0)
1961 compositeElementStr,
1962 meshComposites[indx]);
1964 prevCompositeElementStr = compositeElementStr;
1972 (std::string(
"Unable to read COMPOSITE data for composite: ") +
1979 err = node->QueryStringAttribute(
"NAME", &
name);
1980 if (err == TIXML_SUCCESS)
1982 compositesLabels[indx] =
name;
1986 node = node->NextSiblingElement(
"C");
1990 "At least one composite must be specified.");
1994 const std::string &token,
1997 int meshDimension =
m_meshGraph->GetMeshDimension();
1999 switch (meshDimension)
2014 const std::string &token,
2022 std::istringstream tokenStream(token);
2023 std::istringstream prevTokenStream(prevToken);
2028 tokenStream >> type;
2030 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2031 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2035 (std::string(
"Error reading index definition:") + token).c_str());
2037 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2039 typedef vector<unsigned int> SeqVectorType;
2040 SeqVectorType seqVector;
2045 (std::string(
"Ill-formed sequence definition: ") + indxStr)
2049 prevTokenStream >> prevType;
2052 bool validSequence =
2053 (prevToken.empty() ||
2054 (type ==
'V' && prevType ==
'V') ||
2055 (type ==
'S' && prevType ==
'S'));
2058 std::string(
"Invalid combination of composite items: ") +
2059 type +
" and " + prevType +
".");
2064 for (SeqVectorType::iterator iter = seqVector.begin();
2065 iter != seqVector.end(); ++iter)
2067 if (vertSet.find(*iter) == vertSet.end())
2070 "Unknown vertex index: " +
2071 std::to_string(*iter));
2075 composite->m_geomVec.push_back(vertSet[*iter]);
2081 for (SeqVectorType::iterator iter = seqVector.begin();
2082 iter != seqVector.end(); ++iter)
2084 if (segGeoms.find(*iter) == segGeoms.end())
2087 "Unknown segment index: " +
2088 std::to_string(*iter));
2092 composite->m_geomVec.push_back(segGeoms[*iter]);
2099 "Unrecognized composite token: " + token);
2105 "Problem processing composite token: " + token);
2112 const std::string &token,
2122 std::istringstream tokenStream(token);
2123 std::istringstream prevTokenStream(prevToken);
2128 tokenStream >> type;
2130 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2131 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2135 (std::string(
"Error reading index definition:") + token).c_str());
2137 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2138 std::vector<unsigned int> seqVector;
2139 std::vector<unsigned int>::iterator seqIter;
2144 (std::string(
"Error reading composite elements: ") + indxStr)
2147 prevTokenStream >> prevType;
2150 bool validSequence =
2151 (prevToken.empty() ||
2152 (type ==
'V' && prevType ==
'V') ||
2153 (type ==
'E' && prevType ==
'E') ||
2154 ((type ==
'T' || type ==
'Q') &&
2155 (prevType ==
'T' || prevType ==
'Q')));
2158 std::string(
"Invalid combination of composite items: ") +
2159 type +
" and " + prevType +
".");
2164 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2167 if (segGeoms.find(*seqIter) == segGeoms.end())
2170 "Unknown edge index: " +
2171 std::to_string(*seqIter));
2175 composite->m_geomVec.push_back(segGeoms[*seqIter]);
2182 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2185 if (triGeoms.count(*seqIter) == 0)
2188 "Unknown triangle index: " +
2189 std::to_string(*seqIter));
2195 composite->m_geomVec.push_back(triGeoms[*seqIter]);
2204 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2207 if (quadGeoms.count(*seqIter) == 0)
2211 "Unknown quad index: " + std::to_string(*seqIter) +
2212 " in Composite section");
2216 if (
m_meshGraph->CheckRange(*quadGeoms[*seqIter]))
2218 composite->m_geomVec.push_back(quadGeoms[*seqIter]);
2226 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2229 if (*seqIter >= vertSet.size())
2232 "Unknown vertex index: " +
2233 std::to_string(*seqIter));
2237 composite->m_geomVec.push_back(vertSet[*seqIter]);
2244 "Unrecognized composite token: " + token);
2250 "Problem processing composite token: " + token);
2257 const std::string &token,
2271 std::istringstream tokenStream(token);
2272 std::istringstream prevTokenStream(prevToken);
2277 tokenStream >> type;
2279 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2280 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2283 "Error reading index definition: " + token);
2285 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2287 std::vector<unsigned int> seqVector;
2288 std::vector<unsigned int>::iterator seqIter;
2292 ASSERTL0(err,
"Error reading composite elements: " + indxStr);
2294 prevTokenStream >> prevType;
2298 map<char, int> typeMap;
2309 bool validSequence =
2310 (prevToken.empty() || (typeMap[type] == typeMap[prevType]));
2313 std::string(
"Invalid combination of composite items: ") +
2314 type +
" and " + prevType +
".");
2319 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2322 if (vertSet.find(*seqIter) == vertSet.end())
2325 "Unknown vertex index: " +
2326 std::to_string(*seqIter));
2330 composite->m_geomVec.push_back(vertSet[*seqIter]);
2336 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2339 if (segGeoms.find(*seqIter) == segGeoms.end())
2342 "Unknown edge index: " +
2343 std::to_string(*seqIter));
2347 composite->m_geomVec.push_back(segGeoms[*seqIter]);
2353 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2361 "Unknown face index: " +
2362 std::to_string(*seqIter));
2368 composite->m_geomVec.push_back(face);
2375 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2378 if (triGeoms.find(*seqIter) == triGeoms.end())
2381 "Unknown triangle index: " +
2382 std::to_string(*seqIter));
2388 composite->m_geomVec.push_back(triGeoms[*seqIter]);
2395 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2398 if (quadGeoms.find(*seqIter) == quadGeoms.end())
2401 "Unknown quad index: " +
2402 std::to_string(*seqIter));
2406 if (
m_meshGraph->CheckRange(*quadGeoms[*seqIter]))
2408 composite->m_geomVec.push_back(quadGeoms[*seqIter]);
2416 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2419 if (tetGeoms.find(*seqIter) == tetGeoms.end())
2422 "Unknown tet index: " +
2423 std::to_string(*seqIter));
2429 composite->m_geomVec.push_back(tetGeoms[*seqIter]);
2437 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2440 if (pyrGeoms.find(*seqIter) == pyrGeoms.end())
2443 "Unknown pyramid index: " +
2444 std::to_string(*seqIter));
2450 composite->m_geomVec.push_back(pyrGeoms[*seqIter]);
2458 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2461 if (prismGeoms.find(*seqIter) == prismGeoms.end())
2464 "Unknown prism index: " +
2465 std::to_string(*seqIter));
2469 if (
m_meshGraph->CheckRange(*prismGeoms[*seqIter]))
2471 composite->m_geomVec.push_back(
2472 prismGeoms[*seqIter]);
2480 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2483 if (hexGeoms.find(*seqIter) == hexGeoms.end())
2486 "Unknown hex index: " +
2487 std::to_string(*seqIter));
2493 composite->m_geomVec.push_back(hexGeoms[*seqIter]);
2501 "Unrecognized composite token: " + token);
2507 "Problem processing composite token: " + token);
2515 TiXmlElement *vertTag =
new TiXmlElement(
"VERTEX");
2517 for (
auto &i : verts)
2520 s << scientific << setprecision(8) << (*i.second)(0) <<
" "
2521 << (*i.second)(1) <<
" " << (*i.second)(2);
2522 TiXmlElement *v =
new TiXmlElement(
"V");
2523 v->SetAttribute(
"ID", i.second->GetGlobalID());
2524 v->LinkEndChild(
new TiXmlText(s.str()));
2525 vertTag->LinkEndChild(v);
2528 geomTag->LinkEndChild(vertTag);
2533 int meshDimension =
m_meshGraph->GetMeshDimension();
2535 TiXmlElement *edgeTag =
2536 new TiXmlElement(meshDimension == 1 ?
"ELEMENT" :
"EDGE");
2537 string tag = meshDimension == 1 ?
"S" :
"E";
2539 for (
auto &i : edges)
2543 s << seg->GetVid(0) <<
" " << seg->GetVid(1);
2544 TiXmlElement *e =
new TiXmlElement(tag);
2545 e->SetAttribute(
"ID", i.first);
2546 e->LinkEndChild(
new TiXmlText(s.str()));
2547 edgeTag->LinkEndChild(e);
2550 geomTag->LinkEndChild(edgeTag);
2557 for (
auto &i : tris)
2561 s << tri->GetEid(0) <<
" " << tri->GetEid(1) <<
" " << tri->GetEid(2);
2562 TiXmlElement *t =
new TiXmlElement(tag);
2563 t->SetAttribute(
"ID", i.first);
2564 t->LinkEndChild(
new TiXmlText(s.str()));
2565 faceTag->LinkEndChild(t);
2573 for (
auto &i : quads)
2577 s << quad->GetEid(0) <<
" " << quad->GetEid(1) <<
" " << quad->GetEid(2)
2578 <<
" " << quad->GetEid(3);
2579 TiXmlElement *
q =
new TiXmlElement(tag);
2580 q->SetAttribute(
"ID", i.first);
2581 q->LinkEndChild(
new TiXmlText(s.str()));
2582 faceTag->LinkEndChild(
q);
2590 for (
auto &i : hexs)
2594 s << hex->GetFid(0) <<
" " << hex->GetFid(1) <<
" " << hex->GetFid(2)
2595 <<
" " << hex->GetFid(3) <<
" " << hex->GetFid(4) <<
" "
2596 << hex->GetFid(5) <<
" ";
2597 TiXmlElement *h =
new TiXmlElement(tag);
2598 h->SetAttribute(
"ID", i.first);
2599 h->LinkEndChild(
new TiXmlText(s.str()));
2600 elmtTag->LinkEndChild(h);
2608 for (
auto &i : pris)
2612 s << prism->GetFid(0) <<
" " << prism->GetFid(1) <<
" "
2613 << prism->GetFid(2) <<
" " << prism->GetFid(3) <<
" "
2614 << prism->GetFid(4) <<
" ";
2615 TiXmlElement *
p =
new TiXmlElement(tag);
2616 p->SetAttribute(
"ID", i.first);
2617 p->LinkEndChild(
new TiXmlText(s.str()));
2618 elmtTag->LinkEndChild(
p);
2626 for (
auto &i : pyrs)
2630 s << pyr->GetFid(0) <<
" " << pyr->GetFid(1) <<
" " << pyr->GetFid(2)
2631 <<
" " << pyr->GetFid(3) <<
" " << pyr->GetFid(4) <<
" ";
2632 TiXmlElement *
p =
new TiXmlElement(tag);
2633 p->SetAttribute(
"ID", i.first);
2634 p->LinkEndChild(
new TiXmlText(s.str()));
2635 elmtTag->LinkEndChild(
p);
2643 for (
auto &i : tets)
2647 s << tet->GetFid(0) <<
" " << tet->GetFid(1) <<
" " << tet->GetFid(2)
2648 <<
" " << tet->GetFid(3) <<
" ";
2649 TiXmlElement *t =
new TiXmlElement(tag);
2650 t->SetAttribute(
"ID", i.first);
2651 t->LinkEndChild(
new TiXmlText(s.str()));
2652 elmtTag->LinkEndChild(t);
2659 TiXmlElement *curveTag =
new TiXmlElement(
"CURVED");
2660 CurveMap::iterator curveIt;
2663 for (curveIt = edges.begin(); curveIt != edges.end(); ++curveIt)
2666 TiXmlElement *c =
new TiXmlElement(
"E");
2670 for (
int j = 0; j < curve->m_points.size(); ++j)
2673 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2677 c->SetAttribute(
"ID", curveId++);
2678 c->SetAttribute(
"EDGEID", curve->m_curveID);
2679 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2681 c->LinkEndChild(
new TiXmlText(s.str()));
2682 curveTag->LinkEndChild(c);
2685 for (curveIt = faces.begin(); curveIt != faces.end(); ++curveIt)
2688 TiXmlElement *c =
new TiXmlElement(
"F");
2692 for (
int j = 0; j < curve->m_points.size(); ++j)
2695 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2699 c->SetAttribute(
"ID", curveId++);
2700 c->SetAttribute(
"FACEID", curve->m_curveID);
2701 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2703 c->LinkEndChild(
new TiXmlText(s.str()));
2704 curveTag->LinkEndChild(c);
2707 geomTag->LinkEndChild(curveTag);
2711 std::map<int, std::string> &compLabels)
2713 auto &compositesLabels =
m_meshGraph->GetCompositesLabels();
2714 TiXmlElement *compTag =
new TiXmlElement(
"COMPOSITE");
2716 for (
auto &cIt : comps)
2718 if (cIt.second->m_geomVec.size() == 0)
2723 TiXmlElement *c =
new TiXmlElement(
"C");
2724 c->SetAttribute(
"ID", cIt.first);
2725 if (!compositesLabels[cIt.first].empty())
2727 c->SetAttribute(
"NAME", compLabels[cIt.first]);
2730 compTag->LinkEndChild(c);
2733 geomTag->LinkEndChild(compTag);
2737 std::map<int, CompositeMap> &domainMap)
2739 TiXmlElement *domTag =
new TiXmlElement(
"DOMAIN");
2741 vector<unsigned int> idxList;
2742 for (
auto &domain : domainMap)
2744 TiXmlElement *c =
new TiXmlElement(
"D");
2751 for (
const auto &elem : domain.second)
2753 idxList.push_back(elem.first);
2757 c->SetAttribute(
"ID", domain.first);
2758 c->LinkEndChild(
new TiXmlText(s.str()));
2759 domTag->LinkEndChild(c);
2762 geomTag->LinkEndChild(domTag);
2767 int meshDimension =
m_meshGraph->GetMeshDimension();
2768 auto &meshComposites =
m_meshGraph->GetComposites();
2770 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
2772 for (
auto it = meshComposites.begin(); it != meshComposites.end(); it++)
2774 if (it->second->m_geomVec[0]->GetShapeDim() == meshDimension)
2776 TiXmlElement *exp =
new TiXmlElement(
"E");
2777 exp->SetAttribute(
"COMPOSITE",
2778 "C[" + boost::lexical_cast<string>(it->first) +
2780 exp->SetAttribute(
"NUMMODES", 4);
2781 exp->SetAttribute(
"TYPE",
"MODIFIED");
2782 exp->SetAttribute(
"FIELDS",
"u");
2784 expTag->LinkEndChild(exp);
2787 root->LinkEndChild(expTag);
2795 const std::string &outfilename,
bool defaultExp,
2798 int meshDimension =
m_meshGraph->GetMeshDimension();
2799 int spaceDimension =
m_meshGraph->GetSpaceDimension();
2803 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2804 doc.LinkEndChild(decl);
2806 TiXmlElement *root =
new TiXmlElement(
"NEKTAR");
2807 doc.LinkEndChild(root);
2808 TiXmlElement *geomTag =
new TiXmlElement(
"GEOMETRY");
2809 root->LinkEndChild(geomTag);
2817 geomTag->SetAttribute(
"DIM", meshDimension);
2818 geomTag->SetAttribute(
"SPACE", spaceDimension);
2822 geomTag->SetAttribute(
"PARTITION",
m_session->GetComm()->GetRank());
2831 if (meshDimension > 1)
2833 TiXmlElement *faceTag =
2834 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
2838 geomTag->LinkEndChild(faceTag);
2840 if (meshDimension > 2)
2842 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
2849 geomTag->LinkEndChild(elmtTag);
2865 movement->WriteMovement(root);
2869 doc.SaveFile(outfilename);
2873 vector<set<unsigned int>> elements,
2874 vector<unsigned int> partitions)
2885 string dirname = outname +
"_xml";
2886 fs::path pdirname(dirname);
2888 if (!fs::is_directory(dirname))
2890 fs::create_directory(dirname);
2893 ASSERTL0(elements.size() == partitions.size(),
2894 "error in partitioned information");
2896 for (
int i = 0; i < partitions.size(); i++)
2899 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2900 doc.LinkEndChild(decl);
2902 TiXmlElement *root = doc.FirstChildElement(
"NEKTAR");
2903 TiXmlElement *geomTag;
2908 root =
new TiXmlElement(
"NEKTAR");
2909 doc.LinkEndChild(root);
2911 geomTag =
new TiXmlElement(
"GEOMETRY");
2912 root->LinkEndChild(geomTag);
2917 geomTag = root->FirstChildElement(
"GEOMETRY");
2921 geomTag =
new TiXmlElement(
"GEOMETRY");
2922 root->LinkEndChild(geomTag);
2926 int meshDimension =
m_meshGraph->GetMeshDimension();
2927 int spaceDimension =
m_meshGraph->GetSpaceDimension();
2929 geomTag->SetAttribute(
"DIM", meshDimension);
2930 geomTag->SetAttribute(
"SPACE", spaceDimension);
2931 geomTag->SetAttribute(
"PARTITION", partitions[i]);
2941 auto &prismGeoms =
m_meshGraph->GetAllPrismGeoms();
2943 auto &curvedEdges =
m_meshGraph->GetCurvedEdges();
2944 auto &curvedFaces =
m_meshGraph->GetCurvedFaces();
2945 auto &meshComposites =
m_meshGraph->GetComposites();
2959 vector<set<unsigned int>> entityIds(4);
2960 entityIds[meshDimension] = elements[i];
2962 switch (meshDimension)
2966 for (
auto &j : entityIds[3])
2969 if (hexGeoms.count(j))
2972 localHex[j] = hexGeoms[j];
2974 else if (pyrGeoms.count(j))
2977 localPyr[j] = pyrGeoms[j];
2979 else if (prismGeoms.count(j))
2982 localPrism[j] = prismGeoms[j];
2984 else if (tetGeoms.count(j))
2987 localTet[j] = tetGeoms[j];
2991 ASSERTL0(
false,
"element in partition not found");
2994 for (
int k = 0; k < g->GetNumFaces(); k++)
2996 entityIds[2].insert(g->GetFid(k));
2998 for (
int k = 0; k < g->GetNumEdges(); k++)
3000 entityIds[1].insert(g->GetEid(k));
3002 for (
int k = 0; k < g->GetNumVerts(); k++)
3004 entityIds[0].insert(g->GetVid(k));
3011 for (
auto &j : entityIds[2])
3014 if (triGeoms.count(j))
3017 localTri[j] = triGeoms[j];
3019 else if (quadGeoms.count(j))
3022 localQuad[j] = quadGeoms[j];
3026 ASSERTL0(
false,
"element in partition not found");
3029 for (
int k = 0; k < g->GetNumEdges(); k++)
3031 entityIds[1].insert(g->GetEid(k));
3033 for (
int k = 0; k < g->GetNumVerts(); k++)
3035 entityIds[0].insert(g->GetVid(k));
3042 for (
auto &j : entityIds[1])
3045 if (segGeoms.count(j))
3048 localEdge[j] = segGeoms[j];
3052 ASSERTL0(
false,
"element in partition not found");
3055 for (
int k = 0; k < g->GetNumVerts(); k++)
3057 entityIds[0].insert(g->GetVid(k));
3063 if (meshDimension > 2)
3065 for (
auto &j : entityIds[2])
3067 if (triGeoms.count(j))
3069 localTri[j] = triGeoms[j];
3071 else if (quadGeoms.count(j))
3073 localQuad[j] = quadGeoms[j];
3082 if (meshDimension > 1)
3084 for (
auto &j : entityIds[1])
3086 if (segGeoms.count(j))
3088 localEdge[j] = segGeoms[j];
3097 for (
auto &j : entityIds[0])
3099 if (vertSet.count(j))
3101 localVert[j] = vertSet[j];
3111 if (meshDimension > 1)
3113 TiXmlElement *faceTag =
3114 new TiXmlElement(meshDimension == 2 ?
"ELEMENT" :
"FACE");
3118 geomTag->LinkEndChild(faceTag);
3120 if (meshDimension > 2)
3122 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3129 geomTag->LinkEndChild(elmtTag);
3132 for (
auto &j : localTri)
3134 if (curvedFaces.count(j.first))
3136 localCurveFace[j.first] = curvedFaces[j.first];
3139 for (
auto &j : localQuad)
3141 if (curvedFaces.count(j.first))
3143 localCurveFace[j.first] = curvedFaces[j.first];
3146 for (
auto &j : localEdge)
3148 if (curvedEdges.count(j.first))
3150 localCurveEdge[j.first] = curvedEdges[j.first];
3157 std::map<int, std::string> localCompLabels;
3159 for (
auto &j : meshComposites)
3162 int dim = j.second->m_geomVec[0]->GetShapeDim();
3164 for (
int k = 0; k < j.second->m_geomVec.size(); k++)
3166 if (entityIds[dim].count(j.second->m_geomVec[k]->GetGlobalID()))
3168 comp->m_geomVec.push_back(j.second->m_geomVec[k]);
3172 if (comp->m_geomVec.size())
3174 localComp[j.first] = comp;
3175 auto compositesLabels =
m_meshGraph->GetCompositesLabels();
3176 if (!compositesLabels[j.first].empty())
3178 localCompLabels[j.first] = compositesLabels[j.first];
3185 map<int, CompositeMap> domain;
3186 for (
auto &j : localComp)
3188 for (
auto &dom : globalDomain)
3190 for (
auto &dIt : dom.second)
3192 if (j.first == dIt.first)
3194 domain[dom.first][j.first] = j.second;
3203 if (
m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
3205 std::set<int> vBndRegionIdList;
3206 TiXmlElement *vConditions =
3207 new TiXmlElement(*
m_session->GetElement(
"Nektar/Conditions"));
3208 TiXmlElement *vBndRegions =
3209 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
3212 TiXmlElement *vBndConditions =
3213 vConditions->FirstChildElement(
"BOUNDARYCONDITIONS");
3217 TiXmlElement *vItem;
3223 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3224 ->FirstChildElement(
"TIMELEVEL") !=
nullptr;
3226 TiXmlElement *vNewBndRegions =
3227 multiLevel ?
new TiXmlElement(
"TIMELEVEL")
3228 :
new TiXmlElement(
"BOUNDARYREGIONS");
3229 vItem = vBndRegions->FirstChildElement();
3230 auto graph_bndRegOrder =
m_meshGraph->GetBndRegionOrdering();
3233 std::string vSeqStr =
3234 vItem->FirstChild()->ToText()->Value();
3235 std::string::size_type indxBeg =
3236 vSeqStr.find_first_of(
'[') + 1;
3237 std::string::size_type indxEnd =
3238 vSeqStr.find_last_of(
']') - 1;
3239 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
3240 std::vector<unsigned int> vSeq;
3243 vector<unsigned int> idxList;
3245 for (
unsigned int i = 0; i < vSeq.size(); ++i)
3247 if (localComp.find(vSeq[i]) != localComp.end())
3249 idxList.push_back(vSeq[i]);
3252 int p = atoi(vItem->Attribute(
"ID"));
3254 std::string vListStr =
3257 if (vListStr.length() == 0)
3259 TiXmlElement *tmp = vItem;
3260 vItem = vItem->NextSiblingElement();
3261 vBndRegions->RemoveChild(tmp);
3265 vListStr =
"C[" + vListStr +
"]";
3266 TiXmlText *vList =
new TiXmlText(vListStr);
3267 TiXmlElement *vNewElement =
new TiXmlElement(
"B");
3268 vNewElement->SetAttribute(
"ID",
p);
3269 vNewElement->LinkEndChild(vList);
3270 vNewBndRegions->LinkEndChild(vNewElement);
3271 vBndRegionIdList.insert(
p);
3272 vItem = vItem->NextSiblingElement();
3277 graph_bndRegOrder[
p] = vSeq;
3282 size_t timeLevel = 0;
3285 vNewBndRegions->SetAttribute(
"VALUE", timeLevel);
3286 vConditions->FirstChildElement(
"BOUNDARYREGIONS")
3287 ->ReplaceChild(vBndRegions, *vNewBndRegions);
3288 vBndRegions = vBndRegions->NextSiblingElement();
3294 vConditions->ReplaceChild(vBndRegions, *vNewBndRegions);
3300 vItem = vBndConditions->FirstChildElement();
3303 std::set<int>::iterator x;
3304 if ((x = vBndRegionIdList.find(atoi(vItem->Attribute(
3305 "REF")))) != vBndRegionIdList.end())
3307 vItem->SetAttribute(
"REF", *x);
3308 vItem = vItem->NextSiblingElement();
3312 TiXmlElement *tmp = vItem;
3313 vItem = vItem->NextSiblingElement();
3314 vBndConditions->RemoveChild(tmp);
3318 root->LinkEndChild(vConditions);
3322 TiXmlElement *vSrc =
3323 m_session->GetElement(
"Nektar")->FirstChildElement();
3326 std::string vName = boost::to_upper_copy(vSrc->ValueStr());
3327 if (vName !=
"GEOMETRY" && vName !=
"CONDITIONS")
3329 root->LinkEndChild(
new TiXmlElement(*vSrc));
3331 vSrc = vSrc->NextSiblingElement();
3337 pad % partitions[i];
3338 fs::path pFilename(pad.str());
3340 fs::path fullpath = pdirname / pFilename;
3347 auto &meshComposites =
m_meshGraph->GetComposites();
3352 for (
auto &c : meshComposites)
3354 bool fillComp =
true;
3355 for (
auto &
d : domain[0])
3357 if (c.second ==
d.second)
3364 std::vector<unsigned int> ids;
3365 for (
auto &elmt : c.second->m_geomVec)
3367 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)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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.
static const int kNqfaces
static const int kNtfaces
BndRegionOrdering m_bndRegOrder
LibUtilities::SessionReaderSharedPtr m_session
void ReadGeometry(LibUtilities::DomainRangeShPtr rng, 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_WriteHexs(TiXmlElement *elmtTag, HexGeomMap &hexs)
void ResolveGeomRef2D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
void ResolveGeomRef3D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
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_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, PyrGeomMap &pyrs)
virtual void v_ReadEdges()
virtual void v_ReadFaces()
void v_PartitionMesh(LibUtilities::SessionReaderSharedPtr session) override
virtual void v_ReadCurves()
void WriteDefaultExpansion(TiXmlElement *root)
void v_ReadGeometry(LibUtilities::DomainRangeShPtr rng, bool fillGraph) override
virtual void v_ReadElements2D()
virtual void v_WriteTets(TiXmlElement *elmtTag, TetGeomMap &tets)
void ResolveGeomRef1D(const std::string &prevToken, const std::string &token, CompositeSharedPtr &composite)
virtual void v_WriteEdges(TiXmlElement *geomTag, SegGeomMap &edges)
virtual void v_ReadVertices()
virtual void v_WritePrisms(TiXmlElement *elmtTag, PrismGeomMap &pris)
void WriteComposites(TiXmlElement *geomTag, CompositeMap &comps, std::map< int, std::string > &compLabels)
static std::string className
void WriteXMLGeometry(std::string outname, std::vector< std::set< unsigned int > > elements, std::vector< unsigned int > partitions)
virtual void v_WriteVertices(TiXmlElement *geomTag, PointGeomMap &verts)
CompositeOrdering CreateCompositeOrdering()
virtual void v_WriteQuads(TiXmlElement *faceTag, QuadGeomMap &quads)
virtual void v_WriteTris(TiXmlElement *faceTag, TriGeomMap &tris)
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
static const int kNedges
Get the orientation of face1.
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
static DomainRangeShPtr NullDomainRangeShPtr
@ SIZE_PointsType
Length of enum list.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, TriGeomSharedPtr > TriGeomMap
std::map< int, std::vector< unsigned int > > CompositeOrdering
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
std::map< int, PyrGeomSharedPtr > PyrGeomMap
std::map< int, QuadGeomSharedPtr > QuadGeomMap
std::shared_ptr< PrismGeom > PrismGeomSharedPtr
MeshPartitionFactory & GetMeshPartitionFactory()
std::shared_ptr< Composite > CompositeSharedPtr
std::map< int, SegGeomSharedPtr > SegGeomMap
std::shared_ptr< Curve > CurveSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
std::shared_ptr< HexGeom > HexGeomSharedPtr
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::map< int, TetGeomSharedPtr > TetGeomMap
std::shared_ptr< PyrGeom > PyrGeomSharedPtr
MeshGraphIOFactory & GetMeshGraphIOFactory()
std::shared_ptr< TetGeom > TetGeomSharedPtr
std::map< int, PrismGeomSharedPtr > PrismGeomMap
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::shared_ptr< Geometry > GeometrySharedPtr
std::shared_ptr< TriGeom > TriGeomSharedPtr
std::map< int, HexGeomSharedPtr > HexGeomMap
std::map< int, PointGeomSharedPtr > PointGeomMap
std::map< int, CompositeSharedPtr > CompositeMap
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
std::vector< double > d(NPUPPER *NPUPPER)
std::vector< double > q(NPUPPER *NPUPPER)