www.mooseframework.org
GenericFunctionMaterial.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 #include "Function.h"
12 
15 
16 template <bool is_ad>
19 {
21  params.addClassDescription("Material object for declaring properties that are populated by "
22  "evaluation of Function object.");
23  params.addParam<std::vector<std::string>>("prop_names",
24  "The names of the properties this material will have");
25  params.addParam<std::vector<FunctionName>>("prop_values",
26  "The corresponding names of the "
27  "functions that are going to provide "
28  "the values for the variables");
29  return params;
30 }
31 
32 template <bool is_ad>
34  const InputParameters & parameters)
35  : Material(parameters),
36  _prop_names(getParam<std::vector<std::string>>("prop_names")),
37  _prop_values(getParam<std::vector<FunctionName>>("prop_values"))
38 {
39  unsigned int num_names = _prop_names.size();
40  unsigned int num_values = _prop_values.size();
41 
42  if (num_names != num_values)
43  mooseError(
44  "Number of prop_names must match the number of prop_values for a GenericFunctionMaterial!");
45 
46  _num_props = num_names;
47 
48  _properties.resize(num_names);
49  _functions.resize(num_names);
50 
51  for (unsigned int i = 0; i < _num_props; i++)
52  {
53  _properties[i] = &declareGenericProperty<Real, is_ad>(_prop_names[i]);
55  }
56 }
57 
58 template <bool is_ad>
59 void
61 {
62  computeQpFunctions();
63 }
64 
65 template <bool is_ad>
66 void
68 {
69  computeQpFunctions();
70 }
71 
72 template <bool is_ad>
73 void
75 {
76  for (unsigned int i = 0; i < _num_props; i++)
77  (*_properties[i])[_qp] = (*_functions[i]).value(_t, _q_point[_qp]);
78 }
79 
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
GenericFunctionMaterialTempl(const InputParameters &parameters)
std::vector< std::string > _prop_names
Names of the material properties to define.
std::vector< GenericMaterialProperty< Real, is_ad > * > _properties
Vector of all the properties.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
Definition: Material.C:14
std::vector< FunctionName > _prop_values
The functions to use for each property.
void computeQpFunctions()
A helper method for evaluating the functions.
This material automatically declares as material properties whatever is passed to it through the para...
Materials compute MaterialProperties.
Definition: Material.h:34
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
virtual void computeQpProperties() override
Users must override this method.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
registerMooseObject("MooseApp", GenericFunctionMaterial)
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 option parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
unsigned int _num_props
Number of properties that will be defined.
std::vector< const Function * > _functions
Vector of pointers to the functions, stored here after retrieval using their name.