Nektar++
Triangle.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Triangle.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 triangle object.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
36 #include <LocalRegions/TriExp.h>
38 
40 
41 using namespace std;
42 
43 namespace Nektar
44 {
45 namespace NekMeshUtils
46 {
47 
48 LibUtilities::ShapeType Triangle::m_type =
50  LibUtilities::eTriangle, Triangle::create, "Triangle");
51 
52 /**
53  * @brief Create a triangle element.
54  */
55 Triangle::Triangle(ElmtConfig pConf,
56  vector<NodeSharedPtr> pNodeList,
57  vector<int> pTagList)
58  : Element(pConf, GetNumNodes(pConf), pNodeList.size())
59 {
60  m_tag = "T";
61  m_dim = 2;
62  m_taglist = pTagList;
64  int n = m_conf.m_order - 1;
65 
66  // Create a map to relate edge nodes to a pair of vertices
67  // defining an edge. This is based on the ordering produced by
68  // gmsh.
69  map<pair<int, int>, int> edgeNodeMap;
70  map<pair<int, int>, int>::iterator it;
71  edgeNodeMap[pair<int, int>(1, 2)] = 4;
72  edgeNodeMap[pair<int, int>(2, 3)] = 4 + n;
73  edgeNodeMap[pair<int, int>(3, 1)] = 4 + 2 * n;
74 
75  // Add vertices. This logic will determine (in 2D) whether the
76  // element is clockwise (sum > 0) or counter-clockwise (sum < 0).
77  NekDouble sum = 0.0;
78  for (int i = 0; i < 3; ++i)
79  {
80  int o = (i + 1) % 3;
81  m_vertex.push_back(pNodeList[i]);
82  sum += (pNodeList[o]->m_x - pNodeList[i]->m_x) *
83  (pNodeList[o]->m_y + pNodeList[i]->m_y);
84  }
85 
86  // Create edges (with corresponding set of edge points)
87  for (it = edgeNodeMap.begin(); it != edgeNodeMap.end(); ++it)
88  {
89  vector<NodeSharedPtr> edgeNodes;
90  if (m_conf.m_order > 1)
91  {
92  for (int j = it->second; j < it->second + n; ++j)
93  {
94  edgeNodes.push_back(pNodeList[j - 1]);
95  }
96  }
97  m_edge.push_back(EdgeSharedPtr(new Edge(pNodeList[it->first.first - 1],
98  pNodeList[it->first.second - 1],
99  edgeNodes,
101  }
102 
103  if (pConf.m_reorient)
104  {
105  if (sum > 0.0)
106  {
107  swap(m_vertex[1], m_vertex[2]);
108  reverse(m_edge.begin(), m_edge.end());
109  }
110  }
111 
112  if (m_conf.m_faceNodes)
113  {
114  m_volumeNodes.insert(m_volumeNodes.begin(),
115  pNodeList.begin() + 3 * m_conf.m_order,
116  pNodeList.end());
117  }
118 }
119 
121 {
124 
125  for (int i = 0; i < 3; ++i)
126  {
127  edges[i] = m_edge[i]->GetGeom(coordDim);
128  }
129 
131  m_id, edges);
132  ret->Setup();
133 
134  return ret;
135 }
136 
138 {
139  int locVert = edgeId;
140  if (edge->m_n1 == m_vertex[locVert])
141  {
142  return StdRegions::eForwards;
143  }
144  else if (edge->m_n2 == m_vertex[locVert])
145  {
146  return StdRegions::eBackwards;
147  }
148  else
149  {
150  ASSERTL1(false, "Edge is not connected to this triangle.");
151  }
152 
154 }
155 
156 /**
157  * @brief Return the number of nodes defining a triangle.
158  */
160 {
161  int n = pConf.m_order;
162  if (!pConf.m_faceNodes)
163  return (n + 1) + 2 * (n - 1) + 1;
164  else
165  return (n + 1) * (n + 2) / 2;
166 }
167 
168 void Triangle::GetCurvedNodes(std::vector<NodeSharedPtr> &nodeList) const
169 {
170  int n = m_edge[0]->GetNodeCount();
171  nodeList.resize(n * (n + 1) / 2);
172 
173  // Populate nodelist
174  std::copy(m_vertex.begin(), m_vertex.end(), nodeList.begin());
175  for (int i = 0; i < 3; ++i)
176  {
177  std::copy(m_edge[i]->m_edgeNodes.begin(),
178  m_edge[i]->m_edgeNodes.end(),
179  nodeList.begin() + 3 + i * (n - 2));
180  if (m_edge[i]->m_n1 != m_vertex[i])
181  {
182  // If edge orientation is reversed relative to node ordering, we
183  // need to reverse order of nodes.
184  std::reverse(nodeList.begin() + 3 + i * (n - 2),
185  nodeList.begin() + 3 + (i + 1) * (n - 2));
186  }
187  }
188 
189  // Copy volume nodes.
190  std::copy(m_volumeNodes.begin(),
191  m_volumeNodes.end(),
192  nodeList.begin() + 3 * (n - 1));
193 }
194 
195 void Triangle::MakeOrder(int order,
198  int coordDim,
199  int &id,
200  bool justConfig)
201 
202 {
203  m_conf.m_order = order;
204  m_curveType = pType;
205  m_conf.m_volumeNodes = false;
206  m_volumeNodes.clear();
207 
208  // Triangles of order < 3 have no interior volume points.
209  if (order == 1 || order == 2)
210  {
211  m_conf.m_faceNodes = false;
212  return;
213  }
214 
215  m_conf.m_faceNodes = true;
216 
217  if (justConfig)
218  {
219  return;
220  }
221 
222  int nPoints = order + 1;
223  StdRegions::StdExpansionSharedPtr xmap = geom->GetXmap();
224 
225  Array<OneD, NekDouble> px, py;
226  LibUtilities::PointsKey pKey(nPoints, pType);
227  ASSERTL1(pKey.GetPointsDim() == 2, "Points distribution must be 2D");
228  LibUtilities::PointsManager()[pKey]->GetPoints(px, py);
229 
230  Array<OneD, Array<OneD, NekDouble> > phys(coordDim);
231 
232  for (int i = 0; i < coordDim; ++i)
233  {
234  phys[i] = Array<OneD, NekDouble>(xmap->GetTotPoints());
235  xmap->BwdTrans(geom->GetCoeffs(i), phys[i]);
236  }
237 
238  const int nTriPts = nPoints * (nPoints + 1) / 2;
239  const int nTriIntPts = (nPoints - 3) * (nPoints - 2) / 2;
240  m_volumeNodes.resize(nTriIntPts);
241 
242  for (int i = 3 + 3*(nPoints-2), cnt = 0; i < nTriPts; ++i, ++cnt)
243  {
245  xp[0] = px[i];
246  xp[1] = py[i];
247 
248  Array<OneD, NekDouble> x(3, 0.0);
249  for (int j = 0; j < coordDim; ++j)
250  {
251  x[j] = xmap->PhysEvaluate(xp, phys[j]);
252  }
253 
254  m_volumeNodes[cnt] = std::shared_ptr<Node>(
255  new Node(id++, x[0], x[1], x[2]));
256  }
257 
258  m_conf.m_order = order;
259  m_conf.m_faceNodes = true;
260  m_conf.m_volumeNodes = false;
261 }
262 
264 {
265  Array<OneD, NekDouble> ret(3,0.0);
266 
267  ret[0] = (m_vertex[1]->m_y - m_vertex[0]->m_y) * (m_vertex[2]->m_z - m_vertex[0]->m_z) -
268  (m_vertex[1]->m_z - m_vertex[0]->m_z) * (m_vertex[2]->m_y - m_vertex[0]->m_y);
269  ret[1] = (m_vertex[1]->m_z - m_vertex[0]->m_z) * (m_vertex[2]->m_x - m_vertex[0]->m_x) -
270  (m_vertex[1]->m_x - m_vertex[0]->m_x) * (m_vertex[2]->m_z - m_vertex[0]->m_z);
271  ret[2] = (m_vertex[1]->m_x - m_vertex[0]->m_x) * (m_vertex[2]->m_y - m_vertex[0]->m_y) -
272  (m_vertex[1]->m_y - m_vertex[0]->m_y) * (m_vertex[2]->m_x - m_vertex[0]->m_x);
273 
274  NekDouble mt = ret[0] * ret[0] + ret[1] * ret[1] + ret[2] * ret[2];
275  mt = sqrt(mt);
276 
277  ret[0] /= mt;
278  ret[1] /= mt;
279  ret[2] /= mt;
280 
281  if(m_parentCAD)
282  {
283  //has cad so can orientate based on that
284  if(m_parentCAD->Orientation() == CADOrientation::eBackwards)
285  {
286  ret[0] *= -1.0;
287  ret[1] *= -1.0;
288  ret[2] *= -1.0;
289  }
290 
291  //by default normals point outwards so if we want inward for BLs
292  if(inward)
293  {
294  ret[0] *= -1.0;
295  ret[1] *= -1.0;
296  ret[2] *= -1.0;
297  }
298  }
299  return ret;
300 }
301 
302 }
303 }
bool m_faceNodes
Denotes whether the element contains face nodes. For 2D elements, if this is true then the element co...
Definition: ElementConfig.h:81
CADObjectSharedPtr m_parentCAD
Definition: Element.h:454
Basic information about an element.
Definition: ElementConfig.h:49
Represents an edge which joins two points.
Definition: Edge.h:58
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Triangle.cpp:120
STL namespace.
unsigned int GetPointsDim() const
Definition: Points.h:150
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
def copy(self)
Definition: pycml.py:2663
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
ElmtConfig m_conf
Contains configuration of the element.
Definition: Element.h:462
virtual NEKMESHUTILS_EXPORT void MakeOrder(int order, SpatialDomains::GeometrySharedPtr geom, LibUtilities::PointsType pType, int coordDim, int &id, bool justConfig=false)
Insert interior (i.e. volume) points into this element to make the geometry an order order representa...
Definition: Triangle.cpp:195
std::vector< int > m_taglist
List of integers specifying properties of the element.
Definition: Element.h:466
LibUtilities::PointsType m_edgeCurveType
Distribution of points in edges.
Definition: ElementConfig.h:93
unsigned int m_order
Order of the element.
Definition: ElementConfig.h:88
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
std::vector< NodeSharedPtr > m_vertex
List of element vertex nodes.
Definition: Element.h:468
std::shared_ptr< TriGeom > TriGeomSharedPtr
Definition: TriGeom.h:58
unsigned int m_dim
Dimension of the element.
Definition: Element.h:460
bool m_volumeNodes
Denotes whether the element contains volume (i.e. interior) nodes. These are not supported by either ...
Definition: ElementConfig.h:86
std::vector< EdgeSharedPtr > m_edge
List of element edges.
Definition: Element.h:470
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
virtual NEKMESHUTILS_EXPORT void GetCurvedNodes(std::vector< NodeSharedPtr > &nodeList) const
get list of volume interior nodes
Definition: Triangle.cpp:168
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a triangle.
Definition: Triangle.cpp:159
Defines a specification for a set of points.
Definition: Points.h:59
double NekDouble
std::vector< NodeSharedPtr > m_volumeNodes
List of element volume nodes.
Definition: Element.h:474
std::string m_tag
Tag character describing the element.
Definition: Element.h:464
unsigned int m_id
ID of the element.
Definition: Element.h:458
virtual NEKMESHUTILS_EXPORT StdRegions::Orientation GetEdgeOrient(int edgeId, EdgeSharedPtr edge)
Get the edge orientation of edge with respect to the local element, which lies at edge index edgeId...
Definition: Triangle.cpp:137
LibUtilities::PointsType m_curveType
Volume curve type.
Definition: Element.h:476
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
bool m_reorient
Denotes whether the element needs to be re-orientated for a spectral element framework.
Definition: ElementConfig.h:91
NEKMESHUTILS_EXPORT Array< OneD, NekDouble > Normal(bool inward=false)
returns the normal to the element
Definition: Triangle.cpp:263
2D Evenly-spaced points on a Triangle
Definition: PointsType.h:71
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:62
Base class for element definitions.
Definition: Element.h:60