https://mooseframework.inl.gov
Loading...
Searching...
No Matches
DivergenceAux.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
10#include "DivergenceAux.h"
11#include "MooseMesh.h"
12
15
16template <bool is_ad>
19{
21
22 params.addClassDescription("Computes the divergence of a vector of functors.");
23 // Coupled functors
24 params.addRequiredParam<MooseFunctorName>("u", "x-component of the vector");
25 params.addParam<MooseFunctorName>("v", "y-component of the vector"); // only required in 2D and 3D
26 params.addParam<MooseFunctorName>("w", "z-component of the vector"); // only required in 3D
27
28 return params;
29}
30
31template <bool is_ad>
33 : AuxKernel(parameters),
34 _u(getFunctor<GenericReal<is_ad>>("u")),
35 _v(_mesh.dimension() >= 2 ? &getFunctor<GenericReal<is_ad>>("v") : nullptr),
36 _w(_mesh.dimension() == 3 ? &getFunctor<GenericReal<is_ad>>("w") : nullptr),
37 _use_qp_arg(dynamic_cast<MooseVariableFE<Real> *>(&_var))
38{
39}
40
41template <bool is_ad>
42Real
44{
46 const auto state = determineState();
47 Real divergence = 0;
48 if (_use_qp_arg)
49 {
50 const Moose::ElemQpArg qp_arg = {_current_elem, _qp, _qrule, _q_point[_qp]};
51 divergence += raw_value(_u.gradient(qp_arg, state)(0));
52 if (_v)
53 divergence += raw_value(_v->gradient(qp_arg, state)(1));
54 if (_w)
55 divergence += raw_value(_w->gradient(qp_arg, state)(2));
56 return divergence;
57 }
58 else
59 {
60 const auto elem_arg = makeElemArg(_current_elem);
61 divergence += raw_value(_u.gradient(elem_arg, state)(0));
62 if (_v)
63 divergence += raw_value(_v->gradient(elem_arg, state)(1));
64 if (_w)
65 divergence += raw_value(_w->gradient(elem_arg, state)(2));
66 return divergence;
67 }
68}
registerMooseObject("MooseApp", DivergenceAux)
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
static InputParameters validParams()
Definition AuxKernel.C:27
Computes the divergence of a vector of variables.
DivergenceAuxTempl(const InputParameters &parameters)
virtual Real computeValue()
Compute and return the value of the aux variable.
static InputParameters validParams()
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...
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.
Class for stuff related to variables.
auto raw_value(const Eigen::Map< T > &in)
Argument for requesting functor evaluation at a quadrature point location in an element.