Debian Codegraph @

external/gsl/gsl_ode-initval__gear1.c

raw symbols SCIP
1 /* ode-initval/gear1.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 /* Gear 1. This is the implicit Euler a.k.a backward Euler method. */
21
22 /* Author: G. Jungman
23 */
24
25 /* Error estimation by step doubling, see eg. Ascher, U.M., Petzold,
26 L.R., Computer methods for ordinary differential and
27 differential-algebraic equations, SIAM, Philadelphia, 1998.
28 The method is also described in eg. this reference.
29 */
30
31 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
32 #include <stdlib.h>
33 #include <string.h>
34 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
35 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
36 #include "gsl_odeiv.h"cxx . . $ `<file>/external/gsl/gsl_odeiv.h`/
37
38 #include "gsl_ode-initval__odeiv_util.h"cxx . . $ `<file>/external/gsl/gsl_ode-initval__odeiv_util.h`/
39
40 typedef structcxx . . $ $anonymous_type_8246934be86d91d1_0#
41 {
42 double *kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.;
43 double *y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.;
44 double *y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig.;
45 double *y_onestepcxx . . $ $anonymous_type_8246934be86d91d1_0#y_onestep.;
46 }
47 gear1_state_tcxx . . $ gear1_state_t#;
48
49 static void *
50 gear1_alloccxx . . $ gear1_alloc(bfcfa4d6b7f7ef64). (size_t dim)
51 {
52 gear1_state_tcxx . . $ gear1_state_t# *state = (gear1_state_tcxx . . $ gear1_state_t# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gear1_state_tcxx . . $ gear1_state_t#));
53
54 if (state == 0)
55 {
56 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for gear1_state", GSL_ENOMEM);
57 }
58
59 state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
60
61 if (state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k. == 0)
62 {
63 freecxx . . $ free(5d22bdacc48458e8). (state);
64 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for k", GSL_ENOMEM);
65 }
66
67 state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
68
69 if (state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0. == 0)
70 {
71 freecxx . . $ free(5d22bdacc48458e8). (state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.);
72 freecxx . . $ free(5d22bdacc48458e8). (state);
73 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for y0", GSL_ENOMEM);
74 }
75
76 state->y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
77
78 if (state->y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig. == 0)
79 {
80 freecxx . . $ free(5d22bdacc48458e8). (state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.);
81 freecxx . . $ free(5d22bdacc48458e8). (state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.);
82 freecxx . . $ free(5d22bdacc48458e8). (state);
83 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for y0_orig", GSL_ENOMEM);
84 }
85
86 state->y_onestepcxx . . $ $anonymous_type_8246934be86d91d1_0#y_onestep. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
87
88 if (state->y_onestepcxx . . $ $anonymous_type_8246934be86d91d1_0#y_onestep. == 0)
89 {
90 freecxx . . $ free(5d22bdacc48458e8). (state->y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig.);
91 freecxx . . $ free(5d22bdacc48458e8). (state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.);
92 freecxx . . $ free(5d22bdacc48458e8). (state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.);
93 freecxx . . $ free(5d22bdacc48458e8). (state);
94 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for y_onestep", GSL_ENOMEM);
95 }
96
97 return state;
98 }
99
100 static int
101 gear1_stepcxx . . $ gear1_step(160f76325b0627ee). (double *y, gear1_state_tcxx . . $ gear1_state_t# *state,
102 const double h, const double t,
103 const size_t dim, const gsl_odeiv_systemcxx . . $ gsl_odeiv_system# *sys)
104 {
105 /* Makes an implicit Euler advance with step size h.
106 y0 is the initial values of variables y.
107
108 The implicit matrix equations to solve are:
109
110 k = y0 + h * f(t + h, k)
111
112 y = y0 + h * f(t + h, k)
113 */
114
115 const int iter_steps = 3;
116 int nu;
117 size_t i;
118 double *y0 = state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.;
119 double *k = state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.;
120
121 /* Iterative solution of k = y0 + h * f(t + h, k)
122
123 Note: This method does not check for convergence of the
124 iterative solution!
125 */
126
127 for (nu = 0; nu < iter_steps; nu++)
128 {
129 int s = GSL_ODEIV_FN_EVALcxx . . $ `external/gsl/gsl_odeiv.h:67:9`!(sys, t + h, y, k);
130
131 if (s != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
132 {
133 return s;
134 }
135
136 for (i=0; i<dim; i++)
137 {
138 y[i] = y0[i] + h * k[i];
139 }
140 }
141
142 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
143 }
144
145 static int
146 gear1_applycxx . . $ gear1_apply(46f97775c18f9353).(void * vstate,
147 size_t dim,
148 double t,
149 double h,
150 double y[],
151 double yerr[],
152 const double dydt_in[],
153 double dydt_out[],
154 const gsl_odeiv_systemcxx . . $ gsl_odeiv_system# * sys)
155 {
156 gear1_state_tcxx . . $ gear1_state_t# *state = (gear1_state_tcxx . . $ gear1_state_t# *) vstate;
157
158 size_t i;
159
160 double *y0 = state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.;
161 double *y0_orig = state->y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig.;
162 double *y_onestep = state->y_onestepcxx . . $ $anonymous_type_8246934be86d91d1_0#y_onestep.;
163
164 /* initialization */
165 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`!(y0, y, dim);
166
167 /* Save initial values for possible failures */
168 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y0_orig, y, dim);
169
170 /* First traverse h with one step (save to y_onestep) */
171 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y_onestep, y, dim);
172
173 {
174 int s = gear1_stepcxx . . $ gear1_step(160f76325b0627ee). (y_onestep, state, h, t, dim, sys);
175
176 if (s != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
177 {
178 return s;
179 }
180 }
181
182 /* Then with two steps with half step length (save to y) */
183 {
184 int s = gear1_stepcxx . . $ gear1_step(160f76325b0627ee). (y, state, h / 2.0, t, dim, sys);
185
186 if (s != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
187 {
188 /* Restore original y vector */
189 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y, y0_orig, dim);
190 return s;
191 }
192 }
193
194 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y0, y, dim);
195
196 {
197 int s = gear1_stepcxx . . $ gear1_step(160f76325b0627ee). (y, state, h / 2.0, t + h / 2.0, dim, sys);
198
199 if (s != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
200 {
201 /* Restore original y vector */
202 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y, y0_orig, dim);
203 return s;
204 }
205 }
206
207 /* Cleanup update */
208
209 if (dydt_out != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
210 {
211 int s = GSL_ODEIV_FN_EVALcxx . . $ `external/gsl/gsl_odeiv.h:67:9`! (sys, t + h, y, dydt_out);
212
213 if (s != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
214 {
215 /* Restore original y vector */
216 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y, y0_orig, dim);
217 return s;
218 }
219 }
220
221 /* Error estimation */
222
223 for (i = 0; i < dim; i++)
224 {
225 yerr[i] = 4.0 * (y[i] - y_onestep[i]);
226 }
227
228 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
229 }
230
231 static int
232 gear1_resetcxx . . $ gear1_reset(c0a5f96701d3f89). (void *vstate, size_t dim)
233 {
234 gear1_state_tcxx . . $ gear1_state_t# *state = (gear1_state_tcxx . . $ gear1_state_t# *) vstate;
235
236 DBL_ZERO_MEMSETcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:2:9`! (state->y_onestep, dim);
237 DBL_ZERO_MEMSETcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:2:9`! (state->y0_orig, dim);
238 DBL_ZERO_MEMSETcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:2:9`! (state->y0, dim);
239 DBL_ZERO_MEMSETcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:2:9`! (state->k, dim);
240 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
241 }
242
243 static unsigned int
244 gear1_ordercxx . . $ gear1_order(6769d0e399bf81e3). (void *vstate)
245 {
246 return 1;
247 }
248
249 static void
250 gear1_freecxx . . $ gear1_free(5d22bdacc48458e8). (void *vstate)
251 {
252 gear1_state_tcxx . . $ gear1_state_t# *state = (gear1_state_tcxx . . $ gear1_state_t# *) vstate;
253 freecxx . . $ free(5d22bdacc48458e8). (state->y_onestepcxx . . $ $anonymous_type_8246934be86d91d1_0#y_onestep.);
254 freecxx . . $ free(5d22bdacc48458e8). (state->y0_origcxx . . $ $anonymous_type_8246934be86d91d1_0#y0_orig.);
255 freecxx . . $ free(5d22bdacc48458e8). (state->y0cxx . . $ $anonymous_type_8246934be86d91d1_0#y0.);
256 freecxx . . $ free(5d22bdacc48458e8). (state->kcxx . . $ $anonymous_type_8246934be86d91d1_0#k.);
257 freecxx . . $ free(5d22bdacc48458e8). (state);
258 }
259
260 static const gsl_odeiv_step_typecxx . . $ gsl_odeiv_step_type# gear1_typecxx . . $ gear1_type. = { "gear1", /* name */
261 0, /* can use dydt_in? */
262 1, /* gives exact dydt_out? */
263 &gear1_alloccxx . . $ gear1_alloc(bfcfa4d6b7f7ef64).,
264 &gear1_applycxx . . $ gear1_apply(46f97775c18f9353).,
265 &gear1_resetcxx . . $ gear1_reset(c0a5f96701d3f89).,
266 &gear1_ordercxx . . $ gear1_order(6769d0e399bf81e3).,
267 &gear1_freecxx . . $ gear1_free(5d22bdacc48458e8).
268 };
269
270 const gsl_odeiv_step_typecxx . . $ gsl_odeiv_step_type# *gsl_odeiv_step_gear1cxx . . $ gsl_odeiv_step_gear1. = &gear1_typecxx . . $ gear1_type.;