# DIIS solver

`ElemCo.DIIS`

— ModuleDIIS module for iterative solvers

This module provides the DIIS (Direct Inversion in the Iterative Subspace) method for iterative solvers.

The DIIS method is used to accelerate the convergence of iterative solvers by combining previous solutions to the problem to minimize the residual. The vectors and residuals are stored in files as `Vector{Vector{Float64}}`

.

**Usage**

```
diis = Diis(EC)
for it = 1:maxit
# compute Vec = [Vec1,Vec2,...] and Res = [Res1,Res2,...]
# ...
perform!(diis, Vec, Res)
# ...
end
```

One can also provide a tuple of custom dot-product functions for the residuals components as `customdots`

argument in `perform!`

function.

## Main structure

`ElemCo.DIIS.Diis`

— TypeDIIS object

## Exported functions

`ElemCo.DIIS.perform!`

— Function`perform!(diis::Diis, Amps, Res, customdots=())`

Perform DIIS.

`Amps`

is an array of vectors and `Res`

is an array of residuals. The vectors `Amps`

will be replaced by the DIIS optimized vectors. `customdots`

is a tuple of functions for each residual component to calculate the dot-product. The functions should have the signature `f(ten1::Array{T,N}, ten2::Array{T,N})`

.

## Internal functions

`ElemCo.DIIS.combine`

— Method`combine(diis::Diis, vecfiles, coeffs)`

Combine vectors from files with coefficients.

`ElemCo.DIIS.custom_dot`

— Method`custom_dot(diis::Diis, customdots, tens, vecs)`

Compute weighted (with diis.weights) dot product of vectors using custom dot-product functions `customdots::Tuple`

. `vecs`

are reshaped to the shape of tensors `tens`

.

`ElemCo.DIIS.loadamps`

— Method`loadamps(diis::Diis, ipos)`

Load vectors from file at position `ipos`

as `Vector{Vector{Float64}}`

.

`ElemCo.DIIS.loadres`

— Method`loadres(diis::Diis, ipos)`

Load residuals from file at position `ipos`

as `Vector{Vector{Float64}}`

.

`ElemCo.DIIS.loadvecs`

— Method`loadvecs(file)`

Load vectors from file as `Vector{Vector{Float64}}`

.

`ElemCo.DIIS.saveamps`

— Method`saveamps(diis::Diis, vecs, ipos)`

Save vectors to file (replacing previous vectors at position `ipos`

).

`ElemCo.DIIS.saveres`

— Method`saveres(diis::Diis, vecs, ipos)`

Save residuals to file (replacing previous residuals at position `ipos`

).

`ElemCo.DIIS.update_Bmat`

— Function`update_Bmat(diis::Diis, nDim, Res, ithis, customdots=())`

Update B matrix with new residual (at the position `ithis`

).

B matrix is defined as:

\[{\bf B} = \begin{pmatrix} \langle {\bf R}_1, {\bf R}_1 \rangle & \langle {\bf R}_1, {\bf R}_2 \rangle & \cdots & \langle {\bf R}_1, {\bf R}_{\rm nDim} \rangle & -1 \\ \langle {\bf R}_2, {\bf R}_1 \rangle & \langle {\bf R}_2, {\bf R}_2 \rangle & \cdots & \langle {\bf R}_2, {\bf R}_{\rm nDim} \rangle & -1 \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \langle {\bf R}_{\rm nDim}, {\bf R}_1 \rangle & \langle {\bf R}_{\rm nDim}, {\bf R}_2 \rangle & \cdots & \langle {\bf R}_{\rm nDim}, {\bf R}_{\rm nDim} \rangle & -1 \\ -1 & -1 & \cdots & -1 & 0 \end{pmatrix}\]

Returns the dot product of the new residual with itself, $\langle {\bf R}_{\rm ithis}, {\bf R}_{\rm ithis} \rangle$.

`ElemCo.DIIS.weighted_dot`

— Method`weighted_dot(diis::Diis, vecs1, vecs2)`

Compute weighted (with diis.weights) dot product of vectors.