Go to the documentation of this file.
17 const double omega = 1.0;
18 const int maxiter = 1000;
19 const double tol = 1
e-6,
22 int nrows = SK.
Nrows();
23 assert( nrows ==
static_cast<int>(f.size()) && f.size() ==
u.size() );
25 cout << endl <<
" Start Jacobi solver for " << nrows <<
" d.o.f.s" << endl;
27 for (
int k = 0; k < nrows; ++k) {
31 vector<double> dd(nrows);
32 vector<double> r(nrows);
33 vector<double> w(nrows);
42 const double sigma0 =
dscapr(w, r);
46 double sigma = sigma0;
47 while ( sigma > tol2 * sigma0 && maxiter > iter)
57 cout <<
"aver. Jacobi rate : " << exp(log(sqrt(sigma / sigma0)) / iter) <<
" (" << iter <<
" iter)" << endl;
58 cout <<
"final error: " << sqrt(sigma / sigma0) <<
" (rel) " << sqrt(sigma) <<
" (abs)\n";
66 std::vector<double> &r,
int nsmooth,
double const omega,
bool zero)
70 int const nnodes =
static_cast<int>(
u.size());
77 for (
int ns = 1; ns <= nsmooth; ++ns) {
79 #pragma omp parallel for
80 for (
int k = 0; k <
nnodes; ++k) {
82 u[k] =
u[k] + omega * r[k] / D[k];
94 int const nnodes =
static_cast<int>(w.size());
95 #pragma omp parallel for
96 for (
int k = 0; k <
nnodes; ++k) {
97 w[k] = omega * r[k] / D[k];
105 : _meshes(cmesh, nlevel),
106 _SK(), _u(_meshes.
size()), _f(_meshes.
size()), _d(_meshes.
size()), _w(_meshes.
size()),
109 cout <<
"\n........................ in Multigrid::Multigrid ..................\n";
111 for (
size_t lev = 0; lev <
Nlevels(); ++lev) {
113 const auto nn =
_SK[lev].Nrows();
118 auto vv =
_meshes[lev].GetFathersOfVertices();
119 cout << vv.
size() << endl;
125 for (
size_t lev = 1; lev <
Nlevels(); ++lev) {
131 cout <<
"\n..........................................\n";
139 for (
size_t lev = 0; lev <
Nlevels(); ++lev) {
148 _SK[lev].CalculateLaplace(
_f[lev]);
151 _meshes[lev].SetValues(
_u[lev], [](
double x,
double y) ->
double
152 {
return x *x * std::sin(2.5 * M_PI * y); }
159 _SK[lev].ApplyDirichletBC(
_u[lev],
_f[lev]);
173 int const post_smooth = pre_smooth;
183 _SK[lev].Defect(
_d[lev],
_f[lev],
_u[lev]);
189 MG_Step(lev - 1, pre_smooth,
true, nu);
190 for (
int k = 1; k < nu; ++k) {
192 MG_Step(lev - 1, pre_smooth,
false, nu);
221 MG_Step(lev, pre_smooth, bzero, nu);
223 _SK[lev].Defect(
_d[lev],
_f[lev],
_u[lev]);
228 }
while (si>s0*eps*eps);
231 cout <<
"\nrel. error: " << sqrt(si/s0) <<
" ( " << iter <<
" iter.)" << endl;
void MG_Solve(int pre_smooth=1, double eps=1e-6, int nu=1)
std::vector< std::vector< double > > _w
Correction vector on each level.
std::vector< std::vector< double > > _d
Defect vector on each level.
void MG_Step(size_t lev, int pre_smooth=1, bool const bzero=false, int nu=1)
gMesh_Hierarchy _meshes
mesh hierarchy from coarse (level 0) to fine.
void JacobiSmoother(Matrix const &SK, std::vector< double > const &f, std::vector< double > &u, std::vector< double > &r, int nsmooth, double const omega, bool zero)
void JacobiSolve(size_t lev)
virtual void GetDiag(std::vector< double > &d) const =0
void Defect(std::vector< double > &w, std::vector< double > const &f, std::vector< double > const &u) const override
std::vector< std::vector< double > > _f
Right hand side vector on each level.
virtual void Defect(std::vector< double > &w, std::vector< double > const &f, std::vector< double > const &u) const =0
void vdaxpy(std::vector< double > &x, std::vector< double > const &y, double alpha, std::vector< double > const &z)
Element-wise daxpy operation x(k) = y(k) + alpha*z(k).
double dscapr(std::vector< double > const &x, std::vector< double > const &y)
Calculates the Euclidean inner product of two vectors.
void vddiv(vector< double > &x, vector< double > const &y, vector< double > const &z)
std::vector< BisectIntDirichlet > _Pc2f
Interpolation to level from next coarser level.
void JacobiSolve(CRS_Matrix const &SK, vector< double > const &f, vector< double > &u)
double f_zero(double const x, double const y)
void GetDiag(std::vector< double > &d) const override
void DefineOperator(size_t lev)
std::vector< std::vector< double > > _u
Solution vector on each level.
std::vector< FEM_Matrix > _SK
Sparse matrix on each level.
void DiagPrecond(Matrix const &SK, std::vector< double > const &r, std::vector< double > &w, double const omega)
Simple diagonale preconditioning.
Multigrid(Mesh const &cmesh, int nlevel)