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.
define_python.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 #include <pybind11/pybind11.h>
19 
20 // Project includes
21 #include "intrusive_ptr/intrusive_ptr.hpp"
22 
23 // Always needed for custom holder types
24 PYBIND11_DECLARE_HOLDER_TYPE(T, Kratos::intrusive_ptr<T>);
25 
26 #include <pybind11/stl.h>
27 #include <pybind11/stl/filesystem.h>
28 
29 #include "includes/define.h"
30 
31 
32 #ifdef KRATOS_REGISTER_IN_PYTHON_VARIABLE
33 #undef KRATOS_REGISTER_IN_PYTHON_VARIABLE
34 #endif
35 #define KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,variable) \
36  module.attr(#variable) = &variable;
37 
38 #ifdef KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS
39 #undef KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS
40 #endif
41 #define KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS(module,name) \
42  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name) \
43  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_X) \
44  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_Y) \
45  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_Z)
46 
47 #ifdef KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_2D_TENSOR_VARIABLE_WITH_COMPONENTS
48 #undef KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_2D_TENSOR_VARIABLE_WITH_COMPONENTS
49 #endif
50 #define KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_2D_TENSOR_VARIABLE_WITH_COMPONENTS(module,name) \
51  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name) \
52  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XX) \
53  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YY) \
54  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XY)
55 
56 #ifdef KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_3D_TENSOR_VARIABLE_WITH_COMPONENTS
57 #undef KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_3D_TENSOR_VARIABLE_WITH_COMPONENTS
58 #endif
59 #define KRATOS_REGISTER_IN_PYTHON_SYMMETRIC_3D_TENSOR_VARIABLE_WITH_COMPONENTS(module,name) \
60  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name) \
61  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XX) \
62  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YY) \
63  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_ZZ) \
64  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XY) \
65  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YZ) \
66  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XZ)
67 
68 #ifdef KRATOS_REGISTER_IN_PYTHON_2D_TENSOR_VARIABLE_WITH_COMPONENTS
69 #undef KRATOS_REGISTER_IN_PYTHON_2D_TENSOR_VARIABLE_WITH_COMPONENTS
70 #endif
71 #define KRATOS_REGISTER_IN_PYTHON_2D_TENSOR_VARIABLE_WITH_COMPONENTS(module,name) \
72  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name) \
73  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XX) \
74  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XY) \
75  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YX) \
76  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YY)
77 
78 #ifdef KRATOS_REGISTER_IN_PYTHON_3D_TENSOR_VARIABLE_WITH_COMPONENTS
79 #undef KRATOS_REGISTER_IN_PYTHON_3D_TENSOR_VARIABLE_WITH_COMPONENTS
80 #endif
81 #define KRATOS_REGISTER_IN_PYTHON_3D_TENSOR_VARIABLE_WITH_COMPONENTS(module,name) \
82  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name) \
83  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XX) \
84  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XY) \
85  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_XZ) \
86  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YX) \
87  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YY) \
88  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_YZ) \
89  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_ZX) \
90  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_ZY) \
91  KRATOS_REGISTER_IN_PYTHON_VARIABLE(module,name##_ZZ)
92 
93 #ifdef KRATOS_REGISTER_IN_PYTHON_FLAG_IMPLEMENTATION
94 #undef KRATOS_REGISTER_IN_PYTHON_FLAG_IMPLEMENTATION
95 #endif
96 #define KRATOS_REGISTER_IN_PYTHON_FLAG_IMPLEMENTATION(module,flag) \
97  module.attr(#flag) = &flag;
98 
99 
100 #ifdef KRATOS_REGISTER_IN_PYTHON_FLAG
101 #undef KRATOS_REGISTER_IN_PYTHON_FLAG
102 #endif
103 #define KRATOS_REGISTER_IN_PYTHON_FLAG(module,flag) \
104  KRATOS_REGISTER_IN_PYTHON_FLAG_IMPLEMENTATION(module,flag);
105 
106 // This function is used to print the ofstream-operator
107 // i.e. printing an object will give the same result in Python as in C++
108 // To be defined as the "__str__" function
109 // e.g. ".def("__str__", PrintObject<ProcessInfo>)"
110 // It replicates the function "self_ns::str(self))" of boost-python
111 template< class T>
112 std::string PrintObject(const T& rObject)
113 {
114  std::stringstream ss;
115  ss << rObject;
116  return ss.str();
117 }
PYBIND11_DECLARE_HOLDER_TYPE(T, Kratos::intrusive_ptr< T >)
std::string PrintObject(const T &rObject)
Definition: define_python.h:112