| 1 | /**
|
|---|
| 2 | * @file gsrb.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 13:08:20 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Gauss-Seidel Red Black method
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include "base/discretization.hpp"
|
|---|
| 15 | #include "base/timer.hpp"
|
|---|
| 16 | #include "base/stencil.hpp"
|
|---|
| 17 | #include "comm/comm.hpp"
|
|---|
| 18 | #include "grid/grid.hpp"
|
|---|
| 19 | #include "smoother/gsrb.hpp"
|
|---|
| 20 |
|
|---|
| 21 | using namespace VMG;
|
|---|
| 22 |
|
|---|
| 23 | void GaussSeidelRB::Compute(Grid& sol, Grid& rhs)
|
|---|
| 24 | {
|
|---|
| 25 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 26 | sol.IsConsistent();
|
|---|
| 27 | rhs.IsConsistent();
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #ifdef DEBUG
|
|---|
| 31 | sol.IsCompatible(rhs);
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | Timer::Start("SmootherWithoutCommunication");
|
|---|
| 35 |
|
|---|
| 36 | Index i;
|
|---|
| 37 | vmg_float temp;
|
|---|
| 38 | const Stencil& A = MG::GetDiscretization()->GetStencil();
|
|---|
| 39 | const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
|
|---|
| 40 | const vmg_float diag_inv = 1.0 / A.GetDiag();
|
|---|
| 41 | const int off = rhs.Global().BeginLocal().Sum() - rhs.Local().HasHalo1().Sum();
|
|---|
| 42 |
|
|---|
| 43 | for (i.X()=rhs.Local().Begin().X(); i.X()<rhs.Local().End().X(); ++i.X())
|
|---|
| 44 | for (i.Y()=rhs.Local().Begin().Y(); i.Y()<rhs.Local().End().Y(); ++i.Y())
|
|---|
| 45 | for (i.Z()=rhs.Local().Begin().Z() + ((i.X()+i.Y()+off+1) % 2); i.Z()<rhs.Local().End().Z(); i.Z()+=2) {
|
|---|
| 46 |
|
|---|
| 47 | temp = prefactor_inv * rhs.GetCorrectedVal(i);
|
|---|
| 48 |
|
|---|
| 49 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); ++iter)
|
|---|
| 50 | temp -= iter->Val() * sol.GetVal(i + iter->Disp());
|
|---|
| 51 |
|
|---|
| 52 | sol(i) = temp * diag_inv;
|
|---|
| 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | Timer::Stop("SmootherWithoutCommunication");
|
|---|
| 57 |
|
|---|
| 58 | MG::GetComm()->CommToGhosts(sol);
|
|---|
| 59 |
|
|---|
| 60 | Timer::Start("SmootherWithoutCommunication");
|
|---|
| 61 |
|
|---|
| 62 | for (i.X()=rhs.Local().Begin().X(); i.X()<rhs.Local().End().X(); ++i.X())
|
|---|
| 63 | for (i.Y()=rhs.Local().Begin().Y(); i.Y()<rhs.Local().End().Y(); ++i.Y())
|
|---|
| 64 | for (i.Z()=rhs.Local().Begin().Z() + ((i.X()+i.Y()+off) % 2); i.Z()<rhs.Local().End().Z(); i.Z()+=2) {
|
|---|
| 65 |
|
|---|
| 66 | temp = prefactor_inv * rhs.GetCorrectedVal(i);
|
|---|
| 67 |
|
|---|
| 68 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); ++iter)
|
|---|
| 69 | temp -= iter->Val() * sol.GetVal(i + iter->Disp());
|
|---|
| 70 |
|
|---|
| 71 | sol(i) = temp * diag_inv;
|
|---|
| 72 |
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | Timer::Stop("SmootherWithoutCommunication");
|
|---|
| 76 | }
|
|---|