Debian Codegraph @

external/gsl/gsl_ode-initval__evolve.c

raw symbols SCIP
1 /* ode-initval/evolve.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"cxx . . $ `<file>/external/gsl/gsl__config.h`/
23 #include <string.h>
24 #include <stdlib.h>
25 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
26 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
27 #include "gsl_odeiv.h"cxx . . $ `<file>/external/gsl/gsl_odeiv.h`/
28
29 #include "gsl_ode-initval__odeiv_util.h"cxx . . $ `<file>/external/gsl/gsl_ode-initval__odeiv_util.h`/
30
31 gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# *
32 gsl_odeiv_evolve_alloccxx . . $ gsl_odeiv_evolve_alloc(1e23a3e313ed92be). (size_t dim)
33 {
34 gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# *e =
35 (gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve#));
36
37 if (e == 0)
38 {
39 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for evolve struct",
40 GSL_ENOMEM);
41 }
42
43 e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
44
45 if (e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0. == 0)
46 {
47 freecxx . . $ free(5d22bdacc48458e8). (e);
48 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for y0", GSL_ENOMEM);
49 }
50
51 e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
52
53 if (e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr. == 0)
54 {
55 freecxx . . $ free(5d22bdacc48458e8). (e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0.);
56 freecxx . . $ free(5d22bdacc48458e8). (e);
57 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for yerr", GSL_ENOMEM);
58 }
59
60 e->dydt_incxx . . $ $anonymous_type_c944e69215e42634_5#dydt_in. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
61
62 if (e->dydt_incxx . . $ $anonymous_type_c944e69215e42634_5#dydt_in. == 0)
63 {
64 freecxx . . $ free(5d22bdacc48458e8). (e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr.);
65 freecxx . . $ free(5d22bdacc48458e8). (e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0.);
66 freecxx . . $ free(5d22bdacc48458e8). (e);
67 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for dydt_in", GSL_ENOMEM);
68 }
69
70 e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (dim * sizeof (double));
71
72 if (e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out. == 0)
73 {
74 freecxx . . $ free(5d22bdacc48458e8). (e->dydt_incxx . . $ $anonymous_type_c944e69215e42634_5#dydt_in.);
75 freecxx . . $ free(5d22bdacc48458e8). (e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr.);
76 freecxx . . $ free(5d22bdacc48458e8). (e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0.);
77 freecxx . . $ free(5d22bdacc48458e8). (e);
78 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for dydt_out", GSL_ENOMEM);
79 }
80
81 e->dimensioncxx . . $ $anonymous_type_c944e69215e42634_5#dimension. = dim;
82 e->countcxx . . $ $anonymous_type_c944e69215e42634_5#count. = 0;
83 e->failed_stepscxx . . $ $anonymous_type_c944e69215e42634_5#failed_steps. = 0;
84 e->last_stepcxx . . $ $anonymous_type_c944e69215e42634_5#last_step. = 0.0;
85
86 return e;
87 }
88
89 int
90 gsl_odeiv_evolve_resetcxx . . $ gsl_odeiv_evolve_reset(6485bfccbb78094a). (gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# * e)
91 {
92 e->countcxx . . $ $anonymous_type_c944e69215e42634_5#count. = 0;
93 e->failed_stepscxx . . $ $anonymous_type_c944e69215e42634_5#failed_steps. = 0;
94 e->last_stepcxx . . $ $anonymous_type_c944e69215e42634_5#last_step. = 0.0;
95 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
96 }
97
98 void
99 gsl_odeiv_evolve_freecxx . . $ gsl_odeiv_evolve_free(7f51d7295a2ecb9). (gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# * e)
100 {
101 freecxx . . $ free(5d22bdacc48458e8). (e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out.);
102 freecxx . . $ free(5d22bdacc48458e8). (e->dydt_incxx . . $ $anonymous_type_c944e69215e42634_5#dydt_in.);
103 freecxx . . $ free(5d22bdacc48458e8). (e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr.);
104 freecxx . . $ free(5d22bdacc48458e8). (e->y0cxx . . $ $anonymous_type_c944e69215e42634_5#y0.);
105 freecxx . . $ free(5d22bdacc48458e8). (e);
106 }
107
108 /* Evolution framework method.
109 *
110 * Uses an adaptive step control object
111 */
112 int
113 gsl_odeiv_evolve_applycxx . . $ gsl_odeiv_evolve_apply(7d765d0943e7d9ee). (gsl_odeiv_evolvecxx . . $ gsl_odeiv_evolve# * e,
114 gsl_odeiv_controlcxx . . $ gsl_odeiv_control# * con,
115 gsl_odeiv_stepcxx . . $ gsl_odeiv_step# * step,
116 const gsl_odeiv_systemcxx . . $ gsl_odeiv_system# * dydt,
117 double *t, double t1, double *h, double y[])
118 {
119 const double t0 = *t;
120 double h0 = *h;
121 int step_status;
122 int final_step = 0;
123 double dt = t1 - t0; /* remaining time, possibly less than h */
124
125 if (e->dimensioncxx . . $ $anonymous_type_c944e69215e42634_5#dimension. != step->dimensioncxx . . $ $anonymous_type_c944e69215e42634_2#dimension.)
126 {
127 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("step dimension must match evolution size", GSL_EINVAL);
128 }
129
130 if ((dt < 0.0 && h0 > 0.0) || (dt > 0.0 && h0 < 0.0))
131 {
132 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("step direction must match interval direction", GSL_EINVAL);
133 }
134
135 /* No need to copy if we cannot control the step size. */
136
137 if (con != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
138 {
139 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (e->y0, y, e->dimension);
140 }
141
142 /* Calculate initial dydt once if the method can benefit. */
143
144 if (step->typecxx . . $ $anonymous_type_c944e69215e42634_2#type.->can_use_dydt_incxx . . $ $anonymous_type_c944e69215e42634_1#can_use_dydt_in.)
145 {
146 int status = GSL_ODEIV_FN_EVALcxx . . $ `external/gsl/gsl_odeiv.h:67:9`! (dydt, t0, y, e->dydt_in);
147
148 if (status)
149 {
150 return status;
151 }
152 }
153
154 try_step:
155
156 if ((dt >= 0.0 && h0 > dt) || (dt < 0.0 && h0 < dt))
157 {
158 h0 = dt;
159 final_step = 1;
160 }
161 else
162 {
163 final_step = 0;
164 }
165
166 if (step->typecxx . . $ $anonymous_type_c944e69215e42634_2#type.->can_use_dydt_incxx . . $ $anonymous_type_c944e69215e42634_1#can_use_dydt_in.)
167 {
168 step_status =
169 gsl_odeiv_step_applycxx . . $ gsl_odeiv_step_apply(abc4fc936a94a578). (step, t0, h0, y, e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr., e->dydt_incxx . . $ $anonymous_type_c944e69215e42634_5#dydt_in.,
170 e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out., dydt);
171 }
172 else
173 {
174 step_status =
175 gsl_odeiv_step_applycxx . . $ gsl_odeiv_step_apply(abc4fc936a94a578). (step, t0, h0, y, e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out.,
176 dydt);
177 }
178
179 /* Check for stepper internal failure */
180
181 if (step_status != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
182 {
183 *h = h0; /* notify user of step-size which caused the failure */
184 return step_status;
185 }
186
187 e->countcxx . . $ $anonymous_type_c944e69215e42634_5#count.++;
188 e->last_stepcxx . . $ $anonymous_type_c944e69215e42634_5#last_step. = h0;
189
190 if (final_step)
191 {
192 *t = t1;
193 }
194 else
195 {
196 *t = t0 + h0;
197 }
198
199 if (con != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
200 {
201 /* Check error and attempt to adjust the step. */
202 const int hadjust_status
203 = gsl_odeiv_control_hadjustcxx . . $ gsl_odeiv_control_hadjust(dc16cc4ef2e31d28). (con, step, y, e->yerrcxx . . $ $anonymous_type_c944e69215e42634_5#yerr., e->dydt_outcxx . . $ $anonymous_type_c944e69215e42634_5#dydt_out., &h0);
204
205 if (hadjust_status == GSL_ODEIV_HADJ_DECcxx . . $ `external/gsl/gsl_odeiv.h:168:9`!)
206 {
207 /* Step was decreased. Undo and go back to try again. */
208 DBL_MEMCPYcxx . . $ `external/gsl/gsl_ode-initval__odeiv_util.h:1:9`! (y, e->y0, dydt->dimension);
209 e->failed_stepscxx . . $ $anonymous_type_c944e69215e42634_5#failed_steps.++;
210 goto try_step;
211 }
212 }
213
214 *h = h0; /* suggest step size for next time-step */
215
216 return step_status;
217 }