www.mooseframework.org
Cartesian.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
16 TEST(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 
27 TEST(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  EXPECT_NEAR(answer[i], truth[i], tol);
56 }
57 
58 TEST(FunctionalExpansionsTest, legendreSeriesSqrtMuEvaluation)
59 {
60  const unsigned int order = 15;
61  Real location = -0.90922108754014;
62  const std::array<Real, order> truth = {{0.50000000000000,
63  -1.36383163131021,
64  1.85006119760378,
65  -1.80341832197563,
66  1.19175581122701,
67  -0.11669847057321,
68  -1.20462734483853,
69  2.48341349094950,
70  -3.41981864606651,
71  3.76808851494207,
72  -3.39261995754146,
73  2.30300489952095,
74  -0.66011244776270,
75  -1.24901920248131,
76  3.06342136027001}};
77 
79  {order},
80  expansion_type = "standard",
81  generation_type = "sqrt_mu");
82 
83  legendre.setLocation(Point(location));
84  auto & answer = legendre.getAllGeneration();
85  for (std::size_t i = 0; i < order; ++i)
86  EXPECT_NEAR(answer[i], truth[i] / std::sqrt(i + 0.5), tol);
87 }
88 
89 TEST(FunctionalExpansionsTest, legendreSeriesStandardEvaluation)
90 {
91  const unsigned int order = 15;
92  Real location = -0.90922108754014;
93  const std::array<Real, order> truth = {{0.50000000000000,
94  -1.36383163131021,
95  1.85006119760378,
96  -1.80341832197563,
97  1.19175581122701,
98  -0.11669847057321,
99  -1.20462734483853,
100  2.48341349094950,
101  -3.41981864606651,
102  3.76808851494207,
103  -3.39261995754146,
104  2.30300489952095,
105  -0.66011244776270,
106  -1.24901920248131,
107  3.06342136027001}};
108 
110  {order},
111  expansion_type = "standard",
112  generation_type = "standard");
113 
114  legendre.setLocation(Point(location));
115  auto & answer = legendre.getAllGeneration();
116  for (std::size_t i = 0; i < order; ++i)
117  EXPECT_NEAR(answer[i], truth[i] / (i + 0.5), tol);
118 }
119 
120 TEST(FunctionalExpansionsTest, CartesianConstructor)
121 {
122  std::vector<MooseEnum> domains;
123  std::vector<std::size_t> orders;
124  std::vector<MooseEnum> series;
125  expansion_type = "standard";
126  generation_type = "orthonormal";
127 
128  domains.push_back(FunctionalBasisInterface::_domain_options = "x");
129  orders = {19};
130  series.push_back(single_series_types_1D = "Legendre");
131  Cartesian legendreOne(domains, orders, series, name, expansion_type, generation_type);
132  EXPECT_EQ(legendreOne.getNumberOfTerms(), orders[0] + 1);
133 
134  domains.push_back(FunctionalBasisInterface::_domain_options = "y");
135  orders = {{13, 15}};
136  series.push_back(single_series_types_1D = "Legendre");
137  Cartesian legendreTwo(domains, orders, series, name, expansion_type, generation_type);
138  EXPECT_EQ(legendreTwo.getNumberOfTerms(), (orders[0] + 1) * (orders[1] + 1));
139 
140  domains.push_back(FunctionalBasisInterface::_domain_options = "z");
141  orders = {{14, 21, 22}};
142  series.push_back(single_series_types_1D = "Legendre");
143  Cartesian legendreThree(domains, orders, series, name, expansion_type, generation_type);
144  EXPECT_EQ(legendreThree.getNumberOfTerms(), (orders[0] + 1) * (orders[1] + 1) * (orders[2] + 1));
145 }
146 
147 TEST(FunctionalExpansionsTest, Cartesian3D)
148 {
149  const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
152  const std::vector<std::size_t> orders = {14, 21, 22};
153  const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
154  single_series_types_1D = "Legendre",
155  single_series_types_1D = "Legendre"};
156 
157  Cartesian legendre3D(
158  domains, orders, series, name, expansion_type = "standard", generation_type = "orthonormal");
159 
160  const std::vector<Point> locations = {
161  Point(-0.14854612627465, 0.60364074055275, 0.76978431165674),
162  Point(0.93801805187856, 0.74175118177279, 0.74211345600994),
163  Point(0.35423736896098, -0.83921049062126, -0.02231845586669)};
164  const std::vector<Real> standard_truth = {1.32257143058688, 3.68047786932034, 0.17515811557416};
165  const std::vector<Real> orthogonal_truth = {
166  -2.33043696271172, 74.48747654183713, -14.48091828923379};
167 
168  for (std::size_t i = 0; i < locations.size(); ++i)
169  {
170  legendre3D.setLocation(locations[i]);
171  EXPECT_NEAR(legendre3D.getExpansionSeriesSum(), standard_truth[i], tol);
172  EXPECT_NEAR(legendre3D.getGenerationSeriesSum(), orthogonal_truth[i], tol);
173  }
174 }
175 
176 TEST(FunctionalExpansionsTest, functionalBasisInterfaceCartesian)
177 {
178  const std::vector<MooseEnum> domains = {FunctionalBasisInterface::_domain_options = "x",
181  const std::vector<std::size_t> orders = {4, 5, 3};
182  const std::vector<MooseEnum> series = {single_series_types_1D = "Legendre",
183  single_series_types_1D = "Legendre",
184  single_series_types_1D = "Legendre"};
185 
186  Cartesian legendre3D(
187  domains, orders, series, name, expansion_type = "standard", generation_type = "orthonormal");
188 
189  const Point location(-0.38541903411291, 0.61369802505416, -0.04539307255549);
190  const Real truth = 0.26458908225718;
191  FunctionalBasisInterface & interface = (FunctionalBasisInterface &)legendre3D;
192 
193  interface.setLocation(location);
194  EXPECT_NEAR(interface.getExpansionSeriesSum(), truth, tol);
195 }
FunctionalBasisInterface::_domain_options
static MooseEnum _domain_options
An enumeration of the domains available to each functional series.
Definition: FunctionalBasisInterface.h:115
single_series_types_1D
MooseEnum single_series_types_1D
FunctionalBasisInterface::getGenerationSeriesSum
Real getGenerationSeriesSum()
Gets the sum of all terms in the generation functional basis.
Definition: FunctionalBasisInterface.C:101
expansion_type
MooseEnum expansion_type
generation_type
MooseEnum generation_type
tol
const double tol
Definition: Setup.h:18
FunctionalBasisInterface::getExpansionSeriesSum
Real getExpansionSeriesSum()
Evaluates the sum of all terms in the expansion functional basis up to #_order.
Definition: FunctionalBasisInterface.C:120
name
const std::string name
Definition: Setup.h:21
CompositeSeriesBasisInterface::setLocation
virtual void setLocation(const Point &p) final
Set the location that will be used by the series to compute values.
Definition: CompositeSeriesBasisInterface.C:287
Legendre
This class provides the algorithms and properties of the Legendre polynomial series.
Definition: Legendre.h:17
SingleSeriesBasisInterface::setLocation
virtual void setLocation(const Point &point) final
Set the location that will be used by the series to compute values.
Definition: SingleSeriesBasisInterface.C:102
Setup.h
TEST
TEST(FunctionalExpansionsTest, legendreConstructor)
Definition: Cartesian.C:16
FunctionalBasisInterface::getNumberOfTerms
std::size_t getNumberOfTerms() const
Returns the number of terms in the series.
Definition: FunctionalBasisInterface.C:88
Cartesian
This class constructs a functional expansion using a separate series for each Cartesian dimension.
Definition: Cartesian.h:18
FunctionalBasisInterface
This class provides the basis for any custom functional basis, and is the parent class of both Single...
Definition: FunctionalBasisInterface.h:23