source: src/level/level_operator_cs.cpp@ dfed1c

Last change on this file since dfed1c was dfed1c, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Major vmg update.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1136 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[48b662]1/**
2 * @file level_operator_cs.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 12:59:46 2011
5 *
6 * @brief VMG::LevelOperatorCS
7 *
8 */
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#include "base/index.hpp"
15#include "comm/comm.hpp"
[dfed1c]16#include "grid/grid_iterator.hpp"
[48b662]17#include "grid/multigrid.hpp"
18#include "grid/tempgrid.hpp"
19#include "level/level_operator_cs.hpp"
20#include "mg.hpp"
21
22using namespace VMG;
23
[dfed1c]24void LevelOperatorCS::Restrict(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
[48b662]25{
[dfed1c]26#ifdef DEBUG_MATRIX_CHECKS
27 sol_f.IsConsistent();
28 rhs_f.IsConsistent();
29#endif
30
[48b662]31#ifdef DEBUG
[dfed1c]32 sol_f.IsCompatible(rhs_f);
[48b662]33#endif
34
[dfed1c]35 Grid::iterator iter_f, iter_c;
36 Stencil::iterator stencil_iter;
[48b662]37 vmg_float res;
38
39 const Stencil& op = OperatorRestrict();
40
[dfed1c]41 Index begin_f = rhs_f.Local().Begin() + 2*rhs_c.Global().BeginLocal() - rhs_f.Global().BeginLocal();
42 Index end_f = rhs_f.Local().End();
43
44 /* Modify fine begin/end to align the points on both levels correctly */
45 if (rhs_c.Global().BoundaryType() == GlobalCoarsened)
46 for (int i=0; i<3; ++i) {
47
48 if (rhs_c.Local().HasBoundary1()[i])
49 ++begin_f[i];
[48b662]50
[dfed1c]51 if (rhs_c.Local().HasBoundary2()[i])
52 --end_f[i];
53
54 }
55
56 const GridIteratorSet bounds_f(begin_f, end_f);
57 const GridIteratorSet bounds_c(rhs_c.Local().AlignmentBegin(), rhs_c.Local().AlignmentEnd());
[48b662]58
59 // Compute residual
60 TempGrid *temp = MG::GetTempGrid();
[dfed1c]61 temp->SetProperties(sol_f);
62 temp->ImportFromResidual(sol_f, rhs_f);
[48b662]63
[dfed1c]64 if (rhs_c.Global().BoundaryType() == GlobalCoarsened)
65 rhs_c.ClearBoundary();
[48b662]66
[dfed1c]67 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
[48b662]68
[dfed1c]69 res = op.GetDiag() * temp->GetVal(*iter_f);
[48b662]70
[dfed1c]71 for (stencil_iter=op.begin(); stencil_iter!=op.end(); ++stencil_iter)
72 res += stencil_iter->Val() * temp->GetVal(*iter_f + stencil_iter->Disp());
[48b662]73
[dfed1c]74 rhs_c(*iter_c) = res;
[48b662]75
[dfed1c]76 }
[48b662]77
[dfed1c]78#ifdef DEBUG_MATRIX_CHECKS
79 rhs_c.IsConsistent();
80#endif
[48b662]81}
82
[dfed1c]83void LevelOperatorCS::Prolongate(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
[48b662]84{
[dfed1c]85#ifdef DEBUG_MATRIX_CHECKS
86 sol_c.IsConsistent();
87 rhs_c.IsConsistent();
88 sol_f.IsConsistent();
89 rhs_f.IsConsistent();
90#endif
91
[48b662]92#ifdef DEBUG
[dfed1c]93 sol_c.IsCompatible(rhs_c);
94 sol_f.IsCompatible(rhs_f);
[48b662]95#endif
96
[dfed1c]97 Grid::iterator iter_f, iter_c;
98 Stencil::iterator stencil_iter;
[48b662]99 vmg_float val;
100
101 const Stencil& op = OperatorProlongate();
[dfed1c]102 Comm* comm = MG::GetComm();
[48b662]103
[dfed1c]104 Index begin_f = sol_f.Local().Begin() + 2*sol_c.Global().BeginLocal() - sol_f.Global().BeginLocal();
105 Index end_f = sol_f.Local().End();
[48b662]106
[dfed1c]107 if (sol_c.Global().BoundaryType() == GlobalCoarsened)
108 for (int i=0; i<3; ++i) {
[48b662]109
[dfed1c]110 if (rhs_f.Local().HasBoundary1()[i])
111 ++begin_f[i];
[48b662]112
[dfed1c]113 if (rhs_f.Local().HasBoundary2()[i])
114 --end_f[i];
[48b662]115
[dfed1c]116 }
[48b662]117
[dfed1c]118 const GridIteratorSet bounds_f(begin_f, end_f);
119 const GridIteratorSet bounds_c(sol_c.Local().AlignmentBegin(), sol_c.Local().AlignmentEnd());
[48b662]120
[dfed1c]121 Index apply_stencil_begin, apply_stencil_end;
[48b662]122
[dfed1c]123 for (int i=0; i<3; ++i) {
124 apply_stencil_begin[i] = (sol_f.Local().HasBoundary1()[i] ? 1 : 0);
125 apply_stencil_end[i] = (sol_f.Local().HasBoundary2()[i] ? sol_f.Local().End()[i] : sol_f.Local().SizeTotal()[i]);
126 }
[48b662]127
[dfed1c]128 sol_f.ClearHalo();
[48b662]129
[dfed1c]130 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
[48b662]131
[dfed1c]132 val = sol_c.GetVal(*iter_c);
[48b662]133
[dfed1c]134 sol_f(*iter_f) += op.GetDiag() * val;
[48b662]135
[dfed1c]136 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter) {
[48b662]137
[dfed1c]138 sol_f(*iter_f + stencil_iter->Disp()) += stencil_iter->Val() * val;
[48b662]139
[dfed1c]140 }
[48b662]141
142 }
[dfed1c]143
144 comm->CommFromGhosts(sol_f);
[48b662]145}
Note: See TracBrowser for help on using the repository browser.