AFEPack
|
An algebraic multigrid solver. 更多...
#include <AMGSolver.h>
公有类型 | |
typedef SparseMatrix< double > | Matrix |
公有成员 | |
AMGSolver () | |
upper bound of the sparse degree of the last projected matrix | |
AMGSolver (const Matrix &, double tol=1.0e-12, u_int s=3, u_int nmpo=50, double nmpsd=0.382, double alp=0.25) | |
default constructor | |
virtual | ~AMGSolver () |
void | clear () |
destructor | |
double | tolerence () const |
clear memory used by the solver | |
double & | tolerence () |
u_int | smoothStep () const |
u_int & | smoothStep () |
bool & | isSolveMostProjectExactly () |
bool | isSolveMostProjectExactly () const |
void | reinit (const Matrix &) |
void | solve (Vector< double > &x, const Vector< double > &r, double tol=0.0, u_int step=20, int mode=0) const |
reinitialize using another matrix | |
void | lazyReinit (const Matrix &) |
私有成员 | |
void | lazyInit (const Matrix &) |
reinitialize using another matrix in lazy mode | |
void | lazyProject (const Matrix &M, Matrix *&P, Matrix *&PMPt, Matrix *&Pt) |
void | Project (const Matrix &M, Matrix *&P, Matrix *&PMPt) |
void | GaussSidel (const Matrix &M, Vector< double > &x, const Vector< double > &r, const int &s) const |
Matrix * | getPMPt (const Matrix &P, const Matrix &M, const Matrix &Pt) const |
私有属性 | |
bool | is_initialized |
u_int | n_project |
if the solver is initialized | |
std::vector< Matrix * > | project_matrix |
number of grid levels | |
std::vector< Matrix * > | project_matrix_r |
the left projection matrix | |
std::vector< const Matrix * > | projected_matrix |
the right projection matrix, which is the transpose of the left projection matrix | |
bool | is_most_project_full |
the projected matrix | |
bool | is_solve_most_project_exactly |
if the last projected matrix is full | |
FullMatrix< double > | M_n |
if use gauss-elimination to solve the most projected system exactly | |
double | toler |
if the last projected matrix is full, this is the inverse of this matrix | |
double | alpha |
tolerence | |
u_int | smooth_step |
the parameter for given C-point | |
u_int | n_most_project_order |
GS smooth step in every. | |
double | n_most_project_sparse_degree |
lower bound of the order of the last projected matrix |
An algebraic multigrid solver.
This is an implelementation of the algebraic multigrid solver for a general sparse matrix. The projection operators include a very simple element-free type operator and a comparative complex one. The simple one can be used for solving once for a sequence of systems with the same sparsity pattern(often in a time depended problem). It is faster in preparation but slower in solving. The mode can be accesed by the so-called lazy-mode. The complexier one can be used to solve one system for many times, since it is slower in preparation but faster in solving. The smoother is a Gauss-Sidel iteration. For the two projection operator, please refer Brezina etc, SIAM JSC 22(5), pp1570-1592 and Cleary etc, SIAM JSC 21(5), pp1888-1908.
The usage of this solver is quite simple. The following is an example:
SparseMatrix<double> M; Vector<double> x; Vector<double> rhs; ... ... AMGSolver amg_solver(M); amg_solver.solve(x, rhs);
For the lazy mode, we often want to solve a sequence of systems as follows:
SparseMatrix<double> M; Vector<double> x; Vector<double> rhs; AMGSolver amg_solver; ... ... while (1) { amg_solver.lazyReinit(M); amg_solver.solve(x, rhs); ... ... // made some changes to the matrix }
typedef SparseMatrix<double> AMGSolver::Matrix |
upper bound of the sparse degree of the last projected matrix
AMGSolver::AMGSolver | ( | const Matrix & | m, |
double | tol = 1.0e-12 , |
||
u_int | s = 3 , |
||
u_int | nmpo = 50 , |
||
double | nmpsd = 0.382 , |
||
double | alp = 0.25 |
||
) |
default constructor
AMGSolver::~AMGSolver | ( | ) | [virtual] |
void AMGSolver::clear | ( | ) |
destructor
void AMGSolver::GaussSidel | ( | const Matrix & | M, |
Vector< double > & | x, | ||
const Vector< double > & | r, | ||
const int & | s | ||
) | const [private] |
Matrix * AMGSolver::getPMPt | ( | const Matrix & | P, |
const Matrix & | M, | ||
const Matrix & | Pt | ||
) | const [private] |
< add the diagonal entry at first
bool& AMGSolver::isSolveMostProjectExactly | ( | ) | [inline] |
bool AMGSolver::isSolveMostProjectExactly | ( | ) | const [inline] |
void AMGSolver::lazyInit | ( | const Matrix & | M | ) | [private] |
reinitialize using another matrix in lazy mode
void AMGSolver::lazyProject | ( | const Matrix & | M, |
Matrix *& | P, | ||
Matrix *& | PMPt, | ||
Matrix *& | Pt | ||
) | [private] |
This is the Project subroutine for fast project to solve without high accuracy requirement.
< this row is handled already
void AMGSolver::lazyReinit | ( | const Matrix & | M | ) |
to solve a linear system with the same sparsity pattern as already initialized matrix
void AMGSolver::Project | ( | const Matrix & | M, |
Matrix *& | P, | ||
Matrix *& | PMPt | ||
) | [private] |
choose the core points and influenced points. the procedure is divided into two steps: the first step is to choose the dependent and influenced points.
0: candidate to be C-point 1: F-point -1: C-point
calculate the threshhold to construct the influence set
if this point is not a candidate
label the F-points around this C-point
label this point as C-point
the second step is to check if there are influenced points without common dependent point. if such case occured, we add one of the point to be a dependent point.
if this point is not a F-point
calculate the threshhold to construct the influence set and collect the C-points around this point
check its connected points if there are F-F connection
this is a C-point
this case should have been handled
this is a weak connection
the point selected is now strongly connected to this point and it is a F-point. we check if there are common entries between the C-points around this point and the point selected. if found, this is not a F-F connection; otherwise, it is.
if there is a F-F connection, we label this point to be C-point
then collect the information to construct the project matrix
construct the sparsity pattern for the project matrix
fill the entries for the project matrix
Maybe error, F-F has no common dependence
prepare data for constructing the projected matrix
void AMGSolver::reinit | ( | const Matrix & | M | ) |
u_int AMGSolver::smoothStep | ( | ) | const [inline] |
u_int& AMGSolver::smoothStep | ( | ) | [inline] |
void AMGSolver::solve | ( | Vector< double > & | x, |
const Vector< double > & | r, | ||
double | tol = 0.0 , |
||
u_int | step = 20 , |
||
int | mode = 0 |
||
) | const |
reinitialize using another matrix
solve the linear system with $x$ as solution and $r$ as right hand side.
x | the solution vector |
r | the right hand side vector |
tol | tolerence |
step | upper bound of iteration step |
mode | 0: solve mode; 1: precondition mode |
double AMGSolver::tolerence | ( | ) | const [inline] |
clear memory used by the solver
double& AMGSolver::tolerence | ( | ) | [inline] |
double AMGSolver::alpha [private] |
tolerence
bool AMGSolver::is_initialized [private] |
bool AMGSolver::is_most_project_full [private] |
the projected matrix
bool AMGSolver::is_solve_most_project_exactly [private] |
if the last projected matrix is full
FullMatrix<double> AMGSolver::M_n [private] |
if use gauss-elimination to solve the most projected system exactly
u_int AMGSolver::n_most_project_order [private] |
GS smooth step in every.
double AMGSolver::n_most_project_sparse_degree [private] |
lower bound of the order of the last projected matrix
u_int AMGSolver::n_project [private] |
if the solver is initialized
std::vector<Matrix *> AMGSolver::project_matrix [private] |
number of grid levels
std::vector<Matrix *> AMGSolver::project_matrix_r [private] |
the left projection matrix
std::vector<const Matrix *> AMGSolver::projected_matrix [private] |
the right projection matrix, which is the transpose of the left projection matrix
u_int AMGSolver::smooth_step [private] |
the parameter for given C-point
double AMGSolver::toler [private] |
if the last projected matrix is full, this is the inverse of this matrix