source: src/level/level_operator_cs.cpp@ 32ff22

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

Parallel performance update.

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

  • Property mode set to 100644
File size: 3.7 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)
[894a5f]72 res += stencil_iter->Val() * temp->GetVal(iter_f->X() + stencil_iter->Disp().X(),
73 iter_f->Y() + stencil_iter->Disp().Y(),
74 iter_f->Z() + stencil_iter->Disp().Z());
[48b662]75
[dfed1c]76 rhs_c(*iter_c) = res;
[48b662]77
[dfed1c]78 }
[48b662]79
[dfed1c]80#ifdef DEBUG_MATRIX_CHECKS
81 rhs_c.IsConsistent();
82#endif
[48b662]83}
84
[dfed1c]85void LevelOperatorCS::Prolongate(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
[48b662]86{
[dfed1c]87#ifdef DEBUG_MATRIX_CHECKS
88 sol_c.IsConsistent();
89 rhs_c.IsConsistent();
90 sol_f.IsConsistent();
91 rhs_f.IsConsistent();
92#endif
93
[48b662]94#ifdef DEBUG
[dfed1c]95 sol_c.IsCompatible(rhs_c);
96 sol_f.IsCompatible(rhs_f);
[48b662]97#endif
98
[dfed1c]99 Grid::iterator iter_f, iter_c;
100 Stencil::iterator stencil_iter;
[48b662]101 vmg_float val;
102
103 const Stencil& op = OperatorProlongate();
[dfed1c]104 Comm* comm = MG::GetComm();
[48b662]105
[dfed1c]106 Index begin_f = sol_f.Local().Begin() + 2*sol_c.Global().BeginLocal() - sol_f.Global().BeginLocal();
107 Index end_f = sol_f.Local().End();
[48b662]108
[dfed1c]109 if (sol_c.Global().BoundaryType() == GlobalCoarsened)
110 for (int i=0; i<3; ++i) {
[48b662]111
[dfed1c]112 if (rhs_f.Local().HasBoundary1()[i])
113 ++begin_f[i];
[48b662]114
[dfed1c]115 if (rhs_f.Local().HasBoundary2()[i])
116 --end_f[i];
[48b662]117
[dfed1c]118 }
[48b662]119
[dfed1c]120 const GridIteratorSet bounds_f(begin_f, end_f);
121 const GridIteratorSet bounds_c(sol_c.Local().AlignmentBegin(), sol_c.Local().AlignmentEnd());
[48b662]122
[dfed1c]123 Index apply_stencil_begin, apply_stencil_end;
[48b662]124
[dfed1c]125 for (int i=0; i<3; ++i) {
126 apply_stencil_begin[i] = (sol_f.Local().HasBoundary1()[i] ? 1 : 0);
127 apply_stencil_end[i] = (sol_f.Local().HasBoundary2()[i] ? sol_f.Local().End()[i] : sol_f.Local().SizeTotal()[i]);
128 }
[48b662]129
[dfed1c]130 sol_f.ClearHalo();
[48b662]131
[dfed1c]132 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
133 val = sol_c.GetVal(*iter_c);
134 sol_f(*iter_f) += op.GetDiag() * val;
[894a5f]135 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
136 sol_f(iter_f->X() + stencil_iter->Disp().X(),
137 iter_f->Y() + stencil_iter->Disp().Y(),
138 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
[48b662]139 }
[dfed1c]140
141 comm->CommFromGhosts(sol_f);
[48b662]142}
Note: See TracBrowser for help on using the repository browser.