| 30 |
|
* @time 23:56am |
| 31 |
|
* @version 1.0 |
| 32 |
|
*/ |
| 33 |
+ |
|
| 34 |
|
#ifndef BRAINS_SNAPSHOT_HPP |
| 35 |
|
#define BRAINS_SNAPSHOT_HPP |
| 36 |
|
|
| 43 |
|
|
| 44 |
|
namespace oopse{ |
| 45 |
|
|
| 46 |
+ |
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 |
+ |
//forward declaration |
| 57 |
+ |
class Snapshot; |
| 58 |
+ |
class SnapshotManager; |
| 59 |
+ |
class StuntDouble; |
| 60 |
+ |
|
| 61 |
|
/** |
| 62 |
+ |
* @class DataStorage |
| 63 |
+ |
* @brief |
| 64 |
+ |
* @warning do not try to insert element into (or ease element from) private member data |
| 65 |
+ |
* of DataStorage directly. |
| 66 |
+ |
*/ |
| 67 |
+ |
class DataStorage { |
| 68 |
+ |
public: |
| 69 |
+ |
DataStorage() {}; |
| 70 |
+ |
DataStorage(size_t size); |
| 71 |
+ |
|
| 72 |
+ |
int size(); |
| 73 |
+ |
void resize(size_t size); |
| 74 |
+ |
void reserve(size_t size); |
| 75 |
+ |
|
| 76 |
+ |
friend class Snapshot; |
| 77 |
+ |
friend class StuntDouble; |
| 78 |
+ |
private: |
| 79 |
+ |
vector<Vector3d> position; /** position array */ |
| 80 |
+ |
vector<Vector3d> velocity; /** velocity array */ |
| 81 |
+ |
vector<RotMat3x3d> aMat; /** rotation matrix array */ |
| 82 |
+ |
vector<Vector3d> angularMomentum;/** velocity array */ |
| 83 |
+ |
vector<Vector3d> unitVector; /** the lab frame unit vector array*/ |
| 84 |
+ |
vector<double> zAngle; /** z -angle array */ |
| 85 |
+ |
vector<Vector3d> force; /** force array */ |
| 86 |
+ |
vector<Vector3d> torque; /** torque array */ |
| 87 |
+ |
|
| 88 |
+ |
}; |
| 89 |
+ |
|
| 90 |
+ |
/** |
| 91 |
|
* @class Snapshot Snapshot.hpp "brains/Snapshot.hpp" |
| 92 |
|
* @brief Snapshot class is a repository class for storing dynamic data during |
| 93 |
|
* Simulation |
| 94 |
+ |
* Every snapshot class will contain one DataStorage for atoms and one DataStorage |
| 95 |
+ |
* for rigid bodies. |
| 96 |
|
* @see SimData |
| 97 |
|
*/ |
| 98 |
|
class Snapshot { |
| 99 |
|
public: |
| 100 |
< |
|
| 101 |
< |
Snapshot(int i) { |
| 102 |
< |
|
| 100 |
> |
|
| 101 |
> |
Snapshot(int nAtoms, int nRigidbodies) { |
| 102 |
> |
atomData.resize(nAtoms); |
| 103 |
> |
rigidbodyData.resize(nRigidbodies); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
Snapshot(const Snapshot& s); |
| 117 |
|
id_ = id; |
| 118 |
|
} |
| 119 |
|
|
| 72 |
– |
/** */ |
| 73 |
– |
Snapshot* clone() { |
| 74 |
– |
return new Snapshot(*this); |
| 75 |
– |
} |
| 76 |
– |
|
| 77 |
– |
|
| 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 |
+ |
assert(v.size() > 0); |
| 127 |
|
return v[0].getArrayPointer(); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
static double* getArrayPointer(vector<RotMat3x3d>& v) { |
| 131 |
+ |
assert(v.size() > 0); |
| 132 |
|
return v[0].getArrayPointer(); |
| 133 |
|
} |
| 134 |
|
|
| 136 |
|
assert(v.size() > 0); |
| 137 |
|
return &(v[0]); |
| 138 |
|
} |
| 139 |
+ |
|
| 140 |
+ |
int getSize() { |
| 141 |
+ |
return atomData.size() + rigidbodyData.size(); |
| 142 |
+ |
} |
| 143 |
|
|
| 144 |
< |
vector<Vector3d> pos; |
| 145 |
< |
vector<Vector3d> vel; |
| 146 |
< |
vector<Vector3d> frc; |
| 99 |
< |
vector<Vector3d> trq; |
| 100 |
< |
vector<RotMat3x3d> Amat; |
| 101 |
< |
vector<Vector3d> mu; |
| 102 |
< |
vector<Vector3d> ul; |
| 103 |
< |
vector<double> zAngle; |
| 144 |
> |
int getSizeOfAtoms() { |
| 145 |
> |
return atomData.size(); |
| 146 |
> |
} |
| 147 |
|
|
| 148 |
+ |
int getSizeOfRigidBodies() { |
| 149 |
+ |
return rigidbodyData.size(); |
| 150 |
+ |
} |
| 151 |
+ |
|
| 152 |
+ |
DataStorage atomData; |
| 153 |
+ |
DataStorage rigidbodyData; |
| 154 |
+ |
|
| 155 |
+ |
friend class StuntDouble; |
| 156 |
|
private: |
| 157 |
|
|
| 158 |
|
int id_; /**< identification number of the snapshot */ |
| 159 |
|
}; |
| 160 |
|
|
| 161 |
+ |
typedef DataStorage (Snapshot::*DataStoragePointer); |
| 162 |
|
} |
| 163 |
|
#endif //BRAINS_SNAPSHOT_HPP |