[de061d] | 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 jacobi.hpp
|
---|
| 21 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
---|
| 22 | * @date Fri Apr 27 19:50:36 2012
|
---|
| 23 | *
|
---|
| 24 | * @brief Jacobi smoother
|
---|
| 25 | *
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | #ifdef HAVE_CONFIG_H
|
---|
| 29 | #include <libvmg_config.h>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #ifdef HAVE_MPI
|
---|
| 33 | #include <mpi.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | #include "base/discretization.hpp"
|
---|
| 37 | #include "base/stencil.hpp"
|
---|
| 38 | #include "comm/comm.hpp"
|
---|
| 39 | #include "grid/grid.hpp"
|
---|
| 40 | #include "grid/tempgrid.hpp"
|
---|
| 41 | #include "smoother/jacobi.hpp"
|
---|
| 42 | #include "mg.hpp"
|
---|
| 43 |
|
---|
| 44 | using namespace VMG;
|
---|
| 45 |
|
---|
| 46 | static inline void ComputePartial(Grid& sol_new, const Grid& sol_old, const Grid& rhs,
|
---|
| 47 | const Stencil& mat, const GridIteratorSet& bounds,
|
---|
| 48 | const vmg_float& prefactor, const vmg_float& diag_inv)
|
---|
| 49 | {
|
---|
| 50 | Grid::iterator grid_iter;
|
---|
| 51 | Stencil::iterator stencil_iter;
|
---|
| 52 |
|
---|
| 53 | for (grid_iter=bounds.Begin(); grid_iter!=bounds.End(); ++grid_iter) {
|
---|
| 54 | sol_new(*grid_iter) = prefactor * rhs.GetVal(*grid_iter);
|
---|
| 55 | for (stencil_iter=mat.begin(); stencil_iter!=mat.end(); ++stencil_iter)
|
---|
| 56 | sol_new(*grid_iter) -= stencil_iter->Val() * sol_old.GetVal(*grid_iter + stencil_iter->Disp());
|
---|
| 57 | sol_new(*grid_iter) *= diag_inv;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void Jacobi::Compute(Grid& sol, Grid& rhs)
|
---|
| 62 | {
|
---|
| 63 | Comm& comm = *MG::GetComm();
|
---|
| 64 | TempGrid& sol_new = *MG::GetTempGrid();
|
---|
| 65 |
|
---|
| 66 | const Stencil& mat = MG::GetDiscretization()->GetStencil();
|
---|
| 67 | const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol);
|
---|
| 68 | const vmg_float diag_inv = 1.0 / mat.GetDiag();
|
---|
| 69 |
|
---|
| 70 | sol_new.SetProperties(sol);
|
---|
| 71 |
|
---|
| 72 | comm.CommToGhostsAsyncStart(sol);
|
---|
| 73 | ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().InnerLocalGrid(), prefactor_inv, diag_inv);
|
---|
| 74 | comm.CommToGhostsAsyncFinish(sol);
|
---|
| 75 |
|
---|
| 76 | for (int i=0; i<3; ++i) {
|
---|
| 77 | ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().NearBoundary1()[i], prefactor_inv, diag_inv);
|
---|
| 78 | ComputePartial(sol_new, sol, rhs, mat, sol.Iterators().NearBoundary2()[i], prefactor_inv, diag_inv);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | sol.SetGrid(sol_new);
|
---|
| 82 | }
|
---|