https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FunctorInterface.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 "ADReal.h"
13#include "MooseTypes.h"
14#include "SubProblem.h"
15#include "MooseFunctorForward.h"
16
17#include <vector>
18#include <memory>
19#include <string>
20
21class InputParameters;
22class MooseObject;
23
29{
30public:
32
33 FunctorInterface(const MooseObject * moose_object);
34
35#ifdef MOOSE_KOKKOS_ENABLED
40#endif
41
48 static std::string deduceFunctorName(const std::string & name, const InputParameters & params);
49
50protected:
58 template <typename T>
59 const Moose::Functor<T> & getFunctor(const std::string & name);
60
69 template <typename T>
70 const Moose::Functor<T> & getFunctor(const std::string & name, THREAD_ID tid);
71
80 template <typename T>
81 const Moose::Functor<T> & getFunctor(const std::string & name, SubProblem & subproblem);
82
92 template <typename T>
93 const Moose::Functor<T> &
94 getFunctor(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
95
104 bool isFunctor(const std::string & name) const;
105
115 bool isFunctor(const std::string & name, const SubProblem & subproblem) const;
116
120 std::string deduceFunctorName(const std::string & name) const;
121
126 Moose::ElemArg makeElemArg(const Elem * elem, bool correct_skewnewss = false) const;
127
134 template <typename T>
135 void checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration);
136
144 template <typename T>
145 const Moose::Functor<T> & getFunctorByName(const std::string & name);
146
147private:
156 template <typename T>
157 const Moose::Functor<T> &
158 getFunctorByName(const std::string & name, SubProblem & subproblem, THREAD_ID tid);
159
163 virtual bool isADObject() const = 0;
164
169 template <typename T>
170 const Moose::Functor<T> * defaultFunctor(const std::string & name);
171
174
176 const std::string _fi_name;
177
180
183
185 std::vector<std::unique_ptr<Moose::Functor<Real>>> _default_real_functors;
186
188 std::vector<std::unique_ptr<Moose::Functor<ADReal>>> _default_ad_real_functors;
189};
190
191template <typename T>
192const Moose::Functor<T> &
193FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem, const THREAD_ID tid)
194{
195 // Check if the supplied parameter is a valid input parameter key
196 std::string functor_name = deduceFunctorName(name);
197 return getFunctorByName<T>(functor_name, subproblem, tid);
198}
199
200template <typename T>
201const Moose::Functor<T> &
202FunctorInterface::getFunctor(const std::string & name, SubProblem & subproblem)
203{
204 return getFunctor<T>(name, subproblem, _fi_tid);
205}
206
207template <typename T>
208const Moose::Functor<T> &
209FunctorInterface::getFunctor(const std::string & name, const THREAD_ID tid)
210{
211 mooseAssert(_fi_subproblem, "This must be non-null");
212 return getFunctor<T>(name, *_fi_subproblem, tid);
213}
214
215template <typename T>
216const Moose::Functor<T> &
217FunctorInterface::getFunctor(const std::string & name)
218{
219 mooseAssert(_fi_subproblem, "This must be non-null");
220 return getFunctor<T>(name, *_fi_subproblem, _fi_tid);
221}
222
223template <typename T>
224const Moose::Functor<T> &
225FunctorInterface::getFunctorByName(const std::string & name)
226{
227 mooseAssert(_fi_subproblem, "This must be non-null");
228 return getFunctorByName<T>(name, *_fi_subproblem, _fi_tid);
229}
230
231template <typename T>
232const Moose::Functor<T> &
233FunctorInterface::getFunctorByName(const std::string & name,
234 SubProblem & subproblem,
235 const THREAD_ID tid)
236{
237 // Check if it's just a constant
238 const auto * const default_functor = defaultFunctor<T>(name);
239 if (default_functor)
240 return *default_functor;
241
242 return subproblem.getFunctor<T>(name, tid, _fi_name, isADObject());
243}
244
245template <>
246const Moose::Functor<Real> * FunctorInterface::defaultFunctor<Real>(const std::string & name);
247
248template <>
249const Moose::Functor<ADReal> * FunctorInterface::defaultFunctor<ADReal>(const std::string & name);
250
251// General version for types that do not accept default values
252template <typename T>
253const Moose::Functor<T> *
254FunctorInterface::defaultFunctor(const std::string & /*name*/)
255{
256 return nullptr;
257}
258
259template <typename T>
260void
261FunctorInterface::checkFunctorSupportsSideIntegration(const std::string & name, bool qp_integration)
262{
263 const std::string functor_name = deduceFunctorName(name);
264 const auto & functor = getFunctor<T>(name);
265 if (qp_integration)
266 {
267 if (!functor.supportsElemSideQpArg())
268 mooseError("Quadrature point integration was requested, but the functor '",
269 functor_name,
270 "' does not support this.");
271 }
272 else
273 {
274 if (!functor.supportsFaceArg())
275 mooseError("Face info integration was requested, but the functor '",
276 functor_name,
277 "' does not support this.");
278 }
279}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
An interface for accessing Moose::Functors.
virtual bool isADObject() const =0
Whether this interface is for an AD object.
void checkFunctorSupportsSideIntegration(const std::string &name, bool qp_integration)
Throws error if the functor does not support the requested side integration.
const Moose::Functor< T > * defaultFunctor(const std::string &name)
Helper function to parse default functor values.
const THREAD_ID _fi_tid
Current threaded it.
static std::string deduceFunctorName(const std::string &name, const InputParameters &params)
Helper to look up a functor name through the input parameter keys.
std::vector< std::unique_ptr< Moose::Functor< ADReal > > > _default_ad_real_functors
Storage vector for Moose::Functor<ADReal> default objects.
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...
static InputParameters validParams()
const InputParameters & _fi_params
Parameters of the object with this interface.
SubProblem *const _fi_subproblem
Pointer to subproblem if the subproblem pointer parameter was set.
bool isFunctor(const std::string &name) const
Checks the subproblem for the given functor.
std::vector< std::unique_ptr< Moose::Functor< Real > > > _default_real_functors
Storage vector for Moose::Functor<Real> default objects.
const Moose::Functor< T > & getFunctorByName(const std::string &name)
Retrieves a functor from the subproblem.
const std::string _fi_name
The name of the object that this interface belongs to.
const Moose::Functor< T > & getFunctor(const std::string &name)
Retrieves a functor from the subproblem.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
This is a wrapper that forwards calls to the implementation, which can be switched out at any time wi...
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
const Moose::Functor< T > & getFunctor(const std::string &name, const THREAD_ID tid, const std::string &requestor_name, bool requestor_is_ad)
A structure that is used to evaluate Moose functors logically at an element/cell center.