KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
registered_component_lookup.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // license: HDF5Application/license.txt
9 //
10 // Main author: Michael Andre, https://github.com/msandre
11 //
12 
13 #if !defined(KRATOS_REGISTERED_COMPONENT_LOOKUP_H_INCLUDED)
14 #define KRATOS_REGISTERED_COMPONENT_LOOKUP_H_INCLUDED
15 
16 // System includes
17 #include <string>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
24 
25 // Application includes
26 
27 namespace Kratos
28 {
29 
31 
48 template <typename ...TVariables>
50 {
51  template <template<typename T> class TFunctor, typename ...Targs>
52  struct FunctorWrapper
53  {
54  template <typename TVariable>
55  void Execute(std::string const& rName, bool& found, Targs&... args)
56  {
57  if (!found && KratosComponents<TVariable>::Has(rName))
58  {
59  const TVariable& rVariable = KratosComponents<TVariable>::Get(rName);
60  TFunctor<TVariable>()(rVariable, args...);
61  found = true;
62  }
63  }
64  };
65 
66 public:
67  explicit RegisteredComponentLookup(std::string const& rName) : mName(rName)
68  {}
69 
70  template <template<typename T> class TFunctor, typename ...Targs>
71  void Execute(Targs&... args)
72  {
73  bool found = false;
74  int dummy[sizeof...(TVariables)] = {(FunctorWrapper<TFunctor, Targs...>().template Execute<TVariables>(mName, found, args...), 0)...};
75  ignore_unused_variable_warning(dummy);
76  KRATOS_ERROR_IF(!found) << "Variable \"" << mName << "\" was not found.\n";
77  }
78 
79  private:
80  std::string mName;
81 
82  void ignore_unused_variable_warning(int[]) {}
83 };
84 
85 } // namespace Kratos.
86 
87 #endif // KRATOS_REGISTERED_COMPONENT_LOOKUP_H_INCLUDED defined
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
A class for calling a functor on a variable specified by it's registered name.
Definition: registered_component_lookup.h:50
RegisteredComponentLookup(std::string const &rName)
Definition: registered_component_lookup.h:67
void Execute(Targs &... args)
Definition: registered_component_lookup.h:71
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
args
Definition: generate_gid_list_file.py:37
dummy
Definition: script.py:194