| [dfed1c] | 1 | /**
|
|---|
| 2 | * @file comm.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Wed Jun 16 13:21:06 2010
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Base class for communication.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #ifdef HAVE_BOOST_FILESYSTEM
|
|---|
| 15 | #include <boost/filesystem.hpp>
|
|---|
| 16 | namespace fs = boost::filesystem;
|
|---|
| 17 | #endif
|
|---|
| 18 |
|
|---|
| 19 | #include "base/discretization.hpp"
|
|---|
| 20 | #include "base/helper.hpp"
|
|---|
| 21 | #include "base/stencil.hpp"
|
|---|
| 22 | #include "comm/comm.hpp"
|
|---|
| 23 | #include "comm/domain_decomposition.hpp"
|
|---|
| 24 | #include "grid/grid.hpp"
|
|---|
| 25 | #include "mg.hpp"
|
|---|
| 26 |
|
|---|
| 27 | using namespace VMG;
|
|---|
| 28 |
|
|---|
| 29 | vmg_float Comm::ComputeResidualNorm(Multigrid& sol, Multigrid& rhs)
|
|---|
| 30 | {
|
|---|
| 31 | #ifdef DEBUG_MATRIX_CHECKS
|
|---|
| 32 | sol().IsCompatible(rhs());
|
|---|
| 33 | sol().IsConsistent();
|
|---|
| 34 | rhs().IsConsistent();
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | Grid::iterator grid_iter;
|
|---|
| 38 | Stencil::iterator stencil_iter;
|
|---|
| 39 | vmg_float val;
|
|---|
| 40 | vmg_float norm = 0.0;
|
|---|
| 41 |
|
|---|
| 42 | const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol());
|
|---|
| 43 | const Stencil& A = MG::GetDiscretization()->GetStencil();
|
|---|
| 44 |
|
|---|
| 45 | this->CommToGhosts(sol());
|
|---|
| 46 |
|
|---|
| 47 | if (sol().Global().BoundaryType() == LocallyRefined)
|
|---|
| 48 | MG::GetDiscretization()->SetInnerBoundary(sol(), rhs(), sol(sol.Level()-1));
|
|---|
| 49 |
|
|---|
| 50 | for (grid_iter=rhs().Iterators().Local().Begin(); grid_iter!=rhs().Iterators().Local().End(); ++grid_iter) {
|
|---|
| 51 | val = rhs().GetVal(*grid_iter) - prefactor * A.GetDiag() * sol().GetVal(*grid_iter);
|
|---|
| 52 | for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter)
|
|---|
| [894a5f] | 53 | val -= prefactor * stencil_iter->Val() * sol().GetVal(grid_iter->X() + stencil_iter->Disp().X(),
|
|---|
| 54 | grid_iter->Y() + stencil_iter->Disp().Y(),
|
|---|
| 55 | grid_iter->Z() + stencil_iter->Disp().Z());
|
|---|
| [dfed1c] | 56 | norm += val*val;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | norm = sqrt( Helper::pow_3(sol().MeshWidth()) * GlobalSum(norm) );
|
|---|
| 60 |
|
|---|
| 61 | return norm;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| [894a5f] | 64 | Grid& Comm::GetParticleGrid()
|
|---|
| [dfed1c] | 65 | {
|
|---|
| [894a5f] | 66 | if (particle_grid != NULL)
|
|---|
| 67 | return *particle_grid;
|
|---|
| 68 |
|
|---|
| 69 | const Multigrid& multigrid = *MG::GetRhs();
|
|---|
| 70 | const Grid& grid = multigrid(multigrid.GlobalMaxLevel());
|
|---|
| 71 | LocalIndices local = grid.Local();
|
|---|
| 72 |
|
|---|
| 73 | const int& near_field_cells = MG::GetFactory().GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS");
|
|---|
| 74 |
|
|---|
| 75 | // We don't need a boundary on this grid
|
|---|
| 76 | local.End() -= local.Begin();
|
|---|
| 77 | local.Begin() = 0;
|
|---|
| 78 | local.BoundaryBegin1() = local.BoundaryEnd1() = 0;
|
|---|
| 79 | local.BoundaryBegin2() = local.BoundaryEnd2() = 0;
|
|---|
| 80 |
|
|---|
| 81 | // Set grid size of intermediate temporary grid
|
|---|
| 82 | for (int i=0; i<3; ++i) {
|
|---|
| 83 |
|
|---|
| 84 | if (local.HasHalo1()[i]) {
|
|---|
| 85 | local.HaloBegin1()[i] = 0;
|
|---|
| 86 | local.HaloEnd1()[i] = local.Begin()[i] = near_field_cells+1;
|
|---|
| 87 | local.End()[i] = local.Begin()[i] + local.Size()[i];
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | if (local.HasHalo2()[i]) {
|
|---|
| 91 | local.HaloBegin2()[i] = local.End()[i];
|
|---|
| 92 | local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells+1;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | local.SizeTotal() = local.Size() +
|
|---|
| 98 | local.HaloEnd1() - local.HaloBegin1() +
|
|---|
| 99 | local.HaloEnd2() - local.HaloBegin2();
|
|---|
| 100 |
|
|---|
| 101 | particle_grid = new Grid(grid.Global(), local, grid.Extent());
|
|---|
| 102 |
|
|---|
| 103 | return *particle_grid;
|
|---|
| [dfed1c] | 104 | }
|
|---|
| 105 |
|
|---|
| 106 | Comm::~Comm()
|
|---|
| 107 | {
|
|---|
| 108 | delete dd;
|
|---|
| [894a5f] | 109 | delete particle_grid;
|
|---|
| [dfed1c] | 110 | }
|
|---|
| 111 |
|
|---|
| 112 | const std::string& Comm::OutputPath()
|
|---|
| 113 | {
|
|---|
| 114 | if (!output_directory_is_created) {
|
|---|
| 115 | output_path_str = CreateOutputDirectory();
|
|---|
| 116 | output_directory_is_created = true;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | return output_path_str;
|
|---|
| 120 | }
|
|---|