Skip to content

Commit 1325cd6

Browse files
author
Wallace
committed
Added shutdown job and made minor changes to body.cpp
1 parent f328802 commit 1325cd6

File tree

4 files changed

+46
-66
lines changed

4 files changed

+46
-66
lines changed

trick_sims/SIM_singlerigidbody/S_define

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PURPOSE:
33
( Single body rigid dynamics simulation )
44
LIBRARY DEPENDENCIES:
55
((src/body.cpp)
6+
(src/body_shutdown.cpp)
67
)
78
*************************************************************/
89
#define TRICK_NO_MONTE_CARLO
@@ -22,6 +23,7 @@ class BodySimObject : public Trick::SimObject {
2223
("initialization") body.init() ;
2324
("derivative") body.derivative() ;
2425
("integration") trick_ret = body.integ() ;
26+
("shutdown") body.body_shutdown();
2527
}
2628
};
2729

trick_sims/SIM_singlerigidbody/models/include/body.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ public:
5555
double rotate[3][3];
5656
double angle_force[3];
5757

58+
double tmp_vec[6];
59+
double **mat_mass_dyn;
60+
double **mat_L;
5861

5962
// Methods
6063
void default_data();
6164
void init();
6265
void derivative();
6366
int integ();
67+
int body_shutdown();
6468

65-
void mass_matrix();
6669
void rotation_matrix();
6770
void calcforce();
6871
void calctorque();

trick_sims/SIM_singlerigidbody/models/src/body.cpp

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -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
***************************************************************************/
301264
void BODY::derivative() {
302265

303-
mass_matrix();
304266
rotation_matrix();
305267
calcforce();
306268
calctorque();
@@ -316,7 +278,6 @@ FUNCTION: BODY::integrate()
316278
PURPOSE: (Sets up trick integration)
317279
***************************************************************************/
318280

319-
#ifndef IN_MAKE
320281
int 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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/************************************************************************
2+
PURPOSE: (Shutdown the simulation)
3+
*************************************************************************/
4+
#include "../include/body.hh"
5+
#include "trick/exec_proto.h"
6+
7+
int BODY::body_shutdown() {
8+
9+
delete[] mat_mass_dyn;
10+
delete[] mat_L;
11+
12+
return 0;
13+
};
14+

0 commit comments

Comments
 (0)