-
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
Open
danshapero
wants to merge
16
commits into
firedrakeproject:master
Choose a base branch
from
danshapero:lag-label
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−4
Open
Lag label #228
Changes from 5 commits
Commits
Show all changes
16 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 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
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 |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
|
|
||
|
Comment on lines
+88
to
+98
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. |
||
| class TimeDerivativeRuleset(GenericDerivativeRuleset): | ||
| """Apply AD rules to time derivative expressions.""" | ||
| def __init__(self, t=None, timedep_coeffs=None): | ||
|
|
||
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,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) | ||
|
|
||
| final_time = 10.0 | ||
| num_steps = int(final_time / float(dt)) | ||
| for step in range(num_steps): | ||
| stepper.advance() | ||
|
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. Can we add an assertion here? |
||
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.