www.mooseframework.org
ADPiecewiseLinearInterpolationMaterial.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "MooseVariableFE.h"
13 
15 
18 {
20  params.addClassDescription("Compute a property using a piecewise linear interpolation to define "
21  "its dependence on a variable");
22  params.addRequiredParam<std::string>("property",
23  "The name of the property this material will compute");
24  params.addRequiredCoupledVar(
25  "variable",
26  "The name of the variable whose value is used as the abscissa in the interpolation");
27  params.addParam<std::vector<Real>>("x", "The abscissa values");
28  params.addParam<std::vector<Real>>("y", "The ordinate values");
29  params.addParam<std::vector<Real>>("xy_data",
30  "All function data, supplied in abscissa, ordinate pairs");
31  params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
32  params.addParam<bool>(
33  "extrapolation",
34  false,
35  "Use linear extrapolation to evaluate points that lie outside given data set domain. ");
36  return params;
37 }
38 
40  const InputParameters & parameters)
41  : Material(parameters),
42  _prop_name(getParam<std::string>("property")),
43  _coupled_var(adCoupledValue("variable")),
44  _scale_factor(getParam<Real>("scale_factor")),
45  _extrap(getParam<bool>("extrapolation")),
46  _property(declareADProperty<Real>(_prop_name))
47 {
48  std::vector<Real> x;
49  std::vector<Real> y;
50 
51  if ((parameters.isParamValid("x")) || (parameters.isParamValid("y")))
52  {
53  if (!((parameters.isParamValid("x")) && (parameters.isParamValid("y"))))
54  mooseError("In ", _name, ": Both 'x' and 'y' must be specified if either one is specified.");
55 
56  if (parameters.isParamValid("xy_data"))
57  mooseError("In ", _name, ": Cannot specify 'x', 'y', and 'xy_data' together.");
58 
59  x = getParam<std::vector<Real>>("x");
60  y = getParam<std::vector<Real>>("y");
61  }
62  else if (parameters.isParamValid("xy_data"))
63  {
64  std::vector<Real> xy = getParam<std::vector<Real>>("xy_data");
65  unsigned int xy_size = xy.size();
66  if (xy_size % 2 != 0)
67  mooseError("In ", _name, ": Length of data provided in 'xy_data' must be a multiple of 2.");
68 
69  unsigned int x_size = xy_size / 2;
70  x.reserve(x_size);
71  y.reserve(x_size);
72  for (unsigned int i = 0; i < xy_size / 2; ++i)
73  {
74  x.push_back(xy[i * 2]);
75  y.push_back(xy[i * 2 + 1]);
76  }
77  }
78 
79  try
80  {
81  _linear_interp = std::make_unique<LinearInterpolation>(x, y, _extrap);
82  }
83  catch (std::domain_error & e)
84  {
85  mooseError("In ", _name, ": ", e.what());
86  }
87 }
88 
89 void
91 {
93 }
std::unique_ptr< LinearInterpolation > _linear_interp
LinearInterpolation object.
const std::string & _name
The name of this class, reference to value stored in InputParameters.
Definition: MooseBase.h:75
This material uses a LinearInterpolation object to define the dependence of the material&#39;s value on a...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
unsigned int _qp
Definition: MaterialBase.h:318
static InputParameters validParams()
Definition: Material.C:14
ADMaterialProperty< Real > & _property
Material property to be calculated.
Materials compute MaterialProperties.
Definition: Material.h:34
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", ADPiecewiseLinearInterpolationMaterial)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
const InputParameters & parameters() const
Get the parameters of the object.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
virtual void computeQpProperties() override
Users must override this method.
const ADVariableValue & _coupled_var
Value of the coupled variable to be used as the abscissa in the piecewise linear interpolation.
ADPiecewiseLinearInterpolationMaterial(const InputParameters &parameters)
const Real _scale_factor
Factor to scale the ordinate values by (default = 1)
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.