--- trunk/src/brains/DataStorage.cpp 2008/05/27 16:39:06 1245 +++ trunk/src/brains/DataStorage.cpp 2014/04/29 17:32:31 1993 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,20 +28,29 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** * @file DataStorage.cpp * @author tlin * @date 10/26/2004 - * @time 11:56am * @version 1.0 */ #include "brains/DataStorage.hpp" +using namespace std; +namespace OpenMD { -namespace oopse { - DataStorage::DataStorage() : size_(0), storageLayout_(0){ } @@ -64,47 +64,93 @@ namespace oopse { if (storageLayout_ & dslPosition && position.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } if (storageLayout_ & dslVelocity && velocity.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } + if (storageLayout_ & dslForce && force.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + if (storageLayout_ & dslAmat && aMat.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } if (storageLayout_ & dslAngularMomentum && angularMomentum.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } - if (storageLayout_ & dslElectroFrame && electroFrame.size() != size_) { + if (storageLayout_ & dslTorque && torque.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } - if (storageLayout_ & dslZAngle && zAngle.size() != size_) { + if (storageLayout_ & dslParticlePot && particlePot.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } - if (storageLayout_ & dslForce && force.size() != size_) { + if (storageLayout_ & dslDensity && density.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } - if (storageLayout_ & dslTorque && torque.size() != size_) { + if (storageLayout_ & dslFunctional && functional.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } - if (storageLayout_ & dslParticlePot && particlePot.size() != size_) { + + if (storageLayout_ & dslFunctionalDerivative && functionalDerivative.size() != size_) { //error - std::cerr << "size does not match"<< std::endl; + cerr << "size does not match"<< endl; } + + if (storageLayout_ & dslDipole && dipole.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslQuadrupole && quadrupole.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslElectricField && electricField.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslSkippedCharge && skippedCharge.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslFlucQPosition && flucQPos.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslFlucQVelocity && flucQVel.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslFlucQForce && flucQFrc.size() != size_) { + //error + cerr << "size does not match"<< endl; + } + + if (storageLayout_ & dslSitePotential && sitePotential.size() != size_) { + //error + cerr << "size does not match"<< endl; + } return size_; @@ -120,6 +166,10 @@ namespace oopse { internalResize(velocity, newSize); } + if (storageLayout_ & dslForce) { + internalResize(force, newSize); + } + if (storageLayout_ & dslAmat) { internalResize(aMat, newSize); } @@ -127,27 +177,59 @@ namespace oopse { if (storageLayout_ & dslAngularMomentum) { internalResize(angularMomentum, newSize); } + + if (storageLayout_ & dslTorque) { + internalResize(torque, newSize); + } - if (storageLayout_ & dslElectroFrame) { - internalResize(electroFrame, newSize); + if (storageLayout_ & dslParticlePot) { + internalResize(particlePot, newSize); } - - if (storageLayout_ & dslZAngle) { - internalResize(zAngle, newSize); + + if (storageLayout_ & dslDensity) { + internalResize(density, newSize); } - if (storageLayout_ & dslForce) { - internalResize(force, newSize); + if (storageLayout_ & dslFunctional) { + internalResize(functional, newSize); } - if (storageLayout_ & dslTorque) { - internalResize(torque, newSize); + if (storageLayout_ & dslFunctionalDerivative) { + internalResize(functionalDerivative, newSize); } - if (storageLayout_ & dslParticlePot) { - internalResize(particlePot, newSize); + if (storageLayout_ & dslDipole) { + internalResize(dipole, newSize); } + if (storageLayout_ & dslQuadrupole) { + internalResize(quadrupole, newSize); + } + + if (storageLayout_ & dslElectricField) { + internalResize(electricField, newSize); + } + + if (storageLayout_ & dslSkippedCharge) { + internalResize(skippedCharge, newSize); + } + + if (storageLayout_ & dslFlucQPosition) { + internalResize(flucQPos, newSize); + } + + if (storageLayout_ & dslFlucQVelocity) { + internalResize(flucQVel, newSize); + } + + if (storageLayout_ & dslFlucQForce) { + internalResize(flucQFrc, newSize); + } + + if (storageLayout_ & dslSitePotential) { + internalResize(sitePotential, newSize); + } + size_ = newSize; } @@ -160,6 +242,10 @@ namespace oopse { velocity.reserve(size); } + if (storageLayout_ & dslForce) { + force.reserve(size); + } + if (storageLayout_ & dslAmat) { aMat.reserve(size); } @@ -168,18 +254,6 @@ namespace oopse { angularMomentum.reserve(size); } - if (storageLayout_ & dslElectroFrame) { - electroFrame.reserve(size); - } - - if (storageLayout_ & dslZAngle) { - zAngle.reserve(size); - } - - if (storageLayout_ & dslForce) { - force.reserve(size); - } - if (storageLayout_ & dslTorque) { torque.reserve(size); } @@ -188,6 +262,49 @@ namespace oopse { particlePot.reserve(size); } + if (storageLayout_ & dslDensity) { + density.reserve(size); + } + + if (storageLayout_ & dslFunctional) { + functional.reserve(size); + } + + if (storageLayout_ & dslFunctionalDerivative) { + functionalDerivative.reserve(size); + } + + if (storageLayout_ & dslDipole) { + dipole.reserve(size); + } + + if (storageLayout_ & dslQuadrupole) { + quadrupole.reserve(size); + } + + if (storageLayout_ & dslElectricField) { + electricField.reserve(size); + } + + if (storageLayout_ & dslSkippedCharge) { + skippedCharge.reserve(size); + } + + if (storageLayout_ & dslFlucQPosition) { + flucQPos.reserve(size); + } + + if (storageLayout_ & dslFlucQVelocity) { + flucQVel.reserve(size); + } + + if (storageLayout_ & dslFlucQForce) { + flucQFrc.reserve(size); + } + + if (storageLayout_ & dslSitePotential) { + sitePotential.reserve(size); + } } void DataStorage::copy(int source, int num, int target) { @@ -203,6 +320,10 @@ namespace oopse { internalCopy(velocity, source, num, target); } + if (storageLayout_ & dslForce) { + internalCopy(force, source, num, target); + } + if (storageLayout_ & dslAmat) { internalCopy(aMat, source, num, target); } @@ -211,18 +332,6 @@ namespace oopse { internalCopy(angularMomentum, source, num, target); } - if (storageLayout_ & dslElectroFrame) { - internalCopy(electroFrame, source, num, target); - } - - if (storageLayout_ & dslZAngle) { - internalCopy(zAngle, source, num, target); - } - - if (storageLayout_ & dslForce) { - internalCopy(force, source, num, target); - } - if (storageLayout_ & dslTorque) { internalCopy(torque, source, num, target); } @@ -230,8 +339,49 @@ namespace oopse { if (storageLayout_ & dslParticlePot) { internalCopy(particlePot, source, num, target); } - + if (storageLayout_ & dslDensity) { + internalCopy(density, source, num, target); + } + + if (storageLayout_ & dslFunctional) { + internalCopy(functional, source, num, target); + } + + if (storageLayout_ & dslFunctionalDerivative) { + internalCopy(functionalDerivative, source, num, target); + } + + if (storageLayout_ & dslDipole) { + internalCopy(dipole, source, num, target); + } + + if (storageLayout_ & dslQuadrupole) { + internalCopy(quadrupole, source, num, target); + } + + if (storageLayout_ & dslElectricField) { + internalCopy(electricField, source, num, target); + } + + if (storageLayout_ & dslSkippedCharge) { + internalCopy(skippedCharge, source, num, target); + } + + if (storageLayout_ & dslFlucQPosition) { + internalCopy(flucQPos, source, num, target); + } + + if (storageLayout_ & dslFlucQVelocity) { + internalCopy(flucQVel, source, num, target); + } + if (storageLayout_ & dslFlucQForce) { + internalCopy(flucQFrc, source, num, target); + } + + if (storageLayout_ & dslSitePotential) { + internalCopy(sitePotential, source, num, target); + } } int DataStorage::getStorageLayout() { @@ -248,57 +398,74 @@ namespace oopse { switch (whichArray) { case dslPosition: return internalGetArrayPointer(position); - break; case dslVelocity: return internalGetArrayPointer(velocity); - break; + case dslForce: + return internalGetArrayPointer(force); + case dslAmat: return internalGetArrayPointer(aMat); - break; case dslAngularMomentum: return internalGetArrayPointer(angularMomentum); - break; - case dslElectroFrame: - return internalGetArrayPointer(electroFrame); - break; - - case dslZAngle: - return internalGetArrayPointer(zAngle); - break; - - case dslForce: - return internalGetArrayPointer(force); - break; - case dslTorque: return internalGetArrayPointer(torque); - break; case dslParticlePot: return internalGetArrayPointer(particlePot); - break; - + + case dslDensity: + return internalGetArrayPointer(density); + + case dslFunctional: + return internalGetArrayPointer(functional); + + case dslFunctionalDerivative: + return internalGetArrayPointer(functionalDerivative); + + case dslDipole: + return internalGetArrayPointer(dipole); + + case dslQuadrupole: + return internalGetArrayPointer(quadrupole); + + case dslElectricField: + return internalGetArrayPointer(electricField); + + case dslSkippedCharge: + return internalGetArrayPointer(skippedCharge); + + case dslFlucQPosition: + return internalGetArrayPointer(flucQPos); + + case dslFlucQVelocity: + return internalGetArrayPointer(flucQVel); + + case dslFlucQForce: + return internalGetArrayPointer(flucQFrc); + + case dslSitePotential: + return internalGetArrayPointer(sitePotential); + default: //error message return NULL; - } } RealType* DataStorage::internalGetArrayPointer(std::vector& v) { - if (v.size() == 0) { + if (v.empty()) { return NULL; } else { return v[0].getArrayPointer(); } } - RealType* DataStorage::internalGetArrayPointer(std::vector& v) { - if (v.size() == 0) { + RealType* DataStorage::internalGetArrayPointer(std::vector& v) { + if (v.empty()) { return NULL; } else { return v[0].getArrayPointer(); @@ -307,7 +474,7 @@ namespace oopse { } RealType* DataStorage::internalGetArrayPointer(std::vector& v) { - if (v.size() == 0) { + if (v.empty()) { return NULL; } else { return &(v[0]); @@ -357,27 +524,55 @@ namespace oopse { if (layout & dslVelocity) { bytes += sizeof(Vector3d); } + if (layout & dslForce) { + bytes += sizeof(Vector3d); + } if (layout & dslAmat) { bytes += sizeof(RotMat3x3d); } if (layout & dslAngularMomentum) { bytes += sizeof(Vector3d); } - if (layout & dslElectroFrame) { - bytes += sizeof(Mat3x3d); + if (layout & dslTorque) { + bytes += sizeof(Vector3d); } - if (layout & dslZAngle) { + if (layout & dslParticlePot) { bytes += sizeof(RealType); } - if (layout & dslForce) { + if (layout & dslDensity) { + bytes += sizeof(RealType); + } + if (layout & dslFunctional) { + bytes += sizeof(RealType); + } + if (layout & dslFunctionalDerivative) { + bytes += sizeof(RealType); + } + if (layout & dslDipole) { bytes += sizeof(Vector3d); } - if (layout & dslTorque) { + if (layout & dslQuadrupole) { + bytes += sizeof(Mat3x3d); + } + if (layout & dslElectricField) { bytes += sizeof(Vector3d); } - if (layout & dslParticlePot) { + if (layout & dslSkippedCharge) { bytes += sizeof(RealType); } + if (layout & dslFlucQPosition) { + bytes += sizeof(RealType); + } + if (layout & dslFlucQVelocity) { + bytes += sizeof(RealType); + } + if (layout & dslFlucQForce) { + bytes += sizeof(RealType); + } + if (layout & dslSitePotential) { + bytes += sizeof(RealType); + } + return bytes; }