source: src/comm/comm.cpp@ 49f8653

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

Increase serial performance.

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

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[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>
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
[49f8653]29vmg_float Comm::ComputeResidualNorm(Multigrid& sol_mg, Multigrid& rhs_mg)
[dfed1c]30{
31#ifdef DEBUG_MATRIX_CHECKS
32 sol().IsCompatible(rhs());
33 sol().IsConsistent();
34 rhs().IsConsistent();
35#endif
36
37 Stencil::iterator stencil_iter;
38 vmg_float norm = 0.0;
39
[49f8653]40 const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol_mg());
[dfed1c]41 const Stencil& A = MG::GetDiscretization()->GetStencil();
42
[49f8653]43 this->CommToGhosts(sol_mg());
44
45 if (sol_mg().Global().BoundaryType() == LocallyRefined)
46 MG::GetDiscretization()->SetInnerBoundary(sol_mg(), rhs_mg(), sol_mg(sol_mg.Level()-1));
47
48 const Grid& sol = sol_mg();
49 const Grid& rhs = rhs_mg();
50
51 for (int i=rhs.Local().Begin().X(); i<rhs.Local().End().X(); ++i)
52 for (int j=rhs.Local().Begin().Y(); j<rhs.Local().End().Y(); ++j)
53 for (int k=rhs.Local().Begin().Z(); k<rhs.Local().End().Z(); ++k) {
54 vmg_float val = rhs.GetVal(i,j,k) - prefactor * A.GetDiag() * sol.GetVal(i,j,k);
55 for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter)
56 val -= prefactor * stencil_iter->Val() * sol.GetVal(i + stencil_iter->Disp().X(),
57 j + stencil_iter->Disp().Y(),
58 k + stencil_iter->Disp().Z());
59 norm = val*val;
60 }
61
62 norm = GlobalSum(norm);
63 norm = std::sqrt(sol.Extent().MeshWidth().Product() * norm);
[dfed1c]64
65 return norm;
66}
67
[894a5f]68Grid& Comm::GetParticleGrid()
[dfed1c]69{
[894a5f]70 if (particle_grid != NULL)
71 return *particle_grid;
72
73 const Multigrid& multigrid = *MG::GetRhs();
[ac6d04]74 const Grid& grid = multigrid(multigrid.MaxLevel());
[894a5f]75 LocalIndices local = grid.Local();
76
77 const int& near_field_cells = MG::GetFactory().GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS");
78
[ac6d04]79 local.BoundaryBegin1() = 0;
80 local.BoundaryEnd1() = 0;
81 local.BoundarySize1() = 0;
82
83 local.BoundaryBegin2() = 0;
84 local.BoundaryEnd2() = 0;
85 local.BoundarySize2() = 0;
86
[716da7]87 local.FinerBegin() = 0;
88 local.FinerEnd() = 0;
89 local.FinerSize() = 0;
[ac6d04]90
[894a5f]91 local.End() -= local.Begin();
92 local.Begin() = 0;
93
94 // Set grid size of intermediate temporary grid
95 for (int i=0; i<3; ++i) {
96
[ac6d04]97 if (local.HaloSize1()[i] > 0) {
[894a5f]98 local.HaloBegin1()[i] = 0;
[ac6d04]99 local.HaloEnd1()[i] = near_field_cells;
100 local.HaloSize1()[i] = near_field_cells;
101 local.Begin()[i] = near_field_cells;
[894a5f]102 local.End()[i] = local.Begin()[i] + local.Size()[i];
103 }
104
[ac6d04]105 if (local.HaloSize2()[i] > 0) {
[894a5f]106 local.HaloBegin2()[i] = local.End()[i];
[ac6d04]107 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells;
108 local.HaloSize2()[i] = near_field_cells;
[894a5f]109 }
110
111 }
112
[ac6d04]113 local.SizeTotal() = local.Size() + local.HaloSize1() + local.HaloSize2();
[894a5f]114
115 particle_grid = new Grid(grid.Global(), local, grid.Extent());
116
117 return *particle_grid;
[dfed1c]118}
119
120Comm::~Comm()
121{
122 delete dd;
[894a5f]123 delete particle_grid;
[dfed1c]124}
125
126const std::string& Comm::OutputPath()
127{
128 if (!output_directory_is_created) {
129 output_path_str = CreateOutputDirectory();
130 output_directory_is_created = true;
131 }
132
133 return output_path_str;
134}
Note: See TracBrowser for help on using the repository browser.