-
Notifications
You must be signed in to change notification settings - Fork 589
/
test_absorber_1d.py
54 lines (38 loc) · 1.56 KB
/
test_absorber_1d.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
import unittest
import meep as mp
from meep.materials import Al
class TestAbsorber(unittest.TestCase):
def setUp(self):
resolution = 40
cell_size = mp.Vector3(z=10)
absorber_layers = [mp.Absorber(1, direction=mp.Z)]
sources = [mp.Source(src=mp.GaussianSource(1 / 0.803, fwidth=0.1), center=mp.Vector3(),
component=mp.Ex)]
self.sim = mp.Simulation(cell_size=cell_size,
resolution=resolution,
dimensions=1,
default_material=Al,
boundary_layers=absorber_layers,
sources=sources)
def test_absorber(self):
self.sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ex, mp.Vector3(), 1e-6))
f = self.sim.get_field_point(mp.Ex, mp.Vector3())
self.assertAlmostEqual(f.real, 3.218846961494622e-13, places=6)
def test_absorber_2d(self):
source = mp.Source(
src=mp.GaussianSource(frequency=0.1, fwidth=0.1),
component=mp.Hz,
center=mp.Vector3()
)
sim = mp.Simulation(
cell_size=mp.Vector3(20, 20, 0),
resolution=10,
sources=[source],
boundary_layers=[mp.Absorber(5)]
)
sim.run(until_after_sources=1000)
v = mp.Vector3(4.13, 3.75, 0)
p = sim.get_field_point(mp.Hz, v)
self.assertAlmostEqual(-4.058476603571745e-11, p.real)
if __name__ == '__main__':
unittest.main()