Ejemplo n.º 1
0
def test_potential_2layer():
    ri = 8e-3
    er1, t1 = 6.0, 2e-3
    er2, t2 = 3.0, 20e-3
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    R = np.array([8e-3, 10e-3, 30e-3])
    V = cc.potential(R, Va=12500)
    assert V == approx(np.array([12500, 11347, 0]), abs=1)
Ejemplo n.º 2
0
def test_efield_2layer():
    ri = 8e-3
    er1, t1 = 6.0, 2e-3
    er2, t2 = 3.0, 20e-3
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    R = np.array([8e-3, 10e-3, 10.001e-3, 30e-3])
    E = cc.efield(R, Va=12500)
    assert E == approx(np.array([0.6456e6, 0.5165e6, 1.033e6, 0.3443e6]),
                       abs=1e3)
Ejemplo n.º 3
0
def test_potential_2layer_2():
    # Cheng Ex. 3-16
    ri = 4e-3
    er1, t1 = 3.2, (6.16e-3 - ri)
    er2, t2 = 2.6, (8.32e-3 - 6.16e-3)
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    R = np.array([ri, ri + t1, ri + t1 + t2])
    V = cc.potential(R, Va=20e3)
    assert V == approx(np.array([20e3, 9.3e3, 0]), rel=0.01)
Ejemplo n.º 4
0
def test_2layer():
    ri = 20e-3
    er1, t1 = 2.0, 2.5e-3
    er2, t2 = 5.0, 2.5e-3
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    X, er = cc.get_arrays(N=5)
    assert cc.ro == approx(ri + t1 + t2)
    assert X == approx([20e-3, 21.25e-3, 22.5e-3, 23.75e-3, 25e-3])
    assert er == approx([er1, er1, er2, er2])
Ejemplo n.º 5
0
def test_efield_2layer_2():
    # Cheng Ex. 3-16
    ri = 4e-3
    er1, t1 = 3.2, (6.16e-3 - ri)
    er2, t2 = 2.6, (8.32e-3 - 6.16e-3)
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    R = np.array([ri, 0.999 * (ri + t1), 1.001 * (ri + t1), ri + t1 + t2])
    E = cc.efield(R, Va=20e3)
    assert E == approx(np.array([6.25e6, 4.06e6, 5.00e6, 3.71e6]), rel=0.01)
Ejemplo n.º 6
0
def test_potential_inner():
    ri = 0.5e-3
    ro = 4.0e-3
    N = 5
    cc = CoaxCapacitor(ri, 5.2, ro - ri)
    X = np.linspace(0, ri, N)
    Va = 10.0
    potential = cc.potential(X, Va=Va)
    assert potential == approx(Va)
Ejemplo n.º 7
0
def test_efield():
    ri = 0.5e-3
    ro = 4.0e-3
    N = 5
    cc = CoaxCapacitor(ri, 5.2, ro - ri)
    X = np.linspace(ri, ro, N)
    Va = 10.0
    expected = -Va / X / np.log(ri / ro)
    efield = cc.efield(X, Va=Va)
    assert efield == approx(expected)
Ejemplo n.º 8
0
def test_potential():
    ri = 0.5e-3
    ro = 4.0e-3
    N = 5
    cc = CoaxCapacitor(ri, 5.2, ro - ri)
    X = np.linspace(ri, ro, N)
    Va = 10.0
    expected = Va / np.log(ri / ro) * np.log(X / ro)
    potential = cc.potential(X, Va=Va)
    assert potential == approx(expected)
Ejemplo n.º 9
0
def test_potential_outer():
    ri = 0.5e-3
    ro = 4.0e-3
    Vref = 5.0
    N = 5
    cc = CoaxCapacitor(ri, 5.2, ro - ri)
    X = np.linspace(ro, 10 * ro, N)
    Va = 10.0
    potential = cc.potential(X, Va=Va, Vref=Vref)
    assert potential == approx(Vref)
Ejemplo n.º 10
0
def test_potential_diagonal():
    ri = 0.5e-3
    ro = 4.0e-3
    N = 5
    cc = CoaxCapacitor(ri, 5.2, ro - ri)
    R = np.linspace(ri, ro, N)
    theta = np.pi / 4
    X = R * np.cos(theta)
    Y = R * np.sin(theta)
    Va = 10.0
    expected = Va / np.log(ri / ro) * np.log(R / ro)
    potential = cc.potential(X, Y, Va=Va)
    assert potential == approx(expected)
Ejemplo n.º 11
0
def test_gauss_1d_coax():
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3)
    X, er = cc.get_arrays(101)
    v1 = 10.0
    V = cc.potential(X, Va=v1)
    # 1D gauss returns a charge density over circumference
    # Result is negative due to direction of X
    Q = np.array([
        -2 * np.pi * X[i] * fdm.gauss_1d(X, V, er, i)
        for i in range(1,
                       len(X) - 1)
    ])
    Qa = cc.charge(v1)
    assert Q == approx(Qa, rel=0.01)
Ejemplo n.º 12
0
def test_poisson_2d_coax():
    ri = 2.0e-3
    ro = 4.0e-3
    w = 1.1 * ro
    N = 101
    Va = 10.0
    x = np.linspace(-w, w, N)
    y = np.linspace(-w, w, N)
    X, Y = np.meshgrid(x, y, indexing='ij')
    R = np.sqrt(X**2 + Y**2)
    bc_bool = np.logical_or(R < ri, R > ro)
    bc_val = np.select([R < ri, R > ro], [Va, 0])
    bc = (bc_bool, bc_val)
    cc = CoaxCapacitor(ri, 1.0, ro - ri)
    expected = cc.potential(X, Y, Va=Va)
    potential = fdm.poisson_2d(X, Y, bc=bc, conv=1e-5)
    assert potential == approx(expected, abs=0.4)
Ejemplo n.º 13
0
def test_poisson_2d_coax_xysym():
    ri = 2.0e-3
    ro = 4.0e-3
    w = 1.1 * ro
    dx = ri / 40
    Va = 10.0
    x = np.arange(0, w, dx)
    y = np.arange(0, w, dx)
    X, Y = np.meshgrid(x, y, indexing='ij')
    R = np.sqrt(X**2 + Y**2)
    bc_bool = np.logical_or(R < ri, R > ro)
    bc_val = np.select([R < ri, R > ro], [Va, 0])
    bc = (bc_bool, bc_val)
    cc = CoaxCapacitor(ri, 1.0, ro - ri)
    expected = cc.potential(X, Y, Va=Va)
    potential = fdm.poisson_2d(X, Y, bc=bc, conv=1e-6, xsym=True, ysym=True)
    assert potential == approx(expected, abs=0.4)
Ejemplo n.º 14
0
def test_poisson_2d_coax_2layer():
    ri = 2.0e-3
    re = 2.8e-3
    ro = 4.0e-3
    er1, er2 = 4.0, 1.0
    w = 1.1 * ro
    N = 101
    Va = 10.0
    x = np.linspace(-w, w, N)
    y = np.linspace(-w, w, N)
    X, Y = np.meshgrid(x, y, indexing='ij')
    R = np.sqrt(X**2 + Y**2)
    er = np.select([R <= re, R > re], [er1, er2])[:-1, :-1]
    bc_bool = np.logical_or(R < ri, R > ro)
    bc_val = np.select([R < ri, R > ro], [Va, 0])
    bc = (bc_bool, bc_val)
    cc = CoaxCapacitor(ri, (er1, er2), (re - ri, ro - re))
    expected = cc.potential(X, Y, Va=Va)
    np.savetxt('e2d.csv', expected, delimiter=',', fmt='%.3f')
    potential = fdm.poisson_2d(X, Y, dielectric=er, bc=bc, conv=1e-5)
    assert potential == approx(expected, abs=0.6)
Ejemplo n.º 15
0
def test_gauss_2d_coax_xysym():
    ri = 1.0e-3
    ro = 4.0e-3
    rm = 0.5 * (ri + ro)
    assert rm * 1.414 < ro
    w = 1.1 * ro
    dx = ri / 40
    Va = 10.0
    x = np.arange(0, w, dx)
    y = np.arange(0, w, dx)
    X, Y = np.meshgrid(x, y, indexing='ij')
    cc = CoaxCapacitor(ri, 1.0, ro - ri)
    V = cc.potential(X, Y, Va=Va)
    expected = cc.charge(Va)
    er = np.ones_like(V)[:-1, :-1]
    xi1 = 0
    xi2 = np.searchsorted(x, rm)
    yi1 = 0
    yi2 = np.searchsorted(y, rm)
    gauss = fdm.gauss_2d(X, Y, V, er, xi1, xi2, yi1, yi2)
    assert gauss == approx(expected, rel=0.01, abs=1e-14)
Ejemplo n.º 16
0
def test_capacitance_2layer():
    ri = 20e-3
    er1, t1 = 2.0, 2.5e-3
    er2, t2 = 5.0, 2.5e-3
    cc = CoaxCapacitor(ri, (er1, er2), (t1, t2))
    assert cc.capacitance() == approx(695.7e-12)
Ejemplo n.º 17
0
def test_capacitance():
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3)
    assert cc.capacitance() == approx(139.1e-12, abs=0.1e-12)
Ejemplo n.º 18
0
def test_charge():
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3)
    Va = 10.0
    expected = cc.capacitance() * Va
    assert cc.charge(Va) == approx(expected)
Ejemplo n.º 19
0
def test_energy():
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3)
    Va = 10.0
    expected = 0.5 * cc.capacitance() * Va**2
    assert cc.energy(Va) == approx(expected)
Ejemplo n.º 20
0
def test_get_arrays():
    N = 11
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3)
    X, er = cc.get_arrays(N=N)
    assert X == approx(np.linspace(0.5e-3, 4e-3, N))
    assert er == approx(5.2 * np.ones(N - 1))
Ejemplo n.º 21
0
def test_2layer_mixed_type():
    er1, t1 = 5.0, 1e-3
    er2 = 1.0
    with pytest.raises(Exception):
        CoaxCapacitor(20e-3, (er1, er2), t1)
Ejemplo n.º 22
0
def test_capacitance_length():
    cc = CoaxCapacitor(0.5e-3, 5.2, 3.5e-3, length=10.0)
    assert cc.capacitance() == approx(1.391e-9)
Ejemplo n.º 23
0
def test_2layer_mixed_length():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    with pytest.raises(Exception):
        CoaxCapacitor(20e-3, (er1, er2), (t1, t2, t2))