From c114308212057ac390b180252158804e032c2cad Mon Sep 17 00:00:00 2001 From: Homer Reid Date: Sat, 20 Apr 2019 00:00:27 +0200 Subject: [PATCH] GDSII layers (#817) * updates * add configure check for libGDSII::GetLayers * better error message --- configure.ac | 10 +++++++++- doc/docs/Python_User_Interface.md | 10 ++++++++++ python/meep.i | 1 + python/simulation.py | 2 ++ src/GDSIIgeom.cpp | 11 +++++++++++ src/meepgeom.hpp | 1 + 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1be3e255a..291e9594a 100644 --- a/configure.ac +++ b/configure.ac @@ -432,8 +432,16 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [ctl_printf_callbac ############################################################################## # check for libGDSII AC_CHECK_HEADER(libGDSII.h, [have_gdsii=maybe], [have_gdsii=no]) -if test $have_gdsii = maybe; then +if test "x$have_gdsii" = xmaybe; then AC_CHECK_LIB(GDSII, libGDSIIExists) + if test "x$ac_cv_lib_GDSII_libGDSIIExists" = xyes; then + AC_MSG_CHECKING([for libGDSII::GetLayers]) + have_gdsii_getlayers=no + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [libGDSII::GetLayers("foo")])], + [have_gdsii_getlayers=yes + AC_DEFINE([HAVE_GDSII_GETLAYERS], [1], [If we have libGDSII::GetLayers])]) + AC_MSG_RESULT($have_gdsii_getlayers) + fi fi ############################################################################## diff --git a/doc/docs/Python_User_Interface.md b/doc/docs/Python_User_Interface.md index 9289d9ca0..3042eb928 100644 --- a/doc/docs/Python_User_Interface.md +++ b/doc/docs/Python_User_Interface.md @@ -1489,6 +1489,16 @@ After `solve_cw` completes, it should be as if you had just run the simulation f This feature is only available if Meep is built with [libGDSII](Build_From_Source.md#libgdsii). +**`mp.GDSII_layers(gdsii_filename)`** + +Returns a list of integer-valued layer indices for the layers present in +the specified GDSII file. + +```python +mp.GDSII_layers('python/examples/coupler.gds') +Out[2]: [0, 1, 2, 3, 4, 5, 31, 32] +``` + **`mp.get_GDSII_prisms(material, gdsii_filename, layer)`** — Returns a list of `GeometricObject`s with `material` (`mp.Medium`) on layer number `layer` of a GDSII file `gdsii_filename`. diff --git a/python/meep.i b/python/meep.i index 024fd0fdf..d8334eb99 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1429,6 +1429,7 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where dft_ldos, display_progress, during_sources, + GDSII_layers, GDSII_vol, get_center_and_size, get_eigenmode_freqs, diff --git a/python/simulation.py b/python/simulation.py index a35f6812b..3004dcc31 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -2762,6 +2762,8 @@ def get_center_and_size(v): size = v3rmax - v3rmin return center, size +def GDSII_layers(fname): + return list(mp.get_GDSII_layers(fname)) def GDSII_vol(fname, layer, zmin, zmax): meep_vol = mp.get_GDSII_volume(fname, layer, zmin, zmax) diff --git a/src/GDSIIgeom.cpp b/src/GDSIIgeom.cpp index c05d54fca..5d4c91545 100644 --- a/src/GDSIIgeom.cpp +++ b/src/GDSIIgeom.cpp @@ -292,4 +292,15 @@ meep::volume get_GDSII_volume(const char *GDSIIFile, int Layer, double zmin, dou #endif // HAVE_LIBGDSII +std::vector get_GDSII_layers(const char *GDSIIFile) +{ +#if defined(HAVE_LIBGDSII) && defined(HAVE_GDSII_GETLAYERS) + return libGDSII::GetLayers(GDSIIFile); +#else + GDSIIError("get_GDSII_layers (needs libGDSII version 0.21 or later)"); + std::vector layers; + return layers; +#endif +} + } // namespace meep_geom diff --git a/src/meepgeom.hpp b/src/meepgeom.hpp index 449f8dd49..f4d994242 100644 --- a/src/meepgeom.hpp +++ b/src/meepgeom.hpp @@ -206,6 +206,7 @@ meep::volume get_GDSII_volume(const char *GDSIIFile, const char *Text, int Layer double zmin = 0.0, double zmax = 0.0); meep::volume get_GDSII_volume(const char *GDSIIFile, int Layer, double zmin = 0.0, double zmax = 0.0); +std::vector get_GDSII_layers(const char *GDSIIFile); }; // namespace meep_geom