source: src/level/level_operator_fas.cpp@ 8180d8

Last change on this file since 8180d8 was 8180d8, checked in by Julian Iseringhausen <julian.iseringhausen@…>, 13 years ago

Merge stashed open boundary stuff.

  • Property mode set to 100644
File size: 5.7 KB
Line 
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_fas.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 13:00:23 2011
23 *
24 * @brief VMG::LevelOperatorFAS
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32#include <limits>
33
34#include "base/discretization.hpp"
35#include "base/helper.hpp"
36#include "base/index.hpp"
37#include "comm/comm.hpp"
38#include "grid/grid_index_translations.hpp"
39#include "grid/multigrid.hpp"
40#include "grid/tempgrid.hpp"
41#include "level/level_operator_fas.hpp"
42#include "mg.hpp"
43
44using namespace VMG;
45
46void LevelOperatorFAS::Restrict(Multigrid& sol, Multigrid& rhs)
47{
48 Grid::iterator iter_f, iter_c;
49 Stencil::iterator stencil_iter;
50
51 Comm& comm = *MG::GetComm();
52
53 Grid& sol_f = sol(sol.Level());
54 Grid& rhs_f = rhs(rhs.Level());
55
56 Grid& sol_c_dist = sol(sol.Level()-1);
57 Grid& rhs_c_dist = rhs(rhs.Level()-1);
58
59 Grid& sol_c_undist = comm.GetCoarserGrid(sol);
60 Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
61
62 Index begin_c = rhs_c_undist.Local().FinerBegin();
63 Index end_c = rhs_c_undist.Local().FinerEnd();
64
65 Index begin_f = rhs_f.Local().Begin();
66 Index end_f = rhs_f.Local().End();
67
68 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
69 begin_c += rhs_c_undist.Local().BoundarySize1();
70 end_c -= rhs_c_undist.Local().BoundarySize2();
71 begin_f += rhs_f.Local().BoundarySize1();
72 end_f -= rhs_f.Local().BoundarySize2();
73 }
74
75 GridIteratorSet bounds_c, bounds_f;
76 GridIndexTranslations::GetGridAlignment(rhs_c_undist, bounds_c, rhs_f, bounds_f);
77
78 const Stencil& op_res = OperatorRestrict();
79 const Stencil& op_sol = OperatorSol();
80 const Stencil& op_pde = MG::GetDiscretization()->GetStencil();
81 const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol_c_undist);
82
83 // Communication step
84 comm.CommToGhosts(sol_f);
85 comm.CommSubgrid(sol_c_dist, sol_c_undist, 0);
86 comm.CommSubgrid(rhs_c_dist, rhs_c_undist, 0);
87
88 MG::GetDiscretization()->SetInnerBoundary(sol_f, rhs_f, sol_c_undist);
89
90 // Compute residual
91 VMG::TempGrid *res_grid = MG::GetTempGrid();
92 res_grid->SetProperties(rhs_f);
93 res_grid->ImportFromResidual(sol_f, rhs_f);
94
95 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
96 Helper::AssertVectorsEqual(sol_c_undist.GetSpatialPos(*iter_c), sol_f.GetSpatialPos(*iter_f));
97 sol_c_undist(*iter_c) = op_sol.Apply(sol_f, *iter_f);
98 }
99
100 comm.CommToGhosts(sol_c_undist);
101
102 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
103 Helper::AssertVectorsEqual(rhs_c_undist.GetSpatialPos(*iter_c), (*res_grid).GetSpatialPos(*iter_f));
104 rhs_c_undist(*iter_c) = op_res.Apply(*res_grid, *iter_f) + prefactor * op_pde.Apply(sol_c_undist, *iter_c);
105 }
106
107 /*
108 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened)
109 rhs_c_undist.SetBoundary(sol_c_undist);
110 */
111
112 comm.CommSubgrid(sol_c_undist, sol_c_dist, 1);
113 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
114
115 VMG::TempGrid* sol_old = this->GetTempGrid(sol_c_dist.Level());
116 sol_old->SetProperties(sol_c_dist);
117 sol_old->SetGrid(sol_c_dist);
118
119 // comm.CommToGhosts(rhs_c_dist);
120
121 sol.ToCoarserLevel();
122 rhs.ToCoarserLevel();
123}
124
125void LevelOperatorFAS::Prolongate(Multigrid& sol, Multigrid& rhs)
126{
127 Grid::iterator iter_f, iter_c;
128 Stencil::iterator stencil_iter;
129 vmg_float val;
130
131 Comm& comm = *MG::GetComm();
132
133 Grid& sol_c = sol(sol.Level());
134 Grid& sol_f_dist = sol(sol.Level()+1);
135 Grid& rhs_f_dist = rhs(rhs.Level()+1);
136 Grid& sol_f_undist = comm.GetFinerGrid(sol);
137 Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
138
139 const Stencil& op = OperatorProlongate();
140
141 TempGrid *sol_old = this->GetTempGrid(sol_c.Level());
142
143 Index begin_c = sol_c.Local().FinerBegin();
144 Index end_c = sol_c.Local().FinerEnd();
145
146 Index begin_f = sol_f_undist.Local().Begin();
147 Index end_f = sol_f_undist.Local().End();
148
149 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
150 begin_c += sol_c.Local().BoundarySize1();
151 end_c -= sol_c.Local().BoundarySize2();
152 begin_f += sol_f_undist.Local().BoundarySize1();
153 end_f -= sol_f_undist.Local().BoundarySize2();
154 }
155
156 GridIteratorSet bounds_c, bounds_f;
157 GridIndexTranslations::GetGridAlignment(sol_c, bounds_c, sol_f_undist, bounds_f);
158
159 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
160 sol_f_undist.ClearHalo();
161
162 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c) {
163 Helper::AssertVectorsEqual(sol_c.GetSpatialPos(*iter_c), sol_f_undist.GetSpatialPos(*iter_f));
164 val = sol_c.GetVal(*iter_c) - sol_old->GetVal(*iter_c);
165 sol_f_undist(*iter_f) += op.GetDiag() * val;
166 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
167 sol_f_undist(*iter_f + stencil_iter->Disp()) += stencil_iter->Val() * val;
168 }
169
170 comm.CommFromGhosts(sol_f_undist);
171 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
172
173 if (sol_f_dist.Global().BoundaryType() == LocallyRefined)
174 MG::GetDiscretization()->SetInnerBoundary(sol_f_dist, rhs_f_dist, sol_c);
175
176 sol.ToFinerLevel();
177 rhs.ToFinerLevel();
178}
Note: See TracBrowser for help on using the repository browser.