Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://mooseframework.inl.gov
3 : //*
4 : //* All rights reserved, see COPYRIGHT for full restrictions
5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 : //*
7 : //* Licensed under LGPL 2.1, please see LICENSE for details
8 : //* https://www.gnu.org/licenses/lgpl-2.1.html
9 :
10 : #pragma once
11 :
12 : #ifdef MOOSE_KOKKOS_ENABLED
13 : #include "KokkosAssembly.h"
14 : #include "KokkosSystem.h"
15 : #endif
16 :
17 : // MOOSE includes
18 : #include "SubProblem.h"
19 : #include "GeometricSearchData.h"
20 : #include "MeshDivision.h"
21 : #include "ReporterData.h"
22 : #include "Adaptivity.h"
23 : #include "InitialConditionWarehouse.h"
24 : #include "FVInitialConditionWarehouse.h"
25 : #include "ScalarInitialConditionWarehouse.h"
26 : #include "Restartable.h"
27 : #include "SolverParams.h"
28 : #include "PetscSupport.h"
29 : #include "MooseApp.h"
30 : #include "ExecuteMooseObjectWarehouse.h"
31 : #include "MaterialWarehouse.h"
32 : #include "MortarInterfaceWarehouse.h"
33 : #include "MooseVariableFE.h"
34 : #include "MultiAppTransfer.h"
35 : #include "Postprocessor.h"
36 : #include "HashMap.h"
37 : #include "VectorPostprocessor.h"
38 : #include "PerfGraphInterface.h"
39 : #include "Attributes.h"
40 : #include "MooseObjectWarehouse.h"
41 : #include "MaterialPropertyRegistry.h"
42 : #include "RestartableEquationSystems.h"
43 : #include "SolutionInvalidity.h"
44 : #include "PetscSupport.h"
45 :
46 : #include "libmesh/enum_quadrature_type.h"
47 : #include "libmesh/equation_systems.h"
48 :
49 : #include <unordered_map>
50 : #include <memory>
51 :
52 : // Forward declarations
53 : class AuxiliarySystem;
54 : class DisplacedProblem;
55 : class MooseMesh;
56 : class NonlinearSystemBase;
57 : class LinearSystem;
58 : class SolverSystem;
59 : class NonlinearSystem;
60 : class RandomInterface;
61 : class RandomData;
62 : class MeshChangedInterface;
63 : class MeshDisplacedInterface;
64 : class MultiMooseEnum;
65 : class MaterialPropertyStorage;
66 : class MaterialData;
67 : class MooseEnum;
68 : class MortarInterfaceWarehouse;
69 : class Assembly;
70 : class JacobianBlock;
71 : class Control;
72 : class MultiApp;
73 : class TransientMultiApp;
74 : class ScalarInitialCondition;
75 : class Indicator;
76 : class InternalSideIndicatorBase;
77 : class Marker;
78 : class Material;
79 : class Transfer;
80 : class XFEMInterface;
81 : class SideUserObject;
82 : class NodalUserObject;
83 : class ElementUserObject;
84 : class InternalSideUserObject;
85 : class InterfaceUserObject;
86 : class GeneralUserObject;
87 : class Positions;
88 : class Function;
89 : class Distribution;
90 : class Sampler;
91 : class KernelBase;
92 : class IntegratedBCBase;
93 : class LineSearch;
94 : class UserObject;
95 : class UserObjectBase;
96 : class FVInterpolationMethod;
97 : class FVFaceInterpolationMethod;
98 : class FVAdvectedInterpolationMethod;
99 : class AutomaticMortarGeneration;
100 : class VectorPostprocessor;
101 : class Convergence;
102 : class MooseAppCoordTransform;
103 : class MortarUserObject;
104 : class SolutionInvalidity;
105 :
106 : namespace Moose
107 : {
108 : class FunctionBase;
109 : }
110 :
111 : #ifdef MOOSE_KOKKOS_ENABLED
112 : namespace Moose::Kokkos
113 : {
114 : class MaterialPropertyStorage;
115 : class Function;
116 : class UserObject;
117 : }
118 : #endif
119 :
120 : // libMesh forward declarations
121 : namespace libMesh
122 : {
123 : class CouplingMatrix;
124 : class NonlinearImplicitSystem;
125 : class LinearImplicitSystem;
126 : } // namespace libMesh
127 :
128 : enum class MooseLinearConvergenceReason
129 : {
130 : ITERATING = 0,
131 : // CONVERGED_RTOL_NORMAL = 1,
132 : // CONVERGED_ATOL_NORMAL = 9,
133 : CONVERGED_RTOL = 2,
134 : CONVERGED_ATOL = 3,
135 : CONVERGED_ITS = 4,
136 : // CONVERGED_CG_NEG_CURVE = 5,
137 : // CONVERGED_CG_CONSTRAINED = 6,
138 : // CONVERGED_STEP_LENGTH = 7,
139 : // CONVERGED_HAPPY_BREAKDOWN = 8,
140 : DIVERGED_NULL = -2,
141 : // DIVERGED_ITS = -3,
142 : // DIVERGED_DTOL = -4,
143 : // DIVERGED_BREAKDOWN = -5,
144 : // DIVERGED_BREAKDOWN_BICG = -6,
145 : // DIVERGED_NONSYMMETRIC = -7,
146 : // DIVERGED_INDEFINITE_PC = -8,
147 : DIVERGED_NANORINF = -9,
148 : // DIVERGED_INDEFINITE_MAT = -10
149 : DIVERGED_PCSETUP_FAILED = -11
150 : };
151 :
152 : /**
153 : * Specialization of SubProblem for solving nonlinear equations plus auxiliary equations
154 : *
155 : */
156 : class FEProblemBase : public SubProblem, public Restartable
157 : {
158 : public:
159 : static InputParameters validParams();
160 :
161 : FEProblemBase(const InputParameters & parameters);
162 : virtual ~FEProblemBase();
163 :
164 : /**
165 : * @returns Whether the problem was initialized, i.e. whether \p init() has executed
166 : */
167 62126 : [[nodiscard]] bool initialized() const { return _initialized; }
168 :
169 : enum class CoverageCheckMode
170 : {
171 : FALSE,
172 : TRUE,
173 : OFF,
174 : ON,
175 : SKIP_LIST,
176 : ONLY_LIST,
177 : };
178 :
179 1618113 : virtual libMesh::EquationSystems & es() override { return _req.set().es(); }
180 280589305 : virtual MooseMesh & mesh() override { return _mesh; }
181 2179545101 : virtual const MooseMesh & mesh() const override { return _mesh; }
182 : const MooseMesh & mesh(bool use_displaced) const override;
183 : MooseMesh & mesh(bool use_displaced);
184 :
185 : void setCoordSystem(const std::vector<SubdomainName> & blocks, const MultiMooseEnum & coord_sys);
186 : void setAxisymmetricCoordAxis(const MooseEnum & rz_coord_axis);
187 :
188 : /**
189 : * Set the coupling between variables
190 : * TODO: allow user-defined coupling
191 : * @param type Type of coupling
192 : */
193 : void setCoupling(Moose::CouplingType type);
194 :
195 475089 : Moose::CouplingType coupling() const { return _coupling; }
196 :
197 : /**
198 : * Set custom coupling matrix
199 : * @param cm coupling matrix to be set
200 : * @param nl_sys_num which nonlinear system we are setting the coupling matrix for
201 : */
202 : void setCouplingMatrix(std::unique_ptr<libMesh::CouplingMatrix> cm,
203 : const unsigned int nl_sys_num);
204 :
205 : // DEPRECATED METHOD
206 : void setCouplingMatrix(libMesh::CouplingMatrix * cm, const unsigned int nl_sys_num);
207 :
208 : const libMesh::CouplingMatrix * couplingMatrix(const unsigned int nl_sys_num) const override;
209 :
210 : /// Set custom coupling matrix for variables requiring nonlocal contribution
211 : void setNonlocalCouplingMatrix();
212 :
213 : bool
214 : areCoupled(const unsigned int ivar, const unsigned int jvar, const unsigned int nl_sys_num) const;
215 :
216 : /**
217 : * Whether or not MOOSE will perform a user object/auxiliary kernel state check
218 : */
219 : bool hasUOAuxStateCheck() const { return _uo_aux_state_check; }
220 :
221 : /**
222 : * Return a flag to indicate whether we are executing user objects and auxliary kernels for state
223 : * check
224 : * Note: This function can return true only when hasUOAuxStateCheck() returns true, i.e. the check
225 : * has been activated by users through Problem/check_uo_aux_state input parameter.
226 : */
227 3526 : bool checkingUOAuxState() const { return _checking_uo_aux_state; }
228 :
229 : #ifndef NDEBUG
230 : virtual bool checkResidualForNans() const override { return _check_residual_for_nans; }
231 :
232 : /// Setter for residual NaN/Inf checking
233 : void setCheckResidualForNans(bool check_residual_for_nans)
234 : {
235 : _check_residual_for_nans = check_residual_for_nans;
236 : }
237 : #endif
238 :
239 : /**
240 : * Whether to trust the user coupling matrix even if we want to do things like be paranoid and
241 : * create a full coupling matrix. See https://github.com/idaholab/moose/issues/16395 for detailed
242 : * background
243 : */
244 : void trustUserCouplingMatrix();
245 :
246 : std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> &
247 : couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num);
248 : std::vector<std::pair<MooseVariableFEBase *, MooseVariableFEBase *>> &
249 : nonlocalCouplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num);
250 :
251 : virtual bool hasVariable(const std::string & var_name) const override;
252 : // NOTE: hasAuxiliaryVariable defined in parent class
253 : bool hasSolverVariable(const std::string & var_name) const;
254 : using SubProblem::getVariable;
255 : virtual const MooseVariableFieldBase &
256 : getVariable(const THREAD_ID tid,
257 : const std::string & var_name,
258 : Moose::VarKindType expected_var_type = Moose::VarKindType::VAR_ANY,
259 : Moose::VarFieldType expected_var_field_type =
260 : Moose::VarFieldType::VAR_FIELD_ANY) const override;
261 : MooseVariableFieldBase & getActualFieldVariable(const THREAD_ID tid,
262 : const std::string & var_name) override;
263 : virtual MooseVariable & getStandardVariable(const THREAD_ID tid,
264 : const std::string & var_name) override;
265 : virtual VectorMooseVariable & getVectorVariable(const THREAD_ID tid,
266 : const std::string & var_name) override;
267 : virtual ArrayMooseVariable & getArrayVariable(const THREAD_ID tid,
268 : const std::string & var_name) override;
269 :
270 : virtual bool hasScalarVariable(const std::string & var_name) const override;
271 : virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid,
272 : const std::string & var_name) override;
273 : virtual libMesh::System & getSystem(const std::string & var_name) override;
274 :
275 : /// Get the RestartableEquationSystems object
276 : const RestartableEquationSystems & getRestartableEquationSystems() const;
277 :
278 : /**
279 : * Set the MOOSE variables to be reinited on each element.
280 : * @param moose_vars A set of variables that need to be reinited each time reinit() is called.
281 : *
282 : * @param tid The thread id
283 : */
284 : virtual void setActiveElementalMooseVariables(const std::set<MooseVariableFEBase *> & moose_vars,
285 : const THREAD_ID tid) override;
286 :
287 : /**
288 : * Clear the active elemental MooseVariableFEBase. If there are no active variables then they
289 : * will all be reinited. Call this after finishing the computation that was using a restricted set
290 : * of MooseVariableFEBases
291 : *
292 : * @param tid The thread id
293 : */
294 : virtual void clearActiveElementalMooseVariables(const THREAD_ID tid) override;
295 :
296 : virtual void clearActiveFEVariableCoupleableMatrixTags(const THREAD_ID tid) override;
297 :
298 : virtual void clearActiveFEVariableCoupleableVectorTags(const THREAD_ID tid) override;
299 :
300 : virtual void setActiveFEVariableCoupleableVectorTags(std::set<TagID> & vtags,
301 : const THREAD_ID tid) override;
302 :
303 : virtual void setActiveFEVariableCoupleableMatrixTags(std::set<TagID> & mtags,
304 : const THREAD_ID tid) override;
305 :
306 : virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override;
307 :
308 : virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override;
309 :
310 : virtual void setActiveScalarVariableCoupleableVectorTags(std::set<TagID> & vtags,
311 : const THREAD_ID tid) override;
312 :
313 : virtual void setActiveScalarVariableCoupleableMatrixTags(std::set<TagID> & mtags,
314 : const THREAD_ID tid) override;
315 :
316 : virtual void createQRules(libMesh::QuadratureType type,
317 : libMesh::Order order,
318 : libMesh::Order volume_order = libMesh::INVALID_ORDER,
319 : libMesh::Order face_order = libMesh::INVALID_ORDER,
320 : SubdomainID block = Moose::ANY_BLOCK_ID,
321 : bool allow_negative_qweights = true);
322 :
323 : /**
324 : * Increases the element/volume quadrature order for the specified mesh
325 : * block if and only if the current volume quadrature order is lower. This
326 : * can only cause the quadrature level to increase. If volume_order is
327 : * lower than or equal to the current volume/elem quadrature rule order,
328 : * then nothing is done (i.e. this function is idempotent).
329 : */
330 : void bumpVolumeQRuleOrder(libMesh::Order order, SubdomainID block);
331 :
332 : void bumpAllQRuleOrder(libMesh::Order order, SubdomainID block);
333 :
334 : /**
335 : * @return The maximum number of quadrature points in use on any element in this problem.
336 : */
337 : unsigned int getMaxQps() const;
338 :
339 : /**
340 : * @return The maximum order for all scalar variables in this problem's systems.
341 : */
342 : libMesh::Order getMaxScalarOrder() const;
343 :
344 : /**
345 : * @return Flag indicating nonlocal coupling exists or not.
346 : */
347 : void checkNonlocalCoupling();
348 : void checkUserObjectJacobianRequirement(THREAD_ID tid);
349 : void setVariableAllDoFMap(const std::vector<const MooseVariableFEBase *> & moose_vars);
350 :
351 : const std::vector<const MooseVariableFEBase *> &
352 1272 : getUserObjectJacobianVariables(const THREAD_ID tid) const
353 : {
354 1272 : return _uo_jacobian_moose_vars[tid];
355 : }
356 :
357 : virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override;
358 : virtual const Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) const override;
359 :
360 : #ifdef MOOSE_KOKKOS_ENABLED
361 23447 : Moose::Kokkos::Assembly & kokkosAssembly() { return _kokkos_assembly; }
362 : const Moose::Kokkos::Assembly & kokkosAssembly() const { return _kokkos_assembly; }
363 : #endif
364 :
365 : /**
366 : * Returns a list of all the variables in the problem (both from the NL and Aux systems.
367 : */
368 : virtual std::vector<VariableName> getVariableNames();
369 :
370 : void initialSetup() override;
371 : void checkDuplicatePostprocessorVariableNames();
372 : void timestepSetup() override;
373 : void customSetup(const ExecFlagType & exec_type) override;
374 : void residualSetup() override;
375 : void jacobianSetup() override;
376 :
377 : virtual void prepare(const Elem * elem, const THREAD_ID tid) override;
378 : virtual void prepareFace(const Elem * elem, const THREAD_ID tid) override;
379 : virtual void prepare(const Elem * elem,
380 : unsigned int ivar,
381 : unsigned int jvar,
382 : const std::vector<dof_id_type> & dof_indices,
383 : const THREAD_ID tid) override;
384 :
385 : virtual void setCurrentSubdomainID(const Elem * elem, const THREAD_ID tid) override;
386 : virtual void
387 : setNeighborSubdomainID(const Elem * elem, unsigned int side, const THREAD_ID tid) override;
388 : virtual void setNeighborSubdomainID(const Elem * elem, const THREAD_ID tid);
389 : virtual void prepareAssembly(const THREAD_ID tid) override;
390 :
391 : virtual void addGhostedElem(dof_id_type elem_id) override;
392 : virtual void addGhostedBoundary(BoundaryID boundary_id) override;
393 : virtual void ghostGhostedBoundaries() override;
394 :
395 : virtual void sizeZeroes(unsigned int size, const THREAD_ID tid);
396 : virtual bool reinitDirac(const Elem * elem, const THREAD_ID tid) override;
397 :
398 : virtual void reinitElem(const Elem * elem, const THREAD_ID tid) override;
399 : virtual void reinitElemPhys(const Elem * elem,
400 : const std::vector<Point> & phys_points_in_elem,
401 : const THREAD_ID tid) override;
402 : void reinitElemFace(const Elem * elem, unsigned int side, BoundaryID, const THREAD_ID tid);
403 : virtual void reinitElemFace(const Elem * elem, unsigned int side, const THREAD_ID tid) override;
404 : virtual void reinitLowerDElem(const Elem * lower_d_elem,
405 : const THREAD_ID tid,
406 : const std::vector<Point> * const pts = nullptr,
407 : const std::vector<Real> * const weights = nullptr) override;
408 : virtual void reinitNode(const Node * node, const THREAD_ID tid) override;
409 : virtual void reinitNodeFace(const Node * node, BoundaryID bnd_id, const THREAD_ID tid) override;
410 : virtual void reinitNodes(const std::vector<dof_id_type> & nodes, const THREAD_ID tid) override;
411 : virtual void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes,
412 : const THREAD_ID tid) override;
413 : virtual void reinitNeighbor(const Elem * elem, unsigned int side, const THREAD_ID tid) override;
414 : virtual void reinitNeighborPhys(const Elem * neighbor,
415 : unsigned int neighbor_side,
416 : const std::vector<Point> & physical_points,
417 : const THREAD_ID tid) override;
418 : virtual void reinitNeighborPhys(const Elem * neighbor,
419 : const std::vector<Point> & physical_points,
420 : const THREAD_ID tid) override;
421 : virtual void
422 : reinitElemNeighborAndLowerD(const Elem * elem, unsigned int side, const THREAD_ID tid) override;
423 : virtual void reinitScalars(const THREAD_ID tid,
424 : bool reinit_for_derivative_reordering = false) override;
425 : virtual void reinitOffDiagScalars(const THREAD_ID tid) override;
426 :
427 : /// Fills "elems" with the elements that should be looped over for Dirac Kernels
428 : virtual void getDiracElements(std::set<const Elem *> & elems) override;
429 : virtual void clearDiracInfo() override;
430 :
431 : virtual void subdomainSetup(SubdomainID subdomain, const THREAD_ID tid);
432 : virtual void neighborSubdomainSetup(SubdomainID subdomain, const THREAD_ID tid);
433 :
434 : virtual void newAssemblyArray(std::vector<std::shared_ptr<SolverSystem>> & solver_systems);
435 : virtual void initNullSpaceVectors(const InputParameters & parameters,
436 : std::vector<std::shared_ptr<NonlinearSystemBase>> & nl);
437 :
438 : virtual void init() override;
439 : virtual void solve(const unsigned int nl_sys_num);
440 :
441 : #ifdef MOOSE_KOKKOS_ENABLED
442 : /**
443 : * Construct Kokkos assembly and systems and allocate Kokkos material property storages
444 : */
445 : void initKokkos();
446 : #endif
447 :
448 : /**
449 : * Build and solve a linear system
450 : * @param linear_sys_num The number of the linear system (1,..,num. of lin. systems)
451 : * @param po The petsc options for the solve, if not supplied, the defaults are used
452 : */
453 : virtual void solveLinearSystem(const unsigned int linear_sys_num,
454 : const Moose::PetscSupport::PetscOptions * po = nullptr);
455 :
456 : ///@{
457 : /**
458 : * In general, {evaluable elements} >= {local elements} U {algebraic ghosting elements}. That is,
459 : * the number of evaluable elements does NOT necessarily equal to the number of local and
460 : * algebraic ghosting elements. For example, if using a Lagrange basis for all variables,
461 : * if a non-local, non-algebraically-ghosted element is surrounded by neighbors which are
462 : * local or algebraically ghosted, then all the nodal (Lagrange) degrees of freedom associated
463 : * with the non-local, non-algebraically-ghosted element will be evaluable, and hence that
464 : * element will be considered evaluable.
465 : *
466 : * getNonlinearEvaluableElementRange() returns the evaluable element range based on the nonlinear
467 : * system dofmap;
468 : * getAuxliaryEvaluableElementRange() returns the evaluable element range based on the auxiliary
469 : * system dofmap;
470 : * getEvaluableElementRange() returns the element range that is evaluable based on both the
471 : * nonlinear dofmap and the auxliary dofmap.
472 : */
473 : const libMesh::ConstElemRange & getEvaluableElementRange();
474 : const libMesh::ConstElemRange & getNonlinearEvaluableElementRange();
475 : ///@}
476 :
477 : ///@{
478 : /**
479 : * These are the element and nodes that contribute to the jacobian and
480 : * residual for this local processor.
481 : *
482 : * getCurrentAlgebraicElementRange() returns the element range that contributes to the
483 : * system
484 : * getCurrentAlgebraicNodeRange() returns the node range that contributes to the
485 : * system
486 : * getCurrentAlgebraicBndNodeRange returns the boundary node ranges that contributes
487 : * to the system
488 : */
489 : const libMesh::ConstElemRange & getCurrentAlgebraicElementRange();
490 : const libMesh::ConstNodeRange & getCurrentAlgebraicNodeRange();
491 : const ConstBndNodeRange & getCurrentAlgebraicBndNodeRange();
492 : ///@}
493 :
494 : ///@{
495 : /**
496 : * These functions allow setting custom ranges for the algebraic elements, nodes,
497 : * and boundary nodes that contribute to the jacobian and residual for this local
498 : * processor.
499 : *
500 : * setCurrentAlgebraicElementRange() sets the element range that contributes to the
501 : * system. A nullptr will reset the range to use the mesh's range.
502 : *
503 : * setCurrentAlgebraicNodeRange() sets the node range that contributes to the
504 : * system. A nullptr will reset the range to use the mesh's range.
505 : *
506 : * setCurrentAlgebraicBndNodeRange() sets the boundary node range that contributes
507 : * to the system. A nullptr will reset the range to use the mesh's range.
508 : *
509 : * @param range A pointer to the const range object representing the algebraic
510 : * elements, nodes, or boundary nodes.
511 : */
512 : void setCurrentAlgebraicElementRange(libMesh::ConstElemRange * range);
513 : void setCurrentAlgebraicNodeRange(libMesh::ConstNodeRange * range);
514 : void setCurrentAlgebraicBndNodeRange(ConstBndNodeRange * range);
515 : ///@}
516 :
517 : /**
518 : * Set an exception, which is stored at this point by toggling a member variable in
519 : * this class, and which must be followed up with by a call to
520 : * checkExceptionAndStopSolve().
521 : *
522 : * @param message The error message describing the exception, which will get printed
523 : * when checkExceptionAndStopSolve() is called
524 : */
525 : virtual void setException(const std::string & message);
526 :
527 : /**
528 : * Whether or not an exception has occurred.
529 : */
530 471655081 : virtual bool hasException() { return _has_exception; }
531 :
532 : /**
533 : * Check to see if an exception has occurred on any processor and, if possible,
534 : * force the solve to fail, which will result in the time step being cut.
535 : *
536 : * Notes:
537 : * * The exception have be registered by calling setException() prior to calling this.
538 : * * This is collective on MPI, and must be called simultaneously by all processors!
539 : * * If called when the solve can be interruped, it will do so and also throw a
540 : * MooseException, which must be handled.
541 : * * If called at a stage in the execution when the solve cannot be interupted (i.e.,
542 : * there is no solve active), it will generate an error and terminate the application.
543 : * * DO NOT CALL THIS IN A THREADED REGION! This is meant to be called just after a
544 : * threaded section.
545 : *
546 : * @param print_message whether to print a message with exception information
547 : */
548 : virtual void checkExceptionAndStopSolve(bool print_message = true);
549 :
550 : virtual bool solverSystemConverged(const unsigned int solver_sys_num) override;
551 : virtual unsigned int nNonlinearIterations(const unsigned int nl_sys_num) const override;
552 : virtual unsigned int nLinearIterations(const unsigned int nl_sys_num) const override;
553 : virtual Real finalNonlinearResidual(const unsigned int nl_sys_num) const override;
554 : virtual bool computingPreSMOResidual(const unsigned int nl_sys_num) const override;
555 :
556 : /**
557 : * Return solver type as a human readable string
558 : */
559 : virtual std::string solverTypeString(unsigned int solver_sys_num = 0);
560 :
561 : /**
562 : * Returns true if we are in or beyond the initialSetup stage
563 : */
564 72587 : virtual bool startedInitialSetup() { return _started_initial_setup; }
565 :
566 : virtual void onTimestepBegin() override;
567 : virtual void onTimestepEnd() override;
568 :
569 8657682 : virtual Real & time() const { return _time; }
570 977790 : virtual Real & timeOld() const { return _time_old; }
571 1465162 : virtual int & timeStep() const { return _t_step; }
572 12771268 : virtual Real & dt() const { return _dt; }
573 988074 : virtual Real & dtOld() const { return _dt_old; }
574 : /**
575 : * Returns the time associated with the requested \p state
576 : */
577 : Real getTimeFromStateArg(const Moose::StateArg & state) const;
578 :
579 30547 : virtual void transient(bool trans) { _transient = trans; }
580 2139406884 : virtual bool isTransient() const override { return _transient; }
581 :
582 : virtual void addTimeIntegrator(const std::string & type,
583 : const std::string & name,
584 : InputParameters & parameters);
585 : virtual void
586 : addPredictor(const std::string & type, const std::string & name, InputParameters & parameters);
587 :
588 : virtual void copySolutionsBackwards();
589 :
590 : /// Prevents the copy of the solution vector to the old solution vector in each system.
591 : /// Old -> Older is still performed
592 : /// This is useful for MultiApps fixed point iterations
593 : void skipNextForwardSolutionCopyToOld();
594 :
595 : /**
596 : * Advance all of the state holding vectors / datastructures so that we can move to the next
597 : * timestep.
598 : */
599 : virtual void advanceState();
600 :
601 : virtual void restoreSolutions();
602 :
603 : /**
604 : * Allocate vectors and save old solutions into them.
605 : */
606 : virtual void saveOldSolutions();
607 :
608 : /**
609 : * Restore old solutions from the backup vectors and deallocate them.
610 : */
611 : virtual void restoreOldSolutions();
612 :
613 : /**
614 : * Declare that we need up to old (1) or older (2) solution states for a given type of iteration
615 : * @param oldest_needed oldest solution state needed
616 : * @param iteration_type the type of iteration for which old/older states are needed
617 : */
618 : void needSolutionState(unsigned int oldest_needed, Moose::SolutionIterationType iteration_type);
619 :
620 : /**
621 : * Whether we need up to old (1) or older (2) solution states for a given type of iteration
622 : * @param oldest_needed oldest solution state needed
623 : * @param iteration_type the type of iteration for which old/older states are needed
624 : */
625 : bool hasSolutionState(unsigned int state, Moose::SolutionIterationType iteration_type) const;
626 :
627 : /**
628 : * Output the current step.
629 : * Will ensure that everything is in the proper state to be outputted.
630 : * Then tell the OutputWarehouse to do its thing
631 : * @param type The type execution flag (see Moose.h)
632 : */
633 : virtual void outputStep(ExecFlagType type);
634 :
635 : /**
636 : * Method called at the end of the simulation.
637 : */
638 : virtual void postExecute();
639 :
640 : ///@{
641 : /**
642 : * Ability to enable/disable all output calls
643 : *
644 : * This is needed by Multiapps and applications to disable output for cases when
645 : * executioners call other executions and when Multiapps are sub cycling.
646 : */
647 : void allowOutput(bool state);
648 : template <typename T>
649 : void allowOutput(bool state);
650 : ///@}
651 :
652 : /**
653 : * Indicates that the next call to outputStep should be forced
654 : *
655 : * This is needed by the MultiApp system, if forceOutput is called the next call to outputStep,
656 : * regardless of the type supplied to the call, will be executed with EXEC_FORCED.
657 : *
658 : * Forced output will NOT override the allowOutput flag.
659 : */
660 : void forceOutput();
661 :
662 : /**
663 : * Reinitialize PETSc output for proper linear/nonlinear iteration display. This also may be used
664 : * for some PETSc-related solver settings
665 : */
666 : virtual void initPetscOutputAndSomeSolverSettings();
667 :
668 : /**
669 : * Retrieve a writable reference the PETSc options (used by PetscSupport)
670 : */
671 225762 : Moose::PetscSupport::PetscOptions & getPetscOptions() { return _petsc_options; }
672 :
673 : /**
674 : * Output information about the object just added to the problem
675 : */
676 : void logAdd(const std::string & system,
677 : const std::string & name,
678 : const std::string & type,
679 : const InputParameters & params) const;
680 :
681 : // Function /////
682 : virtual void
683 : addFunction(const std::string & type, const std::string & name, InputParameters & parameters);
684 : virtual bool hasFunction(const std::string & name, const THREAD_ID tid = 0);
685 : virtual Function & getFunction(const std::string & name, const THREAD_ID tid = 0);
686 :
687 : #ifdef MOOSE_KOKKOS_ENABLED
688 : /**
689 : * Add a Kokkos function to the problem
690 : * @param type The Kokkos function type
691 : * @param name The Kokkos function name
692 : * @param parameters The Kokkos function input parameters
693 : */
694 : virtual void addKokkosFunction(const std::string & type,
695 : const std::string & name,
696 : InputParameters & parameters);
697 : /**
698 : * Get whether a Kokkos function exists
699 : * @param name The Kokkos function name
700 : * @returns Whether a Kokkos function exists
701 : */
702 : virtual bool hasKokkosFunction(const std::string & name) const;
703 : /**
704 : * Get a Kokkos function in an abstract type
705 : * @param name The Kokkos function name
706 : * @returns The copy of the Kokkos function in the abstract type
707 : */
708 : virtual Moose::Kokkos::Function getKokkosFunction(const std::string & name);
709 : /**
710 : * Get a Kokkos function in a concrete type
711 : * @tparam T The Kokkos function type
712 : * @param name The Kokkos function name
713 : * @returns The reference of the Kokkos function in the concrete type
714 : */
715 : template <typename T>
716 : T & getKokkosFunction(const std::string & name);
717 : #endif
718 :
719 : /// Add a MeshDivision
720 : virtual void
721 : addMeshDivision(const std::string & type, const std::string & name, InputParameters & params);
722 : /// Get a MeshDivision
723 : MeshDivision & getMeshDivision(const std::string & name, const THREAD_ID tid = 0) const;
724 :
725 : /// Adds a Convergence object
726 : virtual void
727 : addConvergence(const std::string & type, const std::string & name, InputParameters & parameters);
728 : /// Gets a Convergence object
729 : virtual Convergence & getConvergence(const std::string & name, const THREAD_ID tid = 0) const;
730 : /// Gets the Convergence objects
731 : virtual const std::vector<std::shared_ptr<Convergence>> &
732 : getConvergenceObjects(const THREAD_ID tid = 0) const;
733 : /// Returns true if the problem has a Convergence object of the given name
734 : virtual bool hasConvergence(const std::string & name, const THREAD_ID tid = 0) const;
735 : /// Returns true if the problem needs to add the default nonlinear convergence
736 61869 : bool needToAddDefaultNonlinearConvergence() const
737 : {
738 61869 : return _need_to_add_default_nonlinear_convergence;
739 : }
740 : /// Returns true if the problem needs to add the default fixed point convergence
741 61860 : bool needToAddDefaultMultiAppFixedPointConvergence() const
742 : {
743 61860 : return _need_to_add_default_multiapp_fixed_point_convergence;
744 : }
745 : /// Returns true if the problem needs to add the default steady-state detection convergence
746 61851 : bool needToAddDefaultSteadyStateConvergence() const
747 : {
748 61851 : return _need_to_add_default_steady_state_convergence;
749 : }
750 : /// Sets _need_to_add_default_nonlinear_convergence to true
751 60010 : void setNeedToAddDefaultNonlinearConvergence()
752 : {
753 60010 : _need_to_add_default_nonlinear_convergence = true;
754 60010 : }
755 : /// Sets _need_to_add_default_multiapp_fixed_point_convergence to true
756 61848 : void setNeedToAddDefaultMultiAppFixedPointConvergence()
757 : {
758 61848 : _need_to_add_default_multiapp_fixed_point_convergence = true;
759 61848 : }
760 : /// Sets _need_to_add_default_steady_state_convergence to true
761 30383 : void setNeedToAddDefaultSteadyStateConvergence()
762 : {
763 30383 : _need_to_add_default_steady_state_convergence = true;
764 30383 : }
765 : /// Returns true if the problem has set the fixed point convergence name
766 61851 : bool hasSetMultiAppFixedPointConvergenceName() const
767 : {
768 61851 : return _multiapp_fixed_point_convergence_name.has_value();
769 : }
770 : /// Returns true if the problem has set the steady-state detection convergence name
771 : bool hasSetSteadyStateConvergenceName() const
772 : {
773 : return _steady_state_convergence_name.has_value();
774 : }
775 : /**
776 : * Adds the default nonlinear Convergence associated with the problem
777 : *
778 : * This is called if the user does not supply 'nonlinear_convergence'.
779 : *
780 : * @param[in] params Parameters to apply to Convergence parameters
781 : */
782 : virtual void addDefaultNonlinearConvergence(const InputParameters & params);
783 : /**
784 : * Returns true if an error will result if the user supplies 'nonlinear_convergence'
785 : *
786 : * Some problems are strongly tied to their convergence, and it does not make
787 : * sense to use any convergence other than their default and additionally
788 : * would be error-prone.
789 : */
790 396 : virtual bool onlyAllowDefaultNonlinearConvergence() const { return false; }
791 : /**
792 : * Adds the default fixed point Convergence associated with the problem
793 : *
794 : * This is called if the user does not supply 'multiapp_fixed_point_convergence'.
795 : *
796 : * @param[in] params Parameters to apply to Convergence parameters
797 : */
798 : void addDefaultMultiAppFixedPointConvergence(const InputParameters & params);
799 : /**
800 : * Adds the default steady-state detection Convergence
801 : *
802 : * This is called if the user does not supply 'steady_state_convergence'.
803 : *
804 : * @param[in] params Parameters to apply to Convergence parameters
805 : */
806 : void addDefaultSteadyStateConvergence(const InputParameters & params);
807 :
808 : /**
809 : * add a MOOSE line search
810 : */
811 0 : virtual void addLineSearch(const InputParameters & /*parameters*/)
812 : {
813 0 : mooseError("Line search not implemented for this problem type yet.");
814 : }
815 :
816 : /**
817 : * execute MOOSE line search
818 : */
819 : virtual void lineSearch();
820 :
821 : /**
822 : * getter for the MOOSE line search
823 : */
824 0 : LineSearch * getLineSearch() override { return _line_search.get(); }
825 :
826 : /**
827 : * The following functions will enable MOOSE to have the capability to import distributions
828 : */
829 : virtual void
830 : addDistribution(const std::string & type, const std::string & name, InputParameters & parameters);
831 : virtual bool hasDistribution(const std::string & name) const;
832 : virtual Distribution & getDistribution(const std::string & name);
833 :
834 : /**
835 : * The following functions will enable MOOSE to have the capability to import Samplers
836 : */
837 : virtual void
838 : addSampler(const std::string & type, const std::string & name, InputParameters & parameters);
839 : virtual Sampler & getSampler(const std::string & name, const THREAD_ID tid = 0);
840 :
841 : // NL /////
842 : NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num);
843 : const NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num) const;
844 : void setCurrentNonlinearSystem(const unsigned int nl_sys_num);
845 : NonlinearSystemBase & currentNonlinearSystem();
846 : const NonlinearSystemBase & currentNonlinearSystem() const;
847 :
848 : virtual const SystemBase & systemBaseNonlinear(const unsigned int sys_num) const override;
849 : virtual SystemBase & systemBaseNonlinear(const unsigned int sys_num) override;
850 :
851 : virtual const SystemBase & systemBaseSolver(const unsigned int sys_num) const override;
852 : virtual SystemBase & systemBaseSolver(const unsigned int sys_num) override;
853 :
854 : virtual const SystemBase & systemBaseAuxiliary() const override;
855 : virtual SystemBase & systemBaseAuxiliary() override;
856 :
857 : virtual NonlinearSystem & getNonlinearSystem(const unsigned int sys_num);
858 :
859 : #ifdef MOOSE_KOKKOS_ENABLED
860 : /**
861 : * Get all Kokkos systems that are associated with MOOSE nonlinear and auxiliary systems
862 : * @returns The array of Kokkos systems
863 : */
864 : ///@{
865 173865 : Moose::Kokkos::Array<Moose::Kokkos::System> & getKokkosSystems() { return _kokkos_systems; }
866 : const Moose::Kokkos::Array<Moose::Kokkos::System> & getKokkosSystems() const
867 : {
868 : return _kokkos_systems;
869 : }
870 : ///@}
871 : /**
872 : * Get the Kokkos system of a specified number that is associated with MOOSE nonlinear and
873 : * auxiliary systems
874 : * @param sys_num The system number
875 : * @returns The Kokkos system
876 : */
877 : ///@{
878 : Moose::Kokkos::System & getKokkosSystem(const unsigned int sys_num);
879 : const Moose::Kokkos::System & getKokkosSystem(const unsigned int sys_num) const;
880 : ///@}
881 : #endif
882 :
883 : /**
884 : * Get constant reference to a system in this problem
885 : * @param sys_num The number of the system
886 : */
887 : virtual const SystemBase & getSystemBase(const unsigned int sys_num) const;
888 :
889 : /**
890 : * Get non-constant reference to a system in this problem
891 : * @param sys_num The number of the system
892 : */
893 : virtual SystemBase & getSystemBase(const unsigned int sys_num);
894 :
895 : /**
896 : * Get non-constant reference to a system in this problem
897 : * @param sys_name The name of the system
898 : */
899 : SystemBase & getSystemBase(const std::string & sys_name);
900 :
901 : /**
902 : * Get non-constant reference to a linear system
903 : * @param sys_num The number of the linear system
904 : */
905 : LinearSystem & getLinearSystem(unsigned int sys_num);
906 :
907 : /**
908 : * Get a constant reference to a linear system
909 : * @param sys_num The number of the linear system
910 : */
911 : const LinearSystem & getLinearSystem(unsigned int sys_num) const;
912 :
913 : /**
914 : * Get non-constant reference to a solver system
915 : * @param sys_num The number of the solver system
916 : */
917 : SolverSystem & getSolverSystem(unsigned int sys_num);
918 :
919 : /**
920 : * Get a constant reference to a solver system
921 : * @param sys_num The number of the solver system
922 : */
923 : const SolverSystem & getSolverSystem(unsigned int sys_num) const;
924 :
925 : /**
926 : * Set the current linear system pointer
927 : * @param sys_num The number of linear system
928 : */
929 : void setCurrentLinearSystem(unsigned int sys_num);
930 :
931 : /// Get a non-constant reference to the current linear system
932 : LinearSystem & currentLinearSystem();
933 : /// Get a constant reference to the current linear system
934 : const LinearSystem & currentLinearSystem() const;
935 :
936 : /**
937 : * Get a constant base class reference to a linear system
938 : * @param sys_num The number of the linear system
939 : */
940 : virtual const SystemBase & systemBaseLinear(unsigned int sys_num) const override;
941 :
942 : /**
943 : * Get a non-constant base class reference to a linear system
944 : * @param sys_num The number of the linear system
945 : */
946 : virtual SystemBase & systemBaseLinear(unsigned int sys_num) override;
947 :
948 : /**
949 : * Canonical method for adding a non-linear variable
950 : * @param var_type the type of the variable, e.g. MooseVariableScalar
951 : * @param var_name the variable name, e.g. 'u'
952 : * @param params the InputParameters from which to construct the variable
953 : */
954 : virtual void
955 : addVariable(const std::string & var_type, const std::string & var_name, InputParameters & params);
956 :
957 : virtual void addKernel(const std::string & kernel_name,
958 : const std::string & name,
959 : InputParameters & parameters);
960 : virtual void addHDGKernel(const std::string & kernel_name,
961 : const std::string & name,
962 : InputParameters & parameters);
963 : virtual void addNodalKernel(const std::string & kernel_name,
964 : const std::string & name,
965 : InputParameters & parameters);
966 : virtual void addScalarKernel(const std::string & kernel_name,
967 : const std::string & name,
968 : InputParameters & parameters);
969 : virtual void addBoundaryCondition(const std::string & bc_name,
970 : const std::string & name,
971 : InputParameters & parameters);
972 :
973 : #ifdef MOOSE_KOKKOS_ENABLED
974 : virtual void addKokkosKernel(const std::string & kernel_name,
975 : const std::string & name,
976 : InputParameters & parameters);
977 : virtual void addKokkosNodalKernel(const std::string & kernel_name,
978 : const std::string & name,
979 : InputParameters & parameters);
980 : virtual void addKokkosBoundaryCondition(const std::string & bc_name,
981 : const std::string & name,
982 : InputParameters & parameters);
983 : #endif
984 :
985 : virtual void
986 : addConstraint(const std::string & c_name, const std::string & name, InputParameters & parameters);
987 :
988 1729231 : virtual void setInputParametersFEProblem(InputParameters & parameters)
989 : {
990 3458462 : parameters.set<FEProblemBase *>("_fe_problem_base") = this;
991 1729231 : }
992 :
993 : // Aux /////
994 :
995 : /**
996 : * Canonical method for adding an auxiliary variable
997 : * @param var_type the type of the variable, e.g. MooseVariableScalar
998 : * @param var_name the variable name, e.g. 'u'
999 : * @param params the InputParameters from which to construct the variable
1000 : */
1001 : virtual void addAuxVariable(const std::string & var_type,
1002 : const std::string & var_name,
1003 : InputParameters & params);
1004 :
1005 : /**
1006 : * Add an elemental field variable for use in the adaptivity system
1007 : */
1008 : virtual void addElementalFieldVariable(const std::string & var_type,
1009 : const std::string & var_name,
1010 : InputParameters & params);
1011 :
1012 : virtual void addAuxVariable(const std::string & var_name,
1013 : const libMesh::FEType & type,
1014 : const std::set<SubdomainID> * const active_subdomains = NULL);
1015 : virtual void addAuxArrayVariable(const std::string & var_name,
1016 : const libMesh::FEType & type,
1017 : unsigned int components,
1018 : const std::set<SubdomainID> * const active_subdomains = NULL);
1019 : virtual void addAuxScalarVariable(const std::string & var_name,
1020 : libMesh::Order order,
1021 : Real scale_factor = 1.,
1022 : const std::set<SubdomainID> * const active_subdomains = NULL);
1023 : virtual void addAuxKernel(const std::string & kernel_name,
1024 : const std::string & name,
1025 : InputParameters & parameters);
1026 : virtual void addAuxScalarKernel(const std::string & kernel_name,
1027 : const std::string & name,
1028 : InputParameters & parameters);
1029 :
1030 : #ifdef MOOSE_KOKKOS_ENABLED
1031 : virtual void addKokkosAuxKernel(const std::string & kernel_name,
1032 : const std::string & name,
1033 : InputParameters & parameters);
1034 : #endif
1035 :
1036 4927632 : AuxiliarySystem & getAuxiliarySystem() { return *_aux; }
1037 :
1038 : // Dirac /////
1039 : virtual void addDiracKernel(const std::string & kernel_name,
1040 : const std::string & name,
1041 : InputParameters & parameters);
1042 :
1043 : // DG /////
1044 : virtual void addDGKernel(const std::string & kernel_name,
1045 : const std::string & name,
1046 : InputParameters & parameters);
1047 : // FV /////
1048 : virtual void addFVKernel(const std::string & kernel_name,
1049 : const std::string & name,
1050 : InputParameters & parameters);
1051 :
1052 : virtual void addLinearFVKernel(const std::string & kernel_name,
1053 : const std::string & name,
1054 : InputParameters & parameters);
1055 : virtual void
1056 : addFVBC(const std::string & fv_bc_name, const std::string & name, InputParameters & parameters);
1057 : virtual void addLinearFVBC(const std::string & fv_bc_name,
1058 : const std::string & name,
1059 : InputParameters & parameters);
1060 :
1061 : virtual void addFVInterfaceKernel(const std::string & fv_ik_name,
1062 : const std::string & name,
1063 : InputParameters & parameters);
1064 :
1065 : // Interface /////
1066 : virtual void addInterfaceKernel(const std::string & kernel_name,
1067 : const std::string & name,
1068 : InputParameters & parameters);
1069 :
1070 : // IC /////
1071 : virtual void addInitialCondition(const std::string & ic_name,
1072 : const std::string & name,
1073 : InputParameters & parameters);
1074 : /**
1075 : * Add an initial condition for a finite volume variables
1076 : * @param ic_name The name of the boundary condition object
1077 : * @param name The user-defined name from the input file
1078 : * @param parameters The input parameters for construction
1079 : */
1080 : virtual void addFVInitialCondition(const std::string & ic_name,
1081 : const std::string & name,
1082 : InputParameters & parameters);
1083 :
1084 : void projectSolution();
1085 :
1086 : /**
1087 : * Retrieves the current initial condition state.
1088 : * @return current initial condition state
1089 : */
1090 : unsigned short getCurrentICState();
1091 :
1092 : /**
1093 : * Project initial conditions for custom \p elem_range and \p bnd_node_range
1094 : * This is needed when elements/boundary nodes are added to a specific subdomain
1095 : * at an intermediate step
1096 : * @param elem_range Element range to project on
1097 : * @param bnd_node_range Boundary node range to project on
1098 : * @param target_vars Set of variable names to project ICs
1099 : */
1100 : void projectInitialConditionOnCustomRange(
1101 : libMesh::ConstElemRange & elem_range,
1102 : ConstBndNodeRange & bnd_node_range,
1103 : const std::optional<std::set<VariableName>> & target_vars = std::nullopt);
1104 :
1105 : /**
1106 : * Project a function onto a range of elements for a given variable
1107 : *
1108 : * \param elem_range Element range to project on
1109 : * \param func Function to project
1110 : * \param func_grad Gradient of the function
1111 : * \param params Parameters to pass to the function
1112 : * \param target_vars variable names to project
1113 : */
1114 : void projectFunctionOnCustomRange(ConstElemRange & elem_range,
1115 : Number (*func)(const Point &,
1116 : const libMesh::Parameters &,
1117 : const std::string &,
1118 : const std::string &),
1119 : Gradient (*func_grad)(const Point &,
1120 : const libMesh::Parameters &,
1121 : const std::string &,
1122 : const std::string &),
1123 : const libMesh::Parameters & params,
1124 : const std::vector<VariableName> & target_vars);
1125 :
1126 : // Materials
1127 : virtual void addMaterial(const std::string & material_name,
1128 : const std::string & name,
1129 : InputParameters & parameters);
1130 : virtual void addMaterialHelper(std::vector<MaterialWarehouse *> warehouse,
1131 : const std::string & material_name,
1132 : const std::string & name,
1133 : InputParameters & parameters);
1134 : virtual void addInterfaceMaterial(const std::string & material_name,
1135 : const std::string & name,
1136 : InputParameters & parameters);
1137 : virtual void addFunctorMaterial(const std::string & functor_material_name,
1138 : const std::string & name,
1139 : InputParameters & parameters);
1140 :
1141 : #ifdef MOOSE_KOKKOS_ENABLED
1142 : virtual void addKokkosMaterial(const std::string & material_name,
1143 : const std::string & name,
1144 : InputParameters & parameters);
1145 : #endif
1146 :
1147 : /**
1148 : * Add the MooseVariables and the material properties that the current materials depend on to the
1149 : * dependency list.
1150 : * @param consumer_needed_mat_props The material properties needed by consumer objects (other than
1151 : * the materials themselves)
1152 : * @param blk_id The subdomain ID for which we are preparing our list of needed vars and props
1153 : * @param tid The thread ID we are preparing the requirements for
1154 : *
1155 : * This MUST be done after the moose variable dependency list has been set for all the other
1156 : * objects using the \p setActiveElementalMooseVariables API!
1157 : */
1158 : void prepareMaterials(const std::unordered_set<unsigned int> & consumer_needed_mat_props,
1159 : const SubdomainID blk_id,
1160 : const THREAD_ID tid);
1161 :
1162 : void reinitMaterials(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful = true);
1163 :
1164 : /**
1165 : * reinit materials on element faces
1166 : * @param blk_id The subdomain on which the element owning the face lives
1167 : * @param tid The thread id
1168 : * @param swap_stateful Whether to swap stateful material properties between \p MaterialData and
1169 : * \p MaterialPropertyStorage
1170 : * @param reinit_mats specific list of materials to reinit. Used notably in the context of mortar
1171 : * with stateful elements
1172 : */
1173 : void reinitMaterialsFace(SubdomainID blk_id,
1174 : const THREAD_ID tid,
1175 : bool swap_stateful = true,
1176 : const std::deque<MaterialBase *> * reinit_mats = nullptr);
1177 :
1178 : /**
1179 : * reinit materials on element faces on a boundary (internal or external)
1180 : * This specific routine helps us not reinit when don't need to
1181 : * @param boundary_id The boundary on which the face belongs
1182 : * @param blk_id The block id to which the element (who owns the face) belong
1183 : * @param tid The thread id
1184 : * @param swap_stateful Whether to swap stateful material properties between \p MaterialData and
1185 : * \p MaterialPropertyStorage
1186 : * @param reinit_mats specific list of materials to reinit. Used notably in the context of mortar
1187 : * with stateful elements
1188 : */
1189 : void
1190 : reinitMaterialsFaceOnBoundary(const BoundaryID boundary_id,
1191 : const SubdomainID blk_id,
1192 : const THREAD_ID tid,
1193 : const bool swap_stateful = true,
1194 : const std::deque<MaterialBase *> * const reinit_mats = nullptr);
1195 :
1196 : /**
1197 : * reinit materials on neighbor element (usually faces) on a boundary (internal or external)
1198 : * This specific routine helps us not reinit when don't need to
1199 : * @param boundary_id The boundary on which the face belongs
1200 : * @param blk_id The block id to which the element (who owns the face) belong
1201 : * @param tid The thread id
1202 : * @param swap_stateful Whether to swap stateful material properties between \p MaterialData and
1203 : * \p MaterialPropertyStorage
1204 : * @param reinit_mats specific list of materials to reinit. Used notably in the context of mortar
1205 : * with stateful elements
1206 : */
1207 : void
1208 : reinitMaterialsNeighborOnBoundary(const BoundaryID boundary_id,
1209 : const SubdomainID blk_id,
1210 : const THREAD_ID tid,
1211 : const bool swap_stateful = true,
1212 : const std::deque<MaterialBase *> * const reinit_mats = nullptr);
1213 :
1214 : /**
1215 : * reinit materials on the neighboring element face
1216 : * @param blk_id The subdomain on which the neighbor element lives
1217 : * @param tid The thread id
1218 : * @param swap_stateful Whether to swap stateful material properties between \p MaterialData and
1219 : * \p MaterialPropertyStorage
1220 : * @param reinit_mats specific list of materials to reinit. Used notably in the context of mortar
1221 : * with stateful elements
1222 : */
1223 : void reinitMaterialsNeighbor(SubdomainID blk_id,
1224 : const THREAD_ID tid,
1225 : bool swap_stateful = true,
1226 : const std::deque<MaterialBase *> * reinit_mats = nullptr);
1227 :
1228 : /**
1229 : * reinit materials on a boundary
1230 : * @param boundary_id The boundary on which to reinit corresponding materials
1231 : * @param tid The thread id
1232 : * @param swap_stateful Whether to swap stateful material properties between \p MaterialData and
1233 : * \p MaterialPropertyStorage
1234 : * @param execute_stateful Whether to execute material objects that have stateful properties.
1235 : * This should be \p false when for example executing material objects for mortar contexts in
1236 : * which stateful properties don't make sense
1237 : * @param reinit_mats specific list of materials to reinit. Used notably in the context of mortar
1238 : * with stateful elements
1239 : */
1240 : void reinitMaterialsBoundary(BoundaryID boundary_id,
1241 : const THREAD_ID tid,
1242 : bool swap_stateful = true,
1243 : const std::deque<MaterialBase *> * reinit_mats = nullptr);
1244 :
1245 : void
1246 : reinitMaterialsInterface(BoundaryID boundary_id, const THREAD_ID tid, bool swap_stateful = true);
1247 :
1248 : #ifdef MOOSE_KOKKOS_ENABLED
1249 : void prepareKokkosMaterials(const std::unordered_set<unsigned int> & consumer_needed_mat_props);
1250 : void reinitKokkosMaterials();
1251 : #endif
1252 :
1253 : /*
1254 : * Swap back underlying data storing stateful material properties
1255 : */
1256 : virtual void swapBackMaterials(const THREAD_ID tid);
1257 : virtual void swapBackMaterialsFace(const THREAD_ID tid);
1258 : virtual void swapBackMaterialsNeighbor(const THREAD_ID tid);
1259 :
1260 : /**
1261 : * Record and set the material properties required by the current computing thread.
1262 : * @param mat_prop_ids The set of material properties required by the current computing thread.
1263 : *
1264 : * @param tid The thread id
1265 : */
1266 : void setActiveMaterialProperties(const std::unordered_set<unsigned int> & mat_prop_ids,
1267 : const THREAD_ID tid);
1268 :
1269 : /**
1270 : * Method to check whether or not a list of active material roperties has been set. This method
1271 : * is called by reinitMaterials to determine whether Material computeProperties methods need to be
1272 : * called. If the return is False, this check prevents unnecessary material property computation
1273 : * @param tid The thread id
1274 : *
1275 : * @return True if there has been a list of active material properties set, False otherwise
1276 : */
1277 : bool hasActiveMaterialProperties(const THREAD_ID tid) const;
1278 :
1279 : /**
1280 : * Clear the active material properties. Should be called at the end of every computing thread
1281 : *
1282 : * @param tid The thread id
1283 : */
1284 : void clearActiveMaterialProperties(const THREAD_ID tid);
1285 :
1286 : /**
1287 : * Method for creating and adding an object to the warehouse.
1288 : *
1289 : * @tparam T The base object type (registered in the Factory)
1290 : * @param type String type of the object (registered in the Factory)
1291 : * @param name Name for the object to be created
1292 : * @param parameters InputParameters for the object
1293 : * @param threaded Whether or not to create n_threads copies of the object
1294 : * @param var_param_name The name of the parameter on the object which holds the primary variable.
1295 : * @return A vector of shared_ptrs to the added objects
1296 : */
1297 : template <typename T>
1298 : std::vector<std::shared_ptr<T>> addObject(const std::string & type,
1299 : const std::string & name,
1300 : InputParameters & parameters,
1301 : const bool threaded = true,
1302 : const std::string & var_param_name = "variable");
1303 :
1304 : // Postprocessors /////
1305 : virtual void addPostprocessor(const std::string & pp_name,
1306 : const std::string & name,
1307 : InputParameters & parameters);
1308 :
1309 : // VectorPostprocessors /////
1310 : virtual void addVectorPostprocessor(const std::string & pp_name,
1311 : const std::string & name,
1312 : InputParameters & parameters);
1313 :
1314 : /**
1315 : * Add a Reporter object to the simulation.
1316 : * @param type C++ object type to construct
1317 : * @param name A uniquely identifying object name
1318 : * @param parameters Complete parameters for the object to be created.
1319 : *
1320 : * For an example use, refer to AddReporterAction.C/h
1321 : */
1322 : virtual void
1323 : addReporter(const std::string & type, const std::string & name, InputParameters & parameters);
1324 :
1325 : #ifdef MOOSE_KOKKOS_ENABLED
1326 : virtual void addKokkosPostprocessor(const std::string & pp_name,
1327 : const std::string & name,
1328 : InputParameters & parameters);
1329 : virtual void addKokkosVectorPostprocessor(const std::string & pp_name,
1330 : const std::string & name,
1331 : InputParameters & parameters);
1332 : virtual void addKokkosReporter(const std::string & type,
1333 : const std::string & name,
1334 : InputParameters & parameters);
1335 : #endif
1336 :
1337 : /**
1338 : * Provides const access the ReporterData object.
1339 : *
1340 : * NOTE: There is a private non-const version of this function that uses a key object only
1341 : * constructable by the correct interfaces. This was done by design to encourage the use of
1342 : * the Reporter and ReporterInterface classes.
1343 : */
1344 782607 : const ReporterData & getReporterData() const { return _reporter_data; }
1345 :
1346 : /**
1347 : * Provides non-const access the ReporterData object that is used to store reporter values.
1348 : *
1349 : * see ReporterData.h
1350 : */
1351 148081 : ReporterData & getReporterData(ReporterData::WriteKey /*key*/) { return _reporter_data; }
1352 :
1353 : // UserObjects /////
1354 : virtual std::vector<std::shared_ptr<UserObject>> addUserObject(
1355 : const std::string & user_object_name, const std::string & name, InputParameters & parameters);
1356 :
1357 : /**
1358 : * Get the user object by its name
1359 : * @param name The name of the user object being retrieved
1360 : * @return Reference to the user object
1361 : */
1362 : template <class T>
1363 29535 : T & getUserObject(const std::string & name, unsigned int tid = 0) const
1364 : {
1365 29535 : std::vector<T *> objs;
1366 29535 : theWarehouse()
1367 : .query()
1368 59070 : .condition<AttribSystem>("UserObject")
1369 29535 : .condition<AttribThread>(tid)
1370 29535 : .condition<AttribName>(name)
1371 29535 : .queryInto(objs);
1372 29535 : if (objs.empty())
1373 0 : mooseError("Unable to find user object with name '" + name + "'");
1374 59070 : return *(objs[0]);
1375 29535 : }
1376 :
1377 : /**
1378 : * Get the user object by its name
1379 : * @param name The name of the user object being retrieved
1380 : * @param tid The thread of the user object (defaults to 0)
1381 : * @return Const reference to the user object
1382 : */
1383 : const UserObject & getUserObjectBase(const std::string & name, const THREAD_ID tid = 0) const;
1384 :
1385 : /**
1386 : * Check if there if a user object of given name
1387 : * @param name The name of the user object being checked for
1388 : * @return true if the user object exists, false otherwise
1389 : */
1390 : bool hasUserObject(const std::string & name) const;
1391 :
1392 : #ifdef MOOSE_KOKKOS_ENABLED
1393 : virtual void addKokkosUserObject(const std::string & user_object_name,
1394 : const std::string & name,
1395 : InputParameters & parameters);
1396 :
1397 : /**
1398 : * Get the Kokkos user object by its name
1399 : * @param name The name of the Kokkos user object being retrieved
1400 : * @return const reference to the Kokkos user object
1401 : */
1402 : template <class T>
1403 0 : const T & getKokkosUserObject(const std::string & name) const
1404 : {
1405 0 : std::vector<T *> objs;
1406 0 : theWarehouse()
1407 : .query()
1408 0 : .condition<AttribSystem>("KokkosUserObject")
1409 0 : .condition<AttribName>(name)
1410 0 : .queryInto(objs);
1411 0 : if (objs.empty())
1412 0 : mooseError("Unable to find Kokkos user object with name '" + name + "'");
1413 0 : return *(objs[0]);
1414 0 : }
1415 :
1416 : /**
1417 : * Check if there if a Kokkos user object of given name
1418 : * @param name The name of the Kokkos user object being checked for
1419 : * @return true if the Kokkos user object exists, false otherwise
1420 : */
1421 : bool hasKokkosUserObject(const std::string & name) const;
1422 : #endif
1423 :
1424 : /**
1425 : * Check for name collision between different user objects
1426 : * @param name The object name being added
1427 : * @param type The object type being added
1428 : */
1429 : void checkUserObjectNameCollision(const std::string & name, const std::string & type) const;
1430 :
1431 : /**
1432 : * Get the Positions object by its name
1433 : * @param name The name of the Positions object being retrieved
1434 : * @return Const reference to the Positions object
1435 : */
1436 : const Positions & getPositionsObject(const std::string & name) const;
1437 :
1438 : /**
1439 : * Add an FV interpolation method
1440 : * @param method_type The type of the method.
1441 : * @param name The name of the method.
1442 : * @param parameters The input parameters of the method.
1443 : */
1444 : virtual void addFVInterpolationMethod(const std::string & method_type,
1445 : const std::string & name,
1446 : InputParameters & parameters);
1447 :
1448 : /**
1449 : * Retrieve an FV interpolation method
1450 : * @param name The name of the method.
1451 : * @param tid The thread ID.
1452 : */
1453 : const FVInterpolationMethod & getFVInterpolationMethod(const InterpolationMethodName & name,
1454 : const THREAD_ID tid = 0) const;
1455 :
1456 : /**
1457 : * Retrieve a scalar face interpolation method.
1458 : * @param name The name of the method.
1459 : * @param tid The thread ID.
1460 : */
1461 : const FVFaceInterpolationMethod &
1462 : getFVFaceInterpolationMethod(const InterpolationMethodName & name, const THREAD_ID tid = 0) const;
1463 :
1464 : /**
1465 : * Retrieve an advected interpolation method.
1466 : * @param name The name of the method.
1467 : * @param tid The thread ID.
1468 : */
1469 : const FVAdvectedInterpolationMethod &
1470 : getFVAdvectedInterpolationMethod(const InterpolationMethodName & name,
1471 : const THREAD_ID tid = 0) const;
1472 :
1473 : /**
1474 : * Check if an FV interpolation method with a given name exists
1475 : */
1476 : bool hasFVInterpolationMethod(const InterpolationMethodName & name) const;
1477 :
1478 : /**
1479 : * Whether or not a Postprocessor value exists by a given name.
1480 : * @param name The name of the Postprocessor
1481 : * @return True if a Postprocessor value exists
1482 : *
1483 : * Note: You should prioritize the use of PostprocessorInterface::hasPostprocessor
1484 : * and PostprocessorInterface::hasPostprocessorByName over this method when possible.
1485 : */
1486 : bool hasPostprocessorValueByName(const PostprocessorName & name) const;
1487 :
1488 : /**
1489 : * Return the Postprocessor object registered under the supplied object name.
1490 : * @param object_name The name of the Postprocessor object
1491 : * @param tid The thread identifier for thread-local object lookup
1492 : */
1493 : const Postprocessor & getPostprocessorObjectByName(const PostprocessorName & object_name,
1494 : const THREAD_ID tid = 0) const;
1495 :
1496 : /**
1497 : * Get a read-only reference to the value associated with a Postprocessor that exists.
1498 : * @param name The name of the post-processor
1499 : * @param t_index Flag for getting current (0), old (1), or older (2) values
1500 : * @return The reference to the value at the given time index
1501 : *
1502 : * Note: This method is only for retrieving values that already exist, the Postprocessor and
1503 : * PostprocessorInterface objects should be used rather than this method for creating
1504 : * and getting values within objects.
1505 : */
1506 : const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName & name,
1507 : std::size_t t_index = 0) const;
1508 :
1509 : /**
1510 : * Set the value of a PostprocessorValue.
1511 : * @param name The name of the post-processor
1512 : * @param t_index Flag for getting current (0), old (1), or older (2) values
1513 : * @return The reference to the value at the given time index
1514 : *
1515 : * Note: This method is only for setting values that already exist, the Postprocessor and
1516 : * PostprocessorInterface objects should be used rather than this method for creating
1517 : * and getting values within objects.
1518 : *
1519 : * WARNING!
1520 : * This method should be used with caution. It exists to allow Transfers and other
1521 : * similar objects to modify Postprocessor values. It is not intended for general use.
1522 : */
1523 : void setPostprocessorValueByName(const PostprocessorName & name,
1524 : const PostprocessorValue & value,
1525 : std::size_t t_index = 0);
1526 :
1527 : /**
1528 : * Deprecated. Use hasPostprocessorValueByName
1529 : */
1530 : bool hasPostprocessor(const std::string & name) const;
1531 :
1532 : /**
1533 : * Get a read-only reference to the vector value associated with the VectorPostprocessor.
1534 : * @param object_name The name of the VPP object.
1535 : * @param vector_name The namve of the decalred vector within the object.
1536 : * @return Referent to the vector of data.
1537 : *
1538 : * Note: This method is only for retrieving values that already exist, the VectorPostprocessor and
1539 : * VectorPostprocessorInterface objects should be used rather than this method for creating
1540 : * and getting values within objects.
1541 : */
1542 : const VectorPostprocessorValue &
1543 : getVectorPostprocessorValueByName(const std::string & object_name,
1544 : const std::string & vector_name,
1545 : std::size_t t_index = 0) const;
1546 :
1547 : /**
1548 : * Set the value of a VectorPostprocessor vector
1549 : * @param object_name The name of the VPP object
1550 : * @param vector_name The name of the declared vector
1551 : * @param value The data to apply to the vector
1552 : * @param t_index Flag for getting current (0), old (1), or older (2) values
1553 : */
1554 : void setVectorPostprocessorValueByName(const std::string & object_name,
1555 : const std::string & vector_name,
1556 : const VectorPostprocessorValue & value,
1557 : std::size_t t_index = 0);
1558 :
1559 : /**
1560 : * Return the VPP object given the name.
1561 : * @param object_name The name of the VPP object
1562 : * @return Desired VPP object
1563 : *
1564 : * This is used by various output objects as well as the scatter value handling.
1565 : * @see CSV.C, XMLOutput.C, VectorPostprocessorInterface.C
1566 : */
1567 : const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string & object_name,
1568 : const THREAD_ID tid = 0) const;
1569 :
1570 : ///@{
1571 : /**
1572 : * Returns whether or not the current simulation has any multiapps
1573 : */
1574 794 : bool hasMultiApps() const { return _multi_apps.hasActiveObjects(); }
1575 : bool hasMultiApps(ExecFlagType type) const;
1576 : bool hasMultiApp(const std::string & name) const;
1577 : ///@}
1578 :
1579 : // Dampers /////
1580 : virtual void addDamper(const std::string & damper_name,
1581 : const std::string & name,
1582 : InputParameters & parameters);
1583 : void setupDampers();
1584 :
1585 : /**
1586 : * Whether or not this system has dampers.
1587 : */
1588 348676 : bool hasDampers() { return _has_dampers; }
1589 :
1590 : // Indicators /////
1591 : virtual void addIndicator(const std::string & indicator_name,
1592 : const std::string & name,
1593 : InputParameters & parameters);
1594 :
1595 : // Markers //////
1596 : virtual void addMarker(const std::string & marker_name,
1597 : const std::string & name,
1598 : InputParameters & parameters);
1599 :
1600 : /**
1601 : * Add a MultiApp to the problem.
1602 : */
1603 : virtual void addMultiApp(const std::string & multi_app_name,
1604 : const std::string & name,
1605 : InputParameters & parameters);
1606 :
1607 : /**
1608 : * Get a MultiApp object by name.
1609 : */
1610 : std::shared_ptr<MultiApp> getMultiApp(const std::string & multi_app_name) const;
1611 :
1612 : /**
1613 : * Get Transfers by ExecFlagType and direction
1614 : */
1615 : std::vector<std::shared_ptr<Transfer>> getTransfers(ExecFlagType type,
1616 : Transfer::DIRECTION direction) const;
1617 : std::vector<std::shared_ptr<Transfer>> getTransfers(Transfer::DIRECTION direction) const;
1618 :
1619 : /**
1620 : * Return the complete warehouse for MultiAppTransfer object for the given direction
1621 : */
1622 : const ExecuteMooseObjectWarehouse<Transfer> &
1623 : getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const;
1624 :
1625 : /**
1626 : * Execute MultiAppTransfers associated with execution flag and direction.
1627 : * @param type The execution flag to execute.
1628 : * @param direction The direction (to or from) to transfer.
1629 : */
1630 : void execMultiAppTransfers(ExecFlagType type, Transfer::DIRECTION direction);
1631 :
1632 : /**
1633 : * Execute the MultiApps associated with the ExecFlagType
1634 : */
1635 : bool execMultiApps(ExecFlagType type, bool auto_advance = true);
1636 :
1637 : void finalizeMultiApps();
1638 :
1639 : /**
1640 : * Advance the MultiApps t_step (incrementStepOrReject) associated with the ExecFlagType
1641 : */
1642 : void incrementMultiAppTStep(ExecFlagType type);
1643 :
1644 : /**
1645 : * Deprecated method; use finishMultiAppStep and/or incrementMultiAppTStep depending
1646 : * on your purpose
1647 : */
1648 : void advanceMultiApps(ExecFlagType type)
1649 : {
1650 : mooseDeprecated("Deprecated method; use finishMultiAppStep and/or incrementMultiAppTStep "
1651 : "depending on your purpose");
1652 : finishMultiAppStep(type);
1653 : }
1654 :
1655 : /**
1656 : * Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType. Optionally
1657 : * recurse through all multi-app levels
1658 : */
1659 : void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels = false);
1660 :
1661 : /**
1662 : * Backup the MultiApps associated with the ExecFlagType
1663 : */
1664 : void backupMultiApps(ExecFlagType type);
1665 :
1666 : /**
1667 : * Restore the MultiApps associated with the ExecFlagType
1668 : * @param force Force restoration because something went wrong with the solve
1669 : */
1670 : void restoreMultiApps(ExecFlagType type, bool force = false);
1671 :
1672 : /**
1673 : * Find the smallest timestep over all MultiApps
1674 : */
1675 : Real computeMultiAppsDT(ExecFlagType type);
1676 :
1677 : /**
1678 : * Add a Transfer to the problem.
1679 : */
1680 : virtual void addTransfer(const std::string & transfer_name,
1681 : const std::string & name,
1682 : InputParameters & parameters);
1683 :
1684 : /**
1685 : * Execute the Transfers associated with the ExecFlagType
1686 : *
1687 : * Note: This does _not_ execute MultiApp Transfers!
1688 : * Those are executed automatically when MultiApps are executed.
1689 : */
1690 : void execTransfers(ExecFlagType type);
1691 :
1692 : /**
1693 : * Computes the residual of a nonlinear system using whatever is sitting in the current
1694 : * solution vector then returns the L2 norm.
1695 : */
1696 : Real computeResidualL2Norm(NonlinearSystemBase & sys);
1697 :
1698 : /**
1699 : * Computes the residual of a linear system using whatever is sitting in the current
1700 : * solution vector then returns the L2 norm.
1701 : */
1702 : Real computeResidualL2Norm(LinearSystem & sys);
1703 :
1704 : /**
1705 : * Computes the residual using whatever is sitting in the current solution vector then returns the
1706 : * L2 norm.
1707 : *
1708 : * @return The L2 norm of the residual
1709 : */
1710 : virtual Real computeResidualL2Norm();
1711 :
1712 : /**
1713 : * This function is called by Libmesh to form a residual.
1714 : */
1715 : virtual void computeResidualSys(libMesh::NonlinearImplicitSystem & sys,
1716 : const NumericVector<libMesh::Number> & soln,
1717 : NumericVector<libMesh::Number> & residual);
1718 : /**
1719 : * This function is called by Libmesh to form a residual. This is deprecated.
1720 : * We should remove this as soon as RattleSnake is fixed.
1721 : */
1722 : void computeResidual(libMesh::NonlinearImplicitSystem & sys,
1723 : const NumericVector<libMesh::Number> & soln,
1724 : NumericVector<libMesh::Number> & residual);
1725 :
1726 : /**
1727 : * Form a residual with default tags (nontime, time, residual).
1728 : */
1729 : virtual void computeResidual(const NumericVector<libMesh::Number> & soln,
1730 : NumericVector<libMesh::Number> & residual,
1731 : const unsigned int nl_sys_num);
1732 :
1733 : /**
1734 : * Form a residual and Jacobian with default tags
1735 : */
1736 : void computeResidualAndJacobian(const NumericVector<libMesh::Number> & soln,
1737 : NumericVector<libMesh::Number> & residual,
1738 : libMesh::SparseMatrix<libMesh::Number> & jacobian);
1739 :
1740 : /**
1741 : * Form a residual vector for a given tag
1742 : */
1743 : virtual void computeResidualTag(const NumericVector<libMesh::Number> & soln,
1744 : NumericVector<libMesh::Number> & residual,
1745 : TagID tag);
1746 : /**
1747 : * Form a residual vector for a given tag and "residual" tag
1748 : */
1749 : virtual void computeResidualType(const NumericVector<libMesh::Number> & soln,
1750 : NumericVector<libMesh::Number> & residual,
1751 : TagID tag);
1752 :
1753 : /**
1754 : * Form a residual vector for a set of tags. It should not be called directly
1755 : * by users.
1756 : */
1757 : virtual void computeResidualInternal(const NumericVector<libMesh::Number> & soln,
1758 : NumericVector<libMesh::Number> & residual,
1759 : const std::set<TagID> & tags);
1760 : /**
1761 : * Form multiple residual vectors and each is associated with one tag
1762 : */
1763 : virtual void computeResidualTags(const std::set<TagID> & tags);
1764 :
1765 : /**
1766 : * Form a Jacobian matrix. It is called by Libmesh.
1767 : */
1768 : virtual void computeJacobianSys(libMesh::NonlinearImplicitSystem & sys,
1769 : const NumericVector<libMesh::Number> & soln,
1770 : libMesh::SparseMatrix<libMesh::Number> & jacobian);
1771 : /**
1772 : * Form a Jacobian matrix with the default tag (system).
1773 : */
1774 : virtual void computeJacobian(const NumericVector<libMesh::Number> & soln,
1775 : libMesh::SparseMatrix<libMesh::Number> & jacobian,
1776 : const unsigned int nl_sys_num);
1777 :
1778 : /**
1779 : * Form a Jacobian matrix for a given tag.
1780 : */
1781 : virtual void computeJacobianTag(const NumericVector<libMesh::Number> & soln,
1782 : libMesh::SparseMatrix<libMesh::Number> & jacobian,
1783 : TagID tag);
1784 :
1785 : /**
1786 : * Form a Jacobian matrix for multiple tags. It should not be called directly by users.
1787 : */
1788 : virtual void computeJacobianInternal(const NumericVector<libMesh::Number> & soln,
1789 : libMesh::SparseMatrix<libMesh::Number> & jacobian,
1790 : const std::set<TagID> & tags);
1791 :
1792 : /**
1793 : * Form multiple matrices, and each is associated with a tag.
1794 : */
1795 : virtual void computeJacobianTags(const std::set<TagID> & tags);
1796 :
1797 : /**
1798 : * Computes several Jacobian blocks simultaneously, summing their contributions into smaller
1799 : * preconditioning matrices.
1800 : *
1801 : * Used by Physics-based preconditioning
1802 : *
1803 : * @param blocks The blocks to fill in (JacobianBlock is defined in ComputeJacobianBlocksThread)
1804 : */
1805 : virtual void computeJacobianBlocks(std::vector<JacobianBlock *> & blocks,
1806 : const unsigned int nl_sys_num);
1807 :
1808 : /**
1809 : * Really not a good idea to use this.
1810 : *
1811 : * It computes just one block of the Jacobian into a smaller matrix. Calling this in a loop is
1812 : * EXTREMELY ineffecient!
1813 : * Try to use computeJacobianBlocks() instead!
1814 : *
1815 : * @param jacobian The matrix you want to fill
1816 : * @param precond_system The libMesh::system of the preconditioning system
1817 : * @param ivar the block-row of the Jacobian
1818 : * @param jvar the block-column of the Jacobian
1819 : *
1820 : */
1821 : virtual void computeJacobianBlock(libMesh::SparseMatrix<libMesh::Number> & jacobian,
1822 : libMesh::System & precond_system,
1823 : unsigned int ivar,
1824 : unsigned int jvar);
1825 :
1826 : /**
1827 : * Assemble both the right hand side and the system matrix of a given linear
1828 : * system.
1829 : * @param sys The linear system which should be assembled
1830 : * @param system_matrix The sparse matrix which should hold the system matrix
1831 : * @param rhs The vector which should hold the right hand side
1832 : * @param compute_gradients A flag to disable the computation of new gradients during the
1833 : * assembly, can be used to lag gradients
1834 : */
1835 : virtual void computeLinearSystemSys(libMesh::LinearImplicitSystem & sys,
1836 : libMesh::SparseMatrix<libMesh::Number> & system_matrix,
1837 : NumericVector<libMesh::Number> & rhs,
1838 : const bool compute_gradients = true);
1839 :
1840 : /**
1841 : * Assemble the current linear system given a set of vector and matrix tags.
1842 : *
1843 : * @param soln The solution which should be used for the system assembly
1844 : * @param vector_tags The vector tags for the right hand side
1845 : * @param matrix_tags The matrix tags for the matrix
1846 : * @param compute_gradients A flag to disable the computation of new gradients during the
1847 : * assembly, can be used to lag gradients
1848 : */
1849 : void computeLinearSystemTags(const NumericVector<libMesh::Number> & soln,
1850 : const std::set<TagID> & vector_tags,
1851 : const std::set<TagID> & matrix_tags,
1852 : const bool compute_gradients = true);
1853 :
1854 : virtual Real computeDamping(const NumericVector<libMesh::Number> & soln,
1855 : const NumericVector<libMesh::Number> & update);
1856 :
1857 : /**
1858 : * Check to see whether the problem should update the solution
1859 : * @return true if the problem should update the solution, false otherwise
1860 : */
1861 : virtual bool shouldUpdateSolution();
1862 :
1863 : /**
1864 : * Update the solution
1865 : * @param vec_solution Local solution vector that gets modified by this method
1866 : * @param ghosted_solution Ghosted solution vector
1867 : * @return true if the solution was modified, false otherwise
1868 : */
1869 : virtual bool updateSolution(NumericVector<libMesh::Number> & vec_solution,
1870 : NumericVector<libMesh::Number> & ghosted_solution);
1871 :
1872 : /**
1873 : * Perform cleanup tasks after application of predictor to solution vector
1874 : * @param ghosted_solution Ghosted solution vector
1875 : */
1876 : virtual void predictorCleanup(NumericVector<libMesh::Number> & ghosted_solution);
1877 :
1878 : virtual void computeBounds(libMesh::NonlinearImplicitSystem & sys,
1879 : NumericVector<libMesh::Number> & lower,
1880 : NumericVector<libMesh::Number> & upper);
1881 : virtual void computeNearNullSpace(libMesh::NonlinearImplicitSystem & sys,
1882 : std::vector<NumericVector<libMesh::Number> *> & sp);
1883 : virtual void computeNullSpace(libMesh::NonlinearImplicitSystem & sys,
1884 : std::vector<NumericVector<libMesh::Number> *> & sp);
1885 : virtual void computeTransposeNullSpace(libMesh::NonlinearImplicitSystem & sys,
1886 : std::vector<NumericVector<libMesh::Number> *> & sp);
1887 : virtual void computePostCheck(libMesh::NonlinearImplicitSystem & sys,
1888 : const NumericVector<libMesh::Number> & old_soln,
1889 : NumericVector<libMesh::Number> & search_direction,
1890 : NumericVector<libMesh::Number> & new_soln,
1891 : bool & changed_search_direction,
1892 : bool & changed_new_soln);
1893 :
1894 : virtual void computeIndicatorsAndMarkers();
1895 : virtual void computeIndicators();
1896 : virtual void computeMarkers();
1897 :
1898 : virtual void addResidual(const THREAD_ID tid) override;
1899 : virtual void addResidualNeighbor(const THREAD_ID tid) override;
1900 : virtual void addResidualLower(const THREAD_ID tid) override;
1901 : virtual void addResidualScalar(const THREAD_ID tid = 0);
1902 :
1903 : virtual void cacheResidual(const THREAD_ID tid) override;
1904 : virtual void cacheResidualNeighbor(const THREAD_ID tid) override;
1905 : virtual void addCachedResidual(const THREAD_ID tid) override;
1906 :
1907 : /**
1908 : * Allows for all the residual contributions that are currently cached to be added directly into
1909 : * the vector passed in.
1910 : *
1911 : * @param residual The vector to add the cached contributions to.
1912 : * @param tid The thread id.
1913 : */
1914 : virtual void addCachedResidualDirectly(NumericVector<libMesh::Number> & residual,
1915 : const THREAD_ID tid);
1916 :
1917 : virtual void setResidual(NumericVector<libMesh::Number> & residual, const THREAD_ID tid) override;
1918 : virtual void setResidualNeighbor(NumericVector<libMesh::Number> & residual,
1919 : const THREAD_ID tid) override;
1920 :
1921 : virtual void addJacobian(const THREAD_ID tid) override;
1922 : virtual void addJacobianNeighbor(const THREAD_ID tid) override;
1923 : virtual void addJacobianNeighborLowerD(const THREAD_ID tid) override;
1924 : virtual void addJacobianLowerD(const THREAD_ID tid) override;
1925 : virtual void addJacobianBlockTags(libMesh::SparseMatrix<libMesh::Number> & jacobian,
1926 : unsigned int ivar,
1927 : unsigned int jvar,
1928 : const DofMap & dof_map,
1929 : std::vector<dof_id_type> & dof_indices,
1930 : const std::set<TagID> & tags,
1931 : const THREAD_ID tid);
1932 : virtual void addJacobianNeighbor(libMesh::SparseMatrix<libMesh::Number> & jacobian,
1933 : unsigned int ivar,
1934 : unsigned int jvar,
1935 : const DofMap & dof_map,
1936 : std::vector<dof_id_type> & dof_indices,
1937 : std::vector<dof_id_type> & neighbor_dof_indices,
1938 : const std::set<TagID> & tags,
1939 : const THREAD_ID tid) override;
1940 : virtual void addJacobianScalar(const THREAD_ID tid = 0);
1941 : virtual void addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid = 0);
1942 :
1943 : virtual void cacheJacobian(const THREAD_ID tid) override;
1944 : virtual void cacheJacobianNeighbor(const THREAD_ID tid) override;
1945 : virtual void addCachedJacobian(const THREAD_ID tid) override;
1946 :
1947 : virtual void prepareShapes(unsigned int var, const THREAD_ID tid) override;
1948 : virtual void prepareFaceShapes(unsigned int var, const THREAD_ID tid) override;
1949 : virtual void prepareNeighborShapes(unsigned int var, const THREAD_ID tid) override;
1950 :
1951 : // Displaced problem /////
1952 : virtual void addDisplacedProblem(std::shared_ptr<DisplacedProblem> displaced_problem);
1953 0 : virtual std::shared_ptr<const DisplacedProblem> getDisplacedProblem() const
1954 : {
1955 0 : return _displaced_problem;
1956 : }
1957 4351805 : virtual std::shared_ptr<DisplacedProblem> getDisplacedProblem() { return _displaced_problem; }
1958 :
1959 : /**
1960 : * Update this object's geometric search data as well as the displaced problem's if it exists
1961 : */
1962 : virtual void updateGeomSearch(
1963 : GeometricSearchData::GeometricSearchType type = GeometricSearchData::ALL) override;
1964 : virtual void updateMortarMesh();
1965 :
1966 : void createMortarInterface(
1967 : const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
1968 : const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
1969 : bool on_displaced,
1970 : bool periodic,
1971 : const bool debug,
1972 : const bool correct_edge_dropping,
1973 : const Real minimum_projection_angle,
1974 : const MooseEnum & triangulation,
1975 : const bool triangulate_triangles);
1976 :
1977 : /**
1978 : * Return the undisplaced or displaced mortar generation object associated with the provided
1979 : * boundaries and subdomains
1980 : */
1981 : ///@{
1982 : const AutomaticMortarGeneration &
1983 : getMortarInterface(const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
1984 : const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
1985 : bool on_displaced) const;
1986 :
1987 : AutomaticMortarGeneration &
1988 : getMortarInterface(const std::pair<BoundaryID, BoundaryID> & primary_secondary_boundary_pair,
1989 : const std::pair<SubdomainID, SubdomainID> & primary_secondary_subdomain_pair,
1990 : bool on_displaced);
1991 : ///@}
1992 :
1993 : const std::unordered_map<std::pair<BoundaryID, BoundaryID>, MortarInterfaceConfig> &
1994 : getMortarInterfaces(bool on_displaced) const;
1995 :
1996 : virtual void possiblyRebuildGeomSearchPatches();
1997 :
1998 615208 : virtual GeometricSearchData & geomSearchData() override { return _geometric_search_data; }
1999 :
2000 : /**
2001 : * Communicate to the Resurector the name of the restart filer
2002 : * @param file_name The file name for restarting from
2003 : */
2004 : void setRestartFile(const std::string & file_name);
2005 :
2006 : /**
2007 : * @return A reference to the material property registry
2008 : */
2009 2 : const MaterialPropertyRegistry & getMaterialPropertyRegistry() const
2010 : {
2011 2 : return _material_prop_registry;
2012 : }
2013 :
2014 : /**
2015 : * Return a reference to the material property storage
2016 : * @return A const reference to the material property storage
2017 : */
2018 : ///@{
2019 13 : const MaterialPropertyStorage & getMaterialPropertyStorage() { return _material_props; }
2020 : const MaterialPropertyStorage & getBndMaterialPropertyStorage() { return _bnd_material_props; }
2021 : const MaterialPropertyStorage & getNeighborMaterialPropertyStorage()
2022 : {
2023 : return _neighbor_material_props;
2024 : }
2025 :
2026 : #ifdef MOOSE_KOKKOS_ENABLED
2027 : Moose::Kokkos::MaterialPropertyStorage & getKokkosMaterialPropertyStorage()
2028 : {
2029 : return _kokkos_material_props;
2030 : }
2031 : Moose::Kokkos::MaterialPropertyStorage & getKokkosBndMaterialPropertyStorage()
2032 : {
2033 : return _kokkos_bnd_material_props;
2034 : }
2035 : Moose::Kokkos::MaterialPropertyStorage & getKokkosNeighborMaterialPropertyStorage()
2036 : {
2037 : return _kokkos_neighbor_material_props;
2038 : }
2039 : #endif
2040 : ///@}
2041 :
2042 : /**
2043 : * Return indicator/marker storage.
2044 : */
2045 : ///@{
2046 4750 : const MooseObjectWarehouse<Indicator> & getIndicatorWarehouse() { return _indicators; }
2047 4750 : const MooseObjectWarehouse<InternalSideIndicatorBase> & getInternalSideIndicatorWarehouse()
2048 : {
2049 4750 : return _internal_side_indicators;
2050 : }
2051 6513 : const MooseObjectWarehouse<Marker> & getMarkerWarehouse() { return _markers; }
2052 : ///@}
2053 :
2054 : /**
2055 : * Return InitialCondition storage
2056 : */
2057 4426022 : const InitialConditionWarehouse & getInitialConditionWarehouse() const { return _ics; }
2058 :
2059 : /**
2060 : * Return FVInitialCondition storage
2061 : */
2062 7905 : const FVInitialConditionWarehouse & getFVInitialConditionWarehouse() const { return _fv_ics; }
2063 :
2064 : /**
2065 : * Get the solver parameters
2066 : */
2067 : SolverParams & solverParams(unsigned int solver_sys_num = 0);
2068 :
2069 : /**
2070 : * const version
2071 : */
2072 : const SolverParams & solverParams(unsigned int solver_sys_num = 0) const;
2073 :
2074 : #ifdef LIBMESH_ENABLE_AMR
2075 : // Adaptivity /////
2076 157992 : Adaptivity & adaptivity() { return _adaptivity; }
2077 : virtual void initialAdaptMesh();
2078 :
2079 : /**
2080 : * @returns Whether or not the mesh was changed
2081 : */
2082 : virtual bool adaptMesh();
2083 :
2084 : /**
2085 : * @return The number of adaptivity cycles completed.
2086 : */
2087 168 : unsigned int getNumCyclesCompleted() { return _cycles_completed; }
2088 :
2089 : /**
2090 : * Return a Boolean indicating whether initial AMR is turned on.
2091 : */
2092 : bool hasInitialAdaptivity() const { return _adaptivity.getInitialSteps() > 0; }
2093 : #else
2094 : /**
2095 : * Return a Boolean indicating whether initial AMR is turned on.
2096 : */
2097 : bool hasInitialAdaptivity() const { return false; }
2098 : #endif // LIBMESH_ENABLE_AMR
2099 :
2100 : /// Create XFEM controller object
2101 : void initXFEM(std::shared_ptr<XFEMInterface> xfem);
2102 :
2103 : /// Get a pointer to the XFEM controller object
2104 : std::shared_ptr<XFEMInterface> getXFEM() { return _xfem; }
2105 :
2106 : /// Find out whether the current analysis is using XFEM
2107 1222971 : bool haveXFEM() { return _xfem != nullptr; }
2108 :
2109 : /// Update the mesh due to changing XFEM cuts
2110 : virtual bool updateMeshXFEM();
2111 :
2112 : /**
2113 : * Update data after a mesh change.
2114 : * Iff intermediate_change is true, only perform updates as
2115 : * necessary to prepare for another mesh change
2116 : * immediately-subsequent. An example of data that is not updated during an intermediate change is
2117 : * libMesh System matrix data. An example of data that \emph is updated during an intermediate
2118 : * change is libMesh System vectors. These vectors are projected or restricted based off of
2119 : * adaptive mesh refinement or the changing of element subdomain IDs. The flags \p contract_mesh
2120 : * and \p clean_refinement_flags should generally only be set to true when the mesh has changed
2121 : * due to mesh refinement. \p contract_mesh deletes children of coarsened elements and renumbers
2122 : * nodes and elements. \p clean_refinement_flags resets refinement flags such that any subsequent
2123 : * calls to \p System::restrict_vectors or \p System::prolong_vectors before another AMR step do
2124 : * not mistakenly attempt to re-do the restriction/prolongation which occurred in this method
2125 : */
2126 : virtual void
2127 : meshChanged(bool intermediate_change, bool contract_mesh, bool clean_refinement_flags);
2128 :
2129 : /**
2130 : * Register an object that derives from MeshChangedInterface
2131 : * to be notified when the mesh changes.
2132 : */
2133 : void notifyWhenMeshChanges(MeshChangedInterface * mci);
2134 :
2135 : /**
2136 : * Register an object that derives from MeshDisplacedInterface
2137 : * to be notified when the displaced mesh gets updated.
2138 : */
2139 : void notifyWhenMeshDisplaces(MeshDisplacedInterface * mdi);
2140 :
2141 : /**
2142 : * Initialize stateful properties for elements in a specific \p elem_range
2143 : * This is needed when elements/boundary nodes are added to a specific subdomain
2144 : * at an intermediate step
2145 : */
2146 : void initElementStatefulProps(const libMesh::ConstElemRange & elem_range, const bool threaded);
2147 :
2148 : #ifdef MOOSE_KOKKOS_ENABLED
2149 : void initKokkosStatefulProps();
2150 : #endif
2151 :
2152 : /**
2153 : * Method called to perform a series of sanity checks before a simulation is run. This method
2154 : * doesn't return when errors are found, instead it generally calls mooseError() directly.
2155 : */
2156 : virtual void checkProblemIntegrity();
2157 :
2158 : void registerRandomInterface(RandomInterface & random_interface, const std::string & name);
2159 :
2160 : /**
2161 : * Set flag that Jacobian is constant (for optimization purposes)
2162 : * @param state True if the Jacobian is constant, false otherwise
2163 : */
2164 4189 : void setConstJacobian(bool state) { _const_jacobian = state; }
2165 :
2166 : /**
2167 : * Set flag to indicate whether kernel coverage checks should be performed. This check makes
2168 : * sure that at least one kernel is active on all subdomains in the domain (default: true).
2169 : */
2170 : void setKernelCoverageCheck(CoverageCheckMode mode) { _kernel_coverage_check = mode; }
2171 :
2172 : /**
2173 : * Set flag to indicate whether kernel coverage checks should be performed. This check makes
2174 : * sure that at least one kernel is active on all subdomains in the domain (default: true).
2175 : */
2176 : void setKernelCoverageCheck(bool flag)
2177 : {
2178 : _kernel_coverage_check = flag ? CoverageCheckMode::TRUE : CoverageCheckMode::FALSE;
2179 : }
2180 :
2181 : /**
2182 : * Set flag to indicate whether material coverage checks should be performed. This check makes
2183 : * sure that at least one material is active on all subdomains in the domain if any material is
2184 : * supplied. If no materials are supplied anywhere, a simulation is still considered OK as long as
2185 : * no properties are being requested anywhere.
2186 : */
2187 : void setMaterialCoverageCheck(CoverageCheckMode mode) { _material_coverage_check = mode; }
2188 :
2189 : /**
2190 : * Set flag to indicate whether material coverage checks should be performed. This check makes
2191 : * sure that at least one material is active on all subdomains in the domain if any material is
2192 : * supplied. If no materials are supplied anywhere, a simulation is still considered OK as long as
2193 : * no properties are being requested anywhere.
2194 : */
2195 : void setMaterialCoverageCheck(bool flag)
2196 : {
2197 : _material_coverage_check = flag ? CoverageCheckMode::TRUE : CoverageCheckMode::FALSE;
2198 : }
2199 :
2200 : /**
2201 : * Toggle parallel barrier messaging (defaults to on).
2202 : */
2203 : void setParallelBarrierMessaging(bool flag) { _parallel_barrier_messaging = flag; }
2204 :
2205 : /// Make the problem be verbose
2206 : void setVerboseProblem(bool verbose);
2207 :
2208 : /**
2209 : * Whether or not to use verbose printing for MultiApps.
2210 : */
2211 208043 : bool verboseMultiApps() const { return _verbose_multiapps; }
2212 :
2213 : /**
2214 : * Calls parentOutputPositionChanged() on all sub apps.
2215 : */
2216 : void parentOutputPositionChanged();
2217 :
2218 : ///@{
2219 : /**
2220 : * These methods are used to determine whether stateful material properties need to be stored on
2221 : * internal sides. There are five situations where this may be the case: 1) DGKernels
2222 : * 2) IntegratedBCs 3)InternalSideUserObjects 4)ElementalAuxBCs 5)InterfaceUserObjects
2223 : *
2224 : * Method 1:
2225 : * @param bnd_id the boundary id for which to see if stateful material properties need to be
2226 : * stored
2227 : * @param tid the THREAD_ID of the caller
2228 : * @return Boolean indicating whether material properties need to be stored
2229 : *
2230 : * Method 2:
2231 : * @param subdomain_id the subdomain id for which to see if stateful material properties need to
2232 : * be stored
2233 : * @param tid the THREAD_ID of the caller
2234 : * @return Boolean indicating whether material properties need to be stored
2235 : */
2236 : bool needBoundaryMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid);
2237 : bool needInterfaceMaterialOnSide(BoundaryID bnd_id, const THREAD_ID tid);
2238 : bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, const THREAD_ID tid);
2239 : ///@}
2240 :
2241 : /**
2242 : * Dimension of the subspace spanned by vectors with a given prefix.
2243 : * @param prefix Prefix of the vectors spanning the subspace.
2244 : */
2245 887511 : unsigned int subspaceDim(const std::string & prefix) const
2246 : {
2247 887511 : if (_subspace_dim.count(prefix))
2248 887511 : return _subspace_dim.find(prefix)->second;
2249 : else
2250 0 : return 0;
2251 : }
2252 :
2253 : /*
2254 : * Return reference to function warehouse.
2255 : */
2256 2 : const MooseObjectWarehouse<Function> & getFunctionWarehouse() { return _functions; }
2257 :
2258 : /*
2259 : * Return a reference to the material warehouse of *all* Material objects.
2260 : */
2261 4910793 : const MaterialWarehouse & getMaterialWarehouse() const { return _all_materials; }
2262 :
2263 : /*
2264 : * Return a reference to the material warehouse of Material objects to be computed.
2265 : */
2266 11397 : const MaterialWarehouse & getRegularMaterialsWarehouse() const { return _materials; }
2267 10149 : const MaterialWarehouse & getDiscreteMaterialWarehouse() const { return _discrete_materials; }
2268 11335 : const MaterialWarehouse & getInterfaceMaterialsWarehouse() const { return _interface_materials; }
2269 :
2270 : #ifdef MOOSE_KOKKOS_ENABLED
2271 : /*
2272 : * Return a reference to the material warehouse of Kokkos Material objects to be computed.
2273 : */
2274 45978 : const MaterialWarehouse & getKokkosMaterialsWarehouse() const { return _kokkos_materials; }
2275 : #endif
2276 :
2277 : /**
2278 : * Return a pointer to a MaterialBase object. If no_warn is true, suppress
2279 : * warning about retrieving a material reference potentially during the
2280 : * material's calculation.
2281 : *
2282 : * This will return enabled or disabled objects, the main purpose is for iterative materials.
2283 : */
2284 : std::shared_ptr<MaterialBase> getMaterial(std::string name,
2285 : Moose::MaterialDataType type,
2286 : const THREAD_ID tid = 0,
2287 : bool no_warn = false);
2288 :
2289 : /**
2290 : * @return The MaterialData for the type \p type for thread \p tid
2291 : */
2292 : MaterialData & getMaterialData(Moose::MaterialDataType type,
2293 : const THREAD_ID tid = 0,
2294 : const MooseObject * object = nullptr) const;
2295 :
2296 : #ifdef MOOSE_KOKKOS_ENABLED
2297 : /**
2298 : * @return The Kokkos MaterialData for the type \p type for thread \p tid
2299 : */
2300 : MaterialData & getKokkosMaterialData(Moose::MaterialDataType type,
2301 : const MooseObject * object = nullptr) const;
2302 : #endif
2303 :
2304 : /**
2305 : * @return The consumers of the MaterialPropertyStorage for the type \p type
2306 : */
2307 : const std::set<const MooseObject *> &
2308 : getMaterialPropertyStorageConsumers(Moose::MaterialDataType type) const;
2309 :
2310 : #ifdef MOOSE_KOKKOS_ENABLED
2311 : /**
2312 : * @return The consumers of the Kokkos MaterialPropertyStorage for the type \p type
2313 : */
2314 : const std::set<const MooseObject *> &
2315 : getKokkosMaterialPropertyStorageConsumers(Moose::MaterialDataType type) const;
2316 : #endif
2317 :
2318 : /**
2319 : * @returns Whether the original matrix nonzero pattern is restored before each Jacobian assembly
2320 : */
2321 474447 : bool restoreOriginalNonzeroPattern() const { return _restore_original_nonzero_pattern; }
2322 :
2323 : /**
2324 : * Will return True if the user wants to get an error when
2325 : * a nonzero is reallocated in the Jacobian by PETSc
2326 : */
2327 517276 : bool errorOnJacobianNonzeroReallocation() const
2328 : {
2329 517276 : return _error_on_jacobian_nonzero_reallocation;
2330 : }
2331 :
2332 240 : void setErrorOnJacobianNonzeroReallocation(bool state)
2333 : {
2334 240 : _error_on_jacobian_nonzero_reallocation = state;
2335 240 : }
2336 :
2337 : /**
2338 : * Will return True if the executioner in use requires preserving the sparsity pattern of the
2339 : * matrices being formed during the solve. This is usually the Jacobian.
2340 : */
2341 : bool preserveMatrixSparsityPattern() const { return _preserve_matrix_sparsity_pattern; };
2342 :
2343 : /// Set whether the sparsity pattern of the matrices being formed during the solve (usually the Jacobian)
2344 : /// should be preserved. This global setting can be retrieved by kernels, notably those using AD, to decide
2345 : /// whether to take additional care to preserve the sparsity pattern
2346 : void setPreserveMatrixSparsityPattern(bool preserve);
2347 :
2348 : /**
2349 : * Will return true if zeros in the Jacobian are to be dropped from the sparsity pattern.
2350 : * Note that this can make preserving the matrix sparsity pattern impossible.
2351 : */
2352 490293 : bool ignoreZerosInJacobian() const { return _ignore_zeros_in_jacobian; }
2353 :
2354 : /// Set whether the zeros in the Jacobian should be dropped from the sparsity pattern
2355 : void setIgnoreZerosInJacobian(bool state) { _ignore_zeros_in_jacobian = state; }
2356 :
2357 : /**
2358 : * Whether or not to accept the solution based on its invalidity.
2359 : *
2360 : * If this returns false, it means that an invalid solution was encountered
2361 : * (an error) that was not allowed.
2362 : */
2363 : bool acceptInvalidSolution() const;
2364 : /**
2365 : * Whether to accept / allow an invalid solution
2366 : */
2367 310251 : bool allowInvalidSolution() const { return _allow_invalid_solution; }
2368 :
2369 : /**
2370 : * Whether or not to print out the invalid solutions summary table in console
2371 : */
2372 626 : bool showInvalidSolutionConsole() const { return _show_invalid_solution_console; }
2373 :
2374 : /**
2375 : * Whether or not the solution invalid warnings are printed out immediately
2376 : */
2377 31152 : bool immediatelyPrintInvalidSolution() const { return _immediately_print_invalid_solution; }
2378 :
2379 : /// Returns whether or not this Problem has a TimeIntegrator
2380 31083 : bool hasTimeIntegrator() const { return _has_time_integrator; }
2381 :
2382 : ///@{
2383 : /**
2384 : * Return/set the current execution flag.
2385 : *
2386 : * Returns EXEC_NONE when not being executed.
2387 : * @see FEProblemBase::execute
2388 : */
2389 : const ExecFlagType & getCurrentExecuteOnFlag() const;
2390 : void setCurrentExecuteOnFlag(const ExecFlagType &);
2391 : ///@}
2392 :
2393 : /**
2394 : * Convenience function for performing execution of MOOSE systems.
2395 : */
2396 : virtual void execute(const ExecFlagType & exec_type);
2397 : virtual void executeAllObjects(const ExecFlagType & exec_type);
2398 :
2399 0 : virtual Executor & getExecutor(const std::string & name) { return _app.getExecutor(name); }
2400 :
2401 : /**
2402 : * Call compute methods on UserObjects.
2403 : */
2404 : virtual void computeUserObjects(const ExecFlagType & type, const Moose::AuxGroup & group);
2405 :
2406 : /**
2407 : * Compute an user object with the given name
2408 : */
2409 : virtual void computeUserObjectByName(const ExecFlagType & type,
2410 : const Moose::AuxGroup & group,
2411 : const std::string & name);
2412 :
2413 : /**
2414 : * Set a flag that indicated that user required values for the previous Newton iterate
2415 : */
2416 : void needsPreviousNewtonIteration(bool state);
2417 :
2418 : /**
2419 : * Check to see whether we need to compute the variable values of the previous Newton iterate
2420 : * @return true if the user required values of the previous Newton iterate
2421 : */
2422 : bool needsPreviousNewtonIteration() const;
2423 :
2424 : /**
2425 : * Set a flag that indicated that user required values for the previous multiapp fixed point
2426 : * iterate for the solver systems (not auxiliary)
2427 : * @param needed the value that should be set to the flag
2428 : * @param solver_sys_num the index of the solver system for which the previous iteration is needed
2429 : */
2430 : void needsPreviousMultiAppFixedPointIterationSolution(bool needed,
2431 : const unsigned int solver_sys_num);
2432 :
2433 : /**
2434 : * Check to see whether we need to compute the variable values of the previous multiapp fixed
2435 : * point iteration for the solver systems (not auxiliary)
2436 : * @param solver_sys_num the index of the solver system for which the previous iteration is needed
2437 : * @return true if the user required values of the previous multiapp fixed point iteration
2438 : */
2439 : bool needsPreviousMultiAppFixedPointIterationSolution(const unsigned int solver_sys_num) const;
2440 :
2441 : /**
2442 : * Set a flag that indicated that user required values for the previous multiapp fixed point
2443 : * iterate for the auxiliary system
2444 : */
2445 : void needsPreviousMultiAppFixedPointIterationAuxiliary(bool state);
2446 :
2447 : /**
2448 : * Check to see whether we need to compute the variable values of the previous multiapp fixed
2449 : * point iteration for the auxiliary system
2450 : * @return true if the user required values of the previous multiapp fixed point iteration from
2451 : * the auxiliary system
2452 : */
2453 : bool needsPreviousMultiAppFixedPointIterationAuxiliary() const;
2454 :
2455 : ///@{
2456 : /**
2457 : * Convenience zeros
2458 : */
2459 : std::vector<Real> _real_zero;
2460 : std::vector<VariableValue> _scalar_zero;
2461 : std::vector<VariableValue> _zero;
2462 : std::vector<VariablePhiValue> _phi_zero;
2463 : std::vector<MooseArray<ADReal>> _ad_zero;
2464 : std::vector<VariableGradient> _grad_zero;
2465 : std::vector<MooseArray<ADRealVectorValue>> _ad_grad_zero;
2466 : std::vector<VariablePhiGradient> _grad_phi_zero;
2467 : std::vector<VariableSecond> _second_zero;
2468 : std::vector<MooseArray<ADRealTensorValue>> _ad_second_zero;
2469 : std::vector<VariablePhiSecond> _second_phi_zero;
2470 : std::vector<Point> _point_zero;
2471 : std::vector<VectorVariableValue> _vector_zero;
2472 : std::vector<VectorVariableCurl> _vector_curl_zero;
2473 : ///@}
2474 :
2475 : /**
2476 : * Reference to the control logic warehouse.
2477 : */
2478 122973 : ExecuteMooseObjectWarehouse<Control> & getControlWarehouse() { return _control_warehouse; }
2479 :
2480 : /**
2481 : * Performs setup and execute calls for Control objects.
2482 : */
2483 : void executeControls(const ExecFlagType & exec_type);
2484 :
2485 : /**
2486 : * Performs setup and execute calls for Sampler objects.
2487 : */
2488 : void executeSamplers(const ExecFlagType & exec_type);
2489 :
2490 : /**
2491 : * Update the active objects in the warehouses
2492 : */
2493 : virtual void updateActiveObjects();
2494 :
2495 : /**
2496 : * Register a MOOSE object dependency so we can either order
2497 : * operations properly or report when we cannot.
2498 : * a -> b (a depends on b)
2499 : */
2500 : void reportMooseObjectDependency(MooseObject * a, MooseObject * b);
2501 :
2502 94219 : ExecuteMooseObjectWarehouse<MultiApp> & getMultiAppWarehouse() { return _multi_apps; }
2503 :
2504 : /**
2505 : * Returns _has_jacobian
2506 : */
2507 : bool hasJacobian() const;
2508 :
2509 : /**
2510 : * Returns _const_jacobian (whether a MOOSE object has specified that
2511 : * the Jacobian is the same as the previous time it was computed)
2512 : */
2513 : bool constJacobian() const;
2514 :
2515 : /**
2516 : * Adds an Output object.
2517 : */
2518 : void addOutput(const std::string &, const std::string &, InputParameters &);
2519 :
2520 39989539 : inline TheWarehouse & theWarehouse() const { return _app.theWarehouse(); }
2521 :
2522 : /**
2523 : * If or not to reuse the base vector for matrix-free calculation
2524 : */
2525 60406 : void setSNESMFReuseBase(bool reuse, bool set_by_user)
2526 : {
2527 60406 : _snesmf_reuse_base = reuse, _snesmf_reuse_base_set_by_user = set_by_user;
2528 60406 : }
2529 :
2530 : /**
2531 : * Return a flag that indicates if we are reusing the vector base
2532 : */
2533 293738 : bool useSNESMFReuseBase() { return _snesmf_reuse_base; }
2534 :
2535 : /**
2536 : * Set a flag that indicates if we want to skip exception and stop solve
2537 : */
2538 60406 : void skipExceptionCheck(bool skip_exception_check)
2539 : {
2540 60406 : _skip_exception_check = skip_exception_check;
2541 60406 : }
2542 :
2543 : /**
2544 : * Return a flag to indicate if _snesmf_reuse_base is set by users
2545 : */
2546 : bool isSNESMFReuseBaseSetbyUser() { return _snesmf_reuse_base_set_by_user; }
2547 :
2548 : /**
2549 : * If PETSc options are already inserted
2550 : */
2551 1091 : bool & petscOptionsInserted() { return _is_petsc_options_inserted; }
2552 :
2553 : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
2554 24 : PetscOptions & petscOptionsDatabase() { return _petsc_option_data_base; }
2555 : #endif
2556 :
2557 : /// Set boolean flag to true to store solution time derivative
2558 61102 : virtual void setUDotRequested(const bool u_dot_requested) { _u_dot_requested = u_dot_requested; }
2559 :
2560 : /// Set boolean flag to true to store solution second time derivative
2561 300 : virtual void setUDotDotRequested(const bool u_dotdot_requested)
2562 : {
2563 300 : _u_dotdot_requested = u_dotdot_requested;
2564 300 : }
2565 :
2566 : /// Set boolean flag to true to store old solution time derivative
2567 300 : virtual void setUDotOldRequested(const bool u_dot_old_requested)
2568 : {
2569 300 : _u_dot_old_requested = u_dot_old_requested;
2570 300 : }
2571 :
2572 : /// Set boolean flag to true to store old solution second time derivative
2573 300 : virtual void setUDotDotOldRequested(const bool u_dotdot_old_requested)
2574 : {
2575 300 : _u_dotdot_old_requested = u_dotdot_old_requested;
2576 300 : }
2577 :
2578 : /// Get boolean flag to check whether solution time derivative needs to be stored
2579 60987 : virtual bool uDotRequested() { return _u_dot_requested; }
2580 :
2581 : /// Get boolean flag to check whether solution second time derivative needs to be stored
2582 91492 : virtual bool uDotDotRequested() { return _u_dotdot_requested; }
2583 :
2584 : /// Get boolean flag to check whether old solution time derivative needs to be stored
2585 60987 : virtual bool uDotOldRequested()
2586 : {
2587 60987 : if (_u_dot_old_requested && !_u_dot_requested)
2588 0 : mooseError("FEProblemBase: When requesting old time derivative of solution, current time "
2589 : "derivative of solution should also be stored. Please set `u_dot_requested` to "
2590 : "true using setUDotRequested.");
2591 :
2592 60987 : return _u_dot_old_requested;
2593 : }
2594 :
2595 : /// Get boolean flag to check whether old solution second time derivative needs to be stored
2596 60987 : virtual bool uDotDotOldRequested()
2597 : {
2598 60987 : if (_u_dotdot_old_requested && !_u_dotdot_requested)
2599 0 : mooseError("FEProblemBase: When requesting old second time derivative of solution, current "
2600 : "second time derivation of solution should also be stored. Please set "
2601 : "`u_dotdot_requested` to true using setUDotDotRequested.");
2602 60987 : return _u_dotdot_old_requested;
2603 : }
2604 :
2605 : using SubProblem::haveADObjects;
2606 : void haveADObjects(bool have_ad_objects) override;
2607 :
2608 : // Whether or not we should solve this system
2609 350728 : bool shouldSolve() const { return _solve; }
2610 :
2611 : /**
2612 : * Returns the mortar data object
2613 : */
2614 : const MortarInterfaceWarehouse & mortarData() const { return *_mortar_data; }
2615 1414 : MortarInterfaceWarehouse & mortarData() { return *_mortar_data; }
2616 :
2617 : /**
2618 : * Whether the simulation has neighbor coupling
2619 : */
2620 0 : virtual bool hasNeighborCoupling() const { return _has_internal_edge_residual_objects; }
2621 :
2622 : /**
2623 : * Whether the simulation has mortar coupling
2624 : */
2625 0 : virtual bool hasMortarCoupling() const { return _has_mortar; }
2626 :
2627 : using SubProblem::computingNonlinearResid;
2628 : void computingNonlinearResid(bool computing_nonlinear_residual) final;
2629 :
2630 : using SubProblem::currentlyComputingResidual;
2631 : void setCurrentlyComputingResidual(bool currently_computing_residual) final;
2632 :
2633 : /**
2634 : * Set the number of steps in a grid sequences
2635 : */
2636 60391 : void numGridSteps(unsigned int num_grid_steps) { _num_grid_steps = num_grid_steps; }
2637 :
2638 : /**
2639 : * uniformly refine the problem mesh(es). This will also prolong the the solution, and in order
2640 : * for that to be safe, we can only perform one refinement at a time
2641 : */
2642 : void uniformRefine();
2643 :
2644 : using SubProblem::automaticScaling;
2645 : void automaticScaling(bool automatic_scaling) override;
2646 :
2647 : ///@{
2648 : /**
2649 : * Helpers for calling the necessary setup/execute functions for the supplied objects
2650 : */
2651 : template <typename T>
2652 : static void objectSetupHelper(const std::vector<T *> & objects, const ExecFlagType & exec_flag);
2653 : template <typename T>
2654 : static void objectExecuteHelper(const std::vector<T *> & objects);
2655 : ///@}
2656 :
2657 : /**
2658 : * reinitialize FE objects on a given element on a given side at a given set of reference
2659 : * points and then compute variable data. Note that this method makes no assumptions about what's
2660 : * been called beforehand, e.g. you don't have to call some prepare method before this one. This
2661 : * is an all-in-one reinit
2662 : */
2663 : virtual void reinitElemFaceRef(const Elem * elem,
2664 : unsigned int side,
2665 : Real tolerance,
2666 : const std::vector<Point> * const pts,
2667 : const std::vector<Real> * const weights = nullptr,
2668 : const THREAD_ID tid = 0) override;
2669 :
2670 : /**
2671 : * reinitialize FE objects on a given neighbor element on a given side at a given set of reference
2672 : * points and then compute variable data. Note that this method makes no assumptions about what's
2673 : * been called beforehand, e.g. you don't have to call some prepare method before this one. This
2674 : * is an all-in-one reinit
2675 : */
2676 : virtual void reinitNeighborFaceRef(const Elem * neighbor_elem,
2677 : unsigned int neighbor_side,
2678 : Real tolerance,
2679 : const std::vector<Point> * const pts,
2680 : const std::vector<Real> * const weights = nullptr,
2681 : const THREAD_ID tid = 0) override;
2682 :
2683 : /**
2684 : * @return whether to perform a boundary condition integrity check for finite volume
2685 : */
2686 2555 : bool fvBCsIntegrityCheck() const { return _fv_bcs_integrity_check; }
2687 :
2688 : /**
2689 : * @param fv_bcs_integrity_check Whether to perform a boundary condition integrity check for
2690 : * finite volume
2691 : */
2692 : void fvBCsIntegrityCheck(bool fv_bcs_integrity_check);
2693 :
2694 : /**
2695 : * Get the materials and variables potentially needed for FV
2696 : * @param block_id SubdomainID The subdomain id that we want to retrieve materials for
2697 : * @param face_materials The face materials container that we will fill
2698 : * @param neighbor_materials The neighbor materials container that we will fill
2699 : * @param variables The variables container that we will fill that our materials depend on
2700 : * @param tid The thread id
2701 : */
2702 : void getFVMatsAndDependencies(SubdomainID block_id,
2703 : std::vector<std::shared_ptr<MaterialBase>> & face_materials,
2704 : std::vector<std::shared_ptr<MaterialBase>> & neighbor_materials,
2705 : std::set<MooseVariableFieldBase *> & variables,
2706 : const THREAD_ID tid);
2707 :
2708 : /**
2709 : * Resize material data
2710 : * @param data_type The type of material data to resize
2711 : * @param nqp The number of quadrature points to resize for
2712 : * @param tid The thread ID
2713 : */
2714 : void resizeMaterialData(Moose::MaterialDataType data_type, unsigned int nqp, const THREAD_ID tid);
2715 :
2716 2265 : bool haveDisplaced() const override final { return _displaced_problem.get(); }
2717 :
2718 : /// Whether we have linear convergence objects
2719 : bool hasLinearConvergenceObjects() const;
2720 : /**
2721 : * Sets the nonlinear convergence object name(s) if there is one
2722 : */
2723 : void setNonlinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names);
2724 : /**
2725 : * Sets the linear convergence object name(s) if there is one
2726 : */
2727 : void setLinearConvergenceNames(const std::vector<ConvergenceName> & convergence_names);
2728 : /**
2729 : * Sets the MultiApp fixed point convergence object name if there is one
2730 : */
2731 : void setMultiAppFixedPointConvergenceName(const ConvergenceName & convergence_name);
2732 : /**
2733 : * Sets the steady-state detection convergence object name if there is one
2734 : */
2735 : void setSteadyStateConvergenceName(const ConvergenceName & convergence_name);
2736 :
2737 : /**
2738 : * Gets the nonlinear system convergence object name(s).
2739 : */
2740 : const std::vector<ConvergenceName> & getNonlinearConvergenceNames() const;
2741 : /**
2742 : * Gets the linear convergence object name(s).
2743 : */
2744 : const std::vector<ConvergenceName> & getLinearConvergenceNames() const;
2745 : /**
2746 : * Gets the MultiApp fixed point convergence object name.
2747 : */
2748 : const ConvergenceName & getMultiAppFixedPointConvergenceName() const;
2749 : /**
2750 : * Gets the steady-state detection convergence object name.
2751 : */
2752 : const ConvergenceName & getSteadyStateConvergenceName() const;
2753 :
2754 : /**
2755 : * Setter for whether we're computing the scaling jacobian
2756 : */
2757 986 : void computingScalingJacobian(bool computing_scaling_jacobian)
2758 : {
2759 986 : _computing_scaling_jacobian = computing_scaling_jacobian;
2760 986 : }
2761 :
2762 66542403 : bool computingScalingJacobian() const override final { return _computing_scaling_jacobian; }
2763 :
2764 : /**
2765 : * Setter for whether we're computing the scaling residual
2766 : */
2767 90 : void computingScalingResidual(bool computing_scaling_residual)
2768 : {
2769 90 : _computing_scaling_residual = computing_scaling_residual;
2770 90 : }
2771 :
2772 : /**
2773 : * @return whether we are currently computing a residual for automatic scaling purposes
2774 : */
2775 6194848 : bool computingScalingResidual() const override final { return _computing_scaling_residual; }
2776 :
2777 : /**
2778 : * @return the coordinate transformation object that describes how to transform this problem's
2779 : * coordinate system into the canonical/reference coordinate system
2780 : */
2781 : MooseAppCoordTransform & coordTransform();
2782 :
2783 162489617 : virtual std::size_t numNonlinearSystems() const override { return _num_nl_sys; }
2784 :
2785 431060 : virtual std::size_t numLinearSystems() const override { return _num_linear_sys; }
2786 :
2787 11252967 : virtual std::size_t numSolverSystems() const override { return _num_nl_sys + _num_linear_sys; }
2788 :
2789 : /// Check if the solver system is nonlinear
2790 222348 : bool isSolverSystemNonlinear(const unsigned int sys_num) { return sys_num < _num_nl_sys; }
2791 :
2792 : virtual unsigned int currentNlSysNum() const override;
2793 :
2794 : virtual unsigned int currentLinearSysNum() const override;
2795 :
2796 : /**
2797 : * @return the nonlinear system number corresponding to the provided \p nl_sys_name
2798 : */
2799 : virtual unsigned int nlSysNum(const NonlinearSystemName & nl_sys_name) const override;
2800 :
2801 : /**
2802 : * @return the linear system number corresponding to the provided \p linear_sys_name
2803 : */
2804 : unsigned int linearSysNum(const LinearSystemName & linear_sys_name) const override;
2805 :
2806 : /**
2807 : * @return the solver system number corresponding to the provided \p solver_sys_name
2808 : */
2809 : unsigned int solverSysNum(const SolverSystemName & solver_sys_name) const override;
2810 :
2811 : /**
2812 : * @return the system number for the provided \p variable_name
2813 : * Can be nonlinear or auxiliary
2814 : */
2815 : unsigned int systemNumForVariable(const VariableName & variable_name) const;
2816 :
2817 : /// Whether it will skip further residual evaluations and fail the next nonlinear convergence check(s)
2818 1991468 : bool getFailNextNonlinearConvergenceCheck() const { return getFailNextSystemConvergenceCheck(); }
2819 : /// Whether it will fail the next system convergence check(s), triggering failed step behavior
2820 1995749 : bool getFailNextSystemConvergenceCheck() const { return _fail_next_system_convergence_check; }
2821 :
2822 : /// Skip further residual evaluations and fail the next nonlinear convergence check(s)
2823 130 : void setFailNextNonlinearConvergenceCheck() { setFailNextSystemConvergenceCheck(); }
2824 : /// Tell the problem that the system(s) cannot be considered converged next time convergence is checked
2825 130 : void setFailNextSystemConvergenceCheck() { _fail_next_system_convergence_check = true; }
2826 :
2827 : /// Tell the problem that the nonlinear convergence check(s) may proceed as normal
2828 261 : void resetFailNextNonlinearConvergenceCheck() { resetFailNextSystemConvergenceCheck(); }
2829 : /// Tell the problem that the system convergence check(s) may proceed as normal
2830 261 : void resetFailNextSystemConvergenceCheck() { _fail_next_system_convergence_check = false; }
2831 :
2832 : /*
2833 : * Set the status of loop order of execution printing
2834 : * @param print_exec set of execution flags to print on
2835 : */
2836 224 : void setExecutionPrinting(const ExecFlagEnum & print_exec) { _print_execution_on = print_exec; }
2837 :
2838 : /**
2839 : * Check whether the problem should output execution orders at this time
2840 : */
2841 : bool shouldPrintExecution(const THREAD_ID tid) const;
2842 : /**
2843 : * Call \p reinit on mortar user objects with matching primary boundary ID, secondary boundary ID,
2844 : * and displacement characteristics
2845 : */
2846 : void reinitMortarUserObjects(BoundaryID primary_boundary_id,
2847 : BoundaryID secondary_boundary_id,
2848 : bool displaced);
2849 :
2850 : virtual const std::vector<VectorTag> & currentResidualVectorTags() const override;
2851 :
2852 : /**
2853 : * Class that is used as a parameter to set/clearCurrentResidualVectorTags that allows only
2854 : * blessed classes to call said methods
2855 : */
2856 : class CurrentResidualVectorTagsKey
2857 : {
2858 : friend class CrankNicolson;
2859 : friend class FEProblemBase;
2860 : CurrentResidualVectorTagsKey() {}
2861 : CurrentResidualVectorTagsKey(const CurrentResidualVectorTagsKey &) {}
2862 : };
2863 :
2864 : /**
2865 : * Set the current residual vector tag data structure based on the passed in tag IDs
2866 : */
2867 : void setCurrentResidualVectorTags(const std::set<TagID> & vector_tags);
2868 :
2869 : /**
2870 : * Clear the current residual vector tag data structure
2871 : */
2872 : void clearCurrentResidualVectorTags();
2873 :
2874 : /**
2875 : * Clear the current Jacobian matrix tag data structure ... if someone creates it
2876 : */
2877 3540925 : void clearCurrentJacobianMatrixTags() {}
2878 :
2879 6267 : virtual void needFV() override { _have_fv = true; }
2880 349988273 : virtual bool haveFV() const override { return _have_fv; }
2881 :
2882 48363779 : virtual bool hasNonlocalCoupling() const override { return _has_nonlocal_coupling; }
2883 :
2884 : /**
2885 : * Whether to identify variable groups in nonlinear systems. This affects dof ordering
2886 : */
2887 61792 : bool identifyVariableGroupsInNL() const { return _identify_variable_groups_in_nl; }
2888 :
2889 : virtual void setCurrentLowerDElem(const Elem * const lower_d_elem, const THREAD_ID tid) override;
2890 : virtual void setCurrentBoundaryID(BoundaryID bid, const THREAD_ID tid) override;
2891 :
2892 : /**
2893 : * @returns the nolinear system names in the problem
2894 : */
2895 131732 : const std::vector<NonlinearSystemName> & getNonlinearSystemNames() const { return _nl_sys_names; }
2896 : /**
2897 : * @returns the linear system names in the problem
2898 : */
2899 60651 : const std::vector<LinearSystemName> & getLinearSystemNames() const { return _linear_sys_names; }
2900 : /**
2901 : * @returns the solver system names in the problem
2902 : */
2903 614 : const std::vector<SolverSystemName> & getSolverSystemNames() const { return _solver_sys_names; }
2904 :
2905 : virtual const libMesh::CouplingMatrix & nonlocalCouplingMatrix(const unsigned i) const override;
2906 :
2907 : virtual bool checkNonlocalCouplingRequirement() const override;
2908 :
2909 153122 : virtual Moose::FEBackend feBackend() const { return Moose::FEBackend::LibMesh; }
2910 :
2911 : class CreateTaggedMatrixKey
2912 : {
2913 61612 : CreateTaggedMatrixKey() {}
2914 : CreateTaggedMatrixKey(const CreateTaggedMatrixKey &) {}
2915 :
2916 : friend class AddTaggedMatricesAction;
2917 : };
2918 :
2919 : void createTagMatrices(CreateTaggedMatrixKey);
2920 :
2921 1695 : bool useHashTableMatrixAssembly() const { return _use_hash_table_matrix_assembly; }
2922 :
2923 : #ifdef MOOSE_KOKKOS_ENABLED
2924 : /**
2925 : * @returns whether any Kokkos object was added in the problem
2926 : */
2927 58016 : bool hasKokkosObjects() const { return _has_kokkos_objects; }
2928 : /**
2929 : * @returns whether any Kokkos residual object was added in the problem
2930 : */
2931 4795716 : bool hasKokkosResidualObjects() const { return _has_kokkos_residual_objects; }
2932 : /**
2933 : * Add a function hook that needs to be called after Kokkos mesh initialization
2934 : * @param function The function to be called
2935 : */
2936 18890 : void addKokkosMeshInitializationHook(std::function<void()> function)
2937 : {
2938 18890 : _kokkos_mesh_initialization_hooks.push_back(function);
2939 18890 : }
2940 : #endif
2941 :
2942 : protected:
2943 : /**
2944 : * Deprecated. Users should switch to overriding the meshChanged which takes arguments
2945 : */
2946 7026 : virtual void meshChanged() {}
2947 :
2948 : /// Create extra tagged vectors and matrices
2949 : void createTagVectors();
2950 :
2951 : /// Create extra tagged solution vectors
2952 : void createTagSolutions();
2953 :
2954 : /**
2955 : * Update data after a mesh displaced.
2956 : */
2957 : virtual void meshDisplaced();
2958 :
2959 : /**
2960 : * Do generic system computations
2961 : */
2962 : void computeSystems(const ExecFlagType & type);
2963 :
2964 : MooseMesh & _mesh;
2965 :
2966 : private:
2967 : /// The EquationSystems object, wrapped for restart
2968 : Restartable::ManagedValue<RestartableEquationSystems> _req;
2969 :
2970 : /**
2971 : * Set the subproblem and system parameters for residual objects and log their addition
2972 : * @param ro_name The type of the residual object
2973 : * @param name The name of the residual object
2974 : * @param parameters The residual object parameters
2975 : * @param nl_sys_num The nonlinear system that the residual object belongs to
2976 : * @param base_name The base type of the residual object, e.g. Kernel, BoundaryCondition, etc.
2977 : * @param reinit_displaced A data member indicating whether a geometric concept should be reinit'd
2978 : * for the displaced problem. Examples of valid data members to pass in are \p
2979 : * _reinit_displaced_elem and \p _reinit_displaced_face
2980 : */
2981 : void setResidualObjectParamsAndLog(const std::string & ro_name,
2982 : const std::string & name,
2983 : InputParameters & parameters,
2984 : const unsigned int nl_sys_num,
2985 : const std::string & base_name,
2986 : bool & reinit_displaced);
2987 :
2988 : /**
2989 : * Set the subproblem and system parameters for auxiliary kernels and log their addition
2990 : * @param ak_name The type of the auxiliary kernel
2991 : * @param name The name of the auxiliary kernel
2992 : * @param parameters The auxiliary kernel parameters
2993 : * @param base_name The base type of the auxiliary kernel, i.e. AuxKernel or KokkosAuxKernel
2994 : */
2995 : void setAuxKernelParamsAndLog(const std::string & ak_name,
2996 : const std::string & name,
2997 : InputParameters & parameters,
2998 : const std::string & base_name);
2999 :
3000 : /**
3001 : * Make basic solver params for linear solves
3002 : */
3003 : static SolverParams makeLinearSolverParams();
3004 :
3005 : TheWarehouse::Query getUOQuery(const std::string & system,
3006 : const ExecFlagType & type,
3007 : const Moose::AuxGroup & group) const;
3008 :
3009 : void getUOExecutionGroups(TheWarehouse::Query & query, std::set<int> & execution_groups) const;
3010 :
3011 : protected:
3012 : bool _initialized;
3013 :
3014 : /// Nonlinear system(s) convergence name(s)
3015 : std::optional<std::vector<ConvergenceName>> _nonlinear_convergence_names;
3016 : /// Linear system(s) convergence name(s) (if any)
3017 : std::optional<std::vector<ConvergenceName>> _linear_convergence_names;
3018 : /// MultiApp fixed point convergence name
3019 : std::optional<ConvergenceName> _multiapp_fixed_point_convergence_name;
3020 : /// Steady-state detection convergence name
3021 : std::optional<ConvergenceName> _steady_state_convergence_name;
3022 :
3023 : std::set<TagID> _fe_vector_tags;
3024 :
3025 : std::set<TagID> _fe_matrix_tags;
3026 :
3027 : /// Temporary storage for filtered vector tags for linear systems
3028 : std::set<TagID> _linear_vector_tags;
3029 :
3030 : /// Temporary storage for filtered matrix tags for linear systems
3031 : std::set<TagID> _linear_matrix_tags;
3032 :
3033 : /// Whether or not to actually solve the nonlinear system
3034 : const bool & _solve;
3035 :
3036 : bool _transient;
3037 : Real & _time;
3038 : Real & _time_old;
3039 : int & _t_step;
3040 : Real & _dt;
3041 : Real & _dt_old;
3042 :
3043 : /// Flag that the problem needs to add the default nonlinear convergence
3044 : bool _need_to_add_default_nonlinear_convergence;
3045 : /// Flag that the problem needs to add the default fixed point convergence
3046 : bool _need_to_add_default_multiapp_fixed_point_convergence;
3047 : /// Flag that the problem needs to add the default steady convergence
3048 : bool _need_to_add_default_steady_state_convergence;
3049 :
3050 : /// The linear system names
3051 : const std::vector<LinearSystemName> _linear_sys_names;
3052 :
3053 : /// The number of linear systems
3054 : const std::size_t _num_linear_sys;
3055 :
3056 : /// The vector of linear systems
3057 : std::vector<std::shared_ptr<LinearSystem>> _linear_systems;
3058 :
3059 : /// Map from linear system name to number
3060 : std::map<LinearSystemName, unsigned int> _linear_sys_name_to_num;
3061 :
3062 : /// The current linear system that we are solving
3063 : LinearSystem * _current_linear_sys;
3064 :
3065 : /// Boolean to check if we have the default nonlinear system
3066 : const bool _using_default_nl;
3067 :
3068 : /// The nonlinear system names
3069 : const std::vector<NonlinearSystemName> _nl_sys_names;
3070 :
3071 : /// The number of nonlinear systems
3072 : const std::size_t _num_nl_sys;
3073 :
3074 : /// The nonlinear systems
3075 : std::vector<std::shared_ptr<NonlinearSystemBase>> _nl;
3076 :
3077 : /// Map from nonlinear system name to number
3078 : std::map<NonlinearSystemName, unsigned int> _nl_sys_name_to_num;
3079 :
3080 : /// The current nonlinear system that we are solving
3081 : NonlinearSystemBase * _current_nl_sys;
3082 :
3083 : /// The current solver system
3084 : SolverSystem * _current_solver_sys;
3085 :
3086 : /// Combined container to base pointer of every solver system
3087 : std::vector<std::shared_ptr<SolverSystem>> _solver_systems;
3088 :
3089 : /// Map connecting variable names with their respective solver systems
3090 : std::map<SolverVariableName, unsigned int> _solver_var_to_sys_num;
3091 :
3092 : /// Map connecting solver system names with their respective systems
3093 : std::map<SolverSystemName, unsigned int> _solver_sys_name_to_num;
3094 :
3095 : /// The union of nonlinear and linear system names
3096 : std::vector<SolverSystemName> _solver_sys_names;
3097 :
3098 : /// The auxiliary system
3099 : std::shared_ptr<AuxiliarySystem> _aux;
3100 :
3101 : Moose::CouplingType _coupling; ///< Type of variable coupling
3102 : std::vector<std::unique_ptr<libMesh::CouplingMatrix>> _cm; ///< Coupling matrix for variables.
3103 :
3104 : #ifdef MOOSE_KOKKOS_ENABLED
3105 : Moose::Kokkos::Array<Moose::Kokkos::System> _kokkos_systems;
3106 : #endif
3107 :
3108 : /// Dimension of the subspace spanned by the vectors with a given prefix
3109 : std::map<std::string, unsigned int> _subspace_dim;
3110 :
3111 : /// The Assembly objects. The first index corresponds to the thread ID and the second index
3112 : /// corresponds to the nonlinear system number
3113 : std::vector<std::vector<std::unique_ptr<Assembly>>> _assembly;
3114 :
3115 : #ifdef MOOSE_KOKKOS_ENABLED
3116 : Moose::Kokkos::Assembly _kokkos_assembly;
3117 : #endif
3118 :
3119 : /// Warehouse to store mesh divisions
3120 : /// NOTE: this could probably be moved to the MooseMesh instead of the Problem
3121 : /// Time (and people's uses) will tell where this fits best
3122 : MooseObjectWarehouse<MeshDivision> _mesh_divisions;
3123 :
3124 : /// functions
3125 : MooseObjectWarehouse<Function> _functions;
3126 :
3127 : #ifdef MOOSE_KOKKOS_ENABLED
3128 : MooseObjectWarehouse<Moose::FunctionBase> _kokkos_functions;
3129 : #endif
3130 :
3131 : /// convergence warehouse
3132 : MooseObjectWarehouse<Convergence> _convergences;
3133 :
3134 : /// nonlocal kernels
3135 : MooseObjectWarehouse<KernelBase> _nonlocal_kernels;
3136 :
3137 : /// nonlocal integrated_bcs
3138 : MooseObjectWarehouse<IntegratedBCBase> _nonlocal_integrated_bcs;
3139 :
3140 : ///@{
3141 : /// Initial condition storage
3142 : InitialConditionWarehouse _ics;
3143 : FVInitialConditionWarehouse _fv_ics;
3144 : ScalarInitialConditionWarehouse _scalar_ics; // use base b/c of setup methods
3145 : ///@}
3146 :
3147 : // material properties
3148 : MaterialPropertyRegistry _material_prop_registry;
3149 : MaterialPropertyStorage & _material_props;
3150 : MaterialPropertyStorage & _bnd_material_props;
3151 : MaterialPropertyStorage & _neighbor_material_props;
3152 :
3153 : #ifdef MOOSE_KOKKOS_ENABLED
3154 : Moose::Kokkos::MaterialPropertyStorage & _kokkos_material_props;
3155 : Moose::Kokkos::MaterialPropertyStorage & _kokkos_bnd_material_props;
3156 : Moose::Kokkos::MaterialPropertyStorage & _kokkos_neighbor_material_props;
3157 : #endif
3158 : ///@{
3159 : // Material Warehouses
3160 : MaterialWarehouse _materials; // regular materials
3161 : MaterialWarehouse _interface_materials; // interface materials
3162 : MaterialWarehouse _discrete_materials; // Materials that the user must compute
3163 : MaterialWarehouse _all_materials; // All materials for error checking and MaterialData storage
3164 :
3165 : #ifdef MOOSE_KOKKOS_ENABLED
3166 : MaterialWarehouse _kokkos_materials; // Kokkos materials
3167 : #endif
3168 : ///@}
3169 :
3170 : ///@{
3171 : // Indicator Warehouses
3172 : MooseObjectWarehouse<Indicator> _indicators;
3173 : MooseObjectWarehouse<InternalSideIndicatorBase> _internal_side_indicators;
3174 : ///@}
3175 :
3176 : // Marker Warehouse
3177 : MooseObjectWarehouse<Marker> _markers;
3178 :
3179 : // Helper class to access Reporter object values
3180 : ReporterData _reporter_data;
3181 :
3182 : /// MultiApp Warehouse
3183 : ExecuteMooseObjectWarehouse<MultiApp> _multi_apps;
3184 :
3185 : /// Storage for TransientMultiApps (only needed for calling 'computeDT')
3186 : ExecuteMooseObjectWarehouse<TransientMultiApp> _transient_multi_apps;
3187 :
3188 : /// Normal Transfers
3189 : ExecuteMooseObjectWarehouse<Transfer> _transfers;
3190 :
3191 : /// Transfers executed just before MultiApps to transfer data to them
3192 : ExecuteMooseObjectWarehouse<Transfer> _to_multi_app_transfers;
3193 :
3194 : /// Transfers executed just after MultiApps to transfer data from them
3195 : ExecuteMooseObjectWarehouse<Transfer> _from_multi_app_transfers;
3196 :
3197 : /// Transfers executed just before MultiApps to transfer data between them
3198 : ExecuteMooseObjectWarehouse<Transfer> _between_multi_app_transfers;
3199 :
3200 : /// A map of objects that consume random numbers
3201 : std::map<std::string, std::unique_ptr<RandomData>> _random_data_objects;
3202 :
3203 : /// Cache for calculating materials on side
3204 : std::vector<std::unordered_map<SubdomainID, bool>> _block_mat_side_cache;
3205 :
3206 : /// Cache for calculating materials on side
3207 : std::vector<std::unordered_map<BoundaryID, bool>> _bnd_mat_side_cache;
3208 :
3209 : /// Cache for calculating materials on interface
3210 : std::vector<std::unordered_map<BoundaryID, bool>> _interface_mat_side_cache;
3211 :
3212 : /// Objects to be notified when the mesh changes
3213 : std::vector<MeshChangedInterface *> _notify_when_mesh_changes;
3214 :
3215 : /// Objects to be notified when the mesh displaces
3216 : std::vector<MeshDisplacedInterface *> _notify_when_mesh_displaces;
3217 :
3218 : /// Helper to check for duplicate variable names across systems or within a single system
3219 : bool duplicateVariableCheck(const std::string & var_name,
3220 : const libMesh::FEType & type,
3221 : bool is_aux,
3222 : const std::set<SubdomainID> * const active_subdomains);
3223 :
3224 : void computeUserObjectsInternal(const ExecFlagType & type, TheWarehouse::Query & query);
3225 :
3226 : #ifdef MOOSE_KOKKOS_ENABLED
3227 : void computeKokkosUserObjectsInternal(const ExecFlagType & type, TheWarehouse::Query & query);
3228 : #endif
3229 :
3230 : /// Verify that SECOND order mesh uses SECOND order displacements.
3231 : void checkDisplacementOrders();
3232 :
3233 : void checkUserObjects();
3234 :
3235 : /**
3236 : * Helper method for checking Material object dependency.
3237 : *
3238 : * @see checkProblemIntegrity
3239 : */
3240 : void checkDependMaterialsHelper(
3241 : const std::map<SubdomainID, std::vector<std::shared_ptr<MaterialBase>>> & materials_map);
3242 :
3243 : /// Verify that there are no element type/coordinate type conflicts
3244 : void checkCoordinateSystems();
3245 :
3246 : /**
3247 : * Call when it is possible that the needs for ghosted elements has changed.
3248 : * @param mortar_changed Whether an update of mortar data has been requested since the last
3249 : * EquationSystems (re)initialization
3250 : */
3251 : void reinitBecauseOfGhostingOrNewGeomObjects(bool mortar_changed = false);
3252 :
3253 : /**
3254 : * Helper for setting the "_subproblem" and "_sys" parameters in addObject() and
3255 : * in addUserObject().
3256 : *
3257 : * This is needed due to header includes/forward declaration issues
3258 : */
3259 : void addObjectParamsHelper(InputParameters & params,
3260 : const std::string & object_name,
3261 : const std::string & var_param_name = "variable");
3262 :
3263 : #ifdef LIBMESH_ENABLE_AMR
3264 : Adaptivity _adaptivity;
3265 : unsigned int _cycles_completed;
3266 : #endif
3267 :
3268 : /// Pointer to XFEM controller
3269 : std::shared_ptr<XFEMInterface> _xfem;
3270 :
3271 : // Displaced mesh /////
3272 : MooseMesh * _displaced_mesh;
3273 : std::shared_ptr<DisplacedProblem> _displaced_problem;
3274 : GeometricSearchData _geometric_search_data;
3275 : std::unique_ptr<MortarInterfaceWarehouse> _mortar_data;
3276 :
3277 : /// Whether to call DisplacedProblem::reinitElem when this->reinitElem is called
3278 : bool _reinit_displaced_elem;
3279 : /// Whether to call DisplacedProblem::reinitElemFace when this->reinitElemFace is called
3280 : bool _reinit_displaced_face;
3281 : /// Whether to call DisplacedProblem::reinitNeighbor when this->reinitNeighbor is called
3282 : bool _reinit_displaced_neighbor;
3283 :
3284 : /// whether input file has been written
3285 : bool _input_file_saved;
3286 :
3287 : /// Whether or not this system has any Dampers associated with it.
3288 : bool _has_dampers;
3289 :
3290 : /// Whether or not this system has any Constraints.
3291 : bool _has_constraints;
3292 :
3293 : /// If or not to resuse the base vector for matrix-free calculation
3294 : bool _snesmf_reuse_base;
3295 :
3296 : /// If or not skip 'exception and stop solve'
3297 : bool _skip_exception_check;
3298 :
3299 : /// If or not _snesmf_reuse_base is set by user
3300 : bool _snesmf_reuse_base_set_by_user;
3301 :
3302 : /// Whether nor not stateful materials have been initialized
3303 : bool _has_initialized_stateful;
3304 :
3305 : /// true if the Jacobian is constant
3306 : bool _const_jacobian;
3307 :
3308 : /// Indicates if the Jacobian was computed
3309 : bool _has_jacobian;
3310 :
3311 : /// Indicates that we need to compute variable values for previous Newton iteration
3312 : bool _needs_old_newton_iter;
3313 :
3314 : /// Indicates we need to save the previous NL iteration variable values
3315 : bool _previous_nl_solution_required;
3316 : /// Indicates we need to save the previous multiapp fixed-point iteration solver variable values
3317 : std::vector<bool> _previous_multiapp_fp_nl_solution_required;
3318 : /// Indicates we need to save the previous multiapp fixed-point iteration auxiliary variable values
3319 : bool _previous_multiapp_fp_aux_solution_required;
3320 :
3321 : /// Indicates if nonlocal coupling is required/exists
3322 : bool _has_nonlocal_coupling;
3323 : bool _calculate_jacobian_in_uo;
3324 :
3325 : std::vector<std::vector<const MooseVariableFEBase *>> _uo_jacobian_moose_vars;
3326 :
3327 : /// Whether there are active material properties on each thread
3328 : std::vector<unsigned char> _has_active_material_properties;
3329 :
3330 : std::vector<SolverParams> _solver_params;
3331 :
3332 : /// Determines whether and which subdomains are to be checked to ensure that they have an active kernel
3333 : CoverageCheckMode _kernel_coverage_check;
3334 : std::vector<SubdomainName> _kernel_coverage_blocks;
3335 :
3336 : /// whether to perform checking of boundary restricted nodal object variable dependencies,
3337 : /// e.g. whether the variable dependencies are defined on the selected boundaries
3338 : const bool _boundary_restricted_node_integrity_check;
3339 :
3340 : /// whether to perform checking of boundary restricted elemental object variable dependencies,
3341 : /// e.g. whether the variable dependencies are defined on the selected boundaries
3342 : const bool _boundary_restricted_elem_integrity_check;
3343 :
3344 : /// Determines whether and which subdomains are to be checked to ensure that they have an active material
3345 : CoverageCheckMode _material_coverage_check;
3346 : std::vector<SubdomainName> _material_coverage_blocks;
3347 :
3348 : /// Whether to check overlapping Dirichlet and Flux BCs and/or multiple DirichletBCs per sideset
3349 : bool _fv_bcs_integrity_check;
3350 :
3351 : /// Determines whether a check to verify material dependencies on every subdomain
3352 : const bool _material_dependency_check;
3353 :
3354 : /// Whether or not checking the state of uo/aux evaluation
3355 : const bool _uo_aux_state_check;
3356 :
3357 : #ifndef NDEBUG
3358 : /// Whether to check the residual for NaN or Inf values
3359 : bool _check_residual_for_nans;
3360 : #endif
3361 :
3362 : /// Maximum number of quadrature points used in the problem
3363 : unsigned int _max_qps;
3364 :
3365 : /// Maximum scalar variable order
3366 : libMesh::Order _max_scalar_order;
3367 :
3368 : /// Indicates whether or not this executioner has a time integrator (during setup)
3369 : bool _has_time_integrator;
3370 :
3371 : /// Whether or not an exception has occurred
3372 : bool _has_exception;
3373 :
3374 : /// Whether or not information about how many transfers have completed is printed
3375 : bool _parallel_barrier_messaging;
3376 :
3377 : /// Whether or not to be verbose during setup
3378 : MooseEnum _verbose_setup;
3379 :
3380 : /// Whether or not to be verbose with multiapps
3381 : bool _verbose_multiapps;
3382 :
3383 : /// Whether or not to be verbose on solution restoration post a failed time step
3384 : bool _verbose_restore;
3385 :
3386 : /// The error message to go with an exception
3387 : std::string _exception_message;
3388 :
3389 : /// Current execute_on flag
3390 : ExecFlagType _current_execute_on_flag;
3391 :
3392 : /// The control logic warehouse
3393 : ExecuteMooseObjectWarehouse<Control> _control_warehouse;
3394 :
3395 : /// PETSc option storage
3396 : Moose::PetscSupport::PetscOptions _petsc_options;
3397 : #if !PETSC_RELEASE_LESS_THAN(3, 12, 0)
3398 : PetscOptions _petsc_option_data_base;
3399 : #endif
3400 :
3401 : /// If or not PETSc options have been added to database
3402 : bool _is_petsc_options_inserted;
3403 :
3404 : std::shared_ptr<LineSearch> _line_search;
3405 :
3406 : std::unique_ptr<libMesh::ConstElemRange> _evaluable_local_elem_range;
3407 : std::unique_ptr<libMesh::ConstElemRange> _nl_evaluable_local_elem_range;
3408 : std::unique_ptr<libMesh::ConstElemRange> _aux_evaluable_local_elem_range;
3409 :
3410 : std::unique_ptr<libMesh::ConstElemRange> _current_algebraic_elem_range;
3411 : std::unique_ptr<libMesh::ConstNodeRange> _current_algebraic_node_range;
3412 : std::unique_ptr<ConstBndNodeRange> _current_algebraic_bnd_node_range;
3413 :
3414 : /// Automatic differentiaion (AD) flag which indicates whether any consumer has
3415 : /// requested an AD material property or whether any suppier has declared an AD material property
3416 : bool _using_ad_mat_props;
3417 :
3418 : // loop state during projection of initial conditions
3419 : unsigned short _current_ic_state;
3420 :
3421 : /// Whether to assemble matrices using hash tables instead of preallocating matrix memory. This
3422 : /// can be a good option if the sparsity pattern changes throughout the course of the simulation
3423 : const bool _use_hash_table_matrix_assembly;
3424 :
3425 : private:
3426 : /**
3427 : * Handle exceptions. Note that the result of this call will be a thrown MooseException. The
3428 : * caller of this method must determine how to handle the thrown exception
3429 : */
3430 : void handleException(const std::string & calling_method);
3431 :
3432 : /**
3433 : * Helper for getting mortar objects corresponding to primary boundary ID, secondary boundary ID,
3434 : * and displaced parameters, given some initial set
3435 : */
3436 : std::vector<MortarUserObject *>
3437 : getMortarUserObjects(BoundaryID primary_boundary_id,
3438 : BoundaryID secondary_boundary_id,
3439 : bool displaced,
3440 : const std::vector<MortarUserObject *> & mortar_uo_superset);
3441 :
3442 : /**
3443 : * Helper for getting mortar objects corresponding to primary boundary ID, secondary boundary ID,
3444 : * and displaced parameters from the entire active mortar user object set
3445 : */
3446 : std::vector<MortarUserObject *> getMortarUserObjects(BoundaryID primary_boundary_id,
3447 : BoundaryID secondary_boundary_id,
3448 : bool displaced);
3449 :
3450 : /**
3451 : * Determine what solver system the provided variable name lies in
3452 : * @param var_name The name of the variable we are doing solver system lookups for
3453 : * @param error_if_not_found Whether to error if the variable name isn't found in any of the
3454 : * solver systems
3455 : * @return A pair in which the first member indicates whether the variable was found in the
3456 : * solver systems and the second member indicates the solver system number in which the
3457 : * variable was found (or an invalid unsigned integer if not found)
3458 : */
3459 : virtual std::pair<bool, unsigned int>
3460 : determineSolverSystem(const std::string & var_name,
3461 : bool error_if_not_found = false) const override;
3462 :
3463 : /**
3464 : * Checks if the variable of the initial condition is getting restarted and errors for specific
3465 : * cases
3466 : * @param ic_name The name of the initial condition
3467 : * @param var_name The name of the variable
3468 : */
3469 : void checkICRestartError(const std::string & ic_name,
3470 : const std::string & name,
3471 : const VariableName & var_name);
3472 :
3473 : /*
3474 : * Test if stateful property redistribution is expected to be
3475 : * necessary, and set it up if so.
3476 : */
3477 : void addAnyRedistributers();
3478 :
3479 : void updateMaxQps();
3480 :
3481 : void joinAndFinalize(TheWarehouse::Query query, bool isgen = false);
3482 :
3483 : #ifdef MOOSE_KOKKOS_ENABLED
3484 : void kokkosJoinAndFinalize(const std::vector<Moose::Kokkos::UserObject *> & userobjs);
3485 : #endif
3486 :
3487 : /**
3488 : * Reset state of this object in preparation for the next evaluation.
3489 : */
3490 : virtual void resetState();
3491 :
3492 : // Parameters handling Jacobian sparsity pattern behavior
3493 : /// Whether to error when the Jacobian is re-allocated, usually because the sparsity pattern changed
3494 : bool _error_on_jacobian_nonzero_reallocation;
3495 : /// Whether we should restore the original nonzero pattern for every Jacobian evaluation. This
3496 : /// option is useful if the sparsity pattern is constantly changing and you are using hash table
3497 : /// assembly or if you wish to continually restore the matrix to the originally preallocated
3498 : /// sparsity pattern computed by relationship managers.
3499 : const bool _restore_original_nonzero_pattern;
3500 : /// Whether to ignore zeros in the Jacobian, thereby leading to a reduced sparsity pattern
3501 : bool _ignore_zeros_in_jacobian;
3502 : /// Whether to preserve the system matrix / Jacobian sparsity pattern, using 0-valued entries usually
3503 : bool _preserve_matrix_sparsity_pattern;
3504 :
3505 : const bool _force_restart;
3506 : const bool _allow_ics_during_restart;
3507 : const bool _skip_nl_system_check;
3508 : bool _fail_next_system_convergence_check;
3509 : const bool _allow_invalid_solution;
3510 : const bool _show_invalid_solution_console;
3511 : const bool & _immediately_print_invalid_solution;
3512 :
3513 : /// At or beyond initialSteup stage
3514 : bool _started_initial_setup;
3515 :
3516 : /// Whether the problem has dgkernels or interface kernels
3517 : bool _has_internal_edge_residual_objects;
3518 :
3519 : /// Whether solution time derivative needs to be stored
3520 : bool _u_dot_requested;
3521 :
3522 : /// Whether solution second time derivative needs to be stored
3523 : bool _u_dotdot_requested;
3524 :
3525 : /// Whether old solution time derivative needs to be stored
3526 : bool _u_dot_old_requested;
3527 :
3528 : /// Whether old solution second time derivative needs to be stored
3529 : bool _u_dotdot_old_requested;
3530 :
3531 : friend class AuxiliarySystem;
3532 : friend class NonlinearSystemBase;
3533 : friend class MooseEigenSystem;
3534 : friend class Resurrector;
3535 : friend class Restartable;
3536 : friend class DisplacedProblem;
3537 :
3538 : /// Whether the simulation requires mortar coupling
3539 : bool _has_mortar;
3540 :
3541 : /// Number of steps in a grid sequence
3542 : unsigned int _num_grid_steps;
3543 :
3544 : /// Whether to trust the user coupling matrix no matter what. See
3545 : /// https://github.com/idaholab/moose/issues/16395 for detailed background
3546 : bool _trust_user_coupling_matrix = false;
3547 :
3548 : /// Flag used to indicate whether we are computing the scaling Jacobian
3549 : bool _computing_scaling_jacobian = false;
3550 :
3551 : /// Flag used to indicate whether we are computing the scaling Residual
3552 : bool _computing_scaling_residual = false;
3553 :
3554 : /// Flag used to indicate whether we are doing the uo/aux state check in execute
3555 : bool _checking_uo_aux_state = false;
3556 :
3557 : /// When to print the execution of loops
3558 : ExecFlagEnum _print_execution_on;
3559 :
3560 : /// Whether to identify variable groups in nonlinear systems. This affects dof ordering
3561 : const bool _identify_variable_groups_in_nl;
3562 :
3563 : /// A data member to store the residual vector tag(s) passed into \p computeResidualTag(s). This
3564 : /// data member will be used when APIs like \p cacheResidual, \p addCachedResiduals, etc. are
3565 : /// called
3566 : std::vector<VectorTag> _current_residual_vector_tags;
3567 :
3568 : /// Whether we are performing some calculations with finite volume discretizations
3569 : bool _have_fv = false;
3570 :
3571 : /// If we catch an exception during residual/Jacobian evaluaton for which we don't have specific
3572 : /// handling, immediately error instead of allowing the time step to be cut
3573 : const bool _regard_general_exceptions_as_errors;
3574 :
3575 : /// nonlocal coupling matrix
3576 : std::vector<libMesh::CouplingMatrix> _nonlocal_cm;
3577 :
3578 : /// nonlocal coupling requirement flag
3579 : bool _requires_nonlocal_coupling;
3580 :
3581 : #ifdef MOOSE_KOKKOS_ENABLED
3582 : /// Whether we have any Kokkos objects
3583 : bool _has_kokkos_objects = false;
3584 :
3585 : /// Whether we have any Kokkos residual objects
3586 : bool _has_kokkos_residual_objects = false;
3587 :
3588 : /// Container holding hooks for functions that need to be called after Kokkos mesh initialization
3589 : std::vector<std::function<void()>> _kokkos_mesh_initialization_hooks;
3590 : #endif
3591 :
3592 : friend void Moose::PetscSupport::setSinglePetscOption(const std::string & name,
3593 : const std::string & value,
3594 : FEProblemBase * const problem);
3595 : };
3596 :
3597 : using FVProblemBase = FEProblemBase;
3598 :
3599 : template <typename T>
3600 : void
3601 1612 : FEProblemBase::allowOutput(bool state)
3602 : {
3603 1612 : _app.getOutputWarehouse().allowOutput<T>(state);
3604 1612 : }
3605 :
3606 : template <typename T>
3607 : void
3608 295 : FEProblemBase::objectSetupHelper(const std::vector<T *> & objects, const ExecFlagType & exec_flag)
3609 : {
3610 295 : if (exec_flag == EXEC_INITIAL)
3611 : {
3612 590 : for (T * obj_ptr : objects)
3613 295 : obj_ptr->initialSetup();
3614 : }
3615 :
3616 0 : else if (exec_flag == EXEC_TIMESTEP_BEGIN)
3617 : {
3618 0 : for (const auto obj_ptr : objects)
3619 0 : obj_ptr->timestepSetup();
3620 : }
3621 0 : else if (exec_flag == EXEC_SUBDOMAIN)
3622 : {
3623 0 : for (const auto obj_ptr : objects)
3624 0 : obj_ptr->subdomainSetup();
3625 : }
3626 :
3627 0 : else if (exec_flag == EXEC_NONLINEAR)
3628 : {
3629 0 : for (const auto obj_ptr : objects)
3630 0 : obj_ptr->jacobianSetup();
3631 : }
3632 :
3633 0 : else if (exec_flag == EXEC_LINEAR)
3634 : {
3635 0 : for (const auto obj_ptr : objects)
3636 0 : obj_ptr->residualSetup();
3637 : }
3638 295 : }
3639 :
3640 : template <typename T>
3641 : void
3642 295 : FEProblemBase::objectExecuteHelper(const std::vector<T *> & objects)
3643 : {
3644 566 : for (T * obj_ptr : objects)
3645 295 : obj_ptr->execute();
3646 271 : }
3647 :
3648 : template <typename T>
3649 : std::vector<std::shared_ptr<T>>
3650 64451 : FEProblemBase::addObject(const std::string & type,
3651 : const std::string & name,
3652 : InputParameters & parameters,
3653 : const bool threaded,
3654 : const std::string & var_param_name)
3655 : {
3656 : parallel_object_only();
3657 :
3658 64451 : logAdd(MooseUtils::prettyCppType<T>(), name, type, parameters);
3659 : // Add the _subproblem and _sys parameters depending on use_displaced_mesh
3660 64451 : addObjectParamsHelper(parameters, name, var_param_name);
3661 :
3662 64451 : const auto n_threads = threaded ? libMesh::n_threads() : 1;
3663 64451 : std::vector<std::shared_ptr<T>> objects(n_threads);
3664 129748 : for (THREAD_ID tid = 0; tid < n_threads; ++tid)
3665 : {
3666 65354 : std::shared_ptr<T> obj = _factory.create<T>(type, name, parameters, tid);
3667 65297 : theWarehouse().add(obj);
3668 65297 : objects[tid] = std::move(obj);
3669 : }
3670 :
3671 64394 : return objects;
3672 24 : }
3673 :
3674 : inline NonlinearSystemBase &
3675 5091615 : FEProblemBase::getNonlinearSystemBase(const unsigned int sys_num)
3676 : {
3677 : mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
3678 5091615 : return *_nl[sys_num];
3679 : }
3680 :
3681 : inline const NonlinearSystemBase &
3682 499 : FEProblemBase::getNonlinearSystemBase(const unsigned int sys_num) const
3683 : {
3684 : mooseAssert(sys_num < _nl.size(), "System number greater than the number of nonlinear systems");
3685 499 : return *_nl[sys_num];
3686 : }
3687 :
3688 : inline SolverSystem &
3689 4600307 : FEProblemBase::getSolverSystem(const unsigned int sys_num)
3690 : {
3691 : mooseAssert(sys_num < _solver_systems.size(),
3692 : "System number greater than the number of solver systems");
3693 4600307 : return *_solver_systems[sys_num];
3694 : }
3695 :
3696 : inline const SolverSystem &
3697 : FEProblemBase::getSolverSystem(const unsigned int sys_num) const
3698 : {
3699 : mooseAssert(sys_num < _solver_systems.size(),
3700 : "System number greater than the number of solver systems");
3701 : return *_solver_systems[sys_num];
3702 : }
3703 :
3704 : inline NonlinearSystemBase &
3705 9047279 : FEProblemBase::currentNonlinearSystem()
3706 : {
3707 : mooseAssert(_current_nl_sys, "The nonlinear system is not currently set");
3708 9047279 : return *_current_nl_sys;
3709 : }
3710 :
3711 : inline const NonlinearSystemBase &
3712 478551123 : FEProblemBase::currentNonlinearSystem() const
3713 : {
3714 : mooseAssert(_current_nl_sys, "The nonlinear system is not currently set");
3715 478551123 : return *_current_nl_sys;
3716 : }
3717 :
3718 : inline LinearSystem &
3719 78767 : FEProblemBase::getLinearSystem(const unsigned int sys_num)
3720 : {
3721 : mooseAssert(sys_num < _linear_systems.size(),
3722 : "System number greater than the number of linear systems");
3723 78767 : return *_linear_systems[sys_num];
3724 : }
3725 :
3726 : inline const LinearSystem &
3727 : FEProblemBase::getLinearSystem(const unsigned int sys_num) const
3728 : {
3729 : mooseAssert(sys_num < _linear_systems.size(),
3730 : "System number greater than the number of linear systems");
3731 : return *_linear_systems[sys_num];
3732 : }
3733 :
3734 : inline LinearSystem &
3735 4281 : FEProblemBase::currentLinearSystem()
3736 : {
3737 : mooseAssert(_current_linear_sys, "The linear system is not currently set");
3738 4281 : return *_current_linear_sys;
3739 : }
3740 :
3741 : inline const LinearSystem &
3742 0 : FEProblemBase::currentLinearSystem() const
3743 : {
3744 : mooseAssert(_current_linear_sys, "The linear system is not currently set");
3745 0 : return *_current_linear_sys;
3746 : }
3747 :
3748 : inline Assembly &
3749 590512426 : FEProblemBase::assembly(const THREAD_ID tid, const unsigned int sys_num)
3750 : {
3751 : mooseAssert(tid < _assembly.size(), "Assembly objects not initialized");
3752 : mooseAssert(sys_num < _assembly[tid].size(),
3753 : "System number larger than the assembly container size");
3754 590512426 : return *_assembly[tid][sys_num];
3755 : }
3756 :
3757 : inline const Assembly &
3758 532156 : FEProblemBase::assembly(const THREAD_ID tid, const unsigned int sys_num) const
3759 : {
3760 : mooseAssert(tid < _assembly.size(), "Assembly objects not initialized");
3761 : mooseAssert(sys_num < _assembly[tid].size(),
3762 : "System number larger than the assembly container size");
3763 532156 : return *_assembly[tid][sys_num];
3764 : }
3765 :
3766 : inline const libMesh::CouplingMatrix *
3767 2537 : FEProblemBase::couplingMatrix(const unsigned int i) const
3768 : {
3769 2537 : return _cm[i].get();
3770 : }
3771 :
3772 : inline void
3773 : FEProblemBase::fvBCsIntegrityCheck(const bool fv_bcs_integrity_check)
3774 : {
3775 : if (!_fv_bcs_integrity_check)
3776 : // the user has requested that we don't check integrity so we will honor that
3777 : return;
3778 :
3779 : _fv_bcs_integrity_check = fv_bcs_integrity_check;
3780 : }
3781 :
3782 : inline const std::vector<VectorTag> &
3783 393284072 : FEProblemBase::currentResidualVectorTags() const
3784 : {
3785 393284072 : return _current_residual_vector_tags;
3786 : }
3787 :
3788 : inline void
3789 3059656 : FEProblemBase::setCurrentResidualVectorTags(const std::set<TagID> & vector_tags)
3790 : {
3791 3059656 : _current_residual_vector_tags = getVectorTags(vector_tags);
3792 3059656 : }
3793 :
3794 : inline void
3795 3541021 : FEProblemBase::clearCurrentResidualVectorTags()
3796 : {
3797 3541021 : _current_residual_vector_tags.clear();
3798 3541021 : }
3799 :
3800 : #ifdef MOOSE_KOKKOS_ENABLED
3801 : template <typename T>
3802 : T &
3803 153 : FEProblemBase::getKokkosFunction(const std::string & name)
3804 : {
3805 153 : if (!hasKokkosFunction(name))
3806 : {
3807 : // If we didn't find a function, it might be a default function, attempt to construct one now
3808 9 : std::istringstream ss(name);
3809 : Real real_value;
3810 :
3811 : // First see if it's just a constant. If it is, build a ConstantFunction
3812 9 : if (ss >> real_value && ss.eof())
3813 : {
3814 18 : InputParameters params = _factory.getValidParams("KokkosConstantFunction");
3815 18 : params.set<Real>("value") = real_value;
3816 27 : addKokkosFunction("KokkosConstantFunction", ss.str(), params);
3817 9 : }
3818 :
3819 : // Try once more
3820 9 : if (!hasKokkosFunction(name))
3821 0 : mooseError("Unable to find Kokkos function '" + name, "'");
3822 9 : }
3823 :
3824 153 : auto * const ret = dynamic_cast<T *>(_kokkos_functions.getActiveObject(name).get());
3825 153 : if (!ret)
3826 0 : mooseError("No Kokkos function named '", name, "' of appropriate type");
3827 :
3828 153 : return *ret;
3829 : }
3830 : #endif
|