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

High level get_eigenmode_coefficients #248

Merged
merged 7 commits into from
Apr 15, 2018
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
16 changes: 6 additions & 10 deletions python/examples/mode-decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,16 @@ def main(args):
sources=sources,
symmetries=symmetries)

xm = -0.5*sx + dpml + 0.5*Lw; # x-coordinate of monitor
mflux = sim.add_flux(fcen, 0, 1, mp.FluxRegion(center=mp.Vector3(xm,0), size=mp.Vector3(0,sy-2*dpml)));
xm = -0.5*sx + dpml + 0.5*Lw # x-coordinate of monitor
mflux = sim.add_eigenmode(fcen, 0, 1, mp.FluxRegion(center=mp.Vector3(xm,0), size=mp.Vector3(0,sy-2*dpml)))

sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ez, mp.Vector3(xm,0), 1e-10))

bands = np.array([1],dtype=np.int32) # indices of modes for which to compute expansion coefficients
num_bands = 1;
alpha = np.zeros(2*num_bands,dtype=np.complex128) # preallocate array to store coefficients
vgrp = np.zeros(num_bands,dtype=np.float64) # also store mode group velocities
mvol = mp.volume(mp.vec(xm,-0.5*sy+dpml),mp.vec(xm,+0.5*sy-dpml))
sim.fields.get_eigenmode_coefficients(mflux, mp.X, mvol, bands, alpha, vgrp)
bands = [1] # indices of modes for which to compute expansion coefficients
alpha = sim.get_eigenmode_coefficients(mflux, bands)

alpha0Plus = alpha[2*0 + 0]; # coefficient of forward-traveling fundamental mode
alpha0Minus = alpha[2*0 + 1]; # coefficient of backward-traveling fundamental mode
alpha0Plus = alpha[2*0 + 0] # coefficient of forward-traveling fundamental mode
alpha0Minus = alpha[2*0 + 1] # coefficient of backward-traveling fundamental mode

print("refl:, {}, {:.8f}".format(Lt, abs(alpha0Minus)**2))

Expand Down
7 changes: 0 additions & 7 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,6 @@ meep::volume_list *make_volume_list(const meep::volume &v, int c,
$1 = (std::complex<double> *)array_data($input);
}

%typecheck(SWIG_TYPECHECK_POINTER, fragment="NumPy_Fragments") double* vgrp {
$1 = is_array($input);
}

%typemap(in, fragment="NumPy_Macros") double* vgrp {
$1 = (double *)array_data($input);
}
//--------------------------------------------------
// end typemaps for get_eigenmode_coefficients
//--------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ def add_flux(self, fcen, df, nfreq, *fluxes):

return self._add_fluxish_stuff(self.fields.add_dft_flux, fcen, df, nfreq, fluxes)

add_eigenmode = add_flux

def display_fluxes(self, *fluxes):
display_csv(self, 'flux', zip(get_flux_freqs(fluxes[0]), *[get_fluxes(f) for f in fluxes]))

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

def get_eigenmode_coefficients(self, flux, bands):
if self.fields is None:
raise ValueError("Fields must be initialized before calling get_eigenmode_coefficients")

num_bands = len(bands)
coeffs = np.zeros(2 * num_bands, dtype=np.complex128)
self.fields.get_eigenmode_coefficients(flux, np.array(bands, dtype=np.intc), coeffs, None)

return coeffs

def output_field_function(self, name, cs, func, real_only=False, h5file=None):
if self.fields is None:
raise RuntimeError("Fields must be initialized before calling output_field_function")
Expand Down