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 
41 
42 #include "MeshElements.h"
43 #include "InputNekpp.h"
44 
45 namespace Nektar
46 {
47  namespace Utilities
48  {
49  ModuleKey InputNekpp::className =
51  ModuleKey(eInputModule, "xml"), InputNekpp::create,
52  "Reads Nektar++ xml file.");
53 
54  /**
55  * @brief Set up InputNekpp object.
56  */
57  InputNekpp::InputNekpp(MeshSharedPtr m) : InputModule(m)
58  {
59 
60  }
61 
63  {
64 
65  }
66 
67  /**
68  * Gmsh file contains a list of nodes and their coordinates, along with
69  * a list of elements and those nodes which define them. We read in and
70  * store the list of nodes in #m_node and store the list of elements in
71  * #m_element. Each new element is supplied with a list of entries from
72  * #m_node which defines the element. Finally some mesh statistics are
73  * printed.
74  *
75  * @param pFilename Filename of Gmsh file to read.
76  */
78  {
79  vector<string> filename;
80  filename.push_back(m_config["infile"].as<string>());
81 
86 
87  m_mesh->m_expDim = graph->GetMeshDimension ();
88  m_mesh->m_spaceDim = graph->GetSpaceDimension();
89 
90  // Copy vertices.
91  map<int, NodeSharedPtr> vIdMap;
92  int nVerts = graph->GetNvertices();
93  for (int i = 0; i < nVerts; ++i)
94  {
96  graph->GetVertex(i);
97  NodeSharedPtr n(new Node(vert->GetVid(),
98  (*vert)(0), (*vert)(1), (*vert)(2)));
99  m_mesh->m_vertexSet.insert(n);
100  vIdMap[vert->GetVid()] = n;
101  }
102 
103  map<int, EdgeSharedPtr> eIdMap;
105  map<int, FaceSharedPtr> fIdMap;
107 
108  // Load up all edges from graph
109  {
110  int nel = 0;
111  SpatialDomains::SegGeomMap tmp = graph->GetAllSegGeoms();
113  pair<EdgeSet::iterator,bool> testIns;
114  nel += tmp.size();
115 
116  for (it = tmp.begin(); it != tmp.end(); ++it)
117  {
118  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
119  it->first, boost::dynamic_pointer_cast<
120  SpatialDomains::Geometry>(it->second));
121 
122  // load up edge set in order of SegGeomMap;
123  vector<NodeSharedPtr> curve; // curved nodes if deformed
124  int id0 = it->second->GetVid(0);
125  int id1 = it->second->GetVid(1);
126  LibUtilities::PointsType ptype = it->second->GetPointsKeys()[0].GetPointsType();
127  EdgeSharedPtr ed = EdgeSharedPtr(new Edge(vIdMap[id0], vIdMap[id1],
128  curve, ptype));
129 
130  testIns = m_mesh->m_edgeSet.insert(ed);
131  (*(testIns.first))->m_id = it->second->GetEid();
132  eIdMap[it->second->GetEid()] = ed;
133  }
134  }
135 
136 
137  // load up all faces from graph
138  {
139  int nel = 0;
140  SpatialDomains::TriGeomMap tmp = graph->GetAllTriGeoms();
142  pair<FaceSet::iterator,bool> testIns;
143  nel += tmp.size();
144 
145  for (it = tmp.begin(); it != tmp.end(); ++it)
146  {
147  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
148  it->first, boost::dynamic_pointer_cast<
149  SpatialDomains::Geometry>(it->second));
150 
151  vector<NodeSharedPtr> faceVertices;
152  vector<EdgeSharedPtr> faceEdges;
153  vector<NodeSharedPtr> faceNodes;
154 
155  for(int i = 0; i < 3; ++i)
156  {
157  faceVertices.push_back(vIdMap[it->second->GetVid(i)]);
158  faceEdges.push_back(eIdMap[it->second->GetEid(i)]);
159  }
160 
161  FaceSharedPtr fac = FaceSharedPtr( new Face(faceVertices,faceNodes,faceEdges,
163  testIns = m_mesh->m_faceSet.insert(fac);
164  (*(testIns.first))->m_id = it->second->GetFid();
165  fIdMap[it->second->GetFid()] = fac;
166  }
167 
168  SpatialDomains::QuadGeomMap tmp3 = graph->GetAllQuadGeoms();
170 
171  for (it2 = tmp3.begin(); it2 != tmp3.end(); ++it2)
172  {
173  pair<int, SpatialDomains::GeometrySharedPtr> tmp2(
174  it2->first, boost::dynamic_pointer_cast<
175  SpatialDomains::Geometry>(it2->second));
176 
177  vector<NodeSharedPtr> faceVertices;
178  vector<EdgeSharedPtr> faceEdges;
179  vector<NodeSharedPtr> faceNodes;
180 
181  for(int i = 0; i < 4; ++i)
182  {
183  faceVertices.push_back(vIdMap[it2->second->GetVid(i)]);
184  faceEdges.push_back(eIdMap[it2->second->GetEid(i)]);
185  }
186 
187  FaceSharedPtr fac = FaceSharedPtr( new Face(faceVertices,faceNodes,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::CurveVector cvec = graph->GetCurvedEdges();
199 
200  for(int i = 0; i < cvec.size(); ++i)
201  {
202  int id = cvec[i]->m_curveID;
203  ASSERTL1(eIdMap.find(id) != eIdMap.end(),"Failed to find curved edge");
204  EdgeSharedPtr edg = eIdMap[id];
205  edg->m_curveType = cvec[i]->m_ptype;
206  for(int j = 0; j < cvec[i]->m_points.size()-2; ++j)
207  {
208  NodeSharedPtr n(new Node(j, (*cvec[i]->m_points[j+1])(0),
209  (*cvec[i]->m_points[j+1])(1),
210  (*cvec[i]->m_points[j+1])(2)));
211  edg->m_edgeNodes.push_back(n);
212  }
213  }
214 
215  // Curved Faces
216  cvec = graph->GetCurvedFaces();
217 
218  for(int i = 0; i < cvec.size(); ++i)
219  {
220  int id = cvec[i]->m_curveID;
221  ASSERTL1(fIdMap.find(id) != fIdMap.end(),"Failed to find curved edge");
222  FaceSharedPtr fac = fIdMap[id];
223  fac->m_curveType = cvec[i]->m_ptype;
224  int Ntot = cvec[i]->m_points.size();
225 
226 
227  if (fac->m_curveType == LibUtilities::eNodalTriFekete ||
228  fac->m_curveType == LibUtilities::eNodalTriEvenlySpaced ||
229  fac->m_curveType == LibUtilities::eNodalTriElec)
230  {
231  int N = ((int)sqrt(8.0*Ntot+1.0)-1)/2;
232  for(int j = 3+3*(N-2); j < Ntot; ++j)
233  {
234  NodeSharedPtr n(new Node(j, (*cvec[i]->m_points[j])(0),
235  (*cvec[i]->m_points[j])(1),
236  (*cvec[i]->m_points[j])(2)));
237  fac->m_faceNodes.push_back(n);
238  }
239  }
240  else // quad face.
241  {
242  int N = (int)sqrt((double)Ntot);
243  for(int j = 1; j < N-1; ++j)
244  {
245  for(int k = 1; k < N-1; ++k)
246  {
247  NodeSharedPtr n(new Node((j-1)*(N-2)+k-1,
248  (*cvec[i]->m_points[j*N+k])(0),
249  (*cvec[i]->m_points[j*N+k])(1),
250  (*cvec[i]->m_points[j*N+k])(2)));
251  fac->m_faceNodes.push_back(n);
252  }
253  }
254  }
255  }
256 
257 
258  // Get hold of mesh composites and set up m_mesh->m_elements
259 
260  SpatialDomains::CompositeMap GraphComps= graph->GetComposites();
263 
264 
265  // calculate the number of element of dimension
266  // m_mesh->m_expDim in composite list so we can set up
267  // element vector of this size to allow for
268  // non-consecutive insertion to list (Might consider
269  // setting element up as a map)?
270  int nel = 0;
271  for(compIt = GraphComps.begin(); compIt != GraphComps.end(); ++compIt)
272  {
273  // Get hold of dimension
274  int dim = (*compIt->second)[0]->GetShapeDim();
275 
276  if(dim == m_mesh->m_expDim)
277  {
278  nel += (*compIt->second).size();
279  }
280  }
281  m_mesh->m_element[m_mesh->m_expDim].resize(nel);
282 
283  // loop over all composites and set up elements with edges and faces from the maps above.
284  for(compIt = GraphComps.begin(); compIt != GraphComps.end(); ++compIt)
285  {
286  // Get hold of dimension
287  int dim = (*compIt->second)[0]->GetShapeDim();
288 
289  // compIt->second is a GeometryVector
290  for(geomIt = (*compIt->second).begin();
291  geomIt != (*compIt->second).end();
292  ++geomIt)
293  {
294  ElmtConfig conf((*geomIt)->GetShapeType(),1,true,true);
295 
296  // Get hold of geometry
297  vector<NodeSharedPtr> nodeList;
298  for (int i = 0; i < (*geomIt)->GetNumVerts(); ++i)
299  {
300  nodeList.push_back(vIdMap[(*geomIt)->GetVid(i)]);
301  }
302 
303  vector<int> tags;
304  tags.push_back(compIt->first);
305 
307  CreateInstance((*geomIt)->GetShapeType(),conf,nodeList,tags);
308 
309  E->SetId((*geomIt)->GetGlobalID());
310 
311  if(dim == m_mesh->m_expDim) // load mesh into location baded on globalID
312  {
313  m_mesh->m_element[dim][(*geomIt)->GetGlobalID()] = E;
314  }
315  else // push onto vector for later usage as composite region
316  {
317  m_mesh->m_element[dim].push_back(E);
318  }
319 
320  if(dim > 1)
321  {
322  // reset edges
323  for (int i = 0; i < (*geomIt)->GetNumEdges(); ++i)
324  {
325  EdgeSharedPtr edg = eIdMap[(*geomIt)->GetEid(i)];
326  E->SetEdge(i,edg);
327  // set up link back to this element
328  edg->m_elLink.push_back(pair<ElementSharedPtr,int>(E,i));
329  }
330  }
331 
332  if(dim == 3)
333  {
334  // reset faces
335  for (int i = 0; i < (*geomIt)->GetNumFaces(); ++i)
336  {
337  FaceSharedPtr fac = fIdMap[(*geomIt)->GetFid(i)];
338  E->SetFace(i,fac);
339  // set up link back to this slement
340  fac->m_elLink.push_back(pair<ElementSharedPtr,int>(E,i));
341  }
342  }
343  }
344  }
345  ProcessEdges(false);
346  ProcessFaces(false);
348  }
349  }
350 }