forked from NanoComp/meep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dft_energy Python support (NanoComp#747)
* Add dft_energy Python support * Add new functions to meep package * Add explanation of DftObj class * Add test
- Loading branch information
1 parent
b49747d
commit ea84c0e
Showing
4 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import division | ||
|
||
import unittest | ||
import meep as mp | ||
|
||
# compute group velocity of a waveguide mode using two different methods | ||
# (1) ratio of Poynting flux to energy density | ||
# (2) via MPB from get-eigenmode-coefficients | ||
|
||
|
||
class TestDftEnergy(unittest.TestCase): | ||
|
||
def test_dft_energy(self): | ||
resolution = 20 | ||
cell = mp.Vector3(10, 5) | ||
geom = [mp.Block(size=mp.Vector3(mp.inf, 1, mp.inf), material=mp.Medium(epsilon=12))] | ||
pml = [mp.PML(1)] | ||
fsrc = 0.15 | ||
sources = [mp.EigenModeSource(src=mp.GaussianSource(frequency=fsrc, fwidth=0.2*fsrc), | ||
center=mp.Vector3(-3), size=mp.Vector3(y=5), | ||
eig_band=1, eig_parity=mp.ODD_Z+mp.EVEN_Y, | ||
eig_match_freq=True)] | ||
|
||
sim = mp.Simulation(resolution=resolution, cell_size=cell, geometry=geom, | ||
boundary_layers=pml, sources=sources) | ||
|
||
flux = sim.add_flux(fsrc, 0, 1, mp.FluxRegion(center=mp.Vector3(3), size=mp.Vector3(y=5))) | ||
energy = sim.add_energy(fsrc, 0, 1, mp.EnergyRegion(center=mp.Vector3(3), size=mp.Vector3(y=5))) | ||
sim.run(until_after_sources=100) | ||
|
||
res = sim.get_eigenmode_coefficients(flux, [1], eig_parity=mp.ODD_Z+mp.EVEN_Y) | ||
mode_vg = res.vgrp[0] | ||
poynting_flux = mp.get_fluxes(flux)[0] | ||
e_energy = mp.get_electric_energy(energy)[0] | ||
ratio_vg = (0.5 * poynting_flux) / e_energy | ||
m_energy = mp.get_magnetic_energy(energy)[0] | ||
t_energy = mp.get_total_energy(energy)[0] | ||
|
||
self.assertAlmostEqual(m_energy + e_energy, t_energy) | ||
self.assertAlmostEqual(ratio_vg, mode_vg, places=3) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |