Skip to content

Commit 122aa2a

Browse files
committed
GDSII import for Scheme
1 parent ed7d8d3 commit 122aa2a

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

scheme/meep-ctl-swig.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ ctlio::cnumber_list make_casimir_g(double T, double dt, double sigma, meep::fiel
5555

5656
ctlio::cnumber_list make_casimir_g_kz(double T, double dt, double sigma, meep::field_type ft);
5757

58+
ctlio::integer_list GDSII_layers(const char *fname);
59+
meep::volume GDSII_vol(const char *fname, int layer = -1, double zmin = 0, double zmax = 0);
60+
ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer = -1, double zmin = 0.0, double zmax = 0.0);
61+
5862
// wrapper around constructor to fool SWIG
5963
meep::volume_list *make_volume_list(const meep::volume &v, int c, std::complex<double> weight,
6064
meep::volume_list *next);

scheme/meep.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#include "meep-ctl.hpp"
22

3+
/* hack to tell meepgeom.hpp, which includes ctlgeom.h,
4+
to use the ctlgeom.h object definitions and not the
5+
ctl-io.h definitions */
6+
#undef CXX_CTL_IO
7+
#undef CTL_IO_H
8+
#include "meepgeom.hpp"
9+
310
using namespace meep;
411
using namespace std;
512

@@ -198,3 +205,36 @@ ctlio::number_list std_vector_double_to_scm(std::vector<double> *v) {
198205
res.items[i] = (*v)[i];
199206
return res;
200207
}
208+
/***************************************************************************/
209+
210+
ctlio::integer_list GDSII_layers(const char *fname) {
211+
std::vector<int> layers = meep_geom::get_GDSII_layers(fname);
212+
ctlio::integer_list res;
213+
res.num_items = int(layers.size());
214+
res.items = new integer[res.num_items];
215+
for (int i = 0; i < res.num_items; ++i) {
216+
res.items[i] = layers[i];
217+
}
218+
return res;
219+
}
220+
221+
volume GDSII_vol(const char *fname, int layer, double zmin, double zmax) {
222+
return meep_geom::get_GDSII_volume(fname, layer, zmin, zmax);
223+
}
224+
225+
ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer, double zmin, double zmax) {
226+
geometric_object_list go = meep_geom::get_GDSII_prisms(NULL, GDSIIFile, Layer, zmin, zmax);
227+
ctlio::simple_prism_list res;
228+
res.num_items = go.num_items;
229+
res.items = new ctlio::simple_prism[res.num_items];
230+
for (int i = 0; i < res.num_items; ++i) {
231+
prism *p = go.items[i].subclass.prism_data;
232+
res.items[i].vertices.num_items = p->vertices.num_items;
233+
res.items[i].vertices.items = p->vertices.items;
234+
res.items[i].height = p->height;
235+
res.items[i].axis = p->axis;
236+
free(p);
237+
}
238+
delete[] go.items;
239+
return res;
240+
}

scheme/meep.scm.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,18 @@
11051105
(define (output-png c options) (output-png-rm? true c options))
11061106
(define (output-png+h5 c options) (output-png-rm? false c options))
11071107

1108+
; ****************************************************************
1109+
; GDSII import functions
1110+
1111+
(export-type (make-list-type 'integer))
1112+
1113+
(define-class simple-prism no-parent
1114+
(define-property vertices no-default (make-list-type 'vector3))
1115+
(define-property height no-default 'number)
1116+
(define-property axis no-default 'vector3))
1117+
(export-type (make-list-type 'simple-prism))
1118+
1119+
11081120
; ****************************************************************
11091121
; harminv functions for extracting bands, etcetera
11101122

0 commit comments

Comments
 (0)