Ignore:
Timestamp:
Jun 8, 2016, 9:04:17 PM (9 years ago)
Author:
Frederik Heber <heber@…>
Children:
e34888
Parents:
a5d4c3
git-author:
Frederik Heber <heber@…> (06/01/16 08:51:01)
git-committer:
Frederik Heber <heber@…> (06/08/16 21:04:17)
Message:

WindowGrid_converter's refactored a bit with getDiscreteWindowOffsets().

  • Added SamplingGrid::getDiscreteWindowOffsets().
  • WindowGrid_converter now also use NDIM instead of 3 to clarify the use of the spatial degrees of freedom (and not some grid level or else).
File:
1 edited

Legend:

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

    ra5d4c3 rf84241  
    452452    ASSERT( (_wend[index] - _wbegin[index]) == _wlength[index],
    453453        "SamplingGrid::getDiscreteWindowCopyIndices() - end - begin is not equal to length for "
     454        +toString(index)+"th component.");
     455  }
     456}
     457
     458void SamplingGrid::getDiscreteWindowOffsets(
     459    size_t _pre_offset[NDIM],
     460    size_t _post_offset[NDIM],
     461    size_t _length[NDIM],
     462    size_t _total[NDIM]) const
     463{
     464  const double round_offset =
     465      (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
     466          0.5 : 0.; // need offset to get to round_toward_nearest behavior
     467  for(size_t index=0;index<NDIM;++index) {
     468    if (fabs(end[index] - begin[index]) > std::numeric_limits<double>::epsilon()*1e4) {
     469      // we refrain from using floor/ceil as the window's starts and ends,
     470      // the grids have to be compatible (equal level), should always be on
     471      // discrete grid point locations.
     472      const double delta = getDeltaPerAxis(index);
     473      // delta is conversion factor from box length to discrete length, i.e. number of points
     474      _pre_offset[index] = (begin_window[index] - begin[index])/delta+round_offset;
     475      _post_offset[index] = (end[index] - end_window[index])/delta+round_offset;
     476      _length[index] = (end_window[index] - begin_window[index])/delta+round_offset;
     477      _total[index] = (end[index] - begin[index])/delta+round_offset;
     478    } else {
     479      _pre_offset[index] = 0;
     480      _post_offset[index] = 0;
     481      _length[index] = 0;
     482      _total[index] = 0;
     483    }
     484    // total is used as safe-guard against loss due to discrete conversion
     485    ASSERT( (_pre_offset[index] + _post_offset[index]) + _length[index] == _total[index],
     486        "SamplingGrid::getDiscreteWindowCopyIndices() - pre, length, post are not equal to total for "
    454487        +toString(index)+"th component.");
    455488  }
Note: See TracChangeset for help on using the changeset viewer.