source: src/level/level_operator_cs.cpp@ f57182

Last change on this file since f57182 was f57182, checked in by Julian Iseringhausen <isering@…>, 13 years ago

Open boundary conditions.

Conflicts:

lib/vmg/src/Makefile.am
lib/vmg/src/base/factory.cpp
lib/vmg/test/unit_test/library/dirichlet_fas_lr_mpi.cpp

  • Property mode set to 100644
File size: 4.8 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_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"
34#include "grid/grid_iterator.hpp"
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
42void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
43{
44 Grid::iterator iter_f, iter_c;
45
46 Comm& comm = *MG::GetComm();
47
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);
52
53 const Stencil& op = OperatorRestrict();
54
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();
61
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();
64
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 }
70
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;
73
74 const GridIteratorSet bounds_f(begin_f, end_f);
75 const GridIteratorSet bounds_c(begin_c, end_c);
76
77 assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
78
79 // Compute residual
80 TempGrid *temp = MG::GetTempGrid();
81 temp->SetProperties(sol_f);
82 temp->ImportFromResidual(sol_f, rhs_f);
83 comm.CommToGhosts(*temp);
84
85 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
86 rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
87
88 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
89
90 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
91 rhs_c_dist.ClearBoundary();
92
93 sol.ToCoarserLevel();
94 rhs.ToCoarserLevel();
95}
96
97void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
98{
99 Grid::iterator iter_f, iter_c;
100 Stencil::iterator stencil_iter;
101 vmg_float val;
102
103 Comm& comm = *MG::GetComm();
104
105 Grid& sol_c = sol(sol.Level());
106 Grid& sol_f_dist = sol(sol.Level()+1);
107 Grid& sol_f_undist = comm.GetFinerGrid(sol);
108 Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
109
110 const Stencil& op = OperatorProlongate();
111
112 Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin();
113 Index end_f = sol_f_undist.Local().End();
114
115 if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
116 begin_f += rhs_f_undist.Local().BoundarySize1();
117 end_f -= rhs_f_undist.Local().BoundarySize2();
118 }
119
120 const GridIteratorSet bounds_f(begin_f, end_f);
121 const GridIteratorSet bounds_c(sol_c.Local().FinerBegin(), sol_c.Local().FinerEnd());
122
123 assert(bounds_c.Begin().GetEnd()-bounds_c.Begin().GetBegin() == ((bounds_f.Begin().GetEnd()-bounds_f.Begin().GetBegin())-1)/2+1);
124
125 sol_f_undist.ClearHalo();
126
127 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
128
129 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
130 val = sol_c.GetVal(*iter_c);
131 sol_f_undist(*iter_f) += op.GetDiag() * val;
132 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
133 sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
134 iter_f->Y() + stencil_iter->Disp().Y(),
135 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
136 }
137
138 comm.CommFromGhosts(sol_f_undist);
139 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
140
141 sol.ToFinerLevel();
142 rhs.ToFinerLevel();
143}
Note: See TracBrowser for help on using the repository browser.