| 35 | 
  | 
 *                                                                       | 
| 36 | 
  | 
 * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).              | 
| 37 | 
  | 
 * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).           | 
| 38 | 
< | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).           | 
| 38 | 
> | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).           | 
| 39 | 
  | 
 * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
  | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 44 | 
  | 
 * @file DataStorage.cpp | 
| 45 | 
  | 
 * @author tlin | 
| 46 | 
  | 
 * @date 10/26/2004 | 
| 47 | 
– | 
 * @time 11:56am | 
| 47 | 
  | 
 * @version 1.0 | 
| 48 | 
  | 
 */ | 
| 49 | 
  | 
 | 
| 55 | 
  | 
 | 
| 56 | 
  | 
  } | 
| 57 | 
  | 
 | 
| 58 | 
< | 
  DataStorage::DataStorage(int size, int storageLayout) : size_(size){ | 
| 58 | 
> | 
  DataStorage::DataStorage(std::size_t size, int storageLayout) : size_(size){ | 
| 59 | 
  | 
    setStorageLayout(storageLayout); | 
| 60 | 
  | 
    resize(size); | 
| 61 | 
  | 
  } | 
| 62 | 
  | 
 | 
| 63 | 
< | 
  int DataStorage::getSize() { | 
| 63 | 
> | 
  std::size_t DataStorage::getSize() { | 
| 64 | 
  | 
 | 
| 65 | 
  | 
    if (storageLayout_ & dslPosition && position.size() != size_) { | 
| 66 | 
  | 
      //error | 
| 72 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 73 | 
  | 
    } | 
| 74 | 
  | 
 | 
| 75 | 
+ | 
    if (storageLayout_ & dslForce && force.size() != size_) { | 
| 76 | 
+ | 
      //error | 
| 77 | 
+ | 
      cerr << "size does not match"<< endl;         | 
| 78 | 
+ | 
    } | 
| 79 | 
+ | 
 | 
| 80 | 
  | 
    if (storageLayout_ & dslAmat && aMat.size() != size_) { | 
| 81 | 
  | 
      //error | 
| 82 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 87 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 88 | 
  | 
    } | 
| 89 | 
  | 
 | 
| 90 | 
< | 
    if (storageLayout_ & dslElectroFrame && electroFrame.size() != size_) { | 
| 90 | 
> | 
    if (storageLayout_ & dslTorque && torque.size() != size_) { | 
| 91 | 
  | 
      //error | 
| 92 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 93 | 
  | 
    } | 
| 94 | 
  | 
 | 
| 95 | 
< | 
    if (storageLayout_ & dslForce && force.size() != size_) { | 
| 95 | 
> | 
    if (storageLayout_ & dslParticlePot && particlePot.size() != size_) { | 
| 96 | 
  | 
      //error | 
| 97 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 98 | 
  | 
    } | 
| 99 | 
  | 
 | 
| 100 | 
< | 
    if (storageLayout_ & dslTorque && torque.size() != size_) { | 
| 100 | 
> | 
    if (storageLayout_ & dslDensity && density.size() != size_) { | 
| 101 | 
  | 
      //error | 
| 102 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 103 | 
  | 
    } | 
| 104 | 
  | 
 | 
| 105 | 
< | 
    if (storageLayout_ & dslParticlePot && particlePot.size() != size_) { | 
| 105 | 
> | 
    if (storageLayout_ & dslFunctional && functional.size() != size_) { | 
| 106 | 
  | 
      //error | 
| 107 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 108 | 
  | 
    } | 
| 109 | 
  | 
 | 
| 110 | 
< | 
    if (storageLayout_ & dslDensity && density.size() != size_) { | 
| 110 | 
> | 
    if (storageLayout_ & dslFunctionalDerivative && functionalDerivative.size() != size_) { | 
| 111 | 
  | 
      //error | 
| 112 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 113 | 
  | 
    } | 
| 114 | 
  | 
 | 
| 115 | 
< | 
    if (storageLayout_ & dslFunctional && functional.size() != size_) { | 
| 115 | 
> | 
    if (storageLayout_ & dslDipole && dipole.size() != size_) { | 
| 116 | 
  | 
      //error | 
| 117 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 118 | 
  | 
    } | 
| 119 | 
  | 
 | 
| 120 | 
< | 
    if (storageLayout_ & dslFunctionalDerivative && functionalDerivative.size() != size_) { | 
| 120 | 
> | 
    if (storageLayout_ & dslQuadrupole && quadrupole.size() != size_) { | 
| 121 | 
  | 
      //error | 
| 122 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 123 | 
  | 
    } | 
| 146 | 
  | 
      //error | 
| 147 | 
  | 
      cerr << "size does not match"<< endl;         | 
| 148 | 
  | 
    } | 
| 149 | 
+ | 
 | 
| 150 | 
+ | 
    if (storageLayout_ & dslSitePotential && sitePotential.size() != size_) { | 
| 151 | 
+ | 
      //error | 
| 152 | 
+ | 
      cerr << "size does not match"<< endl;         | 
| 153 | 
+ | 
    } | 
| 154 | 
  | 
     | 
| 155 | 
  | 
    return size_; | 
| 156 | 
  | 
 | 
| 157 | 
  | 
  } | 
| 158 | 
  | 
 | 
| 159 | 
< | 
  void DataStorage::resize(int newSize) { | 
| 159 | 
> | 
  void DataStorage::resize(std::size_t newSize) { | 
| 160 | 
  | 
 | 
| 161 | 
  | 
    if (storageLayout_ & dslPosition) { | 
| 162 | 
  | 
      internalResize(position, newSize); | 
| 166 | 
  | 
      internalResize(velocity, newSize); | 
| 167 | 
  | 
    } | 
| 168 | 
  | 
 | 
| 169 | 
+ | 
    if (storageLayout_ & dslForce) { | 
| 170 | 
+ | 
      internalResize(force, newSize); | 
| 171 | 
+ | 
    } | 
| 172 | 
+ | 
 | 
| 173 | 
  | 
    if (storageLayout_ & dslAmat) { | 
| 174 | 
  | 
      internalResize(aMat, newSize); | 
| 175 | 
  | 
    } | 
| 177 | 
  | 
    if (storageLayout_ & dslAngularMomentum) { | 
| 178 | 
  | 
      internalResize(angularMomentum, newSize); | 
| 179 | 
  | 
    } | 
| 167 | 
– | 
 | 
| 168 | 
– | 
    if (storageLayout_ & dslElectroFrame) { | 
| 169 | 
– | 
      internalResize(electroFrame, newSize); | 
| 170 | 
– | 
    } | 
| 180 | 
  | 
     | 
| 172 | 
– | 
    if (storageLayout_ & dslForce) { | 
| 173 | 
– | 
      internalResize(force, newSize); | 
| 174 | 
– | 
    } | 
| 175 | 
– | 
 | 
| 181 | 
  | 
    if (storageLayout_ & dslTorque) { | 
| 182 | 
  | 
      internalResize(torque, newSize); | 
| 183 | 
  | 
    } | 
| 198 | 
  | 
      internalResize(functionalDerivative, newSize); | 
| 199 | 
  | 
    } | 
| 200 | 
  | 
 | 
| 201 | 
+ | 
    if (storageLayout_ & dslDipole) { | 
| 202 | 
+ | 
      internalResize(dipole, newSize); | 
| 203 | 
+ | 
    } | 
| 204 | 
+ | 
 | 
| 205 | 
+ | 
    if (storageLayout_ & dslQuadrupole) { | 
| 206 | 
+ | 
      internalResize(quadrupole, newSize); | 
| 207 | 
+ | 
    } | 
| 208 | 
+ | 
 | 
| 209 | 
  | 
    if (storageLayout_ & dslElectricField) { | 
| 210 | 
  | 
      internalResize(electricField, newSize); | 
| 211 | 
  | 
    } | 
| 226 | 
  | 
      internalResize(flucQFrc, newSize); | 
| 227 | 
  | 
    } | 
| 228 | 
  | 
 | 
| 229 | 
+ | 
    if (storageLayout_ & dslSitePotential) { | 
| 230 | 
+ | 
      internalResize(sitePotential, newSize); | 
| 231 | 
+ | 
    } | 
| 232 | 
+ | 
 | 
| 233 | 
  | 
    size_ = newSize; | 
| 234 | 
  | 
  } | 
| 235 | 
  | 
 | 
| 236 | 
< | 
  void DataStorage::reserve(int size) { | 
| 236 | 
> | 
  void DataStorage::reserve(std::size_t size) { | 
| 237 | 
  | 
    if (storageLayout_ & dslPosition) { | 
| 238 | 
  | 
      position.reserve(size); | 
| 239 | 
  | 
    }  | 
| 242 | 
  | 
      velocity.reserve(size); | 
| 243 | 
  | 
    }  | 
| 244 | 
  | 
 | 
| 245 | 
+ | 
    if (storageLayout_ & dslForce) { | 
| 246 | 
+ | 
      force.reserve(size); | 
| 247 | 
+ | 
    }  | 
| 248 | 
+ | 
 | 
| 249 | 
  | 
    if (storageLayout_ & dslAmat) { | 
| 250 | 
  | 
      aMat.reserve(size); | 
| 251 | 
  | 
    }  | 
| 254 | 
  | 
      angularMomentum.reserve(size); | 
| 255 | 
  | 
    }  | 
| 256 | 
  | 
 | 
| 236 | 
– | 
    if (storageLayout_ & dslElectroFrame) { | 
| 237 | 
– | 
      electroFrame.reserve(size); | 
| 238 | 
– | 
    } | 
| 239 | 
– | 
     | 
| 240 | 
– | 
    if (storageLayout_ & dslForce) { | 
| 241 | 
– | 
      force.reserve(size); | 
| 242 | 
– | 
    }  | 
| 243 | 
– | 
 | 
| 257 | 
  | 
    if (storageLayout_ & dslTorque) { | 
| 258 | 
  | 
      torque.reserve(size); | 
| 259 | 
  | 
    } | 
| 274 | 
  | 
      functionalDerivative.reserve(size); | 
| 275 | 
  | 
    } | 
| 276 | 
  | 
 | 
| 277 | 
+ | 
    if (storageLayout_ & dslDipole) { | 
| 278 | 
+ | 
      dipole.reserve(size); | 
| 279 | 
+ | 
    } | 
| 280 | 
+ | 
 | 
| 281 | 
+ | 
    if (storageLayout_ & dslQuadrupole) { | 
| 282 | 
+ | 
      quadrupole.reserve(size); | 
| 283 | 
+ | 
    } | 
| 284 | 
+ | 
 | 
| 285 | 
  | 
    if (storageLayout_ & dslElectricField) { | 
| 286 | 
  | 
      electricField.reserve(size); | 
| 287 | 
  | 
    } | 
| 301 | 
  | 
    if (storageLayout_ & dslFlucQForce) { | 
| 302 | 
  | 
      flucQFrc.reserve(size); | 
| 303 | 
  | 
    } | 
| 304 | 
+ | 
 | 
| 305 | 
+ | 
    if (storageLayout_ & dslSitePotential) { | 
| 306 | 
+ | 
      sitePotential.reserve(size); | 
| 307 | 
+ | 
    } | 
| 308 | 
  | 
  } | 
| 309 | 
  | 
 | 
| 310 | 
< | 
  void DataStorage::copy(int source, int num, int target) { | 
| 310 | 
> | 
  void DataStorage::copy(int source, std::size_t num, std::size_t target) { | 
| 311 | 
  | 
    if (num + target > size_ ) { | 
| 312 | 
  | 
      //error | 
| 313 | 
  | 
    } | 
| 320 | 
  | 
      internalCopy(velocity, source, num, target); | 
| 321 | 
  | 
    }  | 
| 322 | 
  | 
 | 
| 323 | 
+ | 
    if (storageLayout_ & dslForce) { | 
| 324 | 
+ | 
      internalCopy(force, source, num, target); | 
| 325 | 
+ | 
    }  | 
| 326 | 
+ | 
 | 
| 327 | 
  | 
    if (storageLayout_ & dslAmat) { | 
| 328 | 
  | 
      internalCopy(aMat, source, num, target); | 
| 329 | 
  | 
    }  | 
| 332 | 
  | 
      internalCopy(angularMomentum, source, num, target); | 
| 333 | 
  | 
    }  | 
| 334 | 
  | 
 | 
| 306 | 
– | 
    if (storageLayout_ & dslElectroFrame) { | 
| 307 | 
– | 
      internalCopy(electroFrame, source, num, target); | 
| 308 | 
– | 
    } | 
| 309 | 
– | 
     | 
| 310 | 
– | 
    if (storageLayout_ & dslForce) { | 
| 311 | 
– | 
      internalCopy(force, source, num, target); | 
| 312 | 
– | 
    }  | 
| 313 | 
– | 
 | 
| 335 | 
  | 
    if (storageLayout_ & dslTorque) { | 
| 336 | 
  | 
      internalCopy(torque, source, num, target);  | 
| 337 | 
  | 
    } | 
| 352 | 
  | 
      internalCopy(functionalDerivative, source, num, target); | 
| 353 | 
  | 
    } | 
| 354 | 
  | 
 | 
| 355 | 
+ | 
    if (storageLayout_ & dslDipole) { | 
| 356 | 
+ | 
      internalCopy(dipole, source, num, target); | 
| 357 | 
+ | 
    } | 
| 358 | 
+ | 
 | 
| 359 | 
+ | 
    if (storageLayout_ & dslQuadrupole) { | 
| 360 | 
+ | 
      internalCopy(quadrupole, source, num, target); | 
| 361 | 
+ | 
    } | 
| 362 | 
+ | 
 | 
| 363 | 
  | 
    if (storageLayout_ & dslElectricField) { | 
| 364 | 
  | 
      internalCopy(electricField, source, num, target); | 
| 365 | 
  | 
    } | 
| 378 | 
  | 
    if (storageLayout_ & dslFlucQForce) { | 
| 379 | 
  | 
      internalCopy(flucQFrc, source, num, target); | 
| 380 | 
  | 
    } | 
| 381 | 
+ | 
 | 
| 382 | 
+ | 
    if (storageLayout_ & dslSitePotential) { | 
| 383 | 
+ | 
      internalCopy(sitePotential, source, num, target); | 
| 384 | 
+ | 
    } | 
| 385 | 
  | 
  } | 
| 386 | 
  | 
 | 
| 387 | 
  | 
  int DataStorage::getStorageLayout() { | 
| 402 | 
  | 
    case dslVelocity: | 
| 403 | 
  | 
      return internalGetArrayPointer(velocity); | 
| 404 | 
  | 
             | 
| 405 | 
+ | 
    case dslForce: | 
| 406 | 
+ | 
      return internalGetArrayPointer(force); | 
| 407 | 
+ | 
 | 
| 408 | 
  | 
    case dslAmat: | 
| 409 | 
  | 
      return internalGetArrayPointer(aMat); | 
| 410 | 
  | 
             | 
| 411 | 
  | 
    case dslAngularMomentum: | 
| 412 | 
  | 
      return internalGetArrayPointer(angularMomentum); | 
| 413 | 
  | 
             | 
| 378 | 
– | 
    case dslElectroFrame: | 
| 379 | 
– | 
      return internalGetArrayPointer(electroFrame); | 
| 380 | 
– | 
             | 
| 381 | 
– | 
    case dslForce: | 
| 382 | 
– | 
      return internalGetArrayPointer(force); | 
| 383 | 
– | 
 | 
| 414 | 
  | 
    case dslTorque: | 
| 415 | 
  | 
      return internalGetArrayPointer(torque); | 
| 416 | 
  | 
 | 
| 425 | 
  | 
 | 
| 426 | 
  | 
    case dslFunctionalDerivative: | 
| 427 | 
  | 
      return internalGetArrayPointer(functionalDerivative); | 
| 428 | 
+ | 
 | 
| 429 | 
+ | 
    case dslDipole: | 
| 430 | 
+ | 
      return internalGetArrayPointer(dipole); | 
| 431 | 
+ | 
 | 
| 432 | 
+ | 
    case dslQuadrupole: | 
| 433 | 
+ | 
      return internalGetArrayPointer(quadrupole); | 
| 434 | 
  | 
 | 
| 435 | 
  | 
    case dslElectricField: | 
| 436 | 
  | 
      return internalGetArrayPointer(electricField); | 
| 447 | 
  | 
    case dslFlucQForce: | 
| 448 | 
  | 
      return internalGetArrayPointer(flucQFrc); | 
| 449 | 
  | 
            | 
| 450 | 
+ | 
    case dslSitePotential: | 
| 451 | 
+ | 
      return internalGetArrayPointer(sitePotential); | 
| 452 | 
+ | 
            | 
| 453 | 
  | 
    default: | 
| 454 | 
  | 
      //error message | 
| 455 | 
  | 
      return NULL; | 
| 417 | 
– | 
 | 
| 456 | 
  | 
    } | 
| 457 | 
  | 
  }     | 
| 458 | 
  | 
 | 
| 459 | 
  | 
  RealType* DataStorage::internalGetArrayPointer(std::vector<Vector3d>& v) { | 
| 460 | 
< | 
    if (v.size() == 0) { | 
| 460 | 
> | 
    if (v.empty()) { | 
| 461 | 
  | 
      return NULL; | 
| 462 | 
  | 
    } else { | 
| 463 | 
  | 
      return v[0].getArrayPointer(); | 
| 464 | 
  | 
    } | 
| 465 | 
  | 
  } | 
| 466 | 
  | 
 | 
| 467 | 
< | 
  RealType* DataStorage::internalGetArrayPointer(std::vector<RotMat3x3d>& v) { | 
| 468 | 
< | 
    if (v.size() == 0) { | 
| 467 | 
> | 
  RealType* DataStorage::internalGetArrayPointer(std::vector<Mat3x3d>& v) { | 
| 468 | 
> | 
    if (v.empty()) { | 
| 469 | 
  | 
      return NULL; | 
| 470 | 
  | 
    } else { | 
| 471 | 
  | 
      return v[0].getArrayPointer(); | 
| 474 | 
  | 
  } | 
| 475 | 
  | 
 | 
| 476 | 
  | 
  RealType* DataStorage::internalGetArrayPointer(std::vector<RealType>& v) { | 
| 477 | 
< | 
    if (v.size() == 0) { | 
| 477 | 
> | 
    if (v.empty()) { | 
| 478 | 
  | 
      return NULL; | 
| 479 | 
  | 
    } else { | 
| 480 | 
  | 
      return &(v[0]); | 
| 483 | 
  | 
  }     | 
| 484 | 
  | 
 | 
| 485 | 
  | 
  template<typename T> | 
| 486 | 
< | 
  void DataStorage::internalResize(std::vector<T>& v, int newSize){ | 
| 487 | 
< | 
    int oldSize = v.size(); | 
| 486 | 
> | 
  void DataStorage::internalResize(std::vector<T>& v, std::size_t newSize){ | 
| 487 | 
> | 
    std::size_t oldSize = v.size(); | 
| 488 | 
  | 
 | 
| 489 | 
  | 
    if (oldSize == newSize) { | 
| 490 | 
  | 
      return; | 
| 499 | 
  | 
  } | 
| 500 | 
  | 
 | 
| 501 | 
  | 
  template<typename T> | 
| 502 | 
< | 
  void DataStorage::internalCopy(std::vector<T>& v, int source,  int num, int target) { | 
| 502 | 
> | 
  void DataStorage::internalCopy(std::vector<T>& v, int source, | 
| 503 | 
> | 
                                 std::size_t num, std::size_t target) { | 
| 504 | 
  | 
    typename std::vector<T>::iterator first; | 
| 505 | 
  | 
    typename std::vector<T>::iterator last; | 
| 506 | 
  | 
    typename std::vector<T>::iterator result; | 
| 517 | 
  | 
    std::copy(first, last, result); | 
| 518 | 
  | 
  } | 
| 519 | 
  | 
 | 
| 520 | 
< | 
  int DataStorage::getBytesPerStuntDouble(int layout) { | 
| 521 | 
< | 
    int bytes = 0; | 
| 520 | 
> | 
  std::size_t DataStorage::getBytesPerStuntDouble(int layout) { | 
| 521 | 
> | 
    std::size_t  bytes = 0; | 
| 522 | 
  | 
    if (layout & dslPosition) { | 
| 523 | 
  | 
      bytes += sizeof(Vector3d); | 
| 524 | 
  | 
    } | 
| 525 | 
  | 
    if (layout & dslVelocity) { | 
| 526 | 
  | 
      bytes += sizeof(Vector3d); | 
| 527 | 
  | 
    } | 
| 528 | 
+ | 
    if (layout & dslForce) { | 
| 529 | 
+ | 
      bytes += sizeof(Vector3d); | 
| 530 | 
+ | 
    } | 
| 531 | 
  | 
    if (layout & dslAmat) { | 
| 532 | 
  | 
      bytes += sizeof(RotMat3x3d);     | 
| 533 | 
  | 
    } | 
| 534 | 
  | 
    if (layout & dslAngularMomentum) { | 
| 535 | 
  | 
      bytes += sizeof(Vector3d); | 
| 536 | 
  | 
    } | 
| 495 | 
– | 
    if (layout & dslElectroFrame) { | 
| 496 | 
– | 
      bytes += sizeof(Mat3x3d); | 
| 497 | 
– | 
    } | 
| 498 | 
– | 
    if (layout & dslForce) { | 
| 499 | 
– | 
      bytes += sizeof(Vector3d); | 
| 500 | 
– | 
    } | 
| 537 | 
  | 
    if (layout & dslTorque) { | 
| 538 | 
  | 
      bytes += sizeof(Vector3d); | 
| 539 | 
  | 
    } | 
| 549 | 
  | 
    if (layout & dslFunctionalDerivative) { | 
| 550 | 
  | 
      bytes += sizeof(RealType); | 
| 551 | 
  | 
    } | 
| 552 | 
+ | 
    if (layout & dslDipole) { | 
| 553 | 
+ | 
      bytes += sizeof(Vector3d); | 
| 554 | 
+ | 
    } | 
| 555 | 
+ | 
    if (layout & dslQuadrupole) { | 
| 556 | 
+ | 
      bytes += sizeof(Mat3x3d); | 
| 557 | 
+ | 
    } | 
| 558 | 
  | 
    if (layout & dslElectricField) { | 
| 559 | 
  | 
      bytes += sizeof(Vector3d); | 
| 560 | 
  | 
    } | 
| 570 | 
  | 
    if (layout & dslFlucQForce) { | 
| 571 | 
  | 
      bytes += sizeof(RealType); | 
| 572 | 
  | 
    } | 
| 573 | 
+ | 
    if (layout & dslSitePotential) { | 
| 574 | 
+ | 
      bytes += sizeof(RealType); | 
| 575 | 
+ | 
    } | 
| 576 | 
  | 
 | 
| 577 | 
  | 
    return bytes; | 
| 578 | 
  | 
  } |