From 539e1442049e6a4dcce827607b4262561ef3a22a Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Thu, 26 Oct 2017 20:29:42 -0500 Subject: [PATCH 1/2] set_epsilon wrapper --- python/simulation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/simulation.py b/python/simulation.py index 1b3b7cc9c..6f4c9867e 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -481,6 +481,12 @@ def _run_k_points(self, t, k_points): return all_freqs + def set_epsilon(self, eps): + if self.structure is None: + self._init_fields() + + self.structure.set_epsilon(eps, self.eps_averaging, self.subpixel_tol, self.subpixel_maxeval) + def add_source(self, src): if self.fields is None: self._init_fields() From 752b7b9fe51443885ebe1ccf2788ad29532dc0e0 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Sat, 28 Oct 2017 10:39:03 -0500 Subject: [PATCH 2/2] Return Vector3 from vec2py instead of tuple --- python/simulation.py | 2 +- python/typemap_utils.cpp | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 6f4c9867e..3304d5e97 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -482,7 +482,7 @@ def _run_k_points(self, t, k_points): return all_freqs def set_epsilon(self, eps): - if self.structure is None: + if self.fields is None: self._init_fields() self.structure.set_epsilon(eps, self.eps_averaging, self.subpixel_tol, self.subpixel_maxeval) diff --git a/python/typemap_utils.cpp b/python/typemap_utils.cpp index 31ad71e66..38d520174 100644 --- a/python/typemap_utils.cpp +++ b/python/typemap_utils.cpp @@ -81,10 +81,24 @@ static PyObject* vec2py(const meep::vec &v) { z = v.z(); break; case meep::Dcyl: - return Py_BuildValue("(ddd)", v.r(), v.z(), 0); + x = v.r(); + z = v.z(); + break; } - return Py_BuildValue("(ddd)", x, y, z); + PyObject *geom_mod = PyImport_ImportModule("meep.geom"); + PyObject *v3_class = PyObject_GetAttrString(geom_mod, "Vector3"); + + PyObject *kwargs = Py_BuildValue("{s:d,s:d,s:d}", "x", x, "y", y, "z", z); + PyObject *args = PyTuple_New(0); + PyObject *pyv3 = PyObject_Call(v3_class, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + Py_DECREF(geom_mod); + Py_DECREF(v3_class); + + return pyv3; } static double py_callback_wrap(const meep::vec &v) { @@ -96,7 +110,6 @@ static double py_callback_wrap(const meep::vec &v) { return ret; } - static int pyv3_to_v3(PyObject *po, vector3 *v) { PyObject *py_x = PyObject_GetAttrString(po, "x");