49 using namespace Nektar;
51 void ExpandVertices(TiXmlElement* mesh, map<int,int> jointVerts, map<int,int> &fullVerts);
53 void ExpandEdges(TiXmlElement* mesh, map<int,int> &newVerts,
54 map<int,int> jointEdges, map<int,int> &newEdges);
56 void ExpandElmts(TiXmlElement* mesh, map<int,int> &newEdges,
int &nOrigElmts);
58 void ExpandComposites(TiXmlElement* mesh, map<int,int> fullEdges,
int nOrigElmts);
60 int main(
int argc,
char *argv[])
66 fprintf(stderr,
"Usage: ./ExpandMeshByRotation meshfile outfile\n");
73 = LibUtilities::SessionReader::CreateInstance(argc-1, argv);
78 string meshfile(argv[argc-2]);
81 composite = graphShPt->GetComposite(300);
82 std::map<int,int> jointEdges, jointVerts, newVerts, newEdges;
83 int compsize = composite->size();
84 for(i = 0; i < compsize; ++i)
88 jointEdges[tmp1->GetEid() ] = tmp2->GetEid();
89 jointVerts[tmp1->GetVid(0)] = tmp2->GetVid(1);
90 jointVerts[tmp1->GetVid(1)] = tmp2->GetVid(0);
95 TiXmlDocument& meshdoc = vSession->GetDocument();
97 TiXmlHandle docHandle(&meshdoc);
98 TiXmlElement* mesh = docHandle.FirstChildElement(
"NEKTAR").FirstChildElement(
"GEOMETRY").Element();
111 meshdoc.SaveFile(argv[argc-1]);
115 void ExpandVertices(TiXmlElement* mesh, map<int,int> jointVerts, map<int,int> &newVerts)
118 TiXmlElement* element = mesh->FirstChildElement(
"VERTEX");
119 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
121 TiXmlElement *vertex = element->FirstChildElement(
"V");
124 int nextVertexNumber = -1;
127 vector<NekDouble> xpts,ypts,zpts;
135 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
136 std::string attrName(vertexAttr->Name());
138 ASSERTL0(attrName ==
"ID", (std::string(
"Unknown attribute name: ") + attrName).c_str());
140 err = vertexAttr->QueryIntValue(&indx);
141 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
144 std::string vertexBodyStr;
146 TiXmlNode *vertexBody = vertex->FirstChild();
151 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
153 vertexBodyStr += vertexBody->ToText()->Value();
154 vertexBodyStr +=
" ";
157 vertexBody = vertexBody->NextSibling();
160 ASSERTL0(!vertexBodyStr.empty(),
"Vertex definitions must contain vertex data.");
163 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
167 while(!vertexDataStrm.fail())
169 vertexDataStrm >> xval >> yval >> zval;
171 xpts.push_back(xval);
172 ypts.push_back(yval +yoffset);
173 zpts.push_back(zval);
177 ASSERTL0(
false,
"Unable to read VERTEX data.");
179 vertex = vertex->NextSiblingElement(
"V");
183 int npts = xpts.size();
188 for(
int i = 0; i <
npts; ++i)
190 if(jointVerts.count(i) == 0)
193 xval = xmax - xpts[i];
195 s << scientific << setprecision(8)
196 << xval <<
" " << yval <<
" " << zpts[i];
197 TiXmlElement * v =
new TiXmlElement(
"V" );
198 v->SetAttribute(
"ID",cnt1);
199 v->LinkEndChild(
new TiXmlText(s.str()));
200 element->LinkEndChild(v);
201 newVerts[cnt++] = cnt1++;
205 newVerts[cnt++] = jointVerts[i];
210 void ExpandEdges(TiXmlElement* mesh, map<int,int> &newVerts, map<int,int> jointEdges, map<int,int> &newEdges)
213 TiXmlElement* field = mesh->FirstChildElement(
"EDGE");
215 ASSERTL0(field,
"Unable to find EDGE tag in file.");
220 TiXmlElement *edge = field->FirstChildElement(
"E");
230 int nextEdgeNumber = -1;
232 map<int,int> edgeVert0,edgeVert1;
237 int err = edge->QueryIntAttribute(
"ID",&indx);
238 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read edge attribute ID.");
240 TiXmlNode *child = edge->FirstChild();
242 if (child->Type() == TiXmlNode::TINYXML_TEXT)
244 edgeStr += child->ToText()->ValueStr();
248 int vertex1, vertex2;
249 std::istringstream edgeDataStrm(edgeStr.c_str());
253 while (!edgeDataStrm.fail())
255 edgeDataStrm >> vertex1 >> vertex2;
257 edgeVert0[indx] = vertex1;
258 edgeVert1[indx] = vertex2;
264 edge = edge->NextSiblingElement(
"E");
267 int nedges = edgeVert0.size();
270 int norigverts = newVerts.size();
272 for(
int i = 0; i < nedges; ++i)
274 if(jointEdges.count(i) == 0)
278 s << setw(5) << newVerts[edgeVert0[i]+norigverts] <<
" "
279 << newVerts[edgeVert1[i]+norigverts] <<
" ";
280 TiXmlElement * e =
new TiXmlElement(
"E" );
281 e->SetAttribute(
"ID",cnt1);
282 e->LinkEndChild(
new TiXmlText(s.str()) );
283 field->LinkEndChild(e);
284 newEdges[cnt++] = cnt1++;
288 newEdges[cnt++] = jointEdges[i];
293 void ExpandElmts(TiXmlElement* mesh, map<int,int> &newEdges,
int &nelmts)
296 TiXmlElement* field = mesh->FirstChildElement(
"ELEMENT");
298 ASSERTL0(field,
"Unable to find ELEMENT tag in file.");
300 int nextElementNumber = -1;
305 TiXmlElement *element = field->FirstChildElement();
307 map<int,vector<int> > ElmtEdges;
311 std::string elementType(element->ValueStr());
313 ASSERTL0(elementType ==
"Q" || elementType ==
"T",
314 (std::string(
"Unknown 2D element type: ") + elementType).c_str());
321 int err = element->QueryIntAttribute(
"ID", &indx);
322 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read element attribute ID.");
325 TiXmlNode* elementChild = element->FirstChild();
326 std::string elementStr;
329 if (elementChild->Type() == TiXmlNode::TINYXML_TEXT)
331 elementStr += elementChild->ToText()->ValueStr();
333 elementChild = elementChild->NextSibling();
336 ASSERTL0(!elementStr.empty(),
"Unable to read element description body.");
339 if (elementType ==
"T")
342 int edge1, edge2, edge3;
343 std::istringstream elementDataStrm(elementStr.c_str());
347 elementDataStrm >> edge1;
348 elementDataStrm >> edge2;
349 elementDataStrm >> edge3;
351 ASSERTL0(!elementDataStrm.fail(), (std::string(
"Unable to read element data for TRIANGLE: ") + elementStr).c_str());
354 edges.push_back(edge1);
355 edges.push_back(edge2);
356 edges.push_back(edge3);
358 ElmtEdges[indx] = edges;
365 else if (elementType ==
"Q")
368 int edge1, edge2, edge3, edge4;
369 std::istringstream elementDataStrm(elementStr.c_str());
373 elementDataStrm >> edge1;
374 elementDataStrm >> edge2;
375 elementDataStrm >> edge3;
376 elementDataStrm >> edge4;
378 ASSERTL0(!elementDataStrm.fail(), (std::string(
"Unable to read element data for QUAD: ") + elementStr).c_str());
381 edges.push_back(edge1);
382 edges.push_back(edge2);
383 edges.push_back(edge3);
384 edges.push_back(edge4);
386 ElmtEdges[indx] = edges;
396 element = element->NextSiblingElement();
399 nelmts = ElmtEdges.size();
400 int nedges = newEdges.size();
402 for(
int i = 0; i < ElmtEdges.size(); ++i)
406 for(
int j = 0; j < ElmtEdges[i].size() ; ++j)
408 s << setw(10) << newEdges[ElmtEdges[i][j]+nedges];
412 switch(ElmtEdges[i].size())
415 f =
new TiXmlElement(
"T");
418 f =
new TiXmlElement(
"Q");
423 f->SetAttribute(
"ID", i+nelmts);
424 f->LinkEndChild(
new TiXmlText(s.str()));
425 field->LinkEndChild(f);
438 st <<
" " << tag <<
"[" << vId;
440 for (it = ids.begin()+1; it != ids.end(); ++it){
446 if (prevId > -1 && vId == prevId + 1)
450 if (*it == ids.back())
475 TiXmlElement* field = mesh->FirstChildElement(
"COMPOSITE");
476 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
478 int nextCompositeNumber = -1;
482 TiXmlElement *composite = field->FirstChildElement(
"C");
486 nextCompositeNumber++;
489 int err = composite->QueryIntAttribute(
"ID", &indx);
490 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
492 TiXmlNode* compositeChild = composite->FirstChild();
497 while(compositeChild && compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
499 compositeChild = compositeChild->NextSibling();
502 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
503 std::string compositeStr = compositeChild->ToText()->ValueStr();
506 std::istringstream compositeDataStrm(compositeStr.c_str());
512 std::string compositeElementStr;
513 compositeDataStrm >> compositeElementStr;
515 std::istringstream tokenStream(compositeElementStr);
521 std::string::size_type indxBeg = compositeElementStr.find_first_of(
'[') + 1;
522 std::string::size_type indxEnd = compositeElementStr.find_last_of(
']') - 1;
524 ASSERTL0(indxBeg <= indxEnd, (std::string(
"Error reading index definition:") + compositeElementStr).c_str());
526 std::string indxStr = compositeElementStr.substr(indxBeg, indxEnd - indxBeg + 1);
527 std::vector<unsigned int> seqVector;
530 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
532 ASSERTL0(err, (std::string(
"Error reading composite elements: ") + indxStr).c_str());
538 int seqlen = seqVector.size();
539 int nedges = newEdges.size();
541 map<unsigned int, unsigned int> seqMap;
543 for(
int i =0; i < seqlen; ++i)
545 seqMap[seqVector[i]] = 1;
549 for(
int i =0; i < seqlen; ++i)
551 if(seqMap.count(newEdges[seqVector[i]+nedges]) == 0)
553 seqVector.push_back(newEdges[seqVector[i]+nedges]);
561 int seqlen = seqVector.size();
563 for(
int i = 0; i < seqlen; ++i)
565 seqVector.push_back(seqVector[i]+nOrigElmts);
577 composite->ReplaceChild(compositeChild, TiXmlText(
GetXmlString(type,seqVector)));
584 (std::string(
"Unable to read COMPOSITE data for composite: ") + compositeStr).c_str());
588 composite = composite->NextSiblingElement(
"C");