25
25
#include "sunmatrix/sunmatrix_dense.h"
26
26
27
27
#if defined(SUNDIALS_EXTENDED_PRECISION )
28
- #define GSYM "Lg "
28
+ #define FMT "-7.4Lg "
29
29
#else
30
- #define GSYM "g "
30
+ #define FMT "-7.4g "
31
31
#endif
32
32
33
33
#define ZERO SUN_RCONST(0.0)
@@ -58,14 +58,15 @@ int main(int argc, char* argv[])
58
58
59
59
int flag = 0 ;
60
60
int cvode_flag = 0 ;
61
- int i = 0 ;
62
61
sunrealtype tout = SUN_RCONST (0.10 );
63
62
sunrealtype dt_tout = SUN_RCONST (0.25 );
64
63
sunrealtype tstop = SUN_RCONST (0.30 );
65
64
sunrealtype dt_tstop = SUN_RCONST (0.30 );
66
65
sunrealtype tret = ZERO ;
67
66
sunrealtype tcur = ZERO ;
68
67
68
+ long int num_steps = 0 ;
69
+
69
70
/* --------------
70
71
* Create context
71
72
* -------------- */
@@ -116,15 +117,140 @@ int main(int argc, char* argv[])
116
117
flag = CVodeSetStopTime (cvode_mem , tstop );
117
118
if (flag ) { return 1 ; }
118
119
119
- /* ---------------
120
- * Advance in time
121
- * --------------- */
120
+ /* -------------------
121
+ * Forward Integration
122
+ * ------------------- */
123
+
124
+ printf ("0: tout = %" FMT " tstop = %" FMT " tret = %" FMT
125
+ " tcur = %" FMT " steps = 0\n" ,
126
+ tout , tstop , tret , tcur );
127
+
128
+ for (int i = 1 ; i <= 6 ; i ++ )
129
+ {
130
+ cvode_flag = CVode (cvode_mem , tout , y , & tret , CV_NORMAL );
131
+ if (cvode_flag < 0 )
132
+ {
133
+ flag = 1 ;
134
+ break ;
135
+ }
136
+
137
+ flag = CVodeGetCurrentTime (cvode_mem , & tcur );
138
+ if (flag ) { break ; }
139
+
140
+ flag = CVodeGetNumSteps (cvode_mem , & num_steps );
141
+ if (flag ) { break ; }
142
+
143
+ printf ("%i: tout = %" FMT " tstop = %" FMT " tret = %" FMT
144
+ " tcur = %" FMT " steps = %3li return = %i\n" ,
145
+ i , tout , tstop , tret , tcur , num_steps , cvode_flag );
146
+
147
+ /* First return: output time < stop time < current time -- should return at
148
+ the output time */
149
+ if (i == 1 && cvode_flag != CV_SUCCESS )
150
+ {
151
+ printf ("ERROR: Expected output return!\n" );
152
+ flag = 1 ;
153
+ break ;
154
+ }
155
+
156
+ /* Second return: output time > stop time = current time -- should return at
157
+ the stop time */
158
+ if (i == 2 )
159
+ {
160
+ if (cvode_flag != CV_TSTOP_RETURN )
161
+ {
162
+ printf ("ERROR: Expected stop return!\n" );
163
+ flag = 1 ;
164
+ break ;
165
+ }
166
+
167
+ /* Update stop time */
168
+ tstop += dt_tstop ;
169
+ flag = CVodeSetStopTime (cvode_mem , tstop );
170
+ if (flag ) { break ; }
171
+ }
172
+
173
+ /* Third return: output time = stop time = current time -- should return at
174
+ the stop time */
175
+ if (i == 3 )
176
+ {
177
+ if (cvode_flag != CV_TSTOP_RETURN )
178
+ {
179
+ printf ("ERROR: Expected stop return!\n" );
180
+ flag = 1 ;
181
+ break ;
182
+ }
183
+
184
+ /* Update stop time */
185
+ tstop += dt_tstop ;
186
+ flag = CVodeSetStopTime (cvode_mem , tstop );
187
+ if (flag ) { break ; }
188
+ }
189
+
190
+ /* Fourth return: output time < stop time = current time and the output time
191
+ is overtaken in the same step that the stop time is reached -- should
192
+ return at the output time with current time == stop time */
193
+ if (i == 4 )
194
+ {
195
+ if (cvode_flag != CV_SUCCESS )
196
+ {
197
+ printf ("ERROR: Expected output return!\n" );
198
+ flag = 1 ;
199
+ break ;
200
+ }
201
+ }
202
+
203
+ /* Fifth return: output time > stop time = current time and the stop time
204
+ was already reached but we did not return at that time because of an
205
+ earlier output time return -- should return at the stop time without
206
+ taking a step */
207
+ if (i == 5 )
208
+ {
209
+ if (cvode_flag != CV_TSTOP_RETURN )
210
+ {
211
+ printf ("ERROR: Expected stop return!\n" );
212
+ flag = 1 ;
213
+ break ;
214
+ }
215
+ }
216
+
217
+ /* Sixth return: current time > output time > stop time (not updated) --
218
+ should return at the output time */
219
+ if (i == 6 && cvode_flag != CV_SUCCESS )
220
+ {
221
+ printf ("ERROR: Expected output return!\n" );
222
+ flag = 1 ;
223
+ break ;
224
+ }
225
+
226
+ /* update output time */
227
+ tout += dt_tout ;
228
+ }
229
+
230
+ /* --------------------
231
+ * Backward Integration
232
+ * -------------------- */
233
+
234
+ N_VConst (ONE , y );
235
+
236
+ CVodeReInit (cvode_mem , ONE , y );
237
+ if (flag ) { return 1 ; }
238
+
239
+ tout = SUN_RCONST (0.30 );
240
+ dt_tout = - dt_tout ;
241
+ tstop = SUN_RCONST (0.10 );
242
+ dt_tstop = - dt_tstop ;
243
+ tret = ZERO ;
244
+ tcur = ZERO ;
245
+
246
+ flag = CVodeSetStopTime (cvode_mem , tstop );
247
+ if (flag ) { return 1 ; }
122
248
123
- printf ("0: tout = %" GSYM ", tstop = %" GSYM ", tret = %" GSYM
124
- ", tcur = %" GSYM " \n" ,
249
+ printf ("0: tout = %" FMT " tstop = %" FMT " tret = %" FMT
250
+ " tcur = %" FMT " steps = 0 \n" ,
125
251
tout , tstop , tret , tcur );
126
252
127
- for (i = 1 ; i <= 6 ; i ++ )
253
+ for (int i = 1 ; i <= 6 ; i ++ )
128
254
{
129
255
cvode_flag = CVode (cvode_mem , tout , y , & tret , CV_NORMAL );
130
256
if (cvode_flag < 0 )
@@ -136,9 +262,9 @@ int main(int argc, char* argv[])
136
262
flag = CVodeGetCurrentTime (cvode_mem , & tcur );
137
263
if (flag ) { break ; }
138
264
139
- printf ("%i: tout = %" GSYM ", tstop = %" GSYM ", tret = %" GSYM
140
- ", tcur = %" GSYM ", return = %i\n" ,
141
- i , tout , tstop , tret , tcur , cvode_flag );
265
+ printf ("%i: tout = %" FMT " tstop = %" FMT " tret = %" FMT
266
+ " tcur = %" FMT " steps = %3li return = %i\n" ,
267
+ i , tout , tstop , tret , tcur , num_steps , cvode_flag );
142
268
143
269
/* First return: output time < stop time */
144
270
if (i == 1 && cvode_flag != CV_SUCCESS )
0 commit comments