https://mooseframework.inl.gov
SpatialUserObjectFunctor.h
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 #pragma once
11 
12 #include "MooseFunctor.h"
13 #include "InputParameters.h"
14 #include "BlockRestrictable.h"
15 
19 template <typename UserObjectType>
20 class SpatialUserObjectFunctor : public UserObjectType, public Moose::FunctorBase<Real>
21 {
22 public:
24 
26  virtual bool hasBlocks(SubdomainID sub) const override;
27 
28 protected:
35 
36  virtual Real evaluate(const ElemArg & elem, const Moose::StateArg & state) const override;
37  virtual Real evaluate(const FaceArg & face, const Moose::StateArg & state) const override final;
38  virtual Real evaluate(const ElemQpArg & qp, const Moose::StateArg & state) const override;
39  virtual Real evaluate(const ElemSideQpArg & elem_side_qp,
40  const Moose::StateArg & state) const override final;
41  virtual Real evaluate(const ElemPointArg & elem_point,
42  const Moose::StateArg & state) const override final;
43  virtual Real evaluate(const NodeArg & node, const Moose::StateArg & state) const override final;
44 
45  virtual bool supportsFaceArg() const override final { return true; }
46  virtual bool supportsElemSideQpArg() const override final { return true; }
47 
48 private:
49  /*
50  * Helper template implementing functor evaluations
51  */
52  template <typename SpatialArg>
53  Real evaluateTemplate(const SpatialArg & position, const Moose::StateArg & state) const;
54 };
55 
56 template <typename UserObjectType>
59 {
60  auto params = UserObjectType::validParams();
61  // Spatial UOs are used in the transfers
62  ExecFlagEnum & exec_enum = params.template set<ExecFlagEnum>("execute_on", true);
64  return params;
65 }
66 
67 template <typename UserObjectType>
69  : UserObjectType(params), Moose::FunctorBase<Real>(this->name())
70 {
71 }
72 
73 template <typename UserObjectType>
74 template <typename SpatialArg>
75 Real
77  const SpatialArg & position, const Moose::StateArg & libmesh_dbg_var(state)) const
78 {
79  mooseAssert(state.state == 0, "We do not currently support evaluating at old states");
80  return this->spatialValue(position.getPoint());
81 }
82 
83 template <typename UserObjectType>
84 Real
86  const Moose::StateArg & state) const
87 {
88  return evaluateTemplate(elem, state);
89 }
90 
91 template <typename UserObjectType>
92 Real
94  const Moose::StateArg & state) const
95 {
96  return evaluateTemplate(face, state);
97 }
98 
99 template <typename UserObjectType>
100 Real
102  const Moose::StateArg & state) const
103 {
104  return evaluateTemplate(qp, state);
105 }
106 
107 template <typename UserObjectType>
108 Real
110  const Moose::StateArg & state) const
111 {
112  return evaluateTemplate(elem_side_qp, state);
113 }
114 
115 template <typename UserObjectType>
116 Real
118  const Moose::StateArg & state) const
119 {
120  return evaluateTemplate(elem_point, state);
121 }
122 
123 template <typename UserObjectType>
124 Real
126  const Moose::StateArg & state) const
127 {
128  return evaluateTemplate(node, state);
129 }
130 
131 template <typename UserObjectType>
132 bool
134 {
135  if constexpr (std::is_base_of<BlockRestrictable, UserObjectType>::value)
136  return UserObjectType::hasBlocks(sub_id);
137  else
139 }
std::string name(const ElemQuality q)
virtual bool hasBlocks(SubdomainID) const
Returns whether the functor is defined on this block.
Definition: MooseFunctor.h:237
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:51
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
Base class template for functor objects.
Definition: MooseFunctor.h:137
Real evaluateTemplate(const SpatialArg &position, const Moose::StateArg &state) const
SpatialUserObjectFunctor(const InputParameters &params)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:82
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
InputParameters validParams()
virtual Real evaluate(const ElemArg &elem, const Moose::StateArg &state) const override
Evaluate the functor with a given element.
A structure defining a "face" evaluation calling argument for Moose functors.
virtual bool hasBlocks(SubdomainID sub) const override
Returns whether the functor is defined on this block.
A structure that is used to evaluate Moose functors logically at an element/cell center.
Argument for requesting functor evaluation at a quadrature point location in an element.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for creating a user object with the SpatialUserObject and Moose::Functor APIs...
State argument for evaluating functors.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual bool supportsFaceArg() const override final
Whether this functor supports evaluation with FaceArg.
virtual bool supportsElemSideQpArg() const override final
Whether this functor supports evaluation with ElemSideQpArg.
Argument for requesting functor evaluation at quadrature point locations on an element side...