Skip to content

Commit

Permalink
Add ability to specify starting eigenvector in sparse eigs
Browse files Browse the repository at this point in the history
  • Loading branch information
kburns committed Mar 18, 2024
1 parent a46c36d commit 328a4f4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dedalus/core/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def solve_dense(self, subproblem, rebuild_matrices=False, left=False, normalize_
self.eigenvalues, pre_eigenvectors = eig_output
self.eigenvectors = sp.pre_right @ pre_eigenvectors

def solve_sparse(self, subproblem, N, target, rebuild_matrices=False, left=False, normalize_left=True, raise_on_mismatch=True, **kw):
def solve_sparse(self, subproblem, N, target, rebuild_matrices=False, left=False, normalize_left=True, raise_on_mismatch=True, v0=None, **kw):
"""
Perform targeted sparse eigenvector search for selected subproblem.
This routine finds a subset of eigenvectors near the specified target.
Expand All @@ -249,6 +249,8 @@ def solve_sparse(self, subproblem, N, target, rebuild_matrices=False, left=False
eigenvectors (default: True).
raise_on_mismatch : bool, optional
Raise a RuntimeError if the left and right eigenvalues do not match (default: True).
v0 : ndarray, optional
Initial guess for eigenvector, e.g. from subsystem.gather (default: None).
**kw :
Other keyword options passed to scipy.sparse.linalg.eig.
"""
Expand All @@ -259,9 +261,11 @@ def solve_sparse(self, subproblem, N, target, rebuild_matrices=False, left=False
# Solve as sparse general eigenvalue problem
A = sp.L_min
B = - sp.M_min
# Precondition starting guess if provided
if v0 is not None:
v0 = sp.pre_right_pinv @ v0
# Solve for the right (and optionally left) eigenvectors
eig_output = scipy_sparse_eigs(A=A, B=B, left=left, N=N, target=target, matsolver=self.matsolver, **kw)

eig_output = scipy_sparse_eigs(A=A, B=B, left=left, N=N, target=target, matsolver=self.matsolver, v0=v0, **kw)
if left:
# Note: this definition of "left eigenvectors" is consistent with the documentation for scipy.linalg.eig
self.eigenvalues, pre_right_evecs, self.left_eigenvalues, pre_left_evecs = eig_output
Expand Down

0 comments on commit 328a4f4

Please sign in to comment.