Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 ModuleKey InputNekpp::className =
50  InputNekpp::create,
51  "Reads Nektar++ xml file.");
52 
53 /**
54  * @brief Set up InputNekpp object.
55  */
56 InputNekpp::InputNekpp(MeshSharedPtr m) : InputModule(m)
57 {
58 }
59 
61 {
62 }
63 
64 /**
65  *
66  */
68 {
69  vector<string> filename;
70  filename.push_back(m_config["infile"].as<string>());
71 
76 
77  m_mesh->m_expDim = graph->GetMeshDimension();
78  m_mesh->m_spaceDim = graph->GetSpaceDimension();
79 
80  // Copy vertices.
81  map<int, NodeSharedPtr> vIdMap;
82  const SpatialDomains::PointGeomMap vertset = graph->GetVertSet();
83  SpatialDomains::PointGeomMap::const_iterator vit;
84 
85  for (vit = vertset.begin(); vit != vertset.end(); ++vit)
86  {
88  NodeSharedPtr n(
89  new Node(vert->GetVid(), (*vert)(0), (*vert)(1), (*vert)(2)));
90  m_mesh->m_vertexSet.insert(n);
91  vIdMap[vert->GetVid()] = n;
92  }
93 
94  map<int, EdgeSharedPtr> eIdMap;
96  map<int, FaceSharedPtr> fIdMap;
98 
99  // Load up all edges from graph
100  {
101  int nel = 0;
102  SpatialDomains::SegGeomMap tmp = graph->GetAllSegGeoms();
104  pair<EdgeSet::iterator, bool> testIns;
105  nel += tmp.size();
106 
107  for (it = tmp.begin(); it != tmp.end(); ++it)
108  {
109  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
110  it->first,
111  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
112  it->second));
113 
114  // load up edge set in order of SegGeomMap;
115  vector<NodeSharedPtr> curve; // curved nodes if deformed
116  int id0 = it->second->GetVid(0);
117  int id1 = it->second->GetVid(1);
119  it->second->GetPointsKeys()[0].GetPointsType();
120  EdgeSharedPtr ed =
121  EdgeSharedPtr(new Edge(vIdMap[id0], vIdMap[id1], curve, ptype));
122 
123  testIns = m_mesh->m_edgeSet.insert(ed);
124  (*(testIns.first))->m_id = it->second->GetEid();
125  eIdMap[it->second->GetEid()] = ed;
126  }
127  }
128 
129  // load up all faces from graph
130  {
131  int nel = 0;
132  SpatialDomains::TriGeomMap tmp = graph->GetAllTriGeoms();
134  pair<FaceSet::iterator, bool> testIns;
135  nel += tmp.size();
136 
137  for (it = tmp.begin(); it != tmp.end(); ++it)
138  {
139  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
140  it->first,
141  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
142  it->second));
143 
144  vector<NodeSharedPtr> faceVertices;
145  vector<EdgeSharedPtr> faceEdges;
146  vector<NodeSharedPtr> faceNodes;
147 
148  for (int i = 0; i < 3; ++i)
149  {
150  faceVertices.push_back(vIdMap[it->second->GetVid(i)]);
151  faceEdges.push_back(eIdMap[it->second->GetEid(i)]);
152  }
153 
154  FaceSharedPtr fac =
155  FaceSharedPtr(new Face(faceVertices,
156  faceNodes,
157  faceEdges,
159  testIns = m_mesh->m_faceSet.insert(fac);
160  (*(testIns.first))->m_id = it->second->GetFid();
161  fIdMap[it->second->GetFid()] = fac;
162  }
163 
164  SpatialDomains::QuadGeomMap tmp3 = graph->GetAllQuadGeoms();
166 
167  for (it2 = tmp3.begin(); it2 != tmp3.end(); ++it2)
168  {
169  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
170  it2->first,
171  boost::dynamic_pointer_cast<SpatialDomains::Geometry>(
172  it2->second));
173 
174  vector<NodeSharedPtr> faceVertices;
175  vector<EdgeSharedPtr> faceEdges;
176  vector<NodeSharedPtr> faceNodes;
177 
178  for (int i = 0; i < 4; ++i)
179  {
180  faceVertices.push_back(vIdMap[it2->second->GetVid(i)]);
181  faceEdges.push_back(eIdMap[it2->second->GetEid(i)]);
182  }
183 
184  FaceSharedPtr fac =
185  FaceSharedPtr(new Face(faceVertices,
186  faceNodes,
187  faceEdges,
189  testIns = m_mesh->m_faceSet.insert(fac);
190  (*(testIns.first))->m_id = it2->second->GetFid();
191  fIdMap[it2->second->GetFid()] = fac;
192  }
193  }
194 
195  // Set up curved information
196 
197  // Curved Edges
198  SpatialDomains::CurveMap &curvedEdges = graph->GetCurvedEdges();
200 
201  for (it = curvedEdges.begin(); it != curvedEdges.end(); ++it)
202  {
204  int id = curve->m_curveID;
205  ASSERTL1(eIdMap.find(id) != eIdMap.end(), "Failed to find curved edge");
206  EdgeSharedPtr edg = eIdMap[id];
207  edg->m_curveType = curve->m_ptype;
208  for (int j = 0; j < curve->m_points.size() - 2; ++j)
209  {
210  NodeSharedPtr n(new Node(j,
211  (*curve->m_points[j + 1])(0),
212  (*curve->m_points[j + 1])(1),
213  (*curve->m_points[j + 1])(2)));
214  edg->m_edgeNodes.push_back(n);
215  }
216  }
217 
218  // Curved Faces
219  SpatialDomains::CurveMap &curvedFaces = graph->GetCurvedFaces();
220  for (it = curvedFaces.begin(); it != curvedFaces.end(); ++it)
221  {
223  int id = curve->m_curveID;
224  ASSERTL1(fIdMap.find(id) != fIdMap.end(), "Failed to find curved edge");
225  FaceSharedPtr fac = fIdMap[id];
226  fac->m_curveType = curve->m_ptype;
227  int Ntot = curve->m_points.size();
228 
229  if (fac->m_curveType == LibUtilities::eNodalTriFekete ||
230  fac->m_curveType == LibUtilities::eNodalTriEvenlySpaced ||
231  fac->m_curveType == LibUtilities::eNodalTriElec)
232  {
233  int N = ((int)sqrt(8.0 * Ntot + 1.0) - 1) / 2;
234  for (int j = 3 + 3 * (N - 2); j < Ntot; ++j)
235  {
236  NodeSharedPtr n(new Node(j,
237  (*curve->m_points[j])(0),
238  (*curve->m_points[j])(1),
239  (*curve->m_points[j])(2)));
240  fac->m_faceNodes.push_back(n);
241  }
242  }
243  else // quad face.
244  {
245  int N = (int)sqrt((double)Ntot);
246 
247  for (int j = 1; j < N - 1; ++j)
248  {
249  for (int k = 1; k < N - 1; ++k)
250  {
251  NodeSharedPtr n(new Node((j - 1) * (N - 2) + k - 1,
252  (*curve->m_points[j * N + k])(0),
253  (*curve->m_points[j * N + k])(1),
254  (*curve->m_points[j * N + k])(2)));
255  fac->m_faceNodes.push_back(n);
256  }
257  }
258  }
259  }
260 
261  // Get hold of mesh composites and set up m_mesh->m_elements
262  SpatialDomains::CompositeMap GraphComps = graph->GetComposites();
265 
266  // loop over all composites and set up elements with edges
267  // and faces from the maps above.
268  for (compIt = GraphComps.begin(); compIt != GraphComps.end(); ++compIt)
269  {
270  // Get hold of dimension
271  int dim = (*compIt->second)[0]->GetShapeDim();
272 
273  // compIt->second is a GeometryVector
274  for (geomIt = (*compIt->second).begin();
275  geomIt != (*compIt->second).end();
276  ++geomIt)
277  {
278  ElmtConfig conf((*geomIt)->GetShapeType(), 1, true, true, false);
279 
280  // Get hold of geometry
281  vector<NodeSharedPtr> nodeList;
282  for (int i = 0; i < (*geomIt)->GetNumVerts(); ++i)
283  {
284  nodeList.push_back(vIdMap[(*geomIt)->GetVid(i)]);
285  }
286 
287  vector<int> tags;
288  tags.push_back(compIt->first);
289 
291  (*geomIt)->GetShapeType(), conf, nodeList, tags);
292 
293  E->SetId((*geomIt)->GetGlobalID());
294  m_mesh->m_element[dim].push_back(E);
295 
296  if (dim == 1)
297  {
298  EdgeSharedPtr edg = eIdMap[(*geomIt)->GetGlobalID()];
299  E->SetVolumeNodes(edg->m_edgeNodes);
300  }
301 
302  if (dim > 1)
303  {
304  // reset edges
305  for (int i = 0; i < (*geomIt)->GetNumEdges(); ++i)
306  {
307  EdgeSharedPtr edg = eIdMap[(*geomIt)->GetEid(i)];
308  E->SetEdge(i, edg);
309  // set up link back to this element
310  edg->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
311  }
312 
313  if (dim == 2)
314  {
315  FaceSharedPtr fac = fIdMap[(*geomIt)->GetGlobalID()];
316  E->SetVolumeNodes(fac->m_faceNodes);
317  }
318  }
319 
320  if (dim == 3)
321  {
322  // reset faces
323  for (int i = 0; i < (*geomIt)->GetNumFaces(); ++i)
324  {
325  FaceSharedPtr fac = fIdMap[(*geomIt)->GetFid(i)];
326  E->SetFace(i, fac);
327  // set up link back to this slement
328  fac->m_elLink.push_back(pair<ElementSharedPtr, int>(E, i));
329  }
330  }
331  }
332  }
333 
334  // set up composite labels if they exist
335  m_mesh->m_faceLabels = graph->GetCompositesLabels();
336 
337  ProcessEdges(false);
338  ProcessFaces(false);
340 }
341 }
342 }
Basic information about an element.
Definition: Element.h:58
pair< ModuleType, string > ModuleKey
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:61
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:121
Represents a face comprised of three or more edges.
Definition: Face.h:60
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
Represents a point in the domain.
Definition: Node.h:60
boost::shared_ptr< Curve > CurveSharedPtr
Definition: Curve.hpp:62
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
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:63
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::map< int, PointGeomSharedPtr > PointGeomMap
Definition: MeshGraph.h:111
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
virtual void ProcessComposites()
Generate composites.
std::map< int, Composite > CompositeMap
Definition: MeshGraph.h:115
2D Nodal Fekete Points on a Triangle
Definition: PointsType.h:69
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:196
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:137
std::map< int, QuadGeomSharedPtr > QuadGeomMap
Definition: QuadGeom.h:57
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
boost::unordered_map< int, CurveSharedPtr > CurveMap
Definition: Curve.hpp:63
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:70
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:52
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
Definition: Face.h:378
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:442
boost::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:60
2D Nodal Electrostatic Points on a Triangle
Definition: PointsType.h:68
ModuleFactory & GetModuleFactory()
Abstract base class for input modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215