https://mooseframework.inl.gov
FunctorAux.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 "FunctorAux.h"
11 
12 registerMooseObject("MooseApp", FunctorAux);
13 registerMooseObjectRenamed("MooseApp", FunctorElementalAux, "10/14/2024 00:00", FunctorAux);
14 registerMooseObjectRenamed("MooseApp", ADFunctorElementalAux, "10/14/2024 00:00", FunctorAux);
15 
18 {
20  params.addClassDescription(
21  "Evaluates a functor (variable, function or functor material property) on the current "
22  "element, quadrature point, or node.");
23  params.addRequiredParam<MooseFunctorName>("functor", "The functor to evaluate");
24  params.addParam<MooseFunctorName>("factor", 1, "A factor to apply on the functor");
25  return params;
26 }
27 
29  : AuxKernel(parameters),
30  _functor(getFunctor<Real>("functor")),
31  _factor(getFunctor<Real>("factor")),
32  _is_standard_fe(dynamic_cast<MooseVariableFE<Real> *>(&_var)),
33  _is_standard_fv(dynamic_cast<MooseVariableFV<Real> *>(&_var) ||
34  dynamic_cast<MooseLinearVariableFV<Real> *>(&_var))
35 {
37  paramError(
38  "variable",
39  "The variable must be a non-vector, non-array finite-volume/finite-element variable.");
40 }
41 
42 Real
44 {
45  mooseDoOnce( // PPs: need to execute before this auxkernel
46  const auto & functor_name = getParam<MooseFunctorName>("functor");
47  if (_c_fe_problem.hasPostprocessorValueByName(functor_name)) {
48  if (!(_c_fe_problem.getUserObjectBase(functor_name).isParamValid("force_preaux") &&
49  _c_fe_problem.getUserObjectBase(functor_name).getParam<bool>("force_preaux")))
50  paramError(
51  "functor",
52  "Functor is a postprocessor and does not have 'force_preaux' set to true. The value "
53  "of the postprocessor would be lagged in the functor evaluation. 'force_preaux' will "
54  "ensure the value is updated before the auxiliary variables computation.");
55  } else if (_c_fe_problem.hasUserObject(functor_name)) {
56  const auto & uo = _c_fe_problem.getUserObjectBase(functor_name);
57  if (!(uo.isParamValid("force_preaux") && uo.getParam<bool>("force_preaux")))
58  paramError(
59  "functor",
60  "Functor is a user object and does not have 'force_preaux' set to true. The value "
61  "of the user object would be lagged in the functor evaluation. 'force_preaux' will "
62  "ensure the value is updated before the auxiliary variables computation.");
63  });
64 
65  const auto state = determineState();
66  if (isNodal())
67  {
68  const Moose::NodeArg node_arg = {_current_node,
70  return _factor(node_arg, state) * _functor(node_arg, state);
71  }
72  else if (_is_standard_fe)
73  {
74  const Moose::ElemQpArg qp_arg = {_current_elem, _qp, _qrule, _q_point[_qp]};
75  return _factor(qp_arg, state) * _functor(qp_arg, state);
76  }
77  else
78  {
79  const auto elem_arg = makeElemArg(_current_elem);
80  return _factor(elem_arg, state) * _functor(elem_arg, state);
81  }
82 }
const bool _is_standard_fv
Whether the variable is a standard finite volume variable.
Definition: FunctorAux.h:38
static const std::set< SubdomainID > undefined_subdomain_connection
A static member that can be used when the connection of a node to subdomains is unknown.
Class for stuff related to variables.
Definition: Adaptivity.h:31
registerMooseObject("MooseApp", FunctorAux)
Evaluate a functor (functor material property, function or variable) with either a cell-center...
Definition: FunctorAux.h:18
const Node *const & _current_node
Current node (valid only for nodal kernels)
Definition: AuxKernel.h:214
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
FEProblemBase & _c_fe_problem
Definition: Coupleable.h:1403
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
Helper method to create an elemental argument for a functor that includes whether to perform skewness...
registerMooseObjectRenamed("MooseApp", FunctorElementalAux, "10/14/2024 00:00", FunctorAux)
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Argument for requesting functor evaluation at a quadrature point location in an element.
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 ...
static InputParameters validParams()
Definition: FunctorAux.C:17
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
Quadrature rule being used.
Definition: AuxKernel.h:198
const Moose::Functor< Real > & _functor
Functor to evaluate with the element argument.
Definition: FunctorAux.h:29
const Moose::Functor< Real > & _factor
Factor to multiply the functor with.
Definition: FunctorAux.h:32
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition: AuxKernel.h:204
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:230
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...
virtual Real computeValue() override
Compute and return the value of the aux variable.
Definition: FunctorAux.C:43
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
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
This class provides variable solution values for other classes/objects to bind to when looping over f...
FunctorAux(const InputParameters &parameters)
Definition: FunctorAux.C:28
const MooseArray< Point > & _q_point
Active quadrature points.
Definition: AuxKernel.h:196
This class provides variable solution interface for linear finite volume problems.
Definition: FVUtils.h:24
const bool _is_standard_fe
Whether the variable is a standard finite element variable.
Definition: FunctorAux.h:35
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:86