NanoComp / libctl

Guile-based library implementing flexible control files for scientific simulations
GNU General Public License v2.0
18 stars 22 forks source link

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

Closed HomerReid closed 6 years ago

HomerReid commented 6 years ago

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");                   
stevengj commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

stevengj commented 6 years ago
  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 commented 6 years ago

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