51 map<int, int> &fullVerts);
53void ExpandEdges(TiXmlElement *mesh, map<int, int> &newVerts,
54 map<int, int> jointEdges, map<int, int> &newEdges);
56void ExpandElmts(TiXmlElement *mesh, map<int, int> &newEdges,
int &nOrigElmts);
61int main(
int argc,
char *argv[])
67 fprintf(stderr,
"Usage: ./ExpandMeshByRotation meshfile outfile\n");
79 string meshfile(argv[argc - 2]);
83 composite = graphShPt->GetComposite(300);
84 std::map<int, int> jointEdges, jointVerts, newVerts, newEdges;
85 int compsize = composite->m_geomVec.size();
86 for (i = 0; i < compsize; ++i)
92 composite->m_geomVec[compsize - 1 - i]);
99 TiXmlDocument &meshdoc = vSession->GetDocument();
101 TiXmlHandle docHandle(&meshdoc);
102 TiXmlElement *mesh = docHandle.FirstChildElement(
"NEKTAR")
103 .FirstChildElement(
"GEOMETRY")
117 meshdoc.SaveFile(argv[argc - 1]);
121 map<int, int> &newVerts)
124 TiXmlElement *element = mesh->FirstChildElement(
"VERTEX");
125 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
127 TiXmlElement *vertex = element->FirstChildElement(
"V");
132 vector<NekDouble> xpts, ypts, zpts;
138 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
139 std::string attrName(vertexAttr->Name());
142 (std::string(
"Unknown attribute name: ") + attrName).c_str());
144 err = vertexAttr->QueryIntValue(&indx);
145 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
148 std::string vertexBodyStr;
150 TiXmlNode *vertexBody = vertex->FirstChild();
155 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
157 vertexBodyStr += vertexBody->ToText()->Value();
158 vertexBodyStr +=
" ";
161 vertexBody = vertexBody->NextSibling();
165 "Vertex definitions must contain vertex data.");
168 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
172 while (!vertexDataStrm.fail())
174 vertexDataStrm >> xval >> yval >> zval;
176 xpts.push_back(xval);
177 ypts.push_back(yval + yoffset);
178 zpts.push_back(zval);
182 ASSERTL0(
false,
"Unable to read VERTEX data.");
184 vertex = vertex->NextSiblingElement(
"V");
188 int npts = xpts.size();
193 for (
int i = 0; i < npts; ++i)
195 if (jointVerts.count(i) == 0)
198 xval = xmax - xpts[i];
200 s << scientific << setprecision(8) << xval <<
" " << yval <<
" "
202 TiXmlElement *v =
new TiXmlElement(
"V");
203 v->SetAttribute(
"ID", cnt1);
204 v->LinkEndChild(
new TiXmlText(s.str()));
205 element->LinkEndChild(v);
206 newVerts[cnt++] = cnt1++;
210 newVerts[cnt++] = jointVerts[i];
216 map<int, int> jointEdges, map<int, int> &newEdges)
219 TiXmlElement *field = mesh->FirstChildElement(
"EDGE");
221 ASSERTL0(field,
"Unable to find EDGE tag in file.");
226 TiXmlElement *edge = field->FirstChildElement(
"E");
237 map<int, int> edgeVert0, edgeVert1;
240 int err = edge->QueryIntAttribute(
"ID", &indx);
241 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
243 TiXmlNode *child = edge->FirstChild();
245 if (child->Type() == TiXmlNode::TINYXML_TEXT)
247 edgeStr += child->ToText()->ValueStr();
251 int vertex1, vertex2;
252 std::istringstream edgeDataStrm(edgeStr.c_str());
256 while (!edgeDataStrm.fail())
258 edgeDataStrm >> vertex1 >> vertex2;
260 edgeVert0[indx] = vertex1;
261 edgeVert1[indx] = vertex2;
267 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
269 edge = edge->NextSiblingElement(
"E");
272 int nedges = edgeVert0.size();
275 int norigverts = newVerts.size();
277 for (
int i = 0; i < nedges; ++i)
279 if (jointEdges.count(i) == 0)
283 s << setw(5) << newVerts[edgeVert0[i] + norigverts] <<
" "
284 << newVerts[edgeVert1[i] + norigverts] <<
" ";
285 TiXmlElement *e =
new TiXmlElement(
"E");
286 e->SetAttribute(
"ID", cnt1);
287 e->LinkEndChild(
new TiXmlText(s.str()));
288 field->LinkEndChild(e);
289 newEdges[cnt++] = cnt1++;
293 newEdges[cnt++] = jointEdges[i];
298void ExpandElmts(TiXmlElement *mesh, map<int, int> &newEdges,
int &nelmts)
301 TiXmlElement *field = mesh->FirstChildElement(
"ELEMENT");
303 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
308 TiXmlElement *element = field->FirstChildElement();
310 map<int, vector<int>> ElmtEdges;
314 std::string elementType(element->ValueStr());
317 elementType ==
"Q" || elementType ==
"T",
318 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
322 int err = element->QueryIntAttribute(
"ID", &indx);
323 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
326 TiXmlNode *elementChild = element->FirstChild();
327 std::string elementStr;
330 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
332 elementStr += elementChild->ToText()->ValueStr();
334 elementChild = elementChild->NextSibling();
338 "Unable to read element description body.");
341 if (elementType ==
"T")
344 int edge1, edge2, edge3;
345 std::istringstream elementDataStrm(elementStr.c_str());
349 elementDataStrm >> edge1;
350 elementDataStrm >> edge2;
351 elementDataStrm >> edge3;
354 !elementDataStrm.fail(),
355 (std::string(
"Unable to read element data for TRIANGLE: ") +
360 edges.push_back(edge1);
361 edges.push_back(edge2);
362 edges.push_back(edge3);
364 ElmtEdges[indx] = edges;
370 (std::string(
"Unable to read element data for TRIANGLE: ") +
375 else if (elementType ==
"Q")
378 int edge1, edge2, edge3, edge4;
379 std::istringstream elementDataStrm(elementStr.c_str());
383 elementDataStrm >> edge1;
384 elementDataStrm >> edge2;
385 elementDataStrm >> edge3;
386 elementDataStrm >> edge4;
389 !elementDataStrm.fail(),
390 (std::string(
"Unable to read element data for QUAD: ") +
395 edges.push_back(edge1);
396 edges.push_back(edge2);
397 edges.push_back(edge3);
398 edges.push_back(edge4);
400 ElmtEdges[indx] = edges;
406 (std::string(
"Unable to read element data for QUAD: ") +
413 element = element->NextSiblingElement();
416 nelmts = ElmtEdges.size();
417 int nedges = newEdges.size();
419 for (
int i = 0; i < ElmtEdges.size(); ++i)
423 for (
int j = 0; j < ElmtEdges[i].size(); ++j)
425 s << setw(10) << newEdges[ElmtEdges[i][j] + nedges];
429 switch (ElmtEdges[i].size())
432 f =
new TiXmlElement(
"T");
435 f =
new TiXmlElement(
"Q");
440 f->SetAttribute(
"ID", i + nelmts);
441 f->LinkEndChild(
new TiXmlText(s.str()));
442 field->LinkEndChild(f);
454 st <<
" " << tag <<
"[" << vId;
456 for (
auto it = ids.begin() + 1; it != ids.end(); ++it)
463 if (prevId > -1 && vId == prevId + 1)
467 if (*it == ids.back())
492 TiXmlElement *field = mesh->FirstChildElement(
"COMPOSITE");
493 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
497 TiXmlElement *composite = field->FirstChildElement(
"C");
502 int err = composite->QueryIntAttribute(
"ID", &indx);
503 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
505 TiXmlNode *compositeChild = composite->FirstChild();
510 while (compositeChild &&
511 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
513 compositeChild = compositeChild->NextSibling();
516 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
517 std::string compositeStr = compositeChild->ToText()->ValueStr();
520 std::istringstream compositeDataStrm(compositeStr.c_str());
525 std::string compositeElementStr;
526 compositeDataStrm >> compositeElementStr;
528 std::istringstream tokenStream(compositeElementStr);
534 std::string::size_type indxBeg =
535 compositeElementStr.find_first_of(
'[') + 1;
536 std::string::size_type indxEnd =
537 compositeElementStr.find_last_of(
']') - 1;
540 (std::string(
"Error reading index definition:") +
544 std::string indxStr =
545 compositeElementStr.substr(indxBeg, indxEnd - indxBeg + 1);
546 std::vector<unsigned int> seqVector;
550 ASSERTL0(err, (std::string(
"Error reading composite elements: ") +
558 int seqlen = seqVector.size();
559 int nedges = newEdges.size();
561 map<unsigned int, unsigned int> seqMap;
563 for (
int i = 0; i < seqlen;
566 seqMap[seqVector[i]] = 1;
570 for (
int i = 0; i < seqlen; ++i)
572 if (seqMap.count(newEdges[seqVector[i] + nedges]) == 0)
575 newEdges[seqVector[i] + nedges]);
584 int seqlen = seqVector.size();
586 for (
int i = 0; i < seqlen; ++i)
588 seqVector.push_back(seqVector[i] + nOrigElmts);
595 (std::string(
"Unrecognized composite token: ") +
602 composite->ReplaceChild(compositeChild,
609 (std::string(
"Unable to read COMPOSITE data for composite: ") +
615 composite = composite->NextSiblingElement(
"C");
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
void ExpandVertices(TiXmlElement *mesh, map< int, int > jointVerts, map< int, int > &fullVerts)
void ExpandComposites(TiXmlElement *mesh, map< int, int > fullEdges, int nOrigElmts)
void ExpandElmts(TiXmlElement *mesh, map< int, int > &newEdges, int &nOrigElmts)
void ExpandEdges(TiXmlElement *mesh, map< int, int > &newVerts, map< int, int > jointEdges, map< int, int > &newEdges)
string GetXmlString(char tag, vector< unsigned int > &ids)
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
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.
int GetVid(int i) const
Returns global id of vertex i of this object.
int GetGlobalID(void) const
Get the ID of this object.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Composite > CompositeSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.