Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: GMSH converter.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
42 #include "InputNekpp.h"
43 
44 namespace Nektar
45 {
46 namespace Utilities
47 {
48 
49 using namespace Nektar::NekMeshUtils;
50 
51 ModuleKey InputNekpp::className =
53  InputNekpp::create,
54  "Reads Nektar++ xml file.");
55 /**
56  * @brief Set up InputNekpp object.
57  */
58 InputNekpp::InputNekpp(MeshSharedPtr m) : InputModule(m)
59 {
60 }
61 
63 {
64 }
65 
66 /**
67  *
68  */
70 {
71  vector<string> filename;
72  filename.push_back(m_config["infile"].as<string>());
73 
78 
79  m_mesh->m_expDim = graph->GetMeshDimension();
80  m_mesh->m_spaceDim = graph->GetSpaceDimension();
81 
82  // Copy vertices.
83  map<int, NodeSharedPtr> vIdMap;
84  const SpatialDomains::PointGeomMap vertset = graph->GetVertSet();
85  SpatialDomains::PointGeomMap::const_iterator vit;
86 
87  for (vit = vertset.begin(); vit != vertset.end(); ++vit)
88  {
89  SpatialDomains::PointGeomSharedPtr vert = vit->second;
90  NodeSharedPtr n(
91  new Node(vert->GetVid(), (*vert)(0), (*vert)(1), (*vert)(2)));
92  m_mesh->m_vertexSet.insert(n);
93  vIdMap[vert->GetVid()] = n;
94  }
95 
96  map<int, EdgeSharedPtr> eIdMap;
98  map<int, FaceSharedPtr> fIdMap;
100 
101  // Load up all edges from graph
102  {
103  int nel = 0;
104  SpatialDomains::SegGeomMap tmp = graph->GetAllSegGeoms();
106  pair<EdgeSet::iterator, bool> testIns;
107  nel += tmp.size();
108 
109  for (it = tmp.begin(); it != tmp.end(); ++it)
110  {
111  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
112  it->first,
113  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
114  it->second));
115 
116  // load up edge set in order of SegGeomMap;
117  vector<NodeSharedPtr> curve; // curved nodes if deformed
118  int id0 = it->second->GetVid(0);
119  int id1 = it->second->GetVid(1);
121  it->second->GetPointsKeys()[0].GetPointsType();
122  EdgeSharedPtr ed =
123  EdgeSharedPtr(new Edge(vIdMap[id0], vIdMap[id1], curve, ptype));
124 
125  testIns = m_mesh->m_edgeSet.insert(ed);
126  (*(testIns.first))->m_id = it->second->GetEid();
127  eIdMap[it->second->GetEid()] = ed;
128  }
129  }
130 
131  // load up all faces from graph
132  {
133  int nel = 0;
134  SpatialDomains::TriGeomMap tmp = graph->GetAllTriGeoms();
136  pair<FaceSet::iterator, bool> testIns;
137  nel += tmp.size();
138 
139  for (it = tmp.begin(); it != tmp.end(); ++it)
140  {
141  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
142  it->first,
143  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
144  it->second));
145 
146  vector<NodeSharedPtr> faceVertices;
147  vector<EdgeSharedPtr> faceEdges;
148  vector<NodeSharedPtr> faceNodes;
149 
150  for (int i = 0; i < 3; ++i)
151  {
152  faceVertices.push_back(vIdMap[it->second->GetVid(i)]);
153  faceEdges.push_back(eIdMap[it->second->GetEid(i)]);
154  }
155 
156  FaceSharedPtr fac =
157  FaceSharedPtr(new Face(faceVertices,
158  faceNodes,
159  faceEdges,
161  testIns = m_mesh->m_faceSet.insert(fac);
162  (*(testIns.first))->m_id = it->second->GetFid();
163  fIdMap[it->second->GetFid()] = fac;
164  }
165 
166  SpatialDomains::QuadGeomMap tmp3 = graph->GetAllQuadGeoms();
168 
169  for (it2 = tmp3.begin(); it2 != tmp3.end(); ++it2)
170  {
171  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
172  it2->first,
173  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
174  it2->second));
175 
176  vector<NodeSharedPtr> faceVertices;
177  vector<EdgeSharedPtr> faceEdges;
178  vector<NodeSharedPtr> faceNodes;
179 
180  for (int i = 0; i < 4; ++i)
181  {
182  faceVertices.push_back(vIdMap[it2->second->GetVid(i)]);
183  faceEdges.push_back(eIdMap[it2->second->GetEid(i)]);
184  }
185 
186  FaceSharedPtr fac =
187  FaceSharedPtr(new Face(faceVertices,
188  faceNodes,
189  faceEdges,
191  testIns = m_mesh->m_faceSet.insert(fac);
192  (*(testIns.first))->m_id = it2->second->GetFid();
193  fIdMap[it2->second->GetFid()] = fac;
194  }
195  }
196 
197  // Set up curved information
198 
199  // Curved Edges
200  SpatialDomains::CurveMap &curvedEdges = graph->GetCurvedEdges();
202 
203  for (it = curvedEdges.begin(); it != curvedEdges.end(); ++it)
204  {
205  SpatialDomains::CurveSharedPtr curve = it->second;
206  int id = curve->m_curveID;
207  ASSERTL1(eIdMap.find(id) != eIdMap.end(), "Failed to find curved edge");
208  EdgeSharedPtr edg = eIdMap[id];
209  edg->m_curveType = curve->m_ptype;
210  for (int j = 0; j < curve->m_points.size() - 2; ++j)
211  {
212  NodeSharedPtr n(new Node(j,
213  (*curve->m_points[j + 1])(0),
214  (*curve->m_points[j + 1])(1),
215  (*curve->m_points[j + 1])(2)));
216  edg->m_edgeNodes.push_back(n);
217  }
218  }
219 
220  // Curved Faces
221  SpatialDomains::CurveMap &curvedFaces = graph->GetCurvedFaces();
222  for (it = curvedFaces.begin(); it != curvedFaces.end(); ++it)
223  {
224  SpatialDomains::CurveSharedPtr curve = it->second;
225  int id = curve->m_curveID;
226  ASSERTL1(fIdMap.find(id) != fIdMap.end(), "Failed to find curved edge");
227  FaceSharedPtr fac = fIdMap[id];
228  fac->m_curveType = curve->m_ptype;
229  int Ntot = curve->m_points.size();
230 
231  if (fac->m_curveType == LibUtilities::eNodalTriFekete ||
232  fac->m_curveType == LibUtilities::eNodalTriEvenlySpaced ||
233  fac->m_curveType == LibUtilities::eNodalTriElec)
234  {
235  int N = ((int)sqrt(8.0 * Ntot + 1.0) - 1) / 2;
236  for (int j = 3 + 3 * (N - 2); j < Ntot; ++j)
237  {
238  NodeSharedPtr n(new Node(j,
239  (*curve->m_points[j])(0),
240  (*curve->m_points[j])(1),
241  (*curve->m_points[j])(2)));
242  fac->m_faceNodes.push_back(n);
243  }
244  }
245  else // quad face.
246  {
247  int N = (int)sqrt((double)Ntot);
248 
249  for (int j = 1; j < N - 1; ++j)
250  {
251  for (int k = 1; k < N - 1; ++k)
252  {
253  NodeSharedPtr n(new Node((j - 1) * (N - 2) + k - 1,
254  (*curve->m_points[j * N + k])(0),
255  (*curve->m_points[j * N + k])(1),
256  (*curve->m_points[j * N + k])(2)));
257  fac->m_faceNodes.push_back(n);
258  }
259  }
260  }
261  }
262 
263  // Get hold of mesh composites and set up m_mesh->m_elements
264  SpatialDomains::CompositeMap GraphComps = graph->GetComposites();
267 
268  // loop over all composites and set up elements with edges
269  // and faces from the maps above.
270  for (compIt = GraphComps.begin(); compIt != GraphComps.end(); ++compIt)
271  {
272  // Get hold of dimension
273  int dim = (*compIt->second)[0]->GetShapeDim();
274 
275  // compIt->second is a GeometryVector
276  for (geomIt = (*compIt->second).begin();
277  geomIt != (*compIt->second).end();
278  ++geomIt)
279  {
280  ElmtConfig conf((*geomIt)->GetShapeType(), 1, true, true, false);
281 
282  // Get hold of geometry
283  vector<NodeSharedPtr> nodeList;
284  for (int i = 0; i < (*geomIt)->GetNumVerts(); ++i)
285  {
286  nodeList.push_back(vIdMap[(*geomIt)->GetVid(i)]);
287  }
288 
289  vector<int> tags;
290  tags.push_back(compIt->first);
291 
293  (*geomIt)->GetShapeType(), conf, nodeList, tags);
294 
295  E->SetId((*geomIt)->GetGlobalID());
296  m_mesh->m_element[dim].push_back(E);
297 
298  if (dim == 1)
299  {
300  EdgeSharedPtr edg = eIdMap[(*geomIt)->GetGlobalID()];
301  E->SetVolumeNodes(edg->m_edgeNodes);
302  }
303 
304  if (dim > 1)
305  {
306  // reset edges
307  for (int i = 0; i < (*geomIt)->GetNumEdges(); ++i)
308  {
309  EdgeSharedPtr edg = eIdMap[(*geomIt)->GetEid(i)];
310  E->SetEdge(i, edg);
311  // set up link back to this element
312  edg->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
313  }
314 
315  if (dim == 2)
316  {
317  FaceSharedPtr fac = fIdMap[(*geomIt)->GetGlobalID()];
318  E->SetVolumeNodes(fac->m_faceNodes);
319  }
320  }
321 
322  if (dim == 3)
323  {
324  // reset faces
325  for (int i = 0; i < (*geomIt)->GetNumFaces(); ++i)
326  {
327  FaceSharedPtr fac = fIdMap[(*geomIt)->GetFid(i)];
328  E->SetFace(i, fac);
329  // set up link back to this slement
330  fac->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
331  }
332  }
333  }
334  }
335 
336  // set up composite labels if they exist
337  m_mesh->m_faceLabels = graph->GetCompositesLabels();
338 
339  ProcessEdges(false);
340  ProcessFaces(false);
342 }
343 }
344 }
Basic information about an element.
Definition: ElementConfig.h:50
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
Represents an edge which joins two points.
Definition: Edge.h:58
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:124
Represents a face comprised of three or more edges.
Definition: Face.h:61
STL namespace.
pair< ModuleType, string > ModuleKey
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
boost::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:62
std::vector< GeometrySharedPtr >::iterator GeometryVectorIter
Definition: Geometry.h:58
std::map< int, TriGeomSharedPtr > TriGeomMap
Definition: TriGeom.h:62
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:65
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::map< int, PointGeomSharedPtr > PointGeomMap
Definition: MeshGraph.h:111
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
std::map< int, SegGeomSharedPtr > SegGeomMap
Definition: SegGeom.h:54
std::map< int, Composite >::iterator CompositeMapIter
Definition: MeshGraph.h:116
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
std::map< std::string, ConfigOption > m_config
List of configuration values.
std::map< int, Composite > CompositeMap
Definition: MeshGraph.h:115
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:71
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:135
Abstract base class for input modules.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:147
std::map< int, QuadGeomSharedPtr > QuadGeomMap
Definition: QuadGeom.h:57
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::unordered_map< int, CurveSharedPtr > CurveMap
Definition: Curve.hpp:63
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:72
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
boost::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:148
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:228
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:70
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215