"Fossies" - the Fresh Open Source Software Archive

Member "meep-1.10.0/python/tests/pw_source.py" (22 Dec 2017, 1864 Bytes) of package /linux/privat/meep-1.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 from __future__ import division
    2 
    3 import cmath
    4 import math
    5 import unittest
    6 
    7 import meep as mp
    8 
    9 
   10 class TestPwSource(unittest.TestCase):
   11 
   12     def setUp(self):
   13         s = 11
   14         dpml = 1
   15 
   16         sxy = s + 2 * dpml
   17         cell = mp.Vector3(sxy, sxy, 0)
   18 
   19         pml_layers = [mp.PML(dpml)]
   20         resolution = 10
   21 
   22         def pw_amp(k, x0):
   23             def _pw_amp(x):
   24                 return cmath.exp(1j * k.dot(x + x0))
   25             return _pw_amp
   26 
   27         fcen = 0.8
   28         df = 0.02
   29         kdir = mp.Vector3(1, 1)
   30         self.k = kdir.unit().scale(2 * math.pi * fcen)
   31 
   32         sources = [
   33             mp.Source(
   34                 mp.ContinuousSource(fcen, fwidth=df),
   35                 component=mp.Ez,
   36                 center=mp.Vector3(-0.5 * s, 0),
   37                 size=mp.Vector3(0, s),
   38                 amp_func=pw_amp(self.k, mp.Vector3(x=-0.5 * s))
   39             ),
   40             mp.Source(
   41                 mp.ContinuousSource(fcen, fwidth=df),
   42                 component=mp.Ez,
   43                 center=mp.Vector3(0, -0.5 * s),
   44                 size=mp.Vector3(s, 0),
   45                 amp_func=pw_amp(self.k, mp.Vector3(y=-0.5 * s))
   46             )
   47         ]
   48 
   49         self.sim = mp.Simulation(
   50             cell_size=cell,
   51             sources=sources,
   52             boundary_layers=pml_layers,
   53             resolution=resolution
   54         )
   55         self.s = s
   56 
   57     def test_pw_source(self):
   58         self.sim.run(mp.at_end(mp.output_efield_z), until=400)
   59 
   60         v1 = mp.Vector3(0.5 * self.s, 0)
   61         v2 = mp.Vector3(0.5 * self.s, 0.5 * self.s)
   62 
   63         pt1 = self.sim.get_field_point(mp.Ez, v1)
   64         pt2 = self.sim.get_field_point(mp.Ez, v2)
   65 
   66         self.assertAlmostEqual(pt1 / pt2, 27.557668029008262)
   67         self.assertAlmostEqual(cmath.exp(1j * self.k.dot(v1 - v2)), 0.7654030066070924 - 0.6435512702783076j)
   68 
   69 if __name__ == '__main__':
   70     unittest.main()