Nektar++
Element.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Element.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: Mesh element.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
36 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace NekMeshUtils
42 {
43 
45 {
46  static ElementFactory instance;
47  return instance;
48 }
49 
50 Element::Element(ElmtConfig pConf, unsigned int pNumNodes,
51  unsigned int pGotNodes)
52  : m_conf(pConf), m_curveType(LibUtilities::ePolyEvenlySpaced), m_geom()
53 {
54  if (pNumNodes != pGotNodes)
55  {
56  cerr << "Number of modes mismatch for type " << pConf.m_e
57  << "! Should be " << pNumNodes << " but got " << pGotNodes
58  << " nodes." << endl;
59  abort();
60  }
61 }
62 
63 void Element::SetVertex(unsigned int p, NodeSharedPtr pNew, bool descend)
64 {
65  NodeSharedPtr vOld = m_vertex[p];
66  m_vertex[p] = pNew;
67 
68  if (!descend)
69  {
70  return;
71  }
72 
73  for (unsigned int i = 0; i < m_edge.size(); ++i)
74  {
75  if (m_edge[i]->m_n1 == vOld)
76  {
77  m_edge[i]->m_n1 = pNew;
78  }
79  else if (m_edge[i]->m_n2 == vOld)
80  {
81  m_edge[i]->m_n2 = pNew;
82  }
83  }
84  for (unsigned int i = 0; i < m_face.size(); ++i)
85  {
86  // Replace vertices in faces
87  for (unsigned int j = 0; j < m_face[i]->m_vertexList.size(); ++j)
88  {
89  if (m_face[i]->m_vertexList[j] == vOld)
90  {
91  m_face[i]->m_vertexList[j] = pNew;
92  }
93  }
94  for (unsigned int j = 0; j < m_face[i]->m_edgeList.size(); ++j)
95  {
96  if (m_face[i]->m_edgeList[j]->m_n1 == vOld)
97  {
98  m_face[i]->m_edgeList[j]->m_n1 = pNew;
99  }
100  else if (m_face[i]->m_edgeList[j]->m_n2 == vOld)
101  {
102  m_face[i]->m_edgeList[j]->m_n2 = pNew;
103  }
104  }
105  }
106 }
107 
108 void Element::SetEdge(unsigned int p, EdgeSharedPtr pNew, bool descend)
109 {
110  EdgeSharedPtr vOld = m_edge[p];
111  m_edge[p] = pNew;
112 
113  if (!descend)
114  {
115  return;
116  }
117 
118  for (unsigned int i = 0; i < m_face.size(); ++i)
119  {
120  for (unsigned int j = 0; j < m_face[i]->m_edgeList.size(); ++j)
121  {
122  if (m_face[i]->m_edgeList[j] == vOld)
123  {
124  m_face[i]->m_edgeList[j] = pNew;
125  }
126  }
127  }
128 }
129 
130 void Element::SetFace(unsigned int p, FaceSharedPtr pNew)
131 {
132  m_face[p] = pNew;
133 }
134 
136 {
137  int i, ret = 1;
138 
139  for (i = 0; i < m_edge.size(); ++i)
140  {
141  int edgeOrder = m_edge[i]->GetNodeCount() - 1;
142  if (edgeOrder > ret)
143  {
144  ret = edgeOrder;
145  }
146  }
147 
148  return ret;
149 }
150 
151 unsigned int Element::GetNodeCount()
152 {
153  unsigned int n = m_volumeNodes.size();
154  if (m_dim == 1)
155  {
156  n += 2;
157  }
158  else if (m_dim == 2)
159  {
160  for (int i = 0; i < m_edge.size(); ++i)
161  {
162  n += m_edge[i]->GetNodeCount();
163  }
164  n -= m_vertex.size();
165  }
166  else
167  {
168  for (int i = 0; i < m_face.size(); ++i)
169  {
170  n += m_face[i]->GetNodeCount();
171  }
172  for (int i = 0; i < m_edge.size(); ++i)
173  {
174  n -= m_edge[i]->GetNodeCount();
175  }
176  n += m_vertex.size();
177  std::cerr << "Not supported." << std::endl;
178  exit(1);
179  }
180  return n;
181 }
182 
184 {
185  std::stringstream s;
186  switch (m_dim)
187  {
188  case 1:
189  for (int j = 0; j < m_vertex.size(); ++j)
190  {
191  s << std::setw(5) << m_vertex[j]->m_id << " ";
192  }
193  break;
194  case 2:
195  for (int j = 0; j < m_edge.size(); ++j)
196  {
197  s << std::setw(5) << m_edge[j]->m_id << " ";
198  }
199  break;
200  case 3:
201  for (int j = 0; j < m_face.size(); ++j)
202  {
203  s << std::setw(5) << m_face[j]->m_id << " ";
204  }
205  break;
206  }
207  return s.str();
208 }
209 
211 {
212  // Temporary node list for reordering
213  std::vector<NodeSharedPtr> nodeList;
214 
215  GetCurvedNodes(nodeList);
216 
217  // Finally generate the XML string corresponding to our new
218  // node reordering.
219  std::stringstream s;
220  std::string str;
221  for (int k = 0; k < nodeList.size(); ++k)
222  {
223  s << std::scientific << std::setprecision(8) << " "
224  << nodeList[k]->m_x << " " << nodeList[k]->m_y << " "
225  << nodeList[k]->m_z << " ";
226  }
227  return s.str();
228 }
229 
230 }
231 }
NEKMESHUTILS_EXPORT void SetEdge(unsigned int p, EdgeSharedPtr pNew, bool descend=true)
Replace an edge in the element.
Definition: Element.cpp:108
Basic information about an element.
Definition: ElementConfig.h:49
NEKMESHUTILS_EXPORT void SetFace(unsigned int p, FaceSharedPtr pNew)
Replace a face in the element.
Definition: Element.cpp:130
STL namespace.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
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
NEKMESHUTILS_EXPORT int GetMaxOrder()
Obtain the order of an element by looking at edges.
Definition: Element.cpp:135
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:468
unsigned int m_dim
Dimension of the element.
Definition: Element.h:460
NEKMESHUTILS_EXPORT std::string GetXmlCurveString()
Generates a string listing the coordinates of all nodes associated with this element.
Definition: Element.cpp:210
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:470
virtual NEKMESHUTILS_EXPORT void GetCurvedNodes(std::vector< NodeSharedPtr > &nodeList) const
get list of volume interior nodes
Definition: Element.h:265
std::vector< NodeSharedPtr > m_volumeNodes
List of element volume nodes.
Definition: Element.h:474
virtual NEKMESHUTILS_EXPORT std::string GetXmlString()
Generate a list of vertices (1D), edges (2D), or faces (3D).
Definition: Element.cpp:183
NEKMESHUTILS_EXPORT void SetVertex(unsigned int p, NodeSharedPtr pNew, bool descend=true)
Replace a vertex in the element.
Definition: Element.cpp:63
std::vector< FaceSharedPtr > m_face
List of element faces.
Definition: Element.h:472
LibUtilities::ShapeType m_e
Element type (e.g. triangle, quad, etc).
Definition: ElementConfig.h:78
NEKMESHUTILS_EXPORT unsigned int GetNodeCount()
Returns the total number of nodes (vertices, edge nodes and face nodes and volume nodes)...
Definition: Element.cpp:151
Provides a generic Factory class.
Definition: NekFactory.hpp:103