Пример #1
0
def test_GaussLegendre():
    bt = GaussLegendre(2)
    A = array([[1 / 4, 1 / 4 - sqrt(3) / 6], [1 / 4 + sqrt(3) / 6, 1 / 4]])
    b = array([1 / 2, 1 / 2])
    # btilde = array([1 / 2 + sqrt(3) / 6, 1 / 2 - sqrt(3) / 6])
    c = array([1 / 2 - sqrt(3) / 6, 1 / 2 + sqrt(3) / (6)])
    # assert allclose(btilde, bt.btilde)
    for (X, Y) in zip([A, b, c], [bt.A, bt.b, bt.c]):
        assert allclose(X, Y)
Пример #2
0
def test_appctx():
    msh = UnitIntervalMesh(2)
    V = FunctionSpace(msh, "CG", 1)
    u = Function(V)
    v = TestFunction(V)

    F = inner(Dt(u) + u, v) * dx

    bt = GaussLegendre(1)
    t = Constant(0.0)
    dt = Constant(0.1)

    stepper = TimeStepper(F, bt, t, dt, u, appctx={"hello": "world"})
    assert "hello" in stepper.solver._ctx.appctx
Пример #3
0
def heat(n, deg, time_stages, stage_type="deriv", splitting=IA):
    N = 2**n
    msh = UnitIntervalMesh(N)

    params = {
        "snes_type": "ksponly",
        "ksp_type": "preonly",
        "mat_type": "aij",
        "pc_type": "lu"
    }

    V = FunctionSpace(msh, "CG", deg)
    x, = SpatialCoordinate(msh)

    t = Constant(0.0)
    dt = Constant(2.0 / N)

    uexact = exp(-t) * sin(pi * x)
    rhs = expand_derivatives(diff(uexact, t)) - div(grad(uexact))

    butcher_tableau = GaussLegendre(time_stages)

    u = project(uexact, V)

    v = TestFunction(V)

    F = (inner(Dt(u), v) * dx + inner(grad(u), grad(v)) * dx -
         inner(rhs, v) * dx)

    bc = DirichletBC(V, Constant(0), "on_boundary")

    stepper = TimeStepper(F,
                          butcher_tableau,
                          t,
                          dt,
                          u,
                          bcs=bc,
                          solver_parameters=params,
                          stage_type=stage_type,
                          splitting=splitting)

    while (float(t) < 1.0):
        if (float(t) + float(dt) > 1.0):
            dt.assign(1.0 - float(t))
        stepper.advance()
        t.assign(float(t) + float(dt))

    return errornorm(uexact, u) / norm(uexact)
Пример #4
0
import pytest
from firedrake import *
from math import isclose
from irksome import LobattoIIIA, GaussLegendre, Dt, TimeStepper
from ufl.algorithms.ad import expand_derivatives


@pytest.mark.parametrize("butcher_tableau", [GaussLegendre(3), LobattoIIIA(2)])
def test_1d_heat_dirichletbc(butcher_tableau):

    # Boundary values
    u_0 = Constant(2.0)
    u_1 = Constant(3.0)

    N = 100
    x0 = 0.0
    x1 = 10.0
    msh = IntervalMesh(N, x1)
    V = FunctionSpace(msh, "CG", 1)
    dt = Constant(10.0 / N)
    t = Constant(0.0)
    (x,) = SpatialCoordinate(msh)

    # Method of manufactured solutions copied from Heat equation demo.
    S = Constant(2.0)
    C = Constant(1000.0)
    B = (x - Constant(x0)) * (x - Constant(x1)) / C
    R = (x * x) ** 0.5
    # Note end linear contribution
    uexact = (
        B * atan(t) * (pi / 2.0 - atan(S * (R - t)))
Пример #5
0
def test_inhomog_bc(deg, N, time_stages):
    error = heat_inhomog(N, deg, GaussLegendre(time_stages))
    assert abs(error) < 1e-10
Пример #6
0
def test_wave_eq(deg, N, time_stages, splitting):
    energy = wave(N, deg, GaussLegendre(time_stages), splitting)
    print(energy)
    assert np.allclose(energy[1:], energy[:-1])
Пример #7
0
def test_subdomainbc(deg, N, time_stages, splitting):
    error = heat_subdomainbc(N, deg, GaussLegendre(time_stages), splitting)
    assert abs(error) < 1e-10
Пример #8
0
def test_bc(time_stages, splitting):
    assert elastodynamics(4, 1, GaussLegendre(time_stages), splitting)
Пример #9
0
def test_curl(deg, N, time_stages, splitting):
    error = curltest(N, deg, GaussLegendre(time_stages), AI)
    assert abs(error) < 1e-10
Пример #10
0
def test_RTCF(deg, N, time_stages, splitting):
    error = RTCFtest(N, deg, GaussLegendre(time_stages), splitting)
    assert abs(error) < 1e-10
Пример #11
0
from firedrake import *  # noqa: F403
from irksome import GaussLegendre, getForm, Dt, TimeStepper
import numpy

ButcherTableau = GaussLegendre(1)

# Corners of the box.
x0 = 0.0
x1 = 2.2
y0 = 0.0
y1 = 0.41

#Mesh
stepfile = "circle.step"
# Close to what Turek's time-dependent benchmark has on coarsest mesh
h = 0.1
order = 2
lvl = 3
mh = OpenCascadeMeshHierarchy(stepfile,
                              element_size=h,
                              levels=lvl,
                              order=order,
                              cache=False,
                              verbose=True)

#Space
msh = mh[-1]

V = VectorFunctionSpace(msh, "CG", 4)
W = FunctionSpace(msh, "DG", 3)
Z = V * W