Commit 1c29399f authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[python][io][gmsh] register new functionality

parent 66410b32
......@@ -19,9 +19,12 @@
#ifndef FRACKIT_PYTHON_IO_GMSH_WRITER_HH
#define FRACKIT_PYTHON_IO_GMSH_WRITER_HH
#include <vector>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <frackit/io/gmshwriter.hh>
#include <frackit/common/id.hh>
#include <frackit/entitynetwork/entitynetwork.hh>
#include <frackit/python/entitynetwork/traits.hh>
......@@ -36,8 +39,70 @@ void registerGmshWriter(py::module& module)
py::class_<GmshWriter> cls(module, "GmshWriter");
cls.def(py::init<const EntityNetwork&>());
cls.def(py::init<const EntityNetwork&, int, int>());
using namespace py::literals;
// overloading with py::overload_cast seemed to fail when having mixed template/non-template functions
cls.def("write",
static_cast<void (GmshWriter::*)(const std::string&) const>(&GmshWriter::write),
"fileName"_a, "write the entity network to a .geo file");
// register geometry tags for setter functions
py::enum_<GmshWriter::GeometryTag>(cls, "GeometryTag")
.value("subDomain", GmshWriter::GeometryTag::subDomain)
.value("entity", GmshWriter::GeometryTag::entity)
.value("intersection", GmshWriter::GeometryTag::intersection)
.value("junction", GmshWriter::GeometryTag::junction);
// register geometry tag getter function for given dimension
cls.def("getGeometryTag", &GmshWriter::getGeometryTag,
"returns the geometry tag associated with the geometries of the given dimension");
// physical status setter functions
cls.def("setGmshVersion", &GmshWriter::setGmshVersion, "set gmsh format version");
// we define overloads for vector<Id> which is automatically converted
// by pybind11 such that it can be used with lists from within Python
using IdList = std::vector<Id>;
cls.def("setNonPhysical",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag)>(&GmshWriter::setNonPhysical),
"set all geometries with the given type tag to be non-physical");
cls.def("setNonPhysical",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag, const Id&)>(&GmshWriter::setNonPhysical),
"set the geometry with the given type tag and identifier to be non-physical");
cls.def("setNonPhysical",
py::overload_cast<GmshWriter::GeometryTag, const IdList&>(&GmshWriter::template setNonPhysical<IdList>),
"set all geometries with a specific type tag and with the ids of the given list to be non-physical");
cls.def("setPhysical",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag)>(&GmshWriter::setPhysical),
"set all geometries with the given type tag to be physical");
cls.def("setPhysical",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag, const Id&)>(&GmshWriter::setPhysical),
"set the geometry with the given type tag and identifier to be physical");
cls.def("setPhysical",
py::overload_cast<GmshWriter::GeometryTag, const IdList&>(&GmshWriter::template setPhysical<IdList>),
"set all geometries with a specific type tag and with the ids of the given list to be physical");
// mesh size setters
cls.def("setMeshSize",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag, ctype)>(&GmshWriter::template setMeshSize<ctype>),
"set the mesh size for all geometries with the given type tag");
cls.def("setMeshSize",
static_cast<void (GmshWriter::*)(GmshWriter::GeometryTag, const Id&, ctype)>(&GmshWriter::template setMeshSize<ctype>),
"set the mesh size for the geometry with the given type tag and identifier");
cls.def("setMeshSize",
py::overload_cast<GmshWriter::GeometryTag, const IdList&, ctype>(&GmshWriter::template setMeshSize<IdList, ctype>),
"set the mesh size for all geometries with a specific type tag and with the ids of the given list");
cls.def("resetMeshSizes",
py::overload_cast<>(&GmshWriter::resetMeshSizes),
"Reset all mesh size settings");
cls.def("resetMeshSizes",
py::overload_cast<GmshWriter::GeometryTag>(&GmshWriter::resetMeshSizes),
"Reset the mesh size settings for geometries with the given type tag");
// deprecated (TODO: remove afer 1.2 release)
cls.def("write",
py::overload_cast<const std::string&, ctype, ctype>(&GmshWriter::template write<ctype>),
"fileName"_a, "meshSizeAtEntities"_a, "meshSizeAtBoundary"_a,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment