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

Python interface for slanted prisms #1129

Merged
merged 1 commit into from
Feb 19, 2020
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
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