diff options
author | Alberto Ruiz <aruiz@um.es> | 2012-03-21 19:42:44 +0100 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2012-03-21 19:42:44 +0100 |
commit | d109c791aef6dbb6a15fb65efe5c42121728aed0 (patch) | |
tree | 1a43ebdaea2a25f6c26b1fa25bac41c4516c103a /lib/Numeric/GSL/gsl-aux.c | |
parent | 354d599b56d7bfb2124eb6939d4d87e9efa3faed (diff) |
fall back to old ode if v2 not available
Diffstat (limited to 'lib/Numeric/GSL/gsl-aux.c')
-rw-r--r-- | lib/Numeric/GSL/gsl-aux.c | 87 |
1 files changed, 2 insertions, 85 deletions
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c index 7f1cf68..fc14ff5 100644 --- a/lib/Numeric/GSL/gsl-aux.c +++ b/lib/Numeric/GSL/gsl-aux.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include <gsl/gsl_complex_math.h> | 32 | #include <gsl/gsl_complex_math.h> |
33 | #include <gsl/gsl_rng.h> | 33 | #include <gsl/gsl_rng.h> |
34 | #include <gsl/gsl_randist.h> | 34 | #include <gsl/gsl_randist.h> |
35 | #include <gsl/gsl_odeiv2.h> | ||
36 | #include <gsl/gsl_multifit_nlin.h> | 35 | #include <gsl/gsl_multifit_nlin.h> |
37 | #include <string.h> | 36 | #include <string.h> |
38 | #include <stdio.h> | 37 | #include <stdio.h> |
@@ -1331,89 +1330,7 @@ int random_vector(int seed, int code, RVEC(r)) { | |||
1331 | #undef RAN | 1330 | #undef RAN |
1332 | 1331 | ||
1333 | ////////////////////////////////////////////////////// | 1332 | ////////////////////////////////////////////////////// |
1334 | // ODE | ||
1335 | 1333 | ||
1336 | typedef struct {int n; int (*f)(double,int, const double*, int, double *); int (*j)(double,int, const double*, int, int, double*);} Tode; | 1334 | #include "gsl-ode.c" |
1337 | |||
1338 | int odefunc (double t, const double y[], double f[], void *params) { | ||
1339 | Tode * P = (Tode*) params; | ||
1340 | (P->f)(t,P->n,y,P->n,f); | ||
1341 | return GSL_SUCCESS; | ||
1342 | } | ||
1343 | |||
1344 | int odejac (double t, const double y[], double *dfdy, double dfdt[], void *params) { | ||
1345 | Tode * P = ((Tode*) params); | ||
1346 | (P->j)(t,P->n,y,P->n,P->n,dfdy); | ||
1347 | int j; | ||
1348 | for (j=0; j< P->n; j++) | ||
1349 | dfdt[j] = 0.0; | ||
1350 | return GSL_SUCCESS; | ||
1351 | } | ||
1352 | |||
1353 | |||
1354 | int ode(int method, double h, double eps_abs, double eps_rel, | ||
1355 | int f(double, int, const double*, int, double*), | ||
1356 | int jac(double, int, const double*, int, int, double*), | ||
1357 | KRVEC(xi), KRVEC(ts), RMAT(sol)) { | ||
1358 | |||
1359 | const gsl_odeiv2_step_type * T; | ||
1360 | |||
1361 | switch(method) { | ||
1362 | case 0 : {T = gsl_odeiv2_step_rk2; break; } | ||
1363 | case 1 : {T = gsl_odeiv2_step_rk4; break; } | ||
1364 | case 2 : {T = gsl_odeiv2_step_rkf45; break; } | ||
1365 | case 3 : {T = gsl_odeiv2_step_rkck; break; } | ||
1366 | case 4 : {T = gsl_odeiv2_step_rk8pd; break; } | ||
1367 | case 5 : {T = gsl_odeiv2_step_rk2imp; break; } | ||
1368 | case 6 : {T = gsl_odeiv2_step_rk4imp; break; } | ||
1369 | case 7 : {T = gsl_odeiv2_step_bsimp; break; } | ||
1370 | case 8 : {T = gsl_odeiv2_step_rk1imp; break; } | ||
1371 | case 9 : {T = gsl_odeiv2_step_msadams; break; } | ||
1372 | case 10: {T = gsl_odeiv2_step_msbdf; break; } | ||
1373 | default: ERROR(BAD_CODE); | ||
1374 | } | ||
1375 | |||
1376 | Tode P; | ||
1377 | P.f = f; | ||
1378 | P.j = jac; | ||
1379 | P.n = xin; | ||
1380 | |||
1381 | gsl_odeiv2_system sys = {odefunc, odejac, xin, &P}; | ||
1382 | |||
1383 | gsl_odeiv2_driver * d = | ||
1384 | gsl_odeiv2_driver_alloc_y_new (&sys, T, h, eps_abs, eps_rel); | ||
1385 | |||
1386 | double t = tsp[0]; | ||
1387 | |||
1388 | double* y = (double*)calloc(xin,sizeof(double)); | ||
1389 | int i,j; | ||
1390 | int status; | ||
1391 | for(i=0; i< xin; i++) { | ||
1392 | y[i] = xip[i]; | ||
1393 | solp[i] = xip[i]; | ||
1394 | } | ||
1395 | |||
1396 | for (i = 1; i < tsn ; i++) | ||
1397 | { | ||
1398 | double ti = tsp[i]; | ||
1399 | |||
1400 | status = gsl_odeiv2_driver_apply (d, &t, ti, y); | ||
1401 | |||
1402 | if (status != GSL_SUCCESS) { | ||
1403 | printf ("error in ode, return value=%d\n", status); | ||
1404 | break; | ||
1405 | } | ||
1406 | |||
1407 | // printf ("%.5e %.5e %.5e\n", t, y[0], y[1]); | ||
1408 | |||
1409 | for(j=0; j<xin; j++) { | ||
1410 | solp[i*xin + j] = y[j]; | ||
1411 | } | ||
1412 | } | ||
1413 | |||
1414 | free(y); | ||
1415 | gsl_odeiv2_driver_free (d); | ||
1416 | |||
1417 | return status; | ||
1418 | } | ||
1419 | 1335 | ||
1336 | ////////////////////////////////////////////////////// | ||