https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PiecewiseLinearInterpolationMaterial.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
12// MOOSE includes
13#include "MooseVariableFE.h"
14
16
19{
20
22 params.addClassDescription("Compute a property using a piecewise linear interpolation to define "
23 "its dependence on a variable");
24 params.addRequiredParam<std::string>("property",
25 "The name of the property this material will compute");
27 "variable",
28 "The name of the variable whose value is used as the abscissa in the interpolation");
29 params.addParam<std::vector<Real>>("x", "The abscissa values");
30 params.addParam<std::vector<Real>>("y", "The ordinate values");
31 params.addParam<std::vector<Real>>("xy_data",
32 "All function data, supplied in abscissa, ordinate pairs");
33 params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
34 params.addParam<bool>(
35 "extrapolation",
36 false,
37 "Use linear extrapolation to evaluate points that lie outside given data set domain. ");
38 params.declareControllable("scale_factor");
39 return params;
40}
41
43 const InputParameters & parameters)
45 _prop_name(getParam<std::string>("property")),
46 _coupled_var(coupledValue("variable")),
47 _scale_factor(getParam<Real>("scale_factor")),
48 _extrap(getParam<bool>("extrapolation")),
49 _property(declareProperty<Real>(_prop_name)),
50 _dproperty(isCoupledConstant("variable")
51 ? nullptr
52 : &declarePropertyDerivative<Real>(_prop_name, coupledName("variable", 0)))
53{
54 std::vector<Real> x;
55 std::vector<Real> y;
56
58 {
59 if (!((parameters.isParamValid("x")) && (parameters.isParamValid("y"))))
60 mooseError("In PiecewiseLinearInterpolationMaterial ",
61 _name,
62 ": Both 'x' and 'y' must be specified if either one is specified.");
63
64 if (parameters.isParamValid("xy_data"))
65 mooseError("In PiecewiseLinearInterpolationMaterial ",
66 _name,
67 ": Cannot specify 'x', 'y', and 'xy_data' together.");
68
69 x = getParam<std::vector<Real>>("x");
70 y = getParam<std::vector<Real>>("y");
71 }
72 else if (parameters.isParamValid("xy_data"))
73 {
74 std::vector<Real> xy = getParam<std::vector<Real>>("xy_data");
75 unsigned int xy_size = xy.size();
76 if (xy_size % 2 != 0)
77 mooseError("In PiecewiseLinearInterpolationMaterial ",
78 _name,
79 ": Length of data provided in 'xy_data' must be a multiple of 2.");
80
81 unsigned int x_size = xy_size / 2;
82 x.reserve(x_size);
83 y.reserve(x_size);
84 for (unsigned int i = 0; i < xy_size / 2; ++i)
85 {
86 x.push_back(xy[i * 2]);
87 y.push_back(xy[i * 2 + 1]);
88 }
89 }
90
91 try
92 {
93 _linear_interp = std::make_unique<LinearInterpolation>(x, y, _extrap);
94 }
95 catch (std::domain_error & e)
96 {
97 mooseError("In PiecewiseLinearInterpolationMaterial ", _name, ": ", e.what());
98 }
99}
100
101void
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", PiecewiseLinearInterpolationMaterial)
Interface class ("Veneer") to provide generator methods for derivative material property names.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
unsigned int _qp
Materials compute MaterialProperties.
Definition Material.h:36
static InputParameters validParams()
Definition Material.C:14
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & _name
The name of this class.
Definition MooseBase.h:381
This material uses a LinearInterpolation object to define the dependence of the material's value on a...
PiecewiseLinearInterpolationMaterial(const InputParameters &parameters)
MaterialProperty< Real > *const _dproperty
First derivative of the material property wrt the coupled variable.
const Real & _scale_factor
Factor to scale the ordinate values by (default = 1)
std::unique_ptr< LinearInterpolation > _linear_interp
LinearInterpolation object.
const VariableValue & _coupled_var
Value of the coupled variable to be used as the abscissa in the piecewise linear interpolation.
MaterialProperty< Real > & _property
Material property to be calculated.
virtual void computeQpProperties() override
Users must override this method.