https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FXIntegralBaseUserObject.h
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#pragma once
11
12#include "AuxiliarySystem.h"
13#include "MooseError.h"
14#include "MooseMesh.h"
15#include "MooseVariable.h"
16#include "UserObject.h"
17
18#include "libmesh/quadrature.h"
19
20#include "FunctionSeries.h"
22
31template <class IntegralBaseVariableUserObject>
32class FXIntegralBaseUserObject : public IntegralBaseVariableUserObject,
34{
35public:
37
39
44
45 // Override from <IntegralBaseVariableUserObject>
46 virtual Real getValue() const final;
47
48 // Overrides from UserObject
49 virtual void finalize() final;
50 virtual void initialize() final;
51 virtual Real spatialValue(const Point & location) const final;
52 virtual void threadJoin(const UserObject & sibling) final;
53
54protected:
55 // Policy-based design requires us to specify which inherited members we are using
56 using IntegralBaseVariableUserObject::_communicator;
57 using IntegralBaseVariableUserObject::_console;
58 using IntegralBaseVariableUserObject::_coord;
59 using IntegralBaseVariableUserObject::_integral_value;
60 using IntegralBaseVariableUserObject::_JxW;
61 using IntegralBaseVariableUserObject::_q_point;
62 using IntegralBaseVariableUserObject::_qp;
63 using IntegralBaseVariableUserObject::_variable;
64 using IntegralBaseVariableUserObject::computeIntegral;
65 using IntegralBaseVariableUserObject::computeQpIntegral;
66 using IntegralBaseVariableUserObject::getFunction;
67 using IntegralBaseVariableUserObject::name;
68
69 // Override from <IntegralBaseVariableUserObject>
70 virtual Real computeIntegral() final;
71
75 virtual Point getCentroid() const = 0;
76
80 virtual Real getVolume() const = 0;
81
83 std::vector<std::vector<Real>> _coefficient_history;
84
87
90
92 const bool _keep_history;
93
95 const bool _print_state;
96
99
102};
103
104template <class IntegralBaseVariableUserObject>
106FXIntegralBaseUserObject<IntegralBaseVariableUserObject>::validParams()
107{
108 InputParameters params = IntegralBaseVariableUserObject::validParams();
110
111 params.addClassDescription(
112 "This UserObject interacts with a MooseApp through functional expansions.");
113
114 params.addRequiredParam<FunctionName>("function",
115 "The name of the FunctionSeries \"Function\" object with "
116 "which to generate this functional expansion.");
117
118 params.addParam<bool>(
119 "keep_history", false, "Keep the expansion coefficients from previous solves");
120
121 params.addParam<bool>("print_state", false, "Print the state of the zeroth instance each solve");
122
123 return params;
124}
125
126template <class IntegralBaseVariableUserObject>
128 const InputParameters & parameters)
129 : IntegralBaseVariableUserObject(parameters),
130 MutableCoefficientsInterface(this, parameters),
132 FunctionSeries::checkAndConvertFunction(getFunction("function"), this->getBase(), name())),
133 _keep_history(UserObject::getParam<bool>("keep_history")),
134 _print_state(UserObject::getParam<bool>("print_state")),
135 _standardized_function_volume(_function_series.getStandardizedFunctionVolume())
136{
137 // Size the coefficient arrays
141
142 if (!_keep_history)
143 _coefficient_history.resize(0);
144}
145
146template <class IntegralBaseVariableUserObject>
147Real
149{
150 Real sum = 0.0;
151 const Point centroid = getCentroid();
152
153 // Check to see if this element/side is within the valid boundaries
154 if (!_function_series.isInPhysicalBounds(centroid))
155 return 0.0;
156
157 // Loop over the quadrature points
158 for (_qp = 0; _qp < _q_point.size(); ++_qp)
159 {
160 // Get the functional terms for a vectorized approach
161 _function_series.setLocation(_q_point[_qp]);
162 const std::vector<Real> & term_evaluations = _function_series.getGeneration();
163
164 // Evaluate the functional expansion coefficients at each quadrature point
165 const Real local_contribution = computeQpIntegral();
166 const Real common_evaluation = local_contribution * _JxW[_qp] * _coord[_qp];
167 for (std::size_t c = 0; c < _coefficient_partials.size(); ++c)
168 _coefficient_partials[c] += term_evaluations[c] * common_evaluation;
169
170 sum += local_contribution;
171 }
172
173 _volume += getVolume();
174
175 return sum;
176}
177
178template <class IntegralBaseVariableUserObject>
179void
181{
182 // Sum the coefficient arrays over all processes
183 _communicator.sum(_coefficient_partials);
184 _communicator.sum(_volume);
185
186 // Normalize the volume of the functional expansion to the FX standard space
187 const Real volume_normalization = _standardized_function_volume / _volume;
188 for (auto & partial : _coefficient_partials)
189 partial *= volume_normalization;
190
191 // We now have the completely evaluated coefficients
192 _coefficients = _coefficient_partials;
193
194 // The average value is the same as the zeroth coefficient
195 _integral_value = _coefficient_partials[0];
196
197 if (_keep_history)
198 _coefficient_history.push_back(_coefficients);
199
200 if (_print_state)
201 {
202 _function_series.setCoefficients(_coefficients);
203 _console << COLOR_YELLOW << _function_series << COLOR_DEFAULT << std::endl;
204 }
205}
206
207template <class IntegralBaseVariableUserObject>
208const FunctionSeries &
213
214template <class IntegralBaseVariableUserObject>
215Real
217{
218 return _integral_value;
219}
220
221template <class IntegralBaseVariableUserObject>
222void
224{
225 IntegralBaseVariableUserObject::initialize();
226
227 // Clear the partial sums
228 for (auto & partial : _coefficient_partials)
229 partial = 0;
230
231 _volume = 0;
232}
233
234template <class IntegralBaseVariableUserObject>
235void
237{
240
241 for (std::size_t c = 0; c < _coefficient_partials.size(); ++c)
242 _coefficient_partials[c] += sibling._coefficient_partials[c];
243
244 _volume += sibling._volume;
245}
246
247template <class IntegralBaseVariableUserObject>
248Real
250{
251 _function_series.setLocation(location);
252
253 return _function_series.expand(_coefficients);
254}
const std::string name
Definition Setup.h:21
This class interacts with a MooseApp through functional expansions.
const bool _print_state
Flag to prints the state of the zeroth instance in finalize()
const Real _standardized_function_volume
Volume of the standardized functional space of integration.
FXIntegralBaseUserObject(const InputParameters &parameters)
std::vector< std::vector< Real > > _coefficient_history
History of the expansion coefficients for each solve.
virtual void threadJoin(const UserObject &sibling) final
FunctionSeries & _function_series
Reference to the underlying function series.
virtual Real spatialValue(const Point &location) const final
static InputParameters validParams()
virtual Real getVolume() const =0
Get the volume of the evaluated unit.
std::vector< Real > _coefficient_partials
Current coefficient partial sums.
const FunctionSeries & getFunctionSeries() const
Return a reference to the underlying function series.
Real _volume
Moose volume of evaluation.
const bool _keep_history
Keep the expansion coefficients after each solve.
virtual Real getValue() const final
virtual Point getCentroid() const =0
Get the centroid of the evaluated unit.
This class uses implementations of CompositeSeriesBasisInterface to generate a function based on conv...
std::size_t getNumberOfTerms() const
Returns the number of terms (coefficients) in the underlying function series.
const std::vector< std::size_t > & getOrders() const
Returns a vector of the functional orders in the underlying functional series.
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
This class is designed to provide a uniform interface for any class that uses an array of coefficient...
std::vector< std::size_t > & _characteristics
An array of integer characteristics that can be used to check compatibility.
const ConsoleStream & _console
MooseObject instance of this to provide access to _console
std::vector< Real > & _coefficients
The coefficient array.
void resize(std::size_t size, Real fill=0.0, bool fill_out_to_size=true)
Resize the array, using the value for fill if the new size is larger.