Nektar++
Loading...
Searching...
No Matches
Functions
Nektar::NekMeshHOAlignmentUnitTest Namespace Reference

Functions

static std::vector< std::array< int, 4 > > TetWeights (int np)
 Barycentric position of every node of a nodal tetrahedron.
 
static std::vector< std::array< int, 4 > > PrismPlaces (int np)
 Where every node of a nodal prism sits.
 
 BOOST_AUTO_TEST_CASE (TestHOTetrahedronAlign)
 Aligning a tetrahedron puts every node where its weights say.
 
 BOOST_AUTO_TEST_CASE (TestHOTetrahedronInteriorAlign)
 The interior of a tetrahedron aligns on its own too.
 
 BOOST_AUTO_TEST_CASE (TestHOPrismRotate)
 Turning a prism moves every node round the triangle it sits in.
 
 BOOST_AUTO_TEST_CASE (TestHOPrismThreeTurnsIsIdentity)
 Turning a prism three times leaves it as it was.
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

Nektar::NekMeshHOAlignmentUnitTest::BOOST_AUTO_TEST_CASE ( TestHOPrismRotate  )

Turning a prism moves every node round the triangle it sits in.

Definition at line 206 of file TestHOAlignment.cpp.

207{
208 for (int np = 2; np <= 6; ++np)
209 {
210 const auto w = PrismPlaces(np);
211 const int nTot = w.size();
212
213 for (int nrot = 0; nrot < 3; ++nrot)
214 {
215 std::vector<int> ids = {10, 11, 12, 13, 14, 15}, nodes(nTot);
216 for (int m = 0; m < nTot; ++m)
217 {
218 nodes[m] = m;
219 }
220
221 HOPrism<int> hoPrism(ids, nodes, np);
222 hoPrism.Rotate(nrot);
223
224 for (int m = 0; m < nTot; ++m)
225 {
226 std::array<int, 4> have{};
227 for (int c = 0; c < 3; ++c)
228 {
229 have[(c + nrot) % 3] = w[m][c];
230 }
231 have[3] = w[m][3];
232
233 const int expected =
234 std::find(w.begin(), w.end(), have) - w.begin();
235
236 BOOST_CHECK_MESSAGE(hoPrism.volVerts[m] == expected,
237 "Prism of "
238 << nTot << " nodes, turned " << nrot
239 << ", slot " << m << ": got "
240 << hoPrism.volVerts[m] << ", expected "
241 << expected);
242 }
243 }
244 }
245}
std::vector< SpatialDomains::PointGeom * > nodes
static std::vector< std::array< int, 4 > > PrismPlaces(int np)
Where every node of a nodal prism sits.

References nodes, PrismPlaces(), Nektar::SpatialDomains::HOPrism< T >::Rotate(), and Nektar::SpatialDomains::HOPrism< T >::volVerts.

◆ BOOST_AUTO_TEST_CASE() [2/4]

Nektar::NekMeshHOAlignmentUnitTest::BOOST_AUTO_TEST_CASE ( TestHOPrismThreeTurnsIsIdentity  )

Turning a prism three times leaves it as it was.

Definition at line 250 of file TestHOAlignment.cpp.

251{
252 for (int np = 2; np <= 6; ++np)
253 {
254 const int nTot = np * (np + 1) / 2 * np;
255
256 std::vector<int> ids = {10, 11, 12, 13, 14, 15}, nodes(nTot);
257 for (int m = 0; m < nTot; ++m)
258 {
259 nodes[m] = m;
260 }
261
262 HOPrism<int> hoPrism(ids, nodes, np);
263 hoPrism.Rotate(1);
264 hoPrism.Rotate(1);
265 hoPrism.Rotate(1);
266
267 for (int m = 0; m < nTot; ++m)
268 {
269 BOOST_CHECK_EQUAL(hoPrism.volVerts[m], m);
270 }
271 }
272}

References nodes, Nektar::SpatialDomains::HOPrism< T >::Rotate(), and Nektar::SpatialDomains::HOPrism< T >::volVerts.

◆ BOOST_AUTO_TEST_CASE() [3/4]

Nektar::NekMeshHOAlignmentUnitTest::BOOST_AUTO_TEST_CASE ( TestHOTetrahedronAlign  )

Aligning a tetrahedron puts every node where its weights say.

Checked for all 24 ways the four vertices can be relabelled, with the nodes carrying their own index so that where each one ended up can be seen.

Definition at line 104 of file TestHOAlignment.cpp.

105{
106 for (int np = 2; np <= 6; ++np)
107 {
108 const auto w = TetWeights(np);
109 const int nTot = w.size();
110
111 std::array<int, 4> perm = {0, 1, 2, 3};
112 do
113 {
114 std::vector<int> stored = {10, 11, 12, 13}, want(4), nodes(nTot);
115 for (int i = 0; i < 4; ++i)
116 {
117 want[i] = stored[perm[i]];
118 }
119 for (int m = 0; m < nTot; ++m)
120 {
121 nodes[m] = m;
122 }
123
124 HOTetrahedron<int> hoTet(stored, nodes, np);
125 hoTet.Align(want);
126
127 for (int m = 0; m < nTot; ++m)
128 {
129 std::array<int, 4> have{};
130 for (int i = 0; i < 4; ++i)
131 {
132 have[perm[i]] = w[m][i];
133 }
134
135 const int expected =
136 std::find(w.begin(), w.end(), have) - w.begin();
137
138 BOOST_CHECK_MESSAGE(hoTet.volVerts[m] == expected,
139 "Tetrahedron of "
140 << nTot << " nodes, slot " << m
141 << ": got " << hoTet.volVerts[m]
142 << ", expected " << expected);
143 }
144 } while (std::next_permutation(perm.begin(), perm.end()));
145 }
146}
static std::vector< std::array< int, 4 > > TetWeights(int np)
Barycentric position of every node of a nodal tetrahedron.

References Nektar::SpatialDomains::HOTetrahedron< T >::Align(), nodes, TetWeights(), and Nektar::SpatialDomains::HOTetrahedron< T >::volVerts.

◆ BOOST_AUTO_TEST_CASE() [4/4]

Nektar::NekMeshHOAlignmentUnitTest::BOOST_AUTO_TEST_CASE ( TestHOTetrahedronInteriorAlign  )

The interior of a tetrahedron aligns on its own too.

Given only the interior the order cannot be worked out from the number of nodes – the interior of one order has as many as the whole of another – so this is the case where it is deduced rather than given.

Definition at line 155 of file TestHOAlignment.cpp.

156{
157 for (int np = 5; np <= 7; ++np)
158 {
159 const auto w = TetWeights(np);
160 const int nTot = w.size();
161 const int nInt = (np - 4) * (np - 3) * (np - 2) / 6;
162 const int first = nTot - nInt;
163
164 std::array<int, 4> perm = {0, 1, 2, 3};
165 do
166 {
167 std::vector<int> stored = {10, 11, 12, 13}, want(4), nodes(nInt);
168 for (int i = 0; i < 4; ++i)
169 {
170 want[i] = stored[perm[i]];
171 }
172 for (int s = 0; s < nInt; ++s)
173 {
174 nodes[s] = s;
175 }
176
177 // No point count given: the order is deduced from the interior.
178 HOTetrahedron<int> hoTet(stored, nodes);
179 hoTet.Align(want);
180
181 for (int s = 0; s < nInt; ++s)
182 {
183 std::array<int, 4> have{};
184 for (int i = 0; i < 4; ++i)
185 {
186 have[perm[i]] = w[first + s][i];
187 }
188
189 const int expected =
190 std::find(w.begin() + first, w.end(), have) - w.begin() -
191 first;
192
193 BOOST_CHECK_MESSAGE(hoTet.volVerts[s] == expected,
194 "Tetrahedron interior of "
195 << nInt << " nodes, slot " << s
196 << ": got " << hoTet.volVerts[s]
197 << ", expected " << expected);
198 }
199 } while (std::next_permutation(perm.begin(), perm.end()));
200 }
201}

References Nektar::SpatialDomains::HOTetrahedron< T >::Align(), nodes, TetWeights(), and Nektar::SpatialDomains::HOTetrahedron< T >::volVerts.

◆ PrismPlaces()

static std::vector< std::array< int, 4 > > Nektar::NekMeshHOAlignmentUnitTest::PrismPlaces ( int  np)
static

Where every node of a nodal prism sits.

The first three are its position in the triangular cross-section and the last is how far along the axis it is, again as whole numbers.

Definition at line 80 of file TestHOAlignment.cpp.

81{
82 LibUtilities::PointsKey pKey(np, LibUtilities::eNodalPrismEvenlySpaced);
84 LibUtilities::PointsManager()[pKey]->GetPoints(px, py, pz);
85
86 const int nTot = np * (np + 1) / 2 * np;
87 std::vector<std::array<int, 4>> w(nTot);
88 for (int m = 0; m < nTot; ++m)
89 {
90 w[m][1] = (int)std::lround(0.5 * (1.0 + px[m]) * (np - 1));
91 w[m][2] = (int)std::lround(0.5 * (1.0 + pz[m]) * (np - 1));
92 w[m][0] = (np - 1) - w[m][1] - w[m][2];
93 w[m][3] = (int)std::lround(0.5 * (1.0 + py[m]) * (np - 1));
94 }
95 return w;
96}
Defines a specification for a set of points.
Definition Points.h:50

References Nektar::LibUtilities::eNodalPrismEvenlySpaced, and Nektar::LibUtilities::PointsManager().

Referenced by BOOST_AUTO_TEST_CASE().

◆ TetWeights()

static std::vector< std::array< int, 4 > > Nektar::NekMeshHOAlignmentUnitTest::TetWeights ( int  np)
static

Barycentric position of every node of a nodal tetrahedron.

As whole numbers of 1/(np-1), so that they can be compared exactly. These weights are what says where a node belongs once the vertices are relabelled, so they are also what the test checks the alignment against.

Definition at line 56 of file TestHOAlignment.cpp.

57{
58 LibUtilities::PointsKey pKey(np, LibUtilities::eNodalTetEvenlySpaced);
60 LibUtilities::PointsManager()[pKey]->GetPoints(px, py, pz);
61
62 const int nTot = np * (np + 1) * (np + 2) / 6;
63 std::vector<std::array<int, 4>> w(nTot);
64 for (int m = 0; m < nTot; ++m)
65 {
66 w[m][1] = (int)std::lround(0.5 * (1.0 + px[m]) * (np - 1));
67 w[m][2] = (int)std::lround(0.5 * (1.0 + py[m]) * (np - 1));
68 w[m][3] = (int)std::lround(0.5 * (1.0 + pz[m]) * (np - 1));
69 w[m][0] = (np - 1) - w[m][1] - w[m][2] - w[m][3];
70 }
71 return w;
72}

References Nektar::LibUtilities::eNodalTetEvenlySpaced, and Nektar::LibUtilities::PointsManager().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().