XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ ZHsrIc0()

Sub ZHsrIc0 ( N As  Long,
Val() As  Complex,
Rowptr() As  Long,
Colind() As  Long,
Val2() As  Complex,
Idiag() As  Long,
Optional Info As  Long,
Optional ByVal Uplo As  String = "L",
Optional Base As  Long = -1 
)

Initialize incomplete Cholesky decomposition without fill-in (IC0) preconditioner (Hermitian positive definite matrices) (CSR)

Purpose
This routine computes the incomplete Cholesky decomposition, without fill-in, of the Hermitian positive definite coefficient matrix of the sparse linear equations.
A = L * D * L^H + R or A = U^H * D * U + R
where L is the lower triangular matrix, U is the upper triangular matrix, and D is the diagonal matrix.
It is called that fill-in occurs when a position that is zero in coefficient matrix A but it becomes non-zero after Cholesky decomposition is performed. To avoid this, such positions in L or U in the above equation are forcibly set to zeros. R shows the differences from the complete Cholesky decomposition arising from this modification. Assuming that R is not large, it is expected that this incomplete decomposition can be used to obtain a good approximate solution of linear equations. This decomposition is used as the preconditioner matrix M.
M = L * D * L^H or M = U^H * D * U
This routine outputs L or U and D in Val2(), and indices of diagonal elements in Idiag(). Val2() and Idiag() will be used by ZHsrIcSolve().
Parameters
[in]NDimension of the matrix A. (N >= 0) (if N = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz) (Nnz is number of nonzero elements of matrix A)
Values of non-zero elements of matrix A. (Only the diagonal and lower triangular elements are referenced)
[in]Rowptr()Array Rowptr(LRowptr - 1) (LRowptr >= N + 1)
Row pointers of matrix A.
[in]Colind()Array Colind(LColind - 1) (LColind >= Nnz)
Column indices of matrix A.
[out]Val2()Array Val2(LVal2 - 1) (LVal2 >= Nnz)
Values of non-zero elements of preconditioner matrix M. (Values to be stored in the same location of diagonal and lower triangular elements of A)
[out]Idiag()Array Idiag(LIdiag) (LIdiag >= N)
Indices of diagonal elements.
[out]Info(Optional)
= 0: Successful exit.
= i < 0: The (-i)-th argument is invalid.
= j > 0: Matrix is singular (j-th diagonal element is zero).
[in]Uplo(Optional)
Specifies whether the upper or lower triangular part of input matrix A is stored. (default = "L")
= "U": Upper triangular part (to be factorized to U^H*D*U).
= "L": Lower triangular part (to be factorized to L*D*L^H).
[in]Base(Optional)
Indexing of Rowptr() and Colind().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Rowptr(0) = 1, 0 otherwise)
Example Program
Solve the system of linear equations Ax = B by CG method with IC(0) preconditioner, where
( 1.4 -1.5+0.46i 0.16+0.23i )
A = ( -1.5-0.46i 1.44 -0.12+0.04i )
( 0.16-0.23i -0.12-0.04i 0.05 )
( -2.3215-1.1316i )
B = ( 1.7972+2.0692i )
( -0.4042-0.0049i )
Sub Ex_ZCg_Ic0_Hsr()
Const N = 3, Nnz = 6, Tol = 0.0000000001 '1.0e-10
Dim A(Nnz - 1) As Complex, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(N - 1) As Complex, X(N - 1) As Complex
Dim XX(N - 1) As Complex, YY(N - 1) As Complex
Dim Iter As Long, Res As Double, IRev As Long, Info As Long
A(0) = Cmplx(1.4): A(1) = Cmplx(-1.5, -0.46): A(2) = Cmplx(1.44): A(3) = Cmplx(0.16, -0.23): A(4) = Cmplx(-0.12, -0.04): A(5) = Cmplx(0.05)
Ia(0) = 0: Ia(1) = 1: Ia(2) = 3: Ia(3) = 6
Ja(0) = 0: Ja(1) = 0: Ja(2) = 1: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2
B(0) = Cmplx(-2.3215, -1.1316): B(1) = Cmplx(1.7972, 2.0692): B(2) = Cmplx(-0.4042, -0.0049)
Dim M(Nnz - 1) As Complex, Id(N - 1) As Long
Call ZHsrIc0(N, A(), Ia(), Ja(), M(), Id(), Info)
If Info <> 0 Then Debug.Print "Ic0 Info =" + Str(Info)
IRev = 0
Do
Call ZCg_r(N, B(), X(), Info, XX(), YY(), IRev, Iter, Res)
If IRev = 1 Then '- Matvec
Call HsrZusmv("L", N, Cmplx(1), A(), Ia(), Ja(), XX(), Cmplx(0), YY())
ElseIf IRev = 3 Then '- Psolve
Call ZHsrIcSolve(N, M(), Ia(), Ja(), Id(), YY(), XX(), Info)
If Info <> 0 Then Debug.Print "Ic0Solve Info =" + Str(Info)
ElseIf IRev = 10 Then '- Check convergence
If Res < Tol Then IRev = 11
End If
Loop While IRev <> 0
Debug.Print "X ="
Debug.Print "(" + CStr(Creal(X(0))) + "," + CStr(Cimag(X(0))) + ")"
Debug.Print "(" + CStr(Creal(X(1))) + "," + CStr(Cimag(X(1))) + ")"
Debug.Print "(" + CStr(Creal(X(2))) + "," + CStr(Cimag(X(2))) + ")"
Debug.Print "Iter =" + Str(Iter) + ", Res =" + Str(Res) + ", Info =" + Str(Info)
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex
Building complex number
Function Cimag(A As Complex) As Double
Imaginary part of complex number
Function Creal(A As Complex) As Double
Real part of complex number
Sub HsrZusmv(Uplo As String, N As Long, Alpha As Complex, Val() As Complex, Rowptr() As Long, Colind() As Long, X() As Complex, Beta As Complex, Y() As Complex, Optional Info As Long, Optional Base As Long=-1, Optional IncX As Long=1, Optional IncY As Long=1)
y <- αAx + βy (CSR) (Hermitian matrix)
Sub ZCg_r(N As Long, B() As Complex, X() As Complex, Info As Long, XX() As Complex, YY() As Complex, IRev As Long, Optional Iter As Long, Optional Res As Double, Optional MaxIter As Long=500)
Solution of linear system Ax = b using conjugate gradient (CG) method (Hermitian positive definite ma...
Sub ZHsrIcSolve(N As Long, Val() As Complex, Rowptr() As Long, Colind() As Long, Idiag() As Long, B() As Complex, X() As Complex, Optional Info As Long, Optional ByVal Uplo As String="L", Optional Base As Long=-1)
Incomplete Cholesky preconditioner (IC) (Hermitian positive definite matrices) (CSR)
Sub ZHsrIc0(N As Long, Val() As Complex, Rowptr() As Long, Colind() As Long, Val2() As Complex, Idiag() As Long, Optional Info As Long, Optional ByVal Uplo As String="L", Optional Base As Long=-1)
Initialize incomplete Cholesky decomposition without fill-in (IC0) preconditioner (Hermitian positive...
Example Results
X =
(-0.82,-0.939999999999999)
(0.74,0.2)
(0.479999999999999,0.209999999999999)
Iter = 1, Res = 7.37282538234167E-16, Info = 0