-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: SDC python type SNES #148
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
Draft
JHopeCollins
wants to merge
2
commits into
master
Choose a base branch
from
JHopeCollins/auxiliary-snes
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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from firedrake import * | ||
| from irksome import Dt, TimeStepper, GaussLegendre | ||
|
|
||
| nx = 32 | ||
| re = 100 | ||
| dt = 0.05 | ||
| stages = 3 | ||
|
|
||
| mesh = UnitIntervalMesh(nx) | ||
| V = VectorFunctionSpace(mesh, "CG", 2) | ||
| R = FunctionSpace(mesh, "R", 0) | ||
| t = Function(R).assign(0) | ||
| dt = Function(R).assign(dt) | ||
|
|
||
| x, = SpatialCoordinate(mesh) | ||
| ic = 1 + sin(2*pi*x) | ||
|
|
||
| u = Function(V, name="u").project(as_vector([ic])) | ||
| v = TestFunction(V) | ||
|
|
||
| nu = Constant(1/re) | ||
|
|
||
| F = ( | ||
| inner(Dt(u), v)*dx | ||
| + inner(dot(u, nabla_grad(u)), v)*dx | ||
| + inner(nu*grad(u), grad(v))*dx | ||
| ) | ||
|
|
||
| zero = Constant(0) | ||
| bcs = [DirichletBC(V, as_vector([zero]), "on_boundary")] | ||
| newton_params = { | ||
| "snes_type": "newtonls", | ||
| "ksp_type": "preonly", | ||
| "pc_type": "lu", | ||
| } | ||
|
|
||
| params = { | ||
| "snes": { | ||
| "converged_reason": None, | ||
| "monitor": None, | ||
| "rtol": 1e-5, | ||
| }, | ||
| "snes_type": "python", | ||
| "snes_python_type": "irksome.SDCLDSNES", | ||
| "sdc": newton_params, | ||
| "sdc": { | ||
| "snes_type": "python", | ||
| "snes_python_type": "firedrake.FieldsplitSNES", | ||
| "snes_fieldsplit_type": "multiplicative", | ||
| "fieldsplit_0": newton_params, | ||
| "fieldsplit_1": newton_params, | ||
| "fieldsplit_2": newton_params, | ||
| } | ||
| } | ||
|
|
||
| stepper = TimeStepper( | ||
| F, GaussLegendre(3), t, dt, u, | ||
| bcs=bcs, solver_parameters=params) | ||
|
|
||
| stepper.advance() | ||
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,60 @@ | ||
| import copy | ||
| from firedrake import AuxiliaryOperatorSNES | ||
| from firedrake.dmhooks import get_appctx | ||
| from irksome.pc import ldu | ||
|
|
||
|
|
||
| class IRKAuxiliaryOperatorSNES(AuxiliaryOperatorSNES): | ||
| """Base class that inherits from Firedrake's AuxiliaryOperatorSNES class and | ||
| provides the preconditioning nonlinear form associated with an auxiliary | ||
| Form and/or approximate Butcher matrix (which are provided by subclasses). | ||
| """ | ||
|
|
||
| def getNewForm(self, snes, u0, test): | ||
| """Derived classes can optionally provide an auxiliary Form. | ||
| Must return Fnew, bcnew, unew.""" | ||
| raise NotImplementedError | ||
|
|
||
| def getAtilde(self, A): | ||
| """Derived classes produce a typically structured | ||
| approximation to A.""" | ||
| raise NotImplementedError | ||
|
|
||
| def form(self, snes, u, v): | ||
| """Implements the interface for AuxiliaryOperatorSNES.""" | ||
|
|
||
| appctx = get_appctx(snes.dm).appctx | ||
| stepper = appctx["stepper"] | ||
| butcher = stepper.butcher_tableau | ||
| F = stepper.F | ||
| u0 = stepper.u0 | ||
| bcs = stepper.orig_bcs | ||
| w = stepper.stages.copy(deepcopy=True) | ||
| v0, = F.arguments() | ||
|
|
||
| try: | ||
| # use new Form if provided | ||
| F, bcs = self.getNewForm(snes, u0, v0) | ||
| except NotImplementedError: | ||
| pass | ||
|
|
||
| try: | ||
| # use new ButcherTableau if provided | ||
| Atilde = self.getAtilde(butcher.A) | ||
| butcher = copy.deepcopy(butcher) | ||
| butcher.A = Atilde | ||
| except NotImplementedError: | ||
| pass | ||
|
|
||
| Fnew, bcnew = stepper.get_form_and_bcs(w, tableau=butcher, F=F) | ||
|
|
||
| return Fnew, bcnew, w | ||
|
|
||
|
|
||
| class SDCLDSNES(IRKAuxiliaryOperatorSNES): | ||
| """Implements SDC-type preconditioner using Atilde = DU where A=LDU. (Qdelta = Atilde)""" | ||
| prefix = "sdc_" | ||
|
|
||
| def getAtilde(self, A): | ||
| L, D, U = ldu(A) | ||
| return L @ D |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
"fieldsplit": newton_paramsjust broadcast the options into all splits? This is true for field splits inside of PC.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should do but we haven't yet implemented that in
firedrake.FieldsplitSNESyet. It isn't hard, I have a little function that does it in asQ, I just haven't gotten back to putting it in yet.