| 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 |
|
|---|
| 44 | #include <limits>
|
|---|
| 45 |
|
|---|
| 46 | #include "CodePatterns/Assert.hpp"
|
|---|
| 47 | #include "CodePatterns/Log.hpp"
|
|---|
| 48 |
|
|---|
| 49 | // static instances
|
|---|
| 50 | const double SamplingGrid::zeroOffset[3] = { 0., 0., 0. };
|
|---|
| 51 |
|
|---|
| 52 | SamplingGrid::SamplingGrid() :
|
|---|
| 53 | SamplingGridProperties()
|
|---|
| 54 | {
|
|---|
| 55 | setWindowSize(zeroOffset, zeroOffset);
|
|---|
| 56 | ASSERT( getWindowGridPoints() == (size_t)0,
|
|---|
| 57 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | SamplingGrid::SamplingGrid(const double _begin[3],
|
|---|
| 61 | const double _end[3],
|
|---|
| 62 | const int _level) :
|
|---|
| 63 | SamplingGridProperties(_begin, _end, _level)
|
|---|
| 64 | {
|
|---|
| 65 | setWindowSize(zeroOffset, zeroOffset);
|
|---|
| 66 | ASSERT( getWindowGridPoints() == (size_t)0,
|
|---|
| 67 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | SamplingGrid::SamplingGrid(const double _begin[3],
|
|---|
| 71 | const double _end[3],
|
|---|
| 72 | const int _level,
|
|---|
| 73 | const sampledvalues_t &_sampled_grid) :
|
|---|
| 74 | SamplingGridProperties(_begin, _end, _level),
|
|---|
| 75 | sampled_grid(_sampled_grid)
|
|---|
| 76 | {
|
|---|
| 77 | setWindowSize(_begin, _end);
|
|---|
| 78 | ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
|
|---|
| 79 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | SamplingGrid::SamplingGrid(const SamplingGrid &_grid) :
|
|---|
| 83 | SamplingGridProperties(_grid),
|
|---|
| 84 | sampled_grid(_grid.sampled_grid)
|
|---|
| 85 | {
|
|---|
| 86 | setWindowSize(_grid.begin_window, _grid.end_window);
|
|---|
| 87 | ASSERT( getWindowGridPoints() == _grid.getWindowGridPoints(),
|
|---|
| 88 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | SamplingGrid::SamplingGrid(const SamplingGridProperties &_props) :
|
|---|
| 92 | SamplingGridProperties(_props)
|
|---|
| 93 | {
|
|---|
| 94 | setWindowSize(zeroOffset, zeroOffset);
|
|---|
| 95 | ASSERT( getWindowGridPoints() == (size_t)0,
|
|---|
| 96 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | SamplingGrid::SamplingGrid(
|
|---|
| 100 | const SamplingGridProperties &_props,
|
|---|
| 101 | const sampledvalues_t &_sampled_grid) :
|
|---|
| 102 | SamplingGridProperties(_props),
|
|---|
| 103 | sampled_grid(_sampled_grid)
|
|---|
| 104 | {
|
|---|
| 105 | setWindowSize(_props.begin, _props.end);
|
|---|
| 106 | ASSERT( getWindowGridPoints() == (size_t)_sampled_grid.size(),
|
|---|
| 107 | "SamplingGrid::SamplingGrid() - incorrect number of samples given for the window.");
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | SamplingGrid::~SamplingGrid()
|
|---|
| 111 | {}
|
|---|
| 112 |
|
|---|
| 113 | SamplingGrid& SamplingGrid::operator=(const SamplingGrid& other)
|
|---|
| 114 | {
|
|---|
| 115 | // check for self-assignment
|
|---|
| 116 | if (this != &other) {
|
|---|
| 117 | static_cast<SamplingGridProperties &>(*this) = other;
|
|---|
| 118 | setWindowSize(other.begin_window, other.end_window);
|
|---|
| 119 | sampled_grid = other.sampled_grid;
|
|---|
| 120 | }
|
|---|
| 121 | return *this;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | SamplingGrid& SamplingGrid::operator*=(const SamplingGrid& other)
|
|---|
| 125 | {
|
|---|
| 126 | // check that grids are compatible
|
|---|
| 127 | if (isCompatible(other)) {
|
|---|
| 128 | sampledvalues_t::iterator iter = sampled_grid.begin();
|
|---|
| 129 | sampledvalues_t::const_iterator otheriter = other.sampled_grid.begin();
|
|---|
| 130 | for(; iter != sampled_grid.end(); ++iter, ++otheriter )
|
|---|
| 131 | *iter *= (*otheriter);
|
|---|
| 132 | } else {
|
|---|
| 133 | ASSERT(0, "SamplingGrid::operator*=() - superposing incompatible grids is so far not in the cards.");
|
|---|
| 134 | }
|
|---|
| 135 | return *this;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
|
|---|
| 139 | {
|
|---|
| 140 | /// check that grids are compatible
|
|---|
| 141 | if (isCompatible(other)) {
|
|---|
| 142 | /// get maximum of window
|
|---|
| 143 | double max_begin_window[3];
|
|---|
| 144 | double max_end_window[3];
|
|---|
| 145 | bool doExtend = false;
|
|---|
| 146 | for (size_t index=0; index<3;++index) {
|
|---|
| 147 | if (begin_window[index] >= other.begin_window[index]) {
|
|---|
| 148 | max_begin_window[index] = other.begin_window[index];
|
|---|
| 149 | doExtend = true;
|
|---|
| 150 | } else {
|
|---|
| 151 | max_begin_window[index] = begin_window[index];
|
|---|
| 152 | }
|
|---|
| 153 | if (end_window[index] >= other.end_window[index]) {
|
|---|
| 154 | max_end_window[index] = end_window[index];
|
|---|
| 155 | } else {
|
|---|
| 156 | max_end_window[index] = other.end_window[index];
|
|---|
| 157 | doExtend = true;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | LOG(2, "DEBUG: max begin is " << max_begin_window[0] << "," << max_begin_window[1] << "," << max_begin_window[2] << ".");
|
|---|
| 161 | LOG(2, "DEBUG: max end is " << max_end_window[0] << "," << max_end_window[1] << "," << max_end_window[2] << ".");
|
|---|
| 162 | if (doExtend)
|
|---|
| 163 | extendWindow(max_begin_window, max_end_window);
|
|---|
| 164 | /// and copy other into larger window, too
|
|---|
| 165 | addOntoWindow(other.begin_window, other.end_window, other.sampled_grid, prefactor);
|
|---|
| 166 | } else {
|
|---|
| 167 | ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | const double SamplingGrid::getVolume() const
|
|---|
| 172 | {
|
|---|
| 173 | double volume = 1.;
|
|---|
| 174 | for (size_t i=0;i<3;++i)
|
|---|
| 175 | volume *= end[i]-begin[i];
|
|---|
| 176 | return volume;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | const double SamplingGrid::getWindowVolume() const
|
|---|
| 180 | {
|
|---|
| 181 | double volume = 1.;
|
|---|
| 182 | for (size_t i=0;i<3;++i)
|
|---|
| 183 | volume *= end_window[i]-begin_window[i];
|
|---|
| 184 | return volume;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | const size_t SamplingGrid::getTotalGridPoints() const
|
|---|
| 188 | {
|
|---|
| 189 | return pow(getGridPointsPerAxis(),3);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | const size_t SamplingGrid::getGridPointsPerAxis() const
|
|---|
| 193 | {
|
|---|
| 194 | return pow(2, level);
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | const size_t SamplingGrid::getWindowGridPoints() const
|
|---|
| 198 | {
|
|---|
| 199 | const double volume = getVolume();
|
|---|
| 200 | if (fabs(volume) < std::numeric_limits<double>::epsilon())
|
|---|
| 201 | return 0;
|
|---|
| 202 | else
|
|---|
| 203 | return (getWindowVolume()*getTotalGridPoints())/volume;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | double SamplingGrid::integral() const
|
|---|
| 207 | {
|
|---|
| 208 | const double volume_element = getVolume()/(double)getTotalGridPoints();
|
|---|
| 209 | double int_value = 0.;
|
|---|
| 210 | for (sampledvalues_t::const_iterator iter = sampled_grid.begin();
|
|---|
| 211 | iter != sampled_grid.end();
|
|---|
| 212 | ++iter)
|
|---|
| 213 | int_value += *iter;
|
|---|
| 214 | int_value *= volume_element;
|
|---|
| 215 | LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
|
|---|
| 216 | return int_value;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | double SamplingGrid::integral(const SamplingGrid &weight) const
|
|---|
| 220 | {
|
|---|
| 221 | if (isCompatible(weight)) {
|
|---|
| 222 | const double volume_element = getVolume()/(double)getTotalGridPoints();
|
|---|
| 223 | double int_value = 0.;
|
|---|
| 224 | sampledvalues_t::const_iterator iter = sampled_grid.begin();
|
|---|
| 225 | sampledvalues_t::const_iterator weightiter = weight.sampled_grid.begin();
|
|---|
| 226 | for (;iter != sampled_grid.end();++iter,++weightiter)
|
|---|
| 227 | int_value += (*weightiter) * (*iter);
|
|---|
| 228 | int_value *= volume_element;
|
|---|
| 229 | //LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
|
|---|
| 230 | return int_value;
|
|---|
| 231 | } else
|
|---|
| 232 | return 0.;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | double SamplingGrid::getNearestLowerGridPoint(
|
|---|
| 236 | const double value, const size_t axis) const
|
|---|
| 237 | {
|
|---|
| 238 | const double length = end[axis] - begin[axis];
|
|---|
| 239 | if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
|
|---|
| 240 | return 0.;
|
|---|
| 241 | } else {
|
|---|
| 242 | const double offset = value - begin[axis];
|
|---|
| 243 | const double factor = floor((double)getGridPointsPerAxis()*(offset/length));
|
|---|
| 244 | return factor*(length/(double)getGridPointsPerAxis());
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | double SamplingGrid::getNearestHigherGridPoint(
|
|---|
| 249 | const double value, const size_t axis) const
|
|---|
| 250 | {
|
|---|
| 251 | const double length = end[axis] - begin[axis];
|
|---|
| 252 | if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
|
|---|
| 253 | return 0.;
|
|---|
| 254 | } else {
|
|---|
| 255 | const double offset = value - begin[axis];
|
|---|
| 256 | const double factor = ceil((double)getGridPointsPerAxis()*(offset/length));
|
|---|
| 257 | return factor*(length/(double)getGridPointsPerAxis());
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | void SamplingGrid::setWindowSize(
|
|---|
| 262 | const double _begin_window[3],
|
|---|
| 263 | const double _end_window[3])
|
|---|
| 264 | {
|
|---|
| 265 | for (size_t index=0;index<3;++index) {
|
|---|
| 266 | begin_window[index] = getNearestLowerGridPoint(_begin_window[index], index);
|
|---|
| 267 | ASSERT( begin_window[index] >= begin[index],
|
|---|
| 268 | "SamplingGrid::setWindowSize() - window starts earlier than domain on "
|
|---|
| 269 | +toString(index)+"th component.");
|
|---|
| 270 | end_window[index] = getNearestHigherGridPoint(_end_window[index], index);
|
|---|
| 271 | ASSERT( end_window[index] <= end[index],
|
|---|
| 272 | "SamplingGrid::setWindowSize() - window ends later than domain on "
|
|---|
| 273 | +toString(index)+"th component.");
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | void SamplingGrid::setWindow(
|
|---|
| 278 | const double _begin_window[3],
|
|---|
| 279 | const double _end_window[3])
|
|---|
| 280 | {
|
|---|
| 281 | setWindowSize(_begin_window, _end_window);
|
|---|
| 282 | const size_t gridpoints_window = getWindowGridPoints();
|
|---|
| 283 | sampled_grid.clear();
|
|---|
| 284 | sampled_grid.resize(gridpoints_window, 0.);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | void SamplingGrid::setDomainSize(
|
|---|
| 288 | const double _begin[3],
|
|---|
| 289 | const double _end[3])
|
|---|
| 290 | {
|
|---|
| 291 | for (size_t index=0;index<3;++index) {
|
|---|
| 292 | begin[index] = _begin[index];
|
|---|
| 293 | end[index] = _end[index];
|
|---|
| 294 | }
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | void SamplingGrid::setDomain(
|
|---|
| 298 | const double _begin[3],
|
|---|
| 299 | const double _end[3])
|
|---|
| 300 | {
|
|---|
| 301 | setDomainSize(_begin, _end);
|
|---|
| 302 | setWindowSize(_begin, _end);
|
|---|
| 303 | const size_t gridpoints = getTotalGridPoints();
|
|---|
| 304 | sampled_grid.resize(gridpoints, 0.);
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | void SamplingGrid::extendWindow(
|
|---|
| 308 | const double _begin_window[3],
|
|---|
| 309 | const double _end_window[3])
|
|---|
| 310 | {
|
|---|
| 311 | #ifndef NDEBUG
|
|---|
| 312 | for(size_t index=0;index < 3; ++index) {
|
|---|
| 313 | // check that we truly have to extend the window
|
|---|
| 314 | ASSERT ( begin_window[index] >= _begin_window[index],
|
|---|
| 315 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
|---|
| 316 | " of window start is greater than old value.");
|
|---|
| 317 | ASSERT ( end_window[index] <= _end_window[index],
|
|---|
| 318 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
|---|
| 319 | " of window end is less than old value.");
|
|---|
| 320 |
|
|---|
| 321 | // check that we are still less than domain
|
|---|
| 322 | ASSERT ( _begin_window[index] >= begin[index],
|
|---|
| 323 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
|---|
| 324 | " of window start is less than domain start.");
|
|---|
| 325 | ASSERT ( _end_window[index] <= end[index],
|
|---|
| 326 | "SamplingGrid::extendWindow() - component "+toString(index)+
|
|---|
| 327 | " of window end is greater than domain end.");
|
|---|
| 328 | }
|
|---|
| 329 | #endif
|
|---|
| 330 | // copy old window size and values
|
|---|
| 331 | double old_begin_window[3];
|
|---|
| 332 | double old_end_window[3];
|
|---|
| 333 | for(size_t index=0;index<3;++index) {
|
|---|
| 334 | old_begin_window[index] = begin_window[index];
|
|---|
| 335 | old_end_window[index] = end_window[index];
|
|---|
| 336 | }
|
|---|
| 337 | sampledvalues_t old_values(sampled_grid);
|
|---|
| 338 | // set new window
|
|---|
| 339 | setWindow(_begin_window,_end_window);
|
|---|
| 340 | // now extend it ...
|
|---|
| 341 | addOntoWindow(old_begin_window, old_end_window, old_values, +1.);
|
|---|
| 342 | LOG(2, "DEBUG: Grid after extension is " << sampled_grid << ".");
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | void SamplingGrid::addOntoWindow(
|
|---|
| 346 | const double _begin_window[3],
|
|---|
| 347 | const double _end_window[3],
|
|---|
| 348 | const sampledvalues_t &_sampled_grid,
|
|---|
| 349 | const double prefactor)
|
|---|
| 350 | {
|
|---|
| 351 | #ifndef NDEBUG
|
|---|
| 352 | for(size_t index=0;index<3;++index) {
|
|---|
| 353 | ASSERT( _begin_window[index] >= begin_window[index],
|
|---|
| 354 | "SamplingGrid::addOntoWindow() - given window starts earlier in component "
|
|---|
| 355 | +toString(index)+".");
|
|---|
| 356 | ASSERT( _end_window[index] <= end_window[index],
|
|---|
| 357 | "SamplingGrid::addOntoWindow() - given window ends later in component "
|
|---|
| 358 | +toString(index)+".");
|
|---|
| 359 | }
|
|---|
| 360 | #endif
|
|---|
| 361 | // the only issue are indices
|
|---|
| 362 | const size_t gridpoints_axis = getGridPointsPerAxis();
|
|---|
| 363 | size_t pre_offset[3];
|
|---|
| 364 | size_t post_offset[3];
|
|---|
| 365 | size_t length[3];
|
|---|
| 366 | size_t total[3];
|
|---|
| 367 | const double round_offset =
|
|---|
| 368 | (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
|
|---|
| 369 | 0.5 : 0.; // need offset to get to round_toward_nearest behavior
|
|---|
| 370 | for(size_t index=0;index<3;++index) {
|
|---|
| 371 | // we refrain from using floor/ceil as the window's starts and ends,
|
|---|
| 372 | // the grids have to be compatible (equal level), should always be on
|
|---|
| 373 | // discrete grid point locations.
|
|---|
| 374 | const double delta = (double)gridpoints_axis/(end[index] - begin[index]);
|
|---|
| 375 | // delta is conversion factor from box length to discrete length, i.e. number of points
|
|---|
| 376 | pre_offset[index] = delta*(_begin_window[index] - begin_window[index])+round_offset;
|
|---|
| 377 | length[index] = delta*(_end_window[index] - _begin_window[index])+round_offset;
|
|---|
| 378 | post_offset[index] = delta*(end_window[index] - _end_window[index])+round_offset;
|
|---|
| 379 | total[index] = delta*(end_window[index] - begin_window[index])+round_offset;
|
|---|
| 380 | // total is used as safe-guard against loss due to discrete conversion
|
|---|
| 381 | ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
|
|---|
| 382 | "SamplingGrid::addOntoWindow() - pre, post, and length don't sum up to total for "
|
|---|
| 383 | +toString(index)+"th component.");
|
|---|
| 384 | }
|
|---|
| 385 | // assert that calculated lengths match with given vector sizes
|
|---|
| 386 | #ifndef NDEBUG
|
|---|
| 387 | const size_t calculated_size = length[0]*length[1]*length[2];
|
|---|
| 388 | ASSERT( calculated_size == _sampled_grid.size(),
|
|---|
| 389 | "SamplingGrid::addOntoWindow() - not enough sampled values given: "
|
|---|
| 390 | +toString(calculated_size)+" != "+toString(_sampled_grid.size())+".");
|
|---|
| 391 | ASSERT( calculated_size <= sampled_grid.size(),
|
|---|
| 392 | "SamplingGrid::addOntoWindow() - not enough sampled values available: "
|
|---|
| 393 | +toString(calculated_size)+" <= "+toString(sampled_grid.size())+".");
|
|---|
| 394 | const size_t total_size = total[0]*total[1]*total[2];
|
|---|
| 395 | ASSERT( total_size == sampled_grid.size(),
|
|---|
| 396 | "SamplingGrid::addOntoWindow() - total size is not equal to number of present points: "
|
|---|
| 397 | +toString(total_size)+" != "+toString(sampled_grid.size())+".");
|
|---|
| 398 | #endif
|
|---|
| 399 | size_t N[3];
|
|---|
| 400 | // size_t counter = 0;
|
|---|
| 401 | sampledvalues_t::iterator griditer = sampled_grid.begin();
|
|---|
| 402 | std::advance(griditer, pre_offset[0]*total[1]*total[2]);
|
|---|
| 403 | sampledvalues_t::const_iterator copyiter = _sampled_grid.begin();
|
|---|
| 404 | for(N[0]=0; N[0] < length[0]; ++N[0]) {
|
|---|
| 405 | std::advance(griditer, pre_offset[1]*total[2]);
|
|---|
| 406 | for(N[1]=0; N[1] < length[1]; ++N[1]) {
|
|---|
| 407 | std::advance(griditer, pre_offset[2]);
|
|---|
| 408 | for(N[2]=0; N[2] < length[2]; ++N[2]) {
|
|---|
| 409 | ASSERT( griditer != sampled_grid.end(),
|
|---|
| 410 | "SamplingGrid::addOntoWindow() - griditer is already at end of window.");
|
|---|
| 411 | ASSERT( copyiter != _sampled_grid.end(),
|
|---|
| 412 | "SamplingGrid::addOntoWindow() - griditer is already at end of window.");
|
|---|
| 413 | *griditer++ += prefactor*(*copyiter++);
|
|---|
| 414 | }
|
|---|
| 415 | std::advance(griditer, post_offset[2]);
|
|---|
| 416 | }
|
|---|
| 417 | std::advance(griditer, post_offset[1]*total[2]);
|
|---|
| 418 | }
|
|---|
| 419 | #ifndef NDEBUG
|
|---|
| 420 | std::advance(griditer, post_offset[0]*total[1]*total[2]);
|
|---|
| 421 | ASSERT( griditer == sampled_grid.end(),
|
|---|
| 422 | "SamplingGrid::addOntoWindow() - griditer is not at end of window.");
|
|---|
| 423 | ASSERT( copyiter == _sampled_grid.end(),
|
|---|
| 424 | "SamplingGrid::addOntoWindow() - copyiter is not at end of window.");
|
|---|
| 425 | #endif
|
|---|
| 426 | LOG(2, "DEBUG: Grid after adding other is " << sampled_grid << ".");
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
|
|---|
| 430 | {
|
|---|
| 431 | ost << "SamplingGrid";
|
|---|
| 432 | ost << " starting at " << other.begin[0] << "," << other.begin[1] << "," << other.begin[2];
|
|---|
| 433 | ost << " ending at " << other.end[0] << "," << other.end[1] << "," << other.end[2];
|
|---|
| 434 | ost << ", window starting at " << other.begin_window[0] << "," << other.begin_window[1] << "," << other.begin_window[2];
|
|---|
| 435 | ost << ", window ending at " << other.end_window[0] << "," << other.end_window[1] << "," << other.end_window[2];
|
|---|
| 436 | ost << ", level of " << other.level;
|
|---|
| 437 | ost << " and integrated value of " << other.integral();
|
|---|
| 438 | return ost;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | template<> SamplingGrid ZeroInstance<SamplingGrid>()
|
|---|
| 442 | {
|
|---|
| 443 | SamplingGrid returnvalue;
|
|---|
| 444 | return returnvalue;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | // we need to explicitly instantiate the serialization functions as
|
|---|
| 448 | // its is only serialized through its base class FragmentJob
|
|---|
| 449 | BOOST_CLASS_EXPORT_IMPLEMENT(SamplingGrid)
|
|---|