]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Sundials: Replace realtype with sunrealtype from SUNDIALS 6.0 on
authorDaniel Arndt <arndtd@ornl.gov>
Wed, 15 Nov 2023 23:07:45 +0000 (16:07 -0700)
committerDaniel Arndt <arndtd@ornl.gov>
Thu, 16 Nov 2023 06:03:18 +0000 (23:03 -0700)
include/deal.II/sundials/n_vector.templates.h
source/sundials/arkode.cc
source/sundials/ida.cc
source/sundials/kinsol.cc
source/sundials/sunlinsol_wrapper.cc
tests/sundials/arkode_06.cc
tests/sundials/arkode_07.cc

index 7f7eaad67dc2318996a8ca12365894c7f13b1c7f..1fe1c0cf9a702bc7dd8790f36b70adc77e4bdaa3 100644 (file)
@@ -176,6 +176,12 @@ namespace SUNDIALS
      */
     namespace NVectorOperations
     {
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+      using realtype = ::sunrealtype;
+#  else
+      using realtype = ::realtype;
+#  endif
+
       N_Vector_ID
       get_vector_id(N_Vector v);
 
index 1dab8304da4e779747d5ba2956c2b20e1ef95b0e..a27a52a06e6a72b508a4136c54756cb60b508c05 100644 (file)
@@ -269,8 +269,15 @@ namespace SUNDIALS
     Assert(explicit_function || implicit_function,
            ExcFunctionNotProvided("explicit_function || implicit_function"));
 
-    auto explicit_function_callback =
-      [](realtype tt, N_Vector yy, N_Vector yp, void *user_data) -> int {
+    auto explicit_function_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                        sunrealtype tt,
+#  else
+                                        realtype tt,
+#  endif
+                                        N_Vector yy,
+                                        N_Vector yp,
+                                        void    *user_data) -> int {
       Assert(user_data != nullptr, ExcInternalError());
       ARKode<VectorType> &solver =
         *static_cast<ARKode<VectorType> *>(user_data);
@@ -287,8 +294,15 @@ namespace SUNDIALS
     };
 
 
-    auto implicit_function_callback =
-      [](realtype tt, N_Vector yy, N_Vector yp, void *user_data) -> int {
+    auto implicit_function_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                        sunrealtype tt,
+#  else
+                                        realtype tt,
+#  endif
+                                        N_Vector yy,
+                                        N_Vector yp,
+                                        void    *user_data) -> int {
       Assert(user_data != nullptr, ExcInternalError());
       ARKode<VectorType> &solver =
         *static_cast<ARKode<VectorType> *>(user_data);
@@ -416,7 +430,11 @@ namespace SUNDIALS
 
         auto jacobian_times_vector_callback = [](N_Vector v,
                                                  N_Vector Jv,
-                                                 realtype t,
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                 sunrealtype t,
+#  else
+                                                 realtype      t,
+#  endif
                                                  N_Vector y,
                                                  N_Vector fy,
                                                  void    *user_data,
@@ -441,8 +459,15 @@ namespace SUNDIALS
             *src_fy);
         };
 
-        auto jacobian_times_vector_setup_callback =
-          [](realtype t, N_Vector y, N_Vector fy, void *user_data) -> int {
+        auto jacobian_times_vector_setup_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                      sunrealtype t,
+#  else
+                                                      realtype t,
+#  endif
+                                                      N_Vector y,
+                                                      N_Vector fy,
+                                                      void *user_data) -> int {
           Assert(user_data != nullptr, ExcInternalError());
           ARKode<VectorType> &solver =
             *static_cast<ARKode<VectorType> *>(user_data);
@@ -465,15 +490,25 @@ namespace SUNDIALS
         AssertARKode(status);
         if (jacobian_preconditioner_solve)
           {
-            auto solve_with_jacobian_callback = [](realtype t,
-                                                   N_Vector y,
-                                                   N_Vector fy,
-                                                   N_Vector r,
-                                                   N_Vector z,
-                                                   realtype gamma,
-                                                   realtype delta,
-                                                   int      lr,
-                                                   void    *user_data) -> int {
+            auto solve_with_jacobian_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                  sunrealtype t,
+#  else
+                                                  realtype   t,
+#  endif
+                                                  N_Vector y,
+                                                  N_Vector fy,
+                                                  N_Vector r,
+                                                  N_Vector z,
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                  sunrealtype gamma,
+                                                  sunrealtype delta,
+#  else
+                                                  realtype   gamma,
+                                                  realtype   delta,
+#  endif
+                                                  int   lr,
+                                                  void *user_data) -> int {
               Assert(user_data != nullptr, ExcInternalError());
               ARKode<VectorType> &solver =
                 *static_cast<ARKode<VectorType> *>(user_data);
@@ -497,13 +532,22 @@ namespace SUNDIALS
                 lr);
             };
 
-            auto jacobian_solver_setup_callback = [](realtype     t,
-                                                     N_Vector     y,
-                                                     N_Vector     fy,
-                                                     booleantype  jok,
-                                                     booleantype *jcurPtr,
-                                                     realtype     gamma,
-                                                     void *user_data) -> int {
+            auto jacobian_solver_setup_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                    sunrealtype t,
+#  else
+                                                    realtype t,
+#  endif
+                                                    N_Vector     y,
+                                                    N_Vector     fy,
+                                                    booleantype  jok,
+                                                    booleantype *jcurPtr,
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                    sunrealtype gamma,
+#  else
+                                                    realtype gamma,
+#  endif
+                                                    void *user_data) -> int {
               Assert(user_data != nullptr, ExcInternalError());
               ARKode<VectorType> &solver =
                 *static_cast<ARKode<VectorType> *>(user_data);
@@ -621,7 +665,13 @@ namespace SUNDIALS
         AssertARKode(status);
 
         auto mass_matrix_times_vector_setup_callback =
-          [](realtype t, void *mtimes_data) -> int {
+          [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+            sunrealtype t,
+#  else
+            realtype                                         t,
+#  endif
+            void *mtimes_data) -> int {
           Assert(mtimes_data != nullptr, ExcInternalError());
           ARKode<VectorType> &solver =
             *static_cast<ARKode<VectorType> *>(mtimes_data);
@@ -630,8 +680,14 @@ namespace SUNDIALS
             solver.mass_times_setup, solver.pending_exception, t);
         };
 
-        auto mass_matrix_times_vector_callback =
-          [](N_Vector v, N_Vector Mv, realtype t, void *mtimes_data) -> int {
+        auto mass_matrix_times_vector_callback = [](N_Vector v,
+                                                    N_Vector Mv,
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                    sunrealtype t,
+#  else
+                                                    realtype t,
+#  endif
+                                                    void *mtimes_data) -> int {
           Assert(mtimes_data != nullptr, ExcInternalError());
           ARKode<VectorType> &solver =
             *static_cast<ARKode<VectorType> *>(mtimes_data);
@@ -657,8 +713,13 @@ namespace SUNDIALS
 
         if (mass_preconditioner_solve)
           {
-            auto mass_matrix_solver_setup_callback =
-              [](realtype t, void *user_data) -> int {
+            auto mass_matrix_solver_setup_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                       sunrealtype t,
+#  else
+                                                       realtype t,
+#  endif
+                                                       void *user_data) -> int {
               Assert(user_data != nullptr, ExcInternalError());
               ARKode<VectorType> &solver =
                 *static_cast<ARKode<VectorType> *>(user_data);
@@ -667,12 +728,21 @@ namespace SUNDIALS
                 solver.mass_preconditioner_setup, solver.pending_exception, t);
             };
 
-            auto solve_with_mass_matrix_callback = [](realtype t,
-                                                      N_Vector r,
-                                                      N_Vector z,
-                                                      realtype delta,
-                                                      int      lr,
-                                                      void *user_data) -> int {
+            auto solve_with_mass_matrix_callback = [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                     sunrealtype t,
+#  else
+                                                     realtype   t,
+#  endif
+                                                     N_Vector r,
+                                                     N_Vector z,
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                                                     sunrealtype delta,
+#  else
+                                                     realtype   delta,
+#  endif
+                                                     int   lr,
+                                                     void *user_data) -> int {
               Assert(user_data != nullptr, ExcInternalError());
               ARKode<VectorType> &solver =
                 *static_cast<ARKode<VectorType> *>(user_data);
index 7edaedf3da3fb4a3ce66ab9973fae1bd258037e9..ee26b25fa6977bed6018beaa2eef1888d1b98543 100644 (file)
@@ -227,8 +227,16 @@ namespace SUNDIALS
 
     status = IDAInit(
       ida_mem,
-      [](realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, void *user_data)
-        -> int {
+      [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+        sunrealtype tt,
+#  else
+        realtype tt,
+#  endif
+        N_Vector yy,
+        N_Vector yp,
+        N_Vector rr,
+        void    *user_data) -> int {
         IDA<VectorType> &solver = *static_cast<IDA<VectorType> *>(user_data);
 
         auto *src_yy   = internal::unwrap_nvector_const<VectorType>(yy);
@@ -313,7 +321,7 @@ namespace SUNDIALS
 #  if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
     LS = SUNLinSolNewEmpty();
 #  else
-    LS      = SUNLinSolNewEmpty(ida_ctx);
+    LS = SUNLinSolNewEmpty(ida_ctx);
 #  endif
 
     LS->content = this;
@@ -343,7 +351,12 @@ namespace SUNDIALS
                         SUNMatrix /*ignored*/,
                         N_Vector x,
                         N_Vector b,
-                        realtype tol) -> int {
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                        sunrealtype tol
+#  else
+                        realtype tol
+#  endif
+                        ) -> int {
       IDA<VectorType> &solver = *static_cast<IDA<VectorType> *>(LS->content);
 
       auto *src_b = internal::unwrap_nvector_const<VectorType>(b);
@@ -378,7 +391,7 @@ namespace SUNDIALS
 #  if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
     J = SUNMatNewEmpty();
 #  else
-    J       = SUNMatNewEmpty(ida_ctx);
+    J = SUNMatNewEmpty(ida_ctx);
 #  endif
     J->content = this;
 
@@ -411,16 +424,22 @@ namespace SUNDIALS
     // calling IDASetLinearSolver
     status = IDASetJacFn(
       ida_mem,
-      [](realtype tt,
-         realtype cj,
-         N_Vector yy,
-         N_Vector yp,
-         N_Vector /* residual */,
-         SUNMatrix /* ignored */,
-         void *user_data,
-         N_Vector /* tmp1 */,
-         N_Vector /* tmp2 */,
-         N_Vector /* tmp3 */) -> int {
+      [](
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+        sunrealtype tt,
+        sunrealtype cj,
+#  else
+        realtype tt,
+        realtype cj,
+#  endif
+        N_Vector yy,
+        N_Vector yp,
+        N_Vector /* residual */,
+        SUNMatrix /* ignored */,
+        void *user_data,
+        N_Vector /* tmp1 */,
+        N_Vector /* tmp2 */,
+        N_Vector /* tmp3 */) -> int {
         Assert(user_data != nullptr, ExcInternalError());
         IDA<VectorType> &solver = *static_cast<IDA<VectorType> *>(user_data);
 
index d4ec60ab9fbeaee5834e6ee7cbb876cbc9294548..f80fe1d73c973f4498f8235ee40c64813cd133b4 100644 (file)
@@ -364,7 +364,12 @@ namespace SUNDIALS
                             SUNMatrix /*ignored*/,
                             N_Vector x,
                             N_Vector b,
-                            realtype tol) -> int {
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                            sunrealtype tol
+#  else
+                            realtype tol
+#  endif
+                            ) -> int {
           // Receive the object that describes the linear solver and
           // unpack the pointer to the KINSOL object from which we can then
           // get the 'reinit' and 'solve' functions.
@@ -394,7 +399,7 @@ namespace SUNDIALS
 #  if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
         J = SUNMatNewEmpty();
 #  else
-        J  = SUNMatNewEmpty(kinsol_ctx);
+        J = SUNMatNewEmpty(kinsol_ctx);
 #  endif
         J->content = this;
 
index 0cb81695154d28e10f9e0770855cfbb1a41055e5..45101dcf5b76ba781267c87fd092a232f89090e5 100644 (file)
@@ -197,7 +197,12 @@ namespace SUNDIALS
                         SUNMatrix /*ignored*/,
                         N_Vector x,
                         N_Vector b,
-                        realtype tol)
+#  if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                        sunrealtype tol
+#  else
+                        realtype tol
+#  endif
+    )
     {
       LinearSolverContent<VectorType> *content = access_content<VectorType>(LS);
 
index 4218fc7ad6e8602e7d488547ff462a2c6d9073a5..701cb3829b5c791ddeedf72798f633f3069c928a 100644 (file)
@@ -95,11 +95,17 @@ main()
   };
 
 
-  ode.jacobian_times_setup =
-    [&](realtype t, const VectorType &y, const VectorType &fy) {
-      J       = 0;
-      J(2, 2) = -1.0 / eps;
-    };
+  ode.jacobian_times_setup = [&](
+#if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                               sunrealtype t,
+#else
+                               realtype t,
+#endif
+                               const VectorType &y,
+                               const VectorType &fy) {
+    J       = 0;
+    J(2, 2) = -1.0 / eps;
+  };
 
   ode.jacobian_times_vector = [&](const VectorType &v,
                                   VectorType       &Jv,
index f228c0f0f0e310f201c64eb68926491edde7916d..1e715c40f89d6600b91dcd986987fd89e5d35df5 100644 (file)
@@ -95,11 +95,17 @@ main()
   };
 
 
-  ode.jacobian_times_setup =
-    [&](realtype t, const VectorType &y, const VectorType &fy) {
-      J       = 0;
-      J(2, 2) = -1.0 / eps;
-    };
+  ode.jacobian_times_setup = [&](
+#if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
+                               sunrealtype t,
+#else
+                               realtype t,
+#endif
+                               const VectorType &y,
+                               const VectorType &fy) {
+    J       = 0;
+    J(2, 2) = -1.0 / eps;
+  };
 
   ode.jacobian_times_vector = [&](const VectorType &v,
                                   VectorType       &Jv,

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.