| 1 | /**
|
|---|
| 2 | * @file level_operator_cs.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:59:46 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief VMG::LevelOperatorCS
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include "base/index.hpp"
|
|---|
| 15 | #include "comm/comm.hpp"
|
|---|
| 16 | #include "grid/grid_iterator.hpp"
|
|---|
| 17 | #include "grid/multigrid.hpp"
|
|---|
| 18 | #include "grid/tempgrid.hpp"
|
|---|
| 19 | #include "level/level_operator_cs.hpp"
|
|---|
| 20 | #include "mg.hpp"
|
|---|
| 21 |
|
|---|
| 22 | using namespace VMG;
|
|---|
| 23 |
|
|---|
| 24 | void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
|
|---|
| 25 | {
|
|---|
| 26 | Grid::iterator iter_f, iter_c;
|
|---|
| 27 |
|
|---|
| 28 | Comm& comm = *MG::GetComm();
|
|---|
| 29 |
|
|---|
| 30 | Grid& sol_f = sol(sol.Level());
|
|---|
| 31 | Grid& rhs_f = rhs(rhs.Level());
|
|---|
| 32 |
|
|---|
| 33 | Grid& sol_c_dist = sol(sol.Level()-1);
|
|---|
| 34 | Grid& rhs_c_dist = rhs(rhs.Level()-1);
|
|---|
| 35 |
|
|---|
| 36 | Grid& sol_c_undist = comm.GetCoarserGrid(sol);
|
|---|
| 37 | Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
|
|---|
| 38 |
|
|---|
| 39 | const Stencil& op = OperatorRestrict();
|
|---|
| 40 |
|
|---|
| 41 | const Index begin_f_global = rhs_f.Global().LocalSize().Product() > 0
|
|---|
| 42 | ? rhs_f.Global().LocalBegin() + rhs_f.Global().LocalBegin() % 2
|
|---|
| 43 | : rhs_f.Global().LocalBegin();
|
|---|
| 44 | const Index end_f_global = rhs_f.Global().LocalSize().Product() > 0
|
|---|
| 45 | ? rhs_f.Global().LocalEnd() - (rhs_f.Global().LocalEnd() - 1) % 2
|
|---|
| 46 | : rhs_f.Global().LocalBegin();
|
|---|
| 47 |
|
|---|
| 48 | Index begin_f = begin_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
|
|---|
| 49 | Index end_f = end_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
|
|---|
| 50 |
|
|---|
| 51 | /* Modify fine begin/end to align the points on both levels correctly */
|
|---|
| 52 | if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
|
|---|
| 53 | begin_f += rhs_f.Local().BoundarySize1();
|
|---|
| 54 | end_f -= rhs_f.Local().BoundarySize2();
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | const Index begin_c = rhs_c_undist.Local().Begin() + begin_f_global / 2 - rhs_c_undist.Global().LocalBegin();
|
|---|
| 58 | const Index end_c = rhs_c_undist.Local().Begin() + end_f_global / 2 - rhs_c_undist.Global().LocalBegin() + 1;
|
|---|
| 59 |
|
|---|
| 60 | const GridIteratorSet bounds_f(begin_f, end_f);
|
|---|
| 61 | const GridIteratorSet bounds_c(begin_c, end_c);
|
|---|
| 62 |
|
|---|
| 63 | // Compute residual
|
|---|
| 64 | TempGrid *temp = MG::GetTempGrid();
|
|---|
| 65 | temp->SetProperties(sol_f);
|
|---|
| 66 | temp->ImportFromResidual(sol_f, rhs_f);
|
|---|
| 67 | comm.CommToGhosts(*temp);
|
|---|
| 68 |
|
|---|
| 69 | for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
|
|---|
| 70 | rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
|
|---|
| 71 |
|
|---|
| 72 | comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
|
|---|
| 73 |
|
|---|
| 74 | if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
|
|---|
| 75 | rhs_c_dist.ClearBoundary();
|
|---|
| 76 |
|
|---|
| 77 | sol.ToCoarserLevel();
|
|---|
| 78 | rhs.ToCoarserLevel();
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
|
|---|
| 82 | {
|
|---|
| 83 | Grid::iterator iter_f, iter_c;
|
|---|
| 84 | Stencil::iterator stencil_iter;
|
|---|
| 85 | vmg_float val;
|
|---|
| 86 |
|
|---|
| 87 | Comm& comm = *MG::GetComm();
|
|---|
| 88 |
|
|---|
| 89 | Grid& sol_c = sol(sol.Level());
|
|---|
| 90 | Grid& rhs_c = rhs(rhs.Level());
|
|---|
| 91 |
|
|---|
| 92 | Grid& sol_f_dist = sol(sol.Level()+1);
|
|---|
| 93 | Grid& rhs_f_dist = rhs(rhs.Level()+1);
|
|---|
| 94 |
|
|---|
| 95 | Grid& sol_f_undist = comm.GetFinerGrid(sol);
|
|---|
| 96 | Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
|
|---|
| 97 |
|
|---|
| 98 | const Stencil& op = OperatorProlongate();
|
|---|
| 99 |
|
|---|
| 100 | Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin();
|
|---|
| 101 | Index end_f = sol_f_undist.Local().End();
|
|---|
| 102 |
|
|---|
| 103 | if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
|
|---|
| 104 | begin_f += rhs_f_undist.Local().BoundarySize1();
|
|---|
| 105 | end_f -= rhs_f_undist.Local().BoundarySize2();
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | const GridIteratorSet bounds_f(begin_f, end_f);
|
|---|
| 109 | const GridIteratorSet bounds_c(sol_c.Local().FinerBegin(), sol_c.Local().FinerEnd());
|
|---|
| 110 |
|
|---|
| 111 | sol_f_undist.ClearHalo();
|
|---|
| 112 |
|
|---|
| 113 | comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
|
|---|
| 114 |
|
|---|
| 115 | for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
|
|---|
| 116 | val = sol_c.GetVal(*iter_c);
|
|---|
| 117 | sol_f_undist(*iter_f) += op.GetDiag() * val;
|
|---|
| 118 | for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
|
|---|
| 119 | sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
|
|---|
| 120 | iter_f->Y() + stencil_iter->Disp().Y(),
|
|---|
| 121 | iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | comm.CommFromGhosts(sol_f_undist);
|
|---|
| 125 | comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
|
|---|
| 126 |
|
|---|
| 127 | sol.ToFinerLevel();
|
|---|
| 128 | rhs.ToFinerLevel();
|
|---|
| 129 | }
|
|---|