From 055935d9b85684edbd7f6ee0792a4db0dbc2f16a Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 15 Nov 2023 16:07:45 -0700 Subject: [PATCH] Sundials: Replace realtype with sunrealtype from SUNDIALS 6.0 on --- include/deal.II/sundials/n_vector.templates.h | 6 + source/sundials/arkode.cc | 138 +++++++++++++----- source/sundials/ida.cc | 49 +++++-- source/sundials/kinsol.cc | 9 +- source/sundials/sunlinsol_wrapper.cc | 7 +- tests/sundials/arkode_06.cc | 16 +- tests/sundials/arkode_07.cc | 16 +- 7 files changed, 179 insertions(+), 62 deletions(-) diff --git a/include/deal.II/sundials/n_vector.templates.h b/include/deal.II/sundials/n_vector.templates.h index 7f7eaad67d..1fe1c0cf9a 100644 --- a/include/deal.II/sundials/n_vector.templates.h +++ b/include/deal.II/sundials/n_vector.templates.h @@ -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); diff --git a/source/sundials/arkode.cc b/source/sundials/arkode.cc index 1dab8304da..a27a52a06e 100644 --- a/source/sundials/arkode.cc +++ b/source/sundials/arkode.cc @@ -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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(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 &solver = *static_cast *>(user_data); diff --git a/source/sundials/ida.cc b/source/sundials/ida.cc index 7edaedf3da..ee26b25fa6 100644 --- a/source/sundials/ida.cc +++ b/source/sundials/ida.cc @@ -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 &solver = *static_cast *>(user_data); auto *src_yy = internal::unwrap_nvector_const(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 &solver = *static_cast *>(LS->content); auto *src_b = internal::unwrap_nvector_const(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 &solver = *static_cast *>(user_data); diff --git a/source/sundials/kinsol.cc b/source/sundials/kinsol.cc index d4ec60ab9f..f80fe1d73c 100644 --- a/source/sundials/kinsol.cc +++ b/source/sundials/kinsol.cc @@ -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; diff --git a/source/sundials/sunlinsol_wrapper.cc b/source/sundials/sunlinsol_wrapper.cc index 0cb8169515..45101dcf5b 100644 --- a/source/sundials/sunlinsol_wrapper.cc +++ b/source/sundials/sunlinsol_wrapper.cc @@ -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 *content = access_content(LS); diff --git a/tests/sundials/arkode_06.cc b/tests/sundials/arkode_06.cc index 4218fc7ad6..701cb3829b 100644 --- a/tests/sundials/arkode_06.cc +++ b/tests/sundials/arkode_06.cc @@ -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, diff --git a/tests/sundials/arkode_07.cc b/tests/sundials/arkode_07.cc index f228c0f0f0..1e715c40f8 100644 --- a/tests/sundials/arkode_07.cc +++ b/tests/sundials/arkode_07.cc @@ -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, -- 2.39.5