Nektar++
InputNekpp.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputNekpp.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: GMSH converter.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <string>
36 #include <iostream>
37 using namespace std;
38 
41 #include "InputNekpp.h"
42 
43 namespace Nektar
44 {
45 namespace Utilities
46 {
47 
48 using namespace Nektar::NekMeshUtils;
49 
50 ModuleKey InputNekpp::className =
52  InputNekpp::create,
53  "Reads Nektar++ xml file.");
54 /**
55  * @brief Set up InputNekpp object.
56  */
57 InputNekpp::InputNekpp(MeshSharedPtr m) : InputModule(m)
58 {
59 }
60 
62 {
63 }
64 
65 /**
66  *
67  */
69 {
70  vector<string> filename;
71  filename.push_back(m_config["infile"].as<string>());
72 
73  char *prgname = const_cast<char *>("NekMesh");
75  LibUtilities::SessionReader::CreateInstance(1, &prgname, filename);
78 
79  auto comm = pSession->GetComm();
80  if (comm->GetType().find("MPI") != std::string::npos)
81  {
82  m_mesh->m_comm = comm;
83  }
84 
85  m_mesh->m_expDim = graph->GetMeshDimension();
86  m_mesh->m_spaceDim = graph->GetSpaceDimension();
87 
88  // Copy vertices.
89  map<int, NodeSharedPtr> vIdMap;
90  for (auto &vit : graph->GetAllPointGeoms())
91  {
92  SpatialDomains::PointGeomSharedPtr vert = vit.second;
93  NodeSharedPtr n = std::make_shared<Node>(
94  vert->GetGlobalID(), (*vert)(0), (*vert)(1), (*vert)(2));
95  m_mesh->m_vertexSet.insert(n);
96  vIdMap[vert->GetVid()] = n;
97  }
98 
99  std::unordered_map<int, EdgeSharedPtr> eIdMap;
100  std::unordered_map<int, FaceSharedPtr> fIdMap;
101 
102  // Load up all edges from graph
103  {
104  for (auto &it : graph->GetAllSegGeoms())
105  {
106  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
107  it.first,
108  std::dynamic_pointer_cast<SpatialDomains::Geometry>(
109  it.second));
110 
111  // load up edge set in order of SegGeomMap;
112  vector<NodeSharedPtr> curve; // curved nodes if deformed
113  int id0 = it.second->GetVid(0);
114  int id1 = it.second->GetVid(1);
116  it.second->GetXmap()->GetPointsKeys()[0].GetPointsType();
117  EdgeSharedPtr ed = std::make_shared<Edge>(
118  vIdMap[id0], vIdMap[id1], curve, ptype);
119 
120  auto testIns = m_mesh->m_edgeSet.insert(ed);
121  (*(testIns.first))->m_id = it.second->GetGlobalID();
122  eIdMap[it.second->GetGlobalID()] = ed;
123  }
124  }
125 
126  // load up all faces from graph
127  {
128  for (auto &it : graph->GetAllTriGeoms())
129  {
130  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
131  it.first,
132  std::dynamic_pointer_cast<SpatialDomains::Geometry>(
133  it.second));
134 
135  vector<NodeSharedPtr> faceVertices;
136  vector<EdgeSharedPtr> faceEdges;
137  vector<NodeSharedPtr> faceNodes;
138 
139  for (int i = 0; i < 3; ++i)
140  {
141  faceVertices.push_back(vIdMap[it.second->GetVid(i)]);
142  faceEdges.push_back(eIdMap[it.second->GetEid(i)]);
143  }
144 
145  FaceSharedPtr fac = std::make_shared<Face>(
146  faceVertices, faceNodes, faceEdges,
148  auto testIns = m_mesh->m_faceSet.insert(fac);
149  (*(testIns.first))->m_id = it.second->GetGlobalID();
150  fIdMap[it.second->GetGlobalID()] = fac;
151  }
152 
153  for (auto &it : graph->GetAllQuadGeoms())
154  {
155  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
156  it.first,
157  std::dynamic_pointer_cast<SpatialDomains::Geometry>(
158  it.second));
159 
160  vector<NodeSharedPtr> faceVertices;
161  vector<EdgeSharedPtr> faceEdges;
162  vector<NodeSharedPtr> faceNodes;
163 
164  for (int i = 0; i < 4; ++i)
165  {
166  faceVertices.push_back(vIdMap[it.second->GetVid(i)]);
167  faceEdges.push_back(eIdMap[it.second->GetEid(i)]);
168  }
169 
170  FaceSharedPtr fac = std::make_shared<Face>(
171  faceVertices, faceNodes, faceEdges,
173  auto testIns = m_mesh->m_faceSet.insert(fac);
174  (*(testIns.first))->m_id = it.second->GetGlobalID();
175  fIdMap[it.second->GetGlobalID()] = fac;
176  }
177  }
178 
179  // Set up curved information
180 
181  // Curved Edges
182  for (auto &it : graph->GetCurvedEdges())
183  {
184  SpatialDomains::CurveSharedPtr curve = it.second;
185  int id = curve->m_curveID;
186  ASSERTL1(eIdMap.find(id) != eIdMap.end(), "Failed to find curved edge");
187  EdgeSharedPtr edg = eIdMap[id];
188  edg->m_curveType = curve->m_ptype;
189  for (int j = 0; j < curve->m_points.size() - 2; ++j)
190  {
191  edg->m_edgeNodes.push_back(
192  std::make_shared<Node>(
193  j,
194  (*curve->m_points[j + 1])(0),
195  (*curve->m_points[j + 1])(1),
196  (*curve->m_points[j + 1])(2)));
197  }
198  }
199 
200  // Curved Faces
201  for (auto &it : graph->GetCurvedFaces())
202  {
203  SpatialDomains::CurveSharedPtr curve = it.second;
204  int id = curve->m_curveID;
205  ASSERTL1(fIdMap.find(id) != fIdMap.end(), "Failed to find curved edge");
206  FaceSharedPtr fac = fIdMap[id];
207  fac->m_curveType = curve->m_ptype;
208  int Ntot = curve->m_points.size();
209 
210  if (fac->m_curveType == LibUtilities::eNodalTriFekete ||
211  fac->m_curveType == LibUtilities::eNodalTriEvenlySpaced ||
212  fac->m_curveType == LibUtilities::eNodalTriElec)
213  {
214  int N = ((int)sqrt(8.0 * Ntot + 1.0) - 1) / 2;
215  for (int j = 3 + 3 * (N - 2); j < Ntot; ++j)
216  {
217  fac->m_faceNodes.push_back(
218  std::make_shared<Node>(
219  j,
220  (*curve->m_points[j])(0),
221  (*curve->m_points[j])(1),
222  (*curve->m_points[j])(2)));
223  }
224  }
225  else // quad face.
226  {
227  int N = (int)sqrt((double)Ntot);
228 
229  for (int j = 1; j < N - 1; ++j)
230  {
231  for (int k = 1; k < N - 1; ++k)
232  {
233  fac->m_faceNodes.push_back(
234  std::make_shared<Node>(
235  (j - 1) * (N - 2) + k - 1,
236  (*curve->m_points[j * N + k])(0),
237  (*curve->m_points[j * N + k])(1),
238  (*curve->m_points[j * N + k])(2)));
239  }
240  }
241  }
242  }
243 
244  // Get hold of mesh composites and set up m_mesh->m_elements. Loop over all
245  // composites and set up elements with edges and faces from the maps above.
246  for (auto &compIt : graph->GetComposites())
247  {
248  // Get hold of dimension
249  int dim = compIt.second->m_geomVec[0]->GetShapeDim();
250 
251  // compIt->second is a GeometryVector
252  for (auto &geomIt : compIt.second->m_geomVec)
253  {
254  ElmtConfig conf(geomIt->GetShapeType(), 1, true, true, false);
255 
256  // Get hold of geometry
257  vector<NodeSharedPtr> nodeList;
258  for (int i = 0; i < geomIt->GetNumVerts(); ++i)
259  {
260  nodeList.push_back(vIdMap[geomIt->GetVid(i)]);
261  }
262 
263  vector<int> tags;
264  tags.push_back(compIt.first);
265 
267  geomIt->GetShapeType(), conf, nodeList, tags);
268 
269  E->SetId(geomIt->GetGlobalID());
270  m_mesh->m_element[dim].push_back(E);
271 
272  if (dim == 1)
273  {
274  EdgeSharedPtr edg = eIdMap[geomIt->GetGlobalID()];
275  E->SetVolumeNodes(edg->m_edgeNodes);
276  E->SetCurveType(edg->m_curveType);
277  }
278 
279  if (dim > 1)
280  {
281  // reset edges
282  for (int i = 0; i < geomIt->GetNumEdges(); ++i)
283  {
284  EdgeSharedPtr edg = eIdMap[geomIt->GetEid(i)];
285  E->SetEdge(i, edg);
286  // set up link back to this element
287  edg->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
288  }
289 
290  if (dim == 2)
291  {
292  FaceSharedPtr fac = fIdMap[geomIt->GetGlobalID()];
293  E->SetVolumeNodes(fac->m_faceNodes);
294  E->SetCurveType(fac->m_curveType);
295  }
296  }
297 
298  if (dim == 3)
299  {
300  // reset faces
301  for (int i = 0; i < geomIt->GetNumFaces(); ++i)
302  {
303  FaceSharedPtr fac = fIdMap[geomIt->GetFid(i)];
304  E->SetFace(i, fac);
305  // set up link back to this slement
306  fac->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
307  }
308  }
309  }
310  }
311 
312  // set up composite labels if they exist
313  m_mesh->m_faceLabels = graph->GetCompositesLabels();
314 
315  ProcessEdges(false);
316  ProcessFaces(false);
318 }
319 }
320 }
Basic information about an element.
Definition: ElementConfig.h:49
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
STL namespace.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:156
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:155
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:64
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::pair< ModuleType, std::string > ModuleKey
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
std::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
std::map< std::string, ConfigOption > m_config
List of configuration values.
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:59
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:70
Abstract base class for input modules.
std::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:61
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:71
std::pair< ModuleType, std::string > ModuleKey
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SessionReader > SessionReaderSharedPtr
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, DomainRangeShPtr rng=NullDomainRangeShPtr, bool fillGraph=true)
Definition: MeshGraph.cpp:113
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:69
ModuleFactory & GetModuleFactory()