dolfinx.fem.petsc.LinearProblem for nest and block systems - #3684
Merged
Conversation
Co-authored-by: Michal Habera <michal.habera@gmail.com>
…function for extracting Jacobians
…of `solve`. Let the user do this with the Problem-class function replace solution. Also expose the petsc objects in the solver through properties
francesco-ballarin
approved these changes
Jun 13, 2025
jorgensd
enabled auto-merge
June 13, 2025 10:24
jhale
disabled auto-merge
June 14, 2025 19:56
4 tasks
ordinary-slim
pushed a commit
to ordinary-slim/dolfinx
that referenced
this pull request
Jul 6, 2025
…3684) * Add snes solver * Replace monolitic snes from test * Add nate to copyright * Add snes solvers for blocked problems * Add nest snes solver * Ruff formatting * Shorten description * Add preconditioner property * Apply suggestions from code review * Improve documentation to address reviewer comments * Fix documentation * Typo * Apply suggestions from code review * Unify docs * Ruff * Improve documentation of blocked problem. * Remove communicator from snesproblem * Move petsc imports into tests to avoid failure when petsc is not installed * Update naming scheme * Apply Michals suggestions Co-authored-by: Michal Habera <michal.habera@gmail.com> * Use typing protocol to remove inheritance as well as adding a helper function for extracting Jacobians * Add francesco's comments * Unify snes solver into one * Ruff formatting * Ruff + mypy * Remove error if not converged * Do not update the variable `u` used in the variational forms as part of `solve`. Let the user do this with the Problem-class function replace solution. Also expose the petsc objects in the solver through properties * Start prototyping functional interface * Make solvers work * Remove nonexistent classes * Ruff formatting * mypy + ruff * Fix import * Use public members * Remove snesproblem def * Add note * Fully functional * Remove protocol * Move import * Add docstrings * Use functools partial * Remove update solution * Move snes options to constructor * Rename data structures * Rename again * Rename * Move dfx.fem.Function<->PETSc.Vec methods to dolfinx.fem.petsc * Add example of direct usage with snes * Stricter tolerance * Set tolerance depending on eps * Ruff format * Insert initial guess for hand written solver * Move assembly type into dolfinx.fem.petsc * Rename "default"->"standard". Switch order in Vec->Function * Add prefix for snes options * Apply suggestions from code review * Add full type hints * default->standard for residual and jacobian helper function * Make _create_snes_matrices_and_vectors private * Update python/dolfinx/fem/petsc.py Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk> * Apply suggestions from code review * More minor updates to adhere to reviewer comments * Merge main into snes solver. Add required ghost updates within F and J computations * Fix typehint * Update typesetting of singleton assemble_jacobian * Use try-except instead of if-else * Proposal for supporting blocked problems (not nest) in `LinearProblem`. * Add asserts for typehinting to demos * Add kind as input argument and allow for nest * Use same logic for both blocked and non-blocked problems * Test all use-cases * Centralize ghostupdate function * Simplify vector creation * add element dtypes * Ruff formatting * Use realtype * Use inner * Add kind which is nested list of types * Make ghostupdate private * Ruff format comment and add Preconditioner input to `LinearProblem` * Ruff format * Add entity maps as optional input to snessolver * Fix check * Various import cleanups * Remove unused code. * Unify assemble_residual (FEniCS#3682) * Unify assemble_residual * Ruff format * Fix imports * Add back comma * Move assignment of block data out of assembler * Ignore type-hints * Switch order of operations * Ruff format * Add entity maps * Introduce major API changes and deprecations. * Improve documentation messages on deprecation. * Refactor in progress, tests not passing yet. * Update python/dolfinx/nls/petsc.py Co-authored-by: Jørgen Schartum Dokken <dokken92@gmail.com> * Update python/dolfinx/fem/petsc.py Co-authored-by: Jørgen Schartum Dokken <dokken92@gmail.com> * Fix tests. * Fix test * Fix Cahn-Hilliard - move to new NonlinearProblem class? * Fix ruff. * Refactor compute_jacobian * Ruff format. * Update petsc.py * Illustrate usage of LinearProblem with blocked matrices * Fix import * Consistency with LinearProblem class. * A few extra comments in test. * Consistency petsc_options with LinearProblem * Disable test * Use sequence consistently. * More specific. * Tidy up. * Loosen typing. * Leave that unknown * Fix typing. * More typing fixes. * Fixup comments and typing. * Remove duplicate classes --------- Co-authored-by: Michal Habera <michal.habera@gmail.com> Co-authored-by: Jack S. Hale <mail@jackhale.co.uk> Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With the unification of
create_*,assemble_*andassignfor various PETSc operators, I suggest we letLinearProblemsupport non-blocked and blocked problems, i.e.For now, I've chosen to force the user to specify
ufor blocked problems, as it is hard extract the correct function spaces (dolfinx.fem.FunctionSpace, python class) from the nested list of forms with the current functions (extract_function_spaceswork on the C++ function-spaces).This also introduces an immediate solution vector
_x, in the same fashion as within the proposed SNES solver.It also adds the option of sending in a preconditioner to LinearProblem, as a
ufl.Formor a nested sequence of Forms, which is then set to the krylov-solver.