Exemplo n.º 1
0
def test_temporal_convergence():
    """Take a very small mesh, reduce timestep, expect 2nd order
    convergence."""
    v_errors = []
    u_errors = []
    dts = []
    hs = []
    T = 1.0
    dt = 1.0
    theta = 0.5
    N = 50
    for level in (0, 1, 2, 3):
        a = dt / (2**level)
        (v_error, u_error, h, a, T) = main(N, a, T, theta)
        v_errors.append(v_error)
        u_errors.append(u_error)
        dts.append(a)
        hs.append(h)

    v_rates = convergence_rate(dts, v_errors)
    u_rates = convergence_rate(dts, u_errors)
    print("v_errors = ", v_errors)
    print("u_errors = ", u_errors)
    print("v_rates = ", v_rates)
    print("u_rates = ", u_rates)

    assert v_rates[-1] > 1.95, "Failed convergence for v"
Exemplo n.º 2
0
def test_spatial_and_temporal_convergence():
    v_errors = []
    u_errors = []
    dts = []
    hs = []
    T = 0.5
    dt = 0.05
    theta = 0.5
    N = 5
    for level in (0, 1, 2, 3):
        a = dt / (2**level)
        (v_error, u_error, h, a, T) = main(N * (2**level), a, T, theta)
        v_errors.append(v_error)
        u_errors.append(u_error)
        dts.append(a)
        hs.append(h)

    v_rates = convergence_rate(hs, v_errors)
    u_rates = convergence_rate(hs, u_errors)
    print("v_errors = ", v_errors)
    print("u_errors = ", u_errors)
    print("v_rates = ", v_rates)
    print("u_rates = ", u_rates)

    assert v_rates[-1] > 1.95, "Failed convergence for v"
    assert u_rates[-1] > 1.9, "Failed convergence for u"
Exemplo n.º 3
0
def test_spatial_and_temporal_convergence():
    "Test convergence rates for bidomain solver."
    v_errors = []
    u_errors = []
    dts = []
    hs = []
    T = 0.1
    dt = 0.01
    theta = 0.5
    N = 10
    for level in (0, 1, 2):
        a = dt/(2**level)
        (v_error, u_error, h, a, T) = main(N*(2**level), a, T, theta)
        v_errors.append(v_error)
        u_errors.append(u_error)
        dts.append(a)
        hs.append(h)

    v_rates = convergence_rate(hs, v_errors)
    u_rates = convergence_rate(hs, u_errors)
    print(("v_errors = ", v_errors))
    print(("u_errors = ", u_errors))
    print(("v_rates = ", v_rates))
    print(("u_rates = ", u_rates))

    assert all(v > 1.9 for v in v_rates), "Failed convergence for v"
    assert all(u > 1.9 for u in u_rates), "Failed convergence for u"
Exemplo n.º 4
0
def test_temporal_convergence():
    """Take a small mesh, reduce timestep size, expect 2nd order convergence."""
    v_errors = []
    u_errors = []
    dts = []
    dt = 1.0
    T = 1.0
    N = 150
    for level in (0, 1, 2, 3):
        a = dt / (2**level)
        v_error, u_error, h, a, T = main(N, a, T)
        v_errors.append(v_error)
        u_errors.append(u_error)
        dts.append(a)

    v_rates = convergence_rate(dts, v_errors)
    u_rates = convergence_rate(dts, u_errors)
    print("v_errors = ", v_errors)
    print("u_errors = ", u_errors)
    print("v_rates = ", v_rates)
    print("u_rates = ", u_rates)

    assert v_rates[-1] > 1.95, "Failed convergence for v"
    # Increase spatial resolution to get better temporal convergence for u
    assert u_rates[-1] > 1.78, "Failed convergence for u"
Exemplo n.º 5
0
def test_spatial_convergence():
    """Take a very small timestep, reduce mesh size, expect 2nd order convergence."""
    v_errors = []
    u_errors = []
    hs = []
    dt = 0.01
    T = 1.0
    for N in (5, 10, 20, 40):
        v_error, u_error, h, dt_, T = main(N, dt, T)
        v_errors.append(v_error)
        u_errors.append(u_error)
        hs.append(h)

    v_rates = convergence_rate(hs, v_errors)
    u_rates = convergence_rate(hs, u_errors)
    print("dt, T = ", dt, T)
    print("v_errors = ", v_errors)
    print("u_errors = ", u_errors)
    print("v_rates = ", v_rates)
    print("u_rates = ", u_rates)

    assert all(v > 1.9 for v in v_rates), "Failed convergence for v"
    assert all(u > 1.85 for u in u_rates), "Failed convergence for u"