Ignore:
Timestamp:
Jun 9, 2016, 5:55:45 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Children:
95e8da
Parents:
26f238
git-author:
Frederik Heber <heber@…> (05/26/16 18:15:19)
git-committer:
Frederik Heber <heber@…> (06/09/16 05:55:45)
Message:

SamplingGrid::downsample() uses padWithZerosForEvenNumberedSamples().

  • in the end this requires copying the original grid as we might need to pad it with zeros but should not change the given one.
  • Added some debugging information to downsample().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/SamplingGrid.cpp

    r26f238 r52ecd0  
    5050#include "CodePatterns/Assert.hpp"
    5151#include "CodePatterns/Log.hpp"
     52
     53#include "LinearAlgebra/Vector.hpp"
    5254
    5355// static instances
     
    792794  size_t wnewend_index[NDIM];
    793795  for(size_t i=0;i<NDIM;++i) {
     796    LOG(2, "INFO: window[" << i << "] starts at " << wbegin_index[i] << " and ends at "
     797        << wend_index[i] << " with length " << wlength_index[i]);
    794798    // We require begin and end of window on even indices (and inside grid).
    795799    wnewbegin_index[i] = wbegin_index[i];
     
    822826      end_newwindow[i] = begin[i]+delta*wnewend_index[i];
    823827    }
     828    LOG(2, "INFO: Original window is " << Vector(begin_window) << " <-> "  << Vector(end_window));
     829    LOG(2, "INFO: Padded window is " << Vector(begin_newwindow) << " <-> "  << Vector(end_newwindow));
    824830    // extend window
    825831    extendWindow(begin_newwindow, end_newwindow);
     
    836842{
    837843  if (&instance != &other) {
     844    LOG(2, "INFO: other's window is " << Vector(other.begin_window)
     845        << " <-> " << Vector(other.end_window));
    838846    // take over properties
    839847    static_cast<SamplingGridProperties &>(instance) = other;
    840848    instance.setWindowSize(other.begin_window, other.end_window);
     849    LOG(2, "INFO: Set instance's window to " << Vector(instance.begin_window)
     850        << " <-> " << Vector(instance.end_window));
    841851    ASSERT( _level <= other.level,
    842852        "SamplingGrid::downsample() - desired level "+toString(_level)
     
    850860      // have reached the desired one
    851861
    852       // the reference such that we never have to copy the full grid but only
    853       // downsampled ones
    854       const sampledvalues_t * sourcevalues = &other.sampled_grid;
    855       int length_d[3];
    856       int length_s[3];
    857       getLengthsOfWindow(length_s, other);
     862      // we need to copy the other grid because we might need to pad it with zeros anyway
     863      SamplingGrid FinerGrid(other);
     864      int length_d[NDIM];
     865      int length_s[NDIM];
    858866      for (instance.level = other.level-1; instance.level >= _level; --instance.level) {
     867        // pad with zeros for even indices and get length of fine grid window
     868        FinerGrid.padWithZerosForEvenNumberedSamples();
     869        getLengthsOfWindow(length_s, FinerGrid);
     870        ASSERT( FinerGrid.getWindowGridPoints() % 8 == 0,
     871            "SamplingGrid::downsample() - at level "+toString( instance.level)
     872            +" given grid points "+toString(FinerGrid.getWindowGridPoints())+" are not even numbered per axis anymore.");
     873        // re-adjust the window (length), get the corresponding window length and downsample
     874        instance.setWindow(FinerGrid.begin_window, FinerGrid.end_window);
    859875        getLengthsOfWindow(length_d, instance);
    860         // we always have an eighth of the number of sample points as we stop
    861         ASSERT( sourcevalues->size() % 8 == 0,
     876        ASSERT( instance.sampled_grid.size() == FinerGrid.getWindowGridPoints()/(size_t)8,
    862877            "SamplingGrid::downsample() - at level "+toString( instance.level)
    863             +" given grid points "+toString(sourcevalues->size())+" are not even numbered per axis anymore.");
    864         sampledvalues_t downsampled(sourcevalues->size()/(size_t)8, 0.);
    865         restrictFullWeight(downsampled, length_d, *sourcevalues, length_s);
    866         // then copy the downsampled values
    867         instance.sampled_grid = downsampled;
    868         sourcevalues = &instance.sampled_grid;
    869         // and exchange lengths
    870         for (size_t i=0;i<3;++i) {
    871           length_s[i] = length_d[i];
    872         }
     878            +" points on coarser grid "+toString(instance.sampled_grid.size())
     879            +" and downsampled number on finer grid "
     880            +toString(FinerGrid.getWindowGridPoints()/(size_t)8)+" do not match.");
     881        restrictFullWeight(instance.sampled_grid, length_d, FinerGrid.sampled_grid, length_s);
     882        // then use as new finer grid for next downsampling (if it's not the last level)
     883        if (instance.level > _level)
     884          FinerGrid = instance;
    873885      }
     886      // loop stops at _level-1
    874887      instance.level = _level;
    875888
Note: See TracChangeset for help on using the changeset viewer.