Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usability of user-defined material functions #118

Merged
merged 2 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ def _run_k_points(self, t, k_points):

return all_freqs

def set_epsilon(self, eps):
if self.fields 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()
Expand Down
19 changes: 16 additions & 3 deletions python/typemap_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down