| [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 |
|
|---|
| 52 | val = rhs().GetVal(*grid_iter) - prefactor * A.GetDiag() * sol().GetVal(*grid_iter);
|
|---|
| 53 |
|
|---|
| 54 | for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter)
|
|---|
| 55 | val -= prefactor * stencil_iter->Val() * sol().GetVal(*grid_iter + stencil_iter->Disp());
|
|---|
| 56 |
|
|---|
| 57 | norm += val*val;
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | norm = sqrt( Helper::pow_3(sol().MeshWidth()) * GlobalSum(norm) );
|
|---|
| 62 |
|
|---|
| 63 | return norm;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void Comm::InitComm()
|
|---|
| 67 | {
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | Comm::~Comm()
|
|---|
| 71 | {
|
|---|
| 72 | delete dd;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | const std::string& Comm::OutputPath()
|
|---|
| 76 | {
|
|---|
| 77 | if (!output_directory_is_created) {
|
|---|
| 78 | output_path_str = CreateOutputDirectory();
|
|---|
| 79 | output_directory_is_created = true;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | return output_path_str;
|
|---|
| 83 | }
|
|---|