VERB4D
Functions
MatrixSolver.h File Reference

Solves model matrices for diffusion calculations and has functionality for derivative approximations of matrices. More...

#include "Matrix.h"

Go to the source code of this file.

Functions

void AddBoundary (DiagMatrix &Matrix_A, string type, int in, int id1, double dh)
 
bool AddBoundaries_1D (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix1D< double > &x, int x_size, double x_LBC, double x_UBC, string x_LBC_type, string x_UBC_type, int ix)
 
bool AddBoundaries_2D (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string &x_LBC_type, string &x_UBC_type, string &y_LBC_type, string &y_UBC_type, int ix, int iy, int in)
 
bool MakeModelMatrix_2D (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > &x_LBC, Matrix1D< double > &x_UBC, Matrix1D< double > &y_LBC, Matrix1D< double > &y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, Matrix2D< double > Sources, Matrix2D< double > Losses, double dt)
 FUNCITON NOT IMPLEMENTED.
 
void Lapack (DiagMatrix &A, Matrix1D< double > &B, Matrix1D< double > &X)
 
void SecondDerivativeApproximation_1D (CalculationMatrix &matr_A, int ix, string FirstDerivative, string SecondDerivative, Matrix1D< double > &x, Matrix1D< double > &D, Matrix1D< double > &G, double multiplicator)
 
void GetDerivativeVector_2D (string derivativeType, int &dx, int &dy)
 
void SecondDerivativeApproximation_2D (CalculationMatrix &matr_A, int ix, int iy, string FirstDerivative, string SecondDerivative, Matrix2D< double > &x, Matrix2D< double > &y, Matrix2D< double > &D, Matrix2D< double > &G, double multiplicator)
 
void SecondDerivativeApproximation_2D_y (CalculationMatrix &matr_A, int ix, int iy, string FirstDerivative, string SecondDerivative, Matrix2D< double > &x, Matrix2D< double > &y, Matrix2D< double > &D, Matrix2D< double > &G, double multiplicator)
 
void AnySecondDerivativeApproximation_2D (CalculationMatrix &matr_A, int ix, int iy, string FirstDerivative, string SecondDerivative, Matrix2D< double > &x, Matrix2D< double > &y, Matrix2D< double > &Coef1, Matrix2D< double > &Coef2, double multiplicator)
 
void AnySecondDerivativeApproximation_2D_y (CalculationMatrix &matr_A, int ix, int iy, string FirstDerivative, string SecondDerivative, Matrix2D< double > &x, Matrix2D< double > &y, Matrix2D< double > &Coef1, Matrix2D< double > &Coef2, double multiplicator)
 
bool tridag (double a[], double b[], double c[], double r[], double u[], long n)
 Solve the AU=R system of equations, where A - tridiagonal matrix nxn with diagonals a[], b[], c[]. More...
 
void dgbsv_ (long int *n, long int *kl, long int *ku, long int *nrhs, double *ab, long int *ldab, long int *ipiv, double *b, long int *ldb, long int *info)
 Lapack function for matrix inversion declaration.
 
bool MakeModelMatrix_2D_ADI1_x (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 
bool MakeModelMatrix_2D_ADI1_y (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 
bool MakeModelMatrix_2D_ADI2_x (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 
bool MakeModelMatrix_2D_ADI2_y (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 
bool MakeModelMatrix_2D_ADI3_y (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 
bool MakeModelMatrix_2D_ADI3_x (CalculationMatrix &matr_A, CalculationMatrix &matr_B, CalculationMatrix &matr_C, Matrix2D< double > &x, Matrix2D< double > &y, int x_size, int y_size, Matrix1D< double > x_LBC, Matrix1D< double > x_UBC, Matrix1D< double > y_LBC, Matrix1D< double > y_UBC, string x_LBC_type, string x_UBC_type, string y_LBC_type, string y_UBC_type, Matrix2D< double > &Dxx, Matrix2D< double > &Dyy, Matrix2D< double > &Dxy, Matrix2D< double > &Dyx, Matrix2D< double > &G, double dt)
 THIS FUNCTION IS CURRENTLY NOT BEING USED.
 

Detailed Description

Solves model matrices for diffusion calculations and has functionality for derivative approximations of matrices.

Making model matrixes, solving model matrixes.

Matrix form of linear equations: A*X[t+1] = B*X[t], where A - model matrix, B - RHS, X[t] - known values of function (PSD), X[t+1] - unknown values of function.

In that file there are procedures for making model matrix for 1d-diffusion, 2d-diffusion, some ideas of 3d-diffusion and mixed terms. Solver for tridiagonal matrix, solver by gauss method and iteration method (upper relaxation).

This file is under development, and has a lot of commented code, unfinished etc code.

There is a checked version for 1d diffusion (or split method of 2d, 3d diffusions) - 1d_universal_solver.

Author
Developed under supervision of the PI Yuri Shprits

Function Documentation

bool AddBoundaries_1D ( CalculationMatrix matr_A,
CalculationMatrix matr_B,
CalculationMatrix matr_C,
Matrix1D< double > &  x,
int  x_size,
double  x_LBC,
double  x_UBC,
string  x_LBC_type,
string  x_UBC_type,
int  ix 
)

Adds in the upper and lower boundaries for the 1D case when x is at first or last index

Parameters
matr_A,B,C- calculation matrices
x_LBC,x_UBC,x_LBC_type,x_UBC_type- predefined 1D boundaries/types
bool AddBoundaries_2D ( CalculationMatrix matr_A,
CalculationMatrix matr_B,
CalculationMatrix matr_C,
Matrix2D< double > &  x,
Matrix2D< double > &  y,
int  x_size,
int  y_size,
Matrix1D< double >  x_LBC,
Matrix1D< double >  x_UBC,
Matrix1D< double >  y_LBC,
Matrix1D< double >  y_UBC,
string &  x_LBC_type,
string &  x_UBC_type,
string &  y_LBC_type,
string &  y_UBC_type,
int  ix,
int  iy,
int  in 
)

Adds in the upper and lower boundaries for the 2D case when x or y is at first or last index

Parameters
matr_A,B,C- calculation matrices
LBC,UBCfor x and y - predefined 2D boundaries/types
void AddBoundary ( DiagMatrix matr_A,
string  type,
int  in,
int  id1,
double  dh 
)

Supportive sub-function to add boundary conditions to model matrix

void AnySecondDerivativeApproximation_2D ( CalculationMatrix matr_A,
int  ix,
int  iy,
string  FirstDerivative,
string  SecondDerivative,
Matrix2D< double > &  x,
Matrix2D< double > &  y,
Matrix2D< double > &  Coef1,
Matrix2D< double > &  Coef2,
double  multiplicator 
)

Second derivative approximation, returns coefficients to be put into the model matrix. $ \frac {m Coef1 Coef2}{\frac{d}{dx} \frac{d}{dy}} $

Parameters
xCoordinate x
yCoordinate y
Coef1Coefficient outside of the term
Coef2Coefficient inside the first derivative
void AnySecondDerivativeApproximation_2D_y ( CalculationMatrix matr_A,
int  ix,
int  iy,
string  FirstDerivative,
string  SecondDerivative,
Matrix2D< double > &  x,
Matrix2D< double > &  y,
Matrix2D< double > &  Coef1,
Matrix2D< double > &  Coef2,
double  multiplicator 
)

Second derivative approximation in the y direction first, returns coefficients to be put into the model matrix. $ \frac {m Coef1 Coef2}{\frac{d}{dx} \frac{d}{dy}} $

Parameters
xCoordinate x
yCoordinate y
Coef1Coefficient outside of the term
Coef2Coefficient inside the first derivative
void GetDerivativeVector_2D ( string  derivativeType,
int &  dx,
int &  dy 
)

Get change in indexes according to the derivatives direction.

Used in approximation. If it gets derivativeType == DT_ALPHA_left, for example, that means we have alpha-left-derivative, which is ( f(alpha) - f(alpha-1) ) / ( delta alpha ). So it returns dAlpha = -1, as a derivative direction vector.

void Lapack ( DiagMatrix A,
Matrix1D< double > &  B,
Matrix1D< double > &  X 
)

Lapack inversion.

A * X = B - equation

LAPACK - Linear Algebra PACKage. For linear algebra methods. Using the lapack library from http://www.netlib.org/lapack/

void SecondDerivativeApproximation_1D ( CalculationMatrix matr_A,
int  ix,
string  FirstDerivative,
string  SecondDerivative,
Matrix1D< double > &  x,
Matrix1D< double > &  D,
Matrix1D< double > &  G,
double  multiplicator 
)

numerical derivative approximation of a matrix in 1D

$ Coef1 \frac{d}{dx} $ which is approximatied using the method:

$ \frac{m G(x) D(x)}{[f(x) - f'(x)]G(x)[(f(x) - f''(x))]} $

Done for a couple locations near x[ix] each location has a slightly modified equation

Parameters
ixindex for current location
FirstDerivativedetermines whether first derivative approx. is with the point to the right or left of ix
SecondDerivativedetermines whether second derivative approx. is with the point to the right or left of ix
xx matrix
DDiffusion coefficient
GJacobian
multiplicatormultiplier based on number of iterations done (m)
void SecondDerivativeApproximation_2D ( CalculationMatrix matr_A,
int  ix,
int  iy,
string  FirstDerivative,
string  SecondDerivative,
Matrix2D< double > &  x,
Matrix2D< double > &  y,
Matrix2D< double > &  D,
Matrix2D< double > &  G,
double  multiplicator 
)

Second derivative approximation, returns coefficients to be put into the model matrix.

$ Coef1 \frac{d}{dx} * Coef2 \frac{df}{dy} $

The approximation is done in a similar fashion to SecondDerivativeApproximation_1D

$ \frac{m G(x,y) D(x,y)}{[f(x,y) - f'(x , y)]G(x,y)[(f(x,y) - f''(x , y)]} $

Returns coefficients to be put into model matrix for an approximation of a second derivative.

Parameters
xCoordinate x
yCoordinate y
DDiffusion coefficient
GJacobian
void SecondDerivativeApproximation_2D_y ( CalculationMatrix matr_A,
int  ix,
int  iy,
string  FirstDerivative,
string  SecondDerivative,
Matrix2D< double > &  x,
Matrix2D< double > &  y,
Matrix2D< double > &  D,
Matrix2D< double > &  G,
double  multiplicator 
)

Second derivative approximation in the y direction first, returns coefficients to be put into the model matrix.

$ Coef1 \frac{d}{dx} * Coef2 \frac{df}{dy} $

The approximation is done in a similar fashion to SecondDerivativeApproximation_1D

$ \frac{m G(x,y) D(x,y)}{[f(x,y) - f'(x , y )]G(x,y)[(f(x,y) - f''(x , y)]} $

Returns coefficients to be put into model matrix for an approximation of a second derivative.

Parameters
xCoordinate x
yCoordinate y
DDiffusion coefficient
GJacobian
bool tridag ( double  a[],
double  b[],
double  c[],
double  r[],
double  u[],
long  n 
)

Solve the AU=R system of equations, where A - tridiagonal matrix nxn with diagonals a[], b[], c[].

Solver for a system of equations with 3-diagonal matrix.

Au = r Where A = diag(a, b, c),

Parameters
a[]- array, diagonal '-1' of the matrix
b[]- array, diagonal '0' of the matrix
c[]- array, diagonal '+1' of the matrix
r[]- array, r-vector - the Right Hand Side (RHS)
u[]- array, result
n- size of the matrix