Nektar++
Loading...
Searching...
No Matches
TestGetCoords.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestGetCoords.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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
36#include <LocalRegions/HexExp.h>
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
40
42{
43
47{
48 std::array<SpatialDomains::PointGeom *, 2> vertices = {v0, v1};
50 new SpatialDomains::SegGeom(id, 3, vertices));
51 return result;
52}
53
55 std::array<SpatialDomains::PointGeom *, 8> v,
56 std::array<SpatialDomains::SegGeomUniquePtr, 12> &segVec,
57 std::array<SpatialDomains::QuadGeomUniquePtr, 6> &faceVec)
58{
59 std::array<std::array<int, 2>, 12> edgeVerts = {{{{0, 1}},
60 {{1, 2}},
61 {{2, 3}},
62 {{3, 0}},
63 {{0, 4}},
64 {{1, 5}},
65 {{2, 6}},
66 {{3, 7}},
67 {{4, 5}},
68 {{5, 6}},
69 {{6, 7}},
70 {{7, 4}}}};
71 std::array<std::array<int, 4>, 6> faceEdges = {{{{0, 1, 2, 3}},
72 {{0, 5, 8, 4}},
73 {{1, 6, 9, 5}},
74 {{2, 6, 10, 7}},
75 {{3, 7, 11, 4}},
76 {{8, 9, 10, 11}}}};
77
78 // Create segments from vertices
79 for (int i = 0; i < 12; ++i)
80 {
81 segVec[i] = CreateSegGeom(i, v[edgeVerts[i][0]], v[edgeVerts[i][1]]);
82 }
83
84 // Create faces from edges
85 std::array<SpatialDomains::QuadGeom *, 6> faces;
86 for (int i = 0; i < 6; ++i)
87 {
88 std::array<SpatialDomains::SegGeom *, 4> face;
89 for (int j = 0; j < 4; ++j)
90 {
91 face[j] = segVec[faceEdges[i][j]].get();
92 }
94 new SpatialDomains::QuadGeom(i, face));
95 faces[i] = faceVec[i].get();
96 }
97
99 new SpatialDomains::HexGeom(0, faces));
100 return hexGeom;
101}
102
103BOOST_AUTO_TEST_CASE(TestHexExpThatIsStdRegion)
104{
106 new SpatialDomains::PointGeom(3u, 0u, -1.0, -1.0, -1.0));
108 new SpatialDomains::PointGeom(3u, 1u, 1.0, -1.0, -1.0));
110 new SpatialDomains::PointGeom(3u, 2u, 1.0, 1.0, -1.0));
112 new SpatialDomains::PointGeom(3u, 3u, -1.0, 1.0, -1.0));
114 new SpatialDomains::PointGeom(3u, 4u, -1.0, -1.0, 1.0));
116 new SpatialDomains::PointGeom(3u, 5u, 1.0, -1.0, 1.0));
118 new SpatialDomains::PointGeom(3u, 6u, 1.0, 1.0, 1.0));
120 new SpatialDomains::PointGeom(3u, 7u, -1.0, 1.0, 1.0));
121
122 std::array<SpatialDomains::PointGeom *, 8> v = {
123 v0.get(), v1.get(), v2.get(), v3.get(),
124 v4.get(), v5.get(), v6.get(), v7.get()};
125 std::array<SpatialDomains::SegGeomUniquePtr, 12> segVec;
126 std::array<SpatialDomains::QuadGeomUniquePtr, 6> faceVec;
127 SpatialDomains::HexGeomUniquePtr hexGeom = CreateHex(v, segVec, faceVec);
128
129 Nektar::LibUtilities::PointsType quadPointsTypeDir1 =
131 Nektar::LibUtilities::BasisType basisTypeDir1 =
133 unsigned int numQuadPoints = 6;
134 const Nektar::LibUtilities::PointsKey quadPointsKeyDir1(numQuadPoints,
135 quadPointsTypeDir1);
136 const Nektar::LibUtilities::BasisKey basisKeyDir1(basisTypeDir1, 4,
137 quadPointsKeyDir1);
138
141 basisKeyDir1, basisKeyDir1, basisKeyDir1, hexGeom.get());
142
143 Array<OneD, NekDouble> c0 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
144 Array<OneD, NekDouble> c1 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
145 Array<OneD, NekDouble> c2 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
146 hexExp->GetCoords(c0, c1, c2);
147 std::shared_ptr<StdRegions::StdHexExp> stdHex =
148 std::dynamic_pointer_cast<StdRegions::StdHexExp>(hexExp);
149 stdHex->GetCoords(c0, c1, c2);
150 double epsilon = 1.0e-8;
151 BOOST_CHECK_CLOSE(c0[0], -1.0, epsilon);
152 BOOST_CHECK_CLOSE(c0[1], -0.76505532392946474, epsilon);
153 BOOST_CHECK_CLOSE(c0[2], -0.28523151648064510, epsilon);
154 BOOST_CHECK_CLOSE(c0[3], 0.28523151648064510, epsilon);
155 BOOST_CHECK_CLOSE(c0[4], 0.76505532392946474, epsilon);
156 BOOST_CHECK_CLOSE(c0[5], 1.0, epsilon);
157}
158
159BOOST_AUTO_TEST_CASE(TestScaledAndTranslatedHexExp)
160{
162 new SpatialDomains::PointGeom(3u, 0u, 0.0, 0.0, 0.0));
164 new SpatialDomains::PointGeom(3u, 1u, 0.5, 0.0, 0.0));
166 new SpatialDomains::PointGeom(3u, 2u, 0.5, 0.5, 0.0));
168 new SpatialDomains::PointGeom(3u, 3u, 0.0, 0.5, 0.0));
170 new SpatialDomains::PointGeom(3u, 4u, 0.0, 0.0, 0.5));
172 new SpatialDomains::PointGeom(3u, 5u, 0.5, 0.0, 0.5));
174 new SpatialDomains::PointGeom(3u, 6u, 0.5, 0.5, 0.5));
176 new SpatialDomains::PointGeom(3u, 7u, 0.0, 0.5, 0.5));
177
178 std::array<SpatialDomains::PointGeom *, 8> v = {
179 v0.get(), v1.get(), v2.get(), v3.get(),
180 v4.get(), v5.get(), v6.get(), v7.get()};
181 std::array<SpatialDomains::SegGeomUniquePtr, 12> segVec;
182 std::array<SpatialDomains::QuadGeomUniquePtr, 6> faceVec;
183 SpatialDomains::HexGeomUniquePtr hexGeom = CreateHex(v, segVec, faceVec);
184
185 Nektar::LibUtilities::PointsType quadPointsTypeDir1 =
187 Nektar::LibUtilities::BasisType basisTypeDir1 =
189 unsigned int numQuadPoints = 6;
190 const Nektar::LibUtilities::PointsKey quadPointsKeyDir1(numQuadPoints,
191 quadPointsTypeDir1);
192 const Nektar::LibUtilities::BasisKey basisKeyDir1(basisTypeDir1, 4,
193 quadPointsKeyDir1);
194
197 basisKeyDir1, basisKeyDir1, basisKeyDir1, hexGeom.get());
198
199 Array<OneD, NekDouble> c0 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
200 Array<OneD, NekDouble> c1 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
201 Array<OneD, NekDouble> c2 = Array<OneD, NekDouble>(hexExp->GetTotPoints());
202 hexExp->GetCoords(c0, c1, c2);
203
204 double epsilon = 1.0e-8;
205 BOOST_CHECK_EQUAL(c0[0], 0.0);
206 BOOST_CHECK_CLOSE(c0[1], .05873616902, epsilon);
207 BOOST_CHECK_CLOSE(c0[2], .17869212088, epsilon);
208 BOOST_CHECK_CLOSE(c0[3], .32130787912, epsilon);
209 BOOST_CHECK_CLOSE(c0[4], .44126383098, epsilon);
210 BOOST_CHECK_CLOSE(c0[5], .5, epsilon);
211}
212
213BOOST_AUTO_TEST_CASE(TestPointExpThatIsStdRegion)
214{
216 new SpatialDomains::PointGeom(3u, 0u, -1.0, -1.0, -1.0));
217
218 Nektar::LibUtilities::PointsType quadPointsTypeDir1 =
220 Nektar::LibUtilities::BasisType basisTypeDir1 =
222 unsigned int numQuadPoints = 1;
223 unsigned int numModes = 1;
224 const Nektar::LibUtilities::PointsKey quadPointsKeyDir1(numQuadPoints,
225 quadPointsTypeDir1);
226 const Nektar::LibUtilities::BasisKey basisKeyDir1(basisTypeDir1, numModes,
227 quadPointsKeyDir1);
228
231 v0.get());
232
233 NekDouble c0 = 0, c1 = 0, c2 = 0;
234 pointExp->GetCoords(c0, c1, c2);
235
236 std::shared_ptr<StdRegions::StdPointExp> stdPoint =
237 std::dynamic_pointer_cast<StdRegions::StdPointExp>(pointExp);
238
240 Array<OneD, NekDouble>(pointExp->GetTotPoints());
242 Array<OneD, NekDouble>(pointExp->GetTotPoints());
244 Array<OneD, NekDouble>(pointExp->GetTotPoints());
245 stdPoint->GetCoords(c0_arr, c1_arr, c2_arr);
246
247 double epsilon = 1.0e-8;
248 BOOST_CHECK_CLOSE(c0, -1.0, epsilon);
249 BOOST_CHECK_CLOSE(c0_arr[0], -1.0, epsilon);
250
251 // Get geometry type and check that it is always Regular
252 auto gtype = pointExp->GetMetricInfo()->GetGtype();
253 BOOST_CHECK_EQUAL(gtype, SpatialDomains::eRegular);
254
255 // Get jacobian and check it is equal to one
256 auto jac = pointExp->GetMetricInfo()->GetJac(pointExp->GetPointsKeys());
257 BOOST_CHECK_CLOSE(jac[0], 1.0, epsilon);
258}
259
260} // namespace Nektar::HexExpTests
Describes the specification for a Basis.
Definition Basis.h:45
Defines a specification for a set of points.
Definition Points.h:50
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
BOOST_AUTO_TEST_CASE(TestHexExpThatIsStdRegion)
SpatialDomains::SegGeomUniquePtr CreateSegGeom(unsigned int id, SpatialDomains::PointGeom *v0, SpatialDomains::PointGeom *v1)
SpatialDomains::HexGeomUniquePtr CreateHex(std::array< SpatialDomains::PointGeom *, 8 > v, std::array< SpatialDomains::SegGeomUniquePtr, 12 > &segVec, std::array< SpatialDomains::QuadGeomUniquePtr, 6 > &faceVec)
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:51
@ eModified_A
Principle Modified Functions .
Definition BasisType.h:48
std::shared_ptr< PointExp > PointExpSharedPtr
Definition PointExp.h:130
std::shared_ptr< HexExp > HexExpSharedPtr
Definition HexExp.h:258
unique_ptr_objpool< HexGeom > HexGeomUniquePtr
Definition MeshGraph.h:104
unique_ptr_objpool< QuadGeom > QuadGeomUniquePtr
Definition MeshGraph.h:100
@ eRegular
Geometry is straight-sided with constant geometric factors.
unique_ptr_objpool< SegGeom > SegGeomUniquePtr
Definition MeshGraph.h:98
unique_ptr_objpool< PointGeom > PointGeomUniquePtr
Definition MeshGraph.h:93