File: medium_evaluations.py

package info (click to toggle)
meep-mpi-default 1.17.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 51,672 kB
  • sloc: cpp: 29,881; python: 17,210; lisp: 1,225; makefile: 477; sh: 249; ansic: 133; javascript: 5
file content (67 lines) | stat: -rw-r--r-- 2,501 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

# medium_evaluations.py - Tests the evaluation of material permitivity profiles.
# Checks materials with lorentizian, drude, and non uniform diagonals.
# The extracted values are compared against actual datapoints pulled from
#   refractiveindex.info.
# TODO: 
#  * check materials with off diagonal components
#  * check magnetic profiles

from __future__ import division

import unittest
import meep as mp
import numpy as np


class TestMediumEvaluations(unittest.TestCase):

    def test_medium_evaluations(self):
        from meep.materials import Si, Ag, LiNbO3, fused_quartz

        # Check that scalars work
        w0 = LiNbO3.valid_freq_range.min
        eps = LiNbO3.epsilon(w0)
        self.assertAlmostEqual(np.real(np.sqrt(eps[0,0])), 2.0508, places=4)

        # Check numpy arrays
        try:
            w0 = Si.valid_freq_range.min
            w1 = Si.valid_freq_range.max
            eps = Si.epsilon(np.linspace(w0,w1,100))
        except ExceptionType:
            self.fail("myFunc() raised ExceptionType unexpectedly!")

        # Check that regions outside of domain don't work
        self.assertRaises(ValueError,LiNbO3.epsilon,-1.0)
        self.assertRaises(ValueError,LiNbO3.epsilon,10000.0)

        # Check complex vs non complex numbers
        self.assertTrue(np.iscomplex(Ag.epsilon(1.0)[0,0]))
        self.assertFalse(np.iscomplex(fused_quartz.epsilon(1.0)[0,0]))

        # Check Silicon
        w0 = Si.valid_freq_range.min
        w1 = Si.valid_freq_range.max
        eps = Si.epsilon([w0,w1])
        self.assertAlmostEqual(np.real(np.sqrt(eps[0,0,0])), 3.4175, places=4)
        self.assertAlmostEqual(np.real(np.sqrt(eps[1,0,0])), 3.4971, places=4)

        # Check Silver
        w0 = Ag.valid_freq_range.min
        w1 = Ag.valid_freq_range.max
        eps = Ag.epsilon([w0,w1])
        self.assertAlmostEqual(np.real(np.sqrt(eps[0,0,0])), 17.485, places=2)
        self.assertAlmostEqual(np.real(np.sqrt(eps[1,0,0])), 0.44265, places=4)

        # Check Lithium Niobate
        w0 = LiNbO3.valid_freq_range.min
        w1 = LiNbO3.valid_freq_range.max
        eps = LiNbO3.epsilon([w0,w1])
        self.assertAlmostEqual(np.real(np.sqrt(eps[0,0,0])), 2.0508, places=4)
        self.assertAlmostEqual(np.real(np.sqrt(eps[1,0,0])), 2.4393, places=4)
        self.assertAlmostEqual(np.real(np.sqrt(eps[0,2,2])), 2.0025, places=4)
        self.assertAlmostEqual(np.real(np.sqrt(eps[1,2,2])), 2.3321, places=4)

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