RACIPELIB.c
// solve the ODE by 1st Euler method
solve the ODE by 1st Euler method
solve the ODE by 1st Euler method
void solve_ODE_euler (int j, struct opts *simu_opts, struct topo *topoinfo, struct rlt *tmprlt)
{
  int    n_step     = 1000;
  int    i_step     = 1;
  int    i          = 0;
  double testdelta  = 0.0;
  double t          = 0.0;
  double t_start    = 0.0;
  double t_stop     = 0.0;
  double *y;
  double *yp;
  double *ytmp;
  y     = (double *)calloc(topoinfo->numG,      sizeof(double));
  yp    = (double *)calloc(topoinfo->numG,      sizeof(double));
  ytmp  = (double *)calloc(topoinfo->numG,      sizeof(double));
  for (i = 0; i < topoinfo->numG; i++){
    ytmp[i] = 2000.0;
  }
  int cnt_loop = 0;
  RIVs(y, ytmp, tmprlt->paras, topoinfo);
  testdelta = sumdelta(y, ytmp, topoinfo->numG);
  while (testdelta != 0 && cnt_loop < simu_opts->maxiters) {
    t_start = t_stop;
    t_stop  = t_stop + 100;
    cnt_loop = cnt_loop + 1;
    for ( i_step = 1; i_step <= n_step; i_step++ )
    { 
      for (i = 0; i < topoinfo->numG; i++){
          ytmp[i] = y[i];
      }
      model_ODE ( t, ytmp, yp, tmprlt->paras, topoinfo );
      for (i = 0; i < topoinfo->numG; i++){
              y[i] = ytmp[i] + yp[i]*simu_opts->stepsize;
          }
          t = t + simu_opts->stepsize;
      }
      testdelta = sumdelta(y, ytmp, topoinfo->numG);
    }
  for (i = 0; i < topoinfo->numG; i++){
    tmprlt->y_store[topoinfo->numG*j + i] = y[i];
  }
  free(y);
  free(yp);
  free(ytmp);
}
void solve_ODE_euler ( int j , struct opts * simu_opts , struct topo * topoinfo , struct rlt * tmprlt ) { int n_step = 1000 ; int i_step = 1 ; int i = 0 ; double testdelta = 0.0 ; double t = 0.0 ; double t_start = 0.0 ; double t_stop = 0.0 ; double * y ; double * yp ; double * ytmp ; y = ( double * ) calloc ( topoinfo -> numG , sizeof ( double ) ) ; yp = ( double * ) calloc ( topoinfo -> numG , sizeof ( double ) ) ; ytmp = ( double * ) calloc ( topoinfo -> numG , sizeof ( double ) ) ; for ( i = 0 ; i < topoinfo -> numG ; i ++ ) { ytmp [ i ] = 2000.0 ; } int cnt_loop = 0 ; RIVs ( y , ytmp , tmprlt -> paras , topoinfo ) ; testdelta = sumdelta ( y , ytmp , topoinfo -> numG ) ; while ( testdelta != 0 && cnt_loop < simu_opts -> maxiters ) { t_start = t_stop ; t_stop = t_stop + 100 ; cnt_loop = cnt_loop + 1 ; for ( i_step = 1 ; i_step <= n_step ; i_step ++ ) { for ( i = 0 ; i < topoinfo -> numG ; i ++ ) { ytmp [ i ] = y [ i ] ; } model_ODE ( t , ytmp , yp , tmprlt -> paras , topoinfo ) ; for ( i = 0 ; i < topoinfo -> numG ; i ++ ) { y [ i ] = ytmp [ i ] + yp [ i ] * simu_opts -> stepsize ; } t = t + simu_opts -> stepsize ; } testdelta = sumdelta ( y , ytmp , topoinfo -> numG ) ; } for ( i = 0 ; i < topoinfo -> numG ; i ++ ) { tmprlt -> y_store [ topoinfo -> numG * j + i ] = y [ i ] ; } free ( y ) ; free ( yp ) ; free ( ytmp ) ; }
solve the ODE by 1st Euler method
solve the ODE by 1st Euler method