topoptlab.multigrid module
- topoptlab.multigrid.apply_multigrid(b: ndarray, A: sparray, x0: ndarray, interpolators: List, cycle: Callable, tol: float, smoother_fnc: Callable, smoother_kws: Dict, max_cycles: int = 1, nlevels: int = 2, conv_criterium: Callable = <function res_norm>, conv_args: Dict = {}) Tuple[ndarray, int][source]
Apply a generic multigrid solver for the linear problem Ax=b. In this function we assume that the interpolation from coarse to fine grid via the interpolator P also gives us the map from fine to coarse grid via the transpose of the prolongator P.T. We might call P.T a restrictor/coarsener.
- Parameters:
b (np.ndarray) – right hand side of full system.
A (scipy.sparse.sparray) – system matrix (e. g. stiffness matrix)
x0 (None or np.ndarray) – initial guess for solution.
interpolators (list) – list of matrices P that interpolate from coarse to fine grid. Must be initialized before calling this function.
cycle (callable) – a multigrid cycle. Currently only V-cycle is available, but the common versions are V,F and W.
tol (float) – convergence tolerance.
smoother_fnc (callable) – function for smoothing the error (e. g. Gauss-Seidel or Jacobi iteration).
smoother_kws (dict) – keywords for the smoother.
max_cycles (int) – maximum number of cycles.
nlevels (int) – number of grid levels.
conv_criterium (callable) – converge criterion.
conv_args (dict) – arguments regarding the convergence criterion.
- Returns:
x (np.ndarray) – final result for solution.
info (int) – 0: converged in final post-smoothing , info>0: exited during last post-smoothing due to maximum number of iterations.
- topoptlab.multigrid.multigrid_preconditioner(A: sparray, b: ndarray, x0: ndarray, create_interpolators: Callable, interpolator_kw: Dict, cycle: Callable = <function vcycle>, tol: float = 1e-06, smoother_fnc: Callable = <function smoothed_jacobi>, smoother_kws: Dict = {}, max_cycles: int = 1) LinearOperator[source]
Generic multigrid preconditioner for the linear problem Ax=b. In the current implementation we assume that the interpolation from coarse to fine grid via the interpolator P also gives us the map from fine to coarse grid via the transpose of the prolongator P.T. We might call P.T a restrictor/coarsener.
- Parameters:
A (scipy.sparse.sparray) – system matrix (e. g. stiffness matrix)
b (np.ndarray) – right hand side of full system.
x0 (np.ndarray) – initial guess for solution.
create_interpolators (Callable) – create list of matrices P that interpolate from coarse to fine grid.
interpolator_kw (dict) – keywords needed to construct the interpolators.
cycle (callable) – a multigrid cycle. Currently only V-cycle is available, but the common versions are V,F and W.
tol (float) – convergence tolerance.
smoother_fnc (callable) – function for smoothing the error (e. g. Gauss-Seidel or Jacobi iteration).
smoother_kws (dict) – keywords for the smoother.
max_cycles (int) – maximum number of cycles.
nlevels (int) – number of grid levels.
- Returns:
M – multigrid preconditioner
- Return type:
scipy.sparse.linalg.LinearOperator
- topoptlab.multigrid.vcycle(A: sparray, b: ndarray, x0: ndarray, lvl: int, interpolators: List, smoother_fnc: Callable, smoother_kws: Dict, nlevels: int) Tuple[ndarray, int][source]
Generic, single recursive V-cycle iteration to solve the linear problem Ax=b. In the current implementation we assume that the interpolation from coarse to fine grid via the prolongator/interpolator P also gives us the map from fine to coarse grid via the transpose of the prolongator P.T which we might call the restrictor/coarsener.
- Parameters:
A (scipy.sparse.sparray) – system matrix (e. g. stiffness matrix)
b (np.ndarray) – right hand side of full system.
x0 (np.ndarray) – initial guess for solution.
lvl (int) – number of current level (maximum is nlevels-1).
interpolators (list) – list of matrices P that interpolate from coarse to fine grid. Must be initialized before calling this function.
smoother_fnc (callable) – function for smoothing the error (e. g. Gauss-Seidel or Jacobi iteration).
smoother_kws (dict) – keywords for the smoother.
nlevels (int) – number of grid levels.
- Returns:
x (np.ndarray) – final result for solution.
info (int) – 0: converged in final post-smoothing , info>0: exited during last post-smoothing due to maximum number of iterations.