| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @file gs.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 13:07:44 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Gauss-Seidel method
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include <cassert>
|
|---|
| 15 |
|
|---|
| 16 | #include "base/discretization.hpp"
|
|---|
| 17 | #include "base/stencil.hpp"
|
|---|
| 18 | #include "grid/multigrid.hpp"
|
|---|
| 19 | #include "smoother/gs.hpp"
|
|---|
| 20 | #include "mg.hpp"
|
|---|
| 21 |
|
|---|
| 22 | using namespace VMG;
|
|---|
| 23 |
|
|---|
| 24 | void GaussSeidel::Compute(Grid& sol, Grid& rhs)
|
|---|
| 25 | {
|
|---|
| 26 | #ifdef DEBUG
|
|---|
| 27 | sol.IsConsistent();
|
|---|
| 28 | rhs.IsConsistent();
|
|---|
| 29 | sol.IsCompatible(rhs);
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | int i,j,k;
|
|---|
| 33 | vmg_float temp;
|
|---|
| 34 |
|
|---|
| 35 | const Stencil& A = MG::GetDiscretization()->GetStencil();
|
|---|
| 36 | const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
|
|---|
| 37 | const vmg_float diag_inv = 1.0 / A.GetDiag();
|
|---|
| 38 |
|
|---|
| 39 | for (i=rhs.Local().Begin().X(); i<rhs.Local().End().X(); i++)
|
|---|
| 40 | for (j=rhs.Local().Begin().Y(); j<rhs.Local().End().Y(); j++)
|
|---|
| 41 | for (k=rhs.Local().Begin().Z(); k<rhs.Local().End().Z(); k++) {
|
|---|
| 42 |
|
|---|
| 43 | temp = prefactor_inv * rhs.GetCorrectedVal(i, j, k);
|
|---|
| 44 |
|
|---|
| 45 | for (Stencil::iterator iter=A.begin(); iter!=A.end(); iter++) {
|
|---|
| 46 |
|
|---|
| 47 | assert(i+iter->m >= 0 && i+iter->m < sol.Local().SizeTotal().X());
|
|---|
| 48 | assert(j+iter->n >= 0 && j+iter->n < sol.Local().SizeTotal().Y());
|
|---|
| 49 | assert(k+iter->o >= 0 && k+iter->o < sol.Local().SizeTotal().Z());
|
|---|
| 50 |
|
|---|
| 51 | temp -= iter->val * sol.GetVal(i+iter->m, j+iter->n, k+iter->o);
|
|---|
| 52 |
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | sol(i, j, k) = temp * diag_inv;
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.