source: src/comm/comm.cpp@ fcf7f6

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

vmg: Added license files and headers (GPLv3).

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

  • Property mode set to 100644
File size: 4.1 KB
Line 
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>
34namespace 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
45using namespace VMG;
46
47vmg_float Comm::ComputeResidualNorm(Multigrid& sol_mg, Multigrid& rhs_mg)
48{
49#ifdef DEBUG_MATRIX_CHECKS
50 sol().IsCompatible(rhs());
51 sol().IsConsistent();
52 rhs().IsConsistent();
53#endif
54
55 Stencil::iterator stencil_iter;
56 vmg_float norm = 0.0;
57
58 const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol_mg());
59 const Stencil& A = MG::GetDiscretization()->GetStencil();
60
61 this->CommToGhosts(sol_mg());
62
63 if (sol_mg().Global().BoundaryType() == LocallyRefined)
64 MG::GetDiscretization()->SetInnerBoundary(sol_mg(), rhs_mg(), sol_mg(sol_mg.Level()-1));
65
66 const Grid& sol = sol_mg();
67 const Grid& rhs = rhs_mg();
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
86Grid& 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.FinerBegin() = 0;
106 local.FinerEnd() = 0;
107 local.FinerSize() = 0;
108
109 local.End() -= local.Begin();
110 local.Begin() = 0;
111
112 // Set grid size of intermediate temporary grid
113 for (int i=0; i<3; ++i) {
114
115 if (local.HaloSize1()[i] > 0) {
116 local.HaloBegin1()[i] = 0;
117 local.HaloEnd1()[i] = near_field_cells;
118 local.HaloSize1()[i] = near_field_cells;
119 local.Begin()[i] = near_field_cells;
120 local.End()[i] = local.Begin()[i] + local.Size()[i];
121 }
122
123 if (local.HaloSize2()[i] > 0) {
124 local.HaloBegin2()[i] = local.End()[i];
125 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells;
126 local.HaloSize2()[i] = near_field_cells;
127 }
128
129 }
130
131 local.SizeTotal() = local.Size() + local.HaloSize1() + local.HaloSize2();
132
133 particle_grid = new Grid(grid.Global(), local, grid.Extent());
134
135 return *particle_grid;
136}
137
138Comm::~Comm()
139{
140 delete dd;
141 delete particle_grid;
142}
143
144const std::string& Comm::OutputPath()
145{
146 if (!output_directory_is_created) {
147 output_path_str = CreateOutputDirectory();
148 output_directory_is_created = true;
149 }
150
151 return output_path_str;
152}
Note: See TracBrowser for help on using the repository browser.