-
Notifications
You must be signed in to change notification settings - Fork 589
/
test_material_dispersion.py
58 lines (44 loc) · 1.46 KB
/
test_material_dispersion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import unittest
import numpy as np
import meep as mp
class TestMaterialDispersion(unittest.TestCase):
def test_material_dispersion_with_user_material(self):
susceptibilities = [
mp.LorentzianSusceptibility(frequency=1.1, gamma=1e-5, sigma=0.5),
mp.LorentzianSusceptibility(frequency=0.5, gamma=0.1, sigma=2e-5)
]
def mat_func(p):
return mp.Medium(epsilon=2.25, E_susceptibilities=susceptibilities)
fcen = 1.0
df = 2.0
sources = mp.Source(
mp.GaussianSource(fcen, fwidth=df),
component=mp.Ez,
center=mp.Vector3()
)
kmin = 0.3
kmax = 2.2
k_interp = 5
kpts = mp.interpolate(k_interp, [mp.Vector3(kmin), mp.Vector3(kmax)])
self.sim = mp.Simulation(
cell_size=mp.Vector3(),
geometry=[],
sources=[sources],
material_function=mat_func,
default_material=mp.air,
resolution=20
)
all_freqs = self.sim.run_k_points(200, kpts)
res = [f.real for fs in all_freqs for f in fs]
expected = [
0.1999342026399106,
0.41053963810375294,
0.6202409070451909,
0.8285737385146619,
1.0350739448523063,
1.2392775309110078,
1.4407208712852109,
]
np.testing.assert_allclose(expected, res)
if __name__ == '__main__':
unittest.main()