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
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_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
[f57182]32#include <limits>
33
[48b662]34#include "base/discretization.hpp"
[f57182]35#include "base/helper.hpp"
[48b662]36#include "base/index.hpp"
37#include "comm/comm.hpp"
[8180d8]38#include "grid/grid_index_translations.hpp"
[48b662]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
[ac6d04]46void LevelOperatorFAS::Restrict(Multigrid& sol, Multigrid& rhs)
[48b662]47{
[dfed1c]48 Grid::iterator iter_f, iter_c;
49 Stencil::iterator stencil_iter;
[48b662]50
[ac6d04]51 Comm& comm = *MG::GetComm();
[dfed1c]52
[ac6d04]53 Grid& sol_f = sol(sol.Level());
54 Grid& rhs_f = rhs(rhs.Level());
[dfed1c]55
[ac6d04]56 Grid& sol_c_dist = sol(sol.Level()-1);
57 Grid& rhs_c_dist = rhs(rhs.Level()-1);
[48b662]58
[ac6d04]59 Grid& sol_c_undist = comm.GetCoarserGrid(sol);
60 Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
[48b662]61
[f57182]62 Index begin_c = rhs_c_undist.Local().FinerBegin();
63 Index end_c = rhs_c_undist.Local().FinerEnd();
64
[ac6d04]65 Index begin_f = rhs_f.Local().Begin();
66 Index end_f = rhs_f.Local().End();
[dfed1c]67
[ac6d04]68 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
[f57182]69 begin_c += rhs_c_undist.Local().BoundarySize1();
70 end_c -= rhs_c_undist.Local().BoundarySize2();
[ac6d04]71 begin_f += rhs_f.Local().BoundarySize1();
72 end_f -= rhs_f.Local().BoundarySize2();
73 }
[dfed1c]74
[8180d8]75 GridIteratorSet bounds_c, bounds_f;
76 GridIndexTranslations::GetGridAlignment(rhs_c_undist, bounds_c, rhs_f, bounds_f);
[48b662]77
78 const Stencil& op_res = OperatorRestrict();
79 const Stencil& op_sol = OperatorSol();
80 const Stencil& op_pde = MG::GetDiscretization()->GetStencil();
[ac6d04]81 const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol_c_undist);
[48b662]82
83 // Communication step
[ac6d04]84 comm.CommToGhosts(sol_f);
85 comm.CommSubgrid(sol_c_dist, sol_c_undist, 0);
[f57182]86 comm.CommSubgrid(rhs_c_dist, rhs_c_undist, 0);
[48b662]87
[ac6d04]88 MG::GetDiscretization()->SetInnerBoundary(sol_f, rhs_f, sol_c_undist);
[48b662]89
90 // Compute residual
91 VMG::TempGrid *res_grid = MG::GetTempGrid();
[dfed1c]92 res_grid->SetProperties(rhs_f);
93 res_grid->ImportFromResidual(sol_f, rhs_f);
[48b662]94
[f57182]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));
[ac6d04]97 sol_c_undist(*iter_c) = op_sol.Apply(sol_f, *iter_f);
[f57182]98 }
[48b662]99
[f57182]100 comm.CommToGhosts(sol_c_undist);
[48b662]101
[f57182]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 }
[48b662]106
[f57182]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);
[ac6d04]113 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
[48b662]114
[ac6d04]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);
[48b662]118
[f57182]119 // comm.CommToGhosts(rhs_c_dist);
[48b662]120
[ac6d04]121 sol.ToCoarserLevel();
122 rhs.ToCoarserLevel();
[48b662]123}
124
[ac6d04]125void LevelOperatorFAS::Prolongate(Multigrid& sol, Multigrid& rhs)
[48b662]126{
[dfed1c]127 Grid::iterator iter_f, iter_c;
128 Stencil::iterator stencil_iter;
[48b662]129 vmg_float val;
130
[ac6d04]131 Comm& comm = *MG::GetComm();
[48b662]132
[ac6d04]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);
[48b662]138
[ac6d04]139 const Stencil& op = OperatorProlongate();
[48b662]140
[ac6d04]141 TempGrid *sol_old = this->GetTempGrid(sol_c.Level());
[48b662]142
[f57182]143 Index begin_c = sol_c.Local().FinerBegin();
144 Index end_c = sol_c.Local().FinerEnd();
145
[ac6d04]146 Index begin_f = sol_f_undist.Local().Begin();
147 Index end_f = sol_f_undist.Local().End();
[48b662]148
[ac6d04]149 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
[f57182]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();
[ac6d04]154 }
[48b662]155
[8180d8]156 GridIteratorSet bounds_c, bounds_f;
157 GridIndexTranslations::GetGridAlignment(sol_c, bounds_c, sol_f_undist, bounds_f);
[48b662]158
[f57182]159 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
[ac6d04]160 sol_f_undist.ClearHalo();
[48b662]161
[ac6d04]162 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c) {
[f57182]163 Helper::AssertVectorsEqual(sol_c.GetSpatialPos(*iter_c), sol_f_undist.GetSpatialPos(*iter_f));
[dfed1c]164 val = sol_c.GetVal(*iter_c) - sol_old->GetVal(*iter_c);
[ac6d04]165 sol_f_undist(*iter_f) += op.GetDiag() * val;
[dfed1c]166 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
[ac6d04]167 sol_f_undist(*iter_f + stencil_iter->Disp()) += stencil_iter->Val() * val;
[48b662]168 }
169
[ac6d04]170 comm.CommFromGhosts(sol_f_undist);
171 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
[48b662]172
[ac6d04]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();
[48b662]178}
Note: See TracBrowser for help on using the repository browser.