40 #include <boost/iostreams/filtering_streambuf.hpp>
41 #include <boost/iostreams/copy.hpp>
42 #include <boost/iostreams/filter/gzip.hpp>
43 namespace io = boost::iostreams;
49 #include "../MeshElements.h"
59 "Writes a Nektar++ xml file.");
64 "Compress output file and append a .gz extension.");
66 "Attempt to load resulting mesh and create meshgraph.");
78 cout <<
"OutputNekpp: Writing file..." << endl;
82 TiXmlDeclaration* decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
83 doc.LinkEndChild( decl );
85 TiXmlElement * root =
new TiXmlElement(
"NEKTAR" );
86 doc.LinkEndChild( root );
89 TiXmlElement * geomTag =
new TiXmlElement(
"GEOMETRY" );
90 geomTag->SetAttribute(
"DIM",
m_mesh->m_expDim);
91 geomTag->SetAttribute(
"SPACE",
m_mesh->m_spaceDim);
92 root->LinkEndChild( geomTag );
105 string filename =
m_config[
"outfile"].as<
string>();
111 ofstream fout(filename.c_str(),
112 std::ios_base::out | std::ios_base::binary);
114 std::stringstream decompressed;
116 io::filtering_streambuf<io::output> out;
117 out.push(io::gzip_compressor());
119 io::copy(decompressed, out);
125 doc.SaveFile(filename);
132 vector<string> filenames(1);
133 filenames[0] = filename;
145 TiXmlElement* verTag =
new TiXmlElement(
"VERTEX" );
148 std::set<NodeSharedPtr> tmp(
149 m_mesh->m_vertexSet.begin(),
150 m_mesh->m_vertexSet.end());
152 for (it = tmp.begin(); it != tmp.end(); ++it)
156 s << scientific << setprecision(8)
157 << n->m_x <<
" " << n->m_y <<
" " << n->m_z;
158 TiXmlElement * v =
new TiXmlElement(
"V" );
159 v->SetAttribute(
"ID",n->m_id);
160 v->LinkEndChild(
new TiXmlText(s.str()));
161 verTag->LinkEndChild(v);
163 pRoot->LinkEndChild(verTag);
168 if (
m_mesh->m_expDim >= 2)
170 TiXmlElement* verTag =
new TiXmlElement(
"EDGE" );
172 std::set<EdgeSharedPtr> tmp(
m_mesh->m_edgeSet.begin(),
174 for (it = tmp.begin(); it != tmp.end(); ++it)
179 s << setw(5) << ed->m_n1->m_id <<
" " << ed->m_n2->m_id <<
" ";
180 TiXmlElement * e =
new TiXmlElement(
"E" );
181 e->SetAttribute(
"ID",ed->m_id);
182 e->LinkEndChild(
new TiXmlText(s.str()) );
183 verTag->LinkEndChild(e);
185 pRoot->LinkEndChild( verTag );
191 if (
m_mesh->m_expDim == 3)
193 TiXmlElement* verTag =
new TiXmlElement(
"FACE" );
195 std::set<FaceSharedPtr> tmp(
196 m_mesh->m_faceSet.begin(),
199 for (it = tmp.begin(); it != tmp.end(); ++it)
204 for (
int j = 0; j < fa->m_edgeList.size(); ++j)
206 s << setw(10) << fa->m_edgeList[j]->m_id;
209 switch(fa->m_vertexList.size())
212 f =
new TiXmlElement(
"T");
215 f =
new TiXmlElement(
"Q");
220 f->SetAttribute(
"ID", fa->m_id);
221 f->LinkEndChild(
new TiXmlText(s.str()));
222 verTag->LinkEndChild(f);
224 pRoot->LinkEndChild( verTag );
230 TiXmlElement* verTag =
new TiXmlElement(
"ELEMENT" );
231 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[
m_mesh->m_expDim];
233 for(
int i = 0; i < elmt.size(); ++i)
235 TiXmlElement *elm_tag =
new TiXmlElement(elmt[i]->GetTag());
236 elm_tag->SetAttribute(
"ID", elmt[i]->GetId());
237 elm_tag->LinkEndChild(
new TiXmlText(elmt[i]->
GetXmlString()));
238 verTag->LinkEndChild(elm_tag);
240 pRoot->LinkEndChild(verTag);
251 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
253 if ((*it)->m_edgeNodes.size() > 0)
260 else if (
m_mesh->m_expDim == 1)
262 for (
int i = 0; i <
m_mesh->m_element[1].size(); ++i)
264 if (
m_mesh->m_element[1][i]->GetVolumeNodes().size() > 0)
273 TiXmlElement * curved =
new TiXmlElement (
"CURVED" );
275 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
277 if ((*it)->m_edgeNodes.size() > 0)
279 TiXmlElement * e =
new TiXmlElement(
"E" );
280 e->SetAttribute(
"ID", edgecnt++);
281 e->SetAttribute(
"EDGEID", (*it)->m_id);
282 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
283 e->SetAttribute(
"TYPE",
285 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
287 curved->LinkEndChild(e);
301 if ((*it)->GetVolumeNodes().size() > 0)
303 TiXmlElement * e =
new TiXmlElement(
"E" );
304 e->SetAttribute(
"ID", facecnt++);
305 e->SetAttribute(
"EDGEID", (*it)->GetId());
306 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
307 e->SetAttribute(
"TYPE",
310 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
312 curved->LinkEndChild(e);
316 else if (
m_mesh->m_expDim == 2 &&
m_mesh->m_spaceDim == 3)
323 if ((*it)->GetVolumeNodes().size() > 0)
325 TiXmlElement * e =
new TiXmlElement(
"F" );
326 e->SetAttribute(
"ID", facecnt++);
327 e->SetAttribute(
"FACEID", (*it)->GetId());
328 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
329 e->SetAttribute(
"TYPE",
332 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
334 curved->LinkEndChild(e);
338 else if (
m_mesh->m_expDim == 3)
341 for (it2 =
m_mesh->m_faceSet.begin(); it2 !=
m_mesh->m_faceSet.end(); ++it2)
343 if ((*it2)->m_faceNodes.size() > 0)
345 TiXmlElement * f =
new TiXmlElement(
"F" );
346 f->SetAttribute(
"ID", facecnt++);
347 f->SetAttribute(
"FACEID", (*it2)->m_id);
348 f->SetAttribute(
"NUMPOINTS",(*it2)->GetNodeCount());
349 f->SetAttribute(
"TYPE",
351 TiXmlText * t0 =
new TiXmlText((*it2)->GetXmlCurveString());
353 curved->LinkEndChild(f);
358 pRoot->LinkEndChild( curved );
363 TiXmlElement* verTag =
new TiXmlElement(
"COMPOSITE");
368 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it, ++j)
370 if (it->second->m_items.size() > 0)
372 TiXmlElement *comp_tag =
new TiXmlElement(
"C");
376 for (it2 =
m_mesh->m_condition.begin();
377 it2 !=
m_mesh->m_condition.end(); ++it2)
388 for (
int i = 0; i < c->m_composite.size(); ++i)
390 if (c->m_composite[i] == j)
397 doSort = doSort && it->second->m_reorder;
398 comp_tag->SetAttribute(
"ID", it->second->m_id);
399 if(it->second->m_label.size())
401 comp_tag->SetAttribute(
"LABEL", it->second->m_label);
403 comp_tag->LinkEndChild(
404 new TiXmlText(it->second->GetXmlString(doSort)));
405 verTag->LinkEndChild(comp_tag);
409 cout <<
"Composite " << it->second->m_id <<
" "
410 <<
"contains nothing." << endl;
414 pRoot->LinkEndChild(verTag);
420 TiXmlElement * domain =
new TiXmlElement (
"DOMAIN" );
424 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
426 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
428 if (list.length() > 0)
432 list += boost::lexical_cast<std::string>(it->second->m_id);
435 domain->LinkEndChild(
new TiXmlText(
" C[" + list +
"] "));
436 pRoot->LinkEndChild( domain );
442 TiXmlElement * expansions =
new TiXmlElement (
"EXPANSIONS");
445 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
447 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
449 TiXmlElement * exp =
new TiXmlElement (
"E");
450 exp->SetAttribute(
"COMPOSITE",
"C["
451 + boost::lexical_cast<std::string>(it->second->m_id)
453 exp->SetAttribute(
"NUMMODES",4);
454 exp->SetAttribute(
"TYPE",
"MODIFIED");
456 if (
m_mesh->m_fields.size() == 0)
458 exp->SetAttribute(
"FIELDS",
"u");
463 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
465 fstr +=
m_mesh->m_fields[i]+
",";
467 fstr = fstr.substr(0,fstr.length()-1);
468 exp->SetAttribute(
"FIELDS", fstr);
471 expansions->LinkEndChild(exp);
474 pRoot->LinkEndChild(expansions);
479 TiXmlElement *conditions =
480 new TiXmlElement(
"CONDITIONS");
481 TiXmlElement *boundaryregions =
482 new TiXmlElement(
"BOUNDARYREGIONS");
483 TiXmlElement *boundaryconditions =
484 new TiXmlElement(
"BOUNDARYCONDITIONS");
485 TiXmlElement *variables =
486 new TiXmlElement(
"VARIABLES");
489 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end(); ++it)
495 TiXmlElement *b =
new TiXmlElement(
"B");
496 b->SetAttribute(
"ID", boost::lexical_cast<string>(it->first));
498 for (
int i = 0; i < c->m_composite.size(); ++i)
500 tmp += boost::lexical_cast<
string>(c->m_composite[i]) +
",";
503 tmp = tmp.substr(0, tmp.length()-1);
505 TiXmlText *t0 =
new TiXmlText(
"C["+tmp+
"]");
507 boundaryregions->LinkEndChild(b);
509 TiXmlElement *region =
new TiXmlElement(
"REGION");
510 region->SetAttribute(
511 "REF", boost::lexical_cast<string>(it->first));
513 for (
int i = 0; i < c->type.size(); ++i)
526 TiXmlElement *tag =
new TiXmlElement(tagId);
527 tag->SetAttribute(
"VAR", c->field[i]);
528 tag->SetAttribute(
"VALUE", c->value[i]);
532 tag->SetAttribute(
"USERDEFINEDTYPE",
"H");
535 region->LinkEndChild(tag);
538 boundaryconditions->LinkEndChild(region);
541 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
543 TiXmlElement *v =
new TiXmlElement(
"V");
544 v->SetAttribute(
"ID", boost::lexical_cast<std::string>(i));
545 TiXmlText *t0 =
new TiXmlText(
m_mesh->m_fields[i]);
547 variables->LinkEndChild(v);
550 if (
m_mesh->m_fields.size() > 0)
552 conditions->LinkEndChild(variables);
555 if (
m_mesh->m_condition.size() > 0)
557 conditions->LinkEndChild(boundaryregions);
558 conditions->LinkEndChild(boundaryconditions);
561 pRoot->LinkEndChild(conditions);
void WriteXmlCurves(TiXmlElement *pRoot)
Writes the section of the XML file if needed.
virtual void Process()
Write mesh to output file.
pair< ModuleType, string > ModuleKey
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
void WriteXmlFaces(TiXmlElement *pRoot)
Writes the section of the XML file if needed.
Abstract base class for output modules.
const std::string kPointsTypeStr[]
void WriteXmlNodes(TiXmlElement *pRoot)
Writes the section of the XML file.
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
map< string, ConfigOption > m_config
List of configuration values.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
boost::shared_ptr< Node > NodeSharedPtr
Shared pointer to a Node.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
boost::shared_ptr< Condition > ConditionSharedPtr
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
string GetXmlString(char tag, vector< unsigned int > &ids)
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Represents a command-line configuration option.
void WriteXmlExpansions(TiXmlElement *pRoot)
Writes the section of the XML file.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void WriteXmlDomain(TiXmlElement *pRoot)
Writes the section of the XML file.
void WriteXmlComposites(TiXmlElement *pRoot)
Writes the section of the XML file.
void WriteXmlElements(TiXmlElement *pRoot)
Writes the section of the XML file.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
void WriteXmlConditions(TiXmlElement *pRoot)
Writes the section of the XML file.
void WriteXmlEdges(TiXmlElement *pRoot)
Writes the section of the XML file.
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.