https://mooseframework.inl.gov
GenericFunctorMaterial.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 "GenericFunctorMaterial.h"
11 #include "Function.h"
12 #include "MathUtils.h"
13 
17  GenericConstantFunctorMaterial,
18  "06/30/2022 24:00",
21  ADGenericConstantFunctorMaterial,
22  "06/30/2022 24:00",
25  GenericFunctionFunctorMaterial,
26  "06/30/2022 24:00",
29  ADGenericFunctionFunctorMaterial,
30  "06/30/2022 24:00",
32 
33 template <bool is_ad>
36 {
38  params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
39  params.addClassDescription(
40  "FunctorMaterial object for declaring properties that are populated by evaluation of a "
41  "Functor (a constant, variable, function or functor material property) objects.");
42  params.addParam<std::vector<std::string>>("prop_names",
43  "The names of the properties this material will have");
44  params.addParam<std::vector<MooseFunctorName>>("prop_values",
45  "The corresponding names of the "
46  "functors that are going to provide "
47  "the values for the variables");
48  params.addParam<bool>("define_dot_functors",
49  true,
50  "Whether to define additional functors for the time derivative and the "
51  "time derivative of the gradient");
52  return params;
53 }
54 
55 template <bool is_ad>
57  : FunctorMaterial(parameters),
58  _prop_names(getParam<std::vector<std::string>>("prop_names")),
59  _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values"))
60 {
61  unsigned int num_names = _prop_names.size();
62  unsigned int num_values = _prop_values.size();
63 
64  if (num_names != num_values)
65  mooseError("Number of prop_names must match the number of prop_values for a "
66  "GenericFunctorMaterial!");
67 
68  // Check that there is no name conflict, a common mistake with this object
69  for (const auto i : make_range(num_names))
70  for (const auto j : make_range(num_values))
71  if (_prop_names[i] == _prop_values[j])
72  paramError("prop_names",
73  "prop_names should not be the same as any of the prop_values. They"
74  " can both be functors, and functors may not have the same name.");
75 
76  _num_props = num_names;
77  _functors.resize(num_names);
78 
79  for (const auto i : make_range(_num_props))
80  _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]);
81 
82  const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
83  for (const auto i : make_range(_num_props))
84  {
85  addFunctorProperty<GenericReal<is_ad>>(
86  _prop_names[i],
87  [this, i](const auto & r, const auto & t) -> GenericReal<is_ad>
88  { return (*_functors[i])(r, t); },
89  clearance_schedule);
90  if (getParam<bool>("define_dot_functors"))
91  {
92  addFunctorProperty<GenericReal<is_ad>>(
94  [this, i](const auto & r, const auto & t) -> GenericReal<is_ad>
95  { return _functors[i]->dot(r, t); },
96  clearance_schedule);
97  addFunctorProperty<GenericRealVectorValue<is_ad>>(
99  [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad>
100  { return _functors[i]->gradDot(r, t); },
101  clearance_schedule);
102  }
103  }
104 }
105 
107 template class GenericFunctorMaterialTempl<true>;
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _functors
Vector of the functors.
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:648
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
static InputParameters validParams()
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
unsigned int _num_props
Number of properties to define.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
registerMooseObjectRenamed("MooseApp", GenericConstantFunctorMaterial, "06/30/2022 24:00", GenericFunctorMaterial)
std::vector< MooseFunctorName > _prop_values
Names of the functors to evaluate for those properties.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseEnumIterator end() const
GenericFunctorMaterialTempl(const InputParameters &parameters)
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:49
static InputParameters validParams()
FunctorMaterials compute functor material properties.
registerMooseObject("MooseApp", GenericFunctorMaterial)
Moose::GenericType< RealVectorValue, is_ad > GenericRealVectorValue
Definition: MooseTypes.h:652
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 ...
const ExecFlagEnum & _execute_enum
Execute settings for this object.
This material automatically declares as functor material properties whatever is passed to it through ...
T gradName(const T &base_prop_name)
automatic prefixing for naming material properties based on gradients of coupled variables/functors ...
Definition: MathUtils.h:445
T timeDerivName(const T &base_prop_name)
automatic prefixing for naming material properties based on time derivatives of coupled variables/fun...
Definition: MathUtils.h:456
IntRange< T > make_range(T beg, T end)
std::vector< std::string > _prop_names
Names of the functor material properties to define.
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...