-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BC treatment for explicit plus a test
- Loading branch information
1 parent
f1fdf62
commit 9e276dc
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from math import isclose | ||
|
||
import pytest | ||
from firedrake import * | ||
from irksome import PEPRK, Dt, MeshConstant, TimeStepper | ||
from ufl.algorithms.ad import expand_derivatives | ||
|
||
peprks = [PEPRK(*x) for x in ((4, 2, 5), (5, 2, 6))] | ||
|
||
|
||
@pytest.mark.parametrize("butcher_tableau", peprks) | ||
def test_1d_heat_dirichletbc(butcher_tableau): | ||
# Boundary values | ||
u_0 = Constant(2.0) | ||
u_1 = Constant(3.0) | ||
|
||
N = 10 | ||
x0 = 0.0 | ||
x1 = 10.0 | ||
msh = IntervalMesh(N, x1) | ||
V = FunctionSpace(msh, "CG", 1) | ||
MC = MeshConstant(msh) | ||
dt = MC.Constant(1.0 / N) | ||
t = MC.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))) | ||
+ u_0 | ||
+ ((x - x0) / x1) * (u_1 - u_0) | ||
) | ||
rhs = expand_derivatives(diff(uexact, t)) - div(grad(uexact)) | ||
u = Function(V) | ||
u.interpolate(uexact) | ||
v = TestFunction(V) | ||
F = ( | ||
inner(Dt(u), v) * dx | ||
+ inner(grad(u), grad(v)) * dx | ||
- inner(rhs, v) * dx | ||
) | ||
bc = [ | ||
DirichletBC(V, u_1, 2), | ||
DirichletBC(V, u_0, 1), | ||
] | ||
|
||
luparams = {"mat_type": "aij", "ksp_type": "preonly", "pc_type": "lu"} | ||
|
||
stepper = TimeStepper( | ||
F, butcher_tableau, t, dt, u, bcs=bc, | ||
solver_parameters=luparams, | ||
stage_type="explicit" | ||
) | ||
|
||
t_end = 2.0 | ||
while float(t) < t_end: | ||
if float(t) + float(dt) > t_end: | ||
dt.assign(t_end - float(t)) | ||
stepper.advance() | ||
t.assign(float(t) + float(dt)) | ||
# Check solution and boundary values | ||
assert errornorm(uexact, u) / norm(uexact) < 10.0 ** -3 | ||
assert isclose(u.at(x0), u_0) | ||
assert isclose(u.at(x1), u_1) |