22 "vectorpostprocessor",
23 "The vectorpostprocessor on whose values we perform a least squares fit");
24 params.
addRequiredParam<std::string>(
"x_name",
"The name of the independent variable");
25 params.
addRequiredParam<std::string>(
"y_name",
"The name of the dependent variable");
26 params.
addRequiredParam<
unsigned int>(
"order",
"The order of the polynomial fit");
30 "Truncate the order of the fitted polynomial if an insufficient number of data points are "
31 "provided. If this is set to false, an error will be generated in that case.");
32 params.
addParam<
unsigned int>(
"num_samples",
"The number of samples to be output");
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)");
41 params.
addParam<Real>(
"sample_x_min",
"The minimum x value of the of samples to be output");
42 params.
addParam<Real>(
"sample_x_max",
"The maximum x value of the of samples to be output");
43 MooseEnum output_type(
"Coefficients Samples",
"Coefficients");
45 "output", output_type,
"The quantity to output. Options are: " + output_type.getRawNames());
46 params.
addClassDescription(
"Performs a polynomial least squares fit on the data contained in "
47 "another VectorPostprocessor");
54 _vpp_name(getParam<VectorPostprocessorName>(
"vectorpostprocessor")),
55 _order(parameters.get<unsigned
int>(
"order")),
56 _truncate_order(parameters.get<bool>(
"truncate_order")),
57 _x_name(getParam<
std::string>(
"x_name")),
58 _y_name(getParam<
std::string>(
"y_name")),
59 _x_values(getVectorPostprocessorValue(
"vectorpostprocessor", _x_name)),
60 _y_values(getVectorPostprocessorValue(
"vectorpostprocessor", _y_name)),
61 _output_type(getParam<
MooseEnum>(
"output")),
63 _x_scale(parameters.get<Real>(
"x_scale")),
64 _x_shift(parameters.get<Real>(
"x_shift")),
65 _y_scale(parameters.get<Real>(
"y_scale")),
66 _y_shift(parameters.get<Real>(
"y_shift")),
67 _have_sample_x_min(isParamValid(
"sample_x_min")),
68 _have_sample_x_max(isParamValid(
"sample_x_max")),
78 mooseError(
"In LeastSquaresFit num_samples parameter must be provided with output=Samples");
91 mooseWarning(
"In LeastSquaresFit num_samples parameter is unused with output=Coefficients");
120 mooseError(
"Size of data in x_values and y_values must be equal");
122 mooseError(
"Size of data in x_values and y_values must be > 0");
143 x_min = *(std::min_element(x_values.begin(), x_values.end()));
149 x_max = *(std::max_element(x_values.begin(), x_values.end()));
151 Real x_span = x_max - x_min;
155 Real x = x_min +
static_cast<Real
>(i) /
_num_samples * x_span;
registerMooseObject("MooseApp", LeastSquaresFit)
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
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.
LeastSquaresFit is a VectorPostprocessor that performs a least squares fit on data calculated in anot...
static InputParameters validParams()
VectorPostprocessorValue * _sample_x
The variables used to write out samples of the least squares fit.
const Real _x_scale
Values used to scale and or shift x and y data.
LeastSquaresFit(const InputParameters ¶meters)
Class constructor.
unsigned int _num_samples
The number of samples to be taken.
const VectorPostprocessorValue & _y_values
Real _sample_x_min
The min and max x values for sampling.
bool _have_sample_x_min
Did the user specify the min and max x values for sampling?
virtual void initialize() override
Initialize, clears old results.
const VectorPostprocessorValue & _x_values
The variables with the x, y data to be fit.
VectorPostprocessorValue * _coeffs
The variable used to write out the coefficients of the fit.
const std::string _x_name
The name of the variables storing the x, y data.
const unsigned int _order
The order of the polynomial fit to be performed.
const bool _truncate_order
Whether to truncate the polynomial order if an insufficient number of points is provided.
virtual void execute() override
Perform the least squares fit.
const MooseEnum _output_type
The type of output.
VectorPostprocessorValue * _sample_y
const std::string _y_name
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Least squares polynomial fit.
virtual Real sample(Real x) override
This function will take an independent variable input and will return the dependent variable based on...
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.