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