-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathFEProblemBase.C
9235 lines (7866 loc) · 316 KB
/
FEProblemBase.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
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "FEProblemBase.h"
#include "AuxiliarySystem.h"
#include "MaterialPropertyStorage.h"
#include "MooseEnum.h"
#include "Factory.h"
#include "MooseUtils.h"
#include "DisplacedProblem.h"
#include "SystemBase.h"
#include "MaterialData.h"
#include "ComputeUserObjectsThread.h"
#include "ComputeNodalUserObjectsThread.h"
#include "ComputeThreadedGeneralUserObjectsThread.h"
#include "ComputeMaterialsObjectThread.h"
#include "ProjectMaterialProperties.h"
#include "ComputeIndicatorThread.h"
#include "ComputeMarkerThread.h"
#include "ComputeInitialConditionThread.h"
#include "ComputeFVInitialConditionThread.h"
#include "ComputeBoundaryInitialConditionThread.h"
#include "MaxQpsThread.h"
#include "ActionWarehouse.h"
#include "Conversion.h"
#include "Material.h"
#include "FunctorMaterial.h"
#include "ConstantIC.h"
#include "Parser.h"
#include "ElementH1Error.h"
#include "Function.h"
#include "Convergence.h"
#include "NonlinearSystem.h"
#include "LinearSystem.h"
#include "SolverSystem.h"
#include "Distribution.h"
#include "Sampler.h"
#include "PetscSupport.h"
#include "RandomInterface.h"
#include "RandomData.h"
#include "MooseEigenSystem.h"
#include "MooseParsedFunction.h"
#include "MeshChangedInterface.h"
#include "ComputeJacobianBlocksThread.h"
#include "ScalarInitialCondition.h"
#include "FVInitialConditionTempl.h"
#include "ElementPostprocessor.h"
#include "NodalPostprocessor.h"
#include "SidePostprocessor.h"
#include "InternalSidePostprocessor.h"
#include "InterfacePostprocessor.h"
#include "GeneralPostprocessor.h"
#include "ElementVectorPostprocessor.h"
#include "NodalVectorPostprocessor.h"
#include "SideVectorPostprocessor.h"
#include "InternalSideVectorPostprocessor.h"
#include "GeneralVectorPostprocessor.h"
#include "Positions.h"
#include "Indicator.h"
#include "Marker.h"
#include "MultiApp.h"
#include "MultiAppTransfer.h"
#include "TransientMultiApp.h"
#include "ElementUserObject.h"
#include "DomainUserObject.h"
#include "NodalUserObject.h"
#include "SideUserObject.h"
#include "InternalSideUserObject.h"
#include "InterfaceUserObject.h"
#include "GeneralUserObject.h"
#include "ThreadedGeneralUserObject.h"
#include "InternalSideIndicator.h"
#include "Transfer.h"
#include "MultiAppTransfer.h"
#include "MultiMooseEnum.h"
#include "Predictor.h"
#include "Assembly.h"
#include "Control.h"
#include "XFEMInterface.h"
#include "ConsoleUtils.h"
#include "NonlocalKernel.h"
#include "NonlocalIntegratedBC.h"
#include "ShapeElementUserObject.h"
#include "ShapeSideUserObject.h"
#include "MooseVariableFE.h"
#include "MooseVariableScalar.h"
#include "InputParameterWarehouse.h"
#include "TimeIntegrator.h"
#include "LineSearch.h"
#include "FloatingPointExceptionGuard.h"
#include "MaxVarNDofsPerElem.h"
#include "MaxVarNDofsPerNode.h"
#include "FVKernel.h"
#include "LinearFVKernel.h"
#include "FVTimeKernel.h"
#include "MooseVariableFV.h"
#include "MooseLinearVariableFV.h"
#include "FVBoundaryCondition.h"
#include "LinearFVBoundaryCondition.h"
#include "FVInterfaceKernel.h"
#include "Reporter.h"
#include "ADUtils.h"
#include "Executioner.h"
#include "VariadicTable.h"
#include "BoundaryNodeIntegrityCheckThread.h"
#include "BoundaryElemIntegrityCheckThread.h"
#include "NodalBCBase.h"
#include "MortarUserObject.h"
#include "MortarUserObjectThread.h"
#include "RedistributeProperties.h"
#include "Checkpoint.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/quadrature.h"
#include "libmesh/coupling_matrix.h"
#include "libmesh/nonlinear_solver.h"
#include "libmesh/sparse_matrix.h"
#include "libmesh/string_to_enum.h"
#include "libmesh/fe_interface.h"
#include "libmesh/enum_norm_type.h"
#include "libmesh/petsc_solver_exception.h"
#include "metaphysicl/dualnumber.h"
using namespace libMesh;
// Anonymous namespace for helper function
namespace
{
/**
* Method for sorting the MooseVariableFEBases based on variable numbers
*/
bool
sortMooseVariables(const MooseVariableFEBase * a, const MooseVariableFEBase * b)
{
return a->number() < b->number();
}
} // namespace
Threads::spin_mutex get_function_mutex;
InputParameters
FEProblemBase::validParams()
{
InputParameters params = SubProblem::validParams();
params.addParam<unsigned int>("null_space_dimension", 0, "The dimension of the nullspace");
params.addParam<unsigned int>(
"transpose_null_space_dimension", 0, "The dimension of the transpose nullspace");
params.addParam<unsigned int>(
"near_null_space_dimension", 0, "The dimension of the near nullspace");
params.addParam<bool>("solve",
true,
"Whether or not to actually solve the Nonlinear system. "
"This is handy in the case that all you want to do is "
"execute AuxKernels, Transfers, etc. without actually "
"solving anything");
params.addParam<bool>("use_nonlinear",
true,
"Determines whether to use a Nonlinear vs a "
"Eigenvalue system (Automatically determined based "
"on executioner)");
params.addParam<bool>("error_on_jacobian_nonzero_reallocation",
"This causes PETSc to error if it had to reallocate memory in the Jacobian "
"matrix due to not having enough nonzeros");
params.addParam<bool>("ignore_zeros_in_jacobian",
false,
"Do not explicitly store zero values in "
"the Jacobian matrix if true");
params.addParam<bool>("force_restart",
false,
"EXPERIMENTAL: If true, a sub_app may use a "
"restart file instead of using of using the master "
"backup file");
params.addDeprecatedParam<bool>("skip_additional_restart_data",
false,
"True to skip additional data in equation system for restart.",
"This parameter is no longer used, as we do not load additional "
"vectors by default with restart");
params.addParam<bool>("skip_nl_system_check",
false,
"True to skip the NonlinearSystem check for work to do (e.g. Make sure "
"that there are variables to solve for).");
params.addParam<bool>("allow_initial_conditions_with_restart",
false,
"True to allow the user to specify initial conditions when restarting. "
"Initial conditions can override any restarted field");
/// One entry of coord system per block, the size of _blocks and _coord_sys has to match, except:
/// 1. _blocks.size() == 0, then there needs to be just one entry in _coord_sys, which will
/// be set for the whole domain
/// 2. _blocks.size() > 0 and no coordinate system was specified, then the whole domain will be XYZ.
/// 3. _blocks.size() > 0 and one coordinate system was specified, then the whole domain will be that system.
params.addDeprecatedParam<std::vector<SubdomainName>>(
"block", {}, "Block IDs for the coordinate systems", "Please use 'Mesh/coord_block' instead");
MultiMooseEnum coord_types("XYZ RZ RSPHERICAL", "XYZ");
MooseEnum rz_coord_axis("X=0 Y=1", "Y");
params.addDeprecatedParam<MultiMooseEnum>("coord_type",
coord_types,
"Type of the coordinate system per block param",
"Please use 'Mesh/coord_type' instead");
params.addDeprecatedParam<MooseEnum>("rz_coord_axis",
rz_coord_axis,
"The rotation axis (X | Y) for axisymetric coordinates",
"Please use 'Mesh/rz_coord_axis' instead");
auto coverage_check_description = [](std::string scope, std::string list_param_name)
{
return "Controls, if and how a " + scope +
" subdomain coverage check is performed. "
"With 'TRUE' or 'ON' all subdomains are checked (the default). Setting 'FALSE' or 'OFF' "
"will disable the check for all subdomains. "
"To exclude a predefined set of subdomains 'SKIP_LIST' is to "
"be used, while the subdomains to skip are to be defined in the parameter '" +
list_param_name +
"'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
"be used (again, using the parameter '" +
list_param_name + "').";
};
params.addParam<std::vector<SubdomainName>>(
"default_block",
{},
"Default list of subdomains for block-restrictable objects such as kernels and materials.");
MooseEnum kernel_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>("kernel_coverage_check",
kernel_coverage_check_modes,
coverage_check_description("kernel", "kernel_coverage_block_list"));
params.addParam<std::vector<SubdomainName>>(
"kernel_coverage_block_list",
{},
"List of subdomains for kernel coverage check. The meaning of this list is controlled by the "
"parameter 'kernel_coverage_check' (whether this is the list of subdomains to be checked, "
"not to be checked or not taken into account).");
params.addParam<bool>(
"boundary_restricted_node_integrity_check",
true,
"Set to false to disable checking of boundary restricted nodal object variable dependencies, "
"e.g. are the variable dependencies defined on the selected boundaries?");
params.addParam<bool>("boundary_restricted_elem_integrity_check",
true,
"Set to false to disable checking of boundary restricted elemental object "
"variable dependencies, e.g. are the variable dependencies defined on the "
"selected boundaries?");
MooseEnum material_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>(
"material_coverage_check",
material_coverage_check_modes,
coverage_check_description("material", "material_coverage_block_list"));
params.addParam<std::vector<SubdomainName>>(
"material_coverage_block_list",
{},
"List of subdomains for material coverage check. The meaning of this list is controlled by "
"the parameter 'material_coverage_check' (whether this is the list of subdomains to be "
"checked, not to be checked or not taken into account).");
params.addParam<bool>("fv_bcs_integrity_check",
true,
"Set to false to disable checking of overlapping Dirichlet and Flux BCs "
"and/or multiple DirichletBCs per sideset");
params.addParam<bool>(
"material_dependency_check", true, "Set to false to disable material dependency check");
params.addParam<bool>("parallel_barrier_messaging",
false,
"Displays messaging from parallel "
"barrier notifications when executing "
"or transferring to/from Multiapps "
"(default: false)");
MooseEnum verbosity("false true extra", "false");
params.addParam<MooseEnum>("verbose_setup",
verbosity,
"Set to 'true' to have the problem report on any object created. Set "
"to 'extra' to also display all parameters.");
params.addParam<bool>("verbose_multiapps",
false,
"Set to True to enable verbose screen printing related to MultiApps");
params.addParam<FileNameNoExtension>("restart_file_base",
"File base name used for restart (e.g. "
"<path>/<filebase> or <path>/LATEST to "
"grab the latest file available)");
params.addParam<std::vector<std::vector<TagName>>>(
"extra_tag_vectors",
{},
"Extra vectors to add to the system that can be filled by objects which compute residuals "
"and Jacobians (Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
"nonlinear system the extra tag vectors should be added for");
params.addParam<std::vector<std::vector<TagName>>>(
"not_zeroed_tag_vectors",
{},
"Extra vector tags which the sytem will not zero when other vector tags are zeroed. "
"The outer index is for which nonlinear system the extra tag vectors should be added for");
params.addParam<std::vector<std::vector<TagName>>>(
"extra_tag_matrices",
{},
"Extra matrices to add to the system that can be filled "
"by objects which compute residuals and Jacobians "
"(Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
"nonlinear system the extra tag vectors should be added for");
params.addParam<std::vector<TagName>>(
"extra_tag_solutions",
{},
"Extra solution vectors to add to the system that can be used by "
"objects for coupling variable values stored in them.");
params.addParam<bool>("previous_nl_solution_required",
false,
"True to indicate that this calculation requires a solution vector for "
"storing the previous nonlinear iteration.");
params.addParam<std::vector<NonlinearSystemName>>(
"nl_sys_names", std::vector<NonlinearSystemName>{"nl0"}, "The nonlinear system names");
params.addParam<std::vector<LinearSystemName>>("linear_sys_names", {}, "The linear system names");
params.addParam<bool>("check_uo_aux_state",
false,
"True to turn on a check that no state presents during the evaluation of "
"user objects and aux kernels");
params.addPrivateParam<MooseMesh *>("mesh");
params.declareControllable("solve");
params.addParam<bool>(
"allow_invalid_solution",
false,
"Set to true to allow convergence even though the solution has been marked as 'invalid'");
params.addParam<bool>("show_invalid_solution_console",
true,
"Set to true to show the invalid solution occurance summary in console");
params.addParam<bool>("immediately_print_invalid_solution",
false,
"Whether or not to report invalid solution warnings at the time the "
"warning is produced instead of after the calculation");
params.addParam<bool>(
"identify_variable_groups_in_nl",
true,
"Whether to identify variable groups in nonlinear systems. This affects dof ordering");
params.addParam<bool>(
"regard_general_exceptions_as_errors",
false,
"If we catch an exception during residual/Jacobian evaluaton for which we don't have "
"specific handling, immediately error instead of allowing the time step to be cut");
params.addParamNamesToGroup(
"skip_nl_system_check kernel_coverage_check kernel_coverage_block_list "
"boundary_restricted_node_integrity_check "
"boundary_restricted_elem_integrity_check material_coverage_check "
"material_coverage_block_list fv_bcs_integrity_check "
"material_dependency_check check_uo_aux_state error_on_jacobian_nonzero_reallocation",
"Simulation checks");
params.addParamNamesToGroup("use_nonlinear previous_nl_solution_required nl_sys_names "
"ignore_zeros_in_jacobian identify_variable_groups_in_nl",
"Nonlinear system(s)");
params.addParamNamesToGroup(
"restart_file_base force_restart allow_initial_conditions_with_restart", "Restart");
params.addParamNamesToGroup("verbose_setup verbose_multiapps parallel_barrier_messaging",
"Verbosity");
params.addParamNamesToGroup(
"null_space_dimension transpose_null_space_dimension near_null_space_dimension",
"Null space removal");
params.addParamNamesToGroup(
"extra_tag_vectors extra_tag_matrices extra_tag_solutions not_zeroed_tag_vectors",
"Contribution to tagged field data");
params.addParamNamesToGroup(
"allow_invalid_solution show_invalid_solution_console immediately_print_invalid_solution",
"Solution validity control");
return params;
}
FEProblemBase::FEProblemBase(const InputParameters & parameters)
: SubProblem(parameters),
Restartable(this, "FEProblemBase"),
_mesh(*getCheckedPointerParam<MooseMesh *>("mesh")),
_req(declareManagedRestartableDataWithContext<RestartableEquationSystems>(
"equation_systems", nullptr, _mesh)),
_initialized(false),
_solve(getParam<bool>("solve")),
_transient(false),
_time(declareRestartableData<Real>("time")),
_time_old(declareRestartableData<Real>("time_old")),
_t_step(declareRecoverableData<int>("t_step")),
_dt(declareRestartableData<Real>("dt")),
_dt_old(declareRestartableData<Real>("dt_old")),
_set_nonlinear_convergence_names(false),
_need_to_add_default_nonlinear_convergence(false),
_linear_sys_names(getParam<std::vector<LinearSystemName>>("linear_sys_names")),
_num_linear_sys(_linear_sys_names.size()),
_linear_systems(_num_linear_sys, nullptr),
_current_linear_sys(nullptr),
_using_default_nl(!isParamSetByUser("nl_sys_names")),
_nl_sys_names(!_using_default_nl || (_using_default_nl && !_linear_sys_names.size())
? getParam<std::vector<NonlinearSystemName>>("nl_sys_names")
: std::vector<NonlinearSystemName>()),
_num_nl_sys(_nl_sys_names.size()),
_nl(_num_nl_sys, nullptr),
_current_nl_sys(nullptr),
_solver_systems(_num_nl_sys + _num_linear_sys, nullptr),
_aux(nullptr),
_coupling(Moose::COUPLING_DIAG),
_mesh_divisions(/*threaded=*/true),
_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
"material_props", &_mesh, _material_prop_registry)),
_bnd_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
"bnd_material_props", &_mesh, _material_prop_registry)),
_neighbor_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
"neighbor_material_props", &_mesh, _material_prop_registry)),
_reporter_data(_app),
// TODO: delete the following line after apps have been updated to not call getUserObjects
_all_user_objects(_app.getExecuteOnEnum()),
_multi_apps(_app.getExecuteOnEnum()),
_transient_multi_apps(_app.getExecuteOnEnum()),
_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
_to_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
_from_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
_between_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
#ifdef LIBMESH_ENABLE_AMR
_adaptivity(*this),
_cycles_completed(0),
#endif
_displaced_mesh(nullptr),
_geometric_search_data(*this, _mesh),
_mortar_data(*this),
_reinit_displaced_elem(false),
_reinit_displaced_face(false),
_reinit_displaced_neighbor(false),
_input_file_saved(false),
_has_dampers(false),
_has_constraints(false),
_snesmf_reuse_base(true),
_skip_exception_check(false),
_snesmf_reuse_base_set_by_user(false),
_has_initialized_stateful(false),
_const_jacobian(false),
_has_jacobian(false),
_needs_old_newton_iter(false),
_previous_nl_solution_required(getParam<bool>("previous_nl_solution_required")),
_has_nonlocal_coupling(false),
_calculate_jacobian_in_uo(false),
_default_blocks(getParam<std::vector<SubdomainName>>("default_block")),
_kernel_coverage_check(
isParamSetByUser("kernel_coverage_check") || !isParamSetByUser("default_block")
? getParam<MooseEnum>("kernel_coverage_check").getEnum<CoverageCheckMode>()
: CoverageCheckMode::ONLY_LIST),
_kernel_coverage_blocks(isParamSetByUser("kernel_coverage_check") ||
!isParamSetByUser("default_block")
? getParam<std::vector<SubdomainName>>("kernel_coverage_block_list")
: _default_blocks),
_boundary_restricted_node_integrity_check(
getParam<bool>("boundary_restricted_node_integrity_check")),
_boundary_restricted_elem_integrity_check(
getParam<bool>("boundary_restricted_elem_integrity_check")),
_material_coverage_check(
isParamSetByUser("material_coverage_check") || !isParamSetByUser("default_block")
? getParam<MooseEnum>("material_coverage_check").getEnum<CoverageCheckMode>()
: CoverageCheckMode::ONLY_LIST),
_material_coverage_blocks(
isParamSetByUser("material_coverage_check") || !isParamSetByUser("default_block")
? getParam<std::vector<SubdomainName>>("material_coverage_block_list")
: _default_blocks),
_fv_bcs_integrity_check(getParam<bool>("fv_bcs_integrity_check")),
_material_dependency_check(getParam<bool>("material_dependency_check")),
_uo_aux_state_check(getParam<bool>("check_uo_aux_state")),
_max_qps(std::numeric_limits<unsigned int>::max()),
_max_scalar_order(INVALID_ORDER),
_has_time_integrator(false),
_has_exception(false),
_parallel_barrier_messaging(getParam<bool>("parallel_barrier_messaging")),
_verbose_setup(getParam<MooseEnum>("verbose_setup")),
_verbose_multiapps(getParam<bool>("verbose_multiapps")),
_current_execute_on_flag(EXEC_NONE),
_control_warehouse(_app.getExecuteOnEnum(), /*threaded=*/false),
_is_petsc_options_inserted(false),
_line_search(nullptr),
_using_ad_mat_props(false),
_current_ic_state(0),
_error_on_jacobian_nonzero_reallocation(
isParamValid("error_on_jacobian_nonzero_reallocation")
? getParam<bool>("error_on_jacobian_nonzero_reallocation")
: _app.errorOnJacobianNonzeroReallocation()),
_ignore_zeros_in_jacobian(getParam<bool>("ignore_zeros_in_jacobian")),
_preserve_matrix_sparsity_pattern(true),
_force_restart(getParam<bool>("force_restart")),
_allow_ics_during_restart(getParam<bool>("allow_initial_conditions_with_restart")),
_skip_nl_system_check(getParam<bool>("skip_nl_system_check")),
_fail_next_nonlinear_convergence_check(false),
_allow_invalid_solution(getParam<bool>("allow_invalid_solution")),
_show_invalid_solution_console(getParam<bool>("show_invalid_solution_console")),
_immediately_print_invalid_solution(getParam<bool>("immediately_print_invalid_solution")),
_started_initial_setup(false),
_has_internal_edge_residual_objects(false),
_u_dot_requested(false),
_u_dotdot_requested(false),
_u_dot_old_requested(false),
_u_dotdot_old_requested(false),
_has_mortar(false),
_num_grid_steps(0),
_print_execution_on(),
_identify_variable_groups_in_nl(getParam<bool>("identify_variable_groups_in_nl")),
_regard_general_exceptions_as_errors(getParam<bool>("regard_general_exceptions_as_errors"))
{
auto checkConflict =
[this](const CoverageCheckMode & coverage_check_mode, const std::string & coverage_check)
{
if ((isParamSetByUser(coverage_check) &&
(coverage_check_mode == CoverageCheckMode::ONLY_LIST ||
coverage_check_mode == CoverageCheckMode::SKIP_LIST)) &&
isParamSetByUser("default_block"))
mooseError("Cannot set both '" + coverage_check +
"' as 'ONLY_LIST' or 'SKIP_LIST' and 'default_block'. Please set only one.");
};
checkConflict(_kernel_coverage_check, "kernel_coverage_check");
checkConflict(_material_coverage_check, "material_coverage_check");
// Initialize static do_derivatives member. We initialize this to true so that all the default AD
// things that we setup early in the simulation actually get their derivative vectors initalized.
// We will toggle this to false when doing residual evaluations
ADReal::do_derivatives = true;
_solver_params.reserve(_num_nl_sys + _num_linear_sys);
// Default constructor fine for nonlinear because it will be populated later by framework
// executioner/solve object parameters
_solver_params.resize(_num_nl_sys);
for (const auto i : index_range(_nl_sys_names))
{
const auto & name = _nl_sys_names[i];
_nl_sys_name_to_num[name] = i;
_solver_sys_name_to_num[name] = i;
_solver_sys_names.push_back(name);
}
for (const auto i : index_range(_linear_sys_names))
{
const auto & name = _linear_sys_names[i];
_linear_sys_name_to_num[name] = i;
_solver_sys_name_to_num[name] = i + _num_nl_sys;
_solver_sys_names.push_back(name);
// Unlike for nonlinear these are basically dummy parameters
_solver_params.push_back(makeLinearSolverParams());
}
_nonlocal_cm.resize(_nl_sys_names.size());
_cm.resize(_nl_sys_names.size());
_time = 0.0;
_time_old = 0.0;
_t_step = 0;
_dt = 0;
_dt_old = _dt;
unsigned int n_threads = libMesh::n_threads();
_real_zero.resize(n_threads, 0.);
_scalar_zero.resize(n_threads);
_zero.resize(n_threads);
_phi_zero.resize(n_threads);
_ad_zero.resize(n_threads);
_grad_zero.resize(n_threads);
_ad_grad_zero.resize(n_threads);
_grad_phi_zero.resize(n_threads);
_second_zero.resize(n_threads);
_ad_second_zero.resize(n_threads);
_second_phi_zero.resize(n_threads);
_point_zero.resize(n_threads);
_vector_zero.resize(n_threads);
_vector_curl_zero.resize(n_threads);
_uo_jacobian_moose_vars.resize(n_threads);
_has_active_material_properties.resize(n_threads, 0);
_block_mat_side_cache.resize(n_threads);
_bnd_mat_side_cache.resize(n_threads);
_interface_mat_side_cache.resize(n_threads);
es().parameters.set<FEProblemBase *>("_fe_problem_base") = this;
if (parameters.isParamSetByUser("coord_type"))
setCoordSystem(getParam<std::vector<SubdomainName>>("block"),
getParam<MultiMooseEnum>("coord_type"));
if (parameters.isParamSetByUser("rz_coord_axis"))
setAxisymmetricCoordAxis(getParam<MooseEnum>("rz_coord_axis"));
if (isParamValid("restart_file_base"))
{
std::string restart_file_base = getParam<FileNameNoExtension>("restart_file_base");
// This check reverts to old behavior of providing "restart_file_base=" to mean
// don't restart... BISON currently relies on this. It could probably be removed.
// The new MooseUtils::convertLatestCheckpoint will error out if a checkpoint file
// is not found, which I think makes sense. Which means, without this, if you
// set "restart_file_base=", you'll get a "No checkpoint file found" error
if (restart_file_base.size())
{
restart_file_base = MooseUtils::convertLatestCheckpoint(restart_file_base);
setRestartFile(restart_file_base);
}
}
// // Generally speaking, the mesh is prepared for use, and consequently remote elements are deleted
// // well before our Problem(s) are constructed. Historically, in MooseMesh we have a bunch of
// // needs_prepare type flags that make it so we never call prepare_for_use (and consequently
// // delete_remote_elements) again. So the below line, historically, has had no impact. HOWEVER:
// // I've added some code in SetupMeshCompleteAction for deleting remote elements post
// // EquationSystems::init. If I execute that code without default ghosting, then I get > 40 MOOSE
// // test failures, so we clearly have some simulations that are not yet covered properly by
// // relationship managers. Until that is resolved, I am going to retain default geometric ghosting
// if (!_default_ghosting)
// _mesh.getMesh().remove_ghosting_functor(_mesh.getMesh().default_ghosting());
#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
// Main app should hold the default database to handle system petsc options
if (!_app.isUltimateMaster())
LibmeshPetscCall(PetscOptionsCreate(&_petsc_option_data_base));
#endif
if (!_solve)
{
// If we are not solving, we do not care about seeing unused petsc options
Moose::PetscSupport::setSinglePetscOption("-options_left", "0");
// We don't want petscSetOptions being called in solve and clearing the option that was just set
_is_petsc_options_inserted = true;
}
}
const MooseMesh &
FEProblemBase::mesh(bool use_displaced) const
{
if (use_displaced && !_displaced_problem)
mooseWarning("Displaced mesh was requested but the displaced problem does not exist. "
"Regular mesh will be returned");
return ((use_displaced && _displaced_problem) ? _displaced_problem->mesh() : mesh());
}
void
FEProblemBase::createTagVectors()
{
// add vectors and their tags to system
auto & vectors = getParam<std::vector<std::vector<TagName>>>("extra_tag_vectors");
for (const auto nl_sys_num : index_range(vectors))
for (auto & vector : vectors[nl_sys_num])
{
auto tag = addVectorTag(vector);
_nl[nl_sys_num]->addVector(tag, false, libMesh::GHOSTED);
}
auto & not_zeroed_vectors = getParam<std::vector<std::vector<TagName>>>("not_zeroed_tag_vectors");
for (const auto nl_sys_num : index_range(not_zeroed_vectors))
for (auto & vector : not_zeroed_vectors[nl_sys_num])
{
auto tag = addVectorTag(vector);
_nl[nl_sys_num]->addVector(tag, false, GHOSTED);
addNotZeroedVectorTag(tag);
}
// add matrices and their tags
auto & matrices = getParam<std::vector<std::vector<TagName>>>("extra_tag_matrices");
for (const auto nl_sys_num : index_range(matrices))
for (auto & matrix : matrices[nl_sys_num])
{
auto tag = addMatrixTag(matrix);
_nl[nl_sys_num]->addMatrix(tag);
}
}
void
FEProblemBase::createTagSolutions()
{
for (auto & vector : getParam<std::vector<TagName>>("extra_tag_solutions"))
{
auto tag = addVectorTag(vector, Moose::VECTOR_TAG_SOLUTION);
for (auto & sys : _solver_systems)
sys->addVector(tag, false, libMesh::GHOSTED);
_aux->addVector(tag, false, libMesh::GHOSTED);
}
if (_previous_nl_solution_required)
{
// We'll populate the zeroth state of the nonlinear iterations with the current solution for
// ease of use in doing things like copying solutions backwards. We're just storing pointers in
// the solution states containers so populating the zeroth state does not cost us the memory of
// a new vector
needSolutionState(2, Moose::SolutionIterationType::Nonlinear);
}
auto tag = addVectorTag(Moose::SOLUTION_TAG, Moose::VECTOR_TAG_SOLUTION);
for (auto & sys : _solver_systems)
sys->associateVectorToTag(*sys->system().current_local_solution.get(), tag);
_aux->associateVectorToTag(*_aux->system().current_local_solution.get(), tag);
}
void
FEProblemBase::needSolutionState(unsigned int oldest_needed,
Moose::SolutionIterationType iteration_type)
{
for (const auto i : make_range((unsigned)0, oldest_needed))
{
for (auto & sys : _solver_systems)
sys->needSolutionState(i, iteration_type);
_aux->needSolutionState(i, iteration_type);
}
}
void
FEProblemBase::newAssemblyArray(std::vector<std::shared_ptr<SolverSystem>> & solver_systems)
{
unsigned int n_threads = libMesh::n_threads();
_assembly.resize(n_threads);
for (const auto i : make_range(n_threads))
{
_assembly[i].resize(solver_systems.size());
for (const auto j : index_range(solver_systems))
_assembly[i][j] = std::make_unique<Assembly>(*solver_systems[j], i);
}
}
void
FEProblemBase::initNullSpaceVectors(const InputParameters & parameters,
std::vector<std::shared_ptr<NonlinearSystemBase>> & nls)
{
TIME_SECTION("initNullSpaceVectors", 5, "Initializing Null Space Vectors");
unsigned int dimNullSpace = parameters.get<unsigned int>("null_space_dimension");
unsigned int dimTransposeNullSpace =
parameters.get<unsigned int>("transpose_null_space_dimension");
unsigned int dimNearNullSpace = parameters.get<unsigned int>("near_null_space_dimension");
for (unsigned int i = 0; i < dimNullSpace; ++i)
{
std::ostringstream oss;
oss << "_" << i;
// do not project, since this will be recomputed, but make it ghosted, since the near nullspace
// builder might march over all nodes
for (auto & nl : nls)
nl->addVector("NullSpace" + oss.str(), false, libMesh::GHOSTED);
}
_subspace_dim["NullSpace"] = dimNullSpace;
for (unsigned int i = 0; i < dimTransposeNullSpace; ++i)
{
std::ostringstream oss;
oss << "_" << i;
// do not project, since this will be recomputed, but make it ghosted, since the near nullspace
// builder might march over all nodes
for (auto & nl : nls)
nl->addVector("TransposeNullSpace" + oss.str(), false, libMesh::GHOSTED);
}
_subspace_dim["TransposeNullSpace"] = dimTransposeNullSpace;
for (unsigned int i = 0; i < dimNearNullSpace; ++i)
{
std::ostringstream oss;
oss << "_" << i;
// do not project, since this will be recomputed, but make it ghosted, since the near-nullspace
// builder might march over all semilocal nodes
for (auto & nl : nls)
nl->addVector("NearNullSpace" + oss.str(), false, libMesh::GHOSTED);
}
_subspace_dim["NearNullSpace"] = dimNearNullSpace;
}
FEProblemBase::~FEProblemBase()
{
// Flush the Console stream, the underlying call to Console::mooseConsole
// relies on a call to Output::checkInterval that has references to
// _time, etc. If it is not flushed here memory problems arise if you have
// an unflushed stream and start destructing things.
_console << std::flush;
unsigned int n_threads = libMesh::n_threads();
for (unsigned int i = 0; i < n_threads; i++)
{
_zero[i].release();
_phi_zero[i].release();
_scalar_zero[i].release();
_grad_zero[i].release();
_grad_phi_zero[i].release();
_second_zero[i].release();
_second_phi_zero[i].release();
_vector_zero[i].release();
_vector_curl_zero[i].release();
_ad_zero[i].release();
_ad_grad_zero[i].release();
_ad_second_zero[i].release();
}
#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
if (!_app.isUltimateMaster())
{
auto ierr = PetscOptionsDestroy(&_petsc_option_data_base);
// Don't throw on destruction
CHKERRABORT(this->comm().get(), ierr);
}
#endif
}
void
FEProblemBase::setCoordSystem(const std::vector<SubdomainName> & blocks,
const MultiMooseEnum & coord_sys)
{
TIME_SECTION("setCoordSystem", 5, "Setting Coordinate System");
_mesh.setCoordSystem(blocks, coord_sys);
}
void
FEProblemBase::setAxisymmetricCoordAxis(const MooseEnum & rz_coord_axis)
{
_mesh.setAxisymmetricCoordAxis(rz_coord_axis);
}
const ConstElemRange &
FEProblemBase::getEvaluableElementRange()
{
if (!_evaluable_local_elem_range)
{
std::vector<const DofMap *> dof_maps(es().n_systems());
for (const auto i : make_range(es().n_systems()))
{
const auto & sys = es().get_system(i);
dof_maps[i] = &sys.get_dof_map();
}
_evaluable_local_elem_range =
std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
_mesh.getMesh().multi_evaluable_elements_end(dof_maps));
}
return *_evaluable_local_elem_range;
}
const ConstElemRange &
FEProblemBase::getNonlinearEvaluableElementRange()
{
if (!_nl_evaluable_local_elem_range)
{
std::vector<const DofMap *> dof_maps(_nl.size());
for (const auto i : index_range(dof_maps))
dof_maps[i] = &_nl[i]->dofMap();
_nl_evaluable_local_elem_range =
std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
_mesh.getMesh().multi_evaluable_elements_end(dof_maps));
}
return *_nl_evaluable_local_elem_range;
}
void
FEProblemBase::initialSetup()
{
TIME_SECTION("initialSetup", 2, "Performing Initial Setup");
SubProblem::initialSetup();
if (_app.isRecovering() + _app.isRestarting() + bool(_app.getExReaderForRestart()) > 1)
mooseError("Checkpoint recovery and restart and exodus restart are all mutually exclusive.");
if (_skip_exception_check)
mooseWarning("MOOSE may fail to catch an exception when the \"skip_exception_check\" parameter "
"is used. If you receive a terse MPI error during execution, remove this "
"parameter and rerun your simulation");
// set state flag indicating that we are in or beyond initialSetup.
// This can be used to throw errors in methods that _must_ be called at construction time.
_started_initial_setup = true;
setCurrentExecuteOnFlag(EXEC_INITIAL);
// Setup the solution states (current, old, etc) in each system based on
// its default and the states requested of each of its variables
for (const auto i : index_range(_solver_systems))
{
_solver_systems[i]->initSolutionState();
if (getDisplacedProblem())
getDisplacedProblem()->solverSys(i).initSolutionState();
}
_aux->initSolutionState();
if (getDisplacedProblem())
getDisplacedProblem()->auxSys().initSolutionState();
// always execute to get the max number of DoF per element and node needed to initialize phi_zero
// variables
dof_id_type global_max_var_n_dofs_per_elem = 0;
for (const auto i : index_range(_solver_systems))
{
auto & sys = *_solver_systems[i];
dof_id_type max_var_n_dofs_per_elem;
dof_id_type max_var_n_dofs_per_node;
{
TIME_SECTION("computingMaxDofs", 3, "Computing Max Dofs Per Element");
MaxVarNDofsPerElem mvndpe(*this, sys);
Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), mvndpe);
max_var_n_dofs_per_elem = mvndpe.max();
_communicator.max(max_var_n_dofs_per_elem);
MaxVarNDofsPerNode mvndpn(*this, sys);
Threads::parallel_reduce(*_mesh.getLocalNodeRange(), mvndpn);
max_var_n_dofs_per_node = mvndpn.max();
_communicator.max(max_var_n_dofs_per_node);
global_max_var_n_dofs_per_elem =
std::max(global_max_var_n_dofs_per_elem, max_var_n_dofs_per_elem);
}
{
TIME_SECTION("assignMaxDofs", 5, "Assigning Maximum Dofs Per Elem");
sys.assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
auto displaced_problem = getDisplacedProblem();
if (displaced_problem)
displaced_problem->solverSys(i).assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
sys.assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
if (displaced_problem)
displaced_problem->solverSys(i).assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
}
}
{
TIME_SECTION("resizingVarValues", 5, "Resizing Variable Values");
for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
{
_phi_zero[tid].resize(global_max_var_n_dofs_per_elem, std::vector<Real>(getMaxQps(), 0.));
_grad_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
std::vector<RealGradient>(getMaxQps(), RealGradient(0.)));
_second_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
std::vector<RealTensor>(getMaxQps(), RealTensor(0.)));
}
}
// Set up stateful material property redistribution, if we suspect
// it may be necessary later.
addAnyRedistributers();
if (_app.isRestarting() || _app.isRecovering() || _force_restart)
{
// Only load all of the vectors if we're recovering
_req.set().setLoadAllVectors(_app.isRecovering());
// This forces stateful material property loading to be an exact one-to-one match
if (_app.isRecovering())
for (auto props : {&_material_props, &_bnd_material_props, &_neighbor_material_props})
props->setRecovering();
TIME_SECTION("restore", 3, "Restoring from backup");
// We could have a cached backup when this app is a sub-app and has been given a Backup
if (!_app.hasInitialBackup())
_app.restore(_app.restartFolderBase(_app.getRestartRecoverFileBase()), _app.isRestarting());
else
_app.restoreFromInitialBackup(_app.isRestarting());
/**
* If this is a restart run, the user may want to override the start time, which we already set
* in the constructor. "_time" however will have been "restored" from the restart file. We need
* to honor the original request of the developer now that the restore has been completed.
*/
if (_app.isRestarting())
{
if (_app.hasStartTime())
_time = _time_old = _app.getStartTime();
else
_time_old = _time;
}
}
else
{
libMesh::ExodusII_IO * reader = _app.getExReaderForRestart();
if (reader)
{
TIME_SECTION("copyingFromExodus", 3, "Copying Variables From Exodus");
for (auto & sys : _solver_systems)
sys->copyVars(*reader);
_aux->copyVars(*reader);
}
else
{
if (_solver_systems[0]->hasVarCopy() || _aux->hasVarCopy())
mooseError("Need Exodus reader to restart variables but the reader is not available\n"
"Use either FileMesh with an Exodus mesh file or FileMeshGenerator with an "
"Exodus mesh file and with use_for_exodus_restart equal to true");
}
}
// Perform output related setups
_app.getOutputWarehouse().initialSetup();