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

save and real-time adaptive correct calls

parent 37f56ff2
......@@ -62,6 +62,8 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
opts->adapt_rtoler = 1.0e-3;
opts->adapt_atoler = 1.0e-3;
opts->adapt_dt_max = 1.0e-3;
opts->adapt_dt_save = 1.0e-3;
opts->adapt_dt_rt = 1.0e-3;
opts->adapt_max_steps = 10* ((opts->tf - opts->t0) / opts->dt0); // 10 is a safety factor because the total number of time steps is unknown
dirdyn->options = opts;
......@@ -151,6 +153,10 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data){
dd->tsim = dd->options->t0;
dd->dt = dd->options->dt0;
// adaptive time step
dd->adapt_last_t_save = dd->tsim - dd->options->adapt_dt_save;
dd->adapt_last_t_rt = dd->tsim - dd->options->adapt_dt_rt;
// user intialization
user_init(mbs_data, dd->mbs_aux);
......@@ -430,20 +436,28 @@ void f_prim_dopri5(unsigned n, double tsim, double y[], double dydt[], MbsData *
// user loop
user_loop(s, dd->mbs_aux);
// derivative
mbs_fct_dirdyn(tsim, y, dydt, s, dd->mbs_aux);
// save results to the buffer
if(dd->options->save2file){
if(dd->options->save2file && (dd->tsim - dd->adapt_last_t_save >= dd->options->adapt_dt_save))
{
dd->savePeriodCounter++;
if(dd->savePeriodCounter%dd->options->saveperiod == 0){
dd->adapt_last_t_save = dd->tsim;
if(dd->savePeriodCounter%dd->options->saveperiod == 0)
{
mbs_dirdyn_save(dd, s->tsim);
}
}
// real-time modules
#ifdef REAL_TIME
if (dd->options->realtime)
if (dd->options->realtime && (dd->tsim - dd->adapt_last_t_rt >= dd->options->adapt_dt_rt))
{
dd->adapt_last_t_rt = dd->tsim;
// update real-time buffers
mbs_realtime_update(realtime, mbs_data->tsim);
......
......@@ -66,10 +66,12 @@ typedef struct MbsDirdynOptions
int adapt_time_step; ///< 1 to use dopri5 (adaptive time step), 0 to use runge kutta 4 (fixed time step)
// adaptive time step options
int adapt_max_steps; ///< maximal number of stpes [-]
double adapt_rtoler; ///< relative error tolerances [-]
double adapt_atoler; ///< absolute error tolerances [-]
double adapt_dt_max; ///< maximal time step [s]
int adapt_max_steps; ///< maximal number of stpes [-]
double adapt_rtoler; ///< relative error tolerances [-]
double adapt_atoler; ///< absolute error tolerances [-]
double adapt_dt_max; ///< maximal time step [s]
double adapt_dt_save; ///< minimal time interval between two saved values [s]
double adapt_dt_rt; ///< minimial time interval between two calls to the real-time features [s]
} MbsDirdynOptions;
......@@ -105,6 +107,10 @@ typedef struct MbsDirdyn
/** counter for checking wheter results must be saved */
int savePeriodCounter;
// adaptive time step
double adapt_last_t_save; ///< last time a value was saved [s]
double adapt_last_t_rt; ///< last time the real-time modules were called [s]
} 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