-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDVODEu4cc.pas
2753 lines (2727 loc) · 70.6 KB
/
DVODEu4cc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit DVODEu4cc;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
// VODE: A Variable Coefficient ODE Solver
// Lawrence Livermore National Laboratory
interface
uses classes;
const
MaxSteps=5000;
// MaxSteps=1073741823;//MaxInt div 2
MaxNEQ=500;
// MaxArrayLength=22+9*MaxNEQ+2*MaxNEQ*MaxNEQ;
MaxArrayLength=35+9*MaxNEQ+3*MaxNEQ*MaxNEQ;
type
integertype=Longint;
realtype=double;
realarraytype=array[1..MaxArrayLength] of realtype;
integerarraytype=array[1..MaxArrayLength] of integertype;
TsubNoParms=procedure;
Tdydt4vode=procedure(const NEQ: integertype;var T: realtype;
var Y, YDOT: realtype;
var RPAR: realtype;var IPAR: integertype) of object;
Tdfdy4vode=procedure(const NEQ: integertype;var T: realtype;var Y: realtype;
var ML: integertype;var MU: integertype;var PD: realtype;var NRPD: integertype;
var RPAR: realtype;var IPAR: integertype) of object;
TDVSTEP_VNLS_TYPE =procedure(var x1;var x2;const x3: integertype;var x4;var x5;var
x6;var x7;var x8;var x9;x10: Tdydt4vode;x11: Tdfdy4vode;x12: pointer;
var x13: integertype;var x14;var x15);
TVodeSolver=class
private
protected
procedure dydt(const NEQ: integertype;var T: realtype;var Y_, YDOT_: realtype;
var RPAR_: realtype;var IPAR_: integertype);
procedure dfdy(const NEQ: integertype;var T: realtype;var Y_: realtype;
var ML: integertype;var MU: integertype;var PD_: realtype;var NRPD: integertype;
var RPAR: realtype;var IPAR: integertype);
public
constructor Create;
end;
TTestVodeSolver=class(TVodeSolver)
private
public
procedure dydt(const NEQ: integertype;var T: realtype;var Y_, YDOT_: realtype;
var RPAR_: realtype;var IPAR_: integertype);
procedure dfdy(const NEQ: integertype;var T: realtype;var Y_: realtype;
var ML: integertype;var MU: integertype;var PD_: realtype;var NRPD: integertype;
var RPAR: realtype;var IPAR: integertype);
end;
// procedure TestDVODE;
procedure DVODE(
F_: Tdydt4vode;
const NEQ: integertype{constant};
var Y_;
var T: realtype;
var TOUT: realtype{constant};
var ITOL: integertype{constant};
var RTOL_;
var ATOL_;
var ITASK: integertype{constant};
var ISTATE: integertype;
var IOPT: integertype{constant};
var RWORK_:realtype;
var LRW: integertype{constant};
var IWORK_:integertype;
var LIW: integertype{constant};
JAC_: Tdfdy4vode;
var MF: integertype{constant};
var RPAR_:realtype;
var IPAR_:integertype);
//qqqq test
var
StdOut: TStringList;
I_TEST: integer;
Y_TEST: realtype;
AbortVODE: Boolean;
implementation
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType, LMessages,
{$ENDIF}
math, Sysutils, Dialogs, Forms;
type{records for common blocks}
COMMON_DVOD01_=record
ACNRM: realtype;{1}
CCMXJ: realtype;{9}
CONP: realtype;{17}
CRATE: realtype;{25}
DRC: realtype;{33}
EL: array[1..13] of realtype;{41}
ETA: realtype;{145}
ETAMAX: realtype;{153}
H: realtype;{161}
HMIN: realtype;{169}
HMXI: realtype;{177}
HNEW: realtype;{185}
HSCAL: realtype;{193}
PRL1: realtype;{201}
RC: realtype;{209}
RL1: realtype;{217}
TAU: array[1..13] of realtype;{225}
TQ: array[1..5] of realtype;{329}
TN: realtype;{369}
UROUND: realtype;{377}
ICF: integertype;{385}
INIT: integertype;{389}
IPUP: integertype;{393}
JCUR: integertype;{397}
JSTART: integertype;{401}
JSV: integertype;{405}
KFLAG: integertype;{409}
KUTH: integertype;{413}
L: integertype;{417}
LMAX: integertype;{421}
LYH: integertype;{425}
LEWT: integertype;{429}
LACOR: integertype;{433}
LSAVF: integertype;{437}
LWM: integertype;{441}
LIWM: integertype;{445}
// qq not translated
LOCJS: integertype;{449}
MAXORD: integertype;{453}
METH: integertype;{457}
MITER: integertype;{461}
MSBJ: integertype;{465}
MXHNIL: integertype;{469}
MXSTEP: integertype;{473}
N: integertype;{477}
NEWH: integertype;{481}
NEWQ: integertype;{485}
NHNIL: integertype;{489}
NQ: integertype;{493}
NQNYH: integertype;{497}
NQWAIT: integertype;{501}
NSLJ: integertype;{505}
NSLP: integertype;{509}
NYH: integertype;{513}
end;
COMMON_DVOD02_=record
HU: realtype;{1}
NCFN: integertype;{9}
NETF: integertype;{13}
NFE: integertype;{17}
NJE: integertype;{21}
NLU: integertype;{25}
NNI: integertype;{29}
NQU: integertype;{33}
NST: integertype;{37}
end;
var
{Warning: size of integer: 4, real: 8!}
COMMON_DVOD01: array[1..517] of byte;
COMMON_DVOD02: array[1..40] of byte;
procedure TTestVodeSolver.dfdy(const NEQ: integertype;var T: realtype;var Y_: realtype;
var ML: integertype;var MU: integertype;var PD_: realtype;var NRPD: integertype;
var RPAR: realtype;var IPAR: integertype);
var
PD: realarraytype absolute PD_;
Y: realarraytype absolute Y_;
function PDind(const I1, I2: integertype): integertype;
begin
Result:= (I2-1)*NEQ+I1;
end;
begin
PD[PDind(1, 1)]:= -0.04;
PD[PDind(1, 2)]:= 1.E4*Y[3];
PD[PDind(1, 3)]:= 1.E4*Y[2];
PD[PDind(2, 1)]:= 0.04;
PD[PDind(2, 3)]:= -PD[PDind(1, 3)];
PD[PDind(3, 2)]:= 6.E7*Y[2];
PD[PDind(2, 2)]:= -PD[PDind(1, 2)]-PD[PDind(3, 2)];
//C PD(1,1) = -.04D0
//C PD(1,2) = 1.D4*Y(3)
//C PD(1,3) = 1.D4*Y(2)
//C PD(2,1) = .04D0
//C PD(2,3) = -PD(1,3)
//C PD(3,2) = 6.D7*Y(2)
//C PD(2,2) = -PD(1,2) - PD(3,2)
end;
procedure TTestVodeSolver.dydt(const NEQ: integertype;var T, Y_, YDOT_,
RPAR_: realtype;var IPAR_: integertype);
var
Y: realarraytype absolute Y_;
YDOT: realarraytype absolute YDOT_;
RFAR: realarraytype absolute RPAR_;
IPAR: integerarraytype absolute IPAR_;
begin
I_TEST:= Floor(YDOT[1]);
YDOT[1]:= -0.04*Y[1]+1.E4*Y[2]*Y[3];
YDOT[3]:= 3.E7*Y[2]*Y[2];
YDOT[2]:= -1.0*YDOT[1]-1.0*YDOT[3];
//C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3)
//C YDOT(3) = 3.D7*Y(2)*Y(2)
//C YDOT(2) = -YDOT(1) - YDOT(3)
end;
function RE_(const RR: integertype): realtype;
begin
Result:= 1.0*RR;
end;
function max0(x1, x2: integertype): integertype;
begin
if x1>=x2 then
max0:= x1
else
max0:= x2;
end;
function min0(x1, x2: integertype): integertype;
begin
if x1>=x2 then
min0:= x2
else
min0:= x1;
end;
function rrpowr(x1, x2: realtype): realtype;
begin
if x2=0 then begin rrpowr:= 1;
exit;
end;
if (X1=0)and(X2>0) then rrpowr:= 0 else rrpowr:= exp(ln(x1)*x2);
end;
function ripowr(x1: realtype;x2: integertype): realtype;
var
x: realtype;
i, j: integertype;
begin
if x2=0 then begin ripowr:= 1;
exit;
end;
i:= abs(x2);
x:= x1;
for j:= 1 to i-1 do x:= x*x1;
if x2>=0 then ripowr:= x else ripowr:= 1/x;
end;
function SIGN(const A, B: integertype): integertype; overload;
begin
if B>=0 then
Result:= A
else
Result:= -A;
end;
function SIGN(const A: integertype;B: realtype): integertype; overload;
begin
if B>=0 then
Result:= A
else
Result:= -A;
end;
function SIGN(const A, B: realtype): realtype; overload;
begin
if B>=0 then
Result:= A
else
Result:= -A;
end;
{========== Conversion of DVODE.FOR ==========}
// {$B-}{$F+ Far Calls }{$I-}{$N+ 8087 }{$R-}{$V-}{compiler options}
{$BOOLEVAL OFF}
{$IOCHECKS OFF}
{$RANGECHECKS OFF}
{$VARSTRINGCHECKS OFF}
{$ALIGN OFF}// Eu
//Convertion
{*DECK D1MACH}
function D1MACH(
const IDUM: integertype{constant}): realtype;
{---------- Local variables ----------}
var
COMP, U: realtype;
label
10;
{========== Body of converted D1MACH.FOR ==========}
begin
{C-----------------------------------------------------------------------}
{C This routine computes the unit roundoff of the machine.}
U:= 1.0E0;
10: U:= U*0.5E0;
COMP:= 1.0E0+U;
if (COMP<>1.0E0) then goto 10;
Result:= U*2.0E0;
EXIT;
end;
{========== Conversion of DCOPY.FOR ==========}
procedure DCOPY(
{Warning: Check up parameters: VAR or not}
const N: integertype{constant};
var DX_;
const INCX: integertype{constant};
var DY_;
const INCY: integertype{constant});
{---------- Local variables ----------}
var
DX: realarraytype absolute DX_{ [1*(*-1+1);] elements };
DY: realarraytype absolute DY_{ [1*(*-1+1);] elements };
I, IX, IY, M, MP1: integertype;
label
20, 40;
{========== Body of converted DCOPY.FOR ==========}
begin
{c}
{c copies a vector, x, to a vector, y.}
if (N<=0) then EXIT;
if (INCX=1)and(INCY=1) then goto 20;
{c}
{c code for unequal increments or equal increments}
{c not equal to 1}
{c}
IX:= 1;
IY:= 1;
if (INCX<0) then IX:= (-N+1)*INCX+1;
if (INCY<0) then IY:= (-N+1)*INCY+1;
for I:= 1 to N do {10}
begin
DY[IY]:= DX[IX];
IX:= IX+INCX;
IY:= IY+INCY;
end;{10}
EXIT;
20: M:= ((N)mod(7));
if (M=0) then goto 40;
for I:= 1 to M do DY[I]:= DX[I];
if (N<7) then EXIT;
40: MP1:= M+1;
I:= MP1;
while ((I>=MP1)and(I<=N))or((I>=N)and(I<=MP1)) do {50}
begin
DY[I]:= DX[I];
DY[I+1]:= DX[I+1];
DY[I+2]:= DX[I+2];
DY[I+3]:= DX[I+3];
DY[I+4]:= DX[I+4];
DY[I+5]:= DX[I+5];
DY[I+6]:= DX[I+6];
I:= I+7;
end;{50}
EXIT;
end;
{========== Conversion of DEWSET.FOR ==========}
{*DECK DEWSET}
procedure DEWSET(
const N: integertype{constant};
const ITOL: integertype{constant};
var RTOL_;
var ATOL_;
var YCUR_;
var EWT_);
var
RTOL: realarraytype absolute RTOL_{ [1*(*-1+1);] elements };
ATOL: realarraytype absolute ATOL_{ [1*(*-1+1);] elements };
YCUR: realarraytype absolute YCUR_{ [N] elements };
EWT: realarraytype absolute EWT_{ [N] elements };
I: integertype;
label
10, 20, 30, 40;
begin
{C This subroutine sets the error weight vector EWT according to ITOL}
{C EWT(i) = RTOL(i)*abs(YCUR(i)) + ATOL(i), i = 1,...,N,}
if ITOL=1 then goto 10;// Same For all
if ITOL=2 then goto 20;
if ITOL=3 then goto 30;
if ITOL=4 then goto 40;
10: {CONTINUE};
for I:= 1 to N do EWT[I]:= RTOL[1]*ABS(YCUR[I])+ATOL[1];
EXIT;
20: {CONTINUE};
for I:= 1 to N do EWT[I]:= RTOL[1]*ABS(YCUR[I])+ATOL[I];
EXIT;
30: {CONTINUE};
for I:= 1 to N do EWT[I]:= RTOL[I]*ABS(YCUR[I])+ATOL[1];
EXIT;
40: {CONTINUE};
for I:= 1 to N do EWT[I]:= RTOL[I]*ABS(YCUR[I])+ATOL[I];
EXIT;
{C----------------------- End of Subroutine DEWSET ----------------------}
end;
procedure DSCAL(
const N: integertype{constant};
const DA: realtype{constant};
var DX_;
const INCX: integertype{constant});
var
DX: realarraytype absolute DX_{ [1] elements };
I, M, MP1, NINCX: integertype;
label
20, 40;
begin
{c scales a vector by a constant.}
if (N<=0) then EXIT;
if (INCX=1) then goto 20;
NINCX:= N*INCX;
I:= 1;
while ((I>=1)and(I<=NINCX))or((I>=NINCX)and(I<=1)) do {10}
begin
DX[I]:= DA*DX[I];
I:= I+INCX;
end;{10}
EXIT;
{c clean-up loop}
20: M:= ((N)mod(5));
if (M=0) then goto 40;
for I:= 1 to M do DX[I]:= DA*DX[I];
if (N<5) then EXIT;
40: MP1:= M+1;
I:= MP1;
while ((I>=MP1)and(I<=N))or((I>=N)and(I<=MP1)) do {50}
begin
DX[I]:= DA*DX[I];
DX[I+1]:= DA*DX[I+1];
DX[I+2]:= DA*DX[I+2];
DX[I+3]:= DA*DX[I+3];
DX[I+4]:= DA*DX[I+4];
I:= I+5;
end;{50}
EXIT;
end;
function DVNORM(
const N: integertype{constant};
var V_;
var W_): realtype;
var
V: realarraytype absolute V_{ [N] elements };
W: realarraytype absolute W_{ [N] elements };
I: integertype;
SUM: realtype;
begin
{C This function routine computes the weighted root-mean-square norm}
{C of the vector of length N contained in the array V, with weights}
{C contained in the array W of length N..}
{C DVNORM = sqrt( (1/N) * sum( V(i)*W(i) )**2 )}
SUM:= 0.0E0;
for I:= 1 to N do SUM:= SUM+sqr((V[I]*W[I]));
DVNORM:= SQRT(SUM/RE_(N));
EXIT;
end;
procedure DVHIN(
const N: integertype{constant};
const T0: realtype{constant};
var Y0_;
var YDOT_;
F_: Tdydt4vode;
var RPAR_;
var IPAR_;
const TOUT: realtype{constant};
const UROUND: realtype{constant};
var EWT_;
const ITOL: integertype{constant};
var ATOL_;
var Y_;
var TEMP_;
var H0: realtype;
var NITER: integertype;
var IER: integertype);
const
HALF: realtype=0.5;
HUN: realtype=100.;
PT1: realtype=0.1;
TWO: realtype=2.0;
type
DVHIN_F_TYPE=procedure(var x1: integertype;var x2: realtype;var x3;var x4;
var x5;var x6);
{---------- Local variables ----------}
var
Y0: realarraytype absolute Y0_{ [1*(*-1+1);] elements };
YDOT: realarraytype absolute YDOT_{ [1*(*-1+1);] elements };
RPAR: realarraytype absolute RPAR_{ [1*(*-1+1);] elements };
IPAR: integerarraytype absolute IPAR_{ [1*(*-1+1);] elements };
EWT: realarraytype absolute EWT_{ [1*(*-1+1);] elements };
ATOL: realarraytype absolute ATOL_{ [1*(*-1+1);] elements };
Y: realarraytype absolute Y_{ [1*(*-1+1);] elements };
TEMP: realarraytype absolute TEMP_{ [1*(*-1+1);] elements };
AFI, ATOLI, DELYI, H, HG, HLB, HNEW, HRAT, HUB, T1, TDIST, TROUND,
YDDNRM: realtype;
I, ITER: integertype;
F: Tdydt4vode;
label
50, 80, 90, 100;
{========== Body of converted DVHIN.FOR ==========}
begin
F:= F_;
{C This routine computes the step size, H0, to be attempted on the}
{C first step, when the user has not supplied a value for this.}
NITER:= 0;
TDIST:= ABS(TOUT-T0);
TROUND:= UROUND*MAX(ABS(T0), ABS(TOUT));
if (TDIST<TWO*TROUND) then goto 100;
HLB:= HUN*TROUND;
HUB:= PT1*TDIST;
ATOLI:= ATOL[1];
for I:= 1 to N do {10}
begin
if (ITOL=2)or(ITOL=4) then
begin
ATOLI:= ATOL[I];
end;
DELYI:= PT1*ABS(Y0[I])+ATOLI;
AFI:= ABS(YDOT[I]);
if (AFI*HUB>DELYI) then HUB:= DELYI/AFI;
end;{10}
ITER:= 0;
HG:= SQRT(HLB*HUB);
if (HUB<HLB) then
begin
H0:= HG;
goto 90;
end;
50: {CONTINUE};
H:= SIGN(HG, TOUT-T0);
T1:= T0+H;
for I:= 1 to N do Y[I]:= Y0[I]+H*YDOT[I];
F(N, T1, Y[1], TEMP[1], RPAR[1], IPAR[1]);
for I:= 1 to N do TEMP[I]:= (TEMP[I]-YDOT[I])/H;
YDDNRM:= DVNORM(N, TEMP, EWT);
if (YDDNRM*HUB*HUB>TWO) then HNEW:= SQRT(TWO/YDDNRM)
else
begin
HNEW:= SQRT(HG*HUB);
end;
ITER:= ITER+1;
if (ITER>=4) then goto 80;
HRAT:= HNEW/HG;
if ((HRAT>HALF))and((HRAT<TWO)) then goto 80;
if ((ITER>=2))and((HNEW>TWO*HG)) then
begin
HNEW:= HG;
goto 80;
end;
HG:= HNEW;
goto 50;
80: H0:= HNEW*HALF;
if (H0<HLB) then H0:= HLB;
if (H0>HUB) then H0:= HUB;
90: H0:= SIGN(H0, TOUT-T0);
NITER:= ITER;
IER:= 0;
EXIT;
{C Error return for TOUT - T0 too small. --------------------------------}
100: IER:= -1;
EXIT;
end;
procedure DAXPY(
const N: integertype{constant};
const DA: realtype{constant};
var DX_;
const INCX: integertype{constant};
var DY_;
const INCY: integertype{constant});
var
DX: realarraytype absolute DX_{ [1] elements };
DY: realarraytype absolute DY_{ [1] elements };
I, IX, IY, M, MP1: integertype;
label
20, 40;
begin
{c constant times a vector plus a vector.}
if (N<=0) then EXIT;
if (DA=0.0E0) then EXIT;
if (INCX=1)and(INCY=1) then goto 20;
IX:= 1;
IY:= 1;
if (INCX<0) then IX:= (-N+1)*INCX+1;
if (INCY<0) then IY:= (-N+1)*INCY+1;
for I:= 1 to N do {10}
begin
DY[IY]:= DY[IY]+DA*DX[IX];
IX:= IX+INCX;
IY:= IY+INCY;
end;{10}
EXIT;
{c clean-up loop}
20: M:= ((N)mod(4));
if (M=0) then goto 40;
for I:= 1 to M do DY[I]:= DY[I]+DA*DX[I];
if (N<4) then EXIT;
40: MP1:= M+1;
I:= MP1;
while ((I>=MP1)and(I<=N))or((I>=N)and(I<=MP1)) do {50}
begin
DY[I]:= DY[I]+DA*DX[I];
DY[I+1]:= DY[I+1]+DA*DX[I+1];
DY[I+2]:= DY[I+2]+DA*DX[I+2];
DY[I+3]:= DY[I+3]+DA*DX[I+3];
I:= I+4;
end;{50}
EXIT;
end;
procedure DVJUST(
var YH_;
const LDYH: integertype{constant};
const IORD: integertype{constant});
const
ONE: realtype=1.0;
ZERO: realtype=0.0;
var
DVOD01: COMMON_DVOD01_ absolute COMMON_DVOD01;
YH: realarraytype absolute YH_{ [1*(LDYH-1+1)*(*-1+1);] elements };
ALPH0, ALPH1, HSUM, PROD, T1, XI, XIOLD: realtype;
I, IBACK, J, JP1, LP1,
NQM1, NQM2, NQP1: integertype;
label
100, 180, 200, 300, 340;
{Index of element of YH(LDYH,*)}
function YHind(I1, I2: integertype): integertype;
begin
YHind:= (I2-1)*LDYH+I1;
end;
begin
with DVOD01 do {with common blocks}
begin
{C This subroutine adjusts the YH array on reduction of order,}
{C and also when the order is increased for the stiff option (METH = 2).}
if ((NQ=2))and((IORD<>1)) then EXIT;
NQM1:= NQ-1;
NQM2:= NQ-2;
if METH=1 then goto 100;
if METH=2 then goto 200;
{C Nonstiff option...}
100: {CONTINUE};
if (IORD=1) then goto 180;
for J:= 1 to LMAX do EL[J]:= ZERO;
EL[2]:= ONE;
HSUM:= ZERO;
for J:= 1 to NQM2 do {130}
begin
HSUM:= HSUM+TAU[J];
XI:= HSUM/HSCAL;
JP1:= J+1;
for IBACK:= 1 to JP1 do {120}
begin
I:= (J+3)-IBACK;
EL[I]:= EL[I]*XI+EL[I-1];
end;{120}
end;{130}
for J:= 2 to NQM1 do EL[J+1]:= RE_(NQ)*EL[J]/RE_(J);
for J:= 3 to NQ do {170}
begin
for I:= 1 to N do {160}
begin
YH[YHind(I, J)]:= YH[YHind(I, J)]-YH[YHind(I, L)]*EL[J];
end;{160}
end;{170}
EXIT;
180: {CONTINUE};
LP1:= L+1;
for I:= 1 to N do YH[YHind(I, LP1)]:= ZERO;
EXIT;
{C Stiff option...}
200: {CONTINUE};
if (IORD=1) then goto 300;
for J:= 1 to LMAX do EL[J]:= ZERO;
EL[3]:= ONE;
HSUM:= ZERO;
for J:= 1 to NQM2 do {230}
begin
HSUM:= HSUM+TAU[J];
XI:= HSUM/HSCAL;
JP1:= J+1;
for IBACK:= 1 to JP1 do {220}
begin
I:= (J+4)-IBACK;
EL[I]:= EL[I]*XI+EL[I-1];
end;{220}
end;{230}
for J:= 3 to NQ do {250}
begin
for I:= 1 to N do {240}
begin
YH[YHind(I, J)]:= YH[YHind(I, J)]-YH[YHind(I, L)]*EL[J];
end;{240}
end;{250}
EXIT;
300: for J:= 1 to LMAX do EL[J]:= ZERO;
EL[3]:= ONE;
ALPH0:= -ONE;
ALPH1:= ONE;
PROD:= ONE;
XIOLD:= ONE;
HSUM:= HSCAL;
if (NQ=1) then goto 340;
for J:= 1 to NQM1 do {330}
begin
JP1:= J+1;
HSUM:= HSUM+TAU[JP1];
XI:= HSUM/HSCAL;
PROD:= PROD*XI;
ALPH0:= ALPH0-ONE/RE_(JP1);
ALPH1:= ALPH1+ONE/XI;
for IBACK:= 1 to JP1 do {320}
begin
I:= (J+4)-IBACK;
EL[I]:= EL[I]*XIOLD+EL[I-1];
end;{320}
XIOLD:= XI;
end;{330}
340: {CONTINUE};
T1:= (-ALPH0-ALPH1)/PROD;
LP1:= L+1;
for I:= 1 to N do YH[YHind(I, LP1)]:= T1*YH[YHind(I, LMAX)];
NQP1:= NQ+1;
FOR J:=3 TO NQP1 DO DAXPY(N,EL[J],YH[YHind(1,LP1)],1 ,YH[YHind(1,J)], 1);
EXIT;
end;{with common blocks do}
end;
procedure DVSET;
const
CORTES: realtype=0.1E0;
ONE: realtype=1.0;
SIX: realtype=6.0;
TWO: realtype=2.0;
ZERO: realtype=0.0;
var
DVOD01: COMMON_DVOD01_ absolute COMMON_DVOD01;
AHATN0, ALPH0, CNQM1, CSUM, ELP, EM0, FLOTI, FLOTL, FLOTNQ, HSUM, RXI, RXIS,
S, T1, T2, T3, T4, T5, T6, XI: realtype;
EM: array[1..13] of realtype;
I, IBACK, J, JP1,
NQM1, NQM2: integertype;
label
100, 110, 130, 200, 240, 300;
begin
with DVOD01 do {with common blocks}
begin
{C DVSET is called by DVSTEP and sets coefficients for use there.}
FLOTL:= RE_(L);
NQM1:= NQ-1;
NQM2:= NQ-2;
if METH=1 then goto 100;
if METH=2 then goto 200;
100: if (NQ<>1) then goto 110;
EL[1]:= ONE;
EL[2]:= ONE;
TQ[1]:= ONE;
TQ[2]:= TWO;
TQ[3]:= SIX*TQ[2];
TQ[5]:= ONE;
goto 300;
110: HSUM:= H;
EM[1]:= ONE;
FLOTNQ:= FLOTL-ONE;
for I:= 2 to L do EM[I]:= ZERO;
for J:= 1 to NQM1 do {150}
begin
if ((J<>NQM1))or((NQWAIT<>1)) then
begin
goto 130;
end;
S:= ONE;
CSUM:= ZERO;
for I:= 1 to NQM1 do {120}
begin
CSUM:= CSUM+S*EM[I]/RE_(I+1);
S:= -S;
end;{120}
TQ[1]:= EM[NQM1]/(FLOTNQ*CSUM);
130: RXI:= H/HSUM;
for IBACK:= 1 to J do {140}
begin
I:= (J+2)-IBACK;
EM[I]:= EM[I]+EM[I-1]*RXI;
end;{140}
HSUM:= HSUM+TAU[J];
end;{150}
S:= ONE;
EM0:= ZERO;
CSUM:= ZERO;
for I:= 1 to NQ do {160}
begin
FLOTI:= RE_(I);
EM0:= EM0+S*EM[I]/FLOTI;
CSUM:= CSUM+S*EM[I]/(FLOTI+ONE);
S:= -S;
end;{160}
S:= ONE/EM0;
EL[1]:= ONE;
for I:= 1 to NQ do EL[I+1]:= S*EM[I]/RE_(I);
XI:= HSUM/H;
TQ[2]:= XI*EM0/CSUM;
TQ[5]:= XI/EL[L];
if (NQWAIT<>1) then goto 300;
RXI:= ONE/XI;
for IBACK:= 1 to NQ do {180}
begin
I:= (L+1)-IBACK;
EM[I]:= EM[I]+EM[I-1]*RXI;
end;{180}
S:= ONE;
CSUM:= ZERO;
for I:= 1 to L do {190}
begin
CSUM:= CSUM+S*EM[I]/RE_(I+1);
S:= -S;
end;{190}
TQ[3]:= FLOTL*EM0/CSUM;
goto 300;
200: for I:= 3 to L do EL[I]:= ZERO;
EL[1]:= ONE;
EL[2]:= ONE;
ALPH0:= -ONE;
AHATN0:= -ONE;
HSUM:= H;
RXI:= ONE;
RXIS:= ONE;
if (NQ=1) then goto 240;
for J:= 1 to NQM2 do {230}
begin
HSUM:= HSUM+TAU[J];
RXI:= H/HSUM;
JP1:= J+1;
ALPH0:= ALPH0-ONE/RE_(JP1);
for IBACK:= 1 to JP1 do {220}
begin
I:= (J+3)-IBACK;
EL[I]:= EL[I]+EL[I-1]*RXI;
end;{220}
end;{230}
ALPH0:= ALPH0-ONE/RE_(NQ);
RXIS:= -EL[2]-ALPH0;
HSUM:= HSUM+TAU[NQM1];
RXI:= H/HSUM;
AHATN0:= -EL[2]-RXI;
for IBACK:= 1 to NQ do {235}
begin
I:= (NQ+2)-IBACK;
EL[I]:= EL[I]+EL[I-1]*RXIS;
end;{235}
240: T1:= ONE-AHATN0+ALPH0;
T2:= ONE+RE_(NQ)*T1;
TQ[2]:= ABS(ALPH0*T2/T1);
TQ[5]:= ABS(T2/(EL[L]*RXI/RXIS));
if (NQWAIT<>1) then goto 300;
CNQM1:= RXIS/EL[L];
T3:= ALPH0+ONE/RE_(NQ);
T4:= AHATN0+RXI;
ELP:= T3/(ONE-T4+T3);
TQ[1]:= ABS(ELP/CNQM1);
HSUM:= HSUM+TAU[NQ];
RXI:= H/HSUM;
T5:= ALPH0-ONE/RE_(NQ+1);
T6:= AHATN0-RXI;
ELP:= T2/(ONE-T6+T5);
TQ[3]:= ABS(ELP*RXI*(FLOTL+ONE)*T5);
300: TQ[4]:= CORTES*TQ[2];
EXIT;
end;{with common blocks do}
end;
procedure DVSTEP(
var Y_:realtype;
var YH_:realtype;
const LDYH: integertype{constant};
var YH1_:realtype;
var EWT_:realtype;
var SAVF_:realtype;
var VSAV_:realtype;
var ACOR_:realtype;
var WM_:realtype;
var IWM_:integertype;
F_: Tdydt4vode;
JAC_: Tdfdy4vode;
PSOL: Tdydt4vode;
VNLS_: TDVSTEP_VNLS_TYPE;
var RPAR_:realtype;
var IPAR_:integertype);
const
ADDON: realtype=1.0E-6;
BIAS1: realtype=6.0;
BIAS2: realtype=6.0;
BIAS3: realtype=10.0;
ETACF: realtype=0.25;
ETAMIN: realtype=0.1;
ETAMX1: realtype=1.0E4;
ETAMX2: realtype=10.0;
ETAMX3: realtype=10.0;
ETAMXF: realtype=0.2;
ETAQ: realtype=0.0;
ETAQM1: realtype=0.0;
KFC: integertype=-3;
KFH: integertype=-7;
MXNCF: integertype=10;
ONEPSM: realtype=1.00001;
THRESH: realtype=1.5;
ONE: realtype=1.0;
ZERO: realtype=0.0;
var
DVOD01: COMMON_DVOD01_ absolute COMMON_DVOD01;
DVOD02: COMMON_DVOD02_ absolute COMMON_DVOD02;
Y: realarraytype absolute Y_{ [1*(*-1+1);] elements };
YH: realarraytype absolute YH_{ [1*(LDYH-1+1)*(*-1+1);] elements };
YH1: realarraytype absolute YH1_{ [1*(*-1+1);] elements };
EWT: realarraytype absolute EWT_{ [1*(*-1+1);] elements };
SAVF: realarraytype absolute SAVF_{ [1*(*-1+1);] elements };
VSAV: realarraytype absolute VSAV_{ [1*(*-1+1);] elements };
ACOR: realarraytype absolute ACOR_{ [1*(*-1+1);] elements };
WM: realarraytype absolute WM_{ [1*(*-1+1);] elements };
IWM: integerarraytype absolute IWM_{ [1*(*-1+1);] elements };
RPAR: realarraytype absolute RPAR_{ [1*(*-1+1);] elements };
IPAR: integerarraytype absolute IPAR_{ [1*(*-1+1);] elements };
CNQUOT, DDN, DSM, DUP,
ETAQP1, FLOTL, R, TOLD: realtype;
I, I1, I2, IBACK, J, JB,
NCF, NFLAG: integertype;
F: Tdydt4vode;
JAC: Tdfdy4vode;
VNLS: TDVSTEP_VNLS_TYPE;
//qq
TmpI1, TmpI2: integertype;
label
20, 50, 100, 120, 140, 150, 200, 450, 490, 500, 530, 540, 560, 570, 580, 590, 600, 610, 620,
630, 640, 660, 670, 680, 690, 720;
{Index of element of YH(LDYH,*)}
function YHind(I1, I2: integertype): integertype;
begin
YHind:= (I2-1)*LDYH+I1;
end;
begin
with DVOD01 do with DVOD02 do {with common blocks}
begin
// AddEu2
Application.ProcessMessages;
if AbortVODE then exit;
//qqqqq
F:= F_;
JAC:= JAC_;
VNLS:= VNLS_;
PSOL:= nil;// Dummy name...
{C DVSTEP performs one step of the integration of an initial value}
{C problem for a system of ordinary differential equations.}
{C DVSTEP calls subroutine VNLS for the solution of the nonlinear system}
{C arising in the time step. Thus it is independent of the problem}
{C Jacobian structure and the type of nonlinear system solution method.}
{C DVSTEP returns a completion flag KFLAG (in COMMON).}
{C A return with KFLAG = -1 or -2 means either ABS(H) = HMIN or 10}
{C consecutive failures occurred. On a return with KFLAG negative,}
{C the values of TN and the YH array are as of the beginning of the last}
{C step, and H is the last step size attempted.}
{C PSOL = Dummy name for the subroutine passed to VNLS, for}
{C possible use there.}
KFLAG:= 0;
TOLD:= TN;
NCF:= 0;
JCUR:= 0;
NFLAG:= 0;
if (JSTART>0) then goto 20;
if (JSTART=-1) then goto 100;
LMAX:= MAXORD+1;
NQ:= 1;
L:= 2;
NQNYH:= NQ*LDYH;
TAU[1]:= H;
PRL1:= ONE;
RC:= ZERO;
ETAMAX:= ETAMX1;
NQWAIT:= 2;
HSCAL:= H;
goto 200;
20: {CONTINUE};
if (KUTH=1) then
begin
ETA:= MIN(ETA, H/HSCAL);
NEWH:= 1;
end;
50: if (NEWH=0) then goto 200;
if (NEWQ=NQ) then goto 150;
if (NEWQ<NQ) then
begin
DVJUST(YH,LDYH, -1);
NQ:= NEWQ;
L:= NQ+1;
NQWAIT:= L;
goto 150;
end;
if (NEWQ>NQ) then
begin
DVJUST(YH,LDYH, 1);
NQ:= NEWQ;
L:= NQ+1;
NQWAIT:= L;
goto 150;
end;
100: {CONTINUE};
LMAX:= MAXORD+1;
if (N=LDYH) then goto 120;
I1:= 1+(NEWQ+1)*LDYH;
I2:= (MAXORD+1)*LDYH;
if (I1>I2) then goto 120;