OGS
ogs_mesh_python_module.cpp
Go to the documentation of this file.
1
13#include <pybind11/eigen.h>
14#include <pybind11/pybind11.h>
15#include <pybind11/stl.h>
16
17#include <algorithm>
18#include <numeric>
19
21#include "BaseLib/Logging.h"
22#include "InfoLib/GitInfo.h"
23#include "OGSMesh.h"
24
27{
28#ifndef NDEBUG
30#else // NDEBUG
32#endif // NDEBUG
33 m.attr("__name__") = "ogs.mesh";
34 m.doc() = "pybind11 ogs mesh example plugin";
35
36 pybind11::enum_<MeshLib::MeshItemType>(m, "MeshItemType")
37 .value("Node", MeshLib::MeshItemType::Node)
38 .value("Edge", MeshLib::MeshItemType::Edge)
39 .value("Face", MeshLib::MeshItemType::Face)
40 .value("Cell", MeshLib::MeshItemType::Cell)
41 .value("IntegrationPoint", MeshLib::MeshItemType::IntegrationPoint)
42 .export_values()
43 // Add nice string conversion
44 .def("__str__",
45 [](MeshLib::MeshItemType t) { return std::string(toString(t)); });
46
47 pybind11::class_<OGSMesh>(m, "OGSMesh")
48 .def("points", &OGSMesh::getPointCoordinates, "get node coordinates")
49 .def("cells", &OGSMesh::getCells, pybind11::return_value_policy::copy,
50 "get cells")
51 .def("data_array_names", &OGSMesh::getDataArrayNames,
52 "get names of all data arrays / property "
53 "vectors stored in the mesh")
54 .def("mesh_item_type", &OGSMesh::meshItemType, pybind11::arg("name"),
55 "returns MeshItemType")
56 .def("data_array", &OGSMesh::dataArray_dispatch,
57 pybind11::return_value_policy::reference, pybind11::arg("name"),
58 pybind11::arg("dtype"),
59 "Access a data array / property vector (accesses OGS memory "
60 "directly using numpy array with appropriate shape)");
61}
Git information.
MeshLib::MeshItemType meshItemType(std::string_view const name) const
Definition OGSMesh.cpp:57
std::vector< double > getPointCoordinates() const
Definition OGSMesh.cpp:32
pybind11::object dataArray_dispatch(std::string const &name, std::string const &dtype)
Definition OGSMesh.h:117
std::vector< std::string > getDataArrayNames() const
Definition OGSMesh.cpp:52
std::pair< std::vector< int >, std::vector< int > > getCells() const
Definition OGSMesh.cpp:38
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
PYBIND11_MODULE(OGSMesh, m)
python module name is OpenGeoSys