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