Skip to content

Commit

Permalink
Python interface for slanted prisms (NanoComp#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Feb 19, 2020
1 parent 57e075b commit 71afd27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def __init__(self, **kwargs):

class Prism(GeometricObject):

def __init__(self, vertices, height, axis=Vector3(z=1), center=None, **kwargs):
def __init__(self, vertices, height, axis=Vector3(z=1), center=None, sidewall_angle=0, **kwargs):
centroid = sum(vertices, Vector3(0)) * (1.0 / len(vertices)) # centroid of floor polygon
original_center = centroid + (0.5*height)*axis # center as computed from vertices, height, axis
if center is not None and len(vertices):
Expand All @@ -506,6 +506,7 @@ def __init__(self, vertices, height, axis=Vector3(z=1), center=None, **kwargs):
self.vertices = vertices
self.height = height
self.axis = axis
self.sidewall_angle = sidewall_angle

super(Prism, self).__init__(center=center, **kwargs)

Expand Down
8 changes: 7 additions & 1 deletion python/typemap_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,11 @@ static int pyellipsoid_to_ellipsoid(PyObject *py_ell, geometric_object *e) {

static int pyprism_to_prism(PyObject *py_prism, geometric_object *p) {
material_type material;
double height;
double height, sidewall_angle;
vector3 axis, center;

if (!get_attr_material(py_prism, &material) || !get_attr_dbl(py_prism, &height, "height") ||
!get_attr_dbl(py_prism, &sidewall_angle, "sidewall_angle") ||
!get_attr_v3(py_prism, &center, "center") || !get_attr_v3(py_prism, &axis, "axis")) {

return 0;
Expand All @@ -788,7 +789,12 @@ static int pyprism_to_prism(PyObject *py_prism, geometric_object *p) {
vertices[i] = v3;
}

#if defined(LIBCTL_MAJOR_VERSION) && (LIBCTL_MAJOR_VERSION > 4 || (LIBCTL_MAJOR_VERSION == 4 && LIBCTL_MINOR_VERSION >= 5))
*p = make_slanted_prism(material, vertices, num_vertices, height, axis, sidewall_angle);
#else
if (sidewall_angle != 0) { meep::abort("slanted prisms require libctl 4.5 or later\n"); }
*p = make_prism(material, vertices, num_vertices, height, axis);
#endif
p->center = center;

delete[] vertices;
Expand Down

0 comments on commit 71afd27

Please sign in to comment.