From efe5165439236bccbfbf94fab24020d9d471f228 Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Tue, 25 Jul 2023 01:04:50 +0300 Subject: [PATCH] PETScWrappers::TimeStepper: cannot change the pointers to the matrices use MatCopy instead (just to make sure....) --- include/deal.II/lac/petsc_ts.templates.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/deal.II/lac/petsc_ts.templates.h b/include/deal.II/lac/petsc_ts.templates.h index ad2d87ded1..2b8fadd5da 100644 --- a/include/deal.II/lac/petsc_ts.templates.h +++ b/include/deal.II/lac/petsc_ts.templates.h @@ -746,13 +746,8 @@ namespace PETScWrappers PetscFunctionBeginUser; auto user = static_cast(ctx); - VectorType xdealii(x); - VectorType xdotdealii(xdot); - AMatrixType Adealii(A); - PMatrixType Pdealii(P); - - user->A = &Adealii; - user->P = &Pdealii; + VectorType xdealii(x); + VectorType xdotdealii(xdot); const int lineno = __LINE__; const int err = call_and_possibly_capture_ts_exception( @@ -776,6 +771,13 @@ namespace PETScWrappers PETSC_ERR_LIB, PETSC_ERROR_INITIAL, "Failure in ts_ijacobian_with_setup from dealii::PETScWrappers::TimeStepper"); + // The MatCopy calls below are 99% of the times dummy calls. + // They are only used in case we get different Mats then the one we passed + // to TSSetIJacobian. + if (user->P) + PetscCall(MatCopy(user->P->petsc_matrix(), P, SAME_NONZERO_PATTERN)); + if (user->A) + PetscCall(MatCopy(user->A->petsc_matrix(), A, SAME_NONZERO_PATTERN)); petsc_increment_state_counter(P); // Handle older versions of PETSc for which we cannot pass a MATSHELL -- 2.39.5