From: Marc Fehling Date: Fri, 12 Apr 2024 09:02:39 +0000 (+0200) Subject: Use correct types for sundials 7. X-Git-Tag: v9.6.0-rc1~375^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b2e9022048de3254347eb9d2cdd9a63faa45b2;p=dealii.git Use correct types for sundials 7. --- diff --git a/include/deal.II/sundials/sunlinsol_wrapper.h b/include/deal.II/sundials/sunlinsol_wrapper.h index eeb98898cc..107b768f87 100644 --- a/include/deal.II/sundials/sunlinsol_wrapper.h +++ b/include/deal.II/sundials/sunlinsol_wrapper.h @@ -59,7 +59,9 @@ namespace SUNDIALS * @param a_times_fn A function pointer to the function that computes A*v * @param linsol_ctx The context object used to set up the linear solver and all vectors */ - SundialsOperator(void *A_data, ATimesFn a_times_fn, SUNContext linsol_ctx); + SundialsOperator(void *A_data, + SUNATimesFn a_times_fn, + SUNContext linsol_ctx); # else /** * Constructor. @@ -76,17 +78,23 @@ namespace SUNDIALS */ void *A_data; +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) /** * %Function pointer declared by SUNDIALS to evaluate the matrix vector * product. */ - ATimesFn a_times_fn; + SUNATimesFn a_times_fn; -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) /** * Context object used for SUNDIALS logging. */ SUNContext linsol_ctx; +# else + /** + * %Function pointer declared by SUNDIALS to evaluate the matrix vector + * product. + */ + ATimesFn a_times_fn; # endif }; @@ -124,10 +132,10 @@ namespace SUNDIALS * 6.0.0. If you are using an earlier version of SUNDIALS then you need to * use the other constructor. */ - SundialsPreconditioner(void *P_data, - PSolveFn p_solve_fn, - SUNContext linsol_ctx, - double tol); + SundialsPreconditioner(void *P_data, + SUNPSolveFn p_solve_fn, + SUNContext linsol_ctx, + double tol); # else /** * Constructor. @@ -150,17 +158,23 @@ namespace SUNDIALS */ void *P_data; +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) /** * %Function pointer to a function that computes the preconditioner * application. */ - PSolveFn p_solve_fn; + SUNPSolveFn p_solve_fn; -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) /** * Context object used for SUNDIALS logging. */ SUNContext linsol_ctx; +# else + /** + * %Function pointer to a function that computes the preconditioner + * application. + */ + PSolveFn p_solve_fn; # endif /** diff --git a/source/sundials/arkode.cc b/source/sundials/arkode.cc index 38d8ca06f3..a1a9092901 100644 --- a/source/sundials/arkode.cc +++ b/source/sundials/arkode.cc @@ -69,12 +69,19 @@ namespace SUNDIALS { set_functions_to_trigger_an_assert(); -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) // SUNDIALS will always duplicate communicators if we provide them. This // can cause problems if SUNDIALS is configured with MPI and we pass along // MPI_COMM_SELF in a serial application as MPI won't be // initialized. Hence, work around that by just not providing a // communicator in that case. +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + const int status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &arkode_ctx); + (void)status; + AssertARKode(status); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) const int status = SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? nullptr : &mpi_communicator, @@ -239,9 +246,20 @@ namespace SUNDIALS int status; (void)status; -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) status = SUNContext_Free(&arkode_ctx); AssertARKode(status); + + // Same comment applies as in class constructor: + status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &arkode_ctx); + AssertARKode(status); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + status = SUNContext_Free(&arkode_ctx); + AssertARKode(status); + // Same comment applies as in class constructor: status = SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? nullptr : @@ -409,7 +427,7 @@ namespace SUNDIALS # else sun_linear_solver = SUNLinSol_SPGMR(y_template, - PREC_NONE, + SUN_PREC_NONE, 0 /*krylov subvectors, 0 uses default*/, arkode_ctx); # endif @@ -505,8 +523,13 @@ namespace SUNDIALS auto jacobian_solver_setup_callback = [](SUNDIALS::realtype t, N_Vector y, N_Vector fy, - booleantype jok, - booleantype *jcurPtr, +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + sunbooleantype jok, + sunbooleantype *jcurPtr, +# else + booleantype jok, + booleantype *jcurPtr, +# endif SUNDIALS::realtype gamma, void *user_data) -> int { Assert(user_data != nullptr, ExcInternalError()); @@ -612,13 +635,20 @@ namespace SUNDIALS # else sun_mass_linear_solver = SUNLinSol_SPGMR(y_template, - PREC_NONE, + SUN_PREC_NONE, 0 /*krylov subvectors, 0 uses default*/, arkode_ctx); # endif } + +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + sunbooleantype mass_time_dependent = + data.mass_is_time_independent ? SUNFALSE : SUNTRUE; +# else booleantype mass_time_dependent = data.mass_is_time_independent ? SUNFALSE : SUNTRUE; +# endif + status = ARKStepSetMassLinearSolver(arkode_mem, sun_mass_linear_solver, nullptr, diff --git a/source/sundials/ida.cc b/source/sundials/ida.cc index 65a7093ab7..e9d137a629 100644 --- a/source/sundials/ida.cc +++ b/source/sundials/ida.cc @@ -61,12 +61,21 @@ namespace SUNDIALS , mpi_communicator(mpi_comm) , pending_exception(nullptr) { + set_functions_to_trigger_an_assert(); + // SUNDIALS will always duplicate communicators if we provide them. This // can cause problems if SUNDIALS is configured with MPI and we pass along // MPI_COMM_SELF in a serial application as MPI won't be // initialized. Hence, work around that by just not providing a // communicator in that case. -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + const int status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &ida_ctx); + (void)status; + AssertIDA(status); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) const int status = SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? nullptr : &mpi_communicator, @@ -74,7 +83,6 @@ namespace SUNDIALS (void)status; AssertIDA(status); # endif - set_functions_to_trigger_an_assert(); } @@ -187,7 +195,17 @@ namespace SUNDIALS int status; (void)status; -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + status = SUNContext_Free(&ida_ctx); + AssertIDA(status); + + // Same comment applies as in class constructor: + status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &ida_ctx); + AssertIDA(status); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) status = SUNContext_Free(&ida_ctx); AssertIDA(status); diff --git a/source/sundials/kinsol.cc b/source/sundials/kinsol.cc index 34fbc8cc80..7ad8d70afd 100644 --- a/source/sundials/kinsol.cc +++ b/source/sundials/kinsol.cc @@ -41,7 +41,11 @@ // Make sure we #include the SUNDIALS config file... # include // ...before the rest of the SUNDIALS files: -# include +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) +# include +# else +# include +# endif # include # include @@ -175,12 +179,19 @@ namespace SUNDIALS { set_functions_to_trigger_an_assert(); -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) // SUNDIALS will always duplicate communicators if we provide them. This // can cause problems if SUNDIALS is configured with MPI and we pass along // MPI_COMM_SELF in a serial application as MPI won't be // initialized. Hence, work around that by just not providing a // communicator in that case. +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + const int status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &kinsol_ctx); + (void)status; + AssertKINSOL(status); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) const int status = SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? nullptr : &mpi_communicator, @@ -234,9 +245,17 @@ namespace SUNDIALS AssertKINSOL(status); # endif -# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0) - kinsol_mem = KINCreate(); -# else + +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + // Same comment applies as in class constructor: + status = + SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL : + mpi_communicator, + &kinsol_ctx); + AssertKINSOL(status); + + kinsol_mem = KINCreate(kinsol_ctx); +# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) // Same comment applies as in class constructor: status = SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? nullptr : @@ -245,6 +264,8 @@ namespace SUNDIALS AssertKINSOL(status); kinsol_mem = KINCreate(kinsol_ctx); +# else + kinsol_mem = KINCreate(); # endif status = KINSetUserData(kinsol_mem, static_cast(this)); diff --git a/source/sundials/sunlinsol_wrapper.cc b/source/sundials/sunlinsol_wrapper.cc index e20124eedf..4d728b7e78 100644 --- a/source/sundials/sunlinsol_wrapper.cc +++ b/source/sundials/sunlinsol_wrapper.cc @@ -144,12 +144,16 @@ namespace SUNDIALS , pending_exception(pending_exception) {} +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + SUNATimesFn a_times_fn; + SUNPSetupFn preconditioner_setup; + SUNPSolveFn preconditioner_solve; + + SUNContext linsol_ctx; +# else ATimesFn a_times_fn; PSetupFn preconditioner_setup; PSolveFn preconditioner_solve; - -# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) - SUNContext linsol_ctx; # endif LinearSolveFunction lsolve; @@ -254,10 +258,15 @@ namespace SUNDIALS } - template int - arkode_linsol_set_a_times(SUNLinearSolver LS, void *A_data, ATimesFn ATimes) + arkode_linsol_set_a_times(SUNLinearSolver LS, + void *A_data, +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + SUNATimesFn ATimes) +# else + ATimesFn ATimes) +# endif { LinearSolverContent *content = access_content(LS); @@ -272,8 +281,13 @@ namespace SUNDIALS int arkode_linsol_set_preconditioner(SUNLinearSolver LS, void *P_data, - PSetupFn p_setup, - PSolveFn p_solve) +# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) + SUNPSetupFn p_setup, + SUNPSolveFn p_solve) +# else + PSetupFn p_setup, + PSolveFn p_solve) +# endif { LinearSolverContent *content = access_content(LS); @@ -342,9 +356,9 @@ namespace SUNDIALS # if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) template - SundialsOperator::SundialsOperator(void *A_data, - ATimesFn a_times_fn, - SUNContext linsol_ctx) + SundialsOperator::SundialsOperator(void *A_data, + SUNATimesFn a_times_fn, + SUNContext linsol_ctx) : A_data(A_data) , a_times_fn(a_times_fn) , linsol_ctx(linsol_ctx) @@ -394,10 +408,10 @@ namespace SUNDIALS # if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0) template SundialsPreconditioner::SundialsPreconditioner( - void *P_data, - PSolveFn p_solve_fn, - SUNContext linsol_ctx, - double tol) + void *P_data, + SUNPSolveFn p_solve_fn, + SUNContext linsol_ctx, + double tol) : P_data(P_data) , p_solve_fn(p_solve_fn) , linsol_ctx(linsol_ctx)