https://mooseframework.inl.gov
VectorMagnitudeFunctorMaterial.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  "This class takes up to three scalar-valued functors corresponding to vector "
24  "components *or* a single vector functor and computes the Euclidean norm.");
25  params.addParam<MooseFunctorName>("x_functor", "The functor corresponding to the x component.");
26  params.addParam<MooseFunctorName>(
27  "y_functor", 0, "The functor corresponding to the y component.");
28  params.addParam<MooseFunctorName>(
29  "z_functor", 0, "The functor corresponding to the z component.");
30  params.addRequiredParam<MooseFunctorName>(
31  "vector_magnitude_name", "The name of the vector magnitude functor that we are creating.");
32  params.addParam<MooseFunctorName>(
33  "vector_functor", "The name of a vector functor that we will take the magnitude of.");
34  return params;
35 }
36 
37 template <bool is_ad>
39  const InputParameters & parameters)
40  : FunctorMaterial(parameters),
41  _x(isParamValid("x_functor") ? &getFunctor<GenericReal<is_ad>>("x_functor") : nullptr),
42  _y(getFunctor<GenericReal<is_ad>>("y_functor")),
43  _z(getFunctor<GenericReal<is_ad>>("z_functor")),
44  _vector_functor(isParamValid("vector_functor")
45  ? &getFunctor<VectorValue<GenericReal<is_ad>>>("vector_functor")
46  : nullptr)
47 {
48  auto check_error =
49  [this, &parameters](const std::string & scalar_functor, const bool must_equal_one)
50  {
51  auto error_message = [&scalar_functor, this]()
52  {
53  mooseError("Either a '",
54  scalar_functor,
55  "' or 'vector_functor' parameter "
56  "must be provided to '",
57  name(),
58  "'");
59  };
60  const unsigned short sum =
61  parameters.isParamSetByUser(scalar_functor) + parameters.isParamSetByUser("vector_functor");
62  if (must_equal_one)
63  {
64  if (sum != 1)
65  error_message();
66  }
67  else
68  {
69  if (sum > 1)
70  error_message();
71  }
72  };
73 
74  check_error("x_functor", true);
75  check_error("y_functor", false);
76  check_error("z_functor", false);
77 
78  const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
79 
80  if (isParamValid("x_functor"))
82  "vector_magnitude_name",
83  [this](const auto & r, const auto & t) -> GenericReal<is_ad>
84  {
85  const auto x = (*_x)(r, t);
86  const auto y = _y(r, t);
87  const auto z = _z(r, t);
88  return std::sqrt((x * x) + (y * y) + (z * z));
89  },
90  clearance_schedule);
91  else
92  addFunctorProperty<GenericReal<is_ad>>(
93  "vector_magnitude_name",
94  [this](const auto & r, const auto & t) -> GenericReal<is_ad>
95  {
96  const auto vec = (*_vector_functor)(r, t);
97  return vec.norm();
98  },
99  clearance_schedule);
100 }
101 
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:649
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.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
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:51
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
registerMooseObject("MooseApp", VectorMagnitudeFunctorMaterial)
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
FunctorMaterials compute functor material properties.
This class takes up to three functors corresponding to vector components and computes the Euclidean n...
const ExecFlagEnum & _execute_enum
Execute settings for this object.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
const Moose::Functor< GenericReal< is_ad > > & _y
The y-component functor.
VectorMagnitudeFunctorMaterialTempl(const InputParameters &parameters)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
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.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
const Moose::Functor< GenericReal< is_ad > > & _z
The z-component functor.
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195