/
Ua2D_DefaultParameters.m
executable file
·2291 lines (2003 loc) · 121 KB
/
Ua2D_DefaultParameters.m
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
function CtrlVar=Ua2D_DefaultParameters
%%
% CtrlVar=Ua2D_DefaultParameters
%
% sets the fields of the CtrlVar to their default values
%
%
%%
%
% Most likely when running Ua, only a fairly limited number of the parameters listed below need to be set/changed.
% Changing the parameter values from their default values should be done by the user in `DefineInitialUserInput.m'.
% That user m-file should be located in a separate run-directory, together with all the other user m-files
%%
CtrlVar.WhoAmI="Ua2D CtrlVar" ;
%%
CtrlVar.Experiment='UaDefaultRun';
CtrlVar.time=0; % In a transient run this variable is the (model) time. Set to some
% reasonable initial value, for example CtrlVar.time=0;
%% Types of run
%
CtrlVar.UaRunType="" ; % "-uvh-" , "-uv-h-" , "-uv-" , "-h-" ;
CtrlVar.TimeDependentRun=0 ; % either [0|1].
% If true (i.e. set to 1) then the run is a forward transient one, if not
% then velocities based on the current geometry are calculated.
CtrlVar.InverseRun=0; % if true then a surface-to-bed inversion is to be performed.
% (in an inverse run the value of CtrlVar.TimeDependentRun is irrelevant)
CtrlVar.Restart=0; % If true then the run is a restart run. Note that this variable applies to both forward and inverse runs.
% For example setting:
% CtrlVar.InverseRun=1;
% CtrlVar.Restart=1;
% results in a restart of an inverse run. (make sure a corresponding restart file does exist, see below.)
%
CtrlVar.Implicituvh=1; % 0: prognostic run is semi-implicit (implicit with respect to h only)
% 1: prognostic run is fully-implicit (implicit with respect to uvh)
CtrlVar.TotalNumberOfForwardRunSteps=1; % maximum number of forward run steps. In a transient run this will be the maximum number of time steps.
% In a non-transient (stationary) run, this will be the maximum number of diagnostic calculations.
% (Typically, the number of forward run steps in a non-transient run will be 1, and the user must make sure to set
% the value accordingly, i.e. CtrlVar.TotalNumberOfForwardRunSteps=1;)
% In a restart run, TotalNumberOfForwardRunSteps is the total number of run steps done within that restart run, i.e.
% not the total accumulated number of forward run steps.
CtrlVar.UseUserDefinedRunStopCriterion=false ;
%% Ice flow approximation
CtrlVar.FlowApproximation="SSTREAM" ; % any of ['SSTREAM'|'SSHEET'|'Hybrid']
% Note, both SSTREAM and SSHEET are implemented.
% But Hybrid is still in development and should not be used for the time being.
CtrlVar.MustBe.FlowApproximation=["SSTREAM","SSHEET","Hybrid","SSTREAM-rho","uvhPrescribed"] ;
%% Slope of coordinate system with respect to gravity
CtrlVar.alpha=0 ;
%% Sliding law
%
% Several sliding laws can be defined. These include *Weertman* (power-law relationship
% between basal drag and velocity, i.e. u=C tau^m ) and *Coulomb* friction (basal drag equal a constant times
% effective pressure, i.e. tau = mu N). When using Coulomb friction define mu in
% DefineSlipperiness.m instead of C.
%
% The other sliding laws are all just different ways of combining Weertman and Coulomb.
%
% If the drag calculated using Weertman law is TauW and that calculated using Coulomb law
% is TauC, while Tau is the drag used, then
%
% *Tsai:* Tau=min(TauC,TauW)
%
% *Conford:* 1/Tau^m = 1/TauC^m + 1/TauW^m
%
%
% The *Budd* sliding law is a simple extension of the Weertman sliding law where:
%
% u = C tau^m/N^q
%
% The effective pressure is currently only calculated using a 'zeroth-order' hydrology
% model, where N=rho g (h-h_f) where h_f is the flotation thickness.
%
CtrlVar.SlidingLaw="Weertman" ;
CtrlVar.MustBe.SlidingLaw=["Weertman","Budd","Tsai","Coulomb","Cornford","Umbi","Joughin","W","W-N0","minCW-N0","C","rpCW-N0","rCW-N0","rCW-V0"] ;
%% Boundary conditions
CtrlVar.UpdateBoundaryConditionsAtEachTimeStep=0; % if true, `DefineBoundaryConditions.m' is called at the beginning of each time step to update the boundary conditions.
% otherwise boundary conditions are only updated at the beginning of the run (also at the beginning or a restart run).
% Note that whenever the finite-element mesh is modified (for example during mesh refinement),
% the boundary conditions are updated through a call to DefineBoundaryConditions.m
CtrlVar.BCsWeights=1; % test parameter, do not change
CtrlVar.LinFEbasis=false; % test parameter, do not change
%
%% Ensuring flotation
%
% Where the ice is afloat the upper and lower surfaces (s and b), the ocean
% surface (S) and bedrock (B) and ice density (rho) and ocean density (rhow)
% become interlinked.
%
% Generally, s and b are always calculated from h, B and S given rho and rhow.
% This is done internally at various different stages. Note that s and b, as
% returned by the user in DefineGeometry.m, will be changed to ensure flotation.
%
% It is possible to change the default behavior and calculate h and b from s, B
% and S.
CtrlVar.Calculate.Geometry="bs-FROM-hBS" ; % {"bs-FROM-hBS" ; "bh-FROM-sBS" }
%% Manually updating geometry in the course of a run.
% By default DefineGeometry is only called at the beginning of a run, and after
% any mesh modifications such as re-meshing.
%
% However, it is possible to force additional `manual' updates to geometry
% in a forward run. A `manual' update is simply a call to DefineGeometry.m where the
% geometry is then defined by the user.
%
% The geometrical variables are: s, b, B and S.
%
% To specify which geometrical variables should be updated/modified set the following
% stings accordingly:
%
CtrlVar.GeometricalVarsDefinedEachDiagnosticRunStepByDefineGeometry="";
CtrlVar.GeometricalVarsDefinedEachTransienRunStepByDefineGeometry="";
%
% Possible values for these stings are any combinations of "-s-b-S-B-rho-rhow-g-".
%
% Examples:
%
% CtrlVar.GeometricalVarsDefinedEachTransienRunStepByDefineGeometry="-S-";
%
% forces an update of the ocean surface, S, within each time step. This could, for example, be used to specify a time varying ocean surface
% elevation due to tides. Hence, DefineGeometry will be called at each transient with FieldsToBeDefined='S'
%
% CtrlVar.GeometricalVarsDefinedEachDiagnosticRunStepByDefineGeometry="-s-b-S-B-rho-rhow-g-";
%
% forces all geometrical variables, i.e. upper ice surface (s), lower ice surface (b), ocean surface (S), and bedrock (B) to be defined in each
% diagnostic run step through a call to DefineGeometry with FieldsToBeDefined='-s-b-S-B-rho-rhow-g-'
%
% The default option is not to modify any geometrical variables manually within a run step.
%
%%
CtrlVar.TestForRealValues=1;
CtrlVar.IgnoreComplexPart=1; % it is possible that when solving an asymmetrical system,
% numerical errors cause the solution to no longer be real.
% In that case, set to true to simply ignore complex part.
%% Element type
%
% The options are: linear, quadratic, or cubic Lagrangian triangle elements
CtrlVar.TriNodes=3 ; % Possible values are 3, 6, 10 node (linear/quadratic/cubic)
CtrlVar.MustBe.TriNodes=[3,6,10] ; % Possible values are 3, 6, 10 node (linear/quadratic/cubic)
%% Control on transient runs
% Once either the number of time steps or total time modeled reaches prescribed values
% the run stops.
CtrlVar.TotalTime=1e10; % maximum model time
CtrlVar.dt=1; % time step (usually overwritten by user by defining dt in the DefineInitialUserInputFile
CtrlVar.dtmin=1e-12; % for numerical reasons the time step should always be larger than some very small value
CtrlVar.InitialDiagnosticStep=0; % Start a transient run with an initial diagnostic step, even if the step is a restart step.
% Irrespective of the value of this variable, an initial diagnostic step is always performed at the beginning of a transient run if it is not a restart run.
% An initial diagnostic step is therefore done at the beginning of a transient run if:
% 1) so demanded by the user, i.e. if the user sets CtrlVar.InitialDiagnosticStep=1, and
% 2) at always at the start of an implicit uvh transient run which is not a
% restart run.
% However, unless demanded by the user, no initial diagnostic step is done at the beginning of a transient restart run.
CtrlVar.InitialDiagnosticStepAfterRemeshing=0 ; % Forces a diagnostic calculation after re-meshing.
% Note: a diagnostic calculation is always done after global re-meshing
% irrespective of the value of this parameter. However, after local re-meshing,
% and provided CtrlVar. LocalAdaptMeshSmoothingIterations=0, a diagnostic calculation is
% not performed unless this parameter is set to true.
%% Restart option
CtrlVar.Restart=0; % either 0/false or 1/true. Set to 1 for a restart run. (This also work for inverse runs. See below.)
CtrlVar.WriteRestartFile=1; % if true, a restart file is written
CtrlVar.WriteRestartFileInterval=100; % restart file written at this time-step interval (note, these are run steps, not model time)
CtrlVar.ResetTime=0 ; % set to 1 to reset (model) time at start of restart run
CtrlVar.RestartTime=NaN; % if ResetTime is true, then this is the model time at the start of the restart run
CtrlVar.ResetTimeStep=0; % true if time step should be reset to the dt value given in the Ua2D_InitialUserInputFile
CtrlVar.ResetRunStepNumber=0; % if true, RunStepNumber is set to zero at the beginning of a restart run.
CtrlVar.NameOfRestartFiletoRead='Ua2D_Restartfile.mat';
CtrlVar.NameOfRestartFiletoWrite='Ua2D_Restartfile.mat';
%%
CtrlVar.SaveAdaptMeshFileName=[]; % file name for saving adapt mesh. If left empty, no file is written
%% Plotting
%
% Most plotting is typically done by the user using his own version of the m-file
%
% DefineOutputs.m
%
% or in a separate post-processing step.
%
% However, some basic plots can be generated directly from within Ua.
%
CtrlVar.doplots=1; % if true then plotting during runs by Ua are allowed, set to 0 to suppress all plots
CtrlVar.PlotXYscale=1000; % used to scale x and y axis of some of the figures, only used for plotting purposes
CtrlVar.PlotWaitBar=1; % a waitbar is plotted
CtrlVar.doAdaptMeshPlots=1; % if true and if CtrlVar.doplots true also, then do some extra plotting related to adapt meshing
CtrlVar.PlotOceanLakeNodes=0; % Shows which nodes are considered a part of the `ocean' and which are within `lakes' that have no connection the ocean
CtrlVar.PlotMeltNodes=0;
% (if spatial units are in meters, setting this to 1000 produces xy axis with the units km)
CtrlVar.PlotsXaxisLabel='x' ; CtrlVar.PlotsYaxisLabel='y' ; %
CtrlVar.MinSpeedWhenPlottingVelArrows=0; % when plotting vel arrows with smaller speed are scaled so that their speed its
% equal to this value (setting this to a large value makes all arrows
% equally long)
CtrlVar.BoundaryConditionsFixedNodeArrowScale=1; % Determines the size of arrows indicating boundary conditions when plotting boundary conditions.
% The arrows are automatically scales with respect to mesh size, but if they are
% too small or too large this parameter can be used to affect their size.
CtrlVar.PlotSUPGparameter=0;
CtrlVar.PlotPosition=[100 100 1000 1000];
CtrlVar.Plot.Units.xDistance="m" ;
CtrlVar.Plot.Units.yDistance="m" ;
CtrlVar.Plot.Units.zDistance="m" ;
CtrlVar.Plot.Units.Time="yr" ;
CtrlVar.Plot.Units.Stress="kPa" ;
%% Plotting mesh
% The mesh can be plotted within Ua by setting CtrlVar.PlotMesh=1, or by calling
% either PlotFEmesh or PlotMuaMesh (see help PlotFEmesh)
CtrlVar.PlotMesh=0; % If true then FE mesh is shown every time a new mesh is generated
CtrlVar.WhenPlottingMesh_PlotMeshBoundaryCoordinatesToo=0;
CtrlVar.PlotBCs=0; % If true then boundary conditions are shown at the beginning of the run
CtrlVar.PlotNodes=0; % If true then nodes are plotted when FE mesh is shown
CtrlVar.PlotLabels=0 ; % If true elements and nodes are labeled with their respective numbers
CtrlVar.LabelNodes=0; % Nodal labels are plotted
CtrlVar.LabelElements=0; % Element labels are plotted
CtrlVar.PlotNodesSymbol='o';
CtrlVar.PlotNodesSymbolSize=3;
CtrlVar.MeshColor='k'; CtrlVar.NodeColor='k';
%% Numerical variables related to transient runs
% In general there should be no need to ever change these values except for test purposes
%
% Transient runs can be done either (fully) implicitly, or semi-implicitly
% In a (fully) implicit approach, the time-integration is done implicitly with respect to both velocities and thickness.
% In a semi-implicit approach, the time-integration is done implicitly with respect to thickness, and explicitly with respect to velocities.
%
% There are currently two fully-implicit time-stepping methods implemented: The 'theta' and the 'supg' methods.
%
% The 'theta' method uses a weighted sum of the values at the beginning and the end of a time step.
% The weighting is controlled by CtrlVar.theta and depending on the value of theta different types of
% approximations are obtained: 0,1/2,1 gives forward Euler, Lax-Wendroff and backwards Euler, respectively.
% The 'supg' method is a Streamline-Upwind Petrov-Galerkin method. The supg-method uses the same
% weighting as the 'theta' method, but the test function for the mass-conservation equation is different.
%
% The default time-stepping method is: Fully implicit Streamline-Upwind Petrov-Galerkin with theta=0.5 (Lax Wendroff).
%
%
CtrlVar.Implicituvh=1; % 0: prognostic run is semi-implicit (implicit with respect to h only)
% 1: prognostic run is fully-implicit (implicit with respect to uvh)
CtrlVar.uvhImplicitTimeSteppingMethod="SUPG"; %
CtrlVar.uvhSemiImplicitTimeSteppingMethod="SUPG"; % 'Galerkin'|'supg'
CtrlVar.MustBe.uvhImplicitTimeSteppingMethod="SUPG"; % 'theta'|'supg' actually at the moment I've disabled the theta method...
CtrlVar.MustBe.uvhSemiImplicitTimeSteppingMethod=["TG3","Galerkin","SUPG"] ;
CtrlVar.SUPG.beta0=1 ; CtrlVar.SUPG.beta1=0 ; % parameters related to the SUPG method.
CtrlVar.theta=0.5; % theta=0 is forward Euler, theta=1 is backward Euler, theta=1/2 is Lax-Wendroff and is most accurate
CtrlVar.hTheta=0.5;
% Note: An additional time-stepping method is the Third-Order Taylor-Galerkin (TG3) method.
% It has not been fully tested but seems to work very well for fully implicit transient calculation.
% This option that can be obtained by setting:
% CtrlVar.TG3=1 ; CtrlVar.Test1=1; CtrlVar.Test0=0; CtrlVar.theta=0.5;
% and using the fully-implicit time-stepping option (CtrlVar.Implicituvh=1));
CtrlVar.TG3=0 ; % if true, the prognostic steps uses a third-order Taylor-Galerkin method
% currently only implemented for periodic boundary conditions
% Note, only theta=0.5 is strictly consistent with TG3=1, so
% for backward Euler set theta=1 and TG3=0
CtrlVar.IncludeTG3uvhBoundaryTerm=0; % keep zero (only used for testing)
CtrlVar.IncludeDirichletBoundaryIntegralDiagnostic=0; % keep zero (only used for testing)
%% Explicit estimation
%
% In a transient run u, v and h can estimated explicitly ahead of an implicit uvh
% calculation. If the explicit estimate is a good starting point, then the number of
% non-linear uvh iterations is reduced. One can either use second-order Adams-Bashforth
% method for a variable time step, or calculate dh/dt explicitly from flux convergence and
% then set h1=h0+dt dh/dt. Generally both method work fine and the Adams-Bashforth
% method used to be the default approach. However, experience has shown that occasionally
% the Adams-Bashforth extrapolation appears to give rise to a bad starting points for the
% uvh NR iteration with a loss of convergence. The "-dhdt-" option is arguably better in
% the sense that one calculates dh/dt directly from the velocity field, rather than using
% an estimate of dh/dt from the two previous solutions.
CtrlVar.ExplicitEstimationMethod="-Adams-Bashforth-" ; % {"-Adams-Bashforth-","-dhdt-"}
CtrlVar.MustBe.ExplicitEstimationMethod=["-Adams-Bashforth-","-dhdt-","-no extrapolation-"] ;
CtrlVar.LimitRangeInUpdateFtimeDerivatives=false ;
%% Numerical Regularization Parameters (note: these are not related to inverse modeling regularization)
% Note: Some of those parameters have physical dimensions and these values may have to be
% adjusted to the specific situation.
CtrlVar.SpeedZero=1e-4; % needs to be larger than 0 but should also be much smaller than any velocities of interest.
CtrlVar.EpsZero=1e-10; % needs to be larger than 0 but should also be much smaller than any effective strain rates of interest.
CtrlVar.etaZero=10; % Minimum value for the effective viscosity
% For Glens flow law the effective viscosity is 0.5 A^(-1/n) e^((1-n)/n)
% where e is the effective strain rate. The effective
% strain rate on glaciers is usually around 10^(-4) to
% 10^(-2) 1/yr. A save lower estimate for the effective viscosity would then be
% taking A for temperate ice and strain rates of 1 (1/yr).
% giving:
% n=3 ; eps=1 ; 0.5*AGlenVersusTemp(0)^(-1/n) *181 eps^((1-n)/n) =181
% So setting etaZero=10 kPa/yr would not affect the effective viscosity
% in all realistic cases. However, this might
% sometimes need to me adjusted. Before May-2023 the
% default value was etaZero=0, ie no lower limit on
% the effective viscosity, but this did occasionally
% cause numerical convergence issues.
%
% Whatever value for etaZero is selected, the value should be small compared to
% the smallest eta values based on direct use of Glen's flow law.
% This can be tested by calculating the effective
% viscosity values and plotting a histogram and making
% and inspecting the distribution and how it is
% affected by the value of etaZero, e.g.
%
% etaInt=calcStrainRatesEtaInt(CtrlVar,MUA,F.ub,F.vb,F.AGlen,F.n); figure ; histogram((log10(etaInt(:))),Normalization="probability") ; hold on ; xline(log10(CtrlVar.etaZero),'r',LineWidth=2)
%
%
CtrlVar.Czero=0 ; % must be much smaller than C.
CtrlVar.HeZero=0; % shifts the floating/grounding mask when calculating basal drag, must be << 1. (In effect this shift introduces a
% non-zero basal drag term everywhere.)
%
CtrlVar.Nzero=1e-20 ; % lower value for effective pressure
CtrlVar.CAdjointZero=CtrlVar.Czero; % used as a regularization parameter when calculating dIdCq.
CtrlVar.dbdxZero=1; % when calculating basal shear stresses in the hybrid approximation, a very large bed slope causes errors.
CtrlVar.dbdyZero=1; % a crude solution is to limit bed slopes to 45 degrees.
CtrlVar.AGlenAdjointZero=100*eps;
CtrlVar.AdjointEpsZero=CtrlVar.EpsZero;
%% Constraints on viscosity and slipperiness
% These constraints are always enforced, but only really of any importance when inverting for A and/or C.
% (Using SIA or the hybrid approximation Cmin MUST be set to 0, or at least to a value much less than Czero!)
%
switch lower(CtrlVar.FlowApproximation)
case 'sstream'
CtrlVar.Cmin=1e-20;
otherwise
CtrlVar.Cmin=0;
end
CtrlVar.Cmax=1e50;
CtrlVar.AGlenmin=1e-20;
CtrlVar.AGlenmax=1e20;
%% Non-linear iteration-loop parameters
% The non-linear system is considered solved once the residuals are smaller than
%
% CtlrVar.NLtol
%
% and the normalized chances in u,h and \lambda smaller than du, dh and dl.
%
% The most (arguably even the only) important number is NLtol.
% NLtol is a tolerance on the norm of the solution residuals, i.e. the resulting residuals once the solution is
% plugged back into the equation. So NLtol should ALWAYS be set to a small value (for example <1e-10)
%
% The CtrlVar.du/dh/dl are tolerances for the chance in u,h, and \lambda, respectively, between subsequent non-linear iteration steps.
% Although one would expect these to go to zero with increasing iteration number, these are not very reliable
% estimates of the actual error. Generally set du and dh to not too large value, but do not focus too much on those numbers
% (The error in solving the boundary conditions is always checked internally.)
%
% Note: there is no need to put any constrains on the Lagrange variables used to
% enforce the BCs because 1) the BCs are currently always linear, and 2) it is
% always checked internally that the BCs have been solved correctly. In fact, it
% can be a bad idea to enforce a limit on this change because sometimes the
% change in lambda between non-linear iteration steps is just a direct response
% to how the primary variables (u,v,h) change. The norm of these changes can
% then be large despite the BCs being exactly fulfilled.)
%
%% uvh Convergence criteria
% The non-linear uvh/uv loops are considered to have converged if:
%
% 1) Work and Force tolerances are both less than:
CtrlVar.uvhDesiredWorkAndForceTolerances=[inf 1e-15];
% and, furthermore, at least one of Work and Force tolerances are less than:
CtrlVar.uvhDesiredWorkOrForceTolerances=[inf 1e-15];
%Note: The default uvh tolerances set limits on the Force tolerance only.
% 2) If the step length in the backtracking becomes smaller than
CtrlVar.uvhExitBackTrackingStepLength=1e-3;
% while at the same time these Work and Force tolerances also fulfilled:
CtrlVar.uvhAcceptableWorkAndForceTolerances=[inf 1e-6];
CtrlVar.uvhAcceptableWorkOrForceTolerances=[1 1e-8];
CtrlVar.uvDesiredWorkAndForceTolerances=[inf 1e-15];
CtrlVar.uvDesiredWorkOrForceTolerances=[inf 1e-15];
CtrlVar.uvExitBackTrackingStepLength=1e-10;
CtrlVar.uvAcceptableWorkAndForceTolerances=[inf 1e-15];
CtrlVar.uvAcceptableWorkOrForceTolerances=[inf 1e-15];
CtrlVar.hDesiredWorkAndForceTolerances=[1000 1e-10];
CtrlVar.hDesiredWorkOrForceTolerances=[1 1e-15];
CtrlVar.hExitBackTrackingStepLength=1e-4;
CtrlVar.hAcceptableWorkAndForceTolerances=[inf 1e-6];
CtrlVar.hAcceptableWorkOrForceTolerances=[1 1e-8];
CtrlVar.hSolverMaxIterations=50;
CtrlVar.LevelSetSolverMaxIterations=100;
CtrlVar.LSFDesiredWorkAndForceTolerances=[1e-15 1e-15];
CtrlVar.LSFDesiredWorkOrForceTolerances=[inf 1e-15];
CtrlVar.LSFExitBackTrackingStepLength=1e-3;
CtrlVar.LSFAcceptableWorkAndForceTolerances=[1e-10 1e-12];
CtrlVar.LSFAcceptableWorkOrForceTolerances=[Inf 1e-12];
CtrlVar.uvhMinimisationQuantity="Force Residuals"; % used in SSTREAM/SSA when solving implicitly for u, v, and h
CtrlVar.uvMinimisationQuantity="Force Residuals"; % used in SSTREAM/SSA when solving implicitly for velocities.
CtrlVar.hMinimisationQuantity="Force Residuals"; % used in SSHEET/SIA when solving implicitly for h
CtrlVar.LSFMinimisationQuantity="Force Residuals";
CtrlVar.MustBe.uvhMinimisationQuantity=["Force Residuals","Work Residuals"];
CtrlVar.MustBe.uvMinimisationQuantity=["Force Residuals","Work Residuals"];
CtrlVar.MustBe.hMinimisationQuantity=["Force Residuals","Work Residuals"];
CtrlVar.MustBe.LSFMinimisationQuantity=["Force Residuals","Work Residuals"];
CtrlVar.uvh.SUPG.tau="taus" ; % {'tau1','tau2','taus','taut'}
CtrlVar.h.SUPG.tau="taus"; CtrlVar.h.SUPG.Use=1;
CtrlVar.uvh.SUPG.tauMultiplier=1 ;
CtrlVar.h.SUPG.tauMultiplier=1 ;
%% Newton-Raphson, modified Newton-Raphson, Picard Iteration
%
% When solving the non-linear system (forward model) the recommended option is is
% to use the full Newton-Raphson method
%
% One can also use the modified Newton-Raphson or the Picard iteration.
%
% Modified Newton-Raphson only evaluates the left-hand side (the stiffness
% matrix) if certain criteria are fulfilled. This will reduced time spend with
% matrix assembly but also reduced the rate of convergence. Depending on the
% problem using the modified NR method may, or may not, lead to an overall
% reduction in computational time.
%
% When using the modified Newton-Raphson method, there are two criteria that
% determine if the left-hand side is updated or not: 1) interval and 2)
% (residual) reduction criteria. The interval criteria determines the number of
% iterations between updates. (The matrix is always updated at the beginning of
% the non-linear iteration.) The reduction criteria forces re-assembly if the
% reduction in last iteration was not greater than a given fraction.
%
% Note:Most of the following parameters related to the NR iteration do, in general,
% not to be modified and the default values should in most situation be OK.
CtrlVar.NR=1; % 1 gives Newton-Raphson (use Newton-Raphson whenever possible)
CtrlVar.ModifiedNRuvIntervalCriterion=1; % interval between matrix updates, always a positive integer number.
CtrlVar.ModifiedNRuvReductionCriterion=0.5; % fractional reduction forcing an update
CtrlVar.ModifiedNRuvhIntervalCriterion=1;
CtrlVar.ModifiedNRuvhReductionCriterion=0.5;
% Setting for example:
% CtrlVar.ModifiedNRuvIntervalCriterion=10;
% CtrlVar.ModifiedNRuvReductionCriterion=0.95;
% will cause the matrix only to be updated every 10-th non-linear iteration, unless
% the fractional reduction r/r0 over previous iteration was less than 0.95.
%
CtrlVar.Picard=0; % 1 gives Picard iteration, otherwise NR iteration (always use NR whenever possible).
CtrlVar.NRviscosity=1; % if 1 derivatives with respect to viscosity are included in the NR method
CtrlVar.NRbeta2=1; % if 1 derivatives with respect to slipperiness are included in the NR method
% Note: if Picard=0 then the NRviscosity and NRbeta2 values are overwritten and set to 0.
CtrlVar.NRitmax=50; % maximum number of NR iteration
CtrlVar.Picarditmax=30; % maximum number of Picard iterations
CtrlVar.iarmmax=10; % maximum number of backtracking steps in NR and Picard iteration
CtrlVar.NRitmin=1; % minimum number of NR iteration
CtrlVar.NewtonAcceptRatio=0.5; % accepted reduction in NR without going into back-stepping
CtrlVar.NewtonBacktrackingBeta=1e-4; % affects the Amarijo exit criteria in the back-stepping
CtrlVar.LineSearchAllowedToUseExtrapolation=0; % If true, backtracking algorithm may start with an extrapolation step.
CtrlVar.BacktrackingGammaMin=1e-10; % smallest step-size in Newton/Picard backtracking as a fraction of the full Newton/Picard step.
CtrlVar.BacktrackingGammaMinAdjoint=1e-20; % smallest step-size allowed while backtracking in adjoint step. (This is an absolute step size, i.e. not a fraction of initial step size.)
CtrlVar.GuardAgainstWildExtrapolationInExplicit_uvh_Step=0;
CtrlVar.uvGroupAssembly=false;
CtrlVar.uvhGroupAssembly=false;
%% Backtracking parameters -line search
% Parameters affecting the backtracking algorithm
CtrlVar.BackTrackBeta=0.1 ; % beta in the ArmijoGoldstein exit condition
CtrlVar.BackTrackMaxIterations=50 ; % this is plenty
CtrlVar.BackTrackMaxExtrapolations=50 ; % if set to zero no extrapolation is done (i.e. pure backtracking)
CtrlVar.BackTrackExtrapolationRatio=2.5 ; % ratio between new and old step size in each extrapolation step
CtrlVar.BackTrackMinXfrac=1e-10 ; % exit backtracking if pos. of minimum is changing by less than this fraction of initial step
CtrlVar.BackTrackMaxFuncSame=3 ; % exit backtracking if this many evaluations of cost function resulted in no further decrease of cost function
% Limit stepsize based on quadratic/cubic interpolation to these lower/upper
% limits withing the current lower/upper range.
CtrlVar.BackTrackGuardLower=0.25;
CtrlVar.BackTrackGuardUpper=0.95;
% Backtracking continues even if target has been reached if last reduction in
% ratio is smaller than:
CtrlVar.BackTrackContinueIfLastReductionRatioLessThan=0.5;
% The ratio is CurrentValue/LastValue, so smaller ratio means greater reduction.
% Note: The initial target is CtrlVar.NewtonAcceptRatio, and
% after that target=f(0)+CtrlVar.BackTrackBeta slope step
% CurrentValue/InitalValue < CtrlVar.NewtonAcceptRatio
% unless some other exit criteria are reached.
%% Lin equation solver parameters
%
% Linear symmetrical solver is either Matlab \ operator, or Augmented Lagrangian
% Solver (ALS)
%
%
% The MATLAB \ operator sometimes fails for indefinite block matrices. For
% that reason the default linear solver is Augmented Lagrangian Solver (ALS)
%
% ALS uses an outer iteration and the inner problem is solved direction. Usually
% only a few outer iterations are required.
%
% For asymmetrical indefinite block-structured systems the ALS method is almost
% always better than the default MATLAB backslash operator. ALS is an iterative
% method with an inner and outer iteration. Convergence depends on
% ALSpower. If ALS does not converge then tying a smaller ALSpower
% usually does the trick.
%
CtrlVar.SymmSolver='Auto'; % {'Backslash','Uzawa','AugmentedLagrangian'}
CtrlVar.AsymmSolver='Auto'; % {'Backslash','Uzawa','AugmentedLagrangian'}
CtrlVar.ALSIterationMin=3; CtrlVar.ALSIterationMax=25; CtrlVar.ALSpower=5; % ALS parameters
CtrlVar.UzawaIterationMin=3; CtrlVar.UzawaIterationMax=25; CtrlVar.UzawaPower=5; % Uzawa parameters
CtrlVar.LinSolveTol=1e-8; % Residual when solving linear system.
% If the standard MATLAB backslash algorithm is used, default MATLAB values apply and this number is not used
% For indefinite block-structured systems of the type [A B' ; B 0] [x;y]=[f;g]
% the relative residual is defined in standard way as:
% Residual=norm([A B' ; B sparse(m,m)]*[x;y]-[f ; g])/norm([f;g]);
% A value of 1e-8 is arguably already a relatively small number, in many cases 1e-6 would be considered acceptable
CtrlVar.Solve.LUvector=false; % LU factorisation done using vector format, consider setting to true if memory an issue
%% Internal variables related to matrix assembly
% These variables are only for testing purposes. Do not change from default
% values.
%% Number of integration points and/or quadrature rule degree
% if left empty, the number of integration points is set automatically
CtrlVar.niph=[] ; % number of integration points for uvh in implicit runs, and for the h-solver in semi-implicit runs
CtrlVar.nip=[] ; % number of integration points for the uv solver
% Possible Nr of integration points: 1, 3, 4, 6, 7, 9, 12, 13, 16, 19, 28, 37.
% The default values are:
% nip=6 and niph=6 for linear elements (three node elements)
% nip=12 and niph=12 for quadratic elements (six node elements)
% nip=16 and niph=16 for cubic elements (ten node elements)
% The default values are usually fine, but sometimes increasing the number of
% integration points improves convergence of the Newton-Raphson iteration.
CtrlVar.QuadratureRuleDegree=[] ; % leaving empty means automated selection
CtrlVar.QuadRules2021=true ; % Use the new quad rules implemented in 2021
% This option allows for greater flexibility in selecting quad points.
%% Level of information given during a run
% A number of variables affect the information given during a run.
% Generally the higher the number, the more information is given.
%
% Depending on info levels, figures might be plotted as well. However, this is only done
% if corresponding plotting logicals such as CtrlVar.doplots, CtrlVar.doAdaptMeshPlot, etc, are also true.
%
% Further description of what information is provided depending on the values of the info parameters is provided below.
%% If you, for example set,
%
% CtrlVar.InfoLevelNonLinIt=5 ; CtrlVar.InfoLevelBackTrack=100;
%
% and provided that furthermore
%
% CtrlVar.doplots=1
%
% several figures will be produced showing the change in velocity and ice thickness (if solving uvh) during each time increment.
% and also a figure showing the values calculated as a part of the back-tracking step.
%
%
CtrlVar.InfoLevel=1; % Overall level of information (forward runs)
CtrlVar.InfoLevelInverse=1; % Overall level of information (inverse runs).
% Note: generally good to combine with CtrlVar.InfoLevelNonLinIt=0;
% CtrlVar.InfoLevel=0; to suppress information related to the forward step.
CtrlVar.InfoLevelNonLinIt=1;
%
%
% The level of information giving about the non-linear iteration is determine
% by the variable
%
% CtrlVar.InfoLevelNonLinIt
%
% Higher values give more information
%
% 0 : no information on non-linear step printed.
% 1 : basic convergence information at end of non-linear step.
% >1 : detailed info on residuals given at the end of non-linear step.
% >=2 : info on backtracking step as well.
% >=5 : plots change in velocities and ice thickness over each uvh time step, and basal drag vectors
% >=10 : calculates/plots additional info on residuals as a function of step size within line search, and rate of convergence
% >=100 : plots residual vectors
%
%
% The level of information giving about adaptive meshing is determined by the
% variable
%
% CtrlVar.InfoLevelAdaptiveMeshing
%
% Some plots are generated if the value is >=5, but only if the logical variables
%
% CtrlVar.doplots
% CtrlVar.doAdaptMeshPlots
%
% are both true.
%
% 0 : no information on adaptive meshing printed.
% >=10 : plots showing mesh before and at the end of each mesh adaption.
% >=100 : Further plots on changes in mesh during an adapt mesh iteration produced.
%
%
%
CtrlVar.InfoLevelAdaptiveMeshing=1; % Information related to adapt meshing
% 1 : default basic information
% 10 : additional plots, e.g showing element to be deactivated, refine or coarsened.
% But plots are only produced if additionally CtrlVar.doplots=true ;
CtrlVar.InfoLevelLinSolve=0; % If the linear solver does not converge (it sometimes uses a inner and outer loop to deal with indefinite systems)
% then increasing this number will give further information. G
CtrlVar.ThicknessConstraintsInfoLevel=1 ;
CtrlVar.hInfoLevel=1; % Infolevel for the h solve when using semi-implicit uv/h approach
CtrlVar.InfoLevelThickMin=0 ; % if >=1 prints out info related to resetting thickness to min thick
% if >=10, plots locations of min thickness within mesh
CtrlVar.SymmSolverInfoLevel=0 ;
CtrlVar.InfoLevelBackTrack=1; % Controls information given during backtracking.
% As with other info parameters, higher values provide more information
% 10 :
% 100 : plots evaluated function values along the backtracking direction
% 1000 : plots backtracking with further additional values calculated at regular intervals along the step, and prints detailed info about backtracking
CtrlVar.InfoLevelCPU=0; % if 10 or higher then some info on CPU time usage is given
CtrlVar.StandartOutToLogfile=false ; % if true standard output is directed to a logfile
% name of logfile is $Experiment.log
%% Inversion
%
% Inversion can currently be done for A and C.
%
% One can invert for either A or C individually, or both.
%
% The default option is to invert for log(A) and log(C) simultaneously.
%
% The objective function $J$ (i.e. the function to be minimized) has the form
%
% $$ J= I + R $$
%
% where I is a misfit term, and R a regularization term.
%
%
% The misfit term is:
%
%
% $$I= (1/{\cal{A}}) \int \left (((u-u_{\mathrm{Meas}})/u_{\mathrm{Errors}})^2 + ((v-v_{\mathrm{Meas}})/v_{\mathrm{Errors}})^2) \right ) dx dy = 0$$
%
% where
%
% $${\cal A} = \int dx dy$$
%
%
%
% and the regularization term can be either on the form (Bayesian)
%
% $$ R= (C-C_{prior}) K_C^{-1} (C-C_{prior}) + (A-A_{prior}) K_A^{-1} (A-A_{prior}) $$
%
% where $K_C$ and $K_A$ are covariance matrices, or (Tikhonov)
%
% $$ R= (1/Area) \int ( g_s^2 (\nabla (p-p_{\mathrm{prior}}))^2 + g_a^2 (p-p_{\mathrm{prior}})^2) \; dx dy $$
%
% where $p$ is $A$ or $log(A)$ , $C$ or $log(C)$
%
% There are number of different minimization methods implemented. Although the
% methodology behind the inversion is rigorous, in practice when working with
% real data the inversions sometimes get stuck in some local minimum. The
% different optimization methods implemented use slightly different search
% directions, and switching methods may help getting out of a local minimum as
% seen by one particular method. (When using synthetic data this is hardly ever
% an issue).
%
%
% Hint: Often starting inverting for C using the fix-point method (see "FixPointEstimationOfSlipperiness" below) drives the misfit
% initially quite significantly down. Once that method stagnates (which it almost always will because the gradient used in that method
% is just a rough estimate and generally not exact), switch to another minimization approach, for example the UaOptimisation using the
% adjoint gradients.
%
% FixPoint inversion is an ad-hoc method of estimating the gradient of the cost function with respect to C.% It can produce quite good
% estimates for C using just one or two inversion iterations, but then typically stagnates. The FixPoint method can often be used right
% at the start of an inversion to get a reasonably good C estimate, after which in a restart step one can switch to gradient
% calculation using adjoint
%
% Ua has some inbuilt optimization methods and these are used by default. However, if the matlab optimization toolbox is installed, the
% matlab routines can be used instead.
%
% Note #1: Some parameter combinations can be inconsistent. For example inverting
% for A only and applying regularization on A and C, i.e.
%
% CtrlVar.Inverse.InvertFor='-logA-' ;
% CtrlVar.Inverse.Regularize.Field='-logA-logC-'
%
% is considered inconsistent (although in principle possible.) Also using the
% `FixPoint' gradient calculation, which only works for C inversion, and
% inverting for both A and C, i.e.
%
% CtrlVar.Inverse.DataMisfit.GradientCalculation='Adjoint' ; % {'Adjoint','FixPoint'}
% CtrlVar.Inverse.InvertFor='-logA-logC-' ; % {'-C-','-logC-','-AGlen-','-logA-','-logA-logC-'}
%
% is inconsistent. Ua tries to spot these input parameter mistakes and correct
% for them, but it is better to try to keep all inputs consistent.
%
% Note #2: It is possible to invert for any combination of log(A) or A and log(C)
% or C. So for example one can invert for log(A) and C by setting
%
% CtrlVar.Inverse.InvertFor='-logA-C-' ;
%
% Also one can invert for log(C) and log(A) and regularize A and C by setting
%
%
% CtrlVar.Inverse.InvertFor='-logA-logC-' ;
% CtrlVar.Inverse.Regularize.Field='-A-C-'
%
%
%% Inversion algorithm:
%
% The inversion can be done using either only the gradient, or gradient and an estimate of the Hessian
%
% The gradient calculation is exact, well as exact as a numerical method can be expected to be exact.
%
% The Hessian of the regularization term is exact, but the Hessian of the misfit term is approximated (see details in the Ua
% Compendium)
%
% The optimization step in the inversion can then be done using either the Matlab optimization toolbox, or an some Ua optimization
% routines.
%
% Default is to use Hessian based optimization, which uses both the gradient and the Hessian approximation, or gradient-based
% minimization, which only uses the gradient and builds up an approximation of the Hessian from the gradient.
%
% The default option is Hessian-based optimization using the matlab optimization toolbox.
%
CtrlVar.Inverse.MinimisationMethod="MatlabOptimization-HessianBased"; % Hessian-based, MATLAB toolbox
% ="MatlabOptimization-GradientBased"; % gradient-based, MATLAB toolbox
% ="UaOptimization-GradientBased"; % gradient-based, Ua optimization toolbox
% ="UaOptimization-HessianBased"; % Hessian-based, Ua optimization toolbox
% If a Hessian-based optimization is used, the the expressions for the Hessians can be selected as follows:
CtrlVar.Inverse.Hessian="RHA=E RHC=E IHC=FP IHA=FP";
% Here R stands for Regularization and I stands for Misfit.
% E stands for 'exact' and 'FP' for 'fixed-point'
%
% So RHA=E implies that the Hessian (H) for the AGlen (A) regularization term (R) is based on the exact (E) expression for H.
% So IHC=FP implies that the Hessian (H) for the AGlen (C) misfit term (I) is based on the exact 'fixed-point' (FP) expression for H.
% If the gradient-based approach is used, the gradient of the objective function can be pre-multiplied with the inverse of the mass
% matrix. This creates a `mesh independent' gradient. This has both advantages and disadvantages. The best initial approach is
% presumably to use 'I', and then to try out 'M' for comparison.
CtrlVar.Inverse.AdjointGradientPreMultiplier="M"; % {'I','M'}
% If a Hessian-based approach is used, the pre-multiplier is not of relevance, and not used.
% If a gradient-based approach is used, the gradient is defined with respect to the L2 inner produce when using the M pre-muliplier,
% and with respect to the l2 inner product when using the I pre-multiplier.
%
CtrlVar.Inverse.Iterations=1; % Maximum number of inverse iterations
CtrlVar.Inverse.OptimalityTolerance=1e-10; % see MATLAB documentation on the use of the fmincon function, needed for inversion using the matlab optimisation toolbox
CtrlVar.Inverse.FunctionTolerance=1 ; % see MATLAB documentation on the use of the fmincon function, needed for inversion using the matlab optimisation toolbox
CtrlVar.Inverse.StepTolerance=1e-30 ; % see MATLAB documentation on the use of the fmincon function, needed for inversion using the matlab optimisation toolbox
CtrlVar.Inverse.WriteRestartFile=1; % always a good idea to write a restart file.
CtrlVar.Inverse.NameOfRestartOutputFile='InverseRestart.mat';
CtrlVar.Inverse.NameOfRestartInputFile=CtrlVar.Inverse.NameOfRestartOutputFile;
CtrlVar.Inverse.SaveSlipperinessEstimateInSeperateFile=true ;
CtrlVar.Inverse.SaveAGlenEstimateInSeperateFile=true ;
CtrlVar.NameOfFileForSavingSlipperinessEstimate='C-Estimate.mat';
CtrlVar.NameOfFileForSavingAGlenEstimate='AGlen-Estimate.mat';
%%
%
% Inversion can be done using measurements of:
%
% * horizontal velocities (uv)
% * rate of thickness change (dh/dt).
%
% To select which types of surface measurements to use in the inversion set:
CtrlVar.Inverse.Measurements='-uv-' ; % {'-uv-,'-uv-dhdt-','-dhdt-'}
%%
% It is usually better to invert for log(A) and log(C) rather than A and C.
% The default is to invert for log(A) and log(C) simultaneously.
%
% To select which types of fields to invert for set:
CtrlVar.Inverse.InvertFor='-logA-logC-' ; % {'-C-','-logC-','-A-','-logA-'}
%%
% The gradient of the objective function is calculated using the adjoint method.
% When inverting for C only, one can also use a gradient based on a `FixPoint'
% iteration, which is often a very good initial approach.
CtrlVar.Inverse.DataMisfit.GradientCalculation='Adjoint' ; % {'Adjoint','FixPoint'}
%%
% Regularization can be applied on A and C or log(A) and log(C). Also possible
% to use a covariance matrix for A and C.
%
% Select Bayesian motivated regularization by setting
%
% CtrlVar.Inverse.Regularize.Field='cov'
%
% and Tikhonov regularization
% by setting
%
% CtrlVar.Inverse.Regularize.Field
%
% to either '-C-','-logC-','-AGlen-','-logAGlen-',or '-logAGlen-logC-'
%
% Default is Tikhonov regularization on log(A) and log(C)
%
CtrlVar.Inverse.Methodology="-Tikhonov-" ; % either "-Tikhonov-" or "-Bayesian-"
%
% If using Bayesian inverse methodology the covariance matrix of the priors MUST
% be defined, and it can be dense (although computationally doing so might slow
% the run considerably.)
%
% If using Tikhonov inverse methodology the covariance matrix of the priors CAN
% be defined, but must be diagonal.
%
CtrlVar.Inverse.Regularize.Field='-logAGlen-logC-' ; % {'-cov-','-C-','-logC-','-AGlen-','-logAGlen-','-logAGlen-logC-'}
%%
% [ -- Parameters specific to Tikhonov regularization. See the above definition
% of the regularization term R in the case of Tikhonov regularization. The
% values of these parameters can be expected to be highly problem dependent. By
% default regularization is switched on, but can the switched off by setting the
% gs and the ga parameters to zero.
CtrlVar.Inverse.Regularize.AGlen.gs=[];
CtrlVar.Inverse.Regularize.AGlen.ga=[];
CtrlVar.Inverse.Regularize.logAGlen.ga=[];
CtrlVar.Inverse.Regularize.logAGlen.gs=[] ;
CtrlVar.Inverse.Regularize.C.gs=[];
CtrlVar.Inverse.Regularize.C.ga=[];
CtrlVar.Inverse.Regularize.logC.ga=[];
CtrlVar.Inverse.Regularize.logC.gs=[] ;
CtrlVar.Inverse.Regularize.B.gs=[]; % This is only relevant for a B inversion. Currently B inversion is being tested, do not use.
CtrlVar.Inverse.Regularize.B.ga=[];
% -]
CtrlVar.Inverse.StoreSolutionAtEachIteration=0; % if true then inverse solution at each iteration is saved in the RunInfo variable.
%%
% I and R are multiplied by these following DataMisit and Regularization
% multipliers. This is a convening shortcut of getting rid of either the misfit
% (I) or the regularization term (R) in the objective function (J) altogether.
CtrlVar.Inverse.DataMisfit.Multiplier=1;
CtrlVar.Inverse.Regularize.Multiplier=1;
%
CtrlVar.Inverse.dFuvdClambda=false; % internal control variable, do not change
%%
% [---------- The following parameters are only relevant if using the
% UaOptimization i.e. only if
% CtrlVar.Inverse.MinimisationMethod='UaOptimization';
%
% The Ua optimization is a simple non-linear conjugate-gradient method with
% automated resets, combined with a (one-sided) line search. The reset is done
% if the angle between subsequent steepest decent directions is to far from 90
% degrees, or if the update parameter becomes negative (only relevant for
% Polak-Ribiere and Hestens-Stiefel).
CtrlVar.Inverse.GradientUpgradeMethod='ConjGrad' ; %{'SteepestDecent','ConjGrad'}
CtrlVar.Inverse.InitialLineSearchStepSize=[];
CtrlVar.Inverse.MinimumAbsoluteLineSearchStepSize=1e-20; % minimum step size in backtracking
CtrlVar.Inverse.MinimumRelativelLineSearchStepSize=1e-5; % minimum fractional step size relative to initial step size
CtrlVar.Inverse.MaximumNumberOfLineSearchSteps=50;
CtrlVar.ConjugatedGradientsRestartThreshold=40 ; % degrees!
CtrlVar.ConjugatedGradientsUpdate='PR'; % (FR|PR|HS|DY)
% FR ;Fletcher-Reeves
% PR :Polak-Ribi\`ere
% HR: Hestenes-Stiefel
% DY :Dai-Yan
% end, UaOptimization parameters
% ------------]
%%
% [------ The following parameters are only relevant if using the MatlabOptimisation option
% i.e. only if CtrlVar.Inverse.MinimisationMethod='MatlabOptimization'
%
% Refer to the matlab documentation for further information.
%
% The optimization routines used are either the MATLAB routine fminunc or
% fmincon.
%
% You will need to have the MATLAB optimization toolbox to be able to do this.
%
% The Matlab optimization toolbox has various algorithms to choose from, each of
% which has large number of parameters.
%
% Define the algorithm and set the options defining:
%
% CtrlVar.Inverse.MatlabOptimisationParameters
%
% Below are three examples that you might want to start with.
% The last one (which is the default one) uses fmincon with lbfgs update.
%
%
if license('test','Optimization_Toolbox')
% A few examples of how to set parameters if using the Matlab Optimization
% toolbox when performing an inversion, i.e if
% CtrlVar.Inverse.MinimisationMethod='MatlabOptimization'
%
% You can copy some of these examples into your own DefineInitialUserInput.m
% file and modify as needed. See Matlab documentation for further information.
%
% These are the default parameters using gradient based inversion with the MATLAB optimisation toolbox
CtrlVar.Inverse.MatlabOptimisationGradientParameters = optimoptions('fmincon',...
'Algorithm','interior-point',...
'CheckGradients',false,...
'ConstraintTolerance',1e-10,...
'HonorBounds',true,...
'Diagnostics','on',...
'DiffMaxChange',Inf,...
'DiffMinChange',0,...
'Display','iter-detailed',...
'FunValCheck','off',...
'MaxFunctionEvaluations',1e6,...
'MaxIterations',CtrlVar.Inverse.Iterations,...,...
'OptimalityTolerance',1e-20,...
'OutputFcn',@fminuncOutfun,...
'PlotFcn',{@optimplotlogfval,@optimplotstepsize},...
'StepTolerance',1e-30,...
'FunctionTolerance',1,...
'UseParallel',true,...
'HessianApproximation',{'lbfgs',250},...
'HessianFcn',[],...
'HessianMultiplyFcn',[],...
'InitBarrierParam',1e-7,... % On a restart this might have to be reduced if objective function starts to increase
'ScaleProblem','none',...
'InitTrustRegionRadius',1,... % set to smaller value if the forward problem is not converging
'SpecifyConstraintGradient',false,...
'SpecifyObjectiveGradient',true,...
'SubproblemAlgorithm','cg'); % here the options are 'gc' and 'factorization', unclear which one is the better one, 'factorization' is the matlab default
% 2022-05-21: tried to fix the error with M2022a when using the gradient-based option
% by redefining and simplifying the options, but this did not work either.
options=optimoptions("fmincon");
options.Algorithm="trust-region-reflective";
options.HessianApproximation="lbfgs";
options.SpecifyConstraintGradient=true;
CtrlVar.Inverse.MatlabOptimisationGradientParameters = options ;
% These are the default parameters using gradient based inversion with the MATLAB optimisation toolbox
CtrlVar.Inverse.MatlabOptimisationGradientParameters = optimoptions('fmincon',...
'Algorithm','interior-point',...
'CheckGradients',false,...
'ConstraintTolerance',1e-10,...
'HonorBounds',true,...
'Diagnostics','on',...
'DiffMaxChange',Inf,...
'DiffMinChange',0,...