[28c025] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * SamplingGrid.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: 25.07.2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | // include headers that implement a archive in simple text format
|
---|
| 36 | // otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
|
---|
| 37 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 38 | #include <boost/archive/text_iarchive.hpp>
|
---|
| 39 |
|
---|
| 40 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 41 |
|
---|
| 42 | #include "Jobs/Grid/SamplingGrid.hpp"
|
---|
| 43 |
|
---|
[fb3485] | 44 | #include <boost/bind.hpp>
|
---|
[98f8fe] | 45 | #include <limits>
|
---|
| 46 |
|
---|
[c889b7] | 47 | #include "CodePatterns/Assert.hpp"
|
---|
[cb3363] | 48 | #include "CodePatterns/Log.hpp"
|
---|
[28c025] | 49 |
|
---|
[1a00bb] | 50 | // static instances
|
---|
| 51 | const double SamplingGrid::zeroOffset[3] = { 0., 0., 0. };
|
---|
| 52 |
|
---|
| 53 | SamplingGrid::SamplingGrid() :
|
---|
| 54 | SamplingGridProperties()
|
---|
| 55 | {
|
---|
| 56 | setWindowSize(zeroOffset, zeroOffset);
|
---|
| 57 | ASSERT( getWindowGridPoints() == (size_t)0,
|
---|
| 58 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[c6355f] | 61 | SamplingGrid::SamplingGrid(const double _begin[3],
|
---|
| 62 | const double _end[3],
|
---|
| 63 | const int _level) :
|
---|
| 64 | SamplingGridProperties(_begin, _end, _level)
|
---|
| 65 | {
|
---|
| 66 | setWindowSize(zeroOffset, zeroOffset);
|
---|
| 67 | ASSERT( getWindowGridPoints() == (size_t)0,
|
---|
| 68 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[28c025] | 71 | SamplingGrid::SamplingGrid(const double _begin[3],
|
---|
[3d9a8d] | 72 | const double _end[3],
|
---|
[28c025] | 73 | const int _level,
|
---|
[c889b7] | 74 | const sampledvalues_t &_sampled_grid) :
|
---|
[3d9a8d] | 75 | SamplingGridProperties(_begin, _end, _level),
|
---|
[28c025] | 76 | sampled_grid(_sampled_grid)
|
---|
[1a00bb] | 77 | {
|
---|
| 78 | setWindowSize(_begin, _end);
|
---|
| 79 | ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
|
---|
| 80 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
| 81 | }
|
---|
[28c025] | 82 |
|
---|
| 83 | SamplingGrid::SamplingGrid(const SamplingGrid &_grid) :
|
---|
| 84 | SamplingGridProperties(_grid),
|
---|
| 85 | sampled_grid(_grid.sampled_grid)
|
---|
[1a00bb] | 86 | {
|
---|
[c6355f] | 87 | setWindowSize(_grid.begin_window, _grid.end_window);
|
---|
| 88 | ASSERT( getWindowGridPoints() == _grid.getWindowGridPoints(),
|
---|
| 89 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
[1a00bb] | 90 | }
|
---|
[28c025] | 91 |
|
---|
| 92 | SamplingGrid::SamplingGrid(const SamplingGridProperties &_props) :
|
---|
| 93 | SamplingGridProperties(_props)
|
---|
[1a00bb] | 94 | {
|
---|
[c6355f] | 95 | setWindowSize(zeroOffset, zeroOffset);
|
---|
| 96 | ASSERT( getWindowGridPoints() == (size_t)0,
|
---|
| 97 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
[1a00bb] | 98 | }
|
---|
[28c025] | 99 |
|
---|
[c889b7] | 100 | SamplingGrid::SamplingGrid(
|
---|
| 101 | const SamplingGridProperties &_props,
|
---|
| 102 | const sampledvalues_t &_sampled_grid) :
|
---|
| 103 | SamplingGridProperties(_props),
|
---|
| 104 | sampled_grid(_sampled_grid)
|
---|
[1a00bb] | 105 | {
|
---|
| 106 | setWindowSize(_props.begin, _props.end);
|
---|
| 107 | ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
|
---|
| 108 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
---|
| 109 | }
|
---|
[c889b7] | 110 |
|
---|
[28c025] | 111 | SamplingGrid::~SamplingGrid()
|
---|
| 112 | {}
|
---|
| 113 |
|
---|
[c0e8fb] | 114 | bool SamplingGrid::isCongruent(const SamplingGrid &_props) const
|
---|
| 115 | {
|
---|
| 116 | bool status = true;
|
---|
| 117 | status &= (static_cast<const SamplingGridProperties &>(*this) ==
|
---|
| 118 | static_cast<const SamplingGridProperties &>(_props));
|
---|
| 119 | for(size_t i = 0; i<3; ++i) {
|
---|
| 120 | status &= begin_window[i] == _props.begin_window[i];
|
---|
| 121 | status &= end_window[i] == _props.end_window[i];
|
---|
| 122 | }
|
---|
| 123 | return status;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[c889b7] | 126 | SamplingGrid& SamplingGrid::operator=(const SamplingGrid& other)
|
---|
| 127 | {
|
---|
| 128 | // check for self-assignment
|
---|
| 129 | if (this != &other) {
|
---|
| 130 | static_cast<SamplingGridProperties &>(*this) = other;
|
---|
[e2404f] | 131 | setWindowSize(other.begin_window, other.end_window);
|
---|
[c889b7] | 132 | sampled_grid = other.sampled_grid;
|
---|
| 133 | }
|
---|
| 134 | return *this;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[a1fcc6] | 137 | SamplingGrid& SamplingGrid::operator*=(const SamplingGrid& other)
|
---|
| 138 | {
|
---|
| 139 | // check that grids are compatible
|
---|
[c0e8fb] | 140 | if (isCongruent(other)) {
|
---|
[a1fcc6] | 141 | sampledvalues_t::iterator iter = sampled_grid.begin();
|
---|
| 142 | sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
|
---|
| 143 | for(; iter != sampled_grid.end(); ++iter, ++otheriter )
|
---|
| 144 | *iter *= (*otheriter);
|
---|
| 145 | } else {
|
---|
[c0e8fb] | 146 | ASSERT(0, "SamplingGrid::operator*=() - multiplying incongruent grids is so far not in the cards.");
|
---|
[a1fcc6] | 147 | }
|
---|
| 148 | return *this;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[c889b7] | 151 | void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
|
---|
| 152 | {
|
---|
[1a00bb] | 153 | /// check that grids are compatible
|
---|
[c889b7] | 154 | if (isCompatible(other)) {
|
---|
[1a00bb] | 155 | /// get maximum of window
|
---|
| 156 | double max_begin_window[3];
|
---|
| 157 | double max_end_window[3];
|
---|
| 158 | bool doExtend = false;
|
---|
| 159 | for (size_t index=0; index<3;++index) {
|
---|
| 160 | if (begin_window[index] >= other.begin_window[index]) {
|
---|
| 161 | max_begin_window[index] = other.begin_window[index];
|
---|
| 162 | doExtend = true;
|
---|
| 163 | } else {
|
---|
| 164 | max_begin_window[index] = begin_window[index];
|
---|
| 165 | }
|
---|
| 166 | if (end_window[index] >= other.end_window[index]) {
|
---|
| 167 | max_end_window[index] = end_window[index];
|
---|
| 168 | } else {
|
---|
| 169 | max_end_window[index] = other.end_window[index];
|
---|
| 170 | doExtend = true;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
[de6dfb] | 173 | LOG(2, "DEBUG: max begin is " << max_begin_window[0] << "," << max_begin_window[1] << "," << max_begin_window[2] << ".");
|
---|
| 174 | LOG(2, "DEBUG: max end is " << max_end_window[0] << "," << max_end_window[1] << "," << max_end_window[2] << ".");
|
---|
[1a00bb] | 175 | if (doExtend)
|
---|
| 176 | extendWindow(max_begin_window, max_end_window);
|
---|
| 177 | /// and copy other into larger window, too
|
---|
[de6dfb] | 178 | addOntoWindow(other.begin_window, other.end_window, other.sampled_grid, prefactor);
|
---|
[c889b7] | 179 | } else {
|
---|
| 180 | ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[620517] | 184 | const size_t SamplingGrid::getWindowGridPointsPerAxis(const size_t axis) const
|
---|
[3d9a8d] | 185 | {
|
---|
[620517] | 186 | static const double round_offset(
|
---|
| 187 | (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
|
---|
| 188 | 0.5 : 0.); // need offset to get to round_toward_nearest behavior
|
---|
| 189 | // const double total = getTotalLengthPerAxis(axis);
|
---|
| 190 | const double delta = getDeltaPerAxis(axis);
|
---|
| 191 | if (delta == 0)
|
---|
| 192 | return 0;
|
---|
| 193 | const double length = getWindowLengthPerAxis(axis);
|
---|
| 194 | if (length == 0)
|
---|
[1a00bb] | 195 | return 0;
|
---|
[620517] | 196 | return (size_t)(length/delta+round_offset);
|
---|
[1a00bb] | 197 | }
|
---|
| 198 |
|
---|
[cb3363] | 199 | double SamplingGrid::integral() const
|
---|
| 200 | {
|
---|
[98f8fe] | 201 | const double volume_element = getVolume()/(double)getTotalGridPoints();
|
---|
[cb3363] | 202 | double int_value = 0.;
|
---|
| 203 | for (sampledvalues_t::const_iterator iter = sampled_grid.begin();
|
---|
| 204 | iter != sampled_grid.end();
|
---|
| 205 | ++iter)
|
---|
| 206 | int_value += *iter;
|
---|
| 207 | int_value *= volume_element;
|
---|
| 208 | LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
|
---|
| 209 | return int_value;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[e72c61] | 212 | double SamplingGrid::integral(const SamplingGrid &weight) const
|
---|
| 213 | {
|
---|
| 214 | if (isCompatible(weight)) {
|
---|
[98f8fe] | 215 | const double volume_element = getVolume()/(double)getTotalGridPoints();
|
---|
[e72c61] | 216 | double int_value = 0.;
|
---|
| 217 | sampledvalues_t::const_iterator iter = sampled_grid.begin();
|
---|
| 218 | sampledvalues_t::const_iterator weightiter = weight.sampled_grid.begin();
|
---|
| 219 | for (;iter != sampled_grid.end();++iter,++weightiter)
|
---|
| 220 | int_value += (*weightiter) * (*iter);
|
---|
| 221 | int_value *= volume_element;
|
---|
| 222 | //LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
|
---|
| 223 | return int_value;
|
---|
| 224 | } else
|
---|
| 225 | return 0.;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[64bafe0] | 228 | double SamplingGrid::getNearestLowerGridPoint(
|
---|
| 229 | const double value, const size_t axis) const
|
---|
| 230 | {
|
---|
| 231 | const double length = end[axis] - begin[axis];
|
---|
| 232 | if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
|
---|
| 233 | return 0.;
|
---|
| 234 | } else {
|
---|
| 235 | const double offset = value - begin[axis];
|
---|
[56b04c] | 236 | // modify value a little if value actually has been on a grid point but
|
---|
| 237 | // perturbed by numerical rounding: here up, as we always go lower
|
---|
| 238 | const double factor =
|
---|
| 239 | floor((double)getGridPointsPerAxis()*(offset/length)
|
---|
| 240 | +std::numeric_limits<double>::epsilon()*1.e4);
|
---|
[64bafe0] | 241 | return factor*(length/(double)getGridPointsPerAxis());
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | double SamplingGrid::getNearestHigherGridPoint(
|
---|
| 246 | const double value, const size_t axis) const
|
---|
| 247 | {
|
---|
| 248 | const double length = end[axis] - begin[axis];
|
---|
| 249 | if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
|
---|
| 250 | return 0.;
|
---|
| 251 | } else {
|
---|
| 252 | const double offset = value - begin[axis];
|
---|
[56b04c] | 253 | // modify value a little if value actually has been on a grid point but
|
---|
| 254 | // perturbed by numerical rounding: here down, as we always go higher
|
---|
| 255 | const double factor =
|
---|
| 256 | ceil((double)getGridPointsPerAxis()*(offset/length)
|
---|
| 257 | -std::numeric_limits<double>::epsilon()*1.e4);
|
---|
[64bafe0] | 258 | return factor*(length/(double)getGridPointsPerAxis());
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 |
|
---|
[1a00bb] | 262 | void SamplingGrid::setWindowSize(
|
---|
| 263 | const double _begin_window[3],
|
---|
| 264 | const double _end_window[3])
|
---|
| 265 | {
|
---|
| 266 | for (size_t index=0;index<3;++index) {
|
---|
[64bafe0] | 267 | begin_window[index] = getNearestLowerGridPoint(_begin_window[index], index);
|
---|
| 268 | ASSERT( begin_window[index] >= begin[index],
|
---|
[e2404f] | 269 | "SamplingGrid::setWindowSize() - window starts earlier than domain on "
|
---|
| 270 | +toString(index)+"th component.");
|
---|
[64bafe0] | 271 | end_window[index] = getNearestHigherGridPoint(_end_window[index], index);
|
---|
| 272 | ASSERT( end_window[index] <= end[index],
|
---|
[e2404f] | 273 | "SamplingGrid::setWindowSize() - window ends later than domain on "
|
---|
| 274 | +toString(index)+"th component.");
|
---|
[1a00bb] | 275 | }
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | void SamplingGrid::setWindow(
|
---|
| 279 | const double _begin_window[3],
|
---|
| 280 | const double _end_window[3])
|
---|
| 281 | {
|
---|
| 282 | setWindowSize(_begin_window, _end_window);
|
---|
| 283 | const size_t gridpoints_window = getWindowGridPoints();
|
---|
[c6355f] | 284 | sampled_grid.clear();
|
---|
[1a00bb] | 285 | sampled_grid.resize(gridpoints_window, 0.);
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[e2404f] | 288 | void SamplingGrid::setDomain(
|
---|
| 289 | const double _begin[3],
|
---|
| 290 | const double _end[3])
|
---|
| 291 | {
|
---|
| 292 | setDomainSize(_begin, _end);
|
---|
| 293 | setWindowSize(_begin, _end);
|
---|
| 294 | const size_t gridpoints = getTotalGridPoints();
|
---|
| 295 | sampled_grid.resize(gridpoints, 0.);
|
---|
| 296 | }
|
---|
| 297 |
|
---|
[1a00bb] | 298 | void SamplingGrid::extendWindow(
|
---|
| 299 | const double _begin_window[3],
|
---|
| 300 | const double _end_window[3])
|
---|
| 301 | {
|
---|
| 302 | #ifndef NDEBUG
|
---|
| 303 | for(size_t index=0;index < 3; ++index) {
|
---|
[c6355f] | 304 | // check that we truly have to extend the window
|
---|
[1a00bb] | 305 | ASSERT ( begin_window[index] >= _begin_window[index],
|
---|
| 306 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
---|
| 307 | " of window start is greater than old value.");
|
---|
| 308 | ASSERT ( end_window[index] <= _end_window[index],
|
---|
| 309 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
---|
| 310 | " of window end is less than old value.");
|
---|
[c6355f] | 311 |
|
---|
| 312 | // check that we are still less than domain
|
---|
| 313 | ASSERT ( _begin_window[index] >= begin[index],
|
---|
| 314 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
---|
| 315 | " of window start is less than domain start.");
|
---|
| 316 | ASSERT ( _end_window[index] <= end[index],
|
---|
| 317 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
---|
| 318 | " of window end is greater than domain end.");
|
---|
[1a00bb] | 319 | }
|
---|
| 320 | #endif
|
---|
| 321 | // copy old window size and values
|
---|
| 322 | double old_begin_window[3];
|
---|
| 323 | double old_end_window[3];
|
---|
| 324 | for(size_t index=0;index<3;++index) {
|
---|
| 325 | old_begin_window[index] = begin_window[index];
|
---|
| 326 | old_end_window[index] = end_window[index];
|
---|
| 327 | }
|
---|
| 328 | sampledvalues_t old_values(sampled_grid);
|
---|
[de6dfb] | 329 | // set new window
|
---|
| 330 | setWindow(_begin_window,_end_window);
|
---|
[1a00bb] | 331 | // now extend it ...
|
---|
[de6dfb] | 332 | addOntoWindow(old_begin_window, old_end_window, old_values, +1.);
|
---|
| 333 | LOG(2, "DEBUG: Grid after extension is " << sampled_grid << ".");
|
---|
[1a00bb] | 334 | }
|
---|
| 335 |
|
---|
[fb3485] | 336 | static void addElements(
|
---|
| 337 | double &dest,
|
---|
| 338 | const double &source,
|
---|
| 339 | const double prefactor)
|
---|
| 340 | {
|
---|
| 341 | dest += prefactor*(source);
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[1a00bb] | 344 | void SamplingGrid::addOntoWindow(
|
---|
| 345 | const double _begin_window[3],
|
---|
| 346 | const double _end_window[3],
|
---|
[de6dfb] | 347 | const sampledvalues_t &_sampled_grid,
|
---|
| 348 | const double prefactor)
|
---|
[fb3485] | 349 | {
|
---|
| 350 | addWindowOntoWindow(
|
---|
| 351 | begin_window,
|
---|
| 352 | end_window,
|
---|
| 353 | _begin_window,
|
---|
| 354 | _end_window,
|
---|
| 355 | sampled_grid,
|
---|
| 356 | _sampled_grid,
|
---|
| 357 | boost::bind(addElements, _1, _2, boost::cref(prefactor)),
|
---|
| 358 | thiswindow);
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | void SamplingGrid::addWindowOntoWindow(
|
---|
| 362 | const double wbegin[3],
|
---|
| 363 | const double wend[3],
|
---|
| 364 | const double other_wbegin[3],
|
---|
| 365 | const double other_wend[3],
|
---|
| 366 | sampledvalues_t &sampled_grid,
|
---|
| 367 | const sampledvalues_t &other_sampled_grid,
|
---|
| 368 | boost::function<void (double &, const double &)> op,
|
---|
| 369 | enum LargerWindow choice)
|
---|
[1a00bb] | 370 | {
|
---|
| 371 | #ifndef NDEBUG
|
---|
| 372 | for(size_t index=0;index<3;++index) {
|
---|
[fb3485] | 373 | ASSERT( other_wbegin[index] >= wbegin[index],
|
---|
| 374 | "SamplingGrid::addWindowOntoWindow() - given smaller window starts earlier than larger window in component "
|
---|
[1a00bb] | 375 | +toString(index)+".");
|
---|
[fb3485] | 376 | ASSERT( other_wend[index] <= wend[index],
|
---|
| 377 | "SamplingGrid::addWindowOntoWindow() - given smaller window ends later than larger window in component "
|
---|
[1a00bb] | 378 | +toString(index)+".");
|
---|
| 379 | }
|
---|
| 380 | #endif
|
---|
| 381 | // the only issue are indices
|
---|
[c6355f] | 382 | const size_t gridpoints_axis = getGridPointsPerAxis();
|
---|
[de6dfb] | 383 | size_t pre_offset[3];
|
---|
| 384 | size_t post_offset[3];
|
---|
[1a00bb] | 385 | size_t length[3];
|
---|
[de6dfb] | 386 | size_t total[3];
|
---|
[64bafe0] | 387 | const double round_offset =
|
---|
| 388 | (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
|
---|
| 389 | 0.5 : 0.; // need offset to get to round_toward_nearest behavior
|
---|
[1a00bb] | 390 | for(size_t index=0;index<3;++index) {
|
---|
[64bafe0] | 391 | // we refrain from using floor/ceil as the window's starts and ends,
|
---|
| 392 | // the grids have to be compatible (equal level), should always be on
|
---|
| 393 | // discrete grid point locations.
|
---|
| 394 | const double delta = (double)gridpoints_axis/(end[index] - begin[index]);
|
---|
| 395 | // delta is conversion factor from box length to discrete length, i.e. number of points
|
---|
[fb3485] | 396 | pre_offset[index] = delta*(other_wbegin[index] - wbegin[index])+round_offset;
|
---|
| 397 | length[index] = delta*(other_wend[index] - other_wbegin[index])+round_offset;
|
---|
| 398 | post_offset[index] = delta*(wend[index] - other_wend[index])+round_offset;
|
---|
| 399 | total[index] = delta*(wend[index] - wbegin[index])+round_offset;
|
---|
[64bafe0] | 400 | // total is used as safe-guard against loss due to discrete conversion
|
---|
[de6dfb] | 401 | ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
|
---|
[fb3485] | 402 | "SamplingGrid::addWindowOntoWindow() - pre, post, and length don't sum up to total for "
|
---|
[de6dfb] | 403 | +toString(index)+"th component.");
|
---|
[1a00bb] | 404 | }
|
---|
[64bafe0] | 405 | // assert that calculated lengths match with given vector sizes
|
---|
[c6355f] | 406 | #ifndef NDEBUG
|
---|
| 407 | const size_t calculated_size = length[0]*length[1]*length[2];
|
---|
[fb3485] | 408 | ASSERT( calculated_size == other_sampled_grid.size(),
|
---|
| 409 | "SamplingGrid::addWindowOntoWindow() - not enough sampled values given: "
|
---|
| 410 | +toString(calculated_size)+" != "+toString(other_sampled_grid.size())+".");
|
---|
[c6355f] | 411 | ASSERT( calculated_size <= sampled_grid.size(),
|
---|
[fb3485] | 412 | "SamplingGrid::addWindowOntoWindow() - not enough sampled values available: "
|
---|
[c6355f] | 413 | +toString(calculated_size)+" <= "+toString(sampled_grid.size())+".");
|
---|
| 414 | const size_t total_size = total[0]*total[1]*total[2];
|
---|
| 415 | ASSERT( total_size == sampled_grid.size(),
|
---|
[fb3485] | 416 | "SamplingGrid::addWindowOntoWindow() - total size is not equal to number of present points: "
|
---|
[c6355f] | 417 | +toString(total_size)+" != "+toString(sampled_grid.size())+".");
|
---|
| 418 | #endif
|
---|
[1a00bb] | 419 | size_t N[3];
|
---|
[64bafe0] | 420 | // size_t counter = 0;
|
---|
[de6dfb] | 421 | sampledvalues_t::iterator griditer = sampled_grid.begin();
|
---|
[fb3485] | 422 | sampledvalues_t::const_iterator copyiter = other_sampled_grid.begin();
|
---|
| 423 | if (choice == thiswindow)
|
---|
| 424 | std::advance(griditer, pre_offset[0]*total[1]*total[2]);
|
---|
| 425 | else
|
---|
| 426 | std::advance(copyiter, pre_offset[0]*total[1]*total[2]);
|
---|
[de6dfb] | 427 | for(N[0]=0; N[0] < length[0]; ++N[0]) {
|
---|
[fb3485] | 428 | if (choice == thiswindow)
|
---|
| 429 | std::advance(griditer, pre_offset[1]*total[2]);
|
---|
| 430 | else
|
---|
| 431 | std::advance(copyiter, pre_offset[1]*total[2]);
|
---|
[de6dfb] | 432 | for(N[1]=0; N[1] < length[1]; ++N[1]) {
|
---|
[fb3485] | 433 | if (choice == thiswindow)
|
---|
| 434 | std::advance(griditer, pre_offset[2]);
|
---|
| 435 | else
|
---|
| 436 | std::advance(copyiter, pre_offset[2]);
|
---|
[de6dfb] | 437 | for(N[2]=0; N[2] < length[2]; ++N[2]) {
|
---|
[c6355f] | 438 | ASSERT( griditer != sampled_grid.end(),
|
---|
[fb3485] | 439 | "SamplingGrid::addWindowOntoWindow() - griditer is already at end of window.");
|
---|
| 440 | ASSERT( copyiter != other_sampled_grid.end(),
|
---|
| 441 | "SamplingGrid::addWindowOntoWindow() - griditer is already at end of window.");
|
---|
| 442 | op(*griditer, *copyiter);
|
---|
| 443 | ++griditer;
|
---|
| 444 | ++copyiter;
|
---|
[1a00bb] | 445 | }
|
---|
[fb3485] | 446 | if (choice == thiswindow)
|
---|
| 447 | std::advance(griditer, post_offset[2]);
|
---|
| 448 | else
|
---|
| 449 | std::advance(copyiter, post_offset[2]);
|
---|
[1a00bb] | 450 | }
|
---|
[fb3485] | 451 | if (choice == thiswindow)
|
---|
| 452 | std::advance(griditer, post_offset[1]*total[2]);
|
---|
| 453 | else
|
---|
| 454 | std::advance(copyiter, post_offset[1]*total[2]);
|
---|
[1a00bb] | 455 | }
|
---|
[c6355f] | 456 | #ifndef NDEBUG
|
---|
[fb3485] | 457 | if (choice == thiswindow)
|
---|
| 458 | std::advance(griditer, post_offset[0]*total[1]*total[2]);
|
---|
| 459 | else
|
---|
| 460 | std::advance(copyiter, post_offset[0]*total[1]*total[2]);
|
---|
[c6355f] | 461 | ASSERT( griditer == sampled_grid.end(),
|
---|
[fb3485] | 462 | "SamplingGrid::addWindowOntoWindow() - griditer is not at end of window.");
|
---|
| 463 | ASSERT( copyiter == other_sampled_grid.end(),
|
---|
| 464 | "SamplingGrid::addWindowOntoWindow() - copyiter is not at end of window.");
|
---|
[c6355f] | 465 | #endif
|
---|
[de6dfb] | 466 | LOG(2, "DEBUG: Grid after adding other is " << sampled_grid << ".");
|
---|
[1a00bb] | 467 | }
|
---|
| 468 |
|
---|
[c889b7] | 469 | std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
|
---|
| 470 | {
|
---|
[1a00bb] | 471 | ost << "SamplingGrid";
|
---|
| 472 | ost << " starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
|
---|
| 473 | ost << " ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
|
---|
| 474 | ost << ", window starting at " << other.begin_window[0] << "," << other.begin_window[1] << "," << other.begin_window[2];
|
---|
| 475 | ost << ", window ending at " << other.end_window[0] << "," << other.end_window[1] << "," << other.end_window[2];
|
---|
[80959a1] | 476 | ost << ", level of " << other.level;
|
---|
| 477 | ost << " and integrated value of " << other.integral();
|
---|
[c889b7] | 478 | return ost;
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[beb16e] | 481 | template<> SamplingGrid ZeroInstance<SamplingGrid>()
|
---|
| 482 | {
|
---|
| 483 | SamplingGrid returnvalue;
|
---|
| 484 | return returnvalue;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[28c025] | 487 | // we need to explicitly instantiate the serialization functions as
|
---|
| 488 | // its is only serialized through its base class FragmentJob
|
---|
| 489 | BOOST_CLASS_EXPORT_IMPLEMENT(SamplingGrid)
|
---|