Skip to content

Commit

Permalink
Require SUNDIALS 5.4 or later.
Browse files Browse the repository at this point in the history
  • Loading branch information
drwells committed May 23, 2022
1 parent a56c2ee commit 59f9fcb
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 1,068 deletions.
4 changes: 2 additions & 2 deletions cmake/configure/configure_sundials.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ MACRO(FEATURE_SUNDIALS_FIND_EXTERNAL var)
SET(${var} TRUE)

#
# We require at least sundials 3.0.0
# We require at least sundials 5.4.0
#
SET(_version_required 3.0.0)
SET(_version_required 5.4.0)
IF(SUNDIALS_VERSION VERSION_LESS ${_version_required})
MESSAGE(STATUS "Could not find a sufficient Sundials installation: "
"deal.II requires at least version ${_version_required}, "
Expand Down
213 changes: 0 additions & 213 deletions include/deal.II/sundials/arkode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
# include <deal.II/lac/vector_memory.h>

# include <arkode/arkode.h>
# if DEAL_II_SUNDIALS_VERSION_LT(4, 0, 0)
# include <arkode/arkode_impl.h>
# endif
# include <nvector/nvector_serial.h>
# ifdef DEAL_II_WITH_MPI
# include <nvector/nvector_parallel.h>
Expand Down Expand Up @@ -621,209 +618,6 @@ namespace SUNDIALS
std::function<int(const double t, const VectorType &y, VectorType &res)>
implicit_function;

# if DEAL_II_SUNDIALS_VERSION_LT(4, 0, 0)
/**
* A function object that users may supply and that is intended to
* prepare the linear solver for subsequent calls to
* solve_jacobian_system().
*
* Make sure that after a call to this function, we know how to compute
* solutions of systems $A x = b$, where $A$ is some approximation to the
* Newton matrix, $M - \gamma \partial f_I/\partial y$. This function is
* optional. If the user does not provide it, then solve_jacobian_system()
* is assumed to also perform the setup internally.
*
* The setup_jacobian() function may call a user-supplied function to
* compute needed data related to the Jacobian matrix. Alternatively, it may
* choose to retrieve and use stored values of this data. In either case,
* setup_jacobian() may also preprocess that data as needed for
* solve_jacobian_system(), which may involve calling a generic function
* (such as for LU factorization).
*
* This data may be intended either for direct use (in a direct linear
* solver) or for use in a preconditioner (in a preconditioned iterative
* linear solver). The setup_jacobian() function is not called at every
* stage solve (or even every time step), but only as frequently as the
* solver determines that it is appropriate to perform the setup task. In
* this way, Jacobian-related data generated by setup_jacobian() is
* expected to be used over a number of time steps.
*
* If the user uses a matrix based computation of the Jacobian, then this
* is the right place where an assembly routine shoulde be called to
* assemble both a matrix and a preconditioner for the Jacobian system.
* Subsequent calls (possibly more than one) to solve_jacobian_system() can
* assume that this function has been called at least once.
*
* Notice that no assumption is made by this interface on what the user
* should do in this function. ARKode only assumes that after a call to
* setup_jacobian() it is possible to call solve_jacobian_system(), to
* obtain a solution $x$ to the system $J x = b$. If this function is not
* provided, then it is never called.
*
* Arguments to the function are
*
* @param[in] t the current time
* @param[in] gamma the current factor to use in the jacobian computation
* @param[in] ypred is the predicted $y$ vector for the current ARKode
* internal step
* @param[in] fpred is the value of the implicit right-hand side at ypred,
* $f_I (t_n, ypred)$.
*
* @param[in] convfail Input flag used to indicate any problem that
* occurred during the solution of the nonlinear equation on the current
* time step for which the linear solver is being used. This flag can be
* used to help decide whether the Jacobian data kept by a linear solver
* needs to be updated or not. Its possible values are:
*
* - ARK_NO_FAILURES: this value is passed if either this is the first
* call for this step, or the local error test failed on the previous
* attempt at this step (but the Newton iteration converged).
*
* - ARK_FAIL_BAD_J: this value is passed if (a) the previous Newton
* corrector iteration did not converge and the linear solver's setup
* function indicated that its Jacobian-related data is not current, or
* (b) during the previous Newton corrector iteration, the linear solver's
* solve function failed in a recoverable manner and the linear solver's
* setup function indicated that its Jacobian-related data is not
* current.
*
* - ARK_FAIL_OTHER: this value is passed if during the current internal
* step try, the previous Newton iteration failed to converge even
* though the linear solver was using current Jacobian-related data.
*
* @param[out] j_is_current: a boolean to be filled in by setup_jacobian().
* The value should be set to `true` if the Jacobian data is current after
* the call, and should be set to `false` if its Jacobian data is not
* current. If setup_jacobian() calls for re-evaluation of Jacobian data
* (based on convfail and ARKode state data), then it should set
* `j_is_current` to `true` unconditionally, otherwise an infinite loop can
* result.
*
* This function should return:
* - 0: Success
* - >0: Recoverable error (ARKodeReinit will be called if this happens, and
* then last function will be attempted again
* - <0: Unrecoverable error the computation will be aborted and an
* assertion will be thrown.
*/
std::function<int(const int convfail,
const double t,
const double gamma,
const VectorType &ypred,
const VectorType &fpred,
bool & j_is_current)>
setup_jacobian;

/**
* A function object that users may supply and that is intended to solve
* the Jacobian linear system. This function will be called by ARKode
* (possibly several times) after setup_jacobian() has been called at least
* once. ARKode tries to do its best to call setup_jacobian() the minimum
* amount of times. If convergence can be achieved without updating the
* Jacobian, then ARKode does not call setup_jacobian() again. If, on the
* contrary, internal ARKode convergence tests fail, then ARKode calls
* again setup_jacobian() with updated vectors and coefficients so that
* successive calls to solve_jacobian_systems() lead to better convergence
* in the Newton process.
*
* If you do not specify a solve_jacobian_system() function, then a fixed
* point iteration is used instead of a Newton method. Notice that this may
* not converge, or may converge very slowly.
*
* The jacobian $J$ should be (an approximation of) the system Jacobian
* \f[
* J = M - \gamma \frac{\partial f_I}{\partial y}
* \f]
* evaluated at `t`, `ycur`. `fcur` is $f_I(t,ycur)$.
*
* A call to this function should store in `dst` the result of $J^{-1}$
* applied to `src`, i.e., `J*dst = src`. It is the users responsibility to
* set up proper solvers and preconditioners inside this function.
*
*
* Arguments to the function are
*
* @param[in] t the current time
* @param[in] gamma the current factor to use in the jacobian computation
* @param[in] ycur is the current $y$ vector for the current ARKode
* internal step
* @param[in] fcur is the current value of the implicit right-hand side at
* ycur, $f_I (t_n, ypred)$.
*
*
* This function should return:
* - 0: Success
* - >0: Recoverable error (ARKodeReinit will be called if this happens, and
* then last function will be attempted again
* - <0: Unrecoverable error the computation will be aborted and an
* assertion will be thrown.
*/
std::function<int(const double t,
const double gamma,
const VectorType &ycur,
const VectorType &fcur,
const VectorType &rhs,
VectorType & dst)>
solve_jacobian_system;


/**
* A function object that users may supply and that is intended to set up
* the mass matrix. This function is called by ARKode any time a mass
* matrix update is required. The user should compute the mass matrix (or
* update all the variables that allow the application of the mass matrix).
* This function is called by ARKode once, before any call to
* solve_mass_system().
*
* ARKode supports the case where the mass matrix may depend on time, but
* not the case where the mass matrix depends on the solution itself.
*
* If the user does not provide a solve_mass_matrix() function, then the
* identity is used. If the setup_mass() function is not provided, then
* solve_mass_system() should do all the work by itself.
*
* If the user uses a matrix based computation of the mass matrix, then
* this is the right place where an assembly routine shoulde be called to
* assemble both a matrix and a preconditioner. Subsequent calls (possibly
* more than one) to solve_mass_system() can assume that this function
* has been called at least once.
*
* Notice that no assumption is made by this interface on what the user
* should do in this function. ARKode only assumes that after a call to
* setup_mass() it is possible to call solve_mass_system(), to
* obtain a solution $x$ to the system $M x = b$.
*
* This function should return:
* - 0: Success
* - >0: Recoverable error (ARKodeReinit will be called if this happens, and
* then last function will be attempted again
* - <0: Unrecoverable error the computation will be aborted and an
* assertion will be thrown.
*/
std::function<int(const double t)> setup_mass;

/**
* A function object that users may supply and that is intended to solve
* the mass matrix linear system. This function will be called by ARKode
* (possibly several times) after setup_mass() has been called at least
* once. ARKode tries to do its best to call setup_mass() the minimum
* amount of times.
*
* A call to this function should store in `dst` the result of $M^{-1}$
* applied to `src`, i.e., `M*dst = src`. It is the users responsibility to
* set up proper solvers and preconditioners inside this function.
*
* This function should return:
* - 0: Success
* - >0: Recoverable error (ARKodeReinit will be called if this happens, and
* then last function will be attempted again
* - <0: Unrecoverable error the computation will be aborted and an
* assertion will be thrown.
*/
std::function<int(const VectorType &rhs, VectorType &dst)>
solve_mass_system;
# else

/**
* A function object that users may supply and that is intended to compute
* the product of the mass matrix with a given vector `v`. This function
Expand Down Expand Up @@ -1135,7 +929,6 @@ namespace SUNDIALS
* assertion will be thrown.
*/
std::function<int(double t)> mass_preconditioner_setup;
# endif

/**
* A function object that users may supply and that is intended to
Expand Down Expand Up @@ -1227,8 +1020,6 @@ namespace SUNDIALS
dealii::DiscreteTime &time,
const bool do_reset);

# if DEAL_II_SUNDIALS_VERSION_GTE(4, 0, 0)

/**
* Set up the (non)linear solver and preconditioners in the ARKODE memory
* object based on the user-specified functions.
Expand All @@ -1247,8 +1038,6 @@ namespace SUNDIALS
void
setup_mass_solver(const VectorType &solution);

# endif

/**
* This function is executed at construction time to set the
* std::function above to trigger an assert if they are not
Expand Down Expand Up @@ -1286,10 +1075,8 @@ namespace SUNDIALS
*/
double last_end_time;

# if DEAL_II_SUNDIALS_VERSION_GTE(4, 0, 0)
std::unique_ptr<internal::LinearSolverWrapper<VectorType>> linear_solver;
std::unique_ptr<internal::LinearSolverWrapper<VectorType>> mass_solver;
# endif

# ifdef DEAL_II_WITH_PETSC
# ifdef PETSC_USE_COMPLEX
Expand Down
7 changes: 1 addition & 6 deletions include/deal.II/sundials/ida.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@
# include <ida/ida.h>
# endif

# include <sundials/sundials_config.h>
# if DEAL_II_SUNDIALS_VERSION_LT(3, 0, 0)
# include <ida/ida_spbcgs.h>
# include <ida/ida_spgmr.h>
# include <ida/ida_sptfqmr.h>
# endif
# include <deal.II/sundials/sunlinsol_wrapper.h>

# include <boost/signals2.hpp>

# include <nvector/nvector_serial.h>
# include <sundials/sundials_config.h>
# include <sundials/sundials_math.h>
# include <sundials/sundials_types.h>

Expand Down
3 changes: 0 additions & 3 deletions include/deal.II/sundials/kinsol.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
# include <boost/signals2.hpp>

# include <kinsol/kinsol.h>
# if DEAL_II_SUNDIALS_VERSION_LT(4, 1, 0)
# include <kinsol/kinsol_impl.h>
# endif
# include <nvector/nvector_serial.h>
# include <sundials/sundials_math.h>
# include <sundials/sundials_types.h>
Expand Down
6 changes: 0 additions & 6 deletions include/deal.II/sundials/n_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
# include <deal.II/lac/trilinos_vector.h>
# include <deal.II/lac/vector_memory.h>

# if DEAL_II_SUNDIALS_VERSION_LT(5, 0, 0)
# include <deal.II/sundials/sundials_backport.h>
# endif

DEAL_II_NAMESPACE_OPEN

namespace SUNDIALS
Expand Down Expand Up @@ -1000,11 +996,9 @@ namespace SUNDIALS
v->ops->nvcloneempty = &NVectorOperations::clone_empty;
v->ops->nvdestroy = &NVectorOperations::destroy<VectorType>;
// v->ops->nvspace = undef;
# if DEAL_II_SUNDIALS_VERSION_GTE(5, 0, 0)
v->ops->nvgetcommunicator =
&NVectorOperations::get_communicator_as_void_ptr<VectorType>;
v->ops->nvgetlength = &NVectorOperations::get_global_length<VectorType>;
# endif

/* standard vector operations */
v->ops->nvlinearsum = &NVectorOperations::linear_sum<VectorType>;
Expand Down

0 comments on commit 59f9fcb

Please sign in to comment.