-
Notifications
You must be signed in to change notification settings - Fork 193
Make EigenSolver and NonlinearVariationalSolver have an OptionsManager, not be one #5251
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,22 @@ | ||||||||||||||||||||||||||||||
| """Specify and solve finite element eigenproblems.""" | ||||||||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||||||||
| from functools import cached_property | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from petsc4py import PETSc | ||||||||||||||||||||||||||||||
| from petsctools import OptionsManager, flatten_parameters | ||||||||||||||||||||||||||||||
| from ufl import replace, inner, dx | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from firedrake.assemble import assemble | ||||||||||||||||||||||||||||||
| from firedrake.bcs import extract_subdomain_ids, restricted_function_space | ||||||||||||||||||||||||||||||
| from firedrake.exceptions import ConvergenceError | ||||||||||||||||||||||||||||||
| from firedrake.function import Function | ||||||||||||||||||||||||||||||
| from firedrake.ufl_expr import TrialFunction, TestFunction | ||||||||||||||||||||||||||||||
| from firedrake.exceptions import ConvergenceError | ||||||||||||||||||||||||||||||
| from ufl import replace, inner, dx | ||||||||||||||||||||||||||||||
| from functools import cached_property | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| from slepc4py import SLEPc | ||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||
| SLEPc = None | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| __all__ = ["LinearEigenproblem", | ||||||||||||||||||||||||||||||
| "LinearEigensolver"] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -96,7 +102,7 @@ def dm(self): | |||||||||||||||||||||||||||||
| return self.output_space.dm | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class LinearEigensolver(OptionsManager): | ||||||||||||||||||||||||||||||
| class LinearEigensolver: | ||||||||||||||||||||||||||||||
| r"""Solve a LinearEigenproblem. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||
|
|
@@ -159,8 +165,33 @@ def __init__(self, problem, n_evals, *, options_prefix=None, | |||||||||||||||||||||||||||||
| for key in self.DEFAULT_EPS_PARAMETERS: | ||||||||||||||||||||||||||||||
| value = self.DEFAULT_EPS_PARAMETERS[key] | ||||||||||||||||||||||||||||||
| solver_parameters.setdefault(key, value) | ||||||||||||||||||||||||||||||
| super().__init__(solver_parameters, options_prefix) | ||||||||||||||||||||||||||||||
| self.set_from_options(self.es) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self.options_manager = OptionsManager(solver_parameters, options_prefix) | ||||||||||||||||||||||||||||||
| self.options_manager.set_from_options(self.es) | ||||||||||||||||||||||||||||||
|
Comment on lines
+169
to
+170
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||
| def parameters(self) -> dict: | ||||||||||||||||||||||||||||||
| return self.options_manager.parameters | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||
| def options_prefix(self) -> str: | ||||||||||||||||||||||||||||||
| return self.options_manager.options_prefix | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def set_from_options(self, snes: PETSc.SNES) -> None: | ||||||||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||||||||
| "'LinearEigensolver.set_from_options' is deprecated, use " | ||||||||||||||||||||||||||||||
| "'LinearEigensolver.options_manager.set_from_options' instead", | ||||||||||||||||||||||||||||||
| FutureWarning | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| self.options_manager.set_from_options(snes) | ||||||||||||||||||||||||||||||
|
Comment on lines
+180
to
+186
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def inserted_options(self): | ||||||||||||||||||||||||||||||
| warnings.warn( | ||||||||||||||||||||||||||||||
| "'LinearEigensolver.inserted_options' is deprecated, use " | ||||||||||||||||||||||||||||||
| "'LinearEigensolver.options_manager.inserted_options' instead", | ||||||||||||||||||||||||||||||
| FutureWarning | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| return self.options_manager.inserted_options() | ||||||||||||||||||||||||||||||
|
Comment on lines
+188
to
+194
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def check_es_convergence(self): | ||||||||||||||||||||||||||||||
| r"""Check the convergence of the eigenvalue problem.""" | ||||||||||||||||||||||||||||||
|
|
@@ -193,7 +224,7 @@ def solve(self): | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| self.es.setDimensions(nev=self.n_evals, ncv=self.ncv, mpd=self.mpd) | ||||||||||||||||||||||||||||||
| self.es.setOperators(self.A_mat, self.M_mat) | ||||||||||||||||||||||||||||||
| with self.inserted_options(): | ||||||||||||||||||||||||||||||
| with self.options_manager.inserted_options(): | ||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| self.es.solve() | ||||||||||||||||||||||||||||||
| nconv = self.es.getConverged() | ||||||||||||||||||||||||||||||
| if nconv == 0: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.