46 #include <boost/format.hpp>
54 namespace SpatialDomains
57 std::string MeshGraphXml::className =
59 "Xml", MeshGraphXml::create,
"IO with Xml geometry");
61 void MeshGraphXml::PartitionMesh(
67 const bool isRoot = comm->TreatAsRankZero();
79 int isPartitioned = 0;
82 if (m_session->DefinesElement(
"Nektar/Geometry"))
84 if (m_session->GetElement(
"Nektar/Geometry")->Attribute(
"PARTITION"))
86 std::cout <<
"Using pre-partitioned mesh." << std::endl;
91 comm->Bcast(isPartitioned, 0);
99 m_session->InitSession();
106 string partitionerName =
"Metis";
109 partitionerName =
"Scotch";
111 if (session->DefinesCmdLineArgument(
"use-metis"))
113 partitionerName =
"Metis";
115 if (session->DefinesCmdLineArgument(
"use-scotch"))
117 partitionerName =
"Scotch";
123 if (session->DefinesCmdLineArgument(
"part-only")||
124 session->DefinesCmdLineArgument(
"part-only-overlapping"))
129 "The 'part-only' option should be used in serial.");
136 auto comp = CreateCompositeDescriptor();
140 partitionerName, session, m_meshDimension,
141 CreateMeshEntities(), comp);
143 if (session->DefinesCmdLineArgument(
"part-only"))
145 nParts = session->GetCmdLineArgument<
int>(
"part-only");
146 partitioner->PartitionMesh(nParts,
true);
150 nParts = session->GetCmdLineArgument<
int>(
"part-only-overlapping");
151 partitioner->PartitionMesh(nParts,
true,
true);
154 vector<set<unsigned int>> elmtIDs;
155 vector<unsigned int> parts(nParts);
156 for (
int i = 0; i < nParts; ++i)
158 vector<unsigned int> elIDs;
159 set<unsigned int> tmp;
160 partitioner->GetElementIDs(i, elIDs);
161 tmp.insert(elIDs.begin(), elIDs.end());
162 elmtIDs.push_back(tmp);
166 this->WriteXMLGeometry(m_session->GetSessionName(), elmtIDs, parts);
168 if (isRoot && session->DefinesCmdLineArgument(
"part-info"))
170 partitioner->PrintPartInfo(std::cout);
177 if (commMesh->GetSize() > 1)
179 int nParts = commMesh->GetSize();
181 if (session->GetSharedFilesystem())
183 vector<unsigned int> keys, vals;
192 m_compOrder = CreateCompositeOrdering();
193 auto comp = CreateCompositeDescriptor();
198 partitionerName, session, m_meshDimension,
199 CreateMeshEntities(), comp);
201 partitioner->PartitionMesh(nParts,
true);
203 vector<set<unsigned int>> elmtIDs;
204 vector<unsigned int> parts(nParts);
205 for (i = 0; i < nParts; ++i)
207 vector<unsigned int> elIDs;
208 set<unsigned int> tmp;
209 partitioner->GetElementIDs(i, elIDs);
210 tmp.insert(elIDs.begin(), elIDs.end());
211 elmtIDs.push_back(tmp);
217 this->WriteXMLGeometry(
218 m_session->GetSessionName(), elmtIDs, parts);
225 keys[0] = m_compOrder.size();
226 keys[1] = m_bndRegOrder.size();
227 comm->Bcast(keys, 0);
231 keys.resize(m_compOrder.size());
232 vals.resize(m_compOrder.size());
235 for (
auto &cIt : m_compOrder)
237 keys[i ] = cIt.first;
238 vals[i++] = cIt.second.size();
242 comm->Bcast(keys, 0);
243 comm->Bcast(vals, 0);
244 for (
auto &cIt : m_compOrder)
246 comm->Bcast(cIt.second, 0);
251 keys.resize(m_bndRegOrder.size());
252 vals.resize(m_bndRegOrder.size());
255 for (
auto &bIt : m_bndRegOrder)
257 keys[i ] = bIt.first;
258 vals[i++] = bIt.second.size();
262 comm->Bcast(keys, 0);
263 comm->Bcast(vals, 0);
264 for (
auto &bIt : m_bndRegOrder)
266 comm->Bcast(bIt.second, 0);
269 if (session->DefinesCmdLineArgument(
"part-info"))
271 partitioner->PrintPartInfo(std::cout);
277 comm->Bcast(keys, 0);
279 int cmpSize = keys[0];
280 int bndSize = keys[1];
282 keys.resize(cmpSize);
283 vals.resize(cmpSize);
284 comm->Bcast(keys, 0);
285 comm->Bcast(vals, 0);
287 for (
int i = 0; i < keys.size(); ++i)
289 vector<unsigned int> tmp(vals[i]);
291 m_compOrder[keys[i]] = tmp;
294 keys.resize(bndSize);
295 vals.resize(bndSize);
296 comm->Bcast(keys, 0);
297 comm->Bcast(vals, 0);
299 for (
int i = 0; i < keys.size(); ++i)
301 vector<unsigned int> tmp(vals[i]);
303 m_bndRegOrder[keys[i]] = tmp;
309 m_session->InitSession();
312 m_compOrder = CreateCompositeOrdering();
313 auto comp = CreateCompositeDescriptor();
320 partitionerName, session, m_meshDimension,
321 CreateMeshEntities(), comp);
323 partitioner->PartitionMesh(nParts,
false);
325 vector<unsigned int> parts(1), tmp;
326 parts[0] = commMesh->GetRank();
327 vector<set<unsigned int>> elIDs(1);
328 partitioner->GetElementIDs(parts[0], tmp);
329 elIDs[0].insert(tmp.begin(), tmp.end());
330 this->WriteXMLGeometry(session->GetSessionName(), elIDs, parts);
332 if (m_session->DefinesCmdLineArgument(
"part-info") && isRoot)
334 partitioner->PrintPartInfo(std::cout);
341 std::string dirname = m_session->GetSessionName() +
"_xml";
342 fs::path pdirname(dirname);
344 pad % comm->GetRowComm()->GetRank();
345 fs::path pFilename(pad.str());
346 fs::path fullpath = pdirname / pFilename;
348 std::vector<std::string> filenames = {
350 m_session->InitSession(filenames);
357 m_session->InitSession();
362 void MeshGraphXml::ReadGeometry(
368 m_curvedEdges.clear();
369 m_curvedFaces.clear();
375 m_prismGeoms.clear();
377 m_meshComposites.clear();
378 m_compositesLabels.clear();
380 m_expansionMapShPtrMap.clear();
382 m_faceToElMap.clear();
385 m_xmlGeom = m_session->GetElement(
"NEKTAR/GEOMETRY");
389 TiXmlAttribute *attr = m_xmlGeom->FirstAttribute();
394 m_meshPartitioned =
false;
396 m_spaceDimension = 3;
400 std::string attrName(attr->Name());
401 if (attrName ==
"DIM")
403 err = attr->QueryIntValue(&m_meshDimension);
404 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
406 else if (attrName ==
"SPACE")
408 err = attr->QueryIntValue(&m_spaceDimension);
409 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
411 else if (attrName ==
"PARTITION")
413 err = attr->QueryIntValue(&m_partition);
414 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read partition.");
415 m_meshPartitioned =
true;
419 std::string errstr(
"Unknown attribute: ");
428 ASSERTL0(m_meshDimension <= m_spaceDimension,
429 "Mesh dimension greater than space dimension");
433 if (m_meshDimension >= 2)
436 if (m_meshDimension == 3)
447 MeshGraph::FillGraph();
451 void MeshGraphXml::ReadVertices()
454 TiXmlElement *element = m_xmlGeom->FirstChildElement(
"VERTEX");
455 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
462 const char *xscal = element->Attribute(
"XSCALE");
469 std::string xscalstr = xscal;
471 xscale = expEvaluator.
Evaluate(expr_id);
474 const char *yscal = element->Attribute(
"YSCALE");
481 std::string yscalstr = yscal;
483 yscale = expEvaluator.
Evaluate(expr_id);
486 const char *zscal = element->Attribute(
"ZSCALE");
493 std::string zscalstr = zscal;
495 zscale = expEvaluator.
Evaluate(expr_id);
503 const char *xmov = element->Attribute(
"XMOVE");
510 std::string xmovstr = xmov;
512 xmove = expEvaluator.
Evaluate(expr_id);
515 const char *ymov = element->Attribute(
"YMOVE");
522 std::string ymovstr = ymov;
524 ymove = expEvaluator.
Evaluate(expr_id);
527 const char *zmov = element->Attribute(
"ZMOVE");
534 std::string zmovstr = zmov;
536 zmove = expEvaluator.
Evaluate(expr_id);
539 TiXmlElement *vertex = element->FirstChildElement(
"V");
542 int nextVertexNumber = -1;
548 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
549 std::string attrName(vertexAttr->Name());
552 (std::string(
"Unknown attribute name: ") + attrName).c_str());
554 int err = vertexAttr->QueryIntValue(&indx);
555 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
558 std::string vertexBodyStr;
560 TiXmlNode *vertexBody = vertex->FirstChild();
565 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
567 vertexBodyStr += vertexBody->ToText()->Value();
568 vertexBodyStr +=
" ";
571 vertexBody = vertexBody->NextSibling();
575 "Vertex definitions must contain vertex data.");
579 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
583 while (!vertexDataStrm.fail())
585 vertexDataStrm >> xval >> yval >> zval;
587 xval = xval * xscale + xmove;
588 yval = yval * yscale + ymove;
589 zval = zval * zscale + zmove;
594 if (!vertexDataStrm.fail())
598 m_spaceDimension, indx, xval, yval, zval));
599 m_vertSet[indx] = vert;
605 ASSERTL0(
false,
"Unable to read VERTEX data.");
608 vertex = vertex->NextSiblingElement(
"V");
612 void MeshGraphXml::ReadCurves()
616 TiXmlElement *element = m_xmlGeom->FirstChildElement(
"VERTEX");
617 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
622 const char *xscal = element->Attribute(
"XSCALE");
629 std::string xscalstr = xscal;
631 xscale = expEvaluator.
Evaluate(expr_id);
634 const char *yscal = element->Attribute(
"YSCALE");
641 std::string yscalstr = yscal;
643 yscale = expEvaluator.
Evaluate(expr_id);
646 const char *zscal = element->Attribute(
"ZSCALE");
653 std::string zscalstr = zscal;
655 zscale = expEvaluator.
Evaluate(expr_id);
663 const char *xmov = element->Attribute(
"XMOVE");
670 std::string xmovstr = xmov;
672 xmove = expEvaluator.
Evaluate(expr_id);
675 const char *ymov = element->Attribute(
"YMOVE");
682 std::string ymovstr = ymov;
684 ymove = expEvaluator.
Evaluate(expr_id);
687 const char *zmov = element->Attribute(
"ZMOVE");
694 std::string zmovstr = zmov;
696 zmove = expEvaluator.
Evaluate(expr_id);
702 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"CURVED");
713 TiXmlElement *edgelement = field->FirstChildElement(
"E");
715 int edgeindx, edgeid;
716 int nextEdgeNumber = -1;
723 std::string edge(edgelement->ValueStr());
725 (std::string(
"Unknown 3D curve type:") + edge).c_str());
728 err = edgelement->QueryIntAttribute(
"ID", &edgeindx);
729 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
732 err = edgelement->QueryIntAttribute(
"EDGEID", &edgeid);
734 "Unable to read curve attribute EDGEID.");
737 std::string elementStr;
738 TiXmlNode *elementChild = edgelement->FirstChild();
743 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
745 elementStr += elementChild->ToText()->ValueStr();
748 elementChild = elementChild->NextSibling();
751 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
759 std::string typeStr = edgelement->Attribute(
"TYPE");
760 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
761 "points definition");
765 const std::string *endStr =
767 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
769 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
773 err = edgelement->QueryIntAttribute(
"NUMPOINTS", &numPts);
775 "Unable to read curve attribute NUMPOINTS.");
781 std::istringstream elementDataStrm(elementStr.c_str());
784 while (!elementDataStrm.fail())
786 elementDataStrm >> xval >> yval >> zval;
788 xval = xval * xscale + xmove;
789 yval = yval * yscale + ymove;
790 zval = zval * zscale + zmove;
795 if (!elementDataStrm.fail())
799 m_meshDimension, edgeindx, xval, yval, zval));
801 curve->m_points.push_back(vert);
808 (std::string(
"Unable to read curve data for EDGE: ") +
813 ASSERTL0(curve->m_points.size() == numPts,
814 "Number of points specificed by attribute "
815 "NUMPOINTS is different from number of points "
816 "in list (edgeid = " +
817 boost::lexical_cast<string>(edgeid));
819 m_curvedEdges[edgeid] = curve;
821 edgelement = edgelement->NextSiblingElement(
"E");
827 TiXmlElement *facelement = field->FirstChildElement(
"F");
828 int faceindx, faceid;
832 std::string face(facelement->ValueStr());
834 (std::string(
"Unknown 3D curve type: ") + face).c_str());
837 err = facelement->QueryIntAttribute(
"ID", &faceindx);
838 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read curve attribute ID.");
841 err = facelement->QueryIntAttribute(
"FACEID", &faceid);
843 "Unable to read curve attribute FACEID.");
846 std::string elementStr;
847 TiXmlNode *elementChild = facelement->FirstChild();
852 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
854 elementStr += elementChild->ToText()->ValueStr();
857 elementChild = elementChild->NextSibling();
860 ASSERTL0(!elementStr.empty(),
"Unable to read curve description body.");
866 std::string typeStr = facelement->Attribute(
"TYPE");
867 ASSERTL0(!typeStr.empty(),
"TYPE must be specified in "
868 "points definition");
871 const std::string *endStr =
873 const std::string *ptsStr =
std::find(begStr, endStr, typeStr);
875 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
878 std::string numptsStr = facelement->Attribute(
"NUMPOINTS");
880 "NUMPOINTS must be specified in points definition");
889 ASSERTL0(numPts >= 3,
"NUMPOINTS for face must be greater than 2");
893 ASSERTL0(ptsStr != endStr,
"Invalid points type.");
898 std::istringstream elementDataStrm(elementStr.c_str());
901 while (!elementDataStrm.fail())
903 elementDataStrm >> xval >> yval >> zval;
909 if (!elementDataStrm.fail())
913 m_meshDimension, faceindx, xval, yval, zval));
914 curve->m_points.push_back(vert);
921 (std::string(
"Unable to read curve data for FACE: ") +
925 m_curvedFaces[faceid] = curve;
927 facelement = facelement->NextSiblingElement(
"F");
932 void MeshGraphXml::ReadDomain()
934 TiXmlElement *domain = NULL;
936 domain = m_xmlGeom->FirstChildElement(
"DOMAIN");
938 ASSERTL0(domain,
"Unable to find DOMAIN tag in file.");
942 TiXmlElement *multidomains = domain->FirstChildElement(
"D");
946 int nextDomainNumber = 0;
950 int err = multidomains->QueryIntAttribute(
"ID", &indx);
952 "Unable to read attribute ID in Domain.");
954 TiXmlNode *elementChild = multidomains->FirstChild();
955 while (elementChild &&
956 elementChild->Type() != TiXmlNode::TINYXML_TEXT)
958 elementChild = elementChild->NextSibling();
961 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
962 std::string elementStr = elementChild->ToText()->ValueStr();
964 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
966 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
967 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
968 std::string indxStr =
969 elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
973 "Unable to read domain's composite index (index missing?).");
977 map<int, CompositeSharedPtr> unrollDomain;
978 GetCompositeList(indxStr, unrollDomain);
979 m_domain.push_back(unrollDomain);
981 ASSERTL0(!m_domain[nextDomainNumber++].empty(),
983 "Unable to obtain domain's referenced composite: ") +
988 multidomains = multidomains->NextSiblingElement(
"D");
995 TiXmlNode *elementChild = domain->FirstChild();
996 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
998 elementChild = elementChild->NextSibling();
1001 ASSERTL0(elementChild,
"Unable to read DOMAIN body.");
1002 std::string elementStr = elementChild->ToText()->ValueStr();
1004 elementStr = elementStr.substr(elementStr.find_first_not_of(
" "));
1006 std::string::size_type indxBeg = elementStr.find_first_of(
'[') + 1;
1007 std::string::size_type indxEnd = elementStr.find_last_of(
']') - 1;
1008 std::string indxStr = elementStr.substr(indxBeg, indxEnd - indxBeg + 1);
1011 "Unable to read domain's composite index (index missing?).");
1015 map<int, CompositeSharedPtr> fullDomain;
1016 GetCompositeList(indxStr, fullDomain);
1017 m_domain.push_back(fullDomain);
1020 !m_domain[0].empty(),
1021 (std::string(
"Unable to obtain domain's referenced composite: ") +
1027 void MeshGraphXml::ReadEdges()
1029 CurveMap::iterator it;
1032 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"EDGE");
1034 ASSERTL0(field,
"Unable to find EDGE tag in file.");
1039 TiXmlElement *edge = field->FirstChildElement(
"E");
1047 std::string edgeStr;
1052 int err = edge->QueryIntAttribute(
"ID", &indx);
1053 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
1055 TiXmlNode *child = edge->FirstChild();
1057 if (child->Type() == TiXmlNode::TINYXML_TEXT)
1059 edgeStr += child->ToText()->ValueStr();
1063 int vertex1, vertex2;
1064 std::istringstream edgeDataStrm(edgeStr.c_str());
1068 while (!edgeDataStrm.fail())
1070 edgeDataStrm >> vertex1 >> vertex2;
1077 if (!edgeDataStrm.fail())
1080 GetVertex(vertex2)};
1082 it = m_curvedEdges.find(indx);
1084 if (it == m_curvedEdges.end())
1087 indx, m_spaceDimension, vertices);
1092 indx, m_spaceDimension, vertices, it->second);
1095 m_segGeoms[indx] = edge;
1103 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
1106 edge = edge->NextSiblingElement(
"E");
1110 void MeshGraphXml::ReadFaces()
1113 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"FACE");
1115 ASSERTL0(field,
"Unable to find FACE tag in file.");
1121 TiXmlElement *element = field->FirstChildElement();
1122 CurveMap::iterator it;
1126 std::string elementType(element->ValueStr());
1128 ASSERTL0(elementType ==
"Q" || elementType ==
"T",
1129 (std::string(
"Unknown 3D face type: ") + elementType).c_str());
1133 int err = element->QueryIntAttribute(
"ID", &indx);
1134 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read face attribute ID.");
1137 it = m_curvedFaces.find(indx);
1140 TiXmlNode *elementChild = element->FirstChild();
1141 std::string elementStr;
1142 while (elementChild)
1144 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1146 elementStr += elementChild->ToText()->ValueStr();
1148 elementChild = elementChild->NextSibling();
1151 ASSERTL0(!elementStr.empty(),
"Unable to read face description body.");
1155 if (elementType ==
"T")
1158 int edge1, edge2, edge3;
1159 std::istringstream elementDataStrm(elementStr.c_str());
1163 elementDataStrm >> edge1;
1164 elementDataStrm >> edge2;
1165 elementDataStrm >> edge3;
1168 !elementDataStrm.fail(),
1169 (std::string(
"Unable to read face data for TRIANGLE: ") +
1175 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3)};
1179 if (it == m_curvedFaces.end())
1187 indx, edges, it->second);
1190 trigeom->SetGlobalID(indx);
1192 m_triGeoms[indx] = trigeom;
1198 (std::string(
"Unable to read face data for TRIANGLE: ") +
1203 else if (elementType ==
"Q")
1206 int edge1, edge2, edge3, edge4;
1207 std::istringstream elementDataStrm(elementStr.c_str());
1211 elementDataStrm >> edge1;
1212 elementDataStrm >> edge2;
1213 elementDataStrm >> edge3;
1214 elementDataStrm >> edge4;
1217 (std::string(
"Unable to read face data for QUAD: ") +
1223 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3),
1228 if (it == m_curvedFaces.end())
1236 indx, edges, it->second);
1238 quadgeom->SetGlobalID(indx);
1240 m_quadGeoms[indx] = quadgeom;
1245 (std::string(
"Unable to read face data for QUAD: ") +
1251 element = element->NextSiblingElement();
1255 void MeshGraphXml::ReadElements()
1257 switch (m_meshDimension)
1271 void MeshGraphXml::ReadElements1D()
1273 TiXmlElement *field = NULL;
1276 field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1278 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1283 TiXmlElement *segment = field->FirstChildElement(
"S");
1284 CurveMap::iterator it;
1289 int err = segment->QueryIntAttribute(
"ID", &indx);
1290 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1292 TiXmlNode *elementChild = segment->FirstChild();
1293 while (elementChild && elementChild->Type() != TiXmlNode::TINYXML_TEXT)
1295 elementChild = elementChild->NextSibling();
1298 ASSERTL0(elementChild,
"Unable to read element description body.");
1299 std::string elementStr = elementChild->ToText()->ValueStr();
1304 int vertex1, vertex2;
1305 std::istringstream elementDataStrm(elementStr.c_str());
1309 elementDataStrm >> vertex1;
1310 elementDataStrm >> vertex2;
1313 (std::string(
"Unable to read element data for SEGMENT: ") +
1318 GetVertex(vertex2)};
1320 it = m_curvedEdges.find(indx);
1322 if (it == m_curvedEdges.end())
1325 indx, m_spaceDimension, vertices);
1326 seg->SetGlobalID(indx);
1331 indx, m_spaceDimension, vertices, it->second);
1332 seg->SetGlobalID(indx);
1334 seg->SetGlobalID(indx);
1335 m_segGeoms[indx] = seg;
1340 (std::string(
"Unable to read element data for segment: ") +
1345 segment = segment->NextSiblingElement(
"S");
1349 void MeshGraphXml::ReadElements2D()
1352 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1354 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1357 CurveMap::iterator it;
1362 TiXmlElement *element = field->FirstChildElement();
1366 std::string elementType(element->ValueStr());
1369 elementType ==
"Q" || elementType ==
"T",
1370 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
1374 int err = element->QueryIntAttribute(
"ID", &indx);
1375 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1377 it = m_curvedFaces.find(indx);
1380 TiXmlNode *elementChild = element->FirstChild();
1381 std::string elementStr;
1382 while (elementChild)
1384 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1386 elementStr += elementChild->ToText()->ValueStr();
1388 elementChild = elementChild->NextSibling();
1392 "Unable to read element description body.");
1396 if (elementType ==
"T")
1399 int edge1, edge2, edge3;
1400 std::istringstream elementDataStrm(elementStr.c_str());
1404 elementDataStrm >> edge1;
1405 elementDataStrm >> edge2;
1406 elementDataStrm >> edge3;
1409 !elementDataStrm.fail(),
1410 (std::string(
"Unable to read element data for TRIANGLE: ") +
1416 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3)};
1419 if (it == m_curvedFaces.end())
1427 indx, edges, it->second);
1429 trigeom->SetGlobalID(indx);
1431 m_triGeoms[indx] = trigeom;
1437 (std::string(
"Unable to read element data for TRIANGLE: ") +
1442 else if (elementType ==
"Q")
1445 int edge1, edge2, edge3, edge4;
1446 std::istringstream elementDataStrm(elementStr.c_str());
1450 elementDataStrm >> edge1;
1451 elementDataStrm >> edge2;
1452 elementDataStrm >> edge3;
1453 elementDataStrm >> edge4;
1456 !elementDataStrm.fail(),
1457 (std::string(
"Unable to read element data for QUAD: ") +
1463 GetSegGeom(edge1), GetSegGeom(edge2), GetSegGeom(edge3),
1467 if (it == m_curvedFaces.end())
1475 indx, edges, it->second);
1477 quadgeom->SetGlobalID(indx);
1479 m_quadGeoms[indx] = quadgeom;
1485 (std::string(
"Unable to read element data for QUAD: ") +
1491 element = element->NextSiblingElement();
1495 void MeshGraphXml::ReadElements3D()
1498 TiXmlElement *field = m_xmlGeom->FirstChildElement(
"ELEMENT");
1500 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
1505 TiXmlElement *element = field->FirstChildElement();
1509 std::string elementType(element->ValueStr());
1513 elementType ==
"A" || elementType ==
"P" || elementType ==
"R" ||
1515 (std::string(
"Unknown 3D element type: ") + elementType).c_str());
1519 int err = element->QueryIntAttribute(
"ID", &indx);
1520 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
1523 TiXmlNode *elementChild = element->FirstChild();
1524 std::string elementStr;
1525 while (elementChild)
1527 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
1529 elementStr += elementChild->ToText()->ValueStr();
1531 elementChild = elementChild->NextSibling();
1535 "Unable to read element description body.");
1537 std::istringstream elementDataStrm(elementStr.c_str());
1543 if (elementType ==
"A")
1548 const int kNfaces = TetGeom::kNfaces;
1549 const int kNtfaces = TetGeom::kNtfaces;
1550 const int kNqfaces = TetGeom::kNqfaces;
1557 std::stringstream errorstring;
1558 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1559 <<
" triangle face(s), and " << kNqfaces
1560 <<
" quadrilateral face(s).";
1561 for (
int i = 0; i < kNfaces; i++)
1564 elementDataStrm >> faceID;
1570 std::stringstream errorstring;
1571 errorstring <<
"Element " << indx
1572 <<
" has invalid face: " << faceID;
1573 ASSERTL0(
false, errorstring.str().c_str());
1577 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1579 static_pointer_cast<TriGeom>(face);
1581 else if (face->GetShapeType() ==
1584 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1592 "Unable to read element data for TETRAHEDRON: ") +
1595 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1596 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1601 m_tetGeoms[indx] = tetgeom;
1602 PopulateFaceToElMap(tetgeom, kNfaces);
1608 "Unable to read element data for TETRAHEDRON: ") +
1614 else if (elementType ==
"P")
1619 const int kNfaces = PyrGeom::kNfaces;
1620 const int kNtfaces = PyrGeom::kNtfaces;
1621 const int kNqfaces = PyrGeom::kNqfaces;
1629 std::stringstream errorstring;
1630 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1631 <<
" triangle face(s), and " << kNqfaces
1632 <<
" quadrilateral face(s).";
1633 for (
int i = 0; i < kNfaces; i++)
1636 elementDataStrm >> faceID;
1642 std::stringstream errorstring;
1643 errorstring <<
"Element " << indx
1644 <<
" has invalid face: " << faceID;
1645 ASSERTL0(
false, errorstring.str().c_str());
1649 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1651 static_pointer_cast<TriGeom>(face);
1654 else if (face->GetShapeType() ==
1657 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1659 static_pointer_cast<QuadGeom>(face);
1667 !elementDataStrm.fail(),
1668 (std::string(
"Unable to read element data for PYRAMID: ") +
1671 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1672 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1677 m_pyrGeoms[indx] = pyrgeom;
1678 PopulateFaceToElMap(pyrgeom, kNfaces);
1684 (std::string(
"Unable to read element data for PYRAMID: ") +
1690 else if (elementType ==
"R")
1695 const int kNfaces = PrismGeom::kNfaces;
1696 const int kNtfaces = PrismGeom::kNtfaces;
1697 const int kNqfaces = PrismGeom::kNqfaces;
1705 std::stringstream errorstring;
1706 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1707 <<
" triangle face(s), and " << kNqfaces
1708 <<
" quadrilateral face(s).";
1710 for (
int i = 0; i < kNfaces; i++)
1713 elementDataStrm >> faceID;
1719 std::stringstream errorstring;
1720 errorstring <<
"Element " << indx
1721 <<
" has invalid face: " << faceID;
1722 ASSERTL0(
false, errorstring.str().c_str());
1726 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1728 std::static_pointer_cast<TriGeom>(face);
1731 else if (face->GetShapeType() ==
1734 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1736 std::static_pointer_cast<QuadGeom>(face);
1744 !elementDataStrm.fail(),
1745 (std::string(
"Unable to read element data for PRISM: ") +
1748 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1749 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1754 m_prismGeoms[indx] = prismgeom;
1755 PopulateFaceToElMap(prismgeom, kNfaces);
1761 (std::string(
"Unable to read element data for PRISM: ") +
1767 else if (elementType ==
"H")
1772 const int kNfaces = HexGeom::kNfaces;
1773 const int kNtfaces = HexGeom::kNtfaces;
1774 const int kNqfaces = HexGeom::kNqfaces;
1782 std::stringstream errorstring;
1783 errorstring <<
"Element " << indx <<
" must have " << kNtfaces
1784 <<
" triangle face(s), and " << kNqfaces
1785 <<
" quadrilateral face(s).";
1786 for (
int i = 0; i < kNfaces; i++)
1789 elementDataStrm >> faceID;
1795 std::stringstream errorstring;
1796 errorstring <<
"Element " << indx
1797 <<
" has invalid face: " << faceID;
1798 ASSERTL0(
false, errorstring.str().c_str());
1802 ASSERTL0(Ntfaces < kNtfaces, errorstring.str().c_str());
1806 else if (face->GetShapeType() ==
1809 ASSERTL0(Nqfaces < kNqfaces, errorstring.str().c_str());
1811 std::static_pointer_cast<QuadGeom>(face);
1819 "Unable to read element data for HEXAHEDRAL: ") +
1822 ASSERTL0(Ntfaces == kNtfaces, errorstring.str().c_str());
1823 ASSERTL0(Nqfaces == kNqfaces, errorstring.str().c_str());
1828 m_hexGeoms[indx] = hexgeom;
1829 PopulateFaceToElMap(hexgeom, kNfaces);
1835 "Unable to read element data for HEXAHEDRAL: ") +
1841 element = element->NextSiblingElement();
1845 void MeshGraphXml::ReadComposites()
1847 TiXmlElement *field = NULL;
1850 field = m_xmlGeom->FirstChildElement(
"COMPOSITE");
1852 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
1854 TiXmlElement *node = field->FirstChildElement(
"C");
1857 int nextCompositeNumber = -1;
1864 nextCompositeNumber++;
1867 int err = node->QueryIntAttribute(
"ID", &indx);
1868 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
1872 TiXmlNode *compositeChild = node->FirstChild();
1877 while (compositeChild &&
1878 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
1880 compositeChild = compositeChild->NextSibling();
1883 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
1884 std::string compositeStr = compositeChild->ToText()->ValueStr();
1888 std::istringstream compositeDataStrm(compositeStr.c_str());
1893 std::string prevCompositeElementStr;
1895 while (!compositeDataStrm.fail())
1897 std::string compositeElementStr;
1898 compositeDataStrm >> compositeElementStr;
1900 if (!compositeDataStrm.fail())
1908 m_meshComposites[indx] = curVector;
1911 if (compositeElementStr.length() > 0)
1913 ResolveGeomRef(prevCompositeElementStr,
1914 compositeElementStr,
1915 m_meshComposites[indx]);
1917 prevCompositeElementStr = compositeElementStr;
1925 (std::string(
"Unable to read COMPOSITE data for composite: ") +
1931 node = node->NextSiblingElement(
"C");
1935 "At least one composite must be specified.");
1938 void MeshGraphXml::ResolveGeomRef(
const std::string &prevToken,
1939 const std::string &token,
1942 switch (m_meshDimension)
1945 ResolveGeomRef1D(prevToken, token, composite);
1948 ResolveGeomRef2D(prevToken, token, composite);
1951 ResolveGeomRef3D(prevToken, token, composite);
1956 void MeshGraphXml::ResolveGeomRef1D(
const std::string &prevToken,
1957 const std::string &token,
1962 std::istringstream tokenStream(token);
1963 std::istringstream prevTokenStream(prevToken);
1968 tokenStream >> type;
1970 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
1971 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
1975 (std::string(
"Error reading index definition:") + token).c_str());
1977 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
1979 typedef vector<unsigned int> SeqVectorType;
1980 SeqVectorType seqVector;
1982 if (!ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector))
1985 (std::string(
"Ill-formed sequence definition: ") + indxStr)
1989 prevTokenStream >> prevType;
1992 bool validSequence =
1993 (prevToken.empty() ||
1994 (type ==
'V' && prevType ==
'V') ||
1995 (type ==
'S' && prevType ==
'S'));
1998 (std::string(
"Invalid combination of composite items: ") +
1999 type +
" and " + prevType +
".")
2005 for (SeqVectorType::iterator iter = seqVector.begin();
2006 iter != seqVector.end(); ++iter)
2008 if (m_vertSet.find(*iter) == m_vertSet.end())
2010 char errStr[16] =
"";
2011 ::sprintf(errStr,
"%d", *iter);
2013 ErrorUtil::ewarning,
2014 (std::string(
"Unknown vertex index: ") + errStr)
2019 composite->m_geomVec.push_back(m_vertSet[*iter]);
2025 for (SeqVectorType::iterator iter = seqVector.begin();
2026 iter != seqVector.end(); ++iter)
2028 if (m_segGeoms.find(*iter) == m_segGeoms.end())
2030 char errStr[16] =
"";
2031 ::sprintf(errStr,
"%d", *iter);
2033 ErrorUtil::ewarning,
2034 (std::string(
"Unknown segment index: ") + errStr)
2039 composite->m_geomVec.push_back(m_segGeoms[*iter]);
2046 (std::string(
"Unrecognized composite token: ") + token)
2053 (std::string(
"Problem processing composite token: ") + token)
2060 void MeshGraphXml::ResolveGeomRef2D(
const std::string &prevToken,
2061 const std::string &token,
2066 std::istringstream tokenStream(token);
2067 std::istringstream prevTokenStream(prevToken);
2072 tokenStream >> type;
2074 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2075 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2079 (std::string(
"Error reading index definition:") + token).c_str());
2081 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2082 std::vector<unsigned int> seqVector;
2083 std::vector<unsigned int>::iterator seqIter;
2085 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
2088 (std::string(
"Error reading composite elements: ") + indxStr)
2091 prevTokenStream >> prevType;
2094 bool validSequence =
2095 (prevToken.empty() ||
2096 (type ==
'V' && prevType ==
'V') ||
2097 (type ==
'E' && prevType ==
'E') ||
2098 ((type ==
'T' || type ==
'Q') &&
2099 (prevType ==
'T' || prevType ==
'Q')));
2102 (std::string(
"Invalid combination of composite items: ") +
2103 type +
" and " + prevType +
".")
2109 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2112 if (m_segGeoms.find(*seqIter) == m_segGeoms.end())
2114 char errStr[16] =
"";
2115 ::sprintf(errStr,
"%d", *seqIter);
2117 (std::string(
"Unknown edge index: ") + errStr)
2122 composite->m_geomVec.push_back(m_segGeoms[*seqIter]);
2129 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2132 if (m_triGeoms.count(*seqIter) == 0)
2134 char errStr[16] =
"";
2135 ::sprintf(errStr,
"%d", *seqIter);
2137 ErrorUtil::ewarning,
2138 (std::string(
"Unknown triangle index: ") + errStr)
2143 if (CheckRange(*m_triGeoms[*seqIter]))
2145 composite->m_geomVec.push_back(
2146 m_triGeoms[*seqIter]);
2155 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2158 if (m_quadGeoms.count(*seqIter) == 0)
2160 char errStr[16] =
"";
2161 ::sprintf(errStr,
"%d", *seqIter);
2163 (std::string(
"Unknown quad index: ") + errStr +
2164 std::string(
" in Composite section"))
2169 if (CheckRange(*m_quadGeoms[*seqIter]))
2171 composite->m_geomVec.push_back(
2172 m_quadGeoms[*seqIter]);
2180 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2183 if (*seqIter >= m_vertSet.size())
2185 char errStr[16] =
"";
2186 ::sprintf(errStr,
"%d", *seqIter);
2188 ErrorUtil::ewarning,
2189 (std::string(
"Unknown vertex index: ") + errStr)
2194 composite->m_geomVec.push_back(m_vertSet[*seqIter]);
2201 (std::string(
"Unrecognized composite token: ") + token)
2208 (std::string(
"Problem processing composite token: ") + token)
2215 void MeshGraphXml::ResolveGeomRef3D(
const std::string &prevToken,
2216 const std::string &token,
2221 std::istringstream tokenStream(token);
2222 std::istringstream prevTokenStream(prevToken);
2227 tokenStream >> type;
2229 std::string::size_type indxBeg = token.find_first_of(
'[') + 1;
2230 std::string::size_type indxEnd = token.find_last_of(
']') - 1;
2234 (std::string(
"Error reading index definition:") + token).c_str());
2236 std::string indxStr = token.substr(indxBeg, indxEnd - indxBeg + 1);
2238 std::vector<unsigned int> seqVector;
2239 std::vector<unsigned int>::iterator seqIter;
2241 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
2244 (std::string(
"Error reading composite elements: ") + indxStr)
2247 prevTokenStream >> prevType;
2251 map<char, int> typeMap;
2262 bool validSequence =
2263 (prevToken.empty() || (typeMap[type] == typeMap[prevType]));
2266 (std::string(
"Invalid combination of composite items: ") +
2267 type +
" and " + prevType +
".")
2273 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2276 if (m_vertSet.find(*seqIter) == m_vertSet.end())
2278 char errStr[16] =
"";
2279 ::sprintf(errStr,
"%d", *seqIter);
2281 ErrorUtil::ewarning,
2282 (std::string(
"Unknown vertex index: ") + errStr)
2287 composite->m_geomVec.push_back(m_vertSet[*seqIter]);
2293 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2296 if (m_segGeoms.find(*seqIter) == m_segGeoms.end())
2298 char errStr[16] =
"";
2299 ::sprintf(errStr,
"%d", *seqIter);
2301 (std::string(
"Unknown edge index: ") + errStr)
2306 composite->m_geomVec.push_back(m_segGeoms[*seqIter]);
2312 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2318 char errStr[16] =
"";
2319 ::sprintf(errStr,
"%d", *seqIter);
2321 (std::string(
"Unknown face index: ") + errStr)
2326 if (CheckRange(*face))
2328 composite->m_geomVec.push_back(face);
2335 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2338 if (m_triGeoms.find(*seqIter) == m_triGeoms.end())
2340 char errStr[16] =
"";
2341 ::sprintf(errStr,
"%d", *seqIter);
2343 ErrorUtil::ewarning,
2344 (std::string(
"Unknown triangle index: ") + errStr)
2349 if (CheckRange(*m_triGeoms[*seqIter]))
2351 composite->m_geomVec.push_back(
2352 m_triGeoms[*seqIter]);
2359 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2362 if (m_quadGeoms.find(*seqIter) == m_quadGeoms.end())
2364 char errStr[16] =
"";
2365 ::sprintf(errStr,
"%d", *seqIter);
2367 (std::string(
"Unknown quad index: ") + errStr)
2372 if (CheckRange(*m_quadGeoms[*seqIter]))
2374 composite->m_geomVec.push_back(
2375 m_quadGeoms[*seqIter]);
2383 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2386 if (m_tetGeoms.find(*seqIter) == m_tetGeoms.end())
2388 char errStr[16] =
"";
2389 ::sprintf(errStr,
"%d", *seqIter);
2391 (std::string(
"Unknown tet index: ") + errStr)
2396 if (CheckRange(*m_tetGeoms[*seqIter]))
2398 composite->m_geomVec.push_back(
2399 m_tetGeoms[*seqIter]);
2407 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2410 if (m_pyrGeoms.find(*seqIter) == m_pyrGeoms.end())
2412 char errStr[16] =
"";
2413 ::sprintf(errStr,
"%d", *seqIter);
2415 ErrorUtil::ewarning,
2416 (std::string(
"Unknown pyramid index: ") + errStr)
2421 if (CheckRange(*m_pyrGeoms[*seqIter]))
2423 composite->m_geomVec.push_back(
2424 m_pyrGeoms[*seqIter]);
2432 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2435 if (m_prismGeoms.find(*seqIter) == m_prismGeoms.end())
2437 char errStr[16] =
"";
2438 ::sprintf(errStr,
"%d", *seqIter);
2440 (std::string(
"Unknown prism index: ") + errStr)
2445 if (CheckRange(*m_prismGeoms[*seqIter]))
2447 composite->m_geomVec.push_back(
2448 m_prismGeoms[*seqIter]);
2456 for (seqIter = seqVector.begin(); seqIter != seqVector.end();
2459 if (m_hexGeoms.find(*seqIter) == m_hexGeoms.end())
2461 char errStr[16] =
"";
2462 ::sprintf(errStr,
"%d", *seqIter);
2464 (std::string(
"Unknown hex index: ") + errStr)
2469 if (CheckRange(*m_hexGeoms[*seqIter]))
2471 composite->m_geomVec.push_back(
2472 m_hexGeoms[*seqIter]);
2480 (std::string(
"Unrecognized composite token: ") + token)
2487 (std::string(
"Problem processing composite token: ") + token)
2494 void MeshGraphXml::WriteVertices(TiXmlElement *geomTag,
PointGeomMap &verts)
2496 TiXmlElement *vertTag =
new TiXmlElement(
"VERTEX");
2498 for (
auto &i : verts)
2501 s << scientific << setprecision(8) << (*i.second)(0) <<
" "
2502 << (*i.second)(1) <<
" " << (*i.second)(2);
2503 TiXmlElement *v =
new TiXmlElement(
"V");
2504 v->SetAttribute(
"ID", i.second->GetGlobalID());
2505 v->LinkEndChild(
new TiXmlText(s.str()));
2506 vertTag->LinkEndChild(v);
2509 geomTag->LinkEndChild(vertTag);
2512 void MeshGraphXml::WriteEdges(TiXmlElement *geomTag,
SegGeomMap &edges)
2514 TiXmlElement *edgeTag =
2515 new TiXmlElement(m_meshDimension == 1 ?
"ELEMENT" :
"EDGE");
2516 string tag = m_meshDimension == 1 ?
"S" :
"E";
2518 for (
auto &i : edges)
2522 s << seg->GetVid(0) <<
" " << seg->GetVid(1);
2523 TiXmlElement *e =
new TiXmlElement(tag);
2524 e->SetAttribute(
"ID", i.first);
2525 e->LinkEndChild(
new TiXmlText(s.str()));
2526 edgeTag->LinkEndChild(e);
2529 geomTag->LinkEndChild(edgeTag);
2532 void MeshGraphXml::WriteTris(TiXmlElement *faceTag,
TriGeomMap &tris)
2536 for (
auto &i : tris)
2540 s << tri->GetEid(0) <<
" " << tri->GetEid(1) <<
" " << tri->GetEid(2);
2541 TiXmlElement *t =
new TiXmlElement(tag);
2542 t->SetAttribute(
"ID", i.first);
2543 t->LinkEndChild(
new TiXmlText(s.str()));
2544 faceTag->LinkEndChild(t);
2548 void MeshGraphXml::WriteQuads(TiXmlElement *faceTag,
QuadGeomMap &quads)
2552 for (
auto &i : quads)
2556 s << quad->GetEid(0) <<
" " << quad->GetEid(1) <<
" " << quad->GetEid(2)
2557 <<
" " << quad->GetEid(3);
2558 TiXmlElement *q =
new TiXmlElement(tag);
2559 q->SetAttribute(
"ID", i.first);
2560 q->LinkEndChild(
new TiXmlText(s.str()));
2561 faceTag->LinkEndChild(q);
2565 void MeshGraphXml::WriteHexs(TiXmlElement *elmtTag,
HexGeomMap &hexs)
2569 for (
auto &i : hexs)
2573 s << hex->GetFid(0) <<
" " << hex->GetFid(1) <<
" " << hex->GetFid(2)
2574 <<
" " << hex->GetFid(3) <<
" " << hex->GetFid(4) <<
" "
2575 << hex->GetFid(5) <<
" ";
2576 TiXmlElement *h =
new TiXmlElement(tag);
2577 h->SetAttribute(
"ID", i.first);
2578 h->LinkEndChild(
new TiXmlText(s.str()));
2579 elmtTag->LinkEndChild(h);
2587 for (
auto &i : pris)
2591 s << prism->GetFid(0) <<
" " << prism->GetFid(1) <<
" "
2592 << prism->GetFid(2) <<
" " << prism->GetFid(3) <<
" "
2593 << prism->GetFid(4) <<
" ";
2594 TiXmlElement *
p =
new TiXmlElement(tag);
2595 p->SetAttribute(
"ID", i.first);
2596 p->LinkEndChild(
new TiXmlText(s.str()));
2597 elmtTag->LinkEndChild(
p);
2601 void MeshGraphXml::WritePyrs(TiXmlElement *elmtTag,
PyrGeomMap &pyrs)
2605 for (
auto &i : pyrs)
2609 s << pyr->GetFid(0) <<
" " << pyr->GetFid(1) <<
" " << pyr->GetFid(2)
2610 <<
" " << pyr->GetFid(3) <<
" " << pyr->GetFid(4) <<
" ";
2611 TiXmlElement *
p =
new TiXmlElement(tag);
2612 p->SetAttribute(
"ID", i.first);
2613 p->LinkEndChild(
new TiXmlText(s.str()));
2614 elmtTag->LinkEndChild(
p);
2618 void MeshGraphXml::WriteTets(TiXmlElement *elmtTag,
TetGeomMap &tets)
2622 for (
auto &i : tets)
2626 s << tet->GetFid(0) <<
" " << tet->GetFid(1) <<
" " << tet->GetFid(2)
2627 <<
" " << tet->GetFid(3) <<
" ";
2628 TiXmlElement *t =
new TiXmlElement(tag);
2629 t->SetAttribute(
"ID", i.first);
2630 t->LinkEndChild(
new TiXmlText(s.str()));
2631 elmtTag->LinkEndChild(t);
2635 void MeshGraphXml::WriteCurves(TiXmlElement *geomTag,
CurveMap &edges,
2638 TiXmlElement *curveTag =
new TiXmlElement(
"CURVED");
2639 CurveMap::iterator curveIt;
2642 for (curveIt = edges.begin(); curveIt != edges.end(); ++curveIt)
2645 TiXmlElement *c =
new TiXmlElement(
"E");
2649 for (
int j = 0; j < curve->m_points.size(); ++j)
2652 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2656 c->SetAttribute(
"ID", curveId++);
2657 c->SetAttribute(
"EDGEID", curve->m_curveID);
2658 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2660 c->LinkEndChild(
new TiXmlText(s.str()));
2661 curveTag->LinkEndChild(c);
2664 for (curveIt = faces.begin(); curveIt != faces.end(); ++curveIt)
2667 TiXmlElement *c =
new TiXmlElement(
"F");
2671 for (
int j = 0; j < curve->m_points.size(); ++j)
2674 s << scientific << (*p)(0) <<
" " << (*
p)(1) <<
" " << (*
p)(2)
2678 c->SetAttribute(
"ID", curveId++);
2679 c->SetAttribute(
"FACEID", curve->m_curveID);
2680 c->SetAttribute(
"NUMPOINTS", curve->m_points.size());
2682 c->LinkEndChild(
new TiXmlText(s.str()));
2683 curveTag->LinkEndChild(c);
2686 geomTag->LinkEndChild(curveTag);
2689 void MeshGraphXml::WriteComposites(TiXmlElement *geomTag,
CompositeMap &comps)
2691 TiXmlElement *compTag =
new TiXmlElement(
"COMPOSITE");
2693 for (
auto &cIt : comps)
2695 if (cIt.second->m_geomVec.size() == 0)
2700 TiXmlElement *c =
new TiXmlElement(
"C");
2701 c->SetAttribute(
"ID", cIt.first);
2702 c->LinkEndChild(
new TiXmlText(GetCompositeString(cIt.second)));
2703 compTag->LinkEndChild(c);
2706 geomTag->LinkEndChild(compTag);
2709 void MeshGraphXml::WriteDomain(TiXmlElement *geomTag,
2710 vector<CompositeMap> &domain)
2712 TiXmlElement *domTag =
new TiXmlElement(
"DOMAIN");
2713 stringstream domString;
2716 vector<unsigned int> idxList;
2717 for (
auto cIt = domain[0].begin(); cIt != domain[0].end(); ++cIt)
2719 idxList.push_back(cIt->first);
2722 domString <<
" C[" << ParseUtils::GenerateSeqString(idxList) <<
"] ";
2723 domTag->LinkEndChild(
new TiXmlText(domString.str()));
2724 geomTag->LinkEndChild(domTag);
2727 void MeshGraphXml::WriteDefaultExpansion(TiXmlElement *root)
2729 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
2731 for (
auto it = m_meshComposites.begin(); it != m_meshComposites.end(); it++)
2733 if (it->second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
2735 TiXmlElement *exp =
new TiXmlElement(
"E");
2736 exp->SetAttribute(
"COMPOSITE",
2737 "C[" + boost::lexical_cast<string>(it->first) +
2739 exp->SetAttribute(
"NUMMODES", 4);
2740 exp->SetAttribute(
"TYPE",
"MODIFIED");
2741 exp->SetAttribute(
"FIELDS",
"u");
2743 expTag->LinkEndChild(exp);
2746 root->LinkEndChild(expTag);
2753 void MeshGraphXml::WriteGeometry(
2754 std::string &outfilename,
2760 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2761 doc.LinkEndChild(decl);
2763 TiXmlElement *root =
new TiXmlElement(
"NEKTAR");
2764 doc.LinkEndChild(root);
2765 TiXmlElement *geomTag =
new TiXmlElement(
"GEOMETRY");
2766 root->LinkEndChild(geomTag);
2769 LibUtilities::FieldIO::AddInfoTag(
2775 geomTag->SetAttribute(
"DIM", m_meshDimension);
2776 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
2782 WriteVertices(geomTag, m_vertSet);
2783 WriteEdges(geomTag, m_segGeoms);
2784 if (m_meshDimension > 1)
2786 TiXmlElement *faceTag =
2787 new TiXmlElement(m_meshDimension == 2 ?
"ELEMENT" :
"FACE");
2789 WriteTris(faceTag, m_triGeoms);
2790 WriteQuads(faceTag, m_quadGeoms);
2791 geomTag->LinkEndChild(faceTag);
2793 if (m_meshDimension > 2)
2795 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
2797 WriteHexs(elmtTag, m_hexGeoms);
2798 WritePyrs(elmtTag, m_pyrGeoms);
2799 WritePrisms(elmtTag, m_prismGeoms);
2800 WriteTets(elmtTag, m_tetGeoms);
2802 geomTag->LinkEndChild(elmtTag);
2804 WriteCurves(geomTag, m_curvedEdges, m_curvedFaces);
2805 WriteComposites(geomTag, m_meshComposites);
2806 WriteDomain(geomTag, m_domain);
2810 WriteDefaultExpansion(root);
2814 doc.SaveFile(outfilename);
2817 void MeshGraphXml::WriteXMLGeometry(std::string outname,
2818 vector<set<unsigned int>> elements,
2819 vector<unsigned int> partitions)
2830 string dirname = outname +
"_xml";
2831 boost::filesystem::path pdirname(dirname);
2833 if (!boost::filesystem::is_directory(dirname))
2835 boost::filesystem::create_directory(dirname);
2838 ASSERTL0(elements.size() == partitions.size(),
2839 "error in partitioned information");
2841 for (
int i = 0; i < partitions.size(); i++)
2844 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
2845 doc.LinkEndChild(decl);
2847 TiXmlElement *root = doc.FirstChildElement(
"NEKTAR");
2848 TiXmlElement *geomTag;
2853 root =
new TiXmlElement(
"NEKTAR");
2854 doc.LinkEndChild(root);
2856 geomTag =
new TiXmlElement(
"GEOMETRY");
2857 root->LinkEndChild(geomTag);
2862 geomTag = root->FirstChildElement(
"GEOMETRY");
2866 geomTag =
new TiXmlElement(
"GEOMETRY");
2867 root->LinkEndChild(geomTag);
2871 geomTag->SetAttribute(
"DIM", m_meshDimension);
2872 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
2873 geomTag->SetAttribute(
"PARTITION", partitions[i]);
2888 vector<set<unsigned int>> entityIds(4);
2889 entityIds[m_meshDimension] = elements[i];
2891 switch (m_meshDimension)
2895 for (
auto &j : entityIds[3])
2898 if (m_hexGeoms.count(j))
2901 localHex[j] = m_hexGeoms[j];
2903 else if (m_pyrGeoms.count(j))
2906 localPyr[j] = m_pyrGeoms[j];
2908 else if (m_prismGeoms.count(j))
2910 g = m_prismGeoms[j];
2911 localPrism[j] = m_prismGeoms[j];
2913 else if (m_tetGeoms.count(j))
2916 localTet[j] = m_tetGeoms[j];
2920 ASSERTL0(
false,
"element in partition not found");
2923 for (
int k = 0; k < g->GetNumFaces(); k++)
2925 entityIds[2].insert(g->GetFid(k));
2927 for (
int k = 0; k < g->GetNumEdges(); k++)
2929 entityIds[1].insert(g->GetEid(k));
2931 for (
int k = 0; k < g->GetNumVerts(); k++)
2933 entityIds[0].insert(g->GetVid(k));
2940 for (
auto &j : entityIds[2])
2943 if (m_triGeoms.count(j))
2946 localTri[j] = m_triGeoms[j];
2948 else if (m_quadGeoms.count(j))
2951 localQuad[j] = m_quadGeoms[j];
2955 ASSERTL0(
false,
"element in partition not found");
2958 for (
int k = 0; k < g->GetNumEdges(); k++)
2960 entityIds[1].insert(g->GetEid(k));
2962 for (
int k = 0; k < g->GetNumVerts(); k++)
2964 entityIds[0].insert(g->GetVid(k));
2971 for (
auto &j : entityIds[1])
2974 if (m_segGeoms.count(j))
2977 localEdge[j] = m_segGeoms[j];
2981 ASSERTL0(
false,
"element in partition not found");
2984 for (
int k = 0; k < g->GetNumVerts(); k++)
2986 entityIds[0].insert(g->GetVid(k));
2992 if (m_meshDimension > 2)
2994 for (
auto &j : entityIds[2])
2996 if (m_triGeoms.count(j))
2998 localTri[j] = m_triGeoms[j];
3000 else if (m_quadGeoms.count(j))
3002 localQuad[j] = m_quadGeoms[j];
3011 if (m_meshDimension > 1)
3013 for (
auto &j : entityIds[1])
3015 if (m_segGeoms.count(j))
3017 localEdge[j] = m_segGeoms[j];
3026 for (
auto &j : entityIds[0])
3028 if (m_vertSet.count(j))
3030 localVert[j] = m_vertSet[j];
3038 WriteVertices(geomTag, localVert);
3039 WriteEdges(geomTag, localEdge);
3040 if (m_meshDimension > 1)
3042 TiXmlElement *faceTag =
3043 new TiXmlElement(m_meshDimension == 2 ?
"ELEMENT" :
"FACE");
3045 WriteTris(faceTag, localTri);
3046 WriteQuads(faceTag, localQuad);
3047 geomTag->LinkEndChild(faceTag);
3049 if (m_meshDimension > 2)
3051 TiXmlElement *elmtTag =
new TiXmlElement(
"ELEMENT");
3053 WriteHexs(elmtTag, localHex);
3054 WritePyrs(elmtTag, localPyr);
3055 WritePrisms(elmtTag, localPrism);
3056 WriteTets(elmtTag, localTet);
3058 geomTag->LinkEndChild(elmtTag);
3061 for (
auto &j : localTri)
3063 if (m_curvedFaces.count(j.first))
3065 localCurveFace[j.first] = m_curvedFaces[j.first];
3068 for (
auto &j : localQuad)
3070 if (m_curvedFaces.count(j.first))
3072 localCurveFace[j.first] = m_curvedFaces[j.first];
3075 for (
auto &j : localEdge)
3077 if (m_curvedEdges.count(j.first))
3079 localCurveEdge[j.first] = m_curvedEdges[j.first];
3083 WriteCurves(geomTag, localCurveEdge, localCurveFace);
3087 for (
auto &j : m_meshComposites)
3090 int dim = j.second->m_geomVec[0]->GetShapeDim();
3092 for (
int k = 0; k < j.second->m_geomVec.size(); k++)
3094 if (entityIds[dim].count(j.second->m_geomVec[k]->GetGlobalID()))
3096 comp->m_geomVec.push_back(j.second->m_geomVec[k]);
3100 if (comp->m_geomVec.size())
3102 localComp[j.first] = comp;
3106 WriteComposites(geomTag, localComp);
3108 vector<CompositeMap> domain;
3110 for (
auto &j : localComp)
3112 if (j.second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
3114 domMap[j.first] = j.second;
3117 domain.push_back(domMap);
3119 WriteDomain(geomTag, domain);
3121 if (m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
3123 std::set<int> vBndRegionIdList;
3124 TiXmlElement *vConditions =
3125 new TiXmlElement(*m_session->GetElement(
"Nektar/Conditions"));
3126 TiXmlElement *vBndRegions =
3127 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
3128 TiXmlElement *vBndConditions =
3129 vConditions->FirstChildElement(
"BOUNDARYCONDITIONS");
3130 TiXmlElement *vItem;
3134 TiXmlElement *vNewBndRegions =
3135 new TiXmlElement(
"BOUNDARYREGIONS");
3136 vItem = vBndRegions->FirstChildElement();
3139 std::string vSeqStr =
3140 vItem->FirstChild()->ToText()->Value();
3141 std::string::size_type indxBeg =
3142 vSeqStr.find_first_of(
'[') + 1;
3143 std::string::size_type indxEnd =
3144 vSeqStr.find_last_of(
']') - 1;
3145 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
3146 std::vector<unsigned int> vSeq;
3147 ParseUtils::GenerateSeqVector(vSeqStr.c_str(), vSeq);
3149 vector<unsigned int> idxList;
3151 for (
unsigned int i = 0; i < vSeq.size(); ++i)
3153 if (localComp.find(vSeq[i]) != localComp.end())
3155 idxList.push_back(vSeq[i]);
3158 int p = atoi(vItem->Attribute(
"ID"));
3160 std::string vListStr =
3161 ParseUtils::GenerateSeqString(idxList);
3163 if (vListStr.length() == 0)
3165 TiXmlElement *tmp = vItem;
3166 vItem = vItem->NextSiblingElement();
3167 vBndRegions->RemoveChild(tmp);
3171 vListStr =
"C[" + vListStr +
"]";
3172 TiXmlText *vList =
new TiXmlText(vListStr);
3173 TiXmlElement *vNewElement =
new TiXmlElement(
"B");
3174 vNewElement->SetAttribute(
"ID",
p);
3175 vNewElement->LinkEndChild(vList);
3176 vNewBndRegions->LinkEndChild(vNewElement);
3177 vBndRegionIdList.insert(
p);
3178 vItem = vItem->NextSiblingElement();
3182 m_bndRegOrder[
p] = vSeq;
3184 vConditions->ReplaceChild(vBndRegions, *vNewBndRegions);
3189 vItem = vBndConditions->FirstChildElement();
3192 std::set<int>::iterator x;
3193 if ((x = vBndRegionIdList.find(atoi(vItem->Attribute(
3194 "REF")))) != vBndRegionIdList.end())
3196 vItem->SetAttribute(
"REF", *x);
3197 vItem = vItem->NextSiblingElement();
3201 TiXmlElement *tmp = vItem;
3202 vItem = vItem->NextSiblingElement();
3203 vBndConditions->RemoveChild(tmp);
3207 root->LinkEndChild(vConditions);
3211 TiXmlElement *vSrc =
3212 m_session->GetElement(
"Nektar")->FirstChildElement();
3215 std::string vName = boost::to_upper_copy(vSrc->ValueStr());
3216 if (vName !=
"GEOMETRY" && vName !=
"CONDITIONS")
3218 root->LinkEndChild(
new TiXmlElement(*vSrc));
3220 vSrc = vSrc->NextSiblingElement();
3226 pad % partitions[i];
3227 boost::filesystem::path pFilename(pad.str());
3229 boost::filesystem::path fullpath = pdirname / pFilename;
3238 for (
auto &c : m_meshComposites)
3240 std::vector<unsigned int> ids;
3241 for (
auto &elmt : c.second->m_geomVec)
3243 ids.push_back(elmt->GetGlobalID());
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Interpreter class for the evaluation of mathematical expressions.
int DefineFunction(const std::string &vlist, const std::string &expr)
Defines a function for the purposes of evaluation.
NekDouble Evaluate(const int id)
Evaluate a function which depends only on constants and/or parameters.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::map< std::string, std::string > FieldMetaDataMap
const std::string kPointsTypeStr[]
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< XmlTagWriter > XmlTagWriterSharedPtr
@ 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< DomainRange > DomainRangeShPtr
std::map< int, SegGeomSharedPtr > SegGeomMap
std::shared_ptr< Curve > CurveSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
std::map< int, CompositeSharedPtr > CompositeMap
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::map< int, TetGeomSharedPtr > TetGeomMap
std::shared_ptr< PyrGeom > PyrGeomSharedPtr
std::shared_ptr< TetGeom > TetGeomSharedPtr
static DomainRangeShPtr NullDomainRangeShPtr
std::map< int, PrismGeomSharedPtr > PrismGeomMap
std::shared_ptr< HexGeom > HexGeomSharedPtr
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::shared_ptr< Geometry > GeometrySharedPtr
std::shared_ptr< TriGeom > TriGeomSharedPtr
MeshGraphFactory & GetMeshGraphFactory()
std::shared_ptr< Composite > CompositeSharedPtr
std::map< int, HexGeomSharedPtr > HexGeomMap
std::map< int, PointGeomSharedPtr > PointGeomMap
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)