https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Cartesian.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, legendreConstructor)
17{
18 const unsigned int order = 5;
19
21 {order},
22 expansion_type = "orthonormal",
23 generation_type = "standard");
24 EXPECT_EQ(legendre.getOrder(0), order);
25}
26
27TEST(FunctionalExpansionsTest, legendreSeriesOrthonormalEvaluation)
28{
29 const unsigned int order = 15;
30 Real location = -0.90922108754014;
31 const std::array<Real, order> truth = {{0.50000000000000,
32 -1.36383163131021,
33 1.85006119760378,
34 -1.80341832197563,
35 1.19175581122701,
36 -0.11669847057321,
37 -1.20462734483853,
38 2.48341349094950,
39 -3.41981864606651,
40 3.76808851494207,
41 -3.39261995754146,
42 2.30300489952095,
43 -0.66011244776270,
44 -1.24901920248131,
45 3.06342136027001}};
46
48 {order},
49 expansion_type = "standard",
50 generation_type = "orthonormal");
51
52 legendre.setLocation(Point(location));
53 auto & answer = legendre.getAllGeneration();
54 for (std::size_t i = 0; i < order; ++i)
55 // loose tolerances due to diffs with -march=x86-64-v3
56 EXPECT_NEAR(answer[i], truth[i], 1.e-12);
57}
58
59TEST(FunctionalExpansionsTest, legendreSeriesSqrtMuEvaluation)
60{
61 const unsigned int order = 15;
62 Real location = -0.90922108754014;
63 const std::array<Real, order> truth = {{0.50000000000000,
64 -1.36383163131021,
65 1.85006119760378,
66 -1.80341832197563,
67 1.19175581122701,
68 -0.11669847057321,
69 -1.20462734483853,
70 2.48341349094950,
71 -3.41981864606651,
72 3.76808851494207,
73 -3.39261995754146,
74 2.30300489952095,
75 -0.66011244776270,
76 -1.24901920248131,
77 3.06342136027001}};
78
80 {order},
81 expansion_type = "standard",
82 generation_type = "sqrt_mu");
83
84 legendre.setLocation(Point(location));
85 auto & answer = legendre.getAllGeneration();
86 for (std::size_t i = 0; i < order; ++i)
87 // loose tolerances due to diffs with -march=x86-64-v3
88 EXPECT_NEAR(answer[i], truth[i] / std::sqrt(i + 0.5), 5.e-12);
89}
90
91TEST(FunctionalExpansionsTest, legendreSeriesStandardEvaluation)
92{
93 const unsigned int order = 15;
94 Real location = -0.90922108754014;
95 const std::array<Real, order> truth = {{0.50000000000000,
96 -1.36383163131021,
97 1.85006119760378,
98 -1.80341832197563,
99 1.19175581122701,
100 -0.11669847057321,
101 -1.20462734483853,
102 2.48341349094950,
103 -3.41981864606651,
104 3.76808851494207,
105 -3.39261995754146,
106 2.30300489952095,
107 -0.66011244776270,
108 -1.24901920248131,
109 3.06342136027001}};
110
112 {order},
113 expansion_type = "standard",
114 generation_type = "standard");
115
116 legendre.setLocation(Point(location));
117 auto & answer = legendre.getAllGeneration();
118 for (std::size_t i = 0; i < order; ++i)
119 EXPECT_NEAR(answer[i], truth[i] / (i + 0.5), tol);
120}
121
122TEST(FunctionalExpansionsTest, CartesianConstructor)
123{
124 std::vector<MooseEnum> domains;
125 std::vector<std::size_t> orders;
126 std::vector<MooseEnum> series;
127 expansion_type = "standard";
128 generation_type = "orthonormal";
129
130 domains.push_back(FunctionalBasisInterface::_domain_options = "x");
131 orders = {19};
132 series.push_back(single_series_types_1D = "Legendre");
133 Cartesian legendreOne(domains, orders, series, name, expansion_type, generation_type);
134 EXPECT_EQ(legendreOne.getNumberOfTerms(), orders[0] + 1);
135
136 domains.push_back(FunctionalBasisInterface::_domain_options = "y");
137 orders = {{13, 15}};
138 series.push_back(single_series_types_1D = "Legendre");
139 Cartesian legendreTwo(domains, orders, series, name, expansion_type, generation_type);
140 EXPECT_EQ(legendreTwo.getNumberOfTerms(), (orders[0] + 1) * (orders[1] + 1));
141
142 domains.push_back(FunctionalBasisInterface::_domain_options = "z");
143 orders = {{14, 21, 22}};
144 series.push_back(single_series_types_1D = "Legendre");
145 Cartesian legendreThree(domains, orders, series, name, expansion_type, generation_type);
146 EXPECT_EQ(legendreThree.getNumberOfTerms(), (orders[0] + 1) * (orders[1] + 1) * (orders[2] + 1));
147}
148
149TEST(FunctionalExpansionsTest, Cartesian3D)
150{
151 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
154 const std::vector<std::size_t> orders = {14, 21, 22};
155 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
156 single_series_types_1D = "Legendre",
157 single_series_types_1D = "Legendre"};
158
159 Cartesian legendre3D(
160 domains, orders, series, name, expansion_type = "standard", generation_type = "orthonormal");
161
162 const std::vector<Point> locations = {
163 Point(-0.14854612627465, 0.60364074055275, 0.76978431165674),
164 Point(0.93801805187856, 0.74175118177279, 0.74211345600994),
165 Point(0.35423736896098, -0.83921049062126, -0.02231845586669)};
166 const std::vector<Real> standard_truth = {1.32257143058688, 3.68047786932034, 0.17515811557416};
167 const std::vector<Real> orthogonal_truth = {
168 -2.33043696271172, 74.48747654183713, -14.48091828923379};
169
170 for (std::size_t i = 0; i < locations.size(); ++i)
171 {
172 legendre3D.setLocation(locations[i]);
173 // loose tolerances due to diffs with -march=x86-64-v3
174 EXPECT_NEAR(legendre3D.getExpansionSeriesSum(), standard_truth[i], 5.e-12);
175 EXPECT_NEAR(legendre3D.getGenerationSeriesSum(), orthogonal_truth[i], 5.e-10);
176 }
177}
178
179TEST(FunctionalExpansionsTest, functionalBasisInterfaceCartesian)
180{
181 const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
184 const std::vector<std::size_t> orders = {4, 5, 3};
185 const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
186 single_series_types_1D = "Legendre",
187 single_series_types_1D = "Legendre"};
188
189 Cartesian legendre3D(
190 domains, orders, series, name, expansion_type = "standard", generation_type = "orthonormal");
191
192 const Point location(-0.38541903411291, 0.61369802505416, -0.04539307255549);
193 const Real truth = 0.26458908225718;
194 FunctionalBasisInterface & interface = (FunctionalBasisInterface &)legendre3D;
195
196 interface.setLocation(location);
197 EXPECT_NEAR(interface.getExpansionSeriesSum(), truth, tol);
198}
const double tol
MooseEnum expansion_type
const std::string name
Definition Setup.h:21
MooseEnum generation_type
MooseEnum single_series_types_1D
This class constructs a functional expansion using a separate series for each Cartesian dimension.
Definition Cartesian.h:19
virtual void setLocation(const Point &p) final
Set the location that will be used by the series to compute values.
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.
This class provides the algorithms and properties of the Legendre polynomial series.
Definition Legendre.h:18
TEST(FunctionalExpansionsTest, legendreConstructor)
Definition Cartesian.C:16