From 47ea0f25eed9ab4a9bcdb4da2cf573a26883f9d4 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 25 Feb 2012 12:36:30 +0100 Subject: odeSolveV with safe method interface --- lib/Numeric/GSL/gsl-aux.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'lib/Numeric/GSL/gsl-aux.c') diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c index bf3f684..f74e2e3 100644 --- a/lib/Numeric/GSL/gsl-aux.c +++ b/lib/Numeric/GSL/gsl-aux.c @@ -1325,16 +1325,12 @@ int ode(int method, double h, double eps_abs, double eps_rel, case 5 : {T = gsl_odeiv2_step_rk2imp; break; } case 6 : {T = gsl_odeiv2_step_rk4imp; break; } case 7 : {T = gsl_odeiv2_step_bsimp; break; } - case 8 : {T = gsl_odeiv2_step_msadams; break; } - case 9 : {T = gsl_odeiv2_step_msbdf; break; } + case 8 : {T = gsl_odeiv2_step_rk1imp; break; } + case 9 : {T = gsl_odeiv2_step_msadams; break; } + case 10: {T = gsl_odeiv2_step_msbdf; break; } default: ERROR(BAD_CODE); } - - gsl_odeiv2_step * s = gsl_odeiv2_step_alloc (T, xin); - gsl_odeiv2_control * c = gsl_odeiv2_control_y_new (eps_abs, eps_rel); - gsl_odeiv2_evolve * e = gsl_odeiv2_evolve_alloc (xin); - Tode P; P.f = f; P.j = jac; @@ -1342,10 +1338,14 @@ int ode(int method, double h, double eps_abs, double eps_rel, gsl_odeiv2_system sys = {odefunc, odejac, xin, &P}; + gsl_odeiv2_driver * d = + gsl_odeiv2_driver_alloc_y_new (&sys, T, h, eps_abs, eps_rel); + double t = tsp[0]; double* y = (double*)calloc(xin,sizeof(double)); int i,j; + int status; for(i=0; i< xin; i++) { y[i] = xip[i]; solp[i] = xip[i]; @@ -1354,22 +1354,24 @@ int ode(int method, double h, double eps_abs, double eps_rel, for (i = 1; i < tsn ; i++) { double ti = tsp[i]; - while (t < ti) - { - gsl_odeiv2_evolve_apply (e, c, s, - &sys, - &t, ti, &h, - y); - // if (h < hmin) h = hmin; - } + + status = gsl_odeiv2_driver_apply (d, &t, ti, y); + + if (status != GSL_SUCCESS) { + printf ("error in ode, return value=%d\n", status); + break; + } + +// printf ("%.5e %.5e %.5e\n", t, y[0], y[1]); + for(j=0; j