Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to build Cantera against Sundials 4.0.0 and newer #672

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion include/cantera/numerics/CVodesIntegrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/cantera/numerics/Integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/kinetics/ImplicitSurfChem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
24 changes: 10 additions & 14 deletions src/numerics/CVodesIntegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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 "
Expand Down
6 changes: 5 additions & 1 deletion src/numerics/IDA_Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
1 change: 0 additions & 1 deletion src/zeroD/ReactorNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down