forked from idaholab/moose
/
FEProblemBase.C
7164 lines (6074 loc) · 237 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://www.mooseframework.org
//*
//* 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 "RestartableDataIO.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 "ComputeBoundaryInitialConditionThread.h"
#include "MaxQpsThread.h"
#include "ActionWarehouse.h"
#include "Conversion.h"
#include "Material.h"
#include "ConstantIC.h"
#include "Parser.h"
#include "ElementH1Error.h"
#include "Function.h"
#include "NonlinearSystem.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 "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 "Indicator.h"
#include "Marker.h"
#include "MultiApp.h"
#include "MultiAppTransfer.h"
#include "TransientMultiApp.h"
#include "ElementUserObject.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 "TimedPrint.h"
#include "MaxVarNDofsPerElem.h"
#include "MaxVarNDofsPerNode.h"
#include "FVKernel.h"
#include "FVTimeKernel.h"
#include "MooseVariableFV.h"
#include "FVBoundaryCondition.h"
#include "FVInterfaceKernel.h"
#include "Reporter.h"
#include "ADUtils.h"
#include "Executioner.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 "metaphysicl/dualnumber.h"
// 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;
defineLegacyParams(FEProblemBase);
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.addParam<bool>("skip_additional_restart_data",
false,
"True to skip additional data in equation system for restart. It is useful "
"for starting a transient calculation with a steady-state solution");
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).");
/// 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.addParam<std::vector<SubdomainName>>("block", "Block IDs for the coordinate systems");
MultiMooseEnum coord_types("XYZ RZ RSPHERICAL", "XYZ");
MooseEnum rz_coord_axis("X=0 Y=1", "Y");
params.addParam<MultiMooseEnum>(
"coord_type", coord_types, "Type of the coordinate system per block param");
params.addParam<MooseEnum>(
"rz_coord_axis", rz_coord_axis, "The rotation axis (X | Y) for axisymetric coordinates");
params.addParam<bool>(
"kernel_coverage_check", true, "Set to false to disable kernel->subdomain coverage check");
params.addParam<bool>("material_coverage_check",
true,
"Set to false to disable material->subdomain coverage check");
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)");
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<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.");
params.addParam<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.");
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 prvious nonlinear iteration.");
params.addPrivateParam<MooseMesh *>("mesh");
params.declareControllable("solve");
return params;
}
FEProblemBase::FEProblemBase(const InputParameters & parameters)
: SubProblem(parameters),
Restartable(this, "FEProblemBase"),
_mesh(*getCheckedPointerParam<MooseMesh *>("mesh")),
_eq(_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")),
_nl(nullptr),
_aux(nullptr),
_coupling(Moose::COUPLING_DIAG),
_material_props(
declareRestartableDataWithContext<MaterialPropertyStorage>("material_props", &_mesh)),
_bnd_material_props(
declareRestartableDataWithContext<MaterialPropertyStorage>("bnd_material_props", &_mesh)),
_neighbor_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
"neighbor_material_props", &_mesh)),
_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),
#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),
_has_nonlocal_coupling(false),
_calculate_jacobian_in_uo(false),
_kernel_coverage_check(getParam<bool>("kernel_coverage_check")),
_material_coverage_check(getParam<bool>("material_coverage_check")),
_fv_bcs_integrity_check(getParam<bool>("fv_bcs_integrity_check")),
_material_dependency_check(getParam<bool>("material_dependency_check")),
_max_qps(std::numeric_limits<unsigned int>::max()),
_max_shape_funcs(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")),
_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),
_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")),
_force_restart(getParam<bool>("force_restart")),
_skip_additional_restart_data(getParam<bool>("skip_additional_restart_data")),
_skip_nl_system_check(getParam<bool>("skip_nl_system_check")),
_fail_next_linear_convergence_check(false),
_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),
_displaced_neighbor_ref_pts("invert_elem_phys use_undisplaced_ref unset", "unset")
{
// 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;
_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);
_material_data.resize(n_threads);
_bnd_material_data.resize(n_threads);
_neighbor_material_data.resize(n_threads);
for (unsigned int i = 0; i < n_threads; i++)
{
_material_data[i] = std::make_shared<MaterialData>(_material_props);
_bnd_material_data[i] = std::make_shared<MaterialData>(_bnd_material_props);
_neighbor_material_data[i] = std::make_shared<MaterialData>(_neighbor_material_props);
}
_active_elemental_moose_variables.resize(n_threads);
_block_mat_side_cache.resize(n_threads);
_bnd_mat_side_cache.resize(n_threads);
_interface_mat_side_cache.resize(n_threads);
_restart_io = libmesh_make_unique<RestartableDataIO>(*this);
_eq.parameters.set<FEProblemBase *>("_fe_problem_base") = this;
setCoordSystem(getParam<std::vector<SubdomainName>>("block"),
getParam<MultiMooseEnum>("coord_type"));
setAxisymmetricCoordAxis(getParam<MooseEnum>("rz_coord_axis"));
if (isParamValid("restart_file_base"))
{
std::string restart_file_base = getParam<FileNameNoExtension>("restart_file_base");
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)
// Master app should hold the default database to handle system petsc options
if (!_app.isUltimateMaster())
PetscOptionsCreate(&_petsc_option_data_base);
#endif
}
void
FEProblemBase::createTagVectors()
{
// add vectors and their tags to system
auto & vectors = getParam<std::vector<TagName>>("extra_tag_vectors");
for (auto & vector : vectors)
{
auto tag = addVectorTag(vector);
_nl->addVector(tag, false, GHOSTED);
}
// add matrices and their tags
auto & matrices = getParam<std::vector<TagName>>("extra_tag_matrices");
for (auto & matrix : matrices)
{
auto tag = addMatrixTag(matrix);
_nl->addMatrix(tag);
}
}
void
FEProblemBase::createTagSolutions()
{
auto & vectors = getParam<std::vector<TagName>>("extra_tag_solutions");
for (auto & vector : vectors)
{
auto tag = addVectorTag(vector, Moose::VECTOR_TAG_SOLUTION);
_nl->addVector(tag, false, GHOSTED);
_aux->addVector(tag, false, GHOSTED);
}
if (getParam<bool>("previous_nl_solution_required"))
{
auto tag = addVectorTag(Moose::PREVIOUS_NL_SOLUTION_TAG, Moose::VECTOR_TAG_SOLUTION);
_nl->addVector(tag, false, GHOSTED);
_aux->addVector(tag, false, GHOSTED);
}
auto tag = addVectorTag(Moose::SOLUTION_TAG, Moose::VECTOR_TAG_SOLUTION);
_nl->associateVectorToTag(*_nl->system().current_local_solution.get(), tag);
_aux->associateVectorToTag(*_aux->system().current_local_solution.get(), tag);
}
void
FEProblemBase::newAssemblyArray(NonlinearSystemBase & nl)
{
unsigned int n_threads = libMesh::n_threads();
_assembly.resize(n_threads);
for (unsigned int i = 0; i < n_threads; ++i)
_assembly[i] = libmesh_make_unique<Assembly>(nl, i);
}
void
FEProblemBase::initNullSpaceVectors(const InputParameters & parameters, NonlinearSystemBase & nl)
{
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
nl.addVector("NullSpace" + oss.str(), false, 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
nl.addVector("TransposeNullSpace" + oss.str(), false, 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
nl.addVector("NearNullSpace" + oss.str(), false, 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())
PetscOptionsDestroy(&_petsc_option_data_base);
#endif
}
Moose::CoordinateSystemType
FEProblemBase::getCoordSystem(SubdomainID sid) const
{
auto it = _coord_sys.find(sid);
if (it != _coord_sys.end())
return (*it).second;
else
mooseError("Requested subdomain ", sid, " does not exist.");
}
void
FEProblemBase::setCoordSystem(const std::vector<SubdomainName> & blocks,
const MultiMooseEnum & coord_sys)
{
TIME_SECTION("setCoordSystem", 5, "Setting Coordinate System");
const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
if (blocks.size() == 0)
{
// no blocks specified -> assume the whole domain
Moose::CoordinateSystemType coord_type = Moose::COORD_XYZ; // all is going to be XYZ by default
if (coord_sys.size() == 0)
; // relax, do nothing
else if (coord_sys.size() == 1)
coord_type = Moose::stringToEnum<Moose::CoordinateSystemType>(
coord_sys[0]); // one system specified, the whole domain is going to have that system
else
mooseError("Multiple coordinate systems specified, but no blocks given.");
for (const auto & sbd : subdomains)
_coord_sys[sbd] = coord_type;
}
else
{
// user specified 'blocks' but not coordinate systems
if (coord_sys.size() == 0)
{
// set all blocks to cartesian coordinate system
for (const auto & block : blocks)
{
SubdomainID sid = _mesh.getSubdomainID(block);
_coord_sys[sid] = Moose::COORD_XYZ;
}
}
else if (coord_sys.size() == 1)
{
// set all blocks to the coordinate system specified by `coord_sys[0]`
Moose::CoordinateSystemType coord_type =
Moose::stringToEnum<Moose::CoordinateSystemType>(coord_sys[0]);
for (const auto & block : blocks)
{
SubdomainID sid = _mesh.getSubdomainID(block);
_coord_sys[sid] = coord_type;
}
}
else
{
if (blocks.size() != coord_sys.size())
mooseError("Number of blocks and coordinate systems does not match.");
for (unsigned int i = 0; i < blocks.size(); i++)
{
SubdomainID sid = _mesh.getSubdomainID(blocks[i]);
Moose::CoordinateSystemType coord_type =
Moose::stringToEnum<Moose::CoordinateSystemType>(coord_sys[i]);
_coord_sys[sid] = coord_type;
}
for (const auto & sid : subdomains)
if (_coord_sys.find(sid) == _coord_sys.end())
mooseError("Subdomain '" + Moose::stringify(sid) +
"' does not have a coordinate system specified.");
}
}
}
void
FEProblemBase::setAxisymmetricCoordAxis(const MooseEnum & rz_coord_axis)
{
_rz_coord_axis = rz_coord_axis;
}
const ConstElemRange &
FEProblemBase::getEvaluableElementRange()
{
if (!_evaluable_local_elem_range)
{
_evaluable_local_elem_range =
libmesh_make_unique<ConstElemRange>(_mesh.getMesh().evaluable_elements_begin(_nl->dofMap()),
_mesh.getMesh().evaluable_elements_end(_nl->dofMap()));
}
return *_evaluable_local_elem_range;
}
void
FEProblemBase::initialSetup()
{
TIME_SECTION("initialSetup", 2, "Performing Initial Setup");
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
_nl->initSolutionState();
_aux->initSolutionState();
if (getDisplacedProblem())
{
getDisplacedProblem()->nlSys().initSolutionState();
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 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, *_nl);
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, *_nl);
Threads::parallel_reduce(*_mesh.getLocalNodeRange(), mvndpn);
max_var_n_dofs_per_node = mvndpn.max();
_communicator.max(max_var_n_dofs_per_node);
}
{
TIME_SECTION("assignMaxDofs", 5, "Assigning Maximum Dofs Per Elem");
_nl->assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
auto displaced_problem = getDisplacedProblem();
if (displaced_problem)
displaced_problem->nlSys().assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
_nl->assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
if (displaced_problem)
displaced_problem->nlSys().assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
}
{
TIME_SECTION("settingRequireDerivativeSize", 5, "Setting Required Derivative Size");
#ifndef MOOSE_SPARSE_AD
auto size_required = max_var_n_dofs_per_elem * _nl->nVariables();
if (hasMortarCoupling())
size_required *= 3;
else if (hasNeighborCoupling())
size_required *= 2;
_nl->setRequiredDerivativeSize(size_required);
#endif
}
{
TIME_SECTION("resizingVarValues", 5, "Resizing Variable Vlues");
for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
{
_phi_zero[tid].resize(_nl->getMaxVarNDofsPerElem(), std::vector<Real>(getMaxQps(), 0.));
_grad_phi_zero[tid].resize(_nl->getMaxVarNDofsPerElem(),
std::vector<RealGradient>(getMaxQps(), RealGradient(0.)));
_second_phi_zero[tid].resize(_nl->getMaxVarNDofsPerElem(),
std::vector<RealTensor>(getMaxQps(), RealTensor(0.)));
}
}
if (_app.isRecovering() && (_app.isUltimateMaster() || _force_restart))
{
if (_app.getRestartRecoverFileSuffix() == "cpa")
_restart_io->useAsciiExtension();
}
if ((_app.isRestarting() || _app.isRecovering()) && (_app.isUltimateMaster() || _force_restart))
{
TIME_SECTION("restartFromFile", 3, "Restarting From File");
_restart_io->readRestartableDataHeader(true);
_restart_io->restartEquationSystemsObject();
/**
* TODO: Move the RestartableDataIO call to reload data here. Only a few tests fail when doing
* this now. Material Properties aren't sized properly at this point and fail across the board,
* there are a few other misc tests that fail too.
*
* _restart_io->readRestartableData();
*/
}
else
{
ExodusII_IO * reader = _app.getExReaderForRestart();
if (reader)
{
TIME_SECTION("copyingFromExodus", 3, "Copying Variables From Exodus");
_nl->copyVars(*reader);
_aux->copyVars(*reader);
}
else
{
if (_nl->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();
// Flush all output to _console that occur during construction and initialization of objects
_app.getOutputWarehouse().mooseConsole();
// Build Refinement and Coarsening maps for stateful material projections if necessary
if ((_adaptivity.isOn() || _num_grid_steps) &&
(_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
_neighbor_material_props.hasStatefulProperties()))
{
if (_has_internal_edge_residual_objects)
mooseError("Stateful neighbor material properties do not work with mesh adaptivity");
_mesh.buildRefinementAndCoarseningMaps(_assembly[0].get());
}
if (!_app.isRecovering())
{
/**
* If we are not recovering but we are doing restart (_app.getExodusFileRestart() == true) with
* additional uniform refinements. We have to delay the refinement until this point
* in time so that the equation systems are initialized and projections can be performed.
*/
if (_mesh.uniformRefineLevel() > 0 && _app.getExodusFileRestart())
{
if (!_app.isUltimateMaster())
mooseError(
"Doing extra refinements when restarting is NOT supported for sub-apps of a MultiApp");
adaptivity().uniformRefineWithProjection();
}
}
unsigned int n_threads = libMesh::n_threads();
// UserObject initialSetup
std::set<std::string> depend_objects_ic = _ics.getDependObjects();
std::set<std::string> depend_objects_aux = _aux->getDependObjects();
// This replaces all prior updateDependObjects calls on the old user object warehouses.
std::vector<UserObject *> userobjs;
theWarehouse().query().condition<AttribSystem>("UserObject").queryInto(userobjs);
groupUserObjects(theWarehouse(), userobjs, depend_objects_ic, depend_objects_aux);
for (auto obj : userobjs)
obj->initialSetup();
// check if jacobian calculation is done in userobject
for (THREAD_ID tid = 0; tid < n_threads; ++tid)
checkUserObjectJacobianRequirement(tid);
// Check whether nonlocal couling is required or not
checkNonlocalCoupling();
if (_requires_nonlocal_coupling)
setVariableAllDoFMap(_uo_jacobian_moose_vars[0]);
{
TIME_SECTION("initializingFunctions", 5, "Initializing Functions");
// Call the initialSetup methods for functions
for (THREAD_ID tid = 0; tid < n_threads; tid++)
{
reinitScalars(tid); // initialize scalars so they are properly sized for use as input into
// ParsedFunctions
_functions.initialSetup(tid);
}
}
{
TIME_SECTION("initializingRandomObjects", 5, "Initializing Random Objects");
// Random interface objects
for (const auto & it : _random_data_objects)
it.second->updateSeeds(EXEC_INITIAL);
}
if (!_app.isRecovering())
{
computeUserObjects(EXEC_INITIAL, Moose::PRE_IC);
{
TIME_SECTION("ICiniitalSetup", 5, "Setting Up Initial Conditions");
for (THREAD_ID tid = 0; tid < n_threads; tid++)
_ics.initialSetup(tid);
_scalar_ics.initialSetup();
}
projectSolution();
}
// Materials
if (_all_materials.hasActiveObjects(0))
{
TIME_SECTION("materialInitialSetup", 3, "Setting Up Materials");
for (THREAD_ID tid = 0; tid < n_threads; tid++)
{
// Sort the Material objects, these will be actually computed by MOOSE in reinit methods.
_materials.sort(tid);
_interface_materials.sort(tid);
// Call initialSetup on all material objects
_all_materials.initialSetup(tid);
}
{
TIME_SECTION("computingInitialResidual", 3, "Computing Initial Residual");
ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
ComputeMaterialsObjectThread cmt(*this,
_material_data,
_bnd_material_data,
_neighbor_material_data,
_material_props,
_bnd_material_props,
_neighbor_material_props,
_assembly);
/**
* The ComputeMaterialObjectThread object now allocates memory as needed for the material
* storage system.
* This cannot be done with threads. The first call to this object bypasses threading by
* calling the object directly. The subsequent call can be called with threads.
*/
cmt(elem_range, true);
if (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
_neighbor_material_props.hasStatefulProperties())
_has_initialized_stateful = true;
}
}
for (THREAD_ID tid = 0; tid < n_threads; tid++)
{
_internal_side_indicators.initialSetup(tid);
_indicators.initialSetup(tid);
_markers.sort(tid);
_markers.initialSetup(tid);
}
#ifdef LIBMESH_ENABLE_AMR
if (!_app.isRecovering())
{
unsigned int n = adaptivity().getInitialSteps();
if (n && !_app.isUltimateMaster() && _app.isRestarting())
mooseError("Cannot perform initial adaptivity during restart on sub-apps of a MultiApp!");
initialAdaptMesh();
}
#endif // LIBMESH_ENABLE_AMR
if (!_app.isRecovering() && !_app.isRestarting())
{
// During initial setup the solution is copied to the older solution states (old, older, etc)
copySolutionsBackwards();
}
if (!_app.isRecovering())
{
if (haveXFEM())
updateMeshXFEM();
}
// Call initialSetup on the nonlinear system
_nl->initialSetup();
// Auxilary variable initialSetup calls
_aux->initialSetup();
if (_displaced_problem)
// initialSetup for displaced systems
_displaced_problem->initialSetup();
_nl->setSolution(*(_nl->system().current_local_solution.get()));
// Update the nearest node searches (has to be called after the problem is all set up)
// We do this here because this sets up the Element's DoFs to ghost
updateGeomSearch(GeometricSearchData::NEAREST_NODE);
_mesh.updateActiveSemiLocalNodeRange(_ghosted_elems);
if (_displaced_mesh)
_displaced_mesh->updateActiveSemiLocalNodeRange(_ghosted_elems);
// We need to move the mesh in order to build a map between mortar secondary and primary
// interfaces. This map will then be used by the AgumentSparsityOnInterface ghosting functor to
// know which dofs we need ghosted when we call EquationSystems::reinit
if (_displaced_problem && _mortar_data.hasDisplacedObjects())
_displaced_problem->updateMesh();
// Build the mortar segment meshes for a couple reasons:
// 1) Get the ghosting correct for both static and dynamic meshes
// 2) Make sure the mortar mesh is built for mortar constraints that live on the static mesh
//
// It is worth-while to note that mortar meshes that live on a dynamic mesh will be built
// during residual and Jacobian evaluation because when displacements are solution variables
// the mortar mesh will move and change during the course of a non-linear solve. We DO NOT
// redo ghosting during non-linear solve, so for purpose 1) the below call has to be made
updateMortarMesh();
// Possibly reinit one more time to get ghosting correct
reinitBecauseOfGhostingOrNewGeomObjects();
if (_displaced_mesh)
_displaced_problem->updateMesh();
updateGeomSearch(); // Call all of the rest of the geometric searches
auto ti = _nl->getTimeIntegrator();
if (ti)
{
TIME_SECTION("timeIntegratorInitialSetup", 5, "Initializing Time Integrator");
ti->initialSetup();
}
if (_app.isRestarting() || _app.isRecovering())
{
if (_app.hasCachedBackup()) // This happens when this app is a sub-app and has been given a
// Backup
_app.restoreCachedBackup();
else
{
TIME_SECTION("restoreRestartData", 3, "Restoring Restart Data");
_restart_io->readRestartableData(_app.getRestartableData(), _app.getRecoverableData());
}
// We may have just clobbered initial conditions that were explicitly set
// In a _restart_ scenario it is completely valid to specify new initial conditions
// for some of the variables which should override what's coming from the restart file
if (!_app.isRecovering())
{
TIME_SECTION("reprojectInitialConditions", 3, "Reprojecting Initial Conditions");
for (THREAD_ID tid = 0; tid < n_threads; tid++)
_ics.initialSetup(tid);
_scalar_ics.sort();
projectSolution();
}
}
// HUGE NOTE: MultiApp initialSetup() MUST... I repeat MUST be _after_ main-app restartable data
// has been restored
// Call initialSetup on the MultiApps
if (_multi_apps.hasObjects())
{
TIME_SECTION("initialSetupMultiApps", 2, "Initializing MultiApps", false);
_multi_apps.initialSetup();
}
// Call initialSetup on the transfers
{
TIME_SECTION("initialSetupTransfers", 2, "Initializing Transfers");
_transfers.initialSetup();
// Call initialSetup on the MultiAppTransfers to be executed on TO_MULTIAPP
const auto & to_multi_app_objects = _to_multi_app_transfers.getActiveObjects();
for (const auto & transfer : to_multi_app_objects)