preconditioned conjugate gradient method Parameters ---------- mat : Matrix The left hand side of the equation to solve. The matrix has to be spd o hermitsch. rhs : Vector The right hand side of the equation. pre : Preconditioner If provided the preconditio
(mat, rhs, pre=None, sol=None, tol=1e-12, maxsteps = 100, printrates = True, plotrates = False, initialize = True, conjugate=False, callback=None, **kwargs)
| 291 | |
| 292 | |
| 293 | def CG(mat, rhs, pre=None, sol=None, tol=1e-12, maxsteps = 100, printrates = True, plotrates = False, initialize = True, conjugate=False, callback=None, **kwargs): |
| 294 | """preconditioned conjugate gradient method |
| 295 | |
| 296 | |
| 297 | Parameters |
| 298 | ---------- |
| 299 | |
| 300 | mat : Matrix |
| 301 | The left hand side of the equation to solve. The matrix has to be spd o hermitsch. |
| 302 | |
| 303 | rhs : Vector |
| 304 | The right hand side of the equation. |
| 305 | |
| 306 | pre : Preconditioner |
| 307 | If provided the preconditioner is used. |
| 308 | |
| 309 | sol : Vector |
| 310 | Start vector for CG method, if initialize is set False. Gets overwritten by the solution vector. If sol = None then a new vector is created. |
| 311 | |
| 312 | tol : double |
| 313 | Tolerance of the residuum. CG stops if tolerance is reached. |
| 314 | |
| 315 | maxsteps : int |
| 316 | Number of maximal steps for CG. If the maximal number is reached before the tolerance is reached CG stops. |
| 317 | |
| 318 | printrates : bool |
| 319 | If set to True then the error of the iterations is displayed. |
| 320 | |
| 321 | plotrates : bool |
| 322 | If set to True then the error of the iterations is plotted. |
| 323 | |
| 324 | initialize : bool |
| 325 | If set to True then the initial guess for the CG method is set to zero. Otherwise the values of the vector sol, if provided, is used. |
| 326 | |
| 327 | conjugate : bool |
| 328 | If set to True, then the complex inner product is used. |
| 329 | |
| 330 | |
| 331 | Returns |
| 332 | ------- |
| 333 | (vector) |
| 334 | Solution vector of the CG method. |
| 335 | |
| 336 | """ |
| 337 | solver = CGSolver(mat=mat, pre=pre, conjugate=conjugate, tol=tol, maxiter=maxsteps, |
| 338 | callback=callback, printrates=printrates, plotrates=plotrates, **kwargs) |
| 339 | solver.Solve(rhs=rhs, sol=sol, initialize=initialize) |
| 340 | return solver.sol |
| 341 | |
| 342 | |
| 343 |