Exemplo 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.))
Exemplo n.º 2
0
    def test_phase(self):
        """check phase is 2pi/wavelength"""
        s = SourcePoint(0, 0, 0, 1, 0)
        frequency = 1
        wavelength = speed_of_light / frequency
        k = 2 * pi / wavelength
        f = FieldPoint(wavelength / 2, 0, 0)
        propagate_single(s, f, k)
        self.assertEqual(round(f.phase(), 6), 3.141593)

        # positive phase expected in negative directions because
        # wave travels outward
        fnegx = FieldPoint(-wavelength / 2, 0, 0)
        propagate_single(s, fnegx, k)
        self.assertEqual(round(fnegx.phase(), 6), 3.141593)

        f1 = FieldPoint(wavelength, 0, 0)
        propagate_single(s, f1, k)
        self.assertEqual(round(f1.phase(), 6), 0)