DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Mesh_bind.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "DNDS/Array_bind.hpp"
5#include "Mesh.hpp"
6#include <pybind11/pybind11.h>
7#include <pybind11_json/pybind11_json.hpp>
8#include <pybind11/eigen.h>
9#include <pybind11/functional.h>
10
11namespace DNDS::Geom
12{
14
15 inline void pybind11_ElemInfo_define(py::module_ &m)
16 {
17 auto ElemInfo_ = tPy_ElemInfo(m, "ElemInfo");
18 ElemInfo_
19 .def("getElemType", &ElemInfo::getElemType)
20 .def("setElemType", &ElemInfo::setElemType)
21 .def_readwrite("zone", &ElemInfo::zone);
22 }
23
24 inline void pybind11_ArrayElemInfo_define(py::module_ &m)
25 {
26 pybind11_Array_define<ElemInfo>(m);
27 pybind11_ParArray_define<ElemInfo>(m);
28 pybind11_ArrayTransformer_define<ParArray<ElemInfo>>(m);
29 pybind11_ParArrayPair_define<ElemInfo>(m);
30 }
31
32 inline void pybind11_MeshLocDefine(py::module_ &m)
33 {
34#define DNDS_PY_ENUM_CLASS_MeshLoc_ADD(v) value(#v, MeshLoc::v)
35 py::enum_<MeshLoc>(m, "MeshLoc")
36 .DNDS_PY_ENUM_CLASS_MeshLoc_ADD(Unknown)
37 .DNDS_PY_ENUM_CLASS_MeshLoc_ADD(Node)
38 .DNDS_PY_ENUM_CLASS_MeshLoc_ADD(Face)
39 .DNDS_PY_ENUM_CLASS_MeshLoc_ADD(Cell);
40#undef DNDS_PY_ENUM_CLASS_MeshLoc_ADD
41 }
42
44
45 inline void pybind11_UnstructuredMesh_define(py::module_ &m)
46 {
47#define DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(foo) \
48 def(#foo, &UnstructuredMesh::foo)
49
50#define DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(m_name) \
51 def_readonly(#m_name, &UnstructuredMesh::m_name, py::return_value_policy::reference_internal)
52
53 auto UnstructuredMesh_ = tPy_UnstructuredMesh(m, "UnstructuredMesh");
54 UnstructuredMesh_
55 .def(py::init<>([](const MPIInfo &mpi, int n_dim)
56 { return std::make_shared<UnstructuredMesh>(mpi, n_dim); }))
57 // basic
58 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(coords)
59 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(cell2node)
60 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(bnd2node)
61 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(bnd2cell)
62 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(cell2cell)
63 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(cellElemInfo)
64 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(bndElemInfo)
65 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(cell2cellOrig)
66 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(node2nodeOrig)
67 // interpolated
68 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(cell2face)
69 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(face2cell)
70 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(face2node)
71 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER(faceElemInfo);
72
73 UnstructuredMesh_
74 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(RecoverNode2CellAndNode2Bnd)
75 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(RecoverCell2CellAndBnd2Cell)
76 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(BuildGhostPrimary)
77 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjGlobal2LocalPrimary)
78 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjLocal2GlobalPrimary)
79 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjGlobal2LocalPrimaryForBnd)
80 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjLocal2GlobalPrimaryForBnd)
81 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjGlobal2LocalFacial)
82 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjLocal2GlobalFacial)
83 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjGlobal2LocalC2F)
84 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjLocal2GlobalC2F)
85 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(BuildGhostN2CB)
86 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjGlobal2LocalN2CB)
87 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AdjLocal2GlobalN2CB)
88 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AssertOnN2CB)
89 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(InterpolateFace)
90 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(AssertOnFaces)
91 .def("ConstructBndMesh", [](UnstructuredMesh &self, ssp<UnstructuredMesh> &pbMesh)
92 { self.ConstructBndMesh(*pbMesh); }, py::arg("bndMesh"))
94 // ObtainLocalFactFillOrdering
95 // ObtainSymmetricSymbolicFactorization
96 // .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(ReorderLocalCells) //! it has argument now
97 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(getMPI)
98 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(getDim)
99 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumNode)
100 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumCell)
101 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumFace)
102 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumBnd)
103 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumNodeGhost)
104 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumCellGhost)
105 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumFaceGhost)
106 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumBndGhost)
107 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumNodeProc)
108 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumCellProc)
109 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumFaceProc)
110 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumBndProc)
111 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumNodeGlobal)
112 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumCellGlobal)
113 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumFaceGlobal)
114 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(NumBndGlobal);
115 //!!
116 UnstructuredMesh_
117 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(BuildO2FromO1Elevation)
118 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(BuildBisectO1FormO2)
119 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(RecreatePeriodicNodes)
120 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(BuildVTKConnectivity);
121
122 UnstructuredMesh_
123 .DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(getArrayBytes);
124#undef DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_READONLY_MEMBER
125#undef DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC
126
127 UnstructuredMesh_
128 .def("ReorderLocalCells", &UnstructuredMesh::ReorderLocalCells, py::arg("nParts") = 1, py::arg("nPartsInner") = 1)
129 .def("ReadSerialize", &UnstructuredMesh::ReadSerialize, py::arg("serializer"), py::arg("name"))
130 .def("WriteSerialize", &UnstructuredMesh::WriteSerialize, py::arg("serializer"), py::arg("name"))
131 .def(
132 "ReadSerializeAndDistribute",
134 const std::string &name, py::object options_in)
135 {
136 auto options_full = PartitionOptions();
137 auto json_options_full = nlohmann::ordered_json(options_full);
138 if (!options_in.is_none())
139 {
140 auto json_options_in = nlohmann::json(options_in);
141 json_options_full.merge_patch(json_options_in);
142 }
144 serializer, name,
145 json_options_full.template get<PartitionOptions>());
146 },
147 py::arg("serializer"), py::arg("name"), py::arg("partitionOptions") = py::none());
148
149 UnstructuredMesh_.def("SetPeriodicGeometry", &UnstructuredMesh::SetPeriodicGeometry,
150 py::arg("translation1") = Geom::tPoint{1, 0, 0},
151 py::arg("rotationCenter1") = Geom::tPoint{0, 0, 0},
152 py::arg("eulerAngles1") = Geom::tPoint{0, 0, 0},
153 py::arg("translation2") = Geom::tPoint{0, 1, 0},
154 py::arg("rotationCenter2") = Geom::tPoint{0, 0, 0},
155 py::arg("eulerAngles2") = Geom::tPoint{0, 0, 0},
156 py::arg("translation3") = Geom::tPoint{0, 0, 1},
157 py::arg("rotationCenter3") = Geom::tPoint{0, 0, 0},
158 py::arg("eulerAngles3") = Geom::tPoint{0, 0, 0});
159
160 UnstructuredMesh_
161 .def("CellFaceOther", &UnstructuredMesh::CellFaceOther,
162 py::arg("iCell"), py::arg("iFace"))
163 .def("CellIsFaceBack", &UnstructuredMesh::CellIsFaceBack,
164 py::arg("iCell"), py::arg("iFace"));
165
166 auto WallDistOptions_ = py_class_ssp<UnstructuredMesh::WallDistOptions>(UnstructuredMesh_, "WallDistOptions");
167 WallDistOptions_.def(py::init());
168 WallDistOptions_
169 .def_readwrite("method", &UnstructuredMesh::WallDistOptions::method)
170 .def_readwrite("verbose", &UnstructuredMesh::WallDistOptions::verbose)
171 .def_readwrite("wallDistExecution", &UnstructuredMesh::WallDistOptions::wallDistExecution)
172 .def_readwrite("minWallDist", &UnstructuredMesh::WallDistOptions::minWallDist)
173 .def_readwrite("subdivide_quad", &UnstructuredMesh::WallDistOptions::subdivide_quad);
174
175 UnstructuredMesh_
176 .def("BuildNodeWallDist", &UnstructuredMesh::BuildNodeWallDist, py::arg("fBndIsWall"), py::arg("options") = UnstructuredMesh::WallDistOptions{});
177
178 UnstructuredMesh_
179 .def("to_device", [](UnstructuredMesh &self, const std::string &backend)
180 { self.to_device(device_backend_name_to_enum(backend)); }, py::arg("backend"))
181 .def("to_host", &UnstructuredMesh::to_host);
182 }
183
185
187 {
188 auto UnstructuredMeshSerialRW_ = tPy_UnstructuredMeshSerialRW(m, "UnstructuredMeshSerialRW");
189 UnstructuredMeshSerialRW_
190 .def(py::init(
191 [](ssp<UnstructuredMesh> mesh, MPI_int mRank)
192 { return std::make_shared<UnstructuredMeshSerialRW>(mesh, mRank); }),
193 py::arg("mesh"), py::arg("mRank") = 0)
194 .def_readwrite("mesh", &UnstructuredMeshSerialRW::mesh)
195 .def_readonly("dataIsSerialOut", &UnstructuredMeshSerialRW::dataIsSerialOut)
196 .def_readonly("dataIsSerialIn", &UnstructuredMeshSerialRW::dataIsSerialIn)
197 .def("ReadFromCGNSSerial", py::overload_cast<const std::string &>(&UnstructuredMeshSerialRW::ReadFromCGNSSerial))
198 .def("Deduplicate1to1Periodic", &UnstructuredMeshSerialRW::Deduplicate1to1Periodic)
199 .def("BuildCell2Cell", &UnstructuredMeshSerialRW::BuildCell2Cell)
200 .def("BuildSerialOut", &UnstructuredMeshSerialRW::BuildSerialOut)
201 .def(
202 "MeshPartitionCell2Cell",
203 [](UnstructuredMeshSerialRW &self, py::object options_in) // use default
204 {
205 auto options_full = UnstructuredMeshSerialRW::PartitionOptions();
206 auto json_options_full = nlohmann::ordered_json(options_full); // warning: using {} here makes it a list
207 if (!options_in.is_none())
208 {
209 auto json_options_in = nlohmann::json(options_in);
210 json_options_full.merge_patch(json_options_in);
211 }
212 // std::cout << json_options_full << std::endl;
213 self.MeshPartitionCell2Cell(json_options_full.template get<UnstructuredMeshSerialRW::PartitionOptions>());
214 },
215 py::arg("options") = py::none())
216 .def("PartitionReorderToMeshCell2Cell", &UnstructuredMeshSerialRW::PartitionReorderToMeshCell2Cell);
217 }
218}
pybind11 bindings for Array / ParArray / ArrayPair.
Shared pybind11 plumbing used by every *_bind.hpp in DNDS (buffer-protocol type check,...
#define DNDS_GEOM_UNSTRUCTURED_MESH_PY_DEF_SIMP_FUNC(foo)
void to_host()
Pull every registered pair back to host memory.
void to_device(DeviceBackend B)
Mirror every registered ArrayPair to the given device backend.
void pybind11_ArrayElemInfo_define(py::module_ &m)
Definition Mesh_bind.hpp:24
Eigen::Vector3d tPoint
Definition Geometric.hpp:9
void pybind11_ElemInfo_define(py::module_ &m)
Definition Mesh_bind.hpp:15
py_class_ssp< ElemInfo > tPy_ElemInfo
Definition Mesh_bind.hpp:13
py_class_ssp< UnstructuredMesh > tPy_UnstructuredMesh
Definition Mesh_bind.hpp:43
void pybind11_UnstructuredMeshSerialRW_define(py::module_ &m)
void pybind11_UnstructuredMesh_define(py::module_ &m)
Definition Mesh_bind.hpp:45
void pybind11_MeshLocDefine(py::module_ &m)
Definition Mesh_bind.hpp:32
py_class_ssp< UnstructuredMeshSerialRW > tPy_UnstructuredMeshSerialRW
ssp< SerializerBase > SerializerBaseSSP
py::classh< T > py_class_ssp
DeviceBackend device_backend_name_to_enum(std::string_view s)
Inverse of device_backend_name. Returns Unknown for unrecognised names.
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:138
int MPI_int
MPI counterpart type for MPI_int (= C int). Used for counts and ranks in MPI calls.
Definition MPI.hpp:43
DNDS_DEVICE_CALLABLE Elem::ElemType getElemType() const
t_index zone
positive for BVnum, 0 for internal Elems, Negative for ?
DNDS_DEVICE_CALLABLE void setElemType(Elem::ElemType t)
void MeshPartitionCell2Cell(const PartitionOptions &options)
void ReadFromCGNSSerial(const std::string &fName, const t_FBCName_2_ID &FBCName_2_ID)
reads a cgns file as serial input
void BuildSerialOut()
should be called to build data for serial out
Definition Mesh.cpp:203
DNDS::ssp< UnstructuredMesh > mesh
Definition Mesh.hpp:856
void BuildCell2Cell()
build cell2cell topology, with node-neighbors included
Geom::PartitionOptions PartitionOptions
Definition Mesh.hpp:849
void ReorderLocalCells(int nParts=1, int nPartsInner=1)
Definition Mesh.cpp:2405
void ReadSerialize(Serializer::SerializerBaseSSP serializerP, const std::string &name)
Definition Mesh.cpp:1970
bool CellIsFaceBack(index iCell, index iFace) const
Definition Mesh.hpp:618
index CellFaceOther(index iCell, index iFace) const
Definition Mesh.hpp:624
void SetPeriodicGeometry(const tPoint &translation1, const tPoint &rotationCenter1, const tPoint &eulerAngles1, const tPoint &translation2, const tPoint &rotationCenter2, const tPoint &eulerAngles2, const tPoint &translation3, const tPoint &rotationCenter3, const tPoint &eulerAngles3)
Definition Mesh.cpp:457
void WriteSerialize(Serializer::SerializerBaseSSP serializerP, const std::string &name)
Definition Mesh.cpp:1933
void ReadSerializeAndDistribute(Serializer::SerializerBaseSSP serializerP, const std::string &name, const PartitionOptions &partitionOptions)
Reads mesh from an H5 serializer using even-split distribution, then repartitions via ParMetis for lo...
void ConstructBndMesh(UnstructuredMesh &bMesh)
Definition Mesh.cpp:2061
void BuildNodeWallDist(const std::function< bool(Geom::t_index)> &fBndIsWall, WallDistOptions options=WallDistOptions{})
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215