source: src/level/level_operator_cs.cpp@ 894a5f

Last change on this file since 894a5f 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
Line 
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"
16#include "grid/grid_iterator.hpp"
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
24void LevelOperatorCS::Restrict(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
25{
26#ifdef DEBUG_MATRIX_CHECKS
27 sol_f.IsConsistent();
28 rhs_f.IsConsistent();
29#endif
30
31#ifdef DEBUG
32 sol_f.IsCompatible(rhs_f);
33#endif
34
35 Grid::iterator iter_f, iter_c;
36 Stencil::iterator stencil_iter;
37 vmg_float res;
38
39 const Stencil& op = OperatorRestrict();
40
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];
50
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());
58
59 // Compute residual
60 TempGrid *temp = MG::GetTempGrid();
61 temp->SetProperties(sol_f);
62 temp->ImportFromResidual(sol_f, rhs_f);
63
64 if (rhs_c.Global().BoundaryType() == GlobalCoarsened)
65 rhs_c.ClearBoundary();
66
67 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
68
69 res = op.GetDiag() * temp->GetVal(*iter_f);
70
71 for (stencil_iter=op.begin(); stencil_iter!=op.end(); ++stencil_iter)
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());
75
76 rhs_c(*iter_c) = res;
77
78 }
79
80#ifdef DEBUG_MATRIX_CHECKS
81 rhs_c.IsConsistent();
82#endif
83}
84
85void LevelOperatorCS::Prolongate(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
86{
87#ifdef DEBUG_MATRIX_CHECKS
88 sol_c.IsConsistent();
89 rhs_c.IsConsistent();
90 sol_f.IsConsistent();
91 rhs_f.IsConsistent();
92#endif
93
94#ifdef DEBUG
95 sol_c.IsCompatible(rhs_c);
96 sol_f.IsCompatible(rhs_f);
97#endif
98
99 Grid::iterator iter_f, iter_c;
100 Stencil::iterator stencil_iter;
101 vmg_float val;
102
103 const Stencil& op = OperatorProlongate();
104 Comm* comm = MG::GetComm();
105
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();
108
109 if (sol_c.Global().BoundaryType() == GlobalCoarsened)
110 for (int i=0; i<3; ++i) {
111
112 if (rhs_f.Local().HasBoundary1()[i])
113 ++begin_f[i];
114
115 if (rhs_f.Local().HasBoundary2()[i])
116 --end_f[i];
117
118 }
119
120 const GridIteratorSet bounds_f(begin_f, end_f);
121 const GridIteratorSet bounds_c(sol_c.Local().AlignmentBegin(), sol_c.Local().AlignmentEnd());
122
123 Index apply_stencil_begin, apply_stencil_end;
124
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 }
129
130 sol_f.ClearHalo();
131
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;
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;
139 }
140
141 comm->CommFromGhosts(sol_f);
142}
Note: See TracBrowser for help on using the repository browser.