https://mooseframework.inl.gov
CoupledValueFunctionMaterial.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 #include "Function.h"
12 
15 
16 template <bool is_ad>
19 {
21  params.addClassDescription("Compute a function value from coupled variables");
22  params.addRequiredParam<FunctionName>("function",
23  "Coupled function to evaluate with values from v");
24  MultiMooseEnum parameter_order_enum("X Y Z T");
25  params.addParam<MultiMooseEnum>("parameter_order",
26  parameter_order_enum,
27  "If provided, an entry per couple variable specifies "
28  "the function argument it should apply to.");
29  params.addRequiredParam<MaterialPropertyName>("prop_name", "Output property name");
30  params.addCoupledVar(
31  "v",
32  "List of up to four coupled variables that are substituted for x,y,z, and t "
33  "in the coupled function (or the order chosen using the `parameter_order` parameter)");
34  return params;
35 }
36 
37 template <bool is_ad>
39  const InputParameters & parameters)
40  : Material(parameters),
41  _prop(declareGenericProperty<Real, is_ad>(getParam<MaterialPropertyName>("prop_name"))),
42  _function(getFunction("function")),
43  _vals(coupledGenericValues<is_ad>("v")),
44  _nvals(coupledComponents("v"))
45 {
46  if (_nvals > 4)
47  paramError("v", "Couple a maximum of four variables");
48 
49  const auto & param_order = getParam<MultiMooseEnum>("parameter_order");
50 
51  // no custom order is specified, use x,y,z,t
52  if (param_order.size() == 0)
53  for (const auto i : make_range(_nvals))
54  _order.push_back(i);
55  else if (param_order.size() == _nvals)
56  {
57  for (const auto i : make_range(_nvals))
58  _order.push_back(param_order.get(i));
59 
60  std::set<unsigned int> check_doubles(_order.begin(), _order.end());
61  if (check_doubles.size() != _nvals)
62  paramError("parameter_order", "You must not repeat any positions.");
63  }
64  else
65  paramError("parameter_order",
66  "Specify either as many items as coupled variables, or none at all for the default "
67  "order of x,y,z,t.");
68 }
69 
70 template <bool is_ad>
71 void
73 {
75  GenericReal<is_ad> t = 0.0;
76 
77  for (const auto i : make_range(_nvals))
78  {
79  const auto & j = _order[i];
80  if (j < 3)
81  p(j) = (*_vals[i])[_qp];
82  else
83  t = (*_vals[i])[_qp];
84  }
85 
86  _prop[_qp] = _function.value(t, p);
87 }
88 
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:648
void computeQpProperties() override
Users must override this method.
registerMooseObject("MooseApp", CoupledValueFunctionMaterial)
unsigned int _nvals
number of coupled variables
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...
typename std::conditional< is_ad, typename ADType< T >::type, T >::type GenericType
Definition: MooseTypes.h:644
static InputParameters validParams()
Definition: Material.C:14
CoupledValueFunctionMaterialTempl(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
Materials compute MaterialProperties.
Definition: Material.h:34
Compute a function value from coupled variables.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< unsigned int > _order
mapping of variables to function parameters
IntRange< T > make_range(T beg, T end)
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...
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...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...