File: test_eigfreq.py

package info (click to toggle)
meep-openmpi 1.25.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 64,556 kB
  • sloc: cpp: 32,214; python: 27,958; lisp: 1,225; makefile: 505; sh: 249; ansic: 131; javascript: 5
file content (55 lines) | stat: -rw-r--r-- 1,796 bytes parent folder | download | duplicates (5)
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
import unittest

import meep as mp


class TestEigfreq(unittest.TestCase):
    @unittest.skipIf(
        mp.is_single_precision(), "double-precision floating point specific test"
    )
    def test_eigfreq(self):
        w = 1.2  # width of waveguide
        r = 0.36  # radius of holes
        d = 1.4  # defect spacing (ordinary spacing = 1)
        N = 3  # number of holes on either side of defect
        sy = 6  # size of cell in y direction (perpendicular to wvg.)
        pad = 2  # padding between last hole and PML edge
        dpml = 1  # PML thickness
        sx = 2 * (pad + dpml + N) + d - 1  # size of cell in x direction

        geometry = [
            mp.Block(size=mp.Vector3(mp.inf, w, mp.inf), material=mp.Medium(epsilon=13))
        ]
        for i in range(N):
            geometry.append(mp.Cylinder(r, center=mp.Vector3(d / 2 + i)))
            geometry.append(mp.Cylinder(r, center=mp.Vector3(-(d / 2 + i))))

        fcen = 0.25
        df = 0.2
        src = [
            mp.Source(
                mp.GaussianSource(fcen, fwidth=df),
                component=mp.Hz,
                center=mp.Vector3(0),
                size=mp.Vector3(0, 0),
            )
        ]

        sim = mp.Simulation(
            cell_size=mp.Vector3(sx, sy),
            force_complex_fields=True,
            geometry=geometry,
            boundary_layers=[mp.PML(1.0)],
            sources=src,
            symmetries=[mp.Mirror(mp.X, phase=-1), mp.Mirror(mp.Y, phase=-1)],
            resolution=20,
        )
        sim.init_sim()
        eigfreq = sim.solve_eigfreq(tol=1e-6)

        self.assertAlmostEqual(eigfreq.real, 0.23445413142440263, places=5)
        self.assertAlmostEqual(eigfreq.imag, -0.0003147775697388, places=5)


if __name__ == "__main__":
    unittest.main()