Ejemplo n.º 1
0
 def test_add_value(self):
     """Values are added not replaced"""
     fp1 = FieldPoint(0, 0, 0)
     fp1.add(1 + 2j)
     self.assertEqual(fp1.real(), 1)
     self.assertEqual(fp1.imag(), 2)
     self.assertEqual(fp1.abs(), (1**2 + 2 * 2)**0.5)
     self.assertEqual(fp1.phase(), math.atan(2))
     fp1.add(2 + 2j)
     self.assertEqual(fp1.real(), 3)
     self.assertEqual(fp1.imag(), 4)
     self.assertEqual(fp1.abs(), (3**2 + 4**2)**0.5)
     self.assertEqual(fp1.phase(), math.atan(4. / 3.))
Ejemplo n.º 2
0
    def test_decay_rate(self):
        """ check amplitude decays at rate 1/r"""
        s = SourcePoint(0, 0, 0, 1, 0)
        f = FieldPoint(1, 0, 0)
        frequency = 1
        wavelength = speed_of_light / frequency
        k = 2 * pi / wavelength
        propagate_single(s, f, k)
        self.assertEqual(round(f.real(), 6), 0.079577)
        self.assertEqual(round(f.imag() / 1e-9, 6), 1.66782)

        f2 = FieldPoint(2, 0, 0)
        propagate_single(s, f2, k)
        self.assertEqual(f.abs() / f2.abs(), 2)

        f4 = FieldPoint(4, 0, 0)
        propagate_single(s, f4, k)
        self.assertEqual(round(f.abs() / f4.abs(), 6), 4)