File: test_get_epsilon_grid.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 (97 lines) | stat: -rw-r--r-- 2,905 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import unittest

import meep.adjoint as mpa
import numpy as np
import parameterized
from meep.materials import Co, SiN

import meep as mp


class TestGetEpsilonGrid(unittest.TestCase):
    def setUp(self):
        resolution = 60
        self.cell_size = mp.Vector3(1.0, 1.0, 0)

        matgrid_resolution = 200
        matgrid_size = mp.Vector3(1.0, 1.0, mp.inf)
        Nx, Ny = int(matgrid_size.x * matgrid_resolution), int(
            matgrid_size.y * matgrid_resolution
        )
        x = np.linspace(-0.5 * matgrid_size.x, 0.5 * matgrid_size.x, Nx)
        y = np.linspace(-0.5 * matgrid_size.y, 0.5 * matgrid_size.y, Ny)
        xv, yv = np.meshgrid(x, y)
        rad = 0.201943
        w = 0.104283
        weights = np.logical_and(
            np.sqrt(np.square(xv) + np.square(yv)) > rad,
            np.sqrt(np.square(xv) + np.square(yv)) < rad + w,
            dtype=np.double,
        )

        matgrid = mp.MaterialGrid(
            mp.Vector3(Nx, Ny),
            mp.air,
            mp.Medium(index=3.5),
            weights=weights,
            do_averaging=False,
            beta=0,
            eta=0.5,
        )

        geometry = [
            mp.Cylinder(
                center=mp.Vector3(0.35, 0.1),
                radius=0.1,
                height=mp.inf,
                material=mp.Medium(index=1.5),
            ),
            mp.Block(
                center=mp.Vector3(-0.15, -0.2),
                size=mp.Vector3(0.2, 0.24, mp.inf),
                material=SiN,
            ),
            mp.Block(
                center=mp.Vector3(-0.2, 0.2),
                size=mp.Vector3(0.4, 0.4, mp.inf),
                material=matgrid,
            ),
            mp.Prism(
                vertices=[
                    mp.Vector3(0.05, 0.45),
                    mp.Vector3(0.32, 0.22),
                    mp.Vector3(0.15, 0.10),
                ],
                height=0.5,
                material=Co,
            ),
        ]

        self.sim = mp.Simulation(
            resolution=resolution,
            cell_size=self.cell_size,
            geometry=geometry,
            eps_averaging=False,
        )
        self.sim.init_sim()

    @parameterized.parameterized.expand(
        [
            (mp.Vector3(0.2, 0.2), 1.1),
            (mp.Vector3(-0.2, 0.1), 0.7),
            (mp.Vector3(-0.2, -0.25), 0.55),
            (mp.Vector3(0.4, 0.1), 0),
        ]
    )
    def test_get_epsilon_grid(self, pt, freq):
        eps_grid = self.sim.get_epsilon_grid(
            np.array([pt.x]), np.array([pt.y]), np.array([0]), freq
        )
        eps_pt = self.sim.get_epsilon_point(pt, freq)
        print(f"eps:, ({pt.x},{pt.y}), {eps_grid}, {eps_pt}")
        self.assertAlmostEqual(np.real(eps_grid), np.real(eps_pt), places=6)
        self.assertAlmostEqual(np.imag(eps_grid), np.imag(eps_pt), places=6)


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