Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# We just need the Stiffness and Mass matrix
a = inner(grad(u), grad(v))*dx
m = inner(u, v)*dx
A = topetsc(assemble(a, bcs=[bc]))
M = topetsc(assemble(m, bcs=[bc]))
# This shifts the "1.0" Eigenvalues out of the spectrum
# of interest (which is around 0.0 in this case).
vals = np.repeat(1E8, len(bc.nodes))
A.setValuesLocalRCV(bc.nodes.reshape(-1, 1),
bc.nodes.reshape(-1, 1),
vals.reshape(-1, 1))
A.assemble()
E = SLEPc.EPS()
E.create(comm=mesh.comm)
E.setOperators(A, M)
st = E.getST()
st.setType('sinvert')
kspE = st.getKSP()
kspE.setType('fgmres')
E.setDimensions(5, PETSc.DECIDE)
E.solve()
nconv = E.getConverged()
assert(nconv > 0)
# Create the results vectors
vr, wr = A.getVecs()
vi, wi = A.getVecs()
ev = []
def init_petsc_slepc(self, comm):
import os
petsc_arch = os.environ.get("PETSC_ARCH", None)
import petsc4py
petsc4py.init(args=['-no_signal_handler'], arch=petsc_arch, comm=comm)
import slepc4py
slepc4py.init(args=['-no_signal_handler'], arch=petsc_arch)
self._comm = comm
self._PETSc = petsc4py.PETSc
self._SLEPc = slepc4py.SLEPc
def __init__(self, A, B):
self.eps = SLEPc.EPS().create(wrapping.get_mpi_comm(A))
if B is not None:
self.A = wrapping.to_petsc4py(A)
self.B = wrapping.to_petsc4py(B)
self.eps.setOperators(self.A, self.B)
else:
self.A = wrapping.to_petsc4py(A)
self.B = None
self.eps.setOperators(self.A)
def __init__(self, conf, comm=None, context=None, **kwargs):
if comm is None:
init_slepc_args()
from petsc4py import PETSc as petsc
from slepc4py import SLEPc as slepc
EigenvalueSolver.__init__(self, conf, petsc=petsc, slepc=slepc,
comm=comm, context=context, **kwargs)
# define A and B matrices here
# factor of 3 due to 3 field components
self._A = PETSc.Mat()
self._A.create(PETSc.COMM_WORLD)
self._A.setSizes([3*self._N, 3*self._N])
self._A.setType('aij')
self._A.setUp()
self._B = PETSc.Mat()
self._B.create(PETSc.COMM_WORLD)
self._B.setSizes([3*self._N, 3*self._N])
self._B.setType('aij')
self._B.setUp()
# setup the solver
self._solver = SLEPc.EPS()
self._solver.create()
# we need to set up the spectral transformation so that it doesnt try
# to invert
st = self._solver.getST()
st.setType('sinvert')
# Let's use MUMPS for any system solving since it is fast
ksp = st.getKSP()
#ksp.setType('gmres')
ksp.setType('preonly')
pc = ksp.getPC()
pc.setType('lu')
# backwards compatibility
try: