https://mooseframework.inl.gov
GenericFunctionVectorMaterial.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("Material object for declaring vector properties that are populated "
22  "by evaluation of Function objects.");
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  "minor ordering by component");
30  return params;
31 }
32 
33 template <bool is_ad>
35  const InputParameters & parameters)
36  : Material(parameters),
37  _prop_names(getParam<std::vector<std::string>>("prop_names")),
38  _prop_values(getParam<std::vector<FunctionName>>("prop_values"))
39 {
40  unsigned int num_names = _prop_names.size();
41  unsigned int num_values = _prop_values.size();
42 
43  if (num_names * LIBMESH_DIM != num_values)
44  mooseError("Number of prop_names (",
45  num_names,
46  ") times the libmesh dimension (",
47  LIBMESH_DIM,
48  ") must match the number of prop_values (",
49  num_values,
50  ") for a GenericFunctionVectorMaterial!");
51 
52  _num_props = num_names;
53 
54  _properties.resize(num_names);
55  _functions.resize(num_names * LIBMESH_DIM);
56 
57  for (unsigned int i = 0; i < _num_props; i++)
58  {
59  _properties[i] = &declareGenericProperty<RealVectorValue, is_ad>(_prop_names[i]);
60  for (const auto j : make_range(Moose::dim))
61  _functions[i * LIBMESH_DIM + j] = &getFunctionByName(_prop_values[i * LIBMESH_DIM + j]);
62  }
63 }
64 
65 template <bool is_ad>
66 void
68 {
69  computeQpFunctions();
70 }
71 
72 template <bool is_ad>
73 void
75 {
76  computeQpFunctions();
77 }
78 
79 template <bool is_ad>
80 void
82 {
83  for (unsigned int i = 0; i < _num_props; i++)
84  for (const auto j : make_range(Moose::dim))
85  (*_properties[i])[_qp](j) = (*_functions[i * LIBMESH_DIM + j]).value(_t, _q_point[_qp]);
86 }
87 
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
std::vector< FunctionName > _prop_values
The functions to use for each property&#39;s components.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
registerMooseObject("MooseApp", GenericFunctionVectorMaterial)
virtual void computeQpProperties() override
Users must override this method.
unsigned int _num_props
Number of vector properties that will be defined.
GenericFunctionVectorMaterialTempl(const InputParameters &parameters)
void computeQpFunctions()
A helper method for evaluating the functions.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
Definition: Material.C:14
This material automatically declares as material properties whatever is passed to it through the para...
Materials compute MaterialProperties.
Definition: Material.h:34
std::vector< GenericMaterialProperty< RealVectorValue, is_ad > * > _properties
Vector of all the properties.
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
std::vector< std::string > _prop_names
Names of the vector material properties to define.
std::vector< const Function * > _functions
Vector of pointers to the functions, stored here after retrieval using their name.
IntRange< T > make_range(T beg, T end)
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...
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...