source: src/level/level_operator_cs.cpp@ ac6d04

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

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

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

  • Property mode set to 100644
File size: 3.9 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"
[dfed1c]16#include "grid/grid_iterator.hpp"
[48b662]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
[ac6d04]24void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
[48b662]25{
[ac6d04]26 Grid::iterator iter_f, iter_c;
[dfed1c]27
[ac6d04]28 Comm& comm = *MG::GetComm();
[48b662]29
[ac6d04]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);
[48b662]38
39 const Stencil& op = OperatorRestrict();
40
[ac6d04]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;
[dfed1c]43
[ac6d04]44 assert(begin_f_global % 2 == 0);
45 assert(end_f_global % 2 == 1);
[dfed1c]46
[ac6d04]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();
[48b662]49
[ac6d04]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 }
[dfed1c]55
[ac6d04]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;
[dfed1c]58
59 const GridIteratorSet bounds_f(begin_f, end_f);
[ac6d04]60 const GridIteratorSet bounds_c(begin_c, end_c);
[48b662]61
62 // Compute residual
63 TempGrid *temp = MG::GetTempGrid();
[dfed1c]64 temp->SetProperties(sol_f);
65 temp->ImportFromResidual(sol_f, rhs_f);
[ac6d04]66 comm.CommToGhosts(*temp);
[48b662]67
[ac6d04]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);
[48b662]70
[ac6d04]71 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
[48b662]72
[ac6d04]73 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
74 rhs_c_dist.ClearBoundary();
[48b662]75
[ac6d04]76 sol.ToCoarserLevel();
77 rhs.ToCoarserLevel();
[48b662]78}
79
[ac6d04]80void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
[48b662]81{
[dfed1c]82 Grid::iterator iter_f, iter_c;
83 Stencil::iterator stencil_iter;
[48b662]84 vmg_float val;
85
[ac6d04]86 Comm& comm = *MG::GetComm();
[48b662]87
[ac6d04]88 Grid& sol_c = sol(sol.Level());
89 Grid& rhs_c = rhs(rhs.Level());
[48b662]90
[ac6d04]91 Grid& sol_f_dist = sol(sol.Level()+1);
92 Grid& rhs_f_dist = rhs(rhs.Level()+1);
[48b662]93
[ac6d04]94 Grid& sol_f_undist = comm.GetFinerGrid(sol);
95 Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
[48b662]96
[ac6d04]97 const Stencil& op = OperatorProlongate();
[48b662]98
[ac6d04]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();
[48b662]101
[ac6d04]102 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
103 begin_f += rhs_f_undist.Local().BoundarySize1();
104 end_f -= rhs_f_undist.Local().BoundarySize2();
105 }
[48b662]106
[ac6d04]107 const GridIteratorSet bounds_f(begin_f, end_f);
108 const GridIteratorSet bounds_c(sol_c.Local().FinerBeginFoo(), sol_c.Local().FinerEndFoo());
[48b662]109
[ac6d04]110 sol_f_undist.ClearHalo();
[48b662]111
[ac6d04]112 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
[48b662]113
[dfed1c]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);
[ac6d04]116 sol_f_undist(*iter_f) += op.GetDiag() * val;
[894a5f]117 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
[ac6d04]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;
[48b662]121 }
[dfed1c]122
[ac6d04]123 comm.CommFromGhosts(sol_f_undist);
124 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
125
126 sol.ToFinerLevel();
127 rhs.ToFinerLevel();
[48b662]128}
Note: See TracBrowser for help on using the repository browser.