Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def eig_slepc(AA, BB, **kwargs):
'''Slepc solver'''
assert has_slepc4py()
from slepc4py import SLEPc
nev = 3 # Number of eigenvalues
eigenvalues = np.array([])
size = AA.size[0]
info('System size: %i' % size)
eps_type = kwargs.get('eps_type', SLEPc.EPS.Type.GD)
for which in (SLEPc.EPS.Which.SMALLEST_MAGNITUDE, SLEPc.EPS.Which.LARGEST_MAGNITUDE):
# Setup the eigensolver
E = SLEPc.EPS().create()
E.setOperators(AA ,BB)
E.setType(E.Type.GD)
E.setDimensions(nev, PETSc.DECIDE)
E.setTolerances(1E-6, 8000)
E.setWhichEigenpairs(which)
E.setProblemType(SLEPc.EPS.ProblemType.GHEP)
E.setFromOptions()
# Solve the eigensystem
E.solve()
its = E.getIterationNumber()
elif value == "subspace":
self.eps.setType(SLEPc.EPS.Type.SUBSPACE)
elif value == "arnoldi":
self.eps.setType(SLEPc.EPS.Type.ARNOLDI)
elif value == "lanczos":
self.eps.setType(SLEPc.EPS.Type.LANCZOS)
elif value == "krylov-schur":
self.eps.setType(SLEPc.EPS.Type.KRYLOVSCHUR)
elif value == "lapack":
self.eps.setType(SLEPc.EPS.Type.LAPACK)
elif value == "arpack":
self.eps.setType(SLEPc.EPS.Type.ARPACK)
elif value == "jacobi-davidson":
self.eps.setType(SLEPc.EPS.Type.JD)
elif value == "generalized-davidson":
self.eps.setType(SLEPc.EPS.Type.GD)
else:
raise RuntimeError("Invalid solver type")
elif key == "spectral_shift":
st = self.eps.getST()
st.setShift(value)
elif key == "spectral_transform":
assert value == "shift-and-invert"
st = self.eps.getST()
st.setType(SLEPc.ST.Type.SINVERT)
elif key == "spectrum":
if value == "largest magnitude":
self.eps.setWhichEigenpairs(SLEPc.EPS.Which.LARGEST_MAGNITUDE)
elif value == "smallest magnitude":
self.eps.setWhichEigenpairs(SLEPc.EPS.Which.SMALLEST_MAGNITUDE)
elif value == "largest real":
self.eps.setWhichEigenpairs(SLEPc.EPS.Which.LARGEST_REAL)