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 Vector.hpp |
28 |
* @author Teng Lin |
29 |
* @date 09/14/2004 |
30 |
* @version 1.0 |
31 |
*/ |
32 |
|
33 |
#ifndef BRAINS_DATASTORAGE_HPP |
34 |
#define BRAINS_DATASTORAGE_HPP |
35 |
|
36 |
#include <vector> |
37 |
#include <math/Vector3.hpp> |
38 |
#include <math/SquareMatrix3.hpp> |
39 |
|
40 |
using namespace oopse; |
41 |
|
42 |
|
43 |
|
44 |
//forward declaration |
45 |
class Snapshot; |
46 |
class StuntDouble; |
47 |
class DataStorageTestCase; |
48 |
/** |
49 |
* @class DataStorage |
50 |
* @warning do not try to insert element into (or ease element from) private member data |
51 |
* of DataStorage directly. |
52 |
* @todo DataStorage may need refactorying. Every std::vector can inherit from the same base class |
53 |
* which will make it easy to maintain |
54 |
*/ |
55 |
class DataStorage { |
56 |
public: |
57 |
|
58 |
enum{ |
59 |
dslPosition = 1, |
60 |
dslVelocity = 2, |
61 |
dslAmat = 4, |
62 |
dslAngularMomentum = 8, |
63 |
dslUnitVector = 16, |
64 |
dslZAngle = 32, |
65 |
dslForce = 64, |
66 |
dslTorque = 128 |
67 |
}; |
68 |
|
69 |
|
70 |
DataStorage(); |
71 |
DataStorage(int size, int storageLayout = 0x11111111); |
72 |
/** return the size of this DataStorage. */ |
73 |
int getSize(); |
74 |
/** |
75 |
* Changes the size of this DataStorage. |
76 |
* @param size new size of this DataStorage |
77 |
*/ |
78 |
void resize(int newSize); |
79 |
/** |
80 |
* Reallocates memory manually. The main reason for using reserve() is efficiency |
81 |
* if you know the capacity to which your std::vector must eventually grow, then it is usually more |
82 |
* efficient to allocate that memory all at once. |
83 |
*/ |
84 |
void reserve(int size); |
85 |
/** |
86 |
* Copies data inside DataStorage class. |
87 |
* Copy function actually call std::copy for every std::vector in DataStorage class. |
88 |
* One Precondition of std::copy is that target is not within the range [soruce, soruce + num] |
89 |
* @param souce |
90 |
* @param num number of element to be moved |
91 |
* @param target |
92 |
*/ |
93 |
void copy(int source, int num, int target); |
94 |
/** Returns the storage layout */ |
95 |
int getStorageLayout(); |
96 |
/** Sets the storage layout */ |
97 |
void setStorageLayout(int layout); |
98 |
/** Returns the pointer of internal array */ |
99 |
double *getArrayPointer(int whichArray); |
100 |
friend class StuntDouble; |
101 |
friend class DataStorageTestCase; |
102 |
private: |
103 |
|
104 |
|
105 |
double* internalGetArrayPointer(std::vector<Vector3d>& v); |
106 |
|
107 |
double* internalGetArrayPointer(std::vector<RotMat3x3d>& v); |
108 |
double* internalGetArrayPointer(std::vector<double>& v); |
109 |
|
110 |
template<typename T> |
111 |
void internalResize(std::vector<T>& v, int newSize); |
112 |
|
113 |
template<typename T> |
114 |
void interalCopy(std::vector<T>& v, int source, int num, int target); |
115 |
|
116 |
int size_; |
117 |
int storageLayout_; |
118 |
std::vector<Vector3d> position; /** position array */ |
119 |
std::vector<Vector3d> velocity; /** velocity array */ |
120 |
std::vector<RotMat3x3d> aMat; /** rotation matrix array */ |
121 |
std::vector<Vector3d> angularMomentum;/** angular momentum array (body-fixed) */ |
122 |
std::vector<Vector3d> unitVector; /** the lab frame unit std::vector array*/ |
123 |
std::vector<double> zAngle; /** z -angle array */ |
124 |
std::vector<Vector3d> force; /** force array */ |
125 |
std::vector<Vector3d> torque; /** torque array */ |
126 |
}; |
127 |
|
128 |
|
129 |
#endif //BRAINS_DATASTORAGE_HPP |