Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::Utilities::OutputNekpp Class Reference

Converter for Gmsh files. More...

#include <OutputNekpp.h>

Inheritance diagram for Nektar::Utilities::OutputNekpp:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::OutputNekpp:
Collaboration graph
[legend]

Public Member Functions

 OutputNekpp (MeshSharedPtr m)
virtual ~OutputNekpp ()
virtual void Process ()
 Write mesh to output file.
- Public Member Functions inherited from Nektar::Utilities::OutputModule
 OutputModule (FieldSharedPtr p_f)
void OpenStream ()
 Open a file for output.
 OutputModule (MeshSharedPtr p_m)
void OpenStream ()
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
virtual void Process (po::variables_map &vm)=0
void RegisterConfig (string key, string value)
 Register a configuration option with a module.
void PrintConfig ()
 Print out all configuration options for a module.
void SetDefaults ()
 Sets default configuration options for those which have not been set.
bool GetRequireEquiSpaced (void)
void SetRequireEquiSpaced (bool pVal)
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 Module (MeshSharedPtr p_m)
void RegisterConfig (string key, string value)
void PrintConfig ()
void SetDefaults ()
MeshSharedPtr GetMesh ()
virtual void ProcessVertices ()
 Extract element vertices.

Static Public Member Functions

static boost::shared_ptr< Modulecreate (MeshSharedPtr m)
 Creates an instance of this class.

Static Public Attributes

static ModuleKey className

Private Member Functions

void WriteXmlNodes (TiXmlElement *pRoot)
 Writes the <NODES> section of the XML file.
void WriteXmlEdges (TiXmlElement *pRoot)
 Writes the <EDGES> section of the XML file.
void WriteXmlFaces (TiXmlElement *pRoot)
 Writes the <FACES> section of the XML file if needed.
void WriteXmlElements (TiXmlElement *pRoot)
 Writes the <ELEMENTS> section of the XML file.
void WriteXmlCurves (TiXmlElement *pRoot)
 Writes the <CURVES> section of the XML file if needed.
void WriteXmlComposites (TiXmlElement *pRoot)
 Writes the <COMPOSITES> section of the XML file.
void WriteXmlDomain (TiXmlElement *pRoot)
 Writes the <DOMAIN> section of the XML file.
void WriteXmlExpansions (TiXmlElement *pRoot)
 Writes the <EXPANSIONS> section of the XML file.
void WriteXmlConditions (TiXmlElement *pRoot)
 Writes the <CONDITIONS> section of the XML file.

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::Module
 Module ()
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges.
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces.
virtual void ProcessElements ()
 Generate element IDs.
virtual void ProcessComposites ()
 Generate composites.
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly.
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
- Protected Attributes inherited from Nektar::Utilities::OutputModule
ofstream m_fldFile
 Output stream.
std::ofstream m_mshFile
 Output stream.

Detailed Description

Converter for Gmsh files.

Definition at line 47 of file OutputNekpp.h.

Constructor & Destructor Documentation

Nektar::Utilities::OutputNekpp::OutputNekpp ( MeshSharedPtr  m)

Definition at line 61 of file OutputNekpp.cpp.

References Nektar::Utilities::Module::m_config.

{
m_config["z"] = ConfigOption(true, "0",
"Compress output file and append a .gz extension.");
m_config["test"] = ConfigOption(true, "0",
"Attempt to load resulting mesh and create meshgraph.");
}
Nektar::Utilities::OutputNekpp::~OutputNekpp ( )
virtual

Definition at line 69 of file OutputNekpp.cpp.

{
}

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::OutputNekpp::create ( MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file OutputNekpp.h.

{
return MemoryManager<OutputNekpp>::AllocateSharedPtr(m);
}
void Nektar::Utilities::OutputNekpp::Process ( )
virtual

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 74 of file OutputNekpp.cpp.

References Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_mesh, Nektar::SpatialDomains::MeshGraph::Read(), WriteXmlComposites(), WriteXmlConditions(), WriteXmlCurves(), WriteXmlDomain(), WriteXmlEdges(), WriteXmlElements(), WriteXmlExpansions(), WriteXmlFaces(), and WriteXmlNodes().

{
if (m_mesh->m_verbose)
{
cout << "OutputNekpp: Writing file..." << endl;
}
TiXmlDocument doc;
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "");
doc.LinkEndChild( decl );
TiXmlElement * root = new TiXmlElement( "NEKTAR" );
doc.LinkEndChild( root );
// Begin <GEOMETRY> section
TiXmlElement * geomTag = new TiXmlElement( "GEOMETRY" );
geomTag->SetAttribute("DIM", m_mesh->m_expDim);
geomTag->SetAttribute("SPACE", m_mesh->m_spaceDim);
root->LinkEndChild( geomTag );
WriteXmlNodes (geomTag);
WriteXmlEdges (geomTag);
WriteXmlFaces (geomTag);
WriteXmlElements (geomTag);
WriteXmlCurves (geomTag);
WriteXmlDomain (geomTag);
// Extract the output filename and extension
string filename = m_config["outfile"].as<string>();
// Compress output and append .gz extension
if (m_config["z"].as<bool>())
{
filename += ".gz";
ofstream fout(filename.c_str(),
std::ios_base::out | std::ios_base::binary);
std::stringstream decompressed;
decompressed << doc;
io::filtering_streambuf<io::output> out;
out.push(io::gzip_compressor());
out.push(fout);
io::copy(decompressed, out);
fout.close();
}
else
{
doc.SaveFile(filename);
}
// Test the resulting XML file by loading it with the session reader
// and generating the meshgraph.
if (m_config["test"].beenSet)
{
vector<string> filenames(1);
filenames[0] = filename;
0, NULL, filenames);
}
}
void Nektar::Utilities::OutputNekpp::WriteXmlComposites ( TiXmlElement *  pRoot)
private

Writes the <COMPOSITES> section of the XML file.

Definition at line 325 of file OutputNekpp.cpp.

References Nektar::Utilities::ePeriodic, Nektar::StdRegions::find(), Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
TiXmlElement* verTag = new TiXmlElement("COMPOSITE");
int j = 0;
for (it = m_mesh->m_composite.begin(); it != m_mesh->m_composite.end(); ++it, ++j)
{
if (it->second->m_items.size() > 0)
{
TiXmlElement *comp_tag = new TiXmlElement("C"); // Composite
bool doSort = true;
// Ensure that this composite is not used for periodic BCs!
for (it2 = m_mesh->m_condition.begin();
it2 != m_mesh->m_condition.end(); ++it2)
{
ConditionSharedPtr c = it2->second;
// Ignore non-periodic boundary conditions.
if (find(c->type.begin(), c->type.end(), ePeriodic) ==
c->type.end())
{
continue;
}
for (int i = 0; i < c->m_composite.size(); ++i)
{
if (c->m_composite[i] == j)
{
doSort = false;
}
}
}
doSort = doSort && it->second->m_reorder;
comp_tag->SetAttribute("ID", it->second->m_id);
comp_tag->LinkEndChild(
new TiXmlText(it->second->GetXmlString(doSort)));
verTag->LinkEndChild(comp_tag);
}
else
{
cout << "Composite " << it->second->m_id << " "
<< "contains nothing." << endl;
}
}
pRoot->LinkEndChild(verTag);
}
void Nektar::Utilities::OutputNekpp::WriteXmlConditions ( TiXmlElement *  pRoot)
private

Writes the <CONDITIONS> section of the XML file.

Definition at line 437 of file OutputNekpp.cpp.

References Nektar::Utilities::eDirichlet, Nektar::Utilities::eHOPCondition, Nektar::Utilities::eNeumann, Nektar::Utilities::ePeriodic, Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
TiXmlElement *conditions =
new TiXmlElement("CONDITIONS");
TiXmlElement *boundaryregions =
new TiXmlElement("BOUNDARYREGIONS");
TiXmlElement *boundaryconditions =
new TiXmlElement("BOUNDARYCONDITIONS");
TiXmlElement *variables =
new TiXmlElement("VARIABLES");
for (it = m_mesh->m_condition.begin(); it != m_mesh->m_condition.end(); ++it)
{
ConditionSharedPtr c = it->second;
string tmp;
// First set up boundary regions.
TiXmlElement *b = new TiXmlElement("B");
b->SetAttribute("ID", boost::lexical_cast<string>(it->first));
for (int i = 0; i < c->m_composite.size(); ++i)
{
tmp += boost::lexical_cast<string>(c->m_composite[i]) + ",";
}
tmp = tmp.substr(0, tmp.length()-1);
TiXmlText *t0 = new TiXmlText("C["+tmp+"]");
b->LinkEndChild(t0);
boundaryregions->LinkEndChild(b);
TiXmlElement *region = new TiXmlElement("REGION");
region->SetAttribute(
"REF", boost::lexical_cast<string>(it->first));
for (int i = 0; i < c->type.size(); ++i)
{
string tagId;
switch(c->type[i])
{
case eDirichlet: tagId = "D"; break;
case eNeumann: tagId = "N"; break;
case ePeriodic: tagId = "P"; break;
case eHOPCondition: tagId = "N"; break;
default: break;
}
TiXmlElement *tag = new TiXmlElement(tagId);
tag->SetAttribute("VAR", c->field[i]);
tag->SetAttribute("VALUE", c->value[i]);
if (c->type[i] == eHOPCondition)
{
tag->SetAttribute("USERDEFINEDTYPE", "H");
}
region->LinkEndChild(tag);
}
boundaryconditions->LinkEndChild(region);
}
for (int i = 0; i < m_mesh->m_fields.size(); ++i)
{
TiXmlElement *v = new TiXmlElement("V");
v->SetAttribute("ID", boost::lexical_cast<std::string>(i));
TiXmlText *t0 = new TiXmlText(m_mesh->m_fields[i]);
v->LinkEndChild(t0);
variables->LinkEndChild(v);
}
if (m_mesh->m_fields.size() > 0)
{
conditions->LinkEndChild(variables);
}
if (m_mesh->m_condition.size() > 0)
{
conditions->LinkEndChild(boundaryregions);
conditions->LinkEndChild(boundaryconditions);
}
pRoot->LinkEndChild(conditions);
}
void Nektar::Utilities::OutputNekpp::WriteXmlCurves ( TiXmlElement *  pRoot)
private

Writes the <CURVES> section of the XML file if needed.

Definition at line 243 of file OutputNekpp.cpp.

References Nektar::iterator, Nektar::LibUtilities::kPointsTypeStr, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
int edgecnt = 0;
bool curve = false;
for (it = m_mesh->m_edgeSet.begin(); it != m_mesh->m_edgeSet.end(); ++it)
{
if ((*it)->m_edgeNodes.size() > 0)
{
curve = true;
break;
}
}
if (!curve) return;
TiXmlElement * curved = new TiXmlElement ("CURVED" );
for (it = m_mesh->m_edgeSet.begin(); it != m_mesh->m_edgeSet.end(); ++it)
{
if ((*it)->m_edgeNodes.size() > 0)
{
TiXmlElement * e = new TiXmlElement( "E" );
e->SetAttribute("ID", edgecnt++);
e->SetAttribute("EDGEID", (*it)->m_id);
e->SetAttribute("NUMPOINTS", (*it)->GetNodeCount());
e->SetAttribute("TYPE",
LibUtilities::kPointsTypeStr[(*it)->m_curveType]);
TiXmlText * t0 = new TiXmlText((*it)->GetXmlCurveString());
e->LinkEndChild(t0);
curved->LinkEndChild(e);
}
}
int facecnt = 0;
// 2D elements in 3-space, output face curvature information
if (m_mesh->m_expDim == 2 && m_mesh->m_spaceDim == 3)
{
for (it = m_mesh->m_element[m_mesh->m_expDim].begin();
it != m_mesh->m_element[m_mesh->m_expDim].end(); ++it)
{
// Only generate face curve if there are volume nodes
if ((*it)->GetVolumeNodes().size() > 0)
{
TiXmlElement * e = new TiXmlElement( "F" );
e->SetAttribute("ID", facecnt++);
e->SetAttribute("FACEID", (*it)->GetId());
e->SetAttribute("NUMPOINTS", (*it)->GetNodeCount());
e->SetAttribute("TYPE",
LibUtilities::kPointsTypeStr[(*it)->GetCurveType()]);
TiXmlText * t0 = new TiXmlText((*it)->GetXmlCurveString());
e->LinkEndChild(t0);
curved->LinkEndChild(e);
}
}
}
else if (m_mesh->m_expDim == 3)
{
for (it2 = m_mesh->m_faceSet.begin(); it2 != m_mesh->m_faceSet.end(); ++it2)
{
if ((*it2)->m_faceNodes.size() > 0)
{
TiXmlElement * f = new TiXmlElement( "F" );
f->SetAttribute("ID", facecnt++);
f->SetAttribute("FACEID", (*it2)->m_id);
f->SetAttribute("NUMPOINTS",(*it2)->GetNodeCount());
f->SetAttribute("TYPE",
LibUtilities::kPointsTypeStr[(*it2)->m_curveType]);
TiXmlText * t0 = new TiXmlText((*it2)->GetXmlCurveString());
f->LinkEndChild(t0);
curved->LinkEndChild(f);
}
}
}
pRoot->LinkEndChild( curved );
}
void Nektar::Utilities::OutputNekpp::WriteXmlDomain ( TiXmlElement *  pRoot)
private

Writes the <DOMAIN> section of the XML file.

Definition at line 377 of file OutputNekpp.cpp.

References Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
// Write the <DOMAIN> subsection.
TiXmlElement * domain = new TiXmlElement ("DOMAIN" );
std::string list;
for (it = m_mesh->m_composite.begin(); it != m_mesh->m_composite.end(); ++it)
{
if (it->second->m_items[0]->GetDim() == m_mesh->m_expDim)
{
if (list.length() > 0)
{
list += ",";
}
list += boost::lexical_cast<std::string>(it->second->m_id);
}
}
domain->LinkEndChild( new TiXmlText(" C[" + list + "] "));
pRoot->LinkEndChild( domain );
}
void Nektar::Utilities::OutputNekpp::WriteXmlEdges ( TiXmlElement *  pRoot)
private

Writes the <EDGES> section of the XML file.

Definition at line 166 of file OutputNekpp.cpp.

References Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
if (m_mesh->m_expDim >= 2)
{
TiXmlElement* verTag = new TiXmlElement( "EDGE" );
std::set<EdgeSharedPtr> tmp(m_mesh->m_edgeSet.begin(),
m_mesh->m_edgeSet.end());
for (it = tmp.begin(); it != tmp.end(); ++it)
{
EdgeSharedPtr ed = *it;
stringstream s;
s << setw(5) << ed->m_n1->m_id << " " << ed->m_n2->m_id << " ";
TiXmlElement * e = new TiXmlElement( "E" );
e->SetAttribute("ID",ed->m_id);
e->LinkEndChild( new TiXmlText(s.str()) );
verTag->LinkEndChild(e);
}
pRoot->LinkEndChild( verTag );
}
}
void Nektar::Utilities::OutputNekpp::WriteXmlElements ( TiXmlElement *  pRoot)
private

Writes the <ELEMENTS> section of the XML file.

Definition at line 228 of file OutputNekpp.cpp.

References GetXmlString(), and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
TiXmlElement* verTag = new TiXmlElement( "ELEMENT" );
vector<ElementSharedPtr> &elmt = m_mesh->m_element[m_mesh->m_expDim];
for(int i = 0; i < elmt.size(); ++i)
{
TiXmlElement *elm_tag = new TiXmlElement(elmt[i]->GetTag());
elm_tag->SetAttribute("ID", elmt[i]->GetId());
elm_tag->LinkEndChild(new TiXmlText(elmt[i]->GetXmlString()));
verTag->LinkEndChild(elm_tag);
}
pRoot->LinkEndChild(verTag);
}
void Nektar::Utilities::OutputNekpp::WriteXmlExpansions ( TiXmlElement *  pRoot)
private

Writes the <EXPANSIONS> section of the XML file.

Definition at line 399 of file OutputNekpp.cpp.

References Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
// Write a default <EXPANSIONS> section.
TiXmlElement * expansions = new TiXmlElement ("EXPANSIONS");
for (it = m_mesh->m_composite.begin(); it != m_mesh->m_composite.end(); ++it)
{
if (it->second->m_items[0]->GetDim() == m_mesh->m_expDim)
{
TiXmlElement * exp = new TiXmlElement ( "E");
exp->SetAttribute("COMPOSITE", "C["
+ boost::lexical_cast<std::string>(it->second->m_id)
+ "]");
exp->SetAttribute("NUMMODES",4);
exp->SetAttribute("TYPE","MODIFIED");
if (m_mesh->m_fields.size() == 0)
{
exp->SetAttribute("FIELDS","u");
}
else
{
string fstr;
for (int i = 0; i < m_mesh->m_fields.size(); ++i)
{
fstr += m_mesh->m_fields[i]+",";
}
fstr = fstr.substr(0,fstr.length()-1);
exp->SetAttribute("FIELDS", fstr);
}
expansions->LinkEndChild(exp);
}
}
pRoot->LinkEndChild(expansions);
}
void Nektar::Utilities::OutputNekpp::WriteXmlFaces ( TiXmlElement *  pRoot)
private

Writes the <FACES> section of the XML file if needed.

Definition at line 189 of file OutputNekpp.cpp.

References Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
if (m_mesh->m_expDim == 3)
{
TiXmlElement* verTag = new TiXmlElement( "FACE" );
std::set<FaceSharedPtr> tmp(
m_mesh->m_faceSet.begin(),
m_mesh->m_faceSet.end());
for (it = tmp.begin(); it != tmp.end(); ++it)
{
stringstream s;
FaceSharedPtr fa = *it;
for (int j = 0; j < fa->m_edgeList.size(); ++j)
{
s << setw(10) << fa->m_edgeList[j]->m_id;
}
TiXmlElement * f;
switch(fa->m_vertexList.size())
{
case 3:
f = new TiXmlElement("T");
break;
case 4:
f = new TiXmlElement("Q");
break;
default:
abort();
}
f->SetAttribute("ID", fa->m_id);
f->LinkEndChild( new TiXmlText(s.str()));
verTag->LinkEndChild(f);
}
pRoot->LinkEndChild( verTag );
}
}
void Nektar::Utilities::OutputNekpp::WriteXmlNodes ( TiXmlElement *  pRoot)
private

Writes the <NODES> section of the XML file.

Definition at line 143 of file OutputNekpp.cpp.

References Nektar::iterator, and Nektar::Utilities::Module::m_mesh.

Referenced by Process().

{
TiXmlElement* verTag = new TiXmlElement( "VERTEX" );
std::set<NodeSharedPtr> tmp(
m_mesh->m_vertexSet.begin(),
m_mesh->m_vertexSet.end());
for (it = tmp.begin(); it != tmp.end(); ++it)
{
NodeSharedPtr n = *it;
stringstream s;
s << scientific << setprecision(8)
<< n->m_x << " " << n->m_y << " " << n->m_z;
TiXmlElement * v = new TiXmlElement( "V" );
v->SetAttribute("ID",n->m_id);
v->LinkEndChild(new TiXmlText(s.str()));
verTag->LinkEndChild(v);
}
pRoot->LinkEndChild(verTag);
}

Member Data Documentation

ModuleKey Nektar::Utilities::OutputNekpp::className
static
Initial value:

Definition at line 54 of file OutputNekpp.h.