Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Triangle.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Mesh.h
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 manipulation objects.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NekMeshUtils_MESHELEMENTS_TRIANGLE
37 #define NekMeshUtils_MESHELEMENTS_TRIANGLE
38 
41 
42 namespace Nektar
43 {
44 namespace NekMeshUtils
45 {
46 /**
47  * @brief A lightweight struct for dealing with high-order triangle
48  * alignment.
49  *
50  * The logic underlying these routines is taken from the original Nektar
51  * code.
52  */
53 template <typename T> struct HOTriangle
54 {
55  HOTriangle(std::vector<int> pVertId, std::vector<T> pSurfVerts)
56  : vertId(pVertId), surfVerts(pSurfVerts)
57  {
58  }
59  HOTriangle(std::vector<int> pVertId) : vertId(pVertId)
60  {
61  }
62 
63  /// The triangle vertex IDs
64  std::vector<int> vertId;
65 
66  /// The triangle surface vertices -- templated so that this can
67  /// either be nodes or IDs.
68  std::vector<T> surfVerts;
69 
70  /**
71  * @brief Rotates the triangle of data points inside #surfVerts
72  * counter-clockwise nrot times.
73  *
74  * @param nrot Number of times to rotate triangle.
75  */
76  void Rotate(int nrot)
77  {
78  int n, i, j, cnt;
79  int np = ((int)sqrt(8.0 * surfVerts.size() + 1.0) - 1) / 2;
80  std::vector<T> tmp(np * np);
81 
82  for (n = 0; n < nrot; ++n)
83  {
84  for (cnt = i = 0; i < np; ++i)
85  {
86  for (j = 0; j < np - i; ++j, cnt++)
87  {
88  tmp[i * np + j] = surfVerts[cnt];
89  }
90  }
91  for (cnt = i = 0; i < np; ++i)
92  {
93  for (j = 0; j < np - i; ++j, cnt++)
94  {
95  surfVerts[cnt] = tmp[(np - 1 - i - j) * np + i];
96  }
97  }
98  }
99  }
100 
101  /**
102  * @brief Reflect data points inside #surfVerts.
103  *
104  * This applies a mapping essentially doing the following
105  * reordering:
106  *
107  * 9 9
108  * 7 8 -> 8 7
109  * 4 5 6 6 5 4
110  * 0 1 2 3 3 2 1 0
111  */
112  void Reflect()
113  {
114  int i, j, cnt;
115  int np = ((int)sqrt(8.0 * surfVerts.size() + 1.0) - 1) / 2;
116  std::vector<T> tmp(np * np);
117 
118  for (cnt = i = 0; i < np; ++i)
119  {
120  for (j = 0; j < np - i; ++j, cnt++)
121  {
122  tmp[i * np + np - i - 1 - j] = surfVerts[cnt];
123  }
124  }
125 
126  for (cnt = i = 0; i < np; ++i)
127  {
128  for (j = 0; j < np - i; ++j, cnt++)
129  {
130  surfVerts[cnt] = tmp[i * np + j];
131  }
132  }
133  }
134 
135  /**
136  * @brief Align this surface to a given vertex ID.
137  */
138  void Align(std::vector<int> vertId)
139  {
140  if (vertId[0] == this->vertId[0])
141  {
142  if (vertId[1] == this->vertId[1] || vertId[1] == this->vertId[2])
143  {
144  if (vertId[1] == this->vertId[2])
145  {
146  Rotate(1);
147  Reflect();
148  }
149  }
150  }
151  else if (vertId[0] == this->vertId[1])
152  {
153  if (vertId[1] == this->vertId[0] || vertId[1] == this->vertId[2])
154  {
155  if (vertId[1] == this->vertId[0])
156  {
157  Reflect();
158  }
159  else
160  {
161  Rotate(2);
162  }
163  }
164  }
165  else if (vertId[0] == this->vertId[2])
166  {
167  if (vertId[1] == this->vertId[0] || vertId[1] == this->vertId[1])
168  {
169  if (vertId[1] == this->vertId[1])
170  {
171  Rotate(2);
172  Reflect();
173  }
174  else
175  {
176  Rotate(1);
177  }
178  }
179  }
180  }
181 };
182 
183 /**
184  * @brief A 2-dimensional three-sided element.
185  */
186 class Triangle : public Element
187 {
188 public:
189  /// Creates an instance of this class
191  std::vector<NodeSharedPtr> pNodeList,
192  std::vector<int> pTagList)
193  {
194  return boost::shared_ptr<Element>(
195  new Triangle(pConf, pNodeList, pTagList));
196  }
197  /// Element type
199 
201  std::vector<NodeSharedPtr> pNodeList,
202  std::vector<int> pTagList);
205  {
206  }
207 
209  int coordDim);
210  NEKMESHUTILS_EXPORT virtual void Complete(int order);
211 
212  NEKMESHUTILS_EXPORT static unsigned int GetNumNodes(ElmtConfig pConf);
213 };
214 
216 typedef boost::shared_ptr<HOSurf> HOSurfSharedPtr;
217 
218 /**
219  * Hash class for high-order surfaces.
220  */
221 struct HOSurfHash : std::unary_function<HOSurfSharedPtr, std::size_t>
222 {
223  /**
224  * Calculate hash of a given high-order surface p by taking
225  * successive hashes of the vertex IDs.
226  */
227  std::size_t operator()(HOSurfSharedPtr const &p) const
228  {
229  std::size_t seed = 0;
230  std::vector<int> ids = p->vertId;
231 
232  std::sort(ids.begin(), ids.end());
233  for (int i = 0; i < ids.size(); ++i)
234  {
235  boost::hash_combine(seed, ids[i]);
236  }
237  return seed;
238  }
239 };
240 
241 NEKMESHUTILS_EXPORT bool operator==(HOSurfSharedPtr const &p1,
242  HOSurfSharedPtr const &p2);
243 
244 typedef boost::unordered_set<HOSurfSharedPtr, HOSurfHash> HOSurfSet;
245 }
246 }
247 
248 #endif
virtual NEKMESHUTILS_EXPORT SpatialDomains::GeometrySharedPtr GetGeom(int coordDim)
Generate a Nektar++ geometry object for this element.
Definition: Triangle.cpp:118
boost::unordered_set< HOSurfSharedPtr, HOSurfHash > HOSurfSet
Definition: Triangle.h:244
static LibUtilities::ShapeType m_type
Element type.
Definition: Triangle.h:198
Basic information about an element.
Definition: Element.h:58
void Align(std::vector< int > vertId)
Align this surface to a given vertex ID.
Definition: Triangle.h:138
A 2-dimensional three-sided element.
Definition: Triangle.h:186
boost::shared_ptr< HOSurf > HOSurfSharedPtr
Definition: Triangle.h:216
virtual NEKMESHUTILS_EXPORT void Complete(int order)
Complete this object.
Definition: Triangle.cpp:153
std::size_t operator()(HOSurfSharedPtr const &p) const
Definition: Triangle.h:227
std::vector< T > surfVerts
The triangle surface vertices – templated so that this can either be nodes or IDs.
Definition: Triangle.h:68
std::vector< int > vertId
The triangle vertex IDs.
Definition: Triangle.h:64
void Rotate(int nrot)
Rotates the triangle of data points inside surfVerts counter-clockwise nrot times.
Definition: Triangle.h:76
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
NEKMESHUTILS_EXPORT Triangle(ElmtConfig pConf, std::vector< NodeSharedPtr > pNodeList, std::vector< int > pTagList)
Create a triangle element.
Definition: Triangle.cpp:54
static ElementSharedPtr create(ElmtConfig pConf, std::vector< NodeSharedPtr > pNodeList, std::vector< int > pTagList)
Creates an instance of this class.
Definition: Triangle.h:190
HOTriangle(std::vector< int > pVertId)
Definition: Triangle.h:59
static NEKMESHUTILS_EXPORT unsigned int GetNumNodes(ElmtConfig pConf)
Return the number of nodes defining a triangle.
Definition: Triangle.cpp:144
A lightweight struct for dealing with high-order triangle alignment.
Definition: Triangle.h:53
#define NEKMESHUTILS_EXPORT
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:52
void Reflect()
Reflect data points inside surfVerts.
Definition: Triangle.h:112
virtual NEKMESHUTILS_EXPORT ~Triangle()
Definition: Triangle.h:204
HOTriangle(std::vector< int > pVertId, std::vector< T > pSurfVerts)
Definition: Triangle.h:55
HOTriangle< NodeSharedPtr > HOSurf
Definition: Triangle.h:215
boost::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:53
Base class for element definitions.
Definition: Element.h:115