Ejemplo n.º 1
0
 def test_zero_source(self):
     """check no field if zero mag source"""
     s = SourcePoint(0, 0, 0, 0, pi)
     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)
     self.assertEqual(round(f.imag() / 1e-9, 6), 0)
Ejemplo n.º 2
0
 def test_init(self):
     """Position and value match initialisation parameters"""
     x = 1.1
     y = 2.2
     z = 3.3
     fp = FieldPoint(x, y, z)
     self.assertEqual(fp.x, x)
     self.assertEqual(fp.y, y)
     self.assertEqual(fp.z, z)
     self.assertEqual(fp.v, 0)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def two_element_az():
    """Two element array, azimuth farfield"""
    phis = np.linspace(0, 2 * pi, 100)
    fields = []
    expected = []
    r = 10
    for phi in phis:
        y = r * cos(phi)
        z = r * sin(phi)
        fields.append(FieldPoint(0, y, z))
        # Expected result from J.D. Kraus Antennas For All Applications
        # 3rd Edition (International) pp.90ff
        expected.append(1)
    sources, frequency = get_sources_two_element()
    propagate(sources, fields, frequency)
    ff = []
    for field in fields:
        ff.append(field.abs())
    ffa = np.array(ff)
    normalised_ffa = ffa / np.max(ffa)
    return phis, normalised_ffa, expected
Ejemplo n.º 5
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)
Ejemplo n.º 6
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.º 7
0
 def test_distance(self):
     """Distance between two points is correct"""
     fp1 = FieldPoint(-1, -1, -1)
     fp2 = FieldPoint(1, 1, 1)
     self.assertEqual(fp1.distance(fp2), 2 * 3**0.5)
     self.assertEqual(fp2.distance(fp1), 2 * 3**0.5)