DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
FiniteVolume_bind.cpp
Go to the documentation of this file.
2#include <pybind11/stl.h>
3#include <pybind11/eigen.h>
4#include <pybind11_json/pybind11_json.hpp>
5
6namespace DNDS::CFV
7{
8 void pybind11_FiniteVolume_define(py::module_ &m)
9 {
10 using T = FiniteVolume;
11 auto FiniteVolume_ = tPy_FiniteVolume(m, "FiniteVolume");
12 FiniteVolume_.def(py::init([](MPIInfo &mpi, ssp<Geom::UnstructuredMesh> mesh)
13 { return std::make_shared<T>(mpi, mesh); }));
14 FiniteVolume_
15 .def(
16 "GetSettings", [](T &self)
17 {
18 nlohmann::ordered_json outJson;
19 self.getSettings().WriteIntoJson(outJson);
20 return py::object{outJson}; });
21 FiniteVolume_
22 .def(
23 "ParseSettings", [](T &self, py::object settings)
24 {
25 FiniteVolumeSettings defaultSettings(self.getDim());
26 nlohmann::ordered_json defaultJson;
27 defaultSettings.WriteIntoJson(defaultJson);
28 nlohmann::json settings_json = settings;
29 defaultJson.merge_patch(settings_json);
30 self.parseSettings(defaultJson); },
31 py::arg("settings"));
32
33#define DNDS_PY_DEF_SIMP_FUNC(foo) \
34 def(#foo, &T::foo)
35
36 FiniteVolume_
37 .DNDS_PY_DEF_SIMP_FUNC(SetCellAtrBasic)
38 .
39
40 DNDS_PY_DEF_SIMP_FUNC(ConstructCellVolume)
41 .DNDS_PY_DEF_SIMP_FUNC(ConstructCellBary)
42 .DNDS_PY_DEF_SIMP_FUNC(ConstructCellCent)
43 .DNDS_PY_DEF_SIMP_FUNC(ConstructCellIntJacobiDet)
44 .DNDS_PY_DEF_SIMP_FUNC(ConstructCellIntPPhysics)
45 .DNDS_PY_DEF_SIMP_FUNC(ConstructCellAlignedHBox)
46 . // note this is AABB
47 DNDS_PY_DEF_SIMP_FUNC(ConstructCellMajorHBoxCoordInertia)
48 .
49
50 DNDS_PY_DEF_SIMP_FUNC(SetFaceAtrBasic)
51 .
52
53 DNDS_PY_DEF_SIMP_FUNC(ConstructFaceArea)
54 .DNDS_PY_DEF_SIMP_FUNC(ConstructFaceCent)
55 .DNDS_PY_DEF_SIMP_FUNC(ConstructFaceIntJacobiDet)
56 .DNDS_PY_DEF_SIMP_FUNC(ConstructFaceIntPPhysics)
57 .DNDS_PY_DEF_SIMP_FUNC(ConstructFaceUnitNorm)
58 . // on quad int points
59 DNDS_PY_DEF_SIMP_FUNC(ConstructFaceMeanNorm)
60 .
61
62 DNDS_PY_DEF_SIMP_FUNC(ConstructCellSmoothScale);
63
64 FiniteVolume_
65 .def("GetCellAtr", &T::GetCellAtr, py::arg("iCell"), py::return_value_policy::reference_internal)
66 .def("GetCellOrder", &T::GetCellOrder, py::arg("iCell"));
67
68 FiniteVolume_
69 .def("GetFaceAtr", &T::GetFaceAtr, py::arg("iFace"), py::return_value_policy::reference_internal);
70
71 FiniteVolume_
72 .def("GetCellVol", &T::GetCellVol, py::arg("iCell"))
73 .def("GetFaceArea", &T::GetFaceArea, py::arg("iFace"));
74
75 FiniteVolume_
76 .def("GetGlobalVol", &T::GetGlobalVol);
77 FiniteVolume_
78 .def("GetCellSmoothScaleRatio", &T::GetCellSmoothScaleRatio, py::arg("iCell"));
79
80 FiniteVolume_
81 .def("GetCellJacobiDet", &T::GetCellJacobiDet, py::arg("iCell"), py::arg("iG"))
82 .def("GetFaceJacobiDet", &T::GetFaceJacobiDet, py::arg("iFace"), py::arg("iG"));
83
84 FiniteVolume_
85 .def("GetFaceParamArea", &T::GetFaceParamArea, py::arg("iFace"));
86
87 FiniteVolume_
88 .def("GetCellBary", &T::GetCellBary, py::arg("iCell"));
89
90 FiniteVolume_
91 .def("CellIsFaceBack", &T::CellIsFaceBack, py::arg("iCell"), py::arg("iFace"));
92 FiniteVolume_
93 .def("CellFaceOther", &T::CellFaceOther, py::arg("iCell"), py::arg("iFace"));
94
95 FiniteVolume_
96 .def("GetFaceNorm", &T::GetFaceNorm, py::arg("iFace"), py::arg("iG"));
97 FiniteVolume_
98 .def("GetFaceNormFromCell", &T::GetFaceNormFromCell, py::arg("iFace"), py::arg("iCell"), py::arg("if2c"), py::arg("iG"));
99
100 FiniteVolume_
101 .def("GetFaceQuadraturePPhys", &T::GetFaceQuadraturePPhys, py::arg("iFace"), py::arg("iG"));
102 FiniteVolume_
103 .def("GetFaceQuadraturePPhysFromCell", &T::GetFaceQuadraturePPhysFromCell, py::arg("iFace"), py::arg("iCell"), py::arg("if2c"), py::arg("iG"));
104 FiniteVolume_
105 .def("GetFacePointFromCell", &T::GetFacePointFromCell, py::arg("iFace"), py::arg("iCell"), py::arg("if2c"), py::arg("pnt"));
106
107 FiniteVolume_
108 .def("GetOtherCellBaryFromCell", &T::GetOtherCellBaryFromCell, py::arg("iCell"), py::arg("iCellOther"), py::arg("iFace"));
109 FiniteVolume_
110 .def("GetOtherCellPointFromCell", &T::GetOtherCellPointFromCell, py::arg("iCell"), py::arg("iCellOther"), py::arg("iFace"), py::arg("pnt"));
111 FiniteVolume_
112 .def("GetOtherCellInertiaFromCell", &T::GetOtherCellInertiaFromCell, py::arg("iCell"), py::arg("iCellOther"), py::arg("iFace"));
113 FiniteVolume_
114 .def("GetCellQuadraturePPhys", &T::GetCellQuadraturePPhys, py::arg("iCell"), py::arg("iG"));
115 FiniteVolume_
116 .def("GetCellMaxLenScale", &T::GetCellMaxLenScale, py::arg("iCell"));
117 FiniteVolume_
118 .def("getArrayBytes", &T::getArrayBytes);
119
120 FiniteVolume_
121 .def("to_device", [](FiniteVolume &self, const std::string &backend)
122 { self.to_device(device_backend_name_to_enum(backend)); }, py::arg("backend"))
123 .def("to_host", &FiniteVolume::to_host);
124
125#define DNDS_CFV_FV_PYBIND11_DEFINE_BuildUDof(nVarsFixed) \
126 FiniteVolume_.def( \
127 ("BuildUDof_" + RowSize_To_PySnippet(nVarsFixed)).c_str(), \
128 [](T &self, tUDof<nVarsFixed> &u, int nVars, bool buildSon, bool buildTrans, Geom::MeshLoc varloc) \
129 { self.BuildUDof(u, nVars, buildSon, buildTrans, varloc); }, \
130 py::arg("u"), py::arg("nVars"), py::arg("buildSon") = true, \
131 py::arg("buildTrans") = true, py::arg("varloc") = Geom::MeshLoc::Cell, \
132 DNDS_PYBIND11_OSTREAM_GUARD)
133
134#define DNDS_CFV_FV_PYBIND11_DEFINE_BuildUGrad(nVarsFixed) \
135 FiniteVolume_ \
136 .def( \
137 ("BuildUGrad_2x" + RowSize_To_PySnippet(nVarsFixed)).c_str(), \
138 [](T &self, tUGrad<nVarsFixed, 2> &u, int nVars, bool buildSon, bool buildTrans, Geom::MeshLoc varloc) \
139 { self.BuildUGradD(u, nVars, buildSon, buildTrans, varloc); }, \
140 py::arg("u"), py::arg("nVars"), py::arg("buildSon") = true, \
141 py::arg("buildTrans") = true, py::arg("varloc") = Geom::MeshLoc::Cell, \
142 DNDS_PYBIND11_OSTREAM_GUARD) \
143 .def( \
144 ("BuildUGrad_3x" + RowSize_To_PySnippet(nVarsFixed)).c_str(), \
145 [](T &self, tUGrad<nVarsFixed, 3> &u, int nVars, bool buildSon, bool buildTrans, Geom::MeshLoc varloc) \
146 { self.BuildUGradD(u, nVars, buildSon, buildTrans, varloc); }, \
147 py::arg("u"), py::arg("nVars"), py::arg("buildSon") = true, \
148 py::arg("buildTrans") = true, py::arg("varloc") = Geom::MeshLoc::Cell, \
149 DNDS_PYBIND11_OSTREAM_GUARD)
150
151#define DNDS_CFV_FV_PYBIND11_DEFINE_BuildCalls(nVarsFixed) \
152 { \
153 DNDS_CFV_FV_PYBIND11_DEFINE_BuildUDof(nVarsFixed); \
154 DNDS_CFV_FV_PYBIND11_DEFINE_BuildUGrad(nVarsFixed); \
155 }
156
163 }
164}
#define DNDS_CFV_FV_PYBIND11_DEFINE_BuildCalls(nVarsFixed)
#define DNDS_PY_DEF_SIMP_FUNC(foo)
void to_host()
Pull every registered pair back to host memory.
void pybind11_FiniteVolume_define(py::module_ &m)
py_class_ssp< FiniteVolume > tPy_FiniteVolume
DeviceBackend device_backend_name_to_enum(std::string_view s)
Inverse of device_backend_name. Returns Unknown for unrecognised names.
DNDS_CONSTANT const rowsize DynamicSize
Template parameter flag: "row width is set at runtime but uniform".
Definition Defines.hpp:277
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:138
A means to translate nlohmann json into c++ primitive data types and back; and stores then during com...
DNDS_HOST void WriteIntoJson(json &jsonSetting) const
Backward-compatible write (used by Python bindings and VRSettings).
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215