https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CylindricalDuo.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "gtest/gtest.h"
11
12#include <array>
13
14#include "Setup.h"
15
16TEST(FunctionalExpansionsTest, zernikeConstructor)
17{
18 const unsigned int order = 5;
19 expansion_type = "orthonormal";
20 generation_type = "standard";
23 {order},
26 EXPECT_EQ(zernike.getOrder(0), order);
27}
28
29TEST(FunctionalExpansionsTest, zernikeSeriesEvaluationXY)
30{
31 const unsigned int order = 4;
32 const Point location(-0.90922108754014, 0.262698547343, 0.156796889218);
33 expansion_type = "standard";
34 generation_type = "orthonormal";
35
38 {order},
41 zernike.setLocation(location);
42 const std::array<Real, 15> truth = {{0.318309886183791,
43 -0.300628811510287,
44 -1.117940202314423,
45 0.791881706198328,
46 0.623918544603900,
47 1.365900806059890,
48 -1.357069098439213,
49 -0.288633095470502,
50 -1.073332058640328,
51 -1.349767446988918,
52 1.887803726543957,
53 0.404825692079851,
54 0.223343150486739,
55 0.698275682841869,
56 1.080889714660983}};
57
58 auto & answer = zernike.getAllGeneration();
59 for (std::size_t i = 0; i < zernike.getNumberOfTerms(); ++i)
60 EXPECT_NEAR(answer[i], truth[i], tol);
61}
62
63TEST(FunctionalExpansionsTest, zernikeSeriesEvaluationXZ)
64{
65 const unsigned int order = 4;
66 const Point location(-0.90922108754014, 0.262698547343, 0.156796889218);
67 expansion_type = "standard";
68 generation_type = "orthonormal";
69
72 {order},
75 zernike.setLocation(location);
76 const std::array<Real, 15> truth = {{0.318309886183791,
77 -0.180774038043348,
78 -1.143454732567233,
79 0.487041727962393,
80 0.623918544603900,
81 1.501849527692451,
82 -0.867504286868072,
83 -0.173560777222340,
84 -1.097828505968007,
85 -1.706149176114187,
86 1.276644449771070,
87 0.248985426801565,
88 0.223343150486739,
89 0.767775375651402,
90 1.761335979897610}};
91
92 auto & answer = zernike.getAllGeneration();
93 for (std::size_t i = 0; i < zernike.getNumberOfTerms(); ++i)
94 EXPECT_NEAR(answer[i], truth[i], tol);
95}
96
97TEST(FunctionalExpansionsTest, zernikeSeriesEvaluationYZ)
98{
99 const unsigned int order = 4;
100 const Point location(-0.90922108754014, 0.262698547343, 0.156796889218);
101 expansion_type = "standard";
102 generation_type = "orthonormal";
103
106 {order},
109 zernike.setLocation(location);
110 const std::array<Real, 15> truth = {{0.318309886183791,
111 0.052230505695590,
112 0.330374978445085,
113 0.040657672622662,
114 -0.823129261009826,
115 0.125372638358686,
116 0.020923587239414,
117 -0.187295294511344,
118 -1.184703806003468,
119 0.041151106306071,
120 0.008896570968308,
121 -0.184582980412102,
122 0.978025517529447,
123 -0.569182979683797,
124 0.012274247968574}};
125
126 auto & answer = zernike.getAllGeneration();
127 for (std::size_t i = 0; i < zernike.getNumberOfTerms(); ++i)
128 EXPECT_NEAR(answer[i], truth[i], tol);
129}
130
131TEST(FunctionalExpansionsTest, zernikeSeriesSqrtMuEvaluation)
132{
133 const unsigned int order = 4;
134 const Point location(-0.90922108754014, 0.262698547343, 0.156796889218);
135 expansion_type = "standard";
136 generation_type = "sqrt_mu";
137
140 {order},
143 zernike.setLocation(location);
144 const std::array<Real, 15> truth = {{0.318309886183791,
145 0.052230505695590,
146 0.330374978445085,
147 0.040657672622662,
148 -0.823129261009826,
149 0.125372638358686,
150 0.020923587239414,
151 -0.187295294511344,
152 -1.184703806003468,
153 0.041151106306071,
154 0.008896570968308,
155 -0.184582980412102,
156 0.978025517529447,
157 -0.569182979683797,
158 0.012274247968574}};
159
160 auto & answer = zernike.getAllGeneration();
161 EXPECT_NEAR(answer[0], truth[0] * std::sqrt(M_PI), tol);
162 size_t i = 1;
163 for (size_t n = 1; n < order + 1; ++n)
164 {
165 for (size_t m = 0; m < n + 1; ++m)
166 {
167 if (m != 0 && n / m == 2 && n % m == 0)
168 EXPECT_NEAR(answer[i], truth[i] * std::sqrt(M_PI / (n + 1)), tol);
169 else
170 EXPECT_NEAR(answer[i], truth[i] * std::sqrt(M_PI / (2 * n + 2)), tol);
171 ++i;
172 }
173 }
174}
175
176TEST(FunctionalExpansionsTest, zernikeSeriesStandardEvaluation)
177{
178 const unsigned int order = 4;
179 const Point location(-0.90922108754014, 0.262698547343, 0.156796889218);
180 expansion_type = "standard";
181 generation_type = "standard";
182
185 {order},
188 zernike.setLocation(location);
189 const std::array<Real, 15> truth = {{0.318309886183791,
190 0.052230505695590,
191 0.330374978445085,
192 0.040657672622662,
193 -0.823129261009826,
194 0.125372638358686,
195 0.020923587239414,
196 -0.187295294511344,
197 -1.184703806003468,
198 0.041151106306071,
199 0.008896570968308,
200 -0.184582980412102,
201 0.978025517529447,
202 -0.569182979683797,
203 0.012274247968574}};
204
205 auto & answer = zernike.getAllGeneration();
206 EXPECT_NEAR(answer[0], truth[0] * M_PI, tol);
207 size_t i = 1;
208 for (size_t n = 1; n < order + 1; ++n)
209 {
210 for (size_t m = 0; m < n + 1; ++m)
211 {
212 if (m != 0 && n / m == 2 && n % m == 0)
213 EXPECT_NEAR(answer[i], truth[i] * M_PI / (n + 1), tol);
214 else
215 EXPECT_NEAR(answer[i], truth[i] * M_PI / (2 * n + 2), tol);
216 ++i;
217 }
218 }
219}
220
221TEST(FunctionalExpansionsTest, cylindricalDuoConstructorAxialX)
222{
223 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
226 const std::vector<std::size_t> orders = {5, 18};
227 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
228 single_series_types_2D = "Zernike"};
229 expansion_type = "standard";
230 generation_type = "orthonormal";
231
232 CylindricalDuo cylindrical(domains, orders, series, name, expansion_type, generation_type);
233 EXPECT_EQ(cylindrical.getNumberOfTerms(),
234 (orders[0] + 1) * ((orders[1] + 1) * (orders[1] + 2)) / 2);
235}
236
237TEST(FunctionalExpansionsTest, cylindricalDuoConstructorAxialY)
238{
239 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "y",
242 const std::vector<std::size_t> orders = {23, 8};
243 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
244 single_series_types_2D = "Zernike"};
245 expansion_type = "standard";
246 generation_type = "orthonormal";
247
248 CylindricalDuo cylindrical(domains, orders, series, name, expansion_type, generation_type);
249 EXPECT_EQ(cylindrical.getNumberOfTerms(),
250 (orders[0] + 1) * ((orders[1] + 1) * (orders[1] + 2)) / 2);
251}
252
253TEST(FunctionalExpansionsTest, cylindricalDuoConstructorAxialZ)
254{
255 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "z",
258 const std::vector<std::size_t> orders = {21, 23};
259 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
260 single_series_types_2D = "Zernike"};
261 expansion_type = "standard";
262 generation_type = "orthonormal";
263
264 CylindricalDuo cylindrical(domains, orders, series, name, expansion_type, generation_type);
265 EXPECT_EQ(cylindrical.getNumberOfTerms(),
266 (orders[0] + 1) * ((orders[1] + 1) * (orders[1] + 2)) / 2);
267}
268
269TEST(FunctionalExpansionsTest, cylindricalDuoEvaluator)
270{
271 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
274 const std::vector<std::size_t> orders = {15, 17};
275 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
276 single_series_types_2D = "Zernike"};
277 expansion_type = "standard";
278 generation_type = "orthonormal";
279
280 CylindricalDuo cylindrical(domains, orders, series, name, expansion_type, generation_type);
281
282 const std::vector<Point> locations = {
283 Point(-0.14854612627465, 0.60364074055275, 0.76978431165674),
284 Point(0.93801805187856, 0.74175118177279, 0.45207131996044),
285 Point(0.35423736896098, -0.83921049062126, -0.02231845586669)};
286 const std::vector<Real> standard_truth = {
287 0.42889689399543629, 4.3724388003439207, 0.82275646257084989};
288 const std::vector<Real> orthogonal_truth = {
289 -10.386457517518826, -161.7959192066881, -3.9949571266605481};
290
291 for (std::size_t i = 0; i < locations.size(); ++i)
292 {
293 cylindrical.setLocation(locations[i]);
294 // loose tolerances due to diffs with -march=x86-64-v3
295 EXPECT_NEAR(cylindrical.getExpansionSeriesSum(), standard_truth[i], 5.e-12);
296 EXPECT_NEAR(cylindrical.getGenerationSeriesSum(), orthogonal_truth[i], 5.e-10);
297 }
298}
299
300TEST(FunctionalExpansionsTest, functionalBasisInterfaceCylindrical)
301{
302 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
305 const std::vector<std::size_t> orders = {4, 5};
306 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
307 single_series_types_2D = "Zernike"};
308 expansion_type = "standard";
309 generation_type = "orthonormal";
310
311 CylindricalDuo cylindrical(domains, orders, series, name, expansion_type, generation_type);
312
313 const Point location(-0.38541903411291, 0.61369802505416, -0.04539307255549);
314 const Real truth = 0.10414963426362565;
315 FunctionalBasisInterface & interface = (FunctionalBasisInterface &)cylindrical;
316
317 interface.setLocation(location);
318 EXPECT_NEAR(interface.getExpansionSeriesSum(), truth, tol);
319}
const double tol
MooseEnum expansion_type
const std::string name
Definition Setup.h:21
MooseEnum single_series_types_2D
MooseEnum generation_type
MooseEnum single_series_types_1D
virtual void setLocation(const Point &p) final
Set the location that will be used by the series to compute values.
This class constructs a functional expansion in cylindrical space using a 1D series for the axial dir...
This class provides the basis for any custom functional basis, and is the parent class of both Single...
Real getGenerationSeriesSum()
Gets the sum of all terms in the generation functional basis.
Real getExpansionSeriesSum()
Evaluates the sum of all terms in the expansion functional basis up to #_order.
static MooseEnum _domain_options
An enumeration of the domains available to each functional series.
std::size_t getNumberOfTerms() const
Returns the number of terms in the series.
virtual void setLocation(const Point &point) final
Set the location that will be used by the series to compute values.
This class provides the algorithms and properties of the Zernike polynomial series.
Definition Zernike.h:18
TEST(FunctionalExpansionsTest, zernikeConstructor)