-
Notifications
You must be signed in to change notification settings - Fork 177
Rckirby/patchdemo #4317
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
Merged
Rckirby/patchdemo #4317
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c449752
cleanup, add link
rckirby 4b7f496
Add Stokes demo
rckirby ef2ed4c
few edits, add H(div) riesz map
rckirby e3d9ba6
rename demos, add demos to docs
rckirby cf715da
flake-wrangling
rckirby 11b6d90
slurp SVG and not just PNG from demos
rckirby 1bc8387
Make html build and pass tests
rckirby 1222c7e
Fix text in Hdiv riesz map
rckirby 1f27b05
Shameless self promotion
rckirby 827a6a4
H(curl) patch demo
pbrubeck 2159b99
indent
pbrubeck 1fd8f48
indent
pbrubeck d4365c7
typos
pbrubeck b1c3549
Apply suggestions from code review
pbrubeck fc08961
Fixups
pbrubeck 06d8930
Apply suggestions from code review
pbrubeck 619bf1d
Apply suggestions from code review
rckirby 4252335
merging
rckirby 6a97666
update configuration, running demos test
rckirby 503a478
lint
rckirby 2b19e3b
fix directory name
rckirby 13d6edb
merging
rckirby 3f8f0b0
Update demos/patch/stokes_vanka_patches.py.rst
pbrubeck fdeb7ff
Apply suggestions from code review
pbrubeck c28c3d4
add table
pbrubeck f070084
Update advanced_tut.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| Using patch relaxation for H(curl) | ||
| ================================== | ||
|
|
||
| Contributed by `Robert Kirby <https://sites.baylor.edu/robert_kirby/>`_ | ||
| and `Pablo Brubeck <https://www.maths.ox.ac.uk/people/pablo.brubeckmartinez/>`_. | ||
|
|
||
| Multigrid in H(div) and H(curl) also requires relaxation based on topological patches. | ||
| Here, we demonstrate how to do this in the latter case.:: | ||
|
|
||
| from firedrake import * | ||
|
|
||
| mesh = UnitCubeMesh(2, 2, 2) | ||
| mh = MeshHierarchy(mesh, 3) | ||
| mesh = mh[-1] | ||
|
|
||
| We consider the Riesz map on H(curl), discretized with lowest order | ||
| Nedelec elements. We force the system with a random right-hand side and | ||
| impose homogeneous Dirichlet boundary conditions:: | ||
|
|
||
|
|
||
| def run_solve(mesh, params): | ||
| V = FunctionSpace(mesh, "N1curl", 1) | ||
| u = TrialFunction(V) | ||
| v = TestFunction(V) | ||
| uu = Function(V) | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| a = inner(curl(u), curl(v)) * dx + inner(u, v) * dx | ||
| rg = RandomGenerator(PCG64(seed=123456789)) | ||
| L = rg.uniform(V.dual(), -1, 1) | ||
| bcs = DirichletBC(V, 0, "on_boundary") | ||
|
|
||
| problem = LinearVariationalProblem(a, L, uu, bcs) | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| solver = LinearVariationalSolver(problem, solver_parameters=params) | ||
|
|
||
| solver.solve() | ||
|
|
||
| return solver.snes.getLinearSolveIterations() | ||
|
|
||
| Having done both :class:`~.ASMStarPC` and :class:`~.PatchPC` in other demos, | ||
| here we simply opt for the former. Arnold, Falk, and Winther show that vertex | ||
| patches yield a robust method.:: | ||
|
|
||
|
|
||
| def mg_params(relax): | ||
| return { | ||
| "ksp_type": "cg", | ||
| "pc_type": "mg", | ||
| "mg_levels": { | ||
| "ksp_type": "chebyshev", | ||
| "ksp_max_it": 1, | ||
| **relax | ||
| }, | ||
| "mg_coarse": { | ||
| "ksp_type": "preonly", | ||
| "pc_type": "cholesky" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| def asm_params(construct_dim): | ||
| return { | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.ASMStarPC", | ||
| "pc_star_construct_dim": construct_dim, | ||
| "pc_star_backend_type": "tinyasm" | ||
| } | ||
|
|
||
| Hiptmair proposed a finer space decomposition for Nedelec elements using edge | ||
| patches and vertex patches on the gradient of a Lagrange space. The python type | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| preconditioner :class:`~.HiptmairPC` automatically sets up a two-level method | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using the auxiliary Lagrange space in a multigrid hierarchy. :: | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def hiptmair_params(): | ||
| return { | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.HiptmairPC", | ||
| "hiptmair_mg_levels": asm_params(1), | ||
| "hiptmair_mg_coarse": asm_params(0), | ||
| } | ||
|
|
||
|
|
||
| Now, for each parameter choice, we report the iteration count for the Riesz map | ||
| over a range of meshes. We see that the auxiliary space approach gives lower | ||
| iteration counts than vertex patches, while being cheaper to invert.:: | ||
|
|
||
| names = { | ||
| "Vertex Star": mg_params(asm_params(0)), | ||
| "Hiptmair": mg_params(hiptmair_params()), | ||
| } | ||
|
|
||
| for name, parameters in names.items(): | ||
| print(f"{name}") | ||
| print("Level | Iterations") | ||
| for lvl, msh in enumerate(mh[1:], start=1): | ||
| its = run_solve(msh, parameters) | ||
| print(f"{lvl} | {its}") | ||
|
|
||
| For vertex patches, we expect output like, | ||
|
|
||
| ======== ============ | ||
| Level Iterations | ||
| ======== ============ | ||
| 1 10 | ||
| 2 14 | ||
| 3 16 | ||
| ======== ============ | ||
|
|
||
| and with Hiptmair (edge patches + vertex patches on gradients of Lagrange) | ||
|
|
||
| ======== ============ | ||
| Level Iterations | ||
| ======== ============ | ||
| 1 10 | ||
| 2 12 | ||
| 3 13 | ||
| ======== ============ | ||
|
|
||
| and additional mesh refinement will lead to these numbers leveling off. | ||
|
|
||
| A runnable python version of this demo can be found :demo:`here<hcurl_riesz_star.py>`. | ||
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,94 @@ | ||
| Using patch relaxation for H(div) | ||
| ================================= | ||
|
|
||
| Contributed by `Robert Kirby <https://sites.baylor.edu/robert_kirby/>`_ | ||
| and `Pablo Brubeck <https://www.maths.ox.ac.uk/people/pablo.brubeckmartinez/>`_. | ||
|
|
||
| Multigrid in H(div) and H(curl) also requires relaxation based on topological patches. | ||
| Here, we demonstrate how to do this in the former case.:: | ||
|
|
||
| from firedrake import * | ||
|
|
||
| mesh = UnitCubeMesh(2, 2, 2) | ||
| mh = MeshHierarchy(mesh, 3) | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mesh = mh[-1] | ||
|
|
||
| We consider the Riesz map on H(div), discretized with lowest order | ||
| Raviart--Thomas elements. We force the system with a random right-hand side and | ||
| impose homogeneous Dirichlet boundary conditions:: | ||
|
|
||
|
|
||
| def run_solve(mesh, params): | ||
| V = FunctionSpace(mesh, "RT", 1) | ||
| u = TrialFunction(V) | ||
| v = TestFunction(V) | ||
| uu = Function(V) | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| a = inner(div(u), div(v)) * dx + inner(u, v) * dx | ||
| rg = RandomGenerator(PCG64(seed=123456789)) | ||
| L = rg.uniform(V.dual(), -1, 1) | ||
| bcs = DirichletBC(V, 0, "on_boundary") | ||
|
|
||
| problem = LinearVariationalProblem(a, L, uu, bcs) | ||
pbrubeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| solver = LinearVariationalSolver(problem, solver_parameters=params) | ||
|
|
||
| solver.solve() | ||
|
|
||
| return solver.snes.getLinearSolveIterations() | ||
|
|
||
| Having done both :class:`~.ASMStarPC` and :class:`~.PatchPC` in other demos, here we simply opt for the former. | ||
| Arnold, Falk, and Winther show that either vertex (`construct_dim=0`) or edge patches (`construct_dim=1`) will be acceptable in three dimensions.:: | ||
|
|
||
|
|
||
| def asm_params(construct_dim): | ||
| return { | ||
| "ksp_type": "cg", | ||
| "pc_type": "mg", | ||
| "mg_levels": { | ||
| "ksp_type": "chebyshev", | ||
| "ksp_max_it": 1, | ||
| "pc_type": "python", | ||
| "pc_python_type": "firedrake.ASMStarPC", | ||
| "pc_star_construct_dim": construct_dim, | ||
| "pc_star_backend_type": "tinyasm" | ||
| }, | ||
| "mg_coarse": { | ||
| "ksp_type": "preonly", | ||
| "pc_type": "cholesky", | ||
| } | ||
| } | ||
|
|
||
| Now, for each parameter choice, we report the iteration count for the Riesz map | ||
| over a range of meshes. We see that vertex patches give lower iteration counts than | ||
| edge patches, but they are more expensive.:: | ||
|
|
||
|
|
||
| for cdim in (0, 1): | ||
| print(f"Relaxation with patches of dimension {cdim}") | ||
| print("Level | Iterations") | ||
| for lvl, msh in enumerate(mh[1:], start=1): | ||
| its = run_solve(msh, asm_params(cdim)) | ||
| print(f"{lvl} | {its}") | ||
|
|
||
| For vertex patches, we expect output like, | ||
|
|
||
| ======== ============ | ||
| Level Iterations | ||
| ======== ============ | ||
| 1 9 | ||
| 2 10 | ||
| 3 13 | ||
| ======== ============ | ||
|
|
||
| and with edge patches | ||
|
|
||
| ======== ============ | ||
| Level Iterations | ||
| ======== ============ | ||
| 1 25 | ||
| 2 29 | ||
| 3 32 | ||
| ======== ============ | ||
|
|
||
| and additional mesh refinement will lead to these numbers leveling off. | ||
|
|
||
| A runnable python version of this demo can be found :demo:`here<hdiv_riesz_star.py>`. | ||
Oops, something went wrong.
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.