-
Notifications
You must be signed in to change notification settings - Fork 18
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
Merged
+77
−1
Merged
Lag label #228
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
994168c
Stub out test for Stefan problem
danshapero d46e35e
Stub out lagging
danshapero 28dcbaa
Add lag label to hold back terms to start of timestep
danshapero 77afdaa
Change `irksome.tools.replace` to skip lagged terms
danshapero 15b9062
Add lag to __init__.py
danshapero 872e12d
Apply suggestions from code review
pbrubeck bee0155
Apply suggestions from code review
pbrubeck 1e20358
Apply suggestions from code review
pbrubeck 402b2de
Apply suggestion from @pbrubeck
pbrubeck 33095e6
Apply suggestions from code review
pbrubeck 6148e8f
Apply suggestions from code review
pbrubeck d4830af
Apply suggestion from @pbrubeck
pbrubeck 9fe42ba
Apply suggestion from @pbrubeck
pbrubeck bae1950
Merge branch 'master' into lag-label
pbrubeck 126f9f3
Apply suggestion from @pbrubeck
pbrubeck 19bf4e0
Merge branch 'master' into lag-label
pbrubeck 3048a2b
Add asserts + check implicit form fails in lag test
danshapero 110b070
Move lag into own file
danshapero 9b22b40
Apply suggestions from code review
pbrubeck d894deb
Apply suggestions from code review
pbrubeck 34e6077
Apply suggestion from @pbrubeck
pbrubeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| from ufl.classes import Label, Variable | ||
|
|
||
|
|
||
| # 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) |
This file contains hidden or 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,56 @@ | ||
| import pytest | ||
| import firedrake | ||
| from firedrake import Constant, inner, grad, dx, conditional, assemble | ||
| 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) | ||
| u_0 = u.copy(deepcopy=True) | ||
|
|
||
| T_1 = Constant(1.0) | ||
| T_2 = Constant(-1.0) | ||
| bcs = [firedrake.DirichletBC(V, T_1, 1), firedrake.DirichletBC(V, T_2, 2)] | ||
|
|
||
| v = firedrake.TestFunction(V) | ||
| t = Constant(0.0) | ||
| dt = Constant(0.1) | ||
| final_time = 10.0 | ||
| num_steps = int(final_time / float(dt)) | ||
| solver_params = {"snes_type": "newtonls", "snes_converged_reason": None} | ||
| params = {"bcs": bcs, "solver_parameters": solver_params} | ||
| method = irksome.BackwardEuler() | ||
|
|
||
| k_solid = Constant(2.0) | ||
| k_liquid = Constant(1.0) | ||
|
|
||
| # Check that fully implicit form fails | ||
| k = conditional(u < 0, k_solid, k_liquid) | ||
| F = (Dt(u) * v + k * inner(grad(u), grad(v))) * dx | ||
| stepper = irksome.TimeStepper(F, method, t, dt, u, **params) | ||
| with pytest.raises(firedrake.ConvergenceError): | ||
| for step in range(num_steps): | ||
| stepper.advance() | ||
|
|
||
| # Check that the lagged form works | ||
| u.assign(u_0) | ||
| F = (Dt(u) * v + lag(k) * inner(grad(u), grad(v))) * dx | ||
| stepper = irksome.TimeStepper(F, method, t, dt, u, **params) | ||
| energy = 0.5 * u**2 * dx | ||
| initial_energy = assemble(energy) | ||
|
|
||
| for step in range(num_steps): | ||
| stepper.advance() | ||
|
pbrubeck marked this conversation as resolved.
|
||
|
|
||
| final_energy = assemble(energy) | ||
| print(f"Initial energy: {initial_energy}") | ||
| print(f"Final: {final_energy}") | ||
| assert final_energy <= initial_energy | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.