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

dopri5 dirdyn strucure

parent faa42403
......@@ -37,8 +37,9 @@ MbsDirdyn* mbs_new_dirdyn(MbsData* mbs_data){
MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
MbsDirdyn* dirdyn;
MbsDirdyn *dirdyn;
MbsDirdynOptions* opts;
DirdynDopri5 *dopr;
// Initialize the direct dynamic structure
dirdyn = (MbsDirdyn*)malloc(sizeof(MbsDirdyn));
......@@ -74,14 +75,19 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
dirdyn->savePeriodCounter = 0;
// adaptive time step
dirdyn->adapt_flag_save = 0;
dopr = (DirdynDopri5*) malloc(sizeof(DirdynDopri5));
dopr->flag_save = 0;
dirdyn->dopri5 = dopr;
return dirdyn;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data){
void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data)
{
free(dirdyn->dopri5);
free(dirdyn->options);
freeMbsAux(dirdyn->mbs_aux, mbs_data);
free(dirdyn);
......@@ -141,8 +147,8 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
dd->yd = (double*) malloc(dd->nState*sizeof(double));
// adaptive time step
dd->adapt_dydt_save = (double*) malloc(dd->nState*sizeof(double));
dd->adapt_solout_last_t = mbs_data->t0 - mbs_data->dt0;
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
......@@ -360,10 +366,10 @@ void mbs_dirdyn_finish(MbsDirdyn* dd, MbsData* mbs_data){
// user finalization
user_finish(mbs_data, dd);
free(dd->dopri5->dydt_save);
free(dd->y);
free(dd->yd);
free(dd->yout);
free(dd->adapt_dydt_save);
if(dd->options->save2file){
// write the buffer (in case they were not saved automatically)
......@@ -524,12 +530,15 @@ double loop_dopri5(double cur_t0, double cur_tf, double dt0, double **dopri5_all
void fcn_dopri5(unsigned n, long nr, double tsim, double y[], double dydt[], MbsData *s, MbsDirdyn *dd)
{
int i;
double *dydt_save;
dydt_save = dd->dopri5->dydt_save;
if ( (!nr) && dd->adapt_flag_save ) // use previously computed solution dor first time step
if ( (!nr) && dd->dopri5->flag_save ) // use previously computed solution dor first time step
{
for(i=0; i<n; i++)
{
dydt[i] = dd->adapt_dydt_save[i];
dydt[i] = dydt_save[i];
}
}
else // compute new solution
......@@ -540,10 +549,10 @@ void fcn_dopri5(unsigned n, long nr, double tsim, double y[], double dydt[], Mbs
{
for(i=0; i<n; i++)
{
dd->adapt_dydt_save[i] = dydt[i];
dydt_save[i] = dydt[i];
}
dd->adapt_flag_save = 1;
dd->dopri5->flag_save = 1;
}
}
}
......@@ -561,9 +570,9 @@ void fcn_dopri5(unsigned n, long nr, double tsim, double y[], double dydt[], Mbs
*/
void solout_dopri5(long nr, double tsim_old, double tsim, double y[], unsigned n, int* irtrn, MbsData *s, MbsDirdyn *dd)
{
if (tsim > dd->adapt_solout_last_t)
if (tsim > dd->dopri5->solout_last_t)
{
dd->adapt_solout_last_t = tsim;
dd->dopri5->solout_last_t = tsim;
// user loop
user_loop(s, dd);
......
......@@ -75,6 +75,19 @@ typedef struct MbsDirdynOptions
} MbsDirdynOptions;
/**
* Dopri5 structure for dirdyn
*/
typedef struct DirdynDopri5
{
int flag_save;
double solout_last_t;
double *dydt_save;
} DirdynDopri5;
/**
* General structure of the direct dynamic module
......@@ -107,10 +120,7 @@ typedef struct MbsDirdyn
/** counter for checking wheter results must be saved */
int savePeriodCounter;
// adaptive time step
int adapt_flag_save;
double *adapt_dydt_save;
double adapt_solout_last_t;
DirdynDopri5 *dopri5; ///< Dopri5 structure for dirdyn
} MbsDirdyn;
......
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