| 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/stencil.hpp"
|
|---|
| 16 | #include "grid/grid.hpp"
|
|---|
| 17 | #include "smoother/gsrb.hpp"
|
|---|
| 18 |
|
|---|
| 19 | using namespace VMG;
|
|---|
| 20 |
|
|---|
| 21 | void GaussSeidelRB::Compute(Grid& sol, Grid& rhs)
|
|---|
| 22 | {
|
|---|
| 23 | #ifdef DEBUG
|
|---|
| 24 | sol.IsConsistent();
|
|---|
| 25 | rhs.IsConsistent();
|
|---|
| 26 | sol.IsCompatible(rhs);
|
|---|
| 27 | #endif
|
|---|
| 28 |
|
|---|
| 29 | int i,j,k;
|
|---|
| 30 | vmg_float temp;
|
|---|
| 31 | const Stencil& A = MG::GetDiscretization()->GetStencil();
|
|---|
| 32 | const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
|
|---|
| 33 | const vmg_float diag_inv = 1.0 / A.GetDiag();
|
|---|
| 34 |
|
|---|
| 35 | for (i=rhs.Local().Begin().X(); i<rhs.Local().End().X(); i++)
|
|---|
| 36 | for (j=rhs.Local().Begin().Y(); j<rhs.Local().End().Y(); j++)
|
|---|
| 37 | for (k=rhs.Local().Begin().Z() + ((i+j+1) % 2); k<rhs.Local().End().Z(); k+=2) {
|
|---|
| 38 |
|
|---|
| 39 | temp = prefactor_inv * rhs.GetCorrectedVal(i,j,k);
|
|---|
| 40 |
|
|---|
| 41 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); iter++)
|
|---|
| 42 | temp -= iter->val * sol.GetVal(i+iter->m, j+iter->n, k+iter->o);
|
|---|
| 43 |
|
|---|
| 44 | sol(i, j, k) = temp * diag_inv;
|
|---|
| 45 |
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | for (i=rhs.Local().Begin().X(); i<rhs.Local().End().X(); i++)
|
|---|
| 49 | for (j=rhs.Local().Begin().Y(); j<rhs.Local().End().Y(); j++)
|
|---|
| 50 | for (k=rhs.Local().Begin().Z() + ((i+j) % 2); k<rhs.Local().End().Z(); k+=2) {
|
|---|
| 51 |
|
|---|
| 52 | temp = prefactor_inv * rhs.GetCorrectedVal(i,j,k);
|
|---|
| 53 |
|
|---|
| 54 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); iter++)
|
|---|
| 55 | temp -= iter->val * sol.GetVal(i+iter->m, j+iter->n, k+iter->o);
|
|---|
| 56 |
|
|---|
| 57 | sol(i, j, k) = temp * diag_inv;
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|