diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58086d34..6fa1d022 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,3 +44,11 @@ jobs: run: python3 setup.py install --user --sundials-home=/usr --blas-home=/usr/lib/x86_64-linux-gnu/ --lapack-home=/usr/lib/x86_64-linux-gnu/ --superlu-home=/usr - name: Test run: python3 -m nose --verbose tests/* tests/solvers/* + + - name: Build (cmake) + run: | + cmake -B build -DCMAKE_INSTALL_PREFIX=~/.local . + rm -r ~/.local/lib/python3.*/site-packages/assimulo + cmake --build build --target install --parallel 3 + - name: Test (cmake) + run: python3 -m nose --verbose tests/* tests/solvers/* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..728e3858 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,333 @@ +cmake_minimum_required (VERSION 3.17) + +project (assimulo LANGUAGES C) + +list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + +option(USE_FORTRAN "build Fortran modules" ON) +option(USE_SUNDIALS "build SUNDIALS modules" ON) +option(USE_SUPERLU "use SUPERLU lib" ON) +if (USE_FORTRAN) + enable_language(Fortran) +endif () + +find_package (Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) +include(GNUInstallDirs) +if (NOT DEFINED PYTHON_SITE_PACKAGES) + if (WIN32) + set (PYTHON_SITE_PACKAGES Lib/site-packages CACHE PATH "site-packages dir") + else () + set (PYTHON_SITE_PACKAGES ${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages CACHE PATH "site-packages dir") + endif () +endif () + +find_package(LAPACK) + +if (USE_SUPERLU) + find_package (SuperLU_MT) +endif () + +if (USE_SUNDIALS) + find_package (SUNDIALS CONFIG) + + if (SUNDIALS_FOUND) + message(STATUS "Found SUNDIALS: ${SUNDIALS_DIR} (found version \"${SUNDIALS_VERSION}\")") + else () + # fallback to our module + find_package (SUNDIALS MODULE) + set(SUNDIALS_DIR ${SUNDIALS_INCLUDE_DIRS}) + endif () + + if (SUNDIALS_FOUND) + string (REGEX REPLACE "([0-9]+)\\..*" "\\1" SUNDIALS_MAJOR_VERSION "${SUNDIALS_VERSION}") + string (REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" SUNDIALS_MINOR_VERSION "${SUNDIALS_VERSION}") + string (REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" SUNDIALS_PATCH_VERSION "${SUNDIALS_VERSION}") + math(EXPR SUNDIALS_VERSION_NR "100000 * ${SUNDIALS_MAJOR_VERSION} + 100 * ${SUNDIALS_MINOR_VERSION} + ${SUNDIALS_PATCH_VERSION}") + + if (NOT DEFINED SUNDIALS_INCLUDE_DIR) + find_path (SUNDIALS_INCLUDE_DIR sundials/sundials_config.h HINTS ${SUNDIALS_DIR}/../../../../include ${SUNDIALS_DIR}/../../../include) + endif () + + file (STRINGS ${SUNDIALS_INCLUDE_DIR}/sundials/sundials_config.h _SUNDIALS_INT64_DEFINE REGEX "^#define SUNDIALS_INT64_T") + if (_SUNDIALS_INT64_DEFINE) + set (SUNDIALS_VECTOR_SIZE 64) + else () + set (SUNDIALS_VECTOR_SIZE 32) + endif () + message(STATUS "SUNDIALS has vector type size ${SUNDIALS_VECTOR_SIZE} bits") + + # only SUNDIALS_SUPERLUMT_THREAD_TYPE is consistent across sundials versions + file (STRINGS ${SUNDIALS_INCLUDE_DIR}/sundials/sundials_config.h _SUNDIALS_SUPERLUMT_DEFINE REGEX "^#define SUNDIALS_SUPERLUMT_THREAD_TYPE \"(PTHREAD|OPENMP)\"") + if (_SUNDIALS_SUPERLUMT_DEFINE) + set (SUNDIALS_WITH_SUPERLU True) + else () + set (SUNDIALS_WITH_SUPERLU False) + endif () + message(STATUS "SUNDIALS has SuperLU support: ${SUNDIALS_WITH_SUPERLU}") + + file (STRINGS ${SUNDIALS_INCLUDE_DIR}/sundials/sundials_config.h _SUNDIALS_CVODE_RTOL_VEC_DEFINE REGEX "^#define SUNDIALS_CVODE_RTOL_VEC") + if (_SUNDIALS_CVODE_RTOL_VEC_DEFINE) + set (SUNDIALS_CVODE_RTOL_VEC True) + else () + set (SUNDIALS_CVODE_RTOL_VEC False) + endif () + message(STATUS "SUNDIALS has CVode rtol vectors support: ${SUNDIALS_CVODE_RTOL_VEC}") + + endif () +endif () + +set (cython_clones) +# copy /src tree into CMAKE_BINARY_DIR/assimulo +file (GLOB_RECURSE cython_sources src/*.pyx src/*.pxd src/*.py) +foreach (file ${cython_sources}) + if (EXISTS ${file}) + file (RELATIVE_PATH rel_file "${CMAKE_SOURCE_DIR}/src" "${file}") + get_filename_component (rel_path ${rel_file} PATH) + file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/assimulo/${rel_path}) + set (cython_clone ${CMAKE_BINARY_DIR}/assimulo/${rel_file}) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${file} ${cython_clone}) + add_custom_command (OUTPUT ${cython_clone} + COMMENT "Copying ${file}" + COMMAND ${CMAKE_COMMAND} -E copy ${file} ${cython_clone} + DEPENDS ${file} + ) + list (APPEND cython_clones ${cython_clone}) + endif () +endforeach () + +# copy /thirdparty tree into CMAKE_BINARY_DIR +file (GLOB_RECURSE cython_sources thirdparty/*.pyx thirdparty/*.pxd thirdparty/*.py) +foreach (file ${cython_sources}) + if (EXISTS ${file}) + file (RELATIVE_PATH rel_file "${CMAKE_SOURCE_DIR}/thirdparty" "${file}") + get_filename_component (rel_path ${rel_file} PATH) + file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/thirdparty/${rel_path}) + set (cython_clone ${CMAKE_BINARY_DIR}/thirdparty/${rel_file}) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${file} ${cython_clone}) + add_custom_command (OUTPUT ${cython_clone} + COMMENT "Copying ${file}" + COMMAND ${CMAKE_COMMAND} -E copy ${file} ${cython_clone} + DEPENDS ${file} + ) + list (APPEND cython_clones ${cython_clone}) + endif () +endforeach () + +macro(assimulo_add_cython_module pyx_file) + cmake_parse_arguments(CMOD "" "DESTINATION" "SOURCES" ${ARGN}) + if (NOT DEFINED CMOD_DESTINATION) + set (CMOD_DESTINATION assimulo) + endif () + get_filename_component(name "${pyx_file}" NAME_WE) + get_filename_component(subdir "${pyx_file}" DIRECTORY) + + # PYTHONNOUSERSITE=0 overrides skbuild and allows to use Cython from ~/.local when not available via system packages + add_custom_command( + OUTPUT ${name}.c + COMMENT "Making ${name}.c from ${name}.pyx" + COMMAND ${CMAKE_COMMAND} -E env PYTHONNOUSERSITE=0 ${Python_EXECUTABLE} -m cython -o ${name}.c + --3str --fast-fail ${EXTRA_CYTHON_FLAGS} + -I ${CMAKE_CURRENT_SOURCE_DIR}/src + -I ${CMAKE_CURRENT_SOURCE_DIR}/src/lib + ${CMAKE_CURRENT_BINARY_DIR}/${pyx_file} + DEPENDS ${cython_clones} VERBATIM) + + python_add_library(${name} MODULE ${name}.c ${CMOD_SOURCES} WITH_SOABI) + target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}) + target_link_libraries(${name} PRIVATE Python::NumPy) + target_compile_definitions(${name} PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) + if (CMAKE_C_COMPILER_ID MATCHES "GNU") + target_compile_options(${name} PRIVATE $<$:-O2 -fno-strict-aliasing>) + endif () + install(TARGETS ${name} DESTINATION ${PYTHON_SITE_PACKAGES}/${CMOD_DESTINATION}) +endmacro() + +assimulo_add_cython_module(assimulo/explicit_ode.pyx + SOURCES src/ode_event_locator.c) +assimulo_add_cython_module(assimulo/algebraic.pyx) +assimulo_add_cython_module(assimulo/implicit_ode.pyx) +assimulo_add_cython_module(assimulo/ode.pyx) +assimulo_add_cython_module(assimulo/problem.pyx) +assimulo_add_cython_module(assimulo/special_systems.pyx) +assimulo_add_cython_module(assimulo/support.pyx) +assimulo_add_cython_module(assimulo/solvers/euler.pyx + DESTINATION assimulo/solvers) + +if (SUNDIALS_FOUND) + set(EXTRA_CYTHON_FLAGS -E SUNDIALS_VERSION_NR=${SUNDIALS_VERSION_NR} -E SUNDIALS_VECTOR_SIZE=${SUNDIALS_VECTOR_SIZE} -E SUNDIALS_WITH_SUPERLU=${SUNDIALS_WITH_SUPERLU} -E SUNDIALS_CVODE_RTOL_VEC=${SUNDIALS_CVODE_RTOL_VEC}) + + assimulo_add_cython_module(assimulo/solvers/sundials.pyx + DESTINATION assimulo/solvers) + target_link_libraries(sundials PRIVATE sundials_cvodes sundials_nvecserial sundials_idas) + if (SUNDIALS_VERSION VERSION_GREATER_EQUAL 3) + target_link_libraries(sundials PRIVATE sundials_sunlinsoldense sundials_sunlinsolspgmr sundials_sunmatrixdense sundials_sunmatrixsparse) + endif () + if (SUNDIALS_VERSION VERSION_GREATER_EQUAL 7) + target_link_libraries(sundials PRIVATE sundials_core) + endif () + if (SUNDIALS_WITH_SUPERLU) + target_link_libraries(sundials PRIVATE SuperLU_MT::SuperLU_MT) + if (SUNDIALS_VERSION VERSION_GREATER_EQUAL 3) + target_link_libraries(sundials PRIVATE sundials_sunlinsolsuperlumt) + endif () + endif () + + assimulo_add_cython_module(assimulo/solvers/kinsol.pyx + DESTINATION assimulo/solvers) + target_link_libraries(kinsol PRIVATE sundials_kinsol sundials_nvecserial) + if (SUNDIALS_VERSION VERSION_GREATER_EQUAL 7) + target_link_libraries(kinsol PRIVATE sundials_core) + endif () + if (SUNDIALS_WITH_SUPERLU) + target_link_libraries(kinsol PRIVATE SuperLU_MT::SuperLU_MT) + endif () +endif () + + +assimulo_add_cython_module(thirdparty/radau5/radau5ode.pyx + SOURCES thirdparty/radau5/radau5.c thirdparty/radau5/radau5_io.c + DESTINATION assimulo/lib) + +if (SuperLU_MT_FOUND) + target_sources(radau5ode PRIVATE thirdparty/radau5/superlu_double.c thirdparty/radau5/superlu_complex.c thirdparty/radau5/superlu_util.c) + target_link_libraries(radau5ode PRIVATE SuperLU_MT::SuperLU_MT) + target_compile_definitions(radau5ode PRIVATE __RADAU5_WITH_SUPERLU) +endif() + +if (USE_FORTRAN) + + find_program(F2PY_EXECUTABLE NAMES f2py f2py3 REQUIRED) + + if (NOT DEFINED F2PY_INCLUDE_DIR) + execute_process(COMMAND ${Python_EXECUTABLE} -c "from numpy import f2py; print(f2py.get_include())" + OUTPUT_VARIABLE F2PY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + message(STATUS "Using f2py include dir: ${F2PY_INCLUDE_DIR}") + + # object library with common f2py symbols + add_library(fortranobject OBJECT ${F2PY_INCLUDE_DIR}/fortranobject.c) + target_link_libraries(fortranobject PUBLIC Python::NumPy) + target_compile_definitions(fortranobject PUBLIC NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) + target_include_directories(fortranobject PUBLIC ${F2PY_INCLUDE_DIR}) + set_target_properties(fortranobject PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + + macro(assimulo_add_fortran_module name pyf_file) + cmake_parse_arguments(FMOD "" "" "SOURCES" ${ARGN}) + add_custom_command( + OUTPUT ${name}module.c + COMMENT "Making ${name}module.c from ${pyf_file}" + COMMAND ${F2PY_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${pyf_file} + DEPENDS ${pyf_file} VERBATIM) + + # may be created or not + file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers.f) + file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers2.f90) + + python_add_library(${name} MODULE ${FMOD_SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/${name}module.c + ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers.f + ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers2.f90 + WITH_SOABI) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${name}module.c ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers.f ${CMAKE_CURRENT_BINARY_DIR}/${name}-f2pywrappers2.f90 PROPERTIES GENERATED TRUE) + + target_link_libraries(${name} PRIVATE fortranobject) + if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + target_compile_options(${name} PRIVATE $<$:-O2 --std=legacy>) + endif () + install(TARGETS ${name} DESTINATION ${PYTHON_SITE_PACKAGES}/assimulo/lib) + endmacro() + + assimulo_add_fortran_module(dopri5 thirdparty/hairer/dopri5.pyf + SOURCES thirdparty/hairer/dopri5.f) + + assimulo_add_fortran_module(rodas thirdparty/hairer/rodas_decsol.pyf + SOURCES thirdparty/hairer/rodas_decsol.f) + + assimulo_add_fortran_module(radau5 thirdparty/hairer/radau_decsol.pyf + SOURCES thirdparty/hairer/radau_decsol.f) + + assimulo_add_fortran_module(radar5 thirdparty/hairer/radar5.pyf + SOURCES + thirdparty/hairer/contr5.f90 + thirdparty/hairer/radar5_int.f90 + thirdparty/hairer/radar5.f90 + thirdparty/hairer/dontr5.f90 + thirdparty/hairer/decsol.f90 + thirdparty/hairer/dc_decdel.f90) + + assimulo_add_fortran_module(odepack thirdparty/odepack/odepack.pyf + SOURCES + thirdparty/odepack/opkdmain.f + thirdparty/odepack/opkda1.f + thirdparty/odepack/opkda2.f + thirdparty/odepack/odepack_aux.f90) + + assimulo_add_fortran_module(odassl thirdparty/odassl/odassl.pyf + SOURCES + thirdparty/odassl/odassl.f + thirdparty/odassl/odastp.f + thirdparty/odassl/odacor.f + thirdparty/odassl/odajac.f + thirdparty/odassl/d1mach.f + thirdparty/odassl/daxpy.f + thirdparty/odassl/ddanrm.f + thirdparty/odassl/ddatrp.f + thirdparty/odassl/ddot.f + thirdparty/odassl/ddwats.f + thirdparty/odassl/dgefa.f + thirdparty/odassl/dgesl.f + thirdparty/odassl/dscal.f + thirdparty/odassl/idamax.f + thirdparty/odassl/xerrwv.f) + if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + target_compile_options(odassl PRIVATE $<$:-fdefault-double-8 -fdefault-real-8>) + endif () + + assimulo_add_fortran_module(dasp3dp thirdparty/dasp3/dasp3dp.pyf + SOURCES + thirdparty/dasp3/DASP3.f + thirdparty/dasp3/ANORM.f + thirdparty/dasp3/CTRACT.f + thirdparty/dasp3/DECOMP.f + thirdparty/dasp3/HMAX.f + thirdparty/dasp3/INIVAL.f + thirdparty/dasp3/JACEST.f + thirdparty/dasp3/PDERIV.f + thirdparty/dasp3/PREPOL.f + thirdparty/dasp3/SOLVE.f + thirdparty/dasp3/SPAPAT.f) + + if (LAPACK_FOUND) + assimulo_add_fortran_module(glimda thirdparty/glimda/glimda_complete.pyf + SOURCES + thirdparty/glimda/glimda_complete.f) + target_link_libraries(glimda PRIVATE ${LAPACK_LIBRARIES}) + endif () +endif () + +install(FILES src/__init__.py + src/exception.py + src/problem_algebraic.py + src/algebraic.pxd + src/explicit_ode.pxd + src/implicit_ode.pxd + src/ode.pxd + src/problem.pxd + src/support.px + DESTINATION ${PYTHON_SITE_PACKAGES}/assimulo) +install(FILES src/lib/__init__.py + src/lib/radau_core.py + DESTINATION ${PYTHON_SITE_PACKAGES}/assimulo/lib) +install(FILES src/solvers/__init__.py + src/solvers/dasp3.py + src/solvers/glimda.py + src/solvers/odassl.py + src/solvers/odepack.py + src/solvers/radar5.py + src/solvers/radau5.py + src/solvers/rosenbrock.py + src/solvers/runge_kutta.py + DESTINATION ${PYTHON_SITE_PACKAGES}/assimulo/solvers) +install(DIRECTORY examples + DESTINATION ${PYTHON_SITE_PACKAGES}/assimulo) diff --git a/cmake/FindSUNDIALS.cmake b/cmake/FindSUNDIALS.cmake new file mode 100644 index 00000000..193802f1 --- /dev/null +++ b/cmake/FindSUNDIALS.cmake @@ -0,0 +1,47 @@ +# - Find SUNDIALS +# SUNDIALS, the SUite of Nonlinear and DIfferential/ALgebraic equation Solvers. +# https://computing.llnl.gov/projects/sundials +# +# The module defines the following variables: +# SUNDIALS_VERSION, the version string +# SUNDIALS_INCLUDE_DIRS, where to find sundials_dense.h, etc. +# SUNDIALS_LIBRARIES, the libraries needed to use SUNDIALS +# SUNDIALS_FOUND, If false, do not try to use SUNDIALS +# also defined, but not for general use are +# + +find_path (SUNDIALS_INCLUDE_DIR sundials/sundials_config.h) + +file (STRINGS ${SUNDIALS_INCLUDE_DIR}/sundials/sundials_config.h _VERSION_DEFINE_STRING REGEX "#define (SUNDIALS_VERSION|SUNDIALS_PACKAGE_VERSION) .*") +if (_VERSION_DEFINE_STRING) + string (REGEX REPLACE "#define SUNDIALS[A-Z_]+VERSION \"([0-9\.]+)\"" "\\1" SUNDIALS_VERSION ${_VERSION_DEFINE_STRING}) +endif () + +set(SUNDIALS_LIBRARIES) +set(SUNDIALS_COMPONENTS sunlinsoldense sunlinsolspgmr sunmatrixdense sunmatrixsparse core sunlinsolsuperlumt kinsol nvecserial cvode cvodes) +foreach (COMPONENT ${SUNDIALS_COMPONENTS}) + string(TOUPPER "${COMPONENT}" COMPONENT_UPPER) + find_library (SUNDIALS_${COMPONENT_UPPER}_LIBRARY NAMES sundials_${COMPONENT}) + + if (SUNDIALS_${COMPONENT_UPPER}_LIBRARY) + list (APPEND SUNDIALS_LIBRARIES ${SUNDIALS_${COMPONENT_UPPER}_LIBRARY}) + endif () +endforeach () + +set (SUNDIALS_INCLUDE_DIRS ${SUNDIALS_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SUNDIALS REQUIRED_VARS SUNDIALS_INCLUDE_DIR SUNDIALS_CVODES_LIBRARY VERSION_VAR SUNDIALS_VERSION) + +mark_as_advanced ( + SUNDIALS_LIBRARIES + SUNDIALS_INCLUDE_DIR + SUNDIALS_INCLUDE_DIRS) + +if(NOT TARGET SUNDIALS::ALL) + add_library(SUNDIALS::ALL UNKNOWN IMPORTED) + set_target_properties(SUNDIALS::ALL + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SUNDIALS_INCLUDE_DIRS}") + target_link_libraries(SUNDIALS::ALL INTERFACE ${SUNDIALS_LIBRARIES}) +endif() diff --git a/cmake/FindSuperLU_MT.cmake b/cmake/FindSuperLU_MT.cmake new file mode 100644 index 00000000..9f8191e4 --- /dev/null +++ b/cmake/FindSuperLU_MT.cmake @@ -0,0 +1,58 @@ +# - Find SuperLU_MT +# SuperLU_MT contains a set of subroutines to solve a sparse linear system +# https://github.com/xiaoyeli/superlu_mt +# +# The module defines the following variables: +# SUPERLUMT_INCLUDE_DIRS, where to find superlu.h, etc. +# SUPERLUMT_LIBRARIES, the libraries needed to use SuperLU_MT +# SUPERLUMT_FOUND, If false, do not try to use SuperLU_MT +# also defined, but not for general use are +# SUPERLUMT_LIBRARY, where to find the MPC library. +# + +find_path (SUPERLUMT_INCLUDE_DIR slu_mt_cdefs.h + PATH_SUFFIXES superlu_mt +) + +find_library (SUPERLUMT_LIBRARY + NAMES superlu_mt_OPENMP superlu_mt_THREAD +) + +set (SUPERLUMT_LIBRARIES ${SUPERLUMT_LIBRARY}) +set (SUPERLUMT_INCLUDE_DIRS ${SUPERLUMT_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SuperLU_MT DEFAULT_MSG SUPERLUMT_LIBRARY SUPERLUMT_INCLUDE_DIRS) + +mark_as_advanced ( + SUPERLUMT_LIBRARY + SUPERLUMT_LIBRARIES + SUPERLUMT_INCLUDE_DIR + SUPERLUMT_INCLUDE_DIRS) + + + +if(NOT TARGET SuperLU_MT::SuperLU_MT) + add_library(SuperLU_MT::SuperLU_MT UNKNOWN IMPORTED) + set_target_properties(SuperLU_MT::SuperLU_MT + PROPERTIES + IMPORTED_LOCATION ${SUPERLUMT_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES "${SUPERLUMT_INCLUDE_DIR}") + + find_package(BLAS QUIET) + if (BLAS_LIBRARIES) + target_link_libraries(SuperLU_MT::SuperLU_MT INTERFACE ${BLAS_LIBRARIES}) + endif () + + if (SUPERLUMT_LIBRARY MATCHES OPENMP) + find_package(OpenMP QUIET) + if (OpenMP_FOUND) + target_link_libraries(SuperLU_MT::SuperLU_MT INTERFACE OpenMP::OpenMP_C) + endif () + endif () + + find_library(MATH_LIBRARY NAMES m) + if (MATH_LIBRARY) + target_link_libraries(SuperLU_MT::SuperLU_MT INTERFACE ${MATH_LIBRARY}) + endif () +endif() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1afc2a45 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "assimulo" +version = "3.5.2" +dependencies = [ + "scipy", + "cython", +] + +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[tool.scikit-build] +logging.level = "DEBUG" + +[tool.scikit-build.cmake.define] +CMAKE_VERBOSE_MAKEFILE = "ON" +PYTHON_SITE_PACKAGES = "." diff --git a/setup.py b/setup.py index 3a317fbf..a356dde7 100644 --- a/setup.py +++ b/setup.py @@ -376,7 +376,7 @@ def check_SUNDIALS(self): if os.path.exists(os.path.join(os.path.join(self.incdirs,'cvodes'), 'cvodes.h')): self.with_SUNDIALS=True logging.debug('SUNDIALS found.') - sundials_version = None + sundials_version_tuple = None sundials_vector_type_size = None sundials_with_superlu = False sundials_with_msvc = False @@ -386,8 +386,8 @@ def check_SUNDIALS(self): with open(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')) as f: for line in f: if "SUNDIALS_PACKAGE_VERSION" in line or "SUNDIALS_VERSION" in line: - sundials_version = tuple([int(f) for f in line.split()[-1][1:-1].split('-dev')[0].split(".")]) - logging.debug('SUNDIALS %d.%d found.'%(sundials_version[0], sundials_version[1])) + sundials_version_tuple = tuple([int(f) for f in line.split()[-1][1:-1].split('-dev')[0].split(".")]) + logging.debug('SUNDIALS %d.%d found.'%(sundials_version_tuple[0], sundials_version_tuple[1])) break with open(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')) as f: for line in f: @@ -418,13 +418,13 @@ def check_SUNDIALS(self): sundials_with_msvc = True except Exception: if os.path.exists(os.path.join(os.path.join(self.incdirs,'arkode'), 'arkode.h')): #This was added in 2.6 - sundials_version = (2,6,0) + sundials_version_tuple = (2,6,0) logging.debug('SUNDIALS 2.6 found.') else: - sundials_version = (2,5,0) + sundials_version_tuple = (2,5,0) logging.debug('SUNDIALS 2.5 found.') - - self.SUNDIALS_version = sundials_version + + self.SUNDIALS_version_nr = 100000 * sundials_version_tuple[0] + 100 * sundials_version_tuple[1] + sundials_version_tuple[2] self.SUNDIALS_vector_size = sundials_vector_type_size self.sundials_with_superlu = sundials_with_superlu self.sundials_with_msvc = sundials_with_msvc @@ -489,7 +489,7 @@ def cython_extensionlists(self): # SUNDIALS if self.with_SUNDIALS: - compile_time_env = {'SUNDIALS_VERSION': self.SUNDIALS_version, + compile_time_env = {'SUNDIALS_VERSION_NR': self.SUNDIALS_version_nr, 'SUNDIALS_WITH_SUPERLU': self.sundials_with_superlu and self.with_SLU, 'SUNDIALS_VECTOR_SIZE': self.SUNDIALS_vector_size, 'SUNDIALS_CVODE_RTOL_VEC': self.sundials_cvode_with_rtol_vec} @@ -502,14 +502,14 @@ def cython_extensionlists(self): ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs] ext_list[-1].library_dirs = [self.libdirs] - if self.SUNDIALS_version >= (3,0,0): + if self.SUNDIALS_version_nr >= 300000: ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas", "sundials_sunlinsoldense", "sundials_sunlinsolspgmr", "sundials_sunmatrixdense", "sundials_sunmatrixsparse"] - if self.SUNDIALS_version >= (7,0,0): + if self.SUNDIALS_version_nr >= 700000: ext_list[-1].libraries.extend(["sundials_core"]) else: ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas"] if self.sundials_with_superlu and self.with_SLU: #If SUNDIALS is compiled with support for SuperLU - if self.SUNDIALS_version >= (3,0,0): + if self.SUNDIALS_version_nr >= 300000: ext_list[-1].libraries.extend(["sundials_sunlinsolsuperlumt"]) ext_list[-1].include_dirs.append(self.SLUincdir) @@ -525,7 +525,7 @@ def cython_extensionlists(self): ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs] ext_list[-1].library_dirs = [self.libdirs] ext_list[-1].libraries = ["sundials_kinsol", "sundials_nvecserial"] - if self.SUNDIALS_version >= (7,0,0): + if self.SUNDIALS_version_nr >= 700000: ext_list[-1].libraries.extend(["sundials_core"]) if self.sundials_with_superlu and self.with_SLU: #If SUNDIALS is compiled with support for SuperLU diff --git a/src/lib/sundials_callbacks.pxi b/src/lib/sundials_callbacks.pxi index e970aea8..87ab2698 100644 --- a/src/lib/sundials_callbacks.pxi +++ b/src/lib/sundials_callbacks.pxi @@ -22,9 +22,9 @@ from numpy cimport PyArray_DATA #================= cdef N_Vector N_VNewEmpty_Euclidean(long int n) noexcept: - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = 0 ELSE: cdef void* comm = NULL @@ -40,9 +40,9 @@ cdef inline N_Vector arr2nv(x) noexcept: cdef long int n = len(x) cdef np.ndarray[realtype, ndim=1,mode='c'] ndx=x cdef void* data_ptr=PyArray_DATA(ndx) - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = 0 ELSE: cdef void* comm = NULL diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi index e35497d2..4145752f 100644 --- a/src/lib/sundials_callbacks_ida_cvode.pxi +++ b/src/lib/sundials_callbacks_ida_cvode.pxi @@ -89,7 +89,7 @@ cdef int cv_sens_rhs_all(int Ns, realtype t, N_Vector yv, N_Vector yvdot, return CV_UNREC_RHSFUNC_ERR -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: @cython.boundscheck(False) @cython.wraparound(False) cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac, @@ -163,7 +163,7 @@ ELSE: cdef np.ndarray[int, ndim=1, mode='c'] jindices cdef np.ndarray[int, ndim=1, mode='c'] jindptr - IF SUNDIALS_VERSION >= (2,6,3): + IF SUNDIALS_VERSION_NR >= 200603: cdef int* rowvals = Jacobian.rowvals[0] cdef int* colptrs = Jacobian.colptrs[0] ELSE: @@ -212,7 +212,7 @@ ELSE: return CVDLS_JACFUNC_UNRECVR -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef int cv_jac(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac, void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ @@ -363,7 +363,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef int cv_prec_setup(realtype t, N_Vector yy, N_Vector fyy, bint jok, bint *jcurPtr, realtype gamma, void *problem_data) noexcept: @@ -558,7 +558,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi traceback.print_exc() return IDA_RES_FAIL -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef int ida_jac(realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, SUNMatrix Jac, void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept: """ @@ -744,7 +744,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv # Error handling callback functions # ================================= -IF SUNDIALS_VERSION >= (7,0,0): +IF SUNDIALS_VERSION_NR >= 700000: cdef extern from "sundials/sundials_context.h": ctypedef _SUNContext * SUNContext cdef struct _SUNContext: @@ -776,7 +776,7 @@ ELSE: if error_code < 0: #Error print('[CVode Error]', msg) -IF SUNDIALS_VERSION >= (7,0,0): +IF SUNDIALS_VERSION_NR >= 700000: cdef void ida_err(int line, const char* func, const char* file, const char* msg, SUNErrCode error_code, void* problem_data, SUNContext sunctx) noexcept: """ This method overrides the default handling of error messages. diff --git a/src/lib/sundials_callbacks_kinsol.pxi b/src/lib/sundials_callbacks_kinsol.pxi index 3066c293..7fe27fc9 100644 --- a/src/lib/sundials_callbacks_kinsol.pxi +++ b/src/lib/sundials_callbacks_kinsol.pxi @@ -19,7 +19,7 @@ import cython import traceback from assimulo.exception import AssimuloRecoverableError -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef int kin_jac(N_Vector xv, N_Vector fval, SUNMatrix Jac, void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept: """ @@ -67,7 +67,7 @@ ELSE: except Exception: return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: ctypedef bint kin_jacv_bool ELSE: ctypedef int kin_jacv_bool @@ -115,7 +115,7 @@ cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data) noexcept: traceback.print_exc() return KIN_SYSFUNC_FAIL -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef int kin_prec_solve(N_Vector u, N_Vector uscaleN, N_Vector fval, N_Vector fscaleN, N_Vector v, void *problem_data) noexcept: """ @@ -221,7 +221,7 @@ ELSE: return KIN_SUCCESS -IF SUNDIALS_VERSION >= (7,0,0): +IF SUNDIALS_VERSION_NR >= 700000: cdef extern from "sundials/sundials_context.h": ctypedef _SUNContext * SUNContext cdef struct _SUNContext: diff --git a/src/lib/sundials_includes.pxd b/src/lib/sundials_includes.pxd index 671bc3db..660d1a87 100644 --- a/src/lib/sundials_includes.pxd +++ b/src/lib/sundials_includes.pxd @@ -31,28 +31,28 @@ from numpy cimport NPY_DOUBLE, npy_intp, NPY_INT #External definitions from Sundials headers #============================================== -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "sundials/sundials_context.h": ctypedef _SUNContext * SUNContext cdef struct _SUNContext: pass - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: ctypedef int SUNComm int SUNContext_Create(SUNComm comm, SUNContext* ctx) noexcept ELSE: int SUNContext_Create(void* comm, SUNContext* ctx) noexcept -IF SUNDIALS_VERSION >= (7,0,0): +IF SUNDIALS_VERSION_NR >= 700000: cdef extern from "sundials/sundials_context.h": ctypedef int SUNErrCode ctypedef void (*SUNErrHandlerFn)(int line, const char* func, const char* file, const char* msg, SUNErrCode err_code, void* err_user_data, SUNContext sunctx) noexcept SUNErrCode SUNContext_PushErrHandler(SUNContext sunctx, SUNErrHandlerFn err_fn, void* err_user_data) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "sundials/sundials_types.h": ctypedef double sunrealtype ctypedef bint sunbooleantype - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef int SUN_COMM_NULL ctypedef double realtype ctypedef bint booleantype @@ -82,7 +82,7 @@ cdef extern from "nvector/nvector_serial.h": cdef N_Vector N_VMake_Serial(long int vec_length, realtype *v_data) noexcept void N_VSetArrayPointer_Serial(realtype *v_data, N_Vector v) noexcept void N_VConst_Serial(realtype c, N_Vector z) noexcept - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: N_Vector N_VNew_Serial(long int vec_length, SUNContext ctx) noexcept N_Vector *N_VCloneVectorArray(int count, N_Vector w) noexcept N_Vector *N_VCloneVectorArrayEmpty(int count, N_Vector w) noexcept @@ -95,7 +95,7 @@ cdef extern from "nvector/nvector_serial.h": void N_VPrint_Serial(N_Vector v) noexcept -IF SUNDIALS_VERSION >= (4,0,0): +IF SUNDIALS_VERSION_NR >= 400000: cdef extern from "sundials/sundials_nonlinearsolver.h": ctypedef _generic_SUNNonlinearSolver *SUNNonlinearSolver @@ -105,7 +105,7 @@ ELSE: #Dummy defines ctypedef void *SUNNonlinearSolver -IF SUNDIALS_VERSION >= (3,0,0): +IF SUNDIALS_VERSION_NR >= 300000: cdef extern from "sundials/sundials_types.h": IF SUNDIALS_VECTOR_SIZE == "64": ctypedef long int sunindextype @@ -172,7 +172,7 @@ IF SUNDIALS_VERSION >= (3,0,0): realtype *data sunindextype ldata realtype **cols - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N, SUNContext ctx) noexcept ELSE: SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N) noexcept @@ -191,21 +191,21 @@ IF SUNDIALS_VERSION >= (3,0,0): sunindextype **colptrs sunindextype **colvals sunindextype **rowptrs - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, sunindextype NNZ, int sparsetype, SUNContext ctx) noexcept ELSE: SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, sunindextype NNZ, int sparsetype) noexcept cdef extern from "sunlinsol/sunlinsol_dense.h": - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext ctx) noexcept ELSE: SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A) noexcept ELSE: SUNLinearSolver SUNDenseLinearSolver(N_Vector y, SUNMatrix A) noexcept cdef extern from "sunlinsol/sunlinsol_spgmr.h": - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, SUNContext ctx) noexcept ELSE: SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl) noexcept @@ -237,9 +237,9 @@ cdef extern from "sundials/sundials_direct.h": ctypedef _DlsMat* DlsMat cdef realtype* DENSE_COL(DlsMat A, int j) noexcept -IF SUNDIALS_VERSION >= (5,0,0): +IF SUNDIALS_VERSION_NR >= 500000: pass -ELIF SUNDIALS_VERSION >= (2,6,3): +ELIF SUNDIALS_VERSION_NR >= 200603: cdef extern from "sundials/sundials_sparse.h": cdef struct _SlsMat: int M @@ -255,7 +255,7 @@ ELIF SUNDIALS_VERSION >= (2,6,3): int **colvals int **rowptrs ctypedef _SlsMat* SlsMat -ELIF SUNDIALS_VERSION >= (2,6,0): +ELIF SUNDIALS_VERSION_NR >= 200600: cdef extern from "sundials/sundials_sparse.h": cdef struct _SlsMat: int M @@ -293,9 +293,9 @@ IF SUNDIALS_WITH_SUPERLU: ELSE: cdef inline int with_superlu() noexcept: return 0 -IF SUNDIALS_VERSION >= (4,0,0): +IF SUNDIALS_VERSION_NR >= 400000: cdef extern from "cvodes/cvodes.h": - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: void* CVodeCreate(int lmm, SUNContext ctx) noexcept ELSE: void* CVodeCreate(int lmm) noexcept @@ -305,14 +305,14 @@ IF SUNDIALS_VERSION >= (4,0,0): int CVodeSetNonlinearSolverSensStg(void *cvode_mem, SUNNonlinearSolver NLS) noexcept cdef extern from "sunnonlinsol/sunnonlinsol_newton.h": - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext ctx) noexcept SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, SUNContext ctx) noexcept ELSE: SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y) noexcept SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y) noexcept cdef extern from "sunnonlinsol/sunnonlinsol_fixedpoint.h": - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext ctx) noexcept SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, SUNContext ctx) noexcept ELSE: @@ -361,7 +361,7 @@ cdef extern from "cvodes/cvodes.h": int CVodeGetActualInitStep(void * cvode_mem, realtype *hinused) noexcept int CVodeGetNumSteps(void *cvode_mem, long int *nsteps) noexcept #Number of steps int CVodeGetNumRhsEvals(void *cvode_mem, long int *nrevals) noexcept #Number of function evals - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int CVodeGetNumJacEvals(void *cvode_mem, long int *njevals) noexcept #Number of jac evals int CVodeGetNumLinRhsEvals(void *cvode_mem, long int *nrevalsLS) noexcept #Number of res evals due to jac evals ELSE: @@ -416,7 +416,7 @@ cdef extern from "cvodes/cvodes.h": int CVodeGetStgrSensNumNonlinSolvIters(void *cvode_mem, long int *nSTGR1niters) noexcept int CVodeGetStgrSensNumNonlinSolvConvFails(void *cvode_mem, long int *nSTGR1ncfails) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "cvodes/cvodes_ls.h": ctypedef int (*CVLsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, void* user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept ctypedef int (*CVLsPrecSolveFn)(sunrealtype t, N_Vector y, N_Vector fy, N_Vector r, N_Vector z, sunrealtype gamma, sunrealtype delta, int lr, void* user_data) noexcept @@ -427,7 +427,7 @@ ELSE: ctypedef int (*CVSpilsJacTimesVecFn)(N_Vector v, N_Vector Jv, realtype t, N_Vector y, N_Vector fy, void *user_data, N_Vector tmp) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "cvode/cvode_ls.h": int CVodeSetJacTimes(void *cvode_mem, CVLsJacTimesSetupFn jtsetup, CVLsJacTimesVecFn jtimes) noexcept int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) noexcept @@ -440,11 +440,11 @@ IF SUNDIALS_VERSION >= (6,0,0): cdef inline int cv_spils_jtsetup_dummy(realtype t, N_Vector y, N_Vector fy, void *user_data) noexcept: return 0 cdef inline tuple version(): return (6,0,0) -ELIF SUNDIALS_VERSION >= (3,0,0): +ELIF SUNDIALS_VERSION_NR >= 300000: cdef extern from "cvodes/cvodes_direct.h": ctypedef int (*CVDlsDenseJacFn)(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, SUNMatrix A) noexcept int CVodeSetJacFn(void *cvode_mem, CVDlsDenseJacFn djac) noexcept ELSE: @@ -452,7 +452,7 @@ ELIF SUNDIALS_VERSION >= (3,0,0): int CVDlsSetJacFn(void *cvode_mem, CVDlsDenseJacFn djac) noexcept cdef extern from "cvodes/cvodes_spils.h": ctypedef int (*CVSpilsJacTimesSetupFn)(realtype t, N_Vector y, N_Vector fy, void *user_data) noexcept - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int CVodeSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, CVSpilsJacTimesVecFn jtimes) noexcept ELSE: int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS) noexcept @@ -493,7 +493,7 @@ ELSE: realtype gamma, realtype delta, int lr, void *user_data, N_Vector tmp) noexcept - IF SUNDIALS_VERSION >= (2,6,0): + IF SUNDIALS_VERSION_NR >= 200600: cdef extern from "cvodes/cvodes_sparse.h": ctypedef int (*CVSlsSparseJacFn)(realtype t, N_Vector y, N_Vector fy, SlsMat Jac, void *user_data, N_Vector tmp1, @@ -515,7 +515,7 @@ ELSE: cdef inline int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals) noexcept: return -1 cdef inline tuple version() noexcept: return (2,5,0) -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "cvode/cvode_ls.h": ctypedef int (*CVLsPrecSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, sunbooleantype jok, sunbooleantype* jcurPtr, sunrealtype gamma, void* user_data) noexcept int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn pset, CVLsPrecSolveFn psolve) noexcept @@ -525,7 +525,7 @@ IF SUNDIALS_VERSION >= (6,0,0): int CVodeGetNumPrecSolves(void *cvode_mem, long int *npsolves) noexcept ELSE: cdef extern from "cvodes/cvodes_spils.h": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int CVodeSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn psetup, CVSpilsPrecSolveFn psolve) noexcept int CVodeGetNumJtimesEvals(void *cvode_mem, long int *njvevals) noexcept #Number of jac*vector evals int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) noexcept #Number of res evals due to jac*vector evals @@ -540,7 +540,7 @@ ELSE: cdef extern from "idas/idas.h": ctypedef int (*IDAResFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, void *user_data) noexcept - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: void* IDACreate(SUNContext ctx) noexcept ELSE: void* IDACreate() noexcept @@ -583,7 +583,7 @@ cdef extern from "idas/idas.h": int IDAGetCurrentOrder(void *ida_mem,int *qcurrent) #Order that is about to be tried int IDAGetNumSteps(void *ida_mem, long int *nsteps) #Number of steps int IDAGetNumResEvals(void *ida_mem, long int *nrevals) #Number of res evals - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int IDAGetNumJacEvals(void *ida_mem, long int *njevals) #Number of jac evals int IDAGetNumLinResEvals(void *ida_mem, long int *nrevalsLS) #Number of res evals due to jac evals ELSE: @@ -638,7 +638,7 @@ cdef extern from "idas/idas.h": #End Sensitivities #================= -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "ida/ida_ls.h": ctypedef int (*IDALsJacFn)(sunrealtype t, sunrealtype c_j, N_Vector y, N_Vector yp, N_Vector r, SUNMatrix Jac, void* user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept ctypedef int (*IDALsJacTimesSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, sunrealtype c_j, void* user_data) noexcept @@ -648,19 +648,19 @@ ELSE: ctypedef int (*IDASpilsJacTimesVecFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector v, N_Vector Jv, realtype cj, void *user_data,N_Vector tmp1, N_Vector tmp2) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "ida/ida_ls.h": int IDASetJacFn(void* ida_mem, IDALsJacFn jac) noexcept int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) noexcept int IDASetJacTimes(void* ida_mem, IDALsJacTimesSetupFn jtsetup, IDALsJacTimesVecFn jtimes) noexcept cdef inline int ida_spils_jtsetup_dummy(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, realtype c_j, void *user_data) noexcept: return 0 -ELIF SUNDIALS_VERSION >= (3,0,0): +ELIF SUNDIALS_VERSION_NR >= 300000: cdef extern from "idas/idas_direct.h": ctypedef int (*IDADlsDenseJacFn)(realtype tt, realtype cj, N_Vector yy, N_Vector yp, N_Vector rr, SUNMatrix Jac, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) noexcept - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int IDASetJacFn(void *ida_mem, IDADlsDenseJacFn djac) int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) ELSE: @@ -670,7 +670,7 @@ ELIF SUNDIALS_VERSION >= (3,0,0): cdef extern from "idas/idas_spils.h": ctypedef int (*IDASpilsJacTimesSetupFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, realtype c_j, void *user_data) noexcept - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int IDASetJacTimes(void *ida_mem, IDASpilsJacTimesSetupFn jtsetup, IDASpilsJacTimesVecFn jtimes) ELSE: @@ -695,13 +695,13 @@ ELSE: cdef extern from "idas/idas_spils.h": int IDASpilsSetJacTimesVecFn(void *ida_mem, IDASpilsJacTimesVecFn ida_jacv) -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "ida/ida_ls.h": int IDAGetNumJtimesEvals(void *ida_mem, long int *njvevals) #Number of jac*vector int IDAGetNumResEvals(void *ida_mem, long int *nfevalsLS) #Number of rhs due to jac*vector ELSE: cdef extern from "idas/idas_spils.h": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int IDAGetNumJtimesEvals(void *ida_mem, long int *njvevals) #Number of jac*vector int IDAGetNumResEvals(void *ida_mem, long int *nfevalsLS) #Number of rhs due to jac*vector ELSE: @@ -720,7 +720,7 @@ cdef extern from "kinsol/kinsol.h": ctypedef int (*KINSysFn)(N_Vector uu, N_Vector fval, void *user_data) noexcept ctypedef void (*KINInfoHandlerFn)(const char *module, const char *function, char *msg, void *user_data) noexcept # initialization routines - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: void *KINCreate(SUNContext ctx) noexcept ELSE: void *KINCreate() noexcept @@ -728,7 +728,7 @@ cdef extern from "kinsol/kinsol.h": # optional input spec. functions, # for specificationsdocumentation cf. kinsol.h line 218-449 - IF SUNDIALS_VERSION < (7,0,0): + IF SUNDIALS_VERSION_NR < 700000: int KINSetInfoHandlerFn(void *kinmem, KINInfoHandlerFn ihfun, void *ih_data) int KINSetPrintLevel(void *kinmemm, int printfl) int KINSetUserData(void *kinmem, void *user_data) @@ -769,7 +769,7 @@ cdef extern from "kinsol/kinsol.h": void KINFree(void **kinmem) # Functions for error handling -IF SUNDIALS_VERSION < (7,0,0): +IF SUNDIALS_VERSION_NR < 700000: cdef extern from "kinsol/kinsol.h": ctypedef void (*KINErrHandlerFn)(int error_code, char *module, char *function, char *msg, void *user_data) noexcept int KINSetErrHandlerFn(void *kinmem, KINErrHandlerFn ehfun, void *eh_data) noexcept @@ -780,15 +780,15 @@ IF SUNDIALS_VERSION < (7,0,0): ctypedef void (*IDAErrHandlerFn)(int error_code, const char *module, const char *function, char *msg, void *eh_data) noexcept int IDASetErrHandlerFn(void *ida_mem,IDAErrHandlerFn ehfun, void* eh_data) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "kinsol/kinsol_ls.h": ctypedef int (*KINLsJacFn)(N_Vector u, N_Vector fu, SUNMatrix J, void* user_data, N_Vector tmp1, N_Vector tmp2) noexcept int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) noexcept int KINSetJacFn(void* kinmem, KINLsJacFn jac) noexcept -ELIF SUNDIALS_VERSION >= (3,0,0): +ELIF SUNDIALS_VERSION_NR >= 300000: cdef extern from "kinsol/kinsol_direct.h": ctypedef int (*KINDlsDenseJacFn)(N_Vector u, N_Vector fu, SUNMatrix J, void *user_data, N_Vector tmp1, N_Vector tmp2) noexcept - IF SUNDIALS_VERSION < (4,0,0): + IF SUNDIALS_VERSION_NR < 400000: int KINDlsSetLinearSolver(void *kinmem, SUNLinearSolver LS, SUNMatrix A) int KINDlsSetJacFn(void *kinmem, KINDlsDenseJacFn djac) ELSE: @@ -822,7 +822,7 @@ ELSE: ctypedef int (*KINSpilsPrecSetupFn)(N_Vector u, N_Vector uscale, N_Vector fval, N_Vector fscale, void *problem_data, N_Vector tmp1, N_Vector tmp2) noexcept -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: cdef extern from "kinsol/kinsol_ls.h": ctypedef int (*KINLsPrecSetupFn)(N_Vector uu, N_Vector uscale, N_Vector fval, N_Vector fscale, void* user_data) noexcept ctypedef int (*KINLsPrecSolveFn)(N_Vector uu, N_Vector uscale, N_Vector fval, N_Vector fscale, N_Vector vv, void* user_data) noexcept @@ -842,7 +842,7 @@ ELSE: cdef extern from "kinsol/kinsol_direct.h": # optional output fcts for linear direct solver int KINDlsGetWorkSpace(void *kinmem, long int *lenrwB, long int *leniwB) - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int KINGetLastLinFlag(void *kinmem, long int *flag) int KINGetNumJacEvals(void *kinmem, long int *njevalsB) int KINGetNumFuncEvals(void *kinmem, long int *nfevalsB) @@ -855,7 +855,7 @@ ELSE: cdef extern from "kinsol/kinsol_spils.h": ctypedef int (*KINSpilsJacTimesVecFn)(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u, void *problem_data) noexcept - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: int KINSetJacTimesVecFn(void *kinmem, KINSpilsJacTimesVecFn jacv) noexcept int KINSetPreconditioner(void *kinmem, KINSpilsPrecSetupFn psetup, KINSpilsPrecSolveFn psolve) noexcept int KINGetNumLinIters(void *kinmem, long int *nliters) noexcept diff --git a/src/solvers/kinsol.pyx b/src/solvers/kinsol.pyx index 341f75a1..30eccfa0 100644 --- a/src/solvers/kinsol.pyx +++ b/src/solvers/kinsol.pyx @@ -27,10 +27,10 @@ cimport sundials_includes as SUNDIALS #Various C includes transfered to namespace from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL, sunindextype from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SUNMatrix, SUNMatrixContent_Dense, SUNMatrixContent_Sparse -IF SUNDIALS_VERSION < (5,0,0): +IF SUNDIALS_VERSION_NR < 500000: from sundials_includes cimport SlsMat from sundials_includes cimport malloc, free -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: from sundials_includes cimport N_VDestroy ELSE: from sundials_includes cimport N_VDestroy_Serial as N_VDestroy @@ -114,7 +114,7 @@ cdef class KINSOL(Algebraic): #Free Memory SUNDIALS.KINFree(&self.kinsol_mem) - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: if self.sun_matrix != NULL: SUNDIALS.SUNMatDestroy(self.sun_matrix) @@ -181,9 +181,9 @@ cdef class KINSOL(Algebraic): cdef initialize_kinsol(self): cdef int flag #Used for return - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -195,7 +195,7 @@ cdef class KINSOL(Algebraic): if self.kinsol_mem == NULL: #The solver is not initialized #Create the solver - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.kinsol_mem = SUNDIALS.KINCreate(ctx) ELSE: self.kinsol_mem = SUNDIALS.KINCreate() @@ -209,7 +209,7 @@ cdef class KINSOL(Algebraic): raise KINSOLError(flag) #Specify the error handling - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: flag = SUNDIALS.SUNContext_PushErrHandler(ctx, kin_err, self.pData) ELSE: flag = SUNDIALS.KINSetErrHandlerFn(self.kinsol_mem, kin_err, self.pData) @@ -217,7 +217,7 @@ cdef class KINSOL(Algebraic): raise KINSOLError(flag) #Specify the handling of info messages - IF SUNDIALS_VERSION < (7,0,0): + IF SUNDIALS_VERSION_NR < 700000: flag = SUNDIALS.KINSetInfoHandlerFn(self.kinsol_mem, kin_info, self.pData); if flag < 0: raise KINSOLError(flag) @@ -231,30 +231,30 @@ cdef class KINSOL(Algebraic): raise KINSOLError(flag) cpdef add_linear_solver(self): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL SUNDIALS.SUNContext_Create(comm, &ctx) if self.options["linear_solver"] == "DENSE": - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create a dense Sundials matrix - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim, ctx) ELSE: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim) #Create a dense Sundials linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.y_temp, self.sun_matrix, ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.y_temp, self.sun_matrix) ELSE: self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.y_temp, self.sun_matrix) #Attach it to Kinsol - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetLinearSolver(self.kinsol_mem, self.sun_linearsolver, self.sun_matrix) ELSE: flag = SUNDIALS.KINDlsSetLinearSolver(self.kinsol_mem, self.sun_linearsolver, self.sun_matrix) @@ -264,8 +264,8 @@ cdef class KINSOL(Algebraic): raise KINSOLError(flag) if self.problem_info["jac_fcn"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetJacFn(self.kinsol_mem, kin_jac) ELSE: flag = SUNDIALS.KINDlsSetJacFn(self.kinsol_mem, kin_jac) @@ -274,17 +274,17 @@ cdef class KINSOL(Algebraic): if flag < 0: raise KINSOLError(flag) elif self.options["linear_solver"] == "SPGMR": - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create the linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.y_temp, self.options["precond"], self.options["max_krylov"], ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.y_temp, self.options["precond"], self.options["max_krylov"]) ELSE: self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.y_temp, self.options["precond"], self.options["max_krylov"]) #Attach it to Kinsol - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetLinearSolver(self.kinsol_mem, self.sun_linearsolver, NULL) ELSE: flag = SUNDIALS.KINSpilsSetLinearSolver(self.kinsol_mem, self.sun_linearsolver) @@ -295,7 +295,7 @@ cdef class KINSOL(Algebraic): raise KINSOLError(flag) if self.problem_info["jacv_fcn"]: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetJacTimesVecFn(self.kinsol_mem, kin_jacv) ELSE: flag = SUNDIALS.KINSpilsSetJacTimesVecFn(self.kinsol_mem, kin_jacv) @@ -304,21 +304,21 @@ cdef class KINSOL(Algebraic): if self.problem_info["prec_setup"] or self.problem_info["prec_solve"]: if not self.problem_info["prec_setup"]: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetPreconditioner(self.kinsol_mem, NULL, kin_prec_solve) ELSE: flag = SUNDIALS.KINSpilsSetPreconditioner(self.kinsol_mem, NULL, kin_prec_solve) if flag < 0: raise KINSOLError(flag) elif not self.problem_info["prec_solve"]: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetPreconditioner(self.kinsol_mem, kin_prec_setup, NULL) ELSE: flag = SUNDIALS.KINSpilsSetPreconditioner(self.kinsol_mem, kin_prec_setup, NULL) if flag < 0: raise KINSOLError(flag) else: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINSetPreconditioner(self.kinsol_mem, kin_prec_setup, kin_prec_solve) ELSE: flag = SUNDIALS.KINSpilsSetPreconditioner(self.kinsol_mem, kin_prec_setup, kin_prec_solve) @@ -377,7 +377,7 @@ cdef class KINSOL(Algebraic): if flag < 0: raise KINSOLError(flag) - IF SUNDIALS_VERSION < (7,0,0): + IF SUNDIALS_VERSION_NR < 700000: flag = SUNDIALS.KINSetPrintLevel(self.kinsol_mem, self._get_print_level()); #The function KINSetPrintLevel specifies the level of verbosity of the output. if flag < 0: raise KINSOLError(flag) @@ -442,7 +442,7 @@ cdef class KINSOL(Algebraic): """ cdef int flag = 0, cdef long int lsflag = 0 - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetLastLinFlag(self.kinsol_mem, &lsflag) ELSE: flag = SUNDIALS.KINDlsGetLastFlag(self.kinsol_mem, &lsflag) @@ -478,42 +478,42 @@ cdef class KINSOL(Algebraic): self.statistics["nbcfails"] = nbcfails if self.options["linear_solver"] == "SPGMR": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumLinIters(self.kinsol_mem, &nliters) ELSE: flag = SUNDIALS.KINSpilsGetNumLinIters(self.kinsol_mem, &nliters) if flag < 0: raise KINSOLError(flag) self.statistics["nliters"] = nliters - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumLinConvFails(self.kinsol_mem, &nlcfails) ELSE: flag = SUNDIALS.KINSpilsGetNumConvFails(self.kinsol_mem, &nlcfails) if flag < 0: raise KINSOLError(flag) self.statistics["nlcfails"] = nlcfails - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumPrecEvals(self.kinsol_mem, &npevals) ELSE: flag = SUNDIALS.KINSpilsGetNumPrecEvals(self.kinsol_mem, &npevals) if flag < 0: raise KINSOLError(flag) self.statistics["npevals"] = npevals - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumPrecSolves(self.kinsol_mem, &npsolves) ELSE: flag = SUNDIALS.KINSpilsGetNumPrecSolves(self.kinsol_mem, &npsolves) if flag < 0: raise KINSOLError(flag) self.statistics["npsolves"] = npsolves - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumJtimesEvals(self.kinsol_mem, &njevals) ELSE: flag = SUNDIALS.KINSpilsGetNumJtimesEvals(self.kinsol_mem, &njevals) if flag < 0: raise KINSOLError(flag) self.statistics["njevals"] = njevals - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumFuncEvals(self.kinsol_mem, &nfevalsLS) ELSE: flag = SUNDIALS.KINSpilsGetNumFuncEvals(self.kinsol_mem, &nfevalsLS) @@ -522,14 +522,14 @@ cdef class KINSOL(Algebraic): self.statistics["nfevalsLS"] = nfevalsLS elif self.options["linear_solver"] == "DENSE": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumJacEvals(self.kinsol_mem, &njevals) #The function KINDlsGetNumJacEvals returns the number of calls to the dense Jacobian approximation function. ELSE: flag = SUNDIALS.KINDlsGetNumJacEvals(self.kinsol_mem, &njevals) if flag < 0: raise KINSOLError(flag) self.statistics["njevals"] = njevals - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.KINGetNumFuncEvals(self.kinsol_mem, &nfevalsLS) #The function KINDlsGetNumFuncEvals returns the number of calls to the user system function used to compute the difference quotient approximation to the dense or banded Jacobian. ELSE: flag = SUNDIALS.KINDlsGetNumFuncEvals(self.kinsol_mem, &nfevalsLS) diff --git a/src/solvers/sundials.pyx b/src/solvers/sundials.pyx index a019f539..c45baa95 100644 --- a/src/solvers/sundials.pyx +++ b/src/solvers/sundials.pyx @@ -31,10 +31,10 @@ cimport sundials_includes as SUNDIALS #Various C includes transfered to namespace from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL, sunindextype from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SUNMatrix, SUNMatrixContent_Dense, SUNMatrixContent_Sparse -IF SUNDIALS_VERSION < (5,0,0): +IF SUNDIALS_VERSION_NR < 500000: from sundials_includes cimport SlsMat from sundials_includes cimport malloc, free, N_VConst_Serial -IF SUNDIALS_VERSION >= (6,0,0): +IF SUNDIALS_VERSION_NR >= 600000: from sundials_includes cimport N_VCloneVectorArray, N_VDestroy ELSE: from sundials_includes cimport N_VCloneVectorArray_Serial as N_VCloneVectorArray @@ -181,7 +181,7 @@ cdef class IDA(Implicit_ODE): #Free Memory SUNDIALS.IDAFree(&self.ida_mem) - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: if self.sun_matrix != NULL: SUNDIALS.SUNMatDestroy(self.sun_matrix) @@ -237,9 +237,9 @@ cdef class IDA(Implicit_ODE): cdef initialize_ida(self): cdef int flag #Used for return cdef realtype ZERO = 0.0 - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -267,7 +267,7 @@ cdef class IDA(Implicit_ODE): if self.ida_mem == NULL: #The solver is not initialized - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.ida_mem = SUNDIALS.IDACreate(ctx) ELSE: self.ida_mem = SUNDIALS.IDACreate() #Create solver @@ -281,22 +281,22 @@ cdef class IDA(Implicit_ODE): #Choose a linear solver if and only if NEWTON is choosen if self.options["linear_solver"] == 'DENSE': - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create a dense Sundials matrix - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim, ctx) ELSE: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim) #Create a dense Sundials linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.yTemp, self.sun_matrix, ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.yTemp, self.sun_matrix) ELSE: self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.yTemp, self.sun_matrix) #Attach it to IDA - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetLinearSolver(self.ida_mem, self.sun_linearsolver, self.sun_matrix) ELSE: flag = SUNDIALS.IDADlsSetLinearSolver(self.ida_mem, self.sun_linearsolver, self.sun_matrix) @@ -307,17 +307,17 @@ cdef class IDA(Implicit_ODE): raise IDAError(flag, self.t) elif self.options["linear_solver"] == 'SPGMR': - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create the linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.yTemp, PREC_NONE, 0, ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.yTemp, PREC_NONE, 0) ELSE: self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.yTemp, PREC_NONE, 0) #Attach it to IDAS - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetLinearSolver(self.ida_mem, self.sun_linearsolver, NULL) ELSE: flag = SUNDIALS.IDASpilsSetLinearSolver(self.ida_mem, self.sun_linearsolver) @@ -340,7 +340,7 @@ cdef class IDA(Implicit_ODE): raise IDAError(flag,self.t) #Specify the error handling - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: flag = SUNDIALS.SUNContext_PushErrHandler(ctx, ida_err, self.pData) ELSE: flag = SUNDIALS.IDASetErrHandlerFn(self.ida_mem, ida_err, self.pData) @@ -367,8 +367,8 @@ cdef class IDA(Implicit_ODE): if self.options["linear_solver"] == 'DENSE': #Specify the jacobian to the solver if self.pData.JAC != NULL and self.options["usejac"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetJacFn(self.ida_mem, ida_jac) ELSE: flag = SUNDIALS.IDADlsSetJacFn(self.ida_mem, ida_jac) @@ -377,8 +377,8 @@ cdef class IDA(Implicit_ODE): if flag < 0: raise IDAError(flag,self.t) else: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetJacFn(self.ida_mem, NULL) ELSE: flag = SUNDIALS.IDADlsSetJacFn(self.ida_mem, NULL) @@ -390,8 +390,8 @@ cdef class IDA(Implicit_ODE): elif self.options["linear_solver"] == 'SPGMR': #Specify the jacobian times vector function if self.pData.JACV != NULL and self.options["usejac"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetJacTimes(self.ida_mem, SUNDIALS.ida_spils_jtsetup_dummy, ida_jacv) ELSE: flag = SUNDIALS.IDASpilsSetJacTimes(self.ida_mem, SUNDIALS.ida_spils_jtsetup_dummy, ida_jacv) @@ -400,8 +400,8 @@ cdef class IDA(Implicit_ODE): if flag < 0: raise IDAError(flag, self.t) else: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDASetJacTimes(self.ida_mem, NULL, NULL) ELSE: flag = SUNDIALS.IDASpilsSetJacTimes(self.ida_mem, NULL, NULL) @@ -740,9 +740,9 @@ cdef class IDA(Implicit_ODE): cpdef get_last_estimated_errors(self): cdef flag cdef np.ndarray err, pyweight, pyele - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -778,9 +778,9 @@ cdef class IDA(Implicit_ODE): """ cdef flag cdef np.ndarray res - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -822,9 +822,9 @@ cdef class IDA(Implicit_ODE): A matrix containing the Ns vectors or a vector if i is specified. """ - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -1443,7 +1443,7 @@ cdef class IDA(Implicit_ODE): flag = SUNDIALS.IDAGetNumGEvals(self.ida_mem, &ngevals) if self.options["linear_solver"] == "SPGMR": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDAGetNumJtimesEvals(self.ida_mem, &njvevals) #Number of jac*vector flag = SUNDIALS.IDAGetNumLinResEvals(self.ida_mem, &nfevalsLS) #Number of rhs due to jac*vector ELSE: @@ -1452,7 +1452,7 @@ cdef class IDA(Implicit_ODE): self.statistics["nfcnjacs"] += nfevalsLS self.statistics["njacvecs"] += njvevals else: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.IDAGetNumJacEvals(self.ida_mem, &njevals) flag = SUNDIALS.IDAGetNumLinResEvals(self.ida_mem, &nrevalsLS) ELSE: @@ -1610,7 +1610,7 @@ cdef class CVode(Explicit_ODE): #Free Memory SUNDIALS.CVodeFree(&self.cvode_mem) - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: if self.sun_matrix != NULL: SUNDIALS.SUNMatDestroy(self.sun_matrix) @@ -1626,9 +1626,9 @@ cdef class CVode(Explicit_ODE): if self.cvode_mem == NULL: raise CVodeError(CV_MEM_FAIL) - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -1721,9 +1721,9 @@ cdef class CVode(Explicit_ODE): if self.cvode_mem == NULL: raise CVodeError(CV_MEM_FAIL) - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -1798,9 +1798,9 @@ cdef class CVode(Explicit_ODE): cdef initialize_cvode(self): cdef int flag #Used for return cdef realtype ZERO = 0.0 - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -1830,8 +1830,8 @@ cdef class CVode(Explicit_ODE): if self.cvode_mem == NULL: #The solver is not initialized #Create the solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.cvode_mem = SUNDIALS.CVodeCreate(CV_BDF if self.options["discr"] == "BDF" else CV_ADAMS, ctx) ELSE: self.cvode_mem = SUNDIALS.CVodeCreate(CV_BDF if self.options["discr"] == "BDF" else CV_ADAMS) @@ -1846,14 +1846,14 @@ cdef class CVode(Explicit_ODE): raise CVodeError(flag, self.t) #For Sundials >=4.0 the iteration scheme is set after init - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: if self.options["iter"] == "Newton": - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_nonlinearsolver = SUNDIALS.SUNNonlinSol_Newton(self.yTemp, ctx) ELSE: self.sun_nonlinearsolver = SUNDIALS.SUNNonlinSol_Newton(self.yTemp) else: - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_nonlinearsolver = SUNDIALS.SUNNonlinSol_FixedPoint(self.yTemp, 0, ctx) ELSE: self.sun_nonlinearsolver = SUNDIALS.SUNNonlinSol_FixedPoint(self.yTemp, 0) @@ -1874,7 +1874,7 @@ cdef class CVode(Explicit_ODE): raise CVodeError(flag, self.t) #Specify the error handling - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: flag = SUNDIALS.SUNContext_PushErrHandler(ctx, cv_err, self.pData) ELSE: flag = SUNDIALS.CVodeSetErrHandlerFn(self.cvode_mem, cv_err, self.pData) @@ -1895,16 +1895,16 @@ cdef class CVode(Explicit_ODE): if flag < 0: raise CVodeError(flag, self.t) - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: count = self.pData.dimSens if self.options["sensmethod"] == "STAGGERED" else (self.pData.dimSens+1) if self.options["iter"] == "Newton": - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_nonlinearsolver_sens = SUNDIALS.SUNNonlinSol_NewtonSens(count, self.yTemp, ctx) ELSE: self.sun_nonlinearsolver_sens = SUNDIALS.SUNNonlinSol_NewtonSens(count, self.yTemp) else: - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_nonlinearsolver_sens = SUNDIALS.SUNNonlinSol_FixedPointSens(count, self.yTemp, 0, ctx) ELSE: self.sun_nonlinearsolver_sens = SUNDIALS.SUNNonlinSol_FixedPointSens(count, self.yTemp, 0) @@ -1961,9 +1961,9 @@ cdef class CVode(Explicit_ODE): """ cdef flag cdef np.ndarray res - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -2006,9 +2006,9 @@ cdef class CVode(Explicit_ODE): A matrix containing the Ns vectors or a vector if i is specified. """ - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -2289,9 +2289,9 @@ cdef class CVode(Explicit_ODE): Updates the simulation options. """ cdef flag - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: cdef SUNDIALS.SUNContext ctx = NULL - IF SUNDIALS_VERSION >= (7,0,0): + IF SUNDIALS_VERSION_NR >= 700000: cdef SUNDIALS.SUNComm comm = SUNDIALS.SUN_COMM_NULL ELSE: cdef void* comm = NULL @@ -2299,22 +2299,22 @@ cdef class CVode(Explicit_ODE): #Choose a linear solver if and only if NEWTON is choosen if self.options["linear_solver"] == 'DENSE' and self.options["iter"] == "Newton": - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create a dense Sundials matrix - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 600000: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim, ctx) ELSE: self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim) #Create a dense Sundials linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.yTemp, self.sun_matrix, ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_Dense(self.yTemp, self.sun_matrix) ELSE: self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.yTemp, self.sun_matrix) #Attach it to CVode - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix) ELSE: flag = SUNDIALS.CVDlsSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix) @@ -2328,8 +2328,8 @@ cdef class CVode(Explicit_ODE): #Specify the jacobian to the solver if self.pData.JAC != NULL and self.options["usejac"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetJacFn(self.cvode_mem, cv_jac) ELSE: flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, cv_jac) @@ -2338,8 +2338,8 @@ cdef class CVode(Explicit_ODE): if flag < 0: raise CVodeError(flag) else: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetJacFn(self.cvode_mem, NULL) ELSE: flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, NULL) @@ -2350,17 +2350,17 @@ cdef class CVode(Explicit_ODE): raise CVodeError(flag) elif self.options["linear_solver"] == 'SPGMR' and self.options["iter"] == "Newton": - IF SUNDIALS_VERSION >= (3,0,0): + IF SUNDIALS_VERSION_NR >= 300000: #Create the linear solver - IF SUNDIALS_VERSION >= (4,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 400000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.yTemp, self.options["precond"], self.options["maxkrylov"], ctx) ELSE: self.sun_linearsolver = SUNDIALS.SUNLinSol_SPGMR(self.yTemp, self.options["precond"], self.options["maxkrylov"]) ELSE: self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.yTemp, self.options["precond"], self.options["maxkrylov"]) #Attach it to CVode - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetLinearSolver(self.cvode_mem, self.sun_linearsolver, NULL) ELSE: flag = SUNDIALS.CVSpilsSetLinearSolver(self.cvode_mem, self.sun_linearsolver) @@ -2372,14 +2372,14 @@ cdef class CVode(Explicit_ODE): if self.pData.PREC_SOLVE != NULL: if self.pData.PREC_SETUP != NULL: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetPreconditioner(self.cvode_mem, cv_prec_setup, cv_prec_solve) ELSE: flag = SUNDIALS.CVSpilsSetPreconditioner(self.cvode_mem, cv_prec_setup, cv_prec_solve) if flag < 0: raise CVodeError(flag) else: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetPreconditioner(self.cvode_mem, NULL, cv_prec_solve) ELSE: flag = SUNDIALS.CVSpilsSetPreconditioner(self.cvode_mem, NULL, cv_prec_solve) @@ -2388,8 +2388,8 @@ cdef class CVode(Explicit_ODE): #Specify the jacobian times vector function if self.pData.JACV != NULL and self.options["usejac"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetJacTimes(self.cvode_mem, SUNDIALS.cv_spils_jtsetup_dummy, cv_jacv) ELSE: flag = SUNDIALS.CVSpilsSetJacTimes(self.cvode_mem, SUNDIALS.cv_spils_jtsetup_dummy, cv_jacv) @@ -2398,8 +2398,8 @@ cdef class CVode(Explicit_ODE): if flag < 0: raise CVodeError(flag) else: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetJacTimes(self.cvode_mem, NULL, NULL) ELSE: flag = SUNDIALS.CVSpilsSetJacTimes(self.cvode_mem, NULL, NULL) @@ -2418,14 +2418,14 @@ cdef class CVode(Explicit_ODE): if self.problem_info["jac_fcn_nnz"] == -1: raise AssimuloException("Need to specify the number of non zero elements in the Jacobian via the option 'jac_nnz'") - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (6,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 600000: self.sun_matrix = SUNDIALS.SUNSparseMatrix(self.pData.dim, self.pData.dim, self.problem_info["jac_fcn_nnz"], CSC_MAT, ctx) self.sun_linearsolver = SUNDIALS.SUNLinSol_SuperLUMT(self.yTemp, self.sun_matrix, self.options["num_threads"], ctx) ELSE: self.sun_matrix = SUNDIALS.SUNSparseMatrix(self.pData.dim, self.pData.dim, self.problem_info["jac_fcn_nnz"], CSC_MAT) self.sun_linearsolver = SUNDIALS.SUNSuperLUMT(self.yTemp, self.sun_matrix, self.options["num_threads"]) - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix) ELSE: flag = SUNDIALS.CVDlsSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix) @@ -2436,8 +2436,8 @@ cdef class CVode(Explicit_ODE): #Specify the jacobian to the solver if self.pData.JAC != NULL and self.options["usejac"]: - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeSetJacFn(self.cvode_mem, cv_jac_sparse) ELSE: flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, cv_jac_sparse) @@ -3275,7 +3275,7 @@ cdef class CVode(Explicit_ODE): raise CVodeError(CV_MEM_FAIL) if self.options["linear_solver"] == "SPGMR": - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeGetNumJtimesEvals(self.cvode_mem, &njvevals) #Number of jac*vector flag = SUNDIALS.CVodeGetNumRhsEvals(self.cvode_mem, &nfevalsLS) #Number of rhs due to jac*vector ELSE: @@ -3283,8 +3283,8 @@ cdef class CVode(Explicit_ODE): flag = SUNDIALS.CVSpilsGetNumRhsEvals(self.cvode_mem, &nfevalsLS) #Number of rhs due to jac*vector self.statistics["njacvecs"] += njvevals elif self.options["linear_solver"] == "SPARSE": - IF SUNDIALS_VERSION >= (3,0,0): - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 300000: + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeGetNumJacEvals(self.cvode_mem, &njevals) ELSE: flag = SUNDIALS.CVDlsGetNumJacEvals(self.cvode_mem, &njevals) @@ -3292,7 +3292,7 @@ cdef class CVode(Explicit_ODE): flag = SUNDIALS.CVSlsGetNumJacEvals(self.cvode_mem, &njevals) self.statistics["njacs"] += njevals else: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeGetNumJacEvals(self.cvode_mem, &njevals) #Number of jac evals flag = SUNDIALS.CVodeGetNumLinRhsEvals(self.cvode_mem, &nfevalsLS) #Number of res evals due to jac evals ELSE: @@ -3300,13 +3300,13 @@ cdef class CVode(Explicit_ODE): flag = SUNDIALS.CVDlsGetNumRhsEvals(self.cvode_mem, &nfevalsLS) #Number of res evals due to jac evals self.statistics["njacs"] += njevals if self.pData.PREC_SOLVE != NULL: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeGetNumPrecSolves(self.cvode_mem, &npsolves) ELSE: flag = SUNDIALS.CVSpilsGetNumPrecSolves(self.cvode_mem, &npsolves) self.statistics["nprecs"] += npsolves if self.pData.PREC_SETUP != NULL: - IF SUNDIALS_VERSION >= (4,0,0): + IF SUNDIALS_VERSION_NR >= 400000: flag = SUNDIALS.CVodeGetNumPrecEvals(self.cvode_mem, &npevals) ELSE: flag = SUNDIALS.CVSpilsGetNumPrecEvals(self.cvode_mem, &npevals)