-
Notifications
You must be signed in to change notification settings - Fork 0
/
nleq2.c
4567 lines (4209 loc) · 155 KB
/
nleq2.c
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
/* nleq2.f -- translated by f2c (version 20100827).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
#include "nleq2.h"
/* Table of constant values */
static integer c__1 = 1;
static integer c__0 = 0;
static integer c__2 = 2;
static integer c__3 = 3;
static integer c__4 = 4;
static integer c__5 = 5;
static integer c__9 = 9;
/* Original */
//int nleq2_(integer *n, U_fp fcn, U_fp jac, doublereal *x,
// doublereal *xscal, doublereal *rtol, integer *iopt, integer *ierr,
// integer *liwk, integer *iwk, integer *lrwk, doublereal *rwk)
/* Subroutine */
DLLEXPORT int STDCALL NLEQ2(integer *n, c_NLMFCN fcn, U_fp jac, doublereal *x,
doublereal *xscal, doublereal *rtol, integer *iopt, integer *ierr,
integer *liwk, integer *iwk, integer *lrwk, doublereal *rwk)
{
/* Initialized data */
static char prodct[8] = "NLEQ2 ";
/* Format strings */
static char fmt_10000[] = "(\002 N L E Q 2 ***** V e r s i o n "
"\002,\0022 . 3 ***\002,//,1x,\002Newton-Method \002,\002for the "
"solution of nonlinear systems\002,//)";
static char fmt_10050[] = "(\002 Real Workspace declared as \002,i9"
",\002 is used up to \002,i9,\002 (\002,f5.1,\002 percent)\002,//,"
"\002 Integer Workspace declared as \002,i9,\002 is used up to"
" \002,i9,\002 (\002,f5.1,\002 percent)\002,//)";
static char fmt_10051[] = "(/,\002 N =\002,i4,//,\002 Prescribed relativ"
"e \002,\002precision\002,d10.2,/)";
static char fmt_10052[] = "(\002 The Jacobian is supplied by \002,a)";
static char fmt_10057[] = "(\002 Automatic row scaling of the Jacobian i"
"s \002,a,/)";
static char fmt_10064[] = "(\002 Rank-1 updates are \002,a)";
static char fmt_10065[] = "(\002 Problem is specified as being \002,a)";
static char fmt_10066[] = "(\002 Bounded damping strategy is \002,a,:,/"
",\002 Bounding factor is \002,d10.3)";
static char fmt_10068[] = "(\002 Maximum permitted number of iteration s"
"teps : \002,i6)";
static char fmt_10069[] = "(//,\002 Internal parameters:\002,//,\002 Sta"
"rting value for damping factor FCSTART = \002,d9.2,/,\002 Minimu"
"m allowed damping factor FCMIN = \002,d9.2,/,\002 Rank-1 updates"
" decision parameter SIGMA = \002,d9.2,/,\002 Initial Jacobian ps"
"eudo-rank IRANK =\002,i6,/,\002 Maximum permitted subcondition C"
"OND = \002,d9.2)";
static char fmt_10080[] = "(/,\002 ****** Statistics * \002,a8,\002 *"
"******\002,/,\002 *** Newton iterations : \002,i7,\002 **"
"*\002,/,\002 *** Corrector steps : \002,i7,\002 ***\002,/"
",\002 *** Rejected rk-1 st. : \002,i7,\002 ***\002,/,\002 "
"*** Jacobian eval. : \002,i7,\002 ***\002,/,\002 *** Fun"
"ction eval. : \002,i7,\002 ***\002,/,\002 *** ... for Ja"
"cobian : \002,i7,\002 ***\002,/,\002 ************************"
"*************\002,/)";
static char fmt_10090[] = "(///,20(\002*\002),\002Workspace Error\002,"
"20(\002*\002))";
static char fmt_10091[] = "(/,\002 Real Workspace dimensioned as\002,1x,"
"i9,1x,\002must be enlarged at least up to \002,i9,//)";
static char fmt_10092[] = "(/,\002 Integer Workspace dimensioned as \002"
",i9,\002 must be enlarged at least up \002,\002to \002,i9,//)";
/* System generated locals */
integer i__1;
/* Builtin functions */
integer s_wsfe(cilist *), e_wsfe(void), do_fio(integer *, char *, ftnlen);
/* Local variables */
extern /* Subroutine */ int zibconst_(doublereal *, doublereal *);
static integer m1, m2, l4, l5, l6, l7, l8, l9;
static doublereal fc;
static integer l11, l12, l13, l41, l51, l61, l62, l63, l71, l20, l111,
l121, niw, nrw;
static doublereal cond;
static integer liwl, lrwl;
extern /* Subroutine */ int n2int_(integer *, U_fp, U_fp, doublereal *,
doublereal *, doublereal *, integer *, integer *, integer *,
integer *, integer *, integer *, doublereal *, integer *, integer
*, integer *, integer *, integer *, integer *, integer *, integer
*, integer *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, integer *, integer *, integer *,
integer *, integer *, integer *, integer *, integer *, integer *,
integer *, integer *, integer *, integer *, logical *);
static doublereal fcmin, perci;
static integer irank;
static doublereal small, percr;
static logical qvchk, qsucc;
static integer luerr, lumon, lutim, nbroy, lusol;
extern /* Subroutine */ int n2pchk_(integer *, doublereal *, doublereal *,
doublereal *, integer *, integer *, integer *, integer *,
integer *, doublereal *);
static logical qrank1;
static integer jacgen;
static doublereal epmach;
static logical qbdamp;
extern /* Subroutine */ int mondef_(integer *, char *, ftnlen);
static integer nifrin;
extern /* Subroutine */ int monini_(char *, integer *, ftnlen);
static logical qinimo;
static integer nonlin, nrfrin, nitmax, niwkfr;
static logical qfcstr;
extern /* Subroutine */ int monhlt_(void);
static integer mprerr, mprmon, nrwkfr, mprtim, mprsol;
extern /* Subroutine */ int monprt_(void), monstr_(integer *);
/* Fortran I/O blocks */
static cilist io___16 = { 0, 0, 0, fmt_10000, 0 };
static cilist io___50 = { 0, 0, 0, fmt_10050, 0 };
static cilist io___51 = { 0, 0, 0, fmt_10051, 0 };
static cilist io___52 = { 0, 0, 0, fmt_10052, 0 };
static cilist io___53 = { 0, 0, 0, fmt_10052, 0 };
static cilist io___54 = { 0, 0, 0, fmt_10052, 0 };
static cilist io___55 = { 0, 0, 0, fmt_10057, 0 };
static cilist io___56 = { 0, 0, 0, fmt_10057, 0 };
static cilist io___59 = { 0, 0, 0, fmt_10064, 0 };
static cilist io___60 = { 0, 0, 0, fmt_10064, 0 };
static cilist io___61 = { 0, 0, 0, fmt_10065, 0 };
static cilist io___62 = { 0, 0, 0, fmt_10065, 0 };
static cilist io___63 = { 0, 0, 0, fmt_10065, 0 };
static cilist io___64 = { 0, 0, 0, fmt_10065, 0 };
static cilist io___65 = { 0, 0, 0, fmt_10066, 0 };
static cilist io___66 = { 0, 0, 0, fmt_10066, 0 };
static cilist io___68 = { 0, 0, 0, fmt_10068, 0 };
static cilist io___74 = { 0, 0, 0, fmt_10069, 0 };
static cilist io___75 = { 0, 0, 0, fmt_10080, 0 };
static cilist io___76 = { 0, 0, 0, fmt_10090, 0 };
static cilist io___77 = { 0, 0, 0, fmt_10091, 0 };
static cilist io___78 = { 0, 0, 0, fmt_10092, 0 };
/* * Begin Prologue NLEQ2 */
/* ------------------------------------------------------------ */
/* * 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 with rank- */
/* strategy (see references below) */
/* * Category F2a. - Systems of nonlinear equations */
/* * Keywords Nonlinear equations, Newton methods */
/* * Version 2.3 */
/* * Revision September 1991 */
/* * Latest Change January 2006 */
/* * 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 Bodo Erdmann */
/* 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 with rank strategy for systems of */
/* highly nonlinear equations - damping strategy due to Ref.(1). */
/* (The iteration is done by subroutine N2INT currently. NLEQ2 */
/* 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 DECCON and SOLCON (QR de- */
/* composition with subcondition estimation, rank decision and */
/* computation of the rank-deficient pseudoinverse) . */
/* For special purposes these routines may be substituted. */
/* This is a driver routine for the core solver N2INT. */
/* ------------------------------------------------------------ */
/* * 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: NLEQ2 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 NLEQ2, */
/* if set to a negative value on output */
/* * Input parameters of NLEQ2 */
/* ========================= */
/* 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 NLEQ2 */
/* ========================== */
/* * 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 iteration */
/* > 0 see list of error messages below */
/* Note 1. */
/* The machine dependent values SMALL, GREAT and EPMACH are */
/* gained from calls of the machine constants function ZIBCONST. */
/* As delivered, this function is adapted to use constants */
/* suitable for all machines with IEEE arithmetic. If you use */
/* another type of machine, you have to change ZIBCONST to */
/* statements suitable for your machine. */
/* * Workspace parameters of NLEQ2 */
/* ============================= */
/* LIWK Int Declared dimension of integer */
/* workspace. */
/* Required minimum (for standard linear system */
/* solver) : N+52 */
/* * 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 */
/* expression noted below by N): */
/* (N+NBROY+15)*N+61 */
/* NBROY = Maximum number of Broyden steps */
/* (Default: if Broyden steps are enabled, e.g. */
/* IOPT(32)=1 - */
/* NBROY=MAX(N,10) */
/* else (if IOPT(32)=0) - */
/* NBROY=0 ; */
/* see equally named IWK-field 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: */
/* NLEQ2 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: */
/* NLEQ2 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 NLEQ2 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 subroutine N2JAC) */
/* =3 Jacobian approximation by numerical */
/* differentation with feedback control */
/* (see subroutine N2JCF) */
/* 4..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 4a. */
/* 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 */
/* NLEQ2 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..34 Reserved */
/* 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 4b) */
/* Note 3: */
/* If NLEQ2 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 4a: */
/* The integrated time monitor calls the machine dependent */
/* subroutine ZIBSEC 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 4b: */
/* The user options may be interpreted by the user replacable */
/* routines N2SOUT, N2FACT, N2SOLV - the distributed version */
/* of N2SOUT 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 solver: N+53 */
/* 17 NRWKFR OUT First element of RWK which is free to be used */
/* as workspace between Newton iteration steps. */
/* For standard linear solver and numerically */
/* approximated Jacobian computed by the */
/* expression: (N+9+NBROY)*N+62 */
/* If the Jacobian is computed by a user routine */
/* JAC, subtract N in this expression. */
/* 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 N2FACT (IERR=80), */
/* N2SOLV (IERR=81), FCN (IERR=82) or JAC(IERR=83) */
/* to the nonzero IFAIL value returned by the */
/* routine indicating the failure . */
/* 24..30 Reserved */
/* 31 NITMAX IN Maximum number of permitted iteration */
/* steps (default: 50) */
/* 32 IRANK IN Initial rank of the Jacobian */
/* (at the iteration starting point) */
/* =0 : full rank N */
/* =k with min_rank <= k < N : */
/* deficient rank assumed, */
/* where min_rank = max (1,N-max(N/10,10)) */
/* 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 5) */
/* 22 FCMIN IN Minimal allowed damping factor (see note 5) */
/* 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 5) */
/* 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 COND IN Maximum permitted subcondition for rank- */
/* decision by linear solver. */
/* (Default: 1/epmach, epmach: relative */
/* machine precision) */
/* 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 5: */
/* 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 at stationary point (rank deficient Jacobian */
/* and termination criterion fulfilled) */
/* 2 Termination after NITMAX iterations ( as indicated by */
/* input parameter NITMAX=IWK(31) ) */
/* 3 Termination, since damping factor became to small and */
/* rank of Jacobian matrix is already zero */
/* 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 N2FACT, */
/* for more detailed information see IFAIL-value */
/* stored to IWK(23) */
/* (not used by standard routine N2FACT) */
/* 81 Error signalled by linear solver routine N2SOLV, */
/* for more detailed information see IFAIL-value */
/* stored to IWK(23) */
/* (not used by standard routine N2SOLV) */
/* 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 6 : in case of failure: */
/* - use non-standard options */
/* - use another initial guess */
/* - or reformulate model */
/* - or apply continuation techniques */
/* * Machine dependent constants used: */
/* ================================= */
/* DOUBLE PRECISION EPMACH in NLEQ2, N2PCHK, N2INT */
/* DOUBLE PRECISION GREAT in N2PCHK */
/* DOUBLE PRECISION SMALL in N2PCHK, N2INT, N2SCAL */
/* * Subroutines called: N2PCHK, N2INT, ZIBCONST */
/* ------------------------------------------------------------ */
/* * End Prologue */
/* * Summary of changes: */
/* =================== */
/* 2.2.1 91, June 3 Time monitor included */
/* 2.2.2 91, June 3 Bounded damping strategy implemented */
/* 2.2.3 91, July 26 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 16 Convergence order monitor included */
/* 2.2.5 91, August 19 Standard Broyden updates replaced by */
/* iterative Broyden */
/* 91, Sept. Rank strategy modified */
/* DECCON with new fail exit, for the case that */
/* the square root of a negative number will */
/* appear during pseudo inverse computation. */
/* (Occured, although theoretical impossible!) */
/* 2.2.6 91, Sept. 17 Damping factor reduction by FCN-fail imple- */
/* mented */
/* 2.3 91, Dec. 20 New Release for CodeLib */
/* 00, July 12 RTOL output-value bug fixed */
/* 06, Jan. 24 IERR=5 no longer returned if residuum of */
/* final iterate is exactly zero */
/* 10, July 26 Subroutine N2INT: 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,L41,L5,L51,L6,L61,L62,L63,L7,L71,L9,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..LRWKI-1) Free */
/* Internal arrays stored in RWK (see routine N2INT for descriptions) */
/* Position Array Type Remarks */
/* L4 QA(N,N) Perm Arrays QA and DXSAVE need never to */
/* L4 DXSAVE(N,NBROY) be kept the same time and therefore */
/* Perm may be stored to the same workspace */
/* part */
/* L41 A(N,N) Perm */
/* 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 */
/* L8 Perm Start position of array workspace */
/* needed for linear solver */
/* L9 XW(N) Temp */
/* L11 DXQA(N) Temp */
/* L111 QU(N) Temp */
/* L12 T1(N) Temp */
/* L121 T2(N) Temp */
/* L13 T3(N) Temp Not yet used or even reserved */
/* (for future band mode implementat.) */
/* Which version ? */
/* Version: 2.3.0.2 Latest change: */
/* ----------------------------------------- */
/* Parameter adjustments */
--xscal;
--x;
--iopt;
--iwk;
--rwk;
/* Function Body */
/* * Begin */
zibconst_(&epmach, &small);
*ierr = 0;
qvchk = iwk[12] < 0;
iwk[12] = 21122302;
if (qvchk) {
return 0;
}
/* Print error messages? */
mprerr = iopt[11];
luerr = iopt[12];
if (luerr == 0) {
luerr = 6;
iopt[12] = luerr;
}
/* Print iteration monitor? */
mprmon = iopt[13];
lumon = iopt[14];
if (lumon <= 0 || lumon > 99) {
lumon = 6;
iopt[14] = lumon;
}
/* Print intermediate solutions? */
mprsol = iopt[15];
lusol = iopt[16];
if (lusol == 0) {
lusol = 6;
iopt[16] = lusol;
}
/* Print time summary statistics? */
mprtim = iopt[19];
lutim = iopt[20];
if (lutim == 0) {
lutim = 6;
iopt[20] = lutim;
}
qsucc = iopt[1] == 1;
qinimo = mprmon >= 1 && ! qsucc;
/* Print NLEQ2 heading lines */
if (qinimo) {
/* L10000: */
io___16.ciunit = lumon;
s_wsfe(&io___16);
e_wsfe();
}
/* Check input parameters and options */
n2pchk_(n, &x[1], &xscal[1], rtol, &iopt[1], ierr, liwk, &iwk[1], lrwk, &
rwk[1]);
/* Exit, if any parameter error was detected till here */
if (*ierr != 0) {
return 0;
}
m1 = *n;
m2 = *n;
jacgen = iopt[3];
if (jacgen == 0) {
jacgen = 2;
}
iopt[3] = jacgen;
qrank1 = iopt[32] == 1;
if (qrank1) {
nbroy = iwk[36];
if (nbroy == 0) {
nbroy = max(m2,10);
}
iwk[36] = nbroy;
} else {
nbroy = 0;
}
/* WorkSpace: RWK */
l4 = 61;
l41 = l4 + nbroy * *n;
l5 = l41 + m1 * *n;
l51 = l5 + *n;
l6 = l51 + *n;
l61 = l6 + *n;
l62 = l61 + *n;
l63 = l62 + *n;
l7 = l63 + *n;
l71 = l7 + *n;
if (jacgen != 3) {
l8 = l71;
} else {
l8 = l71 + *n;
}
nrwkfr = l8;
l9 = *lrwk + 1 - *n;
l11 = l9 - *n;
l111 = l11 - *n;
l12 = l111 - *n;
l121 = l12 - *n;
/* L13 : Work array T3, for future band mode implementation */
l13 = l121;
nrw = nrwkfr + *lrwk - l13 + 1;
/* End WorkSpace at NRW */
/* WorkSpace: IWK */
l20 = 51;
niwkfr = l20;
niw = niwkfr - 1;
nifrin = niwkfr;
nrfrin = nrwkfr;
liwl = *n + 2;
lrwl = (*n << 1) + 1;
if (qrank1) {
nrwkfr += lrwl;
niwkfr += liwl;
}
nrw += lrwl;
niw += liwl;
/* End WorkSpace at NIW */
iwk[16] = niwkfr;
iwk[17] = nrwkfr;
if (nrw > *lrwk || niw > *liwk) {
*ierr = 10;
} else {
if (qinimo) {
percr = (doublereal) nrw / (doublereal) (*lrwk) * 100.;
perci = (doublereal) niw / (doublereal) (*liwk) * 100.;
/* Print statistics concerning workspace usage */
/* L10050: */
io___50.ciunit = lumon;
s_wsfe(&io___50);
do_fio(&c__1, (char *)&(*lrwk), (ftnlen)sizeof(integer));
do_fio(&c__1, (char *)&nrw, (ftnlen)sizeof(integer));
do_fio(&c__1, (char *)&percr, (ftnlen)sizeof(doublereal));
do_fio(&c__1, (char *)&(*liwk), (ftnlen)sizeof(integer));
do_fio(&c__1, (char *)&niw, (ftnlen)sizeof(integer));
do_fio(&c__1, (char *)&perci, (ftnlen)sizeof(doublereal));
e_wsfe();
}
if (qinimo) {
/* L10051: */
io___51.ciunit = lumon;
s_wsfe(&io___51);
do_fio(&c__1, (char *)&(*n), (ftnlen)sizeof(integer));
do_fio(&c__1, (char *)&(*rtol), (ftnlen)sizeof(doublereal));
e_wsfe();
/* L10052: */
if (jacgen == 1) {
io___52.ciunit = lumon;
s_wsfe(&io___52);
do_fio(&c__1, "a user subroutine", (ftnlen)17);
e_wsfe();
} else if (jacgen == 2) {
io___53.ciunit = lumon;
s_wsfe(&io___53);
do_fio(&c__1, "numerical differentiation (without feedback s"
"trategy)", (ftnlen)53);
e_wsfe();
} else if (jacgen == 3) {
io___54.ciunit = lumon;
s_wsfe(&io___54);
do_fio(&c__1, "numerical differentiation (feedback strategy "
"included)", (ftnlen)54);
e_wsfe();
}
/* L10057: */
if (iopt[35] == 1) {
io___55.ciunit = lumon;
s_wsfe(&io___55);
do_fio(&c__1, "inhibited", (ftnlen)9);
e_wsfe();
} else {
io___56.ciunit = lumon;
s_wsfe(&io___56);
do_fio(&c__1, "allowed", (ftnlen)7);
e_wsfe();
}
}
nonlin = iopt[31];
if (iopt[38] == 0) {
qbdamp = nonlin == 4;
}
if (iopt[38] == 1) {
qbdamp = TRUE_;
}
if (iopt[38] == 2) {
qbdamp = FALSE_;
}
if (qbdamp) {
if (rwk[20] < 1.) {
rwk[20] = 10.;
}
}
/* L10064: */
if (qinimo) {
if (qrank1) {
io___59.ciunit = lumon;
s_wsfe(&io___59);
do_fio(&c__1, "allowed", (ftnlen)7);
e_wsfe();
} else {
io___60.ciunit = lumon;