OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
DataStorage.hpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48/**
49 * @file Vector.hpp
50 * @author Teng Lin
51 * @date 09/14/2004
52 * @version 1.0
53 */
54
55#ifndef BRAINS_DATASTORAGE_HPP
56#define BRAINS_DATASTORAGE_HPP
57
58#include <vector>
59
61#include <math/Vector3.hpp>
62
63using namespace std;
64namespace OpenMD {
65 /**
66 * @class DataStorage
67 * @warning do not try to insert element into (or ease element from) private
68 * member data of DataStorage directly.
69 * @todo DataStorage may need refactoring. Every vector can inherit from the
70 * same base class which will make it easy to maintain
71 */
72 class DataStorage {
73 public:
74 enum {
75 dslPosition = 1,
76 dslVelocity = 2,
77 dslForce = 4,
78 dslAmat = 8,
79 dslAngularMomentum = 16,
80 dslTorque = 32,
81 dslParticlePot = 64,
82 dslDensity = 128,
83 dslFunctional = 256,
84 dslFunctionalDerivative = 512,
85 dslDipole = 1024,
86 dslQuadrupole = 2048,
87 dslElectricField = 4096,
88 dslSkippedCharge = 8192,
89 dslFlucQPosition = 16384,
90 dslFlucQVelocity = 32768,
91 dslFlucQForce = 65536,
92 dslSitePotential = 131072
93 };
94
95 DataStorage();
96 DataStorage(std::size_t size, int storageLayout = 0);
97 /** return the size of this DataStorage. */
98 std::size_t getSize();
99 /**
100 * Changes the size of this DataStorage.
101 * @param newSize new size of this DataStorage
102 */
103 void resize(std::size_t newSize);
104 /**
105 * Reallocates memory manually.
106 *
107 * The main reason for using reserve() is efficiency if you know
108 * the capacity to which your vector must eventually grow,
109 * then it is usually more efficient to allocate that memory all
110 * at once.
111 */
112 void reserve(std::size_t size);
113 /**
114 * Copies data inside DataStorage class.
115 *
116 * Copy function actually calls copy for every vector in
117 * DataStorage class. One Precondition of copy is that
118 * target is not within the range [source, soruce + num]
119 *
120 * @param source
121 * @param num number of element to be moved
122 * @param target
123 */
124 void copy(int source, std::size_t num, std::size_t target);
125 /** Returns the storage layout */
126 int getStorageLayout();
127 /** Sets the storage layout */
128 void setStorageLayout(int layout);
129 /** Returns the pointer of internal array */
130 RealType* getArrayPointer(int whichArray);
131
132 vector<Vector3d> position; /** position array */
133 vector<Vector3d> velocity; /** velocity array */
134 vector<Vector3d> force; /** force array */
135 vector<RotMat3x3d> aMat; /** rotation matrix array */
136 vector<Vector3d> angularMomentum; /** angular momentum array (body-fixed) */
137 vector<Vector3d> torque; /** torque array */
138 vector<RealType> particlePot; /** particle potential arrray */
139 vector<RealType> density; /** electron density */
140 vector<RealType> functional; /** density functional */
141 vector<RealType> functionalDerivative; /** derivative of functional */
142 vector<Vector3d> dipole; /** space-frame dipole vector */
143 vector<Mat3x3d> quadrupole; /** space-frame quadrupole tensor */
144 vector<Vector3d> electricField; /** local electric field */
145 vector<RealType>
146 skippedCharge; /** charge skipped during normal pairwise calculation */
147 vector<RealType> flucQPos; /** fluctuating charges */
148 vector<RealType> flucQVel; /** fluctuating charge velocities */
149 vector<RealType> flucQFrc; /** fluctuating charge forces */
150 vector<RealType> sitePotential; /** electrostatic site potentials */
151
152 static std::size_t getBytesPerStuntDouble(int layout);
153
154 private:
155 RealType* internalGetArrayPointer(vector<Vector3d>& v);
156 RealType* internalGetArrayPointer(vector<Mat3x3d>& v);
157 RealType* internalGetArrayPointer(vector<RealType>& v);
158
159 template<typename T>
160 void internalResize(std::vector<T>& v, std::size_t newSize);
161
162 template<typename T>
163 void internalCopy(std::vector<T>& v, int source, std::size_t num,
164 std::size_t target);
165
166 std::size_t size_;
167 int storageLayout_;
168 };
169} // namespace OpenMD
170
171#endif // BRAINS_DATASTORAGE_HPP
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.