Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
FldToVtk.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <MultiRegions/ExpList.h>
#include <MultiRegions/ExpList1D.h>
#include <MultiRegions/ExpList2D.h>
#include <MultiRegions/ExpList3D.h>
#include <MultiRegions/ExpList2DHomogeneous1D.h>
#include <MultiRegions/ExpList3DHomogeneous1D.h>
#include <MultiRegions/ExpList3DHomogeneous2D.h>
#include <sys/stat.h>
Include dependency graph for FldToVtk.cpp:

Go to the source code of this file.

Functions

int fexist (const char *filename)
int main (int argc, char *argv[])

Function Documentation

int fexist ( const char *  filename)

Definition at line 15 of file FldToVtk.cpp.

{
struct stat buffer ;
if ( stat( filename, &buffer ) ) return 0 ;
return 1 ;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 21 of file FldToVtk.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::LibUtilities::ePolyEvenlySpaced, fexist(), Nektar::LibUtilities::Import(), and Nektar::SpatialDomains::MeshGraph::Read().

{
unsigned int i,j;
if(argc < 3)
{
fprintf(stderr,"Usage: FldToVtk meshfile fieldfile(s)\n");
exit(1);
}
int nExtraPoints;
= LibUtilities::SessionReader::CreateInstance(argc, argv);
vSession->LoadParameter("OutputExtraPoints", nExtraPoints,0);
//----------------------------------------------
// Read in mesh from input file
= SpatialDomains::MeshGraph::Read(vSession);
//----------------------------------------------
for (int n = 1; n < argc; ++n)
{
string fname = std::string(argv[n]);
if (fname.substr(fname.length() - 1, 1) == "/")
{
fname = fname.substr(0, fname.length() - 1);
}
int fdot = fname.find_last_of('.');
if (fdot != std::string::npos)
{
string ending = fname.substr(fdot);
// If .chk or .fld we exchange the extension in the output file.
// For all other files (e.g. .bse) we append the extension to avoid
// conflicts.
if (ending == ".chk" || ending == ".fld")
{
fname = fname.substr(0,fdot);
}
else if (ending == ".gz")
{
fname = fname.substr(0,fdot);
fdot = fname.find_last_of('.');
ASSERTL0(fdot != std::string::npos,
"Error: expected file extension before .gz.");
ending = fname.substr(fdot);
ASSERTL0(ending == ".xml",
"Compressed non-xml files are not supported.");
continue;
}
else if (ending == ".xml")
{
continue;
}
}
fname = fname + ".vtu";
if (argc > 3)
{
if (fexist(fname.c_str()))
{
cout << "Skipping converted file: " << argv[n] << endl;
continue;
}
cout << "Processing " << argv[n] << endl;
}
//----------------------------------------------
// Import field file.
string fieldfile(argv[n]);
vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
vector<vector<NekDouble> > fielddata;
LibUtilities::Import(fieldfile,fielddef,fielddata);
bool useFFT = false;
bool dealiasing = false;
//----------------------------------------------
//----------------------------------------------
// Set up Expansion information
for(i = 0; i < fielddef.size(); ++i)
{
vector<LibUtilities::PointsType> ptype;
for(j = 0; j < 3; ++j)
{
}
fielddef[i]->m_pointsDef = true;
fielddef[i]->m_points = ptype;
vector<unsigned int> porder;
if(fielddef[i]->m_numPointsDef == false)
{
for(j = 0; j < fielddef[i]->m_numModes.size(); ++j)
{
porder.push_back(fielddef[i]->m_numModes[j]+nExtraPoints);
}
fielddef[i]->m_numPointsDef = true;
}
else
{
for(j = 0; j < fielddef[i]->m_numPoints.size(); ++j)
{
porder.push_back(fielddef[i]->m_numPoints[j]+nExtraPoints);
}
}
fielddef[i]->m_numPoints = porder;
}
graphShPt->SetExpansions(fielddef);
//----------------------------------------------
//----------------------------------------------
// Define Expansion
int expdim = graphShPt->GetMeshDimension();
int nfields = fielddef[0]->m_fields.size();
Array<OneD, MultiRegions::ExpListSharedPtr> Exp(nfields);
switch(expdim)
{
case 1:
{
ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 2,"NumHomogeneousDir is only set up for 1 or 2");
if(fielddef[0]->m_numHomogeneousDir == 1)
{
// Define Homogeneous expansion
//int nplanes = fielddef[0]->m_numModes[1];
int nplanes;
vSession->LoadParameter("HomModesZ",nplanes,fielddef[0]->m_numModes[1]);
// choose points to be at evenly spaced points at
const LibUtilities::BasisKey Bkey(fielddef[0]->m_basis[1],nplanes,Pkey);
NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
Exp2DH1 = MemoryManager<MultiRegions::ExpList2DHomogeneous1D>::AllocateSharedPtr(vSession,Bkey,ly,useFFT,dealiasing,graphShPt);
for(i = 1; i < nfields; ++i)
{
}
}
else if(fielddef[0]->m_numHomogeneousDir == 2)
{
// Define Homogeneous expansion
//int nylines = fielddef[0]->m_numModes[1];
//int nzlines = fielddef[0]->m_numModes[2];
int nylines;
int nzlines;
vSession->LoadParameter("HomModesY",nylines,fielddef[0]->m_numModes[1]);
vSession->LoadParameter("HomModesZ",nzlines,fielddef[0]->m_numModes[2]);
// choose points to be at evenly spaced points at
const LibUtilities::BasisKey BkeyY(fielddef[0]->m_basis[1],nylines,PkeyY);
const LibUtilities::BasisKey BkeyZ(fielddef[0]->m_basis[2],nzlines,PkeyZ);
NekDouble ly = fielddef[0]->m_homogeneousLengths[0];
NekDouble lz = fielddef[0]->m_homogeneousLengths[1];
Exp3DH2 = MemoryManager<MultiRegions::ExpList3DHomogeneous2D>::AllocateSharedPtr(vSession,BkeyY,BkeyZ,ly,lz,useFFT,dealiasing,graphShPt);
Exp[0] = Exp3DH2;
for(i = 1; i < nfields; ++i)
{
}
}
else
{
::AllocateSharedPtr(vSession,graphShPt);
Exp[0] = Exp1D;
for(i = 1; i < nfields; ++i)
{
}
}
}
break;
case 2:
{
ASSERTL0(fielddef[0]->m_numHomogeneousDir <= 1,"NumHomogeneousDir is only set up for 1");
if(fielddef[0]->m_numHomogeneousDir == 1)
{
// Define Homogeneous expansion
//int nplanes = fielddef[0]->m_numModes[2];
int nplanes;
vSession->LoadParameter("HomModesZ",nplanes,fielddef[0]->m_numModes[2]);
// choose points to be at evenly spaced points at
// nplanes + 1 points
const LibUtilities::BasisKey Bkey(fielddef[0]->m_basis[2],nplanes,Pkey);
NekDouble lz = fielddef[0]->m_homogeneousLengths[0];
Exp3DH1 = MemoryManager<MultiRegions::ExpList3DHomogeneous1D>::AllocateSharedPtr(vSession,Bkey,lz,useFFT,dealiasing,graphShPt);
Exp[0] = Exp3DH1;
for(i = 1; i < nfields; ++i)
{
}
}
else
{
::AllocateSharedPtr(vSession,graphShPt);
Exp[0] = Exp2D;
for(i = 1; i < nfields; ++i)
{
}
}
}
break;
case 3:
{
::AllocateSharedPtr(vSession,graphShPt);
Exp[0] = Exp3D;
for(i = 1; i < nfields; ++i)
{
}
}
break;
default:
ASSERTL0(false,"Expansion dimension not recognised");
break;
}
//----------------------------------------------
//----------------------------------------------
// Copy data from field file
for(j = 0; j < nfields; ++j)
{
for(int i = 0; i < fielddata.size(); ++i)
{
Exp[j]->ExtractDataToCoeffs(fielddef [i],
fielddata[i],
fielddef [i]->m_fields[j],
Exp[j]->UpdateCoeffs());
}
Exp[j]->BwdTrans(Exp[j]->GetCoeffs(),Exp[j]->UpdatePhys());
}
//----------------------------------------------
//----------------------------------------------
// Write solution
//string outname(strtok(argv[n],"."));
//outname += ".vtu";
ofstream outfile(fname.c_str());
Exp[0]->WriteVtkHeader(outfile);
// For each field write out field data for each expansion.
for(i = 0; i < Exp[0]->GetNumElmts(); ++i)
{
Exp[0]->WriteVtkPieceHeader(outfile,i);
// For this expansion, write out each field.
for(j = 0; j < Exp.num_elements(); ++j)
{
Exp[j]->WriteVtkPieceData(outfile,i, fielddef[0]->m_fields[j]);
}
Exp[0]->WriteVtkPieceFooter(outfile,i);
}
Exp[0]->WriteVtkFooter(outfile);
cout << "Written file: " << fname << endl;
//----------------------------------------------
}
return 0;
}