Commit 8edfed23 authored by Sébastien Timmermans's avatar Sébastien Timmermans
Browse files

[dd] add oneshot option

parent 36d7bc29
......@@ -74,6 +74,8 @@ MbsDirdyn* mbs_new_dirdyn_aux(MbsData* mbs_data, MbsAux* mbs_aux)
opts->compute_all_uxd = 1;
opts->flag_oneshot = 0;
opts->flag_compute_Qc = COMPUTE_ALL_QC;
// Initialization for fast computation of Qc
int i;
......@@ -158,10 +160,17 @@ void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data)
int mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
{
int err = 0;
if (dd->options->flag_oneshot)
{
mbs_msg("\n>>DIRDYN>> One shot evaluation of the direct dynamics is activated.\n");
dd->options->resfilename = "oneshot";
}
// 1. Initialize the simulation
// - - - - - - - - - - - - - -
err = mbs_dirdyn_init(dd, mbs_data);
if (err < 0){
if (err < 0) {
// Freeing the buffers, without error catching
mbs_dirdyn_finish(dd, mbs_data);
mbs_error_msg("[%d] in mbs_run_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
......@@ -170,14 +179,22 @@ int mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
// 2. Run the simulation
// - - - - - - - - - - -
err = mbs_dirdyn_loop(dd, mbs_data);
if (err < 0){
if (dd->options->flag_oneshot)
{
err = mbs_fct_dirdyn(dd->tsim, dd->y, dd->yd, mbs_data, dd);
}
else
{
err = mbs_dirdyn_loop(dd, mbs_data);
}
if (err < 0) {
// Freeing the buffers, without error catching
mbs_dirdyn_finish(dd, mbs_data);
mbs_error_msg("[%d] in mbs_run_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
// 3. Finish the simulation
// - - - - - - - - - - - -
err = mbs_dirdyn_finish(dd, mbs_data);
......@@ -728,7 +745,7 @@ int mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data)
mbs_msg("\t >Dirdyn> Error: in dirdyn loop during save realtime update ! \n");
}
mbs_msg(">>DIRDYN>> [%d] during direct dynamics loop.\n", err);
return (err<0)?err:err2;
return (err < 0) ? err : err2;
}
// Update times
cur_t0 = cur_tf;
......@@ -740,6 +757,7 @@ int mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data)
return 0;
}
}
return 0;
}
......
......@@ -154,80 +154,90 @@ void set_integrator(MbsDirdyn *mbs_dd) {
int id = opts->integrator;
switch (id) {
case RK4:
mbs_dd->initialize_integrator = initialize_rk4;
mbs_dd->loop_integrator = loop_rk4;
mbs_dd->finish_integrator = finish_rk4;
mbs_msg(" >> Integrator : \t RK4 \n");
break;
case Dopri5:
mbs_dd->initialize_integrator = initialize_dopri5;
mbs_dd->loop_integrator = loop_dopri5;
mbs_dd->finish_integrator = finish_dopri5;
mbs_msg(" >> Integrator : \t Dopri5 \n");
break;
case Rosenbrock:
mbs_dd->initialize_integrator = initialize_rosenbrock;
mbs_dd->loop_integrator = loop_rosenbrock;
mbs_dd->finish_integrator = finish_rosenbrock;
mbs_msg(" >> Integrator : \t Rosenbrock \n");
break;
case EulerEx:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Euler Explicit \n");
break;
case Eulaire:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Eulaire \n");
break;
case AlphaM:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Alpha Method \n");
break;
case EulerIm:
mbs_dd->initialize_integrator = initialize_euler_implicit;
mbs_dd->loop_integrator = loop_euler_implicit;
mbs_dd->finish_integrator = finish_euler_implicit;
mbs_msg(" >> Integrator : \t Euler Implicit \n");
break;
case Bader:
mbs_dd->initialize_integrator = initialize_bader;
mbs_dd->loop_integrator = loop_bader;
mbs_dd->finish_integrator = finish_bader;
mbs_msg(" >> Integrator : \t Semi-implicit Bader-Deuflhard extrapolation method \n");
break;
case WMethods:
mbs_dd->initialize_integrator = initialize_w_methods;
mbs_dd->loop_integrator = loop_w_methods;
mbs_dd->finish_integrator = finish_w_methods;
mbs_msg(" >> Integrator : \t W Methods \n");
break;
case Custom:
mbs_dd->initialize_integrator = initialize_custom;
mbs_dd->loop_integrator = loop_custom;
mbs_dd->finish_integrator = finish_custom;
mbs_msg(" >> Integrator : \t Custom \n");
break;
default:
if (!opts->flag_oneshot)
{
switch (id) {
case RK4:
mbs_dd->initialize_integrator = initialize_rk4;
mbs_dd->loop_integrator = loop_rk4;
mbs_dd->finish_integrator = finish_rk4;
mbs_msg(" >> Integrator : \t RK4 \n");
break;
case Dopri5:
mbs_dd->initialize_integrator = initialize_dopri5;
mbs_dd->loop_integrator = loop_dopri5;
mbs_dd->finish_integrator = finish_dopri5;
mbs_msg(" >> Integrator : \t Dopri5 \n");
break;
case Rosenbrock:
mbs_dd->initialize_integrator = initialize_rosenbrock;
mbs_dd->loop_integrator = loop_rosenbrock;
mbs_dd->finish_integrator = finish_rosenbrock;
mbs_msg(" >> Integrator : \t Rosenbrock \n");
break;
case EulerEx:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Euler Explicit \n");
break;
case Eulaire:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Eulaire \n");
break;
case AlphaM:
mbs_dd->initialize_integrator = initialize_eulerEx;
mbs_dd->loop_integrator = loop_eulerEx;
mbs_dd->finish_integrator = finish_eulerEx;
mbs_msg(" >> Integrator : \t Alpha Method \n");
break;
case EulerIm:
mbs_dd->initialize_integrator = initialize_euler_implicit;
mbs_dd->loop_integrator = loop_euler_implicit;
mbs_dd->finish_integrator = finish_euler_implicit;
mbs_msg(" >> Integrator : \t Euler Implicit \n");
break;
case Bader:
mbs_dd->initialize_integrator = initialize_bader;
mbs_dd->loop_integrator = loop_bader;
mbs_dd->finish_integrator = finish_bader;
mbs_msg(" >> Integrator : \t Semi-implicit Bader-Deuflhard extrapolation method \n");
break;
case WMethods:
mbs_dd->initialize_integrator = initialize_w_methods;
mbs_dd->loop_integrator = loop_w_methods;
mbs_dd->finish_integrator = finish_w_methods;
mbs_msg(" >> Integrator : \t W Methods \n");
break;
case Custom:
mbs_dd->initialize_integrator = initialize_custom;
mbs_dd->loop_integrator = loop_custom;
mbs_dd->finish_integrator = finish_custom;
mbs_msg(" >> Integrator : \t Custom \n");
break;
default:
mbs_dd->initialize_integrator = initialize_rk4;
mbs_dd->loop_integrator = loop_rk4;
mbs_dd->finish_integrator = finish_rk4;
mbs_warning_msg(" >> Integrator not found, possibly not yet supported !\n");
mbs_warning_msg(" >> Continuing with RK4 (Default) \n");
}
}
else
{
mbs_msg(" >> Integrator : \t rk4 is set but useless because oneshot option is activated \n");
mbs_dd->initialize_integrator = initialize_rk4;
mbs_dd->loop_integrator = loop_rk4;
mbs_dd->finish_integrator = finish_rk4;
mbs_warning_msg(" >> Integrator not found, possibly not yet supported !\n");
mbs_warning_msg(" >> Continuing with RK4 (Default) \n");
}
}
......
......@@ -87,6 +87,9 @@ typedef struct MbsDirdynOptions
int accelred; //!< 1 to use accelred, 0 otherwise, default = 0
int flag_oneshot; //!< 1 to compute the derivative function only once (no time integration !), default = 0
//!< The time is the value found in the option t0
int flag_compute_Qc; //!< choose to compute (or not) the Qc for driven variables. For dirdyn only. ==1 by default
//!< this allows to go faster
......
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