@@ -108,60 +108,37 @@ void BODY::init() {
108108
109109 MxSCALAR (m_CM_skew, CM_skew, mass);
110110 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;
111115
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;
147118
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];
148123
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 ];
153127
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 ];
157135
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 ;
161139
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 ];
165142
166143};
167144
@@ -262,21 +239,11 @@ void BODY::eq_solver() {
262239
263240 // Solving a = b * M^-1
264241
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-
274242 for (int i = 0 ; i<6 ; i++)
275243 {
276244 mat_mass_dyn[i] = mat_mass[i];
277245 mat_L[i] = new double [6 ];
278246 }
279-
280247
281248 dLU_Choleski (mat_mass_dyn, mat_L, tmp_vec, 6 , vec_b, vec_a, 0 );
282249
@@ -288,10 +255,6 @@ void BODY::eq_solver() {
288255 for (int i = 0 ; i<3 ; i++)
289256 omegaDot[i] = vec_a[i + 3 ];
290257
291- // Delete dynamic memory
292- delete[] mat_mass_dyn;
293- delete[] mat_L;
294-
295258};
296259
297260/* **************************************************************************
@@ -300,7 +263,6 @@ PURPOSE: (Calls all functions in desired order for calculations)
300263***************************************************************************/
301264void BODY::derivative () {
302265
303- mass_matrix ();
304266 rotation_matrix ();
305267 calcforce ();
306268 calctorque ();
@@ -316,7 +278,6 @@ FUNCTION: BODY::integrate()
316278PURPOSE: (Sets up trick integration)
317279***************************************************************************/
318280
319- #ifndef IN_MAKE
320281int BODY::integ () {
321282
322283 int integration_step;
@@ -329,6 +290,7 @@ int BODY::integ() {
329290
330291 NULL );
331292
293+
332294 load_deriv (
333295 &vel[0 ], &vel[1 ], &vel[2 ],
334296 &acc[0 ], &acc[1 ], &acc[2 ],
@@ -350,4 +312,3 @@ int BODY::integ() {
350312 return (integration_step);
351313
352314};
353- #endif
0 commit comments