adapt missing from pybind11 interface

Issue #1005 new
Sa Wu created an issue

adapt for adapting MeshFunction to refined meshes, formerly dolfin.cpp.fem.adapt is missing from new pybind11 interface. https://fenicsproject.org/docs/dolfin/dev/python/_autogenerated/dolfin.cpp.fem.html https://fenicsproject.org/docs/dolfin/2017.2.0/python/programmers-reference/cpp/fem/adapt.html

Comments (3)

  1. Ivan Yashchuk

    A quick workaround for this omission:

    cpp_code = """
        #include<pybind11/pybind11.h>
        #include<dolfin/adaptivity/adapt.h>
        #include<dolfin/mesh/Mesh.h>
        #include<dolfin/mesh/MeshFunction.h>
    
        namespace py = pybind11;
    
        PYBIND11_MODULE(SIGNATURE, m) {
           m.def("adapt", (std::shared_ptr<dolfin::MeshFunction<std::size_t>> (*)(const dolfin::MeshFunction<std::size_t>&,
              std::shared_ptr<const dolfin::Mesh>)) &dolfin::adapt,
              py::arg("mesh_function"), py::arg("adapted_mesh"));
        }
        """
    
    adapt = compile_cpp_code(cpp_code).adapt
    
    mesh = UnitSquareMesh.create(5, 5, CellType.Type.triangle)
    rmesh = refine(mesh)
    mf = MeshFunction("size_t", coarse_mesh, coarse_mesh.topology().dim(), 0)
    # Now "adapt" is working
    rmf = adapt(mf, rmesh)
    
  2. Jørgen Dokken

    I think what is needed in pybind is the following:

    Add

    #include <dolfin/adaptivity/adapt.h>
    
    #include "casters.h"
    
    namespace py = pybind11;
    
    namespace dolfin_wrappers
    {
      void fem(py::module& m)
      {
        // Adapt functions
        m.def("adapt", [](dolfin::Mesh mesh){return dolfin::adapt(mesh);});
    

    for each adapt function. I will see if I can make a PR for several functions tomorrow. MWE of python demo:

    from dolfin import *
    import matplotlib.pyplot as plt
    
    mesh = UnitSquareMesh(10,10)
    rmesh = cpp.fem.adapt(mesh)
    plot(mesh, color="b")
    plt.figure()
    plot(rmesh, color="r")
    plt.show()
    

    Which adapt functions from the c++ side is wanted, @sa_wu?

  3. Log in to comment