MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
muv.h File Reference

Data Structures

struct  muv_t

Typedefs

typedef void(* exfun_t) (dcell **xout, const void *A, const dcell *xin, const real alpha, int xb, int yb)

Functions

void muv (dcell **xout, const void *A, const dcell *xin, const real alpha)
void muv_trans (dcell **xout, const void *A, const dcell *xin, const real alpha)
void muv_ib (dcell **xout, const void *A, const dcell *xin, const real alpha)
void muv_direct_solve (dcell **xout, const muv_t *A, dcell *xin)
void muv_direct_solve_mat (dmat **xout, const muv_t *A, dmat *xin)
void muv_direct_prep (muv_t *muv, real svd)
void muv_direct_free (muv_t *muv)
void muv_direct_diag_solve (dmat **xout, const muv_t *A, dmat *xin, int ib)
void muv_bgs_solve (dcell **px, const muv_t *A, const dcell *b)
real muv_solve (dcell **px, const muv_t *L, const muv_t *R, dcell *b)
void * muv_direct_spsolve (const muv_t *A, const dsp *xin)
void muv_direct_diag_prep (muv_t *muv, real svd)
void muv_direct_diag_free (muv_t *muv)
void muv_free (muv_t *A)

Detailed Description

Decomposes a matrix into sparse and low rank terms and do math operations.


Data Structure Documentation

◆ muv_t

struct muv_t

Decompose an operator into a sparse operator and optional low rank terms. M-U*V'; M is usually symmetrical.

Collaboration diagram for muv_t:
Data Fields
cell * M

block sparse matrix or dense matrix

dcell * U

low rank terms U

dcell * V

low rank terms V

exfun_t exfun

Optionally attach an extra function that applies extra data

void * extra

Data used by fun to apply: (*exfun)(y,extra,x,alpha) to compute

spchol * C

Cholesky factor.

dmat * Up

\(M^{-1}U\)

dmat * Vp

\(M^{-1}[V*(I-Up'*V)^{-1}]\)

dmat * MI

Inverse of M via svd

dcell * MIB

Inverse of each diagonal element of M via svd

spchol ** CB

Cholesky factor of each diagonal element of M

dcell * UpB

Up for each diagonal component

dcell * VpB

Vp for each diagonal component

int nb

Number of blocks in CB;

cgfun_t Mfun

Do M*x with a function

cgfun_t Mtfun

Do M'*x with a function

void * Mdata

Parameter to Mfun

prefun_t pfun

The preconditioner function

void * pdata

The precondtioner data

int alg

The algorithm: 0: CBS, 1: CG, 2: SVD

int bgs

Whether use BGS (Block Gauss Seidel) method, and how many iterations

int warm

Whether use warm restart

int maxit

How many iterations

Typedef Documentation

◆ exfun_t

typedef void(* exfun_t) (dcell **xout, const void *A, const dcell *xin, const real alpha, int xb, int yb)

Avoid function casting. It will hide data safety check and hide bugs.

Function Documentation

◆ muv()

void muv ( dcell ** xout,
const void * A_,
const dcell * xin,
const real alpha )

Decomposes a matrix into sparse and low rank terms and do math operations.

The forward operations can be represented by a matrix M and two low rank terms as y = ( M - u*v' ) *x , or by a function Mfun and corresponding argument Mdata.

This can also be used to solve linear equations using muv_solve() or muv_bgs_solve(). Apply the sparse plus low rank compuation to xin with scaling of alpha: \(xout=(A.M-A.U*A.V')*xin*alpha\); U,V are low rank.

Parameters
[in,out]xoutThe output, accumulated into. Allocated if NULL.
[in]A_The muv_t operator. Declared void for use as a pcg callback.
[in]xinThe input vector.
[in]alphaScaling factor.

◆ muv_trans()

void muv_trans ( dcell ** xout,
const void * A_,
const dcell * xin,
const real alpha )

Apply the transpose of operation muv(); Apply the sparse plug low rand compuation to xin with scaling of alpha: \(xout=(A.M-A.V*A.U')*xin*alpha\); U,V are low rank.

Parameters
[in,out]xoutThe output, accumulated into. Allocated if NULL.
[in]A_The muv_t operator. Declared void for use as a pcg callback.
[in]xinThe input vector. Nothing is done if NULL and A->M is set.
[in]alphaScaling factor.

◆ muv_ib()

void muv_ib ( dcell ** xout,
const void * B,
const dcell * xin,
const real alpha )

Apply the sparse plus low rand compuation to xin with scaling of alpha for block (xb, yb): \(xout_x=(A.M_xy-A.U_xi*A.V_yi')*xin_y*alpha\); U,V are low rank.

Parameters
[in,out]xoutThe output, block xb is accumulated into. Allocated if NULL.
[in]BPointer to MUV_IB_T containing the muv_t operator and block indices. If xb or yb is -1, the full muv() is applied.
[in]xinThe input vector (one column).
[in]alphaScaling factor.

◆ muv_direct_solve()

void muv_direct_solve ( dcell ** xout,
const muv_t * A,
dcell * xin )

convert the data from dcell to dmat and apply muv_direct_solve_mat(). May be done in place.

Parameters
[out]xoutThe output. Allocated if NULL.
[in]AThe muv_t struct prepared by muv_direct_prep().
[in]xinThe input. Nothing is done if NULL.

◆ muv_direct_solve_mat()

void muv_direct_solve_mat ( dmat ** xout,
const muv_t * A,
dmat * xin )

Apply CBS or SVD multiply to xin to get xout. Create xout is not exist already. xout = A^-1 * xin; xin and xout can be the same for in place operation.

Parameters
[out]xoutThe output. Allocated if NULL. Can be the same as xin.
[in]AThe muv_t struct prepared by muv_direct_prep().
[in]xinThe input.

◆ muv_direct_prep()

void muv_direct_prep ( muv_t * A,
real svd )

Cholesky factorization (svd=0) or svd (svd>0) on the sparse matrix and its low rank terms. if svd is less than 1, it is also used as the threshold in SVD inversion.

When there are low rank terms,

\[ Up=M^{-1}*U, Vp=-M^{-1}*[V*(I-Up'*V)^{-1}] \]

Parameters
[in,out]AThe muv_t struct. The factorization (C or MI, Up, Vp) is stored into it. With svd, U and V are absorbed into MI and freed.
[in]svd0: Cholesky factorization. Otherwise use SVD; if |svd|<1 it is the SVD inversion threshold.

◆ muv_direct_free()

void muv_direct_free ( muv_t * A)

Free cholesky decompositions or SVD.

Parameters
[in,out]AThe muv_t struct whose C, MI, Up, Vp are freed.

◆ muv_direct_diag_solve()

void muv_direct_diag_solve ( dmat ** xout,
const muv_t * A,
dmat * xin,
int ib )

Apply cholesky backsubstitution solve to xin to get xout. Create xout is not exist already. xin and xout can be the same for in place operation.

Parameters
[out]xoutThe output. Allocated if NULL. Can be the same as xin.
[in]AThe muv_t struct prepared by muv_direct_diag_prep().
[in]xinThe input. Nothing is done if NULL.
[in]ibThe diagonal block index.

◆ muv_bgs_solve()

void muv_bgs_solve ( dcell ** px,
const muv_t * A,
const dcell * b )

solve A*x=b using the Block Gauss Seidel algorithm. The matrix is always assembled. We use routines from muv. to do the computation.

Parameters
[in,out]pxThe output vector. Input for warm restart. Allocated if NULL.
[in]AContain info about the left hand side matrix A.
[in]bThe right hand side vector to solve. Nothing is done if NULL.

◆ muv_solve()

real muv_solve ( dcell ** px,
const muv_t * L,
const muv_t * R,
dcell * b )

solve x=A^-1*B*b using algorithms depend on algorithm, wrapper.

Parameters
[in,out]pxThe output vector. Input for warm restart. Allocated if NULL.
[in]LContain info about the left hand side matrix A.
[in]RContain info about the right hand side matrix B. If NULL, b is used as the right hand side directly.
[in]bThe right hand side vector to solve. NULL is special case.
Returns
The residual from pcg() for CG; 0 otherwise.

◆ muv_direct_spsolve()

void * muv_direct_spsolve ( const muv_t * A,
const dsp * xin )

Apply CBS or SVD multiply to square sparse matrix. xout = A^-1 * xin * (A^-1)^T. The output is dmat if using SVD, and dsp if using CBS.

Parameters
[in]AThe muv_t struct prepared by muv_direct_prep().
[in]xinThe square sparse input matrix.
Returns
Newly allocated dmat (SVD) or dsp (CBS); the caller frees it.

◆ muv_direct_diag_prep()

void muv_direct_diag_prep ( muv_t * A,
real svd )

Cholesky factorization (svd=0) or svd (svd>0) on each diagonal element of the block sparse matrix and its low rank terms. if svd is less than 1, it is also used as the threshold in SVD inversion.

When there are low rank terms,

\[ Up=M^{-1}U, Vp=-M^{-1}[V*(I-Up'*V)^{-1}] \]

For each diagonal block.

Parameters
[in,out]AThe muv_t struct. The factorization (CB or MIB, UpB, VpB) is stored into it. U and V are reduced to column block vectors.
[in]svd0: Cholesky factorization. Otherwise use SVD; if svd<1 it is the SVD inversion threshold.

◆ muv_direct_diag_free()

void muv_direct_diag_free ( muv_t * A)

Free cholesky decompositions or SVD of the diagonal blocks.

Parameters
[in,out]AThe muv_t struct whose CB, MIB, UpB, VpB are freed.

◆ muv_free()

void muv_free ( muv_t * A)

Free the content of muv_t struct and zero it. The struct itself is not freed.

Parameters
[in,out]AThe muv_t struct.