source: src/grid/grid_index_translations.cpp@ f57182

Last change on this file since f57182 was a72216, checked in by Olaf Lenz <olenz@…>, 13 years ago

Fixed permissions.

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

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[fcf7f6]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
[dfed1c]19/**
20 * @file grid_index_translations.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Tue May 17 11:46:37 2011
23 *
24 * @brief Class to convert different representations of grid
25 * indices.
26 *
27 */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33#include <cassert>
34
35#include "base/helper.hpp"
36#include "grid/grid_index_translations.hpp"
37#include "grid/grid.hpp"
38#include "grid/multigrid.hpp"
39
40using namespace VMG;
41
42Index GridIndexTranslations::GlobalToLocal(const Index& index_global) const
43{
[ac6d04]44 const Index index_local = index_global - Father()->Global().LocalBegin() + Father()->Local().Begin();
45 return index_local;
[dfed1c]46}
47
48Index GridIndexTranslations::GlobalToFiner(const Index& index_global)
49{
[ac6d04]50 const Index index_finer = 2 * index_global;
51 return index_finer;
[dfed1c]52}
53
54Index GridIndexTranslations::GlobalToCoarser(const Index& index_global)
55{
[ac6d04]56 assert(index_global % 2 == 0);
57 const Index index_coarser = index_global / 2;
58 return index_coarser;
[dfed1c]59}
60
61Index GridIndexTranslations::GlobalToFiner(const Index& index_global, const int& num_levels)
62{
[ac6d04]63 const Index index_finer = Helper::intpow(2, num_levels) * index_global;
64 return index_finer;
[dfed1c]65}
66
67Index GridIndexTranslations::GlobalToCoarser(const Index& index_global, const int& num_levels)
68{
69 int quotient = Helper::intpow(2, num_levels);
[ac6d04]70 assert(index_global % quotient == 0);
71 const Index index_coarser = index_global / quotient;
72 return index_coarser;
[dfed1c]73}
74
75Index GridIndexTranslations::LocalToGlobal(const Index& index_local) const
76{
[ac6d04]77 const Index index_global = index_local - Father()->Local().Begin() + Father()->Global().LocalBegin();
78 return index_global;
[dfed1c]79}
80
81Index GridIndexTranslations::LocalToFiner(const Index& index_local) const
82{
83 assert(Father() != NULL);
84 assert(Father()->Father() != NULL);
85
86 const Multigrid& multigrid = *(Father()->Father());
87
88 assert(Father()->Level() < multigrid.MaxLevel());
89
[ac6d04]90 const Index index_global_fine = GlobalToFiner(LocalToGlobal(index_local));
91 const Index index_local_fine = multigrid(Father()->Level()+1).Indexing().GlobalToLocal(index_global_fine);
[dfed1c]92
[ac6d04]93 return index_local_fine;
[dfed1c]94}
95
96Index GridIndexTranslations::LocalToCoarser(const Index& index_local) const
97{
98 assert(Father() != NULL);
99 assert(Father()->Father() != NULL);
100
101 const Multigrid& multigrid = *(Father()->Father());
102
103 assert(Father()->Level() > multigrid.MinLevel());
104
[ac6d04]105 const Index index_global_coarse = GlobalToCoarser(LocalToGlobal(index_local));
106 const Index index_local_coarse = multigrid(Father()->Level()-1).Indexing().GlobalToLocal(index_global_coarse);
[dfed1c]107
[ac6d04]108 return index_local_coarse;
[dfed1c]109}
110
111Index GridIndexTranslations::FinestGlobalToLocal(const Index& index_finest) const
112{
[ac6d04]113 const Index index_local = GlobalToLocal(FinestGlobalToGlobal(index_finest));
114 return index_local;
[dfed1c]115}
116
117Index GridIndexTranslations::FinestGlobalToGlobal(const Index& index_finest) const
118{
[ac6d04]119 const int quotient = Helper::intpow(2, Father()->Father()->MaxLevel() - Father()->Level());
120 assert(index_finest % quotient == 0);
121 const Index index_global = index_finest / quotient;
122 return index_global;
[dfed1c]123}
124
125void GridIndexTranslations::FineToCoarse(Index& begin, Index& end)
126{
127 Index last_point = end - 1;
128
129 for (int j=0; j<3; ++j) {
130
131 if (begin[j] % 2 == 0)
132 begin[j] /= 2;
133 else
134 begin[j] = (begin[j]+1) / 2;
135
136 if (last_point[j] % 2 == 0)
137 last_point[j] /= 2;
138 else
139 last_point[j] = (last_point[j]-1) / 2;
140
141 }
142
143
144 end = last_point + 1;
145}
146
147void GridIndexTranslations::CoarseToFine(Index& begin, Index& end, const Index& size_global)
148{
149 for (int i=0; i<3; ++i) {
150
151 if (size_global[i] % 2 == 0) {
152
153 begin[i] = 2*begin[i];
154 end[i] = 2*end[i];
155
156 }else {
157
158 if (begin[i] > 0)
159 begin[i] = 2*begin[i] - 1;
160 end[i] = std::max(2*end[i] - 1, begin[i]);
161
162 }
163 }
164}
Note: See TracBrowser for help on using the repository browser.