source: src/comm/comm.cpp@ e3dbbf

Last change on this file since e3dbbf was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 3.3 KB
Line 
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>
16namespace 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
27using namespace VMG;
28
29vmg_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)
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());
56 norm += val*val;
57 }
58
59 norm = sqrt(sol().Extent().MeshWidth().Product() * GlobalSum(norm));
60
61 return norm;
62}
63
64Grid& Comm::GetParticleGrid()
65{
66 if (particle_grid != NULL)
67 return *particle_grid;
68
69 const Multigrid& multigrid = *MG::GetRhs();
70 const Grid& grid = multigrid(multigrid.MaxLevel());
71 LocalIndices local = grid.Local();
72
73 const int& near_field_cells = MG::GetFactory().GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS");
74
75 local.BoundaryBegin1() = 0;
76 local.BoundaryEnd1() = 0;
77 local.BoundarySize1() = 0;
78
79 local.BoundaryBegin2() = 0;
80 local.BoundaryEnd2() = 0;
81 local.BoundarySize2() = 0;
82
83 local.FinerBeginFoo() = 0;
84 local.FinerEndFoo() = 0;
85 local.FinerSizeFoo() = 0;
86
87 local.End() -= local.Begin();
88 local.Begin() = 0;
89
90 // Set grid size of intermediate temporary grid
91 for (int i=0; i<3; ++i) {
92
93 if (local.HaloSize1()[i] > 0) {
94 local.HaloBegin1()[i] = 0;
95 local.HaloEnd1()[i] = near_field_cells;
96 local.HaloSize1()[i] = near_field_cells;
97 local.Begin()[i] = near_field_cells;
98 local.End()[i] = local.Begin()[i] + local.Size()[i];
99 }
100
101 if (local.HaloSize2()[i] > 0) {
102 local.HaloBegin2()[i] = local.End()[i];
103 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells;
104 local.HaloSize2()[i] = near_field_cells;
105 }
106
107 }
108
109 local.SizeTotal() = local.Size() + local.HaloSize1() + local.HaloSize2();
110
111 particle_grid = new Grid(grid.Global(), local, grid.Extent());
112
113 return *particle_grid;
114}
115
116Comm::~Comm()
117{
118 delete dd;
119 delete particle_grid;
120}
121
122const std::string& Comm::OutputPath()
123{
124 if (!output_directory_is_created) {
125 output_path_str = CreateOutputDirectory();
126 output_directory_is_created = true;
127 }
128
129 return output_path_str;
130}
Note: See TracBrowser for help on using the repository browser.