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

Converter for Swansea mesh format. More...

#include <InputSwan.h>

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

Public Member Functions

 InputSwan (MeshSharedPtr m)
virtual ~InputSwan ()
virtual void Process ()
 Populate and validate required data structures.
- Public Member Functions inherited from Nektar::Utilities::InputModule
 InputModule (FieldSharedPtr p_m)
void AddFile (string fileType, string fileName)
 InputModule (MeshSharedPtr p_m)
void OpenStream ()
 Open a file for input.
- 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

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::InputModule
void PrintSummary ()
 Print summary of elements.
void PrintSummary ()
 Print summary of elements.
- Protected Attributes inherited from Nektar::Utilities::InputModule
set< string > m_allowedFiles
std::ifstream m_mshFile
 Input stream.

Detailed Description

Converter for Swansea mesh format.

Definition at line 46 of file InputSwan.h.

Constructor & Destructor Documentation

Nektar::Utilities::InputSwan::InputSwan ( MeshSharedPtr  m)

Definition at line 51 of file InputSwan.cpp.

{
}
Nektar::Utilities::InputSwan::~InputSwan ( )
virtual

Definition at line 56 of file InputSwan.cpp.

{
}

Member Function Documentation

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

Creates an instance of this class.

Definition at line 50 of file InputSwan.h.

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

Populate and validate required data structures.

Implements Nektar::Utilities::Module.

Definition at line 61 of file InputSwan.cpp.

References Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, Nektar::Utilities::GetElementFactory(), Nektar::Utilities::Module::m_mesh, Nektar::Utilities::InputModule::m_mshFile, Nektar::Utilities::InputModule::OpenStream(), Nektar::Utilities::Module::ProcessComposites(), Nektar::Utilities::Module::ProcessEdges(), Nektar::Utilities::Module::ProcessElements(), Nektar::Utilities::Module::ProcessFaces(), and Nektar::Utilities::Module::ProcessVertices().

{
// Open the file stream.
vector<vector<NodeSharedPtr> > elementList;
vector<int> tmp, tets;
vector<double> pts;
if (m_mesh->m_verbose)
{
cout << "InputSwan: Start reading file..." << endl;
}
m_mesh->m_expDim = 3;
m_mesh->m_spaceDim = 3;
// First read in header; 4 integers containing number of tets,
// number of points, nas2 (unknown) and order of the grid
// (i.e. GridOrder = 3 => cubic mesh).
tmp.resize(6);
m_mshFile.read(reinterpret_cast<char*>(&tmp[0]),
static_cast<int> (6*sizeof(int)));
if (tmp[0] != tmp[5] || tmp[0] != 4*sizeof(int))
{
cout << "Header data broken" << endl;
m_mshFile.close();
return;
}
int NB_Tet = tmp[1];
int NB_Points = tmp[2];
int GridOrder = tmp[4];
int ND = (GridOrder+1)*(GridOrder+2)*(GridOrder+3)/6;
cout << "NB_Tet = " << NB_Tet << endl;
cout << "NB_Points = " << NB_Points << endl;
cout << "GridOrder = " << GridOrder << endl;
cout << "ND = " << ND << endl;
// Now read in list of tetrahedra. Each tet has ND points, and
// data are ordered with memory traversed fastest with point
// number.
tets.resize(ND*NB_Tet+2);
m_mshFile.read(reinterpret_cast<char*>(&tets[0]),
static_cast<int> ((ND*NB_Tet+2)*sizeof(int)));
if (tets[0] != tets[ND*NB_Tet+1] || tets[0] != ND*NB_Tet*sizeof(int))
{
cout << "ERROR [InputSwan]: Tetrahedron data broken." << endl;
m_mshFile.close();
return;
}
// Finally, read point data: NB_Points tuples (x,y,z).
tmp.resize(2);
pts.resize(3*NB_Points);
m_mshFile.read(reinterpret_cast<char*>(&tmp[0]),
static_cast<int> (sizeof(int)));
m_mshFile.read(reinterpret_cast<char*>(&pts[0]),
static_cast<int> (3*NB_Points*sizeof(double)));
m_mshFile.read(reinterpret_cast<char*>(&tmp[1]),
static_cast<int> (sizeof(int)));
if (tmp[0] != tmp[1] || tmp[0] != 3*NB_Points*sizeof(double))
{
cout << "ERROR [InputSwan]: Point data broken." << endl;
m_mshFile.close();
return;
}
int vid = 0, i, j;
// Read in list of vertices.
for (i = 0; i < NB_Points; ++i)
{
double x = pts [ i];
double y = pts [1*NB_Points+i];
double z = pts [2*NB_Points+i];
m_mesh->m_node.push_back(boost::shared_ptr<Node>(new Node(vid, x, y, z)));
vid++;
}
// Iterate over list of tetrahedra: for each, create nodes. At the
// moment discard high order data and create linear mesh.
for (i = 0; i < NB_Tet; ++i)
{
vector<NodeSharedPtr> nodeList;
for (j = 0; j < 20; ++j)
{
int vid = tets[j*NB_Tet+i+1];
nodeList.push_back(m_mesh->m_node[vid-1]);
}
vector<int> tags;
tags.push_back(0); // composite
tags.push_back(elType); // element type
ElmtConfig conf(elType,3,true,true);
CreateInstance(elType,conf,nodeList,tags);
m_mesh->m_element[3].push_back(E);
}
// Attempt to read in composites. Need to determine number of
// triangles from data.
tmp.resize(2);
m_mshFile.read(reinterpret_cast<char*>(&tmp[0]),
static_cast<int> (sizeof(int)));
int n_tri = tmp[0]/sizeof(int)/5;
tets.resize(n_tri*5);
m_mshFile.read(reinterpret_cast<char*>(&tets[0]),
static_cast<int> (tmp[0]));
m_mshFile.read(reinterpret_cast<char*>(&tmp[1]),
static_cast<int> (sizeof(int)));
if (tmp[0] != tmp[1])
{
cout << "ERROR [InputSwan]: Surface data broken." << endl;
m_mshFile.close();
return;
}
// Process list of triangles forming surfaces.
for (i = 0; i < n_tri; ++i)
{
vector<NodeSharedPtr> nodeList;
for (j = 0; j < 3; ++j)
{
nodeList.push_back(m_mesh->m_node[tets[i+j*n_tri]-1]);
}
vector<int> tags;
tags.push_back(1); // composite
tags.push_back(elType); // element type
ElmtConfig conf(elType,1,false,false);
CreateInstance(elType,conf,nodeList,tags);
m_mesh->m_element[2].push_back(E);
}
m_mshFile.close();
// Process the rest of the mesh.
}

Member Data Documentation

ModuleKey Nektar::Utilities::InputSwan::className
static
Initial value:
"Reads Swansea plt format for third-order tetrahedra.")

Definition at line 53 of file InputSwan.h.