source: src/smoother/jacobi.cpp@ 06e153

Last change on this file since 06e153 was 4571da, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg: Implement fourth-order discretization of the Poisson equation.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1762 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file jacobi.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Fri Apr 27 19:50:36 2012
5 *
6 * @brief Jacobi smoother
7 *
8 */
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#ifdef HAVE_MPI
15#include <mpi.h>
16#endif
17
18#include "base/discretization.hpp"
19#include "base/stencil.hpp"
20#include "comm/comm.hpp"
21#include "grid/grid.hpp"
22#include "grid/tempgrid.hpp"
23#include "smoother/jacobi.hpp"
24#include "mg.hpp"
25
26using namespace VMG;
27
28static inline void ComputePartial(Grid& sol_new, const Grid& sol_old, const Grid& rhs,
29 const Stencil& mat, const GridIteratorSet& bounds,
30 const vmg_float& prefactor, const vmg_float& diag_inv)
31{
32 Grid::iterator grid_iter;
33 Stencil::iterator stencil_iter;
34
35 for (grid_iter=bounds.Begin(); grid_iter!=bounds.End(); ++grid_iter) {
36 sol_new(*grid_iter) = prefactor * rhs.GetVal(*grid_iter);
37 for (stencil_iter=mat.begin(); stencil_iter!=mat.end(); ++stencil_iter)
38 sol_new(*grid_iter) -= stencil_iter->Val() * sol_old.GetVal(*grid_iter + stencil_iter->Disp());
39 sol_new(*grid_iter) *= diag_inv;
40 }
41}
42
43void Jacobi::Compute(Grid& sol, Grid& rhs)
44{
45 Comm& comm = *MG::GetComm();
46 TempGrid& sol_new = *MG::GetTempGrid();
47
48 const Stencil& mat = MG::GetDiscretization()->GetStencil();
49 const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
50 const vmg_float diag_inv = 1.0 / mat.GetDiag();
51
52 sol_new.SetProperties(sol);
53
54 comm.CommToGhostsAsyncStart(sol);
55 ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().InnerLocalGrid(), prefactor_inv, diag_inv);
56 comm.CommToGhostsAsyncFinish(sol);
57
58 for (int i=0; i<3; ++i) {
59 ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().NearBoundary1()[i], prefactor_inv, diag_inv);
60 ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().NearBoundary2()[i], prefactor_inv, diag_inv);
61 }
62
63 sol.SetGrid(sol_new);
64}
Note: See TracBrowser for help on using the repository browser.