23 "vectorpostprocessor",
24 "The vectorpostprocessor on whose values we perform a least squares fit");
25 params.
addRequiredParam<std::string>(
"x_name",
"The name of the independent variable");
26 params.
addRequiredParam<std::string>(
"y_name",
"The name of the dependent variable");
27 params.
addRequiredParam<
unsigned int>(
"order",
"The order of the polynomial fit");
31 "Truncate the order of the fitted polynomial if an insufficient number of data points are "
32 "provided. If this is set to false, an error will be generated in that case.");
34 "x_scale", 1.0,
"Value used to scale x values (scaling is done after shifting)");
36 "x_shift", 0.0,
"Value used to shift x values (shifting is done before scaling)");
38 "y_scale", 1.0,
"Value used to scale y values (scaling is done after shifting)");
40 "y_shift", 0.0,
"Value used to shift y values (shifting is done before scaling)");
42 "Performs a polynomial least squares fit on the data contained in "
43 "another VectorPostprocessor and stores the full time history of the coefficients");
45 params.
set<
bool>(
"contains_complete_history") =
true;
53 _vpp_name(getParam<VectorPostprocessorName>(
"vectorpostprocessor")),
54 _order(parameters.get<unsigned
int>(
"order")),
55 _truncate_order(parameters.get<bool>(
"truncate_order")),
56 _x_name(getParam<
std::string>(
"x_name")),
57 _y_name(getParam<
std::string>(
"y_name")),
58 _x_values(getVectorPostprocessorValue(
"vectorpostprocessor", _x_name)),
59 _y_values(getVectorPostprocessorValue(
"vectorpostprocessor", _y_name)),
60 _x_scale(parameters.get<Real>(
"x_scale")),
61 _x_shift(parameters.get<Real>(
"x_shift")),
62 _y_scale(parameters.get<Real>(
"y_scale")),
63 _y_shift(parameters.get<Real>(
"y_shift")),
64 _last_t_step(declareRecoverableData<
int>(
"ls_last_t_step", -1))
67 for (
unsigned int i = 0; i <
_coeffs.size(); ++i)
82 mooseError(
"In LeastSquresFitTimeHistory size of data in x_values and y_values must be equal");
84 mooseError(
"In LeastSquresFitTimeHistory size of data in x_values and y_values must be > 0");
89 std::for_each(
_coeffs.begin(),
_coeffs.end(), [](
auto coeff) { coeff->pop_back(); });
109 mooseAssert(coeffs.size() ==
_coeffs.size(),
110 "Sizes of current coefficients and vector of coefficient vectors must match");
111 for (MooseIndex(coeffs) i = 0; i < coeffs.size(); ++i)
112 _coeffs[i]->push_back(coeffs[i]);
registerMooseObject("MooseApp", LeastSquaresFitHistory)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void ErrorVector unsigned int
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
static InputParameters validParams()
virtual void generate()
Generate the fit.
const std::vector< Real > & getCoefficients()
Const reference to the vector of coefficients of the least squares fit.
LeastSquaresFitHistory is a VectorPostprocessor that performs a least squares fit on data calculated ...
std::vector< VectorPostprocessorValue * > _coeffs
Vector of vectors with the individual coefficients.
int & _last_t_step
The last timestep that this object operated on.
const VectorPostprocessorValue & _y_values
const VectorPostprocessorValue & _x_values
The variables with the x, y data to be fit.
VectorPostprocessorValue * _times
Vector of times.
virtual void execute() override
Perform the least squares fit.
const Real _x_scale
Values used to scale and or shift x and y data.
LeastSquaresFitHistory(const InputParameters ¶meters)
Class constructor.
static InputParameters validParams()
const unsigned int _order
The order of the polynomial fit to be performed.
virtual void initialize() override
Initialize, clears old results.
const bool _truncate_order
Whether to truncate the polynomial order if an insufficient number of points is provided.
Least squares polynomial fit.
int & _t_step
The number of the time step.
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
std::string stringify(const T &t)
conversion to string