source: src/level/level_operator_cs.cpp@ 30f2139

Last change on this file since 30f2139 was 30f2139, checked in by Olaf Lenz <olenz@…>, 13 years ago

Merge branch 'p3m-ad-i'

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

  • Property mode set to 100755
File size: 4.6 KB
RevLine 
[fcf7f6]1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
[48b662]19/**
20 * @file level_operator_cs.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:59:46 2011
23 *
24 * @brief VMG::LevelOperatorCS
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32#include "base/index.hpp"
33#include "comm/comm.hpp"
[dfed1c]34#include "grid/grid_iterator.hpp"
[48b662]35#include "grid/multigrid.hpp"
36#include "grid/tempgrid.hpp"
37#include "level/level_operator_cs.hpp"
38#include "mg.hpp"
39
40using namespace VMG;
41
[ac6d04]42void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
[48b662]43{
[ac6d04]44 Grid::iterator iter_f, iter_c;
[dfed1c]45
[ac6d04]46 Comm& comm = *MG::GetComm();
[48b662]47
[ac6d04]48 Grid& sol_f = sol(sol.Level());
49 Grid& rhs_f = rhs(rhs.Level());
50 Grid& rhs_c_dist = rhs(rhs.Level()-1);
51 Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
[48b662]52
53 const Stencil& op = OperatorRestrict();
54
[3bd250]55 const Index begin_f_global = rhs_f.Global().LocalSize().Product() > 0
56 ? rhs_f.Global().LocalBegin() + rhs_f.Global().LocalBegin() % 2
57 : rhs_f.Global().LocalBegin();
58 const Index end_f_global = rhs_f.Global().LocalSize().Product() > 0
59 ? rhs_f.Global().LocalEnd() - (rhs_f.Global().LocalEnd() - 1) % 2
60 : rhs_f.Global().LocalBegin();
[dfed1c]61
[ac6d04]62 Index begin_f = begin_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
63 Index end_f = end_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
[48b662]64
[ac6d04]65 /* Modify fine begin/end to align the points on both levels correctly */
66 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
67 begin_f += rhs_f.Local().BoundarySize1();
68 end_f -= rhs_f.Local().BoundarySize2();
69 }
[dfed1c]70
[ac6d04]71 const Index begin_c = rhs_c_undist.Local().Begin() + begin_f_global / 2 - rhs_c_undist.Global().LocalBegin();
72 const Index end_c = rhs_c_undist.Local().Begin() + end_f_global / 2 - rhs_c_undist.Global().LocalBegin() + 1;
[dfed1c]73
74 const GridIteratorSet bounds_f(begin_f, end_f);
[ac6d04]75 const GridIteratorSet bounds_c(begin_c, end_c);
[48b662]76
77 // Compute residual
78 TempGrid *temp = MG::GetTempGrid();
[dfed1c]79 temp->SetProperties(sol_f);
80 temp->ImportFromResidual(sol_f, rhs_f);
[ac6d04]81 comm.CommToGhosts(*temp);
[48b662]82
[ac6d04]83 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
84 rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
[48b662]85
[ac6d04]86 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
[48b662]87
[ac6d04]88 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
89 rhs_c_dist.ClearBoundary();
[48b662]90
[ac6d04]91 sol.ToCoarserLevel();
92 rhs.ToCoarserLevel();
[48b662]93}
94
[ac6d04]95void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
[48b662]96{
[dfed1c]97 Grid::iterator iter_f, iter_c;
98 Stencil::iterator stencil_iter;
[48b662]99 vmg_float val;
100
[ac6d04]101 Comm& comm = *MG::GetComm();
[48b662]102
[ac6d04]103 Grid& sol_c = sol(sol.Level());
104 Grid& sol_f_dist = sol(sol.Level()+1);
105 Grid& sol_f_undist = comm.GetFinerGrid(sol);
106 Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
[48b662]107
[ac6d04]108 const Stencil& op = OperatorProlongate();
[48b662]109
[ac6d04]110 Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin();
111 Index end_f = sol_f_undist.Local().End();
[48b662]112
[ac6d04]113 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
114 begin_f += rhs_f_undist.Local().BoundarySize1();
115 end_f -= rhs_f_undist.Local().BoundarySize2();
116 }
[48b662]117
[ac6d04]118 const GridIteratorSet bounds_f(begin_f, end_f);
[716da7]119 const GridIteratorSet bounds_c(sol_c.Local().FinerBegin(), sol_c.Local().FinerEnd());
[48b662]120
[ac6d04]121 sol_f_undist.ClearHalo();
[48b662]122
[ac6d04]123 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
[48b662]124
[dfed1c]125 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
126 val = sol_c.GetVal(*iter_c);
[ac6d04]127 sol_f_undist(*iter_f) += op.GetDiag() * val;
[894a5f]128 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
[ac6d04]129 sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
130 iter_f->Y() + stencil_iter->Disp().Y(),
131 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
[48b662]132 }
[dfed1c]133
[ac6d04]134 comm.CommFromGhosts(sol_f_undist);
135 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
136
137 sol.ToFinerLevel();
138 rhs.ToFinerLevel();
[48b662]139}
Note: See TracBrowser for help on using the repository browser.