55#include "brains/DataStorage.hpp"
59 DataStorage::DataStorage() : size_(0), storageLayout_(0) {}
61 DataStorage::DataStorage(std::size_t size,
int storageLayout) : size_(size) {
62 setStorageLayout(storageLayout);
67 if (storageLayout_ & dslPosition && position.size() != size_) {
69 cerr <<
"size does not match" << endl;
72 if (storageLayout_ & dslVelocity &&
velocity.size() != size_) {
74 cerr <<
"size does not match" << endl;
77 if (storageLayout_ & dslForce &&
force.size() != size_) {
79 cerr <<
"size does not match" << endl;
82 if (storageLayout_ & dslAmat &&
aMat.size() != size_) {
84 cerr <<
"size does not match" << endl;
87 if (storageLayout_ & dslAngularMomentum &&
90 cerr <<
"size does not match" << endl;
93 if (storageLayout_ & dslTorque &&
torque.size() != size_) {
95 cerr <<
"size does not match" << endl;
98 if (storageLayout_ & dslParticlePot &&
particlePot.size() != size_) {
100 cerr <<
"size does not match" << endl;
103 if (storageLayout_ & dslDensity &&
density.size() != size_) {
105 cerr <<
"size does not match" << endl;
108 if (storageLayout_ & dslFunctional &&
functional.size() != size_) {
110 cerr <<
"size does not match" << endl;
113 if (storageLayout_ & dslFunctionalDerivative &&
116 cerr <<
"size does not match" << endl;
119 if (storageLayout_ & dslDipole &&
dipole.size() != size_) {
121 cerr <<
"size does not match" << endl;
124 if (storageLayout_ & dslQuadrupole &&
quadrupole.size() != size_) {
126 cerr <<
"size does not match" << endl;
129 if (storageLayout_ & dslElectricField &&
electricField.size() != size_) {
131 cerr <<
"size does not match" << endl;
134 if (storageLayout_ & dslSkippedCharge &&
skippedCharge.size() != size_) {
136 cerr <<
"size does not match" << endl;
139 if (storageLayout_ & dslFlucQPosition &&
flucQPos.size() != size_) {
141 cerr <<
"size does not match" << endl;
144 if (storageLayout_ & dslFlucQVelocity &&
flucQVel.size() != size_) {
146 cerr <<
"size does not match" << endl;
149 if (storageLayout_ & dslFlucQForce &&
flucQFrc.size() != size_) {
151 cerr <<
"size does not match" << endl;
154 if (storageLayout_ & dslSitePotential &&
sitePotential.size() != size_) {
156 cerr <<
"size does not match" << endl;
163 if (storageLayout_ & dslPosition) { internalResize(position, newSize); }
165 if (storageLayout_ & dslVelocity) { internalResize(
velocity, newSize); }
167 if (storageLayout_ & dslForce) { internalResize(
force, newSize); }
169 if (storageLayout_ & dslAmat) { internalResize(
aMat, newSize); }
171 if (storageLayout_ & dslAngularMomentum) {
175 if (storageLayout_ & dslTorque) { internalResize(
torque, newSize); }
177 if (storageLayout_ & dslParticlePot) {
181 if (storageLayout_ & dslDensity) { internalResize(
density, newSize); }
183 if (storageLayout_ & dslFunctional) { internalResize(
functional, newSize); }
185 if (storageLayout_ & dslFunctionalDerivative) {
189 if (storageLayout_ & dslDipole) { internalResize(
dipole, newSize); }
191 if (storageLayout_ & dslQuadrupole) { internalResize(
quadrupole, newSize); }
193 if (storageLayout_ & dslElectricField) {
197 if (storageLayout_ & dslSkippedCharge) {
201 if (storageLayout_ & dslFlucQPosition) {
205 if (storageLayout_ & dslFlucQVelocity) {
209 if (storageLayout_ & dslFlucQForce) { internalResize(
flucQFrc, newSize); }
211 if (storageLayout_ & dslSitePotential) {
219 if (storageLayout_ & dslPosition) { position.reserve(size); }
221 if (storageLayout_ & dslVelocity) {
velocity.reserve(size); }
223 if (storageLayout_ & dslForce) {
force.reserve(size); }
225 if (storageLayout_ & dslAmat) {
aMat.reserve(size); }
227 if (storageLayout_ & dslAngularMomentum) {
angularMomentum.reserve(size); }
229 if (storageLayout_ & dslTorque) {
torque.reserve(size); }
231 if (storageLayout_ & dslParticlePot) {
particlePot.reserve(size); }
233 if (storageLayout_ & dslDensity) {
density.reserve(size); }
235 if (storageLayout_ & dslFunctional) {
functional.reserve(size); }
237 if (storageLayout_ & dslFunctionalDerivative) {
241 if (storageLayout_ & dslDipole) {
dipole.reserve(size); }
243 if (storageLayout_ & dslQuadrupole) {
quadrupole.reserve(size); }
245 if (storageLayout_ & dslElectricField) {
electricField.reserve(size); }
247 if (storageLayout_ & dslSkippedCharge) {
skippedCharge.reserve(size); }
249 if (storageLayout_ & dslFlucQPosition) {
flucQPos.reserve(size); }
251 if (storageLayout_ & dslFlucQVelocity) {
flucQVel.reserve(size); }
253 if (storageLayout_ & dslFlucQForce) {
flucQFrc.reserve(size); }
255 if (storageLayout_ & dslSitePotential) {
sitePotential.reserve(size); }
259 if (num + target > size_) {
263 if (storageLayout_ & dslPosition) {
264 internalCopy(position, source, num, target);
267 if (storageLayout_ & dslVelocity) {
268 internalCopy(
velocity, source, num, target);
271 if (storageLayout_ & dslForce) { internalCopy(
force, source, num, target); }
273 if (storageLayout_ & dslAmat) { internalCopy(
aMat, source, num, target); }
275 if (storageLayout_ & dslAngularMomentum) {
279 if (storageLayout_ & dslTorque) {
280 internalCopy(
torque, source, num, target);
283 if (storageLayout_ & dslParticlePot) {
287 if (storageLayout_ & dslDensity) {
288 internalCopy(
density, source, num, target);
291 if (storageLayout_ & dslFunctional) {
292 internalCopy(
functional, source, num, target);
295 if (storageLayout_ & dslFunctionalDerivative) {
299 if (storageLayout_ & dslDipole) {
300 internalCopy(
dipole, source, num, target);
303 if (storageLayout_ & dslQuadrupole) {
304 internalCopy(
quadrupole, source, num, target);
307 if (storageLayout_ & dslElectricField) {
311 if (storageLayout_ & dslSkippedCharge) {
315 if (storageLayout_ & dslFlucQPosition) {
316 internalCopy(
flucQPos, source, num, target);
319 if (storageLayout_ & dslFlucQVelocity) {
320 internalCopy(
flucQVel, source, num, target);
322 if (storageLayout_ & dslFlucQForce) {
323 internalCopy(
flucQFrc, source, num, target);
326 if (storageLayout_ & dslSitePotential) {
334 storageLayout_ = layout;
339 switch (whichArray) {
341 return internalGetArrayPointer(position);
344 return internalGetArrayPointer(
velocity);
347 return internalGetArrayPointer(
force);
350 return internalGetArrayPointer(
aMat);
352 case dslAngularMomentum:
356 return internalGetArrayPointer(
torque);
362 return internalGetArrayPointer(
density);
367 case dslFunctionalDerivative:
371 return internalGetArrayPointer(
dipole);
376 case dslElectricField:
379 case dslSkippedCharge:
382 case dslFlucQPosition:
383 return internalGetArrayPointer(
flucQPos);
385 case dslFlucQVelocity:
386 return internalGetArrayPointer(
flucQVel);
389 return internalGetArrayPointer(
flucQFrc);
391 case dslSitePotential:
400 RealType* DataStorage::internalGetArrayPointer(std::vector<Vector3d>& v) {
404 return v[0].getArrayPointer();
408 RealType* DataStorage::internalGetArrayPointer(std::vector<Mat3x3d>& v) {
412 return v[0].getArrayPointer();
416 RealType* DataStorage::internalGetArrayPointer(std::vector<RealType>& v) {
425 void DataStorage::internalResize(std::vector<T>& v, std::size_t newSize) {
426 std::size_t oldSize = v.size();
428 if (oldSize == newSize) {
430 }
else if (oldSize < newSize) {
431 v.insert(v.end(), newSize - oldSize, T());
433 typename std::vector<T>::iterator i;
435 std::advance(i, newSize);
441 void DataStorage::internalCopy(std::vector<T>& v,
int source, std::size_t num,
442 std::size_t target) {
443 typename std::vector<T>::iterator first;
444 typename std::vector<T>::iterator last;
445 typename std::vector<T>::iterator result;
451 std::advance(first, source);
453 std::advance(last, num + 1);
454 std::advance(result, target);
456 std::copy(first, last, result);
460 std::size_t bytes = 0;
461 if (layout & dslPosition) { bytes +=
sizeof(Vector3d); }
462 if (layout & dslVelocity) { bytes +=
sizeof(Vector3d); }
463 if (layout & dslForce) { bytes +=
sizeof(Vector3d); }
464 if (layout & dslAmat) { bytes +=
sizeof(RotMat3x3d); }
465 if (layout & dslAngularMomentum) { bytes +=
sizeof(Vector3d); }
466 if (layout & dslTorque) { bytes +=
sizeof(Vector3d); }
467 if (layout & dslParticlePot) { bytes +=
sizeof(RealType); }
468 if (layout & dslDensity) { bytes +=
sizeof(RealType); }
469 if (layout & dslFunctional) { bytes +=
sizeof(RealType); }
470 if (layout & dslFunctionalDerivative) { bytes +=
sizeof(RealType); }
471 if (layout & dslDipole) { bytes +=
sizeof(Vector3d); }
472 if (layout & dslQuadrupole) { bytes +=
sizeof(Mat3x3d); }
473 if (layout & dslElectricField) { bytes +=
sizeof(Vector3d); }
474 if (layout & dslSkippedCharge) { bytes +=
sizeof(RealType); }
475 if (layout & dslFlucQPosition) { bytes +=
sizeof(RealType); }
476 if (layout & dslFlucQVelocity) { bytes +=
sizeof(RealType); }
477 if (layout & dslFlucQForce) { bytes +=
sizeof(RealType); }
478 if (layout & dslSitePotential) { bytes +=
sizeof(RealType); }
void copy(int source, std::size_t num, std::size_t target)
Copies data inside DataStorage class.
vector< RealType > functional
electron density
int getStorageLayout()
Returns the storage layout.
void resize(std::size_t newSize)
Changes the size of this DataStorage.
vector< RealType > flucQFrc
fluctuating charge velocities
vector< RealType > particlePot
torque array
vector< RealType > sitePotential
fluctuating charge forces
vector< Mat3x3d > quadrupole
space-frame dipole vector
vector< RealType > functionalDerivative
density functional
vector< RealType > flucQPos
charge skipped during normal pairwise calculation
vector< Vector3d > velocity
position array
vector< RotMat3x3d > aMat
force array
vector< RealType > density
particle potential arrray
vector< RealType > skippedCharge
local electric field
void setStorageLayout(int layout)
Sets the storage layout.
std::size_t getSize()
return the size of this DataStorage.
static std::size_t getBytesPerStuntDouble(int layout)
electrostatic site potentials
vector< RealType > flucQVel
fluctuating charges
vector< Vector3d > torque
angular momentum array (body-fixed)
vector< Vector3d > force
velocity array
vector< Vector3d > electricField
space-frame quadrupole tensor
void reserve(std::size_t size)
Reallocates memory manually.
vector< Vector3d > dipole
derivative of functional
vector< Vector3d > angularMomentum
rotation matrix array
RealType * getArrayPointer(int whichArray)
Returns the pointer of internal array.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.