source: src/level/level_operator_cs.cpp@ 6e10f33

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

Merge stashed open boundary stuff.

  • Property mode set to 100644
File size: 3.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"
[8180d8]34#include "grid/grid_index_translations.hpp"
[dfed1c]35#include "grid/grid_iterator.hpp"
[48b662]36#include "grid/multigrid.hpp"
37#include "grid/tempgrid.hpp"
38#include "level/level_operator_cs.hpp"
39#include "mg.hpp"
40
41using namespace VMG;
42
[ac6d04]43void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
[48b662]44{
[ac6d04]45 Grid::iterator iter_f, iter_c;
[dfed1c]46
[ac6d04]47 Comm& comm = *MG::GetComm();
[48b662]48
[ac6d04]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);
[48b662]53
54 const Stencil& op = OperatorRestrict();
55
[8180d8]56 GridIteratorSet bounds_c, bounds_f;
57 GridIndexTranslations::GetGridAlignment(rhs_c_undist, bounds_c, rhs_f, bounds_f);
[48b662]58
[f57182]59 assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
60
[48b662]61 // Compute residual
62 TempGrid *temp = MG::GetTempGrid();
[dfed1c]63 temp->SetProperties(sol_f);
64 temp->ImportFromResidual(sol_f, rhs_f);
[ac6d04]65 comm.CommToGhosts(*temp);
[48b662]66
[ac6d04]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);
[48b662]69
[ac6d04]70 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
[48b662]71
[ac6d04]72 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
73 rhs_c_dist.ClearBoundary();
[48b662]74
[ac6d04]75 sol.ToCoarserLevel();
76 rhs.ToCoarserLevel();
[48b662]77}
78
[ac6d04]79void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
[48b662]80{
[dfed1c]81 Grid::iterator iter_f, iter_c;
82 Stencil::iterator stencil_iter;
[48b662]83 vmg_float val;
84
[ac6d04]85 Comm& comm = *MG::GetComm();
[48b662]86
[ac6d04]87 Grid& sol_c = sol(sol.Level());
88 Grid& sol_f_dist = sol(sol.Level()+1);
89 Grid& sol_f_undist = comm.GetFinerGrid(sol);
[48b662]90
[ac6d04]91 const Stencil& op = OperatorProlongate();
[48b662]92
[8180d8]93 GridIteratorSet bounds_c, bounds_f;
94 GridIndexTranslations::GetGridAlignment(sol_c, bounds_c, sol_f_undist, bounds_f);
[48b662]95
[f57182]96 assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
97
[ac6d04]98 sol_f_undist.ClearHalo();
[48b662]99
[ac6d04]100 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
[48b662]101
[dfed1c]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);
[ac6d04]104 sol_f_undist(*iter_f) += op.GetDiag() * val;
[894a5f]105 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
[ac6d04]106 sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
[8180d8]107 iter_f->Y() + stencil_iter->Disp().Y(),
108 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
[48b662]109 }
[dfed1c]110
[ac6d04]111 comm.CommFromGhosts(sol_f_undist);
112 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
113
114 sol.ToFinerLevel();
115 rhs.ToFinerLevel();
[48b662]116}
Note: See TracBrowser for help on using the repository browser.