File: physical.py

package info (click to toggle)
meep-openmpi 1.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 25,828 kB
  • sloc: cpp: 27,370; python: 10,574; lisp: 1,213; makefile: 437; sh: 28
file content (62 lines) | stat: -rw-r--r-- 2,092 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
56
57
58
59
60
61
62
# Copyright (C) 2005-2017 Massachusetts Institute of Technology
#
#  This program is free software you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation either version 2, or (at your option)
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program if not, write to the Free Software Foundation,
#  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import division

import unittest
import meep as mp


class TestPhysical(unittest.TestCase):

    def test_physical(self):

        a = 10.0
        ymax = 3.0
        xmax = 8.0
        dx = 2.0
        w = 0.30

        cell_size = mp.Vector3(xmax, ymax)
        pml_layers = [mp.PML(ymax / 3.0)]

        sources = [mp.Source(src=mp.ContinuousSource(w), component=mp.Ez,
                             center=mp.Vector3(-dx), size=mp.Vector3())]

        sim = mp.Simulation(cell_size=cell_size,
                            resolution=a,
                            boundary_layers=pml_layers,
                            sources=sources,
                            force_complex_fields=True)
        sim.init_sim()
        sim.solve_cw(tol=1e-6)

        p1 = mp.Vector3()
        p2 = mp.Vector3(dx)

        amp1 = sim.get_field_point(mp.Ez, p1)
        amp2 = sim.get_field_point(mp.Ez, p2)

        ratio = abs(amp1) / abs(amp2)
        ratio = ratio ** 2  # in 2d, decay is ~1/sqrt(r), so square to get 1/r

        fail_fmt = "Failed: amp1 = ({}, {}), amp2 = ({}, {})\nabs(amp1/amp2){} = {}, too far from 2.0"
        fail_msg = fail_fmt.format(amp1.real, amp1, amp2.real, amp2, "^2", ratio)

        self.assertTrue(ratio <= 2.12 and ratio >= 1.88, fail_msg)


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