From c5af6646e55535057a0f4613a832d06a566448af Mon Sep 17 00:00:00 2001 From: Alex Lindsay Date: Sun, 7 Apr 2024 00:33:08 -0700 Subject: [PATCH] Must compute time derivatives ahead of Jacobian for coloring With the change to not compute a pre-SMO residual, when we are computing a finite difference Jacobian via coloring, the initial Jacobian computation happens before any residual evaluations. In this case we must ensure that we compute time derivatives on the `NONLINEAR` exec flag Refs #23472 --- framework/include/systems/NonlinearSystem.h | 2 ++ framework/include/systems/SolverSystem.h | 7 +++++++ framework/src/systems/NonlinearSystem.C | 4 ++-- framework/src/systems/SolverSystem.C | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/include/systems/NonlinearSystem.h b/framework/include/systems/NonlinearSystem.h index a561d9ce6299..a48b5912b8b8 100644 --- a/framework/include/systems/NonlinearSystem.h +++ b/framework/include/systems/NonlinearSystem.h @@ -100,5 +100,7 @@ class NonlinearSystem : public NonlinearSystemBase */ void setupColoringFiniteDifferencedPreconditioner(); + virtual bool matrixFromColoring() const override { return _use_coloring_finite_difference; } + bool _use_coloring_finite_difference; }; diff --git a/framework/include/systems/SolverSystem.h b/framework/include/systems/SolverSystem.h index f1deea119c9d..fc45dcd67170 100644 --- a/framework/include/systems/SolverSystem.h +++ b/framework/include/systems/SolverSystem.h @@ -85,6 +85,13 @@ class SolverSystem : public SystemBase /// Boolean to see if solution is invalid bool _solution_is_invalid; + +private: + /** + * Whether a system matrix is formed from coloring. This influences things like when to compute + * time derivatives + */ + virtual bool matrixFromColoring() const { return false; } }; inline const NumericVector * const & diff --git a/framework/src/systems/NonlinearSystem.C b/framework/src/systems/NonlinearSystem.C index b9422eaa8357..953ff165810c 100644 --- a/framework/src/systems/NonlinearSystem.C +++ b/framework/src/systems/NonlinearSystem.C @@ -232,14 +232,14 @@ NonlinearSystem::setupFiniteDifferencedPreconditioner() if (fdp->finiteDifferenceType() == "coloring") { - setupColoringFiniteDifferencedPreconditioner(); _use_coloring_finite_difference = true; + setupColoringFiniteDifferencedPreconditioner(); } else if (fdp->finiteDifferenceType() == "standard") { - setupStandardFiniteDifferencedPreconditioner(); _use_coloring_finite_difference = false; + setupStandardFiniteDifferencedPreconditioner(); } else mooseError("Unknown finite difference type"); diff --git a/framework/src/systems/SolverSystem.C b/framework/src/systems/SolverSystem.C index 84af4ce50088..868a7f2bdc7f 100644 --- a/framework/src/systems/SolverSystem.C +++ b/framework/src/systems/SolverSystem.C @@ -135,7 +135,7 @@ SolverSystem::compute(const ExecFlagType type) compute_tds = true; else if (type == EXEC_NONLINEAR) { - if (_fe_problem.computingScalingJacobian()) + if (_fe_problem.computingScalingJacobian() || matrixFromColoring()) compute_tds = true; } else if ((type == EXEC_TIMESTEP_END) || (type == EXEC_FINAL))