-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make firedrake-ts usable with the current firedrake * make _TSContext as a subclass of _SNESContext to reduce some code duplications * deal with the new notion of cofunction in UFL/firedrake * modify some examples to run * bump firedrake-ts to version 0.2
- Loading branch information
1 parent
9c0cad5
commit 1186966
Showing
7 changed files
with
156 additions
and
362 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
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 |
---|---|---|
@@ -1,28 +1,35 @@ | ||
from firedrake import * | ||
import firedrake_ts | ||
from firedrake.__future__ import interpolate | ||
|
||
mesh = UnitIntervalMesh(11) | ||
mesh = UnitIntervalMesh(10) | ||
V = FunctionSpace(mesh, "P", 1) | ||
|
||
u = Function(V) | ||
u_t = Function(V) | ||
v = TestFunction(V) | ||
|
||
# F(u̇, u, t) = G(u, t) | ||
# F(u_t, u, t) = G(u, t) | ||
F = inner(u_t, v) * dx | ||
G = -(inner(grad(u), grad(v)) * dx - 1.0 * v * dx) | ||
|
||
bc = DirichletBC(V, 0.0, "on_boundary") | ||
bc1 = DirichletBC(V, 1.0, 1) | ||
bc2 = DirichletBC(V, 0.0, 2) | ||
bcs=[bc1, bc2] | ||
|
||
x = SpatialCoordinate(mesh) | ||
bump = conditional(lt(abs(x[0] - 0.5), 0.1), 1.0, 0.0) | ||
u.interpolate(bump) | ||
bump = conditional(lt(x[0], 0.5), 1.0, 0.0) | ||
assemble(interpolate(bump, u), tensor=u) | ||
print(f'{u.dat.data}=') | ||
|
||
problem = firedrake_ts.DAEProblem(F, u, u_t, (0.0, 1.0), bcs=bc, G=G) | ||
solver = firedrake_ts.DAESolver(problem) | ||
|
||
def monitor(ts, step, t, x): | ||
print(f'{solver.ts.getTime()=}') | ||
print(f'{u.dat.data}=') | ||
|
||
problem = firedrake_ts.DAEProblem(F, u, u_t, (0.0, 0.4), bcs=bcs, G=G) | ||
|
||
solver = firedrake_ts.DAESolver(problem, options_prefix='', monitor_callback=monitor) | ||
|
||
solver.solve() | ||
|
||
print(solver.ts.getTime()) | ||
# solver.ts.view() | ||
print(u.dat.data) |
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
Oops, something went wrong.