Skip to content

Commit

Permalink
get_GDSII_prism_data wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Apr 9, 2020
1 parent 587495e commit 457f2c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion scheme/meep-ctl-swig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ctlio::cnumber_list make_casimir_g_kz(double T, double dt, double sigma, meep::f

ctlio::integer_list GDSII_layers(const char *fname);
meep::volume GDSII_vol(const char *fname, int layer = -1, double zmin = 0, double zmax = 0);
ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer = -1, double zmin = 0.0, double zmax = 0.0);
SCM get_GDSII_prism_data(const char *GDSIIFile, int Layer = -1, double zmin = 0.0, double zmax = 0.0);

// wrapper around constructor to fool SWIG
meep::volume_list *make_volume_list(const meep::volume &v, int c, std::complex<double> weight,
Expand Down
25 changes: 15 additions & 10 deletions scheme/meep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,24 @@ volume GDSII_vol(const char *fname, int layer, double zmin, double zmax) {
return meep_geom::get_GDSII_volume(fname, layer, zmin, zmax);
}

ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer, double zmin, double zmax) {
/* We have to jump through some hoops here because the geometric_object data type used
in meepgeom (from libctlgeom) is different from the generated ctlio::geometric_object.
So we take the list of prisms from meep_geom::get_GDSII_prisms and return a simple
Scheme list of triples (vertices height axis). meep.scm then defines a higher-level
function get-GDSII-prisms that constructs the actual prism objects again */
SCM get_GDSII_prism_data(const char *GDSIIFile, int Layer, double zmin, double zmax) {
geometric_object_list go = meep_geom::get_GDSII_prisms(NULL, GDSIIFile, Layer, zmin, zmax);
ctlio::simple_prism_list res;
res.num_items = go.num_items;
res.items = new ctlio::simple_prism[res.num_items];
for (int i = 0; i < res.num_items; ++i) {
SCM res = SCM_EOL;
for (int i = go.num_items - 1; i >= 0; --i) {
prism *p = go.items[i].subclass.prism_data;
res.items[i].vertices.num_items = p->vertices.num_items;
res.items[i].vertices.items = p->vertices.items;
res.items[i].height = p->height;
res.items[i].axis = p->axis;
res = scm_cons(scm_list_3(ctl_convert_list_to_scm(make_vector3_list(p->vertices.num_items, p->vertices.items)),
ctl_convert_number_to_scm(p->height),
ctl_convert_vector3_to_scm(p->axis)),
res);
free(p->vertices.items);
// fixme: free the rest of the prism data
free(p);
}
delete[] go.items;
return res;
}
}
10 changes: 4 additions & 6 deletions scheme/meep.scm.in
Original file line number Diff line number Diff line change
Expand Up @@ -1122,12 +1122,10 @@

(export-type (make-list-type 'integer))

(define-class simple-prism no-parent
(define-property vertices no-default (make-list-type 'vector3))
(define-property height no-default 'number)
(define-property axis no-default 'vector3))
(export-type (make-list-type 'simple-prism))

(define* (get-GDSII-prisms m GDSIIFile #:optional (layer -1) (zmin 0) (zmax 0))
(map (lambda (data)
(make prism (material m) (center auto-center) (vertices (car data)) (height (cadr data)) (axis (caddr data))))
(get-GDSII-prism-data GDSIIFile layer zmin zmax)))

; ****************************************************************
; harminv functions for extracting bands, etcetera
Expand Down

0 comments on commit 457f2c2

Please sign in to comment.