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

outside memory allocation dopri5

parent ca2ef461
......@@ -69,6 +69,16 @@ 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->realtime = 1;
mbs_run_dirdyn(mbs_dirdyn, mbs_data);
mbs_delete_dirdyn(mbs_dirdyn, mbs_data);
......
......@@ -22,6 +22,8 @@
#include "set_output.h"
#include "dopri5.h"
#define DOPRI5_NB_ALLOC_VEC 8 ///< number of vectors to allocate for dopri5
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
MbsDirdyn* mbs_new_dirdyn(MbsData* mbs_data){
......@@ -251,6 +253,7 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
FILE *animFile;
FILE *fileout_dopri5;
int i;
double **dopri5_alloc_tab;
// NUMERICAL INTEGRATION
// - - - - - - - - - - -
......@@ -266,12 +269,29 @@ void mbs_dirdyn_loop(MbsDirdyn* dd, MbsData* mbs_data){
fileout_dopri5 = NULL;
}
// allocated vectors for dopri5
dopri5_alloc_tab = (double**) malloc(DOPRI5_NB_ALLOC_VEC*sizeof(double*));
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
dopri5_alloc_tab[i] = (double*) malloc (dd->nState*sizeof(double));
}
dopri5(dd->nState, mbs_fct_dirdyn, dd->options->t0, dd->y, dd->options->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, dd->options->dt0, dd->options->adapt_nmax, 1, 0, 0, NULL, 0, mbs_data, dd);
0, solout_dopri5, 1, fileout_dopri5, 0.0, 0.0, 0.0, 0.0, 0.0, dd->options->adapt_dt_max, dd->options->dt0, dd->options->adapt_nmax,
1, 0, 0, NULL, 0, dopri5_alloc_tab, mbs_data, dd);
// release memory allocated for dopri5 vectors
for(i=0; i<DOPRI5_NB_ALLOC_VEC; i++)
{
free(dopri5_alloc_tab[i]);
}
free(dopri5_alloc_tab);
}
else
{
while(dd->tsim < dd->options->tf){
while(dd->tsim < dd->options->tf)
{
// user loop
user_loop(mbs_data, dd);
......
......@@ -107,10 +107,6 @@ 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;
......
......@@ -9,7 +9,7 @@
static long nfcn, nstep, naccpt, nrejct;
static double hout, xold, xout;
static unsigned nrds, *indir;
static double *yy1, *k1, *k2, *k3, *k4, *k5, *k6, *ysti;
double *yy1, *k1, *k2, *k3, *k4, *k5, *k6, *ysti;
static double *rcont1, *rcont2, *rcont3, *rcont4, *rcont5;
......@@ -446,13 +446,13 @@ static int dopcor (unsigned n, FcnEqDiff fcn, double x, double* y, double xend,
/* front-end */
// modif: MbsData *s, MbsDirdyn *dd added
// modif: double **dopri5_alloc_tab, MbsData *s, MbsDirdyn *dd added
int dopri5
(unsigned n, FcnEqDiff fcn, double x, double* y, double xend, double* rtoler,
double* atoler, int itoler, SolTrait solout, int iout, FILE* fileout, double uround,
double safe, double fac1, double fac2, double beta, double hmax, double h,
long nmax, int meth, long nstiff, unsigned nrdens, unsigned* icont, unsigned licont,
MbsData *s, MbsDirdyn *dd)
double **dopri5_alloc_tab, MbsData *s, MbsDirdyn *dd)
{
int arret, idid;
unsigned i;
......@@ -597,14 +597,14 @@ int dopri5
hmax = xend - x;
/* is there enough free memory for the method ? */
yy1 = (double*) malloc (n*sizeof(double));
k1 = (double*) malloc (n*sizeof(double));
k2 = (double*) malloc (n*sizeof(double));
k3 = (double*) malloc (n*sizeof(double));
k4 = (double*) malloc (n*sizeof(double));
k5 = (double*) malloc (n*sizeof(double));
k6 = (double*) malloc (n*sizeof(double));
ysti = (double*) malloc (n*sizeof(double));
yy1 = dopri5_alloc_tab[0];
k1 = dopri5_alloc_tab[1];
k2 = dopri5_alloc_tab[2];
k3 = dopri5_alloc_tab[3];
k4 = dopri5_alloc_tab[4];
k5 = dopri5_alloc_tab[5];
k6 = dopri5_alloc_tab[6];
ysti = dopri5_alloc_tab[7];
if (!yy1 || !k1 || !k2 || !k3 || !k4 || !k5 || !k6 || !ysti)
{
......@@ -616,22 +616,7 @@ int dopri5
/* when a failure has occured, we return -1 */
if (arret)
{
if (ysti)
free (ysti);
if (k6)
free (k6);
if (k5)
free (k5);
if (k4)
free (k4);
if (k3)
free (k3);
if (k2)
free (k2);
if (k1)
free (k1);
if (yy1)
free (yy1);
/* modif: remove yy1, k1, k2, k3, k4, k5, k6, ysti memory release (free) */
if (indir)
free (indir);
if (rcont5)
......@@ -651,14 +636,9 @@ int dopri5
{
idid = dopcor (n, fcn, x, y, xend, hmax, h, rtoler, atoler, itoler, fileout,
solout, iout, nmax, uround, meth, nstiff, safe, beta, fac1, fac2, icont, s, dd); // modif: s and dd added
free (ysti);
free (k6);
free (k5); /* reverse order freeing too increase chances */
free (k4); /* of efficient dynamic memory managing */
free (k3);
free (k2);
free (k1);
free (yy1);
/* modif: remove yy1, k1, k2, k3, k4, k5, k6, ysti memory release (free) */
if (indir)
free (indir);
if (rcont5)
......
......@@ -212,8 +212,9 @@ extern int dopri5
unsigned nrdens, /* number of components for which dense outpout is required */
unsigned* icont, /* indexes of components for which dense output is required, >= nrdens */
unsigned licont, /* declared length of icon */
MbsData *s, /* Robotran main fields */
MbsDirdyn *dd /* direct dynamics */
double **dopri5_alloc_tab, /* modif: tabular of allocated vectors */
MbsData *s, /* modif: Robotran main fields */
MbsDirdyn *dd /* modif: direct dynamics */
); // modif: MbsData *s, MbsDirdyn *dd added
extern double contd5
......
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