Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value = wrapping.get_default_linear_solver()
if hasattr(ksp.getPC(), "setFactorSolverType"): # PETSc >= 3.9
ksp.getPC().setFactorSolverType(value)
else:
ksp.getPC().setFactorSolverPackage(value)
elif key == "maximum_iterations":
eps_tolerances[1] = value
elif key == "problem_type":
if value == "hermitian":
self.eps.setProblemType(SLEPc.EPS.ProblemType.HEP)
elif value == "non_hermitian":
self.eps.setProblemType(SLEPc.EPS.ProblemType.NHEP)
elif value == "gen_hermitian":
self.eps.setProblemType(SLEPc.EPS.ProblemType.GHEP)
elif value == "gen_non_hermitian":
self.eps.setProblemType(SLEPc.EPS.ProblemType.GNHEP)
elif value == "pos_gen_non_hermitian":
self.eps.setProblemType(SLEPc.EPS.ProblemType.PGNHEP)
else:
raise RuntimeError("Invalid problem type")
elif key == "solver":
if value == "power":
self.eps.setType(SLEPc.EPS.Type.POWER)
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":
def solve(self):
"""Solve for the modes of the structure.
Notes
-----
This function is run on all nodes.
"""
if(self.verbose and NOT_PARALLEL):
info_message('Solving...')
# Setup the solve options. We are solving a generalized non-hermitian
# eigenvalue problem (GNHEP)
self._solver.setOperators(self._A, self._B)
self._solver.setProblemType(SLEPc.EPS.ProblemType.GNHEP)
self._solver.setDimensions(self.neigs, PETSc.DECIDE)
self._solver.setTarget(self.n0) # "guess" for effective index
self._solver.setFromOptions()
# Solve Ax=nBx using SLEPc.
# Internally, we use a direct solve (MUMPS) to handle the heavy
# lifting.
self._solver.solve()
nconv = self._solver.getConverged()
if(nconv < self.neigs):
warning_message('%d eigenmodes were requested, however only %d ' \
'eigenmodes were found.' % (self.neigs, nconv), \
module='emopt.modes')
# nconv can be bigger than the desired number of eigen values