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

Method _SolveImpl

python/krylovspace.py:263–290  ·  view source on GitHub ↗
(self, rhs : BaseVector, sol : BaseVector)

Source from the content-addressed store, hash-verified

261 return self.residuals
262
263 def _SolveImpl(self, rhs : BaseVector, sol : BaseVector):
264 d, w, s = [sol.CreateVector() for i in range(3)]
265 conjugate = self.conjugate
266 d.data = rhs - self.mat * sol
267 w.data = self.pre * d
268 s.data = w
269 wdn = w.InnerProduct(d, conjugate=conjugate)
270 if self.CheckResidual(sqrt(abs(wdn))):
271 return
272
273 while True:
274 w.data = self.mat * s
275 wd = wdn
276 as_s = s.InnerProduct(w, conjugate=conjugate)
277 if as_s == 0 or wd == 0: break
278 alpha = wd / as_s
279 sol.data += alpha * s
280 d.data += (-alpha) * w
281
282 w.data = self.pre * d
283
284 wdn = w.InnerProduct(d, conjugate=conjugate)
285 if self.CheckResidual(sqrt(abs(wdn))):
286 return
287
288 beta = wdn / wd
289 s *= beta
290 s.data += w
291
292
293def CG(mat, rhs, pre=None, sol=None, tol=1e-12, maxsteps = 100, printrates = True, plotrates = False, initialize = True, conjugate=False, callback=None, **kwargs):

Callers 1

SolveMethod · 0.45

Calls 5

InnerProductMethod · 0.80
CheckResidualMethod · 0.80
sqrtFunction · 0.50
absFunction · 0.50
CreateVectorMethod · 0.45

Tested by

no test coverage detected