@@ -108,60 +108,37 @@ void BODY::init() {
108
108
109
109
MxSCALAR (m_CM_skew, CM_skew, mass);
110
110
MxSCALAR (neg_m_CM_skew, m_CM_skew, -1.0 );
111
+
112
+ // Creates 3x3 matrix for inerta
113
+ inertia = (2.0 /5.0 ) * mass * radius * radius;
114
+ inertia_matrix[0 ][0 ] = inertia_matrix[1 ][1 ] = inertia_matrix[2 ][2 ] = inertia;
111
115
112
- // Inertia matrix
113
- inertia = (2.0 /5.0 ) * mass * radius * radius;
114
-
115
- for (int i = 0 ; i<1 ; i++)
116
- for (int j = 0 ; j<1 ; j++)
117
- inertia_matrix[i][j] = inertia;
118
-
119
- for (int i = 1 ; i<2 ; i++)
120
- for (int j = 1 ; j<2 ; j++)
121
- inertia_matrix[i][j] = inertia;
122
-
123
- for (int i = 2 ; i<3 ; i++)
124
- for (int j = 2 ; j<3 ; j++)
125
- inertia_matrix[i][j] = inertia;
126
-
127
- };
128
-
129
- /* *****************************************************************************
130
- FUNCTION: BODY::mass_matrix()
131
- PURPOSE: (Calculates 6x6 mass matrix M for eq M*a + r = b)
132
- ******************************************************************************/
133
- void BODY::mass_matrix (){
134
-
135
- // Creates mass matrix for mat_mass()
136
- for (int i = 0 ; i<1 ; i++)
137
- for (int j = 0 ; j<1 ; j++)
138
- massmatrix[i][j] = mass;
139
-
140
- for (int i = 1 ; i<2 ; i++)
141
- for (int j = 1 ; j<2 ; j++)
142
- massmatrix[i][j] = mass;
143
-
144
- for (int i = 2 ; i<3 ; i++)
145
- for (int j = 2 ; j<3 ; j++)
146
- massmatrix[i][j] = mass;
116
+ // Creates 3x3 matrix for mass
117
+ massmatrix[0 ][0 ] = massmatrix[1 ][1 ] = massmatrix[2 ][2 ] = mass;
147
118
119
+ // Combines inertia, center of mass, and mass matrix into a 6x6 matrix
120
+ for (int i = 0 ; i<3 ; i++)
121
+ for (int j = 0 ; j<3 ; j++)
122
+ mat_mass[i][j] = massmatrix[i][j];
148
123
149
- // Combines inertia, center of mass, and mass matrix into a 6x6 matrix
150
- for (int i = 0 ; i<3 ; i++)
151
- for (int j = 0 ; j<3 ; j++)
152
- mat_mass[i][j] = massmatrix[i][j];
124
+ for (int i = 0 ; i<3 ; i++)
125
+ for (int j = 3 ; j<6 ; j++)
126
+ mat_mass[i][j] = neg_m_CM_skew[i][j-3 ];
153
127
154
- for (int i = 0 ; i<3 ; i++)
155
- for (int j = 3 ; j<6 ; j++)
156
- mat_mass[i][j] = neg_m_CM_skew[i][j-3 ];
128
+ for (int i = 3 ; i<6 ; i++)
129
+ for (int j = 0 ; j<3 ; j++)
130
+ mat_mass[i][j] = m_CM_skew[i-3 ][j];
131
+
132
+ for (int i = 3 ; i<6 ; i++)
133
+ for (int j = 3 ; j<6 ; j++)
134
+ mat_mass[i][j] = inertia_matrix[i-3 ][j-3 ];
157
135
158
- for ( int i = 3 ; i< 6 ; i++)
159
- for (int j = 0 ; j< 3 ; j ++)
160
- mat_mass [i][j] = m_CM_skew[i- 3 ][j] ;
136
+ // Temporary vector and dynamic memory for Choleski
137
+ for (int i = 0 ; i< 6 ; i ++)
138
+ tmp_vec [i] = 0.0 ;
161
139
162
- for (int i = 3 ; i<6 ; i++)
163
- for (int j = 3 ; j<6 ; j++)
164
- mat_mass[i][j] = inertia_matrix[i-3 ][j-3 ];
140
+ mat_L = new double *[6 ];
141
+ mat_mass_dyn = new double *[6 ];
165
142
166
143
};
167
144
@@ -262,21 +239,11 @@ void BODY::eq_solver() {
262
239
263
240
// Solving a = b * M^-1
264
241
265
- // Temporary vector for Choleski
266
- double tmp_vec[6 ] = {0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 };
267
-
268
- // Dynamic memory set up
269
- double **mat_mass_dyn;
270
- double **mat_L;
271
- mat_L = new double *[6 ];
272
- mat_mass_dyn = new double *[6 ];
273
-
274
242
for (int i = 0 ; i<6 ; i++)
275
243
{
276
244
mat_mass_dyn[i] = mat_mass[i];
277
245
mat_L[i] = new double [6 ];
278
246
}
279
-
280
247
281
248
dLU_Choleski (mat_mass_dyn, mat_L, tmp_vec, 6 , vec_b, vec_a, 0 );
282
249
@@ -288,10 +255,6 @@ void BODY::eq_solver() {
288
255
for (int i = 0 ; i<3 ; i++)
289
256
omegaDot[i] = vec_a[i + 3 ];
290
257
291
- // Delete dynamic memory
292
- delete[] mat_mass_dyn;
293
- delete[] mat_L;
294
-
295
258
};
296
259
297
260
/* **************************************************************************
@@ -300,7 +263,6 @@ PURPOSE: (Calls all functions in desired order for calculations)
300
263
***************************************************************************/
301
264
void BODY::derivative () {
302
265
303
- mass_matrix ();
304
266
rotation_matrix ();
305
267
calcforce ();
306
268
calctorque ();
@@ -316,7 +278,6 @@ FUNCTION: BODY::integrate()
316
278
PURPOSE: (Sets up trick integration)
317
279
***************************************************************************/
318
280
319
- #ifndef IN_MAKE
320
281
int BODY::integ () {
321
282
322
283
int integration_step;
@@ -329,6 +290,7 @@ int BODY::integ() {
329
290
330
291
NULL );
331
292
293
+
332
294
load_deriv (
333
295
&vel[0 ], &vel[1 ], &vel[2 ],
334
296
&acc[0 ], &acc[1 ], &acc[2 ],
@@ -350,4 +312,3 @@ int BODY::integ() {
350
312
return (integration_step);
351
313
352
314
};
353
- #endif
0 commit comments