1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
/** |
27 |
* @file Snapshot.hpp |
28 |
* @author tlin |
29 |
* @date 10/20/2004 |
30 |
* @time 23:56am |
31 |
* @version 1.0 |
32 |
*/ |
33 |
|
34 |
#ifndef BRAINS_SNAPSHOT_HPP |
35 |
#define BRAINS_SNAPSHOT_HPP |
36 |
|
37 |
#include <vector> |
38 |
|
39 |
#include "math/Vector3.hpp" |
40 |
#include "math/SquareMatrix3.hpp" |
41 |
|
42 |
using namespace std; |
43 |
|
44 |
namespace oopse{ |
45 |
|
46 |
|
47 |
//forward declaration |
48 |
class Snapshot; |
49 |
class SnapshotManager; |
50 |
class StuntDouble; |
51 |
|
52 |
/** |
53 |
* @class DataStorage |
54 |
* @warning do not try to insert element into (or ease element from) private member data |
55 |
* of DataStorage directly. |
56 |
*/ |
57 |
class DataStorage { |
58 |
public: |
59 |
|
60 |
enum{ |
61 |
slPosition = 1, |
62 |
slVelocity = 2, |
63 |
slAmat = 4, |
64 |
slAngularMomentum = 8, |
65 |
slUnitVector = 16, |
66 |
slZAngle = 32, |
67 |
slForce = 64, |
68 |
slTorque = 128 |
69 |
}; |
70 |
|
71 |
DataStorage(int size); |
72 |
|
73 |
/** return the size of this DataStorage */ |
74 |
int size(); |
75 |
void resize(int size); |
76 |
void reserve(int size); |
77 |
|
78 |
void move(int source, int num, int target); |
79 |
int getStorageLayout(); |
80 |
void setStorageLayout(int layout); |
81 |
|
82 |
double *getArrayPointer(int ); |
83 |
|
84 |
friend class StuntDouble; |
85 |
|
86 |
private: |
87 |
int size_; |
88 |
int storageLayout_; |
89 |
vector<Vector3d> position; /** position array */ |
90 |
vector<Vector3d> velocity; /** velocity array */ |
91 |
vector<RotMat3x3d> aMat; /** rotation matrix array */ |
92 |
vector<Vector3d> angularMomentum;/** velocity array */ |
93 |
vector<Vector3d> unitVector; /** the lab frame unit vector array*/ |
94 |
vector<double> zAngle; /** z -angle array */ |
95 |
vector<Vector3d> force; /** force array */ |
96 |
vector<Vector3d> torque; /** torque array */ |
97 |
}; |
98 |
|
99 |
/** |
100 |
* @class Snapshot Snapshot.hpp "brains/Snapshot.hpp" |
101 |
* @brief Snapshot class is a repository class for storing dynamic data during |
102 |
* Simulation |
103 |
* Every snapshot class will contain one DataStorage for atoms and one DataStorage |
104 |
* for rigid bodies. |
105 |
* @see SimData |
106 |
*/ |
107 |
class Snapshot { |
108 |
public: |
109 |
|
110 |
Snapshot(int nAtoms, int nRigidbodies) { |
111 |
atomData.resize(nAtoms); |
112 |
rigidbodyData.resize(nRigidbodies); |
113 |
} |
114 |
|
115 |
Snapshot(const Snapshot& s); |
116 |
|
117 |
Snapshot& operator =(const Snapshot& s); |
118 |
|
119 |
/** Returns the id of this Snapshot */ |
120 |
int getID() { |
121 |
return id_; |
122 |
} |
123 |
|
124 |
/** Sets the id of this Snapshot */ |
125 |
void setID(int id) { |
126 |
id_ = id; |
127 |
} |
128 |
|
129 |
//template<typename T> |
130 |
//static typename T::ElemPointerType getArrayPointer(vector<T>& v) { |
131 |
// return v[0]->getArrayPointer(); |
132 |
//} |
133 |
|
134 |
int getSize() { |
135 |
return atomData.size() + rigidbodyData.size(); |
136 |
} |
137 |
|
138 |
/** Returns the number of atoms */ |
139 |
int getNumberOfAtoms() { |
140 |
return atomData.size(); |
141 |
} |
142 |
|
143 |
/** Returns the number of rigid bodies */ |
144 |
int getNumberOfRigidBodies() { |
145 |
return rigidbodyData.size(); |
146 |
} |
147 |
|
148 |
/** Returns the H-Matrix */ |
149 |
Mat3x3d getHmat() { |
150 |
return hmat_; |
151 |
} |
152 |
|
153 |
/** Sets the H-Matrix */ |
154 |
void setHamt(const Mat3x3d& m) { |
155 |
hmat_ = m; |
156 |
invHmat_ = hmat_.inverse(); |
157 |
} |
158 |
|
159 |
/** Returns the inverse H-Matrix */ |
160 |
Mat3x3d getInvHmat() { |
161 |
return invHmat_ |
162 |
} |
163 |
|
164 |
double getTimeStamp() { |
165 |
return timeStamp_; |
166 |
} |
167 |
|
168 |
void setTimeStamp(double timeStamp) { |
169 |
timeStamp_ =timeStamp; |
170 |
} |
171 |
|
172 |
|
173 |
DataStorage atomData; |
174 |
DataStorage rigidbodyData; |
175 |
|
176 |
friend class StuntDouble; |
177 |
|
178 |
private: |
179 |
double timeStamp_; |
180 |
Mat3x3d hmat_; |
181 |
Mat3x3d invHmat_; |
182 |
int id_; /**< identification number of the snapshot */ |
183 |
}; |
184 |
|
185 |
typedef DataStorage (Snapshot::*DataStoragePointer); |
186 |
} |
187 |
#endif //BRAINS_SNAPSHOT_HPP |