Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /**
68  * @brief Replace a vertex in the element.
69  *
70  * When a vertex is replaced, the element edges and faces are also
71  * searched and the corresponding edge/face nodes are updated to
72  * maintain consistency.
73  *
74  * @param p Index of the vertex to replace.
75  * @param pNew New vertex.
76  */
77 void Element::SetVertex(unsigned int p, NodeSharedPtr pNew)
78 {
79  NodeSharedPtr vOld = m_vertex[p];
80  m_vertex[p] = pNew;
81  for (unsigned int i = 0; i < m_edge.size(); ++i)
82  {
83  if (m_edge[i]->m_n1 == vOld)
84  {
85  m_edge[i]->m_n1 = pNew;
86  }
87  else if (m_edge[i]->m_n2 == vOld)
88  {
89  m_edge[i]->m_n2 = pNew;
90  }
91  }
92  for (unsigned int i = 0; i < m_face.size(); ++i)
93  {
94  // Replace vertices in faces
95  for (unsigned int j = 0; j < m_face[i]->m_vertexList.size(); ++j)
96  {
97  if (m_face[i]->m_vertexList[j] == vOld)
98  {
99  m_face[i]->m_vertexList[j] = pNew;
100  }
101  }
102  for (unsigned int j = 0; j < m_face[i]->m_edgeList.size(); ++j)
103  {
104  if (m_face[i]->m_edgeList[j]->m_n1 == vOld)
105  {
106  m_face[i]->m_edgeList[j]->m_n1 = pNew;
107  }
108  else if (m_face[i]->m_edgeList[j]->m_n2 == vOld)
109  {
110  m_face[i]->m_edgeList[j]->m_n2 = pNew;
111  }
112  }
113  }
114 }
115 
116 /**
117  * @brief Replace an edge in the element.
118  *
119  * When an edge is replaced, the element faces are also searched and
120  * the corresponding face edges are updated to maintain consistency.
121  *
122  * @param p Index of the edge to replace.
123  * @param pNew New edge.
124  */
125 void Element::SetEdge(unsigned int p, EdgeSharedPtr pNew)
126 {
127  EdgeSharedPtr vOld = m_edge[p];
128  m_edge[p] = pNew;
129  for (unsigned int i = 0; i < m_face.size(); ++i)
130  {
131  for (unsigned int j = 0; j < m_face[i]->m_edgeList.size(); ++j)
132  {
133  if (m_face[i]->m_edgeList[j] == vOld)
134  {
135  m_face[i]->m_edgeList[j] = pNew;
136  }
137  }
138  }
139 }
140 
141 /**
142  * @brief Replace a face in the element.
143  *
144  * When a face is replaced, no other consistency checks are required.
145  *
146  * @param p Index of the face to replace.
147  * @param pNew New face.
148  */
149 void Element::SetFace(unsigned int p, FaceSharedPtr pNew)
150 {
151  m_face[p] = pNew;
152 }
153 
154 /**
155  * @brief Obtain the order of an element by looking at edges.
156  */
158 {
159  int i, ret = 1;
160 
161  for (i = 0; i < m_edge.size(); ++i)
162  {
163  int edgeOrder = m_edge[i]->GetNodeCount() - 1;
164  if (edgeOrder > ret)
165  {
166  ret = edgeOrder;
167  }
168  }
169 
170  return ret;
171 }
172 }
173 }
Basic information about an element.
Definition: Element.h:58
NEKMESHUTILS_EXPORT int GetMaxOrder()
Obtain the order of an element by looking at edges.
Definition: Element.cpp:157
STL namespace.
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
NEKMESHUTILS_EXPORT void SetFace(unsigned int p, FaceSharedPtr pNew)
Replace a face with another face object.
Definition: Element.cpp:149
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:63
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:502
NEKMESHUTILS_EXPORT void SetEdge(unsigned int p, EdgeSharedPtr pNew)
Replace an edge with another edge object.
Definition: Element.cpp:125
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:504
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:196
std::vector< FaceSharedPtr > m_face
List of element faces.
Definition: Element.h:506
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
Definition: Face.h:378
Nektar::LibUtilities::NekFactory< LibUtilities::ShapeType, Element, ElmtConfig, std::vector< NodeSharedPtr >, std::vector< int > > ElementFactory
Element factory definition.
Definition: Element.h:531
NEKMESHUTILS_EXPORT void SetVertex(unsigned int p, NodeSharedPtr pNew)
Replace a vertex with another vertex object.
Definition: Element.cpp:77
LibUtilities::ShapeType m_e
Element type (e.g. triangle, quad, etc).
Definition: Element.h:85
Provides a generic Factory class.
Definition: NekFactory.hpp:116