def solve_eigensystem(M, C, K): # Setup the eigensolver Q = SLEPc.PEP().create() A = [] A.append(K) A.append(C) A.append(M) Q.setOperators(A) Q.setDimensions(6) Q.setProblemType(SLEPc.PEP.ProblemType.GENERAL) Q.setFromOptions() # Solve the eigensystem Q.solve() # Create the results vectors xr, tmp = K.getVecs() xi, tmp = K.getVecs() its = Q.getIterationNumber() Print("Number of iterations of the method: %i" % its) sol_type = Q.getType() Print("Solution method: %s" % sol_type) nev, ncv, mpd = Q.getDimensions() Print("") Print("Number of requested eigenvalues: %i" % nev) tol, maxit = Q.getTolerances() Print("Stopping condition: tol=%.4g, maxit=%d" % (tol, maxit)) nconv = Q.getConverged() Print("Number of converged approximate eigenpairs: %d" % nconv) if nconv > 0: Print("") Print(" k ||(k^2M+Ck+K)x||/||kx|| ") Print("-------------------- -------------------------") for i in range(nconv): k = Q.getEigenpair(i, xr, xi) error = Q.computeError(i) if k.imag != 0.0: Print("%9f%+9f j %12g" % (k.real, k.imag, error)) else: Print("%12f %12g" % (k.real, error)) Print("")
V = FunctionSpace(mesh, 'CG', 1) u = TrialFunction(V) v = TestFunction(V) bc = DirichletBC(V, Constant(0), DomainBoundary()) a = inner(grad(u), grad(v)) * dx m = inner(u, v) * dx L = inner(Constant(1), v) * dx A, M = PETScMatrix(), PETScMatrix() b = PETScVector() # See that assemble + bc.apply does not imply symmetry assemble(a, A) bc.apply(A) print 'Is symmetric?', np.linalg.norm(A.array() - A.array().T) < 1E-10 # But assemble system does assemble_system(a, L, bc, A_tensor=A, b_tensor=b) assemble_system(m, L, bc, A_tensor=M, b_tensor=b) print 'Is symmetric?', np.linalg.norm(A.array() - A.array().T) < 1E-10 print 'Is symmetric?', np.linalg.norm(M.array() - M.array().T) < 1E-10 from slepc4py import SLEPc E = SLEPc.PEP().create() E.setOperators([A.mat(), M.mat(), A.mat()])
def help(args=None): import sys # program name try: prog = sys.argv[0] except Exception: prog = getattr(sys, 'executable', 'python') # arguments if args is None: args = sys.argv[1:] elif isinstance(args, str): args = args.split() else: args = [str(a) for a in args] # initialization import slepc4py slepc4py.init([prog, '-help'] + args) from slepc4py import SLEPc # and finally ... COMM = SLEPc.COMM_SELF if 'eps' in args: eps = SLEPc.EPS().create(comm=COMM) eps.setFromOptions() eps.destroy() del eps if 'svd' in args: svd = SLEPc.SVD().create(comm=COMM) svd.setFromOptions() svd.destroy() del svd if 'pep' in args: pep = SLEPc.PEP().create(comm=COMM) pep.setFromOptions() pep.destroy() del pep if 'nep' in args: nep = SLEPc.NEP().create(comm=COMM) nep.setFromOptions() nep.destroy() del nep if 'mfn' in args: mfn = SLEPc.MFN().create(comm=COMM) mfn.setFromOptions() mfn.destroy() del mfn if 'st' in args: st = SLEPc.ST().create(comm=COMM) st.setFromOptions() st.destroy() del st if 'bv' in args: bv = SLEPc.BV().create(comm=COMM) bv.setFromOptions() bv.destroy() del bv if 'rg' in args: rg = SLEPc.RG().create(comm=COMM) rg.setFromOptions() rg.destroy() del rg if 'fn' in args: fn = SLEPc.FN().create(comm=COMM) fn.setFromOptions() fn.destroy() del fn if 'ds' in args: ds = SLEPc.DS().create(comm=COMM) ds.setFromOptions() ds.destroy() del ds