| 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 comm.hpp
|
|---|
| 21 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 22 | * @date Wed Jun 16 13:21:06 2010
|
|---|
| 23 | *
|
|---|
| 24 | * @brief Base class for communication.
|
|---|
| 25 | *
|
|---|
| 26 | */
|
|---|
| 27 |
|
|---|
| 28 | #ifdef HAVE_CONFIG_H
|
|---|
| 29 | #include <config.h>
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #ifdef HAVE_BOOST_FILESYSTEM
|
|---|
| 33 | #include <boost/filesystem.hpp>
|
|---|
| 34 | namespace fs = boost::filesystem;
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | #include "base/discretization.hpp"
|
|---|
| 38 | #include "base/helper.hpp"
|
|---|
| 39 | #include "base/stencil.hpp"
|
|---|
| 40 | #include "comm/comm.hpp"
|
|---|
| 41 | #include "comm/domain_decomposition.hpp"
|
|---|
| 42 | #include "grid/grid.hpp"
|
|---|
| 43 | #include "mg.hpp"
|
|---|
| 44 |
|
|---|
| 45 | using namespace VMG;
|
|---|
| 46 |
|
|---|
| 47 | vmg_float Comm::ComputeResidualNorm(Multigrid& sol_mg, Multigrid& rhs_mg)
|
|---|
| 48 | {
|
|---|
| 49 | Stencil::iterator stencil_iter;
|
|---|
| 50 | vmg_float norm = 0.0;
|
|---|
| 51 |
|
|---|
| 52 | const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol_mg());
|
|---|
| 53 | const Stencil& A = MG::GetDiscretization()->GetStencil();
|
|---|
| 54 |
|
|---|
| 55 | this->CommToGhosts(sol_mg());
|
|---|
| 56 |
|
|---|
| 57 | if (sol_mg().Global().BoundaryType() == LocallyRefined)
|
|---|
| 58 | MG::GetDiscretization()->SetInnerBoundary(sol_mg(), rhs_mg(), sol_mg(sol_mg.Level()-1));
|
|---|
| 59 |
|
|---|
| 60 | const Grid& sol = sol_mg();
|
|---|
| 61 | const Grid& rhs = rhs_mg();
|
|---|
| 62 |
|
|---|
| 63 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 64 | sol.IsCompatible(rhs);
|
|---|
| 65 | sol.IsConsistent();
|
|---|
| 66 | rhs.IsConsistent();
|
|---|
| 67 | #endif
|
|---|
| 68 |
|
|---|
| 69 | for (int i=rhs.Local().Begin().X(); i<rhs.Local().End().X(); ++i)
|
|---|
| 70 | for (int j=rhs.Local().Begin().Y(); j<rhs.Local().End().Y(); ++j)
|
|---|
| 71 | for (int k=rhs.Local().Begin().Z(); k<rhs.Local().End().Z(); ++k) {
|
|---|
| 72 | vmg_float val = rhs.GetVal(i,j,k) - prefactor * A.GetDiag() * sol.GetVal(i,j,k);
|
|---|
| 73 | for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter)
|
|---|
| 74 | val -= prefactor * stencil_iter->Val() * sol.GetVal(i + stencil_iter->Disp().X(),
|
|---|
| 75 | j + stencil_iter->Disp().Y(),
|
|---|
| 76 | k + stencil_iter->Disp().Z());
|
|---|
| 77 | norm += val*val;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | norm = GlobalSum(norm);
|
|---|
| 81 | norm = std::sqrt(sol.Extent().MeshWidth().Product() * norm);
|
|---|
| 82 |
|
|---|
| 83 | return norm;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | Grid& Comm::GetParticleGrid()
|
|---|
| 87 | {
|
|---|
| 88 | if (particle_grid != NULL)
|
|---|
| 89 | return *particle_grid;
|
|---|
| 90 |
|
|---|
| 91 | const Multigrid& multigrid = *MG::GetRhs();
|
|---|
| 92 | const Grid& grid = multigrid(multigrid.MaxLevel());
|
|---|
| 93 | LocalIndices local = grid.Local();
|
|---|
| 94 |
|
|---|
| 95 | const int& near_field_cells = MG::GetFactory().GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS");
|
|---|
| 96 |
|
|---|
| 97 | local.BoundaryBegin1() = 0;
|
|---|
| 98 | local.BoundaryEnd1() = 0;
|
|---|
| 99 | local.BoundarySize1() = 0;
|
|---|
| 100 |
|
|---|
| 101 | local.BoundaryBegin2() = 0;
|
|---|
| 102 | local.BoundaryEnd2() = 0;
|
|---|
| 103 | local.BoundarySize2() = 0;
|
|---|
| 104 |
|
|---|
| 105 | local.End() -= local.Begin();
|
|---|
| 106 | local.Begin() = 0;
|
|---|
| 107 |
|
|---|
| 108 | // Set grid size of intermediate temporary grid
|
|---|
| 109 | for (int i=0; i<3; ++i) {
|
|---|
| 110 |
|
|---|
| 111 | if (local.HaloSize1()[i] > 0) {
|
|---|
| 112 | local.HaloBegin1()[i] = 0;
|
|---|
| 113 | local.HaloEnd1()[i] = near_field_cells;
|
|---|
| 114 | local.HaloSize1()[i] = near_field_cells;
|
|---|
| 115 | local.Begin()[i] = near_field_cells;
|
|---|
| 116 | local.End()[i] = local.Begin()[i] + local.Size()[i];
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | if (local.HaloSize2()[i] > 0) {
|
|---|
| 120 | local.HaloBegin2()[i] = local.End()[i];
|
|---|
| 121 | local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells;
|
|---|
| 122 | local.HaloSize2()[i] = near_field_cells;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | local.SizeTotal() = local.Size() + local.HaloSize1() + local.HaloSize2();
|
|---|
| 128 |
|
|---|
| 129 | particle_grid = new Grid(grid.Global(), local, grid.Extent());
|
|---|
| 130 |
|
|---|
| 131 | return *particle_grid;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | Comm::~Comm()
|
|---|
| 135 | {
|
|---|
| 136 | delete dd;
|
|---|
| 137 | delete particle_grid;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | const std::string& Comm::OutputPath()
|
|---|
| 141 | {
|
|---|
| 142 | if (!output_directory_is_created) {
|
|---|
| 143 | output_path_str = CreateOutputDirectory();
|
|---|
| 144 | output_directory_is_created = true;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | return output_path_str;
|
|---|
| 148 | }
|
|---|