Nektar++
Quadrilateral.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Quadrilateral.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 quad object.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <LocalRegions/QuadExp.h>
37 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace NekMeshUtils
45 {
46 
47 LibUtilities::ShapeType Quadrilateral::m_type =
49  LibUtilities::eQuadrilateral, Quadrilateral::create, "Quadrilateral");
50 
51 /**
52  * @brief Create a quadrilateral element.
53  */
54 Quadrilateral::Quadrilateral(ElmtConfig pConf,
55  vector<NodeSharedPtr> pNodeList,
56  vector<int> pTagList)
57  : Element(pConf, GetNumNodes(pConf), pNodeList.size())
58 {
59  m_tag = "Q";
60  m_dim = 2;
61  m_taglist = pTagList;
62  int n = m_conf.m_order - 1;
63 
64  // Create a map to relate edge nodes to a pair of vertices
65  // defining an edge. This is based on the ordering produced by
66  // gmsh.
67  map<pair<int, int>, int> edgeNodeMap;
68  map<pair<int, int>, int>::iterator it;
69  edgeNodeMap[pair<int, int>(1, 2)] = 5;
70  edgeNodeMap[pair<int, int>(2, 3)] = 5 + n;
71  edgeNodeMap[pair<int, int>(3, 4)] = 5 + 2 * n;
72  edgeNodeMap[pair<int, int>(4, 1)] = 5 + 3 * n;
73 
74  // Add vertices. This logic will determine (in 2D) whether the
75  // element is clockwise (sum > 0) or counter-clockwise (sum < 0).
76  NekDouble sum = 0.0;
77  for (int i = 0; i < 4; ++i)
78  {
79  int o = (i + 1) % 4;
80  m_vertex.push_back(pNodeList[i]);
81  sum += (pNodeList[o]->m_x - pNodeList[i]->m_x) *
82  (pNodeList[o]->m_y + pNodeList[i]->m_y);
83  }
84 
85  // Create edges (with corresponding set of edge points)
86  for (it = edgeNodeMap.begin(); it != edgeNodeMap.end(); ++it)
87  {
88  vector<NodeSharedPtr> edgeNodes;
89  if (m_conf.m_order > 1)
90  {
91  for (int j = it->second; j < it->second + n; ++j)
92  {
93  edgeNodes.push_back(pNodeList[j - 1]);
94  }
95  }
96  m_edge.push_back(EdgeSharedPtr(new Edge(pNodeList[it->first.first - 1],
97  pNodeList[it->first.second - 1],
98  edgeNodes,
100  }
101 
102  if (pConf.m_reorient)
103  {
104  if (sum > 0.0)
105  {
106  reverse(m_edge.begin(), m_edge.end());
107  swap(m_vertex[1], m_vertex[3]);
108  }
109  }
110 
111  if (m_conf.m_faceNodes)
112  {
113  m_volumeNodes.insert(m_volumeNodes.begin(),
114  pNodeList.begin() + 4 * m_conf.m_order,
115  pNodeList.end());
116  }
117 }
118 
120  int edgeId, EdgeSharedPtr edge)
121 {
122  int locVert = edgeId;
123  if (edge->m_n1 == m_vertex[locVert])
124  {
125  return StdRegions::eForwards;
126  }
127  else if (edge->m_n2 == m_vertex[locVert])
128  {
129  return StdRegions::eBackwards;
130  }
131  else
132  {
133  ASSERTL1(false, "Edge is not connected to this quadrilateral.");
134  }
135 
137 }
138 
142  int coordDim,
143  int &id,
144  bool justConfig)
145 {
146  m_conf.m_order = order;
147  m_curveType = pType;
148  m_conf.m_volumeNodes = false;
149  m_volumeNodes.clear();
150 
151  // Quadrilaterals of order == 1 have no interior volume points.
152  if (order == 1)
153  {
154  m_conf.m_faceNodes = false;
155  return;
156  }
157 
158  m_conf.m_faceNodes = true;
159 
160  if (justConfig)
161  {
162  return;
163  }
164 
165  int nPoints = order + 1;
166  StdRegions::StdExpansionSharedPtr xmap = geom->GetXmap();
167 
169  LibUtilities::PointsKey pKey(nPoints, pType);
170  ASSERTL1(pKey.GetPointsDim() == 1, "Points distribution must be 1D");
171  LibUtilities::PointsManager()[pKey]->GetPoints(px);
172 
173  Array<OneD, Array<OneD, NekDouble> > phys(coordDim);
174 
175  for (int i = 0; i < coordDim; ++i)
176  {
177  phys[i] = Array<OneD, NekDouble>(xmap->GetTotPoints());
178  xmap->BwdTrans(geom->GetCoeffs(i), phys[i]);
179  }
180 
181  int nQuadIntPts = (nPoints - 2) * (nPoints - 2);
182  m_volumeNodes.resize(nQuadIntPts);
183 
184  for (int i = 1, cnt = 0; i < nPoints-1; ++i)
185  {
186  for (int j = 1; j < nPoints-1; ++j, ++cnt)
187  {
189  xp[0] = px[j];
190  xp[1] = px[i];
191 
192  Array<OneD, NekDouble> x(3, 0.0);
193  for (int k = 0; k < coordDim; ++k)
194  {
195  x[k] = xmap->PhysEvaluate(xp, phys[k]);
196  }
197 
198  m_volumeNodes[cnt] = std::shared_ptr<Node>(
199  new Node(id++, x[0], x[1], x[2]));
200  }
201  }
202 }
203 
205 {
208 
209  for (int i = 0; i < 4; ++i)
210  {
211  edges[i] = m_edge[i]->GetGeom(coordDim);
212  }
213 
215  m_id, edges);
216 
217  ret->Setup();
218  return ret;
219 }
220 
221 void Quadrilateral::GetCurvedNodes(std::vector<NodeSharedPtr> &nodeList) const
222 {
223  int n = m_edge[0]->GetNodeCount();
224  nodeList.resize(n * n);
225 
226  // Write vertices
227  nodeList[0] = m_vertex[0];
228  nodeList[n - 1] = m_vertex[1];
229  nodeList[n * n - 1] = m_vertex[2];
230  nodeList[n * (n - 1)] = m_vertex[3];
231 
232  // Write edge-interior
233  int skips[4][2] = {
234  {0, 1}, {n - 1, n}, {n * n - 1, -1}, {n * (n - 1), -n}};
235  for (int i = 0; i < 4; ++i)
236  {
237  bool reverseEdge = m_edge[i]->m_n1 == m_vertex[i];
238 
239  if (!reverseEdge)
240  {
241  for (int j = 1; j < n - 1; ++j)
242  {
243  nodeList[skips[i][0] + j * skips[i][1]] =
244  m_edge[i]->m_edgeNodes[n - 2 - j];
245  }
246  }
247  else
248  {
249  for (int j = 1; j < n - 1; ++j)
250  {
251  nodeList[skips[i][0] + j * skips[i][1]] =
252  m_edge[i]->m_edgeNodes[j - 1];
253  }
254  }
255  }
256 
257  // Write interior
258  for (int i = 1; i < n - 1; ++i)
259  {
260  for (int j = 1; j < n - 1; ++j)
261  {
262  nodeList[i * n + j] =
263  m_volumeNodes[(i - 1) * (n - 2) + (j - 1)];
264  }
265  }
266 }
267 
268 
269 /**
270  * @brief Return the number of nodes defining a quadrilateral.
271  */
273 {
274  int n = pConf.m_order;
275  if (!pConf.m_faceNodes)
276  return 4 * n;
277  else
278  return (n + 1) * (n + 1);
279 }
280 }
281 }
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
Basic information about an element.
Definition: ElementConfig.h:49
Represents an edge which joins two points.
Definition: Edge.h:58
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a quadrilateral.
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
Definition: HexGeom.h:46
STL namespace.
unsigned int GetPointsDim() const
Definition: Points.h:150
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
ElementFactory & GetElementFactory()
Definition: Element.cpp:44
ElmtConfig m_conf
Contains configuration of the element.
Definition: Element.h:462
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
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
virtual NEKMESHUTILS_EXPORT void GetCurvedNodes(std::vector< NodeSharedPtr > &nodeList) const
get list of volume interior nodes
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
PointsManagerT & PointsManager(void)
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
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...
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
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
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...
#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