https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FunctionInterface.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 "MooseTypes.h"
13#include "MooseObject.h"
14#include "InputParameters.h"
15
16#define usingFunctionInterfaceMembers \
17 using FunctionInterface::getFunction; \
18 using FunctionInterface::getFunctionByName
19
20// Forward declarations
21class FEProblemBase;
22class Function;
23class InputParameters;
24
25namespace Moose
26{
27class FunctionBase;
28}
29
30#ifdef MOOSE_KOKKOS_ENABLED
31namespace Moose::Kokkos
32{
33class Function;
34}
35#endif
36
37template <typename T>
39
47{
48public:
49 FunctionInterface(const MooseObject * moose_object);
50
51#ifdef MOOSE_KOKKOS_ENABLED
56#endif
57
59
65 const Function & getFunction(const std::string & name) const;
66
72 const Function & getFunctionByName(const FunctionName & name) const;
73
80 bool hasFunction(const std::string & param_name) const;
81
87 bool hasFunctionByName(const FunctionName & name) const;
88
89#ifdef MOOSE_KOKKOS_SCOPE
97 Moose::Kokkos::Function getKokkosFunction(const std::string & name) const;
98
105 Moose::Kokkos::Function getKokkosFunctionByName(const FunctionName & name) const;
106
114 template <typename T>
115 const T & getKokkosFunction(const std::string & name) const;
116
124 template <typename T>
125 const T & getKokkosFunctionByName(const FunctionName & name) const;
126
133 bool hasKokkosFunction(const std::string & param_name) const;
134
140 bool hasKokkosFunctionByName(const FunctionName & name) const;
141#endif
142
143private:
144#ifdef MOOSE_KOKKOS_ENABLED
146 const Moose::FunctionBase * getKokkosFunctionByNameHelper(const FunctionName & name) const;
147
150#endif
151
154
157
160};
161
162#ifdef MOOSE_KOKKOS_SCOPE
163template <typename T>
164const T &
165FunctionInterface::getKokkosFunction(const std::string & name) const
166{
167 return getKokkosFunctionByName<T>(_fni_params.get<FunctionName>(name));
168}
169
170template <typename T>
171const T &
172FunctionInterface::getKokkosFunctionByName(const FunctionName & name) const
173{
174 auto function = dynamic_cast<const T *>(getKokkosFunctionByNameHelper(name));
175
176 if (!function)
178 "Kokkos function '", name, "' is not of type '", MooseUtils::prettyCppType<T>(), "'");
179
180 return *function;
181}
182#endif
InputParameters validParams()
unsigned int THREAD_ID
Definition MooseTypes.h:237
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Interface for objects that need to use functions.
bool hasKokkosFunction(const std::string &param_name) const
Determine if the Kokkos function exists.
const THREAD_ID _fni_tid
Thread ID.
bool hasKokkosFunctionByName(const FunctionName &name) const
Determine if the Kokkos function exists.
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
const Function & getFunction(const std::string &name) const
Get a function with a given name.
const Moose::FunctionBase * getKokkosFunctionByNameHelper(const FunctionName &name) const
Helper function to retrieve a Kokkos function.
const InputParameters & _fni_params
Parameters of the object with this interface.
const MooseObject & _fni_object
Reference to the object.
static InputParameters validParams()
bool hasFunctionByName(const FunctionName &name) const
Determine if the function exists.
Moose::Kokkos::Function getKokkosFunctionByName(const FunctionName &name) const
Get a Kokkos function of an abstract type with a given name Calling this function will error out curr...
bool hasFunction(const std::string &param_name) const
Determine if the function exists.
FunctionInterface(const FunctionInterface &object, const Moose::Kokkos::FunctorCopy &key)
Special constructor used for Kokkos functor copy during parallel dispatch.
FEProblemBase & _fni_feproblem
Reference to FEProblemBase instance.
Moose::Kokkos::Function getKokkosFunction(const std::string &name) const
Get a Kokkos function of an abstract type with a given name Calling this function will error out curr...
Base class for function objects.
Definition Function.h:30
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
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:271
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
The abstract class that provides polymorphic interfaces for a function.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...