https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FEProblemBase.C
Go to the documentation of this file.
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
12#endif
13
14#include "FEProblemBase.h"
15#include "AuxiliarySystem.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"
29#include "ComputeMarkerThread.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"
50#include "FVGradientMethod.h"
52#include "PetscSupport.h"
53#include "RandomInterface.h"
54#include "RandomData.h"
55#include "MooseEigenSystem.h"
56#include "MooseParsedFunction.h"
63#include "NodalPostprocessor.h"
64#include "SidePostprocessor.h"
73#include "Positions.h"
74#include "Indicator.h"
75#include "Marker.h"
76#include "MultiApp.h"
77#include "MultiAppTransfer.h"
78#include "TransientMultiApp.h"
79#include "ElementUserObject.h"
80#include "DomainUserObject.h"
81#include "NodalUserObject.h"
82#include "SideUserObject.h"
84#include "InterfaceUserObject.h"
85#include "GeneralUserObject.h"
88#include "Transfer.h"
89#include "MultiAppTransfer.h"
90#include "MultiMooseEnum.h"
91#include "Predictor.h"
92#include "Assembly.h"
93#include "Control.h"
94#include "XFEMInterface.h"
95#include "ConsoleUtils.h"
96#include "NonlocalKernel.h"
99#include "ShapeSideUserObject.h"
100#include "MooseVariableFE.h"
101#include "MooseVariableScalar.h"
103#include "TimeIntegrator.h"
104#include "LineSearch.h"
106#include "MaxVarNDofsPerElem.h"
107#include "MaxVarNDofsPerNode.h"
108#include "FVKernel.h"
109#include "LinearFVKernel.h"
110#include "FVTimeKernel.h"
111#include "MooseVariableFV.h"
113#include "FVBoundaryCondition.h"
114#include "FVFluxBC.h"
116#include "FVInterfaceKernel.h"
117#include "InterfaceKernelBase.h"
118#include "Reporter.h"
119#include "ADUtils.h"
120#include "Executioner.h"
121#include "VariadicTable.h"
124#include "NodalBCBase.h"
125#include "MortarUserObject.h"
128#include "Checkpoint.h"
131#include "DependencyResolver.h"
132
133#include "libmesh/exodusII_io.h"
134#include "libmesh/quadrature.h"
135#include "libmesh/coupling_matrix.h"
136#include "libmesh/nonlinear_solver.h"
137#include "libmesh/sparse_matrix.h"
138#include "libmesh/string_to_enum.h"
139#include "libmesh/fe_interface.h"
140#include "libmesh/enum_norm_type.h"
141#include "libmesh/petsc_solver_exception.h"
142#include "libmesh/remote_elem.h"
143
144#include "metaphysicl/dualnumber.h"
145
146// C++
147#include <cstring> // for "Jacobian" exception test
148
149// Anonymous namespace for helper function
150namespace
151{
155bool
156sortMooseVariables(const MooseVariableFEBase * a, const MooseVariableFEBase * b)
157{
158 return a->number() < b->number();
159}
160
161bool
162shouldSolveForSplineDofs(const libMesh::MeshBase & mesh)
163{
164 // With new libMesh, the most accurate thing to do is always solve
165 // for spline DoFs when we have them. With older libMesh, there's a
166 // bug that prevents that solve from working on meshes where we
167 // store some spline DoFs directly on assembly element vertices,
168 // including a mesh in our regression tests. For now we can detect
169 // these cases and avoid the solve for them.
170 bool have_constraint_rows = !mesh.get_constraint_rows().empty();
171
172 mesh.comm().max(have_constraint_rows);
173
174 // Are there any elements we weren't able to properly evaluate on
175 // directly?
176 bool returnval = false;
177 if (have_constraint_rows)
178 {
179 for (const auto & elem : mesh.active_local_element_ptr_range())
180 if (elem->mapping_type() == libMesh::INVALID_MAP // newer libMesh
181 || elem->type() == libMesh::NODEELEM) // older libMesh
182 {
183 returnval = true;
184 break;
185 }
186
187 mesh.comm().max(returnval);
188 }
189
190 return returnval;
191}
192
193void
194solveForSplineDofs(SystemBase & moose_sys)
195{
196 libMesh::System & sys = moose_sys.system();
198
199 // Old libMesh defaults to a *linear* solver tolerance here, which
200 // turns out to be enough in some cases (where a decent
201 // preconditioner converges us way past it) but which in parallel is
202 // too loose for a solve where we're not taking multiple
203 // quasi-Newton steps.
204 const Real old_linear_tol = es.parameters.get<Real>("linear solver tolerance");
205 es.parameters.set<Real>("linear solver tolerance") =
206 es.parameters.get<Real>("nonlinear solver relative residual tolerance");
207
208 sys.solve_for_unconstrained_dofs(moose_sys.solution());
209 sys.get_dof_map().enforce_constraints_exactly(sys, &moose_sys.solution());
210
211 es.parameters.set<Real>("linear solver tolerance") = old_linear_tol;
212}
213
214} // namespace
215
217
220{
222 params.addParam<unsigned int>("null_space_dimension", 0, "The dimension of the nullspace");
223 params.addParam<unsigned int>(
224 "transpose_null_space_dimension", 0, "The dimension of the transpose nullspace");
225 params.addParam<unsigned int>(
226 "near_null_space_dimension", 0, "The dimension of the near nullspace");
227 params.addParam<std::vector<VariableName>>(
228 "constant_null_space_variables",
229 {},
230 "Variables whose constant fields span the nullspace of the Jacobian. Each variable adds one "
231 "mode that is one on the variable's degrees of freedom and zero elsewhere.");
232 params.addParam<std::vector<VariableName>>(
233 "constant_transpose_null_space_variables",
234 {},
235 "Variables whose equation residual entries have a sum that is independent of the solution. "
236 "For each variable, the residual-space vector that is one on the variable's equations' "
237 "vector entries and zero elsewhere then spans part of the transpose nullspace of the "
238 "Jacobian. The linear solver removes the component of the residual along this vector. A "
239 "sum that is nonzero beyond round-off means that the nonlinear system has no solution "
240 "without projection.");
241 params.addParam<bool>("solve",
242 true,
243 "Whether or not to actually solve the Nonlinear system. "
244 "This is handy in the case that all you want to do is "
245 "execute AuxKernels, Transfers, etc. without actually "
246 "solving anything");
247 params.addParam<bool>("use_nonlinear",
248 true,
249 "Determines whether to use a Nonlinear vs a "
250 "Eigenvalue system (Automatically determined based "
251 "on executioner)");
252 params.addParam<bool>("error_on_jacobian_nonzero_reallocation",
253 "This causes PETSc to error if it had to reallocate memory in the Jacobian "
254 "matrix due to not having enough nonzeros");
255 params.addParam<bool>("ignore_zeros_in_jacobian",
256 false,
257 "Do not explicitly store zero values in "
258 "the Jacobian matrix if true");
259 params.addParam<bool>("force_restart",
260 false,
261 "EXPERIMENTAL: If true, a sub_app may use a "
262 "restart file instead of using of using the master "
263 "backup file");
264 params.addDeprecatedParam<bool>("skip_additional_restart_data",
265 false,
266 "True to skip additional data in equation system for restart.",
267 "This parameter is no longer used, as we do not load additional "
268 "vectors by default with restart");
269 params.addParam<bool>("skip_nl_system_check",
270 false,
271 "True to skip the NonlinearSystem check for work to do (e.g. Make sure "
272 "that there are variables to solve for).");
273 params.addParam<bool>("allow_initial_conditions_with_restart",
274 false,
275 "True to allow the user to specify initial conditions when restarting. "
276 "Initial conditions can override any restarted field");
277
278 auto coverage_check_description = [](std::string scope, std::string list_param_name)
279 {
280 return "Controls, if and how a " + scope +
281 " subdomain coverage check is performed. "
282 "With 'TRUE' or 'ON' all subdomains are checked (the default). Setting 'FALSE' or 'OFF' "
283 "will disable the check for all subdomains. "
284 "To exclude a predefined set of subdomains 'SKIP_LIST' is to "
285 "be used, while the subdomains to skip are to be defined in the parameter '" +
286 list_param_name +
287 "'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
288 "be used (again, using the parameter '" +
289 list_param_name + "').";
290 };
291
292 params.addParam<std::vector<SubdomainName>>(
293 "block",
294 {"ANY_BLOCK_ID"},
295 "List of subdomains for kernel coverage and material coverage checks. Setting this parameter "
296 "is equivalent to setting 'kernel_coverage_block_list' and 'material_coverage_block_list' as "
297 "well as using 'ONLY_LIST' as the coverage check mode.");
298
299 MooseEnum kernel_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
300 params.addParam<MooseEnum>("kernel_coverage_check",
301 kernel_coverage_check_modes,
302 coverage_check_description("kernel", "kernel_coverage_block_list"));
303 params.addParam<std::vector<SubdomainName>>(
304 "kernel_coverage_block_list",
305 {},
306 "List of subdomains for kernel coverage check. The meaning of this list is controlled by the "
307 "parameter 'kernel_coverage_check' (whether this is the list of subdomains to be checked, "
308 "not to be checked or not taken into account).");
309 params.addParam<bool>(
310 "boundary_restricted_node_integrity_check",
311 true,
312 "Set to false to disable checking of boundary restricted nodal object variable dependencies, "
313 "e.g. are the variable dependencies defined on the selected boundaries?");
314 params.addParam<bool>("boundary_restricted_elem_integrity_check",
315 true,
316 "Set to false to disable checking of boundary restricted elemental object "
317 "variable dependencies, e.g. are the variable dependencies defined on the "
318 "selected boundaries?");
319 params.addParam<bool>("interface_kernel_integrity_check",
320 true,
321 "Set to false to disable checking that each interface kernel's 'variable' "
322 "is defined on the primary side and 'neighbor_var' on the secondary side "
323 "of each of its boundaries");
324 params.addParam<bool>(
325 "side_uo_interface_mat_prop_integrity_check",
326 true,
327 "Set to false to disable checking that side user objects do not consume material "
328 "properties declared by interface materials on the same boundary.");
329 MooseEnum material_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
330 params.addParam<MooseEnum>(
331 "material_coverage_check",
332 material_coverage_check_modes,
333 coverage_check_description("material", "material_coverage_block_list"));
334 params.addParam<std::vector<SubdomainName>>(
335 "material_coverage_block_list",
336 {},
337 "List of subdomains for material coverage check. The meaning of this list is controlled by "
338 "the parameter 'material_coverage_check' (whether this is the list of subdomains to be "
339 "checked, not to be checked or not taken into account).");
340
341 params.addParam<bool>("fv_bcs_integrity_check",
342 true,
343 "Set to false to disable checking of overlapping Dirichlet and Flux BCs "
344 "and/or multiple DirichletBCs per sideset");
345
346 params.addParam<bool>(
347 "fv_face_integrity_check",
348 true,
349 "Set to false to disable checking that FV flux boundary conditions and FV interface "
350 "kernels are applied to faces with valid variable ownership and interface topology.");
351
352 params.addParam<bool>(
353 "material_dependency_check", true, "Set to false to disable material dependency check");
354 params.addParam<bool>("parallel_barrier_messaging",
355 false,
356 "Displays messaging from parallel "
357 "barrier notifications when executing "
358 "or transferring to/from Multiapps "
359 "(default: false)");
360 params.addParam<unsigned int>(
361 "num_concurrent_multiapps",
362 1,
363 "Set greater than 1 to solve the multiapps sharing an 'execution_order_group' "
364 "concurrently. Each such multiapp is assigned a disjoint subset of the MPI ranks "
365 "(partitioned using their 'min_procs_per_app'/'max_procs_per_app', otherwise evenly), so "
366 "they solve at the same time on different ranks. The specific value only acts as an "
367 "on/off switch; the number that run at once is set by the ranks available.");
368
369 MooseEnum verbosity("false true extra", "false");
370 params.addParam<MooseEnum>("verbose_setup",
371 verbosity,
372 "Set to 'true' to have the problem report on any object created. Set "
373 "to 'extra' to also display all parameters.");
374 params.addParam<bool>("verbose_multiapps",
375 false,
376 "Set to True to enable verbose screen printing related to MultiApps");
377 params.addParam<bool>(
378 "verbose_restore",
379 false,
380 "Set to True to enable verbose screen printing related to solution restoration");
381
382 params.addParam<FileNameNoExtension>("restart_file_base",
383 "File base name used for restart (e.g. "
384 "<path>/<filebase> or <path>/LATEST to "
385 "grab the latest file available)");
386
387 params.addParam<std::vector<std::vector<TagName>>>(
388 "extra_tag_vectors",
389 {},
390 "Extra vectors to add to the system that can be filled by objects which compute residuals "
391 "and Jacobians (Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
392 "nonlinear system the extra tag vectors should be added for");
393
394 params.addParam<std::vector<std::vector<TagName>>>(
395 "not_zeroed_tag_vectors",
396 {},
397 "Extra vector tags which the sytem will not zero when other vector tags are zeroed. "
398 "The outer index is for which nonlinear system the extra tag vectors should be added for");
399
400 params.addParam<std::vector<std::vector<TagName>>>(
401 "extra_tag_matrices",
402 {},
403 "Extra matrices to add to the system that can be filled "
404 "by objects which compute residuals and Jacobians "
405 "(Kernels, BCs, etc.) by setting tags on them. The outer index is for which "
406 "nonlinear system the extra tag vectors should be added for");
407
408 params.addParam<std::vector<TagName>>(
409 "extra_tag_solutions",
410 {},
411 "Extra solution vectors to add to the system that can be used by "
412 "objects for coupling variable values stored in them.");
413
414 params.addParam<bool>("previous_nl_solution_required",
415 false,
416 "True to indicate that this calculation requires a solution vector for "
417 "storing the previous nonlinear iteration.");
418
419 params.addParam<std::vector<NonlinearSystemName>>(
420 "nl_sys_names", std::vector<NonlinearSystemName>{"nl0"}, "The nonlinear system names");
421
422 params.addParam<std::vector<LinearSystemName>>("linear_sys_names", {}, "The linear system names");
423
424 params.addParam<bool>("check_uo_aux_state",
425 false,
426 "True to turn on a check that no state presents during the evaluation of "
427 "user objects and aux kernels");
428
429 params.addPrivateParam<MooseMesh *>("mesh");
430
431 params.declareControllable("solve");
432
433 params.addParam<bool>(
434 "allow_invalid_solution",
435 false,
436 "Set to true to allow convergence even though the solution has been marked as 'invalid'");
437 params.addParam<bool>("show_invalid_solution_console",
438 true,
439 "Set to true to show the invalid solution occurrence summary in console");
440 params.addParam<bool>("immediately_print_invalid_solution",
441 false,
442 "Whether or not to report invalid solution warnings at the time the "
443 "warning is produced instead of after the calculation");
444
445 params.addParam<bool>(
446 "identify_variable_groups_in_nl",
447 true,
448 "Whether to identify variable groups in nonlinear systems. This affects dof ordering");
449
450 params.addParam<bool>(
451 "regard_general_exceptions_as_errors",
452 false,
453 "If we catch an exception during residual/Jacobian evaluaton for which we don't have "
454 "specific handling, immediately error instead of allowing the time step to be cut");
455
456 params.addParam<bool>("use_hash_table_matrix_assembly",
457 false,
458 "Whether to assemble matrices using hash tables instead of preallocating "
459 "matrix memory. This can be a good option if the sparsity pattern changes "
460 "throughout the course of the simulation.");
461 params.addParam<bool>(
462 "restore_original_nonzero_pattern",
463 "Whether we should reset matrix memory for every Jacobian evaluation. This option is useful "
464 "if the sparsity pattern is constantly changing and you are using hash table assembly or if "
465 "you wish to continually restore the matrix to the originally preallocated sparsity pattern "
466 "computed by relationship managers.");
467
469 "skip_nl_system_check kernel_coverage_check kernel_coverage_block_list "
470 "boundary_restricted_node_integrity_check "
471 "boundary_restricted_elem_integrity_check interface_kernel_integrity_check "
472 "side_uo_interface_mat_prop_integrity_check material_coverage_check "
473 "material_coverage_block_list fv_bcs_integrity_check fv_face_integrity_check "
474 "material_dependency_check check_uo_aux_state error_on_jacobian_nonzero_reallocation",
475 "Simulation checks");
476 params.addParamNamesToGroup("use_nonlinear previous_nl_solution_required nl_sys_names "
477 "ignore_zeros_in_jacobian identify_variable_groups_in_nl "
478 "use_hash_table_matrix_assembly restore_original_nonzero_pattern",
479 "Nonlinear system(s)");
481 "restart_file_base force_restart allow_initial_conditions_with_restart", "Restart");
483 "verbose_setup verbose_multiapps verbose_restore parallel_barrier_messaging", "Verbosity");
485 "null_space_dimension transpose_null_space_dimension near_null_space_dimension "
486 "constant_null_space_variables constant_transpose_null_space_variables",
487 "Null space removal");
489 "extra_tag_vectors extra_tag_matrices extra_tag_solutions not_zeroed_tag_vectors",
490 "Contribution to tagged field data");
492 "allow_invalid_solution show_invalid_solution_console immediately_print_invalid_solution",
493 "Solution validity control");
494
495 return params;
496}
497
499 : SubProblem(parameters),
500 Restartable(this, "FEProblemBase"),
501 _mesh(*getCheckedPointerParam<MooseMesh *>("mesh")),
502 _req(declareManagedRestartableDataWithContext<RestartableEquationSystems>(
503 "equation_systems", nullptr, _mesh)),
504 _initialized(false),
505 _solve(getParam<bool>("solve")),
506 _transient(false),
507 _time(declareRestartableData<Real>("time")),
508 _time_old(declareRestartableData<Real>("time_old")),
509 _time_older(declareRestartableData<Real>("time_older")),
510 _t_step(declareRecoverableData<int>("t_step")),
511 _dt(declareRestartableData<Real>("dt")),
512 _dt_old(declareRestartableData<Real>("dt_old")),
513 _need_to_add_default_nonlinear_convergence(false),
514 _need_to_add_default_multiapp_fixed_point_convergence(false),
515 _need_to_add_default_steady_state_convergence(false),
516 _linear_sys_names(getParam<std::vector<LinearSystemName>>("linear_sys_names")),
517 _num_linear_sys(_linear_sys_names.size()),
518 _linear_systems(_num_linear_sys, nullptr),
519 _current_linear_sys(nullptr),
520 _using_default_nl(!isParamSetByUser("nl_sys_names")),
521 _nl_sys_names(!_using_default_nl || (_using_default_nl && !_linear_sys_names.size())
522 ? getParam<std::vector<NonlinearSystemName>>("nl_sys_names")
523 : std::vector<NonlinearSystemName>()),
524 _num_nl_sys(_nl_sys_names.size()),
525 _nl(_num_nl_sys, nullptr),
526 _current_nl_sys(nullptr),
527 _solver_systems(_num_nl_sys + _num_linear_sys, nullptr),
528 _aux(nullptr),
529 _coupling(Moose::COUPLING_DIAG),
530#ifdef MOOSE_KOKKOS_ENABLED
531 _kokkos_assembly(*this),
532#endif
533 _mesh_divisions(numThreads()),
534 _functions(numThreads()),
535#ifdef MOOSE_KOKKOS_ENABLED
536 _kokkos_functions(/*num_threads=*/1),
537#endif
538 _convergences(numThreads()),
539 _nonlocal_kernels(numThreads()),
540 _nonlocal_integrated_bcs(numThreads()),
541 _ics(numThreads()),
542 _fv_ics(numThreads()),
543 _material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
544 "material_props", &_mesh, _material_prop_registry, *this)),
545 _bnd_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
546 "bnd_material_props", &_mesh, _material_prop_registry, *this)),
547 _neighbor_material_props(declareRestartableDataWithContext<MaterialPropertyStorage>(
548 "neighbor_material_props", &_mesh, _material_prop_registry, *this)),
549#ifdef MOOSE_KOKKOS_ENABLED
550 _kokkos_material_props(
551 declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
552 "kokkos_material_props", &_mesh, _material_prop_registry, *this)),
553 _kokkos_bnd_material_props(
554 declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
555 "kokkos_bnd_material_props", &_mesh, _material_prop_registry, *this)),
556 _kokkos_neighbor_material_props(
557 declareRestartableDataWithContext<Moose::Kokkos::MaterialPropertyStorage>(
558 "kokkos_neighbor_material_props", &_mesh, _material_prop_registry, *this)),
559#endif
560 _materials(numThreads()),
561 _interface_materials(numThreads()),
562 _discrete_materials(numThreads()),
563 _all_materials(numThreads()),
564#ifdef MOOSE_KOKKOS_ENABLED
565 _kokkos_materials(/*num_threads=*/1),
566#endif
567 _indicators(numThreads()),
568 _internal_side_indicators(numThreads()),
569 _markers(numThreads()),
570 _reporter_data(_app),
571 _multi_apps(_app.getExecuteOnEnum(), numThreads()),
572 _transient_multi_apps(_app.getExecuteOnEnum(), numThreads()),
573 _transfers(_app.getExecuteOnEnum(), /*num_threads=*/1),
574 _to_multi_app_transfers(_app.getExecuteOnEnum(), /*num_threads=*/1),
575 _from_multi_app_transfers(_app.getExecuteOnEnum(), /*num_threads=*/1),
576 _between_multi_app_transfers(_app.getExecuteOnEnum(), /*num_threads=*/1),
577 _num_concurrent_multiapps(getParam<unsigned int>("num_concurrent_multiapps")),
578#ifdef LIBMESH_ENABLE_AMR
579 _adaptivity(*this),
580 _cycles_completed(0),
581#endif
582 _displaced_mesh(nullptr),
583 _geometric_search_data(*this, _mesh),
584 _mortar_data(std::make_unique<MortarInterfaceWarehouse>(*this)),
585 _reinit_displaced_elem(false),
586 _reinit_displaced_face(false),
587 _reinit_displaced_neighbor(false),
588 _input_file_saved(false),
589 _has_dampers(false),
590 _has_constraints(false),
591 _snesmf_reuse_base(true),
592 _skip_exception_check(false),
593 _snesmf_reuse_base_set_by_user(false),
594 _has_initialized_stateful(false),
595 _const_jacobian(false),
596 _has_jacobian(false),
597 _needs_old_newton_iter(false),
598 _previous_nl_solution_required(getParam<bool>("previous_nl_solution_required")),
599 _previous_multiapp_fp_nl_solution_required(_num_nl_sys + _num_linear_sys, false),
600 _previous_multiapp_fp_aux_solution_required(false),
601 _previous_multisystem_fp_nl_solution_required(_num_nl_sys + _num_linear_sys, false),
602 _previous_multisystem_fp_aux_solution_required(false),
603 _has_nonlocal_coupling(false),
604 _calculate_jacobian_in_uo(false),
605 _kernel_coverage_check(
606 getParam<MooseEnum>("kernel_coverage_check").getEnum<CoverageCheckMode>()),
607 _kernel_coverage_blocks(getParam<std::vector<SubdomainName>>("kernel_coverage_block_list")),
608 _boundary_restricted_node_integrity_check(
609 getParam<bool>("boundary_restricted_node_integrity_check")),
610 _boundary_restricted_elem_integrity_check(
611 getParam<bool>("boundary_restricted_elem_integrity_check")),
612 _interface_kernel_integrity_check(getParam<bool>("interface_kernel_integrity_check")),
613 _side_uo_interface_mat_prop_integrity_check(
614 getParam<bool>("side_uo_interface_mat_prop_integrity_check")),
615 _material_coverage_check(
616 getParam<MooseEnum>("material_coverage_check").getEnum<CoverageCheckMode>()),
617 _material_coverage_blocks(getParam<std::vector<SubdomainName>>("material_coverage_block_list")),
618 _fv_bcs_integrity_check(getParam<bool>("fv_bcs_integrity_check")),
619 _fv_face_integrity_check(getParam<bool>("fv_face_integrity_check")),
620 _material_dependency_check(getParam<bool>("material_dependency_check")),
621 _uo_aux_state_check(getParam<bool>("check_uo_aux_state")),
622#ifndef NDEBUG
623 _check_residual_for_nans(false),
624#endif
625 _max_qps(std::numeric_limits<unsigned int>::max()),
626 _max_scalar_order(INVALID_ORDER),
627 _has_time_integrator(false),
628 _has_exception(false),
629 _parallel_barrier_messaging(getParam<bool>("parallel_barrier_messaging")),
630 _verbose_setup(getParam<MooseEnum>("verbose_setup")),
631 _verbose_multiapps(getParam<bool>("verbose_multiapps")),
632 _verbose_restore(getParam<bool>("verbose_restore")),
633 _current_execute_on_flag(EXEC_NONE),
634 _control_warehouse(_app.getExecuteOnEnum(), /*num_threads=*/1),
635 _is_petsc_options_inserted(false),
636 _line_search(nullptr),
637 _using_ad_mat_props(false),
638 _current_ic_state(0),
639 _constant_null_space_vars(getParam<std::vector<VariableName>>("constant_null_space_variables")),
640 _constant_transpose_null_space_vars(
641 getParam<std::vector<VariableName>>("constant_transpose_null_space_variables")),
642 _use_hash_table_matrix_assembly(getParam<bool>("use_hash_table_matrix_assembly")),
643 _error_on_jacobian_nonzero_reallocation(
644 isParamValid("error_on_jacobian_nonzero_reallocation")
645 ? getParam<bool>("error_on_jacobian_nonzero_reallocation")
646 : _app.errorOnJacobianNonzeroReallocation()),
647 _restore_original_nonzero_pattern(isParamValid("restore_original_nonzero_pattern")
648 ? getParam<bool>("restore_original_nonzero_pattern")
649 : _use_hash_table_matrix_assembly),
650 _ignore_zeros_in_jacobian(getParam<bool>("ignore_zeros_in_jacobian")),
651 _preserve_matrix_sparsity_pattern(true),
652 _force_restart(getParam<bool>("force_restart")),
653 _allow_ics_during_restart(getParam<bool>("allow_initial_conditions_with_restart")),
654 _skip_nl_system_check(getParam<bool>("skip_nl_system_check")),
655 _fail_next_system_convergence_check(false),
656 _allow_invalid_solution(getParam<bool>("allow_invalid_solution")),
657 _show_invalid_solution_console(getParam<bool>("show_invalid_solution_console")),
658 _immediately_print_invalid_solution(getParam<bool>("immediately_print_invalid_solution")),
659 _started_initial_setup(false),
660 _has_internal_edge_residual_objects(false),
661 _u_dot_requested(false),
662 _u_dotdot_requested(false),
663 _u_dot_old_requested(false),
664 _u_dotdot_old_requested(false),
665 _has_mortar(false),
666 _num_grid_steps(0),
667 _print_execution_on(),
668 _identify_variable_groups_in_nl(getParam<bool>("identify_variable_groups_in_nl")),
669 _regard_general_exceptions_as_errors(getParam<bool>("regard_general_exceptions_as_errors")),
670 _requires_nonlocal_coupling(false)
671{
672 auto checkCoverageCheckConflict =
673 [this](const std::string & coverage_check,
674 const CoverageCheckMode & coverage_check_mode,
675 const std::vector<SubdomainName> & coverage_blocks) -> void
676 {
677 if (coverage_check_mode != CoverageCheckMode::FALSE &&
678 coverage_check_mode != CoverageCheckMode::OFF)
679 if (coverage_blocks.size() > 1)
680 if (std::find(coverage_blocks.begin(), coverage_blocks.end(), "ANY_BLOCK_ID") !=
681 coverage_blocks.end())
682 paramError(coverage_check,
683 "The list of blocks used for ",
684 coverage_check,
685 " cannot contain 'ANY_BLOCK_ID' along with other blocks. ");
686 };
687
688 checkCoverageCheckConflict(
689 "kernel_coverage_check", _kernel_coverage_check, _kernel_coverage_blocks);
690 checkCoverageCheckConflict(
691 "material_coverage_check", _material_coverage_check, _material_coverage_blocks);
692
693 // Initialize static do_derivatives member. We initialize this to true so that all the
694 // default AD things that we setup early in the simulation actually get their derivative
695 // vectors initalized. We will toggle this to false when doing residual evaluations
696 ADReal::do_derivatives = true;
697
698 // Disable refinement/coarsening in EquationSystems::reinit because we already do this ourselves
700
702 // Default constructor fine for nonlinear because it will be populated later by framework
703 // executioner/solve object parameters
705 for (const auto i : index_range(_nl_sys_names))
706 {
707 const auto & name = _nl_sys_names[i];
710 _solver_sys_names.push_back(name);
711 }
712
713 for (const auto i : index_range(_linear_sys_names))
714 {
715 const auto & name = _linear_sys_names[i];
718 _solver_sys_names.push_back(name);
719 // Unlike for nonlinear these are basically dummy parameters
721 }
722
724 _cm.resize(numSolverSystems());
725
726 _time = 0.0;
727 _time_old = 0.0;
728 _time_older = 0.0;
729 _t_step = 0;
730 _dt = 0;
731 _dt_old = _dt;
732
733 unsigned int n_threads = numThreads();
734
735 _real_zero.resize(n_threads, 0.);
736 _scalar_zero.resize(n_threads);
737 _zero.resize(n_threads);
738 _phi_zero.resize(n_threads);
739 _ad_zero.resize(n_threads);
740 _grad_zero.resize(n_threads);
741 _ad_grad_zero.resize(n_threads);
742 _grad_phi_zero.resize(n_threads);
743 _second_zero.resize(n_threads);
744 _ad_second_zero.resize(n_threads);
745 _second_phi_zero.resize(n_threads);
746 _point_zero.resize(n_threads);
747 _vector_zero.resize(n_threads);
748 _vector_curl_zero.resize(n_threads);
749 _uo_jacobian_moose_vars.resize(n_threads);
750
751 _has_active_material_properties.resize(n_threads, 0);
752
753 _block_mat_side_cache.resize(n_threads);
754 _bnd_mat_side_cache.resize(n_threads);
755 _interface_mat_side_cache.resize(n_threads);
756
757 es().parameters.set<FEProblemBase *>("_fe_problem_base") = this;
758
759 if (isParamValid("restart_file_base"))
760 {
761 std::string restart_file_base = getParam<FileNameNoExtension>("restart_file_base");
762
763 // This check reverts to old behavior of providing "restart_file_base=" to mean
764 // don't restart... BISON currently relies on this. It could probably be removed.
765 // The new MooseUtils::convertLatestCheckpoint will error out if a checkpoint file
766 // is not found, which I think makes sense. Which means, without this, if you
767 // set "restart_file_base=", you'll get a "No checkpoint file found" error
768 if (restart_file_base.size())
769 {
770 restart_file_base = MooseUtils::convertLatestCheckpoint(restart_file_base);
771 setRestartFile(restart_file_base);
772 }
773 }
774
775 // // Generally speaking, the mesh is prepared for use, and consequently remote elements are deleted
776 // // well before our Problem(s) are constructed. Historically, in MooseMesh we have a bunch of
777 // // needs_prepare type flags that make it so we never call prepare_for_use (and consequently
778 // // delete_remote_elements) again. So the below line, historically, has had no impact. HOWEVER:
779 // // I've added some code in SetupMeshCompleteAction for deleting remote elements post
780 // // EquationSystems::init. If I execute that code without default ghosting, then I get > 40 MOOSE
781 // // test failures, so we clearly have some simulations that are not yet covered properly by
782 // // relationship managers. Until that is resolved, I am going to retain default geometric ghosting
783 // if (!_default_ghosting)
784 // _mesh.getMesh().remove_ghosting_functor(_mesh.getMesh().default_ghosting());
785
786#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
787 // Main app should hold the default database to handle system petsc options
788 if (!_app.isUltimateMaster())
789 LibmeshPetscCall(PetscOptionsCreate(&_petsc_option_data_base));
790#endif
791
792 if (!_solve)
793 {
794 // If we are not solving, we do not care about seeing unused petsc options
795 Moose::PetscSupport::setSinglePetscOption("-options_left", "0");
796 // We don't want petscSetOptions being called in solve and clearing the option that was just set
798 }
799}
800
801const MooseMesh &
802FEProblemBase::mesh(bool use_displaced) const
803{
804 if (use_displaced && !_displaced_problem)
805 mooseWarning("Displaced mesh was requested but the displaced problem does not exist. "
806 "Regular mesh will be returned");
807 return ((use_displaced && _displaced_problem) ? _displaced_problem->mesh() : mesh());
808}
809
810MooseMesh &
811FEProblemBase::mesh(bool use_displaced)
812{
813 if (use_displaced && !_displaced_problem)
814 mooseWarning("Displaced mesh was requested but the displaced problem does not exist. "
815 "Regular mesh will be returned");
816 return ((use_displaced && _displaced_problem) ? _displaced_problem->mesh() : mesh());
817}
818
819void
821{
822 // add vectors and their tags to system
823 auto & vectors = getParam<std::vector<std::vector<TagName>>>("extra_tag_vectors");
824 for (const auto sys_num : index_range(vectors))
825 for (auto & vector : vectors[sys_num])
826 {
827 auto tag = addVectorTag(vector);
828 _solver_systems[sys_num]->addVector(tag, false, libMesh::GHOSTED);
829 }
830
831 auto & not_zeroed_vectors = getParam<std::vector<std::vector<TagName>>>("not_zeroed_tag_vectors");
832 for (const auto sys_num : index_range(not_zeroed_vectors))
833 for (auto & vector : not_zeroed_vectors[sys_num])
834 {
835 auto tag = addVectorTag(vector);
836 _solver_systems[sys_num]->addVector(tag, false, GHOSTED);
838 }
839}
840
841void
843{
844 auto & matrices = getParam<std::vector<std::vector<TagName>>>("extra_tag_matrices");
845 for (const auto sys_num : index_range(matrices))
846 for (auto & matrix : matrices[sys_num])
847 {
848 auto tag = addMatrixTag(matrix);
849 _solver_systems[sys_num]->addMatrix(tag);
850 }
851
852 for (auto & sys : _solver_systems)
853 sys->sizeVariableMatrixData();
854 _aux->sizeVariableMatrixData();
855}
856
857void
859{
860 for (auto & vector : getParam<std::vector<TagName>>("extra_tag_solutions"))
861 {
862 auto tag = addVectorTag(vector, Moose::VECTOR_TAG_SOLUTION);
863 for (auto & sys : _solver_systems)
864 sys->addVector(tag, false, libMesh::GHOSTED);
865 _aux->addVector(tag, false, libMesh::GHOSTED);
866 }
867
869 {
870 // We'll populate the zeroth state of the nonlinear iterations with the current solution for
871 // ease of use in doing things like copying solutions backwards. We're just storing pointers in
872 // the solution states containers so populating the zeroth state does not cost us the memory of
873 // a new vector
875 }
876
878 for (auto & sys : _solver_systems)
879 sys->associateVectorToTag(*sys->system().current_local_solution.get(), tag);
880 _aux->associateVectorToTag(*_aux->system().current_local_solution.get(), tag);
881}
882
883void
885{
886 for (auto & sys : _solver_systems)
887 sys->needSolutionState(state, iteration_type);
888 _aux->needSolutionState(state, iteration_type);
889}
890
891bool
893 Moose::SolutionIterationType iteration_type) const
894{
895 bool has_solution_state = false;
896 for (auto & sys : _solver_systems)
897 has_solution_state |= sys->hasSolutionState(state, iteration_type);
898 has_solution_state |= _aux->hasSolutionState(state, iteration_type);
899 return has_solution_state;
900}
901
902void
903FEProblemBase::newAssemblyArray(std::vector<std::shared_ptr<SolverSystem>> & solver_systems)
904{
905 unsigned int n_threads = numThreads();
906
907 _assembly.resize(n_threads);
908 for (const auto i : make_range(n_threads))
909 {
910 _assembly[i].resize(solver_systems.size());
911 for (const auto j : index_range(solver_systems))
912 _assembly[i][j] = std::make_unique<Assembly>(*solver_systems[j], i);
913 }
914}
915
916void
918 std::vector<std::shared_ptr<NonlinearSystemBase>> & nls)
919{
920 TIME_SECTION("initNullSpaceVectors", 5, "Initializing Null Space Vectors");
921
922 unsigned int dimNullSpace = parameters.get<unsigned int>("null_space_dimension");
923 unsigned int dimTransposeNullSpace =
924 parameters.get<unsigned int>("transpose_null_space_dimension");
925 unsigned int dimNearNullSpace = parameters.get<unsigned int>("near_null_space_dimension");
926 for (unsigned int i = 0; i < dimNullSpace; ++i)
927 {
928 std::ostringstream oss;
929 oss << "_" << i;
930 // do not project, since this will be recomputed, but make it ghosted, since the near nullspace
931 // builder might march over all nodes
932 for (auto & nl : nls)
933 nl->addVector("NullSpace" + oss.str(), false, libMesh::GHOSTED);
934 }
935 _subspace_dim["NullSpace"] = dimNullSpace;
936 for (unsigned int i = 0; i < dimTransposeNullSpace; ++i)
937 {
938 std::ostringstream oss;
939 oss << "_" << i;
940 // do not project, since this will be recomputed, but make it ghosted, since the near nullspace
941 // builder might march over all nodes
942 for (auto & nl : nls)
943 nl->addVector("TransposeNullSpace" + oss.str(), false, libMesh::GHOSTED);
944 }
945 _subspace_dim["TransposeNullSpace"] = dimTransposeNullSpace;
946 for (unsigned int i = 0; i < dimNearNullSpace; ++i)
947 {
948 std::ostringstream oss;
949 oss << "_" << i;
950 // do not project, since this will be recomputed, but make it ghosted, since the near-nullspace
951 // builder might march over all semilocal nodes
952 for (auto & nl : nls)
953 nl->addVector("NearNullSpace" + oss.str(), false, libMesh::GHOSTED);
954 }
955 _subspace_dim["NearNullSpace"] = dimNearNullSpace;
956}
957
959{
960 // Flush the Console stream, the underlying call to Console::mooseConsole
961 // relies on a call to Output::checkInterval that has references to
962 // _time, etc. If it is not flushed here memory problems arise if you have
963 // an unflushed stream and start destructing things.
964 _console << std::flush;
965
966 unsigned int n_threads = numThreads();
967 for (unsigned int i = 0; i < n_threads; i++)
968 {
969 _zero[i].release();
970 _phi_zero[i].release();
971 _scalar_zero[i].release();
972 _grad_zero[i].release();
973 _grad_phi_zero[i].release();
974 _second_zero[i].release();
975 _second_phi_zero[i].release();
976 _vector_zero[i].release();
977 _vector_curl_zero[i].release();
978 _ad_zero[i].release();
979 _ad_grad_zero[i].release();
980 _ad_second_zero[i].release();
981 }
982
983#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
984 if (!_app.isUltimateMaster())
985 {
986 auto ierr = PetscOptionsDestroy(&_petsc_option_data_base);
987 // Don't throw on destruction
988 CHKERRABORT(this->comm().get(), ierr);
989 }
990#endif
991}
992
993void
994FEProblemBase::setCoordSystem(const std::vector<SubdomainName> & blocks,
995 const MultiMooseEnum & coord_sys)
996{
997 TIME_SECTION("setCoordSystem", 5, "Setting Coordinate System");
998 _mesh.setCoordSystem(blocks, coord_sys);
999}
1000
1001void
1003{
1004 _mesh.setAxisymmetricCoordAxis(rz_coord_axis);
1005}
1006
1007const ConstElemRange &
1009{
1011 {
1012 std::vector<const DofMap *> dof_maps(es().n_systems());
1013 for (const auto i : make_range(es().n_systems()))
1014 {
1015 const auto & sys = es().get_system(i);
1016 dof_maps[i] = &sys.get_dof_map();
1017 }
1019 std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
1020 _mesh.getMesh().multi_evaluable_elements_end(dof_maps));
1021 }
1023}
1024
1025const ConstElemRange &
1027{
1029 {
1030 std::vector<const DofMap *> dof_maps(_nl.size());
1031 for (const auto i : index_range(dof_maps))
1032 dof_maps[i] = &_nl[i]->dofMap();
1034 std::make_unique<ConstElemRange>(_mesh.getMesh().multi_evaluable_elements_begin(dof_maps),
1035 _mesh.getMesh().multi_evaluable_elements_end(dof_maps));
1036 }
1037
1039}
1040
1041void
1043{
1044 TIME_SECTION("initialSetup", 2, "Performing Initial Setup");
1045
1047
1049 mooseError("Checkpoint recovery and restart and exodus restart are all mutually exclusive.");
1050
1052 mooseWarning("MOOSE may fail to catch an exception when the \"skip_exception_check\" parameter "
1053 "is used. If you receive a terse MPI error during execution, remove this "
1054 "parameter and rerun your simulation");
1055
1056 // set state flag indicating that we are in or beyond initialSetup.
1057 // This can be used to throw errors in methods that _must_ be called at construction time.
1060
1061 // Setup the solution states (current, old, etc) in each system based on
1062 // its default and the states requested of each of its variables
1063 for (const auto i : index_range(_solver_systems))
1064 {
1065 _solver_systems[i]->initSolutionState();
1066 if (getDisplacedProblem())
1067 getDisplacedProblem()->solverSys(i).initSolutionState();
1068 }
1069 _aux->initSolutionState();
1070 if (getDisplacedProblem())
1071 getDisplacedProblem()->auxSys().initSolutionState();
1072
1073 // always execute to get the max number of DoF per element and node needed to initialize phi_zero
1074 // variables
1075 dof_id_type global_max_var_n_dofs_per_elem = 0;
1076 for (const auto i : index_range(_solver_systems))
1077 {
1078 auto & sys = *_solver_systems[i];
1079 dof_id_type max_var_n_dofs_per_elem;
1080 dof_id_type max_var_n_dofs_per_node;
1081 {
1082 TIME_SECTION("computingMaxDofs", 3, "Computing Max Dofs Per Element");
1083
1084 MaxVarNDofsPerElem mvndpe(*this, sys);
1086 max_var_n_dofs_per_elem = mvndpe.max();
1087 _communicator.max(max_var_n_dofs_per_elem);
1088
1089 MaxVarNDofsPerNode mvndpn(*this, sys);
1091 max_var_n_dofs_per_node = mvndpn.max();
1092 _communicator.max(max_var_n_dofs_per_node);
1093 global_max_var_n_dofs_per_elem =
1094 std::max(global_max_var_n_dofs_per_elem, max_var_n_dofs_per_elem);
1095 }
1096
1097 {
1098 TIME_SECTION("assignMaxDofs", 5, "Assigning Maximum Dofs Per Elem");
1099
1100 sys.assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
1103 displaced_problem->solverSys(i).assignMaxVarNDofsPerElem(max_var_n_dofs_per_elem);
1104
1105 sys.assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
1107 displaced_problem->solverSys(i).assignMaxVarNDofsPerNode(max_var_n_dofs_per_node);
1108 }
1109 }
1110
1111 {
1112 TIME_SECTION("resizingVarValues", 5, "Resizing Variable Values");
1113
1114 for (unsigned int tid = 0; tid < numThreads(); ++tid)
1115 {
1116 _phi_zero[tid].resize(global_max_var_n_dofs_per_elem, std::vector<Real>(getMaxQps(), 0.));
1117 _grad_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
1118 std::vector<RealGradient>(getMaxQps(), RealGradient(0.)));
1119 _second_phi_zero[tid].resize(global_max_var_n_dofs_per_elem,
1120 std::vector<RealTensor>(getMaxQps(), RealTensor(0.)));
1121 }
1122 }
1123
1124 // Set up stateful material property redistribution, if we suspect
1125 // it may be necessary later.
1127
1129 {
1130 // Only load all of the vectors if we're recovering
1132
1133 // This forces stateful material property loading to be an exact one-to-one match
1134 if (_app.isRecovering())
1135 {
1137 props->setRecovering();
1138
1139#ifdef MOOSE_KOKKOS_ENABLED
1140 for (auto props :
1142 props->setRecovering();
1143#endif
1144 }
1145
1146 TIME_SECTION("restore", 3, "Restoring from backup");
1147
1148 // We could have a cached backup when this app is a sub-app and has been given a Backup
1149 if (!_app.hasInitialBackup())
1151 else
1153
1159 if (_app.isRestarting())
1160 {
1161 if (_app.hasStartTime())
1163 else
1164 {
1166 _time_old = _time;
1167 }
1168 }
1169 }
1170 else
1171 {
1173
1174 if (reader)
1175 {
1176 TIME_SECTION("copyingFromExodus", 3, "Copying Variables From Exodus");
1177
1178 for (auto & sys : _solver_systems)
1179 sys->copyVars(*reader);
1180 _aux->copyVars(*reader);
1181 }
1182 else
1183 {
1184 if (_solver_systems[0]->hasVarCopy() || _aux->hasVarCopy())
1185 mooseError("Need Exodus reader to restart variables but the reader is not available\n"
1186 "Use either FileMesh with an Exodus mesh file or FileMeshGenerator with an "
1187 "Exodus mesh file and with use_for_exodus_restart equal to true");
1188 }
1189 }
1190
1191 // Perform output related setups
1193
1194 // Flush all output to _console that occur during construction and initialization of objects
1196
1197 // Build Refinement and Coarsening maps for stateful material projections if necessary
1198 if ((_adaptivity.isOn() || _num_grid_steps) &&
1201 {
1203 mooseError("Stateful neighbor material properties do not work with mesh adaptivity");
1204
1206 }
1207
1208 if (!_app.isRecovering())
1209 {
1216 {
1217 if (!_app.isUltimateMaster())
1218 mooseError(
1219 "Doing extra refinements when restarting is NOT supported for sub-apps of a MultiApp");
1220
1222 }
1223 }
1224
1225 unsigned int n_threads = numThreads();
1226
1227 // Convergence initial setup
1228 {
1229 TIME_SECTION("convergenceInitialSetup", 5, "Initializing Convergence objects");
1230
1231 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1233 }
1234
1235 // UserObject initialSetup
1236 std::set<std::string> depend_objects_ic = _ics.getDependObjects();
1237 std::set<std::string> depend_objects_aux = _aux->getDependObjects();
1238
1239 std::map<int, std::vector<UserObjectBase *>> group_userobjs;
1240
1241 // This replaces all prior updateDependObjects calls on the old user object warehouses.
1242 TheWarehouse::Query uo_query = theWarehouse().query().condition<AttribSystem>("UserObject");
1243 std::vector<UserObjectBase *> userobjs;
1244 uo_query.queryInto(userobjs);
1246 theWarehouse(), getAuxiliarySystem(), _app.getExecuteOnEnum(), userobjs, depend_objects_ic);
1247
1248 for (auto obj : userobjs)
1249 group_userobjs[obj->getParam<int>("execution_order_group")].push_back(obj);
1250
1251#ifdef MOOSE_KOKKOS_ENABLED
1252 {
1253 TheWarehouse::Query uo_query =
1254 theWarehouse().query().condition<AttribSystem>("KokkosUserObject");
1255 std::vector<UserObjectBase *> userobjs;
1256 uo_query.queryInto(userobjs);
1258 theWarehouse(), getAuxiliarySystem(), _app.getExecuteOnEnum(), userobjs, depend_objects_ic);
1259
1260 for (auto obj : userobjs)
1261 group_userobjs[obj->getParam<int>("execution_order_group")].push_back(obj);
1262 }
1263#endif
1264
1265 for (auto & [group, objs] : group_userobjs)
1266 for (auto obj : objs)
1267 obj->initialSetup();
1268
1269 // check if jacobian calculation is done in userobject
1270 for (THREAD_ID tid = 0; tid < n_threads; ++tid)
1272
1273 // Check whether nonlocal coupling is required or not
1277
1278 {
1279 TIME_SECTION("initializingFunctions", 5, "Initializing Functions");
1280
1281 // Call the initialSetup methods for functions
1282 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1283 {
1284 reinitScalars(tid); // initialize scalars so they are properly sized for use as input into
1285 // ParsedFunctions
1287 }
1288
1289#ifdef MOOSE_KOKKOS_ENABLED
1291#endif
1292 }
1293
1294 {
1295 TIME_SECTION("initializingRandomObjects", 5, "Initializing Random Objects");
1296
1297 // Random interface objects
1298 for (const auto & it : _random_data_objects)
1299 it.second->updateSeeds(EXEC_INITIAL);
1300 }
1301
1302 if (!_app.isRecovering())
1303 {
1305
1306 {
1307 TIME_SECTION("ICinitialSetup", 5, "Setting Up Initial Conditions");
1308
1309 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1310 {
1311 _ics.initialSetup(tid);
1312 _fv_ics.initialSetup(tid);
1313 }
1314
1316 }
1317
1319 }
1320
1321 // Materials
1323 {
1324 TIME_SECTION("materialInitialSetup", 3, "Setting Up Materials");
1325
1326 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1327 {
1328 // Sort the Material objects, these will be actually computed by MOOSE in reinit methods.
1329 _materials.sort(tid);
1331
1332 // Call initialSetup on all material objects
1334
1335 // Discrete materials may insert additional dependencies on materials during the initial
1336 // setup. Therefore we resolve the dependencies once more, now with the additional
1337 // dependencies due to discrete materials.
1339 {
1340 _materials.sort(tid);
1342 }
1343 }
1344
1345#ifdef MOOSE_KOKKOS_ENABLED
1346 _kokkos_materials.sort(0, true);
1347#endif
1348
1349 {
1350 TIME_SECTION("computingInitialStatefulProps", 3, "Computing Initial Material Values");
1351
1353
1357#ifdef MOOSE_KOKKOS_ENABLED
1362#endif
1363 }
1364 }
1365
1366 // setRestartInPlace() is set because the property maps have now been setup and we can
1367 // dataLoad() them directly in place
1368 // setRecovering() is set because from now on we require a one-to-one mapping of
1369 // stateful properties because we shouldn't be declaring any more
1371 {
1372 props->setRestartInPlace();
1373 props->setRecovering();
1374 }
1375
1376 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1377 {
1380 _markers.sort(tid);
1382 }
1383
1384#ifdef LIBMESH_ENABLE_AMR
1385
1387 {
1388 unsigned int n = adaptivity().getInitialSteps();
1389 if (n && !_app.isUltimateMaster() && _app.isRestarting())
1390 mooseError("Cannot perform initial adaptivity during restart on sub-apps of a MultiApp!");
1391
1393 }
1394
1395#endif // LIBMESH_ENABLE_AMR
1396
1397 if (!_app.isRecovering() && !_app.isRestarting())
1398 {
1399 // During initial setup the solution is copied to the older solution states (old, older, etc)
1401
1402 // Check if there are old state initial conditions
1403 auto ics = _ics.getActiveObjects();
1404 auto fv_ics = _fv_ics.getActiveObjects();
1405 auto scalar_ics = _scalar_ics.getActiveObjects();
1406 unsigned short ic_state_max = 0;
1407
1408 auto findMax = [&ic_state_max](const auto & obj_list)
1409 {
1410 for (auto ic : obj_list.getActiveObjects())
1411 ic_state_max = std::max(ic_state_max, ic->getState());
1412 };
1413 findMax(_ics);
1414 findMax(_fv_ics);
1415 findMax(_scalar_ics);
1416
1417 // if there are old state ICs, compute them and write to old states accordingly
1418 if (ic_state_max > 0)
1419 {
1420 // state 0 copy (we'll overwrite current state when evaluating ICs and need to restore it once
1421 // we're done with the old/older state ICs)
1422 std::vector<std::unique_ptr<NumericVector<Real>>> state0_sys_buffers(_solver_systems.size());
1423 std::unique_ptr<NumericVector<Real>> state0_aux_buffer;
1424
1425 // save state 0
1426 for (const auto i : index_range(_solver_systems))
1427 state0_sys_buffers[i] = _solver_systems[i]->solutionState(0).clone();
1428
1429 state0_aux_buffer = _aux->solutionState(0).clone();
1430
1431 // compute old state ICs
1432 for (_current_ic_state = 1; _current_ic_state <= ic_state_max; _current_ic_state++)
1433 {
1435
1436 for (auto & sys : _solver_systems)
1437 sys->solutionState(_current_ic_state) = sys->solutionState(0);
1438
1439 _aux->solutionState(_current_ic_state) = _aux->solutionState(0);
1440 }
1442
1443 // recover state 0
1444 for (const auto i : index_range(_solver_systems))
1445 {
1446 _solver_systems[i]->solutionState(0) = *state0_sys_buffers[i];
1447 _solver_systems[i]->solutionState(0).close();
1448 _solver_systems[i]->update();
1449 }
1450 _aux->solutionState(0) = *state0_aux_buffer;
1451 _aux->solutionState(0).close();
1452 _aux->update();
1453 }
1454 }
1455
1456 if (!_app.isRecovering())
1457 {
1458 if (haveXFEM())
1460 }
1461
1462 // Call initialSetup on the solver systems
1463 for (auto & sys : _solver_systems)
1464 sys->initialSetup();
1465
1466 // Auxilary variable initialSetup calls
1467 _aux->initialSetup();
1468
1470 // initialSetup for displaced systems
1471 _displaced_problem->initialSetup();
1472
1473 for (auto & sys : _solver_systems)
1474 sys->setSolution(*(sys->system().current_local_solution.get()));
1475
1476 // Update the nearest node searches (has to be called after the problem is all set up)
1477 // We do this here because this sets up the Element's DoFs to ghost
1479
1481 if (_displaced_mesh)
1483
1484 // We need to move the mesh in order to build a map between mortar secondary and primary
1485 // interfaces. This map will then be used by the AgumentSparsityOnInterface ghosting functor to
1486 // know which dofs we need ghosted when we call EquationSystems::reinit
1487 if (_displaced_problem && _mortar_data->hasDisplacedObjects())
1488 {
1489 _displaced_problem->updateMesh();
1490 // if displacements were applied to the mesh, the mortar mesh should be updated too
1492 }
1493
1494 // Possibly reinit one more time to get ghosting correct
1496
1497 if (_displaced_mesh)
1498 _displaced_problem->updateMesh();
1499
1500 updateGeomSearch(); // Call all of the rest of the geometric searches
1501
1502 for (auto & sys : _solver_systems)
1503 {
1504 const auto & tis = sys->getTimeIntegrators();
1505
1506 {
1507 TIME_SECTION("timeIntegratorInitialSetup", 5, "Initializing Time Integrator");
1508 for (auto & ti : tis)
1509 ti->initialSetup();
1510 }
1511 }
1512
1513 // HUGE NOTE: MultiApp initialSetup() MUST... I repeat MUST be _after_ main-app restartable data
1514 // has been restored
1515
1516 // Call initialSetup on the MultiApps
1517 if (_multi_apps.hasObjects())
1518 {
1519 TIME_SECTION("initialSetupMultiApps", 2, "Initializing MultiApps", false);
1520 // Assign concurrent multiapps their disjoint rank partitions before the sub-apps are created
1521 // so that each is created on the communicator it will actually run on
1524 }
1525
1526 // Call initialSetup on the transfers
1527 {
1528 TIME_SECTION("initialSetupTransfers", 2, "Initializing Transfers");
1529
1531
1532 // Call initialSetup on the MultiAppTransfers to be executed on TO_MULTIAPP
1533 const auto & to_multi_app_objects = _to_multi_app_transfers.getActiveObjects();
1534 for (const auto & transfer : to_multi_app_objects)
1535 {
1536 transfer->setCurrentDirection(Transfer::DIRECTION::TO_MULTIAPP);
1537 transfer->initialSetup();
1538 }
1539
1540 // Call initialSetup on the MultiAppTransfers to be executed on FROM_MULTIAPP
1541 const auto & from_multi_app_objects = _from_multi_app_transfers.getActiveObjects();
1542 for (const auto & transfer : from_multi_app_objects)
1543 {
1544 transfer->setCurrentDirection(Transfer::DIRECTION::FROM_MULTIAPP);
1545 transfer->initialSetup();
1546 }
1547
1548 // Call initialSetup on the MultiAppTransfers to be executed on BETWEEN_MULTIAPP
1549 const auto & between_multi_app_objects = _between_multi_app_transfers.getActiveObjects();
1550 for (const auto & transfer : between_multi_app_objects)
1551 {
1552 transfer->setCurrentDirection(Transfer::DIRECTION::BETWEEN_MULTIAPP);
1553 transfer->initialSetup();
1554 }
1555 }
1556
1558 {
1559 TIME_SECTION("BoundaryRestrictedNodeIntegrityCheck", 5);
1560
1561 // check that variables are defined along boundaries of boundary restricted nodal objects
1562 const auto & bnd_nodes = getCurrentAlgebraicBndNodeRange();
1563 BoundaryNodeIntegrityCheckThread bnict(*this, uo_query);
1564 Threads::parallel_reduce(bnd_nodes, bnict, numThreads());
1565
1566 // Nodal bcs aren't threaded
1567 for (auto & nl : _nl)
1568 {
1569 const auto & nodal_bcs = nl->getNodalBCWarehouse();
1570 if (!nodal_bcs.hasBoundaryObjects())
1571 continue;
1572
1573 for (const auto & bnode : bnd_nodes)
1574 {
1575 const auto boundary_id = bnode->_bnd_id;
1576 const Node * const node = bnode->_node;
1577
1578 if (node->processor_id() != this->processor_id())
1579 continue;
1580
1581 const auto & bnd_name = _mesh.getBoundaryName(boundary_id);
1582
1583 // Avoid assertion in getBoundaryObjects that we have boundary objects for this boundary ID
1584 if (!nodal_bcs.hasBoundaryObjects(boundary_id))
1585 continue;
1586
1587 const auto & bnd_objects = nodal_bcs.getBoundaryObjects(boundary_id);
1588 for (const auto & bnd_object : bnd_objects)
1589 {
1590 const auto & bnd_variable = bnd_object->variable();
1591 // Skip if this object uses geometric search because coupled variables may be defined on
1592 // paired boundaries instead of the boundary this node is on. Also skip if this boundary
1593 // condition isn't applicable to the current node, e.g. if the node doesn't have any
1594 // degrees of freedom for the boundary condition's variable
1595 if (!bnd_object->requiresGeometricSearch() &&
1596 bnd_object->checkVariableBoundaryIntegrity() &&
1597 node->n_dofs(nl->number(), bnd_variable.number()))
1598 {
1599 std::set<MooseVariableFieldBase *> vars_to_omit = {
1600 &cast_ref<MooseVariableFieldBase &>(const_cast<MooseVariableBase &>(bnd_variable))};
1601
1603 *bnd_object, bnd_object->checkAllVariables(*node, vars_to_omit), bnd_name);
1604 }
1605 }
1606 }
1607 }
1608 }
1609
1611 {
1612 TIME_SECTION("BoundaryRestrictedElemIntegrityCheck", 5);
1613
1614 // check that variables are defined along boundaries of boundary restricted elemental objects
1616 BoundaryElemIntegrityCheckThread beict(*this, uo_query);
1617 Threads::parallel_reduce(bnd_elems, beict, numThreads());
1618 }
1619
1621 {
1622 TIME_SECTION("InterfaceKernelIntegrityCheck", 5);
1623
1624 // Interface kernels skip any face where 'variable' is not active on the primary (element)
1625 // side or 'neighbor_var' is not active on the secondary (neighbor) side, so a kernel whose
1626 // variables do not match the sideset orientation silently contributes nothing.
1627 // A boundary may join several block pairs, and the kernel is skipped on the faces of every
1628 // pair that does not carry both variables, so each pair is checked. A face that is also on
1629 // the boundary from its neighbor's side (e.g. sidesets read from Gmsh lower-dimensional
1630 // elements) is visited in both orientations, and is covered if either orientation is valid.
1631 // Each entry is (boundary, element block, neighbor block, whether the face is two-sided),
1632 // with the flag stored as an integer because TIMPI cannot communicate bool.
1633 std::set<std::tuple<BoundaryID, SubdomainID, SubdomainID, unsigned short>> face_block_pairs;
1634 const auto & boundary_info = _mesh.getMesh().get_boundary_info();
1635 for (const auto & bnd_elem : *_mesh.getBoundaryElementRange())
1636 // A remote neighbor is paired by the processor that holds both elements
1637 if (const auto * const neighbor = bnd_elem->_elem->neighbor_ptr(bnd_elem->_side);
1638 neighbor && neighbor != libMesh::remote_elem)
1639 face_block_pairs.emplace(
1640 bnd_elem->_bnd_id,
1641 bnd_elem->_elem->subdomain_id(),
1642 neighbor->subdomain_id(),
1643 boundary_info.has_boundary_id(
1644 neighbor, neighbor->which_neighbor_am_i(bnd_elem->_elem), bnd_elem->_bnd_id));
1645 _communicator.set_union(face_block_pairs);
1646
1647 for (const auto & nl : _nl)
1648 for (const auto & ik : nl->getInterfaceKernelWarehouse().getObjects())
1649 for (const auto bnd_id : ik->boundaryIDs())
1650 {
1651 const auto & var = ik->variable();
1652 const auto & neighbor_var = ik->neighborVariable();
1653 const auto block_name = [this](const SubdomainID blk)
1654 {
1655 const auto & name = _mesh.getSubdomainName(blk);
1656 return name.empty() ? std::to_string(blk) : name;
1657 };
1658
1659 // Whether the kernel executes on faces with 'elem_var' on the element side and
1660 // 'neigh_var' on the neighbor side
1661 const auto valid = [](const auto & elem_var,
1662 const auto & neigh_var,
1663 const SubdomainID elem_blk,
1664 const SubdomainID neighbor_blk)
1665 {
1666 return elem_var.activeOnSubdomain(elem_blk) &&
1667 neigh_var.activeOnSubdomain(neighbor_blk);
1668 };
1669
1670 // Block pairs of the boundary on whose faces the kernel never executes, the subset of
1671 // those that swapping the variables would cover, and whether swapping the variables
1672 // would cover every face of the boundary. A boundary without neighbors has no pairs; it
1673 // is reported as an external side during assembly.
1674 std::vector<std::string> failing_pairs;
1675 std::vector<std::string> flipped_pairs;
1676 bool all_flipped = true;
1677 for (const auto & [bid, elem_blk, neighbor_blk, two_sided] : face_block_pairs)
1678 if (bid == bnd_id)
1679 {
1680 const bool flipped_valid =
1681 valid(neighbor_var, var, elem_blk, neighbor_blk) ||
1682 (two_sided && valid(neighbor_var, var, neighbor_blk, elem_blk));
1683 if (!flipped_valid)
1684 all_flipped = false;
1685 if (!valid(var, neighbor_var, elem_blk, neighbor_blk) &&
1686 !(two_sided && valid(var, neighbor_var, neighbor_blk, elem_blk)))
1687 {
1688 const auto pair_name = block_name(elem_blk) + " -> " + block_name(neighbor_blk);
1689 failing_pairs.push_back(pair_name);
1690 if (flipped_valid)
1691 flipped_pairs.push_back(pair_name);
1692 }
1693 }
1694 if (failing_pairs.empty())
1695 continue;
1696
1697 std::string flipped_hint;
1698 if (!flipped_pairs.empty())
1699 flipped_hint =
1700 "\nThe variables appear to be flipped relative to the boundary "
1701 "orientation on block pair(s) " +
1702 MooseUtils::join(flipped_pairs, ", ") +
1703 (all_flipped ? "; swap 'variable' and 'neighbor_var', or reverse the "
1704 "orientation of the boundary."
1705 : "; reverse the orientation of the boundary on those pairs.");
1706
1707 ik->paramError(
1708 "boundary",
1709 "The interface kernel will not contribute on all or part of boundary '",
1710 _mesh.getBoundaryName(bnd_id),
1711 "': 'variable' (",
1712 var.name(),
1713 ") must be defined on the primary (element) side and 'neighbor_var' (",
1714 neighbor_var.name(),
1715 ") on the secondary (neighbor) side of each face. Failing block pair(s) (primary -> "
1716 "secondary): ",
1717 MooseUtils::join(failing_pairs, ", "),
1718 ".",
1719 flipped_hint);
1720 }
1721 }
1722
1724 {
1725 TIME_SECTION("FVFaceIntegrityCheck", 5);
1726
1727 auto check_fv_face_integrity = [this](MooseMesh & fv_mesh, const bool on_displaced)
1728 {
1729 auto flux_bc_base_query = theWarehouse()
1730 .query()
1731 .condition<AttribSystem>("FVFluxBC")
1732 .condition<AttribDisplaced>(on_displaced)
1733 .condition<AttribThread>(0);
1734 TheWarehouse::QueryCache<AttribBoundaries> flux_bc_query(flux_bc_base_query);
1735
1736 auto interface_kernel_base_query = theWarehouse()
1737 .query()
1738 .condition<AttribSystem>("FVInterfaceKernel")
1739 .condition<AttribDisplaced>(on_displaced)
1740 .condition<AttribThread>(0);
1741 TheWarehouse::QueryCache<AttribBoundaries> interface_kernel_query(
1742 interface_kernel_base_query);
1743
1744 std::vector<FVFluxBC *> flux_bcs;
1745 std::vector<FVInterfaceKernel *> interface_kernels;
1746
1747 for (auto face_it = fv_mesh.ownedFaceInfoBegin(); face_it != fv_mesh.ownedFaceInfoEnd();
1748 ++face_it)
1749 {
1750 const FaceInfo & fi = **face_it;
1751
1752 for (const auto boundary_id : fi.boundaryIDs())
1753 {
1754 auto boundary_key = std::make_tuple(boundary_id, false);
1755
1756 flux_bc_query.queryInto(flux_bcs, boundary_key);
1757 for (const auto * const flux_bc : flux_bcs)
1758 if (flux_bc->checkVariableBoundaryIntegrity())
1759 flux_bc->checkFaceIntegrity(fi);
1760
1761 interface_kernel_query.queryInto(interface_kernels, boundary_key);
1762 for (const auto * const interface_kernel : interface_kernels)
1763 interface_kernel->checkFaceIntegrity(fi);
1764 }
1765 }
1766 };
1767
1768 if (haveFV())
1769 check_fv_face_integrity(mesh(), false);
1770
1771 if (_displaced_problem && _displaced_problem->haveFV())
1772 check_fv_face_integrity(_displaced_problem->mesh(), true);
1773 }
1774
1775 if (!_app.isRecovering())
1776 {
1778 if (!converged)
1779 mooseError("failed to converge initial MultiApp");
1780
1781 // We'll backup the Multiapp here
1783
1784 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1785 reinitScalars(tid);
1786
1788
1789 // The FEProblemBase::execute method doesn't call all the systems on EXEC_INITIAL, but it does
1790 // set/unset the current flag. Therefore, this resets the current flag to EXEC_INITIAL so that
1791 // subsequent calls (e.g., executeControls) have the proper flag.
1793 }
1794
1795 // Here we will initialize the stateful properties once more since they may have been updated
1796 // during initialSetup by calls to computeProperties.
1797 //
1798 // It's really bad that we don't allow this during restart. It means that we can't add new
1799 // stateful materials
1800 // during restart. This is only happening because this _has_ to be below initial userobject
1801 // execution.
1802 // Otherwise this could be done up above... _before_ restoring restartable data... which would
1803 // allow you to have
1804 // this happen during restart. I honestly have no idea why this has to happen after initial user
1805 // object computation.
1806 // THAT is something we should fix... so I've opened this ticket: #5804
1807 if (!_app.isRecovering() && !_app.isRestarting())
1808 {
1811 {
1812 TIME_SECTION("computeMaterials", 2, "Computing Initial Material Properties");
1813
1815 }
1816#ifdef MOOSE_KOKKOS_ENABLED
1820 {
1821 TIME_SECTION("computeMaterials", 2, "Computing Initial Material Properties");
1822
1824 }
1825#endif
1826 }
1827
1828 // Control Logic
1831
1832 // Scalar variables need to reinited for the initial conditions to be available for output
1833 for (unsigned int tid = 0; tid < n_threads; tid++)
1834 reinitScalars(tid);
1835
1836 if (_displaced_mesh)
1837 _displaced_problem->syncSolutions();
1838
1839 // Writes all calls to _console from initialSetup() methods
1841
1843 {
1845 for (THREAD_ID tid = 0; tid < n_threads; ++tid)
1846 for (auto & assembly : _assembly[tid])
1847 assembly->initNonlocalCoupling();
1848 }
1849
1850 {
1851 TIME_SECTION("lineSearchInitialSetup", 5, "Initializing Line Search");
1852
1853 if (_line_search)
1854 _line_search->initialSetup();
1855 }
1856
1857 // Perform Reporter get/declare check
1859
1860 // We do this late to allow objects to get late restartable data
1863
1865}
1866
1867void
1869{
1870 for (const auto & pp : _reporter_data.getPostprocessorNames())
1871 if (hasScalarVariable(pp))
1872 mooseError("Postprocessor \"" + pp +
1873 "\" has the same name as a scalar variable in the system.");
1874}
1875
1876void
1878{
1880
1881 if (_t_step > 1 && _num_grid_steps)
1882 {
1883 libMesh::MeshRefinement mesh_refinement(_mesh);
1884 std::unique_ptr<libMesh::MeshRefinement> displaced_mesh_refinement(nullptr);
1885 if (_displaced_mesh)
1886 displaced_mesh_refinement = std::make_unique<libMesh::MeshRefinement>(*_displaced_mesh);
1887
1888 for (MooseIndex(_num_grid_steps) i = 0; i < _num_grid_steps; ++i)
1889 {
1891 // If the DisplacedProblem is active, undisplace the DisplacedMesh in preparation for
1892 // refinement. We can't safely refine the DisplacedMesh directly, since the Hilbert keys
1893 // computed on the inconsistenly-displaced Mesh are different on different processors,
1894 // leading to inconsistent Hilbert keys. We must do this before the undisplaced Mesh is
1895 // coarsensed, so that the element and node numbering is still consistent. We also have to
1896 // make sure this is done during every step of coarsening otherwise different partitions
1897 // will be generated for the reference and displaced meshes (even for replicated)
1898 _displaced_problem->undisplaceMesh();
1899
1900 mesh_refinement.uniformly_coarsen();
1901 if (_displaced_mesh)
1902 displaced_mesh_refinement->uniformly_coarsen();
1903
1904 // Mark this as an intermediate change because we do not yet want to reinit_systems. E.g. we
1905 // need things to happen in the following order for the undisplaced problem:
1906 // u1) EquationSystems::reinit_solutions. This will restrict the solution vectors and then
1907 // contract the mesh
1908 // u2) MooseMesh::meshChanged. This will update the node/side lists and other
1909 // things which needs to happen after the contraction
1910 // u3) GeometricSearchData::reinit. Once the node/side lists are updated we can perform our
1911 // geometric searches which will aid in determining sparsity patterns
1912 //
1913 // We do these things for the displaced problem (if it exists)
1914 // d1) EquationSystems::reinit. Restrict the displaced problem vector copies and then contract
1915 // the mesh. It's safe to do a full reinit with the displaced because there are no
1916 // matrices that sparsity pattern calculations will be conducted for
1917 // d2) MooseMesh::meshChanged. This will update the node/side lists and other
1918 // things which needs to happen after the contraction
1919 // d3) UpdateDisplacedMeshThread::operator(). Re-displace the mesh using the *displaced*
1920 // solution vector copy because we don't know the state of the reference solution vector.
1921 // It's safe to use the displaced copy because we are outside of a non-linear solve,
1922 // and there is no concern about differences between solution and current_local_solution
1923 // d4) GeometricSearchData::reinit. With the node/side lists updated and the mesh
1924 // re-displaced, we can perform our geometric searches, which will aid in determining the
1925 // sparsity pattern of the matrix held by the libMesh::ImplicitSystem held by the
1926 // NonlinearSystem held by this
1928 /*intermediate_change=*/true, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
1929 }
1930
1931 // u4) Now that all the geometric searches have been done (both undisplaced and displaced),
1932 // we're ready to update the sparsity pattern
1933 es().reinit_systems();
1934 }
1935
1937 if (_line_search)
1938 _line_search->timestepSetup();
1939
1940 // Random interface objects
1941 for (const auto & it : _random_data_objects)
1942 it.second->updateSeeds(EXEC_TIMESTEP_BEGIN);
1943
1944 unsigned int n_threads = numThreads();
1945 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1946 {
1949 }
1950
1951#ifdef MOOSE_KOKKOS_ENABLED
1953#endif
1954
1955 _aux->timestepSetup();
1956 for (auto & sys : _solver_systems)
1957 sys->timestepSetup();
1958
1960 // timestepSetup for displaced systems
1961 _displaced_problem->timestepSetup();
1962
1963 for (THREAD_ID tid = 0; tid < n_threads; tid++)
1964 {
1968 }
1969
1970 std::vector<UserObject *> userobjs;
1971 theWarehouse().query().condition<AttribSystem>("UserObject").queryIntoUnsorted(userobjs);
1972 for (auto obj : userobjs)
1973 obj->timestepSetup();
1974
1975#ifdef MOOSE_KOKKOS_ENABLED
1976 {
1977 std::vector<UserObjectBase *> userobjs;
1978 theWarehouse().query().condition<AttribSystem>("KokkosUserObject").queryIntoUnsorted(userobjs);
1979 for (auto obj : userobjs)
1980 obj->timestepSetup();
1981 }
1982#endif
1983
1984 // Timestep setup of output objects
1986
1990}
1991
1992unsigned int
1994{
1995 if (_max_qps == std::numeric_limits<unsigned int>::max())
1996 mooseError("Max QPS uninitialized");
1997 return _max_qps;
1998}
1999
2000Order
2005
2006void
2008{
2009 TIME_SECTION("checkNonlocalCoupling", 5, "Checking Nonlocal Coupling");
2010
2011 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
2012 for (auto & nl : _nl)
2013 {
2014 const auto & all_kernels = nl->getKernelWarehouse();
2015 const auto & kernels = all_kernels.getObjects(tid);
2016 for (const auto & kernel : kernels)
2017 {
2018 std::shared_ptr<NonlocalKernel> nonlocal_kernel =
2019 std::dynamic_pointer_cast<NonlocalKernel>(kernel);
2020 if (nonlocal_kernel)
2021 {
2024 _nonlocal_kernels.addObject(kernel, tid);
2025 }
2026 }
2027 const MooseObjectWarehouse<IntegratedBCBase> & all_integrated_bcs =
2028 nl->getIntegratedBCWarehouse();
2029 const auto & integrated_bcs = all_integrated_bcs.getObjects(tid);
2030 for (const auto & integrated_bc : integrated_bcs)
2031 {
2032 std::shared_ptr<NonlocalIntegratedBC> nonlocal_integrated_bc =
2033 std::dynamic_pointer_cast<NonlocalIntegratedBC>(integrated_bc);
2034 if (nonlocal_integrated_bc)
2035 {
2038 _nonlocal_integrated_bcs.addObject(integrated_bc, tid);
2039 }
2040 }
2041 }
2042}
2043
2044void
2046{
2047 std::set<const MooseVariableFEBase *> uo_jacobian_moose_vars;
2048 {
2049 std::vector<ShapeElementUserObject *> objs;
2050 theWarehouse()
2051 .query()
2053 .condition<AttribThread>(tid)
2054 .queryInto(objs);
2055
2056 for (const auto & uo : objs)
2057 {
2058 _calculate_jacobian_in_uo = uo->computeJacobianFlag();
2059 const auto & mv_deps = uo->jacobianMooseVariables();
2060 uo_jacobian_moose_vars.insert(mv_deps.begin(), mv_deps.end());
2061 }
2062 }
2063 {
2064 std::vector<ShapeSideUserObject *> objs;
2065 theWarehouse()
2066 .query()
2068 .condition<AttribThread>(tid)
2069 .queryInto(objs);
2070 for (const auto & uo : objs)
2071 {
2072 _calculate_jacobian_in_uo = uo->computeJacobianFlag();
2073 const auto & mv_deps = uo->jacobianMooseVariables();
2074 uo_jacobian_moose_vars.insert(mv_deps.begin(), mv_deps.end());
2075 }
2076 }
2077
2078 _uo_jacobian_moose_vars[tid].assign(uo_jacobian_moose_vars.begin(), uo_jacobian_moose_vars.end());
2079 std::sort(
2080 _uo_jacobian_moose_vars[tid].begin(), _uo_jacobian_moose_vars[tid].end(), sortMooseVariables);
2081}
2082
2083void
2084FEProblemBase::setVariableAllDoFMap(const std::vector<const MooseVariableFEBase *> & moose_vars)
2085{
2086 for (unsigned int i = 0; i < moose_vars.size(); ++i)
2087 {
2088 VariableName var_name = moose_vars[i]->name();
2089 auto & sys = _solver_systems[moose_vars[i]->sys().number()];
2090 sys->setVariableGlobalDoFs(var_name);
2091 _var_dof_map[var_name] = sys->getVariableGlobalDoFs();
2092 }
2093}
2094
2095void
2096FEProblemBase::prepare(const Elem * elem, const THREAD_ID tid)
2097{
2098 for (const auto i : index_range(_solver_systems))
2099 {
2100 _assembly[tid][i]->reinit(elem);
2101 _solver_systems[i]->prepare(tid);
2102
2103 if (i < _num_nl_sys)
2104 {
2105 // This method is called outside of residual/Jacobian callbacks during initial condition
2106 // evaluation
2108 _assembly[tid][i]->prepareJacobianBlock();
2109 _assembly[tid][i]->prepareResidual();
2111 _assembly[tid][i]->prepareNonlocal();
2112 }
2113 }
2114 _aux->prepare(tid);
2115
2116 if (_displaced_problem &&
2117 // _reinit_displaced_neighbor applies to interface type objects which will do computations
2118 // based on both elem and neighbor. Consequently, despite what you might think by its name, we
2119 // must make sure we prepare the displaced elem
2121 {
2122 _displaced_problem->prepare(_displaced_mesh->elemPtr(elem->id()), tid);
2124 _displaced_problem->prepareNonlocal(tid);
2125 }
2126}
2127
2128void
2129FEProblemBase::prepareFace(const Elem * elem, const THREAD_ID tid)
2130{
2131 for (auto & nl : _nl)
2132 nl->prepareFace(tid, true);
2133 _aux->prepareFace(tid, false);
2134
2136 _displaced_problem->prepareFace(_displaced_mesh->elemPtr(elem->id()), tid);
2137}
2138
2139void
2140FEProblemBase::prepare(const Elem * elem,
2141 unsigned int ivar,
2142 unsigned int jvar,
2143 const std::vector<dof_id_type> & dof_indices,
2144 const THREAD_ID tid)
2145{
2146 for (const auto i : index_range(_nl))
2147 {
2148 _assembly[tid][i]->reinit(elem);
2149 _nl[i]->prepare(tid);
2150 }
2151
2152 _aux->prepare(tid);
2153 const auto current_nl_sys_num = _current_nl_sys->number();
2154 _assembly[tid][current_nl_sys_num]->prepareBlock(ivar, jvar, dof_indices);
2156 if (_nonlocal_cm[current_nl_sys_num](ivar, jvar) != 0)
2157 {
2159 _assembly[tid][current_nl_sys_num]->prepareBlockNonlocal(
2160 ivar, jvar, dof_indices, jv.allDofIndices());
2161 }
2162
2164 {
2165 _displaced_problem->prepare(_displaced_mesh->elemPtr(elem->id()), ivar, jvar, dof_indices, tid);
2167 if (_nonlocal_cm[current_nl_sys_num](ivar, jvar) != 0)
2168 {
2170 _displaced_problem->prepareBlockNonlocal(ivar, jvar, dof_indices, jv.allDofIndices(), tid);
2171 }
2172 }
2173}
2174
2175void
2177{
2178 SubdomainID did = elem->subdomain_id();
2179 for (const auto i : index_range(_solver_systems))
2180 {
2181 _assembly[tid][i]->setCurrentSubdomainID(did);
2182 if (_displaced_problem &&
2184 _displaced_problem->assembly(tid, i).setCurrentSubdomainID(did);
2185 }
2186}
2187
2188void
2189FEProblemBase::setNeighborSubdomainID(const Elem * elem, unsigned int side, const THREAD_ID tid)
2190{
2191 SubdomainID did = elem->neighbor_ptr(side)->subdomain_id();
2192 for (const auto i : index_range(_nl))
2193 {
2194 _assembly[tid][i]->setCurrentNeighborSubdomainID(did);
2195 if (_displaced_problem &&
2197 _displaced_problem->assembly(tid, i).setCurrentNeighborSubdomainID(did);
2198 }
2199}
2200
2201void
2203{
2204 SubdomainID did = elem->subdomain_id();
2205 for (const auto i : index_range(_nl))
2206 {
2207 _assembly[tid][i]->setCurrentNeighborSubdomainID(did);
2208 if (_displaced_problem &&
2210 _displaced_problem->assembly(tid, i).setCurrentNeighborSubdomainID(did);
2211 }
2212}
2213
2214void
2216{
2219 _assembly[tid][_current_nl_sys->number()]->prepareNonlocal();
2220
2221 if (_displaced_problem &&
2223 {
2224 _displaced_problem->prepareAssembly(tid);
2226 _displaced_problem->prepareNonlocal(tid);
2227 }
2228}
2229
2230void
2232{
2233 _assembly[tid][_current_nl_sys->number()]->prepareNeighbor();
2234
2236 _displaced_problem->prepareAssemblyNeighbor(tid);
2237}
2238
2239void
2241{
2244
2246 _displaced_problem->addResidual(tid);
2247}
2248
2249void
2251{
2252 _assembly[tid][_current_nl_sys->number()]->addResidualNeighbor(Assembly::GlobalDataKey{},
2254
2256 _displaced_problem->addResidualNeighbor(tid);
2257}
2258
2259void
2261{
2262 _assembly[tid][_current_nl_sys->number()]->addResidualLower(Assembly::GlobalDataKey{},
2264
2266 _displaced_problem->addResidualLower(tid);
2267}
2268
2269void
2271{
2272 _assembly[tid][_current_nl_sys->number()]->addResidualScalar(Assembly::GlobalDataKey{},
2274}
2275
2276void
2278{
2281 _displaced_problem->cacheResidual(tid);
2282}
2283
2284void
2286{
2289 _displaced_problem->cacheResidualNeighbor(tid);
2290}
2291
2292void
2294{
2297 _displaced_problem->addCachedResidual(tid);
2298}
2299
2300void
2301FEProblemBase::addCachedResidualDirectly(NumericVector<Number> & residual, const THREAD_ID tid)
2302{
2304 _assembly[tid][_current_nl_sys->number()]->addCachedResidualDirectly(
2306
2308 _assembly[tid][_current_nl_sys->number()]->addCachedResidualDirectly(
2310
2311 std::vector<VectorTag> extra_residual_vector_tags;
2312 extra_residual_vector_tags.reserve(currentResidualVectorTags().size());
2313 const auto time_tag = _current_nl_sys->timeVectorTag();
2314 const auto non_time_tag = _current_nl_sys->nonTimeVectorTag();
2315 for (const auto & vector_tag : currentResidualVectorTags())
2316 if (vector_tag._id != time_tag && vector_tag._id != non_time_tag)
2317 extra_residual_vector_tags.push_back(vector_tag);
2318
2319 // Flush extra vector tag caches (e.g. from extra_vector_tags on NodalConstraints)
2320 // to their respective system vectors after the standard TIME/NONTIME caches above.
2321 // Without this, NodalConstraint contributions to extra vector tags are silently
2322 // discarded by the blanket clearCachedResiduals.
2323 _assembly[tid][_current_nl_sys->number()]->addCachedResiduals(Assembly::GlobalDataKey{},
2324 extra_residual_vector_tags);
2325
2326 // We do this because by adding the cached residual directly, we cannot ensure that all of the
2327 // cached residuals are emptied after only the two add calls above
2328 _assembly[tid][_current_nl_sys->number()]->clearCachedResiduals(Assembly::GlobalDataKey{});
2329
2331 _displaced_problem->addCachedResidualDirectly(residual, tid);
2332}
2333
2334void
2335FEProblemBase::setResidual(NumericVector<Number> & residual, const THREAD_ID tid)
2336{
2337 _assembly[tid][_current_nl_sys->number()]->setResidual(
2338 residual,
2340 getVectorTag(_nl[_current_nl_sys->number()]->residualVectorTag()));
2342 _displaced_problem->setResidual(residual, tid);
2343}
2344
2345void
2346FEProblemBase::setResidualNeighbor(NumericVector<Number> & residual, const THREAD_ID tid)
2347{
2348 _assembly[tid][_current_nl_sys->number()]->setResidualNeighbor(
2351 _displaced_problem->setResidualNeighbor(residual, tid);
2352}
2353
2354void
2356{
2359 _assembly[tid][_current_nl_sys->number()]->addJacobianNonlocal(Assembly::GlobalDataKey{});
2361 {
2362 _displaced_problem->addJacobian(tid);
2364 _displaced_problem->addJacobianNonlocal(tid);
2365 }
2366}
2367
2368void
2370{
2371 _assembly[tid][_current_nl_sys->number()]->addJacobianNeighbor(Assembly::GlobalDataKey{});
2373 _displaced_problem->addJacobianNeighbor(tid);
2374}
2375
2376void
2378{
2379 _assembly[tid][_current_nl_sys->number()]->addJacobianNeighborLowerD(Assembly::GlobalDataKey{});
2381 _displaced_problem->addJacobianNeighborLowerD(tid);
2382}
2383
2384void
2386{
2387 _assembly[tid][_current_nl_sys->number()]->addJacobianLowerD(Assembly::GlobalDataKey{});
2389 _displaced_problem->addJacobianLowerD(tid);
2390}
2391
2392void
2394{
2395 _assembly[tid][_current_nl_sys->number()]->addJacobianScalar(Assembly::GlobalDataKey{});
2396}
2397
2398void
2399FEProblemBase::addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid /* = 0*/)
2400{
2401 _assembly[tid][_current_nl_sys->number()]->addJacobianOffDiagScalar(ivar,
2403}
2404
2405void
2407{
2410 _displaced_problem->cacheJacobian(tid);
2411}
2412
2413void
2415{
2418 _displaced_problem->cacheJacobianNeighbor(tid);
2419}
2420
2421void
2423{
2426 _displaced_problem->addCachedJacobian(tid);
2427}
2428
2429void
2430FEProblemBase::addJacobianBlockTags(SparseMatrix<Number> & jacobian,
2431 unsigned int ivar,
2432 unsigned int jvar,
2433 const DofMap & dof_map,
2434 std::vector<dof_id_type> & dof_indices,
2435 const std::set<TagID> & tags,
2436 const THREAD_ID tid)
2437{
2438 _assembly[tid][_current_nl_sys->number()]->addJacobianBlockTags(
2439 jacobian, ivar, jvar, dof_map, dof_indices, Assembly::GlobalDataKey{}, tags);
2440
2442 if (_nonlocal_cm[_current_nl_sys->number()](ivar, jvar) != 0)
2443 {
2445 _assembly[tid][_current_nl_sys->number()]->addJacobianBlockNonlocalTags(
2446 jacobian,
2447 ivar,
2448 jvar,
2449 dof_map,
2450 dof_indices,
2451 jv.allDofIndices(),
2453 tags);
2454 }
2455
2457 {
2458 _displaced_problem->addJacobianBlockTags(jacobian, ivar, jvar, dof_map, dof_indices, tags, tid);
2460 if (_nonlocal_cm[_current_nl_sys->number()](ivar, jvar) != 0)
2461 {
2463 _displaced_problem->addJacobianBlockNonlocal(
2464 jacobian, ivar, jvar, dof_map, dof_indices, jv.allDofIndices(), tags, tid);
2465 }
2466 }
2467}
2468
2469void
2470FEProblemBase::addJacobianNeighbor(SparseMatrix<Number> & jacobian,
2471 unsigned int ivar,
2472 unsigned int jvar,
2473 const DofMap & dof_map,
2474 std::vector<dof_id_type> & dof_indices,
2475 std::vector<dof_id_type> & neighbor_dof_indices,
2476 const std::set<TagID> & tags,
2477 const THREAD_ID tid)
2478{
2479 _assembly[tid][_current_nl_sys->number()]->addJacobianNeighborTags(jacobian,
2480 ivar,
2481 jvar,
2482 dof_map,
2483 dof_indices,
2484 neighbor_dof_indices,
2486 tags);
2488 _displaced_problem->addJacobianNeighbor(
2489 jacobian, ivar, jvar, dof_map, dof_indices, neighbor_dof_indices, tags, tid);
2490}
2491
2492void
2493FEProblemBase::prepareShapes(unsigned int var, const THREAD_ID tid)
2494{
2495 _assembly[tid][_current_nl_sys->number()]->copyShapes(var);
2496}
2497
2498void
2500{
2501 _assembly[tid][_current_nl_sys->number()]->copyFaceShapes(var);
2502}
2503
2504void
2506{
2507 _assembly[tid][_current_nl_sys->number()]->copyNeighborShapes(var);
2508}
2509
2510void
2512{
2513 if (_mesh.elemPtr(elem_id)->processor_id() != processor_id())
2514 _ghosted_elems.insert(elem_id);
2515}
2516
2517void
2524
2525void
2527{
2528 TIME_SECTION("ghostGhostedBoundaries", 3, "Ghosting Ghosted Boundaries");
2529
2531
2534}
2535
2536void
2537FEProblemBase::sizeZeroes(unsigned int /*size*/, const THREAD_ID /*tid*/)
2538{
2539 mooseDoOnce(mooseWarning(
2540 "This function is deprecated and no longer performs any function. Please do not call it."));
2541}
2542
2543bool
2544FEProblemBase::reinitDirac(const Elem * elem, const THREAD_ID tid)
2545{
2546 std::vector<Point> & points = _dirac_kernel_info.getPoints()[elem].first;
2547
2548 unsigned int n_points = points.size();
2549
2550 if (n_points)
2551 {
2552 if (n_points > _max_qps)
2553 {
2554 _max_qps = n_points;
2555
2560 unsigned int max_qpts = getMaxQps();
2561 for (unsigned int tid = 0; tid < numThreads(); ++tid)
2562 {
2563 // the highest available order in libMesh is 43
2564 _scalar_zero[tid].resize(libMesh::FORTYTHIRD, 0);
2565 _zero[tid].resize(max_qpts, 0);
2566 _grad_zero[tid].resize(max_qpts, RealGradient(0.));
2567 _second_zero[tid].resize(max_qpts, RealTensor(0.));
2568 _vector_zero[tid].resize(max_qpts, RealGradient(0.));
2569 _vector_curl_zero[tid].resize(max_qpts, RealGradient(0.));
2570 }
2571 }
2572
2573 for (const auto i : index_range(_nl))
2574 {
2575 _assembly[tid][i]->reinitAtPhysical(elem, points);
2576 _nl[i]->prepare(tid);
2577 }
2578 _aux->prepare(tid);
2579
2580 reinitElem(elem, tid);
2581 }
2582
2583 _assembly[tid][_current_nl_sys->number()]->prepare();
2585 _assembly[tid][_current_nl_sys->number()]->prepareNonlocal();
2586
2587 bool have_points = n_points > 0;
2589 {
2590 have_points |= _displaced_problem->reinitDirac(_displaced_mesh->elemPtr(elem->id()), tid);
2592 _displaced_problem->prepareNonlocal(tid);
2593 }
2594
2595 return have_points;
2596}
2597
2598void
2599FEProblemBase::reinitElem(const Elem * elem, const THREAD_ID tid)
2600{
2601 for (auto & sys : _solver_systems)
2602 sys->reinitElem(elem, tid);
2603 _aux->reinitElem(elem, tid);
2604
2606 _displaced_problem->reinitElem(_displaced_mesh->elemPtr(elem->id()), tid);
2607}
2608
2609void
2610FEProblemBase::reinitElemPhys(const Elem * const elem,
2611 const std::vector<Point> & phys_points_in_elem,
2612 const THREAD_ID tid)
2613{
2614 mooseAssert(_mesh.queryElemPtr(elem->id()) == elem,
2615 "Are you calling this method with a displaced mesh element?");
2616
2617 for (const auto i : index_range(_solver_systems))
2618 {
2619 _assembly[tid][i]->reinitAtPhysical(elem, phys_points_in_elem);
2620 _solver_systems[i]->prepare(tid);
2621 _assembly[tid][i]->prepare();
2623 _assembly[tid][i]->prepareNonlocal();
2624 }
2625 _aux->prepare(tid);
2626
2627 reinitElem(elem, tid);
2628}
2629
2630void
2631FEProblemBase::reinitElemFace(const Elem * const elem,
2632 const unsigned int side,
2633 const BoundaryID,
2634 const THREAD_ID tid)
2635{
2637 "reinitElemFace with a BoundaryID argument is deprecated because the boundary id was never "
2638 "used. Please call reinitElemFace without the BoundaryID argument instead");
2639
2640 reinitElemFace(elem, side, tid);
2641}
2642
2643void
2644FEProblemBase::reinitElemFace(const Elem * const elem, const unsigned int side, const THREAD_ID tid)
2645{
2646 for (const auto i : index_range(_solver_systems))
2647 {
2648 _assembly[tid][i]->reinit(elem, side);
2649 _solver_systems[i]->reinitElemFace(elem, side, tid);
2650 }
2651 _aux->reinitElemFace(elem, side, tid);
2652
2654 _displaced_problem->reinitElemFace(_displaced_mesh->elemPtr(elem->id()), side, tid);
2655}
2656
2657void
2658FEProblemBase::reinitLowerDElem(const Elem * lower_d_elem,
2659 const THREAD_ID tid,
2660 const std::vector<Point> * const pts,
2661 const std::vector<Real> * const weights)
2662{
2663 SubProblem::reinitLowerDElem(lower_d_elem, tid, pts, weights);
2664
2666 _displaced_problem->reinitLowerDElem(
2667 _displaced_mesh->elemPtr(lower_d_elem->id()), tid, pts, weights);
2668}
2669
2670void
2671FEProblemBase::reinitNode(const Node * node, const THREAD_ID tid)
2672{
2674 _displaced_problem->reinitNode(&_displaced_mesh->nodeRef(node->id()), tid);
2675
2676 for (const auto i : index_range(_nl))
2677 {
2678 _assembly[tid][i]->reinit(node);
2679 _nl[i]->reinitNode(node, tid);
2680 }
2681 _aux->reinitNode(node, tid);
2682}
2683
2684void
2685FEProblemBase::reinitNodeFace(const Node * node, BoundaryID bnd_id, const THREAD_ID tid)
2686{
2688 _displaced_problem->reinitNodeFace(&_displaced_mesh->nodeRef(node->id()), bnd_id, tid);
2689
2690 for (const auto i : index_range(_nl))
2691 {
2692 _assembly[tid][i]->reinit(node);
2693 _nl[i]->reinitNodeFace(node, bnd_id, tid);
2694 }
2695 _aux->reinitNodeFace(node, bnd_id, tid);
2696}
2697
2698void
2699FEProblemBase::reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering /*=false*/)
2700{
2701 TIME_SECTION("reinitScalars", 3, "Reinitializing Scalar Variables");
2702
2704 _displaced_problem->reinitScalars(tid, reinit_for_derivative_reordering);
2705
2706 for (auto & nl : _nl)
2707 nl->reinitScalars(tid, reinit_for_derivative_reordering);
2708 _aux->reinitScalars(tid, reinit_for_derivative_reordering);
2709
2710 // This is called outside of residual/Jacobian call-backs
2711 for (auto & assembly : _assembly[tid])
2713}
2714
2715void
2717{
2718 _assembly[tid][_current_nl_sys->number()]->prepareOffDiagScalar();
2720 _displaced_problem->reinitOffDiagScalars(tid);
2721}
2722
2723void
2724FEProblemBase::reinitNeighbor(const Elem * elem, unsigned int side, const THREAD_ID tid)
2725{
2726 setNeighborSubdomainID(elem, side, tid);
2727
2728 const Elem * neighbor = elem->neighbor_ptr(side);
2729 unsigned int neighbor_side = neighbor->which_neighbor_am_i(elem);
2730
2731 for (const auto i : index_range(_nl))
2732 {
2733 _assembly[tid][i]->reinitElemAndNeighbor(elem, side, neighbor, neighbor_side);
2734 _nl[i]->prepareNeighbor(tid);
2735 // Called during stateful material property evaluation outside of solve
2736 _assembly[tid][i]->prepareNeighbor();
2737 }
2738 _aux->prepareNeighbor(tid);
2739
2740 for (auto & nl : _nl)
2741 {
2742 nl->reinitElemFace(elem, side, tid);
2743 nl->reinitNeighborFace(neighbor, neighbor_side, tid);
2744 }
2745 _aux->reinitElemFace(elem, side, tid);
2746 _aux->reinitNeighborFace(neighbor, neighbor_side, tid);
2747
2749 {
2750 // There are cases like for cohesive zone modeling without significant sliding where we cannot
2751 // use FEInterface::inverse_map in Assembly::reinitElemAndNeighbor in the displaced problem
2752 // because the physical points coming from the element don't actually lie on the neighbor.
2753 // Moreover, what's the point of doing another physical point inversion in other cases? We only
2754 // care about the reference points which we can just take from the undisplaced computation
2755 const auto & displaced_ref_pts = _assembly[tid][0]->qRuleNeighbor()->get_points();
2756
2757 _displaced_problem->reinitNeighbor(
2758 _displaced_mesh->elemPtr(elem->id()), side, tid, &displaced_ref_pts);
2759 }
2760}
2761
2762void
2764 unsigned int side,
2765 const THREAD_ID tid)
2766{
2767 reinitNeighbor(elem, side, tid);
2768
2769 const Elem * lower_d_elem = _mesh.getLowerDElem(elem, side);
2770 if (lower_d_elem && _mesh.interiorLowerDBlocks().count(lower_d_elem->subdomain_id()) > 0)
2771 reinitLowerDElem(lower_d_elem, tid);
2772 else
2773 {
2774 // with mesh refinement, lower-dimensional element might be defined on neighbor side
2775 auto & neighbor = _assembly[tid][0]->neighbor();
2776 auto & neighbor_side = _assembly[tid][0]->neighborSide();
2777 const Elem * lower_d_elem_neighbor = _mesh.getLowerDElem(neighbor, neighbor_side);
2778 if (lower_d_elem_neighbor &&
2779 _mesh.interiorLowerDBlocks().count(lower_d_elem_neighbor->subdomain_id()) > 0)
2780 {
2781 auto qps = _assembly[tid][0]->qPointsFaceNeighbor().stdVector();
2782 std::vector<Point> reference_points;
2783 FEMap::inverse_map(
2784 lower_d_elem_neighbor->dim(), lower_d_elem_neighbor, qps, reference_points);
2785 reinitLowerDElem(lower_d_elem_neighbor, tid, &reference_points);
2786 }
2787 }
2788
2790 _displaced_problem->reinitElemNeighborAndLowerD(
2791 _displaced_mesh->elemPtr(elem->id()), side, tid);
2792}
2793
2794void
2796 unsigned int neighbor_side,
2797 const std::vector<Point> & physical_points,
2798 const THREAD_ID tid)
2799{
2800 mooseAssert(_mesh.queryElemPtr(neighbor->id()) == neighbor,
2801 "Are you calling this method with a displaced mesh element?");
2802
2803 for (const auto i : index_range(_nl))
2804 {
2805 // Reinits shape the functions at the physical points
2806 _assembly[tid][i]->reinitNeighborAtPhysical(neighbor, neighbor_side, physical_points);
2807
2808 // Sets the neighbor dof indices
2809 _nl[i]->prepareNeighbor(tid);
2810 }
2811 _aux->prepareNeighbor(tid);
2812
2813 // Resizes Re and Ke
2814 _assembly[tid][_current_nl_sys->number()]->prepareNeighbor();
2815
2816 // Compute the values of each variable at the points
2817 for (auto & nl : _nl)
2818 nl->reinitNeighborFace(neighbor, neighbor_side, tid);
2819 _aux->reinitNeighborFace(neighbor, neighbor_side, tid);
2820}
2821
2822void
2824 const std::vector<Point> & physical_points,
2825 const THREAD_ID tid)
2826{
2827 mooseAssert(_mesh.queryElemPtr(neighbor->id()) == neighbor,
2828 "Are you calling this method with a displaced mesh element?");
2829
2830 for (const auto i : index_range(_nl))
2831 {
2832 // Reinits shape the functions at the physical points
2833 _assembly[tid][i]->reinitNeighborAtPhysical(neighbor, physical_points);
2834
2835 // Sets the neighbor dof indices
2836 _nl[i]->prepareNeighbor(tid);
2837 }
2838 _aux->prepareNeighbor(tid);
2839
2840 // Resizes Re and Ke
2841 _assembly[tid][_current_nl_sys->number()]->prepareNeighbor();
2842
2843 // Compute the values of each variable at the points
2844 for (auto & nl : _nl)
2845 nl->reinitNeighbor(neighbor, tid);
2846 _aux->reinitNeighbor(neighbor, tid);
2847}
2848
2849void
2850FEProblemBase::getDiracElements(std::set<const Elem *> & elems)
2851{
2852 // First add in the undisplaced elements
2854
2856 {
2857 std::set<const Elem *> displaced_elements;
2858 _displaced_problem->getDiracElements(displaced_elements);
2859
2860 { // Use the ids from the displaced elements to get the undisplaced elements
2861 // and add them to the list
2862 for (const auto & elem : displaced_elements)
2863 elems.insert(_mesh.elemPtr(elem->id()));
2864 }
2865 }
2866}
2867
2868void
2870{
2872
2874 _displaced_problem->clearDiracInfo();
2875}
2876
2877void
2879{
2880 _all_materials.subdomainSetup(subdomain, tid);
2881 // Call the subdomain methods of the output system, these are not threaded so only call it once
2882 if (tid == 0)
2884
2885 for (auto & nl : _nl)
2886 nl->subdomainSetup(subdomain, tid);
2887
2888 // FIXME: call displaced_problem->subdomainSetup() ?
2889 // When adding possibility with materials being evaluated on displaced mesh
2890}
2891
2892void
2897
2898void
2899FEProblemBase::addFunction(const std::string & type,
2900 const std::string & name,
2901 InputParameters & parameters)
2902{
2903#ifdef MOOSE_KOKKOS_ENABLED
2906#endif
2907
2908 parallel_object_only();
2909
2910 parameters.set<SubProblem *>("_subproblem") = this;
2911
2912 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
2913 {
2914 std::shared_ptr<Function> func = _factory.create<Function>(type, name, parameters, tid);
2915 logAdd("Function", name, type, parameters);
2916 _functions.addObject(func, tid);
2917
2918 if (auto * const functor = dynamic_cast<Moose::FunctorBase<Real> *>(func.get()))
2919 {
2920 this->addFunctor(name, *functor, tid);
2922 _displaced_problem->addFunctor(name, *functor, tid);
2923 }
2924 else
2925 mooseError("Unrecognized function functor type");
2926 }
2927}
2928
2929void
2930FEProblemBase::addConvergence(const std::string & type,
2931 const std::string & name,
2932 InputParameters & parameters)
2933{
2934 parallel_object_only();
2935
2936 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
2937 {
2938 std::shared_ptr<Convergence> conv = _factory.create<Convergence>(type, name, parameters, tid);
2939 _convergences.addObject(conv, tid);
2940 }
2941}
2942
2943void
2945{
2946 const std::string class_name = "DefaultNonlinearConvergence";
2947 InputParameters params = _factory.getValidParams(class_name);
2948 params.applyParameters(params_to_apply);
2949 params.applyParameters(parameters());
2950 params.set<bool>("added_as_default") = true;
2951 for (const auto & conv_name : getNonlinearConvergenceNames())
2952 addConvergence(class_name, conv_name, params);
2953}
2954
2955void
2957{
2958 const std::string class_name = "DefaultMultiAppFixedPointConvergence";
2959 InputParameters params = _factory.getValidParams(class_name);
2960 params.applyParameters(params_to_apply);
2961 params.applyParameters(parameters());
2962 params.set<bool>("added_as_default") = true;
2964}
2965
2966void
2968{
2969 const std::string class_name = "DefaultSteadyStateConvergence";
2970 InputParameters params = _factory.getValidParams(class_name);
2971 params.applyParameters(params_to_apply);
2972 params.applyParameters(parameters());
2973 params.set<bool>("added_as_default") = true;
2974 addConvergence(class_name, getSteadyStateConvergenceName(), params);
2975}
2976
2977bool
2978FEProblemBase::hasFunction(const std::string & name, const THREAD_ID tid)
2979{
2980 return _functions.hasActiveObject(name, tid);
2981}
2982
2983Function &
2984FEProblemBase::getFunction(const std::string & name, const THREAD_ID tid)
2985{
2986 // This thread lock is necessary since this method will create functions
2987 // for all threads if one is missing.
2988 Threads::spin_mutex::scoped_lock lock(get_function_mutex);
2989
2990 if (!hasFunction(name, tid))
2991 {
2992 // If we didn't find a function, it might be a default function, attempt to construct one now
2993 std::istringstream ss(name);
2994 Real real_value;
2995
2996 // First see if it's just a constant. If it is, build a ConstantFunction
2997 if (ss >> real_value && ss.eof())
2998 {
2999 InputParameters params = _factory.getValidParams("ConstantFunction");
3000 params.set<Real>("value") = real_value;
3001 addFunction("ConstantFunction", ss.str(), params);
3002 }
3003 else
3004 {
3006 std::string vars = "x,y,z,t,NaN,pi,e";
3007 if (fp.Parse(name, vars) == -1) // -1 for success
3008 {
3009 // It parsed ok, so build a MooseParsedFunction
3010 InputParameters params = _factory.getValidParams("ParsedFunction");
3011 params.set<std::string>("expression") = name;
3012 addFunction("ParsedFunction", name, params);
3013 }
3014 }
3015
3016 // Try once more
3017 if (!hasFunction(name, tid))
3018 {
3019 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_function"),
3020 "getFunction() was called before Functions have been constructed. The requested "
3021 "Function '" +
3022 name + "' may exist in the input file, but Functions are not available yet.");
3023
3024 mooseError("Unable to find function " + name);
3025 }
3026 }
3027
3028 auto * const ret = dynamic_cast<Function *>(_functions.getActiveObject(name, tid).get());
3029 if (!ret)
3030 mooseError("No function named ", name, " of appropriate type");
3031
3032 return *ret;
3033}
3034
3035bool
3036FEProblemBase::hasConvergence(const std::string & name, const THREAD_ID tid) const
3037{
3038 return _convergences.hasActiveObject(name, tid);
3039}
3040
3042FEProblemBase::getConvergence(const std::string & name, const THREAD_ID tid) const
3043{
3044 auto * const ret = dynamic_cast<Convergence *>(_convergences.getActiveObject(name, tid).get());
3045 if (!ret)
3046 mooseError("The Convergence object '", name, "' does not exist.");
3047
3048 return *ret;
3049}
3050
3051const std::vector<std::shared_ptr<Convergence>> &
3056
3057void
3058FEProblemBase::addMeshDivision(const std::string & type,
3059 const std::string & name,
3060 InputParameters & parameters)
3061{
3062 parallel_object_only();
3063 parameters.set<FEProblemBase *>("_fe_problem_base") = this;
3064 parameters.set<SubProblem *>("_subproblem") = this;
3065 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
3066 {
3067 std::shared_ptr<MeshDivision> func = _factory.create<MeshDivision>(type, name, parameters, tid);
3068 _mesh_divisions.addObject(func, tid);
3069 }
3070}
3071
3073FEProblemBase::getMeshDivision(const std::string & name, const THREAD_ID tid) const
3074{
3075 auto * const ret = dynamic_cast<MeshDivision *>(_mesh_divisions.getActiveObject(name, tid).get());
3076 if (!ret)
3077 mooseError("No MeshDivision object named ", name, " of appropriate type");
3078 return *ret;
3079}
3080
3081void
3083{
3084 _line_search->lineSearch();
3085}
3086
3088FEProblemBase::getNonlinearSystem(const unsigned int sys_num)
3089{
3090 mooseDeprecated("FEProblemBase::getNonlinearSystem() is deprecated, please use "
3091 "FEProblemBase::getNonlinearSystemBase() \n");
3092
3093 mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
3094 auto nl_sys = std::dynamic_pointer_cast<NonlinearSystem>(_nl[sys_num]);
3095
3096 if (!nl_sys)
3097 mooseError("This is not a NonlinearSystem");
3098
3099 return *nl_sys;
3100}
3101
3102void
3103FEProblemBase::addDistribution(const std::string & type,
3104 const std::string & name,
3105 InputParameters & parameters)
3106{
3107 parameters.set<std::string>("type") = type;
3108 addObject<Distribution>(type, name, parameters, /* threaded = */ false);
3109}
3110
3111bool
3112FEProblemBase::hasDistribution(const std::string & name) const
3113{
3114 std::vector<Distribution *> objs;
3115 theWarehouse()
3116 .query()
3117 .condition<AttribSystem>("Distribution")
3118 .condition<AttribName>(name)
3119 .queryInto(objs);
3120 return !objs.empty();
3121}
3122
3124FEProblemBase::getDistribution(const std::string & name)
3125{
3126 std::vector<Distribution *> objs;
3127 theWarehouse()
3128 .query()
3129 .condition<AttribSystem>("Distribution")
3130 .condition<AttribName>(name)
3131 .queryInto(objs);
3132 if (objs.empty())
3133 {
3134 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_distribution"),
3135 "A Distribution getter was called before Distributions have been constructed. "
3136 "If you are attempting to access this object in the constructor of another object "
3137 "then make sure that the Distribution is constructed before the object using it.");
3138 mooseError("Unable to find Distribution with name '" + name + "'");
3139 }
3140 return *(objs[0]);
3141}
3142
3143void
3144FEProblemBase::addSampler(const std::string & type,
3145 const std::string & name,
3146 InputParameters & parameters)
3147{
3148 const auto samplers = addObject<Sampler>(type, name, parameters);
3149 for (auto & sampler : samplers)
3150 sampler->init();
3151}
3152
3153Sampler &
3154FEProblemBase::getSampler(const std::string & name, const THREAD_ID tid)
3155{
3156 std::vector<Sampler *> objs;
3157 theWarehouse()
3158 .query()
3159 .condition<AttribSystem>("Sampler")
3160 .condition<AttribThread>(tid)
3161 .condition<AttribName>(name)
3162 .queryInto(objs);
3163 if (objs.empty())
3164 {
3165 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_sampler"),
3166 "A Sampler getter was called before Samplers have been constructed. "
3167 "If you are attempting to access this object in the constructor of another object "
3168 "then make sure that the Sampler is constructed before the object using it.");
3169
3170 mooseError(
3171 "Unable to find Sampler with name '" + name +
3172 "', if you are attempting to access this object in the constructor of another object then "
3173 "make sure that the Sampler is constructed before the object using it.");
3174 }
3175 return *(objs[0]);
3176}
3177
3178bool
3179FEProblemBase::duplicateVariableCheck(const std::string & var_name,
3180 const FEType & type,
3181 bool is_aux,
3182 const std::set<SubdomainID> * const active_subdomains)
3183{
3184 std::set<SubdomainID> subdomainIDs;
3185 if (active_subdomains->size() == 0)
3186 {
3187 const auto subdomains = _mesh.meshSubdomains();
3188 subdomainIDs.insert(subdomains.begin(), subdomains.end());
3189 }
3190 else
3191 subdomainIDs.insert(active_subdomains->begin(), active_subdomains->end());
3192
3193 for (auto & sys : _solver_systems)
3194 {
3195 SystemBase * curr_sys_ptr = sys.get();
3196 SystemBase * other_sys_ptr = _aux.get();
3197 std::string error_prefix = "";
3198 if (is_aux)
3199 {
3200 curr_sys_ptr = _aux.get();
3201 other_sys_ptr = sys.get();
3202 error_prefix = "aux";
3203 }
3204
3205 if (other_sys_ptr->hasVariable(var_name))
3206 mooseError("Cannot have an auxiliary variable and a solver variable with the same name: ",
3207 var_name);
3208
3209 if (curr_sys_ptr->hasVariable(var_name))
3210 {
3211 const libMesh::Variable & var =
3212 curr_sys_ptr->system().variable(curr_sys_ptr->system().variable_number(var_name));
3213
3214 // variable type
3215 if (var.type() != type)
3216 mooseError("Mismatching types are specified for ",
3217 error_prefix,
3218 "variable with name '",
3219 var_name,
3220 "': '",
3221 Moose::stringify(var.type()),
3222 "' and '",
3224 "'");
3225
3226 // block-restriction
3227 if (!(active_subdomains->size() == 0 && var.active_subdomains().size() == 0))
3228 {
3229 const auto varActiveSubdomains = var.active_subdomains();
3230 std::set<SubdomainID> varSubdomainIDs;
3231 if (varActiveSubdomains.size() == 0)
3232 {
3233 const auto subdomains = _mesh.meshSubdomains();
3234 varSubdomainIDs.insert(subdomains.begin(), subdomains.end());
3235 }
3236 else
3237 varSubdomainIDs.insert(varActiveSubdomains.begin(), varActiveSubdomains.end());
3238
3239 // Is subdomainIDs a subset of varSubdomainIDs? With this we allow the case that the newly
3240 // requested block restriction is only a subset of the existing one.
3241 const auto isSubset = std::includes(varSubdomainIDs.begin(),
3242 varSubdomainIDs.end(),
3243 subdomainIDs.begin(),
3244 subdomainIDs.end());
3245
3246 if (!isSubset)
3247 {
3248 // helper function: make a string from a set of subdomain ids
3249 const auto stringifySubdomains = [this](std::set<SubdomainID> subdomainIDs)
3250 {
3251 std::stringstream s;
3252 for (auto const i : subdomainIDs)
3253 {
3254 // do we need to insert a comma?
3255 if (s.tellp() != 0)
3256 s << ", ";
3257
3258 // insert subdomain name and id -or- only the id (if no name is given)
3259 const auto subdomainName = _mesh.getSubdomainName(i);
3260 if (subdomainName.empty())
3261 s << i;
3262 else
3263 s << subdomainName << " (" << i << ")";
3264 }
3265 return s.str();
3266 };
3267
3268 const std::string msg = "Mismatching block-restrictions are specified for " +
3269 error_prefix + "variable with name '" + var_name + "': {" +
3270 stringifySubdomains(varSubdomainIDs) + "} and {" +
3271 stringifySubdomains(subdomainIDs) + "}";
3272
3273 mooseError(msg);
3274 }
3275 }
3276
3277 return true;
3278 }
3279 }
3280
3281 return false;
3282}
3283
3284void
3285FEProblemBase::addVariable(const std::string & var_type,
3286 const std::string & var_name,
3287 InputParameters & params)
3288{
3289 parallel_object_only();
3290
3291 const auto fe_type = MooseUtils::variableFEType(params);
3292
3293 const auto active_subdomains_vector =
3294 _mesh.getSubdomainIDs(params.get<std::vector<SubdomainName>>("block"));
3295 const std::set<SubdomainID> active_subdomains(active_subdomains_vector.begin(),
3296 active_subdomains_vector.end());
3297
3298 if (duplicateVariableCheck(var_name, fe_type, /* is_aux = */ false, &active_subdomains))
3299 return;
3300
3301 params.set<FEProblemBase *>("_fe_problem_base") = this;
3303 SolverSystemName sys_name = params.get<SolverSystemName>("solver_sys");
3304
3305 const auto solver_system_number = solverSysNum(sys_name);
3306 logAdd("Variable", var_name, var_type, params);
3307 _solver_systems[solver_system_number]->addVariable(var_type, var_name, params);
3309 // MooseObjects need to be unique so change the name here
3310 _displaced_problem->addVariable(var_type, var_name, params, solver_system_number);
3311
3312 _solver_var_to_sys_num[var_name] = solver_system_number;
3313}
3314
3315std::pair<bool, unsigned int>
3316FEProblemBase::determineSolverSystem(const std::string & var_name,
3317 const bool error_if_not_found) const
3318{
3319 auto map_it = _solver_var_to_sys_num.find(var_name);
3320 const bool var_in_sys = map_it != _solver_var_to_sys_num.end();
3321 if (var_in_sys)
3322 mooseAssert(_solver_systems[map_it->second]->hasVariable(var_name) ||
3323 _solver_systems[map_it->second]->hasScalarVariable(var_name),
3324 "If the variable is in our FEProblem solver system map, then it must be in the "
3325 "solver system we expect");
3326 else if (error_if_not_found)
3327 {
3328 if (_aux->hasVariable(var_name) || _aux->hasScalarVariable(var_name))
3329 mooseError("No solver variable named ",
3330 var_name,
3331 " found. Did you specify an auxiliary variable when you meant to specify a "
3332 "solver variable?");
3333 else
3334 mooseError("Unknown variable '",
3335 var_name,
3336 "'. It does not exist in the solver system(s) or auxiliary system");
3337 }
3338
3339 return std::make_pair(var_in_sys, var_in_sys ? map_it->second : libMesh::invalid_uint);
3340}
3341
3342void
3344 const std::string & name,
3345 InputParameters & parameters,
3346 const unsigned int nl_sys_num,
3347 const std::string & base_name,
3348 bool & reinit_displaced)
3349{
3350 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3351 {
3352 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3353 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3354 reinit_displaced = true;
3355 }
3356 else
3357 {
3358 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3359 {
3360 // We allow Kernels to request that they use_displaced_mesh,
3361 // but then be overridden when no displacements variables are
3362 // provided in the Mesh block. If that happened, update the value
3363 // of use_displaced_mesh appropriately for this Kernel.
3364 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3365 parameters.set<bool>("use_displaced_mesh") = false;
3366 }
3367
3368 parameters.set<SubProblem *>("_subproblem") = this;
3369 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3370 }
3371
3372 logAdd(base_name, name, ro_name, parameters);
3373}
3374
3375void
3377 const std::string & name,
3378 InputParameters & parameters,
3379 const std::string & base_name)
3380{
3381 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3382 {
3383 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3384 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
3385 parameters.set<SystemBase *>("_nl_sys") = &_displaced_problem->solverSys(0);
3386 if (!parameters.get<std::vector<BoundaryName>>("boundary").empty())
3388 else
3390 }
3391 else
3392 {
3393 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3394 {
3395 // We allow AuxKernels to request that they use_displaced_mesh,
3396 // but then be overridden when no displacements variables are
3397 // provided in the Mesh block. If that happened, update the value
3398 // of use_displaced_mesh appropriately for this AuxKernel.
3399 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3400 parameters.set<bool>("use_displaced_mesh") = false;
3401 }
3402
3403 parameters.set<SubProblem *>("_subproblem") = this;
3404 parameters.set<SystemBase *>("_sys") = _aux.get();
3405 parameters.set<SystemBase *>("_nl_sys") = _solver_systems[0].get();
3406 }
3407
3408 logAdd(base_name, name, ak_name, parameters);
3409}
3410
3411void
3412FEProblemBase::addKernel(const std::string & kernel_name,
3413 const std::string & name,
3414 InputParameters & parameters)
3415{
3416#ifdef MOOSE_KOKKOS_ENABLED
3418 return addKokkosKernel(kernel_name, name, parameters);
3419#endif
3420
3421 parallel_object_only();
3422 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3423 if (!isSolverSystemNonlinear(nl_sys_num))
3424 mooseError("You are trying to add a Kernel to a linear variable/system, which is not "
3425 "supported at the moment!");
3427 kernel_name, name, parameters, nl_sys_num, "Kernel", _reinit_displaced_elem);
3428
3429 _nl[nl_sys_num]->addKernel(kernel_name, name, parameters);
3430}
3431
3432void
3433FEProblemBase::addHDGKernel(const std::string & kernel_name,
3434 const std::string & name,
3435 InputParameters & parameters)
3436{
3437 parallel_object_only();
3438 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3439 if (!isSolverSystemNonlinear(nl_sys_num))
3440 mooseError("You are trying to add a HDGKernel to a linear variable/system, which is not "
3441 "supported at the moment!");
3443 kernel_name, name, parameters, nl_sys_num, "HDGKernel", _reinit_displaced_elem);
3444
3445 _nl[nl_sys_num]->addHDGKernel(kernel_name, name, parameters);
3446}
3447
3448void
3449FEProblemBase::addNodalKernel(const std::string & kernel_name,
3450 const std::string & name,
3451 InputParameters & parameters)
3452{
3453#ifdef MOOSE_KOKKOS_ENABLED
3455 return addKokkosNodalKernel(kernel_name, name, parameters);
3456#endif
3457
3458 parallel_object_only();
3459
3460 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3461 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3462 {
3463 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3464 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3466 }
3467 else
3468 {
3469 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3470 {
3471 // We allow NodalKernels to request that they use_displaced_mesh,
3472 // but then be overridden when no displacements variables are
3473 // provided in the Mesh block. If that happened, update the value
3474 // of use_displaced_mesh appropriately for this NodalKernel.
3475 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3476 parameters.set<bool>("use_displaced_mesh") = false;
3477 }
3478
3479 parameters.set<SubProblem *>("_subproblem") = this;
3480 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3481 }
3482 logAdd("NodalKernel", name, kernel_name, parameters);
3483 _nl[nl_sys_num]->addNodalKernel(kernel_name, name, parameters);
3484}
3485
3486void
3487FEProblemBase::addScalarKernel(const std::string & kernel_name,
3488 const std::string & name,
3489 InputParameters & parameters)
3490{
3491 parallel_object_only();
3492
3493 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3494 if (!isSolverSystemNonlinear(nl_sys_num))
3495 mooseError("You are trying to add a ScalarKernel to a linear variable/system, which is not "
3496 "supported at the moment!");
3497
3498 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3499 {
3500 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3501 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3502 }
3503 else
3504 {
3505 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3506 {
3507 // We allow ScalarKernels to request that they use_displaced_mesh,
3508 // but then be overridden when no displacements variables are
3509 // provided in the Mesh block. If that happened, update the value
3510 // of use_displaced_mesh appropriately for this ScalarKernel.
3511 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3512 parameters.set<bool>("use_displaced_mesh") = false;
3513 }
3514
3515 parameters.set<SubProblem *>("_subproblem") = this;
3516 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3517 }
3518
3519 logAdd("ScalarKernel", name, kernel_name, parameters);
3520 _nl[nl_sys_num]->addScalarKernel(kernel_name, name, parameters);
3521}
3522
3523void
3524FEProblemBase::addBoundaryCondition(const std::string & bc_name,
3525 const std::string & name,
3526 InputParameters & parameters)
3527{
3528#ifdef MOOSE_KOKKOS_ENABLED
3530 return addKokkosBoundaryCondition(bc_name, name, parameters);
3531#endif
3532
3533 parallel_object_only();
3534
3535 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3536 if (!isSolverSystemNonlinear(nl_sys_num))
3537 mooseError(
3538 "You are trying to add a BoundaryCondition to a linear variable/system, which is not "
3539 "supported at the moment!");
3540
3542 bc_name, name, parameters, nl_sys_num, "BoundaryCondition", _reinit_displaced_face);
3543 _nl[nl_sys_num]->addBoundaryCondition(bc_name, name, parameters);
3544}
3545
3546void
3547FEProblemBase::addConstraint(const std::string & c_name,
3548 const std::string & name,
3549 InputParameters & parameters)
3550{
3551 parallel_object_only();
3552
3553 _has_constraints = true;
3554
3555 auto determine_var_param_name = [&parameters, this]()
3556 {
3557 if (parameters.isParamValid("variable"))
3558 return "variable";
3559 else
3560 {
3561 // must be a mortar constraint
3562 const bool has_secondary_var = parameters.isParamValid("secondary_variable");
3563 const bool has_primary_var = parameters.isParamValid("primary_variable");
3564 if (!has_secondary_var && !has_primary_var)
3565 mooseError(
3566 "Either a 'secondary_variable' or 'primary_variable' parameter must be supplied for '",
3568 "'");
3569 return has_secondary_var ? "secondary_variable" : "primary_variable";
3570 }
3571 };
3572
3573 const auto nl_sys_num =
3574 determineSolverSystem(parameters.varName(determine_var_param_name(), name), true).second;
3575 if (!isSolverSystemNonlinear(nl_sys_num))
3576 mooseError("You are trying to add a Constraint to a linear variable/system, which is not "
3577 "supported at the moment!");
3578
3579 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3580 {
3581 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3582 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3584 }
3585 else
3586 {
3587 // It might _want_ to use a displaced mesh... but we're not so set it to false
3588 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3589 parameters.set<bool>("use_displaced_mesh") = false;
3590
3591 parameters.set<SubProblem *>("_subproblem") = this;
3592 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3593 }
3594
3595 logAdd("Constraint", name, c_name, parameters);
3596 _nl[nl_sys_num]->addConstraint(c_name, name, parameters);
3597}
3598
3599void
3600FEProblemBase::addAuxVariable(const std::string & var_type,
3601 const std::string & var_name,
3602 InputParameters & params)
3603{
3604 parallel_object_only();
3605
3606 const auto fe_type = MooseUtils::variableFEType(params);
3607
3608 const auto active_subdomains_vector =
3609 _mesh.getSubdomainIDs(params.get<std::vector<SubdomainName>>("block"));
3610 const std::set<SubdomainID> active_subdomains(active_subdomains_vector.begin(),
3611 active_subdomains_vector.end());
3612
3613 if (duplicateVariableCheck(var_name, fe_type, /* is_aux = */ true, &active_subdomains))
3614 return;
3615
3616 params.set<FEProblemBase *>("_fe_problem_base") = this;
3618
3619 logAdd("AuxVariable", var_name, var_type, params);
3620 _aux->addVariable(var_type, var_name, params);
3622 // MooseObjects need to be unique so change the name here
3623 _displaced_problem->addAuxVariable(var_type, var_name, params);
3624}
3625
3626void
3627FEProblemBase::addElementalFieldVariable(const std::string & var_type,
3628 const std::string & var_name,
3629 InputParameters & params)
3630{
3631 addAuxVariable(var_type, var_name, params);
3632}
3633
3634void
3635FEProblemBase::addAuxVariable(const std::string & var_name,
3636 const FEType & type,
3637 const std::set<SubdomainID> * const active_subdomains)
3638{
3639 parallel_object_only();
3640
3641 mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
3642
3643 if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
3644 return;
3645
3646 std::string var_type;
3647 if (type.order == CONSTANT && type.family == MONOMIAL && !type.p_refinement)
3648 var_type = "MooseVariableConstMonomial";
3649 else if (type.family == SCALAR)
3650 var_type = "MooseVariableScalar";
3651 else if (FEInterface::field_type(type) == libMesh::TYPE_VECTOR)
3652 var_type = "VectorMooseVariable";
3653 else
3654 var_type = "MooseVariable";
3655
3656 InputParameters params = _factory.getValidParams(var_type);
3657 params.set<FEProblemBase *>("_fe_problem_base") = this;
3659 params.set<MooseEnum>("order") = type.order.get_order();
3660 params.set<MooseEnum>("family") = Moose::stringify(type.family);
3661 params.set<bool>("p_refinement") = type.p_refinement;
3662
3663 if (active_subdomains)
3664 for (const SubdomainID & id : *active_subdomains)
3665 params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
3666
3667 logAdd("AuxVariable", var_name, var_type, params);
3668 _aux->addVariable(var_type, var_name, params);
3670 _displaced_problem->addAuxVariable("MooseVariable", var_name, params);
3671}
3672
3673void
3674FEProblemBase::addAuxArrayVariable(const std::string & var_name,
3675 const FEType & type,
3676 unsigned int components,
3677 const std::set<SubdomainID> * const active_subdomains)
3678{
3679 parallel_object_only();
3680
3681 mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
3682
3683 if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
3684 return;
3685
3686 InputParameters params = _factory.getValidParams("ArrayMooseVariable");
3687 params.set<FEProblemBase *>("_fe_problem_base") = this;
3689 params.set<MooseEnum>("order") = type.order.get_order();
3690 params.set<MooseEnum>("family") = Moose::stringify(type.family);
3691 params.set<bool>("p_refinement") = type.p_refinement;
3692 params.set<unsigned int>("components") = components;
3693
3694 if (active_subdomains)
3695 for (const SubdomainID & id : *active_subdomains)
3696 params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
3697
3698 logAdd("Variable", var_name, "ArrayMooseVariable", params);
3699 _aux->addVariable("ArrayMooseVariable", var_name, params);
3701 _displaced_problem->addAuxVariable("ArrayMooseVariable", var_name, params);
3702}
3703
3704void
3705FEProblemBase::addAuxScalarVariable(const std::string & var_name,
3706 Order order,
3707 Real /*scale_factor*/,
3708 const std::set<SubdomainID> * const active_subdomains)
3709{
3710 parallel_object_only();
3711
3712 mooseDeprecated("Please use the addAuxVariable(var_type, var_name, params) API instead");
3713
3714 if (order > _max_scalar_order)
3715 _max_scalar_order = order;
3716
3717 FEType type(order, SCALAR);
3718 if (duplicateVariableCheck(var_name, type, /* is_aux = */ true, active_subdomains))
3719 return;
3720
3721 InputParameters params = _factory.getValidParams("MooseVariableScalar");
3722 params.set<FEProblemBase *>("_fe_problem_base") = this;
3724
3725 params.set<MooseEnum>("order") = type.order.get_order();
3726 params.set<MooseEnum>("family") = "SCALAR";
3727 params.set<std::vector<Real>>("scaling") = std::vector<Real>{1};
3728 if (active_subdomains)
3729 for (const SubdomainID & id : *active_subdomains)
3730 params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
3731
3732 logAdd("ScalarVariable", var_name, "MooseVariableScalar", params);
3733 _aux->addVariable("MooseVariableScalar", var_name, params);
3735 _displaced_problem->addAuxVariable("MooseVariableScalar", var_name, params);
3736}
3737
3738void
3739FEProblemBase::addAuxKernel(const std::string & kernel_name,
3740 const std::string & name,
3741 InputParameters & parameters)
3742{
3743#ifdef MOOSE_KOKKOS_ENABLED
3745 return addKokkosAuxKernel(kernel_name, name, parameters);
3746#endif
3747
3748 parallel_object_only();
3749
3750 setAuxKernelParamsAndLog(kernel_name, name, parameters, "AuxKernel");
3751
3752 _aux->addKernel(kernel_name, name, parameters);
3753}
3754
3755void
3756FEProblemBase::addAuxScalarKernel(const std::string & kernel_name,
3757 const std::string & name,
3758 InputParameters & parameters)
3759{
3760 parallel_object_only();
3761
3762 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3763 {
3764 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3765 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
3766 }
3767 else
3768 {
3769 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3770 {
3771 // We allow AuxScalarKernels to request that they use_displaced_mesh,
3772 // but then be overridden when no displacements variables are
3773 // provided in the Mesh block. If that happened, update the value
3774 // of use_displaced_mesh appropriately for this AuxScalarKernel.
3775 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3776 parameters.set<bool>("use_displaced_mesh") = false;
3777 }
3778
3779 parameters.set<SubProblem *>("_subproblem") = this;
3780 parameters.set<SystemBase *>("_sys") = _aux.get();
3781 }
3782
3783 logAdd("AuxScalarKernel", name, kernel_name, parameters);
3784 _aux->addScalarKernel(kernel_name, name, parameters);
3785}
3786
3787void
3788FEProblemBase::addDiracKernel(const std::string & kernel_name,
3789 const std::string & name,
3790 InputParameters & parameters)
3791{
3792 parallel_object_only();
3793
3794 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3795 if (!isSolverSystemNonlinear(nl_sys_num))
3796 mooseError("You are trying to add a DiracKernel to a linear variable/system, which is not "
3797 "supported at the moment!");
3798
3799 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3800 {
3801 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3802 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3804 }
3805 else
3806 {
3807 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3808 {
3809 // We allow DiracKernels to request that they use_displaced_mesh,
3810 // but then be overridden when no displacements variables are
3811 // provided in the Mesh block. If that happened, update the value
3812 // of use_displaced_mesh appropriately for this DiracKernel.
3813 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3814 parameters.set<bool>("use_displaced_mesh") = false;
3815 }
3816
3817 parameters.set<SubProblem *>("_subproblem") = this;
3818 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3819 }
3820
3821 logAdd("DiracKernel", name, kernel_name, parameters);
3822 _nl[nl_sys_num]->addDiracKernel(kernel_name, name, parameters);
3823}
3824
3825// DGKernels ////
3826
3827void
3828FEProblemBase::addDGKernel(const std::string & dg_kernel_name,
3829 const std::string & name,
3830 InputParameters & parameters)
3831{
3832 parallel_object_only();
3833
3834 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3835 if (!isSolverSystemNonlinear(nl_sys_num))
3836 mooseError("You are trying to add a DGKernel to a linear variable/system, which is not "
3837 "supported at the moment!");
3838
3839 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3840 {
3841 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3842 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3844 }
3845 else
3846 {
3847 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3848 {
3849 // We allow DGKernels to request that they use_displaced_mesh,
3850 // but then be overridden when no displacements variables are
3851 // provided in the Mesh block. If that happened, update the value
3852 // of use_displaced_mesh appropriately for this DGKernel.
3853 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3854 parameters.set<bool>("use_displaced_mesh") = false;
3855 }
3856
3857 parameters.set<SubProblem *>("_subproblem") = this;
3858 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3859 }
3860
3861 logAdd("DGKernel", name, dg_kernel_name, parameters);
3862 _nl[nl_sys_num]->addDGKernel(dg_kernel_name, name, parameters);
3863
3865}
3866
3867void
3868FEProblemBase::addFVKernel(const std::string & fv_kernel_name,
3869 const std::string & name,
3870 InputParameters & parameters)
3871{
3872 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3873 // FVElementalKernels are computed in the historically finite element threaded loops. They rely
3874 // on Assembly data like _current_elem. When we call reinit on the FEProblemBase we will only
3875 // reinit the DisplacedProblem and its associated Assembly objects if we mark this boolean as
3876 // true
3878 addObject<FVKernel>(fv_kernel_name, name, parameters);
3879}
3880
3881void
3882FEProblemBase::addFVBC(const std::string & fv_bc_name,
3883 const std::string & name,
3884 InputParameters & parameters)
3885{
3886 addObject<FVBoundaryCondition>(fv_bc_name, name, parameters);
3887}
3888
3889void
3890FEProblemBase::addFVInterfaceKernel(const std::string & fv_ik_name,
3891 const std::string & name,
3892 InputParameters & parameters)
3893{
3896 addObject<FVInterfaceKernel>(
3897 fv_ik_name, name, parameters, /*threaded=*/true, /*variable_param_name=*/"variable1");
3898}
3899
3900void
3901FEProblemBase::addLinearFVKernel(const std::string & kernel_name,
3902 const std::string & name,
3903 InputParameters & parameters)
3904{
3905#ifdef MOOSE_KOKKOS_ENABLED
3907 return addKokkosLinearFVKernel(kernel_name, name, parameters);
3908#endif
3909
3910 addObject<LinearFVKernel>(kernel_name, name, parameters);
3911}
3912
3913void
3914FEProblemBase::addLinearFVBC(const std::string & bc_name,
3915 const std::string & name,
3916 InputParameters & parameters)
3917{
3918#ifdef MOOSE_KOKKOS_ENABLED
3920 return addKokkosLinearFVBC(bc_name, name, parameters);
3921#endif
3922
3923 addObject<LinearFVBoundaryCondition>(bc_name, name, parameters);
3924}
3925
3926// InterfaceKernels ////
3927
3928void
3929FEProblemBase::addInterfaceKernel(const std::string & interface_kernel_name,
3930 const std::string & name,
3931 InputParameters & parameters)
3932{
3933 parallel_object_only();
3934
3935 const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
3936 if (!isSolverSystemNonlinear(nl_sys_num))
3937 mooseError("You are trying to add a InterfaceKernel to a linear variable/system, which is not "
3938 "supported at the moment!");
3939
3940 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
3941 {
3942 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
3943 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(nl_sys_num);
3945 }
3946 else
3947 {
3948 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
3949 {
3950 // We allow InterfaceKernels to request that they use_displaced_mesh,
3951 // but then be overridden when no displacements variables are
3952 // provided in the Mesh block. If that happened, update the value
3953 // of use_displaced_mesh appropriately for this InterfaceKernel.
3954 if (parameters.have_parameter<bool>("use_displaced_mesh"))
3955 parameters.set<bool>("use_displaced_mesh") = false;
3956 }
3957
3958 parameters.set<SubProblem *>("_subproblem") = this;
3959 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
3960 }
3961
3962 logAdd("InterfaceKernel", name, interface_kernel_name, parameters);
3963 _nl[nl_sys_num]->addInterfaceKernel(interface_kernel_name, name, parameters);
3964
3966}
3967
3968void
3969FEProblemBase::checkICRestartError(const std::string & ic_name,
3970 const std::string & name,
3971 const VariableName & var_name)
3972{
3974 {
3975 std::string restart_method = "";
3976 if (_app.isRestarting())
3977 restart_method =
3978 "a checkpoint restart, by IC object '" + ic_name + "' for variable '" + name + "'";
3979 else if (_app.getExReaderForRestart())
3980 {
3981 std::vector<std::string> restarted_vars = _app.getExReaderForRestart()->get_elem_var_names();
3982 const auto nodal_vars = _app.getExReaderForRestart()->get_nodal_var_names();
3983 const auto global_vars = _app.getExReaderForRestart()->get_global_var_names();
3984 restarted_vars.insert(restarted_vars.end(), nodal_vars.begin(), nodal_vars.end());
3985 restarted_vars.insert(restarted_vars.end(), global_vars.begin(), global_vars.end());
3986
3987 if (std::find(restarted_vars.begin(), restarted_vars.end(), var_name) != restarted_vars.end())
3988 restart_method = "an Exodus restart, by IC object '" + ic_name + "' for variable '" + name +
3989 "' that is also being restarted";
3990 }
3991 if (!restart_method.empty())
3992 mooseError(
3993 "Initial conditions have been specified during ",
3994 restart_method,
3995 ".\nThis is only allowed if you specify 'allow_initial_conditions_with_restart' to "
3996 "the [Problem], as initial conditions can override restarted fields");
3997 }
3998}
3999
4000void
4001FEProblemBase::addInitialCondition(const std::string & ic_name,
4002 const std::string & name,
4003 InputParameters & parameters)
4004{
4005 parallel_object_only();
4006
4007 // before we start to mess with the initial condition, we need to check parameters for errors.
4009 const std::string & var_name = parameters.get<VariableName>("variable");
4010
4011 // Forbid initial conditions on a restarted problem, as they would override the restart
4012 checkICRestartError(ic_name, name, var_name);
4013
4014 parameters.set<SubProblem *>("_subproblem") = this;
4015
4016 // field IC
4017 if (hasVariable(var_name))
4018 {
4019 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
4020 {
4023 parameters.set<SystemBase *>("_sys") = &var.sys();
4024 std::shared_ptr<InitialConditionBase> ic;
4025 if (dynamic_cast<MooseVariable *>(&var))
4026 ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
4027 else if (dynamic_cast<VectorMooseVariable *>(&var))
4029 else if (dynamic_cast<ArrayMooseVariable *>(&var))
4030 ic = _factory.create<ArrayInitialCondition>(ic_name, name, parameters, tid);
4031 else if (dynamic_cast<MooseVariableFVReal *>(&var))
4032 ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
4033 else if (dynamic_cast<MooseLinearVariableFVReal *>(&var))
4034 ic = _factory.create<InitialCondition>(ic_name, name, parameters, tid);
4035 else
4036 mooseError("Your FE variable in initial condition ",
4037 name,
4038 " must be either of scalar or vector type");
4039 logAdd("IC", name, ic_name, parameters);
4040 _ics.addObject(ic, tid);
4041 }
4042 }
4043
4044 // scalar IC
4045 else if (hasScalarVariable(var_name))
4046 {
4047 MooseVariableScalar & var = getScalarVariable(0, var_name);
4048 parameters.set<SystemBase *>("_sys") = &var.sys();
4049 std::shared_ptr<ScalarInitialCondition> ic =
4051 logAdd("ScalarIC", name, ic_name, parameters);
4053 }
4054
4055 else
4056 mooseError(
4057 "Variable '", var_name, "' requested in initial condition '", name, "' does not exist.");
4058}
4059
4060void
4061FEProblemBase::addFVInitialCondition(const std::string & ic_name,
4062 const std::string & name,
4063 InputParameters & parameters)
4064{
4065 parallel_object_only();
4066
4067 // before we start to mess with the initial condition, we need to check parameters for errors.
4069 const std::string & var_name = parameters.get<VariableName>("variable");
4070
4071 // Forbid initial conditions on a restarted problem, as they would override the restart
4072 checkICRestartError(ic_name, name, var_name);
4073
4074 parameters.set<SubProblem *>("_subproblem") = this;
4075
4076 // field IC
4077 if (hasVariable(var_name))
4078 {
4079 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
4080 {
4081 auto & var = getVariable(
4083 parameters.set<SystemBase *>("_sys") = &var.sys();
4084 std::shared_ptr<FVInitialConditionBase> ic;
4085 if (var.isFV())
4086 ic = _factory.create<FVInitialCondition>(ic_name, name, parameters, tid);
4087 else
4088 mooseError(
4089 "Your variable for an FVInitialCondition needs to be an a finite volume variable!");
4090 _fv_ics.addObject(ic, tid);
4091 }
4092 }
4093 else
4094 mooseError("Variable '",
4095 var_name,
4096 "' requested in finite volume initial condition '",
4097 name,
4098 "' does not exist.");
4099}
4100
4101void
4103{
4104 TIME_SECTION("projectSolution", 2, "Projecting Initial Solutions")
4105
4107
4110
4111 if (haveFV())
4112 {
4113 using ElemInfoRange = StoredRange<MooseMesh::const_elem_info_iterator, const ElemInfo *>;
4114 ElemInfoRange elem_info_range(_mesh.ownedElemInfoBegin(), _mesh.ownedElemInfoEnd());
4115
4117 Threads::parallel_reduce(elem_info_range, cfvic, numThreads());
4118 }
4119
4120 // Need to close the solution vector here so that boundary ICs take precendence
4121 for (auto & nl : _nl)
4122 nl->solution().close();
4123 _aux->solution().close();
4124
4125 // now run boundary-restricted initial conditions
4128
4129 for (auto & nl : _nl)
4130 nl->solution().close();
4131 _aux->solution().close();
4132
4133 // Also, load values into the SCALAR dofs
4134 // Note: We assume that all SCALAR dofs are on the
4135 // processor with highest ID
4137 {
4138 const auto & ics = _scalar_ics.getActiveObjects();
4139 for (const auto & ic : ics)
4140 {
4141 MooseVariableScalar & var = ic->variable();
4142 var.reinit();
4143
4144 DenseVector<Number> vals(var.order());
4145 ic->compute(vals);
4146
4147 const unsigned int n_scalar_dofs = var.dofIndices().size();
4148 for (unsigned int i = 0; i < n_scalar_dofs; i++)
4149 {
4150 const auto global_index = var.dofIndices()[i];
4151 var.sys().solution().set(global_index, vals(i));
4152 var.setValue(i, vals(i));
4153 }
4154 }
4155 }
4156
4157 // Spline node ICs may need to be evaluated indirectly.
4158 bool solve_for_spline_dofs = shouldSolveForSplineDofs(_mesh.getMesh());
4159
4160 for (auto & sys : _solver_systems)
4161 {
4162 sys->solution().close();
4163 if (solve_for_spline_dofs)
4164 solveForSplineDofs(*sys);
4165 sys->solution().localize(*sys->system().current_local_solution, sys->dofMap().get_send_list());
4166 }
4167
4168 _aux->solution().close();
4169 if (solve_for_spline_dofs)
4170 solveForSplineDofs(*_aux);
4171 _aux->solution().localize(*_aux->sys().current_local_solution, _aux->dofMap().get_send_list());
4172}
4173
4174void
4176 ConstElemRange & elem_range,
4177 ConstBndNodeRange & bnd_nodes,
4178 const std::optional<std::set<VariableName>> & target_vars)
4179{
4180 if (target_vars)
4181 {
4182 ComputeInitialConditionThread cic(*this, &(*target_vars));
4183 Threads::parallel_reduce(elem_range, cic, numThreads());
4184 }
4185 else
4186 {
4188 Threads::parallel_reduce(elem_range, cic, numThreads());
4189 }
4190
4191 // Need to close the solution vector here so that boundary ICs take precendence
4192 for (auto & nl : _nl)
4193 nl->solution().close();
4194 _aux->solution().close();
4195
4196 if (target_vars)
4197 {
4198 ComputeBoundaryInitialConditionThread cbic(*this, &(*target_vars));
4199 Threads::parallel_reduce(bnd_nodes, cbic, numThreads());
4200 }
4201 else
4202 {
4204 Threads::parallel_reduce(bnd_nodes, cbic, numThreads());
4205 }
4206
4207 for (auto & nl : _nl)
4208 nl->solution().close();
4209 _aux->solution().close();
4210
4211 // Also, load values into the SCALAR dofs
4212 // Note: We assume that all SCALAR dofs are on the
4213 // processor with highest ID
4215 {
4216 const auto & ics = _scalar_ics.getActiveObjects();
4217 for (const auto & ic : ics)
4218 {
4219 MooseVariableScalar & var = ic->variable();
4220
4221 if (target_vars && !target_vars->count(var.name()))
4222 continue;
4223
4224 var.reinit();
4225
4226 DenseVector<Number> vals(var.order());
4227 ic->compute(vals);
4228
4229 const unsigned int n_scalar_dofs = var.dofIndices().size();
4230 for (unsigned int i = 0; i < n_scalar_dofs; i++)
4231 {
4232 const auto global_index = var.dofIndices()[i];
4233 var.sys().solution().set(global_index, vals(i));
4234 var.setValue(i, vals(i));
4235 }
4236 }
4237 }
4238
4239 // Spline node ICs may need to be evaluated indirectly.
4240 bool solve_for_spline_dofs = shouldSolveForSplineDofs(_mesh.getMesh());
4241
4242 for (auto & nl : _nl)
4243 {
4244 nl->solution().close();
4245 if (solve_for_spline_dofs)
4246 solveForSplineDofs(*nl);
4247 nl->solution().localize(*nl->system().current_local_solution, nl->dofMap().get_send_list());
4248 }
4249
4250 _aux->solution().close();
4251 if (solve_for_spline_dofs)
4252 solveForSplineDofs(*_aux);
4253 _aux->solution().localize(*_aux->sys().current_local_solution, _aux->dofMap().get_send_list());
4254}
4255
4256void
4258 Number (*func)(const Point &,
4259 const libMesh::Parameters &,
4260 const std::string &,
4261 const std::string &),
4262 Gradient (*func_grad)(const Point &,
4263 const libMesh::Parameters &,
4264 const std::string &,
4265 const std::string &),
4266 const libMesh::Parameters & params,
4267 const std::vector<VariableName> & target_vars)
4268{
4269 mooseAssert(!Threads::in_threads,
4270 "We're performing a projection based on data from just the thread 0 variable, so any "
4271 "modifications to the variable solution must have been thread joined already");
4272
4273 std::unordered_map<unsigned int, std::vector<unsigned int>> sys_to_var_nums;
4274
4275 for (const auto & target_var : target_vars)
4276 {
4277 const auto sn = systemNumForVariable(target_var);
4278 const auto & var = getStandardVariable(0, target_var);
4279 sys_to_var_nums[sn].push_back(var.number());
4280 }
4281
4282 for (const auto & [sys_num, var_nums] : sys_to_var_nums)
4283 {
4284 System & libmesh_sys = getSystemBase(sys_num).system();
4285 libmesh_sys.project_solution(func, func_grad, params, elem_range, var_nums);
4286 }
4287}
4288
4289std::shared_ptr<MaterialBase>
4292 const THREAD_ID tid,
4293 bool no_warn)
4294{
4295 switch (type)
4296 {
4298 name += "_neighbor";
4299 break;
4301 name += "_face";
4302 break;
4303 default:
4304 break;
4305 }
4306
4307 std::shared_ptr<MaterialBase> material = _all_materials[type].getActiveObject(name, tid);
4308 if (!no_warn && material->getParam<bool>("compute") && type == Moose::BLOCK_MATERIAL_DATA)
4309 mooseWarning("You are retrieving a Material object (",
4310 material->name(),
4311 "), but its compute flag is set to true. This indicates that MOOSE is "
4312 "computing this property which may not be desired and produce un-expected "
4313 "results.");
4314
4315 return material;
4316}
4317
4320 const THREAD_ID tid,
4321 const MooseObject * object) const
4322{
4323 switch (type)
4324 {
4326 if (object)
4328 return _material_props.getMaterialData(tid);
4330 if (object)
4336 if (object)
4339 }
4340
4341 mooseError("FEProblemBase::getMaterialData(): Invalid MaterialDataType ", type);
4342}
4343
4344const std::set<const MooseObject *> &
4346{
4347 switch (type)
4348 {
4357 }
4358
4359 mooseError("FEProblemBase::getMaterialPropertyStorageConsumers(): Invalid MaterialDataType ",
4360 type);
4361}
4362
4363void
4365{
4366 if (_ignore_zeros_in_jacobian && preserve)
4368 "ignore_zeros_in_jacobian",
4369 "We likely cannot preserve the sparsity pattern if ignoring zeros in the Jacobian, which "
4370 "leads to removing those entries from the Jacobian sparsity pattern");
4372}
4373
4374bool
4376{
4377 return allowInvalidSolution() || // invalid solutions are always allowed
4378 !_app.solutionInvalidity().hasInvalidSolutionError(); // if not allowed, check for errors
4379}
4380
4381void
4382FEProblemBase::addFunctorMaterial(const std::string & functor_material_name,
4383 const std::string & name,
4384 InputParameters & parameters)
4385{
4386 parallel_object_only();
4387
4388 auto add_functor_materials = [&](const auto & parameters, const auto & name)
4389 {
4390 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
4391 {
4392 // Create the general Block/Boundary MaterialBase object
4393 std::shared_ptr<MaterialBase> material =
4394 _factory.create<MaterialBase>(functor_material_name, name, parameters, tid);
4395 logAdd("FunctorMaterial", name, functor_material_name, parameters);
4396 _all_materials.addObject(material, tid);
4397 _materials.addObject(material, tid);
4398 }
4399 };
4400
4401 parameters.set<SubProblem *>("_subproblem") = this;
4402 add_functor_materials(parameters, name);
4404 {
4405 auto disp_params = parameters;
4406 disp_params.set<SubProblem *>("_subproblem") = _displaced_problem.get();
4407 add_functor_materials(disp_params, name + "_displaced");
4408 }
4409}
4410
4411void
4412FEProblemBase::addMaterial(const std::string & mat_name,
4413 const std::string & name,
4414 InputParameters & parameters)
4415{
4416#ifdef MOOSE_KOKKOS_ENABLED
4418 return addKokkosMaterial(mat_name, name, parameters);
4419#endif
4420
4422}
4423
4424void
4425FEProblemBase::addInterfaceMaterial(const std::string & mat_name,
4426 const std::string & name,
4427 InputParameters & parameters)
4428{
4430}
4431
4432void
4433FEProblemBase::addMaterialHelper(std::vector<MaterialWarehouse *> warehouses,
4434 const std::string & mat_name,
4435 const std::string & name,
4436 InputParameters & parameters)
4437{
4438 parallel_object_only();
4439
4440 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
4441 {
4442 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
4444 }
4445 else
4446 {
4447 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
4448 {
4449 // We allow Materials to request that they use_displaced_mesh,
4450 // but then be overridden when no displacements variables are
4451 // provided in the Mesh block. If that happened, update the value
4452 // of use_displaced_mesh appropriately for this Material.
4453 if (parameters.have_parameter<bool>("use_displaced_mesh"))
4454 parameters.set<bool>("use_displaced_mesh") = false;
4455 }
4456
4457 parameters.set<SubProblem *>("_subproblem") = this;
4458 }
4459
4460 unsigned int n_threads = numThreads();
4461
4462#ifdef MOOSE_KOKKOS_ENABLED
4464 n_threads = 1;
4465#endif
4466
4467 for (THREAD_ID tid = 0; tid < n_threads; tid++)
4468 {
4469 // Create the general Block/Boundary MaterialBase object
4470 std::shared_ptr<MaterialBase> material =
4471 _factory.create<MaterialBase>(mat_name, name, parameters, tid);
4472 logAdd("Material", name, mat_name, parameters);
4473 bool discrete = !material->getParam<bool>("compute");
4474
4475 // If the object is boundary restricted or if it is a functor material we do not create the
4476 // neighbor and face objects
4477 if (material->boundaryRestricted() || dynamic_cast<FunctorMaterial *>(material.get()))
4478 {
4479 _all_materials.addObject(material, tid);
4480 if (discrete)
4481 _discrete_materials.addObject(material, tid);
4482 else
4483 for (auto && warehouse : warehouses)
4484 warehouse->addObject(material, tid);
4485 }
4486
4487 // Non-boundary restricted require face and neighbor objects
4488 else
4489 {
4490 // TODO: we only need to do this if we have needs for face materials (e.g.
4491 // FV, DG, etc.) - but currently we always do it. Figure out how to fix
4492 // this.
4493
4494 // The name of the object being created, this is changed multiple times as objects are
4495 // created below
4496 std::string object_name;
4497
4498 // Create a copy of the supplied parameters to the setting for "_material_data_type" isn't
4499 // used from a previous tid loop
4500 InputParameters current_parameters = parameters;
4501
4502 // face material
4503 current_parameters.set<Moose::MaterialDataType>("_material_data_type") =
4505 object_name = name + "_face";
4506 std::shared_ptr<MaterialBase> face_material =
4507 _factory.create<MaterialBase>(mat_name, object_name, current_parameters, tid);
4508
4509 // neighbor material
4510 current_parameters.set<Moose::MaterialDataType>("_material_data_type") =
4512 current_parameters.set<bool>("_neighbor") = true;
4513 object_name = name + "_neighbor";
4514 std::shared_ptr<MaterialBase> neighbor_material =
4515 _factory.create<MaterialBase>(mat_name, object_name, current_parameters, tid);
4516
4517 // Store the material objects
4518 _all_materials.addObjects(material, neighbor_material, face_material, tid);
4519
4520 if (discrete)
4521 _discrete_materials.addObjects(material, neighbor_material, face_material, tid);
4522 else
4523 for (auto && warehouse : warehouses)
4524 warehouse->addObjects(material, neighbor_material, face_material, tid);
4525
4526 // Names of all controllable parameters for this Material object
4527 const std::string & base = parameters.getBase();
4528 MooseObjectParameterName name(MooseObjectName(base, material->name()), "*");
4529 const auto param_names =
4531
4532 // Connect parameters of the primary Material object to those on the face and neighbor
4533 // objects
4534 for (const auto & p_name : param_names)
4535 {
4536 MooseObjectParameterName primary_name(MooseObjectName(base, material->name()),
4537 p_name.parameter());
4538 MooseObjectParameterName face_name(MooseObjectName(base, face_material->name()),
4539 p_name.parameter());
4540 MooseObjectParameterName neighbor_name(MooseObjectName(base, neighbor_material->name()),
4541 p_name.parameter());
4543 primary_name, face_name, false);
4545 primary_name, neighbor_name, false);
4546 }
4547 }
4548 }
4549}
4550
4551void
4552FEProblemBase::prepareMaterials(const std::unordered_set<unsigned int> & consumer_needed_mat_props,
4553 const SubdomainID blk_id,
4554 const THREAD_ID tid)
4555{
4556 std::set<MooseVariableFEBase *> needed_moose_vars;
4557 std::unordered_set<unsigned int> needed_mat_props;
4558
4559 if (_all_materials.hasActiveBlockObjects(blk_id, tid))
4560 {
4561 _all_materials.updateVariableDependency(needed_moose_vars, tid);
4562 _all_materials.updateBlockMatPropDependency(blk_id, needed_mat_props, tid);
4563 }
4564
4565 const auto & ids = _mesh.getSubdomainBoundaryIds(blk_id);
4566 for (const auto id : ids)
4567 {
4568 _materials.updateBoundaryVariableDependency(id, needed_moose_vars, tid);
4569 _materials.updateBoundaryMatPropDependency(id, needed_mat_props, tid);
4570 }
4571
4572 const auto & current_active_elemental_moose_variables = getActiveElementalMooseVariables(tid);
4573 needed_moose_vars.insert(current_active_elemental_moose_variables.begin(),
4574 current_active_elemental_moose_variables.end());
4575
4576 needed_mat_props.insert(consumer_needed_mat_props.begin(), consumer_needed_mat_props.end());
4577
4578 setActiveElementalMooseVariables(needed_moose_vars, tid);
4579 setActiveMaterialProperties(needed_mat_props, tid);
4580}
4581
4582void
4583FEProblemBase::reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful)
4584{
4586 {
4587 auto && elem = _assembly[tid][0]->elem();
4588 unsigned int n_points = _assembly[tid][0]->qRule()->n_points();
4589
4590 auto & material_data = _material_props.getMaterialData(tid);
4591 material_data.resize(n_points);
4592
4593 // Only swap if requested
4594 if (swap_stateful)
4595 material_data.swap(*elem);
4596
4598 material_data.reset(_discrete_materials.getActiveBlockObjects(blk_id, tid));
4599
4600 if (_materials.hasActiveBlockObjects(blk_id, tid))
4601 material_data.reinit(_materials.getActiveBlockObjects(blk_id, tid));
4602 }
4603}
4604
4605void
4607 const THREAD_ID tid,
4608 const bool swap_stateful,
4609 const std::deque<MaterialBase *> * const reinit_mats)
4610{
4611 // we reinit more often than needed here because we dont have a way to check whether
4612 // we need to compute the face materials on a particular (possibly external) face
4614 {
4615 auto && elem = _assembly[tid][0]->elem();
4616 unsigned int side = _assembly[tid][0]->side();
4617 unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
4618
4619 auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
4620 bnd_material_data.resize(n_points);
4621
4622 if (swap_stateful && !bnd_material_data.isSwapped())
4623 bnd_material_data.swap(*elem, side);
4624
4625 if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4626 bnd_material_data.reset(
4627 _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4628
4629 if (reinit_mats)
4630 bnd_material_data.reinit(*reinit_mats);
4631 else if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4632 bnd_material_data.reinit(
4633 _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4634 }
4635}
4636
4637void
4639 const SubdomainID blk_id,
4640 const THREAD_ID tid,
4641 const bool swap_stateful,
4642 const std::deque<MaterialBase *> * const reinit_mats)
4643{
4644 if (hasActiveMaterialProperties(tid) && (needBoundaryMaterialOnSide(boundary_id, tid) ||
4645 needInterfaceMaterialOnSide(boundary_id, tid) ||
4647 {
4648 const auto * const elem = _assembly[tid][0]->elem();
4649 unsigned int side = _assembly[tid][0]->side();
4650 unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
4651
4652 auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
4653 bnd_material_data.resize(n_points);
4654
4655 if (swap_stateful && !bnd_material_data.isSwapped())
4656 bnd_material_data.swap(*elem, side);
4657
4658 if (_discrete_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4659 bnd_material_data.reset(
4660 _discrete_materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4661
4662 if (reinit_mats)
4663 bnd_material_data.reinit(*reinit_mats);
4664 else if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4665 bnd_material_data.reinit(
4666 _materials[Moose::FACE_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4667 }
4668}
4669
4670void
4672 const BoundaryID boundary_id,
4673 const SubdomainID blk_id,
4674 const THREAD_ID tid,
4675 const bool swap_stateful,
4676 const std::deque<MaterialBase *> * const reinit_mats)
4677{
4678 // Since objects don't declare whether they need the face or neighbor (side) material properties,
4679 // we use the same criteria for skipping material property computations as for face material
4680 // properties This could be a future optimization.
4681 if (hasActiveMaterialProperties(tid) && (needBoundaryMaterialOnSide(boundary_id, tid) ||
4682 needInterfaceMaterialOnSide(boundary_id, tid) ||
4684 reinitMaterialsNeighbor(blk_id, tid, swap_stateful, reinit_mats);
4685}
4686
4687void
4689 const THREAD_ID tid,
4690 const bool swap_stateful,
4691 const std::deque<MaterialBase *> * const reinit_mats)
4692{
4694 {
4695 // NOTE: this will not work with h-adaptivity
4696 // lindsayad: why not?
4697
4698 const Elem * neighbor = _assembly[tid][0]->neighbor();
4699 unsigned int neighbor_side = neighbor->which_neighbor_am_i(_assembly[tid][0]->elem());
4700
4701 mooseAssert(neighbor, "neighbor should be non-null");
4702 mooseAssert(blk_id == neighbor->subdomain_id(),
4703 "The provided blk_id " << blk_id << " and neighbor subdomain ID "
4704 << neighbor->subdomain_id() << " do not match.");
4705
4706 unsigned int n_points = _assembly[tid][0]->qRuleNeighbor()->n_points();
4707
4708 auto & neighbor_material_data = _neighbor_material_props.getMaterialData(tid);
4709 neighbor_material_data.resize(n_points);
4710
4711 // Only swap if requested
4712 if (swap_stateful)
4713 neighbor_material_data.swap(*neighbor, neighbor_side);
4714
4715 if (_discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4716 neighbor_material_data.reset(
4717 _discrete_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4718
4719 if (reinit_mats)
4720 neighbor_material_data.reinit(*reinit_mats);
4721 else if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
4722 neighbor_material_data.reinit(
4723 _materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveBlockObjects(blk_id, tid));
4724 }
4725}
4726
4727void
4729 const THREAD_ID tid,
4730 const bool swap_stateful,
4731 const std::deque<MaterialBase *> * const reinit_mats)
4732{
4733 if (hasActiveMaterialProperties(tid) && needBoundaryMaterialOnSide(boundary_id, tid))
4734 {
4735 auto && elem = _assembly[tid][0]->elem();
4736 unsigned int side = _assembly[tid][0]->side();
4737 unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
4738
4739 auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
4740 bnd_material_data.resize(n_points);
4741
4742 if (swap_stateful && !bnd_material_data.isSwapped())
4743 bnd_material_data.swap(*elem, side);
4744
4745 if (_discrete_materials.hasActiveBoundaryObjects(boundary_id, tid))
4746 bnd_material_data.reset(_discrete_materials.getActiveBoundaryObjects(boundary_id, tid));
4747
4748 if (reinit_mats)
4749 bnd_material_data.reinit(*reinit_mats);
4750 else if (_materials.hasActiveBoundaryObjects(boundary_id, tid))
4751 bnd_material_data.reinit(_materials.getActiveBoundaryObjects(boundary_id, tid));
4752 }
4753}
4754
4755void
4757 const THREAD_ID tid,
4758 bool swap_stateful)
4759{
4760 if (hasActiveMaterialProperties(tid) && needInterfaceMaterialOnSide(boundary_id, tid))
4761 {
4762 const Elem * const & elem = _assembly[tid][0]->elem();
4763 unsigned int side = _assembly[tid][0]->side();
4764 unsigned int n_points = _assembly[tid][0]->qRuleFace()->n_points();
4765
4766 auto & bnd_material_data = _bnd_material_props.getMaterialData(tid);
4767 bnd_material_data.resize(n_points);
4768
4769 if (swap_stateful && !bnd_material_data.isSwapped())
4770 bnd_material_data.swap(*elem, side);
4771
4772 if (_interface_materials.hasActiveBoundaryObjects(boundary_id, tid))
4773 bnd_material_data.reinit(_interface_materials.getActiveBoundaryObjects(boundary_id, tid));
4774 }
4775}
4776
4777void
4779{
4780 auto && elem = _assembly[tid][0]->elem();
4782}
4783
4784void
4786{
4787 auto && elem = _assembly[tid][0]->elem();
4788 unsigned int side = _assembly[tid][0]->side();
4790}
4791
4792void
4794{
4795 // NOTE: this will not work with h-adaptivity
4796 const Elem * neighbor = _assembly[tid][0]->neighbor();
4797 unsigned int neighbor_side =
4798 neighbor ? neighbor->which_neighbor_am_i(_assembly[tid][0]->elem()) : libMesh::invalid_uint;
4799
4800 if (!neighbor)
4801 {
4802 if (haveFV())
4803 {
4804 // If neighbor is null, then we're on the neighbor side of a mesh boundary, e.g. we're off
4805 // the mesh in ghost-land. If we're using the finite volume method, then variable values and
4806 // consequently material properties have well-defined values in this ghost region outside of
4807 // the mesh and we really do want to reinit our neighbor materials in this case. Since we're
4808 // off in ghost land it's safe to do swaps with `MaterialPropertyStorage` using the elem and
4809 // elem_side keys
4810 neighbor = _assembly[tid][0]->elem();
4811 neighbor_side = _assembly[tid][0]->side();
4812 mooseAssert(neighbor, "We should have an appropriate value for elem coming from Assembly");
4813 }
4814 else
4815 mooseError("neighbor is null in Assembly!");
4816 }
4817
4818 _neighbor_material_props.getMaterialData(tid).swapBack(*neighbor, neighbor_side);
4819}
4820
4821void
4822FEProblemBase::logAdd(const std::string & system,
4823 const std::string & name,
4824 const std::string & type,
4825 const InputParameters & params) const
4826{
4827 if (_verbose_setup != "false")
4828 _console << "[DBG] Adding " << system << " '" << name << "' of type " << type << std::endl;
4829 if (_verbose_setup == "extra")
4830 _console << params << std::endl;
4831}
4832
4833void
4835 const std::string & object_name,
4836 const std::string & var_param_name)
4837{
4838 // Due to objects like SolutionUserObject which manipulate libmesh objects
4839 // and variables directly at the back end, we need a default option here
4840 // which is going to be the pointer to the first solver system within this
4841 // problem
4842 unsigned int sys_num = 0;
4843 if (parameters.isParamValid(var_param_name))
4844 {
4845 const auto variable_name = parameters.varName(var_param_name, object_name);
4846 if (this->hasVariable(variable_name) || this->hasScalarVariable(variable_name))
4847 sys_num = getSystem(variable_name).number();
4848 }
4849 if (parameters.isParamValid("solver_sys"))
4850 {
4851 const auto var_sys_num = sys_num;
4852 sys_num = getSystemBase(parameters.get<SolverSystemName>("solver_sys")).number();
4853 if (sys_num != var_sys_num && parameters.isParamValid(var_param_name))
4854 mooseError("We dont support setting 'variable' to a variable that is not set to the same "
4855 "system as the 'solver_sys' parameter");
4856 }
4857
4858 if (_displaced_problem && parameters.have_parameter<bool>("use_displaced_mesh") &&
4859 parameters.get<bool>("use_displaced_mesh"))
4860 {
4861 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
4862 if (sys_num == _aux->number())
4863 parameters.set<SystemBase *>("_sys") = &_displaced_problem->systemBaseAuxiliary();
4864 else
4865 parameters.set<SystemBase *>("_sys") = &_displaced_problem->solverSys(sys_num);
4866 }
4867 else
4868 {
4869 // The object requested use_displaced_mesh, but it was overridden
4870 // due to there being no displacements variables in the [Mesh] block.
4871 // If that happened, update the value of use_displaced_mesh appropriately.
4872 if (!_displaced_problem && parameters.have_parameter<bool>("use_displaced_mesh") &&
4873 parameters.get<bool>("use_displaced_mesh"))
4874 parameters.set<bool>("use_displaced_mesh") = false;
4875
4876 parameters.set<SubProblem *>("_subproblem") = this;
4877
4878 if (sys_num == _aux->number())
4879 parameters.set<SystemBase *>("_sys") = _aux.get();
4880 else
4881 parameters.set<SystemBase *>("_sys") = _solver_systems[sys_num].get();
4882 }
4883}
4884
4885void
4887 const std::string & type) const
4888{
4889 if (hasUserObject(name))
4890 mooseError("A ",
4892 " already exists. You may not add a ",
4893 type,
4894 " by the same name.");
4895
4896#ifdef MOOSE_KOKKOS_ENABLED
4898 mooseError("A ",
4899 getKokkosUserObject<UserObjectBase>(name).typeAndName(),
4900 " already exists. You may not add a ",
4901 type,
4902 " by the same name.");
4903#endif
4904}
4905
4906void
4907FEProblemBase::addPostprocessor(const std::string & pp_name,
4908 const std::string & name,
4909 InputParameters & parameters)
4910{
4911#ifdef MOOSE_KOKKOS_ENABLED
4913 return addKokkosPostprocessor(pp_name, name, parameters);
4914#endif
4915
4916 checkUserObjectNameCollision(name, "Postprocessor");
4917
4918 addUserObject(pp_name, name, parameters);
4919}
4920
4921void
4922FEProblemBase::addVectorPostprocessor(const std::string & pp_name,
4923 const std::string & name,
4924 InputParameters & parameters)
4925{
4926#ifdef MOOSE_KOKKOS_ENABLED
4929#endif
4930
4931 checkUserObjectNameCollision(name, "VectorPostprocessor");
4932
4933 addUserObject(pp_name, name, parameters);
4934}
4935
4936void
4937FEProblemBase::addReporter(const std::string & type,
4938 const std::string & name,
4939 InputParameters & parameters)
4940{
4941#ifdef MOOSE_KOKKOS_ENABLED
4944#endif
4945
4947
4949}
4950
4951std::vector<std::shared_ptr<UserObject>>
4952FEProblemBase::addUserObject(const std::string & user_object_name,
4953 const std::string & name,
4954 InputParameters & parameters)
4955{
4956#ifdef MOOSE_KOKKOS_ENABLED
4958 {
4959 addKokkosUserObject(user_object_name, name, parameters);
4960 return {};
4961 }
4962#endif
4963
4964 parallel_object_only();
4965
4966 std::vector<std::shared_ptr<UserObject>> uos;
4967
4968 // Add the _subproblem and _sys parameters depending on use_displaced_mesh
4970
4971 for (const auto tid : make_range(numThreads()))
4972 {
4973 // Create the UserObject
4974 std::shared_ptr<UserObject> user_object =
4975 _factory.create<UserObject>(user_object_name, name, parameters, tid);
4976 logAdd("UserObject", name, user_object_name, parameters);
4977 uos.push_back(user_object);
4978
4979 if (tid != 0)
4980 user_object->setPrimaryThreadCopy(uos[0].get());
4981
4982 theWarehouse().add(user_object);
4983
4984 // Attempt to create all the possible UserObject types
4985 auto euo = std::dynamic_pointer_cast<ElementUserObject>(user_object);
4986 auto suo = std::dynamic_pointer_cast<SideUserObject>(user_object);
4987 auto isuo = std::dynamic_pointer_cast<InternalSideUserObject>(user_object);
4988 auto iuo = std::dynamic_pointer_cast<InterfaceUserObjectBase>(user_object);
4989 auto nuo = std::dynamic_pointer_cast<NodalUserObject>(user_object);
4990 auto duo = std::dynamic_pointer_cast<DomainUserObject>(user_object);
4991 auto guo = std::dynamic_pointer_cast<GeneralUserObject>(user_object);
4992 auto tguo = std::dynamic_pointer_cast<ThreadedGeneralUserObject>(user_object);
4993 auto muo = std::dynamic_pointer_cast<MortarUserObject>(user_object);
4994
4995 // Account for displaced mesh use
4996 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
4997 {
4998 // Whether to re-init or not depends on the attributes of the base classes.
4999 // For example, InterfaceUOBase has "_current_side_elem" and "_neighbor_elem"
5000 // so it needs to reinit on displaced neighbors and faces
5001 // _reinit_displaced_elem -> _current_elem will be reinited
5002 // _reinit_displaced_face -> _current_elem, lowerD if any and _current_side_elem to be
5003 // reinited _reinit_displaced_neighbor -> _current_elem, lowerD if any and _current_neighbor
5004 // to be reinited Note that as soon as you use materials on the displaced mesh, all three get
5005 // turned on.
5006 if (euo || nuo || duo)
5008 if (suo || duo || isuo || iuo)
5010 if (iuo || duo || isuo)
5012 }
5013
5014 // These objects only require one thread
5015 if ((guo && !tguo) || muo)
5016 break;
5017 }
5018
5019 // Add as a Functor if it is one. We usually need to add the user object from thread 0 as the
5020 // registered functor for all threads because when user objects are thread joined, generally only
5021 // the primary thread copy ends up with all the data
5022 for (const auto tid : make_range(numThreads()))
5023 {
5024 const decltype(uos)::size_type uo_index = uos.front()->needThreadedCopy() ? tid : 0;
5025 if (const auto functor = dynamic_cast<Moose::FunctorBase<Real> *>(uos[uo_index].get()))
5026 {
5027 this->addFunctor(name, *functor, tid);
5029 _displaced_problem->addFunctor(name, *functor, tid);
5030 }
5031 }
5032
5033 return uos;
5034}
5035
5036void
5037FEProblemBase::addFVInterpolationMethod(const std::string & method_type,
5038 const std::string & name,
5039 InputParameters & parameters)
5040{
5041 parallel_object_only();
5042
5044
5045 for (const auto tid : make_range(numThreads()))
5046 {
5047 auto method = _factory.create<FVInterpolationMethod>(method_type, name, parameters, tid);
5048 logAdd("FVInterpolationMethod", name, method_type, parameters);
5049 theWarehouse().add(method);
5050 }
5051}
5052
5053void
5054FEProblemBase::addFVGradientMethod(const std::string & method_type,
5055 const std::string & name,
5056 InputParameters & parameters)
5057{
5058 parallel_object_only();
5059
5061
5062 for (const auto tid : make_range(libMesh::n_threads()))
5063 {
5064 auto method = _factory.create<FVGradientMethod>(method_type, name, parameters, tid);
5065 logAdd("FVGradientMethod", name, method_type, parameters);
5066 theWarehouse().add(method);
5067 }
5068}
5069
5070const UserObject &
5071FEProblemBase::getUserObjectBase(const std::string & name, const THREAD_ID tid /* = 0 */) const
5072{
5073 std::vector<UserObject *> objs;
5074 theWarehouse()
5075 .query()
5076 .condition<AttribSystem>("UserObject")
5077 .condition<AttribThread>(tid)
5078 .condition<AttribName>(name)
5079 .queryInto(objs);
5080 if (objs.empty())
5081 {
5082 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_user_object"),
5083 "A UserObject getter was called before UserObjects have been constructed. The "
5084 "requested UserObject '" +
5085 name + "' may exist in the input file, but UserObjects are not available yet.");
5086
5087 mooseError("Unable to find user object with name '" + name + "'");
5088 }
5089 mooseAssert(objs.size() == 1, "Should only find one UO");
5090 return *(objs[0]);
5091}
5092
5093const Positions &
5094FEProblemBase::getPositionsObject(const std::string & name) const
5095{
5096 std::vector<Positions *> objs;
5097 theWarehouse()
5098 .query()
5099 .condition<AttribSystem>("UserObject")
5100 .condition<AttribName>(name)
5101 .queryInto(objs);
5102 if (objs.empty())
5103 mooseError("Unable to find Positions object with name '" + name + "'");
5104 mooseAssert(objs.size() == 1, "Should only find one Positions");
5105 return *(objs[0]);
5106}
5107
5108bool
5109FEProblemBase::hasUserObject(const std::string & name) const
5110{
5111 std::vector<UserObject *> objs;
5112 theWarehouse()
5113 .query()
5114 .condition<AttribSystem>("UserObject")
5115 .condition<AttribThread>(0)
5116 .condition<AttribName>(name)
5117 .queryInto(objs);
5118 return !objs.empty();
5119}
5120
5121const FVGradientMethod &
5122FEProblemBase::getFVGradientMethod(const GradientMethodName & name, const THREAD_ID tid) const
5123{
5124 std::vector<FVGradientMethod *> methods;
5125 theWarehouse()
5126 .query()
5127 .condition<AttribSystem>("FVGradientMethod")
5128 .condition<AttribThread>(tid)
5129 .condition<AttribName>(name)
5130 .queryInto(methods);
5131
5132 if (methods.empty())
5133 mooseError("Unable to find FVGradientMethod with name '", name, "'");
5134
5135 mooseAssert(methods.size() == 1, "Expected a single FVGradientMethod per thread");
5136 return *(methods[0]);
5137}
5138
5140FEProblemBase::getFVGradientMethod(const GradientMethodName & name, const THREAD_ID tid)
5141{
5142 return const_cast<FVGradientMethod &>(
5143 static_cast<const FEProblemBase &>(*this).getFVGradientMethod(name, tid));
5144}
5145
5146bool
5147FEProblemBase::hasFVGradientMethod(const GradientMethodName & name) const
5148{
5149 std::vector<FVGradientMethod *> methods;
5150 theWarehouse()
5151 .query()
5152 .condition<AttribSystem>("FVGradientMethod")
5153 .condition<AttribThread>(0)
5154 .condition<AttribName>(name)
5155 .queryInto(methods);
5156 return !methods.empty();
5157}
5158
5160FEProblemBase::getFVInterpolationMethod(const InterpolationMethodName & name,
5161 const THREAD_ID tid) const
5162{
5163 std::vector<FVInterpolationMethod *> methods;
5164 theWarehouse()
5165 .query()
5166 .condition<AttribSystem>("FVInterpolationMethod")
5167 .condition<AttribThread>(tid)
5168 .condition<AttribName>(name)
5169 .queryInto(methods);
5170
5171 if (methods.empty())
5172 {
5173 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_interpolation_method"),
5174 "An FVInterpolationMethod getter was called before FVInterpolationMethods have "
5175 "been constructed. If you are attempting to access this object in the constructor "
5176 "of another object then make sure that the FVInterpolationMethod is constructed "
5177 "before the object using it.");
5178
5179 mooseError("Unable to find FVInterpolationMethod with name '", name, "'");
5180 }
5181
5182 mooseAssert(methods.size() == 1, "Expected a single FVInterpolationMethod per thread");
5183 return *(methods[0]);
5184}
5185
5187FEProblemBase::getFVFaceInterpolationMethod(const InterpolationMethodName & name,
5188 const THREAD_ID tid) const
5189{
5190 const auto & method = getFVInterpolationMethod(name, tid);
5191 const auto * face_method = dynamic_cast<const FVFaceInterpolationMethod *>(&method);
5192
5193 if (!face_method)
5194 mooseError("FVInterpolationMethod '",
5195 name,
5196 "' (",
5197 method.type(),
5198 ") is not a scalar face interpolation method.");
5199
5200 return *face_method;
5201}
5202
5204FEProblemBase::getFVAdvectedInterpolationMethod(const InterpolationMethodName & name,
5205 const THREAD_ID tid) const
5206{
5207 const auto & method = getFVInterpolationMethod(name, tid);
5208 const auto * advected_method = dynamic_cast<const FVAdvectedInterpolationMethod *>(&method);
5209
5210 if (!advected_method)
5211 mooseError("FVInterpolationMethod '",
5212 name,
5213 "' (",
5214 method.type(),
5215 ") is not an advected interpolation method.");
5216
5217 return *advected_method;
5218}
5219
5220bool
5221FEProblemBase::hasFVInterpolationMethod(const InterpolationMethodName & name) const
5222{
5223 std::vector<FVInterpolationMethod *> methods;
5224 theWarehouse()
5225 .query()
5226 .condition<AttribSystem>("FVInterpolationMethod")
5227 .condition<AttribThread>(0)
5228 .condition<AttribName>(name)
5229 .queryInto(methods);
5230 return !methods.empty();
5231}
5232
5233bool
5238
5239const Postprocessor &
5240FEProblemBase::getPostprocessorObjectByName(const PostprocessorName & object_name,
5241 const THREAD_ID tid) const
5242{
5243 std::vector<Postprocessor *> objs;
5244 theWarehouse()
5245 .query()
5247 .condition<AttribThread>(tid)
5248 .condition<AttribName>(object_name)
5249 .queryInto(objs);
5250
5251 if (objs.empty())
5252 mooseError("Unable to find Postprocessor with name '", object_name, "'");
5253 mooseAssert(objs.size() == 1,
5254 "We shouldn't find more than one postprocessor object for a given name");
5255 return *(objs[0]);
5256}
5257
5258const PostprocessorValue &
5259FEProblemBase::getPostprocessorValueByName(const PostprocessorName & name,
5260 std::size_t t_index) const
5261{
5263 t_index);
5264}
5265
5266void
5267FEProblemBase::setPostprocessorValueByName(const PostprocessorName & name,
5268 const PostprocessorValue & value,
5269 std::size_t t_index)
5270{
5272 PostprocessorReporterName(name), value, t_index);
5273}
5274
5275bool
5276FEProblemBase::hasPostprocessor(const std::string & name) const
5277{
5278 mooseDeprecated("FEProblemBase::hasPostprocssor is being removed; use "
5279 "hasPostprocessorValueByName instead.");
5281}
5282
5285 const std::string & vector_name,
5286 std::size_t t_index) const
5287{
5289 VectorPostprocessorReporterName(object_name, vector_name), t_index);
5290}
5291
5292void
5294 const std::string & vector_name,
5295 const VectorPostprocessorValue & value,
5296 std::size_t t_index)
5297{
5299 VectorPostprocessorReporterName(object_name, vector_name), value, t_index);
5300}
5301
5302const VectorPostprocessor &
5304 const THREAD_ID tid) const
5305{
5306 std::vector<VectorPostprocessor *> objs;
5307 theWarehouse()
5308 .query()
5310 .condition<AttribThread>(tid)
5311 .condition<AttribName>(object_name)
5312 .queryInto(objs);
5313
5314 if (objs.empty())
5315 {
5316 mooseAssert(
5317 getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor"),
5318 "A VectorPostprocessor getter was called before VectorPostprocessors have been "
5319 "constructed. The requested VectorPostprocessor '" +
5320 object_name +
5321 "' may exist in the input file, but VectorPostprocessors are not available yet.");
5322
5323 mooseError("Unable to find VectorPostprocessor with name '", object_name, "'");
5324 }
5325 mooseAssert(objs.size() == 1,
5326 "We shouldn't find more than one vector postprocessor object for a given name");
5327 return *(objs[0]);
5328}
5329
5330void
5332{
5333 for (const auto & it : _multi_apps)
5334 {
5335 const auto & objects = it.second.getActiveObjects();
5336 for (const auto & obj : objects)
5337 obj->parentOutputPositionChanged();
5338 }
5339}
5340
5341void
5347
5348void
5350{
5351 // Initialize indicator aux variable fields
5353 {
5354 TIME_SECTION("computeIndicators", 1, "Computing Indicators");
5355
5356 // Internal side indicators may lead to creating a much larger sparsity pattern than dictated by
5357 // the actual finite element scheme (e.g. CFEM)
5358 const auto old_do_derivatives = ADReal::do_derivatives;
5359 ADReal::do_derivatives = false;
5360
5361 std::vector<std::string> fields;
5362
5363 // Indicator Fields
5364 const auto & indicators = _indicators.getActiveObjects();
5365 for (const auto & indicator : indicators)
5366 fields.push_back(indicator->name());
5367
5368 // InternalSideIndicator Fields
5369 const auto & internal_indicators = _internal_side_indicators.getActiveObjects();
5370 for (const auto & internal_indicator : internal_indicators)
5371 fields.push_back(internal_indicator->name());
5372
5373 _aux->zeroVariables(fields);
5374
5375 // compute Indicators
5376 ComputeIndicatorThread cit(*this);
5378 _aux->solution().close();
5379 _aux->update();
5380
5381 ComputeIndicatorThread finalize_cit(*this, true);
5383 _aux->solution().close();
5384 _aux->update();
5385
5386 ADReal::do_derivatives = old_do_derivatives;
5387 }
5388}
5389
5390void
5392{
5394 {
5395 TIME_SECTION("computeMarkers", 1, "Computing Markers");
5396
5397 std::vector<std::string> fields;
5398
5399 // Marker Fields
5400 const auto & markers = _markers.getActiveObjects();
5401 for (const auto & marker : markers)
5402 fields.push_back(marker->name());
5403
5404 _aux->zeroVariables(fields);
5405
5407
5408 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
5409 {
5410 const auto & markers = _markers.getActiveObjects(tid);
5411 for (const auto & marker : markers)
5412 marker->markerSetup();
5413 }
5414
5415 ComputeMarkerThread cmt(*this);
5417
5418 _aux->solution().close();
5419 _aux->update();
5420 }
5421}
5422
5423const ExecFlagType &
5428
5429void
5434
5435void
5437{
5438}
5439
5440void
5442{
5443 SubProblem::customSetup(exec_type);
5444
5445 if (_line_search)
5446 _line_search->customSetup(exec_type);
5447
5448 unsigned int n_threads = numThreads();
5449 for (THREAD_ID tid = 0; tid < n_threads; tid++)
5450 {
5451 _all_materials.customSetup(exec_type, tid);
5452 _functions.customSetup(exec_type, tid);
5453 }
5454
5455#ifdef MOOSE_KOKKOS_ENABLED
5456 _kokkos_functions.customSetup(exec_type);
5457#endif
5458
5459 _aux->customSetup(exec_type);
5460 for (auto & nl : _nl)
5461 nl->customSetup(exec_type);
5462
5464 _displaced_problem->customSetup(exec_type);
5465
5466 for (THREAD_ID tid = 0; tid < n_threads; tid++)
5467 {
5468 _internal_side_indicators.customSetup(exec_type, tid);
5469 _indicators.customSetup(exec_type, tid);
5470 _markers.customSetup(exec_type, tid);
5471 }
5472
5473 std::vector<UserObject *> userobjs;
5474 theWarehouse().query().condition<AttribSystem>("UserObject").queryIntoUnsorted(userobjs);
5475 for (auto obj : userobjs)
5476 obj->customSetup(exec_type);
5477
5478#ifdef MOOSE_KOKKOS_ENABLED
5479 {
5480 std::vector<UserObjectBase *> userobjs;
5481 theWarehouse().query().condition<AttribSystem>("KokkosUserObject").queryIntoUnsorted(userobjs);
5482 for (auto obj : userobjs)
5483 obj->customSetup(exec_type);
5484 }
5485#endif
5486
5487 _app.getOutputWarehouse().customSetup(exec_type);
5488}
5489
5490void
5492{
5493 // Set the current flag
5494 setCurrentExecuteOnFlag(exec_type);
5495
5496 if (exec_type != EXEC_INITIAL)
5497 executeControls(exec_type);
5498
5499 // intentially call this after executing controls because the setups may rely on the controls
5500 // FIXME: we skip the following flags because they have dedicated setup functions in
5501 // SetupInterface and it may not be appropriate to call them here.
5502 if (!(exec_type == EXEC_INITIAL || exec_type == EXEC_TIMESTEP_BEGIN ||
5503 exec_type == EXEC_SUBDOMAIN || exec_type == EXEC_NONLINEAR || exec_type == EXEC_LINEAR))
5504 customSetup(exec_type);
5505
5506 executeSamplers(exec_type);
5507
5508 // Pre-aux UserObjects
5510
5511 // Systems (includes system time derivative and aux kernel calculations)
5512 computeSystems(exec_type);
5513 // With the auxiliary system solution computed, sync the displaced problem auxiliary solution
5514 // before computation of post-aux user objects. The undisplaced auxiliary system current local
5515 // solution is updated (via System::update) within the AuxiliarySystem class's variable
5516 // computation methods (e.g. computeElementalVarsHelper, computeNodalVarsHelper), so it is safe to
5517 // use it here
5519 _displaced_problem->syncAuxSolution(*getAuxiliarySystem().currentSolution());
5520
5521 // Post-aux UserObjects
5523
5524 // Return the current flag to None
5526
5528 {
5529 // we will only check aux variables and postprocessors
5530 // checking more reporter data can be added in the future if needed
5531 std::unique_ptr<NumericVector<Number>> x = _aux->currentSolution()->clone();
5532 DenseVector<Real> pp_values = getReporterData().getAllRealReporterValues();
5533
5534 // call THIS execute one more time for checking the possible states
5536 FEProblemBase::execute(exec_type);
5537 _checking_uo_aux_state = false;
5538
5539 const Real check_tol = 1e-8;
5540
5541 const Real xnorm = x->l2_norm();
5542 *x -= *_aux->currentSolution();
5543 if (x->l2_norm() > check_tol * xnorm)
5544 {
5545 const auto & sys = _aux->system();
5546 const unsigned int n_vars = sys.n_vars();
5547 std::multimap<Real, std::string, std::greater<Real>> ordered_map;
5548 for (const auto i : make_range(n_vars))
5549 {
5550 const Real vnorm = sys.calculate_norm(*x, i, DISCRETE_L2);
5551 ordered_map.emplace(vnorm, sys.variable_name(i));
5552 }
5553
5554 std::ostringstream oss;
5555 for (const auto & [error_norm, var_name] : ordered_map)
5556 oss << " {" << var_name << ", " << error_norm << "},\n";
5557
5558 mooseError("Aux kernels, user objects appear to have states for aux variables on ",
5559 exec_type,
5560 ".\nVariable error norms in descending order:\n",
5561 oss.str());
5562 }
5563
5564 const DenseVector<Real> new_pp_values = getReporterData().getAllRealReporterValues();
5565 if (pp_values.size() != new_pp_values.size())
5566 mooseError("Second execution for uo/aux state check should not change the number of "
5567 "real reporter values");
5568
5569 const Real ppnorm = pp_values.l2_norm();
5570 pp_values -= new_pp_values;
5571 if (pp_values.l2_norm() > check_tol * ppnorm)
5572 {
5573 const auto pp_names = getReporterData().getAllRealReporterFullNames();
5574 std::multimap<Real, std::string, std::greater<Real>> ordered_map;
5575 for (const auto i : index_range(pp_names))
5576 ordered_map.emplace(std::abs(pp_values(i)), pp_names[i]);
5577
5578 std::ostringstream oss;
5579 for (const auto & [error_norm, pp_name] : ordered_map)
5580 oss << " {" << pp_name << ", " << error_norm << "},\n";
5581
5582 mooseError("Aux kernels, user objects appear to have states for real reporter values on ",
5583 exec_type,
5584 ".\nErrors of real reporter values in descending order:\n",
5585 oss.str());
5586 }
5587 }
5588}
5589
5590// Finalize, threadJoin, and update PP values of Elemental/Nodal/Side/InternalSideUserObjects
5591void
5593{
5594 std::vector<UserObject *> objs;
5595 query.queryInto(objs);
5596 // The same user objects exist on every process, so every process returns here or none does
5597 if (objs.empty())
5598 return;
5599
5600 if (!isgen)
5601 {
5602 // join all threaded user objects (i.e. not regular general user objects) to the primary
5603 // thread
5605 [&objs]()
5606 {
5607 for (auto obj : objs)
5608 if (obj->primaryThreadCopy())
5609 obj->primaryThreadCopy()->threadJoin(*obj);
5610 });
5612 }
5613
5614 query.condition<AttribThread>(0).queryInto(objs);
5615
5616 // finalize objects and retrieve/store any postprocessor values
5617 for (auto obj : objs)
5618 {
5619 if (isgen && dynamic_cast<ThreadedGeneralUserObject *>(obj))
5620 continue;
5621 if (isgen)
5622 {
5623 // general user objects are not run in their own threaded loop object - so run them here
5624 if (shouldPrintExecution(0))
5625 _console << "[DBG] Initializing, executing & finalizing general UO '" << obj->name()
5626 << "' on " << _current_execute_on_flag.name() << std::endl;
5628 [obj]()
5629 {
5630 obj->initialize();
5631 obj->execute();
5632 });
5634 }
5635
5636 // An exception raised by finalize() is communicated once all objects have been finalized, so
5637 // that a process raising one does not skip the communication in the finalize() of the
5638 // remaining objects
5639 translateUserObjectExceptions([obj]() { obj->finalize(); });
5640
5641 // These have to be stored piecemeal (with every call to this function) because general
5642 // postprocessors (which run last after other userobjects have been completed) might depend on
5643 // them being stored. This wouldn't be a problem if all userobjects satisfied the dependency
5644 // resolver interface and could be sorted appropriately with the general userobjects, but they
5645 // don't.
5646 auto pp = dynamic_cast<const Postprocessor *>(obj);
5647 if (pp)
5648 {
5649 _reporter_data.finalize(obj->name());
5650 setPostprocessorValueByName(obj->name(), pp->getValue());
5651 }
5652
5653 auto vpp = dynamic_cast<VectorPostprocessor *>(obj);
5654 if (vpp)
5655 _reporter_data.finalize(obj->name());
5656
5657 // Update Reporter data
5658 auto reporter = dynamic_cast<Reporter *>(obj);
5659 if (reporter)
5660 _reporter_data.finalize(obj->name());
5661 }
5662
5664}
5665
5667FEProblemBase::getUOQuery(const std::string & system,
5668 const ExecFlagType & type,
5669 const Moose::AuxGroup & group) const
5670{
5672 theWarehouse().query().condition<AttribSystem>(system).condition<AttribExecOns>(type);
5673
5674 if (group == Moose::PRE_IC)
5675 query.condition<AttribPreIC>(true);
5676 else if (group == Moose::PRE_AUX)
5677 query.condition<AttribPreAux>(type);
5678 else if (group == Moose::POST_AUX)
5679 query.condition<AttribPostAux>(type);
5680
5681 return query;
5682}
5683
5684void
5686 std::set<int> & execution_groups) const
5687{
5688 std::vector<UserObjectBase *> uos;
5689 query.queryIntoUnsorted(uos);
5690 for (const auto & uo : uos)
5691 execution_groups.insert(uo->getParam<int>("execution_order_group"));
5692}
5693
5694void
5696 const Moose::AuxGroup & group,
5697 const std::string & name)
5698{
5699 const auto old_exec_flag = _current_execute_on_flag;
5701
5702 std::set<int> execution_groups;
5703
5704#ifdef MOOSE_KOKKOS_ENABLED
5705 TheWarehouse::Query kokkos_query =
5706 getUOQuery("KokkosUserObject", type, group).condition<AttribName>(name);
5707 getUOExecutionGroups(kokkos_query, execution_groups);
5708#endif
5709
5711 getUOExecutionGroups(query, execution_groups);
5712
5713 for (const auto execution_group : execution_groups)
5714 {
5715#ifdef MOOSE_KOKKOS_ENABLED
5717 type, kokkos_query.clone().condition<AttribExecutionOrderGroup>(execution_group));
5718#endif
5719
5721 query.clone().condition<AttribExecutionOrderGroup>(execution_group));
5722 }
5723
5724 _current_execute_on_flag = old_exec_flag;
5725}
5726
5727void
5729{
5730 std::set<int> execution_groups;
5731
5732#ifdef MOOSE_KOKKOS_ENABLED
5733 TheWarehouse::Query kokkos_query = getUOQuery("KokkosUserObject", type, group);
5734 getUOExecutionGroups(kokkos_query, execution_groups);
5735#endif
5736
5737 TheWarehouse::Query query = getUOQuery("UserObject", type, group);
5738 getUOExecutionGroups(query, execution_groups);
5739
5740 for (const auto execution_group : execution_groups)
5741 {
5742#ifdef MOOSE_KOKKOS_ENABLED
5744 type, kokkos_query.clone().condition<AttribExecutionOrderGroup>(execution_group));
5745#endif
5746
5748 query.clone().condition<AttribExecutionOrderGroup>(execution_group));
5749 }
5750
5751 // Exceptions raised on solver execution flags are communicated and handled by the PARALLEL_CATCH
5752 // surrounding the assembly loops of the residual, Jacobian and linear systems. On all other
5753 // execution flags there is no solve left to fail, so the exception is communicated here in order
5754 // to report it at the point of the simulation where it was raised
5757}
5758
5759void
5761{
5762 TIME_SECTION("computeUserObjects", 1, "Computing User Objects");
5763
5764 std::vector<GeneralUserObject *> genobjs;
5765 query.clone().condition<AttribInterfaces>(Interfaces::GeneralUserObject).queryInto(genobjs);
5766
5767 std::vector<UserObject *> userobjs;
5768 query.clone()
5772 .queryInto(userobjs);
5773
5774 std::vector<UserObject *> tgobjs;
5775 query.clone()
5777 .queryInto(tgobjs);
5778
5779 std::vector<UserObject *> nodal;
5780 query.clone().condition<AttribInterfaces>(Interfaces::NodalUserObject).queryInto(nodal);
5781
5782 std::vector<MortarUserObject *> mortar;
5783 query.clone().condition<AttribInterfaces>(Interfaces::MortarUserObject).queryInto(mortar);
5784
5785 if (userobjs.empty() && genobjs.empty() && tgobjs.empty() && nodal.empty() && mortar.empty())
5786 return;
5787
5788 // Start the timer here since we have at least one active user object
5789 std::string compute_uo_tag = "computeUserObjects(" + Moose::stringify(type) + ")";
5790
5791 // Each phase of process-local work below is followed by a check for an exception on any process
5792 // before the phase's user objects are finalized, because finalization communicates. An exception
5793 // stops the execution of user objects on all processes, so that none is finalized with partial
5794 // data
5796 [&]()
5797 {
5798 // Perform Residual/Jacobian setups
5799 if (type == EXEC_LINEAR)
5800 {
5801 for (auto obj : userobjs)
5802 obj->residualSetup();
5803 for (auto obj : nodal)
5804 obj->residualSetup();
5805 for (auto obj : mortar)
5806 obj->residualSetup();
5807 for (auto obj : tgobjs)
5808 obj->residualSetup();
5809 for (auto obj : genobjs)
5810 obj->residualSetup();
5811 }
5812 else if (type == EXEC_NONLINEAR)
5813 {
5814 for (auto obj : userobjs)
5815 obj->jacobianSetup();
5816 for (auto obj : nodal)
5817 obj->jacobianSetup();
5818 for (auto obj : mortar)
5819 obj->jacobianSetup();
5820 for (auto obj : tgobjs)
5821 obj->jacobianSetup();
5822 for (auto obj : genobjs)
5823 obj->jacobianSetup();
5824 }
5825
5826 for (auto obj : userobjs)
5827 obj->initialize();
5828
5829 // Execute Side/InternalSide/Interface/Elemental/DomainUserObjects
5830 if (!userobjs.empty())
5831 {
5832 // non-nodal user objects have to be run separately before the nodal user objects run
5833 // because some nodal user objects (NodalNormal related) depend on elemental user objects
5834 // :-(
5835 ComputeUserObjectsThread cppt(*this, query);
5837 }
5838 });
5840
5841 if (!userobjs.empty())
5842 {
5843 // There is one instance in rattlesnake where an elemental user object's finalize depends
5844 // on a side user object having been finalized first :-(
5850 }
5851
5852 // if any elemental user object may have written to variables we need to close the aux solution
5853 for (const auto & uo : userobjs)
5854 if (auto euo = dynamic_cast<const ElementUserObject *>(uo);
5855 euo && euo->hasWritableCoupledVariables())
5856 {
5857 _aux->solution().close();
5858 _aux->system().update();
5859 break;
5860 }
5861
5862 // Execute NodalUserObjects
5863 // BISON has an axial reloc elemental user object that has a finalize func that depends on a
5864 // nodal user object's prev value. So we can't initialize this until after elemental objects
5865 // have been finalized :-(
5866 if (!nodal.empty())
5867 {
5869 [&]()
5870 {
5871 for (auto obj : nodal)
5872 obj->initialize();
5875 });
5878 }
5879
5880 // if any nodal user object may have written to variables we need to close the aux solution
5881 for (const auto & uo : nodal)
5882 if (auto nuo = dynamic_cast<const NodalUserObject *>(uo);
5883 nuo && nuo->hasWritableCoupledVariables())
5884 {
5885 _aux->solution().close();
5886 _aux->system().update();
5887 break;
5888 }
5889
5890 // Execute MortarUserObjects
5891 if (!mortar.empty())
5892 {
5894 [this, type, &mortar]()
5895 {
5896 for (auto obj : mortar)
5897 obj->initialize();
5898
5899 auto create_and_run_mortar_functors = [this, type, &mortar](const bool displaced)
5900 {
5901 // go over mortar interfaces and construct functors
5902 const auto & mortar_interfaces = getMortarInterfaces(displaced);
5903 for (const auto & [primary_secondary_boundary_pair, interface_config] :
5904 mortar_interfaces)
5905 {
5906 auto mortar_uos_to_execute =
5907 getMortarUserObjects(primary_secondary_boundary_pair.first,
5908 primary_secondary_boundary_pair.second,
5909 displaced,
5910 mortar);
5911
5912 auto * const subproblem = displaced ? cast_ptr<SubProblem *>(_displaced_problem.get())
5913 : cast_ptr<SubProblem *>(this);
5914 MortarUserObjectThread muot(mortar_uos_to_execute,
5915 *interface_config.amg,
5916 *subproblem,
5917 *this,
5918 displaced,
5919 subproblem->assembly(0, 0));
5920
5921 muot();
5922 }
5923 };
5924
5925 create_and_run_mortar_functors(false);
5927 create_and_run_mortar_functors(true);
5928 });
5930
5932 [&mortar]()
5933 {
5934 for (auto obj : mortar)
5935 obj->finalize();
5936 });
5938 }
5939
5940 // Execute threaded general user objects
5941 if (!tgobjs.empty())
5942 {
5944 [&tgobjs]()
5945 {
5946 for (auto obj : tgobjs)
5947 obj->initialize();
5948 });
5950 }
5951 std::vector<GeneralUserObject *> tguos_zero;
5952 query.clone()
5953 .condition<AttribThread>(0)
5954 .condition<AttribInterfaces>(Interfaces::ThreadedGeneralUserObject)
5955 .queryInto(tguos_zero);
5956 for (auto obj : tguos_zero)
5957 {
5958 std::vector<GeneralUserObject *> tguos;
5959 auto q = query.clone()
5960 .condition<AttribName>(obj->name())
5961 .condition<AttribInterfaces>(Interfaces::ThreadedGeneralUserObject);
5962 q.queryInto(tguos);
5963
5965 [this, &tguos]()
5966 {
5968
5969 // Force one thread per ThreadedGeneralUserObject via grainsize
5971 tguos.end(),
5972 /*grainsize=*/1),
5973 ctguot,
5974 numThreads());
5975 });
5977 joinAndFinalize(q);
5978 }
5979
5980 // Execute general user objects
5982}
5983
5984void
5986{
5987 if (_control_warehouse[exec_type].hasActiveObjects())
5988 {
5989 TIME_SECTION("executeControls", 1, "Executing Controls");
5990
5992
5993 auto controls_wh = _control_warehouse[exec_type];
5994 // Add all of the dependencies into the resolver and sort them
5995 for (const auto & it : controls_wh.getActiveObjects())
5996 {
5997 // Make sure an item with no dependencies comes out too!
5998 resolver.addItem(it);
5999
6000 std::vector<std::string> & dependent_controls = it->getDependencies();
6001 for (const auto & depend_name : dependent_controls)
6002 {
6003 if (controls_wh.hasActiveObject(depend_name))
6004 {
6005 auto dep_control = controls_wh.getActiveObject(depend_name);
6006 resolver.addEdge(dep_control, it);
6007 }
6008 else
6009 mooseError("The Control \"",
6010 depend_name,
6011 "\" was not created, did you make a "
6012 "spelling mistake or forget to include it "
6013 "in your input file?");
6014 }
6015 }
6016
6017 const auto & ordered_controls = resolver.getSortedValues();
6018
6019 if (!ordered_controls.empty())
6020 {
6021 // already called by initialSetup when exec_type == EXEC_INITIAL
6022 if (exec_type != EXEC_INITIAL)
6023 _control_warehouse.setup(exec_type);
6024
6025 // Run the controls in the proper order
6026 for (const auto & control : ordered_controls)
6027 control->execute();
6028 }
6029 }
6030}
6031
6032void
6034{
6035 // TODO: This should be done in a threaded loop, but this should be super quick so for now
6036 // do a serial loop.
6037 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
6038 {
6039 std::vector<Sampler *> objects;
6040 theWarehouse()
6041 .query()
6042 .condition<AttribSystem>("Sampler")
6043 .condition<AttribThread>(tid)
6044 .condition<AttribExecOns>(exec_type)
6045 .queryInto(objects);
6046
6047 if (!objects.empty())
6048 {
6049 TIME_SECTION("executeSamplers", 1, "Executing Samplers");
6050 FEProblemBase::objectSetupHelper<Sampler>(objects, exec_type);
6051 FEProblemBase::objectExecuteHelper<Sampler>(objects);
6052 }
6053 }
6054}
6055
6056void
6058{
6059 TIME_SECTION("updateActiveObjects", 5, "Updating Active Objects");
6060
6061 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
6062 {
6063 for (auto & nl : _nl)
6064 nl->updateActive(tid);
6065 _aux->updateActive(tid);
6072 }
6073
6081
6082#ifdef MOOSE_KOKKOS_ENABLED
6084#endif
6085}
6086
6087void
6089{
6090 //<< "Object " << a->name() << " -> " << b->name() << std::endl;
6091}
6092
6093void
6095{
6096 TIME_SECTION("reinitBecauseOfGhostingOrNewGeomObjects",
6097 3,
6098 "Reinitializing Because of Geometric Search Objects");
6099
6100 // Need to see if _any_ processor has ghosted elems or geometry objects.
6101 bool needs_reinit = !_ghosted_elems.empty();
6102 needs_reinit = needs_reinit || !_geometric_search_data._nearest_node_locators.empty() ||
6103 (_mortar_data->hasObjects() && mortar_changed);
6104 needs_reinit =
6105 needs_reinit || (_displaced_problem &&
6106 (!_displaced_problem->geomSearchData()._nearest_node_locators.empty() ||
6107 (_mortar_data->hasDisplacedObjects() && mortar_changed)));
6108 _communicator.max(needs_reinit);
6109
6110 if (needs_reinit)
6111 {
6112 // Call reinit to get the ghosted vectors correct now that some geometric search has been done
6113 es().reinit();
6114
6115 if (_displaced_mesh)
6116 _displaced_problem->es().reinit();
6117 }
6118}
6119
6120void
6121FEProblemBase::addDamper(const std::string & damper_name,
6122 const std::string & name,
6123 InputParameters & parameters)
6124{
6125 parallel_object_only();
6126
6127 const auto nl_sys_num =
6128 parameters.isParamValid("variable")
6129 ? determineSolverSystem(parameters.varName("variable", name), true).second
6130 : (unsigned int)0;
6131
6132 if (!isSolverSystemNonlinear(nl_sys_num))
6133 mooseError("You are trying to add a DGKernel to a linear variable/system, which is not "
6134 "supported at the moment!");
6135
6136 parameters.set<SubProblem *>("_subproblem") = this;
6137 parameters.set<SystemBase *>("_sys") = _nl[nl_sys_num].get();
6138
6139 _has_dampers = true;
6140 logAdd("Damper", name, damper_name, parameters);
6141 _nl[nl_sys_num]->addDamper(damper_name, name, parameters);
6142}
6143
6144void
6146{
6147 for (auto & nl : _nl)
6148 nl->setupDampers();
6149}
6150
6151void
6152FEProblemBase::addIndicator(const std::string & indicator_name,
6153 const std::string & name,
6154 InputParameters & parameters)
6155{
6156 parallel_object_only();
6157
6158 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
6159 {
6160 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
6161 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
6163 }
6164 else
6165 {
6166 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
6167 {
6168 // We allow Indicators to request that they use_displaced_mesh,
6169 // but then be overridden when no displacements variables are
6170 // provided in the Mesh block. If that happened, update the value
6171 // of use_displaced_mesh appropriately for this Indicator.
6172 if (parameters.have_parameter<bool>("use_displaced_mesh"))
6173 parameters.set<bool>("use_displaced_mesh") = false;
6174 }
6175
6176 parameters.set<SubProblem *>("_subproblem") = this;
6177 parameters.set<SystemBase *>("_sys") = _aux.get();
6178 }
6179
6180 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
6181 {
6182 std::shared_ptr<Indicator> indicator =
6183 _factory.create<Indicator>(indicator_name, name, parameters, tid);
6184 logAdd("Indicator", name, indicator_name, parameters);
6185 std::shared_ptr<InternalSideIndicatorBase> isi =
6186 std::dynamic_pointer_cast<InternalSideIndicatorBase>(indicator);
6187 if (isi)
6189 else
6190 _indicators.addObject(indicator, tid);
6191 }
6192}
6193
6194void
6195FEProblemBase::addMarker(const std::string & marker_name,
6196 const std::string & name,
6197 InputParameters & parameters)
6198{
6199 parallel_object_only();
6200
6201 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
6202 {
6203 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
6204 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
6206 }
6207 else
6208 {
6209 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
6210 {
6211 // We allow Markers to request that they use_displaced_mesh,
6212 // but then be overridden when no displacements variables are
6213 // provided in the Mesh block. If that happened, update the value
6214 // of use_displaced_mesh appropriately for this Marker.
6215 if (parameters.have_parameter<bool>("use_displaced_mesh"))
6216 parameters.set<bool>("use_displaced_mesh") = false;
6217 }
6218
6219 parameters.set<SubProblem *>("_subproblem") = this;
6220 parameters.set<SystemBase *>("_sys") = _aux.get();
6221 }
6222
6223 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
6224 {
6225 std::shared_ptr<Marker> marker = _factory.create<Marker>(marker_name, name, parameters, tid);
6226 logAdd("Marker", name, marker_name, parameters);
6227 _markers.addObject(marker, tid);
6228 }
6229}
6230
6231void
6232FEProblemBase::addMultiApp(const std::string & multi_app_name,
6233 const std::string & name,
6234 InputParameters & parameters)
6235{
6236 parallel_object_only();
6237
6238 parameters.set<MPI_Comm>("_mpi_comm") = _communicator.get();
6239
6240 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
6241 {
6242 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
6243 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
6245 }
6246 else
6247 {
6248 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
6249 {
6250 // We allow MultiApps to request that they use_displaced_mesh,
6251 // but then be overridden when no displacements variables are
6252 // provided in the Mesh block. If that happened, update the value
6253 // of use_displaced_mesh appropriately for this MultiApp.
6254 if (parameters.have_parameter<bool>("use_displaced_mesh"))
6255 parameters.set<bool>("use_displaced_mesh") = false;
6256 }
6257
6258 parameters.set<SubProblem *>("_subproblem") = this;
6259 parameters.set<SystemBase *>("_sys") = _aux.get();
6260 }
6261
6262 std::shared_ptr<MultiApp> multi_app = _factory.create<MultiApp>(multi_app_name, name, parameters);
6263 logAdd("MultiApp", name, multi_app_name, parameters);
6264 multi_app->possiblyCreateChildApplications();
6265
6266 _multi_apps.addObject(multi_app);
6267
6268 // Store TransientMultiApp objects in another container, this is needed for calling computeDT
6269 std::shared_ptr<TransientMultiApp> trans_multi_app =
6270 std::dynamic_pointer_cast<TransientMultiApp>(multi_app);
6271 if (trans_multi_app)
6272 _transient_multi_apps.addObject(trans_multi_app);
6273}
6274
6275bool
6280
6281bool
6282FEProblemBase::hasMultiApp(const std::string & multi_app_name) const
6283{
6284 return _multi_apps.hasActiveObject(multi_app_name);
6285}
6286
6287std::shared_ptr<MultiApp>
6288FEProblemBase::getMultiApp(const std::string & multi_app_name) const
6289{
6290 if (!hasMultiApp(multi_app_name))
6291 mooseAssert(getMooseApp().actionWarehouse().isTaskComplete("add_multi_app"),
6292 "A MultiApp getter was called before MultiApps have been constructed. "
6293 "If you are attempting to access this object in the constructor of another object "
6294 "then make sure that the MultiApp is constructed before the object using it.");
6295
6296 return _multi_apps.getObject(multi_app_name);
6297}
6298
6299void
6301 Transfer::DIRECTION direction,
6302 const MultiAppName & source_app)
6303{
6304 // Keep track of whether a transfer is actually executed to avoid extraneous console output
6305 bool is_executing_a_transfer = false;
6306 bool to_multiapp = direction == MultiAppTransfer::TO_MULTIAPP;
6307 bool from_multiapp = direction == MultiAppTransfer::FROM_MULTIAPP;
6308
6309 // Build console output
6310 std::string string_direction;
6311 std::string additional_source_info = "";
6312 if (to_multiapp)
6313 string_direction = " To ";
6314 else if (from_multiapp)
6315 string_direction = " From ";
6316 else
6317 string_direction = " Between ";
6318 if (!source_app.empty())
6319 additional_source_info = " from app '" + source_app + "'";
6320
6321 // This lambda only checks the source app, since the exec_type selection is done in the warehouse
6322 auto executeThisTransfer = [this, &direction, &source_app, &type](auto & transfer)
6323 {
6324 mooseAssert(transfer->getExecuteOnEnum().contains(type), "Should execute on this schedule");
6325 // no restriction / ordering groups on transfers from parent to child at this time
6326 if (direction != MultiAppTransfer::BETWEEN_MULTIAPP)
6327 return true;
6328 // on sibling transfers, we can delay until the app has been executed if the transfer is set
6329 // that way.
6330 if (transfer->getFromName() == source_app && transfer->executeAfterSiblingSourceApp())
6331 {
6332 libmesh_ignore(this);
6333 mooseAssert(this->getMultiApp(transfer->getFromName())->getExecuteOnEnum().contains(type),
6334 "from_multiapp should also execute on this schedule");
6335 }
6336 // Execute if:
6337 // - transfer is set execute before from_multiapp, and we are calling this before source apps
6338 // - from_multiapp app is not executing on this execute_on
6339 // - from_multiapp just executed (set to source app)
6340 if ((source_app.empty() && (!transfer->executeAfterSiblingSourceApp() ||
6341 !transfer->getFromMultiApp()->getExecuteOnEnum().contains(type))) ||
6342 (transfer->getFromName() == source_app && transfer->executeAfterSiblingSourceApp()))
6343 return true;
6344 return false;
6345 };
6346
6348 : from_multiapp ? _from_multi_app_transfers[type]
6350
6351 if (wh.hasActiveObjects())
6352 {
6353 TIME_SECTION("execMultiAppTransfers", 1, "Executing Transfers");
6354
6355 const auto & transfers = wh.getActiveObjects();
6356
6358 {
6360 {"Name", "Type", "From", "To"});
6361
6362 // Build Table of Transfer Info
6363 for (const auto & transfer : transfers)
6364 {
6365 auto multiapp_transfer = dynamic_cast<MultiAppTransfer *>(transfer.get());
6366
6367 // Don't add transfer to table if it won't execute
6368 if (!executeThisTransfer(multiapp_transfer))
6369 continue;
6370
6371 is_executing_a_transfer = true;
6372 table.addRow(multiapp_transfer->name(),
6373 multiapp_transfer->type(),
6374 multiapp_transfer->getFromName(),
6375 multiapp_transfer->getToName());
6376 }
6377
6378 // Print it
6379 if (is_executing_a_transfer)
6380 {
6381 _console << COLOR_CYAN << "\nTransfers on " << Moose::stringify(type) << string_direction
6382 << "MultiApps" << additional_source_info << COLOR_DEFAULT << ":" << std::endl;
6383
6384 table.print(_console);
6385 }
6386 }
6387
6388 for (const auto & transfer : transfers)
6389 {
6390 auto multiapp_transfer = libMesh::cast_ptr<MultiAppTransfer *>(transfer.get());
6391 if (!executeThisTransfer(multiapp_transfer))
6392 continue;
6393
6394 transfer->setCurrentDirection(direction);
6395 transfer->execute();
6396 }
6397
6399
6400 if (_verbose_multiapps && is_executing_a_transfer)
6401 _console << COLOR_CYAN << "Transfers on " << Moose::stringify(type) << " Are Finished\n"
6402 << COLOR_DEFAULT << std::endl;
6403 }
6404
6405 if (_multi_apps[type].getActiveObjects().size() && !is_executing_a_transfer && _verbose_multiapps)
6406 _console << COLOR_CYAN << "\nNo Transfers on " << Moose::stringify(type) << string_direction
6407 << "MultiApps\n"
6408 << COLOR_DEFAULT << std::endl;
6409}
6410
6411std::vector<std::shared_ptr<Transfer>>
6421
6422std::vector<std::shared_ptr<Transfer>>
6432
6435{
6436 if (direction == MultiAppTransfer::TO_MULTIAPP)
6438 else if (direction == MultiAppTransfer::FROM_MULTIAPP)
6440 else
6442}
6443
6444void
6446{
6448 return;
6449
6450 // Group the multiapps by execution order group. Only position-based multiapps are partitioned
6451 // here; sampler-style (non-positions) multiapps assign their own rank configuration.
6452 std::map<unsigned int, std::vector<std::shared_ptr<MultiApp>>> groups;
6453 for (const auto & multi_app : _multi_apps.getActiveObjects())
6454 if (multi_app->usingPositions())
6455 groups[multi_app->getParam<unsigned int>("execution_order_group")].push_back(multi_app);
6456
6457 // For the MultiApps that are using samplers, their partitioning is already handled there
6458 // so we just skipped them. But if they were to share an execution_order_group, we would crash
6459 // if using concurrent multiapps. So let's error.
6460 // For any other MultiApps that are not using positions, we would just need them to know
6461 // numGlobalApps() to benefit from this concurrent partitioning. We can allow them here in the
6462 // future.
6463 std::map<unsigned int, std::vector<std::shared_ptr<MultiApp>>> check_groups;
6464 for (const auto & multi_app : _multi_apps.getActiveObjects())
6465 check_groups[multi_app->getParam<unsigned int>("execution_order_group")].push_back(multi_app);
6466 for (const auto & [group_id, group] : check_groups)
6467 for (const auto & multi_app : group)
6468 if (group.size() > 1 && !multi_app->usingPositions())
6469 multi_app->paramError(
6470 "execution_order_group",
6471 "This MultiApp must be placed in its own execution order group as concurrent execution "
6472 "has not been implemented for this type of app at this time");
6473
6474 const auto n_procs = n_processors();
6475 const auto my_rank = processor_id();
6476
6477 for (const auto & [group_id, group] : groups)
6478 {
6479 // Nothing to run concurrently unless the group has more than one multiapp
6480 if (group.size() < 2)
6481 continue;
6482
6483 // Number of ranks handed to each multiapp. Start each at its per-app minimum (at least one
6484 // rank), then distribute the rest; caps prevent giving a multiapp more ranks than it could
6485 // spread its apps over at 'max_procs_per_app'. With the defaults (min 1, max unbounded) this
6486 // is just an even split.
6487 std::vector<processor_id_type> count(group.size());
6488 std::vector<processor_id_type> caps(group.size());
6489 std::vector<processor_id_type> mins(group.size());
6490 std::vector<processor_id_type> maxs(group.size());
6491 processor_id_type min_total = 0;
6492 for (const auto m : index_range(group))
6493 {
6494 // Each multiapp needs at least one rank, so a 'min_procs_per_app' of 0 is treated as 1
6495 mins[m] = group[m]->getParam<processor_id_type>("min_procs_per_app");
6496 maxs[m] = group[m]->getParam<processor_id_type>("max_procs_per_app");
6497 const auto n_apps_m = cast_int<processor_id_type>(group[m]->numGlobalApps());
6498 caps[m] = (maxs[m] >= n_procs) ? n_procs : std::min(n_procs, n_apps_m * maxs[m]);
6499 count[m] = mins[m];
6500 min_total += mins[m];
6501 }
6502
6503 if (min_total > n_procs)
6504 mooseError("Not enough MPI ranks to run the ",
6505 group.size(),
6506 " multiapps of 'execution_order_group' ",
6507 group_id,
6508 " concurrently: they need at least ",
6509 min_total,
6510 " ranks (from 'min_procs_per_app') but only ",
6511 n_procs,
6512 " are available. Reduce the number of concurrent multiapps, lower "
6513 "'min_procs_per_app', or run with more processors.");
6514
6515 // Hand out the remaining ranks round-robin to multiapps still below their cap
6516 processor_id_type remaining = n_procs - min_total;
6517 bool progress = true;
6518 while (remaining > 0 && progress)
6519 {
6520 progress = false;
6521 for (const auto m : index_range(group))
6522 if (remaining > 0 && count[m] < caps[m])
6523 {
6524 count[m]++;
6525 remaining--;
6526 progress = true;
6527 }
6528 }
6529 // Any leftover ranks (all multiapps already at their cap) simply run no app in this group.
6530
6531 // Assign each multiapp a contiguous, disjoint rank range and (re)initialize it on that range.
6532 // This is collective: every rank calls init() (hence buildComm's split) for every multiapp.
6533 processor_id_type offset = 0;
6534 for (const auto m : index_range(group))
6535 {
6536 LocalRankConfig cfg{0, 0, 0, 0, false, 0};
6537 if (my_rank >= offset && my_rank < offset + count[m])
6538 cfg = rankConfig(
6539 my_rank - offset, count[m], group[m]->numGlobalApps(), mins[m], maxs[m], false);
6540 group[m]->init(group[m]->numGlobalApps(), cfg);
6541 offset += count[m];
6542 }
6543 }
6544}
6545
6546bool
6548{
6549 // Active MultiApps
6550 const std::vector<MooseSharedPointer<MultiApp>> & multi_apps =
6551 _multi_apps[exec_on].getActiveObjects();
6552
6553 // Do anything that needs to be done to Apps before transfers
6554 for (const auto & multi_app : multi_apps)
6555 multi_app->preTransfer(_dt, _time);
6556
6557 // Execute Transfers _to_ MultiApps
6559
6560 // Execute Transfers _beween_ MultiApps for the multiapps that don't execute on this flag
6561 // NOTE: there is usually no need to execute a transfer unless the multiapp providing its
6562 // data also executed. But we need to obey what the user requested for the execution schedule,
6563 // hence the two executions
6565
6566 // Order the multiapps based on their execution group
6567 // Build the ordered multiapp groups
6568 std::map<unsigned int, std::vector<MooseSharedPointer<MultiApp>>> ordered_multi_apps;
6569
6570 for (const auto & multi_app : multi_apps)
6571 ordered_multi_apps[multi_app->getParam<unsigned int>("execution_order_group")].push_back(
6572 multi_app);
6573
6574 // Check that concurrent multiapps will even be used
6575 if (multi_apps.size() && _num_concurrent_multiapps > 1)
6576 {
6577 bool has_concurrent_apps = false;
6578 for (const auto & [group, multi_app_group] : ordered_multi_apps)
6579 if (multi_app_group.size() > 1)
6580 has_concurrent_apps = true;
6581 if (!has_concurrent_apps)
6582 paramInfo(
6583 "num_concurrent_multiapps",
6584 "Due to the specified multiapp execution groups, or differences in execution schedules, "
6585 "concurrent multiapps are not actually used on " +
6586 Moose::stringify(exec_on));
6587 }
6588
6589 // Execute MultiApps
6590 if (multi_apps.size())
6591 {
6592 TIME_SECTION("execMultiApps", 1, "Executing MultiApps", false);
6593
6595 _console << COLOR_CYAN << "\nExecuting MultiApps on " << Moose::stringify(exec_on)
6596 << COLOR_DEFAULT << std::endl;
6597
6598 bool success = true;
6599
6600 for (const auto & [group_id, multi_app_group] : ordered_multi_apps)
6601 {
6602 bool group_success = true;
6603 if (_verbose_multiapps && ordered_multi_apps.size() > 1)
6604 _console << COLOR_CYAN << "\nExecuting MultiApps group " << Moose::stringify(group_id)
6605 << COLOR_DEFAULT << std::endl;
6606
6607 if (_verbose_multiapps && multi_app_group.size() > 1)
6608 {
6609 // Let the user know about concurrent multiapp use (new option: help them set it up)
6610 _console << COLOR_CYAN << "\nConcurrent MultiApps: " << std::endl;
6611 for (const auto & multi_app : multi_app_group)
6612 _console << multi_app->name() << " ";
6613 _console << COLOR_DEFAULT << std::endl;
6614 }
6615
6616 // With concurrent multiapps, the multiapps in a group have each been assigned a disjoint
6617 // subset of the ranks (see partitionConcurrentMultiApps()), so solveStep() does real work
6618 // only on those ranks and returns early on the others. Looping here therefore lets different
6619 // ranks advance different multiapps at the same time - the concurrency comes from the rank
6620 // partition. This notably avoids racing PETSc's process-global state (communicator and
6621 // options database).
6622 for (const auto & multi_app : multi_app_group)
6623 if (!multi_app->solveStep(_dt, _time, auto_advance))
6624 group_success = false;
6625
6626 // Whether to move on to the next group must be a collective decision so that every rank
6627 // leaves the group loop together and stays aligned for the following collectives.
6628 _communicator.min(group_success);
6629
6630 // No need to solve the other groups if this group failed
6631 if (!group_success)
6632 {
6633 success = false;
6634 break;
6635 }
6636
6637 // Execute Transfers _between_ MultiApps after each app executes
6638 for (const auto & multi_app : multi_app_group)
6640 }
6641
6643 _communicator.min(success);
6644
6645 if (!success)
6646 return false;
6647
6649 _console << COLOR_CYAN << "Finished Executing MultiApps on " << Moose::stringify(exec_on)
6650 << "\n"
6651 << COLOR_DEFAULT << std::endl;
6652 }
6653
6654 // Execute Transfers _from_ MultiApps (to the parent app)
6656
6657 // If we made it here then everything passed
6658 return true;
6659}
6660
6661void
6663{
6664 const auto & multi_apps = _multi_apps.getActiveObjects();
6665
6666 for (const auto & multi_app : multi_apps)
6667 multi_app->finalize();
6668}
6669
6670void
6672{
6673 const auto & multi_apps = _multi_apps.getActiveObjects();
6674
6675 for (const auto & multi_app : multi_apps)
6676 multi_app->postExecute();
6677}
6678
6679void
6681{
6682 const auto & multi_apps = _multi_apps[type].getActiveObjects();
6683
6684 if (multi_apps.size())
6685 for (const auto & multi_app : multi_apps)
6686 multi_app->incrementTStep(_time);
6687}
6688
6689void
6690FEProblemBase::finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels)
6691{
6692 const auto & multi_apps = _multi_apps[type].getActiveObjects();
6693
6694 if (multi_apps.size())
6695 {
6697 _console << COLOR_CYAN << "\nAdvancing MultiApps on " << type.name() << COLOR_DEFAULT
6698 << std::endl;
6699
6700 for (const auto & multi_app : multi_apps)
6701 multi_app->finishStep(recurse_through_multiapp_levels);
6702
6704
6706 _console << COLOR_CYAN << "Finished Advancing MultiApps on " << type.name() << "\n"
6707 << COLOR_DEFAULT << std::endl;
6708 }
6709}
6710
6711void
6713{
6714 const auto & multi_apps = _multi_apps[type].getActiveObjects();
6715
6716 if (multi_apps.size())
6717 {
6718 TIME_SECTION("backupMultiApps", 5, "Backing Up MultiApp");
6719
6721 _console << COLOR_CYAN << "\nBacking Up MultiApps on " << type.name() << COLOR_DEFAULT
6722 << std::endl;
6723
6724 for (const auto & multi_app : multi_apps)
6725 multi_app->backup();
6726
6728
6730 _console << COLOR_CYAN << "Finished Backing Up MultiApps on " << type.name() << "\n"
6731 << COLOR_DEFAULT << std::endl;
6732 }
6733}
6734
6735void
6737{
6738 const auto & multi_apps = _multi_apps[type].getActiveObjects();
6739
6740 if (multi_apps.size())
6741 {
6743 {
6744 if (force)
6745 _console << COLOR_CYAN << "\nRestoring Multiapps on " << type.name()
6746 << " because of solve failure!" << COLOR_DEFAULT << std::endl;
6747 else
6748 _console << COLOR_CYAN << "\nRestoring MultiApps on " << type.name() << COLOR_DEFAULT
6749 << std::endl;
6750 }
6751
6752 for (const auto & multi_app : multi_apps)
6753 multi_app->restore(force);
6754
6756
6758 _console << COLOR_CYAN << "Finished Restoring MultiApps on " << type.name() << "\n"
6759 << COLOR_DEFAULT << std::endl;
6760 }
6761}
6762
6763Real
6765{
6766 const auto & multi_apps = _transient_multi_apps[type].getActiveObjects();
6767
6768 Real smallest_dt = std::numeric_limits<Real>::max();
6769
6770 for (const auto & multi_app : multi_apps)
6771 smallest_dt = std::min(smallest_dt, multi_app->computeDT());
6772
6773 return smallest_dt;
6774}
6775
6776void
6777FEProblemBase::addTransfer(const std::string & transfer_name,
6778 const std::string & name,
6779 InputParameters & parameters)
6780{
6781 parallel_object_only();
6782
6783 if (_displaced_problem && parameters.get<bool>("use_displaced_mesh"))
6784 {
6785 parameters.set<SubProblem *>("_subproblem") = _displaced_problem.get();
6786 parameters.set<SystemBase *>("_sys") = &_displaced_problem->auxSys();
6788 }
6789 else
6790 {
6791 if (_displaced_problem == nullptr && parameters.get<bool>("use_displaced_mesh"))
6792 {
6793 // We allow Transfers to request that they use_displaced_mesh,
6794 // but then be overridden when no displacements variables are
6795 // provided in the Mesh block. If that happened, update the value
6796 // of use_displaced_mesh appropriately for this Transfer.
6797 if (parameters.have_parameter<bool>("use_displaced_mesh"))
6798 parameters.set<bool>("use_displaced_mesh") = false;
6799 }
6800
6801 parameters.set<SubProblem *>("_subproblem") = this;
6802 parameters.set<SystemBase *>("_sys") = _aux.get();
6803 }
6804
6805 // Handle the "SAME_AS_MULTIAPP" execute option. The get method is used to test for the
6806 // flag so the set by user flag is not reset, calling set with the true flag causes the set
6807 // by user status to be reset, which should only be done if the EXEC_SAME_AS_MULTIAPP is
6808 // being applied to the object.
6810 {
6811 ExecFlagEnum & exec_enum = parameters.set<ExecFlagEnum>("execute_on", true);
6812 std::shared_ptr<MultiApp> multiapp;
6813 if (parameters.isParamValid("multi_app"))
6814 multiapp = getMultiApp(parameters.get<MultiAppName>("multi_app"));
6815 // This catches the sibling transfer case, where we want to be executing only as often as the
6816 // receiving application. A transfer 'to' a multiapp is executed before that multiapp
6817 else if (parameters.isParamValid("to_multi_app"))
6818 multiapp = getMultiApp(parameters.get<MultiAppName>("to_multi_app"));
6819 else if (parameters.isParamValid("from_multi_app"))
6820 multiapp = getMultiApp(parameters.get<MultiAppName>("from_multi_app"));
6821 // else do nothing because the user has provided invalid input. They should get a nice error
6822 // about this during transfer construction. This necessitates checking for null in this next
6823 // line, however
6824 if (multiapp)
6825 exec_enum = multiapp->getParam<ExecFlagEnum>("execute_on");
6826 }
6827
6828 // Create the Transfer objects
6829 std::shared_ptr<Transfer> transfer = _factory.create<Transfer>(transfer_name, name, parameters);
6830 logAdd("Transfer", name, transfer_name, parameters);
6831
6832 // Add MultiAppTransfer object
6833 std::shared_ptr<MultiAppTransfer> multi_app_transfer =
6834 std::dynamic_pointer_cast<MultiAppTransfer>(transfer);
6835 if (multi_app_transfer)
6836 {
6837 if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::TO_MULTIAPP))
6838 _to_multi_app_transfers.addObject(multi_app_transfer);
6839 if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::FROM_MULTIAPP))
6840 _from_multi_app_transfers.addObject(multi_app_transfer);
6841 if (multi_app_transfer->directions().isValueSet(MultiAppTransfer::BETWEEN_MULTIAPP))
6842 _between_multi_app_transfers.addObject(multi_app_transfer);
6843 }
6844 else
6845 _transfers.addObject(transfer);
6846}
6847
6848bool
6849FEProblemBase::hasVariable(const std::string & var_name) const
6850{
6851 for (auto & sys : _solver_systems)
6852 if (sys->hasVariable(var_name))
6853 return true;
6854 if (_aux->hasVariable(var_name))
6855 return true;
6856
6857 return false;
6858}
6859
6860bool
6861FEProblemBase::hasSolverVariable(const std::string & var_name) const
6862{
6863 for (auto & sys : _solver_systems)
6864 if (sys->hasVariable(var_name))
6865 return true;
6866
6867 return false;
6868}
6869
6872 const std::string & var_name,
6873 Moose::VarKindType expected_var_type,
6874 Moose::VarFieldType expected_var_field_type) const
6875{
6876 return getVariableHelper(
6877 tid, var_name, expected_var_type, expected_var_field_type, _solver_systems, *_aux);
6878}
6879
6881FEProblemBase::getStandardVariable(const THREAD_ID tid, const std::string & var_name)
6882{
6883 for (auto & sys : _solver_systems)
6884 if (sys->hasVariable(var_name))
6885 return sys->getFieldVariable<Real>(tid, var_name);
6886 if (_aux->hasVariable(var_name))
6887 return _aux->getFieldVariable<Real>(tid, var_name);
6888
6889 mooseError("Unknown variable " + var_name);
6890}
6891
6893FEProblemBase::getActualFieldVariable(const THREAD_ID tid, const std::string & var_name)
6894{
6895 for (auto & sys : _solver_systems)
6896 if (sys->hasVariable(var_name))
6897 return sys->getActualFieldVariable<Real>(tid, var_name);
6898 if (_aux->hasVariable(var_name))
6899 return _aux->getActualFieldVariable<Real>(tid, var_name);
6900
6901 mooseError("Unknown variable " + var_name);
6902}
6903
6905FEProblemBase::getVectorVariable(const THREAD_ID tid, const std::string & var_name)
6906{
6907 for (auto & sys : _solver_systems)
6908 if (sys->hasVariable(var_name))
6909 return sys->getFieldVariable<RealVectorValue>(tid, var_name);
6910 if (_aux->hasVariable(var_name))
6911 return _aux->getFieldVariable<RealVectorValue>(tid, var_name);
6912
6913 mooseError("Unknown variable " + var_name);
6914}
6915
6917FEProblemBase::getArrayVariable(const THREAD_ID tid, const std::string & var_name)
6918{
6919 for (auto & sys : _solver_systems)
6920 if (sys->hasVariable(var_name))
6921 return sys->getFieldVariable<RealEigenVector>(tid, var_name);
6922 if (_aux->hasVariable(var_name))
6923 return _aux->getFieldVariable<RealEigenVector>(tid, var_name);
6924
6925 mooseError("Unknown variable " + var_name);
6926}
6927
6928bool
6929FEProblemBase::hasScalarVariable(const std::string & var_name) const
6930{
6931 for (auto & sys : _solver_systems)
6932 if (sys->hasScalarVariable(var_name))
6933 return true;
6934 if (_aux->hasScalarVariable(var_name))
6935 return true;
6936
6937 return false;
6938}
6939
6941FEProblemBase::getScalarVariable(const THREAD_ID tid, const std::string & var_name)
6942{
6943 for (auto & sys : _solver_systems)
6944 if (sys->hasScalarVariable(var_name))
6945 return sys->getScalarVariable(tid, var_name);
6946 if (_aux->hasScalarVariable(var_name))
6947 return _aux->getScalarVariable(tid, var_name);
6948
6949 mooseError("Unknown variable " + var_name);
6950}
6951
6952System &
6953FEProblemBase::getSystem(const std::string & var_name)
6954{
6955 const auto [var_in_sys, sys_num] = determineSolverSystem(var_name);
6956 if (var_in_sys)
6957 return _solver_systems[sys_num]->system();
6958 else if (_aux->hasVariable(var_name) || _aux->hasScalarVariable(var_name))
6959 return _aux->system();
6960 else
6961 mooseError("Unable to find a system containing the variable " + var_name);
6962}
6963
6966{
6967 return _req.get();
6968}
6969
6970void
6972{
6974
6976 _displaced_problem->setActiveFEVariableCoupleableMatrixTags(mtags, tid);
6977}
6978
6979void
6981{
6983
6985 _displaced_problem->setActiveFEVariableCoupleableVectorTags(vtags, tid);
6986}
6987
6988void
6990 const THREAD_ID tid)
6991{
6993
6995 _displaced_problem->setActiveScalarVariableCoupleableMatrixTags(mtags, tid);
6996}
6997
6998void
7000 const THREAD_ID tid)
7001{
7003
7005 _displaced_problem->setActiveScalarVariableCoupleableVectorTags(vtags, tid);
7006}
7007
7008void
7009FEProblemBase::setActiveElementalMooseVariables(const std::set<MooseVariableFEBase *> & moose_vars,
7010 const THREAD_ID tid)
7011{
7013
7015 _displaced_problem->setActiveElementalMooseVariables(moose_vars, tid);
7016}
7017
7018void
7020{
7022
7024 _displaced_problem->clearActiveElementalMooseVariables(tid);
7025}
7026
7027void
7029{
7031
7033 _displaced_problem->clearActiveFEVariableCoupleableMatrixTags(tid);
7034}
7035
7036void
7038{
7040
7042 _displaced_problem->clearActiveFEVariableCoupleableVectorTags(tid);
7043}
7044
7045void
7047{
7049
7051 _displaced_problem->clearActiveScalarVariableCoupleableMatrixTags(tid);
7052}
7053
7054void
7056{
7058
7060 _displaced_problem->clearActiveScalarVariableCoupleableVectorTags(tid);
7061}
7062
7063void
7064FEProblemBase::setActiveMaterialProperties(const std::unordered_set<unsigned int> & mat_prop_ids,
7065 const THREAD_ID tid)
7066{
7067 // mark active properties in every material
7068 for (auto & mat : _all_materials.getObjects(tid))
7069 mat->setActiveProperties(mat_prop_ids);
7070 for (auto & mat : _all_materials[Moose::FACE_MATERIAL_DATA].getObjects(tid))
7071 mat->setActiveProperties(mat_prop_ids);
7073 mat->setActiveProperties(mat_prop_ids);
7074
7075 _has_active_material_properties[tid] = !mat_prop_ids.empty();
7076}
7077
7078bool
7083
7084void
7089
7090void
7092{
7093#ifdef LIBMESH_ENABLE_AMR
7094 if ((_adaptivity.isOn() || _num_grid_steps) &&
7097 {
7098 // Even on a serialized Mesh, we don't keep our material
7099 // properties serialized, so we'll rely on the callback to
7100 // redistribute() to redistribute properties at the same time
7101 // libMesh is redistributing elements.
7102 auto add_redistributer = [this](MooseMesh & mesh,
7103 const std::string & redistributer_name,
7104 const bool use_displaced_mesh)
7105 {
7107 redistribute_params.set<MooseApp *>(MooseBase::app_param) = &_app;
7108 redistribute_params.set<std::string>("for_whom") = this->name();
7109 redistribute_params.set<MooseMesh *>("mesh") = &mesh;
7110 redistribute_params.set<Moose::RelationshipManagerType>("rm_type") =
7112 redistribute_params.set<bool>("use_displaced_mesh") = use_displaced_mesh;
7113 redistribute_params.setHitNode(*parameters().getHitNode(), {});
7114
7115 std::shared_ptr<RedistributeProperties> redistributer =
7117 "RedistributeProperties", redistributer_name, redistribute_params);
7118
7121
7123 redistributer->addMaterialPropertyStorage(_bnd_material_props);
7124
7126 redistributer->addMaterialPropertyStorage(_neighbor_material_props);
7127
7128 mesh.getMesh().add_ghosting_functor(redistributer);
7129 };
7130
7131 add_redistributer(_mesh, "mesh_property_redistributer", false);
7133 add_redistributer(_displaced_problem->mesh(), "displaced_mesh_property_redistributer", true);
7134 }
7135#endif // LIBMESH_ENABLE_AMR
7136}
7137
7138void
7140{
7141 // Find the maximum number of quadrature points
7142 {
7143 MaxQpsThread mqt(*this);
7145 _max_qps = mqt.max();
7146
7147 // If we have more shape functions or more quadrature points on
7148 // another processor, then we may need to handle those elements
7149 // ourselves later after repartitioning.
7151 }
7152
7153 unsigned int max_qpts = getMaxQps();
7154 if (max_qpts > Moose::constMaxQpsPerElem)
7155 mooseError("Max quadrature points per element assumptions made in some code (e.g. Coupleable ",
7156 "and MaterialPropertyInterface classes) have been violated.\n",
7157 "Complain to Moose developers to have constMaxQpsPerElem increased from ",
7159 " to ",
7160 max_qpts);
7161 for (unsigned int tid = 0; tid < numThreads(); ++tid)
7162 {
7163 // the highest available order in libMesh is 43
7164 _scalar_zero[tid].resize(libMesh::FORTYTHIRD, 0);
7165 _zero[tid].resize(max_qpts, 0);
7166 _ad_zero[tid].resize(max_qpts, 0);
7167 _grad_zero[tid].resize(max_qpts, RealGradient(0.));
7168 _ad_grad_zero[tid].resize(max_qpts, ADRealGradient(0));
7169 _second_zero[tid].resize(max_qpts, RealTensor(0.));
7170 _ad_second_zero[tid].resize(max_qpts, ADRealTensorValue(0));
7171 _vector_zero[tid].resize(max_qpts, RealGradient(0.));
7172 _vector_curl_zero[tid].resize(max_qpts, RealGradient(0.));
7173 }
7174}
7175
7176void
7178{
7179 for (unsigned int tid = 0; tid < numThreads(); ++tid)
7180 for (const auto i : index_range(_nl))
7181 _assembly[tid][i]->bumpVolumeQRuleOrder(order, block);
7182
7184 _displaced_problem->bumpVolumeQRuleOrder(order, block);
7185
7186 updateMaxQps();
7187}
7188
7189void
7191{
7192 for (unsigned int tid = 0; tid < numThreads(); ++tid)
7193 for (const auto i : index_range(_nl))
7194 _assembly[tid][i]->bumpAllQRuleOrder(order, block);
7195
7197 _displaced_problem->bumpAllQRuleOrder(order, block);
7198
7199 updateMaxQps();
7200}
7201
7202void
7204 Order order,
7205 Order volume_order,
7206 Order face_order,
7207 SubdomainID block,
7208 const bool allow_negative_qweights)
7209{
7210 if (order == INVALID_ORDER)
7211 {
7212 // automatically determine the integration order
7213 order = _solver_systems[0]->getMinQuadratureOrder();
7214 for (const auto i : make_range(std::size_t(1), _solver_systems.size()))
7215 if (order < _solver_systems[i]->getMinQuadratureOrder())
7216 order = _solver_systems[i]->getMinQuadratureOrder();
7217 if (order < _aux->getMinQuadratureOrder())
7218 order = _aux->getMinQuadratureOrder();
7219 }
7220
7221 if (volume_order == INVALID_ORDER)
7222 volume_order = order;
7223
7224 if (face_order == INVALID_ORDER)
7225 face_order = order;
7226
7227 for (unsigned int tid = 0; tid < numThreads(); ++tid)
7228 for (const auto i : index_range(_solver_systems))
7229 _assembly[tid][i]->createQRules(
7230 type, order, volume_order, face_order, block, allow_negative_qweights);
7231
7233 _displaced_problem->createQRules(
7234 type, order, volume_order, face_order, block, allow_negative_qweights);
7235
7236 updateMaxQps();
7237}
7238
7239void
7241{
7243 {
7245 mooseError("Someone told us (the FEProblemBase) to trust the user coupling matrix, but we "
7246 "haven't been provided a coupling matrix!");
7247
7248 // We've been told to trust the user coupling matrix, so we're going to leave things alone
7249 return;
7250 }
7251
7252 _coupling = type;
7253}
7254
7255void
7256FEProblemBase::setCouplingMatrix(CouplingMatrix * cm, const unsigned int i)
7257{
7258 // TODO: Deprecate method
7260 _cm[i].reset(cm);
7261}
7262
7263void
7264FEProblemBase::setCouplingMatrix(std::unique_ptr<CouplingMatrix> cm, const unsigned int i)
7265{
7267 _cm[i] = std::move(cm);
7268}
7269
7270void
7272{
7274 mooseError("Someone told us (the FEProblemBase) to trust the user coupling matrix, but we "
7275 "haven't been provided a coupling matrix!");
7276
7278}
7279
7280void
7282{
7283 TIME_SECTION("setNonlocalCouplingMatrix", 5, "Setting Nonlocal Coupling Matrix");
7284
7285 if (_nl.size() > 1)
7286 mooseError("Nonlocal kernels are weirdly stored on the FEProblem so we don't currently support "
7287 "multiple nonlinear systems with nonlocal kernels.");
7288
7289 for (const auto nl_sys_num : index_range(_nl))
7290 {
7291 auto & nl = _nl[nl_sys_num];
7292 auto & nonlocal_cm = _nonlocal_cm[nl_sys_num];
7293 unsigned int n_vars = nl->nVariables();
7294 nonlocal_cm.resize(n_vars);
7295 const auto & vars = nl->getVariables(0);
7296 const auto & nonlocal_kernel = _nonlocal_kernels.getObjects();
7297 const auto & nonlocal_integrated_bc = _nonlocal_integrated_bcs.getObjects();
7298 for (const auto & ivar : vars)
7299 {
7300 for (const auto & kernel : nonlocal_kernel)
7301 {
7302 for (unsigned int i = ivar->number(); i < ivar->number() + ivar->count(); ++i)
7303 if (i == kernel->variable().number())
7304 for (const auto & jvar : vars)
7305 {
7306 const auto it = _var_dof_map.find(jvar->name());
7307 if (it != _var_dof_map.end())
7308 {
7309 unsigned int j = jvar->number();
7310 nonlocal_cm(i, j) = 1;
7311 }
7312 }
7313 }
7314 for (const auto & integrated_bc : nonlocal_integrated_bc)
7315 {
7316 for (unsigned int i = ivar->number(); i < ivar->number() + ivar->count(); ++i)
7317 if (i == integrated_bc->variable().number())
7318 for (const auto & jvar : vars)
7319 {
7320 const auto it = _var_dof_map.find(jvar->name());
7321 if (it != _var_dof_map.end())
7322 {
7323 unsigned int j = jvar->number();
7324 nonlocal_cm(i, j) = 1;
7325 }
7326 }
7327 }
7328 }
7329 }
7330}
7331
7332bool
7333FEProblemBase::areCoupled(const unsigned int ivar,
7334 const unsigned int jvar,
7335 const unsigned int nl_sys) const
7336{
7337 return (*_cm[nl_sys])(ivar, jvar);
7338}
7339
7340std::vector<std::pair<MooseVariableFieldBase *, MooseVariableFieldBase *>> &
7341FEProblemBase::couplingEntries(const THREAD_ID tid, const unsigned int nl_sys)
7342{
7343 return _assembly[tid][nl_sys]->couplingEntries();
7344}
7345
7346std::vector<std::pair<MooseVariableFieldBase *, MooseVariableFieldBase *>> &
7347FEProblemBase::nonlocalCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys)
7348{
7349 return _assembly[tid][nl_sys]->nonlocalCouplingEntries();
7350}
7351
7352const std::vector<std::pair<MooseVariableFieldBase *, MooseVariableScalar *>> &
7353FEProblemBase::fieldScalarCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys) const
7354{
7355 return _assembly[tid][nl_sys]->fieldScalarCouplingEntries();
7356}
7357
7358void
7360{
7361 if (_initialized)
7362 return;
7363
7364 TIME_SECTION("init", 2, "Initializing");
7365
7366 // call executioner's preProblemInit so that it can do some setups before problem init
7368
7369 // If we have AD and we are doing global AD indexing, then we should by default set the matrix
7370 // coupling to full. If the user has told us to trust their coupling matrix, then this call will
7371 // not do anything
7374
7375 for (const auto i : index_range(_nl))
7376 {
7377 auto & nl = _nl[i];
7378 auto & cm = _cm[i];
7379
7380 unsigned int n_vars = nl->nVariables();
7381 {
7382 TIME_SECTION("fillCouplingMatrix", 3, "Filling Coupling Matrix");
7383
7384 switch (_coupling)
7385 {
7387 cm = std::make_unique<CouplingMatrix>(n_vars);
7388 for (unsigned int i = 0; i < n_vars; i++)
7389 (*cm)(i, i) = 1;
7390 break;
7391
7392 // for full jacobian
7394 cm = std::make_unique<CouplingMatrix>(n_vars);
7395 for (unsigned int i = 0; i < n_vars; i++)
7396 for (unsigned int j = 0; j < n_vars; j++)
7397 (*cm)(i, j) = 1;
7398 break;
7399
7401 // do nothing, _cm was already set through couplingMatrix() call
7402 break;
7403 }
7404 }
7405
7406 nl->dofMap()._dof_coupling = cm.get();
7407
7408 // If there are no variables, make sure to pass a nullptr coupling
7409 // matrix, to avoid warnings about non-nullptr yet empty
7410 // CouplingMatrices.
7411 if (n_vars == 0)
7412 nl->dofMap()._dof_coupling = nullptr;
7413
7414 nl->dofMap().attach_extra_sparsity_function(&extraSparsity, nl.get());
7415 nl->dofMap().attach_extra_send_list_function(&extraSendList, nl.get());
7416 _aux->dofMap().attach_extra_send_list_function(&extraSendList, _aux.get());
7417
7418 if (!_skip_nl_system_check && _solve && n_vars == 0)
7419 mooseError("No variables specified in nonlinear system '", nl->name(), "'.");
7420 }
7421
7422 for (const auto param :
7423 {"constant_null_space_variables", "constant_transpose_null_space_variables"})
7424 for (const auto & var : getParam<std::vector<VariableName>>(param))
7425 if (std::none_of(_nl.begin(),
7426 _nl.end(),
7427 [&var](const auto & nl)
7428 { return nl->hasVariable(var) || nl->hasScalarVariable(var); }))
7429 paramError(param, "Variable '", var, "' is not in any nonlinear system.");
7430
7431 ghostGhostedBoundaries(); // We do this again right here in case new boundaries have been added
7432
7433 // We may have added element/nodes to the mesh in ghostGhostedBoundaries so we need to update
7434 // all of our mesh information. We need to make sure that mesh information is up-to-date before
7435 // EquationSystems::init because that will call through to updateGeomSearch (for sparsity
7436 // augmentation) and if we haven't added back boundary node information before that latter call,
7437 // then we're screwed. We'll get things like "Unable to find closest node!"
7441
7442 if (_mesh.doingPRefinement())
7443 {
7446 _displaced_problem->preparePRefinement();
7447 }
7448
7449 // do not assemble system matrix for JFNK solve
7450 for (auto & nl : _nl)
7451 if (solverParams(nl->number())._type == Moose::ST_JFNK)
7452 nl->turnOffJacobian();
7453
7454 for (auto & sys : _solver_systems)
7455 sys->preInit();
7456 _aux->preInit();
7457
7458 // Build the mortar segment meshes, if they haven't been already, for a couple reasons:
7459 // 1) Get the ghosting correct for both static and dynamic meshes
7460 // 2) Make sure the mortar mesh is built for mortar constraints that live on the static mesh
7461 //
7462 // It is worth-while to note that mortar meshes that live on a dynamic mesh will be built
7463 // during residual and Jacobian evaluation because when displacements are solution variables
7464 // the mortar mesh will move and change during the course of a non-linear solve. We DO NOT
7465 // redo ghosting during non-linear solve, so for purpose 1) the below call has to be made
7466 if (!_mortar_data->initialized())
7468
7469 {
7470 TIME_SECTION("EquationSystems::Init", 2, "Initializing Equation Systems");
7471 es().init();
7472 }
7473
7474 for (auto & sys : _solver_systems)
7475 sys->postInit();
7476 _aux->postInit();
7477
7478 // Now that the equation system and the dof distribution is done, we can generate the
7479 // finite volume-related parts if needed.
7480 if (haveFV())
7482
7483 for (auto & sys : _solver_systems)
7484 sys->update();
7485 _aux->update();
7486
7487 for (THREAD_ID tid = 0; tid < numThreads(); ++tid)
7488 for (const auto i : index_range(_nl))
7489 {
7490 mooseAssert(
7491 _cm[i],
7492 "Coupling matrix not set for system "
7493 << i
7494 << ". This should only happen if a preconditioner was not setup for this system");
7495 _assembly[tid][i]->init(_cm[i].get());
7496 }
7497
7499 _displaced_problem->init();
7500
7501#ifdef MOOSE_KOKKOS_ENABLED
7503 initKokkos();
7504#endif
7505
7506 _initialized = true;
7507}
7508
7509unsigned int
7510FEProblemBase::nlSysNum(const NonlinearSystemName & nl_sys_name) const
7511{
7512 std::istringstream ss(nl_sys_name);
7513 unsigned int nl_sys_num;
7514 if (!(ss >> nl_sys_num) || !ss.eof())
7515 nl_sys_num = libmesh_map_find(_nl_sys_name_to_num, nl_sys_name);
7516
7517 return nl_sys_num;
7518}
7519
7520unsigned int
7521FEProblemBase::linearSysNum(const LinearSystemName & linear_sys_name) const
7522{
7523 std::istringstream ss(linear_sys_name);
7524 unsigned int linear_sys_num;
7525 if (!(ss >> linear_sys_num) || !ss.eof())
7526 linear_sys_num = libmesh_map_find(_linear_sys_name_to_num, linear_sys_name);
7527
7528 return linear_sys_num;
7529}
7530
7531unsigned int
7532FEProblemBase::solverSysNum(const SolverSystemName & solver_sys_name) const
7533{
7534 std::istringstream ss(solver_sys_name);
7535 unsigned int solver_sys_num;
7536 if (!(ss >> solver_sys_num) || !ss.eof())
7537 {
7538 const auto & search = _solver_sys_name_to_num.find(solver_sys_name);
7539 if (search == _solver_sys_name_to_num.end())
7540 mooseError("The solver system number was requested for system '" + solver_sys_name,
7541 "' but this system does not exist in the Problem. Systems can be added to the "
7542 "problem using the 'nl_sys_names'/'linear_sys_names' parameter.\nSystems in the "
7543 "Problem: " +
7545 solver_sys_num = search->second;
7546 }
7547
7548 return solver_sys_num;
7549}
7550
7551unsigned int
7552FEProblemBase::systemNumForVariable(const VariableName & variable_name) const
7553{
7554 for (const auto & solver_sys : _solver_systems)
7555 if (solver_sys->hasVariable(variable_name))
7556 return solver_sys->number();
7557 mooseAssert(_aux, "Should have an auxiliary system");
7558 if (_aux->hasVariable(variable_name))
7559 return _aux->number();
7560
7561 mooseError("Variable '",
7562 variable_name,
7563 "' was not found in any solver (nonlinear/linear) or auxiliary system");
7564}
7565
7566void
7567FEProblemBase::solve(const unsigned int nl_sys_num)
7568{
7569 TIME_SECTION("solve", 1, "Solving", false);
7570
7571 setCurrentNonlinearSystem(nl_sys_num);
7572
7573 // This prevents stale dof indices from lingering around and possibly leading to invalid reads
7574 // and writes. Dof indices may be made stale through operations like mesh adaptivity
7577 _displaced_problem->clearAllDofIndices();
7578
7579 // Setup the output system for printing linear/nonlinear iteration information and some solver
7580 // settings, including setting matrix prefixes. This must occur before petscSetOptions
7582
7583#if PETSC_RELEASE_LESS_THAN(3, 12, 0)
7585 _petsc_options, _solver_params); // Make sure the PETSc options are setup for this app
7586#else
7587 // Now this database will be the default
7588 // Each app should have only one database
7589 if (!_app.isUltimateMaster())
7590 LibmeshPetscCall(PetscOptionsPush(_petsc_option_data_base));
7591 // We did not add PETSc options to database yet
7593 {
7594 // Insert options for all systems all at once
7597 }
7598#endif
7599
7600 // set up DM which is required if use a field split preconditioner
7601 // We need to setup DM every "solve()" because libMesh destroy SNES after solve()
7602 // Do not worry, DM setup is very cheap
7604
7606
7607 // reset flag so that residual evaluation does not get skipped
7608 // and the next non-linear iteration does not automatically fail with
7609 // "DIVERGED_NANORINF", when we throw an exception and stop solve
7611
7612 if (_solve)
7613 {
7616 }
7617
7618 // sync solutions in displaced problem
7620 _displaced_problem->syncSolutions();
7621
7622#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
7623 if (!_app.isUltimateMaster())
7624 LibmeshPetscCall(PetscOptionsPop());
7625#endif
7626}
7627
7628void
7629FEProblemBase::setException(const std::string & message)
7630{
7631 _has_exception = true;
7632 _exception_message = message;
7633}
7634
7635void
7637{
7639 return;
7640
7641 TIME_SECTION("checkExceptionAndStopSolve", 5);
7642
7643 // See if any processor had an exception. If it did, get back the
7644 // processor that the exception occurred on.
7645 unsigned int processor_id;
7646
7648
7649 if (_has_exception)
7650 {
7652
7654 {
7655 // Print the message
7656 if (_communicator.rank() == 0 && print_message)
7657 {
7658 _console << "\n" << _exception_message << "\n";
7659 if (isTransient())
7660 _console
7661 << "To recover, the solution will fail and then be re-attempted with a reduced time "
7662 "step.\n"
7663 << std::endl;
7664 }
7665
7666 // Stop the solve -- this entails setting
7667 // SNESSetFunctionDomainError() or directly inserting NaNs in the
7668 // residual vector to let PETSc >= 3.6 return DIVERGED_NANORINF.
7669 if (_current_nl_sys)
7671
7674
7675 // and close Aux system (we MUST do this here; see #11525)
7676 _aux->solution().close();
7677
7678 // We've handled this exception, so we no longer have one.
7679 _has_exception = false;
7680
7681 // Force the next non-linear convergence check to fail (and all further residual evaluation
7682 // to be skipped).
7684
7685 // Repropagate the exception, so it can be caught at a higher level, typically
7686 // this is NonlinearSystem::computeResidual().
7688 }
7689 else
7690 mooseError("The following parallel-communicated exception was detected during " +
7691 Moose::stringify(_current_execute_on_flag) + " evaluation:\n" +
7693 "\nBecause this did not occur during residual evaluation, there"
7694 " is no way to handle this, so the solution is aborting.\n");
7695 }
7696}
7697
7698void
7700{
7701 // Our default state is to allow computing derivatives
7702 ADReal::do_derivatives = true;
7704
7705 // Clear the VectorTags and MatrixTags
7708
7711
7716 {
7717 _displaced_problem->setCurrentlyComputingResidual(false);
7718 _displaced_problem->setCurrentlyComputingJacobian(false);
7719 _displaced_problem->setCurrentlyComputingResidualAndJacobian(false);
7720 }
7721}
7722
7723void
7724FEProblemBase::solveLinearSystem(const unsigned int linear_sys_num,
7726{
7727 TIME_SECTION("solve", 1, "Solving", false);
7728
7729 setCurrentLinearSystem(linear_sys_num);
7730
7731 const Moose::PetscSupport::PetscOptions & options = po ? *po : _petsc_options;
7732 auto & solver_params = _solver_params[numNonlinearSystems() + linear_sys_num];
7733
7734 // Set custom convergence criteria
7736
7737#if PETSC_RELEASE_LESS_THAN(3, 12, 0)
7738 LibmeshPetscCall(Moose::PetscSupport::petscSetOptions(
7739 options, solver_params)); // Make sure the PETSc options are setup for this app
7740#else
7741 // Now this database will be the default
7742 // Each app should have only one database
7743 if (!_app.isUltimateMaster())
7744 LibmeshPetscCall(PetscOptionsPush(_petsc_option_data_base));
7745
7746 // We did not add PETSc options to database yet
7748 {
7749 Moose::PetscSupport::petscSetOptions(options, solver_params, this);
7751 }
7752#endif
7753
7754 if (_solve)
7756
7757#if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
7758 if (!_app.isUltimateMaster())
7759 LibmeshPetscCall(PetscOptionsPop());
7760#endif
7761}
7762
7763bool
7764FEProblemBase::solverSystemConverged(const unsigned int sys_num)
7765{
7766 if (_solve)
7767 return _solver_systems[sys_num]->converged();
7768 else
7769 return true;
7770}
7771
7772unsigned int
7773FEProblemBase::nNonlinearIterations(const unsigned int nl_sys_num) const
7774{
7775 return _nl[nl_sys_num]->nNonlinearIterations();
7776}
7777
7778unsigned int
7779FEProblemBase::nLinearIterations(const unsigned int nl_sys_num) const
7780{
7781 return _nl[nl_sys_num]->nLinearIterations();
7782}
7783
7784Real
7785FEProblemBase::finalNonlinearResidual(const unsigned int nl_sys_num) const
7786{
7787 return _nl[nl_sys_num]->finalNonlinearResidual();
7788}
7789
7790bool
7791FEProblemBase::computingPreSMOResidual(const unsigned int nl_sys_num) const
7792{
7793 return _nl[nl_sys_num]->computingPreSMOResidual();
7794}
7795
7796void
7798{
7799 TIME_SECTION("copySolutionsBackwards", 3, "Copying Solutions Backward");
7800
7801 for (auto & sys : _solver_systems)
7802 sys->copyStateHistoryBackwards();
7803 _aux->copyStateHistoryBackwards();
7804}
7805
7806void
7808{
7809 for (auto & sys : _solver_systems)
7810 sys->skipNextSolutionToOldCopy();
7811 _aux->skipNextSolutionToOldCopy();
7812}
7813
7814void
7816{
7817 TIME_SECTION("advanceState", 5, "Advancing State");
7818
7819 for (auto & sys : _solver_systems)
7820 sys->advanceStateHistory(Moose::SolutionIterationType::Time);
7821 _aux->advanceStateHistory(Moose::SolutionIterationType::Time);
7822
7824 {
7825 for (const auto i : index_range(_solver_systems))
7826 _displaced_problem->solverSys(i).advanceStateHistory(Moose::SolutionIterationType::Time);
7827 _displaced_problem->auxSys().advanceStateHistory(Moose::SolutionIterationType::Time);
7828 }
7829
7831
7833
7836
7839
7842
7843#ifdef MOOSE_KOKKOS_ENABLED
7846
7849
7852#endif
7853
7855}
7856
7857void
7859{
7861
7863 _displaced_problem->geomSearchData().backup();
7864}
7865
7866void
7868{
7870
7872 _displaced_problem->geomSearchData().restore();
7873}
7874
7875void
7877{
7878 TIME_SECTION("restoreSolutions", 5, "Restoring Solutions");
7879
7880 if (!_not_zeroed_tagged_vectors.empty())
7881 paramError("not_zeroed_tag_vectors",
7882 "There is currently no way to restore not-zeroed vectors.");
7883
7884 for (auto & sys : _solver_systems)
7885 {
7886 if (_verbose_restore)
7887 _console << "Restoring solutions on system " << sys->name() << "..." << std::endl;
7888 sys->restoreStateHistory();
7889 }
7890
7891 if (_verbose_restore)
7892 _console << "Restoring solutions on Auxiliary system..." << std::endl;
7893 _aux->restoreStateHistory();
7894
7895 if (_verbose_restore)
7896 _console << "Restoring postprocessor, vector-postprocessor, and reporter data..." << std::endl;
7898
7900 _displaced_problem->updateMesh();
7901}
7902
7903void
7905{
7906 TIME_SECTION("saveOldSolutions", 5, "Saving Old Solutions");
7907
7908 for (auto & sys : _solver_systems)
7909 sys->saveOldSolutions();
7910 _aux->saveOldSolutions();
7911}
7912
7913void
7915{
7916 TIME_SECTION("restoreOldSolutions", 5, "Restoring Old Solutions");
7917
7918 for (auto & sys : _solver_systems)
7919 sys->restoreOldSolutions();
7920 _aux->restoreOldSolutions();
7921}
7922
7923void
7925{
7926 TIME_SECTION("outputStep", 1, "Outputting");
7927
7929
7930 for (auto & sys : _solver_systems)
7931 sys->update();
7932 _aux->update();
7933
7935 _displaced_problem->syncSolutions();
7937
7939}
7940
7941void
7943{
7945}
7946
7947void
7952
7953void
7959
7960void
7962{
7963 TIME_SECTION("onTimestepBegin", 2);
7964
7965 for (auto & nl : _nl)
7966 nl->onTimestepBegin();
7967}
7968
7969void
7973
7974Real
7976{
7978 // If we are any iteration type other than time (e.g. nonlinear), then temporally we are still
7979 // in the present time
7980 return time();
7981
7982 switch (state.state)
7983 {
7984 case 0:
7985 return time();
7986
7987 case 1:
7988 return timeOld();
7989
7990 case 2:
7991 return timeOlder();
7992
7993 default:
7994 mooseError("Unhandled state ", state.state, " in FEProblemBase::getTimeFromStateArg");
7995 }
7996}
7997
7998void
7999FEProblemBase::addTimeIntegrator(const std::string & type,
8000 const std::string & name,
8001 InputParameters & parameters)
8002{
8003 parallel_object_only();
8004
8005 parameters.set<SubProblem *>("_subproblem") = this;
8006 logAdd("TimeIntegrator", name, type, parameters);
8007 _aux->addTimeIntegrator(type, name + ":aux", parameters);
8008 for (auto & sys : _solver_systems)
8009 sys->addTimeIntegrator(type, name + ":" + sys->name(), parameters);
8010 _has_time_integrator = true;
8011
8012 // add vectors to store u_dot, u_dotdot, udot_old, u_dotdot_old and
8013 // solution vectors older than 2 time steps, if requested by the time
8014 // integrator
8015 _aux->addDotVectors();
8016 for (auto & nl : _nl)
8017 {
8018 nl->addDotVectors();
8019
8020 auto tag_udot = nl->getTimeIntegrators()[0]->uDotFactorTag();
8021 if (!nl->hasVector(tag_udot))
8022 nl->associateVectorToTag(*nl->solutionUDot(), tag_udot);
8023 auto tag_udotdot = nl->getTimeIntegrators()[0]->uDotDotFactorTag();
8024 if (!nl->hasVector(tag_udotdot) && uDotDotRequested())
8025 nl->associateVectorToTag(*nl->solutionUDotDot(), tag_udotdot);
8026 }
8027
8029 // Time integrator does not exist when displaced problem is created.
8030 _displaced_problem->addTimeIntegrator();
8031}
8032
8033void
8034FEProblemBase::addPredictor(const std::string & type,
8035 const std::string & name,
8036 InputParameters & parameters)
8037{
8038 parallel_object_only();
8039
8041 mooseError("Vector bounds cannot be used with LinearSystems!");
8042
8043 parameters.set<SubProblem *>("_subproblem") = this;
8044 std::shared_ptr<Predictor> predictor = _factory.create<Predictor>(type, name, parameters);
8045 logAdd("Predictor", name, type, parameters);
8046
8047 for (auto & nl : _nl)
8048 nl->setPredictor(predictor);
8049}
8050
8051Real
8053{
8054 _current_nl_sys = &sys;
8055 computeResidual(*sys.currentSolution(), sys.RHS(), sys.number());
8056 return sys.RHS().l2_norm();
8057}
8058
8059Real
8061{
8062 _current_linear_sys = &sys;
8063
8064 // We assemble the current system to check the current residual
8068 /*compute fresh gradients*/ true);
8069
8070 // Unfortunate, but we have to allocate a new vector for the residual
8071 auto residual = sys.linearImplicitSystem().rhs->clone();
8072 residual->scale(-1.0);
8073 residual->add_vector(*sys.currentSolution(), *sys.linearImplicitSystem().matrix);
8074 return residual->l2_norm();
8075}
8076
8077Real
8079{
8080 TIME_SECTION("computeResidualL2Norm", 2, "Computing L2 Norm of Residual");
8081
8082 // We use sum the squared norms of the individual systems and then take the square root of it
8083 Real l2_norm = 0.0;
8084 for (auto sys : _nl)
8085 {
8086 const auto norm = computeResidualL2Norm(*sys);
8087 l2_norm += norm * norm;
8088 }
8089
8090 for (auto sys : _linear_systems)
8091 {
8092 const auto norm = computeResidualL2Norm(*sys);
8093 l2_norm += norm * norm;
8094 }
8095
8096 return std::sqrt(l2_norm);
8097}
8098
8099void
8100FEProblemBase::computeResidualSys(NonlinearImplicitSystem & sys,
8101 const NumericVector<Number> & soln,
8102 NumericVector<Number> & residual)
8103{
8104 parallel_object_only();
8105
8106 TIME_SECTION("computeResidualSys", 5);
8107 // Reset before residual setup, calculation & execution
8109
8110 computeResidual(soln, residual, sys.number());
8111}
8112
8113void
8114FEProblemBase::computeResidual(NonlinearImplicitSystem & sys,
8115 const NumericVector<Number> & soln,
8116 NumericVector<Number> & residual)
8117{
8118 mooseDeprecated("Please use computeResidualSys");
8119
8120 computeResidualSys(sys, soln, residual);
8121}
8122
8123void
8124FEProblemBase::computeResidual(const NumericVector<Number> & soln,
8125 NumericVector<Number> & residual,
8126 const unsigned int nl_sys_num)
8127{
8128 setCurrentNonlinearSystem(nl_sys_num);
8129
8130 // We associate the residual tag with the given residual vector to make sure we
8131 // don't filter it out below
8133 const auto & residual_vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
8134
8135 mooseAssert(_fe_vector_tags.empty(), "This should be empty indicating a clean starting state");
8136 // We filter out tags which do not have associated vectors in the current nonlinear
8137 // system. This is essential to be able to use system-dependent residual tags.
8139
8141 _fe_vector_tags.clear();
8142}
8143
8144void
8145FEProblemBase::computeResidualAndJacobian(const NumericVector<Number> & soln,
8146 NumericVector<Number> & residual,
8147 SparseMatrix<Number> & jacobian)
8148{
8149 try
8150 {
8151 try
8152 {
8153 // vector tags
8155 const auto & residual_vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
8156
8157 mooseAssert(_fe_vector_tags.empty(),
8158 "This should be empty indicating a clean starting state");
8159 // We filter out tags which do not have associated vectors in the current nonlinear
8160 // system. This is essential to be able to use system-dependent residual tags.
8162
8164
8165 // matrix tags
8166 {
8167 _fe_matrix_tags.clear();
8168
8169 auto & tags = getMatrixTags();
8170 for (auto & tag : tags)
8171 _fe_matrix_tags.insert(tag.second);
8172 }
8173
8175
8178
8179 for (const auto tag : _fe_matrix_tags)
8180 if (_current_nl_sys->hasMatrix(tag))
8181 {
8182 auto & matrix = _current_nl_sys->getMatrix(tag);
8183 matrix.zero();
8185 // PETSc algorithms require diagonal allocations regardless of whether there is non-zero
8186 // diagonal dependence. With global AD indexing we only add non-zero
8187 // dependence, so PETSc will scream at us unless we artificially add the diagonals.
8188 for (auto index : make_range(matrix.row_start(), matrix.row_stop()))
8189 matrix.add(index, index, 0);
8190 }
8191
8192 _aux->zeroVariablesForResidual();
8193
8194 unsigned int n_threads = numThreads();
8195
8197
8198 // Random interface objects
8199 for (const auto & it : _random_data_objects)
8200 it.second->updateSeeds(EXEC_LINEAR);
8201
8206 {
8207 _displaced_problem->setCurrentlyComputingResidual(true);
8208 _displaced_problem->setCurrentlyComputingJacobian(true);
8209 _displaced_problem->setCurrentlyComputingResidualAndJacobian(true);
8210 }
8211
8213
8214 for (unsigned int tid = 0; tid < n_threads; tid++)
8215 reinitScalars(tid);
8216
8217 _aux->residualSetup();
8218
8220 {
8222 _displaced_problem->updateMesh();
8223 if (_mortar_data->hasDisplacedObjects())
8225 }
8226
8227 for (THREAD_ID tid = 0; tid < n_threads; tid++)
8228 {
8231 }
8232
8233#ifdef MOOSE_KOKKOS_ENABLED
8235#endif
8236
8238
8240
8242
8244
8246
8249
8251
8254 }
8255 catch (...)
8256 {
8257 handleException("computeResidualAndJacobian");
8258 }
8259 }
8260 catch (const MooseException &)
8261 {
8262 // The buck stops here, we have already handled the exception by
8263 // calling the system's stopSolve() method, it is now up to PETSc to return a
8264 // "diverged" reason during the next solve.
8265 }
8266 catch (...)
8267 {
8268 mooseError("Unexpected exception type");
8269 }
8270
8271 resetState();
8272 _fe_vector_tags.clear();
8273 _fe_matrix_tags.clear();
8274}
8275
8276void
8277FEProblemBase::computeResidualTag(const NumericVector<Number> & soln,
8278 NumericVector<Number> & residual,
8279 TagID tag)
8280{
8281 try
8282 {
8284
8285 _current_nl_sys->associateVectorToTag(residual, tag);
8286
8287 computeResidualTags({tag});
8288
8290 }
8291 catch (MooseException & e)
8292 {
8293 // If a MooseException propagates all the way to here, it means
8294 // that it was thrown from a MOOSE system where we do not
8295 // (currently) properly support the throwing of exceptions, and
8296 // therefore we have no choice but to error out. It may be
8297 // *possible* to handle exceptions from other systems, but in the
8298 // meantime, we don't want to silently swallow any unhandled
8299 // exceptions here.
8300 mooseError("An unhandled MooseException was raised during residual computation. Please "
8301 "contact the MOOSE team for assistance.");
8302 }
8303}
8304
8305void
8306FEProblemBase::computeResidualInternal(const NumericVector<Number> & soln,
8307 NumericVector<Number> & residual,
8308 const std::set<TagID> & tags)
8309{
8310 parallel_object_only();
8311
8312 TIME_SECTION("computeResidualInternal", 1);
8313
8314 try
8315 {
8317
8319
8320 computeResidualTags(tags);
8321
8323 }
8324 catch (MooseException & e)
8325 {
8326 // If a MooseException propagates all the way to here, it means
8327 // that it was thrown from a MOOSE system where we do not
8328 // (currently) properly support the throwing of exceptions, and
8329 // therefore we have no choice but to error out. It may be
8330 // *possible* to handle exceptions from other systems, but in the
8331 // meantime, we don't want to silently swallow any unhandled
8332 // exceptions here.
8333 mooseError("An unhandled MooseException was raised during residual computation. Please "
8334 "contact the MOOSE team for assistance.");
8335 }
8336}
8337
8338void
8339FEProblemBase::computeResidualType(const NumericVector<Number> & soln,
8340 NumericVector<Number> & residual,
8341 TagID tag)
8342{
8343 TIME_SECTION("computeResidualType", 5);
8344
8345 try
8346 {
8348
8350
8352
8354 }
8355 catch (MooseException & e)
8356 {
8357 // If a MooseException propagates all the way to here, it means
8358 // that it was thrown from a MOOSE system where we do not
8359 // (currently) properly support the throwing of exceptions, and
8360 // therefore we have no choice but to error out. It may be
8361 // *possible* to handle exceptions from other systems, but in the
8362 // meantime, we don't want to silently swallow any unhandled
8363 // exceptions here.
8364 mooseError("An unhandled MooseException was raised during residual computation. Please "
8365 "contact the MOOSE team for assistance.");
8366 }
8367}
8368
8369void
8370FEProblemBase::translateCaughtException(const std::string & calling_method)
8371{
8372 auto create_exception_message =
8373 [&calling_method](const std::string & exception_type, const auto & exception)
8374 {
8375 return std::string("A " + exception_type + " was raised during FEProblemBase::" +
8376 calling_method + "\n" + std::string(exception.what()));
8377 };
8378
8379 try
8380 {
8381 throw;
8382 }
8383 catch (const MooseHandledException &)
8384 {
8385 // Already communicated to all processes and the solve has been stopped
8386 throw;
8387 }
8388 catch (const MooseException & e)
8389 {
8390 setException(create_exception_message("MooseException", e));
8391 }
8392 catch (const MetaPhysicL::LogicError & e)
8393 {
8395 }
8396 catch (const libMesh::PetscSolverException & e)
8397 {
8398 // One PETSc solver exception that we cannot currently recover from are new nonzero errors. In
8399 // particular I have observed the following scenario in a parallel test:
8400 // - Both processes throw because of a new nonzero during MOOSE's computeJacobianTags
8401 // - We potentially handle the exceptions nicely here
8402 // - When the matrix is closed in libMesh's libmesh_petsc_snes_solver, there is a new nonzero
8403 // throw which we do not catch here in MOOSE and the simulation terminates. This only appears
8404 // in parallel (and not all the time; a test I was examining threw with distributed mesh, but
8405 // not with replicated). In serial there are no new throws from libmesh_petsc_snes_solver.
8406 // So for uniformity of behavior across serial/parallel, we will choose to abort here and always
8407 // produce a non-zero exit code
8408 mooseError(create_exception_message("libMesh::PetscSolverException", e));
8409 }
8410 catch (const std::exception & e)
8411 {
8412 // This might be libMesh detecting a degenerate Jacobian or matrix
8413 if (strstr(e.what(), "Jacobian") || strstr(e.what(), "singular") ||
8414 strstr(e.what(), "det != 0"))
8415 setException(create_exception_message("libMesh DegenerateMap", e));
8416 else
8417 {
8418 const auto message = create_exception_message("std::exception", e);
8420 mooseError(message);
8421 else
8422 setException(message);
8423 }
8424 }
8425}
8426
8427void
8428FEProblemBase::handleException(const std::string & calling_method)
8429{
8430 translateCaughtException(calling_method);
8432}
8433
8434void
8435FEProblemBase::translateUserObjectExceptions(const std::function<void()> & work)
8436{
8437 try
8438 {
8439 work();
8440 }
8441 catch (...)
8442 {
8443 translateCaughtException("computeUserObjectsInternal");
8444 }
8445}
8446
8447void
8448FEProblemBase::computeResidualTags(const std::set<TagID> & tags)
8449{
8450 parallel_object_only();
8451
8452 try
8453 {
8454 try
8455 {
8456 TIME_SECTION("computeResidualTags", 5, "Computing Residual");
8457
8458 ADReal::do_derivatives = false;
8459
8461
8462 _aux->zeroVariablesForResidual();
8463
8464 unsigned int n_threads = numThreads();
8465
8467
8468 // Random interface objects
8469 for (const auto & it : _random_data_objects)
8470 it.second->updateSeeds(EXEC_LINEAR);
8471
8472 // This is itself a residual evaluation (distinct from the combined residual/Jacobian path
8473 // above, which sets this before its own updateMortarMesh() call): mark it so that
8474 // updateMortarMesh() below knows not to reinit the equation systems mid-evaluation. Reset by
8475 // resetState() at the bottom of this function.
8478 _displaced_problem->setCurrentlyComputingResidual(true);
8479
8481
8482 for (unsigned int tid = 0; tid < n_threads; tid++)
8483 reinitScalars(tid);
8484
8485 _aux->residualSetup();
8486
8488 {
8490 _displaced_problem->updateMesh();
8491 if (_mortar_data->hasDisplacedObjects())
8493 }
8494
8495 for (THREAD_ID tid = 0; tid < n_threads; tid++)
8496 {
8499 }
8500
8501#ifdef MOOSE_KOKKOS_ENABLED
8503#endif
8504
8506
8508
8510
8512
8514
8517 }
8518 catch (...)
8519 {
8520 handleException("computeResidualTags");
8521 }
8522 }
8523 catch (const MooseException &)
8524 {
8525 // The buck stops here, we have already handled the exception by
8526 // calling the system's stopSolve() method, it is now up to PETSc to return a
8527 // "diverged" reason during the next solve.
8528 }
8529 catch (...)
8530 {
8531 mooseError("Unexpected exception type");
8532 }
8533
8534 resetState();
8535}
8536
8537void
8538FEProblemBase::computeJacobianSys(NonlinearImplicitSystem & sys,
8539 const NumericVector<Number> & soln,
8540 SparseMatrix<Number> & jacobian)
8541{
8542 // Reset before Jacobian setup, calculation & execution
8544 computeJacobian(soln, jacobian, sys.number());
8545}
8546
8547void
8548FEProblemBase::computeJacobianTag(const NumericVector<Number> & soln,
8549 SparseMatrix<Number> & jacobian,
8550 TagID tag)
8551{
8553
8554 _current_nl_sys->associateMatrixToTag(jacobian, tag);
8555
8556 computeJacobianTags({tag});
8557
8559}
8560
8561void
8562FEProblemBase::computeJacobian(const NumericVector<Number> & soln,
8563 SparseMatrix<Number> & jacobian,
8564 const unsigned int nl_sys_num)
8565{
8566 setCurrentNonlinearSystem(nl_sys_num);
8567
8568 _fe_matrix_tags.clear();
8569
8570 auto & tags = getMatrixTags();
8571 for (auto & tag : tags)
8572 _fe_matrix_tags.insert(tag.second);
8573
8575}
8576
8577void
8578FEProblemBase::computeJacobianInternal(const NumericVector<Number> & soln,
8579 SparseMatrix<Number> & jacobian,
8580 const std::set<TagID> & tags)
8581{
8582 TIME_SECTION("computeJacobianInternal", 1);
8583
8585
8587
8588 computeJacobianTags(tags);
8589
8591}
8592
8593void
8594FEProblemBase::computeJacobianTags(const std::set<TagID> & tags)
8595{
8596 try
8597 {
8598 try
8599 {
8601 {
8602 TIME_SECTION("computeJacobianTags", 5, "Computing Jacobian");
8603
8604 for (auto tag : tags)
8605 if (_current_nl_sys->hasMatrix(tag))
8606 {
8607 auto & matrix = _current_nl_sys->getMatrix(tag);
8610 else
8611 matrix.zero();
8613 // PETSc algorithms require diagonal allocations regardless of whether there is
8614 // non-zero diagonal dependence. With global AD indexing we only add non-zero
8615 // dependence, so PETSc will scream at us unless we artificially add the diagonals.
8616 for (auto index : make_range(matrix.row_start(), matrix.row_stop()))
8617 matrix.add(index, index, 0);
8618 }
8619
8620 _aux->zeroVariablesForJacobian();
8621
8622 unsigned int n_threads = numThreads();
8623
8624 // Random interface objects
8625 for (const auto & it : _random_data_objects)
8626 it.second->updateSeeds(EXEC_NONLINEAR);
8627
8631 _displaced_problem->setCurrentlyComputingJacobian(true);
8632
8634
8635 for (unsigned int tid = 0; tid < n_threads; tid++)
8636 reinitScalars(tid);
8637
8638 _aux->jacobianSetup();
8639
8641 {
8643 _displaced_problem->updateMesh();
8644 // A standalone scaling Jacobian is assembled without a preceding residual evaluation, so
8645 // the displaced mortar segment mesh can be stale relative to the just-updated displaced
8646 // parent mesh. Every other Jacobian evaluation is preceded by a residual (or combined
8647 // residual/Jacobian) evaluation that already rebuilt the mortar mesh, so doing it here in
8648 // the general case would be duplicative.
8649 if (_current_nl_sys->computingScalingJacobian() && _mortar_data->hasDisplacedObjects())
8651 }
8652
8653 for (unsigned int tid = 0; tid < n_threads; tid++)
8654 {
8657 }
8658
8659#ifdef MOOSE_KOKKOS_ENABLED
8661#endif
8662
8664
8666
8668
8670
8672
8674
8676
8677 // For explicit Euler calculations for example we often compute the Jacobian one time and
8678 // then re-use it over and over. If we're performing automatic scaling, we don't want to
8679 // use that kernel, diagonal-block only Jacobian for our actual matrix when performing
8680 // solves!
8682 _has_jacobian = true;
8683 }
8684 }
8685 catch (...)
8686 {
8687 handleException("computeJacobianTags");
8688 }
8689 }
8690 catch (const MooseException &)
8691 {
8692 // The buck stops here, we have already handled the exception by
8693 // calling the system's stopSolve() method, it is now up to PETSc to return a
8694 // "diverged" reason during the next solve.
8695 }
8696 catch (...)
8697 {
8698 mooseError("Unexpected exception type");
8699 }
8700
8701 resetState();
8702}
8703
8704void
8705FEProblemBase::computeJacobianBlocks(std::vector<JacobianBlock *> & blocks,
8706 const unsigned int nl_sys_num)
8707{
8708 TIME_SECTION("computeTransientImplicitJacobian", 2);
8709 setCurrentNonlinearSystem(nl_sys_num);
8710
8712 {
8714 _displaced_problem->updateMesh();
8715 }
8716
8718
8722}
8723
8724void
8725FEProblemBase::computeJacobianBlock(SparseMatrix<Number> & jacobian,
8726 libMesh::System & precond_system,
8727 unsigned int ivar,
8728 unsigned int jvar)
8729{
8730 JacobianBlock jac_block(precond_system, jacobian, ivar, jvar);
8731 std::vector<JacobianBlock *> blocks = {&jac_block};
8732 mooseAssert(_current_nl_sys, "This should be non-null");
8734}
8735
8736void
8737FEProblemBase::computeBounds(NonlinearImplicitSystem & libmesh_dbg_var(sys),
8738 NumericVector<Number> & lower,
8739 NumericVector<Number> & upper)
8740{
8741 try
8742 {
8743 try
8744 {
8745 mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
8746 "I expect these system numbers to be the same");
8747
8748 if (!_current_nl_sys->hasVector("lower_bound") || !_current_nl_sys->hasVector("upper_bound"))
8749 return;
8750
8751 TIME_SECTION("computeBounds", 1, "Computing Bounds");
8752
8753 NumericVector<Number> & _lower = _current_nl_sys->getVector("lower_bound");
8754 NumericVector<Number> & _upper = _current_nl_sys->getVector("upper_bound");
8755 _lower.swap(lower);
8756 _upper.swap(upper);
8757 for (THREAD_ID tid = 0; tid < numThreads(); tid++)
8759
8760 _aux->residualSetup();
8762 _lower.swap(lower);
8763 _upper.swap(upper);
8764 }
8765 catch (...)
8766 {
8767 handleException("computeBounds");
8768 }
8769 }
8770 catch (MooseException & e)
8771 {
8772 mooseError("Irrecoverable exception: " + std::string(e.what()));
8773 }
8774 catch (...)
8775 {
8776 mooseError("Unexpected exception type");
8777 }
8778}
8779
8780void
8781FEProblemBase::computeLinearSystemSys(LinearImplicitSystem & sys,
8782 SparseMatrix<Number> & system_matrix,
8783 NumericVector<Number> & rhs,
8784 const bool compute_gradients)
8785{
8786 TIME_SECTION("computeLinearSystemSys", 5);
8787
8789
8792
8793 // We are using the residual tag system for right hand sides so we fetch everything
8794 const auto & vector_tags = getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
8795
8796 // We filter out tags which do not have associated vectors in the current
8797 // system. This is essential to be able to use system-dependent vector tags.
8800
8804 compute_gradients);
8805
8810 // We reset the tags to the default containers for further operations
8815}
8816
8817void
8818FEProblemBase::computeLinearSystemTags(const NumericVector<Number> & soln,
8819 const std::set<TagID> & vector_tags,
8820 const std::set<TagID> & matrix_tags,
8821 const bool compute_gradients)
8822{
8823 TIME_SECTION("computeLinearSystemTags", 5, "Computing Linear System");
8824
8826
8827 for (auto tag : matrix_tags)
8828 {
8829 auto & matrix = _current_linear_sys->getMatrix(tag);
8830 matrix.zero();
8831 }
8832
8833 unsigned int n_threads = numThreads();
8834
8836
8837 // Random interface objects
8838 for (const auto & it : _random_data_objects)
8839 it.second->updateSeeds(EXEC_NONLINEAR);
8840
8842
8844
8845 _aux->jacobianSetup();
8846
8847 for (THREAD_ID tid = 0; tid < n_threads; tid++)
8848 {
8850 }
8851
8852#ifdef MOOSE_KOKKOS_ENABLED
8854#endif
8855
8856 try
8857 {
8859 }
8860 catch (MooseException & e)
8861 {
8862 _console << "\nA MooseException was raised during Auxiliary variable computation.\n"
8863 << "The next solve will fail, the timestep will be reduced, and we will try again.\n"
8864 << std::endl;
8865
8866 // We know the next solve is going to fail, so there's no point in
8867 // computing anything else after this. Plus, using incompletely
8868 // computed AuxVariables in subsequent calculations could lead to
8869 // other errors or unhandled exceptions being thrown.
8870 return;
8871 }
8872
8875
8877
8878 _current_linear_sys->computeLinearSystemTags(vector_tags, matrix_tags, compute_gradients);
8879
8880 // Reset execution flag as after this point we are no longer on LINEAR
8882
8883 // These are the relevant parts of resetState()
8886}
8887
8888void
8889FEProblemBase::computeNearNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
8890 std::vector<NumericVector<Number> *> & sp)
8891{
8892 mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
8893 "I expect these system numbers to be the same");
8894
8895 sp.clear();
8896 for (unsigned int i = 0; i < subspaceDim("NearNullSpace"); ++i)
8897 {
8898 std::stringstream postfix;
8899 postfix << "_" << i;
8900 std::string modename = "NearNullSpace" + postfix.str();
8901 sp.push_back(&_current_nl_sys->getVector(modename));
8902 }
8903}
8904
8905void
8906FEProblemBase::computeNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
8907 std::vector<NumericVector<Number> *> & sp)
8908{
8909 mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
8910 "I expect these system numbers to be the same");
8911 sp.clear();
8912 for (unsigned int i = 0; i < subspaceDim("NullSpace"); ++i)
8913 {
8914 std::stringstream postfix;
8915 postfix << "_" << i;
8916 sp.push_back(&_current_nl_sys->getVector("NullSpace" + postfix.str()));
8917 }
8918 appendConstantModes(_constant_null_space_vars, "ConstantNullSpace_", sp);
8919}
8920
8921void
8922FEProblemBase::computeTransposeNullSpace(NonlinearImplicitSystem & libmesh_dbg_var(sys),
8923 std::vector<NumericVector<Number> *> & sp)
8924{
8925 mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
8926 "I expect these system numbers to be the same");
8927 sp.clear();
8928 for (unsigned int i = 0; i < subspaceDim("TransposeNullSpace"); ++i)
8929 {
8930 std::stringstream postfix;
8931 postfix << "_" << i;
8932 sp.push_back(&_current_nl_sys->getVector("TransposeNullSpace" + postfix.str()));
8933 }
8934 appendConstantModes(_constant_transpose_null_space_vars, "ConstantTransposeNullSpace_", sp);
8935}
8936
8937void
8938FEProblemBase::appendConstantModes(const std::vector<VariableName> & vars,
8939 const std::string & prefix,
8940 std::vector<NumericVector<Number> *> & sp)
8941{
8942 auto & sys = _current_nl_sys->system();
8943 std::vector<dof_id_type> dofs;
8944 for (const auto & var : vars)
8945 {
8946 // Each variable lives in exactly one nonlinear system
8947 if (!sys.has_variable(var))
8948 continue;
8949
8950 // The mode is rebuilt on every request so that it stays valid after the dof
8951 // distribution changes, e.g. after mesh adaptivity
8952 auto & mode = _current_nl_sys->addVector(prefix + var, false, libMesh::PARALLEL);
8953 mode.zero();
8955 for (const auto dof : dofs)
8956 mode.set(dof, 1);
8957 mode.close();
8958 sp.push_back(&mode);
8959 }
8960}
8961
8962void
8963FEProblemBase::computePostCheck(NonlinearImplicitSystem & sys,
8964 const NumericVector<Number> & old_soln,
8965 NumericVector<Number> & search_direction,
8966 NumericVector<Number> & new_soln,
8967 bool & changed_search_direction,
8968 bool & changed_new_soln)
8969{
8970 mooseAssert(_current_nl_sys && (sys.number() == _current_nl_sys->number()),
8971 "I expect these system numbers to be the same");
8972
8973 // This function replaces the old PetscSupport::dampedCheck() function.
8974 //
8975 // 1.) Recreate code in PetscSupport::dampedCheck() for constructing
8976 // ghosted "soln" and "update" vectors.
8977 // 2.) Call FEProblemBase::computeDamping() with these ghost vectors.
8978 // 3.) Recreate the code in PetscSupport::dampedCheck() to actually update
8979 // the solution vector based on the damping, and set the "changed" flags
8980 // appropriately.
8981
8982 TIME_SECTION("computePostCheck", 2, "Computing Post Check");
8983
8985
8986 // MOOSE's FEProblemBase doesn't update the solution during the
8987 // postcheck, but FEProblemBase-derived classes might.
8989 {
8990 // We need ghosted versions of new_soln and search_direction (the
8991 // ones we get from libmesh/PETSc are PARALLEL vectors. To make
8992 // our lives simpler, we use the same ghosting pattern as the
8993 // system's current_local_solution to create new ghosted vectors.
8994
8995 // Construct zeroed-out clones with the same ghosted dofs as the
8996 // System's current_local_solution.
8997 std::unique_ptr<NumericVector<Number>> ghosted_solution =
8998 sys.current_local_solution->zero_clone(),
8999 ghosted_search_direction =
9000 sys.current_local_solution->zero_clone();
9001
9002 // Copy values from input vectors into clones with ghosted values.
9003 *ghosted_solution = new_soln;
9004 *ghosted_search_direction = search_direction;
9005
9006 if (_has_dampers)
9007 {
9008 // Compute the damping coefficient using the ghosted vectors
9009 Real damping = computeDamping(*ghosted_solution, *ghosted_search_direction);
9010
9011 // If some non-trivial damping was computed, update the new_soln
9012 // vector accordingly.
9013 if (damping < 1.0)
9014 {
9015 new_soln = old_soln;
9016 new_soln.add(-damping, search_direction);
9017 changed_new_soln = true;
9018 }
9019 }
9020
9022 {
9023 // Update the ghosted copy of the new solution, if necessary.
9024 if (changed_new_soln)
9025 *ghosted_solution = new_soln;
9026
9027 bool updated_solution = updateSolution(new_soln, *ghosted_solution);
9028 if (updated_solution)
9029 changed_new_soln = true;
9030 }
9031 }
9032
9034 {
9036 _aux->copyCurrentIntoPreviousNL();
9037 }
9038
9039 // MOOSE doesn't change the search_direction
9040 changed_search_direction = false;
9041
9043}
9044
9045Real
9046FEProblemBase::computeDamping(const NumericVector<Number> & soln,
9047 const NumericVector<Number> & update)
9048{
9049 // Default to no damping
9050 Real damping = 1.0;
9051
9052 if (_has_dampers)
9053 {
9054 TIME_SECTION("computeDamping", 1, "Computing Damping");
9055
9056 // Save pointer to the current solution
9057 const NumericVector<Number> * _saved_current_solution = _current_nl_sys->currentSolution();
9058
9060 // For now, do not re-compute auxiliary variables. Doing so allows a wild solution increment
9061 // to get to the material models, which may not be able to cope with drastically different
9062 // values. Once more complete dependency checking is in place, auxiliary variables (and
9063 // material properties) will be computed as needed by dampers.
9064 // _aux.compute();
9065 damping = _current_nl_sys->computeDamping(soln, update);
9066
9067 // restore saved solution
9068 _current_nl_sys->setSolution(*_saved_current_solution);
9069 }
9070
9071 return damping;
9072}
9073
9074bool
9076{
9077 return false;
9078}
9079
9080bool
9081FEProblemBase::updateSolution(NumericVector<Number> & /*vec_solution*/,
9082 NumericVector<Number> & /*ghosted_solution*/)
9083{
9084 return false;
9085}
9086
9087void
9088FEProblemBase::predictorCleanup(NumericVector<Number> & /*ghosted_solution*/)
9089{
9090}
9091
9092void
9094{
9095 parallel_object_only();
9096
9099}
9100
9101void
9103{
9104 TIME_SECTION("updateGeometricSearch", 3, "Updating Geometric Search");
9105
9107
9109 _displaced_problem->updateGeomSearch(type);
9110}
9111
9112void
9114{
9115 TIME_SECTION("updateMortarMesh", 5, "Updating Mortar Mesh");
9116
9118
9119 // If any mortar interface's coverage changed, the DoF ghosting and sparsity that
9120 // AugmentSparsityOnInterface computed from the previous coverage are stale (see
9121 // reinitBecauseOfGhostingOrNewGeomObjects()'s mortar_changed parameter); refresh them now rather
9122 // than leaving that to the caller, since this may be called mid-solve where no other reinit
9123 // follows. Guard on _initialized: this is also called from init() itself, before es().init() has
9124 // run for the first time, and reinit()ing an EquationSystems that has never been init()ed is not
9125 // meaningful (init() immediately after will pick up whatever _mortar_data->update() just built).
9126 if (_mortar_data->update() && _initialized && !currentlyComputingResidual() &&
9128 reinitBecauseOfGhostingOrNewGeomObjects(/*mortar_changed=*/true);
9129}
9130
9131void
9133 const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
9134 const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
9135 bool on_displaced,
9136 bool periodic,
9137 const bool debug,
9138 const bool correct_edge_dropping,
9139 const Real minimum_projection_angle,
9140 const Mortar3DSubpatchPlane mortar_3d_subpatch_plane,
9141 const MooseEnum & triangulation,
9142 const bool triangulate_triangles,
9143 const Mortar3DQuadraturePointMapping mortar_3d_qp_mapping)
9144{
9145 _has_mortar = true;
9146
9147 if (on_displaced)
9148 return _mortar_data->createMortarInterface(primary_secondary_boundary_pair,
9149 primary_secondary_subdomain_pair,
9151 on_displaced,
9152 periodic,
9153 debug,
9154 correct_edge_dropping,
9155 minimum_projection_angle,
9156 mortar_3d_subpatch_plane,
9157 triangulation,
9158 triangulate_triangles,
9159 mortar_3d_qp_mapping);
9160 else
9161 return _mortar_data->createMortarInterface(primary_secondary_boundary_pair,
9162 primary_secondary_subdomain_pair,
9163 *this,
9164 on_displaced,
9165 periodic,
9166 debug,
9167 correct_edge_dropping,
9168 minimum_projection_angle,
9169 mortar_3d_subpatch_plane,
9170 triangulation,
9171 triangulate_triangles,
9172 mortar_3d_qp_mapping);
9173}
9174
9177 const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
9178 const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
9179 bool on_displaced) const
9180{
9181 return _mortar_data->getMortarInterface(
9182 primary_secondary_boundary_pair, primary_secondary_subdomain_pair, on_displaced);
9183}
9184
9187 const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
9188 const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
9189 bool on_displaced)
9190{
9191 return _mortar_data->getMortarInterface(
9192 primary_secondary_boundary_pair, primary_secondary_subdomain_pair, on_displaced);
9193}
9194
9195void
9197{
9198 if (_displaced_problem) // Only need to do this if things are moving...
9199 {
9200 TIME_SECTION("possiblyRebuildGeomSearchPatches", 5, "Rebuilding Geometric Search Patches");
9201
9202 switch (_mesh.getPatchUpdateStrategy())
9203 {
9204 case Moose::Never:
9205 break;
9206 case Moose::Iteration:
9207 // Update the list of ghosted elements at the start of the time step
9210
9211 _displaced_problem->geomSearchData().updateGhostedElems();
9213
9214 // The commands below ensure that the sparsity of the Jacobian matrix is
9215 // augmented at the start of the time step using neighbor nodes from the end
9216 // of the previous time step.
9217
9219
9220 // This is needed to reinitialize PETSc output
9222
9223 break;
9224
9225 case Moose::Auto:
9226 {
9227 Real max = _displaced_problem->geomSearchData().maxPatchPercentage();
9228 _communicator.max(max);
9229
9230 // If we haven't moved very far through the patch
9231 if (max < 0.4)
9232 break;
9233 }
9234 libmesh_fallthrough();
9235
9236 // Let this fall through if things do need to be updated...
9237 case Moose::Always:
9238 // Flush output here to see the message before the reinitialization, which could take a
9239 // while
9240 _console << "\n\nUpdating geometric search patches\n" << std::endl;
9241
9244
9245 _displaced_problem->geomSearchData().clearNearestNodeLocators();
9247
9249
9250 // This is needed to reinitialize PETSc output
9252 }
9253 }
9254}
9255
9256#ifdef LIBMESH_ENABLE_AMR
9257void
9259{
9260 unsigned int n = adaptivity().getInitialSteps();
9262 if (n)
9263 {
9264 if (!_mesh.interiorLowerDBlocks().empty() || !_mesh.boundaryLowerDBlocks().empty())
9265 mooseError("HFEM does not support mesh adaptivity currently.");
9266
9267 TIME_SECTION("initialAdaptMesh", 2, "Performing Initial Adaptivity");
9268
9269 for (unsigned int i = 0; i < n; i++)
9270 {
9273
9275 {
9277 /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
9278
9279 // reproject the initial condition
9281
9283 }
9284 else
9285 {
9286 _console << "Mesh unchanged, skipping remaining steps..." << std::endl;
9287 return;
9288 }
9289 }
9290 }
9291}
9292
9293bool
9295{
9296 // reset cycle counter
9298
9300 return false;
9301
9302 TIME_SECTION("adaptMesh", 3, "Adapting Mesh");
9303
9304 unsigned int cycles_per_step = _adaptivity.getCyclesPerStep();
9305
9306 bool mesh_changed = false;
9307
9308 for (unsigned int i = 0; i < cycles_per_step; ++i)
9309 {
9310 if (!_mesh.interiorLowerDBlocks().empty() || !_mesh.boundaryLowerDBlocks().empty())
9311 mooseError("HFEM does not support mesh adaptivity currently.");
9312
9313 // Markers were already computed once by Executioner
9314 if (_adaptivity.getRecomputeMarkersFlag() && i > 0)
9316
9317 bool mesh_changed_this_step;
9318 mesh_changed_this_step = _adaptivity.adaptMesh();
9319
9320 if (mesh_changed_this_step)
9321 {
9322 mesh_changed = true;
9323
9325 /*intermediate_change=*/true, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
9327 }
9328 else
9329 {
9330 // If the mesh didn't change, we still need to update the displaced mesh
9331 // to undo the undisplacement performed in Adaptivity::adaptMesh
9333 _displaced_problem->updateMesh();
9334
9335 _console << "Mesh unchanged, skipping remaining steps..." << std::endl;
9336 break;
9337 }
9338
9339 // Show adaptivity progress
9340 _console << std::flush;
9341 }
9342
9343 // We're done with all intermediate changes; now get systems ready
9344 // for real if necessary.
9345 if (mesh_changed)
9346 es().reinit_systems();
9347
9348 // Execute multi-apps that need to run after adaptivity, but before the next timestep.
9350
9351 return mesh_changed;
9352}
9353#endif // LIBMESH_ENABLE_AMR
9354
9355void
9356FEProblemBase::initXFEM(std::shared_ptr<XFEMInterface> xfem)
9357{
9358 _xfem = xfem;
9359 _xfem->setMesh(&_mesh);
9360 if (_displaced_mesh)
9361 _xfem->setDisplacedMesh(_displaced_mesh);
9362
9363 auto fill_data = [this](auto & storage)
9364 {
9365 std::vector<MaterialData *> data(numThreads());
9366 for (const auto tid : make_range(numThreads()))
9367 data[tid] = &storage.getMaterialData(tid);
9368 return data;
9369 };
9370 _xfem->setMaterialData(fill_data(_material_props));
9371 _xfem->setBoundaryMaterialData(fill_data(_bnd_material_props));
9372
9373 unsigned int n_threads = numThreads();
9374 for (unsigned int i = 0; i < n_threads; ++i)
9375 for (const auto nl_sys_num : index_range(_nl))
9376 {
9377 _assembly[i][nl_sys_num]->setXFEM(_xfem);
9379 _displaced_problem->assembly(i, nl_sys_num).setXFEM(_xfem);
9380 }
9381}
9382
9383bool
9385{
9386 TIME_SECTION("updateMeshXFEM", 5, "Updating XFEM");
9387
9388 bool updated = false;
9389 if (haveXFEM())
9390 {
9391 if (_xfem->updateHeal())
9392 // XFEM exodiff tests rely on a given numbering because they cannot use map = true due to
9393 // having coincident elements. While conceptually speaking we do not need to contract the
9394 // mesh, we need its call to renumber_nodes_and_elements in order to preserve these tests
9396 /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/false);
9397
9398 updated = _xfem->update(_time, _nl, *_aux);
9399 if (updated)
9400 {
9402 /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/false);
9403 _xfem->initSolution(_nl, *_aux);
9405 _console << "\nXFEM update complete: Mesh modified" << std::endl;
9406 }
9407 else
9408 _console << "\nXFEM update complete: Mesh not modified" << std::endl;
9409 }
9410 return updated;
9411}
9412
9413void
9414FEProblemBase::meshChanged(const bool intermediate_change,
9415 const bool contract_mesh,
9416 const bool clean_refinement_flags)
9417{
9418 TIME_SECTION("meshChanged", 3, "Handling Mesh Changes");
9419
9420 const bool should_contract = contract_mesh && allowMeshContractionAfterMeshChanged();
9421
9423
9426 _mesh.cacheChangedLists(); // Currently only used with adaptivity and stateful material
9427 // properties
9428
9429 // Clear these out because they corresponded to the old mesh
9430 _ghosted_elems.clear();
9432
9433 // The mesh changed. We notify the MooseMesh first, because
9434 // callbacks (e.g. for sparsity calculations) triggered by the
9435 // EquationSystems reinit may require up-to-date MooseMesh caches.
9437
9438 // If we're just going to alter the mesh again, all we need to
9439 // handle here is AMR and projections, not full system reinit
9440 if (intermediate_change)
9441 es().reinit_solutions();
9442 else
9443 es().reinit();
9444
9445 if (should_contract)
9446 // Once vectors are restricted, we can delete children of coarsened elements
9447 _mesh.getMesh().contract();
9448 if (clean_refinement_flags)
9449 {
9450 // Finally clear refinement flags so that if someone tries to project vectors again without
9451 // an intervening mesh refinement to clear flags they won't run into trouble
9453 refinement.clean_refinement_flags();
9454 }
9455
9456 if (!intermediate_change)
9457 {
9458 // Since the mesh has changed, we need to make sure that we update any of our
9459 // MOOSE-system specific data.
9460 for (auto & sys : _solver_systems)
9461 sys->reinit();
9462 _aux->reinit();
9463 }
9464
9465 // Updating MooseMesh first breaks other adaptivity code, unless we
9466 // then *again* update the MooseMesh caches. E.g. the definition of
9467 // "active" and "local" may have been *changed* by refinement and
9468 // repartitioning done in EquationSystems::reinit().
9470
9471 // If we have finite volume variables, we will need to recompute additional elemental/face
9472 // quantities
9475
9476 // Let the meshChangedInterface notify the mesh changed event before we update the active
9477 // semilocal nodes, because the set of ghosted elements may potentially be updated during a mesh
9478 // changed event.
9479 for (const auto & mci : _notify_when_mesh_changes)
9480 mci->meshChanged();
9481
9482 // Since the Mesh changed, update the PointLocator object used by DiracKernels.
9484
9485 // Need to redo ghosting
9487
9489 {
9490 // Mesh contraction is necessary when a displaced problem is used.
9492 mooseError("Disabling mesh contraction is not implemented when a displaced problem is used. "
9493 "Please contact a "
9494 "developer of this application to discuss the combination of these features.");
9495
9496 _displaced_problem->meshChanged(should_contract, clean_refinement_flags);
9498 }
9499
9501
9504
9505 // Just like we reinitialized our geometric search objects, we also need to reinitialize our
9506 // mortar meshes. Note that this needs to happen after DisplacedProblem::meshChanged because the
9507 // mortar mesh discretization will depend necessarily on the displaced mesh being re-displaced
9508 _mortar_data->meshChanged();
9509
9510 // Nonlinear systems hold the mortar mesh functors. The domains of definition of the mortar
9511 // functors might have changed when the mesh changed.
9512 for (auto & nl_sys : _nl)
9513 nl_sys->reinitMortarFunctors();
9514
9515 reinitBecauseOfGhostingOrNewGeomObjects(/*mortar_changed=*/true);
9516
9517 // We need to create new storage for newly active elements, and copy
9518 // stateful properties from the old elements.
9521 {
9522 if (doingPRefinement())
9524
9525 // Prolong properties onto newly refined elements' children
9526 {
9528 /* refine = */ true, *this, _material_props, _bnd_material_props, _assembly);
9529 const auto & range = *_mesh.refinedElementRange();
9530 Threads::parallel_reduce(range, pmp, numThreads());
9531
9532 // Concurrent erasure from the shared hash map is not safe while we are reading from it in
9533 // ProjectMaterialProperties, so we handle erasure here. Moreover, erasure based on key is
9534 // not thread safe in and of itself because it is a read-write operation. Note that we do not
9535 // do the erasure for p-refinement because the coarse level element is the same as our active
9536 // refined level element
9537 if (!doingPRefinement())
9538 for (const auto & elem : range)
9539 {
9543 }
9544 }
9545
9546 // Restrict properties onto newly coarsened elements
9547 {
9549 /* refine = */ false, *this, _material_props, _bnd_material_props, _assembly);
9550 const auto & range = *_mesh.coarsenedElementRange();
9551 Threads::parallel_reduce(range, pmp, numThreads());
9552 // Note that we do not do the erasure for p-refinement because the coarse level element is the
9553 // same as our active refined level element
9554 if (!doingPRefinement())
9555 for (const auto & elem : range)
9556 {
9557 auto && coarsened_children = _mesh.coarsenedElementChildren(elem);
9558 for (auto && child : coarsened_children)
9559 {
9563 }
9564 }
9565 }
9566 }
9567
9570
9571 _has_jacobian = false; // we have to recompute jacobian when mesh changed
9572
9573 // Now for backwards compatibility with user code that overrode the old no-arg meshChanged we must
9574 // call it here
9575 meshChanged();
9576}
9577
9578void
9583
9584void
9589
9590void
9592{
9593 for (const auto & mdi : _notify_when_mesh_displaces)
9594 mdi->meshDisplaced();
9595}
9596
9597void
9598FEProblemBase::initElementStatefulProps(const ConstElemRange & elem_range, const bool threaded)
9599{
9602 if (threaded)
9603 Threads::parallel_reduce(elem_range, cmt, numThreads());
9604 else
9605 cmt(elem_range, true);
9606
9607#ifdef MOOSE_KOKKOS_ENABLED
9610#endif
9611}
9612
9613void
9615{
9616 TIME_SECTION("checkProblemIntegrity", 5);
9617
9618 // Subdomains specified by the "Problem/block" parameter
9619 const auto & subdomain_names = getParam<std::vector<SubdomainName>>("block");
9620 auto mesh_subdomains_vec = MooseMeshUtils::getSubdomainIDs(_mesh, subdomain_names);
9621 std::set<SubdomainID> mesh_subdomains(mesh_subdomains_vec.begin(), mesh_subdomains_vec.end());
9622
9623 // Check kernel coverage of subdomains (blocks) in the mesh
9626 {
9627 std::set<SubdomainID> blocks;
9630 blocks = mesh_subdomains;
9632 {
9633 blocks = mesh_subdomains;
9634 for (const auto & subdomain_name : _kernel_coverage_blocks)
9635 {
9636 const auto id = _mesh.getSubdomainID(subdomain_name);
9637 if (id == Moose::INVALID_BLOCK_ID)
9638 paramError("kernel_coverage_block_list",
9639 "Subdomain \"",
9640 subdomain_name,
9641 "\" not found in mesh.");
9642 blocks.erase(id);
9643 }
9644 }
9646 for (const auto & subdomain_name : _kernel_coverage_blocks)
9647 {
9648 const auto id = _mesh.getSubdomainID(subdomain_name);
9649 if (id == Moose::INVALID_BLOCK_ID)
9650 paramError("kernel_coverage_block_list",
9651 "Subdomain \"",
9652 subdomain_name,
9653 "\" not found in mesh.");
9654 blocks.insert(id);
9655 }
9656 if (!blocks.empty())
9657 for (auto & nl : _nl)
9658 nl->checkKernelCoverage(blocks);
9659 }
9660
9661 // Check materials
9662 {
9663#ifdef LIBMESH_ENABLE_AMR
9664 if ((_adaptivity.isOn() || _num_grid_steps) &&
9667 {
9668 _console << "Using EXPERIMENTAL Stateful Material Property projection with Adaptivity!\n"
9669 << std::flush;
9670 }
9671#endif
9672
9673 std::set<SubdomainID> local_mesh_subs(mesh_subdomains);
9674
9677 {
9682 bool check_material_coverage = false;
9683 std::set<SubdomainID> ids = _all_materials.getActiveBlocks();
9684 for (const auto & id : ids)
9685 {
9686 local_mesh_subs.erase(id);
9687 check_material_coverage = true;
9688 }
9689
9690 // did the user limit the subdomains to be checked?
9692 {
9693 for (const auto & subdomain_name : _material_coverage_blocks)
9694 {
9695 const auto id = _mesh.getSubdomainID(subdomain_name);
9696 if (id == Moose::INVALID_BLOCK_ID)
9697 paramError("material_coverage_block_list",
9698 "Subdomain \"" + subdomain_name + "\" not found in mesh.");
9699 local_mesh_subs.erase(id);
9700 }
9701 }
9703 {
9704 std::set<SubdomainID> blocks(local_mesh_subs);
9705 for (const auto & subdomain_name : _material_coverage_blocks)
9706 {
9707 const auto id = _mesh.getSubdomainID(subdomain_name);
9708 if (id == Moose::INVALID_BLOCK_ID)
9709 paramError("material_coverage_block_list",
9710 "Subdomain \"" + subdomain_name + "\" not found in mesh.");
9711 blocks.erase(id);
9712 }
9713 for (const auto id : blocks)
9714 local_mesh_subs.erase(id);
9715 }
9716
9717 // also exclude mortar spaces from the material check
9718 auto && mortar_subdomain_ids = _mortar_data->getMortarSubdomainIDs();
9719 for (auto subdomain_id : mortar_subdomain_ids)
9720 local_mesh_subs.erase(subdomain_id);
9721
9722 // Check Material Coverage
9723 if (check_material_coverage && !local_mesh_subs.empty())
9724 {
9725 std::stringstream extra_subdomain_ids;
9727 std::copy(local_mesh_subs.begin(),
9728 local_mesh_subs.end(),
9729 std::ostream_iterator<unsigned int>(extra_subdomain_ids, " "));
9731 std::vector<SubdomainID> local_mesh_subs_vec(local_mesh_subs.begin(),
9732 local_mesh_subs.end());
9733
9734 mooseError("The following blocks from your input mesh do not contain an active material: " +
9735 extra_subdomain_ids.str() +
9736 "(names: " + Moose::stringify(_mesh.getSubdomainNames(local_mesh_subs_vec)) +
9737 ")\nWhen ANY mesh block contains a Material object, "
9738 "all blocks must contain a Material object.\n");
9739 }
9740 }
9741
9742 // Check material properties on blocks and boundaries
9745
9746 // Check that material properties exist when requested by other properties on a given block
9747 const auto & materials = _all_materials.getActiveObjects();
9748 for (const auto & material : materials)
9749 material->checkStatefulSanity();
9750
9751 // auto mats_to_check = _materials.getActiveBlockObjects();
9752 // const auto & discrete_materials = _discrete_materials.getActiveBlockObjects();
9753 // for (const auto & map_it : discrete_materials)
9754 // for (const auto & container_element : map_it.second)
9755 // mats_to_check[map_it.first].push_back(container_element);
9758 }
9759
9761
9763
9764 // Verify that we don't have any Element type/Coordinate Type conflicts
9766
9767 // Coordinate transforms are only intended for use with MultiApps at this time. If you are not
9768 // using multiapps but still require these, contact a moose developer
9770 !hasMultiApps())
9771 mooseError("Coordinate transformation parameters, listed below, are only to be used in the "
9772 "context of application to application field transfers at this time. The mesh is "
9773 "not modified by these parameters within an application.\n"
9774 "You should likely use a 'TransformGenerator' in the [Mesh] block to achieve the "
9775 "desired mesh modification.\n\n",
9777
9778 // If using displacements, verify that the displaced mesh update can move every mesh node
9780
9781 // Check for postprocessor names with same name as a scalar variable
9783}
9784
9785void
9787{
9788 if (!_displaced_problem)
9789 return;
9790
9791 // The displaced mesh update moves a node with the displacement degree of freedom on it, or,
9792 // for a Lagrange variable, with the nodal_soln of the element degrees of freedom. A node
9793 // with neither would keep its reference position.
9794 for (const auto & var_name : _displaced_problem->getDisplacementVarNames())
9795 {
9796 const auto & var = getVariable(
9798 const bool lagrange = var.feType().family == LAGRANGE;
9799 const auto sys_num = var.sys().number();
9800 const auto & dof_map_var = var.sys().dofMap().variable(var.number());
9801 bool has_nodes_without_dofs = false;
9802 bool has_first_order_prism21 = false;
9803 for (const auto & elem :
9805 {
9806 if (!dof_map_var.active_on_subdomain(elem->subdomain_id()))
9807 continue;
9808 // libMesh's nodal_soln for Lagrange variables below SECOND order does not compute the
9809 // interior node of a PRISM21 from the element degrees of freedom
9810 if (lagrange && var.order() < SECOND && elem->type() == PRISM21)
9811 has_first_order_prism21 = true;
9812 else if (!lagrange)
9813 for (const auto & node : elem->node_ref_range())
9814 if (!node.n_dofs(sys_num, var.number()))
9815 has_nodes_without_dofs = true;
9816 if (has_nodes_without_dofs || has_first_order_prism21)
9817 break;
9818 }
9819
9820 // We checked our local elements, so take the max over all processors.
9821 _mesh.comm().max(has_nodes_without_dofs);
9822 _mesh.comm().max(has_first_order_prism21);
9823 if (has_nodes_without_dofs)
9824 mooseError("The displacement variable '",
9825 var_name,
9826 "' has no degrees of freedom on some mesh nodes, so the displaced mesh cannot be "
9827 "updated at those nodes. Use a LAGRANGE displacement variable.");
9828 if (has_first_order_prism21)
9829 mooseError("The displacement variable '",
9830 var_name,
9831 "' must be at least SECOND order on PRISM21 elements.");
9832 }
9833}
9834
9835void
9837{
9838 // Check user_objects block coverage
9839 std::set<SubdomainID> mesh_subdomains = _mesh.meshSubdomains();
9840 std::set<SubdomainID> user_objects_blocks;
9841
9842 // gather names of all user_objects that were defined in the input file
9843 // and the blocks that they are defined on
9844 std::set<std::string> names;
9845
9846 std::vector<UserObjectBase *> objects;
9848
9849 for (const auto & obj : objects)
9850 names.insert(obj->name());
9851
9852 // See if all referenced blocks are covered
9853 std::set<SubdomainID> difference;
9854 std::set_difference(user_objects_blocks.begin(),
9855 user_objects_blocks.end(),
9856 mesh_subdomains.begin(),
9857 mesh_subdomains.end(),
9858 std::inserter(difference, difference.end()));
9859
9860 if (!difference.empty())
9861 {
9862 std::ostringstream oss;
9863 oss << "One or more UserObjects is referencing a nonexistent block:\n";
9864 for (const auto & id : difference)
9865 oss << id << "\n";
9866 mooseError(oss.str());
9867 }
9868}
9869
9870void
9872{
9873 std::vector<FVGradientMethod *> methods;
9874 theWarehouse().query().condition<AttribSystem>("FVGradientMethod").queryInto(methods);
9875 for (auto * method : methods)
9876 method->resolveGradientMethodDependencies(*this);
9877}
9878
9879void
9881 const std::map<SubdomainID, std::vector<std::shared_ptr<MaterialBase>>> & materials_map)
9882{
9883 for (const auto & it : materials_map)
9884 {
9886 std::set<std::string> block_depend_props, block_supplied_props;
9887
9888 for (const auto & mat1 : it.second)
9889 {
9890 auto & alldeps = mat1->getMatPropDependencies(); // includes requested stateful props
9891 for (auto & dep : alldeps)
9892 block_depend_props.insert(_material_prop_registry.getName(dep));
9893
9894 // See if any of the active materials supply this property
9895 for (const auto & mat2 : it.second)
9896 {
9897 const std::set<std::string> & supplied_props = mat2->MaterialBase::getSuppliedItems();
9898 block_supplied_props.insert(supplied_props.begin(), supplied_props.end());
9899 }
9900 }
9901
9902 // Add zero material properties specific to this block and unrestricted
9903 block_supplied_props.insert(_zero_block_material_props[it.first].begin(),
9904 _zero_block_material_props[it.first].end());
9905
9906 // Error check to make sure all properties consumed by materials are supplied on this block
9907 std::set<std::string> difference;
9908 std::set_difference(block_depend_props.begin(),
9909 block_depend_props.end(),
9910 block_supplied_props.begin(),
9911 block_supplied_props.end(),
9912 std::inserter(difference, difference.end()));
9913
9914 if (!difference.empty())
9915 {
9916 std::ostringstream oss;
9917 oss << "One or more Material Properties were not supplied on block ";
9918 const std::string & subdomain_name = _mesh.getSubdomainName(it.first);
9919 if (subdomain_name.length() > 0)
9920 oss << subdomain_name << " (" << it.first << ")";
9921 else
9922 oss << it.first;
9923 oss << ":\n";
9924 for (const auto & name : difference)
9925 oss << name << "\n";
9926 mooseError(oss.str());
9927 }
9928 }
9929
9930 // This loop checks that materials are not supplied by multiple Material objects
9931 for (const auto & it : materials_map)
9932 {
9933 const auto & materials = it.second;
9934 std::set<std::string> inner_supplied, outer_supplied;
9935
9936 for (const auto & outer_mat : materials)
9937 {
9938 // Storage for properties for this material (outer) and all other materials (inner)
9939 outer_supplied = outer_mat->getSuppliedItems();
9940 inner_supplied.clear();
9941
9942 // Property to material map for error reporting
9943 std::map<std::string, std::set<std::string>> prop_to_mat;
9944 for (const auto & name : outer_supplied)
9945 prop_to_mat[name].insert(outer_mat->name());
9946
9947 for (const auto & inner_mat : materials)
9948 {
9949 if (outer_mat == inner_mat)
9950 continue;
9951
9952 // Check whether these materials are an AD pair
9953 auto outer_mat_type = outer_mat->type();
9954 auto inner_mat_type = inner_mat->type();
9955 removeSubstring(outer_mat_type, "<RESIDUAL>");
9956 removeSubstring(outer_mat_type, "<JACOBIAN>");
9957 removeSubstring(inner_mat_type, "<RESIDUAL>");
9958 removeSubstring(inner_mat_type, "<JACOBIAN>");
9959 if (outer_mat_type == inner_mat_type && outer_mat_type != outer_mat->type() &&
9960 inner_mat_type != inner_mat->type())
9961 continue;
9962
9963 inner_supplied.insert(inner_mat->getSuppliedItems().begin(),
9964 inner_mat->getSuppliedItems().end());
9965
9966 for (const auto & inner_supplied_name : inner_supplied)
9967 prop_to_mat[inner_supplied_name].insert(inner_mat->name());
9968 }
9969
9970 // Test that a property isn't supplied on multiple blocks
9971 std::set<std::string> intersection;
9972 std::set_intersection(outer_supplied.begin(),
9973 outer_supplied.end(),
9974 inner_supplied.begin(),
9975 inner_supplied.end(),
9976 std::inserter(intersection, intersection.end()));
9977
9978 if (!intersection.empty())
9979 {
9980 std::ostringstream oss;
9981 oss << "The following material properties are declared on block " << it.first
9982 << " by multiple materials:\n";
9983 oss << ConsoleUtils::indent(2) << std::setw(30) << std::left << "Material Property"
9984 << "Material Objects\n";
9985 for (const auto & outer_name : intersection)
9986 {
9987 oss << ConsoleUtils::indent(2) << std::setw(30) << std::left << outer_name;
9988 for (const auto & inner_name : prop_to_mat[outer_name])
9989 oss << inner_name << " ";
9990 oss << '\n';
9991 }
9992
9993 mooseError(oss.str());
9994 break;
9995 }
9996 }
9997 }
9998}
9999
10000void
10005
10006void
10007FEProblemBase::setRestartFile(const std::string & file_name)
10008{
10009 if (_app.isRecovering())
10010 {
10011 mooseInfo("Restart file ", file_name, " is NOT being used since we are performing recovery.");
10012 }
10013 else
10014 {
10015 _app.setRestart(true);
10017 mooseInfo("Using ", file_name, " for restart.");
10018 }
10019}
10020
10021std::vector<VariableName>
10023{
10024 std::vector<VariableName> names;
10025
10026 for (auto & sys : _solver_systems)
10027 {
10028 const std::vector<VariableName> & var_names = sys->getVariableNames();
10029 names.insert(names.end(), var_names.begin(), var_names.end());
10030 }
10031
10032 const std::vector<VariableName> & aux_var_names = _aux->getVariableNames();
10033 names.insert(names.end(), aux_var_names.begin(), aux_var_names.end());
10034
10035 return names;
10036}
10037
10039FEProblemBase::solverParams(const unsigned int solver_sys_num)
10040{
10041 mooseAssert(solver_sys_num < numSolverSystems(),
10042 "Solver system number '" << solver_sys_num << "' is out of bounds. We have '"
10043 << numSolverSystems() << "' solver systems");
10044 return _solver_params[solver_sys_num];
10045}
10046
10047const SolverParams &
10048FEProblemBase::solverParams(const unsigned int solver_sys_num) const
10049{
10050 return const_cast<FEProblemBase *>(this)->solverParams(solver_sys_num);
10051}
10052
10053void
10054FEProblemBase::registerRandomInterface(RandomInterface & random_interface, const std::string & name)
10055{
10056 auto insert_pair = moose_try_emplace(
10057 _random_data_objects, name, std::make_unique<RandomData>(*this, random_interface));
10058
10059 auto random_data_ptr = insert_pair.first->second.get();
10060 random_interface.setRandomDataPointer(random_data_ptr);
10061}
10062
10063bool
10065{
10066 if (_bnd_mat_side_cache[tid].find(bnd_id) == _bnd_mat_side_cache[tid].end())
10067 {
10068 auto & bnd_mat_side_cache = _bnd_mat_side_cache[tid][bnd_id];
10069 bnd_mat_side_cache = false;
10070
10071 // Check systems
10072 if (_aux->needMaterialOnSide(bnd_id))
10073 {
10074 bnd_mat_side_cache = true;
10075 return true;
10076 }
10077 for (auto & nl : _nl)
10078 if (nl->needBoundaryMaterialOnSide(bnd_id, tid))
10079 {
10080 bnd_mat_side_cache = true;
10081 return true;
10082 }
10083
10084 // TODO: these objects should be checked for whether they actually consume materials
10085 // NOTE: InterfaceUO can use use boundary properties too
10086 if (theWarehouse()
10087 .query()
10088 .condition<AttribThread>(tid)
10089 .condition<AttribInterfaces>(Interfaces::SideUserObject | Interfaces::DomainUserObject |
10091 .condition<AttribBoundaries>(bnd_id)
10092 .count() > 0)
10093 {
10094 bnd_mat_side_cache = true;
10095 return true;
10096 }
10097 }
10098
10099 return _bnd_mat_side_cache[tid][bnd_id];
10100}
10101
10102bool
10104{
10105 if (_interface_mat_side_cache[tid].find(bnd_id) == _interface_mat_side_cache[tid].end())
10106 {
10107 auto & interface_mat_side_cache = _interface_mat_side_cache[tid][bnd_id];
10108 interface_mat_side_cache = false;
10109
10110 // Aux-system has not needed interface materials so far
10111 for (auto & nl : _nl)
10112 if (nl->needInterfaceMaterialOnSide(bnd_id, tid))
10113 {
10114 interface_mat_side_cache = true;
10115 return true;
10116 }
10117
10118 // TODO: these objects should be checked for whether they actually consume materials
10119 if (theWarehouse()
10120 .query()
10121 .condition<AttribThread>(tid)
10122 .condition<AttribInterfaces>(Interfaces::InterfaceUserObject |
10124 .condition<AttribBoundaries>(bnd_id)
10125 .count() > 0)
10126 {
10127 interface_mat_side_cache = true;
10128 return true;
10129 }
10130 else if (_interface_materials.hasActiveBoundaryObjects(bnd_id, tid))
10131 {
10132 interface_mat_side_cache = true;
10133 return true;
10134 }
10135 }
10136 return _interface_mat_side_cache[tid][bnd_id];
10137}
10138
10139bool
10141{
10142 if (_block_mat_side_cache[tid].find(subdomain_id) == _block_mat_side_cache[tid].end())
10143 {
10144 _block_mat_side_cache[tid][subdomain_id] = false;
10145
10146 for (auto & nl : _nl)
10147 if (nl->needInternalNeighborSideMaterial(subdomain_id, tid))
10148 {
10149 _block_mat_side_cache[tid][subdomain_id] = true;
10150 return true;
10151 }
10152
10153 // TODO: these objects should be checked for whether they actually consume materials
10154 if (theWarehouse()
10155 .query()
10156 .condition<AttribThread>(tid)
10157 .condition<AttribInterfaces>(Interfaces::InternalSideUserObject |
10159 .condition<AttribSubdomains>(subdomain_id)
10160 .count() > 0)
10161 {
10162 _block_mat_side_cache[tid][subdomain_id] = true;
10163 return true;
10164 }
10165 }
10166
10167 return _block_mat_side_cache[tid][subdomain_id];
10168}
10169
10170bool
10175
10176void
10178{
10180 mooseError("Previous nonlinear solution is required but not added through "
10181 "Problem/previous_nl_solution_required=true");
10182}
10183
10184void
10186 const unsigned int solver_sys_num)
10187{
10188 _previous_multiapp_fp_nl_solution_required[solver_sys_num] = needed;
10189}
10190
10191bool
10193 const unsigned int solver_sys_num) const
10194{
10195 return _previous_multiapp_fp_nl_solution_required[solver_sys_num];
10196}
10197
10198void
10203
10204bool
10209
10210void
10212 bool needed, const unsigned int solver_sys_num)
10213{
10214 _previous_multisystem_fp_nl_solution_required[solver_sys_num] = needed;
10215}
10216
10217bool
10219 const unsigned int solver_sys_num) const
10220{
10221 return _previous_multisystem_fp_nl_solution_required[solver_sys_num];
10222}
10223
10224void
10229
10230bool
10235
10236bool
10238{
10239 return _has_jacobian;
10240}
10241
10242bool
10244{
10245 return _const_jacobian;
10246}
10247
10248void
10249FEProblemBase::addOutput(const std::string & object_type,
10250 const std::string & object_name,
10251 InputParameters & parameters)
10252{
10253 parallel_object_only();
10254
10255 // Get a reference to the OutputWarehouse
10256 OutputWarehouse & output_warehouse = _app.getOutputWarehouse();
10257
10258 // Reject the reserved names for objects not built by MOOSE
10259 if (!parameters.get<bool>("_built_by_moose") && output_warehouse.isReservedName(object_name))
10260 mooseError("The name '", object_name, "' is a reserved name for output objects");
10261
10262 // Check that an object by the same name does not already exist; this must be done before the
10263 // object is created to avoid getting misleading errors from the Parser
10264 if (output_warehouse.hasOutput(object_name))
10265 mooseError("An output object named '", object_name, "' already exists");
10266
10267 // Add a pointer to the FEProblemBase class
10268 parameters.addPrivateParam<FEProblemBase *>("_fe_problem_base", this);
10269
10270 // --show-input should enable the display of the input file on the screen
10271 if (object_type == "Console" && _app.getParam<bool>("show_input") &&
10272 parameters.get<bool>("output_screen"))
10273 parameters.set<ExecFlagEnum>("execute_input_on") = EXEC_INITIAL;
10274
10275 // Record whether this object's own block set 'file_base' itself before a common 'file_base'
10276 // from the [Outputs] block, if any, is copied down onto it below -- that copy makes
10277 // 'file_base' look valid and user-set on this object even when only the common block set it
10278 // (see #4215), so this must be captured first.
10279 if (parameters.isParamDefined("_file_base_set_by_own_block"))
10280 parameters.set<bool>("_file_base_set_by_own_block") = parameters.isParamSetByUser("file_base");
10281
10282 // Apply only user-set parameters from the common [Outputs] block so that
10283 // each output type's own defaults are not overridden by common defaults.
10284 const InputParameters * common = output_warehouse.getCommonParameters();
10285 if (common)
10287
10288 // Set the correct value for the binary flag for XDA/XDR output
10289 if (object_type == "XDR")
10290 parameters.set<bool>("_binary") = true;
10291 else if (object_type == "XDA")
10292 parameters.set<bool>("_binary") = false;
10293
10294 // Adjust the checkpoint suffix if auto recovery was enabled
10295 if (object_name == "auto_recovery_checkpoint")
10296 parameters.set<std::string>("suffix") = "auto_recovery";
10297
10298 // Create the object and add it to the warehouse
10299 std::shared_ptr<Output> output = _factory.create<Output>(object_type, object_name, parameters);
10300 logAdd("Output", object_name, object_type, parameters);
10301 output_warehouse.addOutput(output);
10302}
10303
10304void
10305FEProblemBase::haveADObjects(const bool have_ad_objects)
10306{
10307 _have_ad_objects = have_ad_objects;
10309 _displaced_problem->SubProblem::haveADObjects(have_ad_objects);
10310}
10311
10312const SystemBase &
10313FEProblemBase::getSystemBase(const unsigned int sys_num) const
10314{
10315 if (sys_num < _solver_systems.size())
10316 return *_solver_systems[sys_num];
10317
10318 return *_aux;
10319}
10320
10321SystemBase &
10322FEProblemBase::getSystemBase(const std::string & sys_name)
10323{
10324 if (std::find(_solver_sys_names.begin(), _solver_sys_names.end(), sys_name) !=
10325 _solver_sys_names.end())
10326 return getSystemBase(solverSysNum(sys_name));
10327 else if (sys_name == "aux0")
10328 return *_aux;
10329 else
10330 mooseError("System '" + sys_name + "' was requested from problem but does not exist.");
10331}
10332
10333SystemBase &
10334FEProblemBase::getSystemBase(const unsigned int sys_num)
10335{
10336 if (sys_num < _solver_systems.size())
10337 return *_solver_systems[sys_num];
10338
10339 return *_aux;
10340}
10341
10342const SystemBase &
10343FEProblemBase::systemBaseNonlinear(const unsigned int sys_num) const
10344{
10345 mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
10346 return *_nl[sys_num];
10347}
10348
10349SystemBase &
10350FEProblemBase::systemBaseNonlinear(const unsigned int sys_num)
10351{
10352 mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
10353 return *_nl[sys_num];
10354}
10355
10356const SystemBase &
10357FEProblemBase::systemBaseLinear(const unsigned int sys_num) const
10358{
10359 mooseAssert(sys_num < _linear_systems.size(),
10360 "System number greater than the number of linear systems");
10361 return *_linear_systems[sys_num];
10362}
10363
10364SystemBase &
10365FEProblemBase::systemBaseLinear(const unsigned int sys_num)
10366{
10367 mooseAssert(sys_num < _linear_systems.size(),
10368 "System number greater than the number of linear systems");
10369 return *_linear_systems[sys_num];
10370}
10371
10372const SystemBase &
10373FEProblemBase::systemBaseSolver(const unsigned int sys_num) const
10374{
10375 mooseAssert(sys_num < _solver_systems.size(),
10376 "System number greater than the number of solver systems");
10377 return *_solver_systems[sys_num];
10378}
10379
10380SystemBase &
10381FEProblemBase::systemBaseSolver(const unsigned int sys_num)
10382{
10383 mooseAssert(sys_num < _solver_systems.size(),
10384 "System number greater than the number of solver systems");
10385 return *_solver_systems[sys_num];
10386}
10387
10388const SystemBase &
10390{
10391 return *_aux;
10392}
10393
10394SystemBase &
10396{
10397 return *_aux;
10398}
10399
10400void
10401FEProblemBase::computingNonlinearResid(bool computing_nonlinear_residual)
10402{
10403 parallel_object_only();
10404
10406 _displaced_problem->computingNonlinearResid(computing_nonlinear_residual);
10407 _computing_nonlinear_residual = computing_nonlinear_residual;
10408}
10409
10410void
10411FEProblemBase::setCurrentlyComputingResidual(bool currently_computing_residual)
10412{
10414 _displaced_problem->setCurrentlyComputingResidual(currently_computing_residual);
10415 _currently_computing_residual = currently_computing_residual;
10416}
10417
10418void
10420{
10421 // ResetDisplacedMeshThread::onNode looks up the reference mesh by ID, so we need to make sure
10422 // we undisplace before adapting the reference mesh
10424 _displaced_problem->undisplaceMesh();
10425
10429
10431 /*intermediate_change=*/false, /*contract_mesh=*/true, /*clean_refinement_flags=*/true);
10432}
10433
10434void
10435FEProblemBase::automaticScaling(bool automatic_scaling)
10436{
10438 _displaced_problem->automaticScaling(automatic_scaling);
10439
10440 SubProblem::automaticScaling(automatic_scaling);
10441}
10442
10443void
10445 unsigned int side,
10446 Real tolerance,
10447 const std::vector<Point> * const pts,
10448 const std::vector<Real> * const weights,
10449 const THREAD_ID tid)
10450{
10451 SubProblem::reinitElemFaceRef(elem, side, tolerance, pts, weights, tid);
10452
10454 _displaced_problem->reinitElemFaceRef(
10455 _displaced_mesh->elemPtr(elem->id()), side, tolerance, pts, weights, tid);
10456}
10457
10458void
10459FEProblemBase::reinitNeighborFaceRef(const Elem * neighbor_elem,
10460 unsigned int neighbor_side,
10461 Real tolerance,
10462 const std::vector<Point> * const pts,
10463 const std::vector<Real> * const weights,
10464 const THREAD_ID tid)
10465{
10466 SubProblem::reinitNeighborFaceRef(neighbor_elem, neighbor_side, tolerance, pts, weights, tid);
10467
10469 _displaced_problem->reinitNeighborFaceRef(
10470 _displaced_mesh->elemPtr(neighbor_elem->id()), neighbor_side, tolerance, pts, weights, tid);
10471}
10472
10473void
10475 const std::vector<Point> & pts,
10476 const THREAD_ID tid)
10477{
10478 SubProblem::reinitNeighborSurfaceElemRef(neighbor_elem, pts, tid);
10479
10481 _displaced_problem->reinitNeighborSurfaceElemRef(
10482 _displaced_mesh->elemPtr(neighbor_elem->id()), pts, tid);
10483}
10484
10485void
10487 const SubdomainID blk_id,
10488 std::vector<std::shared_ptr<MaterialBase>> & face_materials,
10489 std::vector<std::shared_ptr<MaterialBase>> & neighbor_materials,
10490 std::set<MooseVariableFieldBase *> & variables,
10491 const THREAD_ID tid)
10492{
10493 if (_materials[Moose::FACE_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
10494 {
10495 auto & this_face_mats =
10497 for (std::shared_ptr<MaterialBase> face_mat : this_face_mats)
10498 if (face_mat->ghostable())
10499 {
10500 face_materials.push_back(face_mat);
10501 auto & var_deps = face_mat->getMooseVariableDependencies();
10502 for (auto * var : var_deps)
10503 {
10504 if (!var->isFV())
10505 mooseError(
10506 "Ghostable materials should only have finite volume variables coupled into them.");
10507 else if (face_mat->hasStatefulProperties())
10508 mooseError("Finite volume materials do not currently support stateful properties.");
10509 variables.insert(var);
10510 }
10511 }
10512 }
10513
10514 if (_materials[Moose::NEIGHBOR_MATERIAL_DATA].hasActiveBlockObjects(blk_id, tid))
10515 {
10516 auto & this_neighbor_mats =
10518 for (std::shared_ptr<MaterialBase> neighbor_mat : this_neighbor_mats)
10519 if (neighbor_mat->ghostable())
10520 {
10521 neighbor_materials.push_back(neighbor_mat);
10522#ifndef NDEBUG
10523 auto & var_deps = neighbor_mat->getMooseVariableDependencies();
10524 for (auto * var : var_deps)
10525 {
10526 if (!var->isFV())
10527 mooseError(
10528 "Ghostable materials should only have finite volume variables coupled into them.");
10529 else if (neighbor_mat->hasStatefulProperties())
10530 mooseError("Finite volume materials do not currently support stateful properties.");
10531 auto pr = variables.insert(var);
10532 mooseAssert(!pr.second,
10533 "We should not have inserted any new variables dependencies from our "
10534 "neighbor materials that didn't exist for our face materials");
10535 }
10536#endif
10537 }
10538 }
10539}
10540
10541void
10543 const unsigned int nqp,
10544 const THREAD_ID tid)
10545{
10546 getMaterialData(data_type, tid).resize(nqp);
10547}
10548
10549void
10550FEProblemBase::setNonlinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names)
10551{
10552 if (convergence_names.size() != numNonlinearSystems())
10553 paramError("nonlinear_convergence",
10554 "There must be one convergence object per nonlinear system");
10555
10556 _nonlinear_convergence_names = convergence_names;
10557
10558 for (const auto i : make_range(numNonlinearSystems()))
10559 _nl[i]->setConvergenceName(convergence_names[i]);
10560}
10561
10562void
10563FEProblemBase::setMultiAppFixedPointConvergenceName(const ConvergenceName & convergence_name)
10564{
10565 _multiapp_fixed_point_convergence_name = convergence_name;
10566}
10567
10568void
10569FEProblemBase::setSteadyStateConvergenceName(const ConvergenceName & convergence_name)
10570{
10571 _steady_state_convergence_name = convergence_name;
10572}
10573
10574const std::vector<ConvergenceName> &
10576{
10579 mooseError("The nonlinear system convergence name(s) have not been set.");
10580}
10581
10582bool
10584{
10585 // If false,this means we have not set one, not that we are querying this too early
10586 // TODO: once there is a default linear CV object, error on the 'not set' case
10587 return _linear_convergence_names.has_value();
10588}
10589
10590void
10591FEProblemBase::setLinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names)
10592{
10593 if (convergence_names.size() != numLinearSystems())
10594 paramError("linear_convergence", "There must be one convergence object per linear system");
10595 _linear_convergence_names = convergence_names;
10596}
10597
10598const std::vector<ConvergenceName> &
10600{
10603 mooseError("The linear convergence name(s) have not been set.");
10604}
10605
10606const ConvergenceName &
10608{
10611 else
10612 mooseError("The fixed point convergence name has not been set.");
10613}
10614
10615const ConvergenceName &
10617{
10619 return _steady_state_convergence_name.value();
10620 else
10621 mooseError("The steady convergence name has not been set.");
10622}
10623
10624void
10626{
10628 // We need to setup all the nonlinear systems other than our current one which actually called
10629 // this method (so we have to make sure we don't go in a circle)
10630 for (const auto i : make_range(numNonlinearSystems()))
10631 if (i != currentNlSysNum())
10632 _nl[i]->residualSetup();
10633 // We don't setup the aux sys because that's been done elsewhere
10635 _displaced_problem->residualSetup();
10636}
10637
10638void
10640{
10642 // We need to setup all the nonlinear systems other than our current one which actually called
10643 // this method (so we have to make sure we don't go in a circle)
10644 for (const auto i : make_range(numNonlinearSystems()))
10645 if (i != currentNlSysNum())
10646 _nl[i]->jacobianSetup();
10647 // We don't setup the aux sys because that's been done elsewhere
10649 _displaced_problem->jacobianSetup();
10650}
10651
10654{
10655 return mesh().coordTransform();
10656}
10657
10658unsigned int
10660{
10661 // If we don't have nonlinear systems this should be an invalid number
10662 unsigned int current_nl_sys_num = libMesh::invalid_uint;
10663 if (_nl.size())
10664 current_nl_sys_num = currentNonlinearSystem().number();
10665
10666 return current_nl_sys_num;
10667}
10668
10669unsigned int
10671{
10672 // If we don't have linear systems this should be an invalid number
10673 unsigned int current_linear_sys_num = libMesh::invalid_uint;
10674 if (_linear_systems.size())
10675 current_linear_sys_num = currentLinearSystem().number();
10676
10677 return current_linear_sys_num;
10678}
10679
10680bool
10682{
10683 // For now, only support printing from thread 0
10684 if (tid != 0)
10685 return false;
10686
10689 return true;
10690 else
10691 return false;
10692}
10693
10694std::vector<MortarUserObject *>
10696 const BoundaryID secondary_boundary_id,
10697 const bool displaced,
10698 const std::vector<MortarUserObject *> & mortar_uo_superset)
10699{
10700 std::vector<MortarUserObject *> mortar_uos;
10701 auto * const subproblem =
10702 displaced ? cast_ptr<SubProblem *>(_displaced_problem.get()) : cast_ptr<SubProblem *>(this);
10703 for (auto * const obj : mortar_uo_superset)
10704 if (obj->onInterface(primary_boundary_id, secondary_boundary_id) &&
10705 (&obj->getSubProblem() == subproblem))
10706 mortar_uos.push_back(obj);
10707
10708 return mortar_uos;
10709}
10710
10711std::vector<MortarUserObject *>
10713 const BoundaryID secondary_boundary_id,
10714 const bool displaced)
10715{
10716 std::vector<MortarUserObject *> mortar_uos;
10717 theWarehouse()
10718 .query()
10720 .queryInto(mortar_uos);
10721 return getMortarUserObjects(primary_boundary_id, secondary_boundary_id, displaced, mortar_uos);
10722}
10723
10724void
10726 const BoundaryID secondary_boundary_id,
10727 const bool displaced)
10728{
10729 const auto mortar_uos =
10730 getMortarUserObjects(primary_boundary_id, secondary_boundary_id, displaced);
10731 for (auto * const mortar_uo : mortar_uos)
10732 {
10733 mortar_uo->setNormals();
10734 mortar_uo->reinit();
10735 }
10736}
10737
10738void
10740{
10741 _verbose_setup = verbose ? "true" : "false";
10742 _verbose_multiapps = verbose;
10743 _verbose_restore = verbose;
10744}
10745
10746void
10747FEProblemBase::setCurrentLowerDElem(const Elem * const lower_d_elem, const THREAD_ID tid)
10748{
10749 SubProblem::setCurrentLowerDElem(lower_d_elem, tid);
10751 _displaced_problem->setCurrentLowerDElem(
10752 lower_d_elem ? _displaced_mesh->elemPtr(lower_d_elem->id()) : nullptr, tid);
10753}
10754
10755void
10757{
10760 _displaced_problem->setCurrentBoundaryID(bid, tid);
10761}
10762
10763void
10764FEProblemBase::setCurrentNonlinearSystem(const unsigned int nl_sys_num)
10765{
10766 mooseAssert(nl_sys_num < _nl.size(),
10767 "System number greater than the number of nonlinear systems");
10768 _current_nl_sys = _nl[nl_sys_num].get();
10770}
10771
10772void
10773FEProblemBase::setCurrentLinearSystem(const unsigned int sys_num)
10774{
10775 mooseAssert(sys_num < _linear_systems.size(),
10776 "System number greater than the number of linear systems");
10777 _current_linear_sys = _linear_systems[sys_num].get();
10779}
10780
10781void
10783{
10784 // When performing an adjoint solve in the optimization module, the current solver system is the
10785 // adjoint. However, the adjoint solve requires having accurate time derivative calculations for
10786 // the forward system. The cleanest way to handle such uses is just to compute the time
10787 // derivatives for all solver systems instead of trying to guess which ones we need and don't need
10788 for (auto & solver_sys : _solver_systems)
10789 solver_sys->compute(type);
10790
10791 _aux->compute(type);
10792}
10793
10794const ConstElemRange &
10802const ConstNodeRange &
10810const ConstBndNodeRange &
10818
10819void
10821{
10822 if (!range)
10823 {
10825 return;
10826 }
10827
10828 _current_algebraic_elem_range = std::make_unique<ConstElemRange>(*range);
10829}
10830void
10832{
10833 if (!range)
10834 {
10836 return;
10837 }
10838
10839 _current_algebraic_node_range = std::make_unique<ConstNodeRange>(*range);
10840}
10841void
10843{
10844 if (!range)
10845 {
10847 return;
10848 }
10849
10850 _current_algebraic_bnd_node_range = std::make_unique<ConstBndNodeRange>(*range);
10851}
10852
10853unsigned short
10858
10859std::string
10860FEProblemBase::solverTypeString(const unsigned int solver_sys_num)
10861{
10862 return Moose::stringify(solverParams(solver_sys_num)._type);
10863}
10864
10867{
10868 SolverParams solver_params;
10869 solver_params._type = Moose::SolveType::ST_LINEAR;
10871 return solver_params;
10872}
10873
10876{
10877 return _nonlocal_cm[i];
10878}
10879
10880bool
10885
10886const std::unordered_map<std::pair<BoundaryID, BoundaryID>, MortarInterfaceConfig> &
10888{
10889 return _mortar_data->getMortarInterfaces(on_displaced);
10890}
@ InternalSideUserObject
@ ThreadedGeneralUserObject
@ VectorPostprocessor
@ ShapeSideUserObject
@ InterfaceUserObject
@ ShapeElementUserObject
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
void boundaryIntegrityCheckError(const MooseObject &object, const std::set< MooseVariableFieldBase * > &variables, const BoundaryName &boundary_name)
Compose boundary restricted error message for the provided object, variables, and boundary_name if th...
StoredRange< std::vector< GeneralUserObject * >::iterator, GeneralUserObject * > GeneralUserObjectRange
void groupUserObjects(TheWarehouse &w, AuxiliarySystem &aux, const ExecFlagEnum &execute_flags, const std::vector< T * > &objs, const std::set< std::string > &ic_deps)
Threads::spin_mutex get_function_mutex
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363
unsigned int TagID
Definition MooseTypes.h:238
libMesh::TensorValue< ADReal > ADRealTensorValue
Definition MooseTypes.h:415
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
unsigned int THREAD_ID
Definition MooseTypes.h:237
std::vector< Real > VectorPostprocessorValue
Definition MooseTypes.h:231
ADRealVectorValue ADRealGradient
Definition MooseTypes.h:413
void removeSubstring(std::string &main, const std::string &sub)
const ExecFlagType EXEC_SUBDOMAIN
Definition Moose.C:53
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition Moose.C:38
const ExecFlagType EXEC_SAME_AS_MULTIAPP
Definition Moose.C:56
const ExecFlagType EXEC_POSTCHECK
Definition Moose.C:36
const ExecFlagType EXEC_ALWAYS
Definition Moose.C:54
const ExecFlagType EXEC_POST_ADAPTIVITY
Definition Moose.C:61
std::pair< typename M::iterator, bool > moose_try_emplace(M &m, const typename M::key_type &k, Args &&... args)
Function to mirror the behavior of the C++17 std::map::try_emplace() method (no hint).
Definition Moose.h:103
const ExecFlagType EXEC_INITIAL
Definition Moose.C:31
const ExecFlagType EXEC_LINEAR
Definition Moose.C:32
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:34
const ExecFlagType EXEC_NONE
Definition Moose.C:30
const ExecFlagType EXEC_PRE_DISPLACE
Definition Moose.C:55
unsigned int count
Definition MortarUtils.C:53
LocalRankConfig rankConfig(processor_id_type rank, processor_id_type nprocs, dof_id_type napps, processor_id_type min_app_procs, processor_id_type max_app_procs, bool batch_mode=false)
Returns app partitioning information relevant to the given rank for a multiapp scenario with the give...
Definition MultiApp.C:1369
std::shared_ptr< DisplacedProblem > displaced_problem
for(PetscInt i=0;i< nvars;++i)
char ** vars
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
char ** blocks
void extraSendList(std::vector< dof_id_type > &send_list, void *context)
///< Type of coordinate system
Definition SystemBase.C:38
void extraSparsity(libMesh::SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *context)
Free function used for a libMesh callback.
Definition SystemBase.C:46
unsigned int n_vars
void ErrorVector unsigned int
unsigned int getCyclesPerStep() const
Pull out the number of cycles_per_step previously set through the AdaptivityAction.
Definition Adaptivity.h:126
bool initialAdaptMesh()
Used during initial adaptivity.
Definition Adaptivity.C:295
void uniformRefineWithProjection()
Performs uniform refinement on the meshes in the current object.
Definition Adaptivity.C:328
static void uniformRefine(MooseMesh *mesh, unsigned int level=libMesh::invalid_uint)
Performs uniform refinement of the passed Mesh object.
Definition Adaptivity.C:301
bool getRecomputeMarkersFlag() const
Pull out the _recompute_markers_during_cycles flag previously set through the AdaptivityAction.
Definition Adaptivity.h:139
bool adaptMesh(std::string marker_name=std::string())
Adapts the mesh based on the error estimator used.
Definition Adaptivity.C:145
bool isAdaptivityDue()
Query if an adaptivity step should be performed at the current time / time step.
Definition Adaptivity.C:428
bool isOn()
Is adaptivity on?
Definition Adaptivity.h:193
void updateErrorVectors()
Update the ErrorVectors that have been requested through calls to getErrorVector().
Definition Adaptivity.C:407
unsigned int getInitialSteps() const
Pull out the number of initial steps previously set by calling init()
Definition Adaptivity.h:112
Key structure for APIs manipulating global vectors/matrices.
Definition Assembly.h:847
void prepareScalar()
Definition Assembly.C:3054
AttribBoundaries tracks all boundary IDs associated with an object.
Definition Attributes.h:223
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:429
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:398
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition Attributes.h:379
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
void copyValuesBack()
Copies current chain control data values into old values.
Thread to compute threaded general user objects.
Class for threaded computation of UserObjects.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Base class for convergence criteria.
Definition Convergence.h:26
bool hasWritableCoupledVariables() const
Checks whether the object has any writable coupled variables.
Definition Coupleable.h:142
Class that represents the dependecy as a graph.
void addItem(const T &value)
Add an independent item to the set.
const std::vector< T > & getSortedValues()
This function also returns dependency resolved values but with a simpler single vector interface.
void addEdge(const T &a, const T &b)
Add an edge between nodes 'a' and 'b'.
void clearPoints()
Remove all of the current points and elements.
std::set< const Elem * > & getElements()
Returns a writeable reference to the _elements container.
MultiPointMap & getPoints()
Returns a writeable reference to the _points container.
void updatePointLocator(const MooseMesh &mesh)
Called during FEProblemBase::meshChanged() to update the PointLocator object used by the DiracKernels...
All Distributions should inherit from this class.
A MultiMooseEnum object to hold "execute_on" flags.
A class for storing MooseObjects based on execution flag.
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
void setup(const ExecFlagType &exec_flag, THREAD_ID tid=0) const
virtual void preProblemInit()
Perform initializations during executing actions right before init_problem task.
Definition Executioner.h:57
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void addJacobianScalar(const THREAD_ID tid=0)
virtual bool reinitDirac(const Elem *elem, const THREAD_ID tid) override
Returns true if the Problem has Dirac kernels it needs to compute on elem.
virtual void addJacobianLowerD(const THREAD_ID tid) override
const FVInterpolationMethod & getFVInterpolationMethod(const InterpolationMethodName &name, const THREAD_ID tid=0) const
Retrieve an FV interpolation method.
virtual void addKokkosAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
MaterialData & getMaterialData(Moose::MaterialDataType type, const THREAD_ID tid=0, const MooseObject *object=nullptr) const
std::unique_ptr< libMesh::ConstElemRange > _nl_evaluable_local_elem_range
bool _previous_nl_solution_required
Indicates we need to save the previous NL iteration variable values.
virtual void addKokkosBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters)
std::shared_ptr< AuxiliarySystem > _aux
The auxiliary system.
std::vector< SubdomainName > _material_coverage_blocks
bool hasLinearConvergenceObjects() const
Whether we have linear convergence objects.
bool hasPostprocessor(const std::string &name) const
Deprecated.
std::vector< VariablePhiSecond > _second_phi_zero
void appendConstantModes(const std::vector< VariableName > &vars, const std::string &prefix, std::vector< NumericVector< libMesh::Number > * > &sp)
Append one mode per variable of vars in the current nonlinear system to sp.
unsigned int subspaceDim(const std::string &prefix) const
Dimension of the subspace spanned by vectors with a given prefix.
MooseObjectWarehouse< IntegratedBCBase > _nonlocal_integrated_bcs
nonlocal integrated_bcs
virtual void clearDiracInfo() override
Gets called before Dirac Kernels are asked to add the points they are supposed to be evaluated in.
MaterialWarehouse _materials
virtual void addJacobianBlockTags(libMesh::SparseMatrix< libMesh::Number > &jacobian, unsigned int ivar, unsigned int jvar, const DofMap &dof_map, std::vector< dof_id_type > &dof_indices, const std::set< TagID > &tags, const THREAD_ID tid)
virtual void reinitNeighborSurfaceElemRef(const Elem *neighbor_elem, const std::vector< Point > &pts, const THREAD_ID tid=0) override
reinitialize FE objects on a given neighbor element that is itself the face, i.e.
LinearSystem * _current_linear_sys
The current linear system that we are solving.
std::set< TagID > _fe_vector_tags
std::vector< VariablePhiGradient > _grad_phi_zero
virtual void computeJacobian(const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian, const unsigned int nl_sys_num)
Form a Jacobian matrix with the default tag (system).
virtual void computeNearNullSpace(libMesh::NonlinearImplicitSystem &sys, std::vector< NumericVector< libMesh::Number > * > &sp)
ExecuteMooseObjectWarehouse< Transfer > _between_multi_app_transfers
Transfers executed just before MultiApps to transfer data between them.
bool _trust_user_coupling_matrix
Whether to trust the user coupling matrix no matter what.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid) override
virtual void init() override
virtual const std::vector< std::shared_ptr< Convergence > > & getConvergenceObjects(const THREAD_ID tid=0) const
Gets the Convergence objects.
SolverSystem * _current_solver_sys
The current solver system.
void needSolutionState(unsigned int oldest_needed, Moose::SolutionIterationType iteration_type)
Declare that we need up to old (1) or older (2) solution states for a given type of iteration.
virtual void cacheResidual(const THREAD_ID tid) override
void checkDependMaterialsHelper(const std::map< SubdomainID, std::vector< std::shared_ptr< MaterialBase > > > &materials_map)
Helper method for checking Material object dependency.
virtual void addMaterialHelper(std::vector< MaterialWarehouse * > warehouse, const std::string &material_name, const std::string &name, InputParameters &parameters)
const std::vector< ConvergenceName > & getNonlinearConvergenceNames() const
Gets the nonlinear system convergence object name(s).
void resizeMaterialData(Moose::MaterialDataType data_type, unsigned int nqp, const THREAD_ID tid)
Resize material data.
bool needsPreviousMultiAppFixedPointIterationAuxiliary() const
Check to see whether we need to compute the variable values of the previous multiapp fixed point iter...
virtual void checkProblemIntegrity()
Method called to perform a series of sanity checks before a simulation is run.
void setCouplingMatrix(std::unique_ptr< libMesh::CouplingMatrix > cm, const unsigned int nl_sys_num)
Set custom coupling matrix.
unsigned int getMaxQps() const
void setLinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the linear convergence object name(s) if there is one.
std::string _exception_message
The error message to go with an exception.
std::vector< MooseArray< ADRealVectorValue > > _ad_grad_zero
bool hasJacobian() const
Returns _has_jacobian.
virtual void onTimestepEnd() override
const bool _skip_nl_system_check
std::vector< std::unordered_map< SubdomainID, bool > > _block_mat_side_cache
Cache for calculating materials on side.
std::vector< SolverParams > _solver_params
virtual NonlinearSystem & getNonlinearSystem(const unsigned int sys_num)
ScalarInitialConditionWarehouse _scalar_ics
virtual void addJacobianNeighbor(const THREAD_ID tid) override
virtual ArrayMooseVariable & getArrayVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested ArrayMooseVariable which may be in any system.
void createTagVectors()
Create extra tagged vectors and matrices.
bool hasKokkosUserObject(const std::string &name) const
Check if there if a Kokkos user object of given name.
virtual void addResidualLower(const THREAD_ID tid) override
virtual void lineSearch()
execute MOOSE line search
bool _verbose_multiapps
Whether or not to be verbose with multiapps.
TheWarehouse::Query getUOQuery(const std::string &system, const ExecFlagType &type, const Moose::AuxGroup &group) const
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid) override
virtual void addPredictor(const std::string &type, const std::string &name, InputParameters &parameters)
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
void clearCurrentJacobianMatrixTags()
Clear the current Jacobian matrix tag data structure ... if someone creates it.
virtual void addDistribution(const std::string &type, const std::string &name, InputParameters &parameters)
The following functions will enable MOOSE to have the capability to import distributions.
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
const AutomaticMortarGeneration & getMortarInterface(const std::pair< BoundaryID, BoundaryID > &primary_secondary_boundary_pair, const std::pair< SubdomainID, SubdomainID > &primary_secondary_subdomain_pair, bool on_displaced) const
Return the undisplaced or displaced mortar generation object associated with the provided boundaries ...
const bool & _solve
Whether or not to actually solve the nonlinear system.
bool _parallel_barrier_messaging
Whether or not information about how many transfers have completed is printed.
virtual bool hasScalarVariable(const std::string &var_name) const override
Returns a Boolean indicating whether any system contains a variable with the name provided.
void skipNextForwardSolutionCopyToOld()
Prevents the copy of the solution vector to the old solution vector in each system.
MaterialWarehouse _interface_materials
void addObjectParamsHelper(InputParameters &params, const std::string &object_name, const std::string &var_param_name="variable")
Helper for setting the "_subproblem" and "_sys" parameters in addObject() and in addUserObject().
const Postprocessor & getPostprocessorObjectByName(const PostprocessorName &object_name, const THREAD_ID tid=0) const
Return the Postprocessor object registered under the supplied object name.
void reportMooseObjectDependency(MooseObject *a, MooseObject *b)
Register a MOOSE object dependency so we can either order operations properly or report when we canno...
std::unique_ptr< MortarInterfaceWarehouse > _mortar_data
void customSetup(const ExecFlagType &exec_type) override
virtual void computeResidualTags(const std::set< TagID > &tags)
Form multiple residual vectors and each is associated with one tag.
virtual void reinitElemFaceRef(const Elem *elem, unsigned int side, Real tolerance, const std::vector< Point > *const pts, const std::vector< Real > *const weights=nullptr, const THREAD_ID tid=0) override
reinitialize FE objects on a given element on a given side at a given set of reference points and the...
void checkDisplacementNodes()
Verify that the displaced mesh update can move every node of the elements the displacement variables ...
bool _has_dampers
Whether or not this system has any Dampers associated with it.
virtual void computeUserObjects(const ExecFlagType &type, const Moose::AuxGroup &group)
Call compute methods on UserObjects.
std::shared_ptr< MultiApp > getMultiApp(const std::string &multi_app_name) const
Get a MultiApp object by name.
bool _checking_uo_aux_state
Flag used to indicate whether we are doing the uo/aux state check in execute.
bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, const THREAD_ID tid)
virtual MooseVariable & getStandardVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested MooseVariable which may be in any system.
virtual std::vector< std::shared_ptr< UserObject > > addUserObject(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
virtual bool hasDistribution(const std::string &name) const
void restoreGeometricSearchState()
Restore geometric search state captured by the most recent backupGeometricSearchState().
virtual std::size_t numLinearSystems() const override
void createTagMatrices(CreateTaggedMatrixKey)
bool hasFVInterpolationMethod(const InterpolationMethodName &name) const
Check if an FV interpolation method with a given name exists.
virtual bool haveFV() const override
returns true if this problem includes/needs finite volume functionality.
Moose::Kokkos::MaterialPropertyStorage & _kokkos_neighbor_material_props
libMesh::Order getMaxScalarOrder() const
void reinitMaterialsFace(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on element faces
virtual void addSampler(const std::string &type, const std::string &name, InputParameters &parameters)
The following functions will enable MOOSE to have the capability to import Samplers.
void notifyWhenMeshDisplaces(MeshDisplacedInterface *mdi)
Register an object that derives from MeshDisplacedInterface to be notified when the displaced mesh ge...
void jacobianSetup() override
virtual bool updateMeshXFEM()
Update the mesh due to changing XFEM cuts.
virtual void prepareFaceShapes(unsigned int var, const THREAD_ID tid) override
virtual void resetState()
Reset state of this object in preparation for the next evaluation.
virtual unsigned int currentLinearSysNum() const override
bool areCoupled(const unsigned int ivar, const unsigned int jvar, const unsigned int nl_sys_num) const
virtual void addResidual(const THREAD_ID tid) override
virtual void addInterfaceMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the scalar variable reference from whichever system contains it.
MooseObjectWarehouse< KernelBase > _nonlocal_kernels
nonlocal kernels
ReporterData _reporter_data
const ConvergenceName & getSteadyStateConvergenceName() const
Gets the steady-state detection convergence object name.
std::vector< VariableGradient > _grad_zero
virtual void addConvergence(const std::string &type, const std::string &name, InputParameters &parameters)
Adds a Convergence object.
virtual bool allowMeshContractionAfterMeshChanged() const
Whether meshChanged() should allow the mesh to be contracted (deletes children of coarsened elements ...
virtual libMesh::EquationSystems & es() override
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
void setCurrentAlgebraicNodeRange(libMesh::ConstNodeRange *range)
ExecuteMooseObjectWarehouse< MultiApp > _multi_apps
MultiApp Warehouse.
std::vector< bool > _previous_multisystem_fp_nl_solution_required
Indicates we need to save the previous multi-system fixed-point iteration solver variable values.
const FVFaceInterpolationMethod & getFVFaceInterpolationMethod(const InterpolationMethodName &name, const THREAD_ID tid=0) const
Retrieve a scalar face interpolation method.
virtual void setCurrentBoundaryID(BoundaryID bid, const THREAD_ID tid) override
sets the current boundary ID in assembly
virtual void addResidualScalar(const THREAD_ID tid=0)
void projectInitialConditionOnCustomRange(libMesh::ConstElemRange &elem_range, ConstBndNodeRange &bnd_node_range, const std::optional< std::set< VariableName > > &target_vars=std::nullopt)
Project initial conditions for custom elem_range and bnd_node_range This is needed when elements/boun...
const bool _boundary_restricted_node_integrity_check
whether to perform checking of boundary restricted nodal object variable dependencies,...
virtual void addHDGKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
std::shared_ptr< LineSearch > _line_search
virtual void prepareShapes(unsigned int var, const THREAD_ID tid) override
std::vector< VariableSecond > _second_zero
virtual void addCachedResidual(const THREAD_ID tid) override
AuxiliarySystem & getAuxiliarySystem()
MaterialPropertyStorage & _material_props
void trustUserCouplingMatrix()
Whether to trust the user coupling matrix even if we want to do things like be paranoid and create a ...
void joinAndFinalize(TheWarehouse::Query query, bool isgen=false)
void setAxisymmetricCoordAxis(const MooseEnum &rz_coord_axis)
virtual void reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering=false) override
fills the VariableValue arrays for scalar variables from the solution vector
virtual void neighborSubdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
virtual const libMesh::CouplingMatrix & nonlocalCouplingMatrix(const unsigned i) const override
const RestartableEquationSystems & getRestartableEquationSystems() const
Get the RestartableEquationSystems object.
void setNonlinearConvergenceNames(const std::vector< ConvergenceName > &convergence_names)
Sets the nonlinear convergence object name(s) if there is one.
bool haveXFEM()
Find out whether the current analysis is using XFEM.
virtual std::size_t numSolverSystems() const override
bool needsPreviousNewtonIteration() const
Check to see whether we need to compute the variable values of the previous Newton iterate.
bool _reinit_displaced_neighbor
Whether to call DisplacedProblem::reinitNeighbor when this->reinitNeighbor is called.
virtual void cacheJacobianNeighbor(const THREAD_ID tid) override
virtual void addResidualNeighbor(const THREAD_ID tid) override
virtual const SystemBase & systemBaseAuxiliary() const override
Return the auxiliary system object as a base class reference.
std::vector< libMesh::CouplingMatrix > _nonlocal_cm
nonlocal coupling matrix
unsigned int systemNumForVariable(const VariableName &variable_name) const
virtual void sizeZeroes(unsigned int size, const THREAD_ID tid)
MaterialPropertyStorage & _neighbor_material_props
virtual void addCachedJacobian(const THREAD_ID tid) override
virtual const SystemBase & systemBaseLinear(unsigned int sys_num) const override
Get a constant base class reference to a linear system.
virtual void addGhostedElem(dof_id_type elem_id) override
Will make sure that all dofs connected to elem_id are ghosted to this processor.
MooseMesh & _mesh
virtual void reinitOffDiagScalars(const THREAD_ID tid) override
virtual bool shouldUpdateSolution()
Check to see whether the problem should update the solution.
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & nonlocalCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
virtual void addTimeIntegrator(const std::string &type, const std::string &name, InputParameters &parameters)
virtual std::size_t numNonlinearSystems() const override
unsigned short getCurrentICState()
Retrieves the current initial condition state.
std::vector< std::shared_ptr< LinearSystem > > _linear_systems
The vector of linear systems.
ExecuteMooseObjectWarehouse< Transfer > _to_multi_app_transfers
Transfers executed just before MultiApps to transfer data to them.
std::optional< ConvergenceName > _multiapp_fixed_point_convergence_name
MultiApp fixed point convergence name.
void addAnyRedistributers()
void initElementStatefulProps(const libMesh::ConstElemRange &elem_range, const bool threaded)
Initialize stateful properties for elements in a specific elem_range This is needed when elements/bou...
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
ExecuteMooseObjectWarehouse< Transfer > _transfers
Normal Transfers.
virtual const std::vector< VectorTag > & currentResidualVectorTags() const override
Return the residual vector tags we are currently computing.
void setRestartFile(const std::string &file_name)
Communicate to the Resurector the name of the restart filer.
MooseVariableFieldBase & getActualFieldVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested MooseVariableField which may be in any system.
virtual void computeResidualInternal(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, const std::set< TagID > &tags)
Form a residual vector for a set of tags.
virtual void updateActiveObjects()
Update the active objects in the warehouses.
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual VectorMooseVariable & getVectorVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested VectorMooseVariable which may be in any system.
void computeSystems(const ExecFlagType &type)
Do generic system computations.
void incrementMultiAppTStep(ExecFlagType type)
Advance the MultiApps t_step (incrementStepOrReject) associated with the ExecFlagType.
virtual void computeLinearSystemSys(libMesh::LinearImplicitSystem &sys, libMesh::SparseMatrix< libMesh::Number > &system_matrix, NumericVector< libMesh::Number > &rhs, const bool compute_gradients=true)
Assemble both the right hand side and the system matrix of a given linear system.
std::unique_ptr< libMesh::ConstElemRange > _current_algebraic_elem_range
virtual void addElementalFieldVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
Add an elemental field variable for use in the adaptivity system.
virtual void clearActiveFEVariableCoupleableVectorTags(const THREAD_ID tid) override
void setCurrentAlgebraicElementRange(libMesh::ConstElemRange *range)
These functions allow setting custom ranges for the algebraic elements, nodes, and boundary nodes tha...
virtual void computeJacobianSys(libMesh::NonlinearImplicitSystem &sys, const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian)
Form a Jacobian matrix.
std::map< NonlinearSystemName, unsigned int > _nl_sys_name_to_num
Map from nonlinear system name to number.
bool _has_kokkos_objects
Whether we have any Kokkos objects.
std::vector< std::unique_ptr< libMesh::CouplingMatrix > > _cm
Coupling matrix for variables.
virtual void reinitElem(const Elem *elem, const THREAD_ID tid) override
virtual void cacheJacobian(const THREAD_ID tid) override
virtual void swapBackMaterialsFace(const THREAD_ID tid)
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
Get a read-only reference to the value associated with a Postprocessor that exists.
virtual void addJacobian(const THREAD_ID tid) override
std::vector< VectorVariableValue > _vector_zero
void checkNonlocalCoupling()
virtual void possiblyRebuildGeomSearchPatches()
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
Canonical method for adding a non-linear variable.
LinearSystem & currentLinearSystem()
Get a non-constant reference to the current linear system.
virtual void addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid=0)
ExecuteMooseObjectWarehouse< Control > _control_warehouse
The control logic warehouse.
virtual void addFunction(const std::string &type, const std::string &name, InputParameters &parameters)
void residualSetup() override
virtual void setActiveFEVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid) override
void setSteadyStateConvergenceName(const ConvergenceName &convergence_name)
Sets the steady-state detection convergence object name if there is one.
bool _preserve_matrix_sparsity_pattern
Whether to preserve the system matrix / Jacobian sparsity pattern, using 0-valued entries usually.
virtual Real computeDamping(const NumericVector< libMesh::Number > &soln, const NumericVector< libMesh::Number > &update)
virtual void addKokkosPostprocessor(const std::string &pp_name, const std::string &name, InputParameters &parameters)
virtual ~FEProblemBase()
virtual bool updateSolution(NumericVector< libMesh::Number > &vec_solution, NumericVector< libMesh::Number > &ghosted_solution)
Update the solution.
std::vector< VariablePhiValue > _phi_zero
bool acceptInvalidSolution() const
Whether or not to accept the solution based on its invalidity.
libMesh::Order _max_scalar_order
Maximum scalar variable order.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
CoverageCheckMode _kernel_coverage_check
Determines whether and which subdomains are to be checked to ensure that they have an active kernel.
std::set< TagID > _linear_vector_tags
Temporary storage for filtered vector tags for linear systems.
GeometricSearchData _geometric_search_data
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, const THREAD_ID tid) override
ExecFlagType _current_execute_on_flag
Current execute_on flag.
void setCoordSystem(const std::vector< SubdomainName > &blocks, const MultiMooseEnum &coord_sys)
ExecuteMooseObjectWarehouse< TransientMultiApp > _transient_multi_apps
Storage for TransientMultiApps (only needed for calling 'computeDT')
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
Return the complete warehouse for MultiAppTransfer object for the given direction.
Moose::Kokkos::MaterialPropertyStorage & _kokkos_bnd_material_props
void bumpVolumeQRuleOrder(libMesh::Order order, SubdomainID block)
Increases the element/volume quadrature order for the specified mesh block if and only if the current...
void clearCurrentResidualVectorTags()
Clear the current residual vector tag data structure.
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
void translateUserObjectExceptions(const std::function< void()> &work)
Execute work, user object computations local to this process, and register any exception it raises wi...
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
Compute an user object with the given name.
virtual void addFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
virtual void addTransfer(const std::string &transfer_name, const std::string &name, InputParameters &parameters)
Add a Transfer to the problem.
std::shared_ptr< MaterialBase > getMaterial(std::string name, Moose::MaterialDataType type, const THREAD_ID tid=0, bool no_warn=false)
Return a pointer to a MaterialBase object.
void checkUserObjects()
virtual void addFVGradientMethod(const std::string &method_type, const std::string &name, InputParameters &parameters)
Add an FV gradient method.
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
virtual void restoreOldSolutions()
Restore old solutions from the backup vectors and deallocate them.
std::map< std::string, unsigned int > _subspace_dim
Dimension of the subspace spanned by the vectors with a given prefix.
virtual void predictorCleanup(NumericVector< libMesh::Number > &ghosted_solution)
Perform cleanup tasks after application of predictor to solution vector.
virtual void addKokkosUserObject(const std::string &user_object_name, const std::string &name, InputParameters &parameters)
virtual void getDiracElements(std::set< const Elem * > &elems) override
Fills "elems" with the elements that should be looped over for Dirac Kernels.
bool _ignore_zeros_in_jacobian
Whether to ignore zeros in the Jacobian, thereby leading to a reduced sparsity pattern.
unsigned int _num_grid_steps
Number of steps in a grid sequence.
std::shared_ptr< XFEMInterface > _xfem
Pointer to XFEM controller.
void checkUserObjectNameCollision(const std::string &name, const std::string &type) const
Check for name collision between different user objects.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
void registerRandomInterface(RandomInterface &random_interface, const std::string &name)
virtual void addVectorPostprocessor(const std::string &pp_name, const std::string &name, InputParameters &parameters)
void reinitBecauseOfGhostingOrNewGeomObjects(bool mortar_changed=false)
Call when it is possible that the needs for ghosted elements has changed.
MooseObjectWarehouse< Indicator > _indicators
void setCoupling(Moose::CouplingType type)
Set the coupling between variables TODO: allow user-defined coupling.
std::map< SolverSystemName, unsigned int > _solver_sys_name_to_num
Map connecting solver system names with their respective systems.
void setAuxKernelParamsAndLog(const std::string &ak_name, const std::string &name, InputParameters &parameters, const std::string &base_name)
Set the subproblem and system parameters for auxiliary kernels and log their addition.
virtual void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters)
std::map< std::string, std::unique_ptr< RandomData > > _random_data_objects
A map of objects that consume random numbers.
void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true)
void parentOutputPositionChanged()
Calls parentOutputPositionChanged() on all sub apps.
bool hasSolverVariable(const std::string &var_name) const
virtual void newAssemblyArray(std::vector< std::shared_ptr< SolverSystem > > &solver_systems)
bool hasSolutionState(unsigned int state, Moose::SolutionIterationType iteration_type) const
Whether we need up to old (1) or older (2) solution states for a given type of iteration.
bool isSolverSystemNonlinear(const unsigned int sys_num)
Check if the solver system is nonlinear.
std::set< TagID > _fe_matrix_tags
FVGradientMethod & getFVGradientMethod(const GradientMethodName &name, const THREAD_ID tid=0)
Retrieve a writable FV gradient method owned by this problem.
std::vector< MeshDisplacedInterface * > _notify_when_mesh_displaces
Objects to be notified when the mesh displaces.
bool _has_nonlocal_coupling
Indicates if nonlocal coupling is required/exists.
virtual bool solverSystemConverged(const unsigned int solver_sys_num) override
bool hasFVGradientMethod(const GradientMethodName &name) const
Check if an FV gradient method with a given name exists.
virtual void addAuxScalarVariable(const std::string &var_name, libMesh::Order order, Real scale_factor=1., const std::set< SubdomainID > *const active_subdomains=NULL)
virtual void addJacobianNeighborLowerD(const THREAD_ID tid) override
bool needsPreviousMultiSystemFixedPointIterationAuxiliary() const
Check to see whether we need to compute the variable values of the previous multi-system fixed point ...
void getFVMatsAndDependencies(SubdomainID block_id, std::vector< std::shared_ptr< MaterialBase > > &face_materials, std::vector< std::shared_ptr< MaterialBase > > &neighbor_materials, std::set< MooseVariableFieldBase * > &variables, const THREAD_ID tid)
Get the materials and variables potentially needed for FV.
Restartable::ManagedValue< RestartableEquationSystems > _req
The EquationSystems object, wrapped for restart.
const bool _force_restart
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep.
virtual bool uDotDotRequested()
Get boolean flag to check whether solution second time derivative needs to be stored.
virtual void restoreSolutions()
virtual void solveLinearSystem(const unsigned int linear_sys_num, const Moose::PetscSupport::PetscOptions *po=nullptr)
Build and solve a linear system.
virtual void prepareAssembly(const THREAD_ID tid) override
virtual void addFVInterpolationMethod(const std::string &method_type, const std::string &name, InputParameters &parameters)
Add an FV interpolation method.
const bool _material_dependency_check
Determines whether a check to verify material dependencies on every subdomain.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
virtual void executeAllObjects(const ExecFlagType &exec_type)
void executeControls(const ExecFlagType &exec_type)
Performs setup and execute calls for Control objects.
virtual void postExecute()
Method called at the end of the simulation.
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
void setVerboseProblem(bool verbose)
Make the problem be verbose.
const bool _regard_general_exceptions_as_errors
If we catch an exception during residual/Jacobian evaluaton for which we don't have specific handling...
std::vector< std::shared_ptr< Transfer > > getTransfers(ExecFlagType type, Transfer::DIRECTION direction) const
Get Transfers by ExecFlagType and direction.
bool hasMultiApps() const
Returns whether or not the current simulation has any multiapps.
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
void addOutput(const std::string &, const std::string &, InputParameters &)
Adds an Output object.
virtual void addKokkosLinearFVBC(const std::string &bc_name, const std::string &name, InputParameters &parameters)
const std::vector< LinearSystemName > _linear_sys_names
The linear system names.
MaterialWarehouse _discrete_materials
virtual void computeJacobianBlock(libMesh::SparseMatrix< libMesh::Number > &jacobian, libMesh::System &precond_system, unsigned int ivar, unsigned int jvar)
Really not a good idea to use this.
Real computeMultiAppsDT(ExecFlagType type)
Find the smallest timestep over all MultiApps.
bool _skip_exception_check
If or not skip 'exception and stop solve'.
const ConstBndNodeRange & getCurrentAlgebraicBndNodeRange()
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
void setCurrentLinearSystem(unsigned int sys_num)
Set the current linear system pointer.
std::vector< std::vector< std::unique_ptr< Assembly > > > _assembly
The Assembly objects.
unsigned short _current_ic_state
std::map< LinearSystemName, unsigned int > _linear_sys_name_to_num
Map from linear system name to number.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
virtual void computeNullSpace(libMesh::NonlinearImplicitSystem &sys, std::vector< NumericVector< libMesh::Number > * > &sp)
virtual void reinitElemNeighborAndLowerD(const Elem *elem, unsigned int side, const THREAD_ID tid) override
virtual void prepare(const Elem *elem, const THREAD_ID tid) override
void computeLinearSystemTags(const NumericVector< libMesh::Number > &soln, const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, const bool compute_gradients=true)
Assemble the current linear system given a set of vector and matrix tags.
const std::size_t _num_linear_sys
The number of linear systems.
void handleException(const std::string &calling_method)
Handle exceptions.
virtual void addPostprocessor(const std::string &pp_name, const std::string &name, InputParameters &parameters)
void setNonlocalCouplingMatrix()
Set custom coupling matrix for variables requiring nonlocal contribution.
unsigned int solverSysNum(const SolverSystemName &solver_sys_name) const override
Moose::Kokkos::MaterialPropertyStorage & _kokkos_material_props
const std::vector< VariableName > _constant_null_space_vars
Variables whose constant fields span part of the Jacobian nullspace.
const libMesh::ConstElemRange & getCurrentAlgebraicElementRange()
These are the element and nodes that contribute to the jacobian and residual for this local processor...
std::map< SolverVariableName, unsigned int > _solver_var_to_sys_num
Map connecting variable names with their respective solver systems.
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid) override
MooseObjectWarehouse< InternalSideIndicatorBase > _internal_side_indicators
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
bool _requires_nonlocal_coupling
nonlocal coupling requirement flag
const bool _restore_original_nonzero_pattern
Whether we should restore the original nonzero pattern for every Jacobian evaluation.
void reinitMaterialsNeighbor(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on the neighboring element face
const VectorPostprocessorValue & getVectorPostprocessorValueByName(const std::string &object_name, const std::string &vector_name, std::size_t t_index=0) const
Get a read-only reference to the vector value associated with the VectorPostprocessor.
virtual void swapBackMaterialsNeighbor(const THREAD_ID tid)
void clearActiveMaterialProperties(const THREAD_ID tid)
Clear the active material properties.
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override
Clear the active elemental MooseVariableFEBase.
void setMultiAppFixedPointConvergenceName(const ConvergenceName &convergence_name)
Sets the MultiApp fixed point convergence object name if there is one.
bool _fail_next_system_convergence_check
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
bool _reinit_displaced_elem
Whether to call DisplacedProblem::reinitElem when this->reinitElem is called.
std::vector< VariableValue > _scalar_zero
unsigned int linearSysNum(const LinearSystemName &linear_sys_name) const override
bool _const_jacobian
true if the Jacobian is constant
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
void createMortarInterface(const std::pair< BoundaryID, BoundaryID > &primary_secondary_boundary_pair, const std::pair< SubdomainID, SubdomainID > &primary_secondary_subdomain_pair, bool on_displaced, bool periodic, const bool debug, const bool correct_edge_dropping, const Real minimum_projection_angle, const Mortar3DSubpatchPlane mortar_3d_subpatch_plane, const MooseEnum &triangulation, const bool triangulate_triangles, const Mortar3DQuadraturePointMapping mortar_3d_qp_mapping=Mortar3DQuadraturePointMapping::NORMAL_PROJECTION)
virtual void addKokkosReporter(const std::string &type, const std::string &name, InputParameters &parameters)
bool _has_internal_edge_residual_objects
Whether the problem has dgkernels or interface kernels.
virtual void addGhostedBoundary(BoundaryID boundary_id) override
Will make sure that all necessary elements from boundary_id are ghosted to this processor.
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
const libMesh::ConstElemRange & getEvaluableElementRange()
In general, {evaluable elements} >= {local elements} U {algebraic ghosting elements}.
virtual void addAuxScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addKokkosMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
std::unique_ptr< libMesh::ConstNodeRange > _current_algebraic_node_range
virtual void addDGKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
void setCurrentAlgebraicBndNodeRange(ConstBndNodeRange *range)
virtual void prepareFace(const Elem *elem, const THREAD_ID tid) override
const FVAdvectedInterpolationMethod & getFVAdvectedInterpolationMethod(const InterpolationMethodName &name, const THREAD_ID tid=0) const
Retrieve an advected interpolation method.
virtual void addKokkosKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
void prepareMaterials(const std::unordered_set< unsigned int > &consumer_needed_mat_props, const SubdomainID blk_id, const THREAD_ID tid)
Add the MooseVariables and the material properties that the current materials depend on to the depend...
void checkCoordinateSystems()
Verify that there are no element type/coordinate type conflicts.
MaterialPropertyStorage & _bnd_material_props
void logAdd(const std::string &system, const std::string &name, const std::string &type, const InputParameters &params) const
Output information about the object just added to the problem.
virtual void addAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
void initKokkos()
Construct Kokkos assembly and systems and allocate Kokkos material property storages.
virtual void initNullSpaceVectors(const InputParameters &parameters, std::vector< std::shared_ptr< NonlinearSystemBase > > &nl)
void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID, const THREAD_ID tid)
unsigned int _max_qps
Maximum number of quadrature points used in the problem.
void checkDuplicatePostprocessorVariableNames()
virtual void reinitLowerDElem(const Elem *lower_d_elem, const THREAD_ID tid, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr) override
virtual void addDiracKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
void forceOutput()
Indicates that the next call to outputStep should be forced.
void backupGeometricSearchState()
Snapshot geometric search state (both on the regular and, if present, the displaced mesh) so it can b...
virtual void solve(const unsigned int nl_sys_num)
std::optional< ConvergenceName > _steady_state_convergence_name
Steady-state detection convergence name.
virtual void addDefaultNonlinearConvergence(const InputParameters &params)
Adds the default nonlinear Convergence associated with the problem.
const std::unordered_map< std::pair< BoundaryID, BoundaryID >, MortarInterfaceConfig > & getMortarInterfaces(bool on_displaced) const
void setVariableAllDoFMap(const std::vector< const MooseVariableFEBase * > &moose_vars)
FEProblemBase(const InputParameters &parameters)
void projectFunctionOnCustomRange(ConstElemRange &elem_range, Number(*func)(const Point &, const libMesh::Parameters &, const std::string &, const std::string &), Gradient(*func_grad)(const Point &, const libMesh::Parameters &, const std::string &, const std::string &), const libMesh::Parameters &params, const std::vector< VariableName > &target_vars)
Project a function onto a range of elements for a given variable.
InitialConditionWarehouse _ics
virtual void checkExceptionAndStopSolve(bool print_message=true)
Check to see if an exception has occurred on any processor and, if possible, force the solve to fail,...
NonlinearSystemBase & currentNonlinearSystem()
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
void checkUserObjectJacobianRequirement(THREAD_ID tid)
bool duplicateVariableCheck(const std::string &var_name, const libMesh::FEType &type, bool is_aux, const std::set< SubdomainID > *const active_subdomains)
Helper to check for duplicate variable names across systems or within a single system.
void restoreMultiApps(ExecFlagType type, bool force=false)
Restore the MultiApps associated with the ExecFlagType.
void needsPreviousMultiAppFixedPointIterationSolution(bool needed, const unsigned int solver_sys_num)
Set a flag that indicated that user required values for the previous multiapp fixed point iterate for...
virtual unsigned int currentNlSysNum() const override
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
void setPostprocessorValueByName(const PostprocessorName &name, const PostprocessorValue &value, std::size_t t_index=0)
Set the value of a PostprocessorValue.
void computeResidual(libMesh::NonlinearImplicitSystem &sys, const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual)
This function is called by Libmesh to form a residual.
virtual Real & timeOld() const
virtual void computeBounds(libMesh::NonlinearImplicitSystem &sys, NumericVector< libMesh::Number > &lower, NumericVector< libMesh::Number > &upper)
MaterialWarehouse _all_materials
void setVectorPostprocessorValueByName(const std::string &object_name, const std::string &vector_name, const VectorPostprocessorValue &value, std::size_t t_index=0)
Set the value of a VectorPostprocessor vector.
virtual unsigned int nlSysNum(const NonlinearSystemName &nl_sys_name) const override
const libMesh::ConstElemRange & getNonlinearEvaluableElementRange()
PetscOptions _petsc_option_data_base
virtual unsigned int nNonlinearIterations(const unsigned int nl_sys_num) const override
void setPreserveMatrixSparsityPattern(bool preserve)
Set whether the sparsity pattern of the matrices being formed during the solve (usually the Jacobian)...
bool _has_time_integrator
Indicates whether or not this executioner has a time integrator (during setup)
void computeResidualAndJacobian(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, libMesh::SparseMatrix< libMesh::Number > &jacobian)
Form a residual and Jacobian with default tags.
void timestepSetup() override
virtual void computeIndicators()
virtual void onTimestepBegin() override
virtual MooseMesh & mesh() override
MaterialWarehouse _kokkos_materials
virtual void setResidualNeighbor(NumericVector< libMesh::Number > &residual, const THREAD_ID tid) override
void setCurrentResidualVectorTags(const std::set< TagID > &vector_tags)
Set the current residual vector tag data structure based on the passed in tag IDs.
virtual void addIndicator(const std::string &indicator_name, const std::string &name, InputParameters &parameters)
bool _previous_multiapp_fp_aux_solution_required
Indicates we need to save the previous multiapp fixed-point iteration auxiliary variable values.
std::set< TagID > _linear_matrix_tags
Temporary storage for filtered matrix tags for linear systems.
std::vector< std::unordered_map< BoundaryID, bool > > _interface_mat_side_cache
Cache for calculating materials on interface.
virtual void createQRules(libMesh::QuadratureType type, libMesh::Order order, libMesh::Order volume_order=libMesh::INVALID_ORDER, libMesh::Order face_order=libMesh::INVALID_ORDER, SubdomainID block=Moose::ANY_BLOCK_ID, bool allow_negative_qweights=true)
MooseObjectWarehouse< MeshDivision > _mesh_divisions
Warehouse to store mesh divisions NOTE: this could probably be moved to the MooseMesh instead of the ...
virtual void computePostCheck(libMesh::NonlinearImplicitSystem &sys, const NumericVector< libMesh::Number > &old_soln, NumericVector< libMesh::Number > &search_direction, NumericVector< libMesh::Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln)
Real getTimeFromStateArg(const Moose::StateArg &state) const
Returns the time associated with the requested state.
void setActiveMaterialProperties(const std::unordered_set< unsigned int > &mat_prop_ids, const THREAD_ID tid)
Record and set the material properties required by the current computing thread.
const bool _interface_kernel_integrity_check
Whether to check that interface kernel variables match the orientation of their boundaries.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
std::optional< std::vector< ConvergenceName > > _linear_convergence_names
Linear system(s) convergence name(s) (if any)
MooseObjectWarehouse< Moose::FunctionBase > _kokkos_functions
MooseEnum _verbose_setup
Whether or not to be verbose during setup.
void addDefaultSteadyStateConvergence(const InputParameters &params)
Adds the default steady-state detection Convergence.
virtual void reinitNeighborFaceRef(const Elem *neighbor_elem, unsigned int neighbor_side, Real tolerance, const std::vector< Point > *const pts, const std::vector< Real > *const weights=nullptr, const THREAD_ID tid=0) override
reinitialize FE objects on a given neighbor element on a given side at a given set of reference point...
FVInitialConditionWarehouse _fv_ics
virtual void addDisplacedProblem(std::shared_ptr< DisplacedProblem > displaced_problem)
const bool _boundary_restricted_elem_integrity_check
whether to perform checking of boundary restricted elemental object variable dependencies,...
virtual void addKokkosFunction(const std::string &type, const std::string &name, InputParameters &parameters)
Add a Kokkos function to the problem.
virtual void updateMortarMesh()
virtual bool hasFunction(const std::string &name, const THREAD_ID tid=0)
bool computingNonlinearResid() const
Returns true if the problem is in the process of computing the nonlinear residual.
Definition SubProblem.h:727
virtual void computeResidualTag(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, TagID tag)
Form a residual vector for a given tag.
std::vector< std::unordered_map< BoundaryID, bool > > _bnd_mat_side_cache
Cache for calculating materials on side.
void reinitMaterialsFaceOnBoundary(const BoundaryID boundary_id, const SubdomainID blk_id, const THREAD_ID tid, const bool swap_stateful=true, const std::deque< MaterialBase * > *const reinit_mats=nullptr)
reinit materials on element faces on a boundary (internal or external) This specific routine helps us...
NonlinearSystemBase * _current_nl_sys
The current nonlinear system that we are solving.
const bool _uo_aux_state_check
Whether or not checking the state of uo/aux evaluation.
bool _started_initial_setup
At or beyond initialSteup stage.
Adaptivity _adaptivity
std::vector< SolverSystemName > _solver_sys_names
The union of nonlinear and linear system names.
void reinitMaterialsBoundary(BoundaryID boundary_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on a boundary
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
virtual void saveOldSolutions()
Allocate vectors and save old solutions into them.
const std::vector< ConvergenceName > & getLinearConvergenceNames() const
Gets the linear convergence object name(s).
void checkICRestartError(const std::string &ic_name, const std::string &name, const VariableName &var_name)
Checks if the variable of the initial condition is getting restarted and errors for specific cases.
std::vector< MeshChangedInterface * > _notify_when_mesh_changes
Objects to be notified when the mesh changes.
virtual void addAuxVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
Canonical method for adding an auxiliary variable.
std::shared_ptr< DisplacedProblem > _displaced_problem
void finalizeMultiApps()
void computeUserObjectsInternal(const ExecFlagType &type, TheWarehouse::Query &query)
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFEBase * > &moose_vars, const THREAD_ID tid) override
Set the MOOSE variables to be reinited on each element.
bool _verbose_restore
Whether or not to be verbose on solution restoration post a failed time step.
virtual void computeJacobianBlocks(std::vector< JacobianBlock * > &blocks, const unsigned int nl_sys_num)
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
void reinitMortarUserObjects(BoundaryID primary_boundary_id, BoundaryID secondary_boundary_id, bool displaced)
Call reinit on mortar user objects with matching primary boundary ID, secondary boundary ID,...
bool haveADObjects() const
Method for reading wehther we have any ad objects.
Definition SubProblem.h:791
virtual void swapBackMaterials(const THREAD_ID tid)
virtual void initialAdaptMesh()
void executeSamplers(const ExecFlagType &exec_type)
Performs setup and execute calls for Sampler objects.
void backupMultiApps(ExecFlagType type)
Backup the MultiApps associated with the ExecFlagType.
const std::size_t _num_nl_sys
The number of nonlinear systems.
virtual std::string solverTypeString(unsigned int solver_sys_num=0)
Return solver type as a human readable string.
const std::vector< VariableName > _constant_transpose_null_space_vars
Variables whose constant fields span part of the Jacobian transpose nullspace.
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override
std::vector< VectorVariableCurl > _vector_curl_zero
virtual bool checkNonlocalCouplingRequirement() const override
void setCurrentExecuteOnFlag(const ExecFlagType &)
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
bool shouldPrintExecution(const THREAD_ID tid) const
Check whether the problem should output execution orders at this time.
bool _has_mortar
Whether the simulation requires mortar coupling.
std::vector< bool > _previous_multiapp_fp_nl_solution_required
Indicates we need to save the previous multiapp fixed-point iteration solver variable values.
virtual void addAuxArrayVariable(const std::string &var_name, const libMesh::FEType &type, unsigned int components, const std::set< SubdomainID > *const active_subdomains=NULL)
void setCurrentlyComputingResidual(bool currently_computing_residual) final
Set whether or not the problem is in the process of computing the residual.
const unsigned int _num_concurrent_multiapps
Number of concurrent applications being solved at the same time.
virtual std::vector< VariableName > getVariableNames()
Returns a list of all the variables in the problem (both from the NL and Aux systems.
virtual void updateGeomSearch(GeometricSearchData::GeometricSearchType type=GeometricSearchData::ALL) override
Update this object's geometric search data as well as the displaced problem's if it exists.
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
void partitionConcurrentMultiApps()
Assign each multiapp that shares an 'execution_order_group' with others a disjoint subset of the rank...
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
bool _calculate_jacobian_in_uo
MeshDivision & getMeshDivision(const std::string &name, const THREAD_ID tid=0) const
Get a MeshDivision.
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
bool _reinit_displaced_face
Whether to call DisplacedProblem::reinitElemFace when this->reinitElemFace is called.
bool _has_initialized_stateful
Whether nor not stateful materials have been initialized.
bool _has_constraints
Whether or not this system has any Constraints.
std::vector< MortarUserObject * > getMortarUserObjects(BoundaryID primary_boundary_id, BoundaryID secondary_boundary_id, bool displaced, const std::vector< MortarUserObject * > &mortar_uo_superset)
Helper for getting mortar objects corresponding to primary boundary ID, secondary boundary ID,...
std::vector< std::shared_ptr< NonlinearSystemBase > > _nl
The nonlinear systems.
void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels=false)
Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType.
virtual void addKokkosLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void computeJacobianTags(const std::set< TagID > &tags)
Form multiple matrices, and each is associated with a tag.
Moose::PetscSupport::PetscOptions _petsc_options
PETSc option storage.
void checkGradientMethods()
Let every FVGradientMethod resolve its dependencies on other gradient methods.
virtual void addMultiApp(const std::string &multi_app_name, const std::string &name, InputParameters &parameters)
Add a MultiApp to the problem.
void setResidualObjectParamsAndLog(const std::string &ro_name, const std::string &name, InputParameters &parameters, const unsigned int nl_sys_num, const std::string &base_name, bool &reinit_displaced)
Set the subproblem and system parameters for residual objects and log their addition.
virtual void addMarker(const std::string &marker_name, const std::string &name, InputParameters &parameters)
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid)
These methods are used to determine whether stateful material properties need to be stored on interna...
virtual Distribution & getDistribution(const std::string &name)
TheWarehouse & theWarehouse() const
const bool & currentlyComputingResidual() const
Returns true if the problem is in the process of computing the residual.
Definition SubProblem.h:740
virtual void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addKokkosNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual Real finalNonlinearResidual(const unsigned int nl_sys_num) const override
MooseObjectWarehouse< Convergence > _convergences
convergence warehouse
virtual bool hasConvergence(const std::string &name, const THREAD_ID tid=0) const
Returns true if the problem has a Convergence object of the given name.
virtual Real & time() const
bool _has_jacobian
Indicates if the Jacobian was computed.
virtual const SystemBase & systemBaseSolver(const unsigned int sys_num) const override
Return the solver system object as a base class reference given the system number.
virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid)
void translateCaughtException(const std::string &calling_method)
Classify the exception currently being handled and register its message with setException(),...
virtual bool adaptMesh()
virtual void addFVInterfaceKernel(const std::string &fv_ik_name, const std::string &name, InputParameters &parameters)
void bumpAllQRuleOrder(libMesh::Order order, SubdomainID block)
virtual void addFVInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
Add an initial condition for a finite volume variables.
const std::vector< std::pair< MooseVariableFieldBase *, MooseVariableScalar * > > & fieldScalarCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num) const
std::vector< std::vector< const MooseVariableFEBase * > > _uo_jacobian_moose_vars
Adaptivity & adaptivity()
virtual void computeResidualType(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, TagID tag)
Form a residual vector for a given tag and "residual" tag.
virtual Real & timeOlder() const
The time two steps back.
void reinitMaterialsNeighborOnBoundary(const BoundaryID boundary_id, const SubdomainID blk_id, const THREAD_ID tid, const bool swap_stateful=true, const std::deque< MaterialBase * > *const reinit_mats=nullptr)
reinit materials on neighbor element (usually faces) on a boundary (internal or external) This specif...
virtual void addInterfaceKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addReporter(const std::string &type, const std::string &name, InputParameters &parameters)
Add a Reporter object to the simulation.
const libMesh::ConstNodeRange & getCurrentAlgebraicNodeRange()
std::vector< unsigned char > _has_active_material_properties
Whether there are active material properties on each thread.
void execMultiAppTransfers(ExecFlagType type, Transfer::DIRECTION direction, const MultiAppName &source_app="")
Execute MultiAppTransfers associated with execution flag and direction.
Moose::CouplingType _coupling
Type of variable coupling.
bool _has_exception
Whether or not an exception has occurred.
MooseAppCoordTransform & coordTransform()
virtual void copySolutionsBackwards()
std::vector< Real > _real_zero
Convenience zeros.
void reinitMaterialsInterface(BoundaryID boundary_id, const THREAD_ID tid, bool swap_stateful=true)
virtual void addConstraint(const std::string &c_name, const std::string &name, InputParameters &parameters)
virtual void setCurrentLowerDElem(const Elem *const lower_d_elem, const THREAD_ID tid) override
Set the current lower dimensional element.
virtual void initPetscOutputAndSomeSolverSettings()
Reinitialize PETSc output for proper linear/nonlinear iteration display.
void allowOutput(bool state)
Ability to enable/disable all output calls.
void computeKokkosUserObjectsInternal(const ExecFlagType &type, TheWarehouse::Query &query)
bool hasMultiApp(const std::string &name) const
virtual void meshDisplaced()
Update data after a mesh displaced.
std::unique_ptr< libMesh::ConstElemRange > _evaluable_local_elem_range
std::vector< MooseArray< ADRealTensorValue > > _ad_second_zero
virtual void setResidual(NumericVector< libMesh::Number > &residual, const THREAD_ID tid) override
void initKokkosStatefulProps()
virtual bool isTransient() const override
virtual void addCachedResidualDirectly(NumericVector< libMesh::Number > &residual, const THREAD_ID tid)
Allows for all the residual contributions that are currently cached to be added directly into the vec...
virtual void addFunctorMaterial(const std::string &functor_material_name, const std::string &name, InputParameters &parameters)
virtual void addDamper(const std::string &damper_name, const std::string &name, InputParameters &parameters)
virtual void computeMarkers()
const ConvergenceName & getMultiAppFixedPointConvergenceName() const
Gets the MultiApp fixed point convergence object name.
static SolverParams makeLinearSolverParams()
Make basic solver params for linear solves.
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
unsigned int _cycles_completed
ExecFlagEnum _print_execution_on
When to print the execution of loops.
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override
std::vector< Point > _point_zero
std::vector< MooseArray< ADReal > > _ad_zero
virtual void computeJacobianTag(const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian, TagID tag)
Form a Jacobian matrix for a given tag.
void createTagSolutions()
Create extra tagged solution vectors.
virtual void prepareAssemblyNeighbor(const THREAD_ID tid)
Begin a fresh neighbor accumulation phase by sizing and zeroing the neighbor blocks.
MooseObjectWarehouse< Function > _functions
functions
virtual const SystemBase & systemBaseNonlinear(const unsigned int sys_num) const override
Return the nonlinear system object as a base class reference given the system number.
CoverageCheckMode _material_coverage_check
Determines whether and which subdomains are to be checked to ensure that they have an active material...
const std::set< const MooseObject * > & getMaterialPropertyStorageConsumers(Moose::MaterialDataType type) const
virtual void clearActiveFEVariableCoupleableMatrixTags(const THREAD_ID tid) override
virtual const SystemBase & getSystemBase(const unsigned int sys_num) const
Get constant reference to a system in this problem.
bool allowInvalidSolution() const
Whether to accept / allow an invalid solution.
void needsPreviousMultiSystemFixedPointIterationSolution(bool needed, const unsigned int solver_sys_num)
Set a flag that indicates that user requires values for the previous multi-system fixed point iterate...
void addDefaultMultiAppFixedPointConvergence(const InputParameters &params)
Adds the default fixed point Convergence associated with the problem.
bool hasActiveMaterialProperties(const THREAD_ID tid) const
Method to check whether or not a list of active material roperties has been set.
virtual unsigned int nLinearIterations(const unsigned int nl_sys_num) const override
std::optional< std::vector< ConvergenceName > > _nonlinear_convergence_names
Nonlinear system(s) convergence name(s)
virtual Real computeResidualL2Norm()
Computes the residual using whatever is sitting in the current solution vector then returns the L2 no...
std::unique_ptr< ConstBndNodeRange > _current_algebraic_bnd_node_range
virtual void addFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void computeTransposeNullSpace(libMesh::NonlinearImplicitSystem &sys, std::vector< NumericVector< libMesh::Number > * > &sp)
void initialSetup() override
bool _previous_multisystem_fp_aux_solution_required
Indicates we need to save the previous multi-system fixed-point iteration auxiliary variable values.
std::vector< VariableValue > _zero
virtual void outputStep(ExecFlagType type)
Output the current step.
MooseObjectWarehouse< Marker > _markers
std::vector< std::shared_ptr< SolverSystem > > _solver_systems
Combined container to base pointer of every solver system.
void getUOExecutionGroups(TheWarehouse::Query &query, std::set< int > &execution_groups) const
bool _is_petsc_options_inserted
If or not PETSc options have been added to database.
void notifyWhenMeshChanges(MeshChangedInterface *mci)
Register an object that derives from MeshChangedInterface to be notified when the mesh changes.
virtual void ghostGhostedBoundaries() override
Causes the boundaries added using addGhostedBoundary to actually be ghosted.
virtual void computeJacobianInternal(const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian, const std::set< TagID > &tags)
Form a Jacobian matrix for multiple tags.
virtual void cacheResidualNeighbor(const THREAD_ID tid) override
virtual void computeResidualSys(libMesh::NonlinearImplicitSystem &sys, const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual)
This function is called by Libmesh to form a residual.
virtual void computeIndicatorsAndMarkers()
virtual void reinitNeighbor(const Elem *elem, unsigned int side, const THREAD_ID tid) override
const std::vector< NonlinearSystemName > _nl_sys_names
The nonlinear system names.
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, const THREAD_ID tid) override
const bool _fv_face_integrity_check
Whether to check FV boundary and interface objects against the faces on which they execute.
virtual void meshChanged()
Deprecated.
virtual std::pair< bool, unsigned int > determineSolverSystem(const std::string &var_name, bool error_if_not_found=false) const override
Determine what solver system the provided variable name lies in.
virtual libMesh::System & getSystem(const std::string &var_name) override
Returns the equation system containing the variable provided.
void uniformRefine()
uniformly refine the problem mesh(es).
MooseMesh * _displaced_mesh
ExecuteMooseObjectWarehouse< Transfer > _from_multi_app_transfers
Transfers executed just after MultiApps to transfer data from them.
void initXFEM(std::shared_ptr< XFEMInterface > xfem)
Create XFEM controller object.
std::vector< SubdomainName > _kernel_coverage_blocks
static InputParameters validParams()
MaterialPropertyRegistry _material_prop_registry
virtual bool computingPreSMOResidual(const unsigned int nl_sys_num) const override
Returns true if the problem is in the process of computing it's initial residual.
bool automaticScaling() const
Automatic scaling getter.
bool constJacobian() const
Returns _const_jacobian (whether a MOOSE object has specified that the Jacobian is the same as the pr...
virtual void addMeshDivision(const std::string &type, const std::string &name, InputParameters &params)
Add a MeshDivision.
virtual void prepareNeighborShapes(unsigned int var, const THREAD_ID tid) override
const bool _allow_ics_during_restart
virtual void addKokkosVectorPostprocessor(const std::string &pp_name, const std::string &name, InputParameters &parameters)
Interface for interpolation methods that provide matrix and RHS contributions for advected face value...
Abstract base class for interpolation methods that produce a scalar face value from adjacent cell val...
Base class for linear finite-volume cell-gradient methods.
This is a template class that implements the workhorse compute and computeNodal methods.
void initialSetup(THREAD_ID tid)
Initial setup.
void addObject(std::shared_ptr< FVInitialConditionBase > object, THREAD_ID tid, bool recurse=true)
Add object to the warehouse.
Registered base class for linear FV interpolation objects.
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition Factory.C:142
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
Scope guard for starting and stopping Floating Point Exception Trapping.
Base class for function objects.
Definition Function.h:30
FunctorMaterials compute functor material properties.
void reinit()
Completely redo all geometric search objects.
void restore()
Restore the PenetrationLocators' state captured by the most recent backup().
GeometricSearchType
Used to select groups of geometric search objects to update.
std::map< std::pair< BoundaryID, BoundaryID >, NearestNodeLocator * > _nearest_node_locators
void clearNearestNodeLocators()
Clear out the Penetration Locators so they will redo the search.
void updateGhostedElems()
Updates the list of ghosted elements at the start of each time step for the nonlinear iteration patch...
void update(GeometricSearchType type=ALL)
Update all of the search objects.
void backup()
Snapshot the PenetrationLocators' restartable state (the same state used for restart/recover),...
This is a template class that implements the workhorse compute and computeNodal methods.
std::set< std::string > getDependObjects() const
Get a list of dependent UserObjects for this exec type.
void addObject(std::shared_ptr< InitialConditionBase > object, THREAD_ID tid, bool recurse=true)
Add object to the warehouse.
void initialSetup(THREAD_ID tid)
Initial setup.
std::vector< MooseObjectParameterName > getControllableParameterNames(const MooseObjectParameterName &input) const
Return a vector of parameters names matching the supplied name.
void addControllableParameterConnection(const MooseObjectParameterName &primary, const MooseObjectParameterName &secondary, bool error_on_empty=true)
Method for linking control parameters of different names.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
bool isKokkosObject() const
Returns whether this InputParameters belongs to a Kokkos object Checks whether MooseBase::kokkos_obje...
bool isParamDefined(const std::string &name) const
Method returns true if the parameter is defined for any type.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
std::string varName(const std::string &var_param_name, const std::string &moose_object_with_var_param_name) const
Determine the actual variable name from the given variable \emph parameter name.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
const std::string & getObjectName() const
const hit::Node * getHitNode(const std::string &param) const
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void checkParams(const std::string &parsing_syntax)
This function checks parameters stored in the object to make sure they are in the correct state as th...
const std::string & getBase() const
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
void applyCommonUserSetParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
Variant of applyParameters that only applies parameters explicitly set by the user in common (i....
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
Method for applying common parameters.
Helper class for holding the preconditioning blocks to fill.
Linear system to be solved.
virtual void stopSolve(const ExecFlagType &exec_flag, const std::set< TagID > &vector_tags_to_close) override
Quit the current solve as soon as possible.
TagID rightHandSideVectorTag() const
virtual TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
NumericVector< Number > & getRightHandSideVector()
Fetching the right hand side vector from the libmesh system.
SparseMatrix< Number > & getSystemMatrix()
Fetching the system matrix from the libmesh system.
libMesh::LinearImplicitSystem & linearImplicitSystem()
Return a reference to the stored linear implicit system.
void computeLinearSystemTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, const bool compute_gradients=true)
Compute the right hand side and the system matrix of the system for given tags.
virtual void compute(ExecFlagType type) override
Compute time derivatives, auxiliary variables, etc.
virtual void solve() override
Solve the system (using libMesh magic)
MaterialBases compute MaterialProperties.
Proxy for accessing MaterialPropertyStorage.
void resize(unsigned int n_qpoints)
Resize the data to hold properties for n_qpoints quadrature points.
void swapBack(const Elem &elem, unsigned int side=0)
material properties for given element (and possible side)
const std::string & getName(const unsigned int id) const
Stores the stateful material properties computed by materials.
const std::set< const MooseObject * > & getConsumers(Moose::MaterialDataType type) const
void eraseProperty(const Elem *elem)
Remove the property storage and element pointer from internal data structures Use this when elements ...
void shift()
Shift the material properties in time.
void addConsumer(Moose::MaterialDataType type, const MooseObject *object)
Add object as the consumer of storage of type type.
const MaterialData & getMaterialData(const THREAD_ID tid) const
virtual void jacobianSetup(THREAD_ID tid=0) const override
void addObjects(std::shared_ptr< MaterialBase > block, std::shared_ptr< MaterialBase > neighbor, std::shared_ptr< MaterialBase > face, THREAD_ID tid=0)
A special method unique to this class for adding Block, Neighbor, and Face material objects.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
void sort(THREAD_ID tid=0, bool sort_all_objects=false)
By default, this method only sorts block and boundary-wise object storages that are used by the MOOSE...
virtual void subdomainSetup(THREAD_ID tid=0) const override
virtual void neighborSubdomainSetup(THREAD_ID tid=0) const
virtual void residualSetup(THREAD_ID tid=0) const override
virtual void timestepSetup(THREAD_ID tid=0) const override
virtual void initialSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods that handle the extra neighbor and face objects.
This class determines the maximum number of Quadrature Points and Shape Functions used for a given si...
unsigned int max() const
Interface for notifications that the mesh has changed.
Interface for objects acting when the mesh has been displaced.
Base class for MeshDivision objects.
bool hasScalingOrRotationTransformation() const
Returns true if the app has scaling and/or rotation transformation.
static InputParameters validParams()
Describes the parameters this object can take to setup transformations.
Base class for MOOSE-based applications.
Definition MooseApp.h:110
bool restoredInitialBackupMesh() const
Whether this app has restored mesh topology from its initial Backup object.
Definition MooseApp.h:759
void restoreFromInitialBackup(const bool for_restart)
Restores from a "initial" backup, that is, one set in _initial_backup.
Definition MooseApp.C:1843
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition MooseApp.C:2452
bool hasStartTime() const
Definition MooseApp.h:303
void setRestart(bool value)
Sets the restart/recover flags.
Definition MooseApp.C:2922
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition MooseApp.C:1718
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition MooseApp.C:2058
ChainControlDataSystem & getChainControlDataSystem()
Gets the system that manages the ChainControls.
Definition MooseApp.h:900
std::unique_ptr< Backup > finalizeRestore()
Finalizes (closes) the restoration process done in restore().
Definition MooseApp.C:1850
void setRestartRecoverFileBase(const std::string &file_base)
mutator for recover_base (set by RecoverBaseAction)
Definition MooseApp.h:521
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition MooseApp.h:875
void restore(const std::filesystem::path &folder_base, const bool for_restart)
Restore an application from file.
Definition MooseApp.C:1799
std::string getRestartRecoverFileBase() const
The file_base for the recovery file.
Definition MooseApp.h:509
const ExecFlagEnum & getExecuteOnEnum() const
Return the app level ExecFlagEnum, this contains all the available flags for the app.
Definition MooseApp.h:1049
bool getExodusFileRestart() const
Whether or not we need to use a separate Exodus reader to read the mesh BEFORE we create the mesh.
Definition MooseApp.h:445
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition MooseApp.C:1712
libMesh::ExodusII_IO * getExReaderForRestart() const
Get the Exodus reader to restart variables from an Exodus mesh file.
Definition MooseApp.h:458
bool hasInitialBackup() const
Definition MooseApp.h:1056
Real getStartTime() const
Definition MooseApp.h:308
std::filesystem::path restartFolderBase(const std::filesystem::path &folder_base) const
The file suffix for restartable data.
Definition MooseApp.C:3097
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
Definition MooseApp.h:182
void markMeshChangedForBackup()
Mark this app as requiring mesh topology data in its next Backup object.
Definition MooseApp.h:764
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition MooseApp.C:2910
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
void paramInfo(const std::string &param, Args... args) const
Emits an informational message prefixed with the file and line number of the given param (from the in...
Definition MooseBase.h:480
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Definition MooseBase.C:57
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:466
const std::string & _type
The type of this class.
Definition MooseBase.h:384
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:415
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition MooseBase.h:59
Class for containing MooseEnum item information.
const std::string & name() const
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
Thrown by FEProblemBase::checkExceptionAndStopSolve() once an exception has been communicated to all ...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
const Moose::PatchUpdateType & getPatchUpdateStrategy() const
Get the current patch update strategy.
Definition MooseMesh.C:3546
void setupFiniteVolumeMeshData() const
Sets up the additional data needed for finite volume computations.
Definition MooseMesh.C:4238
const std::set< BoundaryID > & getSubdomainBoundaryIds(const SubdomainID subdomain_id) const
Get the list of boundary ids associated with the given subdomain id.
Definition MooseMesh.C:3630
const Elem * getLowerDElem(const Elem *, unsigned short int) const
Returns a const pointer to a lower dimensional element that corresponds to a side of a higher dimensi...
Definition MooseMesh.C:1692
face_info_iterator ownedFaceInfoEnd()
Definition MooseMesh.C:1511
void meshChanged()
Declares that the MooseMesh has changed, invalidates cached data and rebuilds caches.
Definition MooseMesh.C:904
virtual const Node & nodeRef(const dof_id_type i) const
Definition MooseMesh.C:856
const std::vector< const Elem * > & coarsenedElementChildren(const Elem *elem) const
Get the newly removed children element ids for an element that was just coarsened.
Definition MooseMesh.C:964
unsigned int uniformRefineLevel() const
Returns the level of uniform refinement requested (zero if AMR is disabled).
Definition MooseMesh.C:3324
elem_info_iterator ownedElemInfoEnd()
Definition MooseMesh.C:1528
virtual Elem * elemPtr(const dof_id_type i)
Definition MooseMesh.C:3221
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3581
void buildRefinementAndCoarseningMaps(Assembly *assembly)
Create the refinement and coarsening maps necessary for projection of stateful material properties wh...
Definition MooseMesh.C:2520
std::vector< SubdomainName > getSubdomainNames(const std::vector< SubdomainID > &subdomain_ids) const
Get the associated subdomainNames for the subdomain ids that are passed in.
Definition MooseMesh.C:1764
const std::string & getBoundaryName(const BoundaryID boundary_id) const
Return the name of the boundary given the id.
Definition MooseMesh.C:1787
MooseAppCoordTransform & coordTransform()
Definition MooseMesh.h:2094
void addGhostedBoundary(BoundaryID boundary_id)
This will add the boundary ids to be ghosted to this processor.
Definition MooseMesh.C:3337
ConstElemPointerRange * refinedElementRange() const
Return a range that is suitable for threaded execution over elements that were just refined.
Definition MooseMesh.C:952
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition MooseMesh.C:1722
face_info_iterator ownedFaceInfoBegin()
Iterators to owned faceInfo objects.
Definition MooseMesh.C:1502
libMesh::ConstNodeRange * getLocalNodeRange()
Definition MooseMesh.C:1286
elem_info_iterator ownedElemInfoBegin()
Iterators to owned faceInfo objects.
Definition MooseMesh.C:1520
void ghostGhostedBoundaries()
Actually do the ghosting of boundaries that need to be ghosted to this processor.
Definition MooseMesh.C:3422
void updateActiveSemiLocalNodeRange(std::set< dof_id_type > &ghosted_elems)
Clears the "semi-local" node list and rebuilds it.
Definition MooseMesh.C:972
void checkCoordinateSystems()
Performs a sanity check for every element in the mesh.
Definition MooseMesh.C:4473
bool isFiniteVolumeInfoDirty() const
Definition MooseMesh.h:1472
virtual Elem * queryElemPtr(const dof_id_type i)
Definition MooseMesh.C:3233
void cacheChangedLists()
Cache information about what elements were refined and coarsened in the previous step.
Definition MooseMesh.C:934
const std::set< SubdomainID > & interiorLowerDBlocks() const
Definition MooseMesh.h:1563
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_names) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition MooseMesh.C:1728
ConstElemPointerRange * coarsenedElementRange() const
Return a range that is suitable for threaded execution over elements that were just coarsened.
Definition MooseMesh.C:958
const std::string & getSubdomainName(SubdomainID subdomain_id) const
Return the name of a block given an id.
Definition MooseMesh.C:1758
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition MooseMesh.C:1300
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition MooseMesh.C:3279
void setCoordSystem(const std::vector< SubdomainName > &blocks, const MultiMooseEnum &coord_sys)
Set the coordinate system for the provided blocks to coord_sys.
Definition MooseMesh.C:4247
const MeshBase::element_iterator activeLocalElementsEnd()
Definition MooseMesh.C:3165
void doingPRefinement(bool doing_p_refinement)
Indicate whether the kind of adaptivity we're doing includes p-refinement.
Definition MooseMesh.h:1515
void setAxisymmetricCoordAxis(const MooseEnum &rz_coord_axis)
For axisymmetric simulations, set the symmetry coordinate axis.
Definition MooseMesh.C:4379
const libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
Definition MooseMesh.C:1257
const std::set< SubdomainID > & boundaryLowerDBlocks() const
Definition MooseMesh.h:1567
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
Definition MooseMesh.C:1313
MeshBase::element_iterator activeLocalElementsBegin()
Calls active_local_nodes_begin/end() on the underlying libMesh mesh object.
Definition MooseMesh.C:3159
void buildPRefinementAndCoarseningMaps(Assembly *assembly)
Definition MooseMesh.C:2426
A class for storing the names of MooseObject by tag and object name.
A class for storing an input parameter name.
void updateVariableDependency(std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
std::set< SubdomainID > getActiveBlocks(THREAD_ID tid=0) const
Return a set of active SubdomainsIDs.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getObjects(THREAD_ID tid=0) const
Retrieve complete vector to the all/block/boundary restricted objects for a given thread.
bool hasActiveObject(const std::string &name, THREAD_ID tid=0) const
Convenience functions for checking/getting specific objects.
void sort(THREAD_ID tid=0)
Sort the objects using the DependencyResolver.
void updateBlockMatPropDependency(SubdomainID id, std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
void updateBoundaryVariableDependency(std::set< MooseVariableFieldBase * > &needed_moose_vars, THREAD_ID tid=0) const
bool hasActiveObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void updateBoundaryMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread.
std::shared_ptr< T > getObject(const std::string &name, THREAD_ID tid=0) const
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void residualSetup(THREAD_ID tid=0) const
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void jacobianSetup(THREAD_ID tid=0) const
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:381
Base variable class.
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
SystemBase & sys()
Get the system this variable is part of.
const std::vector< dof_id_type > & allDofIndices() const
Get all global dofindices for the variable.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
unsigned int number() const
Get variable number coming from libMesh.
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void insert(libMesh::NumericVector< libMesh::Number > &vector)=0
Insert the currently cached degree of freedom values into the provided vector.
virtual void prepare()=0
Prepare the elemental degrees of freedom.
Class for scalar variables (they are different).
void setValue(unsigned int i, Number value)
Set the nodal value for this variable (to keep everything up to date.
void reinit(bool reinit_for_derivative_reordering=false)
Fill out the VariableValue arrays from the system solution vector.
Base class template for functor objects.
void shift()
Shift current, old, and older material property data storages.
A struct for storing the various types of petsc options and values.
Base class for all MultiAppTransfer objects.
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition MultiApp.h:140
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
A user object that runs over all the nodes and does an aggregation step to compute a single value.
Nonlinear system to be solved.
TagID timeVectorTag() const override
Ideally, we should not need this API.
void computeResidualTags(const std::set< TagID > &tags)
Form multiple tag-associated residual vectors for all the given tags.
Real computeDamping(const NumericVector< Number > &solution, const NumericVector< Number > &update)
Compute damping.
TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
virtual NumericVector< Number > & RHS()=0
virtual void setPreviousNewtonSolution(const NumericVector< Number > &soln)
void computeJacobianBlocks(std::vector< JacobianBlock * > &blocks)
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
virtual void solve() override=0
Solve the system (using libMesh magic)
void computeJacobianTags(const std::set< TagID > &tags)
Computes multiple (tag associated) Jacobian matricese.
TagID nonTimeVectorTag() const override
virtual libMesh::System & system() override
Get the reference to the libMesh system.
void setupDM()
Setup the PETSc DM object (when appropriate)
void computeResidualAndJacobianTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Form possibly multiple tag-associated vectors and matrices.
TagID residualVectorTag() const override
Nonlinear system to be solved.
Class for storing and utilizing output objects.
const InputParameters * getCommonParameters() const
Get a reference to the common output parameters.
bool isReservedName(const std::string &name)
Test if the given name is reserved.
void solveSetup()
Calls the timestepSetup function for each of the output objects.
void jacobianSetup()
Calls the jacobianSetup function for each of the output objects.
void forceOutput()
Indicates that the next call to outputStep should be forced This is private, users should utilize FEP...
void timestepSetup()
Calls the timestepSetup function for each of the output objects.
void initialSetup()
Calls the initialSetup function for each of the output objects.
void customSetup(const ExecFlagType &exec_type)
Calls the setup function for each of the output objects.
bool hasOutput(const std::string &name) const
Returns true if the output object exists.
void subdomainSetup()
Calls the subdomainSetup function for each of the output objects.
void mooseConsole()
Send current output buffer to Console output objects.
void residualSetup()
Calls the residualSetup function for each of the output objects.
void outputStep(ExecFlagType type)
Calls the outputStep method for each output object.
void allowOutput(bool state)
Ability to enable/disable output calls This is private, users should utilize FEProblemBase::allowOutp...
void addOutput(std::shared_ptr< Output > output)
Adds an existing output object to the warehouse.
Based class for output objects.
Definition Output.h:52
Positions objects are under the hood Reporters.
Definition Positions.h:21
A ReporterName that represents a Postprocessor.
Base class for all Postprocessors.
Base class for predictors.
Definition Predictor.h:29
Interface for objects that need parallel consistent random numbers without patterns over the course o...
void setRandomDataPointer(RandomData *random_data)
RedistributeProperties is used for its redistribute() callback, which ensures that any stateful prope...
static InputParameters validParams()
void addMaterialPropertyStorage(MaterialPropertyStorage &mat_props)
Pushes the given pair ( mat_data , mat_props ) onto our list of _materials data to redistribute each ...
std::vector< std::string > getAllRealReporterFullNames() const
Get full names of all real reporter values Note: For a postprocessor, the full name is the postproces...
DenseVector< Real > getAllRealReporterValues() const
Get all real reporter values including postprocessor and vector postprocessor values into a dense vec...
void check() const
Perform integrity check for get/declare calls.
void copyValuesBack()
At the end of a timestep this method is called to copy the values back in time in preparation for the...
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
void setReporterValue(const ReporterName &reporter_name, const T &value, const std::size_t time_index=0)
Method for setting Reporter values that already exist.
void restoreState(bool verbose=false)
When a time step fails, this method is called to revert the current reporter values to their old stat...
const T & getReporterValue(const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
Method for returning read only references to Reporter values.
std::set< std::string > getPostprocessorNames() const
Return a list of all postprocessor names.
void finalize(const std::string &object_name)
Helper function for performing post calculation actions via the ReporterContext objects.
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
Definition Reporter.h:48
Wrapper class that owns a libMesh EquationSystem and adds advanced restart capability to it.
void setLoadAllVectors(const bool load_all_vectors)
Sets whether or not all vectors are to be loaded.
const T & get() const
Get the restartable value.
Definition Restartable.h:58
A class for creating restricted objects.
Definition Restartable.h:29
This is the base class for Samplers as used within the Stochastic Tools module.
Definition Sampler.h:52
InitialConditions are objects that set the initial value of variables.
void paramWarning(const std::string &param, Args... args) const
bool hasInvalidSolutionError() const
Whether or not an invalid solution was encountered that was an error.
void resetIterationOccurences()
Reset the number of solution invalid occurrences back to zero.
Moose::LineSearchType _line_search
Moose::SolveType _type
virtual void stopSolve(const ExecFlagType &exec_flag, const std::set< TagID > &vector_tags_to_close)=0
Quit the current solve as soon as possible.
void setSolution(const NumericVector< Number > &soln)
Set the solution to a given vector.
virtual const NumericVector< Number > *const & currentSolution() const override final
The solution vector that is currently being operated on.
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
bool _safe_access_tagged_vectors
Is it safe to retrieve data from tagged vectors.
virtual void clearActiveFEVariableCoupleableVectorTags(const THREAD_ID tid)
Definition SubProblem.C:370
THREAD_ID numThreads() const
Definition SubProblem.C:81
virtual void checkBoundaryMatProps()
Checks boundary material properties integrity.
Definition SubProblem.C:657
virtual void cacheJacobianNeighbor(const THREAD_ID tid)
virtual void reinitNeighborSurfaceElemRef(const Elem *neighbor_elem, const std::vector< Point > &pts, const THREAD_ID tid=0)
reinitialize FE objects on a given neighbor element that is itself the face, i.e.
Definition SubProblem.C:949
const bool & currentlyComputingJacobian() const
Returns true if the problem is in the process of computing the Jacobian.
Definition SubProblem.h:704
virtual void checkBlockMatProps()
Checks block material properties integrity.
Definition SubProblem.C:615
virtual void clearActiveFEVariableCoupleableMatrixTags(const THREAD_ID tid)
Definition SubProblem.C:376
bool _currently_computing_residual
Whether the residual is being evaluated.
bool _computing_nonlinear_residual
Whether the non-linear residual is being evaluated.
void clearAllDofIndices()
Clear dof indices from variables in nl and aux systems.
virtual void reinitElemFaceRef(const Elem *elem, unsigned int side, Real tolerance, const std::vector< Point > *const pts, const std::vector< Real > *const weights=nullptr, const THREAD_ID tid=0)
reinitialize FE objects on a given element on a given side at a given set of reference points and the...
Definition SubProblem.C:874
virtual const VectorTag & getVectorTag(const TagID tag_id) const
Get a VectorTag from a TagID.
Definition SubProblem.C:153
virtual const std::set< MooseVariableFieldBase * > & getActiveElementalMooseVariables(const THREAD_ID tid) const
Get the MOOSE variables to be reinited on each element.
Definition SubProblem.C:446
std::map< std::string, std::vector< dof_id_type > > _var_dof_map
Definition SubProblem.h:694
virtual void customSetup(const ExecFlagType &exec_type)
virtual void setCurrentBoundaryID(BoundaryID bid, const THREAD_ID tid)
sets the current boundary ID in assembly
Definition SubProblem.C:781
virtual void cacheResidual(const THREAD_ID tid)
virtual void jacobianSetup()
virtual void initialSetup()
virtual void cacheJacobian(const THREAD_ID tid)
Factory & _factory
The Factory for building objects.
std::vector< VectorTag > getVectorTags(const std::set< TagID > &tag_ids) const
Definition SubProblem.C:164
bool doingPRefinement() const
void setCurrentlyComputingJacobian(const bool currently_computing_jacobian)
Set whether or not the problem is in the process of computing the Jacobian.
Definition SubProblem.h:709
void preparePRefinement()
Prepare DofMap and Assembly classes with our p-refinement information.
static InputParameters validParams()
Definition SubProblem.C:34
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid)
Definition SubProblem.C:394
virtual void reinitNeighborFaceRef(const Elem *neighbor_elem, unsigned int neighbor_side, Real tolerance, const std::vector< Point > *const pts, const std::vector< Real > *const weights=nullptr, const THREAD_ID tid=0)
reinitialize FE objects on a given neighbor element on a given side at a given set of reference point...
Definition SubProblem.C:913
std::map< SubdomainID, std::set< MaterialPropertyName > > _zero_block_material_props
Set of properties returned as zero properties.
void addNotZeroedVectorTag(const TagID tag)
Adds a vector tag to the list of vectors that will not be zeroed when other tagged vectors are.
Definition SubProblem.C:141
DiracKernelInfo _dirac_kernel_info
bool _safe_access_tagged_matrices
Is it safe to retrieve data from tagged matrices.
virtual void setActiveFEVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid)
Definition SubProblem.C:355
virtual TagID addVectorTag(const TagName &tag_name, const Moose::VectorTagType type=Moose::VECTOR_TAG_RESIDUAL)
Create a Tag.
Definition SubProblem.C:84
std::unordered_set< TagID > _not_zeroed_tagged_vectors
the list of vector tags that will not be zeroed when all other tags are
static void selectVectorTagsFromSystem(const SystemBase &system, const std::vector< VectorTag > &input_vector_tags, std::set< TagID > &selected_tags)
Select the vector tags which belong to a specific system.
Definition SubProblem.C:281
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid)
Definition SubProblem.C:401
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid)
Definition SubProblem.C:411
std::set< dof_id_type > _ghosted_elems
Elements that should have Dofs ghosted to the local processor.
virtual void setActiveFEVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid)
Definition SubProblem.C:361
virtual void clearActiveElementalMooseVariables(const THREAD_ID tid)
Clear the active elemental MooseVariableFieldBase.
Definition SubProblem.C:458
static void selectMatrixTagsFromSystem(const SystemBase &system, const std::map< TagName, TagID > &input_matrix_tags, std::set< TagID > &selected_tags)
Select the matrix tags which belong to a specific system.
Definition SubProblem.C:292
virtual bool converged(const unsigned int sys_num)
Eventually we want to convert this virtual over to taking a solver system number argument.
Definition SubProblem.h:116
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid)
Definition SubProblem.C:417
virtual void setCurrentLowerDElem(const Elem *const lower_d_elem, const THREAD_ID tid)
Set the current lower dimensional element.
void setCurrentlyComputingResidualAndJacobian(bool currently_computing_residual_and_jacobian)
Set whether or not the problem is in the process of computing the Jacobian.
MooseVariableFieldBase & getVariableHelper(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type, Moose::VarFieldType expected_var_field_type, const std::vector< T > &nls, const SystemBase &aux) const
Helper function called by getVariable that handles the logic for checking whether Variables of the re...
virtual void addCachedResidual(const THREAD_ID tid)
virtual void addCachedJacobian(const THREAD_ID tid)
virtual TagID addMatrixTag(TagName tag_name)
Create a Tag.
Definition SubProblem.C:303
bool _currently_computing_jacobian
Flag to determine whether the problem is currently computing Jacobian.
virtual std::map< TagName, TagID > & getMatrixTags()
Return all matrix tags in the system, where a tag is represented by a map from name to ID.
Definition SubProblem.h:256
virtual void setActiveElementalMooseVariables(const std::set< MooseVariableFieldBase * > &moose_vars, const THREAD_ID tid)
Set the MOOSE variables to be reinited on each element.
Definition SubProblem.C:435
virtual void timestepSetup()
virtual bool vectorTagExists(const TagID tag_id) const
Check to see if a particular Tag exists.
Definition SubProblem.h:204
virtual void cacheResidualNeighbor(const THREAD_ID tid)
void addFunctor(const std::string &name, const Moose::FunctorBase< T > &functor, const THREAD_ID tid)
add a functor to the problem functor container
virtual void residualSetup()
bool _have_ad_objects
AD flag indicating whether any AD objects have been added.
bool automaticScaling() const
Automatic scaling getter.
virtual void reinitLowerDElem(const Elem *lower_d_elem, const THREAD_ID tid, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)
Definition SubProblem.C:972
Base class for a system (of equations)
Definition SystemBase.h:87
virtual libMesh::SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition SystemBase.C:924
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:92
unsigned int number() const
Gets the number of this system.
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Definition SystemBase.C:933
virtual void disassociateMatrixFromTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Disassociate a matrix from a tag.
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
Definition SystemBase.C:981
bool computingScalingJacobian() const
Whether we are computing an initial Jacobian for automatic variable scaling.
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
Definition SystemBase.C:993
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
Definition SystemBase.C:851
virtual void associateMatrixToTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Associate a matrix to a tag.
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
Definition SystemBase.h:391
NumericVector< Number > & solution()
Definition SystemBase.h:215
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const libMesh::ParallelType type)
Adds a solution length vector to the system.
Definition SystemBase.C:608
void update()
Update the system (doing libMesh magic)
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
void max(const T &r, T &o, Request &req) const
void maxloc(T &r, unsigned int &max_id) const
processor_id_type rank() const
void min(const T &r, T &o, Request &req) const
void set_union(T &data, const unsigned int root_id) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
std::vector< T * > & queryInto(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
void add(std::shared_ptr< MooseObject > obj)
add adds a new object to the warehouse and stores attributes/metadata about it for running queries/fi...
An instance of this object type has one copy per thread that runs on each thread.
Base class for all Transfer objects.
Definition Transfer.h:40
@ FROM_MULTIAPP
Definition Transfer.h:71
@ TO_MULTIAPP
Definition Transfer.h:70
@ BETWEEN_MULTIAPP
Definition Transfer.h:72
Base class for user-specific data.
Definition UserObject.h:20
A class for "pretty printing" a table of data.
A ReporterName that represents a VectorPostprocessor.
Base class for Postprocessors that produce a vector of values.
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
virtual void reinit_systems()
const T_sys & get_system(std::string_view name) const
const std::vector< std::string > & get_global_var_names()
const std::vector< std::string > & get_elem_var_names()
const std::vector< std::string > & get_nodal_var_names()
NumericVector< Number > * rhs
SparseMatrix< Number > * matrix
void uniformly_coarsen(unsigned int n=1)
virtual void set(const numeric_index_type i, const T value)=0
virtual void swap(NumericVector< T > &v)
virtual Real l2_norm() const=0
virtual void zero()=0
virtual std::unique_ptr< NumericVector< T > > clone() const=0
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
T & set(const std::string &)
const T & get(std::string_view) const
virtual void zero()=0
virtual void restore_original_nonzero_pattern()
const std::string & name() const
void solve_for_unconstrained_dofs(NumericVector< Number > &, int is_adjoint=-1) const
virtual void reinit()
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int > > variable_numbers=std::nullopt) const
std::unique_ptr< NumericVector< Number > > current_local_solution
const Variable & variable(unsigned int var) const
sys_type & system()
std::unique_ptr< NumericVector< Number > > solution
const std::string & variable_name(const unsigned int i) const
virtual void update()
unsigned int variable_number(std::string_view var) const
bool has_static_condensation() const
bool has_variable(std::string_view var) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
unsigned int n_vars() const
const DofMap & get_dof_map() const
unsigned int number() const
const EquationSystems & get_equation_systems() const
const std::set< subdomain_id_type > & active_subdomains() const
const FEType & type() const
void fill_data(std::map< processor_id_type, std::vector< std::set< unsigned int > > > &data, int M)
query_obj query
MeshBase & mesh
auto max(const L &left, const R &right)
std::string indent(unsigned int spaces)
Create empty string for indenting.
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
libMesh::FEType variableFEType(const InputParameters &params)
Definition MooseUtils.C:98
std::string convertLatestCheckpoint(std::string orig)
Definition MooseUtils.C:220
void parallelBarrierNotify(const Parallel::Communicator &comm, bool messaging)
Definition MooseUtils.C:390
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
A function for setting the PETSc options in PETSc from the options supplied to MOOSE.
void petscSetDefaults(FEProblemBase &problem)
Sets the default options for PETSc.
void setSinglePetscOption(const std::string &name, const std::string &value="", FEProblemBase *const problem=nullptr)
A wrapper function for dealing with different versions of PetscOptionsSetValue.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
bool isSolverExecFlag(const ExecFlagType &exec_flag)
Definition Moose.C:68
@ ST_LINEAR
Solving a linear problem.
Definition MooseTypes.h:907
@ ST_JFNK
Jacobian-Free Newton Krylov.
Definition MooseTypes.h:904
@ VAR_FIELD_STANDARD
Definition MooseTypes.h:782
@ VAR_FIELD_ANY
Definition MooseTypes.h:786
AuxGroup
Flag for AuxKernel related execution type.
Definition MooseTypes.h:763
@ POST_AUX
Definition MooseTypes.h:766
@ PRE_AUX
Definition MooseTypes.h:765
constexpr std::size_t constMaxQpsPerElem
This is used for places where we initialize some qp-sized data structures that would end up being siz...
Definition MooseTypes.h:258
@ LS_NONE
Definition MooseTypes.h:988
@ VECTOR_TAG_SOLUTION
@ VECTOR_TAG_RESIDUAL
@ Iteration
const TagName PREVIOUS_NL_SOLUTION_TAG
Definition MooseTypes.C:28
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:65
RelationshipManagerType
Main types of Relationship Managers.
MaterialDataType
MaterialData types.
Definition MooseTypes.h:751
@ NEIGHBOR_MATERIAL_DATA
Definition MooseTypes.h:755
@ BOUNDARY_MATERIAL_DATA
Definition MooseTypes.h:753
@ INTERFACE_MATERIAL_DATA
Definition MooseTypes.h:756
@ BLOCK_MATERIAL_DATA
Definition MooseTypes.h:752
@ FACE_MATERIAL_DATA
Definition MooseTypes.h:754
SolutionIterationType
Definition MooseTypes.h:270
@ COUPLING_FULL
Definition MooseTypes.h:792
@ COUPLING_DIAG
Definition MooseTypes.h:791
@ COUPLING_CUSTOM
Definition MooseTypes.h:793
VarKindType
Framework-wide stuff.
Definition MooseTypes.h:774
@ VAR_ANY
Definition MooseTypes.h:777
@ VAR_AUXILIARY
Definition MooseTypes.h:776
@ VAR_SOLVER
Definition MooseTypes.h:775
const SubdomainID INVALID_BLOCK_ID
Definition MooseTypes.C:20
bool globalADIndexing()
Whether we are using global AD indexing.
Definition ADUtils.h:28
const TagName SOLUTION_TAG
Definition MooseTypes.C:25
std::vector< ElemQuality > valid(const ElemType t)
const Elem & get(const ElemType type_in)
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
auto index_range(const T &sizable)
const unsigned int invalid_uint
const RemoteElem * remote_elem
RealTensorValue RealTensor
RealVectorValue RealGradient
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int n_threads()
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition MooseError.C:153
Holds app partitioning information relevant to the a particular rank for a multiapp scenario.
Definition MultiApp.h:47
State argument for evaluating functors.
SolutionIterationType iteration_type
The solution iteration type, e.g. time or nonlinear.
unsigned int state
The state.
Per-mortar-interface configuration.