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 | Private Attributes | List of all members
Nektar::Utilities::OutputTecplot Class Reference

Converter from fld to dat. More...

#include <OutputTecplot.h>

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

Public Member Functions

 OutputTecplot (FieldSharedPtr f)
virtual ~OutputTecplot ()
virtual void Process (po::variables_map &vm)
 Write fld 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)
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)
 Module (MeshSharedPtr p_m)
virtual void Process ()=0
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 (FieldSharedPtr f)
 Creates an instance of this class.

Static Public Attributes

static ModuleKey m_className

Private Member Functions

void WriteTecplotHeader (std::ofstream &outfile, std::string var)
void WriteTecplotZone (std::ofstream &outfile, int expansion=-1)
int GetNumTecplotBlocks (void)
void WriteTecplotField (const int field, std::ofstream &outfile, int expansion=-1)
void WriteTecplotConnectivity (std::ofstream &outfile)

Private Attributes

bool m_doError

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::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 from fld to dat.

Definition at line 47 of file OutputTecplot.h.

Constructor & Destructor Documentation

Nektar::Utilities::OutputTecplot::OutputTecplot ( FieldSharedPtr  f)
Nektar::Utilities::OutputTecplot::~OutputTecplot ( )
virtual

Definition at line 58 of file OutputTecplot.cpp.

{
}

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::OutputTecplot::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file OutputTecplot.h.

int Nektar::Utilities::OutputTecplot::GetNumTecplotBlocks ( void  )
private

Definition at line 313 of file OutputTecplot.cpp.

References Nektar::Utilities::Module::m_f.

Referenced by WriteTecplotZone().

{
int returnval = 0;
if(m_f->m_exp[0]->GetExp(0)->GetNumBases() == 1)
{
for(int i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
{
returnval += (m_f->m_exp[0]->GetExp(i)->GetNumPoints(0)-1);
}
}
else if(m_f->m_exp[0]->GetExp(0)->GetNumBases() == 2)
{
for(int i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
{
returnval += (m_f->m_exp[0]->GetExp(i)->GetNumPoints(0)-1)*
(m_f->m_exp[0]->GetExp(i)->GetNumPoints(1)-1);
}
}
else
{
for(int i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
{
returnval += (m_f->m_exp[0]->GetExp(i)->GetNumPoints(0)-1)*
(m_f->m_exp[0]->GetExp(i)->GetNumPoints(1)-1)*
(m_f->m_exp[0]->GetExp(i)->GetNumPoints(2)-1);
}
}
return returnval;
}
void Nektar::Utilities::OutputTecplot::Process ( po::variables_map &  vm)
virtual

Write fld to output file.

Implements Nektar::Utilities::Module.

Definition at line 62 of file OutputTecplot.cpp.

References Nektar::Utilities::ePtsFile, Nektar::Utilities::ePtsLine, Nektar::Utilities::ePtsPlane, Nektar::Utilities::Module::m_config, m_doError, Nektar::Utilities::Module::m_f, Nektar::Utilities::NullFieldPts, WriteTecplotConnectivity(), WriteTecplotField(), WriteTecplotHeader(), and WriteTecplotZone().

{
m_doError = (vm.count("error") == 1)? true: false;
if (m_f->m_verbose)
{
cout << "OutputTecplot: Writing file..." << endl;
}
// Do nothing if no expansion defined
if(m_f->m_fieldPts == NullFieldPts &&!m_f->m_exp.size())
{
return;
}
// Extract the output filename and extension
string filename = m_config["outfile"].as<string>();
if(m_f->m_fieldPts != NullFieldPts)
{
int dim = m_f->m_fieldPts->m_ptsDim;
// Write solution.
ofstream outfile(filename.c_str());
switch(dim)
{
case 1:
outfile << "VARIABLES = x";
break;
case 2:
outfile << "VARIABLES = x y";
break;
case 3:
outfile << "VARIABLES = x y z";
break;
}
for(int i = 0; i < m_f->m_fieldPts->m_fields.size(); ++i)
{
outfile << " " << m_f->m_fieldPts->m_fields[i];
}
outfile << endl;
switch(m_f->m_fieldPts->m_ptype)
{
outfile << " ZONE I="
<< m_f->m_fieldPts->m_pts[0].num_elements()
<< " F=POINT" << endl;
break;
outfile << " ZONE I=" << m_f->m_fieldPts->m_npts[0]
<< " J=" << m_f->m_fieldPts->m_npts[1]
<< " F=POINT" << endl;
break;
}
for(int i = 0; i < m_f->m_fieldPts->m_pts[0].num_elements(); ++i)
{
for(int j = 0; j < dim; ++j)
{
outfile << std::setw(12)
<< m_f->m_fieldPts->m_pts[j][i] << " ";
}
for(int j = 0; j < m_f->m_fieldPts->m_fields.size(); ++j)
{
outfile << std::setw(12) << m_f->m_data[j][i] << " ";
}
outfile << endl;
}
}
else
{
// Amend for parallel output if required
if(m_f->m_session->GetComm()->GetSize() != 1)
{
int dot = filename.find_last_of('.');
string ext = filename.substr(dot,filename.length()-dot);
string procId = "_P" + boost::lexical_cast<std::string>(
m_f->m_session->GetComm()->GetRank());
string start = filename.substr(0,dot);
filename = start + procId + ext;
}
// Write solution.
ofstream outfile(filename.c_str());
std::string var;
if(m_f->m_fielddef.size())
{
var = m_f->m_fielddef[0]->m_fields[0];
for (int j = 1; j < m_f->m_fielddef[0]->m_fields.size(); ++j)
{
var = var + ", " + m_f->m_fielddef[0]->m_fields[j];
}
}
WriteTecplotHeader(outfile,var);
WriteTecplotZone(outfile);
if(var.length()) // see if any variables are defined
{
for(int j = 0; j < m_f->m_exp.size(); ++j)
{
WriteTecplotField(j,outfile);
}
}
}
cout << "Written file: " << filename << endl;
}
void Nektar::Utilities::OutputTecplot::WriteTecplotConnectivity ( std::ofstream &  outfile)
private

Definition at line 396 of file OutputTecplot.cpp.

References ASSERTL0, Nektar::MultiRegions::e3DH1D, and Nektar::Utilities::Module::m_f.

Referenced by Process().

{
int i,j,k,l;
int nbase = m_f->m_exp[0]->GetExp(0)->GetNumBases();
int cnt = 0;
for(i = 0; i < m_f->m_exp[0]->GetNumElmts(); ++i)
{
if(nbase == 1)
{
int np0 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
for(k = 1; k < np0; ++k)
{
outfile << cnt + k +1 << " ";
outfile << cnt + k << endl;
}
cnt += np0;
}
else if(nbase == 2)
{
int np0 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
int np1 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
int totPoints = m_f->m_exp[0]->GetTotPoints();
int nPlanes = 1;
if (m_f->m_exp[0]->GetExpType() == MultiRegions::e3DH1D)
{
nPlanes = m_f->m_exp[0]->GetZIDs().num_elements();
totPoints = m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
for(int n = 1; n < nPlanes; ++n)
{
for(j = 1; j < np1; ++j)
{
for(k = 1; k < np0; ++k)
{
outfile << cnt + (n-1)*totPoints + (j-1)*np0 + k
<< " ";
outfile << cnt + (n-1)*totPoints + (j-1)*np0 + k + 1
<< " ";
outfile << cnt + (n-1)*totPoints + j*np0 + k + 1
<< " ";
outfile << cnt + (n-1)*totPoints + j*np0 + k
<< " ";
outfile << cnt + n*totPoints + (j-1)*np0 + k
<< " ";
outfile << cnt + n*totPoints + (j-1)*np0 + k + 1
<< " ";
outfile << cnt + n*totPoints + j*np0 + k + 1
<< " ";
outfile << cnt + n*totPoints + j*np0 + k << endl;
}
}
}
cnt += np0*np1;
}
else
{
for(j = 1; j < np1; ++j)
{
for(k = 1; k < np0; ++k)
{
outfile << cnt + (j-1)*np0 + k << " ";
outfile << cnt + (j-1)*np0 + k +1 << " ";
outfile << cnt + j*np0 + k +1 << " ";
outfile << cnt + j*np0 + k << endl;
}
}
cnt += np0*np1;
}
}
else if(nbase == 3)
{
int np0 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
int np1 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
int np2 = m_f->m_exp[0]->GetExp(i)->GetNumPoints(2);
for(j = 1; j < np2; ++j)
{
for(k = 1; k < np1; ++k)
{
for(l = 1; l < np0; ++l)
{
outfile << cnt + (j-1)*np0*np1 + (k-1)*np0 + l << " ";
outfile << cnt + (j-1)*np0*np1 + (k-1)*np0 + l +1 << " ";
outfile << cnt + (j-1)*np0*np1 + k*np0 + l +1 << " ";
outfile << cnt + (j-1)*np0*np1 + k*np0 + l << " ";
outfile << cnt + j*np0*np1 + (k-1)*np0 + l << " ";
outfile << cnt + j*np0*np1 + (k-1)*np0 + l +1 << " ";
outfile << cnt + j*np0*np1 + k*np0 + l +1 << " ";
outfile << cnt + j*np0*np1 + k*np0 + l << endl;
}
}
}
cnt += np0*np1*np2;
}
else
{
ASSERTL0(false,"Not set up for this dimension");
}
}
}
void Nektar::Utilities::OutputTecplot::WriteTecplotField ( const int  field,
std::ofstream &  outfile,
int  expansion = -1 
)
private

Write Tecplot Files Field

Parameters
outfileOutput file name.
expansionExpansion that is considered

Definition at line 351 of file OutputTecplot.cpp.

References m_doError, and Nektar::Utilities::Module::m_f.

Referenced by Process().

{
if(expansion == -1) //write as full block zone
{
int totpoints = m_f->m_exp[0]->GetTotPoints();
if(m_f->m_exp[field]->GetPhysState() == false)
{
m_f->m_exp[field]->BwdTrans(m_f->m_exp[field]->GetCoeffs(),
m_f->m_exp[field]->UpdatePhys());
}
if (m_doError)
{
NekDouble l2err = m_f->m_exp[0]->L2(m_f->m_exp[field]->UpdatePhys());
if(m_f->m_session->GetComm()->GetRank() == 0)
{
cout << "L 2 error (variable "
<< m_f->m_fielddef[0]->m_fields[field] << ") : "
<< l2err << endl;
}
}
else
{
for(int i = 0; i < totpoints; ++i)
{
outfile << m_f->m_exp[field]->GetPhys()[i] << " ";
if((!(i % 1000))&&i)
{
outfile << std::endl;
}
}
}
outfile << std::endl;
}
else
{
m_f->m_exp[field]->WriteTecplotField(outfile,expansion);
}
}
void Nektar::Utilities::OutputTecplot::WriteTecplotHeader ( std::ofstream &  outfile,
std::string  var 
)
private

Write Tecplot Files Header

Parameters
outfileOutput file name.
varvariables names

Definition at line 181 of file OutputTecplot.cpp.

References Nektar::MultiRegions::e3DH1D, Nektar::MultiRegions::e3DH2D, and Nektar::Utilities::Module::m_f.

Referenced by Process().

{
int coordim = m_f->m_exp[0]->GetExp(0)->GetCoordim();
MultiRegions::ExpansionType HomoExpType = m_f->m_exp[0]->GetExpType();
if(HomoExpType == MultiRegions::e3DH1D)
{
coordim +=1;
}
else if (HomoExpType == MultiRegions::e3DH2D)
{
coordim += 2;
}
outfile << "Variables = x";
if(coordim == 2)
{
outfile << ", y";
}
else if (coordim == 3)
{
outfile << ", y, z";
}
if(var.length())
{
outfile << ", "<< var << std::endl << std::endl;
}
else
{
outfile << std::endl << std::endl;
}
}
void Nektar::Utilities::OutputTecplot::WriteTecplotZone ( std::ofstream &  outfile,
int  expansion = -1 
)
private

Write Tecplot Files Zone

Parameters
outfileOutput file name.
expansionExpansion that is considered

Definition at line 223 of file OutputTecplot.cpp.

References Nektar::MultiRegions::e3DH1D, Nektar::MultiRegions::e3DH2D, GetNumTecplotBlocks(), m_doError, and Nektar::Utilities::Module::m_f.

Referenced by Process().

{
if(expansion == -1) //write as full block zone
{
int i,j;
int coordim = m_f->m_exp[0]->GetCoordim(0);
int totpoints = m_f->m_exp[0]->GetTotPoints();
MultiRegions::ExpansionType HomoExpType = m_f->m_exp[0]->GetExpType();
Array<OneD,NekDouble> coords[3];
coords[0] = Array<OneD,NekDouble>(totpoints);
coords[1] = Array<OneD,NekDouble>(totpoints);
coords[2] = Array<OneD,NekDouble>(totpoints);
m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
if (m_doError)
{
NekDouble l2err;
std::string coordval[] = {"x","y","z"};
int rank = m_f->m_session->GetComm()->GetRank();
for(int i = 0; i < coordim; ++i)
{
l2err = m_f->m_exp[0]->L2(coords[i]);
if(rank == 0)
{
cout << "L 2 error (variable "
<< coordval[i] << ") : " << l2err << endl;
}
}
}
int numBlocks = GetNumTecplotBlocks();
int nBases = m_f->m_exp[0]->GetExp(0)->GetNumBases();
if (HomoExpType == MultiRegions::e3DH1D)
{
nBases += 1;
coordim += 1;
int nPlanes = m_f->m_exp[0]->GetZIDs().num_elements();
NekDouble tmp = numBlocks * (nPlanes-1);
numBlocks = (int)tmp;
}
else if (HomoExpType == MultiRegions::e3DH2D)
{
nBases += 2;
coordim += 1;
}
outfile << "Zone, N=" << totpoints << ", E="<<
numBlocks << ", F=FEBlock" ;
switch(nBases)
{
case 1:
outfile << ", ET=LINESEG" << std::endl;
break;
case 2:
outfile << ", ET=QUADRILATERAL" << std::endl;
break;
case 3:
outfile << ", ET=BRICK" << std::endl;
break;
}
// write out coordinates in block format
for(j = 0; j < coordim; ++j)
{
for(i = 0; i < totpoints; ++i)
{
outfile << coords[j][i] << " ";
if((!(i % 1000))&&i)
{
outfile << std::endl;
}
}
outfile << std::endl;
}
}
else
{
m_f->m_exp[0]->WriteTecplotZone(outfile,expansion);
}
}

Member Data Documentation

ModuleKey Nektar::Utilities::OutputTecplot::m_className
static
Initial value:

Definition at line 54 of file OutputTecplot.h.

bool Nektar::Utilities::OutputTecplot::m_doError
private

Definition at line 62 of file OutputTecplot.h.

Referenced by Process(), WriteTecplotField(), and WriteTecplotZone().