https://mooseframework.inl.gov
FunctionalBasisInterface.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 
11 
13 
14 /*
15  * The default constructor is used to initialize a series before knowing the number of terms in the
16  * series. This is called from the CSBI, and in the body of the CSBI constructor, setNumberOfTerms()
17  * is used to after-the-fact perform the same initializations that would be done with the
18  * non-default constructor.
19  */
21  : _is_cache_invalid(true), _is_generation(false)
22 {
23 }
24 
25 /*
26  * The non-default constructor should be used to initialize a series if the number of terms is
27  * known, such as with a single series.
28  */
29 FunctionalBasisInterface::FunctionalBasisInterface(const unsigned int number_of_terms)
30  : _number_of_terms(number_of_terms),
31  _is_cache_invalid(true),
33  _is_generation(false)
34 {
35  _basis_evaluation.shrink_to_fit();
36 }
37 
38 Real
39 FunctionalBasisInterface::operator[](std::size_t index) const
40 {
41  return (index > _basis_evaluation.size() ? 0.0 : _basis_evaluation[index]);
42 }
43 
44 bool
46 {
47  return _is_generation;
48 }
49 
50 bool
52 {
53  return !_is_generation;
54 }
55 
56 const std::vector<Real> &
58 {
59  if (isExpansion() || isCacheInvalid())
60  {
62 
64 
65  _is_generation = true;
66  _is_cache_invalid = false;
67  }
68 
69  return _basis_evaluation;
70 }
71 
72 const std::vector<Real> &
74 {
75  if (isGeneration() || isCacheInvalid())
76  {
78 
80 
81  _is_generation = false;
82  _is_cache_invalid = false;
83  }
84 
85  return _basis_evaluation;
86 }
87 
88 std::size_t
90 {
91  return _number_of_terms;
92 }
93 
94 Real
96 {
97  // Use getAllGeneration() which will lazily evaluate the series as needed
98  return getAllGeneration().back();
99 }
100 
101 Real
103 {
104  Real sum = 0.0;
105 
106  // Use getAllGeneration() which will lazily evaluate the series as needed
107  for (auto term : getAllGeneration())
108  sum += term;
109 
110  return sum;
111 }
112 
113 Real
115 {
116  // Use getAllExpansion() which will lazily evaluate the series as needed
117  return getAllExpansion().back();
118 }
119 
120 Real
122 {
123  Real sum = 0.0;
124 
125  // Use getAllExpansion() which will lazily evaluate the series as needed
126  for (auto term : getAllExpansion())
127  sum += term;
128 
129  return sum;
130 }
131 
132 Real
133 FunctionalBasisInterface::load(std::size_t index) const
134 {
135  return _basis_evaluation[index];
136 }
137 
138 void
139 FunctionalBasisInterface::save(std::size_t index, Real value)
140 {
141  _basis_evaluation[index] = value;
142 }
143 
144 void
145 FunctionalBasisInterface::clearBasisEvaluation(const unsigned int & number_of_terms)
146 {
147  _basis_evaluation.assign(number_of_terms, 0.0);
148  _basis_evaluation.shrink_to_fit();
149 }
std::vector< Real > _basis_evaluation
Stores the values of the basis evaluation.
virtual void evaluateExpansion()=0
Evaluate the expansion form of the functional basis.
Real getExpansion()
Gets the #_order-th term of the expansion functional basis.
Real operator[](std::size_t index) const
Returns the current evaluation at the given index.
bool _is_generation
Indicates whether the current evaluation is expansion or generation.
Real getGeneration()
Gets the last term of the generation functional basis.
const std::vector< Real > & getAllExpansion()
Returns an array reference containing the value of each expansion term.
unsigned int _number_of_terms
The number of terms in the series.
static MooseEnum _domain_options
An enumeration of the domains available to each functional series.
virtual void clearBasisEvaluation(const unsigned int &number_of_terms)
Set all entries of the basis evaluation to zero.
void save(std::size_t index, Real value)
Helper function to store a value in #_series.
Real getGenerationSeriesSum()
Gets the sum of all terms in the generation functional basis.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< Real > & getAllGeneration()
Returns an array reference containing the value of each generation term.
virtual bool isCacheInvalid() const =0
Whether the cached values correspond to the current point.
bool isExpansion() const
Returns true if the current evaluation is expansion.
Real getExpansionSeriesSum()
Evaluates the sum of all terms in the expansion functional basis up to #_order.
Real load(std::size_t index) const
Helper function to load a value from #_series.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void evaluateGeneration()=0
Evaluate the generation form of the functional basis.
std::size_t getNumberOfTerms() const
Returns the number of terms in the series.
bool isGeneration() const
Returns true if the current evaluation is generation.
bool _is_cache_invalid
indicates if the evaluated values correspond to the current location