-
Notifications
You must be signed in to change notification settings - Fork 189
Fix _SNESContext.options_prefix #5092
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
+111
−44
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
386538f
Fix _SNESContext.options_prefix
pbrubeck 2604786
review suggestions
pbrubeck 285db1f
different options_prefix for mg_levels
pbrubeck 3255d59
Merge branch 'release' into pbrubeck/fix/options-prefix
pbrubeck 8d22ff2
add a test
pbrubeck e7bd324
review suggestions
pbrubeck d676711
conflict
pbrubeck 7d4287a
Apply suggestion from @pbrubeck
pbrubeck 76a6e55
Update firedrake/solving_utils.py
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
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,69 @@ | ||
| from firedrake import * | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("named", [False, True], ids=["unnamed", "named"]) | ||
| def test_fieldsplit_mg_options_prefix(named): | ||
| if named: | ||
| names = ("V1", "V2") | ||
| else: | ||
| names = (None, None) | ||
| refine = 2 | ||
| base = UnitIntervalMesh(10) | ||
| mh = MeshHierarchy(base, refine) | ||
| mesh = mh[-1] | ||
| V1 = FunctionSpace(mesh, 'CG', 1, name=names[0]) | ||
| V2 = FunctionSpace(mesh, 'CG', 2, name=names[1]) | ||
| W = MixedFunctionSpace([V1, V2]) | ||
| params0 = { | ||
| "pc_type": "mg", | ||
| "mg_levels_ksp_type": "chebyshev", | ||
| "mg_levels_pc_type": "jacobi", | ||
| "mg_coarse_mat_type": "aij", | ||
| "mg_coarse_ksp_type": "preonly", | ||
| "mg_coarse_pc_type": "lu", | ||
| } | ||
| params1 = { | ||
| "pc_type": "mg", | ||
| "mg_levels_ksp_type": "chebyshev", | ||
| "mg_levels_pc_type": "jacobi", | ||
| "mg_levels_0_mat_type": "aij", | ||
| "mg_levels_0_ksp_type": "preonly", | ||
| "mg_levels_0_pc_type": "lu", | ||
| } | ||
| sp = { | ||
| "mat_type": "matfree", | ||
| "ksp_rtol": 1E-12, | ||
| "ksp_max_it": 12, | ||
| "ksp_type": "cg", | ||
| "pc_type": "fieldsplit", | ||
| "pc_fieldsplit_type": "additive", | ||
| "fieldsplit_ksp_type": "preonly", | ||
| f"fieldsplit_{names[0] or 0}": params0, | ||
| f"fieldsplit_{names[1] or 1}": params1, | ||
| } | ||
|
|
||
| x = SpatialCoordinate(mesh) | ||
| z_exact = as_vector([x[0], x[0]**2]) | ||
| z = Function(W) | ||
| w = TrialFunction(W) | ||
| v = TestFunction(W) | ||
| a = inner(grad(w), grad(v)) * dx | ||
| L = a(v, z_exact) | ||
| bcs = [DirichletBC(W.sub(i), z_exact[i], "on_boundary") for i in range(len(W))] | ||
| problem = LinearVariationalProblem(a, L, z, bcs=bcs) | ||
| solver = LinearVariationalSolver(problem, solver_parameters=sp) | ||
| solver.solve() | ||
| assert errornorm(z_exact, z) / norm(z_exact) < 1E-12 | ||
|
|
||
| assert solver.snes.ksp.pc.getOperators()[0].getType() == "python" | ||
| fsplit = solver.snes.ksp.pc.getFieldSplitSubKSP() | ||
| assert len(fsplit) == len(W) | ||
| for ksp in fsplit: | ||
| coarse = ksp.pc.getMGSmoother(0) | ||
| assert coarse.pc.getType() == "lu" | ||
| assert coarse.getOperators()[0].getType().endswith("aij") | ||
| for l in range(1, len(mh)): | ||
| level = ksp.pc.getMGSmoother(l) | ||
| assert level.pc.getType() == "jacobi" | ||
| assert level.getOperators()[0].getType() == "python" |
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.