source: src/level/level_operator_cs.cpp@ b51c3b

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

Fix energy calculation.

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

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