src/dolfinx_access/nanobind_helpers.cc

Thu, 26 Feb 2026 09:32:12 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 26 Feb 2026 09:32:12 -0500
changeset 1
a4137aedcb3a
permissions
-rw-r--r--

Initial working version for known convectivity and diffusivity

/// Helpers to transmit nanobind C++ → Python bindings Python → Rust → C++.
#include <Python.h>
#include <nanobind/nanobind.h>

#include "pointsource_pde/include/dolfinx_access/nanobind_helpers.h"

using namespace nanobind;

namespace dolfinx_access {
    bool check_Function_f64(const PyObject* obj) {
        auto handle = nanobind::handle(obj);
        return nanobind::isinstance<Function_f64>(handle);
    }

    const Function_f64* cast_Function_f64(const PyObject* obj) {
        auto handle = nanobind::handle(obj);
        return nanobind::cast<const Function_f64*>(handle);
    }

    Function_f64* cast_mut_Function_f64(PyObject* obj) {
        auto handle = nanobind::handle(obj);
        return nanobind::cast<Function_f64*>(handle);
    }

    PyObject* wrap_Function_f64(Function_f64* f) {
        return nanobind::cast(f).release().ptr();
    }

} // namespace dolfinx_access

mercurial