diff --git a/SConstruct b/SConstruct index 206d09c6cd..b953c03626 100644 --- a/SConstruct +++ b/SConstruct @@ -1038,23 +1038,29 @@ env['has_demangle'] = conf.CheckDeclaration("boost::core::demangle", import SCons.Conftest, SCons.SConf context = SCons.SConf.CheckContext(conf) -ret = SCons.Conftest.CheckLib(context, - ['sundials_cvodes'], - header='#include "cvodes/cvodes.h"', - language='C++', - call='CVodeCreate(CV_BDF, CV_NEWTON);', - autoadd=False, - extra_libs=env['blas_lapack_libs']) -if ret: + +# Check initially for Sundials<=3.2 and then for Sundials>=4.0 +for cvode_call in ['CVodeCreate(CV_BDF, CV_NEWTON);','CVodeCreate(CV_BDF);']: + ret = SCons.Conftest.CheckLib(context, + ['sundials_cvodes'], + header='#include "cvodes/cvodes.h"', + language='C++', + call=cvode_call, + autoadd=False, + extra_libs=env['blas_lapack_libs']) # CheckLib returns False to indicate success + if not ret: + if env['system_sundials'] == 'default': + env['system_sundials'] = 'y' + break + +# Execute if the cycle ends without 'break' +else: if env['system_sundials'] == 'default': env['system_sundials'] = 'n' elif env['system_sundials'] == 'y': config_error('Expected system installation of Sundials, but it could ' 'not be found.') -elif env['system_sundials'] == 'default': - env['system_sundials'] = 'y' - # Checkout Sundials submodule if needed if (env['system_sundials'] == 'n' and @@ -1091,7 +1097,7 @@ if env['system_sundials'] == 'y': # Ignore the minor version, e.g. 2.4.x -> 2.4 env['sundials_version'] = '.'.join(sundials_version.split('.')[:2]) - if env['sundials_version'] not in ('2.4','2.5','2.6','2.7','3.0','3.1'): + if env['sundials_version'] not in ('2.4','2.5','2.6','2.7','3.0','3.1','3.2','4.0','4.1'): print("""ERROR: Sundials version %r is not supported.""" % env['sundials_version']) sys.exit(1) print("""INFO: Using system installation of Sundials version %s.""" % sundials_version) diff --git a/include/cantera/numerics/CVodesIntegrator.h b/include/cantera/numerics/CVodesIntegrator.h index 1332336f01..e17d042c88 100644 --- a/include/cantera/numerics/CVodesIntegrator.h +++ b/include/cantera/numerics/CVodesIntegrator.h @@ -51,7 +51,6 @@ class CVodesIntegrator : public Integrator m_maxord = n; } virtual void setMethod(MethodType t); - virtual void setIterator(IterType t); virtual void setMaxStepSize(double hmax); virtual void setMinStepSize(double hmin); virtual void setMaxSteps(int nmax); diff --git a/include/cantera/numerics/Integrator.h b/include/cantera/numerics/Integrator.h index 272468ae9b..58d073b29c 100644 --- a/include/cantera/numerics/Integrator.h +++ b/include/cantera/numerics/Integrator.h @@ -176,8 +176,9 @@ class Integrator } //! Set the linear iterator. + //! @deprecated Unused. To be removed after Cantera 2.5. virtual void setIterator(IterType t) { - warn("setInterator"); + warn_deprecated("Integrator::setIterator", "To be removed after Cantera 2.5."); } //! Set the maximum step size diff --git a/src/kinetics/ImplicitSurfChem.cpp b/src/kinetics/ImplicitSurfChem.cpp index 771a34330c..798d1a7e85 100644 --- a/src/kinetics/ImplicitSurfChem.cpp +++ b/src/kinetics/ImplicitSurfChem.cpp @@ -84,7 +84,6 @@ ImplicitSurfChem::ImplicitSurfChem( // numerically, and use a Newton linear iterator m_integ->setMethod(BDF_Method); m_integ->setProblemType(DENSE + NOJAC); - m_integ->setIterator(Newton_Iter); m_work.resize(ntmax); } diff --git a/src/numerics/CVodesIntegrator.cpp b/src/numerics/CVodesIntegrator.cpp index 806c67dd45..92ee3312cc 100644 --- a/src/numerics/CVodesIntegrator.cpp +++ b/src/numerics/CVodesIntegrator.cpp @@ -89,7 +89,6 @@ CVodesIntegrator::CVodesIntegrator() : m_type(DENSE+NOJAC), m_itol(CV_SS), m_method(CV_BDF), - m_iter(CV_NEWTON), m_maxord(0), m_reltol(1.e-9), m_abstols(1.e-15), @@ -227,17 +226,6 @@ void CVodesIntegrator::setMaxErrTestFails(int n) } } -void CVodesIntegrator::setIterator(IterType t) -{ - if (t == Newton_Iter) { - m_iter = CV_NEWTON; - } else if (t == Functional_Iter) { - m_iter = CV_FUNCTIONAL; - } else { - throw CanteraError("CVodesIntegrator::setIterator", "unknown iterator"); - } -} - void CVodesIntegrator::sensInit(double t0, FuncEval& func) { m_np = func.nparams(); @@ -298,7 +286,11 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func) //! Specify the method and the iteration type. Cantera Defaults: //! CV_BDF - Use BDF methods //! CV_NEWTON - use Newton's method - m_cvode_mem = CVodeCreate(m_method, m_iter); + #if CT_SUNDIALS_VERSION < 40 + m_cvode_mem = CVodeCreate(m_method, CV_NEWTON); + #else + m_cvode_mem = CVodeCreate(m_method); + #endif if (!m_cvode_mem) { throw CanteraError("CVodesIntegrator::initialize", "CVodeCreate failed."); @@ -412,7 +404,11 @@ void CVodesIntegrator::applyOptions() #if CT_SUNDIALS_VERSION >= 30 SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); - m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + #if CT_SUNDIALS_VERSION < 40 + m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + #else + m_linsol_matrix = SUNBandMatrix(N, nu, nl); + #endif if (m_linsol_matrix == nullptr) { throw CanteraError("CVodesIntegrator::applyOptions", "Unable to create SUNBandMatrix of size {} with bandwidths " diff --git a/src/numerics/IDA_Solver.cpp b/src/numerics/IDA_Solver.cpp index 0f071ddfd2..f91354e455 100644 --- a/src/numerics/IDA_Solver.cpp +++ b/src/numerics/IDA_Solver.cpp @@ -446,7 +446,11 @@ void IDA_Solver::init(doublereal t0) #if CT_SUNDIALS_VERSION >= 30 SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); - m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + #if CT_SUNDIALS_VERSION < 40 + m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + #else + m_linsol_matrix = SUNBandMatrix(N, nu, nl); + #endif if (m_linsol_matrix == nullptr) { throw CanteraError("IDA_Solver::init", "Unable to create SUNBandMatrix of size {} with bandwidths " diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 389da71123..3ca6972964 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -28,7 +28,6 @@ ReactorNet::ReactorNet() : // numerically, and use a Newton linear iterator m_integ->setMethod(BDF_Method); m_integ->setProblemType(DENSE + NOJAC); - m_integ->setIterator(Newton_Iter); } void ReactorNet::setInitialTime(double time)