diff --git a/src/simsopt/field/magneticfieldclasses.py b/src/simsopt/field/magneticfieldclasses.py index 286d436fa..474217b2b 100644 --- a/src/simsopt/field/magneticfieldclasses.py +++ b/src/simsopt/field/magneticfieldclasses.py @@ -489,6 +489,7 @@ def __init__(self, field, degree, rrange, phirange, zrange, extrapolate=True, nf logger.warning(fr"Sure about phirange[1]={phirange[1]}? When exploiting rotational symmetry, the interpolant is never evaluated for phi>2\pi/nfp.") sopp.InterpolatedField.__init__(self, field, degree, rrange, phirange, zrange, extrapolate, nfp, stellsym) + self.__field == field def to_vtk(self, filename, h=0.1): """Export the field evaluated on a regular grid for visualisation with e.g. Paraview.""" diff --git a/src/simsoptpp/py_shared_ptr.h b/src/simsoptpp/py_shared_ptr.h deleted file mode 100644 index be7ecce99..000000000 --- a/src/simsoptpp/py_shared_ptr.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -// see https://github.com/pybind/pybind11/issues/1389 - -#include -#include -namespace py = pybind11; - -template class py_shared_ptr { - private: - std::shared_ptr _impl; - - public: - using element_type = T; - - py_shared_ptr(T *ptr) { - py::object pyobj = py::cast(ptr); - PyObject* pyptr = pyobj.ptr(); - Py_INCREF(pyptr); - std::shared_ptr vec_py_ptr( - pyptr, [](PyObject *ob) { Py_DECREF(ob); }); - _impl = std::shared_ptr(vec_py_ptr, ptr); - } - - py_shared_ptr(std::shared_ptr r): _impl(r){} - - operator std::shared_ptr() { return _impl; } - - T* get() const {return _impl.get();} -}; diff --git a/src/simsoptpp/python.cpp b/src/simsoptpp/python.cpp index 48e1977aa..f556ba541 100644 --- a/src/simsoptpp/python.cpp +++ b/src/simsoptpp/python.cpp @@ -1,8 +1,6 @@ #include "pybind11/pybind11.h" #include "pybind11/stl.h" #include "pybind11/functional.h" -#include "py_shared_ptr.h" -PYBIND11_DECLARE_HOLDER_TYPE(T, py_shared_ptr); #define FORCE_IMPORT_ARRAY #include "xtensor-python/pyarray.hpp" // Numpy bindings typedef xt::pyarray PyArray; diff --git a/src/simsoptpp/python_curves.cpp b/src/simsoptpp/python_curves.cpp index 70e73e8b8..41d29bb12 100644 --- a/src/simsoptpp/python_curves.cpp +++ b/src/simsoptpp/python_curves.cpp @@ -2,8 +2,6 @@ #include "pybind11/stl.h" #include "xtensor-python/pyarray.hpp" // Numpy bindings typedef xt::pyarray PyArray; -#include "py_shared_ptr.h" -PYBIND11_DECLARE_HOLDER_TYPE(T, py_shared_ptr); using std::shared_ptr; @@ -90,16 +88,16 @@ template void register_common_curve_methods(S &c) { } void init_curves(py::module_ &m) { - auto pycurve = py::class_, PyCurveTrampoline>(m, "Curve") + auto pycurve = py::class_, PyCurveTrampoline>(m, "Curve") .def(py::init>()); register_common_curve_methods(pycurve); - auto pycurvexyzfourier = py::class_, PyCurveXYZFourierTrampoline, PyCurve>(m, "CurveXYZFourier") + auto pycurvexyzfourier = py::class_, PyCurveXYZFourierTrampoline, PyCurve>(m, "CurveXYZFourier") .def(py::init, int>()) .def_readonly("dofs", &PyCurveXYZFourier::dofs); register_common_curve_methods(pycurvexyzfourier); - auto pycurverzfourier = py::class_, PyCurveRZFourierTrampoline, PyCurve>(m, "CurveRZFourier") + auto pycurverzfourier = py::class_, PyCurveRZFourierTrampoline, PyCurve>(m, "CurveRZFourier") //.def(py::init()) .def(py::init, int, int, bool>()) .def_readwrite("rc", &PyCurveRZFourier::rc) diff --git a/src/simsoptpp/python_surfaces.cpp b/src/simsoptpp/python_surfaces.cpp index 606c9f628..0d19bd6fa 100644 --- a/src/simsoptpp/python_surfaces.cpp +++ b/src/simsoptpp/python_surfaces.cpp @@ -2,8 +2,6 @@ #include "pybind11/stl.h" #include "xtensor-python/pyarray.hpp" // Numpy bindings typedef xt::pyarray PyArray; -#include "py_shared_ptr.h" -PYBIND11_DECLARE_HOLDER_TYPE(T, py_shared_ptr); using std::shared_ptr; using std::vector;