| [48b662] | 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"
|
|---|
| [dfed1c] | 15 | #include "base/timer.hpp"
|
|---|
| [48b662] | 16 | #include "base/stencil.hpp"
|
|---|
| [dfed1c] | 17 | #include "comm/comm.hpp"
|
|---|
| [48b662] | 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 | {
|
|---|
| [dfed1c] | 25 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| [48b662] | 26 | sol.IsConsistent();
|
|---|
| 27 | rhs.IsConsistent();
|
|---|
| [dfed1c] | 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #ifdef DEBUG
|
|---|
| [48b662] | 31 | sol.IsCompatible(rhs);
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| [dfed1c] | 34 | Timer::Start("SmootherWithoutCommunication");
|
|---|
| 35 |
|
|---|
| 36 | Index i;
|
|---|
| [48b662] | 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();
|
|---|
| [dfed1c] | 41 | const int off = rhs.Global().BeginLocal().Sum() - rhs.Local().HasHalo1().Sum();
|
|---|
| [48b662] | 42 |
|
|---|
| [dfed1c] | 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) {
|
|---|
| [48b662] | 46 |
|
|---|
| [dfed1c] | 47 | temp = prefactor_inv * rhs.GetCorrectedVal(i);
|
|---|
| [48b662] | 48 |
|
|---|
| [dfed1c] | 49 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); ++iter)
|
|---|
| 50 | temp -= iter->Val() * sol.GetVal(i + iter->Disp());
|
|---|
| [48b662] | 51 |
|
|---|
| [dfed1c] | 52 | sol(i) = temp * diag_inv;
|
|---|
| [48b662] | 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| [dfed1c] | 56 | Timer::Stop("SmootherWithoutCommunication");
|
|---|
| [48b662] | 57 |
|
|---|
| [dfed1c] | 58 | MG::GetComm()->CommToGhosts(sol);
|
|---|
| [48b662] | 59 |
|
|---|
| [dfed1c] | 60 | Timer::Start("SmootherWithoutCommunication");
|
|---|
| [48b662] | 61 |
|
|---|
| [dfed1c] | 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;
|
|---|
| [48b662] | 72 |
|
|---|
| 73 | }
|
|---|
| [dfed1c] | 74 |
|
|---|
| 75 | Timer::Stop("SmootherWithoutCommunication");
|
|---|
| [48b662] | 76 | }
|
|---|