VERB4D
|
Solves model matrices for diffusion calculations and has functionality for derivative approximations of matrices. More...
#include "MatrixSolver.h"
#include <math.h>
#include <stdlib.h>
#include <string>
#include <ctime>
#include <iostream>
Functions | |
void | AddBoundary (DiagMatrix &matr_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_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_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_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. | |
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... | |
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.
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
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
matr_A,B,C | - calculation matrices |
LBC,UBC | for 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.
x | Coordinate x |
y | Coordinate y |
Coef1 | Coefficient outside of the term |
Coef2 | Coefficient 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.
x | Coordinate x |
y | Coordinate y |
Coef1 | Coefficient outside of the term |
Coef2 | Coefficient 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
which is approximatied using the method:
Done for a couple locations near x[ix] each location has a slightly modified equation
ix | index for current location |
FirstDerivative | determines whether first derivative approx. is with the point to the right or left of ix |
SecondDerivative | determines whether second derivative approx. is with the point to the right or left of ix |
x | x matrix |
D | Diffusion coefficient |
G | Jacobian |
multiplicator | multiplier 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.
The approximation is done in a similar fashion to SecondDerivativeApproximation_1D
Returns coefficients to be put into model matrix for an approximation of a second derivative.
x | Coordinate x |
y | Coordinate y |
D | Diffusion coefficient |
G | Jacobian |
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.
The approximation is done in a similar fashion to SecondDerivativeApproximation_1D
Returns coefficients to be put into model matrix for an approximation of a second derivative.
x | Coordinate x |
y | Coordinate y |
D | Diffusion coefficient |
G | Jacobian |
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),
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 |