-
Notifications
You must be signed in to change notification settings - Fork 17
Mass-conservative update for non-stiffly-accurate stage_value #226
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
sghelichkhani
wants to merge
12
commits into
firedrakeproject:master
Choose a base branch
from
sghelichkhani:sghelichkhani/conservative-update-non-sa
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.
+199
−27
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac344d5
Mass-conservative update for non-stiffly-accurate stage_value
sghelichkhani f2ac418
Updating solver vlaues for testing
sghelichkhani b203d17
Merge branch 'master' into sghelichkhani/conservative-update-non-sa
sghelichkhani dc1d072
Drop DIRK and collocation-update refusal for composite Dt
sghelichkhani 5a54f50
Test reorg: extend test_mass_conservation, isolate classifier test
sghelichkhani fb28b88
Address review: rename, simplify update head, tighten comments
sghelichkhani af058db
Lint fixes: drop unused firedrake imports, remove dict alignment spaces
sghelichkhani 68de837
Replace nonlinear-Dt classifier with ufl.derivative probe
sghelichkhani 539b8aa
Update solver: hard-coded SPD default, no inheritance from stages
sghelichkhani ecea8fe
Apply suggestions from code review
sghelichkhani 05e0d8e
Drop hard-coded update solver default, defer to Firedrake's
sghelichkhani 4a3315a
Lint: drop now-unused Grad and Div imports
sghelichkhani 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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """Classification contract for ``has_nonlinear_time_derivative``. | ||
|
|
||
| The helper is what routes stage_value between the existing | ||
| linear-combination update (``_update_Ainv``) and the new conservative | ||
| variational update. Misclassification has two failure modes: | ||
|
|
||
| * False negative on a nonlinear ``Dt(g(u))`` would silently drop the form | ||
| back onto the linear-combination update and lose mass conservation for | ||
| non-stiffly-accurate tableaux. | ||
|
|
||
| * False positive on a linear ``Dt(c*u)`` or ``Dt(u + f(t))`` would route | ||
| the form through the conservative variational head, which has no | ||
| algebraic block and breaks DAEs. | ||
|
|
||
| Pin both directions of the contract here so a future change to the | ||
| walker cannot quietly regress either case. | ||
| """ | ||
| import pytest | ||
| from firedrake import ( | ||
| Constant, Function, FunctionSpace, TestFunction, | ||
| UnitIntervalMesh, dx, exp, inner, | ||
| ) | ||
| from ufl import sin | ||
|
|
||
| from irksome import Dt | ||
| from irksome.ufl.manipulation import has_nonlinear_time_derivative | ||
|
|
||
|
|
||
| def _theta(h, theta_r=Constant(0.15), theta_s=Constant(0.45), | ||
| alpha=Constant(0.328)): | ||
| """Exponential soil moisture, the canonical nonlinear g(h) we care about.""" | ||
| return theta_r + (theta_s - theta_r) * exp(alpha * h) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def setup(): | ||
| mesh = UnitIntervalMesh(4) | ||
| V = FunctionSpace(mesh, "CG", 1) | ||
| return V, Function(V), TestFunction(V), Constant(0.0) | ||
|
|
||
|
|
||
| def test_linear_arithmetic_is_not_flagged(setup): | ||
| """Constant-coefficient scalings of u and additive time forcings must | ||
| not be flagged. These are linear in u; ``_update_Ainv`` is correct | ||
| for them and is also the path that handles DAE structure.""" | ||
| V, u, v, t = setup | ||
| forms = { | ||
| "Dt(2*u)": Dt(Constant(2.0) * u), | ||
| "Dt(u/2)": Dt(u / Constant(2.0)), | ||
| "Dt(u + sin(t))": Dt(u + sin(t)), | ||
| "Dt(2*u + 3)": Dt(Constant(2.0) * u + Constant(3.0)), | ||
| } | ||
| for name, expr in forms.items(): | ||
| F = inner(expr, v) * dx | ||
| assert not has_nonlinear_time_derivative(F, u), ( | ||
| f"{name} was incorrectly flagged as nonlinear -- the linear " | ||
| "stage_value path would be skipped, breaking DAEs." | ||
| ) | ||
|
|
||
|
|
||
| def test_nonlinear_is_flagged(setup): | ||
| """Genuinely nonlinear g(u) inside Dt must be flagged so that | ||
| stage_value routes through the conservative variational update.""" | ||
| V, u, v, t = setup | ||
| nonlinear = { | ||
| "Dt(u*u)": Dt(u * u), | ||
| "Dt(theta(u))": Dt(_theta(u)), | ||
| "Dt(1/u)": Dt(Constant(1.0) / u), | ||
| } | ||
| for name, expr in nonlinear.items(): | ||
| F = inner(expr, v) * dx | ||
| assert has_nonlinear_time_derivative(F, u), ( | ||
| f"{name} was missed -- this would silently produce a " | ||
| "non-conservative discretisation for non-SA stage_value." | ||
| ) |
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
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.