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");
74 LibUtilities::SessionReader::CreateInstance(argc - 1, argv);
79 string meshfile(argv[argc - 2]);
81 SpatialDomains::MeshGraphIO::Read(vSession);
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)
89 std::dynamic_pointer_cast<SpatialDomains::Geometry1D>(
90 composite->m_geomVec[i]);
92 std::dynamic_pointer_cast<SpatialDomains::Geometry1D>(
93 composite->m_geomVec[compsize - 1 - i]);
94 jointEdges[tmp1->GetGlobalID()] = tmp2->GetGlobalID();
95 jointVerts[tmp1->GetVid(0)] = tmp2->GetVid(1);
96 jointVerts[tmp1->GetVid(1)] = tmp2->GetVid(0);
100 TiXmlDocument &meshdoc = vSession->GetDocument();
102 TiXmlHandle docHandle(&meshdoc);
103 TiXmlElement *mesh = docHandle.FirstChildElement(
"NEKTAR")
104 .FirstChildElement(
"GEOMETRY")
118 meshdoc.SaveFile(argv[argc - 1]);
122 map<int, int> &newVerts)
125 TiXmlElement *element = mesh->FirstChildElement(
"VERTEX");
126 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
128 TiXmlElement *vertex = element->FirstChildElement(
"V");
133 vector<NekDouble> xpts, ypts, zpts;
139 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
140 std::string attrName(vertexAttr->Name());
143 (std::string(
"Unknown attribute name: ") + attrName).c_str());
145 err = vertexAttr->QueryIntValue(&indx);
146 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
149 std::string vertexBodyStr;
151 TiXmlNode *vertexBody = vertex->FirstChild();
156 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
158 vertexBodyStr += vertexBody->ToText()->Value();
159 vertexBodyStr +=
" ";
162 vertexBody = vertexBody->NextSibling();
166 "Vertex definitions must contain vertex data.");
169 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
173 while (!vertexDataStrm.fail())
175 vertexDataStrm >> xval >> yval >> zval;
177 xpts.push_back(xval);
178 ypts.push_back(yval + yoffset);
179 zpts.push_back(zval);
183 ASSERTL0(
false,
"Unable to read VERTEX data.");
185 vertex = vertex->NextSiblingElement(
"V");
189 int npts = xpts.size();
194 for (
int i = 0; i < npts; ++i)
196 if (jointVerts.count(i) == 0)
199 xval = xmax - xpts[i];
201 s << scientific << setprecision(8) << xval <<
" " << yval <<
" "
203 TiXmlElement *v =
new TiXmlElement(
"V");
204 v->SetAttribute(
"ID", cnt1);
205 v->LinkEndChild(
new TiXmlText(s.str()));
206 element->LinkEndChild(v);
207 newVerts[cnt++] = cnt1++;
211 newVerts[cnt++] = jointVerts[i];
217 map<int, int> jointEdges, map<int, int> &newEdges)
220 TiXmlElement *
field = mesh->FirstChildElement(
"EDGE");
227 TiXmlElement *edge =
field->FirstChildElement(
"E");
238 map<int, int> edgeVert0, edgeVert1;
241 int err = edge->QueryIntAttribute(
"ID", &indx);
242 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
244 TiXmlNode *child = edge->FirstChild();
246 if (child->Type() == TiXmlNode::TINYXML_TEXT)
248 edgeStr += child->ToText()->ValueStr();
252 int vertex1, vertex2;
253 std::istringstream edgeDataStrm(edgeStr.c_str());
257 while (!edgeDataStrm.fail())
259 edgeDataStrm >> vertex1 >> vertex2;
261 edgeVert0[indx] = vertex1;
262 edgeVert1[indx] = vertex2;
268 (std::string(
"Unable to read edge data: ") + edgeStr).c_str());
270 edge = edge->NextSiblingElement(
"E");
273 int nedges = edgeVert0.size();
276 int norigverts = newVerts.size();
278 for (
int i = 0; i < nedges; ++i)
280 if (jointEdges.count(i) == 0)
284 s << setw(5) << newVerts[edgeVert0[i] + norigverts] <<
" "
285 << newVerts[edgeVert1[i] + norigverts] <<
" ";
286 TiXmlElement *e =
new TiXmlElement(
"E");
287 e->SetAttribute(
"ID", cnt1);
288 e->LinkEndChild(
new TiXmlText(s.str()));
289 field->LinkEndChild(e);
290 newEdges[cnt++] = cnt1++;
294 newEdges[cnt++] = jointEdges[i];
299void ExpandElmts(TiXmlElement *mesh, map<int, int> &newEdges,
int &nelmts)
302 TiXmlElement *
field = mesh->FirstChildElement(
"ELEMENT");
309 TiXmlElement *element =
field->FirstChildElement();
311 map<int, vector<int>> ElmtEdges;
315 std::string elementType(element->ValueStr());
318 elementType ==
"Q" || elementType ==
"T",
319 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
323 int err = element->QueryIntAttribute(
"ID", &indx);
324 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
327 TiXmlNode *elementChild = element->FirstChild();
328 std::string elementStr;
331 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
333 elementStr += elementChild->ToText()->ValueStr();
335 elementChild = elementChild->NextSibling();
339 "Unable to read element description body.");
342 if (elementType ==
"T")
345 int edge1, edge2, edge3;
346 std::istringstream elementDataStrm(elementStr.c_str());
350 elementDataStrm >> edge1;
351 elementDataStrm >> edge2;
352 elementDataStrm >> edge3;
355 !elementDataStrm.fail(),
356 (std::string(
"Unable to read element data for TRIANGLE: ") +
361 edges.push_back(edge1);
362 edges.push_back(edge2);
363 edges.push_back(edge3);
365 ElmtEdges[indx] = edges;
371 (std::string(
"Unable to read element data for TRIANGLE: ") +
376 else if (elementType ==
"Q")
379 int edge1, edge2, edge3, edge4;
380 std::istringstream elementDataStrm(elementStr.c_str());
384 elementDataStrm >> edge1;
385 elementDataStrm >> edge2;
386 elementDataStrm >> edge3;
387 elementDataStrm >> edge4;
390 !elementDataStrm.fail(),
391 (std::string(
"Unable to read element data for QUAD: ") +
396 edges.push_back(edge1);
397 edges.push_back(edge2);
398 edges.push_back(edge3);
399 edges.push_back(edge4);
401 ElmtEdges[indx] = edges;
407 (std::string(
"Unable to read element data for QUAD: ") +
414 element = element->NextSiblingElement();
417 nelmts = ElmtEdges.size();
418 int nedges = newEdges.size();
420 for (
int i = 0; i < ElmtEdges.size(); ++i)
424 for (
int j = 0; j < ElmtEdges[i].size(); ++j)
426 s << setw(10) << newEdges[ElmtEdges[i][j] + nedges];
430 switch (ElmtEdges[i].size())
433 f =
new TiXmlElement(
"T");
436 f =
new TiXmlElement(
"Q");
441 f->SetAttribute(
"ID", i + nelmts);
442 f->LinkEndChild(
new TiXmlText(s.str()));
443 field->LinkEndChild(f);
455 st <<
" " << tag <<
"[" << vId;
457 for (
auto it = ids.begin() + 1; it != ids.end(); ++it)
464 if (prevId > -1 && vId == prevId + 1)
468 if (*it == ids.back())
493 TiXmlElement *
field = mesh->FirstChildElement(
"COMPOSITE");
498 TiXmlElement *composite =
field->FirstChildElement(
"C");
503 int err = composite->QueryIntAttribute(
"ID", &indx);
504 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
506 TiXmlNode *compositeChild = composite->FirstChild();
511 while (compositeChild &&
512 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
514 compositeChild = compositeChild->NextSibling();
517 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
518 std::string compositeStr = compositeChild->ToText()->ValueStr();
521 std::istringstream compositeDataStrm(compositeStr.c_str());
526 std::string compositeElementStr;
527 compositeDataStrm >> compositeElementStr;
529 std::istringstream tokenStream(compositeElementStr);
535 std::string::size_type indxBeg =
536 compositeElementStr.find_first_of(
'[') + 1;
537 std::string::size_type indxEnd =
538 compositeElementStr.find_last_of(
']') - 1;
541 (std::string(
"Error reading index definition:") +
545 std::string indxStr =
546 compositeElementStr.substr(indxBeg, indxEnd - indxBeg + 1);
547 std::vector<unsigned int> seqVector;
549 bool err = ParseUtils::GenerateSeqVector(indxStr, seqVector);
551 ASSERTL0(err, (std::string(
"Error reading composite elements: ") +
559 int seqlen = seqVector.size();
560 int nedges = newEdges.size();
562 map<unsigned int, unsigned int> seqMap;
564 for (
int i = 0; i < seqlen;
567 seqMap[seqVector[i]] = 1;
571 for (
int i = 0; i < seqlen; ++i)
573 if (seqMap.count(newEdges[seqVector[i] + nedges]) == 0)
576 newEdges[seqVector[i] + nedges]);
585 int seqlen = seqVector.size();
587 for (
int i = 0; i < seqlen; ++i)
589 seqVector.push_back(seqVector[i] + nOrigElmts);
596 (std::string(
"Unrecognized composite token: ") +
603 composite->ReplaceChild(compositeChild,
610 (std::string(
"Unable to read COMPOSITE data for composite: ") +
616 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)
int main(int argc, char *argv[])
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)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Composite > CompositeSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< Geometry1D > Geometry1DSharedPtr
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.