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