https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
16template <bool is_ad>
19{
21 params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
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
37template <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"))
81 addFunctorProperty<GenericReal<is_ad>>(
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 using std::sqrt;
89 return sqrt((x * x) + (y * y) + (z * z));
90 },
91 clearance_schedule);
92 else
93 addFunctorProperty<GenericReal<is_ad>>(
94 "vector_magnitude_name",
95 [this](const auto & r, const auto & t) -> GenericReal<is_ad>
96 {
97 const auto vec = (*_vector_functor)(r, t);
98 return vec.norm();
99 },
100 clearance_schedule);
101}
102
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
const ExecFlagType EXEC_ALWAYS
Definition Moose.C:53
registerMooseObject("MooseApp", VectorMagnitudeFunctorMaterial)
A MultiMooseEnum object to hold "execute_on" flags.
FunctorMaterials compute functor material properties.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
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.
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...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MooseEnumIterator end() const
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the set values in the enum.
const ExecFlagEnum & _execute_enum
Execute settings for this object.
This class takes up to three functors corresponding to vector components and computes the Euclidean n...
VectorMagnitudeFunctorMaterialTempl(const InputParameters &parameters)
const Moose::Functor< GenericReal< is_ad > > & _y
The y-component functor.
const Moose::Functor< GenericReal< is_ad > > & _z
The z-component functor.