LCOV - code coverage report
Current view: top level - src/problems - FEProblemBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31613 (c7d555) with base 7323e9 Lines: 4169 4812 86.6 %
Date: 2025-11-06 14:13:52 Functions: 360 406 88.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #ifdef MOOSE_KOKKOS_ENABLED
      11             : #include "KokkosMaterialPropertyStorage.h"
      12             : #endif
      13             : 
      14             : #include "FEProblemBase.h"
      15             : #include "AuxiliarySystem.h"
      16             : #include "MaterialPropertyStorage.h"
      17             : #include "MooseEnum.h"
      18             : #include "Factory.h"
      19             : #include "MooseUtils.h"
      20             : #include "DisplacedProblem.h"
      21             : #include "SystemBase.h"
      22             : #include "MaterialData.h"
      23             : #include "ComputeUserObjectsThread.h"
      24             : #include "ComputeNodalUserObjectsThread.h"
      25             : #include "ComputeThreadedGeneralUserObjectsThread.h"
      26             : #include "ComputeMaterialsObjectThread.h"
      27             : #include "ProjectMaterialProperties.h"
      28             : #include "ComputeIndicatorThread.h"
      29             : #include "ComputeMarkerThread.h"
      30             : #include "ComputeInitialConditionThread.h"
      31             : #include "ComputeFVInitialConditionThread.h"
      32             : #include "ComputeBoundaryInitialConditionThread.h"
      33             : #include "MaxQpsThread.h"
      34             : #include "ActionWarehouse.h"
      35             : #include "Conversion.h"
      36             : #include "Material.h"
      37             : #include "FunctorMaterial.h"
      38             : #include "ConstantIC.h"
      39             : #include "Parser.h"
      40             : #include "ElementH1Error.h"
      41             : #include "Function.h"
      42             : #include "Convergence.h"
      43             : #include "NonlinearSystem.h"
      44             : #include "LinearSystem.h"
      45             : #include "SolverSystem.h"
      46             : #include "Distribution.h"
      47             : #include "Sampler.h"
      48             : #include "PetscSupport.h"
      49             : #include "RandomInterface.h"
      50             : #include "RandomData.h"
      51             : #include "MooseEigenSystem.h"
      52             : #include "MooseParsedFunction.h"
      53             : #include "MeshChangedInterface.h"
      54             : #include "MeshDisplacedInterface.h"
      55             : #include "ComputeJacobianBlocksThread.h"
      56             : #include "ScalarInitialCondition.h"
      57             : #include "FVInitialConditionTempl.h"
      58             : #include "ElementPostprocessor.h"
      59             : #include "NodalPostprocessor.h"
      60             : #include "SidePostprocessor.h"
      61             : #include "InternalSidePostprocessor.h"
      62             : #include "InterfacePostprocessor.h"
      63             : #include "GeneralPostprocessor.h"
      64             : #include "ElementVectorPostprocessor.h"
      65             : #include "NodalVectorPostprocessor.h"
      66             : #include "SideVectorPostprocessor.h"
      67             : #include "InternalSideVectorPostprocessor.h"
      68             : #include "GeneralVectorPostprocessor.h"
      69             : #include "Positions.h"
      70             : #include "Indicator.h"
      71             : #include "Marker.h"
      72             : #include "MultiApp.h"
      73             : #include "MultiAppTransfer.h"
      74             : #include "TransientMultiApp.h"
      75             : #include "ElementUserObject.h"
      76             : #include "DomainUserObject.h"
      77             : #include "NodalUserObject.h"
      78             : #include "SideUserObject.h"
      79             : #include "InternalSideUserObject.h"
      80             : #include "InterfaceUserObject.h"
      81             : #include "GeneralUserObject.h"
      82             : #include "ThreadedGeneralUserObject.h"
      83             : #include "InternalSideIndicatorBase.h"
      84             : #include "Transfer.h"
      85             : #include "MultiAppTransfer.h"
      86             : #include "MultiMooseEnum.h"
      87             : #include "Predictor.h"
      88             : #include "Assembly.h"
      89             : #include "Control.h"
      90             : #include "XFEMInterface.h"
      91             : #include "ConsoleUtils.h"
      92             : #include "NonlocalKernel.h"
      93             : #include "NonlocalIntegratedBC.h"
      94             : #include "ShapeElementUserObject.h"
      95             : #include "ShapeSideUserObject.h"
      96             : #include "MooseVariableFE.h"
      97             : #include "MooseVariableScalar.h"
      98             : #include "InputParameterWarehouse.h"
      99             : #include "TimeIntegrator.h"
     100             : #include "LineSearch.h"
     101             : #include "FloatingPointExceptionGuard.h"
     102             : #include "MaxVarNDofsPerElem.h"
     103             : #include "MaxVarNDofsPerNode.h"
     104             : #include "FVKernel.h"
     105             : #include "LinearFVKernel.h"
     106             : #include "FVTimeKernel.h"
     107             : #include "MooseVariableFV.h"
     108             : #include "MooseLinearVariableFV.h"
     109             : #include "FVBoundaryCondition.h"
     110             : #include "LinearFVBoundaryCondition.h"
     111             : #include "FVInterfaceKernel.h"
     112             : #include "Reporter.h"
     113             : #include "ADUtils.h"
     114             : #include "Executioner.h"
     115             : #include "VariadicTable.h"
     116             : #include "BoundaryNodeIntegrityCheckThread.h"
     117             : #include "BoundaryElemIntegrityCheckThread.h"
     118             : #include "NodalBCBase.h"
     119             : #include "MortarUserObject.h"
     120             : #include "MortarUserObjectThread.h"
     121             : #include "RedistributeProperties.h"
     122             : #include "Checkpoint.h"
     123             : #include "MortarInterfaceWarehouse.h"
     124             : #include "AutomaticMortarGeneration.h"
     125             : 
     126             : #include "libmesh/exodusII_io.h"
     127             : #include "libmesh/quadrature.h"
     128             : #include "libmesh/coupling_matrix.h"
     129             : #include "libmesh/nonlinear_solver.h"
     130             : #include "libmesh/sparse_matrix.h"
     131             : #include "libmesh/string_to_enum.h"
     132             : #include "libmesh/fe_interface.h"
     133             : #include "libmesh/enum_norm_type.h"
     134             : #include "libmesh/petsc_solver_exception.h"
     135             : 
     136             : #include "metaphysicl/dualnumber.h"
     137             : 
     138             : using namespace libMesh;
     139             : 
     140             : // Anonymous namespace for helper function
     141             : namespace
     142             : {
     143             : /**
     144             :  * Method for sorting the MooseVariableFEBases based on variable numbers
     145             :  */
     146             : bool
     147          74 : sortMooseVariables(const MooseVariableFEBase * a, const MooseVariableFEBase * b)
     148             : {
     149          74 :   return a->number() < b->number();
     150             : }
     151             : } // namespace
     152             : 
     153             : Threads::spin_mutex get_function_mutex;
     154             : 
     155             : InputParameters
     156      352689 : FEProblemBase::validParams()
     157             : {
     158      352689 :   InputParameters params = SubProblem::validParams();
     159     1410756 :   params.addParam<unsigned int>("null_space_dimension", 0, "The dimension of the nullspace");
     160     1058067 :   params.addParam<unsigned int>(
     161      705378 :       "transpose_null_space_dimension", 0, "The dimension of the transpose nullspace");
     162     1058067 :   params.addParam<unsigned int>(
     163      705378 :       "near_null_space_dimension", 0, "The dimension of the near nullspace");
     164     1058067 :   params.addParam<bool>("solve",
     165      705378 :                         true,
     166             :                         "Whether or not to actually solve the Nonlinear system.  "
     167             :                         "This is handy in the case that all you want to do is "
     168             :                         "execute AuxKernels, Transfers, etc. without actually "
     169             :                         "solving anything");
     170     1058067 :   params.addParam<bool>("use_nonlinear",
     171      705378 :                         true,
     172             :                         "Determines whether to use a Nonlinear vs a "
     173             :                         "Eigenvalue system (Automatically determined based "
     174             :                         "on executioner)");
     175     1410756 :   params.addParam<bool>("error_on_jacobian_nonzero_reallocation",
     176             :                         "This causes PETSc to error if it had to reallocate memory in the Jacobian "
     177             :                         "matrix due to not having enough nonzeros");
     178     1058067 :   params.addParam<bool>("ignore_zeros_in_jacobian",
     179      705378 :                         false,
     180             :                         "Do not explicitly store zero values in "
     181             :                         "the Jacobian matrix if true");
     182     1058067 :   params.addParam<bool>("force_restart",
     183      705378 :                         false,
     184             :                         "EXPERIMENTAL: If true, a sub_app may use a "
     185             :                         "restart file instead of using of using the master "
     186             :                         "backup file");
     187     1763445 :   params.addDeprecatedParam<bool>("skip_additional_restart_data",
     188      705378 :                                   false,
     189             :                                   "True to skip additional data in equation system for restart.",
     190             :                                   "This parameter is no longer used, as we do not load additional "
     191             :                                   "vectors by default with restart");
     192     1058067 :   params.addParam<bool>("skip_nl_system_check",
     193      705378 :                         false,
     194             :                         "True to skip the NonlinearSystem check for work to do (e.g. Make sure "
     195             :                         "that there are variables to solve for).");
     196     1058067 :   params.addParam<bool>("allow_initial_conditions_with_restart",
     197      705378 :                         false,
     198             :                         "True to allow the user to specify initial conditions when restarting. "
     199             :                         "Initial conditions can override any restarted field");
     200             : 
     201      705378 :   auto coverage_check_description = [](std::string scope, std::string list_param_name)
     202             :   {
     203     1410756 :     return "Controls, if and how a " + scope +
     204             :            " subdomain coverage check is performed. "
     205             :            "With 'TRUE' or 'ON' all subdomains are checked (the default). Setting 'FALSE' or 'OFF' "
     206             :            "will disable the check for all subdomains. "
     207             :            "To exclude a predefined set of subdomains 'SKIP_LIST' is to "
     208     1410756 :            "be used, while the subdomains to skip are to be defined in the parameter '" +
     209     1410756 :            list_param_name +
     210             :            "'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
     211     2116134 :            "be used (again, using the parameter '" +
     212     1410756 :            list_param_name + "').";
     213             :   };
     214             : 
     215     1763445 :   params.addParam<std::vector<SubdomainName>>(
     216             :       "block",
     217             :       {"ANY_BLOCK_ID"},
     218             :       "List of subdomains for kernel coverage and material coverage checks. Setting this parameter "
     219             :       "is equivalent to setting 'kernel_coverage_block_list' and 'material_coverage_block_list' as "
     220             :       "well as using 'ONLY_LIST' as the coverage check mode.");
     221             : 
     222     1410756 :   MooseEnum kernel_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
     223      352689 :   params.addParam<MooseEnum>("kernel_coverage_check",
     224             :                              kernel_coverage_check_modes,
     225     1763445 :                              coverage_check_description("kernel", "kernel_coverage_block_list"));
     226     1410756 :   params.addParam<std::vector<SubdomainName>>(
     227             :       "kernel_coverage_block_list",
     228             :       {},
     229             :       "List of subdomains for kernel coverage check. The meaning of this list is controlled by the "
     230             :       "parameter 'kernel_coverage_check' (whether this is the list of subdomains to be checked, "
     231             :       "not to be checked or not taken into account).");
     232     1058067 :   params.addParam<bool>(
     233             :       "boundary_restricted_node_integrity_check",
     234      705378 :       true,
     235             :       "Set to false to disable checking of boundary restricted nodal object variable dependencies, "
     236             :       "e.g. are the variable dependencies defined on the selected boundaries?");
     237     1058067 :   params.addParam<bool>("boundary_restricted_elem_integrity_check",
     238      705378 :                         true,
     239             :                         "Set to false to disable checking of boundary restricted elemental object "
     240             :                         "variable dependencies, e.g. are the variable dependencies defined on the "
     241             :                         "selected boundaries?");
     242     1410756 :   MooseEnum material_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
     243      352689 :   params.addParam<MooseEnum>(
     244             :       "material_coverage_check",
     245             :       material_coverage_check_modes,
     246     1763445 :       coverage_check_description("material", "material_coverage_block_list"));
     247     1410756 :   params.addParam<std::vector<SubdomainName>>(
     248             :       "material_coverage_block_list",
     249             :       {},
     250             :       "List of subdomains for material coverage check. The meaning of this list is controlled by "
     251             :       "the parameter 'material_coverage_check' (whether this is the list of subdomains to be "
     252             :       "checked, not to be checked or not taken into account).");
     253             : 
     254     1058067 :   params.addParam<bool>("fv_bcs_integrity_check",
     255      705378 :                         true,
     256             :                         "Set to false to disable checking of overlapping Dirichlet and Flux BCs "
     257             :                         "and/or multiple DirichletBCs per sideset");
     258             : 
     259     1058067 :   params.addParam<bool>(
     260      705378 :       "material_dependency_check", true, "Set to false to disable material dependency check");
     261     1058067 :   params.addParam<bool>("parallel_barrier_messaging",
     262      705378 :                         false,
     263             :                         "Displays messaging from parallel "
     264             :                         "barrier notifications when executing "
     265             :                         "or transferring to/from Multiapps "
     266             :                         "(default: false)");
     267             : 
     268     1410756 :   MooseEnum verbosity("false true extra", "false");
     269     1410756 :   params.addParam<MooseEnum>("verbose_setup",
     270             :                              verbosity,
     271             :                              "Set to 'true' to have the problem report on any object created. Set "
     272             :                              "to 'extra' to also display all parameters.");
     273     1058067 :   params.addParam<bool>("verbose_multiapps",
     274      705378 :                         false,
     275             :                         "Set to True to enable verbose screen printing related to MultiApps");
     276     1058067 :   params.addParam<bool>(
     277             :       "verbose_restore",
     278      705378 :       false,
     279             :       "Set to True to enable verbose screen printing related to solution restoration");
     280             : 
     281     1410756 :   params.addParam<FileNameNoExtension>("restart_file_base",
     282             :                                        "File base name used for restart (e.g. "
     283             :                                        "<path>/<filebase> or <path>/LATEST to "
     284             :                                        "grab the latest file available)");
     285             : 
     286     1410756 :   params.addParam<std::vector<std::vector<TagName>>>(
     287             :       "extra_tag_vectors",
     288             :       {},
     289             :       "Extra vectors to add to the system that can be filled by objects which compute residuals "
     290             :       "and Jacobians (Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
     291             :       "nonlinear system the extra tag vectors should be added for");
     292             : 
     293     1410756 :   params.addParam<std::vector<std::vector<TagName>>>(
     294             :       "not_zeroed_tag_vectors",
     295             :       {},
     296             :       "Extra vector tags which the sytem will not zero when other vector tags are zeroed. "
     297             :       "The outer index is for which nonlinear system the extra tag vectors should be added for");
     298             : 
     299     1410756 :   params.addParam<std::vector<std::vector<TagName>>>(
     300             :       "extra_tag_matrices",
     301             :       {},
     302             :       "Extra matrices to add to the system that can be filled "
     303             :       "by objects which compute residuals and Jacobians "
     304             :       "(Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
     305             :       "nonlinear system the extra tag vectors should be added for");
     306             : 
     307     1410756 :   params.addParam<std::vector<TagName>>(
     308             :       "extra_tag_solutions",
     309             :       {},
     310             :       "Extra solution vectors to add to the system that can be used by "
     311             :       "objects for coupling variable values stored in them.");
     312             : 
     313     1058067 :   params.addParam<bool>("previous_nl_solution_required",
     314      705378 :                         false,
     315             :                         "True to indicate that this calculation requires a solution vector for "
     316             :                         "storing the previous nonlinear iteration.");
     317             : 
     318     1058067 :   params.addParam<std::vector<NonlinearSystemName>>(
     319     1410756 :       "nl_sys_names", std::vector<NonlinearSystemName>{"nl0"}, "The nonlinear system names");
     320             : 
     321     1410756 :   params.addParam<std::vector<LinearSystemName>>("linear_sys_names", {}, "The linear system names");
     322             : 
     323     1058067 :   params.addParam<bool>("check_uo_aux_state",
     324      705378 :                         false,
     325             :                         "True to turn on a check that no state presents during the evaluation of "
     326             :                         "user objects and aux kernels");
     327             : 
     328      352689 :   params.addPrivateParam<MooseMesh *>("mesh");
     329             : 
     330     1058067 :   params.declareControllable("solve");
     331             : 
     332     1058067 :   params.addParam<bool>(
     333             :       "allow_invalid_solution",
     334      705378 :       false,
     335             :       "Set to true to allow convergence even though the solution has been marked as 'invalid'");
     336     1058067 :   params.addParam<bool>("show_invalid_solution_console",
     337      705378 :                         true,
     338             :                         "Set to true to show the invalid solution occurance summary in console");
     339     1058067 :   params.addParam<bool>("immediately_print_invalid_solution",
     340      705378 :                         false,
     341             :                         "Whether or not to report invalid solution warnings at the time the "
     342             :                         "warning is produced instead of after the calculation");
     343             : 
     344     1058067 :   params.addParam<bool>(
     345             :       "identify_variable_groups_in_nl",
     346      705378 :       true,
     347             :       "Whether to identify variable groups in nonlinear systems. This affects dof ordering");
     348             : 
     349     1058067 :   params.addParam<bool>(
     350             :       "regard_general_exceptions_as_errors",
     351      705378 :       false,
     352             :       "If we catch an exception during residual/Jacobian evaluaton for which we don't have "
     353             :       "specific handling, immediately error instead of allowing the time step to be cut");
     354             : 
     355     1058067 :   params.addParam<bool>("use_hash_table_matrix_assembly",
     356      705378 :                         false,
     357             :                         "Whether to assemble matrices using hash tables instead of preallocating "
     358             :                         "matrix memory. This can be a good option if the sparsity pattern changes "
     359             :                         "throughout the course of the simulation.");
     360     1410756 :   params.addParam<bool>(
     361             :       "restore_original_nonzero_pattern",
     362             :       "Whether we should reset matrix memory for every Jacobian evaluation. This option is useful "
     363             :       "if the sparsity pattern is constantly changing and you are using hash table assembly or if "
     364             :       "you wish to continually restore the matrix to the originally preallocated sparsity pattern "
     365             :       "computed by relationship managers.");
     366             : 
     367     1410756 :   params.addParamNamesToGroup(
     368             :       "skip_nl_system_check kernel_coverage_check kernel_coverage_block_list "
     369             :       "boundary_restricted_node_integrity_check "
     370             :       "boundary_restricted_elem_integrity_check material_coverage_check "
     371             :       "material_coverage_block_list fv_bcs_integrity_check "
     372             :       "material_dependency_check check_uo_aux_state error_on_jacobian_nonzero_reallocation",
     373             :       "Simulation checks");
     374     1410756 :   params.addParamNamesToGroup("use_nonlinear previous_nl_solution_required nl_sys_names "
     375             :                               "ignore_zeros_in_jacobian identify_variable_groups_in_nl "
     376             :                               "use_hash_table_matrix_assembly restore_original_nonzero_pattern",
     377             :                               "Nonlinear system(s)");
     378     1410756 :   params.addParamNamesToGroup(
     379             :       "restart_file_base force_restart allow_initial_conditions_with_restart", "Restart");
     380     1410756 :   params.addParamNamesToGroup(
     381             :       "verbose_setup verbose_multiapps verbose_restore parallel_barrier_messaging", "Verbosity");
     382     1410756 :   params.addParamNamesToGroup(
     383             :       "null_space_dimension transpose_null_space_dimension near_null_space_dimension",
     384             :       "Null space removal");
     385     1410756 :   params.addParamNamesToGroup(
     386             :       "extra_tag_vectors extra_tag_matrices extra_tag_solutions not_zeroed_tag_vectors",
     387             :       "Contribution to tagged field data");
     388     1058067 :   params.addParamNamesToGroup(
     389             :       "allow_invalid_solution show_invalid_solution_console immediately_print_invalid_solution",
     390             :       "Solution validity control");
     391             : 
     392      705378 :   return params;
     393     1058067 : }
     394             : 
     395       64746 : FEProblemBase::FEProblemBase(const InputParameters & parameters)
     396             :   : SubProblem(parameters),
     397             :     Restartable(this, "FEProblemBase"),
     398      258984 :     _mesh(*getCheckedPointerParam<MooseMesh *>("mesh")),
     399      129492 :     _req(declareManagedRestartableDataWithContext<RestartableEquationSystems>(
     400             :         "equation_systems", nullptr, _mesh)),
     401       64746 :     _initialized(false),
     402      129492 :     _solve(getParam<bool>("solve")),
     403       64746 :     _transient(false),
     404      129492 :     _time(declareRestartableData<Real>("time")),
     405      129492 :     _time_old(declareRestartableData<Real>("time_old")),
     406      129492 :     _t_step(declareRecoverableData<int>("t_step")),
     407      129492 :     _dt(declareRestartableData<Real>("dt")),
     408      129492 :     _dt_old(declareRestartableData<Real>("dt_old")),
     409       64746 :     _need_to_add_default_nonlinear_convergence(false),
     410       64746 :     _need_to_add_default_multiapp_fixed_point_convergence(false),
     411       64746 :     _need_to_add_default_steady_state_convergence(false),
     412      129492 :     _linear_sys_names(getParam<std::vector<LinearSystemName>>("linear_sys_names")),
     413       64746 :     _num_linear_sys(_linear_sys_names.size()),
     414      129492 :     _linear_systems(_num_linear_sys, nullptr),
     415       64746 :     _current_linear_sys(nullptr),
     416      129492 :     _using_default_nl(!isParamSetByUser("nl_sys_names")),
     417      191684 :     _nl_sys_names(!_using_default_nl || (_using_default_nl && !_linear_sys_names.size())
     418       64746 :                       ? getParam<std::vector<NonlinearSystemName>>("nl_sys_names")
     419             :                       : std::vector<NonlinearSystemName>()),
     420       64746 :     _num_nl_sys(_nl_sys_names.size()),
     421      129492 :     _nl(_num_nl_sys, nullptr),
     422       64746 :     _current_nl_sys(nullptr),
     423      129492 :     _solver_systems(_num_nl_sys + _num_linear_sys, nullptr),
     424       64746 :     _aux(nullptr),
     425       64746 :     _coupling(Moose::COUPLING_DIAG),
     426             : #ifdef MOOSE_KOKKOS_ENABLED
     427       43167 :     _kokkos_assembly(*this),
     428             : #endif
     429       64746 :     _mesh_divisions(/*threaded=*/true),
     430       64746 :     _material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
     431       64746 :         "material_props", &_mesh, _material_prop_registry, *this)),
     432       64746 :     _bnd_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
     433       64746 :         "bnd_material_props", &_mesh, _material_prop_registry, *this)),
     434       64746 :     _neighbor_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
     435       64746 :         "neighbor_material_props", &_mesh, _material_prop_registry, *this)),
     436             : #ifdef MOOSE_KOKKOS_ENABLED
     437       43167 :     _kokkos_material_props(
     438       43167 :         declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
     439       43167 :             "kokkos_material_props", &_mesh, _material_prop_registry, *this)),
     440       43167 :     _kokkos_bnd_material_props(
     441       43167 :         declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
     442       43167 :             "kokkos_bnd_material_props", &_mesh, _material_prop_registry, *this)),
     443       43167 :     _kokkos_neighbor_material_props(
     444       43167 :         declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
     445       43167 :             "kokkos_neighbor_material_props", &_mesh, _material_prop_registry, *this)),
     446             : #endif
     447       64746 :     _reporter_data(_app),
     448             :     // TODO: delete the following line after apps have been updated to not call getUserObjects
     449       64746 :     _all_user_objects(_app.getExecuteOnEnum()),
     450       64746 :     _multi_apps(_app.getExecuteOnEnum()),
     451       64746 :     _transient_multi_apps(_app.getExecuteOnEnum()),
     452       64746 :     _transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
     453       64746 :     _to_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
     454       64746 :     _from_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
     455       64746 :     _between_multi_app_transfers(_app.getExecuteOnEnum(), /*threaded=*/false),
     456             : #ifdef LIBMESH_ENABLE_AMR
     457       64746 :     _adaptivity(*this),
     458       64746 :     _cycles_completed(0),
     459             : #endif
     460       64746 :     _displaced_mesh(nullptr),
     461       64746 :     _geometric_search_data(*this, _mesh),
     462       64746 :     _mortar_data(std::make_unique<MortarInterfaceWarehouse>(*this)),
     463       64746 :     _reinit_displaced_elem(false),
     464       64746 :     _reinit_displaced_face(false),
     465       64746 :     _reinit_displaced_neighbor(false),
     466       64746 :     _input_file_saved(false),
     467       64746 :     _has_dampers(false),
     468       64746 :     _has_constraints(false),
     469       64746 :     _snesmf_reuse_base(true),
     470       64746 :     _skip_exception_check(false),
     471       64746 :     _snesmf_reuse_base_set_by_user(false),
     472       64746 :     _has_initialized_stateful(false),
     473       64746 :     _const_jacobian(false),
     474       64746 :     _has_jacobian(false),
     475       64746 :     _needs_old_newton_iter(false),
     476      129492 :     _previous_nl_solution_required(getParam<bool>("previous_nl_solution_required")),
     477       64746 :     _has_nonlocal_coupling(false),
     478       64746 :     _calculate_jacobian_in_uo(false),
     479       64746 :     _kernel_coverage_check(
     480      129492 :         getParam<MooseEnum>("kernel_coverage_check").getEnum<CoverageCheckMode>()),
     481      129492 :     _kernel_coverage_blocks(getParam<std::vector<SubdomainName>>("kernel_coverage_block_list")),
     482       64746 :     _boundary_restricted_node_integrity_check(
     483      129492 :         getParam<bool>("boundary_restricted_node_integrity_check")),
     484       64746 :     _boundary_restricted_elem_integrity_check(
     485      129492 :         getParam<bool>("boundary_restricted_elem_integrity_check")),
     486       64746 :     _material_coverage_check(
     487      129492 :         getParam<MooseEnum>("material_coverage_check").getEnum<CoverageCheckMode>()),
     488      129492 :     _material_coverage_blocks(getParam<std::vector<SubdomainName>>("material_coverage_block_list")),
     489      129492 :     _fv_bcs_integrity_check(getParam<bool>("fv_bcs_integrity_check")),
     490      129492 :     _material_dependency_check(getParam<bool>("material_dependency_check")),
     491      129492 :     _uo_aux_state_check(getParam<bool>("check_uo_aux_state")),
     492       64746 :     _max_qps(std::numeric_limits<unsigned int>::max()),
     493       64746 :     _max_scalar_order(INVALID_ORDER),
     494       64746 :     _has_time_integrator(false),
     495       64746 :     _has_exception(false),
     496      129492 :     _parallel_barrier_messaging(getParam<bool>("parallel_barrier_messaging")),
     497      129492 :     _verbose_setup(getParam<MooseEnum>("verbose_setup")),
     498      129492 :     _verbose_multiapps(getParam<bool>("verbose_multiapps")),
     499      129492 :     _verbose_restore(getParam<bool>("verbose_restore")),
     500       64746 :     _current_execute_on_flag(EXEC_NONE),
     501       64746 :     _control_warehouse(_app.getExecuteOnEnum(), /*threaded=*/false),
     502       64746 :     _is_petsc_options_inserted(false),
     503       64746 :     _line_search(nullptr),
     504       64746 :     _using_ad_mat_props(false),
     505       64746 :     _current_ic_state(0),
     506      129492 :     _use_hash_table_matrix_assembly(getParam<bool>("use_hash_table_matrix_assembly")),
     507       64746 :     _error_on_jacobian_nonzero_reallocation(
     508      129492 :         isParamValid("error_on_jacobian_nonzero_reallocation")
     509      130098 :             ? getParam<bool>("error_on_jacobian_nonzero_reallocation")
     510       64140 :             : _app.errorOnJacobianNonzeroReallocation()),
     511      129492 :     _restore_original_nonzero_pattern(isParamValid("restore_original_nonzero_pattern")
     512      129492 :                                           ? getParam<bool>("restore_original_nonzero_pattern")
     513       64746 :                                           : _use_hash_table_matrix_assembly),
     514      129492 :     _ignore_zeros_in_jacobian(getParam<bool>("ignore_zeros_in_jacobian")),
     515       64746 :     _preserve_matrix_sparsity_pattern(true),
     516      129492 :     _force_restart(getParam<bool>("force_restart")),
     517      129492 :     _allow_ics_during_restart(getParam<bool>("allow_initial_conditions_with_restart")),
     518      129492 :     _skip_nl_system_check(getParam<bool>("skip_nl_system_check")),
     519       64746 :     _fail_next_system_convergence_check(false),
     520      129492 :     _allow_invalid_solution(getParam<bool>("allow_invalid_solution")),
     521      129492 :     _show_invalid_solution_console(getParam<bool>("show_invalid_solution_console")),
     522      129492 :     _immediately_print_invalid_solution(getParam<bool>("immediately_print_invalid_solution")),
     523       64746 :     _started_initial_setup(false),
     524       64746 :     _has_internal_edge_residual_objects(false),
     525       64746 :     _u_dot_requested(false),
     526       64746 :     _u_dotdot_requested(false),
     527       64746 :     _u_dot_old_requested(false),
     528       64746 :     _u_dotdot_old_requested(false),
     529       64746 :     _has_mortar(false),
     530       64746 :     _num_grid_steps(0),
     531       64746 :     _print_execution_on(),
     532      129492 :     _identify_variable_groups_in_nl(getParam<bool>("identify_variable_groups_in_nl")),
     533       64746 :     _regard_general_exceptions_as_errors(getParam<bool>("regard_general_exceptions_as_errors")),
     534     1230174 :     _requires_nonlocal_coupling(false)
     535             : {
     536             :   auto checkCoverageCheckConflict =
     537      129492 :       [this](const std::string & coverage_check,
     538             :              const CoverageCheckMode & coverage_check_mode,
     539             :              const std::vector<SubdomainName> & coverage_blocks) -> void
     540             :   {
     541      129492 :     if (coverage_check_mode != CoverageCheckMode::FALSE &&
     542      124734 :         coverage_check_mode != CoverageCheckMode::OFF)
     543      124713 :       if (coverage_blocks.size() > 1)
     544           0 :         if (std::find(coverage_blocks.begin(), coverage_blocks.end(), "ANY_BLOCK_ID") !=
     545           0 :             coverage_blocks.end())
     546           0 :           paramError(coverage_check,
     547             :                      "The list of blocks used for ",
     548             :                      coverage_check,
     549             :                      " cannot contain 'ANY_BLOCK_ID' along with other blocks. ");
     550      129492 :   };
     551             : 
     552       64746 :   checkCoverageCheckConflict(
     553       64746 :       "kernel_coverage_check", _kernel_coverage_check, _kernel_coverage_blocks);
     554       64746 :   checkCoverageCheckConflict(
     555       64746 :       "material_coverage_check", _material_coverage_check, _material_coverage_blocks);
     556             : 
     557             :   //  Initialize static do_derivatives member. We initialize this to true so that all the
     558             :   //  default AD things that we setup early in the simulation actually get their derivative
     559             :   //  vectors initalized. We will toggle this to false when doing residual evaluations
     560       64746 :   ADReal::do_derivatives = true;
     561             : 
     562             :   // Disable refinement/coarsening in EquationSystems::reinit because we already do this ourselves
     563       64746 :   es().disable_refine_in_reinit();
     564             : 
     565       64746 :   _solver_params.reserve(_num_nl_sys + _num_linear_sys);
     566             :   // Default constructor fine for nonlinear because it will be populated later by framework
     567             :   // executioner/solve object parameters
     568       64746 :   _solver_params.resize(_num_nl_sys);
     569      128455 :   for (const auto i : index_range(_nl_sys_names))
     570             :   {
     571       63709 :     const auto & name = _nl_sys_names[i];
     572       63709 :     _nl_sys_name_to_num[name] = i;
     573       63709 :     _solver_sys_name_to_num[name] = i;
     574       63709 :     _solver_sys_names.push_back(name);
     575             :   }
     576             : 
     577       66086 :   for (const auto i : index_range(_linear_sys_names))
     578             :   {
     579        1340 :     const auto & name = _linear_sys_names[i];
     580        1340 :     _linear_sys_name_to_num[name] = i;
     581        1340 :     _solver_sys_name_to_num[name] = i + _num_nl_sys;
     582        1340 :     _solver_sys_names.push_back(name);
     583             :     // Unlike for nonlinear these are basically dummy parameters
     584        1340 :     _solver_params.push_back(makeLinearSolverParams());
     585             :   }
     586             : 
     587       64746 :   _nonlocal_cm.resize(numSolverSystems());
     588       64746 :   _cm.resize(numSolverSystems());
     589             : 
     590       64746 :   _time = 0.0;
     591       64746 :   _time_old = 0.0;
     592       64746 :   _t_step = 0;
     593       64746 :   _dt = 0;
     594       64746 :   _dt_old = _dt;
     595             : 
     596       64746 :   unsigned int n_threads = libMesh::n_threads();
     597             : 
     598       64746 :   _real_zero.resize(n_threads, 0.);
     599       64746 :   _scalar_zero.resize(n_threads);
     600       64746 :   _zero.resize(n_threads);
     601       64746 :   _phi_zero.resize(n_threads);
     602       64746 :   _ad_zero.resize(n_threads);
     603       64746 :   _grad_zero.resize(n_threads);
     604       64746 :   _ad_grad_zero.resize(n_threads);
     605       64746 :   _grad_phi_zero.resize(n_threads);
     606       64746 :   _second_zero.resize(n_threads);
     607       64746 :   _ad_second_zero.resize(n_threads);
     608       64746 :   _second_phi_zero.resize(n_threads);
     609       64746 :   _point_zero.resize(n_threads);
     610       64746 :   _vector_zero.resize(n_threads);
     611       64746 :   _vector_curl_zero.resize(n_threads);
     612       64746 :   _uo_jacobian_moose_vars.resize(n_threads);
     613             : 
     614       64746 :   _has_active_material_properties.resize(n_threads, 0);
     615             : 
     616       64746 :   _block_mat_side_cache.resize(n_threads);
     617       64746 :   _bnd_mat_side_cache.resize(n_threads);
     618       64746 :   _interface_mat_side_cache.resize(n_threads);
     619             : 
     620      129492 :   es().parameters.set<FEProblemBase *>("_fe_problem_base") = this;
     621             : 
     622      194238 :   if (isParamValid("restart_file_base"))
     623             :   {
     624        1018 :     std::string restart_file_base = getParam<FileNameNoExtension>("restart_file_base");
     625             : 
     626             :     // This check reverts to old behavior of providing "restart_file_base=" to mean
     627             :     // don't restart... BISON currently relies on this. It could probably be removed.
     628             :     // The new MooseUtils::convertLatestCheckpoint will error out if a checkpoint file
     629             :     // is not found, which I think makes sense. Which means, without this, if you
     630             :     // set "restart_file_base=", you'll get a "No checkpoint file found" error
     631         509 :     if (restart_file_base.size())
     632             :     {
     633         509 :       restart_file_base = MooseUtils::convertLatestCheckpoint(restart_file_base);
     634         509 :       setRestartFile(restart_file_base);
     635             :     }
     636         509 :   }
     637             : 
     638             :   // // Generally speaking, the mesh is prepared for use, and consequently remote elements are deleted
     639             :   // // well before our Problem(s) are constructed. Historically, in MooseMesh we have a bunch of
     640             :   // // needs_prepare type flags that make it so we never call prepare_for_use (and consequently
     641             :   // // delete_remote_elements) again. So the below line, historically, has had no impact. HOWEVER:
     642             :   // // I've added some code in SetupMeshCompleteAction for deleting remote elements post
     643             :   // // EquationSystems::init. If I execute that code without default ghosting, then I get > 40 MOOSE
     644             :   // // test failures, so we clearly have some simulations that are not yet covered properly by
     645             :   // // relationship managers. Until that is resolved, I am going to retain default geometric ghosting
     646             :   // if (!_default_ghosting)
     647             :   //   _mesh.getMesh().remove_ghosting_functor(_mesh.getMesh().default_ghosting());
     648             : 
     649             : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
     650             :   // Main app should hold the default database to handle system petsc options
     651       64746 :   if (!_app.isUltimateMaster())
     652       12471 :     LibmeshPetscCall(PetscOptionsCreate(&_petsc_option_data_base));
     653             : #endif
     654             : 
     655       64746 :   if (!_solve)
     656             :   {
     657             :     // If we are not solving, we do not care about seeing unused petsc options
     658       47421 :     Moose::PetscSupport::setSinglePetscOption("-options_left", "0");
     659             :     // We don't want petscSetOptions being called in solve and clearing the option that was just set
     660       15807 :     _is_petsc_options_inserted = true;
     661             :   }
     662       64746 : }
     663             : 
     664             : const MooseMesh &
     665      322586 : FEProblemBase::mesh(bool use_displaced) const
     666             : {
     667      322586 :   if (use_displaced && !_displaced_problem)
     668           0 :     mooseWarning("Displaced mesh was requested but the displaced problem does not exist. "
     669             :                  "Regular mesh will be returned");
     670      322586 :   return ((use_displaced && _displaced_problem) ? _displaced_problem->mesh() : mesh());
     671             : }
     672             : 
     673             : void
     674       64746 : FEProblemBase::createTagVectors()
     675             : {
     676             :   // add vectors and their tags to system
     677      129492 :   auto & vectors = getParam<std::vector<std::vector<TagName>>>("extra_tag_vectors");
     678       65471 :   for (const auto sys_num : index_range(vectors))
     679        1694 :     for (auto & vector : vectors[sys_num])
     680             :     {
     681         969 :       auto tag = addVectorTag(vector);
     682         969 :       _solver_systems[sys_num]->addVector(tag, false, libMesh::GHOSTED);
     683             :     }
     684             : 
     685      129492 :   auto & not_zeroed_vectors = getParam<std::vector<std::vector<TagName>>>("not_zeroed_tag_vectors");
     686       64758 :   for (const auto sys_num : index_range(not_zeroed_vectors))
     687          24 :     for (auto & vector : not_zeroed_vectors[sys_num])
     688             :     {
     689          12 :       auto tag = addVectorTag(vector);
     690          12 :       _solver_systems[sys_num]->addVector(tag, false, GHOSTED);
     691          12 :       addNotZeroedVectorTag(tag);
     692             :     }
     693       64746 : }
     694             : 
     695             : void
     696       63868 : FEProblemBase::createTagMatrices(CreateTaggedMatrixKey)
     697             : {
     698      127736 :   auto & matrices = getParam<std::vector<std::vector<TagName>>>("extra_tag_matrices");
     699       64116 :   for (const auto sys_num : index_range(matrices))
     700         692 :     for (auto & matrix : matrices[sys_num])
     701             :     {
     702         444 :       auto tag = addMatrixTag(matrix);
     703         444 :       _solver_systems[sys_num]->addMatrix(tag);
     704             :     }
     705             : 
     706      128011 :   for (auto & sys : _solver_systems)
     707       64143 :     sys->sizeVariableMatrixData();
     708       63868 :   _aux->sizeVariableMatrixData();
     709       63868 : }
     710             : 
     711             : void
     712       64746 : FEProblemBase::createTagSolutions()
     713             : {
     714      194269 :   for (auto & vector : getParam<std::vector<TagName>>("extra_tag_solutions"))
     715             :   {
     716          31 :     auto tag = addVectorTag(vector, Moose::VECTOR_TAG_SOLUTION);
     717          62 :     for (auto & sys : _solver_systems)
     718          31 :       sys->addVector(tag, false, libMesh::GHOSTED);
     719          31 :     _aux->addVector(tag, false, libMesh::GHOSTED);
     720             :   }
     721             : 
     722       64746 :   if (_previous_nl_solution_required)
     723             :   {
     724             :     // We'll populate the zeroth state of the nonlinear iterations with the current solution for
     725             :     // ease of use in doing things like copying solutions backwards. We're just storing pointers in
     726             :     // the solution states containers so populating the zeroth state does not cost us the memory of
     727             :     // a new vector
     728          94 :     needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
     729             :   }
     730             : 
     731       64746 :   auto tag = addVectorTag(Moose::SOLUTION_TAG, Moose::VECTOR_TAG_SOLUTION);
     732      129795 :   for (auto & sys : _solver_systems)
     733       65049 :     sys->associateVectorToTag(*sys->system().current_local_solution.get(), tag);
     734       64746 :   _aux->associateVectorToTag(*_aux->system().current_local_solution.get(), tag);
     735       64746 : }
     736             : 
     737             : void
     738         150 : FEProblemBase::needSolutionState(unsigned int state, Moose::SolutionIterationType iteration_type)
     739             : {
     740         300 :   for (auto & sys : _solver_systems)
     741         150 :     sys->needSolutionState(state, iteration_type);
     742         150 :   _aux->needSolutionState(state, iteration_type);
     743         150 : }
     744             : 
     745             : void
     746       64746 : FEProblemBase::newAssemblyArray(std::vector<std::shared_ptr<SolverSystem>> & solver_systems)
     747             : {
     748       64746 :   unsigned int n_threads = libMesh::n_threads();
     749             : 
     750       64746 :   _assembly.resize(n_threads);
     751      135821 :   for (const auto i : make_range(n_threads))
     752             :   {
     753       71075 :     _assembly[i].resize(solver_systems.size());
     754      142477 :     for (const auto j : index_range(solver_systems))
     755       71402 :       _assembly[i][j] = std::make_unique<Assembly>(*solver_systems[j], i);
     756             :   }
     757       64746 : }
     758             : 
     759             : void
     760       62774 : FEProblemBase::initNullSpaceVectors(const InputParameters & parameters,
     761             :                                     std::vector<std::shared_ptr<NonlinearSystemBase>> & nls)
     762             : {
     763      313870 :   TIME_SECTION("initNullSpaceVectors", 5, "Initializing Null Space Vectors");
     764             : 
     765       62774 :   unsigned int dimNullSpace = parameters.get<unsigned int>("null_space_dimension");
     766             :   unsigned int dimTransposeNullSpace =
     767       62774 :       parameters.get<unsigned int>("transpose_null_space_dimension");
     768       62774 :   unsigned int dimNearNullSpace = parameters.get<unsigned int>("near_null_space_dimension");
     769       62800 :   for (unsigned int i = 0; i < dimNullSpace; ++i)
     770             :   {
     771          26 :     std::ostringstream oss;
     772          26 :     oss << "_" << i;
     773             :     // do not project, since this will be recomputed, but make it ghosted, since the near nullspace
     774             :     // builder might march over all nodes
     775          52 :     for (auto & nl : nls)
     776          26 :       nl->addVector("NullSpace" + oss.str(), false, libMesh::GHOSTED);
     777          26 :   }
     778      125548 :   _subspace_dim["NullSpace"] = dimNullSpace;
     779       62787 :   for (unsigned int i = 0; i < dimTransposeNullSpace; ++i)
     780             :   {
     781          13 :     std::ostringstream oss;
     782          13 :     oss << "_" << i;
     783             :     // do not project, since this will be recomputed, but make it ghosted, since the near nullspace
     784             :     // builder might march over all nodes
     785          26 :     for (auto & nl : nls)
     786          13 :       nl->addVector("TransposeNullSpace" + oss.str(), false, libMesh::GHOSTED);
     787          13 :   }
     788      125548 :   _subspace_dim["TransposeNullSpace"] = dimTransposeNullSpace;
     789       62774 :   for (unsigned int i = 0; i < dimNearNullSpace; ++i)
     790             :   {
     791           0 :     std::ostringstream oss;
     792           0 :     oss << "_" << i;
     793             :     // do not project, since this will be recomputed, but make it ghosted, since the near-nullspace
     794             :     // builder might march over all semilocal nodes
     795           0 :     for (auto & nl : nls)
     796           0 :       nl->addVector("NearNullSpace" + oss.str(), false, libMesh::GHOSTED);
     797           0 :   }
     798      125548 :   _subspace_dim["NearNullSpace"] = dimNearNullSpace;
     799       62774 : }
     800             : 
     801      180858 : FEProblemBase::~FEProblemBase()
     802             : {
     803             :   // Flush the Console stream, the underlying call to Console::mooseConsole
     804             :   // relies on a call to Output::checkInterval that has references to
     805             :   // _time, etc. If it is not flushed here memory problems arise if you have
     806             :   // an unflushed stream and start destructing things.
     807       60286 :   _console << std::flush;
     808             : 
     809       60286 :   unsigned int n_threads = libMesh::n_threads();
     810      125774 :   for (unsigned int i = 0; i < n_threads; i++)
     811             :   {
     812       65488 :     _zero[i].release();
     813       65488 :     _phi_zero[i].release();
     814       65488 :     _scalar_zero[i].release();
     815       65488 :     _grad_zero[i].release();
     816       65488 :     _grad_phi_zero[i].release();
     817       65488 :     _second_zero[i].release();
     818       65488 :     _second_phi_zero[i].release();
     819       65488 :     _vector_zero[i].release();
     820       65488 :     _vector_curl_zero[i].release();
     821       65488 :     _ad_zero[i].release();
     822       65488 :     _ad_grad_zero[i].release();
     823       65488 :     _ad_second_zero[i].release();
     824             :   }
     825             : 
     826             : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
     827       60286 :   if (!_app.isUltimateMaster())
     828             :   {
     829       11081 :     auto ierr = PetscOptionsDestroy(&_petsc_option_data_base);
     830             :     // Don't throw on destruction
     831       11081 :     CHKERRABORT(this->comm().get(), ierr);
     832             :   }
     833             : #endif
     834       60286 : }
     835             : 
     836             : void
     837           0 : FEProblemBase::setCoordSystem(const std::vector<SubdomainName> & blocks,
     838             :                               const MultiMooseEnum & coord_sys)
     839             : {
     840           0 :   TIME_SECTION("setCoordSystem", 5, "Setting Coordinate System");
     841           0 :   _mesh.setCoordSystem(blocks, coord_sys);
     842           0 : }
     843             : 
     844             : void
     845           0 : FEProblemBase::setAxisymmetricCoordAxis(const MooseEnum & rz_coord_axis)
     846             : {
     847           0 :   _mesh.setAxisymmetricCoordAxis(rz_coord_axis);
     848           0 : }
     849             : 
     850             : const ConstElemRange &
     851        1457 : FEProblemBase::getEvaluableElementRange()
     852             : {
     853        1457 :   if (!_evaluable_local_elem_range)
     854             :   {
     855         688 :     std::vector<const DofMap *> dof_maps(es().n_systems());
     856        2064 :     for (const auto i : make_range(es().n_systems()))
     857             :     {
     858        1376 :       const auto & sys = es().get_system(i);
     859        1376 :       dof_maps[i] = &sys.get_dof_map();
     860             :     }
     861             :     _evaluable_local_elem_range =
     862        1376 :         std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
     863        2064 :                                          _mesh.getMesh().multi_evaluable_elements_end(dof_maps));
     864         688 :   }
     865        1457 :   return *_evaluable_local_elem_range;
     866             : }
     867             : 
     868             : const ConstElemRange &
     869         234 : FEProblemBase::getNonlinearEvaluableElementRange()
     870             : {
     871         234 :   if (!_nl_evaluable_local_elem_range)
     872             :   {
     873         234 :     std::vector<const DofMap *> dof_maps(_nl.size());
     874         468 :     for (const auto i : index_range(dof_maps))
     875         234 :       dof_maps[i] = &_nl[i]->dofMap();
     876             :     _nl_evaluable_local_elem_range =
     877         468 :         std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
     878         702 :                                          _mesh.getMesh().multi_evaluable_elements_end(dof_maps));
     879         234 :   }
     880             : 
     881         234 :   return *_nl_evaluable_local_elem_range;
     882             : }
     883             : 
     884             : void
     885       62116 : FEProblemBase::initialSetup()
     886             : {
     887      310580 :   TIME_SECTION("initialSetup", 2, "Performing Initial Setup");
     888             : 
     889       62116 :   SubProblem::initialSetup();
     890             : 
     891       62116 :   if (_app.isRecovering() + _app.isRestarting() + bool(_app.getExReaderForRestart()) > 1)
     892           0 :     mooseError("Checkpoint recovery and restart and exodus restart are all mutually exclusive.");
     893             : 
     894       62116 :   if (_skip_exception_check)
     895          10 :     mooseWarning("MOOSE may fail to catch an exception when the \"skip_exception_check\" parameter "
     896             :                  "is used. If you receive a terse MPI error during execution, remove this "
     897             :                  "parameter and rerun your simulation");
     898             : 
     899             :   // set state flag indicating that we are in or beyond initialSetup.
     900             :   // This can be used to throw errors in methods that _must_ be called at construction time.
     901       62116 :   _started_initial_setup = true;
     902       62116 :   setCurrentExecuteOnFlag(EXEC_INITIAL);
     903             : 
     904             :   // Setup the solution states (current, old, etc) in each system based on
     905             :   // its default and the states requested of each of its variables
     906      124507 :   for (const auto i : index_range(_solver_systems))
     907             :   {
     908       62391 :     _solver_systems[i]->initSolutionState();
     909       62391 :     if (getDisplacedProblem())
     910        2234 :       getDisplacedProblem()->solverSys(i).initSolutionState();
     911             :   }
     912       62116 :   _aux->initSolutionState();
     913       62116 :   if (getDisplacedProblem())
     914        2234 :     getDisplacedProblem()->auxSys().initSolutionState();
     915             : 
     916             :   // always execute to get the max number of DoF per element and node needed to initialize phi_zero
     917             :   // variables
     918       62116 :   dof_id_type global_max_var_n_dofs_per_elem = 0;
     919      124507 :   for (const auto i : index_range(_solver_systems))
     920             :   {
     921       62391 :     auto & sys = *_solver_systems[i];
     922             :     dof_id_type max_var_n_dofs_per_elem;
     923             :     dof_id_type max_var_n_dofs_per_node;
     924             :     {
     925      311955 :       TIME_SECTION("computingMaxDofs", 3, "Computing Max Dofs Per Element");
     926             : 
     927       62391 :       MaxVarNDofsPerElem mvndpe(*this, sys);
     928       62391 :       Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), mvndpe);
     929       62391 :       max_var_n_dofs_per_elem = mvndpe.max();
     930       62391 :       _communicator.max(max_var_n_dofs_per_elem);
     931             : 
     932       62391 :       MaxVarNDofsPerNode mvndpn(*this, sys);
     933       62391 :       Threads::parallel_reduce(*_mesh.getLocalNodeRange(), mvndpn);
     934       62391 :       max_var_n_dofs_per_node = mvndpn.max();
     935       62391 :       _communicator.max(max_var_n_dofs_per_node);
     936       62391 :       global_max_var_n_dofs_per_elem =
     937       62391 :           std::max(global_max_var_n_dofs_per_elem, max_var_n_dofs_per_elem);
     938       62391 :     }
     939             : 
     940             :     {
     941      311955 :       TIME_SECTION("assignMaxDofs", 5, "Assigning Maximum Dofs Per Elem");
     942             : 
     943       62391 :       sys.assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
     944       62391 :       auto displaced_problem = getDisplacedProblem();
     945       62391 :       if (displaced_problem)
     946        2234 :         displaced_problem->solverSys(i).assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
     947             : 
     948       62391 :       sys.assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
     949       62391 :       if (displaced_problem)
     950        2234 :         displaced_problem->solverSys(i).assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
     951       62391 :     }
     952             :   }
     953             : 
     954             :   {
     955      310580 :     TIME_SECTION("resizingVarValues", 5, "Resizing Variable Values");
     956             : 
     957      129961 :     for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
     958             :     {
     959      135690 :       _phi_zero[tid].resize(global_max_var_n_dofs_per_elem, std::vector<Real>(getMaxQps(), 0.));
     960      135690 :       _grad_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
     961      135690 :                                  std::vector<RealGradient>(getMaxQps(), RealGradient(0.)));
     962      135690 :       _second_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
     963      135690 :                                    std::vector<RealTensor>(getMaxQps(), RealTensor(0.)));
     964             :     }
     965       62116 :   }
     966             : 
     967             :   // Set up stateful material property redistribution, if we suspect
     968             :   // it may be necessary later.
     969       62116 :   addAnyRedistributers();
     970             : 
     971       62116 :   if (_app.isRestarting() || _app.isRecovering() || _force_restart)
     972             :   {
     973             :     // Only load all of the vectors if we're recovering
     974        4593 :     _req.set().setLoadAllVectors(_app.isRecovering());
     975             : 
     976             :     // This forces stateful material property loading to be an exact one-to-one match
     977        4593 :     if (_app.isRecovering())
     978             :     {
     979       16056 :       for (auto props : {&_material_props, &_bnd_material_props, &_neighbor_material_props})
     980       12042 :         props->setRecovering();
     981             : 
     982             : #ifdef MOOSE_KOKKOS_ENABLED
     983       15836 :       for (auto props :
     984       19795 :            {&_kokkos_material_props, &_kokkos_bnd_material_props, &_kokkos_neighbor_material_props})
     985       11877 :         props->setRecovering();
     986             : #endif
     987             :     }
     988             : 
     989       22965 :     TIME_SECTION("restore", 3, "Restoring from backup");
     990             : 
     991             :     // We could have a cached backup when this app is a sub-app and has been given a Backup
     992        4593 :     if (!_app.hasInitialBackup())
     993        3596 :       _app.restore(_app.restartFolderBase(_app.getRestartRecoverFileBase()), _app.isRestarting());
     994             :     else
     995         997 :       _app.restoreFromInitialBackup(_app.isRestarting());
     996             : 
     997             :     /**
     998             :      * If this is a restart run, the user may want to override the start time, which we already set
     999             :      * in the constructor. "_time" however will have been "restored" from the restart file. We need
    1000             :      * to honor the original request of the developer now that the restore has been completed.
    1001             :      */
    1002        4546 :     if (_app.isRestarting())
    1003             :     {
    1004         532 :       if (_app.hasStartTime())
    1005         178 :         _time = _time_old = _app.getStartTime();
    1006             :       else
    1007         354 :         _time_old = _time;
    1008             :     }
    1009        4546 :   }
    1010             :   else
    1011             :   {
    1012       57523 :     libMesh::ExodusII_IO * reader = _app.getExReaderForRestart();
    1013             : 
    1014       57523 :     if (reader)
    1015             :     {
    1016        1445 :       TIME_SECTION("copyingFromExodus", 3, "Copying Variables From Exodus");
    1017             : 
    1018         586 :       for (auto & sys : _solver_systems)
    1019         301 :         sys->copyVars(*reader);
    1020         285 :       _aux->copyVars(*reader);
    1021         285 :     }
    1022             :     else
    1023             :     {
    1024       57234 :       if (_solver_systems[0]->hasVarCopy() || _aux->hasVarCopy())
    1025           0 :         mooseError("Need Exodus reader to restart variables but the reader is not available\n"
    1026             :                    "Use either FileMesh with an Exodus mesh file or FileMeshGenerator with an "
    1027             :                    "Exodus mesh file and with use_for_exodus_restart equal to true");
    1028             :     }
    1029             :   }
    1030             : 
    1031             :   // Perform output related setups
    1032       62065 :   _app.getOutputWarehouse().initialSetup();
    1033             : 
    1034             :   // Flush all output to _console that occur during construction and initialization of objects
    1035       61997 :   _app.getOutputWarehouse().mooseConsole();
    1036             : 
    1037             :   // Build Refinement and Coarsening maps for stateful material projections if necessary
    1038       64417 :   if ((_adaptivity.isOn() || _num_grid_steps) &&
    1039        2420 :       (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    1040        2349 :        _neighbor_material_props.hasStatefulProperties()))
    1041             :   {
    1042          71 :     if (_has_internal_edge_residual_objects)
    1043           8 :       mooseError("Stateful neighbor material properties do not work with mesh adaptivity");
    1044             : 
    1045          63 :     _mesh.buildRefinementAndCoarseningMaps(_assembly[0][0].get());
    1046             :   }
    1047             : 
    1048       61989 :   if (!_app.isRecovering())
    1049             :   {
    1050             :     /**
    1051             :      * If we are not recovering but we are doing restart (_app.getExodusFileRestart() == true) with
    1052             :      * additional uniform refinements. We have to delay the refinement until this point
    1053             :      * in time so that the equation systems are initialized and projections can be performed.
    1054             :      */
    1055       57975 :     if (_mesh.uniformRefineLevel() > 0 && _app.getExodusFileRestart())
    1056             :     {
    1057          11 :       if (!_app.isUltimateMaster())
    1058           0 :         mooseError(
    1059             :             "Doing extra refinements when restarting is NOT supported for sub-apps of a MultiApp");
    1060             : 
    1061          11 :       adaptivity().uniformRefineWithProjection();
    1062             :     }
    1063             :   }
    1064             : 
    1065       61989 :   unsigned int n_threads = libMesh::n_threads();
    1066             : 
    1067             :   // Convergence initial setup
    1068             :   {
    1069      309945 :     TIME_SECTION("convergenceInitialSetup", 5, "Initializing Convergence objects");
    1070             : 
    1071      129648 :     for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1072       67679 :       _convergences.initialSetup(tid);
    1073       61969 :   }
    1074             : 
    1075             :   // UserObject initialSetup
    1076       61969 :   std::set<std::string> depend_objects_ic = _ics.getDependObjects();
    1077       61969 :   std::set<std::string> depend_objects_aux = _aux->getDependObjects();
    1078             : 
    1079             :   // This replaces all prior updateDependObjects calls on the old user object warehouses.
    1080       61969 :   TheWarehouse::Query uo_query = theWarehouse().query().condition<AttribSystem>("UserObject");
    1081       61969 :   std::vector<UserObject *> userobjs;
    1082       61969 :   uo_query.queryInto(userobjs);
    1083       61969 :   groupUserObjects(
    1084       61969 :       theWarehouse(), getAuxiliarySystem(), _app.getExecuteOnEnum(), userobjs, depend_objects_ic);
    1085             : 
    1086       61969 :   std::map<int, std::vector<UserObject *>> group_userobjs;
    1087      143805 :   for (auto obj : userobjs)
    1088      245508 :     group_userobjs[obj->getParam<int>("execution_order_group")].push_back(obj);
    1089             : 
    1090       94506 :   for (auto & [group, objs] : group_userobjs)
    1091      114333 :     for (auto obj : objs)
    1092       81796 :       obj->initialSetup();
    1093             : 
    1094             :   // check if jacobian calculation is done in userobject
    1095      129403 :   for (THREAD_ID tid = 0; tid < n_threads; ++tid)
    1096       67534 :     checkUserObjectJacobianRequirement(tid);
    1097             : 
    1098             :   // Check whether nonlocal couling is required or not
    1099       61869 :   checkNonlocalCoupling();
    1100       61869 :   if (_requires_nonlocal_coupling)
    1101          81 :     setVariableAllDoFMap(_uo_jacobian_moose_vars[0]);
    1102             : 
    1103             :   {
    1104      309345 :     TIME_SECTION("initializingFunctions", 5, "Initializing Functions");
    1105             : 
    1106             :     // Call the initialSetup methods for functions
    1107      129363 :     for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1108             :     {
    1109       67526 :       reinitScalars(tid); // initialize scalars so they are properly sized for use as input into
    1110             :                           // ParsedFunctions
    1111       67526 :       _functions.initialSetup(tid);
    1112             :     }
    1113       61837 :   }
    1114             : 
    1115             :   {
    1116      309185 :     TIME_SECTION("initializingRandomObjects", 5, "Initializing Random Objects");
    1117             : 
    1118             :     // Random interface objects
    1119       62230 :     for (const auto & it : _random_data_objects)
    1120         393 :       it.second->updateSeeds(EXEC_INITIAL);
    1121       61837 :   }
    1122             : 
    1123       61837 :   if (!_app.isRecovering())
    1124             :   {
    1125       57823 :     computeUserObjects(EXEC_INITIAL, Moose::PRE_IC);
    1126             : 
    1127             :     {
    1128      289115 :       TIME_SECTION("ICinitialSetup", 5, "Setting Up Initial Conditions");
    1129             : 
    1130      121250 :       for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1131       63435 :         _ics.initialSetup(tid);
    1132             : 
    1133       57815 :       _scalar_ics.initialSetup();
    1134       57815 :     }
    1135             : 
    1136       57815 :     projectSolution();
    1137             :   }
    1138             : 
    1139             :   // Materials
    1140       61821 :   if (_all_materials.hasActiveObjects(0))
    1141             :   {
    1142       44605 :     TIME_SECTION("materialInitialSetup", 3, "Setting Up Materials");
    1143             : 
    1144       18488 :     for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1145             :     {
    1146             :       // Sort the Material objects, these will be actually computed by MOOSE in reinit methods.
    1147        9591 :       _materials.sort(tid);
    1148        9587 :       _interface_materials.sort(tid);
    1149             : 
    1150             :       // Call initialSetup on all material objects
    1151        9587 :       _all_materials.initialSetup(tid);
    1152             : 
    1153             :       // Discrete materials may insert additional dependencies on materials during the initial
    1154             :       // setup. Therefore we resolve the dependencies once more, now with the additional
    1155             :       // dependencies due to discrete materials.
    1156        9567 :       if (_discrete_materials.hasActiveObjects())
    1157             :       {
    1158          61 :         _materials.sort(tid);
    1159          61 :         _interface_materials.sort(tid);
    1160             :       }
    1161             :     }
    1162             : 
    1163             : #ifdef MOOSE_KOKKOS_ENABLED
    1164        5986 :     _kokkos_materials.sort(0, true);
    1165             : #endif
    1166             : 
    1167             :     {
    1168       44475 :       TIME_SECTION("computingInitialStatefulProps", 3, "Computing Initial Material Values");
    1169             : 
    1170        8895 :       initElementStatefulProps(*_mesh.getActiveLocalElementRange(), true);
    1171             : 
    1172       17028 :       if (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    1173        8133 :           _neighbor_material_props.hasStatefulProperties())
    1174         762 :         _has_initialized_stateful = true;
    1175             : #ifdef MOOSE_KOKKOS_ENABLED
    1176        5984 :       if (_kokkos_material_props.hasStatefulProperties() ||
    1177       11816 :           _kokkos_bnd_material_props.hasStatefulProperties() ||
    1178        5832 :           _kokkos_neighbor_material_props.hasStatefulProperties())
    1179         152 :         _has_initialized_stateful = true;
    1180             : #endif
    1181        8895 :     }
    1182        8895 :   }
    1183             : 
    1184             :   // setRestartInPlace() is set because the property maps have now been setup and we can
    1185             :   // dataLoad() them directly in place
    1186             :   // setRecovering() is set because from now on we require a one-to-one mapping of
    1187             :   // stateful properties because we shouldn't be declaring any more
    1188      247180 :   for (auto props : {&_material_props, &_bnd_material_props, &_neighbor_material_props})
    1189             :   {
    1190      185385 :     props->setRestartInPlace();
    1191      185385 :     props->setRecovering();
    1192             :   }
    1193             : 
    1194      129236 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1195             :   {
    1196       67441 :     _internal_side_indicators.initialSetup(tid);
    1197       67441 :     _indicators.initialSetup(tid);
    1198       67441 :     _markers.sort(tid);
    1199       67441 :     _markers.initialSetup(tid);
    1200             :   }
    1201             : 
    1202             : #ifdef LIBMESH_ENABLE_AMR
    1203             : 
    1204       61795 :   if (!_app.isRecovering())
    1205             :   {
    1206       57781 :     unsigned int n = adaptivity().getInitialSteps();
    1207       57781 :     if (n && !_app.isUltimateMaster() && _app.isRestarting())
    1208           0 :       mooseError("Cannot perform initial adaptivity during restart on sub-apps of a MultiApp!");
    1209             : 
    1210       57781 :     initialAdaptMesh();
    1211             :   }
    1212             : 
    1213             : #endif // LIBMESH_ENABLE_AMR
    1214             : 
    1215       61791 :   if (!_app.isRecovering() && !_app.isRestarting())
    1216             :   {
    1217             :     // During initial setup the solution is copied to the older solution states (old, older, etc)
    1218       57245 :     copySolutionsBackwards();
    1219             : 
    1220             :     // Check if there are old state initial conditions
    1221       57245 :     auto ics = _ics.getActiveObjects();
    1222       57245 :     auto fv_ics = _fv_ics.getActiveObjects();
    1223       57245 :     auto scalar_ics = _scalar_ics.getActiveObjects();
    1224       57245 :     unsigned short ic_state_max = 0;
    1225             : 
    1226      171735 :     auto findMax = [&ic_state_max](const auto & obj_list)
    1227             :     {
    1228      202321 :       for (auto ic : obj_list.getActiveObjects())
    1229       30586 :         ic_state_max = std::max(ic_state_max, ic->getState());
    1230      228980 :     };
    1231       57245 :     findMax(_ics);
    1232       57245 :     findMax(_fv_ics);
    1233       57245 :     findMax(_scalar_ics);
    1234             : 
    1235             :     // if there are old state ICs, compute them and write to old states accordingly
    1236       57245 :     if (ic_state_max > 0)
    1237             :     {
    1238             :       // state 0 copy (we'll overwrite current state when evaluating ICs and need to restore it once
    1239             :       // we're done with the old/older state ICs)
    1240           0 :       std::vector<std::unique_ptr<NumericVector<Real>>> state0_sys_buffers(_solver_systems.size());
    1241           0 :       std::unique_ptr<NumericVector<Real>> state0_aux_buffer;
    1242             : 
    1243             :       // save state 0
    1244           0 :       for (const auto i : index_range(_solver_systems))
    1245           0 :         state0_sys_buffers[i] = _solver_systems[i]->solutionState(0).clone();
    1246             : 
    1247           0 :       state0_aux_buffer = _aux->solutionState(0).clone();
    1248             : 
    1249             :       // compute old state ICs
    1250           0 :       for (_current_ic_state = 1; _current_ic_state <= ic_state_max; _current_ic_state++)
    1251             :       {
    1252           0 :         projectSolution();
    1253             : 
    1254           0 :         for (auto & sys : _solver_systems)
    1255           0 :           sys->solutionState(_current_ic_state) = sys->solutionState(0);
    1256             : 
    1257           0 :         _aux->solutionState(_current_ic_state) = _aux->solutionState(0);
    1258             :       }
    1259           0 :       _current_ic_state = 0;
    1260             : 
    1261             :       // recover state 0
    1262           0 :       for (const auto i : index_range(_solver_systems))
    1263             :       {
    1264           0 :         _solver_systems[i]->solutionState(0) = *state0_sys_buffers[i];
    1265           0 :         _solver_systems[i]->solutionState(0).close();
    1266           0 :         _solver_systems[i]->update();
    1267             :       }
    1268           0 :       _aux->solutionState(0) = *state0_aux_buffer;
    1269           0 :       _aux->solutionState(0).close();
    1270           0 :       _aux->update();
    1271           0 :     }
    1272       57245 :   }
    1273             : 
    1274       61791 :   if (!_app.isRecovering())
    1275             :   {
    1276       57777 :     if (haveXFEM())
    1277           0 :       updateMeshXFEM();
    1278             :   }
    1279             : 
    1280             :   // Call initialSetup on the solver systems
    1281      123857 :   for (auto & sys : _solver_systems)
    1282       62066 :     sys->initialSetup();
    1283             : 
    1284             :   // Auxilary variable initialSetup calls
    1285       61791 :   _aux->initialSetup();
    1286             : 
    1287       61787 :   if (_displaced_problem)
    1288             :     // initialSetup for displaced systems
    1289        2234 :     _displaced_problem->initialSetup();
    1290             : 
    1291      123849 :   for (auto & sys : _solver_systems)
    1292       62062 :     sys->setSolution(*(sys->system().current_local_solution.get()));
    1293             : 
    1294             :   // Update the nearest node searches (has to be called after the problem is all set up)
    1295             :   // We do this here because this sets up the Element's DoFs to ghost
    1296       61787 :   updateGeomSearch(GeometricSearchData::NEAREST_NODE);
    1297             : 
    1298       61787 :   _mesh.updateActiveSemiLocalNodeRange(_ghosted_elems);
    1299       61787 :   if (_displaced_mesh)
    1300        2234 :     _displaced_mesh->updateActiveSemiLocalNodeRange(_ghosted_elems);
    1301             : 
    1302             :   // We need to move the mesh in order to build a map between mortar secondary and primary
    1303             :   // interfaces. This map will then be used by the AgumentSparsityOnInterface ghosting functor to
    1304             :   // know which dofs we need ghosted when we call EquationSystems::reinit
    1305       61787 :   if (_displaced_problem && _mortar_data->hasDisplacedObjects())
    1306             :   {
    1307         124 :     _displaced_problem->updateMesh();
    1308             :     // if displacements were applied to the mesh, the mortar mesh should be updated too
    1309         124 :     updateMortarMesh();
    1310             :   }
    1311             : 
    1312             :   // Possibly reinit one more time to get ghosting correct
    1313       61787 :   reinitBecauseOfGhostingOrNewGeomObjects();
    1314             : 
    1315       61787 :   if (_displaced_mesh)
    1316        2234 :     _displaced_problem->updateMesh();
    1317             : 
    1318       61787 :   updateGeomSearch(); // Call all of the rest of the geometric searches
    1319             : 
    1320      123845 :   for (auto & sys : _solver_systems)
    1321             :   {
    1322       62062 :     const auto & tis = sys->getTimeIntegrators();
    1323             : 
    1324             :     {
    1325      310310 :       TIME_SECTION("timeIntegratorInitialSetup", 5, "Initializing Time Integrator");
    1326       93200 :       for (auto & ti : tis)
    1327       31142 :         ti->initialSetup();
    1328       62058 :     }
    1329             :   }
    1330             : 
    1331             :   // HUGE NOTE: MultiApp initialSetup() MUST... I repeat MUST be _after_ main-app restartable data
    1332             :   // has been restored
    1333             : 
    1334             :   // Call initialSetup on the MultiApps
    1335       61783 :   if (_multi_apps.hasObjects())
    1336             :   {
    1337       32955 :     TIME_SECTION("initialSetupMultiApps", 2, "Initializing MultiApps", false);
    1338        6591 :     _multi_apps.initialSetup();
    1339        6583 :   }
    1340             : 
    1341             :   // Call initialSetup on the transfers
    1342             :   {
    1343      308875 :     TIME_SECTION("initialSetupTransfers", 2, "Initializing Transfers");
    1344             : 
    1345       61775 :     _transfers.initialSetup();
    1346             : 
    1347             :     // Call initialSetup on the MultiAppTransfers to be executed on TO_MULTIAPP
    1348       61775 :     const auto & to_multi_app_objects = _to_multi_app_transfers.getActiveObjects();
    1349       66939 :     for (const auto & transfer : to_multi_app_objects)
    1350             :     {
    1351        5228 :       transfer->setCurrentDirection(Transfer::DIRECTION::TO_MULTIAPP);
    1352        5228 :       transfer->initialSetup();
    1353             :     }
    1354             : 
    1355             :     // Call initialSetup on the MultiAppTransfers to be executed on FROM_MULTIAPP
    1356       61711 :     const auto & from_multi_app_objects = _from_multi_app_transfers.getActiveObjects();
    1357       67446 :     for (const auto & transfer : from_multi_app_objects)
    1358             :     {
    1359        5791 :       transfer->setCurrentDirection(Transfer::DIRECTION::FROM_MULTIAPP);
    1360        5791 :       transfer->initialSetup();
    1361             :     }
    1362             : 
    1363             :     // Call initialSetup on the MultiAppTransfers to be executed on BETWEEN_MULTIAPP
    1364       61655 :     const auto & between_multi_app_objects = _between_multi_app_transfers.getActiveObjects();
    1365       62851 :     for (const auto & transfer : between_multi_app_objects)
    1366             :     {
    1367        1196 :       transfer->setCurrentDirection(Transfer::DIRECTION::BETWEEN_MULTIAPP);
    1368        1196 :       transfer->initialSetup();
    1369             :     }
    1370       61655 :   }
    1371             : 
    1372       61655 :   if (_boundary_restricted_node_integrity_check)
    1373             :   {
    1374      184926 :     TIME_SECTION("BoundaryRestrictedNodeIntegrityCheck", 5);
    1375             : 
    1376             :     // check that variables are defined along boundaries of boundary restricted nodal objects
    1377       61642 :     ConstBndNodeRange & bnd_nodes = *mesh().getBoundaryNodeRange();
    1378       61642 :     BoundaryNodeIntegrityCheckThread bnict(*this, uo_query);
    1379       61642 :     Threads::parallel_reduce(bnd_nodes, bnict);
    1380             : 
    1381             :     // Nodal bcs aren't threaded
    1382       61630 :     const auto & node_to_elem_map = _mesh.nodeToActiveSemilocalElemMap();
    1383     4694038 :     for (const auto & bnode : bnd_nodes)
    1384             :     {
    1385     4632420 :       const auto boundary_id = bnode->_bnd_id;
    1386     4632420 :       const Node * const node = bnode->_node;
    1387             : 
    1388     4632420 :       if (node->processor_id() != this->processor_id())
    1389      879147 :         continue;
    1390             : 
    1391             :       // Only check vertices. Variables may not be defined on non-vertex nodes (think first order
    1392             :       // Lagrange on a second order mesh) and user-code can often handle that
    1393             :       const Elem * const an_elem =
    1394     3753273 :           _mesh.getMesh().elem_ptr(libmesh_map_find(node_to_elem_map, node->id()).front());
    1395     3753273 :       if (!an_elem->is_vertex(an_elem->get_node_index(node)))
    1396      464237 :         continue;
    1397             : 
    1398     3289036 :       const auto & bnd_name = _mesh.getBoundaryName(boundary_id);
    1399             : 
    1400     6531780 :       for (auto & nl : _nl)
    1401             :       {
    1402     3242756 :         const auto & nodal_bcs = nl->getNodalBCWarehouse();
    1403     3242756 :         if (!nodal_bcs.hasBoundaryObjects(boundary_id, 0))
    1404     2327575 :           continue;
    1405             : 
    1406      915181 :         const auto & bnd_objects = nodal_bcs.getBoundaryObjects(boundary_id, 0);
    1407     1920743 :         for (const auto & bnd_object : bnd_objects)
    1408             :           // Skip if this object uses geometric search because coupled variables may be defined on
    1409             :           // paired boundaries instead of the boundary this node is on
    1410     2011148 :           if (!bnd_object->requiresGeometricSearch() &&
    1411     1005574 :               bnd_object->checkVariableBoundaryIntegrity())
    1412             :           {
    1413             :             std::set<MooseVariableFieldBase *> vars_to_omit = {
    1414             :                 &static_cast<MooseVariableFieldBase &>(
    1415     2011148 :                     const_cast<MooseVariableBase &>(bnd_object->variable()))};
    1416             : 
    1417     2011148 :             boundaryIntegrityCheckError(
    1418     2011136 :                 *bnd_object, bnd_object->checkAllVariables(*node, vars_to_omit), bnd_name);
    1419     1005562 :           }
    1420             :       }
    1421             :     }
    1422       61618 :   }
    1423             : 
    1424       61631 :   if (_boundary_restricted_elem_integrity_check)
    1425             :   {
    1426      184791 :     TIME_SECTION("BoundaryRestrictedElemIntegrityCheck", 5);
    1427             : 
    1428             :     // check that variables are defined along boundaries of boundary restricted elemental objects
    1429       61597 :     ConstBndElemRange & bnd_elems = *mesh().getBoundaryElementRange();
    1430       61597 :     BoundaryElemIntegrityCheckThread beict(*this, uo_query);
    1431       61597 :     Threads::parallel_reduce(bnd_elems, beict);
    1432       61581 :   }
    1433             : 
    1434       61615 :   if (!_app.isRecovering())
    1435             :   {
    1436       57601 :     execTransfers(EXEC_INITIAL);
    1437             : 
    1438       57601 :     bool converged = execMultiApps(EXEC_INITIAL);
    1439       57593 :     if (!converged)
    1440           4 :       mooseError("failed to converge initial MultiApp");
    1441             : 
    1442             :     // We'll backup the Multiapp here
    1443       57589 :     backupMultiApps(EXEC_INITIAL);
    1444             : 
    1445      120733 :     for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1446       63144 :       reinitScalars(tid);
    1447             : 
    1448       57589 :     execute(EXEC_INITIAL);
    1449             : 
    1450             :     // The FEProblemBase::execute method doesn't call all the systems on EXEC_INITIAL, but it does
    1451             :     // set/unset the current flag. Therefore, this resets the current flag to EXEC_INITIAL so that
    1452             :     // subsequent calls (e.g., executeControls) have the proper flag.
    1453       57520 :     setCurrentExecuteOnFlag(EXEC_INITIAL);
    1454             :   }
    1455             : 
    1456             :   // Here we will initialize the stateful properties once more since they may have been updated
    1457             :   // during initialSetup by calls to computeProperties.
    1458             :   //
    1459             :   // It's really bad that we don't allow this during restart.  It means that we can't add new
    1460             :   // stateful materials
    1461             :   // during restart.  This is only happening because this _has_ to be below initial userobject
    1462             :   // execution.
    1463             :   // Otherwise this could be done up above... _before_ restoring restartable data... which would
    1464             :   // allow you to have
    1465             :   // this happen during restart.  I honestly have no idea why this has to happen after initial user
    1466             :   // object computation.
    1467             :   // THAT is something we should fix... so I've opened this ticket: #5804
    1468       61534 :   if (!_app.isRecovering() && !_app.isRestarting())
    1469             :   {
    1470      113330 :     if (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    1471       56342 :         _neighbor_material_props.hasStatefulProperties())
    1472             :     {
    1473        3230 :       TIME_SECTION("computeMaterials", 2, "Computing Initial Material Properties");
    1474             : 
    1475         646 :       initElementStatefulProps(*_mesh.getActiveLocalElementRange(), true);
    1476         646 :     }
    1477             : #ifdef MOOSE_KOKKOS_ENABLED
    1478       37058 :     if (_kokkos_material_props.hasStatefulProperties() ||
    1479       74006 :         _kokkos_bnd_material_props.hasStatefulProperties() ||
    1480       36948 :         _kokkos_neighbor_material_props.hasStatefulProperties())
    1481             :     {
    1482         550 :       TIME_SECTION("computeMaterials", 2, "Computing Initial Material Properties");
    1483             : 
    1484         110 :       initElementStatefulProps(*_mesh.getActiveLocalElementRange(), true);
    1485         110 :     }
    1486             : #endif
    1487             :   }
    1488             : 
    1489             :   // Control Logic
    1490       61534 :   executeControls(EXEC_INITIAL);
    1491             : 
    1492             :   // Scalar variables need to reinited for the initial conditions to be available for output
    1493      128569 :   for (unsigned int tid = 0; tid < n_threads; tid++)
    1494       67071 :     reinitScalars(tid);
    1495             : 
    1496       61498 :   if (_displaced_mesh)
    1497        2234 :     _displaced_problem->syncSolutions();
    1498             : 
    1499             :   // Writes all calls to _console from initialSetup() methods
    1500       61498 :   _app.getOutputWarehouse().mooseConsole();
    1501             : 
    1502       61498 :   if (_requires_nonlocal_coupling)
    1503             :   {
    1504          81 :     setNonlocalCouplingMatrix();
    1505         162 :     for (THREAD_ID tid = 0; tid < n_threads; ++tid)
    1506         162 :       for (auto & assembly : _assembly[tid])
    1507          81 :         assembly->initNonlocalCoupling();
    1508             :   }
    1509             : 
    1510             :   {
    1511      307490 :     TIME_SECTION("lineSearchInitialSetup", 5, "Initializing Line Search");
    1512             : 
    1513       61498 :     if (_line_search)
    1514           0 :       _line_search->initialSetup();
    1515       61498 :   }
    1516             : 
    1517             :   // Perform Reporter get/declare check
    1518       61498 :   _reporter_data.check();
    1519             : 
    1520             :   // We do this late to allow objects to get late restartable data
    1521       61498 :   if (_app.isRestarting() || _app.isRecovering() || _force_restart)
    1522        4546 :     _app.finalizeRestore();
    1523             : 
    1524       61498 :   setCurrentExecuteOnFlag(EXEC_NONE);
    1525       61498 : }
    1526             : 
    1527             : void
    1528       62546 : FEProblemBase::checkDuplicatePostprocessorVariableNames()
    1529             : {
    1530      117896 :   for (const auto & pp : _reporter_data.getPostprocessorNames())
    1531       55350 :     if (hasScalarVariable(pp))
    1532           0 :       mooseError("Postprocessor \"" + pp +
    1533       62546 :                  "\" has the same name as a scalar variable in the system.");
    1534       62546 : }
    1535             : 
    1536             : void
    1537      289691 : FEProblemBase::timestepSetup()
    1538             : {
    1539      289691 :   SubProblem::timestepSetup();
    1540             : 
    1541      289691 :   if (_t_step > 1 && _num_grid_steps)
    1542             :   {
    1543          35 :     libMesh::MeshRefinement mesh_refinement(_mesh);
    1544          35 :     std::unique_ptr<libMesh::MeshRefinement> displaced_mesh_refinement(nullptr);
    1545          35 :     if (_displaced_mesh)
    1546          25 :       displaced_mesh_refinement = std::make_unique<libMesh::MeshRefinement>(*_displaced_mesh);
    1547             : 
    1548          70 :     for (MooseIndex(_num_grid_steps) i = 0; i < _num_grid_steps; ++i)
    1549             :     {
    1550          35 :       if (_displaced_problem)
    1551             :         // If the DisplacedProblem is active, undisplace the DisplacedMesh in preparation for
    1552             :         // refinement.  We can't safely refine the DisplacedMesh directly, since the Hilbert keys
    1553             :         // computed on the inconsistenly-displaced Mesh are different on different processors,
    1554             :         // leading to inconsistent Hilbert keys.  We must do this before the undisplaced Mesh is
    1555             :         // coarsensed, so that the element and node numbering is still consistent. We also have to
    1556             :         // make sure this is done during every step of coarsening otherwise different partitions
    1557             :         // will be generated for the reference and displaced meshes (even for replicated)
    1558          25 :         _displaced_problem->undisplaceMesh();
    1559             : 
    1560          35 :       mesh_refinement.uniformly_coarsen();
    1561          35 :       if (_displaced_mesh)
    1562          25 :         displaced_mesh_refinement->uniformly_coarsen();
    1563             : 
    1564             :       // Mark this as an intermediate change because we do not yet want to reinit_systems. E.g. we
    1565             :       // need things to happen in the following order for the undisplaced problem:
    1566             :       // u1) EquationSystems::reinit_solutions. This will restrict the solution vectors and then
    1567             :       //     contract the mesh
    1568             :       // u2) MooseMesh::meshChanged. This will update the node/side lists and other
    1569             :       //     things which needs to happen after the contraction
    1570             :       // u3) GeometricSearchData::reinit. Once the node/side lists are updated we can perform our
    1571             :       //     geometric searches which will aid in determining sparsity patterns
    1572             :       //
    1573             :       // We do these things for the displaced problem (if it exists)
    1574             :       // d1) EquationSystems::reinit. Restrict the displaced problem vector copies and then contract
    1575             :       //     the mesh. It's safe to do a full reinit with the displaced because there are no
    1576             :       //     matrices that sparsity pattern calculations will be conducted for
    1577             :       // d2) MooseMesh::meshChanged. This will update the node/side lists and other
    1578             :       //     things which needs to happen after the contraction
    1579             :       // d3) UpdateDisplacedMeshThread::operator(). Re-displace the mesh using the *displaced*
    1580             :       //     solution vector copy because we don't know the state of the reference solution vector.
    1581             :       //     It's safe to use the displaced copy because we are outside of a non-linear solve,
    1582             :       //     and there is no concern about differences between solution and current_local_solution
    1583             :       // d4) GeometricSearchData::reinit. With the node/side lists updated and the mesh
    1584             :       //     re-displaced, we can perform our geometric searches, which will aid in determining the
    1585             :       //     sparsity pattern of the matrix held by the libMesh::ImplicitSystem held by the
    1586             :       //     NonlinearSystem held by this
    1587          35 :       meshChanged(
    1588             :           /*intermediate_change=*/true, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
    1589             :     }
    1590             : 
    1591             :     // u4) Now that all the geometric searches have been done (both undisplaced and displaced),
    1592             :     //     we're ready to update the sparsity pattern
    1593          35 :     es().reinit_systems();
    1594          35 :   }
    1595             : 
    1596      289691 :   if (_line_search)
    1597           0 :     _line_search->timestepSetup();
    1598             : 
    1599             :   // Random interface objects
    1600      291404 :   for (const auto & it : _random_data_objects)
    1601        1713 :     it.second->updateSeeds(EXEC_TIMESTEP_BEGIN);
    1602             : 
    1603      289691 :   unsigned int n_threads = libMesh::n_threads();
    1604      605029 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1605             :   {
    1606      315338 :     _all_materials.timestepSetup(tid);
    1607      315338 :     _functions.timestepSetup(tid);
    1608             :   }
    1609             : 
    1610      289691 :   _aux->timestepSetup();
    1611      583157 :   for (auto & sys : _solver_systems)
    1612      293466 :     sys->timestepSetup();
    1613             : 
    1614      289691 :   if (_displaced_problem)
    1615             :     // timestepSetup for displaced systems
    1616       33515 :     _displaced_problem->timestepSetup();
    1617             : 
    1618      605029 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    1619             :   {
    1620      315338 :     _internal_side_indicators.timestepSetup(tid);
    1621      315338 :     _indicators.timestepSetup(tid);
    1622      315338 :     _markers.timestepSetup(tid);
    1623             :   }
    1624             : 
    1625      289691 :   std::vector<UserObject *> userobjs;
    1626      289691 :   theWarehouse().query().condition<AttribSystem>("UserObject").queryIntoUnsorted(userobjs);
    1627      653822 :   for (auto obj : userobjs)
    1628      364131 :     obj->timestepSetup();
    1629             : 
    1630             :   // Timestep setup of output objects
    1631      289691 :   _app.getOutputWarehouse().timestepSetup();
    1632             : 
    1633      289691 :   if (_requires_nonlocal_coupling)
    1634         123 :     if (_nonlocal_kernels.hasActiveObjects() || _nonlocal_integrated_bcs.hasActiveObjects())
    1635         123 :       _has_nonlocal_coupling = true;
    1636      289691 : }
    1637             : 
    1638             : unsigned int
    1639      834702 : FEProblemBase::getMaxQps() const
    1640             : {
    1641      834702 :   if (_max_qps == std::numeric_limits<unsigned int>::max())
    1642           0 :     mooseError("Max QPS uninitialized");
    1643      834702 :   return _max_qps;
    1644             : }
    1645             : 
    1646             : Order
    1647          56 : FEProblemBase::getMaxScalarOrder() const
    1648             : {
    1649          56 :   return _max_scalar_order;
    1650             : }
    1651             : 
    1652             : void
    1653       61869 : FEProblemBase::checkNonlocalCoupling()
    1654             : {
    1655      309345 :   TIME_SECTION("checkNonlocalCoupling", 5, "Checking Nonlocal Coupling");
    1656             : 
    1657      129403 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    1658      134020 :     for (auto & nl : _nl)
    1659             :     {
    1660       66486 :       const auto & all_kernels = nl->getKernelWarehouse();
    1661       66486 :       const auto & kernels = all_kernels.getObjects(tid);
    1662      157637 :       for (const auto & kernel : kernels)
    1663             :       {
    1664             :         std::shared_ptr<NonlocalKernel> nonlocal_kernel =
    1665       91151 :             std::dynamic_pointer_cast<NonlocalKernel>(kernel);
    1666       91151 :         if (nonlocal_kernel)
    1667             :         {
    1668          45 :           if (_calculate_jacobian_in_uo)
    1669          45 :             _requires_nonlocal_coupling = true;
    1670          45 :           _nonlocal_kernels.addObject(kernel, tid);
    1671             :         }
    1672       91151 :       }
    1673             :       const MooseObjectWarehouse<IntegratedBCBase> & all_integrated_bcs =
    1674       66486 :           nl->getIntegratedBCWarehouse();
    1675       66486 :       const auto & integrated_bcs = all_integrated_bcs.getObjects(tid);
    1676       76301 :       for (const auto & integrated_bc : integrated_bcs)
    1677             :       {
    1678             :         std::shared_ptr<NonlocalIntegratedBC> nonlocal_integrated_bc =
    1679        9815 :             std::dynamic_pointer_cast<NonlocalIntegratedBC>(integrated_bc);
    1680        9815 :         if (nonlocal_integrated_bc)
    1681             :         {
    1682          36 :           if (_calculate_jacobian_in_uo)
    1683          36 :             _requires_nonlocal_coupling = true;
    1684          36 :           _nonlocal_integrated_bcs.addObject(integrated_bc, tid);
    1685             :         }
    1686        9815 :       }
    1687             :     }
    1688       61869 : }
    1689             : 
    1690             : void
    1691       67534 : FEProblemBase::checkUserObjectJacobianRequirement(THREAD_ID tid)
    1692             : {
    1693       67534 :   std::set<const MooseVariableFEBase *> uo_jacobian_moose_vars;
    1694             :   {
    1695       67534 :     std::vector<ShapeElementUserObject *> objs;
    1696       67534 :     theWarehouse()
    1697       67534 :         .query()
    1698      135068 :         .condition<AttribInterfaces>(Interfaces::ShapeElementUserObject)
    1699       67534 :         .condition<AttribThread>(tid)
    1700       67534 :         .queryInto(objs);
    1701             : 
    1702       67590 :     for (const auto & uo : objs)
    1703             :     {
    1704          56 :       _calculate_jacobian_in_uo = uo->computeJacobianFlag();
    1705          56 :       const auto & mv_deps = uo->jacobianMooseVariables();
    1706          56 :       uo_jacobian_moose_vars.insert(mv_deps.begin(), mv_deps.end());
    1707             :     }
    1708       67534 :   }
    1709             :   {
    1710       67534 :     std::vector<ShapeSideUserObject *> objs;
    1711       67534 :     theWarehouse()
    1712       67534 :         .query()
    1713      135068 :         .condition<AttribInterfaces>(Interfaces::ShapeSideUserObject)
    1714       67534 :         .condition<AttribThread>(tid)
    1715       67534 :         .queryInto(objs);
    1716       67606 :     for (const auto & uo : objs)
    1717             :     {
    1718          72 :       _calculate_jacobian_in_uo = uo->computeJacobianFlag();
    1719          72 :       const auto & mv_deps = uo->jacobianMooseVariables();
    1720          72 :       uo_jacobian_moose_vars.insert(mv_deps.begin(), mv_deps.end());
    1721             :     }
    1722       67534 :   }
    1723             : 
    1724       67534 :   _uo_jacobian_moose_vars[tid].assign(uo_jacobian_moose_vars.begin(), uo_jacobian_moose_vars.end());
    1725      135068 :   std::sort(
    1726      135068 :       _uo_jacobian_moose_vars[tid].begin(), _uo_jacobian_moose_vars[tid].end(), sortMooseVariables);
    1727       67534 : }
    1728             : 
    1729             : void
    1730          81 : FEProblemBase::setVariableAllDoFMap(const std::vector<const MooseVariableFEBase *> & moose_vars)
    1731             : {
    1732         197 :   for (unsigned int i = 0; i < moose_vars.size(); ++i)
    1733             :   {
    1734         116 :     VariableName var_name = moose_vars[i]->name();
    1735         116 :     auto & sys = _solver_systems[moose_vars[i]->sys().number()];
    1736         116 :     sys->setVariableGlobalDoFs(var_name);
    1737         116 :     _var_dof_map[var_name] = sys->getVariableGlobalDoFs();
    1738         116 :   }
    1739          81 : }
    1740             : 
    1741             : void
    1742   431240857 : FEProblemBase::prepare(const Elem * elem, const THREAD_ID tid)
    1743             : {
    1744   865280674 :   for (const auto i : index_range(_solver_systems))
    1745             :   {
    1746   434039817 :     _assembly[tid][i]->reinit(elem);
    1747   434039817 :     _solver_systems[i]->prepare(tid);
    1748             : 
    1749   434039817 :     if (i < _num_nl_sys)
    1750             :     {
    1751             :       // This method is called outside of residual/Jacobian callbacks during initial condition
    1752             :       // evaluation
    1753   433366987 :       if ((!_has_jacobian || !_const_jacobian) && currentlyComputingJacobian())
    1754    56171637 :         _assembly[tid][i]->prepareJacobianBlock();
    1755   433366987 :       _assembly[tid][i]->prepareResidual();
    1756   433366987 :       if (_has_nonlocal_coupling && currentlyComputingJacobian())
    1757       11792 :         _assembly[tid][i]->prepareNonlocal();
    1758             :     }
    1759             :   }
    1760   431240857 :   _aux->prepare(tid);
    1761             : 
    1762   444523619 :   if (_displaced_problem &&
    1763             :       // _reinit_displaced_neighbor applies to interface type objects which will do computations
    1764             :       // based on both elem and neighbor. Consequently, despite what you might think by its name, we
    1765             :       // must make sure we prepare the displaced elem
    1766   444523619 :       (_reinit_displaced_elem || _reinit_displaced_face || _reinit_displaced_neighbor))
    1767             :   {
    1768     8536374 :     _displaced_problem->prepare(_displaced_mesh->elemPtr(elem->id()), tid);
    1769     8536346 :     if (_has_nonlocal_coupling)
    1770           0 :       _displaced_problem->prepareNonlocal(tid);
    1771             :   }
    1772   431240829 : }
    1773             : 
    1774             : void
    1775       29479 : FEProblemBase::prepareFace(const Elem * elem, const THREAD_ID tid)
    1776             : {
    1777       58958 :   for (auto & nl : _nl)
    1778       29479 :     nl->prepareFace(tid, true);
    1779       29479 :   _aux->prepareFace(tid, false);
    1780             : 
    1781       29479 :   if (_displaced_problem && (_reinit_displaced_elem || _reinit_displaced_face))
    1782           0 :     _displaced_problem->prepareFace(_displaced_mesh->elemPtr(elem->id()), tid);
    1783       29479 : }
    1784             : 
    1785             : void
    1786           0 : FEProblemBase::prepare(const Elem * elem,
    1787             :                        unsigned int ivar,
    1788             :                        unsigned int jvar,
    1789             :                        const std::vector<dof_id_type> & dof_indices,
    1790             :                        const THREAD_ID tid)
    1791             : {
    1792           0 :   for (const auto i : index_range(_nl))
    1793             :   {
    1794           0 :     _assembly[tid][i]->reinit(elem);
    1795           0 :     _nl[i]->prepare(tid);
    1796             :   }
    1797             : 
    1798           0 :   _aux->prepare(tid);
    1799           0 :   const auto current_nl_sys_num = _current_nl_sys->number();
    1800           0 :   _assembly[tid][current_nl_sys_num]->prepareBlock(ivar, jvar, dof_indices);
    1801           0 :   if (_has_nonlocal_coupling)
    1802           0 :     if (_nonlocal_cm[current_nl_sys_num](ivar, jvar) != 0)
    1803             :     {
    1804           0 :       MooseVariableFEBase & jv = _current_nl_sys->getVariable(tid, jvar);
    1805           0 :       _assembly[tid][current_nl_sys_num]->prepareBlockNonlocal(
    1806             :           ivar, jvar, dof_indices, jv.allDofIndices());
    1807             :     }
    1808             : 
    1809           0 :   if (_displaced_problem && (_reinit_displaced_elem || _reinit_displaced_face))
    1810             :   {
    1811           0 :     _displaced_problem->prepare(_displaced_mesh->elemPtr(elem->id()), ivar, jvar, dof_indices, tid);
    1812           0 :     if (_has_nonlocal_coupling)
    1813           0 :       if (_nonlocal_cm[current_nl_sys_num](ivar, jvar) != 0)
    1814             :       {
    1815           0 :         MooseVariableFEBase & jv = _current_nl_sys->getVariable(tid, jvar);
    1816           0 :         _displaced_problem->prepareBlockNonlocal(ivar, jvar, dof_indices, jv.allDofIndices(), tid);
    1817             :       }
    1818             :   }
    1819           0 : }
    1820             : 
    1821             : void
    1822   472065934 : FEProblemBase::setCurrentSubdomainID(const Elem * elem, const THREAD_ID tid)
    1823             : {
    1824   472065934 :   SubdomainID did = elem->subdomain_id();
    1825   948069527 :   for (const auto i : index_range(_solver_systems))
    1826             :   {
    1827   476003593 :     _assembly[tid][i]->setCurrentSubdomainID(did);
    1828   490213197 :     if (_displaced_problem &&
    1829   490213197 :         (_reinit_displaced_elem || _reinit_displaced_face || _reinit_displaced_neighbor))
    1830     8817056 :       _displaced_problem->assembly(tid, i).setCurrentSubdomainID(did);
    1831             :   }
    1832   472065934 : }
    1833             : 
    1834             : void
    1835  1664403010 : FEProblemBase::setNeighborSubdomainID(const Elem * elem, unsigned int side, const THREAD_ID tid)
    1836             : {
    1837  1664403010 :   SubdomainID did = elem->neighbor_ptr(side)->subdomain_id();
    1838  3334086420 :   for (const auto i : index_range(_nl))
    1839             :   {
    1840  1669683410 :     _assembly[tid][i]->setCurrentNeighborSubdomainID(did);
    1841  1719367513 :     if (_displaced_problem &&
    1842  1719367513 :         (_reinit_displaced_elem || _reinit_displaced_face || _reinit_displaced_neighbor))
    1843    29111734 :       _displaced_problem->assembly(tid, i).setCurrentNeighborSubdomainID(did);
    1844             :   }
    1845  1664403010 : }
    1846             : 
    1847             : void
    1848    23572031 : FEProblemBase::setNeighborSubdomainID(const Elem * elem, const THREAD_ID tid)
    1849             : {
    1850    23572031 :   SubdomainID did = elem->subdomain_id();
    1851    48214288 :   for (const auto i : index_range(_nl))
    1852             :   {
    1853    24642257 :     _assembly[tid][i]->setCurrentNeighborSubdomainID(did);
    1854    24699961 :     if (_displaced_problem &&
    1855    24699961 :         (_reinit_displaced_elem || _reinit_displaced_face || _reinit_displaced_neighbor))
    1856       57704 :       _displaced_problem->assembly(tid, i).setCurrentNeighborSubdomainID(did);
    1857             :   }
    1858    23572031 : }
    1859             : 
    1860             : void
    1861      153242 : FEProblemBase::prepareAssembly(const THREAD_ID tid)
    1862             : {
    1863      153242 :   _assembly[tid][_current_nl_sys->number()]->prepare();
    1864      153242 :   if (_has_nonlocal_coupling)
    1865           0 :     _assembly[tid][_current_nl_sys->number()]->prepareNonlocal();
    1866             : 
    1867      153242 :   if (_displaced_problem && (_reinit_displaced_elem || _reinit_displaced_face))
    1868             :   {
    1869       57704 :     _displaced_problem->prepareAssembly(tid);
    1870       57704 :     if (_has_nonlocal_coupling)
    1871           0 :       _displaced_problem->prepareNonlocal(tid);
    1872             :   }
    1873      153242 : }
    1874             : 
    1875             : void
    1876      300146 : FEProblemBase::addResidual(const THREAD_ID tid)
    1877             : {
    1878      600292 :   _assembly[tid][_current_nl_sys->number()]->addResidual(Assembly::GlobalDataKey{},
    1879      300146 :                                                          currentResidualVectorTags());
    1880             : 
    1881      300146 :   if (_displaced_problem)
    1882        5288 :     _displaced_problem->addResidual(tid);
    1883      300146 : }
    1884             : 
    1885             : void
    1886     2337539 : FEProblemBase::addResidualNeighbor(const THREAD_ID tid)
    1887             : {
    1888     4675078 :   _assembly[tid][_current_nl_sys->number()]->addResidualNeighbor(Assembly::GlobalDataKey{},
    1889     2337539 :                                                                  currentResidualVectorTags());
    1890             : 
    1891     2337539 :   if (_displaced_problem)
    1892       68460 :     _displaced_problem->addResidualNeighbor(tid);
    1893     2337539 : }
    1894             : 
    1895             : void
    1896     2312671 : FEProblemBase::addResidualLower(const THREAD_ID tid)
    1897             : {
    1898     4625342 :   _assembly[tid][_current_nl_sys->number()]->addResidualLower(Assembly::GlobalDataKey{},
    1899     2312671 :                                                               currentResidualVectorTags());
    1900             : 
    1901     2312671 :   if (_displaced_problem)
    1902       68688 :     _displaced_problem->addResidualLower(tid);
    1903     2312671 : }
    1904             : 
    1905             : void
    1906       64576 : FEProblemBase::addResidualScalar(const THREAD_ID tid /* = 0*/)
    1907             : {
    1908      129152 :   _assembly[tid][_current_nl_sys->number()]->addResidualScalar(Assembly::GlobalDataKey{},
    1909       64576 :                                                                currentResidualVectorTags());
    1910       64576 : }
    1911             : 
    1912             : void
    1913   329590467 : FEProblemBase::cacheResidual(const THREAD_ID tid)
    1914             : {
    1915   329590467 :   SubProblem::cacheResidual(tid);
    1916   329590467 :   if (_displaced_problem)
    1917     8645975 :     _displaced_problem->cacheResidual(tid);
    1918   329590467 : }
    1919             : 
    1920             : void
    1921       55594 : FEProblemBase::cacheResidualNeighbor(const THREAD_ID tid)
    1922             : {
    1923       55594 :   SubProblem::cacheResidualNeighbor(tid);
    1924       55594 :   if (_displaced_problem)
    1925          36 :     _displaced_problem->cacheResidualNeighbor(tid);
    1926       55594 : }
    1927             : 
    1928             : void
    1929    19085896 : FEProblemBase::addCachedResidual(const THREAD_ID tid)
    1930             : {
    1931    19085896 :   SubProblem::addCachedResidual(tid);
    1932    19085896 :   if (_displaced_problem)
    1933      555761 :     _displaced_problem->addCachedResidual(tid);
    1934    19085896 : }
    1935             : 
    1936             : void
    1937       11826 : FEProblemBase::addCachedResidualDirectly(NumericVector<Number> & residual, const THREAD_ID tid)
    1938             : {
    1939       11826 :   if (_current_nl_sys->hasVector(_current_nl_sys->timeVectorTag()))
    1940       32553 :     _assembly[tid][_current_nl_sys->number()]->addCachedResidualDirectly(
    1941       32553 :         residual, Assembly::GlobalDataKey{}, getVectorTag(_current_nl_sys->timeVectorTag()));
    1942             : 
    1943       11826 :   if (_current_nl_sys->hasVector(_current_nl_sys->nonTimeVectorTag()))
    1944       35478 :     _assembly[tid][_current_nl_sys->number()]->addCachedResidualDirectly(
    1945       35478 :         residual, Assembly::GlobalDataKey{}, getVectorTag(_current_nl_sys->nonTimeVectorTag()));
    1946             : 
    1947             :   // We do this because by adding the cached residual directly, we cannot ensure that all of the
    1948             :   // cached residuals are emptied after only the two add calls above
    1949       11826 :   _assembly[tid][_current_nl_sys->number()]->clearCachedResiduals(Assembly::GlobalDataKey{});
    1950             : 
    1951       11826 :   if (_displaced_problem)
    1952          48 :     _displaced_problem->addCachedResidualDirectly(residual, tid);
    1953       11826 : }
    1954             : 
    1955             : void
    1956           0 : FEProblemBase::setResidual(NumericVector<Number> & residual, const THREAD_ID tid)
    1957             : {
    1958           0 :   _assembly[tid][_current_nl_sys->number()]->setResidual(
    1959             :       residual,
    1960           0 :       Assembly::GlobalDataKey{},
    1961           0 :       getVectorTag(_nl[_current_nl_sys->number()]->residualVectorTag()));
    1962           0 :   if (_displaced_problem)
    1963           0 :     _displaced_problem->setResidual(residual, tid);
    1964           0 : }
    1965             : 
    1966             : void
    1967           0 : FEProblemBase::setResidualNeighbor(NumericVector<Number> & residual, const THREAD_ID tid)
    1968             : {
    1969           0 :   _assembly[tid][_current_nl_sys->number()]->setResidualNeighbor(
    1970           0 :       residual, Assembly::GlobalDataKey{}, getVectorTag(_current_nl_sys->residualVectorTag()));
    1971           0 :   if (_displaced_problem)
    1972           0 :     _displaced_problem->setResidualNeighbor(residual, tid);
    1973           0 : }
    1974             : 
    1975             : void
    1976       42097 : FEProblemBase::addJacobian(const THREAD_ID tid)
    1977             : {
    1978       42097 :   _assembly[tid][_current_nl_sys->number()]->addJacobian(Assembly::GlobalDataKey{});
    1979       42097 :   if (_has_nonlocal_coupling)
    1980           0 :     _assembly[tid][_current_nl_sys->number()]->addJacobianNonlocal(Assembly::GlobalDataKey{});
    1981       42097 :   if (_displaced_problem)
    1982             :   {
    1983         224 :     _displaced_problem->addJacobian(tid);
    1984         224 :     if (_has_nonlocal_coupling)
    1985           0 :       _displaced_problem->addJacobianNonlocal(tid);
    1986             :   }
    1987       42097 : }
    1988             : 
    1989             : void
    1990        9105 : FEProblemBase::addJacobianNeighbor(const THREAD_ID tid)
    1991             : {
    1992        9105 :   _assembly[tid][_current_nl_sys->number()]->addJacobianNeighbor(Assembly::GlobalDataKey{});
    1993        9105 :   if (_displaced_problem)
    1994          54 :     _displaced_problem->addJacobianNeighbor(tid);
    1995        9105 : }
    1996             : 
    1997             : void
    1998      127506 : FEProblemBase::addJacobianNeighborLowerD(const THREAD_ID tid)
    1999             : {
    2000      127506 :   _assembly[tid][_current_nl_sys->number()]->addJacobianNeighborLowerD(Assembly::GlobalDataKey{});
    2001      127506 :   if (_displaced_problem)
    2002        3456 :     _displaced_problem->addJacobianNeighborLowerD(tid);
    2003      127506 : }
    2004             : 
    2005             : void
    2006        5220 : FEProblemBase::addJacobianLowerD(const THREAD_ID tid)
    2007             : {
    2008        5220 :   _assembly[tid][_current_nl_sys->number()]->addJacobianLowerD(Assembly::GlobalDataKey{});
    2009        5220 :   if (_displaced_problem)
    2010         216 :     _displaced_problem->addJacobianLowerD(tid);
    2011        5220 : }
    2012             : 
    2013             : void
    2014       15622 : FEProblemBase::addJacobianScalar(const THREAD_ID tid /* = 0*/)
    2015             : {
    2016       15622 :   _assembly[tid][_current_nl_sys->number()]->addJacobianScalar(Assembly::GlobalDataKey{});
    2017       15622 : }
    2018             : 
    2019             : void
    2020       39233 : FEProblemBase::addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid /* = 0*/)
    2021             : {
    2022       78466 :   _assembly[tid][_current_nl_sys->number()]->addJacobianOffDiagScalar(ivar,
    2023       39233 :                                                                       Assembly::GlobalDataKey{});
    2024       39233 : }
    2025             : 
    2026             : void
    2027    55537886 : FEProblemBase::cacheJacobian(const THREAD_ID tid)
    2028             : {
    2029    55537886 :   SubProblem::cacheJacobian(tid);
    2030    55537886 :   if (_displaced_problem)
    2031     1767232 :     _displaced_problem->cacheJacobian(tid);
    2032    55537886 : }
    2033             : 
    2034             : void
    2035       10576 : FEProblemBase::cacheJacobianNeighbor(const THREAD_ID tid)
    2036             : {
    2037       10576 :   SubProblem::cacheJacobianNeighbor(tid);
    2038       10576 :   if (_displaced_problem)
    2039           0 :     _displaced_problem->cacheJacobianNeighbor(tid);
    2040       10576 : }
    2041             : 
    2042             : void
    2043     3469937 : FEProblemBase::addCachedJacobian(const THREAD_ID tid)
    2044             : {
    2045     3469937 :   SubProblem::addCachedJacobian(tid);
    2046     3469933 :   if (_displaced_problem)
    2047      108971 :     _displaced_problem->addCachedJacobian(tid);
    2048     3469933 : }
    2049             : 
    2050             : void
    2051       81172 : FEProblemBase::addJacobianBlockTags(SparseMatrix<Number> & jacobian,
    2052             :                                     unsigned int ivar,
    2053             :                                     unsigned int jvar,
    2054             :                                     const DofMap & dof_map,
    2055             :                                     std::vector<dof_id_type> & dof_indices,
    2056             :                                     const std::set<TagID> & tags,
    2057             :                                     const THREAD_ID tid)
    2058             : {
    2059      162344 :   _assembly[tid][_current_nl_sys->number()]->addJacobianBlockTags(
    2060       81172 :       jacobian, ivar, jvar, dof_map, dof_indices, Assembly::GlobalDataKey{}, tags);
    2061             : 
    2062       81172 :   if (_has_nonlocal_coupling)
    2063           0 :     if (_nonlocal_cm[_current_nl_sys->number()](ivar, jvar) != 0)
    2064             :     {
    2065           0 :       MooseVariableFEBase & jv = _current_nl_sys->getVariable(tid, jvar);
    2066           0 :       _assembly[tid][_current_nl_sys->number()]->addJacobianBlockNonlocalTags(
    2067             :           jacobian,
    2068             :           ivar,
    2069             :           jvar,
    2070             :           dof_map,
    2071             :           dof_indices,
    2072             :           jv.allDofIndices(),
    2073           0 :           Assembly::GlobalDataKey{},
    2074             :           tags);
    2075             :     }
    2076             : 
    2077       81172 :   if (_displaced_problem)
    2078             :   {
    2079           0 :     _displaced_problem->addJacobianBlockTags(jacobian, ivar, jvar, dof_map, dof_indices, tags, tid);
    2080           0 :     if (_has_nonlocal_coupling)
    2081           0 :       if (_nonlocal_cm[_current_nl_sys->number()](ivar, jvar) != 0)
    2082             :       {
    2083           0 :         MooseVariableFEBase & jv = _current_nl_sys->getVariable(tid, jvar);
    2084           0 :         _displaced_problem->addJacobianBlockNonlocal(
    2085             :             jacobian, ivar, jvar, dof_map, dof_indices, jv.allDofIndices(), tags, tid);
    2086             :       }
    2087             :   }
    2088       81172 : }
    2089             : 
    2090             : void
    2091        1344 : FEProblemBase::addJacobianNeighbor(SparseMatrix<Number> & jacobian,
    2092             :                                    unsigned int ivar,
    2093             :                                    unsigned int jvar,
    2094             :                                    const DofMap & dof_map,
    2095             :                                    std::vector<dof_id_type> & dof_indices,
    2096             :                                    std::vector<dof_id_type> & neighbor_dof_indices,
    2097             :                                    const std::set<TagID> & tags,
    2098             :                                    const THREAD_ID tid)
    2099             : {
    2100        2688 :   _assembly[tid][_current_nl_sys->number()]->addJacobianNeighborTags(jacobian,
    2101             :                                                                      ivar,
    2102             :                                                                      jvar,
    2103             :                                                                      dof_map,
    2104             :                                                                      dof_indices,
    2105             :                                                                      neighbor_dof_indices,
    2106        1344 :                                                                      Assembly::GlobalDataKey{},
    2107             :                                                                      tags);
    2108        1344 :   if (_displaced_problem)
    2109           0 :     _displaced_problem->addJacobianNeighbor(
    2110             :         jacobian, ivar, jvar, dof_map, dof_indices, neighbor_dof_indices, tags, tid);
    2111        1344 : }
    2112             : 
    2113             : void
    2114   146074812 : FEProblemBase::prepareShapes(unsigned int var, const THREAD_ID tid)
    2115             : {
    2116   146074812 :   _assembly[tid][_current_nl_sys->number()]->copyShapes(var);
    2117   146074812 : }
    2118             : 
    2119             : void
    2120      722841 : FEProblemBase::prepareFaceShapes(unsigned int var, const THREAD_ID tid)
    2121             : {
    2122      722841 :   _assembly[tid][_current_nl_sys->number()]->copyFaceShapes(var);
    2123      722841 : }
    2124             : 
    2125             : void
    2126      217901 : FEProblemBase::prepareNeighborShapes(unsigned int var, const THREAD_ID tid)
    2127             : {
    2128      217901 :   _assembly[tid][_current_nl_sys->number()]->copyNeighborShapes(var);
    2129      217901 : }
    2130             : 
    2131             : void
    2132      965942 : FEProblemBase::addGhostedElem(dof_id_type elem_id)
    2133             : {
    2134      965942 :   if (_mesh.elemPtr(elem_id)->processor_id() != processor_id())
    2135      205714 :     _ghosted_elems.insert(elem_id);
    2136      965942 : }
    2137             : 
    2138             : void
    2139       31700 : FEProblemBase::addGhostedBoundary(BoundaryID boundary_id)
    2140             : {
    2141       31700 :   _mesh.addGhostedBoundary(boundary_id);
    2142       31700 :   if (_displaced_problem)
    2143       28798 :     _displaced_mesh->addGhostedBoundary(boundary_id);
    2144       31700 : }
    2145             : 
    2146             : void
    2147       70308 : FEProblemBase::ghostGhostedBoundaries()
    2148             : {
    2149      351540 :   TIME_SECTION("ghostGhostedBoundaries", 3, "Ghosting Ghosted Boundaries");
    2150             : 
    2151       70308 :   _mesh.ghostGhostedBoundaries();
    2152             : 
    2153       70308 :   if (_displaced_problem)
    2154        2879 :     _displaced_mesh->ghostGhostedBoundaries();
    2155       70308 : }
    2156             : 
    2157             : void
    2158           0 : FEProblemBase::sizeZeroes(unsigned int /*size*/, const THREAD_ID /*tid*/)
    2159             : {
    2160           0 :   mooseDoOnce(mooseWarning(
    2161             :       "This function is deprecated and no longer performs any function. Please do not call it."));
    2162           0 : }
    2163             : 
    2164             : bool
    2165      342243 : FEProblemBase::reinitDirac(const Elem * elem, const THREAD_ID tid)
    2166             : {
    2167      342243 :   std::vector<Point> & points = _dirac_kernel_info.getPoints()[elem].first;
    2168             : 
    2169      342243 :   unsigned int n_points = points.size();
    2170             : 
    2171      342243 :   if (n_points)
    2172             :   {
    2173      336731 :     if (n_points > _max_qps)
    2174             :     {
    2175           0 :       _max_qps = n_points;
    2176             : 
    2177             :       /**
    2178             :        * The maximum number of qps can rise if several Dirac points are added to a single element.
    2179             :        * In that case we need to resize the zeros to compensate.
    2180             :        */
    2181           0 :       unsigned int max_qpts = getMaxQps();
    2182           0 :       for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
    2183             :       {
    2184             :         // the highest available order in libMesh is 43
    2185           0 :         _scalar_zero[tid].resize(FORTYTHIRD, 0);
    2186           0 :         _zero[tid].resize(max_qpts, 0);
    2187           0 :         _grad_zero[tid].resize(max_qpts, RealGradient(0.));
    2188           0 :         _second_zero[tid].resize(max_qpts, RealTensor(0.));
    2189           0 :         _vector_zero[tid].resize(max_qpts, RealGradient(0.));
    2190           0 :         _vector_curl_zero[tid].resize(max_qpts, RealGradient(0.));
    2191             :       }
    2192             :     }
    2193             : 
    2194      673462 :     for (const auto i : index_range(_nl))
    2195             :     {
    2196      336731 :       _assembly[tid][i]->reinitAtPhysical(elem, points);
    2197      336731 :       _nl[i]->prepare(tid);
    2198             :     }
    2199      336731 :     _aux->prepare(tid);
    2200             : 
    2201      336731 :     reinitElem(elem, tid);
    2202             :   }
    2203             : 
    2204      342243 :   _assembly[tid][_current_nl_sys->number()]->prepare();
    2205      342243 :   if (_has_nonlocal_coupling)
    2206           0 :     _assembly[tid][_current_nl_sys->number()]->prepareNonlocal();
    2207             : 
    2208      342243 :   bool have_points = n_points > 0;
    2209      342243 :   if (_displaced_problem && (_reinit_displaced_elem))
    2210             :   {
    2211        5512 :     have_points |= _displaced_problem->reinitDirac(_displaced_mesh->elemPtr(elem->id()), tid);
    2212        5512 :     if (_has_nonlocal_coupling)
    2213           0 :       _displaced_problem->prepareNonlocal(tid);
    2214             :   }
    2215             : 
    2216      342243 :   return have_points;
    2217             : }
    2218             : 
    2219             : void
    2220   431505650 : FEProblemBase::reinitElem(const Elem * elem, const THREAD_ID tid)
    2221             : {
    2222   865810260 :   for (auto & sys : _solver_systems)
    2223   434304610 :     sys->reinitElem(elem, tid);
    2224   431505650 :   _aux->reinitElem(elem, tid);
    2225             : 
    2226   431505650 :   if (_displaced_problem && _reinit_displaced_elem)
    2227     4961598 :     _displaced_problem->reinitElem(_displaced_mesh->elemPtr(elem->id()), tid);
    2228   431505650 : }
    2229             : 
    2230             : void
    2231       53607 : FEProblemBase::reinitElemPhys(const Elem * const elem,
    2232             :                               const std::vector<Point> & phys_points_in_elem,
    2233             :                               const THREAD_ID tid)
    2234             : {
    2235             :   mooseAssert(_mesh.queryElemPtr(elem->id()) == elem,
    2236             :               "Are you calling this method with a displaced mesh element?");
    2237             : 
    2238      107214 :   for (const auto i : index_range(_solver_systems))
    2239             :   {
    2240       53607 :     _assembly[tid][i]->reinitAtPhysical(elem, phys_points_in_elem);
    2241       53607 :     _solver_systems[i]->prepare(tid);
    2242       53607 :     _assembly[tid][i]->prepare();
    2243       53607 :     if (_has_nonlocal_coupling)
    2244           0 :       _assembly[tid][i]->prepareNonlocal();
    2245             :   }
    2246       53607 :   _aux->prepare(tid);
    2247             : 
    2248       53607 :   reinitElem(elem, tid);
    2249       53607 : }
    2250             : 
    2251             : void
    2252           0 : FEProblemBase::reinitElemFace(const Elem * const elem,
    2253             :                               const unsigned int side,
    2254             :                               const BoundaryID,
    2255             :                               const THREAD_ID tid)
    2256             : {
    2257           0 :   mooseDeprecated(
    2258             :       "reinitElemFace with a BoundaryID argument is deprecated because the boundary id was never "
    2259             :       "used. Please call reinitElemFace without the BoundaryID argument instead");
    2260             : 
    2261           0 :   reinitElemFace(elem, side, tid);
    2262           0 : }
    2263             : 
    2264             : void
    2265     8556469 : FEProblemBase::reinitElemFace(const Elem * const elem, const unsigned int side, const THREAD_ID tid)
    2266             : {
    2267    17113343 :   for (const auto i : index_range(_solver_systems))
    2268             :   {
    2269     8556874 :     _assembly[tid][i]->reinit(elem, side);
    2270     8556874 :     _solver_systems[i]->reinitElemFace(elem, side, tid);
    2271             :   }
    2272     8556469 :   _aux->reinitElemFace(elem, side, tid);
    2273             : 
    2274     8556469 :   if (_displaced_problem && _reinit_displaced_face)
    2275       97294 :     _displaced_problem->reinitElemFace(_displaced_mesh->elemPtr(elem->id()), side, tid);
    2276     8556469 : }
    2277             : 
    2278             : void
    2279      300210 : FEProblemBase::reinitLowerDElem(const Elem * lower_d_elem,
    2280             :                                 const THREAD_ID tid,
    2281             :                                 const std::vector<Point> * const pts,
    2282             :                                 const std::vector<Real> * const weights)
    2283             : {
    2284      300210 :   SubProblem::reinitLowerDElem(lower_d_elem, tid, pts, weights);
    2285             : 
    2286      300210 :   if (_displaced_problem && _displaced_mesh)
    2287        1080 :     _displaced_problem->reinitLowerDElem(
    2288        1080 :         _displaced_mesh->elemPtr(lower_d_elem->id()), tid, pts, weights);
    2289      300210 : }
    2290             : 
    2291             : void
    2292    29242958 : FEProblemBase::reinitNode(const Node * node, const THREAD_ID tid)
    2293             : {
    2294    29242958 :   if (_displaced_problem && _reinit_displaced_elem)
    2295     1122418 :     _displaced_problem->reinitNode(&_displaced_mesh->nodeRef(node->id()), tid);
    2296             : 
    2297    58489192 :   for (const auto i : index_range(_nl))
    2298             :   {
    2299    29246234 :     _assembly[tid][i]->reinit(node);
    2300    29246234 :     _nl[i]->reinitNode(node, tid);
    2301             :   }
    2302    29242958 :   _aux->reinitNode(node, tid);
    2303    29242958 : }
    2304             : 
    2305             : void
    2306    71962297 : FEProblemBase::reinitNodeFace(const Node * node, BoundaryID bnd_id, const THREAD_ID tid)
    2307             : {
    2308    71962297 :   if (_displaced_problem && _reinit_displaced_face)
    2309     3818746 :     _displaced_problem->reinitNodeFace(&_displaced_mesh->nodeRef(node->id()), bnd_id, tid);
    2310             : 
    2311   144802002 :   for (const auto i : index_range(_nl))
    2312             :   {
    2313    72839705 :     _assembly[tid][i]->reinit(node);
    2314    72839705 :     _nl[i]->reinitNodeFace(node, bnd_id, tid);
    2315             :   }
    2316    71962297 :   _aux->reinitNodeFace(node, bnd_id, tid);
    2317    71962297 : }
    2318             : 
    2319             : void
    2320        6813 : FEProblemBase::reinitNodes(const std::vector<dof_id_type> & nodes, const THREAD_ID tid)
    2321             : {
    2322        6813 :   if (_displaced_problem && _reinit_displaced_elem)
    2323           0 :     _displaced_problem->reinitNodes(nodes, tid);
    2324             : 
    2325       13626 :   for (auto & nl : _nl)
    2326        6813 :     nl->reinitNodes(nodes, tid);
    2327        6813 :   _aux->reinitNodes(nodes, tid);
    2328        6813 : }
    2329             : 
    2330             : void
    2331         723 : FEProblemBase::reinitNodesNeighbor(const std::vector<dof_id_type> & nodes, const THREAD_ID tid)
    2332             : {
    2333         723 :   if (_displaced_problem && _reinit_displaced_elem)
    2334           0 :     _displaced_problem->reinitNodesNeighbor(nodes, tid);
    2335             : 
    2336        1446 :   for (auto & nl : _nl)
    2337         723 :     nl->reinitNodesNeighbor(nodes, tid);
    2338         723 :   _aux->reinitNodesNeighbor(nodes, tid);
    2339         723 : }
    2340             : 
    2341             : void
    2342     9143069 : FEProblemBase::reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering /*=false*/)
    2343             : {
    2344    45715345 :   TIME_SECTION("reinitScalars", 3, "Reinitializing Scalar Variables");
    2345             : 
    2346     9143069 :   if (_displaced_problem && _reinit_displaced_elem)
    2347      124637 :     _displaced_problem->reinitScalars(tid, reinit_for_derivative_reordering);
    2348             : 
    2349    18530877 :   for (auto & nl : _nl)
    2350     9387808 :     nl->reinitScalars(tid, reinit_for_derivative_reordering);
    2351     9143069 :   _aux->reinitScalars(tid, reinit_for_derivative_reordering);
    2352             : 
    2353             :   // This is called outside of residual/Jacobian call-backs
    2354    18537681 :   for (auto & assembly : _assembly[tid])
    2355     9394612 :     assembly->prepareScalar();
    2356     9143069 : }
    2357             : 
    2358             : void
    2359      210604 : FEProblemBase::reinitOffDiagScalars(const THREAD_ID tid)
    2360             : {
    2361      210604 :   _assembly[tid][_current_nl_sys->number()]->prepareOffDiagScalar();
    2362      210604 :   if (_displaced_problem)
    2363          90 :     _displaced_problem->reinitOffDiagScalars(tid);
    2364      210604 : }
    2365             : 
    2366             : void
    2367     4228377 : FEProblemBase::reinitNeighbor(const Elem * elem, unsigned int side, const THREAD_ID tid)
    2368             : {
    2369     4228377 :   setNeighborSubdomainID(elem, side, tid);
    2370             : 
    2371     4228377 :   const Elem * neighbor = elem->neighbor_ptr(side);
    2372     4228377 :   unsigned int neighbor_side = neighbor->which_neighbor_am_i(elem);
    2373             : 
    2374     8456784 :   for (const auto i : index_range(_nl))
    2375             :   {
    2376     4228407 :     _assembly[tid][i]->reinitElemAndNeighbor(elem, side, neighbor, neighbor_side);
    2377     4228407 :     _nl[i]->prepareNeighbor(tid);
    2378             :     // Called during stateful material property evaluation outside of solve
    2379     4228407 :     _assembly[tid][i]->prepareNeighbor();
    2380             :   }
    2381     4228377 :   _aux->prepareNeighbor(tid);
    2382             : 
    2383     8456784 :   for (auto & nl : _nl)
    2384             :   {
    2385     4228407 :     nl->reinitElemFace(elem, side, tid);
    2386     4228407 :     nl->reinitNeighborFace(neighbor, neighbor_side, tid);
    2387             :   }
    2388     4228377 :   _aux->reinitElemFace(elem, side, tid);
    2389     4228377 :   _aux->reinitNeighborFace(neighbor, neighbor_side, tid);
    2390             : 
    2391     4228377 :   if (_displaced_problem && _reinit_displaced_neighbor)
    2392             :   {
    2393             :     // There are cases like for cohesive zone modeling without significant sliding where we cannot
    2394             :     // use FEInterface::inverse_map in Assembly::reinitElemAndNeighbor in the displaced problem
    2395             :     // because the physical points coming from the element don't actually lie on the neighbor.
    2396             :     // Moreover, what's the point of doing another physical point inversion in other cases? We only
    2397             :     // care about the reference points which we can just take from the undisplaced computation
    2398       71886 :     const auto & displaced_ref_pts = _assembly[tid][0]->qRuleNeighbor()->get_points();
    2399             : 
    2400       71886 :     _displaced_problem->reinitNeighbor(
    2401       71886 :         _displaced_mesh->elemPtr(elem->id()), side, tid, &displaced_ref_pts);
    2402             :   }
    2403     4228377 : }
    2404             : 
    2405             : void
    2406     2433898 : FEProblemBase::reinitElemNeighborAndLowerD(const Elem * elem,
    2407             :                                            unsigned int side,
    2408             :                                            const THREAD_ID tid)
    2409             : {
    2410     2433898 :   reinitNeighbor(elem, side, tid);
    2411             : 
    2412     2433898 :   const Elem * lower_d_elem = _mesh.getLowerDElem(elem, side);
    2413     2433898 :   if (lower_d_elem && _mesh.interiorLowerDBlocks().count(lower_d_elem->subdomain_id()) > 0)
    2414       11610 :     reinitLowerDElem(lower_d_elem, tid);
    2415             :   else
    2416             :   {
    2417             :     // with mesh refinement, lower-dimensional element might be defined on neighbor side
    2418     2422288 :     auto & neighbor = _assembly[tid][0]->neighbor();
    2419     2422288 :     auto & neighbor_side = _assembly[tid][0]->neighborSide();
    2420     2422288 :     const Elem * lower_d_elem_neighbor = _mesh.getLowerDElem(neighbor, neighbor_side);
    2421     2422288 :     if (lower_d_elem_neighbor &&
    2422     2422288 :         _mesh.interiorLowerDBlocks().count(lower_d_elem_neighbor->subdomain_id()) > 0)
    2423             :     {
    2424           0 :       auto qps = _assembly[tid][0]->qPointsFaceNeighbor().stdVector();
    2425           0 :       std::vector<Point> reference_points;
    2426           0 :       FEMap::inverse_map(
    2427           0 :           lower_d_elem_neighbor->dim(), lower_d_elem_neighbor, qps, reference_points);
    2428           0 :       reinitLowerDElem(lower_d_elem_neighbor, tid, &reference_points);
    2429           0 :     }
    2430             :   }
    2431             : 
    2432     2433898 :   if (_displaced_problem && (_reinit_displaced_face || _reinit_displaced_neighbor))
    2433       71820 :     _displaced_problem->reinitElemNeighborAndLowerD(
    2434       71820 :         _displaced_mesh->elemPtr(elem->id()), side, tid);
    2435     2433898 : }
    2436             : 
    2437             : void
    2438      108178 : FEProblemBase::reinitNeighborPhys(const Elem * neighbor,
    2439             :                                   unsigned int neighbor_side,
    2440             :                                   const std::vector<Point> & physical_points,
    2441             :                                   const THREAD_ID tid)
    2442             : {
    2443             :   mooseAssert(_mesh.queryElemPtr(neighbor->id()) == neighbor,
    2444             :               "Are you calling this method with a displaced mesh element?");
    2445             : 
    2446      216356 :   for (const auto i : index_range(_nl))
    2447             :   {
    2448             :     // Reinits shape the functions at the physical points
    2449      108178 :     _assembly[tid][i]->reinitNeighborAtPhysical(neighbor, neighbor_side, physical_points);
    2450             : 
    2451             :     // Sets the neighbor dof indices
    2452      108178 :     _nl[i]->prepareNeighbor(tid);
    2453             :   }
    2454      108178 :   _aux->prepareNeighbor(tid);
    2455             : 
    2456             :   // Resizes Re and Ke
    2457      108178 :   _assembly[tid][_current_nl_sys->number()]->prepareNeighbor();
    2458             : 
    2459             :   // Compute the values of each variable at the points
    2460      216356 :   for (auto & nl : _nl)
    2461      108178 :     nl->reinitNeighborFace(neighbor, neighbor_side, tid);
    2462      108178 :   _aux->reinitNeighborFace(neighbor, neighbor_side, tid);
    2463      108178 : }
    2464             : 
    2465             : void
    2466       22720 : FEProblemBase::reinitNeighborPhys(const Elem * neighbor,
    2467             :                                   const std::vector<Point> & physical_points,
    2468             :                                   const THREAD_ID tid)
    2469             : {
    2470             :   mooseAssert(_mesh.queryElemPtr(neighbor->id()) == neighbor,
    2471             :               "Are you calling this method with a displaced mesh element?");
    2472             : 
    2473       45440 :   for (const auto i : index_range(_nl))
    2474             :   {
    2475             :     // Reinits shape the functions at the physical points
    2476       22720 :     _assembly[tid][i]->reinitNeighborAtPhysical(neighbor, physical_points);
    2477             : 
    2478             :     // Sets the neighbor dof indices
    2479       22720 :     _nl[i]->prepareNeighbor(tid);
    2480             :   }
    2481       22720 :   _aux->prepareNeighbor(tid);
    2482             : 
    2483             :   // Resizes Re and Ke
    2484       22720 :   _assembly[tid][_current_nl_sys->number()]->prepareNeighbor();
    2485             : 
    2486             :   // Compute the values of each variable at the points
    2487       45440 :   for (auto & nl : _nl)
    2488       22720 :     nl->reinitNeighbor(neighbor, tid);
    2489       22720 :   _aux->reinitNeighbor(neighbor, tid);
    2490       22720 : }
    2491             : 
    2492             : void
    2493       38812 : FEProblemBase::getDiracElements(std::set<const Elem *> & elems)
    2494             : {
    2495             :   // First add in the undisplaced elements
    2496       38812 :   elems = _dirac_kernel_info.getElements();
    2497             : 
    2498       38812 :   if (_displaced_problem)
    2499             :   {
    2500        2539 :     std::set<const Elem *> displaced_elements;
    2501        2539 :     _displaced_problem->getDiracElements(displaced_elements);
    2502             : 
    2503             :     { // Use the ids from the displaced elements to get the undisplaced elements
    2504             :       // and add them to the list
    2505        8051 :       for (const auto & elem : displaced_elements)
    2506        5512 :         elems.insert(_mesh.elemPtr(elem->id()));
    2507             :     }
    2508        2539 :   }
    2509       38812 : }
    2510             : 
    2511             : void
    2512     3866843 : FEProblemBase::clearDiracInfo()
    2513             : {
    2514     3866843 :   _dirac_kernel_info.clearPoints();
    2515             : 
    2516     3866843 :   if (_displaced_problem)
    2517      159253 :     _displaced_problem->clearDiracInfo();
    2518     3866843 : }
    2519             : 
    2520             : void
    2521     6065414 : FEProblemBase::subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
    2522             : {
    2523     6065414 :   _all_materials.subdomainSetup(subdomain, tid);
    2524             :   // Call the subdomain methods of the output system, these are not threaded so only call it once
    2525     6065414 :   if (tid == 0)
    2526     5616004 :     _app.getOutputWarehouse().subdomainSetup();
    2527             : 
    2528    12282358 :   for (auto & nl : _nl)
    2529     6216944 :     nl->subdomainSetup(subdomain, tid);
    2530             : 
    2531             :   // FIXME: call displaced_problem->subdomainSetup() ?
    2532             :   //        When adding possibility with materials being evaluated on displaced mesh
    2533     6065414 : }
    2534             : 
    2535             : void
    2536    18307316 : FEProblemBase::neighborSubdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
    2537             : {
    2538    18307316 :   _all_materials.neighborSubdomainSetup(subdomain, tid);
    2539    18307316 : }
    2540             : 
    2541             : void
    2542       53284 : FEProblemBase::addFunction(const std::string & type,
    2543             :                            const std::string & name,
    2544             :                            InputParameters & parameters)
    2545             : {
    2546             :   parallel_object_only();
    2547             : 
    2548      106568 :   parameters.set<SubProblem *>("_subproblem") = this;
    2549             : 
    2550      110515 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    2551             :   {
    2552       57368 :     std::shared_ptr<Function> func = _factory.create<Function>(type, name, parameters, tid);
    2553       57231 :     logAdd("Function", name, type, parameters);
    2554       57231 :     _functions.addObject(func, tid);
    2555             : 
    2556       57231 :     if (auto * const functor = dynamic_cast<Moose::FunctorBase<Real> *>(func.get()))
    2557             :     {
    2558       57231 :       this->addFunctor(name, *functor, tid);
    2559       57231 :       if (_displaced_problem)
    2560        1953 :         _displaced_problem->addFunctor(name, *functor, tid);
    2561             :     }
    2562             :     else
    2563           0 :       mooseError("Unrecognized function functor type");
    2564       57231 :   }
    2565       53147 : }
    2566             : 
    2567             : void
    2568      160040 : FEProblemBase::addConvergence(const std::string & type,
    2569             :                               const std::string & name,
    2570             :                               InputParameters & parameters)
    2571             : {
    2572             :   parallel_object_only();
    2573             : 
    2574      335635 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    2575             :   {
    2576      175631 :     std::shared_ptr<Convergence> conv = _factory.create<Convergence>(type, name, parameters, tid);
    2577      175595 :     _convergences.addObject(conv, tid);
    2578      175595 :   }
    2579      160004 : }
    2580             : 
    2581             : void
    2582       63218 : FEProblemBase::addDefaultNonlinearConvergence(const InputParameters & params_to_apply)
    2583             : {
    2584       63218 :   const std::string class_name = "DefaultNonlinearConvergence";
    2585       63218 :   InputParameters params = _factory.getValidParams(class_name);
    2586       63218 :   params.applyParameters(params_to_apply);
    2587       63218 :   params.applyParameters(parameters());
    2588       63218 :   params.set<bool>("added_as_default") = true;
    2589      125375 :   for (const auto & conv_name : getNonlinearConvergenceNames())
    2590       62157 :     addConvergence(class_name, conv_name, params);
    2591       63218 : }
    2592             : 
    2593             : void
    2594       64045 : FEProblemBase::addDefaultMultiAppFixedPointConvergence(const InputParameters & params_to_apply)
    2595             : {
    2596       64045 :   const std::string class_name = "DefaultMultiAppFixedPointConvergence";
    2597       64045 :   InputParameters params = _factory.getValidParams(class_name);
    2598       64045 :   params.applyParameters(params_to_apply);
    2599       64045 :   params.applyParameters(parameters());
    2600       64045 :   params.set<bool>("added_as_default") = true;
    2601       64045 :   addConvergence(class_name, getMultiAppFixedPointConvergenceName(), params);
    2602       64033 : }
    2603             : 
    2604             : void
    2605       31898 : FEProblemBase::addDefaultSteadyStateConvergence(const InputParameters & params_to_apply)
    2606             : {
    2607       31898 :   const std::string class_name = "DefaultSteadyStateConvergence";
    2608       31898 :   InputParameters params = _factory.getValidParams(class_name);
    2609       31898 :   params.applyParameters(params_to_apply);
    2610       31898 :   params.applyParameters(parameters());
    2611       31898 :   params.set<bool>("added_as_default") = true;
    2612       31898 :   addConvergence(class_name, getSteadyStateConvergenceName(), params);
    2613       31898 : }
    2614             : 
    2615             : bool
    2616       89046 : FEProblemBase::hasFunction(const std::string & name, const THREAD_ID tid)
    2617             : {
    2618       89046 :   return _functions.hasActiveObject(name, tid);
    2619             : }
    2620             : 
    2621             : Function &
    2622       64936 : FEProblemBase::getFunction(const std::string & name, const THREAD_ID tid)
    2623             : {
    2624             :   // This thread lock is necessary since this method will create functions
    2625             :   // for all threads if one is missing.
    2626       64936 :   Threads::spin_mutex::scoped_lock lock(get_function_mutex);
    2627             : 
    2628       64936 :   if (!hasFunction(name, tid))
    2629             :   {
    2630             :     // If we didn't find a function, it might be a default function, attempt to construct one now
    2631       20250 :     std::istringstream ss(name);
    2632             :     Real real_value;
    2633             : 
    2634             :     // First see if it's just a constant. If it is, build a ConstantFunction
    2635       20250 :     if (ss >> real_value && ss.eof())
    2636             :     {
    2637       12984 :       InputParameters params = _factory.getValidParams("ConstantFunction");
    2638       12984 :       params.set<Real>("value") = real_value;
    2639       19476 :       addFunction("ConstantFunction", ss.str(), params);
    2640        6492 :     }
    2641             :     else
    2642             :     {
    2643       13758 :       FunctionParserBase<Real> fp;
    2644       13758 :       std::string vars = "x,y,z,t,NaN,pi,e";
    2645       13758 :       if (fp.Parse(name, vars) == -1) // -1 for success
    2646             :       {
    2647             :         // It parsed ok, so build a MooseParsedFunction
    2648       41262 :         InputParameters params = _factory.getValidParams("ParsedFunction");
    2649       13754 :         params.set<std::string>("expression") = name;
    2650       27508 :         addFunction("ParsedFunction", name, params);
    2651       13754 :       }
    2652       13758 :     }
    2653             : 
    2654             :     // Try once more
    2655       20250 :     if (!hasFunction(name, tid))
    2656           4 :       mooseError("Unable to find function " + name);
    2657       20246 :   }
    2658             : 
    2659       64932 :   auto * const ret = dynamic_cast<Function *>(_functions.getActiveObject(name, tid).get());
    2660       64932 :   if (!ret)
    2661           0 :     mooseError("No function named ", name, " of appropriate type");
    2662             : 
    2663       64932 :   return *ret;
    2664       64932 : }
    2665             : 
    2666             : bool
    2667      221754 : FEProblemBase::hasConvergence(const std::string & name, const THREAD_ID tid) const
    2668             : {
    2669      221754 :   return _convergences.hasActiveObject(name, tid);
    2670             : }
    2671             : 
    2672             : Convergence &
    2673     1231891 : FEProblemBase::getConvergence(const std::string & name, const THREAD_ID tid) const
    2674             : {
    2675     1231891 :   auto * const ret = dynamic_cast<Convergence *>(_convergences.getActiveObject(name, tid).get());
    2676     1231891 :   if (!ret)
    2677           0 :     mooseError("The Convergence object '", name, "' does not exist.");
    2678             : 
    2679     1231891 :   return *ret;
    2680             : }
    2681             : 
    2682             : const std::vector<std::shared_ptr<Convergence>> &
    2683      210470 : FEProblemBase::getConvergenceObjects(const THREAD_ID tid) const
    2684             : {
    2685      210470 :   return _convergences.getActiveObjects(tid);
    2686             : }
    2687             : 
    2688             : void
    2689         770 : FEProblemBase::addMeshDivision(const std::string & type,
    2690             :                                const std::string & name,
    2691             :                                InputParameters & parameters)
    2692             : {
    2693             :   parallel_object_only();
    2694        1540 :   parameters.set<FEProblemBase *>("_fe_problem_base") = this;
    2695        1540 :   parameters.set<SubProblem *>("_subproblem") = this;
    2696        1623 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    2697             :   {
    2698         865 :     std::shared_ptr<MeshDivision> func = _factory.create<MeshDivision>(type, name, parameters, tid);
    2699         853 :     _mesh_divisions.addObject(func, tid);
    2700         853 :   }
    2701         758 : }
    2702             : 
    2703             : MeshDivision &
    2704        1665 : FEProblemBase::getMeshDivision(const std::string & name, const THREAD_ID tid) const
    2705             : {
    2706        1665 :   auto * const ret = dynamic_cast<MeshDivision *>(_mesh_divisions.getActiveObject(name, tid).get());
    2707        1665 :   if (!ret)
    2708           0 :     mooseError("No MeshDivision object named ", name, " of appropriate type");
    2709        1665 :   return *ret;
    2710             : }
    2711             : 
    2712             : void
    2713           0 : FEProblemBase::lineSearch()
    2714             : {
    2715           0 :   _line_search->lineSearch();
    2716           0 : }
    2717             : 
    2718             : NonlinearSystem &
    2719           0 : FEProblemBase::getNonlinearSystem(const unsigned int sys_num)
    2720             : {
    2721           0 :   mooseDeprecated("FEProblemBase::getNonlinearSystem() is deprecated, please use "
    2722             :                   "FEProblemBase::getNonlinearSystemBase() \n");
    2723             : 
    2724             :   mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
    2725           0 :   auto nl_sys = std::dynamic_pointer_cast<NonlinearSystem>(_nl[sys_num]);
    2726             : 
    2727           0 :   if (!nl_sys)
    2728           0 :     mooseError("This is not a NonlinearSystem");
    2729             : 
    2730           0 :   return *nl_sys;
    2731           0 : }
    2732             : 
    2733             : void
    2734           0 : FEProblemBase::addDistribution(const std::string & type,
    2735             :                                const std::string & name,
    2736             :                                InputParameters & parameters)
    2737             : {
    2738           0 :   parameters.set<std::string>("type") = type;
    2739           0 :   addObject<Distribution>(type, name, parameters, /* threaded = */ false);
    2740           0 : }
    2741             : 
    2742             : Distribution &
    2743           0 : FEProblemBase::getDistribution(const std::string & name)
    2744             : {
    2745           0 :   std::vector<Distribution *> objs;
    2746           0 :   theWarehouse()
    2747           0 :       .query()
    2748           0 :       .condition<AttribSystem>("Distribution")
    2749           0 :       .condition<AttribName>(name)
    2750           0 :       .queryInto(objs);
    2751           0 :   if (objs.empty())
    2752           0 :     mooseError("Unable to find Distribution with name '" + name + "'");
    2753           0 :   return *(objs[0]);
    2754           0 : }
    2755             : 
    2756             : void
    2757         354 : FEProblemBase::addSampler(const std::string & type,
    2758             :                           const std::string & name,
    2759             :                           InputParameters & parameters)
    2760             : {
    2761         354 :   const auto samplers = addObject<Sampler>(type, name, parameters);
    2762         722 :   for (auto & sampler : samplers)
    2763         380 :     sampler->init();
    2764         342 : }
    2765             : 
    2766             : Sampler &
    2767         342 : FEProblemBase::getSampler(const std::string & name, const THREAD_ID tid)
    2768             : {
    2769         342 :   std::vector<Sampler *> objs;
    2770         342 :   theWarehouse()
    2771         684 :       .query()
    2772         342 :       .condition<AttribSystem>("Sampler")
    2773         342 :       .condition<AttribThread>(tid)
    2774         342 :       .condition<AttribName>(name)
    2775         342 :       .queryInto(objs);
    2776         342 :   if (objs.empty())
    2777           0 :     mooseError(
    2778           0 :         "Unable to find Sampler with name '" + name +
    2779             :         "', if you are attempting to access this object in the constructor of another object then "
    2780             :         "the object being retrieved must occur prior to the caller within the input file.");
    2781         684 :   return *(objs[0]);
    2782         342 : }
    2783             : 
    2784             : bool
    2785      161695 : FEProblemBase::duplicateVariableCheck(const std::string & var_name,
    2786             :                                       const FEType & type,
    2787             :                                       bool is_aux,
    2788             :                                       const std::set<SubdomainID> * const active_subdomains)
    2789             : {
    2790      161695 :   std::set<SubdomainID> subdomainIDs;
    2791      161695 :   if (active_subdomains->size() == 0)
    2792             :   {
    2793      152925 :     const auto subdomains = _mesh.meshSubdomains();
    2794      152925 :     subdomainIDs.insert(subdomains.begin(), subdomains.end());
    2795      152925 :   }
    2796             :   else
    2797        8770 :     subdomainIDs.insert(active_subdomains->begin(), active_subdomains->end());
    2798             : 
    2799      324131 :   for (auto & sys : _solver_systems)
    2800             :   {
    2801      162452 :     SystemBase * curr_sys_ptr = sys.get();
    2802      162452 :     SystemBase * other_sys_ptr = _aux.get();
    2803      162452 :     std::string error_prefix = "";
    2804      162452 :     if (is_aux)
    2805             :     {
    2806       96684 :       curr_sys_ptr = _aux.get();
    2807       96684 :       other_sys_ptr = sys.get();
    2808       96684 :       error_prefix = "aux";
    2809             :     }
    2810             : 
    2811      162452 :     if (other_sys_ptr->hasVariable(var_name))
    2812           4 :       mooseError("Cannot have an auxiliary variable and a solver variable with the same name: ",
    2813             :                  var_name);
    2814             : 
    2815      162448 :     if (curr_sys_ptr->hasVariable(var_name))
    2816             :     {
    2817             :       const Variable & var =
    2818          12 :           curr_sys_ptr->system().variable(curr_sys_ptr->system().variable_number(var_name));
    2819             : 
    2820             :       // variable type
    2821          12 :       if (var.type() != type)
    2822             :       {
    2823          16 :         const auto stringifyType = [](FEType t)
    2824          16 :         { return Moose::stringify(t.family) + " of order " + Moose::stringify(t.order); };
    2825             : 
    2826           8 :         mooseError("Mismatching types are specified for ",
    2827             :                    error_prefix,
    2828             :                    "variable with name '",
    2829             :                    var_name,
    2830             :                    "': '",
    2831           8 :                    stringifyType(var.type()),
    2832             :                    "' and '",
    2833           8 :                    stringifyType(type),
    2834             :                    "'");
    2835             :       }
    2836             : 
    2837             :       // block-restriction
    2838           4 :       if (!(active_subdomains->size() == 0 && var.active_subdomains().size() == 0))
    2839             :       {
    2840           4 :         const auto varActiveSubdomains = var.active_subdomains();
    2841           4 :         std::set<SubdomainID> varSubdomainIDs;
    2842           4 :         if (varActiveSubdomains.size() == 0)
    2843             :         {
    2844           0 :           const auto subdomains = _mesh.meshSubdomains();
    2845           0 :           varSubdomainIDs.insert(subdomains.begin(), subdomains.end());
    2846           0 :         }
    2847             :         else
    2848           4 :           varSubdomainIDs.insert(varActiveSubdomains.begin(), varActiveSubdomains.end());
    2849             : 
    2850             :         // Is subdomainIDs a subset of varSubdomainIDs? With this we allow the case that the newly
    2851             :         // requested block restriction is only a subset of the existing one.
    2852           4 :         const auto isSubset = std::includes(varSubdomainIDs.begin(),
    2853             :                                             varSubdomainIDs.end(),
    2854             :                                             subdomainIDs.begin(),
    2855             :                                             subdomainIDs.end());
    2856             : 
    2857           4 :         if (!isSubset)
    2858             :         {
    2859             :           // helper function: make a string from a set of subdomain ids
    2860           8 :           const auto stringifySubdomains = [this](std::set<SubdomainID> subdomainIDs)
    2861             :           {
    2862           8 :             std::stringstream s;
    2863          20 :             for (auto const i : subdomainIDs)
    2864             :             {
    2865             :               // do we need to insert a comma?
    2866          12 :               if (s.tellp() != 0)
    2867           4 :                 s << ", ";
    2868             : 
    2869             :               // insert subdomain name and id -or- only the id (if no name is given)
    2870          12 :               const auto subdomainName = _mesh.getSubdomainName(i);
    2871          12 :               if (subdomainName.empty())
    2872          12 :                 s << i;
    2873             :               else
    2874           0 :                 s << subdomainName << " (" << i << ")";
    2875          12 :             }
    2876          16 :             return s.str();
    2877           8 :           };
    2878             : 
    2879           8 :           const std::string msg = "Mismatching block-restrictions are specified for " +
    2880           8 :                                   error_prefix + "variable with name '" + var_name + "': {" +
    2881          16 :                                   stringifySubdomains(varSubdomainIDs) + "} and {" +
    2882          12 :                                   stringifySubdomains(subdomainIDs) + "}";
    2883             : 
    2884           4 :           mooseError(msg);
    2885           0 :         }
    2886           0 :       }
    2887             : 
    2888           0 :       return true;
    2889             :     }
    2890      162436 :   }
    2891             : 
    2892      161679 :   return false;
    2893      161679 : }
    2894             : 
    2895             : void
    2896       65167 : FEProblemBase::addVariable(const std::string & var_type,
    2897             :                            const std::string & var_name,
    2898             :                            InputParameters & params)
    2899             : {
    2900             :   parallel_object_only();
    2901             : 
    2902       65167 :   const auto order = Utility::string_to_enum<Order>(params.get<MooseEnum>("order"));
    2903       65167 :   const auto family = Utility::string_to_enum<FEFamily>(params.get<MooseEnum>("family"));
    2904       65167 :   const auto fe_type = FEType(order, family);
    2905             : 
    2906             :   const auto active_subdomains_vector =
    2907       65167 :       _mesh.getSubdomainIDs(params.get<std::vector<SubdomainName>>("block"));
    2908             :   const std::set<SubdomainID> active_subdomains(active_subdomains_vector.begin(),
    2909       65167 :                                                 active_subdomains_vector.end());
    2910             : 
    2911       65167 :   if (duplicateVariableCheck(var_name, fe_type, /* is_aux = */ false, &active_subdomains))
    2912           0 :     return;
    2913             : 
    2914      195489 :   params.set<FEProblemBase *>("_fe_problem_base") = this;
    2915       65163 :   params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_SOLVER;
    2916       65163 :   SolverSystemName sys_name = params.get<SolverSystemName>("solver_sys");
    2917             : 
    2918       65163 :   const auto solver_system_number = solverSysNum(sys_name);
    2919       65163 :   logAdd("Variable", var_name, var_type, params);
    2920       65163 :   _solver_systems[solver_system_number]->addVariable(var_type, var_name, params);
    2921       65147 :   if (_displaced_problem)
    2922             :     // MooseObjects need to be unique so change the name here
    2923        3839 :     _displaced_problem->addVariable(var_type, var_name, params, solver_system_number);
    2924             : 
    2925       65147 :   _solver_var_to_sys_num[var_name] = solver_system_number;
    2926             : 
    2927       65147 :   markFamilyPRefinement(params);
    2928       65147 : }
    2929             : 
    2930             : std::pair<bool, unsigned int>
    2931     5053436 : FEProblemBase::determineSolverSystem(const std::string & var_name,
    2932             :                                      const bool error_if_not_found) const
    2933             : {
    2934     5053436 :   auto map_it = _solver_var_to_sys_num.find(var_name);
    2935     5053436 :   const bool var_in_sys = map_it != _solver_var_to_sys_num.end();
    2936     5053436 :   if (var_in_sys)
    2937             :     mooseAssert(_solver_systems[map_it->second]->hasVariable(var_name) ||
    2938             :                     _solver_systems[map_it->second]->hasScalarVariable(var_name),
    2939             :                 "If the variable is in our FEProblem solver system map, then it must be in the "
    2940             :                 "solver system we expect");
    2941     3413091 :   else if (error_if_not_found)
    2942             :   {
    2943          42 :     if (_aux->hasVariable(var_name) || _aux->hasScalarVariable(var_name))
    2944          28 :       mooseError("No solver variable named ",
    2945             :                  var_name,
    2946             :                  " found. Did you specify an auxiliary variable when you meant to specify a "
    2947             :                  "solver variable?");
    2948             :     else
    2949          14 :       mooseError("Unknown variable '",
    2950             :                  var_name,
    2951             :                  "'. It does not exist in the solver system(s) or auxiliary system");
    2952             :   }
    2953             : 
    2954    10106788 :   return std::make_pair(var_in_sys, var_in_sys ? map_it->second : libMesh::invalid_uint);
    2955             : }
    2956             : 
    2957             : void
    2958      170506 : FEProblemBase::setResidualObjectParamsAndLog(const std::string & ro_name,
    2959             :                                              const std::string & name,
    2960             :                                              InputParameters & parameters,
    2961             :                                              const unsigned int nl_sys_num,
    2962             :                                              const std::string & base_name,
    2963             :                                              bool & reinit_displaced)
    2964             : {
    2965      170506 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    2966             :   {
    2967        2160 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    2968        2160 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    2969        1080 :     reinit_displaced = true;
    2970             :   }
    2971             :   else
    2972             :   {
    2973      169426 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    2974             :     {
    2975             :       // We allow Kernels to request that they use_displaced_mesh,
    2976             :       // but then be overridden when no displacements variables are
    2977             :       // provided in the Mesh block.  If that happened, update the value
    2978             :       // of use_displaced_mesh appropriately for this Kernel.
    2979         136 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    2980         272 :         parameters.set<bool>("use_displaced_mesh") = false;
    2981             :     }
    2982             : 
    2983      338852 :     parameters.set<SubProblem *>("_subproblem") = this;
    2984      508278 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    2985             :   }
    2986             : 
    2987      170506 :   logAdd(base_name, name, ro_name, parameters);
    2988      170506 : }
    2989             : 
    2990             : void
    2991       68709 : FEProblemBase::setAuxKernelParamsAndLog(const std::string & ak_name,
    2992             :                                         const std::string & name,
    2993             :                                         InputParameters & parameters,
    2994             :                                         const std::string & base_name)
    2995             : {
    2996       68709 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    2997             :   {
    2998       24808 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    2999       24808 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    3000       24808 :     parameters.set<SystemBase *>("_nl_sys") = &_displaced_problem->solverSys(0);
    3001       12404 :     if (!parameters.get<std::vector<BoundaryName>>("boundary").empty())
    3002       11916 :       _reinit_displaced_face = true;
    3003             :     else
    3004         488 :       _reinit_displaced_elem = true;
    3005             :   }
    3006             :   else
    3007             :   {
    3008       56305 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3009             :     {
    3010             :       // We allow AuxKernels to request that they use_displaced_mesh,
    3011             :       // but then be overridden when no displacements variables are
    3012             :       // provided in the Mesh block.  If that happened, update the value
    3013             :       // of use_displaced_mesh appropriately for this AuxKernel.
    3014         863 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3015        1726 :         parameters.set<bool>("use_displaced_mesh") = false;
    3016             :     }
    3017             : 
    3018      112610 :     parameters.set<SubProblem *>("_subproblem") = this;
    3019      112610 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    3020      168915 :     parameters.set<SystemBase *>("_nl_sys") = _solver_systems[0].get();
    3021             :   }
    3022             : 
    3023       68709 :   logAdd(base_name, name, ak_name, parameters);
    3024       68709 : }
    3025             : 
    3026             : void
    3027       83751 : FEProblemBase::addKernel(const std::string & kernel_name,
    3028             :                          const std::string & name,
    3029             :                          InputParameters & parameters)
    3030             : {
    3031             :   parallel_object_only();
    3032      167502 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3033       83735 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3034           0 :     mooseError("You are trying to add a Kernel to a linear variable/system, which is not "
    3035             :                "supported at the moment!");
    3036       83735 :   setResidualObjectParamsAndLog(
    3037       83735 :       kernel_name, name, parameters, nl_sys_num, "Kernel", _reinit_displaced_elem);
    3038             : 
    3039       83735 :   _nl[nl_sys_num]->addKernel(kernel_name, name, parameters);
    3040       83531 : }
    3041             : 
    3042             : void
    3043         808 : FEProblemBase::addHDGKernel(const std::string & kernel_name,
    3044             :                             const std::string & name,
    3045             :                             InputParameters & parameters)
    3046             : {
    3047             :   parallel_object_only();
    3048        1616 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3049         808 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3050           0 :     mooseError("You are trying to add a HDGKernel to a linear variable/system, which is not "
    3051             :                "supported at the moment!");
    3052         808 :   setResidualObjectParamsAndLog(
    3053         808 :       kernel_name, name, parameters, nl_sys_num, "HDGKernel", _reinit_displaced_elem);
    3054             : 
    3055         808 :   _nl[nl_sys_num]->addHDGKernel(kernel_name, name, parameters);
    3056         808 : }
    3057             : 
    3058             : void
    3059         620 : FEProblemBase::addNodalKernel(const std::string & kernel_name,
    3060             :                               const std::string & name,
    3061             :                               InputParameters & parameters)
    3062             : {
    3063             :   parallel_object_only();
    3064             : 
    3065        1240 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3066         616 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3067             :   {
    3068           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3069           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3070           0 :     _reinit_displaced_elem = true;
    3071             :   }
    3072             :   else
    3073             :   {
    3074         616 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3075             :     {
    3076             :       // We allow NodalKernels to request that they use_displaced_mesh,
    3077             :       // but then be overridden when no displacements variables are
    3078             :       // provided in the Mesh block.  If that happened, update the value
    3079             :       // of use_displaced_mesh appropriately for this NodalKernel.
    3080           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3081           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3082             :     }
    3083             : 
    3084        1232 :     parameters.set<SubProblem *>("_subproblem") = this;
    3085        1848 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3086             :   }
    3087         616 :   logAdd("NodalKernel", name, kernel_name, parameters);
    3088         616 :   _nl[nl_sys_num]->addNodalKernel(kernel_name, name, parameters);
    3089         616 : }
    3090             : 
    3091             : void
    3092        1551 : FEProblemBase::addScalarKernel(const std::string & kernel_name,
    3093             :                                const std::string & name,
    3094             :                                InputParameters & parameters)
    3095             : {
    3096             :   parallel_object_only();
    3097             : 
    3098        3102 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3099        1551 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3100           0 :     mooseError("You are trying to add a ScalarKernel to a linear variable/system, which is not "
    3101             :                "supported at the moment!");
    3102             : 
    3103        1551 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3104             :   {
    3105           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3106           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3107             :   }
    3108             :   else
    3109             :   {
    3110        1551 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3111             :     {
    3112             :       // We allow ScalarKernels to request that they use_displaced_mesh,
    3113             :       // but then be overridden when no displacements variables are
    3114             :       // provided in the Mesh block.  If that happened, update the value
    3115             :       // of use_displaced_mesh appropriately for this ScalarKernel.
    3116           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3117           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3118             :     }
    3119             : 
    3120        3102 :     parameters.set<SubProblem *>("_subproblem") = this;
    3121        4653 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3122             :   }
    3123             : 
    3124        1551 :   logAdd("ScalarKernel", name, kernel_name, parameters);
    3125        1551 :   _nl[nl_sys_num]->addScalarKernel(kernel_name, name, parameters);
    3126        1543 : }
    3127             : 
    3128             : void
    3129       82940 : FEProblemBase::addBoundaryCondition(const std::string & bc_name,
    3130             :                                     const std::string & name,
    3131             :                                     InputParameters & parameters)
    3132             : {
    3133             :   parallel_object_only();
    3134             : 
    3135      165884 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3136       82930 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3137           0 :     mooseError(
    3138             :         "You are trying to add a BoundaryCondition to a linear variable/system, which is not "
    3139             :         "supported at the moment!");
    3140             : 
    3141       82930 :   setResidualObjectParamsAndLog(
    3142       82930 :       bc_name, name, parameters, nl_sys_num, "BoundaryCondition", _reinit_displaced_face);
    3143       82930 :   _nl[nl_sys_num]->addBoundaryCondition(bc_name, name, parameters);
    3144       82872 : }
    3145             : 
    3146             : void
    3147        1731 : FEProblemBase::addConstraint(const std::string & c_name,
    3148             :                              const std::string & name,
    3149             :                              InputParameters & parameters)
    3150             : {
    3151             :   parallel_object_only();
    3152             : 
    3153        1731 :   _has_constraints = true;
    3154             : 
    3155        1731 :   auto determine_var_param_name = [&parameters, this]()
    3156             :   {
    3157        5193 :     if (parameters.isParamValid("variable"))
    3158        1125 :       return "variable";
    3159             :     else
    3160             :     {
    3161             :       // must be a mortar constraint
    3162        1212 :       const bool has_secondary_var = parameters.isParamValid("secondary_variable");
    3163        1212 :       const bool has_primary_var = parameters.isParamValid("primary_variable");
    3164         606 :       if (!has_secondary_var && !has_primary_var)
    3165           0 :         mooseError(
    3166             :             "Either a 'secondary_variable' or 'primary_variable' parameter must be supplied for '",
    3167           0 :             parameters.getObjectName(),
    3168             :             "'");
    3169         606 :       return has_secondary_var ? "secondary_variable" : "primary_variable";
    3170             :     }
    3171        1731 :   };
    3172             : 
    3173             :   const auto nl_sys_num =
    3174        3462 :       determineSolverSystem(parameters.varName(determine_var_param_name(), name), true).second;
    3175        1727 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3176           0 :     mooseError("You are trying to add a Constraint to a linear variable/system, which is not "
    3177             :                "supported at the moment!");
    3178             : 
    3179        1727 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3180             :   {
    3181         294 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3182         294 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3183         147 :     _reinit_displaced_face = true;
    3184             :   }
    3185             :   else
    3186             :   {
    3187             :     // It might _want_ to use a displaced mesh... but we're not so set it to false
    3188        1580 :     if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3189        3160 :       parameters.set<bool>("use_displaced_mesh") = false;
    3190             : 
    3191        3160 :     parameters.set<SubProblem *>("_subproblem") = this;
    3192        4740 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3193             :   }
    3194             : 
    3195        1727 :   logAdd("Constraint", name, c_name, parameters);
    3196        1727 :   _nl[nl_sys_num]->addConstraint(c_name, name, parameters);
    3197        1719 : }
    3198             : 
    3199             : void
    3200       96528 : FEProblemBase::addAuxVariable(const std::string & var_type,
    3201             :                               const std::string & var_name,
    3202             :                               InputParameters & params)
    3203             : {
    3204             :   parallel_object_only();
    3205             : 
    3206       96528 :   const auto order = Utility::string_to_enum<Order>(params.get<MooseEnum>("order"));
    3207       96528 :   const auto family = Utility::string_to_enum<FEFamily>(params.get<MooseEnum>("family"));
    3208       96528 :   const auto fe_type = FEType(order, family);
    3209             : 
    3210             :   const auto active_subdomains_vector =
    3211       96528 :       _mesh.getSubdomainIDs(params.get<std::vector<SubdomainName>>("block"));
    3212             :   const std::set<SubdomainID> active_subdomains(active_subdomains_vector.begin(),
    3213       96528 :                                                 active_subdomains_vector.end());
    3214             : 
    3215       96528 :   if (duplicateVariableCheck(var_name, fe_type, /* is_aux = */ true, &active_subdomains))
    3216           0 :     return;
    3217             : 
    3218      289548 :   params.set<FEProblemBase *>("_fe_problem_base") = this;
    3219      193032 :   params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
    3220             : 
    3221       96516 :   logAdd("AuxVariable", var_name, var_type, params);
    3222       96516 :   _aux->addVariable(var_type, var_name, params);
    3223       96516 :   if (_displaced_problem)
    3224             :     // MooseObjects need to be unique so change the name here
    3225       11112 :     _displaced_problem->addAuxVariable(var_type, var_name, params);
    3226             : 
    3227       96516 :   markFamilyPRefinement(params);
    3228       96516 : }
    3229             : 
    3230             : void
    3231           0 : FEProblemBase::addAuxVariable(const std::string & var_name,
    3232             :                               const FEType & type,
    3233             :                               const std::set<SubdomainID> * const active_subdomains)
    3234             : {
    3235             :   parallel_object_only();
    3236             : 
    3237           0 :   mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
    3238             : 
    3239           0 :   if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
    3240           0 :     return;
    3241             : 
    3242           0 :   std::string var_type;
    3243           0 :   if (type == FEType(0, MONOMIAL))
    3244           0 :     var_type = "MooseVariableConstMonomial";
    3245           0 :   else if (type.family == SCALAR)
    3246           0 :     var_type = "MooseVariableScalar";
    3247           0 :   else if (FEInterface::field_type(type) == TYPE_VECTOR)
    3248           0 :     var_type = "VectorMooseVariable";
    3249             :   else
    3250           0 :     var_type = "MooseVariable";
    3251             : 
    3252           0 :   InputParameters params = _factory.getValidParams(var_type);
    3253           0 :   params.set<FEProblemBase *>("_fe_problem_base") = this;
    3254           0 :   params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
    3255           0 :   params.set<MooseEnum>("order") = type.order.get_order();
    3256           0 :   params.set<MooseEnum>("family") = Moose::stringify(type.family);
    3257             : 
    3258           0 :   if (active_subdomains)
    3259           0 :     for (const SubdomainID & id : *active_subdomains)
    3260           0 :       params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
    3261             : 
    3262           0 :   logAdd("AuxVariable", var_name, var_type, params);
    3263           0 :   _aux->addVariable(var_type, var_name, params);
    3264           0 :   if (_displaced_problem)
    3265           0 :     _displaced_problem->addAuxVariable("MooseVariable", var_name, params);
    3266             : 
    3267           0 :   markFamilyPRefinement(params);
    3268           0 : }
    3269             : 
    3270             : void
    3271           0 : FEProblemBase::addAuxArrayVariable(const std::string & var_name,
    3272             :                                    const FEType & type,
    3273             :                                    unsigned int components,
    3274             :                                    const std::set<SubdomainID> * const active_subdomains)
    3275             : {
    3276             :   parallel_object_only();
    3277             : 
    3278           0 :   mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
    3279             : 
    3280           0 :   if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
    3281           0 :     return;
    3282             : 
    3283           0 :   InputParameters params = _factory.getValidParams("ArrayMooseVariable");
    3284           0 :   params.set<FEProblemBase *>("_fe_problem_base") = this;
    3285           0 :   params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
    3286           0 :   params.set<MooseEnum>("order") = type.order.get_order();
    3287           0 :   params.set<MooseEnum>("family") = Moose::stringify(type.family);
    3288           0 :   params.set<unsigned int>("components") = components;
    3289             : 
    3290           0 :   if (active_subdomains)
    3291           0 :     for (const SubdomainID & id : *active_subdomains)
    3292           0 :       params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
    3293             : 
    3294           0 :   logAdd("Variable", var_name, "ArrayMooseVariable", params);
    3295           0 :   _aux->addVariable("ArrayMooseVariable", var_name, params);
    3296           0 :   if (_displaced_problem)
    3297           0 :     _displaced_problem->addAuxVariable("ArrayMooseVariable", var_name, params);
    3298             : 
    3299           0 :   markFamilyPRefinement(params);
    3300           0 : }
    3301             : 
    3302             : void
    3303           0 : FEProblemBase::addAuxScalarVariable(const std::string & var_name,
    3304             :                                     Order order,
    3305             :                                     Real /*scale_factor*/,
    3306             :                                     const std::set<SubdomainID> * const active_subdomains)
    3307             : {
    3308             :   parallel_object_only();
    3309             : 
    3310           0 :   mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
    3311             : 
    3312           0 :   if (order > _max_scalar_order)
    3313           0 :     _max_scalar_order = order;
    3314             : 
    3315           0 :   FEType type(order, SCALAR);
    3316           0 :   if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
    3317           0 :     return;
    3318             : 
    3319           0 :   InputParameters params = _factory.getValidParams("MooseVariableScalar");
    3320           0 :   params.set<FEProblemBase *>("_fe_problem_base") = this;
    3321           0 :   params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;
    3322             : 
    3323           0 :   params.set<MooseEnum>("order") = type.order.get_order();
    3324           0 :   params.set<MooseEnum>("family") = "SCALAR";
    3325           0 :   params.set<std::vector<Real>>("scaling") = {1};
    3326           0 :   if (active_subdomains)
    3327           0 :     for (const SubdomainID & id : *active_subdomains)
    3328           0 :       params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
    3329             : 
    3330           0 :   logAdd("ScalarVariable", var_name, "MooseVariableScalar", params);
    3331           0 :   _aux->addVariable("MooseVariableScalar", var_name, params);
    3332           0 :   if (_displaced_problem)
    3333           0 :     _displaced_problem->addAuxVariable("MooseVariableScalar", var_name, params);
    3334           0 : }
    3335             : 
    3336             : void
    3337       68429 : FEProblemBase::addAuxKernel(const std::string & kernel_name,
    3338             :                             const std::string & name,
    3339             :                             InputParameters & parameters)
    3340             : {
    3341             :   parallel_object_only();
    3342             : 
    3343       68429 :   setAuxKernelParamsAndLog(kernel_name, name, parameters, "AuxKernel");
    3344             : 
    3345       68429 :   _aux->addKernel(kernel_name, name, parameters);
    3346       68277 : }
    3347             : 
    3348             : void
    3349         537 : FEProblemBase::addAuxScalarKernel(const std::string & kernel_name,
    3350             :                                   const std::string & name,
    3351             :                                   InputParameters & parameters)
    3352             : {
    3353             :   parallel_object_only();
    3354             : 
    3355         537 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3356             :   {
    3357           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3358           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    3359             :   }
    3360             :   else
    3361             :   {
    3362         537 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3363             :     {
    3364             :       // We allow AuxScalarKernels to request that they use_displaced_mesh,
    3365             :       // but then be overridden when no displacements variables are
    3366             :       // provided in the Mesh block.  If that happened, update the value
    3367             :       // of use_displaced_mesh appropriately for this AuxScalarKernel.
    3368           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3369           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3370             :     }
    3371             : 
    3372        1074 :     parameters.set<SubProblem *>("_subproblem") = this;
    3373        1611 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    3374             :   }
    3375             : 
    3376         537 :   logAdd("AuxScalarKernel", name, kernel_name, parameters);
    3377         537 :   _aux->addScalarKernel(kernel_name, name, parameters);
    3378         533 : }
    3379             : 
    3380             : void
    3381         942 : FEProblemBase::addDiracKernel(const std::string & kernel_name,
    3382             :                               const std::string & name,
    3383             :                               InputParameters & parameters)
    3384             : {
    3385             :   parallel_object_only();
    3386             : 
    3387        1884 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3388         938 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3389           0 :     mooseError("You are trying to add a DiracKernel to a linear variable/system, which is not "
    3390             :                "supported at the moment!");
    3391             : 
    3392         938 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3393             :   {
    3394          26 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3395          26 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3396          13 :     _reinit_displaced_elem = true;
    3397             :   }
    3398             :   else
    3399             :   {
    3400         925 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3401             :     {
    3402             :       // We allow DiracKernels to request that they use_displaced_mesh,
    3403             :       // but then be overridden when no displacements variables are
    3404             :       // provided in the Mesh block.  If that happened, update the value
    3405             :       // of use_displaced_mesh appropriately for this DiracKernel.
    3406           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3407           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3408             :     }
    3409             : 
    3410        1850 :     parameters.set<SubProblem *>("_subproblem") = this;
    3411        2775 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3412             :   }
    3413             : 
    3414         938 :   logAdd("DiracKernel", name, kernel_name, parameters);
    3415         938 :   _nl[nl_sys_num]->addDiracKernel(kernel_name, name, parameters);
    3416         930 : }
    3417             : 
    3418             : // DGKernels ////
    3419             : 
    3420             : void
    3421        1453 : FEProblemBase::addDGKernel(const std::string & dg_kernel_name,
    3422             :                            const std::string & name,
    3423             :                            InputParameters & parameters)
    3424             : {
    3425             :   parallel_object_only();
    3426             : 
    3427        2906 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3428        1449 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3429           0 :     mooseError("You are trying to add a DGKernel to a linear variable/system, which is not "
    3430             :                "supported at the moment!");
    3431             : 
    3432        1449 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3433             :   {
    3434          52 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3435          52 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3436          26 :     _reinit_displaced_neighbor = true;
    3437             :   }
    3438             :   else
    3439             :   {
    3440        1423 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3441             :     {
    3442             :       // We allow DGKernels to request that they use_displaced_mesh,
    3443             :       // but then be overridden when no displacements variables are
    3444             :       // provided in the Mesh block.  If that happened, update the value
    3445             :       // of use_displaced_mesh appropriately for this DGKernel.
    3446           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3447           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3448             :     }
    3449             : 
    3450        2846 :     parameters.set<SubProblem *>("_subproblem") = this;
    3451        4269 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3452             :   }
    3453             : 
    3454        1449 :   logAdd("DGKernel", name, dg_kernel_name, parameters);
    3455        1449 :   _nl[nl_sys_num]->addDGKernel(dg_kernel_name, name, parameters);
    3456             : 
    3457        1449 :   _has_internal_edge_residual_objects = true;
    3458        1449 : }
    3459             : 
    3460             : void
    3461        9122 : FEProblemBase::addFVKernel(const std::string & fv_kernel_name,
    3462             :                            const std::string & name,
    3463             :                            InputParameters & parameters)
    3464             : {
    3465        9122 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3466             :     // FVElementalKernels are computed in the historically finite element threaded loops. They rely
    3467             :     // on Assembly data like _current_elem. When we call reinit on the FEProblemBase we will only
    3468             :     // reinit the DisplacedProblem and its associated Assembly objects if we mark this boolean as
    3469             :     // true
    3470           0 :     _reinit_displaced_elem = true;
    3471        9122 :   addObject<FVKernel>(fv_kernel_name, name, parameters);
    3472        9114 : }
    3473             : 
    3474             : void
    3475        7779 : FEProblemBase::addFVBC(const std::string & fv_bc_name,
    3476             :                        const std::string & name,
    3477             :                        InputParameters & parameters)
    3478             : {
    3479        7779 :   addObject<FVBoundaryCondition>(fv_bc_name, name, parameters);
    3480        7779 : }
    3481             : 
    3482             : void
    3483         327 : FEProblemBase::addFVInterfaceKernel(const std::string & fv_ik_name,
    3484             :                                     const std::string & name,
    3485             :                                     InputParameters & parameters)
    3486             : {
    3487             :   /// We assume that variable1 and variable2 can live on different systems, in this case
    3488             :   /// the user needs to create two interface kernels with flipped variables and parameters
    3489         327 :   addObject<FVInterfaceKernel>(
    3490             :       fv_ik_name, name, parameters, /*threaded=*/true, /*variable_param_name=*/"variable1");
    3491         315 : }
    3492             : 
    3493             : void
    3494        3295 : FEProblemBase::addLinearFVKernel(const std::string & kernel_name,
    3495             :                                  const std::string & name,
    3496             :                                  InputParameters & parameters)
    3497             : {
    3498        3295 :   addObject<LinearFVKernel>(kernel_name, name, parameters);
    3499        3295 : }
    3500             : 
    3501             : void
    3502        2382 : FEProblemBase::addLinearFVBC(const std::string & bc_name,
    3503             :                              const std::string & name,
    3504             :                              InputParameters & parameters)
    3505             : {
    3506        2382 :   addObject<LinearFVBoundaryCondition>(bc_name, name, parameters);
    3507        2382 : }
    3508             : 
    3509             : // InterfaceKernels ////
    3510             : 
    3511             : void
    3512         919 : FEProblemBase::addInterfaceKernel(const std::string & interface_kernel_name,
    3513             :                                   const std::string & name,
    3514             :                                   InputParameters & parameters)
    3515             : {
    3516             :   parallel_object_only();
    3517             : 
    3518        1838 :   const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
    3519         915 :   if (!isSolverSystemNonlinear(nl_sys_num))
    3520           0 :     mooseError("You are trying to add a InterfaceKernel to a linear variable/system, which is not "
    3521             :                "supported at the moment!");
    3522             : 
    3523         915 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    3524             :   {
    3525          26 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3526          26 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
    3527          13 :     _reinit_displaced_neighbor = true;
    3528             :   }
    3529             :   else
    3530             :   {
    3531         902 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    3532             :     {
    3533             :       // We allow InterfaceKernels to request that they use_displaced_mesh,
    3534             :       // but then be overridden when no displacements variables are
    3535             :       // provided in the Mesh block.  If that happened, update the value
    3536             :       // of use_displaced_mesh appropriately for this InterfaceKernel.
    3537           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    3538           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    3539             :     }
    3540             : 
    3541        1804 :     parameters.set<SubProblem *>("_subproblem") = this;
    3542        2706 :     parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    3543             :   }
    3544             : 
    3545         915 :   logAdd("InterfaceKernel", name, interface_kernel_name, parameters);
    3546         915 :   _nl[nl_sys_num]->addInterfaceKernel(interface_kernel_name, name, parameters);
    3547             : 
    3548         915 :   _has_internal_edge_residual_objects = true;
    3549         915 : }
    3550             : 
    3551             : void
    3552       34004 : FEProblemBase::checkICRestartError(const std::string & ic_name,
    3553             :                                    const std::string & name,
    3554             :                                    const VariableName & var_name)
    3555             : {
    3556       34004 :   if (!_allow_ics_during_restart)
    3557             :   {
    3558       33908 :     std::string restart_method = "";
    3559       33908 :     if (_app.isRestarting())
    3560             :       restart_method =
    3561           0 :           "a checkpoint restart, by IC object '" + ic_name + "' for variable '" + name + "'";
    3562       33908 :     else if (_app.getExReaderForRestart())
    3563             :     {
    3564           4 :       std::vector<std::string> restarted_vars = _app.getExReaderForRestart()->get_elem_var_names();
    3565           4 :       const auto nodal_vars = _app.getExReaderForRestart()->get_nodal_var_names();
    3566           4 :       const auto global_vars = _app.getExReaderForRestart()->get_global_var_names();
    3567           4 :       restarted_vars.insert(restarted_vars.end(), nodal_vars.begin(), nodal_vars.end());
    3568           4 :       restarted_vars.insert(restarted_vars.end(), global_vars.begin(), global_vars.end());
    3569             : 
    3570           4 :       if (std::find(restarted_vars.begin(), restarted_vars.end(), var_name) != restarted_vars.end())
    3571           8 :         restart_method = "an Exodus restart, by IC object '" + ic_name + "' for variable '" + name +
    3572           4 :                          "' that is also being restarted";
    3573           4 :     }
    3574       33908 :     if (!restart_method.empty())
    3575           4 :       mooseError(
    3576             :           "Initial conditions have been specified during ",
    3577             :           restart_method,
    3578             :           ".\nThis is only allowed if you specify 'allow_initial_conditions_with_restart' to "
    3579             :           "the [Problem], as initial conditions can override restarted fields");
    3580       33904 :   }
    3581       34000 : }
    3582             : 
    3583             : void
    3584       31148 : FEProblemBase::addInitialCondition(const std::string & ic_name,
    3585             :                                    const std::string & name,
    3586             :                                    InputParameters & parameters)
    3587             : {
    3588             :   parallel_object_only();
    3589             : 
    3590             :   // before we start to mess with the initial condition, we need to check parameters for errors.
    3591       31148 :   parameters.checkParams(name);
    3592       31144 :   const std::string & var_name = parameters.get<VariableName>("variable");
    3593             : 
    3594             :   // Forbid initial conditions on a restarted problem, as they would override the restart
    3595       31144 :   checkICRestartError(ic_name, name, var_name);
    3596             : 
    3597       62280 :   parameters.set<SubProblem *>("_subproblem") = this;
    3598             : 
    3599             :   // field IC
    3600       31140 :   if (hasVariable(var_name))
    3601             :   {
    3602       61706 :     for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    3603             :     {
    3604       32360 :       MooseVariableFEBase & var = getVariable(
    3605             :           tid, var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
    3606       64720 :       parameters.set<SystemBase *>("_sys") = &var.sys();
    3607       32360 :       std::shared_ptr<InitialConditionBase> ic;
    3608       32360 :       if (dynamic_cast<MooseVariable *>(&var))
    3609       29752 :         ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
    3610        2608 :       else if (dynamic_cast<VectorMooseVariable *>(&var))
    3611         272 :         ic = _factory.create<VectorInitialCondition>(ic_name, name, parameters, tid);
    3612        2336 :       else if (dynamic_cast<ArrayMooseVariable *>(&var))
    3613        1314 :         ic = _factory.create<ArrayInitialCondition>(ic_name, name, parameters, tid);
    3614        1022 :       else if (dynamic_cast<MooseVariableFVReal *>(&var))
    3615        1022 :         ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
    3616           0 :       else if (dynamic_cast<MooseLinearVariableFVReal *>(&var))
    3617           0 :         ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
    3618             :       else
    3619           0 :         mooseError("Your FE variable in initial condition ",
    3620             :                    name,
    3621             :                    " must be either of scalar or vector type");
    3622       32332 :       logAdd("IC", name, ic_name, parameters);
    3623       32332 :       _ics.addObject(ic, tid);
    3624       32312 :     }
    3625             :   }
    3626             : 
    3627             :   // scalar IC
    3628        1746 :   else if (hasScalarVariable(var_name))
    3629             :   {
    3630        1746 :     MooseVariableScalar & var = getScalarVariable(0, var_name);
    3631        3492 :     parameters.set<SystemBase *>("_sys") = &var.sys();
    3632             :     std::shared_ptr<ScalarInitialCondition> ic =
    3633        1746 :         _factory.create<ScalarInitialCondition>(ic_name, name, parameters);
    3634        1746 :     logAdd("ScalarIC", name, ic_name, parameters);
    3635        1746 :     _scalar_ics.addObject(ic);
    3636        1746 :   }
    3637             : 
    3638             :   else
    3639           0 :     mooseError(
    3640             :         "Variable '", var_name, "' requested in initial condition '", name, "' does not exist.");
    3641       31092 : }
    3642             : 
    3643             : void
    3644        2860 : FEProblemBase::addFVInitialCondition(const std::string & ic_name,
    3645             :                                      const std::string & name,
    3646             :                                      InputParameters & parameters)
    3647             : {
    3648             :   parallel_object_only();
    3649             : 
    3650             :   // before we start to mess with the initial condition, we need to check parameters for errors.
    3651        2860 :   parameters.checkParams(name);
    3652        2860 :   const std::string & var_name = parameters.get<VariableName>("variable");
    3653             : 
    3654             :   // Forbid initial conditions on a restarted problem, as they would override the restart
    3655        2860 :   checkICRestartError(ic_name, name, var_name);
    3656             : 
    3657        5720 :   parameters.set<SubProblem *>("_subproblem") = this;
    3658             : 
    3659             :   // field IC
    3660        2860 :   if (hasVariable(var_name))
    3661             :   {
    3662        5802 :     for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    3663             :     {
    3664        2942 :       auto & var = getVariable(
    3665             :           tid, var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY);
    3666        5884 :       parameters.set<SystemBase *>("_sys") = &var.sys();
    3667        2942 :       std::shared_ptr<FVInitialConditionBase> ic;
    3668        2942 :       if (var.isFV())
    3669        2942 :         ic = _factory.create<FVInitialCondition>(ic_name, name, parameters, tid);
    3670             :       else
    3671           0 :         mooseError(
    3672             :             "Your variable for an FVInitialCondition needs to be an a finite volume variable!");
    3673        2942 :       _fv_ics.addObject(ic, tid);
    3674        2942 :     }
    3675             :   }
    3676             :   else
    3677           0 :     mooseError("Variable '",
    3678             :                var_name,
    3679             :                "' requested in finite volume initial condition '",
    3680             :                name,
    3681             :                "' does not exist.");
    3682        2860 : }
    3683             : 
    3684             : void
    3685       58791 : FEProblemBase::projectSolution()
    3686             : {
    3687      293955 :   TIME_SECTION("projectSolution", 2, "Projecting Initial Solutions")
    3688             : 
    3689       58791 :   FloatingPointExceptionGuard fpe_guard(_app);
    3690             : 
    3691       58791 :   ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
    3692       58791 :   ComputeInitialConditionThread cic(*this);
    3693       58791 :   Threads::parallel_reduce(elem_range, cic);
    3694             : 
    3695       58783 :   if (haveFV())
    3696             :   {
    3697             :     using ElemInfoRange = StoredRange<MooseMesh::const_elem_info_iterator, const ElemInfo *>;
    3698        5226 :     ElemInfoRange elem_info_range(_mesh.ownedElemInfoBegin(), _mesh.ownedElemInfoEnd());
    3699             : 
    3700        5226 :     ComputeFVInitialConditionThread cfvic(*this);
    3701        5226 :     Threads::parallel_reduce(elem_info_range, cfvic);
    3702        5226 :   }
    3703             : 
    3704             :   // Need to close the solution vector here so that boundary ICs take precendence
    3705      116497 :   for (auto & nl : _nl)
    3706       57714 :     nl->solution().close();
    3707       58783 :   _aux->solution().close();
    3708             : 
    3709             :   // now run boundary-restricted initial conditions
    3710       58783 :   ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
    3711       58783 :   ComputeBoundaryInitialConditionThread cbic(*this);
    3712       58783 :   Threads::parallel_reduce(bnd_nodes, cbic);
    3713             : 
    3714      116497 :   for (auto & nl : _nl)
    3715       57714 :     nl->solution().close();
    3716       58783 :   _aux->solution().close();
    3717             : 
    3718             :   // Also, load values into the SCALAR dofs
    3719             :   // Note: We assume that all SCALAR dofs are on the
    3720             :   // processor with highest ID
    3721       58783 :   if (processor_id() == (n_processors() - 1) && _scalar_ics.hasActiveObjects())
    3722             :   {
    3723         678 :     const auto & ics = _scalar_ics.getActiveObjects();
    3724        1864 :     for (const auto & ic : ics)
    3725             :     {
    3726        1186 :       MooseVariableScalar & var = ic->variable();
    3727        1186 :       var.reinit();
    3728             : 
    3729        1186 :       DenseVector<Number> vals(var.order());
    3730        1186 :       ic->compute(vals);
    3731             : 
    3732        1186 :       const unsigned int n_scalar_dofs = var.dofIndices().size();
    3733        2757 :       for (unsigned int i = 0; i < n_scalar_dofs; i++)
    3734             :       {
    3735        1571 :         const auto global_index = var.dofIndices()[i];
    3736        1571 :         var.sys().solution().set(global_index, vals(i));
    3737        1571 :         var.setValue(i, vals(i));
    3738             :       }
    3739        1186 :     }
    3740             :   }
    3741             : 
    3742      117823 :   for (auto & sys : _solver_systems)
    3743             :   {
    3744       59040 :     sys->solution().close();
    3745       59040 :     sys->solution().localize(*sys->system().current_local_solution, sys->dofMap().get_send_list());
    3746             :   }
    3747             : 
    3748       58783 :   _aux->solution().close();
    3749       58783 :   _aux->solution().localize(*_aux->sys().current_local_solution, _aux->dofMap().get_send_list());
    3750       58783 : }
    3751             : 
    3752             : void
    3753        2191 : FEProblemBase::projectInitialConditionOnCustomRange(
    3754             :     ConstElemRange & elem_range,
    3755             :     ConstBndNodeRange & bnd_nodes,
    3756             :     const std::optional<std::set<VariableName>> & target_vars)
    3757             : {
    3758        2191 :   if (target_vars)
    3759             :   {
    3760        2191 :     ComputeInitialConditionThread cic(*this, &(*target_vars));
    3761        2191 :     Threads::parallel_reduce(elem_range, cic);
    3762             :   }
    3763             :   else
    3764             :   {
    3765           0 :     ComputeInitialConditionThread cic(*this);
    3766           0 :     Threads::parallel_reduce(elem_range, cic);
    3767             :   }
    3768             : 
    3769             :   // Need to close the solution vector here so that boundary ICs take precendence
    3770        4382 :   for (auto & nl : _nl)
    3771        2191 :     nl->solution().close();
    3772        2191 :   _aux->solution().close();
    3773             : 
    3774        2191 :   if (target_vars)
    3775             :   {
    3776        2191 :     ComputeBoundaryInitialConditionThread cbic(*this, &(*target_vars));
    3777        2191 :     Threads::parallel_reduce(bnd_nodes, cbic);
    3778        2191 :   }
    3779             :   else
    3780             :   {
    3781           0 :     ComputeBoundaryInitialConditionThread cbic(*this);
    3782           0 :     Threads::parallel_reduce(bnd_nodes, cbic);
    3783           0 :   }
    3784             : 
    3785        4382 :   for (auto & nl : _nl)
    3786        2191 :     nl->solution().close();
    3787        2191 :   _aux->solution().close();
    3788             : 
    3789             :   // Also, load values into the SCALAR dofs
    3790             :   // Note: We assume that all SCALAR dofs are on the
    3791             :   // processor with highest ID
    3792        2191 :   if (processor_id() == (n_processors() - 1) && _scalar_ics.hasActiveObjects())
    3793             :   {
    3794           0 :     const auto & ics = _scalar_ics.getActiveObjects();
    3795           0 :     for (const auto & ic : ics)
    3796             :     {
    3797           0 :       MooseVariableScalar & var = ic->variable();
    3798             : 
    3799           0 :       if (target_vars && !target_vars->count(var.name()))
    3800           0 :         continue;
    3801             : 
    3802           0 :       var.reinit();
    3803             : 
    3804           0 :       DenseVector<Number> vals(var.order());
    3805           0 :       ic->compute(vals);
    3806             : 
    3807           0 :       const unsigned int n_scalar_dofs = var.dofIndices().size();
    3808           0 :       for (unsigned int i = 0; i < n_scalar_dofs; i++)
    3809             :       {
    3810           0 :         const auto global_index = var.dofIndices()[i];
    3811           0 :         var.sys().solution().set(global_index, vals(i));
    3812           0 :         var.setValue(i, vals(i));
    3813             :       }
    3814           0 :     }
    3815             :   }
    3816             : 
    3817        4382 :   for (auto & nl : _nl)
    3818             :   {
    3819        2191 :     nl->solution().close();
    3820        2191 :     nl->solution().localize(*nl->system().current_local_solution, nl->dofMap().get_send_list());
    3821             :   }
    3822             : 
    3823        2191 :   _aux->solution().close();
    3824        2191 :   _aux->solution().localize(*_aux->sys().current_local_solution, _aux->dofMap().get_send_list());
    3825        2191 : }
    3826             : 
    3827             : void
    3828         765 : FEProblemBase::projectFunctionOnCustomRange(ConstElemRange & elem_range,
    3829             :                                             Number (*func)(const Point &,
    3830             :                                                            const libMesh::Parameters &,
    3831             :                                                            const std::string &,
    3832             :                                                            const std::string &),
    3833             :                                             Gradient (*func_grad)(const Point &,
    3834             :                                                                   const libMesh::Parameters &,
    3835             :                                                                   const std::string &,
    3836             :                                                                   const std::string &),
    3837             :                                             const libMesh::Parameters & params,
    3838             :                                             const VariableName & target_var)
    3839             : {
    3840             :   mooseAssert(!Threads::in_threads,
    3841             :               "We're performing a projection based on data from just the thread 0 variable, so any "
    3842             :               "modifications to the variable solution must have been thread joined already");
    3843             : 
    3844         765 :   const auto & var = getStandardVariable(0, target_var);
    3845         765 :   const auto var_num = var.number();
    3846         765 :   const auto sn = systemNumForVariable(target_var);
    3847         765 :   auto & sys = getSystemBase(sn);
    3848             : 
    3849             :   // Let libmesh handle the projection
    3850         765 :   System & libmesh_sys = getSystem(target_var);
    3851         765 :   auto temp_vec = libmesh_sys.current_local_solution->zero_clone();
    3852         765 :   libmesh_sys.project_vector(func, func_grad, params, *temp_vec);
    3853         765 :   temp_vec->close();
    3854             : 
    3855             :   // Get the dof indices to copy
    3856         765 :   DofMap & dof_map = sys.dofMap();
    3857         765 :   std::set<dof_id_type> dof_indices;
    3858         765 :   std::vector<dof_id_type> elem_dof_indices;
    3859             : 
    3860        4853 :   for (const auto & elem : elem_range)
    3861             :   {
    3862        4088 :     dof_map.dof_indices(elem, elem_dof_indices, var_num);
    3863        4088 :     dof_indices.insert(elem_dof_indices.begin(), elem_dof_indices.end());
    3864             :   }
    3865         765 :   std::vector<dof_id_type> dof_indices_v(dof_indices.begin(), dof_indices.end());
    3866             : 
    3867             :   // Copy the projected values into the solution vector
    3868         765 :   std::vector<Real> dof_vals;
    3869         765 :   temp_vec->get(dof_indices_v, dof_vals);
    3870             :   mooseAssert(sys.solution().closed(),
    3871             :               "The solution should be closed before mapping our projection");
    3872         765 :   sys.solution().insert(dof_vals, dof_indices_v);
    3873         765 :   sys.solution().close();
    3874         765 :   sys.solution().localize(*libmesh_sys.current_local_solution, sys.dofMap().get_send_list());
    3875         765 : }
    3876             : 
    3877             : std::shared_ptr<MaterialBase>
    3878         276 : FEProblemBase::getMaterial(std::string name,
    3879             :                            Moose::MaterialDataType type,
    3880             :                            const THREAD_ID tid,
    3881             :                            bool no_warn)
    3882             : {
    3883         276 :   switch (type)
    3884             :   {
    3885          70 :     case Moose::NEIGHBOR_MATERIAL_DATA:
    3886          70 :       name += "_neighbor";
    3887          70 :       break;
    3888          70 :     case Moose::FACE_MATERIAL_DATA:
    3889          70 :       name += "_face";
    3890          70 :       break;
    3891         136 :     default:
    3892         136 :       break;
    3893             :   }
    3894             : 
    3895         276 :   std::shared_ptr<MaterialBase> material = _all_materials[type].getActiveObject(name, tid);
    3896         716 :   if (!no_warn && material->getParam<bool>("compute") && type == Moose::BLOCK_MATERIAL_DATA)
    3897           4 :     mooseWarning("You are retrieving a Material object (",
    3898           4 :                  material->name(),
    3899             :                  "), but its compute flag is set to true. This indicates that MOOSE is "
    3900             :                  "computing this property which may not be desired and produce un-expected "
    3901             :                  "results.");
    3902             : 
    3903         268 :   return material;
    3904             : }
    3905             : 
    3906             : MaterialData &
    3907    50273258 : FEProblemBase::getMaterialData(Moose::MaterialDataType type,
    3908             :                                const THREAD_ID tid,
    3909             :                                const MooseObject * object) const
    3910             : {
    3911    50273258 :   switch (type)
    3912             :   {
    3913      907835 :     case Moose::BLOCK_MATERIAL_DATA:
    3914      907835 :       if (object)
    3915      282575 :         _material_props.addConsumer(type, object);
    3916      907835 :       return _material_props.getMaterialData(tid);
    3917    23467686 :     case Moose::NEIGHBOR_MATERIAL_DATA:
    3918    23467686 :       if (object)
    3919       26553 :         _neighbor_material_props.addConsumer(type, object);
    3920    23467686 :       return _neighbor_material_props.getMaterialData(tid);
    3921    25897737 :     case Moose::BOUNDARY_MATERIAL_DATA:
    3922             :     case Moose::FACE_MATERIAL_DATA:
    3923             :     case Moose::INTERFACE_MATERIAL_DATA:
    3924    25897737 :       if (object)
    3925       59030 :         _bnd_material_props.addConsumer(type, object);
    3926    25897737 :       return _bnd_material_props.getMaterialData(tid);
    3927             :   }
    3928             : 
    3929           0 :   mooseError("FEProblemBase::getMaterialData(): Invalid MaterialDataType ", type);
    3930             : }
    3931             : 
    3932             : const std::set<const MooseObject *> &
    3933           0 : FEProblemBase::getMaterialPropertyStorageConsumers(Moose::MaterialDataType type) const
    3934             : {
    3935           0 :   switch (type)
    3936             :   {
    3937           0 :     case Moose::BLOCK_MATERIAL_DATA:
    3938           0 :       return _material_props.getConsumers(type);
    3939           0 :     case Moose::NEIGHBOR_MATERIAL_DATA:
    3940           0 :       return _neighbor_material_props.getConsumers(type);
    3941           0 :     case Moose::BOUNDARY_MATERIAL_DATA:
    3942             :     case Moose::FACE_MATERIAL_DATA:
    3943             :     case Moose::INTERFACE_MATERIAL_DATA:
    3944           0 :       return _bnd_material_props.getConsumers(type);
    3945             :   }
    3946             : 
    3947           0 :   mooseError("FEProblemBase::getMaterialPropertyStorageConsumers(): Invalid MaterialDataType ",
    3948             :              type);
    3949             : }
    3950             : 
    3951             : void
    3952           0 : FEProblemBase::setPreserveMatrixSparsityPattern(bool preserve)
    3953             : {
    3954           0 :   if (_ignore_zeros_in_jacobian && preserve)
    3955           0 :     paramWarning(
    3956             :         "ignore_zeros_in_jacobian",
    3957             :         "We likely cannot preserve the sparsity pattern if ignoring zeros in the Jacobian, which "
    3958             :         "leads to removing those entries from the Jacobian sparsity pattern");
    3959           0 :   _preserve_matrix_sparsity_pattern = preserve;
    3960           0 : }
    3961             : 
    3962             : bool
    3963      340306 : FEProblemBase::acceptInvalidSolution() const
    3964             : {
    3965      680518 :   return allowInvalidSolution() || // invalid solutions are always allowed
    3966      680518 :          !_app.solutionInvalidity().hasInvalidSolutionError(); // if not allowed, check for errors
    3967             : }
    3968             : 
    3969             : void
    3970        1177 : FEProblemBase::addFunctorMaterial(const std::string & functor_material_name,
    3971             :                                   const std::string & name,
    3972             :                                   InputParameters & parameters)
    3973             : {
    3974             :   parallel_object_only();
    3975             : 
    3976        1177 :   auto add_functor_materials = [&](const auto & parameters, const auto & name)
    3977             :   {
    3978        2437 :     for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    3979             :     {
    3980             :       // Create the general Block/Boundary MaterialBase object
    3981        1260 :       std::shared_ptr<MaterialBase> material =
    3982        1260 :           _factory.create<MaterialBase>(functor_material_name, name, parameters, tid);
    3983        2520 :       logAdd("FunctorMaterial", name, functor_material_name, parameters);
    3984        1260 :       _all_materials.addObject(material, tid);
    3985        1260 :       _materials.addObject(material, tid);
    3986             :     }
    3987        1177 :   };
    3988             : 
    3989        2354 :   parameters.set<SubProblem *>("_subproblem") = this;
    3990        1177 :   add_functor_materials(parameters, name);
    3991        1177 :   if (_displaced_problem)
    3992             :   {
    3993           0 :     auto disp_params = parameters;
    3994           0 :     disp_params.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    3995           0 :     add_functor_materials(disp_params, name + "_displaced");
    3996           0 :   }
    3997        1177 : }
    3998             : 
    3999             : void
    4000       13522 : FEProblemBase::addMaterial(const std::string & mat_name,
    4001             :                            const std::string & name,
    4002             :                            InputParameters & parameters)
    4003             : {
    4004       27044 :   addMaterialHelper({&_materials}, mat_name, name, parameters);
    4005       13392 : }
    4006             : 
    4007             : void
    4008         348 : FEProblemBase::addInterfaceMaterial(const std::string & mat_name,
    4009             :                                     const std::string & name,
    4010             :                                     InputParameters & parameters)
    4011             : {
    4012         696 :   addMaterialHelper({&_interface_materials}, mat_name, name, parameters);
    4013         348 : }
    4014             : 
    4015             : void
    4016       14164 : FEProblemBase::addMaterialHelper(std::vector<MaterialWarehouse *> warehouses,
    4017             :                                  const std::string & mat_name,
    4018             :                                  const std::string & name,
    4019             :                                  InputParameters & parameters)
    4020             : {
    4021             :   parallel_object_only();
    4022             : 
    4023       14164 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    4024             :   {
    4025         274 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    4026         137 :     _reinit_displaced_elem = _reinit_displaced_face = _reinit_displaced_neighbor = true;
    4027             :   }
    4028             :   else
    4029             :   {
    4030       14027 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    4031             :     {
    4032             :       // We allow Materials to request that they use_displaced_mesh,
    4033             :       // but then be overridden when no displacements variables are
    4034             :       // provided in the Mesh block.  If that happened, update the value
    4035             :       // of use_displaced_mesh appropriately for this Material.
    4036           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    4037           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    4038             :     }
    4039             : 
    4040       42081 :     parameters.set<SubProblem *>("_subproblem") = this;
    4041             :   }
    4042             : 
    4043       29393 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    4044             :   {
    4045             :     // Create the general Block/Boundary MaterialBase object
    4046             :     std::shared_ptr<MaterialBase> material =
    4047       15365 :         _factory.create<MaterialBase>(mat_name, name, parameters, tid);
    4048       15229 :     logAdd("Material", name, mat_name, parameters);
    4049       30458 :     bool discrete = !material->getParam<bool>("compute");
    4050             : 
    4051             :     // If the object is boundary restricted or if it is a functor material we do not create the
    4052             :     // neighbor and face objects
    4053       15229 :     if (material->boundaryRestricted() || dynamic_cast<FunctorMaterial *>(material.get()))
    4054             :     {
    4055        3429 :       _all_materials.addObject(material, tid);
    4056        3429 :       if (discrete)
    4057           5 :         _discrete_materials.addObject(material, tid);
    4058             :       else
    4059        6848 :         for (auto && warehouse : warehouses)
    4060        3424 :           warehouse->addObject(material, tid);
    4061             :     }
    4062             : 
    4063             :     // Non-boundary restricted require face and neighbor objects
    4064             :     else
    4065             :     {
    4066             :       // TODO: we only need to do this if we have needs for face materials (e.g.
    4067             :       // FV, DG, etc.) - but currently we always do it.  Figure out how to fix
    4068             :       // this.
    4069             : 
    4070             :       // The name of the object being created, this is changed multiple times as objects are
    4071             :       // created below
    4072       11800 :       std::string object_name;
    4073             : 
    4074             :       // Create a copy of the supplied parameters to the setting for "_material_data_type" isn't
    4075             :       // used from a previous tid loop
    4076       11800 :       InputParameters current_parameters = parameters;
    4077             : 
    4078             :       // face material
    4079       11800 :       current_parameters.set<Moose::MaterialDataType>("_material_data_type") =
    4080             :           Moose::FACE_MATERIAL_DATA;
    4081       11800 :       object_name = name + "_face";
    4082             :       std::shared_ptr<MaterialBase> face_material =
    4083       11800 :           _factory.create<MaterialBase>(mat_name, object_name, current_parameters, tid);
    4084             : 
    4085             :       // neighbor material
    4086       23600 :       current_parameters.set<Moose::MaterialDataType>("_material_data_type") =
    4087             :           Moose::NEIGHBOR_MATERIAL_DATA;
    4088       11800 :       current_parameters.set<bool>("_neighbor") = true;
    4089       11800 :       object_name = name + "_neighbor";
    4090             :       std::shared_ptr<MaterialBase> neighbor_material =
    4091       11800 :           _factory.create<MaterialBase>(mat_name, object_name, current_parameters, tid);
    4092             : 
    4093             :       // Store the material objects
    4094       11800 :       _all_materials.addObjects(material, neighbor_material, face_material, tid);
    4095             : 
    4096       11800 :       if (discrete)
    4097          80 :         _discrete_materials.addObjects(material, neighbor_material, face_material, tid);
    4098             :       else
    4099       23440 :         for (auto && warehouse : warehouses)
    4100       11720 :           warehouse->addObjects(material, neighbor_material, face_material, tid);
    4101             : 
    4102             :       // Names of all controllable parameters for this Material object
    4103       11800 :       const std::string & base = parameters.getBase();
    4104       35400 :       MooseObjectParameterName name(MooseObjectName(base, material->name()), "*");
    4105             :       const auto param_names =
    4106       11800 :           _app.getInputParameterWarehouse().getControllableParameterNames(name);
    4107             : 
    4108             :       // Connect parameters of the primary Material object to those on the face and neighbor
    4109             :       // objects
    4110       29957 :       for (const auto & p_name : param_names)
    4111             :       {
    4112       36314 :         MooseObjectParameterName primary_name(MooseObjectName(base, material->name()),
    4113       36314 :                                               p_name.parameter());
    4114       36314 :         MooseObjectParameterName face_name(MooseObjectName(base, face_material->name()),
    4115       36314 :                                            p_name.parameter());
    4116       36314 :         MooseObjectParameterName neighbor_name(MooseObjectName(base, neighbor_material->name()),
    4117       36314 :                                                p_name.parameter());
    4118       18157 :         _app.getInputParameterWarehouse().addControllableParameterConnection(
    4119             :             primary_name, face_name, false);
    4120       18157 :         _app.getInputParameterWarehouse().addControllableParameterConnection(
    4121             :             primary_name, neighbor_name, false);
    4122       18157 :       }
    4123       11800 :     }
    4124       15229 :   }
    4125       14028 : }
    4126             : 
    4127             : void
    4128     5605077 : FEProblemBase::prepareMaterials(const std::unordered_set<unsigned int> & consumer_needed_mat_props,
    4129             :                                 const SubdomainID blk_id,
    4130             :                                 const THREAD_ID tid)
    4131             : {
    4132     5605077 :   std::set<MooseVariableFEBase *> needed_moose_vars;
    4133     5605077 :   std::unordered_set<unsigned int> needed_mat_props;
    4134             : 
    4135     5605077 :   if (_all_materials.hasActiveBlockObjects(blk_id, tid))
    4136             :   {
    4137      678273 :     _all_materials.updateVariableDependency(needed_moose_vars, tid);
    4138      678273 :     _all_materials.updateBlockMatPropDependency(blk_id, needed_mat_props, tid);
    4139             :   }
    4140             : 
    4141     5605077 :   const auto & ids = _mesh.getSubdomainBoundaryIds(blk_id);
    4142    25804244 :   for (const auto id : ids)
    4143             :   {
    4144    20199167 :     _materials.updateBoundaryVariableDependency(id, needed_moose_vars, tid);
    4145    20199167 :     _materials.updateBoundaryMatPropDependency(id, needed_mat_props, tid);
    4146             :   }
    4147             : 
    4148     5605077 :   const auto & current_active_elemental_moose_variables = getActiveElementalMooseVariables(tid);
    4149     5605077 :   needed_moose_vars.insert(current_active_elemental_moose_variables.begin(),
    4150             :                            current_active_elemental_moose_variables.end());
    4151             : 
    4152     5605077 :   needed_mat_props.insert(consumer_needed_mat_props.begin(), consumer_needed_mat_props.end());
    4153             : 
    4154     5605077 :   setActiveElementalMooseVariables(needed_moose_vars, tid);
    4155     5605077 :   setActiveMaterialProperties(needed_mat_props, tid);
    4156     5605077 : }
    4157             : 
    4158             : void
    4159   418923770 : FEProblemBase::reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful)
    4160             : {
    4161   418923770 :   if (hasActiveMaterialProperties(tid))
    4162             :   {
    4163    20009316 :     auto && elem = _assembly[tid][0]->elem();
    4164    20009316 :     unsigned int n_points = _assembly[tid][0]->qRule()->n_points();
    4165             : 
    4166    20009316 :     auto & material_data = _material_props.getMaterialData(tid);
    4167    20009316 :     material_data.resize(n_points);
    4168             : 
    4169             :     // Only swap if requested
    4170    20009316 :     if (swap_stateful)
    4171    20001977 :       material_data.swap(*elem);
    4172             : 
    4173    20009316 :     if (_discrete_materials.hasActiveBlockObjects(blk_id, tid))
    4174        3089 :       material_data.reset(_discrete_materials.getActiveBlockObjects(blk_id, tid));
    4175             : 
    4176    20009312 :     if (_materials.hasActiveBlockObjects(blk_id, tid))
    4177    19979208 :       material_data.reinit(_materials.getActiveBlockObjects(blk_id, tid));
    4178             :   }
    4179   418923688 : }
    4180             : 
    4181             : void
    4182     8596481 : FEProblemBase::reinitMaterialsFace(const SubdomainID blk_id,
    4183             :                                    const THREAD_ID tid,
    4184             :                                    const bool swap_stateful,
    4185             :                                    const std::deque<MaterialBase *> * const reinit_mats)
    4186             : {
    4187             :   // we reinit more often than needed here because we dont have a way to check whether
    4188             :   // we need to compute the face materials on a particular (possibly external) face
    4189     8596481 :   if (hasActiveMaterialProperties(tid))
    4190             :   {
    4191     2896935 :     auto && elem = _assembly[tid][0]->elem();
    4192     2896935 :     unsigned int side = _assembly[tid][0]->side();
    4193     2896935 :     unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
    4194             : 
    4195     2896935 :     auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
    4196     2896935 :     bnd_material_data.resize(n_points);
    4197             : 
    4198     2896935 :     if (swap_stateful && !bnd_material_data.isSwapped())
    4199     2872583 :       bnd_material_data.swap(*elem, side);
    4200             : 
    4201     2896935 :     if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4202           0 :       bnd_material_data.reset(
    4203           0 :           _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4204             : 
    4205     2896935 :     if (reinit_mats)
    4206       24352 :       bnd_material_data.reinit(*reinit_mats);
    4207     2872583 :     else if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4208     2872583 :       bnd_material_data.reinit(
    4209     2872583 :           _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4210             :   }
    4211     8596481 : }
    4212             : 
    4213             : void
    4214     4346725 : FEProblemBase::reinitMaterialsFaceOnBoundary(const BoundaryID boundary_id,
    4215             :                                              const SubdomainID blk_id,
    4216             :                                              const THREAD_ID tid,
    4217             :                                              const bool swap_stateful,
    4218             :                                              const std::deque<MaterialBase *> * const reinit_mats)
    4219             : {
    4220     4737879 :   if (hasActiveMaterialProperties(tid) && (needBoundaryMaterialOnSide(boundary_id, tid) ||
    4221      391154 :                                            needInterfaceMaterialOnSide(boundary_id, tid) ||
    4222      391154 :                                            needInternalNeighborSideMaterial(blk_id, tid)))
    4223             :   {
    4224      519715 :     const auto * const elem = _assembly[tid][0]->elem();
    4225      519715 :     unsigned int side = _assembly[tid][0]->side();
    4226      519715 :     unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
    4227             : 
    4228      519715 :     auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
    4229      519715 :     bnd_material_data.resize(n_points);
    4230             : 
    4231      519715 :     if (swap_stateful && !bnd_material_data.isSwapped())
    4232      519715 :       bnd_material_data.swap(*elem, side);
    4233             : 
    4234      519715 :     if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4235           0 :       bnd_material_data.reset(
    4236           0 :           _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4237             : 
    4238      519715 :     if (reinit_mats)
    4239           0 :       bnd_material_data.reinit(*reinit_mats);
    4240      519715 :     else if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4241      503690 :       bnd_material_data.reinit(
    4242      503690 :           _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4243             :   }
    4244     4346725 : }
    4245             : 
    4246             : void
    4247       54438 : FEProblemBase::reinitMaterialsNeighborOnBoundary(
    4248             :     const BoundaryID boundary_id,
    4249             :     const SubdomainID blk_id,
    4250             :     const THREAD_ID tid,
    4251             :     const bool swap_stateful,
    4252             :     const std::deque<MaterialBase *> * const reinit_mats)
    4253             : {
    4254             :   // Since objects don't declare whether they need the face or neighbor (side) material properties,
    4255             :   // we use the same criteria for skipping material property computations as for face material
    4256             :   // properties This could be a future optimization.
    4257       59223 :   if (hasActiveMaterialProperties(tid) && (needBoundaryMaterialOnSide(boundary_id, tid) ||
    4258        4785 :                                            needInterfaceMaterialOnSide(boundary_id, tid) ||
    4259        4785 :                                            needInternalNeighborSideMaterial(blk_id, tid)))
    4260       45110 :     reinitMaterialsNeighbor(blk_id, tid, swap_stateful, reinit_mats);
    4261       54438 : }
    4262             : 
    4263             : void
    4264     4596908 : FEProblemBase::reinitMaterialsNeighbor(const SubdomainID blk_id,
    4265             :                                        const THREAD_ID tid,
    4266             :                                        const bool swap_stateful,
    4267             :                                        const std::deque<MaterialBase *> * const reinit_mats)
    4268             : {
    4269     4596908 :   if (hasActiveMaterialProperties(tid))
    4270             :   {
    4271             :     // NOTE: this will not work with h-adaptivity
    4272             :     // lindsayad: why not?
    4273             : 
    4274     1092527 :     const Elem * neighbor = _assembly[tid][0]->neighbor();
    4275     1092527 :     unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[tid][0]->elem());
    4276             : 
    4277             :     mooseAssert(neighbor, "neighbor should be non-null");
    4278             :     mooseAssert(blk_id == neighbor->subdomain_id(),
    4279             :                 "The provided blk_id " << blk_id << " and neighbor subdomain ID "
    4280             :                                        << neighbor->subdomain_id() << " do not match.");
    4281             : 
    4282     1092527 :     unsigned int n_points = _assembly[tid][0]->qRuleNeighbor()->n_points();
    4283             : 
    4284     1092527 :     auto & neighbor_material_data = _neighbor_material_props.getMaterialData(tid);
    4285     1092527 :     neighbor_material_data.resize(n_points);
    4286             : 
    4287             :     // Only swap if requested
    4288     1092527 :     if (swap_stateful)
    4289     1068175 :       neighbor_material_data.swap(*neighbor, neighbor_side);
    4290             : 
    4291     1092527 :     if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4292           0 :       neighbor_material_data.reset(
    4293           0 :           _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4294             : 
    4295     1092527 :     if (reinit_mats)
    4296       24352 :       neighbor_material_data.reinit(*reinit_mats);
    4297     1068175 :     else if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    4298     1067876 :       neighbor_material_data.reinit(
    4299     1067876 :           _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
    4300             :   }
    4301     4596908 : }
    4302             : 
    4303             : void
    4304     4631154 : FEProblemBase::reinitMaterialsBoundary(const BoundaryID boundary_id,
    4305             :                                        const THREAD_ID tid,
    4306             :                                        const bool swap_stateful,
    4307             :                                        const std::deque<MaterialBase *> * const reinit_mats)
    4308             : {
    4309     4631154 :   if (hasActiveMaterialProperties(tid) && needBoundaryMaterialOnSide(boundary_id, tid))
    4310             :   {
    4311      365687 :     auto && elem = _assembly[tid][0]->elem();
    4312      365687 :     unsigned int side = _assembly[tid][0]->side();
    4313      365687 :     unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
    4314             : 
    4315      365687 :     auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
    4316      365687 :     bnd_material_data.resize(n_points);
    4317             : 
    4318      365687 :     if (swap_stateful && !bnd_material_data.isSwapped())
    4319      310985 :       bnd_material_data.swap(*elem, side);
    4320             : 
    4321      365687 :     if (_discrete_materials.hasActiveBoundaryObjects(boundary_id, tid))
    4322           0 :       bnd_material_data.reset(_discrete_materials.getActiveBoundaryObjects(boundary_id, tid));
    4323             : 
    4324      365687 :     if (reinit_mats)
    4325       24352 :       bnd_material_data.reinit(*reinit_mats);
    4326      341335 :     else if (_materials.hasActiveBoundaryObjects(boundary_id, tid))
    4327       25963 :       bnd_material_data.reinit(_materials.getActiveBoundaryObjects(boundary_id, tid));
    4328             :   }
    4329     4631154 : }
    4330             : 
    4331             : void
    4332       57823 : FEProblemBase::reinitMaterialsInterface(BoundaryID boundary_id,
    4333             :                                         const THREAD_ID tid,
    4334             :                                         bool swap_stateful)
    4335             : {
    4336       57823 :   if (hasActiveMaterialProperties(tid) && needInterfaceMaterialOnSide(boundary_id, tid))
    4337             :   {
    4338       46343 :     const Elem * const & elem = _assembly[tid][0]->elem();
    4339       46343 :     unsigned int side = _assembly[tid][0]->side();
    4340       46343 :     unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
    4341             : 
    4342       46343 :     auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
    4343       46343 :     bnd_material_data.resize(n_points);
    4344             : 
    4345       46343 :     if (swap_stateful && !bnd_material_data.isSwapped())
    4346       44568 :       bnd_material_data.swap(*elem, side);
    4347             : 
    4348       46343 :     if (_interface_materials.hasActiveBoundaryObjects(boundary_id, tid))
    4349        1317 :       bnd_material_data.reinit(_interface_materials.getActiveBoundaryObjects(boundary_id, tid));
    4350             :   }
    4351       57823 : }
    4352             : 
    4353             : void
    4354   417093954 : FEProblemBase::swapBackMaterials(const THREAD_ID tid)
    4355             : {
    4356   417093954 :   auto && elem = _assembly[tid][0]->elem();
    4357   417093954 :   _material_props.getMaterialData(tid).swapBack(*elem);
    4358   417093954 : }
    4359             : 
    4360             : void
    4361    12658758 : FEProblemBase::swapBackMaterialsFace(const THREAD_ID tid)
    4362             : {
    4363    12658758 :   auto && elem = _assembly[tid][0]->elem();
    4364    12658758 :   unsigned int side = _assembly[tid][0]->side();
    4365    12658758 :   _bnd_material_props.getMaterialData(tid).swapBack(*elem, side);
    4366    12658758 : }
    4367             : 
    4368             : void
    4369     4213629 : FEProblemBase::swapBackMaterialsNeighbor(const THREAD_ID tid)
    4370             : {
    4371             :   // NOTE: this will not work with h-adaptivity
    4372     4213629 :   const Elem * neighbor = _assembly[tid][0]->neighbor();
    4373             :   unsigned int neighbor_side =
    4374     4213629 :       neighbor ? neighbor->which_neighbor_am_i(_assembly[tid][0]->elem()) : libMesh::invalid_uint;
    4375             : 
    4376     4213629 :   if (!neighbor)
    4377             :   {
    4378           0 :     if (haveFV())
    4379             :     {
    4380             :       // If neighbor is null, then we're on the neighbor side of a mesh boundary, e.g. we're off
    4381             :       // the mesh in ghost-land. If we're using the finite volume method, then variable values and
    4382             :       // consequently material properties have well-defined values in this ghost region outside of
    4383             :       // the mesh and we really do want to reinit our neighbor materials in this case. Since we're
    4384             :       // off in ghost land it's safe to do swaps with `MaterialPropertyStorage` using the elem and
    4385             :       // elem_side keys
    4386           0 :       neighbor = _assembly[tid][0]->elem();
    4387           0 :       neighbor_side = _assembly[tid][0]->side();
    4388             :       mooseAssert(neighbor, "We should have an appropriate value for elem coming from Assembly");
    4389             :     }
    4390             :     else
    4391           0 :       mooseError("neighbor is null in Assembly!");
    4392             :   }
    4393             : 
    4394     4213629 :   _neighbor_material_props.getMaterialData(tid).swapBack(*neighbor, neighbor_side);
    4395     4213629 : }
    4396             : 
    4397             : void
    4398     1008885 : FEProblemBase::logAdd(const std::string & system,
    4399             :                       const std::string & name,
    4400             :                       const std::string & type,
    4401             :                       const InputParameters & params) const
    4402             : {
    4403     1008885 :   if (_verbose_setup != "false")
    4404       19260 :     _console << "[DBG] Adding " << system << " '" << name << "' of type " << type << std::endl;
    4405     1008885 :   if (_verbose_setup == "extra")
    4406           0 :     _console << params << std::endl;
    4407     1008885 : }
    4408             : 
    4409             : void
    4410      135859 : FEProblemBase::addObjectParamsHelper(InputParameters & parameters,
    4411             :                                      const std::string & object_name,
    4412             :                                      const std::string & var_param_name)
    4413             : {
    4414             :   // Due to objects like SolutionUserObject which manipulate libmesh objects
    4415             :   // and variables directly at the back end, we need a default option here
    4416             :   // which is going to be the pointer to the first solver system within this
    4417             :   // problem
    4418      135859 :   unsigned int sys_num = 0;
    4419      135859 :   if (parameters.isParamValid(var_param_name))
    4420             :   {
    4421       59442 :     const auto variable_name = parameters.varName(var_param_name, object_name);
    4422       59442 :     if (this->hasVariable(variable_name) || this->hasScalarVariable(variable_name))
    4423       57825 :       sys_num = getSystem(variable_name).number();
    4424       59442 :   }
    4425      271718 :   if (parameters.isParamValid("solver_sys"))
    4426             :   {
    4427         921 :     const auto var_sys_num = sys_num;
    4428         921 :     sys_num = getSystemBase(parameters.get<SolverSystemName>("solver_sys")).number();
    4429         921 :     if (sys_num != var_sys_num && parameters.isParamValid(var_param_name))
    4430           0 :       mooseError("We dont support setting 'variable' to a variable that is not set to the same "
    4431             :                  "system as the 'solver_sys' parameter");
    4432             :   }
    4433             : 
    4434      137142 :   if (_displaced_problem && parameters.have_parameter<bool>("use_displaced_mesh") &&
    4435      137142 :       parameters.get<bool>("use_displaced_mesh"))
    4436             :   {
    4437        1260 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    4438         630 :     if (sys_num == _aux->number())
    4439        1197 :       parameters.set<SystemBase *>("_sys") = &_displaced_problem->systemBaseAuxiliary();
    4440             :     else
    4441         693 :       parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(sys_num);
    4442             :   }
    4443             :   else
    4444             :   {
    4445             :     // The object requested use_displaced_mesh, but it was overridden
    4446             :     // due to there being no displacements variables in the [Mesh] block.
    4447             :     // If that happened, update the value of use_displaced_mesh appropriately.
    4448      234728 :     if (!_displaced_problem && parameters.have_parameter<bool>("use_displaced_mesh") &&
    4449      234728 :         parameters.get<bool>("use_displaced_mesh"))
    4450         146 :       parameters.set<bool>("use_displaced_mesh") = false;
    4451             : 
    4452      270458 :     parameters.set<SubProblem *>("_subproblem") = this;
    4453             : 
    4454      135229 :     if (sys_num == _aux->number())
    4455       38538 :       parameters.set<SystemBase *>("_sys") = _aux.get();
    4456             :     else
    4457      367149 :       parameters.set<SystemBase *>("_sys") = _solver_systems[sys_num].get();
    4458             :   }
    4459      135859 : }
    4460             : 
    4461             : void
    4462       55268 : FEProblemBase::addPostprocessor(const std::string & pp_name,
    4463             :                                 const std::string & name,
    4464             :                                 InputParameters & parameters)
    4465             : {
    4466             :   // Check for name collision
    4467       55268 :   if (hasUserObject(name))
    4468           4 :     mooseError("A ",
    4469           4 :                getUserObjectBase(name).typeAndName(),
    4470             :                " already exists. You may not add a Postprocessor by the same name.");
    4471             : 
    4472       55264 :   addUserObject(pp_name, name, parameters);
    4473       55228 : }
    4474             : 
    4475             : void
    4476        5806 : FEProblemBase::addVectorPostprocessor(const std::string & pp_name,
    4477             :                                       const std::string & name,
    4478             :                                       InputParameters & parameters)
    4479             : {
    4480             :   // Check for name collision
    4481        5806 :   if (hasUserObject(name))
    4482           4 :     mooseError("A ",
    4483           4 :                getUserObjectBase(name).typeAndName(),
    4484             :                " already exists. You may not add a VectorPostprocessor by the same name.");
    4485             : 
    4486        5802 :   addUserObject(pp_name, name, parameters);
    4487        5762 : }
    4488             : 
    4489             : void
    4490        4916 : FEProblemBase::addReporter(const std::string & type,
    4491             :                            const std::string & name,
    4492             :                            InputParameters & parameters)
    4493             : {
    4494             :   // Check for name collision
    4495        4916 :   if (hasUserObject(name))
    4496           4 :     mooseError("A ",
    4497           4 :                getUserObjectBase(name).typeAndName(),
    4498             :                " already exists. You may not add a Reporter by the same name.");
    4499             : 
    4500        4912 :   addUserObject(type, name, parameters);
    4501        4868 : }
    4502             : 
    4503             : std::vector<std::shared_ptr<UserObject>>
    4504       80001 : FEProblemBase::addUserObject(const std::string & user_object_name,
    4505             :                              const std::string & name,
    4506             :                              InputParameters & parameters)
    4507             : {
    4508             :   parallel_object_only();
    4509             : 
    4510       80001 :   std::vector<std::shared_ptr<UserObject>> uos;
    4511             : 
    4512             :   // Add the _subproblem and _sys parameters depending on use_displaced_mesh
    4513       80001 :   addObjectParamsHelper(parameters, name);
    4514             : 
    4515      127381 :   for (const auto tid : make_range(libMesh::n_threads()))
    4516             :   {
    4517             :     // Create the UserObject
    4518             :     std::shared_ptr<UserObject> user_object =
    4519       83592 :         _factory.create<UserObject>(user_object_name, name, parameters, tid);
    4520       83212 :     logAdd("UserObject", name, user_object_name, parameters);
    4521       83212 :     uos.push_back(user_object);
    4522             : 
    4523       83212 :     if (tid != 0)
    4524        3591 :       user_object->setPrimaryThreadCopy(uos[0].get());
    4525             : 
    4526             :     // TODO: delete this line after apps have been updated to not call getUserObjects
    4527       83212 :     _all_user_objects.addObject(user_object, tid);
    4528             : 
    4529       83204 :     theWarehouse().add(user_object);
    4530             : 
    4531             :     // Attempt to create all the possible UserObject types
    4532       83204 :     auto euo = std::dynamic_pointer_cast<ElementUserObject>(user_object);
    4533       83204 :     auto suo = std::dynamic_pointer_cast<SideUserObject>(user_object);
    4534       83204 :     auto isuo = std::dynamic_pointer_cast<InternalSideUserObject>(user_object);
    4535       83204 :     auto iuo = std::dynamic_pointer_cast<InterfaceUserObjectBase>(user_object);
    4536       83204 :     auto nuo = std::dynamic_pointer_cast<NodalUserObject>(user_object);
    4537       83204 :     auto duo = std::dynamic_pointer_cast<DomainUserObject>(user_object);
    4538       83204 :     auto guo = std::dynamic_pointer_cast<GeneralUserObject>(user_object);
    4539       83204 :     auto tguo = std::dynamic_pointer_cast<ThreadedGeneralUserObject>(user_object);
    4540       83204 :     auto muo = std::dynamic_pointer_cast<MortarUserObject>(user_object);
    4541             : 
    4542             :     // Account for displaced mesh use
    4543       83204 :     if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    4544             :     {
    4545             :       // Whether to re-init or not depends on the attributes of the base classes.
    4546             :       // For example, InterfaceUOBase has "_current_side_elem" and "_neighbor_elem"
    4547             :       // so it needs to reinit on displaced neighbors and faces
    4548             :       // _reinit_displaced_elem -> _current_elem will be reinited
    4549             :       // _reinit_displaced_face -> _current_elem, lowerD if any and _current_side_elem to be
    4550             :       // reinited _reinit_displaced_neighbor -> _current_elem, lowerD if any and _current_neighbor
    4551             :       // to be reinited Note that as soon as you use materials on the displaced mesh, all three get
    4552             :       // turned on.
    4553         680 :       if (euo || nuo || duo)
    4554         606 :         _reinit_displaced_elem = true;
    4555         680 :       if (suo || duo || isuo || iuo)
    4556          35 :         _reinit_displaced_face = true;
    4557         680 :       if (iuo || duo || isuo)
    4558           0 :         _reinit_displaced_neighbor = true;
    4559             :     }
    4560             : 
    4561             :     // These objects only require one thread
    4562       83204 :     if ((guo && !tguo) || muo)
    4563       35824 :       break;
    4564      405620 :   }
    4565             : 
    4566             :   // Add as a Functor if it is one. We usually need to add the user object from thread 0 as the
    4567             :   // registered functor for all threads because when user objects are thread joined, generally only
    4568             :   // the primary thread copy ends up with all the data
    4569      166347 :   for (const auto tid : make_range(libMesh::n_threads()))
    4570             :   {
    4571       86734 :     const decltype(uos)::size_type uo_index = uos.front()->needThreadedCopy() ? tid : 0;
    4572       86734 :     if (const auto functor = dynamic_cast<Moose::FunctorBase<Real> *>(uos[uo_index].get()))
    4573             :     {
    4574       65251 :       this->addFunctor(name, *functor, tid);
    4575       65251 :       if (_displaced_problem)
    4576         804 :         _displaced_problem->addFunctor(name, *functor, tid);
    4577             :     }
    4578             :   }
    4579             : 
    4580       79613 :   return uos;
    4581          16 : }
    4582             : 
    4583             : const UserObject &
    4584      330329 : FEProblemBase::getUserObjectBase(const std::string & name, const THREAD_ID tid /* = 0 */) const
    4585             : {
    4586      330329 :   std::vector<UserObject *> objs;
    4587      330329 :   theWarehouse()
    4588      660658 :       .query()
    4589      330329 :       .condition<AttribSystem>("UserObject")
    4590      330329 :       .condition<AttribThread>(tid)
    4591      330329 :       .condition<AttribName>(name)
    4592      330329 :       .queryInto(objs);
    4593      330329 :   if (objs.empty())
    4594           0 :     mooseError("Unable to find user object with name '" + name + "'");
    4595             :   mooseAssert(objs.size() == 1, "Should only find one UO");
    4596      660658 :   return *(objs[0]);
    4597      330329 : }
    4598             : 
    4599             : const Positions &
    4600        1154 : FEProblemBase::getPositionsObject(const std::string & name) const
    4601             : {
    4602        1154 :   std::vector<Positions *> objs;
    4603        1154 :   theWarehouse()
    4604        2308 :       .query()
    4605        1154 :       .condition<AttribSystem>("UserObject")
    4606        1154 :       .condition<AttribName>(name)
    4607        1154 :       .queryInto(objs);
    4608        1154 :   if (objs.empty())
    4609           0 :     mooseError("Unable to find Positions object with name '" + name + "'");
    4610             :   mooseAssert(objs.size() == 1, "Should only find one Positions");
    4611        2308 :   return *(objs[0]);
    4612        1154 : }
    4613             : 
    4614             : bool
    4615       93668 : FEProblemBase::hasUserObject(const std::string & name) const
    4616             : {
    4617       93668 :   std::vector<UserObject *> objs;
    4618       93668 :   theWarehouse()
    4619       93668 :       .query()
    4620       93668 :       .condition<AttribSystem>("UserObject")
    4621      187336 :       .condition<AttribThread>(0)
    4622       93668 :       .condition<AttribName>(name)
    4623       93668 :       .queryInto(objs);
    4624      187336 :   return !objs.empty();
    4625       93668 : }
    4626             : 
    4627             : bool
    4628         477 : FEProblemBase::hasPostprocessorValueByName(const PostprocessorName & name) const
    4629             : {
    4630         477 :   return _reporter_data.hasReporterValue<PostprocessorValue>(PostprocessorReporterName(name));
    4631             : }
    4632             : 
    4633             : const PostprocessorValue &
    4634      910767 : FEProblemBase::getPostprocessorValueByName(const PostprocessorName & name,
    4635             :                                            std::size_t t_index) const
    4636             : {
    4637     1821534 :   return _reporter_data.getReporterValue<PostprocessorValue>(PostprocessorReporterName(name),
    4638     1821534 :                                                              t_index);
    4639             : }
    4640             : 
    4641             : void
    4642      602504 : FEProblemBase::setPostprocessorValueByName(const PostprocessorName & name,
    4643             :                                            const PostprocessorValue & value,
    4644             :                                            std::size_t t_index)
    4645             : {
    4646      602504 :   _reporter_data.setReporterValue<PostprocessorValue>(
    4647     1205008 :       PostprocessorReporterName(name), value, t_index);
    4648      602504 : }
    4649             : 
    4650             : bool
    4651          56 : FEProblemBase::hasPostprocessor(const std::string & name) const
    4652             : {
    4653          56 :   mooseDeprecated("FEProblemBase::hasPostprocssor is being removed; use "
    4654             :                   "hasPostprocessorValueByName instead.");
    4655          56 :   return hasPostprocessorValueByName(name);
    4656             : }
    4657             : 
    4658             : const VectorPostprocessorValue &
    4659          57 : FEProblemBase::getVectorPostprocessorValueByName(const std::string & object_name,
    4660             :                                                  const std::string & vector_name,
    4661             :                                                  std::size_t t_index) const
    4662             : {
    4663          57 :   return _reporter_data.getReporterValue<VectorPostprocessorValue>(
    4664         114 :       VectorPostprocessorReporterName(object_name, vector_name), t_index);
    4665             : }
    4666             : 
    4667             : void
    4668          20 : FEProblemBase::setVectorPostprocessorValueByName(const std::string & object_name,
    4669             :                                                  const std::string & vector_name,
    4670             :                                                  const VectorPostprocessorValue & value,
    4671             :                                                  std::size_t t_index)
    4672             : {
    4673          20 :   _reporter_data.setReporterValue<VectorPostprocessorValue>(
    4674          40 :       VectorPostprocessorReporterName(object_name, vector_name), value, t_index);
    4675          20 : }
    4676             : 
    4677             : const VectorPostprocessor &
    4678        9268 : FEProblemBase::getVectorPostprocessorObjectByName(const std::string & object_name,
    4679             :                                                   const THREAD_ID tid) const
    4680             : {
    4681        9268 :   return getUserObject<VectorPostprocessor>(object_name, tid);
    4682             : }
    4683             : 
    4684             : void
    4685          77 : FEProblemBase::parentOutputPositionChanged()
    4686             : {
    4687        2156 :   for (const auto & it : _multi_apps)
    4688             :   {
    4689        2079 :     const auto & objects = it.second.getActiveObjects();
    4690        2100 :     for (const auto & obj : objects)
    4691          21 :       obj->parentOutputPositionChanged();
    4692             :   }
    4693          77 : }
    4694             : 
    4695             : void
    4696           0 : FEProblemBase::computeIndicatorsAndMarkers()
    4697             : {
    4698           0 :   computeIndicators();
    4699           0 :   computeMarkers();
    4700           0 : }
    4701             : 
    4702             : void
    4703      240268 : FEProblemBase::computeIndicators()
    4704             : {
    4705             :   // Initialize indicator aux variable fields
    4706      240268 :   if (_indicators.hasActiveObjects() || _internal_side_indicators.hasActiveObjects())
    4707             :   {
    4708       12880 :     TIME_SECTION("computeIndicators", 1, "Computing Indicators");
    4709             : 
    4710             :     // Internal side indicators may lead to creating a much larger sparsity pattern than dictated by
    4711             :     // the actual finite element scheme (e.g. CFEM)
    4712        2576 :     const auto old_do_derivatives = ADReal::do_derivatives;
    4713        2576 :     ADReal::do_derivatives = false;
    4714             : 
    4715        2576 :     std::vector<std::string> fields;
    4716             : 
    4717             :     // Indicator Fields
    4718        2576 :     const auto & indicators = _indicators.getActiveObjects();
    4719        2736 :     for (const auto & indicator : indicators)
    4720         160 :       fields.push_back(indicator->name());
    4721             : 
    4722             :     // InternalSideIndicator Fields
    4723        2576 :     const auto & internal_indicators = _internal_side_indicators.getActiveObjects();
    4724        5056 :     for (const auto & internal_indicator : internal_indicators)
    4725        2480 :       fields.push_back(internal_indicator->name());
    4726             : 
    4727        2576 :     _aux->zeroVariables(fields);
    4728             : 
    4729             :     // compute Indicators
    4730        2576 :     ComputeIndicatorThread cit(*this);
    4731        2576 :     Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), cit);
    4732        2576 :     _aux->solution().close();
    4733        2576 :     _aux->update();
    4734             : 
    4735        2576 :     ComputeIndicatorThread finalize_cit(*this, true);
    4736        2576 :     Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), finalize_cit);
    4737        2576 :     _aux->solution().close();
    4738        2576 :     _aux->update();
    4739             : 
    4740        2576 :     ADReal::do_derivatives = old_do_derivatives;
    4741        2576 :   }
    4742      240268 : }
    4743             : 
    4744             : void
    4745      240292 : FEProblemBase::computeMarkers()
    4746             : {
    4747      240292 :   if (_markers.hasActiveObjects())
    4748             :   {
    4749       35360 :     TIME_SECTION("computeMarkers", 1, "Computing Markers");
    4750             : 
    4751        7072 :     std::vector<std::string> fields;
    4752             : 
    4753             :     // Marker Fields
    4754        7072 :     const auto & markers = _markers.getActiveObjects();
    4755       15122 :     for (const auto & marker : markers)
    4756        8050 :       fields.push_back(marker->name());
    4757             : 
    4758        7072 :     _aux->zeroVariables(fields);
    4759             : 
    4760        7072 :     _adaptivity.updateErrorVectors();
    4761             : 
    4762       14764 :     for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    4763             :     {
    4764        7696 :       const auto & markers = _markers.getActiveObjects(tid);
    4765       16453 :       for (const auto & marker : markers)
    4766        8761 :         marker->markerSetup();
    4767             :     }
    4768             : 
    4769        7068 :     ComputeMarkerThread cmt(*this);
    4770        7068 :     Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), cmt);
    4771             : 
    4772        7068 :     _aux->solution().close();
    4773        7068 :     _aux->update();
    4774        7068 :   }
    4775      240288 : }
    4776             : 
    4777             : const ExecFlagType &
    4778     2743361 : FEProblemBase::getCurrentExecuteOnFlag() const
    4779             : {
    4780     2743361 :   return _current_execute_on_flag;
    4781             : }
    4782             : 
    4783             : void
    4784     7490384 : FEProblemBase::setCurrentExecuteOnFlag(const ExecFlagType & flag)
    4785             : {
    4786     7490384 :   _current_execute_on_flag = flag;
    4787     7490384 : }
    4788             : 
    4789             : void
    4790          80 : FEProblemBase::executeAllObjects(const ExecFlagType & /*exec_type*/)
    4791             : {
    4792          80 : }
    4793             : 
    4794             : void
    4795     1921055 : FEProblemBase::customSetup(const ExecFlagType & exec_type)
    4796             : {
    4797     1921055 :   SubProblem::customSetup(exec_type);
    4798             : 
    4799     1921055 :   if (_line_search)
    4800           0 :     _line_search->customSetup(exec_type);
    4801             : 
    4802     1921055 :   unsigned int n_threads = libMesh::n_threads();
    4803     4013807 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    4804             :   {
    4805     2092752 :     _all_materials.customSetup(exec_type, tid);
    4806     2092752 :     _functions.customSetup(exec_type, tid);
    4807             :   }
    4808             : 
    4809     1921055 :   _aux->customSetup(exec_type);
    4810     3872716 :   for (auto & nl : _nl)
    4811     1951661 :     nl->customSetup(exec_type);
    4812             : 
    4813     1921055 :   if (_displaced_problem)
    4814      158920 :     _displaced_problem->customSetup(exec_type);
    4815             : 
    4816     4013807 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    4817             :   {
    4818     2092752 :     _internal_side_indicators.customSetup(exec_type, tid);
    4819     2092752 :     _indicators.customSetup(exec_type, tid);
    4820     2092752 :     _markers.customSetup(exec_type, tid);
    4821             :   }
    4822             : 
    4823     1921055 :   std::vector<UserObject *> userobjs;
    4824     1921055 :   theWarehouse().query().condition<AttribSystem>("UserObject").queryIntoUnsorted(userobjs);
    4825     4769651 :   for (auto obj : userobjs)
    4826     2848596 :     obj->customSetup(exec_type);
    4827             : 
    4828     1921055 :   _app.getOutputWarehouse().customSetup(exec_type);
    4829     1921055 : }
    4830             : 
    4831             : void
    4832     2320065 : FEProblemBase::execute(const ExecFlagType & exec_type)
    4833             : {
    4834             :   // Set the current flag
    4835     2320065 :   setCurrentExecuteOnFlag(exec_type);
    4836             : 
    4837     2320065 :   if (exec_type != EXEC_INITIAL)
    4838     2262302 :     executeControls(exec_type);
    4839             : 
    4840             :   // intentially call this after executing controls because the setups may rely on the controls
    4841             :   // FIXME: we skip the following flags because they have dedicated setup functions in
    4842             :   //        SetupInterface and it may not be appropriate to call them here.
    4843     4243816 :   if (!(exec_type == EXEC_INITIAL || exec_type == EXEC_TIMESTEP_BEGIN ||
    4844     1923775 :         exec_type == EXEC_SUBDOMAIN || exec_type == EXEC_NONLINEAR || exec_type == EXEC_LINEAR))
    4845     1921055 :     customSetup(exec_type);
    4846             : 
    4847             :   // Samplers; EXEC_INITIAL is not called because the Sampler::init() method that is called after
    4848             :   // construction makes the first Sampler::execute() call. This ensures that the random number
    4849             :   // generator object is the correct state prior to any other object (e.g., Transfers) attempts to
    4850             :   // extract data from the Sampler. That is, if the Sampler::execute() call is delayed to here
    4851             :   // then it is not in the correct state for other objects.
    4852     2320041 :   if (exec_type != EXEC_INITIAL)
    4853     2262278 :     executeSamplers(exec_type);
    4854             : 
    4855             :   // Pre-aux UserObjects
    4856     2320009 :   computeUserObjects(exec_type, Moose::PRE_AUX);
    4857             : 
    4858             :   // Systems (includes system time derivative and aux kernel calculations)
    4859     2320009 :   computeSystems(exec_type);
    4860             :   // With the auxiliary system solution computed, sync the displaced problem auxiliary solution
    4861             :   // before computation of post-aux user objects. The undisplaced auxiliary system current local
    4862             :   // solution is updated (via System::update) within the AuxiliarySystem class's variable
    4863             :   // computation methods (e.g. computeElementalVarsHelper, computeNodalVarsHelper), so it is safe to
    4864             :   // use it here
    4865     2319964 :   if (_displaced_problem)
    4866      196607 :     _displaced_problem->syncAuxSolution(*getAuxiliarySystem().currentSolution());
    4867             : 
    4868             :   // Post-aux UserObjects
    4869     2319964 :   computeUserObjects(exec_type, Moose::POST_AUX);
    4870             : 
    4871             :   // Return the current flag to None
    4872     2319847 :   setCurrentExecuteOnFlag(EXEC_NONE);
    4873             : 
    4874     2319847 :   if (_uo_aux_state_check && !_checking_uo_aux_state)
    4875             :   {
    4876             :     // we will only check aux variables and postprocessors
    4877             :     // checking more reporter data can be added in the future if needed
    4878         624 :     std::unique_ptr<NumericVector<Number>> x = _aux->currentSolution()->clone();
    4879         624 :     DenseVector<Real> pp_values = getReporterData().getAllRealReporterValues();
    4880             : 
    4881             :     // call THIS execute one more time for checking the possible states
    4882         624 :     _checking_uo_aux_state = true;
    4883         624 :     FEProblemBase::execute(exec_type);
    4884         624 :     _checking_uo_aux_state = false;
    4885             : 
    4886         624 :     const Real check_tol = 1e-8;
    4887             : 
    4888         624 :     const Real xnorm = x->l2_norm();
    4889         624 :     *x -= *_aux->currentSolution();
    4890         624 :     if (x->l2_norm() > check_tol * xnorm)
    4891             :     {
    4892           4 :       const auto & sys = _aux->system();
    4893           4 :       const unsigned int n_vars = sys.n_vars();
    4894           4 :       std::multimap<Real, std::string, std::greater<Real>> ordered_map;
    4895          20 :       for (const auto i : make_range(n_vars))
    4896             :       {
    4897          16 :         const Real vnorm = sys.calculate_norm(*x, i, DISCRETE_L2);
    4898          16 :         ordered_map.emplace(vnorm, sys.variable_name(i));
    4899             :       }
    4900             : 
    4901           4 :       std::ostringstream oss;
    4902          20 :       for (const auto & [error_norm, var_name] : ordered_map)
    4903          16 :         oss << "  {" << var_name << ", " << error_norm << "},\n";
    4904             : 
    4905           4 :       mooseError("Aux kernels, user objects appear to have states for aux variables on ",
    4906             :                  exec_type,
    4907             :                  ".\nVariable error norms in descending order:\n",
    4908           4 :                  oss.str());
    4909           0 :     }
    4910             : 
    4911         620 :     const DenseVector<Real> new_pp_values = getReporterData().getAllRealReporterValues();
    4912         620 :     if (pp_values.size() != new_pp_values.size())
    4913           0 :       mooseError("Second execution for uo/aux state check should not change the number of "
    4914             :                  "real reporter values");
    4915             : 
    4916         620 :     const Real ppnorm = pp_values.l2_norm();
    4917         620 :     pp_values -= new_pp_values;
    4918         620 :     if (pp_values.l2_norm() > check_tol * ppnorm)
    4919             :     {
    4920           4 :       const auto pp_names = getReporterData().getAllRealReporterFullNames();
    4921           4 :       std::multimap<Real, std::string, std::greater<Real>> ordered_map;
    4922          16 :       for (const auto i : index_range(pp_names))
    4923          12 :         ordered_map.emplace(std::abs(pp_values(i)), pp_names[i]);
    4924             : 
    4925           4 :       std::ostringstream oss;
    4926          16 :       for (const auto & [error_norm, pp_name] : ordered_map)
    4927          12 :         oss << "  {" << pp_name << ", " << error_norm << "},\n";
    4928             : 
    4929           4 :       mooseError("Aux kernels, user objects appear to have states for real reporter values on ",
    4930             :                  exec_type,
    4931             :                  ".\nErrors of real reporter values in descending order:\n",
    4932           4 :                  oss.str());
    4933           0 :     }
    4934         616 :   }
    4935     2319839 : }
    4936             : 
    4937             : // Finalize, threadJoin, and update PP values of Elemental/Nodal/Side/InternalSideUserObjects
    4938             : void
    4939     1426820 : FEProblemBase::joinAndFinalize(TheWarehouse::Query query, bool isgen)
    4940             : {
    4941     1426820 :   std::vector<UserObject *> objs;
    4942     1426820 :   query.queryInto(objs);
    4943     1426820 :   if (!isgen)
    4944             :   {
    4945             :     // join all threaded user objects (i.e. not regular general user objects) to the primary
    4946             :     // thread
    4947     1509993 :     for (auto obj : objs)
    4948      392120 :       if (obj->primaryThreadCopy())
    4949       29155 :         obj->primaryThreadCopy()->threadJoin(*obj);
    4950             :   }
    4951             : 
    4952     1426820 :   query.condition<AttribThread>(0).queryInto(objs);
    4953             : 
    4954             :   // finalize objects and retrieve/store any postprocessor values
    4955     2034038 :   for (auto obj : objs)
    4956             :   {
    4957      607327 :     if (isgen && dynamic_cast<ThreadedGeneralUserObject *>(obj))
    4958         116 :       continue;
    4959      607211 :     if (isgen)
    4960             :     {
    4961             :       // general user objects are not run in their own threaded loop object - so run them here
    4962      244246 :       if (shouldPrintExecution(0))
    4963         798 :         _console << "[DBG] Initializing, executing & finalizing general UO '" << obj->name()
    4964         798 :                  << "' on " << _current_execute_on_flag.name() << std::endl;
    4965      244246 :       obj->initialize();
    4966      244246 :       obj->execute();
    4967             :     }
    4968             : 
    4969      607142 :     obj->finalize();
    4970             : 
    4971             :     // These have to be stored piecemeal (with every call to this function) because general
    4972             :     // postprocessors (which run last after other userobjects have been completed) might depend on
    4973             :     // them being stored.  This wouldn't be a problem if all userobjects satisfied the dependency
    4974             :     // resolver interface and could be sorted appropriately with the general userobjects, but they
    4975             :     // don't.
    4976      607122 :     auto pp = dynamic_cast<const Postprocessor *>(obj);
    4977      607122 :     if (pp)
    4978             :     {
    4979      528737 :       _reporter_data.finalize(obj->name());
    4980      528737 :       setPostprocessorValueByName(obj->name(), pp->getValue());
    4981             :     }
    4982             : 
    4983      607110 :     auto vpp = dynamic_cast<VectorPostprocessor *>(obj);
    4984      607110 :     if (vpp)
    4985       14358 :       _reporter_data.finalize(obj->name());
    4986             : 
    4987             :     // Update Reporter data
    4988      607110 :     auto reporter = dynamic_cast<Reporter *>(obj);
    4989      607110 :     if (reporter)
    4990        5391 :       _reporter_data.finalize(obj->name());
    4991             :   }
    4992     1426711 : }
    4993             : 
    4994             : void
    4995       57176 : FEProblemBase::computeUserObjectByName(const ExecFlagType & type,
    4996             :                                        const Moose::AuxGroup & group,
    4997             :                                        const std::string & name)
    4998             : {
    4999       57176 :   const auto old_exec_flag = _current_execute_on_flag;
    5000       57176 :   _current_execute_on_flag = type;
    5001       57176 :   TheWarehouse::Query query = theWarehouse()
    5002      114352 :                                   .query()
    5003       57176 :                                   .condition<AttribSystem>("UserObject")
    5004       57176 :                                   .condition<AttribExecOns>(type)
    5005       57176 :                                   .condition<AttribName>(name);
    5006       57176 :   computeUserObjectsInternal(type, group, query);
    5007       57176 :   _current_execute_on_flag = old_exec_flag;
    5008       57176 : }
    5009             : 
    5010             : void
    5011    12451312 : FEProblemBase::computeUserObjects(const ExecFlagType & type, const Moose::AuxGroup & group)
    5012             : {
    5013             :   TheWarehouse::Query query =
    5014    12451312 :       theWarehouse().query().condition<AttribSystem>("UserObject").condition<AttribExecOns>(type);
    5015    12451312 :   computeUserObjectsInternal(type, group, query);
    5016    12451195 : }
    5017             : 
    5018             : void
    5019    12508488 : FEProblemBase::computeUserObjectsInternal(const ExecFlagType & type,
    5020             :                                           const Moose::AuxGroup & group,
    5021             :                                           TheWarehouse::Query & primary_query)
    5022             : {
    5023             :   try
    5024             :   {
    5025    62542440 :     TIME_SECTION("computeUserObjects", 1, "Computing User Objects");
    5026             : 
    5027             :     // Add group to query
    5028    12508488 :     if (group == Moose::PRE_IC)
    5029       57823 :       primary_query.condition<AttribPreIC>(true);
    5030    12450665 :     else if (group == Moose::PRE_AUX)
    5031     6225097 :       primary_query.condition<AttribPreAux>(type);
    5032     6225568 :     else if (group == Moose::POST_AUX)
    5033     6225524 :       primary_query.condition<AttribPostAux>(type);
    5034             : 
    5035             :     // query everything first to obtain a list of execution groups
    5036    12508488 :     std::vector<UserObject *> uos;
    5037    12508488 :     primary_query.clone().queryIntoUnsorted(uos);
    5038    12508488 :     std::set<int> execution_groups;
    5039    13144990 :     for (const auto & uo : uos)
    5040     1909506 :       execution_groups.insert(uo->getParam<int>("execution_order_group"));
    5041             : 
    5042             :     // iterate over execution order groups
    5043    12817334 :     for (const auto execution_group : execution_groups)
    5044             :     {
    5045      308963 :       auto query = primary_query.clone().condition<AttribExecutionOrderGroup>(execution_group);
    5046             : 
    5047      308963 :       std::vector<GeneralUserObject *> genobjs;
    5048      308963 :       query.clone().condition<AttribInterfaces>(Interfaces::GeneralUserObject).queryInto(genobjs);
    5049             : 
    5050      308963 :       std::vector<UserObject *> userobjs;
    5051      308963 :       query.clone()
    5052      617926 :           .condition<AttribInterfaces>(Interfaces::ElementUserObject | Interfaces::SideUserObject |
    5053             :                                        Interfaces::InternalSideUserObject |
    5054      617926 :                                        Interfaces::InterfaceUserObject |
    5055             :                                        Interfaces::DomainUserObject)
    5056      308963 :           .queryInto(userobjs);
    5057             : 
    5058      308963 :       std::vector<UserObject *> tgobjs;
    5059      308963 :       query.clone()
    5060      617926 :           .condition<AttribInterfaces>(Interfaces::ThreadedGeneralUserObject)
    5061      308963 :           .queryInto(tgobjs);
    5062             : 
    5063      308963 :       std::vector<UserObject *> nodal;
    5064      308963 :       query.clone().condition<AttribInterfaces>(Interfaces::NodalUserObject).queryInto(nodal);
    5065             : 
    5066      308963 :       std::vector<MortarUserObject *> mortar;
    5067      308963 :       query.clone().condition<AttribInterfaces>(Interfaces::MortarUserObject).queryInto(mortar);
    5068             : 
    5069      308963 :       if (userobjs.empty() && genobjs.empty() && tgobjs.empty() && nodal.empty() && mortar.empty())
    5070           0 :         continue;
    5071             : 
    5072             :       // Start the timer here since we have at least one active user object
    5073      308963 :       std::string compute_uo_tag = "computeUserObjects(" + Moose::stringify(type) + ")";
    5074             : 
    5075             :       // Perform Residual/Jacobian setups
    5076      308963 :       if (type == EXEC_LINEAR)
    5077             :       {
    5078      132237 :         for (auto obj : userobjs)
    5079       74488 :           obj->residualSetup();
    5080       62541 :         for (auto obj : nodal)
    5081        4792 :           obj->residualSetup();
    5082       57749 :         for (auto obj : mortar)
    5083           0 :           obj->residualSetup();
    5084       57749 :         for (auto obj : tgobjs)
    5085           0 :           obj->residualSetup();
    5086       69324 :         for (auto obj : genobjs)
    5087       11575 :           obj->residualSetup();
    5088             :       }
    5089      251214 :       else if (type == EXEC_NONLINEAR)
    5090             :       {
    5091       11622 :         for (auto obj : userobjs)
    5092        2809 :           obj->jacobianSetup();
    5093        9237 :         for (auto obj : nodal)
    5094         424 :           obj->jacobianSetup();
    5095        8813 :         for (auto obj : mortar)
    5096           0 :           obj->jacobianSetup();
    5097        8813 :         for (auto obj : tgobjs)
    5098           0 :           obj->jacobianSetup();
    5099       24077 :         for (auto obj : genobjs)
    5100       15264 :           obj->jacobianSetup();
    5101             :       }
    5102             : 
    5103      678211 :       for (auto obj : userobjs)
    5104      369248 :         obj->initialize();
    5105             : 
    5106             :       // Execute Side/InternalSide/Interface/Elemental/DomainUserObjects
    5107      308963 :       if (!userobjs.empty())
    5108             :       {
    5109             :         // non-nodal user objects have to be run separately before the nodal user objects run
    5110             :         // because some nodal user objects (NodalNormal related) depend on elemental user objects
    5111             :         // :-(
    5112      219987 :         ComputeUserObjectsThread cppt(*this, query);
    5113      219987 :         Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), cppt);
    5114             : 
    5115             :         // There is one instance in rattlesnake where an elemental user object's finalize depends
    5116             :         // on a side user object having been finalized first :-(
    5117      219979 :         joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::SideUserObject));
    5118      219975 :         joinAndFinalize(
    5119      439950 :             query.clone().condition<AttribInterfaces>(Interfaces::InternalSideUserObject));
    5120      219975 :         joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::InterfaceUserObject));
    5121      219975 :         joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::ElementUserObject));
    5122      219971 :         joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::DomainUserObject));
    5123      219971 :       }
    5124             : 
    5125             :       // if any userobject may have written to variables we need to close the aux solution
    5126      678093 :       for (const auto & uo : userobjs)
    5127      369182 :         if (auto euo = dynamic_cast<const ElementUserObject *>(uo);
    5128      369182 :             euo && euo->hasWritableCoupledVariables())
    5129             :         {
    5130          36 :           _aux->solution().close();
    5131          36 :           _aux->system().update();
    5132          36 :           break;
    5133             :         }
    5134             : 
    5135             :       // Execute NodalUserObjects
    5136             :       // BISON has an axial reloc elemental user object that has a finalize func that depends on a
    5137             :       // nodal user object's prev value. So we can't initialize this until after elemental objects
    5138             :       // have been finalized :-(
    5139      331407 :       for (auto obj : nodal)
    5140       22460 :         obj->initialize();
    5141      308947 :       if (query.clone().condition<AttribInterfaces>(Interfaces::NodalUserObject).count() > 0)
    5142             :       {
    5143       17882 :         ComputeNodalUserObjectsThread cnppt(*this, query);
    5144       17882 :         Threads::parallel_reduce(*_mesh.getLocalNodeRange(), cnppt);
    5145       17882 :         joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::NodalUserObject));
    5146       17882 :       }
    5147             : 
    5148             :       // if any userobject may have written to variables we need to close the aux solution
    5149      331368 :       for (const auto & uo : nodal)
    5150       22445 :         if (auto nuo = dynamic_cast<const NodalUserObject *>(uo);
    5151       22445 :             nuo && nuo->hasWritableCoupledVariables())
    5152             :         {
    5153          24 :           _aux->solution().close();
    5154          24 :           _aux->system().update();
    5155          24 :           break;
    5156             :         }
    5157             : 
    5158             :       // Execute MortarUserObjects
    5159             :       {
    5160      308971 :         for (auto obj : mortar)
    5161          24 :           obj->initialize();
    5162      308947 :         if (!mortar.empty())
    5163             :         {
    5164          36 :           auto create_and_run_mortar_functors = [this, type, &mortar](const bool displaced)
    5165             :           {
    5166             :             // go over mortar interfaces and construct functors
    5167          36 :             const auto & mortar_interfaces = getMortarInterfaces(displaced);
    5168          60 :             for (const auto & [primary_secondary_boundary_pair, mortar_generation_ptr] :
    5169          96 :                  mortar_interfaces)
    5170             :             {
    5171             :               auto mortar_uos_to_execute =
    5172          24 :                   getMortarUserObjects(primary_secondary_boundary_pair.first,
    5173          24 :                                        primary_secondary_boundary_pair.second,
    5174             :                                        displaced,
    5175          24 :                                        mortar);
    5176             : 
    5177             :               auto * const subproblem = displaced
    5178          24 :                                             ? static_cast<SubProblem *>(_displaced_problem.get())
    5179          24 :                                             : static_cast<SubProblem *>(this);
    5180             :               MortarUserObjectThread muot(mortar_uos_to_execute,
    5181          24 :                                           *mortar_generation_ptr,
    5182             :                                           *subproblem,
    5183             :                                           *this,
    5184             :                                           displaced,
    5185          24 :                                           subproblem->assembly(0, 0));
    5186             : 
    5187          24 :               muot();
    5188          24 :             }
    5189          60 :           };
    5190             : 
    5191          24 :           create_and_run_mortar_functors(false);
    5192          24 :           if (_displaced_problem)
    5193          12 :             create_and_run_mortar_functors(true);
    5194          24 :         }
    5195      308971 :         for (auto obj : mortar)
    5196          24 :           obj->finalize();
    5197             :       }
    5198             : 
    5199             :       // Execute threaded general user objects
    5200      309399 :       for (auto obj : tgobjs)
    5201         452 :         obj->initialize();
    5202      308947 :       std::vector<GeneralUserObject *> tguos_zero;
    5203      308947 :       query.clone()
    5204      308947 :           .condition<AttribThread>(0)
    5205      617894 :           .condition<AttribInterfaces>(Interfaces::ThreadedGeneralUserObject)
    5206      308947 :           .queryInto(tguos_zero);
    5207      309063 :       for (auto obj : tguos_zero)
    5208             :       {
    5209         116 :         std::vector<GeneralUserObject *> tguos;
    5210         116 :         auto q = query.clone()
    5211         116 :                      .condition<AttribName>(obj->name())
    5212         116 :                      .condition<AttribInterfaces>(Interfaces::ThreadedGeneralUserObject);
    5213         116 :         q.queryInto(tguos);
    5214             : 
    5215         116 :         ComputeThreadedGeneralUserObjectsThread ctguot(*this);
    5216         116 :         Threads::parallel_reduce(GeneralUserObjectRange(tguos.begin(), tguos.end()), ctguot);
    5217         116 :         joinAndFinalize(q);
    5218         116 :       }
    5219             : 
    5220             :       // Execute general user objects
    5221      308947 :       joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::GeneralUserObject),
    5222             :                       true);
    5223      308846 :     }
    5224    12508371 :   }
    5225           0 :   catch (...)
    5226             :   {
    5227           0 :     handleException("computeUserObjectsInternal");
    5228           0 :   }
    5229    12508371 : }
    5230             : 
    5231             : void
    5232     6200570 : FEProblemBase::executeControls(const ExecFlagType & exec_type)
    5233             : {
    5234     6200570 :   if (_control_warehouse[exec_type].hasActiveObjects())
    5235             :   {
    5236       41685 :     TIME_SECTION("executeControls", 1, "Executing Controls");
    5237             : 
    5238        8337 :     DependencyResolver<std::shared_ptr<Control>> resolver;
    5239             : 
    5240        8337 :     auto controls_wh = _control_warehouse[exec_type];
    5241             :     // Add all of the dependencies into the resolver and sort them
    5242       20920 :     for (const auto & it : controls_wh.getActiveObjects())
    5243             :     {
    5244             :       // Make sure an item with no dependencies comes out too!
    5245       12587 :       resolver.addItem(it);
    5246             : 
    5247       12587 :       std::vector<std::string> & dependent_controls = it->getDependencies();
    5248       15712 :       for (const auto & depend_name : dependent_controls)
    5249             :       {
    5250        3129 :         if (controls_wh.hasActiveObject(depend_name))
    5251             :         {
    5252        3125 :           auto dep_control = controls_wh.getActiveObject(depend_name);
    5253        3125 :           resolver.addEdge(dep_control, it);
    5254        3125 :         }
    5255             :         else
    5256           4 :           mooseError("The Control \"",
    5257             :                      depend_name,
    5258             :                      "\" was not created, did you make a "
    5259             :                      "spelling mistake or forget to include it "
    5260             :                      "in your input file?");
    5261             :       }
    5262             :     }
    5263             : 
    5264        8333 :     const auto & ordered_controls = resolver.getSortedValues();
    5265             : 
    5266        8333 :     if (!ordered_controls.empty())
    5267             :     {
    5268        8333 :       _control_warehouse.setup(exec_type);
    5269             :       // Run the controls in the proper order
    5270       20860 :       for (const auto & control : ordered_controls)
    5271       12583 :         control->execute();
    5272             :     }
    5273        8277 :   }
    5274     6200510 : }
    5275             : 
    5276             : void
    5277     2262278 : FEProblemBase::executeSamplers(const ExecFlagType & exec_type)
    5278             : {
    5279             :   // TODO: This should be done in a threaded loop, but this should be super quick so for now
    5280             :   // do a serial loop.
    5281     4726188 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    5282             :   {
    5283     2463942 :     std::vector<Sampler *> objects;
    5284     2463942 :     theWarehouse()
    5285     4927884 :         .query()
    5286     2463942 :         .condition<AttribSystem>("Sampler")
    5287     2463942 :         .condition<AttribThread>(tid)
    5288     2463942 :         .condition<AttribExecOns>(exec_type)
    5289     2463942 :         .queryInto(objects);
    5290             : 
    5291     2463942 :     if (!objects.empty())
    5292             :     {
    5293         275 :       TIME_SECTION("executeSamplers", 1, "Executing Samplers");
    5294          55 :       FEProblemBase::objectSetupHelper<Sampler>(objects, exec_type);
    5295          55 :       FEProblemBase::objectExecuteHelper<Sampler>(objects);
    5296          23 :     }
    5297     2463910 :   }
    5298     2262246 : }
    5299             : 
    5300             : void
    5301      338486 : FEProblemBase::updateActiveObjects()
    5302             : {
    5303     1692430 :   TIME_SECTION("updateActiveObjects", 5, "Updating Active Objects");
    5304             : 
    5305      706714 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    5306             :   {
    5307      738980 :     for (auto & nl : _nl)
    5308      370752 :       nl->updateActive(tid);
    5309      368228 :     _aux->updateActive(tid);
    5310      368228 :     _indicators.updateActive(tid);
    5311      368228 :     _internal_side_indicators.updateActive(tid);
    5312      368228 :     _markers.updateActive(tid);
    5313      368228 :     _all_materials.updateActive(tid);
    5314      368228 :     _materials.updateActive(tid);
    5315      368228 :     _discrete_materials.updateActive(tid);
    5316             :   }
    5317             : 
    5318      338486 :   _control_warehouse.updateActive();
    5319      338486 :   _multi_apps.updateActive();
    5320      338486 :   _transient_multi_apps.updateActive();
    5321      338486 :   _transfers.updateActive();
    5322      338486 :   _to_multi_app_transfers.updateActive();
    5323      338486 :   _from_multi_app_transfers.updateActive();
    5324      338486 :   _between_multi_app_transfers.updateActive();
    5325             : 
    5326             : #ifdef MOOSE_KOKKOS_ENABLED
    5327      223035 :   _kokkos_materials.updateActive();
    5328             : #endif
    5329      338486 : }
    5330             : 
    5331             : void
    5332           0 : FEProblemBase::reportMooseObjectDependency(MooseObject * /*a*/, MooseObject * /*b*/)
    5333             : {
    5334             :   //<< "Object " << a->name() << " -> " << b->name() << std::endl;
    5335           0 : }
    5336             : 
    5337             : void
    5338       70243 : FEProblemBase::reinitBecauseOfGhostingOrNewGeomObjects(const bool mortar_changed)
    5339             : {
    5340      351215 :   TIME_SECTION("reinitBecauseOfGhostingOrNewGeomObjects",
    5341             :                3,
    5342             :                "Reinitializing Because of Geometric Search Objects");
    5343             : 
    5344             :   // Need to see if _any_ processor has ghosted elems or geometry objects.
    5345       70243 :   bool needs_reinit = !_ghosted_elems.empty();
    5346      140076 :   needs_reinit = needs_reinit || !_geometric_search_data._nearest_node_locators.empty() ||
    5347       69833 :                  (_mortar_data->hasObjects() && mortar_changed);
    5348       70243 :   needs_reinit =
    5349      142029 :       needs_reinit || (_displaced_problem &&
    5350        5002 :                        (!_displaced_problem->geomSearchData()._nearest_node_locators.empty() ||
    5351       71149 :                         (_mortar_data->hasDisplacedObjects() && mortar_changed)));
    5352       70243 :   _communicator.max(needs_reinit);
    5353             : 
    5354       70243 :   if (needs_reinit)
    5355             :   {
    5356             :     // Call reinit to get the ghosted vectors correct now that some geometric search has been done
    5357        2354 :     es().reinit();
    5358             : 
    5359        2354 :     if (_displaced_mesh)
    5360        1748 :       _displaced_problem->es().reinit();
    5361             :   }
    5362       70243 : }
    5363             : 
    5364             : void
    5365         181 : FEProblemBase::addDamper(const std::string & damper_name,
    5366             :                          const std::string & name,
    5367             :                          InputParameters & parameters)
    5368             : {
    5369             :   parallel_object_only();
    5370             : 
    5371             :   const auto nl_sys_num =
    5372         181 :       parameters.isParamValid("variable")
    5373         582 :           ? determineSolverSystem(parameters.varName("variable", name), true).second
    5374         177 :           : (unsigned int)0;
    5375             : 
    5376         177 :   if (!isSolverSystemNonlinear(nl_sys_num))
    5377           0 :     mooseError("You are trying to add a DGKernel to a linear variable/system, which is not "
    5378             :                "supported at the moment!");
    5379             : 
    5380         354 :   parameters.set<SubProblem *>("_subproblem") = this;
    5381         354 :   parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
    5382             : 
    5383         177 :   _has_dampers = true;
    5384         177 :   logAdd("Damper", name, damper_name, parameters);
    5385         177 :   _nl[nl_sys_num]->addDamper(damper_name, name, parameters);
    5386         177 : }
    5387             : 
    5388             : void
    5389         163 : FEProblemBase::setupDampers()
    5390             : {
    5391         326 :   for (auto & nl : _nl)
    5392         163 :     nl->setupDampers();
    5393         163 : }
    5394             : 
    5395             : void
    5396         697 : FEProblemBase::addIndicator(const std::string & indicator_name,
    5397             :                             const std::string & name,
    5398             :                             InputParameters & parameters)
    5399             : {
    5400             :   parallel_object_only();
    5401             : 
    5402         697 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    5403             :   {
    5404           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    5405           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    5406           0 :     _reinit_displaced_elem = true;
    5407             :   }
    5408             :   else
    5409             :   {
    5410         697 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    5411             :     {
    5412             :       // We allow Indicators to request that they use_displaced_mesh,
    5413             :       // but then be overridden when no displacements variables are
    5414             :       // provided in the Mesh block.  If that happened, update the value
    5415             :       // of use_displaced_mesh appropriately for this Indicator.
    5416           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    5417           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    5418             :     }
    5419             : 
    5420        1394 :     parameters.set<SubProblem *>("_subproblem") = this;
    5421        2091 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    5422             :   }
    5423             : 
    5424        1456 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    5425             :   {
    5426             :     std::shared_ptr<Indicator> indicator =
    5427         759 :         _factory.create<Indicator>(indicator_name, name, parameters, tid);
    5428         759 :     logAdd("Indicator", name, indicator_name, parameters);
    5429             :     std::shared_ptr<InternalSideIndicatorBase> isi =
    5430         759 :         std::dynamic_pointer_cast<InternalSideIndicatorBase>(indicator);
    5431         759 :     if (isi)
    5432         650 :       _internal_side_indicators.addObject(isi, tid);
    5433             :     else
    5434         109 :       _indicators.addObject(indicator, tid);
    5435         759 :   }
    5436         697 : }
    5437             : 
    5438             : void
    5439        2095 : FEProblemBase::addMarker(const std::string & marker_name,
    5440             :                          const std::string & name,
    5441             :                          InputParameters & parameters)
    5442             : {
    5443             :   parallel_object_only();
    5444             : 
    5445        2095 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    5446             :   {
    5447           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    5448           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    5449           0 :     _reinit_displaced_elem = true;
    5450             :   }
    5451             :   else
    5452             :   {
    5453        2095 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    5454             :     {
    5455             :       // We allow Markers to request that they use_displaced_mesh,
    5456             :       // but then be overridden when no displacements variables are
    5457             :       // provided in the Mesh block.  If that happened, update the value
    5458             :       // of use_displaced_mesh appropriately for this Marker.
    5459           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    5460           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    5461             :     }
    5462             : 
    5463        4190 :     parameters.set<SubProblem *>("_subproblem") = this;
    5464        6285 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    5465             :   }
    5466             : 
    5467        4360 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    5468             :   {
    5469        2269 :     std::shared_ptr<Marker> marker = _factory.create<Marker>(marker_name, name, parameters, tid);
    5470        2265 :     logAdd("Marker", name, marker_name, parameters);
    5471        2265 :     _markers.addObject(marker, tid);
    5472        2265 :   }
    5473        2091 : }
    5474             : 
    5475             : void
    5476        7672 : FEProblemBase::addMultiApp(const std::string & multi_app_name,
    5477             :                            const std::string & name,
    5478             :                            InputParameters & parameters)
    5479             : {
    5480             :   parallel_object_only();
    5481             : 
    5482       15344 :   parameters.set<MPI_Comm>("_mpi_comm") = _communicator.get();
    5483             : 
    5484        7672 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    5485             :   {
    5486           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    5487           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    5488           0 :     _reinit_displaced_elem = true;
    5489             :   }
    5490             :   else
    5491             :   {
    5492        7672 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    5493             :     {
    5494             :       // We allow MultiApps to request that they use_displaced_mesh,
    5495             :       // but then be overridden when no displacements variables are
    5496             :       // provided in the Mesh block.  If that happened, update the value
    5497             :       // of use_displaced_mesh appropriately for this MultiApp.
    5498          49 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    5499          98 :         parameters.set<bool>("use_displaced_mesh") = false;
    5500             :     }
    5501             : 
    5502       15344 :     parameters.set<SubProblem *>("_subproblem") = this;
    5503       23016 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    5504             :   }
    5505             : 
    5506        7672 :   std::shared_ptr<MultiApp> multi_app = _factory.create<MultiApp>(multi_app_name, name, parameters);
    5507        7656 :   logAdd("MultiApp", name, multi_app_name, parameters);
    5508        7656 :   multi_app->setupPositions();
    5509             : 
    5510        7541 :   _multi_apps.addObject(multi_app);
    5511             : 
    5512             :   // Store TransientMultiApp objects in another container, this is needed for calling computeDT
    5513             :   std::shared_ptr<TransientMultiApp> trans_multi_app =
    5514        7541 :       std::dynamic_pointer_cast<TransientMultiApp>(multi_app);
    5515        7541 :   if (trans_multi_app)
    5516        5401 :     _transient_multi_apps.addObject(trans_multi_app);
    5517        7541 : }
    5518             : 
    5519             : bool
    5520      120680 : FEProblemBase::hasMultiApps(ExecFlagType type) const
    5521             : {
    5522      120680 :   return _multi_apps[type].hasActiveObjects();
    5523             : }
    5524             : 
    5525             : bool
    5526           0 : FEProblemBase::hasMultiApp(const std::string & multi_app_name) const
    5527             : {
    5528           0 :   return _multi_apps.hasActiveObject(multi_app_name);
    5529             : }
    5530             : 
    5531             : std::shared_ptr<MultiApp>
    5532       24983 : FEProblemBase::getMultiApp(const std::string & multi_app_name) const
    5533             : {
    5534       24983 :   return _multi_apps.getObject(multi_app_name);
    5535             : }
    5536             : 
    5537             : void
    5538    15707297 : FEProblemBase::execMultiAppTransfers(ExecFlagType type, Transfer::DIRECTION direction)
    5539             : {
    5540    15707297 :   bool to_multiapp = direction == MultiAppTransfer::TO_MULTIAPP;
    5541    15707297 :   bool from_multiapp = direction == MultiAppTransfer::FROM_MULTIAPP;
    5542    15707297 :   std::string string_direction;
    5543    15707297 :   if (to_multiapp)
    5544     5235838 :     string_direction = " To ";
    5545    10471459 :   else if (from_multiapp)
    5546     5235669 :     string_direction = " From ";
    5547             :   else
    5548     5235790 :     string_direction = " Between ";
    5549             : 
    5550    15707514 :   const MooseObjectWarehouse<Transfer> & wh = to_multiapp     ? _to_multi_app_transfers[type]
    5551    26178635 :                                               : from_multiapp ? _from_multi_app_transfers[type]
    5552    36650311 :                                                               : _between_multi_app_transfers[type];
    5553             : 
    5554    15707297 :   if (wh.hasActiveObjects())
    5555             :   {
    5556      570085 :     TIME_SECTION("execMultiAppTransfers", 1, "Executing Transfers");
    5557             : 
    5558      114017 :     const auto & transfers = wh.getActiveObjects();
    5559             : 
    5560      114017 :     if (_verbose_multiapps)
    5561             :     {
    5562        2486 :       _console << COLOR_CYAN << "\nTransfers on " << Moose::stringify(type) << string_direction
    5563        2486 :                << "MultiApps" << COLOR_DEFAULT << ":" << std::endl;
    5564             : 
    5565             :       VariadicTable<std::string, std::string, std::string, std::string> table(
    5566        4972 :           {"Name", "Type", "From", "To"});
    5567             : 
    5568             :       // Build Table of Transfer Info
    5569        5932 :       for (const auto & transfer : transfers)
    5570             :       {
    5571        3446 :         auto multiapp_transfer = dynamic_cast<MultiAppTransfer *>(transfer.get());
    5572             : 
    5573        3446 :         table.addRow(multiapp_transfer->name(),
    5574        3446 :                      multiapp_transfer->type(),
    5575        6892 :                      multiapp_transfer->getFromName(),
    5576        6892 :                      multiapp_transfer->getToName());
    5577             :       }
    5578             : 
    5579             :       // Print it
    5580        2486 :       table.print(_console);
    5581        2486 :     }
    5582             : 
    5583      233099 :     for (const auto & transfer : transfers)
    5584             :     {
    5585      119205 :       transfer->setCurrentDirection(direction);
    5586      119205 :       transfer->execute();
    5587             :     }
    5588             : 
    5589      113894 :     MooseUtils::parallelBarrierNotify(_communicator, _parallel_barrier_messaging);
    5590             : 
    5591      113894 :     if (_verbose_multiapps)
    5592        4956 :       _console << COLOR_CYAN << "Transfers on " << Moose::stringify(type) << " Are Finished\n"
    5593        2478 :                << COLOR_DEFAULT << std::endl;
    5594      113894 :   }
    5595    15593280 :   else if (_multi_apps[type].getActiveObjects().size())
    5596             :   {
    5597      116089 :     if (_verbose_multiapps)
    5598        7988 :       _console << COLOR_CYAN << "\nNo Transfers on " << Moose::stringify(type) << string_direction
    5599        3994 :                << "MultiApps\n"
    5600        3994 :                << COLOR_DEFAULT << std::endl;
    5601             :   }
    5602    15707174 : }
    5603             : 
    5604             : std::vector<std::shared_ptr<Transfer>>
    5605          13 : FEProblemBase::getTransfers(ExecFlagType type, Transfer::DIRECTION direction) const
    5606             : {
    5607          13 :   if (direction == MultiAppTransfer::TO_MULTIAPP)
    5608          13 :     return _to_multi_app_transfers[type].getActiveObjects();
    5609           0 :   else if (direction == MultiAppTransfer::FROM_MULTIAPP)
    5610           0 :     return _from_multi_app_transfers[type].getActiveObjects();
    5611             :   else
    5612           0 :     return _between_multi_app_transfers[type].getActiveObjects();
    5613             : }
    5614             : 
    5615             : std::vector<std::shared_ptr<Transfer>>
    5616           0 : FEProblemBase::getTransfers(Transfer::DIRECTION direction) const
    5617             : {
    5618           0 :   if (direction == MultiAppTransfer::TO_MULTIAPP)
    5619           0 :     return _to_multi_app_transfers.getActiveObjects();
    5620           0 :   else if (direction == MultiAppTransfer::FROM_MULTIAPP)
    5621           0 :     return _from_multi_app_transfers.getActiveObjects();
    5622             :   else
    5623           0 :     return _between_multi_app_transfers.getActiveObjects();
    5624             : }
    5625             : 
    5626             : const ExecuteMooseObjectWarehouse<Transfer> &
    5627           0 : FEProblemBase::getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
    5628             : {
    5629           0 :   if (direction == MultiAppTransfer::TO_MULTIAPP)
    5630           0 :     return _to_multi_app_transfers;
    5631           0 :   else if (direction == MultiAppTransfer::FROM_MULTIAPP)
    5632           0 :     return _from_multi_app_transfers;
    5633             :   else
    5634           0 :     return _between_multi_app_transfers;
    5635             : }
    5636             : 
    5637             : bool
    5638     5235842 : FEProblemBase::execMultiApps(ExecFlagType type, bool auto_advance)
    5639             : {
    5640             :   // Active MultiApps
    5641             :   const std::vector<MooseSharedPointer<MultiApp>> & multi_apps =
    5642     5235842 :       _multi_apps[type].getActiveObjects();
    5643             : 
    5644             :   // Do anything that needs to be done to Apps before transfers
    5645     5303788 :   for (const auto & multi_app : multi_apps)
    5646       67950 :     multi_app->preTransfer(_dt, _time);
    5647             : 
    5648             :   // Execute Transfers _to_ MultiApps
    5649     5235838 :   execMultiAppTransfers(type, MultiAppTransfer::TO_MULTIAPP);
    5650             : 
    5651             :   // Execute Transfers _between_ Multiapps
    5652     5235790 :   execMultiAppTransfers(type, MultiAppTransfer::BETWEEN_MULTIAPP);
    5653             : 
    5654             :   // Execute MultiApps
    5655     5235790 :   if (multi_apps.size())
    5656             :   {
    5657      333535 :     TIME_SECTION("execMultiApps", 1, "Executing MultiApps", false);
    5658             : 
    5659       66707 :     if (_verbose_multiapps)
    5660        4192 :       _console << COLOR_CYAN << "\nExecuting MultiApps on " << Moose::stringify(type)
    5661        2096 :                << COLOR_DEFAULT << std::endl;
    5662             : 
    5663       66707 :     bool success = true;
    5664             : 
    5665      134481 :     for (const auto & multi_app : multi_apps)
    5666             :     {
    5667       67887 :       success = multi_app->solveStep(_dt, _time, auto_advance);
    5668             :       // no need to finish executing the subapps if one fails
    5669       67875 :       if (!success)
    5670         101 :         break;
    5671             :     }
    5672             : 
    5673       66695 :     MooseUtils::parallelBarrierNotify(_communicator, _parallel_barrier_messaging);
    5674             : 
    5675       66695 :     _communicator.min(success);
    5676             : 
    5677       66695 :     if (!success)
    5678         109 :       return false;
    5679             : 
    5680       66586 :     if (_verbose_multiapps)
    5681        4192 :       _console << COLOR_CYAN << "Finished Executing MultiApps on " << Moose::stringify(type) << "\n"
    5682        2096 :                << COLOR_DEFAULT << std::endl;
    5683       66695 :   }
    5684             : 
    5685             :   // Execute Transfers _from_ MultiApps
    5686     5235669 :   execMultiAppTransfers(type, MultiAppTransfer::FROM_MULTIAPP);
    5687             : 
    5688             :   // If we made it here then everything passed
    5689     5235594 :   return true;
    5690             : }
    5691             : 
    5692             : void
    5693       50166 : FEProblemBase::finalizeMultiApps()
    5694             : {
    5695       50166 :   const auto & multi_apps = _multi_apps.getActiveObjects();
    5696             : 
    5697       56525 :   for (const auto & multi_app : multi_apps)
    5698        6359 :     multi_app->finalize();
    5699       50166 : }
    5700             : 
    5701             : void
    5702       51766 : FEProblemBase::postExecute()
    5703             : {
    5704       51766 :   const auto & multi_apps = _multi_apps.getActiveObjects();
    5705             : 
    5706       58482 :   for (const auto & multi_app : multi_apps)
    5707        6716 :     multi_app->postExecute();
    5708       51766 : }
    5709             : 
    5710             : void
    5711      725316 : FEProblemBase::incrementMultiAppTStep(ExecFlagType type)
    5712             : {
    5713      725316 :   const auto & multi_apps = _multi_apps[type].getActiveObjects();
    5714             : 
    5715      725316 :   if (multi_apps.size())
    5716       28639 :     for (const auto & multi_app : multi_apps)
    5717       14497 :       multi_app->incrementTStep(_time);
    5718      725316 : }
    5719             : 
    5720             : void
    5721       39872 : FEProblemBase::finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels)
    5722             : {
    5723       39872 :   const auto & multi_apps = _multi_apps[type].getActiveObjects();
    5724             : 
    5725       39872 :   if (multi_apps.size())
    5726             :   {
    5727        9407 :     if (_verbose_multiapps)
    5728         416 :       _console << COLOR_CYAN << "\nAdvancing MultiApps on " << type.name() << COLOR_DEFAULT
    5729         416 :                << std::endl;
    5730             : 
    5731       18828 :     for (const auto & multi_app : multi_apps)
    5732        9421 :       multi_app->finishStep(recurse_through_multiapp_levels);
    5733             : 
    5734        9407 :     MooseUtils::parallelBarrierNotify(_communicator, _parallel_barrier_messaging);
    5735             : 
    5736        9407 :     if (_verbose_multiapps)
    5737         416 :       _console << COLOR_CYAN << "Finished Advancing MultiApps on " << type.name() << "\n"
    5738         416 :                << COLOR_DEFAULT << std::endl;
    5739             :   }
    5740       39872 : }
    5741             : 
    5742             : void
    5743     1215209 : FEProblemBase::backupMultiApps(ExecFlagType type)
    5744             : {
    5745     1215209 :   const auto & multi_apps = _multi_apps[type].getActiveObjects();
    5746             : 
    5747     1215209 :   if (multi_apps.size())
    5748             :   {
    5749      106985 :     TIME_SECTION("backupMultiApps", 5, "Backing Up MultiApp");
    5750             : 
    5751       21397 :     if (_verbose_multiapps)
    5752        1007 :       _console << COLOR_CYAN << "\nBacking Up MultiApps on " << type.name() << COLOR_DEFAULT
    5753        1007 :                << std::endl;
    5754             : 
    5755       43915 :     for (const auto & multi_app : multi_apps)
    5756       22518 :       multi_app->backup();
    5757             : 
    5758       21397 :     MooseUtils::parallelBarrierNotify(_communicator, _parallel_barrier_messaging);
    5759             : 
    5760       21397 :     if (_verbose_multiapps)
    5761        1007 :       _console << COLOR_CYAN << "Finished Backing Up MultiApps on " << type.name() << "\n"
    5762        1007 :                << COLOR_DEFAULT << std::endl;
    5763       21397 :   }
    5764     1215209 : }
    5765             : 
    5766             : void
    5767      118916 : FEProblemBase::restoreMultiApps(ExecFlagType type, bool force)
    5768             : {
    5769      118916 :   const auto & multi_apps = _multi_apps[type].getActiveObjects();
    5770             : 
    5771      118916 :   if (multi_apps.size())
    5772             :   {
    5773       45872 :     if (_verbose_multiapps)
    5774             :     {
    5775        1092 :       if (force)
    5776           3 :         _console << COLOR_CYAN << "\nRestoring Multiapps on " << type.name()
    5777           3 :                  << " because of solve failure!" << COLOR_DEFAULT << std::endl;
    5778             :       else
    5779        1089 :         _console << COLOR_CYAN << "\nRestoring MultiApps on " << type.name() << COLOR_DEFAULT
    5780        1089 :                  << std::endl;
    5781             :     }
    5782             : 
    5783       91829 :     for (const auto & multi_app : multi_apps)
    5784       45961 :       multi_app->restore(force);
    5785             : 
    5786       45868 :     MooseUtils::parallelBarrierNotify(_communicator, _parallel_barrier_messaging);
    5787             : 
    5788       45868 :     if (_verbose_multiapps)
    5789        1092 :       _console << COLOR_CYAN << "Finished Restoring MultiApps on " << type.name() << "\n"
    5790        1092 :                << COLOR_DEFAULT << std::endl;
    5791             :   }
    5792      118912 : }
    5793             : 
    5794             : Real
    5795      753976 : FEProblemBase::computeMultiAppsDT(ExecFlagType type)
    5796             : {
    5797      753976 :   const auto & multi_apps = _transient_multi_apps[type].getActiveObjects();
    5798             : 
    5799      753976 :   Real smallest_dt = std::numeric_limits<Real>::max();
    5800             : 
    5801      772502 :   for (const auto & multi_app : multi_apps)
    5802       18526 :     smallest_dt = std::min(smallest_dt, multi_app->computeDT());
    5803             : 
    5804      753976 :   return smallest_dt;
    5805             : }
    5806             : 
    5807             : void
    5808     5180625 : FEProblemBase::execTransfers(ExecFlagType type)
    5809             : {
    5810     5180625 :   if (_transfers[type].hasActiveObjects())
    5811             :   {
    5812           0 :     TIME_SECTION("execTransfers", 3, "Executing Transfers");
    5813             : 
    5814           0 :     const auto & transfers = _transfers[type].getActiveObjects();
    5815             : 
    5816           0 :     for (const auto & transfer : transfers)
    5817           0 :       transfer->execute();
    5818           0 :   }
    5819     5180625 : }
    5820             : 
    5821             : void
    5822       12603 : FEProblemBase::addTransfer(const std::string & transfer_name,
    5823             :                            const std::string & name,
    5824             :                            InputParameters & parameters)
    5825             : {
    5826             :   parallel_object_only();
    5827             : 
    5828       12603 :   if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
    5829             :   {
    5830           0 :     parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
    5831           0 :     parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
    5832           0 :     _reinit_displaced_elem = true;
    5833             :   }
    5834             :   else
    5835             :   {
    5836       12603 :     if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
    5837             :     {
    5838             :       // We allow Transfers to request that they use_displaced_mesh,
    5839             :       // but then be overridden when no displacements variables are
    5840             :       // provided in the Mesh block.  If that happened, update the value
    5841             :       // of use_displaced_mesh appropriately for this Transfer.
    5842           0 :       if (parameters.have_parameter<bool>("use_displaced_mesh"))
    5843           0 :         parameters.set<bool>("use_displaced_mesh") = false;
    5844             :     }
    5845             : 
    5846       25206 :     parameters.set<SubProblem *>("_subproblem") = this;
    5847       37809 :     parameters.set<SystemBase *>("_sys") = _aux.get();
    5848             :   }
    5849             : 
    5850             :   // Handle the "SAME_AS_MULTIAPP" execute option. The get method is used to test for the
    5851             :   // flag so the set by user flag is not reset, calling set with the true flag causes the set
    5852             :   // by user status to be reset, which should only be done if the EXEC_SAME_AS_MULTIAPP is
    5853             :   // being applied to the object.
    5854       12603 :   if (parameters.get<ExecFlagEnum>("execute_on").isValueSet(EXEC_SAME_AS_MULTIAPP))
    5855             :   {
    5856       10280 :     ExecFlagEnum & exec_enum = parameters.set<ExecFlagEnum>("execute_on", true);
    5857       10280 :     std::shared_ptr<MultiApp> multiapp;
    5858       20560 :     if (parameters.isParamValid("multi_app"))
    5859          56 :       multiapp = getMultiApp(parameters.get<MultiAppName>("multi_app"));
    5860             :     // This catches the sibling transfer case, where we want to be executing only as often as the
    5861             :     // receiving application. A transfer 'to' a multiapp is executed before that multiapp
    5862       20448 :     else if (parameters.isParamValid("to_multi_app"))
    5863        5465 :       multiapp = getMultiApp(parameters.get<MultiAppName>("to_multi_app"));
    5864        9518 :     else if (parameters.isParamValid("from_multi_app"))
    5865        4751 :       multiapp = getMultiApp(parameters.get<MultiAppName>("from_multi_app"));
    5866             :     // else do nothing because the user has provided invalid input. They should get a nice error
    5867             :     // about this during transfer construction. This necessitates checking for null in this next
    5868             :     // line, however
    5869       10280 :     if (multiapp)
    5870       30816 :       exec_enum = multiapp->getParam<ExecFlagEnum>("execute_on");
    5871       10280 :   }
    5872             : 
    5873             :   // Create the Transfer objects
    5874       12603 :   std::shared_ptr<Transfer> transfer = _factory.create<Transfer>(transfer_name, name, parameters);
    5875       12527 :   logAdd("Transfer", name, transfer_name, parameters);
    5876             : 
    5877             :   // Add MultiAppTransfer object
    5878             :   std::shared_ptr<MultiAppTransfer> multi_app_transfer =
    5879       12527 :       std::dynamic_pointer_cast<MultiAppTransfer>(transfer);
    5880       12527 :   if (multi_app_transfer)
    5881             :   {
    5882       12527 :     if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::TO_MULTIAPP))
    5883        5352 :       _to_multi_app_transfers.addObject(multi_app_transfer);
    5884       12527 :     if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::FROM_MULTIAPP))
    5885        5979 :       _from_multi_app_transfers.addObject(multi_app_transfer);
    5886       12527 :     if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::BETWEEN_MULTIAPP))
    5887        1196 :       _between_multi_app_transfers.addObject(multi_app_transfer);
    5888             :   }
    5889             :   else
    5890           0 :     _transfers.addObject(transfer);
    5891       12527 : }
    5892             : 
    5893             : bool
    5894     1511474 : FEProblemBase::hasVariable(const std::string & var_name) const
    5895             : {
    5896     2448915 :   for (auto & sys : _solver_systems)
    5897     1517385 :     if (sys->hasVariable(var_name))
    5898      579944 :       return true;
    5899      931530 :   if (_aux->hasVariable(var_name))
    5900      858980 :     return true;
    5901             : 
    5902       72550 :   return false;
    5903             : }
    5904             : 
    5905             : bool
    5906           0 : FEProblemBase::hasSolverVariable(const std::string & var_name) const
    5907             : {
    5908           0 :   for (auto & sys : _solver_systems)
    5909           0 :     if (sys->hasVariable(var_name))
    5910           0 :       return true;
    5911             : 
    5912           0 :   return false;
    5913             : }
    5914             : 
    5915             : const MooseVariableFieldBase &
    5916     4773522 : FEProblemBase::getVariable(const THREAD_ID tid,
    5917             :                            const std::string & var_name,
    5918             :                            Moose::VarKindType expected_var_type,
    5919             :                            Moose::VarFieldType expected_var_field_type) const
    5920             : {
    5921    14320558 :   return getVariableHelper(
    5922     4773522 :       tid, var_name, expected_var_type, expected_var_field_type, _solver_systems, *_aux);
    5923             : }
    5924             : 
    5925             : MooseVariable &
    5926        8001 : FEProblemBase::getStandardVariable(const THREAD_ID tid, const std::string & var_name)
    5927             : {
    5928       12111 :   for (auto & sys : _solver_systems)
    5929        8001 :     if (sys->hasVariable(var_name))
    5930        3891 :       return sys->getFieldVariable<Real>(tid, var_name);
    5931        4110 :   if (_aux->hasVariable(var_name))
    5932        4106 :     return _aux->getFieldVariable<Real>(tid, var_name);
    5933             : 
    5934           4 :   mooseError("Unknown variable " + var_name);
    5935             : }
    5936             : 
    5937             : MooseVariableFieldBase &
    5938         661 : FEProblemBase::getActualFieldVariable(const THREAD_ID tid, const std::string & var_name)
    5939             : {
    5940         877 :   for (auto & sys : _solver_systems)
    5941         661 :     if (sys->hasVariable(var_name))
    5942         445 :       return sys->getActualFieldVariable<Real>(tid, var_name);
    5943         216 :   if (_aux->hasVariable(var_name))
    5944         216 :     return _aux->getActualFieldVariable<Real>(tid, var_name);
    5945             : 
    5946           0 :   mooseError("Unknown variable " + var_name);
    5947             : }
    5948             : 
    5949             : VectorMooseVariable &
    5950           0 : FEProblemBase::getVectorVariable(const THREAD_ID tid, const std::string & var_name)
    5951             : {
    5952           0 :   for (auto & sys : _solver_systems)
    5953           0 :     if (sys->hasVariable(var_name))
    5954           0 :       return sys->getFieldVariable<RealVectorValue>(tid, var_name);
    5955           0 :   if (_aux->hasVariable(var_name))
    5956           0 :     return _aux->getFieldVariable<RealVectorValue>(tid, var_name);
    5957             : 
    5958           0 :   mooseError("Unknown variable " + var_name);
    5959             : }
    5960             : 
    5961             : ArrayMooseVariable &
    5962         378 : FEProblemBase::getArrayVariable(const THREAD_ID tid, const std::string & var_name)
    5963             : {
    5964         657 :   for (auto & sys : _solver_systems)
    5965         378 :     if (sys->hasVariable(var_name))
    5966          99 :       return sys->getFieldVariable<RealEigenVector>(tid, var_name);
    5967         279 :   if (_aux->hasVariable(var_name))
    5968         279 :     return _aux->getFieldVariable<RealEigenVector>(tid, var_name);
    5969             : 
    5970           0 :   mooseError("Unknown variable " + var_name);
    5971             : }
    5972             : 
    5973             : bool
    5974      190539 : FEProblemBase::hasScalarVariable(const std::string & var_name) const
    5975             : {
    5976      355671 :   for (auto & sys : _solver_systems)
    5977      191162 :     if (sys->hasScalarVariable(var_name))
    5978       26030 :       return true;
    5979      164509 :   if (_aux->hasScalarVariable(var_name))
    5980       12603 :     return true;
    5981             : 
    5982      151906 :   return false;
    5983             : }
    5984             : 
    5985             : MooseVariableScalar &
    5986       56126 : FEProblemBase::getScalarVariable(const THREAD_ID tid, const std::string & var_name)
    5987             : {
    5988       71989 :   for (auto & sys : _solver_systems)
    5989       56126 :     if (sys->hasScalarVariable(var_name))
    5990       40263 :       return sys->getScalarVariable(tid, var_name);
    5991       15863 :   if (_aux->hasScalarVariable(var_name))
    5992       15863 :     return _aux->getScalarVariable(tid, var_name);
    5993             : 
    5994           0 :   mooseError("Unknown variable " + var_name);
    5995             : }
    5996             : 
    5997             : System &
    5998       66486 : FEProblemBase::getSystem(const std::string & var_name)
    5999             : {
    6000       66486 :   const auto [var_in_sys, sys_num] = determineSolverSystem(var_name);
    6001       66486 :   if (var_in_sys)
    6002       47676 :     return _solver_systems[sys_num]->system();
    6003       18810 :   else if (_aux->hasVariable(var_name) || _aux->hasScalarVariable(var_name))
    6004       18810 :     return _aux->system();
    6005             :   else
    6006           0 :     mooseError("Unable to find a system containing the variable " + var_name);
    6007             : }
    6008             : 
    6009             : const RestartableEquationSystems &
    6010           0 : FEProblemBase::getRestartableEquationSystems() const
    6011             : {
    6012           0 :   return _req.get();
    6013             : }
    6014             : 
    6015             : void
    6016      541905 : FEProblemBase::setActiveFEVariableCoupleableMatrixTags(std::set<TagID> & mtags, const THREAD_ID tid)
    6017             : {
    6018      541905 :   SubProblem::setActiveFEVariableCoupleableMatrixTags(mtags, tid);
    6019             : 
    6020      541905 :   if (_displaced_problem)
    6021      114396 :     _displaced_problem->setActiveFEVariableCoupleableMatrixTags(mtags, tid);
    6022      541905 : }
    6023             : 
    6024             : void
    6025     7268948 : FEProblemBase::setActiveFEVariableCoupleableVectorTags(std::set<TagID> & vtags, const THREAD_ID tid)
    6026             : {
    6027     7268948 :   SubProblem::setActiveFEVariableCoupleableVectorTags(vtags, tid);
    6028             : 
    6029     7268948 :   if (_displaced_problem)
    6030      400132 :     _displaced_problem->setActiveFEVariableCoupleableVectorTags(vtags, tid);
    6031     7268948 : }
    6032             : 
    6033             : void
    6034       56031 : FEProblemBase::setActiveScalarVariableCoupleableMatrixTags(std::set<TagID> & mtags,
    6035             :                                                            const THREAD_ID tid)
    6036             : {
    6037       56031 :   SubProblem::setActiveScalarVariableCoupleableMatrixTags(mtags, tid);
    6038             : 
    6039       56031 :   if (_displaced_problem)
    6040           0 :     _displaced_problem->setActiveScalarVariableCoupleableMatrixTags(mtags, tid);
    6041       56031 : }
    6042             : 
    6043             : void
    6044       56031 : FEProblemBase::setActiveScalarVariableCoupleableVectorTags(std::set<TagID> & vtags,
    6045             :                                                            const THREAD_ID tid)
    6046             : {
    6047       56031 :   SubProblem::setActiveScalarVariableCoupleableVectorTags(vtags, tid);
    6048             : 
    6049       56031 :   if (_displaced_problem)
    6050           0 :     _displaced_problem->setActiveScalarVariableCoupleableVectorTags(vtags, tid);
    6051       56031 : }
    6052             : 
    6053             : void
    6054    11293689 : FEProblemBase::setActiveElementalMooseVariables(const std::set<MooseVariableFEBase *> & moose_vars,
    6055             :                                                 const THREAD_ID tid)
    6056             : {
    6057    11293689 :   SubProblem::setActiveElementalMooseVariables(moose_vars, tid);
    6058             : 
    6059    11293689 :   if (_displaced_problem)
    6060      567951 :     _displaced_problem->setActiveElementalMooseVariables(moose_vars, tid);
    6061    11293689 : }
    6062             : 
    6063             : void
    6064     4697794 : FEProblemBase::clearActiveElementalMooseVariables(const THREAD_ID tid)
    6065             : {
    6066     4697794 :   SubProblem::clearActiveElementalMooseVariables(tid);
    6067             : 
    6068     4697794 :   if (_displaced_problem)
    6069      204061 :     _displaced_problem->clearActiveElementalMooseVariables(tid);
    6070     4697794 : }
    6071             : 
    6072             : void
    6073      249320 : FEProblemBase::clearActiveFEVariableCoupleableMatrixTags(const THREAD_ID tid)
    6074             : {
    6075      249320 :   SubProblem::clearActiveFEVariableCoupleableMatrixTags(tid);
    6076             : 
    6077      249320 :   if (_displaced_problem)
    6078       50039 :     _displaced_problem->clearActiveFEVariableCoupleableMatrixTags(tid);
    6079      249320 : }
    6080             : 
    6081             : void
    6082      249320 : FEProblemBase::clearActiveFEVariableCoupleableVectorTags(const THREAD_ID tid)
    6083             : {
    6084      249320 :   SubProblem::clearActiveFEVariableCoupleableVectorTags(tid);
    6085             : 
    6086      249320 :   if (_displaced_problem)
    6087       50039 :     _displaced_problem->clearActiveFEVariableCoupleableVectorTags(tid);
    6088      249320 : }
    6089             : 
    6090             : void
    6091       56031 : FEProblemBase::clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid)
    6092             : {
    6093       56031 :   SubProblem::clearActiveScalarVariableCoupleableMatrixTags(tid);
    6094             : 
    6095       56031 :   if (_displaced_problem)
    6096           0 :     _displaced_problem->clearActiveScalarVariableCoupleableMatrixTags(tid);
    6097       56031 : }
    6098             : 
    6099             : void
    6100       56031 : FEProblemBase::clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid)
    6101             : {
    6102       56031 :   SubProblem::clearActiveScalarVariableCoupleableVectorTags(tid);
    6103             : 
    6104       56031 :   if (_displaced_problem)
    6105           0 :     _displaced_problem->clearActiveScalarVariableCoupleableVectorTags(tid);
    6106       56031 : }
    6107             : 
    6108             : void
    6109     5820403 : FEProblemBase::setActiveMaterialProperties(const std::unordered_set<unsigned int> & mat_prop_ids,
    6110             :                                            const THREAD_ID tid)
    6111             : {
    6112             :   // mark active properties in every material
    6113     7060299 :   for (auto & mat : _all_materials.getObjects(tid))
    6114     1239896 :     mat->setActiveProperties(mat_prop_ids);
    6115     6803723 :   for (auto & mat : _all_materials[Moose::FACE_MATERIAL_DATA].getObjects(tid))
    6116      983320 :     mat->setActiveProperties(mat_prop_ids);
    6117     6803723 :   for (auto & mat : _all_materials[Moose::NEIGHBOR_MATERIAL_DATA].getObjects(tid))
    6118      983320 :     mat->setActiveProperties(mat_prop_ids);
    6119             : 
    6120     5820403 :   _has_active_material_properties[tid] = !mat_prop_ids.empty();
    6121     5820403 : }
    6122             : 
    6123             : bool
    6124   443124545 : FEProblemBase::hasActiveMaterialProperties(const THREAD_ID tid) const
    6125             : {
    6126   443124545 :   return _has_active_material_properties[tid];
    6127             : }
    6128             : 
    6129             : void
    6130     4805217 : FEProblemBase::clearActiveMaterialProperties(const THREAD_ID tid)
    6131             : {
    6132     4805217 :   _has_active_material_properties[tid] = 0;
    6133     4805217 : }
    6134             : 
    6135             : void
    6136       62116 : FEProblemBase::addAnyRedistributers()
    6137             : {
    6138             : #ifdef LIBMESH_ENABLE_AMR
    6139       64536 :   if ((_adaptivity.isOn() || _num_grid_steps) &&
    6140        2420 :       (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    6141        2349 :        _neighbor_material_props.hasStatefulProperties()))
    6142             :   {
    6143             :     // Even on a serialized Mesh, we don't keep our material
    6144             :     // properties serialized, so we'll rely on the callback to
    6145             :     // redistribute() to redistribute properties at the same time
    6146             :     // libMesh is redistributing elements.
    6147          71 :     auto add_redistributer = [this](MooseMesh & mesh,
    6148             :                                     const std::string & redistributer_name,
    6149             :                                     const bool use_displaced_mesh)
    6150             :     {
    6151          71 :       InputParameters redistribute_params = RedistributeProperties::validParams();
    6152          71 :       redistribute_params.set<MooseApp *>(MooseBase::app_param) = &_app;
    6153         142 :       redistribute_params.set<std::string>("for_whom") = this->name();
    6154         213 :       redistribute_params.set<MooseMesh *>("mesh") = &mesh;
    6155          71 :       redistribute_params.set<Moose::RelationshipManagerType>("rm_type") =
    6156             :           Moose::RelationshipManagerType::GEOMETRIC;
    6157         142 :       redistribute_params.set<bool>("use_displaced_mesh") = use_displaced_mesh;
    6158          71 :       redistribute_params.setHitNode(*parameters().getHitNode(), {});
    6159             : 
    6160             :       std::shared_ptr<RedistributeProperties> redistributer =
    6161          71 :           _factory.create<RedistributeProperties>(
    6162         142 :               "RedistributeProperties", redistributer_name, redistribute_params);
    6163             : 
    6164          71 :       if (_material_props.hasStatefulProperties())
    6165          71 :         redistributer->addMaterialPropertyStorage(_material_props);
    6166             : 
    6167          71 :       if (_bnd_material_props.hasStatefulProperties())
    6168          71 :         redistributer->addMaterialPropertyStorage(_bnd_material_props);
    6169             : 
    6170          71 :       if (_neighbor_material_props.hasStatefulProperties())
    6171          71 :         redistributer->addMaterialPropertyStorage(_neighbor_material_props);
    6172             : 
    6173          71 :       mesh.getMesh().add_ghosting_functor(redistributer);
    6174         142 :     };
    6175             : 
    6176          71 :     add_redistributer(_mesh, "mesh_property_redistributer", false);
    6177          71 :     if (_displaced_problem)
    6178           0 :       add_redistributer(_displaced_problem->mesh(), "displaced_mesh_property_redistributer", true);
    6179             :   }
    6180             : #endif // LIBMESH_ENABLE_AMR
    6181       62116 : }
    6182             : 
    6183             : void
    6184       64363 : FEProblemBase::updateMaxQps()
    6185             : {
    6186             :   // Find the maximum number of quadrature points
    6187             :   {
    6188       64363 :     MaxQpsThread mqt(*this);
    6189       64363 :     Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), mqt);
    6190       64363 :     _max_qps = mqt.max();
    6191             : 
    6192             :     // If we have more shape functions or more quadrature points on
    6193             :     // another processor, then we may need to handle those elements
    6194             :     // ourselves later after repartitioning.
    6195       64363 :     _communicator.max(_max_qps);
    6196             :   }
    6197             : 
    6198       64363 :   unsigned int max_qpts = getMaxQps();
    6199       64363 :   if (max_qpts > Moose::constMaxQpsPerElem)
    6200           0 :     mooseError("Max quadrature points per element assumptions made in some code (e.g.  Coupleable ",
    6201             :                "and MaterialPropertyInterface classes) have been violated.\n",
    6202             :                "Complain to Moose developers to have constMaxQpsPerElem increased from ",
    6203             :                Moose::constMaxQpsPerElem,
    6204             :                " to ",
    6205             :                max_qpts);
    6206      134978 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
    6207             :   {
    6208             :     // the highest available order in libMesh is 43
    6209       70615 :     _scalar_zero[tid].resize(FORTYTHIRD, 0);
    6210       70615 :     _zero[tid].resize(max_qpts, 0);
    6211       70615 :     _ad_zero[tid].resize(max_qpts, 0);
    6212       70615 :     _grad_zero[tid].resize(max_qpts, RealGradient(0.));
    6213       70615 :     _ad_grad_zero[tid].resize(max_qpts, ADRealGradient(0));
    6214       70615 :     _second_zero[tid].resize(max_qpts, RealTensor(0.));
    6215       70615 :     _ad_second_zero[tid].resize(max_qpts, ADRealTensorValue(0));
    6216       70615 :     _vector_zero[tid].resize(max_qpts, RealGradient(0.));
    6217       70615 :     _vector_curl_zero[tid].resize(max_qpts, RealGradient(0.));
    6218             :   }
    6219       64363 : }
    6220             : 
    6221             : void
    6222          84 : FEProblemBase::bumpVolumeQRuleOrder(Order order, SubdomainID block)
    6223             : {
    6224         180 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
    6225         192 :     for (const auto i : index_range(_nl))
    6226          96 :       _assembly[tid][i]->bumpVolumeQRuleOrder(order, block);
    6227             : 
    6228          84 :   if (_displaced_problem)
    6229           0 :     _displaced_problem->bumpVolumeQRuleOrder(order, block);
    6230             : 
    6231          84 :   updateMaxQps();
    6232          84 : }
    6233             : 
    6234             : void
    6235          14 : FEProblemBase::bumpAllQRuleOrder(Order order, SubdomainID block)
    6236             : {
    6237          30 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
    6238          32 :     for (const auto i : index_range(_nl))
    6239          16 :       _assembly[tid][i]->bumpAllQRuleOrder(order, block);
    6240             : 
    6241          14 :   if (_displaced_problem)
    6242           0 :     _displaced_problem->bumpAllQRuleOrder(order, block);
    6243             : 
    6244          14 :   updateMaxQps();
    6245          14 : }
    6246             : 
    6247             : void
    6248       64265 : FEProblemBase::createQRules(QuadratureType type,
    6249             :                             Order order,
    6250             :                             Order volume_order,
    6251             :                             Order face_order,
    6252             :                             SubdomainID block,
    6253             :                             const bool allow_negative_qweights)
    6254             : {
    6255       64265 :   if (order == INVALID_ORDER)
    6256             :   {
    6257             :     // automatically determine the integration order
    6258       63758 :     order = _solver_systems[0]->getMinQuadratureOrder();
    6259       64037 :     for (const auto i : make_range(std::size_t(1), _solver_systems.size()))
    6260         279 :       if (order < _solver_systems[i]->getMinQuadratureOrder())
    6261           0 :         order = _solver_systems[i]->getMinQuadratureOrder();
    6262       63758 :     if (order < _aux->getMinQuadratureOrder())
    6263        5616 :       order = _aux->getMinQuadratureOrder();
    6264             :   }
    6265             : 
    6266       64265 :   if (volume_order == INVALID_ORDER)
    6267       64170 :     volume_order = order;
    6268             : 
    6269       64265 :   if (face_order == INVALID_ORDER)
    6270       64170 :     face_order = order;
    6271             : 
    6272      134768 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); ++tid)
    6273      141303 :     for (const auto i : index_range(_solver_systems))
    6274       70800 :       _assembly[tid][i]->createQRules(
    6275             :           type, order, volume_order, face_order, block, allow_negative_qweights);
    6276             : 
    6277       64265 :   if (_displaced_problem)
    6278        2246 :     _displaced_problem->createQRules(
    6279             :         type, order, volume_order, face_order, block, allow_negative_qweights);
    6280             : 
    6281       64265 :   updateMaxQps();
    6282       64265 : }
    6283             : 
    6284             : void
    6285       22768 : FEProblemBase::setCoupling(Moose::CouplingType type)
    6286             : {
    6287       22768 :   if (_trust_user_coupling_matrix)
    6288             :   {
    6289           4 :     if (_coupling != Moose::COUPLING_CUSTOM)
    6290           0 :       mooseError("Someone told us (the FEProblemBase) to trust the user coupling matrix, but we "
    6291             :                  "haven't been provided a coupling matrix!");
    6292             : 
    6293             :     // We've been told to trust the user coupling matrix, so we're going to leave things alone
    6294           4 :     return;
    6295             :   }
    6296             : 
    6297       22764 :   _coupling = type;
    6298             : }
    6299             : 
    6300             : void
    6301           0 : FEProblemBase::setCouplingMatrix(CouplingMatrix * cm, const unsigned int i)
    6302             : {
    6303             :   // TODO: Deprecate method
    6304           0 :   setCoupling(Moose::COUPLING_CUSTOM);
    6305           0 :   _cm[i].reset(cm);
    6306           0 : }
    6307             : 
    6308             : void
    6309       15104 : FEProblemBase::setCouplingMatrix(std::unique_ptr<CouplingMatrix> cm, const unsigned int i)
    6310             : {
    6311       15104 :   setCoupling(Moose::COUPLING_CUSTOM);
    6312       15104 :   _cm[i] = std::move(cm);
    6313       15104 : }
    6314             : 
    6315             : void
    6316           4 : FEProblemBase::trustUserCouplingMatrix()
    6317             : {
    6318           4 :   if (_coupling != Moose::COUPLING_CUSTOM)
    6319           0 :     mooseError("Someone told us (the FEProblemBase) to trust the user coupling matrix, but we "
    6320             :                "haven't been provided a coupling matrix!");
    6321             : 
    6322           4 :   _trust_user_coupling_matrix = true;
    6323           4 : }
    6324             : 
    6325             : void
    6326          81 : FEProblemBase::setNonlocalCouplingMatrix()
    6327             : {
    6328         405 :   TIME_SECTION("setNonlocalCouplingMatrix", 5, "Setting Nonlocal Coupling Matrix");
    6329             : 
    6330          81 :   if (_nl.size() > 1)
    6331           0 :     mooseError("Nonlocal kernels are weirdly stored on the FEProblem so we don't currently support "
    6332             :                "multiple nonlinear systems with nonlocal kernels.");
    6333             : 
    6334         162 :   for (const auto nl_sys_num : index_range(_nl))
    6335             :   {
    6336          81 :     auto & nl = _nl[nl_sys_num];
    6337          81 :     auto & nonlocal_cm = _nonlocal_cm[nl_sys_num];
    6338          81 :     unsigned int n_vars = nl->nVariables();
    6339          81 :     nonlocal_cm.resize(n_vars);
    6340          81 :     const auto & vars = nl->getVariables(0);
    6341          81 :     const auto & nonlocal_kernel = _nonlocal_kernels.getObjects();
    6342          81 :     const auto & nonlocal_integrated_bc = _nonlocal_integrated_bcs.getObjects();
    6343         243 :     for (const auto & ivar : vars)
    6344             :     {
    6345         252 :       for (const auto & kernel : nonlocal_kernel)
    6346             :       {
    6347         180 :         for (unsigned int i = ivar->number(); i < ivar->number() + ivar->count(); ++i)
    6348          90 :           if (i == kernel->variable().number())
    6349         135 :             for (const auto & jvar : vars)
    6350             :             {
    6351          90 :               const auto it = _var_dof_map.find(jvar->name());
    6352          90 :               if (it != _var_dof_map.end())
    6353             :               {
    6354          80 :                 unsigned int j = jvar->number();
    6355          80 :                 nonlocal_cm(i, j) = 1;
    6356             :               }
    6357             :             }
    6358             :       }
    6359         234 :       for (const auto & integrated_bc : nonlocal_integrated_bc)
    6360             :       {
    6361         144 :         for (unsigned int i = ivar->number(); i < ivar->number() + ivar->count(); ++i)
    6362          72 :           if (i == integrated_bc->variable().number())
    6363         108 :             for (const auto & jvar : vars)
    6364             :             {
    6365          72 :               const auto it = _var_dof_map.find(jvar->name());
    6366          72 :               if (it != _var_dof_map.end())
    6367             :               {
    6368          36 :                 unsigned int j = jvar->number();
    6369          36 :                 nonlocal_cm(i, j) = 1;
    6370             :               }
    6371             :             }
    6372             :       }
    6373             :     }
    6374             :   }
    6375          81 : }
    6376             : 
    6377             : bool
    6378         712 : FEProblemBase::areCoupled(const unsigned int ivar,
    6379             :                           const unsigned int jvar,
    6380             :                           const unsigned int nl_sys) const
    6381             : {
    6382         712 :   return (*_cm[nl_sys])(ivar, jvar);
    6383             : }
    6384             : 
    6385             : std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> &
    6386    19040563 : FEProblemBase::couplingEntries(const THREAD_ID tid, const unsigned int nl_sys)
    6387             : {
    6388    19040563 :   return _assembly[tid][nl_sys]->couplingEntries();
    6389             : }
    6390             : 
    6391             : std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> &
    6392        5558 : FEProblemBase::nonlocalCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys)
    6393             : {
    6394        5558 :   return _assembly[tid][nl_sys]->nonlocalCouplingEntries();
    6395             : }
    6396             : 
    6397             : void
    6398       62721 : FEProblemBase::init()
    6399             : {
    6400       62721 :   if (_initialized)
    6401           0 :     return;
    6402             : 
    6403      313605 :   TIME_SECTION("init", 2, "Initializing");
    6404             : 
    6405             :   // call executioner's preProblemInit so that it can do some setups before problem init
    6406       62721 :   _app.getExecutioner()->preProblemInit();
    6407             : 
    6408             :   // If we have AD and we are doing global AD indexing, then we should by default set the matrix
    6409             :   // coupling to full. If the user has told us to trust their coupling matrix, then this call will
    6410             :   // not do anything
    6411       62721 :   if (haveADObjects() && Moose::globalADIndexing())
    6412        7562 :     setCoupling(Moose::COUPLING_FULL);
    6413             : 
    6414      124377 :   for (const auto i : index_range(_nl))
    6415             :   {
    6416       61656 :     auto & nl = _nl[i];
    6417       61656 :     auto & cm = _cm[i];
    6418             : 
    6419       61656 :     unsigned int n_vars = nl->nVariables();
    6420             :     {
    6421      308280 :       TIME_SECTION("fillCouplingMatrix", 3, "Filling Coupling Matrix");
    6422             : 
    6423       61656 :       switch (_coupling)
    6424             :       {
    6425       44649 :         case Moose::COUPLING_DIAG:
    6426       44649 :           cm = std::make_unique<CouplingMatrix>(n_vars);
    6427       83029 :           for (unsigned int i = 0; i < n_vars; i++)
    6428       38380 :             (*cm)(i, i) = 1;
    6429       44649 :           break;
    6430             : 
    6431             :           // for full jacobian
    6432        7705 :         case Moose::COUPLING_FULL:
    6433        7705 :           cm = std::make_unique<CouplingMatrix>(n_vars);
    6434       19555 :           for (unsigned int i = 0; i < n_vars; i++)
    6435       34034 :             for (unsigned int j = 0; j < n_vars; j++)
    6436       22184 :               (*cm)(i, j) = 1;
    6437        7705 :           break;
    6438             : 
    6439        9302 :         case Moose::COUPLING_CUSTOM:
    6440             :           // do nothing, _cm was already set through couplingMatrix() call
    6441        9302 :           break;
    6442             :       }
    6443       61656 :     }
    6444             : 
    6445       61656 :     nl->dofMap()._dof_coupling = cm.get();
    6446             : 
    6447             :     // If there are no variables, make sure to pass a nullptr coupling
    6448             :     // matrix, to avoid warnings about non-nullptr yet empty
    6449             :     // CouplingMatrices.
    6450       61656 :     if (n_vars == 0)
    6451       12258 :       nl->dofMap()._dof_coupling = nullptr;
    6452             : 
    6453       61656 :     nl->dofMap().attach_extra_sparsity_function(&extraSparsity, nl.get());
    6454       61656 :     nl->dofMap().attach_extra_send_list_function(&extraSendList, nl.get());
    6455       61656 :     _aux->dofMap().attach_extra_send_list_function(&extraSendList, _aux.get());
    6456             : 
    6457       61656 :     if (!_skip_nl_system_check && _solve && n_vars == 0)
    6458           0 :       mooseError("No variables specified in nonlinear system '", nl->name(), "'.");
    6459             :   }
    6460             : 
    6461       62721 :   ghostGhostedBoundaries(); // We do this again right here in case new boundaries have been added
    6462             : 
    6463             :   // We may have added element/nodes to the mesh in ghostGhostedBoundaries so we need to update
    6464             :   // all of our mesh information. We need to make sure that mesh information is up-to-date before
    6465             :   // EquationSystems::init because that will call through to updateGeomSearch (for sparsity
    6466             :   // augmentation) and if we haven't added back boundary node information before that latter call,
    6467             :   // then we're screwed. We'll get things like "Unable to find closest node!"
    6468       62721 :   _mesh.meshChanged();
    6469       62721 :   if (_displaced_problem)
    6470        2246 :     _displaced_mesh->meshChanged();
    6471             : 
    6472       62721 :   if (_mesh.doingPRefinement())
    6473             :   {
    6474         234 :     preparePRefinement();
    6475         234 :     if (_displaced_problem)
    6476           0 :       _displaced_problem->preparePRefinement();
    6477             :   }
    6478             : 
    6479             :   // do not assemble system matrix for JFNK solve
    6480      124377 :   for (auto & nl : _nl)
    6481       61656 :     if (solverParams(nl->number())._type == Moose::ST_JFNK)
    6482         139 :       nl->turnOffJacobian();
    6483             : 
    6484      125717 :   for (auto & sys : _solver_systems)
    6485       62996 :     sys->preInit();
    6486       62721 :   _aux->preInit();
    6487             : 
    6488             :   // Build the mortar segment meshes, if they haven't been already, for a couple reasons:
    6489             :   // 1) Get the ghosting correct for both static and dynamic meshes
    6490             :   // 2) Make sure the mortar mesh is built for mortar constraints that live on the static mesh
    6491             :   //
    6492             :   // It is worth-while to note that mortar meshes that live on a dynamic mesh will be built
    6493             :   // during residual and Jacobian evaluation because when displacements are solution variables
    6494             :   // the mortar mesh will move and change during the course of a non-linear solve. We DO NOT
    6495             :   // redo ghosting during non-linear solve, so for purpose 1) the below call has to be made
    6496       62721 :   if (!_mortar_data->initialized())
    6497       46505 :     updateMortarMesh();
    6498             : 
    6499             :   {
    6500      313605 :     TIME_SECTION("EquationSystems::Init", 2, "Initializing Equation Systems");
    6501       62721 :     es().init();
    6502       62721 :   }
    6503             : 
    6504      125717 :   for (auto & sys : _solver_systems)
    6505       62996 :     sys->postInit();
    6506       62721 :   _aux->postInit();
    6507             : 
    6508             :   // Now that the equation system and the dof distribution is done, we can generate the
    6509             :   // finite volume-related parts if needed.
    6510       62721 :   if (haveFV())
    6511        5407 :     _mesh.setupFiniteVolumeMeshData();
    6512             : 
    6513      125717 :   for (auto & sys : _solver_systems)
    6514       62996 :     sys->update();
    6515       62721 :   _aux->update();
    6516             : 
    6517      131314 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
    6518      136138 :     for (const auto i : index_range(_nl))
    6519             :     {
    6520             :       mooseAssert(
    6521             :           _cm[i],
    6522             :           "Coupling matrix not set for system "
    6523             :               << i
    6524             :               << ". This should only happen if a preconditioner was not setup for this system");
    6525       67545 :       _assembly[tid][i]->init(_cm[i].get());
    6526             :     }
    6527             : 
    6528       62721 :   if (_displaced_problem)
    6529        2246 :     _displaced_problem->init();
    6530             : 
    6531             : #ifdef MOOSE_KOKKOS_ENABLED
    6532       41986 :   if (_has_kokkos_objects)
    6533         741 :     initKokkos();
    6534             : #endif
    6535             : 
    6536       62721 :   _initialized = true;
    6537       62721 : }
    6538             : 
    6539             : unsigned int
    6540       13677 : FEProblemBase::nlSysNum(const NonlinearSystemName & nl_sys_name) const
    6541             : {
    6542       13677 :   std::istringstream ss(nl_sys_name);
    6543             :   unsigned int nl_sys_num;
    6544       13677 :   if (!(ss >> nl_sys_num) || !ss.eof())
    6545       13677 :     nl_sys_num = libmesh_map_find(_nl_sys_name_to_num, nl_sys_name);
    6546             : 
    6547       13677 :   return nl_sys_num;
    6548       13677 : }
    6549             : 
    6550             : unsigned int
    6551       39884 : FEProblemBase::linearSysNum(const LinearSystemName & linear_sys_name) const
    6552             : {
    6553       39884 :   std::istringstream ss(linear_sys_name);
    6554             :   unsigned int linear_sys_num;
    6555       39884 :   if (!(ss >> linear_sys_num) || !ss.eof())
    6556       39884 :     linear_sys_num = libmesh_map_find(_linear_sys_name_to_num, linear_sys_name);
    6557             : 
    6558       39884 :   return linear_sys_num;
    6559       39884 : }
    6560             : 
    6561             : unsigned int
    6562      130783 : FEProblemBase::solverSysNum(const SolverSystemName & solver_sys_name) const
    6563             : {
    6564      130783 :   std::istringstream ss(solver_sys_name);
    6565             :   unsigned int solver_sys_num;
    6566      130783 :   if (!(ss >> solver_sys_num) || !ss.eof())
    6567             :   {
    6568      130783 :     const auto & search = _solver_sys_name_to_num.find(solver_sys_name);
    6569      130783 :     if (search == _solver_sys_name_to_num.end())
    6570           0 :       mooseError("The solver system number was requested for system '" + solver_sys_name,
    6571             :                  "' but this system does not exist in the Problem. Systems can be added to the "
    6572             :                  "problem using the 'nl_sys_names'/'linear_sys_names' parameter.\nSystems in the "
    6573           0 :                  "Problem: " +
    6574           0 :                      Moose::stringify(_solver_sys_names));
    6575      130783 :     solver_sys_num = search->second;
    6576             :   }
    6577             : 
    6578      130783 :   return solver_sys_num;
    6579      130783 : }
    6580             : 
    6581             : unsigned int
    6582        1641 : FEProblemBase::systemNumForVariable(const VariableName & variable_name) const
    6583             : {
    6584        1752 :   for (const auto & solver_sys : _solver_systems)
    6585        1641 :     if (solver_sys->hasVariable(variable_name))
    6586        1530 :       return solver_sys->number();
    6587             :   mooseAssert(_aux, "Should have an auxiliary system");
    6588         111 :   if (_aux->hasVariable(variable_name))
    6589         111 :     return _aux->number();
    6590             : 
    6591           0 :   mooseError("Variable '",
    6592             :              variable_name,
    6593             :              "' was not found in any solver (nonlinear/linear) or auxiliary system");
    6594             : }
    6595             : 
    6596             : void
    6597      348123 : FEProblemBase::solve(const unsigned int nl_sys_num)
    6598             : {
    6599     1740615 :   TIME_SECTION("solve", 1, "Solving", false);
    6600             : 
    6601      348123 :   setCurrentNonlinearSystem(nl_sys_num);
    6602             : 
    6603             :   // This prevents stale dof indices from lingering around and possibly leading to invalid reads
    6604             :   // and writes. Dof indices may be made stale through operations like mesh adaptivity
    6605      348123 :   clearAllDofIndices();
    6606      348123 :   if (_displaced_problem)
    6607       35869 :     _displaced_problem->clearAllDofIndices();
    6608             : 
    6609             :   // Setup the output system for printing linear/nonlinear iteration information and some solver
    6610             :   // settings, including setting matrix prefixes. This must occur before petscSetOptions
    6611      348123 :   initPetscOutputAndSomeSolverSettings();
    6612             : 
    6613             : #if PETSC_RELEASE_LESS_THAN(3, 12, 0)
    6614             :   Moose::PetscSupport::petscSetOptions(
    6615             :       _petsc_options, _solver_params); // Make sure the PETSc options are setup for this app
    6616             : #else
    6617             :   // Now this database will be the default
    6618             :   // Each app should have only one database
    6619      348123 :   if (!_app.isUltimateMaster())
    6620       89156 :     LibmeshPetscCall(PetscOptionsPush(_petsc_option_data_base));
    6621             :   // We did not add PETSc options to database yet
    6622      348123 :   if (!_is_petsc_options_inserted)
    6623             :   {
    6624             :     // Insert options for all systems all at once
    6625       42206 :     Moose::PetscSupport::petscSetOptions(_petsc_options, _solver_params, this);
    6626       42206 :     _is_petsc_options_inserted = true;
    6627             :   }
    6628             : #endif
    6629             : 
    6630             :   // set up DM which is required if use a field split preconditioner
    6631             :   // We need to setup DM every "solve()" because libMesh destroy SNES after solve()
    6632             :   // Do not worry, DM setup is very cheap
    6633      348123 :   _current_nl_sys->setupDM();
    6634             : 
    6635      348123 :   possiblyRebuildGeomSearchPatches();
    6636             : 
    6637             :   // reset flag so that residual evaluation does not get skipped
    6638             :   // and the next non-linear iteration does not automatically fail with
    6639             :   // "DIVERGED_NANORINF", when we throw  an exception and stop solve
    6640      348123 :   _fail_next_system_convergence_check = false;
    6641             : 
    6642      348123 :   if (_solve)
    6643             :   {
    6644      316657 :     _current_nl_sys->solve();
    6645      316577 :     _current_nl_sys->update();
    6646             :   }
    6647             : 
    6648             :   // sync solutions in displaced problem
    6649      348043 :   if (_displaced_problem)
    6650       35865 :     _displaced_problem->syncSolutions();
    6651             : 
    6652             : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
    6653      348043 :   if (!_app.isUltimateMaster())
    6654       89156 :     LibmeshPetscCall(PetscOptionsPop());
    6655             : #endif
    6656      348043 : }
    6657             : 
    6658             : void
    6659         213 : FEProblemBase::setException(const std::string & message)
    6660             : {
    6661         213 :   _has_exception = true;
    6662         213 :   _exception_message = message;
    6663         213 : }
    6664             : 
    6665             : void
    6666    21799735 : FEProblemBase::checkExceptionAndStopSolve(bool print_message)
    6667             : {
    6668    21799735 :   if (_skip_exception_check)
    6669         240 :     return;
    6670             : 
    6671    65398485 :   TIME_SECTION("checkExceptionAndStopSolve", 5);
    6672             : 
    6673             :   // See if any processor had an exception.  If it did, get back the
    6674             :   // processor that the exception occurred on.
    6675             :   unsigned int processor_id;
    6676             : 
    6677    21799495 :   _communicator.maxloc(_has_exception, processor_id);
    6678             : 
    6679    21799495 :   if (_has_exception)
    6680             :   {
    6681         337 :     _communicator.broadcast(_exception_message, processor_id);
    6682             : 
    6683         451 :     if (_current_execute_on_flag == EXEC_LINEAR || _current_execute_on_flag == EXEC_NONLINEAR ||
    6684         114 :         _current_execute_on_flag == EXEC_POSTCHECK)
    6685             :     {
    6686             :       // Print the message
    6687         337 :       if (_communicator.rank() == 0 && print_message)
    6688             :       {
    6689         197 :         _console << "\n" << _exception_message << "\n";
    6690         197 :         if (isTransient())
    6691             :           _console
    6692             :               << "To recover, the solution will fail and then be re-attempted with a reduced time "
    6693         180 :                  "step.\n"
    6694         180 :               << std::endl;
    6695             :       }
    6696             : 
    6697             :       // Stop the solve -- this entails setting
    6698             :       // SNESSetFunctionDomainError() or directly inserting NaNs in the
    6699             :       // residual vector to let PETSc >= 3.6 return DIVERGED_NANORINF.
    6700         337 :       if (_current_nl_sys)
    6701         337 :         _current_nl_sys->stopSolve(_current_execute_on_flag, _fe_vector_tags);
    6702             : 
    6703         337 :       if (_current_linear_sys)
    6704           0 :         _current_linear_sys->stopSolve(_current_execute_on_flag, _fe_vector_tags);
    6705             : 
    6706             :       // and close Aux system (we MUST do this here; see #11525)
    6707         337 :       _aux->solution().close();
    6708             : 
    6709             :       // We've handled this exception, so we no longer have one.
    6710         337 :       _has_exception = false;
    6711             : 
    6712             :       // Force the next non-linear convergence check to fail (and all further residual evaluation
    6713             :       // to be skipped).
    6714         337 :       _fail_next_system_convergence_check = true;
    6715             : 
    6716             :       // Repropagate the exception, so it can be caught at a higher level, typically
    6717             :       // this is NonlinearSystem::computeResidual().
    6718         337 :       throw MooseException(_exception_message);
    6719             :     }
    6720             :     else
    6721           0 :       mooseError("The following parallel-communicated exception was detected during " +
    6722           0 :                  Moose::stringify(_current_execute_on_flag) + " evaluation:\n" +
    6723           0 :                  _exception_message +
    6724             :                  "\nBecause this did not occur during residual evaluation, there"
    6725             :                  " is no way to handle this, so the solution is aborting.\n");
    6726             :   }
    6727    21799495 : }
    6728             : 
    6729             : void
    6730     3878089 : FEProblemBase::resetState()
    6731             : {
    6732             :   // Our default state is to allow computing derivatives
    6733     3878089 :   ADReal::do_derivatives = true;
    6734     3878089 :   _current_execute_on_flag = EXEC_NONE;
    6735             : 
    6736             :   // Clear the VectorTags and MatrixTags
    6737     3878089 :   clearCurrentResidualVectorTags();
    6738     3878089 :   clearCurrentJacobianMatrixTags();
    6739             : 
    6740     3878089 :   _safe_access_tagged_vectors = true;
    6741     3878089 :   _safe_access_tagged_matrices = true;
    6742             : 
    6743     3878089 :   setCurrentlyComputingResidual(false);
    6744     3878089 :   setCurrentlyComputingJacobian(false);
    6745     3878089 :   setCurrentlyComputingResidualAndJacobian(false);
    6746     3878089 :   if (_displaced_problem)
    6747             :   {
    6748      160528 :     _displaced_problem->setCurrentlyComputingResidual(false);
    6749      160528 :     _displaced_problem->setCurrentlyComputingJacobian(false);
    6750      160528 :     _displaced_problem->setCurrentlyComputingResidualAndJacobian(false);
    6751             :   }
    6752     3878089 : }
    6753             : 
    6754             : void
    6755        5648 : FEProblemBase::solveLinearSystem(const unsigned int linear_sys_num,
    6756             :                                  const Moose::PetscSupport::PetscOptions * po)
    6757             : {
    6758       28240 :   TIME_SECTION("solve", 1, "Solving", false);
    6759             : 
    6760        5648 :   setCurrentLinearSystem(linear_sys_num);
    6761             : 
    6762        5648 :   const Moose::PetscSupport::PetscOptions & options = po ? *po : _petsc_options;
    6763        5648 :   auto & solver_params = _solver_params[numNonlinearSystems() + linear_sys_num];
    6764             : 
    6765             :   // Set custom convergence criteria
    6766        5648 :   Moose::PetscSupport::petscSetDefaults(*this);
    6767             : 
    6768             : #if PETSC_RELEASE_LESS_THAN(3, 12, 0)
    6769             :   LibmeshPetscCall(Moose::PetscSupport::petscSetOptions(
    6770             :       options, solver_params)); // Make sure the PETSc options are setup for this app
    6771             : #else
    6772             :   // Now this database will be the default
    6773             :   // Each app should have only one database
    6774        5648 :   if (!_app.isUltimateMaster())
    6775         235 :     LibmeshPetscCall(PetscOptionsPush(_petsc_option_data_base));
    6776             : 
    6777             :   // We did not add PETSc options to database yet
    6778        5648 :   if (!_is_petsc_options_inserted)
    6779             :   {
    6780        1257 :     Moose::PetscSupport::petscSetOptions(options, solver_params, this);
    6781        1257 :     _is_petsc_options_inserted = true;
    6782             :   }
    6783             : #endif
    6784             : 
    6785        5648 :   if (_solve)
    6786        5636 :     _current_linear_sys->solve();
    6787             : 
    6788             : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
    6789        5648 :   if (!_app.isUltimateMaster())
    6790         235 :     LibmeshPetscCall(PetscOptionsPop());
    6791             : #endif
    6792        5648 : }
    6793             : 
    6794             : bool
    6795      345498 : FEProblemBase::solverSystemConverged(const unsigned int sys_num)
    6796             : {
    6797      345498 :   if (_solve)
    6798      345474 :     return _solver_systems[sys_num]->converged();
    6799             :   else
    6800          24 :     return true;
    6801             : }
    6802             : 
    6803             : unsigned int
    6804        6328 : FEProblemBase::nNonlinearIterations(const unsigned int nl_sys_num) const
    6805             : {
    6806        6328 :   return _nl[nl_sys_num]->nNonlinearIterations();
    6807             : }
    6808             : 
    6809             : unsigned int
    6810        5425 : FEProblemBase::nLinearIterations(const unsigned int nl_sys_num) const
    6811             : {
    6812        5425 :   return _nl[nl_sys_num]->nLinearIterations();
    6813             : }
    6814             : 
    6815             : Real
    6816         258 : FEProblemBase::finalNonlinearResidual(const unsigned int nl_sys_num) const
    6817             : {
    6818         258 :   return _nl[nl_sys_num]->finalNonlinearResidual();
    6819             : }
    6820             : 
    6821             : bool
    6822      845824 : FEProblemBase::computingPreSMOResidual(const unsigned int nl_sys_num) const
    6823             : {
    6824      845824 :   return _nl[nl_sys_num]->computingPreSMOResidual();
    6825             : }
    6826             : 
    6827             : void
    6828       57245 : FEProblemBase::copySolutionsBackwards()
    6829             : {
    6830      286225 :   TIME_SECTION("copySolutionsBackwards", 3, "Copying Solutions Backward");
    6831             : 
    6832      114747 :   for (auto & sys : _solver_systems)
    6833       57502 :     sys->copySolutionsBackwards();
    6834       57245 :   _aux->copySolutionsBackwards();
    6835       57245 : }
    6836             : 
    6837             : void
    6838      249734 : FEProblemBase::advanceState()
    6839             : {
    6840     1248670 :   TIME_SECTION("advanceState", 5, "Advancing State");
    6841             : 
    6842      503127 :   for (auto & sys : _solver_systems)
    6843      253393 :     sys->copyOldSolutions();
    6844      249734 :   _aux->copyOldSolutions();
    6845             : 
    6846      249734 :   if (_displaced_problem)
    6847             :   {
    6848       67642 :     for (const auto i : index_range(_solver_systems))
    6849       33821 :       _displaced_problem->solverSys(i).copyOldSolutions();
    6850       33821 :     _displaced_problem->auxSys().copyOldSolutions();
    6851             :   }
    6852             : 
    6853      249734 :   _reporter_data.copyValuesBack();
    6854             : 
    6855      249734 :   getMooseApp().getChainControlDataSystem().copyValuesBack();
    6856             : 
    6857      249734 :   if (_material_props.hasStatefulProperties())
    6858        1970 :     _material_props.shift();
    6859             : 
    6860      249734 :   if (_bnd_material_props.hasStatefulProperties())
    6861        1816 :     _bnd_material_props.shift();
    6862             : 
    6863      249734 :   if (_neighbor_material_props.hasStatefulProperties())
    6864        1682 :     _neighbor_material_props.shift();
    6865             : 
    6866             : #ifdef MOOSE_KOKKOS_ENABLED
    6867      164114 :   if (_kokkos_material_props.hasStatefulProperties())
    6868         376 :     _kokkos_material_props.shift();
    6869             : 
    6870      164114 :   if (_kokkos_bnd_material_props.hasStatefulProperties())
    6871         426 :     _kokkos_bnd_material_props.shift();
    6872             : 
    6873      164114 :   if (_kokkos_neighbor_material_props.hasStatefulProperties())
    6874         376 :     _kokkos_neighbor_material_props.shift();
    6875             : #endif
    6876      249734 : }
    6877             : 
    6878             : void
    6879        5367 : FEProblemBase::restoreSolutions()
    6880             : {
    6881       26835 :   TIME_SECTION("restoreSolutions", 5, "Restoring Solutions");
    6882             : 
    6883        5367 :   if (!_not_zeroed_tagged_vectors.empty())
    6884           0 :     paramError("not_zeroed_tag_vectors",
    6885             :                "There is currently no way to restore not-zeroed vectors.");
    6886             : 
    6887       10736 :   for (auto & sys : _solver_systems)
    6888             :   {
    6889        5369 :     if (_verbose_restore)
    6890         395 :       _console << "Restoring solutions on system " << sys->name() << "..." << std::endl;
    6891        5369 :     sys->restoreSolutions();
    6892             :   }
    6893             : 
    6894        5367 :   if (_verbose_restore)
    6895         394 :     _console << "Restoring solutions on Auxiliary system..." << std::endl;
    6896        5367 :   _aux->restoreSolutions();
    6897             : 
    6898        5367 :   if (_verbose_restore)
    6899         394 :     _console << "Restoring postprocessor, vector-postprocessor, and reporter data..." << std::endl;
    6900        5367 :   _reporter_data.restoreState(_verbose_restore);
    6901             : 
    6902        5367 :   if (_displaced_problem)
    6903         136 :     _displaced_problem->updateMesh();
    6904        5367 : }
    6905             : 
    6906             : void
    6907         115 : FEProblemBase::saveOldSolutions()
    6908             : {
    6909         575 :   TIME_SECTION("saveOldSolutions", 5, "Saving Old Solutions");
    6910             : 
    6911         230 :   for (auto & sys : _solver_systems)
    6912         115 :     sys->saveOldSolutions();
    6913         115 :   _aux->saveOldSolutions();
    6914         115 : }
    6915             : 
    6916             : void
    6917         115 : FEProblemBase::restoreOldSolutions()
    6918             : {
    6919         575 :   TIME_SECTION("restoreOldSolutions", 5, "Restoring Old Solutions");
    6920             : 
    6921         230 :   for (auto & sys : _solver_systems)
    6922         115 :     sys->restoreOldSolutions();
    6923         115 :   _aux->restoreOldSolutions();
    6924         115 : }
    6925             : 
    6926             : void
    6927     1334675 : FEProblemBase::outputStep(ExecFlagType type)
    6928             : {
    6929     6673375 :   TIME_SECTION("outputStep", 1, "Outputting");
    6930             : 
    6931     1334675 :   setCurrentExecuteOnFlag(type);
    6932             : 
    6933     2684794 :   for (auto & sys : _solver_systems)
    6934     1350119 :     sys->update();
    6935     1334675 :   _aux->update();
    6936             : 
    6937     1334675 :   if (_displaced_problem)
    6938      138047 :     _displaced_problem->syncSolutions();
    6939     1334675 :   _app.getOutputWarehouse().outputStep(type);
    6940             : 
    6941     1334663 :   setCurrentExecuteOnFlag(EXEC_NONE);
    6942     1334663 : }
    6943             : 
    6944             : void
    6945       89528 : FEProblemBase::allowOutput(bool state)
    6946             : {
    6947       89528 :   _app.getOutputWarehouse().allowOutput(state);
    6948       89528 : }
    6949             : 
    6950             : void
    6951          25 : FEProblemBase::forceOutput()
    6952             : {
    6953          25 :   _app.getOutputWarehouse().forceOutput();
    6954          25 : }
    6955             : 
    6956             : void
    6957      369127 : FEProblemBase::initPetscOutputAndSomeSolverSettings()
    6958             : {
    6959      369127 :   _app.getOutputWarehouse().solveSetup();
    6960      369127 :   Moose::PetscSupport::petscSetDefaults(*this);
    6961      369127 : }
    6962             : 
    6963             : void
    6964      259278 : FEProblemBase::onTimestepBegin()
    6965             : {
    6966      777834 :   TIME_SECTION("onTimestepBegin", 2);
    6967             : 
    6968      521928 :   for (auto & nl : _nl)
    6969      262650 :     nl->onTimestepBegin();
    6970      259278 : }
    6971             : 
    6972             : void
    6973      334590 : FEProblemBase::onTimestepEnd()
    6974             : {
    6975      334590 : }
    6976             : 
    6977             : Real
    6978     8145249 : FEProblemBase::getTimeFromStateArg(const Moose::StateArg & state) const
    6979             : {
    6980     8145249 :   if (state.iteration_type != Moose::SolutionIterationType::Time)
    6981             :     // If we are any iteration type other than time (e.g. nonlinear), then temporally we are still
    6982             :     // in the present time
    6983           0 :     return time();
    6984             : 
    6985     8145249 :   switch (state.state)
    6986             :   {
    6987     8145249 :     case 0:
    6988     8145249 :       return time();
    6989             : 
    6990           0 :     case 1:
    6991           0 :       return timeOld();
    6992             : 
    6993           0 :     default:
    6994           0 :       mooseError("Unhandled state ", state.state, " in FEProblemBase::getTimeFromStateArg");
    6995             :   }
    6996             : }
    6997             : 
    6998             : void
    6999       32034 : FEProblemBase::addTimeIntegrator(const std::string & type,
    7000             :                                  const std::string & name,
    7001             :                                  InputParameters & parameters)
    7002             : {
    7003             :   parallel_object_only();
    7004             : 
    7005       96102 :   parameters.set<SubProblem *>("_subproblem") = this;
    7006       32034 :   logAdd("TimeIntegrator", name, type, parameters);
    7007       32034 :   _aux->addTimeIntegrator(type, name + ":aux", parameters);
    7008       64102 :   for (auto & sys : _solver_systems)
    7009       32068 :     sys->addTimeIntegrator(type, name + ":" + sys->name(), parameters);
    7010       32034 :   _has_time_integrator = true;
    7011             : 
    7012             :   // add vectors to store u_dot, u_dotdot, udot_old, u_dotdot_old and
    7013             :   // solution vectors older than 2 time steps, if requested by the time
    7014             :   // integrator
    7015       32034 :   _aux->addDotVectors();
    7016       64076 :   for (auto & nl : _nl)
    7017             :   {
    7018       32042 :     nl->addDotVectors();
    7019             : 
    7020       32042 :     auto tag_udot = nl->getTimeIntegrators()[0]->uDotFactorTag();
    7021       32042 :     if (!nl->hasVector(tag_udot))
    7022       31984 :       nl->associateVectorToTag(*nl->solutionUDot(), tag_udot);
    7023       32042 :     auto tag_udotdot = nl->getTimeIntegrators()[0]->uDotDotFactorTag();
    7024       32042 :     if (!nl->hasVector(tag_udotdot) && uDotDotRequested())
    7025         164 :       nl->associateVectorToTag(*nl->solutionUDotDot(), tag_udotdot);
    7026             :   }
    7027             : 
    7028       32034 :   if (_displaced_problem)
    7029             :     // Time integrator does not exist when displaced problem is created.
    7030        1908 :     _displaced_problem->addTimeIntegrator();
    7031       32034 : }
    7032             : 
    7033             : void
    7034          24 : FEProblemBase::addPredictor(const std::string & type,
    7035             :                             const std::string & name,
    7036             :                             InputParameters & parameters)
    7037             : {
    7038             :   parallel_object_only();
    7039             : 
    7040          24 :   if (!numNonlinearSystems() && numLinearSystems())
    7041           0 :     mooseError("Vector bounds cannot be used with LinearSystems!");
    7042             : 
    7043          48 :   parameters.set<SubProblem *>("_subproblem") = this;
    7044          24 :   std::shared_ptr<Predictor> predictor = _factory.create<Predictor>(type, name, parameters);
    7045          24 :   logAdd("Predictor", name, type, parameters);
    7046             : 
    7047          48 :   for (auto & nl : _nl)
    7048          24 :     nl->setPredictor(predictor);
    7049          24 : }
    7050             : 
    7051             : Real
    7052       67294 : FEProblemBase::computeResidualL2Norm(NonlinearSystemBase & sys)
    7053             : {
    7054       67294 :   _current_nl_sys = &sys;
    7055       67294 :   computeResidual(*sys.currentSolution(), sys.RHS(), sys.number());
    7056       67294 :   return sys.RHS().l2_norm();
    7057             : }
    7058             : 
    7059             : Real
    7060         102 : FEProblemBase::computeResidualL2Norm(LinearSystem & sys)
    7061             : {
    7062         102 :   _current_linear_sys = &sys;
    7063             : 
    7064             :   // We assemble the current system to check the current residual
    7065         102 :   computeLinearSystemSys(sys.linearImplicitSystem(),
    7066         102 :                          *sys.linearImplicitSystem().matrix,
    7067         102 :                          *sys.linearImplicitSystem().rhs,
    7068             :                          /*compute fresh gradients*/ true);
    7069             : 
    7070             :   // Unfortunate, but we have to allocate a new vector for the residual
    7071         102 :   auto residual = sys.linearImplicitSystem().rhs->clone();
    7072         102 :   residual->scale(-1.0);
    7073         102 :   residual->add_vector(*sys.currentSolution(), *sys.linearImplicitSystem().matrix);
    7074         204 :   return residual->l2_norm();
    7075         102 : }
    7076             : 
    7077             : Real
    7078       67360 : FEProblemBase::computeResidualL2Norm()
    7079             : {
    7080      336800 :   TIME_SECTION("computeResidualL2Norm", 2, "Computing L2 Norm of Residual");
    7081             : 
    7082             :   // We use sum the squared norms of the individual systems and then take the square root of it
    7083       67360 :   Real l2_norm = 0.0;
    7084      134654 :   for (auto sys : _nl)
    7085             :   {
    7086       67294 :     const auto norm = computeResidualL2Norm(*sys);
    7087       67294 :     l2_norm += norm * norm;
    7088       67294 :   }
    7089             : 
    7090       67462 :   for (auto sys : _linear_systems)
    7091             :   {
    7092         102 :     const auto norm = computeResidualL2Norm(*sys);
    7093         102 :     l2_norm += norm * norm;
    7094         102 :   }
    7095             : 
    7096      134720 :   return std::sqrt(l2_norm);
    7097       67360 : }
    7098             : 
    7099             : void
    7100     3234760 : FEProblemBase::computeResidualSys(NonlinearImplicitSystem & sys,
    7101             :                                   const NumericVector<Number> & soln,
    7102             :                                   NumericVector<Number> & residual)
    7103             : {
    7104             :   parallel_object_only();
    7105             : 
    7106     9704280 :   TIME_SECTION("computeResidualSys", 5);
    7107             : 
    7108     3234760 :   computeResidual(soln, residual, sys.number());
    7109     3234716 : }
    7110             : 
    7111             : void
    7112           0 : FEProblemBase::computeResidual(NonlinearImplicitSystem & sys,
    7113             :                                const NumericVector<Number> & soln,
    7114             :                                NumericVector<Number> & residual)
    7115             : {
    7116           0 :   mooseDeprecated("Please use computeResidualSys");
    7117             : 
    7118           0 :   computeResidualSys(sys, soln, residual);
    7119           0 : }
    7120             : 
    7121             : void
    7122     3297941 : FEProblemBase::computeResidual(const NumericVector<Number> & soln,
    7123             :                                NumericVector<Number> & residual,
    7124             :                                const unsigned int nl_sys_num)
    7125             : {
    7126     3297941 :   setCurrentNonlinearSystem(nl_sys_num);
    7127             : 
    7128             :   // We associate the residual tag with the given residual vector to make sure we
    7129             :   // don't filter it out below
    7130     3297941 :   _current_nl_sys->associateVectorToTag(residual, _current_nl_sys->residualVectorTag());
    7131     3297941 :   const auto & residual_vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
    7132             : 
    7133             :   mooseAssert(_fe_vector_tags.empty(), "This should be empty indicating a clean starting state");
    7134             :   // We filter out tags which do not have associated vectors in the current nonlinear
    7135             :   // system. This is essential to be able to use system-dependent residual tags.
    7136     3297941 :   selectVectorTagsFromSystem(*_current_nl_sys, residual_vector_tags, _fe_vector_tags);
    7137             : 
    7138     3297941 :   computeResidualInternal(soln, residual, _fe_vector_tags);
    7139     3297897 :   _fe_vector_tags.clear();
    7140     3297897 : }
    7141             : 
    7142             : void
    7143        3467 : FEProblemBase::computeResidualAndJacobian(const NumericVector<Number> & soln,
    7144             :                                           NumericVector<Number> & residual,
    7145             :                                           SparseMatrix<Number> & jacobian)
    7146             : {
    7147             :   try
    7148             :   {
    7149             :     try
    7150             :     {
    7151             :       // vector tags
    7152        3467 :       _current_nl_sys->associateVectorToTag(residual, _current_nl_sys->residualVectorTag());
    7153        3467 :       const auto & residual_vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
    7154             : 
    7155             :       mooseAssert(_fe_vector_tags.empty(),
    7156             :                   "This should be empty indicating a clean starting state");
    7157             :       // We filter out tags which do not have associated vectors in the current nonlinear
    7158             :       // system. This is essential to be able to use system-dependent residual tags.
    7159        3467 :       selectVectorTagsFromSystem(*_current_nl_sys, residual_vector_tags, _fe_vector_tags);
    7160             : 
    7161        3467 :       setCurrentResidualVectorTags(_fe_vector_tags);
    7162             : 
    7163             :       // matrix tags
    7164             :       {
    7165        3467 :         _fe_matrix_tags.clear();
    7166             : 
    7167        3467 :         auto & tags = getMatrixTags();
    7168       10401 :         for (auto & tag : tags)
    7169        6934 :           _fe_matrix_tags.insert(tag.second);
    7170             :       }
    7171             : 
    7172        3467 :       _current_nl_sys->setSolution(soln);
    7173             : 
    7174        3467 :       _current_nl_sys->associateVectorToTag(residual, _current_nl_sys->residualVectorTag());
    7175        3467 :       _current_nl_sys->associateMatrixToTag(jacobian, _current_nl_sys->systemMatrixTag());
    7176             : 
    7177       10401 :       for (const auto tag : _fe_matrix_tags)
    7178        6934 :         if (_current_nl_sys->hasMatrix(tag))
    7179             :         {
    7180        3467 :           auto & matrix = _current_nl_sys->getMatrix(tag);
    7181        3467 :           matrix.zero();
    7182        3467 :           if (haveADObjects() && !_current_nl_sys->system().has_static_condensation())
    7183             :             // PETSc algorithms require diagonal allocations regardless of whether there is non-zero
    7184             :             // diagonal dependence. With global AD indexing we only add non-zero
    7185             :             // dependence, so PETSc will scream at us unless we artificially add the diagonals.
    7186      139927 :             for (auto index : make_range(matrix.row_start(), matrix.row_stop()))
    7187      136580 :               matrix.add(index, index, 0);
    7188             :         }
    7189             : 
    7190        3467 :       _aux->zeroVariablesForResidual();
    7191             : 
    7192        3467 :       unsigned int n_threads = libMesh::n_threads();
    7193             : 
    7194        3467 :       _current_execute_on_flag = EXEC_LINEAR;
    7195             : 
    7196             :       // Random interface objects
    7197        3467 :       for (const auto & it : _random_data_objects)
    7198           0 :         it.second->updateSeeds(EXEC_LINEAR);
    7199             : 
    7200        3467 :       setCurrentlyComputingResidual(true);
    7201        3467 :       setCurrentlyComputingJacobian(true);
    7202        3467 :       setCurrentlyComputingResidualAndJacobian(true);
    7203        3467 :       if (_displaced_problem)
    7204             :       {
    7205        1172 :         _displaced_problem->setCurrentlyComputingResidual(true);
    7206        1172 :         _displaced_problem->setCurrentlyComputingJacobian(true);
    7207        1172 :         _displaced_problem->setCurrentlyComputingResidualAndJacobian(true);
    7208             :       }
    7209             : 
    7210        3467 :       execTransfers(EXEC_LINEAR);
    7211             : 
    7212        3467 :       execMultiApps(EXEC_LINEAR);
    7213             : 
    7214        7273 :       for (unsigned int tid = 0; tid < n_threads; tid++)
    7215        3806 :         reinitScalars(tid);
    7216             : 
    7217        3467 :       computeUserObjects(EXEC_LINEAR, Moose::PRE_AUX);
    7218             : 
    7219        3467 :       _aux->residualSetup();
    7220             : 
    7221        3467 :       if (_displaced_problem)
    7222             :       {
    7223        1172 :         computeSystems(EXEC_PRE_DISPLACE);
    7224        1172 :         _displaced_problem->updateMesh();
    7225        1172 :         if (_mortar_data->hasDisplacedObjects())
    7226        1172 :           updateMortarMesh();
    7227             :       }
    7228             : 
    7229        7273 :       for (THREAD_ID tid = 0; tid < n_threads; tid++)
    7230             :       {
    7231        3806 :         _all_materials.residualSetup(tid);
    7232        3806 :         _functions.residualSetup(tid);
    7233             :       }
    7234             : 
    7235        3467 :       computeSystems(EXEC_LINEAR);
    7236             : 
    7237        3467 :       computeUserObjects(EXEC_LINEAR, Moose::POST_AUX);
    7238             : 
    7239        3467 :       executeControls(EXEC_LINEAR);
    7240             : 
    7241        3467 :       _app.getOutputWarehouse().residualSetup();
    7242             : 
    7243        3467 :       _safe_access_tagged_vectors = false;
    7244        3467 :       _safe_access_tagged_matrices = false;
    7245             : 
    7246        3467 :       _current_nl_sys->computeResidualAndJacobianTags(_fe_vector_tags, _fe_matrix_tags);
    7247             : 
    7248        3467 :       _current_nl_sys->disassociateMatrixFromTag(jacobian, _current_nl_sys->systemMatrixTag());
    7249        3467 :       _current_nl_sys->disassociateVectorFromTag(residual, _current_nl_sys->residualVectorTag());
    7250             :     }
    7251           0 :     catch (...)
    7252             :     {
    7253           0 :       handleException("computeResidualAndJacobian");
    7254           0 :     }
    7255             :   }
    7256           0 :   catch (const MooseException &)
    7257             :   {
    7258             :     // The buck stops here, we have already handled the exception by
    7259             :     // calling the system's stopSolve() method, it is now up to PETSc to return a
    7260             :     // "diverged" reason during the next solve.
    7261           0 :   }
    7262           0 :   catch (...)
    7263             :   {
    7264           0 :     mooseError("Unexpected exception type");
    7265           0 :   }
    7266             : 
    7267        3467 :   resetState();
    7268        3467 :   _fe_vector_tags.clear();
    7269        3467 :   _fe_matrix_tags.clear();
    7270        3467 : }
    7271             : 
    7272             : void
    7273           0 : FEProblemBase::computeResidualTag(const NumericVector<Number> & soln,
    7274             :                                   NumericVector<Number> & residual,
    7275             :                                   TagID tag)
    7276             : {
    7277             :   try
    7278             :   {
    7279           0 :     _current_nl_sys->setSolution(soln);
    7280             : 
    7281           0 :     _current_nl_sys->associateVectorToTag(residual, tag);
    7282             : 
    7283           0 :     computeResidualTags({tag});
    7284             : 
    7285           0 :     _current_nl_sys->disassociateVectorFromTag(residual, tag);
    7286             :   }
    7287           0 :   catch (MooseException & e)
    7288             :   {
    7289             :     // If a MooseException propagates all the way to here, it means
    7290             :     // that it was thrown from a MOOSE system where we do not
    7291             :     // (currently) properly support the throwing of exceptions, and
    7292             :     // therefore we have no choice but to error out.  It may be
    7293             :     // *possible* to handle exceptions from other systems, but in the
    7294             :     // meantime, we don't want to silently swallow any unhandled
    7295             :     // exceptions here.
    7296           0 :     mooseError("An unhandled MooseException was raised during residual computation.  Please "
    7297             :                "contact the MOOSE team for assistance.");
    7298           0 :   }
    7299           0 : }
    7300             : 
    7301             : void
    7302     3303545 : FEProblemBase::computeResidualInternal(const NumericVector<Number> & soln,
    7303             :                                        NumericVector<Number> & residual,
    7304             :                                        const std::set<TagID> & tags)
    7305             : {
    7306             :   parallel_object_only();
    7307             : 
    7308     9910635 :   TIME_SECTION("computeResidualInternal", 1);
    7309             : 
    7310             :   try
    7311             :   {
    7312     3303545 :     _current_nl_sys->setSolution(soln);
    7313             : 
    7314     3303545 :     _current_nl_sys->associateVectorToTag(residual, _current_nl_sys->residualVectorTag());
    7315             : 
    7316     3303545 :     computeResidualTags(tags);
    7317             : 
    7318     3303501 :     _current_nl_sys->disassociateVectorFromTag(residual, _current_nl_sys->residualVectorTag());
    7319             :   }
    7320           0 :   catch (MooseException & e)
    7321             :   {
    7322             :     // If a MooseException propagates all the way to here, it means
    7323             :     // that it was thrown from a MOOSE system where we do not
    7324             :     // (currently) properly support the throwing of exceptions, and
    7325             :     // therefore we have no choice but to error out.  It may be
    7326             :     // *possible* to handle exceptions from other systems, but in the
    7327             :     // meantime, we don't want to silently swallow any unhandled
    7328             :     // exceptions here.
    7329           0 :     mooseError("An unhandled MooseException was raised during residual computation.  Please "
    7330             :                "contact the MOOSE team for assistance.");
    7331           0 :   }
    7332     3303501 : }
    7333             : 
    7334             : void
    7335           0 : FEProblemBase::computeResidualType(const NumericVector<Number> & soln,
    7336             :                                    NumericVector<Number> & residual,
    7337             :                                    TagID tag)
    7338             : {
    7339           0 :   TIME_SECTION("computeResidualType", 5);
    7340             : 
    7341             :   try
    7342             :   {
    7343           0 :     _current_nl_sys->setSolution(soln);
    7344             : 
    7345           0 :     _current_nl_sys->associateVectorToTag(residual, _current_nl_sys->residualVectorTag());
    7346             : 
    7347           0 :     computeResidualTags({tag, _current_nl_sys->residualVectorTag()});
    7348             : 
    7349           0 :     _current_nl_sys->disassociateVectorFromTag(residual, _current_nl_sys->residualVectorTag());
    7350             :   }
    7351           0 :   catch (MooseException & e)
    7352             :   {
    7353             :     // If a MooseException propagates all the way to here, it means
    7354             :     // that it was thrown from a MOOSE system where we do not
    7355             :     // (currently) properly support the throwing of exceptions, and
    7356             :     // therefore we have no choice but to error out.  It may be
    7357             :     // *possible* to handle exceptions from other systems, but in the
    7358             :     // meantime, we don't want to silently swallow any unhandled
    7359             :     // exceptions here.
    7360           0 :     mooseError("An unhandled MooseException was raised during residual computation.  Please "
    7361             :                "contact the MOOSE team for assistance.");
    7362           0 :   }
    7363           0 : }
    7364             : 
    7365             : void
    7366           4 : FEProblemBase::handleException(const std::string & calling_method)
    7367             : {
    7368             :   auto create_exception_message =
    7369           4 :       [&calling_method](const std::string & exception_type, const auto & exception)
    7370             :   {
    7371             :     return std::string("A " + exception_type + " was raised during FEProblemBase::" +
    7372           8 :                        calling_method + "\n" + std::string(exception.what()));
    7373           4 :   };
    7374             : 
    7375             :   try
    7376             :   {
    7377           4 :     throw;
    7378             :   }
    7379           4 :   catch (const libMesh::LogicError & e)
    7380             :   {
    7381           0 :     setException(create_exception_message("libMesh::LogicError", e));
    7382           0 :   }
    7383           0 :   catch (const MooseException & e)
    7384             :   {
    7385           0 :     setException(create_exception_message("MooseException", e));
    7386           0 :   }
    7387           0 :   catch (const MetaPhysicL::LogicError & e)
    7388             :   {
    7389           0 :     moose::translateMetaPhysicLError(e);
    7390           0 :   }
    7391           4 :   catch (const libMesh::PetscSolverException & e)
    7392             :   {
    7393             :     // One PETSc solver exception that we cannot currently recover from are new nonzero errors. In
    7394             :     // particular I have observed the following scenario in a parallel test:
    7395             :     // - Both processes throw because of a new nonzero during MOOSE's computeJacobianTags
    7396             :     // - We potentially handle the exceptions nicely here
    7397             :     // - When the matrix is closed in libMesh's libmesh_petsc_snes_solver, there is a new nonzero
    7398             :     //   throw which we do not catch here in MOOSE and the simulation terminates. This only appears
    7399             :     //   in parallel (and not all the time; a test I was examining threw with distributed mesh, but
    7400             :     //   not with replicated). In serial there are no new throws from libmesh_petsc_snes_solver.
    7401             :     // So for uniformity of behavior across serial/parallel, we will choose to abort here and always
    7402             :     // produce a non-zero exit code
    7403           8 :     mooseError(create_exception_message("libMesh::PetscSolverException", e));
    7404           0 :   }
    7405           0 :   catch (const std::exception & e)
    7406             :   {
    7407           0 :     const auto message = create_exception_message("std::exception", e);
    7408           0 :     if (_regard_general_exceptions_as_errors)
    7409           0 :       mooseError(message);
    7410             :     else
    7411           0 :       setException(message);
    7412           0 :   }
    7413             : 
    7414           0 :   checkExceptionAndStopSolve();
    7415           0 : }
    7416             : 
    7417             : void
    7418     3339566 : FEProblemBase::computeResidualTags(const std::set<TagID> & tags)
    7419             : {
    7420             :   parallel_object_only();
    7421             : 
    7422             :   try
    7423             :   {
    7424             :     try
    7425             :     {
    7426    16697830 :       TIME_SECTION("computeResidualTags", 5, "Computing Residual");
    7427             : 
    7428     3339566 :       ADReal::do_derivatives = false;
    7429             : 
    7430     3339566 :       setCurrentResidualVectorTags(tags);
    7431             : 
    7432     3339566 :       _aux->zeroVariablesForResidual();
    7433             : 
    7434     3339566 :       unsigned int n_threads = libMesh::n_threads();
    7435             : 
    7436     3339566 :       _current_execute_on_flag = EXEC_LINEAR;
    7437             : 
    7438             :       // Random interface objects
    7439     3355349 :       for (const auto & it : _random_data_objects)
    7440       15783 :         it.second->updateSeeds(EXEC_LINEAR);
    7441             : 
    7442     3339566 :       execTransfers(EXEC_LINEAR);
    7443             : 
    7444     3339566 :       execMultiApps(EXEC_LINEAR);
    7445             : 
    7446     6978863 :       for (unsigned int tid = 0; tid < n_threads; tid++)
    7447     3639297 :         reinitScalars(tid);
    7448             : 
    7449     3339566 :       computeUserObjects(EXEC_LINEAR, Moose::PRE_AUX);
    7450             : 
    7451     3339566 :       _aux->residualSetup();
    7452             : 
    7453     3339566 :       if (_displaced_problem)
    7454             :       {
    7455      136012 :         computeSystems(EXEC_PRE_DISPLACE);
    7456      136012 :         _displaced_problem->updateMesh();
    7457      136012 :         if (_mortar_data->hasDisplacedObjects())
    7458        2429 :           updateMortarMesh();
    7459             :       }
    7460             : 
    7461     6978863 :       for (THREAD_ID tid = 0; tid < n_threads; tid++)
    7462             :       {
    7463     3639297 :         _all_materials.residualSetup(tid);
    7464     3639297 :         _functions.residualSetup(tid);
    7465             :       }
    7466             : 
    7467     3339566 :       computeSystems(EXEC_LINEAR);
    7468             : 
    7469     3339566 :       computeUserObjects(EXEC_LINEAR, Moose::POST_AUX);
    7470             : 
    7471     3339566 :       executeControls(EXEC_LINEAR);
    7472             : 
    7473     3339566 :       _app.getOutputWarehouse().residualSetup();
    7474             : 
    7475     3339566 :       _safe_access_tagged_vectors = false;
    7476     3339566 :       _current_nl_sys->computeResidualTags(tags);
    7477     3339522 :     }
    7478           0 :     catch (...)
    7479             :     {
    7480           0 :       handleException("computeResidualTags");
    7481           0 :     }
    7482             :   }
    7483           0 :   catch (const MooseException &)
    7484             :   {
    7485             :     // The buck stops here, we have already handled the exception by
    7486             :     // calling the system's stopSolve() method, it is now up to PETSc to return a
    7487             :     // "diverged" reason during the next solve.
    7488           0 :   }
    7489           0 :   catch (...)
    7490             :   {
    7491           0 :     mooseError("Unexpected exception type");
    7492           0 :   }
    7493             : 
    7494     3339522 :   resetState();
    7495     3339522 : }
    7496             : 
    7497             : void
    7498      526126 : FEProblemBase::computeJacobianSys(NonlinearImplicitSystem & sys,
    7499             :                                   const NumericVector<Number> & soln,
    7500             :                                   SparseMatrix<Number> & jacobian)
    7501             : {
    7502      526126 :   computeJacobian(soln, jacobian, sys.number());
    7503      526106 : }
    7504             : 
    7505             : void
    7506        4894 : FEProblemBase::computeJacobianTag(const NumericVector<Number> & soln,
    7507             :                                   SparseMatrix<Number> & jacobian,
    7508             :                                   TagID tag)
    7509             : {
    7510        4894 :   _current_nl_sys->setSolution(soln);
    7511             : 
    7512        4894 :   _current_nl_sys->associateMatrixToTag(jacobian, tag);
    7513             : 
    7514        9788 :   computeJacobianTags({tag});
    7515             : 
    7516        4894 :   _current_nl_sys->disassociateMatrixFromTag(jacobian, tag);
    7517        4894 : }
    7518             : 
    7519             : void
    7520      525296 : FEProblemBase::computeJacobian(const NumericVector<Number> & soln,
    7521             :                                SparseMatrix<Number> & jacobian,
    7522             :                                const unsigned int nl_sys_num)
    7523             : {
    7524      525296 :   setCurrentNonlinearSystem(nl_sys_num);
    7525             : 
    7526      525296 :   _fe_matrix_tags.clear();
    7527             : 
    7528      525296 :   auto & tags = getMatrixTags();
    7529     1576160 :   for (auto & tag : tags)
    7530     1050864 :     _fe_matrix_tags.insert(tag.second);
    7531             : 
    7532      525296 :   computeJacobianInternal(soln, jacobian, _fe_matrix_tags);
    7533      525276 : }
    7534             : 
    7535             : void
    7536      525296 : FEProblemBase::computeJacobianInternal(const NumericVector<Number> & soln,
    7537             :                                        SparseMatrix<Number> & jacobian,
    7538             :                                        const std::set<TagID> & tags)
    7539             : {
    7540     1575888 :   TIME_SECTION("computeJacobianInternal", 1);
    7541             : 
    7542      525296 :   _current_nl_sys->setSolution(soln);
    7543             : 
    7544      525296 :   _current_nl_sys->associateMatrixToTag(jacobian, _current_nl_sys->systemMatrixTag());
    7545             : 
    7546      525296 :   computeJacobianTags(tags);
    7547             : 
    7548      525276 :   _current_nl_sys->disassociateMatrixFromTag(jacobian, _current_nl_sys->systemMatrixTag());
    7549      525276 : }
    7550             : 
    7551             : void
    7552      535120 : FEProblemBase::computeJacobianTags(const std::set<TagID> & tags)
    7553             : {
    7554             :   try
    7555             :   {
    7556             :     try
    7557             :     {
    7558      535120 :       if (!_has_jacobian || !_const_jacobian)
    7559             :       {
    7560     2639835 :         TIME_SECTION("computeJacobianTags", 5, "Computing Jacobian");
    7561             : 
    7562     1576063 :         for (auto tag : tags)
    7563     1048096 :           if (_current_nl_sys->hasMatrix(tag))
    7564             :           {
    7565      529953 :             auto & matrix = _current_nl_sys->getMatrix(tag);
    7566      529953 :             if (_restore_original_nonzero_pattern)
    7567        8195 :               matrix.restore_original_nonzero_pattern();
    7568             :             else
    7569      521758 :               matrix.zero();
    7570      529953 :             if (haveADObjects() && !_current_nl_sys->system().has_static_condensation())
    7571             :               // PETSc algorithms require diagonal allocations regardless of whether there is
    7572             :               // non-zero diagonal dependence. With global AD indexing we only add non-zero
    7573             :               // dependence, so PETSc will scream at us unless we artificially add the diagonals.
    7574     8316520 :               for (auto index : make_range(matrix.row_start(), matrix.row_stop()))
    7575     8258014 :                 matrix.add(index, index, 0);
    7576             :           }
    7577             : 
    7578      527967 :         _aux->zeroVariablesForJacobian();
    7579             : 
    7580      527967 :         unsigned int n_threads = libMesh::n_threads();
    7581             : 
    7582             :         // Random interface objects
    7583      530475 :         for (const auto & it : _random_data_objects)
    7584        2508 :           it.second->updateSeeds(EXEC_NONLINEAR);
    7585             : 
    7586      527967 :         _current_execute_on_flag = EXEC_NONLINEAR;
    7587      527967 :         _currently_computing_jacobian = true;
    7588      527967 :         if (_displaced_problem)
    7589       23348 :           _displaced_problem->setCurrentlyComputingJacobian(true);
    7590             : 
    7591      527967 :         execTransfers(EXEC_NONLINEAR);
    7592      527967 :         execMultiApps(EXEC_NONLINEAR);
    7593             : 
    7594     1104751 :         for (unsigned int tid = 0; tid < n_threads; tid++)
    7595      576784 :           reinitScalars(tid);
    7596             : 
    7597      527967 :         computeUserObjects(EXEC_NONLINEAR, Moose::PRE_AUX);
    7598             : 
    7599      527967 :         _aux->jacobianSetup();
    7600             : 
    7601      527967 :         if (_displaced_problem)
    7602             :         {
    7603       23348 :           computeSystems(EXEC_PRE_DISPLACE);
    7604       23348 :           _displaced_problem->updateMesh();
    7605             :         }
    7606             : 
    7607     1104742 :         for (unsigned int tid = 0; tid < n_threads; tid++)
    7608             :         {
    7609      576779 :           _all_materials.jacobianSetup(tid);
    7610      576779 :           _functions.jacobianSetup(tid);
    7611             :         }
    7612             : 
    7613      527963 :         computeSystems(EXEC_NONLINEAR);
    7614             : 
    7615      527963 :         computeUserObjects(EXEC_NONLINEAR, Moose::POST_AUX);
    7616             : 
    7617      527963 :         executeControls(EXEC_NONLINEAR);
    7618             : 
    7619      527963 :         _app.getOutputWarehouse().jacobianSetup();
    7620             : 
    7621      527963 :         _safe_access_tagged_matrices = false;
    7622             : 
    7623      527963 :         _current_nl_sys->computeJacobianTags(tags);
    7624             : 
    7625             :         // For explicit Euler calculations for example we often compute the Jacobian one time and
    7626             :         // then re-use it over and over. If we're performing automatic scaling, we don't want to
    7627             :         // use that kernel, diagonal-block only Jacobian for our actual matrix when performing
    7628             :         // solves!
    7629      527947 :         if (!_current_nl_sys->computingScalingJacobian())
    7630      527345 :           _has_jacobian = true;
    7631      527951 :       }
    7632             :     }
    7633           4 :     catch (...)
    7634             :     {
    7635           4 :       handleException("computeJacobianTags");
    7636           0 :     }
    7637             :   }
    7638           0 :   catch (const MooseException &)
    7639             :   {
    7640             :     // The buck stops here, we have already handled the exception by
    7641             :     // calling the system's stopSolve() method, it is now up to PETSc to return a
    7642             :     // "diverged" reason during the next solve.
    7643           0 :   }
    7644           0 :   catch (...)
    7645             :   {
    7646           0 :     mooseError("Unexpected exception type");
    7647           0 :   }
    7648             : 
    7649      535100 :   resetState();
    7650      535100 : }
    7651             : 
    7652             : void
    7653         302 : FEProblemBase::computeJacobianBlocks(std::vector<JacobianBlock *> & blocks,
    7654             :                                      const unsigned int nl_sys_num)
    7655             : {
    7656         906 :   TIME_SECTION("computeTransientImplicitJacobian", 2);
    7657         302 :   setCurrentNonlinearSystem(nl_sys_num);
    7658             : 
    7659         302 :   if (_displaced_problem)
    7660             :   {
    7661           0 :     computeSystems(EXEC_PRE_DISPLACE);
    7662           0 :     _displaced_problem->updateMesh();
    7663             :   }
    7664             : 
    7665         302 :   computeSystems(EXEC_NONLINEAR);
    7666             : 
    7667         302 :   _currently_computing_jacobian = true;
    7668         302 :   _current_nl_sys->computeJacobianBlocks(blocks);
    7669         302 :   _currently_computing_jacobian = false;
    7670         302 : }
    7671             : 
    7672             : void
    7673           0 : FEProblemBase::computeJacobianBlock(SparseMatrix<Number> & jacobian,
    7674             :                                     libMesh::System & precond_system,
    7675             :                                     unsigned int ivar,
    7676             :                                     unsigned int jvar)
    7677             : {
    7678           0 :   JacobianBlock jac_block(precond_system, jacobian, ivar, jvar);
    7679           0 :   std::vector<JacobianBlock *> blocks = {&jac_block};
    7680             :   mooseAssert(_current_nl_sys, "This should be non-null");
    7681           0 :   computeJacobianBlocks(blocks, _current_nl_sys->number());
    7682           0 : }
    7683             : 
    7684             : void
    7685         778 : FEProblemBase::computeBounds(NonlinearImplicitSystem & libmesh_dbg_var(sys),
    7686             :                              NumericVector<Number> & lower,
    7687             :                              NumericVector<Number> & upper)
    7688             : {
    7689             :   try
    7690             :   {
    7691             :     try
    7692             :     {
    7693             :       mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
    7694             :                   "I expect these system numbers to be the same");
    7695             : 
    7696        3890 :       if (!_current_nl_sys->hasVector("lower_bound") || !_current_nl_sys->hasVector("upper_bound"))
    7697           0 :         return;
    7698             : 
    7699        3890 :       TIME_SECTION("computeBounds", 1, "Computing Bounds");
    7700             : 
    7701        1556 :       NumericVector<Number> & _lower = _current_nl_sys->getVector("lower_bound");
    7702        1556 :       NumericVector<Number> & _upper = _current_nl_sys->getVector("upper_bound");
    7703         778 :       _lower.swap(lower);
    7704         778 :       _upper.swap(upper);
    7705        1620 :       for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
    7706         842 :         _all_materials.residualSetup(tid);
    7707             : 
    7708         778 :       _aux->residualSetup();
    7709         778 :       computeSystems(EXEC_LINEAR);
    7710         778 :       _lower.swap(lower);
    7711         778 :       _upper.swap(upper);
    7712         778 :     }
    7713           0 :     catch (...)
    7714             :     {
    7715           0 :       handleException("computeBounds");
    7716           0 :     }
    7717             :   }
    7718           0 :   catch (MooseException & e)
    7719             :   {
    7720           0 :     mooseError("Irrecoverable exception: " + std::string(e.what()));
    7721           0 :   }
    7722           0 :   catch (...)
    7723             :   {
    7724           0 :     mooseError("Unexpected exception type");
    7725           0 :   }
    7726             : }
    7727             : 
    7728             : void
    7729        5738 : FEProblemBase::computeLinearSystemSys(LinearImplicitSystem & sys,
    7730             :                                       SparseMatrix<Number> & system_matrix,
    7731             :                                       NumericVector<Number> & rhs,
    7732             :                                       const bool compute_gradients)
    7733             : {
    7734       17214 :   TIME_SECTION("computeLinearSystemSys", 5);
    7735             : 
    7736        5738 :   setCurrentLinearSystem(linearSysNum(sys.name()));
    7737             : 
    7738        5738 :   _current_linear_sys->associateVectorToTag(rhs, _current_linear_sys->rightHandSideVectorTag());
    7739        5738 :   _current_linear_sys->associateMatrixToTag(system_matrix, _current_linear_sys->systemMatrixTag());
    7740             : 
    7741             :   // We are using the residual tag system for right hand sides so we fetch everything
    7742        5738 :   const auto & vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
    7743             : 
    7744             :   // We filter out tags which do not have associated vectors in the current
    7745             :   // system. This is essential to be able to use system-dependent vector tags.
    7746        5738 :   selectVectorTagsFromSystem(*_current_linear_sys, vector_tags, _linear_vector_tags);
    7747        5738 :   selectMatrixTagsFromSystem(*_current_linear_sys, getMatrixTags(), _linear_matrix_tags);
    7748             : 
    7749        5738 :   computeLinearSystemTags(*(_current_linear_sys->currentSolution()),
    7750        5738 :                           _linear_vector_tags,
    7751        5738 :                           _linear_matrix_tags,
    7752             :                           compute_gradients);
    7753             : 
    7754        5738 :   _current_linear_sys->disassociateMatrixFromTag(system_matrix,
    7755        5738 :                                                  _current_linear_sys->systemMatrixTag());
    7756        5738 :   _current_linear_sys->disassociateVectorFromTag(rhs,
    7757        5738 :                                                  _current_linear_sys->rightHandSideVectorTag());
    7758             :   // We reset the tags to the default containers for further operations
    7759        5738 :   _current_linear_sys->associateVectorToTag(_current_linear_sys->getRightHandSideVector(),
    7760        5738 :                                             _current_linear_sys->rightHandSideVectorTag());
    7761        5738 :   _current_linear_sys->associateMatrixToTag(_current_linear_sys->getSystemMatrix(),
    7762        5738 :                                             _current_linear_sys->systemMatrixTag());
    7763        5738 : }
    7764             : 
    7765             : void
    7766        5738 : FEProblemBase::computeLinearSystemTags(const NumericVector<Number> & soln,
    7767             :                                        const std::set<TagID> & vector_tags,
    7768             :                                        const std::set<TagID> & matrix_tags,
    7769             :                                        const bool compute_gradients)
    7770             : {
    7771       28690 :   TIME_SECTION("computeLinearSystemTags", 5, "Computing Linear System");
    7772             : 
    7773        5738 :   _current_linear_sys->setSolution(soln);
    7774             : 
    7775       11500 :   for (auto tag : matrix_tags)
    7776             :   {
    7777        5762 :     auto & matrix = _current_linear_sys->getMatrix(tag);
    7778        5762 :     matrix.zero();
    7779             :   }
    7780             : 
    7781        5738 :   unsigned int n_threads = libMesh::n_threads();
    7782             : 
    7783        5738 :   _current_execute_on_flag = EXEC_NONLINEAR;
    7784             : 
    7785             :   // Random interface objects
    7786        5738 :   for (const auto & it : _random_data_objects)
    7787           0 :     it.second->updateSeeds(EXEC_NONLINEAR);
    7788             : 
    7789        5738 :   execTransfers(EXEC_NONLINEAR);
    7790        5738 :   execMultiApps(EXEC_NONLINEAR);
    7791             : 
    7792        5738 :   computeUserObjects(EXEC_NONLINEAR, Moose::PRE_AUX);
    7793             : 
    7794        5738 :   _aux->jacobianSetup();
    7795             : 
    7796       11476 :   for (THREAD_ID tid = 0; tid < n_threads; tid++)
    7797             :   {
    7798        5738 :     _functions.jacobianSetup(tid);
    7799             :   }
    7800             : 
    7801             :   try
    7802             :   {
    7803        5738 :     computeSystems(EXEC_NONLINEAR);
    7804             :   }
    7805           0 :   catch (MooseException & e)
    7806             :   {
    7807           0 :     _console << "\nA MooseException was raised during Auxiliary variable computation.\n"
    7808           0 :              << "The next solve will fail, the timestep will be reduced, and we will try again.\n"
    7809           0 :              << std::endl;
    7810             : 
    7811             :     // We know the next solve is going to fail, so there's no point in
    7812             :     // computing anything else after this.  Plus, using incompletely
    7813             :     // computed AuxVariables in subsequent calculations could lead to
    7814             :     // other errors or unhandled exceptions being thrown.
    7815           0 :     return;
    7816           0 :   }
    7817             : 
    7818        5738 :   computeUserObjects(EXEC_NONLINEAR, Moose::POST_AUX);
    7819        5738 :   executeControls(EXEC_NONLINEAR);
    7820             : 
    7821        5738 :   _app.getOutputWarehouse().jacobianSetup();
    7822             : 
    7823        5738 :   _current_linear_sys->computeLinearSystemTags(vector_tags, matrix_tags, compute_gradients);
    7824             : 
    7825             :   // Reset execution flag as after this point we are no longer on LINEAR
    7826        5738 :   _current_execute_on_flag = EXEC_NONE;
    7827             : 
    7828             :   // These are the relevant parts of resetState()
    7829        5738 :   _safe_access_tagged_vectors = true;
    7830        5738 :   _safe_access_tagged_matrices = true;
    7831        5738 : }
    7832             : 
    7833             : void
    7834      324553 : FEProblemBase::computeNearNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
    7835             :                                     std::vector<NumericVector<Number> *> & sp)
    7836             : {
    7837             :   mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
    7838             :               "I expect these system numbers to be the same");
    7839             : 
    7840      324553 :   sp.clear();
    7841      973659 :   for (unsigned int i = 0; i < subspaceDim("NearNullSpace"); ++i)
    7842             :   {
    7843           0 :     std::stringstream postfix;
    7844           0 :     postfix << "_" << i;
    7845           0 :     std::string modename = "NearNullSpace" + postfix.str();
    7846           0 :     sp.push_back(&_current_nl_sys->getVector(modename));
    7847           0 :   }
    7848      324553 : }
    7849             : 
    7850             : void
    7851      324553 : FEProblemBase::computeNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
    7852             :                                 std::vector<NumericVector<Number> *> & sp)
    7853             : {
    7854             :   mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
    7855             :               "I expect these system numbers to be the same");
    7856      324553 :   sp.clear();
    7857      973731 :   for (unsigned int i = 0; i < subspaceDim("NullSpace"); ++i)
    7858             :   {
    7859          24 :     std::stringstream postfix;
    7860          24 :     postfix << "_" << i;
    7861          24 :     sp.push_back(&_current_nl_sys->getVector("NullSpace" + postfix.str()));
    7862          24 :   }
    7863      324553 : }
    7864             : 
    7865             : void
    7866      324553 : FEProblemBase::computeTransposeNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
    7867             :                                          std::vector<NumericVector<Number> *> & sp)
    7868             : {
    7869             :   mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
    7870             :               "I expect these system numbers to be the same");
    7871      324553 :   sp.clear();
    7872      973695 :   for (unsigned int i = 0; i < subspaceDim("TransposeNullSpace"); ++i)
    7873             :   {
    7874          12 :     std::stringstream postfix;
    7875          12 :     postfix << "_" << i;
    7876          12 :     sp.push_back(&_current_nl_sys->getVector("TransposeNullSpace" + postfix.str()));
    7877          12 :   }
    7878      324553 : }
    7879             : 
    7880             : void
    7881        1976 : FEProblemBase::computePostCheck(NonlinearImplicitSystem & sys,
    7882             :                                 const NumericVector<Number> & old_soln,
    7883             :                                 NumericVector<Number> & search_direction,
    7884             :                                 NumericVector<Number> & new_soln,
    7885             :                                 bool & changed_search_direction,
    7886             :                                 bool & changed_new_soln)
    7887             : {
    7888             :   mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
    7889             :               "I expect these system numbers to be the same");
    7890             : 
    7891             :   // This function replaces the old PetscSupport::dampedCheck() function.
    7892             :   //
    7893             :   // 1.) Recreate code in PetscSupport::dampedCheck() for constructing
    7894             :   //     ghosted "soln" and "update" vectors.
    7895             :   // 2.) Call FEProblemBase::computeDamping() with these ghost vectors.
    7896             :   // 3.) Recreate the code in PetscSupport::dampedCheck() to actually update
    7897             :   //     the solution vector based on the damping, and set the "changed" flags
    7898             :   //     appropriately.
    7899             : 
    7900        9880 :   TIME_SECTION("computePostCheck", 2, "Computing Post Check");
    7901             : 
    7902        1976 :   _current_execute_on_flag = EXEC_POSTCHECK;
    7903             : 
    7904             :   // MOOSE's FEProblemBase doesn't update the solution during the
    7905             :   // postcheck, but FEProblemBase-derived classes might.
    7906        1976 :   if (_has_dampers || shouldUpdateSolution())
    7907             :   {
    7908             :     // We need ghosted versions of new_soln and search_direction (the
    7909             :     // ones we get from libmesh/PETSc are PARALLEL vectors.  To make
    7910             :     // our lives simpler, we use the same ghosting pattern as the
    7911             :     // system's current_local_solution to create new ghosted vectors.
    7912             : 
    7913             :     // Construct zeroed-out clones with the same ghosted dofs as the
    7914             :     // System's current_local_solution.
    7915             :     std::unique_ptr<NumericVector<Number>> ghosted_solution =
    7916        1420 :                                                sys.current_local_solution->zero_clone(),
    7917             :                                            ghosted_search_direction =
    7918        1420 :                                                sys.current_local_solution->zero_clone();
    7919             : 
    7920             :     // Copy values from input vectors into clones with ghosted values.
    7921        1420 :     *ghosted_solution = new_soln;
    7922        1420 :     *ghosted_search_direction = search_direction;
    7923             : 
    7924        1420 :     if (_has_dampers)
    7925             :     {
    7926             :       // Compute the damping coefficient using the ghosted vectors
    7927        1420 :       Real damping = computeDamping(*ghosted_solution, *ghosted_search_direction);
    7928             : 
    7929             :       // If some non-trivial damping was computed, update the new_soln
    7930             :       // vector accordingly.
    7931        1420 :       if (damping < 1.0)
    7932             :       {
    7933         995 :         new_soln = old_soln;
    7934         995 :         new_soln.add(-damping, search_direction);
    7935         995 :         changed_new_soln = true;
    7936             :       }
    7937             :     }
    7938             : 
    7939        1420 :     if (shouldUpdateSolution())
    7940             :     {
    7941             :       // Update the ghosted copy of the new solution, if necessary.
    7942           0 :       if (changed_new_soln)
    7943           0 :         *ghosted_solution = new_soln;
    7944             : 
    7945           0 :       bool updated_solution = updateSolution(new_soln, *ghosted_solution);
    7946           0 :       if (updated_solution)
    7947           0 :         changed_new_soln = true;
    7948             :     }
    7949        1420 :   }
    7950             : 
    7951        1976 :   if (vectorTagExists(Moose::PREVIOUS_NL_SOLUTION_TAG))
    7952             :   {
    7953         556 :     _current_nl_sys->setPreviousNewtonSolution(old_soln);
    7954         556 :     _aux->copyCurrentIntoPreviousNL();
    7955             :   }
    7956             : 
    7957             :   // MOOSE doesn't change the search_direction
    7958        1976 :   changed_search_direction = false;
    7959             : 
    7960        1976 :   _current_execute_on_flag = EXEC_NONE;
    7961        1976 : }
    7962             : 
    7963             : Real
    7964        1420 : FEProblemBase::computeDamping(const NumericVector<Number> & soln,
    7965             :                               const NumericVector<Number> & update)
    7966             : {
    7967             :   // Default to no damping
    7968        1420 :   Real damping = 1.0;
    7969             : 
    7970        1420 :   if (_has_dampers)
    7971             :   {
    7972        7100 :     TIME_SECTION("computeDamping", 1, "Computing Damping");
    7973             : 
    7974             :     // Save pointer to the current solution
    7975        1420 :     const NumericVector<Number> * _saved_current_solution = _current_nl_sys->currentSolution();
    7976             : 
    7977        1420 :     _current_nl_sys->setSolution(soln);
    7978             :     // For now, do not re-compute auxiliary variables.  Doing so allows a wild solution increment
    7979             :     //   to get to the material models, which may not be able to cope with drastically different
    7980             :     //   values.  Once more complete dependency checking is in place, auxiliary variables (and
    7981             :     //   material properties) will be computed as needed by dampers.
    7982             :     //    _aux.compute();
    7983        1420 :     damping = _current_nl_sys->computeDamping(soln, update);
    7984             : 
    7985             :     // restore saved solution
    7986        1420 :     _current_nl_sys->setSolution(*_saved_current_solution);
    7987        1420 :   }
    7988             : 
    7989        1420 :   return damping;
    7990             : }
    7991             : 
    7992             : bool
    7993      318232 : FEProblemBase::shouldUpdateSolution()
    7994             : {
    7995      318232 :   return false;
    7996             : }
    7997             : 
    7998             : bool
    7999           0 : FEProblemBase::updateSolution(NumericVector<Number> & /*vec_solution*/,
    8000             :                               NumericVector<Number> & /*ghosted_solution*/)
    8001             : {
    8002           0 :   return false;
    8003             : }
    8004             : 
    8005             : void
    8006         223 : FEProblemBase::predictorCleanup(NumericVector<Number> & /*ghosted_solution*/)
    8007             : {
    8008         223 : }
    8009             : 
    8010             : void
    8011        2246 : FEProblemBase::addDisplacedProblem(std::shared_ptr<DisplacedProblem> displaced_problem)
    8012             : {
    8013             :   parallel_object_only();
    8014             : 
    8015        2246 :   _displaced_mesh = &displaced_problem->mesh();
    8016        2246 :   _displaced_problem = displaced_problem;
    8017        2246 : }
    8018             : 
    8019             : void
    8020      124805 : FEProblemBase::updateGeomSearch(GeometricSearchData::GeometricSearchType type)
    8021             : {
    8022      624025 :   TIME_SECTION("updateGeometricSearch", 3, "Updating Geometric Search");
    8023             : 
    8024      124805 :   _geometric_search_data.update(type);
    8025             : 
    8026      124805 :   if (_displaced_problem)
    8027        4669 :     _displaced_problem->updateGeomSearch(type);
    8028      124805 : }
    8029             : 
    8030             : void
    8031       74033 : FEProblemBase::updateMortarMesh()
    8032             : {
    8033      370165 :   TIME_SECTION("updateMortarMesh", 5, "Updating Mortar Mesh");
    8034             : 
    8035       74033 :   FloatingPointExceptionGuard fpe_guard(_app);
    8036             : 
    8037       74033 :   _mortar_data->update();
    8038       74033 : }
    8039             : 
    8040             : void
    8041        1448 : FEProblemBase::createMortarInterface(
    8042             :     const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
    8043             :     const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
    8044             :     bool on_displaced,
    8045             :     bool periodic,
    8046             :     const bool debug,
    8047             :     const bool correct_edge_dropping,
    8048             :     const Real minimum_projection_angle)
    8049             : {
    8050        1448 :   _has_mortar = true;
    8051             : 
    8052        1448 :   if (on_displaced)
    8053         276 :     return _mortar_data->createMortarInterface(primary_secondary_boundary_pair,
    8054             :                                                primary_secondary_subdomain_pair,
    8055         138 :                                                *_displaced_problem,
    8056             :                                                on_displaced,
    8057             :                                                periodic,
    8058             :                                                debug,
    8059             :                                                correct_edge_dropping,
    8060         138 :                                                minimum_projection_angle);
    8061             :   else
    8062        1310 :     return _mortar_data->createMortarInterface(primary_secondary_boundary_pair,
    8063             :                                                primary_secondary_subdomain_pair,
    8064             :                                                *this,
    8065             :                                                on_displaced,
    8066             :                                                periodic,
    8067             :                                                debug,
    8068             :                                                correct_edge_dropping,
    8069        1310 :                                                minimum_projection_angle);
    8070             : }
    8071             : 
    8072             : const AutomaticMortarGeneration &
    8073           0 : FEProblemBase::getMortarInterface(
    8074             :     const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
    8075             :     const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
    8076             :     bool on_displaced) const
    8077             : {
    8078           0 :   return _mortar_data->getMortarInterface(
    8079           0 :       primary_secondary_boundary_pair, primary_secondary_subdomain_pair, on_displaced);
    8080             : }
    8081             : 
    8082             : AutomaticMortarGeneration &
    8083      258234 : FEProblemBase::getMortarInterface(
    8084             :     const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
    8085             :     const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
    8086             :     bool on_displaced)
    8087             : {
    8088      258234 :   return _mortar_data->getMortarInterface(
    8089      258234 :       primary_secondary_boundary_pair, primary_secondary_subdomain_pair, on_displaced);
    8090             : }
    8091             : 
    8092             : void
    8093      348123 : FEProblemBase::possiblyRebuildGeomSearchPatches()
    8094             : {
    8095      348123 :   if (_displaced_problem) // Only need to do this if things are moving...
    8096             :   {
    8097      179345 :     TIME_SECTION("possiblyRebuildGeomSearchPatches", 5, "Rebuilding Geometric Search Patches");
    8098             : 
    8099       35869 :     switch (_mesh.getPatchUpdateStrategy())
    8100             :     {
    8101       34675 :       case Moose::Never:
    8102       34675 :         break;
    8103         398 :       case Moose::Iteration:
    8104             :         // Update the list of ghosted elements at the start of the time step
    8105         398 :         _geometric_search_data.updateGhostedElems();
    8106         398 :         _mesh.updateActiveSemiLocalNodeRange(_ghosted_elems);
    8107             : 
    8108         398 :         _displaced_problem->geomSearchData().updateGhostedElems();
    8109         398 :         _displaced_mesh->updateActiveSemiLocalNodeRange(_ghosted_elems);
    8110             : 
    8111             :         // The commands below ensure that the sparsity of the Jacobian matrix is
    8112             :         // augmented at the start of the time step using neighbor nodes from the end
    8113             :         // of the previous time step.
    8114             : 
    8115         398 :         reinitBecauseOfGhostingOrNewGeomObjects();
    8116             : 
    8117             :         // This is needed to reinitialize PETSc output
    8118         398 :         initPetscOutputAndSomeSolverSettings();
    8119             : 
    8120         398 :         break;
    8121             : 
    8122         361 :       case Moose::Auto:
    8123             :       {
    8124         361 :         Real max = _displaced_problem->geomSearchData().maxPatchPercentage();
    8125         361 :         _communicator.max(max);
    8126             : 
    8127             :         // If we haven't moved very far through the patch
    8128         361 :         if (max < 0.4)
    8129         325 :           break;
    8130             :       }
    8131             :         libmesh_fallthrough();
    8132             : 
    8133             :       // Let this fall through if things do need to be updated...
    8134             :       case Moose::Always:
    8135             :         // Flush output here to see the message before the reinitialization, which could take a
    8136             :         // while
    8137         471 :         _console << "\n\nUpdating geometric search patches\n" << std::endl;
    8138             : 
    8139         471 :         _geometric_search_data.clearNearestNodeLocators();
    8140         471 :         _mesh.updateActiveSemiLocalNodeRange(_ghosted_elems);
    8141             : 
    8142         471 :         _displaced_problem->geomSearchData().clearNearestNodeLocators();
    8143         471 :         _displaced_mesh->updateActiveSemiLocalNodeRange(_ghosted_elems);
    8144             : 
    8145         471 :         reinitBecauseOfGhostingOrNewGeomObjects();
    8146             : 
    8147             :         // This is needed to reinitialize PETSc output
    8148         471 :         initPetscOutputAndSomeSolverSettings();
    8149             :     }
    8150       35869 :   }
    8151      348123 : }
    8152             : 
    8153             : #ifdef LIBMESH_ENABLE_AMR
    8154             : void
    8155       57781 : FEProblemBase::initialAdaptMesh()
    8156             : {
    8157       57781 :   unsigned int n = adaptivity().getInitialSteps();
    8158       57781 :   _cycles_completed = 0;
    8159       57781 :   if (n)
    8160             :   {
    8161         695 :     if (!_mesh.interiorLowerDBlocks().empty() || !_mesh.boundaryLowerDBlocks().empty())
    8162           4 :       mooseError("HFEM does not support mesh adaptivity currently.");
    8163             : 
    8164        3455 :     TIME_SECTION("initialAdaptMesh", 2, "Performing Initial Adaptivity");
    8165             : 
    8166        1667 :     for (unsigned int i = 0; i < n; i++)
    8167             :     {
    8168        1169 :       computeIndicators();
    8169        1169 :       computeMarkers();
    8170             : 
    8171        1169 :       if (_adaptivity.initialAdaptMesh())
    8172             :       {
    8173         976 :         meshChanged(
    8174             :             /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
    8175             : 
    8176             :         // reproject the initial condition
    8177         976 :         projectSolution();
    8178             : 
    8179         976 :         _cycles_completed++;
    8180             :       }
    8181             :       else
    8182             :       {
    8183         193 :         _console << "Mesh unchanged, skipping remaining steps..." << std::endl;
    8184         193 :         return;
    8185             :       }
    8186             :     }
    8187         691 :   }
    8188             : }
    8189             : 
    8190             : bool
    8191      182268 : FEProblemBase::adaptMesh()
    8192             : {
    8193             :   // reset cycle counter
    8194      182268 :   _cycles_completed = 0;
    8195             : 
    8196      182268 :   if (!_adaptivity.isAdaptivityDue())
    8197      177332 :     return false;
    8198             : 
    8199       24680 :   TIME_SECTION("adaptMesh", 3, "Adapting Mesh");
    8200             : 
    8201        4936 :   unsigned int cycles_per_step = _adaptivity.getCyclesPerStep();
    8202             : 
    8203        4936 :   bool mesh_changed = false;
    8204             : 
    8205        8674 :   for (unsigned int i = 0; i < cycles_per_step; ++i)
    8206             :   {
    8207        5102 :     if (!_mesh.interiorLowerDBlocks().empty() || !_mesh.boundaryLowerDBlocks().empty())
    8208           0 :       mooseError("HFEM does not support mesh adaptivity currently.");
    8209             : 
    8210             :     // Markers were already computed once by Executioner
    8211        5102 :     if (_adaptivity.getRecomputeMarkersFlag() && i > 0)
    8212          24 :       computeMarkers();
    8213             : 
    8214             :     bool mesh_changed_this_step;
    8215        5102 :     mesh_changed_this_step = _adaptivity.adaptMesh();
    8216             : 
    8217        5102 :     if (mesh_changed_this_step)
    8218             :     {
    8219        3738 :       mesh_changed = true;
    8220             : 
    8221        3738 :       meshChanged(
    8222             :           /*intermediate_change=*/true, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
    8223        3738 :       _cycles_completed++;
    8224             :     }
    8225             :     else
    8226             :     {
    8227             :       // If the mesh didn't change, we still need to update the displaced mesh
    8228             :       // to undo the undisplacement performed in Adaptivity::adaptMesh
    8229        1364 :       if (_displaced_problem)
    8230          48 :         _displaced_problem->updateMesh();
    8231             : 
    8232        1364 :       _console << "Mesh unchanged, skipping remaining steps..." << std::endl;
    8233        1364 :       break;
    8234             :     }
    8235             : 
    8236             :     // Show adaptivity progress
    8237        3738 :     _console << std::flush;
    8238             :   }
    8239             : 
    8240             :   // We're done with all intermediate changes; now get systems ready
    8241             :   // for real if necessary.
    8242        4936 :   if (mesh_changed)
    8243        3584 :     es().reinit_systems();
    8244             : 
    8245             :   // Execute multi-apps that need to run after adaptivity, but before the next timestep.
    8246        4936 :   execMultiApps(EXEC_POST_ADAPTIVITY);
    8247             : 
    8248        4936 :   return mesh_changed;
    8249        4936 : }
    8250             : #endif // LIBMESH_ENABLE_AMR
    8251             : 
    8252             : void
    8253           0 : FEProblemBase::initXFEM(std::shared_ptr<XFEMInterface> xfem)
    8254             : {
    8255           0 :   _xfem = xfem;
    8256           0 :   _xfem->setMesh(&_mesh);
    8257           0 :   if (_displaced_mesh)
    8258           0 :     _xfem->setDisplacedMesh(_displaced_mesh);
    8259             : 
    8260           0 :   auto fill_data = [](auto & storage)
    8261             :   {
    8262           0 :     std::vector<MaterialData *> data(libMesh::n_threads());
    8263           0 :     for (const auto tid : make_range(libMesh::n_threads()))
    8264           0 :       data[tid] = &storage.getMaterialData(tid);
    8265           0 :     return data;
    8266           0 :   };
    8267           0 :   _xfem->setMaterialData(fill_data(_material_props));
    8268           0 :   _xfem->setBoundaryMaterialData(fill_data(_bnd_material_props));
    8269             : 
    8270           0 :   unsigned int n_threads = libMesh::n_threads();
    8271           0 :   for (unsigned int i = 0; i < n_threads; ++i)
    8272           0 :     for (const auto nl_sys_num : index_range(_nl))
    8273             :     {
    8274           0 :       _assembly[i][nl_sys_num]->setXFEM(_xfem);
    8275           0 :       if (_displaced_problem)
    8276           0 :         _displaced_problem->assembly(i, nl_sys_num).setXFEM(_xfem);
    8277             :     }
    8278           0 : }
    8279             : 
    8280             : bool
    8281           0 : FEProblemBase::updateMeshXFEM()
    8282             : {
    8283           0 :   TIME_SECTION("updateMeshXFEM", 5, "Updating XFEM");
    8284             : 
    8285           0 :   bool updated = false;
    8286           0 :   if (haveXFEM())
    8287             :   {
    8288           0 :     if (_xfem->updateHeal())
    8289             :       // XFEM exodiff tests rely on a given numbering because they cannot use map = true due to
    8290             :       // having coincident elements. While conceptually speaking we do not need to contract the
    8291             :       // mesh, we need its call to renumber_nodes_and_elements in order to preserve these tests
    8292           0 :       meshChanged(
    8293             :           /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/false);
    8294             : 
    8295           0 :     updated = _xfem->update(_time, _nl, *_aux);
    8296           0 :     if (updated)
    8297             :     {
    8298           0 :       meshChanged(
    8299             :           /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/false);
    8300           0 :       _xfem->initSolution(_nl, *_aux);
    8301           0 :       restoreSolutions();
    8302           0 :       _console << "\nXFEM update complete: Mesh modified" << std::endl;
    8303             :     }
    8304             :     else
    8305           0 :       _console << "\nXFEM update complete: Mesh not modified" << std::endl;
    8306             :   }
    8307           0 :   return updated;
    8308           0 : }
    8309             : 
    8310             : void
    8311        7587 : FEProblemBase::meshChanged(const bool intermediate_change,
    8312             :                            const bool contract_mesh,
    8313             :                            const bool clean_refinement_flags)
    8314             : {
    8315       37935 :   TIME_SECTION("meshChanged", 3, "Handling Mesh Changes");
    8316             : 
    8317       14942 :   if (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    8318        7355 :       _neighbor_material_props.hasStatefulProperties())
    8319         232 :     _mesh.cacheChangedLists(); // Currently only used with adaptivity and stateful material
    8320             :                                // properties
    8321             : 
    8322             :   // Clear these out because they corresponded to the old mesh
    8323        7587 :   _ghosted_elems.clear();
    8324        7587 :   ghostGhostedBoundaries();
    8325             : 
    8326             :   // The mesh changed.  We notify the MooseMesh first, because
    8327             :   // callbacks (e.g. for sparsity calculations) triggered by the
    8328             :   // EquationSystems reinit may require up-to-date MooseMesh caches.
    8329        7587 :   _mesh.meshChanged();
    8330             : 
    8331             :   // If we're just going to alter the mesh again, all we need to
    8332             :   // handle here is AMR and projections, not full system reinit
    8333        7587 :   if (intermediate_change)
    8334        3773 :     es().reinit_solutions();
    8335             :   else
    8336        3814 :     es().reinit();
    8337             : 
    8338        7587 :   if (contract_mesh)
    8339             :     // Once vectors are restricted, we can delete children of coarsened elements
    8340        4817 :     _mesh.getMesh().contract();
    8341        7587 :   if (clean_refinement_flags)
    8342             :   {
    8343             :     // Finally clear refinement flags so that if someone tries to project vectors again without
    8344             :     // an intervening mesh refinement to clear flags they won't run into trouble
    8345        4817 :     MeshRefinement refinement(_mesh.getMesh());
    8346        4817 :     refinement.clean_refinement_flags();
    8347        4817 :   }
    8348             : 
    8349        7587 :   if (!intermediate_change)
    8350             :   {
    8351             :     // Since the mesh has changed, we need to make sure that we update any of our
    8352             :     // MOOSE-system specific data.
    8353        7628 :     for (auto & sys : _solver_systems)
    8354        3814 :       sys->reinit();
    8355        3814 :     _aux->reinit();
    8356             :   }
    8357             : 
    8358             :   // Updating MooseMesh first breaks other adaptivity code, unless we
    8359             :   // then *again* update the MooseMesh caches.  E.g. the definition of
    8360             :   // "active" and "local" may have been *changed* by refinement and
    8361             :   // repartitioning done in EquationSystems::reinit().
    8362        7587 :   _mesh.meshChanged();
    8363             : 
    8364             :   // If we have finite volume variables, we will need to recompute additional elemental/face
    8365             :   // quantities
    8366        7587 :   if (haveFV() && _mesh.isFiniteVolumeInfoDirty())
    8367         384 :     _mesh.setupFiniteVolumeMeshData();
    8368             : 
    8369             :   // Let the meshChangedInterface notify the mesh changed event before we update the active
    8370             :   // semilocal nodes, because the set of ghosted elements may potentially be updated during a mesh
    8371             :   // changed event.
    8372      133674 :   for (const auto & mci : _notify_when_mesh_changes)
    8373      126087 :     mci->meshChanged();
    8374             : 
    8375             :   // Since the Mesh changed, update the PointLocator object used by DiracKernels.
    8376        7587 :   _dirac_kernel_info.updatePointLocator(_mesh);
    8377             : 
    8378             :   // Need to redo ghosting
    8379        7587 :   _geometric_search_data.reinit();
    8380             : 
    8381        7587 :   if (_displaced_problem)
    8382             :   {
    8383         633 :     _displaced_problem->meshChanged(contract_mesh, clean_refinement_flags);
    8384         633 :     _displaced_mesh->updateActiveSemiLocalNodeRange(_ghosted_elems);
    8385             :   }
    8386             : 
    8387        7587 :   _mesh.updateActiveSemiLocalNodeRange(_ghosted_elems);
    8388             : 
    8389        7587 :   _evaluable_local_elem_range.reset();
    8390        7587 :   _nl_evaluable_local_elem_range.reset();
    8391             : 
    8392             :   // Just like we reinitialized our geometric search objects, we also need to reinitialize our
    8393             :   // mortar meshes. Note that this needs to happen after DisplacedProblem::meshChanged because the
    8394             :   // mortar mesh discretization will depend necessarily on the displaced mesh being re-displaced
    8395        7587 :   updateMortarMesh();
    8396             : 
    8397             :   // Nonlinear systems hold the mortar mesh functors. The domains of definition of the mortar
    8398             :   // functors might have changed when the mesh changed.
    8399       15162 :   for (auto & nl_sys : _nl)
    8400        7575 :     nl_sys->reinitMortarFunctors();
    8401             : 
    8402        7587 :   reinitBecauseOfGhostingOrNewGeomObjects(/*mortar_changed=*/true);
    8403             : 
    8404             :   // We need to create new storage for newly active elements, and copy
    8405             :   // stateful properties from the old elements.
    8406        7819 :   if (_has_initialized_stateful &&
    8407         232 :       (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties()))
    8408             :   {
    8409         232 :     if (havePRefinement())
    8410          72 :       _mesh.buildPRefinementAndCoarseningMaps(_assembly[0][0].get());
    8411             : 
    8412             :     // Prolong properties onto newly refined elements' children
    8413             :     {
    8414             :       ProjectMaterialProperties pmp(
    8415         232 :           /* refine = */ true, *this, _material_props, _bnd_material_props, _assembly);
    8416         232 :       const auto & range = *_mesh.refinedElementRange();
    8417         232 :       Threads::parallel_reduce(range, pmp);
    8418             : 
    8419             :       // Concurrent erasure from the shared hash map is not safe while we are reading from it in
    8420             :       // ProjectMaterialProperties, so we handle erasure here. Moreover, erasure based on key is
    8421             :       // not thread safe in and of itself because it is a read-write operation. Note that we do not
    8422             :       // do the erasure for p-refinement because the coarse level element is the same as our active
    8423             :       // refined level element
    8424         232 :       if (!doingPRefinement())
    8425        3758 :         for (const auto & elem : range)
    8426             :         {
    8427        3598 :           _material_props.eraseProperty(elem);
    8428        3598 :           _bnd_material_props.eraseProperty(elem);
    8429        3598 :           _neighbor_material_props.eraseProperty(elem);
    8430             :         }
    8431         232 :     }
    8432             : 
    8433             :     // Restrict properties onto newly coarsened elements
    8434             :     {
    8435             :       ProjectMaterialProperties pmp(
    8436         232 :           /* refine = */ false, *this, _material_props, _bnd_material_props, _assembly);
    8437         232 :       const auto & range = *_mesh.coarsenedElementRange();
    8438         232 :       Threads::parallel_reduce(range, pmp);
    8439             :       // Note that we do not do the erasure for p-refinement because the coarse level element is the
    8440             :       // same as our active refined level element
    8441         232 :       if (!doingPRefinement())
    8442        1525 :         for (const auto & elem : range)
    8443             :         {
    8444        1365 :           auto && coarsened_children = _mesh.coarsenedElementChildren(elem);
    8445        8861 :           for (auto && child : coarsened_children)
    8446             :           {
    8447        7496 :             _material_props.eraseProperty(child);
    8448        7496 :             _bnd_material_props.eraseProperty(child);
    8449        7496 :             _neighbor_material_props.eraseProperty(child);
    8450             :           }
    8451             :         }
    8452         232 :     }
    8453             :   }
    8454             : 
    8455        7587 :   if (_calculate_jacobian_in_uo)
    8456           0 :     setVariableAllDoFMap(_uo_jacobian_moose_vars[0]);
    8457             : 
    8458        7587 :   _has_jacobian = false; // we have to recompute jacobian when mesh changed
    8459             : 
    8460             :   // Now for backwards compatibility with user code that overrode the old no-arg meshChanged we must
    8461             :   // call it here
    8462        7587 :   meshChanged();
    8463        7587 : }
    8464             : 
    8465             : void
    8466      974143 : FEProblemBase::notifyWhenMeshChanges(MeshChangedInterface * mci)
    8467             : {
    8468      974143 :   _notify_when_mesh_changes.push_back(mci);
    8469      974143 : }
    8470             : 
    8471             : void
    8472       85453 : FEProblemBase::notifyWhenMeshDisplaces(MeshDisplacedInterface * mdi)
    8473             : {
    8474       85453 :   _notify_when_mesh_displaces.push_back(mdi);
    8475       85453 : }
    8476             : 
    8477             : void
    8478       70072 : FEProblemBase::meshDisplaced()
    8479             : {
    8480      101233 :   for (const auto & mdi : _notify_when_mesh_displaces)
    8481       31161 :     mdi->meshDisplaced();
    8482       70072 : }
    8483             : 
    8484             : void
    8485       10246 : FEProblemBase::initElementStatefulProps(const ConstElemRange & elem_range, const bool threaded)
    8486             : {
    8487             :   ComputeMaterialsObjectThread cmt(
    8488       10246 :       *this, _material_props, _bnd_material_props, _neighbor_material_props, _assembly);
    8489       10246 :   if (threaded)
    8490       10246 :     Threads::parallel_reduce(elem_range, cmt);
    8491             :   else
    8492           0 :     cmt(elem_range, true);
    8493             : 
    8494             : #ifdef MOOSE_KOKKOS_ENABLED
    8495        6918 :   if (_has_kokkos_objects)
    8496         310 :     initKokkosStatefulProps();
    8497             : #endif
    8498       10246 : }
    8499             : 
    8500             : void
    8501       62652 : FEProblemBase::checkProblemIntegrity()
    8502             : {
    8503      187956 :   TIME_SECTION("checkProblemIntegrity", 5);
    8504             : 
    8505             :   // Subdomains specified by the "Problem/block" parameter
    8506      125304 :   const auto & subdomain_names = getParam<std::vector<SubdomainName>>("block");
    8507       62652 :   auto mesh_subdomains_vec = MooseMeshUtils::getSubdomainIDs(_mesh, subdomain_names);
    8508       62652 :   std::set<SubdomainID> mesh_subdomains(mesh_subdomains_vec.begin(), mesh_subdomains_vec.end());
    8509             : 
    8510             :   // Check kernel coverage of subdomains (blocks) in the mesh
    8511       62652 :   if (!_skip_nl_system_check && _solve && _kernel_coverage_check != CoverageCheckMode::FALSE &&
    8512       45094 :       _kernel_coverage_check != CoverageCheckMode::OFF)
    8513             :   {
    8514       45081 :     std::set<SubdomainID> blocks;
    8515       45081 :     if (_kernel_coverage_check == CoverageCheckMode::TRUE ||
    8516         237 :         _kernel_coverage_check == CoverageCheckMode::ON)
    8517       44844 :       blocks = mesh_subdomains;
    8518         237 :     else if (_kernel_coverage_check == CoverageCheckMode::SKIP_LIST)
    8519             :     {
    8520          13 :       blocks = mesh_subdomains;
    8521          26 :       for (const auto & subdomain_name : _kernel_coverage_blocks)
    8522             :       {
    8523          13 :         const auto id = _mesh.getSubdomainID(subdomain_name);
    8524          13 :         if (id == Moose::INVALID_BLOCK_ID)
    8525           0 :           paramError("kernel_coverage_block_list",
    8526             :                      "Subdomain \"",
    8527             :                      subdomain_name,
    8528             :                      "\" not found in mesh.");
    8529          13 :         blocks.erase(id);
    8530             :       }
    8531             :     }
    8532         224 :     else if (_kernel_coverage_check == CoverageCheckMode::ONLY_LIST)
    8533         448 :       for (const auto & subdomain_name : _kernel_coverage_blocks)
    8534             :       {
    8535         224 :         const auto id = _mesh.getSubdomainID(subdomain_name);
    8536         224 :         if (id == Moose::INVALID_BLOCK_ID)
    8537           0 :           paramError("kernel_coverage_block_list",
    8538             :                      "Subdomain \"",
    8539             :                      subdomain_name,
    8540             :                      "\" not found in mesh.");
    8541         224 :         blocks.insert(id);
    8542             :       }
    8543       45081 :     if (!blocks.empty())
    8544       89068 :       for (auto & nl : _nl)
    8545       44003 :         nl->checkKernelCoverage(blocks);
    8546       45065 :   }
    8547             : 
    8548             :   // Check materials
    8549             :   {
    8550             : #ifdef LIBMESH_ENABLE_AMR
    8551       65056 :     if ((_adaptivity.isOn() || _num_grid_steps) &&
    8552        2420 :         (_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
    8553        2349 :          _neighbor_material_props.hasStatefulProperties()))
    8554             :     {
    8555          71 :       _console << "Using EXPERIMENTAL Stateful Material Property projection with Adaptivity!\n"
    8556          71 :                << std::flush;
    8557             :     }
    8558             : #endif
    8559             : 
    8560       62636 :     std::set<SubdomainID> local_mesh_subs(mesh_subdomains);
    8561             : 
    8562       62636 :     if (_material_coverage_check != CoverageCheckMode::FALSE &&
    8563       62544 :         _material_coverage_check != CoverageCheckMode::OFF)
    8564             :     {
    8565             :       /**
    8566             :        * If a material is specified for any block in the simulation, then all blocks must
    8567             :        * have a material specified.
    8568             :        */
    8569       62544 :       bool check_material_coverage = false;
    8570       62544 :       std::set<SubdomainID> ids = _all_materials.getActiveBlocks();
    8571       75758 :       for (const auto & id : ids)
    8572             :       {
    8573       13214 :         local_mesh_subs.erase(id);
    8574       13214 :         check_material_coverage = true;
    8575             :       }
    8576             : 
    8577             :       // did the user limit the subdomains to be checked?
    8578       62544 :       if (_material_coverage_check == CoverageCheckMode::SKIP_LIST)
    8579             :       {
    8580          26 :         for (const auto & subdomain_name : _material_coverage_blocks)
    8581             :         {
    8582          13 :           const auto id = _mesh.getSubdomainID(subdomain_name);
    8583          13 :           if (id == Moose::INVALID_BLOCK_ID)
    8584           0 :             paramError("material_coverage_block_list",
    8585           0 :                        "Subdomain \"" + subdomain_name + "\" not found in mesh.");
    8586          13 :           local_mesh_subs.erase(id);
    8587             :         }
    8588             :       }
    8589       62531 :       else if (_material_coverage_check == CoverageCheckMode::ONLY_LIST)
    8590             :       {
    8591         224 :         std::set<SubdomainID> blocks(local_mesh_subs);
    8592         448 :         for (const auto & subdomain_name : _material_coverage_blocks)
    8593             :         {
    8594         224 :           const auto id = _mesh.getSubdomainID(subdomain_name);
    8595         224 :           if (id == Moose::INVALID_BLOCK_ID)
    8596           0 :             paramError("material_coverage_block_list",
    8597           0 :                        "Subdomain \"" + subdomain_name + "\" not found in mesh.");
    8598         224 :           blocks.erase(id);
    8599             :         }
    8600         237 :         for (const auto id : blocks)
    8601          13 :           local_mesh_subs.erase(id);
    8602         224 :       }
    8603             : 
    8604             :       // also exclude mortar spaces from the material check
    8605       62544 :       auto && mortar_subdomain_ids = _mortar_data->getMortarSubdomainIDs();
    8606       64584 :       for (auto subdomain_id : mortar_subdomain_ids)
    8607        2040 :         local_mesh_subs.erase(subdomain_id);
    8608             : 
    8609             :       // Check Material Coverage
    8610       62544 :       if (check_material_coverage && !local_mesh_subs.empty())
    8611             :       {
    8612           8 :         std::stringstream extra_subdomain_ids;
    8613             :         /// unsigned int is necessary to print SubdomainIDs in the statement below
    8614           8 :         std::copy(local_mesh_subs.begin(),
    8615             :                   local_mesh_subs.end(),
    8616          16 :                   std::ostream_iterator<unsigned int>(extra_subdomain_ids, " "));
    8617             :         /// vector is necessary to get the subdomain names
    8618             :         std::vector<SubdomainID> local_mesh_subs_vec(local_mesh_subs.begin(),
    8619           8 :                                                      local_mesh_subs.end());
    8620             : 
    8621          24 :         mooseError("The following blocks from your input mesh do not contain an active material: " +
    8622          16 :                    extra_subdomain_ids.str() +
    8623          24 :                    "(names: " + Moose::stringify(_mesh.getSubdomainNames(local_mesh_subs_vec)) +
    8624             :                    ")\nWhen ANY mesh block contains a Material object, "
    8625             :                    "all blocks must contain a Material object.\n");
    8626           0 :       }
    8627       62536 :     }
    8628             : 
    8629             :     // Check material properties on blocks and boundaries
    8630       62628 :     checkBlockMatProps();
    8631       62586 :     checkBoundaryMatProps();
    8632             : 
    8633             :     // Check that material properties exist when requested by other properties on a given block
    8634       62574 :     const auto & materials = _all_materials.getActiveObjects();
    8635       77364 :     for (const auto & material : materials)
    8636       14790 :       material->checkStatefulSanity();
    8637             : 
    8638             :     // auto mats_to_check = _materials.getActiveBlockObjects();
    8639             :     // const auto & discrete_materials = _discrete_materials.getActiveBlockObjects();
    8640             :     // for (const auto & map_it : discrete_materials)
    8641             :     //   for (const auto & container_element : map_it.second)
    8642             :     //     mats_to_check[map_it.first].push_back(container_element);
    8643       62574 :     if (_material_dependency_check)
    8644       62548 :       checkDependMaterialsHelper(_all_materials.getActiveBlockObjects());
    8645       62558 :   }
    8646             : 
    8647       62558 :   checkUserObjects();
    8648             : 
    8649             :   // Verify that we don't have any Element type/Coordinate Type conflicts
    8650       62558 :   checkCoordinateSystems();
    8651             : 
    8652             :   // Coordinate transforms are only intended for use with MultiApps at this time. If you are not
    8653             :   // using multiapps but still require these, contact a moose developer
    8654       62709 :   if (_mesh.coordTransform().hasScalingOrRotationTransformation() && _app.isUltimateMaster() &&
    8655         155 :       !hasMultiApps())
    8656           4 :     mooseError("Coordinate transformation parameters, listed below, are only to be used in the "
    8657             :                "context of application to application field transfers at this time. The mesh is "
    8658             :                "not modified by these parameters within an application.\n"
    8659             :                "You should likely use a 'TransformGenerator' in the [Mesh] block to achieve the "
    8660             :                "desired mesh modification.\n\n",
    8661           4 :                Moose::stringify(MooseAppCoordTransform::validParams()));
    8662             : 
    8663             :   // If using displacements, verify that the order of the displacement
    8664             :   // variables matches the order of the elements in the displaced
    8665             :   // mesh.
    8666       62550 :   checkDisplacementOrders();
    8667             : 
    8668             :   // Check for postprocessor names with same name as a scalar variable
    8669       62546 :   checkDuplicatePostprocessorVariableNames();
    8670       62546 : }
    8671             : 
    8672             : void
    8673       62550 : FEProblemBase::checkDisplacementOrders()
    8674             : {
    8675       62550 :   if (_displaced_problem)
    8676             :   {
    8677        2246 :     bool mesh_has_second_order_elements = false;
    8678        4492 :     for (const auto & elem : as_range(_displaced_mesh->activeLocalElementsBegin(),
    8679      535056 :                                       _displaced_mesh->activeLocalElementsEnd()))
    8680             :     {
    8681      264537 :       if (elem->default_order() == SECOND)
    8682             :       {
    8683         378 :         mesh_has_second_order_elements = true;
    8684         378 :         break;
    8685             :       }
    8686        2246 :     }
    8687             : 
    8688             :     // We checked our local elements, so take the max over all processors.
    8689        2246 :     _displaced_mesh->comm().max(mesh_has_second_order_elements);
    8690             : 
    8691             :     // If the Mesh has second order elements, make sure the
    8692             :     // displacement variables are second-order.
    8693        2246 :     if (mesh_has_second_order_elements)
    8694             :     {
    8695             :       const std::vector<std::string> & displacement_variables =
    8696         378 :           _displaced_problem->getDisplacementVarNames();
    8697             : 
    8698        1242 :       for (const auto & var_name : displacement_variables)
    8699             :       {
    8700             :         MooseVariableFEBase & mv =
    8701         868 :             _displaced_problem->getVariable(/*tid=*/0,
    8702             :                                             var_name,
    8703             :                                             Moose::VarKindType::VAR_ANY,
    8704             :                                             Moose::VarFieldType::VAR_FIELD_STANDARD);
    8705         868 :         if (mv.order() != SECOND)
    8706           4 :           mooseError("Error: mesh has SECOND order elements, so all displacement variables must be "
    8707             :                      "SECOND order.");
    8708             :       }
    8709             :     }
    8710             :   }
    8711       62546 : }
    8712             : 
    8713             : void
    8714       62558 : FEProblemBase::checkUserObjects()
    8715             : {
    8716             :   // Check user_objects block coverage
    8717       62558 :   std::set<SubdomainID> mesh_subdomains = _mesh.meshSubdomains();
    8718       62558 :   std::set<SubdomainID> user_objects_blocks;
    8719             : 
    8720             :   // gather names of all user_objects that were defined in the input file
    8721             :   // and the blocks that they are defined on
    8722       62558 :   std::set<std::string> names;
    8723             : 
    8724       62558 :   std::vector<UserObject *> objects;
    8725       62558 :   theWarehouse().query().condition<AttribInterfaces>(Interfaces::UserObject).queryInto(objects);
    8726             : 
    8727      144439 :   for (const auto & obj : objects)
    8728       81881 :     names.insert(obj->name());
    8729             : 
    8730             :   // See if all referenced blocks are covered
    8731       62558 :   std::set<SubdomainID> difference;
    8732       62558 :   std::set_difference(user_objects_blocks.begin(),
    8733             :                       user_objects_blocks.end(),
    8734             :                       mesh_subdomains.begin(),
    8735             :                       mesh_subdomains.end(),
    8736             :                       std::inserter(difference, difference.end()));
    8737             : 
    8738       62558 :   if (!difference.empty())
    8739             :   {
    8740           0 :     std::ostringstream oss;
    8741           0 :     oss << "One or more UserObjects is referencing a nonexistent block:\n";
    8742           0 :     for (const auto & id : difference)
    8743           0 :       oss << id << "\n";
    8744           0 :     mooseError(oss.str());
    8745           0 :   }
    8746       62558 : }
    8747             : 
    8748             : void
    8749       62548 : FEProblemBase::checkDependMaterialsHelper(
    8750             :     const std::map<SubdomainID, std::vector<std::shared_ptr<MaterialBase>>> & materials_map)
    8751             : {
    8752       75689 :   for (const auto & it : materials_map)
    8753             :   {
    8754             :     /// These two sets are used to make sure that all dependent props on a block are actually supplied
    8755       13151 :     std::set<std::string> block_depend_props, block_supplied_props;
    8756             : 
    8757       32599 :     for (const auto & mat1 : it.second)
    8758             :     {
    8759       19448 :       auto & alldeps = mat1->getMatPropDependencies(); // includes requested stateful props
    8760       21900 :       for (auto & dep : alldeps)
    8761        2452 :         block_depend_props.insert(_material_prop_registry.getName(dep));
    8762             : 
    8763             :       // See if any of the active materials supply this property
    8764       60144 :       for (const auto & mat2 : it.second)
    8765             :       {
    8766       40696 :         const std::set<std::string> & supplied_props = mat2->MaterialBase::getSuppliedItems();
    8767       40696 :         block_supplied_props.insert(supplied_props.begin(), supplied_props.end());
    8768             :       }
    8769             :     }
    8770             : 
    8771             :     // Add zero material properties specific to this block and unrestricted
    8772       13151 :     block_supplied_props.insert(_zero_block_material_props[it.first].begin(),
    8773       13151 :                                 _zero_block_material_props[it.first].end());
    8774             : 
    8775             :     // Error check to make sure all properties consumed by materials are supplied on this block
    8776       13151 :     std::set<std::string> difference;
    8777       13151 :     std::set_difference(block_depend_props.begin(),
    8778             :                         block_depend_props.end(),
    8779             :                         block_supplied_props.begin(),
    8780             :                         block_supplied_props.end(),
    8781             :                         std::inserter(difference, difference.end()));
    8782             : 
    8783       13151 :     if (!difference.empty())
    8784             :     {
    8785          10 :       std::ostringstream oss;
    8786          10 :       oss << "One or more Material Properties were not supplied on block ";
    8787          10 :       const std::string & subdomain_name = _mesh.getSubdomainName(it.first);
    8788          10 :       if (subdomain_name.length() > 0)
    8789           0 :         oss << subdomain_name << " (" << it.first << ")";
    8790             :       else
    8791          10 :         oss << it.first;
    8792          10 :       oss << ":\n";
    8793          20 :       for (const auto & name : difference)
    8794          10 :         oss << name << "\n";
    8795          10 :       mooseError(oss.str());
    8796           0 :     }
    8797       13141 :   }
    8798             : 
    8799             :   // This loop checks that materials are not supplied by multiple Material objects
    8800       75673 :   for (const auto & it : materials_map)
    8801             :   {
    8802       13141 :     const auto & materials = it.second;
    8803       13141 :     std::set<std::string> inner_supplied, outer_supplied;
    8804             : 
    8805       32565 :     for (const auto & outer_mat : materials)
    8806             :     {
    8807             :       // Storage for properties for this material (outer) and all other materials (inner)
    8808       19430 :       outer_supplied = outer_mat->getSuppliedItems();
    8809       19430 :       inner_supplied.clear();
    8810             : 
    8811             :       // Property to material map for error reporting
    8812       19430 :       std::map<std::string, std::set<std::string>> prop_to_mat;
    8813       40782 :       for (const auto & name : outer_supplied)
    8814       21352 :         prop_to_mat[name].insert(outer_mat->name());
    8815             : 
    8816       60098 :       for (const auto & inner_mat : materials)
    8817             :       {
    8818       40668 :         if (outer_mat == inner_mat)
    8819       19430 :           continue;
    8820             : 
    8821             :         // Check whether these materials are an AD pair
    8822       21238 :         auto outer_mat_type = outer_mat->type();
    8823       21238 :         auto inner_mat_type = inner_mat->type();
    8824       42476 :         removeSubstring(outer_mat_type, "<RESIDUAL>");
    8825       42476 :         removeSubstring(outer_mat_type, "<JACOBIAN>");
    8826       42476 :         removeSubstring(inner_mat_type, "<RESIDUAL>");
    8827       21238 :         removeSubstring(inner_mat_type, "<JACOBIAN>");
    8828       21238 :         if (outer_mat_type == inner_mat_type && outer_mat_type != outer_mat->type() &&
    8829           0 :             inner_mat_type != inner_mat->type())
    8830           0 :           continue;
    8831             : 
    8832       21238 :         inner_supplied.insert(inner_mat->getSuppliedItems().begin(),
    8833       21238 :                               inner_mat->getSuppliedItems().end());
    8834             : 
    8835      124032 :         for (const auto & inner_supplied_name : inner_supplied)
    8836      102794 :           prop_to_mat[inner_supplied_name].insert(inner_mat->name());
    8837       21238 :       }
    8838             : 
    8839             :       // Test that a property isn't supplied on multiple blocks
    8840       19430 :       std::set<std::string> intersection;
    8841       19430 :       std::set_intersection(outer_supplied.begin(),
    8842             :                             outer_supplied.end(),
    8843             :                             inner_supplied.begin(),
    8844             :                             inner_supplied.end(),
    8845             :                             std::inserter(intersection, intersection.end()));
    8846             : 
    8847       19430 :       if (!intersection.empty())
    8848             :       {
    8849           6 :         std::ostringstream oss;
    8850           6 :         oss << "The following material properties are declared on block " << it.first
    8851           6 :             << " by multiple materials:\n";
    8852          12 :         oss << ConsoleUtils::indent(2) << std::setw(30) << std::left << "Material Property"
    8853           6 :             << "Material Objects\n";
    8854          24 :         for (const auto & outer_name : intersection)
    8855             :         {
    8856          18 :           oss << ConsoleUtils::indent(2) << std::setw(30) << std::left << outer_name;
    8857          54 :           for (const auto & inner_name : prop_to_mat[outer_name])
    8858          36 :             oss << inner_name << " ";
    8859          18 :           oss << '\n';
    8860             :         }
    8861             : 
    8862           6 :         mooseError(oss.str());
    8863             :         break;
    8864           0 :       }
    8865       19424 :     }
    8866       13135 :   }
    8867       62532 : }
    8868             : 
    8869             : void
    8870       62558 : FEProblemBase::checkCoordinateSystems()
    8871             : {
    8872       62558 :   _mesh.checkCoordinateSystems();
    8873       62554 : }
    8874             : 
    8875             : void
    8876         509 : FEProblemBase::setRestartFile(const std::string & file_name)
    8877             : {
    8878         509 :   if (_app.isRecovering())
    8879             :   {
    8880          23 :     mooseInfo("Restart file ", file_name, " is NOT being used since we are performing recovery.");
    8881             :   }
    8882             :   else
    8883             :   {
    8884         486 :     _app.setRestart(true);
    8885         486 :     _app.setRestartRecoverFileBase(file_name);
    8886         486 :     mooseInfo("Using ", file_name, " for restart.");
    8887             :   }
    8888         509 : }
    8889             : 
    8890             : std::vector<VariableName>
    8891      380791 : FEProblemBase::getVariableNames()
    8892             : {
    8893      380791 :   std::vector<VariableName> names;
    8894             : 
    8895      766090 :   for (auto & sys : _solver_systems)
    8896             :   {
    8897      385299 :     const std::vector<VariableName> & var_names = sys->getVariableNames();
    8898      385299 :     names.insert(names.end(), var_names.begin(), var_names.end());
    8899             :   }
    8900             : 
    8901      380791 :   const std::vector<VariableName> & aux_var_names = _aux->getVariableNames();
    8902      380791 :   names.insert(names.end(), aux_var_names.begin(), aux_var_names.end());
    8903             : 
    8904      380791 :   return names;
    8905           0 : }
    8906             : 
    8907             : SolverParams &
    8908     1705868 : FEProblemBase::solverParams(const unsigned int solver_sys_num)
    8909             : {
    8910             :   mooseAssert(solver_sys_num < numSolverSystems(),
    8911             :               "Solver system number '" << solver_sys_num << "' is out of bounds. We have '"
    8912             :                                        << numSolverSystems() << "' solver systems");
    8913     1705868 :   return _solver_params[solver_sys_num];
    8914             : }
    8915             : 
    8916             : const SolverParams &
    8917       12911 : FEProblemBase::solverParams(const unsigned int solver_sys_num) const
    8918             : {
    8919       12911 :   return const_cast<FEProblemBase *>(this)->solverParams(solver_sys_num);
    8920             : }
    8921             : 
    8922             : void
    8923         456 : FEProblemBase::registerRandomInterface(RandomInterface & random_interface, const std::string & name)
    8924             : {
    8925         456 :   auto insert_pair = moose_try_emplace(
    8926         456 :       _random_data_objects, name, std::make_unique<RandomData>(*this, random_interface));
    8927             : 
    8928         456 :   auto random_data_ptr = insert_pair.first->second.get();
    8929         456 :   random_interface.setRandomDataPointer(random_data_ptr);
    8930         456 : }
    8931             : 
    8932             : bool
    8933     1917205 : FEProblemBase::needBoundaryMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
    8934             : {
    8935     1917205 :   if (_bnd_mat_side_cache[tid].find(bnd_id) == _bnd_mat_side_cache[tid].end())
    8936             :   {
    8937       31243 :     auto & bnd_mat_side_cache = _bnd_mat_side_cache[tid][bnd_id];
    8938       31243 :     bnd_mat_side_cache = false;
    8939             : 
    8940             :     // Check systems
    8941       31243 :     if (_aux->needMaterialOnSide(bnd_id))
    8942             :     {
    8943         578 :       bnd_mat_side_cache = true;
    8944         578 :       return true;
    8945             :     }
    8946       58204 :     for (auto & nl : _nl)
    8947       30339 :       if (nl->needBoundaryMaterialOnSide(bnd_id, tid))
    8948             :       {
    8949        2800 :         bnd_mat_side_cache = true;
    8950        2800 :         return true;
    8951             :       }
    8952             : 
    8953             :     // TODO: these objects should be checked for whether they actually consume materials
    8954             :     // NOTE: InterfaceUO can use use boundary properties too
    8955       27865 :     if (theWarehouse()
    8956       55730 :             .query()
    8957       27865 :             .condition<AttribThread>(tid)
    8958       27865 :             .condition<AttribInterfaces>(Interfaces::SideUserObject | Interfaces::DomainUserObject |
    8959             :                                          Interfaces::InterfaceUserObject)
    8960       27865 :             .condition<AttribBoundaries>(bnd_id)
    8961       27865 :             .count() > 0)
    8962             :     {
    8963         634 :       bnd_mat_side_cache = true;
    8964         634 :       return true;
    8965             :     }
    8966             :   }
    8967             : 
    8968     1913193 :   return _bnd_mat_side_cache[tid][bnd_id];
    8969             : }
    8970             : 
    8971             : bool
    8972      458582 : FEProblemBase::needInterfaceMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
    8973             : {
    8974      458582 :   if (_interface_mat_side_cache[tid].find(bnd_id) == _interface_mat_side_cache[tid].end())
    8975             :   {
    8976        3238 :     auto & interface_mat_side_cache = _interface_mat_side_cache[tid][bnd_id];
    8977        3238 :     interface_mat_side_cache = false;
    8978             : 
    8979             :     // Aux-system has not needed interface materials so far
    8980        6206 :     for (auto & nl : _nl)
    8981        3238 :       if (nl->needInterfaceMaterialOnSide(bnd_id, tid))
    8982             :       {
    8983         270 :         interface_mat_side_cache = true;
    8984         270 :         return true;
    8985             :       }
    8986             : 
    8987             :     // TODO: these objects should be checked for whether they actually consume materials
    8988        2968 :     if (theWarehouse()
    8989        5936 :             .query()
    8990        2968 :             .condition<AttribThread>(tid)
    8991        2968 :             .condition<AttribInterfaces>(Interfaces::InterfaceUserObject |
    8992             :                                          Interfaces::DomainUserObject)
    8993        2968 :             .condition<AttribBoundaries>(bnd_id)
    8994        2968 :             .count() > 0)
    8995             :     {
    8996          90 :       interface_mat_side_cache = true;
    8997          90 :       return true;
    8998             :     }
    8999        2878 :     else if (_interface_materials.hasActiveBoundaryObjects(bnd_id, tid))
    9000             :     {
    9001          11 :       interface_mat_side_cache = true;
    9002          11 :       return true;
    9003             :     }
    9004             :   }
    9005      458211 :   return _interface_mat_side_cache[tid][bnd_id];
    9006             : }
    9007             : 
    9008             : bool
    9009      446428 : FEProblemBase::needInternalNeighborSideMaterial(SubdomainID subdomain_id, const THREAD_ID tid)
    9010             : {
    9011      446428 :   if (_block_mat_side_cache[tid].find(subdomain_id) == _block_mat_side_cache[tid].end())
    9012             :   {
    9013       13461 :     _block_mat_side_cache[tid][subdomain_id] = false;
    9014             : 
    9015       26344 :     for (auto & nl : _nl)
    9016       13378 :       if (nl->needInternalNeighborSideMaterial(subdomain_id, tid))
    9017             :       {
    9018         495 :         _block_mat_side_cache[tid][subdomain_id] = true;
    9019         495 :         return true;
    9020             :       }
    9021             : 
    9022             :     // TODO: these objects should be checked for whether they actually consume materials
    9023       12966 :     if (theWarehouse()
    9024       25932 :             .query()
    9025       12966 :             .condition<AttribThread>(tid)
    9026       12966 :             .condition<AttribInterfaces>(Interfaces::InternalSideUserObject |
    9027             :                                          Interfaces::DomainUserObject)
    9028       12966 :             .condition<AttribSubdomains>(subdomain_id)
    9029       12966 :             .count() > 0)
    9030             :     {
    9031          38 :       _block_mat_side_cache[tid][subdomain_id] = true;
    9032          38 :       return true;
    9033             :     }
    9034             :   }
    9035             : 
    9036      445895 :   return _block_mat_side_cache[tid][subdomain_id];
    9037             : }
    9038             : 
    9039             : bool
    9040      316256 : FEProblemBase::needsPreviousNewtonIteration() const
    9041             : {
    9042      316256 :   return vectorTagExists(Moose::PREVIOUS_NL_SOLUTION_TAG);
    9043             : }
    9044             : 
    9045             : void
    9046          82 : FEProblemBase::needsPreviousNewtonIteration(bool state)
    9047             : {
    9048          82 :   if (state && !vectorTagExists(Moose::PREVIOUS_NL_SOLUTION_TAG))
    9049           0 :     mooseError("Previous nonlinear solution is required but not added through "
    9050             :                "Problem/previous_nl_solution_required=true");
    9051          82 : }
    9052             : 
    9053             : bool
    9054     8536346 : FEProblemBase::hasJacobian() const
    9055             : {
    9056     8536346 :   return _has_jacobian;
    9057             : }
    9058             : 
    9059             : bool
    9060     7990258 : FEProblemBase::constJacobian() const
    9061             : {
    9062     7990258 :   return _const_jacobian;
    9063             : }
    9064             : 
    9065             : void
    9066      297976 : FEProblemBase::addOutput(const std::string & object_type,
    9067             :                          const std::string & object_name,
    9068             :                          InputParameters & parameters)
    9069             : {
    9070             :   parallel_object_only();
    9071             : 
    9072             :   // Get a reference to the OutputWarehouse
    9073      297976 :   OutputWarehouse & output_warehouse = _app.getOutputWarehouse();
    9074             : 
    9075             :   // Reject the reserved names for objects not built by MOOSE
    9076      297976 :   if (!parameters.get<bool>("_built_by_moose") && output_warehouse.isReservedName(object_name))
    9077           8 :     mooseError("The name '", object_name, "' is a reserved name for output objects");
    9078             : 
    9079             :   // Check that an object by the same name does not already exist; this must be done before the
    9080             :   // object is created to avoid getting misleading errors from the Parser
    9081      297968 :   if (output_warehouse.hasOutput(object_name))
    9082           4 :     mooseError("An output object named '", object_name, "' already exists");
    9083             : 
    9084             :   // Add a pointer to the FEProblemBase class
    9085      595928 :   parameters.addPrivateParam<FEProblemBase *>("_fe_problem_base", this);
    9086             : 
    9087             :   // Create common parameter exclude list
    9088      297964 :   std::vector<std::string> exclude;
    9089      297964 :   if (object_type == "Console")
    9090             :   {
    9091       63357 :     exclude.push_back("execute_on");
    9092             : 
    9093             :     // --show-input should enable the display of the input file on the screen
    9094      190071 :     if (_app.getParam<bool>("show_input") && parameters.get<bool>("output_screen"))
    9095          60 :       parameters.set<ExecFlagEnum>("execute_input_on") = EXEC_INITIAL;
    9096             :   }
    9097             :   // Need this because Checkpoint::validParams changes the default value of
    9098             :   // execute_on
    9099      234607 :   else if (object_type == "Checkpoint")
    9100      101982 :     exclude.push_back("execute_on");
    9101             : 
    9102             :   // Apply the common parameters loaded with Outputs input syntax
    9103      297964 :   const InputParameters * common = output_warehouse.getCommonParameters();
    9104      297964 :   if (common)
    9105      297964 :     parameters.applyParameters(*common, exclude);
    9106      297964 :   if (common && std::find(exclude.begin(), exclude.end(), "execute_on") != exclude.end() &&
    9107      824624 :       common->isParamSetByUser("execute_on") && object_type != "Console")
    9108        7082 :     mooseInfoRepeated(
    9109       14164 :         "'execute_on' parameter specified in [Outputs] block is ignored for object '" +
    9110       21246 :         object_name +
    9111             :         "'.\nDefine this object in its own sub-block of [Outputs] to modify its "
    9112             :         "execution schedule.");
    9113             : 
    9114             :   // Set the correct value for the binary flag for XDA/XDR output
    9115      297964 :   if (object_type == "XDR")
    9116         130 :     parameters.set<bool>("_binary") = true;
    9117      297899 :   else if (object_type == "XDA")
    9118         242 :     parameters.set<bool>("_binary") = false;
    9119             : 
    9120             :   // Adjust the checkpoint suffix if auto recovery was enabled
    9121      297964 :   if (object_name == "auto_recovery_checkpoint")
    9122           0 :     parameters.set<std::string>("suffix") = "auto_recovery";
    9123             : 
    9124             :   // Create the object and add it to the warehouse
    9125      297964 :   std::shared_ptr<Output> output = _factory.create<Output>(object_type, object_name, parameters);
    9126      297948 :   logAdd("Output", object_name, object_type, parameters);
    9127      297948 :   output_warehouse.addOutput(output);
    9128      297948 : }
    9129             : 
    9130             : void
    9131       28343 : FEProblemBase::haveADObjects(const bool have_ad_objects)
    9132             : {
    9133       28343 :   _have_ad_objects = have_ad_objects;
    9134       28343 :   if (_displaced_problem)
    9135         247 :     _displaced_problem->SubProblem::haveADObjects(have_ad_objects);
    9136       28343 : }
    9137             : 
    9138             : const SystemBase &
    9139           0 : FEProblemBase::getSystemBase(const unsigned int sys_num) const
    9140             : {
    9141           0 :   if (sys_num < _solver_systems.size())
    9142           0 :     return *_solver_systems[sys_num];
    9143             : 
    9144           0 :   return *_aux;
    9145             : }
    9146             : 
    9147             : SystemBase &
    9148         921 : FEProblemBase::getSystemBase(const std::string & sys_name)
    9149             : {
    9150         921 :   if (std::find(_solver_sys_names.begin(), _solver_sys_names.end(), sys_name) !=
    9151        1842 :       _solver_sys_names.end())
    9152         921 :     return getSystemBase(solverSysNum(sys_name));
    9153           0 :   else if (sys_name == "aux0")
    9154           0 :     return *_aux;
    9155             :   else
    9156           0 :     mooseError("System '" + sys_name + "' was requested from problem but does not exist.");
    9157             : }
    9158             : 
    9159             : SystemBase &
    9160        2562 : FEProblemBase::getSystemBase(const unsigned int sys_num)
    9161             : {
    9162        2562 :   if (sys_num < _solver_systems.size())
    9163        2451 :     return *_solver_systems[sys_num];
    9164             : 
    9165         111 :   return *_aux;
    9166             : }
    9167             : 
    9168             : const SystemBase &
    9169       14623 : FEProblemBase::systemBaseNonlinear(const unsigned int sys_num) const
    9170             : {
    9171             :   mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
    9172       14623 :   return *_nl[sys_num];
    9173             : }
    9174             : 
    9175             : SystemBase &
    9176     1396214 : FEProblemBase::systemBaseNonlinear(const unsigned int sys_num)
    9177             : {
    9178             :   mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
    9179     1396214 :   return *_nl[sys_num];
    9180             : }
    9181             : 
    9182             : const SystemBase &
    9183           0 : FEProblemBase::systemBaseLinear(const unsigned int sys_num) const
    9184             : {
    9185             :   mooseAssert(sys_num < _linear_systems.size(),
    9186             :               "System number greater than the number of linear systems");
    9187           0 :   return *_linear_systems[sys_num];
    9188             : }
    9189             : 
    9190             : SystemBase &
    9191           0 : FEProblemBase::systemBaseLinear(const unsigned int sys_num)
    9192             : {
    9193             :   mooseAssert(sys_num < _linear_systems.size(),
    9194             :               "System number greater than the number of linear systems");
    9195           0 :   return *_linear_systems[sys_num];
    9196             : }
    9197             : 
    9198             : const SystemBase &
    9199           0 : FEProblemBase::systemBaseSolver(const unsigned int sys_num) const
    9200             : {
    9201             :   mooseAssert(sys_num < _solver_systems.size(),
    9202             :               "System number greater than the number of solver systems");
    9203           0 :   return *_solver_systems[sys_num];
    9204             : }
    9205             : 
    9206             : SystemBase &
    9207     7402004 : FEProblemBase::systemBaseSolver(const unsigned int sys_num)
    9208             : {
    9209             :   mooseAssert(sys_num < _solver_systems.size(),
    9210             :               "System number greater than the number of solver systems");
    9211     7402004 :   return *_solver_systems[sys_num];
    9212             : }
    9213             : 
    9214             : const SystemBase &
    9215          18 : FEProblemBase::systemBaseAuxiliary() const
    9216             : {
    9217          18 :   return *_aux;
    9218             : }
    9219             : 
    9220             : SystemBase &
    9221     9411238 : FEProblemBase::systemBaseAuxiliary()
    9222             : {
    9223     9411238 :   return *_aux;
    9224             : }
    9225             : 
    9226             : void
    9227     4327131 : FEProblemBase::computingNonlinearResid(bool computing_nonlinear_residual)
    9228             : {
    9229             :   parallel_object_only();
    9230             : 
    9231     4327131 :   if (_displaced_problem)
    9232      212324 :     _displaced_problem->computingNonlinearResid(computing_nonlinear_residual);
    9233     4327131 :   _computing_nonlinear_residual = computing_nonlinear_residual;
    9234     4327131 : }
    9235             : 
    9236             : void
    9237    10560856 : FEProblemBase::setCurrentlyComputingResidual(bool currently_computing_residual)
    9238             : {
    9239    10560856 :   if (_displaced_problem)
    9240      433724 :     _displaced_problem->setCurrentlyComputingResidual(currently_computing_residual);
    9241    10560856 :   _currently_computing_residual = currently_computing_residual;
    9242    10560856 : }
    9243             : 
    9244             : void
    9245          57 : FEProblemBase::uniformRefine()
    9246             : {
    9247             :   // ResetDisplacedMeshThread::onNode looks up the reference mesh by ID, so we need to make sure
    9248             :   // we undisplace before adapting the reference mesh
    9249          57 :   if (_displaced_problem)
    9250          37 :     _displaced_problem->undisplaceMesh();
    9251             : 
    9252          57 :   Adaptivity::uniformRefine(&_mesh, 1);
    9253          57 :   if (_displaced_problem)
    9254          37 :     Adaptivity::uniformRefine(&_displaced_problem->mesh(), 1);
    9255             : 
    9256          57 :   meshChanged(
    9257             :       /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
    9258          57 : }
    9259             : 
    9260             : void
    9261       63876 : FEProblemBase::automaticScaling(bool automatic_scaling)
    9262             : {
    9263       63876 :   if (_displaced_problem)
    9264        2246 :     _displaced_problem->automaticScaling(automatic_scaling);
    9265             : 
    9266       63876 :   SubProblem::automaticScaling(automatic_scaling);
    9267       63876 : }
    9268             : 
    9269             : void
    9270      284429 : FEProblemBase::reinitElemFaceRef(const Elem * elem,
    9271             :                                  unsigned int side,
    9272             :                                  Real tolerance,
    9273             :                                  const std::vector<Point> * const pts,
    9274             :                                  const std::vector<Real> * const weights,
    9275             :                                  const THREAD_ID tid)
    9276             : {
    9277      284429 :   SubProblem::reinitElemFaceRef(elem, side, tolerance, pts, weights, tid);
    9278             : 
    9279      284429 :   if (_displaced_problem)
    9280       22778 :     _displaced_problem->reinitElemFaceRef(
    9281       22778 :         _displaced_mesh->elemPtr(elem->id()), side, tolerance, pts, weights, tid);
    9282      284429 : }
    9283             : 
    9284             : void
    9285      284429 : FEProblemBase::reinitNeighborFaceRef(const Elem * neighbor_elem,
    9286             :                                      unsigned int neighbor_side,
    9287             :                                      Real tolerance,
    9288             :                                      const std::vector<Point> * const pts,
    9289             :                                      const std::vector<Real> * const weights,
    9290             :                                      const THREAD_ID tid)
    9291             : {
    9292      284429 :   SubProblem::reinitNeighborFaceRef(neighbor_elem, neighbor_side, tolerance, pts, weights, tid);
    9293             : 
    9294      284429 :   if (_displaced_problem)
    9295       22778 :     _displaced_problem->reinitNeighborFaceRef(
    9296       22778 :         _displaced_mesh->elemPtr(neighbor_elem->id()), neighbor_side, tolerance, pts, weights, tid);
    9297      284429 : }
    9298             : 
    9299             : void
    9300     3857812 : FEProblemBase::getFVMatsAndDependencies(
    9301             :     const SubdomainID blk_id,
    9302             :     std::vector<std::shared_ptr<MaterialBase>> & face_materials,
    9303             :     std::vector<std::shared_ptr<MaterialBase>> & neighbor_materials,
    9304             :     std::set<MooseVariableFieldBase *> & variables,
    9305             :     const THREAD_ID tid)
    9306             : {
    9307     3857812 :   if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    9308             :   {
    9309             :     auto & this_face_mats =
    9310        3996 :         _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid);
    9311        8196 :     for (std::shared_ptr<MaterialBase> face_mat : this_face_mats)
    9312        4200 :       if (face_mat->ghostable())
    9313             :       {
    9314        4200 :         face_materials.push_back(face_mat);
    9315        4200 :         auto & var_deps = face_mat->getMooseVariableDependencies();
    9316        4608 :         for (auto * var : var_deps)
    9317             :         {
    9318         408 :           if (!var->isFV())
    9319           0 :             mooseError(
    9320             :                 "Ghostable materials should only have finite volume variables coupled into them.");
    9321         408 :           else if (face_mat->hasStatefulProperties())
    9322           0 :             mooseError("Finite volume materials do not currently support stateful properties.");
    9323         408 :           variables.insert(var);
    9324             :         }
    9325        4200 :       }
    9326             :   }
    9327             : 
    9328     3857812 :   if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
    9329             :   {
    9330             :     auto & this_neighbor_mats =
    9331        3996 :         _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid);
    9332        8196 :     for (std::shared_ptr<MaterialBase> neighbor_mat : this_neighbor_mats)
    9333        4200 :       if (neighbor_mat->ghostable())
    9334             :       {
    9335        4200 :         neighbor_materials.push_back(neighbor_mat);
    9336             : #ifndef NDEBUG
    9337             :         auto & var_deps = neighbor_mat->getMooseVariableDependencies();
    9338             :         for (auto * var : var_deps)
    9339             :         {
    9340             :           if (!var->isFV())
    9341             :             mooseError(
    9342             :                 "Ghostable materials should only have finite volume variables coupled into them.");
    9343             :           else if (neighbor_mat->hasStatefulProperties())
    9344             :             mooseError("Finite volume materials do not currently support stateful properties.");
    9345             :           auto pr = variables.insert(var);
    9346             :           mooseAssert(!pr.second,
    9347             :                       "We should not have inserted any new variables dependencies from our "
    9348             :                       "neighbor materials that didn't exist for our face materials");
    9349             :         }
    9350             : #endif
    9351        4200 :       }
    9352             :   }
    9353     3857812 : }
    9354             : 
    9355             : void
    9356    48898539 : FEProblemBase::resizeMaterialData(const Moose::MaterialDataType data_type,
    9357             :                                   const unsigned int nqp,
    9358             :                                   const THREAD_ID tid)
    9359             : {
    9360    48898539 :   getMaterialData(data_type, tid).resize(nqp);
    9361    48898539 : }
    9362             : 
    9363             : void
    9364       63796 : FEProblemBase::setNonlinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names)
    9365             : {
    9366       63796 :   if (convergence_names.size() != numNonlinearSystems())
    9367           0 :     paramError("nonlinear_convergence",
    9368             :                "There must be one convergence object per nonlinear system");
    9369       63796 :   _nonlinear_convergence_names = convergence_names;
    9370       63796 : }
    9371             : 
    9372             : void
    9373       64135 : FEProblemBase::setMultiAppFixedPointConvergenceName(const ConvergenceName & convergence_name)
    9374             : {
    9375       64135 :   _multiapp_fixed_point_convergence_name = convergence_name;
    9376       64135 : }
    9377             : 
    9378             : void
    9379       31936 : FEProblemBase::setSteadyStateConvergenceName(const ConvergenceName & convergence_name)
    9380             : {
    9381       31936 :   _steady_state_convergence_name = convergence_name;
    9382       31936 : }
    9383             : 
    9384             : const std::vector<ConvergenceName> &
    9385     1078524 : FEProblemBase::getNonlinearConvergenceNames() const
    9386             : {
    9387     1078524 :   if (_nonlinear_convergence_names)
    9388     1078524 :     return *_nonlinear_convergence_names;
    9389           0 :   mooseError("The nonlinear system convergence name(s) have not been set.");
    9390             : }
    9391             : 
    9392             : bool
    9393        6097 : FEProblemBase::hasLinearConvergenceObjects() const
    9394             : {
    9395             :   // If false,this means we have not set one, not that we are querying this too early
    9396             :   // TODO: once there is a default linear CV object, error on the 'not set' case
    9397        6097 :   return _linear_convergence_names.has_value();
    9398             : }
    9399             : 
    9400             : void
    9401         181 : FEProblemBase::setLinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names)
    9402             : {
    9403         181 :   if (convergence_names.size() != numLinearSystems())
    9404           0 :     paramError("linear_convergence", "There must be one convergence object per linear system");
    9405         181 :   _linear_convergence_names = convergence_names;
    9406         181 : }
    9407             : 
    9408             : const std::vector<ConvergenceName> &
    9409        2634 : FEProblemBase::getLinearConvergenceNames() const
    9410             : {
    9411        2634 :   if (_linear_convergence_names)
    9412        2634 :     return *_linear_convergence_names;
    9413           0 :   mooseError("The linear convergence name(s) have not been set.");
    9414             : }
    9415             : 
    9416             : const ConvergenceName &
    9417      264889 : FEProblemBase::getMultiAppFixedPointConvergenceName() const
    9418             : {
    9419      264889 :   if (_multiapp_fixed_point_convergence_name)
    9420      264889 :     return _multiapp_fixed_point_convergence_name.value();
    9421             :   else
    9422           0 :     mooseError("The fixed point convergence name has not been set.");
    9423             : }
    9424             : 
    9425             : const ConvergenceName &
    9426      108850 : FEProblemBase::getSteadyStateConvergenceName() const
    9427             : {
    9428      108850 :   if (_steady_state_convergence_name)
    9429      108850 :     return _steady_state_convergence_name.value();
    9430             :   else
    9431           0 :     mooseError("The steady convergence name has not been set.");
    9432             : }
    9433             : 
    9434             : void
    9435     3343164 : FEProblemBase::residualSetup()
    9436             : {
    9437     3343164 :   SubProblem::residualSetup();
    9438             :   // We need to setup all the nonlinear systems other than our current one which actually called
    9439             :   // this method (so we have to make sure we don't go in a circle)
    9440     6778868 :   for (const auto i : make_range(numNonlinearSystems()))
    9441     3435704 :     if (i != currentNlSysNum())
    9442       92540 :       _nl[i]->residualSetup();
    9443             :   // We don't setup the aux sys because that's been done elsewhere
    9444     3343164 :   if (_displaced_problem)
    9445      137184 :     _displaced_problem->residualSetup();
    9446     3343164 : }
    9447             : 
    9448             : void
    9449      527963 : FEProblemBase::jacobianSetup()
    9450             : {
    9451      527963 :   SubProblem::jacobianSetup();
    9452             :   // We need to setup all the nonlinear systems other than our current one which actually called
    9453             :   // this method (so we have to make sure we don't go in a circle)
    9454     1071986 :   for (const auto i : make_range(numNonlinearSystems()))
    9455      544023 :     if (i != currentNlSysNum())
    9456       16060 :       _nl[i]->jacobianSetup();
    9457             :   // We don't setup the aux sys because that's been done elsewhere
    9458      527963 :   if (_displaced_problem)
    9459       23344 :     _displaced_problem->jacobianSetup();
    9460      527963 : }
    9461             : 
    9462             : MooseAppCoordTransform &
    9463      104848 : FEProblemBase::coordTransform()
    9464             : {
    9465      104848 :   return mesh().coordTransform();
    9466             : }
    9467             : 
    9468             : unsigned int
    9469   594840285 : FEProblemBase::currentNlSysNum() const
    9470             : {
    9471             :   // If we don't have nonlinear systems this should be an invalid number
    9472   594840285 :   unsigned int current_nl_sys_num = libMesh::invalid_uint;
    9473   594840285 :   if (_nl.size())
    9474   594836189 :     current_nl_sys_num = currentNonlinearSystem().number();
    9475             : 
    9476   594840285 :   return current_nl_sys_num;
    9477             : }
    9478             : 
    9479             : unsigned int
    9480           0 : FEProblemBase::currentLinearSysNum() const
    9481             : {
    9482             :   // If we don't have linear systems this should be an invalid number
    9483           0 :   unsigned int current_linear_sys_num = libMesh::invalid_uint;
    9484           0 :   if (_linear_systems.size())
    9485           0 :     current_linear_sys_num = currentLinearSystem().number();
    9486             : 
    9487           0 :   return current_linear_sys_num;
    9488             : }
    9489             : 
    9490             : bool
    9491   139536024 : FEProblemBase::shouldPrintExecution(const THREAD_ID tid) const
    9492             : {
    9493             :   // For now, only support printing from thread 0
    9494   139536024 :   if (tid != 0)
    9495     8146116 :     return false;
    9496             : 
    9497   262492554 :   if (_print_execution_on.isValueSet(_current_execute_on_flag) ||
    9498   131102646 :       _print_execution_on.isValueSet(EXEC_ALWAYS))
    9499      376597 :     return true;
    9500             :   else
    9501   131013311 :     return false;
    9502             : }
    9503             : 
    9504             : std::vector<MortarUserObject *>
    9505      283097 : FEProblemBase::getMortarUserObjects(const BoundaryID primary_boundary_id,
    9506             :                                     const BoundaryID secondary_boundary_id,
    9507             :                                     const bool displaced,
    9508             :                                     const std::vector<MortarUserObject *> & mortar_uo_superset)
    9509             : {
    9510      283097 :   std::vector<MortarUserObject *> mortar_uos;
    9511      283097 :   auto * const subproblem = displaced ? static_cast<SubProblem *>(_displaced_problem.get())
    9512      283097 :                                       : static_cast<SubProblem *>(this);
    9513      283121 :   for (auto * const obj : mortar_uo_superset)
    9514          48 :     if (obj->onInterface(primary_boundary_id, secondary_boundary_id) &&
    9515          24 :         (&obj->getSubProblem() == subproblem))
    9516          24 :       mortar_uos.push_back(obj);
    9517             : 
    9518      283097 :   return mortar_uos;
    9519           0 : }
    9520             : 
    9521             : std::vector<MortarUserObject *>
    9522      283073 : FEProblemBase::getMortarUserObjects(const BoundaryID primary_boundary_id,
    9523             :                                     const BoundaryID secondary_boundary_id,
    9524             :                                     const bool displaced)
    9525             : {
    9526      283073 :   std::vector<MortarUserObject *> mortar_uos;
    9527      283073 :   theWarehouse()
    9528      283073 :       .query()
    9529      566146 :       .condition<AttribInterfaces>(Interfaces::MortarUserObject)
    9530      283073 :       .queryInto(mortar_uos);
    9531      566146 :   return getMortarUserObjects(primary_boundary_id, secondary_boundary_id, displaced, mortar_uos);
    9532      283073 : }
    9533             : 
    9534             : void
    9535      283073 : FEProblemBase::reinitMortarUserObjects(const BoundaryID primary_boundary_id,
    9536             :                                        const BoundaryID secondary_boundary_id,
    9537             :                                        const bool displaced)
    9538             : {
    9539             :   const auto mortar_uos =
    9540      283073 :       getMortarUserObjects(primary_boundary_id, secondary_boundary_id, displaced);
    9541      283073 :   for (auto * const mortar_uo : mortar_uos)
    9542             :   {
    9543           0 :     mortar_uo->setNormals();
    9544           0 :     mortar_uo->reinit();
    9545             :   }
    9546      283073 : }
    9547             : 
    9548             : void
    9549        1154 : FEProblemBase::setVerboseProblem(bool verbose)
    9550             : {
    9551        1154 :   _verbose_setup = verbose ? "true" : "false";
    9552        1154 :   _verbose_multiapps = verbose;
    9553        1154 :   _verbose_restore = verbose;
    9554        1154 : }
    9555             : 
    9556             : void
    9557      126057 : FEProblemBase::setCurrentLowerDElem(const Elem * const lower_d_elem, const THREAD_ID tid)
    9558             : {
    9559      126057 :   SubProblem::setCurrentLowerDElem(lower_d_elem, tid);
    9560      126057 :   if (_displaced_problem)
    9561       31448 :     _displaced_problem->setCurrentLowerDElem(
    9562           0 :         lower_d_elem ? _displaced_mesh->elemPtr(lower_d_elem->id()) : nullptr, tid);
    9563      126057 : }
    9564             : 
    9565             : void
    9566   135878139 : FEProblemBase::setCurrentBoundaryID(BoundaryID bid, const THREAD_ID tid)
    9567             : {
    9568   135878139 :   SubProblem::setCurrentBoundaryID(bid, tid);
    9569   135878139 :   if (_displaced_problem)
    9570    10148584 :     _displaced_problem->setCurrentBoundaryID(bid, tid);
    9571   135878139 : }
    9572             : 
    9573             : void
    9574     8140229 : FEProblemBase::setCurrentNonlinearSystem(const unsigned int nl_sys_num)
    9575             : {
    9576             :   mooseAssert(nl_sys_num < _nl.size(),
    9577             :               "System number greater than the number of nonlinear systems");
    9578     8140229 :   _current_nl_sys = _nl[nl_sys_num].get();
    9579     8140229 :   _current_solver_sys = _current_nl_sys;
    9580     8140229 : }
    9581             : 
    9582             : void
    9583       17124 : FEProblemBase::setCurrentLinearSystem(const unsigned int sys_num)
    9584             : {
    9585             :   mooseAssert(sys_num < _linear_systems.size(),
    9586             :               "System number greater than the number of linear systems");
    9587       17124 :   _current_linear_sys = _linear_systems[sys_num].get();
    9588       17124 :   _current_solver_sys = _current_linear_sys;
    9589       17124 : }
    9590             : 
    9591             : void
    9592     6358715 : FEProblemBase::computeSystems(const ExecFlagType & type)
    9593             : {
    9594             :   // When performing an adjoint solve in the optimization module, the current solver system is the
    9595             :   // adjoint. However, the adjoint solve requires having accurate time derivative calculations for
    9596             :   // the forward system. The cleanest way to handle such uses is just to compute the time
    9597             :   // derivatives for all solver systems instead of trying to guess which ones we need and don't need
    9598    12873199 :   for (auto & solver_sys : _solver_systems)
    9599     6514484 :     solver_sys->compute(type);
    9600             : 
    9601     6358715 :   _aux->compute(type);
    9602     6358670 : }
    9603             : 
    9604             : const ConstElemRange &
    9605     3872931 : FEProblemBase::getCurrentAlgebraicElementRange()
    9606             : {
    9607     3872931 :   if (!_current_algebraic_elem_range)
    9608     3872931 :     return *_mesh.getActiveLocalElementRange();
    9609             : 
    9610           0 :   return *_current_algebraic_elem_range;
    9611             : }
    9612             : const ConstNodeRange &
    9613       20503 : FEProblemBase::getCurrentAlgebraicNodeRange()
    9614             : {
    9615       20503 :   if (!_current_algebraic_node_range)
    9616       20503 :     return *_mesh.getLocalNodeRange();
    9617             : 
    9618           0 :   return *_current_algebraic_node_range;
    9619             : }
    9620             : const ConstBndNodeRange &
    9621     3643041 : FEProblemBase::getCurrentAlgebraicBndNodeRange()
    9622             : {
    9623     3643041 :   if (!_current_algebraic_bnd_node_range)
    9624     3643041 :     return *_mesh.getBoundaryNodeRange();
    9625             : 
    9626           0 :   return *_current_algebraic_bnd_node_range;
    9627             : }
    9628             : 
    9629             : void
    9630           0 : FEProblemBase::setCurrentAlgebraicElementRange(ConstElemRange * range)
    9631             : {
    9632           0 :   if (!range)
    9633             :   {
    9634           0 :     _current_algebraic_elem_range = nullptr;
    9635           0 :     return;
    9636             :   }
    9637             : 
    9638           0 :   _current_algebraic_elem_range = std::make_unique<ConstElemRange>(*range);
    9639             : }
    9640             : void
    9641           0 : FEProblemBase::setCurrentAlgebraicNodeRange(ConstNodeRange * range)
    9642             : {
    9643           0 :   if (!range)
    9644             :   {
    9645           0 :     _current_algebraic_node_range = nullptr;
    9646           0 :     return;
    9647             :   }
    9648             : 
    9649           0 :   _current_algebraic_node_range = std::make_unique<ConstNodeRange>(*range);
    9650             : }
    9651             : void
    9652           0 : FEProblemBase::setCurrentAlgebraicBndNodeRange(ConstBndNodeRange * range)
    9653             : {
    9654           0 :   if (!range)
    9655             :   {
    9656           0 :     _current_algebraic_bnd_node_range = nullptr;
    9657           0 :     return;
    9658             :   }
    9659             : 
    9660           0 :   _current_algebraic_bnd_node_range = std::make_unique<ConstBndNodeRange>(*range);
    9661             : }
    9662             : 
    9663             : unsigned short
    9664       65957 : FEProblemBase::getCurrentICState()
    9665             : {
    9666       65957 :   return _current_ic_state;
    9667             : }
    9668             : 
    9669             : std::string
    9670       56104 : FEProblemBase::solverTypeString(const unsigned int solver_sys_num)
    9671             : {
    9672       56104 :   return Moose::stringify(solverParams(solver_sys_num)._type);
    9673             : }
    9674             : 
    9675             : SolverParams
    9676        1340 : FEProblemBase::makeLinearSolverParams()
    9677             : {
    9678        1340 :   SolverParams solver_params;
    9679        1340 :   solver_params._type = Moose::SolveType::ST_LINEAR;
    9680        1340 :   solver_params._line_search = Moose::LineSearchType::LS_NONE;
    9681        1340 :   return solver_params;
    9682             : }
    9683             : 
    9684             : const libMesh::CouplingMatrix &
    9685       73848 : FEProblemBase::nonlocalCouplingMatrix(const unsigned i) const
    9686             : {
    9687       73848 :   return _nonlocal_cm[i];
    9688             : }
    9689             : 
    9690             : bool
    9691   105852682 : FEProblemBase::checkNonlocalCouplingRequirement() const
    9692             : {
    9693   105852682 :   return _requires_nonlocal_coupling;
    9694             : }
    9695             : 
    9696             : const std::unordered_map<std::pair<BoundaryID, BoundaryID>,
    9697             :                          std::unique_ptr<AutomaticMortarGeneration>> &
    9698      121488 : FEProblemBase::getMortarInterfaces(bool on_displaced) const
    9699             : {
    9700      121488 :   return _mortar_data->getMortarInterfaces(on_displaced);
    9701             : }

Generated by: LCOV version 1.14