| 1 |
/* ode-initval/control.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_math.h" |
| 25 |
#include "gsl_errno.h" |
| 26 |
#include "gsl_odeiv.h" |
| 27 |
|
| 28 |
gsl_odeiv_control * |
| 29 |
gsl_odeiv_control_alloc(const gsl_odeiv_control_type * T) |
| 30 |
{ |
| 31 |
gsl_odeiv_control * c = |
| 32 |
(gsl_odeiv_control *) malloc(sizeof(gsl_odeiv_control)); |
| 33 |
|
| 34 |
if(c == 0) |
| 35 |
{ |
| 36 |
GSL_ERROR_NULL ("failed to allocate space for control struct", |
| 37 |
GSL_ENOMEM); |
| 38 |
}; |
| 39 |
|
| 40 |
c->type = T; |
| 41 |
c->state = c->type->alloc(); |
| 42 |
|
| 43 |
if (c->state == 0) |
| 44 |
{ |
| 45 |
free (c); /* exception in constructor, avoid memory leak */ |
| 46 |
|
| 47 |
GSL_ERROR_NULL ("failed to allocate space for control state", |
| 48 |
GSL_ENOMEM); |
| 49 |
}; |
| 50 |
|
| 51 |
return c; |
| 52 |
} |
| 53 |
|
| 54 |
int |
| 55 |
gsl_odeiv_control_init(gsl_odeiv_control * c, |
| 56 |
double eps_abs, double eps_rel, |
| 57 |
double a_y, double a_dydt) |
| 58 |
{ |
| 59 |
return c->type->init (c->state, eps_abs, eps_rel, a_y, a_dydt); |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
gsl_odeiv_control_free(gsl_odeiv_control * c) |
| 64 |
{ |
| 65 |
c->type->free(c->state); |
| 66 |
free(c); |
| 67 |
} |
| 68 |
|
| 69 |
const char * |
| 70 |
gsl_odeiv_control_name(const gsl_odeiv_control * c) |
| 71 |
{ |
| 72 |
return c->type->name; |
| 73 |
} |
| 74 |
|
| 75 |
int |
| 76 |
gsl_odeiv_control_hadjust (gsl_odeiv_control * c, gsl_odeiv_step * s, const double y[], const double yerr[], const double dydt[], double * h) |
| 77 |
{ |
| 78 |
return c->type->hadjust(c->state, s->dimension, s->type->order(s->state), |
| 79 |
y, yerr, dydt, h); |
| 80 |
} |