https://mooseframework.inl.gov
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
21 class FEProblemBase;
22 class Function;
23 class InputParameters;
24 
25 namespace Moose
26 {
27 class FunctionBase;
28 }
29 
30 #ifdef MOOSE_KOKKOS_ENABLED
31 namespace Moose::Kokkos
32 {
33 class Function;
34 }
35 #endif
36 
37 template <typename T>
39 
47 {
48 public:
49  FunctionInterface(const MooseObject * moose_object);
50 
51 #ifdef MOOSE_KOKKOS_ENABLED
52 
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_ENABLED
90 
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 
143 private:
144 #ifdef MOOSE_KOKKOS_ENABLED
145  const Moose::FunctionBase * getKokkosFunctionByNameHelper(const FunctionName & name) const;
147 
150 #endif
151 
154 
157 
160 };
161 
162 #ifdef MOOSE_KOKKOS_ENABLED
163 template <typename T>
164 const T &
165 FunctionInterface::getKokkosFunction(const std::string & name) const
166 {
167  return getKokkosFunctionByName<T>(_fni_params.get<FunctionName>(name));
168 }
169 
170 template <typename T>
171 const T &
172 FunctionInterface::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
std::string name(const ElemQuality q)
Base class for function objects.
Definition: Function.h:29
bool hasKokkosFunction(const std::string &param_name) const
Determine if the Kokkos function exists.
FunctionInterface(const MooseObject *moose_object)
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.
const Function & getFunction(const std::string &name) const
Get a function with a given name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
const MooseObject & _fni_object
Reference to the object.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const Moose::FunctionBase * getKokkosFunctionByNameHelper(const FunctionName &name) const
Helper function to retrieve a Kokkos function.
The abstract class that provides polymorphic interfaces for a function.
const THREAD_ID _fni_tid
Thread ID.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
bool hasFunctionByName(const FunctionName &name) const
Determine if the function exists.
FEProblemBase & _fni_feproblem
Reference to FEProblemBase instance.
bool hasFunction(const std::string &param_name) const
Determine if the function exists.
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...
const InputParameters & _fni_params
Parameters of the object with this interface.
static InputParameters validParams()
const Function & getFunctionByName(const FunctionName &name) const
Get a function with a given name.
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
bool hasKokkosFunctionByName(const FunctionName &name) const
Determine if the Kokkos function exists.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
Interface for objects that need to use functions.
InputParameters validParams()
unsigned int THREAD_ID
Definition: MooseTypes.h:237