https://mooseframework.inl.gov
LinearTestMaterial.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 
10 #include "LinearTestMaterial.h"
11 
12 registerMooseObject("ThermalHydraulicsTestApp", LinearTestMaterial);
13 
16 {
18 
19  params.addRequiredCoupledVar("vars",
20  "List of aux variables that the material property depends upon");
21  params.addRequiredParam<std::vector<Real>>(
22  "slopes", "Slopes of the material property with respect to each aux variable");
23  params.addParam<Real>("shift", 0, "Shift constant: 'b' in 'y = m * x + b'");
24  params.addRequiredParam<MaterialPropertyName>("name", "Name of the new material property");
25 
26  return params;
27 }
28 
31  _n_vars(coupledComponents("vars")),
32  _slopes(getParam<std::vector<Real>>("slopes")),
33  _shift(getParam<Real>("shift")),
34  _y_name(getParam<MaterialPropertyName>("name")),
35  _y(declareProperty<Real>(_y_name))
36 {
37  // check that number of provided slopes is consistent with number of variables
38  if (_slopes.size() != _n_vars)
39  mooseError(
40  "LinearTestMaterial:", name(), ": Parameters 'vars' and 'slopes' must have same size.");
41 
42  // get references to coupled variables and new material property derivatives
43  _vars.resize(_n_vars);
44  _y_derivatives.resize(_n_vars);
45  for (unsigned int i = 0; i < _n_vars; ++i)
46  {
47  _vars[i] = &coupledValue("vars", i);
48  if (!isCoupledConstant("vars"))
49  _y_derivatives[i] = &declarePropertyDerivative<Real>(_y_name, coupledName("vars", i));
50  }
51 }
52 
53 void
55 {
56  _y[_qp] = _shift;
57  for (unsigned int i = 0; i < _n_vars; ++i)
58  {
59  _y[_qp] += _slopes[i] * (*_vars[i])[_qp];
60  if (_y_derivatives[i])
61  (*_y_derivatives[i])[_qp] = _slopes[i];
62  }
63 }
virtual bool isCoupledConstant(const std::string &var_name) const
const MaterialPropertyName _y_name
Name of the new material property.
VariableName coupledName(const std::string &var_name, unsigned int comp=0) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< MaterialProperty< Real > * > _y_derivatives
Derivatives of material property with respect to each aux variable.
virtual void computeQpProperties()
registerMooseObject("ThermalHydraulicsTestApp", LinearTestMaterial)
std::vector< const VariableValue * > _vars
List of aux variables the material property depends upon.
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
const std::vector< Real > _slopes
Slopes with respect to the nonlinear variables.
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
LinearTestMaterial(const InputParameters &parameters)
static InputParameters validParams()
const Real _shift
Shift constant: &#39;b&#39; in &#39;y = m * x + b&#39;.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
static InputParameters validParams()
MaterialProperty< Real > & _y
Linear material property.
Computes a material property that is linear with respect to a list of aux variables.
const unsigned int _n_vars
Number of aux variables the material property depends upon.