Example #1
0
def test_potential_2layer():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    pp = ParallelPlates((er1, er2), (t1, t2))
    X = np.linspace(0, 4e-3, 5)
    V = pp.potential(X, 200)
    assert V == approx([0, 12.5, 75, 137.5, 200])
Example #2
0
def test_poisson_1d_dielectric2():
    pp = ParallelPlates((1.0, 5.0, 1.0), (2e-3, 1e-3, 1e-3))
    v0 = 0
    v1 = 200
    X, er = pp.get_arrays(101)
    V = fdm.poisson_1d(X, dielectric=er, v_left=v0, v_right=v1, conv=1e-7)
    Va = pp.potential(X, v1 - v0, v0)
    assert V == approx(Va, abs=0.01)
Example #3
0
def test_gauss_1d_dielectric():
    pp = ParallelPlates((2.0, 4.0), (3e-3, 2e-3))
    X, er = pp.get_arrays(101)
    v1 = 10.0
    V = pp.potential(X, v1)
    Q = np.array([fdm.gauss_1d(X, V, er, i) for i in range(1, len(X) - 1)])
    Qa = pp.charge(v1)
    assert Q == approx(Qa)
Example #4
0
def test_2layer():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    pp = ParallelPlates((er1, er2), (t1, t2))
    X, er = pp.get_arrays(N=5)
    assert pp.thickness == approx(t1 + t2)
    assert X == approx([0.0, 1e-3, 2e-3, 3e-3, 4e-3])
    assert er == approx([er1, er2, er2, er2])
Example #5
0
def test_poisson_1d():
    pp = ParallelPlates(1.0, 5e-3)
    X, _ = pp.get_arrays(101)
    v0 = -2
    v1 = 5
    V = fdm.poisson_1d(X, v_left=v0, v_right=v1, conv=1e-5)
    Va = pp.potential(X, v1 - v0, v0)
    assert V == approx(Va, abs=0.01)
Example #6
0
def test_potential():
    t = 1e-3
    N = 5
    pp = ParallelPlates(3.5, t)
    X = np.linspace(0, t, N)
    Va = 10.0
    expected = Va / t * X
    potential = pp.potential(X, Va)
    assert potential == approx(expected)
Example #7
0
def test_efield_2layer():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    pp = ParallelPlates((er1, er2), (t1, t2))
    X = np.linspace(0, 4e-3, 5)
    E = pp.efield(X, 200)
    E1 = -12.5 / t1
    E2 = -187.5 / t2
    assert E == approx([E1, E1, E2, E2, E2])
Example #8
0
def test_efield():
    t = 1e-3
    N = 5
    pp = ParallelPlates(3.5, t)
    X = np.linspace(0, t, N)
    Va = 10.0
    expected = -Va / t * np.ones(N)
    efield = pp.efield(X, Va)
    assert efield == approx(expected)
Example #9
0
def test_potential_ref():
    t = 1e-3
    N = 5
    pp = ParallelPlates(3.5, t)
    X = np.linspace(0, t, N)
    Va = 10.0
    Vref = 5.0
    expected = Va / t * X + Vref
    potential = pp.potential(X, Va, Vref=Vref)
    assert potential == approx(expected)
Example #10
0
def test_2layer_area():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    A = 3.0
    pp1 = ParallelPlates((er1, er2), (t1, t2))
    pp2 = ParallelPlates((er1, er2), (t1, t2), area=A)
    Va = 25.0
    X = np.linspace(0, t1 + t2, 11)
    assert pp1.capacitance() == approx(pp2.capacitance() / A)
    assert pp1.efield(X, Va) == approx(pp2.efield(X, Va))
    assert pp1.potential(X, Va) == approx(pp2.potential(X, Va))
Example #11
0
def test_efield_pplate():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    Va = 200
    pp = ParallelPlates((er1, er2), (t1, t2))
    X, dx = np.linspace(0, 4e-3, 21, retstep=True)
    V = pp.potential(X, Va)
    E = pp.efield(X, Va)
    Ec = em.efield_1d(V, dx)
    assert Ec[:5] == approx(E[:5])
    # discontinuity at boundary [5]
    assert Ec[6:] == approx(E[6:])
Example #12
0
def test_efield_pplate_fdm():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    Va = 200
    pp = ParallelPlates((er1, er2), (t1, t2))
    X, dx = np.linspace(0, 4e-3, 21, retstep=True)
    V = pp.potential(X, Va)
    E = em.efield_1d(V, dx)

    er = np.where(X[:-1] < t1, er1, er2)
    Vfdm = fdm.poisson_1d(X, dielectric=er, v_right=Va)
    Efdm = em.efield_1d(Vfdm, dx)
    assert Efdm == approx(E, rel=0.001)
Example #13
0
def test_get_arrays():
    N = 11
    pp = ParallelPlates(3.5, 1e-3)
    X, er = pp.get_arrays(N=N)
    assert X == approx(np.linspace(0, 1e-3, N))
    assert er == approx(3.5 * np.ones(N - 1))
Example #14
0
def test_capacitance_2layer():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    pp = ParallelPlates((er1, er2), (t1, t2))
    assert pp.capacitance() == approx(2.767e-9)
Example #15
0
def test_capacitance():
    pp = ParallelPlates(3.5, 1e-3)
    assert pp.capacitance() == approx(30.989e-9)
Example #16
0
def test_2layer_mixed_length():
    er1, t1 = 5.0, 1e-3
    er2, t2 = 1.0, 3e-3
    with pytest.raises(Exception):
        ParallelPlates((er1, er2), (t1, t2, t2))
Example #17
0
def test_2layer_mixed_type():
    er1, t1 = 5.0, 1e-3
    er2 = 1.0
    with pytest.raises(Exception):
        ParallelPlates((er1, er2), t1)
Example #18
0
def test_charge():
    pp = ParallelPlates(3.5, 1e-3)
    Va = 10.0
    expected = pp.capacitance() * Va
    assert pp.charge(Va) == approx(expected)
Example #19
0
def test_energy():
    pp = ParallelPlates(3.5, 1e-3)
    Va = 10.0
    expected = 0.5 * pp.capacitance() * Va**2
    assert pp.energy(Va) == approx(expected)
Example #20
0
def test_capacitance_area():
    pp = ParallelPlates(3.5, 1e-3, area=10.0)
    assert pp.capacitance() == approx(309.89e-9, rel=0.001)