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

Replace #646 get_source_slice parsing with components #652

Merged
merged 17 commits into from
Jan 7, 2019
Merged
21 changes: 21 additions & 0 deletions doc/docs/Python_User_Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@ The most common step function is an output function, which outputs some field co

Note that although the various field components are stored at different places in the [Yee lattice](Yee_Lattice.md), when they are outputted they are all linearly interpolated to the same grid: to the points at the *centers* of the Yee cells, i.e. $(i+0.5,j+0.5,k+0.5)\cdotΔ$ in 3d.

<a name="output_epsilon"></a>
**`output_epsilon()`**
Output the dielectric function (relative permittivity) ε. Note that this only outputs the frequency-independent part of ε (the $\omega\to\infty$ limit).
Expand Down Expand Up @@ -1462,6 +1463,26 @@ Returns the Fourier-transformed fields as a NumPy array.

+ `num_freq`: The index of the frequency: (an integer in the range `0...nfreq-1`, where `nfreq` is the number of frequencies stored in `dft_obj,` as set by the `nfreq` parameter to `add_dft_fields`, `add_dft_flux`, etc.)

#### Source slices

**`get_source_slice(component, vol=None, center=None, size=None)`**

This routine returns an array of the same dimensions as that
returned by `get_array` for the given `vol` or `center/size`,
but containing information on the [*sources*](#source) at grid points,
not the fields there.
(Because sources, unlike fields, are *inputs* rather
than outputs of meep calculations, this routine
is not a means of extracting results from meep calculations,
but is rather a tool to sanity-check visualization
and confirm that the source distribution you specified is the one you
wanted; philosophically it is closer in
spirit to [`output_epsilon()`](#output_epsilon) than to
`get_array/get_dft_array`.

The array returned by `get_source_slice` is always complex,
and corresponds to the given `component`.

#### Harminv

The following step function collects field data from a given point and runs [Harminv](https://github.com/stevengj/harminv) on that data to extract the frequencies, decay rates, and other information.
Expand Down
4 changes: 1 addition & 3 deletions libpympb/pympb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2376,9 +2376,7 @@ double mode_solver::compute_energy_in_objects(geometric_object_list objects) {
return 0.0;
}

for (int i = 0; i < objects.num_items; ++i) {
geom_fix_object(objects.items[i]);
}
geom_fix_objects0(objects);

int n1 = mdata->nx;
int n2 = mdata->ny;
Expand Down
1 change: 1 addition & 0 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ using namespace meep_geom;
extern boolean point_in_objectp(vector3 p, GEOMETRIC_OBJECT o);
extern boolean point_in_periodic_objectp(vector3 p, GEOMETRIC_OBJECT o);
void display_geometric_object_info(int indentby, GEOMETRIC_OBJECT o);

%}

%include "numpy.i"
Expand Down
16 changes: 14 additions & 2 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,11 +1233,11 @@ def add_source(self, src):
if not fname.endswith('.h5'):
fname += '.h5'

add_vol_src(fname, dset, src.amplitude * 1.0,)
add_vol_src(fname, dset, src.amplitude * 1.0)
elif src.amp_func:
add_vol_src(src.amp_func, src.amplitude * 1.0)
elif src.amp_data is not None:
add_vol_src(src.amp_data, src.amplitude * 1.0,)
add_vol_src(src.amp_data, src.amplitude * 1.0)
else:
add_vol_src(src.amplitude * 1.0)

Expand Down Expand Up @@ -1594,6 +1594,18 @@ def get_dft_array(self, dft_obj, component, num_freq):
else:
raise ValueError("Invalid type of dft object: {}".format(dft_swigobj))

def get_source_slice(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)
self.fields.get_array_slice_dimensions(v, dim_sizes)
dims = [s for s in dim_sizes if s != 0]
arr = np.zeros(dims, dtype=np.complex128)
self.fields.get_source_slice(v, component ,arr)
return arr

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, verbose=False):
if self.fields is None:
Expand Down
1 change: 0 additions & 1 deletion python/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def check_positive(prop, val):
else:
raise ValueError("{} must be positive. Got {}".format(prop, val))


class Source(object):

def __init__(self, src, component, center, size=Vector3(), amplitude=1.0, amp_func=None,
Expand Down
5 changes: 5 additions & 0 deletions python/tests/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ def print_field(sim):

self.assertAlmostEqual(result[0], -0.0599602798684155)

def test_source_slice(self):
sim = self.init_simple_simulation()
sim.run(until=5)
slice = sim.get_source_slice(mp.Ez)
print(slice)

if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions python/vec.i
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
%rename(vec_abs) meep::abs;
%rename(vec_max) meep::max;
%rename(vec_min) meep::min;
%rename(vec_str) meep::vec::str;
%rename(ivec_str) meep::ivec::str;
%rename(print_grid_volume) meep::grid_volume::print;
%rename(symmetry_reduce) meep::symmetry::reduce;

Expand Down
Loading