Nektar++
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:
[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=std::string())
 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 std::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, ConfigOptionm_config
 List of configuration values. More...
 

Detailed Description

Converter for Swansea mesh format.

Definition at line 46 of file InputSwan.h.

Constructor & Destructor Documentation

◆ InputSwan()

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

Definition at line 51 of file InputSwan.cpp.

51  : InputModule(m)
52 {
53 }
NEKMESHUTILS_EXPORT InputModule(MeshSharedPtr p_m)

◆ ~InputSwan()

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

Definition at line 55 of file InputSwan.cpp.

56 {
57 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 50 of file InputSwan.h.

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

51  {
53  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ Process()

void Nektar::Utilities::InputSwan::Process ( )
virtual

Populate and validate required data structures.

Implements Nektar::NekMeshUtils::Module.

Definition at line 59 of file InputSwan.cpp.

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::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().

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

Member Data Documentation

◆ className

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

Definition at line 54 of file InputSwan.h.