Robotran C Documentation
integrator.h
Go to the documentation of this file.
1 
14 #ifndef __INTEGRATOR_H_INCLUDED__ // guard against multiple/recursive includes
15 #define __INTEGRATOR_H_INCLUDED__
16 
17 #include "mbs_data.h"
18 #include "mbs_aux.h"
19 
30 
31 
37 typedef void(*initialize_integrator_ptr)(MbsData *mbs_data, MbsDirdyn *mbs_dd);
39 typedef int(*loop_integrator_ptr)(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd);
41 typedef void(*finish_integrator_ptr)(MbsData *mbs_data, MbsDirdyn *mbs_dd);
42 
47 void set_integrator(MbsDirdyn *dd);
48 
55 void print_warnings_integrator(MbsData *mbs_data, MbsDirdyn *mbs_dd, int type_of_integrator);
56 
62 void print_warnings_constant_step_integrator(MbsDirdyn *mbs_dd, char *integrator_name);
63 
83 int rk4(double y[], double dydx[], int n, double x, double h, double yout[],
84  int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *),
85  MbsData *s, MbsDirdyn *dd);
86 
111 int rosenbrock(int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *),
112  double *x, double y[], double eps, double hmax, double htry,
113  long nmax, double dydx[], double yscal[], double *hnext, MbsData *s,
114  MbsDirdyn *dd, double *hdid);
115 
120 int ThetaSC(double y[], double dydx[], int n, double x, double h, double yout[],
121  int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *),
122  MbsData *s, MbsDirdyn *dd);
123 
143 int mbs_estim_jac_acc(double x, double htry, double y[], double dydx[], int compute_dfdx, double dfdx[], double **dfdy, int n,
144  int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *dd);
145 
146 
171 int mbs_freeze_jac(int freeze_index, int *next_freeze_index, double x, double h, double y[], double dydx[],
172  int compute_dfdx, double dfdx[], double **dfdy, double dydx_freeze[], double dfdx_freeze[], double **dfdy_freeze,
173  int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *mbs_dd);
174 
175 
193 int euler_implicit(double y[], double dydx[], int n, double *x, double h, double yout[],
194  int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *),
195  MbsData *s, MbsDirdyn *mbs_dd);
196 
214 int w_methods(double y[], double dydx[], int n, double x, double h, double yout[],
215  int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *),
216  MbsData *s, MbsDirdyn *mbs_dd);
217 
218 #endif
print_warnings_integrator
void print_warnings_integrator(MbsData *mbs_data, MbsDirdyn *mbs_dd, int type_of_integrator)
Check the options set by user to warn him when he modified an unused option for the integrator.
Definition: integrator.c:250
complex_float
Implementation of eig function using lapacke without using the lapackE interface.
Definition: cholesky.c:14
loop_bader
int loop_bader(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_bader.c:61
mbs_estim_jac_acc
int mbs_estim_jac_acc(double x, double htry, double y[], double dydx[], int compute_dfdx, double dfdx[], double **dfdy, int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *dd)
Evaluate the Jacobian of a function accelerations using finite difference.
Definition: integrator.c:30
Bader
@ Bader
Definition: integrator.h:29
mbs_euler_implicit.h
This header defines global functions for Euler Implicit integrator in C.
loop_integrator_ptr
int(* loop_integrator_ptr)(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
main loop of integration, in which the integrator is called
Definition: integrator.h:39
useful_functions.h
mbs_w_methods.h
This header defines global functions for W methods integrator in C.
mbs_eig_0
int mbs_eig_0(double **A, int n, double *eval_a, double *eval_b, double **evec_r, double **evec_phi)
Compute the eigen values and vector of a matrix with index starting a 0.
Definition: eig_lapacke.c:29
mbs_error_msg
void mbs_error_msg(char *msg,...)
Send an error message.
Definition: mbs_message.c:102
mbs_data.h
MbsDirdyn::nState
int nState
size of the state vector
Definition: mbs_dirdyn_struct.h:152
EulerEx
@ EulerEx
Definition: integrator.h:29
mbs_bader.h
This header defines global functions for Bader integrator in C.
mbs_dirdyn_struct.h
loop_w_methods
int loop_w_methods(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_w_methods.c:77
get_dvec_0
double * get_dvec_0(int l_v)
create (with memory allocation) a vector (length l_v) of doubles, starting at index 0
Definition: mbs_1D_array.c:880
MbsDirdynOptions::dt_max
double dt_max
maximal time step [s], default = 1.0e-3
Definition: mbs_dirdyn_struct.h:130
DIRDYN_INTEGRATOR_OPTION_DEFAULT_dt_max
#define DIRDYN_INTEGRATOR_OPTION_DEFAULT_dt_max
Definition: mbs_dirdyn_struct.h:31
print_warnings_constant_step_integrator
void print_warnings_constant_step_integrator(MbsDirdyn *mbs_dd, char *integrator_name)
Print the warning message, called by print_warnings_integrator for constant step size dt integrators.
Definition: integrator.c:324
copy_dmat_0
void copy_dmat_0(double **tab_src, double **tab_dest, int nb_r, int nb_c)
Copy the content of a [nb_r times nb_c] matrix of doubles to a second matrix, starting with index 0.
Definition: mbs_matrix.c:363
MbsDirdynOptions::nmax
int nmax
maximal number of steps [-], default = 1e9
Definition: mbs_dirdyn_struct.h:126
DIRDYN_INTEGRATOR_OPTION_DEFAULT_atoler
#define DIRDYN_INTEGRATOR_OPTION_DEFAULT_atoler
Definition: mbs_dirdyn_struct.h:30
free_dmat_0
void free_dmat_0(double **mat)
release memory for a matrix of doubles, starting at index 0
Definition: mbs_matrix.c:293
initialize_euler_implicit
void initialize_euler_implicit(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Euler Implicit integrator.
Definition: mbs_euler_implicit.c:21
Eulaire
@ Eulaire
Definition: integrator.h:29
DIRDYN_INTEGRATOR_OPTION_DEFAULT_toler
#define DIRDYN_INTEGRATOR_OPTION_DEFAULT_toler
Definition: mbs_dirdyn_struct.h:28
initialize_integrator_ptr
void(* initialize_integrator_ptr)(MbsData *mbs_data, MbsDirdyn *mbs_dd)
These three pointers of functions should be defined for each integrator separately,...
Definition: integrator.h:37
EulerIm
@ EulerIm
Definition: integrator.h:29
mbs_cholsl_0
int mbs_cholsl_0(double **A, int n, double **B, int nb)
Solves a symmetric positive definite system of linear equations AX=B (B being the right hand side wit...
Definition: cholesky.c:40
MbsData::Nux
int Nux
Number of user variable.
Definition: mbs_data.h:288
mbs_rosenbrock.h
This header defines global functions for rosenbrock integrator in C.
loop_rosenbrock
int loop_rosenbrock(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_rosenbrock.c:63
mbs_freeze_jac
int mbs_freeze_jac(int freeze_index, int *next_freeze_index, double x, double h, double y[], double dydx[], int compute_dfdx, double dfdx[], double **dfdy, double dydx_freeze[], double dfdx_freeze[], double **dfdy_freeze, int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *mbs_dd)
Freeze the Jacobian of an integrator structure until mbs_dd->options->n_freeze.
Definition: integrator.c:107
complex_double
Definition: cholesky.c:15
complex_float::x
float x
Definition: cholesky.c:14
choldc_0
int choldc_0(double **a, int n, double *p)
Definition: choldc.c:47
loop_euler_implicit
int loop_euler_implicit(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_euler_implicit.c:56
DIRDYN_INTEGRATOR_OPTION_DEFAULT_rtoler
#define DIRDYN_INTEGRATOR_OPTION_DEFAULT_rtoler
Definition: mbs_dirdyn_struct.h:29
MbsDirdyn::finish_integrator
finish_integrator_ptr finish_integrator
pointer to integrator closing function
Definition: mbs_dirdyn_struct.h:189
mbs_freeze_jac
int mbs_freeze_jac(int freeze_index, int *next_freeze_index, double x, double h, double y[], double dydx[], int compute_dfdx, double dfdx[], double **dfdy, double dydx_freeze[], double dfdx_freeze[], double **dfdy_freeze, int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *mbs_dd)
Freeze the Jacobian of an integrator structure until mbs_dd->options->n_freeze.
Definition: integrator.c:107
get_dmat_0
double ** get_dmat_0(int nb_r, int nb_c)
create (with memory allocation) a [nb_r times nb_c] matrix of doubles, starting at index 0
Definition: mbs_matrix.c:238
MbsDirdynOptions::dt0
double dt0
initial value of the integration step size, default = 0.001
Definition: mbs_dirdyn_struct.h:45
rk4
int rk4(double y[], double dydx[], int n, double x, double h, double yout[], int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *dd)
Runge Kutta 4 integrator implementation Given values for the variables y[1..n] and their derivatives ...
Definition: rk4.c:21
initialize_rk4
void initialize_rk4(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for RK4 integrator.
Definition: mbs_rk4.c:19
finish_euler_implicit
void finish_euler_implicit(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for Euler Implicit integrator.
Definition: mbs_euler_implicit.c:128
loop_custom
int loop_custom(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf with a custom integrator implemented by the user.
Definition: mbs_custom.c:39
loop_eulerEx
int loop_eulerEx(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_euler_explicit.c:55
mbs_choldc_0
int mbs_choldc_0(double **A, int n)
Compute the Cholesky decomposition of A, i.e.
Definition: cholesky.c:25
mbs_msg
void mbs_msg(char *msg,...)
Send a message.
Definition: mbs_message.c:76
finish_dopri5
void finish_dopri5(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Finalize and clear memory allocated for dopri5 integrator.
Definition: mbs_dopri5.c:64
WMethods
@ WMethods
Definition: integrator.h:29
initialize_rosenbrock
void initialize_rosenbrock(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Rosenbrock integrator.
Definition: mbs_rosenbrock.c:26
finish_integrator_ptr
void(* finish_integrator_ptr)(MbsData *mbs_data, MbsDirdyn *mbs_dd)
end of the integration, free the memory
Definition: integrator.h:41
complex_float::y
float y
Definition: cholesky.c:14
MbsDirdynOptions::n_freeze
int n_freeze
number of time step when the jacobian is freezed (computed once at the start of the n_freeze time ste...
Definition: mbs_dirdyn_struct.h:134
initialize_dopri5
void initialize_dopri5(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Dopri5 integrator.
Definition: mbs_dopri5.c:20
initialize_custom
void initialize_custom(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Custom integrator.
Definition: mbs_custom.c:22
Dopri5
@ Dopri5
Definition: integrator.h:29
complex_double::y
double y
Definition: cholesky.c:15
finish_bader
void finish_bader(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for Bader integrator.
Definition: mbs_bader.c:158
MbsDirdynOptions::toler
double toler
mixed error tolerances [-], default = 1.0e-3
Definition: mbs_dirdyn_struct.h:127
finish_eulerEx
void finish_eulerEx(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for Euler Explicit integrator.
Definition: mbs_euler_explicit.c:116
MbsDirdynOptions::flag_oneshot
int flag_oneshot
1 to compute the derivative function only once (no time integration !), default = 0 The time is the v...
Definition: mbs_dirdyn_struct.h:92
print_warnings_constant_step_integrator
void print_warnings_constant_step_integrator(MbsDirdyn *mbs_dd, char *integrator_name)
Print the warning message, called by print_warnings_integrator for constant step size dt integrators.
Definition: integrator.c:324
finish_rosenbrock
void finish_rosenbrock(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for Rosenbrock integrator.
Definition: mbs_rosenbrock.c:143
AlphaM
@ AlphaM
Definition: integrator.h:29
transpose_dmat_0
void transpose_dmat_0(double **tab_src, double **tab_dest, int nb_r, int nb_c)
Transpose a [nb_r times nb_c] matrix of doubles and store the results in a [y times nb_r] matrix,...
Definition: mbs_matrix.c:440
initialize_bader
void initialize_bader(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Bader integrator.
Definition: mbs_bader.c:23
mbs_message.h
mbs_euler_explicit.h
This header defines global functions for Euler Explicit integrator in C.
_MBS_ERR_LOW_EIG_VAL
#define _MBS_ERR_LOW_EIG_VAL
Low Level error number Eigen value problem = -4.
Definition: mbs_errors_names.h:132
ThetaSC
int ThetaSC(double y[], double dydx[], int n, double x, double h, double yout[], int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *dd)
Unknown integrator.
Definition: thetaSC.c:26
complex_double::x
double x
Definition: cholesky.c:15
MbsData
Definition: mbs_data.h:149
MbsDirdynOptions::rtoler
double rtoler
relative error tolerances [-], default = 1.0e-3
Definition: mbs_dirdyn_struct.h:128
set_integrator
void set_integrator(MbsDirdyn *dd)
Set the function pointer in MbsDirdyn.
Definition: integrator.c:151
MbsDirdynOptions
Structure defining the option of a direct dynamic.
Definition: mbs_dirdyn_struct.h:38
cholsl_0
void cholsl_0(double **a, int n, double *p, double *b, double *x)
Definition: cholsl.c:25
set_integrator
void set_integrator(MbsDirdyn *mbs_dd)
Set the function pointer in MbsDirdyn.
Definition: integrator.c:151
mbs_eig_0
int mbs_eig_0(double **A, int n, double *eval_a, double *eval_b, double **evec_a, double **evec_b)
Compute the eigen values and vector of a matrix with index starting a 0.
Definition: eig_lapack.c:32
integrator.h
This header defines specific integrators functions in C.
w_methods
int w_methods(double y[], double dydx[], int n, double x, double h, double yout[], int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *mbs_dd)
W Methods integrator implementation.
Definition: w_methods.c:27
initialize_w_methods
void initialize_w_methods(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for W Methods integrator.
Definition: mbs_w_methods.c:22
MbsDirdyn::initialize_integrator
initialize_integrator_ptr initialize_integrator
pointer to integrator initialize function
Definition: mbs_dirdyn_struct.h:185
MbsDirdynOptions::integrator
int integrator
Set integrator to use, available value: RK4, Dopri5, Rosenbrock, EulerEx, Eulaire,...
Definition: mbs_dirdyn_struct.h:108
DIRDYN_INTEGRATOR_OPTION_DEFAULT_nmax
#define DIRDYN_INTEGRATOR_OPTION_DEFAULT_nmax
Define of default options for integrator in DirdynStruc.
Definition: mbs_dirdyn_struct.h:27
cholsl
void cholsl(double **a, int n, double p[], double b[], double x[])
Definition: cholsl.c:10
mbs_custom.h
This header defines global functions for custom integrator in C. Advanced user can modify this file.
print_warnings_integrator
void print_warnings_integrator(MbsData *mbs_data, MbsDirdyn *mbs_dd, int type_of_integrator)
Check the options set by user to warn him when he modified an unused option for the integrator.
Definition: integrator.c:250
choldc
int choldc(double **a, int n, double p[])
Compute the Cholesky decomposition of a, i.e.
Definition: choldc.c:25
MbsDirdynOptions::verbose
int verbose
1 to get print indications related to time adaptive integrator, 0 otherwise, default = 1
Definition: mbs_dirdyn_struct.h:110
copy_dvec_0
void copy_dvec_0(double *vec_src, double *vec_dest, int l_v)
Copy the content of a vector (of sizel_v) of doubles to a second vector, starting with index 0.
Definition: mbs_1D_array.c:906
free_dvec_0
void free_dvec_0(double *vec)
release memory for a vector of doubles, starting at index 0
Definition: mbs_1D_array.c:896
mbs_estim_jac_acc
int mbs_estim_jac_acc(double x, double htry, double y[], double dydx[], int compute_dfdx, double dfdx[], double **dfdy, int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *dd)
Evaluate the Jacobian of a function accelerations using finite difference.
Definition: integrator.c:30
mbs_dopri5.h
finish_rk4
void finish_rk4(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for RK4 integrator.
Definition: mbs_rk4.c:108
Custom
@ Custom
Definition: integrator.h:29
RK4
@ RK4
Definition: integrator.h:29
MbsDirdynOptions::atoler
double atoler
absolute error tolerances [-], default = 1.0e-6
Definition: mbs_dirdyn_struct.h:129
MbsDirdyn
General structure of the direct dynamic module.
Definition: mbs_dirdyn_struct.h:144
Rosenbrock
@ Rosenbrock
Definition: integrator.h:29
MbsDirdynOptions::flag_waypoint
int flag_waypoint
1 to use waypoints, 0 otherwise, default =0
Definition: mbs_dirdyn_struct.h:121
euler_implicit
int euler_implicit(double y[], double dydx[], int n, double *x, double h, double yout[], int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), MbsData *s, MbsDirdyn *mbs_dd)
Euler Implicit integrator implementation.
Definition: euler_implicit.c:27
mbs_rk4.h
This header defines global functions for Runge Kutta 4 integrator in C.
loop_dopri5
int loop_dopri5(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_dopri5.c:43
MbsDirdyn::loop_integrator
loop_integrator_ptr loop_integrator
pointer to integrator looping function
Definition: mbs_dirdyn_struct.h:187
MbsDirdyn::options
MbsDirdynOptions * options
structure defining the option of a direct dynamic
Definition: mbs_dirdyn_struct.h:146
initialize_eulerEx
void initialize_eulerEx(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Initialize all needed fields in MbsDirdyn for Euler Explicit integrator.
Definition: mbs_euler_explicit.c:19
mbs_warning_msg
void mbs_warning_msg(char *msg,...)
Send a warning message.
Definition: mbs_message.c:89
finish_custom
void finish_custom(MbsData *mbs_data, MbsDirdyn *mbs_dd)
Finalize and clear memory allocated for Custom integrator.
Definition: mbs_custom.c:115
mbs_aux.h
MbsDirdyn::flag_ongoing_jac_computation
int flag_ongoing_jac_computation
flag is ON (=1) when the implicit integrator is currently computing the jacobian, default is 0.
Definition: mbs_dirdyn_struct.h:179
finish_w_methods
void finish_w_methods(MbsData *mbs_data, MbsDirdyn *dd)
Finalize and clear memory allocated for W Methods integrator.
Definition: mbs_w_methods.c:151
loop_rk4
int loop_rk4(double t0, double tf, MbsData *mbs_data, MbsDirdyn *mbs_dd)
Integrate the motion from t0 to tf.
Definition: mbs_rk4.c:34
_MBS_ERR_LOW_LAPACKE
#define _MBS_ERR_LOW_LAPACKE
Low Level error number problem with Lapacke system resolution = -5.
Definition: mbs_errors_names.h:137
mbs_errors_names.h
rosenbrock
int rosenbrock(int n, int(*derivs)(double, double[], double[], MbsData *, MbsDirdyn *), double *x, double y[], double eps, double hmax, double htry, long nmax, double dydx[], double yscal[], double *hnext, MbsData *s, MbsDirdyn *dd, double *hdid)
Fourth-order Rosenbrock step for integrating stiff problems, with monitoring of local truncation erro...
Definition: rosenbrock.c:103