Nektar++
Loading...
Searching...
No Matches
LocalRegions/TestReduceOrderCoeffs.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestReduceOrderCoeffs.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: Unit tests for HexExp::ReduceOrderCoeffs.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <LocalRegions/HexExp.h>
38#include <boost/test/unit_test.hpp>
39
40#include <algorithm>
41#include <array>
42#include <cmath>
43#include <vector>
44
46{
47
51{
52 std::array<SpatialDomains::PointGeom *, 2> vertices = {v0, v1};
54 new SpatialDomains::SegGeom(id, 3, vertices));
55}
56
58 std::array<SpatialDomains::PointGeom *, 8> v,
59 std::array<SpatialDomains::SegGeomUniquePtr, 12> &segVec,
60 std::array<SpatialDomains::QuadGeomUniquePtr, 6> &faceVec)
61{
62 std::array<std::array<int, 2>, 12> edgeVerts = {{{{0, 1}},
63 {{1, 2}},
64 {{2, 3}},
65 {{3, 0}},
66 {{0, 4}},
67 {{1, 5}},
68 {{2, 6}},
69 {{3, 7}},
70 {{4, 5}},
71 {{5, 6}},
72 {{6, 7}},
73 {{7, 4}}}};
74 std::array<std::array<int, 4>, 6> faceEdges = {{{{0, 1, 2, 3}},
75 {{0, 5, 8, 4}},
76 {{1, 6, 9, 5}},
77 {{2, 6, 10, 7}},
78 {{3, 7, 11, 4}},
79 {{8, 9, 10, 11}}}};
80
81 for (int i = 0; i < 12; ++i)
82 {
83 segVec[i] = CreateSegGeom(i, v[edgeVerts[i][0]], v[edgeVerts[i][1]]);
84 }
85
86 std::array<SpatialDomains::QuadGeom *, 6> faces;
87 for (int i = 0; i < 6; ++i)
88 {
89 std::array<SpatialDomains::SegGeom *, 4> face;
90 for (int j = 0; j < 4; ++j)
91 {
92 face[j] = segVec[faceEdges[i][j]].get();
93 }
95 new SpatialDomains::QuadGeom(i, face));
96 faces[i] = faceVec[i].get();
97 }
98
100 new SpatialDomains::HexGeom(0, faces));
101}
102
103/**
104 * @brief Check HexExp::ReduceOrderCoeffs mode by mode on an affine element.
105 *
106 * Each mode of the orthogonal standard hexahedron of the same order and
107 * points is expressed in the element's basis and reduced to @p numMin: a mode
108 * below numMin in every direction must come back unchanged, every other must
109 * vanish. The element is a translated unit cube, so its transforms are those
110 * of the standard element up to a constant Jacobian.
111 */
112void CheckHex(const int nm0, const int nm1, const int nm2, const int numMin)
113{
114 using namespace LibUtilities;
115
116 std::array<SpatialDomains::PointGeomUniquePtr, 8> v;
117 const double c[8][3] = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
118 {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}};
119 std::array<SpatialDomains::PointGeom *, 8> vp;
120 for (int i = 0; i < 8; ++i)
121 {
123 3u, i, 0.5 + c[i][0], 0.25 + c[i][1], -1.0 + c[i][2]));
124 vp[i] = v[i].get();
125 }
126 std::array<SpatialDomains::SegGeomUniquePtr, 12> segVec;
127 std::array<SpatialDomains::QuadGeomUniquePtr, 6> faceVec;
128 SpatialDomains::HexGeomUniquePtr hexGeom = CreateHex(vp, segVec, faceVec);
129
130 const PointsKey pkey0(nm0 + 1, eGaussLobattoLegendre);
131 const PointsKey pkey1(nm1 + 1, eGaussLobattoLegendre);
132 const PointsKey pkey2(nm2 + 1, eGaussLobattoLegendre);
133 const BasisKey b0(eModified_A, nm0, pkey0), b1(eModified_A, nm1, pkey1),
134 b2(eModified_A, nm2, pkey2);
135 const BasisKey o0(eOrtho_A, nm0, pkey0), o1(eOrtho_A, nm1, pkey1),
136 o2(eOrtho_A, nm2, pkey2);
137
139 b0, b1, b2, hexGeom.get());
140 auto ortho =
142
143 const int nm = exp->GetNcoeffs();
144 const int nq = exp->GetTotPoints();
145 BOOST_REQUIRE_EQUAL(ortho->GetNcoeffs(), nm);
146 BOOST_REQUIRE_EQUAL(ortho->GetTotPoints(), nq);
147
148 // Mode (p, q, r) is stored with p fastest; its degree is the largest
149 // index.
150 std::vector<int> degree(nm);
151 for (int r = 0; r < nm2; ++r)
152 {
153 for (int q = 0; q < nm1; ++q)
154 {
155 for (int p = 0; p < nm0; ++p)
156 {
157 degree[(r * nm1 + q) * nm0 + p] = std::max({p, q, r});
158 }
159 }
160 }
161
162 const NekDouble tol = 1.0e-8;
163 for (int mode = 0; mode < nm; ++mode)
164 {
165 Array<OneD, NekDouble> orthoCoeffs(nm, 0.0);
166 orthoCoeffs[mode] = 1.0;
167
168 Array<OneD, NekDouble> phys(nq), coeffs(nm), reduced(nm), back(nq);
169 ortho->BwdTrans(orthoCoeffs, phys);
170 exp->FwdTrans(phys, coeffs);
171 exp->ReduceOrderCoeffs(numMin, coeffs, reduced);
172 exp->BwdTrans(reduced, back);
173
174 const bool kept = degree[mode] < numMin;
175 NekDouble diff = 0.0;
176 for (int q = 0; q < nq; ++q)
177 {
178 diff = std::max(diff, std::abs(back[q] - (kept ? phys[q] : 0.0)));
179 }
180 BOOST_CHECK_MESSAGE(diff < tol,
181 "mode " << mode << " of degree " << degree[mode]
182 << (kept ? " changed by " : " left ")
183 << diff << " with numMin " << numMin);
184 }
185}
186
187BOOST_AUTO_TEST_CASE(TestHexReduceOrderCoeffs)
188{
189 CheckHex(4, 4, 4, 3);
190 CheckHex(4, 4, 4, 2);
191 // Anisotropic: numMin above the smallest mode count, and below it.
192 CheckHex(3, 4, 5, 4);
193 CheckHex(5, 4, 3, 3);
194}
195
196} // namespace Nektar::LocalRegionsReduceOrderTests
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.
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:51
@ eOrtho_A
Principle Orthogonal Functions .
Definition BasisType.h:42
@ eModified_A
Principle Modified Functions .
Definition BasisType.h:48
SpatialDomains::HexGeomUniquePtr CreateHex(std::array< SpatialDomains::PointGeom *, 8 > v, std::array< SpatialDomains::SegGeomUniquePtr, 12 > &segVec, std::array< SpatialDomains::QuadGeomUniquePtr, 6 > &faceVec)
SpatialDomains::SegGeomUniquePtr CreateSegGeom(unsigned int id, SpatialDomains::PointGeom *v0, SpatialDomains::PointGeom *v1)
void CheckHex(const int nm0, const int nm1, const int nm2, const int numMin)
Check HexExp::ReduceOrderCoeffs mode by mode on an affine element.
unique_ptr_objpool< HexGeom > HexGeomUniquePtr
Definition MeshGraph.h:77
unique_ptr_objpool< QuadGeom > QuadGeomUniquePtr
Definition MeshGraph.h:73
unique_ptr_objpool< SegGeom > SegGeomUniquePtr
Definition MeshGraph.h:71
unique_ptr_objpool< PointGeom > PointGeomUniquePtr
Definition Geometry.h:60