https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FunctorElementalGradientAux.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 "metaphysicl/raw_type.h"
12
15
16template <bool is_ad>
19{
22 "Evaluates the gradient of a functor (variable, function or functor material property) on "
23 "the current element or quadrature point.");
24 params.addRequiredParam<MooseFunctorName>("functor", "The functor to evaluate");
25 params.addParam<MooseFunctorName>("factor", 1, "A factor to apply on the functor");
26 params.addParam<MaterialPropertyName>(
27 "factor_matprop", 1, "A (regular) material property factor to apply on the functor");
28
29 // We need some ghosting for the Finite Volume Fields (we use neighbor information to compute
30 // gradient)
31 params.addParam<unsigned short>("ghost_layers", 1, "The number of layers of elements to ghost.");
33 "ElementSideNeighborLayers",
35 [](const InputParameters & obj_params, InputParameters & rm_params)
36 {
37 rm_params.set<unsigned short>("layers") = obj_params.get<unsigned short>("ghost_layers");
38 rm_params.set<bool>("use_displaced_mesh") = obj_params.get<bool>("use_displaced_mesh");
39 });
40 return params;
41}
42
43template <bool is_ad>
45 const InputParameters & parameters)
46 : VectorAuxKernel(parameters),
47 _functor(getFunctor<GenericReal<is_ad>>("functor")),
48 _factor(getFunctor<GenericReal<is_ad>>("factor")),
49 _factor_matprop(getGenericMaterialProperty<Real, is_ad>("factor_matprop")),
50 _use_qp_arg(dynamic_cast<MooseVariableFE<RealVectorValue> *>(&_var))
51{
52 if (!_use_qp_arg && !dynamic_cast<MooseVariableFV<Real> *>(&_var))
54 "variable",
55 "The variable must be a non-vector, non-array finite-volume/finite-element variable.");
56
57 if (isNodal())
58 paramError("variable", "This AuxKernel only supports Elemental fields");
59}
60
61template <bool is_ad>
62RealVectorValue
64{
66 const auto state = determineState();
67 if (_use_qp_arg)
68 {
69 const Moose::ElemQpArg qp_arg = {_current_elem, _qp, _qrule, _q_point[_qp]};
70 return raw_value(_factor(qp_arg, state)) * raw_value(_factor_matprop[_qp]) *
71 raw_value(_functor.gradient(qp_arg, state));
72 }
73 else
74 {
75 const auto elem_arg = makeElemArg(_current_elem);
76 mooseAssert(_qp == 0, "Only one Qp per element expected when using an elemental argument");
77 return raw_value(_factor(elem_arg, state)) * raw_value(_factor_matprop[_qp]) *
78 raw_value(_functor.gradient(elem_arg, state));
79 }
80}
registerMooseObject("MooseApp", FunctorElementalGradientAux)
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
MooseVariableField< RealVectorValue > & _var
This is a regular kernel so we cast to a regular MooseVariable, hides base _var.
Definition AuxKernel.h:113
static InputParameters validParams()
Definition AuxKernel.C:27
Evaluate a functor (functor material property, function or variable) with either the cell-center or q...
virtual RealVectorValue computeValue() override
Compute and return the value of the aux variable.
const bool _use_qp_arg
Whether to use a quadrature-based functor argument, appropriate for finite element evaluations.
FunctorElementalGradientAuxTempl(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
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.
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 ...
Definition MooseBase.h:457
Class for stuff related to variables.
This class provides variable solution values for other classes/objects to bind to when looping over f...
auto raw_value(const Eigen::Map< T > &in)
Argument for requesting functor evaluation at a quadrature point location in an element.