source: src/level/level_operator_cs.cpp@ 48b662

Last change on this file since 48b662 was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

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

  • Property mode set to 100644
File size: 4.2 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"
16#include "grid/multigrid.hpp"
17#include "grid/tempgrid.hpp"
18#include "level/level_operator_cs.hpp"
19#include "mg.hpp"
20
21using namespace VMG;
22
23void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
24{
25#ifdef DEBUG
26 sol().IsConsistent();
27 rhs().IsConsistent();
28 sol().IsCompatible(rhs());
29#endif
30
31 Index i_c, i_f;
32 Stencil::iterator iter;
33 vmg_float res;
34
35 const int l_f = rhs.Level();
36 const int l_c = l_f - 1;
37
38 Index begin_f = rhs().Local().Begin();
39 const Index end_f = rhs().Local().End() - 1;
40 const Index begin_c = rhs(l_c).Local().AlignmentBegin();
41 const Stencil& op = OperatorRestrict();
42
43 if (sol(l_c).Global().BoundaryType() == GlobalCoarsened &&
44 (MG::GetComm()->BoundaryConditions() == Dirichlet || MG::GetComm()->BoundaryConditions() == Quasiperiodic))
45 begin_f += 1;
46
47 // Communication step
48 MG::GetComm()->CommToGhosts(sol());
49
50 // Compute residual
51 TempGrid *temp = MG::GetTempGrid();
52 temp->SetProperties(rhs());
53 temp->ImportFromResidual(sol(), rhs());
54
55 // Bring grids to the next coarser level
56 rhs.ToCoarserLevel();
57 sol.ToCoarserLevel();
58
59#ifdef DEBUG
60 sol().IsConsistent();
61 rhs().IsConsistent();
62 sol().IsCompatible(rhs());
63#endif
64
65 if (rhs().Global().BoundaryType() == GlobalCoarsened)
66 rhs().ClearBoundary();
67
68 // Set coarse grid values according to the given stencil
69 for (i_c.X()=begin_c.X(), i_f.X()=begin_f.X(); i_f.X()<end_f.X(); ++i_c.X(), i_f.X()+=2)
70 for (i_c.Y()=begin_c.Y(), i_f.Y()=begin_f.Y(); i_f.Y()<end_f.Y(); ++i_c.Y(), i_f.Y()+=2)
71 for (i_c.Z()=begin_c.Z(), i_f.Z()=begin_f.Z(); i_f.Z()<end_f.Z(); ++i_c.Z(), i_f.Z()+=2) {
72
73 res = op.GetDiag() * temp->GetVal(i_f);
74
75 for (iter=op.begin(); iter!=op.end(); ++iter)
76 res += iter->val * temp->GetVal(i_f + iter);
77
78 rhs()(i_c) = res;
79
80 }
81}
82
83void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
84{
85#ifdef DEBUG
86 sol().IsConsistent();
87 rhs().IsConsistent();
88 sol().IsCompatible(rhs());
89#endif
90
91 Stencil::iterator iter;
92 Index i_c, i_f;
93 vmg_float val;
94
95 const Stencil& op = OperatorProlongate();
96
97 const int l_c = sol.Level();
98 const int l_f = l_c + 1;
99
100 const Index begin_c = sol().Local().AlignmentBegin();
101 Index begin_f = sol(l_f).Local().Begin();
102 const Index end_f = sol(l_f).Local().End();
103
104 if (sol(l_c).Global().BoundaryType() == GlobalCoarsened &&
105 (MG::GetComm()->BoundaryConditions() == Dirichlet || MG::GetComm()->BoundaryConditions() == Quasiperiodic))
106 begin_f += 1;
107
108 sol.ToFinerLevel();
109 rhs.ToFinerLevel();
110
111#ifdef DEBUG
112 sol().IsConsistent();
113 rhs().IsConsistent();
114 sol().IsCompatible(rhs());
115#endif
116
117 if (MG::GetComm()->BoundaryConditions() == Periodic) {
118
119 sol().ClearHalo();
120
121 for (i_c.X()=begin_c.X(), i_f.X()=begin_f.X(); i_f.X()<end_f.X(); i_c.X()++, i_f.X()+=2)
122 for (i_c.Y()=begin_c.Y(), i_f.Y()=begin_f.Y(); i_f.Y()<end_f.Y(); i_c.Y()++, i_f.Y()+=2)
123 for (i_c.Z()=begin_c.Z(), i_f.Z()=begin_f.Z(); i_f.Z()<end_f.Z(); i_c.Z()++, i_f.Z()+=2) {
124
125 val = sol(l_c).GetVal(i_c);
126
127 sol()(i_f) += op.GetDiag() * val;
128
129 for (iter=op.begin(); iter!=op.end(); ++iter)
130 sol()(i_f + iter) += iter->val * val;
131
132 }
133
134 MG::GetComm()->CommFromGhosts(sol());
135
136 }else if (MG::GetComm()->BoundaryConditions() == Dirichlet ||
137 MG::GetComm()->BoundaryConditions() == Quasiperiodic) {
138
139 for (i_c.X()=begin_c.X(), i_f.X()=begin_f.X(); i_f.X()<end_f.X(); ++i_c.X(), i_f.X()+=2)
140 for (i_c.Y()=begin_c.Y(), i_f.Y()=begin_f.Y(); i_f.Y()<end_f.Y(); ++i_c.Y(), i_f.Y()+=2)
141 for (i_c.Z()=begin_c.Z(), i_f.Z()=begin_f.Z(); i_f.Z()<end_f.Z(); ++i_c.Z(), i_f.Z()+=2) {
142
143 val = sol(l_c).GetVal(i_c);
144
145 sol()(i_f) += op.GetDiag() * val;
146
147 for (iter=op.begin(); iter!=op.end(); ++iter)
148 if (i_f.X()+iter->m >= sol().Local().Begin().X() && i_f.X()+iter->m < sol().Local().End().X() &&
149 i_f.Y()+iter->n >= sol().Local().Begin().Y() && i_f.Y()+iter->n < sol().Local().End().Y() &&
150 i_f.Z()+iter->o >= sol().Local().Begin().Z() && i_f.Z()+iter->o < sol().Local().End().Z()) {
151 sol()(i_f + iter) += iter->val * val;
152 }
153 }
154 }
155}
Note: See TracBrowser for help on using the repository browser.