MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / PINVIT

Function PINVIT

python/eigenvalues.py:75–110  ·  view source on GitHub ↗

preconditioned inverse iteration

(mata, matm, pre, num=1, maxit=20, printrates=True, GramSchmidt=True)

Source from the content-addressed store, hash-verified

73
74
75def PINVIT(mata, matm, pre, num=1, maxit=20, printrates=True, GramSchmidt=True):
76 """preconditioned inverse iteration"""
77 import scipy.linalg
78
79 r = mata.CreateRowVector()
80
81 uvecs = MultiVector(r, num)
82 vecs = MultiVector(r, 2*num)
83 # hv = MultiVector(r, 2*num)
84
85 for v in vecs[0:num]:
86 v.SetRandom()
87 uvecs[:] = pre * vecs[0:num]
88 lams = Vector(num * [1])
89
90 for i in range(maxit):
91 vecs[0:num] = mata * uvecs - (matm * uvecs).Scale (lams)
92 vecs[num:2*num] = pre * vecs[0:num]
93 vecs[0:num] = uvecs
94
95 vecs.Orthogonalize(matm)
96
97 # hv[:] = mata * vecs
98 # asmall = InnerProduct (vecs, hv)
99 # hv[:] = matm * vecs
100 # msmall = InnerProduct (vecs, hv)
101 asmall = InnerProduct (vecs, mata * vecs)
102 msmall = InnerProduct (vecs, matm * vecs)
103
104 ev,evec = scipy.linalg.eigh(a=asmall, b=msmall)
105 lams = Vector(ev[0:num])
106 if printrates:
107 print (i, ":", list(lams))
108
109 uvecs[:] = vecs * Matrix(evec[:,0:num])
110 return lams, uvecs
111
112
113def LOBPCG(mata, matm, pre, num=1, maxit=20, initial=None, printrates=True, largest=False):

Callers

nothing calls this directly

Calls 6

VectorClass · 0.85
MultiVectorClass · 0.50
InnerProductFunction · 0.50
MatrixClass · 0.50
CreateRowVectorMethod · 0.45
ScaleMethod · 0.45

Tested by

no test coverage detected