https://mooseframework.inl.gov
FunctorKernel.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 "FunctorKernel.h"
11 
13 
16 {
18 
19  params.addClassDescription("Adds a term from a functor.");
20 
21  params.addRequiredParam<MooseFunctorName>("functor", "Functor to add");
22  params.addRequiredParam<bool>(
23  "functor_on_rhs",
24  "If true, the functor to add is on the right hand side of the equation. By convention, all "
25  "terms are moved to the left hand side, so if true, a factor of -1 is applied.");
26 
27  MooseEnum modes("add=0 target=1", "add");
28  params.addParam<MooseEnum>("mode",
29  modes,
30  "The operation mode, 'add' just returns the value of the functor and "
31  "therefore adds the functor value to the residual"
32  "'target' sets the residual term in such a way that the residual of "
33  "the variable u vanishes if its value matches the given functor. "
34  "Please note: In mode 'target' this kernel only imposes the equality "
35  "between the variable and the functor when it is the only kernel in "
36  "that variable's equation on the specified subdomains.");
37 
38  return params;
39 }
40 
42  : ADKernelValue(parameters),
43  _mode((Mode)(int)parameters.get<MooseEnum>("mode")),
44  _functor(getFunctor<ADReal>("functor")),
45  _sign(getParam<bool>("functor_on_rhs") ? -1.0 : 1.0)
46 {
47 }
48 
49 ADReal
51 {
52  const Moose::ElemQpArg space_arg = {_current_elem, _qp, _qrule, _q_point[_qp]};
53  const auto functor_value = _functor(space_arg, Moose::currentState());
54 
55  switch (_mode)
56  {
57  case Mode::ADD:
58  return _sign * functor_value;
59 
60  case Mode::TARGET:
61  return _sign * (functor_value - _u[_qp]);
62 
63  default:
64  mooseError("FunctorKernel: Invalid mode");
65  }
66 }
virtual ADReal precomputeQpResidual() override
Called before forming the residual for an element.
Definition: FunctorKernel.C:50
static InputParameters validParams()
Definition: ADKernelValue.C:20
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1133
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ADTemplateVariableValue< T > & _u
Holds the solution at current quadrature points.
Definition: ADKernel.h:92
FunctorKernel(const InputParameters &parameters)
Definition: FunctorKernel.C:41
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:46
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 Real _sign
Sign to apply to functor.
Definition: FunctorKernel.h:40
registerMooseObject("MooseApp", FunctorKernel)
const QBase *const & _qrule
active quadrature rule
Definition: KernelBase.h:49
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
Argument for requesting functor evaluation at a quadrature point location in an element.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
const Moose::Functor< ADReal > & _functor
Functor to add.
Definition: FunctorKernel.h:37
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: FunctorKernel.C:15
const Elem *const & _current_elem
Current element.
Definition: KernelBase.h:37
StateArg currentState()
const Mode _mode
The working mode of this kernel ("add" or "target")
Definition: FunctorKernel.h:31
void ErrorVector unsigned int
const MooseArray< Point > & _q_point
The physical location of the element&#39;s quadrature Points, indexed by _qp.
Definition: KernelBase.h:46
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:43
Adds a term from a functor.
Definition: FunctorKernel.h:17