Commit 943c4c20 authored by Nicolas Van der Noot's avatar Nicolas Van der Noot
Browse files

dopri5 allocated vectors in structure

parent 71ef9a4e
......@@ -26,7 +26,8 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
MbsDirdyn* mbs_new_dirdyn(MbsData* mbs_data){
MbsDirdyn* mbs_new_dirdyn(MbsData* mbs_data)
{
MbsAux* mbs_aux;
// Initialize the local data struct
......@@ -35,8 +36,8 @@ MbsDirdyn* mbs_new_dirdyn(MbsData* mbs_data){
return mbs_new_dirdyn_aux(mbs_data, mbs_aux);
}
MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux)
{
MbsDirdyn *dirdyn;
MbsDirdynOptions* opts;
MbsDirdynDopri5 *dopr;
......@@ -102,8 +103,8 @@ void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data){
void mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
{
int i;
FILE* animFile;
......@@ -120,8 +121,6 @@ void mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data){
// 3. Finish the simulation
// - - - - - - - - - - - -
mbs_dirdyn_finish(dd, mbs_data);
}
void mbs_dirdyn_save(MbsDirdyn* dd, double t){
......@@ -134,9 +133,9 @@ void mbs_dirdyn_save(MbsDirdyn* dd, double t){
mbs_growing_buffer_save(dd->user_buffer, t);
}
void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
int i;
void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
{
int i;
// INITIALIZATION
// - - - - - - - -
......@@ -153,9 +152,20 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
dd->yout = (double*) malloc(dd->nState*sizeof(double));
dd->yd = (double*) malloc(dd->nState*sizeof(double));
// adaptive time step
dd->dopri5->dydt_save = (double*) malloc(dd->nState*sizeof(double));
dd->dopri5->solout_last_t = mbs_data->t0 - mbs_data->dt0;
// allocated vectors for dopri5
if (dd->options->dopri5->flag_use)
{
dd->dopri5->alloc_tab = (double**) malloc(DOPRI5_NB_ALLOC_VEC*sizeof(double*));
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
dd->dopri5->alloc_tab[i] = (double*) malloc (dd->nState*sizeof(double));
}
// adaptive time step
dd->dopri5->dydt_save = (double*) malloc(dd->nState*sizeof(double));
dd->dopri5->solout_last_t = mbs_data->t0 - mbs_data->dt0;
}
// real-time modules activated
#ifdef REAL_TIME
......@@ -195,11 +205,9 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
char* f;
const char * fnameSuffix[] = {"q", "qd", "qdd", "Qq", "ux", "uxd"};
int bufElemNb[] = {mbs_data->njoint, mbs_data->njoint, mbs_data->njoint, mbs_data->njoint, mbs_data->Nux, mbs_data->Nux};
njoint = mbs_data->njoint;
Nux = mbs_data->Nux;
// set the filename if not specified
if(dd->options->resfilename == NULL){
......@@ -215,8 +223,7 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
}
else{
respath = dd->options->respath;
}
}
// set the buffer size if not specified
if (dd->options->buffersize<1){
......@@ -268,13 +275,12 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
}
}
void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data)
{
FILE *animFile;
FILE *fileout_dopri5;
MbsDirdynOptDopri5 *dopr_opt;
int i;
double **dopri5_alloc_tab;
double cur_t0, cur_tf;
// NUMERICAL INTEGRATION
......@@ -293,14 +299,6 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
fileout_dopri5 = NULL;
}
// allocated vectors for dopri5
dopri5_alloc_tab = (double**) malloc(DOPRI5_NB_ALLOC_VEC*sizeof(double*));
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
dopri5_alloc_tab[i] = (double*) malloc (dd->nState*sizeof(double));
}
cur_t0 = dd->options->t0;
if (dopr_opt->flag_waypoint)
......@@ -314,7 +312,7 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
while (cur_tf <= dd->options->tf)
{
loop_dopri5(cur_t0, cur_tf, dd->options->dt0, dopri5_alloc_tab, mbs_data, dd, fileout_dopri5);
loop_dopri5(cur_t0, cur_tf, dd->options->dt0, dd->dopri5->alloc_tab, mbs_data, dd, fileout_dopri5);
cur_t0 = cur_tf;
cur_tf += dopr_opt->delta_t_wp;
......@@ -325,13 +323,6 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
break;
}
}
// release memory allocated for dopri5 vectors
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
free(dopri5_alloc_tab[i]);
}
free(dopri5_alloc_tab);
}
else
{
......@@ -382,7 +373,18 @@ void mbs_dirdyn_finish(MbsDirdyn* dd, MbsData* mbs_data){
// user finalization
user_finish(mbs_data, dd);
free(dd->dopri5->dydt_save);
// release memory allocated for dopri5
if (dd->options->dopri5->flag_use)
{
free(dd->dopri5->dydt_save);
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
free(dd->dopri5->alloc_tab[i]);
}
free(dd->dopri5->alloc_tab);
}
free(dd->y);
free(dd->yd);
free(dd->yout);
......
......@@ -98,6 +98,8 @@ typedef struct MbsDirdynDopri5
double *dydt_save; ///< save dydt of the last time step
double **alloc_tab; ///< allocated state vectors
} MbsDirdynDopri5;
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment