Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meep geom #56

Merged
merged 11 commits into from
Jun 17, 2017
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif

ACLOCAL_AMFLAGS=-I m4

SUBDIRS = src $(LIBCTL) tests examples libmeep_geom
SUBDIRS = src $(LIBCTL) tests examples libmeepgeom

if WITH_PYTHON
SUBDIRS += python
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ AC_CONFIG_FILES([
examples/Makefile
libctl/Makefile
libctl/meep.scm
libmeep_geom/Makefile
libmeepgeom/Makefile
python/Makefile
])

Expand Down
26 changes: 0 additions & 26 deletions libmeep_geom/Makefile.am

This file was deleted.

27 changes: 27 additions & 0 deletions libmeepgeom/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
LIBCTLGEOM = -lctlgeom
LIBMEEP = $(top_builddir)/src/libmeep.la
MEEPLIBS = $(LIBCTLGEOM) $(LIBMEEP)

lib_LTLIBRARIES = libmeepgeom.la
pkginclude_HEADERS = meepgeom.hpp material_data.hpp

#AM_CPPFLAGS = -I$(top_srcdir)/src -std=c++11
AM_CPPFLAGS = -I$(top_srcdir)/src

libmeepgeom_la_SOURCES = \
meepgeom.cpp meepgeom.hpp material_data.hpp

libmeepgeom_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@

check_PROGRAMS = pw-source-ll bend-flux-ll ring-ll

pw_source_ll_SOURCES = pw-source-ll.cpp
pw_source_ll_LDADD = libmeepgeom.la $(MEEPLIBS)

bend_flux_ll_SOURCES = bend-flux-ll.cpp
bend_flux_ll_LDADD = libmeepgeom.la $(MEEPLIBS)

ring_ll_SOURCES = ring-ll.cpp
ring_ll_LDADD = libmeepgeom.la $(MEEPLIBS)

TESTS = pw-source-ll bend-flux-ll ring-ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "ctl-math.h"
#include "ctlgeom.h"

#include "meep_geom.hpp"
#include "meepgeom.hpp"

using namespace meep;

Expand Down
File renamed without changes.
71 changes: 44 additions & 27 deletions libmeep_geom/meep_geom.cpp → libmeepgeom/meepgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "meep_geom.hpp"
#include "meepgeom.hpp"

namespace meep_geom {

Expand All @@ -23,39 +23,55 @@ namespace meep_geom {
/***************************************************************/
/* global variables for default material */
/***************************************************************/
vector3 ones={1.0,1.0,1.0};
vector3 zeroes={0.0,0.0,0.0};

//susceptibility_list empty_sus_list{ .items=0, .num_items=0 };
susceptibility_list empty_sus_list{ 0, 0 };

medium_struct vacuum_medium{
.epsilon_diag = ones,
.epsilon_offdiag = zeroes,
.mu_diag = ones,
.mu_offdiag = zeroes,
.E_susceptibilities = empty_sus_list,
.H_susceptibilities = empty_sus_list,
.E_chi2_diag = zeroes,
.E_chi3_diag = zeroes,
.H_chi2_diag = zeroes,
.H_chi3_diag = zeroes,
.D_conductivity_diag = zeroes,
.B_conductivity_diag = zeroes
};

material_data vacuum_material_data{
material_data::MEDIUM, 0, 0, &vacuum_medium
};
material_type vacuum;
material_type air;
medium_struct vacuum_medium;
material_data vacuum_material_data;
bool materials_initialized = false;

void initialize_materials()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this need to be a function? Can't you just use a static initializer const material_type vacuum = {....}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is what was preventing the build from working on Travis. Previously I had all the initializations done the way you suggested, but these static structure initializations require the -std=c++11 compiler flag, which is not supported by the compiler versions used by Travis.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Static structure initializations can be done even in 1990 ANSI C. You just can't use named fields. i.e.

const medium_struct vacuum_medium = {{1,1,1},{0,0,0},{1,1,1},{0,0,0}};
const material_data vacuum_material = {MEDIUM,NULL,NULL,&vacuum_medium};
const material_type vacuum = {(void*) &vacuum_material};

(Note that the unspecified extra fields in vacuum_medium are initialized to 0, per the C/C++ standard.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, in the latest commit (a1117e6) I've eliminated the initialize_materials() function in favor of static structure initializers.

{
materials_initialized=true;

vector3 ones, zeroes;
ones.x = ones.y = ones.z = 1.0;
zeroes.x = zeroes.y = zeroes.z = 0.0;

vacuum_medium.epsilon_diag
= vacuum_medium.mu_diag
= ones;

vacuum_medium.epsilon_offdiag
= vacuum_medium.mu_offdiag
= vacuum_medium.E_chi2_diag
= vacuum_medium.E_chi3_diag
= vacuum_medium.H_chi2_diag
= vacuum_medium.H_chi3_diag
= vacuum_medium.D_conductivity_diag
= vacuum_medium.B_conductivity_diag
= zeroes;

vacuum_medium.E_susceptibilities.num_items=0;
vacuum_medium.E_susceptibilities.items=0;
vacuum_medium.H_susceptibilities.num_items=0;
vacuum_medium.H_susceptibilities.items=0;

vacuum_material_data.which_subclass = material_data::MEDIUM;
vacuum_material_data.user_func=0;
vacuum_material_data.user_data=0;
vacuum_material_data.medium = &vacuum_medium;

material_type vacuum { (void *)&vacuum_material_data };
material_type air = vacuum;
vacuum.data=(void *)&vacuum_material_data;
air = vacuum;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't bother with the the air synonym in the C++ interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I removed it.

}

/***************************************************************/
/***************************************************************/
/***************************************************************/
material_type make_dielectric(double epsilon)
{
if (!materials_initialized) initialize_materials();

material_data *md = (material_data *)malloc(sizeof(*md));
md->which_subclass=material_data::MEDIUM;
md->user_func=0;
Expand Down Expand Up @@ -1490,6 +1506,7 @@ void set_materials_from_geometry(meep::structure *s,
bool verbose)
{
geom_epsilon::verbose=verbose;
if (!materials_initialized) initialize_materials();

// set global variables in libctlgeom based on data fields in s
default_material = vacuum;
Expand Down
4 changes: 3 additions & 1 deletion libmeep_geom/meep_geom.hpp → libmeepgeom/meepgeom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ namespace meep_geom {
/***************************************************************/
/***************************************************************/
void set_materials_from_geometry(meep::structure *s,
geometric_object_list g,
geometric_object_list g,
bool use_anisotropic_averaging=true,
double tol=DEFAULT_SUBPIXEL_TOL,
int maxeval=DEFAULT_SUBPIXEL_MAXEVAL,
bool ensure_periodicity=false,
bool verbose=false);

material_type make_dielectric(double epsilon);

vector3 vec_to_vector3(const meep::vec &pt);
meep::vec vector3_to_vec(const vector3 v3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "ctl-math.h"
#include "ctlgeom.h"

#include "meep_geom.hpp"
#include "meepgeom.hpp"

using namespace meep;

Expand Down
2 changes: 1 addition & 1 deletion libmeep_geom/ring-ll.cpp → libmeepgeom/ring-ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "ctl-math.h"
#include "ctlgeom.h"

#include "meep_geom.hpp"
#include "meepgeom.hpp"

using namespace meep;

Expand Down