summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/gsl-aux.c
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2012-02-25 12:36:30 +0100
committerAlberto Ruiz <aruiz@um.es>2012-02-25 12:36:30 +0100
commit47ea0f25eed9ab4a9bcdb4da2cf573a26883f9d4 (patch)
treeb91e101621e6a352bfeef68a1fe0a31df8684065 /lib/Numeric/GSL/gsl-aux.c
parentb67148cf9e97a259c398280493829fc3cbed6582 (diff)
odeSolveV with safe method interface
Diffstat (limited to 'lib/Numeric/GSL/gsl-aux.c')
-rw-r--r--lib/Numeric/GSL/gsl-aux.c40
1 files changed, 21 insertions, 19 deletions
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,
1325 case 5 : {T = gsl_odeiv2_step_rk2imp; break; } 1325 case 5 : {T = gsl_odeiv2_step_rk2imp; break; }
1326 case 6 : {T = gsl_odeiv2_step_rk4imp; break; } 1326 case 6 : {T = gsl_odeiv2_step_rk4imp; break; }
1327 case 7 : {T = gsl_odeiv2_step_bsimp; break; } 1327 case 7 : {T = gsl_odeiv2_step_bsimp; break; }
1328 case 8 : {T = gsl_odeiv2_step_msadams; break; } 1328 case 8 : {T = gsl_odeiv2_step_rk1imp; break; }
1329 case 9 : {T = gsl_odeiv2_step_msbdf; break; } 1329 case 9 : {T = gsl_odeiv2_step_msadams; break; }
1330 case 10: {T = gsl_odeiv2_step_msbdf; break; }
1330 default: ERROR(BAD_CODE); 1331 default: ERROR(BAD_CODE);
1331 } 1332 }
1332 1333
1333
1334 gsl_odeiv2_step * s = gsl_odeiv2_step_alloc (T, xin);
1335 gsl_odeiv2_control * c = gsl_odeiv2_control_y_new (eps_abs, eps_rel);
1336 gsl_odeiv2_evolve * e = gsl_odeiv2_evolve_alloc (xin);
1337
1338 Tode P; 1334 Tode P;
1339 P.f = f; 1335 P.f = f;
1340 P.j = jac; 1336 P.j = jac;
@@ -1342,10 +1338,14 @@ int ode(int method, double h, double eps_abs, double eps_rel,
1342 1338
1343 gsl_odeiv2_system sys = {odefunc, odejac, xin, &P}; 1339 gsl_odeiv2_system sys = {odefunc, odejac, xin, &P};
1344 1340
1341 gsl_odeiv2_driver * d =
1342 gsl_odeiv2_driver_alloc_y_new (&sys, T, h, eps_abs, eps_rel);
1343
1345 double t = tsp[0]; 1344 double t = tsp[0];
1346 1345
1347 double* y = (double*)calloc(xin,sizeof(double)); 1346 double* y = (double*)calloc(xin,sizeof(double));
1348 int i,j; 1347 int i,j;
1348 int status;
1349 for(i=0; i< xin; i++) { 1349 for(i=0; i< xin; i++) {
1350 y[i] = xip[i]; 1350 y[i] = xip[i];
1351 solp[i] = xip[i]; 1351 solp[i] = xip[i];
@@ -1354,22 +1354,24 @@ int ode(int method, double h, double eps_abs, double eps_rel,
1354 for (i = 1; i < tsn ; i++) 1354 for (i = 1; i < tsn ; i++)
1355 { 1355 {
1356 double ti = tsp[i]; 1356 double ti = tsp[i];
1357 while (t < ti) 1357
1358 { 1358 status = gsl_odeiv2_driver_apply (d, &t, ti, y);
1359 gsl_odeiv2_evolve_apply (e, c, s, 1359
1360 &sys, 1360 if (status != GSL_SUCCESS) {
1361 &t, ti, &h, 1361 printf ("error in ode, return value=%d\n", status);
1362 y); 1362 break;
1363 // if (h < hmin) h = hmin; 1363 }
1364 } 1364
1365// printf ("%.5e %.5e %.5e\n", t, y[0], y[1]);
1366
1365 for(j=0; j<xin; j++) { 1367 for(j=0; j<xin; j++) {
1366 solp[i*xin + j] = y[j]; 1368 solp[i*xin + j] = y[j];
1367 } 1369 }
1368 } 1370 }
1369 1371
1370 free(y); 1372 free(y);
1371 gsl_odeiv2_evolve_free (e); 1373 gsl_odeiv2_driver_free (d);
1372 gsl_odeiv2_control_free (c); 1374
1373 gsl_odeiv2_step_free (s); 1375 return status;
1374 return 0;
1375} 1376}
1377