-
Notifications
You must be signed in to change notification settings - Fork 0
/
bim_NoWrite.f
1928 lines (1752 loc) · 58.7 KB
/
bim_NoWrite.f
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
c Minor modification
c 2 Aug 2011
c Write statements during execution have been commented out; however, incorrect
c input parameter writes have been left in. Search for "jjv"
C -----------------------------------------------------------------------------------
C THE CODE BIM NUMERICALLY SOLVES (STIFF) DIFFERENTIAL ODE
C PROBLEMS.
C
C Copyright (C)2002-2007
C
C Authors: CECILIA MAGHERINI ([email protected])
C LUIGI BRUGNANO ([email protected])
C
C
C This program is free software; you can redistribute it and/or
C modify it under the terms of the GNU General Public License
C as published by the Free Software Foundation; either version 2
C of the License, or (at your option) any later version.
C
C This program is distributed in the hope that it will be useful,
C but WITHOUT ANY WARRANTY; without even the implied warranty of
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
C GNU General Public License for more details.
C
C Licensed under The GNU General Public License, Version 2 or later.
C http://www.gnu.org/licenses/info/GPLv2orLater.html
C
C You should have received a copy of the GNU General Public License
C along with this program; if not, write to the Free Software
C Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
C USA.
C -----------------------------------------------------------------------------------
SUBROUTINE BIM(M,FCN,T0,TEND,Y0,H,RTOL,ATOL,
& JAC,IJAC,MLJAC,MUJAC,
& WORK,LWORK,IWORK,LIWORK,
& RPAR,IPAR,IOUT,IDID)
C -----------------------------------------------------------------------------------
C -----------------------------------------------------------------------------------
C
C PURPOSE: BIM SOLVES A (STIFF) DIFFERENTIAL ODE PROBLEM,
C --------
C Y' = F(T,Y), T0<=T<=TEND,
C Y(T0) = Y0,
C
C BY MEANS OF BLENDED IMPLICIT METHODS.
C BLENDED IMPLICIT METHODS ARE A CLASS OF BLOCK
C METHODS PROVIDING A (RELATIVELY) EASY DEFINITION
C OF SUITABLE NONLINEAR SPLITTINGS FOR SOLVING THE
C CORRESPONDING DISCRETE PROBLEMS [1,4-6].
C THE CODE BIM IMPLEMENTS A VARIABLE STEPSIZE-
C VARIABLE ORDER METHOD. ORDERS: 4-6-8-10-12.
C IMPLEMENTATION DETAILS ARE IN REFERENCES [1-4].
C
C
C AUTHORS: L.BRUGNANO
C -------- DIPARTIEMNTO DI MATEMATICA "U.DINI"
C VIALE MORGAGNI 67/A
C 50134 FIRENZE
C ITALY
C E-MAIL: [email protected]
C
C C.MAGHERINI,
C DIPARTIMENTO DI MATEMATICA APPLICATA "U.DINI"
C VIA BUONARROTI, 1/C
C 56127 PISA
C ITALY
C E-MAIL: [email protected]
C
C
C
C CODE HOME PAGE: http://www.math.unifi.it/~brugnano/BiM/index.html
C ---------------
C
C CODE: THE CODE IS MADE UP OF THREE FILES:
C ----- - BIM.F (I.E. THE PRESENT FILE) WHICH CONTAINS THE MAIN
C INTEGRATION PROCEDURE
C - SUBBIM.F CONTAINING ADDITIONAL AND LINEAR ALGEBRA
C PROCEDURES
C - PARAM.DAT CONTAINING VARIOUS PARAMETERS USED IN THE CODE
C
C CURRENT RELEASE: 2.0, APRIL 4, 2005.
C ----------------
C
C REL.HISTORY: 1.0 fall of 2002
C ------------ - pre-release;
C 1.1 June 18, 2003
C - first version released;
C 1.1.1 July 20, 2003
C - minor bugs fixed;
C 1.1.2 October 31, 2003
C - criterion to recognize slowly varying solutions modified;
C 2.0 april 4, 2005
C - order 14 method removed,
C - slightly modification of the I/O interface,
C - bug in the order reduction recovery fixed,
C - some minor changes in the order variation strategy.
C
C REFERENCES:
C -----------
C [1] L.BRUGNANO, C.MAGHERINI
C The BiM code for the numerical solution of ODEs
C Jour. CAM 164-165 (2004) 145-158.
C
C [2] L.BRUGNANO, C.MAGHERINI
C Some Linear Algebra issues concerning the implementation
C of Blended Implicit Methods
C Numer. Linear Alg. Appl. 12 (2005) 305-314.
C
C [3] L.BRUGNANO, C.MAGHERINI
C Economical Error Estimates for Block Implicit Methods for
C ODEs via Deferred Correction.
C Appl. Numer. Math. 56 (2006) 608-617.
C
C [4] L.BRUGNANO, C.MAGHERINI
C Blended Implementation of Block Implicit Methods for ODEs
C Appl. Numer. Math. 42 (2002) 29-45.
C
C [5] L.BRUGNANO, D.TRIGIANTE
C Block Implicit Methods for ODEs
C in "Recent Trends in Numerical Analysis", D.Trigiante Ed.
C Nova Science Publ. Inc., New York, 2001, pp. 81-105.
C
C [6] L.BRUGNANO
C Blended Block BVMs (B$_3$VMs): a Family of economical
C implicit methods for ODEs
C Jour. CAM 116 (2000) 41-62.
C
C
C -----------------------------------------------------------------------------------
C -----------------------------------------------------------------------------------
C
C USAGE:
C ------
C
C CALL BIM(M,FCN,T0,TEND,Y0,H,RTOL,ATOL,JAC,IJAC,MLJAC,MUJAC,
C & WORK,LWORK,IWORK,LIWORK,RPAR,IPAR,IOUT,IDID)
C
C
C NOTE: IN ORDER TO GAIN THE BEST PERFORMANCE, THE EXECUTABLE HAS TO
C ----- BE CREATED WITH THE OPTION ALLOWING TO CONTINUE THE EXECUTION
C AFTER A FLOATING-POINT EXCEPTION (E.G., BY USING THE OPTION
C -FPE; SEE YOUR FORTRAN COMPILER REFERENCE MANUAL).
C THE ISNAN LOGICAL FUNCTION IS REQUIRED, TO RECOGNIZE NANs. IF
C NOT SUPPORTED BY YOUR COMPILER, A STANDARD ONE IS PROVIDED AT
C THE TOP OF THE SUBBIM.F FILE.
C
C
C -----------------------------------------------------------------------------------
C INPUT PARAMETERS
C -----------------------------------------------------------------------------------
C
C M SIZE OF THE PROBLEM
C
C FCN SUBROUTINE WITH THE FUNCTION F(T,Y) TO BE INTEGRATED. IT IS IN THE FORM:
C
C subroutine fcn(m,t,y,dy,ierr,rpar,ipar)
C double precision t,y,dy,rpar(*)
C integer m,ierr,ipar(*)
C dimension y(m),dy(m)
CC m size of the continuous problem
CC t,y is the point where f is evaluated
CC dy will contain the value of f(t,y)
CC ierr is a return code (0 means OK)
CC rpar possible external real parameters
CC ipar possible external integer parameters
C ................
C return
C end
C
C
C T0-TEND INTEGRATION INTERVAL
C
C Y0 INITIAL CONDITION
C
C H INITIAL STEPSIZE
C
C RTOL-ATOL RELATIVE AND ABSOLUTE TOLERANCES
C
C JAC SUBROUTINE EVALUATING THE JACOBIAN OF F (DUMMY, IF IJAC=0).
C IF IJAC .NE. 0, IT IS IN THE FORM:
C
C subroutine jac(m,t,y,jac,ldjac,ierr,rpar,ipar)
C double precision t,y,jac,rpar(*)
C integer neqn,ldjac,ierr,ipar(*)
C dimension y(m),jac(ldjac,m)
CC m size of the continuous problem
CC t,y is the point where the Jacobian is evaluated
CC jac will contain the value of the Jacobian at (t,y)
CC ldjac leading dimension of the array ldjac
CC ierr is a return code (0 means OK)
CC rpar possible external real parameters
CC ipar possible external integer parameters
C ............
C return
C end
C
C
C IJAC FLAG: 0=NUMERICAL JACOBIAN, ANALYTICAL OTHERWISE
C
C MLJAC-MUJAC LOWER-UPPER BANDWIDTH OF THE JACOBIAN (MLJAC=M IF FULL JACOBIAN)
C
C LWORK LENGTH OF WORK ( LWORK >= 14 +KMAX +8*M +4*KMAX*M +M*(LDJAC+LDLU),
C
C WHERE:
C
C LDJAC = LDLU = M, IN CASE OF A FULL JACOBIAN,
C LDJAC = MLJAC+MUJAC+1, LDLU = LDJAC+MLJAC, IN CASE OF A SPARSE JACOBIAN;
C
C KMAX = ORDMAX-2, IF ORDMAX>4,
C 3, IF ORDMAX=4. )
C
C WORK(1) UROUND. MACHINE PRECISION. (DEFAULT = 1.D-16)
C
C WORK(2) HMAX. MAXIMUM INTEGRATION STEP. (DEFAULT = (TEND-T0)/8)
C
C WORK(3) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION.
C METHOD OF ORDER 4. (DEFAULT = 1.D-1)
C
C WORK(4) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION.
C METHOD OF ORDER 6. (DEFAULT = 1.D-1)
C
C WORK(5) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION.
C METHOD OF ORDER 8. (DEFAULT = 1.D-1)
C
C WORK(6) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION.
C METHOD OF ORDER 10. (DEFAULT = 1.D-1)
C
C WORK(7) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION.
C METHOD OF ORDER 12. (DEFAULT = 1.D-1)
C
C WORK(8) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION
C IN CASE OF SMALL VALUES OF min(abs(y_0)), min(abs(f_0)) AND OF max(abs(f_0)).
C (DEFAULT = 5D-3)
C
C WORK(9) FACTOL - SAFETY FACTOR FOR THE STOPPING CRITERION OF THE BLENDLED ITERATION
C IN CASE OF SLOWLY VARYING SOLUTIONS (DEFAULT = 5D-2)
C
C WORK(10)-WORK(11) FACL-FACR. THE NEW STEPSIZE MUST SATISFY
C FACL<=HNEW/HOLD<= FACR.
C (DEFAULT: WORK(10)=1.2D-1, WORK(11)=10D0)
C
C WORK(12) SFTY - SAFETY FACTOR FOR PREDICTING THE NEW STEPSIZE FOR THE CURRENT ORDER
C METHOD. (DEFAULT = 1D0/2D1)
C
C WORK(13) SFTYUP - SAFETY FACTOR FOR PREDICTING THE NEW STEPSIZE FOR THE HIGHER ORDER
C METHOD. (DEFAULT = SFTY/2D0)
C
C WORK(14) SFTYDN - SAFETY FACTOR FOR PREDICTING THE NEW STEPSIZE FOR THE LOWER ORDER
C METHOD. (DEFAULT = SFTY)
C
C LIWORK LENGTH OF IWORK (LIWORK >= M+37)
C
C IWORK(1) MAX NUMBER OF INTEGRATION STEPS (DEFAULT = 100000).
C
C IWORK(2) ORDMIN, 4<=ORDMIN<=12. (DEFAULT = 4).
C
C IWORK(3) ORDMAX, ORDMIN<=ORDMAX<=12. (DEFAULT = 12).
C
C IWORK(4) MAX NUMBER OF BLENDED ITERATIONS PER INTEGRATION STEP, METHOD OF ORDER 4
C (DEFAULT = 10).
C
C IWORK(5) MAX NUMBER OF BLENDED ITERATIONS PER INTEGRATION STEP, METHOD OF ORDER 6
C (DEFAULT = 12).
C
C IWORK(6) MAX NUMBER OF BLENDED ITERATIONS PER INTEGRATION STEP, METHOD OF ORDER 8
C (DEFAULT = 14).
C
C IWORK(7) MAX NUMBER OF BLENDED ITERATIONS PER INTEGRATION STEP, METHOD OF ORDER 10
C (DEFAULT = 16).
C
C IWORK(8) MAX NUMBER OF BLENDED ITERATIONS PER INTEGRATION STEP, METHOD OF ORDER 12
C (DEFAULT = 18).
C
C RPAR,IPAR REAL AND INTEGER PARAMETERS (OR PARAMETER ARRAYS) WHICH
C CAN BE USED FOR COMMUNICATION BETWEEN YOUR CALLING
C PROGRAM AND THE FCN, JAC SUBROUTINES.
C
C IOUT OUTPUT FLAG, SET TO 1, IN CASE OF OUTPUT AT EACH SUCCESFULL STEP.
C IF NOT SET TO 1, THE SUBROUTINE SOLOUT MAY BE DUMMY. OTHERWISE,
C IT MUST BE PROVIDED IN THE FOLLOWING FORM:
C
C subroutine solout(m,t,y,f,k,ord,irtrn)
CC m is the size of the problem
CC (t,y) is the current point
CC f is the derivative of y
CC k is the block-size of the method
CC ord is the order of the method
CC irtrn is a return code (0 means that everything is OK)
C ................
C return
C end
C
C
C -----------------------------------------------------------------------------------
C OUTPUT PARAMETERS
C -----------------------------------------------------------------------------------
C
C
C T0 VALUE OF T UP TO WHERE THE SOLUTION HAS BEEN COMPUTED
C (IF THE INTEGRATION HAS BEEN SUCCESFULL,THEN T0=TEND)
C
C Y0 NUMERICAL SOLUTION AT T0
C
C IDID RETURN CODE:
C 0 SUCCESFULL RUN
C -1 WRONG INPUT PARAMETERS
C -2 A LARGER NMAX IS NEEDED
C -3 STEPSIZE TOO SMALL
C -4 REPEATEDLY SINGULAR MATRIX
C -5 TOO MANY CONSECUTIVE NEWTON FAILURES
C -6 ERROR CODE RETURNED BY THE JAC SUBROUTINE
C OR BY THE FCN SUBROUTINE AT THE STARTING
C POINT
C
C IWORK( 9) NUMBER OF FUNCTION EVALUATIONS
C
C IWORK(10) NUMBER OF JACOBIAN EVALUATIONS
C
C IWORK(11) NUMBER OF LU DECOMPOSITION
C
C IWORK(12) NUMBER OF LINEAR SYSTEMS SOLVED
C
C IWORK(13)-IWORK(17) NUMBER OF BLENDED ITERATIONS PER METHOD
C
C IWORK(18)-IWORK(22) NUMBER OF STEPS PER METHOD
C
C IWORK(23)-IWORK(27) NUMBER OF ACCEPTED STEPS PER METHOD
C
C IWORK(28)-IWORK(32) NUMBER OF REFUSED STEPS PER METHOD (ERROR TEST)
C
C IWORK(33)-IWORK(37) NUMBER OF REFUSED STEPS PER METHOD (NEWTON'S CONVERGENCE)
C
C -----------------------------------------------------------------------------------
C -----------------------------------------------------------------------------------
C
Cc-----------------------------------------------------------------------
Cc Sample driver for the code BIM
Cc-----------------------------------------------------------------------
C program BIMDO
C implicit none
C integer MMAX,lwork,liwork
C parameter(MMAX=3,lwork=24+MMAX*(48+2*MMAX),liwork=MMAX+37)
C double precision y(MMAX),work(lwork)
C integer iwork(lwork),ijac,iout
C external feval, jeval, solout
C character problm*8
C double precision t0,tf,h0,h,rtol,atol,
C & y0(MMAX), rpar(1)
C integer neqn,mljac,mujac,itol,i,ierr, ipar(1)
C integer NSTEPS,NACCEPT,NFAILERR,NFAILNEWT,NITER,idid
Cc-----------------------------------------------------------------------
Cc get the problem dependent parameters
Cc-----------------------------------------------------------------------
C neqn = 3
C t0 = 0d0
C tf = 1d15
C ijac = 1
C mljac = 3
C mujac = 3
C y(1) = 1d0
C y(2) = 0d0
C y(3) = 0d0
C
Cc-----------------------------------------------------------------------
Cc read the tolerances and initial stepsize
Cc-----------------------------------------------------------------------
C write(6,*) 'give the absolute tolerance'
C read(5,*) atol
C write(6,*) 'give the relative tolerance'
C read(5,*) rtol
C write(6,*) 'give the initial stepsize '
C read(5,*) h0
C
C h = h0
C do i=1,8
C iwork(i) = 0
C end do
C do i=1,14
C work(i) = 0d0
C end do
C iout = 0
C idid = 0
C
Cc-----------------------------------------------------------------------
Cc call of the subroutine BIM
Cc-----------------------------------------------------------------------
C call BIM(neqn,feval,t0,tf,y,h,rtol,atol,
C & jeval,ijac,mljac,mujac,
C & work,lwork,iwork,liwork,
C & rpar,ipar,iout,idid)
C if (idid.ne.0) then
C write(6,*) 'ERROR: returned idid =', idid
C goto 20
C endif
Cc-----------------------------------------------------------------------
Cc print final solution
Cc-----------------------------------------------------------------------
C write(6,10)
C 10 format(//)
C
C write(6,11) atol,rtol,h0
C 11 format(/,' we solved the problem with',//,
C + ' absolute tolerance = ',d10.4,',',/,
C + ' relative tolerance = ',d10.4,',',/,
C + ' and initial stepsize = ',d10.4,//)
Cc-----------------------------------------------------------------------
Cc print error with respect to reference solution
Cc-----------------------------------------------------------------------
C NSTEPS = 0
C NACCEPT = 0
C NFAILERR = 0
C NFAILNEWT = 0
C NITER = 0
C DO I=1,5
C NITER = NITER + iwork(I+12)
C NSTEPS = NSTEPS + iwork(I+17)
C NACCEPT = NACCEPT + iwork(I+22)
C NFAILERR = NFAILERR + iwork(I+27)
C NFAILNEWT = NFAILNEWT + iwork(I+32)
C END DO
C
C write(6,41) NSTEPS,IWORK(18),IWORK(19),IWORK(20),IWORK(21),
C & IWORK(22),
C & NACCEPT,NFAILNEWT,NFAILERR,
C & IWORK(9),IWORK(10),IWORK(11),IWORK(12),
C & NITER
C 41 format( ///,
C + ' # Steps = ',i8,/
C + ' # Composition = ',i8,i8,i8,i8,i8,/
C + ' # Accept = ',i8,/,
C + ' # Failnwt = ',i8,/,
C + ' # Failerr = ',i8,/,
C + ' # F-eval = ',i8,/,
C + ' # Jac-eval = ',i8,/,
C + ' # LU-decomp = ',i8,/,
C + ' # Linear systems = ',i8,/,
C + ' # Newt. iterat. = ',i8)
C write(6,*) 'Yf = '
C do i = 1, neqn
C write(6,*) y(i)
C end do
C20 continue
C end
C
Cccccccccccccccccccccccccccccccc AUXILIARY SUBROUTINES
C
C subroutine feval(neqn,t,y,dy,ierr,rpar,ipar)
C integer neqn,ierr,ipar
C double precision t,y(neqn),dy(neqn),rpar
C dy(1) = -.04d0*y(1) + 1.d4*y(2)*y(3)
C dy(3) = 3.d7*y(2)*y(2)
C dy(2) = -dy(1) - dy(3)
C return
C end
C
C subroutine jeval(neqn,t,y,jac,ldim,ierr,rpar,ipar)
C integer neqn,ldim,ierr,ipar
C double precision t,y(neqn),jac(ldim,neqn),rpar
C
C integer i,j
C
C do 20 j=1,neqn
C do 10 i=1,neqn
C jac(i,j)=0d0
C 10 continue
C 20 continue
C
C jac(1,1) = -.04d0
C jac(1,2) = 1.d4*y(3)
C jac(1,3) = 1.d4*y(2)
C jac(2,1) = .04d0
C jac(2,3) = -jac(1,3)
C jac(3,1) = 0.0
C jac(3,2) = 6.d7*y(2)
C jac(3,3) = 0.0
C jac(2,2) = -jac(1,2) - jac(3,2)
C return
C end
C
C subroutine solout(m,t,y,f,k,ord,irtrn)
C implicit none
C integer m,k,ord,irtrn
C double precision t(k),y(m,k),f(m,k)
C integer i,j
C 20 format (e22.16,a1)
C write(20,20) t(k)
C do i=1,m
C write(20,20) y(i,k),' '
C end do
C write(20,30) ' '
C 30 format(A1,/)
C irtrn=0
C return
C end
C
C -----------------------------------------------------------------------------------
C -----------------------------------------------------------------------------------
IMPLICIT NONE
EXTERNAL FCN,JAC
INTEGER M,LWORK,LIWORK,IWORK(LIWORK),
& IJAC,MLJAC,MUJAC,LDJAC,
& LDLU,IJOB,IPAR(*),IOUT,IDID
LOGICAL JBAND
DOUBLE PRECISION T0,TEND,Y0(M),H,RTOL,ATOL,WORK(LWORK),RPAR(*)
INTEGER NMETH,KMAX
PARAMETER (NMETH=5,KMAX=10)
INTEGER MAXSTEP,ORDMIN,ORDMAX,ITMAX(NMETH),STEP_ORD(NMETH),
& NFEVAL,NJEVAL,NLU,NLINSYS,NITER(NMETH),NSTEP(NMETH),
& NACCEPT(NMETH),NFAILERR(NMETH),NFAILNEWT(NMETH)
DOUBLE PRECISION UROUND, FACNEWTV(NMETH),FACNSMALL,
& FACNRESTR,FACL,FACR,
& SFTY, SFTYUP, SFTYDN, HMAX,
& RHOMUV(NMETH),RHOMLV(NMETH),
& TOLESTRAP(2)
INTEGER I,INDF0,INDT,INDIPVT,INDEJ0,INDY,INDF,INDTHETA,INDJ0,
& INDERR,INDSCAL,INDDELJ0,INDDELJ0OLD,
& INDFJ0,indord,INDSCALEXT,IND_DD
LOGICAL STOPINT
STEP_ORD(1)= 3
STEP_ORD(2)= 4
STEP_ORD(3)= 6
STEP_ORD(4)= 8
STEP_ORD(5)= 10
STOPINT = .FALSE.
C INITIAL STEP-SIZE AND TOLERANCES
IF (H.EQ.0D0) THEN
H=1.D-6
ELSEIF(H.LT.0D0) THEN
WRITE(6,*) 'WRONG INPUT H=',H
STOPINT=.TRUE.
END IF
C--------------------------------------------------
C PARAMETERS INITIALIZATION
C--------------------------------------------------
IF (IWORK(1).EQ.0) THEN
MAXSTEP=100000
ELSE
MAXSTEP=IWORK(1)
IF (MAXSTEP.LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(1)=',IWORK(1)
STOPINT=.TRUE.
END IF
ENDIF
IF (IWORK(2).EQ.0) THEN
ORDMIN = 4
ELSE
ORDMIN = IWORK(2)
indord = ORDMIN/2-1
IF ((indord.LE.0).OR.(indord.GT.NMETH)) THEN
WRITE(6,*) 'WRONG INPUT IWORK(2)=',IWORK(2)
STOPINT=.TRUE.
END IF
ORDMIN = 2*(indord+1)
ENDIF
IF (IWORK(3).EQ.0) THEN
ORDMAX = 12
indord = NMETH
ELSE
ORDMAX = IWORK(3)
indord = ORDMAX/2-1
IF ((indord.LE.0).OR.(indord.GT.NMETH)) THEN
WRITE(6,*) 'WRONG INPUT IWORK(3)=',IWORK(3)
STOPINT=.TRUE.
END IF
ORDMAX = 2*(indord+1)
ENDIF
IF (ORDMIN.GT.ORDMAX) THEN
WRITE(6,1000) IWORK(2),IWORK(3)
1000 FORMAT(/,/,'INVALID VALUES FOR IWORK(2)=',i3,' (ORDMIN)',/,
& ' AND IWORK(3)=',i3,' (ORDMAX)',/,/)
STOPINT=.TRUE.
END IF
IF (IWORK(4) .EQ. 0) THEN
ITMAX(1) = 10
ELSE
ITMAX(1) = IWORK(4)
IF (ITMAX(1).LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(4)=',IWORK(4)
STOPINT=.TRUE.
END IF
END IF
IF (IWORK(5) .EQ. 0) THEN
ITMAX(2) = 12
ELSE
ITMAX(2) = IWORK(5)
IF (ITMAX(2).LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(5)=',IWORK(5)
STOPINT=.TRUE.
END IF
END IF
IF (IWORK(6) .EQ. 0) THEN
ITMAX(3) = 14
ELSE
ITMAX(3) = IWORK(6)
IF (ITMAX(3).LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(6)=',IWORK(6)
STOPINT=.TRUE.
END IF
END IF
IF (IWORK(7) .EQ. 0) THEN
ITMAX(4) = 16
ELSE
ITMAX(4) = IWORK(7)
IF (ITMAX(4).LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(7)=',IWORK(7)
STOPINT=.TRUE.
END IF
END IF
IF (IWORK(8) .EQ. 0) THEN
ITMAX(5) = 18
ELSE
ITMAX(5) = IWORK(8)
IF (ITMAX(5).LE.0) THEN
WRITE(6,*) 'WRONG INPUT IWORK(8)=',IWORK(8)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(1) .EQ. 0D0) THEN
UROUND = 1.0D-16
ELSE
UROUND = WORK(1)
IF ((UROUND.LE.0D0).OR.(UROUND.GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(1)=',WORK(1)
STOPINT=.TRUE.
END IF
END IF
IF (ATOL.LE.0D0 .OR. RTOL.LE.UROUND) THEN
WRITE(6,*) 'TOLERANCES ARE TOO SMALL'
STOPINT = .TRUE.
END IF
IF (WORK(2) .LE. 0D0) THEN
HMAX = (TEND-T0)/8d0
ELSE
HMAX = WORK(2)
IF (HMAX.GT.(TEND-T0)) HMAX = TEND-T0
END IF
IF (WORK(3) .EQ. 0D0) THEN
FACNEWTV(1) = 1D-1
ELSE
FACNEWTV(1) = WORK(3)
IF ((FACNEWTV(1).LE.0D0).OR.(FACNEWTV(1).GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(3)=',WORK(3)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(4) .EQ. 0D0) THEN
FACNEWTV(2) = 1D-1
ELSE
FACNEWTV(2) = WORK(4)
IF ((FACNEWTV(2).LE.0D0).OR.(FACNEWTV(2).GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(4)=',WORK(4)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(5) .EQ. 0D0) THEN
FACNEWTV(3) = 1D-1
ELSE
FACNEWTV(3) = WORK(5)
IF ((FACNEWTV(3).LE.0D0).OR.(FACNEWTV(3).GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(5)=',WORK(5)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(6) .EQ. 0D0) THEN
FACNEWTV(4) = 1D-1
ELSE
FACNEWTV(4) = WORK(6)
IF ((FACNEWTV(4).LE.0D0).OR.(FACNEWTV(4).GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(6)=',WORK(6)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(7) .EQ. 0D0) THEN
FACNEWTV(5) = 1D-1
ELSE
FACNEWTV(5) = WORK(7)
IF ((FACNEWTV(5).LE.0D0).OR.(FACNEWTV(5).GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(7)=',WORK(7)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(8) .EQ. 0D0) THEN
FACNSMALL = 5d-3
ELSE
FACNSMALL = WORK(8)
IF ((FACNSMALL.LE.0D0).OR.(FACNSMALL.GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(8)=',WORK(8)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(9) .EQ. 0D0) THEN
FACNRESTR = 5d-2
ELSE
FACNRESTR = WORK(9)
IF ((FACNRESTR.LE.0D0).OR.(FACNRESTR.GE.1D0)) THEN
WRITE(6,*) 'WRONG INPUT WORK(9)=',WORK(9)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(10) .EQ. 0D0) THEN
FACL = 1.2D-1
ELSE
FACL = WORK(10)
IF (FACL.LT.0D0) THEN
WRITE(6,*) 'WRONG INPUT WORK(10)=',WORK(10)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(11) .EQ. 0D0) THEN
FACR = 1D1
ELSE
FACR = WORK(11)
IF(FACR.LE.0D0) THEN
WRITE(6,*) 'WRONG INPUT WORK(11)=',WORK(11)
STOPINT=.TRUE.
END IF
IF(FACL.GE.FACR) THEN
WRITE(6,1010) WORK(10),WORK(11)
1010 FORMAT(/,/,'INVALID VALUES FOR WORK(10)=',e10.2,' (FACL)',/,
& ' AND WORK(11)=',e10.2,' (FACR)',/,/)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(12) .EQ. 0D0) THEN
SFTY = 1D0/20D0
ELSE
SFTY = WORK(12)
IF(SFTY.LE.0D0) THEN
WRITE(6,*) 'WRONG INPUT WORK(12)=',WORK(12)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(13) .EQ. 0D0) THEN
SFTYUP = .5d0*SFTY
ELSE
SFTYUP = WORK(13)
IF(SFTYUP.LE.0D0) THEN
WRITE(6,*) 'WRONG INPUT WORK(13)=',WORK(13)
STOPINT=.TRUE.
END IF
END IF
IF (WORK(14) .EQ. 0D0) THEN
SFTYDN = SFTY
ELSE
SFTYDN = WORK(14)
IF(SFTYDN.LE.0D0) THEN
WRITE(6,*) 'WRONG INPUT WORK(14)=',WORK(14)
STOPINT=.TRUE.
END IF
END IF
IF (STOPINT) THEN
C INVALID INPUT PARAMETERS
IDID = -1
RETURN
END IF
C---------------------------------------------------------
C FIXED PARAMETERS
C---------------------------------------------------------
RHOMUV(1) = 1d-2*DABS(DLOG10(DMIN1(RTOL,ATOL,1D-1)))
RHOMLV(1) = 5d-1
DO I=2,NMETH
RHOMUV(I) = RHOMUV(I-1)**(DBLE(STEP_ORD(I))
& /DBLE(STEP_ORD(I-1)))
RHOMLV(I) = RHOMLV(I-1)**(DBLE(STEP_ORD(I))
& /DBLE(STEP_ORD(I-1)))
end do
TOLESTRAP(1) = DMIN1(1D-2,1D2*RTOL)
TOLESTRAP(2) = DMIN1(1D-2,1D2*ATOL)
C---------------------------------------------------------
C BANDED JACOBIAN
C---------------------------------------------------------
JBAND = (MLJAC .LT. M)
IF (JBAND) THEN
LDJAC = MLJAC+MUJAC+1
LDLU = MLJAC+LDJAC
IJOB=2
ELSE
LDJAC = M
LDLU = M
IJOB = 1
END IF
C---------------------------------------------------------
C COMPUTE THE VECTORS ENTRY-POINT IN IWORK AND WORK
C---------------------------------------------------------
INDIPVT = 38
IF ((INDIPVT + M-1) .GT. LIWORK) THEN
WRITE(6,*) 'INSUFF. STORAGE FOR IWORK, MIN. LIWORK=',INDIPVT+M-1
IDID = -1
RETURN
END IF
INDF0 = 15
INDT = INDF0 + M
INDY = INDT + STEP_ORD(indord)
INDF = INDY + M*STEP_ORD(indord)
INDTHETA = INDF + M*STEP_ORD(indord)
INDERR = INDTHETA + M*LDLU
INDSCAL = INDERR + M*STEP_ORD(indord)
INDSCALEXT = INDSCAL + M
INDJ0 = INDSCALEXT + M
INDDELJ0 = INDJ0 + M*LDJAC
INDDELJ0OLD = INDDELJ0 + M
IND_DD = INDDELJ0OLD + M
INDFJ0 = IND_DD + M*(STEP_ORD(indord)+1)
INDEJ0 = INDFJ0 + M
IF ((INDEJ0 + M-1) .GT. LWORK) THEN
WRITE(6,*) 'INSUFF. STORAGE FOR WORK, MIN. LWORK=',INDEJ0+M-1
IDID = -1
RETURN
END IF
CALL BIM0(M,FCN,JAC,NMETH,STEP_ORD(indord),Y0,WORK(INDF0),
& T0,TEND,H,RTOL,ATOL,
& MAXSTEP,ORDMIN,ORDMAX,ITMAX,UROUND,HMAX,FACNEWTV,
& FACNSMALL,FACNRESTR,FACL,FACR,SFTY,SFTYUP,SFTYDN,
& RHOMUV,RHOMLV,
& IWORK(9),IWORK(10),IWORK(11),IWORK(12),IWORK(13),
& IWORK(18),IWORK(23),IWORK(28),IWORK(33),
& IWORK(INDIPVT),STEP_ORD,
& WORK(INDT),WORK(INDY),WORK(INDF),WORK(INDTHETA),
& WORK(INDERR),WORK(INDJ0),WORK(INDDELJ0),
& WORK(INDDELJ0OLD),WORK(INDFJ0),WORK(INDEJ0),
& WORK(INDSCAL),
& WORK(IND_DD),TOLESTRAP,WORK(INDSCALEXT),
& IJAC,MLJAC,MUJAC,LDJAC,LDLU,JBAND,IJOB,
& RPAR,IPAR,IOUT,IDID)
RETURN
END
c------------------------------------------------------------------------------------------------------
C CORE INTEGRATOR
C------------------------------------------------------------------------------------------------------
SUBROUTINE BIM0(M,FCN,JAC,NMETH,KMAX,Y0,F0,T0,TEND,H,RTOL,ATOL,
& MAXSTEP,ORDMIN,ORDMAX,ITMAX,UROUND,HMAX,FACNEWTV,
& FACNSMALL,FACNRESTR,FACL,FACR,SFTY,SFTYUP,SFTYDN,
& RHOMUV,RHOMLV,
& NFEVAL,NJEVAL,NLU,NLINSYS,NITER,NSTEP,NACCEPT,
& NFAILERR,NFAILNEWT,
& IPVT,STEP_ORD,T,Y,F,THETA,ERR,J0,
& DELJ0,DELJ00,FJ0,EJ0,SCAL,
& DD,TOLESTRAP,SCALEXTRAP,
& IJAC,MLJAC,MUJAC,LDJAC,LDLU,JBAND,IJOB,
& RPAR,IPAR,IOUT,IDID)
IMPLICIT NONE
C
C INPUT PARAMETERS
C
EXTERNAL FCN,JAC
INTEGER M,NMETH,KMAX,MAXSTEP,ORDMIN,ORDMAX,ITMAX(NMETH),
& IPVT(M),STEP_ORD(NMETH),
& MLJAC,MUJAC,LDJAC,LDLU,IJOB,IJAC,IPAR(*)
LOGICAL JBAND
DOUBLE PRECISION TEND,H,RTOL,ATOL,UROUND,HMAX,
& FACNEWTV(NMETH),FACNSMALL,FACNRESTR,FACL,FACR,
& SFTY,SFTYUP,SFTYDN,
& T(KMAX),F0(M),THETA(LDLU,M),J0(LDJAC,M),DELJ0(M),
& DELJ00(M),Y(M,KMAX),F(M,KMAX),ERR(M,KMAX),
& RHOMUV(NMETH),RHOMLV(NMETH),SCAL(M),DD(KMAX+1,M),
& TOLESTRAP(2),FJ0(M),SCALEXTRAP(M),EJ0(M),
& RPAR(*)
C
C I/O PARAMETERS
C
DOUBLE PRECISION T0,Y0(M)
real(8) t0vec(1) ! jvallino 26 sep 08
C
C OUTPUT PARAMETERS
C
INTEGER NFEVAL,NJEVAL,NLU,NLINSYS,NITER(NMETH),NSTEP(NMETH),
& NACCEPT(NMETH),NFAILERR(NMETH),NFAILNEWT(NMETH),
& IOUT,IDID
C
C LOCAL VARIABLES
C
INCLUDE 'param.dat'
INTEGER I,J,IT,MAXIT,ORD,ORD_IND,ORDNEW,K,KOLD,KNEW,KUP,K0,
& INDMIN,NFAILCONV,NORD,INFO,IRTRN,IERR,IERR0,
& NFAILCONS,NSTEPS,NSING,NERROR
DOUBLE PRECISION NERR,NERRUP,NERRUP1,NERRDOWN,
& NERR0,NERROLD,NERRSTOP,
& RHO,RHO0,RHOBAD,RHOMU,RHOML,RHOT,RHOTUP,
& RHOOLD,RHOI,RHOIUP,
& RHOMAX,HNEW,HNUP,HNDN,H0,H00,RATH,RATRHO,
& FI,ESP,ESPUP,ESPDN,
& FACNEWT,GAMMA,HGAMMA,
& MINY0,MAXF0,MAXDELTA,
& NU, NUUP,NUDN, NU1, NUUP1, FATERR,HNUP1,FI1,
& SCALJ0_1,NJ0,NJ00,HJ0,RHOJ0,
& DJ0,FATDJ0,FATDJ0I,
& ABSY0,
& DELTAH2,DELTAH1SF,DELTAH1,CFAT1,CFAT2,CFAT3,
& RATHH,HFATT,ALFAFATT,RHOFATT,DISCR,
& tolrhoJ0,RTOLATOL,
& DELT,YSAFE,ITNEW,
& RHOUP,RHONEW,RHODN,
& VUP,SISERR,SISERRDN,SISERRUP,CSIS,CFACT,
& NF0,NF,RTOL0
LOGICAL JVAI,LAST,EXTRAP,EXTRAP0,CALJAC,CALFACT,
& SUCCESS,RESTRICT,
& TRUEJAC,STAGNA,
& LINEAR,CALJAC0,CALFACT0,
& QINF,QINFJ,QINFF,NQINF,SMALLM,
& ESTIM,ESTIM1,NODJ0,NODJ00,ISNAN,
& ERROR
C-------------------------------------------------------------------------------------------------------------------
C STATISTICS
C
NFEVAL = 0
NJEVAL = 0
NLU = 0
NLINSYS= 0
NSTEPS = 0
DO I=1,NMETH
NITER(I) = 0
NSTEP(I) = 0
NACCEPT(I) = 0
NFAILERR(I) = 0
NFAILNEWT(I) = 0
END DO
C-------------------------------------------------------------------------------------------------------------------
C OTHER INITIALIZATIONS
c jjv NJ0 is never initialized, so do so here. I supposed it doesn't matter. (6 aug 2011)
c jjv IT is also never initialized!
c jjv qinf not initialized. Don't have any guess.
nj0 = 0d0
it = 0
qinf = .false.
IF (JBAND) THEN
CSIS = DBLE(2*M*(MLJAC+MUJAC))
CFACT = DBLE(2*M*MLJAC*MUJAC)
ELSE
CSIS = DBLE(2*M**2)
CFACT = DBLE(2*M**3)/3D0
END IF
SMALLM = M.LE.5