-
Notifications
You must be signed in to change notification settings - Fork 17
Lag label #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lag label #228
Changes from 7 commits
994168c
d46e35e
28dcbaa
77afdaa
15b9062
872e12d
bee0155
1e20358
402b2de
33095e6
6148e8f
d4830af
9fe42ba
bae1950
126f9f3
19bf4e0
3048a2b
110b070
9b22b40
d894deb
34e6077
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| from ufl.algorithms.apply_algebra_lowering import apply_algebra_lowering | ||
| from ufl.form import BaseForm | ||
| from ufl.classes import (Coefficient, Conj, Curl, ConstantValue, Derivative, | ||
| Div, Expr, Grad, Indexed, ReferenceGrad, | ||
| Div, Expr, Grad, Indexed, Label, ReferenceGrad, | ||
| ReferenceValue, SpatialCoordinate, Variable) | ||
| from ufl.corealg.multifunction import MultiFunction | ||
|
|
||
|
|
@@ -85,6 +85,17 @@ def Dt(f, order=1): | |
| return f | ||
|
|
||
|
|
||
| # A :class:`ufl.Label` to mark nodes that are only evaluated at the start of | ||
| # the timestep. | ||
| lag_label = Label() | ||
|
|
||
|
|
||
| def lag(expr): | ||
| """Mark a sub-expression to be evaluated only at the start of the | ||
| timestep during the implicit solve.""" | ||
| return Variable(expr, lag_label) | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file does not seem the right place to define this. I think we should be creating a new file.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I put in a new file under the |
||
| class TimeDerivativeRuleset(GenericDerivativeRuleset): | ||
| """Apply AD rules to time derivative expressions.""" | ||
| def __init__(self, t=None, timedep_coeffs=None): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import firedrake | ||
| from firedrake import Constant, inner, grad, dx, conditional | ||
| import irksome | ||
| from irksome import Dt, lag | ||
|
|
||
|
|
||
| def test_stefan_implicit(): | ||
| """Test lagging the conductivity on the Stefan problem""" | ||
| nx = 32 | ||
| mesh = firedrake.UnitIntervalMesh(nx) | ||
| V = firedrake.FunctionSpace(mesh, "CG", 1) | ||
| x, = firedrake.SpatialCoordinate(mesh) | ||
|
|
||
| u = firedrake.Function(V) | ||
| u.interpolate(1 - 2 * x) | ||
|
|
||
| k_solid = Constant(2.0) | ||
| k_liquid = Constant(1.0) | ||
| k = lag(conditional(u < 0, k_solid, k_liquid)) | ||
|
|
||
| v = firedrake.TestFunction(V) | ||
| F = (Dt(u) * v + k * inner(grad(u), grad(v))) * dx | ||
|
|
||
| T_1 = Constant(1.0) | ||
| T_2 = Constant(-1.0) | ||
| bcs = [firedrake.DirichletBC(V, T_1, 1), firedrake.DirichletBC(V, T_2, 2)] | ||
|
|
||
| t = Constant(0.0) | ||
| dt = Constant(0.1) | ||
| solver_params = {"snes_type": "newtonls", "snes_converged_reason": None} | ||
| params = {"bcs": bcs, "solver_parameters": solver_params} | ||
| method = irksome.BackwardEuler() | ||
| stepper = irksome.TimeStepper(F, method, t, dt, u, **params) | ||
|
|
||
|
pbrubeck marked this conversation as resolved.
|
||
| final_time = 10.0 | ||
| num_steps = int(final_time / float(dt)) | ||
| for step in range(num_steps): | ||
| stepper.advance() | ||
|
pbrubeck marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.