source: src/level/level_operator_cs.cpp@ 01be70

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