3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
4 * Copyright (C) 2004 Alfonso Acosta & Daniel RodrÃguez
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 /* Authors: Alfonso Acosta & Daniel RodrÃguez
26 #include <gsl/gsl_errno.h>
27 #include <gsl/gsl_odeiv.h>
29 #include "odeiv_util.h"
38 euler_alloc (size_t dim)
40 euler_state_t *state = (euler_state_t *) malloc (sizeof (euler_state_t));
44 GSL_ERROR_NULL ("failed to allocate space for euler_state", GSL_ENOMEM);
47 state->k = (double *) malloc (dim * sizeof (double));
52 GSL_ERROR_NULL ("failed to allocate space for k", GSL_ENOMEM);
60 euler_apply (void *vstate,
66 const double dydt_in[],
68 const gsl_odeiv_system * sys)
70 euler_state_t *state = (euler_state_t *) vstate;
76 double *const k = state->k;
81 DBL_MEMCPY (k, dydt_in, dim);
85 int s = GSL_ODEIV_FN_EVAL (sys, t, y, k);
86 GSL_STATUS_UPDATE (&status, s);
90 for (i = 0; i < dim; i++)
92 temp = y[i]; /* save y[i] */
104 euler_reset (void *vstate, size_t dim)
106 euler_state_t *state = (euler_state_t *) vstate;
108 DBL_ZERO_MEMSET (state->k, dim);
114 euler_order (void *vstate)
116 euler_state_t *state = (euler_state_t *) vstate;
117 state = 0; /* prevent warnings about unused parameters */
122 euler_free (void *vstate)
124 euler_state_t *state = (euler_state_t *) vstate;
129 static const gsl_odeiv_step_type euler_type = { "euler", /* name */
130 1, /* can use dydt_in */
131 0, /* gives exact dydt_out */
139 const gsl_odeiv_step_type *gsl_odeiv_step_euler = &euler_type;