Ignore:
Timestamp:
Apr 5, 2013, 12:39:30 PM (13 years ago)
Author:
Julian Iseringhausen <julian.iseringhausen@…>
Children:
4a709e
Parents:
f57182
Message:

Merge stashed open boundary stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/grid/grid_index_translations.cpp

    rf57182 r8180d8  
    3131#endif
    3232
    33 #include <cassert>
    34 
    3533#include "base/helper.hpp"
     34#include "grid/grid_double_iterator.hpp"
    3635#include "grid/grid_index_translations.hpp"
    3736#include "grid/grid.hpp"
     
    4039using namespace VMG;
    4140
    42 Index GridIndexTranslations::GlobalToLocal(const Index& index_global) const
     41bool GridIndexTranslations::IsGridPointOf(const Grid& grid, const Index& index_finest)
    4342{
    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;
    4647}
    4748
    48 Index GridIndexTranslations::GlobalToFiner(const Index& index_global)
     49Index GridIndexTranslations::LocalToGlobal(const Grid& grid, const Index& index_local)
    4950{
    50   const Index index_finer = 2 * index_global;
    51   return index_finer;
     51  return index_local - grid.Local().Begin() + grid.Global().LocalBegin();
    5252}
    5353
    54 Index GridIndexTranslations::GlobalToCoarser(const Index& index_global)
     54Index GridIndexTranslations::LocalToGlobalFinest(const Grid& grid, const Index& index_local)
    5555{
    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));
    5957}
    6058
    61 Index GridIndexTranslations::GlobalToFiner(const Index& index_global, const int& num_levels)
     59Index GridIndexTranslations::GlobalToLocal(const Grid& grid, const Index& index_global)
    6260{
    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();
    6562}
    6663
    67 Index GridIndexTranslations::GlobalToCoarser(const Index& index_global, const int& num_levels)
     64Index GridIndexTranslations::GlobalToGlobalFinest(const Grid& grid, const Index& index_global)
    6865{
    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;
    7368}
    7469
    75 Index GridIndexTranslations::LocalToGlobal(const Index& index_local) const
     70Index GridIndexTranslations::GlobalFinestToLocal(const Grid& grid, const Index& index_finest)
    7671{
    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));
    7973}
    8074
    81 Index GridIndexTranslations::LocalToFiner(const Index& index_local) const
     75Index GridIndexTranslations::GlobalFinestToGlobal(const Grid& grid, const Index& index_finest)
    8276{
    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());
    9480}
    9581
    96 Index GridIndexTranslations::LocalToCoarser(const Index& index_local) const
     82void GridIndexTranslations::GlobalCoarseToFine(Index& begin, Index& end)
    9783{
    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  }
    10988}
    11089
    111 Index GridIndexTranslations::FinestGlobalToLocal(const Index& index_finest) const
     90void GridIndexTranslations::GlobalFineToCoarse(Index& begin, Index& end)
    11291{
    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  }
    11596}
    11697
    117 Index GridIndexTranslations::FinestGlobalToGlobal(const Index& index_finest) const
     98void GridIndexTranslations::GetGridAlignment(const Grid& grid_1, GridIteratorSet& bounds_1,
     99                      const Grid& grid_2, GridIteratorSet& bounds_2)
    118100{
    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);
    124103
    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());
    128108
    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());
    130112
    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));
    135115
    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);
    140136
    141137  }
    142 
    143 
    144   end = last_point + 1;
    145138}
    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.