Changeset 8180d8 for src/grid/grid_index_translations.cpp
- Timestamp:
- Apr 5, 2013, 12:39:30 PM (13 years ago)
- Children:
- 4a709e
- Parents:
- f57182
- File:
-
- 1 edited
-
src/grid/grid_index_translations.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/grid/grid_index_translations.cpp
rf57182 r8180d8 31 31 #endif 32 32 33 #include <cassert>34 35 33 #include "base/helper.hpp" 34 #include "grid/grid_double_iterator.hpp" 36 35 #include "grid/grid_index_translations.hpp" 37 36 #include "grid/grid.hpp" … … 40 39 using namespace VMG; 41 40 42 Index GridIndexTranslations::GlobalToLocal(const Index& index_global) const 41 bool GridIndexTranslations::IsGridPointOf(const Grid& grid, const Index& index_finest) 43 42 { 44 const Index index_local = index_global - Father()->Global().LocalBegin() + Father()->Local().Begin(); 45 return index_local; 43 assert(grid.Father() != NULL); 44 return index_finest[0] % Helper::intpow(2, grid.Father()->MaxLevel() - grid.Level()) == 0 && 45 index_finest[1] % Helper::intpow(2, grid.Father()->MaxLevel() - grid.Level()) == 0 && 46 index_finest[2] % Helper::intpow(2, grid.Father()->MaxLevel() - grid.Level()) == 0; 46 47 } 47 48 48 Index GridIndexTranslations:: GlobalToFiner(const Index& index_global)49 Index GridIndexTranslations::LocalToGlobal(const Grid& grid, const Index& index_local) 49 50 { 50 const Index index_finer = 2 * index_global; 51 return index_finer; 51 return index_local - grid.Local().Begin() + grid.Global().LocalBegin(); 52 52 } 53 53 54 Index GridIndexTranslations:: GlobalToCoarser(const Index& index_global)54 Index GridIndexTranslations::LocalToGlobalFinest(const Grid& grid, const Index& index_local) 55 55 { 56 assert(index_global % 2 == 0); 57 const Index index_coarser = index_global / 2; 58 return index_coarser; 56 return GlobalToGlobalFinest(grid, LocalToGlobal(grid, index_local)); 59 57 } 60 58 61 Index GridIndexTranslations::GlobalTo Finer(const Index& index_global, const int& num_levels)59 Index GridIndexTranslations::GlobalToLocal(const Grid& grid, const Index& index_global) 62 60 { 63 const Index index_finer = Helper::intpow(2, num_levels) * index_global; 64 return index_finer; 61 return index_global - grid.Global().LocalBegin() + grid.Local().Begin(); 65 62 } 66 63 67 Index GridIndexTranslations::GlobalTo Coarser(const Index& index_global, const int& num_levels)64 Index GridIndexTranslations::GlobalToGlobalFinest(const Grid& grid, const Index& index_global) 68 65 { 69 int quotient = Helper::intpow(2, num_levels); 70 assert(index_global % quotient == 0); 71 const Index index_coarser = index_global / quotient; 72 return index_coarser; 66 assert(grid.Father() != NULL); 67 return Helper::intpow(2, grid.Father()->MaxLevel() - grid.Level()) * index_global; 73 68 } 74 69 75 Index GridIndexTranslations:: LocalToGlobal(const Index& index_local) const70 Index GridIndexTranslations::GlobalFinestToLocal(const Grid& grid, const Index& index_finest) 76 71 { 77 const Index index_global = index_local - Father()->Local().Begin() + Father()->Global().LocalBegin(); 78 return index_global; 72 return GlobalToLocal(grid, GlobalFinestToGlobal(grid, index_finest)); 79 73 } 80 74 81 Index GridIndexTranslations:: LocalToFiner(const Index& index_local) const75 Index GridIndexTranslations::GlobalFinestToGlobal(const Grid& grid, const Index& index_finest) 82 76 { 83 assert(Father() != NULL); 84 assert(Father()->Father() != NULL); 85 86 const Multigrid& multigrid = *(Father()->Father()); 87 88 assert(Father()->Level() < multigrid.MaxLevel()); 89 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); 92 93 return index_local_fine; 77 assert(grid.Father() != NULL); 78 assert(IsGridPointOf(grid, index_finest)); 79 return index_finest / Helper::intpow(2, grid.Father()->MaxLevel() - grid.Level()); 94 80 } 95 81 96 Index GridIndexTranslations::LocalToCoarser(const Index& index_local) const 82 void GridIndexTranslations::GlobalCoarseToFine(Index& begin, Index& end) 97 83 { 98 assert(Father() != NULL); 99 assert(Father()->Father() != NULL); 100 101 const Multigrid& multigrid = *(Father()->Father()); 102 103 assert(Father()->Level() > multigrid.MinLevel()); 104 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); 107 108 return index_local_coarse; 84 for (int j=0; j<3; ++j) { 85 begin[j] = 2 * begin[j]; 86 end[j] = 2 * (end[j]-1) + 1; 87 } 109 88 } 110 89 111 Index GridIndexTranslations::FinestGlobalToLocal(const Index& index_finest) const 90 void GridIndexTranslations::GlobalFineToCoarse(Index& begin, Index& end) 112 91 { 113 const Index index_local = GlobalToLocal(FinestGlobalToGlobal(index_finest)); 114 return index_local; 92 for (int j=0; j<3; ++j) { 93 begin[j] = Helper::RoundUpToNextMultiple(begin[j], 2) / 2; 94 end[j] = Helper::RoundDownToNextMultiple(end[j]-1, 2) / 2 + 1; 95 } 115 96 } 116 97 117 Index GridIndexTranslations::FinestGlobalToGlobal(const Index& index_finest) const 98 void GridIndexTranslations::GetGridAlignment(const Grid& grid_1, GridIteratorSet& bounds_1, 99 const Grid& grid_2, GridIteratorSet& bounds_2) 118 100 { 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; 123 } 101 assert(grid_1.Father() != NULL); 102 assert(grid_2.Father() != NULL); 124 103 125 void GridIndexTranslations::FineToCoarse(Index& begin, Index& end) 126 { 127 Index last_point = end - 1; 104 if (grid_1.Level() == grid_2.Level()) { 105 const Index begin_global = grid_1.Global() 106 .LocalBegin() 107 .Clamp(grid_2.Global().LocalBegin(), grid_2.Global().LocalEnd()); 128 108 129 for (int j=0; j<3; ++j) { 109 const Index end_global = grid_1.Global() 110 .LocalEnd() 111 .Clamp(grid_2.Global().LocalBegin(), grid_2.Global().LocalEnd()); 130 112 131 if (begin[j] % 2 == 0) 132 begin[j] /= 2; 133 else 134 begin[j] = (begin[j]+1) / 2; 113 bounds_1 = GridIteratorSet(GlobalToLocal(grid_1, begin_global), GlobalToLocal(grid_2, end_global)); 114 bounds_2 = GridIteratorSet(GlobalToLocal(grid_2, begin_global), GlobalToLocal(grid_2, end_global)); 135 115 136 if (last_point[j] % 2 == 0) 137 last_point[j] /= 2; 138 else 139 last_point[j] = (last_point[j]-1) / 2; 116 } else { 117 118 const Grid& grid_c = (grid_1.Level() < grid_2.Level() ? grid_1 : grid_2); 119 const int global_mult = Helper::intpow(2, grid_c.Father()->MaxLevel() - grid_c.Level()); 120 121 Index begin_finest = GlobalToGlobalFinest(grid_1, grid_1.Global().LocalBegin()) 122 .Clamp(GlobalToGlobalFinest(grid_2, grid_2.Global().LocalBegin()), 123 GlobalToGlobalFinest(grid_2, grid_2.Global().LocalEnd()-1)); 124 125 Index end_finest = GlobalToGlobalFinest(grid_1, grid_1.Global().LocalEnd()-1) 126 .Clamp(GlobalToGlobalFinest(grid_2, grid_2.Global().LocalBegin()), 127 GlobalToGlobalFinest(grid_2, grid_2.Global().LocalEnd()-1)); 128 129 for (int j=0; j<3; ++j) { 130 begin_finest[j] = Helper::RoundUpToNextMultiple(begin_finest[j], global_mult); 131 end_finest[j] = Helper::RoundDownToNextMultiple(end_finest[j], global_mult); 132 } 133 134 bounds_1 = GridIteratorSet(GlobalFinestToLocal(grid_1, begin_finest), GlobalFinestToLocal(grid_1, end_finest)+1); 135 bounds_2 = GridIteratorSet(GlobalFinestToLocal(grid_2, begin_finest), GlobalFinestToLocal(grid_2, end_finest)+1); 140 136 141 137 } 142 143 144 end = last_point + 1;145 138 } 146 147 void 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 TracChangeset
for help on using the changeset viewer.
