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

Functions

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)
 
void CheckHex (const int nm0, const int nm1, const int nm2, const int numMin)
 Check HexExp::ReduceOrderCoeffs mode by mode on an affine element.
 
 BOOST_AUTO_TEST_CASE (TestHexReduceOrderCoeffs)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

Nektar::LocalRegionsReduceOrderTests::BOOST_AUTO_TEST_CASE ( TestHexReduceOrderCoeffs  )

Definition at line 187 of file LocalRegions/TestReduceOrderCoeffs.cpp.

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}
void CheckHex(const int nm0, const int nm1, const int nm2, const int numMin)
Check HexExp::ReduceOrderCoeffs mode by mode on an affine element.

References CheckHex().

◆ CheckHex()

void Nektar::LocalRegionsReduceOrderTests::CheckHex ( const int  nm0,
const int  nm1,
const int  nm2,
const int  numMin 
)

Check HexExp::ReduceOrderCoeffs mode by mode on an affine element.

Each mode of the orthogonal standard hexahedron of the same order and points is expressed in the element's basis and reduced to numMin: a mode below numMin in every direction must come back unchanged, every other must vanish. The element is a translated unit cube, so its transforms are those of the standard element up to a constant Jacobian.

Definition at line 112 of file LocalRegions/TestReduceOrderCoeffs.cpp.

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 {
122 v[i] = SpatialDomains::PointGeomUniquePtr(new SpatialDomains::PointGeom(
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
138 auto exp = MemoryManager<LocalRegions::HexExp>::AllocateSharedPtr(
139 b0, b1, b2, hexGeom.get());
140 auto ortho =
141 MemoryManager<StdRegions::StdHexExp>::AllocateSharedPtr(o0, o1, o2);
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}
SpatialDomains::HexGeomUniquePtr CreateHex(std::array< SpatialDomains::PointGeom *, 8 > v, std::array< SpatialDomains::SegGeomUniquePtr, 12 > &segVec, std::array< SpatialDomains::QuadGeomUniquePtr, 6 > &faceVec)
std::vector< double > p(NPUPPER)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), CreateHex(), Nektar::LibUtilities::eGaussLobattoLegendre, Nektar::LibUtilities::eModified_A, and Nektar::LibUtilities::eOrtho_A.

Referenced by BOOST_AUTO_TEST_CASE().

◆ CreateHex()

SpatialDomains::HexGeomUniquePtr Nektar::LocalRegionsReduceOrderTests::CreateHex ( std::array< SpatialDomains::PointGeom *, 8 >  v,
std::array< SpatialDomains::SegGeomUniquePtr, 12 > &  segVec,
std::array< SpatialDomains::QuadGeomUniquePtr, 6 > &  faceVec 
)

Definition at line 57 of file LocalRegions/TestReduceOrderCoeffs.cpp.

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 }
94 faceVec[i] = SpatialDomains::QuadGeomUniquePtr(
95 new SpatialDomains::QuadGeom(i, face));
96 faces[i] = faceVec[i].get();
97 }
98
99 return SpatialDomains::HexGeomUniquePtr(
100 new SpatialDomains::HexGeom(0, faces));
101}
SpatialDomains::SegGeomUniquePtr CreateSegGeom(unsigned int id, SpatialDomains::PointGeom *v0, SpatialDomains::PointGeom *v1)

References CreateSegGeom().

Referenced by CheckHex().

◆ CreateSegGeom()

SpatialDomains::SegGeomUniquePtr Nektar::LocalRegionsReduceOrderTests::CreateSegGeom ( unsigned int  id,
SpatialDomains::PointGeom *  v0,
SpatialDomains::PointGeom *  v1 
)

Definition at line 48 of file LocalRegions/TestReduceOrderCoeffs.cpp.

51{
52 std::array<SpatialDomains::PointGeom *, 2> vertices = {v0, v1};
54 new SpatialDomains::SegGeom(id, 3, vertices));
55}
unique_ptr_objpool< SegGeom > SegGeomUniquePtr
Definition MeshGraph.h:71

Referenced by CreateHex().