-
Notifications
You must be signed in to change notification settings - Fork 2
/
nleq1.f
3569 lines (3569 loc) · 133 KB
/
nleq1.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
SUBROUTINE NLEQ1(N,FCN,JAC,X,XSCAL,RTOL,IOPT,IERR,
$LIWK,IWK,LRWK,RWK)
!* Begin Prologue NLEQ1
INTEGER N
EXTERNAL FCN,JAC
DOUBLE PRECISION X(N),XSCAL(N)
DOUBLE PRECISION RTOL
INTEGER IOPT(50)
INTEGER IERR
INTEGER LIWK
INTEGER IWK(LIWK)
INTEGER LRWK
DOUBLE PRECISION RWK(LRWK)
! ------------------------------------------------------------
!
!* Title
!
! Numerical solution of nonlinear (NL) equations (EQ)
! especially designed for numerically sensitive problems.
!
!* Written by U. Nowak, L. Weimann
!* Purpose Solution of systems of highly nonlinear equations
!* Method Damped affine invariant Newton method
! (see references below)
!* Category F2a. - Systems of nonlinear equations
!* Keywords Nonlinear equations, Newton methods
!* Version 2.4
!* Revision May 2009
!* Latest Change May 2009
!* Library CodeLib
!* Code Fortran 77, Double Precision
!* Environment Standard Fortran 77 environment on PC's,
! workstations and hosts.
!* Copyright (c) Konrad-Zuse-Zentrum fuer
! Informationstechnik Berlin (ZIB)
! Takustrasse 7, D-14195 Berlin-Dahlem
! phone : + 49/30/84185-0
! fax : + 49/30/84185-125
!* Contact Lutz Weimann
! ZIB, Division Scientific Computing,
! Department Numerical Analysis and Modelling
! phone : + 49/30/84185-185
! fax : + 49/30/84185-107
! e-mail: [email protected]
!
!* References:
!
! /1/ P. Deuflhard:
! Newton Methods for Nonlinear Problems. -
! Affine Invariance and Adaptive Algorithms.
! Series Computational Mathematics 35, Springer (2004)
!
! /2/ U. Nowak, L. Weimann:
! A Family of Newton Codes for Systems of Highly Nonlinear
! Equations - Algorithm, Implementation, Application.
! ZIB, Technical Report TR 90-10 (December 1990)
!
! ---------------------------------------------------------------
!
!* Licence
! You may use or modify this code for your own non commercial
! purposes for an unlimited time.
! In any case you should not deliver this code without a special
! permission of ZIB.
! In case you intend to use the code commercially, we oblige you
! to sign an according licence agreement with ZIB.
!
!* Warranty
! This code has been tested up to a certain level. Defects and
! weaknesses, which may be included in the code, do not establish
! any warranties by ZIB. ZIB does not take over any liabilities
! which may follow from acquisition or application of this code.
!
!* Software status
! This code is under care of ZIB and belongs to ZIB software class 1.
!
! ------------------------------------------------------------
!
!* Summary:
! ========
! Damped Newton-algorithm for systems of highly nonlinear
! equations - damping strategy due to Ref. (1).
!
! (The iteration is done by subroutine N1INT currently. NLEQ1
! itself does some house keeping and builds up workspace.)
!
! Jacobian approximation by numerical differences or user
! supplied subroutine JAC.
!
! The numerical solution of the arising linear equations is
! done by means of the subroutines *GETRF and *GETRS ( Gauss-
! algorithm with column-pivoting and row-interchange ) in the
! dense matrix case, or by the subroutines *GBTRF and *GBTRS in
! the band matrix case from LAPACK (replace '*' by 'S' or 'D'
! for single or double precision version respectively).
! For special purposes these routines may be substituted.
!
! This is a driver routine for the core solver N1INT.
!
! ------------------------------------------------------------
!
!* Parameters list description (* marks inout parameters)
! ======================================================
!
!* External subroutines (to be supplied by the user)
! =================================================
!
! (Caution: Arguments declared as (input) must not
! be altered by the user subroutines ! )
!
! FCN(N,X,F,IFAIL) Ext Function subroutine
! N Int Number of vector components (input)
! X(N) Dble Vector of unknowns (input)
! F(N) Dble Vector of function values (output)
! IFAIL Int FCN evaluation-failure indicator. (output)
! On input: Has always value 0 (zero).
! On output: Indicates failure of FCN eval-
! uation, if having a value <= 2.
! If <0: NLEQ1 will be terminated with
! error code = 82, and IFAIL stored
! to IWK(23).
! If =1: A new trial Newton iterate will
! computed, with the damping factor
! reduced to it's half.
! If =2: A new trial Newton iterate will
! computed, with the damping factor
! reduced by a reduct. factor, which
! must be output through F(1) by FCN,
! and it's value must be >0 and < 1.
! Note, that if IFAIL = 1 or 2, additional
! conditions concerning the damping factor,
! e.g. the minimum damping factor or the
! bounded damping strategy may also influ-
! ence the value of the reduced damping
! factor.
!
! JAC(N,LDJAC,X,DFDX,IFAIL)
! Ext Jacobian matrix subroutine
! N Int Number of vector components (input)
! LDJAC Int Leading dimension of Jacobian array
! (input)
! X(N) Dble Vector of unknowns (input)
! DFDX(LDJAC,N) Dble DFDX(i,k): partial derivative of
! I-th component of FCN with respect
! to X(k) (output)
! IFAIL Int JAC evaluation-failure indicator.
! (output)
! Has always value 0 (zero) on input.
! Indicates failure of JAC evaluation
! and causes termination of NLEQ1,
! if set to a negative value on output
!
!
!* Input parameters of NLEQ1
! =========================
!
! N Int Number of unknowns
! * X(N) Dble Initial estimate of the solution
! * XSCAL(N) Dble User scaling (lower threshold) of the
! iteration vector X(N)
! * RTOL Dble Required relative precision of
! solution components -
! RTOL.GE.EPMACH*TEN*N
! * IOPT(50) Int Array of run-time options. Set to zero
! to get default values (details see below)
!
!* Output parameters of NLEQ1
! ==========================
!
! * X(N) Dble Solution values ( or final values,
! respectively )
! * XSCAL(N) Dble After return with IERR.GE.0, it contains
! the latest internal scaling vector used
! After return with IERR.EQ.-1 in onestep-
! mode it contains a possibly adapted
! (as described below) user scaling vector:
! If (XSCAL(I).LT. SMALL) XSCAL(I) = SMALL ,
! If (XSCAL(I).GT. GREAT) XSCAL(I) = GREAT .
! For SMALL and GREAT, see section machine
! constants below and regard note 1.
! * RTOL Dble Finally achieved (relative) accuracy.
! The estimated absolute error of component i
! of x_out is approximately given by
! abs_err(i) = RTOL * XSCAL_out(i) ,
! where (approximately)
! XSCAL_out(i) =
! max(abs(X_out(i)),XSCAL_in(i)).
! IERR Int Return value parameter
! =-1 sucessfull completion of one iteration
! step, subsequent iterations are needed
! to get a solution. (stepwise mode only)
! = 0 successfull completion of the iteration,
! solution has been computed
! > 0 see list of error messages below
!
! Note 1.
! The machine dependent values SMALL and EPMACH are
! gained from calls of the ZIBCONST.
!
!* Workspace parameters of NLEQ1
! =============================
!
! LIWK Int Declared dimension of integer workspace.
! Required minimum (for standard linear system
! solver) : N+50
! * IWK(LIWK) Int Integer Workspace
! LRWK Int Declared dimension of real workspace.
! Required minimum (for standard linear system
! solver and Jacobian computed by numerical
! approximation - if the Jacobian is computed
! by a user subroutine JAC, decrease the
! expressions noted below by N):
! for full case Jacobian: (N+NBROY+13)*N+61
! for a band-matrix Jacobian:
! (2*ML+MU+NBROY+14)*N+61 with
! ML = lower bandwidth , MU = upper bandwidth
! NBROY = Maximum number of Broyden steps
! (Default: if Broyden steps are enabled, e.g.
! IOPT(32)=1 -
! NBROY=N (full Jacobian),
! =ML+MU+1 (band Jacobian),
! but at least NBROY=10
! else (if IOPT(32)=0) -
! NBROY=0 ;
! see equally named IOPT and IWK-fields below)
! * RWK(LRWK) Dble Real Workspace
!
! Note 2a. A test on sufficient workspace is made. If this
! test fails, IERR is set to 10 and an error-message
! is issued from which the minimum of required
! workspace size can be obtained.
!
! Note 2b. The first 50 elements of IWK and RWK are partially
! used as input for internal algorithm parameters (for
! details, see below). In order to set the default values
! of these parameters, the fields must be set to zero.
! Therefore, it's recommanded always to initialize the
! first 50 elements of both workspaces to zero.
!
!* Options IOPT:
! =============
!
! Pos. Name Default Meaning
!
! 1 QSUCC 0 =0 (.FALSE.) initial call:
! NLEQ1 is not yet initialized, i.e. this is
! the first call for this nonlinear system.
! At successfull return with MODE=1,
! QSUCC is set to 1.
! =1 (.TRUE.) successive call:
! NLEQ1 is initialized already and is now
! called to perform one or more following
! Newton-iteration steps.
! ATTENTION:
! Don't destroy the contents of
! IOPT(i) for 1 <= i <= 50 ,
! IWK(j) for 1 <= j < NIWKFR and
! RWK(k) for 1 <= k < NRWKFR.
! (Nevertheless, some of the options, e.g.
! FCMIN, SIGMA, MPR..., can be modified
! before successive calls.)
! 2 MODE 0 =0 Standard mode initial call:
! Return when the required accuracy for the
! iteration vector is reached. User defined
! parameters are evaluated and checked.
! Standard mode successive call:
! If NLEQ1 was called previously with MODE=1,
! it performs all remaining iteration steps.
! =1 Stepwise mode:
! Return after one Newton iteration step.
! 3 JACGEN 0 Method of Jacobian generation
! =0 Standard method is JACGEN=2
! =1 User supplied subroutine JAC will be
! called to generate Jacobian matrix
! =2 Jacobian approximation by numerical
! differentation (see subroutines N1JAC
! and N1JACB)
! =3 Jacobian approximation by numerical
! differentation with feedback control
! (see subroutines N1JCF and N1JCFB)
! 4 MSTOR 0 =0 The Jacobian A is a dense matrix
! =1 A is a band matrix
! 5 Reserved
! 6 ML 0 Lower bandwidth of A (excluding the
! diagonal);
! IOPT(6) ignored, if IOPT(4).NE.1
! 7 MU 0 Upper bandwidth of A (excluding the
! diagonal);
! IOPT(7) ignored, if IOPT(4).NE.1
! 8 Reserved
! 9 ISCAL 0 Determines how to scale the iterate-vector:
! =0 The user supplied scaling vector XSCAL is
! used as a (componentwise) lower threshold
! of the current scaling vector
! =1 The vector XSCAL is always used as the
! current scaling vector
! 10 Reserved
! 11 MPRERR 0 Print error messages
! =0 No output
! =1 Error messages
! =2 Warnings additionally
! =3 Informal messages additionally
! 12 LUERR 6 Logical unit number for error messages
! 13 MPRMON 0 Print iteration Monitor
! =0 No output
! =1 Standard output
! =2 Summary iteration monitor additionally
! =3 Detailed iteration monitor additionally
! =4,5,6 Outputs with increasing level addi-
! tional increasing information for code
! testing purposes. Level 6 produces
! in general extremely large output!
! 14 LUMON 6 Logical unit number for iteration monitor
! 15 MPRSOL 0 Print solutions
! =0 No output
! =1 Initial values and solution values
! =2 Intermediate iterates additionally
! 16 LUSOL 6 Logical unit number for solutions
! 17..18 Reserved
! 19 MPRTIM 0 Output level for the time monitor
! = 0 : no time measurement and no output
! = 1 : time measurement will be done and
! summary output will be written -
! regard note 5a.
! 20 LUTIM 6 Logical output unit for time monitor
! 21..30 Reserved
! 31 NONLIN 3 Problem type specification
! =1 Linear problem
! Warning: If specified, no check will be
! done, if the problem is really linear, and
! NLEQ1 terminates unconditionally after one
! Newton-iteration step.
! =2 Mildly nonlinear problem
! =3 Highly nonlinear problem
! =4 Extremely nonlinear problem
! 32 QRANK1 0 =0 (.FALSE.) Rank-1 updates by Broyden-
! approximation are inhibited.
! =1 (.TRUE.) Rank-1 updates by Broyden-
! approximation are allowed.
! 33 QORDI 0 =0 (.FALSE.) Standard program mode
! =1 (.TRUE.) Special program mode:
! Ordinary Newton iteration is done, e.g.:
! No damping strategy and no monotonicity
! test is applied
! 34 QSIMPL 0 =0 (.FALSE.) Standard program mode
! =1 (.TRUE.) Special program mode:
! Simplified Newton iteration is done, e.g.:
! The Jacobian computed at the starting
! point is fixed for all subsequent
! iteration steps, and
! no damping strategy and no monotonicity
! test is applied.
! 35 QNSCAL 0 Inhibit automatic row scaling:
! =0 (.FALSE.) Automatic row scaling of
! the linear system is activ:
! Rows i=1,...,N will be divided by
! max j=1,...,N (abs(a(i,j)))
! =1 (.TRUE.) No row scaling of the linear
! system. Recommended only for well row-
! scaled nonlinear systems.
! 36..37 Reserved
! 38 IBDAMP Bounded damping strategy switch:
! =0 The default switch takes place, dependent
! on the setting of NONLIN (=IOPT(31)):
! NONLIN = 0,1,2,3 -> IBDAMP = off ,
! NONLIN = 4 -> IBDAMP = on
! =1 means always IBDAMP = on
! =2 means always IBDAMP = off
! 39 IORMON Convergence order monitor
! =0 Standard option is IORMON=2
! =1 Convergence order is not checked,
! the iteration will be always proceeded
! until the solution has the required
! precision RTOL (or some error condition
! occured)
! =2 Use additional 'weak stop' criterion:
! Convergence order is monitored
! and termination due to slowdown of the
! convergence may occur.
! =3 Use additional 'hard stop' criterion:
! Convergence order is monitored
! and termination due to superlinear
! convergence slowdown may occur.
! In case of termination due to convergence
! slowdown, the warning code IERR=4 will be
! set.
! In cases, where the Newton iteration con-
! verges but superlinear convergence order has
! never been detected, the warning code IERR=5
! is returned.
! 40..45 Reserved
! 46..50 User options (see note 5b)
!
! Note 3:
! If NLEQ1 terminates with IERR=2 (maximum iterations)
! or IERR=3 (small damping factor), you may try to continue
! the iteration by increasing NITMAX or decreasing FCMIN
! (see RWK) and setting QSUCC to 1.
!
! Note 4 : Storage of user supplied banded Jacobian
! In the band matrix case, the following lines may build
! up the analytic Jacobian A;
! Here AFL denotes the quadratic matrix A in dense form,
! and ABD the rectangular matrix A in banded form :
!
! ML = IOPT(6)
! MU = IOPT(7)
! MH = MU+1
! DO 20 J = 1,N
! I1 = MAX0(1,J-MU)
! I2 = MIN0(N,J+ML)
! DO 10 I = I1,I2
! K = I-J+MH
! ABD(K,J) = AFL(I,J)
! 10 CONTINUE
! 20 CONTINUE
!
! The total number of rows needed in ABD is ML+MU+1 .
! The MU by MU upper left triangle and the
! ML by ML lower right triangle are not referenced.
!
! Note 5a:
! The integrated time monitor calls the machine dependent
! subroutine SECOND to get the current time stamp in form
! of a real number (Single precision). As delivered, this
! subroutine always return 0.0 as time stamp value. Refer
! to the compiler- or library manual of the FORTRAN compiler
! which you currently use to find out how to get the current
! time stamp on your machine.
!
! Note 5b:
! The user options may be interpreted by the user replacable
! routines N1SOUT, N1FACT, N1SOLV - the distributed version
! of N1SOUT currently uses IOPT(46) as follows:
! 0 = standard plotdata output (may be postprocessed by a user-
! written graphical program)
! 1 = plotdata output is suitable as input to the graphical
! package GRAZIL (based on GKS), which has been developed
! at ZIB.
!
!
!* Optional INTEGER input/output in IWK:
! =======================================
!
! Pos. Name Meaning
!
! 1 NITER IN/OUT Number of Newton-iterations
! 2 reserved
! 3 NCORR IN/OUT Number of corrector steps
! 4 NFCN IN/OUT Number of FCN-evaluations
! 5 NJAC IN/OUT Number of Jacobian generations or
! JAC-calls
! 6 reserved
! 7 reserved
! 8 NFCNJ IN/OUT Number of FCN-evaluations for Jacobian
! approximation
! 9 NREJR1 IN/OUT Number of rejected Newton iteration steps
! done with a rank-1 approximated Jacobian
! 10..11 Reserved
! 12 IDCODE IN/OUT Output: The 8 decimal digits program identi-
! fication number ppppvvvv, consisting of the
! program code pppp and the version code vvvv.
! Input: If containing a negative number,
! it will only be overwritten by the identi-
! fication number, immediately followed by
! a return to the calling program.
! 13..15 Reserved
! 16 NIWKFR OUT First element of IWK which is free to be used
! as workspace between Newton iteration steps
! for standard linear solvers: 51
! 17 NRWKFR OUT First element of RWK which is free to be used
! as workspace between Newton iteration steps.
! For standard linear solvers and numerically
! approximated Jacobian computed by one of the
! expressions:
! (N+7+NBROY)*N+61 for a full Jacobian
! (2*ML+MU+8+NBROY)*N+61 for a banded Jacobian
! If the Jacobian is computed by a user routine
! JAC, subtract N in both expressions.
! 18 LIWKA OUT Length of IWK currently required
! 19 LRWKA OUT Length of RWK currently required
! 20..22 Reserved
! 23 IFAIL OUT Set in case of failure of N1FACT (IERR=80),
! N1SOLV (IERR=81), FCN (IERR=82) or JAC(IERR=83)
! to the nonzero IFAIL value returned by the
! routine indicating the failure .
! 24 ICONV OUT Current status of of the convergence monitor
! (only if convergence order monitor is on -
! see IORMON(=IOPT(39)))
! =0: No convergence indicated yet
! =1: Damping factor is 1.0d0
! =2: Superlinear convergence in progress
! =3: Quadratic convergence in progress
! 25..30 Reserved
! 31 NITMAX IN Maximum number of permitted iteration
! steps (default: 50)
! 32 Reserved
! 33 NEW IN/OUT Count of consecutive rank-1 updates
! 34..35 Reserved
! 36 NBROY IN Maximum number of possible consecutive
! iterative Broyden steps. The total real
! workspace needed (RWK) depends on this value
! (see LRWK above).
! Default is N (see parameter N),
! if MSTOR=0 (=IOPT(4)),
! and ML+MU+1 (=IOPT(6)+IOPT(7)+1), if MSTOR=1
! (but minimum is always 10) -
! provided that Broyden is allowed.
! If Broyden is inhibited, NBROY is always set to
! zero.
! 37..50 Reserved
!
!* Optional REAL input/output in RWK:
! ====================================
!
! Pos. Name Meaning
!
! 1..16 Reserved
! 17 CONV OUT The achieved relative accuracy after the
! current step
! 18 SUMX OUT Natural level (not Normx of printouts)
! of the current iterate, i.e. Sum(DX(i)**2),
! where DX = scaled Newton correction.
! 19 DLEVF OUT Standard level (not Normf of printouts)
! of the current iterate, i.e. Norm2(F(X)),
! where F = nonlinear problem function.
! 20 FCBND IN Bounded damping strategy restriction factor
! (Default is 10)
! 21 FCSTRT IN Damping factor for first Newton iteration -
! overrides option NONLIN, if set (see note 6)
! 22 FCMIN IN Minimal allowed damping factor (see note 6)
! 23 SIGMA IN Broyden-approximation decision parameter
! Required choice: SIGMA.GE.1. Increasing this
! parameter make it less probable that the algo-
! rith performs rank-1 updates.
! Rank-1 updates are inhibited, if
! SIGMA.GT.1/FCMIN is set. (see note 6)
! 24 SIGMA2 IN Decision parameter about increasing damping
! factor to corrector if predictor is small.
! Required choice: SIGMA2.GE.1. Increasing this
! parameter make it less probable that the algo-
! rith performs rank-1 updates.
! 25 Reserved
! 26 AJDEL IN Jacobian approximation without feedback:
! Relative pertubation for components
! (Default: sqrt(epmach*10), epmach: relative
! machine precision)
! 27 AJMIN IN Jacobian approximation without feedback:
! Threshold value (Default: 0.0d0)
! The absolute pertubation for component k is
! computed by
! DELX := AJDEL*max(abs(Xk),AJMIN)
! 28 ETADIF IN Jacobian approximation with feedback:
! Target value for relative pertubation ETA of X
! (Default: 1.0d-6)
! 29 ETAINI IN Jacobian approximation with feedback:
! Initial value for denominator differences
! (Default: 1.0d-6)
! 30..50 Reserved
!
! Note 6:
! The default values of the internal parameters may be obtained
! from the monitor output with at least IOPT field MPRMON set to 2
! and by initializing the corresponding RWK-fields to zero.
!
!* Error and warning messages:
! ===========================
!
! 1 Termination, since jacobian matrix became singular
! 2 Termination after NITMAX iterations ( as indicated by
! input parameter NITMAX=IWK(31) )
! 3 Termination, since damping factor became to small
! 4 Warning: Superlinear or quadratic convergence slowed down
! near the solution.
! Iteration has been stopped therefore with an approximation
! of the solution not such accurate as requested by RTOL,
! because possibly the RTOL requirement may be too stringent
! (i.e. the nonlinear problem is ill-conditioned)
! 5 Warning: Iteration stopped with termination criterion
! (using RTOL as requested precision) satisfied, but no
! superlinear or quadratic convergence has been indicated yet.
! Therefore, possibly the error estimate for the solution may
! not match good enough the really achieved accuracy.
! 10 Integer or real workspace too small
! 20 Bad input to dimensional parameter N
! 21 Nonpositive value for RTOL supplied
! 22 Negative scaling value via vector XSCAL supplied
! 30 One or more fields specified in IOPT are invalid
! (for more information, see error-printout)
! 80 Error signalled by linear solver routine N1FACT,
! for more detailed information see IFAIL-value
! stored to IWK(23)
! 81 Error signalled by linear solver routine N1SOLV,
! for more detailed information see IFAIL-value
! stored to IWK(23)
! (not used by standard routine N1SOLV)
! 82 Error signalled by user routine FCN (Nonzero value
! returned via IFAIL-flag; stored to IWK(23) )
! 83 Error signalled by user routine JAC (Nonzero value
! returned via IFAIL-flag; stored to IWK(23) )
!
! Note 7 : in case of failure:
! - use non-standard options
! - or turn to Newton-algorithm with rank strategy
! - use another initial guess
! - or reformulate model
! - or apply continuation techniques
!
!* Machine dependent constants used:
! =================================
!
! DOUBLE PRECISION EPMACH in N1PCHK, N1INT
! DOUBLE PRECISION GREAT in N1PCHK
! DOUBLE PRECISION SMALL in N1PCHK, N1INT, N1SCAL
!
!* Subroutines called: N1PCHK, N1INT
!
! ------------------------------------------------------------
!* End Prologue
!
!* Summary of changes:
! ===================
!
! 2.2.1 91, May 30 Time monitor included
! 2.2.2 91, May 30 Bounded damping strategy implemented
! 2.2.3 91, June 19 AJDEL, AJMIN as RWK-options for JACGEN.EQ.2,
! ETADIF, ETAINI as RWK-opts. for JACGEN.EQ.3
! FCN-count changed for anal. Jacobian
! 2.2.4 91, August 9 Convergence order monitor included
! 2.2.5 91, August 13 Standard Broyden updates replaced by
! iterative Broyden
! 2.2.6 91, Sept. 16 Damping factor reduction by FCN-fail imple-
! mented
! 2.3 91, Dec. 20 New Release for CodeLib
! 92, March 11 Level of accepted simplified correction
! stored to RWK(IRWKI+4)
! 00, July 12 RTOL output-value bug fixed
! 06, Jan. 24 IERR=5 no longer returned if residuum of
! final iterate is exactly zero
! 2.4 09, May 29 Changed routines N1FACT and N1SOLV to use
! LAPACK Routines DGETRF, DGETRS, DGBTRF and
! DGBTRS instead of LINPACK routines to solve
! linear systems.
! 10, July 26 Subroutine N1INT: Initialization of unitialized
! Variable FCMON fixed.
!
! ------------------------------------------------------------
!
! PARAMETER (IRWKI=xx, LRWKI=yy)
! IRWKI: Start position of internally used RWK part
! LRWKI: Length of internally used RWK part
! (current values see parameter statement below)
!
! INTEGER L4,L5,L51,L6,L61,L62,L63,L7,L71,L8,L9,L10,L11,L12,L121,
! L13,L14,L20
! Starting positions in RWK of formal array parameters of internal
! routine N1INT (dynamically determined in driver routine NLEQ1,
! dependent on N and options setting)
!
! Further RWK positions (only internally used)
!
! Position Name Meaning
!
! IRWKI FCKEEP Damping factor of previous successfull iter.
! IRWKI+1 FCA Previous damping factor
! IRWKI+2 FCPRI A priori estimate of damping factor
! IRWKI+3 DMYCOR Number My of latest corrector damping factor
! (kept for use in rank-1 decision criterium)
! IRWKI+4 SUMXS natural level of accepted simplified correction
! IRWKI+(5..LRWKI-1) Free
!
! Internal arrays stored in RWK (see routine N1INT for descriptions)
!
! Position Array Type Remarks
!
! L4 A(M1,N) Perm M1=N (full mode) or
! M1=2*IOPT(6)+IOPT(7)+1 (band mode)
! L41 DXSAVE(N,NBROY)
! Perm NBROY=IWK(36) (Default: N or 0)
! L5 DX(N) Perm
! L51 DXQ(N) Perm
! L6 XA(N) Perm
! L61 F(N) Perm
! L62 FW(N) Perm
! L63 XWA(N) Perm
! L7 FA(N) Perm
! L71 ETA(N) Perm Only used for JACGEN=IOPT(3)=3
! L9 XW(N) Temp
! L11 DXQA(N) Temp
! L12 T1(N) Temp
! L121 T2(N) Temp
! L13 T3(N) Temp
! L14 Temp Start position of array workspace
! needed for linear solver
!
!
EXTERNAL N1INT
INTRINSIC DBLE
INTEGER IRWKI, LRWKI
PARAMETER (IRWKI=51, LRWKI=10)
DOUBLE PRECISION ONE
PARAMETER (ONE=1.0D0)
DOUBLE PRECISION TEN
PARAMETER (TEN=1.0D1)
DOUBLE PRECISION ZERO
PARAMETER (ZERO=0.0D0)
INTEGER NITMAX,LUERR,LUMON,LUSOL,MPRERR,MPRMON,MPRSOL,
$MSTOR,M1,M2,NRWKFR,NRFRIN,NRW,NIWKFR,NIFRIN,NIW,NONLIN,JACGEN
INTEGER L4,L41,L5,L51,L6,L61,L62,L63,L7,L71,L8,L9,L11,L12,L121,
$L13,L14,L20
DOUBLE PRECISION FC,FCMIN,PERCI,PERCR
LOGICAL QINIMO,QRANK1,QFCSTR,QSUCC,QBDAMP,QSIMPL
CHARACTER CHGDAT*20, PRODCT*8
! Which version ?
LOGICAL QVCHK
INTEGER IVER
PARAMETER( IVER=21112401 )
!
! Version: 2.4.0.1 Latest change:
! -----------------------------------------
!
DATA CHGDAT /'July 26, 2010 '/
DATA PRODCT /'NLEQ1 '/
!* Begin
IERR = 0
QVCHK = IWK(12).LT.0
IWK(12) = IVER
IF (QVCHK) RETURN
! Print error messages?
MPRERR = IOPT(11)
LUERR = IOPT(12)
IF (LUERR .EQ. 0) THEN
LUERR = 6
IOPT(12)=LUERR
ENDIF
! Print iteration monitor?
MPRMON = IOPT(13)
LUMON = IOPT(14)
IF (LUMON .LE. 0 .OR. LUMON .GT. 99) THEN
LUMON = 6
IOPT(14)=LUMON
ENDIF
! Print intermediate solutions?
MPRSOL = IOPT(15)
LUSOL = IOPT(16)
IF (LUSOL .EQ. 0) THEN
LUSOL = 6
IOPT(16)=LUSOL
ENDIF
! Print time summary statistics?
MPRTIM = IOPT(19)
LUTIM = IOPT(20)
IF (LUTIM .EQ. 0) THEN
LUTIM = 6
IOPT(20)=LUTIM
ENDIF
QSUCC = IOPT(1).EQ.1
QINIMO = MPRMON.GE.1.AND..NOT.QSUCC
! Print NLEQ1 heading lines
IF(QINIMO)THEN
10000 FORMAT(' N L E Q 1 ***** V e r s i o n ',
$ '2 . 3 ***',//,1X,'Newton-Method ',
$ 'for the solution of nonlinear systems',//)
WRITE(LUMON,10000)
ENDIF
! Check input parameters and options
CALL N1PCHK(N,X,XSCAL,RTOL,IOPT,IERR,LIWK,IWK,LRWK,RWK)
! Exit, if any parameter error was detected till here
IF (IERR.NE.0) RETURN
!
MSTOR=IOPT(4)
IF (MSTOR.EQ.0) THEN
M1=N
M2=N
ELSE IF (MSTOR.EQ.1) THEN
ML=IOPT(6)
MU=IOPT(7)
M1=2*ML+MU+1
M2=ML+MU+1
ENDIF
JACGEN=IOPT(3)
IF (JACGEN.EQ.0) JACGEN=2
IOPT(3)=JACGEN
QRANK1=IOPT(32).EQ.1
QSIMPL=IOPT(34).EQ.1
IF (QRANK1) THEN
NBROY=IWK(36)
IF (NBROY.EQ.0) NBROY=MAX(M2,10)
IWK(36)=NBROY
ELSE
NBROY=0
ENDIF
! WorkSpace: RWK
L4=IRWKI+LRWKI
L41=L4+M1*N
L5=L41+NBROY*N
L51=L5+N
L6=L51+N
L61=L6+N
L62=L61+N
L63=L62+N
L7=L63+N
L71=L7+N
IF (JACGEN.NE.3) THEN
L8=L71
ELSE
L8=L71+N
ENDIF
NRWKFR = L8
L9=L8
L11=L9+N
L12=L11+N
L121=L12+N
L13=L121+N
L14=L13+N
NRW=L14-1
! End WorkSpace at NRW
! WorkSpace: IWK
L20=51
NIWKFR = L20
IF (QRANK1.OR.QSIMPL) NIWKFR = NIWKFR+N
NIW=L20-1
! End WorkSpace at NIW
IWK(16) = NIW+1
IWK(17) = NRW+1
NIFRIN = NIW+1
NRFRIN = NRW+1
!
IF(NRW.GT.LRWK.OR.NIW.GT.LIWK)THEN
IERR=10
ELSE
IF(QINIMO)THEN
PERCR = DBLE(NRW)/DBLE(LRWK)*100.0D0
PERCI = DBLE(NIW)/DBLE(LIWK)*100.0D0
! Print statistics concerning workspace usage
10050 FORMAT(' Real Workspace declared as ',I9,
$ ' is used up to ',I9,' (',F5.1,' percent)',//,
$ ' Integer Workspace declared as ',I9,
$ ' is used up to ',I9,' (',F5.1,' percent)',//)
WRITE(LUMON,10050)LRWK,NRW,PERCR,LIWK,NIW,PERCI
ENDIF
IF(QINIMO)THEN
10051 FORMAT(/,' N =',I4,//,' Prescribed relative ',
$ 'precision',D10.2,/)
WRITE(LUMON,10051)N,RTOL
10052 FORMAT(' The Jacobian is supplied by ',A)
IF (JACGEN.EQ.1) THEN
WRITE(LUMON,10052) 'a user subroutine'
ELSE IF (JACGEN.EQ.2) THEN
WRITE(LUMON,10052)
$ 'numerical differentiation (without feedback strategy)'
ELSE IF (JACGEN.EQ.3) THEN
WRITE(LUMON,10052)
$ 'numerical differentiation (feedback strategy included)'
ENDIF
10055 FORMAT(' The Jacobian will be stored in ',A,' mode')
IF (MSTOR.EQ.0) THEN
WRITE(LUMON,10055) 'full'
ELSE IF (MSTOR.EQ.1) THEN
WRITE(LUMON,10055) 'banded'
10056 FORMAT(' Lower bandwidth : ',I3,' Upper bandwidth : ',I3)
WRITE(LUMON,10056) ML,MU
ENDIF
10057 FORMAT(' Automatic row scaling of the Jacobian is ',A,/)
IF (IOPT(35).EQ.1) THEN
WRITE(LUMON,10057) 'inhibited'
ELSE
WRITE(LUMON,10057) 'allowed'
ENDIF
ENDIF
NONLIN=IOPT(31)
IF (IOPT(38).EQ.0) QBDAMP = NONLIN.EQ.4
IF (IOPT(38).EQ.1) QBDAMP = .TRUE.
IF (IOPT(38).EQ.2) QBDAMP = .FALSE.
IF (QBDAMP) THEN
IF (RWK(20).LT.ONE) RWK(20) = TEN
ENDIF
10064 FORMAT(' Rank-1 updates are ',A)
IF (QINIMO) THEN
IF (QRANK1) THEN
WRITE(LUMON,10064) 'allowed'
ELSE
WRITE(LUMON,10064) 'inhibited'
ENDIF
10065 FORMAT(' Problem is specified as being ',A)
IF (NONLIN.EQ.1) THEN
WRITE(LUMON,10065) 'linear'
ELSE IF (NONLIN.EQ.2) THEN
WRITE(LUMON,10065) 'mildly nonlinear'
ELSE IF (NONLIN.EQ.3) THEN
WRITE(LUMON,10065) 'highly nonlinear'
ELSE IF (NONLIN.EQ.4) THEN
WRITE(LUMON,10065) 'extremely nonlinear'
ENDIF
10066 FORMAT(' Bounded damping strategy is ',A,:,/,
$ ' Bounding factor is ',D10.3)
IF (QBDAMP) THEN
WRITE(LUMON,10066) 'active', RWK(20)
ELSE
WRITE(LUMON,10066) 'off'
ENDIF
10067 FORMAT(' Special mode: ',A,' Newton iteration will be done')
IF (IOPT(33).EQ.1) WRITE(LUMON,10067) 'Ordinary'
IF (IOPT(34).EQ.1) WRITE(LUMON,10067) 'Simplified'
ENDIF
! Maximum permitted number of iteration steps
NITMAX=IWK(31)
IF (NITMAX.LE.0) NITMAX=50
IWK(31)=NITMAX
10068 FORMAT(' Maximum permitted number of iteration steps : ',
$ I6)
IF (QINIMO) WRITE(LUMON,10068) NITMAX
! Initial damping factor for highly nonlinear problems
QFCSTR=RWK(21).GT.ZERO
IF (.NOT.QFCSTR) THEN
RWK(21)=1.0D-2
IF (NONLIN.EQ.4) RWK(21)=1.0D-4
ENDIF
! Minimal permitted damping factor
IF (RWK(22).LE.ZERO) THEN
RWK(22)=1.0D-4
IF (NONLIN.EQ.4) RWK(22)=1.0D-8
ENDIF
FCMIN=RWK(22)
! Rank1 decision parameter SIGMA
IF (RWK(23).LT.ONE) RWK(23)=3.0D0
IF (.NOT.QRANK1) RWK(23)=10.0D0/FCMIN
! Decision parameter about increasing too small predictor
! to greater corrector value
IF (RWK(24).LT.ONE) RWK(24)=10.0D0/FCMIN
! Starting value of damping factor (FCMIN.LE.FC.LE.1.0)
IF(NONLIN.LE.2.AND..NOT.QFCSTR)THEN
! for linear or mildly nonlinear problems
FC = ONE
ELSE
! for highly or extremely nonlinear problems
FC = RWK(21)
ENDIF
! Simplied Newton iteration implies ordinary Newton it. mode
IF (IOPT(34).EQ.1) IOPT(33)=1
! If ordinary Newton iteration, factor is always one
IF (IOPT(33).EQ.1) FC=1.0D0
RWK(21)=FC
IF (MPRMON.GE.2.AND..NOT.QSUCC) THEN
10069 FORMAT(//,' Internal parameters:',//,
$ ' Starting value for damping factor FCSTART = ',D9.2,/,
$ ' Minimum allowed damping factor FCMIN = ',D9.2,/,
$ ' Rank-1 updates decision parameter SIGMA = ',D9.2)
WRITE(LUMON,10069) RWK(21),FCMIN,RWK(23)
ENDIF
! Store lengths of currently required workspaces
IWK(18) = NIFRIN-1
IWK(19) = NRFRIN-1
!
! Initialize and start time measurements monitor
!
IF ( IOPT(1).EQ.0 .AND. MPRTIM.NE.0 ) THEN
CALL MONINI (' NLEQ1',LUTIM)
CALL MONDEF (0,'NLEQ1')
CALL MONDEF (1,'FCN')
CALL MONDEF (2,'Jacobi')
CALL MONDEF (3,'Lin-Fact')
CALL MONDEF (4,'Lin-Sol')
CALL MONDEF (5,'Output')
CALL MONSTR (IERR)
ENDIF
!
!
!
IERR=-1
! If IERR is unmodified on exit, successive steps are required
! to complete the Newton iteration
IF (NBROY.EQ.0) NBROY=1
CALL N1INT(N,FCN,JAC,X,XSCAL,RTOL,NITMAX,NONLIN,IOPT,IERR,
$ LRWK,RWK,NRFRIN,LIWK,IWK,NIFRIN,
$ M1,M2,NBROY,
$ RWK(L4),RWK(L41),RWK(L5),RWK(L51),RWK(L6),RWK(L63),RWK(L61),
$ RWK(L7),
$ RWK(L71),RWK(L9),RWK(L62),RWK(L11),RWK(L12),RWK(L121),RWK(L13),
$ RWK(21),RWK(22),RWK(23),RWK(24),RWK(IRWKI+1),RWK(IRWKI),
$ RWK(IRWKI+2),RWK(IRWKI+3),RWK(17),RWK(18),RWK(IRWKI+4),RWK(19),
$ MSTOR,MPRERR,MPRMON,MPRSOL,LUERR,LUMON,LUSOL,IWK(1),IWK(3),
$ IWK(4),IWK(5),IWK(8),IWK(9),IWK(33),IWK(24),QBDAMP)
!
IF (MPRTIM.NE.0.AND.IERR.NE.-1.AND.IERR.NE.10) THEN
CALL MONHLT
CALL MONPRT
ENDIF
!
! Free workspaces, so far not used between steps
IWK(16) = NIWKFR
IWK(17) = NRWKFR
ENDIF
! Print statistics
IF (MPRMON.GE.1.AND.IERR.NE.-1.AND.IERR.NE.10) THEN
10080 FORMAT(/, ' ****** Statistics * ', A8, ' *******', /,
$ ' *** Newton iterations : ', I7,' ***', /,
$ ' *** Corrector steps : ', I7,' ***', /,
$ ' *** Rejected rk-1 st. : ', I7,' ***', /,
$ ' *** Jacobian eval. : ', I7,' ***', /,