https://mooseframework.inl.gov
GenericVectorFunctorMaterial.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 "MathUtils.h"
12 
16  GenericConstantVectorFunctorMaterial,
17  "06/30/2022 24:00",
20  ADGenericConstantVectorFunctorMaterial,
21  "06/30/2022 24:00",
23 
24 template <bool is_ad>
27 {
29  params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
30  params.addClassDescription(
31  "FunctorMaterial object for declaring vector properties that are populated by "
32  "evaluation of functor (constants, functions, variables, matprops) object.");
33  params.addParam<std::vector<std::string>>("prop_names",
34  "The names of the properties this material will have");
35  params.addParam<std::vector<MooseFunctorName>>("prop_values",
36  "The corresponding names of the "
37  "functors that are going to provide "
38  "the values for the vector material properties");
39  return params;
40 }
41 
42 template <bool is_ad>
44  const InputParameters & parameters)
45  : FunctorMaterial(parameters),
46  _prop_names(getParam<std::vector<std::string>>("prop_names")),
47  _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values"))
48 {
49  unsigned int num_names = _prop_names.size();
50  unsigned int num_values = _prop_values.size();
51 
52  if (num_names * LIBMESH_DIM != num_values)
53  mooseError("Number of prop_names times three must match the number of prop_values for a "
54  "GenericVectorFunctorMaterial!");
55 
56  // Check that there is no name conflict, a common mistake with this object
57  for (const auto i : make_range(num_names))
58  for (const auto j : make_range(num_values))
59  if (_prop_names[i] == _prop_values[j])
60  paramError("prop_names",
61  "prop_names should not be the same as any of the prop_values. They"
62  " can both be functors, and functors may not have the same name.");
63 
64  _num_props = num_names;
65  _functors.resize(num_values);
66 
67  for (const auto i : make_range(num_values))
68  _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]);
69 
70  const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
71  for (const auto i : make_range(_num_props))
72  {
73  addFunctorProperty<GenericRealVectorValue<is_ad>>(
74  _prop_names[i],
75  [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad>
76  {
77  return {(*_functors[LIBMESH_DIM * i])(r, t),
78  (*_functors[LIBMESH_DIM * i + 1])(r, t),
79  (*_functors[LIBMESH_DIM * i + 2])(r, t)};
80  },
81  clearance_schedule);
82  addFunctorProperty<GenericRealVectorValue<is_ad>>(
84  [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad>
85  {
86  return {_functors[LIBMESH_DIM * i]->dot(r, t),
87  _functors[LIBMESH_DIM * i + 1]->dot(r, t),
88  _functors[LIBMESH_DIM * i + 2]->dot(r, t)};
89  },
90  clearance_schedule);
91  }
92 }
93 
std::vector< MooseFunctorName > _prop_values
Names of the functors to evaluate for the component of these vector properties.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::vector< std::string > _prop_names
Names of the functor vector material properties to define.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseEnumIterator end() const
This material automatically declares as functor material properties whatever is passed to it through ...
GenericVectorFunctorMaterialTempl(const InputParameters &parameters)
const ExecFlagType EXEC_ALWAYS
Definition: Moose.C:49
FunctorMaterials compute functor material properties.
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.
unsigned int _num_props
Number of properties to define.
std::vector< const Moose::Functor< GenericReal< is_ad > > * > _functors
Vector of the functors, inner-ordering per vector component.
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)
registerMooseObjectRenamed("MooseApp", GenericConstantVectorFunctorMaterial, "06/30/2022 24:00", GenericVectorFunctorMaterial)
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...
registerMooseObject("MooseApp", GenericVectorFunctorMaterial)