source: src/level/level_operator_cs.cpp@ cd0fed

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

Fixed some warnings.

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

  • Property mode set to 100644
File size: 3.8 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(Multigrid& sol, Multigrid& rhs)
25{
26 Grid::iterator iter_f, iter_c;
27
28 Comm& comm = *MG::GetComm();
29
30 Grid& sol_f = sol(sol.Level());
31 Grid& rhs_f = rhs(rhs.Level());
32 Grid& rhs_c_dist = rhs(rhs.Level()-1);
33 Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
34
35 const Stencil& op = OperatorRestrict();
36
37 const Index begin_f_global = rhs_f.Global().LocalSize().Product() > 0
38 ? rhs_f.Global().LocalBegin() + rhs_f.Global().LocalBegin() % 2
39 : rhs_f.Global().LocalBegin();
40 const Index end_f_global = rhs_f.Global().LocalSize().Product() > 0
41 ? rhs_f.Global().LocalEnd() - (rhs_f.Global().LocalEnd() - 1) % 2
42 : rhs_f.Global().LocalBegin();
43
44 Index begin_f = begin_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
45 Index end_f = end_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
46
47 /* Modify fine begin/end to align the points on both levels correctly */
48 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
49 begin_f += rhs_f.Local().BoundarySize1();
50 end_f -= rhs_f.Local().BoundarySize2();
51 }
52
53 const Index begin_c = rhs_c_undist.Local().Begin() + begin_f_global / 2 - rhs_c_undist.Global().LocalBegin();
54 const Index end_c = rhs_c_undist.Local().Begin() + end_f_global / 2 - rhs_c_undist.Global().LocalBegin() + 1;
55
56 const GridIteratorSet bounds_f(begin_f, end_f);
57 const GridIteratorSet bounds_c(begin_c, end_c);
58
59 // Compute residual
60 TempGrid *temp = MG::GetTempGrid();
61 temp->SetProperties(sol_f);
62 temp->ImportFromResidual(sol_f, rhs_f);
63 comm.CommToGhosts(*temp);
64
65 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
66 rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
67
68 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
69
70 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
71 rhs_c_dist.ClearBoundary();
72
73 sol.ToCoarserLevel();
74 rhs.ToCoarserLevel();
75}
76
77void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
78{
79 Grid::iterator iter_f, iter_c;
80 Stencil::iterator stencil_iter;
81 vmg_float val;
82
83 Comm& comm = *MG::GetComm();
84
85 Grid& sol_c = sol(sol.Level());
86 Grid& sol_f_dist = sol(sol.Level()+1);
87 Grid& sol_f_undist = comm.GetFinerGrid(sol);
88 Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
89
90 const Stencil& op = OperatorProlongate();
91
92 Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin();
93 Index end_f = sol_f_undist.Local().End();
94
95 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
96 begin_f += rhs_f_undist.Local().BoundarySize1();
97 end_f -= rhs_f_undist.Local().BoundarySize2();
98 }
99
100 const GridIteratorSet bounds_f(begin_f, end_f);
101 const GridIteratorSet bounds_c(sol_c.Local().FinerBegin(), sol_c.Local().FinerEnd());
102
103 sol_f_undist.ClearHalo();
104
105 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
106
107 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
108 val = sol_c.GetVal(*iter_c);
109 sol_f_undist(*iter_f) += op.GetDiag() * val;
110 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
111 sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
112 iter_f->Y() + stencil_iter->Disp().Y(),
113 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
114 }
115
116 comm.CommFromGhosts(sol_f_undist);
117 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
118
119 sol.ToFinerLevel();
120 rhs.ToFinerLevel();
121}
Note: See TracBrowser for help on using the repository browser.