Robotran C Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mbs_lapack.h
Go to the documentation of this file.
1 
13 #ifndef MBS_LAPACK_H_
14 #define MBS_LAPACK_H_
15 #include <stdlib.h>
16 #include "mbs_message.h"
17 
18 #ifdef LAPACK_FOUND
19 
24 // necessary for compatibility with VS
25 #if __STDC_VERSION__ < 1999901L
26  struct complex_float { float x, y; };
27  struct complex_double { double x, y; };
28  #define lapack_complex_float struct complex_float
29  #define lapack_complex_double struct complex_double
30 #endif
31 // include lapacke header to get lapack function declaration
32 #include "lapacke.h"
33 
34 #else
35 
36 #define LPK_ERR ">> LAPACK>> "
37 #define LPK_PRE " >> "
38 
39 // Type conversion.
40 #define lapack_int int
41 #define lapack_logical int
42 
43 #define LAPACKE_malloc( size ) malloc( size )
44 #define LAPACKE_free( p ) free( p )
45 
46 typedef lapack_logical (*LAPACK_D_SELECT2) ( const double*, const double* );
47 
48 // Declare fake functions to catch error (alphabetical ordering)
49 static inline void LAPACK_dgees( char* jobvs, char* sort, LAPACK_D_SELECT2 select,
50  lapack_int* n, double* a, lapack_int* lda, lapack_int* sdim,
51  double* wr, double* wi, double* vs, lapack_int* ldvs,
52  double* work, lapack_int* lwork, lapack_logical* bwork,
53  lapack_int *info )
54 {
55  *info = -1;
56  mbs_msg(LPK_ERR"%s()\n"
57  LPK_PRE"Code compiled without LAPACK libraries.\n"
58  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
59  __func__);
60 }
61 
62 static inline void LAPACK_dgeev( char* jobvl, char* jobvr, lapack_int* n, double* a,
63  lapack_int* lda, double* wr, double* wi, double* vl,
64  lapack_int* ldvl, double* vr, lapack_int* ldvr, double* work,
65  lapack_int* lwork, lapack_int *info )
66 {
67  *info = -1;
68  mbs_msg(LPK_ERR"%s()\n"
69  LPK_PRE"Code compiled without LAPACK libraries.\n"
70  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
71  __func__);
72 }
73 
74 static inline void LAPACK_dgelss( lapack_int* m, lapack_int* n, lapack_int* nrhs, double* a,
75  lapack_int* lda, double* b, lapack_int* ldb, double* s,
76  double* rcond, lapack_int* rank, double* work,
77  lapack_int* lwork, lapack_int *info )
78 {
79  *info = -1;
80  mbs_msg(LPK_ERR"%s()\n"
81  LPK_PRE"Code compiled without LAPACK libraries.\n"
82  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
83  __func__);
84 }
85 
86 static inline void LAPACK_dgesvd( char* jobu, char* jobvt, lapack_int* m, lapack_int* n,
87  double* a, lapack_int* lda, double* s, double* u,
88  lapack_int* ldu, double* vt, lapack_int* ldvt, double* work,
89  lapack_int* lwork, lapack_int *info )
90 {
91  *info = -1;
92  mbs_msg(LPK_ERR"%s()\n"
93  LPK_PRE"Code compiled without LAPACK libraries.\n"
94  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
95  __func__);
96 
97 }
98 
99 static inline void LAPACK_dgetrf(lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
100  lapack_int* ipiv, lapack_int *info )
101 {
102  *info = -1;
103  mbs_msg(LPK_ERR"%s()\n"
104  LPK_PRE"Code compiled without LAPACK libraries.\n"
105  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
106  __func__);
107 }
108 
109 static inline void LAPACK_dgetri( lapack_int* n, double* a, lapack_int* lda,
110  const lapack_int* ipiv, double* work, lapack_int* lwork,
111  lapack_int *info )
112 {
113  *info = -1;
114  mbs_msg(LPK_ERR"%s()\n"
115  LPK_PRE"Code compiled without LAPACK libraries.\n"
116  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
117  __func__);
118 }
119 
120 static inline void LAPACK_dpotrf( char* uplo, lapack_int* n, double* a, lapack_int* lda,
121  lapack_int *info )
122 {
123  *info = -1;
124  mbs_msg(LPK_ERR"%s()\n"
125  LPK_PRE"Code compiled without LAPACK libraries.\n"
126  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
127  __func__);
128 }
129 
130 static inline void LAPACK_dpotrs( char* uplo, lapack_int* n, lapack_int* nrhs,
131  const double* a, lapack_int* lda, double* b,
132  lapack_int* ldb, lapack_int *info )
133 {
134  *info = -1;
135  mbs_msg(LPK_ERR"%s()\n"
136  LPK_PRE"Code compiled without LAPACK libraries.\n"
137  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
138  __func__);
139 }
140 
141 static inline void LAPACK_dtrsen( char* job, char* compq, const lapack_logical* select,
142  lapack_int* n, double* t, lapack_int* ldt, double* q,
143  lapack_int* ldq, double* wr, double* wi, lapack_int* m,
144  double* s, double* sep, double* work, lapack_int* lwork,
145  lapack_int* iwork, lapack_int* liwork, lapack_int *info )
146 {
147  *info = -1;
148  mbs_msg(LPK_ERR"%s()\n"
149  LPK_PRE"Code compiled without LAPACK libraries.\n"
150  LPK_PRE"To use this module, compile MBsysC with LAPACK libraries.\n",
151  __func__);
152 }
153 #endif
154 #endif
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:25
GAM
#define GAM
Definition: rosenbrock.c:47
MBS_INFO_FAILURE
#define MBS_INFO_FAILURE
Definition: mbs_define.h:32
mbs_msg
void mbs_msg(const char *msg,...)
Send a message.
Definition: mbs_message.c:87
SAFETY
#define SAFETY
Definition: rosenbrock.c:38
complex_float
Implementation of eig function using lapackE.
Definition: eig_lapacke.c:21
LAPACK_dpotrs
static void LAPACK_dpotrs(char *uplo, lapack_int *n, lapack_int *nrhs, const double *a, lapack_int *lda, double *b, lapack_int *ldb, lapack_int *info)
Definition: mbs_lapack.h:130
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:35
MbsData::qd
double * qd
Array with the current values of the generalized velocities.
Definition: mbs_data.h:286
E4
#define E4
Definition: rosenbrock.c:64
useful_functions.h
C3X
#define C3X
Definition: rosenbrock.c:67
mbs_w_methods.h
This header defines global functions for W methods integrator in C.
lubksb_0
void lubksb_0(double **a, int n, int *indx, double b[])
Definition: lubksb.c:31
B1
#define B1
Definition: rosenbrock.c:57
MbsData::tsim
double tsim
The time value.
Definition: mbs_data.h:306
MbsDirdyn::y
double * y
Pointer to the state vector, this is a dvec_0 of size nState.
Definition: mbs_dirdyn_struct.h:219
GROW
#define GROW
Definition: rosenbrock.c:39
W_S
#define W_S
Definition: mbs_w_methods.h:21
MbsDirdyn::nState
int nState
size of the state vector
Definition: mbs_dirdyn_struct.h:218
C32
#define C32
Definition: rosenbrock.c:53
mbs_dirdyn_struct.h
ERRCON
#define ERRCON
Definition: rosenbrock.c:43
MbsData::nqu
int nqu
Number of independent articulations.
Definition: mbs_data.h:263
mbs_error_msg
void mbs_error_msg(int err, const char *msg,...)
Send an error message.
Definition: mbs_message.c:131
LAPACK_dgeev
static void LAPACK_dgeev(char *jobvl, char *jobvr, lapack_int *n, double *a, lapack_int *lda, double *wr, double *wi, double *vl, lapack_int *ldvl, double *vr, lapack_int *ldvr, double *work, lapack_int *lwork, lapack_int *info)
Definition: mbs_lapack.h:62
C43
#define C43
Definition: rosenbrock.c:56
LPK_ERR
#define LPK_ERR
Definition: mbs_lapack.h:36
mbs_define.h
A32
#define A32
Definition: rosenbrock.c:50
LAPACK_dgelss
static void LAPACK_dgelss(lapack_int *m, lapack_int *n, lapack_int *nrhs, double *a, lapack_int *lda, double *b, lapack_int *ldb, double *s, double *rcond, lapack_int *rank, double *work, lapack_int *lwork, lapack_int *info)
Definition: mbs_lapack.h:74
E1
#define E1
Definition: rosenbrock.c:61
E2
#define E2
Definition: rosenbrock.c:62
A21
#define A21
Definition: rosenbrock.c:48
PSHRNK
#define PSHRNK
Definition: rosenbrock.c:42
mbs_rosenbrock.h
This header defines global functions for rosenbrock integrator in C.
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:129
complex_double
Definition: eig_lapacke.c:22
complex_float::x
float x
Definition: eig_lapacke.c:21
LAPACK_D_SELECT2
lapack_logical(* LAPACK_D_SELECT2)(const double *, const double *)
Definition: mbs_lapack.h:46
MBSfun.h
mbs_close_kin
void mbs_close_kin(MbsData *s, MbsAux *mbs_aux)
compute the dependent velocities that solves the constraints.
Definition: mbs_close_loops.c:146
MbsDirdyn::integrator_struct
void * integrator_struct
pointer to store integrator structure
Definition: mbs_dirdyn_struct.h:262
A3X
#define A3X
Definition: rosenbrock.c:70
C31
#define C31
Definition: rosenbrock.c:52
C1X
#define C1X
Definition: rosenbrock.c:65
ludcmp_0
int ludcmp_0(double **a, int n, int *indx, double *d)
LU decomposition of a matrix with index starting at 0.
Definition: ludcmp.c:82
LAPACK_dgees
static void LAPACK_dgees(char *jobvs, char *sort, LAPACK_D_SELECT2 select, lapack_int *n, double *a, lapack_int *lda, lapack_int *sdim, double *wr, double *wi, double *vs, lapack_int *ldvs, double *work, lapack_int *lwork, lapack_logical *bwork, lapack_int *info)
Definition: mbs_lapack.h:49
LAPACK_dgetrf
static void LAPACK_dgetrf(lapack_int *m, lapack_int *n, double *a, lapack_int *lda, lapack_int *ipiv, lapack_int *info)
Definition: mbs_lapack.h:99
MbsDirdyn::tsim
double tsim
current simulation time
Definition: mbs_dirdyn_struct.h:215
MbsDirdynRK4
Runge-Kutta 4 structure for dirdyn.
Definition: mbs_rk4.h:25
MbsDirdynRosenbrock
Rosenbrock integration structure for dirdyn.
Definition: mbs_rosenbrock.h:23
MbsData::qu
int * qu
Array with the indices of the independent articulations (free)
Definition: mbs_data.h:272
B2
#define B2
Definition: rosenbrock.c:58
C4X
#define C4X
Definition: rosenbrock.c:68
complex_float::y
float y
Definition: eig_lapacke.c:21
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:184
B3
#define B3
Definition: rosenbrock.c:59
MbsData::q
double * q
Array with the current values of the generalized coordinates.
Definition: mbs_data.h:285
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:105
E3
#define E3
Definition: rosenbrock.c:63
LAPACK_dpotrf
static void LAPACK_dpotrf(char *uplo, lapack_int *n, double *a, lapack_int *lda, lapack_int *info)
Definition: mbs_lapack.h:120
complex_double::y
double y
Definition: eig_lapacke.c:22
lapack_logical
#define lapack_logical
Definition: mbs_lapack.h:41
nrfct.h
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:22
mbs_message.h
MbsDirdynWMethods
W Methods structure for dirdyn.
Definition: mbs_w_methods.h:46
_MBS_ERR_MOD_SPEC_14
#define _MBS_ERR_MOD_SPEC_14
Generic error number Module specific errors range from -11 to -19 please read the error message a...
Definition: mbs_errors_names.h:190
mbs_close_geo
int mbs_close_geo(MbsData *s, MbsAux *mbs_aux)
compute a position of the multibody system which solves the constraints
Definition: mbs_close_loops.c:43
LPK_PRE
#define LPK_PRE
Definition: mbs_lapack.h:37
dmaxarg2
static double dmaxarg2
Definition: rosenbrock.c:102
complex_double::x
double x
Definition: eig_lapacke.c:22
_MBS_ERR_MOD_SPEC_18
#define _MBS_ERR_MOD_SPEC_18
Genericerror number Module specific errors range from -11 to -19 please read the error message an...
Definition: mbs_errors_names.h:214
MbsData
Definition: mbs_data.h:247
MbsDirdyn::mbs_aux
MbsAux * mbs_aux
Definition: mbs_dirdyn_struct.h:213
LAPACK_dgesvd
static void LAPACK_dgesvd(char *jobu, char *jobvt, lapack_int *m, lapack_int *n, double *a, lapack_int *lda, double *s, double *u, lapack_int *ldu, double *vt, lapack_int *ldvt, double *work, lapack_int *lwork, lapack_int *info)
Definition: mbs_lapack.h:86
LAPACK_dgetri
static void LAPACK_dgetri(lapack_int *n, double *a, lapack_int *lda, const lapack_int *ipiv, double *work, lapack_int *lwork, lapack_int *info)
Definition: mbs_lapack.h:109
A31
#define A31
Definition: rosenbrock.c:49
dirdynared
int dirdynared(MbsAux *mbs_aux, MbsData *s)
Compute the joint accelerations of the system in the current configuration.
Definition: mbs_dirdynared.c:26
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 *mbs_dd)
Unknown integrator.
Definition: thetaSC.c:25
dmaxarg1
static double dmaxarg1
Definition: rosenbrock.c:102
C2X
#define C2X
Definition: rosenbrock.c:66
integrator.h
This header defines specific integrators functions in C.
dminarg1
static double dminarg1
Definition: rosenbrock.c:103
A2X
#define A2X
Definition: rosenbrock.c:69
SHRNK
#define SHRNK
Definition: rosenbrock.c:41
LAPACK_dtrsen
static void LAPACK_dtrsen(char *job, char *compq, const lapack_logical *select, lapack_int *n, double *t, lapack_int *ldt, double *q, lapack_int *ldq, double *wr, double *wi, lapack_int *m, double *s, double *sep, double *work, lapack_int *lwork, lapack_int *iwork, lapack_int *liwork, lapack_int *info)
Definition: mbs_lapack.h:141
lapack_int
#define lapack_int
Definition: mbs_lapack.h:40
C41
#define C41
Definition: rosenbrock.c:54
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:1100
C42
#define C42
Definition: rosenbrock.c:55
MbsDirdyn
General structure of the direct dynamic module.
Definition: mbs_dirdyn_struct.h:210
mbs_rk4.h
This header defines global functions for Runge Kutta 4 integrator in C.
MbsData::qdd
double * qdd
Array with the current values of the generalized acceleration.
Definition: mbs_data.h:287
C21
#define C21
Definition: rosenbrock.c:51
B4
#define B4
Definition: rosenbrock.c:60
MbsDirdyn::options
MbsDirdynOptions * options
structure defining the option of a direct dynamic
Definition: mbs_dirdyn_struct.h:212
dminarg2
static double dminarg2
Definition: rosenbrock.c:103
MbsData::nhu
int nhu
Number of independent constraints.
Definition: mbs_data.h:269
mbs_errors_names.h
PGROW
#define PGROW
Definition: rosenbrock.c:40