Skip to content

Commit

Permalink
High level get_eigenmode_coefficients (NanoComp#248)
Browse files Browse the repository at this point in the history
* High level get_eigenmode_coefficients

* Update get_eigenmode_coefficients

* add eigvol to flux

* ../../python/simulation.py

* Attempt at add_eigenmode

* add_eigenmode is alias for add_flux

* No eigvol
  • Loading branch information
ChristopherHogan authored and stevengj committed Apr 15, 2018
1 parent e8f7664 commit 946601d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
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

0 comments on commit 946601d

Please sign in to comment.