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;
57 "Writes a Nektar++ xml file.");
62 "Compress output file and append a .gz extension.");
74 cout <<
"OutputNekpp: Writing file..." << endl;
78 TiXmlDeclaration* decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
79 doc.LinkEndChild( decl );
81 TiXmlElement * root =
new TiXmlElement(
"NEKTAR" );
82 doc.LinkEndChild( root );
85 TiXmlElement * geomTag =
new TiXmlElement(
"GEOMETRY" );
86 geomTag->SetAttribute(
"DIM",
m_mesh->m_expDim);
87 geomTag->SetAttribute(
"SPACE",
m_mesh->m_spaceDim);
88 root->LinkEndChild( geomTag );
101 string filename =
m_config[
"outfile"].as<
string>();
107 ofstream fout(filename.c_str(),
108 std::ios_base::out | std::ios_base::binary);
110 std::stringstream decompressed;
112 io::filtering_streambuf<io::output> out;
113 out.push(io::gzip_compressor());
115 io::copy(decompressed, out);
121 doc.SaveFile(filename);
127 TiXmlElement* verTag =
new TiXmlElement(
"VERTEX" );
130 std::set<NodeSharedPtr> tmp(
131 m_mesh->m_vertexSet.begin(),
132 m_mesh->m_vertexSet.end());
134 for (it = tmp.begin(); it != tmp.end(); ++it)
138 s << scientific << setprecision(8)
139 << n->m_x <<
" " << n->m_y <<
" " << n->m_z;
140 TiXmlElement * v =
new TiXmlElement(
"V" );
141 v->SetAttribute(
"ID",n->m_id);
142 v->LinkEndChild(
new TiXmlText(s.str()));
143 verTag->LinkEndChild(v);
145 pRoot->LinkEndChild(verTag);
150 if (
m_mesh->m_expDim >= 2)
152 TiXmlElement* verTag =
new TiXmlElement(
"EDGE" );
154 std::set<EdgeSharedPtr> tmp(
m_mesh->m_edgeSet.begin(),
156 for (it = tmp.begin(); it != tmp.end(); ++it)
161 s << setw(5) << ed->m_n1->m_id <<
" " << ed->m_n2->m_id <<
" ";
162 TiXmlElement * e =
new TiXmlElement(
"E" );
163 e->SetAttribute(
"ID",ed->m_id);
164 e->LinkEndChild(
new TiXmlText(s.str()) );
165 verTag->LinkEndChild(e);
167 pRoot->LinkEndChild( verTag );
173 if (
m_mesh->m_expDim == 3)
175 TiXmlElement* verTag =
new TiXmlElement(
"FACE" );
177 std::set<FaceSharedPtr> tmp(
178 m_mesh->m_faceSet.begin(),
181 for (it = tmp.begin(); it != tmp.end(); ++it)
186 for (
int j = 0; j < fa->m_edgeList.size(); ++j)
188 s << setw(10) << fa->m_edgeList[j]->m_id;
191 switch(fa->m_vertexList.size())
194 f =
new TiXmlElement(
"T");
197 f =
new TiXmlElement(
"Q");
202 f->SetAttribute(
"ID", fa->m_id);
203 f->LinkEndChild(
new TiXmlText(s.str()));
204 verTag->LinkEndChild(f);
206 pRoot->LinkEndChild( verTag );
212 TiXmlElement* verTag =
new TiXmlElement(
"ELEMENT" );
213 vector<ElementSharedPtr> &elmt =
m_mesh->m_element[
m_mesh->m_expDim];
215 for(
int i = 0; i < elmt.size(); ++i)
217 TiXmlElement *elm_tag =
new TiXmlElement(elmt[i]->GetTag());
218 elm_tag->SetAttribute(
"ID", elmt[i]->GetId());
219 elm_tag->LinkEndChild(
new TiXmlText(elmt[i]->
GetXmlString()));
220 verTag->LinkEndChild(elm_tag);
222 pRoot->LinkEndChild(verTag);
231 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
233 if ((*it)->m_edgeNodes.size() > 0)
241 TiXmlElement * curved =
new TiXmlElement (
"CURVED" );
243 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
245 if ((*it)->m_edgeNodes.size() > 0)
247 TiXmlElement * e =
new TiXmlElement(
"E" );
248 e->SetAttribute(
"ID", edgecnt++);
249 e->SetAttribute(
"EDGEID", (*it)->m_id);
250 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
251 e->SetAttribute(
"TYPE",
253 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
255 curved->LinkEndChild(e);
269 if ((*it)->GetVolumeNodes().size() > 0)
271 TiXmlElement * e =
new TiXmlElement(
"F" );
272 e->SetAttribute(
"ID", facecnt++);
273 e->SetAttribute(
"FACEID", (*it)->GetId());
274 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
275 e->SetAttribute(
"TYPE",
278 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
280 curved->LinkEndChild(e);
284 else if (
m_mesh->m_expDim == 3)
287 for (it2 =
m_mesh->m_faceSet.begin(); it2 !=
m_mesh->m_faceSet.end(); ++it2)
289 if ((*it2)->m_faceNodes.size() > 0)
291 TiXmlElement * f =
new TiXmlElement(
"F" );
292 f->SetAttribute(
"ID", facecnt++);
293 f->SetAttribute(
"FACEID", (*it2)->m_id);
294 f->SetAttribute(
"NUMPOINTS",(*it2)->GetNodeCount());
295 f->SetAttribute(
"TYPE",
297 TiXmlText * t0 =
new TiXmlText((*it2)->GetXmlCurveString());
299 curved->LinkEndChild(f);
304 pRoot->LinkEndChild( curved );
309 TiXmlElement* verTag =
new TiXmlElement(
"COMPOSITE");
314 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it, ++j)
316 if (it->second->m_items.size() > 0)
318 TiXmlElement *comp_tag =
new TiXmlElement(
"C");
322 for (it2 =
m_mesh->m_condition.begin();
323 it2 !=
m_mesh->m_condition.end(); ++it2)
334 for (
int i = 0; i < c->m_composite.size(); ++i)
336 if (c->m_composite[i] == j)
343 doSort = doSort && it->second->m_reorder;
344 comp_tag->SetAttribute(
"ID", it->second->m_id);
345 comp_tag->LinkEndChild(
346 new TiXmlText(it->second->GetXmlString(doSort)));
347 verTag->LinkEndChild(comp_tag);
351 cout <<
"Composite " << it->second->m_id <<
" "
352 <<
"contains nothing." << endl;
356 pRoot->LinkEndChild(verTag);
362 TiXmlElement * domain =
new TiXmlElement (
"DOMAIN" );
366 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
368 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
370 if (list.length() > 0)
374 list += boost::lexical_cast<std::string>(it->second->m_id);
377 domain->LinkEndChild(
new TiXmlText(
" C[" + list +
"] "));
378 pRoot->LinkEndChild( domain );
384 TiXmlElement * expansions =
new TiXmlElement (
"EXPANSIONS");
387 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
389 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
391 TiXmlElement * exp =
new TiXmlElement (
"E");
392 exp->SetAttribute(
"COMPOSITE",
"C["
393 + boost::lexical_cast<std::string>(it->second->m_id)
395 exp->SetAttribute(
"NUMMODES",4);
396 exp->SetAttribute(
"TYPE",
"MODIFIED");
398 if (
m_mesh->m_fields.size() == 0)
400 exp->SetAttribute(
"FIELDS",
"u");
405 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
407 fstr +=
m_mesh->m_fields[i]+
",";
409 fstr = fstr.substr(0,fstr.length()-1);
410 exp->SetAttribute(
"FIELDS", fstr);
413 expansions->LinkEndChild(exp);
416 pRoot->LinkEndChild(expansions);
421 TiXmlElement *conditions =
422 new TiXmlElement(
"CONDITIONS");
423 TiXmlElement *boundaryregions =
424 new TiXmlElement(
"BOUNDARYREGIONS");
425 TiXmlElement *boundaryconditions =
426 new TiXmlElement(
"BOUNDARYCONDITIONS");
427 TiXmlElement *variables =
428 new TiXmlElement(
"VARIABLES");
431 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end(); ++it)
437 TiXmlElement *b =
new TiXmlElement(
"B");
438 b->SetAttribute(
"ID", boost::lexical_cast<string>(it->first));
440 for (
int i = 0; i < c->m_composite.size(); ++i)
442 tmp += boost::lexical_cast<
string>(c->m_composite[i]) +
",";
445 tmp = tmp.substr(0, tmp.length()-1);
447 TiXmlText *t0 =
new TiXmlText(
"C["+tmp+
"]");
449 boundaryregions->LinkEndChild(b);
451 TiXmlElement *region =
new TiXmlElement(
"REGION");
452 region->SetAttribute(
453 "REF", boost::lexical_cast<string>(it->first));
455 for (
int i = 0; i < c->type.size(); ++i)
468 TiXmlElement *tag =
new TiXmlElement(tagId);
469 tag->SetAttribute(
"VAR", c->field[i]);
470 tag->SetAttribute(
"VALUE", c->value[i]);
474 tag->SetAttribute(
"USERDEFINEDTYPE",
"H");
477 region->LinkEndChild(tag);
480 boundaryconditions->LinkEndChild(region);
483 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
485 TiXmlElement *v =
new TiXmlElement(
"V");
486 v->SetAttribute(
"ID", boost::lexical_cast<std::string>(i));
487 TiXmlText *t0 =
new TiXmlText(
m_mesh->m_fields[i]);
489 variables->LinkEndChild(v);
492 if (
m_mesh->m_fields.size() > 0)
494 conditions->LinkEndChild(variables);
497 if (
m_mesh->m_condition.size() > 0)
499 conditions->LinkEndChild(boundaryregions);
500 conditions->LinkEndChild(boundaryconditions);
503 pRoot->LinkEndChild(conditions);