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

dopri5 dirdyn options structure

parent dfcef718
......@@ -69,11 +69,11 @@ int main(int argc, char const *argv[])
mbs_dirdyn->options->save2file = 1;
mbs_dirdyn->options->respath = PROJECT_SOURCE_DIR"/../resultsR";
mbs_dirdyn->options->adapt_time_step = 1;
mbs_dirdyn->options->adapt_rtoler = 1.0e-14;
mbs_dirdyn->options->adapt_atoler = 1.0e-14;
mbs_dirdyn->options->adapt_dt_max = 0.001;
mbs_dirdyn->options->adapt_verbose = 1;
mbs_dirdyn->options->dopri5->flag = 1;
mbs_dirdyn->options->dopri5->rtoler = 1.0e-14;
mbs_dirdyn->options->dopri5->atoler = 1.0e-14;
mbs_dirdyn->options->dopri5->dt_max = 0.001;
mbs_dirdyn->options->dopri5->verbose = 1;
mbs_dirdyn->options->realtime = 1;
......
......@@ -40,15 +40,16 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
MbsDirdyn *dirdyn;
MbsDirdynOptions* opts;
DirdynDopri5 *dopr;
DirdynOptDopri5 *dopr_opt;
// Initialize the direct dynamic structure
dirdyn = (MbsDirdyn*)malloc(sizeof(MbsDirdyn));
dirdyn = (MbsDirdyn*) malloc(sizeof(MbsDirdyn));
// keep the pointer to the auxiliary data structure
dirdyn->mbs_aux = mbs_aux;
// Initialize the options struct with default options
opts = (MbsDirdynOptions*)malloc(sizeof(MbsDirdynOptions));
opts = (MbsDirdynOptions*) malloc(sizeof(MbsDirdynOptions));
opts->t0 = 0.;
opts->tf = 5.;
opts->dt0 = 1e-3;
......@@ -62,13 +63,15 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
opts->accelred = 0;
// adaptive time step integrator
opts->adapt_time_step = 0;
opts->adapt_verbose = 1;
opts->adapt_rtoler = 1.0e-4;
opts->adapt_atoler = 1.0e-3;
opts->adapt_dt_max = 1.0e-3;
opts->adapt_nmax = 1.0e9;
dopr_opt = (DirdynOptDopri5*) malloc(sizeof(DirdynOptDopri5));
dopr_opt->flag = 0;
dopr_opt->verbose = 1;
dopr_opt->rtoler = 1.0e-3;
dopr_opt->atoler = 1.0e-3;
dopr_opt->dt_max = 1.0e-3;
dopr_opt->nmax = 1.0e9;
opts->dopri5 = dopr_opt;
dirdyn->options = opts;
// initial the saving counter
......@@ -88,6 +91,7 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux){
void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data)
{
free(dirdyn->dopri5);
free(dirdyn->options->dopri5);
free(dirdyn->options);
freeMbsAux(dirdyn->mbs_aux, mbs_data);
free(dirdyn);
......@@ -272,9 +276,9 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
// NUMERICAL INTEGRATION
// - - - - - - - - - - -
if (dd->options->adapt_time_step)
if (dd->options->dopri5->flag)
{
if (dd->options->adapt_verbose)
if (dd->options->dopri5->verbose)
{
fileout_dopri5 = stdout;
}
......@@ -510,8 +514,8 @@ double loop_dopri5(double cur_t0, double cur_tf, double dt0, double **dopri5_all
{
double hout;
dopri5(dd->nState, fcn_dopri5, cur_t0, dd->y, cur_tf, &(dd->options->adapt_rtoler), &(dd->options->adapt_atoler),
0, solout_dopri5, 1, fileout_dopri5, 0.0, 0.0, 0.0, 0.0, 0.0, dd->options->adapt_dt_max, dt0, dd->options->adapt_nmax,
dopri5(dd->nState, fcn_dopri5, cur_t0, dd->y, cur_tf, &(dd->options->dopri5->rtoler), &(dd->options->dopri5->atoler),
0, solout_dopri5, 1, fileout_dopri5, 0.0, 0.0, 0.0, 0.0, 0.0, dd->options->dopri5->dt_max, dt0, dd->options->dopri5->nmax,
1, 0, 0, NULL, 0, dopri5_alloc_tab, s, dd, &hout);
return hout;
......
......@@ -20,9 +20,23 @@
#include "mbs_buffer.h"
/**
* Structure defining the option of a direct dynamic
* Dopri5 structure for dirdyn options
*/
typedef struct DirdynOptDopri5
{
int flag; ///< 1 to use dopri5 (adaptive time step), 0 to use runge kutta 4 (fixed time step)
int nmax; ///< maximal number of stpes [-]
int verbose; ///< 1 to get print indications related to time adaptive integrator, 0 otherwise
double rtoler; ///< relative error tolerances [-]
double atoler; ///< absolute error tolerances [-]
double dt_max; ///< maximal time step [s]
} DirdynOptDopri5;
/**
* Structure defining the option of a direct dynamic
*/
typedef struct MbsDirdynOptions
{
/// initial time of the simulation, defaut = 0.0
......@@ -65,13 +79,7 @@ typedef struct MbsDirdynOptions
int accelred; ///< 1 to use accelred, 0 otherwise
// adaptive time step
int adapt_time_step; ///< 1 to use dopri5 (adaptive time step), 0 to use runge kutta 4 (fixed time step)
int adapt_nmax; ///< maximal number of stpes [-]
int adapt_verbose; ///< 1 to get print indications related to time adaptive integrator, 0 otherwise
double adapt_rtoler; ///< relative error tolerances [-]
double adapt_atoler; ///< absolute error tolerances [-]
double adapt_dt_max; ///< maximal time step [s]
DirdynOptDopri5 *dopri5; ///< Dopri5 structure for dirdyn options
} MbsDirdynOptions;
......@@ -80,12 +88,11 @@ typedef struct MbsDirdynOptions
*/
typedef struct DirdynDopri5
{
int flag_save;
int flag_save; ///< 1 if first dydt save done, 0 otherwise
double solout_last_t;
double solout_last_t; ///< last time solout was called
double *dydt_save;
double *dydt_save; ///< save dydt of the last time step
} DirdynDopri5;
......
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