https://mooseframework.inl.gov
GenericFunctorGradientMaterial.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.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
22  params.addClassDescription(
23  "FunctorMaterial object for declaring properties that are populated by evaluation of "
24  "gradients of Functors (a constant, variable, function or functor material property) "
25  "objects.");
26  params.addParam<std::vector<std::string>>("prop_names",
27  "The names of the properties this material will have");
28 
29  params.addParam<std::vector<MooseFunctorName>>("prop_values",
30  "The corresponding names of the "
31  "functors which gradient are going to provide "
32  "the values for the variables");
33  return params;
34 }
35 
36 template <bool is_ad>
38  const InputParameters & parameters)
39  : FunctorMaterial(parameters),
40  _prop_names(getParam<std::vector<std::string>>("prop_names")),
41  _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values"))
42 {
43  unsigned int num_names = _prop_names.size();
44  unsigned int num_values = _prop_values.size();
45 
46  if (num_names != num_values)
47  mooseError("Number of prop_names must match the number of prop_values for a "
48  "GenericFunctorGradientMaterial!");
49 
50  // Check that there is no name conflict, a common mistake with this object
51  for (const auto i : make_range(num_names))
52  for (const auto j : make_range(num_values))
53  if (_prop_names[i] == _prop_values[j])
54  paramError("prop_names",
55  "prop_names should not be the same as any of the prop_values. They"
56  " can both be functors, and functors may not have the same name.");
57 
58  _num_props = num_names;
59  _functors.resize(num_names);
60 
61  for (const auto i : make_range(_num_props))
62  _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]);
63 
64  const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
65  for (const auto i : make_range(_num_props))
67  _prop_names[i],
68  [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad>
69  { return (*_functors[i]).gradient(r, t); },
70  clearance_schedule);
71 }
72 
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
registerMooseObject("MooseApp", GenericFunctorGradientMaterial)
unsigned int _num_props
Number of properties to define.
static InputParameters validParams()
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
This material automatically declares as functor material properties whatever is passed to it through ...
std::vector< MooseFunctorName > _prop_values
Names of the functors to evaluate for those properties.
std::vector< std::string > _prop_names
Names of the functor material properties to define.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseEnumIterator end() const
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:49
GenericFunctorGradientMaterialTempl(const InputParameters &parameters)
FunctorMaterials compute functor material properties.
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _functors
Vector of the functors.
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.
const Moose::FunctorBase< T > & addFunctorProperty(const std::string &name, PolymorphicLambda my_lammy, const std::set< ExecFlagType > &clearance_schedule={EXEC_ALWAYS})
Declare a functor material property.
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...