Skip to content

Commit

Permalink
add yee grid to array slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Hammond committed Jul 2, 2020
1 parent 82fbfb0 commit d3e805e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ kpoint_list get_eigenmode_coefficients_and_kpoints(meep::fields *f, meep::dft_fl
}

PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where, size_t dims[3],
bool collapse_empty_dimensions, bool snap_empty_dimensions) {
bool collapse_empty_dimensions, bool snap_empty_dimensions, meep::component cgrid = Centered) {
meep::direction dirs[3] = {meep::X, meep::X, meep::X};
int rank = f->get_array_slice_dimensions(where, dims, dirs, collapse_empty_dimensions, snap_empty_dimensions);
int rank = f->get_array_slice_dimensions(where, dims, dirs, collapse_empty_dimensions, snap_empty_dimensions, NULL, 0, cgrid);

PyObject *py_dirs = PyList_New(3);
for (Py_ssize_t i = 0; i < 3; ++i) {
Expand Down Expand Up @@ -1368,7 +1368,7 @@ kpoint_list get_eigenmode_coefficients_and_kpoints(meep::fields *f, meep::dft_fl
meep::kpoint_func user_kpoint_func, void *user_kpoint_data,
double *cscale, meep::direction d);
PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where, size_t dims[3],
bool collapse_empty_dimensions, bool snap_empty_dimensions);
bool collapse_empty_dimensions, bool snap_empty_dimensions, meep::component cgrid = Centered);

%ignore eps_func;
%ignore inveps_func;
Expand Down
12 changes: 11 additions & 1 deletion python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,17 @@ def get_dft_array_metadata(self, dft_cell=None, vol=None, center=None, size=None
DeprecationWarning)
return self.get_array_metadata(vol=dft_cell.where if dft_cell is not None else vol,
center=center, size=size, collapse=True)


def get_array_slice_dimensions(self, component, vol=None, center=None, size=None):
if vol is None and center is None and size is None:
v = self.fields.total_volume()
else:
v = self._volume_from_kwargs(vol, center, size)
dim_sizes = np.zeros(3, dtype=np.uintp)
_,_ = mp._get_array_slice_dimensions(self.fields, v, dim_sizes, False, True, component)
dims = [s for s in dim_sizes if s != 0]
return dims

def get_eigenmode_coefficients(self, flux, bands, eig_parity=mp.NO_PARITY, eig_vol=None,
eig_resolution=0, eig_tolerance=1e-12, kpoint_func=None, direction=mp.AUTOMATIC):
if self.fields is None:
Expand Down
4 changes: 2 additions & 2 deletions src/array_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ cdouble *array_to_all(cdouble *array, size_t array_size) {
/***************************************************************/
int fields::get_array_slice_dimensions(const volume &where, size_t dims[3], direction dirs[3],
bool collapse_empty_dimensions, bool snap_empty_dimensions,
vec *min_max_loc, void *caller_data) {
vec *min_max_loc, void *caller_data, component cgrid) {
am_now_working_on(FieldOutput);

// use a local data structure if the caller didn't provide one
Expand All @@ -434,7 +434,7 @@ int fields::get_array_slice_dimensions(const volume &where, size_t dims[3], dire
}

bool use_symmetry = true;
loop_in_chunks(get_array_slice_dimensions_chunkloop, (void *)data, where, Centered, use_symmetry,
loop_in_chunks(get_array_slice_dimensions_chunkloop, (void *)data, where, cgrid, use_symmetry,
snap_empty_dimensions);

data->min_corner = -max_to_all(-data->min_corner); // i.e., min_to_all
Expand Down
2 changes: 1 addition & 1 deletion src/meep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ class fields {
int get_array_slice_dimensions(const volume &where, size_t dims[3], direction dirs[3],
bool collapse_empty_dimensions = false,
bool snap_empty_dimensions = false, vec *min_max_loc = NULL,
void *data = 0);
void *data = 0, component cgrid = Centered);

int get_dft_array_dimensions(const volume &where, size_t dims[3], direction dirs[3]) {
return get_array_slice_dimensions(where, dims, dirs, true);
Expand Down

0 comments on commit d3e805e

Please sign in to comment.