diff --git a/src/numerics/CVodesIntegrator.cpp b/src/numerics/CVodesIntegrator.cpp index 98b2acbf7..d1930aae6 100644 --- a/src/numerics/CVodesIntegrator.cpp +++ b/src/numerics/CVodesIntegrator.cpp @@ -369,6 +369,10 @@ void CVodesIntegrator::applyOptions() SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); m_linsol_matrix = SUNDenseMatrix(N, N); + if (m_linsol_matrix == nullptr) { + throw CanteraError("CVodesIntegrator::applyOptions", + "Unable to create SUNDenseMatrix of size {0} x {0}", N); + } #if CT_SUNDIALS_USE_LAPACK m_linsol = SUNLapackDense(m_y, (SUNMatrix) m_linsol_matrix); #else @@ -400,6 +404,11 @@ void CVodesIntegrator::applyOptions() SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + if (m_linsol_matrix == nullptr) { + throw CanteraError("CVodesIntegrator::applyOptions", + "Unable to create SUNBandMatrix of size {} with bandwidths " + "{} and {}", N, nu, nl); + } #if CT_SUNDIALS_USE_LAPACK m_linsol = SUNLapackBand(m_y, (SUNMatrix) m_linsol_matrix); #else diff --git a/src/numerics/IDA_Solver.cpp b/src/numerics/IDA_Solver.cpp index a5b88101e..0f071ddfd 100644 --- a/src/numerics/IDA_Solver.cpp +++ b/src/numerics/IDA_Solver.cpp @@ -422,6 +422,10 @@ void IDA_Solver::init(doublereal t0) SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); m_linsol_matrix = SUNDenseMatrix(N, N); + if (m_linsol_matrix == nullptr) { + throw CanteraError("IDA_Solver::init", + "Unable to create SUNDenseMatrix of size {0} x {0}", N); + } #if CT_SUNDIALS_USE_LAPACK m_linsol = SUNLapackDense(m_y, (SUNMatrix) m_linsol_matrix); #else @@ -443,6 +447,11 @@ void IDA_Solver::init(doublereal t0) SUNLinSolFree((SUNLinearSolver) m_linsol); SUNMatDestroy((SUNMatrix) m_linsol_matrix); m_linsol_matrix = SUNBandMatrix(N, nu, nl, nu+nl); + if (m_linsol_matrix == nullptr) { + throw CanteraError("IDA_Solver::init", + "Unable to create SUNBandMatrix of size {} with bandwidths " + "{} and {}", N, nu, nl); + } #if CT_SUNDIALS_USE_LAPACK m_linsol = SUNLapackBand(m_y, (SUNMatrix) m_linsol_matrix); #else