def setUp(self): # setup parallel wire cluster current_pve = parameter.ConstantParameter(1) current_nve = parameter.ConstantParameter(-1) wire_top = wire.WireSegment(current_pve, [-1, 1, 0], [1, 1, 0]) wire_bot = wire.WireSegment(current_pve, [-1, -1, 0], [1, -1, 0]) self.cluster_parallel = wire.WireCluster([wire_top, wire_bot]) # And anti-parallel wire_top = wire.WireSegment(current_pve, [-1, 1, 0], [1, 1, 0]) wire_bot = wire.WireSegment(current_nve, [-1, -1, 0], [1, -1, 0]) self.cluster_antiparallel = wire.WireCluster([wire_bot, wire_top])
def test_equality(self): same_wire = wire.WireSegment(self.current, self.start, self.end) self.assertEqual(self.wire, same_wire) # Check with same current same_current = parameter.ConstantParameter(self.current.value(0)) same_wire = wire.WireSegment(same_current, self.start, self.end) self.assertEqual(self.wire, same_wire) # Check with different current diff_current = parameter.ConstantParameter(-2) different_wire = wire.WireSegment(diff_current, [-5, 0, 0], [0, 0, 3]) self.assertNotEqual(self.wire, different_wire)
def setUp(self): self.end_length = 10 self.current = parameter.ConstantParameter(1) self.al = 1. self.z_wire = wire.ZWire(self.current, self.al, end_length=self.end_length)
def setUp(self): """ Initialise a wire for basic testing """ self.start = [-1, 0, 0] self.end = [1, 0, 0] self.current = parameter.ConstantParameter(1) self.wire = wire.WireSegment(self.current, self.start, self.end)
def test_cluster_static(self): """ Test init parameter types for cluster trap sta """ cur = parameter.ConstantParameter(1) zwire = wire.ZWire(cur, 0.1) fld = field.StaticField([0, 0, 0]) cluster_trap = trap.ClusterTrapStatic self.assertRaises(ValueError, cluster_trap, 0, fld) self.assertRaises(ValueError, cluster_trap, zwire, 0)
def test_set_current(self): """ Cannot set int as current (must be of type AbstractParameterProfile) """ with self.assertRaises(ValueError): self.wire.set_current(1) cur = 5 new_current = parameter.ConstantParameter(cur) self.wire.set_current(new_current) self.assertEqual(self.wire.current.value(0), cur)
def test_field_simple_reverse(self): """ Test the field method when the wire current is reversed """ current_nve = parameter.ConstantParameter(-1) self.wire.set_current(current_nve) r = [0, 1, 0] magnitude = spc.mu_0 / (2 * np.sqrt(2) * np.pi) z_hat = np.array([0, 0, 1]) np.testing.assert_array_almost_equal(self.wire.field(0, r), -1 * magnitude * z_hat)
def test_zwire_rt_static(self): """ Test the static zwire trap generated with position and time. Check that the zero is where we expect it to be """ cur = parameter.ConstantParameter(1) zwire = wire.ZWire(cur, 0.1) zero_pos = [0, 0, 0.1] ztrap = trap.ClusterTrapStaticTR(zwire, 0, zero_pos) # Test zero at time 0 zero_value = ztrap.field(0, zero_pos) np.testing.assert_array_almost_equal(zero_value, np.zeros(3)) # Test zero at later times (there should be no time evolution zero_value = ztrap.field(1, zero_pos) np.testing.assert_array_almost_equal(zero_value, np.zeros(3)) # Test that we have a non-zero value elsewhere nonzero_value = ztrap.field(0, [0.1, 0.1, 0.1]) self.assertRaises( AssertionError, np.testing.assert_array_equal, nonzero_value, np.zeros(3) )