topoptlab.solve_linsystem module

topoptlab.solve_linsystem.laplacian(grid: Tuple) Tuple[csc_array, ndarray][source]

Construct Laplacian on a uniform rectangular grid in N dimensions and the right hand side to the linear problem

Lx=b

where the first entry of b is 1 and the last is -1.

This is purely intended as a short test problem to check whether solvers actually work.

Parameters:

grid (tuple) – number of grid points in each direction. len(grid) is n.

Returns:

  • L (csc_array) – Laplacian

  • b (callable) – callable that allows to re-apply the factorization of matrix K to another right hand side.

topoptlab.solve_linsystem.solve_lin(K: ~scipy.sparse._csc.csc_array | ~cvxopt.base.spmatrix, rhs: ~numpy.ndarray | ~cvxopt.base.matrix, solver: str, rhs0: None | ~numpy.ndarray | ~cvxopt.base.matrix = None, solver_kw: ~typing.Dict = {}, factorization: None | ~typing.Callable = None, preconditioner: None | str = None, preconditioner_kw: ~typing.Dict = {}, P: None | ~typing.Callable | ~cvxopt.base.spmatrix | ~scipy.sparse._csc.csc_array = None, logger: ~topoptlab.log_utils.EmptyLogger | ~topoptlab.log_utils.SimpleLogger = <class 'topoptlab.log_utils.EmptyLogger'>, **kwargs: ~typing.Any) Tuple[ndarray, None | Callable, None | Callable | spmatrix | csc_array][source]

Solve linear system Ku=rhs for a generic matrix K with preconditioner P. rhs might contain multiple sets of boundary conditions that are solved sequentially.

Parameters:
  • K (scipy.sparse.csc_arrayor cvxopt.base.spmatrix (ndof_free,ndof_free)) – matrix to solve.

  • rhs (np.ndarray or cvxopt.base.matrix (ndof_free,nbc)) – right hand side of linear system.

  • solver (str) – string that indicates the library and type of solver to be used according to the scheme “library-solvername”. Current libraries are “scipy”, “pyamg” and “topoptlab”. All iterative solvers of scipy.sparse are included under identical names. “topoptlab” has a preconditioned conjugate gradient solver “pcg” capable of logging process and “cg” without preconditioning.

  • rhs0 (None or np.ndarray or cvxopt.base.matrix (ndof_free,nbc)) – initial guess for right hand side of linear system. Only relevant for iterative solvers.

  • solver_kw (dict) – arguments for the solver.

  • preconditioner (str) – string that indicates the library and type of preconditioner to be used according to the scheme “library-solvername”. Current libraries are “scipy”, “pyamg” and “topoptlab”. Scipy has only “ilu”. pyamg has “air”, “ruge_stuben”, “smoothed_aggregation”, “rootnode”, “pairwise” and “adaptive_sa”. For details regarding keywords, check the pyamg documentation.

  • preconditioner_kw (dict) – arguments for the preconditioner.

  • P (callable or sparse matrix format) – preconditioner created during previous solution of Ku. Concrete nature depends on the solver and library used.

  • logger (EmptyLogger or SimpleLogger) – logger for writing information to logfile.

Returns:

  • solution (np.ndarray shape (ndof_free)) – solution of linear system.

  • factorization (callable) – callable that allows to re-apply the factorization of matrix K to another right hand side.

  • preconditioner (callable or scipy.sparse.matrix or similar object) – preconditioner created during the solution. Concrete nature depends on the solver and library used.