Skip to content

add support for prisms (new type of geometric_object) to libctlgeom#13

Merged
stevengj merged 13 commits intoNanoComp:masterfrom
HomerReid:prisms
May 17, 2018
Merged

add support for prisms (new type of geometric_object) to libctlgeom#13
stevengj merged 13 commits intoNanoComp:masterfrom
HomerReid:prisms

Conversation

@HomerReid
Copy link

Added a new implementation of geometric_object for user-defined prisms, i.e. arbitrary planar polygons (given by user-defined list of vertices) extruded a user-defined thickness in a user-defined direction.
Example in utils/test-prism.c.

Sample code:

  vector3 v[4];
  v[0].x=-0.25; v[0].y=-0.5; v[0].z=-0.75;
  v[1].x=+0.25; v[1].y=-0.5; v[1].z=-0.75;
  v[2].x=+0.25; v[2].y=+0.5; v[2].z=-0.75;
  v[3].x=-0.25; v[3].y=+0.5; v[3].z=-0.75;
  geometric_object the_prism=make_prism(m, v, 4, 1.5, zhat);
  draw_prism(the_prism,"the_prism.out");                   

utils/prism.c Outdated
/***************************************************************/
/***************************************************************/
GEOMETRIC_OBJECT make_prism(MATERIAL_TYPE material,
vector3 *vertices, int num_vertices,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a const vector3 * since a copy is made of this vertex data.

utils/prism.c Outdated
/* if **sarray is non-null, on return it points to a newly */
/* allocated array of length equal to the return value. */
/***************************************************************/
int intersect_line_with_prism(prism *prsm, vector3 p, vector3 d, double **sarray)
Copy link
Collaborator

@stevengj stevengj Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an inner-loop function for subpixel integration, so it shouldn't do any allocations via realloc or whatever.

Remember that subpixel averaging only needs to work in the limit where the pixels are very small compared to the object. So we shouldn't ever need to compute all of the intersections — maybe just the first and last intersection, should suffice, or knowing that it doesn't intersect at all.

@stevengj
Copy link
Collaborator

stevengj commented Mar 22, 2018

Change the intersect_line_with_object function to:

/* Compute the intersections with o of a line along p+s*d in the interval s in [a,b], returning
    the length of the s intersection in this interval.  (Note: o must not be a compound object.) */
double intersect_line_segment_with_object(vector3 p, vector3 d, geometric_object o, double a, double b)

To be more precise, define the function χ(s) = 1 if the point p+s*d is in the object, and χ(s) = 0 if the point p+s*d is not in the object. What we want is ∫ₐᵇ χ(s) ds.

@stevengj
Copy link
Collaborator

stevengj commented Mar 22, 2018

For the previously existing objects, intersect_line_segment_with_object is defined by

double s[2];
if (2 == intersect_line_with_object(p, d, o, s)) {
	  double ds = (s[0] < s[1]
		       ? MIN(s[1],b) - MAX(s[0],a)
		       : MIN(s[0],b) - MAX(s[1],a));
	  return (ds > 0 ? ds : 0.0);
}
else 
     return 0.0;

@stevengj
Copy link
Collaborator

stevengj commented Mar 22, 2018

overlap_integrand will now call:

return intersect_line_segment_with_object(p, data->dir, data->o, a0, b0) * scale_result;

instead of intersect_line_with_object

@stevengj
Copy link
Collaborator

cc @DerekK88, who has been playing with GDSII import for Meep.

@stevengj
Copy link
Collaborator

stevengj commented May 17, 2018

  1. for technical reasons having to do with how Scheme code is compiled to use libctl, all the code needs to be in geom.c, so just paste prism.c at the end of this separated by /****************************************/ lines.

  2. at the top of geom.c, add # define PRISM prism:: after the corresponding line for CYL in #ifdef CXX_CTL_IO, and add # define PRISM in the #else clause.

@stevengj
Copy link
Collaborator

Only make_prism should be exported — the other functions (except for make_prism) should be declared as static and removed from ctlgeom.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants