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

◆ CsrSsorSolve()

Sub CsrSsorSolve ( Trans As  String,
N As  Long,
Omega As  Double,
Val() As  Double,
Rowptr() As  Long,
Colind() As  Long,
D() As  Double,
B() As  Double,
X() As  Double,
Optional Info As  Long,
Optional Base As  Long = -1 
)

Symmetric successive over-relaxation (SSOR) preconditioner (CSR)

Purpose
This routine is the symmetric successive over-relaxation (SSOR) preconditioner for the coefficient matrix A of the sparse linear equations. It solves the equation M*x = b or M^T*x = b, where M is the preconditioner matrix.
Parameters
[in]Trans= "N": solve M*x = b.
= "T" or "C": solve M^T*x = b.
[in]NDimension of preconditioner matrix. (N >= 0) (if N = 0, returns without computation)
[in]OmegaThe relaxation parameter ω. (0 < ω < 2)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz)
Values of non-zero elements of matrix A. (Nnz is number of non-zero elements)
[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 (where Nnz is the number of nonzero elements).
[in]D()Array D(LD) (LD >= N)
Diagonal elements of preconditioner matrix M obtained by CSR_SSOR().
[in]B()Array B(LB - 1) (LB >= N)
Right hand side vector b.
[out]X()Array X(LX - 1) (LX >= N)
Solution vector x.
[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]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 FGMRES method with SSOR preconditioner, where
( 0.2 -0.11 -0.93 ) ( -0.3727 )
A = ( -0.32 0.81 0.37 ), B = ( 0.4319 )
( -0.8 -0.92 -0.29 ) ( -1.4247 )
Sub Ex_Fgmres_Ssor_Csr()
Const N = 3, Nnz = N * N, Omega = 0.5, Tol = 0.0000000001 '1.0e-10
Dim A(Nnz - 1) As Double, Ia(N) As Long, Ja(Nnz - 1) As Long
Dim B(N - 1) As Double, X(N - 1) As Double
Dim XX(N - 1) As Double, YY(N - 1) As Double
Dim Iter As Long, Res As Double, IRev As Long, Info As Long
A(0) = 0.2: A(1) = -0.11: A(2) = -0.93: A(3) = -0.32: A(4) = 0.81: A(5) = 0.37: A(6) = -0.8: A(7) = -0.92: A(8) = -0.29
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2
B(0) = -0.3727: B(1) = 0.4319: B(2) = -1.4247
Dim D(N - 1) As Double
Call CsxSsor(N, Omega, A(), Ia(), Ja(), D(), Info)
If Info <> 0 Then Debug.Print "Ssor Info =" + Str(Info)
IRev = 0
Do
Call Fgmres_r(N, B(), X(), Info, XX(), YY(), IRev, Iter, Res)
If IRev = 1 Then '- Matvec
Call CsrDusmv("N", N, N, 1, A(), Ia(), Ja(), XX(), 0, YY())
ElseIf IRev = 3 Then '- Psolve
Call CsrSsorSolve("N", N, Omega, A(), Ia(), Ja(), D(), YY(), XX(), Info)
If Info <> 0 Then Debug.Print "SsorSolve Info =" + Str(Info)
ElseIf IRev = 10 Then '- Check convergence
If Res < Tol Then IRev = 11
End If
Loop While IRev <> 0
Debug.Print "X =", X(0), X(1), X(2)
Debug.Print "Iter = " + CStr(Iter) + ", Res = " + CStr(Res) + ", Info = " + CStr(Info)
End Sub
Sub CsrDusmv(Trans As String, M As Long, N As Long, Alpha As Double, Val() As Double, Rowptr() As Long, Colind() As Long, X() As Double, Beta As Double, Y() As Double, Optional Info As Long, Optional Base As Long=-1, Optional IncX As Long=1, Optional IncY As Long=1)
y <- αAx + βy or y <- αATx + βy (CSR)
Sub Fgmres_r(N As Long, B() As Double, X() As Double, Info As Long, XX() As Double, YY() As Double, IRev As Long, Optional Iter As Long, Optional Res As Double, Optional M As Long=0, Optional MaxIter As Long=500)
Solution of linear system Ax = b using generalized minimum residual (FGMRES) method (Reverse communic...
Sub CsrSsorSolve(Trans As String, N As Long, Omega As Double, Val() As Double, Rowptr() As Long, Colind() As Long, D() As Double, B() As Double, X() As Double, Optional Info As Long, Optional Base As Long=-1)
Symmetric successive over-relaxation (SSOR) preconditioner (CSR)
Sub CsxSsor(N As Long, Omega As Double, Val() As Double, Ptr() As Long, Ind() As Long, D() As Double, Optional Info As Long, Optional Base As Long=-1)
Initialize symmetric successive over-relaxation (SSOR) preconditioner (CSC/CSR)
Example Results
X = 0.86 0.64 0.51
Iter = 3, Res = 9.38872543636381E-16, Info = 0