Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 (NekMeshUtils::MeshSharedPtr m)
 
virtual ~InputSwan ()
 
virtual void Process ()
 Populate and validate required data structures. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::InputModule
NEKMESHUTILS_EXPORT InputModule (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void OpenStream ()
 Open a file for input. More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT Module (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void RegisterConfig (std::string key, std::string value)
 Register a configuration option with a module. More...
 
NEKMESHUTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
NEKMESHUTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
NEKMESHUTILS_EXPORT MeshSharedPtr GetMesh ()
 
virtual NEKMESHUTILS_EXPORT void ProcessVertices ()
 Extract element vertices. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessElements ()
 Generate element IDs. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessComposites ()
 Generate composites. More...
 
virtual NEKMESHUTILS_EXPORT void ClearElementLinks ()
 

Static Public Member Functions

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

Static Public Attributes

static NekMeshUtils::ModuleKey className
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::NekMeshUtils::InputModule
NEKMESHUTILS_EXPORT void PrintSummary ()
 Print summary of elements. More...
 
- Protected Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
NEKMESHUTILS_EXPORT void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::NekMeshUtils::InputModule
io::filtering_istream m_mshFile
 Input stream. More...
 
std::ifstream m_mshFileStream
 Input stream. More...
 
- Protected Attributes inherited from Nektar::NekMeshUtils::Module
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

Converter for Swansea mesh format.

Definition at line 47 of file InputSwan.h.

Constructor & Destructor Documentation

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

Definition at line 52 of file InputSwan.cpp.

52  : InputModule(m)
53 {
54 }
NEKMESHUTILS_EXPORT InputModule(MeshSharedPtr p_m)
Nektar::Utilities::InputSwan::~InputSwan ( )
virtual

Definition at line 56 of file InputSwan.cpp.

57 {
58 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 51 of file InputSwan.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::Utilities::InputSwan::Process ( )
virtual

Populate and validate required data structures.

Implements Nektar::NekMeshUtils::Module.

Definition at line 60 of file InputSwan.cpp.

References Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, Nektar::NekMeshUtils::GetElementFactory(), Nektar::NekMeshUtils::Module::m_mesh, Nektar::NekMeshUtils::InputModule::m_mshFile, class_topology::Node, Nektar::NekMeshUtils::InputModule::OpenStream(), Nektar::NekMeshUtils::Module::ProcessComposites(), Nektar::NekMeshUtils::Module::ProcessEdges(), Nektar::NekMeshUtils::Module::ProcessElements(), Nektar::NekMeshUtils::Module::ProcessFaces(), and Nektar::NekMeshUtils::Module::ProcessVertices().

61 {
62  // Open the file stream.
63  OpenStream();
64 
65  vector<vector<NodeSharedPtr> > elementList;
66  vector<int> tmp, tets;
67  vector<double> pts;
68 
69  if (m_mesh->m_verbose)
70  {
71  cout << "InputSwan: Start reading file..." << endl;
72  }
73 
74  m_mesh->m_expDim = 3;
75  m_mesh->m_spaceDim = 3;
76 
77  // First read in header; 4 integers containing number of tets,
78  // number of points, nas2 (unknown) and order of the grid
79  // (i.e. GridOrder = 3 => cubic mesh).
80  tmp.resize(6);
81  m_mshFile.read(reinterpret_cast<char *>(&tmp[0]),
82  static_cast<int>(6 * sizeof(int)));
83 
84  if (tmp[0] != tmp[5] || tmp[0] != 4 * sizeof(int))
85  {
86  cout << "Header data broken" << endl;
87  m_mshFile.reset();
88  return;
89  }
90 
91  int NB_Tet = tmp[1];
92  int NB_Points = tmp[2];
93  int GridOrder = tmp[4];
94  int ND = (GridOrder + 1) * (GridOrder + 2) * (GridOrder + 3) / 6;
95 
96  cout << "NB_Tet = " << NB_Tet << endl;
97  cout << "NB_Points = " << NB_Points << endl;
98  cout << "GridOrder = " << GridOrder << endl;
99  cout << "ND = " << ND << endl;
100 
101  // Now read in list of tetrahedra. Each tet has ND points, and
102  // data are ordered with memory traversed fastest with point
103  // number.
104  tets.resize(ND * NB_Tet + 2);
105  m_mshFile.read(reinterpret_cast<char *>(&tets[0]),
106  static_cast<int>((ND * NB_Tet + 2) * sizeof(int)));
107 
108  if (tets[0] != tets[ND * NB_Tet + 1] ||
109  tets[0] != ND * NB_Tet * sizeof(int))
110  {
111  cout << "ERROR [InputSwan]: Tetrahedron data broken." << endl;
112  m_mshFile.reset();
113  return;
114  }
115 
116  // Finally, read point data: NB_Points tuples (x,y,z).
117  tmp.resize(2);
118  pts.resize(3 * NB_Points);
119  m_mshFile.read(reinterpret_cast<char *>(&tmp[0]),
120  static_cast<int>(sizeof(int)));
121  m_mshFile.read(reinterpret_cast<char *>(&pts[0]),
122  static_cast<int>(3 * NB_Points * sizeof(double)));
123  m_mshFile.read(reinterpret_cast<char *>(&tmp[1]),
124  static_cast<int>(sizeof(int)));
125 
126  if (tmp[0] != tmp[1] || tmp[0] != 3 * NB_Points * sizeof(double))
127  {
128  cout << "ERROR [InputSwan]: Point data broken." << endl;
129  m_mshFile.reset();
130  return;
131  }
132 
133  int vid = 0, i, j;
135 
136  // Read in list of vertices.
137  for (i = 0; i < NB_Points; ++i)
138  {
139  double x = pts[i];
140  double y = pts[1 * NB_Points + i];
141  double z = pts[2 * NB_Points + i];
142  m_mesh->m_node.push_back(
143  boost::shared_ptr<Node>(new Node(vid, x, y, z)));
144  vid++;
145  }
146 
147  // Iterate over list of tetrahedra: for each, create nodes. At the
148  // moment discard high order data and create linear mesh.
149  for (i = 0; i < NB_Tet; ++i)
150  {
151  vector<NodeSharedPtr> nodeList;
152  for (j = 0; j < 20; ++j)
153  {
154  int vid = tets[j * NB_Tet + i + 1];
155  nodeList.push_back(m_mesh->m_node[vid - 1]);
156  }
157 
158  vector<int> tags;
159  tags.push_back(0); // composite
160  tags.push_back(elType); // element type
161 
162  ElmtConfig conf(elType, 3, true, true);
163  ElementSharedPtr E =
164  GetElementFactory().CreateInstance(elType, conf, nodeList, tags);
165  m_mesh->m_element[3].push_back(E);
166  }
167 
168  // Attempt to read in composites. Need to determine number of
169  // triangles from data.
170  tmp.resize(2);
171  m_mshFile.read(reinterpret_cast<char *>(&tmp[0]),
172  static_cast<int>(sizeof(int)));
173  int n_tri = tmp[0] / sizeof(int) / 5;
174  tets.resize(n_tri * 5);
175  m_mshFile.read(reinterpret_cast<char *>(&tets[0]),
176  static_cast<int>(tmp[0]));
177  m_mshFile.read(reinterpret_cast<char *>(&tmp[1]),
178  static_cast<int>(sizeof(int)));
179 
180  if (tmp[0] != tmp[1])
181  {
182  cout << "ERROR [InputSwan]: Surface data broken." << endl;
183  m_mshFile.reset();
184  return;
185  }
186 
187  elType = LibUtilities::eTriangle;
188 
189  // Process list of triangles forming surfaces.
190  for (i = 0; i < n_tri; ++i)
191  {
192  vector<NodeSharedPtr> nodeList;
193 
194  for (j = 0; j < 3; ++j)
195  {
196  nodeList.push_back(m_mesh->m_node[tets[i + j * n_tri] - 1]);
197  }
198 
199  vector<int> tags;
200  tags.push_back(1); // composite
201  tags.push_back(elType); // element type
202 
203  ElmtConfig conf(elType, 1, false, false);
204  ElementSharedPtr E =
205  GetElementFactory().CreateInstance(elType, conf, nodeList, tags);
206  m_mesh->m_element[2].push_back(E);
207  }
208 
209  m_mshFile.reset();
210 
211  // Process the rest of the mesh.
212  ProcessVertices();
213  ProcessEdges();
214  ProcessFaces();
215  ProcessElements();
217 }
Basic information about an element.
Definition: ElementConfig.h:50
io::filtering_istream m_mshFile
Input stream.
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
NEKMESHUTILS_EXPORT void OpenStream()
Open a file for input.
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.

Member Data Documentation

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

Definition at line 55 of file InputSwan.h.