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 |
|
---|
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 <libvmg_config.h>
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include "base/index.hpp"
|
---|
33 | #include "comm/comm.hpp"
|
---|
34 | #include "grid/grid_index_translations.hpp"
|
---|
35 | #include "grid/grid_iterator.hpp"
|
---|
36 | #include "grid/multigrid.hpp"
|
---|
37 | #include "grid/tempgrid.hpp"
|
---|
38 | #include "level/level_operator_cs.hpp"
|
---|
39 | #include "mg.hpp"
|
---|
40 |
|
---|
41 | using namespace VMG;
|
---|
42 |
|
---|
43 | void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
|
---|
44 | {
|
---|
45 | Grid::iterator iter_f, iter_c;
|
---|
46 |
|
---|
47 | Comm& comm = *MG::GetComm();
|
---|
48 |
|
---|
49 | Grid& sol_f = sol(sol.Level());
|
---|
50 | Grid& rhs_f = rhs(rhs.Level());
|
---|
51 | Grid& rhs_c_dist = rhs(rhs.Level()-1);
|
---|
52 | Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
|
---|
53 |
|
---|
54 | const Stencil& op = OperatorRestrict();
|
---|
55 |
|
---|
56 | GridIteratorSet bounds_c, bounds_f;
|
---|
57 | GridIndexTranslations::GetGridAlignment(rhs_c_undist, bounds_c, rhs_f, bounds_f);
|
---|
58 |
|
---|
59 | assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
|
---|
60 |
|
---|
61 | // Compute residual
|
---|
62 | TempGrid *temp = MG::GetTempGrid();
|
---|
63 | temp->SetProperties(sol_f);
|
---|
64 | temp->ImportFromResidual(sol_f, rhs_f);
|
---|
65 | comm.CommToGhosts(*temp);
|
---|
66 |
|
---|
67 | for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
|
---|
68 | rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
|
---|
69 |
|
---|
70 | comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
|
---|
71 |
|
---|
72 | if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
|
---|
73 | rhs_c_dist.ClearBoundary();
|
---|
74 |
|
---|
75 | sol.ToCoarserLevel();
|
---|
76 | rhs.ToCoarserLevel();
|
---|
77 | }
|
---|
78 |
|
---|
79 | void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
|
---|
80 | {
|
---|
81 | Grid::iterator iter_f, iter_c;
|
---|
82 | Stencil::iterator stencil_iter;
|
---|
83 | vmg_float val;
|
---|
84 |
|
---|
85 | Comm& comm = *MG::GetComm();
|
---|
86 |
|
---|
87 | Grid& sol_c = sol(sol.Level());
|
---|
88 | Grid& sol_f_dist = sol(sol.Level()+1);
|
---|
89 | Grid& sol_f_undist = comm.GetFinerGrid(sol);
|
---|
90 |
|
---|
91 | const Stencil& op = OperatorProlongate();
|
---|
92 |
|
---|
93 | GridIteratorSet bounds_c, bounds_f;
|
---|
94 | GridIndexTranslations::GetGridAlignment(sol_c, bounds_c, sol_f_undist, bounds_f);
|
---|
95 |
|
---|
96 | assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
|
---|
97 |
|
---|
98 | sol_f_undist.ClearHalo();
|
---|
99 |
|
---|
100 | comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
|
---|
101 |
|
---|
102 | for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
|
---|
103 | val = sol_c.GetVal(*iter_c);
|
---|
104 | sol_f_undist(*iter_f) += op.GetDiag() * val;
|
---|
105 | for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
|
---|
106 | sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
|
---|
107 | iter_f->Y() + stencil_iter->Disp().Y(),
|
---|
108 | iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
|
---|
109 | }
|
---|
110 |
|
---|
111 | comm.CommFromGhosts(sol_f_undist);
|
---|
112 | comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
|
---|
113 |
|
---|
114 | sol.ToFinerLevel();
|
---|
115 | rhs.ToFinerLevel();
|
---|
116 | }
|
---|