OpenMD 3.1
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 appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45/**
46 * @file Vector.hpp
47 * @author Teng Lin
48 * @date 09/14/2004
49 * @version 1.0
50 */
51
52#ifndef BRAINS_DATASTORAGE_HPP
53#define BRAINS_DATASTORAGE_HPP
54
55#include <vector>
56
58#include <math/Vector3.hpp>
59
60using namespace std;
61namespace OpenMD {
62 /**
63 * @class DataStorage
64 * @warning do not try to insert element into (or ease element from) private
65 * member data of DataStorage directly.
66 * @todo DataStorage may need refactoring. Every vector can inherit from the
67 * same base class which will make it easy to maintain
68 */
70 public:
71 enum {
72 dslPosition = 1,
73 dslVelocity = 2,
74 dslForce = 4,
75 dslAmat = 8,
76 dslAngularMomentum = 16,
77 dslTorque = 32,
78 dslParticlePot = 64,
79 dslDensity = 128,
80 dslFunctional = 256,
81 dslFunctionalDerivative = 512,
82 dslDipole = 1024,
83 dslQuadrupole = 2048,
84 dslElectricField = 4096,
85 dslSkippedCharge = 8192,
86 dslFlucQPosition = 16384,
87 dslFlucQVelocity = 32768,
88 dslFlucQForce = 65536,
89 dslSitePotential = 131072
90 };
91
93 DataStorage(std::size_t size, int storageLayout = 0);
94 /** return the size of this DataStorage. */
95 std::size_t getSize();
96 /**
97 * Changes the size of this DataStorage.
98 * @param newSize new size of this DataStorage
99 */
100 void resize(std::size_t newSize);
101 /**
102 * Reallocates memory manually.
103 *
104 * The main reason for using reserve() is efficiency if you know
105 * the capacity to which your vector must eventually grow,
106 * then it is usually more efficient to allocate that memory all
107 * at once.
108 */
109 void reserve(std::size_t size);
110 /**
111 * Copies data inside DataStorage class.
112 *
113 * Copy function actually calls copy for every vector in
114 * DataStorage class. One Precondition of copy is that
115 * target is not within the range [source, soruce + num]
116 *
117 * @param source
118 * @param num number of element to be moved
119 * @param target
120 */
121 void copy(int source, std::size_t num, std::size_t target);
122 /** Returns the storage layout */
123 int getStorageLayout();
124 /** Sets the storage layout */
125 void setStorageLayout(int layout);
126 /** Returns the pointer of internal array */
127 RealType* getArrayPointer(int whichArray);
128
129 vector<Vector3d> position; /** position array */
130 vector<Vector3d> velocity; /** velocity array */
131 vector<Vector3d> force; /** force array */
132 vector<RotMat3x3d> aMat; /** rotation matrix array */
133 vector<Vector3d> angularMomentum; /** angular momentum array (body-fixed) */
134 vector<Vector3d> torque; /** torque array */
135 vector<RealType> particlePot; /** particle potential arrray */
136 vector<RealType> density; /** electron density */
137 vector<RealType> functional; /** density functional */
138 vector<RealType> functionalDerivative; /** derivative of functional */
139 vector<Vector3d> dipole; /** space-frame dipole vector */
140 vector<Mat3x3d> quadrupole; /** space-frame quadrupole tensor */
141 vector<Vector3d> electricField; /** local electric field */
142 vector<RealType>
143 skippedCharge; /** charge skipped during normal pairwise calculation */
144 vector<RealType> flucQPos; /** fluctuating charges */
145 vector<RealType> flucQVel; /** fluctuating charge velocities */
146 vector<RealType> flucQFrc; /** fluctuating charge forces */
147 vector<RealType> sitePotential; /** electrostatic site potentials */
148
149 static std::size_t getBytesPerStuntDouble(int layout);
150
151 private:
152 RealType* internalGetArrayPointer(vector<Vector3d>& v);
153 RealType* internalGetArrayPointer(vector<Mat3x3d>& v);
154 RealType* internalGetArrayPointer(vector<RealType>& v);
155
156 template<typename T>
157 void internalResize(std::vector<T>& v, std::size_t newSize);
158
159 template<typename T>
160 void internalCopy(std::vector<T>& v, int source, std::size_t num,
161 std::size_t target);
162
163 std::size_t size_;
164 int storageLayout_;
165 };
166} // namespace OpenMD
167
168#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.