1 |
mmeineke |
670 |
#include <cstdlib> |
2 |
|
|
#include <cstdio> |
3 |
|
|
|
4 |
|
|
#include "simError.h" |
5 |
|
|
#include "SimState.hpp" |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
SimState::SimState(){ |
9 |
|
|
|
10 |
|
|
nElements = 0; |
11 |
|
|
arraysAllocated = false; |
12 |
|
|
|
13 |
|
|
pos = NULL; |
14 |
|
|
vel = NULL; |
15 |
|
|
frc = NULL; |
16 |
|
|
trq = NULL; |
17 |
|
|
Amat = NULL; |
18 |
|
|
mu = NULL; |
19 |
|
|
ul = NULL; |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
SimState::~SimState(){ |
24 |
|
|
|
25 |
|
|
if(pos != NULL) delete[] pos; |
26 |
|
|
if(vel != NULL) delete[] vel; |
27 |
|
|
if(frc != NULL) delete[] frc; |
28 |
|
|
if(trq != NULL) delete[] trq; |
29 |
|
|
if(Amat != NULL) delete[] Amat; |
30 |
|
|
if(mu != NULL) delete[] mu; |
31 |
|
|
if(ul != NULL) delete[] ul; |
32 |
|
|
|
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
void SimState::createArrays (int the_nElements) { |
37 |
|
|
int i, index3, index9; |
38 |
|
|
|
39 |
|
|
if( arraysAllocated ){ |
40 |
|
|
|
41 |
|
|
sprintf( painCave.errMsg, |
42 |
|
|
"Someone has attempted to allocate SimState arrays before " |
43 |
|
|
"deallocating the previous arrays.\n" ); |
44 |
|
|
painCave.isFatal = 1; |
45 |
|
|
simError(); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
nElements = the_nElements; |
49 |
|
|
|
50 |
|
|
pos = new double[nElements*3]; |
51 |
|
|
vel = new double[nElements*3]; |
52 |
|
|
frc = new double[nElements*3]; |
53 |
|
|
trq = new double[nElements*3]; |
54 |
|
|
Amat = new double[nElements*9]; |
55 |
|
|
mu = new double[nElements]; |
56 |
|
|
ul = new double[nElements*3]; |
57 |
|
|
|
58 |
|
|
// init directional values to zero |
59 |
|
|
|
60 |
|
|
for( i=0; i<nElements; i++){ |
61 |
|
|
index3 = i*3; |
62 |
|
|
index9 = i*9; |
63 |
|
|
|
64 |
|
|
trq[index3+0] = 0.0; |
65 |
|
|
trq[index3+1] = 0.0; |
66 |
|
|
trq[index3+2] = 0.0; |
67 |
|
|
|
68 |
|
|
Amat[index9+0] = 1.0; |
69 |
|
|
Amat[index9+1] = 0.0; |
70 |
|
|
Amat[index9+2] = 0.0; |
71 |
|
|
|
72 |
|
|
Amat[index9+3] = 0.0; |
73 |
|
|
Amat[index9+4] = 1.0; |
74 |
|
|
Amat[index9+5] = 0.0; |
75 |
|
|
|
76 |
|
|
Amat[index9+6] = 0.0; |
77 |
|
|
Amat[index9+7] = 0.0; |
78 |
|
|
Amat[index9+8] = 1.0; |
79 |
|
|
|
80 |
|
|
mu[i] = 0.0; |
81 |
|
|
|
82 |
|
|
ul[index3+0] = 1.0; |
83 |
|
|
ul[index3+1] = 0.0; |
84 |
|
|
ul[index3+2] = 0.0; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
arraysAllocated = true; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
void SimState::destroyArrays( void ){ |
91 |
|
|
|
92 |
|
|
if(pos != NULL) delete[] pos; |
93 |
|
|
if(vel != NULL) delete[] vel; |
94 |
|
|
if(frc != NULL) delete[] frc; |
95 |
|
|
if(trq != NULL) delete[] trq; |
96 |
|
|
if(Amat != NULL) delete[] Amat; |
97 |
|
|
if(mu != NULL) delete[] mu; |
98 |
|
|
if(ul != NULL) delete[] ul; |
99 |
|
|
|
100 |
|
|
pos = NULL; |
101 |
|
|
vel = NULL; |
102 |
|
|
frc = NULL; |
103 |
|
|
trq = NULL; |
104 |
|
|
Amat = NULL; |
105 |
|
|
mu = NULL; |
106 |
|
|
ul = NULL; |
107 |
|
|
|
108 |
|
|
arraysAllocated = false; |
109 |
|
|
nElements = 0; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
void SimState::getAtomPointers( int index, |
113 |
|
|
double** the_pos, |
114 |
|
|
double** the_vel, |
115 |
|
|
double** the_frc, |
116 |
|
|
double** the_trq, |
117 |
|
|
double** the_Amat, |
118 |
|
|
double** the_mu, |
119 |
|
|
double** the_ul ){ |
120 |
|
|
int index3, index9; |
121 |
|
|
|
122 |
|
|
if( arraysAllocated ){ |
123 |
|
|
|
124 |
|
|
index3 = index*3; |
125 |
|
|
index9 = index*9; |
126 |
|
|
|
127 |
|
|
*the_pos = &(pos[index3]); |
128 |
|
|
*the_vel = &(vel[index3]); |
129 |
|
|
*the_frc = &(frc[index3]); |
130 |
|
|
*the_trq = &(trq[index3]); |
131 |
|
|
*the_Amat = &(Amat[index9]); |
132 |
|
|
*the_mu = &(mu[index]); |
133 |
|
|
*the_ul = &(ul[index3]); |
134 |
|
|
} |
135 |
|
|
else{ |
136 |
|
|
|
137 |
|
|
sprintf( painCave.errMsg, |
138 |
|
|
"Atom %d attempted to access its arrays before they had been" |
139 |
|
|
" allocated\n", |
140 |
|
|
index ); |
141 |
|
|
painCave.isFatal = 1; |
142 |
|
|
simError(); |
143 |
|
|
} |
144 |
|
|
} |