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).
Location:
src/Fragmentation/Summation/SetValues
Files:
2 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  }
  • src/Fragmentation/Summation/SetValues/SamplingGrid.hpp

    ra5d4c3 rf84241  
    253253      size_t _wend[NDIM]) const;
    254254
     255  /** Returns number of grid points before the window, during the window, and
     256   * after the window including the total length of the domain for check.
     257   *
     258   * \param _pre_offset grid points before start of window
     259   * \param _post_offset grid points after end of window
     260   * \param _length grid points in window
     261   * \param _total grid points in domain
     262   */
     263  void getDiscreteWindowOffsets(
     264      size_t _pre_offset[NDIM],
     265      size_t _post_offset[NDIM],
     266      size_t _length[NDIM],
     267      size_t _total[NDIM]) const;
     268
    255269  /** Equality operator.
    256270   *
Note: See TracChangeset for help on using the changeset viewer.