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;
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);
249 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
251 if ((*it)->m_edgeNodes.size() > 0)
259 TiXmlElement * curved =
new TiXmlElement (
"CURVED" );
261 for (it =
m_mesh->m_edgeSet.begin(); it !=
m_mesh->m_edgeSet.end(); ++it)
263 if ((*it)->m_edgeNodes.size() > 0)
265 TiXmlElement * e =
new TiXmlElement(
"E" );
266 e->SetAttribute(
"ID", edgecnt++);
267 e->SetAttribute(
"EDGEID", (*it)->m_id);
268 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
269 e->SetAttribute(
"TYPE",
271 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
273 curved->LinkEndChild(e);
287 if ((*it)->GetVolumeNodes().size() > 0)
289 TiXmlElement * e =
new TiXmlElement(
"F" );
290 e->SetAttribute(
"ID", facecnt++);
291 e->SetAttribute(
"FACEID", (*it)->GetId());
292 e->SetAttribute(
"NUMPOINTS", (*it)->GetNodeCount());
293 e->SetAttribute(
"TYPE",
296 TiXmlText * t0 =
new TiXmlText((*it)->GetXmlCurveString());
298 curved->LinkEndChild(e);
302 else if (
m_mesh->m_expDim == 3)
305 for (it2 =
m_mesh->m_faceSet.begin(); it2 !=
m_mesh->m_faceSet.end(); ++it2)
307 if ((*it2)->m_faceNodes.size() > 0)
309 TiXmlElement * f =
new TiXmlElement(
"F" );
310 f->SetAttribute(
"ID", facecnt++);
311 f->SetAttribute(
"FACEID", (*it2)->m_id);
312 f->SetAttribute(
"NUMPOINTS",(*it2)->GetNodeCount());
313 f->SetAttribute(
"TYPE",
315 TiXmlText * t0 =
new TiXmlText((*it2)->GetXmlCurveString());
317 curved->LinkEndChild(f);
322 pRoot->LinkEndChild( curved );
327 TiXmlElement* verTag =
new TiXmlElement(
"COMPOSITE");
332 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it, ++j)
334 if (it->second->m_items.size() > 0)
336 TiXmlElement *comp_tag =
new TiXmlElement(
"C");
340 for (it2 =
m_mesh->m_condition.begin();
341 it2 !=
m_mesh->m_condition.end(); ++it2)
352 for (
int i = 0; i < c->m_composite.size(); ++i)
354 if (c->m_composite[i] == j)
361 doSort = doSort && it->second->m_reorder;
362 comp_tag->SetAttribute(
"ID", it->second->m_id);
363 comp_tag->LinkEndChild(
364 new TiXmlText(it->second->GetXmlString(doSort)));
365 verTag->LinkEndChild(comp_tag);
369 cout <<
"Composite " << it->second->m_id <<
" "
370 <<
"contains nothing." << endl;
374 pRoot->LinkEndChild(verTag);
380 TiXmlElement * domain =
new TiXmlElement (
"DOMAIN" );
384 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
386 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
388 if (list.length() > 0)
392 list += boost::lexical_cast<std::string>(it->second->m_id);
395 domain->LinkEndChild(
new TiXmlText(
" C[" + list +
"] "));
396 pRoot->LinkEndChild( domain );
402 TiXmlElement * expansions =
new TiXmlElement (
"EXPANSIONS");
405 for (it =
m_mesh->m_composite.begin(); it !=
m_mesh->m_composite.end(); ++it)
407 if (it->second->m_items[0]->GetDim() ==
m_mesh->m_expDim)
409 TiXmlElement * exp =
new TiXmlElement (
"E");
410 exp->SetAttribute(
"COMPOSITE",
"C["
411 + boost::lexical_cast<std::string>(it->second->m_id)
413 exp->SetAttribute(
"NUMMODES",4);
414 exp->SetAttribute(
"TYPE",
"MODIFIED");
416 if (
m_mesh->m_fields.size() == 0)
418 exp->SetAttribute(
"FIELDS",
"u");
423 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
425 fstr +=
m_mesh->m_fields[i]+
",";
427 fstr = fstr.substr(0,fstr.length()-1);
428 exp->SetAttribute(
"FIELDS", fstr);
431 expansions->LinkEndChild(exp);
434 pRoot->LinkEndChild(expansions);
439 TiXmlElement *conditions =
440 new TiXmlElement(
"CONDITIONS");
441 TiXmlElement *boundaryregions =
442 new TiXmlElement(
"BOUNDARYREGIONS");
443 TiXmlElement *boundaryconditions =
444 new TiXmlElement(
"BOUNDARYCONDITIONS");
445 TiXmlElement *variables =
446 new TiXmlElement(
"VARIABLES");
449 for (it =
m_mesh->m_condition.begin(); it !=
m_mesh->m_condition.end(); ++it)
455 TiXmlElement *b =
new TiXmlElement(
"B");
456 b->SetAttribute(
"ID", boost::lexical_cast<string>(it->first));
458 for (
int i = 0; i < c->m_composite.size(); ++i)
460 tmp += boost::lexical_cast<
string>(c->m_composite[i]) +
",";
463 tmp = tmp.substr(0, tmp.length()-1);
465 TiXmlText *t0 =
new TiXmlText(
"C["+tmp+
"]");
467 boundaryregions->LinkEndChild(b);
469 TiXmlElement *region =
new TiXmlElement(
"REGION");
470 region->SetAttribute(
471 "REF", boost::lexical_cast<string>(it->first));
473 for (
int i = 0; i < c->type.size(); ++i)
486 TiXmlElement *tag =
new TiXmlElement(tagId);
487 tag->SetAttribute(
"VAR", c->field[i]);
488 tag->SetAttribute(
"VALUE", c->value[i]);
492 tag->SetAttribute(
"USERDEFINEDTYPE",
"H");
495 region->LinkEndChild(tag);
498 boundaryconditions->LinkEndChild(region);
501 for (
int i = 0; i <
m_mesh->m_fields.size(); ++i)
503 TiXmlElement *v =
new TiXmlElement(
"V");
504 v->SetAttribute(
"ID", boost::lexical_cast<std::string>(i));
505 TiXmlText *t0 =
new TiXmlText(
m_mesh->m_fields[i]);
507 variables->LinkEndChild(v);
510 if (
m_mesh->m_fields.size() > 0)
512 conditions->LinkEndChild(variables);
515 if (
m_mesh->m_condition.size() > 0)
517 conditions->LinkEndChild(boundaryregions);
518 conditions->LinkEndChild(boundaryconditions);
521 pRoot->LinkEndChild(conditions);