1 |
tim |
122 |
/* |
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 |
tim |
146 |
|
34 |
tim |
122 |
#ifndef BRAINS_SNAPSHOT_HPP |
35 |
|
|
#define BRAINS_SNAPSHOT_HPP |
36 |
tim |
137 |
|
37 |
|
|
#include <vector> |
38 |
|
|
|
39 |
|
|
#include "math/Vector3.hpp" |
40 |
|
|
#include "math/SquareMatrix3.hpp" |
41 |
|
|
|
42 |
|
|
using namespace std; |
43 |
|
|
|
44 |
tim |
122 |
namespace oopse{ |
45 |
|
|
|
46 |
tim |
149 |
enum DataStorageLayout { |
47 |
|
|
dslPosition = 1, |
48 |
|
|
dslVelocity = 2, |
49 |
|
|
dslAMat = 4, |
50 |
|
|
dslAngularMomentum = 8, |
51 |
|
|
dslUnitVector = 16, |
52 |
|
|
dslZAngle = 32, |
53 |
|
|
dslForce = 64, |
54 |
|
|
dslTorque = 128 |
55 |
|
|
}; |
56 |
tim |
146 |
//forward declaration |
57 |
|
|
class Snapshot; |
58 |
|
|
class SnapshotManager; |
59 |
tim |
149 |
class StuntDouble; |
60 |
|
|
|
61 |
tim |
122 |
/** |
62 |
tim |
149 |
* @class DataStorage |
63 |
tim |
146 |
* @brief |
64 |
tim |
149 |
* @warning do not try to insert element into (or ease element from) private member data |
65 |
|
|
* of DataStorage directly. |
66 |
tim |
146 |
*/ |
67 |
|
|
class DataStorage { |
68 |
|
|
public: |
69 |
|
|
DataStorage() {}; |
70 |
|
|
DataStorage(size_t size); |
71 |
tim |
149 |
|
72 |
|
|
int size(); |
73 |
tim |
146 |
void resize(size_t size); |
74 |
|
|
void reserve(size_t size); |
75 |
|
|
|
76 |
tim |
149 |
friend class Snapshot; |
77 |
|
|
friend class StuntDouble; |
78 |
|
|
private: |
79 |
tim |
146 |
vector<Vector3d> position; /** position array */ |
80 |
|
|
vector<Vector3d> velocity; /** velocity array */ |
81 |
tim |
149 |
vector<RotMat3x3d> aMat; /** rotation matrix array */ |
82 |
tim |
146 |
vector<Vector3d> angularMomentum;/** velocity array */ |
83 |
tim |
149 |
vector<Vector3d> unitVector; /** the lab frame unit vector array*/ |
84 |
tim |
146 |
vector<double> zAngle; /** z -angle array */ |
85 |
|
|
vector<Vector3d> force; /** force array */ |
86 |
|
|
vector<Vector3d> torque; /** torque array */ |
87 |
|
|
|
88 |
|
|
}; |
89 |
|
|
|
90 |
|
|
/** |
91 |
tim |
122 |
* @class Snapshot Snapshot.hpp "brains/Snapshot.hpp" |
92 |
|
|
* @brief Snapshot class is a repository class for storing dynamic data during |
93 |
|
|
* Simulation |
94 |
tim |
146 |
* Every snapshot class will contain one DataStorage for atoms and one DataStorage |
95 |
|
|
* for rigid bodies. |
96 |
tim |
122 |
* @see SimData |
97 |
|
|
*/ |
98 |
|
|
class Snapshot { |
99 |
|
|
public: |
100 |
tim |
146 |
|
101 |
tim |
149 |
Snapshot(int nAtoms, int nRigidbodies) { |
102 |
|
|
atomData.resize(nAtoms); |
103 |
|
|
rigidbodyData.resize(nRigidbodies); |
104 |
tim |
137 |
} |
105 |
|
|
|
106 |
|
|
Snapshot(const Snapshot& s); |
107 |
|
|
|
108 |
|
|
Snapshot& operator =(const Snapshot& s); |
109 |
tim |
122 |
|
110 |
tim |
137 |
/** Returns the id of this Snapshot */ |
111 |
|
|
int getID() { |
112 |
|
|
return id_; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/** Sets the id of this Snapshot */ |
116 |
|
|
void setID(int id) { |
117 |
|
|
id_ = id; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
//template<typename T> |
121 |
|
|
//static typename T::ElemPointerType getArrayPointer(vector<T>& v) { |
122 |
|
|
// return v[0]->getArrayPointer(); |
123 |
|
|
//} |
124 |
|
|
|
125 |
|
|
static double* getArrayPointer(vector<Vector3d>& v) { |
126 |
tim |
146 |
assert(v.size() > 0); |
127 |
tim |
137 |
return v[0].getArrayPointer(); |
128 |
|
|
} |
129 |
tim |
122 |
|
130 |
tim |
137 |
static double* getArrayPointer(vector<RotMat3x3d>& v) { |
131 |
tim |
146 |
assert(v.size() > 0); |
132 |
tim |
137 |
return v[0].getArrayPointer(); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
static double* getArrayPointer(vector<double>& v) { |
136 |
|
|
assert(v.size() > 0); |
137 |
|
|
return &(v[0]); |
138 |
|
|
} |
139 |
tim |
149 |
|
140 |
|
|
int getSize() { |
141 |
|
|
return atomData.size() + rigidbodyData.size(); |
142 |
|
|
} |
143 |
tim |
137 |
|
144 |
tim |
149 |
int getSizeOfAtoms() { |
145 |
|
|
return atomData.size(); |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
int getSizeOfRigidBodies() { |
149 |
|
|
return rigidbodyData.size(); |
150 |
|
|
} |
151 |
|
|
|
152 |
tim |
146 |
DataStorage atomData; |
153 |
|
|
DataStorage rigidbodyData; |
154 |
|
|
|
155 |
tim |
149 |
friend class StuntDouble; |
156 |
tim |
122 |
private: |
157 |
tim |
137 |
|
158 |
|
|
int id_; /**< identification number of the snapshot */ |
159 |
tim |
122 |
}; |
160 |
|
|
|
161 |
tim |
149 |
typedef DataStorage (Snapshot::*DataStoragePointer); |
162 |
tim |
122 |
} |
163 |
|
|
#endif //BRAINS_SNAPSHOT_HPP |