https://mooseframework.inl.gov
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 
16 template <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 
31 template <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 
41 template <bool is_ad>
42 Real
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 }
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:648
Class for stuff related to variables.
Definition: Adaptivity.h:31
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DivergenceAuxTempl(const InputParameters &parameters)
Definition: DivergenceAux.C:32
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...
Computes the divergence of a vector of variables.
Definition: DivergenceAux.h:18
Argument for requesting functor evaluation at a quadrature point location in an element.
virtual Real computeValue()
Compute and return the value of the aux variable.
Definition: DivergenceAux.C:43
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", DivergenceAux)
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...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
static InputParameters validParams()
Definition: DivergenceAux.C:18