File: kdom.py

package info (click to toggle)
meep-mpi-default 1.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 25,820 kB
  • sloc: cpp: 27,370; python: 10,574; lisp: 1,213; makefile: 438; sh: 28
file content (53 lines) | stat: -rw-r--r-- 1,460 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
from __future__ import division

import unittest
import meep as mp
import math

class TestKdom(unittest.TestCase):

  def run_kdom(self, theta, num_band):

    resolution = 20        # pixels/um

    sx = 5
    sy = 10
    cell_size = mp.Vector3(sx,sy,0)

    fcen = 1               # center frequency (wavelength = 1 um)
    ng = 1.5
    glass = mp.Medium(index=ng)

    # angle of incident planewave; CCW about Y axis, 0 degrees along +X axis
    theta_in = math.radians(theta)

    # k (in source medium) with correct length (plane of incidence: XY)
    k = mp.Vector3(math.cos(theta_in),math.sin(theta_in),0).scale(fcen*ng)

    symmetries = []
    eig_parity = mp.ODD_Z
    if theta_in == 0:
      k = mp.Vector3(0,0,0)
      eig_parity += mp.EVEN_Y
      symmetries = [mp.Mirror(mp.Y)]
  
    sim = mp.Simulation(resolution=resolution,
                        cell_size=cell_size,
                        k_point=k,
                        symmetries=symmetries,
                        default_material=glass)

    sim.init_sim()

    EigenmodeData = sim.get_eigenmode(fcen, mp.X, mp.Volume(center=mp.Vector3(0.3*sx,0,0), size=mp.Vector3(0,sy,0)),
                                      num_band, k, parity=eig_parity, verbose=True)
    kdom = EigenmodeData.kdom
    
    self.assertAlmostEqual(k.y,kdom.y,places=15)
    
  def test_kdom(self):
      self.run_kdom(10.7, 6)
      self.run_kdom(22.9, 12)
    
if __name__ == '__main__':
  unittest.main()