source: src/grid/grid_index_translations.cpp@ dfed1c

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

Major vmg update.

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

  • Property mode set to 100644
File size: 3.3 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 return index_global - Father()->Global().BeginLocal() + Father()->Local().Begin();
27}
28
29Index GridIndexTranslations::GlobalToFiner(const Index& index_global)
30{
31 return 2 * index_global;
32}
33
34Index GridIndexTranslations::GlobalToCoarser(const Index& index_global)
35{
36 for (int i=0; i<3; ++i)
37 assert(index_global[i] % 2 == 0);
38
39 return index_global / 2;
40}
41
42Index GridIndexTranslations::GlobalToFiner(const Index& index_global, const int& num_levels)
43{
44 return Helper::intpow(2, num_levels) * index_global;
45}
46
47Index GridIndexTranslations::GlobalToCoarser(const Index& index_global, const int& num_levels)
48{
49 int quotient = Helper::intpow(2, num_levels);
50
51 for (int i=0; i<3; ++i)
52 assert(index_global[i] % quotient == 0);
53
54 return index_global / quotient;
55}
56
57Index GridIndexTranslations::LocalToGlobal(const Index& index_local) const
58{
59 return index_local - Father()->Local().Begin() + Father()->Global().BeginLocal();
60}
61
62Index GridIndexTranslations::LocalToFiner(const Index& index_local) const
63{
64 assert(Father() != NULL);
65 assert(Father()->Father() != NULL);
66
67 const Multigrid& multigrid = *(Father()->Father());
68
69 assert(Father()->Level() < multigrid.MaxLevel());
70
71 Index index_global_fine = GlobalToFiner(LocalToGlobal(index_local));
72
73 return multigrid(Father()->Level()+1).Indexing().GlobalToLocal(index_global_fine);
74}
75
76Index GridIndexTranslations::LocalToCoarser(const Index& index_local) const
77{
78 assert(Father() != NULL);
79 assert(Father()->Father() != NULL);
80
81 const Multigrid& multigrid = *(Father()->Father());
82
83 assert(Father()->Level() > multigrid.MinLevel());
84
85 Index index_global_coarse = GlobalToCoarser(LocalToGlobal(index_local));
86
87 return multigrid(Father()->Level()-1).Indexing().GlobalToLocal(index_global_coarse);
88}
89
90Index GridIndexTranslations::FinestGlobalToLocal(const Index& index_finest) const
91{
92 return GlobalToLocal(FinestGlobalToGlobal(index_finest));
93}
94
95Index GridIndexTranslations::FinestGlobalToGlobal(const Index& index_finest) const
96{
97 int quotient = Helper::intpow(2, Father()->Father()->MaxLevel() - Father()->Level());
98
99 for (int i=0; i<3; ++i)
100 assert(index_finest[i] % quotient == 0);
101
102 return index_finest / quotient;
103}
104
105void GridIndexTranslations::FineToCoarse(Index& begin, Index& end)
106{
107 Index last_point = end - 1;
108
109 for (int j=0; j<3; ++j) {
110
111 if (begin[j] % 2 == 0)
112 begin[j] /= 2;
113 else
114 begin[j] = (begin[j]+1) / 2;
115
116 if (last_point[j] % 2 == 0)
117 last_point[j] /= 2;
118 else
119 last_point[j] = (last_point[j]-1) / 2;
120
121 }
122
123
124 end = last_point + 1;
125}
126
127void GridIndexTranslations::CoarseToFine(Index& begin, Index& end, const Index& size_global)
128{
129 for (int i=0; i<3; ++i) {
130
131 if (size_global[i] % 2 == 0) {
132
133 begin[i] = 2*begin[i];
134 end[i] = 2*end[i];
135
136 }else {
137
138 if (begin[i] > 0)
139 begin[i] = 2*begin[i] - 1;
140 end[i] = std::max(2*end[i] - 1, begin[i]);
141
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.