ex12.py: Illustrate the use of arbitrary selection ================================================== This example solves a simple tridiagonal eigenproblem. It illustrates how to set up the arbitrary selection of eigenvalues, where the decision of which is the preferred eigenvalue is made based not only on the value of the approximate eigenvalue but also on the approximate eigenvector. In this example, the selection criterion is based on the projection of the approximate eigenvector onto a precomputed eigenvector. That is why we solve the problem twice. The full source code for this demo can be `downloaded here <../_static/ex12.py>`__. Initialization is similar to previous examples. :: import sys, slepc4py slepc4py.init(sys.argv) from petsc4py import PETSc from slepc4py import SLEPc import numpy The matrix size ``n`` can be specified at the command line. :: opts = PETSc.Options() n = opts.getInt('n', 30) Create the matrix ``tridiag([-1 0 -1])``. :: A = PETSc.Mat(); A.create() A.setSizes([n, n]) A.setFromOptions() rstart, rend = A.getOwnershipRange() for i in range(rstart, rend): if i>0: A[i, i-1] = -1 if i0: sx, _ = A.createVecs() E.getEigenpair(0, sx) vw.pushFormat(PETSc.Viewer.Format.ASCII_INFO_DETAIL) E.errorView(viewer=vw) def myArbitrarySel(evalue, xr, xi, sx): return abs(xr.dot(sx)) E.setArbitrarySelection(myArbitrarySel,sx) E.setWhichEigenpairs(SLEPc.EPS.Which.LARGEST_MAGNITUDE) E.solve() E.errorView(viewer=vw) vw.popFormat() else: Print( "No eigenpairs converged" )