]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PETScWrappers::TimeStepper: cannot change the pointers to the matrices
authorStefano Zampini <stefano.zampini@gmail.com>
Mon, 24 Jul 2023 22:04:50 +0000 (01:04 +0300)
committerStefano Zampini <stefano.zampini@gmail.com>
Mon, 24 Jul 2023 22:04:50 +0000 (01:04 +0300)
use MatCopy instead (just to make sure....)

include/deal.II/lac/petsc_ts.templates.h

index ad2d87ded1421ca0882ff88b29f95952cf2c77ef..2b8fadd5da8868d6f730e03c3bf0f578ea7f48e4 100644 (file)
@@ -746,13 +746,8 @@ namespace PETScWrappers
       PetscFunctionBeginUser;
       auto user = static_cast<TimeStepper *>(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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.