| 1 | /* ode-initval/odeiv.c |
| 2 | * |
| 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | /* Author: G. Jungman |
| 21 | */ |
| 22 | #include "gsl__config.h" |
| 23 | #include <stdlib.h> |
| 24 | #include "gsl_errno.h" |
| 25 | #include "gsl_odeiv.h" |
| 26 | |
| 27 | gsl_odeiv_step * |
| 28 | gsl_odeiv_step_alloc(const gsl_odeiv_step_type * T, size_t dim) |
| 29 | { |
| 30 | gsl_odeiv_step *s = (gsl_odeiv_step *) malloc (sizeof (gsl_odeiv_step)); |
| 31 | |
| 32 | if (s == 0) |
| 33 | { |
| 34 | GSL_ERROR_NULL ("failed to allocate space for ode struct", GSL_ENOMEM); |
| 35 | }; |
| 36 | |
| 37 | s->type = T; |
| 38 | s->dimension = dim; |
| 39 | |
| 40 | s->state = s->type->alloc(dim); |
| 41 | |
| 42 | if (s->state == 0) |
| 43 | { |
| 44 | free (s); /* exception in constructor, avoid memory leak */ |
| 45 | |
| 46 | GSL_ERROR_NULL ("failed to allocate space for ode state", GSL_ENOMEM); |
| 47 | }; |
| 48 | |
| 49 | return s; |
| 50 | } |
| 51 | |
| 52 | const char * |
| 53 | gsl_odeiv_step_name(const gsl_odeiv_step * s) |
| 54 | { |
| 55 | return s->type->name; |
| 56 | } |
| 57 | |
| 58 | unsigned int |
| 59 | gsl_odeiv_step_order(const gsl_odeiv_step * s) |
| 60 | { |
| 61 | return s->type->order(s->state); |
| 62 | } |
| 63 | |
| 64 | int |
| 65 | gsl_odeiv_step_apply( |
| 66 | gsl_odeiv_step * s, |
| 67 | double t, |
| 68 | double h, |
| 69 | double y[], |
| 70 | double yerr[], |
| 71 | const double dydt_in[], |
| 72 | double dydt_out[], |
| 73 | const gsl_odeiv_system * dydt) |
| 74 | { |
| 75 | return s->type->apply(s->state, s->dimension, t, h, y, yerr, dydt_in, dydt_out, dydt); |
| 76 | } |
| 77 | |
| 78 | int |
| 79 | gsl_odeiv_step_reset(gsl_odeiv_step * s) |
| 80 | { |
| 81 | return s->type->reset(s->state, s->dimension); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | gsl_odeiv_step_free(gsl_odeiv_step * s) |
| 86 | { |
| 87 | s->type->free(s->state); |
| 88 | free(s); |
| 89 | } |