def test_wire_mutual_inductance(): # Paul MTL P5.4 rw = 7.5 ref = Wire(0, 0, rw) wi = Wire(-50, 0, rw) wj = Wire(50, 0, rw) L = mtl.wire_mutual_inductance(wi, wj, ref) assert L == approx(0.241e-6, rel=0.001)
def test_two_wire_capacitance_bad_method(): rw = 1e-3 s = 10e-3 wires = [Wire(-0.5 * s, 0, rw)] ref = Wire(0.5 * s, 0, rw) pair = mtl.WireMtl(wires, ref) with pytest.raises(Exception): pair.capacitance(method='junk')
def test_two_wire_inductance(): rw = 7.5 s = 50 wires = [Wire(-0.5 * s, 0, rw)] ref = Wire(0.5 * s, 0, rw) pair = mtl.WireMtl(wires, ref) L = mtl.wire_inductance(s, rw) assert pair.inductance()[[0]] == approx(L, rel=0.02)
def test_two_wire_capacitance(): rw = 7.5 s = 50 wires = [Wire(-0.5 * s, 0, rw)] ref = Wire(0.5 * s, 0, rw) pair = mtl.WireMtl(wires, ref) C = mtl.wire_capacitance(s, rw) assert pair.capacitance()[[0]] == approx(C, rel=0.02, abs=1e-14)
def test_wire_self_inductance(): # Paul MTL P5.4 rw = 7.5 di0 = 50 ref = Wire(0, 0, rw) wire = Wire(di0, 0, rw) L = mtl.wire_self_inductance(wire, ref) assert L == approx(0.759e-6, abs=0.001e-6)
def test_two_wire_capacitance_fdm_near(): rw = 1e-3 s = 3e-3 wires = [Wire(-0.5 * s, 0, rw)] ref = Wire(0.5 * s, 0, rw) pair = mtl.WireMtl(wires, ref) expected = mtl.wire_capacitance(s, rw) C = pair.capacitance(method='fdm', fdm_params={'dx': rw / 10}) assert C == approx(expected, rel=0.05, abs=0.1e-12)
def test_two_wire_capacitance_fdm_diagonal(): rw = 1e-3 x2 = y2 = 6e-3 wires = [Wire(0, 0, rw)] ref = Wire(x2, y2, rw) pair = mtl.WireMtl(wires, ref) expected = pair.capacitance(method='ana') C = pair.capacitance(method='fdm') assert C == approx(expected, rel=0.05, abs=0.1e-12)
def test_two_wire_capacitance_fdm(): rw = 1e-3 s = 8e-3 wires = [Wire(-0.5 * s, 0, rw)] ref = Wire(0.5 * s, 0, rw) pair = mtl.WireMtl(wires, ref) expected = pair.capacitance(method='ana') C = pair.capacitance(method='fdm') assert C == approx(expected, rel=0.05, abs=0.1e-12)
def test_two_wire_inductance_diagonal(): rw = 7.5 s = 50 x2 = y2 = s / np.sqrt(2) wires = [Wire(0, 0, rw)] ref = Wire(x2, y2, rw) pair = mtl.WireMtl(wires, ref) L = mtl.wire_inductance(s, rw) assert pair.inductance()[[0]] == approx(L, rel=0.02)
def test_two_wire_capacitance_diagonal(): rw = 7.5 s = 50 x2 = y2 = s / np.sqrt(2) wires = [Wire(0, 0, rw)] ref = Wire(x2, y2, rw) pair = mtl.WireMtl(wires, ref) C = mtl.wire_capacitance(s, rw) assert pair.capacitance()[[0]] == approx(C, rel=0.02, abs=1e-14)
def test_three_wire_capacitance(): # Paul MTL P5.4 rw = 7.5 s = 50 wires = [Wire(s, 0, rw), Wire(-s, 0, rw)] ref = Wire(0, 0, rw) bus = mtl.WireMtl(wires, ref) C = bus.capacitance() expected = np.array([[16.3, -5.17], [-5.17, 16.3]]) * 1e-12 assert C == approx(expected, rel=0.001, abs=1e-14)
def test_three_wire_inductance(): # Paul MTL P5.4 rw = 7.5 s = 50 wires = [Wire(s, 0, rw), Wire(-s, 0, rw)] ref = Wire(0, 0, rw) bus = mtl.WireMtl(wires, ref) L = bus.inductance() expected = np.array([[0.759, 0.241], [0.241, 0.759]]) * 1e-6 assert L == approx(expected, rel=0.001)
def test_two_wire_inductance_shield(): # Paul MTL P5.10 rw = 0.1905e-3 s = 4 * rw rs = 4 * rw wires = [Wire(-0.5 * s, 0, rw), Wire(0.5 * s, 0, rw)] ref = Shield(rs) pair = mtl.WireMtl(wires, ref) L = pair.inductance() expected = np.array([[0.2197, 0.0446], [0.0446, 0.2197]]) * 1e-6 assert L == approx(expected, rel=0.001)
def test_two_wire_capacitance_plane(): # Paul MTL P5.7 rw = 0.04064 s = 2 h = 2 wires = [Wire(-0.5 * s, h, rw), Wire(0.5 * s, h, rw)] ref = Plane() pair = mtl.WireMtl(wires, ref) C = pair.capacitance() expected = np.array([[12.5, -2.19], [-2.19, 12.5]]) * 1e-12 assert C == approx(expected, rel=0.001, abs=1e-14)
def test_two_wire_inductance_plane(): # Paul MTL P5.7 rw = 0.04064 s = 2 h = 2 wires = [Wire(-0.5 * s, h, rw), Wire(0.5 * s, h, rw)] ref = Plane() pair = mtl.WireMtl(wires, ref) L = pair.inductance() expected = np.array([[0.918, 0.161], [0.161, 0.918]]) * 1e-6 assert L == approx(expected, rel=0.001)
def test_two_wire_capacitance_fdm_rw2(): rw1 = 1e-3 rw2 = 2e-3 s = 20e-3 wires = [Wire(-0.5 * s, 0, rw1)] ref = Wire(0.5 * s, 0, rw2) pair = mtl.WireMtl(wires, ref) expected = pair.capacitance(method='ana') print(expected) C = pair.capacitance(method='fdm') assert C == approx(expected, rel=0.05, abs=0.1e-12)
def test_two_wire_capacitance_shield(): # Paul MTL P5.11 rw = 0.1905e-3 s = 4 * rw rs = 4 * rw wires = [Wire(-0.5 * s, 0, rw), Wire(0.5 * s, 0, rw)] ref = Shield(rs) pair = mtl.WireMtl(wires, ref) C = pair.capacitance() expected = np.array([[52.8, -10.73], [-10.73, 52.8]]) * 1e-12 assert C == approx(expected, rel=0.001, abs=1e-14)
def test_one_wire_capacitance_shield(): rw = 0.5e-3 rs = 4e-3 er = 5.2 wires = [Wire(0, 0, rw)] ref = Shield(rs) cable = mtl.WireMtl(wires, ref, er) C = cable.capacitance() expected = coax.capacitance(rw, rs, er) assert C == approx(expected, rel=0.001, abs=1e-14)
def test_export(): PITCH = 1.27e-3 RW = 0.1905e-3 INS_ER = 3.5 INS_THK = 0.254e-3 # CR Paul MTL Table 5.5 # With / without dielectric # C11 37.432 22.494 pF/m # C12 -18.716 -11.247 pF/m # C22 24.982 16.581 pF/m capacitance = [] options = ((0.0, 1.0, 'no_'), (INS_THK, INS_ER, '')) for (ins_thk, ins_er, prefix) in options: filename = f'ribbon_{prefix}dielectric.lst' ref = Wire(0, 0, RW, ins_thk, ins_er) # ref = Plane() # ref = Shield(3 * PITCH) wires = [ Wire(PITCH, 0, RW, ins_thk, ins_er), Wire(2 * PITCH, 0, RW, ins_thk, ins_er) ] mtl = WireMtl(wires, ref) wire_mtl_to_fastcap2d(mtl, filename) try: capacitance.append(fc.run_fastercap(filename)) except Exception as ex: print(ex) fc.plot_list_file(filename) if len(capacitance) == 2: print('*****') print('No Dielectric (pF/m):') print(capacitance[0] * 1e12) print('With Dielectric (pF/m):') print(capacitance[1] * 1e12) plt.show()
def test_shield_contains_outside(): a = Wire(2.0, 0, 0.5) s = Shield(1.0) assert not s.contains(a)
def test_shield_contains_overlap(): a = Wire(0.6, 0, 0.5) s = Shield(1.0) assert not s.contains(a)
def test_radius_zero(): with pytest.raises(ValueError): Wire(0, 0, 0)
def test_shield_contains_wire_on_edge(): a = Wire(0, 0.5, 0.5) s = Shield(1.0) assert s.contains(a)
def test_shield_contains(): a = Wire(0, 0.0, 0.5) s = Shield(1.0) assert s.contains(a)
def test_shield_contains_wire_larger(): a = Wire(0, 0, 1.5) s = Shield(1.0) assert not s.contains(a)
def test_plane_height(): a = Wire(0, 2.0, 0.5) p = Plane() assert p.height_of(a) == approx(2.0)
def test_offset_zero(): a = Wire(1, 2, 0.5) assert a.offset(1, 2) == approx(0)
def test_offset(): a = Wire(1, 1, 0.5) assert a.offset() == approx(np.sqrt(2))
def test_angle_to_ortho(): a = Wire(1, 0, 0.5) b = Wire(0, 1, 0.5) assert a.angle_to(b) == approx(0.5 * np.pi)
def test_angle_to(): a = Wire(-1, 0, 0.5) b = Wire(1, 0, 0.5) assert a.angle_to(b) == approx(-np.pi) assert b.angle_to(a) == approx(np.pi)