]> https://gitweb.dealii.org/ - dealii.git/commitdiff
implement Wolfgang's comments
authorStefano Zampini <stefano.zampini@gmail.com>
Tue, 1 Aug 2023 14:43:50 +0000 (16:43 +0200)
committerStefano Zampini <stefano.zampini@gmail.com>
Tue, 1 Aug 2023 14:43:50 +0000 (16:43 +0200)
include/deal.II/lac/petsc_ts.h
include/deal.II/lac/petsc_ts.templates.h
tests/petsc/petsc_ts_03.cc

index 72b6e818f7f7fd759e30df51acc1b9d72ed22cf5..a994e8b146ed136761f7578088b04d5dc828a539 100644 (file)
@@ -269,19 +269,20 @@ namespace PETScWrappers
    *    and TimeStepper::explicit_jacobian.
    *  - deal.II style using TimeStepper::setup_jacobian and
    *    TimeStepper::solve_with_jacobian.
-   * The preconditioning matrix can be specified using TimeStepper::set_matrix.
-   * In case both approaches are implemented, the deal.II style will be used.
+   * The preconditioning matrix can be specified using
+   * TimeStepper::set_matrix(). In case both approaches are implemented, the
+   * deal.II style will be used.
    *
-   * TimeStepper::set_matrices must be used in case the user wants to provide
+   * TimeStepper::set_matrices() must be used in case the user wants to provide
    * the iteration matrix of the tangent system in the deal.II style approach,
    * thus replacing the matrix-free linearization.
    *
    * The correctness of the constructed Jacobians passed using
-   * TimeStepper::set_matrix can be checked using
+   * TimeStepper::set_matrix() can be checked using
    * @code
    * ./myApp -snes_test_jacobian
    * @endcode
-   * See TimeStepper::set_matrix and TimeStepper::set_matrices for
+   * See TimeStepper::set_matrix() and TimeStepper::set_matrices() for
    * additional details.
    *
    * The deal.II style approach still allows command line customization, like
@@ -618,7 +619,7 @@ namespace PETScWrappers
     std::function<void(const real_type t, VectorType &y)> distribute;
 
     /**
-     * Callback to setup mesh adaption.
+     * Callback to set up mesh adaption.
      *
      * Implementation of this function is optional.
      * @p resize must be set to true if mesh adaption is to be performed, false
@@ -637,13 +638,13 @@ namespace PETScWrappers
                        const unsigned int step,
                        const VectorType & y,
                        bool &             resize)>
-      prepare_for_coarsening_and_refinement;
+      decide_for_coarsening_and_refinement;
 
     /**
      * Callback to interpolate vectors and perform mesh adaption.
      *
      * Implementation of this function is mandatory if
-     * TimeStepper::prepare_for_coarsening_and_refinement is used.
+     * TimeStepper::decide_for_coarsening_and_refinement is used.
      * This function must perform mesh adaption and interpolate the discrete
      * functions that are stored in @p all_in onto the refined and/or coarsenend grid.
      * Output vectors must be created inside the callback.
index 2b8fadd5da8868d6f730e03c3bf0f578ea7f48e4..747b23583c950e6a1c4516656f4259f229c50a58 100644 (file)
@@ -439,7 +439,7 @@ namespace PETScWrappers
 
       const int lineno = __LINE__;
       const int err    = call_and_possibly_capture_ts_exception(
-        user->prepare_for_coarsening_and_refinement,
+        user->decide_for_coarsening_and_refinement,
         user->pending_exception,
         []() -> void {},
         t,
@@ -451,7 +451,7 @@ namespace PETScWrappers
         return PetscError(
           PetscObjectComm((PetscObject)ts),
           lineno + 1,
-          "prepare_for_coarsening_and_refinement",
+          "decide_for_coarsening_and_refinement",
           __FILE__,
           PETSC_ERR_LIB,
           PETSC_ERROR_INITIAL,
@@ -532,9 +532,13 @@ namespace PETScWrappers
       PetscCall(TSGetApplicationContext(ts, &ctx));
       auto user = static_cast<TimeStepper *>(ctx);
 
-      PetscErrorCode (
-        *transfer_setup)(TS, PetscInt, PetscReal, Vec, PetscBool *, void *);
-      PetscErrorCode (*transfer)(TS, PetscInt, Vec[], Vec[], void *);
+      using transfer_setup_fn =
+        PetscErrorCode (*)(TS, PetscInt, PetscReal, Vec, PetscBool *, void *);
+      using transfer_fn =
+        PetscErrorCode (*)(TS, PetscInt, Vec[], Vec[], void *);
+      transfer_setup_fn transfer_setup;
+      transfer_fn       transfer;
+
       AssertPETSc(PetscObjectQueryFunction((PetscObject)ts,
                                            "__dealii_ts_resize_setup__",
                                            &transfer_setup));
@@ -546,7 +550,7 @@ namespace PETScWrappers
       Vec       x;
       PetscCall(TSGetSolution(ts, &x));
       PetscCall(PetscObjectReference((PetscObject)x));
-      PetscCall((*transfer_setup)(
+      PetscCall(transfer_setup(
         ts, user->get_step_number(), user->get_time(), x, &resize, user));
 
       if (resize)
@@ -558,7 +562,7 @@ namespace PETScWrappers
           // Reinitialize DM. Currently it is not possible to do with public API
           ts_reset_dm(ts);
 
-          PetscCall((*transfer)(ts, 1, &x, &new_x, user));
+          PetscCall(transfer(ts, 1, &x, &new_x, user));
           PetscCall(TSSetSolution(ts, new_x));
           PetscCall(VecDestroy(&new_x));
         }
@@ -1035,7 +1039,7 @@ namespace PETScWrappers
       AssertPETSc(TSMonitorSet(ts, ts_monitor, this, nullptr));
 
     // Handle AMR.
-    if (prepare_for_coarsening_and_refinement)
+    if (decide_for_coarsening_and_refinement)
       {
         AssertThrow(interpolate,
                     StandardExceptions::ExcFunctionNotProvided("interpolate"));
@@ -1129,14 +1133,8 @@ namespace PETScWrappers
   unsigned int TimeStepper<VectorType, PMatrixType, AMatrixType>::solve(
     VectorType &y)
   {
-    try
-      {
-        setup_callbacks();
-      }
-    catch (...)
-      {
-        throw;
-      }
+    // Set up PETSc data structure.
+    setup_callbacks();
 
     // Set solution vector.
     AssertPETSc(TSSetSolution(ts, y.petsc_vector()));
@@ -1147,14 +1145,7 @@ namespace PETScWrappers
 
     // Handle algebraic components. This must be done when we know the layout
     // of the solution vector.
-    try
-      {
-        setup_algebraic_constraints(y);
-      }
-    catch (...)
-      {
-        throw;
-      }
+    setup_algebraic_constraints(y);
 
     // Having set everything up, now do the actual work
     // and let PETSc do the time stepping. If there is
index d98fd0b03ee1f83bf30a1be11e184f7d5a79648b..88f73d0d9d76e5c333fa337b52efd911ed7bcc3b 100644 (file)
@@ -178,7 +178,7 @@ public:
     };
 
     // This callback is used to decide to remesh.
-    time_stepper.prepare_for_coarsening_and_refinement =
+    time_stepper.decide_for_coarsening_and_refinement =
       [&](const real_type    t,
           const unsigned int step,
           const VectorType &,
@@ -187,7 +187,7 @@ public:
       resize = (step && step % 5 == 0);
     };
 
-    // This callback is called if prepare_for_coarsening_and_refinement sets
+    // This callback is called if decide_for_coarsening_and_refinement sets
     // resize to true.
     time_stepper.interpolate = [&](const std::vector<VectorType> &all_in,
                                    std::vector<VectorType> &all_out) -> void {

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.