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

fixes for new material_type in libctlgeom 4 #120

Merged
merged 2 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ AC_SUBST(CTL_H_CPPFLAG)
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $CTL_H_CPPFLAG"
# Check libctl version >= LIBCTL_MAJOR.LIBCTL_MINOR.LIBCTL_BUGFIX
LIBCTL_MAJOR=3; LIBCTL_MINOR=2; LIBCTL_BUGFIX=0
LIBCTL_MAJOR=4; LIBCTL_MINOR=0; LIBCTL_BUGFIX=0
AC_MSG_CHECKING([whether libctl version is at least ${LIBCTL_MAJOR}.${LIBCTL_MINOR}.${LIBCTL_BUGFIX}])
AC_EGREP_CPP(yes, [[
#include <ctl.h>
Expand Down
14 changes: 7 additions & 7 deletions libmeepgeom/array-slice-ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main(int argc, char *argv[])
else
{ master_printf("unknown command-line option %s (aborting)",argv[narg]);
usage(argv[0]);
};
};
};

/***************************************************************/
Expand All @@ -142,8 +142,8 @@ int main(int argc, char *argv[])
gv.center_origin();
symmetry sym = use_symmetry ? -mirror(Y,gv) : identity();
structure the_structure(gv, dummy_eps, pml(dpml), sym);
material_type vacuum = meep_geom::vacuum;
material_type dielectric = meep_geom::make_dielectric(eps);
meep_geom::material_type vacuum = meep_geom::vacuum;
meep_geom::material_type dielectric = meep_geom::make_dielectric(eps);
geometric_object objects[7];
vector3 origin = v3(0.0, 0.0, 0.0);
vector3 xhat = v3(1.0, 0.0, 0.0);
Expand Down Expand Up @@ -194,7 +194,7 @@ int main(int argc, char *argv[])
#define NX 126
#define NY 38
if (write_files)
{
{
h5file *file = f.open_h5file(H5FILENAME);
f.output_hdf5(Hz, v1d, file);
f.output_hdf5(Sy, v2d, file);
Expand All @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
exit(0);
}
else
{
{
//
// read 1D and 2D array-slice data from HDF5 file
//
Expand All @@ -219,14 +219,14 @@ int main(int argc, char *argv[])
file_slice1d[n] = cdouble(rdata[n], idata[n]);
delete[] rdata;
delete[] idata;

file_slice2d = file->read("sy", &rank, dims2D, 2);
if (rank!=2 || dims2D[0]!=NX || dims2D[1]!=NY)
abort("failed to read 2D reference data from file %s.h5",H5FILENAME);
delete file;

//
// generate 1D and 2D array slices and compare to
// generate 1D and 2D array slices and compare to
// data read from file
//
rank=f.get_array_slice_dimensions(v1d, dims1D);
Expand Down
26 changes: 13 additions & 13 deletions libmeepgeom/bend-flux-ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ void bend_flux(bool no_bend)
// (if no-bend?
// (list
// (list
// (make block
// (make block
// (center wvg-xcen (* 0.5 pad))
// (size w (- sy pad) infinity)
// (material (make dielectric (epsilon 12)))))))
// (make block
// (make block
// (center 0 wvg-ycen)
// (size infinity w infinity)
// (material (make dielectric (epsilon 12)))))
// (make block
// (make block
// (center (* -0.5 pad) wvg-ycen)
// (size (- sx pad) w infinity)
// (material (make dielectric (epsilon 12))))
vector3 e1=v3(1.0, 0.0, 0.0);
vector3 e2=v3(0.0, 1.0, 0.0);
vector3 e3=v3(0.0, 0.0, 1.0);

material_type dielectric = meep_geom::make_dielectric(12.0);
meep_geom::material_type dielectric = meep_geom::make_dielectric(12.0);
if (no_bend)
{
geometric_object objects[1];
Expand All @@ -101,21 +101,21 @@ void bend_flux(bool no_bend)
e1, e2, e3,
v3(sx-pad, w, ENORMOUS)
);

objects[1] = make_block(dielectric,
v3(wvg_xcen, 0.5*pad),
e1, e2, e3,
v3(w, sy-pad, ENORMOUS)
);

geometric_object_list g={ 2, objects };
meep_geom::set_materials_from_geometry(&the_structure, g);
};

fields f(&the_structure);

// (set! sources (list
// (make source
// (make source
// (src (make gaussian-src (frequency fcen) (fwidth df)))
// (component Ez)
// (center (+ 1 (* -0.5 sx)) wvg-ycen)
Expand All @@ -137,16 +137,16 @@ void bend_flux(bool no_bend)
double f_start = fcen-0.5*df;
double f_end = fcen+0.5*df;
int nfreq = 100; // number of frequencies at which to compute flux

volume *trans_volume=
no_bend ? new volume(vec(0.5*sx-1.5, wvg_ycen), vec(0.0, 2.0*w))
: new volume(vec(wvg_xcen, 0.5*sy-1.5), vec(2.0*w, 0.0));
volume_list trans_vl = volume_list(*trans_volume, Sz);
dft_flux trans=f.add_dft_flux(&trans_vl, f_start, f_end, nfreq);

//(define refl ; reflected flux
// (add-flux fcen df nfreq
// (make flux-region
// (make flux-region
// (center (+ (* -0.5 sx) 1.5) wvg-ycen) (size 0 (* w 2)))))
//
volume refl_volume( vec(-0.5*sx+1.5, wvg_ycen), vec(0.0,2.0*w));
Expand All @@ -161,7 +161,7 @@ void bend_flux(bool no_bend)
refl.scale_dfts(-1.0);
};

//(run-sources+
//(run-sources+
// (stop-when-fields-decayed 50 Ez
// (if no-bend?
// (vector3 (- (/ sx 2) 1.5) wvg-ycen)
Expand All @@ -177,7 +177,7 @@ void bend_flux(bool no_bend)
double max_abs=0.0, cur_max=0.0;
bool Done=false;
do
{
{
f.step();

// manually check fields-decayed condition
Expand All @@ -197,7 +197,7 @@ void bend_flux(bool no_bend)
//(if no-bend? (save-flux "refl-flux" refl))
if (no_bend)
refl.save_hdf5(f, dataname);

//(display-fluxes trans refl)
printf("%11s | %12s | %12s\n", " Time ", " trans flux", " refl flux");
double f0=fcen-0.5*df, fstep=df/(nfreq-1);
Expand Down
26 changes: 13 additions & 13 deletions libmeepgeom/cyl-ellipsoid-ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool compare_hdf5_datasets(const char *file1, const char *name1,
double rel_tol=1.0e-4, double abs_tol=1.0e-8)
{
h5file f1(file1, h5file::READONLY, false);
int rank1;
int rank1;
int *dims1=new int[expected_rank];
double *data1 = f1.read(name1, &rank1, dims1, expected_rank);
if (!data1) return false;
Expand Down Expand Up @@ -75,25 +75,25 @@ int main(int argc, char *argv[])
{
initialize mpi(argc, argv);

// simple argument parsing
// simple argument parsing
meep::component src_cmpt=Ez;
std::string eps_ref_file = "cyl-ellipsoid-eps-ref.h5";
for(int narg=1; narg<argc; narg++)
{
{
if ( argv[narg] && !strcmp(argv[narg],"--polarization") )
{ if (narg+1 == argc)
{ if (narg+1 == argc)
meep::abort("no option specified for --polarization");
else if (!strcasecmp(argv[narg+1],"S"))
master_printf("Using S-polarization\n");
else if (!strcasecmp(argv[narg+1],"P"))
{ src_cmpt=Hz;
master_printf("Using P-polarization\n");
}
else
else
meep::abort("invalid --polarization %s",argv[narg+1]);
}
else if (argv[narg] && !strcmp(argv[narg],"--eps_ref_file"))
{ if (narg+1 == argc)
{ if (narg+1 == argc)
meep::abort("no option specified for --eps_ref_file");
eps_ref_file=argv[++narg];
}
Expand All @@ -105,14 +105,14 @@ int main(int argc, char *argv[])


//(set-param! resolution 100)
double resolution = 100.0;
double resolution = 100.0;

// (set! geometry-lattice (make lattice (size 10 10 no-size)))
// (set! pml-layers (list (make pml (thickness 1))))
// (if (= src-cmpt Ez)
// (set! symmetries (list (make mirror-sym (direction X))
// (make mirror-sym (direction Y)))))
// (if (= src-cmpt Hz)
// (if (= src-cmpt Hz)
// (set! symmetries (list (make mirror-sym (direction X) (phase -1))
// (set! symmetries (list (make mirror-sym (direction Y) (phase -1))
geometry_lattice.size.x=10.0;
Expand All @@ -124,13 +124,13 @@ int main(int argc, char *argv[])
: -mirror(X,gv) - mirror(Y,gv);
structure the_structure(gv, dummy_eps, pml(1.0), sym);

// (set! geometry (list
// (set! geometry (list
// (make cylinder (center 0 0 0) (radius 3) (height infinity)
// (material (make medium (index 3.5))))
// (make ellipsoid (center 0 0 0) (size 1 2 infinity)
// (material air))))
double n=3.5; // index of refraction
material_type dielectric = meep_geom::make_dielectric(n*n);
meep_geom::material_type dielectric = meep_geom::make_dielectric(n*n);
geometric_object objects[2];
vector3 center = {0.0, 0.0, 0.0};
double radius = 3.0;
Expand All @@ -157,7 +157,7 @@ int main(int argc, char *argv[])
// first test: write permittivity to HDF5 file and
// compare with contents of reference file
if ( am_really_master() )
{
{
f.output_hdf5(Dielectric, f.total_volume());
bool status=compare_hdf5_datasets("eps-000000000.h5", "eps",
eps_ref_path.c_str(), "eps");
Expand All @@ -177,11 +177,11 @@ int main(int argc, char *argv[])
double stop_time = start_time + duration;
while( f.round_time() < stop_time)
f.step();

// second test: compare field component at specified evaluation
// point to reference values
if ( am_really_master() )
{
{
// ref values obtained by running `meep cyl-ellipsoid.ctl`
#define REF_EZ -8.29555720049629e-5
#define REF_HZ -4.5623185899766e-5
Expand Down
19 changes: 12 additions & 7 deletions libmeepgeom/material_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

namespace meep_geom {

/* FIXME: we don't have to emulate the Scheme/libctl code here, which was
limited to C functionality. These types, especially the material types,
should be proper C++ classes */

typedef struct susceptibility_struct {
vector3 sigma_offdiag;
vector3 sigma_diag;
Expand All @@ -52,7 +56,7 @@ typedef struct {
// TODO: this prototype only allows user-defined scalar dielectric permeabilities
// (which seems to be all that is possible via the libctl interface as well).
// extend to allow more complicated user-specified materials?
//
//
typedef std::complex<double> (*user_material_func)(vector3 x, void *user_data);

typedef struct medium_struct {
Expand All @@ -70,11 +74,6 @@ typedef struct medium_struct {
vector3 B_conductivity_diag;
} medium_struct;

typedef struct material_type_list
{ material_type *items;
int num_items;
} material_type_list;

typedef struct material_data_struct
{
enum { MATERIAL_TYPE_SELF, MATERIAL_FUNCTION, PERFECT_METAL, MEDIUM } which_subclass;
Expand All @@ -85,9 +84,15 @@ typedef struct material_data_struct

// used only if which_subclass==MEDIUM
medium_struct *medium;

} material_data;

typedef material_data *material_type;
typedef struct material_type_list
{ material_type *items;
int num_items;
} material_type_list;

// global variables and exported functions
extern material_type vacuum;
material_type make_dielectric(double epsilon);
Expand Down
Loading