https://mooseframework.inl.gov
DiffusionFluxAux.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 "DiffusionFluxAux.h"
11 #include "Assembly.h"
12 
14 
17 {
19  MooseEnum component("x y z normal");
20  params.addClassDescription("Compute components of flux vector for diffusion problems "
21  "$(\\vec{J} = -D \\nabla C)$.");
22  params.addRequiredParam<MooseEnum>("component", component, "The desired component of flux.");
23  params.addRequiredCoupledVar("diffusion_variable", "The name of the variable");
24  params.addRequiredParam<MaterialPropertyName>(
25  "diffusivity",
26  "The name of the diffusivity material property that will be used in the flux computation.");
27  return params;
28 }
29 
31  : AuxKernel(parameters),
32  _use_normal(getParam<MooseEnum>("component") == "normal"),
33  _component(getParam<MooseEnum>("component")),
34  _grad_u(coupledGradient("diffusion_variable")),
35  _diffusion_coef(hasMaterialProperty<Real>("diffusivity")
36  ? &getMaterialProperty<Real>("diffusivity")
37  : nullptr),
38  _ad_diffusion_coef(!_diffusion_coef ? &getADMaterialProperty<Real>("diffusivity") : nullptr),
39  _normals(_assembly.normals()),
40  _fv_var(dynamic_cast<const MooseVariableFVReal *>(&_var))
41 {
42  if (_use_normal && !isParamValid("boundary"))
43  paramError("boundary", "A boundary must be provided if using the normal component!");
44 }
45 
46 Real
48 {
49  Real gradient;
50  // FE relies on coupleable
51  if (!_fv_var)
53  else
54  {
55  // Use the boundary gradient when kernel is boundary restricted
56  const auto _vec_grad =
58  determineState()))
60  gradient = _use_normal ? _vec_grad * _normals[_qp] : _vec_grad(_component);
61  }
62  const Real diffusion_coef = _diffusion_coef ? (*_diffusion_coef)[_qp]
64  return -diffusion_coef * gradient;
65 }
const ADMaterialProperty< Real > *const _ad_diffusion_coef
Holds the diffusivity from the material system if AD.
const unsigned int & _current_side
current side of the current element
Definition: AuxKernel.h:130
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:467
const bool _use_normal
Whether the normal component has been selected.
const int _component
Will hold 0, 1, or 2 corresponding to x, y, or z.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
const MaterialProperty< Real > *const _diffusion_coef
Holds the diffusivity from the material system if non-AD.
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:100
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const MooseVariableFVReal *const _fv_var
Pointer to the variable as a finite volume variable (nullptr if not FV)
MooseMesh & _mesh
Mesh this kernel is active on.
const bool _bnd
true if the kernel is boundary kernel, false if it is interior kernels
Definition: AuxKernelBase.h:90
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...
const std::vector< const FaceInfo * > & faceInfo() const
Accessor for local FaceInfo objects.
Definition: MooseMesh.h:2332
DiffusionFluxAux(const InputParameters &parameters)
registerMooseObject("MooseApp", DiffusionFluxAux)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
const MooseArray< Point > & _normals
normals at quadrature points
virtual Real computeValue()
Compute and return the value of the aux variable.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
Auxiliary kernel responsible for computing the components of the flux vector in diffusion problems...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const OutputTools< Real >::VariableGradient & gradient()
The gradient of the variable this object is operating on.
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:128
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:150
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...
static InputParameters validParams()
Definition: AuxKernel.C:27
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:209
This class provides variable solution values for other classes/objects to bind to when looping over f...
static InputParameters validParams()
const VariableGradient & _grad_u
Holds the solution gradient at the current quadrature points.
const ADTemplateVariableGradient< OutputType > & adGradSln() const override
AD grad solution getter.