| 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 |
|
|---|
| 26 | using namespace VMG;
|
|---|
| 27 |
|
|---|
| 28 | static 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 |
|
|---|
| 43 | void 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 | }
|
|---|