Nektar++
Loading...
Searching...
No Matches
TestInterpCoeff.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestInterpCoeff.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 OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29// SOFTWARE.
30//
31// Description: Unit tests for coefficient interpolation.
32//
33///////////////////////////////////////////////////////////////////////////////
34
40#include <boost/test/tools/floating_point_comparison.hpp>
41#include <boost/test/unit_test.hpp>
42#include <cmath>
43
45{
46
48 const LibUtilities::BasisKey &fbasis0,
49 const LibUtilities::BasisKey &fbasis1,
51 const LibUtilities::BasisKey &tbasis0,
52 const LibUtilities::BasisKey &tbasis1)
53{
54 const size_t fnm0 = fbasis0.GetNumModes();
55 const size_t fnm1 = fbasis1.GetNumModes();
56 const size_t tnm0 = tbasis0.GetNumModes();
57 const size_t tnm1 = tbasis1.GetNumModes();
58
59 DNekMatSharedPtr ft0 = LibUtilities::BasisManager()[fbasis0]->GetI(tbasis0);
60 DNekMatSharedPtr ft1 = LibUtilities::BasisManager()[fbasis1]->GetI(tbasis1);
61
62 Array<OneD, NekDouble> expected(tnm0 * tnm1, 0.0);
63 for (size_t i1 = 0; i1 < tnm1; ++i1)
64 {
65 for (size_t i0 = 0; i0 < tnm0; ++i0)
66 {
67 for (size_t j1 = 0; j1 < fnm1; ++j1)
68 {
69 for (size_t j0 = 0; j0 < fnm0; ++j0)
70 {
71 expected[i0 + tnm0 * i1] +=
72 (*ft0)(i0, j0) * from[j0 + fnm0 * j1] * (*ft1)(i1, j1);
73 }
74 }
75 }
76 }
77
78 return expected;
79}
80
82 const LibUtilities::BasisKey &fbasis0,
83 const LibUtilities::BasisKey &fbasis1,
84 const LibUtilities::BasisKey &fbasis2,
86 const LibUtilities::BasisKey &tbasis0,
87 const LibUtilities::BasisKey &tbasis1,
88 const LibUtilities::BasisKey &tbasis2)
89{
90 const size_t fnm0 = fbasis0.GetNumModes();
91 const size_t fnm1 = fbasis1.GetNumModes();
92 const size_t fnm2 = fbasis2.GetNumModes();
93 const size_t tnm0 = tbasis0.GetNumModes();
94 const size_t tnm1 = tbasis1.GetNumModes();
95 const size_t tnm2 = tbasis2.GetNumModes();
96
97 DNekMatSharedPtr ft0 = LibUtilities::BasisManager()[fbasis0]->GetI(tbasis0);
98 DNekMatSharedPtr ft1 = LibUtilities::BasisManager()[fbasis1]->GetI(tbasis1);
99 DNekMatSharedPtr ft2 = LibUtilities::BasisManager()[fbasis2]->GetI(tbasis2);
100
101 Array<OneD, NekDouble> expected(tnm0 * tnm1 * tnm2, 0.0);
102 for (size_t i2 = 0; i2 < tnm2; ++i2)
103 {
104 for (size_t i1 = 0; i1 < tnm1; ++i1)
105 {
106 for (size_t i0 = 0; i0 < tnm0; ++i0)
107 {
108 for (size_t j2 = 0; j2 < fnm2; ++j2)
109 {
110 for (size_t j1 = 0; j1 < fnm1; ++j1)
111 {
112 for (size_t j0 = 0; j0 < fnm0; ++j0)
113 {
114 expected[i0 + tnm0 * (i1 + tnm1 * i2)] +=
115 (*ft0)(i0, j0) * (*ft1)(i1, j1) *
116 (*ft2)(i2, j2) *
117 from[j0 + fnm0 * (j1 + fnm1 * j2)];
118 }
119 }
120 }
121 }
122 }
123 }
124
125 return expected;
126}
127
128BOOST_AUTO_TEST_CASE(TestInterpCoeff2DDifferentOrdersAndBases)
129{
130 using namespace LibUtilities;
131
133 const BasisKey fbasis1(eOrtho_A, 4, PointsKey(6, eGaussLobattoLegendre));
134 const BasisKey tbasis0(eOrtho_A, 5, PointsKey(7, eGaussLobattoLegendre));
136
137 Array<OneD, NekDouble> coeffs(fbasis0.GetNumModes() *
138 fbasis1.GetNumModes());
139 for (size_t i = 0; i < coeffs.size(); ++i)
140 {
141 coeffs[i] = 0.125 + 0.25 * static_cast<NekDouble>(i);
142 }
143
144 Array<OneD, NekDouble> actual(tbasis0.GetNumModes() *
145 tbasis1.GetNumModes());
146 Array<OneD, NekDouble> expected =
147 TensorProductInterp2D(fbasis0, fbasis1, coeffs, tbasis0, tbasis1);
148
149 LibUtilities::InterpCoeff2D(fbasis0, fbasis1, coeffs, tbasis0, tbasis1,
150 actual);
151
152 BOOST_REQUIRE_EQUAL(expected.size(), actual.size());
153
154 const NekDouble epsilon = 1.0e-10;
155 for (size_t i = 0; i < expected.size(); ++i)
156 {
157 BOOST_CHECK_SMALL(std::abs(expected[i] - actual[i]), epsilon);
158 }
159}
160
161BOOST_AUTO_TEST_CASE(TestInterpCoeff3DDifferentOrdersAndBases)
162{
163 using namespace LibUtilities;
164
166 const BasisKey fbasis1(eOrtho_A, 3, PointsKey(5, eGaussLobattoLegendre));
168 const BasisKey tbasis0(eOrtho_A, 4, PointsKey(6, eGaussLobattoLegendre));
170 const BasisKey tbasis2(eOrtho_A, 6, PointsKey(8, eGaussLobattoLegendre));
171
173 fbasis0.GetNumModes() * fbasis1.GetNumModes() * fbasis2.GetNumModes());
174 for (size_t i = 0; i < coeffs.size(); ++i)
175 {
176 coeffs[i] = 0.2 + 0.1 * static_cast<NekDouble>((3 * i) % 11);
177 }
178
180 tbasis0.GetNumModes() * tbasis1.GetNumModes() * tbasis2.GetNumModes());
182 fbasis0, fbasis1, fbasis2, coeffs, tbasis0, tbasis1, tbasis2);
183
184 LibUtilities::InterpCoeff3D(fbasis0, fbasis1, fbasis2, coeffs, tbasis0,
185 tbasis1, tbasis2, actual);
186
187 BOOST_REQUIRE_EQUAL(expected.size(), actual.size());
188
189 const NekDouble epsilon = 1.0e-10;
190 for (size_t i = 0; i < expected.size(); ++i)
191 {
192 BOOST_CHECK_SMALL(std::abs(expected[i] - actual[i]), epsilon);
193 }
194}
195} // namespace Nektar::UnitTests
Describes the specification for a Basis.
Definition Basis.h:45
int GetNumModes() const
Returns the order of the basis.
Definition Basis.h:74
Defines a specification for a set of points.
Definition Points.h:50
BasisManagerT & BasisManager(void)
void InterpCoeff2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
void InterpCoeff3D(const BasisKey &fbasis0, const BasisKey &fbasis1, const BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, const BasisKey &tbasis2, Array< OneD, NekDouble > &to)
@ 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
Array< OneD, NekDouble > TensorProductInterp3D(const LibUtilities::BasisKey &fbasis0, const LibUtilities::BasisKey &fbasis1, const LibUtilities::BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const LibUtilities::BasisKey &tbasis0, const LibUtilities::BasisKey &tbasis1, const LibUtilities::BasisKey &tbasis2)
Array< OneD, NekDouble > TensorProductInterp2D(const LibUtilities::BasisKey &fbasis0, const LibUtilities::BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const LibUtilities::BasisKey &tbasis0, const LibUtilities::BasisKey &tbasis1)
BOOST_AUTO_TEST_CASE(TestCanGetRawPtr)
std::shared_ptr< DNekMat > DNekMatSharedPtr