# How to construct a linear solver using the "Linear Solver Factory"

The class "LinearSolverFactory" is designed to help in the construction of the Kratos Linear Solvers, and makes an attempt to unify the construction mechanism.

the essential idea is that the "settings" to be used in the construction of a linear solver are defined by constructing a new python class (with arbitrary name) which contains the settings needed for the construction of the solver

Within kratos there exist different classes of linear solvers.

## Solvers available in the Kratos Core

A first group of iterative solvers is included within the Kratos core and is always available to the user. These solvers are

``` BiConjugate gradient stabilized
GMRES
```

This solvers can be used with or without a preconditioner, which is also available within the Kratos core. Available options for the preconditioner are

``` None
DiagonalPreconditioner
ILU0
```

in order to construct a "BiConjugate gradient stabilized" together with an ILU0 preconditioner using the factory class one shall write

```   ##here we specify the settings to be used in the construction
class custom_settings:
scaling = True
preconditioner_type = "DiagonalPreconditioner"
max_iteration = 500
tolerance = 1e-6

##here we actually construct a new linear solver using the "custom settings" just defined
import linear_solver_factory
new_linear_solver =  linear_solver_factory.ConstructSolver(custom_settings)
```

Note that specifying "True" at the scaling option implies that the matrix coefficients is normalized prior to the solution step

The Kratos core also includes a simple direct solver named

```  Skyline LU factorization
```

such solver is appropriate for the solution of relatively small systems of equations which can be conveniently solved by employing a direct solver technology. Since the solver is direct, tolerance, preconditioner_type and max_iterations make no sense and are not required. a new solver of this type could be constructed as

```   ##here we specify the settings to be used in the construction
class other_settings:
```

solver_type = "Skyline LU factorization" scaling = False

```   ##here we actually construct a new linear solver using the "other settings" just defined
import linear_solver_factory
new_direct_solver =  linear_solver_factory.ConstructSolver(other_settings)
```

The kratos core also provides more advanced solvers, specialized to the case of mixed formulations. An example of this is the

```   Mixed UP
```

solver which implements a SIMPLE-like preconditioner for the monolithic Navier-Stokes equations combined with a GMRES solver. This solver combines different linear solvers to be used for the "U block" and for the "P block" and shall be in some sense optimal in the case of dominating intertia