source: src/grid/grid_index_translations.cpp@ ac6d04

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