# blocks_to_amat#

emg3d.core.blocks_to_amat(amat, bvec, middle, left, rhs, im, nc)[source]#

Insert middle, left, and rhs into main arrays amat and bvec.

The banded matrix `amat` contains the main diagonal and the first five lower off-diagonals. They are stored one column after the other, in a 6*n ndarray.

The complete main matrix `amat` and the `middle` and `left` blocks are given by:

```.-0
|X|\   0
0-.-0       left:  middle:  right:
\|X|\                      (not used)
0-.-0      0-     .-      0
\|X|\      \     |X      |\
0-.-0
0   \|X|
0-.

. 1*1, - 4*1, | 1*4, X 4*4, \ 4*4 upper or lower
```

Both, `middle` and `left`, are 5x5 matrices. The corresponding right-hand-side `rhs` is filled into `bvec`. The matrices `left` and `middle` provided in a single call are horizontally aligned (not vertically). The sorting of `amat` (banded matrix) and `bvec` is given by:

``` amat (66,)             example: n = 11                   bvec (11,)
--------------                                                 --
|01            |                    FIRST CALL                  01
|02 07         |                    Only `middle` and `rhs`     02
|03 08 13      |                    are used, not `left`.       03
|04 09 14 19   |                                                04
|05 10 15 20 25|                                                05
-------------- --------------                                  --
| 0 11 16 21 26|31            |     SUBSEQUENT CALLS            06
|   12 17 22 27|32 37         |     (normal case)               07
|      18 23 28|33 38 43      |     Complete `left`,            08
|         24 29|34 39 44 49   |     `middle` and `rhs`          09
|            30|35 40 45 50 55|     are used.                   10
-------------- -------------- ---                              --
| 0 41 46 51 56|61   LAST CALL                   11
|    0  0  0  0| 0   Only top row of `left`
|       0  0  0| 0   and the first elements
|          0  0| 0   of `middle` and `rhs`
|             0| 0   are used.
-------------- ---
| 0

Single zeros (0) show elements in amat which are 0, hence not used.
Their location in amat can be deduced from their neighbours.
```
Parameters:
amatndarray

Main banded matrix (stored as array) of length 6*n.

bvecndarray

Main right-hand-side of length n.

middlendarray

Middle block of size 5x5, as ndarray of length 25. Only the diagonal and the lower triangular part are used.

leftndarray

Left block of size 5x5, as ndarray of length 25. Only the diagonal and the first row are used.

rhsndarray

Corresponding right-hand-side of length 5.

imint

Current minus-index of direction of line relaxation, `i{x;y;z}m`.

ncint

Total number of cells in direction of line relaxation, `n{x;y;z}`.