https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12registerMooseObject("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)
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
53void
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}
registerMooseObject("ThermalHydraulicsTestApp", LinearTestMaterial)
void mooseError(Args &&... args)
const std::string name
Definition Setup.h:21
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Computes a material property that is linear with respect to a list of aux variables.
const Real _shift
Shift constant: 'b' in 'y = m * x + b'.
std::vector< MaterialProperty< Real > * > _y_derivatives
Derivatives of material property with respect to each aux variable.
std::vector< const VariableValue * > _vars
List of aux variables the material property depends upon.
static InputParameters validParams()
const std::vector< Real > _slopes
Slopes with respect to the nonlinear variables.
virtual void computeQpProperties()
MaterialProperty< Real > & _y
Linear material property.
LinearTestMaterial(const InputParameters &parameters)
const MaterialPropertyName _y_name
Name of the new material property.
const unsigned int _n_vars
Number of aux variables the material property depends upon.
static InputParameters validParams()