From c76c7d356698986c30c2f5cc8097ae66817280e9 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Sat, 19 Oct 2024 10:19:31 +0200 Subject: [PATCH] Update amici to v0.26.3-20-g8253a97d (#388) * Update amici to [8253a97d413cbbcfec335fb50fd1355107804e9e](https://github.com/AMICI-dev/AMICI/commit/8253a97d413cbbcfec335fb50fd1355107804e9e) * GHA: disable ceres due to #391 * Address amici deprecations Mysterious amici errors on GHA, specifically for Weber_BMC2015, not locally reproducible, remain https://github.com/AMICI-dev/AMICI/issues/2491. They already occurred (at least) with amici v0.26.1. --- git subrepo clone --branch=8253a97d413cbbcfec335fb50fd1355107804e9e --force git@github.com:dweindl/AMICI.git deps/AMICI subrepo: subdir: "deps/AMICI" merged: "8253a97d" upstream: origin: "git@github.com:dweindl/AMICI.git" branch: "8253a97d413cbbcfec335fb50fd1355107804e9e" commit: "8253a97d" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "110b9eb" --- .github/workflows/benchmark_models.yml | 2 + .github/workflows/parpe_tests.yml | 4 +- .github/workflows/petab_testsuite.yml | 2 + README.md | 12 +- benchmark_collection/import_and_run.sh | 4 +- .../charliecloud/parpe_base/install_parpe.sh | 5 +- .../.github/workflows/deploy_release.yml | 5 - .../test_benchmark_collection_models.yml | 3 +- .../workflows/test_petab_test_suite.yml | 10 +- .../workflows/test_python_cplusplus.yml | 48 + .../workflows/test_python_ver_matrix.yml | 11 + deps/AMICI/.github/workflows/test_windows.yml | 12 + deps/AMICI/.gitignore | 2 + deps/AMICI/.gitrepo | 6 +- deps/AMICI/.pre-commit-config.yaml | 4 +- deps/AMICI/CHANGELOG.md | 43 + deps/AMICI/CMakeLists.txt | 47 +- .../ThirdParty/SuiteSparse/AMD/CMakeLists.txt | 16 +- .../SuiteSparse/AMD/Config/amd.h.in | 4 +- .../ThirdParty/SuiteSparse/AMD/Doc/ChangeLog | 8 + .../SuiteSparse/AMD/Doc/amd_version.tex | 2 +- .../ThirdParty/SuiteSparse/AMD/Include/amd.h | 10 +- .../ThirdParty/SuiteSparse/AMD/Source/amd.f | 1220 --- .../SuiteSparse/AMD/Source/amdbar.f | 1212 --- .../ThirdParty/SuiteSparse/BTF/CMakeLists.txt | 10 +- .../SuiteSparse/BTF/Config/btf.h.in | 4 +- .../ThirdParty/SuiteSparse/BTF/Doc/ChangeLog | 4 + .../ThirdParty/SuiteSparse/BTF/Include/btf.h | 10 +- .../AMICI/ThirdParty/SuiteSparse/CITATION.bib | 5 +- .../ThirdParty/SuiteSparse/CMakeLists.txt | 30 +- .../SuiteSparse/COLAMD/CMakeLists.txt | 10 +- .../SuiteSparse/COLAMD/Config/colamd.h.in | 4 +- .../SuiteSparse/COLAMD/Doc/ChangeLog | 8 + .../SuiteSparse/COLAMD/Include/colamd.h | 10 +- .../ThirdParty/SuiteSparse/CONTRIBUTING.md | 14 +- .../SuiteSparse/CONTRIBUTOR-LICENSE.txt | 177 - deps/AMICI/ThirdParty/SuiteSparse/ChangeLog | 151 + .../ThirdParty/SuiteSparse/KLU/CMakeLists.txt | 28 +- .../SuiteSparse/KLU/Config/klu.h.in | 16 +- .../ThirdParty/SuiteSparse/KLU/Doc/ChangeLog | 8 + .../SuiteSparse/KLU/Doc/klu_version.tex | 2 +- .../ThirdParty/SuiteSparse/KLU/Include/klu.h | 22 +- deps/AMICI/ThirdParty/SuiteSparse/LICENSE.txt | 9 +- deps/AMICI/ThirdParty/SuiteSparse/README.md | 51 +- .../SuiteSparse_config/CMakeLists.txt | 17 +- .../SuiteSparse_config/Config/README.md.in | 49 +- .../Config/SuiteSparse_config.h.in | 1437 ++-- .../SuiteSparse_config/SuiteSparse_config.h | 1447 ++-- .../cmake_modules/SuiteSparseBLAS.cmake | 9 +- .../cmake_modules/SuiteSparsePolicy.cmake | 4 + deps/AMICI/ThirdParty/sundials/CITATIONS.md | 119 + deps/AMICI/ThirdParty/sundials/CMakeLists.txt | 108 +- .../AMICI/ThirdParty/sundials/CONTRIBUTING.md | 91 - deps/AMICI/ThirdParty/sundials/LICENSE | 2 +- deps/AMICI/ThirdParty/sundials/README.md | 94 +- .../sundials/cmake/SUNDIALSConfig.cmake.in | 149 +- .../cmake/SundialsBuildOptionsPost.cmake | 38 +- .../cmake/SundialsBuildOptionsPre.cmake | 228 +- .../sundials/cmake/SundialsDeprecated.cmake | 92 +- .../cmake/SundialsExampleOptions.cmake | 66 +- .../sundials/cmake/SundialsIndexSize.cmake | 14 +- .../sundials/cmake/SundialsSetupCXX.cmake | 28 +- .../cmake/SundialsSetupCompilers.cmake | 396 +- .../sundials/cmake/SundialsSetupConfig.cmake | 81 +- .../sundials/cmake/SundialsSetupTPLs.cmake | 121 +- .../sundials/cmake/SundialsSetupTesting.cmake | 131 +- .../sundials/cmake/SundialsTPLOptions.cmake | 170 +- .../cmake/macros/CorrectWindowsPaths.cmake | 43 - .../cmake/macros/FindPackageMultipass.cmake | 216 - .../cmake/macros/ResolveCompilerPaths.cmake | 134 - .../cmake/macros/SundialsAddBenchmark.cmake | 96 + .../macros/SundialsAddExamplesGinkgo.cmake | 129 + .../cmake/macros/SundialsAddExecutable.cmake | 45 + .../cmake/macros/SundialsAddLibrary.cmake | 121 +- .../cmake/macros/SundialsAddTest.cmake | 107 +- .../cmake/macros/SundialsAddTestInstall.cmake | 2 +- .../cmake/macros/SundialsCMakeMacros.cmake | 56 +- .../macros/SundialsInstallExamples.cmake | 87 +- .../SundialsInstallExamplesGinkgo.cmake | 131 + .../cmake/macros/SundialsOption.cmake | 108 +- .../macros/SundialsTryCompileExecute.cmake | 2 +- .../sundials/cmake/tpl/FindKLU.cmake | 57 +- .../sundials/cmake/tpl/FindSUPERLUDIST.cmake | 142 +- .../sundials/cmake/tpl/FindSUPERLUMT.cmake | 14 +- .../sundials/cmake/tpl/SundialsKLU.cmake | 45 +- .../sundials/cmake/tpl/SundialsLapack.cmake | 244 +- .../sundials/cmake/tpl/SundialsOpenMP.cmake | 8 +- .../cmake/tpl/SundialsPOSIXTimers.cmake | 190 +- .../sundials/cmake/tpl/SundialsPthread.cmake | 6 +- .../cmake/tpl/SundialsSuperLUDIST.cmake | 102 +- .../cmake/tpl/SundialsSuperLUMT.cmake | 11 +- .../sundials/include/cvodes/cvodes.h | 777 +- .../sundials/include/cvodes/cvodes_bandpre.h | 23 +- .../sundials/include/cvodes/cvodes_bbdpre.h | 57 +- .../sundials/include/cvodes/cvodes_diag.h | 31 +- .../sundials/include/cvodes/cvodes_direct.h | 69 - .../sundials/include/cvodes/cvodes_ls.h | 256 +- .../sundials/include/cvodes/cvodes_proj.h | 57 + .../sundials/include/cvodes/cvodes_spils.h | 107 - .../ThirdParty/sundials/include/idas/idas.h | 691 +- .../sundials/include/idas/idas_bbdpre.h | 60 +- .../sundials/include/idas/idas_direct.h | 70 - .../sundials/include/idas/idas_ls.h | 285 +- .../sundials/include/idas/idas_spils.h | 111 - .../sundials/include/nvector/nvector_serial.h | 277 +- .../sunadaptcontroller_imexgus.h | 88 + .../sunadaptcontroller_soderlind.h | 132 + .../sundials/amici_matlab/README_AMICI.md | 4 + .../amici_matlab/sundials/sundials_config.h | 291 + .../sundials}/sundials_export.h | 17 +- .../sundials/priv/sundials_context_impl.h | 45 + .../sundials/priv/sundials_errors_impl.h | 557 ++ .../sundials/sundials_adaptcontroller.h | 157 + .../sundials/include/sundials/sundials_band.h | 155 +- .../include/sundials/sundials_base.hpp | 151 + .../include/sundials/sundials_config.h | 190 - .../include/sundials/sundials_config.in | 257 +- .../include/sundials/sundials_context.h | 66 + .../include/sundials/sundials_context.hpp | 64 + .../sundials/sundials_convertibleto.hpp | 39 + .../sundials/include/sundials/sundials_core.h | 38 + .../include/sundials/sundials_core.hpp | 25 + .../include/sundials/sundials_dense.h | 284 +- .../include/sundials/sundials_direct.h | 257 +- .../include/sundials/sundials_errors.h | 116 + .../include/sundials/sundials_fconfig.in | 47 - .../include/sundials/sundials_fnvector.h | 42 - .../include/sundials/sundials_futils.h | 12 +- .../include/sundials/sundials_iterative.h | 353 +- .../include/sundials/sundials_lapack.h | 256 - .../include/sundials/sundials_linearsolver.h | 171 +- .../sundials/sundials_linearsolver.hpp | 43 + .../include/sundials/sundials_logger.h | 74 + .../sundials/include/sundials/sundials_math.h | 84 +- .../include/sundials/sundials_matrix.h | 111 +- .../include/sundials/sundials_matrix.hpp | 42 + .../include/sundials/sundials_memory.h | 111 +- .../include/sundials/sundials_memory.hpp | 42 + .../include/sundials/sundials_mpi_types.h | 23 +- .../sundials/sundials_nonlinearsolver.h | 143 +- .../sundials/sundials_nonlinearsolver.hpp | 44 + .../include/sundials/sundials_nvector.h | 357 +- .../include/sundials/sundials_nvector.hpp | 42 + .../sundials/sundials_nvector_senswrapper.h | 66 +- .../include/sundials/sundials_profiler.h | 101 + .../include/sundials/sundials_profiler.hpp | 52 + .../include/sundials/sundials_types.h | 169 +- .../sundials/sundials_types_deprecated.h | 72 + .../include/sundials/sundials_version.h | 13 +- .../include/sunlinsol/sunlinsol_band.h | 61 +- .../include/sunlinsol/sunlinsol_dense.h | 62 +- .../include/sunlinsol/sunlinsol_klu.h | 66 +- .../include/sunlinsol/sunlinsol_lapackband.h | 45 +- .../include/sunlinsol/sunlinsol_lapackdense.h | 45 +- .../include/sunlinsol/sunlinsol_pcg.h | 125 +- .../include/sunlinsol/sunlinsol_spbcgs.h | 85 +- .../include/sunlinsol/sunlinsol_spfgmr.h | 109 +- .../include/sunlinsol/sunlinsol_spgmr.h | 108 +- .../include/sunlinsol/sunlinsol_sptfqmr.h | 88 +- .../include/sunlinsol/sunlinsol_superludist.h | 96 +- .../include/sunlinsol/sunlinsol_superlumt.h | 87 +- .../include/sunmatrix/sunmatrix_band.h | 88 +- .../include/sunmatrix/sunmatrix_dense.h | 68 +- .../include/sunmatrix/sunmatrix_slunrloc.h | 52 +- .../include/sunmatrix/sunmatrix_sparse.h | 159 +- .../include/sunmemory/sunmemory_system.h | 65 + .../sunnonlinsol/sunnonlinsol_fixedpoint.h | 146 +- .../sunnonlinsol/sunnonlinsol_newton.h | 119 +- .../ThirdParty/sundials/src/CMakeLists.txt | 3 +- .../sundials/src/cvodes/CMakeLists.txt | 14 +- .../ThirdParty/sundials/src/cvodes/LICENSE | 2 +- .../ThirdParty/sundials/src/cvodes/README.md | 21 +- .../ThirdParty/sundials/src/cvodes/cvodea.c | 2574 +++--- .../sundials/src/cvodes/cvodea_io.c | 629 +- .../ThirdParty/sundials/src/cvodes/cvodes.c | 7231 ++++++++++------- .../sundials/src/cvodes/cvodes_bandpre.c | 515 +- .../sundials/src/cvodes/cvodes_bandpre_impl.h | 41 +- .../sundials/src/cvodes/cvodes_bbdpre.c | 783 +- .../sundials/src/cvodes/cvodes_bbdpre_impl.h | 50 +- .../sundials/src/cvodes/cvodes_diag.c | 376 +- .../sundials/src/cvodes/cvodes_diag_impl.h | 29 +- .../sundials/src/cvodes/cvodes_direct.c | 65 - .../sundials/src/cvodes/cvodes_impl.h | 1232 +-- .../sundials/src/cvodes/cvodes_io.c | 2393 ++++-- .../sundials/src/cvodes/cvodes_ls.c | 2602 +++--- .../sundials/src/cvodes/cvodes_ls_impl.h | 205 +- .../sundials/src/cvodes/cvodes_nls.c | 283 +- .../sundials/src/cvodes/cvodes_nls_sim.c | 447 +- .../sundials/src/cvodes/cvodes_nls_stg.c | 367 +- .../sundials/src/cvodes/cvodes_nls_stg1.c | 280 +- .../sundials/src/cvodes/cvodes_proj.c | 453 ++ .../sundials/src/cvodes/cvodes_proj_impl.h | 75 + .../sundials/src/cvodes/cvodes_spils.c | 107 - .../sundials/src/idas/CMakeLists.txt | 12 +- .../ThirdParty/sundials/src/idas/LICENSE | 2 +- .../ThirdParty/sundials/src/idas/README.md | 21 +- .../AMICI/ThirdParty/sundials/src/idas/idaa.c | 2824 ++++--- .../ThirdParty/sundials/src/idas/idaa_io.c | 709 +- .../AMICI/ThirdParty/sundials/src/idas/idas.c | 6558 ++++++++------- .../sundials/src/idas/idas_bbdpre.c | 719 +- .../sundials/src/idas/idas_bbdpre_impl.h | 48 +- .../sundials/src/idas/idas_direct.c | 66 - .../ThirdParty/sundials/src/idas/idas_ic.c | 1087 +-- .../ThirdParty/sundials/src/idas/idas_impl.h | 1047 +-- .../ThirdParty/sundials/src/idas/idas_io.c | 2157 +++-- .../ThirdParty/sundials/src/idas/idas_ls.c | 2370 +++--- .../sundials/src/idas/idas_ls_impl.h | 221 +- .../ThirdParty/sundials/src/idas/idas_nls.c | 266 +- .../sundials/src/idas/idas_nls_sim.c | 374 +- .../sundials/src/idas/idas_nls_stg.c | 312 +- .../ThirdParty/sundials/src/idas/idas_spils.c | 114 - .../sundials/src/nvector/CMakeLists.txt | 24 +- .../src/nvector/serial/CMakeLists.txt | 24 +- .../src/nvector/serial/nvector_serial.c | 1621 ++-- .../src/sunadaptcontroller/CMakeLists.txt | 19 + .../sunadaptcontroller/imexgus/CMakeLists.txt | 31 + .../imexgus/sunadaptcontroller_imexgus.c | 234 + .../soderlind/CMakeLists.txt | 31 + .../soderlind/sunadaptcontroller_soderlind.c | 435 + .../sundials/src/sundials/CMakeLists.txt | 84 +- .../src/sundials/sundials_adaptcontroller.c | 199 + .../src/sundials/sundials_adiak_metadata.h | 149 + .../sundials/src/sundials/sundials_band.c | 249 +- .../sundials/src/sundials/sundials_context.c | 299 + .../sundials/src/sundials/sundials_debug.h | 12 +- .../sundials/src/sundials/sundials_dense.c | 326 +- .../sundials/src/sundials/sundials_direct.c | 328 +- .../sundials/src/sundials/sundials_errors.c | 116 + .../sundials/src/sundials/sundials_futils.c | 29 +- .../sundials/src/sundials/sundials_hashmap.c | 342 + .../src/sundials/sundials_hashmap_impl.h | 57 + .../src/sundials/sundials_iterative.c | 661 +- .../src/sundials/sundials_iterative_impl.h | 40 + .../src/sundials/sundials_linearsolver.c | 203 +- .../sundials/src/sundials/sundials_logger.c | 474 ++ .../src/sundials/sundials_logger_impl.h | 84 + .../sundials/src/sundials/sundials_macros.h | 39 + .../sundials/src/sundials/sundials_math.c | 98 +- .../sundials/src/sundials/sundials_matrix.c | 140 +- .../sundials/src/sundials/sundials_memory.c | 259 +- .../src/sundials/sundials_nonlinearsolver.c | 180 +- .../sundials/src/sundials/sundials_nvector.c | 907 ++- .../sundials/sundials_nvector_senswrapper.c | 428 +- .../sundials/src/sundials/sundials_profiler.c | 587 ++ .../sundials/src/sundials/sundials_utils.h | 89 + .../sundials/src/sundials/sundials_version.c | 39 +- .../sundials/src/sunlinsol/CMakeLists.txt | 33 +- .../src/sunlinsol/band/CMakeLists.txt | 26 +- .../src/sunlinsol/band/sunlinsol_band.c | 187 +- .../src/sunlinsol/dense/CMakeLists.txt | 26 +- .../src/sunlinsol/dense/sunlinsol_dense.c | 166 +- .../sundials/src/sunlinsol/klu/CMakeLists.txt | 27 +- .../src/sunlinsol/klu/sunlinsol_klu.c | 367 +- .../src/sunlinsol/lapackband/CMakeLists.txt | 26 +- .../lapackband/sunlinsol_lapackband.c | 191 +- .../src/sunlinsol/lapackdense/CMakeLists.txt | 27 +- .../lapackdense/sunlinsol_lapackdense.c | 179 +- .../sundials/src/sunlinsol/pcg/CMakeLists.txt | 28 +- .../src/sunlinsol/pcg/sunlinsol_pcg.c | 591 +- .../src/sunlinsol/spbcgs/CMakeLists.txt | 26 +- .../src/sunlinsol/spbcgs/sunlinsol_spbcgs.c | 786 +- .../src/sunlinsol/spfgmr/CMakeLists.txt | 26 +- .../src/sunlinsol/spfgmr/sunlinsol_spfgmr.c | 733 +- .../src/sunlinsol/spgmr/CMakeLists.txt | 26 +- .../src/sunlinsol/spgmr/sunlinsol_spgmr.c | 818 +- .../src/sunlinsol/sptfqmr/CMakeLists.txt | 26 +- .../src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c | 1066 +-- .../src/sunlinsol/superludist/CMakeLists.txt | 12 +- .../superludist/sunlinsol_superludist.c | 185 +- .../src/sunlinsol/superlumt/CMakeLists.txt | 25 +- .../sunlinsol/superlumt/sunlinsol_superlumt.c | 366 +- .../sundials/src/sunmatrix/CMakeLists.txt | 33 +- .../src/sunmatrix/band/CMakeLists.txt | 24 +- .../src/sunmatrix/band/sunmatrix_band.c | 472 +- .../src/sunmatrix/dense/CMakeLists.txt | 24 +- .../src/sunmatrix/dense/sunmatrix_dense.c | 320 +- .../src/sunmatrix/slunrloc/CMakeLists.txt | 5 +- .../sunmatrix/slunrloc/sunmatrix_slunrloc.c | 311 +- .../src/sunmatrix/sparse/CMakeLists.txt | 24 +- .../src/sunmatrix/sparse/sunmatrix_sparse.c | 1165 ++- .../sundials/src/sunmemory/CMakeLists.txt | 8 +- .../src/sunmemory/system/CMakeLists.txt | 26 + .../sunmemory/system/sundials_system_memory.c | 170 + .../sundials/src/sunnonlinsol/CMakeLists.txt | 2 +- .../sunnonlinsol/fixedpoint/CMakeLists.txt | 26 +- .../fixedpoint/fsunnonlinsol_fixedpoint.c | 95 - .../fixedpoint/fsunnonlinsol_fixedpoint.h | 56 - .../fixedpoint/sunnonlinsol_fixedpoint.c | 689 +- .../src/sunnonlinsol/newton/CMakeLists.txt | 26 +- .../newton/fsunnonlinsol_newton.c | 95 - .../newton/fsunnonlinsol_newton.h | 56 - .../sunnonlinsol/newton/sunnonlinsol_newton.c | 414 +- deps/AMICI/binder/Dockerfile | 2 +- deps/AMICI/cmake/AmiciConfig.cmake | 65 - deps/AMICI/cmake/AmiciConfig.cmake.in | 31 + deps/AMICI/documentation/amici_refs.bib | 45 + deps/AMICI/documentation/conf.py | 2 +- .../documentation/python_installation.rst | 2 +- deps/AMICI/documentation/references.md | 25 +- deps/AMICI/documentation/rtd_requirements.txt | 2 +- deps/AMICI/include/amici/abstract_model.h | 4 - deps/AMICI/include/amici/defines.h | 8 +- deps/AMICI/include/amici/forwardproblem.h | 2 - deps/AMICI/include/amici/misc.h | 1 - deps/AMICI/include/amici/model.h | 46 +- deps/AMICI/include/amici/model_dae.h | 26 +- deps/AMICI/include/amici/model_dimensions.h | 31 +- deps/AMICI/include/amici/model_ode.h | 17 +- deps/AMICI/include/amici/model_state.h | 192 +- deps/AMICI/include/amici/newton_solver.h | 141 +- deps/AMICI/include/amici/rdata.h | 123 +- deps/AMICI/include/amici/serialization.h | 19 +- deps/AMICI/include/amici/solver.h | 50 +- deps/AMICI/include/amici/solver_cvodes.h | 4 - deps/AMICI/include/amici/solver_idas.h | 4 - deps/AMICI/include/amici/steadystateproblem.h | 7 +- .../include/amici/sundials_linsol_wrapper.h | 117 +- .../include/amici/sundials_matrix_wrapper.h | 26 +- deps/AMICI/include/amici/vector.h | 81 +- .../auxiliary/compileAMICIDependencies.m | 19 +- .../models/model_calvetti/CMakeLists.txt | 14 +- .../models/model_calvetti/model_calvetti.h | 4 +- .../models/model_calvetti/swig/CMakeLists.txt | 11 + deps/AMICI/models/model_dirac/CMakeLists.txt | 14 +- deps/AMICI/models/model_dirac/model_dirac.h | 4 +- .../models/model_dirac/swig/CMakeLists.txt | 11 + deps/AMICI/models/model_events/CMakeLists.txt | 14 +- deps/AMICI/models/model_events/model_events.h | 4 +- .../models/model_events/swig/CMakeLists.txt | 11 + .../model_jakstat_adjoint/CMakeLists.txt | 14 +- .../model_jakstat_adjoint.h | 4 +- .../model_jakstat_adjoint/swig/CMakeLists.txt | 11 + .../model_jakstat_adjoint_o2/CMakeLists.txt | 14 +- .../model_jakstat_adjoint_o2.h | 4 +- .../swig/CMakeLists.txt | 11 + .../models/model_nested_events/CMakeLists.txt | 14 +- .../model_nested_events/model_nested_events.h | 4 +- .../model_nested_events/swig/CMakeLists.txt | 11 + deps/AMICI/models/model_neuron/CMakeLists.txt | 14 +- deps/AMICI/models/model_neuron/model_neuron.h | 4 +- .../models/model_neuron/swig/CMakeLists.txt | 11 + .../models/model_neuron_o2/CMakeLists.txt | 14 +- .../models/model_neuron_o2/model_neuron_o2.h | 4 +- .../model_neuron_o2/swig/CMakeLists.txt | 11 + .../models/model_robertson/CMakeLists.txt | 14 +- .../models/model_robertson/model_robertson.h | 4 +- .../model_robertson/swig/CMakeLists.txt | 11 + .../models/model_steadystate/CMakeLists.txt | 14 +- .../model_steadystate/model_steadystate.h | 4 +- .../model_steadystate/swig/CMakeLists.txt | 11 + .../ExampleSteadystate.ipynb | 23 +- deps/AMICI/python/sdist/MANIFEST.in | 1 + deps/AMICI/python/sdist/amici/de_model.py | 38 +- deps/AMICI/python/sdist/amici/import_utils.py | 19 +- .../sdist/amici/petab/cli/import_petab.py | 2 +- deps/AMICI/python/sdist/amici/petab/util.py | 2 +- .../python/sdist/amici/setup.template.py | 5 +- deps/AMICI/python/sdist/amici/splines.py | 10 +- deps/AMICI/python/sdist/pyproject.toml | 1 - deps/AMICI/python/sdist/setup.py | 96 +- .../python/tests/test_preequilibration.py | 25 +- deps/AMICI/python/tests/test_splines.py | 3 +- deps/AMICI/python/tests/test_splines_short.py | 1 + deps/AMICI/scripts/buildAmici.sh | 7 +- deps/AMICI/scripts/buildSuiteSparse.sh | 37 +- deps/AMICI/scripts/buildSundials.sh | 7 +- deps/AMICI/scripts/installAmiciSource.sh | 4 +- deps/AMICI/scripts/run-valgrind-py.sh | 4 +- deps/AMICI/src/CMakeLists.template.cmake | 15 +- deps/AMICI/src/amici.cpp | 37 +- deps/AMICI/src/backwardproblem.cpp | 6 +- deps/AMICI/src/forwardproblem.cpp | 16 +- deps/AMICI/src/model.cpp | 173 +- deps/AMICI/src/model_header.template.h | 10 +- deps/AMICI/src/model_state.cpp | 81 +- deps/AMICI/src/newton_solver.cpp | 251 +- deps/AMICI/src/rdata.cpp | 171 +- deps/AMICI/src/solver.cpp | 144 +- deps/AMICI/src/solver_cvodes.cpp | 85 +- deps/AMICI/src/solver_idas.cpp | 85 +- deps/AMICI/src/steadystateproblem.cpp | 68 +- deps/AMICI/src/sundials_linsol_wrapper.cpp | 203 +- deps/AMICI/src/sundials_matrix_wrapper.cpp | 35 +- deps/AMICI/src/vector.cpp | 16 +- deps/AMICI/swig/CMakeLists_model.cmake | 13 - deps/AMICI/swig/solver.i | 1 + .../test_benchmark_collection.sh | 8 +- .../benchmark-models/test_petab_benchmark.py | 383 +- deps/AMICI/tests/conftest.py | 9 +- deps/AMICI/tests/cpp/CMakeLists.txt | 1 + deps/AMICI/tests/cpp/unittests/testMisc.cpp | 50 +- .../tests/cpp/unittests/testSerialization.cpp | 2 + deps/AMICI/tests/performance/test.py | 4 +- deps/AMICI/tests/testSBMLSuite.py | 6 +- deps/AMICI/version.txt | 2 +- src/parpeamici/CMakeLists.txt | 4 +- src/parpeloadbalancer/CMakeLists.txt | 6 +- tests/parpeoptimization/CMakeLists.txt | 1 + 398 files changed, 46354 insertions(+), 35930 deletions(-) delete mode 100644 deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amd.f delete mode 100644 deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amdbar.f delete mode 100644 deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTOR-LICENSE.txt create mode 100644 deps/AMICI/ThirdParty/sundials/CITATIONS.md delete mode 100644 deps/AMICI/ThirdParty/sundials/CONTRIBUTING.md delete mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/CorrectWindowsPaths.cmake delete mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/FindPackageMultipass.cmake delete mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/ResolveCompilerPaths.cmake create mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddBenchmark.cmake create mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExamplesGinkgo.cmake create mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExecutable.cmake create mode 100644 deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamplesGinkgo.cmake delete mode 100644 deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_direct.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_proj.h delete mode 100644 deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_spils.h delete mode 100644 deps/AMICI/ThirdParty/sundials/include/idas/idas_direct.h delete mode 100644 deps/AMICI/ThirdParty/sundials/include/idas/idas_spils.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_imexgus.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_soderlind.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/README_AMICI.md create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_config.h rename deps/AMICI/ThirdParty/sundials/include/sundials/{ => amici_matlab/sundials}/sundials_export.h (70%) create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_context_impl.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_errors_impl.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_adaptcontroller.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_base.hpp delete mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_convertibleto.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_errors.h delete mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fconfig.in delete mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fnvector.h delete mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_lapack.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_logger.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.hpp create mode 100644 deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types_deprecated.h create mode 100644 deps/AMICI/ThirdParty/sundials/include/sunmemory/sunmemory_system.h delete mode 100644 deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_direct.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj_impl.h delete mode 100644 deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_spils.c delete mode 100644 deps/AMICI/ThirdParty/sundials/src/idas/idas_direct.c delete mode 100644 deps/AMICI/ThirdParty/sundials/src/idas/idas_spils.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/CMakeLists.txt create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/CMakeLists.txt create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/CMakeLists.txt create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adaptcontroller.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adiak_metadata.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_context.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_errors.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap_impl.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative_impl.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger_impl.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_macros.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_profiler.c create mode 100644 deps/AMICI/ThirdParty/sundials/src/sundials/sundials_utils.h create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunmemory/system/CMakeLists.txt create mode 100644 deps/AMICI/ThirdParty/sundials/src/sunmemory/system/sundials_system_memory.c delete mode 100644 deps/AMICI/ThirdParty/sundials/src/sunnonlinsol/fixedpoint/fsunnonlinsol_fixedpoint.c delete mode 100644 deps/AMICI/ThirdParty/sundials/src/sunnonlinsol/fixedpoint/fsunnonlinsol_fixedpoint.h delete mode 100644 deps/AMICI/ThirdParty/sundials/src/sunnonlinsol/newton/fsunnonlinsol_newton.c delete mode 100644 deps/AMICI/ThirdParty/sundials/src/sunnonlinsol/newton/fsunnonlinsol_newton.h delete mode 100644 deps/AMICI/cmake/AmiciConfig.cmake create mode 100644 deps/AMICI/cmake/AmiciConfig.cmake.in diff --git a/.github/workflows/benchmark_models.yml b/.github/workflows/benchmark_models.yml index f67723e18..2a5e92839 100644 --- a/.github/workflows/benchmark_models.yml +++ b/.github/workflows/benchmark_models.yml @@ -33,6 +33,7 @@ jobs: -DCMAKE_BUILD_TYPE=Debug \ -DENABLE_PYTHON=ON \ -DBUILD_TESTS=OFF \ + -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH};${AMICI_PATH}/ThirdParty/SuiteSparse/install" \ && cmake --build "${AMICI_PATH}/build" --parallel -- VERBOSE=1 - name: Configure parpe @@ -40,6 +41,7 @@ jobs: cmake \ -S"${PARPE_BASE}" \ -B"${PARPE_BUILD}" \ + -DPARPE_ENABLE_CERES=OFF \ -DIPOPT_INCLUDE_DIRS=/usr/include/coin/ \ -DIPOPT_LIBRARIES=/usr/lib/libipopt.so \ -DGCOVR_REPORT=TRUE \ diff --git a/.github/workflows/parpe_tests.yml b/.github/workflows/parpe_tests.yml index 1b2cf2dde..3e8d51d95 100644 --- a/.github/workflows/parpe_tests.yml +++ b/.github/workflows/parpe_tests.yml @@ -55,6 +55,7 @@ jobs: -DCMAKE_BUILD_TYPE=Debug \ -DENABLE_PYTHON=ON \ -DBUILD_TESTS=OFF \ + -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH};${AMICI_PATH}/ThirdParty/SuiteSparse/install" \ && cmake --build "${AMICI_PATH}/build" --parallel -- VERBOSE=1 - name: Install parPE deps @@ -75,7 +76,8 @@ jobs: -DIPOPT_LIBRARIES=/usr/lib/libipopt.so \ -DGCOV_REPORT=TRUE \ -DBUILD_TESTING=TRUE \ - -DPARPE_ENABLE_FIDES=TRUE + -DPARPE_ENABLE_FIDES=TRUE \ + -DPARPE_ENABLE_CERES=FALSE - name: Build parPE # with sonar build wrapper diff --git a/.github/workflows/petab_testsuite.yml b/.github/workflows/petab_testsuite.yml index 6265d2ed7..14b59182d 100644 --- a/.github/workflows/petab_testsuite.yml +++ b/.github/workflows/petab_testsuite.yml @@ -34,6 +34,7 @@ jobs: -DCMAKE_BUILD_TYPE=Debug \ -DENABLE_PYTHON=ON \ -DBUILD_TESTS=OFF \ + -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH};${AMICI_PATH}/ThirdParty/SuiteSparse/install" \ && cmake --build "${AMICI_PATH}/build" --parallel -- VERBOSE=1 - name: Configure parpe @@ -41,6 +42,7 @@ jobs: cmake \ -S"${PARPE_BASE}" \ -B"${PARPE_BUILD}" \ + -DPARPE_ENABLE_CERES=OFF \ -DIPOPT_INCLUDE_DIRS=/usr/include/coin/ \ -DIPOPT_LIBRARIES=/usr/lib/libipopt.so \ -DGCOVR_REPORT=TRUE \ diff --git a/README.md b/README.md index d0803e301..b5a29b8f4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ described in [doc/petab_model_import.md](doc/petab_model_import.md). For full functionality, parPE requires the following libraries: -* CMAKE (>=3.15) +* CMAKE (>=3.22) * MPI ([OpenMPI](https://www.open-mpi.org/), [MPICH](https://www.mpich.org/), ...) * IPOPT (>= 1.2.7) (requires coinhsl) @@ -60,7 +60,7 @@ For full functionality, parPE requires the following libraries: * [AMICI](https://github.com/AMICI-dev/AMICI) (included in this repository) (uses SuiteSparse, Sundials) * C++17 compiler -* Python >= 3.9, including header files +* Python >= 3.10, including header files On Debian-based systems, dependencies can be installed via: ```shell @@ -109,10 +109,10 @@ Other sample build scripts are provided as `/build*.sh`. ## Recently tested compilers -* GCC 10.2.0 -* Intel icpc (ICC) 17.0.6 +* GCC 13.2.0 +* Clang 18.1.3 -## Docker +## Containers There is a Dockerfile available in `container/charliecloud/` and images can be found on [dockerhub](https://hub.docker.com/r/dweindl/parpe/). @@ -153,7 +153,7 @@ parPE is being used or has been used in the following projects: parPE has been developed within research projects receiving external funding: -* Through the European Union's Horizon 2020 research and innovation +* Through the European Union's Horizon 2020 research and innovation programme under grant agreement no. 686282 ([CanPathPro](http://canpathpro.eu/)). diff --git a/benchmark_collection/import_and_run.sh b/benchmark_collection/import_and_run.sh index fecc2fcfd..3dc249ce6 100755 --- a/benchmark_collection/import_and_run.sh +++ b/benchmark_collection/import_and_run.sh @@ -47,12 +47,12 @@ amici_root="${AMICI_ROOT:-${parpe_dir}/deps/AMICI/}" cd "${petab_model_dir}" echo "Running petablint on ${petab_yaml}..." -petablint -v -y "${model_name}".yaml +petablint -v "${model_name}".yaml # import AMICI model if [[ ! -d ${amici_model_dir} ]]; then echo "Importing model..." - cmd="amici_import_petab.py --verbose -y ${model_name}.yaml -n ${model_name} -o ${amici_model_dir}" + cmd="amici_import_petab.py --verbose ${model_name}.yaml -n ${model_name} -o ${amici_model_dir}" echo "${cmd}" ${cmd} fi diff --git a/container/charliecloud/parpe_base/install_parpe.sh b/container/charliecloud/parpe_base/install_parpe.sh index d660b5174..fb13eff0a 100755 --- a/container/charliecloud/parpe_base/install_parpe.sh +++ b/container/charliecloud/parpe_base/install_parpe.sh @@ -4,6 +4,7 @@ set -euo pipefail set -x export PARPE_BASE="${PARPE_DIR:-/parPE}" +export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH:-""} # unpack git archive mkdir "$PARPE_BASE" && cd "$PARPE_BASE" @@ -21,7 +22,8 @@ cmake \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DENABLE_PYTHON=ON \ -DBUILD_TESTS=OFF \ - .. && make -j + -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH};${AMICI_PATH}/ThirdParty/SuiteSparse/install" \ + .. && cmake --build . --parallel # install fides optimizer cd "$PARPE_BASE/ThirdParty" && ./installFides.sh @@ -45,6 +47,7 @@ mpi_cmd="$mpi_cmd;--mca;orte_base_help_aggregate;0" cmake \ -DPARPE_BUILD_OPTIMIZED=OFF \ -DPARPE_ENABLE_FIDES=ON \ + -DPARPE_ENABLE_CERES=OFF \ -DIPOPT_INCLUDE_DIRS=/usr/include/coin/ \ -DIPOPT_LIBRARIES=/usr/lib/libipopt.so \ -DMPI_INCLUDE_DIRS=/usr/include/openmpi-x86_64/ \ diff --git a/deps/AMICI/.github/workflows/deploy_release.yml b/deps/AMICI/.github/workflows/deploy_release.yml index b18c31ff2..873c5f6e0 100644 --- a/deps/AMICI/.github/workflows/deploy_release.yml +++ b/deps/AMICI/.github/workflows/deploy_release.yml @@ -36,11 +36,6 @@ jobs: - run: echo "AMICI_DIR=$(pwd)" >> $GITHUB_ENV - - name: Remove direct dependencies from setup.cfg - # Remove any "git+https"-based dependencies that are not supported - # by PyPI and are only required for testing. - run: sed -i '/git+https/d' python/sdist/pyproject.toml - - name: sdist run: scripts/buildSdist.sh diff --git a/deps/AMICI/.github/workflows/test_benchmark_collection_models.yml b/deps/AMICI/.github/workflows/test_benchmark_collection_models.yml index 7c7aacb99..0b14d7371 100644 --- a/deps/AMICI/.github/workflows/test_benchmark_collection_models.yml +++ b/deps/AMICI/.github/workflows/test_benchmark_collection_models.yml @@ -61,13 +61,14 @@ jobs: run: | git clone --depth 1 https://github.com/benchmarking-initiative/Benchmark-Models-PEtab.git \ && export BENCHMARK_COLLECTION="$(pwd)/Benchmark-Models-PEtab/Benchmark-Models/" \ + && pip3 install -e $BENCHMARK_COLLECTION/../src/python \ && AMICI_PARALLEL_COMPILE="" tests/benchmark-models/test_benchmark_collection.sh # run gradient checks - name: Run Gradient Checks run: | pip install git+https://github.com/ICB-DCM/fiddy.git \ - && cd tests/benchmark-models && pytest ./test_petab_benchmark.py + && cd tests/benchmark-models && pytest --durations=10 ./test_petab_benchmark.py # upload results - uses: actions/upload-artifact@v4 diff --git a/deps/AMICI/.github/workflows/test_petab_test_suite.yml b/deps/AMICI/.github/workflows/test_petab_test_suite.yml index 64277fe26..7e86a70d6 100644 --- a/deps/AMICI/.github/workflows/test_petab_test_suite.yml +++ b/deps/AMICI/.github/workflows/test_petab_test_suite.yml @@ -15,7 +15,7 @@ jobs: build: name: PEtab Testsuite - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest env: ENABLE_GCOV_COVERAGE: TRUE @@ -68,12 +68,18 @@ jobs: && source ./venv/bin/activate \ && cd petab_test_suite && pip3 install -e . + - name: Install PEtab benchmark collection + run: | + git clone --depth 1 https://github.com/benchmarking-initiative/Benchmark-Models-PEtab.git \ + && export BENCHMARK_COLLECTION="$(pwd)/Benchmark-Models-PEtab/Benchmark-Models/" \ + && source venv/bin/activate && python -m pip install -e $BENCHMARK_COLLECTION/../src/python + - name: Install petab run: | source ./venv/bin/activate \ && python3 -m pip uninstall -y petab \ && python3 -m pip install git+https://github.com/petab-dev/libpetab-python.git@develop \ - && python3 -m pip install git+https://github.com/FFroehlich/pysb@fix_pattern_matching \ + && python3 -m pip install git+https://github.com/pysb/pysb@master \ && python3 -m pip install sympy>=1.12.1 diff --git a/deps/AMICI/.github/workflows/test_python_cplusplus.yml b/deps/AMICI/.github/workflows/test_python_cplusplus.yml index 2128f4df1..23337986d 100644 --- a/deps/AMICI/.github/workflows/test_python_cplusplus.yml +++ b/deps/AMICI/.github/workflows/test_python_cplusplus.yml @@ -38,6 +38,11 @@ jobs: - name: Set up AMICI C++ libraries uses: ./.github/actions/setup-amici-cpp + - name: Install libsuitesparse-dev + # We don't need libsuitesparse-dev, but let's have it installed, + # to ensure that its presence does not break the build + run: sudo apt-get install -y libsuitesparse-dev + - name: C++ tests run: scripts/run-cpp-tests.sh @@ -125,6 +130,13 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/pooch + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + - uses: actions/checkout@v4 - run: git fetch --prune --unshallow @@ -201,6 +213,13 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cache/pooch + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + - uses: actions/checkout@v4 - run: git fetch --prune --unshallow @@ -259,6 +278,17 @@ jobs: - name: C++ tests run: scripts/run-cpp-tests.sh + - name: Get Pooch Cache Directory + id: get-pooch-cache + run: | + echo "pooch-cache=$(source venv/bin/activate && python -c 'import pooch; print(pooch.os_cache("pooch"))')" >> $GITHUB_ENV + + - name: Cache Pooch Directory + uses: actions/cache@v4 + with: + path: ${{ env.pooch-cache }} + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + - name: Python tests run: | scripts/run-python-tests.sh \ @@ -301,6 +331,24 @@ jobs: - name: Get BioNetGen run: scripts/buildBNGL.sh + + - name: Get Pooch Cache Directory + id: get-pooch-cache + run: | + echo "pooch-cache=$(source venv/bin/activate && python -c 'import pooch; print(pooch.os_cache("pooch"))')" >> $GITHUB_ENV + + - name: Cache Pooch Directory + uses: actions/cache@v4 + with: + path: ${{ env.pooch-cache }} + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + + - name: Install PEtab benchmark collection + run: | + git clone --depth 1 https://github.com/benchmarking-initiative/Benchmark-Models-PEtab.git \ + && export BENCHMARK_COLLECTION="$(pwd)/Benchmark-Models-PEtab/Benchmark-Models/" \ + && source venv/bin/activate && python -m pip install -e $BENCHMARK_COLLECTION/../src/python + - name: Python tests run: | scripts/run-python-tests.sh \ diff --git a/deps/AMICI/.github/workflows/test_python_ver_matrix.yml b/deps/AMICI/.github/workflows/test_python_ver_matrix.yml index da2669b86..55871db7c 100644 --- a/deps/AMICI/.github/workflows/test_python_ver_matrix.yml +++ b/deps/AMICI/.github/workflows/test_python_ver_matrix.yml @@ -60,6 +60,17 @@ jobs: - run: source venv/bin/activate && pip3 install "sympy>=1.12.1" if: matrix.python-version != '3.12' + - name: Get Pooch Cache Directory + id: get-pooch-cache + run: | + echo "pooch-cache=$(source venv/bin/activate && python -c 'import pooch; print(pooch.os_cache("pooch"))')" >> $GITHUB_ENV + + - name: Cache Pooch Directory + uses: actions/cache@v4 + with: + path: ${{ env.pooch-cache }} + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + - name: Python tests run: | source venv/bin/activate \ diff --git a/deps/AMICI/.github/workflows/test_windows.yml b/deps/AMICI/.github/workflows/test_windows.yml index 8b5b3b89f..08532d8d9 100644 --- a/deps/AMICI/.github/workflows/test_windows.yml +++ b/deps/AMICI/.github/workflows/test_windows.yml @@ -77,6 +77,18 @@ jobs: - run: python -m amici + - name: Get Pooch Cache Directory + id: get-pooch-cache + run: | + echo "pooch-cache=$(python -c 'import pooch; print(pooch.os_cache("pooch"))')" >> $GITHUB_ENV + shell: bash + + - name: Cache Pooch Directory + uses: actions/cache@v4 + with: + path: ${{ env.pooch-cache }} + key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ github.job }} + - name: Run Python tests shell: bash run: | diff --git a/deps/AMICI/.gitignore b/deps/AMICI/.gitignore index 4dc288441..0faae713a 100644 --- a/deps/AMICI/.gitignore +++ b/deps/AMICI/.gitignore @@ -182,6 +182,7 @@ ThirdParty/sundials/build/* ThirdParty/SuiteSparse/lib/* ThirdParty/SuiteSparse/include/ ThirdParty/SuiteSparse/share/* +ThirdParty/SuiteSparse/install/* ThirdParty/SuperLU_MT_3.1/ ThirdParty/superlu_mt_3.1.tar.gz ThirdParty/swig-* @@ -203,3 +204,4 @@ cache_fiddy/* debug/* tests/benchmark-models/cache_fiddy/* venv/* +.coverage diff --git a/deps/AMICI/.gitrepo b/deps/AMICI/.gitrepo index 489c6619c..f09bde464 100644 --- a/deps/AMICI/.gitrepo +++ b/deps/AMICI/.gitrepo @@ -5,8 +5,8 @@ ; [subrepo] remote = git@github.com:ICB-DCM/AMICI.git - branch = v0.26.1 - commit = b0d79fffd3ab6e39296353d906e27033bc13dd4c - parent = 157fd81f04bd866127bc75f46887c4ce7c43566d + branch = 8253a97d413cbbcfec335fb50fd1355107804e9e + commit = 8253a97d413cbbcfec335fb50fd1355107804e9e + parent = 4b6205d1b4661c227beee7039416c516d47e91f9 cmdver = 0.4.6 method = merge diff --git a/deps/AMICI/.pre-commit-config.yaml b/deps/AMICI/.pre-commit-config.yaml index 449f94ca7..f16458b29 100644 --- a/deps/AMICI/.pre-commit-config.yaml +++ b/deps/AMICI/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.4.1 + rev: v0.6.7 hooks: # Run the linter. - id: ruff @@ -28,7 +28,7 @@ repos: - python/sdist/pyproject.toml - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.17.0 hooks: - id: pyupgrade args: ["--py310-plus"] diff --git a/deps/AMICI/CHANGELOG.md b/deps/AMICI/CHANGELOG.md index a9f1cde58..44e57b2f2 100644 --- a/deps/AMICI/CHANGELOG.md +++ b/deps/AMICI/CHANGELOG.md @@ -4,6 +4,49 @@ See also our [versioning policy](https://amici.readthedocs.io/en/latest/versioni ## v0.X Series + +### v0.26.3 (2024-10-03) + +**Fixes** + +* Skip building SuiteSparse shared libraries and build all subprojects together + for slightly faster package installation + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2514 + and https://github.com/AMICI-dev/AMICI/pull/2519 + +* Got rid of petab `DeprecationWarnings` when using the `amici_import_petab` + CLI + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2517 + +* Now also sundials and suitesparse are built in debug mode when installing + with `ENABLE_AMICI_DEBUGGING=TRUE` + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2515 + +**Full Changelog**: https://github.com/AMICI-dev/AMICI/compare/v0.26.2...v0.26.3 + +### v0.26.2 (2024-09-25) + +**Fixes** + +* Fixed a sympy float comparison issue in spline code that would cause + an `AssertionError` + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2499 + +* Fixed some warnings from recent CMake versions + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2492 + +* Fixed a potential issue when including AMICI in a CMake project + + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2493 + +**Full Changelog**: https://github.com/AMICI-dev/AMICI/compare/v0.26.1...v0.26.2 + + ### v0.26.1 (2024-07-11) **Fixes** diff --git a/deps/AMICI/CMakeLists.txt b/deps/AMICI/CMakeLists.txt index 2dc0ada46..341bb29dd 100644 --- a/deps/AMICI/CMakeLists.txt +++ b/deps/AMICI/CMakeLists.txt @@ -1,17 +1,10 @@ # # Build AMICI library # -cmake_minimum_required(VERSION 3.15) -cmake_policy(VERSION 3.15...3.27) - -# cmake >=3.27 -if(POLICY CMP0144) - cmake_policy(SET CMP0144 NEW) -endif(POLICY CMP0144) -# cmake >= 3.30 -if(POLICY CMP0167) - cmake_policy(SET CMP0167 NEW) -endif(POLICY CMP0167) +cmake_minimum_required(VERSION 3.22) +# When updating the policy version, please also update it in +# src/CMakeLists.template.cmake +cmake_policy(VERSION 3.22...3.31) project(amici) @@ -137,7 +130,8 @@ elseif(AMICI_TRY_ENABLE_HDF5) endif() set(VENDORED_SUNDIALS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/sundials) -set(SUNDIALS_PRIVATE_INCLUDE_DIRS "${VENDORED_SUNDIALS_DIR}/src") +set(SUNDIALS_PRIVATE_INCLUDE_DIRS + "${VENDORED_SUNDIALS_DIR}/src;${VENDORED_SUNDIALS_DIR}/src/sundials") # Handle different sundials build/install dirs, depending on whether we are # building the Python extension only or the full C++ interface if(AMICI_PYTHON_BUILD_EXT_ONLY) @@ -231,7 +225,14 @@ set(AMICI_CXX_OPTIONS "" CACHE STRING "C++ options for libamici (semicolon-separated)") target_compile_options(${PROJECT_NAME} PRIVATE "${AMICI_CXX_OPTIONS}") - +set_property( + SOURCE src/solver_cvodes.cpp + APPEND + PROPERTY INCLUDE_DIRECTORIES "${SUNDIALS_PRIVATE_INCLUDE_DIRS}") +set_property( + SOURCE src/solver_idas.cpp + APPEND + PROPERTY INCLUDE_DIRECTORIES "${SUNDIALS_PRIVATE_INCLUDE_DIRS}") add_dependencies(${PROJECT_NAME} version) file(GLOB PUBLIC_HEADERS include/amici/*.h) @@ -244,8 +245,7 @@ target_include_directories( $ $ $ - $ - PRIVATE ${SUNDIALS_PRIVATE_INCLUDE_DIRS}) + $) if("$ENV{ENABLE_AMICI_DEBUGGING}" OR "$ENV{ENABLE_GCOV_COVERAGE}" @@ -265,21 +265,14 @@ target_compile_definitions( target_link_libraries( ${PROJECT_NAME} - PUBLIC SUNDIALS::generic_static - SUNDIALS::nvecserial_static + PUBLIC SUNDIALS::nvecserial_static SUNDIALS::sunmatrixband_static SUNDIALS::sunmatrixdense_static SUNDIALS::sunmatrixsparse_static - SUNDIALS::sunlinsolband_static - SUNDIALS::sunlinsoldense_static - SUNDIALS::sunlinsolpcg_static SUNDIALS::sunlinsolspbcgs_static SUNDIALS::sunlinsolspfgmr_static SUNDIALS::sunlinsolspgmr_static SUNDIALS::sunlinsolsptfqmr_static - SUNDIALS::sunlinsolklu_static - SUNDIALS::sunnonlinsolnewton_static - SUNDIALS::sunnonlinsolfixedpoint_static SUNDIALS::cvodes_static SUNDIALS::idas_static $<$:Boost::chrono> @@ -287,6 +280,12 @@ target_link_libraries( ${CMAKE_DL_LIBS} PRIVATE BLAS::BLAS + SUNDIALS::sunnonlinsolnewton_static + SUNDIALS::sunnonlinsolfixedpoint_static + SUNDIALS::sunlinsolklu_static + SUNDIALS::sunlinsolband_static + SUNDIALS::sunlinsoldense_static + SUNDIALS::sunlinsolpcg_static $<$:SUNDIALS::sundials_sunlinsolsuperlumt> ) @@ -377,7 +376,7 @@ export( include(CMakePackageConfigHelpers) include(version) configure_package_config_file( - cmake/AmiciConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/AmiciConfig.cmake" + "cmake/AmiciConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/AmiciConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Amici") write_basic_package_version_file(AmiciConfigVersion.cmake COMPATIBILITY ExactVersion) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/AMD/CMakeLists.txt index 325375911..571400868 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/AMD/CMakeLists.txt @@ -12,10 +12,10 @@ cmake_minimum_required ( VERSION 3.22 ) -set ( AMD_DATE "Jan 10, 2024" ) +set ( AMD_DATE "June 20, 2024" ) set ( AMD_VERSION_MAJOR 3 CACHE STRING "" FORCE ) set ( AMD_VERSION_MINOR 3 CACHE STRING "" FORCE ) -set ( AMD_VERSION_SUB 1 CACHE STRING "" FORCE ) +set ( AMD_VERSION_SUB 3 CACHE STRING "" FORCE ) message ( STATUS "Building AMD version: v" ${AMD_VERSION_MAJOR}. @@ -49,10 +49,10 @@ endif ( ) #------------------------------------------------------------------------------- if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) - find_package ( SuiteSparse_config 7.5.0 + find_package ( SuiteSparse_config 7.8.0 PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) - find_package ( SuiteSparse_config 7.5.0 REQUIRED ) + find_package ( SuiteSparse_config 7.8.0 REQUIRED ) endif ( ) endif ( ) @@ -90,7 +90,8 @@ if ( BUILD_SHARED_LIBS ) OUTPUT_NAME amd SOVERSION ${AMD_VERSION_MAJOR} PUBLIC_HEADER "Include/amd.h" - WINDOWS_EXPORT_ALL_SYMBOLS ON ) + WINDOWS_EXPORT_ALL_SYMBOLS ON + LINKER_LANGUAGE C ) if ( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25" ) set_target_properties ( AMD PROPERTIES EXPORT_NO_SYSTEM ON ) @@ -111,9 +112,10 @@ if ( BUILD_STATIC_LIBS ) C_STANDARD 11 C_STANDARD_REQUIRED ON OUTPUT_NAME amd - PUBLIC_HEADER "Include/amd.h" ) + PUBLIC_HEADER "Include/amd.h" + LINKER_LANGUAGE C ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( AMD_static PROPERTIES OUTPUT_NAME amd_static ) endif ( ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Config/amd.h.in b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Config/amd.h.in index 3192e1139..ffbfbf26e 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Config/amd.h.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Config/amd.h.in @@ -392,8 +392,8 @@ void amd_version (int version [3]) ; #define AMD__VERSION SUITESPARSE__VERCODE(@AMD_VERSION_MAJOR@,@AMD_VERSION_MINOR@,@AMD_VERSION_SUB@) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,5,0)) -#error "AMD @AMD_VERSION_MAJOR@.@AMD_VERSION_MINOR@.@AMD_VERSION_SUB@ requires SuiteSparse_config 7.5.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "AMD @AMD_VERSION_MAJOR@.@AMD_VERSION_MINOR@.@AMD_VERSION_SUB@ requires SuiteSparse_config 7.8.0 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/ChangeLog b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/ChangeLog index 3828f5ab2..4b80d7e8b 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/ChangeLog +++ b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/ChangeLog @@ -1,3 +1,11 @@ +June 20, 2024: version 3.3.3 + + * minor update for MATLAB on Windows + +Mar 22, 2024: version 3.3.2 + + * minor updates to build system + Jan 10, 2024: version 3.3.1 * minor updates to build system diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/amd_version.tex b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/amd_version.tex index 31528c9f3..26f2346a3 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/amd_version.tex +++ b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Doc/amd_version.tex @@ -1,2 +1,2 @@ % version of SuiteSparse/AMD -\date{VERSION 3.3.1, Jan 10, 2024} +\date{VERSION 3.3.3, June 20, 2024} diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Include/amd.h b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Include/amd.h index 188ee5a67..1417b3a25 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Include/amd.h +++ b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Include/amd.h @@ -382,18 +382,18 @@ void amd_version (int version [3]) ; * Versions 1.1 and earlier of AMD do not include a #define'd version number. */ -#define AMD_DATE "Jan 10, 2024" +#define AMD_DATE "June 20, 2024" #define AMD_MAIN_VERSION 3 #define AMD_SUB_VERSION 3 -#define AMD_SUBSUB_VERSION 1 +#define AMD_SUBSUB_VERSION 3 #define AMD_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub) #define AMD_VERSION AMD_VERSION_CODE(3,3) -#define AMD__VERSION SUITESPARSE__VERCODE(3,3,1) +#define AMD__VERSION SUITESPARSE__VERCODE(3,3,3) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,5,0)) -#error "AMD 3.3.1 requires SuiteSparse_config 7.5.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "AMD 3.3.3 requires SuiteSparse_config 7.8.0 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amd.f b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amd.f deleted file mode 100644 index 037807364..000000000 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amd.f +++ /dev/null @@ -1,1220 +0,0 @@ -C----------------------------------------------------------------------- -C AMD/Source/amd.f: Fortran version of AMD -C----------------------------------------------------------------------- - -C AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, -C and C Iain S. Duff. All Rights Reserved. -C SPDX-License-Identifier: BSD-3-clause - -C----------------------------------------------------------------------- - - SUBROUTINE AMD - $ (N, PE, IW, LEN, IWLEN, PFREE, NV, NEXT, - $ LAST, HEAD, ELEN, DEGREE, NCMPA, W) - - INTEGER N, IWLEN, PFREE, NCMPA, IW (IWLEN), PE (N), - $ DEGREE (N), NV (N), NEXT (N), LAST (N), HEAD (N), - $ ELEN (N), W (N), LEN (N) - -C Given a representation of the nonzero pattern of a symmetric matrix, -C A, (excluding the diagonal) perform an approximate minimum -C (UMFPACK/MA38-style) degree ordering to compute a pivot order -C such that the introduction of nonzeros (fill-in) in the Cholesky -C factors A = LL^T are kept low. At each step, the pivot -C selected is the one with the minimum UMFPACK/MA38-style -C upper-bound on the external degree. -C -C Aggresive absorption is used to tighten the bound on the degree. - -C ********************************************************************** -C ***** CAUTION: ARGUMENTS ARE NOT CHECKED FOR ERRORS ON INPUT. ****** -C ********************************************************************** - -C References: -C -C [1] Timothy A. Davis and Iain Duff, "An unsymmetric-pattern -C multifrontal method for sparse LU factorization", SIAM J. -C Matrix Analysis and Applications, vol. 18, no. 1, pp. -C 140-158. Discusses UMFPACK / MA38, which first introduced -C the approximate minimum degree used by this routine. -C -C [2] Patrick Amestoy, Timothy A. Davis, and Iain S. Duff, "An -C approximate degree ordering algorithm," SIAM J. Matrix -C Analysis and Applications, vol. 17, no. 4, pp. 886-905, -C 1996. Discusses AMD, AMDBAR, and MC47B. -C -C [3] Alan George and Joseph Liu, "The evolution of the minimum -C degree ordering algorithm," SIAM Review, vol. 31, no. 1, -C pp. 1-19, 1989. We list below the features mentioned in -C that paper that this code includes: -C -C mass elimination: -C Yes. MA27 relied on supervariable detection for mass -C elimination. -C indistinguishable nodes: -C Yes (we call these "supervariables"). This was also in -C the MA27 code - although we modified the method of -C detecting them (the previous hash was the true degree, -C which we no longer keep track of). A supervariable is -C a set of rows with identical nonzero pattern. All -C variables in a supervariable are eliminated together. -C Each supervariable has as its numerical name that of -C one of its variables (its principal variable). -C quotient graph representation: -C Yes. We use the term "element" for the cliques formed -C during elimination. This was also in the MA27 code. -C The algorithm can operate in place, but it will work -C more efficiently if given some "elbow room." -C element absorption: -C Yes. This was also in the MA27 code. -C external degree: -C Yes. The MA27 code was based on the true degree. -C incomplete degree update and multiple elimination: -C No. This was not in MA27, either. Our method of -C degree update within MC47B/BD is element-based, not -C variable-based. It is thus not well-suited for use -C with incomplete degree update or multiple elimination. - -C----------------------------------------------------------------------- -C Authors, and Copyright (C) 1995 by: -C Timothy A. Davis, Patrick Amestoy, Iain S. Duff, & John K. Reid. -C -C Acknowledgements: -C This work (and the UMFPACK package) was supported by the -C National Science Foundation (ASC-9111263 and DMS-9223088). -C The UMFPACK/MA38 approximate degree update algorithm, the -C unsymmetric analog which forms the basis of MC47B/BD, was -C developed while Tim Davis was supported by CERFACS (Toulouse, -C France) in a post-doctoral position. -C -C Date: September, 1995 -C----------------------------------------------------------------------- - -C----------------------------------------------------------------------- -C INPUT ARGUMENTS (unaltered): -C----------------------------------------------------------------------- - -C n: The matrix order. -C -C Restriction: 1 .le. n .lt. (iovflo/2)-2, where iovflo is -C the largest positive integer that your computer can represent. - -C iwlen: The length of iw (1..iwlen). On input, the matrix is -C stored in iw (1..pfree-1). However, iw (1..iwlen) should be -C slightly larger than what is required to hold the matrix, at -C least iwlen .ge. pfree + n is recommended. Otherwise, -C excessive compressions will take place. -C *** We do not recommend running this algorithm with *** -C *** iwlen .lt. pfree + n. *** -C *** Better performance will be obtained if *** -C *** iwlen .ge. pfree + n *** -C *** or better yet *** -C *** iwlen .gt. 1.2 * pfree *** -C *** (where pfree is its value on input). *** -C The algorithm will not run at all if iwlen .lt. pfree-1. -C -C Restriction: iwlen .ge. pfree-1 - -C----------------------------------------------------------------------- -C INPUT/OUPUT ARGUMENTS: -C----------------------------------------------------------------------- - -C pe: On input, pe (i) is the index in iw of the start of row i, or -C zero if row i has no off-diagonal non-zeros. -C -C During execution, it is used for both supervariables and -C elements: -C -C * Principal supervariable i: index into iw of the -C description of supervariable i. A supervariable -C represents one or more rows of the matrix -C with identical nonzero pattern. -C * Non-principal supervariable i: if i has been absorbed -C into another supervariable j, then pe (i) = -j. -C That is, j has the same pattern as i. -C Note that j might later be absorbed into another -C supervariable j2, in which case pe (i) is still -j, -C and pe (j) = -j2. -C * Unabsorbed element e: the index into iw of the description -C of element e, if e has not yet been absorbed by a -C subsequent element. Element e is created when -C the supervariable of the same name is selected as -C the pivot. -C * Absorbed element e: if element e is absorbed into element -C e2, then pe (e) = -e2. This occurs when the pattern of -C e (that is, Le) is found to be a subset of the pattern -C of e2 (that is, Le2). If element e is "null" (it has -C no nonzeros outside its pivot block), then pe (e) = 0. -C -C On output, pe holds the assembly tree/forest, which implicitly -C represents a pivot order with identical fill-in as the actual -C order (via a depth-first search of the tree). -C -C On output: -C If nv (i) .gt. 0, then i represents a node in the assembly tree, -C and the parent of i is -pe (i), or zero if i is a root. -C If nv (i) = 0, then (i,-pe (i)) represents an edge in a -C subtree, the root of which is a node in the assembly tree. - -C pfree: On input the tail end of the array, iw (pfree..iwlen), -C is empty, and the matrix is stored in iw (1..pfree-1). -C During execution, additional data is placed in iw, and pfree -C is modified so that iw (pfree..iwlen) is always the unused part -C of iw. On output, pfree is set equal to the size of iw that -C would have been needed for no compressions to occur. If -C ncmpa is zero, then pfree (on output) is less than or equal to -C iwlen, and the space iw (pfree+1 ... iwlen) was not used. -C Otherwise, pfree (on output) is greater than iwlen, and all the -C memory in iw was used. - -C----------------------------------------------------------------------- -C INPUT/MODIFIED (undefined on output): -C----------------------------------------------------------------------- - -C len: On input, len (i) holds the number of entries in row i of the -C matrix, excluding the diagonal. The contents of len (1..n) -C are undefined on output. - -C iw: On input, iw (1..pfree-1) holds the description of each row i -C in the matrix. The matrix must be symmetric, and both upper -C and lower triangular parts must be present. The diagonal must -C not be present. Row i is held as follows: -C -C len (i): the length of the row i data structure -C iw (pe (i) ... pe (i) + len (i) - 1): -C the list of column indices for nonzeros -C in row i (simple supervariables), excluding -C the diagonal. All supervariables start with -C one row/column each (supervariable i is just -C row i). -C if len (i) is zero on input, then pe (i) is ignored -C on input. -C -C Note that the rows need not be in any particular order, -C and there may be empty space between the rows. -C -C During execution, the supervariable i experiences fill-in. -C This is represented by placing in i a list of the elements -C that cause fill-in in supervariable i: -C -C len (i): the length of supervariable i -C iw (pe (i) ... pe (i) + elen (i) - 1): -C the list of elements that contain i. This list -C is kept short by removing absorbed elements. -C iw (pe (i) + elen (i) ... pe (i) + len (i) - 1): -C the list of supervariables in i. This list -C is kept short by removing nonprincipal -C variables, and any entry j that is also -C contained in at least one of the elements -C (j in Le) in the list for i (e in row i). -C -C When supervariable i is selected as pivot, we create an -C element e of the same name (e=i): -C -C len (e): the length of element e -C iw (pe (e) ... pe (e) + len (e) - 1): -C the list of supervariables in element e. -C -C An element represents the fill-in that occurs when supervariable -C i is selected as pivot (which represents the selection of row i -C and all non-principal variables whose principal variable is i). -C We use the term Le to denote the set of all supervariables -C in element e. Absorbed supervariables and elements are pruned -C from these lists when computationally convenient. -C -C CAUTION: THE INPUT MATRIX IS OVERWRITTEN DURING COMPUTATION. -C The contents of iw are undefined on output. - -C----------------------------------------------------------------------- -C OUTPUT (need not be set on input): -C----------------------------------------------------------------------- - -C nv: During execution, abs (nv (i)) is equal to the number of rows -C that are represented by the principal supervariable i. If i is -C a nonprincipal variable, then nv (i) = 0. Initially, -C nv (i) = 1 for all i. nv (i) .lt. 0 signifies that i is a -C principal variable in the pattern Lme of the current pivot -C element me. On output, nv (e) holds the true degree of element -C e at the time it was created (including the diagonal part). - -C ncmpa: The number of times iw was compressed. If this is -C excessive, then the execution took longer than what could have -C been. To reduce ncmpa, try increasing iwlen to be 10% or 20% -C larger than the value of pfree on input (or at least -C iwlen .ge. pfree + n). The fastest performance will be -C obtained when ncmpa is returned as zero. If iwlen is set to -C the value returned by pfree on *output*, then no compressions -C will occur. - -C elen: See the description of iw above. At the start of execution, -C elen (i) is set to zero. During execution, elen (i) is the -C number of elements in the list for supervariable i. When e -C becomes an element, elen (e) = -nel is set, where nel is the -C current step of factorization. elen (i) = 0 is done when i -C becomes nonprincipal. -C -C For variables, elen (i) .ge. 0 holds until just before the -C permutation vectors are computed. For elements, -C elen (e) .lt. 0 holds. -C -C On output elen (1..n) holds the inverse permutation (the same -C as the 'INVP' argument in Sparspak). That is, if k = elen (i), -C then row i is the kth pivot row. Row i of A appears as the -C (elen(i))-th row in the permuted matrix, PAP^T. - -C last: In a degree list, last (i) is the supervariable preceding i, -C or zero if i is the head of the list. In a hash bucket, -C last (i) is the hash key for i. last (head (hash)) is also -C used as the head of a hash bucket if head (hash) contains a -C degree list (see head, below). -C -C On output, last (1..n) holds the permutation (the same as the -C 'PERM' argument in Sparspak). That is, if i = last (k), then -C row i is the kth pivot row. Row last (k) of A is the k-th row -C in the permuted matrix, PAP^T. - -C----------------------------------------------------------------------- -C LOCAL (not input or output - used only during execution): -C----------------------------------------------------------------------- - -C degree: If i is a supervariable, then degree (i) holds the -C current approximation of the external degree of row i (an upper -C bound). The external degree is the number of nonzeros in row i, -C minus abs (nv (i)) (the diagonal part). The bound is equal to -C the external degree if elen (i) is less than or equal to two. -C -C We also use the term "external degree" for elements e to refer -C to |Le \ Lme|. If e is an element, then degree (e) holds |Le|, -C which is the degree of the off-diagonal part of the element e -C (not including the diagonal part). - -C head: head is used for degree lists. head (deg) is the first -C supervariable in a degree list (all supervariables i in a -C degree list deg have the same approximate degree, namely, -C deg = degree (i)). If the list deg is empty then -C head (deg) = 0. -C -C During supervariable detection head (hash) also serves as a -C pointer to a hash bucket. -C If head (hash) .gt. 0, there is a degree list of degree hash. -C The hash bucket head pointer is last (head (hash)). -C If head (hash) = 0, then the degree list and hash bucket are -C both empty. -C If head (hash) .lt. 0, then the degree list is empty, and -C -head (hash) is the head of the hash bucket. -C After supervariable detection is complete, all hash buckets -C are empty, and the (last (head (hash)) = 0) condition is -C restored for the non-empty degree lists. - -C next: next (i) is the supervariable following i in a link list, or -C zero if i is the last in the list. Used for two kinds of -C lists: degree lists and hash buckets (a supervariable can be -C in only one kind of list at a time). - -C w: The flag array w determines the status of elements and -C variables, and the external degree of elements. -C -C for elements: -C if w (e) = 0, then the element e is absorbed -C if w (e) .ge. wflg, then w (e) - wflg is the size of -C the set |Le \ Lme|, in terms of nonzeros (the -C sum of abs (nv (i)) for each principal variable i that -C is both in the pattern of element e and NOT in the -C pattern of the current pivot element, me). -C if wflg .gt. w (e) .gt. 0, then e is not absorbed and has -C not yet been seen in the scan of the element lists in -C the computation of |Le\Lme| in loop 150 below. -C -C for variables: -C during supervariable detection, if w (j) .ne. wflg then j is -C not in the pattern of variable i -C -C The w array is initialized by setting w (i) = 1 for all i, -C and by setting wflg = 2. It is reinitialized if wflg becomes -C too large (to ensure that wflg+n does not cause integer -C overflow). - -C----------------------------------------------------------------------- -C LOCAL INTEGERS: -C----------------------------------------------------------------------- - - INTEGER DEG, DEGME, DEXT, DMAX, E, ELENME, ELN, HASH, HMOD, I, - $ ILAST, INEXT, J, JLAST, JNEXT, K, KNT1, KNT2, KNT3, - $ LENJ, LN, MAXMEM, ME, MEM, MINDEG, NEL, NEWMEM, - $ NLEFT, NVI, NVJ, NVPIV, SLENME, WE, WFLG, WNVI, X - -C deg: the degree of a variable or element -C degme: size, |Lme|, of the current element, me (= degree (me)) -C dext: external degree, |Le \ Lme|, of some element e -C dmax: largest |Le| seen so far -C e: an element -C elenme: the length, elen (me), of element list of pivotal var. -C eln: the length, elen (...), of an element list -C hash: the computed value of the hash function -C hmod: the hash function is computed modulo hmod = max (1,n-1) -C i: a supervariable -C ilast: the entry in a link list preceding i -C inext: the entry in a link list following i -C j: a supervariable -C jlast: the entry in a link list preceding j -C jnext: the entry in a link list, or path, following j -C k: the pivot order of an element or variable -C knt1: loop counter used during element construction -C knt2: loop counter used during element construction -C knt3: loop counter used during compression -C lenj: len (j) -C ln: length of a supervariable list -C maxmem: amount of memory needed for no compressions -C me: current supervariable being eliminated, and the -C current element created by eliminating that -C supervariable -C mem: memory in use assuming no compressions have occurred -C mindeg: current minimum degree -C nel: number of pivots selected so far -C newmem: amount of new memory needed for current pivot element -C nleft: n - nel, the number of nonpivotal rows/columns remaining -C nvi: the number of variables in a supervariable i (= nv (i)) -C nvj: the number of variables in a supervariable j (= nv (j)) -C nvpiv: number of pivots in current element -C slenme: number of variables in variable list of pivotal variable -C we: w (e) -C wflg: used for flagging the w array. See description of iw. -C wnvi: wflg - nv (i) -C x: either a supervariable or an element - -C----------------------------------------------------------------------- -C LOCAL POINTERS: -C----------------------------------------------------------------------- - - INTEGER P, P1, P2, P3, PDST, PEND, PJ, PME, PME1, PME2, PN, PSRC - -C Any parameter (pe (...) or pfree) or local variable -C starting with "p" (for Pointer) is an index into iw, -C and all indices into iw use variables starting with -C "p." The only exception to this rule is the iwlen -C input argument. - -C p: pointer into lots of things -C p1: pe (i) for some variable i (start of element list) -C p2: pe (i) + elen (i) - 1 for some var. i (end of el. list) -C p3: index of first supervariable in clean list -C pdst: destination pointer, for compression -C pend: end of memory to compress -C pj: pointer into an element or variable -C pme: pointer into the current element (pme1...pme2) -C pme1: the current element, me, is stored in iw (pme1...pme2) -C pme2: the end of the current element -C pn: pointer into a "clean" variable, also used to compress -C psrc: source pointer, for compression - -C----------------------------------------------------------------------- -C FUNCTIONS CALLED: -C----------------------------------------------------------------------- - - INTRINSIC MAX, MIN, MOD - -C======================================================================= -C INITIALIZATIONS -C======================================================================= - - WFLG = 2 - MINDEG = 1 - NCMPA = 0 - NEL = 0 - HMOD = MAX (1, N-1) - DMAX = 0 - MEM = PFREE - 1 - MAXMEM = MEM - ME = 0 - - DO 10 I = 1, N - LAST (I) = 0 - HEAD (I) = 0 - NV (I) = 1 - W (I) = 1 - ELEN (I) = 0 - DEGREE (I) = LEN (I) -10 CONTINUE - -C ---------------------------------------------------------------- -C initialize degree lists and eliminate rows with no off-diag. nz. -C ---------------------------------------------------------------- - - DO 20 I = 1, N - - DEG = DEGREE (I) - - IF (DEG .GT. 0) THEN - -C ---------------------------------------------------------- -C place i in the degree list corresponding to its degree -C ---------------------------------------------------------- - - INEXT = HEAD (DEG) - IF (INEXT .NE. 0) LAST (INEXT) = I - NEXT (I) = INEXT - HEAD (DEG) = I - - ELSE - -C ---------------------------------------------------------- -C we have a variable that can be eliminated at once because -C there is no off-diagonal non-zero in its row. -C ---------------------------------------------------------- - - NEL = NEL + 1 - ELEN (I) = -NEL - PE (I) = 0 - W (I) = 0 - - ENDIF - -20 CONTINUE - -C======================================================================= -C WHILE (selecting pivots) DO -C======================================================================= - -30 CONTINUE - IF (NEL .LT. N) THEN - -C======================================================================= -C GET PIVOT OF MINIMUM DEGREE -C======================================================================= - -C ------------------------------------------------------------- -C find next supervariable for elimination -C ------------------------------------------------------------- - - DO 40 DEG = MINDEG, N - ME = HEAD (DEG) - IF (ME .GT. 0) GOTO 50 -40 CONTINUE -50 CONTINUE - MINDEG = DEG - -C ------------------------------------------------------------- -C remove chosen variable from link list -C ------------------------------------------------------------- - - INEXT = NEXT (ME) - IF (INEXT .NE. 0) LAST (INEXT) = 0 - HEAD (DEG) = INEXT - -C ------------------------------------------------------------- -C me represents the elimination of pivots nel+1 to nel+nv(me). -C place me itself as the first in this set. It will be moved -C to the nel+nv(me) position when the permutation vectors are -C computed. -C ------------------------------------------------------------- - - ELENME = ELEN (ME) - ELEN (ME) = - (NEL + 1) - NVPIV = NV (ME) - NEL = NEL + NVPIV - -C======================================================================= -C CONSTRUCT NEW ELEMENT -C======================================================================= - -C ------------------------------------------------------------- -C At this point, me is the pivotal supervariable. It will be -C converted into the current element. Scan list of the -C pivotal supervariable, me, setting tree pointers and -C constructing new list of supervariables for the new element, -C me. p is a pointer to the current position in the old list. -C ------------------------------------------------------------- - -C flag the variable "me" as being in Lme by negating nv (me) - NV (ME) = -NVPIV - DEGME = 0 - - IF (ELENME .EQ. 0) THEN - -C ---------------------------------------------------------- -C construct the new element in place -C ---------------------------------------------------------- - - PME1 = PE (ME) - PME2 = PME1 - 1 - - DO 60 P = PME1, PME1 + LEN (ME) - 1 - I = IW (P) - NVI = NV (I) - IF (NVI .GT. 0) THEN - -C ---------------------------------------------------- -C i is a principal variable not yet placed in Lme. -C store i in new list -C ---------------------------------------------------- - - DEGME = DEGME + NVI -C flag i as being in Lme by negating nv (i) - NV (I) = -NVI - PME2 = PME2 + 1 - IW (PME2) = I - -C ---------------------------------------------------- -C remove variable i from degree list. -C ---------------------------------------------------- - - ILAST = LAST (I) - INEXT = NEXT (I) - IF (INEXT .NE. 0) LAST (INEXT) = ILAST - IF (ILAST .NE. 0) THEN - NEXT (ILAST) = INEXT - ELSE -C i is at the head of the degree list - HEAD (DEGREE (I)) = INEXT - ENDIF - - ENDIF -60 CONTINUE -C this element takes no new memory in iw: - NEWMEM = 0 - - ELSE - -C ---------------------------------------------------------- -C construct the new element in empty space, iw (pfree ...) -C ---------------------------------------------------------- - - P = PE (ME) - PME1 = PFREE - SLENME = LEN (ME) - ELENME - - DO 120 KNT1 = 1, ELENME + 1 - - IF (KNT1 .GT. ELENME) THEN -C search the supervariables in me. - E = ME - PJ = P - LN = SLENME - ELSE -C search the elements in me. - E = IW (P) - P = P + 1 - PJ = PE (E) - LN = LEN (E) - ENDIF - -C ------------------------------------------------------- -C search for different supervariables and add them to the -C new list, compressing when necessary. this loop is -C executed once for each element in the list and once for -C all the supervariables in the list. -C ------------------------------------------------------- - - DO 110 KNT2 = 1, LN - I = IW (PJ) - PJ = PJ + 1 - NVI = NV (I) - IF (NVI .GT. 0) THEN - -C ------------------------------------------------- -C compress iw, if necessary -C ------------------------------------------------- - - IF (PFREE .GT. IWLEN) THEN -C prepare for compressing iw by adjusting -C pointers and lengths so that the lists being -C searched in the inner and outer loops contain -C only the remaining entries. - - PE (ME) = P - LEN (ME) = LEN (ME) - KNT1 - IF (LEN (ME) .EQ. 0) THEN -C nothing left of supervariable me - PE (ME) = 0 - ENDIF - PE (E) = PJ - LEN (E) = LN - KNT2 - IF (LEN (E) .EQ. 0) THEN -C nothing left of element e - PE (E) = 0 - ENDIF - - NCMPA = NCMPA + 1 -C store first item in pe -C set first entry to -item - DO 70 J = 1, N - PN = PE (J) - IF (PN .GT. 0) THEN - PE (J) = IW (PN) - IW (PN) = -J - ENDIF -70 CONTINUE - -C psrc/pdst point to source/destination - PDST = 1 - PSRC = 1 - PEND = PME1 - 1 - -C while loop: -80 CONTINUE - IF (PSRC .LE. PEND) THEN -C search for next negative entry - J = -IW (PSRC) - PSRC = PSRC + 1 - IF (J .GT. 0) THEN - IW (PDST) = PE (J) - PE (J) = PDST - PDST = PDST + 1 -C copy from source to destination - LENJ = LEN (J) - DO 90 KNT3 = 0, LENJ - 2 - IW (PDST + KNT3) = IW (PSRC + KNT3) -90 CONTINUE - PDST = PDST + LENJ - 1 - PSRC = PSRC + LENJ - 1 - ENDIF - GOTO 80 - ENDIF - -C move the new partially-constructed element - P1 = PDST - DO 100 PSRC = PME1, PFREE - 1 - IW (PDST) = IW (PSRC) - PDST = PDST + 1 -100 CONTINUE - PME1 = P1 - PFREE = PDST - PJ = PE (E) - P = PE (ME) - ENDIF - -C ------------------------------------------------- -C i is a principal variable not yet placed in Lme -C store i in new list -C ------------------------------------------------- - - DEGME = DEGME + NVI -C flag i as being in Lme by negating nv (i) - NV (I) = -NVI - IW (PFREE) = I - PFREE = PFREE + 1 - -C ------------------------------------------------- -C remove variable i from degree link list -C ------------------------------------------------- - - ILAST = LAST (I) - INEXT = NEXT (I) - IF (INEXT .NE. 0) LAST (INEXT) = ILAST - IF (ILAST .NE. 0) THEN - NEXT (ILAST) = INEXT - ELSE -C i is at the head of the degree list - HEAD (DEGREE (I)) = INEXT - ENDIF - - ENDIF -110 CONTINUE - - IF (E .NE. ME) THEN -C set tree pointer and flag to indicate element e is -C absorbed into new element me (the parent of e is me) - PE (E) = -ME - W (E) = 0 - ENDIF -120 CONTINUE - - PME2 = PFREE - 1 -C this element takes newmem new memory in iw (possibly zero) - NEWMEM = PFREE - PME1 - MEM = MEM + NEWMEM - MAXMEM = MAX (MAXMEM, MEM) - ENDIF - -C ------------------------------------------------------------- -C me has now been converted into an element in iw (pme1..pme2) -C ------------------------------------------------------------- - -C degme holds the external degree of new element - DEGREE (ME) = DEGME - PE (ME) = PME1 - LEN (ME) = PME2 - PME1 + 1 - -C ------------------------------------------------------------- -C make sure that wflg is not too large. With the current -C value of wflg, wflg+n must not cause integer overflow -C ------------------------------------------------------------- - - IF (WFLG + N .LE. WFLG) THEN - DO 130 X = 1, N - IF (W (X) .NE. 0) W (X) = 1 -130 CONTINUE - WFLG = 2 - ENDIF - -C======================================================================= -C COMPUTE (w (e) - wflg) = |Le\Lme| FOR ALL ELEMENTS -C======================================================================= - -C ------------------------------------------------------------- -C Scan 1: compute the external degrees of previous elements -C with respect to the current element. That is: -C (w (e) - wflg) = |Le \ Lme| -C for each element e that appears in any supervariable in Lme. -C The notation Le refers to the pattern (list of -C supervariables) of a previous element e, where e is not yet -C absorbed, stored in iw (pe (e) + 1 ... pe (e) + iw (pe (e))). -C The notation Lme refers to the pattern of the current element -C (stored in iw (pme1..pme2)). If (w (e) - wflg) becomes -C zero, then the element e will be absorbed in scan 2. -C ------------------------------------------------------------- - - DO 150 PME = PME1, PME2 - I = IW (PME) - ELN = ELEN (I) - IF (ELN .GT. 0) THEN -C note that nv (i) has been negated to denote i in Lme: - NVI = -NV (I) - WNVI = WFLG - NVI - DO 140 P = PE (I), PE (I) + ELN - 1 - E = IW (P) - WE = W (E) - IF (WE .GE. WFLG) THEN -C unabsorbed element e has been seen in this loop - WE = WE - NVI - ELSE IF (WE .NE. 0) THEN -C e is an unabsorbed element -C this is the first we have seen e in all of Scan 1 - WE = DEGREE (E) + WNVI - ENDIF - W (E) = WE -140 CONTINUE - ENDIF -150 CONTINUE - -C======================================================================= -C DEGREE UPDATE AND ELEMENT ABSORPTION -C======================================================================= - -C ------------------------------------------------------------- -C Scan 2: for each i in Lme, sum up the degree of Lme (which -C is degme), plus the sum of the external degrees of each Le -C for the elements e appearing within i, plus the -C supervariables in i. Place i in hash list. -C ------------------------------------------------------------- - - DO 180 PME = PME1, PME2 - I = IW (PME) - P1 = PE (I) - P2 = P1 + ELEN (I) - 1 - PN = P1 - HASH = 0 - DEG = 0 - -C ---------------------------------------------------------- -C scan the element list associated with supervariable i -C ---------------------------------------------------------- - - DO 160 P = P1, P2 - E = IW (P) -C dext = | Le \ Lme | - DEXT = W (E) - WFLG - IF (DEXT .GT. 0) THEN - DEG = DEG + DEXT - IW (PN) = E - PN = PN + 1 - HASH = HASH + E - ELSE IF (DEXT .EQ. 0) THEN -C aggressive absorption: e is not adjacent to me, but -C the |Le \ Lme| is 0, so absorb it into me - PE (E) = -ME - W (E) = 0 - ELSE -C element e has already been absorbed, due to -C regular absorption, in do loop 120 above. Ignore it. - CONTINUE - ENDIF -160 CONTINUE - -C count the number of elements in i (including me): - ELEN (I) = PN - P1 + 1 - -C ---------------------------------------------------------- -C scan the supervariables in the list associated with i -C ---------------------------------------------------------- - - P3 = PN - DO 170 P = P2 + 1, P1 + LEN (I) - 1 - J = IW (P) - NVJ = NV (J) - IF (NVJ .GT. 0) THEN -C j is unabsorbed, and not in Lme. -C add to degree and add to new list - DEG = DEG + NVJ - IW (PN) = J - PN = PN + 1 - HASH = HASH + J - ENDIF -170 CONTINUE - -C ---------------------------------------------------------- -C update the degree and check for mass elimination -C ---------------------------------------------------------- - - IF (DEG .EQ. 0) THEN - -C ------------------------------------------------------- -C mass elimination -C ------------------------------------------------------- - -C There is nothing left of this node except for an -C edge to the current pivot element. elen (i) is 1, -C and there are no variables adjacent to node i. -C Absorb i into the current pivot element, me. - - PE (I) = -ME - NVI = -NV (I) - DEGME = DEGME - NVI - NVPIV = NVPIV + NVI - NEL = NEL + NVI - NV (I) = 0 - ELEN (I) = 0 - - ELSE - -C ------------------------------------------------------- -C update the upper-bound degree of i -C ------------------------------------------------------- - -C the following degree does not yet include the size -C of the current element, which is added later: - DEGREE (I) = MIN (DEGREE (I), DEG) - -C ------------------------------------------------------- -C add me to the list for i -C ------------------------------------------------------- - -C move first supervariable to end of list - IW (PN) = IW (P3) -C move first element to end of element part of list - IW (P3) = IW (P1) -C add new element to front of list. - IW (P1) = ME -C store the new length of the list in len (i) - LEN (I) = PN - P1 + 1 - -C ------------------------------------------------------- -C place in hash bucket. Save hash key of i in last (i). -C ------------------------------------------------------- - - HASH = MOD (HASH, HMOD) + 1 - J = HEAD (HASH) - IF (J .LE. 0) THEN -C the degree list is empty, hash head is -j - NEXT (I) = -J - HEAD (HASH) = -I - ELSE -C degree list is not empty -C use last (head (hash)) as hash head - NEXT (I) = LAST (J) - LAST (J) = I - ENDIF - LAST (I) = HASH - ENDIF -180 CONTINUE - - DEGREE (ME) = DEGME - -C ------------------------------------------------------------- -C Clear the counter array, w (...), by incrementing wflg. -C ------------------------------------------------------------- - - DMAX = MAX (DMAX, DEGME) - WFLG = WFLG + DMAX - -C make sure that wflg+n does not cause integer overflow - IF (WFLG + N .LE. WFLG) THEN - DO 190 X = 1, N - IF (W (X) .NE. 0) W (X) = 1 -190 CONTINUE - WFLG = 2 - ENDIF -C at this point, w (1..n) .lt. wflg holds - -C======================================================================= -C SUPERVARIABLE DETECTION -C======================================================================= - - DO 250 PME = PME1, PME2 - I = IW (PME) - IF (NV (I) .LT. 0) THEN -C i is a principal variable in Lme - -C ------------------------------------------------------- -C examine all hash buckets with 2 or more variables. We -C do this by examing all unique hash keys for super- -C variables in the pattern Lme of the current element, me -C ------------------------------------------------------- - - HASH = LAST (I) -C let i = head of hash bucket, and empty the hash bucket - J = HEAD (HASH) - IF (J .EQ. 0) GOTO 250 - IF (J .LT. 0) THEN -C degree list is empty - I = -J - HEAD (HASH) = 0 - ELSE -C degree list is not empty, restore last () of head - I = LAST (J) - LAST (J) = 0 - ENDIF - IF (I .EQ. 0) GOTO 250 - -C while loop: -200 CONTINUE - IF (NEXT (I) .NE. 0) THEN - -C ---------------------------------------------------- -C this bucket has one or more variables following i. -C scan all of them to see if i can absorb any entries -C that follow i in hash bucket. Scatter i into w. -C ---------------------------------------------------- - - LN = LEN (I) - ELN = ELEN (I) -C do not flag the first element in the list (me) - DO 210 P = PE (I) + 1, PE (I) + LN - 1 - W (IW (P)) = WFLG -210 CONTINUE - -C ---------------------------------------------------- -C scan every other entry j following i in bucket -C ---------------------------------------------------- - - JLAST = I - J = NEXT (I) - -C while loop: -220 CONTINUE - IF (J .NE. 0) THEN - -C ------------------------------------------------- -C check if j and i have identical nonzero pattern -C ------------------------------------------------- - - IF (LEN (J) .NE. LN) THEN -C i and j do not have same size data structure - GOTO 240 - ENDIF - IF (ELEN (J) .NE. ELN) THEN -C i and j do not have same number of adjacent el - GOTO 240 - ENDIF -C do not flag the first element in the list (me) - DO 230 P = PE (J) + 1, PE (J) + LN - 1 - IF (W (IW (P)) .NE. WFLG) THEN -C an entry (iw(p)) is in j but not in i - GOTO 240 - ENDIF -230 CONTINUE - -C ------------------------------------------------- -C found it! j can be absorbed into i -C ------------------------------------------------- - - PE (J) = -I -C both nv (i) and nv (j) are negated since they -C are in Lme, and the absolute values of each -C are the number of variables in i and j: - NV (I) = NV (I) + NV (J) - NV (J) = 0 - ELEN (J) = 0 -C delete j from hash bucket - J = NEXT (J) - NEXT (JLAST) = J - GOTO 220 - -C ------------------------------------------------- -240 CONTINUE -C j cannot be absorbed into i -C ------------------------------------------------- - - JLAST = J - J = NEXT (J) - GOTO 220 - ENDIF - -C ---------------------------------------------------- -C no more variables can be absorbed into i -C go to next i in bucket and clear flag array -C ---------------------------------------------------- - - WFLG = WFLG + 1 - I = NEXT (I) - IF (I .NE. 0) GOTO 200 - ENDIF - ENDIF -250 CONTINUE - -C======================================================================= -C RESTORE DEGREE LISTS AND REMOVE NONPRINCIPAL SUPERVAR. FROM ELEMENT -C======================================================================= - - P = PME1 - NLEFT = N - NEL - DO 260 PME = PME1, PME2 - I = IW (PME) - NVI = -NV (I) - IF (NVI .GT. 0) THEN -C i is a principal variable in Lme -C restore nv (i) to signify that i is principal - NV (I) = NVI - -C ------------------------------------------------------- -C compute the external degree (add size of current elem) -C ------------------------------------------------------- - - DEG = MIN (DEGREE (I) + DEGME - NVI, NLEFT - NVI) - -C ------------------------------------------------------- -C place the supervariable at the head of the degree list -C ------------------------------------------------------- - - INEXT = HEAD (DEG) - IF (INEXT .NE. 0) LAST (INEXT) = I - NEXT (I) = INEXT - LAST (I) = 0 - HEAD (DEG) = I - -C ------------------------------------------------------- -C save the new degree, and find the minimum degree -C ------------------------------------------------------- - - MINDEG = MIN (MINDEG, DEG) - DEGREE (I) = DEG - -C ------------------------------------------------------- -C place the supervariable in the element pattern -C ------------------------------------------------------- - - IW (P) = I - P = P + 1 - ENDIF -260 CONTINUE - -C======================================================================= -C FINALIZE THE NEW ELEMENT -C======================================================================= - - NV (ME) = NVPIV + DEGME -C nv (me) is now the degree of pivot (including diagonal part) -C save the length of the list for the new element me - LEN (ME) = P - PME1 - IF (LEN (ME) .EQ. 0) THEN -C there is nothing left of the current pivot element - PE (ME) = 0 - W (ME) = 0 - ENDIF - IF (NEWMEM .NE. 0) THEN -C element was not constructed in place: deallocate part -C of it (final size is less than or equal to newmem, -C since newly nonprincipal variables have been removed). - PFREE = P - MEM = MEM - NEWMEM + LEN (ME) - ENDIF - -C======================================================================= -C END WHILE (selecting pivots) - GOTO 30 - ENDIF -C======================================================================= - -C======================================================================= -C COMPUTE THE PERMUTATION VECTORS -C======================================================================= - -C ---------------------------------------------------------------- -C The time taken by the following code is O(n). At this -C point, elen (e) = -k has been done for all elements e, -C and elen (i) = 0 has been done for all nonprincipal -C variables i. At this point, there are no principal -C supervariables left, and all elements are absorbed. -C ---------------------------------------------------------------- - -C ---------------------------------------------------------------- -C compute the ordering of unordered nonprincipal variables -C ---------------------------------------------------------------- - - DO 290 I = 1, N - IF (ELEN (I) .EQ. 0) THEN - -C ---------------------------------------------------------- -C i is an un-ordered row. Traverse the tree from i until -C reaching an element, e. The element, e, was the -C principal supervariable of i and all nodes in the path -C from i to when e was selected as pivot. -C ---------------------------------------------------------- - - J = -PE (I) -C while (j is a variable) do: -270 CONTINUE - IF (ELEN (J) .GE. 0) THEN - J = -PE (J) - GOTO 270 - ENDIF - E = J - -C ---------------------------------------------------------- -C get the current pivot ordering of e -C ---------------------------------------------------------- - - K = -ELEN (E) - -C ---------------------------------------------------------- -C traverse the path again from i to e, and compress the -C path (all nodes point to e). Path compression allows -C this code to compute in O(n) time. Order the unordered -C nodes in the path, and place the element e at the end. -C ---------------------------------------------------------- - - J = I -C while (j is a variable) do: -280 CONTINUE - IF (ELEN (J) .GE. 0) THEN - JNEXT = -PE (J) - PE (J) = -E - IF (ELEN (J) .EQ. 0) THEN -C j is an unordered row - ELEN (J) = K - K = K + 1 - ENDIF - J = JNEXT - GOTO 280 - ENDIF -C leave elen (e) negative, so we know it is an element - ELEN (E) = -K - ENDIF -290 CONTINUE - -C ---------------------------------------------------------------- -C reset the inverse permutation (elen (1..n)) to be positive, -C and compute the permutation (last (1..n)). -C ---------------------------------------------------------------- - - DO 300 I = 1, N - K = ABS (ELEN (I)) - LAST (K) = I - ELEN (I) = K -300 CONTINUE - -C======================================================================= -C RETURN THE MEMORY USAGE IN IW -C======================================================================= - -C If maxmem is less than or equal to iwlen, then no compressions -C occurred, and iw (maxmem+1 ... iwlen) was unused. Otherwise -C compressions did occur, and iwlen would have had to have been -C greater than or equal to maxmem for no compressions to occur. -C Return the value of maxmem in the pfree argument. - - PFREE = MAXMEM - - RETURN - END - diff --git a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amdbar.f b/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amdbar.f deleted file mode 100644 index 45b829743..000000000 --- a/deps/AMICI/ThirdParty/SuiteSparse/AMD/Source/amdbar.f +++ /dev/null @@ -1,1212 +0,0 @@ -C----------------------------------------------------------------------- -C AMD/Source/amdbar.f: Fortran version of AMD, no aggress absorption -C----------------------------------------------------------------------- - -C AMD, Copyright (c) 1996-2022, Timothy A. Davis, Patrick R. Amestoy, -C and C Iain S. Duff. All Rights Reserved. -C SPDX-License-Identifier: BSD-3-clause - -C----------------------------------------------------------------------- - - SUBROUTINE AMDBAR - $ (N, PE, IW, LEN, IWLEN, PFREE, NV, NEXT, - $ LAST, HEAD, ELEN, DEGREE, NCMPA, W) - - INTEGER N, IWLEN, PFREE, NCMPA, IW (IWLEN), PE (N), - $ DEGREE (N), NV (N), NEXT (N), LAST (N), HEAD (N), - $ ELEN (N), W (N), LEN (N) - -C Given a representation of the nonzero pattern of a symmetric matrix, -C A, (excluding the diagonal) perform an approximate minimum -C (UMFPACK/MA38-style) degree ordering to compute a pivot order -C such that the introduction of nonzeros (fill-in) in the Cholesky -C factors A = LL^T are kept low. At each step, the pivot -C selected is the one with the minimum UMFPACK/MA38-style -C upper-bound on the external degree. -C -C This routine does not do aggresive absorption (as done by AMD). - -C ********************************************************************** -C ***** CAUTION: ARGUMENTS ARE NOT CHECKED FOR ERRORS ON INPUT. ****** -C ********************************************************************** - -C References: -C -C [1] Timothy A. Davis and Iain Duff, "An unsymmetric-pattern -C multifrontal method for sparse LU factorization", SIAM J. -C Matrix Analysis and Applications, vol. 18, no. 1, pp. -C 140-158. Discusses UMFPACK / MA38, which first introduced -C the approximate minimum degree used by this routine. -C -C [2] Patrick Amestoy, Timothy A. Davis, and Iain S. Duff, "An -C approximate degree ordering algorithm," SIAM J. Matrix -C Analysis and Applications, vol. 17, no. 4, pp. 886-905, -C 1996. Discusses AMD, AMDBAR, and MC47B. -C -C [3] Alan George and Joseph Liu, "The evolution of the minimum -C degree ordering algorithm," SIAM Review, vol. 31, no. 1, -C pp. 1-19, 1989. We list below the features mentioned in -C that paper that this code includes: -C -C mass elimination: -C Yes. MA27 relied on supervariable detection for mass -C elimination. -C indistinguishable nodes: -C Yes (we call these "supervariables"). This was also in -C the MA27 code - although we modified the method of -C detecting them (the previous hash was the true degree, -C which we no longer keep track of). A supervariable is -C a set of rows with identical nonzero pattern. All -C variables in a supervariable are eliminated together. -C Each supervariable has as its numerical name that of -C one of its variables (its principal variable). -C quotient graph representation: -C Yes. We use the term "element" for the cliques formed -C during elimination. This was also in the MA27 code. -C The algorithm can operate in place, but it will work -C more efficiently if given some "elbow room." -C element absorption: -C Yes. This was also in the MA27 code. -C external degree: -C Yes. The MA27 code was based on the true degree. -C incomplete degree update and multiple elimination: -C No. This was not in MA27, either. Our method of -C degree update within MC47B/BD is element-based, not -C variable-based. It is thus not well-suited for use -C with incomplete degree update or multiple elimination. - -C----------------------------------------------------------------------- -C Authors, and Copyright (C) 1995 by: -C Timothy A. Davis, Patrick Amestoy, Iain S. Duff, & John K. Reid. -C -C Acknowledgements: -C This work (and the UMFPACK package) was supported by the -C National Science Foundation (ASC-9111263 and DMS-9223088). -C The UMFPACK/MA38 approximate degree update algorithm, the -C unsymmetric analog which forms the basis of MC47B/BD, was -C developed while Tim Davis was supported by CERFACS (Toulouse, -C France) in a post-doctoral position. -C -C Date: September, 1995 -C----------------------------------------------------------------------- - -C----------------------------------------------------------------------- -C INPUT ARGUMENTS (unaltered): -C----------------------------------------------------------------------- - -C n: The matrix order. -C -C Restriction: 1 .le. n .lt. (iovflo/2)-2, where iovflo is -C the largest positive integer that your computer can represent. - -C iwlen: The length of iw (1..iwlen). On input, the matrix is -C stored in iw (1..pfree-1). However, iw (1..iwlen) should be -C slightly larger than what is required to hold the matrix, at -C least iwlen .ge. pfree + n is recommended. Otherwise, -C excessive compressions will take place. -C *** We do not recommend running this algorithm with *** -C *** iwlen .lt. pfree + n. *** -C *** Better performance will be obtained if *** -C *** iwlen .ge. pfree + n *** -C *** or better yet *** -C *** iwlen .gt. 1.2 * pfree *** -C *** (where pfree is its value on input). *** -C The algorithm will not run at all if iwlen .lt. pfree-1. -C -C Restriction: iwlen .ge. pfree-1 - -C----------------------------------------------------------------------- -C INPUT/OUPUT ARGUMENTS: -C----------------------------------------------------------------------- - -C pe: On input, pe (i) is the index in iw of the start of row i, or -C zero if row i has no off-diagonal non-zeros. -C -C During execution, it is used for both supervariables and -C elements: -C -C * Principal supervariable i: index into iw of the -C description of supervariable i. A supervariable -C represents one or more rows of the matrix -C with identical nonzero pattern. -C * Non-principal supervariable i: if i has been absorbed -C into another supervariable j, then pe (i) = -j. -C That is, j has the same pattern as i. -C Note that j might later be absorbed into another -C supervariable j2, in which case pe (i) is still -j, -C and pe (j) = -j2. -C * Unabsorbed element e: the index into iw of the description -C of element e, if e has not yet been absorbed by a -C subsequent element. Element e is created when -C the supervariable of the same name is selected as -C the pivot. -C * Absorbed element e: if element e is absorbed into element -C e2, then pe (e) = -e2. This occurs when the pattern of -C e (that is, Le) is found to be a subset of the pattern -C of e2 (that is, Le2). If element e is "null" (it has -C no nonzeros outside its pivot block), then pe (e) = 0. -C -C On output, pe holds the assembly tree/forest, which implicitly -C represents a pivot order with identical fill-in as the actual -C order (via a depth-first search of the tree). -C -C On output: -C If nv (i) .gt. 0, then i represents a node in the assembly tree, -C and the parent of i is -pe (i), or zero if i is a root. -C If nv (i) = 0, then (i,-pe (i)) represents an edge in a -C subtree, the root of which is a node in the assembly tree. - -C pfree: On input the tail end of the array, iw (pfree..iwlen), -C is empty, and the matrix is stored in iw (1..pfree-1). -C During execution, additional data is placed in iw, and pfree -C is modified so that iw (pfree..iwlen) is always the unused part -C of iw. On output, pfree is set equal to the size of iw that -C would have been needed for no compressions to occur. If -C ncmpa is zero, then pfree (on output) is less than or equal to -C iwlen, and the space iw (pfree+1 ... iwlen) was not used. -C Otherwise, pfree (on output) is greater than iwlen, and all the -C memory in iw was used. - -C----------------------------------------------------------------------- -C INPUT/MODIFIED (undefined on output): -C----------------------------------------------------------------------- - -C len: On input, len (i) holds the number of entries in row i of the -C matrix, excluding the diagonal. The contents of len (1..n) -C are undefined on output. - -C iw: On input, iw (1..pfree-1) holds the description of each row i -C in the matrix. The matrix must be symmetric, and both upper -C and lower triangular parts must be present. The diagonal must -C not be present. Row i is held as follows: -C -C len (i): the length of the row i data structure -C iw (pe (i) ... pe (i) + len (i) - 1): -C the list of column indices for nonzeros -C in row i (simple supervariables), excluding -C the diagonal. All supervariables start with -C one row/column each (supervariable i is just -C row i). -C if len (i) is zero on input, then pe (i) is ignored -C on input. -C -C Note that the rows need not be in any particular order, -C and there may be empty space between the rows. -C -C During execution, the supervariable i experiences fill-in. -C This is represented by placing in i a list of the elements -C that cause fill-in in supervariable i: -C -C len (i): the length of supervariable i -C iw (pe (i) ... pe (i) + elen (i) - 1): -C the list of elements that contain i. This list -C is kept short by removing absorbed elements. -C iw (pe (i) + elen (i) ... pe (i) + len (i) - 1): -C the list of supervariables in i. This list -C is kept short by removing nonprincipal -C variables, and any entry j that is also -C contained in at least one of the elements -C (j in Le) in the list for i (e in row i). -C -C When supervariable i is selected as pivot, we create an -C element e of the same name (e=i): -C -C len (e): the length of element e -C iw (pe (e) ... pe (e) + len (e) - 1): -C the list of supervariables in element e. -C -C An element represents the fill-in that occurs when supervariable -C i is selected as pivot (which represents the selection of row i -C and all non-principal variables whose principal variable is i). -C We use the term Le to denote the set of all supervariables -C in element e. Absorbed supervariables and elements are pruned -C from these lists when computationally convenient. -C -C CAUTION: THE INPUT MATRIX IS OVERWRITTEN DURING COMPUTATION. -C The contents of iw are undefined on output. - -C----------------------------------------------------------------------- -C OUTPUT (need not be set on input): -C----------------------------------------------------------------------- - -C nv: During execution, abs (nv (i)) is equal to the number of rows -C that are represented by the principal supervariable i. If i is -C a nonprincipal variable, then nv (i) = 0. Initially, -C nv (i) = 1 for all i. nv (i) .lt. 0 signifies that i is a -C principal variable in the pattern Lme of the current pivot -C element me. On output, nv (e) holds the true degree of element -C e at the time it was created (including the diagonal part). - -C ncmpa: The number of times iw was compressed. If this is -C excessive, then the execution took longer than what could have -C been. To reduce ncmpa, try increasing iwlen to be 10% or 20% -C larger than the value of pfree on input (or at least -C iwlen .ge. pfree + n). The fastest performance will be -C obtained when ncmpa is returned as zero. If iwlen is set to -C the value returned by pfree on *output*, then no compressions -C will occur. - -C elen: See the description of iw above. At the start of execution, -C elen (i) is set to zero. During execution, elen (i) is the -C number of elements in the list for supervariable i. When e -C becomes an element, elen (e) = -nel is set, where nel is the -C current step of factorization. elen (i) = 0 is done when i -C becomes nonprincipal. -C -C For variables, elen (i) .ge. 0 holds until just before the -C permutation vectors are computed. For elements, -C elen (e) .lt. 0 holds. -C -C On output elen (1..n) holds the inverse permutation (the same -C as the 'INVP' argument in Sparspak). That is, if k = elen (i), -C then row i is the kth pivot row. Row i of A appears as the -C (elen(i))-th row in the permuted matrix, PAP^T. - -C last: In a degree list, last (i) is the supervariable preceding i, -C or zero if i is the head of the list. In a hash bucket, -C last (i) is the hash key for i. last (head (hash)) is also -C used as the head of a hash bucket if head (hash) contains a -C degree list (see head, below). -C -C On output, last (1..n) holds the permutation (the same as the -C 'PERM' argument in Sparspak). That is, if i = last (k), then -C row i is the kth pivot row. Row last (k) of A is the k-th row -C in the permuted matrix, PAP^T. - -C----------------------------------------------------------------------- -C LOCAL (not input or output - used only during execution): -C----------------------------------------------------------------------- - -C degree: If i is a supervariable, then degree (i) holds the -C current approximation of the external degree of row i (an upper -C bound). The external degree is the number of nonzeros in row i, -C minus abs (nv (i)) (the diagonal part). The bound is equal to -C the external degree if elen (i) is less than or equal to two. -C -C We also use the term "external degree" for elements e to refer -C to |Le \ Lme|. If e is an element, then degree (e) holds |Le|, -C which is the degree of the off-diagonal part of the element e -C (not including the diagonal part). - -C head: head is used for degree lists. head (deg) is the first -C supervariable in a degree list (all supervariables i in a -C degree list deg have the same approximate degree, namely, -C deg = degree (i)). If the list deg is empty then -C head (deg) = 0. -C -C During supervariable detection head (hash) also serves as a -C pointer to a hash bucket. -C If head (hash) .gt. 0, there is a degree list of degree hash. -C The hash bucket head pointer is last (head (hash)). -C If head (hash) = 0, then the degree list and hash bucket are -C both empty. -C If head (hash) .lt. 0, then the degree list is empty, and -C -head (hash) is the head of the hash bucket. -C After supervariable detection is complete, all hash buckets -C are empty, and the (last (head (hash)) = 0) condition is -C restored for the non-empty degree lists. - -C next: next (i) is the supervariable following i in a link list, or -C zero if i is the last in the list. Used for two kinds of -C lists: degree lists and hash buckets (a supervariable can be -C in only one kind of list at a time). - -C w: The flag array w determines the status of elements and -C variables, and the external degree of elements. -C -C for elements: -C if w (e) = 0, then the element e is absorbed -C if w (e) .ge. wflg, then w (e) - wflg is the size of -C the set |Le \ Lme|, in terms of nonzeros (the -C sum of abs (nv (i)) for each principal variable i that -C is both in the pattern of element e and NOT in the -C pattern of the current pivot element, me). -C if wflg .gt. w (e) .gt. 0, then e is not absorbed and has -C not yet been seen in the scan of the element lists in -C the computation of |Le\Lme| in loop 150 below. -C -C for variables: -C during supervariable detection, if w (j) .ne. wflg then j is -C not in the pattern of variable i -C -C The w array is initialized by setting w (i) = 1 for all i, -C and by setting wflg = 2. It is reinitialized if wflg becomes -C too large (to ensure that wflg+n does not cause integer -C overflow). - -C----------------------------------------------------------------------- -C LOCAL INTEGERS: -C----------------------------------------------------------------------- - - INTEGER DEG, DEGME, DMAX, E, ELENME, ELN, HASH, HMOD, I, - $ ILAST, INEXT, J, JLAST, JNEXT, K, KNT1, KNT2, KNT3, - $ LENJ, LN, MAXMEM, ME, MEM, MINDEG, NEL, NEWMEM, - $ NLEFT, NVI, NVJ, NVPIV, SLENME, WE, WFLG, WNVI, X - -C deg: the degree of a variable or element -C degme: size, |Lme|, of the current element, me (= degree (me)) -C dext: external degree, |Le \ Lme|, of some element e -C dmax: largest |Le| seen so far -C e: an element -C elenme: the length, elen (me), of element list of pivotal var. -C eln: the length, elen (...), of an element list -C hash: the computed value of the hash function -C hmod: the hash function is computed modulo hmod = max (1,n-1) -C i: a supervariable -C ilast: the entry in a link list preceding i -C inext: the entry in a link list following i -C j: a supervariable -C jlast: the entry in a link list preceding j -C jnext: the entry in a link list, or path, following j -C k: the pivot order of an element or variable -C knt1: loop counter used during element construction -C knt2: loop counter used during element construction -C knt3: loop counter used during compression -C lenj: len (j) -C ln: length of a supervariable list -C maxmem: amount of memory needed for no compressions -C me: current supervariable being eliminated, and the -C current element created by eliminating that -C supervariable -C mem: memory in use assuming no compressions have occurred -C mindeg: current minimum degree -C nel: number of pivots selected so far -C newmem: amount of new memory needed for current pivot element -C nleft: n - nel, the number of nonpivotal rows/columns remaining -C nvi: the number of variables in a supervariable i (= nv (i)) -C nvj: the number of variables in a supervariable j (= nv (j)) -C nvpiv: number of pivots in current element -C slenme: number of variables in variable list of pivotal variable -C we: w (e) -C wflg: used for flagging the w array. See description of iw. -C wnvi: wflg - nv (i) -C x: either a supervariable or an element - -C----------------------------------------------------------------------- -C LOCAL POINTERS: -C----------------------------------------------------------------------- - - INTEGER P, P1, P2, P3, PDST, PEND, PJ, PME, PME1, PME2, PN, PSRC - -C Any parameter (pe (...) or pfree) or local variable -C starting with "p" (for Pointer) is an index into iw, -C and all indices into iw use variables starting with -C "p." The only exception to this rule is the iwlen -C input argument. - -C p: pointer into lots of things -C p1: pe (i) for some variable i (start of element list) -C p2: pe (i) + elen (i) - 1 for some var. i (end of el. list) -C p3: index of first supervariable in clean list -C pdst: destination pointer, for compression -C pend: end of memory to compress -C pj: pointer into an element or variable -C pme: pointer into the current element (pme1...pme2) -C pme1: the current element, me, is stored in iw (pme1...pme2) -C pme2: the end of the current element -C pn: pointer into a "clean" variable, also used to compress -C psrc: source pointer, for compression - -C----------------------------------------------------------------------- -C FUNCTIONS CALLED: -C----------------------------------------------------------------------- - - INTRINSIC MAX, MIN, MOD - -C======================================================================= -C INITIALIZATIONS -C======================================================================= - - WFLG = 2 - MINDEG = 1 - NCMPA = 0 - NEL = 0 - HMOD = MAX (1, N-1) - DMAX = 0 - MEM = PFREE - 1 - MAXMEM = MEM - ME = 0 - - DO 10 I = 1, N - LAST (I) = 0 - HEAD (I) = 0 - NV (I) = 1 - W (I) = 1 - ELEN (I) = 0 - DEGREE (I) = LEN (I) -10 CONTINUE - -C ---------------------------------------------------------------- -C initialize degree lists and eliminate rows with no off-diag. nz. -C ---------------------------------------------------------------- - - DO 20 I = 1, N - - DEG = DEGREE (I) - - IF (DEG .GT. 0) THEN - -C ---------------------------------------------------------- -C place i in the degree list corresponding to its degree -C ---------------------------------------------------------- - - INEXT = HEAD (DEG) - IF (INEXT .NE. 0) LAST (INEXT) = I - NEXT (I) = INEXT - HEAD (DEG) = I - - ELSE - -C ---------------------------------------------------------- -C we have a variable that can be eliminated at once because -C there is no off-diagonal non-zero in its row. -C ---------------------------------------------------------- - - NEL = NEL + 1 - ELEN (I) = -NEL - PE (I) = 0 - W (I) = 0 - - ENDIF - -20 CONTINUE - -C======================================================================= -C WHILE (selecting pivots) DO -C======================================================================= - -30 CONTINUE - IF (NEL .LT. N) THEN - -C======================================================================= -C GET PIVOT OF MINIMUM DEGREE -C======================================================================= - -C ------------------------------------------------------------- -C find next supervariable for elimination -C ------------------------------------------------------------- - - DO 40 DEG = MINDEG, N - ME = HEAD (DEG) - IF (ME .GT. 0) GOTO 50 -40 CONTINUE -50 CONTINUE - MINDEG = DEG - -C ------------------------------------------------------------- -C remove chosen variable from link list -C ------------------------------------------------------------- - - INEXT = NEXT (ME) - IF (INEXT .NE. 0) LAST (INEXT) = 0 - HEAD (DEG) = INEXT - -C ------------------------------------------------------------- -C me represents the elimination of pivots nel+1 to nel+nv(me). -C place me itself as the first in this set. It will be moved -C to the nel+nv(me) position when the permutation vectors are -C computed. -C ------------------------------------------------------------- - - ELENME = ELEN (ME) - ELEN (ME) = - (NEL + 1) - NVPIV = NV (ME) - NEL = NEL + NVPIV - -C======================================================================= -C CONSTRUCT NEW ELEMENT -C======================================================================= - -C ------------------------------------------------------------- -C At this point, me is the pivotal supervariable. It will be -C converted into the current element. Scan list of the -C pivotal supervariable, me, setting tree pointers and -C constructing new list of supervariables for the new element, -C me. p is a pointer to the current position in the old list. -C ------------------------------------------------------------- - -C flag the variable "me" as being in Lme by negating nv (me) - NV (ME) = -NVPIV - DEGME = 0 - - IF (ELENME .EQ. 0) THEN - -C ---------------------------------------------------------- -C construct the new element in place -C ---------------------------------------------------------- - - PME1 = PE (ME) - PME2 = PME1 - 1 - - DO 60 P = PME1, PME1 + LEN (ME) - 1 - I = IW (P) - NVI = NV (I) - IF (NVI .GT. 0) THEN - -C ---------------------------------------------------- -C i is a principal variable not yet placed in Lme. -C store i in new list -C ---------------------------------------------------- - - DEGME = DEGME + NVI -C flag i as being in Lme by negating nv (i) - NV (I) = -NVI - PME2 = PME2 + 1 - IW (PME2) = I - -C ---------------------------------------------------- -C remove variable i from degree list. -C ---------------------------------------------------- - - ILAST = LAST (I) - INEXT = NEXT (I) - IF (INEXT .NE. 0) LAST (INEXT) = ILAST - IF (ILAST .NE. 0) THEN - NEXT (ILAST) = INEXT - ELSE -C i is at the head of the degree list - HEAD (DEGREE (I)) = INEXT - ENDIF - - ENDIF -60 CONTINUE -C this element takes no new memory in iw: - NEWMEM = 0 - - ELSE - -C ---------------------------------------------------------- -C construct the new element in empty space, iw (pfree ...) -C ---------------------------------------------------------- - - P = PE (ME) - PME1 = PFREE - SLENME = LEN (ME) - ELENME - - DO 120 KNT1 = 1, ELENME + 1 - - IF (KNT1 .GT. ELENME) THEN -C search the supervariables in me. - E = ME - PJ = P - LN = SLENME - ELSE -C search the elements in me. - E = IW (P) - P = P + 1 - PJ = PE (E) - LN = LEN (E) - ENDIF - -C ------------------------------------------------------- -C search for different supervariables and add them to the -C new list, compressing when necessary. this loop is -C executed once for each element in the list and once for -C all the supervariables in the list. -C ------------------------------------------------------- - - DO 110 KNT2 = 1, LN - I = IW (PJ) - PJ = PJ + 1 - NVI = NV (I) - IF (NVI .GT. 0) THEN - -C ------------------------------------------------- -C compress iw, if necessary -C ------------------------------------------------- - - IF (PFREE .GT. IWLEN) THEN -C prepare for compressing iw by adjusting -C pointers and lengths so that the lists being -C searched in the inner and outer loops contain -C only the remaining entries. - - PE (ME) = P - LEN (ME) = LEN (ME) - KNT1 - IF (LEN (ME) .EQ. 0) THEN -C nothing left of supervariable me - PE (ME) = 0 - ENDIF - PE (E) = PJ - LEN (E) = LN - KNT2 - IF (LEN (E) .EQ. 0) THEN -C nothing left of element e - PE (E) = 0 - ENDIF - - NCMPA = NCMPA + 1 -C store first item in pe -C set first entry to -item - DO 70 J = 1, N - PN = PE (J) - IF (PN .GT. 0) THEN - PE (J) = IW (PN) - IW (PN) = -J - ENDIF -70 CONTINUE - -C psrc/pdst point to source/destination - PDST = 1 - PSRC = 1 - PEND = PME1 - 1 - -C while loop: -80 CONTINUE - IF (PSRC .LE. PEND) THEN -C search for next negative entry - J = -IW (PSRC) - PSRC = PSRC + 1 - IF (J .GT. 0) THEN - IW (PDST) = PE (J) - PE (J) = PDST - PDST = PDST + 1 -C copy from source to destination - LENJ = LEN (J) - DO 90 KNT3 = 0, LENJ - 2 - IW (PDST + KNT3) = IW (PSRC + KNT3) -90 CONTINUE - PDST = PDST + LENJ - 1 - PSRC = PSRC + LENJ - 1 - ENDIF - GOTO 80 - ENDIF - -C move the new partially-constructed element - P1 = PDST - DO 100 PSRC = PME1, PFREE - 1 - IW (PDST) = IW (PSRC) - PDST = PDST + 1 -100 CONTINUE - PME1 = P1 - PFREE = PDST - PJ = PE (E) - P = PE (ME) - ENDIF - -C ------------------------------------------------- -C i is a principal variable not yet placed in Lme -C store i in new list -C ------------------------------------------------- - - DEGME = DEGME + NVI -C flag i as being in Lme by negating nv (i) - NV (I) = -NVI - IW (PFREE) = I - PFREE = PFREE + 1 - -C ------------------------------------------------- -C remove variable i from degree link list -C ------------------------------------------------- - - ILAST = LAST (I) - INEXT = NEXT (I) - IF (INEXT .NE. 0) LAST (INEXT) = ILAST - IF (ILAST .NE. 0) THEN - NEXT (ILAST) = INEXT - ELSE -C i is at the head of the degree list - HEAD (DEGREE (I)) = INEXT - ENDIF - - ENDIF -110 CONTINUE - - IF (E .NE. ME) THEN -C set tree pointer and flag to indicate element e is -C absorbed into new element me (the parent of e is me) - PE (E) = -ME - W (E) = 0 - ENDIF -120 CONTINUE - - PME2 = PFREE - 1 -C this element takes newmem new memory in iw (possibly zero) - NEWMEM = PFREE - PME1 - MEM = MEM + NEWMEM - MAXMEM = MAX (MAXMEM, MEM) - ENDIF - -C ------------------------------------------------------------- -C me has now been converted into an element in iw (pme1..pme2) -C ------------------------------------------------------------- - -C degme holds the external degree of new element - DEGREE (ME) = DEGME - PE (ME) = PME1 - LEN (ME) = PME2 - PME1 + 1 - -C ------------------------------------------------------------- -C make sure that wflg is not too large. With the current -C value of wflg, wflg+n must not cause integer overflow -C ------------------------------------------------------------- - - IF (WFLG + N .LE. WFLG) THEN - DO 130 X = 1, N - IF (W (X) .NE. 0) W (X) = 1 -130 CONTINUE - WFLG = 2 - ENDIF - -C======================================================================= -C COMPUTE (w (e) - wflg) = |Le\Lme| FOR ALL ELEMENTS -C======================================================================= - -C ------------------------------------------------------------- -C Scan 1: compute the external degrees of previous elements -C with respect to the current element. That is: -C (w (e) - wflg) = |Le \ Lme| -C for each element e that appears in any supervariable in Lme. -C The notation Le refers to the pattern (list of -C supervariables) of a previous element e, where e is not yet -C absorbed, stored in iw (pe (e) + 1 ... pe (e) + iw (pe (e))). -C The notation Lme refers to the pattern of the current element -C (stored in iw (pme1..pme2)). If (w (e) - wflg) becomes -C zero, then the element e will be absorbed in scan 2. -C ------------------------------------------------------------- - - DO 150 PME = PME1, PME2 - I = IW (PME) - ELN = ELEN (I) - IF (ELN .GT. 0) THEN -C note that nv (i) has been negated to denote i in Lme: - NVI = -NV (I) - WNVI = WFLG - NVI - DO 140 P = PE (I), PE (I) + ELN - 1 - E = IW (P) - WE = W (E) - IF (WE .GE. WFLG) THEN -C unabsorbed element e has been seen in this loop - WE = WE - NVI - ELSE IF (WE .NE. 0) THEN -C e is an unabsorbed element -C this is the first we have seen e in all of Scan 1 - WE = DEGREE (E) + WNVI - ENDIF - W (E) = WE -140 CONTINUE - ENDIF -150 CONTINUE - -C======================================================================= -C DEGREE UPDATE AND ELEMENT ABSORPTION -C======================================================================= - -C ------------------------------------------------------------- -C Scan 2: for each i in Lme, sum up the degree of Lme (which -C is degme), plus the sum of the external degrees of each Le -C for the elements e appearing within i, plus the -C supervariables in i. Place i in hash list. -C ------------------------------------------------------------- - - DO 180 PME = PME1, PME2 - I = IW (PME) - P1 = PE (I) - P2 = P1 + ELEN (I) - 1 - PN = P1 - HASH = 0 - DEG = 0 - -C ---------------------------------------------------------- -C scan the element list associated with supervariable i -C ---------------------------------------------------------- - -C UMFPACK/MA38-style approximate degree: - DO 160 P = P1, P2 - E = IW (P) - WE = W (E) - IF (WE .NE. 0) THEN -C e is an unabsorbed element - DEG = DEG + WE - WFLG - IW (PN) = E - PN = PN + 1 - HASH = HASH + E - ENDIF -160 CONTINUE - -C count the number of elements in i (including me): - ELEN (I) = PN - P1 + 1 - -C ---------------------------------------------------------- -C scan the supervariables in the list associated with i -C ---------------------------------------------------------- - - P3 = PN - DO 170 P = P2 + 1, P1 + LEN (I) - 1 - J = IW (P) - NVJ = NV (J) - IF (NVJ .GT. 0) THEN -C j is unabsorbed, and not in Lme. -C add to degree and add to new list - DEG = DEG + NVJ - IW (PN) = J - PN = PN + 1 - HASH = HASH + J - ENDIF -170 CONTINUE - -C ---------------------------------------------------------- -C update the degree and check for mass elimination -C ---------------------------------------------------------- - - IF (ELEN (I) .EQ. 1 .AND. P3 .EQ. PN) THEN - -C ------------------------------------------------------- -C mass elimination -C ------------------------------------------------------- - -C There is nothing left of this node except for an -C edge to the current pivot element. elen (i) is 1, -C and there are no variables adjacent to node i. -C Absorb i into the current pivot element, me. - - PE (I) = -ME - NVI = -NV (I) - DEGME = DEGME - NVI - NVPIV = NVPIV + NVI - NEL = NEL + NVI - NV (I) = 0 - ELEN (I) = 0 - - ELSE - -C ------------------------------------------------------- -C update the upper-bound degree of i -C ------------------------------------------------------- - -C the following degree does not yet include the size -C of the current element, which is added later: - DEGREE (I) = MIN (DEGREE (I), DEG) - -C ------------------------------------------------------- -C add me to the list for i -C ------------------------------------------------------- - -C move first supervariable to end of list - IW (PN) = IW (P3) -C move first element to end of element part of list - IW (P3) = IW (P1) -C add new element to front of list. - IW (P1) = ME -C store the new length of the list in len (i) - LEN (I) = PN - P1 + 1 - -C ------------------------------------------------------- -C place in hash bucket. Save hash key of i in last (i). -C ------------------------------------------------------- - - HASH = MOD (HASH, HMOD) + 1 - J = HEAD (HASH) - IF (J .LE. 0) THEN -C the degree list is empty, hash head is -j - NEXT (I) = -J - HEAD (HASH) = -I - ELSE -C degree list is not empty -C use last (head (hash)) as hash head - NEXT (I) = LAST (J) - LAST (J) = I - ENDIF - LAST (I) = HASH - ENDIF -180 CONTINUE - - DEGREE (ME) = DEGME - -C ------------------------------------------------------------- -C Clear the counter array, w (...), by incrementing wflg. -C ------------------------------------------------------------- - - DMAX = MAX (DMAX, DEGME) - WFLG = WFLG + DMAX - -C make sure that wflg+n does not cause integer overflow - IF (WFLG + N .LE. WFLG) THEN - DO 190 X = 1, N - IF (W (X) .NE. 0) W (X) = 1 -190 CONTINUE - WFLG = 2 - ENDIF -C at this point, w (1..n) .lt. wflg holds - -C======================================================================= -C SUPERVARIABLE DETECTION -C======================================================================= - - DO 250 PME = PME1, PME2 - I = IW (PME) - IF (NV (I) .LT. 0) THEN -C i is a principal variable in Lme - -C ------------------------------------------------------- -C examine all hash buckets with 2 or more variables. We -C do this by examing all unique hash keys for super- -C variables in the pattern Lme of the current element, me -C ------------------------------------------------------- - - HASH = LAST (I) -C let i = head of hash bucket, and empty the hash bucket - J = HEAD (HASH) - IF (J .EQ. 0) GOTO 250 - IF (J .LT. 0) THEN -C degree list is empty - I = -J - HEAD (HASH) = 0 - ELSE -C degree list is not empty, restore last () of head - I = LAST (J) - LAST (J) = 0 - ENDIF - IF (I .EQ. 0) GOTO 250 - -C while loop: -200 CONTINUE - IF (NEXT (I) .NE. 0) THEN - -C ---------------------------------------------------- -C this bucket has one or more variables following i. -C scan all of them to see if i can absorb any entries -C that follow i in hash bucket. Scatter i into w. -C ---------------------------------------------------- - - LN = LEN (I) - ELN = ELEN (I) -C do not flag the first element in the list (me) - DO 210 P = PE (I) + 1, PE (I) + LN - 1 - W (IW (P)) = WFLG -210 CONTINUE - -C ---------------------------------------------------- -C scan every other entry j following i in bucket -C ---------------------------------------------------- - - JLAST = I - J = NEXT (I) - -C while loop: -220 CONTINUE - IF (J .NE. 0) THEN - -C ------------------------------------------------- -C check if j and i have identical nonzero pattern -C ------------------------------------------------- - - IF (LEN (J) .NE. LN) THEN -C i and j do not have same size data structure - GOTO 240 - ENDIF - IF (ELEN (J) .NE. ELN) THEN -C i and j do not have same number of adjacent el - GOTO 240 - ENDIF -C do not flag the first element in the list (me) - DO 230 P = PE (J) + 1, PE (J) + LN - 1 - IF (W (IW (P)) .NE. WFLG) THEN -C an entry (iw(p)) is in j but not in i - GOTO 240 - ENDIF -230 CONTINUE - -C ------------------------------------------------- -C found it! j can be absorbed into i -C ------------------------------------------------- - - PE (J) = -I -C both nv (i) and nv (j) are negated since they -C are in Lme, and the absolute values of each -C are the number of variables in i and j: - NV (I) = NV (I) + NV (J) - NV (J) = 0 - ELEN (J) = 0 -C delete j from hash bucket - J = NEXT (J) - NEXT (JLAST) = J - GOTO 220 - -C ------------------------------------------------- -240 CONTINUE -C j cannot be absorbed into i -C ------------------------------------------------- - - JLAST = J - J = NEXT (J) - GOTO 220 - ENDIF - -C ---------------------------------------------------- -C no more variables can be absorbed into i -C go to next i in bucket and clear flag array -C ---------------------------------------------------- - - WFLG = WFLG + 1 - I = NEXT (I) - IF (I .NE. 0) GOTO 200 - ENDIF - ENDIF -250 CONTINUE - -C======================================================================= -C RESTORE DEGREE LISTS AND REMOVE NONPRINCIPAL SUPERVAR. FROM ELEMENT -C======================================================================= - - P = PME1 - NLEFT = N - NEL - DO 260 PME = PME1, PME2 - I = IW (PME) - NVI = -NV (I) - IF (NVI .GT. 0) THEN -C i is a principal variable in Lme -C restore nv (i) to signify that i is principal - NV (I) = NVI - -C ------------------------------------------------------- -C compute the external degree (add size of current elem) -C ------------------------------------------------------- - - DEG = MAX (1, MIN (DEGREE (I) + DEGME-NVI, NLEFT-NVI)) - -C ------------------------------------------------------- -C place the supervariable at the head of the degree list -C ------------------------------------------------------- - - INEXT = HEAD (DEG) - IF (INEXT .NE. 0) LAST (INEXT) = I - NEXT (I) = INEXT - LAST (I) = 0 - HEAD (DEG) = I - -C ------------------------------------------------------- -C save the new degree, and find the minimum degree -C ------------------------------------------------------- - - MINDEG = MIN (MINDEG, DEG) - DEGREE (I) = DEG - -C ------------------------------------------------------- -C place the supervariable in the element pattern -C ------------------------------------------------------- - - IW (P) = I - P = P + 1 - ENDIF -260 CONTINUE - -C======================================================================= -C FINALIZE THE NEW ELEMENT -C======================================================================= - - NV (ME) = NVPIV + DEGME -C nv (me) is now the degree of pivot (including diagonal part) -C save the length of the list for the new element me - LEN (ME) = P - PME1 - IF (LEN (ME) .EQ. 0) THEN -C there is nothing left of the current pivot element - PE (ME) = 0 - W (ME) = 0 - ENDIF - IF (NEWMEM .NE. 0) THEN -C element was not constructed in place: deallocate part -C of it (final size is less than or equal to newmem, -C since newly nonprincipal variables have been removed). - PFREE = P - MEM = MEM - NEWMEM + LEN (ME) - ENDIF - -C======================================================================= -C END WHILE (selecting pivots) - GOTO 30 - ENDIF -C======================================================================= - -C======================================================================= -C COMPUTE THE PERMUTATION VECTORS -C======================================================================= - -C ---------------------------------------------------------------- -C The time taken by the following code is O(n). At this -C point, elen (e) = -k has been done for all elements e, -C and elen (i) = 0 has been done for all nonprincipal -C variables i. At this point, there are no principal -C supervariables left, and all elements are absorbed. -C ---------------------------------------------------------------- - -C ---------------------------------------------------------------- -C compute the ordering of unordered nonprincipal variables -C ---------------------------------------------------------------- - - DO 290 I = 1, N - IF (ELEN (I) .EQ. 0) THEN - -C ---------------------------------------------------------- -C i is an un-ordered row. Traverse the tree from i until -C reaching an element, e. The element, e, was the -C principal supervariable of i and all nodes in the path -C from i to when e was selected as pivot. -C ---------------------------------------------------------- - - J = -PE (I) -C while (j is a variable) do: -270 CONTINUE - IF (ELEN (J) .GE. 0) THEN - J = -PE (J) - GOTO 270 - ENDIF - E = J - -C ---------------------------------------------------------- -C get the current pivot ordering of e -C ---------------------------------------------------------- - - K = -ELEN (E) - -C ---------------------------------------------------------- -C traverse the path again from i to e, and compress the -C path (all nodes point to e). Path compression allows -C this code to compute in O(n) time. Order the unordered -C nodes in the path, and place the element e at the end. -C ---------------------------------------------------------- - - J = I -C while (j is a variable) do: -280 CONTINUE - IF (ELEN (J) .GE. 0) THEN - JNEXT = -PE (J) - PE (J) = -E - IF (ELEN (J) .EQ. 0) THEN -C j is an unordered row - ELEN (J) = K - K = K + 1 - ENDIF - J = JNEXT - GOTO 280 - ENDIF -C leave elen (e) negative, so we know it is an element - ELEN (E) = -K - ENDIF -290 CONTINUE - -C ---------------------------------------------------------------- -C reset the inverse permutation (elen (1..n)) to be positive, -C and compute the permutation (last (1..n)). -C ---------------------------------------------------------------- - - DO 300 I = 1, N - K = ABS (ELEN (I)) - LAST (K) = I - ELEN (I) = K -300 CONTINUE - -C======================================================================= -C RETURN THE MEMORY USAGE IN IW -C======================================================================= - -C If maxmem is less than or equal to iwlen, then no compressions -C occurred, and iw (maxmem+1 ... iwlen) was unused. Otherwise -C compressions did occur, and iwlen would have had to have been -C greater than or equal to maxmem for no compressions to occur. -C Return the value of maxmem in the pfree argument. - - PFREE = MAXMEM - - RETURN - END - diff --git a/deps/AMICI/ThirdParty/SuiteSparse/BTF/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/BTF/CMakeLists.txt index 059bb80c2..043569d81 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/BTF/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/BTF/CMakeLists.txt @@ -12,10 +12,10 @@ cmake_minimum_required ( VERSION 3.22 ) -set ( BTF_DATE "Jan 10, 2024" ) +set ( BTF_DATE "Mar 22, 2024" ) set ( BTF_VERSION_MAJOR 2 CACHE STRING "" FORCE ) set ( BTF_VERSION_MINOR 3 CACHE STRING "" FORCE ) -set ( BTF_VERSION_SUB 1 CACHE STRING "" FORCE ) +set ( BTF_VERSION_SUB 2 CACHE STRING "" FORCE ) message ( STATUS "Building BTF version: v" ${BTF_VERSION_MAJOR}. @@ -44,10 +44,10 @@ include ( SuiteSparsePolicy ) #------------------------------------------------------------------------------- if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) - find_package ( SuiteSparse_config 7.5.0 + find_package ( SuiteSparse_config 7.7.0 PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) - find_package ( SuiteSparse_config 7.5.0 REQUIRED ) + find_package ( SuiteSparse_config 7.7.0 REQUIRED ) endif ( ) endif ( ) @@ -104,7 +104,7 @@ if ( BUILD_STATIC_LIBS ) OUTPUT_NAME btf PUBLIC_HEADER "Include/btf.h" ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( BTF_static PROPERTIES OUTPUT_NAME btf_static ) endif ( ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Config/btf.h.in b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Config/btf.h.in index a5985db8a..668eac0af 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Config/btf.h.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Config/btf.h.in @@ -274,8 +274,8 @@ void btf_version (int version [3]) ; #define BTF__VERSION SUITESPARSE__VERCODE(@BTF_VERSION_MAJOR@,@BTF_VERSION_MINOR@,@BTF_VERSION_SUB@) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,5,0)) -#error "BTF @BTF_VERSION_MAJOR@.@BTF_VERSION_MINOR@.@BTF_VERSION_SUB@ requires SuiteSparse_config 7.5.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,7,0)) +#error "BTF @BTF_VERSION_MAJOR@.@BTF_VERSION_MINOR@.@BTF_VERSION_SUB@ requires SuiteSparse_config 7.7.0 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Doc/ChangeLog b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Doc/ChangeLog index d857cbc6e..a7c2bf766 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Doc/ChangeLog +++ b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Doc/ChangeLog @@ -1,3 +1,7 @@ +Mar 22, 2024: version 2.3.2 + + * minor updates to build system + Jan 10, 2024: version 2.3.1 * minor updates to build system diff --git a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Include/btf.h b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Include/btf.h index c152e879a..823a135c2 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/BTF/Include/btf.h +++ b/deps/AMICI/ThirdParty/SuiteSparse/BTF/Include/btf.h @@ -264,18 +264,18 @@ void btf_version (int version [3]) ; * #endif */ -#define BTF_DATE "Jan 10, 2024" +#define BTF_DATE "Mar 22, 2024" #define BTF_MAIN_VERSION 2 #define BTF_SUB_VERSION 3 -#define BTF_SUBSUB_VERSION 1 +#define BTF_SUBSUB_VERSION 2 #define BTF_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub) #define BTF_VERSION BTF_VERSION_CODE(2,3) -#define BTF__VERSION SUITESPARSE__VERCODE(2,3,1) +#define BTF__VERSION SUITESPARSE__VERCODE(2,3,2) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,5,0)) -#error "BTF 2.3.1 requires SuiteSparse_config 7.5.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,7,0)) +#error "BTF 2.3.2 requires SuiteSparse_config 7.7.0 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/CITATION.bib b/deps/AMICI/ThirdParty/SuiteSparse/CITATION.bib index 13b13d93a..45fe575c6 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/CITATION.bib +++ b/deps/AMICI/ThirdParty/SuiteSparse/CITATION.bib @@ -474,7 +474,7 @@ @article{10.1145/3337792 @article{10.1145/3519024, author = {Lourenco, Christopher and Chen, Jinhao and Moreno-Centeno, Erick and Davis, Timothy A.}, -title = {Algorithm 1XXX: SPEX Left LU, Exactly Solving Sparse Linear Systems via a Sparse Left-Looking Integer-Preserving LU Factorization}, +title = {Algorithm 1021: SPEX Left LU, Exactly Solving Sparse Linear Systems via a Sparse Left-Looking Integer-Preserving LU Factorization}, year = {2022}, publisher = {Association for Computing Machinery}, address = {New York, NY, USA}, @@ -482,9 +482,8 @@ @article{10.1145/3519024 url = {https://doi.org/10.1145/3519024}, doi = {10.1145/3519024}, abstract = {SPEX Left LU is a software package for exactly solving unsymmetric sparse linear systems. As a component of the sparse exact (SPEX) software package, SPEX Left LU can be applied to any input matrix, A, whose entries are integral, rational, or decimal, and provides a solution to the system Ax = b which is either exact or accurate to user-specified precision. SPEX Left LU preorders the matrix A with a user-specified fill-reducing ordering and computes a left-looking LU factorization with the special property that each operation used to compute the L and U matrices is integral. Notable additional applications of this package include benchmarking the stability and accuracy of state-of-the-art linear solvers, and determining whether singular-to-double-precision matrices are indeed singular. Computationally, this paper evaluates the impact of several novel pivoting schemes in exact arithmetic, benchmarks the exact iterative solvers within Linbox, and benchmarks the accuracy of MATLAB sparse backslash. Most importantly, it is shown that SPEX Left LU outperforms the exact iterative solvers in run time on easy instances and in stability as the iterative solver fails on a sizeable subset of the tested (both easy and hard) instances. The SPEX Left LU package is written in ANSI C, comes with a MATLAB interface, and is distributed via GitHub, as a component of the SPEX software package, and as a component of SuiteSparse.}, -note = {Just Accepted}, journal = {ACM Trans. Math. Softw.}, -month = {feb}, +month = {jun}, keywords = {exact matrix factorization, sparse linear systems, sparse matrix algorithms, exactly solving linear systems, roundoff errors} } diff --git a/deps/AMICI/ThirdParty/SuiteSparse/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/CMakeLists.txt index 0a23a5a48..2a73790b5 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/CMakeLists.txt @@ -85,6 +85,7 @@ option ( SUITESPARSE_USE_SYSTEM_CAMD "ON: use CAMD libraries installed on the bu option ( SUITESPARSE_USE_SYSTEM_CCOLAMD "ON: use CCOLAMD libraries installed on the build system. OFF (default): Automatically build CCOLAMD as dependency if needed." OFF ) option ( SUITESPARSE_USE_SYSTEM_GRAPHBLAS "ON: use GraphBLAS libraries installed on the build system. OFF (default): Automatically build GraphBLAS as dependency if needed." OFF ) option ( SUITESPARSE_USE_SYSTEM_SUITESPARSE_CONFIG "ON: use SuiteSparse_config libraries installed on the build system. OFF (default): Automatically build SuiteSparse_config as dependency if needed." OFF ) +option ( SUITESPARSE_USE_SYSTEM_UMFPACK "ON: use UMFPACK libraries installed on the build system. OFF (default): Automatically build UMFPACK as dependency if needed." OFF ) #------------------------------------------------------------------------------- # global variables @@ -110,7 +111,7 @@ include ( SuiteSparsePolicy ) if ( SUITESPARSE_USE_SYSTEM_GRAPHBLAS ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "graphblas" ) - find_package ( GraphBLAS 9.0.1 REQUIRED ) + find_package ( GraphBLAS 9.3.1 REQUIRED ) else ( ) if ( "lagraph" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) # LAGraph requires GraphBLAS. @@ -123,7 +124,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_BTF ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "btf" ) - find_package ( BTF 2.3.1 REQUIRED ) + find_package ( BTF 2.3.2 REQUIRED ) else ( ) if ( "klu" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) # KLU requires BTF. @@ -134,9 +135,22 @@ else ( ) endif ( ) endif ( ) +if ( SUITESPARSE_USE_SYSTEM_UMFPACK ) + list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "umfpack" ) + find_package ( UMFPACK 6.3.4 REQUIRED ) +else ( ) + if ( "paru" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) + # ParU requires UMFPACK. + if ( NOT "umfpack" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) + message ( STATUS "Adding \"umfpack\" to the list of built targets." ) + list ( APPEND SUITESPARSE_ENABLE_PROJECTS "umfpack" ) + endif ( ) + endif ( ) +endif ( ) + if ( SUITESPARSE_USE_SYSTEM_CHOLMOD ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "cholmod" ) - find_package ( CHOLMOD 5.2.0 REQUIRED ) + find_package ( CHOLMOD 5.3.0 REQUIRED ) else ( ) if ( ( KLU_USE_CHOLMOD AND "klu" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) OR ( UMFPACK_USE_CHOLMOD AND "umfpack" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) @@ -154,7 +168,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_AMD ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "amd" ) - find_package ( AMD 3.3.1 REQUIRED ) + find_package ( AMD 3.3.3 REQUIRED ) else ( ) if ( "cholmod" IN_LIST SUITESPARSE_ENABLE_PROJECTS OR "ldl" IN_LIST SUITESPARSE_ENABLE_PROJECTS @@ -170,7 +184,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_COLAMD ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "colamd" ) - find_package ( COLAMD 3.3.2 REQUIRED ) + find_package ( COLAMD 3.3.4 REQUIRED ) else ( ) if ( "cholmod" IN_LIST SUITESPARSE_ENABLE_PROJECTS OR "spex" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) @@ -184,7 +198,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_CAMD ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "camd" ) - find_package ( CAMD 3.3.1 REQUIRED ) + find_package ( CAMD 3.3.3 REQUIRED ) else ( ) if ( CHOLMOD_CAMD AND "cholmod" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) # CHOLMOD can optionally use CAMD. @@ -197,7 +211,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_CCOLAMD ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "ccolamd" ) - find_package ( CCOLAMD 3.3.2 REQUIRED ) + find_package ( CCOLAMD 3.3.4 REQUIRED ) else ( ) if ( CHOLMOD_CAMD AND "cholmod" IN_LIST SUITESPARSE_ENABLE_PROJECTS ) # CHOLMOD can optionally use CCOLAMD. @@ -210,7 +224,7 @@ endif ( ) if ( SUITESPARSE_USE_SYSTEM_SUITESPARSE_CONFIG ) list ( REMOVE_ITEM SUITESPARSE_ENABLE_PROJECTS "suitesparse_config" ) - find_package ( SuiteSparse_config 7.6.0 REQUIRED ) + find_package ( SuiteSparse_config 7.8.2 REQUIRED ) else ( ) if ( "mongoose" IN_LIST SUITESPARSE_ENABLE_PROJECTS OR "amd" IN_LIST SUITESPARSE_ENABLE_PROJECTS diff --git a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/CMakeLists.txt index 39ac72eda..5848678a0 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/CMakeLists.txt @@ -11,10 +11,10 @@ cmake_minimum_required ( VERSION 3.22 ) -set ( COLAMD_DATE "Jan 20, 2024" ) +set ( COLAMD_DATE "June 20, 2024" ) set ( COLAMD_VERSION_MAJOR 3 CACHE STRING "" FORCE ) set ( COLAMD_VERSION_MINOR 3 CACHE STRING "" FORCE ) -set ( COLAMD_VERSION_SUB 2 CACHE STRING "" FORCE ) +set ( COLAMD_VERSION_SUB 4 CACHE STRING "" FORCE ) message ( STATUS "Building COLAMD version: v" ${COLAMD_VERSION_MAJOR}. @@ -43,10 +43,10 @@ include ( SuiteSparsePolicy ) #------------------------------------------------------------------------------- if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) - find_package ( SuiteSparse_config 7.6.0 + find_package ( SuiteSparse_config 7.8.0 PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) - find_package ( SuiteSparse_config 7.6.0 REQUIRED ) + find_package ( SuiteSparse_config 7.8.0 REQUIRED ) endif ( ) endif ( ) @@ -104,7 +104,7 @@ if ( BUILD_STATIC_LIBS ) C_STANDARD_REQUIRED ON PUBLIC_HEADER "Include/colamd.h" ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( COLAMD_static PROPERTIES OUTPUT_NAME colamd_static ) endif ( ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Config/colamd.h.in b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Config/colamd.h.in index 2d9a0c07f..8ee81174c 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Config/colamd.h.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Config/colamd.h.in @@ -75,8 +75,8 @@ #define COLAMD__VERSION SUITESPARSE__VERCODE(@COLAMD_VERSION_MAJOR@,@COLAMD_VERSION_MINOR@,@COLAMD_VERSION_SUB@) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,6,0)) -#error "COLAMD @COLAMD_VERSION_MAJOR@.@COLAMD_VERSION_MINOR@.@COLAMD_VERSION_SUB@ requires SuiteSparse_config 7.6.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "COLAMD @COLAMD_VERSION_MAJOR@.@COLAMD_VERSION_MINOR@.@COLAMD_VERSION_SUB@ requires SuiteSparse_config 7.8.0 or later" #endif /* ========================================================================== */ diff --git a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Doc/ChangeLog b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Doc/ChangeLog index 9904dacaf..dc7f12e65 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Doc/ChangeLog +++ b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Doc/ChangeLog @@ -1,3 +1,11 @@ +June 20, 2024: version 3.3.4 + + * minor update for MATLAB on Windows + +Mar 22, 2024: version 3.3.3 + + * minor updates to build system + Jan 20, 2024: version 3.3.2 * minor updates to build system diff --git a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Include/colamd.h b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Include/colamd.h index 93c2c08eb..a60ef6f0a 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Include/colamd.h +++ b/deps/AMICI/ThirdParty/SuiteSparse/COLAMD/Include/colamd.h @@ -65,18 +65,18 @@ * Versions 2.3 and earlier of COLAMD do not include a #define'd version number. */ -#define COLAMD_DATE "Jan 20, 2024" +#define COLAMD_DATE "June 20, 2024" #define COLAMD_MAIN_VERSION 3 #define COLAMD_SUB_VERSION 3 -#define COLAMD_SUBSUB_VERSION 2 +#define COLAMD_SUBSUB_VERSION 4 #define COLAMD_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub) #define COLAMD_VERSION COLAMD_VERSION_CODE(3,3) -#define COLAMD__VERSION SUITESPARSE__VERCODE(3,3,2) +#define COLAMD__VERSION SUITESPARSE__VERCODE(3,3,4) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,6,0)) -#error "COLAMD 3.3.2 requires SuiteSparse_config 7.6.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "COLAMD 3.3.4 requires SuiteSparse_config 7.8.0 or later" #endif /* ========================================================================== */ diff --git a/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTING.md b/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTING.md index a81e104cf..6348f2f48 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTING.md +++ b/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTING.md @@ -6,13 +6,13 @@ you can use the issue tracker on github.com, at (https://github.com/DrTimothyAldenDavis/SuiteSparse/issues). To contribute code, you can submit a pull request. To do so, -you must first agree to the Contributor License Agreement -[`CONTRIBUTOR-LICENSE.txt`](CONTRIBUTOR-LICENSE.txt). -Print a copy of the txt file (as a PDF), sign and date it, -and email it to me at DrTimothyAldenDavis@gmail.com. Pull -requests will only be included into SuiteSparse after I receive -your email with the signed PDF. +you must first agree to the Contributor License +in the [`Contributor_License`](Contributor_License) folder. +Sign and date it the PDF, and email it to me at +DrTimothyAldenDavis@gmail.com. Pull requests will only be +included into SuiteSparse after I receive your email with +the signed PDF. Do not submit a pull request to the default branch. -Instead, use the dev or dev2 branches. +Instead, use the dev2 branch. diff --git a/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTOR-LICENSE.txt b/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTOR-LICENSE.txt deleted file mode 100644 index 7cd19eec6..000000000 --- a/deps/AMICI/ThirdParty/SuiteSparse/CONTRIBUTOR-LICENSE.txt +++ /dev/null @@ -1,177 +0,0 @@ -SuiteSparse Individual Contributor License Agreement - -Thank you for your interest in contributing to SuiteSparse ("We" or "Us"). - -This contributor agreement ("Agreement") documents the rights granted by -contributors to Us. To make this document effective, please sign it and send it -to Us by electronic submission. This is a legally binding document, so please -read it carefully before agreeing to it. The Agreement may cover more than one -software project managed by Us. - -1. Definitions - - "You" means the individual who Submits a Contribution to Us. - - "Contribution" means any work of authorship that is Submitted by You to Us - in which You own or assert ownership of the Copyright. - - "Copyright" means all rights protecting works of authorship owned or - controlled by You, including copyright, moral and neighboring rights, as - appropriate, for the full term of their existence including any extensions - by You. - - "Material" means the work of authorship which is made available by Us to - third parties. When this Agreement covers more than one software project, - the Material means the work of authorship to which the Contribution was - Submitted. After You Submit the Contribution, it may be included in the - Material. - - "Submit" means any form of electronic, verbal, or written communication - sent to Us or our representatives, including but not limited to electronic - mailing lists, source code control systems, and issue tracking systems that - are managed by, or on behalf of, Us for the purpose of discussing and - improving the Material, but excluding communication that is conspicuously - marked or otherwise designated in writing by You as "Not a Contribution." - - "Submission Date" means the date on which You Submit a Contribution to Us. - - "Effective Date" means the date You execute this Agreement or the date You - first Submit a Contribution to Us, whichever is earlier. - -2. Grant of Rights - - 2.1 Copyright License - - (a) You retain ownership of the Copyright in Your Contribution and have - the same rights to use or license the Contribution which You would have - had without entering into the Agreement. - - (b) To the maximum extent permitted by the relevant law, You grant to - Us a perpetual, worldwide, non-exclusive, transferable, royalty-free, - irrevocable license under the Copyright covering the Contribution, with - the right to sublicense such rights through multiple tiers of - sublicensees, to reproduce, modify, display, perform and distribute the - Contribution as part of the Material; provided that this license is - conditioned upon compliance with Section 2.3. - - 2.2 Patent License - - For patent claims including, without limitation, method, process, and - apparatus claims which You own, control or have the right to grant, now - or in the future, You grant to Us a perpetual, worldwide, - non-exclusive, transferable, royalty-free, irrevocable patent license, - with the right to sublicense these rights to multiple tiers of - sublicensees, to make, have made, use, sell, offer for sale, import and - otherwise transfer the Contribution and the Contribution in combination - with the Material (and portions of such combination). This license is - granted only to the extent that the exercise of the licensed rights - infringes such patent claims; and provided that this license is - conditioned upon compliance with Section 2.3. - - 2.3 Outbound License - - Based on the grant of rights in Sections 2.1 and 2.2, if We include - Your Contribution in a Material, We may license the Contribution under - any license, including copyleft, permissive, commercial, or proprietary - licenses. - - 2.4 Moral Rights. - - If moral rights apply to the Contribution, to the maximum extent - permitted by law, You waive and agree not to assert such moral rights - against Us or our successors in interest, or any of our licensees, - either direct or indirect. - - 2.5 Our Rights. - - You acknowledge that We are not obligated to use Your Contribution as - part of the Material and may decide to include any Contribution We - consider appropriate. - - 2.6 Reservation of Rights. - - Any rights not expressly licensed under this section are expressly - reserved by You. - -3. Agreement - - You confirm that: - - (a) You have the legal authority to enter into this Agreement. - - (b) You own the Copyright and patent claims covering the Contribution which - are required to grant the rights under Section 2. - - (c) The grant of rights under Section 2 does not violate any grant of - rights which You have made to third parties, including Your employer. If - You are an employee, You have had Your employer approve this Agreement or - sign the Entity version of this document. If You are less than eighteen - years old, please have Your parents or guardian sign the Agreement. - -4. Disclaimer - - EXCEPT FOR THE EXPRESS WARRANTIES IN SECTION 3, THE CONTRIBUTION IS - PROVIDED "AS IS". MORE PARTICULARLY, ALL EXPRESS OR IMPLIED WARRANTIES - INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTY OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY - DISCLAIMED BY YOU TO US. TO THE EXTENT THAT ANY SUCH WARRANTIES CANNOT BE - DISCLAIMED, SUCH WARRANTY IS LIMITED IN DURATION TO THE MINIMUM PERIOD - PERMITTED BY LAW. - -5. Consequential Damage Waiver - - TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL YOU BE - LIABLE FOR ANY LOSS OF PROFITS, LOSS OF ANTICIPATED SAVINGS, LOSS OF DATA, - INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL AND EXEMPLARY DAMAGES ARISING - OUT OF THIS AGREEMENT REGARDLESS OF THE LEGAL OR EQUITABLE THEORY - (CONTRACT, TORT OR OTHERWISE) UPON WHICH THE CLAIM IS BASED. - -6. Miscellaneous - - 6.1 This Agreement will be governed by and construed in accordance with the - laws of the State of Texas excluding its conflicts of law provisions. Under - certain circumstances, the governing law in this section might be - superseded by the United Nations Convention on Contracts for the - International Sale of Goods ("UN Convention") and the parties intend to - avoid the application of the UN Convention to this Agreement and, thus, - exclude the application of the UN Convention in its entirety to this - Agreement. - - 6.2 This Agreement sets out the entire agreement between You and Us for - Your Contributions to Us and overrides all other agreements or - understandings. - - 6.3 If You or We assign the rights or obligations received through this - Agreement to a third party, as a condition of the assignment, that third - party must agree in writing to abide by all the rights and obligations in - the Agreement. - - 6.4 The failure of either party to require performance by the other party - of any provision of this Agreement in one situation shall not affect the - right of a party to require such performance at any time in the future. A - waiver of performance under a provision in one situation shall not be - considered a waiver of the performance of the provision in the future or a - waiver of the provision in its entirety. - - 6.5 If any provision of this Agreement is found void and unenforceable, - such provision will be replaced to the extent possible with a provision - that comes closest to the meaning of the original provision and which is - enforceable. The terms and conditions set forth in this Agreement shall - apply notwithstanding any failure of essential purpose of this Agreement or - any limited remedy to the maximum extent possible under law. - -Us -Timothy A. Davis, and all SuiteSparse co-authors (varies according to -the SuiteSparse package) - - -You: - - Your Name (printed): - - - Your Signature: - - - Date: - diff --git a/deps/AMICI/ThirdParty/SuiteSparse/ChangeLog b/deps/AMICI/ThirdParty/SuiteSparse/ChangeLog index 0f1eb8790..d8a7ed8b1 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/ChangeLog +++ b/deps/AMICI/ThirdParty/SuiteSparse/ChangeLog @@ -1,3 +1,154 @@ +Aug 20, 2024: version 7.8.2 + + * LAGraph 1.1.4: bug fix for LAGraph_MMWrite when matrix is dense + * SPEX 3.2.1: release date revised, sync with primary SPEX repo + * SuiteSparse_config, Example: modified to reflect the release of + LAGraph 1.1.4 and SPEX 3.2.1 + * ParU 0.3.0: added parameter to ParU_Get + * Package versions in this release: (* denotes a new version) + SuiteSparse_config 7.8.2 * + AMD 3.3.3 + BTF 2.3.2 + CAMD 3.3.3 + CCOLAMD 3.3.4 + CHOLMOD 5.3.0 + COLAMD 3.3.4 + CSparse 4.3.2 + CXSparse 4.4.1 + Example 1.8.2 * + GraphBLAS 9.3.1 + KLU 2.3.4 + LDL 3.3.2 + LAGraph 1.1.4 * + SuiteSparse_Mongoose 3.3.4 + ParU 0.3.0 * + RBio 4.3.3 + SPEX 3.2.1 * + SPQR 4.3.4 + UMFPACK 6.3.4 + +Aug 12, 2024: version 7.8.1 + + * GraphBLAS 9.3.1: bug fix in creation of JIT package + * SuiteSparse_config, Example: modified to reflect the release of + GraphBLAS 9.3.1 + * Package versions in this release: (* denotes a new version) + SuiteSparse_config 7.8.1 * + AMD 3.3.3 + BTF 2.3.2 + CAMD 3.3.3 + CCOLAMD 3.3.4 + CHOLMOD 5.3.0 + COLAMD 3.3.4 + CSparse 4.3.2 + CXSparse 4.4.1 + Example 1.8.1 * + GraphBLAS 9.3.1 * + KLU 2.3.4 + LDL 3.3.2 + LAGraph 1.1.3 + SuiteSparse_Mongoose 3.3.4 + ParU 0.2.0 + RBio 4.3.3 + SPEX 3.2.0 + SPQR 4.3.4 + UMFPACK 6.3.4 + +Aug 2, 2024: version 7.8.0 + + * ParU 0.2.0: many changes; nearing a stable release. + * CHOLMOD 5.3.0: added cholmod_query, and #define's in cholmod.h, + to query which Modules and features have been configured. + * GraphBLAS 9.3.0: simpler MATLAB install; sanitize environment variables; + code restructuring. + * SPQR 4.3.4: changes to reflect updates to CHOLMOD + * SPEX 3.2.0: control Python interface, fix build issues on Mac, + split SPEX Cholesky into LDL and Cholesky. + * SuiteSparse_config: changes to SuiteSparse timer, BLA_VENDOR. Added + SUITESPARSE_USE_PYTHON option. Split BLAS prototypes and macros. + * .github: new CI runner for riscv64, and other changes in CI workflows. + * AMD, CAMD, COLAMD, CCOLAMD, CXSparse, KLU, SuiteSparse_Mongoose, + RBio, UMFPACK: minor changes for MATLAB in Windows + * no changes to: BTF, CSparse, LDL, and LAGraph + * Package versions in this release: (* denotes a new version) + SuiteSparse_config 7.8.0 * + AMD 3.3.3 * + BTF 2.3.2 same as SuiteSparse 7.7.0 + CAMD 3.3.3 * + CCOLAMD 3.3.4 * + CHOLMOD 5.3.0 * + COLAMD 3.3.4 * + CSparse 4.3.2 same as SuiteSparse 7.7.0 + CXSparse 4.4.1 * + Example 1.8.0 * + GraphBLAS 9.3.0 * + KLU 2.3.4 * + LDL 3.3.2 same as SuiteSparse 7.7.0 + LAGraph 1.1.3 same as SuiteSparse 7.7.0 + SuiteSparse_Mongoose 3.3.4 * + ParU 0.2.0 * + RBio 4.3.3 * + SPEX 3.2.0 * + SPQR 4.3.4 * + UMFPACK 6.3.4 * + +Mar 22, 2024: version 7.7.0 + + * SPEX 3.1.0: major revision to API, new methods. Added SPEX_Cholesky, + SPEX_Backslash, and python interface. MATLAB interface revised. + * Example 1.7.0: revised for change in SPEX API + * GraphBLAS 9.1.0: revised defn of C11 or MSVC complex type, bug fix + * CXSparse 4.4.0: revise malloc/calloc/realloc/free wrappers + * All others: minor changes to build system + * Package versions in this release: + SuiteSparse_config 7.7.0 + AMD 3.3.2 + BTF 2.3.2 + CAMD 3.3.2 + CCOLAMD 3.3.3 + CHOLMOD 5.2.1 + COLAMD 3.3.3 + CSparse 4.3.2 + CXSparse 4.4.0 + Example 1.7.0 + GraphBLAS 9.1.0 + KLU 2.3.3 + LDL 3.3.2 + LAGraph 1.1.3 + SuiteSparse_Mongoose 3.3.3 + ParU 0.1.3 + RBio 4.3.2 + SPEX 3.1.0 + SPQR 4.3.3 + UMFPACK 6.3.3 + +Mar 2, 2024: version 7.6.1 + + * GraphBLAS 9.0.3: performance bug fix (JIT kernels were not compiled with + OpenMP, since v8.3.1), and fix to Makefile ("make static") + * SuiteSparse_config 7.6.1: version number, added link to math.js in README + * Package versions in this release: + SuiteSparse_config 7.6.1 + AMD 3.3.1 + BTF 2.3.1 + CAMD 3.3.1 + CCOLAMD 3.3.2 + CHOLMOD 5.2.0 + COLAMD 3.3.2 + CSparse 4.3.1 + CXSparse 4.3.1 + Example 1.6.2 + GraphBLAS 9.0.3 + KLU 2.3.2 + LDL 3.3.1 + LAGraph 1.1.2 + SuiteSparse_Mongoose 3.3.2 + ParU 0.1.2 + RBio 4.3.1 + SPEX 2.3.2 + SPQR 4.3.2 + UMFPACK 6.3.2 + Jan 20, 2024: version 7.6.0 * CHOLMOD 5.2.0: bug fix (restore ABI compatibility with 5.0.x, i.e., 5.2.0 diff --git a/deps/AMICI/ThirdParty/SuiteSparse/KLU/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/KLU/CMakeLists.txt index 05025e37f..9e52f2b03 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/KLU/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/KLU/CMakeLists.txt @@ -12,10 +12,10 @@ cmake_minimum_required ( VERSION 3.22 ) -set ( KLU_DATE "Jan 20, 2024" ) +set ( KLU_DATE "June 20, 2024" ) set ( KLU_VERSION_MAJOR 2 CACHE STRING "" FORCE ) set ( KLU_VERSION_MINOR 3 CACHE STRING "" FORCE ) -set ( KLU_VERSION_SUB 2 CACHE STRING "" FORCE ) +set ( KLU_VERSION_SUB 4 CACHE STRING "" FORCE ) message ( STATUS "Building KLU version: v" ${KLU_VERSION_MAJOR}. @@ -43,28 +43,28 @@ include ( SuiteSparsePolicy ) #------------------------------------------------------------------------------- if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) - find_package ( SuiteSparse_config 7.6.0 + find_package ( SuiteSparse_config 7.8.0 PATHS ${CMAKE_SOURCE_DIR}/../SuiteSparse_config/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::SuiteSparseConfig ) - find_package ( SuiteSparse_config 7.6.0 REQUIRED ) + find_package ( SuiteSparse_config 7.8.0 REQUIRED ) endif ( ) - find_package ( AMD 3.3.1 + find_package ( AMD 3.3.2 PATHS ${CMAKE_SOURCE_DIR}/../AMD/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::AMD ) - find_package ( AMD 3.3.1 REQUIRED ) + find_package ( AMD 3.3.2 REQUIRED ) endif ( ) - find_package ( COLAMD 3.3.2 + find_package ( COLAMD 3.3.3 PATHS ${CMAKE_SOURCE_DIR}/../COLAMD/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::COLAMD ) - find_package ( COLAMD 3.3.2 REQUIRED ) + find_package ( COLAMD 3.3.3 REQUIRED ) endif ( ) - find_package ( BTF 2.3.1 + find_package ( BTF 2.3.2 PATHS ${CMAKE_SOURCE_DIR}/../BTF/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::BTF ) - find_package ( BTF 2.3.1 REQUIRED ) + find_package ( BTF 2.3.2 REQUIRED ) endif ( ) endif ( ) @@ -77,10 +77,10 @@ if ( SUITESPARSE_ROOT_CMAKELISTS ) else ( ) if ( KLU_USE_CHOLMOD ) # look for CHOLMOD (optional fill-reducing orderings) - find_package ( CHOLMOD 5.2.0 + find_package ( CHOLMOD 5.2.1 PATHS ${CMAKE_SOURCE_DIR}/../CHOLMOD/build NO_DEFAULT_PATH ) if ( NOT TARGET SuiteSparse::CHOLMOD ) - find_package ( CHOLMOD 5.2.0 ) + find_package ( CHOLMOD 5.2.1 ) endif ( ) if ( NOT CHOLMOD_FOUND ) # CHOLMOD not found so disable it @@ -162,7 +162,7 @@ if ( BUILD_STATIC_LIBS ) OUTPUT_NAME klu PUBLIC_HEADER "Include/klu.h" ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( KLU_static PROPERTIES OUTPUT_NAME klu_static ) endif ( ) @@ -213,7 +213,7 @@ if ( KLU_HAS_CHOLMOD ) OUTPUT_NAME klu_cholmod PUBLIC_HEADER "User/klu_cholmod.h" ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( KLU_CHOLMOD_static PROPERTIES OUTPUT_NAME klu_cholmod_static ) endif ( ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Config/klu.h.in b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Config/klu.h.in index 1f02c4be5..09c8780ef 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Config/klu.h.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Config/klu.h.in @@ -833,23 +833,23 @@ void klu_version (int version [3]) ; #define KLU__VERSION SUITESPARSE__VERCODE(@KLU_VERSION_MAJOR@,@KLU_VERSION_MINOR@,@KLU_VERSION_SUB@) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,6,0)) -#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires SuiteSparse_config 7.6.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires SuiteSparse_config 7.8.0 or later" #endif #if !defined (AMD__VERSION) || \ - (AMD__VERSION < SUITESPARSE__VERCODE(3,3,1)) -#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires AMD 3.3.1 or later" + (AMD__VERSION < SUITESPARSE__VERCODE(3,3,3)) +#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires AMD 3.3.3 or later" #endif #if !defined (COLAMD__VERSION) || \ - (COLAMD__VERSION < SUITESPARSE__VERCODE(3,3,2)) -#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires COLAMD 3.3.2 or later" + (COLAMD__VERSION < SUITESPARSE__VERCODE(3,3,4)) +#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires COLAMD 3.3.4 or later" #endif #if !defined (BTF__VERSION) || \ - (BTF__VERSION < SUITESPARSE__VERCODE(2,3,1)) -#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires BTF 2.3.1 or later" + (BTF__VERSION < SUITESPARSE__VERCODE(2,3,2)) +#error "KLU @KLU_VERSION_MAJOR@.@KLU_VERSION_MINOR@.@KLU_VERSION_SUB@ requires BTF 2.3.2 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/ChangeLog b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/ChangeLog index d4313dbc5..bb6ebb833 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/ChangeLog +++ b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/ChangeLog @@ -1,3 +1,11 @@ +June 20, 2024: version 2.3.4 + + * minor update for MATLAB on Windows + +Mar 22, 2024: version 2.3.3 + + * minor update to build system + Jan 20, 2024: version 2.3.2 * revise version numbers for dependencies diff --git a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/klu_version.tex b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/klu_version.tex index 5e71c34bc..6f663b4a8 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/klu_version.tex +++ b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Doc/klu_version.tex @@ -1,2 +1,2 @@ % version of SuiteSparse/KLU -\date{VERSION 2.3.2, Jan 20, 2024} +\date{VERSION 2.3.4, June 20, 2024} diff --git a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Include/klu.h b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Include/klu.h index 22155ff8b..da3ae6f39 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/KLU/Include/klu.h +++ b/deps/AMICI/ThirdParty/SuiteSparse/KLU/Include/klu.h @@ -823,33 +823,33 @@ void klu_version (int version [3]) ; * #endif */ -#define KLU_DATE "Jan 20, 2024" +#define KLU_DATE "June 20, 2024" #define KLU_MAIN_VERSION 2 #define KLU_SUB_VERSION 3 -#define KLU_SUBSUB_VERSION 2 +#define KLU_SUBSUB_VERSION 4 #define KLU_VERSION_CODE(main,sub) SUITESPARSE_VER_CODE(main,sub) #define KLU_VERSION KLU_VERSION_CODE(2,3) -#define KLU__VERSION SUITESPARSE__VERCODE(2,3,2) +#define KLU__VERSION SUITESPARSE__VERCODE(2,3,4) #if !defined (SUITESPARSE__VERSION) || \ - (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,6,0)) -#error "KLU 2.3.2 requires SuiteSparse_config 7.6.0 or later" + (SUITESPARSE__VERSION < SUITESPARSE__VERCODE(7,8,0)) +#error "KLU 2.3.4 requires SuiteSparse_config 7.8.0 or later" #endif #if !defined (AMD__VERSION) || \ - (AMD__VERSION < SUITESPARSE__VERCODE(3,3,1)) -#error "KLU 2.3.2 requires AMD 3.3.1 or later" + (AMD__VERSION < SUITESPARSE__VERCODE(3,3,3)) +#error "KLU 2.3.4 requires AMD 3.3.3 or later" #endif #if !defined (COLAMD__VERSION) || \ - (COLAMD__VERSION < SUITESPARSE__VERCODE(3,3,2)) -#error "KLU 2.3.2 requires COLAMD 3.3.2 or later" + (COLAMD__VERSION < SUITESPARSE__VERCODE(3,3,4)) +#error "KLU 2.3.4 requires COLAMD 3.3.4 or later" #endif #if !defined (BTF__VERSION) || \ - (BTF__VERSION < SUITESPARSE__VERCODE(2,3,1)) -#error "KLU 2.3.2 requires BTF 2.3.1 or later" + (BTF__VERSION < SUITESPARSE__VERCODE(2,3,2)) +#error "KLU 2.3.4 requires BTF 2.3.2 or later" #endif #endif diff --git a/deps/AMICI/ThirdParty/SuiteSparse/LICENSE.txt b/deps/AMICI/ThirdParty/SuiteSparse/LICENSE.txt index 8c6d47346..722cb63d0 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/LICENSE.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/LICENSE.txt @@ -2,15 +2,14 @@ This file lists all licenses for all packages in SuiteSparse, for your convenience. Each package has its own separate license, which can be found in the lists below. -==> SPEX/License/license.txt <== +==> SPEX/LICENSE <== - SPEX: a Sparse Left-looking Integer-Preserving LU Factorization + SPEX: a SParse EXact Factorization Framework for solving SLEs - Copyright (c) 2019-2023, Christopher Lourenco, JinHao Chen, Erick Moreno- - Centeno, and Timothy A. Davis. + Copyright (c) 2019-2024, Christopher Lourenco, Jinhao Chen, + Lorena Mejia Domenzain, Erick Moreno-Centeno, and Timothy A. Davis. Available at: - https://github.com/clouren/SPEX http://suitesparse.com diff --git a/deps/AMICI/ThirdParty/SuiteSparse/README.md b/deps/AMICI/ThirdParty/SuiteSparse/README.md index 29c74df12..c8239dbf3 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/README.md +++ b/deps/AMICI/ThirdParty/SuiteSparse/README.md @@ -2,7 +2,7 @@ SuiteSparse: A Suite of Sparse matrix packages at http://suitesparse.com ----------------------------------------------------------------------------- -Jan 20, 2024, SuiteSparse VERSION 7.6.0 +Aug 20, 2024, SuiteSparse VERSION 7.8.2 SuiteSparse is a set of sparse-matrix-related packages written or co-authored by Tim Davis, available at https://github.com/DrTimothyAldenDavis/SuiteSparse . @@ -713,9 +713,9 @@ particular BLAS library use either: cd Package ; cmake -DBLA_VENDOR=OpenBLAS .. make To use the default (hunt for a BLAS), do not set `BLA_VENDOR`, or set it to -`ANY`. In this case, if `SUITESPARSE_USE_64BIT_BLAS` is ON, preference is -given to a 64-bit BLAS, but a 32-bit BLAS library will be used if no 64-bit -library is found. However, if both `SUITESPARSE_USE_64BIT_BLAS` and +an empty string. In this case, if `SUITESPARSE_USE_64BIT_BLAS` is ON, +preference is given to a 64-bit BLAS, but a 32-bit BLAS library will be used if +no 64-bit library is found. However, if both `SUITESPARSE_USE_64BIT_BLAS` and `SUITESPARSE_USE_STRICT` are ON, then only a 64-bit BLAS is considered. When selecting a particular BLAS library, the `SUITESPARSE_USE_64BIT_BLAS` @@ -979,6 +979,12 @@ build type). The static libraries will not be built (since If `ON`, look for a 64-bit BLAS. If `OFF`: 32-bit only. Default: `OFF`. +* `SUITESPARSE_USE_PYTHON`: + + If `ON`, build Python interfaces for any package in SuiteSparse that has + one (currently only SPEX). If `OFF`: do not build any Python interface. + Default: `ON`. + * `SUITESPARSE_USE_OPENMP`: If `ON`, OpenMP is used by default if it is available. Default: `ON`. @@ -1023,6 +1029,11 @@ build type). The static libraries will not be built (since If `ON`, OpenMP is used in ParU if it is available. Default: `SUITESPARSE_USE_OPENMP`. +* `SPEX_USE_OPENMP`: + + If `ON`, OpenMP is used in SPEX if it is available. + Default: `SUITESPARSE_USE_OPENMP`. + * `SUITESPARSE_DEMOS`: If `ON`, build the demo programs for each package. Default: `OFF`. @@ -1072,10 +1083,32 @@ build type). The static libraries will not be built (since If `ON`, use the Fortran compiler to determine how C calls Fortan, and to build several optional Fortran routines. If `OFF`, use - `SUITESPARSE_C_TO_FORTRAN` to define how C calls Fortran (see - `SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake` for details). + `SUITESPARSE_C_TO_FORTRAN` to define how C calls Fortran. Default: `ON`. +* `SUITESPARSE_C_TO_FORTRAN` + + A string that defines how C calls Fortran (i.e., functions exported by the + BLAS library). This setting is used if no working Fortran compiler could be + detected or `SUITESPARSE_USE_FORTRAN` is set to `OFF`. This string is to be + read as the argument list and the body of a preprocessor macro. The first + argument to that macro is any Fortran function name in lowercase letters. + The second argument is the same function name in uppercase letters. The body + defines by which function name Fortran functions are called. This is + necessary because Fortran is case-insensitive, and different Fortran + compilers use different name mangling conventions. If a MSVC C/C++ compiler + is used, this defaults to `"(name,NAME) name"` (i.e., lower case without + trailing underscore). That is the name mangling convention for the Intel + Fortran compiler on Windows. If any other C/C++ compilers are used, this + defaults to `"(name,NAME) name##_"` (i.e., lower case with trailing + underscore). That is the name mangling convention for most of the commonly + used Fortran compilers (like `ifx` on platforms other than Windows, + `gfortran`, `flang`, ...). The latter name mangling convention is also used + by default by OpenBLAS (independent on the platform or the compiler used to + build OpenBLAS). You might need to configure with + `-DSUITESPARSE_C_TO_FORTRAN="(name,NAME) name##_"` if you'd like to build + SuiteSparse using a MSVC compiler and link to OpenBLAS. + Additional options are available for specific packages: * `UMFPACK_USE_CHOLMOD`: @@ -1182,7 +1215,7 @@ Julia interface: https://github.com/JuliaSparse/SparseArrays.jl -python interface to GraphBLAS by Anaconda and NVIDIA: +Python interface to GraphBLAS by Anaconda and NVIDIA: https://pypi.org/project/python-graphblas @@ -1195,6 +1228,10 @@ See scikit-sparse and scikit-umfpack for the Python interface via SciPy: https://github.com/scikit-sparse/scikit-sparse https://github.com/scikit-umfpack/scikit-umfpack +See math.js by Jos de Jong for a JavaScript port of CSparse: + + https://github.com/josdejong/mathjs + See russell for a Rust interface: https://github.com/cpmech/russell diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/CMakeLists.txt b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/CMakeLists.txt index 8e5c119b5..f76fd0e01 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/CMakeLists.txt @@ -15,10 +15,10 @@ cmake_minimum_required ( VERSION 3.22 ) # version of both SuiteSparse and SuiteSparse_config -set ( SUITESPARSE_DATE "Jan 20, 2024" ) +set ( SUITESPARSE_DATE "Aug 20, 2024" ) set ( SUITESPARSE_VERSION_MAJOR 7 ) -set ( SUITESPARSE_VERSION_MINOR 6 ) -set ( SUITESPARSE_VERSION_SUB 0 ) +set ( SUITESPARSE_VERSION_MINOR 8 ) +set ( SUITESPARSE_VERSION_SUB 2 ) set ( SUITESPARSE_CONFIG_VERSION_MAJOR ${SUITESPARSE_VERSION_MAJOR} CACHE STRING "" FORCE ) set ( SUITESPARSE_CONFIG_VERSION_MINOR ${SUITESPARSE_VERSION_MINOR} CACHE STRING "" FORCE ) set ( SUITESPARSE_CONFIG_VERSION_PATCH ${SUITESPARSE_VERSION_SUB} CACHE STRING "" FORCE ) @@ -112,7 +112,14 @@ else ( ) endif ( ) endif ( ) -if ( NOT SUITESPARSE_CONFIG_USE_OPENMP AND NOT SUITESPARSE_HAVE_CLOCK_GETTIME ) +if ( SUITESPARSE_CONFIG_USE_OPENMP OR SUITESPARSE_HAVE_CLOCK_GETTIME ) + set ( SUITESPARSE_TIMER_ENABLED ON ) + if ( SUITESPARSE_CONFIG_USE_OPENMP ) + set ( SUITESPARSE_CONFIG_TIMER "omp_get_wtime" ) + else ( ) + set ( SUITESPARSE_CONFIG_TIMER "clock_gettime" ) + endif ( ) +else ( ) message ( STATUS "No OpenMP and no clock_gettime available. Timing functions won't work." ) endif ( ) @@ -174,7 +181,7 @@ if ( BUILD_STATIC_LIBS ) OUTPUT_NAME suitesparseconfig PUBLIC_HEADER "SuiteSparse_config.h" ) - if ( MSVC ) + if ( MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") ) set_target_properties ( SuiteSparseConfig_static PROPERTIES OUTPUT_NAME suitesparseconfig_static ) endif ( ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/README.md.in b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/README.md.in index bc0c9142f..e7be286ef 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/README.md.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/README.md.in @@ -713,9 +713,9 @@ particular BLAS library use either: cd Package ; cmake -DBLA_VENDOR=OpenBLAS .. make To use the default (hunt for a BLAS), do not set `BLA_VENDOR`, or set it to -`ANY`. In this case, if `SUITESPARSE_USE_64BIT_BLAS` is ON, preference is -given to a 64-bit BLAS, but a 32-bit BLAS library will be used if no 64-bit -library is found. However, if both `SUITESPARSE_USE_64BIT_BLAS` and +an empty string. In this case, if `SUITESPARSE_USE_64BIT_BLAS` is ON, +preference is given to a 64-bit BLAS, but a 32-bit BLAS library will be used if +no 64-bit library is found. However, if both `SUITESPARSE_USE_64BIT_BLAS` and `SUITESPARSE_USE_STRICT` are ON, then only a 64-bit BLAS is considered. When selecting a particular BLAS library, the `SUITESPARSE_USE_64BIT_BLAS` @@ -979,6 +979,12 @@ build type). The static libraries will not be built (since If `ON`, look for a 64-bit BLAS. If `OFF`: 32-bit only. Default: `OFF`. +* `SUITESPARSE_USE_PYTHON`: + + If `ON`, build Python interfaces for any package in SuiteSparse that has + one (currently only SPEX). If `OFF`: do not build any Python interface. + Default: `ON`. + * `SUITESPARSE_USE_OPENMP`: If `ON`, OpenMP is used by default if it is available. Default: `ON`. @@ -1023,6 +1029,11 @@ build type). The static libraries will not be built (since If `ON`, OpenMP is used in ParU if it is available. Default: `SUITESPARSE_USE_OPENMP`. +* `SPEX_USE_OPENMP`: + + If `ON`, OpenMP is used in SPEX if it is available. + Default: `SUITESPARSE_USE_OPENMP`. + * `SUITESPARSE_DEMOS`: If `ON`, build the demo programs for each package. Default: `OFF`. @@ -1072,10 +1083,32 @@ build type). The static libraries will not be built (since If `ON`, use the Fortran compiler to determine how C calls Fortan, and to build several optional Fortran routines. If `OFF`, use - `SUITESPARSE_C_TO_FORTRAN` to define how C calls Fortran (see - `SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake` for details). + `SUITESPARSE_C_TO_FORTRAN` to define how C calls Fortran. Default: `ON`. +* `SUITESPARSE_C_TO_FORTRAN` + + A string that defines how C calls Fortran (i.e., functions exported by the + BLAS library). This setting is used if no working Fortran compiler could be + detected or `SUITESPARSE_USE_FORTRAN` is set to `OFF`. This string is to be + read as the argument list and the body of a preprocessor macro. The first + argument to that macro is any Fortran function name in lowercase letters. + The second argument is the same function name in uppercase letters. The body + defines by which function name Fortran functions are called. This is + necessary because Fortran is case-insensitive, and different Fortran + compilers use different name mangling conventions. If a MSVC C/C++ compiler + is used, this defaults to `"(name,NAME) name"` (i.e., lower case without + trailing underscore). That is the name mangling convention for the Intel + Fortran compiler on Windows. If any other C/C++ compilers are used, this + defaults to `"(name,NAME) name##_"` (i.e., lower case with trailing + underscore). That is the name mangling convention for most of the commonly + used Fortran compilers (like `ifx` on platforms other than Windows, + `gfortran`, `flang`, ...). The latter name mangling convention is also used + by default by OpenBLAS (independent on the platform or the compiler used to + build OpenBLAS). You might need to configure with + `-DSUITESPARSE_C_TO_FORTRAN="(name,NAME) name##_"` if you'd like to build + SuiteSparse using a MSVC compiler and link to OpenBLAS. + Additional options are available for specific packages: * `UMFPACK_USE_CHOLMOD`: @@ -1182,7 +1215,7 @@ Julia interface: https://github.com/JuliaSparse/SparseArrays.jl -python interface to GraphBLAS by Anaconda and NVIDIA: +Python interface to GraphBLAS by Anaconda and NVIDIA: https://pypi.org/project/python-graphblas @@ -1195,6 +1228,10 @@ See scikit-sparse and scikit-umfpack for the Python interface via SciPy: https://github.com/scikit-sparse/scikit-sparse https://github.com/scikit-umfpack/scikit-umfpack +See math.js by Jos de Jong for a JavaScript port of CSparse: + + https://github.com/josdejong/mathjs + See russell for a Rust interface: https://github.com/cpmech/russell diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/SuiteSparse_config.h.in b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/SuiteSparse_config.h.in index 0d203f55e..d0576a22d 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/SuiteSparse_config.h.in +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/Config/SuiteSparse_config.h.in @@ -19,11 +19,6 @@ #ifndef SUITESPARSE_CONFIG_H #define SUITESPARSE_CONFIG_H -#ifdef __cplusplus -extern "C" -{ -#endif - //------------------------------------------------------------------------------ // SuiteSparse-wide ANSI C11 #include files //------------------------------------------------------------------------------ @@ -263,6 +258,11 @@ extern "C" #endif +#ifdef __cplusplus +extern "C" +{ +#endif + //============================================================================== // SuiteSparse_config parameters and functions //============================================================================== @@ -372,20 +372,34 @@ int SuiteSparse_divcomplex // but other packages can themselves use OpenMP. In this case, // those packages should use omp_get_wtime() directly. This can // be done via the SUITESPARSE_TIME macro, defined below: + #cmakedefine SUITESPARSE_TIMER_ENABLED #cmakedefine SUITESPARSE_HAVE_CLOCK_GETTIME - #if defined ( _OPENMP ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (omp_get_wtime ( )) - #elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #cmakedefine SUITESPARSE_CONFIG_TIMER @SUITESPARSE_CONFIG_TIMER@ + #if defined ( SUITESPARSE_TIMER_ENABLED ) + #if defined ( _OPENMP ) + // Avoid indirection through the library if the compilation unit + // including this header happens to use OpenMP. + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #endif #else // No timer is available #define SUITESPARSE_TIME (0) #endif #else - // The timer is explictly disabled - #define SUITESPARSE_TIME (0) + // The SuiteSparse_config timer is explictly disabled; + // use the OpenMP timer omp_get_wtime if available. + #undef SUITESPARSE_TIMER_ENABLED + #undef SUITESPARSE_HAVE_CLOCK_GETTIME + #undef SUITESPARSE_CONFIG_TIMER + #if defined ( _OPENMP ) + #define SUITESPARSE_CONFIG_TIMER omp_get_wtime + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_CONFIG_TIMER none + #define SUITESPARSE_TIME (0) + #endif #endif // SuiteSparse printf macro @@ -653,7 +667,7 @@ int SuiteSparse_version // returns SUITESPARSE_VERSION #define SUITESPARSE_LAPACK_CLARFB SUITESPARSE_BLAS ( clarfb , CLARFB ) //------------------------------------------------------------------------------ -// prototypes of BLAS and SUITESPARSE_LAPACK functions +// prototypes and macros for BLAS and SUITESPARSE_LAPACK functions //------------------------------------------------------------------------------ // For complex functions, the (void *) parameters are actually pointers to @@ -668,14 +682,26 @@ int SuiteSparse_version // returns SUITESPARSE_VERSION // library and integer size is used. However, these definitions should not // (normally) be exposed to the user application. -// If a user application wishes to use these definitions, simply add - +// If a user application wishes to use these definitions, simply add the +// following prior to #include'ing any SuiteSparse headers (amd.h, and so on): +// // #define SUITESPARSE_BLAS_DEFINITIONS // #include "SuiteSparse_config.h" -// prior to #include'ing any SuiteSparse headers (amd.h, and so on). - #if defined ( SUITESPARSE_BLAS_DEFINITIONS ) +#ifndef SUITESPARSE_BLAS_PROTOTYPES +#define SUITESPARSE_BLAS_PROTOTYPES +#endif +#ifndef SUITESPARSE_BLAS_MACROS +#define SUITESPARSE_BLAS_MACROS +#endif +#endif + +//------------------------------------------------------------------------------ +// prototypes of BLAS and SUITESPARSE_LAPACK functions +//------------------------------------------------------------------------------ + +#if defined ( SUITESPARSE_BLAS_PROTOTYPES ) //------------------------------------------------------------------------------ // gemv: Y = alpha*A*x + beta*Y @@ -699,20 +725,6 @@ void SUITESPARSE_BLAS_DGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_dgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGEMV ( // input: @@ -731,20 +743,6 @@ void SUITESPARSE_BLAS_SGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_sgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGEMV ( // input: @@ -763,20 +761,6 @@ void SUITESPARSE_BLAS_ZGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_zgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGEMV ( // input: @@ -795,20 +779,6 @@ void SUITESPARSE_BLAS_CGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_cgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // trsv: solve Lx=b, Ux=b, L'x=b, or U'x=b //------------------------------------------------------------------------------ @@ -828,18 +798,6 @@ void SUITESPARSE_BLAS_DTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dtrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_STRSV ( // input: @@ -855,18 +813,6 @@ void SUITESPARSE_BLAS_STRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_strsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_STRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZTRSV ( // input: @@ -882,18 +828,6 @@ void SUITESPARSE_BLAS_ZTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_ztrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CTRSV ( // input: @@ -909,18 +843,6 @@ void SUITESPARSE_BLAS_CTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_ctrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // trsm: solve LX=B, UX=B, L'X=B, or U'X=B //------------------------------------------------------------------------------ @@ -943,19 +865,6 @@ void SUITESPARSE_BLAS_DTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_dtrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_STRSM ( // input: @@ -974,19 +883,6 @@ void SUITESPARSE_BLAS_STRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_strsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_STRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZTRSM ( // input: @@ -1005,19 +901,6 @@ void SUITESPARSE_BLAS_ZTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_ztrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CTRSM ( // input: @@ -1036,19 +919,6 @@ void SUITESPARSE_BLAS_CTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_ctrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // gemm: C = alpha*A*B + beta*C //------------------------------------------------------------------------------ @@ -1073,23 +943,6 @@ void SUITESPARSE_BLAS_DGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_dgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGEMM ( // input: @@ -1110,23 +963,6 @@ void SUITESPARSE_BLAS_SGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_sgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGEMM ( // input: @@ -1147,23 +983,6 @@ void SUITESPARSE_BLAS_ZGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_zgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGEMM ( // input: @@ -1184,23 +1003,6 @@ void SUITESPARSE_BLAS_CGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_cgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // syrk/herk: C = alpha*A*A' + beta*C ; or C = alpha*A'*A + beta*C //------------------------------------------------------------------------------ @@ -1222,19 +1024,6 @@ void SUITESPARSE_BLAS_DSYRK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_dsyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SSYRK ( // input: @@ -1252,19 +1041,6 @@ void SUITESPARSE_BLAS_SSYRK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_ssyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZHERK ( // input: @@ -1282,19 +1058,6 @@ void SUITESPARSE_BLAS_ZHERK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_zherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CHERK ( // input: @@ -1312,19 +1075,6 @@ void SUITESPARSE_BLAS_CHERK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_cherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // potrf: Cholesky factorization //------------------------------------------------------------------------------ @@ -1342,20 +1092,6 @@ void SUITESPARSE_LAPACK_DPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_dpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_DPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = (Int) LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_SPOTRF ( // input: @@ -1369,20 +1105,6 @@ void SUITESPARSE_LAPACK_SPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_spotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_SPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = (Int) LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_ZPOTRF ( // input: @@ -1396,20 +1118,6 @@ void SUITESPARSE_LAPACK_ZPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_zpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_ZPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_CPOTRF ( // input: @@ -1423,20 +1131,6 @@ void SUITESPARSE_LAPACK_CPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_cpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_CPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = LAPACK_Info ; \ - } \ -} - //------------------------------------------------------------------------------ // scal: Y = alpha*Y //------------------------------------------------------------------------------ @@ -1452,16 +1146,6 @@ void SUITESPARSE_BLAS_DSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_dscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SSCAL ( // input: @@ -1473,16 +1157,6 @@ void SUITESPARSE_BLAS_SSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_sscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZSCAL ( // input: @@ -1494,16 +1168,6 @@ void SUITESPARSE_BLAS_ZSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_zscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CSCAL ( // input: @@ -1515,16 +1179,6 @@ void SUITESPARSE_BLAS_CSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_cscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // ger/geru: A = alpha*x*y' + A //------------------------------------------------------------------------------ @@ -1545,20 +1199,6 @@ void SUITESPARSE_BLAS_DGER const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_dger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGER (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGER ( // input: @@ -1575,20 +1215,6 @@ void SUITESPARSE_BLAS_SGER const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_sger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGER (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGERU ( // input: @@ -1605,20 +1231,6 @@ void SUITESPARSE_BLAS_ZGERU const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_zgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGERU (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGERU ( // input: @@ -1635,20 +1247,6 @@ void SUITESPARSE_BLAS_CGERU const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_cgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGERU (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larft: T = block Householder factor //------------------------------------------------------------------------------ @@ -1669,19 +1267,6 @@ void SUITESPARSE_LAPACK_DLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_dlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFT ( // input: @@ -1698,19 +1283,6 @@ void SUITESPARSE_LAPACK_SLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_slarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFT ( // input: @@ -1727,19 +1299,6 @@ void SUITESPARSE_LAPACK_ZLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_zlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFT ( // input: @@ -1756,19 +1315,6 @@ void SUITESPARSE_LAPACK_CLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_clarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larfb: apply block Householder reflector //------------------------------------------------------------------------------ @@ -1797,24 +1343,6 @@ void SUITESPARSE_LAPACK_DLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_dlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFB ( // input: @@ -1839,24 +1367,6 @@ void SUITESPARSE_LAPACK_SLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_slarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFB ( // input: @@ -1881,24 +1391,6 @@ void SUITESPARSE_LAPACK_ZLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_zlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFB ( // input: @@ -1923,24 +1415,6 @@ void SUITESPARSE_LAPACK_CLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_clarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // nrm2: vector 2-norm //------------------------------------------------------------------------------ @@ -1953,17 +1427,6 @@ double SUITESPARSE_BLAS_DNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dnrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_DNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - float SUITESPARSE_BLAS_SNRM2 ( // input: @@ -1972,17 +1435,6 @@ float SUITESPARSE_BLAS_SNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_snrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_SNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - double SUITESPARSE_BLAS_DZNRM2 ( // input: @@ -1991,17 +1443,6 @@ double SUITESPARSE_BLAS_DZNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dznrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_DZNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - float SUITESPARSE_BLAS_SCNRM2 ( // input: @@ -2010,17 +1451,6 @@ float SUITESPARSE_BLAS_SCNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_scnrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_SCNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larfg: generate Householder reflector //------------------------------------------------------------------------------ @@ -2038,17 +1468,6 @@ void SUITESPARSE_LAPACK_DLARFG double *tau ) ; -#define SUITESPARSE_LAPACK_dlarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFG ( // input: @@ -2062,17 +1481,6 @@ void SUITESPARSE_LAPACK_SLARFG float *tau ) ; -#define SUITESPARSE_LAPACK_slarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFG ( // input: @@ -2086,17 +1494,6 @@ void SUITESPARSE_LAPACK_ZLARFG void *tau ) ; -#define SUITESPARSE_LAPACK_zlarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFG ( // input: @@ -2110,17 +1507,6 @@ void SUITESPARSE_LAPACK_CLARFG void *tau ) ; -#define SUITESPARSE_LAPACK_clarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - //------------------------------------------------------------------------------ // larf: apply Householder reflector //------------------------------------------------------------------------------ @@ -2142,19 +1528,6 @@ void SUITESPARSE_LAPACK_DLARF double *Work ) ; -#define SUITESPARSE_LAPACK_dlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARF ( // input: @@ -2172,19 +1545,6 @@ void SUITESPARSE_LAPACK_SLARF float *Work ) ; -#define SUITESPARSE_LAPACK_slarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARF ( // input: @@ -2202,19 +1562,6 @@ void SUITESPARSE_LAPACK_ZLARF void *Work ) ; -#define SUITESPARSE_LAPACK_zlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARF ( // input: @@ -2232,19 +1579,705 @@ void SUITESPARSE_LAPACK_CLARF void *Work ) ; -#define SUITESPARSE_LAPACK_clarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +#endif + +//------------------------------------------------------------------------------ +// macros for BLAS and SUITESPARSE_LAPACK functions +//------------------------------------------------------------------------------ + +#if defined ( SUITESPARSE_BLAS_MACROS ) + +#define SUITESPARSE_BLAS_dgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ { \ SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ if (ok) \ { \ - SUITESPARSE_LAPACK_CLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + SUITESPARSE_BLAS_DGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ } \ } +#define SUITESPARSE_BLAS_cgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dtrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_strsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_STRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ztrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ctrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dtrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_strsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_STRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ztrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ctrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dsyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ssyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_DPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = (Int) LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_spotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_SPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = (Int) LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_ZPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_cpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_CPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_BLAS_dscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DGER (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGER (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGERU (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGERU (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dnrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_DNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_snrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_SNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dznrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_DZNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_scnrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_SCNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} #endif //------------------------------------------------------------------------------ diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/SuiteSparse_config.h b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/SuiteSparse_config.h index d2300dcfc..8e532262c 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/SuiteSparse_config.h +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/SuiteSparse_config.h @@ -19,11 +19,6 @@ #ifndef SUITESPARSE_CONFIG_H #define SUITESPARSE_CONFIG_H -#ifdef __cplusplus -extern "C" -{ -#endif - //------------------------------------------------------------------------------ // SuiteSparse-wide ANSI C11 #include files //------------------------------------------------------------------------------ @@ -263,6 +258,11 @@ extern "C" #endif +#ifdef __cplusplus +extern "C" +{ +#endif + //============================================================================== // SuiteSparse_config parameters and functions //============================================================================== @@ -372,20 +372,34 @@ int SuiteSparse_divcomplex // but other packages can themselves use OpenMP. In this case, // those packages should use omp_get_wtime() directly. This can // be done via the SUITESPARSE_TIME macro, defined below: + #define SUITESPARSE_TIMER_ENABLED #define SUITESPARSE_HAVE_CLOCK_GETTIME - #if defined ( _OPENMP ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (omp_get_wtime ( )) - #elif defined ( SUITESPARSE_HAVE_CLOCK_GETTIME ) - #define SUITESPARSE_TIMER_ENABLED - #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #define SUITESPARSE_CONFIG_TIMER clock_gettime + #if defined ( SUITESPARSE_TIMER_ENABLED ) + #if defined ( _OPENMP ) + // Avoid indirection through the library if the compilation unit + // including this header happens to use OpenMP. + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_TIME (SuiteSparse_time ( )) + #endif #else // No timer is available #define SUITESPARSE_TIME (0) #endif #else - // The timer is explictly disabled - #define SUITESPARSE_TIME (0) + // The SuiteSparse_config timer is explictly disabled; + // use the OpenMP timer omp_get_wtime if available. + #undef SUITESPARSE_TIMER_ENABLED + #undef SUITESPARSE_HAVE_CLOCK_GETTIME + #undef SUITESPARSE_CONFIG_TIMER + #if defined ( _OPENMP ) + #define SUITESPARSE_CONFIG_TIMER omp_get_wtime + #define SUITESPARSE_TIME (omp_get_wtime ( )) + #else + #define SUITESPARSE_CONFIG_TIMER none + #define SUITESPARSE_TIME (0) + #endif #endif // SuiteSparse printf macro @@ -420,19 +434,19 @@ int SuiteSparse_version // returns SUITESPARSE_VERSION #define SUITESPARSE_HAS_VERSION_FUNCTION -#define SUITESPARSE_DATE "Jan 20, 2024" +#define SUITESPARSE_DATE "Aug 20, 2024" #define SUITESPARSE_MAIN_VERSION 7 -#define SUITESPARSE_SUB_VERSION 6 -#define SUITESPARSE_SUBSUB_VERSION 0 +#define SUITESPARSE_SUB_VERSION 8 +#define SUITESPARSE_SUBSUB_VERSION 2 // version format x.y #define SUITESPARSE_VER_CODE(main,sub) ((main) * 1000 + (sub)) -#define SUITESPARSE_VERSION SUITESPARSE_VER_CODE(7, 6) +#define SUITESPARSE_VERSION SUITESPARSE_VER_CODE(7, 8) // version format x.y.z #define SUITESPARSE__VERCODE(main,sub,patch) \ (((main)*1000ULL + (sub))*1000ULL + (patch)) -#define SUITESPARSE__VERSION SUITESPARSE__VERCODE(7,6,0) +#define SUITESPARSE__VERSION SUITESPARSE__VERCODE(7,8,2) //============================================================================== // SuiteSparse interface to the BLAS and LAPACK libraries @@ -653,7 +667,7 @@ int SuiteSparse_version // returns SUITESPARSE_VERSION #define SUITESPARSE_LAPACK_CLARFB SUITESPARSE_BLAS ( clarfb , CLARFB ) //------------------------------------------------------------------------------ -// prototypes of BLAS and SUITESPARSE_LAPACK functions +// prototypes and macros for BLAS and SUITESPARSE_LAPACK functions //------------------------------------------------------------------------------ // For complex functions, the (void *) parameters are actually pointers to @@ -668,14 +682,26 @@ int SuiteSparse_version // returns SUITESPARSE_VERSION // library and integer size is used. However, these definitions should not // (normally) be exposed to the user application. -// If a user application wishes to use these definitions, simply add - +// If a user application wishes to use these definitions, simply add the +// following prior to #include'ing any SuiteSparse headers (amd.h, and so on): +// // #define SUITESPARSE_BLAS_DEFINITIONS // #include "SuiteSparse_config.h" -// prior to #include'ing any SuiteSparse headers (amd.h, and so on). - #if defined ( SUITESPARSE_BLAS_DEFINITIONS ) +#ifndef SUITESPARSE_BLAS_PROTOTYPES +#define SUITESPARSE_BLAS_PROTOTYPES +#endif +#ifndef SUITESPARSE_BLAS_MACROS +#define SUITESPARSE_BLAS_MACROS +#endif +#endif + +//------------------------------------------------------------------------------ +// prototypes of BLAS and SUITESPARSE_LAPACK functions +//------------------------------------------------------------------------------ + +#if defined ( SUITESPARSE_BLAS_PROTOTYPES ) //------------------------------------------------------------------------------ // gemv: Y = alpha*A*x + beta*Y @@ -699,20 +725,6 @@ void SUITESPARSE_BLAS_DGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_dgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGEMV ( // input: @@ -731,20 +743,6 @@ void SUITESPARSE_BLAS_SGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_sgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGEMV ( // input: @@ -763,20 +761,6 @@ void SUITESPARSE_BLAS_ZGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_zgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGEMV ( // input: @@ -795,20 +779,6 @@ void SUITESPARSE_BLAS_CGEMV const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_cgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ - &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // trsv: solve Lx=b, Ux=b, L'x=b, or U'x=b //------------------------------------------------------------------------------ @@ -828,18 +798,6 @@ void SUITESPARSE_BLAS_DTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dtrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_STRSV ( // input: @@ -855,18 +813,6 @@ void SUITESPARSE_BLAS_STRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_strsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_STRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZTRSV ( // input: @@ -882,18 +828,6 @@ void SUITESPARSE_BLAS_ZTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_ztrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CTRSV ( // input: @@ -909,18 +843,6 @@ void SUITESPARSE_BLAS_CTRSV const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_ctrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CTRSV (uplo, trans, diag, &N_blas_int, A, \ - &LDA_blas_int, X, &INCX_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // trsm: solve LX=B, UX=B, L'X=B, or U'X=B //------------------------------------------------------------------------------ @@ -943,19 +865,6 @@ void SUITESPARSE_BLAS_DTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_dtrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_STRSM ( // input: @@ -974,19 +883,6 @@ void SUITESPARSE_BLAS_STRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_strsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_STRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZTRSM ( // input: @@ -1005,19 +901,6 @@ void SUITESPARSE_BLAS_ZTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_ztrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CTRSM ( // input: @@ -1036,19 +919,6 @@ void SUITESPARSE_BLAS_CTRSM const SUITESPARSE_BLAS_INT *ldb ) ; -#define SUITESPARSE_BLAS_ctrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CTRSM (side, uplo, transa, diag, &M_blas_int, \ - &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // gemm: C = alpha*A*B + beta*C //------------------------------------------------------------------------------ @@ -1073,23 +943,6 @@ void SUITESPARSE_BLAS_DGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_dgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGEMM ( // input: @@ -1110,23 +963,6 @@ void SUITESPARSE_BLAS_SGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_sgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGEMM ( // input: @@ -1147,23 +983,6 @@ void SUITESPARSE_BLAS_ZGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_zgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGEMM ( // input: @@ -1184,23 +1003,6 @@ void SUITESPARSE_BLAS_CGEMM const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_cgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ - C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGEMM (transa, transb, &M_blas_int, &N_blas_int, \ - &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ - &LDC_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // syrk/herk: C = alpha*A*A' + beta*C ; or C = alpha*A'*A + beta*C //------------------------------------------------------------------------------ @@ -1222,19 +1024,6 @@ void SUITESPARSE_BLAS_DSYRK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_dsyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SSYRK ( // input: @@ -1252,19 +1041,6 @@ void SUITESPARSE_BLAS_SSYRK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_ssyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZHERK ( // input: @@ -1282,19 +1058,6 @@ void SUITESPARSE_BLAS_ZHERK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_zherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CHERK ( // input: @@ -1312,19 +1075,6 @@ void SUITESPARSE_BLAS_CHERK const SUITESPARSE_BLAS_INT *ldc ) ; -#define SUITESPARSE_BLAS_cherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ - A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // potrf: Cholesky factorization //------------------------------------------------------------------------------ @@ -1342,20 +1092,6 @@ void SUITESPARSE_LAPACK_DPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_dpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_DPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = (Int) LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_SPOTRF ( // input: @@ -1369,20 +1105,6 @@ void SUITESPARSE_LAPACK_SPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_spotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_SPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = (Int) LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_ZPOTRF ( // input: @@ -1396,20 +1118,6 @@ void SUITESPARSE_LAPACK_ZPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_zpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_ZPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = LAPACK_Info ; \ - } \ -} - void SUITESPARSE_LAPACK_CPOTRF ( // input: @@ -1423,20 +1131,6 @@ void SUITESPARSE_LAPACK_CPOTRF SUITESPARSE_BLAS_INT *info ) ; -#define SUITESPARSE_LAPACK_cpotrf(uplo,n,A,lda,info,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - info = 1 ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ - SUITESPARSE_LAPACK_CPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ - &LAPACK_Info) ; \ - info = LAPACK_Info ; \ - } \ -} - //------------------------------------------------------------------------------ // scal: Y = alpha*Y //------------------------------------------------------------------------------ @@ -1452,16 +1146,6 @@ void SUITESPARSE_BLAS_DSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_dscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SSCAL ( // input: @@ -1473,16 +1157,6 @@ void SUITESPARSE_BLAS_SSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_sscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZSCAL ( // input: @@ -1494,16 +1168,6 @@ void SUITESPARSE_BLAS_ZSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_zscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CSCAL ( // input: @@ -1515,16 +1179,6 @@ void SUITESPARSE_BLAS_CSCAL const SUITESPARSE_BLAS_INT *incy ) ; -#define SUITESPARSE_BLAS_cscal(n,alpha,Y,incy,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // ger/geru: A = alpha*x*y' + A //------------------------------------------------------------------------------ @@ -1545,20 +1199,6 @@ void SUITESPARSE_BLAS_DGER const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_dger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_DGER (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_SGER ( // input: @@ -1575,20 +1215,6 @@ void SUITESPARSE_BLAS_SGER const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_sger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_SGER (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_ZGERU ( // input: @@ -1605,20 +1231,6 @@ void SUITESPARSE_BLAS_ZGERU const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_zgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_ZGERU (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - void SUITESPARSE_BLAS_CGERU ( // input: @@ -1635,20 +1247,6 @@ void SUITESPARSE_BLAS_CGERU const SUITESPARSE_BLAS_INT *lda ) ; -#define SUITESPARSE_BLAS_cgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_BLAS_CGERU (&M_blas_int, &N_blas_int, alpha, X, \ - &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larft: T = block Householder factor //------------------------------------------------------------------------------ @@ -1669,19 +1267,6 @@ void SUITESPARSE_LAPACK_DLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_dlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFT ( // input: @@ -1698,19 +1283,6 @@ void SUITESPARSE_LAPACK_SLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_slarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFT ( // input: @@ -1727,19 +1299,6 @@ void SUITESPARSE_LAPACK_ZLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_zlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFT ( // input: @@ -1756,19 +1315,6 @@ void SUITESPARSE_LAPACK_CLARFT const SUITESPARSE_BLAS_INT *ldt ) ; -#define SUITESPARSE_LAPACK_clarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFT (direct, storev, &N_blas_int, &K_blas_int, \ - V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larfb: apply block Householder reflector //------------------------------------------------------------------------------ @@ -1797,24 +1343,6 @@ void SUITESPARSE_LAPACK_DLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_dlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFB ( // input: @@ -1839,24 +1367,6 @@ void SUITESPARSE_LAPACK_SLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_slarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFB ( // input: @@ -1881,24 +1391,6 @@ void SUITESPARSE_LAPACK_ZLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_zlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFB ( // input: @@ -1923,24 +1415,6 @@ void SUITESPARSE_LAPACK_CLARFB const SUITESPARSE_BLAS_INT *ldwork ) ; -#define SUITESPARSE_LAPACK_clarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ - C,ldc,Work,ldwork,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFB (side, trans, direct, storev, &M_blas_int, \ - &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ - &LDC_blas_int, Work, &LDWORK_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // nrm2: vector 2-norm //------------------------------------------------------------------------------ @@ -1953,17 +1427,6 @@ double SUITESPARSE_BLAS_DNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dnrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_DNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - float SUITESPARSE_BLAS_SNRM2 ( // input: @@ -1972,17 +1435,6 @@ float SUITESPARSE_BLAS_SNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_snrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_SNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - double SUITESPARSE_BLAS_DZNRM2 ( // input: @@ -1991,17 +1443,6 @@ double SUITESPARSE_BLAS_DZNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_dznrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_DZNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - float SUITESPARSE_BLAS_SCNRM2 ( // input: @@ -2010,17 +1451,6 @@ float SUITESPARSE_BLAS_SCNRM2 const SUITESPARSE_BLAS_INT *incx ) ; -#define SUITESPARSE_BLAS_scnrm2(result,n,X,incx,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - result = 0 ; \ - if (ok) \ - { \ - result = SUITESPARSE_BLAS_SCNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ - } \ -} - //------------------------------------------------------------------------------ // larfg: generate Householder reflector //------------------------------------------------------------------------------ @@ -2038,17 +1468,6 @@ void SUITESPARSE_LAPACK_DLARFG double *tau ) ; -#define SUITESPARSE_LAPACK_dlarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARFG ( // input: @@ -2062,17 +1481,6 @@ void SUITESPARSE_LAPACK_SLARFG float *tau ) ; -#define SUITESPARSE_LAPACK_slarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARFG ( // input: @@ -2086,17 +1494,6 @@ void SUITESPARSE_LAPACK_ZLARFG void *tau ) ; -#define SUITESPARSE_LAPACK_zlarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARFG ( // input: @@ -2110,17 +1507,6 @@ void SUITESPARSE_LAPACK_CLARFG void *tau ) ; -#define SUITESPARSE_LAPACK_clarfg(n,alpha,X,incx,tau,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_CLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ - tau) ; \ - } \ -} - //------------------------------------------------------------------------------ // larf: apply Householder reflector //------------------------------------------------------------------------------ @@ -2142,19 +1528,6 @@ void SUITESPARSE_LAPACK_DLARF double *Work ) ; -#define SUITESPARSE_LAPACK_dlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_DLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_SLARF ( // input: @@ -2172,19 +1545,6 @@ void SUITESPARSE_LAPACK_SLARF float *Work ) ; -#define SUITESPARSE_LAPACK_slarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_SLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_ZLARF ( // input: @@ -2202,19 +1562,6 @@ void SUITESPARSE_LAPACK_ZLARF void *Work ) ; -#define SUITESPARSE_LAPACK_zlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ -{ \ - SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ - SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ - if (ok) \ - { \ - SUITESPARSE_LAPACK_ZLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ - } \ -} - void SUITESPARSE_LAPACK_CLARF ( // input: @@ -2232,19 +1579,705 @@ void SUITESPARSE_LAPACK_CLARF void *Work ) ; -#define SUITESPARSE_LAPACK_clarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +#endif + +//------------------------------------------------------------------------------ +// macros for BLAS and SUITESPARSE_LAPACK functions +//------------------------------------------------------------------------------ + +#if defined ( SUITESPARSE_BLAS_MACROS ) + +#define SUITESPARSE_BLAS_dgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ { \ SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ - SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ - SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ if (ok) \ { \ - SUITESPARSE_LAPACK_CLARF (side, &M_blas_int, &N_blas_int, V, \ - &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + SUITESPARSE_BLAS_DGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ } \ } +#define SUITESPARSE_BLAS_cgemv(trans,m,n,alpha,A,lda,X,incx,beta,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGEMV (trans, &M_blas_int, &N_blas_int, alpha, A, \ + &LDA_blas_int, X, &INCX_blas_int, beta, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dtrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_strsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_STRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ztrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ctrsv(uplo,trans,diag,n,A,lda,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CTRSV (uplo, trans, diag, &N_blas_int, A, \ + &LDA_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dtrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_strsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_STRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ztrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ctrsm(side,uplo,transa,diag,m,n,alpha,A,lda,B,ldb,ok)\ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CTRSM (side, uplo, transa, diag, &M_blas_int, \ + &N_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cgemm(transa,transb,m,n,k,alpha,A,lda,B,ldb,beta, \ + C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDB_blas_int, ldb, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGEMM (transa, transb, &M_blas_int, &N_blas_int, \ + &K_blas_int, alpha, A, &LDA_blas_int, B, &LDB_blas_int, beta, C, \ + &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dsyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_ssyrk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SSYRK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cherk(uplo,trans,n,k,alpha,A,lda,beta,C,ldc,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CHERK (uplo, trans, &N_blas_int, &K_blas_int, alpha, \ + A, &LDA_blas_int, beta, C, &LDC_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_DPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = (Int) LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_spotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_SPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = (Int) LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_ZPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_LAPACK_cpotrf(uplo,n,A,lda,info,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + info = 1 ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_INT LAPACK_Info = -999 ; \ + SUITESPARSE_LAPACK_CPOTRF (uplo, &N_blas_int, A, &LDA_blas_int, \ + &LAPACK_Info) ; \ + info = LAPACK_Info ; \ + } \ +} + +#define SUITESPARSE_BLAS_dscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cscal(n,alpha,Y,incy,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CSCAL (&N_blas_int, alpha, Y, &INCY_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_DGER (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_sger(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_SGER (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_zgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_ZGERU (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_cgeru(m,n,alpha,X,incx,Y,incy,A,lda,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCY_blas_int, incy, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDA_blas_int, lda, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_BLAS_CGERU (&M_blas_int, &N_blas_int, alpha, X, \ + &INCX_blas_int, Y, &INCY_blas_int, A, &LDA_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarft(direct,storev,n,k,V,ldv,Tau,T,ldt,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFT (direct, storev, &N_blas_int, &K_blas_int, \ + V, &LDV_blas_int, Tau, T, &LDT_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarfb(side,trans,direct,storev,m,n,k,V,ldv,T,ldt, \ + C,ldc,Work,ldwork,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (K_blas_int, k, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDV_blas_int, ldv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDT_blas_int, ldt, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDWORK_blas_int, ldwork, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFB (side, trans, direct, storev, &M_blas_int, \ + &N_blas_int, &K_blas_int, V, &LDV_blas_int, T, &LDT_blas_int, C, \ + &LDC_blas_int, Work, &LDWORK_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dnrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_DNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_snrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_SNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_dznrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_DZNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_BLAS_scnrm2(result,n,X,incx,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + result = 0 ; \ + if (ok) \ + { \ + result = SUITESPARSE_BLAS_SCNRM2 (&N_blas_int, X, &INCX_blas_int) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarfg(n,alpha,X,incx,tau,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCX_blas_int, incx, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARFG (&N_blas_int, alpha, X, &INCX_blas_int, \ + tau) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_dlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_DLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_slarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_SLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_zlarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_ZLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} + +#define SUITESPARSE_LAPACK_clarf(side,m,n,V,incv,tau,C,ldc,Work,ok) \ +{ \ + SUITESPARSE_TO_BLAS_INT (M_blas_int, m, ok) ; \ + SUITESPARSE_TO_BLAS_INT (N_blas_int, n, ok) ; \ + SUITESPARSE_TO_BLAS_INT (INCV_blas_int, incv, ok) ; \ + SUITESPARSE_TO_BLAS_INT (LDC_blas_int, ldc, ok) ; \ + if (ok) \ + { \ + SUITESPARSE_LAPACK_CLARF (side, &M_blas_int, &N_blas_int, V, \ + &INCV_blas_int, tau, C, &LDC_blas_int, Work) ; \ + } \ +} #endif //------------------------------------------------------------------------------ diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake index 2225f5373..327dfdf79 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparseBLAS.cmake @@ -21,8 +21,6 @@ cmake_minimum_required ( VERSION 3.22 ) if ( DEFINED ENV{BLA_VENDOR} ) set ( BLA_VENDOR $ENV{BLA_VENDOR} ) endif ( ) -set ( BLA_VENDOR "ANY" CACHE STRING - "if ANY (default): searches for any BLAS. Otherwise: search for a specific BLAS" ) # To allow the use of a BLAS with 64-bit integers, set this to ON option ( SUITESPARSE_USE_64BIT_BLAS @@ -33,9 +31,6 @@ option ( BLA_STATIC "OFF (default): dynamic linking of BLAS. ON: static linking of BLAS" OFF ) if ( DEFINED BLAS_LIBRARIES OR DEFINED BLAS_INCLUDE_DIRS ) - # AMICI -- silence cmake "Manually-specified variables were not used by the project" - set(amici_ignore "${BLAS_LIBRARIES} ${BLAS_INCLUDE_DIRS}") - # User supplied variables for libraries and/or include directories. # Use them as-is. if ( SUITESPARSE_USE_64BIT_BLAS ) @@ -53,7 +48,7 @@ endif ( ) # To request specific BLAS, use either (for example): # # CMAKE_OPTIONS="-DBLA_VENDOR=Apple" make -# cd build && cmake -DBLA_VENDOR=Apple .. ; make +# cd build && cmake -DBLA_VENDOR=Apple .. ; cmake --build . # # Use SUITESPARSE_USE_64BIT_BLAS to select 64-bit or 32-bit BLAS. If # BLA_VENDOR is also defined, this setting is strictly enforced. If set to @@ -66,7 +61,7 @@ endif ( ) # # The default for SUITESPARSE_USE_64BIT_BLAS is OFF. -if ( NOT (BLA_VENDOR STREQUAL "ANY" ) ) +if ( NOT ( "${BLA_VENDOR} " STREQUAL " " ) ) # only look for the BLAS from a single vendor if ( ( BLA_VENDOR MATCHES "64ilp" ) OR ( BLA_VENDOR MATCHES "ilp64" ) ) diff --git a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake index b6b195407..26f22bb60 100644 --- a/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake +++ b/deps/AMICI/ThirdParty/SuiteSparse/SuiteSparse_config/cmake_modules/SuiteSparsePolicy.cmake @@ -132,6 +132,10 @@ set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} # Use OpenMP option ( SUITESPARSE_USE_OPENMP "ON (default): Use OpenMP in libraries by default if available. OFF: Do not use OpenMP by default." ON ) +# control the use of Python interfaces in SuiteSparse packages (currently only +# for SPEX) +option ( SUITESPARSE_USE_PYTHON "ON (default): build Python interfaces for SuiteSparse packages (SPEX). OFF: do not build Python interfaces for SuiteSparse packages" ON ) + # strict usage option ( SUITESPARSE_USE_STRICT "ON: treat all _USE__ settings as strict if they are ON. OFF (default): consider *_USE_* as preferences, not strict" OFF ) diff --git a/deps/AMICI/ThirdParty/sundials/CITATIONS.md b/deps/AMICI/ThirdParty/sundials/CITATIONS.md new file mode 100644 index 000000000..9e93aa7ce --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/CITATIONS.md @@ -0,0 +1,119 @@ +# Citing SUNDIALS + +We ask users of SUNDIALS to cite the following papers in any publications +reporting work done with SUNDIALS: + +```bibtex +@article{gardner2022sundials, + title = {Enabling new flexibility in the {SUNDIALS} suite of nonlinear and differential/algebraic equation solvers}, + author = {Gardner, David J and Reynolds, Daniel R and Woodward, Carol S and Balos, Cody J}, + journal = {ACM Transactions on Mathematical Software (TOMS)}, + publisher = {ACM}, + volume = {48}, + number = {3}, + pages = {1--24}, + year = {2022}, + doi = {10.1145/3539801} +} +``` + +```bibtex +@article{hindmarsh2005sundials, + title = {{SUNDIALS}: Suite of nonlinear and differential/algebraic equation solvers}, + author = {Hindmarsh, Alan C and Brown, Peter N and Grant, Keith E and Lee, Steven L and Serban, Radu and Shumaker, Dan E and Woodward, Carol S}, + journal = {ACM Transactions on Mathematical Software (TOMS)}, + publisher = {ACM}, + volume = {31}, + number = {3}, + pages = {363--396}, + year = {2005}, + doi = {10.1145/1089014.1089020} +} +``` + +If any GPU features of SUNDIALS were utilized, please also cite: + +```bibtex +@article{balos2021enabling, + title = {{Enabling GPU accelerated computing in the SUNDIALS time integration library}}, + author = {Balos, Cody J and Gardner, David J and Woodward, Carol S and Reynolds, Daniel R}, + journal = {Parallel Computing}, + publisher = {Elsevier}, + volume = {108}, + pages = {102836}, + year = {2021}, + doi = {10.1016/j.parco.2021.102836} +} +``` + +When using the ARKODE package from SUNDIALS, please also cite: + +```bibtex +@article{reynolds2023arkode, + title = {{ARKODE: A flexible IVP solver infrastructure for one-step methods}}, + author = {Reynolds, Daniel R and Gardner, David J and Woodward, Carol S and Chinomona, Rujeko}, + journal = {ACM Transactions on Mathematical Software}, + volume = {49}, + number = {2}, + pages = {1--26}, + year = {2023}, + doi = {10.1145/3594632} +} +``` + +We also ask that users cite the documentation for the package and version that +they are using rather than the combined SUNDIALS online guide: + +```bibtex +@Misc{arkodeDocumentation, + author = {Daniel R. Reynolds and David J. Gardner and Carol S. Woodward and Cody J. Balos}, + title = {User Documentation for ARKODE}, + year = {2024}, + note = {v6.1.1} +} +``` + +```bibtex +@Misc{cvodeDocumentation, + author = {Alan C. Hindmarsh and Radu Serban and Cody J. Balos and David J. Gardner and Daniel R. Reynolds and Carol S. Woodward}, + title = {User Documentation for CVODE}, + year = {2024}, + note = {v7.1.1} +} +``` + +```bibtex +@Misc{cvodesDocumentation, + author = {Alan C. Hindmarsh and Radu Serban and Cody J. Balos and David J. Gardner and Daniel R. Reynolds and Carol S. Woodward}, + title = {User Documentation for CVODES}, + year = {2024}, + note = {v7.1.1} +} +``` + +```bibtex +@Misc{idaDocumentation, + author = {Alan C. Hindmarsh and Radu Serban and Cody J. Balos and David J. Gardner and Daniel R. Reynolds and Carol S. Woodward}, + title = {User Documentation for IDA}, + year = {2024}, + note = {v7.1.1} +} +``` + +```bibtex +@Misc{idasDocumentation, + author = {Radu Serban and Cosmin Petra and Alan C. Hindmarsh and Cody J. Balos and David J. Gardner and Daniel R. Reynolds and Carol S. Woodward}, + title = {User Documentation for IDAS}, + year = {2024}, + note = {v6.1.1} +} +``` + +```bibtex +@Misc{kinsolDocumentation, + author = {Alan C. Hindmarsh and Radu Serban and Cody J. Balos and David J. Gardner and Daniel R. Reynolds and Carol S. Woodward}, + title = {User Documentation for KINSOL}, + year = {2024}, + note = {v7.1.1} +} +``` diff --git a/deps/AMICI/ThirdParty/sundials/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/CMakeLists.txt index e23332cf3..b5cca95af 100644 --- a/deps/AMICI/ThirdParty/sundials/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/CMakeLists.txt @@ -3,7 +3,7 @@ # and Slaven Peles @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -19,7 +19,12 @@ # Initial setup. # =============================================================== -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.18) + +# Address DOWNLOAD_EXTRACT_TIMESTAMP warning with CMake 3.24+ +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + cmake_policy(SET CMP0135 NEW) +endif() # Project SUNDIALS (initially only C supported) # sets PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR variables. @@ -27,20 +32,23 @@ project(SUNDIALS C) # Specify the location of additional CMAKE modules set(CMAKE_MODULE_PATH - "${PROJECT_SOURCE_DIR}/cmake" - "${PROJECT_SOURCE_DIR}/cmake/macros" - "${PROJECT_SOURCE_DIR}/cmake/tpl" + ${CMAKE_MODULE_PATH} + ${PROJECT_SOURCE_DIR}/cmake + ${PROJECT_SOURCE_DIR}/cmake/macros + ${PROJECT_SOURCE_DIR}/cmake/tpl ) # MACRO definitions include(SundialsCMakeMacros) -include(FindPackageHandleStandardArgs) include(CMakePrintHelpers) +include(CheckCSourceCompiles) +include(FindPackageHandleStandardArgs) + # Set some variables with info on the SUNDIALS project set(PACKAGE_BUGREPORT "sundials-users@llnl.gov") set(PACKAGE_NAME "SUNDIALS") -set(PACKAGE_STRING "SUNDIALS 5.8.0") +set(PACKAGE_STRING "SUNDIALS 7.1.1") set(PACKAGE_TARNAME "sundials") # Set SUNDIALS version numbers @@ -48,9 +56,9 @@ sundials_git_version() # sets SUNDIALS_GIT_VERSION message(STATUS "SUNDIALS_GIT_VERSION: ${SUNDIALS_GIT_VERSION}") # (use "" for the version label if none is needed) -set(PACKAGE_VERSION_MAJOR "5") -set(PACKAGE_VERSION_MINOR "8") -set(PACKAGE_VERSION_PATCH "0") +set(PACKAGE_VERSION_MAJOR "7") +set(PACKAGE_VERSION_MINOR "1") +set(PACKAGE_VERSION_PATCH "1") set(PACKAGE_VERSION_LABEL "") if(PACKAGE_VERSION_LABEL) @@ -65,38 +73,38 @@ endif() # Specify the VERSION and SOVERSION for shared libraries -set(arkodelib_VERSION "4.8.0") -set(arkodelib_SOVERSION "4") +set(arkodelib_VERSION "6.1.1") +set(arkodelib_SOVERSION "6") -set(cvodelib_VERSION "5.8.0") -set(cvodelib_SOVERSION "5") +set(cvodelib_VERSION "7.1.1") +set(cvodelib_SOVERSION "7") -set(cvodeslib_VERSION "5.8.0") -set(cvodeslib_SOVERSION "5") +set(cvodeslib_VERSION "7.1.1") +set(cvodeslib_SOVERSION "7") -set(idalib_VERSION "5.8.0") -set(idalib_SOVERSION "5") +set(idalib_VERSION "7.1.1") +set(idalib_SOVERSION "7") -set(idaslib_VERSION "4.8.0") -set(idaslib_SOVERSION "4") +set(idaslib_VERSION "6.1.1") +set(idaslib_SOVERSION "6") -set(kinsollib_VERSION "5.8.0") -set(kinsollib_SOVERSION "5") +set(kinsollib_VERSION "7.1.1") +set(kinsollib_SOVERSION "7") set(cpodeslib_VERSION "0.0.0") set(cpodeslib_SOVERSION "0") -set(nveclib_VERSION "5.8.0") -set(nveclib_SOVERSION "5") +set(nveclib_VERSION "7.1.1") +set(nveclib_SOVERSION "7") -set(sunmatrixlib_VERSION "3.8.0") -set(sunmatrixlib_SOVERSION "3") +set(sunmatrixlib_VERSION "5.1.1") +set(sunmatrixlib_SOVERSION "5") -set(sunlinsollib_VERSION "3.8.0") -set(sunlinsollib_SOVERSION "3") +set(sunlinsollib_VERSION "5.1.1") +set(sunlinsollib_SOVERSION "5") -set(sunnonlinsollib_VERSION "2.8.0") -set(sunnonlinsollib_SOVERSION "2") +set(sunnonlinsollib_VERSION "4.1.1") +set(sunnonlinsollib_SOVERSION "4") set(sundialslib_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}" @@ -109,7 +117,7 @@ set(sundialslib_SOVERSION "${PACKAGE_VERSION_MAJOR}") # Prohibit in-source build if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - print_error("In-source build prohibited.") + message(FATAL_ERROR "In-source build prohibited.") endif() # Organize targets into folders when using an IDE @@ -136,6 +144,16 @@ set(_SHARED_LIB_SUFFIX set(_SUNDIALS_ALIAS_TARGETS "" CACHE INTERNAL "" FORCE) +# We default to release builds +set(_DEFAULT_CMAKE_BUILD_TYPE RelWithDebInfo) +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Building SUNDIALS in '${_DEFAULT_CMAKE_BUILD_TYPE}' mode as CMAKE_BUILD_TYPE was not specified.") + set(CMAKE_BUILD_TYPE "${_DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +else() + message(STATUS "Building SUNDIALS in '${CMAKE_BUILD_TYPE}' mode.") +endif() + # =============================================================== # Build options to be processed first # =============================================================== @@ -193,6 +211,20 @@ if(_BUILD_EXAMPLES) add_subdirectory(examples) endif() +# Add benchmarks to the build +if(BUILD_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + +# Add unit tests to the build if they are enabled +if(SUNDIALS_TEST_UNITTESTS) + add_subdirectory(test/unit_tests) +endif() + +if(SUNDIALS_ENABLE_EXTERNAL_ADDONS) + add_subdirectory(external) +endif() + # =============================================================== # Install configuration header files and license file. # =============================================================== @@ -207,11 +239,6 @@ install(FILES "${PROJECT_BINARY_DIR}/include/sundials/sundials_config.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sundials" ) -# install configured header file for Fortran 90 -install(FILES "${PROJECT_BINARY_DIR}/include/sundials/sundials_fconfig.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sundials" -) - # install shared Fortran 2003 modules if(BUILD_FORTRAN_MODULE_INTERFACE) # While the .mod files get generated for static and shared @@ -241,7 +268,7 @@ include(CMakePackageConfigHelpers) write_basic_package_version_file( SUNDIALSConfigVersion.cmake VERSION ${PACKAGE_VERSION} - COMPATIBILITY SameMajorVersion + COMPATIBILITY AnyNewerVersion ) # install targets @@ -262,3 +289,10 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SUNDIALSConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/SUNDIALSConfigVersion.cmake" DESTINATION "${SUNDIALS_INSTALL_CMAKEDIR}" ) + +# Export targets so build directory can be used directly +export( + EXPORT sundials-targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/SUNDIALSTargets.cmake" + NAMESPACE SUNDIALS:: +) diff --git a/deps/AMICI/ThirdParty/sundials/CONTRIBUTING.md b/deps/AMICI/ThirdParty/sundials/CONTRIBUTING.md deleted file mode 100644 index 9ea2f6f9c..000000000 --- a/deps/AMICI/ThirdParty/sundials/CONTRIBUTING.md +++ /dev/null @@ -1,91 +0,0 @@ -# Contributing to SUNDIALS - -At this time, the SUNDIALS team does not have the resources to review and take -in large additions to the code or significant new features. Contributions -addressing bug fixes or minor changes are preferred via a pull request to the -[SUNDIALS GitHub repository](https://github.com/LLNL/sundials). - -All new contributions to SUNDIALS must be made under the BSD 3-clause license. -See the [LICENSE](./LICENSE) and [NOTICE](./NOTICE) files for details. The -SUNDIALS team will not accept any file previously released under any other open -source license. By submitting code, the contributor gives irreversible consent -to the redistribution and/or modification of the contributed source code. - -Please ensure that any pull request includes user guide additions or changes as -appropriate, has been tested, and includes a test for any added features. - -Any added files submitted with a pull request must contain a header section at -the top including the originating author's name and file origin date as well as -a pointer to the SUNDIALS LICENSE and NOTICE files. - -The act of submitting a pull request (with or without an explicit Signed-off-by -tag) will be understood as an affirmation of the following [Developer's -Certificate of Origin (DCO)](http://developercertificate.org/). - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -1 Letterman Drive -Suite D4700 -San Francisco, CA, 94129 - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -As discussed in the [Docker software project blog](https://blog.docker.com/2014/01/docker-code-contributions-require-developer-certificate-of-origin/) -this DCO "lets us know that you are entitled to contribute this code to -[SUNDIALS] and that you are willing to have it used in distributions and -derivative works." - -"By including the DCO signature, you are stating that one or -more of the following is true of your contribution: - -1. You created this contribution/change and have the right to submit it - to SUNDIALS; or -2. You created this contribution/change based on a previous work with a - compatible open source license; or -3. This contribution/change has been provided to you by someone who did - 1 or 2 and you are submitting the contribution unchanged. -4. You understand this contribution is public and may be redistributed as - open source software" under the BSD license. - -All commits submitted to the SUNDIALS project need to have the following sign -off line in the commit message: -``` -Signed-off-by: Jane Doe -``` -Replacing Jane Doe’s details with your name and email address. - -If you've set `user.name` and `user.email` in your Git configuration, you can -automatically add a sign off line at the end of the commit message by using the -`-s` option (e.g., `git commit -s`). diff --git a/deps/AMICI/ThirdParty/sundials/LICENSE b/deps/AMICI/ThirdParty/sundials/LICENSE index 4ba2c4848..2b12386cc 100644 --- a/deps/AMICI/ThirdParty/sundials/LICENSE +++ b/deps/AMICI/ThirdParty/sundials/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2002-2021, Lawrence Livermore National Security and Southern Methodist University. +Copyright (c) 2002-2024, Lawrence Livermore National Security and Southern Methodist University. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/deps/AMICI/ThirdParty/sundials/README.md b/deps/AMICI/ThirdParty/sundials/README.md index aa87e594f..c410afb6c 100644 --- a/deps/AMICI/ThirdParty/sundials/README.md +++ b/deps/AMICI/ThirdParty/sundials/README.md @@ -1,52 +1,43 @@ # SUNDIALS: SUite of Nonlinear and DIfferential/ALgebraic equation Solvers # -### Version 5.8.0 (Sep 2021) ### +### Version 7.1.1 (Jun 2024) ### **Center for Applied Scientific Computing, Lawrence Livermore National Laboratory** -SUNDIALS is a family of software packages implemented with the goal of -providing robust time integrators and nonlinear solvers that can easily be -incorporated into existing simulation codes. The primary design goals are to -require minimal information from the user, allow users to easily supply their -own data structures underneath the packages, and allow for easy incorporation -of user-supplied linear solvers and preconditioners. The various packages share -many subordinate modules and are organized as a family with a directory -structure that exploits sharing common functionality. +SUNDIALS is a family of software packages providing robust and efficient time +integrators and nonlinear solvers that can easily be incorporated into existing +simulation codes. The packages are designed to require minimal information from +the user, allow users to supply their own data structures underneath the +packages, and enable interfacing with user-supplied or third-party algebraic +solvers and preconditioners. -The SUNDIALS suite consists of the following packages: +The SUNDIALS suite consists of the following packages for ordinary differential +equation (ODE) systems, differential-algebraic equation (DAE) systems, and +nonlinear algebraic systems: -* ARKODE - for integration of stiff, nonstiff, and multirate ordinary -differential equation systems (ODEs) of the form +* ARKODE - for integrating stiff, nonstiff, and multirate ODEs of the form + $$M(t) \\, y' = f_1(t,y) + f_2(t,y), \quad y(t_0) = y_0$$ - ``` M y' = f1(t,y) + f2(t,y), y(t0) = y0 ``` +* CVODE - for integrating stiff and nonstiff ODEs of the form + $$y' = f(t,y), \quad y(t_0) = y_0$$ -* CVODE - for integration of stiff and nonstiff ordinary differential equation -systems (ODEs) of the form +* CVODES - for integrating and sensitivity analysis (forward and adjoint) of + ODEs of the form + $$y' = f(t,y,p), \quad y(t_0) = y_0(p)$$ - ``` y' = f(t,y), y(t0) = y0 ``` +* IDA - for integrating DAEs of the form + $$F(t,y,y') = 0, \quad y(t_0) = y_0, \quad y'(t_0) = y_0'$$ -* CVODES - for integration and sensitivity analysis (forward and adjoint) of -ordinary differential equation systems (ODEs) of the form +* IDAS - for integrating and sensitivity analysis (forward and adjoint) of DAEs + of the form + $$F(t,y,y',p) = 0, \quad y(t_0) = y_0(p), \quad y'(t_0) = y_0'(p)$$ - ``` y' = f(t,y,p), y(t0) = y0(p) ``` - -* IDA - for integration of differential-algebraic equation systems (DAEs) of -the form - - ``` F(t,y,y') = 0, y(t0) = y0, y'(t0) = y0' ``` - -* IDAS - for integration and sensitivity analysis (forward and adjoint) of -differential-algebraic equation systems (DAEs) of the form - - ``` F(t,y,y',p) = 0, y(t0) = y0(p), y'(t0) = y0'(p) ``` - -* KINSOL - for solution of nonlinear algebraic systems of the form - - ``` F(u) = 0 ``` +* KINSOL - for solving nonlinear algebraic systems of the form + $$F(u) = 0 \quad \text{or} \quad G(u) = u$$ ## Installation ## -For installation directions see the [INSTALL_GUIDE](./INSTALL_GUIDE.pdf) or -the installation chapter in any of the package user guides. +For installation directions see the [online install guide](https://sundials.readthedocs.io/en/latest/Install_link.html), +the installation chapter in any of the package user guides, or INSTALL_GUIDE.pdf. Warning to users who receive more than one of the individual packages at different times: Mixing old and new versions of SUNDIALS may fail. To avoid @@ -54,8 +45,12 @@ such failures, obtain all desired package at the same time. ## Support ## -Full user guides for SUNDIALS packages are provided in the [doc](./doc) -directory along with documentation for example programs. +Full user guides for all of the SUNDIALS packages are available [online](https://sundials.readthedocs.io) +and in the [doc](./doc) directory. Additionally, the [doc](./doc) directory +contains documentation for the package example programs. + +For information on recent changes to SUNDIALS see the [CHANGELOG](./CHANGELOG.md) +or the introduction chapter of any package user guide. A list of Frequently Asked Questions on build and installation procedures as well as common usage issues is available on the SUNDIALS [FAQ](https://computing.llnl.gov/projects/sundials/faq). @@ -71,11 +66,11 @@ Bug fixes or minor changes are preferred via a pull request to the [SUNDIALS GitHub repository](https://github.com/LLNL/sundials). For more information on contributing see the [CONTRIBUTING](./CONTRIBUTING.md) file. -## Release History ## +## Citing ## -Information on recent changes to SUNDIALS can be found in the "Introduction" -chapter of each package's user guide and a complete release history is available -in the "SUNDIALS Release History" appendix of each user guide. +See the [online documentation](https://sundials.readthedocs.io/en/latest/index.html#citing) +or [CITATIONS](./CITATIONS.md) file for information on how to cite SUNDIALS in +any publications reporting work done using SUNDIALS packages. ## Authors ## @@ -87,20 +82,9 @@ We thank Radu Serban for significant and critical past contributions. Other contributors to SUNDIALS include: James Almgren-Bell, Lawrence E. Banks, Peter N. Brown, George Byrne, Rujeko Chinomona, Scott D. Cohen, Aaron Collier, Keith E. Grant, Steven L. Lee, Shelby L. Lockhart, John Loffeld, Daniel McGreer, -Slaven Peles, Cosmin Petra, H. Hunter Schwartz, Jean M. Sexton, -Dan Shumaker, Steve G. Smith, Allan G. Taylor, Hilari C. Tiedeman, Chris White, -Ting Yan, and Ulrike M. Yang. - - -### Citing SUNDIALS ### - -We ask users of SUNDIALS to cite the following paper in any publications -reporting work done with SUNDIALS: - -* Alan C. Hindmarsh, Peter N. Brown, Keith E. Grant, Steven L. Lee, Radu -Serban, Dan E. Shumaker, and Carol S. Woodward. 2005. SUNDIALS: Suite of -nonlinear and differential/algebraic equation solvers. ACM Trans. Math. Softw. -31, 3 (September 2005), 363-396. DOI=http://dx.doi.org/10.1145/1089014.1089020 +Yu Pan, Slaven Peles, Cosmin Petra, Steven B. Roberts, H. Hunter Schwartz, +Jean M. Sexton, Dan Shumaker, Steve G. Smith, Shahbaj Sohal, Allan G. Taylor, +Hilari C. Tiedeman, Chris White, Ting Yan, and Ulrike M. Yang. ## License ## diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SUNDIALSConfig.cmake.in b/deps/AMICI/ThirdParty/sundials/cmake/SUNDIALSConfig.cmake.in index 6846c5353..9cbe9e6c2 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SUNDIALSConfig.cmake.in +++ b/deps/AMICI/ThirdParty/sundials/cmake/SUNDIALSConfig.cmake.in @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -55,102 +55,119 @@ endforeach() ### ------- Create TPL imported targets -if(@ENABLE_HYPRE@ AND NOT TARGET SUNDIALS::HYPRE) +if("@ENABLE_MPI@" AND NOT TARGET MPI::MPI_C) + set(MPI_C_COMPILER "@MPI_C_COMPILER@") + find_dependency(MPI) +endif() + +if("@ENABLE_OPENMP@" AND NOT TARGET OpenMP::OpenMP_C) + find_dependency(OpenMP) +endif() + +if("@ENABLE_CALIPER@" AND NOT TARGET caliper) + find_dependency(CALIPER PATHS "@CALIPER_DIR@") +endif() + +if("@ENABLE_ADIAK@" AND NOT TARGET adiak::adiak) + find_dependency(adiak PATHS "@adiak_DIR@") +endif() + +if("@ENABLE_CUDA@" AND NOT (TARGET CUDA::cudart AND TARGET CUDA::cublas + AND TARGET CUDA::cusparse AND TARGET CUDA::cusolver)) + find_dependency(CUDAToolkit) +endif() + +if("@ENABLE_GINKGO@" AND NOT TARGET Ginkgo::ginkgo) + if(NOT TARGET hwloc AND NOT HWLOC_DIR) + set(HWLOC_DIR "@HWLOC_DIR@") + endif() + find_dependency(Ginkgo PATHS "@Ginkgo_DIR@") +endif() + +if("@ENABLE_HYPRE@" AND NOT TARGET SUNDIALS::HYPRE) add_library(SUNDIALS::HYPRE INTERFACE IMPORTED) target_link_libraries(SUNDIALS::HYPRE INTERFACE "@HYPRE_LIBRARIES@") set_target_properties(SUNDIALS::HYPRE PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@HYPRE_INCLUDE_DIR@") endif() -if(@ENABLE_KLU@ AND NOT TARGET SUNDIALS::KLU) - add_library(SUNDIALS::KLU INTERFACE IMPORTED) - target_link_libraries(SUNDIALS::KLU INTERFACE "@KLU_LIBRARIES@") - set_target_properties(SUNDIALS::KLU PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@KLU_INCLUDE_DIR@") -endif() - -if(@ENABLE_PETSC@) - set(PETSC_LIBRARY_SINGLE "@PETSC_LIBRARY_SINGLE@") - if(${PETSC_LIBRARY_SINGLE}) - foreach(suffix SYS VEC MAT DM KSP SNES TS ALL) - if(NOT TARGET SUNDIALS::PETSC_${suffix}) - add_library(SUNDIALS::PETSC_${suffix} UNKNOWN IMPORTED) - set_target_properties(SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "@PETSC_INCLUDES_@") - set_target_properties(SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_LINK_LIBRARIES "@PETSC_LIBRARIES_@") - set_target_properties(SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_COMPILE_OPTIONS "@PETSC_DEFINITIONS@") - set_target_properties(SUNDIALS::PETSC_${suffix} PROPERTIES - IMPORTED_LOCATION "${PETSC_LIBRARY_SINGLE}") - endif() - endforeach() +if("@ENABLE_KLU@" AND NOT TARGET SUNDIALS::KLU) + if("@KLU_SUITESPARSE_TARGET@") + find_dependency(KLU) else() - set(PESTC_LIBRARY_SYS "@PETSC_LIBRARY_SYS@") - set(PESTC_LIBRARY_VEC "@PETSC_LIBRARY_VEC@") - set(PESTC_LIBRARY_MAT "@PETSC_LIBRARY_MAT@") - set(PESTC_LIBRARY_DM "@PETSC_LIBRARY_DM@") - set(PESTC_LIBRARY_KSP "@PETSC_LIBRARY_KSP@") - set(PESTC_LIBRARY_SNES "@PETSC_LIBRARY_SNES@") - set(PESTC_LIBRARY_TS "@PETSC_LIBRARY_TS@") - set(PESTC_LIBRARY_ALL "@PETSC_LIBRARY_ALL@") - - set(PESTC_LIBRARIES_SYS "@PETSC_LIBRARIES_SYS@") - set(PESTC_LIBRARIES_VEC "@PETSC_LIBRARIES_VEC@") - set(PESTC_LIBRARIES_MAT "@PETSC_LIBRARIES_MAT@") - set(PESTC_LIBRARIES_DM "@PETSC_LIBRARIES_DM@") - set(PESTC_LIBRARIES_KSP "@PETSC_LIBRARIES_KSP@") - set(PESTC_LIBRARIES_SNES "@PETSC_LIBRARIES_SNES@") - set(PESTC_LIBRARIES_TS "@PETSC_LIBRARIES_TS@") - set(PESTC_LIBRARIES_ALL "@PETSC_LIBRARIES_ALL@") - - foreach(suffix SYS VEC MAT DM KSP SNES TS ALL) - if(NOT TARGET SUNDIALS::PETSC_${suffix}) - add_library(SUNDIALS::PETSC_${suffix} UNKNOWN IMPORTED) - set_target_properties (SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "@PETSC_INCLUDES_@") - set_target_properties (SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_LINK_LIBRARIES "${PETSC_LIBRARIES_${suffix}}") - set_target_properties (SUNDIALS::PETSC_${suffix} PROPERTIES - INTERFACE_COMPILE_OPTIONS "${PETSC_DEFINITIONS}") - set_target_properties (SUNDIALS::PETSC_${suffix} PROPERTIES - IMPORTED_LOCATION "${PETSC_LIBRARY_${suffix}}") - endif() - endforeach() + add_library(SUNDIALS::KLU INTERFACE IMPORTED) + target_link_libraries(SUNDIALS::KLU INTERFACE "@KLU_LIBRARIES@") + set_target_properties(SUNDIALS::KLU PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@KLU_INCLUDE_DIR@") + endif() +endif() + +if("@ENABLE_KOKKOS@" AND NOT TARGET Kokkos::kokkos) + find_dependency(Kokkos PATHS "@Kokkos_DIR@") +endif() + +if("@ENABLE_KOKKOS_KERNELS@" AND NOT TARGET Kokkos::kokkoskernels) + find_dependency(KokkosKernels PATHS "@KokkosKernels_DIR@") +endif() + +if("@ENABLE_PETSC@" AND NOT TARGET SUNDIALS::PETSC) + add_library(SUNDIALS::PETSC INTERFACE IMPORTED) + target_link_libraries(SUNDIALS::PETSC INTERFACE "@PETSC_LIBRARIES@") + set_target_properties(SUNDIALS::PETSC PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@PETSC_INCLUDE_DIRS@") + + # for backwards compatibility + foreach(suffix SYS VEC MAT DM KSP SNES TS ALL) + if(NOT TARGET SUNDIALS::PETSC_${suffix}) + add_library(SUNDIALS::PETSC_${suffix} INTERFACE IMPORTED) + set_target_properties (SUNDIALS::PETSC_${suffix} PROPERTIES + INTERFACE_LINK_LIBRARIES "SUNDIALS::PETSC") + endif() + endforeach() + + if("@PETSC_LIBRARIES@" MATCHES "Kokkos::kokkos") + if(NOT TARGET Kokkos::kokkoskernels) + find_dependency(KokkosKernels PATHS "@KokkosKernels_DIR@") + endif() + if(NOT TARGET Kokkos::kokkos) + find_dependency(Kokkos PATHS "@Kokkos_DIR@") + endif() endif() endif() -if(@ENABLE_MAGMA@ AND NOT TARGET SUNDIALS::MAGMA) +if("@ENABLE_MAGMA@" AND NOT TARGET SUNDIALS::MAGMA) add_library(SUNDIALS::MAGMA INTERFACE IMPORTED) target_link_libraries(SUNDIALS::MAGMA INTERFACE "@MAGMA_LIBRARIES@") set_target_properties(SUNDIALS::MAGMA PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@MAGMA_INCLUDE_DIR@") endif() -if(@ENABLE_ONEMKL@ AND NOT TARGET MKL) - find_package(MKL PATHS @ONEMKL_DIR@) +if("@ENABLE_ONEMKL@" AND NOT TARGET MKL) + find_dependency(MKL PATHS "@ONEMKL_DIR@") endif() -if(@ENABLE_SUPERLUDIST@ AND NOT TARGET SUNDIALS::SUPERLUDIST) +if("@ENABLE_SUPERLUDIST@" AND NOT TARGET SUNDIALS::SUPERLUDIST) add_library(SUNDIALS::SUPERLUDIST INTERFACE IMPORTED) - target_link_libraries(SUNDIALS::SUPERLUDIST INTERFACE "@SUPERLUDIST_LIBRARIES@") - set_target_properties(SUNDIALS::SUPERLUDIST PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@SUPERLUDIST_INCLUDE_DIR@") + target_link_libraries(SUNDIALS::SUPERLUDIST INTERFACE "@SUPERLUDIST_LINK_LIBRARIES@") + set_target_properties(SUNDIALS::SUPERLUDIST PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@SUPERLUDIST_INCLUDE_DIRS@") endif() -if(@ENABLE_SUPERLUMT@ AND NOT TARGET SUNDIALS::SUPERLUMT) +if("@ENABLE_SUPERLUMT@" AND NOT TARGET SUNDIALS::SUPERLUMT) add_library(SUNDIALS::SUPERLUMT INTERFACE IMPORTED) target_link_libraries(SUNDIALS::SUPERLUMT INTERFACE "@SUPERLUMT_LIBRARIES@") set_target_properties(SUNDIALS::SUPERLUMT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@SUPERLUMT_INCLUDE_DIR@") endif() -if(@ENABLE_RAJA@ AND NOT TARGET RAJA) - find_package(RAJA PATHS @RAJA_DIR@) +if("@ENABLE_RAJA@" AND NOT TARGET RAJA) + if(NOT TARGET camp AND NOT camp_DIR) + set(camp_DIR "@camp_DIR@") + endif() + find_dependency(RAJA PATHS "@RAJA_DIR@") endif() -if(@ENABLE_TRILINOS@ AND NOT TARGET SUNDIALS::TRILINOS) +if("@ENABLE_TRILINOS@" AND NOT TARGET SUNDIALS::TRILINOS) add_library(SUNDIALS::TRILINOS INTERFACE IMPORTED) target_link_libraries(SUNDIALS::TRILINOS INTERFACE "@Trilinos_LIBRARIES@") set_target_properties(SUNDIALS::TRILINOS PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@Trilinos_INCLUDE_DIRS@") endif() -if(@ENABLE_XBRAID@ AND NOT TARGET SUNDIALS::XBRAID) +if("@ENABLE_XBRAID@" AND NOT TARGET SUNDIALS::XBRAID) add_library(SUNDIALS::XBRAID INTERFACE IMPORTED) target_link_libraries(SUNDIALS::XBRAID INTERFACE "@XBRAID_LIBRARIES@") set_target_properties(SUNDIALS::XBRAID PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@XBRAID_INCLUDE_DIR@") diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPost.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPost.cmake index d39b51803..01d6969bc 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPost.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPost.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -20,10 +20,15 @@ # Currently only available in CVODE. # --------------------------------------------------------------- +if(ENABLE_CUDA OR ENABLE_HIP) + set(CUDA_OR_HIP TRUE) +else() + set(CUDA_OR_HIP FALSE) +endif() + sundials_option(SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS BOOL "Build specialized fused GPU kernels" OFF - DEPENDS_ON BUILD_CVODE - DEPENDS_ON_THROW_ERROR - SHOW_IF BUILD_CVODE) + DEPENDS_ON BUILD_CVODE CUDA_OR_HIP + DEPENDS_ON_THROW_ERROR) # --------------------------------------------------------------- # Options to enable/disable build for NVECTOR modules. @@ -102,6 +107,11 @@ sundials_option(BUILD_NVECTOR_TRILINOS BOOL "Build the NVECTOR_TRILINOS module ( ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_NVECTOR_TRILINOS") +sundials_option(BUILD_NVECTOR_KOKKOS BOOL "Build the NVECTOR_KOKKOS module (requires Kokkos)" ON + DEPENDS_ON ENABLE_KOKKOS KOKKOS_WORKS + ADVANCED) +list(APPEND SUNDIALS_BUILD_LIST "BUILD_NVECTOR_KOKKOS") + # --------------------------------------------------------------- # Options to enable/disable build for SUNMATRIX modules. @@ -124,6 +134,16 @@ sundials_option(BUILD_SUNMATRIX_CUSPARSE BOOL "Build the SUNMATRIX_CUSPARSE modu ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNMATRIX_CUSPARSE") +sundials_option(BUILD_SUNMATRIX_GINKGO BOOL "Build the SUNMATRIX_GINKGO module (requires Ginkgo)" ON + DEPENDS_ON ENABLE_GINKGO GINKGO_WORKS + ADVANCED) +list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNMATRIX_GINKGO") + +sundials_option(BUILD_SUNMATRIX_KOKKOSDENSE BOOL "Build the SUNMATRIX_KOKKOSDENSE module" ON + DEPENDS_ON ENABLE_KOKKOS KOKKOS_WORKS ENABLE_KOKKOS_KERNELS KOKKOS_KERNELS_WORKS + ADVANCED) +list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNMATRIX_KOKKOSDENSE") + sundials_option(BUILD_SUNMATRIX_MAGMADENSE BOOL "Build the SUNMATRIX_MAGMADENSE module (requires MAGMA)" ON DEPENDS_ON ENABLE_MAGMA MAGMA_WORKS ADVANCED) @@ -164,11 +184,21 @@ sundials_option(BUILD_SUNLINSOL_CUSOLVERSP BOOL "Build the SUNLINSOL_CUSOLVERSP ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_CUSOLVERSP") +sundials_option(BUILD_SUNLINSOL_GINKGO BOOL "Build the SUNLINSOL_GINKGO module (requires Ginkgo)" ON + DEPENDS_ON ENABLE_GINKGO GINKGO_WORKS + ADVANCED) +list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_GINKGO") + sundials_option(BUILD_SUNLINSOL_KLU BOOL "Build the SUNLINSOL_KLU module (requires KLU)" ON DEPENDS_ON ENABLE_KLU KLU_WORKS ADVANCED) list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_KLU") +sundials_option(BUILD_SUNLINSOL_KOKKOSDENSE BOOL "Build the SUNLINSOL_KOKKOSDENSE module" ON + DEPENDS_ON ENABLE_KOKKOS KOKKOS_WORKS ENABLE_KOKKOS_KERNELS KOKKOS_KERNELS_WORKS + ADVANCED) +list(APPEND SUNDIALS_BUILD_LIST "BUILD_SUNLINSOL_KOKKOSDENSE") + sundials_option(BUILD_SUNLINSOL_LAPACKBAND BOOL "Build the SUNLINSOL_LAPACKBAND module (requires LAPACK)" ON DEPENDS_ON ENABLE_LAPACK LAPACK_WORKS ADVANCED) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPre.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPre.cmake index 07a7fde71..3c3f6b16c 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPre.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsBuildOptionsPre.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -24,17 +24,10 @@ sundials_option(USE_XSDK_DEFAULTS BOOL "Enable default xSDK settings" OFF) if(USE_XSDK_DEFAULTS) message(STATUS "Enabling xSDK defaults:") - - # set the CMake build type, SUNDIALS does not set a build type by default - if(NOT CMAKE_BUILD_TYPE) - message(STATUS " Setting build type to Debug") - set(DOCSTR "Choose the type of build: None Debug Release RelWithDebInfo MinSizeRel") - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "${DOCSTR}" FORCE) - endif() endif() # --------------------------------------------------------------- -# Option to specify precision (realtype) +# Option to specify precision (sunrealtype) # --------------------------------------------------------------- set(DOCSTR "single, double, or extended") @@ -58,21 +51,64 @@ set(DOCSTR "Integer type to use for indices in SUNDIALS") sundials_option(SUNDIALS_INDEX_TYPE STRING "${DOCSTR}" "" ADVANCED) # --------------------------------------------------------------- -# Option to specify monitoring +# Option to enable monitoring # --------------------------------------------------------------- set(DOCSTR "Build with simulation monitoring capabilities enabled") sundials_option(SUNDIALS_BUILD_WITH_MONITORING BOOL "${DOCSTR}" OFF) # --------------------------------------------------------------- -# Option to use the generic math libraries (UNIX only) +# Option to enable profiling +# --------------------------------------------------------------- + +set(DOCSTR "Build with simulation profiling capabilities enabled") +sundials_option(SUNDIALS_BUILD_WITH_PROFILING BOOL "${DOCSTR}" OFF) + +if(SUNDIALS_BUILD_WITH_PROFILING) + message(WARNING "SUNDIALS built with profiling turned on, performance may be affected.") +endif() + +# --------------------------------------------------------------- +# Option to enable/disable error checking +# --------------------------------------------------------------- + +if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo") + set(_default_err_checks OFF) +else() + set(_default_err_checks ON) +endif() + +set(DOCSTR "Build with error checking enabled/disabled. Enabling error checks may affect performance.") +sundials_option(SUNDIALS_ENABLE_ERROR_CHECKS BOOL "${DOCSTR}" ${_default_err_checks}) +if(SUNDIALS_ENABLE_ERROR_CHECKS) + message(STATUS "SUNDIALS error checking enabled") + message(WARNING "SUNDIALS is being built with extensive error checks, performance may be affected.") +endif() + +# --------------------------------------------------------------- +# Option to enable logging +# --------------------------------------------------------------- + +set(DOCSTR "Build with logging capabilities enabled (0 = no logging, 1 = errors, 2 = +warnings, 3 = +info, 4 = +debug, 5 = +extras") +sundials_option(SUNDIALS_LOGGING_LEVEL STRING "${DOCSTR}" 2 + OPTIONS "0;1;2;3;4;5") + +if(SUNDIALS_LOGGING_LEVEL GREATER_EQUAL 3) + message(STATUS "SUNDIALS logging level set to ${SUNDIALS_LOGGING_LEVEL}") + message(WARNING "SUNDIALS built with additional logging turned on, performance may be affected.") +endif() + +# --------------------------------------------------------------- +# Option to set the math library # --------------------------------------------------------------- if(UNIX) - sundials_option(USE_GENERIC_MATH BOOL "Use generic (std-c) math libraries" ON) - # all executables will be linked against -lm - set(EXTRA_LINK_LIBS -lm) + sundials_option(SUNDIALS_MATH_LIBRARY PATH "Which math library (e.g., libm) to link to" "-lm" ADVANCED) +else() + sundials_option(SUNDIALS_MATH_LIBRARY PATH "Which math library (e.g., libm) to link to" "" ADVANCED) endif() +# all executables will be linked against the math library +set(EXE_EXTRA_LINK_LIBS "${SUNDIALS_MATH_LIBRARY}") # --------------------------------------------------------------- # Options to enable static and/or shared libraries @@ -83,7 +119,7 @@ sundials_option(BUILD_SHARED_LIBS BOOL "Build shared libraries" ON) # Make sure we build at least one type of libraries if(NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS) - print_error("Both static and shared library generation were disabled.") + message(FATAL_ERROR "Both static and shared library generation were disabled.") endif() # --------------------------------------------------------------- @@ -139,21 +175,6 @@ endif() # Options to enable Fortran interfaces. # --------------------------------------------------------------- -# Fortran interface is disabled by default -set(DOCSTR "Enable Fortran 77 interfaces") -sundials_option(BUILD_FORTRAN77_INTERFACE BOOL "${DOCSTR}" OFF) - -# Check that at least one solver with a Fortran 77 interface is built -if(BUILD_FORTRAN77_INTERFACE) - if(NOT (BUILD_ARKODE OR BUILD_CVODE OR BUILD_IDA OR BUILD_KINSOL)) - print_warning("Enabled packages do not support Fortran 77 interface" "Disabling F77 interface") - set(BUILD_FORTRAN77_INTERFACE OFF CACHE BOOL "${DOCSTR}" FORCE) - elseif(NOT BUILD_STATIC_LIBS) - print_error("Fortran 77 interfaces can only be built as static libraries" "Disabling F77 interface") - set(BUILD_FORTRAN77_INTERFACE OFF CACHE BOOL "${DOCSTR}" FORCE) - endif() -endif() - # Fortran 2003 interface is disabled by default set(DOCSTR "Enable Fortran 2003 modules") sundials_option(BUILD_FORTRAN_MODULE_INTERFACE BOOL "${DOCSTR}" OFF) @@ -161,12 +182,7 @@ sundials_option(BUILD_FORTRAN_MODULE_INTERFACE BOOL "${DOCSTR}" OFF) if(BUILD_FORTRAN_MODULE_INTERFACE) # F2003 interface only supports double precision if(NOT (SUNDIALS_PRECISION MATCHES "DOUBLE")) - print_error("F2003 interface is not compatible with ${SUNDIALS_PRECISION} precision") - endif() - - # F2003 interface only supports 64-bit indices - if(NOT (SUNDIALS_INDEX_SIZE MATCHES "64")) - print_error("F2003 interface is not compatible with ${SUNDIALS_INDEX_SIZE}-bit indicies") + message(FATAL_ERROR "F2003 interface is not compatible with ${SUNDIALS_PRECISION} precision") endif() # Allow a user to set where the Fortran modules will be installed @@ -174,6 +190,146 @@ if(BUILD_FORTRAN_MODULE_INTERFACE) sundials_option(Fortran_INSTALL_MODDIR STRING "${DOCSTR}" "fortran") endif() +# --------------------------------------------------------------- +# Options for benchmark suite +# --------------------------------------------------------------- + +sundials_option(BUILD_BENCHMARKS BOOL "Build the SUNDIALS benchmark suite" OFF) + +sundials_option(BENCHMARKS_INSTALL_PATH PATH "Output directory for installing benchmark executables" "${CMAKE_INSTALL_PREFIX}/benchmarks") + +# --------------------------------------------------------------- +# Options for CMake config installation +# --------------------------------------------------------------- + set(DOCSTR "Path to SUNDIALS cmake files") sundials_option(SUNDIALS_INSTALL_CMAKEDIR STRING "${DOCSTR}" "${CMAKE_INSTALL_LIBDIR}/cmake/sundials") + +# --------------------------------------------------------------- +# Options to enable compiler warnings, address sanitizer +# --------------------------------------------------------------- + +sundials_option(ENABLE_ALL_WARNINGS BOOL + "Enable all compiler warnings" OFF ADVANCED) + +sundials_option(ENABLE_WARNINGS_AS_ERRORS BOOL + "Enable compiler warnings as errors" OFF ADVANCED) + +sundials_option(ENABLE_ADDRESS_SANITIZER BOOL + "Enable address sanitizer" OFF ADVANCED) + +# --------------------------------------------------------------- +# Options to enable SUNDIALS debugging +# --------------------------------------------------------------- + +# List of debugging options (used to add preprocessor directives) +set(_SUNDIALS_DEBUG_OPTIONS + SUNDIALS_DEBUG + SUNDIALS_DEBUG_ASSERT + SUNDIALS_DEBUG_CUDA_LASTERROR + SUNDIALS_DEBUG_HIP_LASTERROR + SUNDIALS_DEBUG_PRINTVEC) + +sundials_option(SUNDIALS_DEBUG BOOL + "Enable additional debugging output and options" OFF + ADVANCED) + +if(SUNDIALS_DEBUG AND SUNDIALS_LOGGING_LEVEL LESS 4) + set(DOCSTR "SUNDIALS_DEBUG=ON forced the logging level to 4") + message(STATUS "${DOCSTR}") + set(SUNDIALS_LOGGING_LEVEL "4" CACHE STRING "${DOCSTR}" FORCE) +endif() + +sundials_option(SUNDIALS_DEBUG_ASSERT BOOL + "Enable assert when debugging" OFF + DEPENDS_ON SUNDIALS_DEBUG + ADVANCED) + +sundials_option(SUNDIALS_DEBUG_CUDA_LASTERROR BOOL + "Enable CUDA last error checks when debugging" OFF + DEPENDS_ON SUNDIALS_DEBUG ENABLE_CUDA + ADVANCED) + +sundials_option(SUNDIALS_DEBUG_HIP_LASTERROR BOOL + "Enable HIP last error checks when debugging" OFF + DEPENDS_ON SUNDIALS_DEBUG ENABLE_HIP + ADVANCED) + +sundials_option(SUNDIALS_DEBUG_PRINTVEC BOOL + "Enable vector printing when debugging" OFF + DEPENDS_ON SUNDIALS_DEBUG + ADVANCED) + +if(SUNDIALS_DEBUG_PRINTVEC AND SUNDIALS_LOGGING_LEVEL LESS 5) + set(DOCSTR "SUNDIALS_DEBUG_PRINTVEC=ON forced the logging level to 5") + message(STATUS "${DOCSTR}") + set(SUNDIALS_LOGGING_LEVEL "5" CACHE STRING "${DOCSTR}" FORCE) +endif() + +# --------------------------------------------------------------- +# Options for SUNDIALS external +# --------------------------------------------------------------- + +sundials_option(SUNDIALS_ENABLE_EXTERNAL_ADDONS BOOL + "Enables including EXTERNALLY MAINTAINED addons in the SUNDIALS build." OFF) +if(SUNDIALS_ENABLE_EXTERNAL_ADDONS) + message(WARNING "SUNDIALS_ENABLE_EXTERNAL_ADDONS=TRUE. External addons are not maintained by the SUNDIALS team. Use at your own risk.") +endif() + +# --------------------------------------------------------------- +# Options for SUNDIALS testing +# --------------------------------------------------------------- + +sundials_option(SUNDIALS_TEST_FLOAT_PRECISION STRING + "Precision for floating point comparisons (number of digits)" "-1" ADVANCED) + +sundials_option(SUNDIALS_TEST_INTEGER_PRECISION STRING + "Precision for integer comparisons (percent difference)" "-1" ADVANCED) + +sundials_option(SUNDIALS_TEST_OUTPUT_DIR PATH + "Location to write testing output files" "" ADVANCED) + +sundials_option(SUNDIALS_TEST_ANSWER_DIR PATH + "Location of testing answer files" "" ADVANCED) + +sundials_option(SUNDIALS_TEST_PROFILE BOOL + "Use Caliper to profile SUNDIALS tests" OFF ADVANCED) + +sundials_option(SUNDIALS_TEST_NODIFF BOOL + "Disable output comparison in the regression test suite" OFF ADVANCED) + +sundials_option(SUNDIALS_TEST_CONTAINER_EXE PATH + "Path to docker or podman" "" ADVANCED) + +sundials_option(SUNDIALS_TEST_CONTAINER_RUN_EXTRA_ARGS STRING + "Extra arguments to pass to docker/podman run command" "--tls-verify=false" ADVANCED) + +sundials_option(SUNDIALS_TEST_CONTAINER_MNT STRING + "Path to project root inside the container" "/sundials" ADVANCED) + +# Include development examples in regression tests +sundials_option(SUNDIALS_TEST_DEVTESTS BOOL + "Include development tests in make test" OFF ADVANCED) + +# Include unit tests in regression tests +sundials_option(SUNDIALS_TEST_UNITTESTS BOOL + "Include unit tests in make test" OFF ADVANCED) + +# Include googletest unit tests in regression tests +sundials_option(SUNDIALS_TEST_ENABLE_GTEST BOOL + "Disable GTest unit tests" ON ADVANCED) + +sundials_option(SUNDIALS_DEV_IWYU BOOL + "Enable include-what-you-use" OFF ADVANCED) + +sundials_option(SUNDIALS_DEV_CLANG_TIDY BOOL + "Enable clang-tidy" OFF ADVANCED) + +sundials_option(SUNDIALS_SCHEDULER_COMMAND STRING "Job scheduler command to use to launch SUNDIALS MPI tests" "" ADVANCED) + +sundials_option(SUNDIALS_CALIPER_OUTPUT_DIR PATH "Location to write caliper output files" "" ADVANCED) + +sundials_option(SUNDIALS_BENCHMARK_NUM_CPUS STRING "Number of CPU cores to run benchmarks with" "40" ADVANCED) + +sundials_option(SUNDIALS_BENCHMARK_NUM_GPUS STRING "Number of GPUs to run benchmarks with" "4" ADVANCED) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsDeprecated.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsDeprecated.cmake index d0f69a6c3..385a11361 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsDeprecated.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsDeprecated.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -17,125 +17,127 @@ # if(DEFINED F2003_INTERFACE_ENABLE) - print_warning("The CMake option F2003_INTERFACE_ENABLE is deprecated" - "Use BUILD_FORTRAN_MODULE_INTERFACE instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option F2003_INTERFACE_ENABLE is deprecated. " + "Use BUILD_FORTRAN_MODULE_INTERFACE instead.") set(BUILD_FORTRAN_MODULE_INTERFACE ${F2003_INTERFACE_ENABLE} CACHE BOOL "Enable Fortran 2003 module interfaces") endif() -if(DEFINED F77_INTERFACE_ENABLE) - print_warning("The CMake option F77_INTERFACE_ENABLE is deprecated" - "Use BUILD_FORTRAN77_INTERFACE instead" - MODE DEPRECATION) - set(BUILD_FORTRAN77_INTERFACE ${F77_INTERFACE_ENABLE} CACHE BOOL "Enable Fortran 77 interfaces") -endif() - unset(F2003_INTERFACE_ENABLE CACHE) -unset(F77_INTERFACE_ENABLE CACHE) # # Deprecated TPL options # if(DEFINED MPI_ENABLE) - print_warning("The CMake option MPI_ENABLE is deprecated" "Use ENABLE_MPI instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option MPI_ENABLE is deprecated. " + "Use ENABLE_MPI instead.") set(ENABLE_MPI ${MPI_ENABLE} CACHE BOOL "Enable MPI support" FORCE) unset(MPI_ENABLE CACHE) endif() if(DEFINED OPENMP_ENABLE) - print_warning("The CMake option OPENMP_ENABLE is deprecated" "Use ENABLE_OPENMP instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option OPENMP_ENABLE is deprecated. " + "Use ENABLE_OPENMP instead.") set(ENABLE_OPENMP ${OPENMP_ENABLE} CACHE BOOL "Enable OpenMP support" FORCE) unset(OPENMP_ENABLE CACHE) endif() if(DEFINED OPENMP_DEVICE_ENABLE) - print_warning("The CMake option OPENMP_DEVICE_ENABLE is deprecated" - "Use ENABLE_OPENMP_DEVICE instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option OPENMP_DEVICE_ENABLE is deprecated. " + "Use ENABLE_OPENMP_DEVICE instead.") set(ENABLE_OPENMP_DEVICE ${OPENMP_DEVICE_ENABLE} CACHE BOOL "Enable OpenMP device offloading support" FORCE) unset(OPENMP_DEVICE_ENABLE CACHE) endif() if(DEFINED SKIP_OPENMP_DEVICE_CHECK) - print_warning("The CMake option SKIP_OPENMP_DEVICE_CHECK is deprecated" - "Use OPENMP_DEVICE_WORKS instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option SKIP_OPENMP_DEVICE_CHECK is deprecated. " + "Use OPENMP_DEVICE_WORKS instead.") set(OPENMP_DEVICE_WORKS ${SKIP_OPENMP_DEVICE_CHECK} CACHE BOOL "Skip the compiler check for OpenMP device offloading" FORCE) unset(SKIP_OPENMP_DEVICE_CHECK CACHE) endif() if(DEFINED PTHREAD_ENABLE) - print_warning("The CMake option PTHREAD_ENABLE is deprecated" "Use ENABLE_PTHREAD instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option PTHREAD_ENABLE is deprecated. " + "Use ENABLE_PTHREAD instead") set(ENABLE_PTHREAD ${PTHREAD_ENABLE} CACHE BOOL "Enable Pthreads support" FORCE) unset(PTHREAD_ENABLE CACHE) endif() if(DEFINED CUDA_ENABLE) - print_warning("The CMake option CUDA_ENABLE is deprecated" "Use ENABLE_CUDA instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option CUDA_ENABLE is deprecated. " + "Use ENABLE_CUDA instead.") set(ENABLE_CUDA ${CUDA_ENABLE} CACHE BOOL "Enable CUDA support" FORCE) unset(CUDA_ENABLE CACHE) endif() if(DEFINED LAPACK_ENABLE) - print_warning("The CMake option LAPACK_ENABLE is deprecated" "Use ENABLE_LAPACK instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option LAPACK_ENABLE is deprecated. " + "Use ENABLE_LAPACK instead.") set(ENABLE_LAPACK ${LAPACK_ENABLE} CACHE BOOL "Enable LAPACK support" FORCE) unset(LAPACK_ENABLE CACHE) endif() if(DEFINED SUPERLUDIST_ENABLE) - print_warning("The CMake option SUPERLUDIST_ENABLE is deprecated" - "Use ENABLE_SUPERLUDIST instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option SUPERLUDIST_ENABLE is deprecated. " + "Use ENABLE_SUPERLUDIST instead.") set(ENABLE_SUPERLUDIST ${SUPERLUDIST_ENABLE} CACHE BOOL "Enable SuperLU_DIST support" FORCE) unset(SUPERLUDIST_ENABLE CACHE) endif() +# Deprecated with SUNDIALS 6.4.0 +if(DEFINED SUPERLUDIST_LIBRARY_DIR) + message(DEPRECATION "The CMake option SUPERLUDIST_LIBRARY_DIR is deprecated. " + "Use SUPERLUDIST_DIR instead.") + set(SUPERLUDIST_DIR "${SUPERLUDIST_LIBRARY_DIR}/../" CACHE BOOL "SuperLU_DIST root directory" FORCE) + unset(SUPERLUDIST_LIBRARY_DIR CACHE) +endif() +if(DEFINED SUPERLUDIST_INCLUDE_DIR) + message(DEPRECATION "The CMake option SUPERLUDIST_INCLUDE_DIR is deprecated. " + "Use SUPERLUDIST_INCLUDE_DIRS instead.") + set(SUPERLUDIST_INCLUDE_DIRS "${SUPERLUDIST_INCLUDE_DIR}" CACHE BOOL "SuperLU_DIST include directoroes" FORCE) + unset(SUPERLUDIST_INCLUDE_DIR CACHE) +endif() + if(DEFINED SUPERLUMT_ENABLE) - print_warning("The CMake option SUPERLUMT_ENABLE is deprecated" "Use ENABLE_SUPERLUMT instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option SUPERLUMT_ENABLE is deprecated. " + "Use ENABLE_SUPERLUMT instead.") set(ENABLE_SUPERLUMT ${SUPERLUMT_ENABLE} CACHE BOOL "Enable SuperLU_MT support" FORCE) unset(SUPERLUMT_ENABLE CACHE) endif() if(DEFINED KLU_ENABLE) - print_warning("The CMake option KLU_ENABLE is deprecated" "Use ENABLE_KLU instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option KLU_ENABLE is deprecated. " + "Use ENABLE_KLU instead.") set(ENABLE_KLU ${KLU_ENABLE} CACHE BOOL "Enable KLU support" FORCE) unset(KLU_ENABLE CACHE) endif() if(DEFINED HYPRE_ENABLE) - print_warning("The CMake option HYPRE_ENABLE is deprecated" "Use ENABLE_HYPRE instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option HYPRE_ENABLE is deprecated. " + "Use ENABLE_HYPRE instead.") set(ENABLE_HYPRE ${HYPRE_ENABLE} CACHE BOOL "Enable HYPRE support" FORCE) unset(HYPRE_ENABLE CACHE) endif() if(DEFINED PETSC_ENABLE) - print_warning("The CMake option PETSC_ENABLE is deprecated" "Use ENABLE_PETSC instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option PETSC_ENABLE is deprecated. " + "Use ENABLE_PETSC instead.") set(ENABLE_PETSC ${PETSC_ENABLE} CACHE BOOL "Enable PETSC support" FORCE) unset(PETSC_ENABLE CACHE) endif() if(DEFINED Trilinos_ENABLE) - print_warning("The CMake option Trilinos_ENABLE is deprecated" "Use ENABLE_TRILINOS instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option Trilinos_ENABLE is deprecated. " + "Use ENABLE_TRILINOS instead.") set(ENABLE_TRILINOS ${Trilinos_ENABLE} CACHE BOOL "Enable Trilinos support" FORCE) unset(Trilinos_ENABLE CACHE) endif() if(DEFINED RAJA_ENABLE) - print_warning("The CMake option RAJA_ENABLE is deprecated" "Use ENABLE_RAJA instead" - MODE DEPRECATION) + message(DEPRECATION "The CMake option RAJA_ENABLE is deprecated. " + "Use ENABLE_RAJA instead.") set(ENABLE_RAJA ${RAJA_ENABLE} CACHE BOOL "Enable RAJA support" FORCE) unset(RAJA_ENABLE CACHE) endif() @@ -145,8 +147,8 @@ endif() # if(DEFINED CUDA_ARCH) - print_warning("The CMake option CUDA_ARCH is deprecated" "Use CMAKE_CUDA_ARCHITECTURES instead" - MODE DEPRECATION) + print_warning("The CMake option CUDA_ARCH is deprecated. " + "Use CMAKE_CUDA_ARCHITECTURES instead.") # convert sm_** to just ** string(REGEX MATCH "[0-9]+" arch_name "${CUDA_ARCH}") set(CMAKE_CUDA_ARCHITECTURES ${arch_name} CACHE STRING "CUDA Architectures" FORCE) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsExampleOptions.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsExampleOptions.cmake index 442faff3f..40d692771 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsExampleOptions.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsExampleOptions.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -23,7 +23,8 @@ sundials_option(EXAMPLES_ENABLE_C BOOL "Build SUNDIALS C examples" ON) # Some TPLs only have C++ examples. Default the C++ examples to ON if any of # these are enabled on the initial configuration pass. if (ENABLE_TRILINOS OR ENABLE_SUPERLUDIST OR ENABLE_XBRAID OR ENABLE_HIP OR - ENABLE_MAGMA OR ENABLE_SYCL OR ENABLE_ONEMKL OR ENABLE_RAJA) + ENABLE_MAGMA OR ENABLE_SYCL OR ENABLE_ONEMKL OR ENABLE_RAJA OR ENABLE_GINKGO OR + ENABLE_KOKKOS) sundials_option(EXAMPLES_ENABLE_CXX BOOL "Build SUNDIALS C++ examples" ON) else() sundials_option(EXAMPLES_ENABLE_CXX BOOL "Build SUNDIALS C++ examples" OFF) @@ -33,65 +34,24 @@ endif() # Options for Fortran Examples # ----------------------------------------------------------------------------- -set(DOCSTR "Build SUNDIALS FORTRAN 77 examples") -if(BUILD_FORTRAN77_INTERFACE) - - sundials_option(EXAMPLES_ENABLE_F77 BOOL "${DOCSTR}" ON) - - # Fortran 77 examples do not support single or extended precision - if(EXAMPLES_ENABLE_F77 AND (SUNDIALS_PRECISION MATCHES "EXTENDED" OR SUNDIALS_PRECISION MATCHES "SINGLE")) - print_warning("F77 examples are not compatible with ${SUNDIALS_PRECISION} precision. " - "Setting EXAMPLES_ENABLE_F77 to OFF.") - force_variable(EXAMPLES_ENABLE_F77 BOOL "${DOCSTR}" OFF) - endif() - - sundials_option(EXAMPLES_ENABLE_F90 BOOL "Build SUNDIALS FORTRAN 90 examples" ON) - - # Fortran 90 examples do not support extended precision - if(EXAMPLES_ENABLE_F90 AND (SUNDIALS_PRECISION MATCHES "EXTENDED")) - print_warning("F90 examples are not compatible with ${SUNDIALS_PRECISION} precision. " - "Setting EXAMPLES_ENABLE_F90 to OFF.") - force_variable(EXAMPLES_ENABLE_F90 BOOL "${DOCSTR}" OFF) - endif() - -else() - - # set back to OFF (in case it was ON) - if(EXAMPLES_ENABLE_F77) - print_warning("EXAMPLES_ENABLE_F77 is ON but BUILD_FORTRAN77_INTERFACE is OFF. " - "Setting EXAMPLES_ENABLE_F77 to OFF.") - force_variable(EXAMPLES_ENABLE_F77 BOOL "${DOCSTR}" OFF) - endif() - -endif() - # F2003 examples (on by default) are an option only if the # Fortran 2003 interface is enabled. set(DOCSTR "Build SUNDIALS Fortran 2003 examples") if(BUILD_FORTRAN_MODULE_INTERFACE) - - sundials_option(EXAMPLES_ENABLE_F2003 BOOL "${DOCSTR}" ON) + set(EXAMPLES_ENABLE_F2003 ON CACHE BOOL "${DOCSTR}") # Fortran 2003 examples only support double precision if(EXAMPLES_ENABLE_F2003 AND (NOT (SUNDIALS_PRECISION MATCHES "DOUBLE"))) - print_warning("F2003 examples are not compatible with ${SUNDIALS_PRECISION} precision. " - "Setting EXAMPLES_ENABLE_F2003 to OFF.") + message(WARNING "F2003 examples are not compatible with ${SUNDIALS_PRECISION} precision. " + "Setting EXAMPLES_ENABLE_F2003 to OFF.") force_variable(EXAMPLES_ENABLE_F2003 BOOL "${DOCSTR}" OFF) endif() - - # Fortran 2003 examples only support 64-bit indices - if(EXAMPLES_ENABLE_F2003 AND (NOT (SUNDIALS_INDEX_SIZE MATCHES "64"))) - print_warning("F2003 examples are not compatible with ${SUNDIALS_INDEX_SIZE}-bit indices. " - "Setting EXAMPLES_ENABLE_F2003 to OFF.") - force_variable(EXAMPLES_ENABLE_F2003 BOOL "${DOCSTR}" OFF) - endif() - else() # set back to OFF (in case it was ON) if(EXAMPLES_ENABLE_F2003) - print_warning("EXAMPLES_ENABLE_F2003 is ON but BUILD_FORTRAN_MODULE_INTERFACE is OFF. " - "Setting EXAMPLES_ENABLE_F2003 to OFF.") + message(WARNING "EXAMPLES_ENABLE_F2003 is ON but BUILD_FORTRAN_MODULE_INTERFACE is OFF. " + "Setting EXAMPLES_ENABLE_F2003 to OFF.") force_variable(EXAMPLES_ENABLE_F2003 BOOL "${DOCSTR}" OFF) endif() @@ -102,9 +62,7 @@ endif() # ----------------------------------------------------------------------------- sundials_option(EXAMPLES_ENABLE_CUDA BOOL "Build SUNDIALS CUDA examples" ON - DEPENDS_ON ENABLE_CUDA - SHOW_IF ENABLE_CUDA) - + DEPENDS_ON ENABLE_CUDA) # ----------------------------------------------------------------------------- # Options for installing examples @@ -117,8 +75,8 @@ sundials_option(EXAMPLES_INSTALL_PATH PATH "Output directory for installing exam # If examples are to be exported, check where we should install them. if(EXAMPLES_INSTALL AND NOT EXAMPLES_INSTALL_PATH) - print_warning("The example installation path is empty. " - "Example installation path was reset to its default value") + message(WARNING "The example installation path is empty. Example installation " + "path was reset to its default value") set(EXAMPLES_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/examples" CACHE STRING "Output directory for installing example files" FORCE) endif() @@ -130,8 +88,6 @@ endif() if(EXAMPLES_ENABLE_C OR EXAMPLES_ENABLE_CXX OR EXAMPLES_ENABLE_CUDA OR - EXAMPLES_ENABLE_F77 OR - EXAMPLES_ENABLE_F90 OR EXAMPLES_ENABLE_F2003) set(_BUILD_EXAMPLES TRUE CACHE INTERNAL "") else() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsIndexSize.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsIndexSize.cmake index b2b1733fe..6498637bd 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsIndexSize.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsIndexSize.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -42,9 +42,8 @@ if(SUNDIALS_INDEX_SIZE MATCHES "64") endforeach() if(NOT SUNDIALS_CINDEX_TYPE) - print_error("No integer type of size 8 was found.\n\ - Tried ${POSSIBLE_INT64}.\n\ - Try setting the advanced option SUNDIALS_INDEX_TYPE.") + message(FATAL_ERROR "No integer type of size 8 was found. Tried " + "${POSSIBLE_INT64}. Try setting the advanced option SUNDIALS_INDEX_TYPE.") endif() # set Fortran integer size too @@ -70,13 +69,12 @@ elseif(SUNDIALS_INDEX_SIZE MATCHES "32") endforeach() if(NOT SUNDIALS_CINDEX_TYPE) - print_error("No integer type of size 4 was found.\n\ - Tried ${POSSIBLE_INT32}\n\ - Try setting the advanced option SUNDIALS_INDEX_TYPE.") + message(FATAL_ERROR "No integer type of size 4 was found. Tried " + "${POSSIBLE_INT32}. Try setting the advanced option SUNDIALS_INDEX_TYPE.") endif() # set Fortran integer size too set(SUNDIALS_FINDEX_TYPE "4") else() - print_error("Invalid index size.") + message(FATAL_ERROR "Invalid index size.") endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCXX.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCXX.cmake index 0d2646a12..32a6a9b00 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCXX.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCXX.cmake @@ -3,7 +3,7 @@ # Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -24,13 +24,27 @@ set(CXX_FOUND TRUE) # compiler and related options. # --------------------------------------------------------------- -set(DOCSTR "The C++ standard to use if C++ is enabled (98, 11, 14, 17, 20)") -sundials_option(CMAKE_CXX_STANDARD STRING "${DOCSTR}" "11" - OPTIONS "98;11;14;17;20") +# Do not allow decaying to previous standards -- generates error if the standard +# is not supported +sundials_option(CMAKE_CXX_STANDARD_REQUIRED BOOL + "Require C++ standard version" ON) + +if(ENABLE_SYCL) + set(DOCSTR "The C++ standard to use if C++ is enabled (17, 20)") + sundials_option(CMAKE_CXX_STANDARD STRING "${DOCSTR}" "17" + OPTIONS "17;20") +else() + set(DOCSTR "The C++ standard to use if C++ is enabled (14, 17, 20)") + sundials_option(CMAKE_CXX_STANDARD STRING "${DOCSTR}" "14" + OPTIONS "14;17;20") +endif() +message(STATUS "CXX standard set to ${CMAKE_CXX_STANDARD}") + +set(DOCSTR "Enable C++ compiler specific extensions") +sundials_option(CMAKE_CXX_EXTENSIONS BOOL "${DOCSTR}" ON) +message(STATUS "C++ extensions set to ${CMAKE_CXX_EXTENSIONS}") # SYCL requries C++17 if(ENABLE_SYCL AND (CMAKE_CXX_STANDARD LESS "17")) - set(CMAKE_CXX_STANDARD "17" CACHE STRING "${DOCSTR}" FORCE) + message(SEND_ERROR "CMAKE_CXX_STANDARD must be >= 17 because ENABLE_SYCL=ON") endif() - -message(STATUS "CXX standard set to ${CMAKE_CXX_STANDARD}") diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCompilers.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCompilers.cmake index 162d30884..7790f6160 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCompilers.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupCompilers.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -27,7 +27,13 @@ include(SundialsIndexSize) if(WIN32) # Under Windows, add compiler directive to inhibit warnings # about use of unsecure functions. - add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + + # Under Windows, we need to have dll and exe files in the + # same directory to run the test suite properly. + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") endif() if(APPLE) @@ -62,18 +68,201 @@ if(BUILD_SHARED_LIBS) endif() # =============================================================== -# Fortran settings +# Configure compiler flags +# +# TODO(DJG): Set flags based on CMAKE__COMPILER_ID # =============================================================== +if(ENABLE_ALL_WARNINGS) + message(STATUS "Enabling all compiler warnings") + + # Avoid numerous warnings from printf + if(SUNDIALS_PRECISION MATCHES "EXTENDED") + set(CMAKE_C_FLAGS "-Wdouble-promotion ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wdouble-promotion ${CMAKE_CXX_FLAGS}") + endif() + + if((SUNDIALS_PRECISION MATCHES "DOUBLE") AND (SUNDIALS_INDEX_SIZE MATCHES "32")) + set(CMAKE_C_FLAGS "-Wconversion -Wno-sign-conversion ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wconversion -Wno-sign-conversion ${CMAKE_CXX_FLAGS}") + endif() + + # Avoid numerous warnings from SWIG generated functions + if(NOT BUILD_FORTRAN_MODULE_INTERFACE) + set(CMAKE_C_FLAGS "-Wmissing-declarations -Wcast-qual ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wmissing-declarations -Wcast-qual ${CMAKE_CXX_FLAGS}") + endif() + + set(CMAKE_C_FLAGS "-Wall -Wpedantic -Wextra -Wshadow ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wall -Wpedantic -Wextra -Wshadow ${CMAKE_CXX_FLAGS}") + + # TODO(DJG): Add -fcheck=all,no-pointer,no-recursion once Jenkins is updated + # to use gfortran > 5.5 which segfaults with -fcheck=array-temps,bounds,do,mem + # no- options were added in gfortran 6 + # + # Exclude run-time pointer checks (no-pointer) because passing null objects + # to SUNDIALS functions (e.g., sunmat => null() to SetLinearSolver) causes a + # run-time error with this check + # + # Exclude checks for subroutines and functions not marked as recursive + # (no-recursion) e.g., ark_brusselator1D_task_local_nls_f2003 calls + # SUNNonlinsolFree from within a custom nonlinear solver implementation of + # SUNNonlinsolFree which causes a run-time error with this check + set(CMAKE_Fortran_FLAGS "-Wall -Wpedantic -Wno-unused-dummy-argument -Wno-c-binding-type -ffpe-summary=none ${CMAKE_Fortran_FLAGS}") +endif() + +if(ENABLE_WARNINGS_AS_ERRORS) + message(STATUS "Enabling compiler warnings as errors") + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Werror") +endif() + +if(ENABLE_ADDRESS_SANITIZER) + message(STATUS "Enabling address sanitizer") + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined") +endif() + +if(SUNDIALS_DEBUG) + message(STATUS "Adding debugging preprocessor directives") + + foreach(debug ${_SUNDIALS_DEBUG_OPTIONS}) + if (${${debug}}) + add_compile_definitions(${debug}) + endif() + endforeach() +endif() + +# =============================================================== +# C settings +# =============================================================== + +set(DOCSTR "The C standard to use (99, 11, 17)") +sundials_option(CMAKE_C_STANDARD STRING "${DOCSTR}" "99" + OPTIONS "99;11;17") +message(STATUS "C standard set to ${CMAKE_C_STANDARD}") + +set(DOCSTR "Enable C compiler specific extensions") +sundials_option(CMAKE_C_EXTENSIONS BOOL "${DOCSTR}" ON) +message(STATUS "C extensions set to ${CMAKE_C_EXTENSIONS}") + +# --------------------------------------------------------------- +# Check for __builtin_expect +# --------------------------------------------------------------- + +check_c_source_compiles(" + #include + int main(void) { + double a = 0.0; + if (__builtin_expect(a < 0, 0)) { + a = 0.0; + } + a = a + 1.0; + printf(\"a=%g\", a); + return 0; + } +" SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT) + +# --------------------------------------------------------------- +# Check for assume related extensions +# --------------------------------------------------------------- + +# gcc >= 13 should have __attribute__((assume)) +check_c_source_compiles(" + #include + int main(void) { + double a = 0.0; + #if defined(__has_attribute) + # if !__has_attribute(assume) + # error no assume + # endif + #else + #error no __has_attribute + #endif + __attribute__((assume(a >= 0.0))); + a = a + 1.0; + printf(\"a=%g\", a); + return 0; + } +" SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME) + +# LLVM based compilers should have __builtin_assume +if(NOT SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME) + check_c_source_compiles(" + #include + int main(void) { + double a = 0.0; + __builtin_assume(a >= 0.0); + a = a + 1.0; + printf(\"a=%g\", a); + return 0; + } + " SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME) +endif() + +# MSVC provides __assume +if(NOT (SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME OR SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME)) + check_c_source_compiles(" + #include + int main(void) { + double a = 0.0; + __assume(a >= 0.0)); + a = a + 1.0; + printf(\"a=%g\", a); + return 0; + } + " SUNDIALS_C_COMPILER_HAS_ASSUME) +endif() + # --------------------------------------------------------------- -# A Fortran compiler is needed to: -# (a) Determine compiler the name-mangling scheme if the F77 -# interfaces or LAPACK are enabled -# (b) Compile example programs if F77 or F90 examples are enabled +# Check for unused extension # --------------------------------------------------------------- -# Do we need a Fortran name-mangling scheme? -if(BUILD_FORTRAN77_INTERFACE OR ENABLE_LAPACK) +check_c_source_compiles(" + int main(void) { + __attribute__((unused)) double a = 0.0; + return 0; + } +" SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED) + +# --------------------------------------------------------------- +# Check for POSIX timers +# --------------------------------------------------------------- +include(SundialsPOSIXTimers) + +if(SUNDIALS_POSIX_TIMERS AND POSIX_TIMERS_NEED_POSIX_C_SOURCE) + set(DOCSTR "Value of _POSIX_C_SOURCE") + sundials_option(SUNDIALS_POSIX_C_SOURCE STRING "${DOCSTR}" "200112L" + ADVANCED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=${SUNDIALS_POSIX_C_SOURCE}") +endif() + + +# --------------------------------------------------------------- +# Check for deprecated attribute with message +# --------------------------------------------------------------- +if(WIN32) + set(COMPILER_DEPRECATED_MSG_ATTRIBUTE "__declspec(deprecated(msg))" CACHE INTERNAL "") +else() + set(COMPILER_DEPRECATED_MSG_ATTRIBUTE "__attribute__ ((__deprecated__(msg)))" CACHE INTERNAL "") +endif() +check_c_source_compiles(" + #define msg \"test\" + ${COMPILER_DEPRECATED_MSG_ATTRIBUTE} int somefunc(void) { return 0; } + int main(void) { return somefunc();}" COMPILER_HAS_DEPRECATED_MSG +) + +# =============================================================== +# Fortran settings +# =============================================================== + +# When LAPACK is enabled we will need a Fortran compiler to infer the +# name-mangling scheme if it is not set by the user +if(ENABLE_LAPACK) set(NEED_FORTRAN_NAME_MANGLING TRUE) endif() @@ -86,83 +275,86 @@ endif() # or the user needs to override the inferred or default scheme, the following # options specify the case and number of appended underscores corresponding to # the Fortran name-mangling scheme of symbol names that do not themselves -# contain underscores. This is all we really need for the FCMIX and LAPACK -# interfaces. A working Fortran compiler is only necessary for building Fortran -# example programs. +# contain underscores. This is all we really need for the LAPACK interfaces. A +# working Fortran compiler is only necessary for building Fortran example +# programs. # ------------------------------------------------------------------------------ # The case to use in the name-mangling scheme -sundials_option(SUNDIALS_F77_FUNC_CASE STRING - "case of Fortran function names (lower/upper)" +sundials_option(SUNDIALS_LAPACK_CASE STRING + "case of LAPACK function names (lower/upper)" "" ADVANCED) # The number of underscores of appended in the name-mangling scheme -sundials_option(SUNDIALS_F77_FUNC_UNDERSCORES STRING - "number of underscores appended to Fortran function names (none/one/two)" +sundials_option(SUNDIALS_LAPACK_UNDERSCORES STRING + "number of underscores appended to LAPACK function names (none/one/two)" "" ADVANCED) # If used, both case and underscores must be set -if((NOT SUNDIALS_F77_FUNC_CASE) AND SUNDIALS_F77_FUNC_UNDERSCORES) - print_error("If SUNDIALS_F77_FUNC_UNDERSCORES is set, " - "SUNDIALS_F77_FUNC_CASE must also be set.") +if((NOT SUNDIALS_LAPACK_CASE) AND SUNDIALS_LAPACK_UNDERSCORES) + message(FATAL_ERROR "If SUNDIALS_LAPACK_UNDERSCORES is set, " + "SUNDIALS_LAPACK_CASE must also be set.") endif() -if(SUNDIALS_F77_FUNC_CASE AND (NOT SUNDIALS_F77_FUNC_UNDERSCORES)) - print_error("If SUNDIALS_F77_FUNC_CASE is set, " - "SUNDIALS_F77_FUNC_UNDERSCORES must also be set.") +if(SUNDIALS_LAPACK_CASE AND (NOT SUNDIALS_LAPACK_UNDERSCORES)) + message(FATAL_ERROR "If SUNDIALS_LAPACK_CASE is set, " + "SUNDIALS_LAPACK_UNDERSCORES must also be set.") endif() # Did the user provide a name-mangling scheme? -if(SUNDIALS_F77_FUNC_CASE AND SUNDIALS_F77_FUNC_UNDERSCORES) +if(SUNDIALS_LAPACK_CASE AND SUNDIALS_LAPACK_UNDERSCORES) - string(TOUPPER ${SUNDIALS_F77_FUNC_CASE} SUNDIALS_F77_FUNC_CASE) - string(TOUPPER ${SUNDIALS_F77_FUNC_UNDERSCORES} SUNDIALS_F77_FUNC_UNDERSCORES) + string(TOUPPER ${SUNDIALS_LAPACK_CASE} SUNDIALS_LAPACK_CASE) + string(TOUPPER ${SUNDIALS_LAPACK_UNDERSCORES} SUNDIALS_LAPACK_UNDERSCORES) # Based on the given case and number of underscores, set the C preprocessor # macro definitions. Since SUNDIALS never uses symbols names containing # underscores we set the name-mangling schemes to be the same. In general, # names of symbols with and without underscore may be mangled differently # (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__) - if(SUNDIALS_F77_FUNC_CASE MATCHES "LOWER") - if(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "NONE") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) name") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) name") - elseif(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "ONE") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) name ## _") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) name ## _") - elseif(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "TWO") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) name ## __") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) name ## __") + if(SUNDIALS_LAPACK_CASE MATCHES "LOWER") + if(SUNDIALS_LAPACK_UNDERSCORES MATCHES "NONE") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name") + elseif(SUNDIALS_LAPACK_UNDERSCORES MATCHES "ONE") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") + elseif(SUNDIALS_LAPACK_UNDERSCORES MATCHES "TWO") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") else() - print_error("Invalid SUNDIALS_F77_FUNC_UNDERSCORES option.") + message(FATAL_ERROR "Invalid SUNDIALS_LAPACK_UNDERSCORES option.") endif() - elseif(SUNDIALS_F77_FUNC_CASE MATCHES "UPPER") - if(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "NONE") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) NAME") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) NAME") - elseif(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "ONE") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) NAME ## _") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) NAME ## _") - elseif(SUNDIALS_F77_FUNC_UNDERSCORES MATCHES "TWO") - set(F77_MANGLE_MACRO1 "#define SUNDIALS_F77_FUNC(name,NAME) NAME ## __") - set(F77_MANGLE_MACRO2 "#define SUNDIALS_F77_FUNC_(name,NAME) NAME ## __") + elseif(SUNDIALS_LAPACK_CASE MATCHES "UPPER") + if(SUNDIALS_LAPACK_UNDERSCORES MATCHES "NONE") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME") + elseif(SUNDIALS_LAPACK_UNDERSCORES MATCHES "ONE") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") + elseif(SUNDIALS_LAPACK_UNDERSCORES MATCHES "TWO") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") else() - print_error("Invalid SUNDIALS_F77_FUNC_UNDERSCORES option.") + message(FATAL_ERROR "Invalid SUNDIALS_LAPACK_UNDERSCORES option.") endif() else() - print_error("Invalid SUNDIALS_F77_FUNC_CASE option.") + message(FATAL_ERROR "Invalid SUNDIALS_LAPACK_CASE option.") endif() # name-mangling scheme has been manually set set(NEED_FORTRAN_NAME_MANGLING FALSE) + configure_file( + ${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in + ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h + ) + endif() # Do we need a Fortran compiler? if(BUILD_FORTRAN_MODULE_INTERFACE OR - EXAMPLES_ENABLE_F77 OR - EXAMPLES_ENABLE_F90 OR NEED_FORTRAN_NAME_MANGLING) include(SundialsSetupFortran) endif() @@ -171,26 +363,17 @@ endif() # C++ settings # =============================================================== -# --------------------------------------------------------------- -# A C++ compiler is only needed if: -# (a) C++ examples are enabled -# (b) CUDA is enabled -# (c) HIP is enabled -# (d) SYCL is enabled -# (e) RAJA is enabled -# (f) Trilinos is enabled -# (g) SuperLU_DIST is enabled -# (e) MAGMA is enabled -# --------------------------------------------------------------- - -if(EXAMPLES_ENABLE_CXX OR +if(BUILD_BENCHMARKS OR SUNDIALS_TEST_UNITTESTS OR EXAMPLES_ENABLE_CXX OR ENABLE_CUDA OR ENABLE_HIP OR ENABLE_SYCL OR ENABLE_RAJA OR ENABLE_TRILINOS OR ENABLE_SUPERLUDIST OR - ENABLE_MAGMA) + ENABLE_MAGMA OR + ENABLE_GINKGO OR + ENABLE_KOKKOS OR + ENABLE_ADIAK) include(SundialsSetupCXX) endif() @@ -210,27 +393,16 @@ endif() if(ENABLE_HIP) include(SundialsSetupHIP) + # we treat HIP as both a TPL and a language list(APPEND SUNDIALS_TPL_LIST "HIP") endif() -# =============================================================== -# Default flags for build types -# =============================================================== - -set(CMAKE_C_FLAGS_DEV "${CMAKE_C_FLAGS_DEV} -g -O0 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror") -set(CMAKE_CXX_FLAGS_DEV "${CMAKE_CXX_FLAGS_DEV} -g -O0 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror") -set(CMAKE_Fortran_FLAGS_DEV "${CMAKE_Fortran_FLAGS_DEV} -g -O0 -Wall -Wpedantic -ffpe-summary=none") -set(CMAKE_C_FLAGS_DEVSTRICT "-std=c89 ${CMAKE_C_FLAGS_DEV}") -set(CMAKE_CXX_FLAGS_DEVSTRICT "${CMAKE_CXX_FLAGS_DEV}") -set(CMAKE_Fortran_FLAGS_DEVSTRICT "${CMAKE_Fortran_FLAGS_DEV}") - # =============================================================== # Configure presentation of language options # =============================================================== -set(build_types DEBUG RELEASE RELWITHDEBINFO MINSIZEREL DEV DEVSTRICT) +# List of enabled languages set(_SUNDIALS_ENABLED_LANGS "C") - if(CXX_FOUND) list(APPEND _SUNDIALS_ENABLED_LANGS "CXX") endif() @@ -241,13 +413,15 @@ if(CUDA_FOUND) list(APPEND _SUNDIALS_ENABLED_LANGS "CUDA") endif() +# Upper case version of build type +string(TOUPPER "${CMAKE_BUILD_TYPE}" _cmake_build_type) + # Make build type specific flag options ADVANCED, # except for the one corresponding to the current build type foreach(lang ${_SUNDIALS_ENABLED_LANGS}) - foreach(build_type ${build_types}) - string(TOUPPER "${CMAKE_BUILD_TYPE}" _cmake_build_type) - if(${_cmake_build_type} MATCHES "${build_type}") - message("Appending ${lang} ${build_type} flags") + foreach(build_type DEBUG;RELEASE;RELWITHDEBINFO;MINSIZEREL) + if("${_cmake_build_type}" STREQUAL "${build_type}") + message(STATUS "Appending ${lang} ${build_type} flags") mark_as_advanced(CLEAR CMAKE_${lang}_FLAGS_${build_type}) else() mark_as_advanced(FORCE CMAKE_${lang}_FLAGS_${build_type}) @@ -256,3 +430,63 @@ foreach(lang ${_SUNDIALS_ENABLED_LANGS}) # show the language compiler and flags mark_as_advanced(CLEAR CMAKE_${lang}_COMPILER CMAKE_${lang}_FLAGS) endforeach() + + +# =============================================================== +# Configure compilers for installed examples +# =============================================================== + +foreach(lang ${_SUNDIALS_ENABLED_LANGS}) + if(ENABLE_MPI) + if(DEFINED MPI_${lang}_COMPILER) + set(_EXAMPLES_${lang}_COMPILER "${MPI_${lang}_COMPILER}" CACHE INTERNAL "${lang} compiler for installed examples") + endif() + else() + set(_EXAMPLES_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE INTERNAL "${lang} compiler for installed examples") + endif() +endforeach() + + +# =============================================================== +# Configure clang-tidy for linting +# =============================================================== + +set(SUNDIALS_DEV_CLANG_TIDY_DIR ${CMAKE_BINARY_DIR}/clang-tidy/) + +if(SUNDIALS_DEV_CLANG_TIDY) + find_program(CLANG_TIDY_PATH NAMES clang-tidy) + if(NOT CLANG_TIDY_PATH) + message(FATAL_ERROR "Could not find the program clang-tidy") + endif() + message(STATUS "Found clang-tidy: ${CLANG_TIDY_PATH}") + + make_directory(${SUNDIALS_DEV_CLANG_TIDY_DIR}) + if(SUNDIALS_DEV_CLANG_TIDY_FIX_ERRORS) + set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_PATH} -format-style='file' --fix) + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PATH} -format-style='file' --fix) + else() + set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_PATH} + -format-style='file' + --export-fixes=${SUNDIALS_DEV_CLANG_TIDY_DIR}/clang-tidy-fixes.yaml + ) + set(CMAKE_CXX_CLANG_TIDY + ${CLANG_TIDY_PATH} + -format-style='file' + --export-fixes=${SUNDIALS_DEV_CLANG_TIDY_DIR}/clang-tidy-cxx-fixes.yaml + ) + endif() +endif() + +if(SUNDIALS_DEV_IWYU) + find_program(IWYU_PATH NAMES include-what-you-use iwyu) + if(NOT IWYU_PATH) + message(FATAL_ERROR "Could not find the program include-what-you-use") + endif() + message(STATUS "Found IWYU: ${IWYU_PATH}") + set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH} + -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/scripts/iwyu.imp + -Xiwyu --error_always) + set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_PATH} + -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/scripts/iwyu.imp + -Xiwyu --error_always) +endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupConfig.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupConfig.cmake index 4d4cae83d..482a267ac 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupConfig.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupConfig.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -11,8 +11,8 @@ # SPDX-License-Identifier: BSD-3-Clause # SUNDIALS Copyright End # --------------------------------------------------------------- -# Configures the SUNDIALS config header files: -# sundials_config.h and sundials_fconfig.h +# Configures the SUNDIALS config header file: +# sundials_config.h # --------------------------------------------------------------- # ============================================================================ @@ -26,32 +26,25 @@ set(PRECISION_LEVEL "#define SUNDIALS_${SUNDIALS_PRECISION}_PRECISION 1") # prepare substitution variable INDEX_TYPE for sundials_config.h set(INDEX_TYPE "#define SUNDIALS_INT${SUNDIALS_INDEX_SIZE}_T 1") -# Prepare substitution variable SUNDIALS_EXPORT for sundials_config.h -# When building shared SUNDIALS libraries under Windows, use -# #define SUNDIALS_EXPORT __declspec(dllexport) -# When linking to shared SUNDIALS libraries under Windows, use -# #define SUNDIALS_EXPORT __declspec(dllimport) -# In all other cases (other platforms or static libraries -# under Windows), the SUNDIALS_EXPORT macro is empty. -# See https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/BuildingWinDLL -if(BUILD_SHARED_LIBS) - set(SUNDIALS_EXPORT_MACRO -"#if defined(_WIN32) - #if defined(SUNDIALS_EXPORT) - #define SUNDIALS_EXPORT __declspec(dllexport) - #else - #define SUNDIALS_EXPORT __declspec(dllimport) - #endif -#else - #define SUNDIALS_EXPORT -#endif") +if(COMPILER_HAS_DEPRECATED_MSG) + set(SUNDIALS_DEPRECATED_MSG_MACRO "${COMPILER_DEPRECATED_MSG_ATTRIBUTE}") +else() + set(SUNDIALS_DEPRECATED_MSG_MACRO "SUNDIALS_DEPRECATED") endif() -# prepare substitution variable SUNDIALS_USE_GENERIC_MATH for sundials_config.h -if(USE_GENERIC_MATH) - set(SUNDIALS_USE_GENERIC_MATH TRUE) +if($ENV{CI_JOB_ID}) + set(JOB_ID $ENV{CI_JOB_ID}) +else() + string(TIMESTAMP JOB_ID "%Y%m%d%H%M%S") endif() +if($ENV{CI_JOB_STARTED_AT}) + set(JOB_START_TIME $ENV{CI_JOB_STARTED_AT}) +else() + string(TIMESTAMP JOB_START_TIME "%Y%m%d%H%M%S") +endif() + + # ============================================================================ # Generate macros and substitution variables related to TPLs # that SUNDIALS is being built with. @@ -66,10 +59,10 @@ foreach(_item ${SUNDIALS_BUILD_LIST}) endif() endforeach() -# prepare substitution variable SUNDIALS_MPI_ENABLED for sundials_config.h -if(ENABLE_MPI) - set(SUNDIALS_MPI_ENABLED TRUE) -endif() +# prepare substitution variable SUNDIALS_${TPL NAME}_ENABLED for sundials_config.h +foreach(tpl ${SUNDIALS_TPL_LIST}) + set(SUNDIALS_${tpl}_ENABLED TRUE) +endforeach() # prepare substitution variable SUNDIALS_TRILINOS_HAVE_MPI for sundials_config.h if(Trilinos_MPI) @@ -81,35 +74,21 @@ foreach(backend ${SUNDIALS_RAJA_BACKENDS}) set(SUNDIALS_RAJA_BACKENDS_${backend} TRUE) endforeach() +# prepare substitution variable(s) SUNDIALS_GINKGO_BACKENDS_* +foreach(backend ${SUNDIALS_GINKGO_BACKENDS}) + set(SUNDIALS_GINKGO_BACKENDS_${backend} TRUE) +endforeach() + # prepare substitution variable(s) SUNDIALS_MAGMA_BACKENDS_* foreach(backend ${SUNDIALS_MAGMA_BACKENDS}) set(SUNDIALS_MAGMA_BACKENDS_${backend} TRUE) endforeach() # prepare substitution variable SUNDIALS_HAVE_POSIX_TIMERS for sundials_config.h -if(POSIX_TIMERS_TEST_OK) # set in SundialsPOSIXTimers.cmake +if(SUNDIALS_POSIX_TIMERS) # set in SundialsPOSIXTimers.cmake set(SUNDIALS_HAVE_POSIX_TIMERS TRUE) endif() -# ============================================================================ -# Generate macros and substitution variables for the FCMIX interface. -# ============================================================================ - -# prepare substitution variable FPRECISION_LEVEL for sundials_fconfig.h -if(SUNDIALS_PRECISION MATCHES "SINGLE") - set(FPRECISION_LEVEL "4") -endif(SUNDIALS_PRECISION MATCHES "SINGLE") -if(SUNDIALS_PRECISION MATCHES "DOUBLE") - set(FPRECISION_LEVEL "8") -endif(SUNDIALS_PRECISION MATCHES "DOUBLE") -if(SUNDIALS_PRECISION MATCHES "EXTENDED") - set(FPRECISION_LEVEL "16") -endif(SUNDIALS_PRECISION MATCHES "EXTENDED") - -# always define FMPI_COMM_F2C substitution variable in sundials_fconfig.h -set(F77_MPI_COMM_F2C "#define SUNDIALS_MPI_COMM_F2C 1") -set(FMPI_COMM_F2C ".true.") - # ============================================================================= # All required substitution variables should be available at this point. # Generate the header file and place it in the binary dir. @@ -119,7 +98,3 @@ configure_file( ${PROJECT_SOURCE_DIR}/include/sundials/sundials_config.in ${PROJECT_BINARY_DIR}/include/sundials/sundials_config.h ) -configure_file( - ${PROJECT_SOURCE_DIR}/include/sundials/sundials_fconfig.in - ${PROJECT_BINARY_DIR}/include/sundials/sundials_fconfig.h - ) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTPLs.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTPLs.cmake index 0b8339340..fe57c20a7 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTPLs.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTPLs.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -15,7 +15,12 @@ # --------------------------------------------------------------- # --------------------------------------------------------------- -# Find MPI. +# Setup MPI, OpenMP, and OpenMP offload first as other TPLs may +# need targets or variables corresponding to these TPLs. +# --------------------------------------------------------------- + +# --------------------------------------------------------------- +# Find MPI # --------------------------------------------------------------- if(ENABLE_MPI) @@ -42,57 +47,62 @@ if(ENABLE_OPENMP_DEVICE) endif() # --------------------------------------------------------------- -# Find PThreads +# Setup other TPLs (listed in alphabetical order) # --------------------------------------------------------------- -if(ENABLE_PTHREAD) - include(SundialsPthread) - list(APPEND SUNDIALS_TPL_LIST "PTHREAD") +# --------------------------------------------------------------- +# Find (and test) the Adiak libraries +# --------------------------------------------------------------- + +if(ENABLE_ADIAK) + include(SundialsAdiak) + list(APPEND SUNDIALS_TPL_LIST "ADIAK") endif() # --------------------------------------------------------------- -# Find (and test) the LAPACK and BLAS libraries +# Find (and test) the Caliper libraries # --------------------------------------------------------------- -if(ENABLE_LAPACK) - include(SundialsLapack) - list(APPEND SUNDIALS_TPL_LIST "BLAS_LAPACK") +if(ENABLE_CALIPER) + include(SundialsCaliper) + list(APPEND SUNDIALS_TPL_LIST "CALIPER") endif() # --------------------------------------------------------------- -# Find (and test) the MAGMA libraries +# Find (and test) the Ginkgo libraries # --------------------------------------------------------------- -if(ENABLE_MAGMA) - include(SundialsMAGMA) - list(APPEND SUNDIALS_TPL_LIST "MAGMA") +if(ENABLE_GINKGO) + include(SundialsGinkgo) + list(APPEND SUNDIALS_TPL_LIST "GINKGO") endif() + # --------------------------------------------------------------- -# Find (and test) the oneMKL libraries +# Find (and test) the hypre libraries # --------------------------------------------------------------- -if(ENABLE_ONEMKL) - include(SundialsONEMKL) - list(APPEND SUNDIALS_TPL_LIST "ONEMKL") +if(ENABLE_HYPRE) + include(SundialsHypre) + list(APPEND SUNDIALS_TPL_LIST "HYPRE") endif() # --------------------------------------------------------------- -# Find (and test) the SuperLUDIST libraries +# Find (and test) Kokkos # --------------------------------------------------------------- -if(ENABLE_SUPERLUDIST) - include(SundialsSuperLUDIST) - list(APPEND SUNDIALS_TPL_LIST "SUPERLUDIST") +if(ENABLE_KOKKOS) + include(SundialsKokkos) + list(APPEND SUNDIALS_TPL_LIST "KOKKOS") endif() # --------------------------------------------------------------- -# Find (and test) the SUPERLUMT libraries +# Find (and test) Kokkos Kernels # --------------------------------------------------------------- -if(ENABLE_SUPERLUMT) - include(SundialsSuperLUMT) - list(APPEND SUNDIALS_TPL_LIST "SUPERLUMT") +if(ENABLE_KOKKOS_KERNELS) + include(SundialsKokkosKernels) + list(APPEND SUNDIALS_TPL_LIST "KOKKOS_KERNELS") endif() # --------------------------------------------------------------- @@ -105,12 +115,30 @@ if(ENABLE_KLU) endif() # --------------------------------------------------------------- -# Find (and test) the hypre libraries +# Find (and test) the LAPACK and BLAS libraries # --------------------------------------------------------------- -if(ENABLE_HYPRE) - include(SundialsHypre) - list(APPEND SUNDIALS_TPL_LIST "HYPRE") +if(ENABLE_LAPACK) + include(SundialsLapack) + list(APPEND SUNDIALS_TPL_LIST "BLAS_LAPACK") +endif() + +# --------------------------------------------------------------- +# Find (and test) the MAGMA libraries +# --------------------------------------------------------------- + +if(ENABLE_MAGMA) + include(SundialsMAGMA) + list(APPEND SUNDIALS_TPL_LIST "MAGMA") +endif() + +# --------------------------------------------------------------- +# Find (and test) the oneMKL libraries +# --------------------------------------------------------------- + +if(ENABLE_ONEMKL) + include(SundialsONEMKL) + list(APPEND SUNDIALS_TPL_LIST "ONEMKL") endif() # --------------------------------------------------------------- @@ -122,6 +150,15 @@ if(ENABLE_PETSC) list(APPEND SUNDIALS_TPL_LIST "PETSC") endif() +# --------------------------------------------------------------- +# Find PThreads +# --------------------------------------------------------------- + +if(ENABLE_PTHREAD) + include(SundialsPthread) + list(APPEND SUNDIALS_TPL_LIST "PTHREAD") +endif() + # ------------------------------------------------------------- # Find (and test) RAJA # ------------------------------------------------------------- @@ -131,6 +168,24 @@ if(ENABLE_RAJA) list(APPEND SUNDIALS_TPL_LIST "RAJA") endif() +# --------------------------------------------------------------- +# Find (and test) the SuperLUDIST libraries +# --------------------------------------------------------------- + +if(ENABLE_SUPERLUDIST) + include(SundialsSuperLUDIST) + list(APPEND SUNDIALS_TPL_LIST "SUPERLUDIST") +endif() + +# --------------------------------------------------------------- +# Find (and test) the SUPERLUMT libraries +# --------------------------------------------------------------- + +if(ENABLE_SUPERLUMT) + include(SundialsSuperLUMT) + list(APPEND SUNDIALS_TPL_LIST "SUPERLUMT") +endif() + # ------------------------------------------------------------- # Find (and test) Trilinos # ------------------------------------------------------------- @@ -148,9 +203,3 @@ if(ENABLE_XBRAID) include(SundialsXBRAID) list(APPEND SUNDIALS_TPL_LIST "XBRAID") endif() - -# --------------------------------------------------------------- -# Check for POSIX timers -# --------------------------------------------------------------- - -include(SundialsPOSIXTimers) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTesting.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTesting.cmake index 0f1dd066f..11a445900 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTesting.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsSetupTesting.cmake @@ -2,7 +2,7 @@ # Programmer(s): David J. Gardner @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -14,42 +14,29 @@ # Enable SUNDIALS Testing # --------------------------------------------------------------- -# Include development examples in regression tests -sundials_option(SUNDIALS_TEST_DEVTESTS BOOL "Include development tests in make test" OFF ADVANCED) - -# Include unit tests in regression tests -sundials_option(SUNDIALS_TEST_UNITTESTS BOOL "Include unit tests in make test" OFF ADVANCED) - # Enable testing with 'make test' include(CTest) -# Add unit tests to the build if they are enabled -if(SUNDIALS_TEST_UNITTESTS) - add_subdirectory(test/unit_tests) -endif() - # Check if development tests are enabled -if(SUNDIALS_TEST_DEVTESTS) - - message("SUNDIALS Development testing") - +if (SUNDIALS_TEST_DEVTESTS OR BUILD_BENCHMARKS) # Python is needed to use the test runner - find_package(PythonInterp REQUIRED) - if(${PYTHON_VERSION_MAJOR} LESS 3) - if(${PYTHON_VERSION_MINOR} LESS 7) - print_warning("Python version must be 2.7.x or greater to run development tests" - "Examples will build but 'make test' may fail.") - endif() - endif() + find_package(Python3 REQUIRED) # look for the testRunner script in the test directory find_program(TESTRUNNER testRunner PATHS test NO_DEFAULT_PATH) if(NOT TESTRUNNER) - print_error("Could not locate testRunner. Set SUNDIALS_TEST_DEVTESTS=OFF to continue.") + message(FATAL_ERROR "Could not locate testRunner. Set SUNDIALS_TEST_DEVTESTS=OFF or BUILD_BENCHMARKS=OFF to continue.") endif() message(STATUS "Found testRunner: ${TESTRUNNER}") set(TESTRUNNER ${TESTRUNNER} CACHE INTERNAL "") +endif() + +# Check if development tests are enabled +if(SUNDIALS_TEST_DEVTESTS) + + message("SUNDIALS Development testing") + # Create the default test output directory set(TEST_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Testing/output) @@ -69,19 +56,95 @@ if(SUNDIALS_TEST_DEVTESTS) if(SUNDIALS_TEST_ANSWER_DIR) message(STATUS "Using non-default test answer directory: ${SUNDIALS_TEST_ANSWER_DIR}") if(NOT EXISTS ${SUNDIALS_TEST_ANSWER_DIR}) - print_error("SUNDIALS_TEST_ANSWER_DIR does not exist!") + message(FATAL_ERROR "SUNDIALS_TEST_ANSWER_DIR does not exist!") + endif() + endif() + + # If a non-default caliper output directory was provided make sure it exists + if(SUNDIALS_CALIPER_OUTPUT_DIR) + message(STATUS "Using non-default caliper output directory: ${SUNDIALS_CALIPER_OUTPUT_DIR}") + if(NOT EXISTS ${SUNDIALS_CALIPER_OUTPUT_DIR}/Example/${JOB_ID}) + file(MAKE_DIRECTORY ${SUNDIALS_CALIPER_OUTPUT_DIR}/Example/${JOB_ID}) endif() endif() # Check if using non-default comparison precisions when testing - if(SUNDIALS_TEST_FLOAT_PRECISION) + if(SUNDIALS_TEST_FLOAT_PRECISION GREATER_EQUAL "0") message(STATUS "Using non-default float precision: ${SUNDIALS_TEST_FLOAT_PRECISION}") endif() - if(SUNDIALS_TEST_INTEGER_PRECISION) + if(SUNDIALS_TEST_INTEGER_PRECISION GREATER_EQUAL "0") message(STATUS "Using non-default integer precision: ${SUNDIALS_TEST_INTEGER_PRECISION}") endif() + # + # Target to run tests in CI containers + # + if(NOT SUNDIALS_TEST_CONTAINER_EXE) + find_program(container_exe docker) + if(NOT container_exe) + find_program(container_exe podman) + endif() + set(SUNDIALS_TEST_CONTAINER_EXE ${container_exe} CACHE PATH "Path to docker or podman" FORCE) + endif() + + if(SUNDIALS_TEST_CONTAINER_EXE) + add_custom_target(setup_local_ci + ${CMAKE_COMMAND} -E cmake_echo_color --cyan + "Pulled SUNDIALS CI containers.") + + add_custom_target(test_local_ci + ${CMAKE_COMMAND} -E cmake_echo_color --cyan + "All testing with SUNDIALS CI containers complete.") + + macro(add_local_ci_target index_size precision tag) + string(TOLOWER "${precision}" precision_) + set(container sundials-ci-int${index_size}-${precision_}) + set(container_exe_args run ${SUNDIALS_TEST_CONTAINER_RUN_EXTRA_ARGS} -t -d --name ${container} --cap-add SYS_PTRACE + -v ${CMAKE_SOURCE_DIR}:${SUNDIALS_TEST_CONTAINER_MNT} ghcr.io/llnl/${container}:${tag}) + add_custom_target(setup_local_ci_${index_size}_${precision_} + COMMENT "Pulling SUNDIALS CI container ghcr.io/llnl/${container}:${tag}" + COMMAND ${SUNDIALS_TEST_CONTAINER_EXE} ${container_exe_args}) + add_dependencies(setup_local_ci setup_local_ci_${index_size}_${precision_}) + + set(container_test_exe ./test_driver.sh) + set(container_test_exe_args --testtype CUSTOM --env env/docker.sh --tpls --sunrealtype ${precision_} --indexsize ${index_size}) + set(container_exe_args exec -w ${SUNDIALS_TEST_CONTAINER_MNT}/test ${container} ${container_test_exe} ${container_test_exe_args}) + add_custom_target(test_local_ci_${index_size}_${precision_} + COMMENT "Running tests in CI container ${container}:${tag}" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND ${SUNDIALS_TEST_CONTAINER_EXE} ${container_exe_args} + VERBATIM) + add_dependencies(test_local_ci test_local_ci_${index_size}_${precision_}) + + unset(container) + unset(container_exe_args) + unset(container_test_exe) + unset(container_test_exe_args) + endmacro() + + add_local_ci_target(${SUNDIALS_INDEX_SIZE} ${SUNDIALS_PRECISION} latest) + endif() + +endif() + +# Check if unit tests are enabled +if(SUNDIALS_TEST_UNITTESTS AND SUNDIALS_TEST_ENABLE_GTEST) + # find_package(GTest) + if(NOT (TARGET GTest::gtest_main OR TARGET GTest::Main)) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + GIT_TAG v1.14.0 + ) + if(WIN32) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + endif() + FetchContent_MakeAvailable(googletest) + include(GoogleTest) + endif() endif() # If examples are installed, create post install smoke test targets @@ -109,4 +172,16 @@ if(EXAMPLES_INSTALL) ${CMAKE_COMMAND} -E cmake_echo_color --cyan "All installation tests complete.") -endif() \ No newline at end of file +endif() + +# If benchmarks are enabled, set up `make benchmark` +if(BUILD_BENCHMARKS) + + message("SUNDIALS Benchmarking") + + # Create benchmark targets + add_custom_target(benchmark + ${CMAKE_COMMAND} -E cmake_echo_color --cyan + "All benchmarks complete." + ) +endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/SundialsTPLOptions.cmake b/deps/AMICI/ThirdParty/sundials/cmake/SundialsTPLOptions.cmake index b8c7d8b85..36e0dc5a1 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/SundialsTPLOptions.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/SundialsTPLOptions.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -49,7 +49,7 @@ sundials_option(ENABLE_CUDA BOOL "Enable CUDA support" OFF) # CMake 3.18 adds this option. sundials_option(CMAKE_CUDA_ARCHITECTURES STRING "Target CUDA architecture" "70" - SHOW_IF ENABLE_CUDA) + DEPENDS_ON ENABLE_CUDA) # ------------------------------------------------------------- # Enable HIP support? @@ -61,16 +61,36 @@ sundials_option(ENABLE_HIP BOOL "Enable HIP support" OFF) # ------------------------------------------------------------- sundials_option(ENABLE_SYCL BOOL "Enable SYCL support" OFF) +sundials_option(SUNDIALS_SYCL_2020_UNSUPPORTED BOOL + "Disable the use of some SYCL 2020 features in SUNDIALS libraries and examples" OFF + DEPENDS_ON ENABLE_SYCL + ADVANCED) + # --------------------------------------------------------------- # Enable LAPACK support? # --------------------------------------------------------------- sundials_option(ENABLE_LAPACK BOOL "Enable Lapack support" OFF) sundials_option(LAPACK_LIBRARIES STRING "Lapack and Blas libraries" "${LAPACK_LIBRARIES}" - SHOW_IF ENABLE_LAPACK) + DEPENDS_ON ENABLE_LAPACK) sundials_option(LAPACK_WORKS BOOL "Set to ON to force CMake to accept a given LAPACK configuration" OFF - SHOW_IF ENABLE_LAPACK + DEPENDS_ON ENABLE_LAPACK + ADVANCED) + +# --------------------------------------------------------------- +# Enable Ginkgo support? +# --------------------------------------------------------------- +sundials_option(ENABLE_GINKGO BOOL "Enable Ginkgo support" OFF) + +sundials_option(Ginkgo_DIR PATH "Path to the root of a Ginkgo installation" "${Ginkgo_DIR}" + DEPENDS_ON ENABLE_GINKGO) + +sundials_option(SUNDIALS_GINKGO_BACKENDS STRING "Which Ginkgo backend(s) to build the SUNDIALS Ginkgo interfaces for (REF, OMP, CUDA, HIP, SYCL)" "REF;OMP" + DEPENDS_ON ENABLE_GINKGO) + +sundials_option(GINKGO_WORKS BOOL "Set to ON to force CMake to accept a given Ginkgo configuration" OFF + DEPENDS_ON ENABLE_GINKGO ADVANCED) # --------------------------------------------------------------- @@ -79,14 +99,14 @@ sundials_option(LAPACK_WORKS BOOL "Set to ON to force CMake to accept a given LA sundials_option(ENABLE_MAGMA BOOL "Enable MAGMA support" OFF) sundials_option(MAGMA_DIR PATH "Path to the root of a MAGMA installation" "${MAGMA_DIR}" - SHOW_IF ENABLE_MAGMA) + DEPENDS_ON ENABLE_MAGMA) sundials_option(SUNDIALS_MAGMA_BACKENDS STRING "Which MAGMA backend to use under the SUNDIALS MAGMA interfaces (CUDA, HIP)" "CUDA" OPTIONS "CUDA;HIP" - SHOW_IF ENABLE_MAGMA) + DEPENDS_ON ENABLE_MAGMA) sundials_option(MAGMA_WORKS BOOL "Set to ON to force CMake to accept a given MAGMA configuration" OFF - SHOW_IF ENABLE_MAGMA + DEPENDS_ON ENABLE_MAGMA ADVANCED) # --------------------------------------------------------------- @@ -94,20 +114,22 @@ sundials_option(MAGMA_WORKS BOOL "Set to ON to force CMake to accept a given MAG # --------------------------------------------------------------- sundials_option(ENABLE_SUPERLUDIST BOOL "Enable SuperLU_DIST support" OFF) -sundials_option(SUPERLUDIST_INCLUDE_DIR PATH "SuperLU_DIST include directory" "${SUPERLUDIST_INCLUDE_DIR}" - SHOW_IF ENABLE_SUPERLUDIST) +sundials_option(SUPERLUDIST_DIR PATH "Path to the root of the SuperLU_DIST installation" "${SUPERLUDIST_DIR}" + DEPENDS_ON ENABLE_SUPERLUDIST) -sundials_option(SUPERLUDIST_LIBRARY_DIR PATH "SuperLU_DIST library directory" "${SUPERLUDIST_LIBRARY_DIR}" - SHOW_IF ENABLE_SUPERLUDIST) +sundials_option(SUPERLUDIST_INCLUDE_DIRS PATH "SuperLU_DIST include directories" "${SUPERLUDIST_INCLUDE_DIRS}" + DEPENDS_ON ENABLE_SUPERLUDIST + ADVANCED) -sundials_option(SUPERLUDIST_LIBRARIES STRING "Semi-colon separated list of additional libraries needed for SuperLU_DIST." "${SUPERLUDIST_LIBRARIES}" - SHOW_IF ENABLE_SUPERLUDIST) +sundials_option(SUPERLUDIST_LIBRARIES STRING "Semi-colon separated list of libraries needed for SuperLU_DIST." "${SUPERLUDIST_LIBRARIES}" + DEPENDS_ON ENABLE_SUPERLUDIST + ADVANCED) sundials_option(SUPERLUDIST_OpenMP BOOL "Enable SUNDIALS support for SuperLU_DIST OpenMP on-node parallelism" OFF - SHOW_IF ENABLE_SUPERLUDIST) + DEPENDS_ON ENABLE_SUPERLUDIST) -sundials_option(SUPERLUDIST_WORKS BOOL "Set to ON to force CMake to accept a given SUPERLUDIST configuration" OFF - SHOW_IF ENABLE_SUPERLUDIST +sundials_option(SUPERLUDIST_WORKS BOOL "Set to ON to force CMake to accept a given SuperLU_DIST configuration" OFF + DEPENDS_ON ENABLE_SUPERLUDIST ADVANCED) # --------------------------------------------------------------- @@ -116,19 +138,19 @@ sundials_option(SUPERLUDIST_WORKS BOOL "Set to ON to force CMake to accept a giv sundials_option(ENABLE_SUPERLUMT BOOL "Enable SuperLU_MT support" OFF) sundials_option(SUPERLUMT_INCLUDE_DIR PATH "SuperLU_MT include directory" "${SUPERLUMT_INCLUDE_DIR}" - SHOW_IF ENABLE_SUPERLUMT) + DEPENDS_ON ENABLE_SUPERLUMT) sundials_option(SUPERLUMT_LIBRARY_DIR PATH "SuperLU_MT library directory" "${SUPERLUMT_LIBRARY_DIR}" - SHOW_IF ENABLE_SUPERLUMT) + DEPENDS_ON ENABLE_SUPERLUMT) sundials_option(SUPERLUMT_LIBRARIES STRING "Semi-colon separated list of additional libraries needed for SuperLU_MT." "${SUPERLUMT_LIBRARIES}" - SHOW_IF ENABLE_SUPERLUMT) + DEPENDS_ON ENABLE_SUPERLUMT) sundials_option(SUPERLUMT_THREAD_TYPE STRING "SuperLU_MT threading type: OPENMP or PTHREAD" "PTHREAD" - SHOW_IF ENABLE_SUPERLUMT) + DEPENDS_ON ENABLE_SUPERLUMT) sundials_option(SUPERLUMT_WORKS BOOL "Set to ON to force CMake to accept a given SUPERLUMT configuration" OFF - SHOW_IF ENABLE_SUPERLUMT + DEPENDS_ON ENABLE_SUPERLUMT ADVANCED) # --------------------------------------------------------------- @@ -137,13 +159,13 @@ sundials_option(SUPERLUMT_WORKS BOOL "Set to ON to force CMake to accept a given sundials_option(ENABLE_KLU BOOL "Enable KLU support" OFF) sundials_option(KLU_INCLUDE_DIR PATH "KLU include directory" "${KLU_INCLUDE_DIR}" - SHOW_IF ENABLE_KLU) + DEPENDS_ON ENABLE_KLU) sundials_option(KLU_LIBRARY_DIR PATH "KLU library directory" "${KLU_LIBRARY_DIR}" - SHOW_IF ENABLE_KLU) + DEPENDS_ON ENABLE_KLU) sundials_option(KLU_WORKS BOOL "Set to ON to force CMake to accept a given KLU configuration" OFF - SHOW_IF ENABLE_KLU + DEPENDS_ON ENABLE_KLU ADVANCED) # --------------------------------------------------------------- @@ -151,14 +173,17 @@ sundials_option(KLU_WORKS BOOL "Set to ON to force CMake to accept a given KLU c # --------------------------------------------------------------- sundials_option(ENABLE_HYPRE BOOL "Enable hypre support" OFF) +sundials_option(HYPRE_DIR PATH "Path to hypre installation" "${HYPRE_DIR}" + DEPENDS_ON ENABLE_HYPRE) + sundials_option(HYPRE_INCLUDE_DIR PATH "HYPRE include directory" "${HYPRE_INCLUDE_DIR}" - SHOW_IF ENABLE_HYPRE) + DEPENDS_ON ENABLE_HYPRE) sundials_option(HYPRE_LIBRARY_DIR PATH "HYPRE library directory" "${HYPRE_LIBRARY_DIR}" - SHOW_IF ENABLE_HYPRE) + DEPENDS_ON ENABLE_HYPRE) sundials_option(HYPRE_WORKS BOOL "Set to ON to force CMake to accept a given hypre configuration" OFF - SHOW_IF ENABLE_HYPRE + DEPENDS_ON ENABLE_HYPRE ADVANCED) # --------------------------------------------------------------- @@ -168,21 +193,21 @@ sundials_option(HYPRE_WORKS BOOL "Set to ON to force CMake to accept a given hyp sundials_option(ENABLE_PETSC BOOL "Enable PETSc support" OFF) sundials_option(PETSC_DIR PATH "Path to the root of a PETSc installation" "${PETSC_DIR}" - SHOW_IF ENABLE_PETSC) + DEPENDS_ON ENABLE_PETSC) sundials_option(PETSC_ARCH STRING "PETSc architecture (optional)" "${PETSC_ARCH}" - SHOW_IF ENABLE_PETSC) + DEPENDS_ON ENABLE_PETSC) sundials_option(PETSC_LIBRARIES STRING "Semi-colon separated list of PETSc link libraries" "${PETSC_LIBRARIES}" - SHOW_IF ENABLE_PETSC + DEPENDS_ON ENABLE_PETSC ADVANCED) sundials_option(PETSC_INCLUDES STRING "Semi-colon separated list of PETSc include directories" "${PETSC_INCLUDES}" - SHOW_IF ENABLE_PETSC + DEPENDS_ON ENABLE_PETSC ADVANCED) sundials_option(PETSC_WORKS BOOL "Set to ON to force CMake to accept a given PETSc configuration" OFF - SHOW_IF ENABLE_PETSC + DEPENDS_ON ENABLE_PETSC ADVANCED) # ------------------------------------------------------------- @@ -191,11 +216,11 @@ sundials_option(PETSC_WORKS BOOL "Set to ON to force CMake to accept a given PET sundials_option(ENABLE_RAJA BOOL "Enable RAJA support" OFF) sundials_option(RAJA_DIR PATH "Path to root of RAJA installation" "${RAJA_DIR}" - SHOW_IF ENABLE_RAJA) + DEPENDS_ON ENABLE_RAJA) sundials_option(SUNDIALS_RAJA_BACKENDS STRING "Which RAJA backend under the SUNDIALS RAJA interfaces (CUDA, HIP, SYCL)" "CUDA" OPTIONS "CUDA;HIP;SYCL" - SHOW_IF ENABLE_RAJA) + DEPENDS_ON ENABLE_RAJA) # --------------------------------------------------------------- # Enable Trilinos support? @@ -203,35 +228,35 @@ sundials_option(SUNDIALS_RAJA_BACKENDS STRING "Which RAJA backend under the SUND sundials_option(ENABLE_TRILINOS BOOL "Enable Trilinos support" OFF) sundials_option(Trilinos_DIR PATH "Path to root of Trilinos installation" "${Trilinos_DIR}" - SHOW_IF ENABLE_TRILINOS) + DEPENDS_ON ENABLE_TRILINOS) sundials_option(Trilinos_INTERFACE_CXX_COMPILER STRING "C++ compiler for Trilinos interface" "${Trilinos_CXX_COMPILER}" - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) sundials_option(Trilinos_INTERFACE_C_COMPILER STRING "C compiler for Trilinos interface" "${Trilinos_C_COMPILER}" - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) sundials_option(Trilinos_INTERFACE_CXX_COMPILER_FLAGS STRING "C++ compiler flags for Trilinos interface" "${Trilinos_CXX_COMPILER_FLAGS}" - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) sundials_option(Trilinos_INTERFACE_C_COMPILER_FLAGS STRING "C compiler flags for Trilinos interface" "${Trilinos_C_COMPILER_FLAGS}" - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) sundials_option(Trilinos_INTERFACE_MPIEXEC STRING "MPI executable for Trilinos interface" "${Trilinos_MPI_EXEC}" - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) sundials_option(Trilinos_WORKS BOOL "Set to ON to force CMake to accept a given Trilinos configuration" OFF - SHOW_IF ENABLE_TRILINOS + DEPENDS_ON ENABLE_TRILINOS ADVANCED) # --------------------------------------------------------------- @@ -252,7 +277,7 @@ sundials_option(XBRAID_INCLUDES STRING "Semi-colon separated list of XBraid incl ADVANCED) sundials_option(XBRAID_WORKS BOOL "Set to ON to force CMake to accept a given XBraid configuration" OFF - SHOW_IF ENABLE_XBRAID + DEPENDS_ON ENABLE_XBRAID ADVANCED) # ------------------------------------------------------------- @@ -261,6 +286,65 @@ sundials_option(XBRAID_WORKS BOOL "Set to ON to force CMake to accept a given XB sundials_option(ENABLE_ONEMKL BOOL "Enable oneMKL support" OFF) +sundials_option(ONEMKL_DIR PATH "Path to root of oneMKL installation" "${ONEMKL_DIR}" + DEPENDS_ON ENABLE_ONEMKL) + sundials_option(ONEMKL_WORKS BOOL "Set to ON to force CMake to accept a given oneMKL configuration" OFF - SHOW_IF ENABLE_ONEMKL + DEPENDS_ON ENABLE_ONEMKL + ADVANCED) + +sundials_option(SUNDIALS_ONEMKL_USE_GETRF_LOOP BOOL + "Replace batched getrf call with loop over getrf" OFF + DEPENDS_ON ENABLE_ONEMKL + ADVANCED) + +sundials_option(SUNDIALS_ONEMKL_USE_GETRS_LOOP BOOL + "Replace batched getrs call with loop over getrs" OFF + DEPENDS_ON ENABLE_ONEMKL + ADVANCED) + +# --------------------------------------------------------------- +# Enable Caliper support? +# --------------------------------------------------------------- + +sundials_option(ENABLE_CALIPER BOOL "Enable CALIPER support" OFF + DEPENDS_ON SUNDIALS_BUILD_WITH_PROFILING) + +sundials_option(CALIPER_DIR PATH "Path to the root of an CALIPER installation" "${CALIPER_DIR}" + DEPENDS_ON ENABLE_CALIPER) + +sundials_option(CALIPER_WORKS BOOL "Set to ON to force CMake to accept a given CALIPER configuration" OFF + DEPENDS_ON ENABLE_CALIPER + ADVANCED) + +# --------------------------------------------------------------- +# Enable Adiak support? +# --------------------------------------------------------------- + +sundials_option(ENABLE_ADIAK BOOL "Enable Adiak support" OFF DEPENDS_ON SUNDIALS_BUILD_WITH_PROFILING) + +sundials_option(adiak_DIR PATH "Path to the root of an Adiak installation" "${ADIAK_DIR}" DEPENDS_ON ENABLE_ADIAK) + +# --------------------------------------------------------------- +# Enable Kokkos support? +# --------------------------------------------------------------- + +sundials_option(ENABLE_KOKKOS BOOL "Enable Kokkos support" OFF) + +sundials_option(Kokkos_DIR PATH "Path to the root of a Kokkos installation" "${Kokkos_DIR}") + +sundials_option(KOKKOS_WORKS BOOL "Set to ON to force CMake to accept a given Kokkos configuration" OFF + DEPENDS_ON ENABLE_KOKKOS + ADVANCED) + +# --------------------------------------------------------------- +# Enable Kokkos Kernels support? +# --------------------------------------------------------------- + +sundials_option(ENABLE_KOKKOS_KERNELS BOOL "Enable Kokkos Kernels support" OFF) + +sundials_option(KokkosKernels_DIR PATH "Path to the root of a Kokkos Kernels installation" "${KokkosKernels_DIR}") + +sundials_option(KOKKOS_KERNELS_WORKS BOOL "Set to ON to force CMake to accept a given Kokkos configuration" OFF + DEPENDS_ON ENABLE_KOKKOS ENABLE_KOKKOS_KERNELS ADVANCED) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/CorrectWindowsPaths.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/CorrectWindowsPaths.cmake deleted file mode 100644 index 667ae173e..000000000 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/CorrectWindowsPaths.cmake +++ /dev/null @@ -1,43 +0,0 @@ -# --------------------------------------------------------------- -# Copyright Jed Brown -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# --------------------------------------------------------------- -# CorrectWindowsPaths - this module defines one macro -# -# CONVERT_CYGWIN_PATH( PATH ) -# This uses the command cygpath (provided by cygwin) to convert -# unix-style paths into paths useable by cmake on windows -# --------------------------------------------------------------- - -macro (CONVERT_CYGWIN_PATH _path) - if (WIN32) - EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}} - OUTPUT_VARIABLE ${_path}) - string (STRIP ${${_path}} ${_path}) - endif (WIN32) -endmacro (CONVERT_CYGWIN_PATH) - diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/FindPackageMultipass.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/FindPackageMultipass.cmake deleted file mode 100644 index 1f54532cf..000000000 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/FindPackageMultipass.cmake +++ /dev/null @@ -1,216 +0,0 @@ -# --------------------------------------------------------------- -# Programmer: Cody Balos @ LLNL -# --------------------------------------------------------------- -# SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security -# and Southern Methodist University. -# All rights reserved. -# -# See the top-level LICENSE and NOTICE files for details. -# -# SPDX-License-Identifier: BSD-3-Clause -# SUNDIALS Copyright End -# --------------------------------------------------------------- -# Based on the FindPackageMultipass module by Jed Brown. -# --------------------------------------------------------------- -# Copyright Jed Brown -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# --------------------------------------------------------------- -# PackageMultipass - this module defines two macros -# -# FIND_PACKAGE_MULTIPASS (Name CURRENT -# STATES VAR0 VAR1 ... -# DEPENDENTS DEP0 DEP1 ...) -# -# This function creates a cache entry _CURRENT which -# the user can set to "NO" to trigger a reconfiguration of the package. -# The first time this function is called, the values of -# _VAR0, ... are saved. If _CURRENT -# is false or if any STATE has changed since the last time -# FIND_PACKAGE_MULTIPASS() was called, then CURRENT will be set to "NO", -# otherwise CURRENT will be "YES". IF not CURRENT, then -# _DEP0, ... will be FORCED to NOTFOUND. -# Example: -# find_path (FOO_DIR include/foo.h) -# FIND_PACKAGE_MULTIPASS (Foo foo_current -# STATES DIR -# DEPENDENTS INCLUDES LIBRARIES) -# if (NOT foo_current) -# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES -# endif (NOT foo_current) -# -# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE) -# Always runs the given test, use this when you need to re-run tests -# because parent variables have made old cache entries stale. The LANGUAGE -# variable is either C or CXX indicating which compiler the test should -# use. -# --------------------------------------------------------------- - -macro (FIND_PACKAGE_MULTIPASS _name _current) - - # convert the package name to all caps - string (TOUPPER ${_name} _NAME) - - # copy all input args and remove _name and _current - set (_args ${ARGV}) - list (REMOVE_AT _args 0 1) - - # initialize package status to current - set (_states_current "YES") - - # check if the keyword STATES was input - list (GET _args 0 _cmd) - if (_cmd STREQUAL "STATES") - - # remove STATE from the args list and get the first state variable - list (REMOVE_AT _args 0) - list (GET _args 0 _state) - - # loop over the state variables until none are left or DEPENDENTS is reached - while (_state AND NOT _state STREQUAL "DEPENDENTS") - - # get the name of the variable with the stored state variable value - set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state}) - - # if the stored value is different from the current value, signal that - # reconfiguration is necessary - if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") - set (_states_current "NO") - endif () - - # update the stored value - set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE) - - # remove the current state variable from the args list and get the next one - list (REMOVE_AT _args 0) - list (GET _args 0 _state) - - endwhile () - - endif () - - # get the name of the package status variable - set (_stored ${_NAME}_CURRENT) - - # check if reconfiguration was requested - if (NOT ${_stored}) - set (${_stored} "YES" CACHE BOOL "Is the configuration for ${_name} current? Set to \"NO\" to reconfigure." FORCE) - set (_states_current "NO") - endif () - - # set the output package status - set (${_current} ${_states_current}) - - # check the if dependent variables need to be cleared so that the calling - # module can reset their values - if (NOT ${_current} AND PACKAGE_MULTIPASS_${_name}_CALLED) - - message (STATUS "Clearing ${_name} dependent variables") - - # check if the keyword DEPENDENTS was input - list (GET _args 0 _cmd) - if (_cmd STREQUAL "DEPENDENTS") - - # remove the DEPENDENTS from the list - list (REMOVE_AT _args 0) - - # clear the value of each dependent variable in the list - foreach (dep ${_args}) - set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) - endforeach () - - endif () - - # reset the package FOUND status - set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) - - endif () - - # signal that multipass has previously been called for this package - set (PACKAGE_MULTIPASS_${_name}_CALLED YES CACHE INTERNAL "Private" FORCE) - -endmacro (FIND_PACKAGE_MULTIPASS) - - -macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language) - # This is a ridiculous hack. CHECK_${language}_SOURCE_* - # thinks that if the *name* of the return variable doesn't change, - # then the test does not need to be re-run. We keep an internal count - # which we increment to guarantee that every test name is unique. If we've - # gotten here, then the configuration has changed enough that the - # test *needs* to be rerun. - if (NOT MULTIPASS_TEST_COUNT) - set (MULTIPASS_TEST_COUNT 00) - endif (NOT MULTIPASS_TEST_COUNT) - math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable? - set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID") - set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs}) - set (testdir ${PROJECT_BINARY_DIR}/PETSC_test) - if (NOT EXISTS ${testdir}) - file(MAKE_DIRECTORY ${testdir}) - endif () - set (CMAKE_REQUIRED_INCLUDES ${includes}) - set (CMAKE_REQUIRED_LIBRARIES ${libraries}) - # if MPI is available, use it for the test - if (MPI_${language}_COMPILER) - set (REQUIRED_COMPILER ${MPI_${language}_COMPILER}) - else () - set (REQUIRED_COMPILER ${CMAKE_${language}_COMPILER}) - endif () - if(${language} STREQUAL "C") - set (extension c) - else () - set (extension cxx) - endif () - # Create simple test code - file(WRITE ${testdir}/src.${extension} "${source}") - # Create a CMakeLists.txt file for the test code - file(WRITE ${testdir}/CMakeLists.txt - "cmake_minimum_required(VERSION 3.5)\n" - "project(ctest ${language})\n" - "set(CMAKE_VERBOSE_MAKEFILE ON)\n" - "set(CMAKE_${language}_COMPILER \"${REQUIRED_COMPILER}\")\n" - "set(CMAKE_${language}_FLAGS \"${CMAKE_${language}_FLAGS}\")\n" - "include_directories(${CMAKE_REQUIRED_INCLUDES})\n" - "add_executable(ctest src.${extension})\n" - "target_link_libraries(ctest ${CMAKE_REQUIRED_LIBRARIES})\n") - # Attempt to compile the test code - try_compile(${testname} ${testdir} ${testdir} ctest - OUTPUT_VARIABLE _output) - # Write output compiling the test code - file(WRITE ${testdir}/src.out "${_output}") - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. - file(REMOVE_RECURSE ${testdir}/CMakeFiles) - # Process test result - if (${testname}) - set (${runs} TRUE) - else () - set (${runs} FALSE) - endif () - unset (_output) -endmacro (MULTIPASS_SOURCE_RUNS) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/ResolveCompilerPaths.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/ResolveCompilerPaths.cmake deleted file mode 100644 index 78ef940b4..000000000 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/ResolveCompilerPaths.cmake +++ /dev/null @@ -1,134 +0,0 @@ -# --------------------------------------------------------------- -# Copyright Jed Brown -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# --------------------------------------------------------------- -# ResolveCompilerPaths - this module defines two macros -# -# RESOLVE_LIBRARIES (XXX_LIBRARIES LINK_LINE) -# This macro is intended to be used by FindXXX.cmake modules. -# It parses a compiler link line and resolves all libraries -# (-lfoo) using the library path contexts (-L/path) in scope. -# The result in XXX_LIBRARIES is the list of fully resolved libs. -# Example: -# -# RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld") -# -# will be resolved to -# -# FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so" -# -# if the filesystem looks like -# -# /A: liba.so libc.so -# /B: liba.so libb.so -# /usr/lib: liba.so libb.so libc.so libd.so -# -# and /usr/lib is a system directory. -# -# Note: If RESOLVE_LIBRARIES() resolves a link line differently from -# the native linker, there is a bug in this macro (please report it). -# -# RESOLVE_INCLUDES (XXX_INCLUDES INCLUDE_LINE) -# This macro is intended to be used by FindXXX.cmake modules. -# It parses a compile line and resolves all includes -# (-I/path/to/include) to a list of directories. Other flags are ignored. -# Example: -# -# RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B") -# -# will be resolved to -# -# FOO_INCLUDES:STRING="/A;/B" -# -# assuming both directories exist. -# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry) -# --------------------------------------------------------------- -include (CorrectWindowsPaths) - -macro (RESOLVE_LIBRARIES LIBS LINK_LINE) - string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))" _all_tokens "${LINK_LINE}") - set (_libs_found "") - set (_directory_list "") - foreach (token ${_all_tokens}) - if (token MATCHES "-L([^\" ]+|\"[^\"]+\")") - # If it's a library path, add it to the list - string (REGEX REPLACE "^-L" "" token ${token}) - string (REGEX REPLACE "//" "/" token ${token}) - convert_cygwin_path(token) - list (APPEND _directory_list ${token}) - elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))") - # It's a library, resolve the path by looking in the list and then (by default) in system directories - if (WIN32) #windows expects "libfoo", linux expects "foo" - string (REGEX REPLACE "^-l" "lib" token ${token}) - else (WIN32) - string (REGEX REPLACE "^-l" "" token ${token}) - endif (WIN32) - set (_root "") - if (token MATCHES "^/") # We have an absolute path - #separate into a path and a library name: - string (REGEX MATCH "[^/]*\\.(a|so|dll|lib)$" libname ${token}) - string (REGEX MATCH ".*[^${libname}$]" libpath ${token}) - convert_cygwin_path(libpath) - set (_directory_list ${_directory_list} ${libpath}) - set (token ${libname}) - endif (token MATCHES "^/") - set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) - find_library (_lib ${token} HINTS ${_directory_list} ${_root}) - if (_lib) - string (REPLACE "//" "/" _lib ${_lib}) - list (APPEND _libs_found ${_lib}) - else (_lib) - message (STATUS "Unable to find library ${token}") - endif (_lib) - endif (token MATCHES "-L([^\" ]+|\"[^\"]+\")") - endforeach (token) - set (_lib "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) - # only the LAST occurence of each library is required since there should be no circular dependencies - if (_libs_found) - list (REVERSE _libs_found) - list (REMOVE_DUPLICATES _libs_found) - list (REVERSE _libs_found) - endif (_libs_found) - set (${LIBS} "${_libs_found}") -endmacro (RESOLVE_LIBRARIES) - -macro (RESOLVE_INCLUDES INCS COMPILE_LINE) - string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}") - set (_incs_found "") - foreach (token ${_all_tokens}) - string (REGEX REPLACE "^-I" "" token ${token}) - string (REGEX REPLACE "//" "/" token ${token}) - convert_cygwin_path(token) - if (EXISTS ${token}) - list (APPEND _incs_found ${token}) - else (EXISTS ${token}) - message (STATUS "Include directory ${token} does not exist") - endif (EXISTS ${token}) - endforeach (token) - list (REMOVE_DUPLICATES _incs_found) - set (${INCS} "${_incs_found}") -endmacro (RESOLVE_INCLUDES) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddBenchmark.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddBenchmark.cmake new file mode 100644 index 000000000..f3b3aec4e --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddBenchmark.cmake @@ -0,0 +1,96 @@ +# --------------------------------------------------------------- +# Programmer(s): Yu Pan @ LLNL +# --------------------------------------------------------------- +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# --------------------------------------------------------------- +# CMake macro for adding benchmarks to `make benchmark`. +# --------------------------------------------------------------- + +macro(sundials_add_benchmark NAME EXECUTABLE BASE_BENCHMARK_NAME) + + # Define single value parameters the macro takes in to set up the test runner + # + # NUM_CORES = number of cores (GPU count or CPU count) to run on/number of resource sets + # BENCHMARK_ARGS = arguments to pass to the executable + # IDENTIFIER = suffix to append to end of benchmark name + set(oneValueArgs NUM_CORES BENCHMARK_ARGS IDENTIFIER) + + # TEST_RUNNER_ARGS = command line arguments to pass to the test executable + set(multiValueArgs TEST_RUNNER_ARGS ) + + # ENABLE_GPU = indicate this benchmark should be run with GPUs + set(options ENABLE_GPU) + + cmake_parse_arguments(sundials_add_benchmark + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # set the target name + if(sundials_add_benchmark_IDENTIFIER) + set(TARGET_NAME ${NAME}_${sundials_add_benchmark_IDENTIFIER}) + else() + if(sundials_add_benchmark_BENCHMARK_ARGS) + string(REPLACE " " "_" TEST_SUFFIX "${sundials_add_benchmark_BENCHMARK_ARGS}") + set(TARGET_NAME ${NAME}_${TEST_SUFFIX}) + else() + set(TARGET_NAME ${NAME}_run) + endif() + endif() + + # Create default benchmark caliper output directory if custom directory is not defined + if(SUNDIALS_CALIPER_OUTPUT_DIR) + set(SUNDIALS_BENCHMARK_OUTPUT_DIR ${SUNDIALS_CALIPER_OUTPUT_DIR}/Benchmarking/${BASE_BENCHMARK_NAME}) + else() + set(SUNDIALS_BENCHMARK_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Benchmarking/${BASE_BENCHMARK_NAME}) + endif() + + # make the caliper output directory if it doesn't exist + if(NOT EXISTS ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}) + file(MAKE_DIRECTORY ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}) + endif() + + # make the the output directory if it doesn't exist + if(NOT EXISTS ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output) + file(MAKE_DIRECTORY ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output) + endif() + + # command line arguments for the test runner script + set(TEST_RUNNER_ARGS + "--profile" + "--verbose" + "--executablename=$" + "--outputdir=${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output" + "--calidir=${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}" + "--nodiff") + + # incorporate scheduler arguments into test_runner + if(SUNDIALS_SCHEDULER_COMMAND STREQUAL "flux run") + set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES}") + elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "jsrun" AND ${sundials_add_benchmark_ENABLE_GPU}) + set(SCHEDULER_STRING " --smpiargs=\\\"-gpu\\\" -n${sundials_add_benchmark_NUM_CORES} -a1 -c1 -g1") + elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "jsrun") + set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES} -a1 -c1") + elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "srun") + set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES} --cpus-per-task=1 --ntasks-per-node=1") + endif() + string(REPLACE " " ";" SCHEDULER_ARGS "${SCHEDULER_STRING}") + string(REPLACE " " ";" SCHEDULER_COMMAND_ARGS "${SUNDIALS_SCHEDULER_COMMAND}") + + string(STRIP "${RUN_COMMAND}" RUN_COMMAND) + set(RUN_COMMAND ${SCHEDULER_COMMAND_ARGS} ${SCHEDULER_ARGS}) + list(APPEND TEST_RUNNER_ARGS "--runcommand=\"${RUN_COMMAND}\"") + + list(APPEND TEST_RUNNER_ARGS "--runargs=${sundials_add_benchmark_BENCHMARK_ARGS}" "--testname=${TARGET_NAME}") + add_custom_target(${TARGET_NAME} + COMMENT "Running ${TARGET_NAME}" + COMMAND ${PYTHON_EXECUTABLE} ${TESTRUNNER} ${TEST_RUNNER_ARGS}) + add_dependencies(benchmark ${TARGET_NAME}) + +endmacro() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExamplesGinkgo.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExamplesGinkgo.cmake new file mode 100644 index 000000000..1e23dfdb5 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExamplesGinkgo.cmake @@ -0,0 +1,129 @@ +# ------------------------------------------------------------------------------ +# Programmer(s): David J. Gardner @ LLNL +# ------------------------------------------------------------------------------ +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# ------------------------------------------------------------------------------ +# The macro: +# +# sundials_install_examples_ginkgo(EXAMPLES_VAR +# [TARGETS targets] +# [BACKENDS backends] +# [UNIT_TEST] +# ) +# +# adds a build target for each example tuple in EXAMPLES_VAR. +# +# The TARGETS option is a list of CMake targets provided to +# target_link_libraries. +# +# The BACKENDS is a list of Ginkgo backends compatible with the examples in +# EXAMPLES_VAR. +# +# When the UNIT_TEST option is provided sundials_add_test is called with NODIFF +# so the example return value determines pass/fail. Otherwise, the ANSWER_DIR +# and ANSWER_FILE are used to set an output file for comparison. +# ------------------------------------------------------------------------------ + +# Add the build targets for each CVODE example +macro(sundials_add_examples_ginkgo EXAMPLES_VAR) + + set(options UNIT_TEST) + set(oneValueArgs) + set(multiValueArgs TARGETS BACKENDS) + + # Parse keyword arguments and options + cmake_parse_arguments(arg + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + foreach(example_tuple ${${EXAMPLES_VAR}}) + foreach(backend ${arg_BACKENDS}) + + # parse the example tuple + list(GET example_tuple 0 example) + list(GET example_tuple 1 example_args) + list(GET example_tuple 2 example_type) + + if(NOT (SUNDIALS_GINKGO_BACKENDS MATCHES "${backend}")) + continue() + endif() + + set(float_precision "default") + if(backend MATCHES "CUDA") + set_source_files_properties(${example} PROPERTIES LANGUAGE CUDA) + set(vector nveccuda) + set(float_precision "4") + elseif(backend MATCHES "HIP") + set_source_files_properties(${example} PROPERTIES LANGUAGE CXX) + set(vector nvechip) + elseif(backend MATCHES "SYCL") + set(vector nvecsycl) + elseif(backend MATCHES "OMP") + set(vector nvecopenmp) + elseif(backend MATCHES "REF") + set(vector nvecserial) + endif() + + # extract the file name without extension + get_filename_component(example_target ${example} NAME_WE) + set(example_target "${example_target}.${backend}") + + if(NOT TARGET ${example_target}) + + # create target + add_executable(${example_target} ${example}) + + # folder for IDEs + set_target_properties(${example_target} PROPERTIES FOLDER "Examples") + + # which backend to use + target_compile_definitions(${example_target} PRIVATE USE_${backend}) + + # directories to include + target_include_directories(${example_target} + PRIVATE + "${PROJECT_SOURCE_DIR}/examples/utilities") + + # libraries to link against + target_link_libraries(${example_target} + PRIVATE + ${arg_TARGETS} + sundials_${vector} + Ginkgo::ginkgo + ${EXTRA_LINK_LIBS}) + + endif() + + # check if example args are provided and set the test name + if("${example_args}" STREQUAL "") + set(test_name ${example_target}) + else() + string(REGEX REPLACE " " "_" test_name ${example_target}_${example_args}) + endif() + + # add example to regression tests + if(${arg_UNIT_TEST}) + sundials_add_test(${test_name} ${example_target} + EXAMPLE_TYPE ${example_type} + TEST_ARGS ${example_args} + NODIFF) + else() + sundials_add_test(${test_name} ${example_target} + EXAMPLE_TYPE ${example_type} + TEST_ARGS ${example_args} + ANSWER_DIR ${CMAKE_CURRENT_SOURCE_DIR} + ANSWER_FILE ${test_name}.out + FLOAT_PRECISION ${float_precision}) + endif() + + endforeach() + endforeach() + +endmacro() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExecutable.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExecutable.cmake new file mode 100644 index 000000000..a2582a348 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddExecutable.cmake @@ -0,0 +1,45 @@ +# --------------------------------------------------------------- +# Programmer(s): Cody J. Balos @ LLNL +# --------------------------------------------------------------- +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# --------------------------------------------------------------- +# CMake macro for adding executables. +# --------------------------------------------------------------- + +macro(sundials_add_nvector_benchmark NAME) + + set(options ) + set(singleValueArgs ) + set(multiValueArgs SOURCES SUNDIALS_TARGETS LINK_LIBRARIES + INSTALL_SUBDIR) + + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(BENCHMARKS_DIR ${PROJECT_SOURCE_DIR}/benchmarks) + + add_executable(${NAME} + ${BENCHMARKS_DIR}/nvector/test_nvector_performance.c + ${arg_SOURCES}) + + set_target_properties(${NAME} PROPERTIES FOLDER "Benchmarks") + + target_include_directories(${NAME} PRIVATE + ${BENCHMARKS_DIR}/nvector) + + target_link_libraries(${NAME} PRIVATE + ${arg_SUNDIALS_TARGETS} ${arg_LINK_LIBRARIES} -lm) + + install(TARGETS ${NAME} + DESTINATION "${BENCHMARKS_INSTALL_PATH}/${arg_INSTALL_SUBDIR}") + +endmacro(sundials_add_nvector_benchmark) + diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddLibrary.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddLibrary.cmake index 32d33167f..199f790e6 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddLibrary.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddLibrary.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -150,7 +150,9 @@ macro(sundials_add_library target) # -------------------------------------------------------------------------- # create the target for the object library - add_library(${obj_target} OBJECT ${sources}) + add_library(${obj_target} OBJECT ${sources} ${sundials_add_library_UNPARSED_ARGUMENTS}) + + set_target_properties(${obj_target} PROPERTIES FOLDER "obj") # add all object libraries to object library if(sundials_add_library_OBJECT_LIBRARIES) @@ -159,8 +161,11 @@ macro(sundials_add_library target) endif() # add all link libraries to object library - if(USE_GENERIC_MATH) - target_link_libraries(${obj_target} PRIVATE m) + if(SUNDIALS_MATH_LIBRARY) + target_link_libraries(${obj_target} PRIVATE "${SUNDIALS_MATH_LIBRARY}") + endif() + if(SUNDIALS_RT_LIBRARY) + target_link_libraries(${obj_target} PRIVATE "${SUNDIALS_RT_LIBRARY}") endif() if(sundials_add_library_LINK_LIBRARIES) if(${_libtype} MATCHES "STATIC") @@ -168,15 +173,38 @@ macro(sundials_add_library target) else() set(_all_libs ${sundials_add_library_LINK_LIBRARIES}) endif() + # Due to various issues in CMake, particularly https://gitlab.kitware.com/cmake/cmake/-/issues/25365, + # we create a fake custom target to enforce a build order. Without this, parallel builds + # might fail with an error about a missing '.mod' file when Fortran is enabled (see GitHub #410). + set(_stripped_all_libs ${_all_libs}) + list(FILTER _stripped_all_libs EXCLUDE REGEX "PUBLIC|INTERFACE|PRIVATE") + foreach(_item ${_stripped_all_libs}) + if(NOT TARGET ${_item}) + list(REMOVE_ITEM _stripped_all_libs ${_item}) + endif() + endforeach() + add_custom_target(fake_to_force_build_order_${obj_target}) + add_dependencies(fake_to_force_build_order_${obj_target} ${_stripped_all_libs}) + add_dependencies(${obj_target} fake_to_force_build_order_${obj_target}) target_link_libraries(${obj_target} ${_all_libs}) endif() + if(SUNDIALS_BUILD_WITH_PROFILING) + if(ENABLE_CALIPER) + target_link_libraries(${obj_target} PUBLIC caliper) + endif() + if(ENABLE_ADIAK) + target_link_libraries(${obj_target} PUBLIC adiak::adiak ${CMAKE_DL_LIBS}) + endif() + endif() + # add includes to object library target_include_directories(${obj_target} PUBLIC $ $ - $ + $ + $ ) if(sundials_add_library_INCLUDE_DIRECTORIES) string(REPLACE "{{libtype}}" "${_libtype}" _includes "${sundials_add_library_INCLUDE_DIRECTORIES}") @@ -185,9 +213,9 @@ macro(sundials_add_library target) # add compile definitions to object library for SUNDIALS_EXPORT if(${_libtype} MATCHES "STATIC") - target_compile_definitions(${obj_target} PRIVATE SUNDIALS_STATIC_DEFINE) + target_compile_definitions(${obj_target} PUBLIC SUNDIALS_STATIC_DEFINE) else() - target_compile_definitions(${obj_target} PRIVATE sundials_generic_EXPORTS) + target_compile_definitions(${obj_target} PRIVATE sundials_core_EXPORTS) endif() # add all other compile definitions to object library @@ -224,9 +252,7 @@ macro(sundials_add_library target) # set target name set(_actual_target_name ${target}${_lib_suffix}) - add_library(${_actual_target_name} ${_libtype} $) - - # add any object library dependencies + set(_object_sources $) if(sundials_add_library_OBJECT_LIBRARIES) if(${_libtype} MATCHES "STATIC") append_static_suffix(sundials_add_library_OBJECT_LIBRARIES _all_objs) @@ -234,27 +260,42 @@ macro(sundials_add_library target) set(_all_objs ${sundials_add_library_OBJECT_LIBRARIES}) endif() foreach(_tmp ${_all_objs}) - # We use target_sources since target_link_libraries does not work - # properly with CMake 3.12. - target_sources(${_actual_target_name} PRIVATE $) + list(APPEND _object_sources $) endforeach() endif() + add_library(${_actual_target_name} ${_libtype} ${_object_sources} ${sundials_add_library_UNPARSED_ARGUMENTS}) + + set_target_properties(${_actual_target_name} PROPERTIES FOLDER "src") + # add all link libraries - if(USE_GENERIC_MATH) - target_link_libraries(${_actual_target_name} PRIVATE m) + if(SUNDIALS_MATH_LIBRARY) + target_link_libraries(${_actual_target_name} PRIVATE "${SUNDIALS_MATH_LIBRARY}") + endif() + if(SUNDIALS_RT_LIBRARY) + target_link_libraries(${_actual_target_name} PRIVATE "${SUNDIALS_RT_LIBRARY}") endif() if(sundials_add_library_LINK_LIBRARIES) target_link_libraries(${_actual_target_name} ${sundials_add_library_LINK_LIBRARIES}) endif() + if(SUNDIALS_BUILD_WITH_PROFILING) + if(ENABLE_CALIPER) + target_link_libraries(${_actual_target_name} PUBLIC caliper) + endif() + if(ENABLE_ADIAK) + target_link_libraries(${_actual_target_name} PUBLIC adiak::adiak ${CMAKE_DL_LIBS}) + endif() + endif() + # add common includes # Building: public, config/export generated, and shared private headers # Installing: installed include directory target_include_directories(${_actual_target_name} PUBLIC $ $ - $ + $ + $ $) # add all other includes @@ -265,9 +306,9 @@ macro(sundials_add_library target) # add compile definitions for SUNDIALS_EXPORT if(${_libtype} MATCHES "STATIC") - target_compile_definitions(${_actual_target_name} PRIVATE SUNDIALS_STATIC_DEFINE) + target_compile_definitions(${_actual_target_name} PUBLIC SUNDIALS_STATIC_DEFINE) else() - target_compile_definitions(${obj_target} PRIVATE sundials_generic_EXPORTS) + target_compile_definitions(${obj_target} PRIVATE sundials_core_EXPORTS) endif() # add all other compile definitions @@ -294,10 +335,17 @@ macro(sundials_add_library target) # set the correct output name if(sundials_add_library_OUTPUT_NAME) - set_target_properties(${_actual_target_name} PROPERTIES - OUTPUT_NAME ${sundials_add_library_OUTPUT_NAME} - CLEAN_DIRECT_OUTPUT 1 - ) + if((MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) AND ${_libtype} MATCHES "STATIC") + set_target_properties(${_actual_target_name} PROPERTIES + OUTPUT_NAME "${sundials_add_library_OUTPUT_NAME}_static" + CLEAN_DIRECT_OUTPUT 1 + ) + else() + set_target_properties(${_actual_target_name} PROPERTIES + OUTPUT_NAME ${sundials_add_library_OUTPUT_NAME} + CLEAN_DIRECT_OUTPUT 1 + ) + endif() else() set_target_properties(${_actual_target_name} PROPERTIES OUTPUT_NAME ${target} @@ -324,7 +372,7 @@ macro(sundials_add_library target) endif() # install phase - install(TARGETS ${_actual_target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT sundials-targets) + install(TARGETS ${_actual_target_name} EXPORT sundials-targets) endif() @@ -348,12 +396,20 @@ macro(sundials_add_library target) if(NOT sundials_add_library_OBJECT_LIB_ONLY) add_library(${target} ALIAS ${target}${_SHARED_LIB_SUFFIX}) set(_SUNDIALS_ALIAS_TARGETS "${target}->${target}${_SHARED_LIB_SUFFIX};${_SUNDIALS_ALIAS_TARGETS}" CACHE INTERNAL "" FORCE) + + # Namespaced alias for using build directory directly + string(REPLACE "sundials_" "" _export_name "${target}") + add_library(SUNDIALS::${_export_name} ALIAS ${target}${_SHARED_LIB_SUFFIX}) endif() else() add_library(${target}_obj ALIAS ${target}_obj${_STATIC_LIB_SUFFIX}) if(NOT sundials_add_library_OBJECT_LIB_ONLY) add_library(${target} ALIAS ${target}${_STATIC_LIB_SUFFIX}) set(_SUNDIALS_ALIAS_TARGETS "${target}->${target}${_STATIC_LIB_SUFFIX};${_SUNDIALS_ALIAS_TARGETS}" CACHE INTERNAL "" FORCE) + + # Namespaced alias for using build directory directly + string(REPLACE "sundials_" "" _export_name "${target}") + add_library(SUNDIALS::${_export_name} ALIAS ${target}${_STATIC_LIB_SUFFIX}) endif() endif() @@ -380,38 +436,46 @@ macro(sundials_add_f2003_library target) cmake_parse_arguments(sundials_add_f2003_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - # set target properties and target dependencies so that includes - # and links get passed on when this target is used if(CMAKE_Fortran_MODULE_DIRECTORY) set(_includes PUBLIC $ $ ) - set(_properties PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}_{{libtype}}") + set(_properties PROPERTIES + Fortran_MODULE_DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}_{{libtype}}" + WINDOWS_EXPORT_ALL_SYMBOLS ON) else() set(_includes PUBLIC $ $ ) - set(_properties PROPERTIES Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir") + set(_properties PROPERTIES + Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir" + WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() # get the name of the C library which the fortran library interfaces to string(REPLACE "sundials_f" "sundials_" _clib_name "${target}") string(REPLACE "_mod" "" _clib_name "${_clib_name}") + if(TARGET ${_clib_name}) + set(_clib_target ${_clib_name}) + else() + set(_clib_target ) + endif() sundials_add_library(${target} SOURCES ${sundials_add_f2003_library_SOURCES} OBJECT_LIBRARIES ${sundials_add_f2003_library_OBJECT_LIBRARIES} LINK_LIBRARIES + PUBLIC ${_clib_target} # depend on the c library ${sundials_add_f2003_library_LINK_LIBRARIES} - PUBLIC ${_clib_name} # depend on the c library INCLUDE_DIRECTORIES ${sundials_add_f2003_library_INCLUDE_DIRECTORIES} ${_includes} COMPILE_DEFINITIONS ${sundials_add_f2003_library_COMPILE_DEFINITIONS} + PUBLIC "SUNDIALS_INT${SUNDIALS_INDEX_SIZE}_T" COMPILE_OPTIONS ${sundials_add_f2003_library_COMPILE_OPTIONS} PROPERTIES ${sundials_add_f2003_library_PROPERTIES} ${_properties} OUTPUT_NAME ${sundials_add_f2003_library_OUTPUT_NAME} @@ -419,7 +483,6 @@ macro(sundials_add_f2003_library target) SOVERSION ${sundials_add_f2003_library_SOVERSION} ${sundials_add_f2003_library_UNPARSED_ARGUMENTS} ) - endmacro() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTest.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTest.cmake index af39ed364..33eb8d7fa 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTest.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTest.cmake @@ -2,7 +2,7 @@ # Programmer(s): Steven Smith and David J. Gardner @ LLNL # ------------------------------------------------------------------------------ # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -28,7 +28,7 @@ # floating point values and 10% for integer values. # # The level of precision can be adjusted for an individual test with the -# FLOAT_PRECISION AND INTEGER_PERCENTAGE keyword inputs to the macro or globally +# FLOAT_PRECISION AND INTEGER_PRECISION keyword inputs to the macro or globally # for all tests with the cache variables SUNDIALS_TEST_FLOAT_PRECISION and # SUNDIALS_TEST_INTEGER_PRECISION. # @@ -42,6 +42,12 @@ # # -D SUNDIALS_TEST_OUTPUT_DIR= # -D SUNDIALS_TEST_ANSWER_DIR= +# +# By default the caliper output is written to builddir/Caliper. This can be +# changed by setting the cache variable SUNDIALS_CALIPER_OUTPUT_DIR. +# +# -D SUNDIALS_CALIPER_OUTPUT_DIR= +# # ------------------------------------------------------------------------------ macro(SUNDIALS_ADD_TEST NAME EXECUTABLE) @@ -51,29 +57,33 @@ macro(SUNDIALS_ADD_TEST NAME EXECUTABLE) set(options "NODIFF") # macro keyword inputs followed by a single value - # MPI_NPROCS = number of mpi tasks to use in parallel tests - # FLOAT_PRECISION = precision for floating point failure comparision (num digits), - # to use the default, either don't provide the keyword, or - # provide the value "default" - # INTEGER_PRECENTAGE = integer percentage difference for failure comparison - # ANSWER_DIR = path to the directory containing the test answer file - # ANSWER_FILE = name of test answer file - # EXAMPLE_TYPE = release or develop examples - set(oneValueArgs "MPI_NPROCS" "FLOAT_PRECISION" "INTEGER_PERCENTAGE" + # MPI_NPROCS = number of mpi tasks to use in parallel tests + # FLOAT_PRECISION = precision for floating point failure comparision (num digits), + # to use the default, either don't provide the keyword, or + # provide the value "default" + # INTEGER_PRECISION = integer percentage difference for failure comparison + # ANSWER_DIR = path to the directory containing the test answer file + # ANSWER_FILE = name of test answer file + # EXAMPLE_TYPE = release or develop examples + set(oneValueArgs "MPI_NPROCS" "FLOAT_PRECISION" "INTEGER_PRECISION" "ANSWER_DIR" "ANSWER_FILE" "EXAMPLE_TYPE") # macro keyword inputs followed by multiple values # TEST_ARGS = command line arguments to pass to the test executable - set(multiValueArgs "TEST_ARGS") + set(multiValueArgs "TEST_ARGS" "EXTRA_ARGS") # parse inputs and create variables SUNDIALS_ADD_TEST_ cmake_parse_arguments(SUNDIALS_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - # SGS add check to make sure parallel is integer - # check that the test is not excluded - if(NOT ("${SUNDIALS_ADD_TEST_EXAMPLE_TYPE}" STREQUAL "exclude")) + string(TOLOWER "exclude-${SUNDIALS_PRECISION}" _exclude_precision) + if( ("${SUNDIALS_ADD_TEST_EXAMPLE_TYPE}" STREQUAL "exclude") OR + ("${SUNDIALS_ADD_TEST_EXAMPLE_TYPE}" STREQUAL _exclude_precision) ) + + message(STATUS "Skipped test ${NAME} because it had type ${SUNDIALS_ADD_TEST_EXAMPLE_TYPE}") + + else() if(SUNDIALS_TEST_DEVTESTS) @@ -86,6 +96,15 @@ macro(SUNDIALS_ADD_TEST NAME EXECUTABLE) "--executablename=$" ) + if(SUNDIALS_TEST_PROFILE) + list(APPEND TEST_ARGS "--profile") + if (SUNDIALS_CALIPER_OUTPUT_DIR) + list(APPEND TEST_ARGS "--calidir=${SUNDIALS_CALIPER_OUTPUT_DIR}/Example/${JOB_ID}") + else() + list(APPEND TEST_ARGS "--calidir=${TEST_OUTPUT_DIR}/Caliper/Example") + endif() + endif() + # check for a non-default output directory if(SUNDIALS_TEST_OUTPUT_DIR) list(APPEND TEST_ARGS "--outputdir=${SUNDIALS_TEST_OUTPUT_DIR}") @@ -106,39 +125,55 @@ macro(SUNDIALS_ADD_TEST NAME EXECUTABLE) endif() # check if a diff is needed and if non-default precisions were provided - if(SUNDIALS_ADD_TEST_NODIFF) + if(SUNDIALS_ADD_TEST_NODIFF OR SUNDIALS_TEST_NODIFF) # do not diff the output and answer files list(APPEND TEST_ARGS "--nodiff") else() # set a non-default floating point precision (number of digits, default 4) - if(SUNDIALS_TEST_FLOAT_PRECISION) - list(APPEND TEST_ARGS "--floatprecision=${SUNDIALS_TEST_FLOAT_PRECISION}") - elseif(SUNDIALS_ADD_TEST_FLOAT_PRECISION AND - (NOT SUNDIALS_ADD_TEST_FLOAT_PRECISION MATCHES "DEFAULT|default")) + if(SUNDIALS_ADD_TEST_FLOAT_PRECISION AND + (NOT SUNDIALS_ADD_TEST_FLOAT_PRECISION MATCHES "DEFAULT|default")) list(APPEND TEST_ARGS "--floatprecision=${SUNDIALS_ADD_TEST_FLOAT_PRECISION}") + elseif(SUNDIALS_TEST_FLOAT_PRECISION GREATER_EQUAL "0") + list(APPEND TEST_ARGS "--floatprecision=${SUNDIALS_TEST_FLOAT_PRECISION}") endif() # set a non-default integer precision (percent difference, default 10%) - if(SUNDIALS_TEST_INTEGER_PRECISION) + if(SUNDIALS_ADD_TEST_INTEGER_PRECISION AND + (NOT SUNDIALS_ADD_TEST_INTEGER_PRECISION MATCHES "DEFAULT|default")) + list(APPEND TEST_ARGS "--integerpercentage=${SUNDIALS_ADD_TEST_INTEGER_PRECISION}") + elseif(SUNDIALS_TEST_INTEGER_PRECISION GREATER_EQUAL "0") list(APPEND TEST_ARGS "--integerpercentage=${SUNDIALS_TEST_INTEGER_PRECISION}") - elseif(SUNDIALS_ADD_TEST_INTEGER_PERCENTAGE) - list(APPEND TEST_ARGS "--integerpercentage=${SUNDIALS_ADD_TEST_INTEGER_PERCENTAGE}") endif() endif() # check if this test is run with MPI and set the MPI run command - if((SUNDIALS_ADD_TEST_MPI_NPROCS) AND (MPIEXEC_EXECUTABLE)) - if(MPIEXEC_EXECUTABLE MATCHES "srun") - set(RUN_COMMAND "srun -N1 -n${SUNDIALS_ADD_TEST_MPI_NPROCS} -ppdebug") - else() - set(RUN_COMMAND "${MPIEXEC_EXECUTABLE} -n ${SUNDIALS_ADD_TEST_MPI_NPROCS}") + if((SUNDIALS_ADD_TEST_MPI_NPROCS) AND ((MPIEXEC_EXECUTABLE) OR (SUNDIALS_TEST_MPIRUN_COMMAND))) + if (SUNDIALS_TEST_MPIRUN_COMMAND) + set(RUN_COMMAND "${SUNDIALS_TEST_MPIRUN_COMMAND} ${MPIEXEC_NUMPROC_FLAG} ${SUNDIALS_ADD_TEST_MPI_NPROCS} ${MPIEXEC_PREFLAGS}") + elseif(MPIEXEC_EXECUTABLE) + set(RUN_COMMAND "${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${SUNDIALS_ADD_TEST_MPI_NPROCS} ${MPIEXEC_PREFLAGS}") endif() + + # remove trailing white space (empty MPIEXEC_PREFLAGS) as it can cause + # erroneous test failures with some MPI implementations + string(STRIP "${RUN_COMMAND}" RUN_COMMAND) list(APPEND TEST_ARGS "--runcommand=\"${RUN_COMMAND}\"") endif() # set the test input args if(SUNDIALS_ADD_TEST_TEST_ARGS) - string(REPLACE ";" " " USER_ARGS "${SUNDIALS_ADD_TEST_TEST_ARGS}") - list(APPEND TEST_ARGS "--runargs=\"${USER_ARGS}\"") + string(REPLACE ";" " " _user_args "${SUNDIALS_ADD_TEST_TEST_ARGS}") + set(_run_args "${_user_args}") + unset(_user_args) + endif() + if(SUNDIALS_ADD_TEST_EXTRA_ARGS) + string(REPLACE ";" " " _extra_args "${SUNDIALS_ADD_TEST_EXTRA_ARGS}") + set(_run_args "${_run_args} ${_extra_args}") + unset(_extra_args) + endif() + if (_run_args) + string(STRIP "${_run_args}" _run_args) + list(APPEND TEST_ARGS "--runargs=\"${_run_args}\"") + unset(_run_args) endif() # create test case with the corresponding test runner command and arguments @@ -155,8 +190,16 @@ macro(SUNDIALS_ADD_TEST NAME EXECUTABLE) endif() # check if this test is run with MPI and add the test run command - if((SUNDIALS_ADD_TEST_MPI_NPROCS) AND (MPIEXEC_EXECUTABLE)) - add_test(NAME ${NAME} COMMAND ${MPIEXEC_EXECUTABLE} -n ${SUNDIALS_ADD_TEST_MPI_NPROCS} $ ${TEST_ARGS}) + if((SUNDIALS_ADD_TEST_MPI_NPROCS) AND ((MPIEXEC_EXECUTABLE) OR (SUNDIALS_TEST_MPIRUN_COMMAND))) + if(MPIEXEC_PREFLAGS) + string(REPLACE " " ";" PREFLAGS "${MPIEXEC_PREFLAGS}") + endif() + if (SUNDIALS_TEST_MPIRUN_COMMAND) + string(REPLACE " " ";" MPI_EXEC_ARGS "${SUNDIALS_TEST_MPIRUN_COMMAND}") + add_test(NAME ${NAME} COMMAND ${MPI_EXEC_ARGS} ${MPIEXEC_NUMPROC_FLAG} ${SUNDIALS_ADD_TEST_MPI_NPROCS} ${PREFLAGS} $ ${TEST_ARGS}) + else() + add_test(NAME ${NAME} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${SUNDIALS_ADD_TEST_MPI_NPROCS} ${PREFLAGS} $ ${TEST_ARGS}) + endif() else() add_test(NAME ${NAME} COMMAND $ ${TEST_ARGS}) endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTestInstall.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTestInstall.cmake index 489492d03..cf2a6fb76 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTestInstall.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsAddTestInstall.cmake @@ -2,7 +2,7 @@ # Programmer(s): David J. Gardner @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsCMakeMacros.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsCMakeMacros.cmake index 85a252a6c..20d101c83 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsCMakeMacros.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsCMakeMacros.cmake @@ -3,7 +3,7 @@ # Radu Serban @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -40,55 +40,6 @@ macro(ADD_PREFIX prefix rootlist) set(${rootlist} ${outlist}) endmacro(ADD_PREFIX) -# Macro to print warnings. - -macro(print_warning message action) - set(options ) - set(oneValueArgs MODE) - set(multiValueArgs ) - - # parse inputs and create variables print_warning_ - cmake_parse_arguments(print_warning "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - - if(print_warning_MODE) - set(_mode ${print_warning_MODE}) - else() - set(_mode WARNING) - endif() - - set(MSG - "------------------------------------------------------------------------\n" - "WARNING: ${message}\n" - "${action}\n" - "------------------------------------------------------------------------") - - message(${_mode} ${MSG}) -endmacro() - -# Macro to print error messages. - -macro(print_error message) - set(options ) - set(oneValueArgs MODE) - set(multiValueArgs ) - - # parse inputs and create variables print_warning_ - cmake_parse_arguments(print_error "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - - if(print_error_MODE) - set(_mode ${print_error_MODE}) - else() - set(_mode FATAL_ERROR) - endif() - - set(MSG - "************************************************************************\n" - "ERROR: ${message}\n" - "************************************************************************") - - message(${_mode} ${MSG}) -endmacro() - # Returns an unquoted string. Note that CMake will readily turn such # strings back into lists, due to the duality of lists and # semicolon-separated strings. So be careful how you use it. @@ -130,9 +81,12 @@ function(sundials_git_version) endfunction() # Macros from other files - +include(SundialsAddExamplesGinkgo) +include(SundialsAddExecutable) include(SundialsAddLibrary) include(SundialsAddTest) include(SundialsAddTestInstall) include(SundialsInstallExamples) +include(SundialsInstallExamplesGinkgo) include(SundialsOption) +include(SundialsAddBenchmark) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamples.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamples.cmake index 5441b08d1..7f40b7af6 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamples.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamples.cmake @@ -1,8 +1,8 @@ -# --------------------------------------------------------------- +# ------------------------------------------------------------------------------ # Programmer(s): Cody J. Balos @ LLNL -# --------------------------------------------------------------- +# ------------------------------------------------------------------------------ # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -10,9 +10,9 @@ # # SPDX-License-Identifier: BSD-3-Clause # SUNDIALS Copyright End -# --------------------------------------------------------------- +# ------------------------------------------------------------------------------ # CMake macro for installing examples. -# --------------------------------------------------------------- +# ------------------------------------------------------------------------------ # The macro: # @@ -20,40 +20,63 @@ # DESTINATION path # CMAKE_TEMPLATE name # [MAKE_TEMPLATE name [SOLVER_LIBRARY target]] -# [TEST_INSTALL target] +# [SUNDIALS_COMPONENTS components] # [SUNDIALS_TARGETS targets] +# [DEPENDENCIES files] +# [TEST_INSTALL target] # [EXTRA_FILES files] # [EXTRA_INCLUDES includes] # ) # -# adds an install target for examples in EXAMPLES_VAR that go with MOUDLE (e.g. arkode, nvecserial). +# adds an install target for examples in EXAMPLES_VAR that go with MODULE (e.g. +# arkode, nvecserial). +# +# The DESTINATION option is the path *within* EXAMPLES_INSTALL_PATH that the +# files should be installed under. # -# The DESTINATION option is the path *within* EXAMPLES_INSTALL_PATH that the files should be installed. +# The CMAKE_TEMPLATE option is the name of the examples/templates CMake template +# to use (e.g. cmakelists_CXX_ex.in). # -# The CMAKE_TEMPLATE option is the name of the examples/templates CMake template to use (e.g. cmakelists_CXX_ex.in) +# The MAKE_TEMPLATE option is the name of the examples/templates Make template +# to use. # -# The MAKE_TEMPLATE option is the name of the examples/templates Make template to use +# The SUNDIALS_COMPONENTS option is a list of CMake targets in the SUNDIALS:: +# namespace provided to find_package. Note this may be the same as or a superset +# of SUNDIALS_TARGETS depending on the CMakeLists.txt template. # -# The SOLVER_LIBRARY option is used when a MAKE_TEMPLATE is provided. It should be the library name for SUNDIALS solver (e.g. arkode, cvode, ...) +# The SUNDIALS_TARGETS option is a list of CMake targets in the SUNDIALS:: +# namespace provided to target_link_libraries. Note this may be the same as or a +# subset of SUNDIALS_COMPONENTS depending on the CMakeLists.txt template. # -# The TEST_INSTALL option adds a test_install target with the given target name for the MODULE. +# The SOLVER_LIBRARY option is used when a MAKE_TEMPLATE is provided. It should +# be the library name for SUNDIALS solver (e.g. arkode, cvode, ...) # -# The SUNDIALS_TARGETS option is a list of CMake targets in the SUNDIALS:: namespace that the examples need to be linked to. +# The TEST_INSTALL option adds a test_install target with the given target name +# for the MODULE. # -# The OTHER_TARGETS option is a list of CMake targets that the examples need to be linked to. +# The SUNDIALS_TARGETS option is a list of CMake targets in the SUNDIALS:: +# namespace that the examples need to be linked to. # -# The EXAMPLE_DEPENDENCIES option is a list of additional source files that the examples are dependent on. +# The OTHER_TARGETS option is a list of CMake targets that the examples need to +# be linked to. # -# The EXTRA_FILES option is a list of files to install that are not example source code. +# The EXAMPLES_DEPENDENCIES option is a list of additional source files that the +# examples are dependent on. # -# The EXTRA_INCLUDES option is a list of additional includes to set with INCLUDE_DIRECTORIES. +# The EXTRA_FILES option is a list of files to install that are not example +# source code. # +# The EXTRA_INCLUDES option is a list of additional includes to set with +# INCLUDE_DIRECTORIES. +# ------------------------------------------------------------------------------ macro(sundials_install_examples MODULE EXAMPLES_VAR) set(options ) - set(oneValueArgs SOLVER_LIBRARY DESTINATION CMAKE_TEMPLATE MAKE_TEMPLATE TEST_INSTALL) - set(multiValueArgs SUNDIALS_TARGETS OTHER_TARGETS EXAMPLES_DEPENDENCIES EXTRA_FILES EXTRA_INCLUDES) + set(oneValueArgs SOLVER_LIBRARY DESTINATION CMAKE_TEMPLATE MAKE_TEMPLATE + TEST_INSTALL) + set(multiValueArgs SUNDIALS_TARGETS SUNDIALS_COMPONENTS OTHER_TARGETS + EXAMPLES_DEPENDENCIES EXTRA_FILES EXTRA_INCLUDES) # Parse keyword arguments/options cmake_parse_arguments(sundials_install_examples @@ -68,17 +91,12 @@ macro(sundials_install_examples MODULE EXAMPLES_VAR) foreach(example_tuple ${${EXAMPLES_VAR}}) list(GET example_tuple 0 example) # filename always has to be the first item in the example tuple get_filename_component(example_noext ${example} NAME_WE) + file(GLOB example_header ${example_noext}.h*) file(GLOB example_out ${example_noext}*.out) - install(FILES ${example} ${example_out} - DESTINATION ${EXAMPLES_INSTALL_PATH}/${sundials_install_examples_DESTINATION}) + install(FILES ${example} ${example_header} ${example_out} + DESTINATION ${EXAMPLES_INSTALL_PATH}/${sundials_install_examples_DESTINATION}) endforeach() - # Install the example dependencies - if(DEFINED sundials_install_examples_EXAMPLES_DEPENDENCIES) - install(FILES ${sundials_install_examples_EXAMPLES_DEPENDENCIES} - DESTINATION ${EXAMPLES_INSTALL_PATH}/${sundials_install_examples_DESTINATION}) - endif() - # Prepare substitution variables for Makefile and/or CMakeLists templates string(TOUPPER "${MODULE}" SOLVER) set(SOLVER_LIB "${sundials_install_examples_SOLVER_LIBRARY}") @@ -86,14 +104,29 @@ macro(sundials_install_examples MODULE EXAMPLES_VAR) set(EXTRA_INCLUDES "${sundials_install_examples_EXTRA_INCLUDES}") examples2string(${EXAMPLES_VAR} EXAMPLES) + # components for find_package + set(components_list "") + foreach(target ${sundials_install_examples_SUNDIALS_TARGETS}) + list(APPEND components_list ${target}) + endforeach() + if(sundials_install_examples_SUNDIALS_COMPONENTS) + foreach(component ${sundials_install_examples_SUNDIALS_COMPONENTS}) + list(APPEND components_list ${component}) + endforeach() + endif() + list2string(components_list EXAMPLES_CMAKE_COMPONENTS) + set(target_list "") + set(libs_list "") foreach(target ${sundials_install_examples_SUNDIALS_TARGETS}) list(APPEND target_list SUNDIALS::${target}) + list(APPEND libs_list -lsundials_${target}) endforeach() foreach(target ${sundials_install_examples_OTHER_TARGETS}) list(APPEND target_list ${target}) endforeach() list2string(target_list EXAMPLES_CMAKE_TARGETS) + list2string(libs_list EXAMPLES_MAKEFILE_LIBS) # Regardless of the platform we're on, we will generate and install # CMakeLists.txt file for building the examples. This file can then diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamplesGinkgo.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamplesGinkgo.cmake new file mode 100644 index 000000000..05427f205 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsInstallExamplesGinkgo.cmake @@ -0,0 +1,131 @@ +# ------------------------------------------------------------------------------ +# Programmer(s): David J. Gardner @ LLNL +# ------------------------------------------------------------------------------ +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# ------------------------------------------------------------------------------ +# The macro: +# +# sundials_install_examples_ginkgo( +# [CPU_EXAMPLES_VAR var] +# [GPU_EXAMPLES_VAR var] +# [CPU_GPU_EXAMPLES_VAR var] +# [DESTINATION path] +# [SUNDIALS_COMPONENTS components] +# [SUNDIALS_TARGETS targets] +# [DEPENDENCIES files] +# [EXTRA_FILES files] +# ) +# +# adds an install target for each example tuple in CPU_EXAMPLES_VAR, +# GPU_EXAMPLES_VAR, and CPU_GPU_EXAMPLES_VAR that go with MODULE (e.g. cvode, +# sunlinsol). +# +# The DESTINATION option is the path *within* EXAMPLES_INSTALL_PATH that the +# files should be installed under. +# +# The SUNDIALS_COMPONENTS option is a list of CMake targets in the SUNDIALS:: +# namespace provided to find_package. Note this may be the same as or a superset +# of SUNDIALS_TARGETS depending on the CMakeLists.txt template. +# +# The SUNDIALS_TARGETS option is a list of CMake targets in the SUNDIALS:: +# namespace provided to target_link_libraries. Note this may be the same as or a +# subset of SUNDIALS_COMPONENTS depending on the CMakeLists.txt template. +# +# The DEPENDENCIES option is a list of additional source files that the +# examples are dependent on. +# +# The EXTRA_FILES option is a list of files to install that are not example +# source code. +# ------------------------------------------------------------------------------ + +macro(sundials_install_examples_ginkgo MODULE) + + set(options ) + set(oneValueArgs DESTINATION) + set(multiValueArgs CPU_EXAMPLES_VAR GPU_EXAMPLES_VAR CPU_GPU_EXAMPLES_VAR + SUNDIALS_COMPONENTS SUNDIALS_TARGETS EXTRA_FILES DEPENDENCIES) + + # Parse keyword arguments/options + cmake_parse_arguments(arg + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Install the example source, header, and output file + foreach(example_type CPU GPU CPU_GPU) + foreach(example_tuple ${${arg_${example_type}_EXAMPLES_VAR}}) + + # filename must be the first item in the list of example tuples + list(GET example_tuple 0 example) + + # extract the file name without extension + get_filename_component(example_noext ${example} NAME_WE) + + # get example header and output files + file(GLOB example_header ${example_noext}.h*) + file(GLOB example_out ${example_noext}*.out) + + # install files + install(FILES ${example} ${example_header} ${example_out} + DESTINATION ${EXAMPLES_INSTALL_PATH}/${arg_DESTINATION}) + + endforeach() + endforeach() + + # Install the extra files and dependencies + if(arg_EXTRA_FILES OR arg_DEPENDENCIES) + install(FILES ${arg_EXTRA_FILES} ${arg_DEPENDENCIES} + DESTINATION ${EXAMPLES_INSTALL_PATH}/${arg_DESTINATION}) + endif() + + # Prepare substitution variables for CMakeLists and/or Makefile templates + if(arg_DEPENDENCIES) + list2string(arg_DEPENDENCIES EXAMPLES_DEPENDENCIES) + endif() + + if(arg_CPU_EXAMPLES_VAR) + examples2string(${arg_CPU_EXAMPLES_VAR} CPU_EXAMPLES) + endif() + if(arg_GPU_EXAMPLES_VAR) + examples2string(${arg_GPU_EXAMPLES_VAR} GPU_EXAMPLES) + endif() + if(arg_CPU_GPU_EXAMPLES_VAR) + examples2string(${arg_CPU_GPU_EXAMPLES_VAR} CPU_GPU_EXAMPLES) + endif() + + # components for find_package + if(arg_SUNDIALS_COMPONENTS) + list2string(arg_SUNDIALS_COMPONENTS EXAMPLES_CMAKE_COMPONENTS) + endif() + + # targets for target_link_libraries + foreach(target ${arg_SUNDIALS_TARGETS}) + list(APPEND target_list SUNDIALS::${target}) + endforeach() + if(target_list) + list2string(target_list EXAMPLES_CMAKE_TARGETS) + endif() + + # Generate CMakelists.txt in the binary directory + configure_file( + ${PROJECT_SOURCE_DIR}/examples/templates/cmakelists_CXX_ginkgo_ex.in + ${PROJECT_BINARY_DIR}/examples/${arg_DESTINATION}/CMakeLists.txt + @ONLY + ) + + # Install CMakelists.txt + install( + FILES ${PROJECT_BINARY_DIR}/examples/${arg_DESTINATION}/CMakeLists.txt + DESTINATION ${EXAMPLES_INSTALL_PATH}/${arg_DESTINATION} + ) + + # Add test_install target + sundials_add_test_install(${MODULE} ginkgo) + +endmacro() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsOption.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsOption.cmake index fd488f2a3..e80ed5aac 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsOption.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsOption.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # --------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -14,68 +14,53 @@ # Provides the macro: # # SUNDIALS_OPTION( -# [SHOW_IF dependencies] # [DEPENDS_ON dependencies] # [DEPNDS_ON_THROW_ERROR]) # # Within CMake creates a cache variable and sets it to the value -# if is not yet defined. may be any of the -# types valid for CMake's set command (FILEPATH, PATH, STRING, BOOL, INTERNAL). -# is a description of the . +# if is not yet defined and, if provided, all of its +# dependencies evaluate to true. Otherwise, is not created. +# may be any of the types valid for CMake's set command (FILEPATH, PATH, STRING, +# BOOL, INTERNAL). is a description of the . # -# The SHOW_IF option can be used to provide variables which must evaluate -# to true in order to make a CACHE variable. If not all dependencies -# are met is made an INTERNAL variable. +# The DEPENDS_ON option can be used to provide variables which must evaluate to +# true for to be created. If the dependencies do not all evaluate to +# true and exists, then a warning is printed and is unset. # -# The DEPENDS_ON option can be used to provide variable which must evaluate -# to true in order to set . If the DEPENDS_ON dependencies do not -# all evaluate to true, then is set to "" and a warning is printed. # The DEPENDS_ON_THROW_ERROR option will change the warning to be an error. # -# The OPTIONS macro can be used to provide a list of valid values for the -# variable. +# The OPTIONS option can be used to provide a list of valid values. # # The ADVANCED option can be used to make an advanced CMake option. # --------------------------------------------------------------------------- - macro(sundials_option NAME TYPE DOCSTR DEFAULT_VALUE) - set(options DEPENDS_ON_THROW_ERROR ADVANCED) # macro options - set(multiValueArgs OPTIONS SHOW_IF DEPENDS_ON) # macro keyword inputs followed by multiple values + + # macro options and keyword inputs followed by multiple values + set(options DEPENDS_ON_THROW_ERROR ADVANCED) + set(multiValueArgs OPTIONS DEPENDS_ON) # parse inputs and create variables sundials_option_ cmake_parse_arguments(sundials_option "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - # check if dependencies for this option have been met - set(all_show_if_dependencies_met TRUE) - if(sundials_option_SHOW_IF) - foreach(_dependency ${sundials_option_SHOW_IF}) - if(NOT ${_dependency}) - set(all_show_if_dependencies_met FALSE) - endif() - endforeach() - endif() - # check if dependencies for this option have been met set(all_depends_on_dependencies_met TRUE) if(sundials_option_DEPENDS_ON) - foreach(_dependency ${sundials_option_DEPENDS_ON}) - if(NOT ${_dependency}) - set(all_depends_on_dependencies_met FALSE) - list(APPEND depends_on_dependencies_not_met "${_dependency},") - endif() + foreach(_dependency ${sundials_option_DEPENDS_ON}) + if(NOT ${_dependency}) + set(all_depends_on_dependencies_met FALSE) + list(APPEND depends_on_dependencies_not_met "${_dependency},") + endif() endforeach() endif() - if(all_show_if_dependencies_met AND all_depends_on_dependencies_met) + if(all_depends_on_dependencies_met) - if(DEFINED ${NAME}) - # if the variable is already defined, keep its value - set(${NAME} ${${NAME}} CACHE ${TYPE} ${DOCSTR} FORCE) + if(NOT DEFINED ${NAME}) + set(${NAME} "${DEFAULT_VALUE}" CACHE ${TYPE} ${DOCSTR}) else() - # if the variable is not already defined, use the default value - set(${NAME} ${DEFAULT_VALUE} CACHE ${TYPE} ${DOCSTR}) + set(${NAME} "${${NAME}}" CACHE ${TYPE} ${DOCSTR}) endif() # make the option advanced if necessary @@ -83,41 +68,33 @@ macro(sundials_option NAME TYPE DOCSTR DEFAULT_VALUE) mark_as_advanced(FORCE ${NAME}) endif() - elseif(NOT all_depends_on_dependencies_met) + else() - # don't set the normal variable unless all dependencies were met + # if necessary, remove the CACHE variable i.e., all the variable + # dependencies were previously met but are no longer satisfied if(DEFINED ${NAME}) - if(${NAME}) - string(CONCAT _warn_msg_string - "The variable ${NAME} was set to ${${NAME}} " - "but not all of its dependencies " - "(${depends_on_dependencies_not_met}) evaluate to TRUE." - ) - if(sundials_option_DEPENDS_ON_THROW_ERROR) - print_error("${_warn_msg_string}" "Setting ${NAME} to \"\".") - else() - print_warning("${_warn_msg_string}" "Setting ${NAME} to \"\".") - endif() + string(CONCAT _warn_msg_string + "The variable ${NAME} was set to ${${NAME}} but not all of its " + "dependencies (${depends_on_dependencies_not_met}) evaluate to TRUE. " + "Unsetting ${NAME}.") + unset(${NAME} CACHE) + if(sundials_option_DEPENDS_ON_THROW_ERROR) + message(FATAL_ERROR "${_warn_msg_string}") + else() + message(WARNING "${_warn_msg_string}") endif() - set(${NAME} "" CACHE INTERNAL ${DOCSTR} FORCE) - endif() - - elseif(NOT all_show_if_dependencies_met) - - # hide the normal variable if not all dependencies were met - if(DEFINED ${NAME}) - set(${NAME} ${${NAME}} CACHE INTERNAL ${DOCSTR} FORCE) - else() - set(${NAME} ${DEFAULT_VALUE} CACHE INTERNAL ${DOCSTR}) endif() endif() - if(sundials_option_OPTIONS) - if(NOT (${NAME} IN_LIST sundials_option_OPTIONS)) - list(JOIN sundials_option_OPTIONS ", " _options_msg) - print_error("Value of ${NAME} must be one of ${_options_msg}") - endif() + # check for valid option choices + if((DEFINED ${NAME}) AND sundials_option_OPTIONS) + foreach(_option ${${NAME}}) + if(NOT (${_option} IN_LIST sundials_option_OPTIONS)) + list(JOIN sundials_option_OPTIONS ", " _options_msg) + message(FATAL_ERROR "Value of ${NAME} must be one of ${_options_msg}") + endif() + endforeach() get_property(is_in_cache CACHE ${NAME} PROPERTY TYPE) if(is_in_cache) set_property(CACHE ${NAME} PROPERTY STRINGS ${sundials_option_OPTIONS}) @@ -125,7 +102,6 @@ macro(sundials_option NAME TYPE DOCSTR DEFAULT_VALUE) unset(is_in_cache) endif() - unset(all_show_if_dependencies_met) unset(all_depends_on_dependencies_met) unset(depends_on_dependencies_not_met) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsTryCompileExecute.cmake b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsTryCompileExecute.cmake index c25f92638..81e972b92 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsTryCompileExecute.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/macros/SundialsTryCompileExecute.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ------------------------------------------------------------------------------ # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindKLU.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindKLU.cmake index 98465aa18..a20a4f88f 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindKLU.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindKLU.cmake @@ -2,7 +2,7 @@ # Programmer(s): Steven Smith and Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -30,16 +30,34 @@ # KLU_LIBRARIES - all of the libraries needed for KLU # --------------------------------------------------------------- +if (NOT (KLU_INCLUDE_DIR OR KLU_LIBRARY_DIR OR KLU_LIBRARY)) + # Prefer the import target from upstream SuiteSparse if it is available + # and the user didn't point to a specific (different) version. + find_package(KLU CONFIG) + + if(TARGET SuiteSparse::KLU) + if(NOT TARGET SUNDIALS::KLU) + # AMICI -- https://github.com/LLNL/sundials/issues/579 + get_target_property(klu_aliased_target SuiteSparse::KLU ALIASED_TARGET) + if (klu_aliased_target) + add_library(SUNDIALS::KLU ALIAS ${klu_aliased_target}) + else() + add_library(SUNDIALS::KLU ALIAS SuiteSparse::KLU) + endif() + # add_library(SUNDIALS::KLU ALIAS SuiteSparse::KLU) + set(KLU_SUITESPARSE_TARGET ON) + mark_as_advanced(KLU_SUITESPARSE_TARGET) + endif() + return() + endif() +endif() + # Set library prefixes for Windows -if(WIN32) +if(MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) set(CMAKE_FIND_LIBRARY_PREFIXES lib ${CMAKE_FIND_LIBRARY_PREFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES d.lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) elseif(APPLE) - # AMICI - # set(CMAKE_FIND_LIBRARY_SUFFIXES d.a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a d.a ${CMAKE_FIND_LIBRARY_SUFFIXES}) -else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES d.a ${CMAKE_FIND_LIBRARY_SUFFIXES}) endif() ### Find include dir @@ -59,52 +77,41 @@ if (KLU_LIBRARY) else () # find library with user provided directory path set(KLU_LIBRARY_NAME klu) - # AMICI - # find_library(KLU_LIBRARY ${KLU_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) - find_library(KLU_LIBRARY NAMES ${KLU_LIBRARY_NAME} klu_static.lib klu.lib PATHS ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) + find_library(KLU_LIBRARY ${KLU_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) endif () mark_as_advanced(KLU_LIBRARY) if (NOT AMD_LIBRARY) set(AMD_LIBRARY_NAME amd) - # AMICI - # find_library(AMD_LIBRARY ${AMD_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) - find_library(AMD_LIBRARY NAMES ${AMD_LIBRARY_NAME} amd_static.lib amd.lib PATHS ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) + find_library(AMD_LIBRARY ${AMD_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) mark_as_advanced(AMD_LIBRARY) endif () if (NOT COLAMD_LIBRARY) set(COLAMD_LIBRARY_NAME colamd) - # AMICI - # find_library(COLAMD_LIBRARY ${COLAMD_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) - find_library(COLAMD_LIBRARY NAMES ${COLAMD_LIBRARY_NAME} colamd_static.lib colamd.lib PATHS ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) + find_library(COLAMD_LIBRARY ${COLAMD_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) mark_as_advanced(COLAMD_LIBRARY) endif () if (NOT BTF_LIBRARY) set(BTF_LIBRARY_NAME btf) - # AMICI - # find_library( BTF_LIBRARY ${BTF_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) - find_library(BTF_LIBRARY NAMES ${BTF_LIBRARY_NAME} btf_static.lib btf.lib PATHS ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) + find_library( BTF_LIBRARY ${BTF_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) mark_as_advanced(BTF_LIBRARY) endif () if (NOT SUITESPARSECONFIG_LIBRARY) set(SUITESPARSECONFIG_LIBRARY_NAME suitesparseconfig) # NOTE: no prefix for this library on windows - if(WIN32 AND NOT MSYS) + if(MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) set(CMAKE_FIND_LIBRARY_PREFIXES "") endif() - # AMICI - # find_library( SUITESPARSECONFIG_LIBRARY ${SUITESPARSECONFIG_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) - find_library(SUITESPARSECONFIG_LIBRARY NAMES suitesparseconfig_static.lib ${SUITESPARSECONFIG_LIBRARY_NAME} suitesparseconfig.lib PATHS ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) + find_library( SUITESPARSECONFIG_LIBRARY ${SUITESPARSECONFIG_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) mark_as_advanced(SUITESPARSECONFIG_LIBRARY) endif () -set(KLU_LIBRARIES "${KLU_LIBRARY}" "${AMD_LIBRARY}" "${COLAMD_LIBRARY}" "${BTF_LIBRARY}" "${SUITESPARSECONFIG_LIBRARY}") +set(KLU_LIBRARIES ${KLU_LIBRARY} ${AMD_LIBRARY} ${COLAMD_LIBRARY} ${BTF_LIBRARY} ${SUITESPARSECONFIG_LIBRARY}) # set package variables including KLU_FOUND -include(FindPackageHandleStandardArgs) find_package_handle_standard_args(KLU REQUIRED_VARS KLU_LIBRARY diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUDIST.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUDIST.cmake index 6db94a505..016f1c8ec 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUDIST.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUDIST.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -14,81 +14,90 @@ # SuperLUDIST find module that creates an imported target for # SuperLU_DIST. The target is SUNDIALS::SUPERLUDIST. # -# The variable SUPERLUDIST_LIBRARY_DIR can be used to control -# where the module looks for the library. +# The module has two modes: one 'automatic' mode that uses +# pkg-conf to locate and determine the SuperLU DIST +# libraries and includes, and one 'manual' mode which +# requires the libraries and includes to be specified. # -# The variable SUPERLUDIST_INCLUDE_DIR can be used to set the -# include path for the library. +# If SUPERLUDIST_LIBRARIES is set, then the 'manual' mode is +# chosen and the SUPERLUDIST_INCLUDE_DIRS variable must also +# be set. # -# Additional libraries can be passed in SUPERLUDIST_LIBRARIES. +# The variable SUPERLUDIST_DIR can be used to control where +# the module looks for the library in 'automatic' mode. # -# This module also defines variables, but it is best to use -# the defined target to ensure includes and compile/link -# options are correctly passed to consumers. +# This module also defines additional variables: # -# SUPERLUDIST_FOUND - system has SuperLU_DIST library -# SUPERLUDIST_LIBRARY - the SuperLU_DIST library +# SUPERLUDIST_FOUND - the SuperLU_DIST libraries were found # SUPERLUDIST_INDEX_SIZE - the bit width of indices in SUPERLUDIST +# SUPERLUDIST_CUDA - SuperLU_DIST has CUDA support +# SUPERLUDIST_ROCM - SuperLU_DIST has ROCm support # --------------------------------------------------------------- -# Check if SUPERLUDIST_LIBRARIES contains the superlu_dist -# library as well as TPLs. If so, extract it into the -# SUPERLUDIST_LIBRARY variable. -if(SUPERLUDIST_LIBRARIES MATCHES "superlu_dist") - foreach(lib ${SUPERLUDIST_LIBRARIES}) - if(lib MATCHES "superlu_dist") - set(SUPERLUDIST_LIBRARY ${lib}) +if(NOT SUPERLUDIST_LINK_LIBRARIES AND SUPERLUDIST_LIBRARIES) + set(SUPERLUDIST_LINK_LIBRARIES "${SUPERLUDIST_LIBRARIES}" CACHE INTERNAL "") +elseif(NOT SUPERLUDIST_LINK_LIBRARIES) + find_package(PkgConfig REQUIRED) + list(APPEND CMAKE_PREFIX_PATH "${SUPERLUDIST_DIR}") + if(DEFINED SUPERLUDIST_FIND_VERSION) + if(SUPERLUDIST_FIND_VERSION_EXACT) + set(_pkg_version_spec "=${SUPERLUDIST_FIND_VERSION}") + else() + set(_pkg_version_spec ">=${SUPERLUDIST_FIND_VERSION}") endif() - endforeach() -endif() - -# find library -if(NOT SUPERLUDIST_LIBRARY) - # search user provided directory path - find_library(SUPERLUDIST_LIBRARY superlu_dist - PATHS ${SUPERLUDIST_LIBRARY_DIR} NO_DEFAULT_PATH) - # if user didn't provide a path, search anywhere - if(NOT (SUPERLUDIST_LIBRARY_DIR OR SUPERLUDIST_LIBRARY)) - find_library(SUPERLUDIST_LIBRARY superlu_dist) endif() - mark_as_advanced(SUPERLUDIST_LIBRARY) - set(SUPERLUDIST_LIBRARIES "${SUPERLUDIST_LIBRARY};${SUPERLUDIST_LIBRARIES}" CACHE STRING "" FORCE) -endif() - -# set the library dir option if it wasn't preset -if(SUPERLUDIST_LIBRARY AND (NOT SUPERLUDIST_LIBRARY_DIR)) - get_filename_component(SUPERLUDIST_LIBRARY_DIR ${SUPERLUDIST_LIBRARY} DIRECTORY) - set(SUPERLUDIST_LIBRARY_DIR ${SUPERLUDIST_LIBRARY_DIR} CACHE PATH "" FORCE) -endif() - -# set the include dir option if it wasn't preset -if(SUPERLUDIST_LIBRARY AND (NOT SUPERLUDIST_INCLUDE_DIR)) - get_filename_component(SUPERLUDIST_INCLUDE_DIR ${SUPERLUDIST_LIBRARY_DIR} DIRECTORY) - set(SUPERLUDIST_INCLUDE_DIR "${SUPERLUDIST_INCLUDE_DIR}/include" CACHE PATH "" FORCE) + pkg_search_module(SUPERLUDIST REQUIRED "superlu_dist${_pkg_version_spec}") + set(SUPERLUDIST_LINK_LIBRARIES "${SUPERLUDIST_LINK_LIBRARIES}" CACHE INTERNAL "") + set(SUPERLUDIST_INCLUDE_DIRS "${SUPERLUDIST_INCLUDE_DIRS}" CACHE INTERNAL "") endif() # find the library configuration file -if(SUPERLUDIST_LIBRARY AND SUPERLUDIST_INCLUDE_DIR) - find_file(SUPERLUDIST_CONFIG_PATH superlu_dist_config.h PATHS ${SUPERLUDIST_INCLUDE_DIR}) - file(STRINGS ${SUPERLUDIST_CONFIG_PATH} _strings_with_index_size REGEX "XSDK_INDEX_SIZE") - list(GET _strings_with_index_size 0 _index_size_string) - string(REGEX MATCHALL "[0-9][0-9]" SUPERLUDIST_INDEX_SIZE "${_index_size_string}") +set(SUPERLUDIST_CUDA FALSE CACHE BOOL "SuperLU DIST was built with CUDA support") +set(SUPERLUDIST_ROCM FALSE CACHE BOOL "SuperLU DIST was built with ROCm support") +if(SUPERLUDIST_INCLUDE_DIRS) + find_file(SUPERLUDIST_CONFIG_PATH superlu_dist_config.h PATHS "${SUPERLUDIST_INCLUDE_DIRS}") mark_as_advanced(FORCE SUPERLUDIST_CONFIG_PATH) + if(SUPERLUDIST_VERSION VERSION_GREATER_EQUAL "8.0.0") + file(STRINGS "${SUPERLUDIST_CONFIG_PATH}" _index_size_64 REGEX "#define XSDK_INDEX_SIZE 64") + file(STRINGS "${SUPERLUDIST_CONFIG_PATH}" _index_size_32 REGEX "#undef XSDK_INDEX_SIZE") + if(_index_size_64) + set(SUPERLUDIST_INDEX_SIZE 64 CACHE STRING "SuperLU DIST index size (bit width)" FORCE) + else() + set(SUPERLUDIST_INDEX_SIZE 32 CACHE STRING "SuperLU DIST index size (bit width)" FORCE) + endif() + mark_as_advanced(FORCE SUPERLUDIST_INDEX_SIZE) + else() + file(STRINGS "${SUPERLUDIST_CONFIG_PATH}" _strings_with_index_size REGEX "XSDK_INDEX_SIZE") + list(GET _strings_with_index_size 0 _index_size_string) + string(REGEX MATCHALL "[0-9][0-9]" SUPERLUDIST_INDEX_SIZE "${_index_size_string}") + endif() + file(STRINGS "${SUPERLUDIST_CONFIG_PATH}" _strings_have_cuda REGEX "HAVE_CUDA") + string(REGEX MATCH "TRUE|FALSE" _has_cuda "${_strings_have_cuda}") + file(STRINGS "${SUPERLUDIST_CONFIG_PATH}" _strings_have_rocm REGEX "HAVE_HIP") + string(REGEX MATCH "TRUE|FALSE" _has_rocm "${_strings_have_rocm}") + if(_has_cuda) + set(SUPERLUDIST_CUDA TRUE CACHE BOOL "SuperLU DIST was built with CUDA support" FORCE) + endif() + if(_has_rocm) + set(SUPERLUDIST_ROCM TRUE CACHE BOOL "SuperLU DIST was built with ROCm support" FORCE) + endif() + unset(_has_cuda) + unset(_has_rocm) endif() # find the library version file -if(SUPERLUDIST_LIBRARY AND SUPERLUDIST_INCLUDE_DIR) - find_file(SUPERLUDIST_VERSION_PATH superlu_defs.h PATHS ${SUPERLUDIST_INCLUDE_DIR}) +if(NOT SUPERLUDIST_VERSION AND SUPERLUDIST_INCLUDE_DIRS) + find_file(SUPERLUDIST_VERSION_PATH superlu_defs.h PATHS "${SUPERLUDIST_INCLUDE_DIRS}") - file(STRINGS ${SUPERLUDIST_VERSION_PATH} _version_major REGEX "SUPERLU_DIST_MAJOR_VERSION") + file(STRINGS "${SUPERLUDIST_VERSION_PATH}" _version_major REGEX "SUPERLU_DIST_MAJOR_VERSION") list(GET _version_major 0 _version_string) string(REGEX MATCHALL "[0-9]" _version_major "${_version_string}") - file(STRINGS ${SUPERLUDIST_VERSION_PATH} _version_minor REGEX "SUPERLU_DIST_MINOR_VERSION") + file(STRINGS "${SUPERLUDIST_VERSION_PATH}" _version_minor REGEX "SUPERLU_DIST_MINOR_VERSION") list(GET _version_minor 0 _version_string) string(REGEX MATCHALL "[0-9]" _version_minor "${_version_string}") - file(STRINGS ${SUPERLUDIST_VERSION_PATH} _version_patch REGEX "SUPERLU_DIST_PATCH_VERSION") + file(STRINGS "${SUPERLUDIST_VERSION_PATH}" _version_patch REGEX "SUPERLU_DIST_PATCH_VERSION") list(GET _version_patch 0 _version_string) string(REGEX MATCHALL "[0-9]" _version_patch "${_version_string}") @@ -96,12 +105,26 @@ if(SUPERLUDIST_LIBRARY AND SUPERLUDIST_INCLUDE_DIR) mark_as_advanced(FORCE SUPERLUDIST_VERSION_PATH) endif() +# add libraries for OpenMP support +if(SUPERLUDIST_OpenMP) + list(APPEND SUPERLUDIST_LINK_LIBRARIES OpenMP::OpenMP_CXX) +endif() +# add libraries for GPU support +if(SUPERLUDIST_CUDA) + list(APPEND SUPERLUDIST_LINK_LIBRARIES CUDA::cudart CUDA::cublas) +endif() +if(SUPERLUDIST_ROCM) + find_package(hipblas REQUIRED) + find_package(rocsolver REQUIRED) + find_package(rocblas REQUIRED) + list(APPEND SUPERLUDIST_LINK_LIBRARIES hip::device roc::hipblas roc::rocblas roc::rocsolver) +endif() + # set package variables including SUPERLUDIST_FOUND find_package_handle_standard_args(SUPERLUDIST REQUIRED_VARS - SUPERLUDIST_LIBRARY - SUPERLUDIST_LIBRARIES - SUPERLUDIST_INCLUDE_DIR + SUPERLUDIST_LINK_LIBRARIES + SUPERLUDIST_INCLUDE_DIRS SUPERLUDIST_INDEX_SIZE VERSION_VAR SUPERLUDIST_VERSION @@ -111,12 +134,11 @@ find_package_handle_standard_args(SUPERLUDIST if(SUPERLUDIST_FOUND) if(NOT TARGET SUNDIALS::SUPERLUDIST) - add_library(SUNDIALS::SUPERLUDIST UNKNOWN IMPORTED) + add_library(SUNDIALS::SUPERLUDIST INTERFACE IMPORTED) endif() set_target_properties(SUNDIALS::SUPERLUDIST PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SUPERLUDIST_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${SUPERLUDIST_LIBRARIES}" - IMPORTED_LOCATION "${SUPERLUDIST_LIBRARY}") + INTERFACE_INCLUDE_DIRECTORIES "${SUPERLUDIST_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${SUPERLUDIST_LINK_LIBRARIES}") endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUMT.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUMT.cmake index 153fa7c04..4e1acb30b 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUMT.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/FindSUPERLUMT.cmake @@ -2,7 +2,7 @@ # Programmer(s): Eddy Banks and David J. Gardner @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -38,7 +38,8 @@ force_variable(SUPERLUMT_THREAD_TYPE STRING "SuperLU_MT threading type: OPENMP o if(SUPERLUMT_THREAD_TYPE AND NOT SUPERLUMT_THREAD_TYPE STREQUAL "OPENMP" AND NOT SUPERLUMT_THREAD_TYPE STREQUAL "PTHREAD") - print_error("Unknown thread type: ${SUPERLUMT_THREAD_TYPE}" "Please enter PTHREAD or OPENMP") + message(FATAL_ERROR "Unknown thread type: ${SUPERLUMT_THREAD_TYPE} " + "Please enter PTHREAD or OPENMP") endif() # check if the threading library has been found @@ -51,7 +52,7 @@ if(SUPERLUMT_THREAD_TYPE STREQUAL "PTHREAD") message(STATUS "Using Pthreads") else() set(PTHREADS_FOUND FALSE) - print_error("Could not determine Pthreads compiler flags") + message(FATAL_ERROR "Could not determine Pthreads compiler flags") endif() endif() else(SUPERLUMT_THREAD_TYPE STREQUAL "OPENMP") @@ -92,8 +93,9 @@ if(NOT SUPERLUMT_LIBRARY) endif() # set the libraries, stripping out 'NOTFOUND' from previous attempts -string(REPLACE "SUPERLUMT_LIBRARY-NOTFOUND" "" SUPERLUMT_LIBRARIES "${SUPERLUMT_LIBRARIES}") -set(SUPERLUMT_LIBRARIES "${SUPERLUMT_LIBRARY};${SUPERLUMT_LIBRARIES}" CACHE STRING "" FORCE) +if(NOT (SUPERLUMT_LIBRARIES MATCHES "${SUPERLUMT_LIBRARY_NAME}")) + set(SUPERLUMT_LIBRARIES "${SUPERLUMT_LIBRARY};${SUPERLUMT_LIBRARIES}" CACHE STRING "" FORCE) +endif() # set the library dir option if it wasn't preset if(SUPERLUMT_LIBRARY AND (NOT SUPERLUMT_LIBRARY_DIR)) @@ -137,4 +139,6 @@ if(SUPERLUMT_FOUND) INTERFACE_LINK_LIBRARIES "${SUPERLUMT_LIBRARIES}" IMPORTED_LOCATION "${SUPERLUMT_LIBRARY}") + list2string(SUPERLUMT_LIBRARIES EXAMPLES_SUPERLUMT_LIBRARIES) + endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsKLU.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsKLU.cmake index fd7947cac..f3c006608 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsKLU.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsKLU.cmake @@ -2,7 +2,7 @@ # Programmer(s): Steven Smith and Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -38,7 +38,7 @@ endif() # KLU does not support single or extended precision if(SUNDIALS_PRECISION MATCHES "SINGLE" OR SUNDIALS_PRECISION MATCHES "EXTENDED") - print_error("KLU is not compatible with ${SUNDIALS_PRECISION} precision") + message(FATAL_ERROR "KLU is not compatible with ${SUNDIALS_PRECISION} precision") endif() # ----------------------------------------------------------------------------- @@ -49,8 +49,7 @@ find_package(KLU REQUIRED) message(STATUS "KLU_LIBRARIES: ${KLU_LIBRARIES}") message(STATUS "KLU_INCLUDE_DIR: ${KLU_INCLUDE_DIR}") -list(JOIN KLU_LIBRARIES "\" \"" KLU_LIBRARIES_TMP) -set(KLU_LIBRARIES_TMP \"${KLU_LIBRARIES_TMP}\") + # ----------------------------------------------------------------------------- # Section 4: Test the TPL # ----------------------------------------------------------------------------- @@ -58,29 +57,47 @@ set(KLU_LIBRARIES_TMP \"${KLU_LIBRARIES_TMP}\") if(KLU_FOUND AND (NOT KLU_WORKS)) # Do any checks which don't require compilation first. + if(SUNDIALS_INDEX_SIZE MATCHES "64") + # Check size of SuiteSparse_long + include(CheckTypeSize) + set(save_CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES}) + list(APPEND CMAKE_EXTRA_INCLUDE_FILES "klu.h") + set(save_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${KLU_INCLUDE_DIR}) + check_type_size("SuiteSparse_long" SIZEOF_SUITESPARSE_LONG) + set(CMAKE_EXTRA_INCLUDE_FILES ${save_CMAKE_EXTRA_INCLUDE_FILES}) + set(CMAKE_REQUIRED_INCLUDES ${save_CMAKE_REQUIRED_INCLUDES}) + message(STATUS "Size of SuiteSparse_long is ${SIZEOF_SUITESPARSE_LONG}") + if(NOT SIZEOF_SUITESPARSE_LONG EQUAL "8") + message(FATAL_ERROR "Size of 'sunindextype' is 8 but size of 'SuiteSparse_long' is ${SIZEOF_SUITESPARSE_LONG}. KLU cannot be used.") + endif() + endif() + # Create the KLU_TEST directory - set(KLU_TEST_DIR "${PROJECT_BINARY_DIR}/KLU_TEST") + set(KLU_TEST_DIR ${PROJECT_BINARY_DIR}/KLU_TEST) file(MAKE_DIRECTORY ${KLU_TEST_DIR}) # Create a CMakeLists.txt file - file(WRITE "${KLU_TEST_DIR}/CMakeLists.txt" - "CMAKE_MINIMUM_REQUIRED(VERSION 3.1.3)\n" + file(WRITE ${KLU_TEST_DIR}/CMakeLists.txt + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ltest C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_STANDARD \"${CMAKE_C_STANDARD}\")\n" "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" - "INCLUDE_DIRECTORIES(\"${KLU_INCLUDE_DIR}\")\n" + "INCLUDE_DIRECTORIES(${KLU_INCLUDE_DIR})\n" "ADD_EXECUTABLE(ltest ltest.c)\n" - "TARGET_LINK_LIBRARIES(ltest ${KLU_LIBRARIES_TMP})\n") + "TARGET_LINK_LIBRARIES(ltest ${KLU_LIBRARIES})\n") # Create a C source file which calls a KLU function - file(WRITE "${KLU_TEST_DIR}/ltest.c" + file(WRITE ${KLU_TEST_DIR}/ltest.c "\#include \"klu.h\"\n" - "int main(){\n" + "int main(void) {\n" "klu_common Common;\n" "klu_defaults (&Common);\n" "return(0);\n" @@ -88,10 +105,10 @@ if(KLU_FOUND AND (NOT KLU_WORKS)) # To ensure we do not use stuff from the previous attempts, # we must remove the CMakeFiles directory. - file(REMOVE_RECURSE "${KLU_TEST_DIR}/CMakeFiles") + file(REMOVE_RECURSE ${KLU_TEST_DIR}/CMakeFiles) # Attempt to build and link the "ltest" executable - try_compile(COMPILE_OK "${KLU_TEST_DIR}" "${KLU_TEST_DIR}" ltest + try_compile(COMPILE_OK ${KLU_TEST_DIR} ${KLU_TEST_DIR} ltest OUTPUT_VARIABLE COMPILE_OUTPUT) # Process test result @@ -102,7 +119,7 @@ if(KLU_FOUND AND (NOT KLU_WORKS)) message(STATUS "Checking if KLU works... FAILED") message(STATUS "Check output: ") message("${COMPILE_OUTPUT}") - print_error("SUNDIALS interface to KLU is not functional.") + message(FATAL_ERROR "SUNDIALS interface to KLU is not functional.") endif() elseif(KLU_FOUND AND KLU_WORKS) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsLapack.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsLapack.cmake index 05f9b7d87..0047d6afd 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsLapack.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsLapack.cmake @@ -2,7 +2,7 @@ # Programmer(s): Radu Serban and Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -65,6 +65,231 @@ message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}") # Section 4: Test the TPL # ----------------------------------------------------------------------------- +# --------------------------------------------------------------- +# Determining the name-mangling scheme if needed +# --------------------------------------------------------------- +# In general, names of symbols with and without underscore may be mangled +# differently (e.g. g77 mangles mysub to mysub_ and my_sub to my_sub__), +# we have to consider both cases. +# +# Method: +# 1) create a library from a Fortran source file which defines a function "mysub" +# 2) attempt to link with this library a C source file which calls the "mysub" +# function using various possible schemes (6 different schemes, corresponding +# to all combinations lower/upper case and none/one/two underscores). +# 3) define the name-mangling scheme based on the test that was successful. +# +# On exit, if we were able to infer the scheme, the variables +# CMAKE_Fortran_SCHEME_NO_UNDERSCORES and CMAKE_Fortran_SCHEME_WITH_UNDERSCORES +# contain the mangled names for "mysub" and "my_sub", respectively. +# --------------------------------------------------------------- +if(NEED_FORTRAN_NAME_MANGLING) + + set(CMAKE_Fortran_SCHEME_NO_UNDERSCORES "") + set(CMAKE_Fortran_SCHEME_WITH_UNDERSCORES "") + + # Create the FortranTest directory + set(FortranTest_DIR ${PROJECT_BINARY_DIR}/FortranTest) + file(MAKE_DIRECTORY ${FortranTest_DIR}) + + # Create a CMakeLists.txt file which will generate the "flib" library + # and an executable "ftest" + file(WRITE ${FortranTest_DIR}/CMakeLists.txt + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" + "PROJECT(ftest Fortran)\n" + "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" + "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_Fortran_COMPILER \"${CMAKE_Fortran_COMPILER}\")\n" + "SET(CMAKE_Fortran_FLAGS \"${CMAKE_Fortran_FLAGS}\")\n" + "SET(CMAKE_Fortran_FLAGS_RELEASE \"${CMAKE_Fortran_FLAGS_RELEASE}\")\n" + "SET(CMAKE_Fortran_FLAGS_DEBUG \"${CMAKE_Fortran_FLAGS_DEBUG}\")\n" + "SET(CMAKE_Fortran_FLAGS_RELWITHDEBUGINFO \"${CMAKE_Fortran_FLAGS_RELWITHDEBUGINFO}\")\n" + "SET(CMAKE_Fortran_FLAGS_MINSIZE \"${CMAKE_Fortran_FLAGS_MINSIZE}\")\n" + "ADD_LIBRARY(flib flib.f)\n" + "ADD_EXECUTABLE(ftest ftest.f)\n" + "TARGET_LINK_LIBRARIES(ftest flib)\n") + + # Create the Fortran source flib.f which defines two subroutines, "mysub" and "my_sub" + file(WRITE ${FortranTest_DIR}/flib.f + " SUBROUTINE mysub\n" + " RETURN\n" + " END\n" + " SUBROUTINE my_sub\n" + " RETURN\n" + " END\n") + + # Create the Fortran source ftest.f which calls "mysub" and "my_sub" + file(WRITE ${FortranTest_DIR}/ftest.f + " PROGRAM ftest\n" + " CALL mysub()\n" + " CALL my_sub()\n" + " END\n") + + # Use TRY_COMPILE to make the targets "flib" and "ftest" + try_compile(FTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ftest OUTPUT_VARIABLE MY_OUTPUT) + + # To ensure we do not use stuff from the previous attempts, + # we must remove the CMakeFiles directory. + file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) + + # Proceed based on test results + if(FTEST_OK) + + # Infer Fortran name-mangling scheme for symbols WITHOUT underscores. + # Overwrite CMakeLists.txt with one which will generate the "ctest1" executable + file(WRITE ${FortranTest_DIR}/CMakeLists.txt + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" + "PROJECT(ctest1 C)\n" + "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" + "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" + "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" + "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" + "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" + "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" + "ADD_EXECUTABLE(ctest1 ctest1.c)\n" + "FIND_LIBRARY(FLIB flib \"${FortranTest_DIR}\")\n" + "TARGET_LINK_LIBRARIES(ctest1 \${FLIB})\n") + + # Define the list "options" of all possible schemes that we want to consider + # Get its length and initialize the counter "iopt" to zero + set(options mysub mysub_ mysub__ MYSUB MYSUB_ MYSUB__) + list(LENGTH options imax) + set(iopt 0) + + # We will attempt to sucessfully generate the "ctest1" executable as long as + # there still are entries in the "options" list + while(${iopt} LESS ${imax}) + # Get the current list entry (current scheme) + list(GET options ${iopt} opt) + # Generate C source which calls the "mysub" function using the current scheme + file(WRITE ${FortranTest_DIR}/ctest1.c + "extern void ${opt}();\n" + "int main(void){${opt}();return(0);}\n") + # Use TRY_COMPILE to make the "ctest1" executable from the current C source + # and linking to the previously created "flib" library. + try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ctest1 OUTPUT_VARIABLE MY_OUTPUT) + # Write output compiling the test code + file(WRITE ${FortranTest_DIR}/ctest1_${opt}.out "${MY_OUTPUT}") + # To ensure we do not use stuff from the previous attempts, + # we must remove the CMakeFiles directory. + file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) + # Test if we successfully created the "ctest" executable. + # If yes, save the current scheme, and set the counter "iopt" to "imax" + # so that we exit the while loop. + # Otherwise, increment the counter "iopt" and go back in the while loop. + if(CTEST_OK) + set(CMAKE_Fortran_SCHEME_NO_UNDERSCORES ${opt}) + set(iopt ${imax}) + else(CTEST_OK) + math(EXPR iopt ${iopt}+1) + endif() + endwhile(${iopt} LESS ${imax}) + + # Infer Fortran name-mangling scheme for symbols WITH underscores. + # Practically a duplicate of the previous steps. + file(WRITE ${FortranTest_DIR}/CMakeLists.txt + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" + "PROJECT(ctest2 C)\n" + "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" + "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" + "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" + "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" + "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" + "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" + "ADD_EXECUTABLE(ctest2 ctest2.c)\n" + "FIND_LIBRARY(FLIB flib \"${FortranTest_DIR}\")\n" + "TARGET_LINK_LIBRARIES(ctest2 \${FLIB})\n") + + set(options my_sub my_sub_ my_sub__ MY_SUB MY_SUB_ MY_SUB__) + list(LENGTH options imax) + set(iopt 0) + while(${iopt} LESS ${imax}) + list(GET options ${iopt} opt) + file(WRITE ${FortranTest_DIR}/ctest2.c + "extern void ${opt}();\n" + "int main(void){${opt}();return(0);}\n") + try_compile(CTEST_OK ${FortranTest_DIR} ${FortranTest_DIR} + ctest2 OUTPUT_VARIABLE MY_OUTPUT) + file(WRITE ${FortranTest_DIR}/ctest2_${opt}.out "${MY_OUTPUT}") + file(REMOVE_RECURSE ${FortranTest_DIR}/CMakeFiles) + if(CTEST_OK) + set(CMAKE_Fortran_SCHEME_WITH_UNDERSCORES ${opt}) + set(iopt ${imax}) + else(CTEST_OK) + math(EXPR iopt ${iopt}+1) + endif() + endwhile(${iopt} LESS ${imax}) + + # If a name-mangling scheme was found set the C preprocessor macros to use + # that scheme. Otherwise default to lower case with one underscore. + if(CMAKE_Fortran_SCHEME_NO_UNDERSCORES AND CMAKE_Fortran_SCHEME_WITH_UNDERSCORES) + message(STATUS "Determining Fortran name-mangling scheme... OK") + else() + message(STATUS "Determining Fortran name-mangling scheme... DEFAULT") + set(CMAKE_Fortran_SCHEME_NO_UNDERSCORES "mysub_") + set(CMAKE_Fortran_SCHEME_WITH_UNDERSCORES "my_sub_") + endif() + + # Symbols NO underscores + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name") + endif() + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub_") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## _") + endif() + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "mysub__") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) name ## __") + endif() + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME") + endif() + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB_") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## _") + endif() + if(${CMAKE_Fortran_SCHEME_NO_UNDERSCORES} MATCHES "MYSUB__") + set(LAPACK_MANGLE_MACRO1 "#define SUNDIALS_LAPACK_FUNC(name,NAME) NAME ## __") + endif() + + # Symbols WITH underscores + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name") + endif() + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub_") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## _") + endif() + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "my_sub__") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) name ## __") + endif() + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME") + endif() + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB_") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## _") + endif() + if(${CMAKE_Fortran_SCHEME_WITH_UNDERSCORES} MATCHES "MY_SUB__") + set(LAPACK_MANGLE_MACRO2 "#define SUNDIALS_LAPACK_FUNC_(name,NAME) NAME ## __") + endif() + + # name-mangling scheme has been set + set(NEED_FORTRAN_NAME_MANGLING FALSE) + + configure_file( + ${PROJECT_SOURCE_DIR}/src/sundials/sundials_lapack_defs.h.in + ${PROJECT_BINARY_DIR}/src/sundials/sundials_lapack_defs.h + ) + + else(FTEST_OK) + message(STATUS "Determining Fortran name-mangling scheme... FAILED") + endif() + +endif() + # If we have the LAPACK libraries, determine if they work. if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) # Create the LapackTest directory @@ -73,10 +298,12 @@ if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) # Create a CMakeLists.txt file file(WRITE ${LapackTest_DIR}/CMakeLists.txt - "CMAKE_MINIMUM_REQUIRED(VERSION 2.4)\n" + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ltest C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_STANDARD \"${CMAKE_C_STANDARD}\")\n" "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" @@ -87,14 +314,15 @@ if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) # Create a C source file which calls a Blas function (dcopy) and an Lapack function (dgetrf) file(WRITE ${LapackTest_DIR}/ltest.c - "${F77_MANGLE_MACRO1}\n" - "#define dcopy_f77 SUNDIALS_F77_FUNC(dcopy, DCOPY)\n" - "#define dgetrf_f77 SUNDIALS_F77_FUNC(dgetrf, DGETRF)\n" + "${LAPACK_MANGLE_MACRO1}\n" + "#define dcopy_f77 SUNDIALS_LAPACK_FUNC(dcopy, DCOPY)\n" + "#define dgetrf_f77 SUNDIALS_LAPACK_FUNC(dgetrf, DGETRF)\n" "extern void dcopy_f77(int *n, const double *x, const int *inc_x, double *y, const int *inc_y);\n" "extern void dgetrf_f77(const int *m, const int *n, double *a, int *lda, int *ipiv, int *info);\n" - "int main(){\n" + "int main(void) {\n" "int n=1;\n" - "double x, y;\n" + "double x=1.0;\n" + "double y=1.0;\n" "dcopy_f77(&n, &x, &n, &y, &n);\n" "dgetrf_f77(&n, &n, &x, &n, &n, &n);\n" "return(0);\n" @@ -127,7 +355,7 @@ if(LAPACK_LIBRARIES AND (NOT LAPACK_WORKS)) message(STATUS "Checking if LAPACK works with SUNDIALS... FAILED") message(STATUS "Check output: ") message("${COMPILE_OUTPUT}") - print_error("SUNDIALS interface to LAPACK is not functional.") + message(FATAL_ERROR "SUNDIALS interface to LAPACK is not functional.") endif() elseif(LAPACK_LIBRARIES AND LAPACK_WORKS) diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsOpenMP.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsOpenMP.cmake index 50a43ab97..d845a2788 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsOpenMP.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsOpenMP.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -69,7 +69,7 @@ if(OPENMP_FOUND AND (ENABLE_OPENMP_DEVICE OR SUPERLUDIST_OpenMP)) # The user has asked for checks to be skipped, assume offloading is supported set(OPENMP45_FOUND TRUE) set(OPENMP_SUPPORTS_DEVICE_OFFLOADING TRUE) - print_warning("Skipping OpenMP device/version check." "SUNDIALS OpenMP functionality dependent on OpenMP 4.5+ is not guaranteed.") + message(WARNING "Skipping OpenMP device/version check." "SUNDIALS OpenMP functionality dependent on OpenMP 4.5+ is not guaranteed.") else() @@ -84,9 +84,9 @@ if(OPENMP_FOUND AND (ENABLE_OPENMP_DEVICE OR SUPERLUDIST_OpenMP)) message(STATUS "Checking whether OpenMP supports device offloading -- no") set(OPENMP45_FOUND FALSE) set(OPENMP_SUPPORTS_DEVICE_OFFLOADING FALSE) - print_error("The found OpenMP version does not support device offloading.") + message(FATAL_ERROR "The found OpenMP version does not support device offloading.") endif() endif() -endif() \ No newline at end of file +endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPOSIXTimers.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPOSIXTimers.cmake index 0fd718e4b..4670849ac 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPOSIXTimers.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPOSIXTimers.cmake @@ -1,8 +1,8 @@ -# --------------------------------------------------------------------------- +# ------------------------------------------------------------------------------ # Programmer(s): David J. Gardner @ LLNL -# --------------------------------------------------------------------------- +# ------------------------------------------------------------------------------ # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -10,78 +10,120 @@ # # SPDX-License-Identifier: BSD-3-Clause # SUNDIALS Copyright End -# --------------------------------------------------------------------------- -# Check if POSIX timers are available and test if they can be used as some -# compiler flags will preclude using POSIX timers even if they are present -# (e.g., -ansi). -# --------------------------------------------------------------------------- - -# clock-monotonic, see if we need to link with rt -include(CheckSymbolExists) - -# save and overwrite required libraries to check for timers -set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES}) -set(CMAKE_REQUIRED_LIBRARIES rt) - -# check if _POSIX_TIMERS macro is defined in required libraries -check_symbol_exists(_POSIX_TIMERS "unistd.h;time.h" SUNDIALS_POSIX_TIMERS) - -# restore required libraries -set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE}) - -if(SUNDIALS_POSIX_TIMERS) - - # locate rt library and hide cache variable - find_library(SUNDIALS_RT_LIBRARY NAMES rt) - mark_as_advanced(SUNDIALS_RT_LIBRARY) - - if(SUNDIALS_RT_LIBRARY) - - # Test timers with a simple program - set(POSIXTest_DIR ${PROJECT_BINARY_DIR}/PosixTimersTest) - file(MAKE_DIRECTORY ${POSIXTest_DIR}) - - # Create a CMakeLists.txt file which will generate the test executable - file(WRITE ${POSIXTest_DIR}/CMakeLists.txt - "CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)\n" - "PROJECT(posixtimerstest C)\n" - "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" - "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" - "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" - "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" - "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" - "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" - "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" - "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" - "ADD_EXECUTABLE(posixtimerstest posixtimerstest.c)\n" - "TARGET_LINK_LIBRARIES(posixtimerstest ${SUNDIALS_RT_LIBRARY})\n") - - # Create a simple C source for testing - file(WRITE ${POSIXTest_DIR}/posixtimerstest.c - "#include \n" - "#include \n" - "int main(){\n" - "time_t base_time_tv_sec = 0;\n" - "struct timespec spec;\n" - "clock_gettime(CLOCK_MONOTONIC_RAW, &spec);\n" - "base_time_tv_sec = spec.tv_sec;\n" - "clock_getres(CLOCK_MONOTONIC_RAW, &spec);\n" - "return(0);\n" - "}\n") - - # Use TRY_COMPILE to make the target - try_compile(POSIX_TIMERS_TEST_OK ${POSIXTest_DIR} ${POSIXTest_DIR} - posixtimerstest OUTPUT_VARIABLE MY_OUTPUT) - - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. - file(REMOVE_RECURSE ${POSIXTest_DIR}/CMakeFiles) - - # Process test result - if(POSIX_TIMERS_TEST_OK) - # add rt library to list of extra libraries linked against - set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} ${SUNDIALS_RT_LIBRARY}) +# ------------------------------------------------------------------------------ +# Test if POSIX timers are available and can be used (some compiler flags will +# disable POSIX timers even if they are present e.g., -ansi). +# ------------------------------------------------------------------------------ + +macro(posix_timers_test) + + set(options ) + set(oneValueArgs POSIX RT_LIB) + set(multiValueArgs ) + + # parse keyword arguments/options + cmake_parse_arguments(posix_timers_test + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Test timers with a simple program + set(POSIX_TIMER_TEST_DIR ${PROJECT_BINARY_DIR}/POSIX_TIMER_TEST) + file(MAKE_DIRECTORY ${POSIX_TIMER_TEST_DIR}) + + # Create a CMakeLists.txt file which will generate the test executable + file(WRITE ${POSIX_TIMER_TEST_DIR}/CMakeLists.txt + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" + "PROJECT(ltest C)\n" + "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" + "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" + "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_STANDARD ${CMAKE_C_STANDARD})\n" + "SET(CMAKE_C_EXTENSIONS ${CMAKE_C_EXTENSIONS})\n" + "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" + "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" + "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" + "SET(CMAKE_C_FLAGS_RELWITHDEBUGINFO \"${CMAKE_C_FLAGS_RELWITHDEBUGINFO}\")\n" + "SET(CMAKE_C_FLAGS_MINSIZE \"${CMAKE_C_FLAGS_MINSIZE}\")\n" + "ADD_EXECUTABLE(ltest ltest.c)\n" + "TARGET_COMPILE_DEFINITIONS(ltest PRIVATE \"${posix_timers_test_POSIX}\")\n" + "TARGET_LINK_LIBRARIES(ltest \"${posix_timers_test_RT_LIB}\")\n") + + # Create a simple C source for testing + file(WRITE ${POSIX_TIMER_TEST_DIR}/ltest.c + "#include \n" + "#include \n" + "int main(void) {\n" + "struct timespec spec;\n" + "clock_gettime(CLOCK_MONOTONIC, &spec);\n" + "clock_getres(CLOCK_MONOTONIC, &spec);\n" + "return(0);\n" + "}\n") + + # To ensure we do not use stuff from the previous attempts, + # we must remove the CMakeFiles directory. + file(REMOVE_RECURSE ${POSIX_TIMER_TEST_DIR}/CMakeFiles) + + # Use TRY_COMPILE to make the target + try_compile(COMPILE_OK ${POSIX_TIMER_TEST_DIR} ${POSIX_TIMER_TEST_DIR} ltest + OUTPUT_VARIABLE COMPILE_OUTPUT) + +endmacro() + + +if (NOT SUNDIALS_POSIX_TIMERS) + + # Test for timers without any modifications + posix_timers_test() + if(COMPILE_OK) + message(STATUS "Looking for POSIX timers... found") + endif() + + # Test failed, try again with -D_POSIX_C_SOURCE=200112L + if(NOT COMPILE_OK) + posix_timers_test(POSIX "_POSIX_C_SOURCE=200112L") + if(COMPILE_OK) + message(STATUS "Looking for POSIX timers (setting _POSIX_C_SOURCE)... found") + set(POSIX_TIMERS_NEED_POSIX_C_SOURCE TRUE) + endif() + endif() + + # Test failed, try again linking to rt + if(NOT COMPILE_OK) + + # Locate rt library and hide cache variable + find_library(SUNDIALS_RT_LIBRARY NAMES rt) + mark_as_advanced(SUNDIALS_RT_LIBRARY) + + if(SUNDIALS_RT_LIBRARY) + message(STATUS "Looking for rt library... found") + posix_timers_test(RT_LIB "${SUNDIALS_RT_LIBRARY}") + if(COMPILE_OK) + message(STATUS "Looking for POSIX timers (linking to rt)... found") + set(POSIX_TIMERS_NEED_RT_LIBRARY TRUE) + set(EXE_EXTRA_LINK_LIBS ${EXE_EXTRA_LINK_LIBS} ${SUNDIALS_RT_LIBRARY}) + endif() + else() + message(STATUS "Looking for rt library... FAILED") endif() endif() + + # Test failed, try again linking to rt and with -D_POSIX_C_SOURCE=200112L + if((NOT COMPILE_OK) AND SUNDIALS_RT_LIBRARY) + posix_timers_test(POSIX "_POSIX_C_SOURCE=200112L" RT_LIB "${SUNDIALS_RT_LIBRARY}") + if(COMPILE_OK) + message(STATUS "Looking for POSIX timers (setting _POSIX_C_SOURCE and linking to rt)... found") + set(POSIX_TIMERS_NEED_POSIX_C_SOURCE TRUE) + set(POSIX_TIMERS_NEED_RT_LIBRARY TRUE) + set(EXE_EXTRA_LINK_LIBS ${EXE_EXTRA_LINK_LIBS} ${SUNDIALS_RT_LIBRARY}) + endif() + endif() + + # Set POSIX timer status + if(COMPILE_OK) + set(SUNDIALS_POSIX_TIMERS TRUE) + else() + message(STATUS "Looking for POSIX timers... FAILED") + set(SUNDIALS_POSIX_TIMERS FALSE) + endif() + endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPthread.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPthread.cmake index be715af64..f19b07c09 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPthread.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsPthread.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -53,5 +53,5 @@ if(CMAKE_USE_PTHREADS_INIT) else() set(PTHREADS_FOUND FALSE) message(STATUS "Checking if Pthreads is available... FAILED") - print_error("Could not determine Pthreads compiler flags") -endif() \ No newline at end of file + message(FATAL_ERROR "Could not determine Pthreads compiler flags") +endif() diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUDIST.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUDIST.cmake index bb676d20d..2dfc84a56 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUDIST.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUDIST.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -38,17 +38,17 @@ endif() # SuperLU_DIST only supports double precision if(SUNDIALS_PRECISION MATCHES "SINGLE" OR SUNDIALS_PRECISION MATCHES "EXTENDED") - print_error("SuperLU_DIST is not compatible with ${SUNDIALS_PRECISION} precision") + message(FATAL_ERROR "SuperLU_DIST is not compatible with ${SUNDIALS_PRECISION} precision") endif() # Using SUPERLUDIST requires building with MPI enabled if(ENABLE_SUPERLUDIST AND NOT ENABLE_MPI) - print_error("MPI is required for SuperLU DIST support. Set ENABLE_MPI to ON.") + message(FATAL_ERROR "MPI is required for SuperLU DIST support. Set ENABLE_MPI to ON.") endif() # Using SUPERLUDIST with OpenMP requires building with OpenMP enabled if(ENABLE_SUPERLUDIST AND SUPERLUDIST_OpenMP AND NOT ENABLE_OPENMP) - print_error("OpenMP is required for SuperLU DIST support. Set ENABLE_OPENMP to ON.") + message(FATAL_ERROR "OpenMP is required for SuperLU DIST support. Set ENABLE_OPENMP to ON.") endif() # ----------------------------------------------------------------------------- @@ -58,28 +58,16 @@ endif() # We need MPI for SuperLU_DIST support include(SundialsMPI) -# SuperLU_DIST OpenMP node parallelism is on, make sure OpenMP as found and is -# at least version 4.5. -if(SUPERLUDIST_OpenMP) - include(SundialsOpenMP) - - if(NOT OPENMP_FOUND) - print_error("SUPERLUDIST_OpenMP is set to ON but OpenMP was not found.") - elseif(NOT OPENMP45_FOUND) - string(CONCAT ERRSTR "SuperLUDIST requires OpenMP 4.5+ but it was not found. " - "If you are sure OpenMP 4.5+ is available set the OPENMP_DEVICE_WORKS " - "advanced option to ON.") - print_error(${ERRSTR}) - endif() -endif() - # Try to find SuperLU_DIST -find_package(SUPERLUDIST 6.1.1 REQUIRED) +find_package(SUPERLUDIST 7.0.0 REQUIRED) -message(STATUS "SUPERLUDIST_LIBRARIES: ${SUPERLUDIST_LIBRARIES}") -message(STATUS "SUPERLUDIST_INCLUDE_DIR: ${SUPERLUDIST_INCLUDE_DIR}") -message(STATUS "SUPERLUDIST_INDEX_SIZE: ${SUPERLUDIST_INDEX_SIZE}") -message(STATUS "SUPERLUDIST_OpenMP: ${SUPERLUDIST_OpenMP}") +message(STATUS "SUPERLUDIST_VERSION: ${SUPERLUDIST_VERSION}") +message(STATUS "SUPERLUDIST_LINK_LIBRARIES: ${SUPERLUDIST_LINK_LIBRARIES}") +message(STATUS "SUPERLUDIST_INCLUDE_DIRS: ${SUPERLUDIST_INCLUDE_DIRS}") +message(STATUS "SUPERLUDIST_INDEX_SIZE: ${SUPERLUDIST_INDEX_SIZE}") +message(STATUS "SUPERLUDIST_OpenMP: ${SUPERLUDIST_OpenMP}") +message(STATUS "SUPERLUDIST_CUDA: ${SUPERLUDIST_CUDA}") +message(STATUS "SUPERLUDIST_ROCM: ${SUPERLUDIST_ROCM}") # ----------------------------------------------------------------------------- # Section 4: Test the TPL @@ -88,65 +76,25 @@ message(STATUS "SUPERLUDIST_OpenMP: ${SUPERLUDIST_OpenMP}") # If we have the SuperLU_DIST libraries, test them if(SUPERLUDIST_FOUND AND (NOT SUPERLUDIST_WORKS)) + if(SUPERLUDIST_CUDA AND (NOT ENABLE_CUDA)) + message(FATAL_ERROR "SuperLU_DIST was built with CUDA but SUNDIALS does not have CUDA enabled. Set ENABLE_CUDA=TRUE.") + endif() + + if(SUPERLUDIST_HIP AND (NOT ENABLE_HIP)) + message(FATAL_ERROR "SuperLU_DIST was built with HIP but SUNDIALS does not have HIP enabled. Set ENABLE_HIP=TRUE.") + endif() + # Check index size if(NOT (SUNDIALS_INDEX_SIZE STREQUAL SUPERLUDIST_INDEX_SIZE)) set(_err_msg_string "SuperLU_DIST not functional due to index size mismatch:\n") string(APPEND _err_msg_string "SUNDIALS_INDEX_SIZE=${SUNDIALS_INDEX_SIZE}, but SuperLU_DIST was built with ${SUPERLUDIST_INDEX_SIZE}-bit indices\n") - string(APPEND _err_msg_string "SUPERLUDIST_INCLUDE_DIR: ${SUPERLUDIST_INCLUDE_DIR}\n") - print_error("${_err_msg_string}") + string(APPEND _err_msg_string "SUPERLUDIST_INCLUDE_DIRS: ${SUPERLUDIST_INCLUDE_DIRS}\n") + message(FATAL_ERROR "${_err_msg_string}") endif() - # Create the SUPERLUDIST_TEST directory - set(SUPERLUDIST_TEST_DIR ${PROJECT_BINARY_DIR}/SUPERLUDIST_Test) - file(MAKE_DIRECTORY ${SUPERLUDIST_TEST_DIR}) - - # Create a CMakeLists.txt file - file(WRITE ${SUPERLUDIST_TEST_DIR}/CMakeLists.txt - "CMAKE_MINIMUM_REQUIRED(VERSION 3.1.3)\n" - "PROJECT(ltest CXX)\n" - "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" - "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" - "SET(CMAKE_CXX_COMPILER \"${MPI_CXX_COMPILER}\")\n" - "SET(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS}\")\n" - "SET(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE}\")\n" - "SET(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG}\")\n" - "SET(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO \"${CMAKE_CXX_FLAGS_RELWITHDEBUGINFO}\")\n" - "SET(CMAKE_CXX_FLAGS_MINSIZE \"${CMAKE_CXX_FLAGS_MINSIZE}\")\n" - "ADD_EXECUTABLE(ltest ltest.cpp)\n" - "TARGET_INCLUDE_DIRECTORIES(ltest PRIVATE ${SUPERLUDIST_INCLUDE_DIR})\n" - "TARGET_LINK_LIBRARIES(ltest ${SUPERLUDIST_LIBRARIES})\n") - - # Create a CXX source file which calls a SuperLUDIST function - # and also prints the size of the indices used. - file(WRITE ${SUPERLUDIST_TEST_DIR}/ltest.cpp - "\#include \n" - "int main(){\n" - "SuperMatrix *A;\n" - "NRformat_loc *Astore;\n" - "A = NULL;\n" - "Astore = NULL;\n" - "if (A != NULL || Astore != NULL) return(1);\n" - "else return(0);\n" - "}\n") - - # Attempt to build and link the "ltest" executable - try_compile(COMPILE_OK ${SUPERLUDIST_TEST_DIR} ${SUPERLUDIST_TEST_DIR} ltest - OUTPUT_VARIABLE COMPILE_OUTPUT) - - # To ensure we do not use stuff from the previous attempts, - # we must remove the CMakeFiles directory. - file(REMOVE_RECURSE ${SUPERLUDIST_TEST_DIR}/CMakeFiles) - - # Process test result - if(COMPILE_OK) - message(STATUS "Checking if SuperLU_DIST works with SUNDIALS... OK") - set(SUPERLUDIST_WORKS TRUE CACHE BOOL "SuperLU_DIST works with SUNDIALS as configured" FORCE) - else() - message(STATUS "Checking if SuperLU_DIST works with SUNDIALS... FAILED") - message(STATUS "Check output: ") - message("${COMPILE_OUTPUT}") - print_error("SUNDIALS interface to SuperLU_DIST is not functional.") - endif() + + message(STATUS "Checking if SuperLU_DIST works with SUNDIALS... OK") + set(SUPERLUDIST_WORKS TRUE CACHE BOOL "SuperLU_DIST works with SUNDIALS as configured" FORCE) elseif(SUPERLUDIST_FOUND AND SUPERLUDIST_WORKS) message(STATUS "Skipped SuperLU_DIST tests, assuming SuperLU_DIST works with SUNDIALS. Set SUPERLUDIST_WORKS=FALSE to (re)run compatibility test.") diff --git a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUMT.cmake b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUMT.cmake index 83bca0de2..a7b6bf863 100644 --- a/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUMT.cmake +++ b/deps/AMICI/ThirdParty/sundials/cmake/tpl/SundialsSuperLUMT.cmake @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ----------------------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -38,7 +38,7 @@ endif() # SUPERLUMT does not support extended precision if(SUNDIALS_PRECISION MATCHES "EXTENDED") - print_error("SUPERLUMT is not compatible with ${SUNDIALS_PRECISION} precision") + message(FATAL_ERROR "SUPERLUMT is not compatible with ${SUNDIALS_PRECISION} precision") endif() # ----------------------------------------------------------------------------- @@ -62,11 +62,12 @@ if(SUPERLUMT_FOUND AND (NOT SUPERLUMT_WORKS)) # Create a CMakeLists.txt file file(WRITE ${SUPERLUMT_TEST_DIR}/CMakeLists.txt - "CMAKE_MINIMUM_REQUIRED(VERSION 3.1.3)\n" + "CMAKE_MINIMUM_REQUIRED(VERSION ${CMAKE_VERSION})\n" "PROJECT(ltest C)\n" "SET(CMAKE_VERBOSE_MAKEFILE ON)\n" "SET(CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\")\n" "SET(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n" + "SET(CMAKE_C_STANDARD ${CMAKE_C_STANDARD})\n" "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n" "SET(CMAKE_C_FLAGS_RELEASE \"${CMAKE_C_FLAGS_RELEASE}\")\n" "SET(CMAKE_C_FLAGS_DEBUG \"${CMAKE_C_FLAGS_DEBUG}\")\n" @@ -79,7 +80,7 @@ if(SUPERLUMT_FOUND AND (NOT SUPERLUMT_WORKS)) # Create a C source file which calls a SUPERLUMT function file(WRITE ${SUPERLUMT_TEST_DIR}/ltest.c "\#include \"slu_mt_ddefs.h\"\n" - "int main(){\n" + "int main(void) {\n" "SuperMatrix *A;\n" "NCformat *Astore;\n" "A = NULL;\n" @@ -105,7 +106,7 @@ if(SUPERLUMT_FOUND AND (NOT SUPERLUMT_WORKS)) message(STATUS "Checking if SuperLU_MT works with SUNDIALS... FAILED") message(STATUS "Check output: ") message("${COMPILE_OUTPUT}") - print_error("SUNDIALS interface to SuperLU_MT is not functional.") + message(FATAL_ERROR "SUNDIALS interface to SuperLU_MT is not functional.") endif() elseif(SUPERLUMT_FOUND AND SUPERLUMT_WORKS) diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes.h index 58fdff67b..8af98fc26 100644 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes.h +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -17,12 +17,12 @@ #ifndef _CVODES_H #define _CVODES_H -#include -#include -#include #include +#include +#include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -31,436 +31,450 @@ extern "C" { * ----------------- */ /* lmm */ -#define CV_ADAMS 1 -#define CV_BDF 2 +#define CV_ADAMS 1 +#define CV_BDF 2 /* itask */ -#define CV_NORMAL 1 -#define CV_ONE_STEP 2 +#define CV_NORMAL 1 +#define CV_ONE_STEP 2 /* ism */ -#define CV_SIMULTANEOUS 1 -#define CV_STAGGERED 2 -#define CV_STAGGERED1 3 +#define CV_SIMULTANEOUS 1 +#define CV_STAGGERED 2 +#define CV_STAGGERED1 3 /* DQtype */ -#define CV_CENTERED 1 -#define CV_FORWARD 2 +#define CV_CENTERED 1 +#define CV_FORWARD 2 /* interp */ -#define CV_HERMITE 1 -#define CV_POLYNOMIAL 2 +#define CV_HERMITE 1 +#define CV_POLYNOMIAL 2 /* return values */ -#define CV_SUCCESS 0 -#define CV_TSTOP_RETURN 1 -#define CV_ROOT_RETURN 2 - -#define CV_WARNING 99 - -#define CV_TOO_MUCH_WORK -1 -#define CV_TOO_MUCH_ACC -2 -#define CV_ERR_FAILURE -3 -#define CV_CONV_FAILURE -4 - -#define CV_LINIT_FAIL -5 -#define CV_LSETUP_FAIL -6 -#define CV_LSOLVE_FAIL -7 -#define CV_RHSFUNC_FAIL -8 -#define CV_FIRST_RHSFUNC_ERR -9 -#define CV_REPTD_RHSFUNC_ERR -10 -#define CV_UNREC_RHSFUNC_ERR -11 -#define CV_RTFUNC_FAIL -12 -#define CV_NLS_INIT_FAIL -13 -#define CV_NLS_SETUP_FAIL -14 -#define CV_CONSTR_FAIL -15 -#define CV_NLS_FAIL -16 - -#define CV_MEM_FAIL -20 -#define CV_MEM_NULL -21 -#define CV_ILL_INPUT -22 -#define CV_NO_MALLOC -23 -#define CV_BAD_K -24 -#define CV_BAD_T -25 -#define CV_BAD_DKY -26 -#define CV_TOO_CLOSE -27 -#define CV_VECTOROP_ERR -28 - -#define CV_NO_QUAD -30 -#define CV_QRHSFUNC_FAIL -31 -#define CV_FIRST_QRHSFUNC_ERR -32 -#define CV_REPTD_QRHSFUNC_ERR -33 -#define CV_UNREC_QRHSFUNC_ERR -34 - -#define CV_NO_SENS -40 -#define CV_SRHSFUNC_FAIL -41 -#define CV_FIRST_SRHSFUNC_ERR -42 -#define CV_REPTD_SRHSFUNC_ERR -43 -#define CV_UNREC_SRHSFUNC_ERR -44 - -#define CV_BAD_IS -45 - -#define CV_NO_QUADSENS -50 -#define CV_QSRHSFUNC_FAIL -51 -#define CV_FIRST_QSRHSFUNC_ERR -52 -#define CV_REPTD_QSRHSFUNC_ERR -53 -#define CV_UNREC_QSRHSFUNC_ERR -54 - - -#define CV_UNRECOGNIZED_ERR -99 +#define CV_SUCCESS 0 +#define CV_TSTOP_RETURN 1 +#define CV_ROOT_RETURN 2 + +#define CV_WARNING 99 + +#define CV_TOO_MUCH_WORK -1 +#define CV_TOO_MUCH_ACC -2 +#define CV_ERR_FAILURE -3 +#define CV_CONV_FAILURE -4 + +#define CV_LINIT_FAIL -5 +#define CV_LSETUP_FAIL -6 +#define CV_LSOLVE_FAIL -7 +#define CV_RHSFUNC_FAIL -8 +#define CV_FIRST_RHSFUNC_ERR -9 +#define CV_REPTD_RHSFUNC_ERR -10 +#define CV_UNREC_RHSFUNC_ERR -11 +#define CV_RTFUNC_FAIL -12 +#define CV_NLS_INIT_FAIL -13 +#define CV_NLS_SETUP_FAIL -14 +#define CV_CONSTR_FAIL -15 +#define CV_NLS_FAIL -16 + +#define CV_MEM_FAIL -20 +#define CV_MEM_NULL -21 +#define CV_ILL_INPUT -22 +#define CV_NO_MALLOC -23 +#define CV_BAD_K -24 +#define CV_BAD_T -25 +#define CV_BAD_DKY -26 +#define CV_TOO_CLOSE -27 +#define CV_VECTOROP_ERR -28 + +#define CV_NO_QUAD -30 +#define CV_QRHSFUNC_FAIL -31 +#define CV_FIRST_QRHSFUNC_ERR -32 +#define CV_REPTD_QRHSFUNC_ERR -33 +#define CV_UNREC_QRHSFUNC_ERR -34 + +#define CV_NO_SENS -40 +#define CV_SRHSFUNC_FAIL -41 +#define CV_FIRST_SRHSFUNC_ERR -42 +#define CV_REPTD_SRHSFUNC_ERR -43 +#define CV_UNREC_SRHSFUNC_ERR -44 + +#define CV_BAD_IS -45 + +#define CV_NO_QUADSENS -50 +#define CV_QSRHSFUNC_FAIL -51 +#define CV_FIRST_QSRHSFUNC_ERR -52 +#define CV_REPTD_QSRHSFUNC_ERR -53 +#define CV_UNREC_QSRHSFUNC_ERR -54 + +#define CV_CONTEXT_ERR -55 + +#define CV_PROJ_MEM_NULL -56 +#define CV_PROJFUNC_FAIL -57 +#define CV_REPTD_PROJFUNC_ERR -58 + +#define CV_BAD_TINTERP -59 + +#define CV_UNRECOGNIZED_ERR -99 /* adjoint return values */ -#define CV_NO_ADJ -101 -#define CV_NO_FWD -102 -#define CV_NO_BCK -103 -#define CV_BAD_TB0 -104 -#define CV_REIFWD_FAIL -105 -#define CV_FWD_FAIL -106 -#define CV_GETY_BADT -107 +#define CV_NO_ADJ -101 +#define CV_NO_FWD -102 +#define CV_NO_BCK -103 +#define CV_BAD_TB0 -104 +#define CV_REIFWD_FAIL -105 +#define CV_FWD_FAIL -106 +#define CV_GETY_BADT -107 /* ------------------------------ * User-Supplied Function Types * ------------------------------ */ -typedef int (*CVRhsFn)(realtype t, N_Vector y, - N_Vector ydot, void *user_data); +typedef int (*CVRhsFn)(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data); -typedef int (*CVRootFn)(realtype t, N_Vector y, realtype *gout, - void *user_data); +typedef int (*CVRootFn)(sunrealtype t, N_Vector y, sunrealtype* gout, + void* user_data); -typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void *user_data); +typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void* user_data); -typedef void (*CVErrHandlerFn)(int error_code, - const char *module, const char *function, - char *msg, void *user_data); +typedef int (*CVMonitorFn)(void* cvode_mem, void* user_data); -typedef int (*CVQuadRhsFn)(realtype t, N_Vector y, - N_Vector yQdot, void *user_data); +typedef int (*CVQuadRhsFn)(sunrealtype t, N_Vector y, N_Vector yQdot, + void* user_data); -typedef int (*CVSensRhsFn)(int Ns, realtype t, - N_Vector y, N_Vector ydot, - N_Vector *yS, N_Vector *ySdot, - void *user_data, +typedef int (*CVSensRhsFn)(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + N_Vector* yS, N_Vector* ySdot, void* user_data, N_Vector tmp1, N_Vector tmp2); -typedef int (*CVSensRhs1Fn)(int Ns, realtype t, - N_Vector y, N_Vector ydot, +typedef int (*CVSensRhs1Fn)(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, int iS, N_Vector yS, N_Vector ySdot, - void *user_data, - N_Vector tmp1, N_Vector tmp2); - -typedef int (*CVQuadSensRhsFn)(int Ns, realtype t, - N_Vector y, N_Vector *yS, - N_Vector yQdot, N_Vector *yQSdot, - void *user_data, - N_Vector tmp, N_Vector tmpQ); + void* user_data, N_Vector tmp1, N_Vector tmp2); -typedef int (*CVRhsFnB)(realtype t, N_Vector y, N_Vector yB, N_Vector yBdot, - void *user_dataB); +typedef int (*CVQuadSensRhsFn)(int Ns, sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yQdot, N_Vector* yQSdot, + void* user_data, N_Vector tmp, N_Vector tmpQ); -typedef int (*CVRhsFnBS)(realtype t, N_Vector y, N_Vector *yS, - N_Vector yB, N_Vector yBdot, void *user_dataB); +typedef int (*CVRhsFnB)(sunrealtype t, N_Vector y, N_Vector yB, N_Vector yBdot, + void* user_dataB); +typedef int (*CVRhsFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector yBdot, void* user_dataB); -typedef int (*CVQuadRhsFnB)(realtype t, N_Vector y, N_Vector yB, N_Vector qBdot, - void *user_dataB); - -typedef int (*CVQuadRhsFnBS)(realtype t, N_Vector y, N_Vector *yS, - N_Vector yB, N_Vector qBdot, void *user_dataB); +typedef int (*CVQuadRhsFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector qBdot, void* user_dataB); +typedef int (*CVQuadRhsFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector qBdot, void* user_dataB); /* --------------------------------------- * Exported Functions -- Forward Problems * --------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT void *CVodeCreate(int lmm); +SUNDIALS_EXPORT void* CVodeCreate(int lmm, SUNContext sunctx); -SUNDIALS_EXPORT int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, +SUNDIALS_EXPORT int CVodeInit(void* cvode_mem, CVRhsFn f, sunrealtype t0, N_Vector y0); -SUNDIALS_EXPORT int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0); +SUNDIALS_EXPORT int CVodeReInit(void* cvode_mem, sunrealtype t0, N_Vector y0); /* Tolerance input functions */ -SUNDIALS_EXPORT int CVodeSStolerances(void *cvode_mem, realtype reltol, - realtype abstol); -SUNDIALS_EXPORT int CVodeSVtolerances(void *cvode_mem, realtype reltol, +SUNDIALS_EXPORT int CVodeSStolerances(void* cvode_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, N_Vector abstol); -SUNDIALS_EXPORT int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun); +SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun); /* Optional input functions */ -SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, - void *eh_data); -SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp); -SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data); -SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); -SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); -SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); -SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); -SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin); -SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); -SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); -SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); -SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef); -SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor); -SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); -SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); -SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp); -SUNDIALS_EXPORT int CVodeSetConstraints(void *cvode_mem, N_Vector constraints); -SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void *cvode_mem, + +SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, + sunrealtype dgmax_lsetup); +SUNDIALS_EXPORT int CVodeSetInitStep(void* cvode_mem, sunrealtype hin); +SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp); +SUNDIALS_EXPORT int CVodeSetMaxConvFails(void* cvode_mem, int maxncf); +SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef); +SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil); +SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void* cvode_mem, int maxcor); +SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps); +SUNDIALS_EXPORT int CVodeSetMaxOrd(void* cvode_mem, int maxord); +SUNDIALS_EXPORT int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax); +SUNDIALS_EXPORT int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin); +SUNDIALS_EXPORT int CVodeSetMonitorFn(void* cvode_mem, CVMonitorFn fn); +SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void* cvode_mem, long int nst); +SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef); +SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void* cvode_mem, SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void *cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype stldet); +SUNDIALS_EXPORT int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop); +SUNDIALS_EXPORT int CVodeSetInterpolateStopTime(void* cvode_mem, + sunbooleantype interp); +SUNDIALS_EXPORT int CVodeClearStopTime(void* cvode_mem); +SUNDIALS_EXPORT int CVodeSetUserData(void* cvode_mem, void* user_data); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int CVodeSetEtaFixedStepBounds(void* cvode_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs); +SUNDIALS_EXPORT +int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es); +SUNDIALS_EXPORT +int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst); +SUNDIALS_EXPORT +int CVodeSetEtaMax(void* cvode_mem, sunrealtype eta_max_gs); +SUNDIALS_EXPORT +int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int CVodeSetEtaMinErrFail(void* cvode_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef); +SUNDIALS_EXPORT +int CVodeSetNumFailsEtaMaxErrFail(void* cvode_mem, int small_nef); +SUNDIALS_EXPORT +int CVodeSetEtaConvFail(void* cvode_mem, sunrealtype eta_cf); /* Rootfinding initialization function */ -SUNDIALS_EXPORT int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g); +SUNDIALS_EXPORT int CVodeRootInit(void* cvode_mem, int nrtfn, CVRootFn g); /* Rootfinding optional input functions */ -SUNDIALS_EXPORT int CVodeSetRootDirection(void *cvode_mem, int *rootdir); -SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void *cvode_mem); +SUNDIALS_EXPORT int CVodeSetRootDirection(void* cvode_mem, int* rootdir); +SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void* cvode_mem); /* Solver function */ -SUNDIALS_EXPORT int CVode(void *cvode_mem, realtype tout, N_Vector yout, - realtype *tret, int itask); +SUNDIALS_EXPORT int CVode(void* cvode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask); /* Utility functions to update/compute y based on ycor */ -SUNDIALS_EXPORT int CVodeComputeState(void *cvode_mem, N_Vector ycor, - N_Vector y); -SUNDIALS_EXPORT int CVodeComputeStateSens(void *cvode_mem, N_Vector *yScor, - N_Vector *yS); -SUNDIALS_EXPORT int CVodeComputeStateSens1(void *cvode_mem, int idx, +SUNDIALS_EXPORT int CVodeComputeState(void* cvode_mem, N_Vector ycor, N_Vector y); +SUNDIALS_EXPORT int CVodeComputeStateSens(void* cvode_mem, N_Vector* yScor, + N_Vector* yS); +SUNDIALS_EXPORT int CVodeComputeStateSens1(void* cvode_mem, int idx, N_Vector yScor1, N_Vector yS1); /* Dense output function */ -SUNDIALS_EXPORT int CVodeGetDky(void *cvode_mem, realtype t, int k, +SUNDIALS_EXPORT int CVodeGetDky(void* cvode_mem, sunrealtype t, int k, N_Vector dky); /* Optional output functions */ -SUNDIALS_EXPORT int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, - long int *leniw); -SUNDIALS_EXPORT int CVodeGetNumSteps(void *cvode_mem, long int *nsteps); -SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals); -SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void *cvode_mem, - long int *nlinsetups); -SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void *cvode_mem, - long int *netfails); -SUNDIALS_EXPORT int CVodeGetLastOrder(void *cvode_mem, int *qlast); -SUNDIALS_EXPORT int CVodeGetCurrentOrder(void *cvode_mem, int *qcur); -SUNDIALS_EXPORT int CVodeGetCurrentGamma(void *cvode_mem, realtype *gamma); -SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void *cvode_mem, - long int *nslred); -SUNDIALS_EXPORT int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused); -SUNDIALS_EXPORT int CVodeGetLastStep(void *cvode_mem, realtype *hlast); -SUNDIALS_EXPORT int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur); -SUNDIALS_EXPORT int CVodeGetCurrentState(void *cvode_mem, N_Vector *y); -SUNDIALS_EXPORT int CVodeGetCurrentStateSens(void *cvode_mem, N_Vector **yS); -SUNDIALS_EXPORT int CVodeGetCurrentSensSolveIndex(void *cvode_mem, int *index); -SUNDIALS_EXPORT int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur); -SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfac); -SUNDIALS_EXPORT int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight); -SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele); -SUNDIALS_EXPORT int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals); -SUNDIALS_EXPORT int CVodeGetRootInfo(void *cvode_mem, int *rootsfound); -SUNDIALS_EXPORT int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, - long int *nfevals, - long int *nlinsetups, - long int *netfails, - int *qlast, int *qcur, - realtype *hinused, realtype *hlast, - realtype *hcur, realtype *tcur); -SUNDIALS_EXPORT int CVodeGetNonlinearSystemData(void *cvode_mem, realtype *tcur, - N_Vector *ypred, N_Vector *yn, - N_Vector *fn, realtype *gamma, - realtype *rl1, N_Vector *zn1, - void **user_data); -SUNDIALS_EXPORT int CVodeGetNonlinearSystemDataSens(void *cvode_mem, - realtype *tcur, - N_Vector **ySpred, - N_Vector **ySn, - realtype *gamma, - realtype *rl1, - N_Vector **zn1, - void **user_data); -SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void *cvode_mem, - long int *nniters); -SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, - long int *nncfails); -SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters, - long int *nncfails); -SUNDIALS_EXPORT char *CVodeGetReturnFlagName(long int flag); +SUNDIALS_EXPORT int CVodeGetWorkSpace(void* cvode_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int CVodeGetNumSteps(void* cvode_mem, long int* nsteps); +SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void* cvode_mem, long int* nfevals); +SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void* cvode_mem, + long int* nlinsetups); +SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void* cvode_mem, long int* netfails); +SUNDIALS_EXPORT int CVodeGetLastOrder(void* cvode_mem, int* qlast); +SUNDIALS_EXPORT int CVodeGetCurrentOrder(void* cvode_mem, int* qcur); +SUNDIALS_EXPORT int CVodeGetCurrentGamma(void* cvode_mem, sunrealtype* gamma); +SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void* cvode_mem, + long int* nslred); +SUNDIALS_EXPORT int CVodeGetActualInitStep(void* cvode_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int CVodeGetLastStep(void* cvode_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int CVodeGetCurrentStep(void* cvode_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int CVodeGetCurrentState(void* cvode_mem, N_Vector* y); +SUNDIALS_EXPORT int CVodeGetCurrentStateSens(void* cvode_mem, N_Vector** yS); +SUNDIALS_EXPORT int CVodeGetCurrentSensSolveIndex(void* cvode_mem, int* index); +SUNDIALS_EXPORT int CVodeGetCurrentTime(void* cvode_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void* cvode_mem, sunrealtype* tolsfac); +SUNDIALS_EXPORT int CVodeGetErrWeights(void* cvode_mem, N_Vector eweight); +SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void* cvode_mem, N_Vector ele); +SUNDIALS_EXPORT int CVodeGetNumGEvals(void* cvode_mem, long int* ngevals); +SUNDIALS_EXPORT int CVodeGetRootInfo(void* cvode_mem, int* rootsfound); +SUNDIALS_EXPORT int CVodeGetIntegratorStats( + void* cvode_mem, long int* nsteps, long int* nfevals, long int* nlinsetups, + long int* netfails, int* qlast, int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, sunrealtype* tcur); +SUNDIALS_EXPORT int CVodeGetNonlinearSystemData(void* cvode_mem, + sunrealtype* tcur, + N_Vector* ypred, N_Vector* yn, + N_Vector* fn, sunrealtype* gamma, + sunrealtype* rl1, N_Vector* zn1, + void** user_data); +SUNDIALS_EXPORT int CVodeGetNonlinearSystemDataSens( + void* cvode_mem, sunrealtype* tcur, N_Vector** ySpred, N_Vector** ySn, + sunrealtype* gamma, sunrealtype* rl1, N_Vector** zn1, void** user_data); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void* cvode_mem, + long int* nniters); +SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void* cvode_mem, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void* cvode_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int CVodeGetNumStepSolveFails(void* cvode_mem, + long int* nncfails); +SUNDIALS_EXPORT int CVodeGetUserData(void* cvode_mem, void** user_data); +SUNDIALS_EXPORT int CVodePrintAllStats(void* cvode_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* CVodeGetReturnFlagName(long int flag); /* Free function */ -SUNDIALS_EXPORT void CVodeFree(void **cvode_mem); +SUNDIALS_EXPORT void CVodeFree(void** cvode_mem); /* CVLS interface function that depends on CVRhsFn */ -SUNDIALS_EXPORT int CVodeSetJacTimesRhsFn(void *cvode_mem, - CVRhsFn jtimesRhsFn); - +SUNDIALS_EXPORT int CVodeSetJacTimesRhsFn(void* cvode_mem, CVRhsFn jtimesRhsFn); /* --------------------------------- * Exported Functions -- Quadrature * --------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT int CVodeQuadInit(void *cvode_mem, CVQuadRhsFn fQ, - N_Vector yQ0); -SUNDIALS_EXPORT int CVodeQuadReInit(void *cvode_mem, N_Vector yQ0); +SUNDIALS_EXPORT int CVodeQuadInit(void* cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0); +SUNDIALS_EXPORT int CVodeQuadReInit(void* cvode_mem, N_Vector yQ0); /* Tolerance input functions */ -SUNDIALS_EXPORT int CVodeQuadSStolerances(void *cvode_mem, realtype reltolQ, - realtype abstolQ); -SUNDIALS_EXPORT int CVodeQuadSVtolerances(void *cvode_mem, realtype reltolQ, +SUNDIALS_EXPORT int CVodeQuadSStolerances(void* cvode_mem, sunrealtype reltolQ, + sunrealtype abstolQ); +SUNDIALS_EXPORT int CVodeQuadSVtolerances(void* cvode_mem, sunrealtype reltolQ, N_Vector abstolQ); /* Optional input specification functions */ -SUNDIALS_EXPORT int CVodeSetQuadErrCon(void *cvode_mem, booleantype errconQ); +SUNDIALS_EXPORT int CVodeSetQuadErrCon(void* cvode_mem, sunbooleantype errconQ); /* Extraction and Dense Output Functions for Forward Problems */ -SUNDIALS_EXPORT int CVodeGetQuad(void *cvode_mem, realtype *tret, +SUNDIALS_EXPORT int CVodeGetQuad(void* cvode_mem, sunrealtype* tret, N_Vector yQout); -SUNDIALS_EXPORT int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, +SUNDIALS_EXPORT int CVodeGetQuadDky(void* cvode_mem, sunrealtype t, int k, N_Vector dky); /* Optional output specification functions */ -SUNDIALS_EXPORT int CVodeGetQuadNumRhsEvals(void *cvode_mem, - long int *nfQevals); -SUNDIALS_EXPORT int CVodeGetQuadNumErrTestFails(void *cvode_mem, - long int *nQetfails); -SUNDIALS_EXPORT int CVodeGetQuadErrWeights(void *cvode_mem, N_Vector eQweight); -SUNDIALS_EXPORT int CVodeGetQuadStats(void *cvode_mem, long int *nfQevals, - long int *nQetfails); +SUNDIALS_EXPORT int CVodeGetQuadNumRhsEvals(void* cvode_mem, long int* nfQevals); +SUNDIALS_EXPORT int CVodeGetQuadNumErrTestFails(void* cvode_mem, + long int* nQetfails); +SUNDIALS_EXPORT int CVodeGetQuadErrWeights(void* cvode_mem, N_Vector eQweight); +SUNDIALS_EXPORT int CVodeGetQuadStats(void* cvode_mem, long int* nfQevals, + long int* nQetfails); /* Free function */ -SUNDIALS_EXPORT void CVodeQuadFree(void *cvode_mem); - +SUNDIALS_EXPORT void CVodeQuadFree(void* cvode_mem); /* ------------------------------------ * Exported Functions -- Sensitivities * ------------------------------------ */ /* Initialization functions */ -SUNDIALS_EXPORT int CVodeSensInit(void *cvode_mem, int Ns, int ism, - CVSensRhsFn fS, N_Vector *yS0); -SUNDIALS_EXPORT int CVodeSensInit1(void *cvode_mem, int Ns, int ism, - CVSensRhs1Fn fS1, N_Vector *yS0); -SUNDIALS_EXPORT int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0); +SUNDIALS_EXPORT int CVodeSensInit(void* cvode_mem, int Ns, int ism, + CVSensRhsFn fS, N_Vector* yS0); +SUNDIALS_EXPORT int CVodeSensInit1(void* cvode_mem, int Ns, int ism, + CVSensRhs1Fn fS1, N_Vector* yS0); +SUNDIALS_EXPORT int CVodeSensReInit(void* cvode_mem, int ism, N_Vector* yS0); /* Tolerance input functions */ -SUNDIALS_EXPORT int CVodeSensSStolerances(void *cvode_mem, realtype reltolS, - realtype *abstolS); -SUNDIALS_EXPORT int CVodeSensSVtolerances(void *cvode_mem, realtype reltolS, - N_Vector *abstolS); -SUNDIALS_EXPORT int CVodeSensEEtolerances(void *cvode_mem); +SUNDIALS_EXPORT int CVodeSensSStolerances(void* cvode_mem, sunrealtype reltolS, + sunrealtype* abstolS); +SUNDIALS_EXPORT int CVodeSensSVtolerances(void* cvode_mem, sunrealtype reltolS, + N_Vector* abstolS); +SUNDIALS_EXPORT int CVodeSensEEtolerances(void* cvode_mem); /* Optional input specification functions */ -SUNDIALS_EXPORT int CVodeSetSensDQMethod(void *cvode_mem, int DQtype, - realtype DQrhomax); -SUNDIALS_EXPORT int CVodeSetSensErrCon(void *cvode_mem, booleantype errconS); -SUNDIALS_EXPORT int CVodeSetSensMaxNonlinIters(void *cvode_mem, int maxcorS); -SUNDIALS_EXPORT int CVodeSetSensParams(void *cvode_mem, realtype *p, - realtype *pbar, int *plist); +SUNDIALS_EXPORT int CVodeSetSensDQMethod(void* cvode_mem, int DQtype, + sunrealtype DQrhomax); +SUNDIALS_EXPORT int CVodeSetSensErrCon(void* cvode_mem, sunbooleantype errconS); +SUNDIALS_EXPORT int CVodeSetSensMaxNonlinIters(void* cvode_mem, int maxcorS); +SUNDIALS_EXPORT int CVodeSetSensParams(void* cvode_mem, sunrealtype* p, + sunrealtype* pbar, int* plist); /* Integrator nonlinear solver specification functions */ -SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensSim(void *cvode_mem, +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensSim(void* cvode_mem, SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg(void *cvode_mem, +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg(void* cvode_mem, SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg1(void *cvode_mem, +SUNDIALS_EXPORT int CVodeSetNonlinearSolverSensStg1(void* cvode_mem, SUNNonlinearSolver NLS); /* Enable/disable sensitivities */ -SUNDIALS_EXPORT int CVodeSensToggleOff(void *cvode_mem); +SUNDIALS_EXPORT int CVodeSensToggleOff(void* cvode_mem); /* Extraction and dense output functions */ -SUNDIALS_EXPORT int CVodeGetSens(void *cvode_mem, realtype *tret, - N_Vector *ySout); -SUNDIALS_EXPORT int CVodeGetSens1(void *cvode_mem, realtype *tret, int is, +SUNDIALS_EXPORT int CVodeGetSens(void* cvode_mem, sunrealtype* tret, + N_Vector* ySout); +SUNDIALS_EXPORT int CVodeGetSens1(void* cvode_mem, sunrealtype* tret, int is, N_Vector ySout); -SUNDIALS_EXPORT int CVodeGetSensDky(void *cvode_mem, realtype t, int k, - N_Vector *dkyA); -SUNDIALS_EXPORT int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, - N_Vector dky); +SUNDIALS_EXPORT int CVodeGetSensDky(void* cvode_mem, sunrealtype t, int k, + N_Vector* dkyA); +SUNDIALS_EXPORT int CVodeGetSensDky1(void* cvode_mem, sunrealtype t, int k, + int is, N_Vector dky); /* Optional output specification functions */ -SUNDIALS_EXPORT int CVodeGetSensNumRhsEvals(void *cvode_mem, - long int *nfSevals); -SUNDIALS_EXPORT int CVodeGetNumRhsEvalsSens(void *cvode_mem, - long int *nfevalsS); -SUNDIALS_EXPORT int CVodeGetSensNumErrTestFails(void *cvode_mem, - long int *nSetfails); -SUNDIALS_EXPORT int CVodeGetSensNumLinSolvSetups(void *cvode_mem, - long int *nlinsetupsS); -SUNDIALS_EXPORT int CVodeGetSensErrWeights(void *cvode_mem, N_Vector *eSweight); -SUNDIALS_EXPORT int CVodeGetSensStats(void *cvode_mem, long int *nfSevals, - long int *nfevalsS, long int *nSetfails, - long int *nlinsetupsS); -SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvIters(void *cvode_mem, - long int *nSniters); -SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvConvFails(void *cvode_mem, - long int *nSncfails); -SUNDIALS_EXPORT int CVodeGetSensNonlinSolvStats(void *cvode_mem, - long int *nSniters, - long int *nSncfails); -SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvIters(void *cvode_mem, - long int *nSTGR1niters); -SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvConvFails(void *cvode_mem, - long int *nSTGR1ncfails); -SUNDIALS_EXPORT int CVodeGetStgrSensNonlinSolvStats(void *cvode_mem, - long int *nSTGR1niters, - long int *nSTGR1ncfails); +SUNDIALS_EXPORT int CVodeGetSensNumRhsEvals(void* cvode_mem, long int* nfSevals); +SUNDIALS_EXPORT int CVodeGetNumRhsEvalsSens(void* cvode_mem, long int* nfevalsS); +SUNDIALS_EXPORT int CVodeGetSensNumErrTestFails(void* cvode_mem, + long int* nSetfails); +SUNDIALS_EXPORT int CVodeGetSensNumLinSolvSetups(void* cvode_mem, + long int* nlinsetupsS); +SUNDIALS_EXPORT int CVodeGetSensErrWeights(void* cvode_mem, N_Vector* eSweight); +SUNDIALS_EXPORT int CVodeGetSensStats(void* cvode_mem, long int* nfSevals, + long int* nfevalsS, long int* nSetfails, + long int* nlinsetupsS); +SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvIters(void* cvode_mem, + long int* nSniters); +SUNDIALS_EXPORT int CVodeGetSensNumNonlinSolvConvFails(void* cvode_mem, + long int* nSnfails); +SUNDIALS_EXPORT int CVodeGetSensNonlinSolvStats(void* cvode_mem, + long int* nSniters, + long int* nSnfails); +SUNDIALS_EXPORT int CVodeGetNumStepSensSolveFails(void* cvode_mem, + long int* nSncfails); +SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvIters(void* cvode_mem, + long int* nSTGR1niters); +SUNDIALS_EXPORT int CVodeGetStgrSensNumNonlinSolvConvFails(void* cvode_mem, + long int* nSTGR1nfails); +SUNDIALS_EXPORT int CVodeGetStgrSensNonlinSolvStats(void* cvode_mem, + long int* nSTGR1niters, + long int* nSTGR1nfails); +SUNDIALS_EXPORT int CVodeGetNumStepStgrSensSolveFails(void* cvode_mem, + long int* nSTGR1ncfails); /* Free function */ -SUNDIALS_EXPORT void CVodeSensFree(void *cvode_mem); - +SUNDIALS_EXPORT void CVodeSensFree(void* cvode_mem); /* ------------------------------------------------------- * Exported Functions -- Sensitivity dependent quadrature * ------------------------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT int CVodeQuadSensInit(void *cvode_mem, CVQuadSensRhsFn fQS, - N_Vector *yQS0); -SUNDIALS_EXPORT int CVodeQuadSensReInit(void *cvode_mem, N_Vector *yQS0); +SUNDIALS_EXPORT int CVodeQuadSensInit(void* cvode_mem, CVQuadSensRhsFn fQS, + N_Vector* yQS0); +SUNDIALS_EXPORT int CVodeQuadSensReInit(void* cvode_mem, N_Vector* yQS0); /* Tolerance input functions */ -SUNDIALS_EXPORT int CVodeQuadSensSStolerances(void *cvode_mem, - realtype reltolQS, - realtype *abstolQS); -SUNDIALS_EXPORT int CVodeQuadSensSVtolerances(void *cvode_mem, - realtype reltolQS, - N_Vector *abstolQS); -SUNDIALS_EXPORT int CVodeQuadSensEEtolerances(void *cvode_mem); +SUNDIALS_EXPORT int CVodeQuadSensSStolerances(void* cvode_mem, + sunrealtype reltolQS, + sunrealtype* abstolQS); +SUNDIALS_EXPORT int CVodeQuadSensSVtolerances(void* cvode_mem, + sunrealtype reltolQS, + N_Vector* abstolQS); +SUNDIALS_EXPORT int CVodeQuadSensEEtolerances(void* cvode_mem); /* Optional input specification functions */ -SUNDIALS_EXPORT int CVodeSetQuadSensErrCon(void *cvode_mem, - booleantype errconQS); +SUNDIALS_EXPORT int CVodeSetQuadSensErrCon(void* cvode_mem, + sunbooleantype errconQS); /* Extraction and dense output functions */ -SUNDIALS_EXPORT int CVodeGetQuadSens(void *cvode_mem, realtype *tret, - N_Vector *yQSout); -SUNDIALS_EXPORT int CVodeGetQuadSens1(void *cvode_mem, realtype *tret, int is, - N_Vector yQSout); - -SUNDIALS_EXPORT int CVodeGetQuadSensDky(void *cvode_mem, realtype t, int k, - N_Vector *dkyQS_all); -SUNDIALS_EXPORT int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, +SUNDIALS_EXPORT int CVodeGetQuadSens(void* cvode_mem, sunrealtype* tret, + N_Vector* yQSout); +SUNDIALS_EXPORT int CVodeGetQuadSens1(void* cvode_mem, sunrealtype* tret, + int is, N_Vector yQSout); + +SUNDIALS_EXPORT int CVodeGetQuadSensDky(void* cvode_mem, sunrealtype t, int k, + N_Vector* dkyQS_all); +SUNDIALS_EXPORT int CVodeGetQuadSensDky1(void* cvode_mem, sunrealtype t, int k, int is, N_Vector dkyQS); /* Optional output specification functions */ -SUNDIALS_EXPORT int CVodeGetQuadSensNumRhsEvals(void *cvode_mem, - long int *nfQSevals); -SUNDIALS_EXPORT int CVodeGetQuadSensNumErrTestFails(void *cvode_mem, - long int *nQSetfails); -SUNDIALS_EXPORT int CVodeGetQuadSensErrWeights(void *cvode_mem, - N_Vector *eQSweight); -SUNDIALS_EXPORT int CVodeGetQuadSensStats(void *cvode_mem, - long int *nfQSevals, - long int *nQSetfails); +SUNDIALS_EXPORT int CVodeGetQuadSensNumRhsEvals(void* cvode_mem, + long int* nfQSevals); +SUNDIALS_EXPORT int CVodeGetQuadSensNumErrTestFails(void* cvode_mem, + long int* nQSetfails); +SUNDIALS_EXPORT int CVodeGetQuadSensErrWeights(void* cvode_mem, + N_Vector* eQSweight); +SUNDIALS_EXPORT int CVodeGetQuadSensStats(void* cvode_mem, long int* nfQSevals, + long int* nQSetfails); /* Free function */ -SUNDIALS_EXPORT void CVodeQuadSensFree(void *cvode_mem); - +SUNDIALS_EXPORT void CVodeQuadSensFree(void* cvode_mem); /* ---------------------------------------- * Exported Functions -- Backward Problems @@ -468,107 +482,105 @@ SUNDIALS_EXPORT void CVodeQuadSensFree(void *cvode_mem); /* Initialization functions */ -SUNDIALS_EXPORT int CVodeAdjInit(void *cvode_mem, long int steps, int interp); +SUNDIALS_EXPORT int CVodeAdjInit(void* cvode_mem, long int steps, int interp); -SUNDIALS_EXPORT int CVodeAdjReInit(void *cvode_mem); +SUNDIALS_EXPORT int CVodeAdjReInit(void* cvode_mem); -SUNDIALS_EXPORT void CVodeAdjFree(void *cvode_mem); +SUNDIALS_EXPORT void CVodeAdjFree(void* cvode_mem); /* Backward Problem Setup Functions */ -SUNDIALS_EXPORT int CVodeCreateB(void *cvode_mem, int lmmB, int *which); - -SUNDIALS_EXPORT int CVodeInitB(void *cvode_mem, int which, - CVRhsFnB fB, - realtype tB0, N_Vector yB0); -SUNDIALS_EXPORT int CVodeInitBS(void *cvode_mem, int which, - CVRhsFnBS fBs, - realtype tB0, N_Vector yB0); -SUNDIALS_EXPORT int CVodeReInitB(void *cvode_mem, int which, - realtype tB0, N_Vector yB0); - -SUNDIALS_EXPORT int CVodeSStolerancesB(void *cvode_mem, int which, - realtype reltolB, realtype abstolB); -SUNDIALS_EXPORT int CVodeSVtolerancesB(void *cvode_mem, int which, - realtype reltolB, N_Vector abstolB); - -SUNDIALS_EXPORT int CVodeQuadInitB(void *cvode_mem, int which, - CVQuadRhsFnB fQB, N_Vector yQB0); -SUNDIALS_EXPORT int CVodeQuadInitBS(void *cvode_mem, int which, - CVQuadRhsFnBS fQBs, N_Vector yQB0); -SUNDIALS_EXPORT int CVodeQuadReInitB(void *cvode_mem, int which, N_Vector yQB0); - -SUNDIALS_EXPORT int CVodeQuadSStolerancesB(void *cvode_mem, int which, - realtype reltolQB, - realtype abstolQB); -SUNDIALS_EXPORT int CVodeQuadSVtolerancesB(void *cvode_mem, int which, - realtype reltolQB, +SUNDIALS_EXPORT int CVodeCreateB(void* cvode_mem, int lmmB, int* which); + +SUNDIALS_EXPORT int CVodeInitB(void* cvode_mem, int which, CVRhsFnB fB, + sunrealtype tB0, N_Vector yB0); +SUNDIALS_EXPORT int CVodeInitBS(void* cvode_mem, int which, CVRhsFnBS fBs, + sunrealtype tB0, N_Vector yB0); +SUNDIALS_EXPORT int CVodeReInitB(void* cvode_mem, int which, sunrealtype tB0, + N_Vector yB0); + +SUNDIALS_EXPORT int CVodeSStolerancesB(void* cvode_mem, int which, + sunrealtype reltolB, sunrealtype abstolB); +SUNDIALS_EXPORT int CVodeSVtolerancesB(void* cvode_mem, int which, + sunrealtype reltolB, N_Vector abstolB); + +SUNDIALS_EXPORT int CVodeQuadInitB(void* cvode_mem, int which, CVQuadRhsFnB fQB, + N_Vector yQB0); +SUNDIALS_EXPORT int CVodeQuadInitBS(void* cvode_mem, int which, + CVQuadRhsFnBS fQBs, N_Vector yQB0); +SUNDIALS_EXPORT int CVodeQuadReInitB(void* cvode_mem, int which, N_Vector yQB0); + +SUNDIALS_EXPORT int CVodeQuadSStolerancesB(void* cvode_mem, int which, + sunrealtype reltolQB, + sunrealtype abstolQB); +SUNDIALS_EXPORT int CVodeQuadSVtolerancesB(void* cvode_mem, int which, + sunrealtype reltolQB, N_Vector abstolQB); /* Solver Function For Forward Problems */ -SUNDIALS_EXPORT int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, - realtype *tret, int itask, int *ncheckPtr); - +SUNDIALS_EXPORT int CVodeF(void* cvode_mem, sunrealtype tout, N_Vector yout, + sunrealtype* tret, int itask, int* ncheckPtr); /* Solver Function For Backward Problems */ -SUNDIALS_EXPORT int CVodeB(void *cvode_mem, realtype tBout, int itaskB); +SUNDIALS_EXPORT int CVodeB(void* cvode_mem, sunrealtype tBout, int itaskB); /* Optional Input Functions For Adjoint Problems */ -SUNDIALS_EXPORT int CVodeSetAdjNoSensi(void *cvode_mem); +SUNDIALS_EXPORT int CVodeSetAdjNoSensi(void* cvode_mem); -SUNDIALS_EXPORT int CVodeSetUserDataB(void *cvode_mem, int which, - void *user_dataB); -SUNDIALS_EXPORT int CVodeSetMaxOrdB(void *cvode_mem, int which, int maxordB); -SUNDIALS_EXPORT int CVodeSetMaxNumStepsB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetUserDataB(void* cvode_mem, int which, + void* user_dataB); +SUNDIALS_EXPORT int CVodeSetMaxOrdB(void* cvode_mem, int which, int maxordB); +SUNDIALS_EXPORT int CVodeSetMaxNumStepsB(void* cvode_mem, int which, long int mxstepsB); -SUNDIALS_EXPORT int CVodeSetStabLimDetB(void *cvode_mem, int which, - booleantype stldetB); -SUNDIALS_EXPORT int CVodeSetInitStepB(void *cvode_mem, int which, - realtype hinB); -SUNDIALS_EXPORT int CVodeSetMinStepB(void *cvode_mem, int which, - realtype hminB); -SUNDIALS_EXPORT int CVodeSetMaxStepB(void *cvode_mem, int which, - realtype hmaxB); -SUNDIALS_EXPORT int CVodeSetConstraintsB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetStabLimDetB(void* cvode_mem, int which, + sunbooleantype stldetB); +SUNDIALS_EXPORT int CVodeSetInitStepB(void* cvode_mem, int which, + sunrealtype hinB); +SUNDIALS_EXPORT int CVodeSetMinStepB(void* cvode_mem, int which, + sunrealtype hminB); +SUNDIALS_EXPORT int CVodeSetMaxStepB(void* cvode_mem, int which, + sunrealtype hmaxB); +SUNDIALS_EXPORT int CVodeSetConstraintsB(void* cvode_mem, int which, N_Vector constraintsB); -SUNDIALS_EXPORT int CVodeSetQuadErrConB(void *cvode_mem, int which, - booleantype errconQB); +SUNDIALS_EXPORT int CVodeSetQuadErrConB(void* cvode_mem, int which, + sunbooleantype errconQB); -SUNDIALS_EXPORT int CVodeSetNonlinearSolverB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetNonlinearSolverB(void* cvode_mem, int which, SUNNonlinearSolver NLS); /* Extraction And Dense Output Functions For Backward Problems */ -SUNDIALS_EXPORT int CVodeGetB(void *cvode_mem, int which, - realtype *tBret, N_Vector yB); -SUNDIALS_EXPORT int CVodeGetQuadB(void *cvode_mem, int which, - realtype *tBret, N_Vector qB); +SUNDIALS_EXPORT int CVodeGetB(void* cvode_mem, int which, sunrealtype* tBret, + N_Vector yB); +SUNDIALS_EXPORT int CVodeGetQuadB(void* cvode_mem, int which, + sunrealtype* tBret, N_Vector qB); /* Optional Output Functions For Backward Problems */ -SUNDIALS_EXPORT void *CVodeGetAdjCVodeBmem(void *cvode_mem, int which); +SUNDIALS_EXPORT void* CVodeGetAdjCVodeBmem(void* cvode_mem, int which); -SUNDIALS_EXPORT int CVodeGetAdjY(void *cvode_mem, realtype t, N_Vector y); +SUNDIALS_EXPORT int CVodeGetAdjY(void* cvode_mem, sunrealtype t, N_Vector y); -typedef struct { - void *my_addr; - void *next_addr; - realtype t0; - realtype t1; +typedef struct +{ + void* my_addr; + void* next_addr; + sunrealtype t0; + sunrealtype t1; long int nstep; int order; - realtype step; + sunrealtype step; } CVadjCheckPointRec; -SUNDIALS_EXPORT int CVodeGetAdjCheckPointsInfo(void *cvode_mem, - CVadjCheckPointRec *ckpnt); +SUNDIALS_EXPORT int CVodeGetAdjCheckPointsInfo(void* cvode_mem, + CVadjCheckPointRec* ckpnt); /* CVLS interface function that depends on CVRhsFn */ -int CVodeSetJacTimesRhsFnB(void *cvode_mem, int which, CVRhsFn jtimesRhsFn); - +SUNDIALS_EXPORT int CVodeSetJacTimesRhsFnB(void* cvode_mem, int which, + CVRhsFn jtimesRhsFn); /* Undocumented Optional Output Functions For Backward Problems */ @@ -590,12 +602,12 @@ int CVodeSetJacTimesRhsFnB(void *cvode_mem, int which, CVRhsFn jtimesRhsFn); * CV_POLYNOMIAL, or CV_SUCCESS otherwise. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int CVodeGetAdjDataPointHermite(void *cvode_mem, int which, - realtype *t, N_Vector y, +SUNDIALS_EXPORT int CVodeGetAdjDataPointHermite(void* cvode_mem, int which, + sunrealtype* t, N_Vector y, N_Vector yd); -SUNDIALS_EXPORT int CVodeGetAdjDataPointPolynomial(void *cvode_mem, int which, - realtype *t, int *order, +SUNDIALS_EXPORT int CVodeGetAdjDataPointPolynomial(void* cvode_mem, int which, + sunrealtype* t, int* order, N_Vector y); /* ----------------------------------------------------------------- @@ -603,8 +615,7 @@ SUNDIALS_EXPORT int CVodeGetAdjDataPointPolynomial(void *cvode_mem, int which, * Returns the address of the 'active' check point. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int CVodeGetAdjCurrentCheckPoint(void *cvode_mem, void **addr); - +SUNDIALS_EXPORT int CVodeGetAdjCurrentCheckPoint(void* cvode_mem, void** addr); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bandpre.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bandpre.h index 7397dcfba..fe5869884 100644 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bandpre.h +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bandpre.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,37 +21,32 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /*----------------- FORWARD PROBLEMS -----------------*/ /* BandPrec inititialization function */ -SUNDIALS_EXPORT int CVBandPrecInit(void *cvode_mem, sunindextype N, +SUNDIALS_EXPORT int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu, sunindextype ml); /* Optional output functions */ -SUNDIALS_EXPORT int CVBandPrecGetWorkSpace(void *cvode_mem, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int CVBandPrecGetNumRhsEvals(void *cvode_mem, - long int *nfevalsBP); - +SUNDIALS_EXPORT int CVBandPrecGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVBandPrecGetNumRhsEvals(void* cvode_mem, + long int* nfevalsBP); /*------------------ BACKWARD PROBLEMS ------------------*/ -SUNDIALS_EXPORT int CVBandPrecInitB(void *cvode_mem, int which, - sunindextype nB, sunindextype muB, - sunindextype mlB); - +SUNDIALS_EXPORT int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB, + sunindextype muB, sunindextype mlB); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bbdpre.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bbdpre.h index 8f8b15f80..f888904a7 100644 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bbdpre.h +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_bbdpre.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,44 +22,40 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /*----------------- FORWARD PROBLEMS -----------------*/ /* User-supplied function Types */ -typedef int (*CVLocalFn)(sunindextype Nlocal, realtype t, - N_Vector y, N_Vector g, void *user_data); +typedef int (*CVLocalFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + N_Vector g, void* user_data); -typedef int (*CVCommFn)(sunindextype Nlocal, realtype t, - N_Vector y, void *user_data); +typedef int (*CVCommFn)(sunindextype Nlocal, sunrealtype t, N_Vector y, + void* user_data); /* Exported Functions */ -SUNDIALS_EXPORT int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, +SUNDIALS_EXPORT int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, sunindextype mudq, sunindextype mldq, sunindextype mukeep, sunindextype mlkeep, - realtype dqrely, CVLocalFn gloc, CVCommFn cfn); - -SUNDIALS_EXPORT int CVBBDPrecReInit(void *cvode_mem, - sunindextype mudq, sunindextype mldq, - realtype dqrely); + sunrealtype dqrely, CVLocalFn gloc, + CVCommFn cfn); +SUNDIALS_EXPORT int CVBBDPrecReInit(void* cvode_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dqrely); /* Optional output functions */ -SUNDIALS_EXPORT int CVBBDPrecGetWorkSpace(void *cvode_mem, - long int *lenrwBBDP, - long int *leniwBBDP); - -SUNDIALS_EXPORT int CVBBDPrecGetNumGfnEvals(void *cvode_mem, - long int *ngevalsBBDP); +SUNDIALS_EXPORT int CVBBDPrecGetWorkSpace(void* cvode_mem, long int* lenrwBBDP, + long int* leniwBBDP); +SUNDIALS_EXPORT int CVBBDPrecGetNumGfnEvals(void* cvode_mem, + long int* ngevalsBBDP); /*------------------ BACKWARD PROBLEMS @@ -67,24 +63,23 @@ SUNDIALS_EXPORT int CVBBDPrecGetNumGfnEvals(void *cvode_mem, /* User-Supplied Function Types */ -typedef int (*CVLocalFnB)(sunindextype NlocalB, realtype t, - N_Vector y, N_Vector yB, N_Vector gB, void *user_dataB); - -typedef int (*CVCommFnB)(sunindextype NlocalB, realtype t, - N_Vector y, N_Vector yB, void *user_dataB); +typedef int (*CVLocalFnB)(sunindextype NlocalB, sunrealtype t, N_Vector y, + N_Vector yB, N_Vector gB, void* user_dataB); +typedef int (*CVCommFnB)(sunindextype NlocalB, sunrealtype t, N_Vector y, + N_Vector yB, void* user_dataB); /* Exported Functions */ -SUNDIALS_EXPORT int CVBBDPrecInitB(void *cvode_mem, int which, sunindextype NlocalB, - sunindextype mudqB, sunindextype mldqB, - sunindextype mukeepB, sunindextype mlkeepB, - realtype dqrelyB, CVLocalFnB glocB, CVCommFnB cfnB); +SUNDIALS_EXPORT int CVBBDPrecInitB(void* cvode_mem, int which, + sunindextype NlocalB, sunindextype mudqB, + sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dqrelyB, + CVLocalFnB glocB, CVCommFnB cfnB); -SUNDIALS_EXPORT int CVBBDPrecReInitB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVBBDPrecReInitB(void* cvode_mem, int which, sunindextype mudqB, sunindextype mldqB, - realtype dqrelyB); - + sunrealtype dqrelyB); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_diag.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_diag.h index d8bb65c94..2a795af27 100644 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_diag.h +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_diag.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * --------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,7 +19,7 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -27,11 +27,11 @@ extern "C" { * CVDIAG return values * --------------------- */ -#define CVDIAG_SUCCESS 0 -#define CVDIAG_MEM_NULL -1 -#define CVDIAG_LMEM_NULL -2 -#define CVDIAG_ILL_INPUT -3 -#define CVDIAG_MEM_FAIL -4 +#define CVDIAG_SUCCESS 0 +#define CVDIAG_MEM_NULL -1 +#define CVDIAG_LMEM_NULL -2 +#define CVDIAG_ILL_INPUT -3 +#define CVDIAG_MEM_FAIL -4 /* Additional last_flag values */ @@ -41,7 +41,7 @@ extern "C" { /* Return values for adjoint module */ -#define CVDIAG_NO_ADJ -101 +#define CVDIAG_NO_ADJ -101 /* ----------------- * Forward Problems @@ -49,22 +49,21 @@ extern "C" { /* CVDiag initialization function */ -SUNDIALS_EXPORT int CVDiag(void *cvode_mem); +SUNDIALS_EXPORT int CVDiag(void* cvode_mem); /* Optional output functions */ -SUNDIALS_EXPORT int CVDiagGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int CVDiagGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); -SUNDIALS_EXPORT int CVDiagGetLastFlag(void *cvode_mem, long int *flag); -SUNDIALS_EXPORT char *CVDiagGetReturnFlagName(long int flag); +SUNDIALS_EXPORT int CVDiagGetWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVDiagGetNumRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVDiagGetLastFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVDiagGetReturnFlagName(long int flag); /* ------------------------------------- * Backward Problems - Function CVDiagB * ------------------------------------- */ -SUNDIALS_EXPORT int CVDiagB(void *cvode_mem, int which); - +SUNDIALS_EXPORT int CVDiagB(void* cvode_mem, int which); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_direct.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_direct.h deleted file mode 100644 index cf1d3c9dd..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_direct.h +++ /dev/null @@ -1,69 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated direct linear solver interface in - * CVODES; these routines now just wrap the updated CVODE generic - * linear solver interface in cvodes_ls.h. - * -----------------------------------------------------------------*/ - -#ifndef _CVSDLS_H -#define _CVSDLS_H - -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - - -/*================================================================= - Function Types (typedefs for equivalent types in cvodes_ls.h) - =================================================================*/ - -typedef CVLsJacFn CVDlsJacFn; -typedef CVLsJacFnB CVDlsJacFnB; -typedef CVLsJacFnBS CVDlsJacFnBS; - -/*==================================================================== - Exported Functions (wrappers for equivalent routines in cvodes_ls.h) - ====================================================================*/ - -SUNDIALS_EXPORT int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, - SUNMatrix A); - -SUNDIALS_EXPORT int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac); - -SUNDIALS_EXPORT int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS); - -SUNDIALS_EXPORT int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals); - -SUNDIALS_EXPORT int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); - -SUNDIALS_EXPORT int CVDlsGetLastFlag(void *cvode_mem, long int *flag); - -SUNDIALS_EXPORT char *CVDlsGetReturnFlagName(long int flag); - -SUNDIALS_EXPORT int CVDlsSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS, SUNMatrix A); - -SUNDIALS_EXPORT int CVDlsSetJacFnB(void *cvode_mem, int which, CVDlsJacFnB jacB); - -SUNDIALS_EXPORT int CVDlsSetJacFnBS(void *cvode_mem, int which, CVDlsJacFnBS jacBS); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_ls.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_ls.h index b92a7374a..a4294e087 100644 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_ls.h +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_ls.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -24,16 +24,15 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /*================================================================= CVLS Constants =================================================================*/ -#define CVLS_SUCCESS 0 +#define CVLS_SUCCESS 0 #define CVLS_MEM_NULL -1 #define CVLS_LMEM_NULL -2 #define CVLS_ILL_INPUT -3 @@ -46,9 +45,8 @@ extern "C" { /* Return values for the adjoint module */ -#define CVLS_NO_ADJ -101 -#define CVLS_LMEMB_NULL -102 - +#define CVLS_NO_ADJ -101 +#define CVLS_LMEMB_NULL -102 /*================================================================= Forward problems @@ -58,86 +56,79 @@ extern "C" { CVLS user-supplied function prototypes =================================================================*/ -typedef int (*CVLsJacFn)(realtype t, N_Vector y, N_Vector fy, - SUNMatrix Jac, void *user_data, - N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); +typedef int (*CVLsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + void* user_data, N_Vector tmp1, N_Vector tmp2, + N_Vector tmp3); -typedef int (*CVLsPrecSetupFn)(realtype t, N_Vector y, N_Vector fy, - booleantype jok, booleantype *jcurPtr, - realtype gamma, void *user_data); +typedef int (*CVLsPrecSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* user_data); -typedef int (*CVLsPrecSolveFn)(realtype t, N_Vector y, N_Vector fy, - N_Vector r, N_Vector z, realtype gamma, - realtype delta, int lr, void *user_data); +typedef 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); -typedef int (*CVLsJacTimesSetupFn)(realtype t, N_Vector y, - N_Vector fy, void *user_data); +typedef int (*CVLsJacTimesSetupFn)(sunrealtype t, N_Vector y, N_Vector fy, + void* user_data); -typedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, realtype t, - N_Vector y, N_Vector fy, - void *user_data, N_Vector tmp); +typedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, sunrealtype t, + N_Vector y, N_Vector fy, void* user_data, + N_Vector tmp); -typedef int (*CVLsLinSysFn)(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, - booleantype jok, booleantype *jcur, realtype gamma, - void *user_data, N_Vector tmp1, N_Vector tmp2, - N_Vector tmp3); +typedef int (*CVLsLinSysFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix A, + sunbooleantype jok, sunbooleantype* jcur, + sunrealtype gamma, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); /*================================================================= CVLS Exported functions =================================================================*/ -SUNDIALS_EXPORT int CVodeSetLinearSolver(void *cvode_mem, - SUNLinearSolver LS, +SUNDIALS_EXPORT int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A); - /*----------------------------------------------------------------- Optional inputs to the CVLS linear solver interface -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int CVodeSetJacFn(void *cvode_mem, CVLsJacFn jac); -SUNDIALS_EXPORT int CVodeSetJacEvalFrequency(void *cvode_mem, - long int msbj); -SUNDIALS_EXPORT int CVodeSetLinearSolutionScaling(void *cvode_mem, - booleantype onoff); -SUNDIALS_EXPORT int CVodeSetEpsLin(void *cvode_mem, realtype eplifac); -SUNDIALS_EXPORT int CVodeSetLSNormFactor(void *arkode_mem, - realtype nrmfac); -SUNDIALS_EXPORT int CVodeSetPreconditioner(void *cvode_mem, - CVLsPrecSetupFn pset, +SUNDIALS_EXPORT int CVodeSetJacFn(void* cvode_mem, CVLsJacFn jac); +SUNDIALS_EXPORT int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj); +SUNDIALS_EXPORT int CVodeSetLinearSolutionScaling(void* cvode_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, + sunrealtype dgmax_jbad); +SUNDIALS_EXPORT int CVodeSetEpsLin(void* cvode_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int CVodeSetLSNormFactor(void* arkode_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn pset, CVLsPrecSolveFn psolve); -SUNDIALS_EXPORT int CVodeSetJacTimes(void *cvode_mem, - CVLsJacTimesSetupFn jtsetup, +SUNDIALS_EXPORT int CVodeSetJacTimes(void* cvode_mem, CVLsJacTimesSetupFn jtsetup, CVLsJacTimesVecFn jtimes); -SUNDIALS_EXPORT int CVodeSetLinSysFn(void *cvode_mem, CVLsLinSysFn linsys); +SUNDIALS_EXPORT int CVodeSetLinSysFn(void* cvode_mem, CVLsLinSysFn linsys); /*----------------------------------------------------------------- Optional outputs from the CVLS linear solver interface -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int CVodeGetLinWorkSpace(void *cvode_mem, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int CVodeGetNumJacEvals(void *cvode_mem, - long int *njevals); -SUNDIALS_EXPORT int CVodeGetNumPrecEvals(void *cvode_mem, - long int *npevals); -SUNDIALS_EXPORT int CVodeGetNumPrecSolves(void *cvode_mem, - long int *npsolves); -SUNDIALS_EXPORT int CVodeGetNumLinIters(void *cvode_mem, - long int *nliters); -SUNDIALS_EXPORT int CVodeGetNumLinConvFails(void *cvode_mem, - long int *nlcfails); -SUNDIALS_EXPORT int CVodeGetNumJTSetupEvals(void *cvode_mem, - long int *njtsetups); -SUNDIALS_EXPORT int CVodeGetNumJtimesEvals(void *cvode_mem, - long int *njvevals); -SUNDIALS_EXPORT int CVodeGetNumLinRhsEvals(void *cvode_mem, - long int *nfevalsLS); -SUNDIALS_EXPORT int CVodeGetLastLinFlag(void *cvode_mem, - long int *flag); -SUNDIALS_EXPORT char *CVodeGetLinReturnFlagName(long int flag); - +SUNDIALS_EXPORT int CVodeGetJac(void* cvode_mem, SUNMatrix* J); +SUNDIALS_EXPORT int CVodeGetJacTime(void* cvode_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int CVodeGetJacNumSteps(void* cvode_mem, long int* nst_J); +SUNDIALS_EXPORT int CVodeGetLinWorkSpace(void* cvode_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int CVodeGetNumJacEvals(void* cvode_mem, long int* njevals); +SUNDIALS_EXPORT int CVodeGetNumPrecEvals(void* cvode_mem, long int* npevals); +SUNDIALS_EXPORT int CVodeGetNumPrecSolves(void* cvode_mem, long int* npsolves); +SUNDIALS_EXPORT int CVodeGetNumLinIters(void* cvode_mem, long int* nliters); +SUNDIALS_EXPORT int CVodeGetNumLinConvFails(void* cvode_mem, long int* nlcfails); +SUNDIALS_EXPORT int CVodeGetNumJTSetupEvals(void* cvode_mem, long int* njtsetups); +SUNDIALS_EXPORT int CVodeGetNumJtimesEvals(void* cvode_mem, long int* njvevals); +SUNDIALS_EXPORT int CVodeGetNumLinRhsEvals(void* cvode_mem, long int* nfevalsLS); +SUNDIALS_EXPORT int CVodeGetLinSolveStats(void* cvode_mem, long int* njevals, + long int* nfevalsLS, + long int* nliters, long int* nlcfails, + long int* npevals, long int* npsolves, + long int* njtsetups, long int* njtimes); +SUNDIALS_EXPORT int CVodeGetLastLinFlag(void* cvode_mem, long int* flag); +SUNDIALS_EXPORT char* CVodeGetLinReturnFlagName(long int flag); /*================================================================= Backward problems @@ -147,74 +138,66 @@ SUNDIALS_EXPORT char *CVodeGetLinReturnFlagName(long int flag); CVLS user-supplied function prototypes =================================================================*/ -typedef int (*CVLsJacFnB)(realtype t, N_Vector y, N_Vector yB, - N_Vector fyB, SUNMatrix JB, - void *user_dataB, N_Vector tmp1B, +typedef int (*CVLsJacFnB)(sunrealtype t, N_Vector y, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* user_dataB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); -typedef int (*CVLsJacFnBS)(realtype t, N_Vector y, N_Vector *yS, - N_Vector yB, N_Vector fyB, SUNMatrix JB, - void *user_dataB, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); - -typedef int (*CVLsPrecSetupFnB)(realtype t, N_Vector y, N_Vector yB, - N_Vector fyB, booleantype jokB, - booleantype *jcurPtrB, - realtype gammaB, void *user_dataB); - -typedef int (*CVLsPrecSetupFnBS)(realtype t, N_Vector y, - N_Vector *yS, N_Vector yB, - N_Vector fyB, booleantype jokB, - booleantype *jcurPtrB, - realtype gammaB, void *user_dataB); - -typedef int (*CVLsPrecSolveFnB)(realtype t, N_Vector y, N_Vector yB, - N_Vector fyB, N_Vector rB, - N_Vector zB, realtype gammaB, - realtype deltaB, int lrB, - void *user_dataB); - -typedef int (*CVLsPrecSolveFnBS)(realtype t, N_Vector y, N_Vector *yS, - N_Vector yB, N_Vector fyB, - N_Vector rB, N_Vector zB, - realtype gammaB, realtype deltaB, - int lrB, void *user_dataB); - -typedef int (*CVLsJacTimesSetupFnB)(realtype t, N_Vector y, N_Vector yB, - N_Vector fyB, void *jac_dataB); - -typedef int (*CVLsJacTimesSetupFnBS)(realtype t, N_Vector y, - N_Vector *yS, N_Vector yB, - N_Vector fyB, void *jac_dataB); - -typedef int (*CVLsJacTimesVecFnB)(N_Vector vB, N_Vector JvB, realtype t, +typedef int (*CVLsJacFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector fyB, SUNMatrix JB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*CVLsPrecSetupFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, sunbooleantype jokB, + sunbooleantype* jcurPtrB, sunrealtype gammaB, + void* user_dataB); + +typedef int (*CVLsPrecSetupFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, sunbooleantype jokB, + sunbooleantype* jcurPtrB, sunrealtype gammaB, + void* user_dataB); + +typedef int (*CVLsPrecSolveFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, N_Vector rB, N_Vector zB, + sunrealtype gammaB, sunrealtype deltaB, int lrB, + void* user_dataB); + +typedef int (*CVLsPrecSolveFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, N_Vector rB, + N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* user_dataB); + +typedef int (*CVLsJacTimesSetupFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, void* jac_dataB); + +typedef int (*CVLsJacTimesSetupFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, + N_Vector yB, N_Vector fyB, void* jac_dataB); + +typedef int (*CVLsJacTimesVecFnB)(N_Vector vB, N_Vector JvB, sunrealtype t, N_Vector y, N_Vector yB, N_Vector fyB, - void *jac_dataB, N_Vector tmpB); + void* jac_dataB, N_Vector tmpB); -typedef int (*CVLsJacTimesVecFnBS)(N_Vector vB, N_Vector JvB, - realtype t, N_Vector y, N_Vector *yS, - N_Vector yB, N_Vector fyB, - void *jac_dataB, N_Vector tmpB); +typedef int (*CVLsJacTimesVecFnBS)(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector y, N_Vector* yS, N_Vector yB, + N_Vector fyB, void* jac_dataB, N_Vector tmpB); -typedef int (*CVLsLinSysFnB)(realtype t, N_Vector y, N_Vector yB, N_Vector fyB, - SUNMatrix AB, booleantype jokB, booleantype *jcurB, - realtype gammaB, void *user_dataB, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); +typedef int (*CVLsLinSysFnB)(sunrealtype t, N_Vector y, N_Vector yB, + N_Vector fyB, SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* user_dataB, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B); -typedef int (*CVLsLinSysFnBS)(realtype t, N_Vector y, N_Vector* yS, +typedef int (*CVLsLinSysFnBS)(sunrealtype t, N_Vector y, N_Vector* yS, N_Vector yB, N_Vector fyB, SUNMatrix AB, - booleantype jokB, booleantype *jcurB, - realtype gammaB, void *user_dataB, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); + sunbooleantype jokB, sunbooleantype* jcurB, + sunrealtype gammaB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); /*================================================================= CVLS Exported functions =================================================================*/ -SUNDIALS_EXPORT int CVodeSetLinearSolverB(void *cvode_mem, - int which, - SUNLinearSolver LS, - SUNMatrix A); +SUNDIALS_EXPORT int CVodeSetLinearSolverB(void* cvode_mem, int which, + SUNLinearSolver LS, SUNMatrix A); /*----------------------------------------------------------------- Each CVodeSet***B or CVodeSet***BS function below links the @@ -223,43 +206,38 @@ SUNDIALS_EXPORT int CVodeSetLinearSolverB(void *cvode_mem, The 'which' argument is the int returned by CVodeCreateB. -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int CVodeSetJacFnB(void *cvode_mem, int which, - CVLsJacFnB jacB); -SUNDIALS_EXPORT int CVodeSetJacFnBS(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetJacFnB(void* cvode_mem, int which, CVLsJacFnB jacB); +SUNDIALS_EXPORT int CVodeSetJacFnBS(void* cvode_mem, int which, CVLsJacFnBS jacBS); -SUNDIALS_EXPORT int CVodeSetEpsLinB(void *cvode_mem, int which, - realtype eplifacB); +SUNDIALS_EXPORT int CVodeSetEpsLinB(void* cvode_mem, int which, + sunrealtype eplifacB); -SUNDIALS_EXPORT int CVodeSetLSNormFactorB(void *arkode_mem, int which, - realtype nrmfacB); +SUNDIALS_EXPORT int CVodeSetLSNormFactorB(void* arkode_mem, int which, + sunrealtype nrmfacB); -SUNDIALS_EXPORT int CVodeSetLinearSolutionScalingB(void *cvode_mem, int which, - booleantype onoffB); +SUNDIALS_EXPORT int CVodeSetLinearSolutionScalingB(void* cvode_mem, int which, + sunbooleantype onoffB); -SUNDIALS_EXPORT int CVodeSetPreconditionerB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetPreconditionerB(void* cvode_mem, int which, CVLsPrecSetupFnB psetB, CVLsPrecSolveFnB psolveB); -SUNDIALS_EXPORT int CVodeSetPreconditionerBS(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetPreconditionerBS(void* cvode_mem, int which, CVLsPrecSetupFnBS psetBS, CVLsPrecSolveFnBS psolveBS); -SUNDIALS_EXPORT int CVodeSetJacTimesB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetJacTimesB(void* cvode_mem, int which, CVLsJacTimesSetupFnB jtsetupB, CVLsJacTimesVecFnB jtimesB); -SUNDIALS_EXPORT int CVodeSetJacTimesBS(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetJacTimesBS(void* cvode_mem, int which, CVLsJacTimesSetupFnBS jtsetupBS, CVLsJacTimesVecFnBS jtimesBS); -SUNDIALS_EXPORT int CVodeSetLinSysFnB(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetLinSysFnB(void* cvode_mem, int which, CVLsLinSysFnB linsys); -SUNDIALS_EXPORT int CVodeSetLinSysFnBS(void *cvode_mem, int which, +SUNDIALS_EXPORT int CVodeSetLinSysFnBS(void* cvode_mem, int which, CVLsLinSysFnBS linsys); -/* Deprecated functions */ -SUNDIALS_DEPRECATED_EXPORT -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj); - #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_proj.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_proj.h new file mode 100644 index 000000000..8ff792e21 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_proj.h @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------------------- + * Based on CPODES by Radu Serban @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * This is the header file for CVODE's projection interface. + * ---------------------------------------------------------------------------*/ + +#ifndef _CVPROJ_H +#define _CVPROJ_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * CVProj user-supplied function prototypes + * ---------------------------------------------------------------------------*/ + +typedef int (*CVProjFn)(sunrealtype t, N_Vector ycur, N_Vector corr, + sunrealtype epsProj, N_Vector err, void* user_data); + +/* ----------------------------------------------------------------------------- + * CVProj Exported functions + * ---------------------------------------------------------------------------*/ + +/* Projection initialization functions */ +SUNDIALS_EXPORT int CVodeSetProjFn(void* cvode_mem, CVProjFn pfun); + +/* Optional input functions */ +SUNDIALS_EXPORT int CVodeSetProjErrEst(void* cvode_mem, sunbooleantype onoff); +SUNDIALS_EXPORT int CVodeSetProjFrequency(void* cvode_mem, long int proj_freq); +SUNDIALS_EXPORT int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails); +SUNDIALS_EXPORT int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps); +SUNDIALS_EXPORT int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta); + +/* Optional output functions */ +SUNDIALS_EXPORT int CVodeGetNumProjEvals(void* cvode_mem, long int* nproj); +SUNDIALS_EXPORT int CVodeGetNumProjFails(void* cvode_mem, long int* nprf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_spils.h b/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_spils.h deleted file mode 100644 index 66a9b0095..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/cvodes/cvodes_spils.h +++ /dev/null @@ -1,107 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated Scaled, Preconditioned Iterative - * Linear Solver interface in CVODES; these routines now just wrap - * the updated CVODES generic linear solver interface in cvodes_ls.h. - * -----------------------------------------------------------------*/ - -#ifndef _CVSSPILS_H -#define _CVSSPILS_H - -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - - -/*=============================================================== - Function Types (typedefs for equivalent types in cvodes_ls.h) - ===============================================================*/ - -typedef CVLsPrecSetupFn CVSpilsPrecSetupFn; -typedef CVLsPrecSolveFn CVSpilsPrecSolveFn; -typedef CVLsJacTimesSetupFn CVSpilsJacTimesSetupFn; -typedef CVLsJacTimesVecFn CVSpilsJacTimesVecFn; -typedef CVLsPrecSetupFnB CVSpilsPrecSetupFnB; -typedef CVLsPrecSetupFnBS CVSpilsPrecSetupFnBS; -typedef CVLsPrecSolveFnB CVSpilsPrecSolveFnB; -typedef CVLsPrecSolveFnBS CVSpilsPrecSolveFnBS; -typedef CVLsJacTimesSetupFnB CVSpilsJacTimesSetupFnB; -typedef CVLsJacTimesSetupFnBS CVSpilsJacTimesSetupFnBS; -typedef CVLsJacTimesVecFnB CVSpilsJacTimesVecFnB; -typedef CVLsJacTimesVecFnBS CVSpilsJacTimesVecFnBS; - -/*==================================================================== - Exported Functions (wrappers for equivalent routines in cvodes_ls.h) - ====================================================================*/ - -SUNDIALS_EXPORT int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS); - -SUNDIALS_EXPORT int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac); - -SUNDIALS_EXPORT int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, - CVSpilsPrecSolveFn psolve); - -SUNDIALS_EXPORT int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, - CVSpilsJacTimesVecFn jtimes); - -SUNDIALS_EXPORT int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS); - -SUNDIALS_EXPORT int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals); - -SUNDIALS_EXPORT int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves); - -SUNDIALS_EXPORT int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters); - -SUNDIALS_EXPORT int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails); - -SUNDIALS_EXPORT int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups); - -SUNDIALS_EXPORT int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals); - -SUNDIALS_EXPORT int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); - -SUNDIALS_EXPORT int CVSpilsGetLastFlag(void *cvode_mem, long int *flag); - -SUNDIALS_EXPORT char *CVSpilsGetReturnFlagName(long int flag); - -SUNDIALS_EXPORT int CVSpilsSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS); - -SUNDIALS_EXPORT int CVSpilsSetEpsLinB(void *cvode_mem, int which, realtype eplifacB); - -SUNDIALS_EXPORT int CVSpilsSetPreconditionerB(void *cvode_mem, int which, - CVSpilsPrecSetupFnB psetB, - CVSpilsPrecSolveFnB psolveB); - -SUNDIALS_EXPORT int CVSpilsSetPreconditionerBS(void *cvode_mem, int which, - CVSpilsPrecSetupFnBS psetBS, - CVSpilsPrecSolveFnBS psolveBS); - -SUNDIALS_EXPORT int CVSpilsSetJacTimesB(void *cvode_mem, int which, - CVSpilsJacTimesSetupFnB jtsetupB, - CVSpilsJacTimesVecFnB jtimesB); - -SUNDIALS_EXPORT int CVSpilsSetJacTimesBS(void *cvode_mem, int which, - CVSpilsJacTimesSetupFnBS jtsetupBS, - CVSpilsJacTimesVecFnBS jtimesBS); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/idas/idas.h b/deps/AMICI/ThirdParty/sundials/include/idas/idas.h index e685cd818..3f82d6f47 100644 --- a/deps/AMICI/ThirdParty/sundials/include/idas/idas.h +++ b/deps/AMICI/ThirdParty/sundials/include/idas/idas.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -17,12 +17,11 @@ #ifndef _IDAS_H #define _IDAS_H -#include -#include -#include #include +#include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -31,45 +30,45 @@ extern "C" { * ----------------- */ /* itask */ -#define IDA_NORMAL 1 -#define IDA_ONE_STEP 2 +#define IDA_NORMAL 1 +#define IDA_ONE_STEP 2 /* icopt */ -#define IDA_YA_YDP_INIT 1 -#define IDA_Y_INIT 2 +#define IDA_YA_YDP_INIT 1 +#define IDA_Y_INIT 2 /* ism */ -#define IDA_SIMULTANEOUS 1 -#define IDA_STAGGERED 2 +#define IDA_SIMULTANEOUS 1 +#define IDA_STAGGERED 2 /* DQtype */ -#define IDA_CENTERED 1 -#define IDA_FORWARD 2 +#define IDA_CENTERED 1 +#define IDA_FORWARD 2 /* interp */ -#define IDA_HERMITE 1 -#define IDA_POLYNOMIAL 2 +#define IDA_HERMITE 1 +#define IDA_POLYNOMIAL 2 /* return values */ -#define IDA_SUCCESS 0 -#define IDA_TSTOP_RETURN 1 -#define IDA_ROOT_RETURN 2 +#define IDA_SUCCESS 0 +#define IDA_TSTOP_RETURN 1 +#define IDA_ROOT_RETURN 2 -#define IDA_WARNING 99 +#define IDA_WARNING 99 -#define IDA_TOO_MUCH_WORK -1 -#define IDA_TOO_MUCH_ACC -2 -#define IDA_ERR_FAIL -3 -#define IDA_CONV_FAIL -4 +#define IDA_TOO_MUCH_WORK -1 +#define IDA_TOO_MUCH_ACC -2 +#define IDA_ERR_FAIL -3 +#define IDA_CONV_FAIL -4 -#define IDA_LINIT_FAIL -5 -#define IDA_LSETUP_FAIL -6 -#define IDA_LSOLVE_FAIL -7 -#define IDA_RES_FAIL -8 -#define IDA_REP_RES_ERR -9 -#define IDA_RTFUNC_FAIL -10 -#define IDA_CONSTR_FAIL -11 +#define IDA_LINIT_FAIL -5 +#define IDA_LSETUP_FAIL -6 +#define IDA_LSOLVE_FAIL -7 +#define IDA_RES_FAIL -8 +#define IDA_REP_RES_ERR -9 +#define IDA_RTFUNC_FAIL -10 +#define IDA_CONSTR_FAIL -11 #define IDA_FIRST_RES_FAIL -12 #define IDA_LINESEARCH_FAIL -13 @@ -78,25 +77,27 @@ extern "C" { #define IDA_NLS_SETUP_FAIL -16 #define IDA_NLS_FAIL -17 -#define IDA_MEM_NULL -20 -#define IDA_MEM_FAIL -21 -#define IDA_ILL_INPUT -22 -#define IDA_NO_MALLOC -23 -#define IDA_BAD_EWT -24 -#define IDA_BAD_K -25 -#define IDA_BAD_T -26 -#define IDA_BAD_DKY -27 -#define IDA_VECTOROP_ERR -28 - -#define IDA_NO_QUAD -30 -#define IDA_QRHS_FAIL -31 -#define IDA_FIRST_QRHS_ERR -32 -#define IDA_REP_QRHS_ERR -33 - -#define IDA_NO_SENS -40 -#define IDA_SRES_FAIL -41 -#define IDA_REP_SRES_ERR -42 -#define IDA_BAD_IS -43 +#define IDA_MEM_NULL -20 +#define IDA_MEM_FAIL -21 +#define IDA_ILL_INPUT -22 +#define IDA_NO_MALLOC -23 +#define IDA_BAD_EWT -24 +#define IDA_BAD_K -25 +#define IDA_BAD_T -26 +#define IDA_BAD_DKY -27 +#define IDA_VECTOROP_ERR -28 + +#define IDA_CONTEXT_ERR -29 + +#define IDA_NO_QUAD -30 +#define IDA_QRHS_FAIL -31 +#define IDA_FIRST_QRHS_ERR -32 +#define IDA_REP_QRHS_ERR -33 + +#define IDA_NO_SENS -40 +#define IDA_SRES_FAIL -41 +#define IDA_REP_SRES_ERR -42 +#define IDA_BAD_IS -43 #define IDA_NO_QUADSENS -50 #define IDA_QSRHS_FAIL -51 @@ -107,471 +108,462 @@ extern "C" { /* adjoint return values */ -#define IDA_NO_ADJ -101 -#define IDA_NO_FWD -102 -#define IDA_NO_BCK -103 -#define IDA_BAD_TB0 -104 -#define IDA_REIFWD_FAIL -105 -#define IDA_FWD_FAIL -106 -#define IDA_GETY_BADT -107 +#define IDA_NO_ADJ -101 +#define IDA_NO_FWD -102 +#define IDA_NO_BCK -103 +#define IDA_BAD_TB0 -104 +#define IDA_REIFWD_FAIL -105 +#define IDA_FWD_FAIL -106 +#define IDA_GETY_BADT -107 /* ------------------------------ * User-Supplied Function Types * ------------------------------ */ -typedef int (*IDAResFn)(realtype tt, N_Vector yy, N_Vector yp, - N_Vector rr, void *user_data); - -typedef int (*IDARootFn)(realtype t, N_Vector y, N_Vector yp, - realtype *gout, void *user_data); - -typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void *user_data); +typedef int (*IDAResFn)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, + void* user_data); -typedef void (*IDAErrHandlerFn)(int error_code, - const char *module, const char *function, - char *msg, void *user_data); +typedef int (*IDARootFn)(sunrealtype t, N_Vector y, N_Vector yp, + sunrealtype* gout, void* user_data); -typedef int (*IDAQuadRhsFn)(realtype tres, N_Vector yy, N_Vector yp, - N_Vector rrQ, void *user_data); +typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void* user_data); -typedef int (*IDASensResFn)(int Ns, realtype t, - N_Vector yy, N_Vector yp, N_Vector resval, - N_Vector *yyS, N_Vector *ypS, - N_Vector *resvalS, void *user_data, - N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); +typedef int (*IDAQuadRhsFn)(sunrealtype tres, N_Vector yy, N_Vector yp, + N_Vector rrQ, void* user_data); -typedef int (*IDAQuadSensRhsFn)(int Ns, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS, - N_Vector rrQ, N_Vector *rhsvalQS, - void *user_data, - N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS); +typedef int (*IDASensResFn)(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector resval, N_Vector* yyS, N_Vector* ypS, + N_Vector* resvalS, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); -typedef int (*IDAResFnB)(realtype tt, - N_Vector yy, N_Vector yp, - N_Vector yyB, N_Vector ypB, - N_Vector rrB, void *user_dataB); +typedef int (*IDAQuadSensRhsFn)(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector rrQ, + N_Vector* rhsvalQS, void* user_data, + N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS); -typedef int (*IDAResFnBS)(realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS, - N_Vector yyB, N_Vector ypB, - N_Vector rrBS, void *user_dataB); +typedef int (*IDAResFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector yyB, + N_Vector ypB, N_Vector rrB, void* user_dataB); -typedef int (*IDAQuadRhsFnB)(realtype tt, - N_Vector yy, N_Vector yp, - N_Vector yyB, N_Vector ypB, - N_Vector rhsvalBQ, void *user_dataB); +typedef int (*IDAResFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrBS, void* user_dataB); -typedef int (*IDAQuadRhsFnBS)(realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS, - N_Vector yyB, N_Vector ypB, - N_Vector rhsvalBQS, void *user_dataB); +typedef int (*IDAQuadRhsFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rhsvalBQ, + void* user_dataB); +typedef int (*IDAQuadRhsFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rhsvalBQS, void* user_dataB); /* --------------------------------------- * Exported Functions -- Forward Problems * --------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT void *IDACreate(void); +SUNDIALS_EXPORT void* IDACreate(SUNContext sunctx); -SUNDIALS_EXPORT int IDAInit(void *ida_mem, IDAResFn res, realtype t0, +SUNDIALS_EXPORT int IDAInit(void* ida_mem, IDAResFn res, sunrealtype t0, N_Vector yy0, N_Vector yp0); -SUNDIALS_EXPORT int IDAReInit(void *ida_mem, realtype t0, N_Vector yy0, +SUNDIALS_EXPORT int IDAReInit(void* ida_mem, sunrealtype t0, N_Vector yy0, N_Vector yp0); /* Tolerance input functions */ -SUNDIALS_EXPORT int IDASStolerances(void *ida_mem, realtype reltol, - realtype abstol); -SUNDIALS_EXPORT int IDASVtolerances(void *ida_mem, realtype reltol, +SUNDIALS_EXPORT int IDASStolerances(void* ida_mem, sunrealtype reltol, + sunrealtype abstol); +SUNDIALS_EXPORT int IDASVtolerances(void* ida_mem, sunrealtype reltol, N_Vector abstol); -SUNDIALS_EXPORT int IDAWFtolerances(void *ida_mem, IDAEwtFn efun); +SUNDIALS_EXPORT int IDAWFtolerances(void* ida_mem, IDAEwtFn efun); /* Initial condition calculation function */ -SUNDIALS_EXPORT int IDACalcIC(void *ida_mem, int icopt, realtype tout1); +SUNDIALS_EXPORT int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1); /* Initial condition calculation optional input functions */ -SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void *ida_mem, realtype epiccon); -SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void *ida_mem, int maxnh); -SUNDIALS_EXPORT int IDASetMaxNumJacsIC(void *ida_mem, int maxnj); -SUNDIALS_EXPORT int IDASetMaxNumItersIC(void *ida_mem, int maxnit); -SUNDIALS_EXPORT int IDASetLineSearchOffIC(void *ida_mem, booleantype lsoff); -SUNDIALS_EXPORT int IDASetStepToleranceIC(void *ida_mem, realtype steptol); -SUNDIALS_EXPORT int IDASetMaxBacksIC(void *ida_mem, int maxbacks); +SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon); +SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void* ida_mem, int maxnh); +SUNDIALS_EXPORT int IDASetMaxNumJacsIC(void* ida_mem, int maxnj); +SUNDIALS_EXPORT int IDASetMaxNumItersIC(void* ida_mem, int maxnit); +SUNDIALS_EXPORT int IDASetLineSearchOffIC(void* ida_mem, sunbooleantype lsoff); +SUNDIALS_EXPORT int IDASetStepToleranceIC(void* ida_mem, sunrealtype steptol); +SUNDIALS_EXPORT int IDASetMaxBacksIC(void* ida_mem, int maxbacks); /* Optional input functions */ -SUNDIALS_EXPORT int IDASetErrHandlerFn(void *ida_mem, IDAErrHandlerFn ehfun, - void *eh_data); -SUNDIALS_EXPORT int IDASetErrFile(void *ida_mem, FILE *errfp); -SUNDIALS_EXPORT int IDASetUserData(void *ida_mem, void *user_data); -SUNDIALS_EXPORT int IDASetMaxOrd(void *ida_mem, int maxord); -SUNDIALS_EXPORT int IDASetMaxNumSteps(void *ida_mem, long int mxsteps); -SUNDIALS_EXPORT int IDASetInitStep(void *ida_mem, realtype hin); -SUNDIALS_EXPORT int IDASetMaxStep(void *ida_mem, realtype hmax); -SUNDIALS_EXPORT int IDASetStopTime(void *ida_mem, realtype tstop); -SUNDIALS_EXPORT int IDASetNonlinConvCoef(void *ida_mem, realtype epcon); -SUNDIALS_EXPORT int IDASetMaxErrTestFails(void *ida_mem, int maxnef); -SUNDIALS_EXPORT int IDASetMaxNonlinIters(void *ida_mem, int maxcor); -SUNDIALS_EXPORT int IDASetMaxConvFails(void *ida_mem, int maxncf); -SUNDIALS_EXPORT int IDASetSuppressAlg(void *ida_mem, booleantype suppressalg); -SUNDIALS_EXPORT int IDASetId(void *ida_mem, N_Vector id); -SUNDIALS_EXPORT int IDASetConstraints(void *ida_mem, N_Vector constraints); - -SUNDIALS_EXPORT int IDASetNonlinearSolver(void *ida_mem, - SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int IDASetNlsResFn(void *IDA_mem, IDAResFn res); +SUNDIALS_EXPORT int IDASetDeltaCjLSetup(void* ida_max, sunrealtype dcj); +SUNDIALS_EXPORT int IDASetUserData(void* ida_mem, void* user_data); +SUNDIALS_EXPORT int IDASetMaxOrd(void* ida_mem, int maxord); +SUNDIALS_EXPORT int IDASetMaxNumSteps(void* ida_mem, long int mxsteps); +SUNDIALS_EXPORT int IDASetInitStep(void* ida_mem, sunrealtype hin); +SUNDIALS_EXPORT int IDASetMaxStep(void* ida_mem, sunrealtype hmax); +SUNDIALS_EXPORT int IDASetMinStep(void* ida_mem, sunrealtype hmin); +SUNDIALS_EXPORT int IDASetStopTime(void* ida_mem, sunrealtype tstop); +SUNDIALS_EXPORT int IDAClearStopTime(void* ida_mem); +SUNDIALS_EXPORT int IDASetMaxErrTestFails(void* ida_mem, int maxnef); +SUNDIALS_EXPORT int IDASetSuppressAlg(void* ida_mem, sunbooleantype suppressalg); +SUNDIALS_EXPORT int IDASetId(void* ida_mem, N_Vector id); +SUNDIALS_EXPORT int IDASetConstraints(void* ida_mem, N_Vector constraints); + +/* Optional step adaptivity input functions */ +SUNDIALS_EXPORT +int IDASetEtaFixedStepBounds(void* ida_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx); +SUNDIALS_EXPORT +int IDASetEtaMin(void* ida_mem, sunrealtype eta_min); +SUNDIALS_EXPORT +int IDASetEtaMax(void* ida_mem, sunrealtype eta_max); +SUNDIALS_EXPORT +int IDASetEtaLow(void* ida_mem, sunrealtype eta_low); +SUNDIALS_EXPORT +int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef); +SUNDIALS_EXPORT +int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf); + +/* Nonlinear solve input functions */ +SUNDIALS_EXPORT int IDASetMaxConvFails(void* ida_mem, int maxncf); +SUNDIALS_EXPORT int IDASetMaxNonlinIters(void* ida_mem, int maxcor); +SUNDIALS_EXPORT int IDASetNlsResFn(void* IDA_mem, IDAResFn res); +SUNDIALS_EXPORT int IDASetNonlinConvCoef(void* ida_mem, sunrealtype epcon); +SUNDIALS_EXPORT int IDASetNonlinearSolver(void* ida_mem, SUNNonlinearSolver NLS); /* Rootfinding initialization function */ -SUNDIALS_EXPORT int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g); +SUNDIALS_EXPORT int IDARootInit(void* ida_mem, int nrtfn, IDARootFn g); /* Rootfinding optional input functions */ -SUNDIALS_EXPORT int IDASetRootDirection(void *ida_mem, int *rootdir); -SUNDIALS_EXPORT int IDASetNoInactiveRootWarn(void *ida_mem); +SUNDIALS_EXPORT int IDASetRootDirection(void* ida_mem, int* rootdir); +SUNDIALS_EXPORT int IDASetNoInactiveRootWarn(void* ida_mem); /* Solver function */ -SUNDIALS_EXPORT int IDASolve(void *ida_mem, realtype tout, realtype *tret, +SUNDIALS_EXPORT int IDASolve(void* ida_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, N_Vector ypret, int itask); /* Utility functions to update/compute y and yp based on ycor */ -SUNDIALS_EXPORT int IDAComputeY(void *ida_mem, N_Vector ycor, N_Vector y); -SUNDIALS_EXPORT int IDAComputeYp(void *ida_mem, N_Vector ycor, N_Vector yp); -SUNDIALS_EXPORT int IDAComputeYSens(void *ida_mem, N_Vector *ycor, N_Vector *yyS); -SUNDIALS_EXPORT int IDAComputeYpSens(void *ida_mem, N_Vector *ycor, N_Vector *ypS); +SUNDIALS_EXPORT int IDAComputeY(void* ida_mem, N_Vector ycor, N_Vector y); +SUNDIALS_EXPORT int IDAComputeYp(void* ida_mem, N_Vector ycor, N_Vector yp); +SUNDIALS_EXPORT int IDAComputeYSens(void* ida_mem, N_Vector* ycor, N_Vector* yyS); +SUNDIALS_EXPORT int IDAComputeYpSens(void* ida_mem, N_Vector* ycor, + N_Vector* ypS); /* Dense output function */ -SUNDIALS_EXPORT int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky); +SUNDIALS_EXPORT int IDAGetDky(void* ida_mem, sunrealtype t, int k, N_Vector dky); /* Optional output functions */ -SUNDIALS_EXPORT int IDAGetWorkSpace(void *ida_mem, long int *lenrw, - long int *leniw); -SUNDIALS_EXPORT int IDAGetNumSteps(void *ida_mem, long int *nsteps); -SUNDIALS_EXPORT int IDAGetNumResEvals(void *ida_mem, long int *nrevals); -SUNDIALS_EXPORT int IDAGetNumLinSolvSetups(void *ida_mem, long int *nlinsetups); -SUNDIALS_EXPORT int IDAGetNumErrTestFails(void *ida_mem, long int *netfails); -SUNDIALS_EXPORT int IDAGetNumBacktrackOps(void *ida_mem, long int *nbacktr); -SUNDIALS_EXPORT int IDAGetConsistentIC(void *ida_mem, N_Vector yy0_mod, +SUNDIALS_EXPORT int IDAGetWorkSpace(void* ida_mem, long int* lenrw, + long int* leniw); +SUNDIALS_EXPORT int IDAGetNumSteps(void* ida_mem, long int* nsteps); +SUNDIALS_EXPORT int IDAGetNumResEvals(void* ida_mem, long int* nrevals); +SUNDIALS_EXPORT int IDAGetNumLinSolvSetups(void* ida_mem, long int* nlinsetups); +SUNDIALS_EXPORT int IDAGetNumErrTestFails(void* ida_mem, long int* netfails); +SUNDIALS_EXPORT int IDAGetNumBacktrackOps(void* ida_mem, long int* nbacktr); +SUNDIALS_EXPORT int IDAGetConsistentIC(void* ida_mem, N_Vector yy0_mod, N_Vector yp0_mod); -SUNDIALS_EXPORT int IDAGetLastOrder(void *ida_mem, int *klast); -SUNDIALS_EXPORT int IDAGetCurrentOrder(void *ida_mem, int *kcur); -SUNDIALS_EXPORT int IDAGetCurrentCj(void *ida_mem, realtype *cj); -SUNDIALS_EXPORT int IDAGetCurrentY(void *ida_mem, N_Vector *ycur); -SUNDIALS_EXPORT int IDAGetCurrentYSens(void *ida_mem, N_Vector **yS); -SUNDIALS_EXPORT int IDAGetCurrentYp(void *ida_mem, N_Vector *ypcur); -SUNDIALS_EXPORT int IDAGetCurrentYpSens(void *ida_mem, N_Vector **ypS); -SUNDIALS_EXPORT int IDAGetActualInitStep(void *ida_mem, realtype *hinused); -SUNDIALS_EXPORT int IDAGetLastStep(void *ida_mem, realtype *hlast); -SUNDIALS_EXPORT int IDAGetCurrentStep(void *ida_mem, realtype *hcur); -SUNDIALS_EXPORT int IDAGetCurrentTime(void *ida_mem, realtype *tcur); -SUNDIALS_EXPORT int IDAGetTolScaleFactor(void *ida_mem, realtype *tolsfact); -SUNDIALS_EXPORT int IDAGetErrWeights(void *ida_mem, N_Vector eweight); -SUNDIALS_EXPORT int IDAGetEstLocalErrors(void *ida_mem, N_Vector ele); -SUNDIALS_EXPORT int IDAGetNumGEvals(void *ida_mem, long int *ngevals); -SUNDIALS_EXPORT int IDAGetRootInfo(void *ida_mem, int *rootsfound); -SUNDIALS_EXPORT int IDAGetIntegratorStats(void *ida_mem, long int *nsteps, - long int *nrevals, - long int *nlinsetups, - long int *netfails, - int *qlast, int *qcur, - realtype *hinused, realtype *hlast, - realtype *hcur, realtype *tcur); -SUNDIALS_EXPORT int IDAGetNonlinearSystemData(void *ida_mem, realtype *tcur, - N_Vector *yypred, - N_Vector *yppred, - N_Vector *yyn, N_Vector *ypn, - N_Vector *res, realtype *cj, - void **user_data); -SUNDIALS_EXPORT int IDAGetNonlinearSystemDataSens(void *ida_mem, realtype *tcur, - N_Vector **yySpred, - N_Vector **ypSpred, - N_Vector **yySn, - N_Vector **ypSn, - realtype *cj, - void **user_data); -SUNDIALS_EXPORT int IDAGetNumNonlinSolvIters(void *ida_mem, long int *nniters); -SUNDIALS_EXPORT int IDAGetNumNonlinSolvConvFails(void *ida_mem, - long int *nncfails); -SUNDIALS_EXPORT int IDAGetNonlinSolvStats(void *ida_mem, long int *nniters, - long int *nncfails); -SUNDIALS_EXPORT char *IDAGetReturnFlagName(long int flag); +SUNDIALS_EXPORT int IDAGetLastOrder(void* ida_mem, int* klast); +SUNDIALS_EXPORT int IDAGetCurrentOrder(void* ida_mem, int* kcur); +SUNDIALS_EXPORT int IDAGetCurrentCj(void* ida_mem, sunrealtype* cj); +SUNDIALS_EXPORT int IDAGetCurrentY(void* ida_mem, N_Vector* ycur); +SUNDIALS_EXPORT int IDAGetCurrentYSens(void* ida_mem, N_Vector** yS); +SUNDIALS_EXPORT int IDAGetCurrentYp(void* ida_mem, N_Vector* ypcur); +SUNDIALS_EXPORT int IDAGetCurrentYpSens(void* ida_mem, N_Vector** ypS); +SUNDIALS_EXPORT int IDAGetActualInitStep(void* ida_mem, sunrealtype* hinused); +SUNDIALS_EXPORT int IDAGetLastStep(void* ida_mem, sunrealtype* hlast); +SUNDIALS_EXPORT int IDAGetCurrentStep(void* ida_mem, sunrealtype* hcur); +SUNDIALS_EXPORT int IDAGetCurrentTime(void* ida_mem, sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetTolScaleFactor(void* ida_mem, sunrealtype* tolsfact); +SUNDIALS_EXPORT int IDAGetErrWeights(void* ida_mem, N_Vector eweight); +SUNDIALS_EXPORT int IDAGetEstLocalErrors(void* ida_mem, N_Vector ele); +SUNDIALS_EXPORT int IDAGetNumGEvals(void* ida_mem, long int* ngevals); +SUNDIALS_EXPORT int IDAGetRootInfo(void* ida_mem, int* rootsfound); +SUNDIALS_EXPORT int IDAGetIntegratorStats(void* ida_mem, long int* nsteps, + long int* nrevals, long int* nlinsetups, + long int* netfails, int* qlast, + int* qcur, sunrealtype* hinused, + sunrealtype* hlast, sunrealtype* hcur, + sunrealtype* tcur); +SUNDIALS_EXPORT int IDAGetNonlinearSystemData(void* ida_mem, sunrealtype* tcur, + N_Vector* yypred, + N_Vector* yppred, N_Vector* yyn, + N_Vector* ypn, N_Vector* res, + sunrealtype* cj, void** user_data); +SUNDIALS_EXPORT int IDAGetNonlinearSystemDataSens( + void* ida_mem, sunrealtype* tcur, N_Vector** yySpred, N_Vector** ypSpred, + N_Vector** yySn, N_Vector** ypSn, sunrealtype* cj, void** user_data); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvIters(void* ida_mem, long int* nniters); +SUNDIALS_EXPORT int IDAGetNumNonlinSolvConvFails(void* ida_mem, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNonlinSolvStats(void* ida_mem, long int* nniters, + long int* nnfails); +SUNDIALS_EXPORT int IDAGetNumStepSolveFails(void* ida_mem, long int* nncfails); +SUNDIALS_EXPORT int IDAGetUserData(void* ida_mem, void** user_data); +SUNDIALS_EXPORT int IDAPrintAllStats(void* ida_mem, FILE* outfile, + SUNOutputFormat fmt); +SUNDIALS_EXPORT char* IDAGetReturnFlagName(long int flag); /* Free function */ -SUNDIALS_EXPORT void IDAFree(void **ida_mem); +SUNDIALS_EXPORT void IDAFree(void** ida_mem); /* IDALS interface function that depends on IDAResFn */ -SUNDIALS_EXPORT int IDASetJacTimesResFn(void *ida_mem, - IDAResFn jtimesResFn); - +SUNDIALS_EXPORT int IDASetJacTimesResFn(void* ida_mem, IDAResFn jtimesResFn); /* --------------------------------- * Exported Functions -- Quadrature * --------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT int IDAQuadInit(void *ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0); -SUNDIALS_EXPORT int IDAQuadReInit(void *ida_mem, N_Vector yQ0); +SUNDIALS_EXPORT int IDAQuadInit(void* ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0); +SUNDIALS_EXPORT int IDAQuadReInit(void* ida_mem, N_Vector yQ0); /* Tolerance input functions */ -SUNDIALS_EXPORT int IDAQuadSStolerances(void *ida_mem, realtype reltolQ, - realtype abstolQ); -SUNDIALS_EXPORT int IDAQuadSVtolerances(void *ida_mem, realtype reltolQ, +SUNDIALS_EXPORT int IDAQuadSStolerances(void* ida_mem, sunrealtype reltolQ, + sunrealtype abstolQ); +SUNDIALS_EXPORT int IDAQuadSVtolerances(void* ida_mem, sunrealtype reltolQ, N_Vector abstolQ); /* Optional input specification functions */ -SUNDIALS_EXPORT int IDASetQuadErrCon(void *ida_mem, booleantype errconQ); +SUNDIALS_EXPORT int IDASetQuadErrCon(void* ida_mem, sunbooleantype errconQ); /* Extraction and dense output functions */ -SUNDIALS_EXPORT int IDAGetQuad(void *ida_mem, realtype *t, N_Vector yQout); -SUNDIALS_EXPORT int IDAGetQuadDky(void *ida_mem, realtype t, int k, +SUNDIALS_EXPORT int IDAGetQuad(void* ida_mem, sunrealtype* t, N_Vector yQout); +SUNDIALS_EXPORT int IDAGetQuadDky(void* ida_mem, sunrealtype t, int k, N_Vector dky); /* Optional output specification functions */ -SUNDIALS_EXPORT int IDAGetQuadNumRhsEvals(void *ida_mem, long int *nrhsQevals); -SUNDIALS_EXPORT int IDAGetQuadNumErrTestFails(void *ida_mem, - long int *nQetfails); -SUNDIALS_EXPORT int IDAGetQuadErrWeights(void *ida_mem, N_Vector eQweight); -SUNDIALS_EXPORT int IDAGetQuadStats(void *ida_mem, long int *nrhsQevals, - long int *nQetfails); +SUNDIALS_EXPORT int IDAGetQuadNumRhsEvals(void* ida_mem, long int* nrhsQevals); +SUNDIALS_EXPORT int IDAGetQuadNumErrTestFails(void* ida_mem, long int* nQetfails); +SUNDIALS_EXPORT int IDAGetQuadErrWeights(void* ida_mem, N_Vector eQweight); +SUNDIALS_EXPORT int IDAGetQuadStats(void* ida_mem, long int* nrhsQevals, + long int* nQetfails); /* Free function */ -SUNDIALS_EXPORT void IDAQuadFree(void *ida_mem); - +SUNDIALS_EXPORT void IDAQuadFree(void* ida_mem); /* ------------------------------------ * Exported Functions -- Sensitivities * ------------------------------------ */ /* Initialization functions */ -SUNDIALS_EXPORT int IDASensInit(void *ida_mem, int Ns, int ism, - IDASensResFn resS, N_Vector *yS0, - N_Vector *ypS0); -SUNDIALS_EXPORT int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, - N_Vector *ypS0); +SUNDIALS_EXPORT int IDASensInit(void* ida_mem, int Ns, int ism, + IDASensResFn resS, N_Vector* yS0, N_Vector* ypS0); +SUNDIALS_EXPORT int IDASensReInit(void* ida_mem, int ism, N_Vector* yS0, + N_Vector* ypS0); /* Tolerance input functions */ -SUNDIALS_EXPORT int IDASensSStolerances(void *ida_mem, realtype reltolS, - realtype *abstolS); -SUNDIALS_EXPORT int IDASensSVtolerances(void *ida_mem, realtype reltolS, - N_Vector *abstolS); -SUNDIALS_EXPORT int IDASensEEtolerances(void *ida_mem); +SUNDIALS_EXPORT int IDASensSStolerances(void* ida_mem, sunrealtype reltolS, + sunrealtype* abstolS); +SUNDIALS_EXPORT int IDASensSVtolerances(void* ida_mem, sunrealtype reltolS, + N_Vector* abstolS); +SUNDIALS_EXPORT int IDASensEEtolerances(void* ida_mem); /* Initial condition calculation function */ -SUNDIALS_EXPORT int IDAGetSensConsistentIC(void *ida_mem, N_Vector *yyS0, - N_Vector *ypS0); +SUNDIALS_EXPORT int IDAGetSensConsistentIC(void* ida_mem, N_Vector* yyS0, + N_Vector* ypS0); /* Optional input specification functions */ -SUNDIALS_EXPORT int IDASetSensDQMethod(void *ida_mem, int DQtype, - realtype DQrhomax); -SUNDIALS_EXPORT int IDASetSensErrCon(void *ida_mem, booleantype errconS); -SUNDIALS_EXPORT int IDASetSensMaxNonlinIters(void *ida_mem, int maxcorS); -SUNDIALS_EXPORT int IDASetSensParams(void *ida_mem, realtype *p, realtype *pbar, - int *plist); +SUNDIALS_EXPORT int IDASetSensDQMethod(void* ida_mem, int DQtype, + sunrealtype DQrhomax); +SUNDIALS_EXPORT int IDASetSensErrCon(void* ida_mem, sunbooleantype errconS); +SUNDIALS_EXPORT int IDASetSensMaxNonlinIters(void* ida_mem, int maxcorS); +SUNDIALS_EXPORT int IDASetSensParams(void* ida_mem, sunrealtype* p, + sunrealtype* pbar, int* plist); /* Integrator nonlinear solver specification functions */ -SUNDIALS_EXPORT int IDASetNonlinearSolverSensSim(void *ida_mem, +SUNDIALS_EXPORT int IDASetNonlinearSolverSensSim(void* ida_mem, SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int IDASetNonlinearSolverSensStg(void *ida_mem, +SUNDIALS_EXPORT int IDASetNonlinearSolverSensStg(void* ida_mem, SUNNonlinearSolver NLS); /* Enable/disable sensitivities */ -SUNDIALS_EXPORT int IDASensToggleOff(void *ida_mem); +SUNDIALS_EXPORT int IDASensToggleOff(void* ida_mem); /* Extraction and dense output functions */ -SUNDIALS_EXPORT int IDAGetSens(void *ida_mem, realtype *tret, N_Vector *yySout); -SUNDIALS_EXPORT int IDAGetSens1(void *ida_mem, realtype *tret, int is, +SUNDIALS_EXPORT int IDAGetSens(void* ida_mem, sunrealtype* tret, + N_Vector* yySout); +SUNDIALS_EXPORT int IDAGetSens1(void* ida_mem, sunrealtype* tret, int is, N_Vector yySret); -SUNDIALS_EXPORT int IDAGetSensDky(void *ida_mem, realtype t, int k, - N_Vector *dkyS); -SUNDIALS_EXPORT int IDAGetSensDky1(void *ida_mem, realtype t, int k, int is, +SUNDIALS_EXPORT int IDAGetSensDky(void* ida_mem, sunrealtype t, int k, + N_Vector* dkyS); +SUNDIALS_EXPORT int IDAGetSensDky1(void* ida_mem, sunrealtype t, int k, int is, N_Vector dkyS); /* Optional output specification functions */ -SUNDIALS_EXPORT int IDAGetSensNumResEvals(void *ida_mem, long int *nresSevals); -SUNDIALS_EXPORT int IDAGetNumResEvalsSens(void *ida_mem, long int *nresevalsS); -SUNDIALS_EXPORT int IDAGetSensNumErrTestFails(void *ida_mem, - long int *nSetfails); -SUNDIALS_EXPORT int IDAGetSensNumLinSolvSetups(void *ida_mem, - long int *nlinsetupsS); -SUNDIALS_EXPORT int IDAGetSensErrWeights(void *ida_mem, N_Vector_S eSweight); -SUNDIALS_EXPORT int IDAGetSensStats(void *ida_mem, long int *nresSevals, - long int *nresevalsS, long int *nSetfails, - long int *nlinsetupsS); -SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvIters(void *ida_mem, - long int *nSniters); -SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvConvFails(void *ida_mem, - long int *nSncfails); -SUNDIALS_EXPORT int IDAGetSensNonlinSolvStats(void *ida_mem, - long int *nSniters, - long int *nSncfails); +SUNDIALS_EXPORT int IDAGetSensNumResEvals(void* ida_mem, long int* nresSevals); +SUNDIALS_EXPORT int IDAGetNumResEvalsSens(void* ida_mem, long int* nresevalsS); +SUNDIALS_EXPORT int IDAGetSensNumErrTestFails(void* ida_mem, long int* nSetfails); +SUNDIALS_EXPORT int IDAGetSensNumLinSolvSetups(void* ida_mem, + long int* nlinsetupsS); +SUNDIALS_EXPORT int IDAGetSensErrWeights(void* ida_mem, N_Vector_S eSweight); +SUNDIALS_EXPORT int IDAGetSensStats(void* ida_mem, long int* nresSevals, + long int* nresevalsS, long int* nSetfails, + long int* nlinsetupsS); +SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvIters(void* ida_mem, + long int* nSniters); +SUNDIALS_EXPORT int IDAGetSensNumNonlinSolvConvFails(void* ida_mem, + long int* nSnfails); +SUNDIALS_EXPORT int IDAGetSensNonlinSolvStats(void* ida_mem, long int* nSniters, + long int* nSnfails); +SUNDIALS_EXPORT int IDAGetNumStepSensSolveFails(void* ida_mem, + long int* nSncfails); /* Free function */ -SUNDIALS_EXPORT void IDASensFree(void *ida_mem); - +SUNDIALS_EXPORT void IDASensFree(void* ida_mem); /* ------------------------------------------------------- * Exported Functions -- Sensitivity dependent quadrature * ------------------------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT int IDAQuadSensInit(void *ida_mem, IDAQuadSensRhsFn resQS, - N_Vector *yQS0); -SUNDIALS_EXPORT int IDAQuadSensReInit(void *ida_mem, N_Vector *yQS0); +SUNDIALS_EXPORT int IDAQuadSensInit(void* ida_mem, IDAQuadSensRhsFn resQS, + N_Vector* yQS0); +SUNDIALS_EXPORT int IDAQuadSensReInit(void* ida_mem, N_Vector* yQS0); /* Tolerance input functions */ -SUNDIALS_EXPORT int IDAQuadSensSStolerances(void *ida_mem, realtype reltolQS, - realtype *abstolQS); -SUNDIALS_EXPORT int IDAQuadSensSVtolerances(void *ida_mem, realtype reltolQS, - N_Vector *abstolQS); -SUNDIALS_EXPORT int IDAQuadSensEEtolerances(void *ida_mem); +SUNDIALS_EXPORT int IDAQuadSensSStolerances(void* ida_mem, sunrealtype reltolQS, + sunrealtype* abstolQS); +SUNDIALS_EXPORT int IDAQuadSensSVtolerances(void* ida_mem, sunrealtype reltolQS, + N_Vector* abstolQS); +SUNDIALS_EXPORT int IDAQuadSensEEtolerances(void* ida_mem); /* Optional input specification functions */ -SUNDIALS_EXPORT int IDASetQuadSensErrCon(void *ida_mem, booleantype errconQS); +SUNDIALS_EXPORT int IDASetQuadSensErrCon(void* ida_mem, sunbooleantype errconQS); /* Extraction and dense output functions */ -SUNDIALS_EXPORT int IDAGetQuadSens(void *ida_mem, realtype *tret, - N_Vector *yyQSout); -SUNDIALS_EXPORT int IDAGetQuadSens1(void *ida_mem, realtype *tret, int is, +SUNDIALS_EXPORT int IDAGetQuadSens(void* ida_mem, sunrealtype* tret, + N_Vector* yyQSout); +SUNDIALS_EXPORT int IDAGetQuadSens1(void* ida_mem, sunrealtype* tret, int is, N_Vector yyQSret); -SUNDIALS_EXPORT int IDAGetQuadSensDky(void *ida_mem, realtype t, int k, - N_Vector *dkyQS); -SUNDIALS_EXPORT int IDAGetQuadSensDky1(void *ida_mem, realtype t, int k, int is, - N_Vector dkyQS); +SUNDIALS_EXPORT int IDAGetQuadSensDky(void* ida_mem, sunrealtype t, int k, + N_Vector* dkyQS); +SUNDIALS_EXPORT int IDAGetQuadSensDky1(void* ida_mem, sunrealtype t, int k, + int is, N_Vector dkyQS); /* Optional output specification functions */ -SUNDIALS_EXPORT int IDAGetQuadSensNumRhsEvals(void *ida_mem, - long int *nrhsQSevals); -SUNDIALS_EXPORT int IDAGetQuadSensNumErrTestFails(void *ida_mem, - long int *nQSetfails); -SUNDIALS_EXPORT int IDAGetQuadSensErrWeights(void *ida_mem, - N_Vector *eQSweight); -SUNDIALS_EXPORT int IDAGetQuadSensStats(void *ida_mem, - long int *nrhsQSevals, - long int *nQSetfails); +SUNDIALS_EXPORT int IDAGetQuadSensNumRhsEvals(void* ida_mem, + long int* nrhsQSevals); +SUNDIALS_EXPORT int IDAGetQuadSensNumErrTestFails(void* ida_mem, + long int* nQSetfails); +SUNDIALS_EXPORT int IDAGetQuadSensErrWeights(void* ida_mem, N_Vector* eQSweight); +SUNDIALS_EXPORT int IDAGetQuadSensStats(void* ida_mem, long int* nrhsQSevals, + long int* nQSetfails); /* Free function */ SUNDIALS_EXPORT void IDAQuadSensFree(void* ida_mem); - /* ---------------------------------------- * Exported Functions -- Backward Problems * ---------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT int IDAAdjInit(void *ida_mem, long int steps, int interp); +SUNDIALS_EXPORT int IDAAdjInit(void* ida_mem, long int steps, int interp); -SUNDIALS_EXPORT int IDAAdjReInit(void *ida_mem); +SUNDIALS_EXPORT int IDAAdjReInit(void* ida_mem); -SUNDIALS_EXPORT void IDAAdjFree(void *ida_mem); +SUNDIALS_EXPORT void IDAAdjFree(void* ida_mem); /* Backward Problem Setup Functions */ -SUNDIALS_EXPORT int IDACreateB(void *ida_mem, int *which); +SUNDIALS_EXPORT int IDACreateB(void* ida_mem, int* which); -SUNDIALS_EXPORT int IDAInitB(void *ida_mem, int which, IDAResFnB resB, - realtype tB0, N_Vector yyB0, N_Vector ypB0); +SUNDIALS_EXPORT int IDAInitB(void* ida_mem, int which, IDAResFnB resB, + sunrealtype tB0, N_Vector yyB0, N_Vector ypB0); -SUNDIALS_EXPORT int IDAInitBS(void *ida_mem, int which, IDAResFnBS resS, - realtype tB0, N_Vector yyB0, N_Vector ypB0); +SUNDIALS_EXPORT int IDAInitBS(void* ida_mem, int which, IDAResFnBS resS, + sunrealtype tB0, N_Vector yyB0, N_Vector ypB0); -SUNDIALS_EXPORT int IDAReInitB(void *ida_mem, int which, - realtype tB0, N_Vector yyB0, N_Vector ypB0); +SUNDIALS_EXPORT int IDAReInitB(void* ida_mem, int which, sunrealtype tB0, + N_Vector yyB0, N_Vector ypB0); -SUNDIALS_EXPORT int IDASStolerancesB(void *ida_mem, int which, - realtype relTolB, realtype absTolB); -SUNDIALS_EXPORT int IDASVtolerancesB(void *ida_mem, int which, - realtype relTolB, N_Vector absTolB); +SUNDIALS_EXPORT int IDASStolerancesB(void* ida_mem, int which, + sunrealtype relTolB, sunrealtype absTolB); +SUNDIALS_EXPORT int IDASVtolerancesB(void* ida_mem, int which, + sunrealtype relTolB, N_Vector absTolB); -SUNDIALS_EXPORT int IDAQuadInitB(void *ida_mem, int which, - IDAQuadRhsFnB rhsQB, N_Vector yQB0); +SUNDIALS_EXPORT int IDAQuadInitB(void* ida_mem, int which, IDAQuadRhsFnB rhsQB, + N_Vector yQB0); -SUNDIALS_EXPORT int IDAQuadInitBS(void *ida_mem, int which, +SUNDIALS_EXPORT int IDAQuadInitBS(void* ida_mem, int which, IDAQuadRhsFnBS rhsQS, N_Vector yQB0); -SUNDIALS_EXPORT int IDAQuadReInitB(void *ida_mem, int which, N_Vector yQB0); +SUNDIALS_EXPORT int IDAQuadReInitB(void* ida_mem, int which, N_Vector yQB0); -SUNDIALS_EXPORT int IDAQuadSStolerancesB(void *ida_mem, int which, - realtype reltolQB, realtype abstolQB); -SUNDIALS_EXPORT int IDAQuadSVtolerancesB(void *ida_mem, int which, - realtype reltolQB, N_Vector abstolQB); +SUNDIALS_EXPORT int IDAQuadSStolerancesB(void* ida_mem, int which, + sunrealtype reltolQB, + sunrealtype abstolQB); +SUNDIALS_EXPORT int IDAQuadSVtolerancesB(void* ida_mem, int which, + sunrealtype reltolQB, N_Vector abstolQB); /* Consistent IC calculation functions */ -SUNDIALS_EXPORT int IDACalcICB (void *ida_mem, int which, realtype tout1, - N_Vector yy0, N_Vector yp0); +SUNDIALS_EXPORT int IDACalcICB(void* ida_mem, int which, sunrealtype tout1, + N_Vector yy0, N_Vector yp0); -SUNDIALS_EXPORT int IDACalcICBS(void *ida_mem, int which, realtype tout1, - N_Vector yy0, N_Vector yp0, - N_Vector *yyS0, N_Vector *ypS0); +SUNDIALS_EXPORT int IDACalcICBS(void* ida_mem, int which, sunrealtype tout1, + N_Vector yy0, N_Vector yp0, N_Vector* yyS0, + N_Vector* ypS0); /* Solver Function For Forward Problems */ -SUNDIALS_EXPORT int IDASolveF(void *ida_mem, realtype tout, - realtype *tret, - N_Vector yret, N_Vector ypret, - int itask, int *ncheckPtr); +SUNDIALS_EXPORT int IDASolveF(void* ida_mem, sunrealtype tout, + sunrealtype* tret, N_Vector yret, N_Vector ypret, + int itask, int* ncheckPtr); /* Solver Function For Backward Problems */ -SUNDIALS_EXPORT int IDASolveB(void *ida_mem, realtype tBout, int itaskB); +SUNDIALS_EXPORT int IDASolveB(void* ida_mem, sunrealtype tBout, int itaskB); /* Optional Input Functions For Adjoint Problems */ -SUNDIALS_EXPORT int IDAAdjSetNoSensi(void *ida_mem); +SUNDIALS_EXPORT int IDAAdjSetNoSensi(void* ida_mem); -SUNDIALS_EXPORT int IDASetUserDataB(void *ida_mem, int which, void *user_dataB); -SUNDIALS_EXPORT int IDASetMaxOrdB(void *ida_mem, int which, int maxordB); -SUNDIALS_EXPORT int IDASetMaxNumStepsB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetUserDataB(void* ida_mem, int which, void* user_dataB); +SUNDIALS_EXPORT int IDASetMaxOrdB(void* ida_mem, int which, int maxordB); +SUNDIALS_EXPORT int IDASetMaxNumStepsB(void* ida_mem, int which, long int mxstepsB); -SUNDIALS_EXPORT int IDASetInitStepB(void *ida_mem, int which, realtype hinB); -SUNDIALS_EXPORT int IDASetMaxStepB(void *ida_mem, int which, realtype hmaxB); -SUNDIALS_EXPORT int IDASetSuppressAlgB(void *ida_mem, int which, - booleantype suppressalgB); -SUNDIALS_EXPORT int IDASetIdB(void *ida_mem, int which, N_Vector idB); -SUNDIALS_EXPORT int IDASetConstraintsB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetInitStepB(void* ida_mem, int which, sunrealtype hinB); +SUNDIALS_EXPORT int IDASetMaxStepB(void* ida_mem, int which, sunrealtype hmaxB); +SUNDIALS_EXPORT int IDASetSuppressAlgB(void* ida_mem, int which, + sunbooleantype suppressalgB); +SUNDIALS_EXPORT int IDASetIdB(void* ida_mem, int which, N_Vector idB); +SUNDIALS_EXPORT int IDASetConstraintsB(void* ida_mem, int which, N_Vector constraintsB); -SUNDIALS_EXPORT int IDASetQuadErrConB(void *ida_mem, int which, int errconQB); +SUNDIALS_EXPORT int IDASetQuadErrConB(void* ida_mem, int which, int errconQB); -SUNDIALS_EXPORT int IDASetNonlinearSolverB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetNonlinearSolverB(void* ida_mem, int which, SUNNonlinearSolver NLS); /* Extraction And Dense Output Functions For Backward Problems */ -SUNDIALS_EXPORT int IDAGetB(void* ida_mem, int which, realtype *tret, +SUNDIALS_EXPORT int IDAGetB(void* ida_mem, int which, sunrealtype* tret, N_Vector yy, N_Vector yp); -SUNDIALS_EXPORT int IDAGetQuadB(void *ida_mem, int which, - realtype *tret, N_Vector qB); +SUNDIALS_EXPORT int IDAGetQuadB(void* ida_mem, int which, sunrealtype* tret, + N_Vector qB); /* Optional Output Functions For Backward Problems */ -SUNDIALS_EXPORT void *IDAGetAdjIDABmem(void *ida_mem, int which); +SUNDIALS_EXPORT void* IDAGetAdjIDABmem(void* ida_mem, int which); -SUNDIALS_EXPORT int IDAGetConsistentICB(void *ida_mem, int which, - N_Vector yyB0, N_Vector ypB0); +SUNDIALS_EXPORT int IDAGetConsistentICB(void* ida_mem, int which, N_Vector yyB0, + N_Vector ypB0); -SUNDIALS_EXPORT int IDAGetAdjY(void *ida_mem, realtype t, - N_Vector yy, N_Vector yp); +SUNDIALS_EXPORT int IDAGetAdjY(void* ida_mem, sunrealtype t, N_Vector yy, + N_Vector yp); -typedef struct { - void *my_addr; - void *next_addr; - realtype t0; - realtype t1; +typedef struct +{ + void* my_addr; + void* next_addr; + sunrealtype t0; + sunrealtype t1; long int nstep; int order; - realtype step; + sunrealtype step; } IDAadjCheckPointRec; -SUNDIALS_EXPORT int IDAGetAdjCheckPointsInfo(void *ida_mem, - IDAadjCheckPointRec *ckpnt); +SUNDIALS_EXPORT int IDAGetAdjCheckPointsInfo(void* ida_mem, + IDAadjCheckPointRec* ckpnt); /* IDALS interface function that depends on IDAResFn */ -SUNDIALS_EXPORT int IDASetJacTimesResFnB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetJacTimesResFnB(void* ida_mem, int which, IDAResFn jtimesResFn); - /* Undocumented Optional Output Functions For Backward Problems */ /* ----------------------------------------------------------------- @@ -592,12 +584,12 @@ SUNDIALS_EXPORT int IDASetJacTimesResFnB(void *ida_mem, int which, * IDA_POLYNOMIAL, or IDA_SUCCESS otherwise. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int IDAGetAdjDataPointHermite(void *ida_mem, int which, - realtype *t, N_Vector yy, +SUNDIALS_EXPORT int IDAGetAdjDataPointHermite(void* ida_mem, int which, + sunrealtype* t, N_Vector yy, N_Vector yd); -SUNDIALS_EXPORT int IDAGetAdjDataPointPolynomial(void *ida_mem, int which, - realtype *t, int *order, +SUNDIALS_EXPORT int IDAGetAdjDataPointPolynomial(void* ida_mem, int which, + sunrealtype* t, int* order, N_Vector y); /* ----------------------------------------------------------------- @@ -605,8 +597,7 @@ SUNDIALS_EXPORT int IDAGetAdjDataPointPolynomial(void *ida_mem, int which, * Returns the address of the 'active' check point. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int IDAGetAdjCurrentCheckPoint(void *ida_mem, void **addr); - +SUNDIALS_EXPORT int IDAGetAdjCurrentCheckPoint(void* ida_mem, void** addr); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/idas/idas_bbdpre.h b/deps/AMICI/ThirdParty/sundials/include/idas/idas_bbdpre.h index 784314abd..47d5a8c27 100644 --- a/deps/AMICI/ThirdParty/sundials/include/idas/idas_bbdpre.h +++ b/deps/AMICI/ThirdParty/sundials/include/idas/idas_bbdpre.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh, Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,7 +22,7 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -32,34 +32,30 @@ extern "C" { /* User-supplied function Types */ -typedef int (*IDABBDLocalFn)(sunindextype Nlocal, realtype tt, - N_Vector yy, N_Vector yp, N_Vector gval, - void *user_data); +typedef int (*IDABBDLocalFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector gval, void* user_data); -typedef int (*IDABBDCommFn)(sunindextype Nlocal, realtype tt, - N_Vector yy, N_Vector yp, void *user_data); +typedef int (*IDABBDCommFn)(sunindextype Nlocal, sunrealtype tt, N_Vector yy, + N_Vector yp, void* user_data); /* Exported Functions */ -SUNDIALS_EXPORT int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, +SUNDIALS_EXPORT int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, sunindextype mudq, sunindextype mldq, sunindextype mukeep, sunindextype mlkeep, - realtype dq_rel_yy, - IDABBDLocalFn Gres, IDABBDCommFn Gcomm); + sunrealtype dq_rel_yy, IDABBDLocalFn Gres, + IDABBDCommFn Gcomm); -SUNDIALS_EXPORT int IDABBDPrecReInit(void *ida_mem, - sunindextype mudq, sunindextype mldq, - realtype dq_rel_yy); +SUNDIALS_EXPORT int IDABBDPrecReInit(void* ida_mem, sunindextype mudq, + sunindextype mldq, sunrealtype dq_rel_yy); /* Optional output functions */ -SUNDIALS_EXPORT int IDABBDPrecGetWorkSpace(void *ida_mem, - long int *lenrwBBDP, - long int *leniwBBDP); - -SUNDIALS_EXPORT int IDABBDPrecGetNumGfnEvals(void *ida_mem, - long int *ngevalsBBDP); +SUNDIALS_EXPORT int IDABBDPrecGetWorkSpace(void* ida_mem, long int* lenrwBBDP, + long int* leniwBBDP); +SUNDIALS_EXPORT int IDABBDPrecGetNumGfnEvals(void* ida_mem, + long int* ngevalsBBDP); /*------------------ BACKWARD PROBLEMS @@ -67,27 +63,25 @@ SUNDIALS_EXPORT int IDABBDPrecGetNumGfnEvals(void *ida_mem, /* User-Supplied Function Types */ -typedef int (*IDABBDLocalFnB)(sunindextype NlocalB, realtype tt, - N_Vector yy, N_Vector yp, - N_Vector yyB, N_Vector ypB, - N_Vector gvalB, void *user_dataB); +typedef int (*IDABBDLocalFnB)(sunindextype NlocalB, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector yyB, N_Vector ypB, + N_Vector gvalB, void* user_dataB); -typedef int (*IDABBDCommFnB)(sunindextype NlocalB, realtype tt, - N_Vector yy, N_Vector yp, - N_Vector yyB, N_Vector ypB, void *user_dataB); +typedef int (*IDABBDCommFnB)(sunindextype NlocalB, sunrealtype tt, N_Vector yy, + N_Vector yp, N_Vector yyB, N_Vector ypB, + void* user_dataB); /* Exported Functions */ -SUNDIALS_EXPORT int IDABBDPrecInitB(void *ida_mem, int which, sunindextype NlocalB, - sunindextype mudqB, sunindextype mldqB, - sunindextype mukeepB, sunindextype mlkeepB, - realtype dq_rel_yyB, +SUNDIALS_EXPORT int IDABBDPrecInitB(void* ida_mem, int which, + sunindextype NlocalB, sunindextype mudqB, + sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dq_rel_yyB, IDABBDLocalFnB GresB, IDABBDCommFnB GcommB); -SUNDIALS_EXPORT int IDABBDPrecReInitB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDABBDPrecReInitB(void* ida_mem, int which, sunindextype mudqB, sunindextype mldqB, - realtype dq_rel_yyB); - + sunrealtype dq_rel_yyB); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/idas/idas_direct.h b/deps/AMICI/ThirdParty/sundials/include/idas/idas_direct.h deleted file mode 100644 index 840a38425..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/idas/idas_direct.h +++ /dev/null @@ -1,70 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated direct linear solver interface in - * IDA; these routines now just wrap the updated IDA generic - * linear solver interface in idas_ls.h. - * -----------------------------------------------------------------*/ - -#ifndef _IDADLS_H -#define _IDADLS_H - -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - - -/*================================================================= - Function Types (typedefs for equivalent types in ida_ls.h) - =================================================================*/ - -typedef IDALsJacFn IDADlsJacFn; -typedef IDALsJacFnB IDADlsJacFnB; -typedef IDALsJacFnBS IDADlsJacFnBS; - -/*=================================================================== - Exported Functions (wrappers for equivalent routines in idas_ls.h) - ===================================================================*/ - -SUNDIALS_EXPORT int IDADlsSetLinearSolver(void *ida_mem, SUNLinearSolver LS, - SUNMatrix A); - -SUNDIALS_EXPORT int IDADlsSetJacFn(void *ida_mem, IDADlsJacFn jac); - -SUNDIALS_EXPORT int IDADlsGetWorkSpace(void *ida_mem, long int *lenrwLS, - long int *leniwLS); - -SUNDIALS_EXPORT int IDADlsGetNumJacEvals(void *ida_mem, long int *njevals); - -SUNDIALS_EXPORT int IDADlsGetNumResEvals(void *ida_mem, long int *nrevalsLS); - -SUNDIALS_EXPORT int IDADlsGetLastFlag(void *ida_mem, long int *flag); - -char *IDADlsGetReturnFlagName(long int flag); - -SUNDIALS_EXPORT int IDADlsSetLinearSolverB(void *ida_mem, int which, - SUNLinearSolver LS, SUNMatrix A); - -SUNDIALS_EXPORT int IDADlsSetJacFnB(void *ida_mem, int which, IDADlsJacFnB jacB); - -SUNDIALS_EXPORT int IDADlsSetJacFnBS(void *ida_mem, int which, IDADlsJacFnBS jacBS); - - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/idas/idas_ls.h b/deps/AMICI/ThirdParty/sundials/include/idas/idas_ls.h index 18d10e9ec..bfd9003aa 100644 --- a/deps/AMICI/ThirdParty/sundials/include/idas/idas_ls.h +++ b/deps/AMICI/ThirdParty/sundials/include/idas/idas_ls.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -24,30 +24,28 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /*================================================================= IDALS Constants =================================================================*/ -#define IDALS_SUCCESS 0 -#define IDALS_MEM_NULL -1 -#define IDALS_LMEM_NULL -2 -#define IDALS_ILL_INPUT -3 -#define IDALS_MEM_FAIL -4 -#define IDALS_PMEM_NULL -5 -#define IDALS_JACFUNC_UNRECVR -6 -#define IDALS_JACFUNC_RECVR -7 -#define IDALS_SUNMAT_FAIL -8 -#define IDALS_SUNLS_FAIL -9 +#define IDALS_SUCCESS 0 +#define IDALS_MEM_NULL -1 +#define IDALS_LMEM_NULL -2 +#define IDALS_ILL_INPUT -3 +#define IDALS_MEM_FAIL -4 +#define IDALS_PMEM_NULL -5 +#define IDALS_JACFUNC_UNRECVR -6 +#define IDALS_JACFUNC_RECVR -7 +#define IDALS_SUNMAT_FAIL -8 +#define IDALS_SUNLS_FAIL -9 /* Return values for the adjoint module */ -#define IDALS_NO_ADJ -101 -#define IDALS_LMEMB_NULL -102 - +#define IDALS_NO_ADJ -101 +#define IDALS_LMEMB_NULL -102 /*================================================================= Forward problems @@ -57,87 +55,69 @@ extern "C" { IDALS user-supplied function prototypes =================================================================*/ -typedef int (*IDALsJacFn)(realtype t, realtype 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); - -typedef int (*IDALsPrecSetupFn)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector rr, - realtype c_j, void *user_data); - -typedef int (*IDALsPrecSolveFn)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector rr, - N_Vector rvec, N_Vector zvec, - realtype c_j, realtype delta, - void *user_data); - -typedef int (*IDALsJacTimesSetupFn)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector rr, - realtype c_j, void *user_data); - -typedef int (*IDALsJacTimesVecFn)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector rr, - N_Vector v, N_Vector Jv, - realtype c_j, void *user_data, - N_Vector tmp1, N_Vector tmp2); +typedef 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); +typedef int (*IDALsPrecSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, void* user_data); + +typedef int (*IDALsPrecSolveFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector rvec, N_Vector zvec, + sunrealtype c_j, sunrealtype delta, + void* user_data); + +typedef int (*IDALsJacTimesSetupFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, + void* user_data); + +typedef int (*IDALsJacTimesVecFn)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, N_Vector v, N_Vector Jv, + sunrealtype c_j, void* user_data, + N_Vector tmp1, N_Vector tmp2); /*================================================================= IDALS Exported functions =================================================================*/ -SUNDIALS_EXPORT int IDASetLinearSolver(void *ida_mem, - SUNLinearSolver LS, +SUNDIALS_EXPORT int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A); - /*----------------------------------------------------------------- Optional inputs to the IDALS linear solver interface -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int IDASetJacFn(void *ida_mem, IDALsJacFn jac); -SUNDIALS_EXPORT int IDASetPreconditioner(void *ida_mem, - IDALsPrecSetupFn pset, +SUNDIALS_EXPORT int IDASetJacFn(void* ida_mem, IDALsJacFn jac); +SUNDIALS_EXPORT int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn pset, IDALsPrecSolveFn psolve); -SUNDIALS_EXPORT int IDASetJacTimes(void *ida_mem, - IDALsJacTimesSetupFn jtsetup, +SUNDIALS_EXPORT int IDASetJacTimes(void* ida_mem, IDALsJacTimesSetupFn jtsetup, IDALsJacTimesVecFn jtimes); -SUNDIALS_EXPORT int IDASetEpsLin(void *ida_mem, realtype eplifac); -SUNDIALS_EXPORT int IDASetLSNormFactor(void *ida_mem, - realtype nrmfac); -SUNDIALS_EXPORT int IDASetLinearSolutionScaling(void *ida_mem, - booleantype onoff); -SUNDIALS_EXPORT int IDASetIncrementFactor(void *ida_mem, - realtype dqincfac); +SUNDIALS_EXPORT int IDASetEpsLin(void* ida_mem, sunrealtype eplifac); +SUNDIALS_EXPORT int IDASetLSNormFactor(void* ida_mem, sunrealtype nrmfac); +SUNDIALS_EXPORT int IDASetLinearSolutionScaling(void* ida_mem, + sunbooleantype onoff); +SUNDIALS_EXPORT int IDASetIncrementFactor(void* ida_mem, sunrealtype dqincfac); /*----------------------------------------------------------------- Optional outputs from the IDALS linear solver interface -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int IDAGetLinWorkSpace(void *ida_mem, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int IDAGetNumJacEvals(void *ida_mem, - long int *njevals); -SUNDIALS_EXPORT int IDAGetNumPrecEvals(void *ida_mem, - long int *npevals); -SUNDIALS_EXPORT int IDAGetNumPrecSolves(void *ida_mem, - long int *npsolves); -SUNDIALS_EXPORT int IDAGetNumLinIters(void *ida_mem, - long int *nliters); -SUNDIALS_EXPORT int IDAGetNumLinConvFails(void *ida_mem, - long int *nlcfails); -SUNDIALS_EXPORT int IDAGetNumJTSetupEvals(void *ida_mem, - long int *njtsetups); -SUNDIALS_EXPORT int IDAGetNumJtimesEvals(void *ida_mem, - long int *njvevals); -SUNDIALS_EXPORT int IDAGetNumLinResEvals(void *ida_mem, - long int *nrevalsLS); -SUNDIALS_EXPORT int IDAGetLastLinFlag(void *ida_mem, - long int *flag); -SUNDIALS_EXPORT char *IDAGetLinReturnFlagName(long int flag); - +SUNDIALS_EXPORT int IDAGetJac(void* ida_mem, SUNMatrix* J); +SUNDIALS_EXPORT int IDAGetJacCj(void* ida_mem, sunrealtype* cj_J); +SUNDIALS_EXPORT int IDAGetJacTime(void* ida_mem, sunrealtype* t_J); +SUNDIALS_EXPORT int IDAGetJacNumSteps(void* ida_mem, long int* nst_J); +SUNDIALS_EXPORT int IDAGetLinWorkSpace(void* ida_mem, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT int IDAGetNumJacEvals(void* ida_mem, long int* njevals); +SUNDIALS_EXPORT int IDAGetNumPrecEvals(void* ida_mem, long int* npevals); +SUNDIALS_EXPORT int IDAGetNumPrecSolves(void* ida_mem, long int* npsolves); +SUNDIALS_EXPORT int IDAGetNumLinIters(void* ida_mem, long int* nliters); +SUNDIALS_EXPORT int IDAGetNumLinConvFails(void* ida_mem, long int* nlcfails); +SUNDIALS_EXPORT int IDAGetNumJTSetupEvals(void* ida_mem, long int* njtsetups); +SUNDIALS_EXPORT int IDAGetNumJtimesEvals(void* ida_mem, long int* njvevals); +SUNDIALS_EXPORT int IDAGetNumLinResEvals(void* ida_mem, long int* nrevalsLS); +SUNDIALS_EXPORT int IDAGetLastLinFlag(void* ida_mem, long int* flag); +SUNDIALS_EXPORT char* IDAGetLinReturnFlagName(long int flag); /*================================================================= Backward problems @@ -147,80 +127,65 @@ SUNDIALS_EXPORT char *IDAGetLinReturnFlagName(long int flag); IDALS user-supplied function prototypes =================================================================*/ -typedef int (*IDALsJacFnB)(realtype tt, realtype c_jB, N_Vector yy, +typedef int (*IDALsJacFnB)(sunrealtype tt, sunrealtype c_jB, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, - N_Vector rrB, SUNMatrix JacB, - void *user_dataB, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); + N_Vector rrB, SUNMatrix JacB, void* user_dataB, + N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); -typedef int (*IDALsJacFnBS)(realtype tt, realtype c_jB, N_Vector yy, - N_Vector yp, N_Vector *yS, N_Vector *ypS, +typedef int (*IDALsJacFnBS)(sunrealtype tt, sunrealtype c_jB, N_Vector yy, + N_Vector yp, N_Vector* yS, N_Vector* ypS, N_Vector yyB, N_Vector ypB, N_Vector rrB, - SUNMatrix JacB, void *user_dataB, - N_Vector tmp1B, N_Vector tmp2B, - N_Vector tmp3B); - -typedef int (*IDALsPrecSetupFnB)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *user_dataB); - -typedef int (*IDALsPrecSetupFnBS)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector *yyS, - N_Vector *ypS, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *user_dataB); - -typedef int (*IDALsPrecSolveFnB)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector rvecB, N_Vector zvecB, - realtype c_jB, realtype deltaB, - void *user_dataB); - -typedef int (*IDALsPrecSolveFnBS)(realtype tt, N_Vector yy, - N_Vector yp, N_Vector *yyS, - N_Vector *ypS, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector rvecB, N_Vector zvecB, - realtype c_jB, realtype deltaB, - void *user_dataB); - -typedef int (*IDALsJacTimesSetupFnB)(realtype t, N_Vector yy, - N_Vector yp, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *user_dataB); - -typedef int (*IDALsJacTimesSetupFnBS)(realtype t, N_Vector yy, - N_Vector yp, N_Vector *yyS, - N_Vector *ypS, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *user_dataB); - -typedef int (*IDALsJacTimesVecFnB)(realtype t, N_Vector yy, - N_Vector yp, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector vB, N_Vector JvB, - realtype c_jB, void *user_dataB, - N_Vector tmp1B, N_Vector tmp2B); - -typedef int (*IDALsJacTimesVecFnBS)(realtype t, N_Vector yy, - N_Vector yp, N_Vector *yyS, - N_Vector *ypS, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector vB, N_Vector JvB, - realtype c_jB, void *user_dataB, - N_Vector tmp1B, N_Vector tmp2B); - + SUNMatrix JacB, void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B); + +typedef int (*IDALsPrecSetupFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsPrecSetupFnBS)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, sunrealtype c_jB, + void* user_dataB); + +typedef int (*IDALsPrecSolveFnB)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + N_Vector rvecB, N_Vector zvecB, sunrealtype c_jB, + sunrealtype deltaB, void* user_dataB); + +typedef int (*IDALsPrecSolveFnBS)(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, N_Vector rvecB, + N_Vector zvecB, sunrealtype c_jB, + sunrealtype deltaB, void* user_dataB); + +typedef int (*IDALsJacTimesSetupFnB)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsJacTimesSetupFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + sunrealtype c_jB, void* user_dataB); + +typedef int (*IDALsJacTimesVecFnB)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector yyB, N_Vector ypB, N_Vector rrB, + N_Vector vB, N_Vector JvB, sunrealtype c_jB, + void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B); + +typedef int (*IDALsJacTimesVecFnBS)(sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector* yyS, N_Vector* ypS, N_Vector yyB, + N_Vector ypB, N_Vector rrB, N_Vector vB, + N_Vector JvB, sunrealtype c_jB, + void* user_dataB, N_Vector tmp1B, + N_Vector tmp2B); /*================================================================= IDALS Exported functions =================================================================*/ -SUNDIALS_EXPORT int IDASetLinearSolverB(void *ida_mem, - int which, - SUNLinearSolver LS, - SUNMatrix A); +SUNDIALS_EXPORT int IDASetLinearSolverB(void* ida_mem, int which, + SUNLinearSolver LS, SUNMatrix A); /*----------------------------------------------------------------- Each IDASet***B or IDASet***BS function below links the @@ -229,33 +194,29 @@ SUNDIALS_EXPORT int IDASetLinearSolverB(void *ida_mem, The 'which' argument is the int returned by IDACreateB. -----------------------------------------------------------------*/ -SUNDIALS_EXPORT int IDASetJacFnB(void *ida_mem, int which, - IDALsJacFnB jacB); -SUNDIALS_EXPORT int IDASetJacFnBS(void *ida_mem, int which, - IDALsJacFnBS jacBS); - -SUNDIALS_EXPORT int IDASetEpsLinB(void *ida_mem, int which, - realtype eplifacB); -SUNDIALS_EXPORT int IDASetLSNormFactorB(void *ida_mem, int which, - realtype nrmfacB); -SUNDIALS_EXPORT int IDASetLinearSolutionScalingB(void *ida_mem, int which, - booleantype onoffB); -SUNDIALS_EXPORT int IDASetIncrementFactorB(void *ida_mem, int which, - realtype dqincfacB); -SUNDIALS_EXPORT int IDASetPreconditionerB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetJacFnB(void* ida_mem, int which, IDALsJacFnB jacB); +SUNDIALS_EXPORT int IDASetJacFnBS(void* ida_mem, int which, IDALsJacFnBS jacBS); + +SUNDIALS_EXPORT int IDASetEpsLinB(void* ida_mem, int which, sunrealtype eplifacB); +SUNDIALS_EXPORT int IDASetLSNormFactorB(void* ida_mem, int which, + sunrealtype nrmfacB); +SUNDIALS_EXPORT int IDASetLinearSolutionScalingB(void* ida_mem, int which, + sunbooleantype onoffB); +SUNDIALS_EXPORT int IDASetIncrementFactorB(void* ida_mem, int which, + sunrealtype dqincfacB); +SUNDIALS_EXPORT int IDASetPreconditionerB(void* ida_mem, int which, IDALsPrecSetupFnB psetB, IDALsPrecSolveFnB psolveB); -SUNDIALS_EXPORT int IDASetPreconditionerBS(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetPreconditionerBS(void* ida_mem, int which, IDALsPrecSetupFnBS psetBS, IDALsPrecSolveFnBS psolveBS); -SUNDIALS_EXPORT int IDASetJacTimesB(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetJacTimesB(void* ida_mem, int which, IDALsJacTimesSetupFnB jtsetupB, IDALsJacTimesVecFnB jtimesB); -SUNDIALS_EXPORT int IDASetJacTimesBS(void *ida_mem, int which, +SUNDIALS_EXPORT int IDASetJacTimesBS(void* ida_mem, int which, IDALsJacTimesSetupFnBS jtsetupBS, IDALsJacTimesVecFnBS jtimesBS); - #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/include/idas/idas_spils.h b/deps/AMICI/ThirdParty/sundials/include/idas/idas_spils.h deleted file mode 100644 index ee3175d8c..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/idas/idas_spils.h +++ /dev/null @@ -1,111 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated Scaled, Preconditioned Iterative - * Linear Solver interface in IDAS; these routines now just wrap - * the updated IDA generic linear solver interface in idas_ls.h. - * -----------------------------------------------------------------*/ - -#ifndef _IDASSPILS_H -#define _IDASSPILS_H - -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - - -/*=============================================================== - Function Types (typedefs for equivalent types in idas_ls.h) - ===============================================================*/ - -typedef IDALsPrecSetupFn IDASpilsPrecSetupFn; -typedef IDALsPrecSolveFn IDASpilsPrecSolveFn; -typedef IDALsJacTimesSetupFn IDASpilsJacTimesSetupFn; -typedef IDALsJacTimesVecFn IDASpilsJacTimesVecFn; -typedef IDALsPrecSetupFnB IDASpilsPrecSetupFnB; -typedef IDALsPrecSetupFnBS IDASpilsPrecSetupFnBS; -typedef IDALsPrecSolveFnB IDASpilsPrecSolveFnB; -typedef IDALsPrecSolveFnBS IDASpilsPrecSolveFnBS; -typedef IDALsJacTimesSetupFnB IDASpilsJacTimesSetupFnB; -typedef IDALsJacTimesSetupFnBS IDASpilsJacTimesSetupFnBS; -typedef IDALsJacTimesVecFnB IDASpilsJacTimesVecFnB; -typedef IDALsJacTimesVecFnBS IDASpilsJacTimesVecFnBS; - -/*==================================================================== - Exported Functions (wrappers for equivalent routines in idas_ls.h) - ====================================================================*/ - -SUNDIALS_EXPORT int IDASpilsSetLinearSolver(void *ida_mem, SUNLinearSolver LS); - -SUNDIALS_EXPORT int IDASpilsSetPreconditioner(void *ida_mem, IDASpilsPrecSetupFn pset, - IDASpilsPrecSolveFn psolve); - -SUNDIALS_EXPORT int IDASpilsSetJacTimes(void *ida_mem, IDASpilsJacTimesSetupFn jtsetup, - IDASpilsJacTimesVecFn jtimes); - -SUNDIALS_EXPORT int IDASpilsSetEpsLin(void *ida_mem, realtype eplifac); - -SUNDIALS_EXPORT int IDASpilsSetIncrementFactor(void *ida_mem, realtype dqincfac); - -SUNDIALS_EXPORT int IDASpilsGetWorkSpace(void *ida_mem, long int *lenrwLS, long int *leniwLS); - -SUNDIALS_EXPORT int IDASpilsGetNumPrecEvals(void *ida_mem, long int *npevals); - -SUNDIALS_EXPORT int IDASpilsGetNumPrecSolves(void *ida_mem, long int *npsolves); - -SUNDIALS_EXPORT int IDASpilsGetNumLinIters(void *ida_mem, long int *nliters); - -SUNDIALS_EXPORT int IDASpilsGetNumConvFails(void *ida_mem, long int *nlcfails); - -SUNDIALS_EXPORT int IDASpilsGetNumJTSetupEvals(void *ida_mem, long int *njtsetups); - -SUNDIALS_EXPORT int IDASpilsGetNumJtimesEvals(void *ida_mem, long int *njvevals); - -SUNDIALS_EXPORT int IDASpilsGetNumResEvals(void *ida_mem, long int *nrevalsLS); - -SUNDIALS_EXPORT int IDASpilsGetLastFlag(void *ida_mem, long int *flag); - -SUNDIALS_EXPORT char *IDASpilsGetReturnFlagName(long int flag); - -SUNDIALS_EXPORT int IDASpilsSetLinearSolverB(void *ida_mem, int which, - SUNLinearSolver LS); - -SUNDIALS_EXPORT int IDASpilsSetEpsLinB(void *ida_mem, int which, realtype eplifacB); - -SUNDIALS_EXPORT int IDASpilsSetIncrementFactorB(void *ida_mem, int which, - realtype dqincfacB); - -SUNDIALS_EXPORT int IDASpilsSetPreconditionerB(void *ida_mem, int which, - IDASpilsPrecSetupFnB psetB, - IDASpilsPrecSolveFnB psolveB); - -SUNDIALS_EXPORT int IDASpilsSetPreconditionerBS(void *ida_mem, int which, - IDASpilsPrecSetupFnBS psetBS, - IDASpilsPrecSolveFnBS psolveBS); - -SUNDIALS_EXPORT int IDASpilsSetJacTimesB(void *ida_mem, int which, - IDASpilsJacTimesSetupFnB jtsetupB, - IDASpilsJacTimesVecFnB jtimesB); - -SUNDIALS_EXPORT int IDASpilsSetJacTimesBS(void *ida_mem, int which, - IDASpilsJacTimesSetupFnBS jtsetupBS, - IDASpilsJacTimesVecFnBS jtimesBS); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/nvector/nvector_serial.h b/deps/AMICI/ThirdParty/sundials/include/nvector/nvector_serial.h index 646bde1d8..988e090af 100644 --- a/deps/AMICI/ThirdParty/sundials/include/nvector/nvector_serial.h +++ b/deps/AMICI/ThirdParty/sundials/include/nvector/nvector_serial.h @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,11 +20,11 @@ * - The definition of the generic N_Vector structure can be found * in the header file sundials_nvector.h. * - * - The definition of the type 'realtype' can be found in the + * - The definition of the type 'sunrealtype' can be found in the * header file sundials_types.h, and it may be changed (at the * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition - * for the type 'booleantype'. + * for the type 'sunbooleantype'. * * - N_Vector arguments to arithmetic vector operations need not * be distinct. For example, the following call: @@ -41,7 +41,7 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -51,13 +51,14 @@ extern "C" { * ----------------------------------------------------------------- */ -struct _N_VectorContent_Serial { - sunindextype length; /* vector length */ - booleantype own_data; /* data ownership flag */ - realtype *data; /* data array */ +struct _N_VectorContent_Serial +{ + sunindextype length; /* vector length */ + sunbooleantype own_data; /* data ownership flag */ + sunrealtype* data; /* data array */ }; -typedef struct _N_VectorContent_Serial *N_VectorContent_Serial; +typedef struct _N_VectorContent_Serial* N_VectorContent_Serial; /* * ----------------------------------------------------------------- @@ -66,15 +67,15 @@ typedef struct _N_VectorContent_Serial *N_VectorContent_Serial; * ----------------------------------------------------------------- */ -#define NV_CONTENT_S(v) ( (N_VectorContent_Serial)(v->content) ) +#define NV_CONTENT_S(v) ((N_VectorContent_Serial)(v->content)) -#define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) +#define NV_LENGTH_S(v) (NV_CONTENT_S(v)->length) -#define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data ) +#define NV_OWN_DATA_S(v) (NV_CONTENT_S(v)->own_data) -#define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) +#define NV_DATA_S(v) (NV_CONTENT_S(v)->data) -#define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) +#define NV_Ith_S(v, i) (NV_DATA_S(v)[i]) /* * ----------------------------------------------------------------- @@ -82,93 +83,162 @@ typedef struct _N_VectorContent_Serial *N_VectorContent_Serial; * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNew_Serial(sunindextype vec_length); +SUNDIALS_EXPORT +N_Vector N_VNewEmpty_Serial(sunindextype vec_length, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VNewEmpty_Serial(sunindextype vec_length); +SUNDIALS_EXPORT +N_Vector N_VNew_Serial(sunindextype vec_length, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VMake_Serial(sunindextype vec_length, realtype *v_data); +SUNDIALS_EXPORT +N_Vector N_VMake_Serial(sunindextype vec_length, sunrealtype* v_data, + SUNContext sunctx); -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w); +SUNDIALS_EXPORT +sunindextype N_VGetLength_Serial(N_Vector v); -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w); +SUNDIALS_EXPORT +void N_VPrint_Serial(N_Vector v); -SUNDIALS_EXPORT void N_VDestroyVectorArray_Serial(N_Vector* vs, int count); +SUNDIALS_EXPORT +void N_VPrintFile_Serial(N_Vector v, FILE* outfile); -SUNDIALS_EXPORT sunindextype N_VGetLength_Serial(N_Vector v); +SUNDIALS_EXPORT +N_Vector_ID N_VGetVectorID_Serial(N_Vector v); -SUNDIALS_EXPORT void N_VPrint_Serial(N_Vector v); +SUNDIALS_EXPORT +N_Vector N_VCloneEmpty_Serial(N_Vector w); -SUNDIALS_EXPORT void N_VPrintFile_Serial(N_Vector v, FILE *outfile); +SUNDIALS_EXPORT +N_Vector N_VClone_Serial(N_Vector w); -SUNDIALS_EXPORT N_Vector_ID N_VGetVectorID_Serial(N_Vector v); -SUNDIALS_EXPORT N_Vector N_VCloneEmpty_Serial(N_Vector w); -SUNDIALS_EXPORT N_Vector N_VClone_Serial(N_Vector w); -SUNDIALS_EXPORT void N_VDestroy_Serial(N_Vector v); -SUNDIALS_EXPORT void N_VSpace_Serial(N_Vector v, sunindextype *lrw, sunindextype *liw); -SUNDIALS_EXPORT realtype *N_VGetArrayPointer_Serial(N_Vector v); -SUNDIALS_EXPORT void N_VSetArrayPointer_Serial(realtype *v_data, N_Vector v); +SUNDIALS_EXPORT +void N_VDestroy_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VSpace_Serial(N_Vector v, sunindextype* lrw, sunindextype* liw); + +SUNDIALS_EXPORT +sunrealtype* N_VGetArrayPointer_Serial(N_Vector v); + +SUNDIALS_EXPORT +void N_VSetArrayPointer_Serial(sunrealtype* v_data, N_Vector v); /* standard vector operations */ -SUNDIALS_EXPORT void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VConst_Serial(realtype c, N_Vector z); -SUNDIALS_EXPORT void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VScale_Serial(realtype c, N_Vector x, N_Vector z); -SUNDIALS_EXPORT void N_VAbs_Serial(N_Vector x, N_Vector z); -SUNDIALS_EXPORT void N_VInv_Serial(N_Vector x, N_Vector z); -SUNDIALS_EXPORT void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z); -SUNDIALS_EXPORT realtype N_VDotProd_Serial(N_Vector x, N_Vector y); -SUNDIALS_EXPORT realtype N_VMaxNorm_Serial(N_Vector x); -SUNDIALS_EXPORT realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id); -SUNDIALS_EXPORT realtype N_VMin_Serial(N_Vector x); -SUNDIALS_EXPORT realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VL1Norm_Serial(N_Vector x); -SUNDIALS_EXPORT void N_VCompare_Serial(realtype c, N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VInvTest_Serial(N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); -SUNDIALS_EXPORT realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); +SUNDIALS_EXPORT +void N_VLinearSum_Serial(sunrealtype a, N_Vector x, sunrealtype b, N_Vector y, + N_Vector z); +SUNDIALS_EXPORT +void N_VConst_Serial(sunrealtype c, N_Vector z); + +SUNDIALS_EXPORT +void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); + +SUNDIALS_EXPORT +void N_VScale_Serial(sunrealtype c, N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAbs_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VInv_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +void N_VAddConst_Serial(N_Vector x, sunrealtype b, N_Vector z); + +SUNDIALS_EXPORT +sunrealtype N_VDotProd_Serial(N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +sunrealtype N_VMaxNorm_Serial(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id); + +SUNDIALS_EXPORT +sunrealtype N_VMin_Serial(N_Vector x); + +SUNDIALS_EXPORT +sunrealtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VL1Norm_Serial(N_Vector x); + +SUNDIALS_EXPORT +void N_VCompare_Serial(sunrealtype c, N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +sunbooleantype N_VInvTest_Serial(N_Vector x, N_Vector z); + +SUNDIALS_EXPORT +sunbooleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); + +SUNDIALS_EXPORT +sunrealtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); /* fused vector operations */ -SUNDIALS_EXPORT int N_VLinearCombination_Serial(int nvec, realtype* c, N_Vector* V, - N_Vector z); -SUNDIALS_EXPORT int N_VScaleAddMulti_Serial(int nvec, realtype* a, N_Vector x, - N_Vector* Y, N_Vector* Z); -SUNDIALS_EXPORT int N_VDotProdMulti_Serial(int nvec, N_Vector x, - N_Vector* Y, realtype* dotprods); +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombination_Serial(int nvec, sunrealtype* c, N_Vector* V, + N_Vector z); +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMulti_Serial(int nvec, sunrealtype* a, N_Vector x, + N_Vector* Y, N_Vector* Z); +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMulti_Serial(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); /* vector array operations */ -SUNDIALS_EXPORT int N_VLinearSumVectorArray_Serial(int nvec, - realtype a, N_Vector* X, - realtype b, N_Vector* Y, - N_Vector* Z); -SUNDIALS_EXPORT int N_VScaleVectorArray_Serial(int nvec, realtype* c, - N_Vector* X, N_Vector* Z); -SUNDIALS_EXPORT int N_VConstVectorArray_Serial(int nvecs, realtype c, - N_Vector* Z); -SUNDIALS_EXPORT int N_VWrmsNormVectorArray_Serial(int nvecs, N_Vector* X, - N_Vector* W, realtype* nrm); -SUNDIALS_EXPORT int N_VWrmsNormMaskVectorArray_Serial(int nvecs, N_Vector* X, - N_Vector* W, N_Vector id, - realtype* nrm); -SUNDIALS_EXPORT int N_VScaleAddMultiVectorArray_Serial(int nvec, int nsum, - realtype* a, - N_Vector* X, - N_Vector** Y, - N_Vector** Z); -SUNDIALS_EXPORT int N_VLinearCombinationVectorArray_Serial(int nvec, int nsum, - realtype* c, - N_Vector** X, - N_Vector* Z); +SUNDIALS_EXPORT +SUNErrCode N_VLinearSumVectorArray_Serial(int nvec, sunrealtype a, N_Vector* X, + sunrealtype b, N_Vector* Y, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleVectorArray_Serial(int nvec, sunrealtype* c, N_Vector* X, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VConstVectorArray_Serial(int nvecs, sunrealtype c, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormVectorArray_Serial(int nvecs, N_Vector* X, N_Vector* W, + sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormMaskVectorArray_Serial(int nvecs, N_Vector* X, N_Vector* W, + N_Vector id, sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMultiVectorArray_Serial(int nvec, int nsum, + sunrealtype* a, N_Vector* X, + N_Vector** Y, N_Vector** Z); + +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombinationVectorArray_Serial(int nvec, int nsum, + sunrealtype* c, N_Vector** X, + N_Vector* Z); /* OPTIONAL local reduction kernels (no parallel communication) */ -SUNDIALS_EXPORT realtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VWSqrSumMaskLocal_Serial(N_Vector x, N_Vector w, N_Vector id); +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w); + +SUNDIALS_EXPORT +sunrealtype N_VWSqrSumMaskLocal_Serial(N_Vector x, N_Vector w, N_Vector id); /* OPTIONAL XBraid interface operations */ -SUNDIALS_EXPORT int N_VBufSize_Serial(N_Vector x, sunindextype *size); -SUNDIALS_EXPORT int N_VBufPack_Serial(N_Vector x, void *buf); -SUNDIALS_EXPORT int N_VBufUnpack_Serial(N_Vector x, void *buf); +SUNDIALS_EXPORT +SUNErrCode N_VBufSize_Serial(N_Vector x, sunindextype* size); + +SUNDIALS_EXPORT +SUNErrCode N_VBufPack_Serial(N_Vector x, void* buf); + +SUNDIALS_EXPORT +SUNErrCode N_VBufUnpack_Serial(N_Vector x, void* buf); /* * ----------------------------------------------------------------- @@ -176,19 +246,40 @@ SUNDIALS_EXPORT int N_VBufUnpack_Serial(N_Vector x, void *buf); * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int N_VEnableFusedOps_Serial(N_Vector v, booleantype tf); +SUNDIALS_EXPORT +SUNErrCode N_VEnableFusedOps_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearCombination_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleAddMulti_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableDotProdMulti_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearSumVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableConstVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormVectorArray_Serial(N_Vector v, sunbooleantype tf); + +SUNDIALS_EXPORT +SUNErrCode N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, sunbooleantype tf); -SUNDIALS_EXPORT int N_VEnableLinearCombination_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableScaleAddMulti_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableDotProdMulti_Serial(N_Vector v, booleantype tf); +SUNDIALS_EXPORT +SUNErrCode N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, + sunbooleantype tf); -SUNDIALS_EXPORT int N_VEnableLinearSumVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableScaleVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableConstVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableWrmsNormVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, booleantype tf); -SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, booleantype tf); +SUNDIALS_EXPORT +SUNErrCode N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, + sunbooleantype tf); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_imexgus.h b/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_imexgus.h new file mode 100644 index 000000000..7235bec0a --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_imexgus.h @@ -0,0 +1,88 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This is the header file for the SUNAdaptController_ImExGus module. + * -----------------------------------------------------------------*/ + +#ifndef _SUNADAPTCONTROLLER_IMEXGUS_H +#define _SUNADAPTCONTROLLER_IMEXGUS_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------- + * ImEx Gustafsson implementation of SUNAdaptController + * ---------------------------------------------------- */ + +struct _SUNAdaptControllerContent_ImExGus +{ + sunrealtype k1i; /* internal controller parameters */ + sunrealtype k2i; + sunrealtype k1e; + sunrealtype k2e; + sunrealtype bias; /* error bias factor */ + sunrealtype ep; /* error from previous step */ + sunrealtype hp; /* previous step size */ + sunbooleantype firststep; /* flag indicating first step */ +}; + +typedef struct _SUNAdaptControllerContent_ImExGus* SUNAdaptControllerContent_ImExGus; + +/* ------------------ + * Exported Functions + * ------------------ */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, + sunrealtype k1e, sunrealtype k2e, + sunrealtype k1i, sunrealtype k2i); +SUNDIALS_EXPORT +SUNAdaptController_Type SUNAdaptController_GetType_ImExGus(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, + sunrealtype bias); +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space_ImExGus(SUNAdaptController C, + long int* lenrw, long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNADAPTCONTROLLER_IMEXGUS_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_soderlind.h b/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_soderlind.h new file mode 100644 index 000000000..898e8be11 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sunadaptcontroller/sunadaptcontroller_soderlind.h @@ -0,0 +1,132 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This is the header file for the SUNAdaptController_Soderlind + * module. + * -----------------------------------------------------------------*/ + +#ifndef _SUNADAPTCONTROLLER_SODERLIND_H +#define _SUNADAPTCONTROLLER_SODERLIND_H + +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------- + * Soderlind implementation of SUNAdaptController + * ---------------------------------------------------- */ + +struct _SUNAdaptControllerContent_Soderlind +{ + sunrealtype k1; /* internal controller parameters */ + sunrealtype k2; + sunrealtype k3; + sunrealtype k4; + sunrealtype k5; + sunrealtype bias; /* error bias factor */ + sunrealtype ep; /* error from previous step */ + sunrealtype epp; /* error from 2 steps ago */ + sunrealtype hp; /* previous step size */ + sunrealtype hpp; /* step size from 2 steps ago */ + int firststeps; /* flag to handle first few steps */ +}; + +typedef struct _SUNAdaptControllerContent_Soderlind* SUNAdaptControllerContent_Soderlind; + +/* ------------------ + * Exported Functions + * ------------------ */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, + sunrealtype k1, sunrealtype k2, + sunrealtype k3, sunrealtype k4, + sunrealtype k5); + +SUNDIALS_EXPORT +SUNAdaptController_Type SUNAdaptController_GetType_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, + sunrealtype bias); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, + sunrealtype h, sunrealtype dsm); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space_Soderlind(SUNAdaptController C, + long int* lenrw, long int* leniw); + +/* Convenience routines to construct subsidiary controllers */ + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_PID(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, + sunrealtype k2, sunrealtype k3); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_PI(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, + sunrealtype k2); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_I(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); + +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNADAPTCONTROLLER_SODERLIND_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/README_AMICI.md b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/README_AMICI.md new file mode 100644 index 000000000..cce87b90d --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/README_AMICI.md @@ -0,0 +1,4 @@ +This directory contains include files that are required for the Matlab-based installation without CMake. +Normally, those files would be generated by CMake. We can't add them to the other includes, because they +would be found before the CMake-generated ones. Then, they will either not work on some systems, or they +would disable some features we'd want. diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_config.h b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_config.h new file mode 100644 index 000000000..0287cb948 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_config.h @@ -0,0 +1,291 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS configuration header file. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONFIG_H +#define _SUNDIALS_CONFIG_H + +#include "sundials/sundials_export.h" + +/* Indicates that the function will not report an error via last_err, + a return code. In C++, it is just defined as noexcept. */ +#if defined(__cplusplus) +#define SUNDIALS_NOEXCEPT noexcept +#else +#define SUNDIALS_NOEXCEPT +#endif + +#ifndef SUNDIALS_DEPRECATED_MSG +# define SUNDIALS_DEPRECATED_MSG(msg) __attribute__ ((__deprecated__(msg))) +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT_MSG +# define SUNDIALS_DEPRECATED_EXPORT_MSG(msg) SUNDIALS_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT_MSG +# define SUNDIALS_DEPRECATED_NO_EXPORT_MSG(msg) SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +/* ------------------------------------------------------------------ + * Define SUNDIALS version numbers + * -----------------------------------------------------------------*/ + + +#define SUNDIALS_VERSION "7.1.1" +#define SUNDIALS_VERSION_MAJOR 7 +#define SUNDIALS_VERSION_MINOR 1 +#define SUNDIALS_VERSION_PATCH 1 +#define SUNDIALS_VERSION_LABEL "" +#define SUNDIALS_GIT_VERSION "" + + +/* ------------------------------------------------------------------ + * SUNDIALS build information + * -----------------------------------------------------------------*/ + +#define SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME +/* #undef SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME */ +/* #undef SUNDIALS_C_COMPILER_HAS_ASSUME */ +/* #define SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED */ + +/* Define precision of SUNDIALS data type 'sunrealtype' + * Depending on the precision level, one of the following + * three macros will be defined: + * #define SUNDIALS_SINGLE_PRECISION 1 + * #define SUNDIALS_DOUBLE_PRECISION 1 + * #define SUNDIALS_EXTENDED_PRECISION 1 + */ +#define SUNDIALS_DOUBLE_PRECISION 1 + +/* Define type of vector indices in SUNDIALS 'sunindextype'. + * Depending on user choice of index type, one of the following + * two macros will be defined: + * #define SUNDIALS_INT64_T 1 + * #define SUNDIALS_INT32_T 1 + */ +#define SUNDIALS_INT64_T 1 + +/* Define the type of vector indices in SUNDIALS 'sunindextype'. + * The macro will be defined with a type of the appropriate size. + */ +#define SUNDIALS_INDEX_TYPE int64_t + +/* Use POSIX timers if available. + * #define SUNDIALS_HAVE_POSIX_TIMERS + */ +#define SUNDIALS_HAVE_POSIX_TIMERS + +/* BUILD CVODE with fused kernel functionality */ +/* #undef SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS */ + +/* BUILD SUNDIALS with monitoring functionalities */ +/* #undef SUNDIALS_BUILD_WITH_MONITORING */ + +/* BUILD SUNDIALS with profiling functionalities */ +/* #undef SUNDIALS_BUILD_WITH_PROFILING */ + +/* Enable error checking within SUNDIALS */ +/* #undef SUNDIALS_ENABLE_ERROR_CHECKS */ + +/* BUILD SUNDIALS with logging functionalities */ +#define SUNDIALS_LOGGING_LEVEL 2 + +/* Build metadata */ +#define SUN_C_COMPILER "GNU" +#define SUN_C_COMPILER_VERSION "13.2.0" +#define SUN_C_COMPILER_FLAGS "" + +#define SUN_CXX_COMPILER "" +#define SUN_CXX_COMPILER_VERSION "" +#define SUN_CXX_COMPILER_FLAGS "" + +#define SUN_FORTRAN_COMPILER "" +#define SUN_FORTRAN_COMPILER_VERSION "" +#define SUN_FORTRAN_COMPILER_FLAGS "" + +#define SUN_BUILD_TYPE "RelWithDebInfo" + +#define SUN_JOB_ID "20240927133023" +#define SUN_JOB_START_TIME "20240927133023" + +#define SUN_TPL_LIST "KLU" +#define SUN_TPL_LIST_SIZE "" + +#define SUNDIALS_SPACK_VERSION "" + +/* ------------------------------------------------------------------ + * SUNDIALS TPL macros + * -----------------------------------------------------------------*/ + +/* Caliper */ +/* #undef SUNDIALS_CALIPER_ENABLED */ + +/* Adiak */ +/* #undef SUNDIALS_ADIAK_ENABLED */ + +/* Ginkgo */ +/* #undef SUNDIALS_GINKGO_ENABLED */ +#define SUN_GINKGO_VERSION "" + +/* HYPRE */ +/* #undef SUNDIALS_HYPRE_ENABLED */ +#define SUN_HYPRE_VERSION "" + +/* KLU */ +#define SUNDIALS_KLU_ENABLED +#define SUN_KLU_VERSION "" + +/* KOKKOS */ +/* #undef SUNDIALS_KOKKOS_ENABLED */ +#define SUN_KOKKOS_VERSION "" + +/* KOKKOS_KERNELS */ +/* #undef SUNDIALS_KOKKOS_KERNELS_ENABLED */ +#define SUN_KOKKOS_KERNELS_VERSION "" + +/* LAPACK */ +/* #undef SUNDIALS_BLAS_LAPACK_ENABLED */ +#define SUN_LAPACK_VERSION "" + +/* MAGMA */ +/* #undef SUNDIALS_MAGMA_ENABLED */ +#define SUN_MAGMA_VERSION "" + +/* MPI */ +#define SUN_MPI_C_COMPILER "" +#define SUN_MPI_C_VERSION "" + +#define SUN_MPI_CXX_COMPILER "" +#define SUN_MPI_CXX_VERSION "" + +#define SUN_MPI_FORTRAN_COMPILER "" +#define SUN_MPI_FORTRAN_VERSION "" + +/* ONEMKL */ +/* #undef SUNDIALS_ONEMKL_ENABLED */ +#define SUN_ONEMKL_VERSION "" + +/* OpenMP */ +/* #undef SUNDIALS_OPENMP_ENABLED */ +#define SUN_OPENMP_VERSION "" + +/* PETSC */ +/* #undef SUNDIALS_PETSC_ENABLED */ +#define SUN_PETSC_VERSION "" + +/* PTHREADS */ +/* #undef SUNDIALS_PTHREADS_ENABLED */ +#define SUN_PTHREADS_VERSION "" + +/* RAJA */ +/* #undef SUNDIALS_RAJA_ENABLED */ +#define SUN_RAJA_VERSION "" + +/* SUPERLUDIST */ +/* #undef SUNDIALS_SUPERLUDIST_ENABLED */ +#define SUN_SUPERLUDIST_VERSION "" + +/* SUPERLUMT */ +/* #undef SUNDIALS_SUPERLUMT_ENABLED */ +#define SUN_SUPERLUMT_VERSION "" + +/* TRILLINOS */ +/* #undef SUNDIALS_TRILLINOS_ENABLED */ +#define SUN_TRILLINOS_VERSION "" + +/* XBRAID */ +/* #undef SUNDIALS_XBRAID_ENABLED */ +#define SUN_XBRAID_VERSION "" + +/* RAJA backends */ +/* #undef SUNDIALS_RAJA_BACKENDS_CUDA */ +/* #undef SUNDIALS_RAJA_BACKENDS_HIP */ +/* #undef SUNDIALS_RAJA_BACKENDS_SYCL */ + +/* Ginkgo backends */ +/* #undef SUNDIALS_GINKGO_BACKENDS_CUDA */ +/* #undef SUNDIALS_GINKGO_BACKENDS_HIP */ +/* #undef SUNDIALS_GINKGO_BACKENDS_OMP */ +/* #undef SUNDIALS_GINKGO_BACKENDS_REF */ +/* #undef SUNDIALS_GINKGO_BACKENDS_SYCL */ + +/* MAGMA backends */ +/* #undef SUNDIALS_MAGMA_BACKENDS_CUDA */ +/* #undef SUNDIALS_MAGMA_BACKENDS_HIP */ + +/* Set if SUNDIALS is built with MPI support, then + * #define SUNDIALS_MPI_ENABLED 1 + * otherwise + * #define SUNDIALS_MPI_ENABLED 0 + */ +#define SUNDIALS_MPI_ENABLED 0 + +/* oneMKL interface options */ +/* #undef SUNDIALS_ONEMKL_USE_GETRF_LOOP */ +/* #undef SUNDIALS_ONEMKL_USE_GETRS_LOOP */ + +/* SUPERLUMT threading type */ +#define SUNDIALS_SUPERLUMT_THREAD_TYPE "" + +/* Trilinos with MPI is available, then + * #define SUNDIALS_TRILINOS_HAVE_MPI + */ +/* #undef SUNDIALS_TRILINOS_HAVE_MPI */ + + +/* ------------------------------------------------------------------ + * SUNDIALS language macros + * -----------------------------------------------------------------*/ + +/* CUDA */ +/* #undef SUNDIALS_CUDA_ENABLED */ +#define SUN_CUDA_VERSION "" +#define SUN_CUDA_COMPILER "" +#define SUN_CUDA_ARCHITECTURES "" + +/* HIP */ +/* #undef SUNDIALS_HIP_ENABLED */ +#define SUN_HIP_VERSION "" +#define SUN_AMDGPU_TARGETS "" + +/* SYCL options */ +/* #undef SUNDIALS_SYCL_2020_UNSUPPORTED */ + + +/* ------------------------------------------------------------------ + * SUNDIALS modules enabled + * -----------------------------------------------------------------*/ + +#define SUNDIALS_CVODES 1 +#define SUNDIALS_IDAS 1 +#define SUNDIALS_NVECTOR_SERIAL 1 +#define SUNDIALS_SUNMATRIX_BAND 1 +#define SUNDIALS_SUNMATRIX_DENSE 1 +#define SUNDIALS_SUNMATRIX_SPARSE 1 +#define SUNDIALS_SUNLINSOL_BAND 1 +#define SUNDIALS_SUNLINSOL_DENSE 1 +#define SUNDIALS_SUNLINSOL_PCG 1 +#define SUNDIALS_SUNLINSOL_SPBCGS 1 +#define SUNDIALS_SUNLINSOL_SPFGMR 1 +#define SUNDIALS_SUNLINSOL_SPGMR 1 +#define SUNDIALS_SUNLINSOL_SPTFQMR 1 +#define SUNDIALS_SUNLINSOL_KLU 1 +#define SUNDIALS_SUNNONLINSOL_NEWTON 1 +#define SUNDIALS_SUNNONLINSOL_FIXEDPOINT 1 + + +#endif /* _SUNDIALS_CONFIG_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_export.h b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_export.h similarity index 70% rename from deps/AMICI/ThirdParty/sundials/include/sundials/sundials_export.h rename to deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_export.h index 5ad995643..77eece4eb 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_export.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/amici_matlab/sundials/sundials_export.h @@ -7,28 +7,22 @@ # define SUNDIALS_NO_EXPORT #else # ifndef SUNDIALS_EXPORT -# ifdef sundials_generic_EXPORTS +# ifdef sundials_core_EXPORTS /* We are building this library */ -# define SUNDIALS_EXPORT +# define SUNDIALS_EXPORT # else /* We are using this library */ -# define SUNDIALS_EXPORT +# define SUNDIALS_EXPORT # endif # endif # ifndef SUNDIALS_NO_EXPORT -# define SUNDIALS_NO_EXPORT +# define SUNDIALS_NO_EXPORT # endif #endif #ifndef SUNDIALS_DEPRECATED -/* BEGIN changed for AMICI */ -# ifdef __GNUC__ -# define SUNDIALS_DEPRECATED __attribute__ ((__deprecated__)) -# else -# define SUNDIALS_DEPRECATED -# endif -/* END changed for AMICI */ +# define SUNDIALS_DEPRECATED __attribute__ ((__deprecated__)) #endif #ifndef SUNDIALS_DEPRECATED_EXPORT @@ -39,6 +33,7 @@ # define SUNDIALS_DEPRECATED_NO_EXPORT SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED #endif +/* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */ #if 0 /* DEFINE_NO_DEPRECATED */ # ifndef SUNDIALS_NO_DEPRECATED # define SUNDIALS_NO_DEPRECATED diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_context_impl.h b/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_context_impl.h new file mode 100644 index 000000000..1281333ce --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_context_impl.h @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This is a 'private' header file and should not be used in user + * code. It is subject to change without warning. + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ----------------------------------------------------------------- + * SUNDIALS context class implementation. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_IMPL_H +#define _SUNDIALS_CONTEXT_IMPL_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +struct SUNContext_ +{ + SUNProfiler profiler; + sunbooleantype own_profiler; + SUNLogger logger; + sunbooleantype own_logger; + SUNErrCode last_err; + SUNErrHandler err_handler; + SUNComm comm; +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_errors_impl.h b/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_errors_impl.h new file mode 100644 index 000000000..115b5eefd --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/priv/sundials_errors_impl.h @@ -0,0 +1,557 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This is a 'private' header file and should not be used in user + * code. It is subject to change without warning. + * !!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ----------------------------------------------------------------- + * Contains all error checking macros and private error handling API. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ERRORS_IMPL_H +#define _SUNDIALS_ERRORS_IMPL_H + +#include + +#include "sundials/sundials_config.h" +#include "sundials/sundials_context.h" +#include "sundials/sundials_export.h" +#include "sundials/sundials_logger.h" +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ---------------------------------------------------------------------------- + * Macros used in error handling + * ---------------------------------------------------------------------------*/ + +/* ------------------------------------------------------------------ + * SUNDIALS __builtin_expect related macros. + * These macros provide hints to the compiler that the condition + * is typically false (or true) which may allow the compiler to + * optimize. + * -----------------------------------------------------------------*/ + +/* Hint to the compiler that the branch is unlikely to be taken */ +#ifdef SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNHintFalse(cond) __builtin_expect((cond), 0) +#else +#define SUNHintFalse(cond) (cond) +#endif + +/* Hint to the compiler that the branch is likely to be taken */ +#ifdef SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#define SUNHintTrue(cond) __builtin_expect((cond), 1) +#else +#define SUNHintTrue(cond) (cond) +#endif + +/* ------------------------------------------------------------------ + * SUNAssume + * + * This macro tells the compiler that the condition should be assumed + * to be true. The consequence is that what happens if the assumption + * is violated is undefined. If there is not compiler support for + * assumptions, then we dont do anything as there is no reliable + * way to avoid the condition being executed in all cases (such as + * the condition being an opaque function call, which we have a lot of). + * -----------------------------------------------------------------*/ + +#if __cplusplus >= 202302L +#define SUNAssume(...) [[assume(__VA_ARGS__)]] +#elif defined(SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME) +#define SUNAssume(...) __attribute__((assume(__VA_ARGS__))) +#elif defined(SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME) +#define SUNAssume(...) __builtin_assume(__VA_ARGS__) +#elif defined(SUNDIALS_C_COMPILER_HAS_ASSUME) +#define SUNAssume(...) __assume(__VA_ARGS__) +#else +#define SUNAssume(...) +#endif + +/* ---------------------------------------------------------------------------- + * SUNErrHandler_ definition. + * ---------------------------------------------------------------------------*/ + +struct SUNErrHandler_ +{ + SUNErrHandler previous; /* next error handler to call (singly linked-list) */ + SUNErrHandlerFn call; + void* data; +}; + +/* + This function creates a new SUNErrHandler object which is a node in a + singly linked-lis of error handlers. + + :param eh_fn: An error handler callback function + :param eh_data: A pointer that will be passed back to the error handler + callback function + :param eh_out: The new SUNErrHandler object + + :return: A SUNErrCode indicating success or failure +*/ +SUNDIALS_EXPORT +SUNErrCode SUNErrHandler_Create(SUNErrHandlerFn eh_fn, void* eh_data, + SUNErrHandler* eh_out); + +/* + This function destroys and frees the memory for the given SUNErrHandler + object. + + :param eh: A pointer to a SUNErrHandler object + + :return: void +*/ +SUNDIALS_EXPORT +void SUNErrHandler_Destroy(SUNErrHandler* eh); + +/* + This function will print an error out to stderr. It is used as a fallback + when the SUNContext is NULL or corrupt. It should not be used otherwise. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msg: a message associated with the error + :param args: the arguments to be provided to the format message + + :return: void +*/ +SUNDIALS_EXPORT +void SUNGlobalFallbackErrHandler(int line, const char* func, const char* file, + const char* msgfmt, SUNErrCode code, ...); + +/* + This function calls the error handlers registered with the SUNContext + with the provided message. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msgfmt: a message associated with the error with formatting + :param code: the SUNErrCode for the error + :param sunctx: a valid SUNContext object + + :return: void +*/ +static inline void SUNHandleErrWithMsg(int line, const char* func, + const char* file, const char* msg, + SUNErrCode code, SUNContext sunctx) +{ + if (!sunctx) { SUNGlobalFallbackErrHandler(line, func, file, msg, code); } + + sunctx->last_err = code; + SUNErrHandler eh = sunctx->err_handler; + while (eh != NULL) + { + eh->call(line, func, file, msg, code, eh->data, sunctx); + eh = eh->previous; + } +} + +/* + This function calls the error handlers registered with the SUNContext + with the provided format message. + + :param line: the line number of the error + :param func: the function in which the error occurred + :param file: the file in which the error occurred + :param msgfmt: a message associated with the error with formatting + :param code: the SUNErrCode for the error + :param sunctx: a valid SUNContext object + :param args: the arguments to be provided to the format message + + :return: void +*/ +static inline void SUNHandleErrWithFmtMsg(int line, const char* func, + const char* file, const char* msgfmt, + SUNErrCode code, SUNContext sunctx, ...) +{ + size_t msglen; + char* msg; + va_list values; + va_start(values, sunctx); + msglen = (size_t)vsnprintf(NULL, (size_t)0, msgfmt, values); /* determine size + of buffer + needed */ + msg = (char*)malloc(msglen + 1); + vsnprintf(msg, msglen + 1, msgfmt, values); + SUNHandleErrWithMsg(line, func, file, msg, code, sunctx); + va_end(values); + free(msg); +} + +/* + The SUNCTX_ macro expands to the name of the local SUNContext object + defined by SUNFunctionBegin. SUNCTX_ should be used to reference the + SUNContext inside of SUNDIALS functions. + */ +#define SUNCTX_ sunctx_local_scope_ + +/* + The SUNFunctionBegin macro is used to declare the local SUNContext object to + be used a function. It should be used at the start of every SUNDIALS + functions. + + :param sunctx: the SUNContext to set the local SUNContext variable to + */ +#define SUNFunctionBegin(sunctx) \ + SUNContext SUNCTX_ = sunctx; \ + (void)SUNCTX_ + +/* ---------------------------------------------------------------------------- + * SUNCheck* family of error checking macros + * + * We define several different versions of SUNCheck* macros to cover various + * programming scenarios. + * + * SUNCheckCall* macros are used to check SUNDIALS function calls that + * return a SUNErrCode. + * + * SUNCheckLastErr* macros are used to check SUNDIALS function calls that + * do not return a SUNErrCode. + * ---------------------------------------------------------------------------*/ + +/* + SUNCheck evaluates the given expression and calls the error handler if it is + false. It should be used to check expressions that do not imply stringent + assumptions. If the expression should be strictly assumed as true, then use + SUNAssert instead. + + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheck(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return code; \ + } \ + } \ + while (0) +#else +#define SUNCheck(expr, code) +#endif + +/* + SUNCheckNoRet is the same as SUNCheck but *does not return from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckNoRet(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + } \ + } \ + while (0) +#else +#define SUNCheckNoRet(expr, code) +#endif + +/* + SUNCheckNull is the same as SUNCheck but *returns NULL from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckNull(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return NULL; \ + } \ + } \ + while (0) +#else +#define SUNCheckNull(expr, code) +#endif + +/* + SUNCheckNull is the same as SUNCheck but *returns void from the caller*. + Use SUNAssert macros to check for conditions that do not make sense e.g., + to check if malloc returned NULL. + + :param expr: an expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckVoid(expr, code) \ + do { \ + if (SUNHintFalse(!(expr))) \ + { \ + SUNHandleErrWithFmtMsg(__LINE__, __func__, __FILE__, "expected %s", \ + code, SUNCTX_, #expr); \ + return; \ + } \ + } \ + while (0) +#else +#define SUNCheckVoid(expr, code) +#endif + +/* + SUNCheckCallMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then return the error code**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return sun_chk_call_err_code_; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNoRetMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, and call the error handler. **It does not return**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallNoRetMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + } \ + } \ + while (0) +#else +#define SUNCheckCallNoRetMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns NULL**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallNullMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return NULL; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallNullMsg(call, msg) (void)call +#endif + +/* + SUNCheckCallNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns void**. + + :param call: the function call + :param msg: an error message +*/ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckCallVoidMsg(call, msg) \ + do { \ + SUNErrCode sun_chk_call_err_code_ = call; \ + if (SUNHintFalse(sun_chk_call_err_code_ < 0)) \ + { \ + SUNHandleErrWithMsg(__LINE__, __func__, __FILE__, msg, \ + sun_chk_call_err_code_, SUNCTX_); \ + return; \ + } \ + } \ + while (0) +#else +#define SUNCheckCallVoidMsg(call, msg) (void)call +#endif + +/* These versions of SUNCheckCall do not take a custom message so a + default message associated with the error code will be used. */ +#define SUNCheckCall(call) SUNCheckCallMsg(call, NULL) +#define SUNCheckCallNoRet(call) SUNCheckCallNoRetMsg(call, NULL) +#define SUNCheckCallNull(call) SUNCheckCallNullMsg(call, NULL) +#define SUNCheckCallVoid(call) SUNCheckCallVoidMsg(call, NULL) + +/* SUNCheckLastErrMsg checks the last_err value in the SUNContext. + If an error occured, then it will log the error, set the last_err + value, and call the error handler, **and then returns the code**. */ +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNCheckLastErrMsg(msg) \ + do { \ + SUNCheckCallMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrNoRetMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler. **It does not return.** + + :param msg: an error message +*/ +#define SUNCheckLastErrNoRetMsg(msg) \ + do { \ + SUNCheckCallNoRetMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrNullMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns NULL**. + + :param msg: an error message +*/ +#define SUNCheckLastErrNullMsg(msg) \ + do { \ + SUNCheckCallNullMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) + +/* + SUNCheckLastErrVoidMsg performs the SUNDIALS function call, and checks the + returned error code. If an error occured, then it will log the error, set the + last_err value, call the error handler, **and then returns void**. + + :param msg: an error message +*/ +#define SUNCheckLastErrVoidMsg(msg) \ + do { \ + SUNCheckCallVoidMsg(SUNContext_PeekLastError(SUNCTX_), msg); \ + } \ + while (0) +#else +#define SUNCheckLastErrNoRetMsg(msg) +#define SUNCheckLastErrMsg(msg) +#define SUNCheckLastErrVoidMsg(msg) +#define SUNCheckLastErrNullMsg(msg) +#endif + +/* These versions of SUNCheckLastErr do not take a custom message so the + default message associated with the error code will be used. */ +#define SUNCheckLastErr() SUNCheckLastErrMsg(NULL) +#define SUNCheckLastErrNoRet() SUNCheckLastErrNoRetMsg(NULL) +#define SUNCheckLastErrVoid() SUNCheckLastErrVoidMsg(NULL) +#define SUNCheckLastErrNull() SUNCheckLastErrNullMsg(NULL) + +/* + SUNAssert checks if an expression is true. It expands to SUNCheck in debug + builds othewrise we try to expand it to an assumption, if the compiler + supports assumptions, so that the compiler can make optimizations based on the + assumption. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssert(expr, code) SUNCheck(expr, code) +#else +#define SUNAssert(expr, code) +#endif + +/* + SUNAssertNoRet is the same as SUNAssert but it does not return from the + caller. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertNoRet(expr, code) SUNCheckNoRet(expr, code) +#else +#define SUNAssertNoRet(expr, code) +#endif + +/* + SUNAssertNull is the same as SUNAssert but it *returns NULL from the caller*. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertNull(expr, code) SUNCheckNull(expr, code) +#else +#define SUNAssertNull(expr, code) +#endif + +/* + SUNAssertVoid is the same as SUNAssert but it *returns void from the caller*. + + :param expr: a expression to evaluate as true or false + :param code: the error code to pass to the error handler if the expression is + false +*/ + +#if defined(SUNDIALS_ENABLE_ERROR_CHECKS) +#define SUNAssertVoid(expr, code) SUNCheckVoid(expr, code) +#else +#define SUNAssertVoid(expr, code) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_ERRORS_IMPL_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_adaptcontroller.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_adaptcontroller.h new file mode 100644 index 000000000..b27d7c73c --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_adaptcontroller.h @@ -0,0 +1,157 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS accuracy-based adaptivity controller class. These + * objects estimate step sizes for time integration methods such + * that the next step solution should satisfy a desired temporal + * accuracy. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ADAPTCONTROLLER_H +#define _SUNDIALS_ADAPTCONTROLLER_H + +#include +#include +#include + +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ----------------------------------------------------------------- + * SUNAdaptController types (currently, only "H" is implemented; + * others are planned): + * NONE - empty controller (does nothing) + * H - controls a single-rate step size + * ----------------------------------------------------------------- */ + +typedef enum +{ + SUN_ADAPTCONTROLLER_NONE, + SUN_ADAPTCONTROLLER_H +} SUNAdaptController_Type; + +/* ----------------------------------------------------------------- + * Generic definition of SUNAdaptController + * ----------------------------------------------------------------- */ + +/* Forward reference for pointer to SUNAdaptController_Ops object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNAdaptController_Ops* SUNAdaptController_Ops; + +/* Forward reference for pointer to SUNAdaptController object */ +typedef _SUNDIALS_STRUCT_ _generic_SUNAdaptController* SUNAdaptController; + +/* Structure containing function pointers to controller operations */ +struct _generic_SUNAdaptController_Ops +{ + /* REQUIRED of all controller implementations. */ + SUNAdaptController_Type (*gettype)(SUNAdaptController C); + + /* REQUIRED for controllers of SUN_ADAPTCONTROLLER_H type. */ + SUNErrCode (*estimatestep)(SUNAdaptController C, sunrealtype h, int p, + sunrealtype dsm, sunrealtype* hnew); + + /* OPTIONAL for all SUNAdaptController implementations. */ + SUNErrCode (*destroy)(SUNAdaptController C); + SUNErrCode (*reset)(SUNAdaptController C); + SUNErrCode (*setdefaults)(SUNAdaptController C); + SUNErrCode (*write)(SUNAdaptController C, FILE* fptr); + SUNErrCode (*seterrorbias)(SUNAdaptController C, sunrealtype bias); + SUNErrCode (*updateh)(SUNAdaptController C, sunrealtype h, sunrealtype dsm); + SUNErrCode (*space)(SUNAdaptController C, long int* lenrw, long int* leniw); +}; + +/* A SUNAdaptController is a structure with an implementation-dependent + 'content' field, and a pointer to a structure of + operations corresponding to that implementation. */ +struct _generic_SUNAdaptController +{ + void* content; + SUNAdaptController_Ops ops; + SUNContext sunctx; +}; + +/* ----------------------------------------------------------------- + * Functions exported by SUNAdaptController module + * ----------------------------------------------------------------- */ + +/* Function to create an empty SUNAdaptController data structure. */ +SUNDIALS_EXPORT +SUNAdaptController SUNAdaptController_NewEmpty(SUNContext sunctx); + +/* Function to free a generic SUNAdaptController (assumes content is already empty) */ +SUNDIALS_EXPORT +void SUNAdaptController_DestroyEmpty(SUNAdaptController C); + +/* Function to report the type of a SUNAdaptController object. */ +SUNDIALS_EXPORT +SUNAdaptController_Type SUNAdaptController_GetType(SUNAdaptController C); + +/* Function to deallocate a SUNAdaptController object. + + Any return value other than SUN_SUCCESS will be treated as + an unrecoverable failure. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C); + +/* Main step size controller function. This is called following + a time step with size 'h' and local error factor 'dsm', and the + controller should estimate 'hnew' so that the ensuing step + will have 'dsm' value JUST BELOW 1. + + Any return value other than SUN_SUCCESS will be treated as + an unrecoverable failure. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, + int p, sunrealtype dsm, + sunrealtype* hnew); + +/* Function to reset the controller to its initial state, e.g., if + it stores a small number of previous dsm or step size values. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Reset(SUNAdaptController C); + +/* Function to set the controller parameters to their default values. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C); + +/* Function to write all controller parameters to the indicated file + pointer. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Write(SUNAdaptController C, FILE* fptr); + +/* Function to set an error bias factor to use for scaling the local error + 'dsm' factors above. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, + sunrealtype bias); + +/* Function to notify a controller of type SUN_ADAPTCONTROLLER_H that + a successful time step was taken with stepsize h and local error factor + dsm, indicating that these can be saved for subsequent controller functions. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, + sunrealtype dsm); + +/* Function to return the memory requirements of the controller object. */ +SUNDIALS_EXPORT +SUNErrCode SUNAdaptController_Space(SUNAdaptController C, long int* lenrw, + long int* leniw); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_ADAPTCONTROLLER_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_band.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_band.h index 1d244452b..9860acfa5 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_band.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_band.h @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -12,13 +12,13 @@ * SUNDIALS Copyright End * ----------------------------------------------------------------- * This is the header file for a generic BAND linear solver - * package, based on the DlsMat type defined in sundials_direct.h. + * package, based on the SUNDlsMat type defined in sundials_direct.h. * * There are two sets of band solver routines listed in - * this file: one set uses type DlsMat defined below and the - * other set uses the type realtype ** for band matrix arguments. - * Routines that work with the type DlsMat begin with "Band". - * Routines that work with realtype ** begin with "band". + * this file: one set uses type SUNDlsMat defined below and the + * other set uses the type sunrealtype ** for band matrix arguments. + * Routines that work with the type SUNDlsMat begin with "Band". + * Routines that work with sunrealtype ** begin with "band". * -----------------------------------------------------------------*/ #ifndef _SUNDIALS_BAND_H @@ -26,18 +26,18 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* * ----------------------------------------------------------------- - * Function : BandGBTRF + * Function: SUNDlsMat_BandGBTRF * ----------------------------------------------------------------- - * Usage : ier = BandGBTRF(A, p); + * Usage : ier = SUNDlsMat_BandGBTRF(A, p); * if (ier != 0) ... A is singular * ----------------------------------------------------------------- - * BandGBTRF performs the LU factorization of the N by N band + * SUNDlsMat_BandGBTRF performs the LU factorization of the N by N band * matrix A. This is done using standard Gaussian elimination * with partial pivoting. * @@ -45,7 +45,7 @@ extern "C" { * pivot array p with the following information: * * (1) p[k] contains the row number of the pivot element chosen - * at the beginning of elimination step k, k=0, 1, ..., N-1. + * at the beginning of elimination step k, k = 0, 1, ..., N-1. * * (2) If the unique LU factorization of A is given by PA = LU, * where P is a permutation matrix, L is a lower triangular @@ -54,7 +54,7 @@ extern "C" { * (including its diagonal) contains U and the strictly lower * triangular part of A contains the multipliers, I-L. * - * BandGBTRF returns 0 if successful. Otherwise it encountered + * SUNDlsMat_BandGBTRF returns 0 if successful. Otherwise it encountered * a zero diagonal element during the factorization. In this case * it returns the column index (numbered from one) at which * it encountered the zero. @@ -68,111 +68,124 @@ extern "C" { * call A = BandAllocMat(N,mu,ml,smu), where mu, ml, and smu are * as defined above. The user does not have to zero the "extra" * storage allocated for the purpose of factorization. This will - * handled by the BandGBTRF routine. + * handled by the SUNDlsMat_BandGBTRF routine. * - * BandGBTRF is only a wrapper around bandGBTRF. All work is done - * in bandGBTRF, which works directly on the data in the DlsMat A - * (i.e. in the field A->cols). + * SUNDlsMat_BandGBTRF is only a wrapper around SUNDlsMat_bandGBTRF. + * All work is done in SUNDlsMat_bandGBTRF, which works directly on the + * data in the SUNDlsMat A (i.e. in the field A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype BandGBTRF(DlsMat A, sunindextype *p); -SUNDIALS_EXPORT sunindextype bandGBTRF(realtype **a, sunindextype n, - sunindextype mu, sunindextype ml, - sunindextype smu, sunindextype *p); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_BandGBTRF(SUNDlsMat A, sunindextype* p); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_bandGBTRF(sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, + sunindextype smu, sunindextype* p); /* * ----------------------------------------------------------------- - * Function : BandGBTRS + * Function: SUNDlsMat_BandGBTRS * ----------------------------------------------------------------- - * Usage : BandGBTRS(A, p, b); + * Usage: SUNDlsMat_BandGBTRS(A, p, b); * ----------------------------------------------------------------- - * BandGBTRS solves the N-dimensional system A x = b using - * the LU factorization in A and the pivot information in p - * computed in BandGBTRF. The solution x is returned in b. This - * routine cannot fail if the corresponding call to BandGBTRF - * did not fail. + * SUNDlsMat_BandGBTRS solves the N-dimensional system A x = b using + * the LU factorization in A and the pivot information in p computed + * in SUNDlsMat_BandGBTRF. The solution x is returned in b. This + * routine cannot fail if the corresponding call to + * SUNDlsMat_BandGBTRF did not fail. * - * BandGBTRS is only a wrapper around bandGBTRS which does all the - * work directly on the data in the DlsMat A (i.e. in A->cols). + * SUNDlsMat_BandGBTRS is only a wrapper around SUNDlsMat_bandGBTRS + * which does all the work directly on the data in the DlsMat A (i.e. + * in A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandGBTRS(DlsMat A, sunindextype *p, realtype *b); -SUNDIALS_EXPORT void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, - sunindextype ml, sunindextype *p, realtype *b); +SUNDIALS_EXPORT +void SUNDlsMat_BandGBTRS(SUNDlsMat A, sunindextype* p, sunrealtype* b); + +SUNDIALS_EXPORT +void SUNDlsMat_bandGBTRS(sunrealtype** a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype* p, sunrealtype* b); /* * ----------------------------------------------------------------- - * Function : BandCopy + * Function: SUNDlsMat_BandCopy * ----------------------------------------------------------------- - * Usage : BandCopy(A, B, copymu, copyml); + * Usage: SUNDlsMat_BandCopy(A, B, copymu, copyml); * ----------------------------------------------------------------- - * BandCopy copies the submatrix with upper and lower bandwidths - * copymu, copyml of the N by N band matrix A into the N by N - * band matrix B. + * SUNDlsMat_BandCopy copies the submatrix with upper and lower + * bandwidths copymu, copyml of the N by N band matrix A into the N by + * N band matrix B. * - * BandCopy is a wrapper around bandCopy which accesses the data - * in the DlsMat A and DlsMat B (i.e. the fields cols). + * SUNDlsMat_BandCopy is a wrapper around SUNDlsMat_bandCopy which + * accesses the data in the DlsMat A and DlsMat B (i.e. the fields + * cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandCopy(DlsMat A, DlsMat B, sunindextype copymu, - sunindextype copyml); -SUNDIALS_EXPORT void bandCopy(realtype **a, realtype **b, sunindextype n, - sunindextype a_smu, sunindextype b_smu, - sunindextype copymu, sunindextype copyml); +SUNDIALS_EXPORT +void SUNDlsMat_BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, + sunindextype copyml); +SUNDIALS_EXPORT +void SUNDlsMat_bandCopy(sunrealtype** a, sunrealtype** b, sunindextype n, + sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml); /* * ----------------------------------------------------------------- - * Function: BandScale + * Function: SUNDlsMat_BandScale * ----------------------------------------------------------------- - * Usage : BandScale(c, A); + * Usage: SUNDlsMat_BandScale(c, A); * ----------------------------------------------------------------- - * A(i,j) <- c*A(i,j), j-(A->mu) <= i <= j+(A->ml). + * A(i,j) <- c*A(i,j), j-(A->mu) < = i < = j+(A->ml). * - * BandScale is a wrapper around bandScale which performs the actual - * scaling by accessing the data in the DlsMat A (i.e. the field - * A->cols). + * SUNDlsMat_BandScale is a wrapper around SUNDlsMat_bandScale which + * performs the actual scaling by accessing the data in the + * SUNDlsMat A (i.e. the field A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandScale(realtype c, DlsMat A); -SUNDIALS_EXPORT void bandScale(realtype c, realtype **a, sunindextype n, - sunindextype mu, sunindextype ml, - sunindextype smu); +void SUNDlsMat_BandScale(sunrealtype c, SUNDlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_bandScale(sunrealtype c, sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu); /* * ----------------------------------------------------------------- - * Function: bandAddIdentity + * Function: SUNDlsMat_bandAddIdentity * ----------------------------------------------------------------- - * bandAddIdentity adds the identity matrix to the n-by-n matrix - * stored in the realtype** arrays. + * SUNDlsMat_bandAddIdentity adds the identity matrix to the n-by-n + * matrix stored in the sunrealtype** arrays. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void bandAddIdentity(realtype **a, sunindextype n, - sunindextype smu); - +void SUNDlsMat_bandAddIdentity(sunrealtype** a, sunindextype n, sunindextype smu); /* * ----------------------------------------------------------------- - * Function: BandMatvec + * Function: SUNDlsMat_BandMatvec * ----------------------------------------------------------------- - * BandMatvec computes the matrix-vector product y = A*x, where A - * is an M-by-N band matrix, x is a vector of length N, and y is a - * vector of length M. No error checking is performed on the length - * of the arrays x and y. Only y is modified in this routine. + * SUNDlsMat_BandMatvec computes the matrix-vector product y = A*x, + * where A is an M-by-N band matrix, x is a vector of length N, and y + * is a vector of length M. No error checking is performed on the + * length of the arrays x and y. Only y is modified in this routine. * - * BandMatvec is a wrapper around bandMatvec which performs the - * actual product by accessing the data in the DlsMat A. + * SUNDlsMat_BandMatvec is a wrapper around SUNDlsMat_bandMatvec which + * performs the actual product by accessing the data in the SUNDlsMat + * A. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandMatvec(DlsMat A, realtype *x, realtype *y); -SUNDIALS_EXPORT void bandMatvec(realtype **a, realtype *x, realtype *y, - sunindextype n, sunindextype mu, - sunindextype ml, sunindextype smu); +SUNDIALS_EXPORT +void SUNDlsMat_BandMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y); + +SUNDIALS_EXPORT +void SUNDlsMat_bandMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, + sunindextype n, sunindextype mu, sunindextype ml, + sunindextype smu); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_base.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_base.hpp new file mode 100644 index 000000000..9a43da93f --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_base.hpp @@ -0,0 +1,151 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * Base classes for C++ implementations of SUNDIALS objects and wrappers (views) + * of SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_BASE_HPP +#define _SUNDIALS_BASE_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { + +// +// Common base class for C++ implementations of SUNDIALS data structures. +// +template +class BaseObject +{ +public: + BaseObject() = default; + + BaseObject(SUNContext sunctx) + : sunctx_(sunctx), + object_(std::make_unique()), + object_ops_(std::make_unique()) + { + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + } + + // Move constructor + BaseObject(BaseObject&& other) noexcept + : sunctx_(std::move(other.sunctx_)), + object_(std::move(other.object_)), + object_ops_(std::move(other.object_ops_)) + { + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + } + + // Copy constructor + BaseObject(const BaseObject& other) + : sunctx_(other.sunctx_), + object_(std::make_unique()), + object_ops_(std::make_unique(*other.object_ops_)) + { + object_->content = this; + object_->sunctx = other.sunctx_; + object_->ops = object_ops_.get(); + } + + // Move assignment + BaseObject& operator=(BaseObject&& rhs) noexcept + { + sunctx_ = std::move(rhs.sunctx_); + object_ops_ = std::move(rhs.object_ops_); + object_ = std::move(rhs.object_); + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + return *this; + } + + // Copy assignment + BaseObject& operator=(const BaseObject& rhs) + { + sunctx_ = rhs.sunctx_; + object_ops_ = std::make_unique(*rhs.object_ops_); + object_ = std::make_unique(); + object_->content = this; + object_->sunctx = sunctx_; + object_->ops = object_ops_.get(); + return *this; + } + + // We have a pure virtual destructor to make this an asbtract class + virtual ~BaseObject() = 0; + + // Getters + SUNContext sunctx() const { return this->object_->sunctx; } + +protected: + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + SUNContext sunctx_{}; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + std::unique_ptr object_; + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) + std::unique_ptr object_ops_; +}; + +// Pure virtual destructor requires implementation +template +BaseObject::~BaseObject() = default; + +} // namespace impl + +namespace experimental { + +template +class ClassView : public sundials::ConvertibleTo +{ +public: + ClassView() : object_(nullptr) {} + + ClassView(T&& object) : object_(std::make_unique(object)) {} + + ClassView(const ClassView&) = delete; + ClassView(ClassView&& other) = default; + + ClassView& operator=(const ClassView&) = delete; + ClassView& operator=(ClassView&& rhs) = default; + + ~ClassView() + { + if (object_) { Deleter{}(this->Convert()); } + }; + + // Override ConvertibleTo functions + T Convert() override { return *object_.get(); } + + T Convert() const override { return *object_.get(); } + + operator T() override { return *object_.get(); } + + operator T() const override { return *object_.get(); } + +private: + std::unique_ptr object_; +}; + +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.h deleted file mode 100644 index 674ec0df1..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.h +++ /dev/null @@ -1,190 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * SUNDIALS configuration header file. - * -----------------------------------------------------------------*/ - -#include "sundials_export.h" - -/* ------------------------------------------------------------------ - * Define SUNDIALS version numbers - * -----------------------------------------------------------------*/ - - -#define SUNDIALS_VERSION "5.8.0" -#define SUNDIALS_VERSION_MAJOR 5 -#define SUNDIALS_VERSION_MINOR 8 -#define SUNDIALS_VERSION_PATCH 0 -#define SUNDIALS_VERSION_LABEL "" -#define SUNDIALS_GIT_VERSION "" - - -/* ------------------------------------------------------------------ - * SUNDIALS build information - * -----------------------------------------------------------------*/ - - -/* Define precision of SUNDIALS data type 'realtype' - * Depending on the precision level, one of the following - * three macros will be defined: - * #define SUNDIALS_SINGLE_PRECISION 1 - * #define SUNDIALS_DOUBLE_PRECISION 1 - * #define SUNDIALS_EXTENDED_PRECISION 1 - */ -#define SUNDIALS_DOUBLE_PRECISION 1 - -/* Define type of vector indices in SUNDIALS 'sunindextype'. - * Depending on user choice of index type, one of the following - * two macros will be defined: - * #define SUNDIALS_INT64_T 1 - * #define SUNDIALS_INT32_T 1 - */ -#define SUNDIALS_INT64_T 1 - -/* Define the type of vector indices in SUNDIALS 'sunindextype'. - * The macro will be defined with a type of the appropriate size. - */ -#define SUNDIALS_INDEX_TYPE int64_t - -/* Use generic math functions - * If it was decided that generic math functions can be used, then - * #define SUNDIALS_USE_GENERIC_MATH - */ -#define SUNDIALS_USE_GENERIC_MATH - -/* Use POSIX timers if available. - * #define SUNDIALS_HAVE_POSIX_TIMERS - */ -#define SUNDIALS_HAVE_POSIX_TIMERS - -/* CVODE should use fused kernels if utilizing - * the CUDA NVector. - */ -/* #undef SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS */ - - -/* BUILD SUNDIALS with monitoring functionalities - * the CUDA NVector. - */ -/* #undef SUNDIALS_BUILD_WITH_MONITORING */ - -/* ------------------------------------------------------------------ - * SUNDIALS TPL macros - * -----------------------------------------------------------------*/ - - - - -/* MAGMA backends */ -#define SUNDIALS_MAGMA_BACKENDS_CUDA -/* #undef SUNDIALS_MAGMA_BACKENDS_HIP */ - -/* Set if SUNDIALS is built with MPI support, then - * #define SUNDIALS_MPI_ENABLED 1 - * otherwise - * #define SUNDIALS_MPI_ENABLED 0 - */ -#define SUNDIALS_MPI_ENABLED 0 - - /* SUPERLUMT threading type */ -/* #undef SUNDIALS_SUPERLUMT_THREAD_TYPE */ - - /* Trilinos with MPI is available, then - * #define SUNDIALS_TRILINOS_HAVE_MPI - */ -/* #undef SUNDIALS_TRILINOS_HAVE_MPI */ - -/* RAJA backends */ -#define SUNDIALS_RAJA_BACKENDS_CUDA -/* #undef SUNDIALS_RAJA_BACKENDS_HIP */ -/* #undef SUNDIALS_RAJA_BACKENDS_SYCL */ - -/* ------------------------------------------------------------------ - * SUNDIALS modules enabled - * -----------------------------------------------------------------*/ - - -#define SUNDIALS_CVODES 1 -#define SUNDIALS_IDAS 1 -#define SUNDIALS_NVECTOR_SERIAL 1 -#define SUNDIALS_SUNMATRIX_BAND 1 -#define SUNDIALS_SUNMATRIX_DENSE 1 -#define SUNDIALS_SUNMATRIX_SPARSE 1 -#define SUNDIALS_SUNLINSOL_BAND 1 -#define SUNDIALS_SUNLINSOL_DENSE 1 -#define SUNDIALS_SUNLINSOL_PCG 1 -#define SUNDIALS_SUNLINSOL_SPBCGS 1 -#define SUNDIALS_SUNLINSOL_SPFGMR 1 -#define SUNDIALS_SUNLINSOL_SPGMR 1 -#define SUNDIALS_SUNLINSOL_SPTFQMR 1 -#define SUNDIALS_SUNLINSOL_KLU 1 -#define SUNDIALS_SUNNONLINSOL_NEWTON 1 -#define SUNDIALS_SUNNONLINSOL_FIXEDPOINT 1 - - - -/* ------------------------------------------------------------------ - * SUNDIALS fortran configuration - * -----------------------------------------------------------------*/ - - -/* FCMIX: Define Fortran name-mangling macro for C identifiers. - * Depending on the inferred scheme, one of the following six - * macros will be defined: - * #define SUNDIALS_F77_FUNC(name,NAME) name - * #define SUNDIALS_F77_FUNC(name,NAME) name ## _ - * #define SUNDIALS_F77_FUNC(name,NAME) name ## __ - * #define SUNDIALS_F77_FUNC(name,NAME) NAME - * #define SUNDIALS_F77_FUNC(name,NAME) NAME ## _ - * #define SUNDIALS_F77_FUNC(name,NAME) NAME ## __ - */ - - -/* FCMIX: Define Fortran name-mangling macro for C identifiers - * which contain underscores. - */ - - -/* FNVECTOR: Allow user to specify different MPI communicator - * If it was found that the MPI implementation supports MPI_Comm_f2c, then - * #define SUNDIALS_MPI_COMM_F2C 1 - * otherwise - * #define SUNDIALS_MPI_COMM_F2C 0 - */ -#define SUNDIALS_MPI_COMM_F2C 1 - - -/* ------------------------------------------------------------------ - * SUNDIALS inline macros. - * -----------------------------------------------------------------*/ - - -/* Mark SUNDIALS function as inline. - */ -#ifndef SUNDIALS_CXX_INLINE -#define SUNDIALS_CXX_INLINE inline -#endif - -#ifndef SUNDIALS_C_INLINE -#define SUNDIALS_C_INLINE inline -#endif - -#ifdef __cplusplus -#define SUNDIALS_INLINE SUNDIALS_CXX_INLINE -#else -#define SUNDIALS_INLINE SUNDIALS_C_INLINE -#endif - -/* Mark SUNDIALS function as static inline. - */ -#define SUNDIALS_STATIC_INLINE static SUNDIALS_INLINE diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.in b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.in index b7dde7826..def1a8741 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.in +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_config.in @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,7 +14,30 @@ * SUNDIALS configuration header file. * -----------------------------------------------------------------*/ -#include "sundials_export.h" +#ifndef _SUNDIALS_CONFIG_H +#define _SUNDIALS_CONFIG_H + +#include "sundials/sundials_export.h" + +/* Indicates that the function will not report an error via last_err, + a return code. In C++, it is just defined as noexcept. */ +#if defined(__cplusplus) +#define SUNDIALS_NOEXCEPT noexcept +#else +#define SUNDIALS_NOEXCEPT +#endif + +#ifndef SUNDIALS_DEPRECATED_MSG +# define SUNDIALS_DEPRECATED_MSG(msg) @SUNDIALS_DEPRECATED_MSG_MACRO@ +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT_MSG +# define SUNDIALS_DEPRECATED_EXPORT_MSG(msg) SUNDIALS_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT_MSG +# define SUNDIALS_DEPRECATED_NO_EXPORT_MSG(msg) SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif /* ------------------------------------------------------------------ * Define SUNDIALS version numbers @@ -33,8 +56,13 @@ * SUNDIALS build information * -----------------------------------------------------------------*/ +#cmakedefine SUNDIALS_C_COMPILER_HAS_BUILTIN_EXPECT +#cmakedefine SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME +#cmakedefine SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME +#cmakedefine SUNDIALS_C_COMPILER_HAS_ASSUME +#cmakedefine SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED -/* Define precision of SUNDIALS data type 'realtype' +/* Define precision of SUNDIALS data type 'sunrealtype' * Depending on the precision level, one of the following * three macros will be defined: * #define SUNDIALS_SINGLE_PRECISION 1 @@ -56,34 +84,144 @@ */ #define SUNDIALS_INDEX_TYPE @SUNDIALS_CINDEX_TYPE@ -/* Use generic math functions - * If it was decided that generic math functions can be used, then - * #define SUNDIALS_USE_GENERIC_MATH - */ -#cmakedefine SUNDIALS_USE_GENERIC_MATH - /* Use POSIX timers if available. * #define SUNDIALS_HAVE_POSIX_TIMERS */ #cmakedefine SUNDIALS_HAVE_POSIX_TIMERS -/* CVODE should use fused kernels if utilizing - * the CUDA NVector. - */ +/* BUILD CVODE with fused kernel functionality */ #cmakedefine SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS - -/* BUILD SUNDIALS with monitoring functionalities - * the CUDA NVector. - */ +/* BUILD SUNDIALS with monitoring functionalities */ #cmakedefine SUNDIALS_BUILD_WITH_MONITORING +/* BUILD SUNDIALS with profiling functionalities */ +#cmakedefine SUNDIALS_BUILD_WITH_PROFILING + +/* Enable error checking within SUNDIALS */ +#cmakedefine SUNDIALS_ENABLE_ERROR_CHECKS + +/* BUILD SUNDIALS with logging functionalities */ +#define SUNDIALS_LOGGING_LEVEL @SUNDIALS_LOGGING_LEVEL@ + +/* Build metadata */ +#define SUN_C_COMPILER "@CMAKE_C_COMPILER_ID@" +#define SUN_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@" +#define SUN_C_COMPILER_FLAGS "@CMAKE_C_FLAGS@" + +#define SUN_CXX_COMPILER "@CMAKE_CXX_COMPILER_ID@" +#define SUN_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@" +#define SUN_CXX_COMPILER_FLAGS "@CMAKE_CXX_FLAGS@" + +#define SUN_FORTRAN_COMPILER "@CMAKE_FORTRAN_COMPILER_ID@" +#define SUN_FORTRAN_COMPILER_VERSION "@CMAKE_FORTRAN_COMPILER_VERSION@" +#define SUN_FORTRAN_COMPILER_FLAGS "@CMAKE_FORTRAN_FLAGS@" + +#define SUN_BUILD_TYPE "@CMAKE_BUILD_TYPE@" + +#define SUN_JOB_ID "@JOB_ID@" +#define SUN_JOB_START_TIME "@JOB_START_TIME@" + +#define SUN_TPL_LIST "@SUNDIALS_TPL_LIST@" +#define SUN_TPL_LIST_SIZE "@SUNDIALS_TPL_LIST_SIZE@" + +#define SUNDIALS_SPACK_VERSION "@SPACK_VERSION@" + /* ------------------------------------------------------------------ * SUNDIALS TPL macros * -----------------------------------------------------------------*/ +/* Caliper */ +#cmakedefine SUNDIALS_CALIPER_ENABLED + +/* Adiak */ +#cmakedefine SUNDIALS_ADIAK_ENABLED + +/* Ginkgo */ +#cmakedefine SUNDIALS_GINKGO_ENABLED +#define SUN_GINKGO_VERSION "@Ginkgo_VERSION@" + +/* HYPRE */ +#cmakedefine SUNDIALS_HYPRE_ENABLED +#define SUN_HYPRE_VERSION "@HYPRE_VERSION@" + +/* KLU */ +#cmakedefine SUNDIALS_KLU_ENABLED +#define SUN_KLU_VERSION "@KLU_VERSION@" + +/* KOKKOS */ +#cmakedefine SUNDIALS_KOKKOS_ENABLED +#define SUN_KOKKOS_VERSION "@Kokkos_VERSION@" + +/* KOKKOS_KERNELS */ +#cmakedefine SUNDIALS_KOKKOS_KERNELS_ENABLED +#define SUN_KOKKOS_KERNELS_VERSION "@KokkosKernels_VERSION@" + +/* LAPACK */ +#cmakedefine SUNDIALS_BLAS_LAPACK_ENABLED +#define SUN_LAPACK_VERSION "@LAPACK_VERSION@" + +/* MAGMA */ +#cmakedefine SUNDIALS_MAGMA_ENABLED +#define SUN_MAGMA_VERSION "@MAGMA_VERSION@" + +/* MPI */ +#define SUN_MPI_C_COMPILER "@MPI_C_COMPILER@" +#define SUN_MPI_C_VERSION "@MPI_C_VERSION@" + +#define SUN_MPI_CXX_COMPILER "@MPI_CXX_COMPILER@" +#define SUN_MPI_CXX_VERSION "@MPI_CXX_VERSION@" + +#define SUN_MPI_FORTRAN_COMPILER "@MPI_FORTRAN_COMPILER@" +#define SUN_MPI_FORTRAN_VERSION "@MPI_FORTRAN_VERSION@" + +/* ONEMKL */ +#cmakedefine SUNDIALS_ONEMKL_ENABLED +#define SUN_ONEMKL_VERSION "@MKL_VERSION@" + +/* OpenMP */ +#cmakedefine SUNDIALS_OPENMP_ENABLED +#define SUN_OPENMP_VERSION "@OpenMP_VERSION@" + +/* PETSC */ +#cmakedefine SUNDIALS_PETSC_ENABLED +#define SUN_PETSC_VERSION "@PETSC_VERSION@" + +/* PTHREADS */ +#cmakedefine SUNDIALS_PTHREADS_ENABLED +#define SUN_PTHREADS_VERSION "@Threads_VERSION@" + +/* RAJA */ +#cmakedefine SUNDIALS_RAJA_ENABLED +#define SUN_RAJA_VERSION "@RAJA_VERSION@" -@SUNDIALS_CONFIGH_TPLS@ +/* SUPERLUDIST */ +#cmakedefine SUNDIALS_SUPERLUDIST_ENABLED +#define SUN_SUPERLUDIST_VERSION "@SUPERLUDIST_VERSION@" + +/* SUPERLUMT */ +#cmakedefine SUNDIALS_SUPERLUMT_ENABLED +#define SUN_SUPERLUMT_VERSION "@SUPERLUMT_VERSION@" + +/* TRILLINOS */ +#cmakedefine SUNDIALS_TRILLINOS_ENABLED +#define SUN_TRILLINOS_VERSION "@Trillinos_VERSION@" + +/* XBRAID */ +#cmakedefine SUNDIALS_XBRAID_ENABLED +#define SUN_XBRAID_VERSION "@XBRAID_VERSION@" + +/* RAJA backends */ +#cmakedefine SUNDIALS_RAJA_BACKENDS_CUDA +#cmakedefine SUNDIALS_RAJA_BACKENDS_HIP +#cmakedefine SUNDIALS_RAJA_BACKENDS_SYCL + +/* Ginkgo backends */ +#cmakedefine SUNDIALS_GINKGO_BACKENDS_CUDA +#cmakedefine SUNDIALS_GINKGO_BACKENDS_HIP +#cmakedefine SUNDIALS_GINKGO_BACKENDS_OMP +#cmakedefine SUNDIALS_GINKGO_BACKENDS_REF +#cmakedefine SUNDIALS_GINKGO_BACKENDS_SYCL /* MAGMA backends */ #cmakedefine SUNDIALS_MAGMA_BACKENDS_CUDA @@ -96,79 +234,42 @@ */ #cmakedefine01 SUNDIALS_MPI_ENABLED - /* SUPERLUMT threading type */ -#cmakedefine SUNDIALS_SUPERLUMT_THREAD_TYPE "@SUPERLUMT_THREAD_TYPE@" - - /* Trilinos with MPI is available, then - * #define SUNDIALS_TRILINOS_HAVE_MPI - */ -#cmakedefine SUNDIALS_TRILINOS_HAVE_MPI - -/* RAJA backends */ -#cmakedefine SUNDIALS_RAJA_BACKENDS_CUDA -#cmakedefine SUNDIALS_RAJA_BACKENDS_HIP -#cmakedefine SUNDIALS_RAJA_BACKENDS_SYCL - -/* ------------------------------------------------------------------ - * SUNDIALS modules enabled - * -----------------------------------------------------------------*/ +/* oneMKL interface options */ +#cmakedefine SUNDIALS_ONEMKL_USE_GETRF_LOOP +#cmakedefine SUNDIALS_ONEMKL_USE_GETRS_LOOP +/* SUPERLUMT threading type */ +#define SUNDIALS_SUPERLUMT_THREAD_TYPE "@SUPERLUMT_THREAD_TYPE@" -@SUNDIALS_CONFIGH_BUILDS@ +/* Trilinos with MPI is available, then + * #define SUNDIALS_TRILINOS_HAVE_MPI + */ +#cmakedefine SUNDIALS_TRILINOS_HAVE_MPI /* ------------------------------------------------------------------ - * SUNDIALS fortran configuration + * SUNDIALS language macros * -----------------------------------------------------------------*/ +/* CUDA */ +#cmakedefine SUNDIALS_CUDA_ENABLED +#define SUN_CUDA_VERSION "@CMAKE_CUDA_COMPILER_VERSION@" +#define SUN_CUDA_COMPILER "@CMAKE_CUDA_COMPILER@" +#define SUN_CUDA_ARCHITECTURES "@CMAKE_CUDA_ARCHITECTURES@" -/* FCMIX: Define Fortran name-mangling macro for C identifiers. - * Depending on the inferred scheme, one of the following six - * macros will be defined: - * #define SUNDIALS_F77_FUNC(name,NAME) name - * #define SUNDIALS_F77_FUNC(name,NAME) name ## _ - * #define SUNDIALS_F77_FUNC(name,NAME) name ## __ - * #define SUNDIALS_F77_FUNC(name,NAME) NAME - * #define SUNDIALS_F77_FUNC(name,NAME) NAME ## _ - * #define SUNDIALS_F77_FUNC(name,NAME) NAME ## __ - */ -@F77_MANGLE_MACRO1@ - -/* FCMIX: Define Fortran name-mangling macro for C identifiers - * which contain underscores. - */ -@F77_MANGLE_MACRO2@ +/* HIP */ +#cmakedefine SUNDIALS_HIP_ENABLED +#define SUN_HIP_VERSION "@HIP_VERSION@" +#define SUN_AMDGPU_TARGETS "@AMDGPU_TARGETS@" -/* FNVECTOR: Allow user to specify different MPI communicator - * If it was found that the MPI implementation supports MPI_Comm_f2c, then - * #define SUNDIALS_MPI_COMM_F2C 1 - * otherwise - * #define SUNDIALS_MPI_COMM_F2C 0 - */ -@F77_MPI_COMM_F2C@ +/* SYCL options */ +#cmakedefine SUNDIALS_SYCL_2020_UNSUPPORTED /* ------------------------------------------------------------------ - * SUNDIALS inline macros. + * SUNDIALS modules enabled * -----------------------------------------------------------------*/ +@SUNDIALS_CONFIGH_BUILDS@ -/* Mark SUNDIALS function as inline. - */ -#ifndef SUNDIALS_CXX_INLINE -#define SUNDIALS_CXX_INLINE inline -#endif - -#ifndef SUNDIALS_C_INLINE -#define SUNDIALS_C_INLINE inline -#endif - -#ifdef __cplusplus -#define SUNDIALS_INLINE SUNDIALS_CXX_INLINE -#else -#define SUNDIALS_INLINE SUNDIALS_C_INLINE -#endif - -/* Mark SUNDIALS function as static inline. - */ -#define SUNDIALS_STATIC_INLINE static SUNDIALS_INLINE +#endif /* _SUNDIALS_CONFIG_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.h new file mode 100644 index 000000000..49e2bda2d --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.h @@ -0,0 +1,66 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS context class. A context object holds data that all + * SUNDIALS objects in a simulation share. It is thread-safe provided + * that each thread has its own context object. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_H +#define _SUNDIALS_CONTEXT_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +SUNErrCode SUNContext_Create(SUNComm comm, SUNContext* sunctx_out); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetLastError(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PeekLastError(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PushErrHandler(SUNContext sunctx, SUNErrHandlerFn err_fn, + void* err_user_data); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_PopErrHandler(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_ClearErrHandlers(SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetProfiler(SUNContext sunctx, SUNProfiler* profiler); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_SetProfiler(SUNContext sunctx, SUNProfiler profiler); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_GetLogger(SUNContext sunctx, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_SetLogger(SUNContext sunctx, SUNLogger logger); + +SUNDIALS_EXPORT +SUNErrCode SUNContext_Free(SUNContext* ctx); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.hpp new file mode 100644 index 000000000..c28fb8026 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_context.hpp @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ interface to the SUNDIALS context object + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_HPP +#define _SUNDIALS_CONTEXT_HPP + +#include +#include +#include + +#include "sundials/sundials_types.h" + +namespace sundials { + +class Context : public sundials::ConvertibleTo +{ +public: + explicit Context(SUNComm comm = SUN_COMM_NULL) + { + sunctx_ = std::make_unique(); + SUNContext_Create(comm, sunctx_.get()); + } + + /* disallow copy, but allow move construction */ + Context(const Context&) = delete; + Context(Context&&) = default; + + /* disallow copy, but allow move operators */ + Context& operator=(const Context&) = delete; + Context& operator=(Context&&) = default; + + SUNContext Convert() override { return *sunctx_.get(); } + + SUNContext Convert() const override { return *sunctx_.get(); } + + operator SUNContext() override { return *sunctx_.get(); } + + operator SUNContext() const override { return *sunctx_.get(); } + + ~Context() + { + if (sunctx_) { SUNContext_Free(sunctx_.get()); } + } + +private: + std::unique_ptr sunctx_; +}; + +} // namespace sundials + +#endif // _SUNDIALS_CONTEXT_HPP diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_convertibleto.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_convertibleto.hpp new file mode 100644 index 000000000..7443ed4cf --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_convertibleto.hpp @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * Base class for converting C++ wappers (views) to SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONVERTIBLETO_HPP +#define _SUNDIALS_CONVERTIBLETO_HPP + +namespace sundials { + +template +class ConvertibleTo +{ +public: + // Explicit conversion to the underlying type + virtual T Convert() = 0; + virtual T Convert() const = 0; + + // Implicit conversion to the underlying type + virtual operator T() = 0; + virtual operator T() const = 0; + + virtual ~ConvertibleTo() = default; +}; + +} // namespace sundials + +#endif // _SUNDIALS_CONVERTIBLETO_HPP diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.h new file mode 100644 index 000000000..592d1d7b1 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.h @@ -0,0 +1,38 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * Header file that includes the SUNDIALS core. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CORE_H +#define _SUNDIALS_CORE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if SUNDIALS_MPI_ENABLED +#include +#endif + +#endif /* _SUNDIALS_CORE_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.hpp new file mode 100644 index 000000000..51372a3f0 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_core.hpp @@ -0,0 +1,25 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CORE_HPP +#define _SUNDIALS_CORE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* _SUNDIALS_CORE_HPP */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_dense.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_dense.h index ae6ca8d42..8ee196412 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_dense.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_dense.h @@ -2,7 +2,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -16,9 +16,9 @@ * * There are two sets of dense solver routines listed in * this file: one set uses type DlsMat defined below and the - * other set uses the type realtype ** for dense matrix arguments. + * other set uses the type sunrealtype ** for dense matrix arguments. * Routines that work with the type DlsMat begin with "Dense". - * Routines that work with realtype** begin with "dense". + * Routines that work with sunrealtype** begin with "dense". * -----------------------------------------------------------------*/ #ifndef _SUNDIALS_DENSE_H @@ -26,184 +26,206 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* - * ----------------------------------------------------------------- - * Functions: DenseGETRF and DenseGETRS - * ----------------------------------------------------------------- - * DenseGETRF performs the LU factorization of the M by N dense - * matrix A. This is done using standard Gaussian elimination - * with partial (row) pivoting. Note that this applies only - * to matrices with M >= N and full column rank. - * - * A successful LU factorization leaves the matrix A and the - * pivot array p with the following information: - * - * (1) p[k] contains the row number of the pivot element chosen - * at the beginning of elimination step k, k=0, 1, ..., N-1. - * - * (2) If the unique LU factorization of A is given by PA = LU, - * where P is a permutation matrix, L is a lower trapezoidal - * matrix with all 1's on the diagonal, and U is an upper - * triangular matrix, then the upper triangular part of A - * (including its diagonal) contains U and the strictly lower + * ---------------------------------------------------------------------------- + * Functions: SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF performs the LU factorization of the M by N dense matrix A. + * This is done using standard Gaussian elimination with partial (row) pivoting. + * Note that this applies only to matrices with M >= N and full column rank. + * + * A successful LU factorization leaves the matrix A and the pivot array p with + * the following information: + * + * (1) p[k] contains the row number of the pivot element chosen at the beginning + * of elimination step k, k=0, 1, ..., N-1. + * + * (2) If the unique LU factorization of A is given by PA = LU, where P is a + * permutation matrix, L is a lower trapezoidal matrix with all 1's on the + * diagonal, and U is an upper triangular matrix, then the upper triangular + * part of A (including its diagonal) contains U and the strictly lower * trapezoidal part of A contains the multipliers, I-L. * * For square matrices (M = N), L is unit lower triangular. * - * DenseGETRF returns 0 if successful. Otherwise it encountered - * a zero diagonal element during the factorization. In this case - * it returns the column index (numbered from one) at which - * it encountered the zero. - * - * DenseGETRS solves the N-dimensional system A x = b using - * the LU factorization in A and the pivot information in p - * computed in DenseGETRF. The solution x is returned in b. This - * routine cannot fail if the corresponding call to DenseGETRF - * did not fail. - * DenseGETRS does NOT check for a square matrix! - * - * ----------------------------------------------------------------- - * DenseGETRF and DenseGETRS are simply wrappers around denseGETRF - * and denseGETRS, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. in A->cols). - * ----------------------------------------------------------------- + * SUNDlsMat_DenseGETRF returns 0 if successful. Otherwise it encountered a zero + * diagonal element during the factorization. In this case it returns the column + * index (numbered from one) at which it encountered the zero. + * + * SUNDlsMat_DenseGETRS solves the N-dimensional system A x = b using the LU + * factorization in A and the pivot information in p computed in + * SUNDlsMat_DenseGETRF. The solution x is returned in b. This routine cannot fail + * if the corresponding call to SUNDlsMat_DenseGETRF did not fail. + * SUNDlsMat_DenseGETRS does NOT check for a square matrix! + * + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS are simply wrappers around + * SUNDlsMat_denseGETRF and SUNDlsMat_denseGETRS, respectively, which perform all the + * work by directly accessing the data in the SUNDlsMat A (i.e. in A->cols). + * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype DenseGETRF(DlsMat A, sunindextype *p); -SUNDIALS_EXPORT void DenseGETRS(DlsMat A, sunindextype *p, realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DenseGETRF(SUNDlsMat A, sunindextype* p); + +SUNDIALS_EXPORT +void SUNDlsMat_DenseGETRS(SUNDlsMat A, sunindextype* p, sunrealtype* b); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_denseGETRF(sunrealtype** a, sunindextype m, + sunindextype n, sunindextype* p); -SUNDIALS_EXPORT sunindextype denseGETRF(realtype **a, sunindextype m, - sunindextype n, sunindextype *p); -SUNDIALS_EXPORT void denseGETRS(realtype **a, sunindextype n, sunindextype *p, - realtype *b); +SUNDIALS_EXPORT +void SUNDlsMat_denseGETRS(sunrealtype** a, sunindextype n, sunindextype* p, + sunrealtype* b); /* - * ----------------------------------------------------------------- - * Functions : DensePOTRF and DensePOTRS - * ----------------------------------------------------------------- - * DensePOTRF computes the Cholesky factorization of a real symmetric + * ---------------------------------------------------------------------------- + * Functions : SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF computes the Cholesky factorization of a real symmetric * positive definite matrix A. - * ----------------------------------------------------------------- - * DensePOTRS solves a system of linear equations A*X = B with a - * symmetric positive definite matrix A using the Cholesky factorization - * A = L*L**T computed by DensePOTRF. - * - * ----------------------------------------------------------------- - * DensePOTRF and DensePOTRS are simply wrappers around densePOTRF - * and densePOTRS, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. the field cols) - * ----------------------------------------------------------------- + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRS solves a system of linear equations A*X = B with a + * symmetric positive definite matrix A using the Cholesky factorization A = + * L*L**T computed by SUNDlsMat_DensePOTRF. + * + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS are simply wrappers around + * SUNDlsMat_densePOTRF and SUNDlsMat_densePOTRS, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype DensePOTRF(DlsMat A); -SUNDIALS_EXPORT void DensePOTRS(DlsMat A, realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DensePOTRF(SUNDlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_DensePOTRS(SUNDlsMat A, sunrealtype* b); -SUNDIALS_EXPORT sunindextype densePOTRF(realtype **a, sunindextype m); -SUNDIALS_EXPORT void densePOTRS(realtype **a, sunindextype m, realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_densePOTRF(sunrealtype** a, sunindextype m); + +SUNDIALS_EXPORT +void SUNDlsMat_densePOTRS(sunrealtype** a, sunindextype m, sunrealtype* b); /* - * ----------------------------------------------------------------- - * Functions : DenseGEQRF and DenseORMQR - * ----------------------------------------------------------------- - * DenseGEQRF computes a QR factorization of a real M-by-N matrix A: - * A = Q * R (with M>= N). + * ----------------------------------------------------------------------------- + * Functions : SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF computes a QR factorization of a real M-by-N matrix A: A = + * Q * R (with M>= N). * - * DenseGEQRF requires a temporary work vector wrk of length M. - * ----------------------------------------------------------------- - * DenseORMQR computes the product w = Q * v where Q is a real - * orthogonal matrix defined as the product of k elementary reflectors + * SUNDlsMat_DenseGEQRF requires a temporary work vector wrk of length M. + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseORMQR computes the product w = Q * v where Q is a real orthogonal + * matrix defined as the product of k elementary reflectors * * Q = H(1) H(2) . . . H(k) * - * as returned by DenseGEQRF. Q is an M-by-N matrix, v is a vector - * of length N and w is a vector of length M (with M >= N). + * as returned by SUNDlsMat_DenseGEQRF. Q is an M-by-N matrix, v is a vector of + * length N and w is a vector of length M (with M >= N). * - * DenseORMQR requires a temporary work vector wrk of length M. + * SUNDlsMat_DenseORMQR requires a temporary work vector wrk of length M. * - * ----------------------------------------------------------------- - * DenseGEQRF and DenseORMQR are simply wrappers around denseGEQRF - * and denseORMQR, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. the field cols) - * ----------------------------------------------------------------- + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR are simply wrappers around + * SUNDlsMat_denseGEQRF and SUNDlsMat_denseORMQR, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk); -SUNDIALS_EXPORT int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, - realtype *vm, realtype *wrk); +SUNDIALS_EXPORT +int SUNDlsMat_DenseGEQRF(SUNDlsMat A, sunrealtype* beta, sunrealtype* wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_DenseORMQR(SUNDlsMat A, sunrealtype* beta, sunrealtype* vn, + sunrealtype* vm, sunrealtype* wrk); -SUNDIALS_EXPORT int denseGEQRF(realtype **a, sunindextype m, sunindextype n, - realtype *beta, realtype *wrk); -SUNDIALS_EXPORT int denseORMQR(realtype **a, sunindextype m, sunindextype n, - realtype *beta, realtype *v, realtype *w, - realtype *wrk); +SUNDIALS_EXPORT +int SUNDlsMat_denseGEQRF(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_denseORMQR(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* v, sunrealtype* w, + sunrealtype* wrk); /* - * ----------------------------------------------------------------- - * Function : DenseCopy - * ----------------------------------------------------------------- - * DenseCopy copies the contents of the M-by-N matrix A into the + * ---------------------------------------------------------------------------- + * Function : SUNDlsMat_DenseCopy + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseCopy copies the contents of the M-by-N matrix A into the * M-by-N matrix B. * - * DenseCopy is a wrapper around denseCopy which accesses the data - * in the DlsMat A and DlsMat B (i.e. the fields cols) - * ----------------------------------------------------------------- + * SUNDlsMat_DenseCopy is a wrapper around SUNDlsMat_denseCopy which accesses + * the data in the SUNDlsMat A and SUNDlsMat B (i.e. the fields cols) + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseCopy(DlsMat A, DlsMat B); -SUNDIALS_EXPORT void denseCopy(realtype **a, realtype **b, sunindextype m, - sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseCopy(SUNDlsMat A, SUNDlsMat B); + +SUNDIALS_EXPORT +void SUNDlsMat_denseCopy(sunrealtype** a, sunrealtype** b, sunindextype m, + sunindextype n); /* - * ----------------------------------------------------------------- - * Function: DenseScale - * ----------------------------------------------------------------- - * DenseScale scales the elements of the M-by-N matrix A by the + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseScale + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseScale scales the elements of the M-by-N matrix A by the * constant c and stores the result back in A. * - * DenseScale is a wrapper around denseScale which performs the actual - * scaling by accessing the data in the DlsMat A (i.e. in A->cols). - * ----------------------------------------------------------------- + * SUNDlsMat_DenseScale is a wrapper around SUNDlsMat_denseScale which performs + * the actual scaling by accessing the data in the SUNDlsMat A (i.e. in + * A->cols). + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseScale(realtype c, DlsMat A); -SUNDIALS_EXPORT void denseScale(realtype c, realtype **a, sunindextype m, - sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseScale(sunrealtype c, SUNDlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_denseScale(sunrealtype c, sunrealtype** a, sunindextype m, + sunindextype n); /* - * ----------------------------------------------------------------- - * Function: denseAddIdentity - * ----------------------------------------------------------------- - * denseAddIdentity adds the identity matrix to the n-by-n matrix - * stored in a realtype** array. - * ----------------------------------------------------------------- + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_denseAddIdentity + * ----------------------------------------------------------------------------- + * SUNDlsMat_denseAddIdentity adds the identity matrix to the n-by-n matrix + * stored in a sunrealtype** array. + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void denseAddIdentity(realtype **a, sunindextype n); - +SUNDIALS_EXPORT +void SUNDlsMat_denseAddIdentity(sunrealtype** a, sunindextype n); /* - * ----------------------------------------------------------------- - * Function: DenseMatvec - * ----------------------------------------------------------------- - * DenseMatvec computes the matrix-vector product y = A*x, where A - * is an M-by-N matrix, x is a vector of length N, and y is a vector - * of length M. No error checking is performed on the length of the - * arrays x and y. Only y is modified in this routine. - * - * DenseMatvec is a wrapper around denseMatvec which performs the - * actual product by accessing the data in the DlsMat A. - * ----------------------------------------------------------------- + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseMatvec + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseMatvec computes the matrix-vector product y = A*x, where A is + * an M-by-N matrix, x is a vector of length N, and y is a vector of length M. + * No error checking is performed on the length of the arrays x and y. Only y + * is modified in this routine. + * + * SUNDlsMat_DenseMatvec is a wrapper around SUNDlsMat_denseMatvec which + * performs the actual product by accessing the data in the SUNDlsMat A. + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseMatvec(DlsMat A, realtype *x, realtype *y); -SUNDIALS_EXPORT void denseMatvec(realtype **a, realtype *x, realtype *y, - sunindextype m, sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y); +SUNDIALS_EXPORT +void SUNDlsMat_denseMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, + sunindextype m, sunindextype n); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_direct.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_direct.h index 0004e23f7..7b8b315d5 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_direct.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_direct.h @@ -2,7 +2,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,7 +22,7 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -48,9 +48,9 @@ extern "C" { /* * ----------------------------------------------------------------- - * Type : DlsMat + * Type : SUNDlsMat * ----------------------------------------------------------------- - * The type DlsMat is defined to be a pointer to a structure + * The type SUNDlsMat is defined to be a pointer to a structure * with various sizes, a data field, and an array of pointers to * the columns which defines a dense or band matrix for use in * direct linear solvers. The M and N fields indicates the number @@ -58,29 +58,30 @@ extern "C" { * dimensional array used for component storage. The cols field * stores the pointers in data for the beginning of each column. * ----------------------------------------------------------------- - * For DENSE matrices, the relevant fields in DlsMat are: + * For DENSE matrices, the relevant fields in SUNDlsMat are: * type = SUNDIALS_DENSE * M - number of rows * N - number of columns * ldim - leading dimension (ldim >= M) - * data - pointer to a contiguous block of realtype variables + * data - pointer to a contiguous block of sunrealtype variables * ldata - length of the data array =ldim*N * cols - array of pointers. cols[j] points to the first element * of the j-th column of the matrix in the array data. * * The elements of a dense matrix are stored columnwise (i.e. columns * are stored one on top of the other in memory). - * If A is of type DlsMat, then the (i,j)th element of A (with + * If A is of type SUNDlsMat, then the (i,j)th element of A (with * 0 <= i < M and 0 <= j < N) is given by (A->data)[j*n+i]. * - * The DENSE_COL and DENSE_ELEM macros below allow a user to access - * efficiently individual matrix elements without writing out explicit - * data structure references and without knowing too much about the - * underlying element storage. The only storage assumption needed is - * that elements are stored columnwise and that a pointer to the - * jth column of elements can be obtained via the DENSE_COL macro. - * ----------------------------------------------------------------- - * For BAND matrices, the relevant fields in DlsMat are: + * The SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM macros below allow a + * user to access efficiently individual matrix elements without + * writing out explicit data structure references and without knowing + * too much about the underlying element storage. The only storage + * assumption needed is that elements are stored columnwise and that a + * pointer to the jth column of elements can be obtained via the + * SUNDLS_DENSE_COL macro. + * ----------------------------------------------------------------- + * For BAND matrices, the relevant fields in SUNDlsMat are: * type = SUNDIALS_BAND * M - number of rows * N - number of columns @@ -93,26 +94,28 @@ extern "C" { * partial pivoting. The s_mu field holds the upper * bandwidth allocated for A. * ldim - leading dimension (ldim >= s_mu) - * data - pointer to a contiguous block of realtype variables + * data - pointer to a contiguous block of sunrealtype variables * ldata - length of the data array =ldim*(s_mu+ml+1) * cols - array of pointers. cols[j] points to the first element * of the j-th column of the matrix in the array data. * - * The BAND_COL, BAND_COL_ELEM, and BAND_ELEM macros below allow a - * user to access individual matrix elements without writing out - * explicit data structure references and without knowing too much - * about the underlying element storage. The only storage assumption - * needed is that elements are stored columnwise and that a pointer - * into the jth column of elements can be obtained via the BAND_COL - * macro. The BAND_COL_ELEM macro selects an element from a column - * which has already been isolated via BAND_COL. The macro - * BAND_COL_ELEM allows the user to avoid the translation - * from the matrix location (i,j) to the index in the array returned - * by BAND_COL at which the (i,j)th element is stored. + * The SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM + * macros below allow a user to access individual matrix elements + * without writing out explicit data structure references and without + * knowing too much about the underlying element storage. The only + * storage assumption needed is that elements are stored columnwise + * and that a pointer into the jth column of elements can be obtained + * via the SUNDLS_BAND_COL macro. The SUNDLS_BAND_COL_ELEM macro + * selects an element from a column which has already been isolated + * via SUNDLS_BAND_COL. The macro SUNDLS_BAND_COL_ELEM allows the user + * to avoid the translation from the matrix location (i,j) to the + * index in the array returned by SUNDLS_BAND_COL at which the (i,j)th + * element is stored. * ----------------------------------------------------------------- */ -typedef struct _DlsMat { +typedef struct _DlsMat +{ int type; sunindextype M; sunindextype N; @@ -120,10 +123,10 @@ typedef struct _DlsMat { sunindextype mu; sunindextype ml; sunindextype s_mu; - realtype *data; + sunrealtype* data; sunindextype ldata; - realtype **cols; -} *DlsMat; + sunrealtype** cols; +}* SUNDlsMat; /* * ================================================================== @@ -133,177 +136,189 @@ typedef struct _DlsMat { /* * ----------------------------------------------------------------- - * DENSE_COL and DENSE_ELEM + * SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM * ----------------------------------------------------------------- * - * DENSE_COL(A,j) references the jth column of the M-by-N dense - * matrix A, 0 <= j < N. The type of the expression DENSE_COL(A,j) - * is (realtype *). After the assignment col_j = DENSE_COL(A,j), - * col_j may be treated as an array indexed from 0 to M-1. - * The (i,j)-th element of A is thus referenced by col_j[i]. + * SUNDLS_DENSE_COL(A,j) references the jth column of the M-by-N dense + * matrix A, 0 <= j < N. The type of the expression SUNDLS_DENSE_COL(A,j) + * is (sunrealtype *). After the assignment col_j = SUNDLS_DENSE_COL(A,j), + * col_j may be treated as an array indexed from 0 to M-1. The (i,j)-th + * element of A is thus referenced by * col_j[i]. * - * DENSE_ELEM(A,i,j) references the (i,j)th element of the dense + * SUNDLS_DENSE_ELEM(A,i,j) references the (i,j)th element of the dense * M-by-N matrix A, 0 <= i < M ; 0 <= j < N. * * ----------------------------------------------------------------- */ -#define DENSE_COL(A,j) ((A->cols)[j]) -#define DENSE_ELEM(A,i,j) ((A->cols)[j][i]) +#define SUNDLS_DENSE_COL(A, j) ((A->cols)[j]) +#define SUNDLS_DENSE_ELEM(A, i, j) ((A->cols)[j][i]) /* * ----------------------------------------------------------------- - * BAND_COL, BAND_COL_ELEM, and BAND_ELEM + * SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM * ----------------------------------------------------------------- * - * BAND_COL(A,j) references the diagonal element of the jth column - * of the N by N band matrix A, 0 <= j <= N-1. The type of the - * expression BAND_COL(A,j) is realtype *. The pointer returned by - * the call BAND_COL(A,j) can be treated as an array which is - * indexed from -(A->mu) to (A->ml). + * SUNDLS_BAND_COL(A,j) references the diagonal element of the jth + * column of the N by N band matrix A, 0 <= j <= N-1. The type of the + * expression SUNDLS_BAND_COL(A,j) is sunrealtype *. The pointer returned + * by the call SUNDLS_BAND_COL(A,j) can be treated as an array which + * is indexed from -(A->mu) to (A->ml). * - * BAND_COL_ELEM references the (i,j)th entry of the band matrix A - * when used in conjunction with BAND_COL. The index (i,j) should - * satisfy j-(A->mu) <= i <= j+(A->ml). + * SUNDLS_BAND_COL_ELEM references the (i,j)th entry of the band + * matrix A when used in conjunction with SUNDLS_BAND_COL. The index + * (i,j) should satisfy j-(A->mu) <= i <= j+(A->ml). * - * BAND_ELEM(A,i,j) references the (i,j)th element of the M-by-N - * band matrix A, where 0 <= i,j <= N-1. The location (i,j) should - * further satisfy j-(A->mu) <= i <= j+(A->ml). + * SUNDLS_BAND_ELEM(A,i,j) references the (i,j)th element of the + * M-by-N band matrix A, where 0 <= i,j <= N-1. The location (i,j) + * should further satisfy j-(A->mu) <= i <= j+(A->ml). * * ----------------------------------------------------------------- */ -#define BAND_COL(A,j) (((A->cols)[j])+(A->s_mu)) -#define BAND_COL_ELEM(col_j,i,j) (col_j[(i)-(j)]) -#define BAND_ELEM(A,i,j) ((A->cols)[j][(i)-(j)+(A->s_mu)]) - +#define SUNDLS_BAND_COL(A, j) (((A->cols)[j]) + (A->s_mu)) +#define SUNDLS_BAND_COL_ELEM(col_j, i, j) (col_j[(i) - (j)]) +#define SUNDLS_BAND_ELEM(A, i, j) ((A->cols)[j][(i) - (j) + (A->s_mu)]) /* * ================================================================== - * Exported function prototypes (functions working on dlsMat) + * Exported function prototypes (functions working on SUNDlsMat) * ================================================================== */ /* * ----------------------------------------------------------------- - * Function: NewDenseMat + * Function: SUNDlsMat_NewDenseMat * ----------------------------------------------------------------- - * NewDenseMat allocates memory for an M-by-N dense matrix and - * returns the storage allocated (type DlsMat). NewDenseMat - * returns NULL if the request for matrix storage cannot be - * satisfied. See the above documentation for the type DlsMat - * for matrix storage details. + * SUNDlsMat_NewDenseMat allocates memory for an M-by-N dense matrix + * and returns the storage allocated (type SUNDlsMat). + * SUNDlsMat_NewDenseMat returns NULL if the request for matrix + * storage cannot be satisfied. See the above documentation for the + * type SUNDlsMat for matrix storage details. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT DlsMat NewDenseMat(sunindextype M, sunindextype N); +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewDenseMat(sunindextype M, sunindextype N); /* * ----------------------------------------------------------------- - * Function: NewBandMat + * Function: SUNDlsMat_NewBandMat * ----------------------------------------------------------------- - * NewBandMat allocates memory for an M-by-N band matrix + * SUNDlsMat_NewBandMat allocates memory for an M-by-N band matrix * with upper bandwidth mu, lower bandwidth ml, and storage upper - * bandwidth smu. Pass smu as follows depending on whether A will - * be LU factored: + * bandwidth smu. Pass smu as follows depending on whether A will be + * LU factored: * * (1) Pass smu = mu if A will not be factored. * * (2) Pass smu = MIN(N-1,mu+ml) if A will be factored. * - * NewBandMat returns the storage allocated (type DlsMat) or - * NULL if the request for matrix storage cannot be satisfied. - * See the documentation for the type DlsMat for matrix storage + * SUNDlsMat_NewBandMat returns the storage allocated (type SUNDlsMat) + * or NULL if the request for matrix storage cannot be satisfied. See + * the documentation for the type SUNDlsMat for matrix storage * details. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT DlsMat NewBandMat(sunindextype N, sunindextype mu, - sunindextype ml, sunindextype smu); +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, + sunindextype smu); /* * ----------------------------------------------------------------- - * Functions: DestroyMat + * Functions: SUNDlsMat_DestroyMat * ----------------------------------------------------------------- - * DestroyMat frees the memory allocated by NewDenseMat or NewBandMat + * SUNDlsMat_DestroyMat frees the memory allocated by + * SUNDlsMat_NewDenseMat or SUNDlsMat_NewBandMat * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void DestroyMat(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_DestroyMat(SUNDlsMat A); /* * ----------------------------------------------------------------- - * Function: NewIntArray + * Function: SUNDlsMat_NewIntArray * ----------------------------------------------------------------- - * NewIntArray allocates memory an array of N int's and returns - * the pointer to the memory it allocates. If the request for + * SUNDlsMat_NewIntArray allocates memory an array of N int's and + * returns the pointer to the memory it allocates. If the request for * memory storage cannot be satisfied, it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int *NewIntArray(int N); +SUNDIALS_EXPORT +int* SUNDlsMat_NewIntArray(int N); /* * ----------------------------------------------------------------- - * Function: NewIndexArray + * Function: SUNDlsMat_NewIndexArray * ----------------------------------------------------------------- - * NewIndexArray allocates memory an array of N sunindextype's and - * returns the pointer to the memory it allocates. If the request - * for memory storage cannot be satisfied, it returns NULL. + * SUNDlsMat_NewIndexArray allocates memory an array of N + * sunindextype's and returns the pointer to the memory it + * allocates. If the request for memory storage cannot be satisfied, + * it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype *NewIndexArray(sunindextype N); +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_NewIndexArray(sunindextype N); /* * ----------------------------------------------------------------- - * Function: NewRealArray + * Function: SUNDlsMat_NewRealArray * ----------------------------------------------------------------- - * NewRealArray allocates memory an array of N realtype and returns - * the pointer to the memory it allocates. If the request for + * SUNDlsMat_NewRealArray allocates memory an array of N sunrealtype and + * returns the pointer to the memory it allocates. If the request for * memory storage cannot be satisfied, it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT realtype *NewRealArray(sunindextype N); +SUNDIALS_EXPORT +sunrealtype* SUNDlsMat_NewRealArray(sunindextype N); /* * ----------------------------------------------------------------- - * Function: DestroyArray + * Function: SUNDlsMat_DestroyArray * ----------------------------------------------------------------- - * DestroyArray frees memory allocated by NewIntArray, NewIndexArray, - * or NewRealArray. + * SUNDlsMat_DestroyArray frees memory allocated by + * SUNDlsMat_NewIntArray, SUNDlsMat_NewIndexArray, or + * SUNDlsMat_NewRealArray. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void DestroyArray(void *p); +SUNDIALS_EXPORT +void SUNDlsMat_DestroyArray(void* p); /* * ----------------------------------------------------------------- - * Function : AddIdentity + * Function : SUNDlsMat_AddIdentity * ----------------------------------------------------------------- - * AddIdentity adds 1.0 to the main diagonal (A_ii, i=0,1,...,N-1) of - * the M-by-N matrix A (M>= N) and stores the result back in A. - * AddIdentity is typically used with square matrices. - * AddIdentity does not check for M >= N and therefore a segmentation - * fault will occur if M < N! + * SUNDlsMat_AddIdentity adds 1.0 to the main diagonal (A_ii, + * i=0,1,...,N-1) of the M-by-N matrix A (M>= N) and stores the result + * back in A. SUNDlsMat_AddIdentity is typically used with square + * matrices. SUNDlsMat_AddIdentity does not check for M >= N and + * therefore a segmentation fault will occur if M < N! * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void AddIdentity(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_AddIdentity(SUNDlsMat A); /* * ----------------------------------------------------------------- - * Function : SetToZero + * Function : SUNDlsMat_SetToZero * ----------------------------------------------------------------- - * SetToZero sets all the elements of the M-by-N matrix A to 0.0. + * SUNDlsMat_SetToZero sets all the elements of the M-by-N matrix A + * to 0.0. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void SetToZero(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_SetToZero(SUNDlsMat A); /* * ----------------------------------------------------------------- - * Functions: PrintMat + * Functions: SUNDlsMat_PrintMat * ----------------------------------------------------------------- * This function prints the M-by-N (dense or band) matrix A to * outfile as it would normally appear on paper. @@ -313,24 +328,36 @@ SUNDIALS_EXPORT void SetToZero(DlsMat A); * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void PrintMat(DlsMat A, FILE *outfile); - +SUNDIALS_EXPORT +void SUNDlsMat_PrintMat(SUNDlsMat A, FILE* outfile); /* * ================================================================== - * Exported function prototypes (functions working on realtype**) + * Exported function prototypes (functions working on sunrealtype**) * ================================================================== */ -SUNDIALS_EXPORT realtype **newDenseMat(sunindextype m, sunindextype n); -SUNDIALS_EXPORT realtype **newBandMat(sunindextype n, sunindextype smu, - sunindextype ml); -SUNDIALS_EXPORT void destroyMat(realtype **a); -SUNDIALS_EXPORT int *newIntArray(int n); -SUNDIALS_EXPORT sunindextype *newIndexArray(sunindextype n); -SUNDIALS_EXPORT realtype *newRealArray(sunindextype m); -SUNDIALS_EXPORT void destroyArray(void *v); +SUNDIALS_EXPORT +sunrealtype** SUNDlsMat_newDenseMat(sunindextype m, sunindextype n); + +SUNDIALS_EXPORT +sunrealtype** SUNDlsMat_newBandMat(sunindextype n, sunindextype smu, + sunindextype ml); + +SUNDIALS_EXPORT +void SUNDlsMat_destroyMat(sunrealtype** a); + +SUNDIALS_EXPORT +int* SUNDlsMat_newIntArray(int n); + +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_newIndexArray(sunindextype n); + +SUNDIALS_EXPORT +sunrealtype* SUNDlsMat_newRealArray(sunindextype m); +SUNDIALS_EXPORT +void SUNDlsMat_destroyArray(void* v); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_errors.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_errors.h new file mode 100644 index 000000000..b132b0f3b --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_errors.h @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * Contains all error handling interfaces for SUNDIALS that do + * not depend on MPI. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ERRORS_H +#define _SUNDIALS_ERRORS_H + +#include +#include +#include +#include +#include +#include + +/* ---------------------------------------------------------------------------- + * Error code definitions + * ---------------------------------------------------------------------------*/ + +/* SUN_ERR_CODE_LIST is an X macro that can be expanded in various ways */ +#define SUN_ERR_CODE_LIST(ENTRY) \ + ENTRY(SUN_ERR_ARG_CORRUPT, "argument provided is NULL or corrupted") \ + ENTRY(SUN_ERR_ARG_INCOMPATIBLE, "argument provided is not compatible") \ + ENTRY(SUN_ERR_ARG_OUTOFRANGE, "argument is out of the valid range") \ + ENTRY(SUN_ERR_ARG_WRONGTYPE, "argument provided is not the right type") \ + ENTRY(SUN_ERR_ARG_DIMSMISMATCH, "argument dimensions do not agree") \ + \ + ENTRY(SUN_ERR_GENERIC, "an error occurred") \ + ENTRY(SUN_ERR_CORRUPT, "value is NULL or corrupt") \ + ENTRY(SUN_ERR_OUTOFRANGE, "Value is out of the expected range") \ + ENTRY(SUN_ERR_FILE_OPEN, "Unable to open file") \ + ENTRY(SUN_ERR_OP_FAIL, "an operation failed") \ + ENTRY(SUN_ERR_MEM_FAIL, "a memory operation failed") \ + ENTRY(SUN_ERR_MALLOC_FAIL, "malloc returned NULL") \ + ENTRY(SUN_ERR_EXT_FAIL, "a failure occurred in an external library") \ + ENTRY(SUN_ERR_DESTROY_FAIL, "a destroy function returned an error") \ + ENTRY(SUN_ERR_NOT_IMPLEMENTED, \ + "operation is not implemented: function pointer is NULL") \ + ENTRY(SUN_ERR_USER_FCN_FAIL, "the user provided callback function failed") \ + \ + ENTRY(SUN_ERR_PROFILER_MAPFULL, \ + "the number of profiler entries exceeded SUNPROFILER_MAX_ENTRIES") \ + ENTRY(SUN_ERR_PROFILER_MAPGET, "unknown error getting SUNProfiler timer") \ + ENTRY(SUN_ERR_PROFILER_MAPINSERT, \ + "unknown error inserting SUNProfiler timer") \ + ENTRY(SUN_ERR_PROFILER_MAPKEYNOTFOUND, "timer was not found in SUNProfiler") \ + ENTRY(SUN_ERR_PROFILER_MAPSORT, "error sorting SUNProfiler map") \ + \ + ENTRY(SUN_ERR_SUNCTX_CORRUPT, "SUNContext is NULL or corrupt") \ + \ + ENTRY(SUN_ERR_MPI_FAIL, \ + "an MPI call returned something other than MPI_SUCCESS") \ + \ + ENTRY(SUN_ERR_UNREACHABLE, \ + "Reached code that should be unreachable: open an issue at: " \ + "https://github.com/LLNL/sundials") \ + ENTRY(SUN_ERR_UNKNOWN, "Unknown error occured: open an issue at " \ + "https://github.com/LLNL/sundials") + +/* Expand SUN_ERR_CODE_LIST to enum */ +#define SUN_EXPAND_TO_ENUM(name, description) name, + +/* SUNErrorCode range is [-10000, -1000] to avoid conflicts with package error + codes, and old/deprecated codes for matrix and (non)linear solvers. */ + +/* clang-format off */ +enum +{ + SUN_ERR_MINIMUM = -10000, + SUN_ERR_CODE_LIST(SUN_EXPAND_TO_ENUM) + SUN_ERR_MAXIMUM = -1000, + SUN_SUCCESS = 0 +}; + +/* clang-format on */ + +/* ---------------------------------------------------------------------------- + * Error handler definitions + * ---------------------------------------------------------------------------*/ + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +void SUNLogErrHandlerFn(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNAbortErrHandlerFn(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +/* ---------------------------------------------------------------------------- + * Error functions + * ---------------------------------------------------------------------------*/ + +/* Turn error code into error message */ +SUNDIALS_EXPORT +const char* SUNGetErrMsg(SUNErrCode code); + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +} /* extern "C" */ +#endif +#endif /* _SUNDIALS_ERRORS_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fconfig.in b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fconfig.in deleted file mode 100644 index ba09e3d89..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fconfig.in +++ /dev/null @@ -1,47 +0,0 @@ -! -! ----------------------------------------------------------------- -! Programmer(s): Daniel R. Reynolds @ SMU -!----------------------------------------------------------------- -! SUNDIALS Copyright Start -! Copyright (c) 2002-2021, Lawrence Livermore National Security -! and Southern Methodist University. -! All rights reserved. -! -! See the top-level LICENSE and NOTICE files for details. -! -! SPDX-License-Identifier: BSD-3-Clause -! SUNDIALS Copyright End -! ------------------------------------------------------------------ -! SUNDIALS fortran configuration input -! ------------------------------------------------------------------ - -! Define precision of SUNDIALS data type 'realtype' as Fortran -! parameter "REALTYPE" -! -! Depending on the precision level, this value will be one of -! 4 (SUNDIALS_SINGLE_PRECISION) -! 8 (SUNDIALS_DOUBLE_PRECISION) -! 16 (SUNDIALS_EXTENDED_PRECISION) -! -integer REALTYPE -parameter (REALTYPE=@FPRECISION_LEVEL@) - -! Define type of vector indices in SUNDIALS 'sunindextype' as -! the Fortran parameter "SUNINDEXTYPE" -! -! Depending on the user choice of indextype, this will be one of -! 4 (32BIT) -! 8 (64BIT) -! -integer SUNINDEXTYPE -parameter (SUNINDEXTYPE=@SUNDIALS_FINDEX_TYPE@) - -! If building with MPI enabled, define the logical flag -! "SUNDIALS_MPI_COMM_F2C" indicating whether the user can specify -! a different MPI communicator than MPI_COMM_WORLD to FNVInitP -! -! .true. (communicator can differ from MPI_COMM_WORLD) -! .false. (communicator must be MPI_COMM_WORLD) -! -logical SUNDIALS_MPI_COMM_F2C -parameter (SUNDIALS_MPI_COMM_F2C=@FMPI_COMM_F2C@) diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fnvector.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fnvector.h deleted file mode 100644 index e1f398083..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_fnvector.h +++ /dev/null @@ -1,42 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Radu Serban and Aaron Collier @ LLNL - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * This file (companion of nvector.h) contains definitions - * needed for the initialization of vector operations in Fortran. - * -----------------------------------------------------------------*/ - - -#ifndef _FNVECTOR_H -#define _FNVECTOR_H - -#ifndef _SUNDIALS_CONFIG_H -#define _SUNDIALS_CONFIG_H -#include -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/* SUNDIALS solver IDs */ - -#define FCMIX_CVODE 1 -#define FCMIX_IDA 2 -#define FCMIX_KINSOL 3 -#define FCMIX_ARKODE 4 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_futils.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_futils.h index 1ba352a23..257e685fe 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_futils.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_futils.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,16 +20,18 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#include "sundials/sundials_types.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Create a file pointer with the given file name and mode. */ -SUNDIALS_EXPORT FILE* SUNDIALSFileOpen(const char* filename, const char* modes); +SUNDIALS_EXPORT SUNErrCode SUNDIALSFileOpen(const char* filename, + const char* modes, FILE** fp); /* Close a file pointer with the given file name. */ -SUNDIALS_EXPORT void SUNDIALSFileClose(FILE* fp); - +SUNDIALS_EXPORT SUNErrCode SUNDIALSFileClose(FILE** fp); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_iterative.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_iterative.h index 0278ff558..6192bf7f9 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_iterative.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_iterative.h @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------- * Programmer(s): Scott D. Cohen and Alan C. Hindmarsh @ LLNL + * Shelby Lockhart @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -17,90 +18,101 @@ * The function type declarations give the prototypes for the * functions to be called within an iterative linear solver, that * are responsible for - * multiplying A by a given vector v (ATimesFn), - * setting up a preconditioner P (PSetupFn), and - * solving the preconditioner equation Pz = r (PSolveFn). + * multiplying A by a given vector v (SUNATimesFn), + * setting up a preconditioner P (SUNPSetupFn), and + * solving the preconditioner equation Pz = r (SUNPSolveFn). * -----------------------------------------------------------------*/ -#ifndef _ITERATIVE_H -#define _ITERATIVE_H +#ifndef _SUNDIALS_ITERATIVE_H +#define _SUNDIALS_ITERATIVE_H +#include +#include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /* * ----------------------------------------------------------------- * enum : types of preconditioning * ----------------------------------------------------------------- - * PREC_NONE : The iterative linear solver should not use - * preconditioning. + * SUN_PREC_NONE : The iterative linear solver should not use + * preconditioning. * - * PREC_LEFT : The iterative linear solver uses preconditioning on - * the left only. + * SUN_PREC_LEFT : The iterative linear solver uses preconditioning + * on the left only. * - * PREC_RIGHT : The iterative linear solver uses preconditioning on - * the right only. + * SUN_PREC_RIGHT : The iterative linear solver uses preconditioning + * on the right only. * - * PREC_BOTH : The iterative linear solver uses preconditioning on - * both the left and the right. + * SUN_PREC_BOTH : The iterative linear solver uses preconditioning + * on both the left and the right. * ----------------------------------------------------------------- */ -enum { PREC_NONE, PREC_LEFT, PREC_RIGHT, PREC_BOTH }; +enum +{ + SUN_PREC_NONE, + SUN_PREC_LEFT, + SUN_PREC_RIGHT, + SUN_PREC_BOTH +}; /* * ----------------------------------------------------------------- * enum : types of Gram-Schmidt routines * ----------------------------------------------------------------- - * MODIFIED_GS : The iterative solver uses the modified - * Gram-Schmidt routine ModifiedGS listed in this - * file. + * SUN_MODIFIED_GS : The iterative solver uses the modified + * Gram-Schmidt routine SUNModifiedGS listed in + * this file. * - * CLASSICAL_GS : The iterative solver uses the classical - * Gram-Schmidt routine ClassicalGS listed in this - * file. + * SUN_CLASSICAL_GS : The iterative solver uses the classical + * Gram-Schmidt routine SUNClassicalGS listed in + * this file. * ----------------------------------------------------------------- */ -enum { MODIFIED_GS = 1, CLASSICAL_GS = 2 }; +enum +{ + SUN_MODIFIED_GS = 1, + SUN_CLASSICAL_GS = 2 +}; /* * ----------------------------------------------------------------- - * Type: ATimesFn + * Type: SUNATimesFn * ----------------------------------------------------------------- - * An ATimesFn multiplies Av and stores the result in z. The + * An SUNATimesFn multiplies Av and stores the result in z. The * caller is responsible for allocating memory for the z vector. * The parameter A_data is a pointer to any information about A * which the function needs in order to do its job. The vector v - * is unchanged. An ATimesFn returns 0 if successful and a + * is unchanged. An SUNATimesFn returns 0 if successful and a * non-zero value if unsuccessful. * ----------------------------------------------------------------- */ -typedef int (*ATimesFn)(void *A_data, N_Vector v, N_Vector z); +typedef int (*SUNATimesFn)(void* A_data, N_Vector v, N_Vector z); /* * ----------------------------------------------------------------- - * Type: PSetupFn + * Type: SUNPSetupFn * ----------------------------------------------------------------- - * A PSetupFn is an integrator-supplied routine that accesses data - * stored in the integrator memory structure (P_data), and calls - * the user-supplied, integrator-specific preconditioner setup - * routine. + * A SUNPSetupFn is an integrator-supplied routine that accesses data + * stored in the integrator memory structure (P_data), and calls the + * user-supplied, integrator-specific preconditioner setup routine. * ----------------------------------------------------------------- */ -typedef int (*PSetupFn)(void *P_data); +typedef int (*SUNPSetupFn)(void* P_data); /* * ----------------------------------------------------------------- - * Type: PSolveFn + * Type: SUNPSolveFn * ----------------------------------------------------------------- - * A PSolveFn solves the preconditioner equation Pz = r for the + * A SUNPSolveFn solves the preconditioner equation Pz = r for the * vector z. The caller is responsible for allocating memory for * the z vector. The parameter P_data is a pointer to any * information about P which the function needs in order to do @@ -113,8 +125,8 @@ typedef int (*PSetupFn)(void *P_data); * || Pz - r ||_wrms < tol * where the weight vector for the WRMS norm may be accessed from * the main integrator memory structure. - * The vector r should not be modified by the PSolveFn. - * A PSolveFn returns 0 if successful and a non-zero value if + * The vector r should not be modified by the SUNPSolveFn. + * A SUNPSolveFn returns 0 if successful and a non-zero value if * unsuccessful. On a failure, a negative return value indicates * an unrecoverable condition, while a positive value indicates * a recoverable one, in which the calling routine may reattempt @@ -122,14 +134,41 @@ typedef int (*PSetupFn)(void *P_data); * ----------------------------------------------------------------- */ -typedef int (*PSolveFn)(void *P_data, N_Vector r, N_Vector z, - realtype tol, int lr); +typedef int (*SUNPSolveFn)(void* P_data, N_Vector r, N_Vector z, + sunrealtype tol, int lr); /* * ----------------------------------------------------------------- - * Function: ModifiedGS + * Type: SUNQRAddFn * ----------------------------------------------------------------- - * ModifiedGS performs a modified Gram-Schmidt orthogonalization + * A QRAddFn updates a given QR factorization defined by the input + * parameters: + * Q : N_Vector * + * R : sunrealtype * + * with the input vector + * f : N_Vector + * + * Additional input parameters include: + * + * m : (int) the number of vectors already in the QR factorization + * + * mMax : (int) the maximum number of vectors to be in the QR + * factorization (the number of N_Vectors allocated to be in Q) + * + * SUNQR_data : (void *) a structure containing any additional inputs + * required for the execution of QRAddFn + * + * ----------------------------------------------------------------- + */ + +typedef int (*SUNQRAddFn)(N_Vector* Q, sunrealtype* R, N_Vector f, int m, + int mMax, void* QR_data); + +/* + * ----------------------------------------------------------------- + * Function: SUNModifiedGS + * ----------------------------------------------------------------- + * SUNModifiedGS performs a modified Gram-Schmidt orthogonalization * of the N_Vector v[k] against the p unit N_Vectors at * v[k-1], v[k-2], ..., v[k-p]. * @@ -152,47 +191,49 @@ typedef int (*PSolveFn)(void *P_data, N_Vector r, N_Vector z, * new_vk_norm is a pointer to memory allocated by the caller to * hold the Euclidean norm of the orthogonalized vector v[k]. * - * If (k-p) < 0, then ModifiedGS uses p=k. The orthogonalized + * If (k-p) < 0, then SUNModifiedGS uses p=k. The orthogonalized * v[k] is NOT normalized and is stored over the old v[k]. Once * the orthogonalization has been performed, the Euclidean norm * of v[k] is stored in (*new_vk_norm). * - * ModifiedGS returns 0 to indicate success. It cannot fail. + * SUNModifiedGS returns 0 to indicate success. It cannot fail. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int ModifiedGS(N_Vector* v, realtype **h, int k, int p, - realtype *new_vk_norm); +SUNDIALS_EXPORT +SUNErrCode SUNModifiedGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm); /* * ----------------------------------------------------------------- - * Function: ClassicalGS + * Function: SUNClassicalGS * ----------------------------------------------------------------- - * ClassicalGS performs a classical Gram-Schmidt + * SUNClassicalGS performs a classical Gram-Schmidt * orthogonalization of the N_Vector v[k] against the p unit * N_Vectors at v[k-1], v[k-2], ..., v[k-p]. The parameters v, h, * k, p, and new_vk_norm are as described in the documentation - * for ModifiedGS. + * for SUNModifiedGS. * - * stemp is a length k+1 array of realtype which can be used as - * workspace by the ClassicalGS routine. + * stemp is a length k+1 array of sunrealtype which can be used as + * workspace by the SUNClassicalGS routine. * * vtemp is an N_Vector array of k+1 vectors which can be used as - * workspace by the ClassicalGS routine. + * workspace by the SUNClassicalGS routine. * - * ClassicalGS returns 0 to indicate success. + * SUNClassicalGS returns 0 to indicate success. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int ClassicalGS(N_Vector* v, realtype **h, int k, int p, - realtype *new_vk_norm, realtype *stemp, - N_Vector* vtemp); +SUNDIALS_EXPORT +SUNErrCode SUNClassicalGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm, sunrealtype* stemp, + N_Vector* vtemp); /* * ----------------------------------------------------------------- - * Function: QRfact + * Function: SUNQRfact * ----------------------------------------------------------------- - * QRfact performs a QR factorization of the Hessenberg matrix H. + * SUNQRfact performs a QR factorization of the Hessenberg matrix H. * * n is the problem size; the matrix H is (n+1) by n. * @@ -211,50 +252,220 @@ SUNDIALS_EXPORT int ClassicalGS(N_Vector* v, realtype **h, int k, int p, * n-1 columns of h have already been factored and only the last * column needs to be updated. * - * QRfact returns 0 if successful. If a zero is encountered on - * the diagonal of the triangular factor R, then QRfact returns + * SUNQRfact returns 0 if successful. If a zero is encountered on + * the diagonal of the triangular factor R, then SUNQRfact returns * the equation number of the zero entry, where the equations are - * numbered from 1, not 0. If QRsol is subsequently called in + * numbered from 1, not 0. If SUNQRsol is subsequently called in * this situation, it will return an error because it could not * divide by the zero diagonal entry. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int QRfact(int n, realtype **h, realtype *q, int job); +SUNDIALS_EXPORT +int SUNQRfact(int n, sunrealtype** h, sunrealtype* q, int job); /* * ----------------------------------------------------------------- - * Function: QRsol + * Function: SUNQRsol * ----------------------------------------------------------------- - * QRsol solves the linear least squares problem + * SUNQRsol solves the linear least squares problem * * min (b - H*x, b - H*x), x in R^n, * * where H is a Hessenberg matrix, and b is in R^(n+1). - * It uses the QR factors of H computed by QRfact. + * It uses the QR factors of H computed by SUNQRfact. * * n is the problem size; the matrix H is (n+1) by n. * - * h is a matrix (computed by QRfact) containing the upper + * h is a matrix (computed by SUNQRfact) containing the upper * triangular factor R of the original Hessenberg matrix H. * - * q is an array of length 2*n (computed by QRfact) containing + * q is an array of length 2*n (computed by SUNQRfact) containing * the Givens rotations used to factor H. * * b is the (n+1)-vector appearing in the least squares problem * above. * * On return, b contains the solution x of the least squares - * problem, if QRsol was successful. + * problem, if SUNQRsol was successful. * - * QRsol returns a 0 if successful. Otherwise, a zero was + * SUNQRsol returns a 0 if successful. Otherwise, a zero was * encountered on the diagonal of the triangular factor R. - * In this case, QRsol returns the equation number (numbered + * In this case, SUNQRsol returns the equation number (numbered * from 1, not 0) of the zero entry. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int QRsol(int n, realtype **h, realtype *q, realtype *b); +SUNDIALS_EXPORT +int SUNQRsol(int n, sunrealtype** h, sunrealtype* q, sunrealtype* b); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_MGS + * ----------------------------------------------------------------- + * SUNQRAdd_MGS uses Modified Gram Schmidt to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_MGS was successful. + * + * SUNQRAdd_MGS returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_MGS(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY + * ----------------------------------------------------------------- + * SUNQRAdd_ICWY uses the Inverse Compact WY Modified Gram Schmidt + * method to update the QR factorization stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * - sunrealtype *T (held within (void *) QRdata) + * to include the orthonormalized vector input by + * - N_Vector df. + * where the factorization to be updated is of the form + * Q * T * R + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, sunrealtype *temp_array (this will be used for T) + * + * On return, Q, R, and T contain the updated Q T R factors, if + * SUNQRAdd_ICWY was successful. + * + * SUNQRAdd_ICWY returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_ICWY(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_ICWY but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_ICWY_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_CGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_CGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation to update the QR factorization stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, sunrealtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_CGS2 was successful. + * + * SUNQRAdd_CGS2 returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_CGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_DCGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation that delays reorthogonlization (for the purpose of + * reducing number of inner products) to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - sunrealtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, sunrealtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_DCGS2 was successful. + * + * SUNQRAdd_DCGS2 returns a 0 if successful. Otherwise,.... + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_DCGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_DCGS2 but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +SUNErrCode SUNQRAdd_DCGS2_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_lapack.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_lapack.h deleted file mode 100644 index 089625a22..000000000 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_lapack.h +++ /dev/null @@ -1,256 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer: Radu Serban @ LLNL - * Daniel Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * This is the header file for a generic package of direct matrix - * operations for use with BLAS/LAPACK. - * -----------------------------------------------------------------*/ - -#ifndef _SUNDIALS_LAPACK_H -#define _SUNDIALS_LAPACK_H - -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/* - * ================================================================== - * Blas and Lapack functions - * ================================================================== - */ - -#if defined(SUNDIALS_F77_FUNC) - -#define dcopy_f77 SUNDIALS_F77_FUNC(dcopy, DCOPY) -#define dscal_f77 SUNDIALS_F77_FUNC(dscal, DSCAL) -#define dgemv_f77 SUNDIALS_F77_FUNC(dgemv, DGEMV) -#define dtrsv_f77 SUNDIALS_F77_FUNC(dtrsv, DTRSV) -#define dsyrk_f77 SUNDIALS_F77_FUNC(dsyrk, DSKYR) - -#define dgbtrf_f77 SUNDIALS_F77_FUNC(dgbtrf, DGBTRF) -#define dgbtrs_f77 SUNDIALS_F77_FUNC(dgbtrs, DGBTRS) -#define dgetrf_f77 SUNDIALS_F77_FUNC(dgetrf, DGETRF) -#define dgetrs_f77 SUNDIALS_F77_FUNC(dgetrs, DGETRS) -#define dgeqp3_f77 SUNDIALS_F77_FUNC(dgeqp3, DGEQP3) -#define dgeqrf_f77 SUNDIALS_F77_FUNC(dgeqrf, DGEQRF) -#define dormqr_f77 SUNDIALS_F77_FUNC(dormqr, DORMQR) -#define dpotrf_f77 SUNDIALS_F77_FUNC(dpotrf, DPOTRF) -#define dpotrs_f77 SUNDIALS_F77_FUNC(dpotrs, DPOTRS) - -#define scopy_f77 SUNDIALS_F77_FUNC(scopy, SCOPY) -#define sscal_f77 SUNDIALS_F77_FUNC(sscal, SSCAL) -#define sgemv_f77 SUNDIALS_F77_FUNC(sgemv, SGEMV) -#define strsv_f77 SUNDIALS_F77_FUNC(strsv, STRSV) -#define ssyrk_f77 SUNDIALS_F77_FUNC(ssyrk, SSKYR) - -#define sgbtrf_f77 SUNDIALS_F77_FUNC(sgbtrf, SGBTRF) -#define sgbtrs_f77 SUNDIALS_F77_FUNC(sgbtrs, SGBTRS) -#define sgetrf_f77 SUNDIALS_F77_FUNC(sgetrf, SGETRF) -#define sgetrs_f77 SUNDIALS_F77_FUNC(sgetrs, SGETRS) -#define sgeqp3_f77 SUNDIALS_F77_FUNC(sgeqp3, SGEQP3) -#define sgeqrf_f77 SUNDIALS_F77_FUNC(sgeqrf, SGEQRF) -#define sormqr_f77 SUNDIALS_F77_FUNC(sormqr, SORMQR) -#define spotrf_f77 SUNDIALS_F77_FUNC(spotrf, SPOTRF) -#define spotrs_f77 SUNDIALS_F77_FUNC(spotrs, SPOTRS) - -#else - -#define dcopy_f77 dcopy_ -#define dscal_f77 dscal_ -#define dgemv_f77 dgemv_ -#define dtrsv_f77 dtrsv_ -#define dsyrk_f77 dsyrk_ - -#define dgbtrf_f77 dgbtrf_ -#define dgbtrs_f77 dgbtrs_ -#define dgeqp3_f77 dgeqp3_ -#define dgeqrf_f77 dgeqrf_ -#define dgetrf_f77 dgetrf_ -#define dgetrs_f77 dgetrs_ -#define dormqr_f77 dormqr_ -#define dpotrf_f77 dpotrf_ -#define dpotrs_f77 dpotrs_ - -#define scopy_f77 scopy_ -#define sscal_f77 sscal_ -#define sgemv_f77 sgemv_ -#define strsv_f77 strsv_ -#define ssyrk_f77 ssyrk_ - -#define sgbtrf_f77 sgbtrf_ -#define sgbtrs_f77 sgbtrs_ -#define sgeqp3_f77 sgeqp3_ -#define sgeqrf_f77 sgeqrf_ -#define sgetrf_f77 sgetrf_ -#define sgetrs_f77 sgetrs_ -#define sormqr_f77 sormqr_ -#define spotrf_f77 spotrf_ -#define spotrs_f77 spotrs_ - -#endif - -/* Level-1 BLAS */ - -extern void dcopy_f77(sunindextype *n, const double *x, - const sunindextype *inc_x, double *y, - const sunindextype *inc_y); - -extern void dscal_f77(sunindextype *n, const double *alpha, double *x, - const sunindextype *inc_x); - -extern void scopy_f77(sunindextype *n, const float *x, - const sunindextype *inc_x, float *y, - const sunindextype *inc_y); - -extern void sscal_f77(sunindextype *n, const float *alpha, float *x, - const sunindextype *inc_x); - -/* Level-2 BLAS */ - -extern void dgemv_f77(const char *trans, sunindextype *m, sunindextype *n, - const double *alpha, const double *a, sunindextype *lda, - const double *x, sunindextype *inc_x, const double *beta, - double *y, sunindextype *inc_y); - -extern void dtrsv_f77(const char *uplo, const char *trans, const char *diag, - const sunindextype *n, const double *a, - const sunindextype *lda, double *x, - const sunindextype *inc_x); - -extern void sgemv_f77(const char *trans, sunindextype *m, sunindextype *n, - const float *alpha, const float *a, sunindextype *lda, - const float *x, sunindextype *inc_x, const float *beta, - float *y, sunindextype *inc_y); - -extern void strsv_f77(const char *uplo, const char *trans, const char *diag, - const sunindextype *n, const float *a, - const sunindextype *lda, float *x, - const sunindextype *inc_x); - -/* Level-3 BLAS */ - -extern void dsyrk_f77(const char *uplo, const char *trans, - const sunindextype *n, const sunindextype *k, - const double *alpha, const double *a, - const sunindextype *lda, const double *beta, - const double *c, const sunindextype *ldc); - -extern void ssyrk_f77(const char *uplo, const char *trans, - const sunindextype *n, const sunindextype *k, - const float *alpha, const float *a, - const sunindextype *lda, const float *beta, - const float *c, const sunindextype *ldc); - -/* LAPACK */ - -extern void dgbtrf_f77(const sunindextype *m, const sunindextype *n, - const sunindextype *kl, const sunindextype *ku, - double *ab, sunindextype *ldab, sunindextype *ipiv, - sunindextype *info); - -extern void dgbtrs_f77(const char *trans, const sunindextype *n, - const sunindextype *kl, const sunindextype *ku, - const sunindextype *nrhs, double *ab, - const sunindextype *ldab, sunindextype *ipiv, - double *b, const sunindextype *ldb, sunindextype *info); - - -extern void dgeqp3_f77(const sunindextype *m, const sunindextype *n, double *a, - const sunindextype *lda, sunindextype *jpvt, double *tau, - double *work, const sunindextype *lwork, - sunindextype *info); - -extern void dgeqrf_f77(const sunindextype *m, const sunindextype *n, double *a, - const sunindextype *lda, double *tau, double *work, - const sunindextype *lwork, sunindextype *info); - -extern void dgetrf_f77(const sunindextype *m, const sunindextype *n, double *a, - sunindextype *lda, sunindextype *ipiv, - sunindextype *info); - -extern void dgetrs_f77(const char *trans, const sunindextype *n, - const sunindextype *nrhs, double *a, - const sunindextype *lda, sunindextype *ipiv, double *b, - const sunindextype *ldb, sunindextype *info); - - -extern void dormqr_f77(const char *side, const char *trans, - const sunindextype *m, const sunindextype *n, - const sunindextype *k, double *a, - const sunindextype *lda, double *tau, double *c, - const sunindextype *ldc, double *work, - const sunindextype *lwork, sunindextype *info); - -extern void dpotrf_f77(const char *uplo, const sunindextype *n, double *a, - sunindextype *lda, sunindextype *info); - -extern void dpotrs_f77(const char *uplo, const sunindextype *n, - const sunindextype *nrhs, double *a, - const sunindextype *lda, double *b, - const sunindextype *ldb, sunindextype *info); - - -extern void sgbtrf_f77(const sunindextype *m, const sunindextype *n, - const sunindextype *kl, const sunindextype *ku, - float *ab, sunindextype *ldab, sunindextype *ipiv, - sunindextype *info); - -extern void sgbtrs_f77(const char *trans, const sunindextype *n, - const sunindextype *kl, const sunindextype *ku, - const sunindextype *nrhs, float *ab, - const sunindextype *ldab, sunindextype *ipiv, - float *b, const sunindextype *ldb, sunindextype *info); - - -extern void sgeqp3_f77(const sunindextype *m, const sunindextype *n, float *a, - const sunindextype *lda, sunindextype *jpvt, float *tau, - float *work, const sunindextype *lwork, - sunindextype *info); - -extern void sgeqrf_f77(const sunindextype *m, const sunindextype *n, float *a, - const sunindextype *lda, float *tau, float *work, - const sunindextype *lwork, sunindextype *info); - -extern void sgetrf_f77(const sunindextype *m, const sunindextype *n, float *a, - sunindextype *lda, sunindextype *ipiv, - sunindextype *info); - -extern void sgetrs_f77(const char *trans, const sunindextype *n, - const sunindextype *nrhs, float *a, - const sunindextype *lda, sunindextype *ipiv, - float *b, const sunindextype *ldb, sunindextype *info); - - -extern void sormqr_f77(const char *side, const char *trans, - const sunindextype *m, const sunindextype *n, - const sunindextype *k, float *a, const sunindextype *lda, - float *tau, float *c, const sunindextype *ldc, - float *work, const sunindextype *lwork, - sunindextype *info); - -extern void spotrf_f77(const char *uplo, const sunindextype *n, float *a, - sunindextype *lda, sunindextype *info); - -extern void spotrs_f77(const char *uplo, const sunindextype *n, - const sunindextype *nrhs, float *a, - const sunindextype *lda, float *b, - const sunindextype *ldb, sunindextype *info); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.h index ad3b05116..6aa6c065f 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.h @@ -4,7 +4,7 @@ * Slaven Peles, Cody Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -53,28 +53,32 @@ #ifndef _SUNLINEARSOLVER_H #define _SUNLINEARSOLVER_H -#include +#include +#include +#include #include #include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /* ----------------------------------------------------------------- * Implemented SUNLinearSolver types and IDs: * ----------------------------------------------------------------- */ -typedef enum { +typedef enum +{ SUNLINEARSOLVER_DIRECT, SUNLINEARSOLVER_ITERATIVE, SUNLINEARSOLVER_MATRIX_ITERATIVE, SUNLINEARSOLVER_MATRIX_EMBEDDED } SUNLinearSolver_Type; -typedef enum { +typedef enum +{ SUNLINEARSOLVER_BAND, SUNLINEARSOLVER_DENSE, SUNLINEARSOLVER_KLU, @@ -90,122 +94,137 @@ typedef enum { SUNLINEARSOLVER_CUSOLVERSP_BATCHQR, SUNLINEARSOLVER_MAGMADENSE, SUNLINEARSOLVER_ONEMKLDENSE, + SUNLINEARSOLVER_GINKGO, + SUNLINEARSOLVER_KOKKOSDENSE, SUNLINEARSOLVER_CUSTOM } SUNLinearSolver_ID; - /* ----------------------------------------------------------------- * Generic definition of SUNLinearSolver * ----------------------------------------------------------------- */ /* Forward reference for pointer to SUNLinearSolver_Ops object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver_Ops *SUNLinearSolver_Ops; +typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver_Ops* SUNLinearSolver_Ops; /* Forward reference for pointer to SUNLinearSolver object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver *SUNLinearSolver; +typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver* SUNLinearSolver; /* Structure containing function pointers to linear solver operations */ -struct _generic_SUNLinearSolver_Ops { +struct _generic_SUNLinearSolver_Ops +{ SUNLinearSolver_Type (*gettype)(SUNLinearSolver); - SUNLinearSolver_ID (*getid)(SUNLinearSolver); - int (*setatimes)(SUNLinearSolver, void*, ATimesFn); - int (*setpreconditioner)(SUNLinearSolver, void*, - PSetupFn, PSolveFn); - int (*setscalingvectors)(SUNLinearSolver, - N_Vector, N_Vector); - int (*setzeroguess)(SUNLinearSolver, booleantype); - int (*initialize)(SUNLinearSolver); - int (*setup)(SUNLinearSolver, SUNMatrix); - int (*solve)(SUNLinearSolver, SUNMatrix, N_Vector, - N_Vector, realtype); - int (*numiters)(SUNLinearSolver); - realtype (*resnorm)(SUNLinearSolver); - sunindextype (*lastflag)(SUNLinearSolver); - int (*space)(SUNLinearSolver, long int*, long int*); - N_Vector (*resid)(SUNLinearSolver); - int (*free)(SUNLinearSolver); + SUNLinearSolver_ID (*getid)(SUNLinearSolver); + SUNErrCode (*setatimes)(SUNLinearSolver, void*, SUNATimesFn); + SUNErrCode (*setpreconditioner)(SUNLinearSolver, void*, SUNPSetupFn, + SUNPSolveFn); + SUNErrCode (*setscalingvectors)(SUNLinearSolver, N_Vector, N_Vector); + SUNErrCode (*setzeroguess)(SUNLinearSolver, sunbooleantype); + SUNErrCode (*initialize)(SUNLinearSolver); + int (*setup)(SUNLinearSolver, SUNMatrix); + int (*solve)(SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, sunrealtype); + int (*numiters)(SUNLinearSolver); + sunrealtype (*resnorm)(SUNLinearSolver); + sunindextype (*lastflag)(SUNLinearSolver); + SUNErrCode (*space)(SUNLinearSolver, long int*, long int*); + N_Vector (*resid)(SUNLinearSolver); + SUNErrCode (*free)(SUNLinearSolver); }; /* A linear solver is a structure with an implementation-dependent 'content' field, and a pointer to a structure of linear solver operations corresponding to that implementation. */ -struct _generic_SUNLinearSolver { - void *content; +struct _generic_SUNLinearSolver +{ + void* content; SUNLinearSolver_Ops ops; + SUNContext sunctx; }; - /* ----------------------------------------------------------------- * Functions exported by SUNLinearSolver module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSolNewEmpty(); - -SUNDIALS_EXPORT void SUNLinSolFreeEmpty(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx); -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType(SUNLinearSolver S); +SUNDIALS_EXPORT +void SUNLinSolFreeEmpty(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, - PSetupFn Pset, PSolveFn Psol); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, - N_Vector s2); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess(SUNLinearSolver S, booleantype onoff); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, + N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolInitialize(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetZeroGuess(SUNLinearSolver S, sunbooleantype onoff); -SUNDIALS_EXPORT int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, - N_Vector b, realtype tol); +SUNDIALS_EXPORT +int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A); -SUNDIALS_EXPORT int SUNLinSolNumIters(SUNLinearSolver S); +SUNDIALS_EXPORT +int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); -SUNDIALS_EXPORT realtype SUNLinSolResNorm(SUNLinearSolver S); +/* TODO(CJB): We should consider changing the return type to long int since + batched solvers could in theory return a very large number here. */ +SUNDIALS_EXPORT +int SUNLinSolNumIters(SUNLinearSolver S); -SUNDIALS_EXPORT N_Vector SUNLinSolResid(SUNLinearSolver S); +SUNDIALS_EXPORT +sunrealtype SUNLinSolResNorm(SUNLinearSolver S); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag(SUNLinearSolver S); +SUNDIALS_EXPORT +N_Vector SUNLinSolResid(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace(SUNLinearSolver S, long int *lenrwLS, - long int *leniwLS); +/* TODO(CJB): sunindextype being the return type here could cause a problem if + sunindextype happened to be smaller than an int. */ +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolFree(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree(SUNLinearSolver S); /* ----------------------------------------------------------------- * SUNLinearSolver return values * ----------------------------------------------------------------- */ -#define SUNLS_SUCCESS 0 /* successful/converged */ - -#define SUNLS_MEM_NULL -801 /* mem argument is NULL */ -#define SUNLS_ILL_INPUT -802 /* illegal function input */ -#define SUNLS_MEM_FAIL -803 /* failed memory access */ -#define SUNLS_ATIMES_NULL -804 /* atimes function is NULL */ -#define SUNLS_ATIMES_FAIL_UNREC -805 /* atimes unrecoverable failure */ -#define SUNLS_PSET_FAIL_UNREC -806 /* pset unrecoverable failure */ -#define SUNLS_PSOLVE_NULL -807 /* psolve function is NULL */ -#define SUNLS_PSOLVE_FAIL_UNREC -808 /* psolve unrecoverable failure */ -#define SUNLS_PACKAGE_FAIL_UNREC -809 /* external package unrec. fail */ -#define SUNLS_GS_FAIL -810 /* Gram-Schmidt failure */ -#define SUNLS_QRSOL_FAIL -811 /* QRsol found singular R */ -#define SUNLS_VECTOROP_ERR -812 /* vector operation error */ - -#define SUNLS_RES_REDUCED 801 /* nonconv. solve, resid reduced */ -#define SUNLS_CONV_FAIL 802 /* nonconvergent solve */ -#define SUNLS_ATIMES_FAIL_REC 803 /* atimes failed recoverably */ -#define SUNLS_PSET_FAIL_REC 804 /* pset failed recoverably */ -#define SUNLS_PSOLVE_FAIL_REC 805 /* psolve failed recoverably */ -#define SUNLS_PACKAGE_FAIL_REC 806 /* external package recov. fail */ -#define SUNLS_QRFACT_FAIL 807 /* QRfact found singular matrix */ -#define SUNLS_LUFACT_FAIL 808 /* LUfact found singular matrix */ +#define SUNLS_ATIMES_NULL -804 /* atimes function is NULL */ +#define SUNLS_ATIMES_FAIL_UNREC -805 /* atimes unrecoverable failure */ +#define SUNLS_PSET_FAIL_UNREC -806 /* pset unrecoverable failure */ +#define SUNLS_PSOLVE_NULL -807 /* psolve function is NULL */ +#define SUNLS_PSOLVE_FAIL_UNREC -808 /* psolve unrecoverable failure */ +#define SUNLS_GS_FAIL -810 /* Gram-Schmidt failure */ +#define SUNLS_QRSOL_FAIL -811 /* QRsol found singular R */ + +#define SUNLS_RECOV_FAILURE 800 /* generic recoverable failure */ +#define SUNLS_RES_REDUCED 801 /* nonconv. solve, resid reduced */ +#define SUNLS_CONV_FAIL 802 /* nonconvergent solve */ +#define SUNLS_ATIMES_FAIL_REC 803 /* atimes failed recoverably */ +#define SUNLS_PSET_FAIL_REC 804 /* pset failed recoverably */ +#define SUNLS_PSOLVE_FAIL_REC 805 /* psolve failed recoverably */ +#define SUNLS_PACKAGE_FAIL_REC 806 /* external package recov. fail */ +#define SUNLS_QRFACT_FAIL 807 /* QRfact found singular matrix */ +#define SUNLS_LUFACT_FAIL 808 /* LUfact found singular matrix */ /* ----------------------------------------------------------------------------- * SUNLinearSolver messages diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.hpp new file mode 100644 index 000000000..54266119a --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_linearsolver.hpp @@ -0,0 +1,43 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNLinaerSolver + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_LINEARSOLVER_HPP +#define _SUNDIALS_LINEARSOLVER_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseLinearSolver = + BaseObject<_generic_SUNLinearSolver, _generic_SUNLinearSolver_Ops>; +} // namespace impl + +namespace experimental { +struct SUNLinearSolverDeleter +{ + void operator()(SUNLinearSolver LS) + { + if (LS) { SUNLinSolFree(LS); } + } +}; + +using SUNLinearSolverView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_logger.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_logger.h new file mode 100644 index 000000000..7525404b2 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_logger.h @@ -0,0 +1,74 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_LOGGER_H +#define _SUNDIALS_LOGGER_H + +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef enum +{ + SUN_LOGLEVEL_ALL = -1, + SUN_LOGLEVEL_NONE = 0, + SUN_LOGLEVEL_ERROR = 1, + SUN_LOGLEVEL_WARNING = 2, + SUN_LOGLEVEL_INFO = 3, + SUN_LOGLEVEL_DEBUG = 4 +} SUNLogLevel; + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Create(SUNComm comm, int output_rank, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_CreateFromEnv(SUNComm comm, SUNLogger* logger); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetErrorFilename(SUNLogger logger, + const char* error_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetWarningFilename(SUNLogger logger, + const char* warning_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetDebugFilename(SUNLogger logger, + const char* debug_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_SetInfoFilename(SUNLogger logger, const char* info_filename); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl, + const char* scope, const char* label, + const char* msg_txt, ...); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Flush(SUNLogger logger, SUNLogLevel lvl); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_GetOutputRank(SUNLogger logger, int* output_rank); + +SUNDIALS_EXPORT +SUNErrCode SUNLogger_Destroy(SUNLogger* logger); + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +} +#endif +#endif /* SUNDIALS_LOGGER_H_ */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_math.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_math.h index f79344e5d..4585c7c7f 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_math.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_math.h @@ -4,7 +4,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,7 +14,7 @@ * SUNDIALS Copyright End * ----------------------------------------------------------------- * This is the header file for a simple C-language math library. The - * routines listed here work with the type realtype as defined in + * routines listed here work with the type sunrealtype as defined in * the header file sundials_types.h. * ----------------------------------------------------------------- */ @@ -23,10 +23,9 @@ #define _SUNDIALSMATH_H #include - #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -59,14 +58,14 @@ extern "C" { #endif #ifndef SUNSQR -#define SUNSQR(A) ((A)*(A)) +#define SUNSQR(A) ((A) * (A)) #endif /* * ----------------------------------------------------------------- * Function : SUNRsqrt * ----------------------------------------------------------------- - * Usage : realtype sqrt_x; + * Usage : sunrealtype sqrt_x; * sqrt_x = SUNRsqrt(x); * ----------------------------------------------------------------- * SUNRsqrt(x) returns the square root of x. If x < ZERO, then @@ -75,14 +74,15 @@ extern "C" { */ #ifndef SUNRsqrt -#if defined(SUNDIALS_USE_GENERIC_MATH) -#define SUNRsqrt(x) ((x) <= RCONST(0.0) ? (RCONST(0.0)) : ((realtype) sqrt((double) (x)))) -#elif defined(SUNDIALS_DOUBLE_PRECISION) -#define SUNRsqrt(x) ((x) <= RCONST(0.0) ? (RCONST(0.0)) : (sqrt((x)))) +#if defined(SUNDIALS_DOUBLE_PRECISION) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrt((x)))) #elif defined(SUNDIALS_SINGLE_PRECISION) -#define SUNRsqrt(x) ((x) <= RCONST(0.0) ? (RCONST(0.0)) : (sqrtf((x)))) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrtf((x)))) #elif defined(SUNDIALS_EXTENDED_PRECISION) -#define SUNRsqrt(x) ((x) <= RCONST(0.0) ? (RCONST(0.0)) : (sqrtl((x)))) +#define SUNRsqrt(x) ((x) <= SUN_RCONST(0.0) ? (SUN_RCONST(0.0)) : (sqrtl((x)))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" #endif #endif @@ -90,7 +90,7 @@ extern "C" { * ----------------------------------------------------------------- * Function : SUNRabs * ----------------------------------------------------------------- - * Usage : realtype abs_x; + * Usage : sunrealtype abs_x; * abs_x = SUNRabs(x); * ----------------------------------------------------------------- * SUNRabs(x) returns the absolute value of x. @@ -98,14 +98,15 @@ extern "C" { */ #ifndef SUNRabs -#if defined(SUNDIALS_USE_GENERIC_MATH) -#define SUNRabs(x) ((realtype) fabs((double) (x))) -#elif defined(SUNDIALS_DOUBLE_PRECISION) +#if defined(SUNDIALS_DOUBLE_PRECISION) #define SUNRabs(x) (fabs((x))) #elif defined(SUNDIALS_SINGLE_PRECISION) #define SUNRabs(x) (fabsf((x))) #elif defined(SUNDIALS_EXTENDED_PRECISION) #define SUNRabs(x) (fabsl((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" #endif #endif @@ -113,7 +114,7 @@ extern "C" { * ----------------------------------------------------------------- * Function : SUNRexp * ----------------------------------------------------------------- - * Usage : realtype exp_x; + * Usage : sunrealtype exp_x; * exp_x = SUNRexp(x); * ----------------------------------------------------------------- * SUNRexp(x) returns e^x (base-e exponential function). @@ -121,14 +122,15 @@ extern "C" { */ #ifndef SUNRexp -#if defined(SUNDIALS_USE_GENERIC_MATH) -#define SUNRexp(x) ((realtype) exp((double) (x))) -#elif defined(SUNDIALS_DOUBLE_PRECISION) +#if defined(SUNDIALS_DOUBLE_PRECISION) #define SUNRexp(x) (exp((x))) #elif defined(SUNDIALS_SINGLE_PRECISION) #define SUNRexp(x) (expf((x))) #elif defined(SUNDIALS_EXTENDED_PRECISION) #define SUNRexp(x) (expl((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" #endif #endif @@ -136,7 +138,7 @@ extern "C" { * ----------------------------------------------------------------- * Function : SUNRceil * ----------------------------------------------------------------- - * Usage : realtype ceil_x; + * Usage : sunrealtype ceil_x; * ceil_x = SUNRceil(x); * ----------------------------------------------------------------- * SUNRceil(x) returns the smallest integer value not less than x. @@ -144,14 +146,15 @@ extern "C" { */ #ifndef SUNRceil -#if defined(SUNDIALS_USE_GENERIC_MATH) -#define SUNRceil(x) ((realtype) ceil((double) (x))) -#elif defined(SUNDIALS_DOUBLE_PRECISION) +#if defined(SUNDIALS_DOUBLE_PRECISION) #define SUNRceil(x) (ceil((x))) #elif defined(SUNDIALS_SINGLE_PRECISION) #define SUNRceil(x) (ceilf((x))) #elif defined(SUNDIALS_EXTENDED_PRECISION) #define SUNRceil(x) (ceill((x))) +#else +#error \ + "SUNDIALS precision not defined, report to github.com/LLNL/sundials/issues" #endif #endif @@ -160,37 +163,37 @@ extern "C" { * Function : SUNRpowerI * ----------------------------------------------------------------- * Usage : int exponent; - * realtype base, ans; + * sunrealtype base, ans; * ans = SUNRpowerI(base,exponent); * ----------------------------------------------------------------- * SUNRpowerI returns the value of base^exponent, where base is of type - * realtype and exponent is of type int. + * sunrealtype and exponent is of type int. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT realtype SUNRpowerI(realtype base, int exponent); +SUNDIALS_EXPORT sunrealtype SUNRpowerI(sunrealtype base, int exponent); /* * ----------------------------------------------------------------- * Function : SUNRpowerR * ----------------------------------------------------------------- - * Usage : realtype base, exponent, ans; + * Usage : sunrealtype base, exponent, ans; * ans = SUNRpowerR(base,exponent); * ----------------------------------------------------------------- * SUNRpowerR returns the value of base^exponent, where both base and - * exponent are of type realtype. If base < ZERO, then SUNRpowerR + * exponent are of type sunrealtype. If base < ZERO, then SUNRpowerR * returns ZERO. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT realtype SUNRpowerR(realtype base, realtype exponent); +SUNDIALS_EXPORT sunrealtype SUNRpowerR(sunrealtype base, sunrealtype exponent); /* * ----------------------------------------------------------------- * Function : SUNRCompare * ----------------------------------------------------------------- * Usage : int isNotEqual; - * realtype a, b; + * sunrealtype a, b; * isNotEqual = SUNRCompare(a, b); * ----------------------------------------------------------------- * SUNRCompareTol returns 0 if the relative difference of a and b is @@ -201,14 +204,14 @@ SUNDIALS_EXPORT realtype SUNRpowerR(realtype base, realtype exponent); * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT booleantype SUNRCompare(realtype a, realtype b); +SUNDIALS_EXPORT sunbooleantype SUNRCompare(sunrealtype a, sunrealtype b); /* * ----------------------------------------------------------------- * Function : SUNRCompareTol * ----------------------------------------------------------------- * Usage : int isNotEqual; - * realtype a, b, tol; + * sunrealtype a, b, tol; * isNotEqual = SUNRCompareTol(a, b, tol); * ----------------------------------------------------------------- * SUNRCompareTol returns 0 if the relative difference of a and b is @@ -219,8 +222,21 @@ SUNDIALS_EXPORT booleantype SUNRCompare(realtype a, realtype b); * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT booleantype SUNRCompareTol(realtype a, realtype b, realtype tol); +SUNDIALS_EXPORT sunbooleantype SUNRCompareTol(sunrealtype a, sunrealtype b, + sunrealtype tol); + +/* + * ----------------------------------------------------------------- + * Function : SUNStrToReal + * ----------------------------------------------------------------- + * Usage : sunrealtype a = SUNStrToReal(const char* str) + * ----------------------------------------------------------------- + * SUNStrToReal parses str into the sunrealtype variable. Uses standard + * strtod variants when they are available. + * ----------------------------------------------------------------- + */ +SUNDIALS_EXPORT sunrealtype SUNStrToReal(const char* str); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.h index ebb73d528..40dfdc22c 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.h @@ -4,7 +4,7 @@ * Cody Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -44,19 +44,21 @@ #ifndef _SUNMATRIX_H #define _SUNMATRIX_H -#include +#include +#include +#include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /* ----------------------------------------------------------------- * Implemented SUNMatrix types * ----------------------------------------------------------------- */ -typedef enum { +typedef enum +{ SUNMATRIX_DENSE, SUNMATRIX_MAGMADENSE, SUNMATRIX_ONEMKLDENSE, @@ -64,74 +66,91 @@ typedef enum { SUNMATRIX_SPARSE, SUNMATRIX_SLUNRLOC, SUNMATRIX_CUSPARSE, + SUNMATRIX_GINKGO, + SUNMATRIX_KOKKOSDENSE, SUNMATRIX_CUSTOM } SUNMatrix_ID; - /* ----------------------------------------------------------------- * Generic definition of SUNMatrix * ----------------------------------------------------------------- */ /* Forward reference for pointer to SUNMatrix_Ops object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix_Ops *SUNMatrix_Ops; +typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix_Ops* SUNMatrix_Ops; /* Forward reference for pointer to SUNMatrix object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix *SUNMatrix; +typedef _SUNDIALS_STRUCT_ _generic_SUNMatrix* SUNMatrix; /* Structure containing function pointers to matrix operations */ -struct _generic_SUNMatrix_Ops { +struct _generic_SUNMatrix_Ops +{ SUNMatrix_ID (*getid)(SUNMatrix); - SUNMatrix (*clone)(SUNMatrix); - void (*destroy)(SUNMatrix); - int (*zero)(SUNMatrix); - int (*copy)(SUNMatrix, SUNMatrix); - int (*scaleadd)(realtype, SUNMatrix, SUNMatrix); - int (*scaleaddi)(realtype, SUNMatrix); - int (*matvecsetup)(SUNMatrix); - int (*matvec)(SUNMatrix, N_Vector, N_Vector); - int (*space)(SUNMatrix, long int*, long int*); + SUNMatrix (*clone)(SUNMatrix); + void (*destroy)(SUNMatrix); + SUNErrCode (*zero)(SUNMatrix); + SUNErrCode (*copy)(SUNMatrix, SUNMatrix); + SUNErrCode (*scaleadd)(sunrealtype, SUNMatrix, SUNMatrix); + SUNErrCode (*scaleaddi)(sunrealtype, SUNMatrix); + SUNErrCode (*matvecsetup)(SUNMatrix); + SUNErrCode (*matvec)(SUNMatrix, N_Vector, N_Vector); + SUNErrCode (*space)(SUNMatrix, long int*, long int*); }; /* A matrix is a structure with an implementation-dependent 'content' field, and a pointer to a structure of matrix operations corresponding to that implementation. */ -struct _generic_SUNMatrix { - void *content; +struct _generic_SUNMatrix +{ + void* content; SUNMatrix_Ops ops; + SUNContext sunctx; }; - /* ----------------------------------------------------------------- * Functions exported by SUNMatrix module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT SUNMatrix SUNMatNewEmpty(); -SUNDIALS_EXPORT void SUNMatFreeEmpty(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopyOps(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID(SUNMatrix A); -SUNDIALS_EXPORT SUNMatrix SUNMatClone(SUNMatrix A); -SUNDIALS_EXPORT void SUNMatDestroy(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatZero(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopy(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAdd(realtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAddI(realtype c, SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvecSetup(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvec(SUNMatrix A, N_Vector x, N_Vector y); -SUNDIALS_EXPORT int SUNMatSpace(SUNMatrix A, long int *lenrw, long int *leniw); - -/* - * ----------------------------------------------------------------- - * IV. SUNMatrix error codes - * --------------------------------------------------------------- - */ +SUNDIALS_EXPORT +SUNMatrix SUNMatNewEmpty(SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNMatFreeEmpty(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatCopyOps(SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNMatrix_ID SUNMatGetID(SUNMatrix A); + +SUNDIALS_EXPORT +SUNMatrix SUNMatClone(SUNMatrix A); + +SUNDIALS_EXPORT +void SUNMatDestroy(SUNMatrix A); -#define SUNMAT_SUCCESS 0 /* function successfull */ -#define SUNMAT_ILL_INPUT -701 /* illegal function input */ -#define SUNMAT_MEM_FAIL -702 /* failed memory access/alloc */ -#define SUNMAT_OPERATION_FAIL -703 /* a SUNMatrix operation returned nonzero */ -#define SUNMAT_MATVEC_SETUP_REQUIRED -704 /* the SUNMatMatvecSetup routine needs to be called */ +SUNDIALS_EXPORT +SUNErrCode SUNMatZero(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatCopy(SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAdd(sunrealtype c, SUNMatrix A, SUNMatrix B); + +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAddI(sunrealtype c, SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvecSetup(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvec(SUNMatrix A, N_Vector x, N_Vector y); + +SUNDIALS_EXPORT +SUNErrCode SUNMatSpace(SUNMatrix A, long int* lenrw, long int* leniw); #ifdef __cplusplus } #endif -#endif + +#endif /* _SUNMATRIX_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.hpp new file mode 100644 index 000000000..b6b8a795c --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_matrix.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNMatrix + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MATRIX_HPP +#define _SUNDIALS_MATRIX_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseMatrix = BaseObject<_generic_SUNMatrix, _generic_SUNMatrix_Ops>; +} // namespace impl + +namespace experimental { +struct SUNMatrixDeleter +{ + void operator()(SUNMatrix A) + { + if (A) { SUNMatDestroy(A); } + } +}; + +using SUNMatrixView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.h index 36603ff14..b2ac7c64a 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,69 +18,76 @@ #define _SUNDIALS_MEMORY_H #include - +#include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif typedef enum { - SUNMEMTYPE_HOST, /* pageable memory accessible on the host */ - SUNMEMTYPE_PINNED, /* page-locked memory accesible on the host */ - SUNMEMTYPE_DEVICE, /* memory accessible from the device */ - SUNMEMTYPE_UVM /* memory accessible from the host or device */ + SUNMEMTYPE_HOST, /* pageable memory accessible on the host */ + SUNMEMTYPE_PINNED, /* page-locked memory accesible on the host */ + SUNMEMTYPE_DEVICE, /* memory accessible from the device */ + SUNMEMTYPE_UVM /* memory accessible from the host or device */ } SUNMemoryType; - /* * SUNMemory is a simple abstraction of a pointer to some * contiguos memory, so that we can keep track of its type * and its ownership. */ -typedef struct _SUNMemory *SUNMemory; +typedef struct SUNMemory_* SUNMemory; -struct _SUNMemory +struct SUNMemory_ { - void* ptr; + void* ptr; SUNMemoryType type; - booleantype own; + sunbooleantype own; + size_t bytes; }; /* Creates a new SUNMemory object with a NULL ptr */ -SUNDIALS_EXPORT SUNMemory SUNMemoryNewEmpty(); +SUNDIALS_EXPORT SUNMemory SUNMemoryNewEmpty(SUNContext sunctx); /* * SUNMemoryHelper holds ops which can allocate, deallocate, * and copy SUNMemory. */ -typedef struct _SUNMemoryHelper_Ops *SUNMemoryHelper_Ops; -typedef struct _SUNMemoryHelper *SUNMemoryHelper; +typedef struct SUNMemoryHelper_Ops_* SUNMemoryHelper_Ops; +typedef struct SUNMemoryHelper_* SUNMemoryHelper; -struct _SUNMemoryHelper +struct SUNMemoryHelper_ { - void* content; + void* content; SUNMemoryHelper_Ops ops; + SUNContext sunctx; }; -struct _SUNMemoryHelper_Ops +struct SUNMemoryHelper_Ops_ { /* operations that implementations are required to provide */ - int (*alloc)(SUNMemoryHelper, SUNMemory* memptr, size_t mem_size, SUNMemoryType mem_type); - int (*dealloc)(SUNMemoryHelper, SUNMemory mem); - int (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, size_t mem_size); + SUNErrCode (*alloc)(SUNMemoryHelper, SUNMemory* memptr, size_t mem_size, + SUNMemoryType mem_type, void* queue); + SUNErrCode (*dealloc)(SUNMemoryHelper, SUNMemory mem, void* queue); + SUNErrCode (*copy)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); /* operations that provide default implementations */ - int (*copyasync)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, - size_t mem_size, void* ctx); + SUNErrCode (*copyasync)(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); + SUNErrCode (*getallocstats)(SUNMemoryHelper, SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); SUNMemoryHelper (*clone)(SUNMemoryHelper); - int (*destroy)(SUNMemoryHelper); + SUNErrCode (*destroy)(SUNMemoryHelper); }; - /* * Generic SUNMemoryHelper functions that work without a SUNMemoryHelper object. */ @@ -89,59 +96,73 @@ struct _SUNMemoryHelper_Ops * SUNMemory object. * The SUNMemory returned will not own the ptr, therefore, it will not free * the ptr in Dealloc. */ -SUNDIALS_EXPORT SUNMemory SUNMemoryHelper_Alias(SUNMemory mem); +SUNDIALS_EXPORT +SUNMemory SUNMemoryHelper_Alias(SUNMemoryHelper, SUNMemory mem); /* Creates a new SUNMemory object with ptr set to the user provided pointer * The SUNMemory returned will not own the ptr, therefore, it will not free * the ptr in Dealloc. */ -SUNDIALS_EXPORT SUNMemory SUNMemoryHelper_Wrap(void* ptr, SUNMemoryType mem_type); - +SUNDIALS_EXPORT +SUNMemory SUNMemoryHelper_Wrap(SUNMemoryHelper, void* ptr, + SUNMemoryType mem_type); /* * Required SUNMemoryHelper operations. */ +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Alloc(SUNMemoryHelper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); -SUNDIALS_EXPORT int SUNMemoryHelper_Alloc(SUNMemoryHelper, SUNMemory* memptr, - size_t mem_size, SUNMemoryType mem_type); - -SUNDIALS_EXPORT int SUNMemoryHelper_Dealloc(SUNMemoryHelper, SUNMemory mem); +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Dealloc(SUNMemoryHelper, SUNMemory mem, void* queue); -SUNDIALS_EXPORT int SUNMemoryHelper_Copy(SUNMemoryHelper, SUNMemory dst, - SUNMemory src, size_t mem_size); +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Copy(SUNMemoryHelper, SUNMemory dst, SUNMemory src, + size_t mem_size, void* queue); /* * Optional SUNMemoryHelper operations. */ -SUNDIALS_EXPORT int SUNMemoryHelper_CopyAsync(SUNMemoryHelper, SUNMemory dst, - SUNMemory src, size_t mem_size, - void* ctx); +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_CopyAsync(SUNMemoryHelper, SUNMemory dst, + SUNMemory src, size_t mem_size, void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_GetAllocStats(SUNMemoryHelper, SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); /* Clones the SUNMemoryHelper */ -SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_Clone(SUNMemoryHelper); +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Clone(SUNMemoryHelper); /* Frees the SUNMemoryHelper */ -SUNDIALS_EXPORT int SUNMemoryHelper_Destroy(SUNMemoryHelper); +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Destroy(SUNMemoryHelper); /* * Utility SUNMemoryHelper functions. */ /* Creates an empty SUNMemoryHelper object */ -SUNDIALS_EXPORT SUNMemoryHelper SUNMemoryHelper_NewEmpty(); +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_NewEmpty(SUNContext sunctx); /* Copyies the SUNMemoryHelper ops structure from src->ops to dst->ops. */ -SUNDIALS_EXPORT int SUNMemoryHelper_CopyOps(SUNMemoryHelper src, - SUNMemoryHelper dst); +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_CopyOps(SUNMemoryHelper src, SUNMemoryHelper dst); /* Checks that all required SUNMemoryHelper ops are provided */ SUNDIALS_EXPORT -booleantype SUNMemoryHelper_ImplementsRequiredOps(SUNMemoryHelper); - +sunbooleantype SUNMemoryHelper_ImplementsRequiredOps(SUNMemoryHelper); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.hpp new file mode 100644 index 000000000..cb6427925 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_memory.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNMemoryHelper + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_MEMORY_HPP +#define _SUNDIALS_MEMORY_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseMemoryHelper = BaseObject; +} // namespace impl + +namespace experimental { +struct SUNMemoryHelperDeleter +{ + void operator()(SUNMemoryHelper helper) + { + if (helper) { SUNMemoryHelper_Destroy(helper); } + } +}; + +using SUNMemoryHelperView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_mpi_types.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_mpi_types.h index 99ecd7375..697327e1c 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_mpi_types.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_mpi_types.h @@ -1,9 +1,6 @@ /* ----------------------------------------------------------------- - * Programmer(s): Scott Cohen, Alan Hindmarsh, Radu Serban, - * Aaron Collier, and Slaven Peles @ LLNL - * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -16,24 +13,26 @@ * are used by MPI parallel vector implementations. * -----------------------------------------------------------------*/ +#ifndef _SUNDIALS_MPI_TYPES_H +#define _SUNDIALS_MPI_TYPES_H + +#include #include /* define MPI data types */ #if defined(SUNDIALS_SINGLE_PRECISION) - #define MPI_SUNREALTYPE MPI_FLOAT +#define MPI_SUNREALTYPE MPI_FLOAT #elif defined(SUNDIALS_DOUBLE_PRECISION) - #define MPI_SUNREALTYPE MPI_DOUBLE +#define MPI_SUNREALTYPE MPI_DOUBLE #elif defined(SUNDIALS_EXTENDED_PRECISION) - #define MPI_SUNREALTYPE MPI_LONG_DOUBLE +#define MPI_SUNREALTYPE MPI_LONG_DOUBLE #endif #if defined(SUNDIALS_INT64_T) - #define MPI_SUNINDEXTYPE MPI_INT64_T +#define MPI_SUNINDEXTYPE MPI_INT64_T #elif defined(SUNDIALS_INT32_T) - #define MPI_SUNINDEXTYPE MPI_INT32_T +#define MPI_SUNINDEXTYPE MPI_INT32_T #endif -/* define legacy SUNDIALS MPI data types */ -#define PVEC_REAL_MPI_TYPE MPI_SUNREALTYPE -#define PVEC_INTEGER_MPI_TYPE MPI_SUNINDEXTYPE +#endif /* _SUNDIALS_MPI_TYPES_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.h index 65e8a4c8a..a4b2e1591 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner, and Cody J. Balos @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -31,7 +31,7 @@ * pointers to such structures (SUNNonlinearSolver), * - prototypes for the nonlinear solver functions which operate * on/by SUNNonlinearSolver objects, and - * - return codes for SUNLinearSolver objects. + * - return codes for SUNNonLinearSolver objects. * ----------------------------------------------------------------------------- * At a minimum, a particular implementation of a SUNNonlinearSolver must do the * following: @@ -47,24 +47,25 @@ #ifndef _SUNNONLINEARSOLVER_H #define _SUNNONLINEARSOLVER_H -#include +#include +#include +#include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /* ----------------------------------------------------------------------------- * Forward references for SUNNonlinearSolver types defined below * ---------------------------------------------------------------------------*/ /* Forward reference for pointer to SUNNonlinearSolver_Ops object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver_Ops *SUNNonlinearSolver_Ops; +typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver_Ops* SUNNonlinearSolver_Ops; /* Forward reference for pointer to SUNNonlinearSolver object */ -typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver *SUNNonlinearSolver; - +typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver* SUNNonlinearSolver; /* ----------------------------------------------------------------------------- * Integrator supplied function types @@ -72,124 +73,124 @@ typedef _SUNDIALS_STRUCT_ _generic_SUNNonlinearSolver *SUNNonlinearSolver; typedef int (*SUNNonlinSolSysFn)(N_Vector y, N_Vector F, void* mem); -typedef int (*SUNNonlinSolLSetupFn)(booleantype jbad, booleantype* jcur, +typedef int (*SUNNonlinSolLSetupFn)(sunbooleantype jbad, sunbooleantype* jcur, void* mem); typedef int (*SUNNonlinSolLSolveFn)(N_Vector b, void* mem); typedef int (*SUNNonlinSolConvTestFn)(SUNNonlinearSolver NLS, N_Vector y, - N_Vector del, realtype tol, N_Vector ewt, - void* mem); - + N_Vector del, sunrealtype tol, + N_Vector ewt, void* mem); /* ----------------------------------------------------------------------------- * SUNNonlinearSolver types * ---------------------------------------------------------------------------*/ -typedef enum { +typedef enum +{ SUNNONLINEARSOLVER_ROOTFIND, SUNNONLINEARSOLVER_FIXEDPOINT } SUNNonlinearSolver_Type; - /* ----------------------------------------------------------------------------- * Generic definition of SUNNonlinearSolver * ---------------------------------------------------------------------------*/ /* Structure containing function pointers to nonlinear solver operations */ -struct _generic_SUNNonlinearSolver_Ops { +struct _generic_SUNNonlinearSolver_Ops +{ SUNNonlinearSolver_Type (*gettype)(SUNNonlinearSolver); - int (*initialize)(SUNNonlinearSolver); + SUNErrCode (*initialize)(SUNNonlinearSolver); int (*setup)(SUNNonlinearSolver, N_Vector, void*); - int (*solve)(SUNNonlinearSolver, N_Vector, N_Vector, N_Vector, realtype, - booleantype, void*); - int (*free)(SUNNonlinearSolver); - int (*setsysfn)(SUNNonlinearSolver, SUNNonlinSolSysFn); - int (*setlsetupfn)(SUNNonlinearSolver, SUNNonlinSolLSetupFn); - int (*setlsolvefn)(SUNNonlinearSolver, SUNNonlinSolLSolveFn); - int (*setctestfn)(SUNNonlinearSolver, SUNNonlinSolConvTestFn, void*); - int (*setmaxiters)(SUNNonlinearSolver, int); - int (*getnumiters)(SUNNonlinearSolver, long int*); - int (*getcuriter)(SUNNonlinearSolver, int*); - int (*getnumconvfails)(SUNNonlinearSolver, long int*); + int (*solve)(SUNNonlinearSolver, N_Vector, N_Vector, N_Vector, sunrealtype, + sunbooleantype, void*); + SUNErrCode (*free)(SUNNonlinearSolver); + SUNErrCode (*setsysfn)(SUNNonlinearSolver, SUNNonlinSolSysFn); + SUNErrCode (*setlsetupfn)(SUNNonlinearSolver, SUNNonlinSolLSetupFn); + SUNErrCode (*setlsolvefn)(SUNNonlinearSolver, SUNNonlinSolLSolveFn); + SUNErrCode (*setctestfn)(SUNNonlinearSolver, SUNNonlinSolConvTestFn, void*); + SUNErrCode (*setmaxiters)(SUNNonlinearSolver, int); + SUNErrCode (*getnumiters)(SUNNonlinearSolver, long int*); + SUNErrCode (*getcuriter)(SUNNonlinearSolver, int*); + SUNErrCode (*getnumconvfails)(SUNNonlinearSolver, long int*); }; /* A nonlinear solver is a structure with an implementation-dependent 'content' field, and a pointer to a structure of solver nonlinear solver operations corresponding to that implementation. */ -struct _generic_SUNNonlinearSolver { - void *content; +struct _generic_SUNNonlinearSolver +{ + void* content; SUNNonlinearSolver_Ops ops; + SUNContext sunctx; }; - /* ----------------------------------------------------------------------------- * Functions exported by SUNNonlinearSolver module * ---------------------------------------------------------------------------*/ /* empty constructor/destructor */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSolNewEmpty(); -SUNDIALS_EXPORT void SUNNonlinSolFreeEmpty(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSolNewEmpty(SUNContext sunctx); + +SUNDIALS_EXPORT +void SUNNonlinSolFreeEmpty(SUNNonlinearSolver NLS); /* core functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type SUNNonlinSolGetType(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSetup(SUNNonlinearSolver NLS, - N_Vector y, void* mem); +SUNDIALS_EXPORT +int SUNNonlinSolSetup(SUNNonlinearSolver NLS, N_Vector y, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolSolve(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, realtype tol, - booleantype callLSetup, void *mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, N_Vector w, + sunrealtype tol, sunbooleantype callLSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolFree(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree(SUNNonlinearSolver NLS); /* set functions */ -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSetupFn(SUNNonlinearSolver NLS, - SUNNonlinSolLSetupFn SetupFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSetupFn(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn SetupFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSolveFn(SUNNonlinearSolver NLS, - SUNNonlinSolLSolveFn SolveFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSolveFn(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn SolveFn); -SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn(SUNNonlinearSolver NLS, - SUNNonlinSolConvTestFn CTestFn, - void* ctest_data); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); -SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters(SUNNonlinearSolver NLS, - int maxiters); -/* get functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters(SUNNonlinearSolver NLS, - long int *niters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters(SUNNonlinearSolver NLS, int maxiters); -SUNDIALS_EXPORT int SUNNonlinSolGetCurIter(SUNNonlinearSolver NLS, - int *iter); +/* get functions */ +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters(SUNNonlinearSolver NLS, long int* niters); -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails(SUNNonlinearSolver NLS, - long int *nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter(SUNNonlinearSolver NLS, int* iter); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails(SUNNonlinearSolver NLS, + long int* nconvfails); /* ----------------------------------------------------------------------------- * SUNNonlinearSolver return values * ---------------------------------------------------------------------------*/ -#define SUN_NLS_SUCCESS 0 /* successful / converged */ - /* Recoverable */ -#define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ -#define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ - -/* Unrecoverable */ -#define SUN_NLS_MEM_NULL -901 /* memory argument is NULL */ -#define SUN_NLS_MEM_FAIL -902 /* failed memory access / allocation */ -#define SUN_NLS_ILL_INPUT -903 /* illegal function input */ -#define SUN_NLS_VECTOROP_ERR -904 /* failed NVector operation */ -#define SUN_NLS_EXT_FAIL -905 /* failed in external library call */ - +#define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ +#define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ /* ----------------------------------------------------------------------------- * SUNNonlinearSolver messages diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.hpp new file mode 100644 index 000000000..d4a5cae69 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nonlinearsolver.hpp @@ -0,0 +1,44 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS SUNNonlinearSolver + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_NONLINEARSOLVER_HPP +#define _SUNDIALS_NONLINEARSOLVER_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseNonlinearSolver = + BaseObject<_generic_SUNNonlinearSolver, _generic_SUNNonlinearSolver_Ops>; +} // namespace impl + +namespace experimental { +struct SUNNonlinearSolverDeleter +{ + void operator()(SUNNonlinearSolver NLS) + { + if (NLS) { SUNNonlinSolFree(NLS); } + } +}; + +using SUNNonlinearSolverView = + ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.h index 7e5a60f65..68ea9340e 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -47,19 +47,21 @@ #include #include - +#include +#include +#include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /* ----------------------------------------------------------------- * Implemented N_Vector types * ----------------------------------------------------------------- */ -typedef enum { +typedef enum +{ SUNDIALS_NVEC_SERIAL, SUNDIALS_NVEC_PARALLEL, SUNDIALS_NVEC_OPENMP, @@ -70,6 +72,7 @@ typedef enum { SUNDIALS_NVEC_HIP, SUNDIALS_NVEC_SYCL, SUNDIALS_NVEC_RAJA, + SUNDIALS_NVEC_KOKKOS, SUNDIALS_NVEC_OPENMPDEV, SUNDIALS_NVEC_TRILINOS, SUNDIALS_NVEC_MANYVECTOR, @@ -78,86 +81,112 @@ typedef enum { SUNDIALS_NVEC_CUSTOM } N_Vector_ID; - /* ----------------------------------------------------------------- * Generic definition of N_Vector * ----------------------------------------------------------------- */ /* Forward reference for pointer to N_Vector_Ops object */ -typedef _SUNDIALS_STRUCT_ _generic_N_Vector_Ops *N_Vector_Ops; +typedef _SUNDIALS_STRUCT_ _generic_N_Vector_Ops* N_Vector_Ops; /* Forward reference for pointer to N_Vector object */ -typedef _SUNDIALS_STRUCT_ _generic_N_Vector *N_Vector; +typedef _SUNDIALS_STRUCT_ _generic_N_Vector* N_Vector; /* Define array of N_Vectors */ -typedef N_Vector *N_Vector_S; +typedef N_Vector* N_Vector_S; /* Structure containing function pointers to vector operations */ -struct _generic_N_Vector_Ops { - N_Vector_ID (*nvgetvectorid)(N_Vector); - N_Vector (*nvclone)(N_Vector); - N_Vector (*nvcloneempty)(N_Vector); - void (*nvdestroy)(N_Vector); - void (*nvspace)(N_Vector, sunindextype *, sunindextype *); - realtype* (*nvgetarraypointer)(N_Vector); - realtype* (*nvgetdevicearraypointer)(N_Vector); - void (*nvsetarraypointer)(realtype *, N_Vector); - void* (*nvgetcommunicator)(N_Vector); +struct _generic_N_Vector_Ops +{ + /* + * REQUIRED operations. + * + * These must be implemented by derivations of the generic N_Vector. + */ + + /* constructors, destructors, and utility operations */ + N_Vector_ID (*nvgetvectorid)(N_Vector); + N_Vector (*nvclone)(N_Vector); + N_Vector (*nvcloneempty)(N_Vector); + void (*nvdestroy)(N_Vector); + void (*nvspace)(N_Vector, sunindextype*, sunindextype*); + sunrealtype* (*nvgetarraypointer)(N_Vector); + sunrealtype* (*nvgetdevicearraypointer)(N_Vector); + void (*nvsetarraypointer)(sunrealtype*, N_Vector); + SUNComm (*nvgetcommunicator)(N_Vector); sunindextype (*nvgetlength)(N_Vector); + sunindextype (*nvgetlocallength)(N_Vector); /* standard vector operations */ - void (*nvlinearsum)(realtype, N_Vector, realtype, N_Vector, N_Vector); - void (*nvconst)(realtype, N_Vector); - void (*nvprod)(N_Vector, N_Vector, N_Vector); - void (*nvdiv)(N_Vector, N_Vector, N_Vector); - void (*nvscale)(realtype, N_Vector, N_Vector); - void (*nvabs)(N_Vector, N_Vector); - void (*nvinv)(N_Vector, N_Vector); - void (*nvaddconst)(N_Vector, realtype, N_Vector); - realtype (*nvdotprod)(N_Vector, N_Vector); - realtype (*nvmaxnorm)(N_Vector); - realtype (*nvwrmsnorm)(N_Vector, N_Vector); - realtype (*nvwrmsnormmask)(N_Vector, N_Vector, N_Vector); - realtype (*nvmin)(N_Vector); - realtype (*nvwl2norm)(N_Vector, N_Vector); - realtype (*nvl1norm)(N_Vector); - void (*nvcompare)(realtype, N_Vector, N_Vector); - booleantype (*nvinvtest)(N_Vector, N_Vector); - booleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); - realtype (*nvminquotient)(N_Vector, N_Vector); - - /* fused vector operations */ - int (*nvlinearcombination)(int, realtype*, N_Vector*, N_Vector); - int (*nvscaleaddmulti)(int, realtype*, N_Vector, N_Vector*, N_Vector*); - int (*nvdotprodmulti)(int, N_Vector, N_Vector*, realtype*); - - /* vector array operations */ - int (*nvlinearsumvectorarray)(int, realtype, N_Vector*, realtype, N_Vector*, + void (*nvlinearsum)(sunrealtype, N_Vector, sunrealtype, N_Vector, N_Vector); + void (*nvconst)(sunrealtype, N_Vector); + void (*nvprod)(N_Vector, N_Vector, N_Vector); + void (*nvdiv)(N_Vector, N_Vector, N_Vector); + void (*nvscale)(sunrealtype, N_Vector, N_Vector); + void (*nvabs)(N_Vector, N_Vector); + void (*nvinv)(N_Vector, N_Vector); + void (*nvaddconst)(N_Vector, sunrealtype, N_Vector); + sunrealtype (*nvdotprod)(N_Vector, N_Vector); + sunrealtype (*nvmaxnorm)(N_Vector); + sunrealtype (*nvwrmsnorm)(N_Vector, N_Vector); + sunrealtype (*nvwrmsnormmask)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvmin)(N_Vector); + sunrealtype (*nvwl2norm)(N_Vector, N_Vector); + sunrealtype (*nvl1norm)(N_Vector); + void (*nvcompare)(sunrealtype, N_Vector, N_Vector); + sunbooleantype (*nvinvtest)(N_Vector, N_Vector); + sunbooleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvminquotient)(N_Vector, N_Vector); + + /* + * OPTIONAL operations. + * + * These operations provide default implementations that may be overriden. + */ + + /* OPTIONAL fused vector operations */ + SUNErrCode (*nvlinearcombination)(int, sunrealtype*, N_Vector*, N_Vector); + SUNErrCode (*nvscaleaddmulti)(int, sunrealtype*, N_Vector, N_Vector*, N_Vector*); - int (*nvscalevectorarray)(int, realtype*, N_Vector*, N_Vector*); - int (*nvconstvectorarray)(int, realtype, N_Vector*); - int (*nvwrmsnormvectorarray)(int, N_Vector*, N_Vector*, realtype*); - int (*nvwrmsnormmaskvectorarray)(int, N_Vector*, N_Vector*, N_Vector, realtype*); - int (*nvscaleaddmultivectorarray)(int, int, realtype*, N_Vector*, N_Vector**, N_Vector**); - int (*nvlinearcombinationvectorarray)(int, int, realtype*, N_Vector**, N_Vector*); - - /* OPTIONAL local reduction kernels (no parallel communication) */ - realtype (*nvdotprodlocal)(N_Vector, N_Vector); - realtype (*nvmaxnormlocal)(N_Vector); - realtype (*nvminlocal)(N_Vector); - realtype (*nvl1normlocal)(N_Vector); - booleantype (*nvinvtestlocal)(N_Vector, N_Vector); - booleantype (*nvconstrmasklocal)(N_Vector, N_Vector, N_Vector); - realtype (*nvminquotientlocal)(N_Vector, N_Vector); - realtype (*nvwsqrsumlocal)(N_Vector, N_Vector); - realtype (*nvwsqrsummasklocal)(N_Vector, N_Vector, N_Vector); - - /* OPTIONAL XBraid interface operations */ - int (*nvbufsize)(N_Vector, sunindextype*); - int (*nvbufpack)(N_Vector, void*); - int (*nvbufunpack)(N_Vector, void*); - - /* debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined) */ + SUNErrCode (*nvdotprodmulti)(int, N_Vector, N_Vector*, sunrealtype*); + + /* OPTIONAL vector array operations */ + SUNErrCode (*nvlinearsumvectorarray)(int, sunrealtype, N_Vector*, sunrealtype, + N_Vector*, N_Vector*); + SUNErrCode (*nvscalevectorarray)(int, sunrealtype*, N_Vector*, N_Vector*); + SUNErrCode (*nvconstvectorarray)(int, sunrealtype, N_Vector*); + SUNErrCode (*nvwrmsnormvectorarray)(int, N_Vector*, N_Vector*, sunrealtype*); + SUNErrCode (*nvwrmsnormmaskvectorarray)(int, N_Vector*, N_Vector*, N_Vector, + sunrealtype*); + SUNErrCode (*nvscaleaddmultivectorarray)(int, int, sunrealtype*, N_Vector*, + N_Vector**, N_Vector**); + SUNErrCode (*nvlinearcombinationvectorarray)(int, int, sunrealtype*, + N_Vector**, N_Vector*); + + /* + * OPTIONAL operations with no default implementation. + */ + + /* Local reduction kernels (no parallel communication) */ + sunrealtype (*nvdotprodlocal)(N_Vector, N_Vector); + sunrealtype (*nvmaxnormlocal)(N_Vector); + sunrealtype (*nvminlocal)(N_Vector); + sunrealtype (*nvl1normlocal)(N_Vector); + sunbooleantype (*nvinvtestlocal)(N_Vector, N_Vector); + sunbooleantype (*nvconstrmasklocal)(N_Vector, N_Vector, N_Vector); + sunrealtype (*nvminquotientlocal)(N_Vector, N_Vector); + sunrealtype (*nvwsqrsumlocal)(N_Vector, N_Vector); + sunrealtype (*nvwsqrsummasklocal)(N_Vector, N_Vector, N_Vector); + + /* Single buffer reduction operations */ + SUNErrCode (*nvdotprodmultilocal)(int, N_Vector, N_Vector*, sunrealtype*); + SUNErrCode (*nvdotprodmultiallreduce)(int, N_Vector, sunrealtype*); + + /* XBraid interface operations */ + SUNErrCode (*nvbufsize)(N_Vector, sunindextype*); + SUNErrCode (*nvbufpack)(N_Vector, void*); + SUNErrCode (*nvbufunpack)(N_Vector, void*); + + /* Debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined). */ void (*nvprint)(N_Vector); void (*nvprintfile)(N_Vector, FILE*); }; @@ -165,118 +194,145 @@ struct _generic_N_Vector_Ops { /* A vector is a structure with an implementation-dependent 'content' field, and a pointer to a structure of vector operations corresponding to that implementation. */ -struct _generic_N_Vector { - void *content; +struct _generic_N_Vector +{ + void* content; N_Vector_Ops ops; + SUNContext sunctx; }; - /* ----------------------------------------------------------------- * Functions exported by NVECTOR module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNewEmpty(); +SUNDIALS_EXPORT N_Vector N_VNewEmpty(SUNContext sunctx); SUNDIALS_EXPORT void N_VFreeEmpty(N_Vector v); -SUNDIALS_EXPORT int N_VCopyOps(N_Vector w, N_Vector v); +SUNDIALS_EXPORT SUNErrCode N_VCopyOps(N_Vector w, N_Vector v); + +/* + * Required operations. + */ SUNDIALS_EXPORT N_Vector_ID N_VGetVectorID(N_Vector w); SUNDIALS_EXPORT N_Vector N_VClone(N_Vector w); SUNDIALS_EXPORT N_Vector N_VCloneEmpty(N_Vector w); SUNDIALS_EXPORT void N_VDestroy(N_Vector v); -SUNDIALS_EXPORT void N_VSpace(N_Vector v, sunindextype *lrw, sunindextype *liw); -SUNDIALS_EXPORT realtype *N_VGetArrayPointer(N_Vector v); -SUNDIALS_EXPORT realtype *N_VGetDeviceArrayPointer(N_Vector v); -SUNDIALS_EXPORT void N_VSetArrayPointer(realtype *v_data, N_Vector v); -SUNDIALS_EXPORT void *N_VGetCommunicator(N_Vector v); +SUNDIALS_EXPORT void N_VSpace(N_Vector v, sunindextype* lrw, sunindextype* liw); +SUNDIALS_EXPORT sunrealtype* N_VGetArrayPointer(N_Vector v); +SUNDIALS_EXPORT sunrealtype* N_VGetDeviceArrayPointer(N_Vector v); +SUNDIALS_EXPORT void N_VSetArrayPointer(sunrealtype* v_data, N_Vector v); +SUNDIALS_EXPORT SUNComm N_VGetCommunicator(N_Vector v); SUNDIALS_EXPORT sunindextype N_VGetLength(N_Vector v); +SUNDIALS_EXPORT sunindextype N_VGetLocalLength(N_Vector v); /* standard vector operations */ -SUNDIALS_EXPORT void N_VLinearSum(realtype a, N_Vector x, realtype b, +SUNDIALS_EXPORT void N_VLinearSum(sunrealtype a, N_Vector x, sunrealtype b, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VConst(realtype c, N_Vector z); +SUNDIALS_EXPORT void N_VConst(sunrealtype c, N_Vector z); SUNDIALS_EXPORT void N_VProd(N_Vector x, N_Vector y, N_Vector z); SUNDIALS_EXPORT void N_VDiv(N_Vector x, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VScale(realtype c, N_Vector x, N_Vector z); +SUNDIALS_EXPORT void N_VScale(sunrealtype c, N_Vector x, N_Vector z); SUNDIALS_EXPORT void N_VAbs(N_Vector x, N_Vector z); SUNDIALS_EXPORT void N_VInv(N_Vector x, N_Vector z); -SUNDIALS_EXPORT void N_VAddConst(N_Vector x, realtype b, N_Vector z); -SUNDIALS_EXPORT realtype N_VDotProd(N_Vector x, N_Vector y); -SUNDIALS_EXPORT realtype N_VMaxNorm(N_Vector x); -SUNDIALS_EXPORT realtype N_VWrmsNorm(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VWrmsNormMask(N_Vector x, N_Vector w, N_Vector id); -SUNDIALS_EXPORT realtype N_VMin(N_Vector x); -SUNDIALS_EXPORT realtype N_VWL2Norm(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VL1Norm(N_Vector x); -SUNDIALS_EXPORT void N_VCompare(realtype c, N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VInvTest(N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); -SUNDIALS_EXPORT realtype N_VMinQuotient(N_Vector num, N_Vector denom); - -/* OPTIONAL fused vector operations */ -SUNDIALS_EXPORT int N_VLinearCombination(int nvec, realtype* c, N_Vector* X, - N_Vector z); - -SUNDIALS_EXPORT int N_VScaleAddMulti(int nvec, realtype* a, N_Vector x, - N_Vector* Y, N_Vector* Z); - -SUNDIALS_EXPORT int N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, - realtype* dotprods); - -/* OPTIONAL vector array operations */ -SUNDIALS_EXPORT int N_VLinearSumVectorArray(int nvec, - realtype a, N_Vector* X, - realtype b, N_Vector* Y, - N_Vector* Z); - -SUNDIALS_EXPORT int N_VScaleVectorArray(int nvec, realtype* c, N_Vector* X, - N_Vector* Z); - -SUNDIALS_EXPORT int N_VConstVectorArray(int nvec, realtype c, N_Vector* Z); - -SUNDIALS_EXPORT int N_VWrmsNormVectorArray(int nvec, N_Vector* X, N_Vector* W, - realtype* nrm); - -SUNDIALS_EXPORT int N_VWrmsNormMaskVectorArray(int nvec, N_Vector* X, - N_Vector* W, N_Vector id, - realtype* nrm); - -SUNDIALS_EXPORT int N_VScaleAddMultiVectorArray(int nvec, int nsum, - realtype* a, N_Vector* X, - N_Vector** Y, N_Vector** Z); - -SUNDIALS_EXPORT int N_VLinearCombinationVectorArray(int nvec, int nsum, - realtype* c, N_Vector** X, - N_Vector* Z); - -/* OPTIONAL local reduction kernels (no parallel communication) */ -SUNDIALS_EXPORT realtype N_VDotProdLocal(N_Vector x, N_Vector y); -SUNDIALS_EXPORT realtype N_VMaxNormLocal(N_Vector x); -SUNDIALS_EXPORT realtype N_VMinLocal(N_Vector x); -SUNDIALS_EXPORT realtype N_VL1NormLocal(N_Vector x); -SUNDIALS_EXPORT realtype N_VWSqrSumLocal(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VWSqrSumMaskLocal(N_Vector x, N_Vector w, N_Vector id); -SUNDIALS_EXPORT booleantype N_VInvTestLocal(N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VConstrMaskLocal(N_Vector c, N_Vector x, N_Vector m); -SUNDIALS_EXPORT realtype N_VMinQuotientLocal(N_Vector num, N_Vector denom); - -/* OPTIONAL XBraid interface operations */ -SUNDIALS_EXPORT int N_VBufSize(N_Vector x, sunindextype *size); -SUNDIALS_EXPORT int N_VBufPack(N_Vector x, void *buf); -SUNDIALS_EXPORT int N_VBufUnpack(N_Vector x, void *buf); +SUNDIALS_EXPORT void N_VAddConst(N_Vector x, sunrealtype b, N_Vector z); +SUNDIALS_EXPORT sunrealtype N_VDotProd(N_Vector x, N_Vector y); +SUNDIALS_EXPORT sunrealtype N_VMaxNorm(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWrmsNorm(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VWrmsNormMask(N_Vector x, N_Vector w, N_Vector id); +SUNDIALS_EXPORT sunrealtype N_VMin(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWL2Norm(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VL1Norm(N_Vector x); +SUNDIALS_EXPORT void N_VCompare(sunrealtype c, N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VInvTest(N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); +SUNDIALS_EXPORT sunrealtype N_VMinQuotient(N_Vector num, N_Vector denom); + +/* + * OPTIONAL operations with default implementations. + */ + +/* fused vector operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombination(int nvec, sunrealtype* c, N_Vector* X, + N_Vector z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMulti(int nvec, sunrealtype* a, N_Vector x, N_Vector* Y, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); + +/* vector array operations */ +SUNDIALS_EXPORT +SUNErrCode N_VLinearSumVectorArray(int nvec, sunrealtype a, N_Vector* X, + sunrealtype b, N_Vector* Y, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleVectorArray(int nvec, sunrealtype* c, N_Vector* X, + N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VConstVectorArray(int nvec, sunrealtype c, N_Vector* Z); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormVectorArray(int nvec, N_Vector* X, N_Vector* W, + sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VWrmsNormMaskVectorArray(int nvec, N_Vector* X, N_Vector* W, + N_Vector id, sunrealtype* nrm); + +SUNDIALS_EXPORT +SUNErrCode N_VScaleAddMultiVectorArray(int nvec, int nsum, sunrealtype* a, + N_Vector* X, N_Vector** Y, N_Vector** Z); + +SUNDIALS_EXPORT +SUNErrCode N_VLinearCombinationVectorArray(int nvec, int nsum, sunrealtype* c, + N_Vector** X, N_Vector* Z); + +/* + * OPTIONAL operations with no default implementation. + */ + +/* local reduction kernels (no parallel communication) */ +SUNDIALS_EXPORT sunrealtype N_VDotProdLocal(N_Vector x, N_Vector y); +SUNDIALS_EXPORT sunrealtype N_VMaxNormLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VMinLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VL1NormLocal(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWSqrSumLocal(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VWSqrSumMaskLocal(N_Vector x, N_Vector w, + N_Vector id); +SUNDIALS_EXPORT sunbooleantype N_VInvTestLocal(N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VConstrMaskLocal(N_Vector c, N_Vector x, + N_Vector m); +SUNDIALS_EXPORT sunrealtype N_VMinQuotientLocal(N_Vector num, N_Vector denom); + +/* single buffer reduction operations */ +SUNDIALS_EXPORT SUNErrCode N_VDotProdMultiLocal(int nvec, N_Vector x, N_Vector* Y, + sunrealtype* dotprods); +SUNDIALS_EXPORT SUNErrCode N_VDotProdMultiAllReduce(int nvec_total, N_Vector x, + sunrealtype* sum); + +/* XBraid interface operations */ +SUNDIALS_EXPORT SUNErrCode N_VBufSize(N_Vector x, sunindextype* size); +SUNDIALS_EXPORT SUNErrCode N_VBufPack(N_Vector x, void* buf); +SUNDIALS_EXPORT SUNErrCode N_VBufUnpack(N_Vector x, void* buf); /* ----------------------------------------------------------------- * Additional functions exported by NVECTOR module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector* N_VNewVectorArray(int count); +SUNDIALS_EXPORT N_Vector* N_VNewVectorArray(int count, SUNContext sunctx); SUNDIALS_EXPORT N_Vector* N_VCloneEmptyVectorArray(int count, N_Vector w); SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray(int count, N_Vector w); SUNDIALS_EXPORT void N_VDestroyVectorArray(N_Vector* vs, int count); /* These function are really only for users of the Fortran interface */ SUNDIALS_EXPORT N_Vector N_VGetVecAtIndexVectorArray(N_Vector* vs, int index); -SUNDIALS_EXPORT void N_VSetVecAtIndexVectorArray(N_Vector* vs, int index, N_Vector w); - +SUNDIALS_EXPORT void N_VSetVecAtIndexVectorArray(N_Vector* vs, int index, + N_Vector w); /* ----------------------------------------------------------------- * Debugging functions @@ -285,7 +341,6 @@ SUNDIALS_EXPORT void N_VSetVecAtIndexVectorArray(N_Vector* vs, int index, N_Vect SUNDIALS_EXPORT void N_VPrint(N_Vector v); SUNDIALS_EXPORT void N_VPrintFile(N_Vector v, FILE* outfile); - #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.hpp new file mode 100644 index 000000000..e8151fa00 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector.hpp @@ -0,0 +1,42 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * C++ view of SUNDIALS NVector + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_NVECTOR_HPP +#define _SUNDIALS_NVECTOR_HPP + +#include +#include +#include + +namespace sundials { +namespace impl { +using BaseNVector = BaseObject<_generic_N_Vector, _generic_N_Vector_Ops>; +} // namespace impl + +namespace experimental { +struct NVectorDeleter +{ + void operator()(N_Vector v) + { + if (v) { N_VDestroy(v); } + } +}; + +using NVectorView = ClassView; +} // namespace experimental +} // namespace sundials + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector_senswrapper.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector_senswrapper.h index 2dddbe60a..5454bb019 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector_senswrapper.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_nvector_senswrapper.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -29,7 +29,7 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -37,30 +37,31 @@ extern "C" { PART I: NVector wrapper content structure ============================================================================*/ -struct _N_VectorContent_SensWrapper { - N_Vector* vecs; /* array of wrapped vectors */ - int nvecs; /* number of wrapped vectors */ - booleantype own_vecs; /* flag indicating if wrapper owns vectors */ +struct _N_VectorContent_SensWrapper +{ + N_Vector* vecs; /* array of wrapped vectors */ + int nvecs; /* number of wrapped vectors */ + sunbooleantype own_vecs; /* flag indicating if wrapper owns vectors */ }; -typedef struct _N_VectorContent_SensWrapper *N_VectorContent_SensWrapper; +typedef struct _N_VectorContent_SensWrapper* N_VectorContent_SensWrapper; /*============================================================================== PART II: Macros to access wrapper content ============================================================================*/ -#define NV_CONTENT_SW(v) ( (N_VectorContent_SensWrapper)(v->content) ) -#define NV_VECS_SW(v) ( NV_CONTENT_SW(v)->vecs ) -#define NV_NVECS_SW(v) ( NV_CONTENT_SW(v)->nvecs ) -#define NV_OWN_VECS_SW(v) ( NV_CONTENT_SW(v)->own_vecs ) -#define NV_VEC_SW(v,i) ( NV_VECS_SW(v)[i] ) +#define NV_CONTENT_SW(v) ((N_VectorContent_SensWrapper)(v->content)) +#define NV_VECS_SW(v) (NV_CONTENT_SW(v)->vecs) +#define NV_NVECS_SW(v) (NV_CONTENT_SW(v)->nvecs) +#define NV_OWN_VECS_SW(v) (NV_CONTENT_SW(v)->own_vecs) +#define NV_VEC_SW(v, i) (NV_VECS_SW(v)[i]) /*============================================================================== PART III: Exported functions ============================================================================*/ /* constructor creates an empty vector wrapper */ -SUNDIALS_EXPORT N_Vector N_VNewEmpty_SensWrapper(int nvecs); +SUNDIALS_EXPORT N_Vector N_VNewEmpty_SensWrapper(int nvecs, SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VNew_SensWrapper(int count, N_Vector w); /* clone operations */ @@ -71,31 +72,32 @@ SUNDIALS_EXPORT N_Vector N_VClone_SensWrapper(N_Vector w); SUNDIALS_EXPORT void N_VDestroy_SensWrapper(N_Vector v); /* standard vector operations */ -SUNDIALS_EXPORT void N_VLinearSum_SensWrapper(realtype a, N_Vector x, - realtype b, N_Vector y, +SUNDIALS_EXPORT void N_VLinearSum_SensWrapper(sunrealtype a, N_Vector x, + sunrealtype b, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VConst_SensWrapper(realtype c, N_Vector z); +SUNDIALS_EXPORT void N_VConst_SensWrapper(sunrealtype c, N_Vector z); SUNDIALS_EXPORT void N_VProd_SensWrapper(N_Vector x, N_Vector y, N_Vector z); SUNDIALS_EXPORT void N_VDiv_SensWrapper(N_Vector x, N_Vector y, N_Vector z); -SUNDIALS_EXPORT void N_VScale_SensWrapper(realtype c, N_Vector x, N_Vector z); +SUNDIALS_EXPORT void N_VScale_SensWrapper(sunrealtype c, N_Vector x, N_Vector z); SUNDIALS_EXPORT void N_VAbs_SensWrapper(N_Vector x, N_Vector z); SUNDIALS_EXPORT void N_VInv_SensWrapper(N_Vector x, N_Vector z); -SUNDIALS_EXPORT void N_VAddConst_SensWrapper(N_Vector x, realtype b, +SUNDIALS_EXPORT void N_VAddConst_SensWrapper(N_Vector x, sunrealtype b, N_Vector z); -SUNDIALS_EXPORT realtype N_VDotProd_SensWrapper(N_Vector x, N_Vector y); -SUNDIALS_EXPORT realtype N_VMaxNorm_SensWrapper(N_Vector x); -SUNDIALS_EXPORT realtype N_VWrmsNorm_SensWrapper(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VWrmsNormMask_SensWrapper(N_Vector x, N_Vector w, - N_Vector id); -SUNDIALS_EXPORT realtype N_VMin_SensWrapper(N_Vector x); -SUNDIALS_EXPORT realtype N_VWL2Norm_SensWrapper(N_Vector x, N_Vector w); -SUNDIALS_EXPORT realtype N_VL1Norm_SensWrapper(N_Vector x); -SUNDIALS_EXPORT void N_VCompare_SensWrapper(realtype c, N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VInvTest_SensWrapper(N_Vector x, N_Vector z); -SUNDIALS_EXPORT booleantype N_VConstrMask_SensWrapper(N_Vector c, N_Vector x, - N_Vector m); -SUNDIALS_EXPORT realtype N_VMinQuotient_SensWrapper(N_Vector num, - N_Vector denom); +SUNDIALS_EXPORT sunrealtype N_VDotProd_SensWrapper(N_Vector x, N_Vector y); +SUNDIALS_EXPORT sunrealtype N_VMaxNorm_SensWrapper(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWrmsNorm_SensWrapper(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VWrmsNormMask_SensWrapper(N_Vector x, N_Vector w, + N_Vector id); +SUNDIALS_EXPORT sunrealtype N_VMin_SensWrapper(N_Vector x); +SUNDIALS_EXPORT sunrealtype N_VWL2Norm_SensWrapper(N_Vector x, N_Vector w); +SUNDIALS_EXPORT sunrealtype N_VL1Norm_SensWrapper(N_Vector x); +SUNDIALS_EXPORT void N_VCompare_SensWrapper(sunrealtype c, N_Vector x, + N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VInvTest_SensWrapper(N_Vector x, N_Vector z); +SUNDIALS_EXPORT sunbooleantype N_VConstrMask_SensWrapper(N_Vector c, N_Vector x, + N_Vector m); +SUNDIALS_EXPORT sunrealtype N_VMinQuotient_SensWrapper(N_Vector num, + N_Vector denom); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.h new file mode 100644 index 000000000..98da9e471 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.h @@ -0,0 +1,101 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_PROFILER_H +#define _SUNDIALS_PROFILER_H + +#include +#include +#include + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) +#include "caliper/cali.h" +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Create(SUNComm comm, const char* title, SUNProfiler* p); +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Free(SUNProfiler* p); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Begin(SUNProfiler p, const char* name); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_End(SUNProfiler p, const char* name); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_GetTimerResolution(SUNProfiler p, double* resolution); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_GetElapsedTime(SUNProfiler p, const char* name, + double* time); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Print(SUNProfiler p, FILE* fp); + +SUNDIALS_EXPORT +SUNErrCode SUNProfiler_Reset(SUNProfiler p); + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) CALI_MARK_FUNCTION_BEGIN + +#define SUNDIALS_MARK_FUNCTION_END(profobj) CALI_MARK_FUNCTION_END + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \ + CALI_WRAP_STATEMENT(name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) CALI_MARK_BEGIN(name) + +#define SUNDIALS_MARK_END(profobj, name) CALI_MARK_END(name) + +#elif defined(SUNDIALS_BUILD_WITH_PROFILING) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) \ + SUNProfiler_Begin(profobj, __func__) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) SUNProfiler_End(profobj, __func__) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \ + SUNProfiler_Begin(profobj, (name)); \ + stmt; \ + SUNProfiler_End(profobj, (name)); + +#define SUNDIALS_MARK_BEGIN(profobj, name) SUNProfiler_Begin(profobj, (name)) + +#define SUNDIALS_MARK_END(profobj, name) SUNProfiler_End(profobj, (name)) + +#else + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) + +#define SUNDIALS_MARK_END(profobj, name) + +#endif + +#ifdef __cplusplus +} + +#endif +#endif /* SUNDIALS_PROFILER_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.hpp b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.hpp new file mode 100644 index 000000000..df589fa1e --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_profiler.hpp @@ -0,0 +1,52 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_PROFILER_HPP +#define _SUNDIALS_PROFILER_HPP + +#include +#include +#include + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) +#define SUNDIALS_CXX_MARK_FUNCTION(projobj) CALI_CXX_MARK_FUNCTION +#elif defined(SUNDIALS_BUILD_WITH_PROFILING) +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) \ + sundials::ProfilerMarkScope ProfilerMarkScope__(profobj, __func__) +#else +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) +#endif + +namespace sundials { +/* Convenience class for C++ codes. + Allows for simpler profiler statements using C++ scoping rules. */ +class ProfilerMarkScope +{ +public: + ProfilerMarkScope(SUNProfiler prof, const char* name) + { + prof_ = prof; + name_ = name; + SUNProfiler_Begin(prof_, name_); + } + + ~ProfilerMarkScope() { SUNProfiler_End(prof_, name_); } + +private: + SUNProfiler prof_; + const char* name_; +}; +} // namespace sundials + +#endif /* SUNDIALS_PROFILER_HPP */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types.h index ee304d9b5..c959b6fe3 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types.h @@ -3,7 +3,7 @@ * Aaron Collier, and Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -12,18 +12,18 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This header file exports three types: realtype, sunindextype and - * booleantype, as well as the constants SUNTRUE and SUNFALSE. + * This header file exports three types: sunrealtype, sunindextype, + * and sunbooleantype, as well as the constants SUNTRUE and SUNFALSE. * * Users should include the header file sundials_types.h in every - * program file and use the exported name realtype instead of + * program file and use the exported name sunrealtype instead of * float, double or long double. * * The constants SUNDIALS_SINGLE_PRECISION, SUNDIALS_DOUBLE_PRECISION * and SUNDIALS_LONG_DOUBLE_PRECISION indicate the underlying data - * type of realtype. + * type of sunrealtype. * - * The legal types for realtype are float, double and long double. + * The legal types for sunrealtype are float, double and long double. * * The constants SUNDIALS_INT64_T and SUNDIALS_INT32_T indicate * the underlying data type of sunindextype -- the integer data type @@ -31,33 +31,33 @@ * * Data types are set at the configuration stage. * - * The macro RCONST gives the user a convenient way to define + * The macro SUN_RCONST gives the user a convenient way to define * real-valued literal constants. To use the constant 1.0, for example, * the user should write the following: * - * #define ONE RCONST(1.0) + * #define ONE SUN_RCONST(1.0) * - * If realtype is defined as a double, then RCONST(1.0) expands - * to 1.0. If realtype is defined as a float, then RCONST(1.0) - * expands to 1.0F. If realtype is defined as a long double, - * then RCONST(1.0) expands to 1.0L. There is never a need to - * explicitly cast 1.0 to (realtype). The macro can be used for + * If sunrealtype is defined as a double, then SUN_RCONST(1.0) expands + * to 1.0. If sunrealtype is defined as a float, then SUN_RCONST(1.0) + * expands to 1.0F. If sunrealtype is defined as a long double, + * then SUN_RCONST(1.0) expands to 1.0L. There is never a need to + * explicitly cast 1.0 to (sunrealtype). The macro can be used for * literal constants only. It cannot be used for expressions. * -----------------------------------------------------------------*/ -#ifndef _SUNDIALSTYPES_H -#define _SUNDIALSTYPES_H - -#ifndef _SUNDIALS_CONFIG_H -#define _SUNDIALS_CONFIG_H -#include -#endif +#ifndef _SUNDIALS_TYPES_H +#define _SUNDIALS_TYPES_H #include #include #include +#include + +#if SUNDIALS_MPI_ENABLED +#include +#endif -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -67,7 +67,7 @@ extern "C" { * The _SUNDIALS_STRUCT_ macro is defined as a `struct` unless * generating the SWIG interfaces - in that case it is defined as * nothing. This is needed to work around a bug in SWIG which prevents - * it from properly parsing our generic module structures. + * it from properly parsing our generic module structures. *------------------------------------------------------------------ */ #ifdef SWIG @@ -78,39 +78,38 @@ extern "C" { /* *------------------------------------------------------------------ - * Type realtype - * Macro RCONST - * Constants BIG_REAL, SMALL_REAL, and UNIT_ROUNDOFF + * Type sunrealtype + * Macro SUN_RCONST + * Constants SUN_SMALL_REAL, SUN_BIG_REAL, and SUN_UNIT_ROUNDOFF *------------------------------------------------------------------ */ #if defined(SUNDIALS_SINGLE_PRECISION) -typedef float realtype; -# define RCONST(x) x##F -# define BIG_REAL FLT_MAX -# define SMALL_REAL FLT_MIN -# define UNIT_ROUNDOFF FLT_EPSILON +typedef float sunrealtype; +#define SUN_RCONST(x) x##F +#define SUN_BIG_REAL FLT_MAX +#define SUN_SMALL_REAL FLT_MIN +#define SUN_UNIT_ROUNDOFF FLT_EPSILON #elif defined(SUNDIALS_DOUBLE_PRECISION) -typedef double realtype; -# define RCONST(x) x -# define BIG_REAL DBL_MAX -# define SMALL_REAL DBL_MIN -# define UNIT_ROUNDOFF DBL_EPSILON +typedef double sunrealtype; +#define SUN_RCONST(x) x +#define SUN_BIG_REAL DBL_MAX +#define SUN_SMALL_REAL DBL_MIN +#define SUN_UNIT_ROUNDOFF DBL_EPSILON #elif defined(SUNDIALS_EXTENDED_PRECISION) -typedef long double realtype; -# define RCONST(x) x##L -# define BIG_REAL LDBL_MAX -# define SMALL_REAL LDBL_MIN -# define UNIT_ROUNDOFF LDBL_EPSILON +typedef long double sunrealtype; +#define SUN_RCONST(x) x##L +#define SUN_BIG_REAL LDBL_MAX +#define SUN_SMALL_REAL LDBL_MIN +#define SUN_UNIT_ROUNDOFF LDBL_EPSILON #endif - /* *------------------------------------------------------------------ * Type : sunindextype @@ -126,23 +125,23 @@ typedef SUNDIALS_INDEX_TYPE sunindextype; /* *------------------------------------------------------------------ - * Type : booleantype + * Type : sunbooleantype *------------------------------------------------------------------ * Constants : SUNFALSE and SUNTRUE *------------------------------------------------------------------ * ANSI C does not have a built-in boolean data type. Below is the - * definition for a new type called booleantype. The advantage of - * using the name booleantype (instead of int) is an increase in + * definition for a new type called sunbooleantype. The advantage of + * using the name sunbooleantype (instead of int) is an increase in * code readability. It also allows the programmer to make a * distinction between int and boolean data. Variables of type - * booleantype are intended to have only the two values SUNFALSE and + * sunbooleantype are intended to have only the two values SUNFALSE and * SUNTRUE which are defined below to be equal to 0 and 1, * respectively. *------------------------------------------------------------------ */ -#ifndef booleantype -#define booleantype int +#ifndef sunbooleantype +#define sunbooleantype int #endif #ifndef SUNFALSE @@ -153,8 +152,82 @@ typedef SUNDIALS_INDEX_TYPE sunindextype; #define SUNTRUE 1 #endif +/* + *------------------------------------------------------------------ + * Type : SUNOutputFormat + *------------------------------------------------------------------ + * Constants for different output formats + *------------------------------------------------------------------ + */ + +typedef enum +{ + SUN_OUTPUTFORMAT_TABLE, + SUN_OUTPUTFORMAT_CSV +} SUNOutputFormat; + +/* + *------------------------------------------------------------------ + * Type : SUNErrCode + *------------------------------------------------------------------ + * Error code type + *------------------------------------------------------------------ + */ + +typedef int SUNErrCode; + +/* ----------------------------------------------------------------------------- + * Forward declarations of SUNDIALS objects + * ---------------------------------------------------------------------------*/ + +/* SUNDIALS context -- see sundials_context_impl.h */ +typedef struct SUNContext_* SUNContext; + +/* SUNDIALS error handler -- see sundials_errors.h */ +typedef struct SUNErrHandler_* SUNErrHandler; + +/* SUNDIALS profiler */ +typedef struct SUNProfiler_* SUNProfiler; + +/* SUNDIALS logger */ +typedef struct SUNLogger_* SUNLogger; + +/* ----------------------------------------------------------------------------- + * SUNDIALS function types + * ---------------------------------------------------------------------------*/ + +/* Error handler function */ +typedef void (*SUNErrHandlerFn)(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + void* err_user_data, SUNContext sunctx); + +/* + *------------------------------------------------------------------ + * Type : SUNComm + *------------------------------------------------------------------ + * SUNComm replaces MPI_Comm use in SUNDIALS code. It maps to + * MPI_Comm when MPI is enabled. + *------------------------------------------------------------------ + */ + +/* We don't define SUN_COMM_NULL when SWIG is processing the header + because we manually insert the wrapper code for SUN_COMM_NULL + (and %ignoring it in the SWIG code doesn't seem to work). */ + +#if SUNDIALS_MPI_ENABLED +#ifndef SWIG +#define SUN_COMM_NULL MPI_COMM_NULL +#endif +typedef MPI_Comm SUNComm; +#else +#ifndef SWIG +#define SUN_COMM_NULL 0 +#endif +typedef int SUNComm; +#endif + #ifdef __cplusplus } #endif -#endif /* _SUNDIALSTYPES_H */ +#endif /* _SUNDIALS_TYPES_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types_deprecated.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types_deprecated.h new file mode 100644 index 000000000..431363911 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_types_deprecated.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This header file exports realtype and booleantype and a few macros + * related to realtype for backwards compatibility. It is preferable + * to only use the types defined in sundials_types.h . + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_TYPES_DEPRECATED_H +#define _SUNDIALS_TYPES_DEPRECATED_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* + *------------------------------------------------------------------ + * Type realtype + * Macro RCONST + * Constants SMALL_REAL, BIG_REAL, and UNIT_ROUNDOFF + *------------------------------------------------------------------ + */ + +#if defined(SUNDIALS_SINGLE_PRECISION) + +typedef float realtype; +#define RCONST(x) x##F +#define BIG_REAL FLT_MAX +#define SMALL_REAL FLT_MIN +#define UNIT_ROUNDOFF FLT_EPSILON + +#elif defined(SUNDIALS_DOUBLE_PRECISION) + +typedef double realtype; +#define RCONST(x) x +#define BIG_REAL DBL_MAX +#define SMALL_REAL DBL_MIN +#define UNIT_ROUNDOFF DBL_EPSILON + +#elif defined(SUNDIALS_EXTENDED_PRECISION) + +typedef long double realtype; +#define RCONST(x) x##L +#define BIG_REAL LDBL_MAX +#define SMALL_REAL LDBL_MIN +#define UNIT_ROUNDOFF LDBL_EPSILON + +#endif + +#ifndef booleantype +#define booleantype int +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_TYPES_DEPRECATED_H */ diff --git a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_version.h b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_version.h index dd819c5c2..ca47c68c6 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_version.h +++ b/deps/AMICI/ThirdParty/sundials/include/sundials/sundials_version.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,18 +18,21 @@ #define _SUNDIALS_VERSION_H #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Fill a string with SUNDIALS version information */ -SUNDIALS_EXPORT int SUNDIALSGetVersion(char *version, int len); +SUNDIALS_EXPORT +SUNErrCode SUNDIALSGetVersion(char* version, int len); /* Fills integers with the major, minor, and patch release version numbers and a string with the release label.*/ -SUNDIALS_EXPORT int SUNDIALSGetVersionNumber(int *major, int *minor, int *patch, - char *label, int len); +SUNDIALS_EXPORT +SUNErrCode SUNDIALSGetVersionNumber(int* major, int* minor, int* patch, + char* label, int len); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_band.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_band.h index 5b203a543..280c901c1 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_band.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_band.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -24,13 +24,13 @@ #ifndef _SUNLINSOL_BAND_H #define _SUNLINSOL_BAND_H +#include #include #include #include -#include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -38,36 +38,47 @@ extern "C" { * Band Implementation of SUNLinearSolver * --------------------------------------- */ -struct _SUNLinearSolverContent_Band { - sunindextype N; - sunindextype *pivots; +struct _SUNLinearSolverContent_Band +{ + sunindextype N; + sunindextype* pivots; sunindextype last_flag; }; -typedef struct _SUNLinearSolverContent_Band *SUNLinearSolverContent_Band; - +typedef struct _SUNLinearSolverContent_Band* SUNLinearSolverContent_Band; /* -------------------------------------- * Exported Functions for SUNLINSOL_BAND * -------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNBandLinearSolver(N_Vector y, - SUNMatrix A); - -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A); -SUNDIALS_EXPORT int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_Band(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_Band(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Band(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_dense.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_dense.h index c10eec8b3..cc7d49a6c 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_dense.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_dense.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,24 +18,24 @@ * Notes: * - The definition of the generic SUNLinearSolver structure can * be found in the header file sundials_linearsolver.h. - * - The definition of the type 'realtype' can be found in the + * - The definition of the type 'sunrealtype' can be found in the * header file sundials_types.h, and it may be changed (at the * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition - * for the type 'booleantype' and 'indextype'. + * for the type 'sunbooleantype' and 'indextype'. * ----------------------------------------------------------------- */ #ifndef _SUNLINSOL_DENSE_H #define _SUNLINSOL_DENSE_H +#include #include #include #include -#include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -43,35 +43,47 @@ extern "C" { * Dense Implementation of SUNLinearSolver * ---------------------------------------- */ -struct _SUNLinearSolverContent_Dense { +struct _SUNLinearSolverContent_Dense +{ sunindextype N; - sunindextype *pivots; + sunindextype* pivots; sunindextype last_flag; }; -typedef struct _SUNLinearSolverContent_Dense *SUNLinearSolverContent_Dense; +typedef struct _SUNLinearSolverContent_Dense* SUNLinearSolverContent_Dense; /* ---------------------------------------- * Exported Functions for SUNLINSOL_DENSE * ---------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNDenseLinearSolver(N_Vector y, - SUNMatrix A); - -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A); -SUNDIALS_EXPORT int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_Dense(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_Dense(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Dense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_klu.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_klu.h index 482705e92..cdedc9d1d 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_klu.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_klu.h @@ -5,7 +5,7 @@ * code, written by Carol S. Woodward @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -34,14 +34,14 @@ #include #endif -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default KLU solver parameters */ -#define SUNKLU_ORDERING_DEFAULT 1 /* COLAMD */ -#define SUNKLU_REINIT_FULL 1 -#define SUNKLU_REINIT_PARTIAL 2 +#define SUNKLU_ORDERING_DEFAULT 1 /* COLAMD */ +#define SUNKLU_REINIT_FULL 1 +#define SUNKLU_REINIT_PARTIAL 2 /* Interfaces to match 'sunindextype' with the correct KLU types/functions */ #if defined(SUNDIALS_INT64_T) @@ -68,13 +68,13 @@ extern "C" { #define sun_klu_defaults klu_defaults #define sun_klu_free_symbolic klu_free_symbolic #define sun_klu_free_numeric klu_free_numeric -#else /* incompatible sunindextype for KLU */ -#error Incompatible sunindextype for KLU +#else /* incompatible sunindextype for KLU */ +#error Incompatible sunindextype for KLU #endif #if defined(SUNDIALS_DOUBLE_PRECISION) #else -#error Incompatible realtype for KLU +#error Incompatible sunrealtype for KLU #endif /* -------------------------------------- @@ -85,40 +85,32 @@ extern "C" { * warning messages about sunindextype vs internal KLU index types. */ typedef sunindextype (*KLUSolveFn)(sun_klu_symbolic*, sun_klu_numeric*, - sunindextype, sunindextype, - double*, sun_klu_common*); - -struct _SUNLinearSolverContent_KLU { - int last_flag; - int first_factorize; - sun_klu_symbolic *symbolic; - sun_klu_numeric *numeric; - sun_klu_common common; - KLUSolveFn klu_solver; + sunindextype, sunindextype, double*, + sun_klu_common*); + +struct _SUNLinearSolverContent_KLU +{ + int last_flag; + int first_factorize; + sun_klu_symbolic* symbolic; + sun_klu_numeric* numeric; + sun_klu_common common; + KLUSolveFn klu_solver; }; -typedef struct _SUNLinearSolverContent_KLU *SUNLinearSolverContent_KLU; - +typedef struct _SUNLinearSolverContent_KLU* SUNLinearSolverContent_KLU; /* ------------------------------------- * Exported Functions for SUNLINSOL_KLU * ------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_KLU(N_Vector y, SUNMatrix A); +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_KLU(N_Vector y, SUNMatrix A, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, int reinit_type); SUNDIALS_EXPORT int SUNLinSol_KLUSetOrdering(SUNLinearSolver S, int ordering_choice); -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNKLU(N_Vector y, SUNMatrix A); -/* deprecated */ -SUNDIALS_EXPORT int SUNKLUReInit(SUNLinearSolver S, SUNMatrix A, - sunindextype nnz, int reinit_type); -/* deprecated */ -SUNDIALS_EXPORT int SUNKLUSetOrdering(SUNLinearSolver S, - int ordering_choice); - /* -------------------- * Accessor functions * -------------------- */ @@ -127,23 +119,21 @@ SUNDIALS_EXPORT sun_klu_symbolic* SUNLinSol_KLUGetSymbolic(SUNLinearSolver S); SUNDIALS_EXPORT sun_klu_numeric* SUNLinSol_KLUGetNumeric(SUNLinearSolver S); SUNDIALS_EXPORT sun_klu_common* SUNLinSol_KLUGetCommon(SUNLinearSolver S); - /* ----------------------------------------------- * Implementations of SUNLinearSolver operations * ----------------------------------------------- */ SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_KLU(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_KLU(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_KLU(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_KLU(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_KLU(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_KLU(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_KLU(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_KLU(SUNLinearSolver S); - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_KLU(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_KLU(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackband.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackband.h index 6524a8dde..19756161c 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackband.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackband.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -25,60 +25,45 @@ #define _SUNLINSOL_LAPBAND_H #include -#include #include #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif -/* Interfaces to match 'realtype' with the correct LAPACK functions */ -#if defined(SUNDIALS_DOUBLE_PRECISION) -#define xgbtrf_f77 dgbtrf_f77 -#define xgbtrs_f77 dgbtrs_f77 -#elif defined(SUNDIALS_SINGLE_PRECISION) -#define xgbtrf_f77 sgbtrf_f77 -#define xgbtrs_f77 sgbtrs_f77 -#else -#error Incompatible realtype for LAPACK; disable LAPACK and rebuild -#endif - /* ---------------------------------------------- * LAPACK band implementation of SUNLinearSolver * ---------------------------------------------- */ -struct _SUNLinearSolverContent_LapackBand { +struct _SUNLinearSolverContent_LapackBand +{ sunindextype N; - sunindextype *pivots; + sunindextype* pivots; sunindextype last_flag; }; -typedef struct _SUNLinearSolverContent_LapackBand *SUNLinearSolverContent_LapackBand; - +typedef struct _SUNLinearSolverContent_LapackBand* SUNLinearSolverContent_LapackBand; /* -------------------------------------------- * Exported Functions for SUNLINSOL_LAPACKBAND * -------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackBand(N_Vector y, - SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNLapackBand(N_Vector y, SUNMatrix A); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackBand(N_Vector y, SUNMatrix A, + SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackBand(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_LapackBand(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_LapackBand(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_LapackBand(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_LapackBand(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_LapackBand(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_LapackBand(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_LapackBand(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackdense.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackdense.h index 4c0899b5c..9c6c1e7b7 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackdense.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_lapackdense.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -25,60 +25,45 @@ #define _SUNLINSOL_LAPDENSE_H #include -#include #include #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif -/* Interfaces to match 'realtype' with the correct LAPACK functions */ -#if defined(SUNDIALS_DOUBLE_PRECISION) -#define xgetrf_f77 dgetrf_f77 -#define xgetrs_f77 dgetrs_f77 -#elif defined(SUNDIALS_SINGLE_PRECISION) -#define xgetrf_f77 sgetrf_f77 -#define xgetrs_f77 sgetrs_f77 -#else -#error Incompatible realtype for LAPACK; disable LAPACK and rebuild -#endif - /* ----------------------------------------------- * LAPACK dense implementation of SUNLinearSolver * ----------------------------------------------- */ -struct _SUNLinearSolverContent_LapackDense { +struct _SUNLinearSolverContent_LapackDense +{ sunindextype N; - sunindextype *pivots; + sunindextype* pivots; sunindextype last_flag; }; -typedef struct _SUNLinearSolverContent_LapackDense *SUNLinearSolverContent_LapackDense; - +typedef struct _SUNLinearSolverContent_LapackDense* SUNLinearSolverContent_LapackDense; /* --------------------------------------------- * Exported Functions for SUNLINSOL_LAPACKDENSE * --------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackDense(N_Vector y, - SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNLapackDense(N_Vector y, SUNMatrix A); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackDense(N_Vector y, SUNMatrix A, + SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_LapackDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_LapackDense(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_LapackDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_LapackDense(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_LapackDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_LapackDense(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_LapackDense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_pcg.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_pcg.h index 549ed1cc8..ad604fe72 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_pcg.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_pcg.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -29,29 +29,30 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default PCG solver parameters */ -#define SUNPCG_MAXL_DEFAULT 5 +#define SUNPCG_MAXL_DEFAULT 5 /* -------------------------------------- * PCG Implementation of SUNLinearSolver * -------------------------------------- */ -struct _SUNLinearSolverContent_PCG { +struct _SUNLinearSolverContent_PCG +{ int maxl; int pretype; - booleantype zeroguess; + sunbooleantype zeroguess; int numiters; - realtype resnorm; + sunrealtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s; @@ -59,59 +60,73 @@ struct _SUNLinearSolverContent_PCG { N_Vector p; N_Vector z; N_Vector Ap; - - int print_level; - FILE* info_file; }; -typedef struct _SUNLinearSolverContent_PCG *SUNLinearSolverContent_PCG; - +typedef struct _SUNLinearSolverContent_PCG* SUNLinearSolverContent_PCG; /* ------------------------------------- * Exported Functions for SUNLINSOL_PCG * ------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_PCG(N_Vector y, - int pretype, - int maxl); -SUNDIALS_EXPORT int SUNLinSol_PCGSetPrecType(SUNLinearSolver S, - int pretype); -SUNDIALS_EXPORT int SUNLinSol_PCGSetMaxl(SUNLinearSolver S, - int maxl); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNPCG(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetMaxl(SUNLinearSolver S, int maxl); - -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, - void* P_data, - PSetupFn Pset, - PSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, - N_Vector s, - N_Vector nul); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, - booleantype onoff); -SUNDIALS_EXPORT int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul); -SUNDIALS_EXPORT int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, - N_Vector x, N_Vector b, realtype tol); -SUNDIALS_EXPORT int SUNLinSolNumIters_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT realtype SUNLinSolResNorm_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT N_Vector SUNLinSolResid_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_PCG(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetInfoFile_PCG(SUNLinearSolver LS, - FILE* info_file); -SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_PCG(SUNLinearSolver LS, - int print_level); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, + SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, + N_Vector nul); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, sunbooleantype onoff); + +SUNDIALS_EXPORT +int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul); + +SUNDIALS_EXPORT +int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +int SUNLinSolNumIters_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunrealtype SUNLinSolResNorm_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +N_Vector SUNLinSolResid_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_PCG(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spbcgs.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spbcgs.h index 9f928a4aa..2b9b8a58f 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spbcgs.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spbcgs.h @@ -5,7 +5,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -28,12 +28,11 @@ #define _SUNLINSOL_SPBCGS_H #include - #include #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -44,18 +43,19 @@ extern "C" { * SPBCGS Implementation of SUNLinearSolver * ---------------------------------------- */ -struct _SUNLinearSolverContent_SPBCGS { +struct _SUNLinearSolverContent_SPBCGS +{ int maxl; int pretype; - booleantype zeroguess; + sunbooleantype zeroguess; int numiters; - realtype resnorm; + sunrealtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -67,61 +67,46 @@ struct _SUNLinearSolverContent_SPBCGS { N_Vector u; N_Vector Ap; N_Vector vtemp; - - int print_level; - FILE* info_file; }; -typedef struct _SUNLinearSolverContent_SPBCGS *SUNLinearSolverContent_SPBCGS; - +typedef struct _SUNLinearSolverContent_SPBCGS* SUNLinearSolverContent_SPBCGS; /* --------------------------------------- *Exported Functions for SUNLINSOL_SPBCGS * --------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, - int pretype, - int maxl); -SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, - int pretype); -SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, - int maxl); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPBCGS(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPBCGSSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPBCGSSetMaxl(SUNLinearSolver S, int maxl); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, - void* P_data, - PSetupFn Pset, - PSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, - N_Vector s1, - N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, - booleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPBCGS(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT int SUNLinSolNumIters_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPBCGS(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPBCGS(SUNLinearSolver S, - FILE* info_file); -SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPBCGS(SUNLinearSolver S, - int print_level); - - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPBCGS(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPBCGS(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spfgmr.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spfgmr.h index 6aec1d1a3..5f9508e44 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spfgmr.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spfgmr.h @@ -5,7 +5,7 @@ * Hilari C. Tiedeman @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -32,104 +32,91 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default SPFGMR solver parameters */ -#define SUNSPFGMR_MAXL_DEFAULT 5 -#define SUNSPFGMR_MAXRS_DEFAULT 0 -#define SUNSPFGMR_GSTYPE_DEFAULT MODIFIED_GS +#define SUNSPFGMR_MAXL_DEFAULT 5 +#define SUNSPFGMR_MAXRS_DEFAULT 0 +#define SUNSPFGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS /* ----------------------------------------- * SPFGMR Implementation of SUNLinearSolver * ----------------------------------------- */ -struct _SUNLinearSolverContent_SPFGMR { +struct _SUNLinearSolverContent_SPFGMR +{ int maxl; int pretype; int gstype; int max_restarts; - booleantype zeroguess; + sunbooleantype zeroguess; int numiters; - realtype resnorm; + sunrealtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; N_Vector s2; - N_Vector *V; - N_Vector *Z; - realtype **Hes; - realtype *givens; + N_Vector* V; + N_Vector* Z; + sunrealtype** Hes; + sunrealtype* givens; N_Vector xcor; - realtype *yg; + sunrealtype* yg; N_Vector vtemp; - realtype *cv; - N_Vector *Xv; - - int print_level; - FILE* info_file; + sunrealtype* cv; + N_Vector* Xv; }; -typedef struct _SUNLinearSolverContent_SPFGMR *SUNLinearSolverContent_SPFGMR; +typedef struct _SUNLinearSolverContent_SPFGMR* SUNLinearSolverContent_SPFGMR; /* ---------------------------------------- * Exported Functions for SUNLINSOL_SPFGMR * ---------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, - int pretype, - int maxl); -SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, - int pretype); -SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, - int gstype); -SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, - int maxrs); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPFGMR(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetGSType(SUNLinearSolver S, int gstype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, + int gstype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, + int maxrs); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, - void* P_data, - PSetupFn Pset, - PSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, - N_Vector s1, - N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, - booleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPFGMR(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPFGMR(SUNLinearSolver LS, - FILE* info_file); -SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPFGMR(SUNLinearSolver LS, - int print_level); - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPFGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPFGMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spgmr.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spgmr.h index 55eaef938..ecf3bde8c 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spgmr.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_spgmr.h @@ -5,7 +5,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -29,109 +29,93 @@ #define _SUNLINSOL_SPGMR_H #include - #include #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default SPGMR solver parameters */ -#define SUNSPGMR_MAXL_DEFAULT 5 -#define SUNSPGMR_MAXRS_DEFAULT 0 -#define SUNSPGMR_GSTYPE_DEFAULT MODIFIED_GS +#define SUNSPGMR_MAXL_DEFAULT 5 +#define SUNSPGMR_MAXRS_DEFAULT 0 +#define SUNSPGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS /* ---------------------------------------- * SPGMR Implementation of SUNLinearSolver * ---------------------------------------- */ -struct _SUNLinearSolverContent_SPGMR { +struct _SUNLinearSolverContent_SPGMR +{ int maxl; int pretype; int gstype; int max_restarts; - booleantype zeroguess; + sunbooleantype zeroguess; int numiters; - realtype resnorm; + sunrealtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; N_Vector s2; - N_Vector *V; - realtype **Hes; - realtype *givens; + N_Vector* V; + sunrealtype** Hes; + sunrealtype* givens; N_Vector xcor; - realtype *yg; + sunrealtype* yg; N_Vector vtemp; - realtype *cv; - N_Vector *Xv; - - int print_level; - FILE* info_file; + sunrealtype* cv; + N_Vector* Xv; }; -typedef struct _SUNLinearSolverContent_SPGMR *SUNLinearSolverContent_SPGMR; - +typedef struct _SUNLinearSolverContent_SPGMR* SUNLinearSolverContent_SPGMR; /* --------------------------------------- * Exported Functions for SUNLINSOL_SPGMR * --------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, - int pretype, - int maxl); -SUNDIALS_EXPORT int SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, - int pretype); -SUNDIALS_EXPORT int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, - int gstype); -SUNDIALS_EXPORT int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, - int maxrs); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPGMR(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetGSType(SUNLinearSolver S, int gstype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, + int gstype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, + int maxrs); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, - void* P_data, - PSetupFn Pset, - PSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, - N_Vector s1, - N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, - booleantype onff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, + sunbooleantype onff); SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT int SUNLinSolNumIters_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPGMR(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPGMR(SUNLinearSolver LS, - FILE* info_file); -SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPGMR(SUNLinearSolver LS, - int print_level); - - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPGMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_sptfqmr.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_sptfqmr.h index bbdcd13b0..e7dc35cb9 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_sptfqmr.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_sptfqmr.h @@ -4,7 +4,7 @@ * Based on code sundials_sptfqmr.h by: Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -31,29 +31,30 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default SPTFQMR solver parameters */ -#define SUNSPTFQMR_MAXL_DEFAULT 5 +#define SUNSPTFQMR_MAXL_DEFAULT 5 /* ------------------------------------------ * SPTFQMR Implementation of SUNLinearSolver * ------------------------------------------ */ -struct _SUNLinearSolverContent_SPTFQMR { +struct _SUNLinearSolverContent_SPTFQMR +{ int maxl; int pretype; - booleantype zeroguess; + sunbooleantype zeroguess; int numiters; - realtype resnorm; + sunrealtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -63,64 +64,51 @@ struct _SUNLinearSolverContent_SPTFQMR { N_Vector d; N_Vector v; N_Vector p; - N_Vector *r; + N_Vector* r; N_Vector u; N_Vector vtemp1; N_Vector vtemp2; N_Vector vtemp3; - - int print_level; - FILE* info_file; }; -typedef struct _SUNLinearSolverContent_SPTFQMR *SUNLinearSolverContent_SPTFQMR; +typedef struct _SUNLinearSolverContent_SPTFQMR* SUNLinearSolverContent_SPTFQMR; - /* ------------------------------------- +/* ------------------------------------- * Exported Functions SUNLINSOL_SPTFQMR * -------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, - int pretype, - int maxl); -SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, - int pretype); -SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, - int maxl); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPTFQMR(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPTFQMRSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPTFQMRSetMaxl(SUNLinearSolver S, int maxl); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, + int maxl, SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, + int pretype); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, - void* P_data, - PSetupFn Pset, - PSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, - N_Vector s1, - N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, - booleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPTFQMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT int SUNLinSolNumIters_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPTFQMR(SUNLinearSolver LS, - FILE* info_file); -SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPTFQMR(SUNLinearSolver LS, - int print_level); - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPTFQMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superludist.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superludist.h index 80c9b8c66..ca77c2cdd 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superludist.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superludist.h @@ -3,7 +3,7 @@ * Programmer(s): Cody J. Balos @ LLNL * ---------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -32,61 +32,46 @@ #define _SUNLINSOL_SLUDIST_H #include - -#include - #include #include #include #include +#include -#if (SUPERLU_DIST_MAJOR_VERSION >= 7) || ((SUPERLU_DIST_MAJOR_VERSION == 6) && (SUPERLU_DIST_MINOR_VERSION >= 3)) -#define xLUstructInit dLUstructInit +#define xLUstructInit dLUstructInit #define xScalePermstructInit dScalePermstructInit #define xScalePermstructFree dScalePermstructFree -#define xLUstructFree dLUstructFree -#define xDestroy_LU dDestroy_LU -#define xScalePermstruct_t dScalePermstruct_t -#define xLUstruct_t dLUstruct_t -#define xSOLVEstruct_t dSOLVEstruct_t -#else -#define xLUstructInit LUstructInit -#define xScalePermstructInit ScalePermstructInit -#define xScalePermstructFree ScalePermstructFree -#define xLUstructFree LUstructFree -#define xDestroy_LU Destroy_LU -#define xScalePermstruct_t ScalePermstruct_t -#define xLUstruct_t LUstruct_t -#define xSOLVEstruct_t SOLVEstruct_t -#endif - +#define xLUstructFree dLUstructFree +#define xDestroy_LU dDestroy_LU +#define xScalePermstruct_t dScalePermstruct_t +#define xLUstruct_t dLUstruct_t +#define xSOLVEstruct_t dSOLVEstruct_t #ifdef __cplusplus extern "C" { #endif - /* * ---------------------------------------------------------------------------- * PART I: SuperLU-DIST implementation of SUNLinearSolver * ---------------------------------------------------------------------------- */ -struct _SUNLinearSolverContent_SuperLUDIST { - booleantype first_factorize; - int last_flag; - realtype berr; - gridinfo_t *grid; - xLUstruct_t *lu; - superlu_dist_options_t *options; - xScalePermstruct_t *scaleperm; - xSOLVEstruct_t *solve; - SuperLUStat_t *stat; - sunindextype N; +struct _SUNLinearSolverContent_SuperLUDIST +{ + sunbooleantype first_factorize; + int last_flag; + sunrealtype berr; + gridinfo_t* grid; + xLUstruct_t* lu; + superlu_dist_options_t* options; + xScalePermstruct_t* scaleperm; + xSOLVEstruct_t* solve; + SuperLUStat_t* stat; + sunindextype N; }; -typedef struct _SUNLinearSolverContent_SuperLUDIST *SUNLinearSolverContent_SuperLUDIST; - +typedef struct _SUNLinearSolverContent_SuperLUDIST* SUNLinearSolverContent_SuperLUDIST; /* * ---------------------------------------------------------------------------- @@ -94,13 +79,10 @@ typedef struct _SUNLinearSolverContent_SuperLUDIST *SUNLinearSolverContent_Super * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUDIST(N_Vector y, SUNMatrix A, - gridinfo_t *grid, - xLUstruct_t *lu, - xScalePermstruct_t *scaleperm, - xSOLVEstruct_t *solve, - SuperLUStat_t *stat, - superlu_dist_options_t *options); +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUDIST( + N_Vector y, SUNMatrix A, gridinfo_t* grid, xLUstruct_t* lu, + xScalePermstruct_t* scaleperm, xSOLVEstruct_t* solve, SuperLUStat_t* stat, + superlu_dist_options_t* options, SUNContext sunctx); /* * ---------------------------------------------------------------------------- @@ -108,13 +90,17 @@ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUDIST(N_Vector y, SUNMatrix A, * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT realtype SUNLinSol_SuperLUDIST_GetBerr(SUNLinearSolver LS); +SUNDIALS_EXPORT sunrealtype SUNLinSol_SuperLUDIST_GetBerr(SUNLinearSolver LS); SUNDIALS_EXPORT gridinfo_t* SUNLinSol_SuperLUDIST_GetGridinfo(SUNLinearSolver LS); SUNDIALS_EXPORT xLUstruct_t* SUNLinSol_SuperLUDIST_GetLUstruct(SUNLinearSolver LS); -SUNDIALS_EXPORT superlu_dist_options_t* SUNLinSol_SuperLUDIST_GetSuperLUOptions(SUNLinearSolver LS); -SUNDIALS_EXPORT xScalePermstruct_t* SUNLinSol_SuperLUDIST_GetScalePermstruct(SUNLinearSolver LS); -SUNDIALS_EXPORT xSOLVEstruct_t* SUNLinSol_SuperLUDIST_GetSOLVEstruct(SUNLinearSolver LS); -SUNDIALS_EXPORT SuperLUStat_t* SUNLinSol_SuperLUDIST_GetSuperLUStat(SUNLinearSolver LS); +SUNDIALS_EXPORT superlu_dist_options_t* SUNLinSol_SuperLUDIST_GetSuperLUOptions( + SUNLinearSolver LS); +SUNDIALS_EXPORT xScalePermstruct_t* SUNLinSol_SuperLUDIST_GetScalePermstruct( + SUNLinearSolver LS); +SUNDIALS_EXPORT xSOLVEstruct_t* SUNLinSol_SuperLUDIST_GetSOLVEstruct( + SUNLinearSolver LS); +SUNDIALS_EXPORT SuperLUStat_t* SUNLinSol_SuperLUDIST_GetSuperLUStat( + SUNLinearSolver LS); /* * ---------------------------------------------------------------------------- @@ -124,16 +110,16 @@ SUNDIALS_EXPORT SuperLUStat_t* SUNLinSol_SuperLUDIST_GetSuperLUStat(SUNLinearSol SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUDIST(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SuperLUDIST(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_SuperLUDIST(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SuperLUDIST(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SuperLUDIST(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SuperLUDIST(SUNLinearSolver S); - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SuperLUDIST(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superlumt.h b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superlumt.h index 79768dae5..07f7bcf07 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superlumt.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunlinsol/sunlinsol_superlumt.h @@ -5,7 +5,7 @@ * written by Carol S. Woodward @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -36,88 +36,79 @@ #define _LONGINT #endif -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* Default SuperLU_MT solver parameters */ -#define SUNSLUMT_ORDERING_DEFAULT 3 /* COLAMD */ +#define SUNSLUMT_ORDERING_DEFAULT 3 /* COLAMD */ -/* Interfaces to match 'realtype' with the correct SuperLUMT functions */ +/* Interfaces to match 'sunrealtype' with the correct SuperLUMT functions */ #if defined(SUNDIALS_DOUBLE_PRECISION) #ifndef _SLUMT_H #define _SLUMT_H #include "slu_mt_ddefs.h" #endif -#define xgstrs dgstrs -#define pxgstrf pdgstrf -#define pxgstrf_init pdgstrf_init -#define xCreate_Dense_Matrix dCreate_Dense_Matrix -#define xCreate_CompCol_Matrix dCreate_CompCol_Matrix +#define xgstrs dgstrs +#define pxgstrf pdgstrf +#define pxgstrf_init pdgstrf_init +#define xCreate_Dense_Matrix dCreate_Dense_Matrix +#define xCreate_CompCol_Matrix dCreate_CompCol_Matrix #elif defined(SUNDIALS_SINGLE_PRECISION) #ifndef _SLUMT_H #define _SLUMT_H #include "slu_mt_sdefs.h" #endif -#define xgstrs sgstrs -#define pxgstrf psgstrf -#define pxgstrf_init psgstrf_init -#define xCreate_Dense_Matrix sCreate_Dense_Matrix -#define xCreate_CompCol_Matrix sCreate_CompCol_Matrix -#else /* incompatible sunindextype for SuperLUMT */ -#error Incompatible realtype for SuperLUMT +#define xgstrs sgstrs +#define pxgstrf psgstrf +#define pxgstrf_init psgstrf_init +#define xCreate_Dense_Matrix sCreate_Dense_Matrix +#define xCreate_CompCol_Matrix sCreate_CompCol_Matrix +#else /* incompatible sunindextype for SuperLUMT */ +#error Incompatible sunrealtype for SuperLUMT #endif - /* -------------------------------------------- * SuperLUMT Implementation of SUNLinearSolver * -------------------------------------------- */ -struct _SUNLinearSolverContent_SuperLUMT { - int last_flag; - int first_factorize; - SuperMatrix *A, *AC, *L, *U, *B; - Gstat_t *Gstat; +struct _SUNLinearSolverContent_SuperLUMT +{ + int last_flag; + int first_factorize; + SuperMatrix *A, *AC, *L, *U, *B; + Gstat_t* Gstat; sunindextype *perm_r, *perm_c; sunindextype N; - int num_threads; - realtype diag_pivot_thresh; - int ordering; - superlumt_options_t *options; + int num_threads; + sunrealtype diag_pivot_thresh; + int ordering; + superlumt_options_t* options; }; -typedef struct _SUNLinearSolverContent_SuperLUMT *SUNLinearSolverContent_SuperLUMT; - +typedef struct _SUNLinearSolverContent_SuperLUMT* SUNLinearSolverContent_SuperLUMT; /* ------------------------------------------- * Exported Functions for SUNLINSOL_SUPERLUMT * ------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, - SUNMatrix A, - int num_threads); -SUNDIALS_EXPORT int SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, - int ordering_choice); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNSuperLUMT(N_Vector y, SUNMatrix A, - int num_threads); -/* deprecated */ -SUNDIALS_EXPORT int SUNSuperLUMTSetOrdering(SUNLinearSolver S, - int ordering_choice); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, SUNMatrix A, + int num_threads, + SUNContext sunctx); +SUNDIALS_EXPORT SUNErrCode SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, + int ordering_choice); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SuperLUMT(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_SuperLUMT(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SuperLUMT(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, realtype tol); + N_Vector x, N_Vector b, + sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SuperLUMT(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, - long int *lenrwLS, - long int *leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SuperLUMT(SUNLinearSolver S); - +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SuperLUMT(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_band.h b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_band.h index f6e16b916..1936d6ada 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_band.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_band.h @@ -5,7 +5,7 @@ * Based on code sundials_direct.h by: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,17 +14,17 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the band implementation of the + * This is the header file for the band implementation of the * SUNMATRIX module, SUNMATRIX_BAND. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. - * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition - * for the type 'booleantype' and 'indextype'. + * for the type 'sunbooleantype' and 'indextype'. * ----------------------------------------------------------------- */ @@ -34,71 +34,70 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* --------------------------------- * Band implementation of SUNMatrix * --------------------------------- */ - -struct _SUNMatrixContent_Band { + +struct _SUNMatrixContent_Band +{ sunindextype M; sunindextype N; sunindextype ldim; sunindextype mu; sunindextype ml; sunindextype s_mu; - realtype *data; + sunrealtype* data; sunindextype ldata; - realtype **cols; + sunrealtype** cols; }; -typedef struct _SUNMatrixContent_Band *SUNMatrixContent_Band; +typedef struct _SUNMatrixContent_Band* SUNMatrixContent_Band; - /* ------------------------------------ * Macros for access to SUNMATRIX_BAND * ------------------------------------ */ -#define SM_CONTENT_B(A) ( (SUNMatrixContent_Band)(A->content) ) - -#define SM_ROWS_B(A) ( SM_CONTENT_B(A)->M ) +#define SM_CONTENT_B(A) ((SUNMatrixContent_Band)(A->content)) -#define SM_COLUMNS_B(A) ( SM_CONTENT_B(A)->N ) +#define SM_ROWS_B(A) (SM_CONTENT_B(A)->M) -#define SM_LDATA_B(A) ( SM_CONTENT_B(A)->ldata ) +#define SM_COLUMNS_B(A) (SM_CONTENT_B(A)->N) -#define SM_UBAND_B(A) ( SM_CONTENT_B(A)->mu ) +#define SM_LDATA_B(A) (SM_CONTENT_B(A)->ldata) -#define SM_LBAND_B(A) ( SM_CONTENT_B(A)->ml ) +#define SM_UBAND_B(A) (SM_CONTENT_B(A)->mu) -#define SM_SUBAND_B(A) ( SM_CONTENT_B(A)->s_mu ) +#define SM_LBAND_B(A) (SM_CONTENT_B(A)->ml) -#define SM_LDIM_B(A) ( SM_CONTENT_B(A)->ldim ) +#define SM_SUBAND_B(A) (SM_CONTENT_B(A)->s_mu) -#define SM_DATA_B(A) ( SM_CONTENT_B(A)->data ) +#define SM_LDIM_B(A) (SM_CONTENT_B(A)->ldim) -#define SM_COLS_B(A) ( SM_CONTENT_B(A)->cols ) +#define SM_DATA_B(A) (SM_CONTENT_B(A)->data) -#define SM_COLUMN_B(A,j) ( ((SM_CONTENT_B(A)->cols)[j])+SM_SUBAND_B(A) ) +#define SM_COLS_B(A) (SM_CONTENT_B(A)->cols) -#define SM_COLUMN_ELEMENT_B(col_j,i,j) (col_j[(i)-(j)]) +#define SM_COLUMN_B(A, j) (((SM_CONTENT_B(A)->cols)[j]) + SM_SUBAND_B(A)) -#define SM_ELEMENT_B(A,i,j) ( (SM_CONTENT_B(A)->cols)[j][(i)-(j)+SM_SUBAND_B(A)] ) +#define SM_COLUMN_ELEMENT_B(col_j, i, j) (col_j[(i) - (j)]) +#define SM_ELEMENT_B(A, i, j) \ + ((SM_CONTENT_B(A)->cols)[j][(i) - (j) + SM_SUBAND_B(A)]) /* ---------------------------------------- - * Exported Functions for SUNMATRIX_BAND + * Exported Functions for SUNMATRIX_BAND * ---------------------------------------- */ SUNDIALS_EXPORT SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, - sunindextype ml); + sunindextype ml, SUNContext sunctx); -SUNDIALS_EXPORT SUNMatrix SUNBandMatrixStorage(sunindextype N, - sunindextype mu, - sunindextype ml, - sunindextype smu); +SUNDIALS_EXPORT SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, + sunindextype ml, sunindextype smu, + SUNContext sunctx); SUNDIALS_EXPORT void SUNBandMatrix_Print(SUNMatrix A, FILE* outfile); @@ -108,20 +107,23 @@ SUNDIALS_EXPORT sunindextype SUNBandMatrix_LowerBandwidth(SUNMatrix A); SUNDIALS_EXPORT sunindextype SUNBandMatrix_UpperBandwidth(SUNMatrix A); SUNDIALS_EXPORT sunindextype SUNBandMatrix_StoredUpperBandwidth(SUNMatrix A); SUNDIALS_EXPORT sunindextype SUNBandMatrix_LDim(SUNMatrix A); -SUNDIALS_EXPORT realtype* SUNBandMatrix_Data(SUNMatrix A); -SUNDIALS_EXPORT realtype** SUNBandMatrix_Cols(SUNMatrix A); -SUNDIALS_EXPORT realtype* SUNBandMatrix_Column(SUNMatrix A, sunindextype j); +SUNDIALS_EXPORT sunindextype SUNBandMatrix_LData(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNBandMatrix_Data(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype** SUNBandMatrix_Cols(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNBandMatrix_Column(SUNMatrix A, sunindextype j); SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Band(SUNMatrix A); SUNDIALS_EXPORT SUNMatrix SUNMatClone_Band(SUNMatrix A); SUNDIALS_EXPORT void SUNMatDestroy_Band(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatZero_Band(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopy_Band(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAdd_Band(realtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAddI_Band(realtype c, SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvec_Band(SUNMatrix A, N_Vector x, N_Vector y); -SUNDIALS_EXPORT int SUNMatSpace_Band(SUNMatrix A, long int *lenrw, long int *leniw); - +SUNDIALS_EXPORT SUNErrCode SUNMatZero_Band(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatCopy_Band(SUNMatrix A, SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAdd_Band(sunrealtype c, SUNMatrix A, + SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAddI_Band(sunrealtype c, SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvec_Band(SUNMatrix A, N_Vector x, N_Vector y); +SUNDIALS_EXPORT SUNErrCode SUNMatSpace_Band(SUNMatrix A, long int* lenrw, + long int* leniw); + #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_dense.h b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_dense.h index 9b23a3e84..2a49da378 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_dense.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_dense.h @@ -5,7 +5,7 @@ * Based on code sundials_direct.h by: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,17 +14,17 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the dense implementation of the + * This is the header file for the dense implementation of the * SUNMATRIX module, SUNMATRIX_DENSE. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. - * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition - * for the type 'booleantype' and 'indextype'. + * for the type 'sunbooleantype' and 'indextype'. * ----------------------------------------------------------------- */ @@ -34,70 +34,74 @@ #include #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif /* ---------------------------------- * Dense implementation of SUNMatrix * ---------------------------------- */ - -struct _SUNMatrixContent_Dense { + +struct _SUNMatrixContent_Dense +{ sunindextype M; sunindextype N; - realtype *data; + sunrealtype* data; sunindextype ldata; - realtype **cols; + sunrealtype** cols; }; -typedef struct _SUNMatrixContent_Dense *SUNMatrixContent_Dense; +typedef struct _SUNMatrixContent_Dense* SUNMatrixContent_Dense; /* ------------------------------------ * Macros for access to SUNMATRIX_DENSE * ------------------------------------ */ -#define SM_CONTENT_D(A) ( (SUNMatrixContent_Dense)(A->content) ) +#define SM_CONTENT_D(A) ((SUNMatrixContent_Dense)(A->content)) -#define SM_ROWS_D(A) ( SM_CONTENT_D(A)->M ) +#define SM_ROWS_D(A) (SM_CONTENT_D(A)->M) -#define SM_COLUMNS_D(A) ( SM_CONTENT_D(A)->N ) +#define SM_COLUMNS_D(A) (SM_CONTENT_D(A)->N) -#define SM_LDATA_D(A) ( SM_CONTENT_D(A)->ldata ) +#define SM_LDATA_D(A) (SM_CONTENT_D(A)->ldata) -#define SM_DATA_D(A) ( SM_CONTENT_D(A)->data ) +#define SM_DATA_D(A) (SM_CONTENT_D(A)->data) -#define SM_COLS_D(A) ( SM_CONTENT_D(A)->cols ) +#define SM_COLS_D(A) (SM_CONTENT_D(A)->cols) -#define SM_COLUMN_D(A,j) ( (SM_CONTENT_D(A)->cols)[j] ) +#define SM_COLUMN_D(A, j) ((SM_CONTENT_D(A)->cols)[j]) -#define SM_ELEMENT_D(A,i,j) ( (SM_CONTENT_D(A)->cols)[j][i] ) +#define SM_ELEMENT_D(A, i, j) ((SM_CONTENT_D(A)->cols)[j][i]) /* --------------------------------------- * Exported Functions for SUNMATRIX_DENSE * --------------------------------------- */ -SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N); +SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N, + SUNContext sunctx); SUNDIALS_EXPORT void SUNDenseMatrix_Print(SUNMatrix A, FILE* outfile); SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Rows(SUNMatrix A); SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Columns(SUNMatrix A); SUNDIALS_EXPORT sunindextype SUNDenseMatrix_LData(SUNMatrix A); -SUNDIALS_EXPORT realtype* SUNDenseMatrix_Data(SUNMatrix A); -SUNDIALS_EXPORT realtype** SUNDenseMatrix_Cols(SUNMatrix A); -SUNDIALS_EXPORT realtype* SUNDenseMatrix_Column(SUNMatrix A, sunindextype j); +SUNDIALS_EXPORT sunrealtype* SUNDenseMatrix_Data(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype** SUNDenseMatrix_Cols(SUNMatrix A); +SUNDIALS_EXPORT sunrealtype* SUNDenseMatrix_Column(SUNMatrix A, sunindextype j); SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Dense(SUNMatrix A); SUNDIALS_EXPORT SUNMatrix SUNMatClone_Dense(SUNMatrix A); SUNDIALS_EXPORT void SUNMatDestroy_Dense(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatZero_Dense(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopy_Dense(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAdd_Dense(realtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAddI_Dense(realtype c, SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvec_Dense(SUNMatrix A, N_Vector x, N_Vector y); -SUNDIALS_EXPORT int SUNMatSpace_Dense(SUNMatrix A, long int *lenrw, long int *leniw); - - +SUNDIALS_EXPORT SUNErrCode SUNMatZero_Dense(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatCopy_Dense(SUNMatrix A, SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAdd_Dense(sunrealtype c, SUNMatrix A, + SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAddI_Dense(sunrealtype c, SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvec_Dense(SUNMatrix A, N_Vector x, + N_Vector y); +SUNDIALS_EXPORT SUNErrCode SUNMatSpace_Dense(SUNMatrix A, long int* lenrw, + long int* leniw); + #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_slunrloc.h b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_slunrloc.h index 63ea673a2..52d29ed65 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_slunrloc.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_slunrloc.h @@ -3,7 +3,7 @@ * Programmer(s): Cody Balos @ LLNL * ---------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -16,53 +16,50 @@ * ---------------------------------------------------------------------------- */ - #ifndef _SUNMATRIX_SUPERLUNRLOC_H #define _SUNMATRIX_SUPERLUNRLOC_H #include -#include #include +#include #ifdef __cplusplus extern "C" { #endif - /* ---------------------------------------------------------------------------- * PART 1: SUNMatrix wrapper for the SuperLU SuperMatrix structure with * Stype = SLU_NR_loc, i.e. a SuperMatrix stored in a distributed * CSR format. * ---------------------------------------------------------------------------*/ - -struct _SUNMatrixContent_SLUNRloc { - booleantype own_data; - gridinfo_t *grid; - sunindextype *row_to_proc; - pdgsmv_comm_t *gsmv_comm; - SuperMatrix *A_super; - SuperMatrix *ACS_super; +struct _SUNMatrixContent_SLUNRloc +{ + sunbooleantype own_data; + gridinfo_t* grid; + sunindextype* row_to_proc; + pdgsmv_comm_t* gsmv_comm; + SuperMatrix* A_super; + SuperMatrix* ACS_super; }; -typedef struct _SUNMatrixContent_SLUNRloc *SUNMatrixContent_SLUNRloc; - +typedef struct _SUNMatrixContent_SLUNRloc* SUNMatrixContent_SLUNRloc; /* ---------------------------------------------------------------------------- * PART 2: Functions exported by SUNMatrix_SLUNRloc: * --------------------------------------------------------------------------*/ - -SUNDIALS_EXPORT SUNMatrix SUNMatrix_SLUNRloc(SuperMatrix *A_super, gridinfo_t *grid); -SUNDIALS_EXPORT void SUNMatrix_SLUNRloc_Print(SUNMatrix A, FILE *fp); +SUNDIALS_EXPORT SUNMatrix SUNMatrix_SLUNRloc(SuperMatrix* A_super, + gridinfo_t* grid, SUNContext sunctx); +SUNDIALS_EXPORT void SUNMatrix_SLUNRloc_Print(SUNMatrix A, FILE* fp); /* ---------------------------------------------------------------------------- * Accessor Functions: * --------------------------------------------------------------------------*/ -SUNDIALS_EXPORT SuperMatrix* SUNMatrix_SLUNRloc_SuperMatrix(SUNMatrix A); +SUNDIALS_EXPORT SuperMatrix* SUNMatrix_SLUNRloc_SuperMatrix(SUNMatrix A); SUNDIALS_EXPORT gridinfo_t* SUNMatrix_SLUNRloc_ProcessGrid(SUNMatrix A); -SUNDIALS_EXPORT booleantype SUNMatrix_SLUNRloc_OwnData(SUNMatrix A); +SUNDIALS_EXPORT sunbooleantype SUNMatrix_SLUNRloc_OwnData(SUNMatrix A); /* ----------------------------------------------------------------------------- * SuperLU implementations of various SUNMatrix operations: @@ -71,13 +68,16 @@ SUNDIALS_EXPORT booleantype SUNMatrix_SLUNRloc_OwnData(SUNMatrix A); SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_SLUNRloc(SUNMatrix A); SUNDIALS_EXPORT SUNMatrix SUNMatClone_SLUNRloc(SUNMatrix A); SUNDIALS_EXPORT void SUNMatDestroy_SLUNRloc(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatZero_SLUNRloc(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopy_SLUNRloc(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAdd_SLUNRloc(realtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAddI_SLUNRloc(realtype c, SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvecSetup_SLUNRloc(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvec_SLUNRloc(SUNMatrix A, N_Vector x, N_Vector y); -SUNDIALS_EXPORT int SUNMatSpace_SLUNRloc(SUNMatrix A, long int *lenrw, long int *leniw); +SUNDIALS_EXPORT SUNErrCode SUNMatZero_SLUNRloc(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatCopy_SLUNRloc(SUNMatrix A, SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAdd_SLUNRloc(sunrealtype c, SUNMatrix A, + SUNMatrix B); +SUNDIALS_EXPORT SUNErrCode SUNMatScaleAddI_SLUNRloc(sunrealtype c, SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvecSetup_SLUNRloc(SUNMatrix A); +SUNDIALS_EXPORT SUNErrCode SUNMatMatvec_SLUNRloc(SUNMatrix A, N_Vector x, + N_Vector y); +SUNDIALS_EXPORT SUNErrCode SUNMatSpace_SLUNRloc(SUNMatrix A, long int* lenrw, + long int* leniw); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_sparse.h b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_sparse.h index 102c78a0d..edb929cef 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_sparse.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunmatrix/sunmatrix_sparse.h @@ -2,11 +2,11 @@ * ----------------------------------------------------------------- * Programmer(s): Daniel Reynolds @ SMU * David Gardner @ LLNL - * Based on code sundials_sparse.h by: Carol Woodward and + * Based on code sundials_sparse.h by: Carol Woodward and * Slaven Peles @ LLNL, and Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -15,17 +15,17 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the sparse implementation of the + * This is the header file for the sparse implementation of the * SUNMATRIX module, SUNMATRIX_SPARSE. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. - * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * - The definition of the type 'sunrealtype' can be found in the + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition - * for the type 'booleantype' and 'indextype'. + * for the type 'sunbooleantype' and 'indextype'. * ----------------------------------------------------------------- */ @@ -34,10 +34,12 @@ #include #include -#include #include +#include + +#include "sundials/sundials_types.h" -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -48,96 +50,133 @@ extern "C" { #define CSC_MAT 0 #define CSR_MAT 1 - /* ------------------------------------------ * Sparse Implementation of SUNMATRIX_SPARSE * ------------------------------------------ */ - -struct _SUNMatrixContent_Sparse { + +struct _SUNMatrixContent_Sparse +{ sunindextype M; sunindextype N; sunindextype NNZ; sunindextype NP; - realtype *data; + sunrealtype* data; int sparsetype; - sunindextype *indexvals; - sunindextype *indexptrs; + sunindextype* indexvals; + sunindextype* indexptrs; /* CSC indices */ - sunindextype **rowvals; - sunindextype **colptrs; + sunindextype** rowvals; + sunindextype** colptrs; /* CSR indices */ - sunindextype **colvals; - sunindextype **rowptrs; + sunindextype** colvals; + sunindextype** rowptrs; }; -typedef struct _SUNMatrixContent_Sparse *SUNMatrixContent_Sparse; - +typedef struct _SUNMatrixContent_Sparse* SUNMatrixContent_Sparse; /* --------------------------------------- * Macros for access to SUNMATRIX_SPARSE * --------------------------------------- */ -#define SM_CONTENT_S(A) ( (SUNMatrixContent_Sparse)(A->content) ) +#define SM_CONTENT_S(A) ((SUNMatrixContent_Sparse)(A->content)) -#define SM_ROWS_S(A) ( SM_CONTENT_S(A)->M ) +#define SM_ROWS_S(A) (SM_CONTENT_S(A)->M) -#define SM_COLUMNS_S(A) ( SM_CONTENT_S(A)->N ) +#define SM_COLUMNS_S(A) (SM_CONTENT_S(A)->N) -#define SM_NNZ_S(A) ( SM_CONTENT_S(A)->NNZ ) +#define SM_NNZ_S(A) (SM_CONTENT_S(A)->NNZ) -#define SM_NP_S(A) ( SM_CONTENT_S(A)->NP ) +#define SM_NP_S(A) (SM_CONTENT_S(A)->NP) -#define SM_SPARSETYPE_S(A) ( SM_CONTENT_S(A)->sparsetype ) +#define SM_SPARSETYPE_S(A) (SM_CONTENT_S(A)->sparsetype) -#define SM_DATA_S(A) ( SM_CONTENT_S(A)->data ) +#define SM_DATA_S(A) (SM_CONTENT_S(A)->data) -#define SM_INDEXVALS_S(A) ( SM_CONTENT_S(A)->indexvals ) +#define SM_INDEXVALS_S(A) (SM_CONTENT_S(A)->indexvals) -#define SM_INDEXPTRS_S(A) ( SM_CONTENT_S(A)->indexptrs ) +#define SM_INDEXPTRS_S(A) (SM_CONTENT_S(A)->indexptrs) /* ---------------------------------------- * Exported Functions for SUNMATRIX_SPARSE * ---------------------------------------- */ -SUNDIALS_EXPORT SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, - sunindextype NNZ, int sparsetype); +SUNDIALS_EXPORT +SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, sunindextype NNZ, + int sparsetype, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNMatrix SUNSparseFromDenseMatrix(SUNMatrix A, sunrealtype droptol, + int sparsetype); + +SUNDIALS_EXPORT +SUNMatrix SUNSparseFromBandMatrix(SUNMatrix A, sunrealtype droptol, + int sparsetype); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_ToCSR(const SUNMatrix A, SUNMatrix* Bout); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_ToCSC(const SUNMatrix A, SUNMatrix* Bout); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_Realloc(SUNMatrix A); + +SUNDIALS_EXPORT +SUNErrCode SUNSparseMatrix_Reallocate(SUNMatrix A, sunindextype NNZ); + +SUNDIALS_EXPORT +void SUNSparseMatrix_Print(SUNMatrix A, FILE* outfile); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_Rows(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_Columns(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_NNZ(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype SUNSparseMatrix_NP(SUNMatrix A); + +SUNDIALS_EXPORT +int SUNSparseMatrix_SparseType(SUNMatrix A); + +SUNDIALS_EXPORT +sunrealtype* SUNSparseMatrix_Data(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype* SUNSparseMatrix_IndexValues(SUNMatrix A); + +SUNDIALS_EXPORT +sunindextype* SUNSparseMatrix_IndexPointers(SUNMatrix A); -SUNDIALS_EXPORT SUNMatrix SUNSparseFromDenseMatrix(SUNMatrix A, - realtype droptol, - int sparsetype); +SUNDIALS_EXPORT +SUNMatrix_ID SUNMatGetID_Sparse(SUNMatrix A); -SUNDIALS_EXPORT SUNMatrix SUNSparseFromBandMatrix(SUNMatrix A, - realtype droptol, - int sparsetype); +SUNDIALS_EXPORT +SUNMatrix SUNMatClone_Sparse(SUNMatrix A); -SUNDIALS_EXPORT int SUNSparseMatrix_ToCSR(const SUNMatrix A, SUNMatrix* Bout); -SUNDIALS_EXPORT int SUNSparseMatrix_ToCSC(const SUNMatrix A, SUNMatrix* Bout); +SUNDIALS_EXPORT +void SUNMatDestroy_Sparse(SUNMatrix A); -SUNDIALS_EXPORT int SUNSparseMatrix_Realloc(SUNMatrix A); +SUNDIALS_EXPORT +SUNErrCode SUNMatZero_Sparse(SUNMatrix A); -SUNDIALS_EXPORT int SUNSparseMatrix_Reallocate(SUNMatrix A, sunindextype NNZ); +SUNDIALS_EXPORT +SUNErrCode SUNMatCopy_Sparse(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT void SUNSparseMatrix_Print(SUNMatrix A, FILE* outfile); +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAdd_Sparse(sunrealtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT sunindextype SUNSparseMatrix_Rows(SUNMatrix A); -SUNDIALS_EXPORT sunindextype SUNSparseMatrix_Columns(SUNMatrix A); -SUNDIALS_EXPORT sunindextype SUNSparseMatrix_NNZ(SUNMatrix A); -SUNDIALS_EXPORT sunindextype SUNSparseMatrix_NP(SUNMatrix A); -SUNDIALS_EXPORT int SUNSparseMatrix_SparseType(SUNMatrix A); -SUNDIALS_EXPORT realtype* SUNSparseMatrix_Data(SUNMatrix A); -SUNDIALS_EXPORT sunindextype* SUNSparseMatrix_IndexValues(SUNMatrix A); -SUNDIALS_EXPORT sunindextype* SUNSparseMatrix_IndexPointers(SUNMatrix A); +SUNDIALS_EXPORT +SUNErrCode SUNMatScaleAddI_Sparse(sunrealtype c, SUNMatrix A); -SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Sparse(SUNMatrix A); -SUNDIALS_EXPORT SUNMatrix SUNMatClone_Sparse(SUNMatrix A); -SUNDIALS_EXPORT void SUNMatDestroy_Sparse(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatZero_Sparse(SUNMatrix A); -SUNDIALS_EXPORT int SUNMatCopy_Sparse(SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAdd_Sparse(realtype c, SUNMatrix A, SUNMatrix B); -SUNDIALS_EXPORT int SUNMatScaleAddI_Sparse(realtype c, SUNMatrix A); -SUNDIALS_EXPORT int SUNMatMatvec_Sparse(SUNMatrix A, N_Vector x, N_Vector y); -SUNDIALS_EXPORT int SUNMatSpace_Sparse(SUNMatrix A, long int *lenrw, long int *leniw); +SUNDIALS_EXPORT +SUNErrCode SUNMatMatvec_Sparse(SUNMatrix A, N_Vector x, N_Vector y); +SUNDIALS_EXPORT +SUNErrCode SUNMatSpace_Sparse(SUNMatrix A, long int* lenrw, long int* leniw); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunmemory/sunmemory_system.h b/deps/AMICI/ThirdParty/sundials/include/sunmemory/sunmemory_system.h new file mode 100644 index 000000000..2e45ca24f --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/include/sunmemory/sunmemory_system.h @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS system memory helper header file. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_SYSMEMORY_H +#define _SUNDIALS_SYSMEMORY_H + +#include + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* Implementation specific functions */ + +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Sys(SUNContext sunctx); + +/* SUNMemoryHelper functions */ + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Alloc_Sys(SUNMemoryHelper helper, SUNMemory* memptr, + size_t mem_size, SUNMemoryType mem_type, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Dealloc_Sys(SUNMemoryHelper helper, SUNMemory mem, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Copy_Sys(SUNMemoryHelper helper, SUNMemory dst, + SUNMemory src, size_t memory_size, + void* queue); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_GetAllocStats_Sys(SUNMemoryHelper helper, + SUNMemoryType mem_type, + unsigned long* num_allocations, + unsigned long* num_deallocations, + size_t* bytes_allocated, + size_t* bytes_high_watermark); + +SUNDIALS_EXPORT +SUNMemoryHelper SUNMemoryHelper_Clone_Sys(SUNMemoryHelper helper); + +SUNDIALS_EXPORT +SUNErrCode SUNMemoryHelper_Destroy_Sys(SUNMemoryHelper helper); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h b/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h index 22be29b05..779538abf 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_fixedpoint.h @@ -1,8 +1,8 @@ -/*----------------------------------------------------------------------------- +/* --------------------------------------------------------------------------- * Programmer(s): Daniel R. Reynolds @ SMU - *----------------------------------------------------------------------------- + * --------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -10,23 +10,23 @@ * * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End - *----------------------------------------------------------------------------- + * --------------------------------------------------------------------------- * This is the header file for the SUNNonlinearSolver module implementation of * the Anderson-accelerated fixed-point method. * * Part I defines the solver-specific content structure. * * Part II contains prototypes for the solver constructor and operations. - *---------------------------------------------------------------------------*/ + * ---------------------------------------------------------------------------*/ #ifndef _SUNNONLINSOL_FIXEDPOINT_H #define _SUNNONLINSOL_FIXEDPOINT_H +#include + #include "sundials/sundials_types.h" -#include "sundials/sundials_nvector.h" -#include "sundials/sundials_nonlinearsolver.h" -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -34,96 +34,98 @@ extern "C" { I. Content structure ---------------------------------------------------------------------------*/ -struct _SUNNonlinearSolverContent_FixedPoint { - +struct _SUNNonlinearSolverContent_FixedPoint +{ /* functions provided by the integrator */ - SUNNonlinSolSysFn Sys; /* fixed-point iteration function */ - SUNNonlinSolConvTestFn CTest; /* convergence test function */ + SUNNonlinSolSysFn Sys; /* fixed-point iteration function */ + SUNNonlinSolConvTestFn CTest; /* convergence test function */ /* nonlinear solver variables */ - int m; /* number of acceleration vectors to use */ - int *imap; /* array of length m */ - booleantype damping; /* flag to apply dampling in acceleration */ - realtype beta; /* damping paramter */ - realtype *R; /* array of length m*m */ - realtype *gamma; /* array of length m */ - realtype *cvals; /* array of length m+1 for fused vector op */ - N_Vector *df; /* vector array of length m */ - N_Vector *dg; /* vector array of length m */ - N_Vector *q; /* vector array of length m */ - N_Vector *Xvecs; /* array of length m+1 for fused vector op */ - N_Vector yprev; /* temporary vectors for performing solve */ - N_Vector gy; - N_Vector fold; - N_Vector gold; - N_Vector delta; /* correction vector (change between 2 iterates) */ - int curiter; /* current iteration number in a solve attempt */ - int maxiters; /* maximum number of iterations per solve attempt */ - long int niters; /* total number of iterations across all solves */ - long int nconvfails; /* total number of convergence failures */ - void *ctest_data; /* data to pass to convergence test function */ - - /* if 0 (default) nothing is printed, if 1 the residual is printed every iteration */ - int print_level; - /* if NULL nothing is printed, if 1 the residual is printed every iteration */ - FILE* info_file; + int m; /* number of acceleration vectors to use */ + int* imap; /* array of length m */ + sunbooleantype damping; /* flag to apply dampling in acceleration */ + sunrealtype beta; /* damping paramter */ + sunrealtype* R; /* array of length m*m */ + sunrealtype* gamma; /* array of length m */ + sunrealtype* cvals; /* array of length m+1 for fused vector op */ + N_Vector* df; /* vector array of length m */ + N_Vector* dg; /* vector array of length m */ + N_Vector* q; /* vector array of length m */ + N_Vector* Xvecs; /* array of length m+1 for fused vector op */ + N_Vector yprev; /* temporary vectors for performing solve */ + N_Vector gy; + N_Vector fold; + N_Vector gold; + N_Vector delta; /* correction vector (change between 2 iterates) */ + int curiter; /* current iteration number in a solve attempt */ + int maxiters; /* maximum number of iterations per solve attempt */ + long int niters; /* total number of iterations across all solves */ + long int nconvfails; /* total number of convergence failures */ + void* ctest_data; /* data to pass to convergence test function */ }; -typedef struct _SUNNonlinearSolverContent_FixedPoint *SUNNonlinearSolverContent_FixedPoint; +typedef struct _SUNNonlinearSolverContent_FixedPoint* SUNNonlinearSolverContent_FixedPoint; /* ----------------------------------------------------------------------------- II: Exported functions ---------------------------------------------------------------------------*/ /* Constructor to create solver and allocates memory */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m); -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, + SUNContext sunctx); /* core functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, realtype tol, - booleantype callSetup, void *mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, + N_Vector y, N_Vector w, sunrealtype tol, + sunbooleantype callSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS); /* set functions */ -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolConvTestFn CTestFn, - void* ctest_data); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); -SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, - int maxiters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, + int maxiters); -SUNDIALS_EXPORT int SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, - realtype beta); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, + sunrealtype beta); /* get functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, - long int *niters); - -SUNDIALS_EXPORT int SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, - int *iter); - -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, - long int *nconvfails); - -SUNDIALS_EXPORT int SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn *SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, + long int* niters); -SUNDIALS_EXPORT int SUNNonlinSolSetInfoFile_FixedPoint(SUNNonlinearSolver NLS, - FILE* info_file); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, int* iter); -SUNDIALS_EXPORT int SUNNonlinSolSetPrintLevel_FixedPoint(SUNNonlinearSolver NLS, - int print_level); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, + long int* nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_newton.h b/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_newton.h index db2624bdc..ef7774e74 100644 --- a/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_newton.h +++ b/deps/AMICI/ThirdParty/sundials/include/sunnonlinsol/sunnonlinsol_newton.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,11 +22,11 @@ #ifndef _SUNNONLINSOL_NEWTON_H #define _SUNNONLINSOL_NEWTON_H -#include "sundials/sundials_types.h" -#include "sundials/sundials_nvector.h" #include "sundials/sundials_nonlinearsolver.h" +#include "sundials/sundials_nvector.h" +#include "sundials/sundials_types.h" -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -34,87 +34,90 @@ extern "C" { * I. Content structure * ---------------------------------------------------------------------------*/ -struct _SUNNonlinearSolverContent_Newton { - +struct _SUNNonlinearSolverContent_Newton +{ /* functions provided by the integrator */ - SUNNonlinSolSysFn Sys; /* nonlinear system residual function */ - SUNNonlinSolLSetupFn LSetup; /* linear solver setup function */ - SUNNonlinSolLSolveFn LSolve; /* linear solver solve function */ - SUNNonlinSolConvTestFn CTest; /* nonlinear solver convergence test function */ + SUNNonlinSolSysFn Sys; /* nonlinear system residual function */ + SUNNonlinSolLSetupFn LSetup; /* linear solver setup function */ + SUNNonlinSolLSolveFn LSolve; /* linear solver solve function */ + SUNNonlinSolConvTestFn CTest; /* nonlinear solver convergence test function */ /* nonlinear solver variables */ - N_Vector delta; /* Newton update vector */ - booleantype jcur; /* Jacobian status, current = SUNTRUE / stale = SUNFALSE */ - int curiter; /* current number of iterations in a solve attempt */ - int maxiters; /* maximum number of iterations in a solve attempt */ - long int niters; /* total number of nonlinear iterations across all solves */ - long int nconvfails; /* total number of convergence failures across all solves */ - void* ctest_data; /* data to pass to convergence test function */ - - /* if 0 (default) nothing is printed, if 1 the residual is printed every iteration */ - int print_level; - /* if NULL nothing is printed, if 1 the residual is printed every iteration */ - FILE* info_file; + N_Vector delta; /* Newton update vector */ + sunbooleantype jcur; /* Jacobian status, current = SUNTRUE / stale = SUNFALSE */ + int curiter; /* current number of iterations in a solve attempt */ + int maxiters; /* maximum number of iterations in a solve attempt */ + long int niters; /* total number of nonlinear iterations across all solves */ + long int nconvfails; /* total number of convergence failures across all solves + */ + void* ctest_data; /* data to pass to convergence test function */ }; -typedef struct _SUNNonlinearSolverContent_Newton *SUNNonlinearSolverContent_Newton; +typedef struct _SUNNonlinearSolverContent_Newton* SUNNonlinearSolverContent_Newton; /* ----------------------------------------------------------------------------- * II: Exported functions * ---------------------------------------------------------------------------*/ /* Constructor to create solver and allocates memory */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y); -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, + SUNContext sunctx); /* core functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, realtype tol, - booleantype callLSetup, void *mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, + N_Vector w, sunrealtype tol, + sunbooleantype callLSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS); /* set functions */ -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSetupFn LSetupFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn LSetupFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSolveFn LSolveFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn LSolveFn); -SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolConvTestFn CTestFn, - void* ctest_data); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); -SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, - int maxiters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, int maxiters); /* get functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, - long int *niters); - -SUNDIALS_EXPORT int SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, - int *iter); - -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, - long int *nconvfails); - -SUNDIALS_EXPORT int SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn *SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, + long int* niters); -SUNDIALS_EXPORT int SUNNonlinSolSetInfoFile_Newton(SUNNonlinearSolver NLS, - FILE* info_file); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, int* iter); -SUNDIALS_EXPORT int SUNNonlinSolSetPrintLevel_Newton(SUNNonlinearSolver NLS, - int print_level); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, + long int* nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/CMakeLists.txt index 0c8e4e496..dbe00927c 100644 --- a/deps/AMICI/ThirdParty/sundials/src/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/CMakeLists.txt @@ -3,7 +3,7 @@ # Cody Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -22,6 +22,7 @@ add_subdirectory(sunmatrix) add_subdirectory(sunlinsol) add_subdirectory(sunnonlinsol) add_subdirectory(sunmemory) +add_subdirectory(sunadaptcontroller) # ARKODE library if(BUILD_ARKODE) diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/cvodes/CMakeLists.txt index e1a5a9964..1879c4961 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/CMakeLists.txt @@ -3,7 +3,7 @@ # Radu Serban, Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -25,14 +25,13 @@ set(cvodes_SOURCES cvodes_bandpre.c cvodes_bbdpre.c cvodes_diag.c - cvodes_direct.c cvodes_io.c cvodes_ls.c cvodes_nls.c cvodes_nls_sim.c cvodes_nls_stg.c cvodes_nls_stg1.c - cvodes_spils.c + cvodes_proj.c ) # Add variable cvodes_HEADERS with the exported CVODES header files @@ -41,9 +40,8 @@ set(cvodes_HEADERS cvodes_bandpre.h cvodes_bbdpre.h cvodes_diag.h - cvodes_direct.h cvodes_ls.h - cvodes_spils.h + cvodes_proj.h ) # Add prefix with complete path to the CVODES header files @@ -57,8 +55,10 @@ sundials_add_library(sundials_cvodes ${cvodes_HEADERS} INCLUDE_SUBDIR cvodes + LINK_LIBRARIES + PUBLIC sundials_core OBJECT_LIBRARIES - sundials_generic_obj + sundials_sunmemsys_obj sundials_nvecserial_obj sundials_sunmatrixband_obj sundials_sunmatrixdense_obj @@ -85,5 +85,5 @@ message(STATUS "Added CVODES module") # Add F2003 module if the interface is enabled if(BUILD_FORTRAN_MODULE_INTERFACE) - add_subdirectory(fmod) + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/LICENSE b/deps/AMICI/ThirdParty/sundials/src/cvodes/LICENSE index 4ba2c4848..2b12386cc 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/LICENSE +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2002-2021, Lawrence Livermore National Security and Southern Methodist University. +Copyright (c) 2002-2024, Lawrence Livermore National Security and Southern Methodist University. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/README.md b/deps/AMICI/ThirdParty/sundials/src/cvodes/README.md index 392e3b198..0c4171ee5 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/README.md +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/README.md @@ -1,7 +1,7 @@ # CVODES -### Version 5.8.0 (Sep 2021) +### Version 7.1.1 (Jun 2024) -**Alan C. Hindmarsh, Radu Serban, Cody J. Balos, David J. Gardner, +**Alan C. Hindmarsh, Radu Serban, Cody J. Balos, David J. Gardner, and Carol S. Woodward, Center for Applied Scientific Computing, LLNL** **Daniel R. Reynolds, Department of Mathematics, Southern Methodist University** @@ -27,14 +27,13 @@ nonlinear solver APIs used across SUNDIALS packages. ## Documentation -See the [CVODES User Guide](/doc/cvodes/cvs_guide.pdf) and -[CVODES Examples](/doc/cvodes/cvs_examples.pdf) document for more information -about CVODES usage and the provided example programs respectively. +See the CVODES documentation at [Read the Docs](https://sundials.readthedocs.io/en/latest/cvodes) +for more information about CVODES usage. ## Installation -For installation instructions see the [INSTALL_GUIDE](/INSTALL_GUIDE.pdf) -or the "Installation Procedure" chapter in the CVODES User Guide. +For installation instructions see the +[SUNDIALS Installation Guide](https://sundials.readthedocs.io/en/latest/Install_link.html). ## Release History @@ -45,11 +44,11 @@ the "SUNDIALS Release History" appendix of the CVODES User Guide. ## References * A. C. Hindmarsh, R. Serban, C. J. Balos, D. J. Gardner, D. R. Reynolds - and C. S. Woodward, "User Documentation for CVODES v5.8.0," - LLNL technical report UCRL-SM-208111, Sep 2021. + and C. S. Woodward, "User Documentation for CVODES v7.1.1," + LLNL technical report UCRL-SM-208111, Jun 2024. -* A. C. Hindmarsh and R. Serban, "Example Programs for CVODES v5.8.0," - LLNL technical report UCRL-SM-208115, Sep 2021. +* A. C. Hindmarsh and R. Serban, "Example Programs for CVODES v7.1.1," + LLNL technical report UCRL-SM-208115, Jun 2024. * R. Serban and A. C. Hindmarsh, "CVODES: the Sensitivity-Enabled ODE solver in SUNDIALS," Proceedings of IDETC/CIE 2005, Sept. 2005, diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea.c index ddde603dc..2df97cf71 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea.c @@ -3,7 +3,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -24,23 +24,28 @@ #include #include - -#include "cvodes_impl.h" - #include #include +#include "cvodes_impl.h" + /* * ================================================================= * CVODEA PRIVATE CONSTANTS * ================================================================= */ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define HUNDRED RCONST(100.0) /* real 100.0 */ -#define FUZZ_FACTOR RCONST(1000000.0) /* fuzz factor for IMget */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWO SUN_RCONST(2.0) /* real 2.0 */ +#define HUNDRED SUN_RCONST(100.0) /* real 100.0 */ +#define FUZZ_FACTOR SUN_RCONST(1000000.0) /* fuzz factor for IMget */ + +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define CV_PROFILER cv_mem->cv_sunctx->profiler /* * ================================================================= @@ -48,35 +53,35 @@ * ================================================================= */ -static CkpntMem CVAckpntInit(CVodeMem cv_mem); -static CkpntMem CVAckpntNew(CVodeMem cv_mem); -static void CVAckpntDelete(CkpntMem *ck_memPtr); +static CVckpntMem CVAckpntInit(CVodeMem cv_mem); +static CVckpntMem CVAckpntNew(CVodeMem cv_mem); +static void CVAckpntDelete(CVckpntMem* ck_memPtr); -static void CVAbckpbDelete(CVodeBMem *cvB_memPtr); +static void CVAbckpbDelete(CVodeBMem* cvB_memPtr); -static int CVAdataStore(CVodeMem cv_mem, CkpntMem ck_mem); -static int CVAckpntGet(CVodeMem cv_mem, CkpntMem ck_mem); +static int CVAdataStore(CVodeMem cv_mem, CVckpntMem ck_mem); +static int CVAckpntGet(CVodeMem cv_mem, CVckpntMem ck_mem); -static int CVAfindIndex(CVodeMem cv_mem, realtype t, - long int *indx, booleantype *newpoint); +static int CVAfindIndex(CVodeMem cv_mem, sunrealtype t, long int* indx, + sunbooleantype* newpoint); -static booleantype CVAhermiteMalloc(CVodeMem cv_mem); +static sunbooleantype CVAhermiteMalloc(CVodeMem cv_mem); static void CVAhermiteFree(CVodeMem cv_mem); -static int CVAhermiteGetY(CVodeMem cv_mem, realtype t, N_Vector y, N_Vector *yS); -static int CVAhermiteStorePnt(CVodeMem cv_mem, DtpntMem d); +static int CVAhermiteGetY(CVodeMem cv_mem, sunrealtype t, N_Vector y, + N_Vector* yS); +static int CVAhermiteStorePnt(CVodeMem cv_mem, CVdtpntMem d); -static booleantype CVApolynomialMalloc(CVodeMem cv_mem); +static sunbooleantype CVApolynomialMalloc(CVodeMem cv_mem); static void CVApolynomialFree(CVodeMem cv_mem); -static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, N_Vector y, N_Vector *yS); -static int CVApolynomialStorePnt(CVodeMem cv_mem, DtpntMem d); +static int CVApolynomialGetY(CVodeMem cv_mem, sunrealtype t, N_Vector y, + N_Vector* yS); +static int CVApolynomialStorePnt(CVodeMem cv_mem, CVdtpntMem d); /* Wrappers */ -static int CVArhs(realtype t, N_Vector yB, - N_Vector yBdot, void *cvode_mem); +static int CVArhs(sunrealtype t, N_Vector yB, N_Vector yBdot, void* cvode_mem); -static int CVArhsQ(realtype t, N_Vector yB, - N_Vector qBdot, void *cvode_mem); +static int CVArhsQ(sunrealtype t, N_Vector yB, N_Vector qBdot, void* cvode_mem); /* * ================================================================= @@ -91,7 +96,7 @@ static int CVArhsQ(realtype t, N_Vector yB, * memory structure. */ -int CVodeAdjInit(void *cvode_mem, long int steps, int interp) +int CVodeAdjInit(void* cvode_mem, long int steps, int interp) { CVadjMem ca_mem; CVodeMem cv_mem; @@ -101,20 +106,29 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) * Check arguments * --------------- */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeAdjInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } cv_mem = (CVodeMem)cvode_mem; - if (steps <= 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeAdjInit", MSGCV_BAD_STEPS); - return(CV_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (steps <= 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_STEPS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - if ( (interp != CV_HERMITE) && (interp != CV_POLYNOMIAL) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeAdjInit", MSGCV_BAD_INTERP); - return(CV_ILL_INPUT); + if ((interp != CV_HERMITE) && (interp != CV_POLYNOMIAL)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_INTERP); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* ---------------------------- @@ -122,10 +136,13 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) * ---------------------------- */ ca_mem = NULL; - ca_mem = (CVadjMem) malloc(sizeof(struct CVadjMemRec)); - if (ca_mem == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + ca_mem = (CVadjMem)malloc(sizeof(struct CVadjMemRec)); + if (ca_mem == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* Attach ca_mem to CVodeMem structure */ @@ -163,29 +180,44 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) /* Allocate space for the array of Data Point structures */ ca_mem->dt_mem = NULL; - ca_mem->dt_mem = (DtpntMem *) malloc((steps+1)*sizeof(struct DtpntMemRec *)); - if (ca_mem->dt_mem == NULL) { - free(ca_mem); ca_mem = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + ca_mem->dt_mem = + (CVdtpntMem*)malloc((steps + 1) * sizeof(struct CVdtpntMemRec*)); + if (ca_mem->dt_mem == NULL) + { + free(ca_mem); + ca_mem = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } - for (i=0; i<=steps; i++) { + for (i = 0; i <= steps; i++) + { ca_mem->dt_mem[i] = NULL; - ca_mem->dt_mem[i] = (DtpntMem) malloc(sizeof(struct DtpntMemRec)); - if (ca_mem->dt_mem[i] == NULL) { - for(ii=0; iidt_mem[ii]); ca_mem->dt_mem[ii] = NULL;} - free(ca_mem->dt_mem); ca_mem->dt_mem = NULL; - free(ca_mem); ca_mem = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + ca_mem->dt_mem[i] = (CVdtpntMem)malloc(sizeof(struct CVdtpntMemRec)); + if (ca_mem->dt_mem[i] == NULL) + { + for (ii = 0; ii < i; ii++) + { + free(ca_mem->dt_mem[ii]); + ca_mem->dt_mem[ii] = NULL; + } + free(ca_mem->dt_mem); + ca_mem->dt_mem = NULL; + free(ca_mem); + ca_mem = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } } /* Attach functions for the appropriate interpolation module */ - switch(interp) { - + switch (interp) + { case CV_HERMITE: ca_mem->ca_IMmalloc = CVAhermiteMalloc; @@ -203,7 +235,6 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) ca_mem->ca_IMstore = CVApolynomialStorePnt; break; - } /* The interpolation module has not been initialized yet */ @@ -216,16 +247,16 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) * - IMinterpSensi will be set in CVodeB to SUNTRUE if IMstoreSensi is * SUNTRUE and if at least one backward problem requires sensitivities */ - ca_mem->ca_IMstoreSensi = SUNTRUE; + ca_mem->ca_IMstoreSensi = SUNTRUE; ca_mem->ca_IMinterpSensi = SUNFALSE; /* ------------------------------------ * Initialize list of backward problems * ------------------------------------ */ - ca_mem->cvB_mem = NULL; + ca_mem->cvB_mem = NULL; ca_mem->ca_bckpbCrt = NULL; - ca_mem->ca_nbckpbs = 0; + ca_mem->ca_nbckpbs = 0; /* -------------------------------- * CVodeF and CVodeB not called yet @@ -242,10 +273,11 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) * ASA initialized and allocated * --------------------------------------------- */ - cv_mem->cv_adj = SUNTRUE; + cv_mem->cv_adj = SUNTRUE; cv_mem->cv_adjMallocDone = SUNTRUE; - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* CVodeAdjReInit @@ -263,34 +295,39 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) * ASA with CVodeAdjInit. */ -int CVodeAdjReInit(void *cvode_mem) +int CVodeAdjReInit(void* cvode_mem) { CVadjMem ca_mem; CVodeMem cv_mem; /* Check cvode_mem */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeAdjReInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeAdjReInit", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Free current list of Check Points */ - while (ca_mem->ck_mem != NULL) CVAckpntDelete(&(ca_mem->ck_mem)); + while (ca_mem->ck_mem != NULL) { CVAckpntDelete(&(ca_mem->ck_mem)); } /* Initialization of check points */ - ca_mem->ck_mem = NULL; - ca_mem->ca_nckpnts = 0; + ca_mem->ck_mem = NULL; + ca_mem->ca_nckpnts = 0; ca_mem->ca_ckpntData = NULL; /* CVodeF and CVodeB not called yet */ @@ -299,7 +336,8 @@ int CVodeAdjReInit(void *cvode_mem) ca_mem->ca_tstopCVodeFcall = SUNFALSE; ca_mem->ca_firstCVodeBcall = SUNTRUE; - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -308,27 +346,26 @@ int CVodeAdjReInit(void *cvode_mem) * This routine frees the memory allocated by CVodeAdjInit. */ -void CVodeAdjFree(void *cvode_mem) +void CVodeAdjFree(void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; long int i; - if (cvode_mem == NULL) return; - cv_mem = (CVodeMem) cvode_mem; - - if (cv_mem->cv_adjMallocDone) { + if (cvode_mem == NULL) { return; } + cv_mem = (CVodeMem)cvode_mem; + if (cv_mem->cv_adjMallocDone) + { ca_mem = cv_mem->cv_adj_mem; /* Delete check points one by one */ - while (ca_mem->ck_mem != NULL) CVAckpntDelete(&(ca_mem->ck_mem)); + while (ca_mem->ck_mem != NULL) { CVAckpntDelete(&(ca_mem->ck_mem)); } /* Free vectors at all data points */ - if (ca_mem->ca_IMmallocDone) { - ca_mem->ca_IMfree(cv_mem); - } - for(i=0; i<=ca_mem->ca_nsteps; i++) { + if (ca_mem->ca_IMmallocDone) { ca_mem->ca_IMfree(cv_mem); } + for (i = 0; i <= ca_mem->ca_nsteps; i++) + { free(ca_mem->dt_mem[i]); ca_mem->dt_mem[i] = NULL; } @@ -336,14 +373,12 @@ void CVodeAdjFree(void *cvode_mem) ca_mem->dt_mem = NULL; /* Delete backward problems one by one */ - while (ca_mem->cvB_mem != NULL) CVAbckpbDelete(&(ca_mem->cvB_mem)); + while (ca_mem->cvB_mem != NULL) { CVAbckpbDelete(&(ca_mem->cvB_mem)); } /* Free CVODEA memory */ free(ca_mem); cv_mem->cv_adj_mem = NULL; - } - } /* @@ -357,49 +392,63 @@ void CVodeAdjFree(void *cvode_mem) * ncheckPtr points to the number of check points stored so far. */ -int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, - realtype *tret, int itask, int *ncheckPtr) +int CVodeF(void* cvode_mem, sunrealtype tout, N_Vector yout, sunrealtype* tret, + int itask, int* ncheckPtr) { CVadjMem ca_mem; CVodeMem cv_mem; - CkpntMem tmp; - DtpntMem *dt_mem; + CVckpntMem tmp; + CVdtpntMem* dt_mem; long int nstloc; int flag, i; - booleantype allocOK, earlyret; - realtype ttest; + sunbooleantype allocOK, earlyret; + sunrealtype ttest; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeF", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeF", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check for yout != NULL */ - if (yout == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_YOUT_NULL); - return(CV_ILL_INPUT); + if (yout == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_YOUT_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Check for tret != NULL */ - if (tret == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_TRET_NULL); - return(CV_ILL_INPUT); + if (tret == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Check for valid itask */ - if ( (itask != CV_NORMAL) && (itask != CV_ONE_STEP) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_BAD_ITASK); - return(CV_ILL_INPUT); + if ((itask != CV_NORMAL) && (itask != CV_ONE_STEP)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* All error checking done */ @@ -407,9 +456,10 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, dt_mem = ca_mem->dt_mem; /* If tstop is enabled, store some info */ - if (cv_mem->cv_tstopset) { + if (cv_mem->cv_tstopset) + { ca_mem->ca_tstopCVodeFcall = SUNTRUE; - ca_mem->ca_tstopCVodeF = cv_mem->cv_tstop; + ca_mem->ca_tstopCVodeF = cv_mem->cv_tstop; } /* On the first step: @@ -419,45 +469,51 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, * - load dt_mem[0] * On subsequent steps, test if taking a new step is necessary. */ - if ( ca_mem->ca_firstCVodeFcall ) { - + if (ca_mem->ca_firstCVodeFcall) + { ca_mem->ca_tinitial = cv_mem->cv_tn; ca_mem->ck_mem = CVAckpntInit(cv_mem); - if (ca_mem->ck_mem == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeF", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (ca_mem->ck_mem == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } - if ( !ca_mem->ca_IMmallocDone ) { - + if (!ca_mem->ca_IMmallocDone) + { /* Do we need to store sensitivities? */ - if (!cv_mem->cv_sensi) ca_mem->ca_IMstoreSensi = SUNFALSE; + if (!cv_mem->cv_sensi) { ca_mem->ca_IMstoreSensi = SUNFALSE; } /* Allocate space for interpolation data */ allocOK = ca_mem->ca_IMmalloc(cv_mem); - if (!allocOK) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeF", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (!allocOK) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* Rename zn and, if needed, znS for use in interpolation */ - for (i=0;ica_Y[i] = cv_mem->cv_zn[i]; - if (ca_mem->ca_IMstoreSensi) { - for (i=0;ica_YS[i] = cv_mem->cv_znS[i]; + for (i = 0; i < L_MAX; i++) { ca_mem->ca_Y[i] = cv_mem->cv_zn[i]; } + if (ca_mem->ca_IMstoreSensi) + { + for (i = 0; i < L_MAX; i++) { ca_mem->ca_YS[i] = cv_mem->cv_znS[i]; } } ca_mem->ca_IMmallocDone = SUNTRUE; - } dt_mem[0]->t = ca_mem->ck_mem->ck_t0; ca_mem->ca_IMstore(cv_mem, dt_mem[0]); ca_mem->ca_firstCVodeFcall = SUNFALSE; - - } else if ( itask == CV_NORMAL ) { - + } + else if (itask == CV_NORMAL) + { /* When in normal mode, check if tout was passed or if a previous root was not reported and return an interpolated solution. No changes to ck_mem or dt_mem are needed. */ @@ -469,39 +525,44 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, to the current time tn */ ttest = (ca_mem->ca_rootret) ? ca_mem->ca_troot : cv_mem->cv_tn; - if ((ttest - tout)*cv_mem->cv_h >= ZERO) { + if ((ttest - tout) * cv_mem->cv_h >= ZERO) + { /* ttest is after tout, interpolate to tout */ - *tret = tout; - flag = CVodeGetDky(cv_mem, tout, 0, yout); + *tret = tout; + flag = CVodeGetDky(cv_mem, tout, 0, yout); earlyret = SUNTRUE; - } else if (ca_mem->ca_rootret) { + } + else if (ca_mem->ca_rootret) + { /* tout is after troot, interpolate to troot */ - *tret = ca_mem->ca_troot; - flag = CVodeGetDky(cv_mem, ca_mem->ca_troot, 0, yout); - flag = CV_ROOT_RETURN; + *tret = ca_mem->ca_troot; + flag = CVodeGetDky(cv_mem, ca_mem->ca_troot, 0, yout); + flag = CV_ROOT_RETURN; ca_mem->ca_rootret = SUNFALSE; - earlyret = SUNTRUE; + earlyret = SUNTRUE; } /* return if necessary */ - if (earlyret) { - *ncheckPtr = ca_mem->ca_nckpnts; + if (earlyret) + { + *ncheckPtr = ca_mem->ca_nckpnts; ca_mem->ca_IMnewData = SUNTRUE; ca_mem->ca_ckpntData = ca_mem->ck_mem; - ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; - return(flag); + ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } - } /* Integrate to tout (in CV_ONE_STEP mode) while loading check points */ nstloc = 0; - for(;;) { - + for (;;) + { /* Check for too many steps */ - if ( (cv_mem->cv_mxstep>0) && (nstloc >= cv_mem->cv_mxstep) ) { - cvProcessError(cv_mem, CV_TOO_MUCH_WORK, "CVODEA", "CVodeF", + if ((cv_mem->cv_mxstep > 0) && (nstloc >= cv_mem->cv_mxstep)) + { + cvProcessError(cv_mem, CV_TOO_MUCH_WORK, __LINE__, __func__, __FILE__, MSGCV_MAX_STEPS, cv_mem->cv_tn); flag = CV_TOO_MUCH_WORK; break; @@ -510,24 +571,26 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, /* Perform one step of the integration */ flag = CVode(cv_mem, tout, yout, tret, CV_ONE_STEP); - if (flag < 0) break; + if (flag < 0) { break; } nstloc++; /* Test if a new check point is needed */ - if ( cv_mem->cv_nst % ca_mem->ca_nsteps == 0 ) { - + if (cv_mem->cv_nst % ca_mem->ca_nsteps == 0) + { ca_mem->ck_mem->ck_t1 = cv_mem->cv_tn; /* Create a new check point, load it, and append it to the list */ tmp = CVAckpntNew(cv_mem); - if (tmp == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeF", MSGCV_MEM_FAIL); + if (tmp == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); flag = CV_MEM_FAIL; break; } - tmp->ck_next = ca_mem->ck_mem; + tmp->ck_next = ca_mem->ck_mem; ca_mem->ck_mem = tmp; ca_mem->ca_nckpnts++; cv_mem->cv_forceSetup = SUNTRUE; @@ -535,13 +598,12 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, /* Reset i=0 and load dt_mem[0] */ dt_mem[0]->t = ca_mem->ck_mem->ck_t0; ca_mem->ca_IMstore(cv_mem, dt_mem[0]); - - } else { - + } + else + { /* Load next point in dt_mem */ dt_mem[cv_mem->cv_nst % ca_mem->ca_nsteps]->t = cv_mem->cv_tn; ca_mem->ca_IMstore(cv_mem, dt_mem[cv_mem->cv_nst % ca_mem->ca_nsteps]); - } /* Set t1 field of the current ckeck point structure @@ -553,22 +615,23 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, ca_mem->ca_tfinal = cv_mem->cv_tn; /* Return if in CV_ONE_STEP mode */ - if (itask == CV_ONE_STEP) break; + if (itask == CV_ONE_STEP) { break; } /* CV_NORMAL_STEP returns */ /* Return if tout reached */ - if ( (*tret - tout)*cv_mem->cv_h >= ZERO ) { - + if ((*tret - tout) * cv_mem->cv_h >= ZERO) + { /* If this was a root return, save the root time to return later */ - if (flag == CV_ROOT_RETURN) { + if (flag == CV_ROOT_RETURN) + { ca_mem->ca_rootret = SUNTRUE; ca_mem->ca_troot = *tret; } /* Get solution value at tout to return now */ *tret = tout; - flag = CVodeGetDky(cv_mem, tout, 0, yout); + flag = CVodeGetDky(cv_mem, tout, 0, yout); /* Reset tretlast in cv_mem so that CVodeGetQuad and CVodeGetSens * evaluate quadratures and/or sensitivities at the proper time */ @@ -578,7 +641,7 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, } /* Return if tstop or a root was found */ - if ( (flag == CV_TSTOP_RETURN) || (flag == CV_ROOT_RETURN) ) break; + if ((flag == CV_TSTOP_RETURN) || (flag == CV_ROOT_RETURN)) { break; } } /* end of for(;;) */ @@ -588,93 +651,94 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, /* Data is available for the last interval */ ca_mem->ca_IMnewData = SUNTRUE; ca_mem->ca_ckpntData = ca_mem->ck_mem; - ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; + ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } - - /* * ================================================================= * FUNCTIONS FOR BACKWARD PROBLEMS * ================================================================= */ - -int CVodeCreateB(void *cvode_mem, int lmmB, int *which) +int CVodeCreateB(void* cvode_mem, int lmmB, int* which) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem new_cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeCreateB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeCreateB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Allocate space for new CVodeBMem object */ new_cvB_mem = NULL; - new_cvB_mem = (CVodeBMem) malloc(sizeof(struct CVodeBMemRec)); - if (new_cvB_mem == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeCreateB", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + new_cvB_mem = (CVodeBMem)malloc(sizeof(struct CVodeBMemRec)); + if (new_cvB_mem == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } /* Create and set a new CVODES object for the backward problem */ - cvodeB_mem = CVodeCreate(lmmB); - if (cvodeB_mem == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeCreateB", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cvodeB_mem = CVodeCreate(lmmB, cv_mem->cv_sunctx); + if (cvodeB_mem == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } CVodeSetUserData(cvodeB_mem, cvode_mem); CVodeSetMaxHnilWarns(cvodeB_mem, -1); - CVodeSetErrHandlerFn(cvodeB_mem, cv_mem->cv_ehfun, cv_mem->cv_eh_data); - CVodeSetErrFile(cvodeB_mem, cv_mem->cv_errfp); - /* Set/initialize fields in the new CVodeBMem object, new_cvB_mem */ - new_cvB_mem->cv_index = ca_mem->ca_nbckpbs; + new_cvB_mem->cv_index = ca_mem->ca_nbckpbs; - new_cvB_mem->cv_mem = (CVodeMem) cvodeB_mem; + new_cvB_mem->cv_mem = (CVodeMem)cvodeB_mem; - new_cvB_mem->cv_f = NULL; - new_cvB_mem->cv_fs = NULL; + new_cvB_mem->cv_f = NULL; + new_cvB_mem->cv_fs = NULL; - new_cvB_mem->cv_fQ = NULL; - new_cvB_mem->cv_fQs = NULL; + new_cvB_mem->cv_fQ = NULL; + new_cvB_mem->cv_fQs = NULL; - new_cvB_mem->cv_user_data = NULL; + new_cvB_mem->cv_user_data = NULL; - new_cvB_mem->cv_lmem = NULL; - new_cvB_mem->cv_lfree = NULL; - new_cvB_mem->cv_pmem = NULL; - new_cvB_mem->cv_pfree = NULL; + new_cvB_mem->cv_lmem = NULL; + new_cvB_mem->cv_lfree = NULL; + new_cvB_mem->cv_pmem = NULL; + new_cvB_mem->cv_pfree = NULL; - new_cvB_mem->cv_y = NULL; + new_cvB_mem->cv_y = NULL; - new_cvB_mem->cv_f_withSensi = SUNFALSE; + new_cvB_mem->cv_f_withSensi = SUNFALSE; new_cvB_mem->cv_fQ_withSensi = SUNFALSE; /* Attach the new object to the linked list cvB_mem */ new_cvB_mem->cv_next = ca_mem->cvB_mem; - ca_mem->cvB_mem = new_cvB_mem; + ca_mem->cvB_mem = new_cvB_mem; /* Return the index of the newly created CVodeBMem object. * This must be passed to CVodeInitB and to other ***B @@ -684,499 +748,599 @@ int CVodeCreateB(void *cvode_mem, int lmmB, int *which) ca_mem->ca_nbckpbs++; - return(CV_SUCCESS); + return (CV_SUCCESS); } -int CVodeInitB(void *cvode_mem, int which, - CVRhsFnB fB, - realtype tB0, N_Vector yB0) +int CVodeInitB(void* cvode_mem, int which, CVRhsFnB fB, sunrealtype tB0, + N_Vector yB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeInitB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeInitB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeInitB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Allocate and set the CVODES object */ flag = CVodeInit(cvodeB_mem, CVArhs, tB0, yB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); + } /* Copy fB function in cvB_mem */ cvB_mem->cv_f_withSensi = SUNFALSE; - cvB_mem->cv_f = fB; + cvB_mem->cv_f = fB; /* Allocate space and initialize the y Nvector in cvB_mem */ cvB_mem->cv_t0 = tB0; - cvB_mem->cv_y = N_VClone(yB0); + cvB_mem->cv_y = N_VClone(yB0); N_VScale(ONE, yB0, cvB_mem->cv_y); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } -int CVodeInitBS(void *cvode_mem, int which, - CVRhsFnBS fBs, - realtype tB0, N_Vector yB0) +int CVodeInitBS(void* cvode_mem, int which, CVRhsFnBS fBs, sunrealtype tB0, + N_Vector yB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeInitBS", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeInitBS", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeInitBS", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Allocate and set the CVODES object */ flag = CVodeInit(cvodeB_mem, CVArhs, tB0, yB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); + } /* Copy fBs function in cvB_mem */ cvB_mem->cv_f_withSensi = SUNTRUE; - cvB_mem->cv_fs = fBs; + cvB_mem->cv_fs = fBs; /* Allocate space and initialize the y Nvector in cvB_mem */ cvB_mem->cv_t0 = tB0; - cvB_mem->cv_y = N_VClone(yB0); + cvB_mem->cv_y = N_VClone(yB0); N_VScale(ONE, yB0, cvB_mem->cv_y); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } - -int CVodeReInitB(void *cvode_mem, int which, - realtype tB0, N_Vector yB0) +int CVodeReInitB(void* cvode_mem, int which, sunrealtype tB0, N_Vector yB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeReInitB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeReInitB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeReInitB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Reinitialize CVODES object */ flag = CVodeReInit(cvodeB_mem, tB0, yB0); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } - -int CVodeSStolerancesB(void *cvode_mem, int which, realtype reltolB, realtype abstolB) +int CVodeSStolerancesB(void* cvode_mem, int which, sunrealtype reltolB, + sunrealtype abstolB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSStolerancesB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSStolerancesB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSStolerancesB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Set tolerances */ flag = CVodeSStolerances(cvodeB_mem, reltolB, abstolB); - return(flag); + return (flag); } - -int CVodeSVtolerancesB(void *cvode_mem, int which, realtype reltolB, N_Vector abstolB) +int CVodeSVtolerancesB(void* cvode_mem, int which, sunrealtype reltolB, + N_Vector abstolB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSVtolerancesB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSVtolerancesB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSVtolerancesB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Set tolerances */ flag = CVodeSVtolerances(cvodeB_mem, reltolB, abstolB); - return(flag); + return (flag); } - -int CVodeQuadInitB(void *cvode_mem, int which, - CVQuadRhsFnB fQB, N_Vector yQB0) +int CVodeQuadInitB(void* cvode_mem, int which, CVQuadRhsFnB fQB, N_Vector yQB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeQuadInitB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadInitB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadInitB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeQuadInit(cvodeB_mem, CVArhsQ, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); + } cvB_mem->cv_fQ_withSensi = SUNFALSE; - cvB_mem->cv_fQ = fQB; + cvB_mem->cv_fQ = fQB; - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } -int CVodeQuadInitBS(void *cvode_mem, int which, - CVQuadRhsFnBS fQBs, N_Vector yQB0) +int CVodeQuadInitBS(void* cvode_mem, int which, CVQuadRhsFnBS fQBs, N_Vector yQB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeQuadInitBS", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadInitBS", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadInitBS", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeQuadInit(cvodeB_mem, CVArhsQ, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); + } cvB_mem->cv_fQ_withSensi = SUNTRUE; - cvB_mem->cv_fQs = fQBs; + cvB_mem->cv_fQs = fQBs; - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } -int CVodeQuadReInitB(void *cvode_mem, int which, N_Vector yQB0) +int CVodeQuadReInitB(void* cvode_mem, int which, N_Vector yQB0) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeQuadReInitB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadReInitB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadReInitB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeQuadReInit(cvodeB_mem, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); + } - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } -int CVodeQuadSStolerancesB(void *cvode_mem, int which, realtype reltolQB, realtype abstolQB) +int CVodeQuadSStolerancesB(void* cvode_mem, int which, sunrealtype reltolQB, + sunrealtype abstolQB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeQuadSStolerances(cvodeB_mem, reltolQB, abstolQB); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } -int CVodeQuadSVtolerancesB(void *cvode_mem, int which, realtype reltolQB, N_Vector abstolQB) +int CVodeQuadSVtolerancesB(void* cvode_mem, int which, sunrealtype reltolQB, + N_Vector abstolQB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeQuadSVtolerances(cvodeB_mem, reltolQB, abstolQB); - return(flag); + return (flag); } /* @@ -1198,45 +1362,54 @@ int CVodeQuadSVtolerancesB(void *cvode_mem, int which, realtype reltolQB, N_Vect * when called in ONE_STEP mode. */ -int CVodeB(void *cvode_mem, realtype tBout, int itaskB) +int CVodeB(void* cvode_mem, sunrealtype tBout, int itaskB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem, tmp_cvB_mem; - CkpntMem ck_mem; - int sign, flag=0; - realtype tfuzz, tBret, tBn; - booleantype gotCheckpoint, isActive, reachedTBout; + CVckpntMem ck_mem; + int sign, flag = 0; + sunrealtype tfuzz, tBret, tBn; + sunbooleantype gotCheckpoint, isActive, reachedTBout; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check if any backward problem has been defined */ - if ( ca_mem->ca_nbckpbs == 0 ) { - cvProcessError(cv_mem, CV_NO_BCK, "CVODEA", "CVodeB", MSGCV_NO_BCK); - return(CV_NO_BCK); + if (ca_mem->ca_nbckpbs == 0) + { + cvProcessError(cv_mem, CV_NO_BCK, __LINE__, __func__, __FILE__, MSGCV_NO_BCK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_BCK); } cvB_mem = ca_mem->cvB_mem; /* Check whether CVodeF has been called */ - if ( ca_mem->ca_firstCVodeFcall ) { - cvProcessError(cv_mem, CV_NO_FWD, "CVODEA", "CVodeB", MSGCV_NO_FWD); - return(CV_NO_FWD); + if (ca_mem->ca_firstCVodeFcall) + { + cvProcessError(cv_mem, CV_NO_FWD, __LINE__, __func__, __FILE__, MSGCV_NO_FWD); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_FWD); } sign = (ca_mem->ca_tfinal - ca_mem->ca_tinitial > ZERO) ? 1 : -1; @@ -1246,36 +1419,45 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) * - check whether we need to interpolate forward sensitivities */ - if ( ca_mem->ca_firstCVodeBcall ) { - + if (ca_mem->ca_firstCVodeBcall) + { tmp_cvB_mem = cvB_mem; - while(tmp_cvB_mem != NULL) { - + while (tmp_cvB_mem != NULL) + { tBn = tmp_cvB_mem->cv_mem->cv_tn; - if ( (sign*(tBn-ca_mem->ca_tinitial) < ZERO) || (sign*(ca_mem->ca_tfinal-tBn) < ZERO) ) { - cvProcessError(cv_mem, CV_BAD_TB0, "CVODEA", "CVodeB", MSGCV_BAD_TB0, - tmp_cvB_mem->cv_index); - return(CV_BAD_TB0); + if ((sign * (tBn - ca_mem->ca_tinitial) < ZERO) || + (sign * (ca_mem->ca_tfinal - tBn) < ZERO)) + { + cvProcessError(cv_mem, CV_BAD_TB0, __LINE__, __func__, __FILE__, + MSGCV_BAD_TB0, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_TB0); } - if (sign*(tBn-tBout) <= ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_TBOUT, - tmp_cvB_mem->cv_index); - return(CV_ILL_INPUT); + if (sign * (tBn - tBout) <= ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_TBOUT, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - if ( tmp_cvB_mem->cv_f_withSensi || tmp_cvB_mem->cv_fQ_withSensi ) - ca_mem->ca_IMinterpSensi = SUNTRUE; + if (tmp_cvB_mem->cv_f_withSensi || tmp_cvB_mem->cv_fQ_withSensi) + { + ca_mem->ca_IMinterpSensi = SUNTRUE; + } tmp_cvB_mem = tmp_cvB_mem->cv_next; - } - if ( ca_mem->ca_IMinterpSensi && !ca_mem->ca_IMstoreSensi) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_SENSI); - return(CV_ILL_INPUT); + if (ca_mem->ca_IMinterpSensi && !ca_mem->ca_IMstoreSensi) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_SENSI); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } ca_mem->ca_firstCVodeBcall = SUNFALSE; @@ -1283,20 +1465,32 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) /* Check if itaskB is legal */ - if ( (itaskB != CV_NORMAL) && (itaskB != CV_ONE_STEP) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_ITASKB); - return(CV_ILL_INPUT); + if ((itaskB != CV_NORMAL) && (itaskB != CV_ONE_STEP)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ITASKB); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Check if tBout is legal */ - if ( (sign*(tBout-ca_mem->ca_tinitial) < ZERO) || (sign*(ca_mem->ca_tfinal-tBout) < ZERO) ) { - tfuzz = HUNDRED*cv_mem->cv_uround*(SUNRabs(ca_mem->ca_tinitial) + SUNRabs(ca_mem->ca_tfinal)); - if ( (sign*(tBout-ca_mem->ca_tinitial) < ZERO) && (SUNRabs(tBout-ca_mem->ca_tinitial) < tfuzz) ) { + if ((sign * (tBout - ca_mem->ca_tinitial) < ZERO) || + (sign * (ca_mem->ca_tfinal - tBout) < ZERO)) + { + tfuzz = HUNDRED * cv_mem->cv_uround * + (SUNRabs(ca_mem->ca_tinitial) + SUNRabs(ca_mem->ca_tfinal)); + if ((sign * (tBout - ca_mem->ca_tinitial) < ZERO) && + (SUNRabs(tBout - ca_mem->ca_tinitial) < tfuzz)) + { tBout = ca_mem->ca_tinitial; - } else { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_TBOUT); - return(CV_ILL_INPUT); + } + else + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_TBOUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } } @@ -1308,18 +1502,22 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) gotCheckpoint = SUNFALSE; - for(;;) { - + for (;;) + { tmp_cvB_mem = cvB_mem; - while(tmp_cvB_mem != NULL) { + while (tmp_cvB_mem != NULL) + { tBn = tmp_cvB_mem->cv_mem->cv_tn; - if ( sign*(tBn-ck_mem->ck_t0) > ZERO ) { + if (sign * (tBn - ck_mem->ck_t0) > ZERO) + { gotCheckpoint = SUNTRUE; break; } - if ( (itaskB==CV_NORMAL) && (tBn == ck_mem->ck_t0) && (sign*(tBout-ck_mem->ck_t0) >= ZERO) ) { + if ((itaskB == CV_NORMAL) && (tBn == ck_mem->ck_t0) && + (sign * (tBout - ck_mem->ck_t0) >= ZERO)) + { gotCheckpoint = SUNTRUE; break; } @@ -1327,9 +1525,9 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) tmp_cvB_mem = tmp_cvB_mem->cv_next; } - if (gotCheckpoint) break; + if (gotCheckpoint) { break; } - if (ck_mem->ck_next == NULL) break; + if (ck_mem->ck_next == NULL) { break; } ck_mem = ck_mem->ck_next; } @@ -1337,51 +1535,60 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) /* Starting with the current check point from above, loop over check points while propagating backward problems */ - for(;;) { - + for (;;) + { /* Store interpolation data if not available. This is the 2nd forward integration pass */ - if (ck_mem != ca_mem->ca_ckpntData) { + if (ck_mem != ca_mem->ca_ckpntData) + { flag = CVAdataStore(cv_mem, ck_mem); - if (flag != CV_SUCCESS) break; + if (flag != CV_SUCCESS) { break; } } /* Loop through all backward problems and, if needed, * propagate their solution towards tBout */ tmp_cvB_mem = cvB_mem; - while (tmp_cvB_mem != NULL) { - + while (tmp_cvB_mem != NULL) + { /* Decide if current backward problem is "active" in this check point */ isActive = SUNTRUE; tBn = tmp_cvB_mem->cv_mem->cv_tn; - if ( (tBn == ck_mem->ck_t0) && (sign*(tBout-ck_mem->ck_t0) < ZERO ) ) isActive = SUNFALSE; - if ( (tBn == ck_mem->ck_t0) && (itaskB==CV_ONE_STEP) ) isActive = SUNFALSE; - - if ( sign * (tBn - ck_mem->ck_t0) < ZERO ) isActive = SUNFALSE; + if ((tBn == ck_mem->ck_t0) && (sign * (tBout - ck_mem->ck_t0) < ZERO)) + { + isActive = SUNFALSE; + } + if ((tBn == ck_mem->ck_t0) && (itaskB == CV_ONE_STEP)) + { + isActive = SUNFALSE; + } - if ( isActive ) { + if (sign * (tBn - ck_mem->ck_t0) < ZERO) { isActive = SUNFALSE; } + if (isActive) + { /* Store the address of current backward problem memory * in ca_mem to be used in the wrapper functions */ ca_mem->ca_bckpbCrt = tmp_cvB_mem; /* Integrate current backward problem */ CVodeSetStopTime(tmp_cvB_mem->cv_mem, ck_mem->ck_t0); - flag = CVode(tmp_cvB_mem->cv_mem, tBout, tmp_cvB_mem->cv_y, &tBret, itaskB); + flag = CVode(tmp_cvB_mem->cv_mem, tBout, tmp_cvB_mem->cv_y, &tBret, + itaskB); /* Set the time at which we will report solution and/or quadratures */ tmp_cvB_mem->cv_tout = tBret; /* If an error occurred, exit while loop */ - if (flag < 0) break; - - } else { - flag = CV_SUCCESS; + if (flag < 0) { break; } + } + else + { + flag = CV_SUCCESS; tmp_cvB_mem->cv_tout = tBn; } @@ -1392,141 +1599,152 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) /* If an error occurred, return now */ - if (flag <0) { - cvProcessError(cv_mem, flag, "CVODEA", "CVodeB", MSGCV_BACK_ERROR, - tmp_cvB_mem->cv_index); - return(flag); + if (flag < 0) + { + cvProcessError(cv_mem, flag, __LINE__, __func__, __FILE__, + MSGCV_BACK_ERROR, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } /* If in CV_ONE_STEP mode, return now (flag = CV_SUCCESS) */ - if (itaskB == CV_ONE_STEP) break; + if (itaskB == CV_ONE_STEP) { break; } /* If all backward problems have succesfully reached tBout, return now */ reachedTBout = SUNTRUE; tmp_cvB_mem = cvB_mem; - while(tmp_cvB_mem != NULL) { - if ( sign*(tmp_cvB_mem->cv_tout - tBout) > ZERO ) { + while (tmp_cvB_mem != NULL) + { + if (sign * (tmp_cvB_mem->cv_tout - tBout) > ZERO) + { reachedTBout = SUNFALSE; break; } tmp_cvB_mem = tmp_cvB_mem->cv_next; } - if ( reachedTBout ) break; + if (reachedTBout) { break; } /* Move check point in linked list to next one */ ck_mem = ck_mem->ck_next; - } - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } - -int CVodeGetB(void *cvode_mem, int which, realtype *tret, N_Vector yB) +int CVodeGetB(void* cvode_mem, int which, sunrealtype* tret, N_Vector yB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeGetB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } N_VScale(ONE, cvB_mem->cv_y, yB); *tret = cvB_mem->cv_tout; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * CVodeGetQuadB */ -int CVodeGetQuadB(void *cvode_mem, int which, realtype *tret, N_Vector qB) +int CVodeGetQuadB(void* cvode_mem, int which, sunrealtype* tret, N_Vector qB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; long int nstB; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetQuadB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetQuadB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeGetQuadB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* If the integration for this backward problem has not started yet, * simply return the current value of qB (i.e. the final conditions) */ flag = CVodeGetNumSteps(cvodeB_mem, &nstB); - if (nstB == 0) { + if (nstB == 0) + { N_VScale(ONE, cvB_mem->cv_mem->cv_znQ[0], qB); *tret = cvB_mem->cv_tout; - } else { - flag = CVodeGetQuad(cvodeB_mem, tret, qB); } + else { flag = CVodeGetQuad(cvodeB_mem, tret, qB); } - return(flag); + return (flag); } - /* * ================================================================= * PRIVATE FUNCTIONS FOR CHECK POINTS @@ -1540,27 +1758,31 @@ int CVodeGetQuadB(void *cvode_mem, int which, realtype *tret, N_Vector qB) * information from the initial time. */ -static CkpntMem CVAckpntInit(CVodeMem cv_mem) +static CVckpntMem CVAckpntInit(CVodeMem cv_mem) { - CkpntMem ck_mem; + CVckpntMem ck_mem; int is; /* Allocate space for ckdata */ ck_mem = NULL; - ck_mem = (CkpntMem) malloc(sizeof(struct CkpntMemRec)); - if (ck_mem == NULL) return(NULL); + ck_mem = (CVckpntMem)malloc(sizeof(struct CVckpntMemRec)); + if (ck_mem == NULL) { return (NULL); } ck_mem->ck_zn[0] = N_VClone(cv_mem->cv_tempv); - if (ck_mem->ck_zn[0] == NULL) { - free(ck_mem); ck_mem = NULL; - return(NULL); + if (ck_mem->ck_zn[0] == NULL) + { + free(ck_mem); + ck_mem = NULL; + return (NULL); } ck_mem->ck_zn[1] = N_VClone(cv_mem->cv_tempv); - if (ck_mem->ck_zn[1] == NULL) { + if (ck_mem->ck_zn[1] == NULL) + { N_VDestroy(ck_mem->ck_zn[0]); - free(ck_mem); ck_mem = NULL; - return(NULL); + free(ck_mem); + ck_mem = NULL; + return (NULL); } /* ck_mem->ck_zn[qmax] was not allocated */ @@ -1568,76 +1790,80 @@ static CkpntMem CVAckpntInit(CVodeMem cv_mem) /* Load ckdata from cv_mem */ N_VScale(ONE, cv_mem->cv_zn[0], ck_mem->ck_zn[0]); - ck_mem->ck_t0 = cv_mem->cv_tn; - ck_mem->ck_nst = 0; - ck_mem->ck_q = 1; - ck_mem->ck_h = 0.0; + ck_mem->ck_t0 = cv_mem->cv_tn; + ck_mem->ck_nst = 0; + ck_mem->ck_q = 1; + ck_mem->ck_h = ZERO; /* Do we need to carry quadratures */ ck_mem->ck_quadr = cv_mem->cv_quadr && cv_mem->cv_errconQ; - if (ck_mem->ck_quadr) { - + if (ck_mem->ck_quadr) + { ck_mem->ck_znQ[0] = N_VClone(cv_mem->cv_tempvQ); - if (ck_mem->ck_znQ[0] == NULL) { + if (ck_mem->ck_znQ[0] == NULL) + { N_VDestroy(ck_mem->ck_zn[0]); N_VDestroy(ck_mem->ck_zn[1]); - free(ck_mem); ck_mem = NULL; - return(NULL); + free(ck_mem); + ck_mem = NULL; + return (NULL); } N_VScale(ONE, cv_mem->cv_znQ[0], ck_mem->ck_znQ[0]); - } /* Do we need to carry sensitivities? */ ck_mem->ck_sensi = cv_mem->cv_sensi; - if (ck_mem->ck_sensi) { - + if (ck_mem->ck_sensi) + { ck_mem->ck_Ns = cv_mem->cv_Ns; ck_mem->ck_znS[0] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (ck_mem->ck_znS[0] == NULL) { + if (ck_mem->ck_znS[0] == NULL) + { N_VDestroy(ck_mem->ck_zn[0]); N_VDestroy(ck_mem->ck_zn[1]); - if (ck_mem->ck_quadr) N_VDestroy(ck_mem->ck_znQ[0]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (ck_mem->ck_quadr) { N_VDestroy(ck_mem->ck_znQ[0]); } + free(ck_mem); + ck_mem = NULL; + return (NULL); } - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znS[0], ck_mem->ck_znS[0]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znS[0], ck_mem->ck_znS[0]); } /* Do we need to carry quadrature sensitivities? */ ck_mem->ck_quadr_sensi = cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS; - if (ck_mem->ck_quadr_sensi) { + if (ck_mem->ck_quadr_sensi) + { ck_mem->ck_znQS[0] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempvQ); - if (ck_mem->ck_znQS[0] == NULL) { + if (ck_mem->ck_znQS[0] == NULL) + { N_VDestroy(ck_mem->ck_zn[0]); N_VDestroy(ck_mem->ck_zn[1]); - if (ck_mem->ck_quadr) N_VDestroy(ck_mem->ck_znQ[0]); + if (ck_mem->ck_quadr) { N_VDestroy(ck_mem->ck_znQ[0]); } N_VDestroyVectorArray(ck_mem->ck_znS[0], cv_mem->cv_Ns); - free(ck_mem); ck_mem = NULL; - return(NULL); + free(ck_mem); + ck_mem = NULL; + return (NULL); } - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znQS[0], ck_mem->ck_znQS[0]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znQS[0], ck_mem->ck_znQS[0]); } /* Next in list */ - ck_mem->ck_next = NULL; + ck_mem->ck_next = NULL; - return(ck_mem); + return (ck_mem); } /* @@ -1647,15 +1873,15 @@ static CkpntMem CVAckpntInit(CVodeMem cv_mem) * its data from current values in cv_mem. */ -static CkpntMem CVAckpntNew(CVodeMem cv_mem) +static CVckpntMem CVAckpntNew(CVodeMem cv_mem) { - CkpntMem ck_mem; + CVckpntMem ck_mem; int j, jj, is, qmax; /* Allocate space for ckdata */ ck_mem = NULL; - ck_mem = (CkpntMem) malloc(sizeof(struct CkpntMemRec)); - if (ck_mem == NULL) return(NULL); + ck_mem = (CVckpntMem)malloc(sizeof(struct CVckpntMemRec)); + if (ck_mem == NULL) { return (NULL); } /* Set cv_next to NULL */ ck_mem->ck_next = NULL; @@ -1663,204 +1889,290 @@ static CkpntMem CVAckpntNew(CVodeMem cv_mem) /* Test if we need to allocate space for the last zn. * NOTE: zn(qmax) may be needed for a hot restart, if an order * increase is deemed necessary at the first step after a check point */ - qmax = cv_mem->cv_qmax; + qmax = cv_mem->cv_qmax; ck_mem->ck_zqm = (cv_mem->cv_q < qmax) ? qmax : 0; - for (j=0; j<=cv_mem->cv_q; j++) { + for (j = 0; j <= cv_mem->cv_q; j++) + { ck_mem->ck_zn[j] = N_VClone(cv_mem->cv_tempv); - if (ck_mem->ck_zn[j] == NULL) { - for (jj=0; jjck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (ck_mem->ck_zn[j] == NULL) + { + for (jj = 0; jj < j; jj++) { N_VDestroy(ck_mem->ck_zn[jj]); } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - if (cv_mem->cv_q < qmax) { + if (cv_mem->cv_q < qmax) + { ck_mem->ck_zn[qmax] = N_VClone(cv_mem->cv_tempv); - if (ck_mem->ck_zn[qmax] == NULL) { - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (ck_mem->ck_zn[qmax] == NULL) + { + for (jj = 0; jj <= cv_mem->cv_q; jj++) { N_VDestroy(ck_mem->ck_zn[jj]); } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } /* Test if we need to carry quadratures */ ck_mem->ck_quadr = cv_mem->cv_quadr && cv_mem->cv_errconQ; - if (ck_mem->ck_quadr) { - - for (j=0; j<=cv_mem->cv_q; j++) { + if (ck_mem->ck_quadr) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { ck_mem->ck_znQ[j] = N_VClone(cv_mem->cv_tempvQ); - if(ck_mem->ck_znQ[j] == NULL) { - for (jj=0; jjck_znQ[jj]); - if (cv_mem->cv_q < qmax) N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; j++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (ck_mem->ck_znQ[j] == NULL) + { + for (jj = 0; jj < j; jj++) { N_VDestroy(ck_mem->ck_znQ[jj]); } + if (cv_mem->cv_q < qmax) { N_VDestroy(ck_mem->ck_zn[qmax]); } + for (jj = 0; jj <= cv_mem->cv_q; j++) { N_VDestroy(ck_mem->ck_zn[jj]); } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - if (cv_mem->cv_q < qmax) { + if (cv_mem->cv_q < qmax) + { ck_mem->ck_znQ[qmax] = N_VClone(cv_mem->cv_tempvQ); - if (ck_mem->ck_znQ[qmax] == NULL) { - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_znQ[jj]); + if (ck_mem->ck_znQ[qmax] == NULL) + { + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_znQ[jj]); + } N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - } /* Test if we need to carry sensitivities */ ck_mem->ck_sensi = cv_mem->cv_sensi; - if (ck_mem->ck_sensi) { - + if (ck_mem->ck_sensi) + { ck_mem->ck_Ns = cv_mem->cv_Ns; - for (j=0; j<=cv_mem->cv_q; j++) { + for (j = 0; j <= cv_mem->cv_q; j++) + { ck_mem->ck_znS[j] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (ck_mem->ck_znS[j] == NULL) { - for (jj=0; jjck_znS[jj], cv_mem->cv_Ns); - if (ck_mem->ck_quadr) { - if (cv_mem->cv_q < qmax) N_VDestroy(ck_mem->ck_znQ[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_znQ[jj]); + if (ck_mem->ck_znS[j] == NULL) + { + for (jj = 0; jj < j; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); + } + if (ck_mem->ck_quadr) + { + if (cv_mem->cv_q < qmax) { N_VDestroy(ck_mem->ck_znQ[qmax]); } + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_znQ[jj]); + } } - if (cv_mem->cv_q < qmax) N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (cv_mem->cv_q < qmax) { N_VDestroy(ck_mem->ck_zn[qmax]); } + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - if ( cv_mem->cv_q < qmax) { + if (cv_mem->cv_q < qmax) + { ck_mem->ck_znS[qmax] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (ck_mem->ck_znS[qmax] == NULL) { - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); - if (ck_mem->ck_quadr) { + if (ck_mem->ck_znS[qmax] == NULL) + { + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); + } + if (ck_mem->ck_quadr) + { N_VDestroy(ck_mem->ck_znQ[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_znQ[jj]); + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_znQ[jj]); + } } N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - } /* Test if we need to carry quadrature sensitivities */ ck_mem->ck_quadr_sensi = cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS; - if (ck_mem->ck_quadr_sensi) { - - for (j=0; j<=cv_mem->cv_q; j++) { + if (ck_mem->ck_quadr_sensi) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { ck_mem->ck_znQS[j] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempvQ); - if (ck_mem->ck_znQS[j] == NULL) { - for (jj=0; jjck_znQS[jj], cv_mem->cv_Ns); - if (cv_mem->cv_q < qmax) N_VDestroyVectorArray(ck_mem->ck_znS[qmax], cv_mem->cv_Ns); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); - if (ck_mem->ck_quadr) { - if (cv_mem->cv_q < qmax) N_VDestroy(ck_mem->ck_znQ[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_znQ[jj]); + if (ck_mem->ck_znQS[j] == NULL) + { + for (jj = 0; jj < j; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znQS[jj], cv_mem->cv_Ns); } - if (cv_mem->cv_q < qmax) N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + if (cv_mem->cv_q < qmax) + { + N_VDestroyVectorArray(ck_mem->ck_znS[qmax], cv_mem->cv_Ns); + } + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); + } + if (ck_mem->ck_quadr) + { + if (cv_mem->cv_q < qmax) { N_VDestroy(ck_mem->ck_znQ[qmax]); } + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_znQ[jj]); + } + } + if (cv_mem->cv_q < qmax) { N_VDestroy(ck_mem->ck_zn[qmax]); } + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - if ( cv_mem->cv_q < qmax) { - ck_mem->ck_znQS[qmax] = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempvQ); - if (ck_mem->ck_znQS[qmax] == NULL) { - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroyVectorArray(ck_mem->ck_znQS[jj], cv_mem->cv_Ns); + if (cv_mem->cv_q < qmax) + { + ck_mem->ck_znQS[qmax] = N_VCloneVectorArray(cv_mem->cv_Ns, + cv_mem->cv_tempvQ); + if (ck_mem->ck_znQS[qmax] == NULL) + { + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znQS[jj], cv_mem->cv_Ns); + } N_VDestroyVectorArray(ck_mem->ck_znS[qmax], cv_mem->cv_Ns); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); - if (ck_mem->ck_quadr) { + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroyVectorArray(ck_mem->ck_znS[jj], cv_mem->cv_Ns); + } + if (ck_mem->ck_quadr) + { N_VDestroy(ck_mem->ck_znQ[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } } N_VDestroy(ck_mem->ck_zn[qmax]); - for (jj=0; jj<=cv_mem->cv_q; jj++) N_VDestroy(ck_mem->ck_zn[jj]); - free(ck_mem); ck_mem = NULL; - return(NULL); + for (jj = 0; jj <= cv_mem->cv_q; jj++) + { + N_VDestroy(ck_mem->ck_zn[jj]); + } + free(ck_mem); + ck_mem = NULL; + return (NULL); } } - } /* Load check point data from cv_mem */ - for (j=0; j<=cv_mem->cv_q; j++) - cv_mem->cv_cvals[j] = ONE; + for (j = 0; j <= cv_mem->cv_q; j++) { cv_mem->cv_cvals[j] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_q+1, cv_mem->cv_cvals, - cv_mem->cv_zn, ck_mem->ck_zn); + (void)N_VScaleVectorArray(cv_mem->cv_q + 1, cv_mem->cv_cvals, cv_mem->cv_zn, + ck_mem->ck_zn); - if ( cv_mem->cv_q < qmax ) + if (cv_mem->cv_q < qmax) + { N_VScale(ONE, cv_mem->cv_zn[qmax], ck_mem->ck_zn[qmax]); + } - if (ck_mem->ck_quadr) { - for (j=0; j<=cv_mem->cv_q; j++) - cv_mem->cv_cvals[j] = ONE; + if (ck_mem->ck_quadr) + { + for (j = 0; j <= cv_mem->cv_q; j++) { cv_mem->cv_cvals[j] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_q+1, cv_mem->cv_cvals, - cv_mem->cv_znQ, ck_mem->ck_znQ); + (void)N_VScaleVectorArray(cv_mem->cv_q + 1, cv_mem->cv_cvals, + cv_mem->cv_znQ, ck_mem->ck_znQ); - if ( cv_mem->cv_q < qmax ) + if (cv_mem->cv_q < qmax) + { N_VScale(ONE, cv_mem->cv_znQ[qmax], ck_mem->ck_znQ[qmax]); + } } - if (ck_mem->ck_sensi) { - for (j=0; j<=cv_mem->cv_q; j++) { - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[j*cv_mem->cv_Ns+is] = ONE; - cv_mem->cv_Xvecs[j*cv_mem->cv_Ns+is] = cv_mem->cv_znS[j][is]; - cv_mem->cv_Zvecs[j*cv_mem->cv_Ns+is] = ck_mem->ck_znS[j][is]; + if (ck_mem->ck_sensi) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[j * cv_mem->cv_Ns + is] = ONE; + cv_mem->cv_Xvecs[j * cv_mem->cv_Ns + is] = cv_mem->cv_znS[j][is]; + cv_mem->cv_Zvecs[j * cv_mem->cv_Ns + is] = ck_mem->ck_znS[j][is]; } } - (void) N_VScaleVectorArray(cv_mem->cv_Ns*(cv_mem->cv_q+1), - cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Zvecs); + (void)N_VScaleVectorArray(cv_mem->cv_Ns * (cv_mem->cv_q + 1), + cv_mem->cv_cvals, cv_mem->cv_Xvecs, + cv_mem->cv_Zvecs); - if ( cv_mem->cv_q < qmax ) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_q < qmax) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znS[qmax], ck_mem->ck_znS[qmax]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znS[qmax], ck_mem->ck_znS[qmax]); } } - if (ck_mem->ck_quadr_sensi) { - for (j=0; j<=cv_mem->cv_q; j++) { - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[j*cv_mem->cv_Ns+is] = ONE; - cv_mem->cv_Xvecs[j*cv_mem->cv_Ns+is] = cv_mem->cv_znQS[j][is]; - cv_mem->cv_Zvecs[j*cv_mem->cv_Ns+is] = ck_mem->ck_znQS[j][is]; + if (ck_mem->ck_quadr_sensi) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[j * cv_mem->cv_Ns + is] = ONE; + cv_mem->cv_Xvecs[j * cv_mem->cv_Ns + is] = cv_mem->cv_znQS[j][is]; + cv_mem->cv_Zvecs[j * cv_mem->cv_Ns + is] = ck_mem->ck_znQS[j][is]; } } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Zvecs); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_Xvecs, + cv_mem->cv_Zvecs); - if ( cv_mem->cv_q < qmax ) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_q < qmax) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znQS[qmax], ck_mem->ck_znQS[qmax]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znQS[qmax], ck_mem->ck_znQS[qmax]); } } - for (j=0; j<=L_MAX; j++) ck_mem->ck_tau[j] = cv_mem->cv_tau[j]; - for (j=0; j<=NUM_TESTS; j++) ck_mem->ck_tq[j] = cv_mem->cv_tq[j]; - for (j=0; j<=cv_mem->cv_q; j++) ck_mem->ck_l[j] = cv_mem->cv_l[j]; + for (j = 0; j <= L_MAX; j++) { ck_mem->ck_tau[j] = cv_mem->cv_tau[j]; } + for (j = 0; j <= NUM_TESTS; j++) { ck_mem->ck_tq[j] = cv_mem->cv_tq[j]; } + for (j = 0; j <= cv_mem->cv_q; j++) { ck_mem->ck_l[j] = cv_mem->cv_l[j]; } ck_mem->ck_nst = cv_mem->cv_nst; ck_mem->ck_tretlast = cv_mem->cv_tretlast; ck_mem->ck_q = cv_mem->cv_q; @@ -1876,7 +2188,7 @@ static CkpntMem CVAckpntNew(CVodeMem cv_mem) ck_mem->ck_t0 = cv_mem->cv_tn; ck_mem->ck_saved_tq5 = cv_mem->cv_saved_tq5; - return(ck_mem); + return (ck_mem); } /* @@ -1886,12 +2198,12 @@ static CkpntMem CVAckpntNew(CVodeMem cv_mem) * the new list head */ -static void CVAckpntDelete(CkpntMem *ck_memPtr) +static void CVAckpntDelete(CVckpntMem* ck_memPtr) { - CkpntMem tmp; + CVckpntMem tmp; int j; - if (*ck_memPtr == NULL) return; + if (*ck_memPtr == NULL) { return; } /* store head of list */ tmp = *ck_memPtr; @@ -1900,53 +2212,62 @@ static void CVAckpntDelete(CkpntMem *ck_memPtr) *ck_memPtr = (*ck_memPtr)->ck_next; /* free N_Vectors in tmp */ - for (j=0;j<=tmp->ck_q;j++) N_VDestroy(tmp->ck_zn[j]); - if (tmp->ck_zqm != 0) N_VDestroy(tmp->ck_zn[tmp->ck_zqm]); + for (j = 0; j <= tmp->ck_q; j++) { N_VDestroy(tmp->ck_zn[j]); } + if (tmp->ck_zqm != 0) { N_VDestroy(tmp->ck_zn[tmp->ck_zqm]); } /* free N_Vectors for quadratures in tmp * Note that at the check point at t_initial, only znQ_[0] * was allocated */ - if (tmp->ck_quadr) { - - if (tmp->ck_next != NULL) { - for (j=0;j<=tmp->ck_q;j++) N_VDestroy(tmp->ck_znQ[j]); - if (tmp->ck_zqm != 0) N_VDestroy(tmp->ck_znQ[tmp->ck_zqm]); - } else { - N_VDestroy(tmp->ck_znQ[0]); + if (tmp->ck_quadr) + { + if (tmp->ck_next != NULL) + { + for (j = 0; j <= tmp->ck_q; j++) { N_VDestroy(tmp->ck_znQ[j]); } + if (tmp->ck_zqm != 0) { N_VDestroy(tmp->ck_znQ[tmp->ck_zqm]); } } - + else { N_VDestroy(tmp->ck_znQ[0]); } } /* free N_Vectors for sensitivities in tmp * Note that at the check point at t_initial, only znS_[0] * was allocated */ - if (tmp->ck_sensi) { - - if (tmp->ck_next != NULL) { - for (j=0;j<=tmp->ck_q;j++) N_VDestroyVectorArray(tmp->ck_znS[j], tmp->ck_Ns); - if (tmp->ck_zqm != 0) N_VDestroyVectorArray(tmp->ck_znS[tmp->ck_zqm], tmp->ck_Ns); - } else { - N_VDestroyVectorArray(tmp->ck_znS[0], tmp->ck_Ns); + if (tmp->ck_sensi) + { + if (tmp->ck_next != NULL) + { + for (j = 0; j <= tmp->ck_q; j++) + { + N_VDestroyVectorArray(tmp->ck_znS[j], tmp->ck_Ns); + } + if (tmp->ck_zqm != 0) + { + N_VDestroyVectorArray(tmp->ck_znS[tmp->ck_zqm], tmp->ck_Ns); + } } - + else { N_VDestroyVectorArray(tmp->ck_znS[0], tmp->ck_Ns); } } /* free N_Vectors for quadrature sensitivities in tmp * Note that at the check point at t_initial, only znQS_[0] * was allocated */ - if (tmp->ck_quadr_sensi) { - - if (tmp->ck_next != NULL) { - for (j=0;j<=tmp->ck_q;j++) N_VDestroyVectorArray(tmp->ck_znQS[j], tmp->ck_Ns); - if (tmp->ck_zqm != 0) N_VDestroyVectorArray(tmp->ck_znQS[tmp->ck_zqm], tmp->ck_Ns); - } else { - N_VDestroyVectorArray(tmp->ck_znQS[0], tmp->ck_Ns); + if (tmp->ck_quadr_sensi) + { + if (tmp->ck_next != NULL) + { + for (j = 0; j <= tmp->ck_q; j++) + { + N_VDestroyVectorArray(tmp->ck_znQS[j], tmp->ck_Ns); + } + if (tmp->ck_zqm != 0) + { + N_VDestroyVectorArray(tmp->ck_znQS[tmp->ck_zqm], tmp->ck_Ns); + } } - + else { N_VDestroyVectorArray(tmp->ck_znQS[0], tmp->ck_Ns); } } - free(tmp); tmp = NULL; - + free(tmp); + tmp = NULL; } /* @@ -1955,13 +2276,13 @@ static void CVAckpntDelete(CkpntMem *ck_memPtr) * ================================================================= */ -static void CVAbckpbDelete(CVodeBMem *cvB_memPtr) +static void CVAbckpbDelete(CVodeBMem* cvB_memPtr) { CVodeBMem tmp; - void *cvode_mem; - - if (*cvB_memPtr != NULL) { + void* cvode_mem; + if (*cvB_memPtr != NULL) + { /* Save head of the list */ tmp = *cvB_memPtr; @@ -1969,22 +2290,21 @@ static void CVAbckpbDelete(CVodeBMem *cvB_memPtr) *cvB_memPtr = (*cvB_memPtr)->cv_next; /* Free CVODES memory in tmp */ - cvode_mem = (void *)(tmp->cv_mem); + cvode_mem = (void*)(tmp->cv_mem); CVodeFree(&cvode_mem); /* Free linear solver memory */ - if (tmp->cv_lfree != NULL) tmp->cv_lfree(tmp); + if (tmp->cv_lfree != NULL) { tmp->cv_lfree(tmp); } /* Free preconditioner memory */ - if (tmp->cv_pfree != NULL) tmp->cv_pfree(tmp); + if (tmp->cv_pfree != NULL) { tmp->cv_pfree(tmp); } /* Free workspace Nvector */ N_VDestroy(tmp->cv_y); - free(tmp); tmp = NULL; - + free(tmp); + tmp = NULL; } - } /* @@ -2005,11 +2325,11 @@ static void CVAbckpbDelete(CVodeBMem *cvB_memPtr) * CV_FWD_FAIL */ -static int CVAdataStore(CVodeMem cv_mem, CkpntMem ck_mem) +static int CVAdataStore(CVodeMem cv_mem, CVckpntMem ck_mem) { CVadjMem ca_mem; - DtpntMem *dt_mem; - realtype t; + CVdtpntMem* dt_mem; + sunrealtype t; long int i; int flag, sign; @@ -2018,44 +2338,37 @@ static int CVAdataStore(CVodeMem cv_mem, CkpntMem ck_mem) /* Initialize cv_mem with data from ck_mem */ flag = CVAckpntGet(cv_mem, ck_mem); - if (flag != CV_SUCCESS) - return(CV_REIFWD_FAIL); + if (flag != CV_SUCCESS) { return (CV_REIFWD_FAIL); } /* Set first structure in dt_mem[0] */ dt_mem[0]->t = ck_mem->ck_t0; ca_mem->ca_IMstore(cv_mem, dt_mem[0]); /* Decide whether TSTOP must be activated */ - if (ca_mem->ca_tstopCVodeFcall) { + if (ca_mem->ca_tstopCVodeFcall) + { CVodeSetStopTime(cv_mem, ca_mem->ca_tstopCVodeF); } sign = (ca_mem->ca_tfinal - ca_mem->ca_tinitial > ZERO) ? 1 : -1; - /* Run CVode to set following structures in dt_mem[i] */ i = 1; do { - /* Modified for AMICI - * (dt_mem has dimension ca_mem->ca_nsteps) - */ - if (i > ca_mem->ca_nsteps) return(CV_FWD_FAIL); - flag = CVode(cv_mem, ck_mem->ck_t1, ca_mem->ca_ytmp, &t, CV_ONE_STEP); - if (flag < 0) return(CV_FWD_FAIL); + if (flag < 0) { return (CV_FWD_FAIL); } dt_mem[i]->t = t; ca_mem->ca_IMstore(cv_mem, dt_mem[i]); i++; + } + while (sign * (ck_mem->ck_t1 - t) > ZERO); - } while ( sign*(ck_mem->ck_t1 - t) > ZERO ); - - - ca_mem->ca_IMnewData = SUNTRUE; /* New data is now available */ - ca_mem->ca_ckpntData = ck_mem; /* starting at this check point */ - ca_mem->ca_np = i; /* and we have this many points */ + ca_mem->ca_IMnewData = SUNTRUE; /* New data is now available */ + ca_mem->ca_ckpntData = ck_mem; /* starting at this check point */ + ca_mem->ca_np = i; /* and we have this many points */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -2065,12 +2378,12 @@ static int CVAdataStore(CVodeMem cv_mem, CkpntMem ck_mem) * the check point ck_mem */ -static int CVAckpntGet(CVodeMem cv_mem, CkpntMem ck_mem) +static int CVAckpntGet(CVodeMem cv_mem, CVckpntMem ck_mem) { int flag, j, is, qmax, retval; - if (ck_mem->ck_next == NULL) { - + if (ck_mem->ck_next == NULL) + { /* In this case, we just call the reinitialization routine, * but make sure we use the same initial stepsize as on * the first run. */ @@ -2078,25 +2391,28 @@ static int CVAckpntGet(CVodeMem cv_mem, CkpntMem ck_mem) CVodeSetInitStep(cv_mem, cv_mem->cv_h0u); flag = CVodeReInit(cv_mem, ck_mem->ck_t0, ck_mem->ck_zn[0]); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } - if (ck_mem->ck_quadr) { + if (ck_mem->ck_quadr) + { flag = CVodeQuadReInit(cv_mem, ck_mem->ck_znQ[0]); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } } - if (ck_mem->ck_sensi) { + if (ck_mem->ck_sensi) + { flag = CVodeSensReInit(cv_mem, cv_mem->cv_ism, ck_mem->ck_znS[0]); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } } - if (ck_mem->ck_quadr_sensi) { + if (ck_mem->ck_quadr_sensi) + { flag = CVodeQuadSensReInit(cv_mem, ck_mem->ck_znQS[0]); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } } - - } else { - + } + else + { qmax = cv_mem->cv_qmax; /* Copy parameters from check point data structure */ @@ -2118,87 +2434,96 @@ static int CVAckpntGet(CVodeMem cv_mem, CkpntMem ck_mem) /* Copy the arrays from check point data structure */ - for (j=0; j<=cv_mem->cv_q; j++) - cv_mem->cv_cvals[j] = ONE; + for (j = 0; j <= cv_mem->cv_q; j++) { cv_mem->cv_cvals[j] = ONE; } - retval = N_VScaleVectorArray(cv_mem->cv_q+1, cv_mem->cv_cvals, + retval = N_VScaleVectorArray(cv_mem->cv_q + 1, cv_mem->cv_cvals, ck_mem->ck_zn, cv_mem->cv_zn); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - if ( cv_mem->cv_q < qmax ) + if (cv_mem->cv_q < qmax) + { N_VScale(ONE, ck_mem->ck_zn[qmax], cv_mem->cv_zn[qmax]); + } - if (ck_mem->ck_quadr) { - for (j=0; j<=cv_mem->cv_q; j++) - cv_mem->cv_cvals[j] = ONE; + if (ck_mem->ck_quadr) + { + for (j = 0; j <= cv_mem->cv_q; j++) { cv_mem->cv_cvals[j] = ONE; } - retval = N_VScaleVectorArray(cv_mem->cv_q+1, cv_mem->cv_cvals, + retval = N_VScaleVectorArray(cv_mem->cv_q + 1, cv_mem->cv_cvals, ck_mem->ck_znQ, cv_mem->cv_znQ); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - if ( cv_mem->cv_q < qmax ) + if (cv_mem->cv_q < qmax) + { N_VScale(ONE, ck_mem->ck_znQ[qmax], cv_mem->cv_znQ[qmax]); + } } - if (ck_mem->ck_sensi) { - for (j=0; j<=cv_mem->cv_q; j++) { - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[j*cv_mem->cv_Ns+is] = ONE; - cv_mem->cv_Xvecs[j*cv_mem->cv_Ns+is] = ck_mem->ck_znS[j][is]; - cv_mem->cv_Zvecs[j*cv_mem->cv_Ns+is] = cv_mem->cv_znS[j][is]; + if (ck_mem->ck_sensi) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[j * cv_mem->cv_Ns + is] = ONE; + cv_mem->cv_Xvecs[j * cv_mem->cv_Ns + is] = ck_mem->ck_znS[j][is]; + cv_mem->cv_Zvecs[j * cv_mem->cv_Ns + is] = cv_mem->cv_znS[j][is]; } } - retval = N_VScaleVectorArray(cv_mem->cv_Ns*(cv_mem->cv_q+1), - cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Zvecs); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns * (cv_mem->cv_q + 1), + cv_mem->cv_cvals, cv_mem->cv_Xvecs, + cv_mem->cv_Zvecs); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - if ( cv_mem->cv_q < qmax ) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_q < qmax) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, ck_mem->ck_znS[qmax], cv_mem->cv_znS[qmax]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } } - if (ck_mem->ck_quadr_sensi) { - for (j=0; j<=cv_mem->cv_q; j++) { - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[j*cv_mem->cv_Ns+is] = ONE; - cv_mem->cv_Xvecs[j*cv_mem->cv_Ns+is] = ck_mem->ck_znQS[j][is]; - cv_mem->cv_Zvecs[j*cv_mem->cv_Ns+is] = cv_mem->cv_znQS[j][is]; + if (ck_mem->ck_quadr_sensi) + { + for (j = 0; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[j * cv_mem->cv_Ns + is] = ONE; + cv_mem->cv_Xvecs[j * cv_mem->cv_Ns + is] = ck_mem->ck_znQS[j][is]; + cv_mem->cv_Zvecs[j * cv_mem->cv_Ns + is] = cv_mem->cv_znQS[j][is]; } } - retval = N_VScaleVectorArray(cv_mem->cv_Ns*(cv_mem->cv_q+1), - cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Zvecs); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns * (cv_mem->cv_q + 1), + cv_mem->cv_cvals, cv_mem->cv_Xvecs, + cv_mem->cv_Zvecs); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - if ( cv_mem->cv_q < qmax ) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_q < qmax) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - ck_mem->ck_znQS[qmax], cv_mem->cv_znQS[qmax]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + ck_mem->ck_znQS[qmax], + cv_mem->cv_znQS[qmax]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } } - for (j=0; j<=L_MAX; j++) cv_mem->cv_tau[j] = ck_mem->ck_tau[j]; - for (j=0; j<=NUM_TESTS; j++) cv_mem->cv_tq[j] = ck_mem->ck_tq[j]; - for (j=0; j<=cv_mem->cv_q; j++) cv_mem->cv_l[j] = ck_mem->ck_l[j]; + for (j = 0; j <= L_MAX; j++) { cv_mem->cv_tau[j] = ck_mem->ck_tau[j]; } + for (j = 0; j <= NUM_TESTS; j++) { cv_mem->cv_tq[j] = ck_mem->ck_tq[j]; } + for (j = 0; j <= cv_mem->cv_q; j++) { cv_mem->cv_l[j] = ck_mem->ck_l[j]; } /* Force a call to setup */ cv_mem->cv_forceSetup = SUNTRUE; - } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -2220,13 +2545,13 @@ static int CVAckpntGet(CVodeMem cv_mem, CkpntMem ck_mem) * find indx (t is too far beyond limits). */ -static int CVAfindIndex(CVodeMem cv_mem, realtype t, - long int *indx, booleantype *newpoint) +static int CVAfindIndex(CVodeMem cv_mem, sunrealtype t, long int* indx, + sunbooleantype* newpoint) { CVadjMem ca_mem; - DtpntMem *dt_mem; + CVdtpntMem* dt_mem; int sign; - booleantype to_left, to_right; + sunbooleantype to_left, to_right; ca_mem = cv_mem->cv_adj_mem; dt_mem = ca_mem->dt_mem; @@ -2237,64 +2562,66 @@ static int CVAfindIndex(CVodeMem cv_mem, realtype t, sign = (ca_mem->ca_tfinal - ca_mem->ca_tinitial > ZERO) ? 1 : -1; /* If this is the first time we use new data */ - if (ca_mem->ca_IMnewData) { - ca_mem->ca_ilast = ca_mem->ca_np-1; - *newpoint = SUNTRUE; + if (ca_mem->ca_IMnewData) + { + ca_mem->ca_ilast = ca_mem->ca_np - 1; + *newpoint = SUNTRUE; ca_mem->ca_IMnewData = SUNFALSE; } /* Search for indx starting from ilast */ - to_left = ( sign*(t - dt_mem[ca_mem->ca_ilast-1]->t) < ZERO); - to_right = ( sign*(t - dt_mem[ca_mem->ca_ilast]->t) > ZERO); + to_left = (sign * (t - dt_mem[ca_mem->ca_ilast - 1]->t) < ZERO); + to_right = (sign * (t - dt_mem[ca_mem->ca_ilast]->t) > ZERO); - if ( to_left ) { + if (to_left) + { /* look for a new indx to the left */ *newpoint = SUNTRUE; *indx = ca_mem->ca_ilast; - for(;;) { - if ( *indx == 0 ) break; - if ( sign*(t - dt_mem[*indx-1]->t) <= ZERO ) (*indx)--; - else break; + for (;;) + { + if (*indx == 0) { break; } + if (sign * (t - dt_mem[*indx - 1]->t) <= ZERO) { (*indx)--; } + else { break; } } - if ( *indx == 0 ) - ca_mem->ca_ilast = 1; - else - ca_mem->ca_ilast = *indx; + if (*indx == 0) { ca_mem->ca_ilast = 1; } + else { ca_mem->ca_ilast = *indx; } - if ( *indx == 0 ) { + if (*indx == 0) + { /* t is beyond leftmost limit. Is it too far? */ - if ( SUNRabs(t - dt_mem[0]->t) > FUZZ_FACTOR * cv_mem->cv_uround ) { - return(CV_GETY_BADT); + if (SUNRabs(t - dt_mem[0]->t) > FUZZ_FACTOR * cv_mem->cv_uround) + { + return (CV_GETY_BADT); } } - - } else if ( to_right ) { + } + else if (to_right) + { /* look for a new indx to the right */ *newpoint = SUNTRUE; *indx = ca_mem->ca_ilast; - for(;;) { - if ( sign*(t - dt_mem[*indx]->t) > ZERO) (*indx)++; - else break; + for (;;) + { + if (sign * (t - dt_mem[*indx]->t) > ZERO) { (*indx)++; } + else { break; } } ca_mem->ca_ilast = *indx; - - - } else { + } + else + { /* ilast is still OK */ *indx = ca_mem->ca_ilast; - } - return(CV_SUCCESS); - - + return (CV_SUCCESS); } /* @@ -2304,23 +2631,24 @@ static int CVAfindIndex(CVodeMem cv_mem, realtype t, * The user must allocate space for y. */ -int CVodeGetAdjY(void *cvode_mem, realtype t, N_Vector y) +int CVodeGetAdjY(void* cvode_mem, sunrealtype t, N_Vector y) { CVodeMem cv_mem; CVadjMem ca_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetAdjY", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; ca_mem = cv_mem->cv_adj_mem; flag = ca_mem->ca_IMget(cv_mem, t, y, NULL); - return(flag); + return (flag); } /* @@ -2338,13 +2666,13 @@ int CVodeGetAdjY(void *cvode_mem, realtype t, N_Vector y) * at any other time. */ -static booleantype CVAhermiteMalloc(CVodeMem cv_mem) +static sunbooleantype CVAhermiteMalloc(CVodeMem cv_mem) { CVadjMem ca_mem; - DtpntMem *dt_mem; - HermiteDataMem content; - long int i, ii=0; - booleantype allocOK; + CVdtpntMem* dt_mem; + CVhermiteDataMem content; + long int i, ii = 0; + sunbooleantype allocOK; allocOK = SUNTRUE; @@ -2353,15 +2681,15 @@ static booleantype CVAhermiteMalloc(CVodeMem cv_mem) /* Allocate space for the vectors ytmp and yStmp */ ca_mem->ca_ytmp = N_VClone(cv_mem->cv_tempv); - if (ca_mem->ca_ytmp == NULL) { - return(SUNFALSE); - } + if (ca_mem->ca_ytmp == NULL) { return (SUNFALSE); } - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { ca_mem->ca_yStmp = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (ca_mem->ca_yStmp == NULL) { + if (ca_mem->ca_yStmp == NULL) + { N_VDestroy(ca_mem->ca_ytmp); - return(SUNFALSE); + return (SUNFALSE); } } @@ -2369,86 +2697,96 @@ static booleantype CVAhermiteMalloc(CVodeMem cv_mem) dt_mem = ca_mem->dt_mem; - for (i=0; i<=ca_mem->ca_nsteps; i++) { - + for (i = 0; i <= ca_mem->ca_nsteps; i++) + { content = NULL; - content = (HermiteDataMem) malloc(sizeof(struct HermiteDataMemRec)); - if (content == NULL) { - ii = i; + content = (CVhermiteDataMem)malloc(sizeof(struct CVhermiteDataMemRec)); + if (content == NULL) + { + ii = i; allocOK = SUNFALSE; break; } content->y = N_VClone(cv_mem->cv_tempv); - if (content->y == NULL) { - free(content); content = NULL; - ii = i; + if (content->y == NULL) + { + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } content->yd = N_VClone(cv_mem->cv_tempv); - if (content->yd == NULL) { + if (content->yd == NULL) + { N_VDestroy(content->y); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - if (ca_mem->ca_IMstoreSensi) { - + if (ca_mem->ca_IMstoreSensi) + { content->yS = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (content->yS == NULL) { + if (content->yS == NULL) + { N_VDestroy(content->y); N_VDestroy(content->yd); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } content->ySd = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (content->ySd == NULL) { + if (content->ySd == NULL) + { N_VDestroy(content->y); N_VDestroy(content->yd); N_VDestroyVectorArray(content->yS, cv_mem->cv_Ns); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - } dt_mem[i]->content = content; - } /* If an error occurred, deallocate and return */ - if (!allocOK) { - + if (!allocOK) + { N_VDestroy(ca_mem->ca_ytmp); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(ca_mem->ca_yStmp, cv_mem->cv_Ns); } - for (i=0; icontent); + for (i = 0; i < ii; i++) + { + content = (CVhermiteDataMem)(dt_mem[i]->content); N_VDestroy(content->y); N_VDestroy(content->yd); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(content->yS, cv_mem->cv_Ns); N_VDestroyVectorArray(content->ySd, cv_mem->cv_Ns); } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } - } - return(allocOK); + return (allocOK); } /* @@ -2460,29 +2798,33 @@ static booleantype CVAhermiteMalloc(CVodeMem cv_mem) static void CVAhermiteFree(CVodeMem cv_mem) { CVadjMem ca_mem; - DtpntMem *dt_mem; - HermiteDataMem content; + CVdtpntMem* dt_mem; + CVhermiteDataMem content; long int i; ca_mem = cv_mem->cv_adj_mem; N_VDestroy(ca_mem->ca_ytmp); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(ca_mem->ca_yStmp, cv_mem->cv_Ns); } dt_mem = ca_mem->dt_mem; - for (i=0; i<=ca_mem->ca_nsteps; i++) { - content = (HermiteDataMem) (dt_mem[i]->content); + for (i = 0; i <= ca_mem->ca_nsteps; i++) + { + content = (CVhermiteDataMem)(dt_mem[i]->content); N_VDestroy(content->y); N_VDestroy(content->yd); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(content->yS, cv_mem->cv_Ns); N_VDestroyVectorArray(content->ySd, cv_mem->cv_Ns); } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } } @@ -2494,57 +2836,61 @@ static void CVAhermiteFree(CVodeMem cv_mem) * Note that the time is already stored. */ -static int CVAhermiteStorePnt(CVodeMem cv_mem, DtpntMem d) +static int CVAhermiteStorePnt(CVodeMem cv_mem, CVdtpntMem d) { CVadjMem ca_mem; - HermiteDataMem content; + CVhermiteDataMem content; int is, retval; ca_mem = cv_mem->cv_adj_mem; - content = (HermiteDataMem) d->content; + content = (CVhermiteDataMem)d->content; /* Load solution */ N_VScale(ONE, cv_mem->cv_zn[0], content->y); - if (ca_mem->ca_IMstoreSensi) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (ca_mem->ca_IMstoreSensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znS[0], content->yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } /* Load derivative */ - if (cv_mem->cv_nst == 0) { + if (cv_mem->cv_nst == 0) + { + /* retval = */ cv_mem->cv_f(cv_mem->cv_tn, content->y, content->yd, + cv_mem->cv_user_data); - /* retval = */ cv_mem->cv_f(cv_mem->cv_tn, content->y, content->yd, cv_mem->cv_user_data); - - if (ca_mem->ca_IMstoreSensi) { - /* retval = */ cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, content->y, content->yd, - content->yS, content->ySd, - cv_mem->cv_tempv, cv_mem->cv_ftemp); + if (ca_mem->ca_IMstoreSensi) + { + /* retval = */ cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, content->y, + content->yd, content->yS, content->ySd, + cv_mem->cv_tempv, cv_mem->cv_ftemp); } - - } else { - - N_VScale(ONE/cv_mem->cv_h, cv_mem->cv_zn[1], content->yd); - - if (ca_mem->ca_IMstoreSensi) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE/cv_mem->cv_h; + } + else + { + N_VScale(ONE / cv_mem->cv_h, cv_mem->cv_zn[1], content->yd); + + if (ca_mem->ca_IMstoreSensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[is] = ONE / cv_mem->cv_h; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znS[1], content->ySd); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - } - return(0); + return (0); } /* @@ -2557,27 +2903,26 @@ static int CVAhermiteStorePnt(CVodeMem cv_mem, DtpntMem d) * can be directly called by the user through CVodeGetAdjY */ -static int CVAhermiteGetY(CVodeMem cv_mem, realtype t, - N_Vector y, N_Vector *yS) +static int CVAhermiteGetY(CVodeMem cv_mem, sunrealtype t, N_Vector y, N_Vector* yS) { CVadjMem ca_mem; - DtpntMem *dt_mem; - HermiteDataMem content0, content1; + CVdtpntMem* dt_mem; + CVhermiteDataMem content0, content1; - realtype t0, t1, delta; - realtype factor1, factor2, factor3; + sunrealtype t0, t1, delta; + sunrealtype factor1, factor2, factor3; N_Vector y0, yd0, y1, yd1; - N_Vector *yS0=NULL, *ySd0=NULL, *yS1, *ySd1; + N_Vector *yS0 = NULL, *ySd0 = NULL, *yS1, *ySd1; int flag, is, NS; long int indx; - booleantype newpoint; + sunbooleantype newpoint; /* local variables for fused vector oerations */ int retval; - realtype cvals[4]; - N_Vector Xvecs[4]; + sunrealtype cvals[4]; + N_Vector Xvecs[4]; N_Vector* XXvecs[4]; ca_mem = cv_mem->cv_adj_mem; @@ -2590,103 +2935,118 @@ static int CVAhermiteGetY(CVodeMem cv_mem, realtype t, /* Get the index in dt_mem */ flag = CVAfindIndex(cv_mem, t, &indx, &newpoint); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } /* If we are beyond the left limit but close enough, then return y at the left limit. */ - if (indx == 0) { - content0 = (HermiteDataMem) (dt_mem[0]->content); + if (indx == 0) + { + content0 = (CVhermiteDataMem)(dt_mem[0]->content); N_VScale(ONE, content0->y, y); - if (NS > 0) { - for (is=0; iscv_cvals[is] = ONE; + if (NS > 0) + { + for (is = 0; is < NS; is++) { cv_mem->cv_cvals[is] = ONE; } - retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, - content0->yS, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, content0->yS, yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* Extract stuff from the appropriate data points */ - t0 = dt_mem[indx-1]->t; - t1 = dt_mem[indx]->t; + t0 = dt_mem[indx - 1]->t; + t1 = dt_mem[indx]->t; delta = t1 - t0; - content0 = (HermiteDataMem) (dt_mem[indx-1]->content); - y0 = content0->y; - yd0 = content0->yd; - if (ca_mem->ca_IMinterpSensi) { + content0 = (CVhermiteDataMem)(dt_mem[indx - 1]->content); + y0 = content0->y; + yd0 = content0->yd; + if (ca_mem->ca_IMinterpSensi) + { yS0 = content0->yS; ySd0 = content0->ySd; } - if (newpoint) { - + if (newpoint) + { /* Recompute Y0 and Y1 */ - content1 = (HermiteDataMem) (dt_mem[indx]->content); + content1 = (CVhermiteDataMem)(dt_mem[indx]->content); y1 = content1->y; yd1 = content1->yd; /* Y1 = delta (yd1 + yd0) - 2 (y1 - y0) */ - cvals[0] = -TWO; Xvecs[0] = y1; - cvals[1] = TWO; Xvecs[1] = y0; - cvals[2] = delta; Xvecs[2] = yd1; - cvals[3] = delta; Xvecs[3] = yd0; + cvals[0] = -TWO; + Xvecs[0] = y1; + cvals[1] = TWO; + Xvecs[1] = y0; + cvals[2] = delta; + Xvecs[2] = yd1; + cvals[3] = delta; + Xvecs[3] = yd0; retval = N_VLinearCombination(4, cvals, Xvecs, ca_mem->ca_Y[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Y0 = y1 - y0 - delta * yd0 */ - cvals[0] = ONE; Xvecs[0] = y1; - cvals[1] = -ONE; Xvecs[1] = y0; - cvals[2] = -delta; Xvecs[2] = yd0; + cvals[0] = ONE; + Xvecs[0] = y1; + cvals[1] = -ONE; + Xvecs[1] = y0; + cvals[2] = -delta; + Xvecs[2] = yd0; retval = N_VLinearCombination(3, cvals, Xvecs, ca_mem->ca_Y[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Recompute YS0 and YS1, if needed */ - if (NS > 0) { - + if (NS > 0) + { yS1 = content1->yS; ySd1 = content1->ySd; /* YS1 = delta (ySd1 + ySd0) - 2 (yS1 - yS0) */ - cvals[0] = -TWO; XXvecs[0] = yS1; - cvals[1] = TWO; XXvecs[1] = yS0; - cvals[2] = delta; XXvecs[2] = ySd1; - cvals[3] = delta; XXvecs[3] = ySd0; - - retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, ca_mem->ca_YS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + cvals[0] = -TWO; + XXvecs[0] = yS1; + cvals[1] = TWO; + XXvecs[1] = yS0; + cvals[2] = delta; + XXvecs[2] = ySd1; + cvals[3] = delta; + XXvecs[3] = ySd0; + + retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, + ca_mem->ca_YS[1]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* YS0 = yS1 - yS0 - delta * ySd0 */ - cvals[0] = ONE; XXvecs[0] = yS1; - cvals[1] = -ONE; XXvecs[1] = yS0; - cvals[2] = -delta; XXvecs[2] = ySd0; - - retval = N_VLinearCombinationVectorArray(NS, 3, cvals, XXvecs, ca_mem->ca_YS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + cvals[0] = ONE; + XXvecs[0] = yS1; + cvals[1] = -ONE; + XXvecs[1] = yS0; + cvals[2] = -delta; + XXvecs[2] = ySd0; + retval = N_VLinearCombinationVectorArray(NS, 3, cvals, XXvecs, + ca_mem->ca_YS[0]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - } /* Perform the actual interpolation. */ factor1 = t - t0; - factor2 = factor1/delta; - factor2 = factor2*factor2; + factor2 = factor1 / delta; + factor2 = factor2 * factor2; - factor3 = factor2*(t-t1)/delta; + factor3 = factor2 * (t - t1) / delta; cvals[0] = ONE; cvals[1] = factor1; @@ -2700,22 +3060,21 @@ static int CVAhermiteGetY(CVodeMem cv_mem, realtype t, Xvecs[3] = ca_mem->ca_Y[1]; retval = N_VLinearCombination(4, cvals, Xvecs, y); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* yS = yS0 + factor1 ySd0 + factor2 * YS[0] + factor3 YS[1], if needed */ - if (NS > 0) { - + if (NS > 0) + { XXvecs[0] = yS0; XXvecs[1] = ySd0; XXvecs[2] = ca_mem->ca_YS[0]; XXvecs[3] = ca_mem->ca_YS[1]; retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); - + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -2733,13 +3092,13 @@ static int CVAhermiteGetY(CVodeMem cv_mem, realtype t, * at any other time. */ -static booleantype CVApolynomialMalloc(CVodeMem cv_mem) +static sunbooleantype CVApolynomialMalloc(CVodeMem cv_mem) { CVadjMem ca_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; - long int i, ii=0; - booleantype allocOK; + CVdtpntMem* dt_mem; + CVpolynomialDataMem content; + long int i, ii = 0; + sunbooleantype allocOK; allocOK = SUNTRUE; @@ -2748,15 +3107,15 @@ static booleantype CVApolynomialMalloc(CVodeMem cv_mem) /* Allocate space for the vectors ytmp and yStmp */ ca_mem->ca_ytmp = N_VClone(cv_mem->cv_tempv); - if (ca_mem->ca_ytmp == NULL) { - return(SUNFALSE); - } + if (ca_mem->ca_ytmp == NULL) { return (SUNFALSE); } - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { ca_mem->ca_yStmp = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (ca_mem->ca_yStmp == NULL) { + if (ca_mem->ca_yStmp == NULL) + { N_VDestroy(ca_mem->ca_ytmp); - return(SUNFALSE); + return (SUNFALSE); } } @@ -2764,64 +3123,69 @@ static booleantype CVApolynomialMalloc(CVodeMem cv_mem) dt_mem = ca_mem->dt_mem; - for (i=0; i<=ca_mem->ca_nsteps; i++) { - + for (i = 0; i <= ca_mem->ca_nsteps; i++) + { content = NULL; - content = (PolynomialDataMem) malloc(sizeof(struct PolynomialDataMemRec)); - if (content == NULL) { - ii = i; + content = (CVpolynomialDataMem)malloc(sizeof(struct CVpolynomialDataMemRec)); + if (content == NULL) + { + ii = i; allocOK = SUNFALSE; break; } content->y = N_VClone(cv_mem->cv_tempv); - if (content->y == NULL) { - free(content); content = NULL; - ii = i; + if (content->y == NULL) + { + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - if (ca_mem->ca_IMstoreSensi) { - + if (ca_mem->ca_IMstoreSensi) + { content->yS = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - if (content->yS == NULL) { + if (content->yS == NULL) + { N_VDestroy(content->y); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - } dt_mem[i]->content = content; - } /* If an error occurred, deallocate and return */ - if (!allocOK) { - + if (!allocOK) + { N_VDestroy(ca_mem->ca_ytmp); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(ca_mem->ca_yStmp, cv_mem->cv_Ns); } - for (i=0; icontent); + for (i = 0; i < ii; i++) + { + content = (CVpolynomialDataMem)(dt_mem[i]->content); N_VDestroy(content->y); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(content->yS, cv_mem->cv_Ns); } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } - } - return(allocOK); - + return (allocOK); } /* @@ -2833,27 +3197,31 @@ static booleantype CVApolynomialMalloc(CVodeMem cv_mem) static void CVApolynomialFree(CVodeMem cv_mem) { CVadjMem ca_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + CVdtpntMem* dt_mem; + CVpolynomialDataMem content; long int i; ca_mem = cv_mem->cv_adj_mem; N_VDestroy(ca_mem->ca_ytmp); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(ca_mem->ca_yStmp, cv_mem->cv_Ns); } dt_mem = ca_mem->dt_mem; - for (i=0; i<=ca_mem->ca_nsteps; i++) { - content = (PolynomialDataMem) (dt_mem[i]->content); + for (i = 0; i <= ca_mem->ca_nsteps; i++) + { + content = (CVpolynomialDataMem)(dt_mem[i]->content); N_VDestroy(content->y); - if (ca_mem->ca_IMstoreSensi) { + if (ca_mem->ca_IMstoreSensi) + { N_VDestroyVectorArray(content->yS, cv_mem->cv_Ns); } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } } @@ -2865,29 +3233,29 @@ static void CVApolynomialFree(CVodeMem cv_mem) * Note that the time is already stored. */ -static int CVApolynomialStorePnt(CVodeMem cv_mem, DtpntMem d) +static int CVApolynomialStorePnt(CVodeMem cv_mem, CVdtpntMem d) { CVadjMem ca_mem; - PolynomialDataMem content; + CVpolynomialDataMem content; int is, retval; ca_mem = cv_mem->cv_adj_mem; - content = (PolynomialDataMem) d->content; + content = (CVpolynomialDataMem)d->content; N_VScale(ONE, cv_mem->cv_zn[0], content->y); - if (ca_mem->ca_IMstoreSensi) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (ca_mem->ca_IMstoreSensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znS[0], content->yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } content->order = cv_mem->cv_qu; - return(0); + return (0); } /* @@ -2899,17 +3267,17 @@ static int CVApolynomialStorePnt(CVodeMem cv_mem, DtpntMem d) * can be directly called by the user through CVodeGetAdjY. */ -static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, - N_Vector y, N_Vector *yS) +static int CVApolynomialGetY(CVodeMem cv_mem, sunrealtype t, N_Vector y, + N_Vector* yS) { CVadjMem ca_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + CVdtpntMem* dt_mem; + CVpolynomialDataMem content; int flag, dir, order, i, j, is, NS, retval; long int indx, base; - booleantype newpoint; - realtype dt, factor; + sunbooleantype newpoint; + sunrealtype dt, factor; ca_mem = cv_mem->cv_adj_mem; dt_mem = ca_mem->dt_mem; @@ -2921,28 +3289,29 @@ static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, /* Get the index in dt_mem */ flag = CVAfindIndex(cv_mem, t, &indx, &newpoint); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { return (flag); } /* If we are beyond the left limit but close enough, then return y at the left limit. */ - if (indx == 0) { - content = (PolynomialDataMem) (dt_mem[0]->content); + if (indx == 0) + { + content = (CVpolynomialDataMem)(dt_mem[0]->content); N_VScale(ONE, content->y, y); - if (NS > 0) { - for (is=0; iscv_cvals[is] = ONE; + if (NS > 0) + { + for (is = 0; is < NS; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, content->yS, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* Scaling factor */ - dt = SUNRabs(dt_mem[indx]->t - dt_mem[indx-1]->t); + dt = SUNRabs(dt_mem[indx]->t - dt_mem[indx - 1]->t); /* Find the direction of the forward integration */ @@ -2951,64 +3320,75 @@ static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, /* Establish the base point depending on the integration direction. Modify the base if there are not enough points for the current order */ - if (dir == 1) { - base = indx; - content = (PolynomialDataMem) (dt_mem[base]->content); - order = content->order; - if(indx < order) base += order-indx; - } else { - base = indx-1; - content = (PolynomialDataMem) (dt_mem[base]->content); - order = content->order; - if (ca_mem->ca_np-indx > order) base -= indx+order-ca_mem->ca_np; + if (dir == 1) + { + base = indx; + content = (CVpolynomialDataMem)(dt_mem[base]->content); + order = content->order; + if (indx < order) { base += order - indx; } + } + else + { + base = indx - 1; + content = (CVpolynomialDataMem)(dt_mem[base]->content); + order = content->order; + if (ca_mem->ca_np - indx > order) { base -= indx + order - ca_mem->ca_np; } } /* Recompute Y (divided differences for Newton polynomial) if needed */ - if (newpoint) { - + if (newpoint) + { /* Store 0-th order DD */ - if (dir == 1) { - for(j=0;j<=order;j++) { - ca_mem->ca_T[j] = dt_mem[base-j]->t; - content = (PolynomialDataMem) (dt_mem[base-j]->content); + if (dir == 1) + { + for (j = 0; j <= order; j++) + { + ca_mem->ca_T[j] = dt_mem[base - j]->t; + content = (CVpolynomialDataMem)(dt_mem[base - j]->content); N_VScale(ONE, content->y, ca_mem->ca_Y[j]); - if (NS > 0) { - for (is=0; iscv_cvals[is] = ONE; - retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, - content->yS, ca_mem->ca_YS[j]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (NS > 0) + { + for (is = 0; is < NS; is++) { cv_mem->cv_cvals[is] = ONE; } + retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, content->yS, + ca_mem->ca_YS[j]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } } - } else { - for(j=0;j<=order;j++) { - ca_mem->ca_T[j] = dt_mem[base-1+j]->t; - content = (PolynomialDataMem) (dt_mem[base-1+j]->content); + } + else + { + for (j = 0; j <= order; j++) + { + ca_mem->ca_T[j] = dt_mem[base - 1 + j]->t; + content = (CVpolynomialDataMem)(dt_mem[base - 1 + j]->content); N_VScale(ONE, content->y, ca_mem->ca_Y[j]); - if (NS > 0) { - for (is=0; iscv_cvals[is] = ONE; - retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, - content->yS, ca_mem->ca_YS[j]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (NS > 0) + { + for (is = 0; is < NS; is++) { cv_mem->cv_cvals[is] = ONE; } + retval = N_VScaleVectorArray(NS, cv_mem->cv_cvals, content->yS, + ca_mem->ca_YS[j]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } } } /* Compute higher-order DD */ - for(i=1;i<=order;i++) { - for(j=order;j>=i;j--) { - factor = dt/(ca_mem->ca_T[j]-ca_mem->ca_T[j-i]); - N_VLinearSum(factor, ca_mem->ca_Y[j], -factor, ca_mem->ca_Y[j-1], ca_mem->ca_Y[j]); - - if (NS > 0) { - retval = N_VLinearSumVectorArray(NS, - factor, ca_mem->ca_YS[j], - -factor, ca_mem->ca_YS[j-1], + for (i = 1; i <= order; i++) + { + for (j = order; j >= i; j--) + { + factor = dt / (ca_mem->ca_T[j] - ca_mem->ca_T[j - i]); + N_VLinearSum(factor, ca_mem->ca_Y[j], -factor, ca_mem->ca_Y[j - 1], + ca_mem->ca_Y[j]); + + if (NS > 0) + { + retval = N_VLinearSumVectorArray(NS, factor, ca_mem->ca_YS[j], + -factor, ca_mem->ca_YS[j - 1], ca_mem->ca_YS[j]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } } } @@ -3017,19 +3397,22 @@ static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, /* Perform the actual interpolation using nested multiplications */ cv_mem->cv_cvals[0] = ONE; - for (i=0; icv_cvals[i+1] = cv_mem->cv_cvals[i] * (t-ca_mem->ca_T[i]) / dt; + for (i = 0; i < order; i++) + { + cv_mem->cv_cvals[i + 1] = cv_mem->cv_cvals[i] * (t - ca_mem->ca_T[i]) / dt; + } - retval = N_VLinearCombination(order+1, cv_mem->cv_cvals, ca_mem->ca_Y, y); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VLinearCombination(order + 1, cv_mem->cv_cvals, ca_mem->ca_Y, y); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - if (NS > 0) { - retval = N_VLinearCombinationVectorArray(NS, order+1, cv_mem->cv_cvals, ca_mem->ca_YS, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (NS > 0) + { + retval = N_VLinearCombinationVectorArray(NS, order + 1, cv_mem->cv_cvals, + ca_mem->ca_YS, yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(CV_SUCCESS); - + return (CV_SUCCESS); } /* @@ -3044,15 +3427,14 @@ static int CVApolynomialGetY(CVodeMem cv_mem, realtype t, * provided by the user. */ -static int CVArhs(realtype t, N_Vector yB, - N_Vector yBdot, void *cvode_mem) +static int CVArhs(sunrealtype t, N_Vector yB, N_Vector yBdot, void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; int flag, retval; - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; ca_mem = cv_mem->cv_adj_mem; @@ -3061,23 +3443,32 @@ static int CVArhs(realtype t, N_Vector yB, /* Get forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); + } + else { flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } - if (flag != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVODEA", "CVArhs", MSGCV_BAD_TINTERP, t); - return(-1); + if (flag != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGCV_BAD_TINTERP, + t); + return (-1); } /* Call the user's RHS function */ if (cvB_mem->cv_f_withSensi) - retval = (cvB_mem->cv_fs)(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, yBdot, cvB_mem->cv_user_data); + { + retval = (cvB_mem->cv_fs)(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, yBdot, + cvB_mem->cv_user_data); + } else - retval = (cvB_mem->cv_f)(t, ca_mem->ca_ytmp, yB, yBdot, cvB_mem->cv_user_data); + { + retval = (cvB_mem->cv_f)(t, ca_mem->ca_ytmp, yB, yBdot, + cvB_mem->cv_user_data); + } - return(retval); + return (retval); } /* @@ -3087,8 +3478,7 @@ static int CVArhs(realtype t, N_Vector yB, * provided by the user. */ -static int CVArhsQ(realtype t, N_Vector yB, - N_Vector qBdot, void *cvode_mem) +static int CVArhsQ(sunrealtype t, N_Vector yB, N_Vector qBdot, void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; @@ -3096,7 +3486,7 @@ static int CVArhsQ(realtype t, N_Vector yB, /* int flag; */ int retval; - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; ca_mem = cv_mem->cv_adj_mem; @@ -3105,16 +3495,26 @@ static int CVArhsQ(realtype t, N_Vector yB, /* Get forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { /* flag = */ ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); + } else - /* flag = */ ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); + { /* flag = */ + ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); + } /* Call the user's RHS function */ if (cvB_mem->cv_fQ_withSensi) - retval = (cvB_mem->cv_fQs)(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, qBdot, cvB_mem->cv_user_data); + { + retval = (cvB_mem->cv_fQs)(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, qBdot, + cvB_mem->cv_user_data); + } else - retval = (cvB_mem->cv_fQ)(t, ca_mem->ca_ytmp, yB, qBdot, cvB_mem->cv_user_data); + { + retval = (cvB_mem->cv_fQ)(t, ca_mem->ca_ytmp, yB, qBdot, + cvB_mem->cv_user_data); + } - return(retval); + return (retval); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea_io.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea_io.c index 69b364244..a442fff39 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea_io.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodea_io.c @@ -6,7 +6,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,7 +20,7 @@ * ----------------------------------------------------------------- */ -/* +/* * ================================================================= * IMPORTED HEADER FILES * ================================================================= @@ -28,484 +28,531 @@ #include #include +#include #include "cvodes_impl.h" -#include -/* +/* * ================================================================= * CVODEA PRIVATE CONSTANTS * ================================================================= */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) -/* +/* * ================================================================= * EXPORTED FUNCTIONS IMPLEMENTATION * ================================================================= */ -/* +/* * ----------------------------------------------------------------- * Optional input functions for ASA * ----------------------------------------------------------------- */ -int CVodeSetAdjNoSensi(void *cvode_mem) +int CVodeSetAdjNoSensi(void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetAdjNoSensi", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetAdjNoSensi", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; ca_mem->ca_IMstoreSensi = SUNFALSE; - return(CV_SUCCESS); + return (CV_SUCCESS); } -/* +/* * ----------------------------------------------------------------- * Optional input functions for backward integration * ----------------------------------------------------------------- */ -int CVodeSetNonlinearSolverB(void *cvode_mem, int which, SUNNonlinearSolver NLS) +int CVodeSetNonlinearSolverB(void* cvode_mem, int which, SUNNonlinearSolver NLS) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", - "CVodeSetNonlinearSolverB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", - "CVodeSetNonlinearSolverB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", - "CVodeSetNonlinearSolverB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); - return(CVodeSetNonlinearSolver(cvodeB_mem, NLS)); + return (CVodeSetNonlinearSolver(cvodeB_mem, NLS)); } -int CVodeSetUserDataB(void *cvode_mem, int which, void *user_dataB) +int CVodeSetUserDataB(void* cvode_mem, int which, void* user_dataB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetUserDataB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetUserDataB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetUserDataB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } cvB_mem->cv_user_data = user_dataB; - return(CV_SUCCESS); + return (CV_SUCCESS); } -int CVodeSetMaxOrdB(void *cvode_mem, int which, int maxordB) +int CVodeSetMaxOrdB(void* cvode_mem, int which, int maxordB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; - /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetMaxOrdB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetMaxOrdB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetMaxOrdB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetMaxOrd(cvodeB_mem, maxordB); - return(flag); + return (flag); } - -int CVodeSetMaxNumStepsB(void *cvode_mem, int which, long int mxstepsB) +int CVodeSetMaxNumStepsB(void* cvode_mem, int which, long int mxstepsB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetMaxNumStepsB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetMaxNumStepsB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetMaxNumStepsB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetMaxNumSteps(cvodeB_mem, mxstepsB); - return(flag); + return (flag); } -int CVodeSetStabLimDetB(void *cvode_mem, int which, booleantype stldetB) +int CVodeSetStabLimDetB(void* cvode_mem, int which, sunbooleantype stldetB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetStabLimDetB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetStabLimDetB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetStabLimDetB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetStabLimDet(cvodeB_mem, stldetB); - return(flag); + return (flag); } -int CVodeSetInitStepB(void *cvode_mem, int which, realtype hinB) +int CVodeSetInitStepB(void* cvode_mem, int which, sunrealtype hinB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetInitStepB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetInitStepB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetInitStepB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetInitStep(cvodeB_mem, hinB); - return(flag); + return (flag); } -int CVodeSetMinStepB(void *cvode_mem, int which, realtype hminB) +int CVodeSetMinStepB(void* cvode_mem, int which, sunrealtype hminB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetMinStepB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetMinStepB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetMinStepB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetMinStep(cvodeB_mem, hminB); - return(flag); + return (flag); } -int CVodeSetMaxStepB(void *cvode_mem, int which, realtype hmaxB) +int CVodeSetMaxStepB(void* cvode_mem, int which, sunrealtype hmaxB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetMaxStepB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetMaxStepB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetMaxStepB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetMaxStep(cvodeB_mem, hmaxB); - return(flag); + return (flag); } -int CVodeSetConstraintsB(void *cvode_mem, int which, N_Vector constraintsB) +int CVodeSetConstraintsB(void* cvode_mem, int which, N_Vector constraintsB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Is cvode_mem valid? */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetConstraintsB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Is ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetConstraintsB", MSGCV_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check the value of which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetConstraintsB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to 'which'. */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } /* advance */ cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) cvB_mem->cv_mem; + cvodeB_mem = (void*)cvB_mem->cv_mem; flag = CVodeSetConstraints(cvodeB_mem, constraintsB); - return(flag); + return (flag); } /* * CVodeSetQuad*B * - * Wrappers for the backward phase around the corresponding + * Wrappers for the backward phase around the corresponding * CVODES quadrature optional input functions */ -int CVodeSetQuadErrConB(void *cvode_mem, int which, booleantype errconQB) +int CVodeSetQuadErrConB(void* cvode_mem, int which, sunbooleantype errconQB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeSetQuadErrConB", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeSetQuadErrConB", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeSetQuadErrConB", MSGCV_BAD_WHICH); - return(CV_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_WHICH); + return (CV_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); flag = CVodeSetQuadErrCon(cvodeB_mem, errconQB); - return(flag); + return (flag); } -/* +/* * ----------------------------------------------------------------- * Optional output functions for backward integration * ----------------------------------------------------------------- @@ -514,49 +561,53 @@ int CVodeSetQuadErrConB(void *cvode_mem, int which, booleantype errconQB) /* * CVodeGetAdjCVodeBmem * - * This function returns a (void *) pointer to the CVODES - * memory allocated for the backward problem. This pointer can - * then be used to call any of the CVodeGet* CVODES routines to + * This function returns a (void *) pointer to the CVODES + * memory allocated for the backward problem. This pointer can + * then be used to call any of the CVodeGet* CVODES routines to * extract optional output for the backward integration phase. */ -void *CVodeGetAdjCVodeBmem(void *cvode_mem, int which) +void* CVodeGetAdjCVodeBmem(void* cvode_mem, int which) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, 0, "CVODEA", "CVodeGetAdjCVodeBmem", MSGCV_NO_MEM); - return(NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, 0, "CVODEA", "CVodeGetAdjCVodeBmem", MSGCV_NO_ADJ); - return(NULL); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, 0, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (NULL); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, 0, "CVODEA", "CVodeGetAdjCVodeBmem", MSGCV_BAD_WHICH); - return(NULL); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, 0, __LINE__, __func__, __FILE__, MSGCV_BAD_WHICH); + return (NULL); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); - return(cvodeB_mem); + return (cvodeB_mem); } /* @@ -566,58 +617,56 @@ void *CVodeGetAdjCVodeBmem(void *cvode_mem, int which) * The user must allocate space for ckpnt. */ -int CVodeGetAdjCheckPointsInfo(void *cvode_mem, CVadjCheckPointRec *ckpnt) +int CVodeGetAdjCheckPointsInfo(void* cvode_mem, CVadjCheckPointRec* ckpnt) { CVodeMem cv_mem; CVadjMem ca_mem; - CkpntMem ck_mem; + CVckpntMem ck_mem; int i; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetAdjCheckPointsInfo", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetAdjCheckPointsInfo", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; ck_mem = ca_mem->ck_mem; i = 0; - while (ck_mem != NULL) { - - ckpnt[i].my_addr = (void *) ck_mem; - ckpnt[i].next_addr = (void *) ck_mem->ck_next; - ckpnt[i].t0 = ck_mem->ck_t0; - ckpnt[i].t1 = ck_mem->ck_t1; - ckpnt[i].nstep = ck_mem->ck_nst; - ckpnt[i].order = ck_mem->ck_q; - ckpnt[i].step = ck_mem->ck_h; + while (ck_mem != NULL) + { + ckpnt[i].my_addr = (void*)ck_mem; + ckpnt[i].next_addr = (void*)ck_mem->ck_next; + ckpnt[i].t0 = ck_mem->ck_t0; + ckpnt[i].t1 = ck_mem->ck_t1; + ckpnt[i].nstep = ck_mem->ck_nst; + ckpnt[i].order = ck_mem->ck_q; + ckpnt[i].step = ck_mem->ck_h; ck_mem = ck_mem->ck_next; i++; - } - return(CV_SUCCESS); - + return (CV_SUCCESS); } - -/* +/* * ----------------------------------------------------------------- * Undocumented Development User-Callable Functions * ----------------------------------------------------------------- */ - /* * CVodeGetAdjDataPointHermite * @@ -625,46 +674,48 @@ int CVodeGetAdjCheckPointsInfo(void *cvode_mem, CVadjCheckPointRec *ckpnt) * at the 'which' data point. Cubic Hermite interpolation. */ -int CVodeGetAdjDataPointHermite(void *cvode_mem, int which, - realtype *t, N_Vector y, N_Vector yd) +int CVodeGetAdjDataPointHermite(void* cvode_mem, int which, sunrealtype* t, + N_Vector y, N_Vector yd) { CVodeMem cv_mem; CVadjMem ca_mem; - DtpntMem *dt_mem; - HermiteDataMem content; + CVdtpntMem* dt_mem; + CVhermiteDataMem content; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetAdjDataPointHermite", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetAdjDataPointHermite", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; dt_mem = ca_mem->dt_mem; - if (ca_mem->ca_IMtype != CV_HERMITE) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVadjGetDataPointHermite", MSGCV_WRONG_INTERP); - return(CV_ILL_INPUT); + if (ca_mem->ca_IMtype != CV_HERMITE) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_WRONG_INTERP); + return (CV_ILL_INPUT); } *t = dt_mem[which]->t; - content = (HermiteDataMem) (dt_mem[which]->content); + content = (CVhermiteDataMem)(dt_mem[which]->content); - if (y != NULL) - N_VScale(ONE, content->y, y); + if (y != NULL) { N_VScale(ONE, content->y, y); } - if (yd != NULL) - N_VScale(ONE, content->yd, yd); + if (yd != NULL) { N_VScale(ONE, content->yd, yd); } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -674,74 +725,78 @@ int CVodeGetAdjDataPointHermite(void *cvode_mem, int which, * at the 'which' data point. Polynomial interpolation. */ -int CVodeGetAdjDataPointPolynomial(void *cvode_mem, int which, - realtype *t, int *order, N_Vector y) +int CVodeGetAdjDataPointPolynomial(void* cvode_mem, int which, sunrealtype* t, + int* order, N_Vector y) { CVodeMem cv_mem; CVadjMem ca_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + CVdtpntMem* dt_mem; + CVpolynomialDataMem content; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetAdjDataPointPolynomial", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetAdjDataPointPolynomial", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; dt_mem = ca_mem->dt_mem; - if (ca_mem->ca_IMtype != CV_POLYNOMIAL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVadjGetDataPointPolynomial", MSGCV_WRONG_INTERP); - return(CV_ILL_INPUT); + if (ca_mem->ca_IMtype != CV_POLYNOMIAL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_WRONG_INTERP); + return (CV_ILL_INPUT); } *t = dt_mem[which]->t; - content = (PolynomialDataMem) (dt_mem[which]->content); + content = (CVpolynomialDataMem)(dt_mem[which]->content); - if (y != NULL) - N_VScale(ONE, content->y, y); + if (y != NULL) { N_VScale(ONE, content->y, y); } *order = content->order; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * CVodeGetAdjCurrentCheckPoint * * Returns the address of the 'active' check point. */ -int CVodeGetAdjCurrentCheckPoint(void *cvode_mem, void **addr) +int CVodeGetAdjCurrentCheckPoint(void* cvode_mem, void** addr) { CVodeMem cv_mem; CVadjMem ca_mem; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODEA", "CVodeGetAdjCurrentCheckPoint", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeGetAdjCurrentCheckPoint", MSGCV_NO_ADJ); - return(CV_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_ADJ, __LINE__, __func__, __FILE__, MSGCV_NO_ADJ); + return (CV_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; - *addr = (void *) ca_mem->ca_ckpntData; + *addr = (void*)ca_mem->ca_ckpntData; - return(CV_SUCCESS); + return (CV_SUCCESS); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes.c index a0d8a168e..228911bee 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes.c @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -185,93 +185,41 @@ /* Import Header Files */ /*=================================================================*/ +#include #include #include -#include #include - -#include "cvodes_impl.h" -#include #include #include +#include "cvodes_impl.h" +#include "sundials/priv/sundials_errors_impl.h" +#include "sundials/sundials_context.h" + /*=================================================================*/ /* CVODE Private Constants */ /*=================================================================*/ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define TINY RCONST(1.0e-10) /* small number */ -#define PT1 RCONST(0.1) /* real 0.1 */ -#define POINT2 RCONST(0.2) /* real 0.2 */ -#define FOURTH RCONST(0.25) /* real 0.25 */ -#define HALF RCONST(0.5) /* real 0.5 */ -#define PT9 RCONST(0.9) /* real 0.9 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define ONEPT5 RCONST(1.50) /* real 1.5 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define THREE RCONST(3.0) /* real 3.0 */ -#define FOUR RCONST(4.0) /* real 4.0 */ -#define FIVE RCONST(5.0) /* real 5.0 */ -#define TWELVE RCONST(12.0) /* real 12.0 */ -#define HUNDRED RCONST(100.0) /* real 100.0 */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define TINY SUN_RCONST(1.0e-10) /* small number */ +#define PT1 SUN_RCONST(0.1) /* real 0.1 */ +#define POINT2 SUN_RCONST(0.2) /* real 0.2 */ +#define FOURTH SUN_RCONST(0.25) /* real 0.25 */ +#define HALF SUN_RCONST(0.5) /* real 0.5 */ +#define PT9 SUN_RCONST(0.9) /* real 0.9 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define ONEPT5 SUN_RCONST(1.50) /* real 1.5 */ +#define TWO SUN_RCONST(2.0) /* real 2.0 */ +#define THREE SUN_RCONST(3.0) /* real 3.0 */ +#define FOUR SUN_RCONST(4.0) /* real 4.0 */ +#define FIVE SUN_RCONST(5.0) /* real 5.0 */ +#define TWELVE SUN_RCONST(12.0) /* real 12.0 */ +#define HUNDRED SUN_RCONST(100.0) /* real 100.0 */ /*=================================================================*/ /* CVODE Routine-Specific Constants */ /*=================================================================*/ -/* - * Control constants for lower-level functions used by cvStep - * ---------------------------------------------------------- - * - * cvHin return values: - * CV_SUCCESS, - * CV_RHSFUNC_FAIL, CV_RPTD_RHSFUNC_ERR, - * CV_QRHSFUNC_FAIL, CV_RPTD_QRHSFUNC_ERR, - * CV_SRHSFUNC_FAIL, CV_RPTD_SRHSFUNC_ERR, - * CV_TOO_CLOSE - * - * cvStep control constants: - * DO_ERROR_TEST - * PREDICT_AGAIN - * - * cvStep return values: - * CV_SUCCESS, - * CV_CONV_FAILURE, CV_ERR_FAILURE, - * CV_LSETUP_FAIL, CV_LSOLVE_FAIL, - * CV_RTFUNC_FAIL, - * CV_RHSFUNC_FAIL, CV_QRHSFUNC_FAIL, CV_SRHSFUNC_FAIL, CV_QSRHSFUNC_FAIL, - * CV_FIRST_RHSFUNC_ERR, CV_FIRST_QRHSFUNC_ERR, CV_FIRST_SRHSFUNC_ERR, CV_FIRST_QSRHSFUNC_ERR, - * CV_UNREC_RHSFUNC_ERR, CV_UNREC_QRHSFUNC_ERR, CV_UNREC_SRHSFUNC_ERR, CV_UNREC_QSRHSFUNC_ERR, - * CV_REPTD_RHSFUNC_ERR, CV_REPTD_QRHSFUNC_ERR, CV_REPTD_SRHSFUNC_ERR, CV_REPTD_QSRHSFUNC_ERR, - * - * cvNls input nflag values: - * FIRST_CALL - * PREV_CONV_FAIL - * PREV_ERR_FAIL - * - * cvNls return values: - * CV_SUCCESS, - * CV_LSETUP_FAIL, CV_LSOLVE_FAIL, - * CV_RHSFUNC_FAIL, CV_SRHSFUNC_FAIL, - * SUN_NLS_CONV_RECVR, - * RHSFUNC_RECVR, SRHSFUNC_RECVR - * - */ - -#define DO_ERROR_TEST +2 -#define PREDICT_AGAIN +3 - -#define CONV_FAIL +4 -#define TRY_AGAIN +5 -#define FIRST_CALL +6 -#define PREV_CONV_FAIL +7 -#define PREV_ERR_FAIL +8 - -#define CONSTR_RECVR +10 - -#define QRHSFUNC_RECVR +11 -#define QSRHSFUNC_RECVR +13 - /* * Control constants for lower-level rootfinding functions * ------------------------------------------------------- @@ -294,37 +242,37 @@ * RTFOUND */ -#define RTFOUND +1 -#define CLOSERT +3 +#define RTFOUND +1 +#define CLOSERT +3 /* * Control constants for sensitivity DQ * ------------------------------------ */ -#define CENTERED1 +1 -#define CENTERED2 +2 -#define FORWARD1 +3 -#define FORWARD2 +4 +#define CENTERED1 +1 +#define CENTERED2 +2 +#define FORWARD1 +3 +#define FORWARD2 +4 /* * Control constants for type of sensitivity RHS * --------------------------------------------- */ -#define CV_ONESENS 1 -#define CV_ALLSENS 2 +#define CV_ONESENS 1 +#define CV_ALLSENS 2 /* * Control constants for tolerances * -------------------------------- */ -#define CV_NN 0 -#define CV_SS 1 -#define CV_SV 2 -#define CV_WF 3 -#define CV_EE 4 +#define CV_NN 0 +#define CV_SS 1 +#define CV_SV 2 +#define CV_WF 3 +#define CV_EE 4 /* * Algorithmic constants @@ -345,74 +293,22 @@ * * CORTES constant in nonlinear iteration convergence test * - * cvStep - * - * THRESH if eta < THRESH reject a change in step size or order - * ETAMX1 -+ - * ETAMX2 | - * ETAMX3 |-> bounds for eta (step size change) - * ETAMXF | - * ETAMIN | - * ETACF -+ - * ADDON safety factor in computing eta - * BIAS1 -+ - * BIAS2 |-> bias factors in eta selection - * BIAS3 -+ - * ONEPSM (1+epsilon) used in testing if the step size is below its bound - * - * SMALL_NST nst > SMALL_NST => use ETAMX3 - * MXNCF max no. of convergence failures during one step try - * MXNEF max no. of error test failures during one step try - * MXNEF1 max no. of error test failures before forcing a reduction of order - * SMALL_NEF if an error failure occurs and SMALL_NEF <= nef <= MXNEF1, then - * reset eta = SUNMIN(eta, ETAMXF) - * LONG_WAIT number of steps to wait before considering an order change when - * q==1 and MXNEF1 error test failures have occurred - * - * cvNls - * - * DGMAX |gamma/gammap-1| > DGMAX => call lsetup - * */ +#define FUZZ_FACTOR SUN_RCONST(100.0) -#define FUZZ_FACTOR RCONST(100.0) - -#define HLB_FACTOR RCONST(100.0) -#define HUB_FACTOR RCONST(0.1) +#define HLB_FACTOR SUN_RCONST(100.0) +#define HUB_FACTOR SUN_RCONST(0.1) #define H_BIAS HALF #define MAX_ITERS 4 -#define CORTES RCONST(0.1) - -#define THRESH RCONST(1.5) -#define ETAMX1 RCONST(10000.0) -#define ETAMX2 RCONST(10.0) -#define ETAMX3 RCONST(10.0) -#define ETAMXF RCONST(0.2) -#define ETAMIN RCONST(0.1) -#define ETACF RCONST(0.25) -#define ADDON RCONST(0.000001) -#define BIAS1 RCONST(6.0) -#define BIAS2 RCONST(6.0) -#define BIAS3 RCONST(10.0) -#define ONEPSM RCONST(1.000001) - -#define SMALL_NST 10 -#define MXNCF 10 -#define MXNEF 7 -#define MXNEF1 3 -#define SMALL_NEF 2 -#define LONG_WAIT 10 - -#define DGMAX RCONST(0.3) - +#define CORTES SUN_RCONST(0.1) /*=================================================================*/ /* Private Helper Functions Prototypes */ /*=================================================================*/ -static booleantype cvCheckNvector(N_Vector tmpl); +static sunbooleantype cvCheckNvector(N_Vector tmpl); /* Initial setup */ @@ -420,19 +316,18 @@ static int cvInitialSetup(CVodeMem cv_mem); /* Memory allocation/deallocation */ -static booleantype cvAllocVectors(CVodeMem cv_mem, N_Vector tmpl); +static sunbooleantype cvAllocVectors(CVodeMem cv_mem, N_Vector tmpl); static void cvFreeVectors(CVodeMem cv_mem); -static booleantype cvQuadAllocVectors(CVodeMem cv_mem, N_Vector tmpl); +static sunbooleantype cvQuadAllocVectors(CVodeMem cv_mem, N_Vector tmpl); static void cvQuadFreeVectors(CVodeMem cv_mem); -static booleantype cvSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl); +static sunbooleantype cvSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl); static void cvSensFreeVectors(CVodeMem cv_mem); -static booleantype cvQuadSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl); +static sunbooleantype cvQuadSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl); static void cvQuadSensFreeVectors(CVodeMem cv_mem); - static int cvEwtSetSS(CVodeMem cv_mem, N_Vector ycur, N_Vector weight); static int cvEwtSetSV(CVodeMem cv_mem, N_Vector ycur, N_Vector weight); @@ -440,22 +335,25 @@ static int cvQuadEwtSet(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ); static int cvQuadEwtSetSS(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ); static int cvQuadEwtSetSV(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ); -static int cvSensEwtSet(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS); -static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS); -static int cvSensEwtSetSS(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS); -static int cvSensEwtSetSV(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS); - -static int cvQuadSensEwtSet(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS); -static int cvQuadSensEwtSetEE(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS); -static int cvQuadSensEwtSetSS(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS); -static int cvQuadSensEwtSetSV(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS); +static int cvSensEwtSet(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS); +static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS); +static int cvSensEwtSetSS(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS); +static int cvSensEwtSetSV(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS); +static int cvQuadSensEwtSet(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS); +static int cvQuadSensEwtSetEE(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS); +static int cvQuadSensEwtSetSS(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS); +static int cvQuadSensEwtSetSV(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS); /* Initial stepsize calculation */ -static int cvHin(CVodeMem cv_mem, realtype tout); -static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist); -static int cvYddNorm(CVodeMem cv_mem, realtype hg, realtype *yddnrm); +static int cvHin(CVodeMem cv_mem, sunrealtype tout); +static sunrealtype cvUpperBoundH0(CVodeMem cv_mem, sunrealtype tdist); +static int cvYddNorm(CVodeMem cv_mem, sunrealtype hg, sunrealtype* yddnrm); /* Main cvStep function */ @@ -469,16 +367,17 @@ static void cvAdjustAdams(CVodeMem cv_mem, int deltaq); static void cvAdjustBDF(CVodeMem cv_mem, int deltaq); static void cvIncreaseBDF(CVodeMem cv_mem); static void cvDecreaseBDF(CVodeMem cv_mem); -static void cvRescale(CVodeMem cv_mem); static void cvPredict(CVodeMem cv_mem); static void cvSet(CVodeMem cv_mem); static void cvSetAdams(CVodeMem cv_mem); -static realtype cvAdamsStart(CVodeMem cv_mem, realtype m[]); -static void cvAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype hsum); -static realtype cvAltSum(int iend, realtype a[], int k); +static sunrealtype cvAdamsStart(CVodeMem cv_mem, sunrealtype m[]); +static void cvAdamsFinish(CVodeMem cv_mem, sunrealtype m[], sunrealtype M[], + sunrealtype hsum); +static sunrealtype cvAltSum(int iend, sunrealtype a[], int k); static void cvSetBDF(CVodeMem cv_mem); -static void cvSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, - realtype alpha0_hat, realtype xi_inv, realtype xistar_inv); +static void cvSetTqBDF(CVodeMem cv_mem, sunrealtype hsum, sunrealtype alpha0, + sunrealtype alpha0_hat, sunrealtype xi_inv, + sunrealtype xistar_inv); /* Nonlinear solver functions */ @@ -490,29 +389,27 @@ static int cvQuadSensNls(CVodeMem cv_mem); static int cvCheckConstraints(CVodeMem cv_mem); -static int cvHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - int *ncfPtr, long int *ncfnPtr); - -static void cvRestore(CVodeMem cv_mem, realtype saved_t); +static int cvHandleNFlag(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + int* ncfPtr, long int* ncfnPtr); /* Error Test */ -static int cvDoErrorTest(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - realtype acor_nrm, - int *nefPtr, long int *netfPtr, realtype *dsmPtr); +static int cvDoErrorTest(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + sunrealtype acor_nrm, int* nefPtr, long int* netfPtr, + sunrealtype* dsmPtr); /* Function called after a successful step */ static void cvCompleteStep(CVodeMem cv_mem); -static void cvPrepareNextStep(CVodeMem cv_mem, realtype dsm); +static void cvPrepareNextStep(CVodeMem cv_mem, sunrealtype dsm); static void cvSetEta(CVodeMem cv_mem); -static realtype cvComputeEtaqm1(CVodeMem cv_mem); -static realtype cvComputeEtaqp1(CVodeMem cv_mem); +static sunrealtype cvComputeEtaqm1(CVodeMem cv_mem); +static sunrealtype cvComputeEtaqp1(CVodeMem cv_mem); static void cvChooseEta(CVodeMem cv_mem); /* Function to handle failures */ -static int cvHandleFailure(CVodeMem cv_mem,int flag); +static int cvHandleFailure(CVodeMem cv_mem, int flag); /* Functions for BDF Stability Limit Detection */ @@ -528,25 +425,22 @@ static int cvRootfind(CVodeMem cv_mem); /* Function for combined norms */ -static realtype cvQuadUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector xQ, N_Vector wQ); +static sunrealtype cvQuadUpdateNorm(CVodeMem cv_mem, sunrealtype old_nrm, + N_Vector xQ, N_Vector wQ); -static realtype cvQuadSensNorm(CVodeMem cv_mem, N_Vector *xQS, N_Vector *wQS); -static realtype cvQuadSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector *xQS, N_Vector *wQS); +static sunrealtype cvQuadSensNorm(CVodeMem cv_mem, N_Vector* xQS, N_Vector* wQS); +static sunrealtype cvQuadSensUpdateNorm(CVodeMem cv_mem, sunrealtype old_nrm, + N_Vector* xQS, N_Vector* wQS); /* Internal sensitivity RHS DQ functions */ -static int cvQuadSensRhsInternalDQ(int Ns, realtype t, - N_Vector y, N_Vector *yS, - N_Vector yQdot, N_Vector *yQSdot, - void *cvode_mem, - N_Vector tmp, N_Vector tmpQ); +static int cvQuadSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector y, + N_Vector* yS, N_Vector yQdot, N_Vector* yQSdot, + void* cvode_mem, N_Vector tmp, N_Vector tmpQ); -static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, - N_Vector y, N_Vector yS, - N_Vector yQdot, N_Vector yQSdot, - N_Vector tmp, N_Vector tmpQ); +static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, sunrealtype t, + N_Vector y, N_Vector yS, N_Vector yQdot, + N_Vector yQSdot, N_Vector tmp, N_Vector tmpQ); /* * ================================================================= @@ -571,23 +465,31 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, * message to standard err and returns NULL. */ -void *CVodeCreate(int lmm) +void* CVodeCreate(int lmm, SUNContext sunctx) { int maxord; CVodeMem cv_mem; /* Test inputs */ - if ((lmm != CV_ADAMS) && (lmm != CV_BDF)) { - cvProcessError(NULL, 0, "CVODES", "CVodeCreate", MSGCV_BAD_LMM); - return(NULL); + if ((lmm != CV_ADAMS) && (lmm != CV_BDF)) + { + cvProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSGCV_BAD_LMM); + return (NULL); + } + + if (sunctx == NULL) + { + cvProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSGCV_NULL_SUNCTX); + return (NULL); } cv_mem = NULL; - cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); - if (cv_mem == NULL) { - cvProcessError(NULL, 0, "CVODES", "CVodeCreate", MSGCV_CVMEM_FAIL); - return(NULL); + cv_mem = (CVodeMem)malloc(sizeof(struct CVodeMemRec)); + if (cv_mem == NULL) + { + cvProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSGCV_CVMEM_FAIL); + return (NULL); } /* Zero out cv_mem */ @@ -595,78 +497,97 @@ void *CVodeCreate(int lmm) maxord = (lmm == CV_ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; - /* copy input parameters into cv_mem */ - cv_mem->cv_lmm = lmm; + /* Copy input parameters into cv_mem */ + cv_mem->cv_sunctx = sunctx; + cv_mem->cv_lmm = lmm; /* Set uround */ - cv_mem->cv_uround = UNIT_ROUNDOFF; + cv_mem->cv_uround = SUN_UNIT_ROUNDOFF; /* Set default values for integrator optional inputs */ - cv_mem->cv_f = NULL; - cv_mem->cv_user_data = NULL; - cv_mem->cv_itol = CV_NN; - cv_mem->cv_atolmin0 = SUNTRUE; - cv_mem->cv_user_efun = SUNFALSE; - cv_mem->cv_efun = NULL; - cv_mem->cv_e_data = NULL; - cv_mem->cv_ehfun = cvErrHandler; - cv_mem->cv_eh_data = cv_mem; - cv_mem->cv_errfp = stderr; - cv_mem->cv_qmax = maxord; - cv_mem->cv_mxstep = MXSTEP_DEFAULT; - cv_mem->cv_mxhnil = MXHNIL_DEFAULT; - cv_mem->cv_sldeton = SUNFALSE; - cv_mem->cv_hin = ZERO; - cv_mem->cv_hmin = HMIN_DEFAULT; - cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT; - cv_mem->cv_tstopset = SUNFALSE; - cv_mem->cv_maxnef = MXNEF; - cv_mem->cv_maxncf = MXNCF; - cv_mem->cv_nlscoef = CORTES; - cv_mem->cv_msbp = MSBP; - cv_mem->convfail = CV_NO_FAILURES; - cv_mem->cv_constraints = NULL; - cv_mem->cv_constraintsSet = SUNFALSE; + cv_mem->cv_f = NULL; + cv_mem->cv_user_data = NULL; + cv_mem->cv_itol = CV_NN; + cv_mem->cv_atolmin0 = SUNTRUE; + cv_mem->cv_user_efun = SUNFALSE; + cv_mem->cv_efun = NULL; + cv_mem->cv_e_data = NULL; + cv_mem->cv_monitorfun = NULL; + cv_mem->cv_monitor_interval = 0; + cv_mem->cv_qmax = maxord; + cv_mem->cv_mxstep = MXSTEP_DEFAULT; + cv_mem->cv_mxhnil = MXHNIL_DEFAULT; + cv_mem->cv_sldeton = SUNFALSE; + cv_mem->cv_hin = ZERO; + cv_mem->cv_hmin = HMIN_DEFAULT; + cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT; + cv_mem->cv_eta_min_fx = ETA_MIN_FX_DEFAULT; + cv_mem->cv_eta_max_fx = ETA_MAX_FX_DEFAULT; + cv_mem->cv_eta_max_fs = ETA_MAX_FS_DEFAULT; + cv_mem->cv_eta_max_es = ETA_MAX_ES_DEFAULT; + cv_mem->cv_eta_max_gs = ETA_MAX_GS_DEFAULT; + cv_mem->cv_eta_min = ETA_MIN_DEFAULT; + cv_mem->cv_eta_min_ef = ETA_MIN_EF_DEFAULT; + cv_mem->cv_eta_max_ef = ETA_MAX_EF_DEFAULT; + cv_mem->cv_eta_cf = ETA_CF_DEFAULT; + cv_mem->cv_small_nst = SMALL_NST_DEFAULT; + cv_mem->cv_small_nef = SMALL_NEF_DEFAULT; + cv_mem->cv_tstopset = SUNFALSE; + cv_mem->cv_tstopinterp = SUNFALSE; + cv_mem->cv_maxnef = MXNEF; + cv_mem->cv_maxncf = MXNCF; + cv_mem->cv_nlscoef = CORTES; + cv_mem->cv_msbp = MSBP_DEFAULT; + cv_mem->cv_dgmax_lsetup = DGMAX_LSETUP_DEFAULT; + cv_mem->convfail = CV_NO_FAILURES; + cv_mem->cv_constraints = NULL; + cv_mem->cv_constraintsSet = SUNFALSE; /* Initialize root finding variables */ - cv_mem->cv_glo = NULL; - cv_mem->cv_ghi = NULL; - cv_mem->cv_grout = NULL; - cv_mem->cv_iroots = NULL; - cv_mem->cv_rootdir = NULL; - cv_mem->cv_gfun = NULL; - cv_mem->cv_nrtfn = 0; - cv_mem->cv_gactive = NULL; - cv_mem->cv_mxgnull = 1; + cv_mem->cv_glo = NULL; + cv_mem->cv_ghi = NULL; + cv_mem->cv_grout = NULL; + cv_mem->cv_iroots = NULL; + cv_mem->cv_rootdir = NULL; + cv_mem->cv_gfun = NULL; + cv_mem->cv_nrtfn = 0; + cv_mem->cv_gactive = NULL; + cv_mem->cv_mxgnull = 1; + + /* Initialize projection variables */ + cv_mem->proj_mem = NULL; + cv_mem->proj_enabled = SUNFALSE; + cv_mem->proj_applied = SUNFALSE; /* Set default values for quad. optional inputs */ - cv_mem->cv_quadr = SUNFALSE; - cv_mem->cv_fQ = NULL; - cv_mem->cv_errconQ = SUNFALSE; - cv_mem->cv_itolQ = CV_NN; - cv_mem->cv_atolQmin0 = SUNTRUE; + cv_mem->cv_quadr = SUNFALSE; + cv_mem->cv_fQ = NULL; + cv_mem->cv_errconQ = SUNFALSE; + cv_mem->cv_itolQ = CV_NN; + cv_mem->cv_atolQmin0 = SUNTRUE; /* Set default values for sensi. optional inputs */ - cv_mem->cv_sensi = SUNFALSE; - cv_mem->cv_fS_data = NULL; - cv_mem->cv_fS = cvSensRhsInternalDQ; - cv_mem->cv_fS1 = cvSensRhs1InternalDQ; - cv_mem->cv_fSDQ = SUNTRUE; - cv_mem->cv_ifS = CV_ONESENS; - cv_mem->cv_DQtype = CV_CENTERED; - cv_mem->cv_DQrhomax = ZERO; - cv_mem->cv_p = NULL; - cv_mem->cv_pbar = NULL; - cv_mem->cv_plist = NULL; - cv_mem->cv_errconS = SUNFALSE; - cv_mem->cv_ncfS1 = NULL; - cv_mem->cv_ncfnS1 = NULL; - cv_mem->cv_nniS1 = NULL; - cv_mem->cv_itolS = CV_NN; - cv_mem->cv_atolSmin0 = NULL; + cv_mem->cv_sensi = SUNFALSE; + cv_mem->cv_fS_data = NULL; + cv_mem->cv_fS = cvSensRhsInternalDQ; + cv_mem->cv_fS1 = cvSensRhs1InternalDQ; + cv_mem->cv_fSDQ = SUNTRUE; + cv_mem->cv_ifS = CV_ONESENS; + cv_mem->cv_DQtype = CV_CENTERED; + cv_mem->cv_DQrhomax = ZERO; + cv_mem->cv_p = NULL; + cv_mem->cv_pbar = NULL; + cv_mem->cv_plist = NULL; + cv_mem->cv_errconS = SUNFALSE; + cv_mem->cv_ncfS1 = NULL; + cv_mem->cv_ncfnS1 = NULL; + cv_mem->cv_nniS1 = NULL; + cv_mem->cv_nnfS1 = NULL; + cv_mem->cv_itolS = CV_NN; + cv_mem->cv_atolSmin0 = NULL; /* Set default values for quad. sensi. optional inputs */ @@ -680,8 +601,8 @@ void *CVodeCreate(int lmm) /* Set default for ASA */ - cv_mem->cv_adj = SUNFALSE; - cv_mem->cv_adj_mem = NULL; + cv_mem->cv_adj = SUNFALSE; + cv_mem->cv_adj_mem = NULL; /* Set the saved value for qmax_alloc */ @@ -691,7 +612,7 @@ void *CVodeCreate(int lmm) /* Initialize lrw and liw */ - cv_mem->cv_lrw = 65 + 2*L_MAX + NUM_TESTS; + cv_mem->cv_lrw = 65 + 2 * L_MAX + NUM_TESTS; cv_mem->cv_liw = 52; /* No mallocs have been done yet */ @@ -700,18 +621,18 @@ void *CVodeCreate(int lmm) cv_mem->cv_MallocDone = SUNFALSE; cv_mem->cv_constraintsMallocDone = SUNFALSE; - cv_mem->cv_VabstolQMallocDone = SUNFALSE; - cv_mem->cv_QuadMallocDone = SUNFALSE; + cv_mem->cv_VabstolQMallocDone = SUNFALSE; + cv_mem->cv_QuadMallocDone = SUNFALSE; - cv_mem->cv_VabstolSMallocDone = SUNFALSE; - cv_mem->cv_SabstolSMallocDone = SUNFALSE; - cv_mem->cv_SensMallocDone = SUNFALSE; + cv_mem->cv_VabstolSMallocDone = SUNFALSE; + cv_mem->cv_SabstolSMallocDone = SUNFALSE; + cv_mem->cv_SensMallocDone = SUNFALSE; cv_mem->cv_VabstolQSMallocDone = SUNFALSE; cv_mem->cv_SabstolQSMallocDone = SUNFALSE; cv_mem->cv_QuadSensMallocDone = SUNFALSE; - cv_mem->cv_adjMallocDone = SUNFALSE; + cv_mem->cv_adjMallocDone = SUNFALSE; /* Initialize nonlinear solver variables */ cv_mem->NLS = NULL; @@ -731,15 +652,15 @@ void *CVodeCreate(int lmm) cv_mem->ewtStg = NULL; cv_mem->stgMallocDone = SUNFALSE; - cv_mem->NLSstg1 = NULL; - cv_mem->ownNLSstg1 = SUNFALSE; + cv_mem->NLSstg1 = NULL; + cv_mem->ownNLSstg1 = SUNFALSE; cv_mem->sens_solve = SUNFALSE; cv_mem->sens_solve_idx = -1; /* Return pointer to CVODES memory block */ - return((void *)cv_mem); + return ((void*)cv_mem); } /*-----------------------------------------------------------------*/ @@ -753,48 +674,59 @@ void *CVodeCreate(int lmm) * errfp and an error flag is returned. Otherwise, it returns CV_SUCCESS */ -int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) +int CVodeInit(void* cvode_mem, CVRhsFn f, sunrealtype t0, N_Vector y0) { CVodeMem cv_mem; - booleantype nvectorOK, allocOK; + sunbooleantype nvectorOK, allocOK; sunindextype lrw1, liw1; - int i,k, retval; + int i, k, retval; SUNNonlinearSolver NLS; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Check for legal input parameters */ - if (y0==NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", MSGCV_NULL_Y0); - return(CV_ILL_INPUT); + if (y0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_Y0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - if (f == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", MSGCV_NULL_F); - return(CV_ILL_INPUT); + if (f == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_F); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Test if all required vector operations are implemented */ nvectorOK = cvCheckNvector(y0); - if(!nvectorOK) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", + if (!nvectorOK) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_NVECTOR); - return(CV_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Set space requirements for one N_Vector */ - if (y0->ops->nvspace != NULL) { - N_VSpace(y0, &lrw1, &liw1); - } else { + if (y0->ops->nvspace != NULL) { N_VSpace(y0, &lrw1, &liw1); } + else + { lrw1 = 0; liw1 = 0; } @@ -804,28 +736,32 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) /* Allocate the vectors (using y0 as a template) */ allocOK = cvAllocVectors(cv_mem, y0); - if (!allocOK) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (!allocOK) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* Allocate temporary work arrays for fused vector ops */ cv_mem->cv_cvals = NULL; - cv_mem->cv_cvals = (realtype *) malloc(L_MAX*sizeof(realtype)); + cv_mem->cv_cvals = (sunrealtype*)malloc(L_MAX * sizeof(sunrealtype)); cv_mem->cv_Xvecs = NULL; - cv_mem->cv_Xvecs = (N_Vector *) malloc(L_MAX*sizeof(N_Vector)); + cv_mem->cv_Xvecs = (N_Vector*)malloc(L_MAX * sizeof(N_Vector)); cv_mem->cv_Zvecs = NULL; - cv_mem->cv_Zvecs = (N_Vector *) malloc(L_MAX*sizeof(N_Vector)); + cv_mem->cv_Zvecs = (N_Vector*)malloc(L_MAX * sizeof(N_Vector)); - if ((cv_mem->cv_cvals == NULL) || - (cv_mem->cv_Xvecs == NULL) || - (cv_mem->cv_Zvecs == NULL)) { + if ((cv_mem->cv_cvals == NULL) || (cv_mem->cv_Xvecs == NULL) || + (cv_mem->cv_Zvecs == NULL)) + { cvFreeVectors(cv_mem); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* Input checks complete at this point and history array allocated */ @@ -838,25 +774,30 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) N_VScale(ONE, y0, cv_mem->cv_zn[0]); /* create a Newton nonlinear solver object by default */ - NLS = SUNNonlinSol_Newton(y0); + NLS = SUNNonlinSol_Newton(y0, cv_mem->cv_sunctx); /* check that nonlinear solver is non-NULL */ - if (NLS == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", MSGCV_MEM_FAIL); + if (NLS == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); cvFreeVectors(cv_mem); - return(CV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* attach the nonlinear solver to the CVODE memory */ retval = CVodeSetNonlinearSolver(cv_mem, NLS); /* check that the nonlinear solver was successfully attached */ - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, retval, "CVODES", "CVodeInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); cvFreeVectors(cv_mem); SUNNonlinSolFree(NLS); - return(CV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_MEM_FAIL); } /* set ownership flag */ @@ -869,7 +810,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cv_mem->cv_q = 1; cv_mem->cv_L = 2; cv_mem->cv_qwait = cv_mem->cv_L; - cv_mem->cv_etamax = ETAMX1; + cv_mem->cv_etamax = cv_mem->cv_eta_max_fs; cv_mem->cv_qu = 0; cv_mem->cv_hu = ZERO; @@ -895,19 +836,20 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cv_mem->cv_ncfn = 0; cv_mem->cv_netf = 0; cv_mem->cv_nni = 0; + cv_mem->cv_nnf = 0; cv_mem->cv_nsetups = 0; cv_mem->cv_nhnil = 0; cv_mem->cv_nstlp = 0; cv_mem->cv_nscon = 0; cv_mem->cv_nge = 0; - cv_mem->cv_irfnd = 0; + cv_mem->cv_irfnd = 0; /* Initialize other integrator optional outputs */ - cv_mem->cv_h0u = ZERO; - cv_mem->cv_next_h = ZERO; - cv_mem->cv_next_q = 0; + cv_mem->cv_h0u = ZERO; + cv_mem->cv_next_h = ZERO; + cv_mem->cv_next_q = 0; /* Initialize Stablilty Limit Detection data */ /* NOTE: We do this even if stab lim det was not @@ -916,14 +858,16 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cv_mem->cv_nor = 0; for (i = 1; i <= 5; i++) - for (k = 1; k <= 3; k++) - cv_mem->cv_ssdat[i-1][k-1] = ZERO; + { + for (k = 1; k <= 3; k++) { cv_mem->cv_ssdat[i - 1][k - 1] = ZERO; } + } /* Problem has been successfully initialized */ cv_mem->cv_MallocDone = SUNTRUE; - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -940,33 +884,40 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) * a negative value otherwise. */ -int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) +int CVodeReInit(void* cvode_mem, sunrealtype t0, N_Vector y0) { CVodeMem cv_mem; - int i,k; + int i, k; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeReInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Check if cvode_mem was allocated */ - if (cv_mem->cv_MallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVodeReInit", + if (cv_mem->cv_MallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_MALLOC, __LINE__, __func__, __FILE__, MSGCV_NO_MALLOC); - return(CV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_MALLOC); } /* Check for legal input parameters */ - if (y0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeReInit", + if (y0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_Y0); - return(CV_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Copy the input parameters into CVODES state */ @@ -978,7 +929,7 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) cv_mem->cv_q = 1; cv_mem->cv_L = 2; cv_mem->cv_qwait = cv_mem->cv_L; - cv_mem->cv_etamax = ETAMX1; + cv_mem->cv_etamax = cv_mem->cv_eta_max_fs; cv_mem->cv_qu = 0; cv_mem->cv_hu = ZERO; @@ -999,30 +950,33 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) cv_mem->cv_ncfn = 0; cv_mem->cv_netf = 0; cv_mem->cv_nni = 0; + cv_mem->cv_nnf = 0; cv_mem->cv_nsetups = 0; cv_mem->cv_nhnil = 0; cv_mem->cv_nstlp = 0; cv_mem->cv_nscon = 0; cv_mem->cv_nge = 0; - cv_mem->cv_irfnd = 0; + cv_mem->cv_irfnd = 0; /* Initialize other integrator optional outputs */ - cv_mem->cv_h0u = ZERO; - cv_mem->cv_next_h = ZERO; - cv_mem->cv_next_q = 0; + cv_mem->cv_h0u = ZERO; + cv_mem->cv_next_h = ZERO; + cv_mem->cv_next_q = 0; /* Initialize Stablilty Limit Detection data */ cv_mem->cv_nor = 0; for (i = 1; i <= 5; i++) - for (k = 1; k <= 3; k++) - cv_mem->cv_ssdat[i-1][k-1] = ZERO; + { + for (k = 1; k <= 3; k++) { cv_mem->cv_ssdat[i - 1][k - 1] = ZERO; } + } /* Problem has been successfully re-initialized */ - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1043,94 +997,101 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) * which will be called to set the error weight vector. */ -int CVodeSStolerances(void *cvode_mem, realtype reltol, realtype abstol) +int CVodeSStolerances(void* cvode_mem, sunrealtype reltol, sunrealtype abstol) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSStolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_MallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVodeSStolerances", + if (cv_mem->cv_MallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_MALLOC, __LINE__, __func__, __FILE__, MSGCV_NO_MALLOC); - return(CV_NO_MALLOC); + return (CV_NO_MALLOC); } /* Check inputs */ - if (reltol < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSStolerances", + if (reltol < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_RELTOL); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (abstol < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSStolerances", + if (abstol < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ABSTOL); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Copy tolerances into memory */ - cv_mem->cv_reltol = reltol; - cv_mem->cv_Sabstol = abstol; + cv_mem->cv_reltol = reltol; + cv_mem->cv_Sabstol = abstol; cv_mem->cv_atolmin0 = (abstol == ZERO); cv_mem->cv_itol = CV_SS; cv_mem->cv_user_efun = SUNFALSE; - cv_mem->cv_efun = cvEwtSet; - cv_mem->cv_e_data = NULL; /* will be set to cvode_mem in InitialSetup */ + cv_mem->cv_efun = cvEwtSet; + cv_mem->cv_e_data = NULL; /* will be set to cvode_mem in InitialSetup */ - return(CV_SUCCESS); + return (CV_SUCCESS); } - -int CVodeSVtolerances(void *cvode_mem, realtype reltol, N_Vector abstol) +int CVodeSVtolerances(void* cvode_mem, sunrealtype reltol, N_Vector abstol) { CVodeMem cv_mem; - realtype atolmin; + sunrealtype atolmin; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSVtolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_MallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVodeSVtolerances", + if (cv_mem->cv_MallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_MALLOC, __LINE__, __func__, __FILE__, MSGCV_NO_MALLOC); - return(CV_NO_MALLOC); + return (CV_NO_MALLOC); } /* Check inputs */ - if (reltol < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSVtolerances", + if (reltol < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_RELTOL); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (abstol->ops->nvmin == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSVtolerances", + if (abstol->ops->nvmin == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Missing N_VMin routine from N_Vector"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } atolmin = N_VMin(abstol); - if (atolmin < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSVtolerances", + if (atolmin < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ABSTOL); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Copy tolerances into memory */ - if ( !(cv_mem->cv_VabstolMallocDone) ) { + if (!(cv_mem->cv_VabstolMallocDone)) + { cv_mem->cv_Vabstol = N_VClone(cv_mem->cv_ewt); cv_mem->cv_lrw += cv_mem->cv_lrw1; cv_mem->cv_liw += cv_mem->cv_liw1; @@ -1144,37 +1105,37 @@ int CVodeSVtolerances(void *cvode_mem, realtype reltol, N_Vector abstol) cv_mem->cv_itol = CV_SV; cv_mem->cv_user_efun = SUNFALSE; - cv_mem->cv_efun = cvEwtSet; - cv_mem->cv_e_data = NULL; /* will be set to cvode_mem in InitialSetup */ + cv_mem->cv_efun = cvEwtSet; + cv_mem->cv_e_data = NULL; /* will be set to cvode_mem in InitialSetup */ - return(CV_SUCCESS); + return (CV_SUCCESS); } - -int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun) +int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeWFtolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_MallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVodeWFtolerances", + if (cv_mem->cv_MallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_MALLOC, __LINE__, __func__, __FILE__, MSGCV_NO_MALLOC); - return(CV_NO_MALLOC); + return (CV_NO_MALLOC); } cv_mem->cv_itol = CV_WF; cv_mem->cv_user_efun = SUNTRUE; - cv_mem->cv_efun = efun; - cv_mem->cv_e_data = NULL; /* will be set to user_data in InitialSetup */ + cv_mem->cv_efun = efun; + cv_mem->cv_e_data = NULL; /* will be set to user_data in InitialSetup */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1190,19 +1151,19 @@ int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun) * a negative value otherwise. */ -int CVodeQuadInit(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0) +int CVodeQuadInit(void* cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0) { CVodeMem cv_mem; - booleantype allocOK; + sunbooleantype allocOK; sunindextype lrw1Q, liw1Q; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeQuadInit", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Set space requirements for one N_Vector */ N_VSpace(yQ0, &lrw1Q, &liw1Q); @@ -1211,10 +1172,11 @@ int CVodeQuadInit(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0) /* Allocate the vectors (using yQ0 as a template) */ allocOK = cvQuadAllocVectors(cv_mem, yQ0); - if (!allocOK) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeQuadInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (!allocOK) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } /* Initialize znQ[0] in the history array */ @@ -1228,11 +1190,11 @@ int CVodeQuadInit(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0) cv_mem->cv_netfQ = 0; /* Quadrature integration turned ON */ - cv_mem->cv_quadr = SUNTRUE; + cv_mem->cv_quadr = SUNTRUE; cv_mem->cv_QuadMallocDone = SUNTRUE; /* Quadrature initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1250,23 +1212,24 @@ int CVodeQuadInit(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0) * a negative value otherwise. */ -int CVodeQuadReInit(void *cvode_mem, N_Vector yQ0) +int CVodeQuadReInit(void* cvode_mem, N_Vector yQ0) { CVodeMem cv_mem; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadReInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Ckeck if quadrature was initialized? */ - if (cv_mem->cv_QuadMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", - "CVodeQuadReInit", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } /* Initialize znQ[0] in the history array */ @@ -1280,7 +1243,7 @@ int CVodeQuadReInit(void *cvode_mem, N_Vector yQ0) cv_mem->cv_quadr = SUNTRUE; /* Quadrature re-initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1300,104 +1263,113 @@ int CVodeQuadReInit(void *cvode_mem, N_Vector yQ0) * vector component). */ -int CVodeQuadSStolerances(void *cvode_mem, realtype reltolQ, realtype abstolQ) +int CVodeQuadSStolerances(void* cvode_mem, sunrealtype reltolQ, + sunrealtype abstolQ) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadSStolerances", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Ckeck if quadrature was initialized? */ - if (cv_mem->cv_QuadMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", - "CVodeQuadSStolerances", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQ < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSStolerances", MSGCV_BAD_RELTOLQ); - return(CV_ILL_INPUT); + if (reltolQ < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_RELTOLQ); + return (CV_ILL_INPUT); } - if (abstolQ < 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSStolerances", MSGCV_BAD_ABSTOLQ); - return(CV_ILL_INPUT); + if (abstolQ < 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ABSTOLQ); + return (CV_ILL_INPUT); } /* Copy tolerances into memory */ cv_mem->cv_itolQ = CV_SS; - cv_mem->cv_reltolQ = reltolQ; - cv_mem->cv_SabstolQ = abstolQ; + cv_mem->cv_reltolQ = reltolQ; + cv_mem->cv_SabstolQ = abstolQ; cv_mem->cv_atolQmin0 = (abstolQ == ZERO); - return(CV_SUCCESS); + return (CV_SUCCESS); } -int CVodeQuadSVtolerances(void *cvode_mem, realtype reltolQ, N_Vector abstolQ) +int CVodeQuadSVtolerances(void* cvode_mem, sunrealtype reltolQ, N_Vector abstolQ) { CVodeMem cv_mem; - realtype atolmin; + sunrealtype atolmin; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadSVtolerances", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Ckeck if quadrature was initialized? */ - if (cv_mem->cv_QuadMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", - "CVodeQuadSVtolerances", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQ < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSVtolerances", MSGCV_BAD_RELTOLQ); - return(CV_ILL_INPUT); + if (reltolQ < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_RELTOLQ); + return (CV_ILL_INPUT); } - if (abstolQ == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSVtolerances", MSGCV_NULL_ABSTOLQ); - return(CV_ILL_INPUT); + if (abstolQ == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_ABSTOLQ); + return (CV_ILL_INPUT); } - if (abstolQ->ops->nvmin == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSVtolerances", + if (abstolQ->ops->nvmin == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Missing N_VMin routine from N_Vector"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } atolmin = N_VMin(abstolQ); - if (atolmin < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSVtolerances", MSGCV_BAD_ABSTOLQ); - return(CV_ILL_INPUT); + if (atolmin < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ABSTOLQ); + return (CV_ILL_INPUT); } /* Copy tolerances into memory */ cv_mem->cv_itolQ = CV_SV; - cv_mem->cv_reltolQ = reltolQ; + cv_mem->cv_reltolQ = reltolQ; - if ( !(cv_mem->cv_VabstolQMallocDone) ) { + if (!(cv_mem->cv_VabstolQMallocDone)) + { cv_mem->cv_VabstolQ = N_VClone(cv_mem->cv_tempvQ); cv_mem->cv_lrw += cv_mem->cv_lrw1Q; cv_mem->cv_liw += cv_mem->cv_liw1Q; @@ -1407,10 +1379,9 @@ int CVodeQuadSVtolerances(void *cvode_mem, realtype reltolQ, N_Vector abstolQ) N_VScale(ONE, abstolQ, cv_mem->cv_VabstolQ); cv_mem->cv_atolQmin0 = (atolmin == ZERO); - return(CV_SUCCESS); + return (CV_SUCCESS); } - /*-----------------------------------------------------------------*/ /* @@ -1424,62 +1395,67 @@ int CVodeQuadSVtolerances(void *cvode_mem, realtype reltolQ, N_Vector abstolQ) * a negative value otherwise. */ -int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS0) +int CVodeSensInit(void* cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector* yS0) { CVodeMem cv_mem; - booleantype allocOK; + sunbooleantype allocOK; int is, retval; SUNNonlinearSolver NLS; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensInit", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if CVodeSensInit or CVodeSensInit1 was already called */ - if (cv_mem->cv_SensMallocDone) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit", + if (cv_mem->cv_SensMallocDone) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_SENSINIT_2); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Check if Ns is legal */ - if (Ns<=0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit", + if (Ns <= 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_NS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->cv_Ns = Ns; /* Check if ism is compatible */ - if (ism==CV_STAGGERED1) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit", + if (ism == CV_STAGGERED1) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ISM_IFS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Check if ism is legal */ - if ((ism!=CV_SIMULTANEOUS) && (ism!=CV_STAGGERED)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit", + if ((ism != CV_SIMULTANEOUS) && (ism != CV_STAGGERED)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ISM); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->cv_ism = ism; /* Check if yS0 is non-null */ - if (yS0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit", + if (yS0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_YS0); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Store sensitivity RHS-related data */ @@ -1487,18 +1463,17 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS cv_mem->cv_ifS = CV_ALLSENS; cv_mem->cv_fS1 = NULL; - if (fS == NULL) { - - cv_mem->cv_fSDQ = SUNTRUE; - cv_mem->cv_fS = cvSensRhsInternalDQ; + if (fS == NULL) + { + cv_mem->cv_fSDQ = SUNTRUE; + cv_mem->cv_fS = cvSensRhsInternalDQ; cv_mem->cv_fS_data = cvode_mem; - - } else { - - cv_mem->cv_fSDQ = SUNFALSE; - cv_mem->cv_fS = fS; + } + else + { + cv_mem->cv_fSDQ = SUNFALSE; + cv_mem->cv_fS = fS; cv_mem->cv_fS_data = cv_mem->cv_user_data; - } /* No memory allocation for STAGGERED1 */ @@ -1508,29 +1483,34 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS /* Allocate the vectors (using yS0[0] as a template) */ allocOK = cvSensAllocVectors(cv_mem, yS0[0]); - if (!allocOK) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSensInit", + if (!allocOK) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* Check if larger temporary work arrays are needed for fused vector ops */ - if (Ns*L_MAX > L_MAX) { - free(cv_mem->cv_cvals); cv_mem->cv_cvals = NULL; - free(cv_mem->cv_Xvecs); cv_mem->cv_Xvecs = NULL; - free(cv_mem->cv_Zvecs); cv_mem->cv_Zvecs = NULL; - - cv_mem->cv_cvals = (realtype *) malloc((Ns*L_MAX)*sizeof(realtype)); - cv_mem->cv_Xvecs = (N_Vector *) malloc((Ns*L_MAX)*sizeof(N_Vector)); - cv_mem->cv_Zvecs = (N_Vector *) malloc((Ns*L_MAX)*sizeof(N_Vector)); - - if ((cv_mem->cv_cvals == NULL) || - (cv_mem->cv_Xvecs == NULL) || - (cv_mem->cv_Zvecs == NULL)) { + if (Ns * L_MAX > L_MAX) + { + free(cv_mem->cv_cvals); + cv_mem->cv_cvals = NULL; + free(cv_mem->cv_Xvecs); + cv_mem->cv_Xvecs = NULL; + free(cv_mem->cv_Zvecs); + cv_mem->cv_Zvecs = NULL; + + cv_mem->cv_cvals = (sunrealtype*)malloc((Ns * L_MAX) * sizeof(sunrealtype)); + cv_mem->cv_Xvecs = (N_Vector*)malloc((Ns * L_MAX) * sizeof(N_Vector)); + cv_mem->cv_Zvecs = (N_Vector*)malloc((Ns * L_MAX) * sizeof(N_Vector)); + + if ((cv_mem->cv_cvals == NULL) || (cv_mem->cv_Xvecs == NULL) || + (cv_mem->cv_Zvecs == NULL)) + { cvSensFreeVectors(cv_mem); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSensInit", + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } } @@ -1540,11 +1520,10 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS /* Initialize znS[0] in the history array */ - for (is=0; iscv_cvals[is] = ONE; + for (is = 0; is < Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(Ns, cv_mem->cv_cvals, yS0, cv_mem->cv_znS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Initialize all sensitivity related counters */ @@ -1553,57 +1532,64 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS cv_mem->cv_ncfnS = 0; cv_mem->cv_netfS = 0; cv_mem->cv_nniS = 0; + cv_mem->cv_nnfS = 0; cv_mem->cv_nsetupsS = 0; /* Set default values for plist and pbar */ - for (is=0; iscv_plist[is] = is; - cv_mem->cv_pbar[is] = ONE; + cv_mem->cv_pbar[is] = ONE; } /* Sensitivities will be computed */ - cv_mem->cv_sensi = SUNTRUE; + cv_mem->cv_sensi = SUNTRUE; cv_mem->cv_SensMallocDone = SUNTRUE; /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(Ns + 1, cv_mem->cv_acor, cv_mem->cv_sunctx); + } else - NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor, cv_mem->cv_sunctx); + } /* check that the nonlinear solver is non-NULL */ - if (NLS == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSensInit", MSGCV_MEM_FAIL); + if (NLS == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); cvSensFreeVectors(cv_mem); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* attach the nonlinear solver to the CVODE memory */ if (ism == CV_SIMULTANEOUS) + { retval = CVodeSetNonlinearSolverSensSim(cv_mem, NLS); - else - retval = CVodeSetNonlinearSolverSensStg(cv_mem, NLS); + } + else { retval = CVodeSetNonlinearSolverSensStg(cv_mem, NLS); } /* check that the nonlinear solver was successfully attached */ - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, retval, "CVODES", "CVodeSensInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); cvSensFreeVectors(cv_mem); SUNNonlinSolFree(NLS); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* set ownership flag */ - if (ism == CV_SIMULTANEOUS) - cv_mem->ownNLSsim = SUNTRUE; - else - cv_mem->ownNLSstg = SUNTRUE; + if (ism == CV_SIMULTANEOUS) { cv_mem->ownNLSsim = SUNTRUE; } + else { cv_mem->ownNLSstg = SUNTRUE; } /* Sensitivity initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1617,54 +1603,59 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS * a negative value otherwise. */ -int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector *yS0) +int CVodeSensInit1(void* cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, + N_Vector* yS0) { CVodeMem cv_mem; - booleantype allocOK; + sunbooleantype allocOK; int is, retval; SUNNonlinearSolver NLS; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensInit1", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if CVodeSensInit or CVodeSensInit1 was already called */ - if (cv_mem->cv_SensMallocDone) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit1", + if (cv_mem->cv_SensMallocDone) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_SENSINIT_2); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Check if Ns is legal */ - if (Ns<=0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit1", + if (Ns <= 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_NS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->cv_Ns = Ns; /* Check if ism is legal */ - if ((ism!=CV_SIMULTANEOUS) && (ism!=CV_STAGGERED) && (ism!=CV_STAGGERED1)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit1", + if ((ism != CV_SIMULTANEOUS) && (ism != CV_STAGGERED) && (ism != CV_STAGGERED1)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ISM); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->cv_ism = ism; /* Check if yS0 is non-null */ - if (yS0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensInit1", + if (yS0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_YS0); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Store sensitivity RHS-related data */ @@ -1672,77 +1663,95 @@ int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector cv_mem->cv_ifS = CV_ONESENS; cv_mem->cv_fS = NULL; - if (fS1 == NULL) { - - cv_mem->cv_fSDQ = SUNTRUE; - cv_mem->cv_fS1 = cvSensRhs1InternalDQ; + if (fS1 == NULL) + { + cv_mem->cv_fSDQ = SUNTRUE; + cv_mem->cv_fS1 = cvSensRhs1InternalDQ; cv_mem->cv_fS_data = cvode_mem; - - } else { - - cv_mem->cv_fSDQ = SUNFALSE; - cv_mem->cv_fS1 = fS1; + } + else + { + cv_mem->cv_fSDQ = SUNFALSE; + cv_mem->cv_fS1 = fS1; cv_mem->cv_fS_data = cv_mem->cv_user_data; - } /* Allocate ncfS1, ncfnS1, and nniS1 if needed */ - if (ism == CV_STAGGERED1) { + if (ism == CV_STAGGERED1) + { cv_mem->cv_stgr1alloc = SUNTRUE; - cv_mem->cv_ncfS1 = NULL; - cv_mem->cv_ncfS1 = (int*)malloc(Ns*sizeof(int)); - cv_mem->cv_ncfnS1 = NULL; - cv_mem->cv_ncfnS1 = (long int*)malloc(Ns*sizeof(long int)); - cv_mem->cv_nniS1 = NULL; - cv_mem->cv_nniS1 = (long int*)malloc(Ns*sizeof(long int)); - if ( (cv_mem->cv_ncfS1 == NULL) || - (cv_mem->cv_ncfnS1 == NULL) || - (cv_mem->cv_nniS1 == NULL) ) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSensInit1", + cv_mem->cv_ncfS1 = NULL; + cv_mem->cv_ncfS1 = (int*)malloc(Ns * sizeof(int)); + cv_mem->cv_ncfnS1 = NULL; + cv_mem->cv_ncfnS1 = (long int*)malloc(Ns * sizeof(long int)); + cv_mem->cv_nniS1 = NULL; + cv_mem->cv_nniS1 = (long int*)malloc(Ns * sizeof(long int)); + cv_mem->cv_nnfS1 = NULL; + cv_mem->cv_nnfS1 = (long int*)malloc(Ns * sizeof(long int)); + if ((cv_mem->cv_ncfS1 == NULL) || (cv_mem->cv_ncfnS1 == NULL) || + (cv_mem->cv_nniS1 == NULL) || (cv_mem->cv_nnfS1 == NULL)) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } - } else { - cv_mem->cv_stgr1alloc = SUNFALSE; } + else { cv_mem->cv_stgr1alloc = SUNFALSE; } /* Allocate the vectors (using yS0[0] as a template) */ allocOK = cvSensAllocVectors(cv_mem, yS0[0]); - if (!allocOK) { - if (cv_mem->cv_stgr1alloc) { - free(cv_mem->cv_ncfS1); cv_mem->cv_ncfS1 = NULL; - free(cv_mem->cv_ncfnS1); cv_mem->cv_ncfnS1 = NULL; - free(cv_mem->cv_nniS1); cv_mem->cv_nniS1 = NULL; + if (!allocOK) + { + if (cv_mem->cv_stgr1alloc) + { + free(cv_mem->cv_ncfS1); + cv_mem->cv_ncfS1 = NULL; + free(cv_mem->cv_ncfnS1); + cv_mem->cv_ncfnS1 = NULL; + free(cv_mem->cv_nniS1); + cv_mem->cv_nniS1 = NULL; + free(cv_mem->cv_nnfS1); + cv_mem->cv_nnfS1 = NULL; } - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSensInit1", + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* Check if larger temporary work arrays are needed for fused vector ops */ - if (Ns*L_MAX > L_MAX) { - free(cv_mem->cv_cvals); cv_mem->cv_cvals = NULL; - free(cv_mem->cv_Xvecs); cv_mem->cv_Xvecs = NULL; - free(cv_mem->cv_Zvecs); cv_mem->cv_Zvecs = NULL; - - cv_mem->cv_cvals = (realtype *) malloc((Ns*L_MAX)*sizeof(realtype)); - cv_mem->cv_Xvecs = (N_Vector *) malloc((Ns*L_MAX)*sizeof(N_Vector)); - cv_mem->cv_Zvecs = (N_Vector *) malloc((Ns*L_MAX)*sizeof(N_Vector)); - - if ((cv_mem->cv_cvals == NULL) || - (cv_mem->cv_Xvecs == NULL) || - (cv_mem->cv_Zvecs == NULL)) { - if (cv_mem->cv_stgr1alloc) { - free(cv_mem->cv_ncfS1); cv_mem->cv_ncfS1 = NULL; - free(cv_mem->cv_ncfnS1); cv_mem->cv_ncfnS1 = NULL; - free(cv_mem->cv_nniS1); cv_mem->cv_nniS1 = NULL; + if (Ns * L_MAX > L_MAX) + { + free(cv_mem->cv_cvals); + cv_mem->cv_cvals = NULL; + free(cv_mem->cv_Xvecs); + cv_mem->cv_Xvecs = NULL; + free(cv_mem->cv_Zvecs); + cv_mem->cv_Zvecs = NULL; + + cv_mem->cv_cvals = (sunrealtype*)malloc((Ns * L_MAX) * sizeof(sunrealtype)); + cv_mem->cv_Xvecs = (N_Vector*)malloc((Ns * L_MAX) * sizeof(N_Vector)); + cv_mem->cv_Zvecs = (N_Vector*)malloc((Ns * L_MAX) * sizeof(N_Vector)); + + if ((cv_mem->cv_cvals == NULL) || (cv_mem->cv_Xvecs == NULL) || + (cv_mem->cv_Zvecs == NULL)) + { + if (cv_mem->cv_stgr1alloc) + { + free(cv_mem->cv_ncfS1); + cv_mem->cv_ncfS1 = NULL; + free(cv_mem->cv_ncfnS1); + cv_mem->cv_ncfnS1 = NULL; + free(cv_mem->cv_nniS1); + cv_mem->cv_nniS1 = NULL; + free(cv_mem->cv_nnfS1); + cv_mem->cv_nnfS1 = NULL; } cvSensFreeVectors(cv_mem); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSensInit1", + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } } @@ -1752,11 +1761,10 @@ int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector /* Initialize znS[0] in the history array */ - for (is=0; iscv_cvals[is] = ONE; + for (is = 0; is < Ns; is++) { cv_mem->cv_cvals[is] = ONE; } retval = N_VScaleVectorArray(Ns, cv_mem->cv_cvals, yS0, cv_mem->cv_znS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Initialize all sensitivity related counters */ @@ -1765,68 +1773,79 @@ int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector cv_mem->cv_ncfnS = 0; cv_mem->cv_netfS = 0; cv_mem->cv_nniS = 0; + cv_mem->cv_nnfS = 0; cv_mem->cv_nsetupsS = 0; - if (ism==CV_STAGGERED1) - for (is=0; iscv_ncfnS1[is] = 0; - cv_mem->cv_nniS1[is] = 0; + cv_mem->cv_nniS1[is] = 0; + cv_mem->cv_nnfS1[is] = 0; } + } /* Set default values for plist and pbar */ - for (is=0; iscv_plist[is] = is; - cv_mem->cv_pbar[is] = ONE; + cv_mem->cv_pbar[is] = ONE; } /* Sensitivities will be computed */ - cv_mem->cv_sensi = SUNTRUE; + cv_mem->cv_sensi = SUNTRUE; cv_mem->cv_SensMallocDone = SUNTRUE; /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(Ns + 1, cv_mem->cv_acor, cv_mem->cv_sunctx); + } else if (ism == CV_STAGGERED) - NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor); - else - NLS = SUNNonlinSol_Newton(cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor, cv_mem->cv_sunctx); + } + else { NLS = SUNNonlinSol_Newton(cv_mem->cv_acor, cv_mem->cv_sunctx); } /* check that the nonlinear solver is non-NULL */ - if (NLS == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSensInit1", MSGCV_MEM_FAIL); + if (NLS == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); cvSensFreeVectors(cv_mem); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* attach the nonlinear solver to the CVODE memory */ if (ism == CV_SIMULTANEOUS) + { retval = CVodeSetNonlinearSolverSensSim(cv_mem, NLS); + } else if (ism == CV_STAGGERED) + { retval = CVodeSetNonlinearSolverSensStg(cv_mem, NLS); - else - retval = CVodeSetNonlinearSolverSensStg1(cv_mem, NLS); + } + else { retval = CVodeSetNonlinearSolverSensStg1(cv_mem, NLS); } /* check that the nonlinear solver was successfully attached */ - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, retval, "CVODES", "CVodeSensInit1", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); cvSensFreeVectors(cv_mem); SUNNonlinSolFree(NLS); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* set ownership flag */ - if (ism == CV_SIMULTANEOUS) - cv_mem->ownNLSsim = SUNTRUE; - else if (ism == CV_STAGGERED) - cv_mem->ownNLSstg = SUNTRUE; - else - cv_mem->ownNLSstg1 = SUNTRUE; + if (ism == CV_SIMULTANEOUS) { cv_mem->ownNLSsim = SUNTRUE; } + else if (ism == CV_STAGGERED) { cv_mem->ownNLSstg = SUNTRUE; } + else { cv_mem->ownNLSstg1 = SUNTRUE; } /* Sensitivity initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1846,7 +1865,7 @@ int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector * a negative value otherwise. */ -int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) +int CVodeSensReInit(void* cvode_mem, int ism, N_Vector* yS0) { CVodeMem cv_mem; int is, retval; @@ -1854,62 +1873,69 @@ int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensReInit", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSensReInit", + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_NO_SENS); + return (CV_NO_SENS); } /* Check if ism is compatible */ - if ((cv_mem->cv_ifS==CV_ALLSENS) && (ism==CV_STAGGERED1)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensReInit", MSGCV_BAD_ISM_IFS); - return(CV_ILL_INPUT); + if ((cv_mem->cv_ifS == CV_ALLSENS) && (ism == CV_STAGGERED1)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ISM_IFS); + return (CV_ILL_INPUT); } /* Check if ism is legal */ - if ((ism!=CV_SIMULTANEOUS) && (ism!=CV_STAGGERED) && (ism!=CV_STAGGERED1)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensReInit", MSGCV_BAD_ISM); - return(CV_ILL_INPUT); + if ((ism != CV_SIMULTANEOUS) && (ism != CV_STAGGERED) && (ism != CV_STAGGERED1)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ISM); + return (CV_ILL_INPUT); } cv_mem->cv_ism = ism; /* Check if yS0 is non-null */ - if (yS0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensReInit", MSGCV_NULL_YS0); - return(CV_ILL_INPUT); + if (yS0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_YS0); + return (CV_ILL_INPUT); } /* Allocate ncfS1, ncfnS1, and nniS1 if needed */ - if ( (ism==CV_STAGGERED1) && (cv_mem->cv_stgr1alloc==SUNFALSE) ) { + if ((ism == CV_STAGGERED1) && (cv_mem->cv_stgr1alloc == SUNFALSE)) + { cv_mem->cv_stgr1alloc = SUNTRUE; - cv_mem->cv_ncfS1 = NULL; - cv_mem->cv_ncfS1 = (int*)malloc(cv_mem->cv_Ns*sizeof(int)); - cv_mem->cv_ncfnS1 = NULL; - cv_mem->cv_ncfnS1 = (long int*)malloc(cv_mem->cv_Ns*sizeof(long int)); - cv_mem->cv_nniS1 = NULL; - cv_mem->cv_nniS1 = (long int*)malloc(cv_mem->cv_Ns*sizeof(long int)); - if ( (cv_mem->cv_ncfS1==NULL) || - (cv_mem->cv_ncfnS1==NULL) || - (cv_mem->cv_nniS1==NULL) ) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSensReInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cv_mem->cv_ncfS1 = NULL; + cv_mem->cv_ncfS1 = (int*)malloc(cv_mem->cv_Ns * sizeof(int)); + cv_mem->cv_ncfnS1 = NULL; + cv_mem->cv_ncfnS1 = (long int*)malloc(cv_mem->cv_Ns * sizeof(long int)); + cv_mem->cv_nniS1 = NULL; + cv_mem->cv_nniS1 = (long int*)malloc(cv_mem->cv_Ns * sizeof(long int)); + cv_mem->cv_nnfS1 = NULL; + cv_mem->cv_nnfS1 = (long int*)malloc(cv_mem->cv_Ns * sizeof(long int)); + if ((cv_mem->cv_ncfS1 == NULL) || (cv_mem->cv_ncfnS1 == NULL) || + (cv_mem->cv_nniS1 == NULL) || (cv_mem->cv_nnfS1 == NULL)) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } } @@ -1919,12 +1945,11 @@ int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) /* Initialize znS[0] in the history array */ - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - yS0, cv_mem->cv_znS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, yS0, + cv_mem->cv_znS[0]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Initialize all sensitivity related counters */ @@ -1933,79 +1958,89 @@ int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) cv_mem->cv_ncfnS = 0; cv_mem->cv_netfS = 0; cv_mem->cv_nniS = 0; + cv_mem->cv_nnfS = 0; cv_mem->cv_nsetupsS = 0; - if (ism==CV_STAGGERED1) - for (is=0; iscv_Ns; is++) { + if (ism == CV_STAGGERED1) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_ncfnS1[is] = 0; - cv_mem->cv_nniS1[is] = 0; + cv_mem->cv_nniS1[is] = 0; + cv_mem->cv_nnfS1[is] = 0; } + } /* Problem has been successfully re-initialized */ cv_mem->cv_sensi = SUNTRUE; /* Check if the NLS exists, create the default NLS if needed */ - if ( (ism == CV_SIMULTANEOUS && cv_mem->NLSsim == NULL) || - (ism == CV_STAGGERED && cv_mem->NLSstg == NULL) || - (ism == CV_STAGGERED1 && cv_mem->NLSstg1 == NULL) ) { - + if ((ism == CV_SIMULTANEOUS && cv_mem->NLSsim == NULL) || + (ism == CV_STAGGERED && cv_mem->NLSstg == NULL) || + (ism == CV_STAGGERED1 && cv_mem->NLSstg1 == NULL)) + { /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns+1, cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns + 1, cv_mem->cv_acor, + cv_mem->cv_sunctx); + } else if (ism == CV_STAGGERED) - NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns, cv_mem->cv_acor); - else - NLS = SUNNonlinSol_Newton(cv_mem->cv_acor); + { + NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns, cv_mem->cv_acor, + cv_mem->cv_sunctx); + } + else { NLS = SUNNonlinSol_Newton(cv_mem->cv_acor, cv_mem->cv_sunctx); } /* check that the nonlinear solver is non-NULL */ - if (NLS == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSensReInit", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (NLS == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } /* attach the nonlinear solver to the CVODES memory */ if (ism == CV_SIMULTANEOUS) + { retval = CVodeSetNonlinearSolverSensSim(cv_mem, NLS); + } else if (ism == CV_STAGGERED) + { retval = CVodeSetNonlinearSolverSensStg(cv_mem, NLS); - else - retval = CVodeSetNonlinearSolverSensStg1(cv_mem, NLS); + } + else { retval = CVodeSetNonlinearSolverSensStg1(cv_mem, NLS); } /* check that the nonlinear solver was successfully attached */ - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, retval, "CVODES", "CVodeSensReInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); SUNNonlinSolFree(NLS); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* set ownership flag */ - if (ism == CV_SIMULTANEOUS) - cv_mem->ownNLSsim = SUNTRUE; - else if (ism == CV_STAGGERED) - cv_mem->ownNLSstg = SUNTRUE; - else - cv_mem->ownNLSstg1 = SUNTRUE; + if (ism == CV_SIMULTANEOUS) { cv_mem->ownNLSsim = SUNTRUE; } + else if (ism == CV_STAGGERED) { cv_mem->ownNLSstg = SUNTRUE; } + else { cv_mem->ownNLSstg1 = SUNTRUE; } /* initialize the NLS object, this assumes that the linear solver has already been initialized in CVodeInit */ - if (ism == CV_SIMULTANEOUS) - retval = cvNlsInitSensSim(cv_mem); - else if (ism == CV_STAGGERED) - retval = cvNlsInitSensStg(cv_mem); - else - retval = cvNlsInitSensStg1(cv_mem); - - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_NLS_INIT_FAIL, "CVODES", - "CVodeSensReInit", MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + if (ism == CV_SIMULTANEOUS) { retval = cvNlsInitSensSim(cv_mem); } + else if (ism == CV_STAGGERED) { retval = cvNlsInitSensStg(cv_mem); } + else { retval = cvNlsInitSensStg1(cv_mem); } + + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, + MSGCV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } } /* Sensitivity re-initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -2022,50 +2057,57 @@ int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) * CVodeSensSVtolerances specifies scalar relative tolerance and a vector * absolute tolerance for each sensitivity vector (a potentially different * absolute tolerance for each vector component). - * CVodeEEtolerances specifies that tolerances for sensitivity variables + * CVodeSensEEtolerances specifies that tolerances for sensitivity variables * should be estimated from those provided for the state variables. */ -int CVodeSensSStolerances(void *cvode_mem, realtype reltolS, realtype *abstolS) +int CVodeSensSStolerances(void* cvode_mem, sunrealtype reltolS, + sunrealtype* abstolS) { CVodeMem cv_mem; int is; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensSStolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSensSStolerances", + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_NO_SENS); + return (CV_NO_SENS); } /* Test user-supplied tolerances */ - if (reltolS < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensSStolerances", + if (reltolS < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_RELTOLS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (abstolS == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensSStolerances", + if (abstolS == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_ABSTOLS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - for (is=0; iscv_Ns; is++) - if (abstolS[is] < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSensSStolerances", + for (is = 0; is < cv_mem->cv_Ns; is++) + { + if (abstolS[is] < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_ABSTOLS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } + } /* Copy tolerances into memory */ @@ -2073,71 +2115,80 @@ int CVodeSensSStolerances(void *cvode_mem, realtype reltolS, realtype *abstolS) cv_mem->cv_reltolS = reltolS; - if ( !(cv_mem->cv_SabstolSMallocDone) ) { + if (!(cv_mem->cv_SabstolSMallocDone)) + { cv_mem->cv_SabstolS = NULL; - cv_mem->cv_SabstolS = (realtype *)malloc(cv_mem->cv_Ns*sizeof(realtype)); - cv_mem->cv_atolSmin0 = (booleantype *)malloc(cv_mem->cv_Ns*sizeof(booleantype)); + cv_mem->cv_SabstolS = + (sunrealtype*)malloc(cv_mem->cv_Ns * sizeof(sunrealtype)); + cv_mem->cv_atolSmin0 = + (sunbooleantype*)malloc(cv_mem->cv_Ns * sizeof(sunbooleantype)); cv_mem->cv_lrw += cv_mem->cv_Ns; cv_mem->cv_SabstolSMallocDone = SUNTRUE; } - for (is=0; iscv_Ns; is++) { - cv_mem->cv_SabstolS[is] = abstolS[is]; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_SabstolS[is] = abstolS[is]; cv_mem->cv_atolSmin0[is] = (abstolS[is] == ZERO); } - return(CV_SUCCESS); + return (CV_SUCCESS); } -int CVodeSensSVtolerances(void *cvode_mem, realtype reltolS, N_Vector *abstolS) +int CVodeSensSVtolerances(void* cvode_mem, sunrealtype reltolS, N_Vector* abstolS) { CVodeMem cv_mem; int is, retval; - realtype *atolmin; + sunrealtype* atolmin; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensSVtolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSensSVtolerances", + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_NO_SENS); + return (CV_NO_SENS); } /* Test user-supplied tolerances */ - if (reltolS < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensSVtolerances", MSGCV_BAD_RELTOLS); - return(CV_ILL_INPUT); + if (reltolS < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_RELTOLS); + return (CV_ILL_INPUT); } - if (abstolS == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensSVtolerances", MSGCV_NULL_ABSTOLS); - return(CV_ILL_INPUT); + if (abstolS == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_ABSTOLS); + return (CV_ILL_INPUT); } - if (cv_mem->cv_tempv->ops->nvmin == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensSVtolerances", + if (cv_mem->cv_tempv->ops->nvmin == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Missing N_VMin routine from N_Vector"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - atolmin = (realtype *)malloc(cv_mem->cv_Ns*sizeof(realtype)); - for (is=0; iscv_Ns; is++) { + atolmin = (sunrealtype*)malloc(cv_mem->cv_Ns * sizeof(sunrealtype)); + for (is = 0; is < cv_mem->cv_Ns; is++) + { atolmin[is] = N_VMin(abstolS[is]); - if (atolmin[is] < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSensSVtolerances", MSGCV_BAD_ABSTOLS); + if (atolmin[is] < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ABSTOLS); free(atolmin); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } } @@ -2147,53 +2198,55 @@ int CVodeSensSVtolerances(void *cvode_mem, realtype reltolS, N_Vector *abstolS) cv_mem->cv_reltolS = reltolS; - if ( !(cv_mem->cv_VabstolSMallocDone) ) { + if (!(cv_mem->cv_VabstolSMallocDone)) + { cv_mem->cv_VabstolS = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempv); - cv_mem->cv_atolSmin0 = (booleantype *)malloc(cv_mem->cv_Ns*sizeof(booleantype)); - cv_mem->cv_lrw += cv_mem->cv_Ns*cv_mem->cv_lrw1; - cv_mem->cv_liw += cv_mem->cv_Ns*cv_mem->cv_liw1; + cv_mem->cv_atolSmin0 = + (sunbooleantype*)malloc(cv_mem->cv_Ns * sizeof(sunbooleantype)); + cv_mem->cv_lrw += cv_mem->cv_Ns * cv_mem->cv_lrw1; + cv_mem->cv_liw += cv_mem->cv_Ns * cv_mem->cv_liw1; cv_mem->cv_VabstolSMallocDone = SUNTRUE; } - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[is] = ONE; cv_mem->cv_atolSmin0[is] = (atolmin[is] == ZERO); } free(atolmin); - retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - abstolS, cv_mem->cv_VabstolS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, abstolS, + cv_mem->cv_VabstolS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -int CVodeSensEEtolerances(void *cvode_mem) +int CVodeSensEEtolerances(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensEEtolerances", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSensEEtolerances", + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_NO_SENS); + return (CV_NO_SENS); } cv_mem->cv_itolS = CV_EE; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /*-----------------------------------------------------------------*/ /* @@ -2201,40 +2254,43 @@ int CVodeSensEEtolerances(void *cvode_mem) * */ -int CVodeQuadSensInit(void *cvode_mem, CVQuadSensRhsFn fQS, N_Vector *yQS0) +int CVodeQuadSensInit(void* cvode_mem, CVQuadSensRhsFn fQS, N_Vector* yQS0) { - CVodeMem cv_mem; - booleantype allocOK; + CVodeMem cv_mem; + sunbooleantype allocOK; int is, retval; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeQuadSensInit", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if sensitivity analysis is active */ - if (!cv_mem->cv_sensi) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeQuadSensInit", + if (!cv_mem->cv_sensi) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Check if yQS0 is non-null */ - if (yQS0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeQuadSensInit", + if (yQS0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_YQS0); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Allocate the vectors (using yQS0[0] as a template) */ allocOK = cvQuadSensAllocVectors(cv_mem, yQS0[0]); - if (!allocOK) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeQuadSensInit", + if (!allocOK) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /*---------------------------------------------- @@ -2242,29 +2298,27 @@ int CVodeQuadSensInit(void *cvode_mem, CVQuadSensRhsFn fQS, N_Vector *yQS0) -----------------------------------------------*/ /* Set fQS */ - if (fQS == NULL) { - + if (fQS == NULL) + { cv_mem->cv_fQSDQ = SUNTRUE; - cv_mem->cv_fQS = cvQuadSensRhsInternalDQ; + cv_mem->cv_fQS = cvQuadSensRhsInternalDQ; cv_mem->cv_fQS_data = cvode_mem; - - } else { - + } + else + { cv_mem->cv_fQSDQ = SUNFALSE; - cv_mem->cv_fQS = fQS; + cv_mem->cv_fQS = fQS; cv_mem->cv_fQS_data = cv_mem->cv_user_data; - } /* Initialize znQS[0] in the history array */ - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - yQS0, cv_mem->cv_znQS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, yQS0, + cv_mem->cv_znQS[0]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Initialize all sensitivity related counters */ cv_mem->cv_nfQSe = 0; @@ -2272,11 +2326,11 @@ int CVodeQuadSensInit(void *cvode_mem, CVQuadSensRhsFn fQS, N_Vector *yQS0) cv_mem->cv_netfQS = 0; /* Quadrature sensitivities will be computed */ - cv_mem->cv_quadr_sensi = SUNTRUE; + cv_mem->cv_quadr_sensi = SUNTRUE; cv_mem->cv_QuadSensMallocDone = SUNTRUE; /* Sensitivity initialization was successfull */ - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -2284,38 +2338,41 @@ int CVodeQuadSensInit(void *cvode_mem, CVQuadSensRhsFn fQS, N_Vector *yQS0) * */ -int CVodeQuadSensReInit(void *cvode_mem, N_Vector *yQS0) +int CVodeQuadSensReInit(void* cvode_mem, N_Vector* yQS0) { CVodeMem cv_mem; int is, retval; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeQuadSensReInit", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if sensitivity analysis is active */ - if (!cv_mem->cv_sensi) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensReInit", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (!cv_mem->cv_sensi) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } /* Was quadrature sensitivity initialized? */ - if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", - "CVodeQuadSensReInit", MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUADSENS); } /* Check if yQS0 is non-null */ - if (yQS0 == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensReInit", MSGCV_NULL_YQS0); - return(CV_ILL_INPUT); + if (yQS0 == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_YQS0); + return (CV_ILL_INPUT); } /*---------------------------------------------- @@ -2323,12 +2380,11 @@ int CVodeQuadSensReInit(void *cvode_mem, N_Vector *yQS0) -----------------------------------------------*/ /* Initialize znQS[0] in the history array */ - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - yQS0, cv_mem->cv_znQS[0]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, yQS0, + cv_mem->cv_znQS[0]); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* Initialize all sensitivity related counters */ cv_mem->cv_nfQSe = 0; @@ -2339,10 +2395,9 @@ int CVodeQuadSensReInit(void *cvode_mem, N_Vector *yQS0) cv_mem->cv_quadr_sensi = SUNTRUE; /* Problem has been successfully re-initialized */ - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * CVodeQuadSensSStolerances * CVodeQuadSensSVtolerances @@ -2362,54 +2417,62 @@ int CVodeQuadSensReInit(void *cvode_mem, N_Vector *yQS0) * specified through a call to one of CVodeQuad**tolerances. */ -int CVodeQuadSensSStolerances(void *cvode_mem, realtype reltolQS, realtype *abstolQS) +int CVodeQuadSensSStolerances(void* cvode_mem, sunrealtype reltolQS, + sunrealtype* abstolQS) { CVodeMem cv_mem; int is; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadSensSStolerances", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if sensitivity was initialized */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeQuadSensSStolerances", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } /* Ckeck if quadrature sensitivity was initialized? */ - if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", - "CVodeQuadSSensSStolerances", MSGCV_NO_QUADSENSI); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQS < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSStolerances", MSGCV_BAD_RELTOLQS); - return(CV_ILL_INPUT); + if (reltolQS < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_RELTOLQS); + return (CV_ILL_INPUT); } - if (abstolQS == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSStolerances", MSGCV_NULL_ABSTOLQS); - return(CV_ILL_INPUT); + if (abstolQS == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_ABSTOLQS); + return (CV_ILL_INPUT); } - for (is=0; iscv_Ns; is++) - if (abstolQS[is] < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSStolerances", MSGCV_BAD_ABSTOLQS); - return(CV_ILL_INPUT); + for (is = 0; is < cv_mem->cv_Ns; is++) + { + if (abstolQS[is] < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ABSTOLQS); + return (CV_ILL_INPUT); } + } /* Copy tolerances into memory */ @@ -2417,79 +2480,90 @@ int CVodeQuadSensSStolerances(void *cvode_mem, realtype reltolQS, realtype *abst cv_mem->cv_reltolQS = reltolQS; - if ( !(cv_mem->cv_SabstolQSMallocDone) ) { + if (!(cv_mem->cv_SabstolQSMallocDone)) + { cv_mem->cv_SabstolQS = NULL; - cv_mem->cv_SabstolQS = (realtype *)malloc(cv_mem->cv_Ns*sizeof(realtype)); - cv_mem->cv_atolQSmin0 = (booleantype *)malloc(cv_mem->cv_Ns*sizeof(booleantype)); + cv_mem->cv_SabstolQS = + (sunrealtype*)malloc(cv_mem->cv_Ns * sizeof(sunrealtype)); + cv_mem->cv_atolQSmin0 = + (sunbooleantype*)malloc(cv_mem->cv_Ns * sizeof(sunbooleantype)); cv_mem->cv_lrw += cv_mem->cv_Ns; cv_mem->cv_SabstolQSMallocDone = SUNTRUE; } - for (is=0; iscv_Ns; is++) { - cv_mem->cv_SabstolQS[is] = abstolQS[is]; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_SabstolQS[is] = abstolQS[is]; cv_mem->cv_atolQSmin0[is] = (abstolQS[is] == ZERO); } - return(CV_SUCCESS); + return (CV_SUCCESS); } -int CVodeQuadSensSVtolerances(void *cvode_mem, realtype reltolQS, N_Vector *abstolQS) +int CVodeQuadSensSVtolerances(void* cvode_mem, sunrealtype reltolQS, + N_Vector* abstolQS) { CVodeMem cv_mem; int is, retval; - realtype *atolmin; + sunrealtype* atolmin; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* check if sensitivity was initialized */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } /* Ckeck if quadrature sensitivity was initialized? */ - if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_NO_QUADSENSI); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQS < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_BAD_RELTOLQS); - return(CV_ILL_INPUT); + if (reltolQS < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_RELTOLQS); + return (CV_ILL_INPUT); } - if (abstolQS == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_NULL_ABSTOLQS); - return(CV_ILL_INPUT); + if (abstolQS == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NULL_ABSTOLQS); + return (CV_ILL_INPUT); } - if (cv_mem->cv_tempv->ops->nvmin == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSVtolerances", + if (cv_mem->cv_tempv->ops->nvmin == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Missing N_VMin routine from N_Vector"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - atolmin = (realtype *)malloc(cv_mem->cv_Ns*sizeof(realtype)); - for (is=0; iscv_Ns; is++) { + atolmin = (sunrealtype*)malloc(cv_mem->cv_Ns * sizeof(sunrealtype)); + for (is = 0; is < cv_mem->cv_Ns; is++) + { atolmin[is] = N_VMin(abstolQS[is]); - if (atolmin[is] < ZERO) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeQuadSensSVtolerances", MSGCV_BAD_ABSTOLQS); + if (atolmin[is] < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ABSTOLQS); free(atolmin); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } } @@ -2499,58 +2573,62 @@ int CVodeQuadSensSVtolerances(void *cvode_mem, realtype reltolQS, N_Vector *abs cv_mem->cv_reltolQS = reltolQS; - if ( !(cv_mem->cv_VabstolQSMallocDone) ) { + if (!(cv_mem->cv_VabstolQSMallocDone)) + { cv_mem->cv_VabstolQS = N_VCloneVectorArray(cv_mem->cv_Ns, cv_mem->cv_tempvQ); - cv_mem->cv_atolQSmin0 = (booleantype *)malloc(cv_mem->cv_Ns*sizeof(booleantype)); - cv_mem->cv_lrw += cv_mem->cv_Ns*cv_mem->cv_lrw1Q; - cv_mem->cv_liw += cv_mem->cv_Ns*cv_mem->cv_liw1Q; + cv_mem->cv_atolQSmin0 = + (sunbooleantype*)malloc(cv_mem->cv_Ns * sizeof(sunbooleantype)); + cv_mem->cv_lrw += cv_mem->cv_Ns * cv_mem->cv_lrw1Q; + cv_mem->cv_liw += cv_mem->cv_Ns * cv_mem->cv_liw1Q; cv_mem->cv_VabstolQSMallocDone = SUNTRUE; } - for (is=0; iscv_Ns; is++) { - cv_mem->cv_cvals[is] = ONE; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[is] = ONE; cv_mem->cv_atolQSmin0[is] = (atolmin[is] == ZERO); } free(atolmin); - retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - abstolQS, cv_mem->cv_VabstolQS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, abstolQS, + cv_mem->cv_VabstolQS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -int CVodeQuadSensEEtolerances(void *cvode_mem) +int CVodeQuadSensEEtolerances(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeQuadSensEEtolerances", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* check if sensitivity was initialized */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeQuadSensEEtolerances", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } /* Ckeck if quadrature sensitivity was initialized? */ - if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", - "CVodeQuadSensEEtolerances", MSGCV_NO_QUADSENSI); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUAD); } cv_mem->cv_itolQS = CV_EE; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -2562,23 +2640,23 @@ int CVodeQuadSensEEtolerances(void *cvode_mem) * It does NOT deallocate sensitivity-related memory. */ -int CVodeSensToggleOff(void *cvode_mem) +int CVodeSensToggleOff(void* cvode_mem) { CVodeMem cv_mem; /* Check cvode_mem */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSensToggleOff", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Disable sensitivities */ - cv_mem->cv_sensi = SUNFALSE; + cv_mem->cv_sensi = SUNFALSE; cv_mem->cv_quadr_sensi = SUNFALSE; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -2593,30 +2671,38 @@ int CVodeSensToggleOff(void *cvode_mem) * occurred, or a negative value otherwise. */ -int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g) +int CVodeRootInit(void* cvode_mem, int nrtfn, CVRootFn g) { CVodeMem cv_mem; int i, nrt; /* Check cvode_mem pointer */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeRootInit", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; nrt = (nrtfn < 0) ? 0 : nrtfn; /* If rerunning CVodeRootInit() with a different number of root functions (changing number of gfun components), then free currently held memory resources */ - if ((nrt != cv_mem->cv_nrtfn) && (cv_mem->cv_nrtfn > 0)) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - free(cv_mem->cv_iroots); cv_mem->cv_iroots = NULL; - free(cv_mem->cv_rootdir); cv_mem->cv_rootdir = NULL; - free(cv_mem->cv_gactive); cv_mem->cv_gactive = NULL; + if ((nrt != cv_mem->cv_nrtfn) && (cv_mem->cv_nrtfn > 0)) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + free(cv_mem->cv_iroots); + cv_mem->cv_iroots = NULL; + free(cv_mem->cv_rootdir); + cv_mem->cv_rootdir = NULL; + free(cv_mem->cv_gactive); + cv_mem->cv_gactive = NULL; cv_mem->cv_lrw -= 3 * (cv_mem->cv_nrtfn); cv_mem->cv_liw -= 3 * (cv_mem->cv_nrtfn); @@ -2624,10 +2710,11 @@ int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g) /* If CVodeRootInit() was called with nrtfn == 0, then set cv_nrtfn to zero and cv_gfun to NULL before returning */ - if (nrt == 0) { + if (nrt == 0) + { cv_mem->cv_nrtfn = nrt; - cv_mem->cv_gfun = NULL; - return(CV_SUCCESS); + cv_mem->cv_gfun = NULL; + return (CV_SUCCESS); } /* If rerunning CVodeRootInit() with the same number of root functions @@ -2635,114 +2722,146 @@ int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g) function argument has changed */ /* If g != NULL then return as currently reserved memory resources will suffice */ - if (nrt == cv_mem->cv_nrtfn) { - if (g != cv_mem->cv_gfun) { - if (g == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - free(cv_mem->cv_iroots); cv_mem->cv_iroots = NULL; - free(cv_mem->cv_rootdir); cv_mem->cv_rootdir = NULL; - free(cv_mem->cv_gactive); cv_mem->cv_gactive = NULL; - - cv_mem->cv_lrw -= 3*nrt; - cv_mem->cv_liw -= 3*nrt; - - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeRootInit", + if (nrt == cv_mem->cv_nrtfn) + { + if (g != cv_mem->cv_gfun) + { + if (g == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + free(cv_mem->cv_iroots); + cv_mem->cv_iroots = NULL; + free(cv_mem->cv_rootdir); + cv_mem->cv_rootdir = NULL; + free(cv_mem->cv_gactive); + cv_mem->cv_gactive = NULL; + + cv_mem->cv_lrw -= 3 * nrt; + cv_mem->cv_liw -= 3 * nrt; + + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_G); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - else { + else + { cv_mem->cv_gfun = g; - return(CV_SUCCESS); + return (CV_SUCCESS); } } - else return(CV_SUCCESS); + else { return (CV_SUCCESS); } } /* Set variable values in CVode memory block */ cv_mem->cv_nrtfn = nrt; - if (g == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeRootInit", + if (g == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_G); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - else cv_mem->cv_gfun = g; + else { cv_mem->cv_gfun = g; } /* Allocate necessary memory and return */ cv_mem->cv_glo = NULL; - cv_mem->cv_glo = (realtype *) malloc(nrt*sizeof(realtype)); - if (cv_mem->cv_glo == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_glo = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (cv_mem->cv_glo == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->cv_ghi = NULL; - cv_mem->cv_ghi = (realtype *) malloc(nrt*sizeof(realtype)); - if (cv_mem->cv_ghi == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_ghi = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (cv_mem->cv_ghi == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->cv_grout = NULL; - cv_mem->cv_grout = (realtype *) malloc(nrt*sizeof(realtype)); - if (cv_mem->cv_grout == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_grout = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (cv_mem->cv_grout == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->cv_iroots = NULL; - cv_mem->cv_iroots = (int *) malloc(nrt*sizeof(int)); - if (cv_mem->cv_iroots == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_iroots = (int*)malloc(nrt * sizeof(int)); + if (cv_mem->cv_iroots == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->cv_rootdir = NULL; - cv_mem->cv_rootdir = (int *) malloc(nrt*sizeof(int)); - if (cv_mem->cv_rootdir == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - free(cv_mem->cv_iroots); cv_mem->cv_iroots = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_rootdir = (int*)malloc(nrt * sizeof(int)); + if (cv_mem->cv_rootdir == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + free(cv_mem->cv_iroots); + cv_mem->cv_iroots = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->cv_gactive = NULL; - cv_mem->cv_gactive = (booleantype *) malloc(nrt*sizeof(booleantype)); - if (cv_mem->cv_gactive == NULL) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - free(cv_mem->cv_iroots); cv_mem->cv_iroots = NULL; - free(cv_mem->cv_rootdir); cv_mem->cv_rootdir = NULL; - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeRootInit", + cv_mem->cv_gactive = (sunbooleantype*)malloc(nrt * sizeof(sunbooleantype)); + if (cv_mem->cv_gactive == NULL) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + free(cv_mem->cv_iroots); + cv_mem->cv_iroots = NULL; + free(cv_mem->cv_rootdir); + cv_mem->cv_rootdir = NULL; + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + return (CV_MEM_FAIL); } /* Set default values for rootdir (both directions) */ - for(i=0; icv_rootdir[i] = 0; + for (i = 0; i < nrt; i++) { cv_mem->cv_rootdir[i] = 0; } /* Set default values for gactive (all active) */ - for(i=0; icv_gactive[i] = SUNTRUE; + for (i = 0; i < nrt; i++) { cv_mem->cv_gactive[i] = SUNTRUE; } - cv_mem->cv_lrw += 3*nrt; - cv_mem->cv_liw += 3*nrt; + cv_mem->cv_lrw += 3 * nrt; + cv_mem->cv_liw += 3 * nrt; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -2768,14 +2887,14 @@ int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g) * In the CV_ONE_STEP mode, it takes one internal step and returns. */ -int CVode(void *cvode_mem, realtype tout, N_Vector yout, - realtype *tret, int itask) +int CVode(void* cvode_mem, sunrealtype tout, N_Vector yout, sunrealtype* tret, + int itask) { CVodeMem cv_mem; long int nstloc; int retval, hflag, kflag, istate, is, ir, ier, irfndp; - realtype troundoff, tout_hin, rh, nrm; - booleantype inactive_roots; + sunrealtype troundoff, tout_hin, rh, nrm; + sunbooleantype inactive_roots; /* * ------------------------------------- @@ -2784,37 +2903,52 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, */ /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVode", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); /* Check if cvode_mem was allocated */ - if (cv_mem->cv_MallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVode", MSGCV_NO_MALLOC); - return(CV_NO_MALLOC); + if (cv_mem->cv_MallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_MALLOC, __LINE__, __func__, __FILE__, + MSGCV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_MALLOC); } /* Check for yout != NULL */ - if ((cv_mem->cv_y = yout) == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_YOUT_NULL); - return(CV_ILL_INPUT); + if ((cv_mem->cv_y = yout) == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_YOUT_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Check for tret != NULL */ - if (tret == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_TRET_NULL); - return(CV_ILL_INPUT); + if (tret == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } /* Check for valid itask */ - if ( (itask != CV_NORMAL) && (itask != CV_ONE_STEP) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_ITASK); - return(CV_ILL_INPUT); + if ((itask != CV_NORMAL) && (itask != CV_ONE_STEP)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - if (itask == CV_NORMAL) cv_mem->cv_toutc = tout; + if (itask == CV_NORMAL) { cv_mem->cv_toutc = tout; } cv_mem->cv_taskc = itask; /* @@ -2829,14 +2963,18 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, * ---------------------------------------- */ - if (cv_mem->cv_nst == 0) { - + if (cv_mem->cv_nst == 0) + { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; /* Check inputs for corectness */ ier = cvInitialSetup(cv_mem); - if (ier!= CV_SUCCESS) return(ier); + if (ier != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (ier); + } /* * Call f at (t0,y0), set zn[1] = y'(t0). @@ -2845,109 +2983,148 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, * If computing quadr. sensi., call fQS at (t0,y0,yS0), set znQS[1][is] = yQS'(t0), is=1,...,Ns. */ - retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_zn[0], - cv_mem->cv_zn[1], cv_mem->cv_user_data); + retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_zn[1], + cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) { - cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODES", "CVode", + if (retval < 0) + { + cvProcessError(cv_mem, CV_RHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); - return(CV_RHSFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_RHSFUNC_FAIL); } - if (retval > 0) { - cvProcessError(cv_mem, CV_FIRST_RHSFUNC_ERR, "CVODES", "CVode", + if (retval > 0) + { + cvProcessError(cv_mem, CV_FIRST_RHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_RHSFUNC_FIRST); - return(CV_FIRST_RHSFUNC_ERR); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_FIRST_RHSFUNC_ERR); } - if (cv_mem->cv_quadr) { - retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_zn[0], - cv_mem->cv_znQ[1], cv_mem->cv_user_data); + if (cv_mem->cv_quadr) + { + retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_znQ[1], + cv_mem->cv_user_data); cv_mem->cv_nfQe++; - if (retval < 0) { - cvProcessError(cv_mem, CV_QRHSFUNC_FAIL, "CVODES", "CVode", + if (retval < 0) + { + cvProcessError(cv_mem, CV_QRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_QRHSFUNC_FAILED, cv_mem->cv_tn); - return(CV_QRHSFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_QRHSFUNC_FAIL); } - if (retval > 0) { - cvProcessError(cv_mem, CV_FIRST_QRHSFUNC_ERR, "CVODES", - "CVode", MSGCV_QRHSFUNC_FIRST); - return(CV_FIRST_QRHSFUNC_ERR); + if (retval > 0) + { + cvProcessError(cv_mem, CV_FIRST_QRHSFUNC_ERR, __LINE__, __func__, + __FILE__, MSGCV_QRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_FIRST_QRHSFUNC_ERR); } } - if (cv_mem->cv_sensi) { + if (cv_mem->cv_sensi) + { retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_zn[1], cv_mem->cv_znS[0], cv_mem->cv_znS[1], cv_mem->cv_tempv, cv_mem->cv_ftemp); - if (retval < 0) { - cvProcessError(cv_mem, CV_SRHSFUNC_FAIL, "CVODES", "CVode", + if (retval < 0) + { + cvProcessError(cv_mem, CV_SRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_SRHSFUNC_FAILED, cv_mem->cv_tn); - return(CV_SRHSFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SRHSFUNC_FAIL); } - if (retval > 0) { - cvProcessError(cv_mem, CV_FIRST_SRHSFUNC_ERR, "CVODES", - "CVode", MSGCV_SRHSFUNC_FIRST); - return(CV_FIRST_SRHSFUNC_ERR); + if (retval > 0) + { + cvProcessError(cv_mem, CV_FIRST_SRHSFUNC_ERR, __LINE__, __func__, + __FILE__, MSGCV_SRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_FIRST_SRHSFUNC_ERR); } } - if (cv_mem->cv_quadr_sensi) { + if (cv_mem->cv_quadr_sensi) + { retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_znS[0], cv_mem->cv_znQ[1], cv_mem->cv_znQS[1], cv_mem->cv_fQS_data, cv_mem->cv_tempv, cv_mem->cv_tempvQ); cv_mem->cv_nfQSe++; - if (retval < 0) { - cvProcessError(cv_mem, CV_QSRHSFUNC_FAIL, "CVODES", "CVode", + if (retval < 0) + { + cvProcessError(cv_mem, CV_QSRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_QSRHSFUNC_FAILED, cv_mem->cv_tn); - return(CV_QSRHSFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_QSRHSFUNC_FAIL); } - if (retval > 0) { - cvProcessError(cv_mem, CV_FIRST_QSRHSFUNC_ERR, "CVODES", - "CVode", MSGCV_QSRHSFUNC_FIRST); - return(CV_FIRST_QSRHSFUNC_ERR); + if (retval > 0) + { + cvProcessError(cv_mem, CV_FIRST_QSRHSFUNC_ERR, __LINE__, __func__, + __FILE__, MSGCV_QSRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_FIRST_QSRHSFUNC_ERR); } } /* Test input tstop for legality. */ - if (cv_mem->cv_tstopset) { - if ( (cv_mem->cv_tstop - cv_mem->cv_tn)*(tout - cv_mem->cv_tn) <= ZERO ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + if (cv_mem->cv_tstopset) + { + if ((cv_mem->cv_tstop - cv_mem->cv_tn) * (tout - cv_mem->cv_tn) <= ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); - return(CV_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } } /* Set initial h (from H0 or cvHin). */ cv_mem->cv_h = cv_mem->cv_hin; - if ( (cv_mem->cv_h != ZERO) && ((tout-cv_mem->cv_tn)*cv_mem->cv_h < ZERO) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_H0); - return(CV_ILL_INPUT); + if ((cv_mem->cv_h != ZERO) && ((tout - cv_mem->cv_tn) * cv_mem->cv_h < ZERO)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_H0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - if (cv_mem->cv_h == ZERO) { + if (cv_mem->cv_h == ZERO) + { tout_hin = tout; - if ( cv_mem->cv_tstopset && - (tout-cv_mem->cv_tn)*(tout-cv_mem->cv_tstop) > ZERO ) + if (cv_mem->cv_tstopset && + (tout - cv_mem->cv_tn) * (tout - cv_mem->cv_tstop) > ZERO) + { tout_hin = cv_mem->cv_tstop; + } hflag = cvHin(cv_mem, tout_hin); - if (hflag != CV_SUCCESS) { + if (hflag != CV_SUCCESS) + { istate = cvHandleFailure(cv_mem, hflag); - return(istate); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (istate); } } - rh = SUNRabs(cv_mem->cv_h)*cv_mem->cv_hmax_inv; - if (rh > ONE) cv_mem->cv_h /= rh; + + /* Enforce hmax and hmin */ + + rh = SUNRabs(cv_mem->cv_h) * cv_mem->cv_hmax_inv; + if (rh > ONE) { cv_mem->cv_h /= rh; } if (SUNRabs(cv_mem->cv_h) < cv_mem->cv_hmin) - cv_mem->cv_h *= cv_mem->cv_hmin/SUNRabs(cv_mem->cv_h); + { + cv_mem->cv_h *= cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h); + } /* Check for approach to tstop */ - if (cv_mem->cv_tstopset) { - if ( (cv_mem->cv_tn + cv_mem->cv_h - cv_mem->cv_tstop)*cv_mem->cv_h > ZERO ) - cv_mem->cv_h = (cv_mem->cv_tstop - cv_mem->cv_tn)*(ONE-FOUR*cv_mem->cv_uround); + if (cv_mem->cv_tstopset) + { + if ((cv_mem->cv_tn + cv_mem->cv_h - cv_mem->cv_tstop) * cv_mem->cv_h > ZERO) + { + cv_mem->cv_h = (cv_mem->cv_tstop - cv_mem->cv_tn) * + (ONE - FOUR * cv_mem->cv_uround); + } } /* @@ -2964,38 +3141,55 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, N_VScale(cv_mem->cv_h, cv_mem->cv_zn[1], cv_mem->cv_zn[1]); if (cv_mem->cv_quadr) + { N_VScale(cv_mem->cv_h, cv_mem->cv_znQ[1], cv_mem->cv_znQ[1]); + } - if (cv_mem->cv_sensi) { - for (is=0; iscv_Ns; is++) + if (cv_mem->cv_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_h; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znS[1], cv_mem->cv_znS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } } - if (cv_mem->cv_quadr_sensi) { - for (is=0; iscv_Ns; is++) + if (cv_mem->cv_quadr_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_h; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znQS[1], cv_mem->cv_znQS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } } /* Check for zeros of root function g at and near t0. */ - if (cv_mem->cv_nrtfn > 0) { - + if (cv_mem->cv_nrtfn > 0) + { retval = cvRcheck1(cv_mem); - if (retval == CV_RTFUNC_FAIL) { - cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck1", + if (retval == CV_RTFUNC_FAIL) + { + cvProcessError(cv_mem, CV_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RTFUNC_FAILED, cv_mem->cv_tn); - return(CV_RTFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_RTFUNC_FAIL); } - } } /* end of first call block */ @@ -3012,104 +3206,142 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, * ------------------------------------------------------- */ - if (cv_mem->cv_nst > 0) { - + if (cv_mem->cv_nst > 0) + { /* Estimate an infinitesimal time interval to be used as a roundoff for time quantities (based on current time and step size) */ troundoff = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); /* First, check for a root in the last step taken, other than the last root found, if any. If itask = CV_ONE_STEP and y(tn) was not returned because of an intervening root, return y(tn) now. */ - if (cv_mem->cv_nrtfn > 0) { - + if (cv_mem->cv_nrtfn > 0) + { irfndp = cv_mem->cv_irfnd; retval = cvRcheck2(cv_mem); - if (retval == CLOSERT) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvRcheck2", + if (retval == CLOSERT) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_CLOSE_ROOTS, cv_mem->cv_tlo); - return(CV_ILL_INPUT); - } else if (retval == CV_RTFUNC_FAIL) { - cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck2", + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); + } + else if (retval == CV_RTFUNC_FAIL) + { + cvProcessError(cv_mem, CV_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); - return(CV_RTFUNC_FAIL); - } else if (retval == RTFOUND) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_RTFUNC_FAIL); + } + else if (retval == RTFOUND) + { cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; - return(CV_ROOT_RETURN); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ROOT_RETURN); } /* If tn is distinct from tretlast (within roundoff), check remaining interval for roots */ - if ( SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff ) { - + if (SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff) + { retval = cvRcheck3(cv_mem); - if (retval == CV_SUCCESS) { /* no root found */ + if (retval == CV_SUCCESS) + { /* no root found */ cv_mem->cv_irfnd = 0; - if ((irfndp == 1) && (itask == CV_ONE_STEP)) { + if ((irfndp == 1) && (itask == CV_ONE_STEP)) + { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } - } else if (retval == RTFOUND) { /* a new root was found */ - cv_mem->cv_irfnd = 1; + } + else if (retval == RTFOUND) + { /* a new root was found */ + cv_mem->cv_irfnd = 1; cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; - return(CV_ROOT_RETURN); - } else if (retval == CV_RTFUNC_FAIL) { /* g failed */ - cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck3", + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ROOT_RETURN); + } + else if (retval == CV_RTFUNC_FAIL) + { /* g failed */ + cvProcessError(cv_mem, CV_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); - return(CV_RTFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_RTFUNC_FAIL); } - } } /* end of root stop check */ + /* Test for tn at tstop or near tstop */ + if (cv_mem->cv_tstopset) + { + /* Test for tn at tstop */ + if (SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff) + { + /* Ensure tout >= tstop, otherwise check for tout return below */ + if ((tout - cv_mem->cv_tstop) * cv_mem->cv_h >= ZERO || + SUNRabs(tout - cv_mem->cv_tstop) <= troundoff) + { + if (cv_mem->cv_tstopinterp) + { + ier = CVodeGetDky(cv_mem, cv_mem->cv_tstop, 0, yout); + if (ier != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); + } + } + else { N_VScale(ONE, cv_mem->cv_zn[0], yout); } + cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; + cv_mem->cv_tstopset = SUNFALSE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_TSTOP_RETURN); + } + } + /* If next step would overtake tstop, adjust stepsize */ + else if ((cv_mem->cv_tn + cv_mem->cv_hprime - cv_mem->cv_tstop) * + cv_mem->cv_h > + ZERO) + { + cv_mem->cv_hprime = (cv_mem->cv_tstop - cv_mem->cv_tn) * + (ONE - FOUR * cv_mem->cv_uround); + cv_mem->cv_eta = cv_mem->cv_hprime / cv_mem->cv_h; + } + } + /* In CV_NORMAL mode, test if tout was reached */ - if ( (itask == CV_NORMAL) && ((cv_mem->cv_tn-tout)*cv_mem->cv_h >= ZERO) ) { + if ((itask == CV_NORMAL) && ((cv_mem->cv_tn - tout) * cv_mem->cv_h >= ZERO)) + { cv_mem->cv_tretlast = *tret = tout; - ier = CVodeGetDky(cv_mem, tout, 0, yout); - if (ier != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + ier = CVodeGetDky(cv_mem, tout, 0, yout); + if (ier != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_TOUT, tout); - return(CV_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_ILL_INPUT); } - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* In CV_ONE_STEP mode, test if tn was returned */ - if ( itask == CV_ONE_STEP && - SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff ) { + if (itask == CV_ONE_STEP && + SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff) + { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); - return(CV_SUCCESS); - } - - /* Test for tn at tstop or near tstop */ - if ( cv_mem->cv_tstopset ) { - - if ( SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff ) { - ier = CVodeGetDky(cv_mem, cv_mem->cv_tstop, 0, yout); - if (ier != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", - MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); - return(CV_ILL_INPUT); - } - cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; - cv_mem->cv_tstopset = SUNFALSE; - return(CV_TSTOP_RETURN); - } - - /* If next step would overtake tstop, adjust stepsize */ - if ( (cv_mem->cv_tn + cv_mem->cv_hprime - cv_mem->cv_tstop)*cv_mem->cv_h > ZERO ) { - cv_mem->cv_hprime = (cv_mem->cv_tstop - cv_mem->cv_tn)*(ONE-FOUR*cv_mem->cv_uround); - cv_mem->cv_eta = cv_mem->cv_hprime / cv_mem->cv_h; - } - + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } } /* end stopping tests block */ @@ -3131,72 +3363,83 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, */ nstloc = 0; - for(;;) { - + for (;;) + { cv_mem->cv_next_h = cv_mem->cv_h; cv_mem->cv_next_q = cv_mem->cv_q; /* Reset and check ewt, ewtQ, ewtS */ - if (cv_mem->cv_nst > 0) { - + if (cv_mem->cv_nst > 0) + { ier = cv_mem->cv_efun(cv_mem->cv_zn[0], cv_mem->cv_ewt, cv_mem->cv_e_data); - if(ier != 0) { + if (ier != 0) + { if (cv_mem->cv_itol == CV_WF) - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWT_NOW_FAIL, cv_mem->cv_tn); + } else - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWT_NOW_BAD, cv_mem->cv_tn); + } - istate = CV_ILL_INPUT; + istate = CV_ILL_INPUT; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; } - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { ier = cvQuadEwtSet(cv_mem, cv_mem->cv_znQ[0], cv_mem->cv_ewtQ); - if(ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWTQ_NOW_BAD, cv_mem->cv_tn); - istate = CV_ILL_INPUT; + istate = CV_ILL_INPUT; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; } } - if (cv_mem->cv_sensi) { + if (cv_mem->cv_sensi) + { ier = cvSensEwtSet(cv_mem, cv_mem->cv_znS[0], cv_mem->cv_ewtS); - if (ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWTS_NOW_BAD, cv_mem->cv_tn); - istate = CV_ILL_INPUT; + istate = CV_ILL_INPUT; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; } } - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { ier = cvQuadSensEwtSet(cv_mem, cv_mem->cv_znQS[0], cv_mem->cv_ewtQS); - if (ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWTQS_NOW_BAD, cv_mem->cv_tn); - istate = CV_ILL_INPUT; + istate = CV_ILL_INPUT; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; } } - } /* Check for too many steps */ - if ( (cv_mem->cv_mxstep>0) && (nstloc >= cv_mem->cv_mxstep) ) { - cvProcessError(cv_mem, CV_TOO_MUCH_WORK, "CVODES", "CVode", + if ((cv_mem->cv_mxstep > 0) && (nstloc >= cv_mem->cv_mxstep)) + { + cvProcessError(cv_mem, CV_TOO_MUCH_WORK, __LINE__, __func__, __FILE__, MSGCV_MAX_STEPS, cv_mem->cv_tn); - istate = CV_TOO_MUCH_WORK; + istate = CV_TOO_MUCH_WORK; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; @@ -3204,44 +3447,55 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, /* Check for too much accuracy requested */ nrm = N_VWrmsNorm(cv_mem->cv_zn[0], cv_mem->cv_ewt); - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { nrm = cvQuadUpdateNorm(cv_mem, nrm, cv_mem->cv_znQ[0], cv_mem->cv_ewtQ); } - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { nrm = cvSensUpdateNorm(cv_mem, nrm, cv_mem->cv_znS[0], cv_mem->cv_ewtS); } - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { - nrm = cvQuadSensUpdateNorm(cv_mem, nrm, cv_mem->cv_znQS[0], cv_mem->cv_ewtQS); + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { + nrm = cvQuadSensUpdateNorm(cv_mem, nrm, cv_mem->cv_znQS[0], + cv_mem->cv_ewtQS); } cv_mem->cv_tolsf = cv_mem->cv_uround * nrm; - if (cv_mem->cv_tolsf > ONE) { - cvProcessError(cv_mem, CV_TOO_MUCH_ACC, "CVODES", "CVode", + if (cv_mem->cv_tolsf > ONE) + { + cvProcessError(cv_mem, CV_TOO_MUCH_ACC, __LINE__, __func__, __FILE__, MSGCV_TOO_MUCH_ACC, cv_mem->cv_tn); - istate = CV_TOO_MUCH_ACC; + istate = CV_TOO_MUCH_ACC; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); cv_mem->cv_tolsf *= TWO; break; - } else { - cv_mem->cv_tolsf = ONE; } + else { cv_mem->cv_tolsf = ONE; } /* Check for h below roundoff level in tn */ - if (cv_mem->cv_tn + cv_mem->cv_h == cv_mem->cv_tn) { + if (cv_mem->cv_tn + cv_mem->cv_h == cv_mem->cv_tn) + { cv_mem->cv_nhnil++; if (cv_mem->cv_nhnil <= cv_mem->cv_mxhnil) - cvProcessError(cv_mem, CV_WARNING, "CVODES", "CVode", MSGCV_HNIL, - cv_mem->cv_tn, cv_mem->cv_h); + { + cvProcessError(cv_mem, CV_WARNING, __LINE__, __func__, __FILE__, + MSGCV_HNIL, cv_mem->cv_tn, cv_mem->cv_h); + } if (cv_mem->cv_nhnil == cv_mem->cv_mxhnil) - cvProcessError(cv_mem, CV_WARNING, "CVODES", "CVode", MSGCV_HNIL_DONE); + { + cvProcessError(cv_mem, CV_WARNING, __LINE__, __func__, __FILE__, + MSGCV_HNIL_DONE); + } } /* Call cvStep to take a step */ kflag = cvStep(cv_mem); /* Process failed step cases, and exit loop */ - if (kflag != CV_SUCCESS) { - istate = cvHandleFailure(cv_mem, kflag); + if (kflag != CV_SUCCESS) + { + istate = cvHandleFailure(cv_mem, kflag); cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); break; @@ -3250,25 +3504,31 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, nstloc++; /* If tstop is set and was reached, reset tn = tstop */ - if ( cv_mem->cv_tstopset ) { + if (cv_mem->cv_tstopset) + { troundoff = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); - if ( SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff) + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); + if (SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff) + { cv_mem->cv_tn = cv_mem->cv_tstop; + } } /* Check for root in last step taken. */ - if (cv_mem->cv_nrtfn > 0) { - + if (cv_mem->cv_nrtfn > 0) + { retval = cvRcheck3(cv_mem); - if (retval == RTFOUND) { /* A new root was found */ - cv_mem->cv_irfnd = 1; - istate = CV_ROOT_RETURN; + if (retval == RTFOUND) + { /* A new root was found */ + cv_mem->cv_irfnd = 1; + istate = CV_ROOT_RETURN; cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; break; - } else if (retval == CV_RTFUNC_FAIL) { /* g failed */ - cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck3", + } + else if (retval == CV_RTFUNC_FAIL) + { /* g failed */ + cvProcessError(cv_mem, CV_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); istate = CV_RTFUNC_FAIL; break; @@ -3279,55 +3539,75 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, * as this may indicate a user error in the implementation * of the root function. */ - if (cv_mem->cv_nst==1) { + if (cv_mem->cv_nst == 1) + { inactive_roots = SUNFALSE; - for (ir=0; ircv_nrtfn; ir++) { - if (!cv_mem->cv_gactive[ir]) { + for (ir = 0; ir < cv_mem->cv_nrtfn; ir++) + { + if (!cv_mem->cv_gactive[ir]) + { inactive_roots = SUNTRUE; break; } } - if ((cv_mem->cv_mxgnull > 0) && inactive_roots) { - cvProcessError(cv_mem, CV_WARNING, "CVODES", "CVode", + if ((cv_mem->cv_mxgnull > 0) && inactive_roots) + { + cvProcessError(cv_mem, CV_WARNING, __LINE__, __func__, __FILE__, MSGCV_INACTIVE_ROOTS); } } - - } - - /* In NORMAL mode, check if tout reached */ - if ( (itask == CV_NORMAL) && (cv_mem->cv_tn-tout)*cv_mem->cv_h >= ZERO ) { - istate = CV_SUCCESS; - cv_mem->cv_tretlast = *tret = tout; - (void) CVodeGetDky(cv_mem, tout, 0, yout); - cv_mem->cv_next_q = cv_mem->cv_qprime; - cv_mem->cv_next_h = cv_mem->cv_hprime; - break; } /* Check if tn is at tstop or near tstop */ - if ( cv_mem->cv_tstopset ) { - + if (cv_mem->cv_tstopset) + { troundoff = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); - if ( SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff) { - (void) CVodeGetDky(cv_mem, cv_mem->cv_tstop, 0, yout); - cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; - cv_mem->cv_tstopset = SUNFALSE; - istate = CV_TSTOP_RETURN; - break; + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)); + + /* Test for tn at tstop */ + if (SUNRabs(cv_mem->cv_tn - cv_mem->cv_tstop) <= troundoff) + { + /* Ensure tout >= tstop, otherwise check for tout return below */ + if ((tout - cv_mem->cv_tstop) * cv_mem->cv_h >= ZERO || + SUNRabs(tout - cv_mem->cv_tstop) <= troundoff) + { + if (cv_mem->cv_tstopinterp) + { + (void)CVodeGetDky(cv_mem, cv_mem->cv_tstop, 0, yout); + } + else { N_VScale(ONE, cv_mem->cv_zn[0], yout); } + cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; + cv_mem->cv_tstopset = SUNFALSE; + istate = CV_TSTOP_RETURN; + break; + } } - - if ( (cv_mem->cv_tn + cv_mem->cv_hprime - cv_mem->cv_tstop)*cv_mem->cv_h > ZERO ) { - cv_mem->cv_hprime = (cv_mem->cv_tstop - cv_mem->cv_tn)*(ONE-FOUR*cv_mem->cv_uround); + /* If next step would overtake tstop, adjust stepsize */ + else if ((cv_mem->cv_tn + cv_mem->cv_hprime - cv_mem->cv_tstop) * + cv_mem->cv_h > + ZERO) + { + cv_mem->cv_hprime = (cv_mem->cv_tstop - cv_mem->cv_tn) * + (ONE - FOUR * cv_mem->cv_uround); cv_mem->cv_eta = cv_mem->cv_hprime / cv_mem->cv_h; } + } + /* In NORMAL mode, check if tout reached */ + if ((itask == CV_NORMAL) && (cv_mem->cv_tn - tout) * cv_mem->cv_h >= ZERO) + { + istate = CV_SUCCESS; + cv_mem->cv_tretlast = *tret = tout; + (void)CVodeGetDky(cv_mem, tout, 0, yout); + cv_mem->cv_next_q = cv_mem->cv_qprime; + cv_mem->cv_next_h = cv_mem->cv_hprime; + break; } /* In ONE_STEP mode, copy y and exit loop */ - if (itask == CV_ONE_STEP) { - istate = CV_SUCCESS; + if (itask == CV_ONE_STEP) + { + istate = CV_SUCCESS; cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); cv_mem->cv_next_q = cv_mem->cv_qprime; @@ -3338,16 +3618,21 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, } /* end looping for internal steps */ /* Load optional output */ - if (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED1)) { + if (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED1)) + { cv_mem->cv_nniS = 0; + cv_mem->cv_nnfS = 0; cv_mem->cv_ncfnS = 0; - for (is=0; iscv_Ns; is++) { - cv_mem->cv_nniS += cv_mem->cv_nniS1[is]; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_nniS += cv_mem->cv_nniS1[is]; + cv_mem->cv_nnfS += cv_mem->cv_nnfS1[is]; cv_mem->cv_ncfnS += cv_mem->cv_ncfnS1[is]; } } - return(istate); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (istate); } /* @@ -3355,21 +3640,24 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, * * Computes y based on the current prediction and given correction. */ -int CVodeComputeState(void *cvode_mem, N_Vector ycor, N_Vector y) +int CVodeComputeState(void* cvode_mem, N_Vector ycor, N_Vector y) { CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeComputeState", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, y); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3377,25 +3665,31 @@ int CVodeComputeState(void *cvode_mem, N_Vector ycor, N_Vector y) * * Computes yS based on the current prediction and given correction. */ -int CVodeComputeStateSens(void *cvode_mem, N_Vector *ycorS, N_Vector *yS) +int CVodeComputeStateSens(void* cvode_mem, N_Vector* ycorS, N_Vector* yS) { - int retval; + int retval; CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeComputeStateSens", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, ycorS, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); - return(CV_SUCCESS); + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + ycorS, yS); + if (retval != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } + + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3403,25 +3697,26 @@ int CVodeComputeStateSens(void *cvode_mem, N_Vector *ycorS, N_Vector *yS) * * Computes yS[idx] based on the current prediction and given correction. */ -int CVodeComputeStateSens1(void *cvode_mem, int idx, N_Vector ycorS1, - N_Vector yS1) +int CVodeComputeStateSens1(void* cvode_mem, int idx, N_Vector ycorS1, N_Vector yS1) { CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeComputeStateSens1", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); N_VLinearSum(ONE, cv_mem->cv_znS[0][idx], ONE, ycorS1, yS1); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } - /* * ----------------------------------------------------------------- * Interpolated output and extraction functions @@ -3444,63 +3739,82 @@ int CVodeComputeStateSens1(void *cvode_mem, int idx, N_Vector ycorS1, * may also be called directly by the user. */ -int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) +int CVodeGetDky(void* cvode_mem, sunrealtype t, int k, N_Vector dky) { - realtype s, r; - realtype tfuzz, tp, tn1; + sunrealtype s, r; + sunrealtype tfuzz, tp, tn1; int i, j, nvec, ier; CVodeMem cv_mem; /* Check all inputs for legality */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetDky", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (dky == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetDky", MSGCV_NULL_DKY); - return(CV_BAD_DKY); + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (dky == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, + MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - if ((k < 0) || (k > cv_mem->cv_q)) { - cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetDky", MSGCV_BAD_K); - return(CV_BAD_K); + if ((k < 0) || (k > cv_mem->cv_q)) + { + cvProcessError(cv_mem, CV_BAD_K, __LINE__, __func__, __FILE__, MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_K); } /* Allow for some slack */ tfuzz = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); - if (cv_mem->cv_hu < ZERO) tfuzz = -tfuzz; - tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); + if (cv_mem->cv_hu < ZERO) { tfuzz = -tfuzz; } + tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; tn1 = cv_mem->cv_tn + tfuzz; - if ((t-tp)*(t-tn1) > ZERO) { - cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetDky", MSGCV_BAD_T, - t, cv_mem->cv_tn-cv_mem->cv_hu, cv_mem->cv_tn); - return(CV_BAD_T); + if ((t - tp) * (t - tn1) > ZERO) + { + cvProcessError(cv_mem, CV_BAD_T, __LINE__, __func__, __FILE__, MSGCV_BAD_T, + t, cv_mem->cv_tn - cv_mem->cv_hu, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_T); } /* Sum the differentiated interpolating polynomial */ nvec = 0; s = (t - cv_mem->cv_tn) / cv_mem->cv_h; - for (j=cv_mem->cv_q; j >= k; j--) { + for (j = cv_mem->cv_q; j >= k; j--) + { cv_mem->cv_cvals[nvec] = ONE; - for (i=j; i >= j-k+1; i--) - cv_mem->cv_cvals[nvec] *= i; - for (i=0; i < j-k; i++) - cv_mem->cv_cvals[nvec] *= s; + for (i = j; i >= j - k + 1; i--) { cv_mem->cv_cvals[nvec] *= i; } + for (i = 0; i < j - k; i++) { cv_mem->cv_cvals[nvec] *= s; } cv_mem->cv_Xvecs[nvec] = cv_mem->cv_zn[j]; nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dky); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dky, dky); - return(CV_SUCCESS); + + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3511,22 +3825,26 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) * This is just a wrapper that calls CVodeGetQuadDky with k=0. */ -int CVodeGetQuad(void *cvode_mem, realtype *tret, N_Vector yQout) +int CVodeGetQuad(void* cvode_mem, sunrealtype* tret, N_Vector yQout) { CVodeMem cv_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuad", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); *tret = cv_mem->cv_tretlast; - flag = CVodeGetQuadDky(cvode_mem,cv_mem->cv_tretlast,0,yQout); + flag = CVodeGetQuadDky(cvode_mem, cv_mem->cv_tretlast, 0, yQout); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } /* @@ -3543,68 +3861,89 @@ int CVodeGetQuad(void *cvode_mem, realtype *tret, N_Vector yQout) * computation enabled. */ -int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dkyQ) +int CVodeGetQuadDky(void* cvode_mem, sunrealtype t, int k, N_Vector dkyQ) { - realtype s, r; - realtype tfuzz, tp, tn1; + sunrealtype s, r; + sunrealtype tfuzz, tp, tn1; int i, j, nvec, ier; CVodeMem cv_mem; /* Check all inputs for legality */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadDky", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if(cv_mem->cv_quadr != SUNTRUE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadDky", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (cv_mem->cv_quadr != SUNTRUE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_QUAD); } - if (dkyQ == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetQuadDky", MSGCV_NULL_DKY); - return(CV_BAD_DKY); + if (dkyQ == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, + MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - if ((k < 0) || (k > cv_mem->cv_q)) { - cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetQuadDky", MSGCV_BAD_K); - return(CV_BAD_K); + if ((k < 0) || (k > cv_mem->cv_q)) + { + cvProcessError(cv_mem, CV_BAD_K, __LINE__, __func__, __FILE__, MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_K); } /* Allow for some slack */ tfuzz = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); - if (cv_mem->cv_hu < ZERO) tfuzz = -tfuzz; - tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); + if (cv_mem->cv_hu < ZERO) { tfuzz = -tfuzz; } + tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; tn1 = cv_mem->cv_tn + tfuzz; - if ((t-tp)*(t-tn1) > ZERO) { - cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetQuadDky", MSGCV_BAD_T); - return(CV_BAD_T); + if ((t - tp) * (t - tn1) > ZERO) + { + cvProcessError(cv_mem, CV_BAD_T, __LINE__, __func__, __FILE__, MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_T); } /* Sum the differentiated interpolating polynomial */ nvec = 0; s = (t - cv_mem->cv_tn) / cv_mem->cv_h; - for (j=cv_mem->cv_q; j >= k; j--) { + for (j = cv_mem->cv_q; j >= k; j--) + { cv_mem->cv_cvals[nvec] = ONE; - for (i=j; i >= j-k+1; i--) - cv_mem->cv_cvals[nvec] *= i; - for (i=0; i < j-k; i++) - cv_mem->cv_cvals[nvec] *= s; + for (i = j; i >= j - k + 1; i--) { cv_mem->cv_cvals[nvec] *= i; } + for (i = 0; i < j - k; i++) { cv_mem->cv_cvals[nvec] *= s; } cv_mem->cv_Xvecs[nvec] = cv_mem->cv_znQ[j]; nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyQ); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyQ, dkyQ); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3615,22 +3954,26 @@ int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dkyQ) * This is just a wrapper that calls CVodeSensDky with k=0. */ -int CVodeGetSens(void *cvode_mem, realtype *tret, N_Vector *ySout) +int CVodeGetSens(void* cvode_mem, sunrealtype* tret, N_Vector* ySout) { CVodeMem cv_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSens", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); *tret = cv_mem->cv_tretlast; - flag = CVodeGetSensDky(cvode_mem,cv_mem->cv_tretlast,0,ySout); + flag = CVodeGetSensDky(cvode_mem, cv_mem->cv_tretlast, 0, ySout); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } /* @@ -3641,22 +3984,26 @@ int CVodeGetSens(void *cvode_mem, realtype *tret, N_Vector *ySout) * This is just a wrapper that calls CVodeSensDky1 with k=0. */ -int CVodeGetSens1(void *cvode_mem, realtype *tret, int is, N_Vector ySout) +int CVodeGetSens1(void* cvode_mem, sunrealtype* tret, int is, N_Vector ySout) { CVodeMem cv_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSens1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); *tret = cv_mem->cv_tretlast; - flag = CVodeGetSensDky1(cvode_mem,cv_mem->cv_tretlast,0,is,ySout); + flag = CVodeGetSensDky1(cvode_mem, cv_mem->cv_tretlast, 0, is, ySout); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } /* @@ -3668,30 +4015,37 @@ int CVodeGetSens1(void *cvode_mem, realtype *tret, int is, N_Vector ySout) * ier=CV_BAD_T are possible. */ -int CVodeGetSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyS) +int CVodeGetSensDky(void* cvode_mem, sunrealtype t, int k, N_Vector* dkyS) { - int ier=CV_SUCCESS; + int ier = CV_SUCCESS; int is; CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensDky", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (dkyS == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", - "CVodeGetSensDky", MSGCV_NULL_DKYA); - return(CV_BAD_DKY); + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (dkyS == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, + MSGCV_NULL_DKYA); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - for (is=0; iscv_Ns; is++) { - ier = CVodeGetSensDky1(cvode_mem,t,k,is,dkyS[is]); - if (ier!=CV_SUCCESS) break; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + ier = CVodeGetSensDky1(cvode_mem, t, k, is, dkyS[is]); + if (ier != CV_SUCCESS) { break; } } - return(ier); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (ier); } /* @@ -3708,79 +4062,96 @@ int CVodeGetSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyS) * computation enabled. */ -int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyS) +int CVodeGetSensDky1(void* cvode_mem, sunrealtype t, int k, int is, N_Vector dkyS) { - realtype s, r; - realtype tfuzz, tp, tn1; + sunrealtype s, r; + sunrealtype tfuzz, tp, tn1; int i, j, nvec, ier; CVodeMem cv_mem; /* Check all inputs for legality */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensDky1", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if(cv_mem->cv_sensi != SUNTRUE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensDky1", + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (cv_mem->cv_sensi != SUNTRUE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_NO_SENS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_SENS); } - if (dkyS == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetSensDky1", + if (dkyS == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, MSGCV_NULL_DKY); - return(CV_BAD_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - if ((k < 0) || (k > cv_mem->cv_q)) { - cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetSensDky1", - MSGCV_BAD_K); - return(CV_BAD_K); + if ((k < 0) || (k > cv_mem->cv_q)) + { + cvProcessError(cv_mem, CV_BAD_K, __LINE__, __func__, __FILE__, MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_K); } - if ((is < 0) || (is > cv_mem->cv_Ns-1)) { - cvProcessError(cv_mem, CV_BAD_IS, "CVODES", "CVodeGetSensDky1", - MSGCV_BAD_IS); - return(CV_BAD_IS); + if ((is < 0) || (is > cv_mem->cv_Ns - 1)) + { + cvProcessError(cv_mem, CV_BAD_IS, __LINE__, __func__, __FILE__, MSGCV_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_IS); } /* Allow for some slack */ tfuzz = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); - if (cv_mem->cv_hu < ZERO) tfuzz = -tfuzz; - tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); + if (cv_mem->cv_hu < ZERO) { tfuzz = -tfuzz; } + tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; tn1 = cv_mem->cv_tn + tfuzz; - if ((t-tp)*(t-tn1) > ZERO) { - cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetSensDky1", - MSGCV_BAD_T); - return(CV_BAD_T); + if ((t - tp) * (t - tn1) > ZERO) + { + cvProcessError(cv_mem, CV_BAD_T, __LINE__, __func__, __FILE__, MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_T); } /* Sum the differentiated interpolating polynomial */ nvec = 0; s = (t - cv_mem->cv_tn) / cv_mem->cv_h; - for (j=cv_mem->cv_q; j >= k; j--) { + for (j = cv_mem->cv_q; j >= k; j--) + { cv_mem->cv_cvals[nvec] = ONE; - for (i=j; i >= j-k+1; i--) - cv_mem->cv_cvals[nvec] *= i; - for (i=0; i < j-k; i++) - cv_mem->cv_cvals[nvec] *= s; + for (i = j; i >= j - k + 1; i--) { cv_mem->cv_cvals[nvec] *= i; } + for (i = 0; i < j - k; i++) { cv_mem->cv_cvals[nvec] *= s; } cv_mem->cv_Xvecs[nvec] = cv_mem->cv_znS[j][is]; nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyS); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyS, dkyS); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3790,42 +4161,48 @@ int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyS) * vectors at the time at which CVode returned the ODE solution. */ -int CVodeGetQuadSens(void *cvode_mem, realtype *tret, N_Vector *yQSout) +int CVodeGetQuadSens(void* cvode_mem, sunrealtype* tret, N_Vector* yQSout) { CVodeMem cv_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSens", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); *tret = cv_mem->cv_tretlast; - flag = CVodeGetQuadSensDky(cvode_mem,cv_mem->cv_tretlast,0,yQSout); + flag = CVodeGetQuadSensDky(cvode_mem, cv_mem->cv_tretlast, 0, yQSout); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } -int CVodeGetQuadSens1(void *cvode_mem, realtype *tret, int is, N_Vector yQSout) +int CVodeGetQuadSens1(void* cvode_mem, sunrealtype* tret, int is, N_Vector yQSout) { CVodeMem cv_mem; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSens1", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); *tret = cv_mem->cv_tretlast; - flag = CVodeGetQuadSensDky1(cvode_mem,cv_mem->cv_tretlast,0,is,yQSout); + flag = CVodeGetQuadSensDky1(cvode_mem, cv_mem->cv_tretlast, 0, is, yQSout); - return(flag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (flag); } /* @@ -3835,106 +4212,130 @@ int CVodeGetQuadSens1(void *cvode_mem, realtype *tret, int is, N_Vector yQSout) * vectors (or derivative thereof). */ -int CVodeGetQuadSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyQS_all) +int CVodeGetQuadSensDky(void* cvode_mem, sunrealtype t, int k, N_Vector* dkyQS_all) { - int ier=CV_SUCCESS; + int ier = CV_SUCCESS; int is; CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensDky", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); - if (dkyQS_all == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetSensDky", + if (dkyQS_all == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, MSGCV_NULL_DKYA); - return(CV_BAD_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - for (is=0; iscv_Ns; is++) { - ier = CVodeGetQuadSensDky1(cvode_mem,t,k,is,dkyQS_all[is]); - if (ier!=CV_SUCCESS) break; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + ier = CVodeGetQuadSensDky1(cvode_mem, t, k, is, dkyQS_all[is]); + if (ier != CV_SUCCESS) { break; } } - return(ier); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (ier); } -int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyQS) +int CVodeGetQuadSensDky1(void* cvode_mem, sunrealtype t, int k, int is, + N_Vector dkyQS) { - realtype s, r; - realtype tfuzz, tp, tn1; + sunrealtype s, r; + sunrealtype tfuzz, tp, tn1; int i, j, nvec, ier; CVodeMem cv_mem; /* Check all inputs for legality */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensDky1", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if(cv_mem->cv_quadr_sensi != SUNTRUE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensDky1", + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + + if (cv_mem->cv_quadr_sensi != SUNTRUE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_NO_QUADSENS); } - if (dkyQS == NULL) { - cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetQuadSensDky1", + if (dkyQS == NULL) + { + cvProcessError(cv_mem, CV_BAD_DKY, __LINE__, __func__, __FILE__, MSGCV_NULL_DKY); - return(CV_BAD_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_DKY); } - if ((k < 0) || (k > cv_mem->cv_q)) { - cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetQuadSensDky1", - MSGCV_BAD_K); - return(CV_BAD_K); + if ((k < 0) || (k > cv_mem->cv_q)) + { + cvProcessError(cv_mem, CV_BAD_K, __LINE__, __func__, __FILE__, MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_K); } - if ((is < 0) || (is > cv_mem->cv_Ns-1)) { - cvProcessError(cv_mem, CV_BAD_IS, "CVODES", "CVodeGetQuadSensDky1", - MSGCV_BAD_IS); - return(CV_BAD_IS); + if ((is < 0) || (is > cv_mem->cv_Ns - 1)) + { + cvProcessError(cv_mem, CV_BAD_IS, __LINE__, __func__, __FILE__, MSGCV_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_IS); } /* Allow for some slack */ tfuzz = FUZZ_FACTOR * cv_mem->cv_uround * - (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); - if (cv_mem->cv_hu < ZERO) tfuzz = -tfuzz; - tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; + (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_hu)); + if (cv_mem->cv_hu < ZERO) { tfuzz = -tfuzz; } + tp = cv_mem->cv_tn - cv_mem->cv_hu - tfuzz; tn1 = cv_mem->cv_tn + tfuzz; - if ((t-tp)*(t-tn1) > ZERO) { - cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetQuadSensDky1", - MSGCV_BAD_T); - return(CV_BAD_T); + if ((t - tp) * (t - tn1) > ZERO) + { + cvProcessError(cv_mem, CV_BAD_T, __LINE__, __func__, __FILE__, MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_BAD_T); } /* Sum the differentiated interpolating polynomial */ nvec = 0; s = (t - cv_mem->cv_tn) / cv_mem->cv_h; - for (j=cv_mem->cv_q; j >= k; j--) { + for (j = cv_mem->cv_q; j >= k; j--) + { cv_mem->cv_cvals[nvec] = ONE; - for (i=j; i >= j-k+1; i--) - cv_mem->cv_cvals[nvec] *= i; - for (i=0; i < j-k; i++) - cv_mem->cv_cvals[nvec] *= s; + for (i = j; i >= j - k + 1; i--) { cv_mem->cv_cvals[nvec] *= i; } + for (i = 0; i < j - k; i++) { cv_mem->cv_cvals[nvec] *= s; } cv_mem->cv_Xvecs[nvec] = cv_mem->cv_znQS[j][is]; nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyQS); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) + { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyQS, dkyQS); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_SUCCESS); } /* @@ -3953,21 +4354,22 @@ int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dk * sensitivity computations by CVodeSensInit. */ -void CVodeFree(void **cvode_mem) +void CVodeFree(void** cvode_mem) { CVodeMem cv_mem; - if (*cvode_mem == NULL) return; + if (*cvode_mem == NULL) { return; } - cv_mem = (CVodeMem) (*cvode_mem); + cv_mem = (CVodeMem)(*cvode_mem); cvFreeVectors(cv_mem); /* if CVODE created the nonlinear solver object then free it */ - if (cv_mem->ownNLS) { + if (cv_mem->ownNLS) + { SUNNonlinSolFree(cv_mem->NLS); cv_mem->ownNLS = SUNFALSE; - cv_mem->NLS = NULL; + cv_mem->NLS = NULL; } CVodeQuadFree(cv_mem); @@ -3978,20 +4380,32 @@ void CVodeFree(void **cvode_mem) CVodeAdjFree(cv_mem); - if (cv_mem->cv_lfree != NULL) cv_mem->cv_lfree(cv_mem); - - if (cv_mem->cv_nrtfn > 0) { - free(cv_mem->cv_glo); cv_mem->cv_glo = NULL; - free(cv_mem->cv_ghi); cv_mem->cv_ghi = NULL; - free(cv_mem->cv_grout); cv_mem->cv_grout = NULL; - free(cv_mem->cv_iroots); cv_mem->cv_iroots = NULL; - free(cv_mem->cv_rootdir); cv_mem->cv_rootdir = NULL; - free(cv_mem->cv_gactive); cv_mem->cv_gactive = NULL; - } + if (cv_mem->cv_lfree != NULL) { cv_mem->cv_lfree(cv_mem); } + + if (cv_mem->cv_nrtfn > 0) + { + free(cv_mem->cv_glo); + cv_mem->cv_glo = NULL; + free(cv_mem->cv_ghi); + cv_mem->cv_ghi = NULL; + free(cv_mem->cv_grout); + cv_mem->cv_grout = NULL; + free(cv_mem->cv_iroots); + cv_mem->cv_iroots = NULL; + free(cv_mem->cv_rootdir); + cv_mem->cv_rootdir = NULL; + free(cv_mem->cv_gactive); + cv_mem->cv_gactive = NULL; + } + + free(cv_mem->cv_cvals); + cv_mem->cv_cvals = NULL; + free(cv_mem->cv_Xvecs); + cv_mem->cv_Xvecs = NULL; + free(cv_mem->cv_Zvecs); + cv_mem->cv_Zvecs = NULL; - free(cv_mem->cv_cvals); cv_mem->cv_cvals = NULL; - free(cv_mem->cv_Xvecs); cv_mem->cv_Xvecs = NULL; - free(cv_mem->cv_Zvecs); cv_mem->cv_Zvecs = NULL; + if (cv_mem->proj_mem) { cvProjFree(&(cv_mem->proj_mem)); } free(*cvode_mem); *cvode_mem = NULL; @@ -4005,17 +4419,18 @@ void CVodeFree(void **cvode_mem) * cvode_mem returned by CVodeCreate. */ -void CVodeQuadFree(void *cvode_mem) +void CVodeQuadFree(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem == NULL) return; - cv_mem = (CVodeMem) cvode_mem; + if (cvode_mem == NULL) { return; } + cv_mem = (CVodeMem)cvode_mem; - if(cv_mem->cv_QuadMallocDone) { + if (cv_mem->cv_QuadMallocDone) + { cvQuadFreeVectors(cv_mem); cv_mem->cv_QuadMallocDone = SUNFALSE; - cv_mem->cv_quadr = SUNFALSE; + cv_mem->cv_quadr = SUNFALSE; } } @@ -4027,58 +4442,77 @@ void CVodeQuadFree(void *cvode_mem) * cvode_mem returned by CVodeCreate. */ -void CVodeSensFree(void *cvode_mem) +void CVodeSensFree(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem == NULL) return; - cv_mem = (CVodeMem) cvode_mem; - - if(cv_mem->cv_SensMallocDone) { - if (cv_mem->cv_stgr1alloc) { - free(cv_mem->cv_ncfS1); cv_mem->cv_ncfS1 = NULL; - free(cv_mem->cv_ncfnS1); cv_mem->cv_ncfnS1 = NULL; - free(cv_mem->cv_nniS1); cv_mem->cv_nniS1 = NULL; + if (cvode_mem == NULL) { return; } + cv_mem = (CVodeMem)cvode_mem; + + if (cv_mem->cv_SensMallocDone) + { + if (cv_mem->cv_stgr1alloc) + { + free(cv_mem->cv_ncfS1); + cv_mem->cv_ncfS1 = NULL; + free(cv_mem->cv_ncfnS1); + cv_mem->cv_ncfnS1 = NULL; + free(cv_mem->cv_nniS1); + cv_mem->cv_nniS1 = NULL; + free(cv_mem->cv_nnfS1); + cv_mem->cv_nnfS1 = NULL; cv_mem->cv_stgr1alloc = SUNFALSE; } cvSensFreeVectors(cv_mem); cv_mem->cv_SensMallocDone = SUNFALSE; - cv_mem->cv_sensi = SUNFALSE; + cv_mem->cv_sensi = SUNFALSE; } /* free any vector wrappers */ - if (cv_mem->simMallocDone) { - N_VDestroy(cv_mem->zn0Sim); cv_mem->zn0Sim = NULL; - N_VDestroy(cv_mem->ycorSim); cv_mem->ycorSim = NULL; - N_VDestroy(cv_mem->ewtSim); cv_mem->ewtSim = NULL; + if (cv_mem->simMallocDone) + { + N_VDestroy(cv_mem->zn0Sim); + cv_mem->zn0Sim = NULL; + N_VDestroy(cv_mem->ycorSim); + cv_mem->ycorSim = NULL; + N_VDestroy(cv_mem->ewtSim); + cv_mem->ewtSim = NULL; cv_mem->simMallocDone = SUNFALSE; } - if (cv_mem->stgMallocDone) { - N_VDestroy(cv_mem->zn0Stg); cv_mem->zn0Stg = NULL; - N_VDestroy(cv_mem->ycorStg); cv_mem->ycorStg = NULL; - N_VDestroy(cv_mem->ewtStg); cv_mem->ewtStg = NULL; + if (cv_mem->stgMallocDone) + { + N_VDestroy(cv_mem->zn0Stg); + cv_mem->zn0Stg = NULL; + N_VDestroy(cv_mem->ycorStg); + cv_mem->ycorStg = NULL; + N_VDestroy(cv_mem->ewtStg); + cv_mem->ewtStg = NULL; cv_mem->stgMallocDone = SUNFALSE; } /* if CVODES created a NLS object then free it */ - if (cv_mem->ownNLSsim) { + if (cv_mem->ownNLSsim) + { SUNNonlinSolFree(cv_mem->NLSsim); cv_mem->ownNLSsim = SUNFALSE; - cv_mem->NLSsim = NULL; + cv_mem->NLSsim = NULL; } - if (cv_mem->ownNLSstg) { + if (cv_mem->ownNLSstg) + { SUNNonlinSolFree(cv_mem->NLSstg); cv_mem->ownNLSstg = SUNFALSE; - cv_mem->NLSstg = NULL; + cv_mem->NLSstg = NULL; } - if (cv_mem->ownNLSstg1) { + if (cv_mem->ownNLSstg1) + { SUNNonlinSolFree(cv_mem->NLSstg1); cv_mem->ownNLSstg1 = SUNFALSE; - cv_mem->NLSstg1 = NULL; + cv_mem->NLSstg1 = NULL; } /* free min atol array if necessary */ - if (cv_mem->cv_atolSmin0) { + if (cv_mem->cv_atolSmin0) + { free(cv_mem->cv_atolSmin0); cv_mem->cv_atolSmin0 = NULL; } @@ -4092,27 +4526,28 @@ void CVodeSensFree(void *cvode_mem) * cvode_mem returned by CVodeCreate. */ -void CVodeQuadSensFree(void *cvode_mem) +void CVodeQuadSensFree(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem == NULL) return; - cv_mem = (CVodeMem) cvode_mem; + if (cvode_mem == NULL) { return; } + cv_mem = (CVodeMem)cvode_mem; - if(cv_mem->cv_QuadSensMallocDone) { + if (cv_mem->cv_QuadSensMallocDone) + { cvQuadSensFreeVectors(cv_mem); cv_mem->cv_QuadSensMallocDone = SUNFALSE; - cv_mem->cv_quadr_sensi = SUNFALSE; + cv_mem->cv_quadr_sensi = SUNFALSE; } /* free min atol array if necessary */ - if (cv_mem->cv_atolQSmin0) { + if (cv_mem->cv_atolQSmin0) + { free(cv_mem->cv_atolQSmin0); cv_mem->cv_atolQSmin0 = NULL; } } - /* * ================================================================= * Private Functions Implementation @@ -4125,23 +4560,18 @@ void CVodeQuadSensFree(void *cvode_mem) * If any of them is missing it returns SUNFALSE. */ -static booleantype cvCheckNvector(N_Vector tmpl) +static sunbooleantype cvCheckNvector(N_Vector tmpl) { - if((tmpl->ops->nvclone == NULL) || - (tmpl->ops->nvdestroy == NULL) || - (tmpl->ops->nvlinearsum == NULL) || - (tmpl->ops->nvconst == NULL) || - (tmpl->ops->nvprod == NULL) || - (tmpl->ops->nvdiv == NULL) || - (tmpl->ops->nvscale == NULL) || - (tmpl->ops->nvabs == NULL) || - (tmpl->ops->nvinv == NULL) || - (tmpl->ops->nvaddconst == NULL) || - (tmpl->ops->nvmaxnorm == NULL) || - (tmpl->ops->nvwrmsnorm == NULL)) - return(SUNFALSE); - else - return(SUNTRUE); + if ((tmpl->ops->nvclone == NULL) || (tmpl->ops->nvdestroy == NULL) || + (tmpl->ops->nvlinearsum == NULL) || (tmpl->ops->nvconst == NULL) || + (tmpl->ops->nvprod == NULL) || (tmpl->ops->nvdiv == NULL) || + (tmpl->ops->nvscale == NULL) || (tmpl->ops->nvabs == NULL) || + (tmpl->ops->nvinv == NULL) || (tmpl->ops->nvaddconst == NULL) || + (tmpl->ops->nvmaxnorm == NULL) || (tmpl->ops->nvwrmsnorm == NULL)) + { + return (SUNFALSE); + } + else { return (SUNTRUE); } } /* @@ -4162,71 +4592,79 @@ static booleantype cvCheckNvector(N_Vector tmpl) * allocated here. */ -static booleantype cvAllocVectors(CVodeMem cv_mem, N_Vector tmpl) +static sunbooleantype cvAllocVectors(CVodeMem cv_mem, N_Vector tmpl) { int i, j; /* Allocate ewt, acor, tempv, ftemp */ cv_mem->cv_ewt = N_VClone(tmpl); - if (cv_mem->cv_ewt == NULL) return(SUNFALSE); + if (cv_mem->cv_ewt == NULL) { return (SUNFALSE); } cv_mem->cv_acor = N_VClone(tmpl); - if (cv_mem->cv_acor == NULL) { + if (cv_mem->cv_acor == NULL) + { N_VDestroy(cv_mem->cv_ewt); - return(SUNFALSE); + return (SUNFALSE); } cv_mem->cv_tempv = N_VClone(tmpl); - if (cv_mem->cv_tempv == NULL) { + if (cv_mem->cv_tempv == NULL) + { N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); - return(SUNFALSE); + return (SUNFALSE); } cv_mem->cv_ftemp = N_VClone(tmpl); - if (cv_mem->cv_ftemp == NULL) { + if (cv_mem->cv_ftemp == NULL) + { N_VDestroy(cv_mem->cv_tempv); N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); - return(SUNFALSE); + return (SUNFALSE); } cv_mem->cv_vtemp1 = N_VClone(tmpl); - if (cv_mem->cv_vtemp1 == NULL) { + if (cv_mem->cv_vtemp1 == NULL) + { N_VDestroy(cv_mem->cv_ftemp); N_VDestroy(cv_mem->cv_tempv); N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); - return(SUNFALSE); + return (SUNFALSE); } cv_mem->cv_vtemp2 = N_VClone(tmpl); - if (cv_mem->cv_vtemp2 == NULL) { + if (cv_mem->cv_vtemp2 == NULL) + { N_VDestroy(cv_mem->cv_vtemp1); N_VDestroy(cv_mem->cv_ftemp); N_VDestroy(cv_mem->cv_tempv); N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); - return(SUNFALSE); + return (SUNFALSE); } cv_mem->cv_vtemp3 = N_VClone(tmpl); - if (cv_mem->cv_vtemp3 == NULL) { + if (cv_mem->cv_vtemp3 == NULL) + { N_VDestroy(cv_mem->cv_vtemp2); N_VDestroy(cv_mem->cv_vtemp1); N_VDestroy(cv_mem->cv_ftemp); N_VDestroy(cv_mem->cv_tempv); N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate zn[0] ... zn[qmax] */ - for (j=0; j <= cv_mem->cv_qmax; j++) { + for (j = 0; j <= cv_mem->cv_qmax; j++) + { cv_mem->cv_zn[j] = N_VClone(tmpl); - if (cv_mem->cv_zn[j] == NULL) { + if (cv_mem->cv_zn[j] == NULL) + { N_VDestroy(cv_mem->cv_ewt); N_VDestroy(cv_mem->cv_acor); N_VDestroy(cv_mem->cv_tempv); @@ -4234,19 +4672,19 @@ static booleantype cvAllocVectors(CVodeMem cv_mem, N_Vector tmpl) N_VDestroy(cv_mem->cv_vtemp1); N_VDestroy(cv_mem->cv_vtemp2); N_VDestroy(cv_mem->cv_vtemp3); - for (i=0; i < j; i++) N_VDestroy(cv_mem->cv_zn[i]); - return(SUNFALSE); + for (i = 0; i < j; i++) { N_VDestroy(cv_mem->cv_zn[i]); } + return (SUNFALSE); } } /* Update solver workspace lengths */ - cv_mem->cv_lrw += (cv_mem->cv_qmax + 8)*cv_mem->cv_lrw1; - cv_mem->cv_liw += (cv_mem->cv_qmax + 8)*cv_mem->cv_liw1; + cv_mem->cv_lrw += (cv_mem->cv_qmax + 8) * cv_mem->cv_lrw1; + cv_mem->cv_liw += (cv_mem->cv_qmax + 8) * cv_mem->cv_liw1; /* Store the value of qmax used here */ cv_mem->cv_qmax_alloc = cv_mem->cv_qmax; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -4268,18 +4706,20 @@ static void cvFreeVectors(CVodeMem cv_mem) N_VDestroy(cv_mem->cv_vtemp1); N_VDestroy(cv_mem->cv_vtemp2); N_VDestroy(cv_mem->cv_vtemp3); - for (j=0; j <= maxord; j++) N_VDestroy(cv_mem->cv_zn[j]); + for (j = 0; j <= maxord; j++) { N_VDestroy(cv_mem->cv_zn[j]); } - cv_mem->cv_lrw -= (maxord + 8)*cv_mem->cv_lrw1; - cv_mem->cv_liw -= (maxord + 8)*cv_mem->cv_liw1; + cv_mem->cv_lrw -= (maxord + 8) * cv_mem->cv_lrw1; + cv_mem->cv_liw -= (maxord + 8) * cv_mem->cv_liw1; - if (cv_mem->cv_VabstolMallocDone) { + if (cv_mem->cv_VabstolMallocDone) + { N_VDestroy(cv_mem->cv_Vabstol); cv_mem->cv_lrw -= cv_mem->cv_lrw1; cv_mem->cv_liw -= cv_mem->cv_liw1; } - if (cv_mem->cv_constraintsMallocDone) { + if (cv_mem->cv_constraintsMallocDone) + { N_VDestroy(cv_mem->cv_constraints); cv_mem->cv_lrw -= cv_mem->cv_lrw1; cv_mem->cv_liw -= cv_mem->cv_liw1; @@ -4297,51 +4737,54 @@ static void cvFreeVectors(CVodeMem cv_mem) * CVodeQuadReInit. */ -static booleantype cvQuadAllocVectors(CVodeMem cv_mem, N_Vector tmpl) +static sunbooleantype cvQuadAllocVectors(CVodeMem cv_mem, N_Vector tmpl) { int i, j; /* Allocate ewtQ */ cv_mem->cv_ewtQ = N_VClone(tmpl); - if (cv_mem->cv_ewtQ == NULL) { - return(SUNFALSE); - } + if (cv_mem->cv_ewtQ == NULL) { return (SUNFALSE); } /* Allocate acorQ */ cv_mem->cv_acorQ = N_VClone(tmpl); - if (cv_mem->cv_acorQ == NULL) { + if (cv_mem->cv_acorQ == NULL) + { N_VDestroy(cv_mem->cv_ewtQ); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate yQ */ cv_mem->cv_yQ = N_VClone(tmpl); - if (cv_mem->cv_yQ == NULL) { + if (cv_mem->cv_yQ == NULL) + { N_VDestroy(cv_mem->cv_ewtQ); N_VDestroy(cv_mem->cv_acorQ); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate tempvQ */ cv_mem->cv_tempvQ = N_VClone(tmpl); - if (cv_mem->cv_tempvQ == NULL) { + if (cv_mem->cv_tempvQ == NULL) + { N_VDestroy(cv_mem->cv_ewtQ); N_VDestroy(cv_mem->cv_acorQ); N_VDestroy(cv_mem->cv_yQ); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate zQn[0] ... zQn[maxord] */ - for (j=0; j <= cv_mem->cv_qmax; j++) { + for (j = 0; j <= cv_mem->cv_qmax; j++) + { cv_mem->cv_znQ[j] = N_VClone(tmpl); - if (cv_mem->cv_znQ[j] == NULL) { + if (cv_mem->cv_znQ[j] == NULL) + { N_VDestroy(cv_mem->cv_ewtQ); N_VDestroy(cv_mem->cv_acorQ); N_VDestroy(cv_mem->cv_yQ); N_VDestroy(cv_mem->cv_tempvQ); - for (i=0; i < j; i++) N_VDestroy(cv_mem->cv_znQ[i]); - return(SUNFALSE); + for (i = 0; i < j; i++) { N_VDestroy(cv_mem->cv_znQ[i]); } + return (SUNFALSE); } } @@ -4349,10 +4792,10 @@ static booleantype cvQuadAllocVectors(CVodeMem cv_mem, N_Vector tmpl) cv_mem->cv_qmax_allocQ = cv_mem->cv_qmax; /* Update solver workspace lengths */ - cv_mem->cv_lrw += (cv_mem->cv_qmax + 5)*cv_mem->cv_lrw1Q; - cv_mem->cv_liw += (cv_mem->cv_qmax + 5)*cv_mem->cv_liw1Q; + cv_mem->cv_lrw += (cv_mem->cv_qmax + 5) * cv_mem->cv_lrw1Q; + cv_mem->cv_liw += (cv_mem->cv_qmax + 5) * cv_mem->cv_liw1Q; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -4372,12 +4815,13 @@ static void cvQuadFreeVectors(CVodeMem cv_mem) N_VDestroy(cv_mem->cv_yQ); N_VDestroy(cv_mem->cv_tempvQ); - for (j=0; j<=maxord; j++) N_VDestroy(cv_mem->cv_znQ[j]); + for (j = 0; j <= maxord; j++) { N_VDestroy(cv_mem->cv_znQ[j]); } - cv_mem->cv_lrw -= (maxord + 5)*cv_mem->cv_lrw1Q; - cv_mem->cv_liw -= (maxord + 5)*cv_mem->cv_liw1Q; + cv_mem->cv_lrw -= (maxord + 5) * cv_mem->cv_lrw1Q; + cv_mem->cv_liw -= (maxord + 5) * cv_mem->cv_liw1Q; - if (cv_mem->cv_VabstolQMallocDone) { + if (cv_mem->cv_VabstolQMallocDone) + { N_VDestroy(cv_mem->cv_VabstolQ); cv_mem->cv_lrw -= cv_mem->cv_lrw1Q; cv_mem->cv_liw -= cv_mem->cv_liw1Q; @@ -4393,101 +4837,116 @@ static void cvQuadFreeVectors(CVodeMem cv_mem) * using the N_Vector 'tmpl' as a template. */ -static booleantype cvSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl) +static sunbooleantype cvSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl) { int i, j; /* Allocate yS */ cv_mem->cv_yS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_yS == NULL) { - return(SUNFALSE); - } + if (cv_mem->cv_yS == NULL) { return (SUNFALSE); } /* Allocate ewtS */ cv_mem->cv_ewtS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_ewtS == NULL) { + if (cv_mem->cv_ewtS == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate acorS */ cv_mem->cv_acorS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_acorS == NULL) { + if (cv_mem->cv_acorS == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate tempvS */ cv_mem->cv_tempvS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_tempvS == NULL) { + if (cv_mem->cv_tempvS == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate ftempS */ cv_mem->cv_ftempS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_ftempS == NULL) { + if (cv_mem->cv_ftempS == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate znS */ - for (j=0; j<=cv_mem->cv_qmax; j++) { + for (j = 0; j <= cv_mem->cv_qmax; j++) + { cv_mem->cv_znS[j] = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_znS[j] == NULL) { + if (cv_mem->cv_znS[j] == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ftempS, cv_mem->cv_Ns); - for (i=0; icv_znS[i], cv_mem->cv_Ns); - return(SUNFALSE); + } + return (SUNFALSE); } } /* Allocate space for pbar and plist */ cv_mem->cv_pbar = NULL; - cv_mem->cv_pbar = (realtype *)malloc(cv_mem->cv_Ns*sizeof(realtype)); - if (cv_mem->cv_pbar == NULL) { + cv_mem->cv_pbar = (sunrealtype*)malloc(cv_mem->cv_Ns * sizeof(sunrealtype)); + if (cv_mem->cv_pbar == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ftempS, cv_mem->cv_Ns); - for (i=0; i<=cv_mem->cv_qmax; i++) + for (i = 0; i <= cv_mem->cv_qmax; i++) + { N_VDestroyVectorArray(cv_mem->cv_znS[i], cv_mem->cv_Ns); - return(SUNFALSE); + } + return (SUNFALSE); } cv_mem->cv_plist = NULL; - cv_mem->cv_plist = (int *)malloc(cv_mem->cv_Ns*sizeof(int)); - if (cv_mem->cv_plist == NULL) { + cv_mem->cv_plist = (int*)malloc(cv_mem->cv_Ns * sizeof(int)); + if (cv_mem->cv_plist == NULL) + { N_VDestroyVectorArray(cv_mem->cv_yS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ftempS, cv_mem->cv_Ns); - for (i=0; i<=cv_mem->cv_qmax; i++) + for (i = 0; i <= cv_mem->cv_qmax; i++) + { N_VDestroyVectorArray(cv_mem->cv_znS[i], cv_mem->cv_Ns); - free(cv_mem->cv_pbar); cv_mem->cv_pbar = NULL; - return(SUNFALSE); + } + free(cv_mem->cv_pbar); + cv_mem->cv_pbar = NULL; + return (SUNFALSE); } /* Update solver workspace lengths */ - cv_mem->cv_lrw += (cv_mem->cv_qmax + 6)*cv_mem->cv_Ns*cv_mem->cv_lrw1 + cv_mem->cv_Ns; - cv_mem->cv_liw += (cv_mem->cv_qmax + 6)*cv_mem->cv_Ns*cv_mem->cv_liw1 + cv_mem->cv_Ns; + cv_mem->cv_lrw += (cv_mem->cv_qmax + 6) * cv_mem->cv_Ns * cv_mem->cv_lrw1 + + cv_mem->cv_Ns; + cv_mem->cv_liw += (cv_mem->cv_qmax + 6) * cv_mem->cv_Ns * cv_mem->cv_liw1 + + cv_mem->cv_Ns; /* Store the value of qmax used here */ cv_mem->cv_qmax_allocS = cv_mem->cv_qmax; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -4508,22 +4967,31 @@ static void cvSensFreeVectors(CVodeMem cv_mem) N_VDestroyVectorArray(cv_mem->cv_tempvS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ftempS, cv_mem->cv_Ns); - for (j=0; j<=maxord; j++) + for (j = 0; j <= maxord; j++) + { N_VDestroyVectorArray(cv_mem->cv_znS[j], cv_mem->cv_Ns); + } - free(cv_mem->cv_pbar); cv_mem->cv_pbar = NULL; - free(cv_mem->cv_plist); cv_mem->cv_plist = NULL; + free(cv_mem->cv_pbar); + cv_mem->cv_pbar = NULL; + free(cv_mem->cv_plist); + cv_mem->cv_plist = NULL; - cv_mem->cv_lrw -= (maxord + 6)*cv_mem->cv_Ns*cv_mem->cv_lrw1 + cv_mem->cv_Ns; - cv_mem->cv_liw -= (maxord + 6)*cv_mem->cv_Ns*cv_mem->cv_liw1 + cv_mem->cv_Ns; + cv_mem->cv_lrw -= (maxord + 6) * cv_mem->cv_Ns * cv_mem->cv_lrw1 + + cv_mem->cv_Ns; + cv_mem->cv_liw -= (maxord + 6) * cv_mem->cv_Ns * cv_mem->cv_liw1 + + cv_mem->cv_Ns; - if (cv_mem->cv_VabstolSMallocDone) { + if (cv_mem->cv_VabstolSMallocDone) + { N_VDestroyVectorArray(cv_mem->cv_VabstolS, cv_mem->cv_Ns); - cv_mem->cv_lrw -= cv_mem->cv_Ns*cv_mem->cv_lrw1; - cv_mem->cv_liw -= cv_mem->cv_Ns*cv_mem->cv_liw1; + cv_mem->cv_lrw -= cv_mem->cv_Ns * cv_mem->cv_lrw1; + cv_mem->cv_liw -= cv_mem->cv_Ns * cv_mem->cv_liw1; } - if (cv_mem->cv_SabstolSMallocDone) { - free(cv_mem->cv_SabstolS); cv_mem->cv_SabstolS = NULL; + if (cv_mem->cv_SabstolSMallocDone) + { + free(cv_mem->cv_SabstolS); + cv_mem->cv_SabstolS = NULL; cv_mem->cv_lrw -= cv_mem->cv_Ns; } cv_mem->cv_VabstolSMallocDone = SUNFALSE; @@ -4537,73 +5005,79 @@ static void cvSensFreeVectors(CVodeMem cv_mem) * using the N_Vector 'tmpl' as a template. */ -static booleantype cvQuadSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl) +static sunbooleantype cvQuadSensAllocVectors(CVodeMem cv_mem, N_Vector tmpl) { int i, j; /* Allocate ftempQ */ cv_mem->cv_ftempQ = N_VClone(tmpl); - if (cv_mem->cv_ftempQ == NULL) { - return(SUNFALSE); - } + if (cv_mem->cv_ftempQ == NULL) { return (SUNFALSE); } /* Allocate yQS */ cv_mem->cv_yQS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_yQS == NULL) { + if (cv_mem->cv_yQS == NULL) + { N_VDestroy(cv_mem->cv_ftempQ); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate ewtQS */ cv_mem->cv_ewtQS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_ewtQS == NULL) { + if (cv_mem->cv_ewtQS == NULL) + { N_VDestroy(cv_mem->cv_ftempQ); N_VDestroyVectorArray(cv_mem->cv_yQS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate acorQS */ cv_mem->cv_acorQS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_acorQS == NULL) { + if (cv_mem->cv_acorQS == NULL) + { N_VDestroy(cv_mem->cv_ftempQ); N_VDestroyVectorArray(cv_mem->cv_yQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtQS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate tempvQS */ cv_mem->cv_tempvQS = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_tempvQS == NULL) { + if (cv_mem->cv_tempvQS == NULL) + { N_VDestroy(cv_mem->cv_ftempQ); N_VDestroyVectorArray(cv_mem->cv_yQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorQS, cv_mem->cv_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate znQS */ - for (j=0; j<=cv_mem->cv_qmax; j++) { + for (j = 0; j <= cv_mem->cv_qmax; j++) + { cv_mem->cv_znQS[j] = N_VCloneVectorArray(cv_mem->cv_Ns, tmpl); - if (cv_mem->cv_znQS[j] == NULL) { + if (cv_mem->cv_znQS[j] == NULL) + { N_VDestroy(cv_mem->cv_ftempQ); N_VDestroyVectorArray(cv_mem->cv_yQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_ewtQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_acorQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvQS, cv_mem->cv_Ns); - for (i=0; icv_znQS[i], cv_mem->cv_Ns); - return(SUNFALSE); + } + return (SUNFALSE); } } /* Update solver workspace lengths */ - cv_mem->cv_lrw += (cv_mem->cv_qmax + 5)*cv_mem->cv_Ns*cv_mem->cv_lrw1Q; - cv_mem->cv_liw += (cv_mem->cv_qmax + 5)*cv_mem->cv_Ns*cv_mem->cv_liw1Q; + cv_mem->cv_lrw += (cv_mem->cv_qmax + 5) * cv_mem->cv_Ns * cv_mem->cv_lrw1Q; + cv_mem->cv_liw += (cv_mem->cv_qmax + 5) * cv_mem->cv_Ns * cv_mem->cv_liw1Q; /* Store the value of qmax used here */ cv_mem->cv_qmax_allocQS = cv_mem->cv_qmax; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -4625,34 +5099,36 @@ static void cvQuadSensFreeVectors(CVodeMem cv_mem) N_VDestroyVectorArray(cv_mem->cv_acorQS, cv_mem->cv_Ns); N_VDestroyVectorArray(cv_mem->cv_tempvQS, cv_mem->cv_Ns); - for (j=0; j<=maxord; j++) + for (j = 0; j <= maxord; j++) + { N_VDestroyVectorArray(cv_mem->cv_znQS[j], cv_mem->cv_Ns); + } - cv_mem->cv_lrw -= (maxord + 5)*cv_mem->cv_Ns*cv_mem->cv_lrw1Q; - cv_mem->cv_liw -= (maxord + 5)*cv_mem->cv_Ns*cv_mem->cv_liw1Q; + cv_mem->cv_lrw -= (maxord + 5) * cv_mem->cv_Ns * cv_mem->cv_lrw1Q; + cv_mem->cv_liw -= (maxord + 5) * cv_mem->cv_Ns * cv_mem->cv_liw1Q; - if (cv_mem->cv_VabstolQSMallocDone) { + if (cv_mem->cv_VabstolQSMallocDone) + { N_VDestroyVectorArray(cv_mem->cv_VabstolQS, cv_mem->cv_Ns); - cv_mem->cv_lrw -= cv_mem->cv_Ns*cv_mem->cv_lrw1Q; - cv_mem->cv_liw -= cv_mem->cv_Ns*cv_mem->cv_liw1Q; + cv_mem->cv_lrw -= cv_mem->cv_Ns * cv_mem->cv_lrw1Q; + cv_mem->cv_liw -= cv_mem->cv_Ns * cv_mem->cv_liw1Q; } - if (cv_mem->cv_SabstolQSMallocDone) { - free(cv_mem->cv_SabstolQS); cv_mem->cv_SabstolQS = NULL; + if (cv_mem->cv_SabstolQSMallocDone) + { + free(cv_mem->cv_SabstolQS); + cv_mem->cv_SabstolQS = NULL; cv_mem->cv_lrw -= cv_mem->cv_Ns; } cv_mem->cv_VabstolQSMallocDone = SUNFALSE; cv_mem->cv_SabstolQSMallocDone = SUNFALSE; - } - /* * ----------------------------------------------------------------- * Initial setup * ----------------------------------------------------------------- */ - /* * cvInitialSetup * @@ -4664,170 +5140,186 @@ static void cvQuadSensFreeVectors(CVodeMem cv_mem) static int cvInitialSetup(CVodeMem cv_mem) { int ier; - booleantype conOK; + sunbooleantype conOK; /* Did the user specify tolerances? */ - if (cv_mem->cv_itol == CV_NN) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_itol == CV_NN) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_TOL); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* If using a built-in routine for error weights with abstol==0, ensure that N_VMin is available */ - if ((!cv_mem->cv_user_efun) && (cv_mem->cv_atolmin0) && (!cv_mem->cv_tempv->ops->nvmin)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if ((!cv_mem->cv_user_efun) && (cv_mem->cv_atolmin0) && + (!cv_mem->cv_tempv->ops->nvmin)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Missing N_VMin routine from N_Vector"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Set data for efun */ - if (cv_mem->cv_user_efun) cv_mem->cv_e_data = cv_mem->cv_user_data; - else cv_mem->cv_e_data = cv_mem; + if (cv_mem->cv_user_efun) { cv_mem->cv_e_data = cv_mem->cv_user_data; } + else { cv_mem->cv_e_data = cv_mem; } /* Check to see if y0 satisfies constraints */ - if (cv_mem->cv_constraintsSet) { - - if (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_SIMULTANEOUS)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", MSGCV_BAD_ISM_CONSTR); - return(CV_ILL_INPUT); + if (cv_mem->cv_constraintsSet) + { + if (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_SIMULTANEOUS)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_ISM_CONSTR); + return (CV_ILL_INPUT); } - conOK = N_VConstrMask(cv_mem->cv_constraints, cv_mem->cv_zn[0], cv_mem->cv_tempv); - if (!conOK) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + conOK = N_VConstrMask(cv_mem->cv_constraints, cv_mem->cv_zn[0], + cv_mem->cv_tempv); + if (!conOK) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_Y0_FAIL_CONSTR); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } } /* Load initial error weights */ ier = cv_mem->cv_efun(cv_mem->cv_zn[0], cv_mem->cv_ewt, cv_mem->cv_e_data); - if (ier != 0) { + if (ier != 0) + { if (cv_mem->cv_itol == CV_WF) - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_EWT_FAIL); + } else - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_EWT); - return(CV_ILL_INPUT); + } + return (CV_ILL_INPUT); } /* Quadrature initial setup */ - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { - + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { /* Did the user specify tolerances? */ - if (cv_mem->cv_itolQ == CV_NN) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_itolQ == CV_NN) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_TOLQ); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Load ewtQ */ ier = cvQuadEwtSet(cv_mem, cv_mem->cv_znQ[0], cv_mem->cv_ewtQ); - if (ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_EWTQ); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - } - if (!cv_mem->cv_quadr) cv_mem->cv_errconQ = SUNFALSE; + if (!cv_mem->cv_quadr) { cv_mem->cv_errconQ = SUNFALSE; } /* Forward sensitivity initial setup */ - if (cv_mem->cv_sensi) { - + if (cv_mem->cv_sensi) + { /* Did the user specify tolerances? */ - if (cv_mem->cv_itolS == CV_NN) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_itolS == CV_NN) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_TOLS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* If using the internal DQ functions, we must have access to the problem parameters */ - if(cv_mem->cv_fSDQ && (cv_mem->cv_p == NULL)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_fSDQ && (cv_mem->cv_p == NULL)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_P); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Load ewtS */ ier = cvSensEwtSet(cv_mem, cv_mem->cv_znS[0], cv_mem->cv_ewtS); - if (ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_EWTS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - } /* FSA of quadrature variables */ - if (cv_mem->cv_quadr_sensi) { - + if (cv_mem->cv_quadr_sensi) + { /* If using the internal DQ functions, we must have access to fQ * (i.e. quadrature integration must be enabled) and to the problem parameters */ - if (cv_mem->cv_fQSDQ) { - + if (cv_mem->cv_fQSDQ) + { /* Test if quadratures are defined, so we can use fQ */ - if (!cv_mem->cv_quadr) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (!cv_mem->cv_quadr) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_FQ); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Test if we have the problem parameters */ - if(cv_mem->cv_p == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_p == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NULL_P); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - } - if (cv_mem->cv_errconQS) { - + if (cv_mem->cv_errconQS) + { /* Did the user specify tolerances? */ - if (cv_mem->cv_itolQS == CV_NN) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (cv_mem->cv_itolQS == CV_NN) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_TOLQS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* If needed, did the user provide quadrature tolerances? */ - if ( (cv_mem->cv_itolQS == CV_EE) && (cv_mem->cv_itolQ == CV_NN) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if ((cv_mem->cv_itolQS == CV_EE) && (cv_mem->cv_itolQ == CV_NN)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_TOLQ); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Load ewtQS */ ier = cvQuadSensEwtSet(cv_mem, cv_mem->cv_znQS[0], cv_mem->cv_ewtQS); - if (ier != 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvInitialSetup", + if (ier != 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_BAD_EWTQS); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - } - - } else { - - cv_mem->cv_errconQS = SUNFALSE; - } + else { cv_mem->cv_errconQS = SUNFALSE; } /* Call linit function (if it exists) */ - if (cv_mem->cv_linit != NULL) { + if (cv_mem->cv_linit != NULL) + { ier = cv_mem->cv_linit(cv_mem); - if (ier != 0) { - cvProcessError(cv_mem, CV_LINIT_FAIL, "CVODES", "cvInitialSetup", + if (ier != 0) + { + cvProcessError(cv_mem, CV_LINIT_FAIL, __LINE__, __func__, __FILE__, MSGCV_LINIT_FAIL); - return(CV_LINIT_FAIL); + return (CV_LINIT_FAIL); } } @@ -4836,42 +5328,69 @@ static int cvInitialSetup(CVodeMem cv_mem) /* always initialize the ODE NLS in case the user disables sensitivities */ ier = cvNlsInit(cv_mem); - if (ier != 0) { - cvProcessError(cv_mem, CV_NLS_INIT_FAIL, "CVODES", "cvInitialSetup", + if (ier != 0) + { + cvProcessError(cv_mem, CV_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } - if (cv_mem->NLSsim != NULL) { + if (cv_mem->NLSsim != NULL) + { ier = cvNlsInitSensSim(cv_mem); - if (ier != 0) { - cvProcessError(cv_mem, CV_NLS_INIT_FAIL, "CVODES", - "cvInitialSetup", MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + if (ier != 0) + { + cvProcessError(cv_mem, CV_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, + MSGCV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } } - if (cv_mem->NLSstg != NULL) { + if (cv_mem->NLSstg != NULL) + { ier = cvNlsInitSensStg(cv_mem); - if (ier != 0) { - cvProcessError(cv_mem, CV_NLS_INIT_FAIL, "CVODES", - "cvInitialSetup", MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + if (ier != 0) + { + cvProcessError(cv_mem, CV_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, + MSGCV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } } - if (cv_mem->NLSstg1 != NULL) { + if (cv_mem->NLSstg1 != NULL) + { ier = cvNlsInitSensStg1(cv_mem); - if (ier != 0) { - cvProcessError(cv_mem, CV_NLS_INIT_FAIL, "CVODES", - "cvInitialSetup", MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + if (ier != 0) + { + cvProcessError(cv_mem, CV_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, + MSGCV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } } - return(CV_SUCCESS); -} + /* Initialize projection data */ + if (cv_mem->proj_enabled && cv_mem->proj_mem == NULL) + { + cvProcessError(cv_mem, CV_PROJ_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_CV_PROJ_MEM_NULL); + return (CV_PROJ_MEM_NULL); + } + + if (cv_mem->proj_mem != NULL) + { + ier = cvProjInit(cv_mem->proj_mem); + if (ier != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); + } + cv_mem->proj_applied = SUNFALSE; + } + /* Initial setup complete */ + return (CV_SUCCESS); +} /* * ----------------------------------------------------------------- @@ -4914,22 +5433,22 @@ static int cvInitialSetup(CVodeMem cv_mem) * Finally, we apply a bias (0.5) and verify that h0 is within bounds. */ -static int cvHin(CVodeMem cv_mem, realtype tout) +static int cvHin(CVodeMem cv_mem, sunrealtype tout) { int retval, sign, count1, count2; - realtype tdiff, tdist, tround, hlb, hub; - realtype hg, hgs, hs, hnew, hrat, h0, yddnrm; - booleantype hgOK; + sunrealtype tdiff, tdist, tround, hlb, hub; + sunrealtype hg, hgs, hs, hnew, hrat, h0, yddnrm; + sunbooleantype hgOK; /* If tout is too close to tn, give up */ - if ((tdiff = tout-cv_mem->cv_tn) == ZERO) return(CV_TOO_CLOSE); + if ((tdiff = tout - cv_mem->cv_tn) == ZERO) { return (CV_TOO_CLOSE); } - sign = (tdiff > ZERO) ? 1 : -1; - tdist = SUNRabs(tdiff); + sign = (tdiff > ZERO) ? 1 : -1; + tdist = SUNRabs(tdiff); tround = cv_mem->cv_uround * SUNMAX(SUNRabs(cv_mem->cv_tn), SUNRabs(tout)); - if (tdist < TWO*tround) return(CV_TOO_CLOSE); + if (tdist < TWO * tround) { return (CV_TOO_CLOSE); } /* Set lower and upper bounds on h0, and take geometric mean @@ -4940,43 +5459,51 @@ static int cvHin(CVodeMem cv_mem, realtype tout) hlb = HLB_FACTOR * tround; hub = cvUpperBoundH0(cv_mem, tdist); - hg = SUNRsqrt(hlb*hub); + hg = SUNRsqrt(hlb * hub); - if (hub < hlb) { - if (sign == -1) cv_mem->cv_h = -hg; - else cv_mem->cv_h = hg; - return(CV_SUCCESS); + if (hub < hlb) + { + if (sign == -1) { cv_mem->cv_h = -hg; } + else { cv_mem->cv_h = hg; } + return (CV_SUCCESS); } /* Outer loop */ - hs = hg; /* safeguard against 'uninitialized variable' warning */ - - for(count1 = 1; count1 <= MAX_ITERS; count1++) { + hs = hg; /* safeguard against 'uninitialized variable' warning */ + for (count1 = 1; count1 <= MAX_ITERS; count1++) + { /* Attempts to estimate ydd */ hgOK = SUNFALSE; - for (count2 = 1; count2 <= MAX_ITERS; count2++) { - hgs = hg*sign; + for (count2 = 1; count2 <= MAX_ITERS; count2++) + { + hgs = hg * sign; retval = cvYddNorm(cv_mem, hgs, &yddnrm); /* If a RHS function failed unrecoverably, give up */ - if (retval < 0) return(retval); + if (retval < 0) { return (retval); } /* If successful, we can use ydd */ - if (retval == CV_SUCCESS) {hgOK = SUNTRUE; break;} + if (retval == CV_SUCCESS) + { + hgOK = SUNTRUE; + break; + } /* A RHS function failed recoverably; cut step size and test again */ hg *= POINT2; } /* If a RHS function failed recoverably MAX_ITERS times */ - if (!hgOK) { + if (!hgOK) + { /* Exit if this is the first or second pass. No recovery possible */ - if (count1 <= 2) { - if (retval == RHSFUNC_RECVR) return(CV_REPTD_RHSFUNC_ERR); - if (retval == QRHSFUNC_RECVR) return(CV_REPTD_QRHSFUNC_ERR); - if (retval == SRHSFUNC_RECVR) return(CV_REPTD_SRHSFUNC_ERR); + if (count1 <= 2) + { + if (retval == RHSFUNC_RECVR) { return (CV_REPTD_RHSFUNC_ERR); } + if (retval == QRHSFUNC_RECVR) { return (CV_REPTD_QRHSFUNC_ERR); } + if (retval == SRHSFUNC_RECVR) { return (CV_REPTD_SRHSFUNC_ERR); } } /* We have a fall-back option. The value hs is a previous hnew which passed through f(). Use it and break */ @@ -4988,36 +5515,37 @@ static int cvHin(CVodeMem cv_mem, realtype tout) hs = hg; /* Propose new step size */ - hnew = (yddnrm*hub*hub > TWO) ? SUNRsqrt(TWO/yddnrm) : SUNRsqrt(hg*hub); + hnew = (yddnrm * hub * hub > TWO) ? SUNRsqrt(TWO / yddnrm) + : SUNRsqrt(hg * hub); /* If last pass, stop now with hnew */ - if (count1 == MAX_ITERS) break; + if (count1 == MAX_ITERS) { break; } - hrat = hnew/hg; + hrat = hnew / hg; /* Accept hnew if it does not differ from hg by more than a factor of 2 */ - if ((hrat > HALF) && (hrat < TWO)) break; + if ((hrat > HALF) && (hrat < TWO)) { break; } /* After one pass, if ydd seems to be bad, use fall-back value. */ - if ((count1 > 1) && (hrat > TWO)) { + if ((count1 > 1) && (hrat > TWO)) + { hnew = hg; break; } /* Send this value back through f() */ hg = hnew; - } /* Apply bounds, bias factor, and attach sign */ - h0 = H_BIAS*hnew; - if (h0 < hlb) h0 = hlb; - if (h0 > hub) h0 = hub; - if (sign == -1) h0 = -h0; + h0 = H_BIAS * hnew; + if (h0 < hlb) { h0 = hlb; } + if (h0 > hub) { h0 = hub; } + if (sign == -1) { h0 = -h0; } cv_mem->cv_h = h0; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -5027,13 +5555,13 @@ static int cvHin(CVodeMem cv_mem, realtype tout) * tdist = tn - t0 and the values of y[i]/y'[i]. */ -static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) +static sunrealtype cvUpperBoundH0(CVodeMem cv_mem, sunrealtype tdist) { - realtype hub_inv, hubQ_inv, hubS_inv, hubQS_inv, hub; + sunrealtype hub_inv, hubQ_inv, hubS_inv, hubQS_inv, hub; N_Vector temp1, temp2; N_Vector tempQ1, tempQ2; - N_Vector *tempS1; - N_Vector *tempQS1; + N_Vector* tempS1; + N_Vector* tempQS1; int is; /* @@ -5057,8 +5585,8 @@ static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) /* Bound based on |yQ|/|yQ'| */ - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { - + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { tempQ1 = cv_mem->cv_tempvQ; tempQ2 = cv_mem->cv_acorQ; @@ -5072,19 +5600,18 @@ static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) N_VDiv(tempQ2, tempQ1, tempQ1); hubQ_inv = N_VMaxNorm(tempQ1); - if (hubQ_inv > hub_inv) hub_inv = hubQ_inv; - + if (hubQ_inv > hub_inv) { hub_inv = hubQ_inv; } } /* Bound based on |yS|/|yS'| */ - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { - + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { tempS1 = cv_mem->cv_acorS; cvSensEwtSet(cv_mem, cv_mem->cv_znS[0], tempS1); - for (is=0; iscv_Ns; is++) { - + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(cv_mem->cv_znS[0][is], temp2); N_VInv(tempS1[is], temp1); N_VLinearSum(HUB_FACTOR, temp2, ONE, temp1, temp1); @@ -5094,24 +5621,22 @@ static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) N_VDiv(temp2, temp1, temp1); hubS_inv = N_VMaxNorm(temp1); - if (hubS_inv > hub_inv) hub_inv = hubS_inv; - + if (hubS_inv > hub_inv) { hub_inv = hubS_inv; } } - } /* Bound based on |yQS|/|yQS'| */ - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { - + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { tempQ1 = cv_mem->cv_tempvQ; tempQ2 = cv_mem->cv_acorQ; tempQS1 = cv_mem->cv_acorQS; cvQuadSensEwtSet(cv_mem, cv_mem->cv_znQS[0], tempQS1); - for (is=0; iscv_Ns; is++) { - + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(cv_mem->cv_znQS[0][is], tempQ2); N_VInv(tempQS1[is], tempQ1); N_VLinearSum(HUB_FACTOR, tempQ2, ONE, tempQ1, tempQ1); @@ -5121,25 +5646,22 @@ static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) N_VDiv(tempQ2, tempQ1, tempQ1); hubQS_inv = N_VMaxNorm(tempQ1); - if (hubQS_inv > hub_inv) hub_inv = hubQS_inv; - + if (hubQS_inv > hub_inv) { hub_inv = hubQS_inv; } } - } - /* * bound based on tdist -- allow at most a step of magnitude * HUB_FACTOR * tdist */ - hub = HUB_FACTOR*tdist; + hub = HUB_FACTOR * tdist; /* Use the smaller of the two */ - if (hub*hub_inv > ONE) hub = ONE/hub_inv; + if (hub * hub_inv > ONE) { hub = ONE / hub_inv; } - return(hub); + return (hub); } /* @@ -5151,7 +5673,7 @@ static realtype cvUpperBoundH0(CVodeMem cv_mem, realtype tdist) * Y contains all variables included in the error test. */ -static int cvYddNorm(CVodeMem cv_mem, realtype hg, realtype *yddnrm) +static int cvYddNorm(CVodeMem cv_mem, sunrealtype hg, sunrealtype* yddnrm) { int retval; N_Vector wrk1, wrk2; @@ -5160,94 +5682,96 @@ static int cvYddNorm(CVodeMem cv_mem, realtype hg, realtype *yddnrm) N_VLinearSum(hg, cv_mem->cv_zn[1], ONE, cv_mem->cv_zn[0], cv_mem->cv_y); - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - hg, cv_mem->cv_znS[1], - ONE, cv_mem->cv_znS[0], - cv_mem->cv_yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, hg, cv_mem->cv_znS[1], ONE, + cv_mem->cv_znS[0], cv_mem->cv_yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } /* tempv <- f(t+h, h*y'(t)+y(t)) */ - retval = cv_mem->cv_f(cv_mem->cv_tn+hg, cv_mem->cv_y, - cv_mem->cv_tempv, cv_mem->cv_user_data); + retval = cv_mem->cv_f(cv_mem->cv_tn + hg, cv_mem->cv_y, cv_mem->cv_tempv, + cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(RHSFUNC_RECVR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (RHSFUNC_RECVR); } - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { - retval = cv_mem->cv_fQ(cv_mem->cv_tn+hg, cv_mem->cv_y, - cv_mem->cv_tempvQ, cv_mem->cv_user_data); + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { + retval = cv_mem->cv_fQ(cv_mem->cv_tn + hg, cv_mem->cv_y, cv_mem->cv_tempvQ, + cv_mem->cv_user_data); cv_mem->cv_nfQe++; - if (retval < 0) return(CV_QRHSFUNC_FAIL); - if (retval > 0) return(QRHSFUNC_RECVR); + if (retval < 0) { return (CV_QRHSFUNC_FAIL); } + if (retval > 0) { return (QRHSFUNC_RECVR); } } - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { - wrk1 = cv_mem->cv_ftemp; - wrk2 = cv_mem->cv_acor; - retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn+hg, cv_mem->cv_y, + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { + wrk1 = cv_mem->cv_ftemp; + wrk2 = cv_mem->cv_acor; + retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn + hg, cv_mem->cv_y, cv_mem->cv_tempv, cv_mem->cv_yS, cv_mem->cv_tempvS, wrk1, wrk2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } } - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { - wrk1 = cv_mem->cv_ftemp; - wrk2 = cv_mem->cv_acorQ; - retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn+hg, - cv_mem->cv_y, cv_mem->cv_yS, - cv_mem->cv_tempvQ, cv_mem->cv_tempvQS, - cv_mem->cv_fQS_data, wrk1, wrk2); + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { + wrk1 = cv_mem->cv_ftemp; + wrk2 = cv_mem->cv_acorQ; + retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn + hg, cv_mem->cv_y, + cv_mem->cv_yS, cv_mem->cv_tempvQ, + cv_mem->cv_tempvQS, cv_mem->cv_fQS_data, wrk1, wrk2); cv_mem->cv_nfQSe++; - if (retval < 0) return(CV_QSRHSFUNC_FAIL); - if (retval > 0) return(QSRHSFUNC_RECVR); + if (retval < 0) { return (CV_QSRHSFUNC_FAIL); } + if (retval > 0) { return (QSRHSFUNC_RECVR); } } /* Load estimate of ||y''|| into tempv: * tempv <- (1/h) * f(t+h, h*y'(t)+y(t)) - y'(t) */ - N_VLinearSum(ONE/hg, cv_mem->cv_tempv, -ONE/hg, cv_mem->cv_zn[1], cv_mem->cv_tempv); + N_VLinearSum(ONE / hg, cv_mem->cv_tempv, -ONE / hg, cv_mem->cv_zn[1], + cv_mem->cv_tempv); *yddnrm = N_VWrmsNorm(cv_mem->cv_tempv, cv_mem->cv_ewt); - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) { - N_VLinearSum(ONE/hg, cv_mem->cv_tempvQ, -ONE/hg, cv_mem->cv_znQ[1], + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { + N_VLinearSum(ONE / hg, cv_mem->cv_tempvQ, -ONE / hg, cv_mem->cv_znQ[1], cv_mem->cv_tempvQ); *yddnrm = cvQuadUpdateNorm(cv_mem, *yddnrm, cv_mem->cv_tempvQ, cv_mem->cv_ewtQ); } - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE/hg, cv_mem->cv_tempvS, - -ONE/hg, cv_mem->cv_znS[1], + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE / hg, cv_mem->cv_tempvS, + -ONE / hg, cv_mem->cv_znS[1], cv_mem->cv_tempvS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } *yddnrm = cvSensUpdateNorm(cv_mem, *yddnrm, cv_mem->cv_tempvS, cv_mem->cv_ewtS); } - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE/hg, cv_mem->cv_tempvQS, - -ONE/hg, cv_mem->cv_znQS[1], - cv_mem->cv_tempvQS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE / hg, + cv_mem->cv_tempvQS, -ONE / hg, + cv_mem->cv_znQS[1], cv_mem->cv_tempvQS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } *yddnrm = cvQuadSensUpdateNorm(cv_mem, *yddnrm, cv_mem->cv_tempvQS, cv_mem->cv_ewtQS); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * ----------------------------------------------------------------- * Main cvStep function @@ -5275,39 +5799,71 @@ static int cvYddNorm(CVodeMem cv_mem, realtype hg, realtype *yddnrm) static int cvStep(CVodeMem cv_mem) { - realtype saved_t, dsm, dsmQ, dsmS, dsmQS; - booleantype do_sensi_stg, do_sensi_stg1; - int ncf, ncfS; - int nef, nefQ, nefS, nefQS; - int nflag, kflag, eflag; + sunrealtype saved_t; /* time to restore to if a failure occurs */ + sunrealtype dsm; /* local truncation error estimate */ + sunrealtype dsmQ; /* quadrature error estimate */ + sunrealtype dsmS; /* sensitivity error estimate */ + sunrealtype dsmQS; /* quadrature sensitivity error estimate */ + int ncf; /* corrector failures in this step attempt */ + int ncfS; /* sensitivity corrector failures */ + int npf; /* projection failures in this step attempt */ + int nef; /* error test failures in this step attempt */ + int nefQ; /* quadrature error test fails */ + int nefS; /* sensitivity error test fails */ + int nefQS; /* quadrature sensitivity error test fails */ + int nflag, kflag; /* nonlinear solver flags */ + int pflag; /* projection return flag */ + int eflag; /* error test return flag */ int retval, is; + sunbooleantype doProjection; /* flag to apply projection in this step */ + sunbooleantype do_sensi_stg; /* staggered strategy */ + sunbooleantype do_sensi_stg1; /* staggered 1 strategy */ /* Are we computing sensitivities with a staggered approach? */ - do_sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED)); - do_sensi_stg1 = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED1)); + do_sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED)); + do_sensi_stg1 = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED1)); /* Initialize local counters for convergence and error test failures */ - ncf = nef = 0; + ncf = npf = nef = 0; nefQ = nefQS = 0; ncfS = nefS = 0; - if (do_sensi_stg1) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_ncfS1[is] = 0; + if (do_sensi_stg1) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_ncfS1[is] = 0; } } - /* If needed, adjust method parameters */ - + /* If the step size has changed, update the history array */ if ((cv_mem->cv_nst > 0) && (cv_mem->cv_hprime != cv_mem->cv_h)) + { cvAdjustParams(cv_mem); + } + + /* Check if this step should be projected */ + doProjection = SUNFALSE; + if (cv_mem->proj_enabled) + { + doProjection = + cv_mem->proj_mem->freq > 0 && + (cv_mem->cv_nst == 0 || + (cv_mem->cv_nst >= cv_mem->proj_mem->nstlprj + cv_mem->proj_mem->freq)); + } /* Looping point for attempts to take a step */ saved_t = cv_mem->cv_tn; - nflag = FIRST_CALL; - - for(;;) { + nflag = FIRST_CALL; + + for (;;) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvStep", + "enter-step-attempt-loop", + "step = %li, h = %.16g, q = %d, t_n = %.16g", + cv_mem->cv_nst, cv_mem->cv_next_h, cv_mem->cv_next_q, + cv_mem->cv_tn); +#endif cvPredict(cv_mem); cvSet(cv_mem); @@ -5318,120 +5874,140 @@ static int cvStep(CVodeMem cv_mem) kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, &ncf, &(cv_mem->cv_ncfn)); /* Go back in loop if we need to predict again (nflag=PREV_CONV_FAIL) */ - if (kflag == PREDICT_AGAIN) continue; + if (kflag == PREDICT_AGAIN) { continue; } + + /* Return if nonlinear solve failed and recovery is not possible. */ + if (kflag != DO_ERROR_TEST) { return (kflag); } - /* Return if nonlinear solve failed and recovery not possible. */ - if (kflag != DO_ERROR_TEST) return(kflag); + /* Check if a projection needs to be performed */ + cv_mem->proj_applied = SUNFALSE; + + if (doProjection) + { + /* Perform projection (nflag=CV_SUCCESS) */ + pflag = cvDoProjection(cv_mem, &nflag, saved_t, &npf); + + /* Go back in loop if we need to predict again (nflag=PREV_PROJ_FAIL) */ + if (pflag == PREDICT_AGAIN) { continue; } + + /* Return if projection failed and recovery is not possible */ + if (pflag != CV_SUCCESS) { return (pflag); } + } /* Perform error test (nflag=CV_SUCCESS) */ - eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrm, - &nef, &(cv_mem->cv_netf), &dsm); + eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrm, &nef, + &(cv_mem->cv_netf), &dsm); /* Go back in loop if we need to predict again (nflag=PREV_ERR_FAIL) */ - if (eflag == TRY_AGAIN) continue; + if (eflag == TRY_AGAIN) { continue; } - /* Return if error test failed and recovery not possible. */ - if (eflag != CV_SUCCESS) return(eflag); + /* Return if error test failed and recovery is not possible. */ + if (eflag != CV_SUCCESS) { return (eflag); } /* Error test passed (eflag=CV_SUCCESS, nflag=CV_SUCCESS), go on */ /* ------ Correct the quadrature variables ------ */ - if (cv_mem->cv_quadr) { - + if (cv_mem->cv_quadr) + { ncf = nef = 0; /* reset counters for states */ nflag = cvQuadNls(cv_mem); kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, &ncf, &(cv_mem->cv_ncfn)); - if (kflag == PREDICT_AGAIN) continue; - if (kflag != DO_ERROR_TEST) return(kflag); + if (kflag == PREDICT_AGAIN) { continue; } + if (kflag != DO_ERROR_TEST) { return (kflag); } /* Error test on quadratures */ - if (cv_mem->cv_errconQ) { + if (cv_mem->cv_errconQ) + { cv_mem->cv_acnrmQ = N_VWrmsNorm(cv_mem->cv_acorQ, cv_mem->cv_ewtQ); - eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrmQ, - &nefQ, &(cv_mem->cv_netfQ), &dsmQ); + eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrmQ, &nefQ, + &(cv_mem->cv_netfQ), &dsmQ); - if (eflag == TRY_AGAIN) continue; - if (eflag != CV_SUCCESS) return(eflag); + if (eflag == TRY_AGAIN) { continue; } + if (eflag != CV_SUCCESS) { return (eflag); } /* Set dsm = max(dsm, dsmQ) to be used in cvPrepareNextStep */ - if (dsmQ > dsm) dsm = dsmQ; + if (dsmQ > dsm) { dsm = dsmQ; } } - } /* ------ Correct the sensitivity variables (STAGGERED or STAGGERED1) ------- */ - if (do_sensi_stg || do_sensi_stg1) { - - ncf = nef = 0; /* reset counters for states */ - if (cv_mem->cv_quadr) nefQ = 0; /* reset counter for quadratures */ + if (do_sensi_stg || do_sensi_stg1) + { + ncf = nef = 0; /* reset counters for states */ + if (cv_mem->cv_quadr) { nefQ = 0; /* reset counter for quadratures */ } /* Evaluate f at converged y, needed for future evaluations of sens. RHS * If f() fails recoverably, treat it as a convergence failure and * attempt the step again */ - retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_y, - cv_mem->cv_ftemp, cv_mem->cv_user_data); + retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_y, cv_mem->cv_ftemp, + cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) { + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) + { nflag = PREV_CONV_FAIL; continue; } - if (do_sensi_stg) { + if (do_sensi_stg) + { /* Nonlinear solve for sensitivities (all-at-once) */ nflag = cvStgrNls(cv_mem); kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, &ncfS, &(cv_mem->cv_ncfnS)); - } else { + } + else + { /* Nonlinear solve for sensitivities (one-by-one) */ - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->sens_solve_idx = is; - nflag = cvStgr1Nls(cv_mem, is); - kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, - &(cv_mem->cv_ncfS1[is]), + nflag = cvStgr1Nls(cv_mem, is); + kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, &(cv_mem->cv_ncfS1[is]), &(cv_mem->cv_ncfnS1[is])); - if (kflag != DO_ERROR_TEST) break; + if (kflag != DO_ERROR_TEST) { break; } } } - if (kflag == PREDICT_AGAIN) continue; - if (kflag != DO_ERROR_TEST) return(kflag); + if (kflag == PREDICT_AGAIN) { continue; } + if (kflag != DO_ERROR_TEST) { return (kflag); } /* Error test on sensitivities */ - if (cv_mem->cv_errconS) { - + if (cv_mem->cv_errconS) + { if (!cv_mem->cv_acnrmScur) - cv_mem->cv_acnrmS = cvSensNorm(cv_mem, cv_mem->cv_acorS, cv_mem->cv_ewtS); + { + cv_mem->cv_acnrmS = cvSensNorm(cv_mem, cv_mem->cv_acorS, + cv_mem->cv_ewtS); + } - eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrmS, - &nefS, &(cv_mem->cv_netfS), &dsmS); + eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrmS, &nefS, + &(cv_mem->cv_netfS), &dsmS); - if (eflag == TRY_AGAIN) continue; - if (eflag != CV_SUCCESS) return(eflag); + if (eflag == TRY_AGAIN) { continue; } + if (eflag != CV_SUCCESS) { return (eflag); } /* Set dsm = max(dsm, dsmS) to be used in cvPrepareNextStep */ - if (dsmS > dsm) dsm = dsmS; - + if (dsmS > dsm) { dsm = dsmS; } } - } /* ------ Correct the quadrature sensitivity variables ------ */ - if (cv_mem->cv_quadr_sensi) { - + if (cv_mem->cv_quadr_sensi) + { /* Reset local convergence and error test failure counters */ ncf = nef = 0; - if (cv_mem->cv_quadr) nefQ = 0; - if (do_sensi_stg) ncfS = nefS = 0; - if (do_sensi_stg1) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_ncfS1[is] = 0; + if (cv_mem->cv_quadr) { nefQ = 0; } + if (do_sensi_stg) { ncfS = nefS = 0; } + if (do_sensi_stg1) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_ncfS1[is] = 0; } nefS = 0; } @@ -5441,28 +6017,27 @@ static int cvStep(CVodeMem cv_mem) nflag = cvQuadSensNls(cv_mem); kflag = cvHandleNFlag(cv_mem, &nflag, saved_t, &ncf, &(cv_mem->cv_ncfn)); - if (kflag == PREDICT_AGAIN) continue; - if (kflag != DO_ERROR_TEST) return(kflag); + if (kflag == PREDICT_AGAIN) { continue; } + if (kflag != DO_ERROR_TEST) { return (kflag); } /* Error test on quadrature sensitivities */ - if (cv_mem->cv_errconQS) { + if (cv_mem->cv_errconQS) + { cv_mem->cv_acnrmQS = cvQuadSensNorm(cv_mem, cv_mem->cv_acorQS, cv_mem->cv_ewtQS); eflag = cvDoErrorTest(cv_mem, &nflag, saved_t, cv_mem->cv_acnrmQS, &nefQS, &(cv_mem->cv_netfQS), &dsmQS); - if (eflag == TRY_AGAIN) continue; - if (eflag != CV_SUCCESS) return(eflag); + if (eflag == TRY_AGAIN) { continue; } + if (eflag != CV_SUCCESS) { return (eflag); } /* Set dsm = max(dsm, dsmQS) to be used in cvPrepareNextStep */ - if (dsmQS > dsm) dsm = dsmQS; + if (dsmQS > dsm) { dsm = dsmQS; } } - } /* Error test passed (eflag=CV_SUCCESS), break from loop */ break; - } /* Nonlinear system solve and error test were both successful. @@ -5475,9 +6050,11 @@ static int cvStep(CVodeMem cv_mem) /* If Stablilty Limit Detection is turned on, call stability limit detection routine for possible order reduction. */ - if (cv_mem->cv_sldeton) cvBDFStab(cv_mem); + if (cv_mem->cv_sldeton) { cvBDFStab(cv_mem); } - cv_mem->cv_etamax = (cv_mem->cv_nst <= SMALL_NST) ? ETAMX2 : ETAMX3; + cv_mem->cv_etamax = (cv_mem->cv_nst <= cv_mem->cv_small_nst) + ? cv_mem->cv_eta_max_es + : cv_mem->cv_eta_max_gs; /* Finally, we rescale the acor array to be the estimated local error vector. */ @@ -5485,27 +6062,35 @@ static int cvStep(CVodeMem cv_mem) N_VScale(cv_mem->cv_tq[2], cv_mem->cv_acor, cv_mem->cv_acor); if (cv_mem->cv_quadr) + { N_VScale(cv_mem->cv_tq[2], cv_mem->cv_acorQ, cv_mem->cv_acorQ); + } - if (cv_mem->cv_sensi) { - for (is=0; iscv_Ns; is++) + if (cv_mem->cv_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_tq[2]; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_acorS, cv_mem->cv_acorS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - if (cv_mem->cv_quadr_sensi) { - for (is=0; iscv_Ns; is++) + if (cv_mem->cv_quadr_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_tq[2]; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_acorQS, cv_mem->cv_acorQS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -5526,10 +6111,11 @@ static int cvStep(CVodeMem cv_mem) static void cvAdjustParams(CVodeMem cv_mem) { - if (cv_mem->cv_qprime != cv_mem->cv_q) { - cvAdjustOrder(cv_mem, cv_mem->cv_qprime-cv_mem->cv_q); - cv_mem->cv_q = cv_mem->cv_qprime; - cv_mem->cv_L = cv_mem->cv_q+1; + if (cv_mem->cv_qprime != cv_mem->cv_q) + { + cvAdjustOrder(cv_mem, cv_mem->cv_qprime - cv_mem->cv_q); + cv_mem->cv_q = cv_mem->cv_qprime; + cv_mem->cv_L = cv_mem->cv_q + 1; cv_mem->cv_qwait = cv_mem->cv_L; } cvRescale(cv_mem); @@ -5547,15 +6133,12 @@ static void cvAdjustParams(CVodeMem cv_mem) static void cvAdjustOrder(CVodeMem cv_mem, int deltaq) { - if ((cv_mem->cv_q==2) && (deltaq != 1)) return; + if ((cv_mem->cv_q == 2) && (deltaq != 1)) { return; } - switch(cv_mem->cv_lmm){ - case CV_ADAMS: - cvAdjustAdams(cv_mem, deltaq); - break; - case CV_BDF: - cvAdjustBDF(cv_mem, deltaq); - break; + switch (cv_mem->cv_lmm) + { + case CV_ADAMS: cvAdjustAdams(cv_mem, deltaq); break; + case CV_BDF: cvAdjustBDF(cv_mem, deltaq); break; } } @@ -5569,17 +6152,19 @@ static void cvAdjustOrder(CVodeMem cv_mem, int deltaq) static void cvAdjustAdams(CVodeMem cv_mem, int deltaq) { int i, j; - realtype xi, hsum; + sunrealtype xi, hsum; /* On an order increase, set new column of zn to zero and return */ - if (deltaq==1) { + if (deltaq == 1) + { N_VConst(ZERO, cv_mem->cv_zn[cv_mem->cv_L]); - if (cv_mem->cv_quadr) - N_VConst(ZERO, cv_mem->cv_znQ[cv_mem->cv_L]); + if (cv_mem->cv_quadr) { N_VConst(ZERO, cv_mem->cv_znQ[cv_mem->cv_L]); } if (cv_mem->cv_sensi) - (void) N_VConstVectorArray(cv_mem->cv_Ns, ZERO, - cv_mem->cv_znS[cv_mem->cv_L]); + { + (void)N_VConstVectorArray(cv_mem->cv_Ns, ZERO, + cv_mem->cv_znS[cv_mem->cv_L]); + } return; } @@ -5592,41 +6177,50 @@ static void cvAdjustAdams(CVodeMem cv_mem, int deltaq) * where xi_j = [t_n - t_(n-j)]/h => xi_0 = 0 */ - for (i=0; i <= cv_mem->cv_qmax; i++) cv_mem->cv_l[i] = ZERO; + for (i = 0; i <= cv_mem->cv_qmax; i++) { cv_mem->cv_l[i] = ZERO; } cv_mem->cv_l[1] = ONE; - hsum = ZERO; - for (j=1; j <= cv_mem->cv_q-2; j++) { + hsum = ZERO; + for (j = 1; j <= cv_mem->cv_q - 2; j++) + { hsum += cv_mem->cv_tau[j]; xi = hsum / cv_mem->cv_hscale; - for (i=j+1; i >= 1; i--) - cv_mem->cv_l[i] = cv_mem->cv_l[i]*xi + cv_mem->cv_l[i-1]; + for (i = j + 1; i >= 1; i--) + { + cv_mem->cv_l[i] = cv_mem->cv_l[i] * xi + cv_mem->cv_l[i - 1]; + } } - for (j=1; j <= cv_mem->cv_q-2; j++) - cv_mem->cv_l[j+1] = cv_mem->cv_q * (cv_mem->cv_l[j] / (j+1)); - - if (cv_mem->cv_q > 2) { + for (j = 1; j <= cv_mem->cv_q - 2; j++) + { + cv_mem->cv_l[j + 1] = cv_mem->cv_q * (cv_mem->cv_l[j] / (j + 1)); + } - for (j=2; j < cv_mem->cv_q; j++) - cv_mem->cv_cvals[j-2] = -cv_mem->cv_l[j]; + if (cv_mem->cv_q > 2) + { + for (j = 2; j < cv_mem->cv_q; j++) + { + cv_mem->cv_cvals[j - 2] = -cv_mem->cv_l[j]; + } - (void) N_VScaleAddMulti(cv_mem->cv_q-2, cv_mem->cv_cvals, - cv_mem->cv_zn[cv_mem->cv_q], - cv_mem->cv_zn+2, cv_mem->cv_zn+2); + (void)N_VScaleAddMulti(cv_mem->cv_q - 2, cv_mem->cv_cvals, + cv_mem->cv_zn[cv_mem->cv_q], cv_mem->cv_zn + 2, + cv_mem->cv_zn + 2); if (cv_mem->cv_quadr) - (void) N_VScaleAddMulti(cv_mem->cv_q-2, cv_mem->cv_cvals, - cv_mem->cv_znQ[cv_mem->cv_q], - cv_mem->cv_znQ+2, cv_mem->cv_znQ+2); + { + (void)N_VScaleAddMulti(cv_mem->cv_q - 2, cv_mem->cv_cvals, + cv_mem->cv_znQ[cv_mem->cv_q], cv_mem->cv_znQ + 2, + cv_mem->cv_znQ + 2); + } if (cv_mem->cv_sensi) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q-2, - cv_mem->cv_cvals, - cv_mem->cv_znS[cv_mem->cv_q], - cv_mem->cv_znS+2, - cv_mem->cv_znS+2); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q - 2, + cv_mem->cv_cvals, + cv_mem->cv_znS[cv_mem->cv_q], + cv_mem->cv_znS + 2, cv_mem->cv_znS + 2); + } } - } /* @@ -5640,13 +6234,10 @@ static void cvAdjustAdams(CVodeMem cv_mem, int deltaq) static void cvAdjustBDF(CVodeMem cv_mem, int deltaq) { - switch(deltaq) { - case 1: - cvIncreaseBDF(cv_mem); - return; - case -1: - cvDecreaseBDF(cv_mem); - return; + switch (deltaq) + { + case 1: cvIncreaseBDF(cv_mem); return; + case -1: cvDecreaseBDF(cv_mem); return; } } @@ -5664,23 +6255,27 @@ static void cvAdjustBDF(CVodeMem cv_mem, int deltaq) static void cvIncreaseBDF(CVodeMem cv_mem) { - realtype alpha0, alpha1, prod, xi, xiold, hsum, A1; + sunrealtype alpha0, alpha1, prod, xi, xiold, hsum, A1; int i, j; int is; - for (i=0; i <= cv_mem->cv_qmax; i++) cv_mem->cv_l[i] = ZERO; + for (i = 0; i <= cv_mem->cv_qmax; i++) { cv_mem->cv_l[i] = ZERO; } cv_mem->cv_l[2] = alpha1 = prod = xiold = ONE; - alpha0 = -ONE; - hsum = cv_mem->cv_hscale; - if (cv_mem->cv_q > 1) { - for (j=1; j < cv_mem->cv_q; j++) { - hsum += cv_mem->cv_tau[j+1]; + alpha0 = -ONE; + hsum = cv_mem->cv_hscale; + if (cv_mem->cv_q > 1) + { + for (j = 1; j < cv_mem->cv_q; j++) + { + hsum += cv_mem->cv_tau[j + 1]; xi = hsum / cv_mem->cv_hscale; prod *= xi; - alpha0 -= ONE / (j+1); + alpha0 -= ONE / (j + 1); alpha1 += ONE / xi; - for (i=j+2; i >= 2; i--) - cv_mem->cv_l[i] = cv_mem->cv_l[i]*xiold + cv_mem->cv_l[i-1]; + for (i = j + 2; i >= 2; i--) + { + cv_mem->cv_l[i] = cv_mem->cv_l[i] * xiold + cv_mem->cv_l[i - 1]; + } xiold = xi; } } @@ -5694,62 +6289,65 @@ static void cvIncreaseBDF(CVodeMem cv_mem) A1 contains dbar = (1/xi* - 1/xi_q)/prod(xi_j) */ - N_VScale(A1, cv_mem->cv_zn[cv_mem->cv_indx_acor], - cv_mem->cv_zn[cv_mem->cv_L]); + N_VScale(A1, cv_mem->cv_zn[cv_mem->cv_indx_acor], cv_mem->cv_zn[cv_mem->cv_L]); /* for (j=2; j <= cv_mem->cv_q; j++) */ if (cv_mem->cv_q > 1) - (void) N_VScaleAddMulti(cv_mem->cv_q-1, cv_mem->cv_l+2, - cv_mem->cv_zn[cv_mem->cv_L], - cv_mem->cv_zn+2, cv_mem->cv_zn+2); + { + (void)N_VScaleAddMulti(cv_mem->cv_q - 1, cv_mem->cv_l + 2, + cv_mem->cv_zn[cv_mem->cv_L], cv_mem->cv_zn + 2, + cv_mem->cv_zn + 2); + } - if (cv_mem->cv_quadr) { + if (cv_mem->cv_quadr) + { N_VScale(A1, cv_mem->cv_znQ[cv_mem->cv_indx_acor], cv_mem->cv_znQ[cv_mem->cv_L]); /* for (j=2; j <= cv_mem->cv_q; j++) */ if (cv_mem->cv_q > 1) - (void) N_VScaleAddMulti(cv_mem->cv_q-1, cv_mem->cv_l+2, - cv_mem->cv_znQ[cv_mem->cv_L], - cv_mem->cv_znQ+2, cv_mem->cv_znQ+2); + { + (void)N_VScaleAddMulti(cv_mem->cv_q - 1, cv_mem->cv_l + 2, + cv_mem->cv_znQ[cv_mem->cv_L], cv_mem->cv_znQ + 2, + cv_mem->cv_znQ + 2); + } } - if (cv_mem->cv_sensi) { - - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = A1; + if (cv_mem->cv_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = A1; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znS[cv_mem->cv_indx_acor], - cv_mem->cv_znS[cv_mem->cv_L]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znS[cv_mem->cv_indx_acor], + cv_mem->cv_znS[cv_mem->cv_L]); /* for (j=2; j <= cv_mem->cv_q; j++) */ if (cv_mem->cv_q > 1) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q-1, - cv_mem->cv_l+2, - cv_mem->cv_znS[cv_mem->cv_L], - cv_mem->cv_znS+2, - cv_mem->cv_znS+2); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q - 1, + cv_mem->cv_l + 2, + cv_mem->cv_znS[cv_mem->cv_L], + cv_mem->cv_znS + 2, cv_mem->cv_znS + 2); + } } - if (cv_mem->cv_quadr_sensi) { - - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = A1; + if (cv_mem->cv_quadr_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = A1; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_znQS[cv_mem->cv_indx_acor], - cv_mem->cv_znQS[cv_mem->cv_L]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_znQS[cv_mem->cv_indx_acor], + cv_mem->cv_znQS[cv_mem->cv_L]); /* for (j=2; j <= cv_mem->cv_q; j++) */ if (cv_mem->cv_q > 1) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q-1, - cv_mem->cv_l+2, - cv_mem->cv_znQS[cv_mem->cv_L], - cv_mem->cv_znQS+2, - cv_mem->cv_znQS+2); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q - 1, + cv_mem->cv_l + 2, + cv_mem->cv_znQS[cv_mem->cv_L], + cv_mem->cv_znQS + 2, cv_mem->cv_znQS + 2); + } } - } /* @@ -5764,48 +6362,56 @@ static void cvIncreaseBDF(CVodeMem cv_mem) static void cvDecreaseBDF(CVodeMem cv_mem) { - realtype hsum, xi; + sunrealtype hsum, xi; int i, j; - for (i=0; i <= cv_mem->cv_qmax; i++) cv_mem->cv_l[i] = ZERO; + for (i = 0; i <= cv_mem->cv_qmax; i++) { cv_mem->cv_l[i] = ZERO; } cv_mem->cv_l[2] = ONE; - hsum = ZERO; - for (j=1; j <= cv_mem->cv_q-2; j++) { + hsum = ZERO; + for (j = 1; j <= cv_mem->cv_q - 2; j++) + { hsum += cv_mem->cv_tau[j]; xi = hsum / cv_mem->cv_hscale; - for (i=j+2; i >= 2; i--) - cv_mem->cv_l[i] = cv_mem->cv_l[i]*xi + cv_mem->cv_l[i-1]; + for (i = j + 2; i >= 2; i--) + { + cv_mem->cv_l[i] = cv_mem->cv_l[i] * xi + cv_mem->cv_l[i - 1]; + } } - if (cv_mem->cv_q > 2) { - - for (j=2; j < cv_mem->cv_q; j++) - cv_mem->cv_cvals[j-2] = -cv_mem->cv_l[j]; + if (cv_mem->cv_q > 2) + { + for (j = 2; j < cv_mem->cv_q; j++) + { + cv_mem->cv_cvals[j - 2] = -cv_mem->cv_l[j]; + } - (void) N_VScaleAddMulti(cv_mem->cv_q-2, cv_mem->cv_cvals, - cv_mem->cv_zn[cv_mem->cv_q], - cv_mem->cv_zn+2, cv_mem->cv_zn+2); + (void)N_VScaleAddMulti(cv_mem->cv_q - 2, cv_mem->cv_cvals, + cv_mem->cv_zn[cv_mem->cv_q], cv_mem->cv_zn + 2, + cv_mem->cv_zn + 2); if (cv_mem->cv_quadr) - (void) N_VScaleAddMulti(cv_mem->cv_q-2, cv_mem->cv_cvals, - cv_mem->cv_znQ[cv_mem->cv_q], - cv_mem->cv_znQ+2, cv_mem->cv_znQ+2); + { + (void)N_VScaleAddMulti(cv_mem->cv_q - 2, cv_mem->cv_cvals, + cv_mem->cv_znQ[cv_mem->cv_q], cv_mem->cv_znQ + 2, + cv_mem->cv_znQ + 2); + } if (cv_mem->cv_sensi) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q-2, - cv_mem->cv_cvals, - cv_mem->cv_znS[cv_mem->cv_q], - cv_mem->cv_znS+2, - cv_mem->cv_znS+2); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q - 2, + cv_mem->cv_cvals, + cv_mem->cv_znS[cv_mem->cv_q], + cv_mem->cv_znS + 2, cv_mem->cv_znS + 2); + } if (cv_mem->cv_quadr_sensi) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q-2, - cv_mem->cv_cvals, - cv_mem->cv_znQS[cv_mem->cv_q], - cv_mem->cv_znQS+2, - cv_mem->cv_znQS+2); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q - 2, + cv_mem->cv_cvals, + cv_mem->cv_znQS[cv_mem->cv_q], + cv_mem->cv_znQS + 2, cv_mem->cv_znQS + 2); + } } - } /* @@ -5816,55 +6422,76 @@ static void cvDecreaseBDF(CVodeMem cv_mem) * h is rescaled by eta, and hscale is reset to h. */ -static void cvRescale(CVodeMem cv_mem) +void cvRescale(CVodeMem cv_mem) { int j; int is; /* compute scaling factors */ cv_mem->cv_cvals[0] = cv_mem->cv_eta; - for (j=1; j <= cv_mem->cv_q; j++) - cv_mem->cv_cvals[j] = cv_mem->cv_eta * cv_mem->cv_cvals[j-1]; + for (j = 1; j <= cv_mem->cv_q; j++) + { + cv_mem->cv_cvals[j] = cv_mem->cv_eta * cv_mem->cv_cvals[j - 1]; + } - (void) N_VScaleVectorArray(cv_mem->cv_q, cv_mem->cv_cvals, - cv_mem->cv_zn+1, cv_mem->cv_zn+1); + (void)N_VScaleVectorArray(cv_mem->cv_q, cv_mem->cv_cvals, cv_mem->cv_zn + 1, + cv_mem->cv_zn + 1); if (cv_mem->cv_quadr) - (void) N_VScaleVectorArray(cv_mem->cv_q, cv_mem->cv_cvals, - cv_mem->cv_znQ+1, cv_mem->cv_znQ+1); + { + (void)N_VScaleVectorArray(cv_mem->cv_q, cv_mem->cv_cvals, + cv_mem->cv_znQ + 1, cv_mem->cv_znQ + 1); + } /* compute sensi scaling factors */ - if (cv_mem->cv_sensi || cv_mem->cv_quadr_sensi) { - for (is=0; iscv_Ns; is++) + if (cv_mem->cv_sensi || cv_mem->cv_quadr_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_eta; - for (j=1; j <= cv_mem->cv_q; j++) - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[j*cv_mem->cv_Ns+is] = - cv_mem->cv_eta * cv_mem->cv_cvals[(j-1)*cv_mem->cv_Ns+is]; + } + for (j = 1; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_cvals[j * cv_mem->cv_Ns + is] = + cv_mem->cv_eta * cv_mem->cv_cvals[(j - 1) * cv_mem->cv_Ns + is]; + } + } } - if (cv_mem->cv_sensi) { - for (j=1; j <= cv_mem->cv_q; j++) - for (is=0; iscv_Ns; is++) - cv_mem->cv_Xvecs[(j-1)*cv_mem->cv_Ns+is] = cv_mem->cv_znS[j][is]; + if (cv_mem->cv_sensi) + { + for (j = 1; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_Xvecs[(j - 1) * cv_mem->cv_Ns + is] = cv_mem->cv_znS[j][is]; + } + } - (void) N_VScaleVectorArray(cv_mem->cv_q*cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Xvecs); + (void)N_VScaleVectorArray(cv_mem->cv_q * cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_Xvecs, cv_mem->cv_Xvecs); } - if (cv_mem->cv_quadr_sensi) { - for (j=1; j <= cv_mem->cv_q; j++) - for (is=0; iscv_Ns; is++) - cv_mem->cv_Xvecs[(j-1)*cv_mem->cv_Ns+is] = cv_mem->cv_znQS[j][is]; + if (cv_mem->cv_quadr_sensi) + { + for (j = 1; j <= cv_mem->cv_q; j++) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + cv_mem->cv_Xvecs[(j - 1) * cv_mem->cv_Ns + is] = cv_mem->cv_znQS[j][is]; + } + } - (void) N_VScaleVectorArray(cv_mem->cv_q*cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_Xvecs, cv_mem->cv_Xvecs); + (void)N_VScaleVectorArray(cv_mem->cv_q * cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_Xvecs, cv_mem->cv_Xvecs); } - cv_mem->cv_h = cv_mem->cv_hscale * cv_mem->cv_eta; + cv_mem->cv_h = cv_mem->cv_hscale * cv_mem->cv_eta; cv_mem->cv_next_h = cv_mem->cv_h; cv_mem->cv_hscale = cv_mem->cv_h; - cv_mem->cv_nscon = 0; + cv_mem->cv_nscon = 0; } /* @@ -5879,44 +6506,94 @@ static void cvRescale(CVodeMem cv_mem) static void cvPredict(CVodeMem cv_mem) { +#ifdef SUNDIALS_LOGGING_EXTRA_DEBUG + int i; +#endif int j, k; cv_mem->cv_tn += cv_mem->cv_h; - if (cv_mem->cv_tstopset) { - if ((cv_mem->cv_tn - cv_mem->cv_tstop)*cv_mem->cv_h > ZERO) + if (cv_mem->cv_tstopset) + { + if ((cv_mem->cv_tn - cv_mem->cv_tstop) * cv_mem->cv_h > ZERO) + { cv_mem->cv_tn = cv_mem->cv_tstop; + } } for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - N_VLinearSum(ONE, cv_mem->cv_zn[j-1], ONE, - cv_mem->cv_zn[j], cv_mem->cv_zn[j-1]); + { + N_VLinearSum(ONE, cv_mem->cv_zn[j - 1], ONE, cv_mem->cv_zn[j], + cv_mem->cv_zn[j - 1]); + } + } - if (cv_mem->cv_quadr) { +#ifdef SUNDIALS_LOGGING_EXTRA_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvPredict", + "forward", "zn_0(:) =", ""); + N_VPrintFile(cv_mem->cv_zn[0], CV_LOGGER->debug_fp); +#endif + + if (cv_mem->cv_quadr) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - N_VLinearSum(ONE, cv_mem->cv_znQ[j-1], ONE, - cv_mem->cv_znQ[j], cv_mem->cv_znQ[j-1]); + { + N_VLinearSum(ONE, cv_mem->cv_znQ[j - 1], ONE, cv_mem->cv_znQ[j], + cv_mem->cv_znQ[j - 1]); + } + } + +#ifdef SUNDIALS_LOGGING_EXTRA_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvPredict", + "quad", "znQ_0(:) =", ""); + N_VPrintFile(cv_mem->cv_znQ[0], CV_LOGGER->debug_fp); +#endif } - if (cv_mem->cv_sensi) { + if (cv_mem->cv_sensi) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[j-1], - ONE, cv_mem->cv_znS[j], - cv_mem->cv_znS[j-1]); + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[j - 1], + ONE, cv_mem->cv_znS[j], + cv_mem->cv_znS[j - 1]); +#ifdef SUNDIALS_LOGGING_EXTRA_DEBUG + for (i = 0; i < cv_mem->cv_Ns; i++) + { + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvPredict", + "sensi", " i = %d, znS_i(:) = ", i); + N_VPrintFile(cv_mem->cv_znS[0][i], CV_LOGGER->debug_fp); + } +#endif + } + } } - if (cv_mem->cv_quadr_sensi) { + if (cv_mem->cv_quadr_sensi) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znQS[j-1], - ONE, cv_mem->cv_znQS[j], - cv_mem->cv_znQS[j-1]); + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znQS[j - 1], + ONE, cv_mem->cv_znQS[j], + cv_mem->cv_znQS[j - 1]); +#ifdef SUNDIALS_LOGGING_EXTRA_DEBUG + for (i = 0; i < cv_mem->cv_Ns; i++) + { + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvPredict", + "quad-sensi", " i = %d, znQS_i(:) = ", i); + N_VPrintFile(cv_mem->cv_znQS[0][i], CV_LOGGER->debug_fp); + } +#endif + } + } } - } /* @@ -5939,19 +6616,16 @@ static void cvPredict(CVodeMem cv_mem) static void cvSet(CVodeMem cv_mem) { - switch(cv_mem->cv_lmm) { - case CV_ADAMS: - cvSetAdams(cv_mem); - break; - case CV_BDF: - cvSetBDF(cv_mem); - break; + switch (cv_mem->cv_lmm) + { + case CV_ADAMS: cvSetAdams(cv_mem); break; + case CV_BDF: cvSetBDF(cv_mem); break; } - cv_mem->cv_rl1 = ONE / cv_mem->cv_l[1]; + cv_mem->cv_rl1 = ONE / cv_mem->cv_l[1]; cv_mem->cv_gamma = cv_mem->cv_h * cv_mem->cv_rl1; - if (cv_mem->cv_nst == 0) cv_mem->cv_gammap = cv_mem->cv_gamma; - cv_mem->cv_gamrat = (cv_mem->cv_nst > 0) ? - cv_mem->cv_gamma / cv_mem->cv_gammap : ONE; /* protect x / x != 1.0 */ + if (cv_mem->cv_nst == 0) { cv_mem->cv_gammap = cv_mem->cv_gamma; } + cv_mem->cv_gamrat = (cv_mem->cv_nst > 0) ? cv_mem->cv_gamma / cv_mem->cv_gammap + : ONE; /* protect x / x != 1.0 */ } /* @@ -5974,20 +6648,21 @@ static void cvSet(CVodeMem cv_mem) static void cvSetAdams(CVodeMem cv_mem) { - realtype m[L_MAX], M[3], hsum; + sunrealtype m[L_MAX], M[3], hsum; - if (cv_mem->cv_q == 1) { + if (cv_mem->cv_q == 1) + { cv_mem->cv_l[0] = cv_mem->cv_l[1] = cv_mem->cv_tq[1] = cv_mem->cv_tq[5] = ONE; cv_mem->cv_tq[2] = HALF; - cv_mem->cv_tq[3] = ONE/TWELVE; - cv_mem->cv_tq[4] = cv_mem->cv_nlscoef / cv_mem->cv_tq[2]; /* = 0.1 / tq[2] */ + cv_mem->cv_tq[3] = ONE / TWELVE; + cv_mem->cv_tq[4] = cv_mem->cv_nlscoef / cv_mem->cv_tq[2]; /* = 0.1 / tq[2] */ return; } hsum = cvAdamsStart(cv_mem, m); - M[0] = cvAltSum(cv_mem->cv_q-1, m, 1); - M[1] = cvAltSum(cv_mem->cv_q-1, m, 2); + M[0] = cvAltSum(cv_mem->cv_q - 1, m, 1); + M[1] = cvAltSum(cv_mem->cv_q - 1, m, 2); cvAdamsFinish(cv_mem, m, M, hsum); } @@ -5999,25 +6674,27 @@ static void cvSetAdams(CVodeMem cv_mem) * polynomial needed for the Adams l and tq coefficients for q > 1. */ -static realtype cvAdamsStart(CVodeMem cv_mem, realtype m[]) +static sunrealtype cvAdamsStart(CVodeMem cv_mem, sunrealtype m[]) { - realtype hsum, xi_inv, sum; + sunrealtype hsum, xi_inv, sum; int i, j; hsum = cv_mem->cv_h; m[0] = ONE; - for (i=1; i <= cv_mem->cv_q; i++) m[i] = ZERO; - for (j=1; j < cv_mem->cv_q; j++) { - if ((j==cv_mem->cv_q-1) && (cv_mem->cv_qwait == 1)) { - sum = cvAltSum(cv_mem->cv_q-2, m, 2); - cv_mem->cv_tq[1] = cv_mem->cv_q * sum / m[cv_mem->cv_q-2]; + for (i = 1; i <= cv_mem->cv_q; i++) { m[i] = ZERO; } + for (j = 1; j < cv_mem->cv_q; j++) + { + if ((j == cv_mem->cv_q - 1) && (cv_mem->cv_qwait == 1)) + { + sum = cvAltSum(cv_mem->cv_q - 2, m, 2); + cv_mem->cv_tq[1] = cv_mem->cv_q * sum / m[cv_mem->cv_q - 2]; } xi_inv = cv_mem->cv_h / hsum; - for (i=j; i >= 1; i--) m[i] += m[i-1] * xi_inv; + for (i = j; i >= 1; i--) { m[i] += m[i - 1] * xi_inv; } hsum += cv_mem->cv_tau[j]; /* The m[i] are coefficients of product(1 to j) (1 + x/xi_i) */ } - return(hsum); + return (hsum); } /* @@ -6026,25 +6703,29 @@ static realtype cvAdamsStart(CVodeMem cv_mem, realtype m[]) * This routine completes the calculation of the Adams l and tq. */ -static void cvAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype hsum) +static void cvAdamsFinish(CVodeMem cv_mem, sunrealtype m[], sunrealtype M[], + sunrealtype hsum) { int i; - realtype M0_inv, xi, xi_inv; + sunrealtype M0_inv, xi, xi_inv; M0_inv = ONE / M[0]; cv_mem->cv_l[0] = ONE; - for (i=1; i <= cv_mem->cv_q; i++) - cv_mem->cv_l[i] = M0_inv * (m[i-1] / i); - xi = hsum / cv_mem->cv_h; + for (i = 1; i <= cv_mem->cv_q; i++) + { + cv_mem->cv_l[i] = M0_inv * (m[i - 1] / i); + } + xi = hsum / cv_mem->cv_h; xi_inv = ONE / xi; cv_mem->cv_tq[2] = M[1] * M0_inv / xi; cv_mem->cv_tq[5] = xi / cv_mem->cv_l[cv_mem->cv_q]; - if (cv_mem->cv_qwait == 1) { - for (i=cv_mem->cv_q; i >= 1; i--) m[i] += m[i-1] * xi_inv; - M[2] = cvAltSum(cv_mem->cv_q, m, 2); + if (cv_mem->cv_qwait == 1) + { + for (i = cv_mem->cv_q; i >= 1; i--) { m[i] += m[i - 1] * xi_inv; } + M[2] = cvAltSum(cv_mem->cv_q, m, 2); cv_mem->cv_tq[3] = M[2] * M0_inv / cv_mem->cv_L; } @@ -6061,20 +6742,21 @@ static void cvAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype * of a polynomial x^(k-1) M(x) given the coefficients of M(x). */ -static realtype cvAltSum(int iend, realtype a[], int k) +static sunrealtype cvAltSum(int iend, sunrealtype a[], int k) { int i, sign; - realtype sum; + sunrealtype sum; - if (iend < 0) return(ZERO); + if (iend < 0) { return (ZERO); } - sum = ZERO; + sum = ZERO; sign = 1; - for (i=0; i <= iend; i++) { - sum += sign * (a[i] / (i+k)); + for (i = 0; i <= iend; i++) + { + sum += sign * (a[i] / (i + k)); sign = -sign; } - return(sum); + return (sum); } /* @@ -6089,7 +6771,15 @@ static realtype cvAltSum(int iend, realtype a[], int k) * q-1 * Lambda(x) = (1 + x / xi*_q) * PRODUCT (1 + x / xi_i) , where * i=1 - * xi_i = [t_n - t_(n-i)] / h. + * + * The components of the array p (for projections) are the + * coefficients of a polynomial Phi(x) = p_0 + p_1 x + ... + p_q x^q, + * given by + * q + * Phi(x) = PRODUCT (1 + x / xi_i) + * i=1 + * + * Here xi_i = [t_n - t_(n-i)] / h. * * The array tq is set to test quantities used in the convergence * test, the error test, and the selection of h at a new order. @@ -6097,30 +6787,52 @@ static realtype cvAltSum(int iend, realtype a[], int k) static void cvSetBDF(CVodeMem cv_mem) { - realtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum; - int i,j; + sunrealtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum; + int i, j; cv_mem->cv_l[0] = cv_mem->cv_l[1] = xi_inv = xistar_inv = ONE; - for (i=2; i <= cv_mem->cv_q; i++) cv_mem->cv_l[i] = ZERO; + for (i = 2; i <= cv_mem->cv_q; i++) { cv_mem->cv_l[i] = ZERO; } alpha0 = alpha0_hat = -ONE; - hsum = cv_mem->cv_h; - if (cv_mem->cv_q > 1) { - for (j=2; j < cv_mem->cv_q; j++) { - hsum += cv_mem->cv_tau[j-1]; + hsum = cv_mem->cv_h; + + if (cv_mem->proj_enabled) + { + for (i = 0; i <= cv_mem->cv_q; i++) { cv_mem->proj_p[i] = cv_mem->cv_l[i]; } + } + + if (cv_mem->cv_q > 1) + { + for (j = 2; j < cv_mem->cv_q; j++) + { + hsum += cv_mem->cv_tau[j - 1]; xi_inv = cv_mem->cv_h / hsum; alpha0 -= ONE / j; - for (i=j; i >= 1; i--) cv_mem->cv_l[i] += cv_mem->cv_l[i-1]*xi_inv; + for (i = j; i >= 1; i--) + { + cv_mem->cv_l[i] += cv_mem->cv_l[i - 1] * xi_inv; + } /* The l[i] are coefficients of product(1 to j) (1 + x/xi_i) */ } /* j = q */ alpha0 -= ONE / cv_mem->cv_q; xistar_inv = -cv_mem->cv_l[1] - alpha0; - hsum += cv_mem->cv_tau[cv_mem->cv_q-1]; - xi_inv = cv_mem->cv_h / hsum; + hsum += cv_mem->cv_tau[cv_mem->cv_q - 1]; + xi_inv = cv_mem->cv_h / hsum; alpha0_hat = -cv_mem->cv_l[1] - xi_inv; - for (i=cv_mem->cv_q; i >= 1; i--) - cv_mem->cv_l[i] += cv_mem->cv_l[i-1]*xistar_inv; + + if (cv_mem->proj_enabled) + { + for (i = cv_mem->cv_q; i >= 1; i--) + { + cv_mem->proj_p[i] = cv_mem->cv_l[i] + cv_mem->proj_p[i - 1] * xi_inv; + } + } + + for (i = cv_mem->cv_q; i >= 1; i--) + { + cv_mem->cv_l[i] += cv_mem->cv_l[i - 1] * xistar_inv; + } } cvSetTqBDF(cv_mem, hsum, alpha0, alpha0_hat, xi_inv, xistar_inv); @@ -6133,31 +6845,35 @@ static void cvSetBDF(CVodeMem cv_mem) * lmm == CV_BDF. */ -static void cvSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, - realtype alpha0_hat, realtype xi_inv, realtype xistar_inv) +static void cvSetTqBDF(CVodeMem cv_mem, sunrealtype hsum, sunrealtype alpha0, + sunrealtype alpha0_hat, sunrealtype xi_inv, + sunrealtype xistar_inv) { - realtype A1, A2, A3, A4, A5, A6; - realtype C, Cpinv, Cppinv; + sunrealtype A1, A2, A3, A4, A5, A6; + sunrealtype C, Cpinv, Cppinv; - A1 = ONE - alpha0_hat + alpha0; - A2 = ONE + cv_mem->cv_q * A1; + A1 = ONE - alpha0_hat + alpha0; + A2 = ONE + cv_mem->cv_q * A1; cv_mem->cv_tq[2] = SUNRabs(A1 / (alpha0 * A2)); - cv_mem->cv_tq[5] = SUNRabs(A2 * xistar_inv / (cv_mem->cv_l[cv_mem->cv_q] * xi_inv)); - if (cv_mem->cv_qwait == 1) { - if (cv_mem->cv_q > 1) { - C = xistar_inv / cv_mem->cv_l[cv_mem->cv_q]; - A3 = alpha0 + ONE / cv_mem->cv_q; - A4 = alpha0_hat + xi_inv; - Cpinv = (ONE - A4 + A3) / A3; + cv_mem->cv_tq[5] = + SUNRabs(A2 * xistar_inv / (cv_mem->cv_l[cv_mem->cv_q] * xi_inv)); + if (cv_mem->cv_qwait == 1) + { + if (cv_mem->cv_q > 1) + { + C = xistar_inv / cv_mem->cv_l[cv_mem->cv_q]; + A3 = alpha0 + ONE / cv_mem->cv_q; + A4 = alpha0_hat + xi_inv; + Cpinv = (ONE - A4 + A3) / A3; cv_mem->cv_tq[1] = SUNRabs(C * Cpinv); } - else cv_mem->cv_tq[1] = ONE; + else { cv_mem->cv_tq[1] = ONE; } hsum += cv_mem->cv_tau[cv_mem->cv_q]; - xi_inv = cv_mem->cv_h / hsum; - A5 = alpha0 - (ONE / (cv_mem->cv_q+1)); - A6 = alpha0_hat - xi_inv; - Cppinv = (ONE - A6 + A5) / A2; - cv_mem->cv_tq[3] = SUNRabs(Cppinv / (xi_inv * (cv_mem->cv_q+2) * A5)); + xi_inv = cv_mem->cv_h / hsum; + A5 = alpha0 - (ONE / (cv_mem->cv_q + 1)); + A6 = alpha0_hat - xi_inv; + Cppinv = (ONE - A6 + A5) / A2; + cv_mem->cv_tq[3] = SUNRabs(Cppinv / (xi_inv * (cv_mem->cv_q + 2) * A5)); } cv_mem->cv_tq[4] = cv_mem->cv_nlscoef / cv_mem->cv_tq[2]; } @@ -6178,77 +6894,86 @@ static void cvSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, static int cvNls(CVodeMem cv_mem, int nflag) { int flag = CV_SUCCESS; - booleantype callSetup; - booleantype do_sensi_sim; - long int nni_inc; + sunbooleantype callSetup; + sunbooleantype do_sensi_sim; + long int nni_inc = 0; + long int nnf_inc = 0; /* Are we computing sensitivities with the CV_SIMULTANEOUS approach? */ - do_sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_SIMULTANEOUS)); + do_sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_SIMULTANEOUS)); /* Decide whether or not to call setup routine (if one exists) and */ /* set flag convfail (input to lsetup for its evaluation decision) */ - if (cv_mem->cv_lsetup) { - cv_mem->convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) ? - CV_NO_FAILURES : CV_FAIL_OTHER; + if (cv_mem->cv_lsetup) + { + cv_mem->convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) + ? CV_NO_FAILURES + : CV_FAIL_OTHER; callSetup = (nflag == PREV_CONV_FAIL) || (nflag == PREV_ERR_FAIL) || - (cv_mem->cv_nst == 0) || - (cv_mem->cv_nst >= cv_mem->cv_nstlp + cv_mem->cv_msbp) || - (SUNRabs(cv_mem->cv_gamrat-ONE) > DGMAX); + (cv_mem->cv_nst == 0) || + (cv_mem->cv_nst >= cv_mem->cv_nstlp + cv_mem->cv_msbp) || + (SUNRabs(cv_mem->cv_gamrat - ONE) > cv_mem->cv_dgmax_lsetup); /* Decide whether to force a call to setup */ - if (cv_mem->cv_forceSetup) { - callSetup = SUNTRUE; + if (cv_mem->cv_forceSetup) + { + callSetup = SUNTRUE; cv_mem->convfail = CV_FAIL_OTHER; } - } else { + } + else + { cv_mem->cv_crate = ONE; - cv_mem->cv_crateS = ONE; /* if NO lsetup all conv. rates are set to ONE */ - callSetup = SUNFALSE; + cv_mem->cv_crateS = ONE; /* if NO lsetup all conv. rates are set to ONE */ + callSetup = SUNFALSE; } /* initial guess for the correction to the predictor */ - if (do_sensi_sim) - N_VConst(ZERO, cv_mem->ycorSim); - else - N_VConst(ZERO, cv_mem->cv_acor); + if (do_sensi_sim) { N_VConst(ZERO, cv_mem->ycorSim); } + else { N_VConst(ZERO, cv_mem->cv_acor); } /* call nonlinear solver setup if it exists */ - if ((cv_mem->NLS)->ops->setup) { + if ((cv_mem->NLS)->ops->setup) + { if (do_sensi_sim) + { flag = SUNNonlinSolSetup(cv_mem->NLS, cv_mem->ycorSim, cv_mem); - else - flag = SUNNonlinSolSetup(cv_mem->NLS, cv_mem->cv_acor, cv_mem); + } + else { flag = SUNNonlinSolSetup(cv_mem->NLS, cv_mem->cv_acor, cv_mem); } - if (flag < 0) return(CV_NLS_SETUP_FAIL); - if (flag > 0) return(SUN_NLS_CONV_RECVR); + if (flag < 0) { return (CV_NLS_SETUP_FAIL); } + if (flag > 0) { return (SUN_NLS_CONV_RECVR); } } /* solve the nonlinear system */ - if (do_sensi_sim) { - + if (do_sensi_sim) + { flag = SUNNonlinSolSolve(cv_mem->NLSsim, cv_mem->zn0Sim, cv_mem->ycorSim, cv_mem->ewtSim, cv_mem->cv_tq[4], callSetup, cv_mem); - /* increment counter */ - nni_inc = 0; - (void) SUNNonlinSolGetNumIters(cv_mem->NLSsim, &(nni_inc)); + /* increment counters */ + (void)SUNNonlinSolGetNumIters(cv_mem->NLSsim, &nni_inc); cv_mem->cv_nni += nni_inc; - } else { - + (void)SUNNonlinSolGetNumConvFails(cv_mem->NLSsim, &nnf_inc); + cv_mem->cv_nnf += nnf_inc; + } + else + { flag = SUNNonlinSolSolve(cv_mem->NLS, cv_mem->cv_zn[0], cv_mem->cv_acor, cv_mem->cv_ewt, cv_mem->cv_tq[4], callSetup, cv_mem); - /* increment counter */ - nni_inc = 0; - (void) SUNNonlinSolGetNumIters(cv_mem->NLS, &(nni_inc)); + /* increment counters */ + (void)SUNNonlinSolGetNumIters(cv_mem->NLS, &nni_inc); cv_mem->cv_nni += nni_inc; + (void)SUNNonlinSolGetNumConvFails(cv_mem->NLS, &nnf_inc); + cv_mem->cv_nnf += nnf_inc; } /* if the solve failed return */ - if (flag != CV_SUCCESS) return(flag); + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ @@ -6256,28 +6981,29 @@ static int cvNls(CVodeMem cv_mem, int nflag) N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, cv_mem->cv_acor, cv_mem->cv_y); /* update the sensitivities based on the final correction from the nonlinear solver */ - if (do_sensi_sim) { - N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, cv_mem->cv_acorS, cv_mem->cv_yS); + if (do_sensi_sim) + { + N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + cv_mem->cv_acorS, cv_mem->cv_yS); } /* compute acnrm if is was not already done by the nonlinear solver */ - if (!cv_mem->cv_acnrmcur) { + if (!cv_mem->cv_acnrmcur) + { if (do_sensi_sim && cv_mem->cv_errconS) + { cv_mem->cv_acnrm = N_VWrmsNorm(cv_mem->ycorSim, cv_mem->ewtSim); - else - cv_mem->cv_acnrm = N_VWrmsNorm(cv_mem->cv_acor, cv_mem->cv_ewt); + } + else { cv_mem->cv_acnrm = N_VWrmsNorm(cv_mem->cv_acor, cv_mem->cv_ewt); } } /* update Jacobian status */ cv_mem->cv_jcur = SUNFALSE; /* check inequality constraints */ - if (cv_mem->cv_constraintsSet) - flag = cvCheckConstraints(cv_mem); + if (cv_mem->cv_constraintsSet) { flag = cvCheckConstraints(cv_mem); } - return(flag); + return (flag); } /* @@ -6297,14 +7023,14 @@ static int cvNls(CVodeMem cv_mem, int nflag) static int cvCheckConstraints(CVodeMem cv_mem) { - booleantype constraintsPassed; - realtype vnorm; + sunbooleantype constraintsPassed; + sunrealtype vnorm; N_Vector mm = cv_mem->cv_ftemp; N_Vector tmp = cv_mem->cv_tempv; /* Get mask vector mm, set where constraints failed */ constraintsPassed = N_VConstrMask(cv_mem->cv_constraints, cv_mem->cv_y, mm); - if (constraintsPassed) return(CV_SUCCESS); + if (constraintsPassed) { return (CV_SUCCESS); } /* Constraints not met */ @@ -6315,29 +7041,33 @@ static int cvCheckConstraints(CVodeMem cv_mem) N_VLinearSum(ONE, cv_mem->cv_y, -PT1, tmp, tmp); /* y - 0.1 * a * c * wt */ N_VProd(tmp, mm, tmp); /* v = mm*(y-0.1*a*c*wt) */ - vnorm = N_VWrmsNorm(tmp, cv_mem->cv_ewt); /* ||v|| */ + vnorm = N_VWrmsNorm(tmp, cv_mem->cv_ewt); /* ||v|| */ /* If vector v of constraint corrections is small in norm, correct and accept this step */ - if (vnorm <= cv_mem->cv_tq[4]) { - N_VLinearSum(ONE, cv_mem->cv_acor, - -ONE, tmp, cv_mem->cv_acor); /* acor <- acor - v */ - return(CV_SUCCESS); + if (vnorm <= cv_mem->cv_tq[4]) + { + N_VLinearSum(ONE, cv_mem->cv_acor, -ONE, tmp, + cv_mem->cv_acor); /* acor <- acor - v */ + return (CV_SUCCESS); } /* Return with error if |h| == hmin */ - if (SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin*ONEPSM) return(CV_CONSTR_FAIL); + if (SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin * ONEPSM) + { + return (CV_CONSTR_FAIL); + } /* Constraint correction is too large, reduce h by computing eta = h'/h */ N_VLinearSum(ONE, cv_mem->cv_zn[0], -ONE, cv_mem->cv_y, tmp); N_VProd(mm, tmp, tmp); - cv_mem->cv_eta = PT9*N_VMinQuotient(cv_mem->cv_zn[0], tmp); + cv_mem->cv_eta = PT9 * N_VMinQuotient(cv_mem->cv_zn[0], tmp); cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta, PT1); cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta, cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); /* Reattempt step with new step size */ - return(CONSTR_RECVR); + return (CONSTR_RECVR); } /* @@ -6361,26 +7091,27 @@ static int cvQuadNls(CVodeMem cv_mem) int retval; /* Save quadrature correction in acorQ */ - retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_y, - cv_mem->cv_acorQ, cv_mem->cv_user_data); + retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_y, cv_mem->cv_acorQ, + cv_mem->cv_user_data); cv_mem->cv_nfQe++; - if (retval < 0) return(CV_QRHSFUNC_FAIL); - if (retval > 0) return(QRHSFUNC_RECVR); + if (retval < 0) { return (CV_QRHSFUNC_FAIL); } + if (retval > 0) { return (QRHSFUNC_RECVR); } /* If needed, save the value of yQdot = fQ into ftempQ * for use in evaluating fQS */ - if (cv_mem->cv_quadr_sensi) { + if (cv_mem->cv_quadr_sensi) + { N_VScale(ONE, cv_mem->cv_acorQ, cv_mem->cv_ftempQ); } - N_VLinearSum(cv_mem->cv_h, cv_mem->cv_acorQ, -ONE, - cv_mem->cv_znQ[1], cv_mem->cv_acorQ); + N_VLinearSum(cv_mem->cv_h, cv_mem->cv_acorQ, -ONE, cv_mem->cv_znQ[1], + cv_mem->cv_acorQ); N_VScale(cv_mem->cv_rl1, cv_mem->cv_acorQ, cv_mem->cv_acorQ); /* Apply correction to quadrature variables */ N_VLinearSum(ONE, cv_mem->cv_znQ[0], ONE, cv_mem->cv_acorQ, cv_mem->cv_yQ); - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -6405,27 +7136,26 @@ static int cvQuadSensNls(CVodeMem cv_mem) /* Save quadrature correction in acorQ */ retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn, cv_mem->cv_y, - cv_mem->cv_yS, cv_mem->cv_ftempQ, - cv_mem->cv_acorQS, cv_mem->cv_user_data, - cv_mem->cv_tempv, cv_mem->cv_tempvQ); + cv_mem->cv_yS, cv_mem->cv_ftempQ, cv_mem->cv_acorQS, + cv_mem->cv_user_data, cv_mem->cv_tempv, + cv_mem->cv_tempvQ); cv_mem->cv_nfQSe++; - if (retval < 0) return(CV_QSRHSFUNC_FAIL); - if (retval > 0) return(QSRHSFUNC_RECVR); - + if (retval < 0) { return (CV_QSRHSFUNC_FAIL); } + if (retval > 0) { return (QSRHSFUNC_RECVR); } - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VLinearSum(cv_mem->cv_h, cv_mem->cv_acorQS[is], -ONE, cv_mem->cv_znQS[1][is], cv_mem->cv_acorQS[is]); N_VScale(cv_mem->cv_rl1, cv_mem->cv_acorQS[is], cv_mem->cv_acorQS[is]); /* Apply correction to quadrature sensitivity variables */ - N_VLinearSum(ONE, cv_mem->cv_znQS[0][is], ONE, - cv_mem->cv_acorQS[is], cv_mem->cv_yQS[is]); + N_VLinearSum(ONE, cv_mem->cv_znQS[0][is], ONE, cv_mem->cv_acorQS[is], + cv_mem->cv_yQS[is]); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * cvStgrNls * @@ -6436,13 +7166,13 @@ static int cvQuadSensNls(CVodeMem cv_mem) static int cvStgrNls(CVodeMem cv_mem) { - booleantype callSetup; - int flag=CV_SUCCESS; - long int nniS_inc; + sunbooleantype callSetup; + int flag = CV_SUCCESS; + long int nniS_inc = 0; + long int nnfS_inc = 0; callSetup = SUNFALSE; - if (cv_mem->cv_lsetup == NULL) - cv_mem->cv_crateS = ONE; + if (cv_mem->cv_lsetup == NULL) { cv_mem->cv_crateS = ONE; } /* initial guess for the correction to the predictor */ N_VConst(ZERO, cv_mem->ycorStg); @@ -6454,28 +7184,29 @@ static int cvStgrNls(CVodeMem cv_mem) flag = SUNNonlinSolSolve(cv_mem->NLSstg, cv_mem->zn0Stg, cv_mem->ycorStg, cv_mem->ewtStg, cv_mem->cv_tq[4], callSetup, cv_mem); - /* increment counter */ - nniS_inc = 0; - (void) SUNNonlinSolGetNumIters(cv_mem->NLSstg, &(nniS_inc)); + /* increment counters */ + (void)SUNNonlinSolGetNumIters(cv_mem->NLSstg, &nniS_inc); cv_mem->cv_nniS += nniS_inc; + (void)SUNNonlinSolGetNumConvFails(cv_mem->NLSstg, &nnfS_inc); + cv_mem->cv_nnfS += nnfS_inc; + /* reset sens solve flag */ cv_mem->sens_solve = SUNFALSE; /* if the solve failed return */ - if (flag != CV_SUCCESS) return(flag); + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ /* update the sensitivities based on the final correction from the nonlinear solver */ - N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, cv_mem->cv_acorS, cv_mem->cv_yS); + N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + cv_mem->cv_acorS, cv_mem->cv_yS); /* update Jacobian status */ cv_mem->cv_jcur = SUNFALSE; - return(flag); + return (flag); } /* @@ -6488,14 +7219,13 @@ static int cvStgrNls(CVodeMem cv_mem) static int cvStgr1Nls(CVodeMem cv_mem, int is) { - booleantype callSetup; - long int nniS1_inc; - int flag=CV_SUCCESS; - + sunbooleantype callSetup; + long int nniS1_inc = 0; + long int nnfS1_inc = 0; + int flag = CV_SUCCESS; callSetup = SUNFALSE; - if (cv_mem->cv_lsetup == NULL) - cv_mem->cv_crateS = ONE; + if (cv_mem->cv_lsetup == NULL) { cv_mem->cv_crateS = ONE; } /* initial guess for the correction to the predictor */ N_VConst(ZERO, cv_mem->cv_acorS[is]); @@ -6504,31 +7234,33 @@ static int cvStgr1Nls(CVodeMem cv_mem, int is) cv_mem->sens_solve = SUNTRUE; /* solve the nonlinear system */ - flag = SUNNonlinSolSolve(cv_mem->NLSstg1, - cv_mem->cv_znS[0][is], cv_mem->cv_acorS[is], - cv_mem->cv_ewtS[is], cv_mem->cv_tq[4], callSetup, cv_mem); + flag = SUNNonlinSolSolve(cv_mem->NLSstg1, cv_mem->cv_znS[0][is], + cv_mem->cv_acorS[is], cv_mem->cv_ewtS[is], + cv_mem->cv_tq[4], callSetup, cv_mem); - /* increment counter */ - nniS1_inc = 0; - (void) SUNNonlinSolGetNumIters(cv_mem->NLSstg1, &(nniS1_inc)); + /* increment counters */ + (void)SUNNonlinSolGetNumIters(cv_mem->NLSstg1, &nniS1_inc); cv_mem->cv_nniS1[is] += nniS1_inc; + (void)SUNNonlinSolGetNumConvFails(cv_mem->NLSstg1, &nnfS1_inc); + cv_mem->cv_nnfS1[is] += nnfS1_inc; + /* reset sens solve flag */ cv_mem->sens_solve = SUNFALSE; /* if the solve failed return */ - if (flag != CV_SUCCESS) return(flag); + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ /* update the sensitivity with the final correction from the nonlinear solver */ - N_VLinearSum(ONE, cv_mem->cv_znS[0][is], - ONE, cv_mem->cv_acorS[is], cv_mem->cv_yS[is]); + N_VLinearSum(ONE, cv_mem->cv_znS[0][is], ONE, cv_mem->cv_acorS[is], + cv_mem->cv_yS[is]); /* update Jacobian status */ cv_mem->cv_jcur = SUNFALSE; - return(flag); + return (flag); } /* @@ -6574,55 +7306,60 @@ static int cvStgr1Nls(CVodeMem cv_mem, int is) * */ -static int cvHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - int *ncfPtr, long int *ncfnPtr) +static int cvHandleNFlag(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + int* ncfPtr, long int* ncfnPtr) { int nflag; nflag = *nflagPtr; - if (nflag == CV_SUCCESS) return(DO_ERROR_TEST); + if (nflag == CV_SUCCESS) { return (DO_ERROR_TEST); } /* The nonlinear soln. failed; increment ncfn and restore zn */ (*ncfnPtr)++; cvRestore(cv_mem, saved_t); /* Return if failed unrecoverably */ - if (nflag < 0) { - if (nflag == CV_LSETUP_FAIL) return(CV_LSETUP_FAIL); - else if (nflag == CV_LSOLVE_FAIL) return(CV_LSOLVE_FAIL); - else if (nflag == CV_RHSFUNC_FAIL) return(CV_RHSFUNC_FAIL); - else if (nflag == CV_QRHSFUNC_FAIL) return(CV_QRHSFUNC_FAIL); - else if (nflag == CV_SRHSFUNC_FAIL) return(CV_SRHSFUNC_FAIL); - else if (nflag == CV_QSRHSFUNC_FAIL) return(CV_QSRHSFUNC_FAIL); - else return(CV_NLS_FAIL); + if (nflag < 0) + { + if (nflag == CV_LSETUP_FAIL) { return (CV_LSETUP_FAIL); } + else if (nflag == CV_LSOLVE_FAIL) { return (CV_LSOLVE_FAIL); } + else if (nflag == CV_RHSFUNC_FAIL) { return (CV_RHSFUNC_FAIL); } + else if (nflag == CV_QRHSFUNC_FAIL) { return (CV_QRHSFUNC_FAIL); } + else if (nflag == CV_SRHSFUNC_FAIL) { return (CV_SRHSFUNC_FAIL); } + else if (nflag == CV_QSRHSFUNC_FAIL) { return (CV_QSRHSFUNC_FAIL); } + else { return (CV_NLS_FAIL); } } - /* At this point, a recoverable error occured. */ + /* At this point, a recoverable error occurred. */ (*ncfPtr)++; cv_mem->cv_etamax = ONE; /* If we had maxncf failures or |h| = hmin, return failure. */ - if ((SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin*ONEPSM) || - (*ncfPtr == cv_mem->cv_maxncf)) { - if (nflag == SUN_NLS_CONV_RECVR) return(CV_CONV_FAILURE); - if (nflag == CONSTR_RECVR) return(CV_CONSTR_FAIL); - if (nflag == RHSFUNC_RECVR) return(CV_REPTD_RHSFUNC_ERR); - if (nflag == QRHSFUNC_RECVR) return(CV_REPTD_QRHSFUNC_ERR); - if (nflag == SRHSFUNC_RECVR) return(CV_REPTD_SRHSFUNC_ERR); - if (nflag == QSRHSFUNC_RECVR) return(CV_REPTD_QSRHSFUNC_ERR); + if ((SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin * ONEPSM) || + (*ncfPtr == cv_mem->cv_maxncf)) + { + if (nflag == SUN_NLS_CONV_RECVR) { return (CV_CONV_FAILURE); } + if (nflag == CONSTR_RECVR) { return (CV_CONSTR_FAIL); } + if (nflag == RHSFUNC_RECVR) { return (CV_REPTD_RHSFUNC_ERR); } + if (nflag == QRHSFUNC_RECVR) { return (CV_REPTD_QRHSFUNC_ERR); } + if (nflag == SRHSFUNC_RECVR) { return (CV_REPTD_SRHSFUNC_ERR); } + if (nflag == QSRHSFUNC_RECVR) { return (CV_REPTD_QSRHSFUNC_ERR); } } /* Reduce step size; return to reattempt the step Note that if nflag = CONSTR_RECVR, then eta was already set in cvCheckConstraints */ if (nflag != CONSTR_RECVR) - cv_mem->cv_eta = SUNMAX(ETACF, cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + { + cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta_cf, + cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + } *nflagPtr = PREV_CONV_FAIL; cvRescale(cv_mem); - return(PREDICT_AGAIN); + return (PREDICT_AGAIN); } /* @@ -6633,39 +7370,56 @@ static int cvHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, * the same values as before the call to cvPredict. */ -static void cvRestore(CVodeMem cv_mem, realtype saved_t) +void cvRestore(CVodeMem cv_mem, sunrealtype saved_t) { int j, k; cv_mem->cv_tn = saved_t; for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - N_VLinearSum(ONE, cv_mem->cv_zn[j-1], -ONE, - cv_mem->cv_zn[j], cv_mem->cv_zn[j-1]); + { + N_VLinearSum(ONE, cv_mem->cv_zn[j - 1], -ONE, cv_mem->cv_zn[j], + cv_mem->cv_zn[j - 1]); + } + } - if (cv_mem->cv_quadr) { + if (cv_mem->cv_quadr) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - N_VLinearSum(ONE, cv_mem->cv_znQ[j-1], -ONE, - cv_mem->cv_znQ[j], cv_mem->cv_znQ[j-1]); + { + N_VLinearSum(ONE, cv_mem->cv_znQ[j - 1], -ONE, cv_mem->cv_znQ[j], + cv_mem->cv_znQ[j - 1]); + } + } } - if (cv_mem->cv_sensi) { + if (cv_mem->cv_sensi) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[j-1], - -ONE, cv_mem->cv_znS[j], - cv_mem->cv_znS[j-1]); + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[j - 1], + -ONE, cv_mem->cv_znS[j], + cv_mem->cv_znS[j - 1]); + } + } } - if (cv_mem->cv_quadr_sensi) { + if (cv_mem->cv_quadr_sensi) + { for (k = 1; k <= cv_mem->cv_q; k++) + { for (j = cv_mem->cv_q; j >= k; j--) - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znQS[j-1], - -ONE, cv_mem->cv_znQS[j], - cv_mem->cv_znQS[j-1]); + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znQS[j - 1], + -ONE, cv_mem->cv_znQS[j], + cv_mem->cv_znQS[j - 1]); + } + } } } @@ -6704,19 +7458,25 @@ static void cvRestore(CVodeMem cv_mem, realtype saved_t) * */ -static int cvDoErrorTest(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - realtype acor_nrm, - int *nefPtr, long int *netfPtr, realtype *dsmPtr) +static int cvDoErrorTest(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + sunrealtype acor_nrm, int* nefPtr, long int* netfPtr, + sunrealtype* dsmPtr) { - realtype dsm; + sunrealtype dsm; int retval, is; N_Vector wrk1, wrk2; dsm = acor_nrm * cv_mem->cv_tq[2]; +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvDoErrorTest", + "error-test", "step = %li, h = %.16g, dsm = %.16g", + cv_mem->cv_nst, cv_mem->cv_h, dsm); +#endif + /* If est. local error norm dsm passes test, return CV_SUCCESS */ *dsmPtr = dsm; - if (dsm <= ONE) return(CV_SUCCESS); + if (dsm <= ONE) { return (CV_SUCCESS); } /* Test failed; increment counters, set nflag, and restore zn array */ (*nefPtr)++; @@ -6725,104 +7485,132 @@ static int cvDoErrorTest(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, cvRestore(cv_mem, saved_t); /* At maxnef failures or |h| = hmin, return CV_ERR_FAILURE */ - if ((SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin*ONEPSM) || + if ((SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin * ONEPSM) || (*nefPtr == cv_mem->cv_maxnef)) - return(CV_ERR_FAILURE); + { + return (CV_ERR_FAILURE); + } /* Set etamax = 1 to prevent step size increase at end of this step */ cv_mem->cv_etamax = ONE; /* Set h ratio eta from dsm, rescale, and return for retry of step */ - if (*nefPtr <= MXNEF1) { - cv_mem->cv_eta = ONE / (SUNRpowerR(BIAS2*dsm,ONE/cv_mem->cv_L) + ADDON); - cv_mem->cv_eta = SUNMAX(ETAMIN, SUNMAX(cv_mem->cv_eta, - cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h))); - if (*nefPtr >= SMALL_NEF) cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta, ETAMXF); + if (*nefPtr <= MXNEF1) + { + cv_mem->cv_eta = ONE / (SUNRpowerR(BIAS2 * dsm, ONE / cv_mem->cv_L) + ADDON); + cv_mem->cv_eta = + SUNMAX(cv_mem->cv_eta_min_ef, + SUNMAX(cv_mem->cv_eta, cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h))); + if (*nefPtr >= cv_mem->cv_small_nef) + { + cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta, cv_mem->cv_eta_max_ef); + } + cvRescale(cv_mem); - return(TRY_AGAIN); + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvDoErrorTest", + "new-step-eta", "eta = %.16g", cv_mem->cv_eta); +#endif + + return (TRY_AGAIN); } /* After MXNEF1 failures, force an order reduction and retry step */ - if (cv_mem->cv_q > 1) { - cv_mem->cv_eta = SUNMAX(ETAMIN, cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); - cvAdjustOrder(cv_mem,-1); + if (cv_mem->cv_q > 1) + { + cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta_min_ef, + cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + cvAdjustOrder(cv_mem, -1); cv_mem->cv_L = cv_mem->cv_q; cv_mem->cv_q--; cv_mem->cv_qwait = cv_mem->cv_L; cvRescale(cv_mem); - return(TRY_AGAIN); +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvDoErrorTest", + "new-step-eta-mxnef1", "eta = %.16g", cv_mem->cv_eta); +#endif + return (TRY_AGAIN); } /* If already at order 1, restart: reload zn, znQ, znS, znQS from scratch */ - cv_mem->cv_eta = SUNMAX(ETAMIN, cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta_min_ef, + cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); cv_mem->cv_h *= cv_mem->cv_eta; cv_mem->cv_next_h = cv_mem->cv_h; cv_mem->cv_hscale = cv_mem->cv_h; - cv_mem->cv_qwait = LONG_WAIT; - cv_mem->cv_nscon = 0; + cv_mem->cv_qwait = LONG_WAIT; + cv_mem->cv_nscon = 0; - retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_zn[0], - cv_mem->cv_tempv, cv_mem->cv_user_data); + retval = cv_mem->cv_f(cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_tempv, + cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(CV_UNREC_RHSFUNC_ERR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (CV_UNREC_RHSFUNC_ERR); } N_VScale(cv_mem->cv_h, cv_mem->cv_tempv, cv_mem->cv_zn[1]); - if (cv_mem->cv_quadr) { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvDoErrorTest", + "new-step-eta-mxnef1-q1", "eta = %.16g", cv_mem->cv_eta); +#endif - retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_zn[0], - cv_mem->cv_tempvQ, cv_mem->cv_user_data); + if (cv_mem->cv_quadr) + { + retval = cv_mem->cv_fQ(cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_tempvQ, + cv_mem->cv_user_data); cv_mem->cv_nfQe++; - if (retval < 0) return(CV_QRHSFUNC_FAIL); - if (retval > 0) return(CV_UNREC_QRHSFUNC_ERR); + if (retval < 0) { return (CV_QRHSFUNC_FAIL); } + if (retval > 0) { return (CV_UNREC_QRHSFUNC_ERR); } N_VScale(cv_mem->cv_h, cv_mem->cv_tempvQ, cv_mem->cv_znQ[1]); - } - if (cv_mem->cv_sensi) { - + if (cv_mem->cv_sensi) + { wrk1 = cv_mem->cv_ftemp; wrk2 = cv_mem->cv_ftempS[0]; retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_zn[0], cv_mem->cv_tempv, cv_mem->cv_znS[0], cv_mem->cv_tempvS, wrk1, wrk2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(CV_UNREC_SRHSFUNC_ERR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (CV_UNREC_SRHSFUNC_ERR); } - for (is=0; iscv_Ns; is++) + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_h; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_tempvS, cv_mem->cv_znS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - if (cv_mem->cv_quadr_sensi) { - + if (cv_mem->cv_quadr_sensi) + { wrk1 = cv_mem->cv_ftemp; wrk2 = cv_mem->cv_ftempQ; - retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn, - cv_mem->cv_zn[0], cv_mem->cv_znS[0], - cv_mem->cv_tempvQ, cv_mem->cv_tempvQS, - cv_mem->cv_fQS_data, wrk1, wrk2); + retval = cv_mem->cv_fQS(cv_mem->cv_Ns, cv_mem->cv_tn, cv_mem->cv_zn[0], + cv_mem->cv_znS[0], cv_mem->cv_tempvQ, + cv_mem->cv_tempvQS, cv_mem->cv_fQS_data, wrk1, wrk2); cv_mem->cv_nfQSe++; - if (retval < 0) return(CV_QSRHSFUNC_FAIL); - if (retval > 0) return(CV_UNREC_QSRHSFUNC_ERR); + if (retval < 0) { return (CV_QSRHSFUNC_FAIL); } + if (retval > 0) { return (CV_UNREC_QSRHSFUNC_ERR); } - for (is=0; iscv_Ns; is++) + for (is = 0; is < cv_mem->cv_Ns; is++) + { cv_mem->cv_cvals[is] = cv_mem->cv_h; + } retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_tempvQS, cv_mem->cv_znQS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } } - return(TRY_AGAIN); + return (TRY_AGAIN); } /* @@ -6853,28 +7641,47 @@ static void cvCompleteStep(CVodeMem cv_mem) cv_mem->cv_hu = cv_mem->cv_h; cv_mem->cv_qu = cv_mem->cv_q; - for (i=cv_mem->cv_q; i >= 2; i--) cv_mem->cv_tau[i] = cv_mem->cv_tau[i-1]; - if ((cv_mem->cv_q==1) && (cv_mem->cv_nst > 1)) + for (i = cv_mem->cv_q; i >= 2; i--) + { + cv_mem->cv_tau[i] = cv_mem->cv_tau[i - 1]; + } + if ((cv_mem->cv_q == 1) && (cv_mem->cv_nst > 1)) + { cv_mem->cv_tau[2] = cv_mem->cv_tau[1]; + } cv_mem->cv_tau[1] = cv_mem->cv_h; /* Apply correction to column j of zn: l_j * Delta_n */ - (void) N_VScaleAddMulti(cv_mem->cv_q+1, cv_mem->cv_l, cv_mem->cv_acor, - cv_mem->cv_zn, cv_mem->cv_zn); + (void)N_VScaleAddMulti(cv_mem->cv_q + 1, cv_mem->cv_l, cv_mem->cv_acor, + cv_mem->cv_zn, cv_mem->cv_zn); + + /* Apply the projection correction to column j of zn: p_j * Delta_n */ + if (cv_mem->proj_applied) + { + (void)N_VScaleAddMulti(cv_mem->cv_q + 1, cv_mem->proj_p, + cv_mem->cv_tempv, /* tempv = acorP */ + cv_mem->cv_zn, cv_mem->cv_zn); + } if (cv_mem->cv_quadr) - (void) N_VScaleAddMulti(cv_mem->cv_q+1, cv_mem->cv_l, cv_mem->cv_acorQ, - cv_mem->cv_znQ, cv_mem->cv_znQ); + { + (void)N_VScaleAddMulti(cv_mem->cv_q + 1, cv_mem->cv_l, cv_mem->cv_acorQ, + cv_mem->cv_znQ, cv_mem->cv_znQ); + } if (cv_mem->cv_sensi) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q+1, - cv_mem->cv_l, cv_mem->cv_acorS, - cv_mem->cv_znS, cv_mem->cv_znS); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q + 1, + cv_mem->cv_l, cv_mem->cv_acorS, + cv_mem->cv_znS, cv_mem->cv_znS); + } if (cv_mem->cv_quadr_sensi) - (void) N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q+1, - cv_mem->cv_l, cv_mem->cv_acorQS, - cv_mem->cv_znQS, cv_mem->cv_znQS); + { + (void)N_VScaleAddMultiVectorArray(cv_mem->cv_Ns, cv_mem->cv_q + 1, + cv_mem->cv_l, cv_mem->cv_acorQS, + cv_mem->cv_znQS, cv_mem->cv_znQS); + } /* If necessary, store Delta_n in zn[qmax] to be used in order increase. * This actually will be Delta_{n-1} in the ELTE at q+1 since it happens at @@ -6882,32 +7689,50 @@ static void cvCompleteStep(CVodeMem cv_mem) */ cv_mem->cv_qwait--; - if ((cv_mem->cv_qwait == 1) && (cv_mem->cv_q != cv_mem->cv_qmax)) { - + if ((cv_mem->cv_qwait == 1) && (cv_mem->cv_q != cv_mem->cv_qmax)) + { N_VScale(ONE, cv_mem->cv_acor, cv_mem->cv_zn[cv_mem->cv_qmax]); if (cv_mem->cv_quadr) + { N_VScale(ONE, cv_mem->cv_acorQ, cv_mem->cv_znQ[cv_mem->cv_qmax]); + } - if (cv_mem->cv_sensi) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_acorS, cv_mem->cv_znS[cv_mem->cv_qmax]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_acorS, + cv_mem->cv_znS[cv_mem->cv_qmax]); } - if (cv_mem->cv_quadr_sensi) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_quadr_sensi) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_acorQS, cv_mem->cv_znQS[cv_mem->cv_qmax]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_acorQS, + cv_mem->cv_znQS[cv_mem->cv_qmax]); } cv_mem->cv_saved_tq5 = cv_mem->cv_tq[5]; cv_mem->cv_indx_acor = cv_mem->cv_qmax; } + +#ifdef SUNDIALS_BUILD_WITH_MONITORING + /* If user access function was provided, call it now */ + if (cv_mem->cv_monitorfun != NULL && + !(cv_mem->cv_nst % cv_mem->cv_monitor_interval)) + { + cv_mem->cv_monitorfun((void*)cv_mem, cv_mem->cv_user_data); + } +#endif + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvCompleteStep", + "return", "nst = %d, nscon = %d", cv_mem->cv_nst, + cv_mem->cv_nscon); +#endif } /* @@ -6919,36 +7744,48 @@ static void cvCompleteStep(CVodeMem cv_mem) * related to a change of step size or order. */ -static void cvPrepareNextStep(CVodeMem cv_mem, realtype dsm) +static void cvPrepareNextStep(CVodeMem cv_mem, sunrealtype dsm) { /* If etamax = 1, defer step size or order changes */ - if (cv_mem->cv_etamax == ONE) { - cv_mem->cv_qwait = SUNMAX(cv_mem->cv_qwait, 2); + if (cv_mem->cv_etamax == ONE) + { + cv_mem->cv_qwait = SUNMAX(cv_mem->cv_qwait, 2); cv_mem->cv_qprime = cv_mem->cv_q; cv_mem->cv_hprime = cv_mem->cv_h; - cv_mem->cv_eta = ONE; - return; + cv_mem->cv_eta = ONE; } - - /* etaq is the ratio of new to old h at the current order */ - cv_mem->cv_etaq = ONE /(SUNRpowerR(BIAS2*dsm,ONE/cv_mem->cv_L) + ADDON); - - /* If no order change, adjust eta and acor in cvSetEta and return */ - if (cv_mem->cv_qwait != 0) { - cv_mem->cv_eta = cv_mem->cv_etaq; - cv_mem->cv_qprime = cv_mem->cv_q; - cvSetEta(cv_mem); - return; + else + { + /* etaq is the ratio of new to old h at the current order */ + cv_mem->cv_etaq = ONE / (SUNRpowerR(BIAS2 * dsm, ONE / cv_mem->cv_L) + ADDON); + + /* If no order change, adjust eta and acor in cvSetEta and return */ + if (cv_mem->cv_qwait != 0) + { + cv_mem->cv_eta = cv_mem->cv_etaq; + cv_mem->cv_qprime = cv_mem->cv_q; + cvSetEta(cv_mem); + } + else + { + /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are + the ratios of new to old h at orders q-1 and q+1, respectively. + cvChooseEta selects the largest; cvSetEta adjusts eta and acor */ + cv_mem->cv_qwait = 2; + cv_mem->cv_etaqm1 = cvComputeEtaqm1(cv_mem); + cv_mem->cv_etaqp1 = cvComputeEtaqp1(cv_mem); + cvChooseEta(cv_mem); + cvSetEta(cv_mem); + } } - /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are - the ratios of new to old h at orders q-1 and q+1, respectively. - cvChooseEta selects the largest; cvSetEta adjusts eta and acor */ - cv_mem->cv_qwait = 2; - cv_mem->cv_etaqm1 = cvComputeEtaqm1(cv_mem); - cv_mem->cv_etaqp1 = cvComputeEtaqp1(cv_mem); - cvChooseEta(cv_mem); - cvSetEta(cv_mem); +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODES::cvPrepareNextStep", + "return", + "eta = %.16g, hprime = %.16g, qprime = %d, qwait = %d\n", + cv_mem->cv_eta, cv_mem->cv_hprime, cv_mem->cv_qprime, + cv_mem->cv_qwait); +#endif } /* @@ -6960,18 +7797,32 @@ static void cvPrepareNextStep(CVodeMem cv_mem, realtype dsm) static void cvSetEta(CVodeMem cv_mem) { - - /* If eta below the threshhold THRESH, reject a change of step size */ - if (cv_mem->cv_eta < THRESH) { - cv_mem->cv_eta = ONE; + if ((cv_mem->cv_eta > cv_mem->cv_eta_min_fx) && + (cv_mem->cv_eta < cv_mem->cv_eta_max_fx)) + { + /* Eta is within the fixed step bounds, retain step size */ + cv_mem->cv_eta = ONE; cv_mem->cv_hprime = cv_mem->cv_h; - } else { - /* Limit eta by etamax and hmax, then set hprime */ - cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta, cv_mem->cv_etamax); - cv_mem->cv_eta /= SUNMAX(ONE, SUNRabs(cv_mem->cv_h) * - cv_mem->cv_hmax_inv*cv_mem->cv_eta); + } + else + { + if (cv_mem->cv_eta >= cv_mem->cv_eta_max_fx) + { + /* Increase the step size, limit eta by etamax and hmax */ + cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta, cv_mem->cv_etamax); + cv_mem->cv_eta /= SUNMAX(ONE, SUNRabs(cv_mem->cv_h) * + cv_mem->cv_hmax_inv * cv_mem->cv_eta); + } + else + { + /* Reduce the step size, limit eta by etamin and hmin */ + cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta, cv_mem->cv_eta_min); + cv_mem->cv_eta = SUNMAX(cv_mem->cv_eta, + cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + } + /* Set hprime */ cv_mem->cv_hprime = cv_mem->cv_h * cv_mem->cv_eta; - if (cv_mem->cv_qprime < cv_mem->cv_q) cv_mem->cv_nscon = 0; + if (cv_mem->cv_qprime < cv_mem->cv_q) { cv_mem->cv_nscon = 0; } } } @@ -6982,30 +7833,38 @@ static void cvSetEta(CVodeMem cv_mem) * possible decrease in order by 1. */ -static realtype cvComputeEtaqm1(CVodeMem cv_mem) +static sunrealtype cvComputeEtaqm1(CVodeMem cv_mem) { - realtype ddn; + sunrealtype ddn; cv_mem->cv_etaqm1 = ZERO; - if (cv_mem->cv_q > 1) { + if (cv_mem->cv_q > 1) + { ddn = N_VWrmsNorm(cv_mem->cv_zn[cv_mem->cv_q], cv_mem->cv_ewt); - if ( cv_mem->cv_quadr && cv_mem->cv_errconQ ) + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { ddn = cvQuadUpdateNorm(cv_mem, ddn, cv_mem->cv_znQ[cv_mem->cv_q], cv_mem->cv_ewtQ); + } - if ( cv_mem->cv_sensi && cv_mem->cv_errconS ) + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { ddn = cvSensUpdateNorm(cv_mem, ddn, cv_mem->cv_znS[cv_mem->cv_q], cv_mem->cv_ewtS); + } - if ( cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS ) + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { ddn = cvQuadSensUpdateNorm(cv_mem, ddn, cv_mem->cv_znQS[cv_mem->cv_q], cv_mem->cv_ewtQS); + } - ddn = ddn * cv_mem->cv_tq[1]; - cv_mem->cv_etaqm1 = ONE/(SUNRpowerR(BIAS1*ddn, ONE/cv_mem->cv_q) + ADDON); + ddn = ddn * cv_mem->cv_tq[1]; + cv_mem->cv_etaqm1 = ONE / + (SUNRpowerR(BIAS1 * ddn, ONE / cv_mem->cv_q) + ADDON); } - return(cv_mem->cv_etaqm1); + return (cv_mem->cv_etaqm1); } /* @@ -7015,47 +7874,50 @@ static realtype cvComputeEtaqm1(CVodeMem cv_mem) * possible increase in order by 1. */ -static realtype cvComputeEtaqp1(CVodeMem cv_mem) +static sunrealtype cvComputeEtaqp1(CVodeMem cv_mem) { - realtype dup, cquot; + sunrealtype dup, cquot; cv_mem->cv_etaqp1 = ZERO; - if (cv_mem->cv_q != cv_mem->cv_qmax) { - if (cv_mem->cv_saved_tq5 == ZERO) return(cv_mem->cv_etaqp1); + if (cv_mem->cv_q != cv_mem->cv_qmax) + { + if (cv_mem->cv_saved_tq5 == ZERO) { return (cv_mem->cv_etaqp1); } cquot = (cv_mem->cv_tq[5] / cv_mem->cv_saved_tq5) * - SUNRpowerI(cv_mem->cv_h/cv_mem->cv_tau[2], cv_mem->cv_L); - N_VLinearSum(-cquot, cv_mem->cv_zn[cv_mem->cv_qmax], ONE, - cv_mem->cv_acor, cv_mem->cv_tempv); + SUNRpowerI(cv_mem->cv_h / cv_mem->cv_tau[2], cv_mem->cv_L); + N_VLinearSum(-cquot, cv_mem->cv_zn[cv_mem->cv_qmax], ONE, cv_mem->cv_acor, + cv_mem->cv_tempv); dup = N_VWrmsNorm(cv_mem->cv_tempv, cv_mem->cv_ewt); - if ( cv_mem->cv_quadr && cv_mem->cv_errconQ ) { + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { N_VLinearSum(-cquot, cv_mem->cv_znQ[cv_mem->cv_qmax], ONE, cv_mem->cv_acorQ, cv_mem->cv_tempvQ); dup = cvQuadUpdateNorm(cv_mem, dup, cv_mem->cv_tempvQ, cv_mem->cv_ewtQ); } - if ( cv_mem->cv_sensi && cv_mem->cv_errconS ) { - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - -cquot, cv_mem->cv_znS[cv_mem->cv_qmax], - ONE, cv_mem->cv_acorS, - cv_mem->cv_tempvS); + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, -cquot, + cv_mem->cv_znS[cv_mem->cv_qmax], ONE, + cv_mem->cv_acorS, cv_mem->cv_tempvS); dup = cvSensUpdateNorm(cv_mem, dup, cv_mem->cv_tempvS, cv_mem->cv_ewtS); } - if ( cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS ) { - (void) N_VLinearSumVectorArray(cv_mem->cv_Ns, - -cquot, cv_mem->cv_znQS[cv_mem->cv_qmax], - ONE, cv_mem->cv_acorQS, - cv_mem->cv_tempvQS); + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { + (void)N_VLinearSumVectorArray(cv_mem->cv_Ns, -cquot, + cv_mem->cv_znQS[cv_mem->cv_qmax], ONE, + cv_mem->cv_acorQS, cv_mem->cv_tempvQS); dup = cvSensUpdateNorm(cv_mem, dup, cv_mem->cv_tempvQS, cv_mem->cv_ewtQS); } dup = dup * cv_mem->cv_tq[3]; - cv_mem->cv_etaqp1 = ONE / (SUNRpowerR(BIAS3*dup, ONE/(cv_mem->cv_L+1)) + ADDON); + cv_mem->cv_etaqp1 = + ONE / (SUNRpowerR(BIAS3 * dup, ONE / (cv_mem->cv_L + 1)) + ADDON); } - return(cv_mem->cv_etaqp1); + return (cv_mem->cv_etaqp1); } /* @@ -7066,65 +7928,72 @@ static realtype cvComputeEtaqp1(CVodeMem cv_mem) * corresponding value of q. If there is a tie, the preference * order is to (1) keep the same order, then (2) decrease the order, * and finally (3) increase the order. If the maximum eta value - * is below the threshhold THRESH, the order is kept unchanged and + * is within the fixed step bounds, the order is kept unchanged and * eta is set to 1. */ static void cvChooseEta(CVodeMem cv_mem) { - realtype etam; + sunrealtype etam; int is; etam = SUNMAX(cv_mem->cv_etaqm1, SUNMAX(cv_mem->cv_etaq, cv_mem->cv_etaqp1)); - if (etam < THRESH) { - cv_mem->cv_eta = ONE; + if ((etam > cv_mem->cv_eta_min_fx) && (etam < cv_mem->cv_eta_max_fx)) + { + cv_mem->cv_eta = ONE; cv_mem->cv_qprime = cv_mem->cv_q; - return; } + else + { + if (etam == cv_mem->cv_etaq) + { + cv_mem->cv_eta = cv_mem->cv_etaq; + cv_mem->cv_qprime = cv_mem->cv_q; + } + else if (etam == cv_mem->cv_etaqm1) + { + cv_mem->cv_eta = cv_mem->cv_etaqm1; + cv_mem->cv_qprime = cv_mem->cv_q - 1; + } + else + { + cv_mem->cv_eta = cv_mem->cv_etaqp1; + cv_mem->cv_qprime = cv_mem->cv_q + 1; + + if (cv_mem->cv_lmm == CV_BDF) + { + /* + * Store Delta_n in zn[qmax] to be used in order increase + * + * This happens at the last step of order q before an increase + * to order q+1, so it represents Delta_n in the ELTE at q+1 + */ + + N_VScale(ONE, cv_mem->cv_acor, cv_mem->cv_zn[cv_mem->cv_qmax]); + + if (cv_mem->cv_quadr && cv_mem->cv_errconQ) + { + N_VScale(ONE, cv_mem->cv_acorQ, cv_mem->cv_znQ[cv_mem->cv_qmax]); + } - if (etam == cv_mem->cv_etaq) { - - cv_mem->cv_eta = cv_mem->cv_etaq; - cv_mem->cv_qprime = cv_mem->cv_q; - - } else if (etam == cv_mem->cv_etaqm1) { - - cv_mem->cv_eta = cv_mem->cv_etaqm1; - cv_mem->cv_qprime = cv_mem->cv_q - 1; - - } else { - - cv_mem->cv_eta = cv_mem->cv_etaqp1; - cv_mem->cv_qprime = cv_mem->cv_q + 1; - - if (cv_mem->cv_lmm == CV_BDF) { - /* - * Store Delta_n in zn[qmax] to be used in order increase - * - * This happens at the last step of order q before an increase - * to order q+1, so it represents Delta_n in the ELTE at q+1 - */ - - N_VScale(ONE, cv_mem->cv_acor, cv_mem->cv_zn[cv_mem->cv_qmax]); - - if (cv_mem->cv_quadr && cv_mem->cv_errconQ) - N_VScale(ONE, cv_mem->cv_acorQ, cv_mem->cv_znQ[cv_mem->cv_qmax]); - - if (cv_mem->cv_sensi && cv_mem->cv_errconS) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_sensi && cv_mem->cv_errconS) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_acorS, cv_mem->cv_znS[cv_mem->cv_qmax]); - } + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_acorS, + cv_mem->cv_znS[cv_mem->cv_qmax]); + } - if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) { - for (is=0; iscv_Ns; is++) - cv_mem->cv_cvals[is] = ONE; + if (cv_mem->cv_quadr_sensi && cv_mem->cv_errconQS) + { + for (is = 0; is < cv_mem->cv_Ns; is++) { cv_mem->cv_cvals[is] = ONE; } - (void) N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, - cv_mem->cv_acorQS, cv_mem->cv_znQS[cv_mem->cv_qmax]); + (void)N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, + cv_mem->cv_acorQS, + cv_mem->cv_znQS[cv_mem->cv_qmax]); + } } } } @@ -7146,7 +8015,6 @@ static void cvChooseEta(CVodeMem cv_mem) static int cvHandleFailure(CVodeMem cv_mem, int flag) { - /* Set vector of absolute weighted local errors */ /* N_VProd(acor, ewt, tempv); @@ -7154,107 +8022,119 @@ static int cvHandleFailure(CVodeMem cv_mem, int flag) */ /* Depending on flag, print error message and return error flag */ - switch (flag) { + switch (flag) + { case CV_ERR_FAILURE: - cvProcessError(cv_mem, CV_ERR_FAILURE, "CVODES", "CVode", + cvProcessError(cv_mem, CV_ERR_FAILURE, __LINE__, __func__, __FILE__, MSGCV_ERR_FAILS, cv_mem->cv_tn, cv_mem->cv_h); break; case CV_CONV_FAILURE: - cvProcessError(cv_mem, CV_CONV_FAILURE, "CVODES", "CVode", + cvProcessError(cv_mem, CV_CONV_FAILURE, __LINE__, __func__, __FILE__, MSGCV_CONV_FAILS, cv_mem->cv_tn, cv_mem->cv_h); break; case CV_LSETUP_FAIL: - cvProcessError(cv_mem, CV_LSETUP_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_LSETUP_FAIL, __LINE__, __func__, __FILE__, MSGCV_SETUP_FAILED, cv_mem->cv_tn); break; case CV_LSOLVE_FAIL: - cvProcessError(cv_mem, CV_LSOLVE_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_LSOLVE_FAIL, __LINE__, __func__, __FILE__, MSGCV_SOLVE_FAILED, cv_mem->cv_tn); break; case CV_RHSFUNC_FAIL: - cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_RHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); break; case CV_UNREC_RHSFUNC_ERR: - cvProcessError(cv_mem, CV_UNREC_RHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_UNREC_RHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_RHSFUNC_UNREC, cv_mem->cv_tn); break; case CV_REPTD_RHSFUNC_ERR: - cvProcessError(cv_mem, CV_REPTD_RHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_REPTD_RHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_RHSFUNC_REPTD, cv_mem->cv_tn); break; case CV_RTFUNC_FAIL: - cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_RTFUNC_FAILED, cv_mem->cv_tn); break; case CV_QRHSFUNC_FAIL: - cvProcessError(cv_mem, CV_QRHSFUNC_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_QRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_QRHSFUNC_FAILED, cv_mem->cv_tn); break; case CV_UNREC_QRHSFUNC_ERR: - cvProcessError(cv_mem, CV_UNREC_QRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_UNREC_QRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_QRHSFUNC_UNREC, cv_mem->cv_tn); break; case CV_REPTD_QRHSFUNC_ERR: - cvProcessError(cv_mem, CV_REPTD_QRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_REPTD_QRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_QRHSFUNC_REPTD, cv_mem->cv_tn); break; case CV_SRHSFUNC_FAIL: - cvProcessError(cv_mem, CV_SRHSFUNC_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_SRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_SRHSFUNC_FAILED, cv_mem->cv_tn); break; case CV_UNREC_SRHSFUNC_ERR: - cvProcessError(cv_mem, CV_UNREC_SRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_UNREC_SRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_SRHSFUNC_UNREC, cv_mem->cv_tn); break; case CV_REPTD_SRHSFUNC_ERR: - cvProcessError(cv_mem, CV_REPTD_SRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_REPTD_SRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_SRHSFUNC_REPTD, cv_mem->cv_tn); break; case CV_QSRHSFUNC_FAIL: - cvProcessError(cv_mem, CV_QSRHSFUNC_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_QSRHSFUNC_FAIL, __LINE__, __func__, __FILE__, MSGCV_QSRHSFUNC_FAILED, cv_mem->cv_tn); break; case CV_UNREC_QSRHSFUNC_ERR: - cvProcessError(cv_mem, CV_UNREC_QSRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_UNREC_QSRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_QSRHSFUNC_UNREC, cv_mem->cv_tn); break; case CV_REPTD_QSRHSFUNC_ERR: - cvProcessError(cv_mem, CV_REPTD_QSRHSFUNC_ERR, "CVODES", "CVode", + cvProcessError(cv_mem, CV_REPTD_QSRHSFUNC_ERR, __LINE__, __func__, __FILE__, MSGCV_QSRHSFUNC_REPTD, cv_mem->cv_tn); break; case CV_TOO_CLOSE: - cvProcessError(cv_mem, CV_TOO_CLOSE, "CVODES", "CVode", + cvProcessError(cv_mem, CV_TOO_CLOSE, __LINE__, __func__, __FILE__, MSGCV_TOO_CLOSE); break; case CV_MEM_NULL: - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVode", - MSGCV_NO_MEM); + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); break; - case SUN_NLS_MEM_NULL: - cvProcessError(cv_mem, CV_MEM_NULL, "CVODES", "CVode", + case SUN_ERR_ARG_CORRUPT: + cvProcessError(cv_mem, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NLS_INPUT_NULL, cv_mem->cv_tn); break; case CV_NLS_SETUP_FAIL: - cvProcessError(cv_mem, CV_NLS_SETUP_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_NLS_SETUP_FAIL, __LINE__, __func__, __FILE__, MSGCV_NLS_SETUP_FAILED, cv_mem->cv_tn); break; case CV_CONSTR_FAIL: - cvProcessError(cv_mem, CV_CONSTR_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_CONSTR_FAIL, __LINE__, __func__, __FILE__, MSGCV_FAILED_CONSTR, cv_mem->cv_tn); break; case CV_NLS_FAIL: - cvProcessError(cv_mem, CV_NLS_FAIL, "CVODES", "CVode", + cvProcessError(cv_mem, CV_NLS_FAIL, __LINE__, __func__, __FILE__, MSGCV_NLS_FAIL, cv_mem->cv_tn); break; + case CV_PROJ_MEM_NULL: + cvProcessError(cv_mem, CV_PROJ_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_CV_PROJ_MEM_NULL); + break; + case CV_PROJFUNC_FAIL: + cvProcessError(cv_mem, CV_PROJFUNC_FAIL, __LINE__, __func__, __FILE__, + MSG_CV_PROJFUNC_FAIL, cv_mem->cv_tn); + break; + case CV_REPTD_PROJFUNC_ERR: + cvProcessError(cv_mem, CV_REPTD_PROJFUNC_ERR, __LINE__, __func__, __FILE__, + MSG_CV_REPTD_PROJFUNC_ERR, cv_mem->cv_tn); + break; default: /* This return should never happen */ - cvProcessError(cv_mem, CV_UNRECOGNIZED_ERR, "CVODES", "CVode", - "CVODES encountered an unrecognized error. Please report this to the Sundials developers at sundials-users@llnl.gov"); + cvProcessError(cv_mem, CV_UNRECOGNIZED_ERR, __LINE__, __func__, + __FILE__, "CVODES encountered an unrecognized error. Please report this to the Sundials developers at sundials-users@llnl.gov"); return (CV_UNRECOGNIZED_ERR); } - return(flag); + return (flag); } /* @@ -7277,51 +8157,60 @@ static int cvHandleFailure(CVodeMem cv_mem, int flag) static void cvBDFStab(CVodeMem cv_mem) { - int i,k, ldflag, factorial; - realtype sq, sqm1, sqm2; + int i, k, ldflag, factorial; + sunrealtype sq, sqm1, sqm2; /* If order is 3 or greater, then save scaled derivative data, push old data down in i, then add current values to top. */ - if (cv_mem->cv_q >= 3) { + if (cv_mem->cv_q >= 3) + { for (k = 1; k <= 3; k++) + { for (i = 5; i >= 2; i--) - cv_mem->cv_ssdat[i][k] = cv_mem->cv_ssdat[i-1][k]; + { + cv_mem->cv_ssdat[i][k] = cv_mem->cv_ssdat[i - 1][k]; + } + } factorial = 1; - for (i = 1; i <= cv_mem->cv_q-1; i++) factorial *= i; - sq = factorial * cv_mem->cv_q * (cv_mem->cv_q+1) * - cv_mem->cv_acnrm / SUNMAX(cv_mem->cv_tq[5],TINY); + for (i = 1; i <= cv_mem->cv_q - 1; i++) { factorial *= i; } + sq = factorial * cv_mem->cv_q * (cv_mem->cv_q + 1) * cv_mem->cv_acnrm / + SUNMAX(cv_mem->cv_tq[5], TINY); sqm1 = factorial * cv_mem->cv_q * - N_VWrmsNorm(cv_mem->cv_zn[cv_mem->cv_q], cv_mem->cv_ewt); + N_VWrmsNorm(cv_mem->cv_zn[cv_mem->cv_q], cv_mem->cv_ewt); sqm2 = factorial * - N_VWrmsNorm(cv_mem->cv_zn[cv_mem->cv_q-1], cv_mem->cv_ewt); - cv_mem->cv_ssdat[1][1] = sqm2*sqm2; - cv_mem->cv_ssdat[1][2] = sqm1*sqm1; - cv_mem->cv_ssdat[1][3] = sq*sq; + N_VWrmsNorm(cv_mem->cv_zn[cv_mem->cv_q - 1], cv_mem->cv_ewt); + cv_mem->cv_ssdat[1][1] = sqm2 * sqm2; + cv_mem->cv_ssdat[1][2] = sqm1 * sqm1; + cv_mem->cv_ssdat[1][3] = sq * sq; } - if (cv_mem->cv_qprime >= cv_mem->cv_q) { - + if (cv_mem->cv_qprime >= cv_mem->cv_q) + { /* If order is 3 or greater, and enough ssdat has been saved, nscon >= q+5, then call stability limit detection routine. */ - if ( (cv_mem->cv_q >= 3) && (cv_mem->cv_nscon >= cv_mem->cv_q+5) ) { + if ((cv_mem->cv_q >= 3) && (cv_mem->cv_nscon >= cv_mem->cv_q + 5)) + { ldflag = cvSLdet(cv_mem); - if (ldflag > 3) { + if (ldflag > 3) + { /* A stability limit violation is indicated by a return flag of 4, 5, or 6. Reduce new order. */ - cv_mem->cv_qprime = cv_mem->cv_q-1; - cv_mem->cv_eta = cv_mem->cv_etaqm1; - cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta,cv_mem->cv_etamax); - cv_mem->cv_eta = cv_mem->cv_eta / - SUNMAX(ONE,SUNRabs(cv_mem->cv_h)*cv_mem->cv_hmax_inv*cv_mem->cv_eta); + cv_mem->cv_qprime = cv_mem->cv_q - 1; + cv_mem->cv_eta = cv_mem->cv_etaqm1; + cv_mem->cv_eta = SUNMIN(cv_mem->cv_eta, cv_mem->cv_etamax); + cv_mem->cv_eta = cv_mem->cv_eta / + SUNMAX(ONE, SUNRabs(cv_mem->cv_h) * + cv_mem->cv_hmax_inv * cv_mem->cv_eta); cv_mem->cv_hprime = cv_mem->cv_h * cv_mem->cv_eta; - cv_mem->cv_nor = cv_mem->cv_nor + 1; + cv_mem->cv_nor = cv_mem->cv_nor + 1; } } } - else { + else + { /* Otherwise, let order increase happen, and reset stability limit counter, nscon. */ cv_mem->cv_nscon = 0; @@ -7367,22 +8256,22 @@ static void cvBDFStab(CVodeMem cv_mem) static int cvSLdet(CVodeMem cv_mem) { int i, k, j, it, kmin = 0, kflag = 0; - realtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4]; - realtype drr[4], rrc[4],sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; - realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; - realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; - realtype tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; - realtype rsa, rsb, rsc, rsd, rd1a, rd1b, rd1c; - realtype rd2a, rd2b, rd3a, cest1, corr1; - realtype ratp, ratm, qfac1, qfac2, bb, rrb; + sunrealtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4]; + sunrealtype drr[4], rrc[4], sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; + sunrealtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; + sunrealtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; + sunrealtype tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; + sunrealtype rsa, rsb, rsc, rsd, rd1a, rd1b, rd1c; + sunrealtype rd2a, rd2b, rd3a, cest1, corr1; + sunrealtype ratp, ratm, qfac1, qfac2, bb, rrb; /* The following are cutoffs and tolerances used by this routine */ - rrcut = RCONST(0.98); - vrrtol = RCONST(1.0e-4); - vrrt2 = RCONST(5.0e-4); - sqtol = RCONST(1.0e-3); - rrtol = RCONST(1.0e-2); + rrcut = SUN_RCONST(0.98); + vrrtol = SUN_RCONST(1.0e-4); + vrrt2 = SUN_RCONST(5.0e-4); + sqtol = SUN_RCONST(1.0e-3); + rrtol = SUN_RCONST(1.0e-2); rr = ZERO; @@ -7396,190 +8285,213 @@ static int cvSLdet(CVodeMem cv_mem) /* get maxima, minima, and variances, and form quartic coefficients */ - for (k=1; k<=3; k++) { + for (k = 1; k <= 3; k++) + { smink = cv_mem->cv_ssdat[1][k]; smaxk = ZERO; - for (i=1; i<=5; i++) { - smink = SUNMIN(smink,cv_mem->cv_ssdat[i][k]); - smaxk = SUNMAX(smaxk,cv_mem->cv_ssdat[i][k]); + for (i = 1; i <= 5; i++) + { + smink = SUNMIN(smink, cv_mem->cv_ssdat[i][k]); + smaxk = SUNMAX(smaxk, cv_mem->cv_ssdat[i][k]); } - if (smink < TINY*smaxk) { + if (smink < TINY * smaxk) + { kflag = -1; - return(kflag); + return (kflag); } - smax[k] = smaxk; - ssmax[k] = smaxk*smaxk; + smax[k] = smaxk; + ssmax[k] = smaxk * smaxk; sumrat = ZERO; sumrsq = ZERO; - for (i=1; i<=4; i++) { - rat[i][k] = cv_mem->cv_ssdat[i][k] / cv_mem->cv_ssdat[i+1][k]; - sumrat = sumrat + rat[i][k]; - sumrsq = sumrsq + rat[i][k]*rat[i][k]; + for (i = 1; i <= 4; i++) + { + rat[i][k] = cv_mem->cv_ssdat[i][k] / cv_mem->cv_ssdat[i + 1][k]; + sumrat = sumrat + rat[i][k]; + sumrsq = sumrsq + rat[i][k] * rat[i][k]; } - rav[k] = FOURTH*sumrat; - vrat[k] = SUNRabs(FOURTH*sumrsq - rav[k]*rav[k]); + rav[k] = FOURTH * sumrat; + vrat[k] = SUNRabs(FOURTH * sumrsq - rav[k] * rav[k]); qc[5][k] = cv_mem->cv_ssdat[1][k] * cv_mem->cv_ssdat[3][k] - - cv_mem->cv_ssdat[2][k] * cv_mem->cv_ssdat[2][k]; + cv_mem->cv_ssdat[2][k] * cv_mem->cv_ssdat[2][k]; qc[4][k] = cv_mem->cv_ssdat[2][k] * cv_mem->cv_ssdat[3][k] - - cv_mem->cv_ssdat[1][k] * cv_mem->cv_ssdat[4][k]; + cv_mem->cv_ssdat[1][k] * cv_mem->cv_ssdat[4][k]; qc[3][k] = ZERO; qc[2][k] = cv_mem->cv_ssdat[2][k] * cv_mem->cv_ssdat[5][k] - - cv_mem->cv_ssdat[3][k] * cv_mem->cv_ssdat[4][k]; + cv_mem->cv_ssdat[3][k] * cv_mem->cv_ssdat[4][k]; qc[1][k] = cv_mem->cv_ssdat[4][k] * cv_mem->cv_ssdat[4][k] - - cv_mem->cv_ssdat[3][k] * cv_mem->cv_ssdat[5][k]; + cv_mem->cv_ssdat[3][k] * cv_mem->cv_ssdat[5][k]; - for (i=1; i<=5; i++) - qco[i][k] = qc[i][k]; + for (i = 1; i <= 5; i++) { qco[i][k] = qc[i][k]; } - } /* End of k loop */ + } /* End of k loop */ /* Isolate normal or nearly-normal matrix case. The three quartics will have a common or nearly-common root in this case. Return a kflag = 1 if this procedure works. If the three roots differ more than vrrt2, return error kflag = -3. */ - vmin = SUNMIN(vrat[1],SUNMIN(vrat[2],vrat[3])); - vmax = SUNMAX(vrat[1],SUNMAX(vrat[2],vrat[3])); + vmin = SUNMIN(vrat[1], SUNMIN(vrat[2], vrat[3])); + vmax = SUNMAX(vrat[1], SUNMAX(vrat[2], vrat[3])); - if (vmin < vrrtol*vrrtol) { - - if (vmax > vrrt2*vrrt2) { + if (vmin < vrrtol * vrrtol) + { + if (vmax > vrrt2 * vrrt2) + { kflag = -2; - return(kflag); - } else { - rr = (rav[1] + rav[2] + rav[3])/THREE; + return (kflag); + } + else + { + rr = (rav[1] + rav[2] + rav[3]) / THREE; drrmax = ZERO; - for (k = 1;k<=3;k++) { - adrr = SUNRabs(rav[k] - rr); + for (k = 1; k <= 3; k++) + { + adrr = SUNRabs(rav[k] - rr); drrmax = SUNMAX(drrmax, adrr); } - if (drrmax > vrrt2) { kflag = -3; return(kflag); } + if (drrmax > vrrt2) + { + kflag = -3; + return (kflag); + } kflag = 1; /* can compute charactistic root, drop to next section */ } - - } else { - + } + else + { /* use the quartics to get rr. */ - if (SUNRabs(qco[1][1]) < TINY*ssmax[1]) { + if (SUNRabs(qco[1][1]) < TINY * ssmax[1]) + { kflag = -4; - return(kflag); + return (kflag); } - tem = qco[1][2]/qco[1][1]; - for (i=2; i<=5; i++) { - qco[i][2] = qco[i][2] - tem*qco[i][1]; - } + tem = qco[1][2] / qco[1][1]; + for (i = 2; i <= 5; i++) { qco[i][2] = qco[i][2] - tem * qco[i][1]; } qco[1][2] = ZERO; - tem = qco[1][3]/qco[1][1]; - for (i=2; i<=5; i++) { - qco[i][3] = qco[i][3] - tem*qco[i][1]; - } + tem = qco[1][3] / qco[1][1]; + for (i = 2; i <= 5; i++) { qco[i][3] = qco[i][3] - tem * qco[i][1]; } qco[1][3] = ZERO; - if (SUNRabs(qco[2][2]) < TINY*ssmax[2]) { + if (SUNRabs(qco[2][2]) < TINY * ssmax[2]) + { kflag = -4; - return(kflag); + return (kflag); } - tem = qco[2][3]/qco[2][2]; - for (i=3; i<=5; i++) { - qco[i][3] = qco[i][3] - tem*qco[i][2]; - } + tem = qco[2][3] / qco[2][2]; + for (i = 3; i <= 5; i++) { qco[i][3] = qco[i][3] - tem * qco[i][2]; } - if (SUNRabs(qco[4][3]) < TINY*ssmax[3]) { + if (SUNRabs(qco[4][3]) < TINY * ssmax[3]) + { kflag = -4; - return(kflag); + return (kflag); } - rr = -qco[5][3]/qco[4][3]; + rr = -qco[5][3] / qco[4][3]; - if (rr < TINY || rr > HUNDRED) { + if (rr < TINY || rr > HUNDRED) + { kflag = -5; - return(kflag); + return (kflag); } - for (k=1; k<=3; k++) - qkr[k] = qc[5][k] + rr*(qc[4][k] + rr*rr*(qc[2][k] + rr*qc[1][k])); + for (k = 1; k <= 3; k++) + { + qkr[k] = qc[5][k] + rr * (qc[4][k] + rr * rr * (qc[2][k] + rr * qc[1][k])); + } sqmax = ZERO; - for (k=1; k<=3; k++) { - saqk = SUNRabs(qkr[k])/ssmax[k]; - if (saqk > sqmax) sqmax = saqk; + for (k = 1; k <= 3; k++) + { + saqk = SUNRabs(qkr[k]) / ssmax[k]; + if (saqk > sqmax) { sqmax = saqk; } } - if (sqmax < sqtol) { + if (sqmax < sqtol) + { kflag = 2; /* can compute charactistic root, drop to "given rr,etc" */ - - } else { - + } + else + { /* do Newton corrections to improve rr. */ - for (it=1; it<=3; it++) { - for (k=1; k<=3; k++) { - qp = qc[4][k] + rr*rr*(THREE*qc[2][k] + rr*FOUR*qc[1][k]); + for (it = 1; it <= 3; it++) + { + for (k = 1; k <= 3; k++) + { + qp = qc[4][k] + rr * rr * (THREE * qc[2][k] + rr * FOUR * qc[1][k]); drr[k] = ZERO; - if (SUNRabs(qp) > TINY*ssmax[k]) drr[k] = -qkr[k]/qp; + if (SUNRabs(qp) > TINY * ssmax[k]) { drr[k] = -qkr[k] / qp; } rrc[k] = rr + drr[k]; } - for (k=1; k<=3; k++) { - s = rrc[k]; + for (k = 1; k <= 3; k++) + { + s = rrc[k]; sqmaxk = ZERO; - for (j=1; j<=3; j++) { - qjk[j][k] = qc[5][j] + s*(qc[4][j] + s*s*(qc[2][j] + s*qc[1][j])); - saqj = SUNRabs(qjk[j][k])/ssmax[j]; - if (saqj > sqmaxk) sqmaxk = saqj; + for (j = 1; j <= 3; j++) + { + qjk[j][k] = qc[5][j] + + s * (qc[4][j] + s * s * (qc[2][j] + s * qc[1][j])); + saqj = SUNRabs(qjk[j][k]) / ssmax[j]; + if (saqj > sqmaxk) { sqmaxk = saqj; } } sqmx[k] = sqmaxk; } sqmin = sqmx[1] + ONE; - for (k=1; k<=3; k++) { - if (sqmx[k] < sqmin) { - kmin = k; + for (k = 1; k <= 3; k++) + { + if (sqmx[k] < sqmin) + { + kmin = k; sqmin = sqmx[k]; } } rr = rrc[kmin]; - if (sqmin < sqtol) { + if (sqmin < sqtol) + { kflag = 3; /* can compute charactistic root */ /* break out of Newton correction loop and drop to "given rr,etc" */ break; - } else { - for (j=1; j<=3; j++) { - qkr[j] = qjk[j][kmin]; - } + } + else + { + for (j = 1; j <= 3; j++) { qkr[j] = qjk[j][kmin]; } } } /* end of Newton correction loop */ - if (sqmin > sqtol) { + if (sqmin > sqtol) + { kflag = -6; - return(kflag); + return (kflag); } } /* end of if (sqmax < sqtol) else */ - } /* end of if (vmin < vrrtol*vrrtol) else, quartics to get rr. */ + } /* end of if (vmin < vrrtol*vrrtol) else, quartics to get rr. */ /* given rr, find sigsq[k] and verify rr. */ /* All positive kflag drop to this section */ - for (k=1; k<=3; k++) { - rsa = cv_mem->cv_ssdat[1][k]; - rsb = cv_mem->cv_ssdat[2][k]*rr; - rsc = cv_mem->cv_ssdat[3][k]*rr*rr; - rsd = cv_mem->cv_ssdat[4][k]*rr*rr*rr; + for (k = 1; k <= 3; k++) + { + rsa = cv_mem->cv_ssdat[1][k]; + rsb = cv_mem->cv_ssdat[2][k] * rr; + rsc = cv_mem->cv_ssdat[3][k] * rr * rr; + rsd = cv_mem->cv_ssdat[4][k] * rr * rr * rr; rd1a = rsa - rsb; rd1b = rsb - rsc; rd1c = rsc - rsd; @@ -7587,55 +8499,60 @@ static int cvSLdet(CVodeMem cv_mem) rd2b = rd1b - rd1c; rd3a = rd2a - rd2b; - if (SUNRabs(rd1b) < TINY*smax[k]) { + if (SUNRabs(rd1b) < TINY * smax[k]) + { kflag = -7; - return(kflag); + return (kflag); } - cest1 = -rd3a/rd1b; - if (cest1 < TINY || cest1 > FOUR) { + cest1 = -rd3a / rd1b; + if (cest1 < TINY || cest1 > FOUR) + { kflag = -7; - return(kflag); + return (kflag); } - corr1 = (rd2b/cest1)/(rr*rr); + corr1 = (rd2b / cest1) / (rr * rr); sigsq[k] = cv_mem->cv_ssdat[3][k] + corr1; } - if (sigsq[2] < TINY) { + if (sigsq[2] < TINY) + { kflag = -8; - return(kflag); + return (kflag); } - ratp = sigsq[3]/sigsq[2]; - ratm = sigsq[1]/sigsq[2]; - qfac1 = FOURTH*(cv_mem->cv_q*cv_mem->cv_q - ONE); - qfac2 = TWO/(cv_mem->cv_q - ONE); - bb = ratp*ratm - ONE - qfac1*ratp; - tem = ONE - qfac2*bb; + ratp = sigsq[3] / sigsq[2]; + ratm = sigsq[1] / sigsq[2]; + qfac1 = FOURTH * (cv_mem->cv_q * cv_mem->cv_q - ONE); + qfac2 = TWO / (cv_mem->cv_q - ONE); + bb = ratp * ratm - ONE - qfac1 * ratp; + tem = ONE - qfac2 * bb; - if (SUNRabs(tem) < TINY) { + if (SUNRabs(tem) < TINY) + { kflag = -8; - return(kflag); + return (kflag); } - rrb = ONE/tem; + rrb = ONE / tem; - if (SUNRabs(rrb - rr) > rrtol) { + if (SUNRabs(rrb - rr) > rrtol) + { kflag = -9; - return(kflag); + return (kflag); } /* Check to see if rr is above cutoff rrcut */ - if (rr > rrcut) { - if (kflag == 1) kflag = 4; - if (kflag == 2) kflag = 5; - if (kflag == 3) kflag = 6; + if (rr > rrcut) + { + if (kflag == 1) { kflag = 4; } + if (kflag == 2) { kflag = 5; } + if (kflag == 3) { kflag = 6; } } /* All positive kflag returned at this point */ - return(kflag); - + return (kflag); } /* @@ -7659,48 +8576,52 @@ static int cvSLdet(CVodeMem cv_mem) static int cvRcheck1(CVodeMem cv_mem) { int i, retval; - realtype smallh, hratio, tplus; - booleantype zroot; + sunrealtype smallh, hratio, tplus; + sunbooleantype zroot; - for (i = 0; i < cv_mem->cv_nrtfn; i++) cv_mem->cv_iroots[i] = 0; - cv_mem->cv_tlo = cv_mem->cv_tn; + for (i = 0; i < cv_mem->cv_nrtfn; i++) { cv_mem->cv_iroots[i] = 0; } + cv_mem->cv_tlo = cv_mem->cv_tn; cv_mem->cv_ttol = (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)) * - cv_mem->cv_uround*HUNDRED; + cv_mem->cv_uround * HUNDRED; /* Evaluate g at initial t and check for zero values. */ - retval = cv_mem->cv_gfun(cv_mem->cv_tlo, cv_mem->cv_zn[0], - cv_mem->cv_glo, cv_mem->cv_user_data); + retval = cv_mem->cv_gfun(cv_mem->cv_tlo, cv_mem->cv_zn[0], cv_mem->cv_glo, + cv_mem->cv_user_data); cv_mem->cv_nge = 1; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } zroot = SUNFALSE; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if (SUNRabs(cv_mem->cv_glo[i]) == ZERO) { - zroot = SUNTRUE; + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (SUNRabs(cv_mem->cv_glo[i]) == ZERO) + { + zroot = SUNTRUE; cv_mem->cv_gactive[i] = SUNFALSE; } } - if (!zroot) return(CV_SUCCESS); + if (!zroot) { return (CV_SUCCESS); } /* Some g_i is zero at t0; look at g at t0+(small increment). */ - hratio = SUNMAX(cv_mem->cv_ttol/SUNRabs(cv_mem->cv_h), PT1); - smallh = hratio*cv_mem->cv_h; - tplus = cv_mem->cv_tlo + smallh; + hratio = SUNMAX(cv_mem->cv_ttol / SUNRabs(cv_mem->cv_h), PT1); + smallh = hratio * cv_mem->cv_h; + tplus = cv_mem->cv_tlo + smallh; N_VLinearSum(ONE, cv_mem->cv_zn[0], hratio, cv_mem->cv_zn[1], cv_mem->cv_y); - retval = cv_mem->cv_gfun(tplus, cv_mem->cv_y, - cv_mem->cv_ghi, cv_mem->cv_user_data); + retval = cv_mem->cv_gfun(tplus, cv_mem->cv_y, cv_mem->cv_ghi, + cv_mem->cv_user_data); cv_mem->cv_nge++; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } /* We check now only the components of g which were exactly 0.0 at t0 * to see if we can 'activate' them. */ - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if (!cv_mem->cv_gactive[i] && SUNRabs(cv_mem->cv_ghi[i]) != ZERO) { + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i] && SUNRabs(cv_mem->cv_ghi[i]) != ZERO) + { cv_mem->cv_gactive[i] = SUNTRUE; - cv_mem->cv_glo[i] = cv_mem->cv_ghi[i]; + cv_mem->cv_glo[i] = cv_mem->cv_ghi[i]; } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -7727,60 +8648,65 @@ static int cvRcheck1(CVodeMem cv_mem) static int cvRcheck2(CVodeMem cv_mem) { int i, retval; - realtype smallh, hratio, tplus; - booleantype zroot; + sunrealtype smallh, hratio, tplus; + sunbooleantype zroot; - if (cv_mem->cv_irfnd == 0) return(CV_SUCCESS); + if (cv_mem->cv_irfnd == 0) { return (CV_SUCCESS); } - (void) CVodeGetDky(cv_mem, cv_mem->cv_tlo, 0, cv_mem->cv_y); - retval = cv_mem->cv_gfun(cv_mem->cv_tlo, cv_mem->cv_y, - cv_mem->cv_glo, cv_mem->cv_user_data); + (void)CVodeGetDky(cv_mem, cv_mem->cv_tlo, 0, cv_mem->cv_y); + retval = cv_mem->cv_gfun(cv_mem->cv_tlo, cv_mem->cv_y, cv_mem->cv_glo, + cv_mem->cv_user_data); cv_mem->cv_nge++; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } zroot = SUNFALSE; - for (i = 0; i < cv_mem->cv_nrtfn; i++) cv_mem->cv_iroots[i] = 0; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if (!cv_mem->cv_gactive[i]) continue; - if (SUNRabs(cv_mem->cv_glo[i]) == ZERO) { - zroot = SUNTRUE; + for (i = 0; i < cv_mem->cv_nrtfn; i++) { cv_mem->cv_iroots[i] = 0; } + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i]) { continue; } + if (SUNRabs(cv_mem->cv_glo[i]) == ZERO) + { + zroot = SUNTRUE; cv_mem->cv_iroots[i] = 1; } } - if (!zroot) return(CV_SUCCESS); + if (!zroot) { return (CV_SUCCESS); } /* One or more g_i has a zero at tlo. Check g at tlo+smallh. */ cv_mem->cv_ttol = (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)) * - cv_mem->cv_uround * HUNDRED; + cv_mem->cv_uround * HUNDRED; smallh = (cv_mem->cv_h > ZERO) ? cv_mem->cv_ttol : -cv_mem->cv_ttol; - tplus = cv_mem->cv_tlo + smallh; - if ( (tplus - cv_mem->cv_tn)*cv_mem->cv_h >= ZERO) { - hratio = smallh/cv_mem->cv_h; + tplus = cv_mem->cv_tlo + smallh; + if ((tplus - cv_mem->cv_tn) * cv_mem->cv_h >= ZERO) + { + hratio = smallh / cv_mem->cv_h; N_VLinearSum(ONE, cv_mem->cv_y, hratio, cv_mem->cv_zn[1], cv_mem->cv_y); - } else { - (void) CVodeGetDky(cv_mem, tplus, 0, cv_mem->cv_y); } - retval = cv_mem->cv_gfun(tplus, cv_mem->cv_y, - cv_mem->cv_ghi, cv_mem->cv_user_data); + else { (void)CVodeGetDky(cv_mem, tplus, 0, cv_mem->cv_y); } + retval = cv_mem->cv_gfun(tplus, cv_mem->cv_y, cv_mem->cv_ghi, + cv_mem->cv_user_data); cv_mem->cv_nge++; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } /* Check for close roots (error return), for a new zero at tlo+smallh, and for a g_i that changed from zero to nonzero. */ zroot = SUNFALSE; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if (!cv_mem->cv_gactive[i]) continue; - if (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) { - if (cv_mem->cv_iroots[i] == 1) return(CLOSERT); - zroot = SUNTRUE; + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i]) { continue; } + if (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) + { + if (cv_mem->cv_iroots[i] == 1) { return (CLOSERT); } + zroot = SUNTRUE; cv_mem->cv_iroots[i] = 1; - } else { - if (cv_mem->cv_iroots[i] == 1) - cv_mem->cv_glo[i] = cv_mem->cv_ghi[i]; + } + else + { + if (cv_mem->cv_iroots[i] == 1) { cv_mem->cv_glo[i] = cv_mem->cv_ghi[i]; } } } - if (zroot) return(RTFOUND); - return(CV_SUCCESS); + if (zroot) { return (RTFOUND); } + return (CV_SUCCESS); } /* @@ -7801,46 +8727,58 @@ static int cvRcheck3(CVodeMem cv_mem) int i, ier, retval; /* Set thi = tn or tout, whichever comes first; set y = y(thi). */ - if (cv_mem->cv_taskc == CV_ONE_STEP) { + if (cv_mem->cv_taskc == CV_ONE_STEP) + { cv_mem->cv_thi = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], cv_mem->cv_y); } - if (cv_mem->cv_taskc == CV_NORMAL) { - if ( (cv_mem->cv_toutc - cv_mem->cv_tn)*cv_mem->cv_h >= ZERO) { + if (cv_mem->cv_taskc == CV_NORMAL) + { + if ((cv_mem->cv_toutc - cv_mem->cv_tn) * cv_mem->cv_h >= ZERO) + { cv_mem->cv_thi = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], cv_mem->cv_y); - } else { + } + else + { cv_mem->cv_thi = cv_mem->cv_toutc; - (void) CVodeGetDky(cv_mem, cv_mem->cv_thi, 0, cv_mem->cv_y); + (void)CVodeGetDky(cv_mem, cv_mem->cv_thi, 0, cv_mem->cv_y); } } /* Set ghi = g(thi) and call cvRootfind to search (tlo,thi) for roots. */ - retval = cv_mem->cv_gfun(cv_mem->cv_thi, cv_mem->cv_y, - cv_mem->cv_ghi, cv_mem->cv_user_data); + retval = cv_mem->cv_gfun(cv_mem->cv_thi, cv_mem->cv_y, cv_mem->cv_ghi, + cv_mem->cv_user_data); cv_mem->cv_nge++; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } cv_mem->cv_ttol = (SUNRabs(cv_mem->cv_tn) + SUNRabs(cv_mem->cv_h)) * - cv_mem->cv_uround * HUNDRED; + cv_mem->cv_uround * HUNDRED; ier = cvRootfind(cv_mem); - if (ier == CV_RTFUNC_FAIL) return(CV_RTFUNC_FAIL); - for(i=0; icv_nrtfn; i++) { - if(!cv_mem->cv_gactive[i] && cv_mem->cv_grout[i] != ZERO) + if (ier == CV_RTFUNC_FAIL) { return (CV_RTFUNC_FAIL); } + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i] && cv_mem->cv_grout[i] != ZERO) + { cv_mem->cv_gactive[i] = SUNTRUE; + } } cv_mem->cv_tlo = cv_mem->cv_trout; for (i = 0; i < cv_mem->cv_nrtfn; i++) + { cv_mem->cv_glo[i] = cv_mem->cv_grout[i]; + } /* If no root found, return CV_SUCCESS. */ - if (ier == CV_SUCCESS) return(CV_SUCCESS); + if (ier == CV_SUCCESS) { return (CV_SUCCESS); } /* If a root was found, interpolate to get y(trout) and return. */ - (void) CVodeGetDky(cv_mem, cv_mem->cv_trout, 0, cv_mem->cv_y); - return(RTFOUND); + (void)CVodeGetDky(cv_mem, cv_mem->cv_trout, 0, cv_mem->cv_y); + return (RTFOUND); } +#define DIFFERENT_SIGN(a, b) (((a) < 0 && (b) > 0) || ((a) > 0 && (b) < 0)) + /* * cvRootfind * @@ -7920,30 +8858,38 @@ static int cvRcheck3(CVodeMem cv_mem) static int cvRootfind(CVodeMem cv_mem) { - realtype alph, tmid, gfrac, maxfrac, fracint, fracsub; + sunrealtype alph, tmid, gfrac, maxfrac, fracint, fracsub; int i, retval, imax, side, sideprev; - booleantype zroot, sgnchg; + sunbooleantype zroot, sgnchg; imax = 0; /* First check for change in sign in ghi or for a zero in ghi. */ maxfrac = ZERO; - zroot = SUNFALSE; - sgnchg = SUNFALSE; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if(!cv_mem->cv_gactive[i]) continue; - if (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) { - if(cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) { + zroot = SUNFALSE; + sgnchg = SUNFALSE; + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i]) { continue; } + if (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) + { + if (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO) + { zroot = SUNTRUE; } - } else { - if ( (cv_mem->cv_glo[i]*cv_mem->cv_ghi[i] < ZERO) && - (cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) ) { - gfrac = SUNRabs(cv_mem->cv_ghi[i]/(cv_mem->cv_ghi[i] - cv_mem->cv_glo[i])); - if (gfrac > maxfrac) { - sgnchg = SUNTRUE; + } + else + { + if ((DIFFERENT_SIGN(cv_mem->cv_glo[i], cv_mem->cv_ghi[i])) && + (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO)) + { + gfrac = + SUNRabs(cv_mem->cv_ghi[i] / (cv_mem->cv_ghi[i] - cv_mem->cv_glo[i])); + if (gfrac > maxfrac) + { + sgnchg = SUNTRUE; maxfrac = gfrac; - imax = i; + imax = i; } } } @@ -7951,18 +8897,25 @@ static int cvRootfind(CVodeMem cv_mem) /* If no sign change was found, reset trout and grout. Then return CV_SUCCESS if no zero was found, or set iroots and return RTFOUND. */ - if (!sgnchg) { + if (!sgnchg) + { cv_mem->cv_trout = cv_mem->cv_thi; - for (i = 0; i < cv_mem->cv_nrtfn; i++) cv_mem->cv_grout[i] = cv_mem->cv_ghi[i]; - if (!zroot) return(CV_SUCCESS); - for (i = 0; i < cv_mem->cv_nrtfn; i++) { + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + cv_mem->cv_grout[i] = cv_mem->cv_ghi[i]; + } + if (!zroot) { return (CV_SUCCESS); } + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { cv_mem->cv_iroots[i] = 0; - if(!cv_mem->cv_gactive[i]) continue; - if ( (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) && - (cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) ) + if (!cv_mem->cv_gactive[i]) { continue; } + if ((SUNRabs(cv_mem->cv_ghi[i]) == ZERO) && + (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO)) + { cv_mem->cv_iroots[i] = cv_mem->cv_glo[i] > 0 ? -1 : 1; + } } - return(RTFOUND); + return (RTFOUND); } /* Initialize alph to avoid compiler warning */ @@ -7970,11 +8923,13 @@ static int cvRootfind(CVodeMem cv_mem) /* A sign change was found. Loop to locate nearest root. */ - side = 0; sideprev = -1; - for(;;) { /* Looping point */ + side = 0; + sideprev = -1; + for (;;) + { /* Looping point */ /* If interval size is already less than tolerance ttol, break. */ - if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) break; + if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) { break; } /* Set weight alph. On the first two passes, set alph = 1. Thereafter, reset alph @@ -7986,73 +8941,91 @@ static int cvRootfind(CVodeMem cv_mem) The next guess tmid is the secant method value if alph = 1, but is closer to tlo if alph < 1, and closer to thi if alph > 1. */ - if (sideprev == side) { - alph = (side == 2) ? alph*TWO : alph*HALF; - } else { - alph = ONE; - } + if (sideprev == side) { alph = (side == 2) ? alph * TWO : alph * HALF; } + else { alph = ONE; } /* Set next root approximation tmid and get g(tmid). If tmid is too close to tlo or thi, adjust it inward, by a fractional distance that is between 0.1 and 0.5. */ - tmid = cv_mem->cv_thi - (cv_mem->cv_thi - cv_mem->cv_tlo) * - cv_mem->cv_ghi[imax] / (cv_mem->cv_ghi[imax] - alph*cv_mem->cv_glo[imax]); - if (SUNRabs(tmid - cv_mem->cv_tlo) < HALF*cv_mem->cv_ttol) { - fracint = SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo)/cv_mem->cv_ttol; - fracsub = (fracint > FIVE) ? PT1 : HALF/fracint; - tmid = cv_mem->cv_tlo + fracsub*(cv_mem->cv_thi - cv_mem->cv_tlo); + tmid = cv_mem->cv_thi - + (cv_mem->cv_thi - cv_mem->cv_tlo) * cv_mem->cv_ghi[imax] / + (cv_mem->cv_ghi[imax] - alph * cv_mem->cv_glo[imax]); + if (SUNRabs(tmid - cv_mem->cv_tlo) < HALF * cv_mem->cv_ttol) + { + fracint = SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) / cv_mem->cv_ttol; + fracsub = (fracint > FIVE) ? PT1 : HALF / fracint; + tmid = cv_mem->cv_tlo + fracsub * (cv_mem->cv_thi - cv_mem->cv_tlo); } - if (SUNRabs(cv_mem->cv_thi - tmid) < HALF*cv_mem->cv_ttol) { - fracint = SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo)/cv_mem->cv_ttol; - fracsub = (fracint > FIVE) ? PT1 : HALF/fracint; - tmid = cv_mem->cv_thi - fracsub*(cv_mem->cv_thi - cv_mem->cv_tlo); + if (SUNRabs(cv_mem->cv_thi - tmid) < HALF * cv_mem->cv_ttol) + { + fracint = SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) / cv_mem->cv_ttol; + fracsub = (fracint > FIVE) ? PT1 : HALF / fracint; + tmid = cv_mem->cv_thi - fracsub * (cv_mem->cv_thi - cv_mem->cv_tlo); } - (void) CVodeGetDky(cv_mem, tmid, 0, cv_mem->cv_y); + (void)CVodeGetDky(cv_mem, tmid, 0, cv_mem->cv_y); retval = cv_mem->cv_gfun(tmid, cv_mem->cv_y, cv_mem->cv_grout, cv_mem->cv_user_data); cv_mem->cv_nge++; - if (retval != 0) return(CV_RTFUNC_FAIL); + if (retval != 0) { return (CV_RTFUNC_FAIL); } /* Check to see in which subinterval g changes sign, and reset imax. Set side = 1 if sign change is on low side, or 2 if on high side. */ - maxfrac = ZERO; - zroot = SUNFALSE; - sgnchg = SUNFALSE; + maxfrac = ZERO; + zroot = SUNFALSE; + sgnchg = SUNFALSE; sideprev = side; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - if(!cv_mem->cv_gactive[i]) continue; - if (SUNRabs(cv_mem->cv_grout[i]) == ZERO) { - if(cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) zroot = SUNTRUE; - } else { - if ( (cv_mem->cv_glo[i]*cv_mem->cv_grout[i] < ZERO) && - (cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) ) { + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + if (!cv_mem->cv_gactive[i]) { continue; } + if (SUNRabs(cv_mem->cv_grout[i]) == ZERO) + { + if (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO) + { + zroot = SUNTRUE; + } + } + else + { + if ((DIFFERENT_SIGN(cv_mem->cv_glo[i], cv_mem->cv_grout[i])) && + (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO)) + { gfrac = SUNRabs(cv_mem->cv_grout[i] / (cv_mem->cv_grout[i] - cv_mem->cv_glo[i])); - if (gfrac > maxfrac) { - sgnchg = SUNTRUE; + if (gfrac > maxfrac) + { + sgnchg = SUNTRUE; maxfrac = gfrac; - imax = i; + imax = i; } } } } - if (sgnchg) { + if (sgnchg) + { /* Sign change found in (tlo,tmid); replace thi with tmid. */ cv_mem->cv_thi = tmid; for (i = 0; i < cv_mem->cv_nrtfn; i++) + { cv_mem->cv_ghi[i] = cv_mem->cv_grout[i]; + } side = 1; /* Stop at root thi if converged; otherwise loop. */ - if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) break; - continue; /* Return to looping point. */ + if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) + { + break; + } + continue; /* Return to looping point. */ } - if (zroot) { + if (zroot) + { /* No sign change in (tlo,tmid), but g = 0 at tmid; return root tmid. */ cv_mem->cv_thi = tmid; for (i = 0; i < cv_mem->cv_nrtfn; i++) + { cv_mem->cv_ghi[i] = cv_mem->cv_grout[i]; + } break; } @@ -8060,27 +9033,34 @@ static int cvRootfind(CVodeMem cv_mem) Sign change must be in (tmid,thi). Replace tlo with tmid. */ cv_mem->cv_tlo = tmid; for (i = 0; i < cv_mem->cv_nrtfn; i++) + { cv_mem->cv_glo[i] = cv_mem->cv_grout[i]; + } side = 2; /* Stop at root thi if converged; otherwise loop back. */ - if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) break; + if (SUNRabs(cv_mem->cv_thi - cv_mem->cv_tlo) <= cv_mem->cv_ttol) { break; } } /* End of root-search loop */ /* Reset trout and grout, set iroots, and return RTFOUND. */ cv_mem->cv_trout = cv_mem->cv_thi; - for (i = 0; i < cv_mem->cv_nrtfn; i++) { - cv_mem->cv_grout[i] = cv_mem->cv_ghi[i]; + for (i = 0; i < cv_mem->cv_nrtfn; i++) + { + cv_mem->cv_grout[i] = cv_mem->cv_ghi[i]; cv_mem->cv_iroots[i] = 0; - if(!cv_mem->cv_gactive[i]) continue; - if ( (SUNRabs(cv_mem->cv_ghi[i]) == ZERO) && - (cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) ) + if (!cv_mem->cv_gactive[i]) { continue; } + if ((SUNRabs(cv_mem->cv_ghi[i]) == ZERO) && + (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO)) + { cv_mem->cv_iroots[i] = cv_mem->cv_glo[i] > 0 ? -1 : 1; - if ( (cv_mem->cv_glo[i]*cv_mem->cv_ghi[i] < ZERO) && - (cv_mem->cv_rootdir[i]*cv_mem->cv_glo[i] <= ZERO) ) + } + if ((DIFFERENT_SIGN(cv_mem->cv_glo[i], cv_mem->cv_ghi[i])) && + (cv_mem->cv_rootdir[i] * cv_mem->cv_glo[i] <= ZERO)) + { cv_mem->cv_iroots[i] = cv_mem->cv_glo[i] > 0 ? -1 : 1; + } } - return(RTFOUND); + return (RTFOUND); } /* @@ -8107,25 +9087,22 @@ static int cvRootfind(CVodeMem cv_mem) * All the real work is done in the routines cvEwtSetSS, cvEwtSetSV. */ -int cvEwtSet(N_Vector ycur, N_Vector weight, void *data) +int cvEwtSet(N_Vector ycur, N_Vector weight, void* data) { CVodeMem cv_mem; int flag = 0; /* data points to cv_mem here */ - cv_mem = (CVodeMem) data; + cv_mem = (CVodeMem)data; - switch(cv_mem->cv_itol) { - case CV_SS: - flag = cvEwtSetSS(cv_mem, ycur, weight); - break; - case CV_SV: - flag = cvEwtSetSV(cv_mem, ycur, weight); - break; + switch (cv_mem->cv_itol) + { + case CV_SS: flag = cvEwtSetSS(cv_mem, ycur, weight); break; + case CV_SV: flag = cvEwtSetSV(cv_mem, ycur, weight); break; } - return(flag); + return (flag); } /* @@ -8143,11 +9120,12 @@ static int cvEwtSetSS(CVodeMem cv_mem, N_Vector ycur, N_Vector weight) N_VAbs(ycur, cv_mem->cv_tempv); N_VScale(cv_mem->cv_reltol, cv_mem->cv_tempv, cv_mem->cv_tempv); N_VAddConst(cv_mem->cv_tempv, cv_mem->cv_Sabstol, cv_mem->cv_tempv); - if (cv_mem->cv_atolmin0) { - if (N_VMin(cv_mem->cv_tempv) <= ZERO) return(-1); + if (cv_mem->cv_atolmin0) + { + if (N_VMin(cv_mem->cv_tempv) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempv, weight); - return(0); + return (0); } /* @@ -8163,13 +9141,14 @@ static int cvEwtSetSS(CVodeMem cv_mem, N_Vector ycur, N_Vector weight) static int cvEwtSetSV(CVodeMem cv_mem, N_Vector ycur, N_Vector weight) { N_VAbs(ycur, cv_mem->cv_tempv); - N_VLinearSum(cv_mem->cv_reltol, cv_mem->cv_tempv, ONE, - cv_mem->cv_Vabstol, cv_mem->cv_tempv); - if (cv_mem->cv_atolmin0) { - if (N_VMin(cv_mem->cv_tempv) <= ZERO) return(-1); + N_VLinearSum(cv_mem->cv_reltol, cv_mem->cv_tempv, ONE, cv_mem->cv_Vabstol, + cv_mem->cv_tempv); + if (cv_mem->cv_atolmin0) + { + if (N_VMin(cv_mem->cv_tempv) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempv, weight); - return(0); + return (0); } /* @@ -8179,19 +9158,15 @@ static int cvEwtSetSV(CVodeMem cv_mem, N_Vector ycur, N_Vector weight) static int cvQuadEwtSet(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ) { - int flag=0; + int flag = 0; - switch (cv_mem->cv_itolQ) { - case CV_SS: - flag = cvQuadEwtSetSS(cv_mem, qcur, weightQ); - break; - case CV_SV: - flag = cvQuadEwtSetSV(cv_mem, qcur, weightQ); - break; + switch (cv_mem->cv_itolQ) + { + case CV_SS: flag = cvQuadEwtSetSS(cv_mem, qcur, weightQ); break; + case CV_SV: flag = cvQuadEwtSetSV(cv_mem, qcur, weightQ); break; } - return(flag); - + return (flag); } /* @@ -8204,11 +9179,12 @@ static int cvQuadEwtSetSS(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ) N_VAbs(qcur, cv_mem->cv_tempvQ); N_VScale(cv_mem->cv_reltolQ, cv_mem->cv_tempvQ, cv_mem->cv_tempvQ); N_VAddConst(cv_mem->cv_tempvQ, cv_mem->cv_SabstolQ, cv_mem->cv_tempvQ); - if (cv_mem->cv_atolQmin0) { - if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) return(-1); + if (cv_mem->cv_atolQmin0) + { + if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempvQ, weightQ); - return(0); + return (0); } /* @@ -8219,13 +9195,14 @@ static int cvQuadEwtSetSS(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ) static int cvQuadEwtSetSV(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ) { N_VAbs(qcur, cv_mem->cv_tempvQ); - N_VLinearSum(cv_mem->cv_reltolQ, cv_mem->cv_tempvQ, ONE, - cv_mem->cv_VabstolQ, cv_mem->cv_tempvQ); - if (cv_mem->cv_atolQmin0) { - if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) return(-1); + N_VLinearSum(cv_mem->cv_reltolQ, cv_mem->cv_tempvQ, ONE, cv_mem->cv_VabstolQ, + cv_mem->cv_tempvQ); + if (cv_mem->cv_atolQmin0) + { + if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempvQ, weightQ); - return(0); + return (0); } /* @@ -8233,23 +9210,18 @@ static int cvQuadEwtSetSV(CVodeMem cv_mem, N_Vector qcur, N_Vector weightQ) * */ -static int cvSensEwtSet(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) +static int cvSensEwtSet(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS) { - int flag=0; + int flag = 0; - switch (cv_mem->cv_itolS) { - case CV_EE: - flag = cvSensEwtSetEE(cv_mem, yScur, weightS); - break; - case CV_SS: - flag = cvSensEwtSetSS(cv_mem, yScur, weightS); - break; - case CV_SV: - flag = cvSensEwtSetSV(cv_mem, yScur, weightS); - break; + switch (cv_mem->cv_itolS) + { + case CV_EE: flag = cvSensEwtSetEE(cv_mem, yScur, weightS); break; + case CV_SS: flag = cvSensEwtSetSS(cv_mem, yScur, weightS); break; + case CV_SV: flag = cvSensEwtSetSV(cv_mem, yScur, weightS); break; } - return(flag); + return (flag); } /* @@ -8264,7 +9236,7 @@ static int cvSensEwtSet(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) +static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS) { int is; N_Vector pyS; @@ -8273,13 +9245,14 @@ static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) /* Use tempvS[0] as temporary storage for the scaled sensitivity */ pyS = cv_mem->cv_tempvS[0]; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VScale(cv_mem->cv_pbar[is], yScur[is], pyS); flag = cv_mem->cv_efun(pyS, weightS[is], cv_mem->cv_e_data); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } N_VScale(cv_mem->cv_pbar[is], weightS[is], weightS[is]); } - return(0); + return (0); } /* @@ -8287,20 +9260,22 @@ static int cvSensEwtSetEE(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int cvSensEwtSetSS(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) +static int cvSensEwtSetSS(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS) { int is; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(yScur[is], cv_mem->cv_tempv); N_VScale(cv_mem->cv_reltolS, cv_mem->cv_tempv, cv_mem->cv_tempv); N_VAddConst(cv_mem->cv_tempv, cv_mem->cv_SabstolS[is], cv_mem->cv_tempv); - if (cv_mem->cv_atolSmin0[is]) { - if (N_VMin(cv_mem->cv_tempv) <= ZERO) return(-1); + if (cv_mem->cv_atolSmin0[is]) + { + if (N_VMin(cv_mem->cv_tempv) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempv, weightS[is]); } - return(0); + return (0); } /* @@ -8308,20 +9283,22 @@ static int cvSensEwtSetSS(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int cvSensEwtSetSV(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) +static int cvSensEwtSetSV(CVodeMem cv_mem, N_Vector* yScur, N_Vector* weightS) { int is; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(yScur[is], cv_mem->cv_tempv); N_VLinearSum(cv_mem->cv_reltolS, cv_mem->cv_tempv, ONE, cv_mem->cv_VabstolS[is], cv_mem->cv_tempv); - if (cv_mem->cv_atolSmin0[is]) { - if (N_VMin(cv_mem->cv_tempv) <= ZERO) return(-1); + if (cv_mem->cv_atolSmin0[is]) + { + if (N_VMin(cv_mem->cv_tempv) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempv, weightS[is]); } - return(0); + return (0); } /* @@ -8329,23 +9306,18 @@ static int cvSensEwtSetSV(CVodeMem cv_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int cvQuadSensEwtSet(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS) +static int cvQuadSensEwtSet(CVodeMem cv_mem, N_Vector* yQScur, N_Vector* weightQS) { - int flag=0; + int flag = 0; - switch (cv_mem->cv_itolQS) { - case CV_EE: - flag = cvQuadSensEwtSetEE(cv_mem, yQScur, weightQS); - break; - case CV_SS: - flag = cvQuadSensEwtSetSS(cv_mem, yQScur, weightQS); - break; - case CV_SV: - flag = cvQuadSensEwtSetSV(cv_mem, yQScur, weightQS); - break; + switch (cv_mem->cv_itolQS) + { + case CV_EE: flag = cvQuadSensEwtSetEE(cv_mem, yQScur, weightQS); break; + case CV_SS: flag = cvQuadSensEwtSetSS(cv_mem, yQScur, weightQS); break; + case CV_SV: flag = cvQuadSensEwtSetSV(cv_mem, yQScur, weightQS); break; } - return(flag); + return (flag); } /* @@ -8360,7 +9332,8 @@ static int cvQuadSensEwtSet(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQ * weight vector calculation as the quadrature vector. * */ -static int cvQuadSensEwtSetEE(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS) +static int cvQuadSensEwtSetEE(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; N_Vector pyS; @@ -8369,45 +9342,52 @@ static int cvQuadSensEwtSetEE(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weigh /* Use tempvQS[0] as temporary storage for the scaled sensitivity */ pyS = cv_mem->cv_tempvQS[0]; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VScale(cv_mem->cv_pbar[is], yQScur[is], pyS); flag = cvQuadEwtSet(cv_mem, pyS, weightQS[is]); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } N_VScale(cv_mem->cv_pbar[is], weightQS[is], weightQS[is]); } - return(0); + return (0); } -static int cvQuadSensEwtSetSS(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS) +static int cvQuadSensEwtSetSS(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(yQScur[is], cv_mem->cv_tempvQ); N_VScale(cv_mem->cv_reltolQS, cv_mem->cv_tempvQ, cv_mem->cv_tempvQ); N_VAddConst(cv_mem->cv_tempvQ, cv_mem->cv_SabstolQS[is], cv_mem->cv_tempvQ); - if (cv_mem->cv_atolQSmin0[is]) { - if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) return(-1); + if (cv_mem->cv_atolQSmin0[is]) + { + if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempvQ, weightQS[is]); } - return(0); + return (0); } -static int cvQuadSensEwtSetSV(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weightQS) +static int cvQuadSensEwtSetSV(CVodeMem cv_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VAbs(yQScur[is], cv_mem->cv_tempvQ); N_VLinearSum(cv_mem->cv_reltolQS, cv_mem->cv_tempvQ, ONE, cv_mem->cv_VabstolQS[is], cv_mem->cv_tempvQ); - if (cv_mem->cv_atolQSmin0[is]) { - if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) return(-1); + if (cv_mem->cv_atolQSmin0[is]) + { + if (N_VMin(cv_mem->cv_tempvQ) <= ZERO) { return (-1); } } N_VInv(cv_mem->cv_tempvQ, weightQS[is]); } - return(0); + return (0); } /* @@ -8422,14 +9402,14 @@ static int cvQuadSensEwtSetSV(CVodeMem cv_mem, N_Vector *yQScur, N_Vector *weigh * Updates the norm old_nrm to account for all quadratures. */ -static realtype cvQuadUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector xQ, N_Vector wQ) +static sunrealtype cvQuadUpdateNorm(SUNDIALS_MAYBE_UNUSED CVodeMem cv_mem, + sunrealtype old_nrm, N_Vector xQ, N_Vector wQ) { - realtype qnrm; + sunrealtype qnrm; qnrm = N_VWrmsNorm(xQ, wQ); - if (old_nrm > qnrm) return(old_nrm); - else return(qnrm); + if (old_nrm > qnrm) { return (old_nrm); } + else { return (qnrm); } } /* @@ -8444,18 +9424,20 @@ static realtype cvQuadUpdateNorm(CVodeMem cv_mem, realtype old_nrm, * during the NLS solution and before the error test. */ -realtype cvSensNorm(CVodeMem cv_mem, N_Vector *xS, N_Vector *wS) +sunrealtype cvSensNorm(CVodeMem cv_mem, N_Vector* xS, N_Vector* wS) { int is; - realtype nrm; + sunrealtype nrm; - (void) N_VWrmsNormVectorArray(cv_mem->cv_Ns, xS, wS, cv_mem->cv_cvals); + (void)N_VWrmsNormVectorArray(cv_mem->cv_Ns, xS, wS, cv_mem->cv_cvals); nrm = cv_mem->cv_cvals[0]; - for (is=1; iscv_Ns; is++) - if ( cv_mem->cv_cvals[is] > nrm ) nrm = cv_mem->cv_cvals[is]; + for (is = 1; is < cv_mem->cv_Ns; is++) + { + if (cv_mem->cv_cvals[is] > nrm) { nrm = cv_mem->cv_cvals[is]; } + } - return(nrm); + return (nrm); } /* @@ -8464,14 +9446,14 @@ realtype cvSensNorm(CVodeMem cv_mem, N_Vector *xS, N_Vector *wS) * Updates the norm old_nrm to account for all sensitivities. */ -realtype cvSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector *xS, N_Vector *wS) +sunrealtype cvSensUpdateNorm(CVodeMem cv_mem, sunrealtype old_nrm, N_Vector* xS, + N_Vector* wS) { - realtype snrm; + sunrealtype snrm; snrm = cvSensNorm(cv_mem, xS, wS); - if (old_nrm > snrm) return(old_nrm); - else return(snrm); + if (old_nrm > snrm) { return (old_nrm); } + else { return (snrm); } } /* @@ -8485,18 +9467,20 @@ realtype cvSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, * Called by cvQuadSensUpdateNorm. */ -static realtype cvQuadSensNorm(CVodeMem cv_mem, N_Vector *xQS, N_Vector *wQS) +static sunrealtype cvQuadSensNorm(CVodeMem cv_mem, N_Vector* xQS, N_Vector* wQS) { int is; - realtype nrm; + sunrealtype nrm; - (void) N_VWrmsNormVectorArray(cv_mem->cv_Ns, xQS, wQS, cv_mem->cv_cvals); + (void)N_VWrmsNormVectorArray(cv_mem->cv_Ns, xQS, wQS, cv_mem->cv_cvals); nrm = cv_mem->cv_cvals[0]; - for (is=1; iscv_Ns; is++) - if ( cv_mem->cv_cvals[is] > nrm ) nrm = cv_mem->cv_cvals[is]; + for (is = 1; is < cv_mem->cv_Ns; is++) + { + if (cv_mem->cv_cvals[is] > nrm) { nrm = cv_mem->cv_cvals[is]; } + } - return(nrm); + return (nrm); } /* @@ -8505,14 +9489,14 @@ static realtype cvQuadSensNorm(CVodeMem cv_mem, N_Vector *xQS, N_Vector *wQS) * Updates the norm old_nrm to account for all quadrature sensitivities. */ -static realtype cvQuadSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector *xQS, N_Vector *wQS) +static sunrealtype cvQuadSensUpdateNorm(CVodeMem cv_mem, sunrealtype old_nrm, + N_Vector* xQS, N_Vector* wQS) { - realtype snrm; + sunrealtype snrm; snrm = cvQuadSensNorm(cv_mem, xQS, wQS); - if (old_nrm > snrm) return(old_nrm); - else return(snrm); + if (old_nrm > snrm) { return (old_nrm); } + else { return (snrm); } } /* @@ -8541,27 +9525,30 @@ static realtype cvQuadSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, * */ -int cvSensRhsWrapper(CVodeMem cv_mem, realtype time, - N_Vector ycur, N_Vector fcur, - N_Vector *yScur, N_Vector *fScur, +int cvSensRhsWrapper(CVodeMem cv_mem, sunrealtype time, N_Vector ycur, + N_Vector fcur, N_Vector* yScur, N_Vector* fScur, N_Vector temp1, N_Vector temp2) { - int retval=0, is; + int retval = 0, is; - if (cv_mem->cv_ifS==CV_ALLSENS) { - retval = cv_mem->cv_fS(cv_mem->cv_Ns, time, ycur, fcur, yScur, - fScur, cv_mem->cv_fS_data, temp1, temp2); + if (cv_mem->cv_ifS == CV_ALLSENS) + { + retval = cv_mem->cv_fS(cv_mem->cv_Ns, time, ycur, fcur, yScur, fScur, + cv_mem->cv_fS_data, temp1, temp2); cv_mem->cv_nfSe++; - } else { - for (is=0; iscv_Ns; is++) { + } + else + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { retval = cv_mem->cv_fS1(cv_mem->cv_Ns, time, ycur, fcur, is, yScur[is], fScur[is], cv_mem->cv_fS_data, temp1, temp2); cv_mem->cv_nfSe++; - if (retval != 0) break; + if (retval != 0) { break; } } } - return(retval); + return (retval); } /* @@ -8577,18 +9564,17 @@ int cvSensRhsWrapper(CVodeMem cv_mem, realtype time, * The return value is that of the sensitivity RHS function fS1, */ -int cvSensRhs1Wrapper(CVodeMem cv_mem, realtype time, - N_Vector ycur, N_Vector fcur, - int is, N_Vector yScur, N_Vector fScur, +int cvSensRhs1Wrapper(CVodeMem cv_mem, sunrealtype time, N_Vector ycur, + N_Vector fcur, int is, N_Vector yScur, N_Vector fScur, N_Vector temp1, N_Vector temp2) { int retval; - retval = cv_mem->cv_fS1(cv_mem->cv_Ns, time, ycur, fcur, is, yScur, - fScur, cv_mem->cv_fS_data, temp1, temp2); + retval = cv_mem->cv_fS1(cv_mem->cv_Ns, time, ycur, fcur, is, yScur, fScur, + cv_mem->cv_fS_data, temp1, temp2); cv_mem->cv_nfSe++; - return(retval); + return (retval); } /* @@ -8608,21 +9594,20 @@ int cvSensRhs1Wrapper(CVodeMem cv_mem, realtype time, * by finite differences */ -int cvSensRhsInternalDQ(int Ns, realtype t, - N_Vector y, N_Vector ydot, - N_Vector *yS, N_Vector *ySdot, - void *cvode_mem, +int cvSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + N_Vector* yS, N_Vector* ySdot, void* cvode_mem, N_Vector ytemp, N_Vector ftemp) { int is, retval; - for (is=0; iscv_reltol, cv_mem->cv_uround)); - rdelta = ONE/delta; + delta = SUNRsqrt(SUNMAX(cv_mem->cv_reltol, cv_mem->cv_uround)); + rdelta = ONE / delta; pbari = cv_mem->cv_pbar[is]; @@ -8668,128 +9651,137 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, psave = cv_mem->cv_p[which]; Deltap = pbari * delta; - rDeltap = ONE/Deltap; + rDeltap = ONE / Deltap; norms = N_VWrmsNorm(yS, cv_mem->cv_ewt) * pbari; rDeltay = SUNMAX(norms, rdelta) / pbari; - Deltay = ONE/rDeltay; + Deltay = ONE / rDeltay; - if (cv_mem->cv_DQrhomax == ZERO) { + if (cv_mem->cv_DQrhomax == ZERO) + { /* No switching */ - method = (cv_mem->cv_DQtype==CV_CENTERED) ? CENTERED1 : FORWARD1; - } else { + method = (cv_mem->cv_DQtype == CV_CENTERED) ? CENTERED1 : FORWARD1; + } + else + { /* switch between simultaneous/separate DQ */ ratio = Deltay * rDeltap; - if ( SUNMAX(ONE/ratio, ratio) <= cv_mem->cv_DQrhomax ) - method = (cv_mem->cv_DQtype==CV_CENTERED) ? CENTERED1 : FORWARD1; - else - method = (cv_mem->cv_DQtype==CV_CENTERED) ? CENTERED2 : FORWARD2; + if (SUNMAX(ONE / ratio, ratio) <= cv_mem->cv_DQrhomax) + { + method = (cv_mem->cv_DQtype == CV_CENTERED) ? CENTERED1 : FORWARD1; + } + else { method = (cv_mem->cv_DQtype == CV_CENTERED) ? CENTERED2 : FORWARD2; } } - switch(method) { - + switch (method) + { case CENTERED1: - Delta = SUNMIN(Deltay, Deltap); - r2Delta = HALF/Delta; + Delta = SUNMIN(Deltay, Deltap); + r2Delta = HALF / Delta; - N_VLinearSum(ONE,y,Delta,yS,ytemp); + N_VLinearSum(ONE, y, Delta, yS, ytemp); cv_mem->cv_p[which] = psave + Delta; retval = cv_mem->cv_f(t, ytemp, ySdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } - N_VLinearSum(ONE,y,-Delta,yS,ytemp); + N_VLinearSum(ONE, y, -Delta, yS, ytemp); cv_mem->cv_p[which] = psave - Delta; retval = cv_mem->cv_f(t, ytemp, ftemp, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } - N_VLinearSum(r2Delta,ySdot,-r2Delta,ftemp,ySdot); + N_VLinearSum(r2Delta, ySdot, -r2Delta, ftemp, ySdot); break; case CENTERED2: - r2Deltap = HALF/Deltap; - r2Deltay = HALF/Deltay; + r2Deltap = HALF / Deltap; + r2Deltay = HALF / Deltay; - N_VLinearSum(ONE,y,Deltay,yS,ytemp); + N_VLinearSum(ONE, y, Deltay, yS, ytemp); retval = cv_mem->cv_f(t, ytemp, ySdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } - N_VLinearSum(ONE,y,-Deltay,yS,ytemp); + N_VLinearSum(ONE, y, -Deltay, yS, ytemp); retval = cv_mem->cv_f(t, ytemp, ftemp, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(r2Deltay, ySdot, -r2Deltay, ftemp, ySdot); cv_mem->cv_p[which] = psave + Deltap; - retval = cv_mem->cv_f(t, y, ytemp, cv_mem->cv_user_data); + retval = cv_mem->cv_f(t, y, ytemp, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } cv_mem->cv_p[which] = psave - Deltap; - retval = cv_mem->cv_f(t, y, ftemp, cv_mem->cv_user_data); + retval = cv_mem->cv_f(t, y, ftemp, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* ySdot = ySdot + r2Deltap * ytemp - r2Deltap * ftemp */ - cvals[0] = ONE; Xvecs[0] = ySdot; - cvals[1] = r2Deltap; Xvecs[1] = ytemp; - cvals[2] = -r2Deltap; Xvecs[2] = ftemp; + cvals[0] = ONE; + Xvecs[0] = ySdot; + cvals[1] = r2Deltap; + Xvecs[1] = ytemp; + cvals[2] = -r2Deltap; + Xvecs[2] = ftemp; retval = N_VLinearCombination(3, cvals, Xvecs, ySdot); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } break; case FORWARD1: - Delta = SUNMIN(Deltay, Deltap); - rDelta = ONE/Delta; + Delta = SUNMIN(Deltay, Deltap); + rDelta = ONE / Delta; - N_VLinearSum(ONE,y,Delta,yS,ytemp); + N_VLinearSum(ONE, y, Delta, yS, ytemp); cv_mem->cv_p[which] = psave + Delta; retval = cv_mem->cv_f(t, ytemp, ySdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } - N_VLinearSum(rDelta,ySdot,-rDelta,ydot,ySdot); + N_VLinearSum(rDelta, ySdot, -rDelta, ydot, ySdot); break; case FORWARD2: - N_VLinearSum(ONE,y,Deltay,yS,ytemp); + N_VLinearSum(ONE, y, Deltay, yS, ytemp); retval = cv_mem->cv_f(t, ytemp, ySdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(rDeltay, ySdot, -rDeltay, ydot, ySdot); cv_mem->cv_p[which] = psave + Deltap; - retval = cv_mem->cv_f(t, y, ytemp, cv_mem->cv_user_data); + retval = cv_mem->cv_f(t, y, ytemp, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* ySdot = ySdot + rDeltap * ytemp - rDeltap * ydot */ - cvals[0] = ONE; Xvecs[0] = ySdot; - cvals[1] = rDeltap; Xvecs[1] = ytemp; - cvals[2] = -rDeltap; Xvecs[2] = ydot; + cvals[0] = ONE; + Xvecs[0] = ySdot; + cvals[1] = rDeltap; + Xvecs[1] = ytemp; + cvals[2] = -rDeltap; + Xvecs[2] = ydot; retval = N_VLinearCombination(3, cvals, Xvecs, ySdot); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } break; - } cv_mem->cv_p[which] = psave; @@ -8797,10 +9789,9 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, /* Increment counter nfeS */ cv_mem->cv_nfeS += nfel; - return(0); + return (0); } - /* * cvQuadSensRhsInternalDQ - internal CVQuadSensRhsFn * @@ -8809,45 +9800,41 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, * done in cvQuadSensRhs1InternalDQ. */ -static int cvQuadSensRhsInternalDQ(int Ns, realtype t, - N_Vector y, N_Vector *yS, - N_Vector yQdot, N_Vector *yQSdot, - void *cvode_mem, - N_Vector tmp, N_Vector tmpQ) +static int cvQuadSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector y, + N_Vector* yS, N_Vector yQdot, N_Vector* yQSdot, + void* cvode_mem, N_Vector tmp, N_Vector tmpQ) { CVodeMem cv_mem; int is, retval; /* cvode_mem is passed here as user data */ - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - for (is=0; iscv_reltol, cv_mem->cv_uround)); - rdelta = ONE/delta; + delta = SUNRsqrt(SUNMAX(cv_mem->cv_reltol, cv_mem->cv_uround)); + rdelta = ONE / delta; pbari = cv_mem->cv_pbar[is]; @@ -8858,30 +9845,30 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, Deltap = pbari * delta; norms = N_VWrmsNorm(yS, cv_mem->cv_ewt) * pbari; rDeltay = SUNMAX(norms, rdelta) / pbari; - Deltay = ONE/rDeltay; + Deltay = ONE / rDeltay; - method = (cv_mem->cv_DQtype==CV_CENTERED) ? CENTERED1 : FORWARD1; - - switch(method) { + method = (cv_mem->cv_DQtype == CV_CENTERED) ? CENTERED1 : FORWARD1; + switch (method) + { case CENTERED1: - Delta = SUNMIN(Deltay, Deltap); - r2Delta = HALF/Delta; + Delta = SUNMIN(Deltay, Deltap); + r2Delta = HALF / Delta; N_VLinearSum(ONE, y, Delta, yS, tmp); cv_mem->cv_p[which] = psave + Delta; retval = cv_mem->cv_fQ(t, tmp, yQSdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(ONE, y, -Delta, yS, tmp); cv_mem->cv_p[which] = psave - Delta; retval = cv_mem->cv_fQ(t, tmp, tmpQ, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(r2Delta, yQSdot, -r2Delta, tmpQ, yQSdot); @@ -8889,20 +9876,19 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, case FORWARD1: - Delta = SUNMIN(Deltay, Deltap); - rDelta = ONE/Delta; + Delta = SUNMIN(Deltay, Deltap); + rDelta = ONE / Delta; N_VLinearSum(ONE, y, Delta, yS, tmp); cv_mem->cv_p[which] = psave + Delta; retval = cv_mem->cv_fQ(t, tmp, yQSdot, cv_mem->cv_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(rDelta, yQSdot, -rDelta, yQdot, yQSdot); break; - } cv_mem->cv_p[which] = psave; @@ -8910,82 +9896,63 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, /* Increment counter nfQeS */ cv_mem->cv_nfQeS += nfel; - return(0); + return (0); } - - /* * ----------------------------------------------------------------- * Error message handling functions * ----------------------------------------------------------------- */ -/* - * cvProcessError is a high level error handling function. - * - If cv_mem==NULL it prints the error message to stderr. - * - Otherwise, it sets up and calls the error handling function - * pointed to by cv_ehfun. - */ - -void cvProcessError(CVodeMem cv_mem, - int error_code, const char *module, const char *fname, - const char *msgfmt, ...) +void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...) { - va_list ap; - char msg[256]; - - /* Initialize the argument pointer variable + /* We initialize the argument pointer variable before each vsnprintf call to avoid undefined behavior (msgfmt is the last required argument to cvProcessError) */ - - va_start(ap, msgfmt); + va_list ap; /* Compose the message */ - - vsprintf(msg, msgfmt, ap); - - if (cv_mem == NULL) { /* We write to stderr */ -#ifndef NO_FPRINTF_OUTPUT - fprintf(stderr, "\n[%s ERROR] %s\n ", module, fname); - fprintf(stderr, "%s\n\n", msg); -#endif - - } else { /* We can call ehfun */ - cv_mem->cv_ehfun(error_code, module, fname, msg, cv_mem->cv_eh_data); - } - - /* Finalize argument processing */ + va_start(ap, msgfmt); + size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1; va_end(ap); - return; -} - -/* - * cvErrHandler is the default error handling function. - * It sends the error message to the stream pointed to by cv_errfp. - */ + char* msg = (char*)malloc(msglen); -void cvErrHandler(int error_code, const char *module, - const char *function, char *msg, void *data) -{ - CVodeMem cv_mem; - char err_type[10]; + va_start(ap, msgfmt); + vsnprintf(msg, msglen, msgfmt, ap); + va_end(ap); - /* data points to cv_mem here */ + do { + if (cv_mem == NULL) + { + SUNGlobalFallbackErrHandler(line, func, file, msg, error_code); + break; + } - cv_mem = (CVodeMem) data; +/* AMICI: https://github.com/AMICI-dev/AMICI/issues/2550 */ +#ifdef AMICI_SUNLOGGER_WARNINGS + if (error_code == CV_WARNING) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING + char* file_and_line = sunCombineFileAndLine(line, file); + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_WARNING, file_and_line, func, + msg); + free(file_and_line); +#endif + break; + } +#endif - if (error_code == CV_WARNING) - sprintf(err_type,"WARNING"); - else - sprintf(err_type,"ERROR"); + /* Call the SUNDIALS main error handler */ + SUNHandleErrWithMsg(line, func, file, msg, error_code, cv_mem->cv_sunctx); -#ifndef NO_FPRINTF_OUTPUT - if (cv_mem->cv_errfp!=NULL) { - fprintf(cv_mem->cv_errfp,"\n[%s %s] %s\n",module,err_type,function); - fprintf(cv_mem->cv_errfp," %s\n\n",msg); + /* Clear the last error value */ + (void)SUNContext_GetLastError(cv_mem->cv_sunctx); } -#endif + while (0); + + free(msg); return; } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre.c index d8e6a282b..55dbe1afb 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre.c @@ -4,7 +4,7 @@ * Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,34 +21,32 @@ #include #include +#include -#include "cvodes_impl.h" #include "cvodes_bandpre_impl.h" +#include "cvodes_impl.h" #include "cvodes_ls_impl.h" -#include -#define MIN_INC_MULT RCONST(1000.0) -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#define MIN_INC_MULT SUN_RCONST(1000.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /* Prototypes of cvBandPrecSetup and cvBandPrecSolve */ -static int cvBandPrecSetup(realtype t, N_Vector y, N_Vector fy, - booleantype jok, booleantype *jcurPtr, - realtype gamma, void *bp_data); -static int cvBandPrecSolve(realtype t, N_Vector y, N_Vector fy, - N_Vector r, N_Vector z, - realtype gamma, realtype delta, - int lr, void *bp_data); +static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* bp_data); +static int cvBandPrecSolve(sunrealtype t, N_Vector y, N_Vector fy, N_Vector r, + N_Vector z, sunrealtype gamma, sunrealtype delta, + int lr, void* bp_data); /* Prototype for cvBandPrecFree */ static int cvBandPrecFree(CVodeMem cv_mem); /* Prototype for difference quotient Jacobian calculation routine */ -static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, +static int cvBandPrecDQJac(CVBandPrecData pdata, sunrealtype t, N_Vector y, N_Vector fy, N_Vector ftemp, N_Vector ytemp); - /*================================================================ PART I - Forward Problems ================================================================*/ @@ -61,8 +59,8 @@ static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, internal representation by checking that the function N_VGetArrayPointer exists. -----------------------------------------------------------------*/ -int CVBandPrecInit(void *cvode_mem, sunindextype N, - sunindextype mu, sunindextype ml) +int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu, + sunindextype ml) { CVodeMem cv_mem; CVLsMem cvls_mem; @@ -70,122 +68,137 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, sunindextype mup, mlp, storagemu; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Test if the CVSLS linear solver interface has been attached */ - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Test compatibility of NVECTOR package with the BAND preconditioner */ - if(cv_mem->cv_tempv->ops->nvgetarraypointer == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_BAD_NVECTOR); - return(CVLS_ILL_INPUT); + if (cv_mem->cv_tempv->ops->nvgetarraypointer == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBP_BAD_NVECTOR); + return (CVLS_ILL_INPUT); } /* Allocate data memory */ pdata = NULL; - pdata = (CVBandPrecData) malloc(sizeof *pdata); - if (pdata == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + pdata = (CVBandPrecData)malloc(sizeof *pdata); + if (pdata == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Load pointers and bandwidths into pdata block. */ pdata->cvode_mem = cvode_mem; - pdata->N = N; - pdata->mu = mup = SUNMIN(N-1, SUNMAX(0,mu)); - pdata->ml = mlp = SUNMIN(N-1, SUNMAX(0,ml)); + pdata->N = N; + pdata->mu = mup = SUNMIN(N - 1, SUNMAX(0, mu)); + pdata->ml = mlp = SUNMIN(N - 1, SUNMAX(0, ml)); /* Initialize nfeBP counter */ pdata->nfeBP = 0; /* Allocate memory for saved banded Jacobian approximation. */ pdata->savedJ = NULL; - pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup); - if (pdata->savedJ == NULL) { - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup, cv_mem->cv_sunctx); + if (pdata->savedJ == NULL) + { + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Allocate memory for banded preconditioner. */ - storagemu = SUNMIN(N-1, mup+mlp); + storagemu = SUNMIN(N - 1, mup + mlp); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu); - if (pdata->savedP == NULL) { + pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu, cv_mem->cv_sunctx); + if (pdata->savedP == NULL) + { SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP); - if (pdata->LS == NULL) { + pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP, cv_mem->cv_sunctx); + if (pdata->LS == NULL) + { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* allocate memory for temporary N_Vectors */ pdata->tmp1 = NULL; pdata->tmp1 = N_VClone(cv_mem->cv_tempv); - if (pdata->tmp1 == NULL) { + if (pdata->tmp1 == NULL) + { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } pdata->tmp2 = NULL; pdata->tmp2 = N_VClone(cv_mem->cv_tempv); - if (pdata->tmp2 == NULL) { + if (pdata->tmp2 == NULL) + { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); N_VDestroy(pdata->tmp1); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBP_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) { + if (flag != SUN_SUCCESS) + { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSBANDPRE", - "CVBandPrecInit", MSGBP_SUNLS_FAIL); - return(CVLS_SUNLS_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, + MSGBP_SUNLS_FAIL); + return (CVLS_SUNLS_FAIL); } /* make sure P_data is free from any previous allocations */ - if (cvls_mem->pfree) - cvls_mem->pfree(cv_mem); + if (cvls_mem->pfree) { cvls_mem->pfree(cv_mem); } /* Point to the new P_data field in the LS memory */ cvls_mem->P_data = pdata; @@ -194,14 +207,11 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, cvls_mem->pfree = cvBandPrecFree; /* Attach preconditioner solve and setup functions */ - flag = CVodeSetPreconditioner(cvode_mem, cvBandPrecSetup, - cvBandPrecSolve); - return(flag); + flag = CVodeSetPreconditioner(cvode_mem, cvBandPrecSetup, cvBandPrecSolve); + return (flag); } - -int CVBandPrecGetWorkSpace(void *cvode_mem, long int *lenrwBP, - long int *leniwBP) +int CVBandPrecGetWorkSpace(void* cvode_mem, long int* lenrwBP, long int* leniwBP) { CVodeMem cv_mem; CVLsMem cvls_mem; @@ -210,91 +220,99 @@ int CVBandPrecGetWorkSpace(void *cvode_mem, long int *lenrwBP, long int lrw, liw; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", - "CVBandPrecGetWorkSpace", MSGBP_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE", - "CVBandPrecGetWorkSpace", MSGBP_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) { - cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBANDPRE", - "CVBandPrecGetWorkSpace", MSGBP_PMEM_NULL); - return(CVLS_PMEM_NULL); + if (cvls_mem->P_data == NULL) + { + cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_PMEM_NULL); + return (CVLS_PMEM_NULL); } - pdata = (CVBandPrecData) cvls_mem->P_data; + pdata = (CVBandPrecData)cvls_mem->P_data; /* sum space requirements for all objects in pdata */ *leniwBP = 4; *lenrwBP = 0; - if (cv_mem->cv_tempv->ops->nvspace) { + if (cv_mem->cv_tempv->ops->nvspace) + { N_VSpace(cv_mem->cv_tempv, &lrw1, &liw1); - *leniwBP += 2*liw1; - *lenrwBP += 2*lrw1; + *leniwBP += 2 * liw1; + *lenrwBP += 2 * lrw1; } - if (pdata->savedJ->ops->space) { + if (pdata->savedJ->ops->space) + { flag = SUNMatSpace(pdata->savedJ, &lrw, &liw); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } *leniwBP += liw; *lenrwBP += lrw; } - if (pdata->savedP->ops->space) { + if (pdata->savedP->ops->space) + { flag = SUNMatSpace(pdata->savedP, &lrw, &liw); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } *leniwBP += liw; *lenrwBP += lrw; } - if (pdata->LS->ops->space) { + if (pdata->LS->ops->space) + { flag = SUNLinSolSpace(pdata->LS, &lrw, &liw); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } *leniwBP += liw; *lenrwBP += lrw; } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - -int CVBandPrecGetNumRhsEvals(void *cvode_mem, long int *nfevalsBP) +int CVBandPrecGetNumRhsEvals(void* cvode_mem, long int* nfevalsBP) { CVodeMem cv_mem; CVLsMem cvls_mem; CVBandPrecData pdata; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", - "CVBandPrecGetNumRhsEvals", MSGBP_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE", - "CVBandPrecGetNumRhsEvals", MSGBP_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) { - cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBANDPRE", - "CVBandPrecGetNumRhsEvals", MSGBP_PMEM_NULL); - return(CVLS_PMEM_NULL); + if (cvls_mem->P_data == NULL) + { + cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_PMEM_NULL); + return (CVLS_PMEM_NULL); } - pdata = (CVBandPrecData) cvls_mem->P_data; + pdata = (CVBandPrecData)cvls_mem->P_data; *nfevalsBP = pdata->nfeBP; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*----------------------------------------------------------------- cvBandPrecSetup ----------------------------------------------------------------- @@ -336,83 +354,73 @@ int CVBandPrecGetNumRhsEvals(void *cvode_mem, long int *nfevalsBP) 0 if successful, or 1 if the band factorization failed. -----------------------------------------------------------------*/ -static int cvBandPrecSetup(realtype t, N_Vector y, N_Vector fy, - booleantype jok, booleantype *jcurPtr, - realtype gamma, void *bp_data) +static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* bp_data) { CVBandPrecData pdata; CVodeMem cv_mem; int retval; /* Assume matrix and lpivots have already been allocated. */ - pdata = (CVBandPrecData) bp_data; - cv_mem = (CVodeMem) pdata->cvode_mem; - - if (jok) { + pdata = (CVBandPrecData)bp_data; + cv_mem = (CVodeMem)pdata->cvode_mem; + if (jok) + { /* If jok = SUNTRUE, use saved copy of J. */ *jcurPtr = SUNFALSE; - retval = SUNMatCopy(pdata->savedJ, pdata->savedP); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBANDPRE", - "cvBandPrecSetup", MSGBP_SUNMAT_FAIL); - return(-1); + retval = SUNMatCopy(pdata->savedJ, pdata->savedP); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL); + return (-1); } - if (retval > 0) { - return(1); - } - - } else { - + if (retval > 0) { return (1); } + } + else + { /* If jok = SUNFALSE, call CVBandPDQJac for new J value. */ *jcurPtr = SUNTRUE; - retval = SUNMatZero(pdata->savedJ); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBANDPRE", - "cvBandPrecSetup", MSGBP_SUNMAT_FAIL); - return(-1); - } - if (retval > 0) { - return(1); - } - - retval = cvBandPrecDQJac(pdata, t, y, fy, - pdata->tmp1, pdata->tmp2); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBANDPRE", - "cvBandPrecSetup", MSGBP_RHSFUNC_FAILED); - return(-1); + retval = SUNMatZero(pdata->savedJ); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL); + return (-1); } - if (retval > 0) { - return(1); + if (retval > 0) { return (1); } + + retval = cvBandPrecDQJac(pdata, t, y, fy, pdata->tmp1, pdata->tmp2); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, + MSGBP_RHSFUNC_FAILED); + return (-1); } + if (retval > 0) { return (1); } retval = SUNMatCopy(pdata->savedJ, pdata->savedP); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBANDPRE", - "cvBandPrecSetup", MSGBP_SUNMAT_FAIL); - return(-1); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL); + return (-1); } - if (retval > 0) { - return(1); - } - + if (retval > 0) { return (1); } } /* Scale and add identity to get savedP = I - gamma*J. */ retval = SUNMatScaleAddI(-gamma, pdata->savedP); - if (retval) { - cvProcessError(cv_mem, -1, "CVBANDPRE", - "cvBandPrecSetup", MSGBP_SUNMAT_FAIL); - return(-1); + if (retval) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL); + return (-1); } /* Do LU factorization of matrix and return error flag */ retval = SUNLinSolSetup_Band(pdata->LS, pdata->savedP); - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvBandPrecSolve ----------------------------------------------------------------- @@ -430,32 +438,34 @@ static int cvBandPrecSetup(realtype t, N_Vector y, N_Vector fy, The value returned by the cvBandPrecSolve function is always 0, indicating success. -----------------------------------------------------------------*/ -static int cvBandPrecSolve(realtype t, N_Vector y, N_Vector fy, - N_Vector r, N_Vector z, realtype gamma, - realtype delta, int lr, void *bp_data) +static int cvBandPrecSolve(SUNDIALS_MAYBE_UNUSED sunrealtype t, + SUNDIALS_MAYBE_UNUSED N_Vector y, + SUNDIALS_MAYBE_UNUSED N_Vector fy, N_Vector r, + N_Vector z, SUNDIALS_MAYBE_UNUSED sunrealtype gamma, + SUNDIALS_MAYBE_UNUSED sunrealtype delta, + SUNDIALS_MAYBE_UNUSED int lr, void* bp_data) { CVBandPrecData pdata; int retval; /* Assume matrix and lpivots have already been allocated. */ - pdata = (CVBandPrecData) bp_data; + pdata = (CVBandPrecData)bp_data; /* Call banded solver object to do the work */ retval = SUNLinSolSolve(pdata->LS, pdata->savedP, z, r, ZERO); - return(retval); + return (retval); } - static int cvBandPrecFree(CVodeMem cv_mem) { CVLsMem cvls_mem; CVBandPrecData pdata; - if (cv_mem->cv_lmem == NULL) return(0); - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + if (cv_mem->cv_lmem == NULL) { return (0); } + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) return(0); - pdata = (CVBandPrecData) cvls_mem->P_data; + if (cvls_mem->P_data == NULL) { return (0); } + pdata = (CVBandPrecData)cvls_mem->P_data; SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); @@ -466,10 +476,9 @@ static int cvBandPrecFree(CVodeMem cv_mem) free(pdata); pdata = NULL; - return(0); + return (0); } - /*----------------------------------------------------------------- cvBandPrecDQJac ----------------------------------------------------------------- @@ -481,20 +490,20 @@ static int cvBandPrecFree(CVodeMem cv_mem) write a simple for loop to set each of the elements of a column in succession. -----------------------------------------------------------------*/ -static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, +static int cvBandPrecDQJac(CVBandPrecData pdata, sunrealtype t, N_Vector y, N_Vector fy, N_Vector ftemp, N_Vector ytemp) { CVodeMem cv_mem; - realtype fnorm, minInc, inc, inc_inv, yj, srur, conj; + sunrealtype fnorm, minInc, inc, inc_inv, yj, srur, conj; sunindextype group, i, j, width, ngroups, i1, i2; - realtype *col_j, *ewt_data, *fy_data, *ftemp_data; - realtype *y_data, *ytemp_data, *cns_data; + sunrealtype *col_j, *ewt_data, *fy_data, *ftemp_data; + sunrealtype *y_data, *ytemp_data, *cns_data; int retval; /* initialize cns_data to avoid compiler warning */ cns_data = NULL; - cv_mem = (CVodeMem) pdata->cvode_mem; + cv_mem = (CVodeMem)pdata->cvode_mem; /* Obtain pointers to the data for ewt, fy, ftemp, y, ytemp. */ ewt_data = N_VGetArrayPointer(cv_mem->cv_ewt); @@ -503,33 +512,44 @@ static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, y_data = N_VGetArrayPointer(y); ytemp_data = N_VGetArrayPointer(ytemp); if (cv_mem->cv_constraintsSet) - cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + { + cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + } /* Load ytemp with y = predicted y vector. */ N_VScale(ONE, y, ytemp); /* Set minimum increment based on uround and norm of f. */ - srur = SUNRsqrt(cv_mem->cv_uround); - fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); - minInc = (fnorm != ZERO) ? - (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * cv_mem->cv_uround * pdata->N * fnorm) : ONE; + srur = SUNRsqrt(cv_mem->cv_uround); + fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); + minInc = (fnorm != ZERO) ? (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * + cv_mem->cv_uround * pdata->N * fnorm) + : ONE; /* Set bandwidth and number of column groups for band differencing. */ - width = pdata->ml + pdata->mu + 1; + width = pdata->ml + pdata->mu + 1; ngroups = SUNMIN(width, pdata->N); - for (group = 1; group <= ngroups; group++) { - + for (group = 1; group <= ngroups; group++) + { /* Increment all y_j in group. */ - for(j = group-1; j < pdata->N; j += width) { - inc = SUNMAX(srur*SUNRabs(y_data[j]), minInc/ewt_data[j]); - yj = y_data[j]; + for (j = group - 1; j < pdata->N; j += width) + { + inc = SUNMAX(srur * SUNRabs(y_data[j]), minInc / ewt_data[j]); + yj = y_data[j]; /* Adjust sign(inc) again if yj has an inequality constraint. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } ytemp_data[j] += inc; @@ -538,34 +558,43 @@ static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, /* Evaluate f with incremented y. */ retval = cv_mem->cv_f(t, ytemp, ftemp, cv_mem->cv_user_data); pdata->nfeBP++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Restore ytemp, then form and load difference quotients. */ - for (j = group-1; j < pdata->N; j += width) { - yj = y_data[j]; + for (j = group - 1; j < pdata->N; j += width) + { + yj = y_data[j]; ytemp_data[j] = y_data[j]; - col_j = SUNBandMatrix_Column(pdata->savedJ,j); - inc = SUNMAX(srur*SUNRabs(y_data[j]), minInc/ewt_data[j]); + col_j = SUNBandMatrix_Column(pdata->savedJ, j); + inc = SUNMAX(srur * SUNRabs(y_data[j]), minInc / ewt_data[j]); /* Adjust sign(inc) as before. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } - inc_inv = ONE/inc; - i1 = SUNMAX(0, j-pdata->mu); - i2 = SUNMIN(j + pdata->ml, pdata->N - 1); - for (i=i1; i <= i2; i++) - SM_COLUMN_ELEMENT_B(col_j,i,j) = inc_inv * (ftemp_data[i] - fy_data[i]); + inc_inv = ONE / inc; + i1 = SUNMAX(0, j - pdata->mu); + i2 = SUNMIN(j + pdata->ml, pdata->N - 1); + for (i = i1; i <= i2; i++) + { + SM_COLUMN_ELEMENT_B(col_j, i, j) = inc_inv * (ftemp_data[i] - fy_data[i]); + } } } - return(0); + return (0); } - /*================================================================ PART II - Backward Problems ================================================================*/ @@ -574,52 +603,56 @@ static int cvBandPrecDQJac(CVBandPrecData pdata, realtype t, N_Vector y, User-Callable initialization function: wrapper for the backward phase around the corresponding CVODES functions ---------------------------------------------------------------*/ -int CVBandPrecInitB(void *cvode_mem, int which, sunindextype nB, +int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB, sunindextype muB, sunindextype mlB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", - "CVBandPrecInitB", MSGBP_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBP_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CVLS_NO_ADJ, "CVSBANDPRE", - "CVBandPrecInitB", MSGBP_NO_ADJ); - return(CVLS_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CVLS_NO_ADJ, __LINE__, __func__, __FILE__, + MSGBP_NO_ADJ); + return (CVLS_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBANDPRE", - "CVBandPrecInitB", MSGBP_BAD_WHICH); - return(CVLS_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBP_BAD_WHICH); + return (CVLS_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } /* advance */ cvB_mem = cvB_mem->cv_next; } /* cv_mem corresponding to 'which' problem. */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Set pfree */ cvB_mem->cv_pfree = NULL; /* Initialize the band preconditioner for this backward problem. */ flag = CVBandPrecInit(cvodeB_mem, nB, muB, mlB); - return(flag); + return (flag); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre_impl.h index c7cd866d3..e35197b27 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bandpre_impl.h @@ -1,10 +1,10 @@ /* - * ----------------------------------------------------------------- + * ----------------------------------------------------------------- * Programmer(s): Daniel R. Reynolds @ SMU * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,10 +21,10 @@ #define _CVSBANDPRE_IMPL_H #include -#include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -32,8 +32,8 @@ extern "C" { Type: CVBandPrecData -----------------------------------------------------------------*/ -typedef struct CVBandPrecDataRec { - +typedef struct CVBandPrecDataRec +{ /* Data set by user in CVBandPrecInit */ sunindextype N; sunindextype ml, mu; @@ -49,26 +49,29 @@ typedef struct CVBandPrecDataRec { long int nfeBP; /* Pointer to cvode_mem */ - void *cvode_mem; + void* cvode_mem; -} *CVBandPrecData; +}* CVBandPrecData; - /*----------------------------------------------------------------- CVBANDPRE error messages -----------------------------------------------------------------*/ -#define MSGBP_MEM_NULL "Integrator memory is NULL." -#define MSGBP_LMEM_NULL "Linear solver memory is NULL. One of the SPILS linear solvers must be attached." -#define MSGBP_MEM_FAIL "A memory request failed." -#define MSGBP_BAD_NVECTOR "A required vector operation is not implemented." -#define MSGBP_SUNMAT_FAIL "An error arose from a SUNBandMatrix routine." -#define MSGBP_SUNLS_FAIL "An error arose from a SUNBandLinearSolver routine." -#define MSGBP_PMEM_NULL "Band preconditioner memory is NULL. CVBandPrecInit must be called." -#define MSGBP_RHSFUNC_FAILED "The right-hand side routine failed in an unrecoverable manner." +#define MSGBP_MEM_NULL "Integrator memory is NULL." +#define MSGBP_LMEM_NULL \ + "Linear solver memory is NULL. One of the SPILS linear solvers must be " \ + "attached." +#define MSGBP_MEM_FAIL "A memory request failed." +#define MSGBP_BAD_NVECTOR "A required vector operation is not implemented." +#define MSGBP_SUNMAT_FAIL "An error arose from a SUNBandMatrix routine." +#define MSGBP_SUNLS_FAIL "An error arose from a SUNBandLinearSolver routine." +#define MSGBP_PMEM_NULL \ + "Band preconditioner memory is NULL. CVBandPrecInit must be called." +#define MSGBP_RHSFUNC_FAILED \ + "The right-hand side routine failed in an unrecoverable manner." -#define MSGBP_NO_ADJ "Illegal attempt to call before calling CVodeAdjInit." -#define MSGBP_BAD_WHICH "Illegal value for parameter which." +#define MSGBP_NO_ADJ "Illegal attempt to call before calling CVodeAdjInit." +#define MSGBP_BAD_WHICH "Illegal value for parameter which." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre.c index 710c5c460..12eb1b788 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre.c @@ -4,7 +4,7 @@ * Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,48 +20,44 @@ * ----------------------------------------------------------------- */ +#include #include #include +#include -#include "cvodes_impl.h" #include "cvodes_bbdpre_impl.h" +#include "cvodes_impl.h" #include "cvodes_ls_impl.h" -#include -#include -#define MIN_INC_MULT RCONST(1000.0) -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#define MIN_INC_MULT SUN_RCONST(1000.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /* Prototypes of functions cvBBDPrecSetup and cvBBDPrecSolve */ -static int cvBBDPrecSetup(realtype t, N_Vector y, N_Vector fy, - booleantype jok, booleantype *jcurPtr, - realtype gamma, void *bbd_data); -static int cvBBDPrecSolve(realtype t, N_Vector y, N_Vector fy, - N_Vector r, N_Vector z, - realtype gamma, realtype delta, - int lr, void *bbd_data); +static int cvBBDPrecSetup(sunrealtype t, N_Vector y, N_Vector fy, + sunbooleantype jok, sunbooleantype* jcurPtr, + sunrealtype gamma, void* bbd_data); +static int cvBBDPrecSolve(sunrealtype t, N_Vector y, N_Vector fy, N_Vector r, + N_Vector z, sunrealtype gamma, sunrealtype delta, + int lr, void* bbd_data); /* Prototype for cvBBDPrecFree */ static int cvBBDPrecFree(CVodeMem cv_mem); /* Wrapper functions for adjoint code */ -static int cvGlocWrapper(sunindextype NlocalB, realtype t, - N_Vector yB, N_Vector gB, - void *cvadj_mem); -static int cvCfnWrapper(sunindextype NlocalB, realtype t, - N_Vector yB, void *cvadj_mem); +static int cvGlocWrapper(sunindextype NlocalB, sunrealtype t, N_Vector yB, + N_Vector gB, void* cvadj_mem); +static int cvCfnWrapper(sunindextype NlocalB, sunrealtype t, N_Vector yB, + void* cvadj_mem); /* Prototype for difference quotient Jacobian calculation routine */ -static int cvBBDDQJac(CVBBDPrecData pdata, realtype t, - N_Vector y, N_Vector gy, - N_Vector ytemp, N_Vector gtemp); +static int cvBBDDQJac(CVBBDPrecData pdata, sunrealtype t, N_Vector y, + N_Vector gy, N_Vector ytemp, N_Vector gtemp); /* Prototype for the backward pfree routine */ static int CVBBDPrecFreeB(CVodeBMem cvB_mem); - /*================================================================ PART I - forward problems ================================================================*/ @@ -69,10 +65,9 @@ static int CVBBDPrecFreeB(CVodeBMem cvB_mem); /*----------------------------------------------------------------- User-Callable Functions: initialization, reinit and free -----------------------------------------------------------------*/ -int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, - sunindextype mudq, sunindextype mldq, - sunindextype mukeep, sunindextype mlkeep, - realtype dqrely, CVLocalFn gloc, CVCommFn cfn) +int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, sunindextype mudq, + sunindextype mldq, sunindextype mukeep, sunindextype mlkeep, + sunrealtype dqrely, CVLocalFn gloc, CVCommFn cfn) { CVodeMem cv_mem; CVLsMem cvls_mem; @@ -81,135 +76,155 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, long int lrw, liw; int flag; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Test if the CVSLS linear solver interface has been created */ - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Test compatibility of NVECTOR package with the BBD preconditioner */ - if(cv_mem->cv_tempv->ops->nvgetarraypointer == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_BAD_NVECTOR); - return(CVLS_ILL_INPUT); + if (cv_mem->cv_tempv->ops->nvgetarraypointer == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBBD_BAD_NVECTOR); + return (CVLS_ILL_INPUT); } /* Allocate data memory */ pdata = NULL; - pdata = (CVBBDPrecData) malloc(sizeof *pdata); - if (pdata == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + pdata = (CVBBDPrecData)malloc(sizeof *pdata); + if (pdata == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Set pointers to gloc and cfn; load half-bandwidths */ pdata->cvode_mem = cvode_mem; - pdata->gloc = gloc; - pdata->cfn = cfn; - pdata->mudq = SUNMIN(Nlocal-1, SUNMAX(0,mudq)); - pdata->mldq = SUNMIN(Nlocal-1, SUNMAX(0,mldq)); - muk = SUNMIN(Nlocal-1, SUNMAX(0,mukeep)); - mlk = SUNMIN(Nlocal-1, SUNMAX(0,mlkeep)); - pdata->mukeep = muk; - pdata->mlkeep = mlk; + pdata->gloc = gloc; + pdata->cfn = cfn; + pdata->mudq = SUNMIN(Nlocal - 1, SUNMAX(0, mudq)); + pdata->mldq = SUNMIN(Nlocal - 1, SUNMAX(0, mldq)); + muk = SUNMIN(Nlocal - 1, SUNMAX(0, mukeep)); + mlk = SUNMIN(Nlocal - 1, SUNMAX(0, mlkeep)); + pdata->mukeep = muk; + pdata->mlkeep = mlk; /* Allocate memory for saved Jacobian */ - pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk); - if (pdata->savedJ == NULL) { - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk, cv_mem->cv_sunctx); + if (pdata->savedJ == NULL) + { + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Allocate memory for preconditioner matrix */ - storage_mu = SUNMIN(Nlocal-1, muk + mlk); + storage_mu = SUNMIN(Nlocal - 1, muk + mlk); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu); - if (pdata->savedP == NULL) { + pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu, + cv_mem->cv_sunctx); + if (pdata->savedP == NULL) + { SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Allocate memory for temporary N_Vectors */ pdata->zlocal = NULL; - pdata->zlocal = N_VNewEmpty_Serial(Nlocal); - if (pdata->zlocal == NULL) { + pdata->zlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); + if (pdata->zlocal == NULL) + { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } pdata->rlocal = NULL; - pdata->rlocal = N_VNewEmpty_Serial(Nlocal); - if (pdata->rlocal == NULL) { + pdata->rlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); + if (pdata->rlocal == NULL) + { N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } pdata->tmp1 = NULL; pdata->tmp1 = N_VClone(cv_mem->cv_tempv); - if (pdata->tmp1 == NULL) { + if (pdata->tmp1 == NULL) + { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } pdata->tmp2 = NULL; pdata->tmp2 = N_VClone(cv_mem->cv_tempv); - if (pdata->tmp2 == NULL) { + if (pdata->tmp2 == NULL) + { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } pdata->tmp3 = NULL; pdata->tmp3 = N_VClone(cv_mem->cv_tempv); - if (pdata->tmp3 == NULL) { + if (pdata->tmp3 == NULL) + { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP); - if (pdata->LS == NULL) { + pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP, cv_mem->cv_sunctx); + if (pdata->LS == NULL) + { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); N_VDestroy(pdata->tmp3); @@ -217,15 +232,17 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, N_VDestroy(pdata->rlocal); SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) { + if (flag != SUN_SUCCESS) + { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); N_VDestroy(pdata->tmp3); @@ -234,15 +251,15 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); SUNLinSolFree(pdata->LS); - free(pdata); pdata = NULL; - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSBBDPRE", - "CVBBDPrecInit", MSGBBD_SUNLS_FAIL); - return(CVLS_SUNLS_FAIL); + free(pdata); + pdata = NULL; + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_SUNLS_FAIL); + return (CVLS_SUNLS_FAIL); } /* Set pdata->dqrely based on input dqrely (0 implies default). */ - pdata->dqrely = (dqrely > ZERO) ? - dqrely : SUNRsqrt(cv_mem->cv_uround); + pdata->dqrely = (dqrely > ZERO) ? dqrely : SUNRsqrt(cv_mem->cv_uround); /* Store Nlocal to be used in CVBBDPrecSetup */ pdata->n_local = Nlocal; @@ -250,27 +267,32 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Set work space sizes and initialize nge */ pdata->rpwsize = 0; pdata->ipwsize = 0; - if (cv_mem->cv_tempv->ops->nvspace) { + if (cv_mem->cv_tempv->ops->nvspace) + { N_VSpace(cv_mem->cv_tempv, &lrw1, &liw1); - pdata->rpwsize += 3*lrw1; - pdata->ipwsize += 3*liw1; + pdata->rpwsize += 3 * lrw1; + pdata->ipwsize += 3 * liw1; } - if (pdata->rlocal->ops->nvspace) { + if (pdata->rlocal->ops->nvspace) + { N_VSpace(pdata->rlocal, &lrw1, &liw1); - pdata->rpwsize += 2*lrw1; - pdata->ipwsize += 2*liw1; + pdata->rpwsize += 2 * lrw1; + pdata->ipwsize += 2 * liw1; } - if (pdata->savedJ->ops->space) { + if (pdata->savedJ->ops->space) + { flag = SUNMatSpace(pdata->savedJ, &lrw, &liw); pdata->rpwsize += lrw; pdata->ipwsize += liw; } - if (pdata->savedP->ops->space) { + if (pdata->savedP->ops->space) + { flag = SUNMatSpace(pdata->savedP, &lrw, &liw); pdata->rpwsize += lrw; pdata->ipwsize += liw; } - if (pdata->LS->ops->space) { + if (pdata->LS->ops->space) + { flag = SUNLinSolSpace(pdata->LS, &lrw, &liw); pdata->rpwsize += lrw; pdata->ipwsize += liw; @@ -278,8 +300,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, pdata->nge = 0; /* make sure s_P_data is free from any previous allocations */ - if (cvls_mem->pfree) - cvls_mem->pfree(cv_mem); + if (cvls_mem->pfree) { cvls_mem->pfree(cv_mem); } /* Point to the new P_data field in the LS memory */ cvls_mem->P_data = pdata; @@ -288,129 +309,130 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, cvls_mem->pfree = cvBBDPrecFree; /* Attach preconditioner solve and setup functions */ - flag = CVodeSetPreconditioner(cvode_mem, cvBBDPrecSetup, - cvBBDPrecSolve); - return(flag); + flag = CVodeSetPreconditioner(cvode_mem, cvBBDPrecSetup, cvBBDPrecSolve); + return (flag); } - -int CVBBDPrecReInit(void *cvode_mem, sunindextype mudq, - sunindextype mldq, realtype dqrely) +int CVBBDPrecReInit(void* cvode_mem, sunindextype mudq, sunindextype mldq, + sunrealtype dqrely) { CVodeMem cv_mem; CVLsMem cvls_mem; CVBBDPrecData pdata; sunindextype Nlocal; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecReInit", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Test if the LS linear solver interface has been created */ - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBBDPRE", - "CVBBDPrecReInit", MSGBBD_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Test if the preconditioner data is non-NULL */ - if (cvls_mem->P_data == NULL) { - cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBBDPRE", - "CVBBDPrecReInit", MSGBBD_PMEM_NULL); - return(CVLS_PMEM_NULL); + if (cvls_mem->P_data == NULL) + { + cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (CVLS_PMEM_NULL); } - pdata = (CVBBDPrecData) cvls_mem->P_data; + pdata = (CVBBDPrecData)cvls_mem->P_data; /* Load half-bandwidths */ - Nlocal = pdata->n_local; - pdata->mudq = SUNMIN(Nlocal-1, SUNMAX(0,mudq)); - pdata->mldq = SUNMIN(Nlocal-1, SUNMAX(0,mldq)); + Nlocal = pdata->n_local; + pdata->mudq = SUNMIN(Nlocal - 1, SUNMAX(0, mudq)); + pdata->mldq = SUNMIN(Nlocal - 1, SUNMAX(0, mldq)); /* Set pdata->dqrely based on input dqrely (0 implies default). */ - pdata->dqrely = (dqrely > ZERO) ? - dqrely : SUNRsqrt(cv_mem->cv_uround); + pdata->dqrely = (dqrely > ZERO) ? dqrely : SUNRsqrt(cv_mem->cv_uround); /* Re-initialize nge */ pdata->nge = 0; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - -int CVBBDPrecGetWorkSpace(void *cvode_mem, - long int *lenrwBBDP, - long int *leniwBBDP) +int CVBBDPrecGetWorkSpace(void* cvode_mem, long int* lenrwBBDP, + long int* leniwBBDP) { CVodeMem cv_mem; CVLsMem cvls_mem; CVBBDPrecData pdata; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetWorkSpace", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetWorkSpace", MSGBBD_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) { - cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetWorkSpace", MSGBBD_PMEM_NULL); - return(CVLS_PMEM_NULL); + if (cvls_mem->P_data == NULL) + { + cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (CVLS_PMEM_NULL); } - pdata = (CVBBDPrecData) cvls_mem->P_data; + pdata = (CVBBDPrecData)cvls_mem->P_data; *lenrwBBDP = pdata->rpwsize; *leniwBBDP = pdata->ipwsize; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - -int CVBBDPrecGetNumGfnEvals(void *cvode_mem, - long int *ngevalsBBDP) +int CVBBDPrecGetNumGfnEvals(void* cvode_mem, long int* ngevalsBBDP) { CVodeMem cv_mem; CVLsMem cvls_mem; CVBBDPrecData pdata; - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetNumGfnEvals", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_lmem == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetNumGfnEvals", MSGBBD_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) { - cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBBDPRE", - "CVBBDPrecGetNumGfnEvals", MSGBBD_PMEM_NULL); - return(CVLS_PMEM_NULL); + if (cvls_mem->P_data == NULL) + { + cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (CVLS_PMEM_NULL); } - pdata = (CVBBDPrecData) cvls_mem->P_data; + pdata = (CVBBDPrecData)cvls_mem->P_data; *ngevalsBBDP = pdata->nge; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*----------------------------------------------------------------- Function : cvBBDPrecSetup ----------------------------------------------------------------- @@ -457,81 +479,77 @@ int CVBBDPrecGetNumGfnEvals(void *cvode_mem, 0 if successful, 1 for a recoverable error (step will be retried). -----------------------------------------------------------------*/ -static int cvBBDPrecSetup(realtype t, N_Vector y, N_Vector fy, - booleantype jok, booleantype *jcurPtr, - realtype gamma, void *bbd_data) +static int cvBBDPrecSetup(sunrealtype t, N_Vector y, + SUNDIALS_MAYBE_UNUSED N_Vector fy, sunbooleantype jok, + sunbooleantype* jcurPtr, sunrealtype gamma, + void* bbd_data) { CVBBDPrecData pdata; CVodeMem cv_mem; int retval; - pdata = (CVBBDPrecData) bbd_data; - cv_mem = (CVodeMem) pdata->cvode_mem; + pdata = (CVBBDPrecData)bbd_data; + cv_mem = (CVodeMem)pdata->cvode_mem; /* If jok = SUNTRUE, use saved copy of J */ - if (jok) { + if (jok) + { *jcurPtr = SUNFALSE; - retval = SUNMatCopy(pdata->savedJ, pdata->savedP); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBBDPRE", - "CVBBDPrecSetup", MSGBBD_SUNMAT_FAIL); - return(-1); + retval = SUNMatCopy(pdata->savedJ, pdata->savedP); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, + MSGBBD_SUNMAT_FAIL); + return (-1); } - if (retval > 0) { - return(1); - } - - /* Otherwise call cvBBDDQJac for new J value */ - } else { + if (retval > 0) { return (1); } + /* Otherwise call cvBBDDQJac for new J value */ + } + else + { *jcurPtr = SUNTRUE; - retval = SUNMatZero(pdata->savedJ); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBBDPRE", - "CVBBDPrecSetup", MSGBBD_SUNMAT_FAIL); - return(-1); - } - if (retval > 0) { - return(1); + retval = SUNMatZero(pdata->savedJ); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, + MSGBBD_SUNMAT_FAIL); + return (-1); } + if (retval > 0) { return (1); } - retval = cvBBDDQJac(pdata, t, y, pdata->tmp1, - pdata->tmp2, pdata->tmp3); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBBDPRE", "CVBBDPrecSetup", + retval = cvBBDDQJac(pdata, t, y, pdata->tmp1, pdata->tmp2, pdata->tmp3); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_FUNC_FAILED); - return(-1); - } - if (retval > 0) { - return(1); + return (-1); } + if (retval > 0) { return (1); } retval = SUNMatCopy(pdata->savedJ, pdata->savedP); - if (retval < 0) { - cvProcessError(cv_mem, -1, "CVBBDPRE", - "CVBBDPrecSetup", MSGBBD_SUNMAT_FAIL); - return(-1); - } - if (retval > 0) { - return(1); + if (retval < 0) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, + MSGBBD_SUNMAT_FAIL); + return (-1); } - + if (retval > 0) { return (1); } } /* Scale and add I to get P = I - gamma*J */ retval = SUNMatScaleAddI(-gamma, pdata->savedP); - if (retval) { - cvProcessError(cv_mem, -1, "CVBBDPRE", - "CVBBDPrecSetup", MSGBBD_SUNMAT_FAIL); - return(-1); + if (retval) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_SUNMAT_FAIL); + return (-1); } /* Do LU factorization of matrix and return error flag */ retval = SUNLinSolSetup_Band(pdata->LS, pdata->savedP); - return(retval); + return (retval); } - /*----------------------------------------------------------------- Function : cvBBDPrecSolve ----------------------------------------------------------------- @@ -551,15 +569,17 @@ static int cvBBDPrecSetup(realtype t, N_Vector y, N_Vector fy, The value returned by the cvBBDPrecSolve function is always 0, indicating success. -----------------------------------------------------------------*/ -static int cvBBDPrecSolve(realtype t, N_Vector y, N_Vector fy, - N_Vector r, N_Vector z, - realtype gamma, realtype delta, - int lr, void *bbd_data) +static int cvBBDPrecSolve(SUNDIALS_MAYBE_UNUSED sunrealtype t, + SUNDIALS_MAYBE_UNUSED N_Vector y, + SUNDIALS_MAYBE_UNUSED N_Vector fy, N_Vector r, + N_Vector z, SUNDIALS_MAYBE_UNUSED sunrealtype gamma, + SUNDIALS_MAYBE_UNUSED sunrealtype delta, + SUNDIALS_MAYBE_UNUSED int lr, void* bbd_data) { int retval; CVBBDPrecData pdata; - pdata = (CVBBDPrecData) bbd_data; + pdata = (CVBBDPrecData)bbd_data; /* Attach local data arrays for r and z to rlocal and zlocal */ N_VSetArrayPointer(N_VGetArrayPointer(r), pdata->rlocal); @@ -573,20 +593,19 @@ static int cvBBDPrecSolve(realtype t, N_Vector y, N_Vector fy, N_VSetArrayPointer(NULL, pdata->rlocal); N_VSetArrayPointer(NULL, pdata->zlocal); - return(retval); + return (retval); } - static int cvBBDPrecFree(CVodeMem cv_mem) { CVLsMem cvls_mem; CVBBDPrecData pdata; - if (cv_mem->cv_lmem == NULL) return(0); - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + if (cv_mem->cv_lmem == NULL) { return (0); } + cvls_mem = (CVLsMem)cv_mem->cv_lmem; - if (cvls_mem->P_data == NULL) return(0); - pdata = (CVBBDPrecData) cvls_mem->P_data; + if (cvls_mem->P_data == NULL) { return (0); } + pdata = (CVBBDPrecData)cvls_mem->P_data; SUNLinSolFree(pdata->LS); N_VDestroy(pdata->tmp1); @@ -600,10 +619,9 @@ static int cvBBDPrecFree(CVodeMem cv_mem) free(pdata); pdata = NULL; - return(0); + return (0); } - /*----------------------------------------------------------------- Function : cvBBDDQJac ----------------------------------------------------------------- @@ -618,104 +636,121 @@ static int cvBBDPrecFree(CVodeMem cv_mem) This routine also assumes that the local elements of a vector are stored contiguously. -----------------------------------------------------------------*/ -static int cvBBDDQJac(CVBBDPrecData pdata, realtype t, N_Vector y, +static int cvBBDDQJac(CVBBDPrecData pdata, sunrealtype t, N_Vector y, N_Vector gy, N_Vector ytemp, N_Vector gtemp) { CVodeMem cv_mem; - realtype gnorm, minInc, inc, inc_inv, yj, conj; + sunrealtype gnorm, minInc, inc, inc_inv, yj, conj; sunindextype group, i, j, width, ngroups, i1, i2; - realtype *y_data, *ewt_data, *gy_data, *gtemp_data; - realtype *ytemp_data, *col_j, *cns_data; + sunrealtype *y_data, *ewt_data, *gy_data, *gtemp_data; + sunrealtype *ytemp_data, *col_j, *cns_data; int retval; /* initialize cns_data to avoid compiler warning */ cns_data = NULL; - cv_mem = (CVodeMem) pdata->cvode_mem; + cv_mem = (CVodeMem)pdata->cvode_mem; /* Load ytemp with y = predicted solution vector */ N_VScale(ONE, y, ytemp); /* Call cfn and gloc to get base value of g(t,y) */ - if (pdata->cfn != NULL) { + if (pdata->cfn != NULL) + { retval = pdata->cfn(pdata->n_local, t, y, cv_mem->cv_user_data); - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } } - retval = pdata->gloc(pdata->n_local, t, ytemp, gy, - cv_mem->cv_user_data); + retval = pdata->gloc(pdata->n_local, t, ytemp, gy, cv_mem->cv_user_data); pdata->nge++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Obtain pointers to the data for various vectors */ - y_data = N_VGetArrayPointer(y); - gy_data = N_VGetArrayPointer(gy); - ewt_data = N_VGetArrayPointer(cv_mem->cv_ewt); - ytemp_data = N_VGetArrayPointer(ytemp); - gtemp_data = N_VGetArrayPointer(gtemp); + y_data = N_VGetArrayPointer(y); + gy_data = N_VGetArrayPointer(gy); + ewt_data = N_VGetArrayPointer(cv_mem->cv_ewt); + ytemp_data = N_VGetArrayPointer(ytemp); + gtemp_data = N_VGetArrayPointer(gtemp); if (cv_mem->cv_constraintsSet) - cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + { + cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + } /* Set minimum increment based on uround and norm of g */ - gnorm = N_VWrmsNorm(gy, cv_mem->cv_ewt); - minInc = (gnorm != ZERO) ? - (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * - cv_mem->cv_uround * pdata->n_local * gnorm) : ONE; + gnorm = N_VWrmsNorm(gy, cv_mem->cv_ewt); + minInc = (gnorm != ZERO) ? (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * + cv_mem->cv_uround * pdata->n_local * gnorm) + : ONE; /* Set bandwidth and number of column groups for band differencing */ - width = pdata->mldq + pdata->mudq + 1; + width = pdata->mldq + pdata->mudq + 1; ngroups = SUNMIN(width, pdata->n_local); /* Loop over groups */ - for (group=1; group <= ngroups; group++) { - + for (group = 1; group <= ngroups; group++) + { /* Increment all y_j in group */ - for(j=group-1; j < pdata->n_local; j+=width) { - inc = SUNMAX(pdata->dqrely * SUNRabs(y_data[j]), minInc/ewt_data[j]); - yj = y_data[j]; + for (j = group - 1; j < pdata->n_local; j += width) + { + inc = SUNMAX(pdata->dqrely * SUNRabs(y_data[j]), minInc / ewt_data[j]); + yj = y_data[j]; /* Adjust sign(inc) again if yj has an inequality constraint. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } ytemp_data[j] += inc; } /* Evaluate g with incremented y */ - retval = pdata->gloc(pdata->n_local, t, ytemp, gtemp, - cv_mem->cv_user_data); + retval = pdata->gloc(pdata->n_local, t, ytemp, gtemp, cv_mem->cv_user_data); pdata->nge++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Restore ytemp, then form and load difference quotients */ - for (j=group-1; j < pdata->n_local; j+=width) { + for (j = group - 1; j < pdata->n_local; j += width) + { yj = ytemp_data[j] = y_data[j]; - col_j = SUNBandMatrix_Column(pdata->savedJ,j); - inc = SUNMAX(pdata->dqrely * SUNRabs(y_data[j]), minInc/ewt_data[j]); + col_j = SUNBandMatrix_Column(pdata->savedJ, j); + inc = SUNMAX(pdata->dqrely * SUNRabs(y_data[j]), minInc / ewt_data[j]); /* Adjust sign(inc) as before. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } - inc_inv = ONE/inc; - i1 = SUNMAX(0, j-pdata->mukeep); - i2 = SUNMIN(j + pdata->mlkeep, pdata->n_local-1); - for (i=i1; i <= i2; i++) - SM_COLUMN_ELEMENT_B(col_j,i,j) = - inc_inv * (gtemp_data[i] - gy_data[i]); + inc_inv = ONE / inc; + i1 = SUNMAX(0, j - pdata->mukeep); + i2 = SUNMIN(j + pdata->mlkeep, pdata->n_local - 1); + for (i = i1; i <= i2; i++) + { + SM_COLUMN_ELEMENT_B(col_j, i, j) = inc_inv * (gtemp_data[i] - gy_data[i]); + } } } - return(0); + return (0); } - /*================================================================ PART II - Backward Problems ================================================================*/ @@ -723,64 +758,69 @@ static int cvBBDDQJac(CVBBDPrecData pdata, realtype t, N_Vector y, /*--------------------------------------------------------------- User-Callable Functions: initialization, reinit and free ---------------------------------------------------------------*/ -int CVBBDPrecInitB(void *cvode_mem, int which, sunindextype NlocalB, - sunindextype mudqB, sunindextype mldqB, - sunindextype mukeepB, sunindextype mlkeepB, - realtype dqrelyB, CVLocalFnB glocB, CVCommFnB cfnB) +int CVBBDPrecInitB(void* cvode_mem, int which, sunindextype NlocalB, + sunindextype mudqB, sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dqrelyB, CVLocalFnB glocB, + CVCommFnB cfnB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; CVBBDPrecDataB cvbbdB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecInitB", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CVLS_NO_ADJ, "CVSBBDPRE", - "CVBBDPrecInitB", MSGBBD_NO_ADJ); - return(CVLS_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CVLS_NO_ADJ, __LINE__, __func__, __FILE__, + MSGBBD_NO_ADJ); + return (CVLS_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBBDPRE", - "CVBBDPrecInitB", MSGBBD_BAD_WHICH); - return(CVLS_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBBD_BAD_WHICH); + return (CVLS_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } /* advance */ cvB_mem = cvB_mem->cv_next; } /* cv_mem corresponding to 'which' problem. */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* Initialize the BBD preconditioner for this backward problem. */ - flag = CVBBDPrecInit(cvodeB_mem, NlocalB, mudqB, mldqB, mukeepB, - mlkeepB, dqrelyB, cvGlocWrapper, cvCfnWrapper); - if (flag != CV_SUCCESS) return(flag); + flag = CVBBDPrecInit(cvodeB_mem, NlocalB, mudqB, mldqB, mukeepB, mlkeepB, + dqrelyB, cvGlocWrapper, cvCfnWrapper); + if (flag != CV_SUCCESS) { return (flag); } /* Allocate memory for CVBBDPrecDataB to store the user-provided functions which will be called from the wrappers */ cvbbdB_mem = NULL; - cvbbdB_mem = (CVBBDPrecDataB) malloc(sizeof(* cvbbdB_mem)); - if (cvbbdB_mem == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", - "CVBBDPrecInitB", MSGBBD_MEM_FAIL); - return(CVLS_MEM_FAIL); + cvbbdB_mem = (CVBBDPrecDataB)malloc(sizeof(*cvbbdB_mem)); + if (cvbbdB_mem == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* set pointers to user-provided functions */ @@ -791,73 +831,74 @@ int CVBBDPrecInitB(void *cvode_mem, int which, sunindextype NlocalB, cvB_mem->cv_pmem = cvbbdB_mem; cvB_mem->cv_pfree = CVBBDPrecFreeB; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - -int CVBBDPrecReInitB(void *cvode_mem, int which, sunindextype mudqB, - sunindextype mldqB, realtype dqrelyB) +int CVBBDPrecReInitB(void* cvode_mem, int which, sunindextype mudqB, + sunindextype mldqB, sunrealtype dqrelyB) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSBBDPRE", - "CVBBDPrecReInitB", MSGBBD_MEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CVLS_NO_ADJ, "CVSBBDPRE", - "CVBBDPrecReInitB", MSGBBD_NO_ADJ); - return(CVLS_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CVLS_NO_ADJ, __LINE__, __func__, __FILE__, + MSGBBD_NO_ADJ); + return (CVLS_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBBDPRE", - "CVBBDPrecReInitB", MSGBBD_BAD_WHICH); - return(CVLS_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBBD_BAD_WHICH); + return (CVLS_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } /* advance */ cvB_mem = cvB_mem->cv_next; } /* cv_mem corresponding to 'which' backward problem. */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); /* ReInitialize the BBD preconditioner for this backward problem. */ flag = CVBBDPrecReInit(cvodeB_mem, mudqB, mldqB, dqrelyB); - return(flag); + return (flag); } - static int CVBBDPrecFreeB(CVodeBMem cvB_mem) { free(cvB_mem->cv_pmem); cvB_mem->cv_pmem = NULL; - return(0); + return (0); } - /*---------------------------------------------------------------- Wrapper functions ----------------------------------------------------------------*/ /* cvGlocWrapper interfaces to the CVLocalFnB routine provided by the user */ -static int cvGlocWrapper(sunindextype NlocalB, realtype t, N_Vector yB, - N_Vector gB, void *cvode_mem) +static int cvGlocWrapper(sunindextype NlocalB, sunrealtype t, N_Vector yB, + N_Vector gB, void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; @@ -865,28 +906,27 @@ static int cvGlocWrapper(sunindextype NlocalB, realtype t, N_Vector yB, CVBBDPrecDataB cvbbdB_mem; int flag; - cv_mem = (CVodeMem) cvode_mem; - ca_mem = cv_mem->cv_adj_mem; - cvB_mem = ca_mem->ca_bckpbCrt; - cvbbdB_mem = (CVBBDPrecDataB) (cvB_mem->cv_pmem); + cv_mem = (CVodeMem)cvode_mem; + ca_mem = cv_mem->cv_adj_mem; + cvB_mem = ca_mem->ca_bckpbCrt; + cvbbdB_mem = (CVBBDPrecDataB)(cvB_mem->cv_pmem); /* Get forward solution from interpolation */ flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (flag != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSBBDPRE", "cvGlocWrapper", - MSGBBD_BAD_TINTERP); - return(-1); + if (flag != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_BAD_TINTERP); + return (-1); } /* Call user's adjoint glocB routine */ - return cvbbdB_mem->glocB(NlocalB, t, ca_mem->ca_ytmp, yB, - gB, cvB_mem->cv_user_data); + return cvbbdB_mem->glocB(NlocalB, t, ca_mem->ca_ytmp, yB, gB, + cvB_mem->cv_user_data); } - /* cvCfnWrapper interfaces to the CVCommFnB routine provided by the user */ -static int cvCfnWrapper(sunindextype NlocalB, realtype t, - N_Vector yB, void *cvode_mem) +static int cvCfnWrapper(sunindextype NlocalB, sunrealtype t, N_Vector yB, + void* cvode_mem) { CVodeMem cv_mem; CVadjMem ca_mem; @@ -894,21 +934,20 @@ static int cvCfnWrapper(sunindextype NlocalB, realtype t, CVBBDPrecDataB cvbbdB_mem; int flag; - cv_mem = (CVodeMem) cvode_mem; - ca_mem = cv_mem->cv_adj_mem; - cvB_mem = ca_mem->ca_bckpbCrt; - cvbbdB_mem = (CVBBDPrecDataB) (cvB_mem->cv_pmem); - if (cvbbdB_mem->cfnB == NULL) return(0); + cv_mem = (CVodeMem)cvode_mem; + ca_mem = cv_mem->cv_adj_mem; + cvB_mem = ca_mem->ca_bckpbCrt; + cvbbdB_mem = (CVBBDPrecDataB)(cvB_mem->cv_pmem); + if (cvbbdB_mem->cfnB == NULL) { return (0); } /* Get forward solution from interpolation */ flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (flag != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSBBDPRE", "cvCfnWrapper", - MSGBBD_BAD_TINTERP); - return(-1); + if (flag != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_BAD_TINTERP); + return (-1); } /* Call user's adjoint cfnB routine */ - return cvbbdB_mem->cfnB(NlocalB, t, ca_mem->ca_ytmp, - yB, cvB_mem->cv_user_data); + return cvbbdB_mem->cfnB(NlocalB, t, ca_mem->ca_ytmp, yB, cvB_mem->cv_user_data); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre_impl.h index 924b17502..270c9d79f 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_bbdpre_impl.h @@ -1,10 +1,10 @@ /* - * ----------------------------------------------------------------- + * ----------------------------------------------------------------- * Programmer(s): Daniel R. Reynolds @ SMU * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,10 +21,10 @@ #define _CVSBBDPRE_IMPL_H #include -#include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -32,11 +32,11 @@ extern "C" { Type: CVBBDPrecData -----------------------------------------------------------------*/ -typedef struct CVBBDPrecDataRec { - +typedef struct CVBBDPrecDataRec +{ /* passed by user to CVBBDPrecInit and used by PrecSetup/PrecSolve */ sunindextype mudq, mldq, mukeep, mlkeep; - realtype dqrely; + sunrealtype dqrely; CVLocalFn gloc; CVCommFn cfn; @@ -59,43 +59,45 @@ typedef struct CVBBDPrecDataRec { long int nge; /* pointer to cvode_mem */ - void *cvode_mem; - -} *CVBBDPrecData; + void* cvode_mem; +}* CVBBDPrecData; /*----------------------------------------------------------------- Type: CVBBDPrecDataB -----------------------------------------------------------------*/ -typedef struct CVBBDPrecDataRecB { - +typedef struct CVBBDPrecDataRecB +{ /* BBD user functions (glocB and cfnB) for backward run */ CVLocalFnB glocB; - CVCommFnB cfnB; - -} *CVBBDPrecDataB; + CVCommFnB cfnB; +}* CVBBDPrecDataB; /*----------------------------------------------------------------- CVBBDPRE error messages -----------------------------------------------------------------*/ -#define MSGBBD_MEM_NULL "Integrator memory is NULL." -#define MSGBBD_LMEM_NULL "Linear solver memory is NULL. One of the SPILS linear solvers must be attached." +#define MSGBBD_MEM_NULL "Integrator memory is NULL." +#define MSGBBD_LMEM_NULL \ + "Linear solver memory is NULL. One of the SPILS linear solvers must be " \ + "attached." #define MSGBBD_MEM_FAIL "A memory request failed." #define MSGBBD_BAD_NVECTOR "A required vector operation is not implemented." #define MSGBBD_SUNMAT_FAIL "An error arose from a SUNBandMatrix routine." #define MSGBBD_SUNLS_FAIL "An error arose from a SUNBandLinearSolver routine." -#define MSGBBD_PMEM_NULL "BBD peconditioner memory is NULL. CVBBDPrecInit must be called." -#define MSGBBD_FUNC_FAILED "The gloc or cfn routine failed in an unrecoverable manner." - -#define MSGBBD_NO_ADJ "Illegal attempt to call before calling CVodeAdjInit." -#define MSGBBD_BAD_WHICH "Illegal value for the which parameter." -#define MSGBBD_PDATAB_NULL "BBD preconditioner memory is NULL for the backward integration." +#define MSGBBD_PMEM_NULL \ + "BBD peconditioner memory is NULL. CVBBDPrecInit must be called." +#define MSGBBD_FUNC_FAILED \ + "The gloc or cfn routine failed in an unrecoverable manner." + +#define MSGBBD_NO_ADJ "Illegal attempt to call before calling CVodeAdjInit." +#define MSGBBD_BAD_WHICH "Illegal value for the which parameter." +#define MSGBBD_PDATAB_NULL \ + "BBD preconditioner memory is NULL for the backward integration." #define MSGBBD_BAD_TINTERP "Bad t for interpolation." - #ifdef __cplusplus } #endif diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag.c index 49ee7e99e..857a81bf7 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag.c @@ -1,9 +1,9 @@ /* - * ----------------------------------------------------------------- + * ----------------------------------------------------------------- * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -23,16 +23,16 @@ #include "cvodes_impl.h" /* Other Constants */ - -#define FRACT RCONST(0.1) -#define ONE RCONST(1.0) + +#define FRACT SUN_RCONST(0.1) +#define ONE SUN_RCONST(1.0) /* CVDIAG linit, lsetup, lsolve, and lfree routines */ static int CVDiagInit(CVodeMem cv_mem); static int CVDiagSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, + N_Vector fpred, sunbooleantype* jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, @@ -40,8 +40,7 @@ static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, static int CVDiagFree(CVodeMem cv_mem); - -/* +/* * ================================================================ * * PART I - forward problems @@ -49,26 +48,25 @@ static int CVDiagFree(CVodeMem cv_mem); * ================================================================ */ - /* Readability Replacements */ -#define lrw1 (cv_mem->cv_lrw1) -#define liw1 (cv_mem->cv_liw1) -#define f (cv_mem->cv_f) -#define uround (cv_mem->cv_uround) -#define tn (cv_mem->cv_tn) -#define h (cv_mem->cv_h) -#define rl1 (cv_mem->cv_rl1) -#define gamma (cv_mem->cv_gamma) -#define ewt (cv_mem->cv_ewt) -#define nfe (cv_mem->cv_nfe) -#define zn (cv_mem->cv_zn) -#define linit (cv_mem->cv_linit) -#define lsetup (cv_mem->cv_lsetup) -#define lsolve (cv_mem->cv_lsolve) -#define lfree (cv_mem->cv_lfree) -#define lmem (cv_mem->cv_lmem) -#define vec_tmpl (cv_mem->cv_tempv) +#define lrw1 (cv_mem->cv_lrw1) +#define liw1 (cv_mem->cv_liw1) +#define f (cv_mem->cv_f) +#define uround (cv_mem->cv_uround) +#define tn (cv_mem->cv_tn) +#define h (cv_mem->cv_h) +#define rl1 (cv_mem->cv_rl1) +#define gamma (cv_mem->cv_gamma) +#define ewt (cv_mem->cv_ewt) +#define nfe (cv_mem->cv_nfe) +#define zn (cv_mem->cv_zn) +#define linit (cv_mem->cv_linit) +#define lsetup (cv_mem->cv_lsetup) +#define lsolve (cv_mem->cv_lsolve) +#define lfree (cv_mem->cv_lfree) +#define lmem (cv_mem->cv_lmem) +#define vec_tmpl (cv_mem->cv_tempv) #define setupNonNull (cv_mem->cv_setupNonNull) #define gammasv (cvdiag_mem->di_gammasv) @@ -78,10 +76,9 @@ static int CVDiagFree(CVodeMem cv_mem); #define nfeDI (cvdiag_mem->di_nfeDI) #define last_flag (cvdiag_mem->di_last_flag) - /* * ----------------------------------------------------------------- - * CVDiag + * CVDiag * ----------------------------------------------------------------- * This routine initializes the memory record and sets various function * fields specific to the diagonal linear solver module. CVDense first @@ -92,32 +89,35 @@ static int CVDiagFree(CVodeMem cv_mem); * CVDiagMemRec and sets the cv_lmem field in (*cvode_mem) to the * address of this structure. It sets setupNonNull in (*cvode_mem) to * SUNTRUE. Finally, it allocates memory for M, bit, and bitcomp. - * The CVDiag return value is SUCCESS = 0, LMEM_FAIL = -1, or + * The CVDiag return value is SUCCESS = 0, LMEM_FAIL = -1, or * LIN_ILL_INPUT=-2. * ----------------------------------------------------------------- */ - -int CVDiag(void *cvode_mem) + +int CVDiag(void* cvode_mem) { CVodeMem cv_mem; CVDiagMem cvdiag_mem; /* Return immediately if cvode_mem is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVDIAG_MEM_NULL, "CVDIAG", "CVDiag", MSGDG_CVMEM_NULL); - return(CVDIAG_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVDIAG_MEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_CVMEM_NULL); + return (CVDIAG_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Check if N_VCompare and N_VInvTest are present */ - if(vec_tmpl->ops->nvcompare == NULL || - vec_tmpl->ops->nvinvtest == NULL) { - cvProcessError(cv_mem, CVDIAG_ILL_INPUT, "CVDIAG", "CVDiag", MSGDG_BAD_NVECTOR); - return(CVDIAG_ILL_INPUT); + if (vec_tmpl->ops->nvcompare == NULL || vec_tmpl->ops->nvinvtest == NULL) + { + cvProcessError(cv_mem, CVDIAG_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGDG_BAD_NVECTOR); + return (CVDIAG_ILL_INPUT); } - if (lfree != NULL) lfree(cv_mem); - + if (lfree != NULL) { lfree(cv_mem); } + /* Set four main function fields in cv_mem */ linit = CVDiagInit; lsetup = CVDiagSetup; @@ -126,42 +126,53 @@ int CVDiag(void *cvode_mem) /* Get memory for CVDiagMemRec */ cvdiag_mem = NULL; - cvdiag_mem = (CVDiagMem) malloc(sizeof(CVDiagMemRec)); - if (cvdiag_mem == NULL) { - cvProcessError(cv_mem, CVDIAG_MEM_FAIL, "CVDIAG", "CVDiag", MSGDG_MEM_FAIL); - return(CVDIAG_MEM_FAIL); + cvdiag_mem = (CVDiagMem)malloc(sizeof(CVDiagMemRec)); + if (cvdiag_mem == NULL) + { + cvProcessError(cv_mem, CVDIAG_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGDG_MEM_FAIL); + return (CVDIAG_MEM_FAIL); } last_flag = CVDIAG_SUCCESS; /* Allocate memory for M, bit, and bitcomp */ - + M = N_VClone(vec_tmpl); - if (M == NULL) { - cvProcessError(cv_mem, CVDIAG_MEM_FAIL, "CVDIAG", "CVDiag", MSGDG_MEM_FAIL); - free(cvdiag_mem); cvdiag_mem = NULL; - return(CVDIAG_MEM_FAIL); + if (M == NULL) + { + cvProcessError(cv_mem, CVDIAG_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGDG_MEM_FAIL); + free(cvdiag_mem); + cvdiag_mem = NULL; + return (CVDIAG_MEM_FAIL); } bit = N_VClone(vec_tmpl); - if (bit == NULL) { - cvProcessError(cv_mem, CVDIAG_MEM_FAIL, "CVDIAG", "CVDiag", MSGDG_MEM_FAIL); + if (bit == NULL) + { + cvProcessError(cv_mem, CVDIAG_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGDG_MEM_FAIL); N_VDestroy(M); - free(cvdiag_mem); cvdiag_mem = NULL; - return(CVDIAG_MEM_FAIL); + free(cvdiag_mem); + cvdiag_mem = NULL; + return (CVDIAG_MEM_FAIL); } bitcomp = N_VClone(vec_tmpl); - if (bitcomp == NULL) { - cvProcessError(cv_mem, CVDIAG_MEM_FAIL, "CVDIAG", "CVDiag", MSGDG_MEM_FAIL); + if (bitcomp == NULL) + { + cvProcessError(cv_mem, CVDIAG_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGDG_MEM_FAIL); N_VDestroy(M); N_VDestroy(bit); - free(cvdiag_mem); cvdiag_mem = NULL; - return(CVDIAG_MEM_FAIL); + free(cvdiag_mem); + cvdiag_mem = NULL; + return (CVDIAG_MEM_FAIL); } /* Attach linear solver memory to integrator memory */ lmem = cvdiag_mem; - return(CVDIAG_SUCCESS); + return (CVDIAG_SUCCESS); } /* @@ -170,21 +181,23 @@ int CVDiag(void *cvode_mem) * ----------------------------------------------------------------- */ -int CVDiagGetWorkSpace(void *cvode_mem, long int *lenrwLS, long int *leniwLS) +int CVDiagGetWorkSpace(void* cvode_mem, long int* lenrwLS, long int* leniwLS) { CVodeMem cv_mem; /* Return immediately if cvode_mem is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVDIAG_MEM_NULL, "CVDIAG", "CVDiagGetWorkSpace", MSGDG_CVMEM_NULL); - return(CVDIAG_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVDIAG_MEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_CVMEM_NULL); + return (CVDIAG_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - *lenrwLS = 3*lrw1; - *leniwLS = 3*liw1; + *lenrwLS = 3 * lrw1; + *leniwLS = 3 * liw1; - return(CVDIAG_SUCCESS); + return (CVDIAG_SUCCESS); } /* @@ -193,27 +206,31 @@ int CVDiagGetWorkSpace(void *cvode_mem, long int *lenrwLS, long int *leniwLS) * ----------------------------------------------------------------- */ -int CVDiagGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) +int CVDiagGetNumRhsEvals(void* cvode_mem, long int* nfevalsLS) { CVodeMem cv_mem; CVDiagMem cvdiag_mem; /* Return immediately if cvode_mem is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVDIAG_MEM_NULL, "CVDIAG", "CVDiagGetNumRhsEvals", MSGDG_CVMEM_NULL); - return(CVDIAG_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVDIAG_MEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_CVMEM_NULL); + return (CVDIAG_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (lmem == NULL) { - cvProcessError(cv_mem, CVDIAG_LMEM_NULL, "CVDIAG", "CVDiagGetNumRhsEvals", MSGDG_LMEM_NULL); - return(CVDIAG_LMEM_NULL); + if (lmem == NULL) + { + cvProcessError(cv_mem, CVDIAG_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_LMEM_NULL); + return (CVDIAG_LMEM_NULL); } - cvdiag_mem = (CVDiagMem) lmem; + cvdiag_mem = (CVDiagMem)lmem; *nfevalsLS = nfeDI; - return(CVDIAG_SUCCESS); + return (CVDIAG_SUCCESS); } /* @@ -222,27 +239,31 @@ int CVDiagGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) * ----------------------------------------------------------------- */ -int CVDiagGetLastFlag(void *cvode_mem, long int *flag) +int CVDiagGetLastFlag(void* cvode_mem, long int* flag) { CVodeMem cv_mem; CVDiagMem cvdiag_mem; /* Return immediately if cvode_mem is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVDIAG_MEM_NULL, "CVDIAG", "CVDiagGetLastFlag", MSGDG_CVMEM_NULL); - return(CVDIAG_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVDIAG_MEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_CVMEM_NULL); + return (CVDIAG_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (lmem == NULL) { - cvProcessError(cv_mem, CVDIAG_LMEM_NULL, "CVDIAG", "CVDiagGetLastFlag", MSGDG_LMEM_NULL); - return(CVDIAG_LMEM_NULL); + if (lmem == NULL) + { + cvProcessError(cv_mem, CVDIAG_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_LMEM_NULL); + return (CVDIAG_LMEM_NULL); } - cvdiag_mem = (CVDiagMem) lmem; + cvdiag_mem = (CVDiagMem)lmem; *flag = last_flag; - return(CVDIAG_SUCCESS); + return (CVDIAG_SUCCESS); } /* @@ -251,45 +272,27 @@ int CVDiagGetLastFlag(void *cvode_mem, long int *flag) * ----------------------------------------------------------------- */ -char *CVDiagGetReturnFlagName(long int flag) +char* CVDiagGetReturnFlagName(long int flag) { - char *name; - - name = (char *)malloc(30*sizeof(char)); - - switch(flag) { - case CVDIAG_SUCCESS: - sprintf(name,"CVDIAG_SUCCESS"); - break; - case CVDIAG_MEM_NULL: - sprintf(name,"CVDIAG_MEM_NULL"); - break; - case CVDIAG_LMEM_NULL: - sprintf(name,"CVDIAG_LMEM_NULL"); - break; - case CVDIAG_ILL_INPUT: - sprintf(name,"CVDIAG_ILL_INPUT"); - break; - case CVDIAG_MEM_FAIL: - sprintf(name,"CVDIAG_MEM_FAIL"); - break; - case CVDIAG_INV_FAIL: - sprintf(name,"CVDIAG_INV_FAIL"); - break; - case CVDIAG_RHSFUNC_UNRECVR: - sprintf(name,"CVDIAG_RHSFUNC_UNRECVR"); - break; - case CVDIAG_RHSFUNC_RECVR: - sprintf(name,"CVDIAG_RHSFUNC_RECVR"); - break; - case CVDIAG_NO_ADJ: - sprintf(name,"CVDIAG_NO_ADJ"); - break; - default: - sprintf(name,"NONE"); + char* name; + + name = (char*)malloc(30 * sizeof(char)); + + switch (flag) + { + case CVDIAG_SUCCESS: sprintf(name, "CVDIAG_SUCCESS"); break; + case CVDIAG_MEM_NULL: sprintf(name, "CVDIAG_MEM_NULL"); break; + case CVDIAG_LMEM_NULL: sprintf(name, "CVDIAG_LMEM_NULL"); break; + case CVDIAG_ILL_INPUT: sprintf(name, "CVDIAG_ILL_INPUT"); break; + case CVDIAG_MEM_FAIL: sprintf(name, "CVDIAG_MEM_FAIL"); break; + case CVDIAG_INV_FAIL: sprintf(name, "CVDIAG_INV_FAIL"); break; + case CVDIAG_RHSFUNC_UNRECVR: sprintf(name, "CVDIAG_RHSFUNC_UNRECVR"); break; + case CVDIAG_RHSFUNC_RECVR: sprintf(name, "CVDIAG_RHSFUNC_RECVR"); break; + case CVDIAG_NO_ADJ: sprintf(name, "CVDIAG_NO_ADJ"); break; + default: sprintf(name, "NONE"); } - return(name); + return (name); } /* @@ -305,35 +308,36 @@ static int CVDiagInit(CVodeMem cv_mem) { CVDiagMem cvdiag_mem; - cvdiag_mem = (CVDiagMem) lmem; + cvdiag_mem = (CVDiagMem)lmem; nfeDI = 0; last_flag = CVDIAG_SUCCESS; - return(0); + return (0); } /* * ----------------------------------------------------------------- * CVDiagSetup * ----------------------------------------------------------------- - * This routine does the setup operations for the diagonal linear - * solver. It constructs a diagonal approximation to the Newton matrix + * This routine does the setup operations for the diagonal linear + * solver. It constructs a diagonal approximation to the Newton matrix * M = I - gamma*J, updates counters, and inverts M. * ----------------------------------------------------------------- */ -static int CVDiagSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3) +static int CVDiagSetup(CVodeMem cv_mem, SUNDIALS_MAYBE_UNUSED int convfail, + N_Vector ypred, N_Vector fpred, sunbooleantype* jcurPtr, + N_Vector vtemp1, N_Vector vtemp2, + SUNDIALS_MAYBE_UNUSED N_Vector vtemp3) { - realtype r; + sunrealtype r; N_Vector ftemp, y; - booleantype invOK; + sunbooleantype invOK; CVDiagMem cvdiag_mem; int retval; - cvdiag_mem = (CVDiagMem) lmem; + cvdiag_mem = (CVDiagMem)lmem; /* Rename work vectors for use as temporary values of y and f */ ftemp = vtemp1; @@ -347,14 +351,17 @@ static int CVDiagSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, /* Evaluate f at perturbed y */ retval = f(tn, y, M, cv_mem->cv_user_data); nfeDI++; - if (retval < 0) { - cvProcessError(cv_mem, CVDIAG_RHSFUNC_UNRECVR, "CVDIAG", "CVDiagSetup", MSGDG_RHSFUNC_FAILED); + if (retval < 0) + { + cvProcessError(cv_mem, CVDIAG_RHSFUNC_UNRECVR, __LINE__, __func__, __FILE__, + MSGDG_RHSFUNC_FAILED); last_flag = CVDIAG_RHSFUNC_UNRECVR; - return(-1); + return (-1); } - if (retval > 0) { + if (retval > 0) + { last_flag = CVDIAG_RHSFUNC_RECVR; - return(1); + return (1); } /* Construct M = I - gamma*J with J = diag(deltaf_i/deltay_i) */ @@ -372,16 +379,17 @@ static int CVDiagSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, /* Invert M with test for zero components */ invOK = N_VInvTest(M, M); - if (!invOK) { + if (!invOK) + { last_flag = CVDIAG_INV_FAIL; - return(1); + return (1); } /* Set jcur = SUNTRUE, save gamma in gammasv, and return */ - *jcurPtr = SUNTRUE; - gammasv = gamma; + *jcurPtr = SUNTRUE; + gammasv = gamma; last_flag = CVDIAG_SUCCESS; - return(0); + return (0); } /* @@ -393,25 +401,29 @@ static int CVDiagSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, * ----------------------------------------------------------------- */ -static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, - N_Vector ycur, N_Vector fcur) +static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, + SUNDIALS_MAYBE_UNUSED N_Vector weight, + SUNDIALS_MAYBE_UNUSED N_Vector ycur, + SUNDIALS_MAYBE_UNUSED N_Vector fcur) { - booleantype invOK; - realtype r; + sunbooleantype invOK; + sunrealtype r; CVDiagMem cvdiag_mem; - cvdiag_mem = (CVDiagMem) lmem; - + cvdiag_mem = (CVDiagMem)lmem; + /* If gamma has changed, update factor in M, and save gamma value */ - if (gammasv != gamma) { + if (gammasv != gamma) + { r = gamma / gammasv; N_VInv(M, M); N_VAddConst(M, -ONE, M); N_VScale(r, M, M); N_VAddConst(M, ONE, M); invOK = N_VInvTest(M, M); - if (!invOK) { + if (!invOK) + { last_flag = CVDIAG_INV_FAIL; return (1); } @@ -422,7 +434,7 @@ static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_VProd(b, M, b); last_flag = CVDIAG_SUCCESS; - return(0); + return (0); } /* @@ -436,20 +448,19 @@ static int CVDiagSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, static int CVDiagFree(CVodeMem cv_mem) { CVDiagMem cvdiag_mem; - - cvdiag_mem = (CVDiagMem) lmem; + + cvdiag_mem = (CVDiagMem)lmem; N_VDestroy(M); N_VDestroy(bit); N_VDestroy(bitcomp); free(cvdiag_mem); cv_mem->cv_lmem = NULL; - - return(0); -} + return (0); +} -/* +/* * ================================================================ * * PART II - backward problems @@ -457,53 +468,58 @@ static int CVDiagFree(CVodeMem cv_mem) * ================================================================ */ - /* * CVDiagB * - * Wrappers for the backward phase around the corresponding + * Wrappers for the backward phase around the corresponding * CVODES functions */ -int CVDiagB(void *cvode_mem, int which) +int CVDiagB(void* cvode_mem, int which) { CVodeMem cv_mem; CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; + void* cvodeB_mem; int flag; - /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVDIAG_MEM_NULL, "CVSDIAG", "CVDiagB", MSGDG_CVMEM_NULL); - return(CVDIAG_MEM_NULL); + /* Check if cvode_mem exists */ + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVDIAG_MEM_NULL, __LINE__, __func__, __FILE__, + MSGDG_CVMEM_NULL); + return (CVDIAG_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CVDIAG_NO_ADJ, "CVSDIAG", "CVDiagB", MSGDG_NO_ADJ); - return(CVDIAG_NO_ADJ); - } + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CVDIAG_NO_ADJ, __LINE__, __func__, __FILE__, + MSGDG_NO_ADJ); + return (CVDIAG_NO_ADJ); + } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CVDIAG_ILL_INPUT, "CVSDIAG", "CVDiagB", MSGDG_BAD_WHICH); - return(CVDIAG_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CVDIAG_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGDG_BAD_WHICH); + return (CVDIAG_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } - cvodeB_mem = (void *) (cvB_mem->cv_mem); - + cvodeB_mem = (void*)(cvB_mem->cv_mem); + flag = CVDiag(cvodeB_mem); - return(flag); + return (flag); } - diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag_impl.h index beb90d4ee..f8d9ed39b 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_diag_impl.h @@ -1,9 +1,9 @@ /* - * ----------------------------------------------------------------- + * ----------------------------------------------------------------- * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,7 +21,7 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -34,17 +34,17 @@ extern "C" { * ----------------------------------------------------------------- */ -typedef struct { - - realtype di_gammasv; /* gammasv = gamma at the last call to setup or solve */ +typedef struct +{ + sunrealtype di_gammasv; /* gammasv = gamma at the last call to setup or solve */ - N_Vector di_M; /* M = (I - gamma J)^{-1} , gamma = h / l1 */ + N_Vector di_M; /* M = (I - gamma J)^{-1} , gamma = h / l1 */ - N_Vector di_bit; /* temporary storage vector */ + N_Vector di_bit; /* temporary storage vector */ N_Vector di_bitcomp; /* temporary storage vector */ - long int di_nfeDI; /* no. of calls to f due to difference + long int di_nfeDI; /* no. of calls to f due to difference quotient diagonal Jacobian approximation */ long int di_last_flag; /* last error return flag */ @@ -53,13 +53,14 @@ typedef struct { /* Error Messages */ -#define MSGDG_CVMEM_NULL "Integrator memory is NULL." -#define MSGDG_MEM_FAIL "A memory request failed." +#define MSGDG_CVMEM_NULL "Integrator memory is NULL." +#define MSGDG_MEM_FAIL "A memory request failed." #define MSGDG_BAD_NVECTOR "A required vector operation is not implemented." -#define MSGDG_LMEM_NULL "CVDIAG memory is NULL." -#define MSGDG_RHSFUNC_FAILED "The right-hand side routine failed in an unrecoverable manner." +#define MSGDG_LMEM_NULL "CVDIAG memory is NULL." +#define MSGDG_RHSFUNC_FAILED \ + "The right-hand side routine failed in an unrecoverable manner." -#define MSGDG_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." +#define MSGDG_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." #define MSGDG_BAD_WHICH "Illegal value for which." #ifdef __cplusplus diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_direct.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_direct.c deleted file mode 100644 index bc18925e6..000000000 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_direct.c +++ /dev/null @@ -1,65 +0,0 @@ -/* ----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated direct linear solver interface in - * CVODES; these routines now just wrap the updated CVODE generic - * linear solver interface in cvodes_ls.h. - * -----------------------------------------------------------------*/ - -#include -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/*================================================================= - Exported Functions (wrappers for equivalent routines in cvodes_ls.h) - =================================================================*/ - -int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, - SUNMatrix A) -{ return(CVodeSetLinearSolver(cvode_mem, LS, A)); } - -int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac) -{ return(CVodeSetJacFn(cvode_mem, jac)); } - -int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS) -{ return(CVodeGetLinWorkSpace(cvode_mem, lenrwLS, leniwLS)); } - -int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals) -{ return(CVodeGetNumJacEvals(cvode_mem, njevals)); } - -int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) -{ return(CVodeGetNumLinRhsEvals(cvode_mem, nfevalsLS)); } - -int CVDlsGetLastFlag(void *cvode_mem, long int *flag) -{ return(CVodeGetLastLinFlag(cvode_mem, flag)); } - -char *CVDlsGetReturnFlagName(long int flag) -{ return(CVodeGetLinReturnFlagName(flag)); } - -int CVDlsSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS, SUNMatrix A) -{ return(CVodeSetLinearSolverB(cvode_mem, which, LS, A)); } - -int CVDlsSetJacFnB(void *cvode_mem, int which, CVDlsJacFnB jacB) -{ return(CVodeSetJacFnB(cvode_mem, which, jacB)); } - -int CVDlsSetJacFnBS(void *cvode_mem, int which, CVDlsJacFnBS jacBS) -{ return(CVodeSetJacFnBS(cvode_mem, which, jacBS)); } - -#ifdef __cplusplus -} -#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_impl.h index aa24dd674..c22d16635 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_impl.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,12 +19,33 @@ #include -#include "cvodes/cvodes.h" +#include +#include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#include "cvodes_proj_impl.h" +#include "sundials_logger_impl.h" +#include "sundials_macros.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif +#if defined(SUNDIALS_EXTENDED_PRECISION) +#define RSYM ".32Lg" +#define RSYMW "19.32Lg" +#else +#define RSYM ".16g" +#define RSYMW "23.16g" +#endif + +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define CV_PROFILER cv_mem->cv_sunctx->profiler +#define CV_LOGGER cv_mem->cv_sunctx->logger + /* * ================================================================= * I N T E R N A L C O N S T A N T S @@ -33,24 +54,144 @@ extern "C" { /* Basic constants */ -#define ADAMS_Q_MAX 12 /* max value of q for lmm == ADAMS */ -#define BDF_Q_MAX 5 /* max value of q for lmm == BDF */ -#define Q_MAX ADAMS_Q_MAX /* max value of q for either lmm */ -#define L_MAX (Q_MAX+1) /* max value of L for either lmm */ -#define NUM_TESTS 5 /* number of error test quantities */ +#define ADAMS_Q_MAX 12 /* max value of q for lmm == ADAMS */ +#define BDF_Q_MAX 5 /* max value of q for lmm == BDF */ +#define Q_MAX ADAMS_Q_MAX /* max value of q for either lmm */ +#define L_MAX (Q_MAX + 1) /* max value of L for either lmm */ +#define NUM_TESTS 5 /* number of error test quantities */ + +#define HMIN_DEFAULT SUN_RCONST(0.0) /* hmin default value */ +#define HMAX_INV_DEFAULT SUN_RCONST(0.0) /* hmax_inv default value */ +#define MXHNIL_DEFAULT 10 /* mxhnil default value */ +#define MXSTEP_DEFAULT 500 /* mxstep default value */ + +#define MSBP_DEFAULT 20 /* max steps between lsetup calls */ +#define DGMAX_LSETUP_DEFAULT \ + SUN_RCONST(0.3) /* gamma threshold to call lsetup */ + +/* Step size change constants + * -------------------------- + * ETA_MIN_FX_DEFAULT if eta_min_fx < eta < eta_max_fx reject a change in step size or order + * ETA_MAX_FX_DEFAULT + * ETA_MAX_FS_DEFAULT -+ + * ETA_MAX_ES_DEFAULT | + * ETA_MAX_GS_DEFAULT | + * ETA_MIN_DEFAULT |-> bounds for eta (step size change) + * ETA_MAX_EF_DEFAULT | + * ETA_MIN_EF_DEFAULT | + * ETA_CF_DEFAULT -+ + * SMALL_NST_DEFAULT nst <= SMALL_NST => use eta_max_es + * SMALL_NEF_DEFAULT if small_nef <= nef <= MXNEF1, then eta = SUNMIN(eta, eta_max_ef) + * ONEPSM (1+epsilon) used in testing if the step size is below its bound + */ + +#define ETA_MIN_FX_DEFAULT SUN_RCONST(0.0) +#define ETA_MAX_FX_DEFAULT SUN_RCONST(1.5) +#define ETA_MAX_FS_DEFAULT SUN_RCONST(10000.0) +#define ETA_MAX_ES_DEFAULT SUN_RCONST(10.0) +#define ETA_MAX_GS_DEFAULT SUN_RCONST(10.0) +#define ETA_MIN_DEFAULT SUN_RCONST(0.1) +#define ETA_MAX_EF_DEFAULT SUN_RCONST(0.2) +#define ETA_MIN_EF_DEFAULT SUN_RCONST(0.1) +#define ETA_CF_DEFAULT SUN_RCONST(0.25) +#define SMALL_NST_DEFAULT 10 +#define SMALL_NEF_DEFAULT 2 +#define ONEPSM SUN_RCONST(1.000001) + +/* Step size controller constants + * ------------------------------ + * ADDON safety factor in computing eta + * BIAS1 -+ + * BIAS2 |-> bias factors in eta selection + * BIAS3 -+ + */ + +#define ADDON SUN_RCONST(0.000001) +#define BIAS1 SUN_RCONST(6.0) +#define BIAS2 SUN_RCONST(6.0) +#define BIAS3 SUN_RCONST(10.0) + +/* Order selection constants + * ------------------------- + * LONG_WAIT number of steps to wait before considering an order change when + * q==1 and MXNEF1 error test failures have occurred + */ -#define HMIN_DEFAULT RCONST(0.0) /* hmin default value */ -#define HMAX_INV_DEFAULT RCONST(0.0) /* hmax_inv default value */ -#define MXHNIL_DEFAULT 10 /* mxhnil default value */ -#define MXSTEP_DEFAULT 500 /* mxstep default value */ +#define LONG_WAIT 10 + +/* Failure limits + * -------------- + * MXNCF max no. of convergence failures during one step try + * MXNEF max no. of error test failures during one step try + * MXNEF1 max no. of error test failures before forcing a reduction of order + */ + +#define MXNCF 10 +#define MXNEF 7 +#define MXNEF1 3 + +/* Control constants for lower-level functions used by cvStep + * ---------------------------------------------------------- + * + * cvHin return values: + * CV_SUCCESS, + * CV_RHSFUNC_FAIL, CV_RPTD_RHSFUNC_ERR, + * CV_QRHSFUNC_FAIL, CV_RPTD_QRHSFUNC_ERR, + * CV_SRHSFUNC_FAIL, CV_RPTD_SRHSFUNC_ERR, + * CV_TOO_CLOSE + * + * cvStep control constants: + * DO_ERROR_TEST + * PREDICT_AGAIN + * + * cvStep return values: + * CV_SUCCESS, + * CV_CONV_FAILURE, CV_ERR_FAILURE, + * CV_LSETUP_FAIL, CV_LSOLVE_FAIL, + * CV_RTFUNC_FAIL, + * CV_RHSFUNC_FAIL, CV_QRHSFUNC_FAIL, CV_SRHSFUNC_FAIL, CV_QSRHSFUNC_FAIL, + * CV_FIRST_RHSFUNC_ERR, CV_FIRST_QRHSFUNC_ERR, CV_FIRST_SRHSFUNC_ERR, CV_FIRST_QSRHSFUNC_ERR, + * CV_UNREC_RHSFUNC_ERR, CV_UNREC_QRHSFUNC_ERR, CV_UNREC_SRHSFUNC_ERR, CV_UNREC_QSRHSFUNC_ERR, + * CV_REPTD_RHSFUNC_ERR, CV_REPTD_QRHSFUNC_ERR, CV_REPTD_SRHSFUNC_ERR, CV_REPTD_QSRHSFUNC_ERR, + * + * cvNls input nflag values: + * FIRST_CALL + * PREV_CONV_FAIL + * PREV_PROJ_FAIL + * PREV_ERR_FAIL + * + * cvNls return values: + * CV_SUCCESS, + * CV_LSETUP_FAIL, CV_LSOLVE_FAIL, + * CV_RHSFUNC_FAIL, CV_SRHSFUNC_FAIL, + * SUN_NLS_CONV_RECVR, + * RHSFUNC_RECVR, SRHSFUNC_RECVR + * + * cvNewtonIteration return values: + * CV_SUCCESS, + * CV_LSOLVE_FAIL, CV_RHSFUNC_FAIL + * RHSFUNC_RECVR, + * TRY_AGAIN + * + */ -#define MSBP 20 /* max no. of steps between lsetup calls */ +#define DO_ERROR_TEST +2 +#define PREDICT_AGAIN +3 -/* Return values for lower level routines used by CVode and functions - provided to the nonlinear solver */ +#define TRY_AGAIN +5 +#define FIRST_CALL +6 +#define PREV_CONV_FAIL +7 +#define PREV_PROJ_FAIL +8 +#define PREV_ERR_FAIL +9 -#define RHSFUNC_RECVR +9 -#define SRHSFUNC_RECVR +12 +#define RHSFUNC_RECVR +10 +#define CONSTR_RECVR +11 +#define CONSTRFUNC_RECVR +12 +#define PROJFUNC_RECVR +13 + +#define QRHSFUNC_RECVR +14 +#define SRHSFUNC_RECVR +15 +#define QSRHSFUNC_RECVR +16 /* nonlinear solver constants NLS_MAXCOR maximum no. of corrector iterations for the nonlinear solver @@ -59,8 +200,8 @@ extern "C" { RDIV declare divergence if ratio del/delp > RDIV */ #define NLS_MAXCOR 3 -#define CRDOWN RCONST(0.3) -#define RDIV RCONST(2.0) +#define CRDOWN SUN_RCONST(0.3) +#define RDIV SUN_RCONST(2.0) /* * ================================================================= @@ -68,10 +209,10 @@ extern "C" { * ================================================================= */ -typedef struct CVadjMemRec *CVadjMem; -typedef struct CkpntMemRec *CkpntMem; -typedef struct DtpntMemRec *DtpntMem; -typedef struct CVodeBMemRec *CVodeBMem; +typedef struct CVadjMemRec* CVadjMem; +typedef struct CVckpntMemRec* CVckpntMem; +typedef struct CVdtpntMemRec* CVdtpntMem; +typedef struct CVodeBMemRec* CVodeBMem; /* * ================================================================= @@ -79,7 +220,6 @@ typedef struct CVodeBMemRec *CVodeBMem; * ================================================================= */ - /* * ----------------------------------------------------------------- * Types: struct CVodeMemRec, CVodeMem @@ -89,99 +229,101 @@ typedef struct CVodeBMemRec *CVodeBMem; * ----------------------------------------------------------------- */ -typedef struct CVodeMemRec { +typedef struct CVodeMemRec +{ + SUNContext cv_sunctx; - realtype cv_uround; /* machine unit roundoff */ + sunrealtype cv_uround; /* machine unit roundoff */ /*-------------------------- Problem Specification Data --------------------------*/ - CVRhsFn cv_f; /* y' = f(t,y(t)) */ - void *cv_user_data; /* user pointer passed to f */ - int cv_lmm; /* lmm = CV_ADAMS or CV_BDF */ - int cv_itol; /* itol = CV_SS, CV_SV, CV_WF, CV_NN */ + CVRhsFn cv_f; /* y' = f(t,y(t)) */ + void* cv_user_data; /* user pointer passed to f */ + int cv_lmm; /* lmm = CV_ADAMS or CV_BDF */ + int cv_itol; /* itol = CV_SS, CV_SV, CV_WF, CV_NN */ - realtype cv_reltol; /* relative tolerance */ - realtype cv_Sabstol; /* scalar absolute tolerance */ - N_Vector cv_Vabstol; /* vector absolute tolerance */ - booleantype cv_atolmin0; /* flag indicating that min(abstol) = 0 */ - booleantype cv_user_efun; /* SUNTRUE if user sets efun */ - CVEwtFn cv_efun; /* function to set ewt */ - void *cv_e_data; /* user pointer passed to efun */ + sunrealtype cv_reltol; /* relative tolerance */ + sunrealtype cv_Sabstol; /* scalar absolute tolerance */ + N_Vector cv_Vabstol; /* vector absolute tolerance */ + sunbooleantype cv_atolmin0; /* flag indicating that min(abstol) = 0 */ + sunbooleantype cv_user_efun; /* SUNTRUE if user sets efun */ + CVEwtFn cv_efun; /* function to set ewt */ + void* cv_e_data; /* user pointer passed to efun */ - booleantype cv_constraintsSet; /* constraints vector present: + sunbooleantype cv_constraintsSet; /* constraints vector present: do constraints calc */ /*----------------------- Quadrature Related Data -----------------------*/ - booleantype cv_quadr; /* SUNTRUE if integrating quadratures */ + sunbooleantype cv_quadr; /* SUNTRUE if integrating quadratures */ - CVQuadRhsFn cv_fQ; /* q' = fQ(t, y(t)) */ + CVQuadRhsFn cv_fQ; /* q' = fQ(t, y(t)) */ - booleantype cv_errconQ; /* SUNTRUE if quadrs. are included in error test */ + sunbooleantype cv_errconQ; /* SUNTRUE if quadrs. are included in error test */ - int cv_itolQ; /* itolQ = CV_SS or CV_SV */ - realtype cv_reltolQ; /* relative tolerance for quadratures */ - realtype cv_SabstolQ; /* scalar absolute tolerance for quadratures */ - N_Vector cv_VabstolQ; /* vector absolute tolerance for quadratures */ - booleantype cv_atolQmin0; /* flag indicating that min(abstolQ) = 0 */ + int cv_itolQ; /* itolQ = CV_SS or CV_SV */ + sunrealtype cv_reltolQ; /* relative tolerance for quadratures */ + sunrealtype cv_SabstolQ; /* scalar absolute tolerance for quadratures */ + N_Vector cv_VabstolQ; /* vector absolute tolerance for quadratures */ + sunbooleantype cv_atolQmin0; /* flag indicating that min(abstolQ) = 0 */ /*------------------------ Sensitivity Related Data ------------------------*/ - booleantype cv_sensi; /* SUNTRUE if computing sensitivities */ + sunbooleantype cv_sensi; /* SUNTRUE if computing sensitivities */ - int cv_Ns; /* Number of sensitivities */ + int cv_Ns; /* Number of sensitivities */ - int cv_ism; /* ism = SIMULTANEOUS or STAGGERED */ + int cv_ism; /* ism = SIMULTANEOUS or STAGGERED */ - CVSensRhsFn cv_fS; /* fS = (df/dy)*yS + (df/dp) */ - CVSensRhs1Fn cv_fS1; /* fS1 = (df/dy)*yS_i + (df/dp) */ - void *cv_fS_data; /* data pointer passed to fS */ - booleantype cv_fSDQ; /* SUNTRUE if using internal DQ functions */ - int cv_ifS; /* ifS = ALLSENS or ONESENS */ + CVSensRhsFn cv_fS; /* fS = (df/dy)*yS + (df/dp) */ + CVSensRhs1Fn cv_fS1; /* fS1 = (df/dy)*yS_i + (df/dp) */ + void* cv_fS_data; /* data pointer passed to fS */ + sunbooleantype cv_fSDQ; /* SUNTRUE if using internal DQ functions */ + int cv_ifS; /* ifS = ALLSENS or ONESENS */ - realtype *cv_p; /* parameters in f(t,y,p) */ - realtype *cv_pbar; /* scale factors for parameters */ - int *cv_plist; /* list of sensitivities */ - int cv_DQtype; /* central/forward finite differences */ - realtype cv_DQrhomax; /* cut-off value for separate/simultaneous FD */ + sunrealtype* cv_p; /* parameters in f(t,y,p) */ + sunrealtype* cv_pbar; /* scale factors for parameters */ + int* cv_plist; /* list of sensitivities */ + int cv_DQtype; /* central/forward finite differences */ + sunrealtype cv_DQrhomax; /* cut-off value for separate/simultaneous FD */ - booleantype cv_errconS; /* SUNTRUE if yS are considered in err. control */ + sunbooleantype cv_errconS; /* SUNTRUE if yS are considered in err. control */ int cv_itolS; - realtype cv_reltolS; /* relative tolerance for sensitivities */ - realtype *cv_SabstolS; /* scalar absolute tolerances for sensi. */ - N_Vector *cv_VabstolS; /* vector absolute tolerances for sensi. */ - booleantype *cv_atolSmin0; /* flags indicating that min(abstolS[i]) = 0 */ + sunrealtype cv_reltolS; /* relative tolerance for sensitivities */ + sunrealtype* cv_SabstolS; /* scalar absolute tolerances for sensi. */ + N_Vector* cv_VabstolS; /* vector absolute tolerances for sensi. */ + sunbooleantype* cv_atolSmin0; /* flags indicating that min(abstolS[i]) = 0 */ /*----------------------------------- Quadrature Sensitivity Related Data -----------------------------------*/ - booleantype cv_quadr_sensi; /* SUNTRUE if computing sensitivties of quadrs. */ + sunbooleantype cv_quadr_sensi; /* SUNTRUE if computing sensitivties of quadrs. */ - CVQuadSensRhsFn cv_fQS; /* fQS = (dfQ/dy)*yS + (dfQ/dp) */ - void *cv_fQS_data; /* data pointer passed to fQS */ - booleantype cv_fQSDQ; /* SUNTRUE if using internal DQ functions */ + CVQuadSensRhsFn cv_fQS; /* fQS = (dfQ/dy)*yS + (dfQ/dp) */ + void* cv_fQS_data; /* data pointer passed to fQS */ + sunbooleantype cv_fQSDQ; /* SUNTRUE if using internal DQ functions */ - booleantype cv_errconQS; /* SUNTRUE if yQS are considered in err. con. */ + sunbooleantype cv_errconQS; /* SUNTRUE if yQS are considered in err. con. */ int cv_itolQS; - realtype cv_reltolQS; /* relative tolerance for yQS */ - realtype *cv_SabstolQS; /* scalar absolute tolerances for yQS */ - N_Vector *cv_VabstolQS; /* vector absolute tolerances for yQS */ - booleantype *cv_atolQSmin0; /* flags indicating that min(abstolQS[i]) = 0 */ + sunrealtype cv_reltolQS; /* relative tolerance for yQS */ + sunrealtype* cv_SabstolQS; /* scalar absolute tolerances for yQS */ + N_Vector* cv_VabstolQS; /* vector absolute tolerances for yQS */ + sunbooleantype* cv_atolQSmin0; /* flags indicating that min(abstolQS[i]) = 0 */ /*----------------------- Nordsieck History Array -----------------------*/ - N_Vector cv_zn[L_MAX]; /* Nordsieck array, of size N x (q+1). + N_Vector cv_zn[L_MAX]; /* Nordsieck array, of size N x (q+1). zn[j] is a vector of length N (j=0,...,q) zn[j] = [1/factorial(j)] * h^j * (jth derivative of the interpolating polynomial) */ @@ -190,18 +332,18 @@ typedef struct CVodeMemRec { Vectors of length N -------------------*/ - N_Vector cv_ewt; /* error weight vector */ - N_Vector cv_y; /* y is used as temporary storage by the solver + N_Vector cv_ewt; /* error weight vector */ + N_Vector cv_y; /* y is used as temporary storage by the solver The memory is provided by the user to CVode where the vector is named yout. */ - N_Vector cv_acor; /* In the context of the solution of the nonlinear + N_Vector cv_acor; /* In the context of the solution of the nonlinear equation, acor = y_n(m) - y_n(0). On return, this vector is scaled to give the estimated local error */ - N_Vector cv_tempv; /* temporary storage vector */ - N_Vector cv_ftemp; /* temporary storage vector */ - N_Vector cv_vtemp1; /* temporary storage vector */ - N_Vector cv_vtemp2; /* temporary storage vector */ - N_Vector cv_vtemp3; /* temporary storage vector */ + N_Vector cv_tempv; /* temporary storage vector */ + N_Vector cv_ftemp; /* temporary storage vector */ + N_Vector cv_vtemp1; /* temporary storage vector */ + N_Vector cv_vtemp2; /* temporary storage vector */ + N_Vector cv_vtemp3; /* temporary storage vector */ N_Vector cv_constraints; /* vector of inequality constraint options */ @@ -209,176 +351,193 @@ typedef struct CVodeMemRec { Quadrature Related Vectors --------------------------*/ - N_Vector cv_znQ[L_MAX]; /* Nordsieck arrays for quadratures */ - N_Vector cv_ewtQ; /* error weight vector for quadratures */ - N_Vector cv_yQ; /* Unlike y, yQ is not allocated by the user */ - N_Vector cv_acorQ; /* acorQ = yQ_n(m) - yQ_n(0) */ - N_Vector cv_tempvQ; /* temporary storage vector (~ tempv) */ + N_Vector cv_znQ[L_MAX]; /* Nordsieck arrays for quadratures */ + N_Vector cv_ewtQ; /* error weight vector for quadratures */ + N_Vector cv_yQ; /* Unlike y, yQ is not allocated by the user */ + N_Vector cv_acorQ; /* acorQ = yQ_n(m) - yQ_n(0) */ + N_Vector cv_tempvQ; /* temporary storage vector (~ tempv) */ /*--------------------------- Sensitivity Related Vectors ---------------------------*/ - N_Vector *cv_znS[L_MAX]; /* Nordsieck arrays for sensitivities */ - N_Vector *cv_ewtS; /* error weight vectors for sensitivities */ - N_Vector *cv_yS; /* yS=yS0 (allocated by the user) */ - N_Vector *cv_acorS; /* acorS = yS_n(m) - yS_n(0) */ - N_Vector *cv_tempvS; /* temporary storage vector (~ tempv) */ - N_Vector *cv_ftempS; /* temporary storage vector (~ ftemp) */ + N_Vector* cv_znS[L_MAX]; /* Nordsieck arrays for sensitivities */ + N_Vector* cv_ewtS; /* error weight vectors for sensitivities */ + N_Vector* cv_yS; /* yS=yS0 (allocated by the user) */ + N_Vector* cv_acorS; /* acorS = yS_n(m) - yS_n(0) */ + N_Vector* cv_tempvS; /* temporary storage vector (~ tempv) */ + N_Vector* cv_ftempS; /* temporary storage vector (~ ftemp) */ - booleantype cv_stgr1alloc; /* Did we allocate ncfS1, ncfnS1, and nniS1? */ + sunbooleantype cv_stgr1alloc; /* Did we allocate ncfS1, ncfnS1, and nniS1? */ /*-------------------------------------- Quadrature Sensitivity Related Vectors --------------------------------------*/ - N_Vector *cv_znQS[L_MAX]; /* Nordsieck arrays for quadr. sensitivities */ - N_Vector *cv_ewtQS; /* error weight vectors for sensitivities */ - N_Vector *cv_yQS; /* Unlike yS, yQS is not allocated by the user */ - N_Vector *cv_acorQS; /* acorQS = yQS_n(m) - yQS_n(0) */ - N_Vector *cv_tempvQS; /* temporary storage vector (~ tempv) */ - N_Vector cv_ftempQ; /* temporary storage vector (~ ftemp) */ + N_Vector* cv_znQS[L_MAX]; /* Nordsieck arrays for quadr. sensitivities */ + N_Vector* cv_ewtQS; /* error weight vectors for sensitivities */ + N_Vector* cv_yQS; /* Unlike yS, yQS is not allocated by the user */ + N_Vector* cv_acorQS; /* acorQS = yQS_n(m) - yQS_n(0) */ + N_Vector* cv_tempvQS; /* temporary storage vector (~ tempv) */ + N_Vector cv_ftempQ; /* temporary storage vector (~ ftemp) */ /*----------------- Tstop information -----------------*/ - booleantype cv_tstopset; - realtype cv_tstop; + sunbooleantype cv_tstopset; + sunbooleantype cv_tstopinterp; + sunrealtype cv_tstop; /*--------- Step Data ---------*/ - int cv_q; /* current order */ - int cv_qprime; /* order to be used on the next step + int cv_q; /* current order */ + int cv_qprime; /* order to be used on the next step qprime = q-1, q, or q+1 */ - int cv_next_q; /* order to be used on the next step */ - int cv_qwait; /* number of internal steps to wait before + int cv_next_q; /* order to be used on the next step */ + int cv_qwait; /* number of internal steps to wait before considering a change in q */ - int cv_L; /* L = q + 1 */ - - realtype cv_hin; /* initial step size */ - realtype cv_h; /* current step size */ - realtype cv_hprime; /* step size to be used on the next step */ - realtype cv_next_h; /* step size to be used on the next step */ - realtype cv_eta; /* eta = hprime / h */ - realtype cv_hscale; /* value of h used in zn */ - realtype cv_tn; /* current internal value of t */ - realtype cv_tretlast; /* last value of t returned by CVode */ - - realtype cv_tau[L_MAX+1]; /* array of previous q+1 successful step + int cv_L; /* L = q + 1 */ + + sunrealtype cv_hin; /* initial step size */ + sunrealtype cv_h; /* current step size */ + sunrealtype cv_hprime; /* step size to be used on the next step */ + sunrealtype cv_next_h; /* step size to be used on the next step */ + sunrealtype cv_eta; /* eta = hprime / h */ + sunrealtype cv_hscale; /* value of h used in zn */ + sunrealtype cv_tn; /* current internal value of t */ + sunrealtype cv_tretlast; /* last value of t returned by CVode */ + + sunrealtype cv_tau[L_MAX + 1]; /* array of previous q+1 successful step sizes indexed from 1 to q+1 */ - realtype cv_tq[NUM_TESTS+1]; /* array of test quantities indexed from + sunrealtype cv_tq[NUM_TESTS + 1]; /* array of test quantities indexed from 1 to NUM_TESTS(=5) */ - realtype cv_l[L_MAX]; /* coefficients of l(x) (degree q poly) */ - - realtype cv_rl1; /* the scalar 1/l[1] */ - realtype cv_gamma; /* gamma = h * rl1 */ - realtype cv_gammap; /* gamma at the last setup call */ - realtype cv_gamrat; /* gamma / gammap */ - - realtype cv_crate; /* estimated corrector convergence rate */ - realtype cv_crateS; /* estimated corrector convergence rate (Stgr) */ - realtype cv_delp; /* norm of previous nonlinear solver update */ - realtype cv_acnrm; /* | acor | */ - booleantype cv_acnrmcur; /* is | acor | current? */ - realtype cv_acnrmQ; /* | acorQ | */ - realtype cv_acnrmS; /* | acorS | */ - booleantype cv_acnrmScur; /* is | acorS | current? */ - realtype cv_acnrmQS; /* | acorQS | */ - realtype cv_nlscoef; /* coeficient in nonlinear convergence test */ - int *cv_ncfS1; /* Array of Ns local counters for conv. + sunrealtype cv_l[L_MAX]; /* coefficients of l(x) (degree q poly) */ + + sunrealtype cv_rl1; /* the scalar 1/l[1] */ + sunrealtype cv_gamma; /* gamma = h * rl1 */ + sunrealtype cv_gammap; /* gamma at the last setup call */ + sunrealtype cv_gamrat; /* gamma / gammap */ + + sunrealtype cv_crate; /* estimated corrector convergence rate */ + sunrealtype cv_crateS; /* estimated corrector convergence rate (Stgr) */ + sunrealtype cv_delp; /* norm of previous nonlinear solver update */ + sunrealtype cv_acnrm; /* | acor | */ + sunbooleantype cv_acnrmcur; /* is | acor | current? */ + sunrealtype cv_acnrmQ; /* | acorQ | */ + sunrealtype cv_acnrmS; /* | acorS | */ + sunbooleantype cv_acnrmScur; /* is | acorS | current? */ + sunrealtype cv_acnrmQS; /* | acorQS | */ + sunrealtype cv_nlscoef; /* coeficient in nonlinear convergence test */ + int* cv_ncfS1; /* Array of Ns local counters for conv. * failures (used in CVStep for STAGGERED1) */ /*------ Limits ------*/ - int cv_qmax; /* q <= qmax */ - long int cv_mxstep; /* maximum number of internal steps for one user call */ - int cv_mxhnil; /* maximum number of warning messages issued to the - user that t + h == t for the next internal step */ - int cv_maxnef; /* maximum number of error test failures */ - int cv_maxncf; /* maximum number of nonlinear convergence failures */ - - realtype cv_hmin; /* |h| >= hmin */ - realtype cv_hmax_inv; /* |h| <= 1/hmax_inv */ - realtype cv_etamax; /* eta <= etamax */ + int cv_qmax; /* q <= qmax */ + long int cv_mxstep; /* maximum number of internal steps for one user call */ + int cv_mxhnil; /* maximum number of warning messages issued to the + user that t + h == t for the next internal step */ + int cv_maxnef; /* maximum number of error test failures */ + int cv_maxncf; /* maximum number of nonlinear convergence failures */ + + sunrealtype cv_hmin; /* |h| >= hmin */ + sunrealtype cv_hmax_inv; /* |h| <= 1/hmax_inv */ + sunrealtype cv_etamax; /* eta <= etamax */ + sunrealtype cv_eta_min_fx; /* eta_min_fx < eta < eta_max_fx keep the current h */ + sunrealtype cv_eta_max_fx; + sunrealtype cv_eta_max_fs; /* eta <= eta_max_fs on the first step */ + sunrealtype cv_eta_max_es; /* eta <= eta_max_es on early steps */ + sunrealtype cv_eta_max_gs; /* eta <= eta_max_gs on a general step */ + sunrealtype cv_eta_min; /* eta >= eta_min on a general step */ + sunrealtype cv_eta_min_ef; /* eta >= eta_min_ef after an error test failure */ + sunrealtype cv_eta_max_ef; /* eta on multiple (>= small_nef) error test failures */ + sunrealtype cv_eta_cf; /* eta on a nonlinear solver convergence failure */ + + long int cv_small_nst; /* nst <= small_nst use eta_max_es */ + int cv_small_nef; /* nef >= small_nef use eta_max_ef */ /*-------- Counters --------*/ - long int cv_nst; /* number of internal steps taken */ + long int cv_nst; /* number of internal steps taken */ - long int cv_nfe; /* number of f calls */ - long int cv_nfQe; /* number of fQ calls */ - long int cv_nfSe; /* number of fS calls */ - long int cv_nfeS; /* number of f calls from sensi DQ */ - long int cv_nfQSe; /* number of fQS calls */ - long int cv_nfQeS; /* number of fQ calls from sensi DQ */ + long int cv_nfe; /* number of f calls */ + long int cv_nfQe; /* number of fQ calls */ + long int cv_nfSe; /* number of fS calls */ + long int cv_nfeS; /* number of f calls from sensi DQ */ + long int cv_nfQSe; /* number of fQS calls */ + long int cv_nfQeS; /* number of fQ calls from sensi DQ */ - long int cv_ncfn; /* number of corrector convergence failures */ - long int cv_ncfnS; /* number of total sensi. corr. conv. failures */ - long int *cv_ncfnS1; /* number of sensi. corrector conv. failures */ + long int cv_ncfn; /* number of corrector convergence failures */ + long int cv_ncfnS; /* number of total sensi. corr. conv. failures */ + long int* cv_ncfnS1; /* number of sensi. corrector conv. failures */ - long int cv_nni; /* number of nonlinear iterations performed */ - long int cv_nniS; /* number of total sensi. nonlinear iterations */ - long int *cv_nniS1; /* number of sensi. nonlinear iterations */ + long int cv_nni; /* number of nonlinear iterations performed */ + long int cv_nniS; /* number of total sensi. nonlinear iterations */ + long int* cv_nniS1; /* number of sensi. nonlinear iterations */ - long int cv_netf; /* number of error test failures */ - long int cv_netfQ; /* number of quadr. error test failures */ - long int cv_netfS; /* number of sensi. error test failures */ - long int cv_netfQS; /* number of quadr. sensi. error test failures */ + long int cv_nnf; /* number of nonlinear convergence fails */ + long int cv_nnfS; /* number of total sensi. nonlinear conv. fails */ + long int* cv_nnfS1; /* number of sensi. nonlinear conv. fails */ - long int cv_nsetups; /* number of setup calls */ - long int cv_nsetupsS; /* number of setup calls due to sensitivities */ + long int cv_netf; /* number of error test failures */ + long int cv_netfQ; /* number of quadr. error test failures */ + long int cv_netfS; /* number of sensi. error test failures */ + long int cv_netfQS; /* number of quadr. sensi. error test failures */ - int cv_nhnil; /* number of messages issued to the user that + long int cv_nsetups; /* number of setup calls */ + long int cv_nsetupsS; /* number of setup calls due to sensitivities */ + + int cv_nhnil; /* number of messages issued to the user that t + h == t for the next iternal step */ /*---------------- Step size ratios ----------------*/ - realtype cv_etaqm1; /* ratio of new to old h for order q-1 */ - realtype cv_etaq; /* ratio of new to old h for order q */ - realtype cv_etaqp1; /* ratio of new to old h for order q+1 */ + sunrealtype cv_etaqm1; /* ratio of new to old h for order q-1 */ + sunrealtype cv_etaq; /* ratio of new to old h for order q */ + sunrealtype cv_etaqp1; /* ratio of new to old h for order q+1 */ /*------------------ Space requirements ------------------*/ - sunindextype cv_lrw1; /* no. of realtype words in 1 N_Vector y */ - sunindextype cv_liw1; /* no. of integer words in 1 N_Vector y */ - sunindextype cv_lrw1Q; /* no. of realtype words in 1 N_Vector yQ */ - sunindextype cv_liw1Q; /* no. of integer words in 1 N_Vector yQ */ - long int cv_lrw; /* no. of realtype words in CVODE work vectors */ - long int cv_liw; /* no. of integer words in CVODE work vectors */ + sunindextype cv_lrw1; /* no. of sunrealtype words in 1 N_Vector y */ + sunindextype cv_liw1; /* no. of integer words in 1 N_Vector y */ + sunindextype cv_lrw1Q; /* no. of sunrealtype words in 1 N_Vector yQ */ + sunindextype cv_liw1Q; /* no. of integer words in 1 N_Vector yQ */ + long int cv_lrw; /* no. of sunrealtype words in CVODE work vectors */ + long int cv_liw; /* no. of integer words in CVODE work vectors */ /*--------------------- Nonlinear Solver Data ---------------------*/ - SUNNonlinearSolver NLS; /* nonlinear solver object */ - booleantype ownNLS; /* flag indicating NLS ownership */ + SUNNonlinearSolver NLS; /* nonlinear solver object */ + sunbooleantype ownNLS; /* flag indicating NLS ownership */ - SUNNonlinearSolver NLSsim; /* NLS object for the simultaneous corrector */ - booleantype ownNLSsim; /* flag indicating NLS ownership */ + SUNNonlinearSolver NLSsim; /* NLS object for the simultaneous corrector */ + sunbooleantype ownNLSsim; /* flag indicating NLS ownership */ - SUNNonlinearSolver NLSstg; /* NLS object for the staggered corrector */ - booleantype ownNLSstg; /* flag indicating NLS ownership */ + SUNNonlinearSolver NLSstg; /* NLS object for the staggered corrector */ + sunbooleantype ownNLSstg; /* flag indicating NLS ownership */ - SUNNonlinearSolver NLSstg1; /* NLS object for the staggered1 corrector */ - booleantype ownNLSstg1; /* flag indicating NLS ownership */ - int sens_solve_idx; /* index of the current staggered1 solve */ - long int nnip; /* previous total number of iterations */ + SUNNonlinearSolver NLSstg1; /* NLS object for the staggered1 corrector */ + sunbooleantype ownNLSstg1; /* flag indicating NLS ownership */ + int sens_solve_idx; /* index of the current staggered1 solve */ + long int nnip; /* previous total number of iterations */ - booleantype sens_solve; /* flag indicating if the current solve is a + sunbooleantype sens_solve; /* flag indicating if the current solve is a staggered or staggered1 sensitivity solve */ - CVRhsFn nls_f; /* f(t,y(t)) used in the nonlinear solver */ - int convfail; /* flag to indicate when a Jacobian update may + CVRhsFn nls_f; /* f(t,y(t)) used in the nonlinear solver */ + int convfail; /* flag to indicate when a Jacobian update may be needed */ /* The following vectors are NVector wrappers for use with the simultaneous @@ -397,9 +556,8 @@ typedef struct CVodeMemRec { /* flags indicating if vector wrappers for the simultaneous and staggered correctors have been allocated */ - booleantype simMallocDone; - booleantype stgMallocDone; - + sunbooleantype simMallocDone; + sunbooleantype stgMallocDone; /*------------------ Linear Solver Data @@ -407,78 +565,75 @@ typedef struct CVodeMemRec { /* Linear Solver functions to be called */ - int (*cv_linit)(struct CVodeMemRec *cv_mem); + int (*cv_linit)(struct CVodeMemRec* cv_mem); - int (*cv_lsetup)(struct CVodeMemRec *cv_mem, int convfail, - N_Vector ypred, N_Vector fpred, booleantype *jcurPtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + int (*cv_lsetup)(struct CVodeMemRec* cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, sunbooleantype* jcurPtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); - int (*cv_lsolve)(struct CVodeMemRec *cv_mem, N_Vector b, N_Vector weight, + int (*cv_lsolve)(struct CVodeMemRec* cv_mem, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur); - int (*cv_lfree)(struct CVodeMemRec *cv_mem); + int (*cv_lfree)(struct CVodeMemRec* cv_mem); /* Linear Solver specific memory */ - void *cv_lmem; /* linear solver interface memory structure */ - long int cv_msbp; /* max number of steps between lsetip calls */ - - /* Flag to request a call to the setup routine */ - - booleantype cv_forceSetup; + void* cv_lmem; /* linear solver interface memory structure */ + long int cv_msbp; /* max number of steps between lsetip calls */ + sunrealtype cv_dgmax_lsetup; /* gamma ratio threshold to signal for a linear + * solver setup */ + sunbooleantype cv_forceSetup; /* flag to request a call to the setup routine */ /*------------ Saved Values ------------*/ - int cv_qu; /* last successful q value used */ - long int cv_nstlp; /* step number of last setup call */ - realtype cv_h0u; /* actual initial stepsize */ - realtype cv_hu; /* last successful h value used */ - realtype cv_saved_tq5; /* saved value of tq[5] */ - booleantype cv_jcur; /* is Jacobian info for linear solver current? */ - int cv_convfail; /* flag storing previous solver failure mode */ - realtype cv_tolsf; /* tolerance scale factor */ - int cv_qmax_alloc; /* value of qmax used when allocating mem */ - int cv_qmax_allocQ; /* qmax used when allocating quad. mem */ - int cv_qmax_allocS; /* qmax used when allocating sensi. mem */ - int cv_qmax_allocQS; /* qmax used when allocating quad. sensi. mem */ - int cv_indx_acor; /* index of the zn vector with saved acor */ + int cv_qu; /* last successful q value used */ + long int cv_nstlp; /* step number of last setup call */ + sunrealtype cv_h0u; /* actual initial stepsize */ + sunrealtype cv_hu; /* last successful h value used */ + sunrealtype cv_saved_tq5; /* saved value of tq[5] */ + sunbooleantype cv_jcur; /* is Jacobian info for linear solver current? */ + int cv_convfail; /* flag storing previous solver failure mode */ + sunrealtype cv_tolsf; /* tolerance scale factor */ + int cv_qmax_alloc; /* value of qmax used when allocating mem */ + int cv_qmax_allocQ; /* qmax used when allocating quad. mem */ + int cv_qmax_allocS; /* qmax used when allocating sensi. mem */ + int cv_qmax_allocQS; /* qmax used when allocating quad. sensi. mem */ + int cv_indx_acor; /* index of the zn vector with saved acor */ /*-------------------------------------------------------------------- Flags turned ON by CVodeInit, CVodeSensMalloc, and CVodeQuadMalloc and read by CVodeReInit, CVodeSensReInit, and CVodeQuadReInit --------------------------------------------------------------------*/ - booleantype cv_VabstolMallocDone; - booleantype cv_MallocDone; - booleantype cv_constraintsMallocDone; + sunbooleantype cv_VabstolMallocDone; + sunbooleantype cv_MallocDone; + sunbooleantype cv_constraintsMallocDone; - booleantype cv_VabstolQMallocDone; - booleantype cv_QuadMallocDone; + sunbooleantype cv_VabstolQMallocDone; + sunbooleantype cv_QuadMallocDone; - booleantype cv_VabstolSMallocDone; - booleantype cv_SabstolSMallocDone; - booleantype cv_SensMallocDone; + sunbooleantype cv_VabstolSMallocDone; + sunbooleantype cv_SabstolSMallocDone; + sunbooleantype cv_SensMallocDone; - booleantype cv_VabstolQSMallocDone; - booleantype cv_SabstolQSMallocDone; - booleantype cv_QuadSensMallocDone; + sunbooleantype cv_VabstolQSMallocDone; + sunbooleantype cv_SabstolQSMallocDone; + sunbooleantype cv_QuadSensMallocDone; /*------------------------------------------- - Error handler function and error ouput file + User access function -------------------------------------------*/ - - CVErrHandlerFn cv_ehfun; /* error messages are handled by ehfun */ - void *cv_eh_data; /* data pointer passed to ehfun */ - FILE *cv_errfp; /* CVODE error messages are sent to errfp */ + CVMonitorFn cv_monitorfun; /* func called with CVODE mem and user data */ + long int cv_monitor_interval; /* step interval to call cv_monitorfun */ /*------------------------- Stability Limit Detection -------------------------*/ - booleantype cv_sldeton; /* is Stability Limit Detection on? */ - realtype cv_ssdat[6][4]; /* scaled data array for STALD */ + sunbooleantype cv_sldeton; /* is Stability Limit Detection on? */ + sunrealtype cv_ssdat[6][4]; /* scaled data array for STALD */ int cv_nscon; /* counter for STALD method */ long int cv_nor; /* counter for number of order reductions */ @@ -486,44 +641,52 @@ typedef struct CVodeMemRec { Rootfinding Data ----------------*/ - CVRootFn cv_gfun; /* function g for roots sought */ - int cv_nrtfn; /* number of components of g */ - int *cv_iroots; /* array for root information */ - int *cv_rootdir; /* array specifying direction of zero-crossing */ - realtype cv_tlo; /* nearest endpoint of interval in root search */ - realtype cv_thi; /* farthest endpoint of interval in root search */ - realtype cv_trout; /* t value returned by rootfinding routine */ - realtype *cv_glo; /* saved array of g values at t = tlo */ - realtype *cv_ghi; /* saved array of g values at t = thi */ - realtype *cv_grout; /* array of g values at t = trout */ - realtype cv_toutc; /* copy of tout (if NORMAL mode) */ - realtype cv_ttol; /* tolerance on root location trout */ - int cv_taskc; /* copy of parameter itask */ - int cv_irfnd; /* flag showing whether last step had a root */ - long int cv_nge; /* counter for g evaluations */ - booleantype *cv_gactive; /* array with active/inactive event functions */ - int cv_mxgnull; /* number of warning messages about possible g==0 */ + CVRootFn cv_gfun; /* function g for roots sought */ + int cv_nrtfn; /* number of components of g */ + int* cv_iroots; /* array for root information */ + int* cv_rootdir; /* array specifying direction of zero-crossing */ + sunrealtype cv_tlo; /* nearest endpoint of interval in root search */ + sunrealtype cv_thi; /* farthest endpoint of interval in root search */ + sunrealtype cv_trout; /* t value returned by rootfinding routine */ + sunrealtype* cv_glo; /* saved array of g values at t = tlo */ + sunrealtype* cv_ghi; /* saved array of g values at t = thi */ + sunrealtype* cv_grout; /* array of g values at t = trout */ + sunrealtype cv_toutc; /* copy of tout (if NORMAL mode) */ + sunrealtype cv_ttol; /* tolerance on root location trout */ + int cv_taskc; /* copy of parameter itask */ + int cv_irfnd; /* flag showing whether last step had a root */ + long int cv_nge; /* counter for g evaluations */ + sunbooleantype* cv_gactive; /* array with active/inactive event functions */ + int cv_mxgnull; /* number of warning messages about possible g==0 */ + + /*--------------- + Projection Data + ---------------*/ + + CVodeProjMem proj_mem; /* projection memory structure */ + sunbooleantype proj_enabled; /* flag indicating if projection is enabled */ + sunbooleantype proj_applied; /* flag indicating if projection was applied */ + sunrealtype proj_p[L_MAX]; /* coefficients of p(x) (degree q poly) */ /*----------------------- Fused Vector Operations -----------------------*/ - realtype* cv_cvals; /* array of scalars */ - N_Vector* cv_Xvecs; /* array of vectors */ - N_Vector* cv_Zvecs; /* array of vectors */ + sunrealtype* cv_cvals; /* array of scalars */ + N_Vector* cv_Xvecs; /* array of vectors */ + N_Vector* cv_Zvecs; /* array of vectors */ /*------------------------ Adjoint sensitivity data ------------------------*/ - booleantype cv_adj; /* SUNTRUE if performing ASA */ - - struct CVadjMemRec *cv_adj_mem; /* Pointer to adjoint memory structure */ + sunbooleantype cv_adj; /* SUNTRUE if performing ASA */ - booleantype cv_adjMallocDone; + struct CVadjMemRec* cv_adj_mem; /* Pointer to adjoint memory structure */ -} *CVodeMem; + sunbooleantype cv_adjMallocDone; +}* CVodeMem; /* * ================================================================= @@ -533,43 +696,43 @@ typedef struct CVodeMemRec { /* * ----------------------------------------------------------------- - * Types : struct CkpntMemRec, CkpntMem + * Types : struct CVckpntMemRec, CVckpntMem * ----------------------------------------------------------------- - * The type CkpntMem is type pointer to struct CkpntMemRec. + * The type CVckpntMem is type pointer to struct CVckpntMemRec. * This structure contains fields to store all information at a * check point that is needed to 'hot' start cvodes. * ----------------------------------------------------------------- */ -struct CkpntMemRec { - +struct CVckpntMemRec +{ /* Integration limits */ - realtype ck_t0; - realtype ck_t1; + sunrealtype ck_t0; + sunrealtype ck_t1; /* Nordsieck History Array */ N_Vector ck_zn[L_MAX]; /* Do we need to carry quadratures? */ - booleantype ck_quadr; + sunbooleantype ck_quadr; /* Nordsieck History Array for quadratures */ N_Vector ck_znQ[L_MAX]; /* Do we need to carry sensitivities? */ - booleantype ck_sensi; + sunbooleantype ck_sensi; /* number of sensitivities */ int ck_Ns; /* Nordsieck History Array for sensitivities */ - N_Vector *ck_znS[L_MAX]; + N_Vector* ck_znS[L_MAX]; /* Do we need to carry quadrature sensitivities? */ - booleantype ck_quadr_sensi; + sunbooleantype ck_quadr_sensi; /* Nordsieck History Array for quadrature sensitivities */ - N_Vector *ck_znQS[L_MAX]; + N_Vector* ck_znQS[L_MAX]; /* Was ck_zn[qmax] allocated? ck_zqm = 0 - no @@ -578,27 +741,26 @@ struct CkpntMemRec { /* Step data */ long int ck_nst; - realtype ck_tretlast; - int ck_q; - int ck_qprime; - int ck_qwait; - int ck_L; - realtype ck_gammap; - realtype ck_h; - realtype ck_hprime; - realtype ck_hscale; - realtype ck_eta; - realtype ck_etamax; - realtype ck_tau[L_MAX+1]; - realtype ck_tq[NUM_TESTS+1]; - realtype ck_l[L_MAX]; + sunrealtype ck_tretlast; + int ck_q; + int ck_qprime; + int ck_qwait; + int ck_L; + sunrealtype ck_gammap; + sunrealtype ck_h; + sunrealtype ck_hprime; + sunrealtype ck_hscale; + sunrealtype ck_eta; + sunrealtype ck_etamax; + sunrealtype ck_tau[L_MAX + 1]; + sunrealtype ck_tq[NUM_TESTS + 1]; + sunrealtype ck_l[L_MAX]; /* Saved values */ - realtype ck_saved_tq5; + sunrealtype ck_saved_tq5; /* Pointer to next structure in list */ - struct CkpntMemRec *ck_next; - + struct CVckpntMemRec* ck_next; }; /* @@ -616,14 +778,15 @@ struct CkpntMemRec { * ----------------------------------------------------------------- */ -typedef booleantype (*cvaIMMallocFn)(CVodeMem cv_mem); +typedef sunbooleantype (*cvaIMMallocFn)(CVodeMem cv_mem); typedef void (*cvaIMFreeFn)(CVodeMem cv_mem); -typedef int (*cvaIMGetYFn)(CVodeMem cv_mem, realtype t, N_Vector y, N_Vector *yS); -typedef int (*cvaIMStorePntFn)(CVodeMem cv_mem, DtpntMem d); +typedef int (*cvaIMGetYFn)(CVodeMem cv_mem, sunrealtype t, N_Vector y, + N_Vector* yS); +typedef int (*cvaIMStorePntFn)(CVodeMem cv_mem, CVdtpntMem d); /* * ----------------------------------------------------------------- - * Type : struct DtpntMemRec + * Type : struct CVdtpntMemRec * ----------------------------------------------------------------- * This structure contains fields to store all information at a * data point that is needed to interpolate solution of forward @@ -631,26 +794,28 @@ typedef int (*cvaIMStorePntFn)(CVodeMem cv_mem, DtpntMem d); * ----------------------------------------------------------------- */ -struct DtpntMemRec { - realtype t; /* time */ - void *content; /* IMtype-dependent content */ +struct CVdtpntMemRec +{ + sunrealtype t; /* time */ + void* content; /* IMtype-dependent content */ }; /* Data for cubic Hermite interpolation */ -typedef struct HermiteDataMemRec { +typedef struct CVhermiteDataMemRec +{ N_Vector y; N_Vector yd; - N_Vector *yS; - N_Vector *ySd; -} *HermiteDataMem; + N_Vector* yS; + N_Vector* ySd; +}* CVhermiteDataMem; /* Data for polynomial interpolation */ -typedef struct PolynomialDataMemRec { +typedef struct CVpolynomialDataMemRec +{ N_Vector y; - N_Vector *yS; + N_Vector* yS; int order; -} *PolynomialDataMem; - +}* CVpolynomialDataMem; /* * ----------------------------------------------------------------- @@ -662,21 +827,21 @@ typedef struct PolynomialDataMemRec { * ----------------------------------------------------------------- */ -struct CVodeBMemRec { - +struct CVodeBMemRec +{ /* Index of this backward problem */ int cv_index; /* Time at which the backward problem is initialized */ - realtype cv_t0; + sunrealtype cv_t0; /* CVODES memory for this backward problem */ CVodeMem cv_mem; /* Flags to indicate that this backward problem's RHS or quad RHS * require forward sensitivities */ - booleantype cv_f_withSensi; - booleantype cv_fQ_withSensi; + sunbooleantype cv_f_withSensi; + sunbooleantype cv_fQ_withSensi; /* Right hand side function for backward run */ CVRhsFnB cv_f; @@ -687,29 +852,28 @@ struct CVodeBMemRec { CVQuadRhsFnBS cv_fQs; /* User user_data */ - void *cv_user_data; + void* cv_user_data; /* Memory block for a linear solver's interface to CVODEA */ - void *cv_lmem; + void* cv_lmem; /* Function to free any memory allocated by the linear solver */ int (*cv_lfree)(CVodeBMem cvB_mem); /* Memory block for a preconditioner's module interface to CVODEA */ - void *cv_pmem; + void* cv_pmem; /* Function to free any memory allocated by the preconditioner module */ int (*cv_pfree)(CVodeBMem cvB_mem); /* Time at which to extract solution / quadratures */ - realtype cv_tout; + sunrealtype cv_tout; /* Workspace Nvector */ N_Vector cv_y; /* Pointer to next structure in list */ - struct CVodeBMemRec *cv_next; - + struct CVodeBMemRec* cv_next; }; /* @@ -722,55 +886,55 @@ struct CVodeBMemRec { * ----------------------------------------------------------------- */ -struct CVadjMemRec { - +struct CVadjMemRec +{ /* -------------------- * Forward problem data * -------------------- */ /* Integration interval */ - realtype ca_tinitial, ca_tfinal; + sunrealtype ca_tinitial, ca_tfinal; /* Flag for first call to CVodeF */ - booleantype ca_firstCVodeFcall; + sunbooleantype ca_firstCVodeFcall; /* Flag if CVodeF was called with TSTOP */ - booleantype ca_tstopCVodeFcall; - realtype ca_tstopCVodeF; + sunbooleantype ca_tstopCVodeFcall; + sunrealtype ca_tstopCVodeF; /* Flag if CVodeF was called in CV_NORMAL_MODE and encountered a root after tout */ - booleantype ca_rootret; - realtype ca_troot; + sunbooleantype ca_rootret; + sunrealtype ca_troot; /* ---------------------- * Backward problems data * ---------------------- */ /* Storage for backward problems */ - struct CVodeBMemRec *cvB_mem; + struct CVodeBMemRec* cvB_mem; /* Number of backward problems */ int ca_nbckpbs; /* Address of current backward problem */ - struct CVodeBMemRec *ca_bckpbCrt; + struct CVodeBMemRec* ca_bckpbCrt; /* Flag for first call to CVodeB */ - booleantype ca_firstCVodeBcall; + sunbooleantype ca_firstCVodeBcall; /* ---------------- * Check point data * ---------------- */ /* Storage for check point information */ - struct CkpntMemRec *ck_mem; + struct CVckpntMemRec* ck_mem; /* Number of check points */ int ca_nckpnts; /* address of the check point structure for which data is available */ - struct CkpntMemRec *ca_ckpntData; + struct CVckpntMemRec* ca_ckpntData; /* ------------------ * Interpolation data @@ -783,7 +947,7 @@ struct CVadjMemRec { long int ca_ilast; /* Storage for data from forward runs */ - struct DtpntMemRec **dt_mem; + struct CVdtpntMemRec** dt_mem; /* Actual number of data points in dt_mem (typically np=nsteps+1) */ long int ca_np; @@ -792,21 +956,21 @@ struct CVadjMemRec { int ca_IMtype; /* Functions set by the interpolation module */ - cvaIMMallocFn ca_IMmalloc; - cvaIMFreeFn ca_IMfree; + cvaIMMallocFn ca_IMmalloc; + cvaIMFreeFn ca_IMfree; cvaIMStorePntFn ca_IMstore; /* store a new interpolation point */ - cvaIMGetYFn ca_IMget; /* interpolate forward solution */ + cvaIMGetYFn ca_IMget; /* interpolate forward solution */ /* Flags controlling the interpolation module */ - booleantype ca_IMmallocDone; /* IM initialized? */ - booleantype ca_IMnewData; /* new data available in dt_mem?*/ - booleantype ca_IMstoreSensi; /* store sensitivities? */ - booleantype ca_IMinterpSensi; /* interpolate sensitivities? */ + sunbooleantype ca_IMmallocDone; /* IM initialized? */ + sunbooleantype ca_IMnewData; /* new data available in dt_mem?*/ + sunbooleantype ca_IMstoreSensi; /* store sensitivities? */ + sunbooleantype ca_IMinterpSensi; /* interpolate sensitivities? */ /* Workspace for the interpolation module */ - N_Vector ca_Y[L_MAX]; /* pointers to zn[i] */ - N_Vector *ca_YS[L_MAX]; /* pointers to znS[i] */ - realtype ca_T[L_MAX]; + N_Vector ca_Y[L_MAX]; /* pointers to zn[i] */ + N_Vector* ca_YS[L_MAX]; /* pointers to znS[i] */ + sunrealtype ca_T[L_MAX]; /* ------------------------------- * Workspace for wrapper functions @@ -814,11 +978,9 @@ struct CVadjMemRec { N_Vector ca_ytmp; - N_Vector *ca_yStmp; - + N_Vector* ca_yStmp; }; - /* * ================================================================= * I N T E R F A C E T O L I N E A R S O L V E R S @@ -878,7 +1040,7 @@ struct CVadjMemRec { /* * ----------------------------------------------------------------- * int (*cv_lsetup)(CVodeMem cv_mem, int convfail, N_Vector ypred, - * N_Vector fpred, booleantype *jcurPtr, + * N_Vector fpred, sunbooleantype *jcurPtr, * N_Vector vtemp1, N_Vector vtemp2, * N_Vector vtemp3); * ----------------------------------------------------------------- @@ -959,24 +1121,24 @@ struct CVadjMemRec { /* Norm functions */ -realtype cvSensNorm(CVodeMem cv_mem, N_Vector *xS, N_Vector *wS); +sunrealtype cvSensNorm(CVodeMem cv_mem, N_Vector* xS, N_Vector* wS); -realtype cvSensUpdateNorm(CVodeMem cv_mem, realtype old_nrm, - N_Vector *xS, N_Vector *wS); +sunrealtype cvSensUpdateNorm(CVodeMem cv_mem, sunrealtype old_nrm, N_Vector* xS, + N_Vector* wS); /* Prototype of internal ewtSet function */ -int cvEwtSet(N_Vector ycur, N_Vector weight, void *data); +int cvEwtSet(N_Vector ycur, N_Vector weight, void* data); /* High level error handler */ -void cvProcessError(CVodeMem cv_mem, int error_code, const char *module, - const char *fname, const char *msgfmt, ...); +void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...); /* Prototype of internal ErrHandler function */ -void cvErrHandler(int error_code, const char *module, const char *function, - char *msg, void *data); +void cvErrHandler(int error_code, const char* module, const char* function, + char* msg, void* data); /* Nonlinear solver initialization */ @@ -985,30 +1147,39 @@ int cvNlsInitSensSim(CVodeMem cv_mem); int cvNlsInitSensStg(CVodeMem cv_mem); int cvNlsInitSensStg1(CVodeMem cv_mem); +/* Projection functions */ + +int cvDoProjection(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + int* npfPtr); +int cvProjInit(CVodeProjMem proj_mem); +int cvProjFree(CVodeProjMem* proj_mem); + +/* Restore tn and undo prediction to reattempt a step */ + +void cvRestore(CVodeMem cv_mem, sunrealtype saved_t); + +/* Reset h and rescale history array to prepare for a step */ + +void cvRescale(CVodeMem cv_mem); + /* Prototypes for internal sensitivity rhs wrappers */ -int cvSensRhsWrapper(CVodeMem cv_mem, realtype time, - N_Vector ycur, N_Vector fcur, - N_Vector *yScur, N_Vector *fScur, +int cvSensRhsWrapper(CVodeMem cv_mem, sunrealtype time, N_Vector ycur, + N_Vector fcur, N_Vector* yScur, N_Vector* fScur, N_Vector temp1, N_Vector temp2); -int cvSensRhs1Wrapper(CVodeMem cv_mem, realtype time, - N_Vector ycur, N_Vector fcur, - int is, N_Vector yScur, N_Vector fScur, +int cvSensRhs1Wrapper(CVodeMem cv_mem, sunrealtype time, N_Vector ycur, + N_Vector fcur, int is, N_Vector yScur, N_Vector fScur, N_Vector temp1, N_Vector temp2); /* Prototypes for internal sensitivity rhs DQ functions */ -int cvSensRhsInternalDQ(int Ns, realtype t, - N_Vector y, N_Vector ydot, - N_Vector *yS, N_Vector *ySdot, - void *fS_data, +int cvSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + N_Vector* yS, N_Vector* ySdot, void* fS_data, N_Vector tempv, N_Vector ftemp); -int cvSensRhs1InternalDQ(int Ns, realtype t, - N_Vector y, N_Vector ydot, - int is, N_Vector yS, N_Vector ySdot, - void *fS_data, +int cvSensRhs1InternalDQ(int Ns, sunrealtype t, N_Vector y, N_Vector ydot, + int is, N_Vector yS, N_Vector ySdot, void* fS_data, N_Vector tempv, N_Vector ftemp); /* @@ -1019,151 +1190,238 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, #if defined(SUNDIALS_EXTENDED_PRECISION) -#define MSG_TIME "t = %Lg" -#define MSG_TIME_H "t = %Lg and h = %Lg" -#define MSG_TIME_INT "t = %Lg is not between tcur - hu = %Lg and tcur = %Lg." -#define MSG_TIME_TOUT "tout = %Lg" -#define MSG_TIME_TSTOP "tstop = %Lg" +#define MSG_TIME "t = %Lg" +#define MSG_TIME_H "t = %Lg and h = %Lg" +#define MSG_TIME_INT "t = %Lg is not between tcur - hu = %Lg and tcur = %Lg." +#define MSG_TIME_TOUT "tout = %Lg" +#define MSG_TIME_TSTOP "tstop = %Lg" #elif defined(SUNDIALS_DOUBLE_PRECISION) -#define MSG_TIME "t = %lg" -#define MSG_TIME_H "t = %lg and h = %lg" -#define MSG_TIME_INT "t = %lg is not between tcur - hu = %lg and tcur = %lg." -#define MSG_TIME_TOUT "tout = %lg" -#define MSG_TIME_TSTOP "tstop = %lg" +#define MSG_TIME "t = %lg" +#define MSG_TIME_H "t = %lg and h = %lg" +#define MSG_TIME_INT "t = %lg is not between tcur - hu = %lg and tcur = %lg." +#define MSG_TIME_TOUT "tout = %lg" +#define MSG_TIME_TSTOP "tstop = %lg" #else -#define MSG_TIME "t = %g" -#define MSG_TIME_H "t = %g and h = %g" -#define MSG_TIME_INT "t = %g is not between tcur - hu = %g and tcur = %g." -#define MSG_TIME_TOUT "tout = %g" -#define MSG_TIME_TSTOP "tstop = %g" +#define MSG_TIME "t = %g" +#define MSG_TIME_H "t = %g and h = %g" +#define MSG_TIME_INT "t = %g is not between tcur - hu = %g and tcur = %g." +#define MSG_TIME_TOUT "tout = %g" +#define MSG_TIME_TSTOP "tstop = %g" #endif /* Initialization and I/O error messages */ -#define MSGCV_NO_MEM "cvode_mem = NULL illegal." +#define MSGCV_NO_MEM "cvode_mem = NULL illegal." #define MSGCV_CVMEM_FAIL "Allocation of cvode_mem failed." -#define MSGCV_MEM_FAIL "A memory request failed." -#define MSGCV_BAD_LMM "Illegal value for lmm. The legal values are CV_ADAMS and CV_BDF." -#define MSGCV_NO_MALLOC "Attempt to call before CVodeInit." -#define MSGCV_NEG_MAXORD "maxord <= 0 illegal." +#define MSGCV_MEM_FAIL "A memory request failed." +#define MSGCV_BAD_LMM \ + "Illegal value for lmm. The legal values are CV_ADAMS and CV_BDF." +#define MSGCV_NULL_SUNCTX "sunctx = NULL illegal." +#define MSGCV_NO_MALLOC "Attempt to call before CVodeInit." +#define MSGCV_NEG_MAXORD "maxord <= 0 illegal." #define MSGCV_BAD_MAXORD "Illegal attempt to increase maximum method order." -#define MSGCV_SET_SLDET "Attempt to use stability limit detection with the CV_ADAMS method illegal." -#define MSGCV_NEG_HMIN "hmin < 0 illegal." -#define MSGCV_NEG_HMAX "hmax < 0 illegal." -#define MSGCV_BAD_HMIN_HMAX "Inconsistent step size limits: hmin > hmax." -#define MSGCV_BAD_RELTOL "reltol < 0 illegal." -#define MSGCV_BAD_ABSTOL "abstol has negative component(s) (illegal)." -#define MSGCV_NULL_ABSTOL "abstol = NULL illegal." -#define MSGCV_NULL_Y0 "y0 = NULL illegal." +#define MSGCV_SET_SLDET \ + "Attempt to use stability limit detection with the CV_ADAMS method illegal." +#define MSGCV_NEG_HMIN "hmin < 0 illegal." +#define MSGCV_NEG_HMAX "hmax < 0 illegal." +#define MSGCV_BAD_HMIN_HMAX "Inconsistent step size limits: hmin > hmax." +#define MSGCV_BAD_RELTOL "reltol < 0 illegal." +#define MSGCV_BAD_ABSTOL "abstol has negative component(s) (illegal)." +#define MSGCV_NULL_ABSTOL "abstol = NULL illegal." +#define MSGCV_NULL_Y0 "y0 = NULL illegal." #define MSGCV_Y0_FAIL_CONSTR "y0 fails to satisfy constraints." -#define MSGCV_BAD_ISM_CONSTR "Constraints can not be enforced while forward sensitivity is used with simultaneous method" -#define MSGCV_NULL_F "f = NULL illegal." -#define MSGCV_NULL_G "g = NULL illegal." -#define MSGCV_BAD_NVECTOR "A required vector operation is not implemented." -#define MSGCV_BAD_CONSTR "Illegal values in constraints vector." -#define MSGCV_BAD_K "Illegal value for k." -#define MSGCV_NULL_DKY "dky = NULL illegal." -#define MSGCV_BAD_T "Illegal value for t." MSG_TIME_INT -#define MSGCV_NO_ROOT "Rootfinding was not initialized." +#define MSGCV_BAD_ISM_CONSTR \ + "Constraints can not be enforced while forward sensitivity is used with " \ + "simultaneous method" +#define MSGCV_NULL_F "f = NULL illegal." +#define MSGCV_NULL_G "g = NULL illegal." +#define MSGCV_BAD_NVECTOR "A required vector operation is not implemented." +#define MSGCV_BAD_CONSTR "Illegal values in constraints vector." +#define MSGCV_BAD_K "Illegal value for k." +#define MSGCV_NULL_DKY "dky = NULL illegal." +#define MSGCV_BAD_T "Illegal value for t." MSG_TIME_INT +#define MSGCV_NO_ROOT "Rootfinding was not initialized." #define MSGCV_NLS_INIT_FAIL "The nonlinear solver's init routine failed." -#define MSGCV_NO_QUAD "Quadrature integration not activated." -#define MSGCV_BAD_ITOLQ "Illegal value for itolQ. The legal values are CV_SS and CV_SV." +#define MSGCV_NO_QUAD "Quadrature integration not activated." +#define MSGCV_BAD_ITOLQ \ + "Illegal value for itolQ. The legal values are CV_SS and CV_SV." #define MSGCV_NULL_ABSTOLQ "abstolQ = NULL illegal." -#define MSGCV_BAD_RELTOLQ "reltolQ < 0 illegal." -#define MSGCV_BAD_ABSTOLQ "abstolQ has negative component(s) (illegal)." +#define MSGCV_BAD_RELTOLQ "reltolQ < 0 illegal." +#define MSGCV_BAD_ABSTOLQ "abstolQ has negative component(s) (illegal)." #define MSGCV_SENSINIT_2 "Sensitivity analysis already initialized." -#define MSGCV_NO_SENSI "Forward sensitivity analysis not activated." -#define MSGCV_BAD_ITOLS "Illegal value for itolS. The legal values are CV_SS, CV_SV, and CV_EE." +#define MSGCV_NO_SENSI "Forward sensitivity analysis not activated." +#define MSGCV_BAD_ITOLS \ + "Illegal value for itolS. The legal values are CV_SS, CV_SV, and CV_EE." #define MSGCV_NULL_ABSTOLS "abstolS = NULL illegal." -#define MSGCV_BAD_RELTOLS "reltolS < 0 illegal." -#define MSGCV_BAD_ABSTOLS "abstolS has negative component(s) (illegal)." -#define MSGCV_BAD_PBAR "pbar has zero component(s) (illegal)." -#define MSGCV_BAD_PLIST "plist has negative component(s) (illegal)." -#define MSGCV_BAD_NS "NS <= 0 illegal." -#define MSGCV_NULL_YS0 "yS0 = NULL illegal." -#define MSGCV_BAD_ISM "Illegal value for ism. Legal values are: CV_SIMULTANEOUS, CV_STAGGERED and CV_STAGGERED1." -#define MSGCV_BAD_IFS "Illegal value for ifS. Legal values are: CV_ALLSENS and CV_ONESENS." +#define MSGCV_BAD_RELTOLS "reltolS < 0 illegal." +#define MSGCV_BAD_ABSTOLS "abstolS has negative component(s) (illegal)." +#define MSGCV_BAD_PBAR "pbar has zero component(s) (illegal)." +#define MSGCV_BAD_PLIST "plist has negative component(s) (illegal)." +#define MSGCV_BAD_NS "NS <= 0 illegal." +#define MSGCV_NULL_YS0 "yS0 = NULL illegal." +#define MSGCV_BAD_ISM \ + "Illegal value for ism. Legal values are: CV_SIMULTANEOUS, CV_STAGGERED " \ + "and CV_STAGGERED1." +#define MSGCV_BAD_IFS \ + "Illegal value for ifS. Legal values are: CV_ALLSENS and CV_ONESENS." #define MSGCV_BAD_ISM_IFS "Illegal ism = CV_STAGGERED1 for CVodeSensInit." -#define MSGCV_BAD_IS "Illegal value for is." -#define MSGCV_NULL_DKYA "dkyA = NULL illegal." -#define MSGCV_BAD_DQTYPE "Illegal value for DQtype. Legal values are: CV_CENTERED and CV_FORWARD." +#define MSGCV_BAD_IS "Illegal value for is." +#define MSGCV_NULL_DKYA "dkyA = NULL illegal." +#define MSGCV_BAD_DQTYPE \ + "Illegal value for DQtype. Legal values are: CV_CENTERED and CV_FORWARD." #define MSGCV_BAD_DQRHO "DQrhomax < 0 illegal." -#define MSGCV_BAD_ITOLQS "Illegal value for itolQS. The legal values are CV_SS, CV_SV, and CV_EE." +#define MSGCV_BAD_ITOLQS \ + "Illegal value for itolQS. The legal values are CV_SS, CV_SV, and CV_EE." #define MSGCV_NULL_ABSTOLQS "abstolQS = NULL illegal." -#define MSGCV_BAD_RELTOLQS "reltolQS < 0 illegal." -#define MSGCV_BAD_ABSTOLQS "abstolQS has negative component(s) (illegal)." -#define MSGCV_NO_QUADSENSI "Forward sensitivity analysis for quadrature variables not activated." +#define MSGCV_BAD_RELTOLQS "reltolQS < 0 illegal." +#define MSGCV_BAD_ABSTOLQS "abstolQS has negative component(s) (illegal)." +#define MSGCV_NO_QUADSENSI \ + "Forward sensitivity analysis for quadrature variables not activated." #define MSGCV_NULL_YQS0 "yQS0 = NULL illegal." /* CVode Error Messages */ -#define MSGCV_NO_TOL "No integration tolerances have been specified." +#define MSGCV_NO_TOL "No integration tolerances have been specified." #define MSGCV_LSOLVE_NULL "The linear solver's solve routine is NULL." -#define MSGCV_YOUT_NULL "yout = NULL illegal." -#define MSGCV_TRET_NULL "tret = NULL illegal." -#define MSGCV_BAD_EWT "Initial ewt has component(s) equal to zero (illegal)." +#define MSGCV_YOUT_NULL "yout = NULL illegal." +#define MSGCV_TRET_NULL "tret = NULL illegal." +#define MSGCV_BAD_EWT "Initial ewt has component(s) equal to zero (illegal)." #define MSGCV_EWT_NOW_BAD "At " MSG_TIME ", a component of ewt has become <= 0." -#define MSGCV_BAD_ITASK "Illegal value for itask." -#define MSGCV_BAD_H0 "h0 and tout - t0 inconsistent." -#define MSGCV_BAD_TOUT "Trouble interpolating at " MSG_TIME_TOUT ". tout too far back in direction of integration" +#define MSGCV_BAD_ITASK "Illegal value for itask." +#define MSGCV_BAD_H0 "h0 and tout - t0 inconsistent." +#define MSGCV_BAD_TOUT \ + "Trouble interpolating at " MSG_TIME_TOUT \ + ". tout too far back in direction of integration" #define MSGCV_EWT_FAIL "The user-provide EwtSet function failed." -#define MSGCV_EWT_NOW_FAIL "At " MSG_TIME ", the user-provide EwtSet function failed." +#define MSGCV_EWT_NOW_FAIL \ + "At " MSG_TIME ", the user-provide EwtSet function failed." #define MSGCV_LINIT_FAIL "The linear solver's init routine failed." -#define MSGCV_HNIL_DONE "The above warning has been issued mxhnil times and will not be issued again for this problem." +#define MSGCV_HNIL_DONE \ + "The above warning has been issued mxhnil times and will not be issued " \ + "again for this problem." #define MSGCV_TOO_CLOSE "tout too close to t0 to start integration." -#define MSGCV_MAX_STEPS "At " MSG_TIME ", mxstep steps taken before reaching tout." +#define MSGCV_MAX_STEPS \ + "At " MSG_TIME ", mxstep steps taken before reaching tout." #define MSGCV_TOO_MUCH_ACC "At " MSG_TIME ", too much accuracy requested." -#define MSGCV_HNIL "Internal " MSG_TIME_H " are such that t + h = t on the next step. The solver will continue anyway." -#define MSGCV_ERR_FAILS "At " MSG_TIME_H ", the error test failed repeatedly or with |h| = hmin." -#define MSGCV_CONV_FAILS "At " MSG_TIME_H ", the corrector convergence test failed repeatedly or with |h| = hmin." -#define MSGCV_SETUP_FAILED "At " MSG_TIME ", the setup routine failed in an unrecoverable manner." -#define MSGCV_SOLVE_FAILED "At " MSG_TIME ", the solve routine failed in an unrecoverable manner." -#define MSGCV_FAILED_CONSTR "At " MSG_TIME ", unable to satisfy inequality constraints." -#define MSGCV_RHSFUNC_FAILED "At " MSG_TIME ", the right-hand side routine failed in an unrecoverable manner." -#define MSGCV_RHSFUNC_UNREC "At " MSG_TIME ", the right-hand side failed in a recoverable manner, but no recovery is possible." -#define MSGCV_RHSFUNC_REPTD "At " MSG_TIME " repeated recoverable right-hand side function errors." -#define MSGCV_RHSFUNC_FIRST "The right-hand side routine failed at the first call." -#define MSGCV_RTFUNC_FAILED "At " MSG_TIME ", the rootfinding routine failed in an unrecoverable manner." +#define MSGCV_HNIL \ + "Internal " MSG_TIME_H " are such that t + h = t on the next step. The " \ + "solver will continue anyway." +#define MSGCV_ERR_FAILS \ + "At " MSG_TIME_H ", the error test failed repeatedly or with |h| = hmin." +#define MSGCV_CONV_FAILS \ + "At " MSG_TIME_H \ + ", the corrector convergence test failed repeatedly or with |h| = hmin." +#define MSGCV_SETUP_FAILED \ + "At " MSG_TIME ", the setup routine failed in an unrecoverable manner." +#define MSGCV_SOLVE_FAILED \ + "At " MSG_TIME ", the solve routine failed in an unrecoverable manner." +#define MSGCV_FAILED_CONSTR \ + "At " MSG_TIME ", unable to satisfy inequality constraints." +#define MSGCV_RHSFUNC_FAILED \ + "At " MSG_TIME \ + ", the right-hand side routine failed in an unrecoverable manner." +#define MSGCV_RHSFUNC_UNREC \ + "At " MSG_TIME ", the right-hand side failed in a recoverable manner, but " \ + "no recovery is possible." +#define MSGCV_RHSFUNC_REPTD \ + "At " MSG_TIME " repeated recoverable right-hand side function errors." +#define MSGCV_RHSFUNC_FIRST \ + "The right-hand side routine failed at the first call." +#define MSGCV_RTFUNC_FAILED \ + "At " MSG_TIME ", the rootfinding routine failed in an unrecoverable " \ + "manner." #define MSGCV_CLOSE_ROOTS "Root found at and very near " MSG_TIME "." -#define MSGCV_BAD_TSTOP "The value " MSG_TIME_TSTOP " is behind current " MSG_TIME " in the direction of integration." -#define MSGCV_INACTIVE_ROOTS "At the end of the first step, there are still some root functions identically 0. This warning will not be issued again." -#define MSGCV_NLS_SETUP_FAILED "At " MSG_TIME ", the nonlinear solver setup failed unrecoverably." -#define MSGCV_NLS_INPUT_NULL "At " MSG_TIME ", the nonlinear solver was passed a NULL input." -#define MSGCV_NLS_FAIL "At " MSG_TIME ", the nonlinear solver failed in an unrecoverable manner." - -#define MSGCV_NO_TOLQ "No integration tolerances for quadrature variables have been specified." +#define MSGCV_BAD_TSTOP \ + "The value " MSG_TIME_TSTOP " is behind current " MSG_TIME \ + " in the direction of integration." +#define MSGCV_INACTIVE_ROOTS \ + "At the end of the first step, there are still some root functions " \ + "identically 0. This warning will not be issued again." +#define MSGCV_NLS_SETUP_FAILED \ + "At " MSG_TIME ", the nonlinear solver setup failed unrecoverably." +#define MSGCV_NLS_INPUT_NULL \ + "At " MSG_TIME ", the nonlinear solver was passed a NULL input." +#define MSGCV_NLS_FAIL \ + "At " MSG_TIME ", the nonlinear solver failed in an unrecoverable manner." + +/* CVode Projection Error Messages */ + +#define MSG_CV_MEM_NULL "cvode_mem = NULL illegal." +#define MSG_CV_MEM_FAIL "A memory request failed." + +#define MSG_CV_PROJ_MEM_NULL "proj_mem = NULL illegal." +#define MSG_CV_PROJFUNC_FAIL \ + "At " MSG_TIME " the projection function failed with an unrecoverable " \ + "error." +#define MSG_CV_REPTD_PROJFUNC_ERR \ + "At " MSG_TIME " the projection function had repeated recoverable errors." + +#define MSGCV_NO_TOLQ \ + "No integration tolerances for quadrature variables have been specified." #define MSGCV_BAD_EWTQ "Initial ewtQ has component(s) equal to zero (illegal)." -#define MSGCV_EWTQ_NOW_BAD "At " MSG_TIME ", a component of ewtQ has become <= 0." -#define MSGCV_QRHSFUNC_FAILED "At " MSG_TIME ", the quadrature right-hand side routine failed in an unrecoverable manner." -#define MSGCV_QRHSFUNC_UNREC "At " MSG_TIME ", the quadrature right-hand side failed in a recoverable manner, but no recovery is possible." -#define MSGCV_QRHSFUNC_REPTD "At " MSG_TIME " repeated recoverable quadrature right-hand side function errors." -#define MSGCV_QRHSFUNC_FIRST "The quadrature right-hand side routine failed at the first call." - -#define MSGCV_NO_TOLS "No integration tolerances for sensitivity variables have been specified." -#define MSGCV_NULL_P "p = NULL when using internal DQ for sensitivity RHS illegal." +#define MSGCV_EWTQ_NOW_BAD \ + "At " MSG_TIME ", a component of ewtQ has become <= 0." +#define MSGCV_QRHSFUNC_FAILED \ + "At " MSG_TIME ", the quadrature right-hand side routine failed in an " \ + "unrecoverable manner." +#define MSGCV_QRHSFUNC_UNREC \ + "At " MSG_TIME ", the quadrature right-hand side failed in a recoverable " \ + "manner, but no recovery is possible." +#define MSGCV_QRHSFUNC_REPTD \ + "At " MSG_TIME \ + " repeated recoverable quadrature right-hand side function errors." +#define MSGCV_QRHSFUNC_FIRST \ + "The quadrature right-hand side routine failed at the first call." + +#define MSGCV_NO_TOLS \ + "No integration tolerances for sensitivity variables have been specified." +#define MSGCV_NULL_P \ + "p = NULL when using internal DQ for sensitivity RHS illegal." #define MSGCV_BAD_EWTS "Initial ewtS has component(s) equal to zero (illegal)." -#define MSGCV_EWTS_NOW_BAD "At " MSG_TIME ", a component of ewtS has become <= 0." -#define MSGCV_SRHSFUNC_FAILED "At " MSG_TIME ", the sensitivity right-hand side routine failed in an unrecoverable manner." -#define MSGCV_SRHSFUNC_UNREC "At " MSG_TIME ", the sensitivity right-hand side failed in a recoverable manner, but no recovery is possible." -#define MSGCV_SRHSFUNC_REPTD "At " MSG_TIME " repeated recoverable sensitivity right-hand side function errors." -#define MSGCV_SRHSFUNC_FIRST "The sensitivity right-hand side routine failed at the first call." - -#define MSGCV_NULL_FQ "CVODES is expected to use DQ to evaluate the RHS of quad. sensi., but quadratures were not initialized." -#define MSGCV_NO_TOLQS "No integration tolerances for quadrature sensitivity variables have been specified." -#define MSGCV_BAD_EWTQS "Initial ewtQS has component(s) equal to zero (illegal)." -#define MSGCV_EWTQS_NOW_BAD "At " MSG_TIME ", a component of ewtQS has become <= 0." -#define MSGCV_QSRHSFUNC_FAILED "At " MSG_TIME ", the quadrature sensitivity right-hand side routine failed in an unrecoverable manner." -#define MSGCV_QSRHSFUNC_UNREC "At " MSG_TIME ", the quadrature sensitivity right-hand side failed in a recoverable manner, but no recovery is possible." -#define MSGCV_QSRHSFUNC_REPTD "At " MSG_TIME " repeated recoverable quadrature sensitivity right-hand side function errors." -#define MSGCV_QSRHSFUNC_FIRST "The quadrature sensitivity right-hand side routine failed at the first call." +#define MSGCV_EWTS_NOW_BAD \ + "At " MSG_TIME ", a component of ewtS has become <= 0." +#define MSGCV_SRHSFUNC_FAILED \ + "At " MSG_TIME ", the sensitivity right-hand side routine failed in an " \ + "unrecoverable manner." +#define MSGCV_SRHSFUNC_UNREC \ + "At " MSG_TIME ", the sensitivity right-hand side failed in a recoverable " \ + "manner, but no recovery is possible." +#define MSGCV_SRHSFUNC_REPTD \ + "At " MSG_TIME \ + " repeated recoverable sensitivity right-hand side function errors." +#define MSGCV_SRHSFUNC_FIRST \ + "The sensitivity right-hand side routine failed at the first call." + +#define MSGCV_NULL_FQ \ + "CVODES is expected to use DQ to evaluate the RHS of quad. sensi., but " \ + "quadratures were not initialized." +#define MSGCV_NO_TOLQS \ + "No integration tolerances for quadrature sensitivity variables have been " \ + "specified." +#define MSGCV_BAD_EWTQS \ + "Initial ewtQS has component(s) equal to zero (illegal)." +#define MSGCV_EWTQS_NOW_BAD \ + "At " MSG_TIME ", a component of ewtQS has become <= 0." +#define MSGCV_QSRHSFUNC_FAILED \ + "At " MSG_TIME ", the quadrature sensitivity right-hand side routine " \ + "failed in an unrecoverable manner." +#define MSGCV_QSRHSFUNC_UNREC \ + "At " MSG_TIME ", the quadrature sensitivity right-hand side failed in a " \ + "recoverable manner, but no recovery is possible." +#define MSGCV_QSRHSFUNC_REPTD \ + "At " MSG_TIME " repeated recoverable quadrature sensitivity right-hand " \ + "side function errors." +#define MSGCV_QSRHSFUNC_FIRST \ + "The quadrature sensitivity right-hand side routine failed at the first " \ + "call." /* * ================================================================= @@ -1171,19 +1429,27 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, * ================================================================= */ -#define MSGCV_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." -#define MSGCV_BAD_STEPS "Steps nonpositive illegal." -#define MSGCV_BAD_INTERP "Illegal value for interp." -#define MSGCV_BAD_WHICH "Illegal value for which." -#define MSGCV_NO_BCK "No backward problems have been defined yet." -#define MSGCV_NO_FWD "Illegal attempt to call before calling CVodeF." -#define MSGCV_BAD_TB0 "The initial time tB0 for problem %d is outside the interval over which the forward problem was solved." -#define MSGCV_BAD_SENSI "At least one backward problem requires sensitivities, but they were not stored for interpolation." -#define MSGCV_BAD_ITASKB "Illegal value for itaskB. Legal values are CV_NORMAL and CV_ONE_STEP." -#define MSGCV_BAD_TBOUT "The final time tBout is outside the interval over which the forward problem was solved." +#define MSGCV_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." +#define MSGCV_BAD_STEPS "Steps nonpositive illegal." +#define MSGCV_BAD_INTERP "Illegal value for interp." +#define MSGCV_BAD_WHICH "Illegal value for which." +#define MSGCV_NO_BCK "No backward problems have been defined yet." +#define MSGCV_NO_FWD "Illegal attempt to call before calling CVodeF." +#define MSGCV_BAD_TB0 \ + "The initial time tB0 for problem %d is outside the interval over which " \ + "the forward problem was solved." +#define MSGCV_BAD_SENSI \ + "At least one backward problem requires sensitivities, but they were not " \ + "stored for interpolation." +#define MSGCV_BAD_ITASKB \ + "Illegal value for itaskB. Legal values are CV_NORMAL and CV_ONE_STEP." +#define MSGCV_BAD_TBOUT \ + "The final time tBout is outside the interval over which the forward " \ + "problem was solved." #define MSGCV_BACK_ERROR "Error occured while integrating backward problem # %d" #define MSGCV_BAD_TINTERP "Bad t = %g for interpolation." -#define MSGCV_WRONG_INTERP "This function cannot be called for the specified interp type." +#define MSGCV_WRONG_INTERP \ + "This function cannot be called for the specified interp type." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_io.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_io.c index 602a41377..e4599bd85 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_io.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_io.c @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,13 +19,13 @@ #include #include "cvodes_impl.h" +#include "cvodes_ls_impl.h" #include "sundials/sundials_types.h" -#include "sundials/sundials_math.h" -#define ZERO RCONST(0.0) -#define HALF RCONST(0.5) -#define ONE RCONST(1.0) -#define TWOPT5 RCONST(2.5) +#define ZERO SUN_RCONST(0.0) +#define HALF SUN_RCONST(0.5) +#define ONE SUN_RCONST(1.0) +#define TWOPT5 SUN_RCONST(2.5) /* * ================================================================= @@ -34,70 +34,117 @@ */ /* - * CVodeSetErrHandlerFn + * CVodeSetDeltaGammaMaxLSetup * - * Specifies the error handler function + * Specifies the gamma ratio threshold to signal for a linear solver setup */ -int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data) +int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem, sunrealtype dgmax_lsetup) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetErrHandlerFn", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - cv_mem->cv_ehfun = ehfun; - cv_mem->cv_eh_data = eh_data; + /* Set value or use default */ + if (dgmax_lsetup < ZERO) { cv_mem->cv_dgmax_lsetup = DGMAX_LSETUP_DEFAULT; } + else { cv_mem->cv_dgmax_lsetup = dgmax_lsetup; } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* - * CVodeSetErrFile + * CVodeSetUserData * - * Specifies the FILE pointer for output (NULL means no messages) + * Specifies the user data pointer for f */ -int CVodeSetErrFile(void *cvode_mem, FILE *errfp) +int CVodeSetUserData(void* cvode_mem, void* user_data) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetErrFile", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - cv_mem->cv_errfp = errfp; + cv_mem->cv_user_data = user_data; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* - * CVodeSetUserData + * CVodeSetMonitorFn * - * Specifies the user data pointer for f + * Specifies the user function to call for monitoring + * the solution and/or integrator statistics. */ -int CVodeSetUserData(void *cvode_mem, void *user_data) +int CVodeSetMonitorFn(void* cvode_mem, CVMonitorFn fn) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetUserData", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - cv_mem->cv_user_data = user_data; +#ifdef SUNDIALS_BUILD_WITH_MONITORING + cv_mem->cv_monitorfun = fn; + return (CV_SUCCESS); +#else + /* silence warnings when monitoring is disabled */ + ((void)fn); + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "SUNDIALS was not built with monitoring enabled."); + return (CV_ILL_INPUT); +#endif +} + +/* + * CVodeSetMonitorFrequency + * + * Specifies the frequency with which to call the user function. + */ - return(CV_SUCCESS); +int CVodeSetMonitorFrequency(void* cvode_mem, long int nst) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + if (nst < 0) + { + cvProcessError(NULL, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "step interval must be >= 0\n"); + return (CV_ILL_INPUT); + } + + cv_mem = (CVodeMem)cvode_mem; + +#ifdef SUNDIALS_BUILD_WITH_MONITORING + cv_mem->cv_monitor_interval = nst; + return (CV_SUCCESS); +#else + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "SUNDIALS was not built with monitoring enabled."); + return (CV_ILL_INPUT); +#endif } /* @@ -106,21 +153,24 @@ int CVodeSetUserData(void *cvode_mem, void *user_data) * Specifies the maximum method order */ -int CVodeSetMaxOrd(void *cvode_mem, int maxord) +int CVodeSetMaxOrd(void* cvode_mem, int maxord) { CVodeMem cv_mem; int qmax_alloc; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxOrd", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (maxord <= 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMaxOrd", MSGCV_NEG_MAXORD); - return(CV_ILL_INPUT); + if (maxord <= 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NEG_MAXORD); + return (CV_ILL_INPUT); } /* Cannot increase maximum order beyond the value that @@ -129,14 +179,16 @@ int CVodeSetMaxOrd(void *cvode_mem, int maxord) qmax_alloc = SUNMIN(qmax_alloc, cv_mem->cv_qmax_allocQ); qmax_alloc = SUNMIN(qmax_alloc, cv_mem->cv_qmax_allocS); - if (maxord > qmax_alloc) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMaxOrd", MSGCV_BAD_MAXORD); - return(CV_ILL_INPUT); + if (maxord > qmax_alloc) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_MAXORD); + return (CV_ILL_INPUT); } cv_mem->cv_qmax = maxord; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -145,24 +197,23 @@ int CVodeSetMaxOrd(void *cvode_mem, int maxord) * Specifies the maximum number of integration steps */ -int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps) +int CVodeSetMaxNumSteps(void* cvode_mem, long int mxsteps) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxNumSteps", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Passing mxsteps=0 sets the default. Passing mxsteps<0 disables the test. */ - if (mxsteps == 0) - cv_mem->cv_mxstep = MXSTEP_DEFAULT; - else - cv_mem->cv_mxstep = mxsteps; + if (mxsteps == 0) { cv_mem->cv_mxstep = MXSTEP_DEFAULT; } + else { cv_mem->cv_mxstep = mxsteps; } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -171,20 +222,21 @@ int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps) * Specifies the maximum number of warnings for small h */ -int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil) +int CVodeSetMaxHnilWarns(void* cvode_mem, int mxhnil) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxHnilWarns", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_mxhnil = mxhnil; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -193,25 +245,28 @@ int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil) * Turns on/off the stability limit detection algorithm */ -int CVodeSetStabLimDet(void *cvode_mem, booleantype sldet) +int CVodeSetStabLimDet(void* cvode_mem, sunbooleantype sldet) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetStabLimDet", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if( sldet && (cv_mem->cv_lmm != CV_BDF) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetStabLimDet", MSGCV_SET_SLDET); - return(CV_ILL_INPUT); + if (sldet && (cv_mem->cv_lmm != CV_BDF)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_SET_SLDET); + return (CV_ILL_INPUT); } cv_mem->cv_sldeton = sldet; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -220,20 +275,21 @@ int CVodeSetStabLimDet(void *cvode_mem, booleantype sldet) * Specifies the initial step size */ -int CVodeSetInitStep(void *cvode_mem, realtype hin) +int CVodeSetInitStep(void* cvode_mem, sunrealtype hin) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetInitStep", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_hin = hin; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -242,36 +298,42 @@ int CVodeSetInitStep(void *cvode_mem, realtype hin) * Specifies the minimum step size */ -int CVodeSetMinStep(void *cvode_mem, realtype hmin) +int CVodeSetMinStep(void* cvode_mem, sunrealtype hmin) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMinStep", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (hmin<0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMinStep", MSGCV_NEG_HMIN); - return(CV_ILL_INPUT); + if (hmin < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NEG_HMIN); + return (CV_ILL_INPUT); } /* Passing 0 sets hmin = zero */ - if (hmin == ZERO) { + if (hmin == ZERO) + { cv_mem->cv_hmin = HMIN_DEFAULT; - return(CV_SUCCESS); + return (CV_SUCCESS); } - if (hmin * cv_mem->cv_hmax_inv > ONE) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMinStep", MSGCV_BAD_HMIN_HMAX); - return(CV_ILL_INPUT); + if (hmin * cv_mem->cv_hmax_inv > ONE) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_HMIN_HMAX); + return (CV_ILL_INPUT); } cv_mem->cv_hmin = hmin; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -280,38 +342,314 @@ int CVodeSetMinStep(void *cvode_mem, realtype hmin) * Specifies the maximum step size */ -int CVodeSetMaxStep(void *cvode_mem, realtype hmax) +int CVodeSetMaxStep(void* cvode_mem, sunrealtype hmax) { - realtype hmax_inv; + sunrealtype hmax_inv; CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxStep", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (hmax < 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMaxStep", MSGCV_NEG_HMAX); - return(CV_ILL_INPUT); + if (hmax < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NEG_HMAX); + return (CV_ILL_INPUT); } /* Passing 0 sets hmax = infinity */ - if (hmax == ZERO) { + if (hmax == ZERO) + { cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT; - return(CV_SUCCESS); + return (CV_SUCCESS); } - hmax_inv = ONE/hmax; - if (hmax_inv * cv_mem->cv_hmin > ONE) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMaxStep", MSGCV_BAD_HMIN_HMAX); - return(CV_ILL_INPUT); + hmax_inv = ONE / hmax; + if (hmax_inv * cv_mem->cv_hmin > ONE) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_HMIN_HMAX); + return (CV_ILL_INPUT); } cv_mem->cv_hmax_inv = hmax_inv; - return(CV_SUCCESS); + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaFixedStepBounds + * + * Specifies the bounds for retaining the current step size + */ + +int CVodeSetEtaFixedStepBounds(void* cvode_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_min_fx < ZERO || eta_min_fx >= ONE) + { + cv_mem->cv_eta_min_fx = ETA_MIN_FX_DEFAULT; + } + else { cv_mem->cv_eta_min_fx = eta_min_fx; } + + if (eta_max_fx <= ONE) { cv_mem->cv_eta_max_fx = ETA_MAX_FX_DEFAULT; } + else { cv_mem->cv_eta_max_fx = eta_max_fx; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMaxFirstStep + * + * Specifies the maximum step size change on the first step + */ + +int CVodeSetEtaMaxFirstStep(void* cvode_mem, sunrealtype eta_max_fs) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_max_fs <= ONE) { cv_mem->cv_eta_max_fs = ETA_MAX_FS_DEFAULT; } + else { cv_mem->cv_eta_max_fs = eta_max_fs; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMaxEarlyStep + * + * Specifies the maximum step size change on steps early in the integration + * when nst <= small_nst + */ + +int CVodeSetEtaMaxEarlyStep(void* cvode_mem, sunrealtype eta_max_es) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_max_es <= ONE) { cv_mem->cv_eta_max_es = ETA_MAX_ES_DEFAULT; } + else { cv_mem->cv_eta_max_es = eta_max_es; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetNumStepsEtaMaxEarlyStep + * + * Specifies the maximum number of steps for using the early integration change + * factor + */ + +int CVodeSetNumStepsEtaMaxEarlyStep(void* cvode_mem, long int small_nst) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (small_nst < 0) { cv_mem->cv_small_nst = SMALL_NST_DEFAULT; } + else { cv_mem->cv_small_nst = small_nst; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMax + * + * Specifies the maximum step size change on a general steps (nst > small_nst) + */ + +int CVodeSetEtaMax(void* cvode_mem, sunrealtype eta_max_gs) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_max_gs <= ONE) { cv_mem->cv_eta_max_gs = ETA_MAX_GS_DEFAULT; } + else { cv_mem->cv_eta_max_gs = eta_max_gs; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMin + * + * Specifies the minimum change on a general steps + */ + +int CVodeSetEtaMin(void* cvode_mem, sunrealtype eta_min) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_min <= ZERO || eta_min >= ONE) + { + cv_mem->cv_eta_min = ETA_MIN_DEFAULT; + } + else { cv_mem->cv_eta_min = eta_min; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMinErrFail + * + * Specifies the minimum step size change after an error test failure + */ + +int CVodeSetEtaMinErrFail(void* cvode_mem, sunrealtype eta_min_ef) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_min_ef <= ZERO || eta_min_ef >= ONE) + { + cv_mem->cv_eta_min_ef = ETA_MIN_EF_DEFAULT; + } + else { cv_mem->cv_eta_min_ef = eta_min_ef; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaMaxErrFail + * + * Specifies the maximum step size change after multiple (>= small_nef) error + * test failures + */ + +int CVodeSetEtaMaxErrFail(void* cvode_mem, sunrealtype eta_max_ef) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_max_ef <= ZERO || eta_max_ef >= ONE) + { + cv_mem->cv_eta_max_ef = ETA_MAX_EF_DEFAULT; + } + else { cv_mem->cv_eta_max_ef = eta_max_ef; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetNumFailsEtaMaxErrFail + * + * Specifies the maximum number of error test failures necessary to enforce + * eta_max_ef + */ + +int CVodeSetNumFailsEtaMaxErrFail(void* cvode_mem, int small_nef) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (small_nef < 0) { cv_mem->cv_small_nef = SMALL_NEF_DEFAULT; } + else { cv_mem->cv_small_nef = small_nef; } + + return (CV_SUCCESS); +} + +/* + * CVodeSetEtaConvFail + * + * Specifies the step size change after a nonlinear solver failure + */ + +int CVodeSetEtaConvFail(void* cvode_mem, sunrealtype eta_cf) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + /* set allowed value or use default */ + if (eta_cf <= ZERO || eta_cf >= ONE) { cv_mem->cv_eta_cf = ETA_CF_DEFAULT; } + else { cv_mem->cv_eta_cf = eta_cf; } + + return (CV_SUCCESS); } /* @@ -320,33 +658,77 @@ int CVodeSetMaxStep(void *cvode_mem, realtype hmax) * Specifies the time beyond which the integration is not to proceed. */ -int CVodeSetStopTime(void *cvode_mem, realtype tstop) +int CVodeSetStopTime(void* cvode_mem, sunrealtype tstop) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetStopTime", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* If CVode was called at least once, test if tstop is legal * (i.e. if it was not already passed). * If CVodeSetStopTime is called before the first call to CVode, * tstop will be checked in CVode. */ - if (cv_mem->cv_nst > 0) { - - if ( (tstop - cv_mem->cv_tn) * cv_mem->cv_h < ZERO ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetStopTime", MSGCV_BAD_TSTOP, tstop, cv_mem->cv_tn); - return(CV_ILL_INPUT); + if (cv_mem->cv_nst > 0) + { + if ((tstop - cv_mem->cv_tn) * cv_mem->cv_h < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_TSTOP, tstop, cv_mem->cv_tn); + return (CV_ILL_INPUT); } - } - cv_mem->cv_tstop = tstop; + cv_mem->cv_tstop = tstop; cv_mem->cv_tstopset = SUNTRUE; - return(CV_SUCCESS); + return (CV_SUCCESS); +} + +/* + * CVodeSetInterpolateStopTime + * + * Specifies to use interpolation to fill the returned solution at the stop time (instead of a copy). + */ + +int CVodeSetInterpolateStopTime(void* cvode_mem, sunbooleantype interp) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + cv_mem = (CVodeMem)cvode_mem; + cv_mem->cv_tstopinterp = interp; + return (CV_SUCCESS); +} + +/* + * CVodeClearStopTime + * + * Disable the stop time. + */ + +int CVodeClearStopTime(void* cvode_mem) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + cv_mem = (CVodeMem)cvode_mem; + + cv_mem->cv_tstopset = SUNFALSE; + + return (CV_SUCCESS); } /* @@ -356,20 +738,21 @@ int CVodeSetStopTime(void *cvode_mem, realtype tstop) * step try. */ -int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef) +int CVodeSetMaxErrTestFails(void* cvode_mem, int maxnef) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxErrTestFails", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_maxnef = maxnef; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -379,20 +762,21 @@ int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef) * during one step try. */ -int CVodeSetMaxConvFails(void *cvode_mem, int maxncf) +int CVodeSetMaxConvFails(void* cvode_mem, int maxncf) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMaxConvFails", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_maxncf = maxncf; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -402,46 +786,48 @@ int CVodeSetMaxConvFails(void *cvode_mem, int maxncf) * one solve. */ -int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor) +int CVodeSetMaxNonlinIters(void* cvode_mem, int maxcor) { CVodeMem cv_mem; - booleantype sensi_sim; + sunbooleantype sensi_sim; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeSetMaxNonlinIters", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Are we computing sensitivities with the simultaneous approach? */ - sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_SIMULTANEOUS)); - - if (sensi_sim) { + sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_SIMULTANEOUS)); + if (sensi_sim) + { /* check that the NLS is non-NULL */ - if (cv_mem->NLSsim == NULL) { - cvProcessError(NULL, CV_MEM_FAIL, "CVODES", - "CVodeSetMaxNonlinIters", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->NLSsim == NULL) + { + cvProcessError(NULL, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(cv_mem->NLSsim, maxcor)); - - } else { - + return (SUNNonlinSolSetMaxIters(cv_mem->NLSsim, maxcor)); + } + else + { /* check that the NLS is non-NULL */ - if (cv_mem->NLS == NULL) { - cvProcessError(NULL, CV_MEM_FAIL, "CVODES", - "CVodeSetMaxNonlinIters", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->NLS == NULL) + { + cvProcessError(NULL, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(cv_mem->NLS, maxcor)); + return (SUNNonlinSolSetMaxIters(cv_mem->NLS, maxcor)); } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -451,20 +837,21 @@ int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor) * test */ -int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef) +int CVodeSetNonlinConvCoef(void* cvode_mem, sunrealtype nlscoef) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetNonlinConvCoef", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_nlscoef = nlscoef; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -474,29 +861,30 @@ int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef) * recompute the Jacobian matrix and/or preconditioner */ -int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp) +int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp) { CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetLSetupFrequency", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* check for a valid input */ - if (msbp < 0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetLSetupFrequency", + if (msbp < 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "A negative setup frequency was provided"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* use default or user provided value */ - cv_mem->cv_msbp = (msbp == 0) ? MSBP : msbp; + cv_mem->cv_msbp = (msbp == 0) ? MSBP_DEFAULT : msbp; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -506,30 +894,32 @@ int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp) * The default is to monitor both crossings. */ -int CVodeSetRootDirection(void *cvode_mem, int *rootdir) +int CVodeSetRootDirection(void* cvode_mem, int* rootdir) { CVodeMem cv_mem; int i, nrt; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetRootDirection", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; nrt = cv_mem->cv_nrtfn; - if (nrt==0) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetRootDirection", MSGCV_NO_ROOT); - return(CV_ILL_INPUT); + if (nrt == 0) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_NO_ROOT); + return (CV_ILL_INPUT); } - for(i=0; icv_rootdir[i] = rootdir[i]; + for (i = 0; i < nrt; i++) { cv_mem->cv_rootdir[i] = rootdir[i]; } - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * CVodeSetNoInactiveRootWarn * @@ -537,20 +927,21 @@ int CVodeSetRootDirection(void *cvode_mem, int *rootdir) * to be identically zero at the beginning of the integration */ -int CVodeSetNoInactiveRootWarn(void *cvode_mem) +int CVodeSetNoInactiveRootWarn(void* cvode_mem) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetNoInactiveRootWarn", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_mxgnull = 0; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -559,49 +950,56 @@ int CVodeSetNoInactiveRootWarn(void *cvode_mem) * Setup for constraint handling feature */ -int CVodeSetConstraints(void *cvode_mem, N_Vector constraints) +int CVodeSetConstraints(void* cvode_mem, N_Vector constraints) { CVodeMem cv_mem; - realtype temptest; + sunrealtype temptest; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetConstraints", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* If there are no constraints, destroy data structures */ - if (constraints == NULL) { - if (cv_mem->cv_constraintsMallocDone) { + if (constraints == NULL) + { + if (cv_mem->cv_constraintsMallocDone) + { N_VDestroy(cv_mem->cv_constraints); cv_mem->cv_lrw -= cv_mem->cv_lrw1; cv_mem->cv_liw -= cv_mem->cv_liw1; } cv_mem->cv_constraintsMallocDone = SUNFALSE; - cv_mem->cv_constraintsSet = SUNFALSE; - return(CV_SUCCESS); + cv_mem->cv_constraintsSet = SUNFALSE; + return (CV_SUCCESS); } /* Test if required vector ops. are defined */ - if (constraints->ops->nvdiv == NULL || - constraints->ops->nvmaxnorm == NULL || - constraints->ops->nvcompare == NULL || - constraints->ops->nvconstrmask == NULL || - constraints->ops->nvminquotient == NULL) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetConstraints", MSGCV_BAD_NVECTOR); - return(CV_ILL_INPUT); + if (constraints->ops->nvdiv == NULL || constraints->ops->nvmaxnorm == NULL || + constraints->ops->nvcompare == NULL || + constraints->ops->nvconstrmask == NULL || + constraints->ops->nvminquotient == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_NVECTOR); + return (CV_ILL_INPUT); } /* Check the constraints vector */ temptest = N_VMaxNorm(constraints); - if ((temptest > TWOPT5) || (temptest < HALF)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetConstraints", MSGCV_BAD_CONSTR); - return(CV_ILL_INPUT); + if ((temptest > TWOPT5) || (temptest < HALF)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_CONSTR); + return (CV_ILL_INPUT); } - if ( !(cv_mem->cv_constraintsMallocDone) ) { + if (!(cv_mem->cv_constraintsMallocDone)) + { cv_mem->cv_constraints = N_VClone(constraints); cv_mem->cv_lrw += cv_mem->cv_lrw1; cv_mem->cv_liw += cv_mem->cv_liw1; @@ -613,7 +1011,7 @@ int CVodeSetConstraints(void *cvode_mem, N_Vector constraints) cv_mem->cv_constraintsSet = SUNTRUE; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -622,19 +1020,20 @@ int CVodeSetConstraints(void *cvode_mem, N_Vector constraints) * ================================================================= */ -int CVodeSetQuadErrCon(void *cvode_mem, booleantype errconQ) +int CVodeSetQuadErrCon(void* cvode_mem, sunbooleantype errconQ) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetQuadErrCon", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_errconQ = errconQ; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -643,113 +1042,125 @@ int CVodeSetQuadErrCon(void *cvode_mem, booleantype errconQ) * ================================================================= */ -int CVodeSetSensDQMethod(void *cvode_mem, int DQtype, realtype DQrhomax) +int CVodeSetSensDQMethod(void* cvode_mem, int DQtype, sunrealtype DQrhomax) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetSensDQMethod", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if ( (DQtype != CV_CENTERED) && (DQtype != CV_FORWARD) ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetSensDQMethod", MSGCV_BAD_DQTYPE); - return(CV_ILL_INPUT); + if ((DQtype != CV_CENTERED) && (DQtype != CV_FORWARD)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_DQTYPE); + return (CV_ILL_INPUT); } - if (DQrhomax < ZERO ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetSensDQMethod", MSGCV_BAD_DQRHO); - return(CV_ILL_INPUT); + if (DQrhomax < ZERO) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGCV_BAD_DQRHO); + return (CV_ILL_INPUT); } - cv_mem->cv_DQtype = DQtype; + cv_mem->cv_DQtype = DQtype; cv_mem->cv_DQrhomax = DQrhomax; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeSetSensErrCon(void *cvode_mem, booleantype errconS) +int CVodeSetSensErrCon(void* cvode_mem, sunbooleantype errconS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetSensErrCon", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; cv_mem->cv_errconS = errconS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeSetSensMaxNonlinIters(void *cvode_mem, int maxcorS) +int CVodeSetSensMaxNonlinIters(void* cvode_mem, int maxcorS) { CVodeMem cv_mem; - booleantype sensi_stg; + sunbooleantype sensi_stg; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeSetSensMaxNonlinIters", MSGCV_NO_MEM); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Are we computing sensitivities with a staggered approach? */ - sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED)); - - if (sensi_stg) { + sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED)); + if (sensi_stg) + { /* check that the NLS is non-NULL */ - if (cv_mem->NLSstg == NULL) { - cvProcessError(NULL, CV_MEM_FAIL, "CVODES", - "CVodeSetSensMaxNonlinIters", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->NLSstg == NULL) + { + cvProcessError(NULL, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(cv_mem->NLSstg, maxcorS)); - - } else { - + return (SUNNonlinSolSetMaxIters(cv_mem->NLSstg, maxcorS)); + } + else + { /* check that the NLS is non-NULL */ - if (cv_mem->NLSstg1 == NULL) { - cvProcessError(NULL, CV_MEM_FAIL, "CVODES", - "CVodeSetMaxNonlinIters", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->NLSstg1 == NULL) + { + cvProcessError(NULL, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(cv_mem->NLSstg1, maxcorS)); + return (SUNNonlinSolSetMaxIters(cv_mem->NLSstg1, maxcorS)); } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeSetSensParams(void *cvode_mem, realtype *p, realtype *pbar, int *plist) +int CVodeSetSensParams(void* cvode_mem, sunrealtype* p, sunrealtype* pbar, + int* plist) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetSensParams", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSetSensParams", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } Ns = cv_mem->cv_Ns; @@ -761,63 +1172,80 @@ int CVodeSetSensParams(void *cvode_mem, realtype *p, realtype *pbar, int *plist) /* pbar */ if (pbar != NULL) - for (is=0; iscv_pbar[is] = SUNRabs(pbar[is]); } + } else - for (is=0; iscv_pbar[is] = ONE; + { + for (is = 0; is < Ns; is++) { cv_mem->cv_pbar[is] = ONE; } + } /* plist */ if (plist != NULL) - for (is=0; iscv_plist[is] = plist[is]; } + } else - for (is=0; iscv_plist[is] = is; + { + for (is = 0; is < Ns; is++) { cv_mem->cv_plist[is] = is; } + } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeSetQuadSensErrCon(void *cvode_mem, booleantype errconQS) +int CVodeSetQuadSensErrCon(void* cvode_mem, sunbooleantype errconQS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetQuadSensErrCon", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was sensitivity initialized? */ - if (cv_mem->cv_SensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeSetQuadSensTolerances", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_SensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } /* Ckeck if quadrature sensitivity was initialized? */ - if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeSetQuadSensErrCon", MSGCV_NO_QUADSENSI); - return(CV_NO_QUAD); + if (cv_mem->cv_QuadSensMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUAD); } cv_mem->cv_errconQS = errconQS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -832,20 +1260,21 @@ int CVodeSetQuadSensErrCon(void *cvode_mem, booleantype errconQS) * Returns the current number of integration steps */ -int CVodeGetNumSteps(void *cvode_mem, long int *nsteps) +int CVodeGetNumSteps(void* cvode_mem, long int* nsteps) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumSteps", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *nsteps = cv_mem->cv_nst; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -854,20 +1283,21 @@ int CVodeGetNumSteps(void *cvode_mem, long int *nsteps) * Returns the current number of calls to f */ -int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals) +int CVodeGetNumRhsEvals(void* cvode_mem, long int* nfevals) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumRhsEvals", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *nfevals = cv_mem->cv_nfe; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -876,20 +1306,21 @@ int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals) * Returns the current number of calls to the linear solver setup routine */ -int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups) +int CVodeGetNumLinSolvSetups(void* cvode_mem, long int* nlinsetups) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumLinSolvSetups", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *nlinsetups = cv_mem->cv_nsetups; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -898,20 +1329,21 @@ int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups) * Returns the current number of error test failures */ -int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails) +int CVodeGetNumErrTestFails(void* cvode_mem, long int* netfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumErrTestFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *netfails = cv_mem->cv_netf; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -920,20 +1352,21 @@ int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails) * Returns the order on the last succesful step */ -int CVodeGetLastOrder(void *cvode_mem, int *qlast) +int CVodeGetLastOrder(void* cvode_mem, int* qlast) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetLastOrder", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *qlast = cv_mem->cv_qu; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -942,20 +1375,21 @@ int CVodeGetLastOrder(void *cvode_mem, int *qlast) * Returns the order to be attempted on the next step */ -int CVodeGetCurrentOrder(void *cvode_mem, int *qcur) +int CVodeGetCurrentOrder(void* cvode_mem, int* qcur) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentOrder", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *qcur = cv_mem->cv_next_q; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -964,20 +1398,21 @@ int CVodeGetCurrentOrder(void *cvode_mem, int *qcur) * Returns the value of gamma for the current step. */ -int CVodeGetCurrentGamma(void *cvode_mem, realtype *gamma) +int CVodeGetCurrentGamma(void* cvode_mem, sunrealtype* gamma) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentGamma", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *gamma = cv_mem->cv_gamma; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -987,23 +1422,22 @@ int CVodeGetCurrentGamma(void *cvode_mem, realtype *gamma) * limit detection algorithm */ -int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred) +int CVodeGetNumStabLimOrderReds(void* cvode_mem, long int* nslred) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumStabLimOrderReds", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sldeton==SUNFALSE) - *nslred = 0; - else - *nslred = cv_mem->cv_nor; + if (cv_mem->cv_sldeton == SUNFALSE) { *nslred = 0; } + else { *nslred = cv_mem->cv_nor; } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1012,20 +1446,21 @@ int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred) * Returns the step size used on the first step */ -int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused) +int CVodeGetActualInitStep(void* cvode_mem, sunrealtype* hinused) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetActualInitStep", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *hinused = cv_mem->cv_h0u; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1034,20 +1469,21 @@ int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused) * Returns the step size used on the last successful step */ -int CVodeGetLastStep(void *cvode_mem, realtype *hlast) +int CVodeGetLastStep(void* cvode_mem, sunrealtype* hlast) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetLastStep", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *hlast = cv_mem->cv_hu; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1056,20 +1492,21 @@ int CVodeGetLastStep(void *cvode_mem, realtype *hlast) * Returns the step size to be attempted on the next step */ -int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur) +int CVodeGetCurrentStep(void* cvode_mem, sunrealtype* hcur) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentStep", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *hcur = cv_mem->cv_next_h; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1078,20 +1515,21 @@ int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur) * Returns the current state vector */ -int CVodeGetCurrentState(void *cvode_mem, N_Vector *y) +int CVodeGetCurrentState(void* cvode_mem, N_Vector* y) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentState", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *y = cv_mem->cv_y; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1100,20 +1538,21 @@ int CVodeGetCurrentState(void *cvode_mem, N_Vector *y) * Returns the current sensitivity state vector array */ -int CVodeGetCurrentStateSens(void *cvode_mem, N_Vector **yS) +int CVodeGetCurrentStateSens(void* cvode_mem, N_Vector** yS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentStateSens", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *yS = cv_mem->cv_yS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1123,20 +1562,21 @@ int CVodeGetCurrentStateSens(void *cvode_mem, N_Vector **yS) * the staggered1 nonlinear solver. */ -int CVodeGetCurrentSensSolveIndex(void *cvode_mem, int *index) +int CVodeGetCurrentSensSolveIndex(void* cvode_mem, int* index) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentSensSolveIndex", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *index = cv_mem->sens_solve_idx; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1145,20 +1585,21 @@ int CVodeGetCurrentSensSolveIndex(void *cvode_mem, int *index) * Returns the current value of the independent variable */ -int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur) +int CVodeGetCurrentTime(void* cvode_mem, sunrealtype* tcur) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetCurrentTime", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *tcur = cv_mem->cv_tn; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1167,20 +1608,21 @@ int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur) * Returns a suggested factor for scaling tolerances */ -int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfact) +int CVodeGetTolScaleFactor(void* cvode_mem, sunrealtype* tolsfact) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetTolScaleFactor", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *tolsfact = cv_mem->cv_tolsf; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1189,20 +1631,21 @@ int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfact) * This routine returns the current weight vector. */ -int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight) +int CVodeGetErrWeights(void* cvode_mem, N_Vector eweight) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetErrWeights", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; N_VScale(ONE, cv_mem->cv_ewt, eweight); - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1211,20 +1654,21 @@ int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight) * Returns an estimate of the local error */ -int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele) +int CVodeGetEstLocalErrors(void* cvode_mem, N_Vector ele) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetEstLocalErrors", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; N_VScale(ONE, cv_mem->cv_acor, ele); - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1233,21 +1677,22 @@ int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele) * Returns integrator work space requirements */ -int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw) +int CVodeGetWorkSpace(void* cvode_mem, long int* lenrw, long int* leniw) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetWorkSpace", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *leniw = cv_mem->cv_liw; *lenrw = cv_mem->cv_lrw; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1256,32 +1701,33 @@ int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw) * Returns integrator statistics */ -int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, long int *nfevals, - long int *nlinsetups, long int *netfails, int *qlast, - int *qcur, realtype *hinused, realtype *hlast, - realtype *hcur, realtype *tcur) +int CVodeGetIntegratorStats(void* cvode_mem, long int* nsteps, long int* nfevals, + long int* nlinsetups, long int* netfails, int* qlast, + int* qcur, sunrealtype* hinused, sunrealtype* hlast, + sunrealtype* hcur, sunrealtype* tcur) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetIntegratorStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - *nsteps = cv_mem->cv_nst; - *nfevals = cv_mem->cv_nfe; + *nsteps = cv_mem->cv_nst; + *nfevals = cv_mem->cv_nfe; *nlinsetups = cv_mem->cv_nsetups; - *netfails = cv_mem->cv_netf; - *qlast = cv_mem->cv_qu; - *qcur = cv_mem->cv_next_q; - *hinused = cv_mem->cv_h0u; - *hlast = cv_mem->cv_hu; - *hcur = cv_mem->cv_next_h; - *tcur = cv_mem->cv_tn; + *netfails = cv_mem->cv_netf; + *qlast = cv_mem->cv_qu; + *qcur = cv_mem->cv_next_q; + *hinused = cv_mem->cv_h0u; + *hlast = cv_mem->cv_hu; + *hcur = cv_mem->cv_next_h; + *tcur = cv_mem->cv_tn; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1290,20 +1736,21 @@ int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, long int *nfevals * Returns the current number of calls to g (for rootfinding) */ -int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals) +int CVodeGetNumGEvals(void* cvode_mem, long int* ngevals) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumGEvals", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *ngevals = cv_mem->cv_nge; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1312,47 +1759,47 @@ int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals) * Returns pointer to array rootsfound showing roots found */ -int CVodeGetRootInfo(void *cvode_mem, int *rootsfound) +int CVodeGetRootInfo(void* cvode_mem, int* rootsfound) { CVodeMem cv_mem; int i, nrt; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetRootInfo", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; nrt = cv_mem->cv_nrtfn; - for (i=0; icv_iroots[i]; + for (i = 0; i < nrt; i++) { rootsfound[i] = cv_mem->cv_iroots[i]; } - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * CVodeGetNumNonlinSolvIters * * Returns the current number of iterations in the nonlinear solver */ -int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters) +int CVodeGetNumNonlinSolvIters(void* cvode_mem, long int* nniters) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetNumNonlinSolvIters", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *nniters = cv_mem->cv_nni; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1362,20 +1809,21 @@ int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters) * nonlinear solver */ -int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails) +int CVodeGetNumNonlinSolvConvFails(void* cvode_mem, long int* nnfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumNonlinSolvConvFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - *nncfails = cv_mem->cv_ncfn; + *nnfails = cv_mem->cv_nnf; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1384,25 +1832,47 @@ int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails) * Returns nonlinear solver statistics */ -int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters, - long int *nncfails) +int CVodeGetNonlinSolvStats(void* cvode_mem, long int* nniters, long int* nnfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetNonlinSolvStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - *nniters = cv_mem->cv_nni; - *nncfails = cv_mem->cv_ncfn; + *nniters = cv_mem->cv_nni; + *nnfails = cv_mem->cv_nnf; - return(CV_SUCCESS); + return (CV_SUCCESS); } +/* + * CVodeGetNumStepSolveFails + * + * Returns the current number of failed steps due to a nonlinear solver + * convergence failure + */ + +int CVodeGetNumStepSolveFails(void* cvode_mem, long int* nncfails) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + *nncfails = cv_mem->cv_ncfn; + + return (CV_SUCCESS); +} /* * ================================================================= @@ -1412,95 +1882,107 @@ int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters, /*-----------------------------------------------------------------*/ -int CVodeGetQuadNumRhsEvals(void *cvode_mem, long int *nfQevals) +int CVodeGetQuadNumRhsEvals(void* cvode_mem, long int* nfQevals) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadNumRhsEvals", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadNumRhsEvals", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_quadr == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } *nfQevals = cv_mem->cv_nfQe; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadNumErrTestFails(void *cvode_mem, long int *nQetfails) +int CVodeGetQuadNumErrTestFails(void* cvode_mem, long int* nQetfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadNumErrTestFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadNumErrTestFails", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_quadr == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } *nQetfails = cv_mem->cv_netfQ; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadErrWeights(void *cvode_mem, N_Vector eQweight) +int CVodeGetQuadErrWeights(void* cvode_mem, N_Vector eQweight) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadErrWeights", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadErrWeights", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_quadr == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } - if(cv_mem->cv_errconQ) N_VScale(ONE, cv_mem->cv_ewtQ, eQweight); + if (cv_mem->cv_errconQ) { N_VScale(ONE, cv_mem->cv_ewtQ, eQweight); } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadStats(void *cvode_mem, long int *nfQevals, long int *nQetfails) +int CVodeGetQuadStats(void* cvode_mem, long int* nfQevals, long int* nQetfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadStats", MSGCV_NO_QUAD); - return(CV_NO_QUAD); + if (cv_mem->cv_quadr == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUAD, __LINE__, __func__, __FILE__, + MSGCV_NO_QUAD); + return (CV_NO_QUAD); } - *nfQevals = cv_mem->cv_nfQe; + *nfQevals = cv_mem->cv_nfQe; *nQetfails = cv_mem->cv_netfQ; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* @@ -1511,102 +1993,118 @@ int CVodeGetQuadStats(void *cvode_mem, long int *nfQevals, long int *nQetfails) /*-----------------------------------------------------------------*/ -int CVodeGetQuadSensNumRhsEvals(void *cvode_mem, long int *nfQSevals) +int CVodeGetQuadSensNumRhsEvals(void* cvode_mem, long int* nfQSevals) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensNumRhsEvals", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr_sensi == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensNumRhsEvals", MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + if (cv_mem->cv_quadr_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUADSENS); } *nfQSevals = cv_mem->cv_nfQSe; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadSensNumErrTestFails(void *cvode_mem, long int *nQSetfails) +int CVodeGetQuadSensNumErrTestFails(void* cvode_mem, long int* nQSetfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensNumErrTestFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr_sensi == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensNumErrTestFails", MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + if (cv_mem->cv_quadr_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUADSENS); } *nQSetfails = cv_mem->cv_netfQS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadSensErrWeights(void *cvode_mem, N_Vector *eQSweight) +int CVodeGetQuadSensErrWeights(void* cvode_mem, N_Vector* eQSweight) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensErrWeights", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr_sensi == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensErrWeights", MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + if (cv_mem->cv_quadr_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUADSENS); } Ns = cv_mem->cv_Ns; if (cv_mem->cv_errconQS) - for (is=0; iscv_ewtQS[is], eQSweight[is]); + } + } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetQuadSensStats(void *cvode_mem, long int *nfQSevals, long int *nQSetfails) +int CVodeGetQuadSensStats(void* cvode_mem, long int* nfQSevals, + long int* nQSetfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetQuadSensStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_quadr_sensi == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensStats", MSGCV_NO_QUADSENSI); - return(CV_NO_QUADSENS); + if (cv_mem->cv_quadr_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSGCV_NO_QUADSENSI); + return (CV_NO_QUADSENS); } - *nfQSevals = cv_mem->cv_nfQSe; + *nfQSevals = cv_mem->cv_nfQSe; *nQSetfails = cv_mem->cv_netfQS; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* * ================================================================= * FSA optional output functions @@ -1615,450 +2113,745 @@ int CVodeGetQuadSensStats(void *cvode_mem, long int *nfQSevals, long int *nQSetf /*-----------------------------------------------------------------*/ -int CVodeGetSensNumRhsEvals(void *cvode_mem, long int *nfSevals) +int CVodeGetSensNumRhsEvals(void* cvode_mem, long int* nfSevals) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensNumRhsEvals", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensNumRhsEvals", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } *nfSevals = cv_mem->cv_nfSe; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetNumRhsEvalsSens(void *cvode_mem, long int *nfevalsS) +int CVodeGetNumRhsEvalsSens(void* cvode_mem, long int* nfevalsS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNumRhsEvalsSens", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetNumRhsEvalsSens", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } *nfevalsS = cv_mem->cv_nfeS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensNumErrTestFails(void *cvode_mem, long int *nSetfails) +int CVodeGetSensNumErrTestFails(void* cvode_mem, long int* nSetfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensNumErrTestFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensNumErrTestFails", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } *nSetfails = cv_mem->cv_netfS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensNumLinSolvSetups(void *cvode_mem, long int *nlinsetupsS) +int CVodeGetSensNumLinSolvSetups(void* cvode_mem, long int* nlinsetupsS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensNumLinSolvSetups", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensNumLinSolvSetups", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } *nlinsetupsS = cv_mem->cv_nsetupsS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensErrWeights(void *cvode_mem, N_Vector *eSweight) +int CVodeGetSensErrWeights(void* cvode_mem, N_Vector* eSweight) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensErrWeights", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensErrWeights", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } Ns = cv_mem->cv_Ns; - for (is=0; iscv_ewtS[is], eSweight[is]); + } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensStats(void *cvode_mem, long int *nfSevals, long int *nfevalsS, - long int *nSetfails, long int *nlinsetupsS) +int CVodeGetSensStats(void* cvode_mem, long int* nfSevals, long int* nfevalsS, + long int* nSetfails, long int* nlinsetupsS) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensStats", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - *nfSevals = cv_mem->cv_nfSe; - *nfevalsS = cv_mem->cv_nfeS; - *nSetfails = cv_mem->cv_netfS; + *nfSevals = cv_mem->cv_nfSe; + *nfevalsS = cv_mem->cv_nfeS; + *nSetfails = cv_mem->cv_netfS; *nlinsetupsS = cv_mem->cv_nsetupsS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensNumNonlinSolvIters(void *cvode_mem, long int *nSniters) +int CVodeGetSensNumNonlinSolvIters(void* cvode_mem, long int* nSniters) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetSensNumNonlinSolvIters", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeGetSensNumNonlinSolvIters", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } *nSniters = cv_mem->cv_nniS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensNumNonlinSolvConvFails(void *cvode_mem, long int *nSncfails) +int CVodeGetSensNumNonlinSolvConvFails(void* cvode_mem, long int* nSnfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetSensNumNonlinSolvConvFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensNumNonlinSolvConvFails", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - *nSncfails = cv_mem->cv_ncfnS; + *nSnfails = cv_mem->cv_nnfS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetSensNonlinSolvStats(void *cvode_mem, long int *nSniters, - long int *nSncfails) +int CVodeGetSensNonlinSolvStats(void* cvode_mem, long int* nSniters, + long int* nSnfails) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetSensNonlinSolvStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeGetSensNonlinSolvStats", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); + } + + *nSniters = cv_mem->cv_nniS; + *nSnfails = cv_mem->cv_nnfS; + + return (CV_SUCCESS); +} + +int CVodeGetNumStepSensSolveFails(void* cvode_mem, long int* nSncfails) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - *nSniters = cv_mem->cv_nniS; *nSncfails = cv_mem->cv_ncfnS; - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetStgrSensNumNonlinSolvIters(void *cvode_mem, long int *nSTGR1niters) +int CVodeGetStgrSensNumNonlinSolvIters(void* cvode_mem, long int* nSTGR1niters) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetStgrSensNumNonlinSolvIters", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; Ns = cv_mem->cv_Ns; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetStgrSensNumNonlinSolvIters", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - if(cv_mem->cv_ism==CV_STAGGERED1) - for(is=0; iscv_nniS1[is]; + if (cv_mem->cv_ism == CV_STAGGERED1) + { + for (is = 0; is < Ns; is++) { nSTGR1niters[is] = cv_mem->cv_nniS1[is]; } + } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetStgrSensNumNonlinSolvConvFails(void *cvode_mem, long int *nSTGR1ncfails) +int CVodeGetStgrSensNumNonlinSolvConvFails(void* cvode_mem, long int* nSTGR1nfails) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetStgrSensNumNonlinSolvConvFails", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; Ns = cv_mem->cv_Ns; - if (cv_mem->cv_sensi==SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetStgrSensNumNonlinSolvConvFails", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - if(cv_mem->cv_ism==CV_STAGGERED1) - for(is=0; iscv_ncfnS1[is]; + if (cv_mem->cv_ism == CV_STAGGERED1) + { + for (is = 0; is < Ns; is++) { nSTGR1nfails[is] = cv_mem->cv_nnfS1[is]; } + } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -int CVodeGetStgrSensNonlinSolvStats(void *cvode_mem, - long int *nSTGR1niters, - long int *nSTGR1ncfails) +int CVodeGetStgrSensNonlinSolvStats(void* cvode_mem, long int* nSTGR1niters, + long int* nSTGR1nfails) { CVodeMem cv_mem; int is, Ns; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetStgrSensNonlinSolvStats", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; Ns = cv_mem->cv_Ns; - if (cv_mem->cv_sensi == SUNFALSE) { - cvProcessError(cv_mem, CV_NO_SENS, "CVODES", - "CVodeGetStgrSensNonlinSolvStats", MSGCV_NO_SENSI); - return(CV_NO_SENS); + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); } - if(cv_mem->cv_ism == CV_STAGGERED1) { - for(is=0; iscv_nniS1[is]; - for(is=0; iscv_ncfnS1[is]; + if (cv_mem->cv_ism == CV_STAGGERED1) + { + for (is = 0; is < Ns; is++) { nSTGR1niters[is] = cv_mem->cv_nniS1[is]; } + for (is = 0; is < Ns; is++) { nSTGR1nfails[is] = cv_mem->cv_nnfS1[is]; } } - return(CV_SUCCESS); + return (CV_SUCCESS); } /*-----------------------------------------------------------------*/ -char *CVodeGetReturnFlagName(long int flag) +int CVodeGetNumStepStgrSensSolveFails(void* cvode_mem, long int* nSTGR1ncfails) { - char *name; + CVodeMem cv_mem; + int is, Ns; - name = (char *)malloc(24*sizeof(char)); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } - switch(flag) { - case CV_SUCCESS: - sprintf(name,"CV_SUCCESS"); - break; - case CV_TSTOP_RETURN: - sprintf(name,"CV_TSTOP_RETURN"); - break; - case CV_ROOT_RETURN: - sprintf(name,"CV_ROOT_RETURN"); - break; - case CV_TOO_MUCH_WORK: - sprintf(name,"CV_TOO_MUCH_WORK"); - break; - case CV_TOO_MUCH_ACC: - sprintf(name,"CV_TOO_MUCH_ACC"); - break; - case CV_ERR_FAILURE: - sprintf(name,"CV_ERR_FAILURE"); - break; - case CV_CONV_FAILURE: - sprintf(name,"CV_CONV_FAILURE"); - break; - case CV_LINIT_FAIL: - sprintf(name,"CV_LINIT_FAIL"); - break; - case CV_LSETUP_FAIL: - sprintf(name,"CV_LSETUP_FAIL"); - break; - case CV_LSOLVE_FAIL: - sprintf(name,"CV_LSOLVE_FAIL"); - break; - case CV_RHSFUNC_FAIL: - sprintf(name,"CV_RHSFUNC_FAIL"); - break; - case CV_FIRST_RHSFUNC_ERR: - sprintf(name,"CV_FIRST_RHSFUNC_ERR"); - break; - case CV_REPTD_RHSFUNC_ERR: - sprintf(name,"CV_REPTD_RHSFUNC_ERR"); - break; - case CV_UNREC_RHSFUNC_ERR: - sprintf(name,"CV_UNREC_RHSFUNC_ERR"); - break; - case CV_RTFUNC_FAIL: - sprintf(name,"CV_RTFUNC_FAIL"); - break; - case CV_MEM_FAIL: - sprintf(name,"CV_MEM_FAIL"); - break; - case CV_MEM_NULL: - sprintf(name,"CV_MEM_NULL"); - break; - case CV_ILL_INPUT: - sprintf(name,"CV_ILL_INPUT"); - break; - case CV_NO_MALLOC: - sprintf(name,"CV_NO_MALLOC"); - break; - case CV_BAD_K: - sprintf(name,"CV_BAD_K"); - break; - case CV_BAD_T: - sprintf(name,"CV_BAD_T"); - break; - case CV_BAD_DKY: - sprintf(name,"CV_BAD_DKY"); - break; - case CV_NO_QUAD: - sprintf(name,"CV_NO_QUAD"); - break; - case CV_QRHSFUNC_FAIL: - sprintf(name,"CV_QRHSFUNC_FAIL"); - break; - case CV_FIRST_QRHSFUNC_ERR: - sprintf(name,"CV_FIRST_QRHSFUNC_ERR"); - break; - case CV_REPTD_QRHSFUNC_ERR: - sprintf(name,"CV_REPTD_QRHSFUNC_ERR"); - break; - case CV_UNREC_QRHSFUNC_ERR: - sprintf(name,"CV_UNREC_QRHSFUNC_ERR"); - break; - case CV_BAD_IS: - sprintf(name,"CV_BAD_IS"); - break; - case CV_NO_SENS: - sprintf(name,"CV_NO_SENS"); - break; - case CV_SRHSFUNC_FAIL: - sprintf(name,"CV_SRHSFUNC_FAIL"); - break; - case CV_FIRST_SRHSFUNC_ERR: - sprintf(name,"CV_FIRST_SRHSFUNC_ERR"); - break; - case CV_REPTD_SRHSFUNC_ERR: - sprintf(name,"CV_REPTD_SRHSFUNC_ERR"); - break; - case CV_UNREC_SRHSFUNC_ERR: - sprintf(name,"CV_UNREC_SRHSFUNC_ERR"); - break; - case CV_TOO_CLOSE: - sprintf(name,"CV_TOO_CLOSE"); - break; - case CV_NO_ADJ: - sprintf(name,"CV_NO_ADJ"); - break; - case CV_NO_FWD: - sprintf(name,"CV_NO_FWD"); - break; - case CV_NO_BCK: - sprintf(name,"CV_NO_BCK"); - break; - case CV_BAD_TB0: - sprintf(name,"CV_BAD_TB0"); - break; - case CV_REIFWD_FAIL: - sprintf(name,"CV_REIFWD_FAIL"); - break; - case CV_FWD_FAIL: - sprintf(name,"CV_FWD_FAIL"); - break; - case CV_GETY_BADT: - sprintf(name,"CV_GETY_BADT"); + cv_mem = (CVodeMem)cvode_mem; + + Ns = cv_mem->cv_Ns; + + if (cv_mem->cv_sensi == SUNFALSE) + { + cvProcessError(cv_mem, CV_NO_SENS, __LINE__, __func__, __FILE__, + MSGCV_NO_SENSI); + return (CV_NO_SENS); + } + + if (cv_mem->cv_ism == CV_STAGGERED1) + { + for (is = 0; is < Ns; is++) { nSTGR1ncfails[is] = cv_mem->cv_ncfnS1[is]; } + } + + return (CV_SUCCESS); +} + +/* + * CVodePrintAllStats + * + * Print all integrator statistics + */ + +int CVodePrintAllStats(void* cvode_mem, FILE* outfile, SUNOutputFormat fmt) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + CVodeProjMem cvproj_mem; + int is; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + switch (fmt) + { + case SUN_OUTPUTFORMAT_TABLE: + /* step and method stats */ + fprintf(outfile, "Current time = %" RSYM "\n", cv_mem->cv_tn); + fprintf(outfile, "Steps = %ld\n", cv_mem->cv_nst); + fprintf(outfile, "Error test fails = %ld\n", cv_mem->cv_netf); + fprintf(outfile, "NLS step fails = %ld\n", cv_mem->cv_ncfn); + fprintf(outfile, "Initial step size = %" RSYM "\n", + cv_mem->cv_h0u); + fprintf(outfile, "Last step size = %" RSYM "\n", cv_mem->cv_hu); + fprintf(outfile, "Current step size = %" RSYM "\n", + cv_mem->cv_next_h); + fprintf(outfile, "Last method order = %d\n", cv_mem->cv_qu); + fprintf(outfile, "Current method order = %d\n", cv_mem->cv_next_q); + fprintf(outfile, "Stab. lim. order reductions = %ld\n", cv_mem->cv_nor); + + /* function evaluations */ + fprintf(outfile, "RHS fn evals = %ld\n", cv_mem->cv_nfe); + + /* nonlinear solver stats */ + fprintf(outfile, "NLS iters = %ld\n", cv_mem->cv_nni); + fprintf(outfile, "NLS fails = %ld\n", cv_mem->cv_nnf); + if (cv_mem->cv_nst > 0) + { + fprintf(outfile, "NLS iters per step = %" RSYM "\n", + (sunrealtype)cv_mem->cv_nni / (sunrealtype)cv_mem->cv_nst); + } + + /* linear solver stats */ + fprintf(outfile, "LS setups = %ld\n", cv_mem->cv_nsetups); + if (cv_mem->cv_lmem) + { + cvls_mem = (CVLsMem)(cv_mem->cv_lmem); + fprintf(outfile, "Jac fn evals = %ld\n", cvls_mem->nje); + fprintf(outfile, "LS RHS fn evals = %ld\n", cvls_mem->nfeDQ); + fprintf(outfile, "Prec setup evals = %ld\n", cvls_mem->npe); + fprintf(outfile, "Prec solves = %ld\n", cvls_mem->nps); + fprintf(outfile, "LS iters = %ld\n", cvls_mem->nli); + fprintf(outfile, "LS fails = %ld\n", cvls_mem->ncfl); + fprintf(outfile, "Jac-times setups = %ld\n", + cvls_mem->njtsetup); + fprintf(outfile, "Jac-times evals = %ld\n", cvls_mem->njtimes); + if (cv_mem->cv_nni > 0) + { + fprintf(outfile, "LS iters per NLS iter = %" RSYM "\n", + (sunrealtype)cvls_mem->nli / (sunrealtype)cv_mem->cv_nni); + fprintf(outfile, "Jac evals per NLS iter = %" RSYM "\n", + (sunrealtype)cvls_mem->nje / (sunrealtype)cv_mem->cv_nni); + fprintf(outfile, "Prec evals per NLS iter = %" RSYM "\n", + (sunrealtype)cvls_mem->npe / (sunrealtype)cv_mem->cv_nni); + } + } + + /* rootfinding stats */ + fprintf(outfile, "Root fn evals = %ld\n", cv_mem->cv_nge); + + /* projection stats */ + if (cv_mem->proj_mem) + { + cvproj_mem = (CVodeProjMem)(cv_mem->proj_mem); + fprintf(outfile, "Projection fn evals = %ld\n", cvproj_mem->nproj); + fprintf(outfile, "Projection fails = %ld\n", + cvproj_mem->npfails); + } + + /* quadrature stats */ + if (cv_mem->cv_quadr) + { + fprintf(outfile, "Quad fn evals = %ld\n", cv_mem->cv_nfQe); + fprintf(outfile, "Quad error test fails = %ld\n", cv_mem->cv_netfQ); + } + + /* sensitivity stats */ + if (cv_mem->cv_sensi) + { + fprintf(outfile, "Sens fn evals = %ld\n", cv_mem->cv_nfSe); + fprintf(outfile, "Sens RHS fn evals = %ld\n", cv_mem->cv_nfeS); + fprintf(outfile, "Sens error test fails = %ld\n", cv_mem->cv_netfS); + if (cv_mem->cv_ism != CV_SIMULTANEOUS) + { + fprintf(outfile, "Sens NLS iters = %ld\n", cv_mem->cv_nniS); + fprintf(outfile, "Sens NLS fails = %ld\n", cv_mem->cv_nnfS); + fprintf(outfile, "Sens NLS step fails = %ld\n", + cv_mem->cv_ncfnS); + } + if (cv_mem->cv_ism == CV_STAGGERED1) + { + fprintf(outfile, "Sens stgr1 NLS iters = %ld", + cv_mem->cv_nniS1[0]); + for (is = 1; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ", %ld", cv_mem->cv_nniS1[is]); + } + fprintf(outfile, "\n"); + fprintf(outfile, "Sens stgr1 NLS fails = %ld", + cv_mem->cv_nnfS1[0]); + for (is = 1; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ", %ld", cv_mem->cv_nnfS1[is]); + } + fprintf(outfile, "\n"); + fprintf(outfile, "Sens stgr1 NLS step fails = %ld", + cv_mem->cv_ncfnS1[0]); + for (is = 1; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ", %ld", cv_mem->cv_ncfnS1[is]); + } + fprintf(outfile, "\n"); + } + fprintf(outfile, "Sens LS setups = %ld\n", + cv_mem->cv_nsetupsS); + } + + /* quadrature-sensitivity stats */ + if (cv_mem->cv_quadr_sensi) + { + fprintf(outfile, "QuadSens fn evals = %ld\n", cv_mem->cv_nfQSe); + fprintf(outfile, "QuadSens error test fails = %ld\n", cv_mem->cv_netfQS); + } break; - case CV_NLS_FAIL: - sprintf(name,"CV_NLS_FAIL"); + + case SUN_OUTPUTFORMAT_CSV: + /* step and method stats */ + fprintf(outfile, "Time,%" RSYM, cv_mem->cv_tn); + fprintf(outfile, ",Steps,%ld", cv_mem->cv_nst); + fprintf(outfile, ",Error test fails,%ld", cv_mem->cv_netf); + fprintf(outfile, ",NLS step fails,%ld", cv_mem->cv_ncfn); + fprintf(outfile, ",Initial step size,%" RSYM, cv_mem->cv_h0u); + fprintf(outfile, ",Last step size,%" RSYM, cv_mem->cv_hu); + fprintf(outfile, ",Current step size,%" RSYM, cv_mem->cv_next_h); + fprintf(outfile, ",Last method order,%d", cv_mem->cv_qu); + fprintf(outfile, ",Current method order,%d", cv_mem->cv_next_q); + fprintf(outfile, ",Stab. lim. order reductions,%ld", cv_mem->cv_nor); + + /* function evaluations */ + fprintf(outfile, ",RHS fn evals,%ld", cv_mem->cv_nfe); + + /* nonlinear solver stats */ + fprintf(outfile, ",NLS iters,%ld", cv_mem->cv_nni); + fprintf(outfile, ",NLS fails,%ld", cv_mem->cv_nnf); + if (cv_mem->cv_nst > 0) + { + fprintf(outfile, ",NLS iters per step,%" RSYM, + (sunrealtype)cv_mem->cv_nni / (sunrealtype)cv_mem->cv_nst); + } + else { fprintf(outfile, ",NLS iters per step,0"); } + + /* linear solver stats */ + fprintf(outfile, ",LS setups,%ld", cv_mem->cv_nsetups); + if (cv_mem->cv_lmem) + { + cvls_mem = (CVLsMem)(cv_mem->cv_lmem); + fprintf(outfile, ",Jac fn evals,%ld", cvls_mem->nje); + fprintf(outfile, ",LS RHS fn evals,%ld", cvls_mem->nfeDQ); + fprintf(outfile, ",Prec setup evals,%ld", cvls_mem->npe); + fprintf(outfile, ",Prec solves,%ld", cvls_mem->nps); + fprintf(outfile, ",LS iters,%ld", cvls_mem->nli); + fprintf(outfile, ",LS fails,%ld", cvls_mem->ncfl); + fprintf(outfile, ",Jac-times setups,%ld", cvls_mem->njtsetup); + fprintf(outfile, ",Jac-times evals,%ld", cvls_mem->njtimes); + if (cv_mem->cv_nni > 0) + { + fprintf(outfile, ",LS iters per NLS iter,%" RSYM, + (sunrealtype)cvls_mem->nli / (sunrealtype)cv_mem->cv_nni); + fprintf(outfile, ",Jac evals per NLS iter,%" RSYM, + (sunrealtype)cvls_mem->nje / (sunrealtype)cv_mem->cv_nni); + fprintf(outfile, ",Prec evals per NLS iter,%" RSYM, + (sunrealtype)cvls_mem->npe / (sunrealtype)cv_mem->cv_nni); + } + else + { + fprintf(outfile, ",LS iters per NLS iter,0"); + fprintf(outfile, ",Jac evals per NLS iter,0"); + fprintf(outfile, ",Prec evals per NLS iter,0"); + } + } + + /* rootfinding stats */ + fprintf(outfile, ",Root fn evals,%ld", cv_mem->cv_nge); + + /* projection stats */ + if (cv_mem->proj_mem) + { + cvproj_mem = (CVodeProjMem)(cv_mem->proj_mem); + fprintf(outfile, ",Projection fn evals,%ld", cvproj_mem->nproj); + fprintf(outfile, ",Projection fails,%ld", cvproj_mem->npfails); + } + + /* quadrature stats */ + if (cv_mem->cv_quadr) + { + fprintf(outfile, ",Quad fn evals,%ld", cv_mem->cv_nfQe); + fprintf(outfile, ",Quad error test fails,%ld", cv_mem->cv_netfQ); + } + + /* sensitivity stats */ + if (cv_mem->cv_sensi) + { + fprintf(outfile, ",Sens fn evals,%ld", cv_mem->cv_nfSe); + fprintf(outfile, ",Sens RHS fn evals,%ld", cv_mem->cv_nfeS); + fprintf(outfile, ",Sens error test fails,%ld", cv_mem->cv_netfS); + if (cv_mem->cv_ism != CV_SIMULTANEOUS) + { + fprintf(outfile, ",Sens NLS iters,%ld", cv_mem->cv_nniS); + fprintf(outfile, ",Sens NLS fails,%ld", cv_mem->cv_nnfS); + fprintf(outfile, ",Sens NLS step fails,%ld", cv_mem->cv_ncfnS); + } + if (cv_mem->cv_ism == CV_STAGGERED1) + { + for (is = 0; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ",Sens stgr1[%i] NLS iters,%ld", is, + cv_mem->cv_nniS1[is]); + } + for (is = 0; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ",Sens stgr1[%i] NLS fails,%ld", is, + cv_mem->cv_nnfS1[is]); + } + for (is = 0; is < cv_mem->cv_Ns; is++) + { + fprintf(outfile, ",Sens stgr1[%i] NLS step fails,%ld", is, + cv_mem->cv_ncfnS1[is]); + } + } + fprintf(outfile, ",Sens LS setups,%ld", cv_mem->cv_nsetupsS); + } + + /* quadrature-sensitivity stats */ + if (cv_mem->cv_quadr_sensi) + { + fprintf(outfile, ",QuadSens fn evals,%ld", cv_mem->cv_nfQSe); + fprintf(outfile, ",QuadSens error test fails,%ld", cv_mem->cv_netfQS); + } + fprintf(outfile, "\n"); break; + default: - sprintf(name,"NONE"); + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "Invalid formatting option."); + return (CV_ILL_INPUT); } - return(name); + return (CV_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int CVodeGetUserData(void* cvode_mem, void** user_data) +{ + CVodeMem cv_mem; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); + } + + cv_mem = (CVodeMem)cvode_mem; + + *user_data = cv_mem->cv_user_data; + + return (CV_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +char* CVodeGetReturnFlagName(long int flag) +{ + char* name; + + name = (char*)malloc(24 * sizeof(char)); + + switch (flag) + { + case CV_SUCCESS: sprintf(name, "CV_SUCCESS"); break; + case CV_TSTOP_RETURN: sprintf(name, "CV_TSTOP_RETURN"); break; + case CV_ROOT_RETURN: sprintf(name, "CV_ROOT_RETURN"); break; + case CV_TOO_MUCH_WORK: sprintf(name, "CV_TOO_MUCH_WORK"); break; + case CV_TOO_MUCH_ACC: sprintf(name, "CV_TOO_MUCH_ACC"); break; + case CV_ERR_FAILURE: sprintf(name, "CV_ERR_FAILURE"); break; + case CV_CONV_FAILURE: sprintf(name, "CV_CONV_FAILURE"); break; + case CV_LINIT_FAIL: sprintf(name, "CV_LINIT_FAIL"); break; + case CV_LSETUP_FAIL: sprintf(name, "CV_LSETUP_FAIL"); break; + case CV_LSOLVE_FAIL: sprintf(name, "CV_LSOLVE_FAIL"); break; + case CV_RHSFUNC_FAIL: sprintf(name, "CV_RHSFUNC_FAIL"); break; + case CV_FIRST_RHSFUNC_ERR: sprintf(name, "CV_FIRST_RHSFUNC_ERR"); break; + case CV_REPTD_RHSFUNC_ERR: sprintf(name, "CV_REPTD_RHSFUNC_ERR"); break; + case CV_UNREC_RHSFUNC_ERR: sprintf(name, "CV_UNREC_RHSFUNC_ERR"); break; + case CV_RTFUNC_FAIL: sprintf(name, "CV_RTFUNC_FAIL"); break; + case CV_MEM_FAIL: sprintf(name, "CV_MEM_FAIL"); break; + case CV_MEM_NULL: sprintf(name, "CV_MEM_NULL"); break; + case CV_ILL_INPUT: sprintf(name, "CV_ILL_INPUT"); break; + case CV_NO_MALLOC: sprintf(name, "CV_NO_MALLOC"); break; + case CV_BAD_K: sprintf(name, "CV_BAD_K"); break; + case CV_BAD_T: sprintf(name, "CV_BAD_T"); break; + case CV_BAD_DKY: sprintf(name, "CV_BAD_DKY"); break; + case CV_NO_QUAD: sprintf(name, "CV_NO_QUAD"); break; + case CV_QRHSFUNC_FAIL: sprintf(name, "CV_QRHSFUNC_FAIL"); break; + case CV_FIRST_QRHSFUNC_ERR: sprintf(name, "CV_FIRST_QRHSFUNC_ERR"); break; + case CV_REPTD_QRHSFUNC_ERR: sprintf(name, "CV_REPTD_QRHSFUNC_ERR"); break; + case CV_UNREC_QRHSFUNC_ERR: sprintf(name, "CV_UNREC_QRHSFUNC_ERR"); break; + case CV_BAD_IS: sprintf(name, "CV_BAD_IS"); break; + case CV_NO_SENS: sprintf(name, "CV_NO_SENS"); break; + case CV_SRHSFUNC_FAIL: sprintf(name, "CV_SRHSFUNC_FAIL"); break; + case CV_FIRST_SRHSFUNC_ERR: sprintf(name, "CV_FIRST_SRHSFUNC_ERR"); break; + case CV_REPTD_SRHSFUNC_ERR: sprintf(name, "CV_REPTD_SRHSFUNC_ERR"); break; + case CV_UNREC_SRHSFUNC_ERR: sprintf(name, "CV_UNREC_SRHSFUNC_ERR"); break; + case CV_TOO_CLOSE: sprintf(name, "CV_TOO_CLOSE"); break; + case CV_NO_ADJ: sprintf(name, "CV_NO_ADJ"); break; + case CV_NO_FWD: sprintf(name, "CV_NO_FWD"); break; + case CV_NO_BCK: sprintf(name, "CV_NO_BCK"); break; + case CV_BAD_TB0: sprintf(name, "CV_BAD_TB0"); break; + case CV_REIFWD_FAIL: sprintf(name, "CV_REIFWD_FAIL"); break; + case CV_FWD_FAIL: sprintf(name, "CV_FWD_FAIL"); break; + case CV_GETY_BADT: sprintf(name, "CV_GETY_BADT"); break; + case CV_NLS_FAIL: sprintf(name, "CV_NLS_FAIL"); break; + default: sprintf(name, "NONE"); + } + + return (name); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls.c index ef368e1ad..539a69a1d 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls.c @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -23,30 +23,30 @@ #include #include #include - -#include "cvodes_impl.h" -#include "cvodes_ls_impl.h" #include #include #include #include +#include "cvodes_impl.h" +#include "cvodes_ls_impl.h" + /* Private constants */ -#define MIN_INC_MULT RCONST(1000.0) -#define MAX_DQITERS 3 /* max. number of attempts to recover in DQ J*v */ -#define ZERO RCONST(0.0) -#define PT25 RCONST(0.25) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#define MIN_INC_MULT SUN_RCONST(1000.0) +#define MAX_DQITERS 3 /* max. number of attempts to recover in DQ J*v */ +#define ZERO SUN_RCONST(0.0) +#define PT25 SUN_RCONST(0.25) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /*================================================================= PRIVATE FUNCTION PROTOTYPES - forward problems =================================================================*/ -static int cvLsLinSys(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, - booleantype jok, booleantype *jcur, realtype gamma, - void *user_data, N_Vector tmp1, N_Vector tmp2, - N_Vector tmp3); +static int cvLsLinSys(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix A, + sunbooleantype jok, sunbooleantype* jcur, + sunrealtype gamma, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); /*================================================================= PRIVATE FUNCTION PROTOTYPES - backward problems @@ -55,71 +55,66 @@ static int cvLsLinSys(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, /* cvLsJacBWrapper and cvLsJacBSWrapper have type CVLsJacFn, and wrap around user-provided functions of type CVLsJacFnB and CVLsJacFnBS, respectively */ -static int cvLsJacBWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix JB, void *cvode_mem, - N_Vector tmp1B, N_Vector tmp2B, - N_Vector tmp3B); +static int cvLsJacBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* cvode_mem, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B); -static int cvLsJacBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix JB, void *cvode_mem, - N_Vector tmp1B, N_Vector tmp2B, - N_Vector tmp3B); +static int cvLsJacBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* cvode_mem, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B); /* cvLsPrecSetupBWrapper and cvLsPrecSetupBSWrapper have type CVLsPrecSetupFn, and wrap around user-provided functions of type CVLsPrecSetupFnB and CVLsPrecSetupFnBS, respectively */ -static int cvLsPrecSetupBWrapper(realtype t, N_Vector yB, N_Vector fyB, - booleantype jokB, booleantype *jcurPtrB, - realtype gammaB, void *cvode_mem); -static int cvLsPrecSetupBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - booleantype jokB, booleantype *jcurPtrB, - realtype gammaB, void *cvode_mem); +static int cvLsPrecSetupBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + sunbooleantype jokB, sunbooleantype* jcurPtrB, + sunrealtype gammaB, void* cvode_mem); +static int cvLsPrecSetupBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + sunbooleantype jokB, sunbooleantype* jcurPtrB, + sunrealtype gammaB, void* cvode_mem); /* cvLsPrecSolveBWrapper and cvLsPrecSolveBSWrapper have type CVLsPrecSolveFn, and wrap around user-provided functions of type CVLsPrecSolveFnB and CVLsPrecSolveFnBS, respectively */ -static int cvLsPrecSolveBWrapper(realtype t, N_Vector yB, N_Vector fyB, - N_Vector rB, N_Vector zB, - realtype gammaB, realtype deltaB, - int lrB, void *cvode_mem); -static int cvLsPrecSolveBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - N_Vector rB, N_Vector zB, - realtype gammaB, realtype deltaB, - int lrB, void *cvode_mem); +static int cvLsPrecSolveBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + N_Vector rB, N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* cvode_mem); +static int cvLsPrecSolveBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + N_Vector rB, N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* cvode_mem); /* cvLsJacTimesSetupBWrapper and cvLsJacTimesSetupBSWrapper have type CVLsJacTimesSetupFn, and wrap around user-provided functions of type CVLsJacTimesSetupFnB and CVLsJacTimesSetupFnBS, respectively */ -static int cvLsJacTimesSetupBWrapper(realtype t, N_Vector yB, - N_Vector fyB, void *cvode_mem); -static int cvLsJacTimesSetupBSWrapper(realtype t, N_Vector yB, - N_Vector fyB, void *cvode_mem); +static int cvLsJacTimesSetupBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + void* cvode_mem); +static int cvLsJacTimesSetupBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + void* cvode_mem); /* cvLsJacTimesVecBWrapper and cvLsJacTimesVecBSWrapper have type CVLsJacTimesVecFn, and wrap around user-provided functions of type CVLsJacTimesVecFnB and CVLsJacTimesVecFnBS, respectively */ -static int cvLsJacTimesVecBWrapper(N_Vector vB, N_Vector JvB, realtype t, - N_Vector yB, N_Vector fyB, - void *cvode_mem, N_Vector tmpB); -static int cvLsJacTimesVecBSWrapper(N_Vector vB, N_Vector JvB, realtype t, - N_Vector yB, N_Vector fyB, - void *cvode_mem, N_Vector tmpB); +static int cvLsJacTimesVecBWrapper(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector yB, N_Vector fyB, void* cvode_mem, + N_Vector tmpB); +static int cvLsJacTimesVecBSWrapper(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector yB, N_Vector fyB, void* cvode_mem, + N_Vector tmpB); /* cvLsLinSysFnBWrapper and cvLsLinSysFnBSWrapper have type CVLsLinSysFn, and wrap around user-provided functions of type CVLsLinSysFnB and CVLsLinSysFnBS, respectively */ -static int cvLsLinSysBWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix AB, booleantype jokB, - booleantype *jcurB, realtype gammaB, - void *user_dataB, N_Vector tmp1B, N_Vector tmp2B, +static int cvLsLinSysBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* user_dataB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B); -static int cvLsLinSysBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix AB, booleantype jokB, - booleantype *jcurB, realtype gammaB, - void *user_dataB, N_Vector tmp1B, N_Vector tmp2B, +static int cvLsLinSysBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* user_dataB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3); - /*================================================================ PART I - forward problems ================================================================*/ @@ -131,35 +126,35 @@ static int cvLsLinSysBSWrapper(realtype t, N_Vector yB, N_Vector fyB, /*--------------------------------------------------------------- CVodeSetLinearSolver specifies the linear solver ---------------------------------------------------------------*/ -int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, - SUNMatrix A) +int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) { - CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval, LSType; - booleantype iterative; /* is the solver iterative? */ - booleantype matrixbased; /* is a matrix structure used? */ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval, LSType; + sunbooleantype iterative; /* is the solver iterative? */ + sunbooleantype matrixbased; /* is a matrix structure used? */ /* Return immediately if either cvode_mem or LS inputs are NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); - } - if (LS == NULL) { - cvProcessError(NULL, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetLinearSolver", + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); + } + if (LS == NULL) + { + cvProcessError(NULL, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "LS must be non-NULL"); - return(CVLS_ILL_INPUT); + return (CVLS_ILL_INPUT); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Test if solver is compatible with LS interface */ - if ( (LS->ops->gettype == NULL) || (LS->ops->solve == NULL) ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetLinearSolver", + if ((LS->ops->gettype == NULL) || (LS->ops->solve == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "LS object is missing a required operation"); - return(CVLS_ILL_INPUT); + return (CVLS_ILL_INPUT); } /* Retrieve the LS type */ @@ -171,52 +166,56 @@ int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, (LSType != SUNLINEARSOLVER_MATRIX_EMBEDDED)); /* Test if vector is compatible with LS interface */ - if ( (cv_mem->cv_tempv->ops->nvconst == NULL) || - (cv_mem->cv_tempv->ops->nvwrmsnorm == NULL) ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_BAD_NVECTOR); - return(CVLS_ILL_INPUT); + if ((cv_mem->cv_tempv->ops->nvconst == NULL) || + (cv_mem->cv_tempv->ops->nvwrmsnorm == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (CVLS_ILL_INPUT); } /* Ensure that A is NULL when LS is matrix-embedded */ - if ((LSType == SUNLINEARSOLVER_MATRIX_EMBEDDED) && (A != NULL)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVLS", "CVodeSetLinearSolver", - "Incompatible inputs: matrix-embedded LS requires NULL matrix"); - return(CVLS_ILL_INPUT); + if ((LSType == SUNLINEARSOLVER_MATRIX_EMBEDDED) && (A != NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: matrix-embedded LS requires NULL matrix"); + return (CVLS_ILL_INPUT); } /* Check for compatible LS type, matrix and "atimes" support */ - if (iterative) { - - if (cv_mem->cv_tempv->ops->nvgetlength == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_BAD_NVECTOR); - return(CVLS_ILL_INPUT); + if (iterative) + { + if (cv_mem->cv_tempv->ops->nvgetlength == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (CVLS_ILL_INPUT); } if (!matrixbased && (LSType != SUNLINEARSOLVER_MATRIX_EMBEDDED) && - (LS->ops->setatimes == NULL)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetLinearSolver", - "Incompatible inputs: iterative LS must support ATimes routine"); - return(CVLS_ILL_INPUT); + (LS->ops->setatimes == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: iterative LS must support ATimes routine"); + return (CVLS_ILL_INPUT); } - if (matrixbased && (A == NULL)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetLinearSolver", - "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); - return(CVLS_ILL_INPUT); + if (matrixbased && (A == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); + return (CVLS_ILL_INPUT); } - - } else if (A == NULL) { - - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetLinearSolver", + } + else if (A == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "Incompatible inputs: direct LS requires non-NULL matrix"); - return(CVLS_ILL_INPUT); - + return (CVLS_ILL_INPUT); } /* free any existing system solver attached to CVode */ - if (cv_mem->cv_lfree) cv_mem->cv_lfree(cv_mem); + if (cv_mem->cv_lfree) { cv_mem->cv_lfree(cv_mem); } /* Set four main system linear solver function fields in cv_mem */ cv_mem->cv_linit = cvLsInitialize; @@ -226,11 +225,12 @@ int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, /* Allocate memory for CVLsMemRec */ cvls_mem = NULL; - cvls_mem = (CVLsMem) malloc(sizeof(struct CVLsMemRec)); - if (cvls_mem == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_MEM_FAIL); - return(CVLS_MEM_FAIL); + cvls_mem = (CVLsMem)malloc(sizeof(struct CVLsMemRec)); + if (cvls_mem == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + return (CVLS_MEM_FAIL); } memset(cvls_mem, 0, sizeof(struct CVLsMemRec)); @@ -242,11 +242,14 @@ int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, cvls_mem->matrixbased = matrixbased; /* Set defaults for Jacobian-related fields */ - if (A != NULL) { + if (A != NULL) + { cvls_mem->jacDQ = SUNTRUE; cvls_mem->jac = cvLsDQJac; cvls_mem->J_data = cv_mem; - } else { + } + else + { cvls_mem->jacDQ = SUNFALSE; cvls_mem->jac = NULL; cvls_mem->J_data = NULL; @@ -272,106 +275,114 @@ int CVodeSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, cvLsInitializeCounters(cvls_mem); /* Set default values for the rest of the LS parameters */ - cvls_mem->msbj = CVLS_MSBJ; - cvls_mem->jbad = SUNTRUE; - cvls_mem->eplifac = CVLS_EPLIN; - cvls_mem->last_flag = CVLS_SUCCESS; + cvls_mem->msbj = CVLS_MSBJ; + cvls_mem->jbad = SUNTRUE; + cvls_mem->dgmax_jbad = CVLS_DGMAX; + cvls_mem->eplifac = CVLS_EPLIN; + cvls_mem->last_flag = CVLS_SUCCESS; /* If LS supports ATimes, attach CVLs routine */ - if (LS->ops->setatimes) { + if (LS->ops->setatimes) + { retval = SUNLinSolSetATimes(LS, cv_mem, cvLsATimes); - if (retval != SUNLS_SUCCESS) { - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", - "CVodeSetLinearSolver", + if (retval != SUN_SUCCESS) + { + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetATimes"); - free(cvls_mem); cvls_mem = NULL; - return(CVLS_SUNLS_FAIL); + free(cvls_mem); + cvls_mem = NULL; + return (CVLS_SUNLS_FAIL); } } /* If LS supports preconditioning, initialize pset/psol to NULL */ - if (LS->ops->setpreconditioner) { + if (LS->ops->setpreconditioner) + { retval = SUNLinSolSetPreconditioner(LS, cv_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) { - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", - "CVodeSetLinearSolver", + if (retval != SUN_SUCCESS) + { + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); - free(cvls_mem); cvls_mem = NULL; - return(CVLS_SUNLS_FAIL); + free(cvls_mem); + cvls_mem = NULL; + return (CVLS_SUNLS_FAIL); } } /* When using a SUNMatrix object, store pointer to A and initialize savedJ */ - if (A != NULL) { - cvls_mem->A = A; + if (A != NULL) + { + cvls_mem->A = A; cvls_mem->savedJ = NULL; /* allocated in cvLsInitialize */ } /* Allocate memory for ytemp and x */ cvls_mem->ytemp = N_VClone(cv_mem->cv_tempv); - if (cvls_mem->ytemp == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_MEM_FAIL); - free(cvls_mem); cvls_mem = NULL; - return(CVLS_MEM_FAIL); + if (cvls_mem->ytemp == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + free(cvls_mem); + cvls_mem = NULL; + return (CVLS_MEM_FAIL); } cvls_mem->x = N_VClone(cv_mem->cv_tempv); - if (cvls_mem->x == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSLS", - "CVodeSetLinearSolver", MSG_LS_MEM_FAIL); + if (cvls_mem->x == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); N_VDestroy(cvls_mem->ytemp); - free(cvls_mem); cvls_mem = NULL; - return(CVLS_MEM_FAIL); + free(cvls_mem); + cvls_mem = NULL; + return (CVLS_MEM_FAIL); } /* For iterative LS, compute default norm conversion factor */ - if (iterative) - cvls_mem->nrmfac = SUNRsqrt( N_VGetLength(cvls_mem->ytemp) ); + if (iterative) { cvls_mem->nrmfac = SUNRsqrt(N_VGetLength(cvls_mem->ytemp)); } /* Check if solution scaling should be enabled */ - if (matrixbased && cv_mem->cv_lmm == CV_BDF) - cvls_mem->scalesol = SUNTRUE; - else - cvls_mem->scalesol = SUNFALSE; + if (matrixbased && cv_mem->cv_lmm == CV_BDF) { cvls_mem->scalesol = SUNTRUE; } + else { cvls_mem->scalesol = SUNFALSE; } /* Attach linear solver memory to integrator memory */ cv_mem->cv_lmem = cvls_mem; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*=============================================================== - Optional input/output routines + Optional Set routines ===============================================================*/ - /* CVodeSetJacFn specifies the Jacobian function. */ -int CVodeSetJacFn(void *cvode_mem, CVLsJacFn jac) +int CVodeSetJacFn(void* cvode_mem, CVLsJacFn jac) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetJacFn", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* return with failure if jac cannot be used */ - if ((jac != NULL) && (cvls_mem->A == NULL)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetJacFn", + if ((jac != NULL) && (cvls_mem->A == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "Jacobian routine cannot be supplied for NULL SUNMatrix"); - return(CVLS_ILL_INPUT); + return (CVLS_ILL_INPUT); } /* set the Jacobian routine pointer, and update relevant flags */ - if (jac != NULL) { + if (jac != NULL) + { cvls_mem->jacDQ = SUNFALSE; cvls_mem->jac = jac; cvls_mem->J_data = cv_mem->cv_user_data; - } else { + } + else + { cvls_mem->jacDQ = SUNTRUE; cvls_mem->jac = cvLsDQJac; cvls_mem->J_data = cv_mem; @@ -382,194 +393,209 @@ int CVodeSetJacFn(void *cvode_mem, CVLsJacFn jac) cvls_mem->linsys = cvLsLinSys; cvls_mem->A_data = cv_mem; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } +/* CVodeSetDeltaGammaMaxBadJac specifies the maximum gamma ratio change + * after a NLS convergence failure with a potentially bad Jacobian. If + * |gamma/gammap-1| < dgmax_jbad then the Jacobian is marked as bad */ +int CVodeSetDeltaGammaMaxBadJac(void* cvode_mem, sunrealtype dgmax_jbad) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* Access CVLsMem structure */ + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } + + /* Set value or use default */ + if (dgmax_jbad <= ZERO) { cvls_mem->dgmax_jbad = CVLS_DGMAX; } + else { cvls_mem->dgmax_jbad = dgmax_jbad; } + + return (CVLS_SUCCESS); +} /* CVodeSetEpsLin specifies the nonlinear -> linear tolerance scale factor */ -int CVodeSetEpsLin(void *cvode_mem, realtype eplifac) +int CVodeSetEpsLin(void* cvode_mem, sunrealtype eplifac) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetEpsLin", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Check for legal eplifac */ - if(eplifac < ZERO) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetEpsLin", MSG_LS_BAD_EPLIN); - return(CVLS_ILL_INPUT); + if (eplifac < ZERO) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_EPLIN); + return (CVLS_ILL_INPUT); } cvls_mem->eplifac = (eplifac == ZERO) ? CVLS_EPLIN : eplifac; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetLSNormFactor sets or computes the factor to use when converting from the integrator tolerance to the linear solver tolerance (WRMS to L2 norm). */ -int CVodeSetLSNormFactor(void *cvode_mem, realtype nrmfac) +int CVodeSetLSNormFactor(void* cvode_mem, sunrealtype nrmfac) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetLSNormFactor", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } - if (nrmfac > ZERO) { + if (nrmfac > ZERO) + { /* user-provided factor */ cvls_mem->nrmfac = nrmfac; - } else if (nrmfac < ZERO) { + } + else if (nrmfac < ZERO) + { /* compute factor for WRMS norm with dot product */ N_VConst(ONE, cvls_mem->ytemp); cvls_mem->nrmfac = SUNRsqrt(N_VDotProd(cvls_mem->ytemp, cvls_mem->ytemp)); - } else { + } + else + { /* compute default factor for WRMS norm from vector legnth */ cvls_mem->nrmfac = SUNRsqrt(N_VGetLength(cvls_mem->ytemp)); } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetJacEvalFrequency specifies the frequency for recomputing the Jacobian matrix and/or preconditioner */ -int CVodeSetJacEvalFrequency(void *cvode_mem, long int msbj) +int CVodeSetJacEvalFrequency(void* cvode_mem, long int msbj) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; store input and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetJacEvalFrequency", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Check for legal msbj */ - if(msbj < 0) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVLS", "CVodeSetJacEvalFrequency", + if (msbj < 0) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "A negative evaluation frequency was provided."); - return(CVLS_ILL_INPUT); + return (CVLS_ILL_INPUT); } cvls_mem->msbj = (msbj == 0) ? CVLS_MSBJ : msbj; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } -/* Deprecated */ -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj) -{ - return(CVodeSetJacEvalFrequency(cvode_mem, msbj)); -} - - /* CVodeSetLinearSolutionScaling enables or disables scaling the linear solver solution to account for changes in gamma. */ -int CVodeSetLinearSolutionScaling(void *cvode_mem, booleantype onoff) +int CVodeSetLinearSolutionScaling(void* cvode_mem, sunbooleantype onoff) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; store input and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetLinearSolutionScaling", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* check for valid solver and method type */ if (!(cvls_mem->matrixbased) || cv_mem->cv_lmm != CV_BDF) - return(CVLS_ILL_INPUT); + { + return (CVLS_ILL_INPUT); + } /* set solution scaling flag */ cvls_mem->scalesol = onoff; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetPreconditioner specifies the user-supplied preconditioner setup and solve routines */ -int CVodeSetPreconditioner(void *cvode_mem, CVLsPrecSetupFn psetup, +int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn psetup, CVLsPrecSolveFn psolve) { CVodeMem cv_mem; - CVLsMem cvls_mem; - PSetupFn cvls_psetup; - PSolveFn cvls_psolve; - int retval; + CVLsMem cvls_mem; + SUNPSetupFn cvls_psetup; + SUNPSolveFn cvls_psolve; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetPreconditioner", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* store function pointers for user-supplied routines in CVLs interface */ cvls_mem->pset = psetup; cvls_mem->psolve = psolve; /* issue error if LS object does not allow user-supplied preconditioning */ - if (cvls_mem->LS->ops->setpreconditioner == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetPreconditioner", - "SUNLinearSolver object does not support user-supplied preconditioning"); - return(CVLS_ILL_INPUT); + if (cvls_mem->LS->ops->setpreconditioner == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + "SUNLinearSolver object does not support user-supplied " + "preconditioning"); + return (CVLS_ILL_INPUT); } /* notify iterative linear solver to call CVLs interface routines */ cvls_psetup = (psetup == NULL) ? NULL : cvLsPSetup; cvls_psolve = (psolve == NULL) ? NULL : cvLsPSolve; - retval = SUNLinSolSetPreconditioner(cvls_mem->LS, cv_mem, - cvls_psetup, cvls_psolve); - if (retval != SUNLS_SUCCESS) { - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", - "CVLsSetPreconditioner", + retval = SUNLinSolSetPreconditioner(cvls_mem->LS, cv_mem, cvls_psetup, + cvls_psolve); + if (retval != SUN_SUCCESS) + { + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); - return(CVLS_SUNLS_FAIL); + return (CVLS_SUNLS_FAIL); } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetJacTimes specifies the user-supplied Jacobian-vector product setup and multiply routines */ -int CVodeSetJacTimes(void *cvode_mem, CVLsJacTimesSetupFn jtsetup, +int CVodeSetJacTimes(void* cvode_mem, CVLsJacTimesSetupFn jtsetup, CVLsJacTimesVecFn jtimes) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetJacTimes", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* issue error if LS object does not allow user-supplied ATimes */ - if (cvls_mem->LS->ops->setatimes == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetJacTimes", - "SUNLinearSolver object does not support user-supplied ATimes routine"); - return(CVLS_ILL_INPUT); + if (cvls_mem->LS->ops->setatimes == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "SUNLinearSolver object does not support user-supplied ATimes routine"); + return (CVLS_ILL_INPUT); } /* store function pointers for user-supplied routines in CVLs interface (NULL jtimes implies use of DQ default) */ - if (jtimes != NULL) { + if (jtimes != NULL) + { cvls_mem->jtimesDQ = SUNFALSE; cvls_mem->jtsetup = jtsetup; cvls_mem->jtimes = jtimes; cvls_mem->jt_data = cv_mem->cv_user_data; - } else { + } + else + { cvls_mem->jtimesDQ = SUNTRUE; cvls_mem->jtsetup = NULL; cvls_mem->jtimes = cvLsDQJtimes; @@ -577,329 +603,357 @@ int CVodeSetJacTimes(void *cvode_mem, CVLsJacTimesSetupFn jtsetup, cvls_mem->jt_data = cv_mem; } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetJacTimesRhsFn specifies an alternative user-supplied ODE right-hand side function to use in the internal finite difference Jacobian-vector product */ -int CVodeSetJacTimesRhsFn(void *cvode_mem, CVRhsFn jtimesRhsFn) +int CVodeSetJacTimesRhsFn(void* cvode_mem, CVRhsFn jtimesRhsFn) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetJacTimesRhsFn", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* check if using internal finite difference approximation */ - if (!(cvls_mem->jtimesDQ)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetJacTimesRhsFn", - "Internal finite-difference Jacobian-vector product is disabled."); - return(CVLS_ILL_INPUT); + if (!(cvls_mem->jtimesDQ)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Internal finite-difference Jacobian-vector product is disabled."); + return (CVLS_ILL_INPUT); } /* store function pointers for RHS function (NULL implies use ODE RHS) */ - if (jtimesRhsFn != NULL) - cvls_mem->jt_f = jtimesRhsFn; - else - cvls_mem->jt_f = cv_mem->cv_f; + if (jtimesRhsFn != NULL) { cvls_mem->jt_f = jtimesRhsFn; } + else { cvls_mem->jt_f = cv_mem->cv_f; } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeSetLinSysFn specifies the linear system setup function. */ -int CVodeSetLinSysFn(void *cvode_mem, CVLsLinSysFn linsys) +int CVodeSetLinSysFn(void* cvode_mem, CVLsLinSysFn linsys) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeSetLinSysFn", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* return with failure if linsys cannot be used */ - if ((linsys != NULL) && (cvls_mem->A == NULL)) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "CVodeSetLinSysFn", - "Linear system setup routine cannot be supplied for NULL SUNMatrix"); - return(CVLS_ILL_INPUT); + if ((linsys != NULL) && (cvls_mem->A == NULL)) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Linear system setup routine cannot be supplied for NULL SUNMatrix"); + return (CVLS_ILL_INPUT); } /* set the linear system routine pointer, and update relevant flags */ - if (linsys != NULL) { + if (linsys != NULL) + { cvls_mem->user_linsys = SUNTRUE; cvls_mem->linsys = linsys; cvls_mem->A_data = cv_mem->cv_user_data; - } else { + } + else + { cvls_mem->user_linsys = SUNFALSE; cvls_mem->linsys = cvLsLinSys; cvls_mem->A_data = cv_mem; } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } +/*=============================================================== + Optional Get routines + ===============================================================*/ + +int CVodeGetJac(void* cvode_mem, SUNMatrix* J) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* access CVLsMem structure; set output and return */ + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return retval; } + *J = cvls_mem->savedJ; + return CVLS_SUCCESS; +} + +int CVodeGetJacTime(void* cvode_mem, sunrealtype* t_J) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* access CVLsMem structure; set output and return */ + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return retval; } + *t_J = cvls_mem->tnlj; + return CVLS_SUCCESS; +} + +int CVodeGetJacNumSteps(void* cvode_mem, long int* nst_J) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* access CVLsMem structure; set output and return */ + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return retval; } + *nst_J = cvls_mem->nstlj; + return CVLS_SUCCESS; +} /* CVodeGetLinWorkSpace returns the length of workspace allocated for the CVLS linear solver interface */ -int CVodeGetLinWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS) +int CVodeGetLinWorkSpace(void* cvode_mem, long int* lenrwLS, long int* leniwLS) { - CVodeMem cv_mem; - CVLsMem cvls_mem; + CVodeMem cv_mem; + CVLsMem cvls_mem; sunindextype lrw1, liw1; - long int lrw, liw; - int retval; + long int lrw, liw; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetLinWorkSpace", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* start with fixed sizes plus vector/matrix pointers */ *lenrwLS = 2; *leniwLS = 30; /* add NVector sizes */ - if (cv_mem->cv_tempv->ops->nvspace) { + if (cv_mem->cv_tempv->ops->nvspace) + { N_VSpace(cv_mem->cv_tempv, &lrw1, &liw1); - *lenrwLS += 2*lrw1; - *leniwLS += 2*liw1; + *lenrwLS += 2 * lrw1; + *leniwLS += 2 * liw1; } /* add SUNMatrix size (only account for the one owned by Ls interface) */ if (cvls_mem->savedJ) - if (cvls_mem->savedJ->ops->space) { + { + if (cvls_mem->savedJ->ops->space) + { retval = SUNMatSpace(cvls_mem->savedJ, &lrw, &liw); - if (retval == 0) { + if (retval == 0) + { *lenrwLS += lrw; *leniwLS += liw; } } + } /* add LS sizes */ - if (cvls_mem->LS->ops->space) { + if (cvls_mem->LS->ops->space) + { retval = SUNLinSolSpace(cvls_mem->LS, &lrw, &liw); - if (retval == 0) { + if (retval == 0) + { *lenrwLS += lrw; *leniwLS += liw; } } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumJacEvals returns the number of Jacobian evaluations */ -int CVodeGetNumJacEvals(void *cvode_mem, long int *njevals) +int CVodeGetNumJacEvals(void* cvode_mem, long int* njevals) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumJacEvals", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *njevals = cvls_mem->nje; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumLinRhsEvals returns the number of calls to the ODE function needed for the DQ Jacobian approximation or J*v product approximation */ -int CVodeGetNumLinRhsEvals(void *cvode_mem, long int *nfevalsLS) +int CVodeGetNumLinRhsEvals(void* cvode_mem, long int* nfevalsLS) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumLinRhsEvals", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *nfevalsLS = cvls_mem->nfeDQ; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumPrecEvals returns the number of calls to the user- or CVode-supplied preconditioner setup routine */ -int CVodeGetNumPrecEvals(void *cvode_mem, long int *npevals) +int CVodeGetNumPrecEvals(void* cvode_mem, long int* npevals) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumPrecEvals", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *npevals = cvls_mem->npe; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumPrecSolves returns the number of calls to the user- or CVode-supplied preconditioner solve routine */ -int CVodeGetNumPrecSolves(void *cvode_mem, long int *npsolves) +int CVodeGetNumPrecSolves(void* cvode_mem, long int* npsolves) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumPrecSolves", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *npsolves = cvls_mem->nps; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumLinIters returns the number of linear iterations (if accessible from the LS object) */ -int CVodeGetNumLinIters(void *cvode_mem, long int *nliters) +int CVodeGetNumLinIters(void* cvode_mem, long int* nliters) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumLinIters", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *nliters = cvls_mem->nli; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumLinConvFails returns the number of linear solver convergence failures (as reported by the LS object) */ -int CVodeGetNumLinConvFails(void *cvode_mem, long int *nlcfails) +int CVodeGetNumLinConvFails(void* cvode_mem, long int* nlcfails) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumLinConvFails", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *nlcfails = cvls_mem->ncfl; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumJTSetupEvals returns the number of calls to the user-supplied Jacobian-vector product setup routine */ -int CVodeGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups) +int CVodeGetNumJTSetupEvals(void* cvode_mem, long int* njtsetups) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumJTSetupEvals", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *njtsetups = cvls_mem->njtsetup; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetNumJtimesEvals returns the number of calls to the Jacobian-vector product multiply routine */ -int CVodeGetNumJtimesEvals(void *cvode_mem, long int *njvevals) +int CVodeGetNumJtimesEvals(void* cvode_mem, long int* njvevals) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetNumJtimesEvals", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *njvevals = cvls_mem->njtimes; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } +/* CVodeGetLinSolveStats returns statistics related to the linear solve. */ +int CVodeGetLinSolveStats(void* cvode_mem, long int* njevals, long int* nfevalsLS, + long int* nliters, long int* nlcfails, + long int* npevals, long int* npsolves, + long int* njtsetups, long int* njtimes) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* access CVLsMem structure; set output value and return */ + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } + + *njevals = cvls_mem->nje; + *nfevalsLS = cvls_mem->nfeDQ; + *nliters = cvls_mem->nli; + *nlcfails = cvls_mem->ncfl; + *npevals = cvls_mem->npe; + *npsolves = cvls_mem->nps; + *njtsetups = cvls_mem->njtsetup; + *njtimes = cvls_mem->njtimes; + + return (CVLS_SUCCESS); +} /* CVodeGetLastLinFlag returns the last flag set in a CVLS function */ -int CVodeGetLastLinFlag(void *cvode_mem, long int *flag) +int CVodeGetLastLinFlag(void* cvode_mem, long int* flag) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure; set output value and return */ - retval = cvLs_AccessLMem(cvode_mem, "CVodeGetLastLinFlag", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } *flag = cvls_mem->last_flag; - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* CVodeGetLinReturnFlagName translates from the integer error code returned by an CVLs routine to the corresponding string equivalent for that flag */ -char *CVodeGetLinReturnFlagName(long int flag) +char* CVodeGetLinReturnFlagName(long int flag) { - char *name = (char *)malloc(30*sizeof(char)); + char* name = (char*)malloc(30 * sizeof(char)); - switch(flag) { - case CVLS_SUCCESS: - sprintf(name,"CVLS_SUCCESS"); - break; - case CVLS_MEM_NULL: - sprintf(name,"CVLS_MEM_NULL"); - break; - case CVLS_LMEM_NULL: - sprintf(name,"CVLS_LMEM_NULL"); - break; - case CVLS_ILL_INPUT: - sprintf(name,"CVLS_ILL_INPUT"); - break; - case CVLS_MEM_FAIL: - sprintf(name,"CVLS_MEM_FAIL"); - break; - case CVLS_PMEM_NULL: - sprintf(name,"CVLS_PMEM_NULL"); - break; - case CVLS_JACFUNC_UNRECVR: - sprintf(name,"CVLS_JACFUNC_UNRECVR"); - break; - case CVLS_JACFUNC_RECVR: - sprintf(name,"CVLS_JACFUNC_RECVR"); - break; - case CVLS_SUNMAT_FAIL: - sprintf(name,"CVLS_SUNMAT_FAIL"); - break; - case CVLS_SUNLS_FAIL: - sprintf(name,"CVLS_SUNLS_FAIL"); - break; - case CVLS_NO_ADJ: - sprintf(name,"CVLS_NO_ADJ"); - break; - case CVLS_LMEMB_NULL: - sprintf(name,"CVLS_LMEMB_NULL"); - break; - default: - sprintf(name,"NONE"); + switch (flag) + { + case CVLS_SUCCESS: sprintf(name, "CVLS_SUCCESS"); break; + case CVLS_MEM_NULL: sprintf(name, "CVLS_MEM_NULL"); break; + case CVLS_LMEM_NULL: sprintf(name, "CVLS_LMEM_NULL"); break; + case CVLS_ILL_INPUT: sprintf(name, "CVLS_ILL_INPUT"); break; + case CVLS_MEM_FAIL: sprintf(name, "CVLS_MEM_FAIL"); break; + case CVLS_PMEM_NULL: sprintf(name, "CVLS_PMEM_NULL"); break; + case CVLS_JACFUNC_UNRECVR: sprintf(name, "CVLS_JACFUNC_UNRECVR"); break; + case CVLS_JACFUNC_RECVR: sprintf(name, "CVLS_JACFUNC_RECVR"); break; + case CVLS_SUNMAT_FAIL: sprintf(name, "CVLS_SUNMAT_FAIL"); break; + case CVLS_SUNLS_FAIL: sprintf(name, "CVLS_SUNLS_FAIL"); break; + case CVLS_NO_ADJ: sprintf(name, "CVLS_NO_ADJ"); break; + case CVLS_LMEMB_NULL: sprintf(name, "CVLS_LMEMB_NULL"); break; + default: sprintf(name, "NONE"); } - return(name); + return (name); } - /*================================================================= CVSLS private functions =================================================================*/ @@ -913,34 +967,29 @@ char *CVodeGetLinReturnFlagName(long int flag) The return value is the same as the value returned by jtimes -- 0 if successful, nonzero otherwise. -----------------------------------------------------------------*/ -int cvLsATimes(void *cvode_mem, N_Vector v, N_Vector z) +int cvLsATimes(void* cvode_mem, N_Vector v, N_Vector z) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "cvLsATimes", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* call Jacobian-times-vector product routine (either user-supplied or internal DQ) */ - retval = cvls_mem->jtimes(v, z, cv_mem->cv_tn, - cvls_mem->ycur, - cvls_mem->fcur, - cvls_mem->jt_data, - cvls_mem->ytemp); + retval = cvls_mem->jtimes(v, z, cv_mem->cv_tn, cvls_mem->ycur, cvls_mem->fcur, + cvls_mem->jt_data, cvls_mem->ytemp); cvls_mem->njtimes++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* add contribution from identity matrix */ N_VLinearSum(ONE, v, -cv_mem->cv_gamma, z, z); - return(0); + return (0); } - /*--------------------------------------------------------------- cvLsPSetup: @@ -951,27 +1000,24 @@ int cvLsATimes(void *cvode_mem, N_Vector v, N_Vector z) iterative linear solvers guarantee that cvLsPSetup will only be called in the case that the user's psetup routine is non-NULL. ---------------------------------------------------------------*/ -int cvLsPSetup(void *cvode_mem) +int cvLsPSetup(void* cvode_mem) { - int retval; + int retval; CVodeMem cv_mem; - CVLsMem cvls_mem; + CVLsMem cvls_mem; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "cvLsPSetup", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Call user pset routine to update preconditioner and possibly reset jcur (pass !jbad as update suggestion) */ - retval = cvls_mem->pset(cv_mem->cv_tn, cvls_mem->ycur, - cvls_mem->fcur, !(cvls_mem->jbad), - &cv_mem->cv_jcur, cv_mem->cv_gamma, + retval = cvls_mem->pset(cv_mem->cv_tn, cvls_mem->ycur, cvls_mem->fcur, + !(cvls_mem->jbad), &cv_mem->cv_jcur, cv_mem->cv_gamma, cvls_mem->P_data); - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvLsPSolve @@ -984,27 +1030,23 @@ int cvLsPSetup(void *cvode_mem) only case in which the user's psolve routine is allowed to be NULL. -----------------------------------------------------------------*/ -int cvLsPSolve(void *cvode_mem, N_Vector r, N_Vector z, realtype tol, int lr) +int cvLsPSolve(void* cvode_mem, N_Vector r, N_Vector z, sunrealtype tol, int lr) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "cvLsPSolve", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* call the user-supplied psolve routine, and accumulate count */ - retval = cvls_mem->psolve(cv_mem->cv_tn, cvls_mem->ycur, - cvls_mem->fcur, r, z, - cv_mem->cv_gamma, tol, lr, - cvls_mem->P_data); + retval = cvls_mem->psolve(cv_mem->cv_tn, cvls_mem->ycur, cvls_mem->fcur, r, z, + cv_mem->cv_gamma, tol, lr, cvls_mem->P_data); cvls_mem->nps++; - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvLsDQJac @@ -1012,26 +1054,28 @@ int cvLsPSolve(void *cvode_mem, N_Vector r, N_Vector z, realtype tol, int lr) implementations of the difference quotient Jacobian approximation routines. ---------------------------------------------------------------*/ -int cvLsDQJac(realtype t, N_Vector y, N_Vector fy, - SUNMatrix Jac, void *cvode_mem, N_Vector tmp1, - N_Vector tmp2, N_Vector tmp3) +int cvLsDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + void* cvode_mem, N_Vector tmp1, N_Vector tmp2, + SUNDIALS_MAYBE_UNUSED N_Vector tmp3) { CVodeMem cv_mem; - int retval; + int retval; /* access CVodeMem structure */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - "cvLsDQJac", MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* verify that Jac is non-NULL */ - if (Jac == NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSLS", - "cvLsDQJac", MSG_LS_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (Jac == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (CVLS_LMEM_NULL); } /* Verify that N_Vector supports required operations */ @@ -1041,26 +1085,31 @@ int cvLsDQJac(realtype t, N_Vector y, N_Vector fy, cv_mem->cv_tempv->ops->nvdestroy == NULL || cv_mem->cv_tempv->ops->nvscale == NULL || cv_mem->cv_tempv->ops->nvgetarraypointer == NULL || - cv_mem->cv_tempv->ops->nvsetarraypointer == NULL) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "cvLsDQJac", MSG_LS_BAD_NVECTOR); - return(CVLS_ILL_INPUT); + cv_mem->cv_tempv->ops->nvsetarraypointer == NULL) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (CVLS_ILL_INPUT); } /* Call the matrix-structure-specific DQ approximation routine */ - if (SUNMatGetID(Jac) == SUNMATRIX_DENSE) { + if (SUNMatGetID(Jac) == SUNMATRIX_DENSE) + { retval = cvLsDenseDQJac(t, y, fy, Jac, cv_mem, tmp1); - } else if (SUNMatGetID(Jac) == SUNMATRIX_BAND) { + } + else if (SUNMatGetID(Jac) == SUNMATRIX_BAND) + { retval = cvLsBandDQJac(t, y, fy, Jac, cv_mem, tmp1, tmp2); - } else { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "cvLsDQJac", + } + else + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, "unrecognized matrix type for cvLsDQJac"); retval = CVLS_ILL_INPUT; } - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvLsDenseDQJac @@ -1073,11 +1122,11 @@ int cvLsDQJac(realtype t, N_Vector y, N_Vector fy, function. Finally, the actual computation of the jth column of the Jacobian is done with a call to N_VLinearSum. -----------------------------------------------------------------*/ -int cvLsDenseDQJac(realtype t, N_Vector y, N_Vector fy, - SUNMatrix Jac, CVodeMem cv_mem, N_Vector tmp1) +int cvLsDenseDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + CVodeMem cv_mem, N_Vector tmp1) { - realtype fnorm, minInc, inc, inc_inv, yjsaved, srur, conj; - realtype *y_data, *ewt_data, *cns_data; + sunrealtype fnorm, minInc, inc, inc_inv, yjsaved, srur, conj; + sunrealtype *y_data, *ewt_data, *cns_data; N_Vector ftemp, jthCol; sunindextype j, N; CVLsMem cvls_mem; @@ -1087,7 +1136,7 @@ int cvLsDenseDQJac(realtype t, N_Vector y, N_Vector fy, cns_data = NULL; /* access LsMem interface structure */ - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* access matrix dimension */ N = SUNDenseMatrix_Columns(Jac); @@ -1102,50 +1151,58 @@ int cvLsDenseDQJac(realtype t, N_Vector y, N_Vector fy, ewt_data = N_VGetArrayPointer(cv_mem->cv_ewt); y_data = N_VGetArrayPointer(y); if (cv_mem->cv_constraintsSet) + { cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + } /* Set minimum increment based on uround and norm of f */ - srur = SUNRsqrt(cv_mem->cv_uround); - fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); - minInc = (fnorm != ZERO) ? - (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * cv_mem->cv_uround * N * fnorm) : ONE; - - for (j = 0; j < N; j++) { - + srur = SUNRsqrt(cv_mem->cv_uround); + fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); + minInc = (fnorm != ZERO) ? (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * + cv_mem->cv_uround * N * fnorm) + : ONE; + + for (j = 0; j < N; j++) + { /* Generate the jth col of J(tn,y) */ - N_VSetArrayPointer(SUNDenseMatrix_Column(Jac,j), jthCol); + N_VSetArrayPointer(SUNDenseMatrix_Column(Jac, j), jthCol); yjsaved = y_data[j]; - inc = SUNMAX(srur*SUNRabs(yjsaved), minInc/ewt_data[j]); + inc = SUNMAX(srur * SUNRabs(yjsaved), minInc / ewt_data[j]); /* Adjust sign(inc) if y_j has an inequality constraint. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((yjsaved+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yjsaved+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yjsaved + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yjsaved + inc) * conj <= ZERO) { inc = -inc; } + } } y_data[j] += inc; retval = cv_mem->cv_f(t, y, ftemp, cv_mem->cv_user_data); cvls_mem->nfeDQ++; - if (retval != 0) break; + if (retval != 0) { break; } y_data[j] = yjsaved; - inc_inv = ONE/inc; + inc_inv = ONE / inc; N_VLinearSum(inc_inv, ftemp, -inc_inv, fy, jthCol); - } /* Destroy jthCol vector */ - N_VSetArrayPointer(NULL, jthCol); /* SHOULDN'T BE NEEDED */ + N_VSetArrayPointer(NULL, jthCol); /* SHOULDN'T BE NEEDED */ N_VDestroy(jthCol); - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvLsBandDQJac @@ -1157,13 +1214,13 @@ int cvLsDenseDQJac(realtype t, N_Vector y, N_Vector fy, a simple for loop to set each of the elements of a column in succession. -----------------------------------------------------------------*/ -int cvLsBandDQJac(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, +int cvLsBandDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, CVodeMem cv_mem, N_Vector tmp1, N_Vector tmp2) { N_Vector ftemp, ytemp; - realtype fnorm, minInc, inc, inc_inv, srur, conj; - realtype *col_j, *ewt_data, *fy_data, *ftemp_data; - realtype *y_data, *ytemp_data, *cns_data; + sunrealtype fnorm, minInc, inc, inc_inv, srur, conj; + sunrealtype *col_j, *ewt_data, *fy_data, *ftemp_data; + sunrealtype *y_data, *ytemp_data, *cns_data; sunindextype group, i, j, width, ngroups, i1, i2; sunindextype N, mupper, mlower; CVLsMem cvls_mem; @@ -1173,10 +1230,10 @@ int cvLsBandDQJac(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, cns_data = NULL; /* access LsMem interface structure */ - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* access matrix dimensions */ - N = SUNBandMatrix_Columns(Jac); + N = SUNBandMatrix_Columns(Jac); mupper = SUNBandMatrix_UpperBandwidth(Jac); mlower = SUNBandMatrix_LowerBandwidth(Jac); @@ -1191,68 +1248,88 @@ int cvLsBandDQJac(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, y_data = N_VGetArrayPointer(y); ytemp_data = N_VGetArrayPointer(ytemp); if (cv_mem->cv_constraintsSet) + { cns_data = N_VGetArrayPointer(cv_mem->cv_constraints); + } /* Load ytemp with y = predicted y vector */ N_VScale(ONE, y, ytemp); /* Set minimum increment based on uround and norm of f */ - srur = SUNRsqrt(cv_mem->cv_uround); - fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); - minInc = (fnorm != ZERO) ? - (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * cv_mem->cv_uround * N * fnorm) : ONE; + srur = SUNRsqrt(cv_mem->cv_uround); + fnorm = N_VWrmsNorm(fy, cv_mem->cv_ewt); + minInc = (fnorm != ZERO) ? (MIN_INC_MULT * SUNRabs(cv_mem->cv_h) * + cv_mem->cv_uround * N * fnorm) + : ONE; /* Set bandwidth and number of column groups for band differencing */ - width = mlower + mupper + 1; + width = mlower + mupper + 1; ngroups = SUNMIN(width, N); /* Loop over column groups. */ - for (group=1; group <= ngroups; group++) { - + for (group = 1; group <= ngroups; group++) + { /* Increment all y_j in group */ - for(j=group-1; j < N; j+=width) { - inc = SUNMAX(srur*SUNRabs(y_data[j]), minInc/ewt_data[j]); + for (j = group - 1; j < N; j += width) + { + inc = SUNMAX(srur * SUNRabs(y_data[j]), minInc / ewt_data[j]); /* Adjust sign(inc) if yj has an inequality constraint. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((ytemp_data[j]+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((ytemp_data[j]+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((ytemp_data[j] + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((ytemp_data[j] + inc) * conj <= ZERO) { inc = -inc; } + } } ytemp_data[j] += inc; } /* Evaluate f with incremented y */ - retval = cv_mem->cv_f(cv_mem->cv_tn, ytemp, ftemp, cv_mem->cv_user_data); + retval = cv_mem->cv_f(t, ytemp, ftemp, cv_mem->cv_user_data); cvls_mem->nfeDQ++; - if (retval != 0) break; + if (retval != 0) { break; } /* Restore ytemp, then form and load difference quotients */ - for (j=group-1; j < N; j+=width) { + for (j = group - 1; j < N; j += width) + { ytemp_data[j] = y_data[j]; - col_j = SUNBandMatrix_Column(Jac, j); - inc = SUNMAX(srur*SUNRabs(y_data[j]), minInc/ewt_data[j]); + col_j = SUNBandMatrix_Column(Jac, j); + inc = SUNMAX(srur * SUNRabs(y_data[j]), minInc / ewt_data[j]); /* Adjust sign(inc) as before. */ - if (cv_mem->cv_constraintsSet) { + if (cv_mem->cv_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if ((ytemp_data[j]+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((ytemp_data[j]+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((ytemp_data[j] + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((ytemp_data[j] + inc) * conj <= ZERO) { inc = -inc; } + } } - inc_inv = ONE/inc; - i1 = SUNMAX(0, j-mupper); - i2 = SUNMIN(j+mlower, N-1); - for (i=i1; i <= i2; i++) - SM_COLUMN_ELEMENT_B(col_j,i,j) = inc_inv * (ftemp_data[i] - fy_data[i]); + inc_inv = ONE / inc; + i1 = SUNMAX(0, j - mupper); + i2 = SUNMIN(j + mlower, N - 1); + for (i = i1; i <= i2; i++) + { + SM_COLUMN_ELEMENT_B(col_j, i, j) = inc_inv * (ftemp_data[i] - fy_data[i]); + } } } - return(retval); + return (retval); } - /*----------------------------------------------------------------- cvLsDQJtimes @@ -1261,137 +1338,137 @@ int cvLsBandDQJac(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, Jv = [f(y + v*sig) - f(y)]/sig, where sig = 1 / ||v||_WRMS, i.e. the WRMS norm of v*sig is 1. -----------------------------------------------------------------*/ -int cvLsDQJtimes(N_Vector v, N_Vector Jv, realtype t, - N_Vector y, N_Vector fy, void *cvode_mem, - N_Vector work) +int cvLsDQJtimes(N_Vector v, N_Vector Jv, sunrealtype t, N_Vector y, + N_Vector fy, void* cvode_mem, N_Vector work) { CVodeMem cv_mem; - CVLsMem cvls_mem; - realtype sig, siginv; - int iter, retval; + CVLsMem cvls_mem; + sunrealtype sig, siginv; + int iter, retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "cvLsDQJtimes", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Initialize perturbation to 1/||v|| */ - sig = ONE/N_VWrmsNorm(v, cv_mem->cv_ewt); - - for (iter=0; itercv_ewt); + for (iter = 0; iter < MAX_DQITERS; iter++) + { /* Set work = y + sig*v */ N_VLinearSum(sig, v, ONE, y, work); /* Set Jv = f(tn, y+sig*v) */ retval = cvls_mem->jt_f(t, work, Jv, cv_mem->cv_user_data); cvls_mem->nfeDQ++; - if (retval == 0) break; - if (retval < 0) return(-1); + if (retval == 0) { break; } + if (retval < 0) { return (-1); } /* If f failed recoverably, shrink sig and retry */ sig *= PT25; } /* If retval still isn't 0, return with a recoverable failure */ - if (retval > 0) return(+1); + if (retval > 0) { return (+1); } /* Replace Jv by (Jv - fy)/sig */ - siginv = ONE/sig; + siginv = ONE / sig; N_VLinearSum(siginv, Jv, -siginv, fy, Jv); - return(0); + return (0); } - /*----------------------------------------------------------------- cvLsLinSys Setup the linear system A = I - gamma J -----------------------------------------------------------------*/ -static int cvLsLinSys(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, - booleantype jok, booleantype *jcur, realtype gamma, - void *cvode_mem, N_Vector vtemp1, N_Vector vtemp2, - N_Vector vtemp3) +static int cvLsLinSys(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix A, + sunbooleantype jok, sunbooleantype* jcur, + sunrealtype gamma, void* cvode_mem, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3) { CVodeMem cv_mem; - CVLsMem cvls_mem; - int retval; + CVLsMem cvls_mem; + int retval; /* access CVLsMem structure */ - retval = cvLs_AccessLMem(cvode_mem, "cvLsLinSys", - &cv_mem, &cvls_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMem(cvode_mem, __func__, &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Check if Jacobian needs to be updated */ - if (jok) { - + if (jok) + { /* Use saved copy of J */ *jcur = SUNFALSE; /* Overwrite linear system matrix with saved J */ retval = SUNMatCopy(cvls_mem->savedJ, A); - if (retval) { - cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, "CVSLS", - "cvLsSetup", MSG_LS_SUNMAT_FAILED); + if (retval) + { + cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_SUNMAT_FAILED); cvls_mem->last_flag = CVLS_SUNMAT_FAIL; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - - } else { - + } + else + { /* Call jac() routine to update J */ *jcur = SUNTRUE; /* Clear the linear system matrix if necessary */ - if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_DIRECT) { + if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_DIRECT) + { retval = SUNMatZero(A); - if (retval) { - cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, "CVSLS", - "cvLsSetup", MSG_LS_SUNMAT_FAILED); + if (retval) + { + cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_SUNMAT_FAILED); cvls_mem->last_flag = CVLS_SUNMAT_FAIL; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } } /* Compute new Jacobian matrix */ - retval = cvls_mem->jac(t, y, fy, A, cvls_mem->J_data, - vtemp1, vtemp2, vtemp3); - if (retval < 0) { - cvProcessError(cv_mem, CVLS_JACFUNC_UNRECVR, "CVSLS", - "cvLsSetup", MSG_LS_JACFUNC_FAILED); + retval = cvls_mem->jac(t, y, fy, A, cvls_mem->J_data, vtemp1, vtemp2, vtemp3); + if (retval < 0) + { + cvProcessError(cv_mem, CVLS_JACFUNC_UNRECVR, __LINE__, __func__, __FILE__, + MSG_LS_JACFUNC_FAILED); cvls_mem->last_flag = CVLS_JACFUNC_UNRECVR; - return(-1); + return (-1); } - if (retval > 0) { + if (retval > 0) + { cvls_mem->last_flag = CVLS_JACFUNC_RECVR; - return(1); + return (1); } /* Update saved copy of the Jacobian matrix */ retval = SUNMatCopy(A, cvls_mem->savedJ); - if (retval) { - cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, "CVSLS", - "cvLsSetup", MSG_LS_SUNMAT_FAILED); + if (retval) + { + cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_SUNMAT_FAILED); cvls_mem->last_flag = CVLS_SUNMAT_FAIL; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - } /* Perform linear combination A = I - gamma*J */ retval = SUNMatScaleAddI(-gamma, A); - if (retval) { - cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, "CVSLS", - "cvLsSetup", MSG_LS_SUNMAT_FAILED); + if (retval) + { + cvProcessError(cv_mem, CVLS_SUNMAT_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_SUNMAT_FAILED); cvls_mem->last_flag = CVLS_SUNMAT_FAIL; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*----------------------------------------------------------------- cvLsInitialize @@ -1401,80 +1478,81 @@ static int cvLsLinSys(realtype t, N_Vector y, N_Vector fy, SUNMatrix A, int cvLsInitialize(CVodeMem cv_mem) { CVLsMem cvls_mem; - int retval; + int retval; /* access CVLsMem structure */ - if (cv_mem->cv_lmem==NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSLS", - "cvLsInitialize", MSG_LS_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Test for valid combinations of matrix & Jacobian routines: */ - if (cvls_mem->A != NULL) { - + if (cvls_mem->A != NULL) + { /* Matrix-based case */ - if (cvls_mem->user_linsys) { - + if (cvls_mem->user_linsys) + { /* User-supplied linear system function, reset A_data (just in case) */ cvls_mem->A_data = cv_mem->cv_user_data; - - } else { - + } + else + { /* Internal linear system function, reset pointers (just in case) */ cvls_mem->linsys = cvLsLinSys; cvls_mem->A_data = cv_mem; /* Check if an internal or user-supplied Jacobian function is used */ - if (cvls_mem->jacDQ) { - + if (cvls_mem->jacDQ) + { /* Internal difference quotient Jacobian. Check that A is dense or band, otherwise return an error */ retval = 0; - if (cvls_mem->A->ops->getid) { - - if ( (SUNMatGetID(cvls_mem->A) == SUNMATRIX_DENSE) || - (SUNMatGetID(cvls_mem->A) == SUNMATRIX_BAND) ) { + if (cvls_mem->A->ops->getid) + { + if ((SUNMatGetID(cvls_mem->A) == SUNMATRIX_DENSE) || + (SUNMatGetID(cvls_mem->A) == SUNMATRIX_BAND)) + { cvls_mem->jac = cvLsDQJac; cvls_mem->J_data = cv_mem; - } else { - retval++; } - - } else { - retval++; + else { retval++; } } - if (retval) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", "cvLsInitialize", - "No Jacobian constructor available for SUNMatrix type"); + else { retval++; } + if (retval) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "No Jacobian constructor available for SUNMatrix type"); cvls_mem->last_flag = CVLS_ILL_INPUT; - return(CVLS_ILL_INPUT); + return (CVLS_ILL_INPUT); } - - } else { - + } + else + { /* User-supplied Jacobian, reset J_data pointer (just in case) */ cvls_mem->J_data = cv_mem->cv_user_data; - } /* Allocate internally saved Jacobian if not already done */ - if (cvls_mem->savedJ == NULL) { + if (cvls_mem->savedJ == NULL) + { cvls_mem->savedJ = SUNMatClone(cvls_mem->A); - if (cvls_mem->savedJ == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSLS", "cvLsInitialize", + if (cvls_mem->savedJ == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSG_LS_MEM_FAIL); cvls_mem->last_flag = CVLS_MEM_FAIL; - return(CVLS_MEM_FAIL); + return (CVLS_MEM_FAIL); } } } /* end matrix-based case */ - - } else { - + } + else + { /* Matrix-free case: ensure 'jac' and `linsys` function pointers are NULL */ cvls_mem->jacDQ = SUNFALSE; cvls_mem->jac = NULL; @@ -1483,38 +1561,39 @@ int cvLsInitialize(CVodeMem cv_mem) cvls_mem->user_linsys = SUNFALSE; cvls_mem->linsys = NULL; cvls_mem->A_data = NULL; - } /* reset counters */ cvLsInitializeCounters(cvls_mem); /* Set Jacobian-vector product related fields, based on jtimesDQ */ - if (cvls_mem->jtimesDQ) { + if (cvls_mem->jtimesDQ) + { cvls_mem->jtsetup = NULL; cvls_mem->jtimes = cvLsDQJtimes; cvls_mem->jt_data = cv_mem; - } else { - cvls_mem->jt_data = cv_mem->cv_user_data; } + else { cvls_mem->jt_data = cv_mem->cv_user_data; } /* if A is NULL and psetup is not present, then cvLsSetup does not need to be called, so set the lsetup function to NULL */ - if ( (cvls_mem->A == NULL) && (cvls_mem->pset == NULL) ) + if ((cvls_mem->A == NULL) && (cvls_mem->pset == NULL)) + { cv_mem->cv_lsetup = NULL; + } /* When using a matrix-embedded linear solver, disable lsetup call and solution scaling */ - if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) { - cv_mem->cv_lsetup = NULL; + if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) + { + cv_mem->cv_lsetup = NULL; cvls_mem->scalesol = SUNFALSE; } /* Call LS initialize routine, and return result */ cvls_mem->last_flag = SUNLinSolInitialize(cvls_mem->LS); - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - /*----------------------------------------------------------------- cvLsSetup @@ -1529,26 +1608,28 @@ int cvLsInitialize(CVodeMem cv_mem) This routine then calls the LS 'setup' routine with A. -----------------------------------------------------------------*/ -int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) +int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, N_Vector fpred, + sunbooleantype* jcurPtr, N_Vector vtemp1, N_Vector vtemp2, + N_Vector vtemp3) { - CVLsMem cvls_mem; - realtype dgamma; - int retval; + CVLsMem cvls_mem; + sunrealtype dgamma; + int retval; /* access CVLsMem structure */ - if (cv_mem->cv_lmem==NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSLS", - "cvLsSetup", MSG_LS_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Immediately return when using matrix-embedded linear solver */ - if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) { + if (SUNLinSolGetType(cvls_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) + { cvls_mem->last_flag = CVLS_SUCCESS; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } /* Set CVLs N_Vector pointers to current solution and rhs */ @@ -1556,48 +1637,54 @@ int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, cvls_mem->fcur = fpred; /* Use nst, gamma/gammap, and convfail to set J/P eval. flag jok */ - dgamma = SUNRabs((cv_mem->cv_gamma/cv_mem->cv_gammap) - ONE); + dgamma = SUNRabs((cv_mem->cv_gamma / cv_mem->cv_gammap) - ONE); cvls_mem->jbad = (cv_mem->cv_nst == 0) || - (cv_mem->cv_nst >= cvls_mem->nstlj + cvls_mem->msbj) || - ((convfail == CV_FAIL_BAD_J) && (dgamma < CVLS_DGMAX)) || - (convfail == CV_FAIL_OTHER); + (cv_mem->cv_nst >= cvls_mem->nstlj + cvls_mem->msbj) || + ((convfail == CV_FAIL_BAD_J) && + (dgamma < cvls_mem->dgmax_jbad)) || + (convfail == CV_FAIL_OTHER); /* Setup the linear system if necessary */ - if (cvls_mem->A != NULL) { - + if (cvls_mem->A != NULL) + { /* Update J if appropriate and evaluate A = I - gamma J */ retval = cvls_mem->linsys(cv_mem->cv_tn, ypred, fpred, cvls_mem->A, !(cvls_mem->jbad), jcurPtr, cv_mem->cv_gamma, cvls_mem->A_data, vtemp1, vtemp2, vtemp3); /* Update J eval count and step when J was last updated */ - if (*jcurPtr) { + if (*jcurPtr) + { cvls_mem->nje++; cvls_mem->nstlj = cv_mem->cv_nst; + cvls_mem->tnlj = cv_mem->cv_tn; } /* Check linsys() return value and return if necessary */ - if (retval != CVLS_SUCCESS) { - if (cvls_mem->user_linsys) { - if (retval < 0) { - cvProcessError(cv_mem, CVLS_JACFUNC_UNRECVR, "CVSLS", - "cvLsSetup", MSG_LS_JACFUNC_FAILED); + if (retval != CVLS_SUCCESS) + { + if (cvls_mem->user_linsys) + { + if (retval < 0) + { + cvProcessError(cv_mem, CVLS_JACFUNC_UNRECVR, __LINE__, __func__, + __FILE__, MSG_LS_JACFUNC_FAILED); cvls_mem->last_flag = CVLS_JACFUNC_UNRECVR; - return(-1); - } else { + return (-1); + } + else + { cvls_mem->last_flag = CVLS_JACFUNC_RECVR; - return(1); + return (1); } - } else { - return(retval); } + else { return (retval); } } - - } else { - + } + else + { /* Matrix-free case, set jcur to jbad */ *jcurPtr = cvls_mem->jbad; - } /* Call LS setup routine -- the LS may call cvLsPSetup, who will @@ -1605,22 +1692,23 @@ int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, cvls_mem->last_flag = SUNLinSolSetup(cvls_mem->LS, cvls_mem->A); /* If Matrix-free, update heuristics flags */ - if (cvls_mem->A == NULL) { - + if (cvls_mem->A == NULL) + { /* If user set jcur to SUNTRUE, increment npe and save nst value */ - if (*jcurPtr) { + if (*jcurPtr) + { cvls_mem->npe++; cvls_mem->nstlj = cv_mem->cv_nst; + cvls_mem->tnlj = cv_mem->cv_tn; } /* Update jcur flag if we suggested an update */ - if (cvls_mem->jbad) *jcurPtr = SUNTRUE; + if (cvls_mem->jbad) { *jcurPtr = SUNTRUE; } } - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - /*----------------------------------------------------------------- cvLsSolve @@ -1629,53 +1717,65 @@ int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, and scaling vectors, calling the solver, and accumulating statistics from the solve for use/reporting by CVode. -----------------------------------------------------------------*/ -int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, - N_Vector ynow, N_Vector fnow) +int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, + N_Vector fnow) { - CVLsMem cvls_mem; - realtype bnorm, deltar, delta, w_mean; - int curiter, nli_inc, retval; - booleantype do_sensi_sim, do_sensi_stg, do_sensi_stg1; + CVLsMem cvls_mem; + sunrealtype bnorm = ZERO; + sunrealtype deltar, delta, w_mean; + int curiter, nli_inc, retval; + sunbooleantype do_sensi_sim, do_sensi_stg, do_sensi_stg1; +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + sunrealtype resnorm; + long int nps_inc; +#endif /* access CVLsMem structure */ - if (cv_mem->cv_lmem==NULL) { - cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSLS", - "cvLsSolve", MSG_LS_LMEM_NULL); - return(CVLS_LMEM_NULL); + if (cv_mem->cv_lmem == NULL) + { + cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (CVLS_LMEM_NULL); } - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* are we computing sensitivities and with which approach? */ - do_sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_SIMULTANEOUS)); - do_sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED)); - do_sensi_stg1 = (cv_mem->cv_sensi && (cv_mem->cv_ism==CV_STAGGERED1)); + do_sensi_sim = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_SIMULTANEOUS)); + do_sensi_stg = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED)); + do_sensi_stg1 = (cv_mem->cv_sensi && (cv_mem->cv_ism == CV_STAGGERED1)); /* get current nonlinear solver iteration */ if (do_sensi_sim) + { retval = SUNNonlinSolGetCurIter(cv_mem->NLSsim, &curiter); + } else if (do_sensi_stg && cv_mem->sens_solve) + { retval = SUNNonlinSolGetCurIter(cv_mem->NLSstg, &curiter); + } else if (do_sensi_stg1 && cv_mem->sens_solve) + { retval = SUNNonlinSolGetCurIter(cv_mem->NLSstg1, &curiter); - else - retval = SUNNonlinSolGetCurIter(cv_mem->NLS, &curiter); + } + else { retval = SUNNonlinSolGetCurIter(cv_mem->NLS, &curiter); } /* If the linear solver is iterative: test norm(b), if small, return x = 0 or x = b; set linear solver tolerance (in left/right scaled 2-norm) */ - if (cvls_mem->iterative) { + if (cvls_mem->iterative) + { deltar = cvls_mem->eplifac * cv_mem->cv_tq[4]; - bnorm = N_VWrmsNorm(b, weight); - if (bnorm <= deltar) { - if (curiter > 0) N_VConst(ZERO, b); + bnorm = N_VWrmsNorm(b, weight); + if (bnorm <= deltar) + { + if (curiter > 0) { N_VConst(ZERO, b); } cvls_mem->last_flag = CVLS_SUCCESS; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } /* Adjust tolerance for 2-norm */ delta = deltar * cvls_mem->nrmfac; - } else { - delta = ZERO; } + else { delta = ZERO; } /* Set vectors ycur and fcur for use by the Atimes and Psolve interface routines */ @@ -1683,18 +1783,18 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, cvls_mem->fcur = fnow; /* Set scaling vectors for LS to use (if applicable) */ - if (cvls_mem->LS->ops->setscalingvectors) { - retval = SUNLinSolSetScalingVectors(cvls_mem->LS, - weight, - weight); - if (retval != SUNLS_SUCCESS) { - cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", "cvLsSolve", + if (cvls_mem->LS->ops->setscalingvectors) + { + retval = SUNLinSolSetScalingVectors(cvls_mem->LS, weight, weight); + if (retval != SUN_SUCCESS) + { + cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetScalingVectors"); cvls_mem->last_flag = CVLS_SUNLS_FAIL; - return(cvls_mem->last_flag); + return (cvls_mem->last_flag); } - /* If solver is iterative and does not support scaling vectors, update the + /* If solver is iterative and does not support scaling vectors, update the tolerance in an attempt to account for weight vector. We make the following assumptions: 1. w_i = w_mean, for i=0,...,n-1 (i.e. the weights are homogeneous) @@ -1708,12 +1808,12 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, <=> \sum_{i=0}^{n-1} (b - A x_i)^2 < tol^2 / w_mean^2 <=> || b - A x ||_2 < tol / w_mean So we compute w_mean = ||w||_RMS = ||w||_2 and scale the desired tolerance accordingly. */ - } else if (cvls_mem->iterative) { - + } + else if (cvls_mem->iterative) + { N_VConst(ONE, cvls_mem->x); w_mean = N_VWrmsNorm(weight, cvls_mem->x); delta /= w_mean; - } /* Set initial guess x = 0 to LS */ @@ -1721,17 +1821,24 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(cvls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) return(-1); + if (retval != SUN_SUCCESS) { return (-1); } + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + /* Store previous nps value in nps_inc */ + nps_inc = cvls_mem->nps; +#endif /* If a user-provided jtsetup routine is supplied, call that here */ - if (cvls_mem->jtsetup) { + if (cvls_mem->jtsetup) + { cvls_mem->last_flag = cvls_mem->jtsetup(cv_mem->cv_tn, ynow, fnow, cvls_mem->jt_data); cvls_mem->njtsetup++; - if (cvls_mem->last_flag != 0) { - cvProcessError(cv_mem, retval, "CVSLS", - "cvLsSolve", MSG_LS_JTSETUP_FAILED); - return(cvls_mem->last_flag); + if (cvls_mem->last_flag != 0) + { + cvProcessError(cv_mem, retval, __LINE__, __func__, __FILE__, + MSG_LS_JTSETUP_FAILED); + return (cvls_mem->last_flag); } } @@ -1742,68 +1849,79 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, /* If using a direct or matrix-iterative solver, BDF method, and gamma has changed, scale the correction to account for change in gamma */ if (cvls_mem->scalesol && cv_mem->cv_gamrat != ONE) - N_VScale(TWO/(ONE + cv_mem->cv_gamrat), b, b); + { + N_VScale(TWO / (ONE + cv_mem->cv_gamrat), b, b); + } /* Retrieve statistics from iterative linear solvers */ +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + resnorm = ZERO; +#endif nli_inc = 0; - if (cvls_mem->iterative && cvls_mem->LS->ops->numiters) - nli_inc = SUNLinSolNumIters(cvls_mem->LS); + if (cvls_mem->iterative) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + if (cvls_mem->LS->ops->resnorm) resnorm = SUNLinSolResNorm(cvls_mem->LS); +#endif + if (cvls_mem->LS->ops->numiters) + { + nli_inc = SUNLinSolNumIters(cvls_mem->LS); + } + } /* Increment counters nli and ncfl */ cvls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) cvls_mem->ncfl++; + if (retval != SUN_SUCCESS) { cvls_mem->ncfl++; } /* Interpret solver return value */ cvls_mem->last_flag = retval; - switch(retval) { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + SUNLogger_QueueMsg(CV_LOGGER, SUN_LOGLEVEL_DEBUG, "CVODE::cvLsSolve", + "ls-stats", "bnorm = %.16g, resnorm = %.16g, ls_iters = %i, prec_solves = %i", + bnorm, resnorm, nli_inc, (int)(cvls_mem->nps - nps_inc)); +#endif - case SUNLS_SUCCESS: - return(0); - break; + switch (retval) + { + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: /* allow reduction but not solution on first Newton iteration, otherwise return with a recoverable failure */ - if (curiter == 0) return(0); - else return(1); + if (curiter == 0) { return (0); } + else { return (1); } break; case SUNLS_CONV_FAIL: case SUNLS_ATIMES_FAIL_REC: case SUNLS_PSOLVE_FAIL_REC: case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: - case SUNLS_LUFACT_FAIL: - return(1); - break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUNLS_LUFACT_FAIL: return (1); break; + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: - case SUNLS_QRSOL_FAIL: - return(-1); - break; - case SUNLS_PACKAGE_FAIL_UNREC: - cvProcessError(cv_mem, SUNLS_PACKAGE_FAIL_UNREC, "CVSLS", - "cvLsSolve", - "Failure in SUNLinSol external package"); - return(-1); + case SUNLS_QRSOL_FAIL: return (-1); break; + case SUN_ERR_EXT_FAIL: + cvProcessError(cv_mem, SUN_ERR_EXT_FAIL, __LINE__, __func__, __FILE__, + "Failure in SUNLinSol external package"); + return (-1); break; case SUNLS_ATIMES_FAIL_UNREC: - cvProcessError(cv_mem, SUNLS_ATIMES_FAIL_UNREC, "CVSLS", - "cvLsSolve", MSG_LS_JTIMES_FAILED); - return(-1); + cvProcessError(cv_mem, SUNLS_ATIMES_FAIL_UNREC, __LINE__, __func__, + __FILE__, MSG_LS_JTIMES_FAILED); + return (-1); break; case SUNLS_PSOLVE_FAIL_UNREC: - cvProcessError(cv_mem, SUNLS_PSOLVE_FAIL_UNREC, "CVSLS", - "cvLsSolve", MSG_LS_PSOLVE_FAILED); - return(-1); + cvProcessError(cv_mem, SUNLS_PSOLVE_FAIL_UNREC, __LINE__, __func__, + __FILE__, MSG_LS_PSOLVE_FAILED); + return (-1); break; } - return(0); + return (0); } - /*----------------------------------------------------------------- cvLsFree @@ -1815,22 +1933,25 @@ int cvLsFree(CVodeMem cv_mem) CVLsMem cvls_mem; /* Return immediately if CVodeMem or CVLsMem are NULL */ - if (cv_mem == NULL) return (CVLS_SUCCESS); - if (cv_mem->cv_lmem == NULL) return(CVLS_SUCCESS); - cvls_mem = (CVLsMem) cv_mem->cv_lmem; + if (cv_mem == NULL) { return (CVLS_SUCCESS); } + if (cv_mem->cv_lmem == NULL) { return (CVLS_SUCCESS); } + cvls_mem = (CVLsMem)cv_mem->cv_lmem; /* Free N_Vector memory */ - if (cvls_mem->ytemp) { + if (cvls_mem->ytemp) + { N_VDestroy(cvls_mem->ytemp); cvls_mem->ytemp = NULL; } - if (cvls_mem->x) { + if (cvls_mem->x) + { N_VDestroy(cvls_mem->x); cvls_mem->x = NULL; } /* Free savedJ memory */ - if (cvls_mem->savedJ) { + if (cvls_mem->savedJ) + { SUNMatDestroy(cvls_mem->savedJ); cvls_mem->savedJ = NULL; } @@ -1843,15 +1964,14 @@ int cvLsFree(CVodeMem cv_mem) cvls_mem->A = NULL; /* Free preconditioner memory (if applicable) */ - if (cvls_mem->pfree) cvls_mem->pfree(cv_mem); + if (cvls_mem->pfree) { cvls_mem->pfree(cv_mem); } /* free CVLs interface structure */ free(cv_mem->cv_lmem); - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*----------------------------------------------------------------- cvLsInitializeCounters @@ -1868,10 +1988,9 @@ int cvLsInitializeCounters(CVLsMem cvls_mem) cvls_mem->ncfl = 0; cvls_mem->njtsetup = 0; cvls_mem->njtimes = 0; - return(0); + return (0); } - /*--------------------------------------------------------------- cvLs_AccessLMem @@ -1879,25 +1998,26 @@ int cvLsInitializeCounters(CVLsMem cvls_mem) void* pointer. If either is missing it returns CVLS_MEM_NULL or CVLS_LMEM_NULL. ---------------------------------------------------------------*/ -int cvLs_AccessLMem(void* cvode_mem, const char *fname, - CVodeMem *cv_mem, CVLsMem *cvls_mem) +int cvLs_AccessLMem(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVLsMem* cvls_mem) { - if (cvode_mem==NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - fname, MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); } - *cv_mem = (CVodeMem) cvode_mem; - if ((*cv_mem)->cv_lmem==NULL) { - cvProcessError(*cv_mem, CVLS_LMEM_NULL, "CVSLS", - fname, MSG_LS_LMEM_NULL); - return(CVLS_LMEM_NULL); + *cv_mem = (CVodeMem)cvode_mem; + if ((*cv_mem)->cv_lmem == NULL) + { + cvProcessError(*cv_mem, CVLS_LMEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEM_NULL); + return (CVLS_LMEM_NULL); } - *cvls_mem = (CVLsMem) (*cv_mem)->cv_lmem; - return(CVLS_SUCCESS); + *cvls_mem = (CVLsMem)(*cv_mem)->cv_lmem; + return (CVLS_SUCCESS); } - /*================================================================ PART II - backward problems ================================================================*/ @@ -1908,53 +2028,58 @@ int cvLs_AccessLMem(void* cvode_mem, const char *fname, /* CVodeSetLinearSolverB specifies the linear solver for backward integration */ -int CVodeSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS, SUNMatrix A) +int CVodeSetLinearSolverB(void* cvode_mem, int which, SUNLinearSolver LS, + SUNMatrix A) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - void *cvodeB_mem; - CVLsMemB cvlsB_mem; - int retval; + void* cvodeB_mem; + CVLsMemB cvlsB_mem; + int retval; /* Check if cvode_mem exists */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - "CVodeSetLinearSolverB", MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Was ASA initialized? */ - if (cv_mem->cv_adjMallocDone == SUNFALSE) { - cvProcessError(cv_mem, CVLS_NO_ADJ, "CVSLS", - "CVodeSetLinearSolverB", MSG_LS_NO_ADJ); - return(CVLS_NO_ADJ); + if (cv_mem->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(cv_mem, CVLS_NO_ADJ, __LINE__, __func__, __FILE__, + MSG_LS_NO_ADJ); + return (CVLS_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; /* Check which */ - if ( which >= ca_mem->ca_nbckpbs ) { - cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSLS", - "CVodeSetLinearSolverB", MSG_LS_BAD_WHICH); - return(CVLS_ILL_INPUT); + if (which >= ca_mem->ca_nbckpbs) + { + cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_WHICH); + return (CVLS_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ cvB_mem = ca_mem->cvB_mem; - while (cvB_mem != NULL) { - if ( which == cvB_mem->cv_index ) break; + while (cvB_mem != NULL) + { + if (which == cvB_mem->cv_index) { break; } cvB_mem = cvB_mem->cv_next; } /* Get memory for CVLsMemRecB */ cvlsB_mem = NULL; - cvlsB_mem = (CVLsMemB) malloc(sizeof(struct CVLsMemRecB)); - if (cvlsB_mem == NULL) { - cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSLS", - "CVodeSetLinearSolverB", MSG_LS_MEM_FAIL); - return(CVLS_MEM_FAIL); + cvlsB_mem = (CVLsMemB)malloc(sizeof(struct CVLsMemRecB)); + if (cvlsB_mem == NULL) + { + cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + return (CVLS_MEM_FAIL); } /* initialize Jacobian and preconditioner functions */ @@ -1971,860 +2096,831 @@ int CVodeSetLinearSolverB(void *cvode_mem, int which, cvlsB_mem->P_dataB = NULL; /* free any existing system solver attached to cvB */ - if (cvB_mem->cv_lfree) cvB_mem->cv_lfree(cvB_mem); + if (cvB_mem->cv_lfree) { cvB_mem->cv_lfree(cvB_mem); } /* Attach lmemB data and lfreeB function. */ cvB_mem->cv_lmem = cvlsB_mem; cvB_mem->cv_lfree = cvLsFreeB; /* set the linear solver for this backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - retval = CVodeSetLinearSolver(cvodeB_mem, LS, A); - if (retval != CVLS_SUCCESS) { + cvodeB_mem = (void*)(cvB_mem->cv_mem); + retval = CVodeSetLinearSolver(cvodeB_mem, LS, A); + if (retval != CVLS_SUCCESS) + { free(cvlsB_mem); cvlsB_mem = NULL; } - return(retval); + return (retval); } - /*--------------------------------------------------------------- CVSLS Exported functions -- Optional input/output ---------------------------------------------------------------*/ -int CVodeSetJacFnB(void *cvode_mem, int which, CVLsJacFnB jacB) +int CVodeSetJacFnB(void* cvode_mem, int which, CVLsJacFnB jacB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetJacFnB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* set jacB function pointer */ cvlsB_mem->jacB = jacB; /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - if (jacB != NULL) { - retval = CVodeSetJacFn(cvodeB_mem, cvLsJacBWrapper); - } else { - retval = CVodeSetJacFn(cvodeB_mem, NULL); - } + cvodeB_mem = (void*)(cvB_mem->cv_mem); + if (jacB != NULL) { retval = CVodeSetJacFn(cvodeB_mem, cvLsJacBWrapper); } + else { retval = CVodeSetJacFn(cvodeB_mem, NULL); } - return(retval); + return (retval); } - -int CVodeSetJacFnBS(void *cvode_mem, int which, CVLsJacFnBS jacBS) +int CVodeSetJacFnBS(void* cvode_mem, int which, CVLsJacFnBS jacBS) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetJacFnBS", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* set jacBS function pointer */ cvlsB_mem->jacBS = jacBS; /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - if (jacBS != NULL) { - retval = CVodeSetJacFn(cvodeB_mem, cvLsJacBSWrapper); - } else { - retval = CVodeSetJacFn(cvodeB_mem, NULL); - } + cvodeB_mem = (void*)(cvB_mem->cv_mem); + if (jacBS != NULL) { retval = CVodeSetJacFn(cvodeB_mem, cvLsJacBSWrapper); } + else { retval = CVodeSetJacFn(cvodeB_mem, NULL); } - return(retval); + return (retval); } - -int CVodeSetEpsLinB(void *cvode_mem, int which, realtype eplifacB) +int CVodeSetEpsLinB(void* cvode_mem, int which, sunrealtype eplifacB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetEpsLinB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - return(CVodeSetEpsLin(cvodeB_mem, eplifacB)); + cvodeB_mem = (void*)(cvB_mem->cv_mem); + return (CVodeSetEpsLin(cvodeB_mem, eplifacB)); } - -int CVodeSetLSNormFactorB(void *cvode_mem, int which, realtype nrmfacB) +int CVodeSetLSNormFactorB(void* cvode_mem, int which, sunrealtype nrmfacB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetLSNormFactorB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - return(CVodeSetLSNormFactor(cvodeB_mem, nrmfacB)); + cvodeB_mem = (void*)(cvB_mem->cv_mem); + return (CVodeSetLSNormFactor(cvodeB_mem, nrmfacB)); } - -int CVodeSetLinearSolutionScalingB(void *cvode_mem, int which, - booleantype onoffB) +int CVodeSetLinearSolutionScalingB(void* cvode_mem, int which, + sunbooleantype onoffB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetLinearSolutionScalingB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - return(CVodeSetLinearSolutionScaling(cvodeB_mem, onoffB)); + cvodeB_mem = (void*)(cvB_mem->cv_mem); + return (CVodeSetLinearSolutionScaling(cvodeB_mem, onoffB)); } - -int CVodeSetPreconditionerB(void *cvode_mem, int which, - CVLsPrecSetupFnB psetupB, - CVLsPrecSolveFnB psolveB) +int CVodeSetPreconditionerB(void* cvode_mem, int which, + CVLsPrecSetupFnB psetupB, CVLsPrecSolveFnB psolveB) { - CVodeMem cv_mem; - CVadjMem ca_mem; - CVodeBMem cvB_mem; - void *cvodeB_mem; - CVLsMemB cvlsB_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; + CVodeBMem cvB_mem; + void* cvodeB_mem; + CVLsMemB cvlsB_mem; CVLsPrecSetupFn cvls_psetup; CVLsPrecSolveFn cvls_psolve; - int retval; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetPreconditionerB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Set preconditioners for the backward problem. */ cvlsB_mem->psetB = psetupB; cvlsB_mem->psolveB = psolveB; /* Call the corresponding "set" routine for the backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); cvls_psetup = (psetupB == NULL) ? NULL : cvLsPrecSetupBWrapper; cvls_psolve = (psolveB == NULL) ? NULL : cvLsPrecSolveBWrapper; - return(CVodeSetPreconditioner(cvodeB_mem, cvls_psetup, cvls_psolve)); + return (CVodeSetPreconditioner(cvodeB_mem, cvls_psetup, cvls_psolve)); } - -int CVodeSetPreconditionerBS(void *cvode_mem, int which, +int CVodeSetPreconditionerBS(void* cvode_mem, int which, CVLsPrecSetupFnBS psetupBS, CVLsPrecSolveFnBS psolveBS) { - CVodeMem cv_mem; - CVadjMem ca_mem; - CVodeBMem cvB_mem; - void *cvodeB_mem; - CVLsMemB cvlsB_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; + CVodeBMem cvB_mem; + void* cvodeB_mem; + CVLsMemB cvlsB_mem; CVLsPrecSetupFn cvls_psetup; CVLsPrecSolveFn cvls_psolve; - int retval; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetPreconditionerBS", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Set preconditioners for the backward problem. */ cvlsB_mem->psetBS = psetupBS; cvlsB_mem->psolveBS = psolveBS; /* Call the corresponding "set" routine for the backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); cvls_psetup = (psetupBS == NULL) ? NULL : cvLsPrecSetupBSWrapper; cvls_psolve = (psolveBS == NULL) ? NULL : cvLsPrecSolveBSWrapper; - return(CVodeSetPreconditioner(cvodeB_mem, cvls_psetup, cvls_psolve)); + return (CVodeSetPreconditioner(cvodeB_mem, cvls_psetup, cvls_psolve)); } - -int CVodeSetJacTimesB(void *cvode_mem, int which, - CVLsJacTimesSetupFnB jtsetupB, +int CVodeSetJacTimesB(void* cvode_mem, int which, CVLsJacTimesSetupFnB jtsetupB, CVLsJacTimesVecFnB jtimesB) { - CVodeMem cv_mem; - CVadjMem ca_mem; - CVodeBMem cvB_mem; - void *cvodeB_mem; - CVLsMemB cvlsB_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; + CVodeBMem cvB_mem; + void* cvodeB_mem; + CVLsMemB cvlsB_mem; CVLsJacTimesSetupFn cvls_jtsetup; - CVLsJacTimesVecFn cvls_jtimes; - int retval; + CVLsJacTimesVecFn cvls_jtimes; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetJacTimesB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Set jacobian routines for the backward problem. */ cvlsB_mem->jtsetupB = jtsetupB; cvlsB_mem->jtimesB = jtimesB; /* Call the corresponding "set" routine for the backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); cvls_jtsetup = (jtsetupB == NULL) ? NULL : cvLsJacTimesSetupBWrapper; - cvls_jtimes = (jtimesB == NULL) ? NULL : cvLsJacTimesVecBWrapper; - return(CVodeSetJacTimes(cvodeB_mem, cvls_jtsetup, cvls_jtimes)); + cvls_jtimes = (jtimesB == NULL) ? NULL : cvLsJacTimesVecBWrapper; + return (CVodeSetJacTimes(cvodeB_mem, cvls_jtsetup, cvls_jtimes)); } - -int CVodeSetJacTimesBS(void *cvode_mem, int which, +int CVodeSetJacTimesBS(void* cvode_mem, int which, CVLsJacTimesSetupFnBS jtsetupBS, CVLsJacTimesVecFnBS jtimesBS) { - CVodeMem cv_mem; - CVadjMem ca_mem; - CVodeBMem cvB_mem; - void *cvodeB_mem; - CVLsMemB cvlsB_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; + CVodeBMem cvB_mem; + void* cvodeB_mem; + CVLsMemB cvlsB_mem; CVLsJacTimesSetupFn cvls_jtsetup; - CVLsJacTimesVecFn cvls_jtimes; - int retval; + CVLsJacTimesVecFn cvls_jtimes; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetJacTimesBS", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Set jacobian routines for the backward problem. */ cvlsB_mem->jtsetupBS = jtsetupBS; cvlsB_mem->jtimesBS = jtimesBS; /* Call the corresponding "set" routine for the backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); + cvodeB_mem = (void*)(cvB_mem->cv_mem); cvls_jtsetup = (jtsetupBS == NULL) ? NULL : cvLsJacTimesSetupBSWrapper; - cvls_jtimes = (jtimesBS == NULL) ? NULL : cvLsJacTimesVecBSWrapper; - return(CVodeSetJacTimes(cvodeB_mem, cvls_jtsetup, cvls_jtimes)); + cvls_jtimes = (jtimesBS == NULL) ? NULL : cvLsJacTimesVecBSWrapper; + return (CVodeSetJacTimes(cvodeB_mem, cvls_jtsetup, cvls_jtimes)); } - -int CVodeSetJacTimesRhsFnB(void *cvode_mem, int which, CVRhsFn jtimesRhsFn) +int CVodeSetJacTimesRhsFnB(void* cvode_mem, int which, CVRhsFn jtimesRhsFn) { - CVodeMem cv_mem; - CVadjMem ca_mem; - CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVodeMem cv_mem; + CVadjMem ca_mem; + CVodeBMem cvB_mem; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetJacTimesRhsFnB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Call the corresponding "set" routine for the backward problem */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - return(CVodeSetJacTimesRhsFn(cvodeB_mem, jtimesRhsFn)); + cvodeB_mem = (void*)(cvB_mem->cv_mem); + return (CVodeSetJacTimesRhsFn(cvodeB_mem, jtimesRhsFn)); } - -int CVodeSetLinSysFnB(void *cvode_mem, int which, CVLsLinSysFnB linsysB) +int CVodeSetLinSysFnB(void* cvode_mem, int which, CVLsLinSysFnB linsysB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetLinSysFnB", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* set linsysB function pointer */ cvlsB_mem->linsysB = linsysB; /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - if (linsysB != NULL) { + cvodeB_mem = (void*)(cvB_mem->cv_mem); + if (linsysB != NULL) + { retval = CVodeSetLinSysFn(cvodeB_mem, cvLsLinSysBWrapper); - } else { - retval = CVodeSetLinSysFn(cvodeB_mem, NULL); } + else { retval = CVodeSetLinSysFn(cvodeB_mem, NULL); } - return(retval); + return (retval); } - -int CVodeSetLinSysFnBS(void *cvode_mem, int which, CVLsLinSysFnBS linsysBS) +int CVodeSetLinSysFnBS(void* cvode_mem, int which, CVLsLinSysFnBS linsysBS) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - void *cvodeB_mem; - int retval; + CVLsMemB cvlsB_mem; + void* cvodeB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemB(cvode_mem, which, "CVodeSetLinSysFnBS", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemB(cvode_mem, which, __func__, &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* set linsysB function pointer */ cvlsB_mem->linsysBS = linsysBS; /* call corresponding routine for cvodeB_mem structure */ - cvodeB_mem = (void *) (cvB_mem->cv_mem); - if (linsysBS != NULL) { + cvodeB_mem = (void*)(cvB_mem->cv_mem); + if (linsysBS != NULL) + { retval = CVodeSetLinSysFn(cvodeB_mem, cvLsLinSysBSWrapper); - } else { - retval = CVodeSetLinSysFn(cvodeB_mem, NULL); } + else { retval = CVodeSetLinSysFn(cvodeB_mem, NULL); } - return(retval); + return (retval); } - /*----------------------------------------------------------------- CVSLS private functions for backwards problems -----------------------------------------------------------------*/ /* cvLsJacBWrapper interfaces to the CVLsJacFnB routine provided by the user. cvLsJacBWrapper is of type CVLsJacFn. */ -static int cvLsJacBWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix JB, void *cvode_mem, - N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) +static int cvLsJacBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* cvode_mem, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacBWrapper", &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint jacB routine (of type CVLsJacFnB) */ - return(cvlsB_mem->jacB(t, ca_mem->ca_ytmp, yB, fyB, JB, - cvB_mem->cv_user_data, tmp1B, tmp2B, tmp3B)); + return (cvlsB_mem->jacB(t, ca_mem->ca_ytmp, yB, fyB, JB, + cvB_mem->cv_user_data, tmp1B, tmp2B, tmp3B)); } /* cvLsJacBSWrapper interfaces to the CVLsJacFnBS routine provided by the user. cvLsJacBSWrapper is of type CVLsJacFn. */ -static int cvLsJacBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix JB, void *cvode_mem, - N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) +static int cvLsJacBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix JB, void* cvode_mem, N_Vector tmp1B, + N_Vector tmp2B, N_Vector tmp3B) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacBSWrapper", &cv_mem, &ca_mem, + &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint dense djacBS routine (of type CVLsDenseJacFnBS) */ - return(cvlsB_mem->jacBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, - JB, cvB_mem->cv_user_data, tmp1B, tmp2B, tmp3B)); + return (cvlsB_mem->jacBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, JB, + cvB_mem->cv_user_data, tmp1B, tmp2B, tmp3B)); } - /* cvLsPrecSetupBWrapper interfaces to the CVLsPrecSetupFnB routine provided by the user */ -static int cvLsPrecSetupBWrapper(realtype t, N_Vector yB, N_Vector fyB, - booleantype jokB, booleantype *jcurPtrB, - realtype gammaB, void *cvode_mem) +static int cvLsPrecSetupBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + sunbooleantype jokB, sunbooleantype* jcurPtrB, + sunrealtype gammaB, void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSetupBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSetupBWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Get forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsPrecSetupBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint precondB routine */ - return(cvlsB_mem->psetB(t, ca_mem->ca_ytmp, yB, fyB, jokB, - jcurPtrB, gammaB, cvB_mem->cv_user_data)); + return (cvlsB_mem->psetB(t, ca_mem->ca_ytmp, yB, fyB, jokB, jcurPtrB, gammaB, + cvB_mem->cv_user_data)); } /* cvLsPrecSetupBSWrapper interfaces to the CVLsPrecSetupFnBS routine provided by the user */ -static int cvLsPrecSetupBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - booleantype jokB, booleantype *jcurPtrB, - realtype gammaB, void *cvode_mem) +static int cvLsPrecSetupBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + sunbooleantype jokB, sunbooleantype* jcurPtrB, + sunrealtype gammaB, void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSetupBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSetupBSWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsPrecSetupBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint precondB routine */ - return(cvlsB_mem->psetBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, - yB, fyB, jokB, jcurPtrB, gammaB, - cvB_mem->cv_user_data)); + return (cvlsB_mem->psetBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, jokB, + jcurPtrB, gammaB, cvB_mem->cv_user_data)); } - /* cvLsPrecSolveBWrapper interfaces to the CVLsPrecSolveFnB routine provided by the user */ -static int cvLsPrecSolveBWrapper(realtype t, N_Vector yB, N_Vector fyB, - N_Vector rB, N_Vector zB, - realtype gammaB, realtype deltaB, - int lrB, void *cvode_mem) +static int cvLsPrecSolveBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + N_Vector rB, N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSolveBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSolveBWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsPrecSolveBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint psolveB routine */ - return(cvlsB_mem->psolveB(t, ca_mem->ca_ytmp, yB, fyB, rB, zB, - gammaB, deltaB, lrB, cvB_mem->cv_user_data)); + return (cvlsB_mem->psolveB(t, ca_mem->ca_ytmp, yB, fyB, rB, zB, gammaB, + deltaB, lrB, cvB_mem->cv_user_data)); } - /* cvLsPrecSolveBSWrapper interfaces to the CVLsPrecSolveFnBS routine provided by the user */ -static int cvLsPrecSolveBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - N_Vector rB, N_Vector zB, - realtype gammaB, realtype deltaB, - int lrB, void *cvode_mem) +static int cvLsPrecSolveBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + N_Vector rB, N_Vector zB, sunrealtype gammaB, + sunrealtype deltaB, int lrB, void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSolveBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsPrecSolveBSWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsPrecSolveBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint psolveBS routine */ - return(cvlsB_mem->psolveBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, - yB, fyB, rB, zB, gammaB, deltaB, - lrB, cvB_mem->cv_user_data)); + return (cvlsB_mem->psolveBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, rB, + zB, gammaB, deltaB, lrB, cvB_mem->cv_user_data)); } - /* cvLsJacTimesSetupBWrapper interfaces to the CVLsJacTimesSetupFnB routine provided by the user */ -static int cvLsJacTimesSetupBWrapper(realtype t, N_Vector yB, - N_Vector fyB, void *cvode_mem) +static int cvLsJacTimesSetupBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesSetupBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesSetupBWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacTimesVecBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint jtsetupB routine */ - return(cvlsB_mem->jtsetupB(t, ca_mem->ca_ytmp, yB, - fyB, cvB_mem->cv_user_data)); + return (cvlsB_mem->jtsetupB(t, ca_mem->ca_ytmp, yB, fyB, cvB_mem->cv_user_data)); } - /* cvLsJacTimesSetupBSWrapper interfaces to the CVLsJacTimesSetupFnBS routine provided by the user */ -static int cvLsJacTimesSetupBSWrapper(realtype t, N_Vector yB, - N_Vector fyB, void *cvode_mem) +static int cvLsJacTimesSetupBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + void* cvode_mem) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesSetupBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesSetupBSWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacTimesVecBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint jtsetupBS routine */ - return(cvlsB_mem->jtsetupBS(t, ca_mem->ca_ytmp, - ca_mem->ca_yStmp, yB, fyB, - cvB_mem->cv_user_data)); + return (cvlsB_mem->jtsetupBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, + cvB_mem->cv_user_data)); } - /* cvLsJacTimesVecBWrapper interfaces to the CVLsJacTimesVecFnB routine provided by the user */ -static int cvLsJacTimesVecBWrapper(N_Vector vB, N_Vector JvB, realtype t, - N_Vector yB, N_Vector fyB, - void *cvode_mem, N_Vector tmpB) +static int cvLsJacTimesVecBWrapper(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector yB, N_Vector fyB, void* cvode_mem, + N_Vector tmpB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesVecBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesVecBWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacTimesVecBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint jtimesB routine */ - return(cvlsB_mem->jtimesB(vB, JvB, t, ca_mem->ca_ytmp, yB, - fyB, cvB_mem->cv_user_data, tmpB)); + return (cvlsB_mem->jtimesB(vB, JvB, t, ca_mem->ca_ytmp, yB, fyB, + cvB_mem->cv_user_data, tmpB)); } - /* cvLsJacTimesVecBSWrapper interfaces to the CVLsJacTimesVecFnBS routine provided by the user */ -static int cvLsJacTimesVecBSWrapper(N_Vector vB, N_Vector JvB, realtype t, - N_Vector yB, N_Vector fyB, - void *cvode_mem, N_Vector tmpB) +static int cvLsJacTimesVecBSWrapper(N_Vector vB, N_Vector JvB, sunrealtype t, + N_Vector yB, N_Vector fyB, void* cvode_mem, + N_Vector tmpB) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesVecBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsJacTimesVecBSWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsJacTimesVecBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint jtimesBS routine */ - return(cvlsB_mem->jtimesBS(vB, JvB, t, ca_mem->ca_ytmp, - ca_mem->ca_yStmp, yB, fyB, - cvB_mem->cv_user_data, tmpB)); + return (cvlsB_mem->jtimesBS(vB, JvB, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, + fyB, cvB_mem->cv_user_data, tmpB)); } - /* cvLsLinSysBWrapper interfaces to the CVLsLinSysFnB routine provided by the user. cvLsLinSysBWrapper is of type CVLsLinSysFn. */ -static int cvLsLinSysBWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix AB, booleantype jokB, - booleantype *jcurB, realtype gammaB, - void *cvode_mem, N_Vector tmp1B, N_Vector tmp2B, +static int cvLsLinSysBWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* cvode_mem, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsLinSysBWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsLinSysBWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsLinSysBWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint linsysB routine (of type CVLsLinSysFnB) */ - return(cvlsB_mem->linsysB(t, ca_mem->ca_ytmp, yB, fyB, AB, jokB, jcurB, - gammaB, cvB_mem->cv_user_data, tmp1B, tmp2B, - tmp3B)); + return (cvlsB_mem->linsysB(t, ca_mem->ca_ytmp, yB, fyB, AB, jokB, jcurB, + gammaB, cvB_mem->cv_user_data, tmp1B, tmp2B, tmp3B)); } - /* cvLsLinSysBSWrapper interfaces to the CVLsLinSysFnBS routine provided by the user. cvLsLinSysBSWrapper is of type CVLsLinSysFn. */ -static int cvLsLinSysBSWrapper(realtype t, N_Vector yB, N_Vector fyB, - SUNMatrix AB, booleantype jokB, - booleantype *jcurB, realtype gammaB, - void *cvode_mem, N_Vector tmp1B, N_Vector tmp2B, +static int cvLsLinSysBSWrapper(sunrealtype t, N_Vector yB, N_Vector fyB, + SUNMatrix AB, sunbooleantype jokB, + sunbooleantype* jcurB, sunrealtype gammaB, + void* cvode_mem, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) { - CVodeMem cv_mem; - CVadjMem ca_mem; + CVodeMem cv_mem; + CVadjMem ca_mem; CVodeBMem cvB_mem; - CVLsMemB cvlsB_mem; - int retval; + CVLsMemB cvlsB_mem; + int retval; /* access relevant memory structures */ - retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsLinSysBSWrapper", - &cv_mem, &ca_mem, &cvB_mem, &cvlsB_mem); - if (retval != CVLS_SUCCESS) return(retval); + retval = cvLs_AccessLMemBCur(cvode_mem, "cvLsLinSysBSWrapper", &cv_mem, + &ca_mem, &cvB_mem, &cvlsB_mem); + if (retval != CVLS_SUCCESS) { return (retval); } /* Forward solution from interpolation */ if (ca_mem->ca_IMinterpSensi) + { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, ca_mem->ca_yStmp); - else - retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, -1, "CVSLS", "cvLsLinSysBSWrapper", - MSG_LS_BAD_TINTERP); - return(-1); + } + else { retval = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, NULL); } + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSG_LS_BAD_TINTERP); + return (-1); } /* Call user's adjoint dense djacBS routine (of type CVLsDenseJacFnBS) */ - return(cvlsB_mem->linsysBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, - AB, jokB, jcurB, gammaB, cvB_mem->cv_user_data, - tmp1B, tmp2B, tmp3B)); + return (cvlsB_mem->linsysBS(t, ca_mem->ca_ytmp, ca_mem->ca_yStmp, yB, fyB, AB, + jokB, jcurB, gammaB, cvB_mem->cv_user_data, tmp1B, + tmp2B, tmp3B)); } - /* cvLsFreeB frees memory associated with the CVSLS wrapper */ int cvLsFreeB(CVodeBMem cvB_mem) { CVLsMemB cvlsB_mem; /* Return immediately if cvB_mem or cvB_mem->cv_lmem are NULL */ - if (cvB_mem == NULL) return(CVLS_SUCCESS); - if (cvB_mem->cv_lmem == NULL) return(CVLS_SUCCESS); - cvlsB_mem = (CVLsMemB) (cvB_mem->cv_lmem); + if (cvB_mem == NULL) { return (CVLS_SUCCESS); } + if (cvB_mem->cv_lmem == NULL) { return (CVLS_SUCCESS); } + cvlsB_mem = (CVLsMemB)(cvB_mem->cv_lmem); /* free CVLsMemB interface structure */ free(cvlsB_mem); - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* cvLs_AccessLMemB unpacks the cv_mem, ca_mem, cvB_mem and cvlsB_mem structures from the void* cvode_mem pointer. If any are missing it returns CVLS_MEM_NULL, CVLS_NO_ADJ, CVS_ILL_INPUT, or CVLS_LMEMB_NULL. */ -int cvLs_AccessLMemB(void *cvode_mem, int which, const char *fname, - CVodeMem *cv_mem, CVadjMem *ca_mem, - CVodeBMem *cvB_mem, CVLsMemB *cvlsB_mem) +int cvLs_AccessLMemB(void* cvode_mem, int which, const char* fname, + CVodeMem* cv_mem, CVadjMem* ca_mem, CVodeBMem* cvB_mem, + CVLsMemB* cvlsB_mem) { - /* access CVodeMem structure */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - fname, MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); } - *cv_mem = (CVodeMem) cvode_mem; + *cv_mem = (CVodeMem)cvode_mem; /* access CVadjMem structure */ - if ((*cv_mem)->cv_adjMallocDone == SUNFALSE) { - cvProcessError(*cv_mem, CVLS_NO_ADJ, "CVSLS", - fname, MSG_LS_NO_ADJ); - return(CVLS_NO_ADJ); + if ((*cv_mem)->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(*cv_mem, CVLS_NO_ADJ, __LINE__, fname, __FILE__, + MSG_LS_NO_ADJ); + return (CVLS_NO_ADJ); } *ca_mem = (*cv_mem)->cv_adj_mem; /* Check which */ - if ( which >= (*ca_mem)->ca_nbckpbs ) { - cvProcessError(*cv_mem, CVLS_ILL_INPUT, "CVSLS", - fname, MSG_LS_BAD_WHICH); - return(CVLS_ILL_INPUT); + if (which >= (*ca_mem)->ca_nbckpbs) + { + cvProcessError(*cv_mem, CVLS_ILL_INPUT, __LINE__, fname, __FILE__, + MSG_LS_BAD_WHICH); + return (CVLS_ILL_INPUT); } /* Find the CVodeBMem entry in the linked list corresponding to which */ *cvB_mem = (*ca_mem)->cvB_mem; - while ((*cvB_mem) != NULL) { - if ( which == (*cvB_mem)->cv_index ) break; + while ((*cvB_mem) != NULL) + { + if (which == (*cvB_mem)->cv_index) { break; } *cvB_mem = (*cvB_mem)->cv_next; } /* access CVLsMemB structure */ - if ((*cvB_mem)->cv_lmem == NULL) { - cvProcessError(*cv_mem, CVLS_LMEMB_NULL, "CVSLS", - fname, MSG_LS_LMEMB_NULL); - return(CVLS_LMEMB_NULL); + if ((*cvB_mem)->cv_lmem == NULL) + { + cvProcessError(*cv_mem, CVLS_LMEMB_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEMB_NULL); + return (CVLS_LMEMB_NULL); } - *cvlsB_mem = (CVLsMemB) ((*cvB_mem)->cv_lmem); + *cvlsB_mem = (CVLsMemB)((*cvB_mem)->cv_lmem); - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /* cvLs_AccessLMemBCur unpacks the cv_mem, ca_mem, cvB_mem and cvlsB_mem structures from the void* cvode_mem pointer. If any are missing it returns CVLS_MEM_NULL, CVLS_NO_ADJ, or CVLS_LMEMB_NULL. */ -int cvLs_AccessLMemBCur(void *cvode_mem, const char *fname, - CVodeMem *cv_mem, CVadjMem *ca_mem, - CVodeBMem *cvB_mem, CVLsMemB *cvlsB_mem) +int cvLs_AccessLMemBCur(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVadjMem* ca_mem, CVodeBMem* cvB_mem, CVLsMemB* cvlsB_mem) { - /* access CVodeMem structure */ - if (cvode_mem==NULL) { - cvProcessError(NULL, CVLS_MEM_NULL, "CVSLS", - fname, MSG_LS_CVMEM_NULL); - return(CVLS_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_CVMEM_NULL); + return (CVLS_MEM_NULL); } - *cv_mem = (CVodeMem) cvode_mem; + *cv_mem = (CVodeMem)cvode_mem; /* access CVadjMem structure */ - if ((*cv_mem)->cv_adjMallocDone == SUNFALSE) { - cvProcessError(*cv_mem, CVLS_NO_ADJ, "CVSLS", - fname, MSG_LS_NO_ADJ); - return(CVLS_NO_ADJ); + if ((*cv_mem)->cv_adjMallocDone == SUNFALSE) + { + cvProcessError(*cv_mem, CVLS_NO_ADJ, __LINE__, fname, __FILE__, + MSG_LS_NO_ADJ); + return (CVLS_NO_ADJ); } *ca_mem = (*cv_mem)->cv_adj_mem; /* get current backward problem */ - if ((*ca_mem)->ca_bckpbCrt == NULL) { - cvProcessError(*cv_mem, CVLS_LMEMB_NULL, "CVSLS", - fname, MSG_LS_LMEMB_NULL); - return(CVLS_LMEMB_NULL); + if ((*ca_mem)->ca_bckpbCrt == NULL) + { + cvProcessError(*cv_mem, CVLS_LMEMB_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEMB_NULL); + return (CVLS_LMEMB_NULL); } *cvB_mem = (*ca_mem)->ca_bckpbCrt; /* access CVLsMemB structure */ - if ((*cvB_mem)->cv_lmem == NULL) { - cvProcessError(*cv_mem, CVLS_LMEMB_NULL, "CVSLS", - fname, MSG_LS_LMEMB_NULL); - return(CVLS_LMEMB_NULL); + if ((*cvB_mem)->cv_lmem == NULL) + { + cvProcessError(*cv_mem, CVLS_LMEMB_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEMB_NULL); + return (CVLS_LMEMB_NULL); } - *cvlsB_mem = (CVLsMemB) ((*cvB_mem)->cv_lmem); + *cvlsB_mem = (CVLsMemB)((*cvB_mem)->cv_lmem); - return(CVLS_SUCCESS); + return (CVLS_SUCCESS); } - /*--------------------------------------------------------------- EOF ---------------------------------------------------------------*/ diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls_impl.h index 0f3e74fa1..4fd13c850 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_ls_impl.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,13 +19,13 @@ #define _CVSLS_IMPL_H #include + #include "cvodes_impl.h" -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif - /*----------------------------------------------------------------- CVSLS solver constants @@ -37,10 +37,9 @@ extern "C" { the nonlinear iteration is multiplied to get a tolerance on the linear iteration -----------------------------------------------------------------*/ -#define CVLS_MSBJ 51 -#define CVLS_DGMAX RCONST(0.2) -#define CVLS_EPLIN RCONST(0.05) - +#define CVLS_MSBJ 51 +#define CVLS_DGMAX SUN_RCONST(0.2) +#define CVLS_EPLIN SUN_RCONST(0.05) /*================================================================= PART I: Forward Problems @@ -51,24 +50,26 @@ extern "C" { The type CVLsMem is pointer to a CVLsMemRec. -----------------------------------------------------------------*/ -typedef struct CVLsMemRec { - +typedef struct CVLsMemRec +{ /* Linear solver type information */ - booleantype iterative; /* is the solver iterative? */ - booleantype matrixbased; /* is a matrix structure used? */ + sunbooleantype iterative; /* is the solver iterative? */ + sunbooleantype matrixbased; /* is a matrix structure used? */ /* Jacobian construction & storage */ - booleantype jacDQ; /* SUNTRUE if using internal DQ Jac approx. */ - CVLsJacFn jac; /* Jacobian routine to be called */ - void *J_data; /* user data is passed to jac */ - booleantype jbad; /* heuristic suggestion for pset */ + sunbooleantype jacDQ; /* SUNTRUE if using internal DQ Jac approx. */ + CVLsJacFn jac; /* Jacobian routine to be called */ + void* J_data; /* user data is passed to jac */ + sunbooleantype jbad; /* heuristic suggestion for pset */ + sunrealtype dgmax_jbad; /* if convfail = FAIL_BAD_J and the gamma ratio * + * |gamma/gammap-1| < dgmax_jbad then J is bad */ /* Matrix-based solver, scale solution to account for change in gamma */ - booleantype scalesol; + sunbooleantype scalesol; /* Iterative solver tolerance */ - realtype eplifac; /* nonlinear -> linear tol scaling factor */ - realtype nrmfac; /* integrator -> LS norm conversion factor */ + sunrealtype eplifac; /* nonlinear -> linear tol scaling factor */ + sunrealtype nrmfac; /* integrator -> LS norm conversion factor */ /* Linear solver, matrix and vector objects/pointers */ SUNLinearSolver LS; /* generic linear solver object */ @@ -80,17 +81,18 @@ typedef struct CVLsMemRec { N_Vector fcur; /* fcur = f(tn, ycur) */ /* Statistics and associated parameters */ - long int msbj; /* max num steps between jac/pset calls */ - long int nje; /* nje = no. of calls to jac */ - long int nfeDQ; /* no. of calls to f due to DQ Jacobian or J*v + long int msbj; /* max num steps between jac/pset calls */ + long int nje; /* nje = no. of calls to jac */ + long int nfeDQ; /* no. of calls to f due to DQ Jacobian or J*v approximations */ - long int nstlj; /* nstlj = nst at last jac/pset call */ - long int npe; /* npe = total number of pset calls */ - long int nli; /* nli = total number of linear iterations */ - long int nps; /* nps = total number of psolve calls */ - long int ncfl; /* ncfl = total number of convergence failures */ - long int njtsetup; /* njtsetup = total number of calls to jtsetup */ - long int njtimes; /* njtimes = total number of calls to jtimes */ + long int nstlj; /* nstlj = nst at last jac/pset call */ + long int npe; /* npe = total number of pset calls */ + long int nli; /* nli = total number of linear iterations */ + long int nps; /* nps = total number of psolve calls */ + long int ncfl; /* ncfl = total number of convergence failures */ + long int njtsetup; /* njtsetup = total number of calls to jtsetup */ + long int njtimes; /* njtimes = total number of calls to jtimes */ + sunrealtype tnlj; /* tnlj = t_n at last jac/pset call */ /* Preconditioner computation * (a) user-provided: @@ -102,7 +104,7 @@ typedef struct CVLsMemRec { CVLsPrecSetupFn pset; CVLsPrecSolveFn psolve; int (*pfree)(CVodeMem cv_mem); - void *P_data; + void* P_data; /* Jacobian times vector compuation * (a) jtimes function provided by the user: @@ -111,11 +113,11 @@ typedef struct CVLsMemRec { * (b) internal jtimes * - jt_data == cvode_mem * - jtimesDQ == SUNTRUE */ - booleantype jtimesDQ; + sunbooleantype jtimesDQ; CVLsJacTimesSetupFn jtsetup; CVLsJacTimesVecFn jtimes; CVRhsFn jt_f; - void *jt_data; + void* jt_data; /* Linear system setup function * (a) user-provided linsys function: @@ -124,13 +126,13 @@ typedef struct CVLsMemRec { * (b) internal linsys function: * - user_linsys = SUNFALSE * - A_data = cvode_mem */ - booleantype user_linsys; + sunbooleantype user_linsys; CVLsLinSysFn linsys; void* A_data; int last_flag; /* last error flag returned by any function */ -} *CVLsMem; +}* CVLsMem; /*----------------------------------------------------------------- Prototypes of internal functions @@ -139,36 +141,33 @@ typedef struct CVLsMemRec { /* Interface routines called by system SUNLinearSolver */ int cvLsATimes(void* cvode_mem, N_Vector v, N_Vector z); int cvLsPSetup(void* cvode_mem); -int cvLsPSolve(void* cvode_mem, N_Vector r, N_Vector z, - realtype tol, int lr); +int cvLsPSolve(void* cvode_mem, N_Vector r, N_Vector z, sunrealtype tol, int lr); /* Difference quotient approximation for Jac times vector */ -int cvLsDQJtimes(N_Vector v, N_Vector Jv, realtype t, - N_Vector y, N_Vector fy, void *data, - N_Vector work); +int cvLsDQJtimes(N_Vector v, N_Vector Jv, sunrealtype t, N_Vector y, + N_Vector fy, void* data, N_Vector work); /* Difference-quotient Jacobian approximation routines */ -int cvLsDQJac(realtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, - void *data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); -int cvLsDenseDQJac(realtype t, N_Vector y, N_Vector fy, - SUNMatrix Jac, CVodeMem cv_mem, N_Vector tmp1); -int cvLsBandDQJac(realtype t, N_Vector y, N_Vector fy, - SUNMatrix Jac, CVodeMem cv_mem, N_Vector tmp1, - N_Vector tmp2); +int cvLsDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, void* data, + N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); +int cvLsDenseDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + CVodeMem cv_mem, N_Vector tmp1); +int cvLsBandDQJac(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac, + CVodeMem cv_mem, N_Vector tmp1, N_Vector tmp2); /* Generic linit/lsetup/lsolve/lfree interface routines for CVode to call */ int cvLsInitialize(CVodeMem cv_mem); -int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); -int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, - N_Vector ycur, N_Vector fcur); +int cvLsSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, N_Vector fpred, + sunbooleantype* jcurPtr, N_Vector vtemp1, N_Vector vtemp2, + N_Vector vtemp3); +int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ycur, + N_Vector fcur); int cvLsFree(CVodeMem cv_mem); /* Auxilliary functions */ int cvLsInitializeCounters(CVLsMem cvls_mem); -int cvLs_AccessLMem(void* cvode_mem, const char* fname, - CVodeMem* cv_mem, CVLsMem* cvls_mem); +int cvLs_AccessLMem(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVLsMem* cvls_mem); /*================================================================= PART II: Backward Problems @@ -180,65 +179,73 @@ int cvLs_AccessLMem(void* cvode_mem, const char* fname, CVodeSetLinearSolverB attaches such a structure to the lmemB field of CVodeBMem -----------------------------------------------------------------*/ -typedef struct CVLsMemRecB { - - CVLsJacFnB jacB; - CVLsJacFnBS jacBS; - CVLsJacTimesSetupFnB jtsetupB; +typedef struct CVLsMemRecB +{ + CVLsJacFnB jacB; + CVLsJacFnBS jacBS; + CVLsJacTimesSetupFnB jtsetupB; CVLsJacTimesSetupFnBS jtsetupBS; - CVLsJacTimesVecFnB jtimesB; - CVLsJacTimesVecFnBS jtimesBS; - CVLsLinSysFnB linsysB; - CVLsLinSysFnBS linsysBS; - CVLsPrecSetupFnB psetB; - CVLsPrecSetupFnBS psetBS; - CVLsPrecSolveFnB psolveB; - CVLsPrecSolveFnBS psolveBS; - void *P_dataB; - -} *CVLsMemB; - + CVLsJacTimesVecFnB jtimesB; + CVLsJacTimesVecFnBS jtimesBS; + CVLsLinSysFnB linsysB; + CVLsLinSysFnBS linsysBS; + CVLsPrecSetupFnB psetB; + CVLsPrecSetupFnBS psetBS; + CVLsPrecSolveFnB psolveB; + CVLsPrecSolveFnBS psolveBS; + void* P_dataB; + +}* CVLsMemB; /*----------------------------------------------------------------- Prototypes of internal functions -----------------------------------------------------------------*/ int cvLsFreeB(CVodeBMem cvb_mem); -int cvLs_AccessLMemB(void *cvode_mem, int which, const char *fname, - CVodeMem *cv_mem, CVadjMem *ca_mem, - CVodeBMem *cvB_mem, CVLsMemB *cvlsB_mem); -int cvLs_AccessLMemBCur(void *cvode_mem, const char *fname, - CVodeMem *cv_mem, CVadjMem *ca_mem, - CVodeBMem *cvB_mem, CVLsMemB *cvlsB_mem); - +int cvLs_AccessLMemB(void* cvode_mem, int which, const char* fname, + CVodeMem* cv_mem, CVadjMem* ca_mem, CVodeBMem* cvB_mem, + CVLsMemB* cvlsB_mem); +int cvLs_AccessLMemBCur(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVadjMem* ca_mem, CVodeBMem* cvB_mem, + CVLsMemB* cvlsB_mem); /*================================================================= Error Messages =================================================================*/ -#define MSG_LS_CVMEM_NULL "Integrator memory is NULL." -#define MSG_LS_MEM_FAIL "A memory request failed." -#define MSG_LS_BAD_NVECTOR "A required vector operation is not implemented." -#define MSG_LS_BAD_LSTYPE "Incompatible linear solver type." -#define MSG_LS_LMEM_NULL "Linear solver memory is NULL." -#define MSG_LS_BAD_SIZES "Illegal bandwidth parameter(s). Must have 0 <= ml, mu <= N-1." -#define MSG_LS_BAD_EPLIN "eplifac < 0 illegal." -#define MSG_LS_BAD_PRETYPE "Illegal value for pretype. Legal values are PREC_NONE, PREC_LEFT, PREC_RIGHT, and PREC_BOTH." -#define MSG_LS_PSOLVE_REQ "pretype != PREC_NONE, but PSOLVE = NULL is illegal." -#define MSG_LS_BAD_GSTYPE "Illegal value for gstype. Legal values are MODIFIED_GS and CLASSICAL_GS." - -#define MSG_LS_PSET_FAILED "The preconditioner setup routine failed in an unrecoverable manner." -#define MSG_LS_PSOLVE_FAILED "The preconditioner solve routine failed in an unrecoverable manner." -#define MSG_LS_JTSETUP_FAILED "The Jacobian x vector setup routine failed in an unrecoverable manner." -#define MSG_LS_JTIMES_FAILED "The Jacobian x vector routine failed in an unrecoverable manner." -#define MSG_LS_JACFUNC_FAILED "The Jacobian routine failed in an unrecoverable manner." -#define MSG_LS_SUNMAT_FAILED "A SUNMatrix routine failed in an unrecoverable manner." - -#define MSG_LS_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." -#define MSG_LS_BAD_WHICH "Illegal value for which." -#define MSG_LS_LMEMB_NULL "Linear solver memory is NULL for the backward integration." -#define MSG_LS_BAD_TINTERP "Bad t for interpolation." - +#define MSG_LS_CVMEM_NULL "Integrator memory is NULL." +#define MSG_LS_MEM_FAIL "A memory request failed." +#define MSG_LS_BAD_NVECTOR "A required vector operation is not implemented." +#define MSG_LS_BAD_LSTYPE "Incompatible linear solver type." +#define MSG_LS_LMEM_NULL "Linear solver memory is NULL." +#define MSG_LS_BAD_SIZES \ + "Illegal bandwidth parameter(s). Must have 0 <= ml, mu <= N-1." +#define MSG_LS_BAD_EPLIN "eplifac < 0 illegal." +#define MSG_LS_BAD_PRETYPE \ + "Illegal value for pretype. Legal values are PREC_NONE, PREC_LEFT, " \ + "PREC_RIGHT, and PREC_BOTH." +#define MSG_LS_PSOLVE_REQ "pretype != PREC_NONE, but PSOLVE = NULL is illegal." +#define MSG_LS_BAD_GSTYPE \ + "Illegal value for gstype. Legal values are MODIFIED_GS and CLASSICAL_GS." + +#define MSG_LS_PSET_FAILED \ + "The preconditioner setup routine failed in an unrecoverable manner." +#define MSG_LS_PSOLVE_FAILED \ + "The preconditioner solve routine failed in an unrecoverable manner." +#define MSG_LS_JTSETUP_FAILED \ + "The Jacobian x vector setup routine failed in an unrecoverable manner." +#define MSG_LS_JTIMES_FAILED \ + "The Jacobian x vector routine failed in an unrecoverable manner." +#define MSG_LS_JACFUNC_FAILED \ + "The Jacobian routine failed in an unrecoverable manner." +#define MSG_LS_SUNMAT_FAILED \ + "A SUNMatrix routine failed in an unrecoverable manner." + +#define MSG_LS_NO_ADJ "Illegal attempt to call before calling CVodeAdjMalloc." +#define MSG_LS_BAD_WHICH "Illegal value for which." +#define MSG_LS_LMEMB_NULL \ + "Linear solver memory is NULL for the backward integration." +#define MSG_LS_BAD_TINTERP "Bad t for interpolation." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls.c index 0d1ccca1c..2cf29b569 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,52 +19,57 @@ #include "sundials/sundials_nvector_senswrapper.h" /* constant macros */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) /* private functions */ static int cvNlsResidual(N_Vector ycor, N_Vector res, void* cvode_mem); static int cvNlsFPFunction(N_Vector ycor, N_Vector res, void* cvode_mem); -static int cvNlsLSetup(booleantype jbad, booleantype* jcur, void* cvode_mem); +static int cvNlsLSetup(sunbooleantype jbad, sunbooleantype* jcur, + void* cvode_mem); static int cvNlsLSolve(N_Vector delta, void* cvode_mem); static int cvNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* cvode_mem); + sunrealtype tol, N_Vector ewt, void* cvode_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int CVodeSetNonlinearSolver(void *cvode_mem, SUNNonlinearSolver NLS) +int CVodeSetNonlinearSolver(void* cvode_mem, SUNNonlinearSolver NLS) { CVodeMem cv_mem; int retval; /* Return immediately if CVode memory is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetNonlinearSolver", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Return immediately if NLS memory is NULL */ - if (NLS == NULL) { - cvProcessError(NULL, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (NLS == NULL) + { + cvProcessError(NULL, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); return (CV_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* free any existing nonlinear solver */ if ((cv_mem->NLS != NULL) && (cv_mem->ownNLS)) + { retval = SUNNonlinSolFree(cv_mem->NLS); + } /* set SUNNonlinearSolver pointer */ cv_mem->NLS = NLS; @@ -74,53 +79,61 @@ int CVodeSetNonlinearSolver(void *cvode_mem, SUNNonlinearSolver NLS) cv_mem->ownNLS = SUNFALSE; /* set the nonlinear system function */ - if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) { + if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLS, cvNlsResidual); - } else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) { + } + else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLS, cvNlsFPFunction); - } else { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + } + else + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Invalid nonlinear solver type"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(cv_mem->NLS, cvNlsConvTest, cvode_mem); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(cv_mem->NLS, NLS_MAXCOR); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Reset the acnrmcur flag to SUNFALSE */ cv_mem->cv_acnrmcur = SUNFALSE; /* Set the nonlinear system RHS function */ - if (!(cv_mem->cv_f)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetNonlinearSolver", + if (!(cv_mem->cv_f)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "The ODE RHS function is NULL"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->nls_f = cv_mem->cv_f; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /*--------------------------------------------------------------- CVodeSetNlsRhsFn: @@ -128,48 +141,44 @@ int CVodeSetNonlinearSolver(void *cvode_mem, SUNNonlinearSolver NLS) side function to use in the evaluation of nonlinear system functions. ---------------------------------------------------------------*/ -int CVodeSetNlsRhsFn(void *cvode_mem, CVRhsFn f) +int CVodeSetNlsRhsFn(void* cvode_mem, CVRhsFn f) { CVodeMem cv_mem; - if (cvode_mem==NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetNlsRhsFn", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - if (f) - cv_mem->nls_f = f; - else - cv_mem->nls_f = cv_mem->cv_f; + if (f) { cv_mem->nls_f = f; } + else { cv_mem->nls_f = cv_mem->cv_f; } - return(CV_SUCCESS); + return (CV_SUCCESS); } - /*--------------------------------------------------------------- CVodeGetNonlinearSystemData: This routine provides access to the relevant data needed to compute the nonlinear system function. ---------------------------------------------------------------*/ -int CVodeGetNonlinearSystemData(void *cvode_mem, realtype *tcur, - N_Vector *ypred, N_Vector *yn, - N_Vector *fn, realtype *gamma, - realtype *rl1, N_Vector *zn1, - void **user_data) +int CVodeGetNonlinearSystemData(void* cvode_mem, sunrealtype* tcur, + N_Vector* ypred, N_Vector* yn, N_Vector* fn, + sunrealtype* gamma, sunrealtype* rl1, + N_Vector* zn1, void** user_data) { CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeGetNonlinearSystemData", - MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *tcur = cv_mem->cv_tn; *ypred = cv_mem->cv_zn[0]; @@ -180,74 +189,77 @@ int CVodeGetNonlinearSystemData(void *cvode_mem, realtype *tcur, *zn1 = cv_mem->cv_zn[1]; *user_data = cv_mem->cv_user_data; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ - int cvNlsInit(CVodeMem cvode_mem) { int retval; /* set the linear solver setup wrapper function */ if (cvode_mem->cv_lsetup) + { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLS, cvNlsLSetup); - else - retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLS, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLS, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODE", "cvNlsInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (cvode_mem->cv_lsolve) + { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLS, cvNlsLSolve); - else - retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLS, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLS, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODE", "cvNlsInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(cvode_mem->NLS); - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODE", "cvNlsInit", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsLSetup(booleantype jbad, booleantype* jcur, void* cvode_mem) +static int cvNlsLSetup(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem) { CVodeMem cv_mem; - int retval; + int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODE", "cvNlsLSetup", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* if the nonlinear solver marked the Jacobian as bad update convfail */ - if (jbad) - cv_mem->convfail = CV_FAIL_BAD_J; + if (jbad) { cv_mem->convfail = CV_FAIL_BAD_J; } /* setup the linear solver */ - retval = cv_mem->cv_lsetup(cv_mem, cv_mem->convfail, cv_mem->cv_y, cv_mem->cv_ftemp, - &(cv_mem->cv_jcur), cv_mem->cv_vtemp1, cv_mem->cv_vtemp2, + retval = cv_mem->cv_lsetup(cv_mem, cv_mem->convfail, cv_mem->cv_y, + cv_mem->cv_ftemp, &(cv_mem->cv_jcur), + cv_mem->cv_vtemp1, cv_mem->cv_vtemp2, cv_mem->cv_vtemp3); cv_mem->cv_nsetups++; @@ -261,88 +273,94 @@ static int cvNlsLSetup(booleantype jbad, booleantype* jcur, void* cvode_mem) cv_mem->cv_crateS = ONE; cv_mem->cv_nstlp = cv_mem->cv_nst; - if (retval < 0) return(CV_LSETUP_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSETUP_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsLSolve(N_Vector delta, void* cvode_mem) { CVodeMem cv_mem; - int retval; + int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODE", "cvNlsLSolve", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; - retval = cv_mem->cv_lsolve(cv_mem, delta, cv_mem->cv_ewt, cv_mem->cv_y, cv_mem->cv_ftemp); + retval = cv_mem->cv_lsolve(cv_mem, delta, cv_mem->cv_ewt, cv_mem->cv_y, + cv_mem->cv_ftemp); - if (retval < 0) return(CV_LSOLVE_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSOLVE_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector delta, - realtype tol, N_Vector ewt, void* cvode_mem) + sunrealtype tol, N_Vector ewt, void* cvode_mem) { CVodeMem cv_mem; int m, retval; - realtype del; - realtype dcon; + sunrealtype del; + sunrealtype dcon; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODE", "cvNlsConvTest", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* compute the norm of the correction */ del = N_VWrmsNorm(delta, ewt); /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != CV_SUCCESS) return(CV_MEM_NULL); + if (retval != CV_SUCCESS) { return (CV_MEM_NULL); } /* Test for convergence. If m > 0, an estimate of the convergence rate constant is stored in crate, and used in the test. */ - if (m > 0) { - cv_mem->cv_crate = SUNMAX(CRDOWN * cv_mem->cv_crate, del/cv_mem->cv_delp); + if (m > 0) + { + cv_mem->cv_crate = SUNMAX(CRDOWN * cv_mem->cv_crate, del / cv_mem->cv_delp); } dcon = del * SUNMIN(ONE, cv_mem->cv_crate) / tol; - if (dcon <= ONE) { - cv_mem->cv_acnrm = (m==0) ? del : N_VWrmsNorm(ycor, ewt); + if (dcon <= ONE) + { + cv_mem->cv_acnrm = (m == 0) ? del : N_VWrmsNorm(ycor, ewt); cv_mem->cv_acnrmcur = SUNTRUE; - return(CV_SUCCESS); /* Nonlinear system was solved successfully */ + return (CV_SUCCESS); /* Nonlinear system was solved successfully */ } /* check if the iteration seems to be diverging */ - if ((m >= 1) && (del > RDIV*cv_mem->cv_delp)) return(SUN_NLS_CONV_RECVR); + if ((m >= 1) && (del > RDIV * cv_mem->cv_delp)) + { + return (SUN_NLS_CONV_RECVR); + } /* Save norm of correction and loop again */ cv_mem->cv_delp = del; /* Not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } - static int cvNlsResidual(N_Vector ycor, N_Vector res, void* cvode_mem) { CVodeMem cv_mem; int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODE", "cvNlsResidual", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* update the state based on the current correction */ N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, cv_mem->cv_y); @@ -351,40 +369,39 @@ static int cvNlsResidual(N_Vector ycor, N_Vector res, void* cvode_mem) retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, cv_mem->cv_ftemp, cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(RHSFUNC_RECVR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (RHSFUNC_RECVR); } /* compute the resiudal */ N_VLinearSum(cv_mem->cv_rl1, cv_mem->cv_zn[1], ONE, ycor, res); N_VLinearSum(-cv_mem->cv_gamma, cv_mem->cv_ftemp, ONE, res, res); - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsFPFunction(N_Vector ycor, N_Vector res, void* cvode_mem) { - CVodeMem cv_mem; + CVodeMem cv_mem; int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODE", "cvNlsFPFunction", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* update the state based on the current correction */ N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, cv_mem->cv_y); /* evaluate the rhs function */ - retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, res, - cv_mem->cv_user_data); + retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, res, cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(RHSFUNC_RECVR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (RHSFUNC_RECVR); } N_VLinearSum(cv_mem->cv_h, res, -ONE, cv_mem->cv_zn[1], res); N_VScale(cv_mem->cv_rl1, res, res); - return(CV_SUCCESS); + return (CV_SUCCESS); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_sim.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_sim.c index 706124be9..5298f0d6a 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_sim.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_sim.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -28,7 +28,7 @@ #include "sundials/sundials_nvector_senswrapper.h" /* constant macros */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) /* private functions */ static int cvNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, @@ -36,67 +36,68 @@ static int cvNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, static int cvNlsFPFunctionSensSim(N_Vector ycorSim, N_Vector resSim, void* cvode_mem); -static int cvNlsLSetupSensSim(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensSim(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem); static int cvNlsLSolveSensSim(N_Vector deltaSim, void* cvode_mem); -static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, - N_Vector ycorSim, N_Vector delSim, - realtype tol, N_Vector ewtSim, void* cvode_mem); +static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycorSim, + N_Vector delSim, sunrealtype tol, + N_Vector ewtSim, void* cvode_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int CVodeSetNonlinearSolverSensSim(void *cvode_mem, SUNNonlinearSolver NLS) +int CVodeSetNonlinearSolverSensSim(void* cvode_mem, SUNNonlinearSolver NLS) { CVodeMem cv_mem; int retval, is; /* Return immediately if CVode memory is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeSetNonlinearSolverSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Return immediately if NLS memory is NULL */ - if (NLS == NULL) { - cvProcessError(NULL, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (NLS == NULL) + { + cvProcessError(NULL, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); return (CV_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that sensitivities were initialized */ - if (!(cv_mem->cv_sensi)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (!(cv_mem->cv_sensi)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that simultaneous corrector was selected */ - if (cv_mem->cv_ism != CV_SIMULTANEOUS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (cv_mem->cv_ism != CV_SIMULTANEOUS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Sensitivity solution method is not CV_SIMULTANEOUS"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* free any existing nonlinear solver */ if ((cv_mem->NLSsim != NULL) && (cv_mem->ownNLSsim)) + { retval = SUNNonlinSolFree(cv_mem->NLSsim); + } /* set SUNNonlinearSolver pointer */ cv_mem->NLSsim = NLS; @@ -106,120 +107,130 @@ int CVodeSetNonlinearSolverSensSim(void *cvode_mem, SUNNonlinearSolver NLS) cv_mem->ownNLSsim = SUNFALSE; /* set the nonlinear system function */ - if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) { + if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSsim, cvNlsResidualSensSim); - } else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) { + } + else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSsim, cvNlsFPFunctionSensSim); - } else { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + } + else + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Invalid nonlinear solver type"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(cv_mem->NLSsim, cvNlsConvTestSensSim, cvode_mem); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(cv_mem->NLSsim, NLS_MAXCOR); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* create vector wrappers if necessary */ - if (cv_mem->simMallocDone == SUNFALSE) { - - cv_mem->zn0Sim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); - if (cv_mem->zn0Sim == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensSim", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->simMallocDone == SUNFALSE) + { + cv_mem->zn0Sim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns + 1, + cv_mem->cv_sunctx); + if (cv_mem->zn0Sim == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - cv_mem->ycorSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); - if (cv_mem->ycorSim == NULL) { + cv_mem->ycorSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns + 1, + cv_mem->cv_sunctx); + if (cv_mem->ycorSim == NULL) + { N_VDestroy(cv_mem->zn0Sim); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensSim", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - cv_mem->ewtSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); - if (cv_mem->ewtSim == NULL) { + cv_mem->ewtSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns + 1, + cv_mem->cv_sunctx); + if (cv_mem->ewtSim == NULL) + { N_VDestroy(cv_mem->zn0Sim); N_VDestroy(cv_mem->ycorSim); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensSim", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->simMallocDone = SUNTRUE; } /* attach vectors to vector wrappers */ - NV_VEC_SW(cv_mem->zn0Sim, 0) = cv_mem->cv_zn[0]; + NV_VEC_SW(cv_mem->zn0Sim, 0) = cv_mem->cv_zn[0]; NV_VEC_SW(cv_mem->ycorSim, 0) = cv_mem->cv_acor; - NV_VEC_SW(cv_mem->ewtSim, 0) = cv_mem->cv_ewt; + NV_VEC_SW(cv_mem->ewtSim, 0) = cv_mem->cv_ewt; - for (is=0; is < cv_mem->cv_Ns; is++) { - NV_VEC_SW(cv_mem->zn0Sim, is+1) = cv_mem->cv_znS[0][is]; - NV_VEC_SW(cv_mem->ycorSim, is+1) = cv_mem->cv_acorS[is]; - NV_VEC_SW(cv_mem->ewtSim, is+1) = cv_mem->cv_ewtS[is]; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + NV_VEC_SW(cv_mem->zn0Sim, is + 1) = cv_mem->cv_znS[0][is]; + NV_VEC_SW(cv_mem->ycorSim, is + 1) = cv_mem->cv_acorS[is]; + NV_VEC_SW(cv_mem->ewtSim, is + 1) = cv_mem->cv_ewtS[is]; } /* Reset the acnrmcur flag to SUNFALSE */ cv_mem->cv_acnrmcur = SUNFALSE; /* Set the nonlinear system RHS function */ - if (!(cv_mem->cv_f)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensSim", + if (!(cv_mem->cv_f)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "The ODE RHS function is NULL"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } cv_mem->nls_f = cv_mem->cv_f; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /*--------------------------------------------------------------- CVodeGetNonlinearSystemDataSens: This routine provides access to the relevant data needed to compute the nonlinear system function. ---------------------------------------------------------------*/ -int CVodeGetNonlinearSystemDataSens(void *cvode_mem, realtype *tcur, - N_Vector **ySpred, N_Vector **ySn, - realtype *gamma, realtype *rl1, - N_Vector **znS1, void **user_data) +int CVodeGetNonlinearSystemDataSens(void* cvode_mem, sunrealtype* tcur, + N_Vector** ySpred, N_Vector** ySn, + sunrealtype* gamma, sunrealtype* rl1, + N_Vector** znS1, void** user_data) { CVodeMem cv_mem; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeGetNonlinearSystemDataSens", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; *tcur = cv_mem->cv_tn; *ySpred = cv_mem->cv_znS[0]; @@ -229,72 +240,73 @@ int CVodeGetNonlinearSystemDataSens(void *cvode_mem, realtype *tcur, *znS1 = cv_mem->cv_znS[1]; *user_data = cv_mem->cv_user_data; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ - int cvNlsInitSensSim(CVodeMem cvode_mem) { int retval; /* set the linear solver setup wrapper function */ if (cvode_mem->cv_lsetup) + { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSsim, cvNlsLSetupSensSim); - else - retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSsim, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSsim, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (cvode_mem->cv_lsolve) + { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSsim, cvNlsLSolveSensSim); - else - retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSsim, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSsim, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(cvode_mem->NLSsim); - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensSim", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsLSetupSensSim(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensSim(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem) { CVodeMem cv_mem; int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSetupSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* if the nonlinear solver marked the Jacobian as bad update convfail */ - if (jbad) - cv_mem->convfail = CV_FAIL_BAD_J; + if (jbad) { cv_mem->convfail = CV_FAIL_BAD_J; } /* setup the linear solver */ retval = cv_mem->cv_lsetup(cv_mem, cv_mem->convfail, cv_mem->cv_y, @@ -313,81 +325,80 @@ static int cvNlsLSetupSensSim(booleantype jbad, booleantype* jcur, cv_mem->cv_crateS = ONE; cv_mem->cv_nstlp = cv_mem->cv_nst; - if (retval < 0) return(CV_LSETUP_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSETUP_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsLSolveSensSim(N_Vector deltaSim, void* cvode_mem) { CVodeMem cv_mem; int retval, is; N_Vector delta; - N_Vector *deltaS; + N_Vector* deltaS; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSolveSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract state delta from the vector wrapper */ - delta = NV_VEC_SW(deltaSim,0); + delta = NV_VEC_SW(deltaSim, 0); /* solve the state linear system */ retval = cv_mem->cv_lsolve(cv_mem, delta, cv_mem->cv_ewt, cv_mem->cv_y, cv_mem->cv_ftemp); - if (retval < 0) return(CV_LSOLVE_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSOLVE_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } /* extract sensitivity deltas from the vector wrapper */ - deltaS = NV_VECS_SW(deltaSim)+1; + deltaS = NV_VECS_SW(deltaSim) + 1; /* solve the sensitivity linear systems */ - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { retval = cv_mem->cv_lsolve(cv_mem, deltaS[is], cv_mem->cv_ewtS[is], cv_mem->cv_y, cv_mem->cv_ftemp); - if (retval < 0) return(CV_LSOLVE_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSOLVE_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, - N_Vector ycorSim, N_Vector deltaSim, - realtype tol, N_Vector ewtSim, void* cvode_mem) +static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycorSim, + N_Vector deltaSim, sunrealtype tol, + N_Vector ewtSim, void* cvode_mem) { CVodeMem cv_mem; int m, retval; - realtype del, delS, Del; - realtype dcon; + sunrealtype del, delS, Del; + sunrealtype dcon; N_Vector ycor, delta, ewt; N_Vector *deltaS, *ewtS; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsConvTestSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract the current state and sensitivity corrections */ - ycor = NV_VEC_SW(ycorSim,0); + ycor = NV_VEC_SW(ycorSim, 0); /* extract state and sensitivity deltas */ - delta = NV_VEC_SW(deltaSim,0); - deltaS = NV_VECS_SW(deltaSim)+1; + delta = NV_VEC_SW(deltaSim, 0); + deltaS = NV_VECS_SW(deltaSim) + 1; /* extract state and sensitivity error weights */ - ewt = NV_VEC_SW(ewtSim,0); - ewtS = NV_VECS_SW(ewtSim)+1; + ewt = NV_VEC_SW(ewtSim, 0); + ewtS = NV_VECS_SW(ewtSim) + 1; /* compute the norm of the state and sensitivity corrections */ del = N_VWrmsNorm(delta, ewt); @@ -398,7 +409,7 @@ static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != CV_SUCCESS) return(CV_MEM_NULL); + if (retval != CV_SUCCESS) { return (CV_MEM_NULL); } /* Test for convergence. If m > 0, an estimate of the convergence rate constant is stored in crate, and used in the test. @@ -408,53 +419,57 @@ static int cvNlsConvTestSensSim(SUNNonlinearSolver NLS, in the error test and thus it has different forms depending on errconS (and this explains why we have to carry around del and delS). */ - if (m > 0) { - cv_mem->cv_crate = SUNMAX(CRDOWN * cv_mem->cv_crate, Del/cv_mem->cv_delp); + if (m > 0) + { + cv_mem->cv_crate = SUNMAX(CRDOWN * cv_mem->cv_crate, Del / cv_mem->cv_delp); } dcon = Del * SUNMIN(ONE, cv_mem->cv_crate) / tol; /* check if nonlinear system was solved successfully */ - if (dcon <= ONE) { - if (m == 0) { - cv_mem->cv_acnrm = (cv_mem->cv_errconS) ? delS : del; - } else { - cv_mem->cv_acnrm = (cv_mem->cv_errconS) ? - N_VWrmsNorm(ycorSim, ewtSim) : N_VWrmsNorm(ycor, ewt); + if (dcon <= ONE) + { + if (m == 0) { cv_mem->cv_acnrm = (cv_mem->cv_errconS) ? delS : del; } + else + { + cv_mem->cv_acnrm = (cv_mem->cv_errconS) ? N_VWrmsNorm(ycorSim, ewtSim) + : N_VWrmsNorm(ycor, ewt); } cv_mem->cv_acnrmcur = SUNTRUE; - return(CV_SUCCESS); + return (CV_SUCCESS); } /* check if the iteration seems to be diverging */ - if ((m >= 1) && (Del > RDIV*cv_mem->cv_delp)) return(SUN_NLS_CONV_RECVR); + if ((m >= 1) && (Del > RDIV * cv_mem->cv_delp)) + { + return (SUN_NLS_CONV_RECVR); + } /* Save norm of correction and loop again */ cv_mem->cv_delp = Del; /* Not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } - static int cvNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, void* cvode_mem) { CVodeMem cv_mem; int retval; N_Vector ycor, res; N_Vector *ycorS, *resS; - realtype cvals[3]; + sunrealtype cvals[3]; N_Vector* XXvecs[3]; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsResidualSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract state and residual vectors from the vector wrapper */ - ycor = NV_VEC_SW(ycorSim,0); - res = NV_VEC_SW(resSim,0); + ycor = NV_VEC_SW(ycorSim, 0); + res = NV_VEC_SW(resSim, 0); /* update the state based on the current correction */ N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, cv_mem->cv_y); @@ -463,100 +478,98 @@ static int cvNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, void* cvode_m retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, cv_mem->cv_ftemp, cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(RHSFUNC_RECVR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (RHSFUNC_RECVR); } /* compute the resiudal */ N_VLinearSum(cv_mem->cv_rl1, cv_mem->cv_zn[1], ONE, ycor, res); N_VLinearSum(-cv_mem->cv_gamma, cv_mem->cv_ftemp, ONE, res, res); /* extract sensitivity and residual vectors from the vector wrapper */ - ycorS = NV_VECS_SW(ycorSim)+1; - resS = NV_VECS_SW(resSim)+1; + ycorS = NV_VECS_SW(ycorSim) + 1; + resS = NV_VECS_SW(resSim) + 1; /* update sensitivities based on the current correction */ - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, ycorS, cv_mem->cv_yS); - if (retval != CV_SUCCESS) return(CV_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + ycorS, cv_mem->cv_yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* evaluate the sensitivity rhs function */ - retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, cv_mem->cv_ftemp, - cv_mem->cv_yS, cv_mem->cv_ftempS, + retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, + cv_mem->cv_ftemp, cv_mem->cv_yS, cv_mem->cv_ftempS, cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* compute the sensitivity resiudal */ - cvals[0] = cv_mem->cv_rl1; XXvecs[0] = cv_mem->cv_znS[1]; - cvals[1] = ONE; XXvecs[1] = ycorS; - cvals[2] = -cv_mem->cv_gamma; XXvecs[2] = cv_mem->cv_ftempS; + cvals[0] = cv_mem->cv_rl1; + XXvecs[0] = cv_mem->cv_znS[1]; + cvals[1] = ONE; + XXvecs[1] = ycorS; + cvals[2] = -cv_mem->cv_gamma; + XXvecs[2] = cv_mem->cv_ftempS; - retval = N_VLinearCombinationVectorArray(cv_mem->cv_Ns, - 3, cvals, XXvecs, resS); - if (retval != CV_SUCCESS) return(CV_VECTOROP_ERR); + retval = N_VLinearCombinationVectorArray(cv_mem->cv_Ns, 3, cvals, XXvecs, resS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsFPFunctionSensSim(N_Vector ycorSim, N_Vector resSim, void* cvode_mem) +static int cvNlsFPFunctionSensSim(N_Vector ycorSim, N_Vector resSim, + void* cvode_mem) { - CVodeMem cv_mem; - int retval, is; - N_Vector ycor, res; - N_Vector *ycorS, *resS; - - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsFPFunctionSensSim", MSGCV_NO_MEM); - return(CV_MEM_NULL); + CVodeMem cv_mem; + int retval, is; + N_Vector ycor, res; + N_Vector *ycorS, *resS; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract state and residual vectors from the vector wrapper */ - ycor = NV_VEC_SW(ycorSim,0); - res = NV_VEC_SW(resSim,0); + ycor = NV_VEC_SW(ycorSim, 0); + res = NV_VEC_SW(resSim, 0); /* update the state based on the current correction */ N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, cv_mem->cv_y); /* evaluate the rhs function */ - retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, res, - cv_mem->cv_user_data); + retval = cv_mem->nls_f(cv_mem->cv_tn, cv_mem->cv_y, res, cv_mem->cv_user_data); cv_mem->cv_nfe++; - if (retval < 0) return(CV_RHSFUNC_FAIL); - if (retval > 0) return(RHSFUNC_RECVR); + if (retval < 0) { return (CV_RHSFUNC_FAIL); } + if (retval > 0) { return (RHSFUNC_RECVR); } /* evaluate fixed point function */ N_VLinearSum(cv_mem->cv_h, res, -ONE, cv_mem->cv_zn[1], res); N_VScale(cv_mem->cv_rl1, res, res); /* extract sensitivity and residual vectors from the vector wrapper */ - ycorS = NV_VECS_SW(ycorSim)+1; - resS = NV_VECS_SW(resSim)+1; + ycorS = NV_VECS_SW(ycorSim) + 1; + resS = NV_VECS_SW(resSim) + 1; /* update the sensitivities based on the current correction */ - N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, ycorS, cv_mem->cv_yS); + N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, ycorS, + cv_mem->cv_yS); /* evaluate the sensitivity rhs function */ - retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, res, - cv_mem->cv_yS, resS, - cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); + retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, res, + cv_mem->cv_yS, resS, cv_mem->cv_vtemp1, + cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* evaluate sensitivity fixed point function */ - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VLinearSum(cv_mem->cv_h, resS[is], -ONE, cv_mem->cv_znS[1][is], resS[is]); N_VScale(cv_mem->cv_rl1, resS[is], resS[is]); } - return(CV_SUCCESS); + return (CV_SUCCESS); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg.c index fba4c6b57..55fb8d75f 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,7 +19,7 @@ #include "sundials/sundials_nvector_senswrapper.h" /* constant macros */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) /* private functions */ static int cvNlsResidualSensStg(N_Vector ycorStg, N_Vector resStg, @@ -27,67 +27,68 @@ static int cvNlsResidualSensStg(N_Vector ycorStg, N_Vector resStg, static int cvNlsFPFunctionSensStg(N_Vector ycorStg, N_Vector resStg, void* cvode_mem); -static int cvNlsLSetupSensStg(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensStg(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem); static int cvNlsLSolveSensStg(N_Vector deltaStg, void* cvode_mem); -static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, - N_Vector ycorStg, N_Vector delStg, - realtype tol, N_Vector ewtStg, void* cvode_mem); +static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycorStg, + N_Vector delStg, sunrealtype tol, + N_Vector ewtStg, void* cvode_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int CVodeSetNonlinearSolverSensStg(void *cvode_mem, SUNNonlinearSolver NLS) +int CVodeSetNonlinearSolverSensStg(void* cvode_mem, SUNNonlinearSolver NLS) { CVodeMem cv_mem; int retval, is; /* Return immediately if CVode memory is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeSetNonlinearSolverSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Return immediately if NLS memory is NULL */ - if (NLS == NULL) { - cvProcessError(NULL, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (NLS == NULL) + { + cvProcessError(NULL, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); return (CV_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that sensitivities were initialized */ - if (!(cv_mem->cv_sensi)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (!(cv_mem->cv_sensi)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that staggered corrector was selected */ - if (cv_mem->cv_ism != CV_STAGGERED) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (cv_mem->cv_ism != CV_STAGGERED) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Sensitivity solution method is not CV_STAGGERED"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* free any existing nonlinear solver */ if ((cv_mem->NLSstg != NULL) && (cv_mem->ownNLSstg)) + { retval = SUNNonlinSolFree(cv_mem->NLSstg); + } /* set SUNNonlinearSolver pointer */ cv_mem->NLSstg = NLS; @@ -97,149 +98,158 @@ int CVodeSetNonlinearSolverSensStg(void *cvode_mem, SUNNonlinearSolver NLS) cv_mem->ownNLSstg = SUNFALSE; /* set the nonlinear system function */ - if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) { + if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSstg, cvNlsResidualSensStg); - } else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) { + } + else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSstg, cvNlsFPFunctionSensStg); - } else { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + } + else + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Invalid nonlinear solver type"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(cv_mem->NLSstg, cvNlsConvTestSensStg, cvode_mem); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(cv_mem->NLSstg, NLS_MAXCOR); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* create vector wrappers if necessary */ - if (cv_mem->stgMallocDone == SUNFALSE) { - - cv_mem->zn0Stg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); - if (cv_mem->zn0Stg == NULL) { - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensStg", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + if (cv_mem->stgMallocDone == SUNFALSE) + { + cv_mem->zn0Stg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); + if (cv_mem->zn0Stg == NULL) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - cv_mem->ycorStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); - if (cv_mem->ycorStg == NULL) { + cv_mem->ycorStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); + if (cv_mem->ycorStg == NULL) + { N_VDestroy(cv_mem->zn0Stg); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensStg", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } - cv_mem->ewtStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); - if (cv_mem->ewtStg == NULL) { + cv_mem->ewtStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); + if (cv_mem->ewtStg == NULL) + { N_VDestroy(cv_mem->zn0Stg); N_VDestroy(cv_mem->ycorStg); - cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", - "CVodeSetNonlinearSolverSensStg", MSGCV_MEM_FAIL); - return(CV_MEM_FAIL); + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGCV_MEM_FAIL); + return (CV_MEM_FAIL); } cv_mem->stgMallocDone = SUNTRUE; } /* attach vectors to vector wrappers */ - for (is=0; is < cv_mem->cv_Ns; is++) { - NV_VEC_SW(cv_mem->zn0Stg, is) = cv_mem->cv_znS[0][is]; + for (is = 0; is < cv_mem->cv_Ns; is++) + { + NV_VEC_SW(cv_mem->zn0Stg, is) = cv_mem->cv_znS[0][is]; NV_VEC_SW(cv_mem->ycorStg, is) = cv_mem->cv_acorS[is]; - NV_VEC_SW(cv_mem->ewtStg, is) = cv_mem->cv_ewtS[is]; + NV_VEC_SW(cv_mem->ewtStg, is) = cv_mem->cv_ewtS[is]; } /* Reset the acnrmScur flag to SUNFALSE */ cv_mem->cv_acnrmScur = SUNFALSE; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ - int cvNlsInitSensStg(CVodeMem cvode_mem) { int retval; /* set the linear solver setup wrapper function */ if (cvode_mem->cv_lsetup) + { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg, cvNlsLSetupSensStg); - else - retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (cvode_mem->cv_lsolve) + { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg, cvNlsLSolveSensStg); - else - retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(cvode_mem->NLSstg); - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsLSetupSensStg(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensStg(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem) { CVodeMem cv_mem; int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSetupSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* if the nonlinear solver marked the Jacobian as bad update convfail */ - if (jbad) - cv_mem->convfail = CV_FAIL_BAD_J; + if (jbad) { cv_mem->convfail = CV_FAIL_BAD_J; } /* setup the linear solver */ retval = cv_mem->cv_lsetup(cv_mem, cv_mem->convfail, cv_mem->cv_y, @@ -252,64 +262,63 @@ static int cvNlsLSetupSensStg(booleantype jbad, booleantype* jcur, /* update Jacobian status */ *jcur = cv_mem->cv_jcur; - cv_mem->cv_gamrat = ONE; - cv_mem->cv_gammap = cv_mem->cv_gamma; - cv_mem->cv_crate = ONE; - cv_mem->cv_crateS = ONE; - cv_mem->cv_nstlp = cv_mem->cv_nst; + cv_mem->cv_gamrat = ONE; + cv_mem->cv_gammap = cv_mem->cv_gamma; + cv_mem->cv_crate = ONE; + cv_mem->cv_crateS = ONE; + cv_mem->cv_nstlp = cv_mem->cv_nst; - if (retval < 0) return(CV_LSETUP_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSETUP_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsLSolveSensStg(N_Vector deltaStg, void* cvode_mem) { CVodeMem cv_mem; int retval, is; - N_Vector *deltaS; + N_Vector* deltaS; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSolveSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract sensitivity deltas from the vector wrapper */ deltaS = NV_VECS_SW(deltaStg); /* solve the sensitivity linear systems */ - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { retval = cv_mem->cv_lsolve(cv_mem, deltaS[is], cv_mem->cv_ewtS[is], cv_mem->cv_y, cv_mem->cv_ftemp); - if (retval < 0) return(CV_LSOLVE_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSOLVE_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, - N_Vector ycorStg, N_Vector deltaStg, - realtype tol, N_Vector ewtStg, void* cvode_mem) +static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycorStg, + N_Vector deltaStg, sunrealtype tol, + N_Vector ewtStg, void* cvode_mem) { CVodeMem cv_mem; int m, retval; - realtype Del; - realtype dcon; + sunrealtype Del; + sunrealtype dcon; N_Vector *ycorS, *deltaS, *ewtS; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsConvTestSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract the current sensitivity corrections */ ycorS = NV_VECS_SW(ycorStg); @@ -325,7 +334,7 @@ static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != CV_SUCCESS) return(CV_MEM_NULL); + if (retval != CV_SUCCESS) { return (CV_MEM_NULL); } /* Test for convergence. If m > 0, an estimate of the convergence rate constant is stored in crate, and used in the test. @@ -335,115 +344,119 @@ static int cvNlsConvTestSensStg(SUNNonlinearSolver NLS, in the error test and thus it has different forms depending on errconS (and this explains why we have to carry around del and delS). */ - if (m > 0) { - cv_mem->cv_crateS = SUNMAX(CRDOWN * cv_mem->cv_crateS, Del/cv_mem->cv_delp); + if (m > 0) + { + cv_mem->cv_crateS = SUNMAX(CRDOWN * cv_mem->cv_crateS, Del / cv_mem->cv_delp); } dcon = Del * SUNMIN(ONE, cv_mem->cv_crateS) / tol; /* check if nonlinear system was solved successfully */ - if (dcon <= ONE) { - if (cv_mem->cv_errconS) { - cv_mem->cv_acnrmS = (m==0) ? Del : cvSensNorm(cv_mem, ycorS, ewtS); + if (dcon <= ONE) + { + if (cv_mem->cv_errconS) + { + cv_mem->cv_acnrmS = (m == 0) ? Del : cvSensNorm(cv_mem, ycorS, ewtS); cv_mem->cv_acnrmScur = SUNTRUE; } - return(CV_SUCCESS); + return (CV_SUCCESS); } /* check if the iteration seems to be diverging */ - if ((m >= 1) && (Del > RDIV*cv_mem->cv_delp)) return(SUN_NLS_CONV_RECVR); + if ((m >= 1) && (Del > RDIV * cv_mem->cv_delp)) + { + return (SUN_NLS_CONV_RECVR); + } /* Save norm of correction and loop again */ cv_mem->cv_delp = Del; /* Not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } - static int cvNlsResidualSensStg(N_Vector ycorStg, N_Vector resStg, void* cvode_mem) { CVodeMem cv_mem; int retval; N_Vector *ycorS, *resS; - realtype cvals[3]; + sunrealtype cvals[3]; N_Vector* XXvecs[3]; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsResidualSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract sensitivity and residual vectors from the vector wrapper */ ycorS = NV_VECS_SW(ycorStg); resS = NV_VECS_SW(resStg); /* update sensitivities based on the current correction */ - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, ycorS, cv_mem->cv_yS); - if (retval != CV_SUCCESS) return(CV_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + ycorS, cv_mem->cv_yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* evaluate the sensitivity rhs function */ - retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, cv_mem->cv_ftemp, - cv_mem->cv_yS, cv_mem->cv_ftempS, + retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, + cv_mem->cv_ftemp, cv_mem->cv_yS, cv_mem->cv_ftempS, cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* compute the sensitivity resiudal */ - cvals[0] = cv_mem->cv_rl1; XXvecs[0] = cv_mem->cv_znS[1]; - cvals[1] = ONE; XXvecs[1] = ycorS; - cvals[2] = -cv_mem->cv_gamma; XXvecs[2] = cv_mem->cv_ftempS; + cvals[0] = cv_mem->cv_rl1; + XXvecs[0] = cv_mem->cv_znS[1]; + cvals[1] = ONE; + XXvecs[1] = ycorS; + cvals[2] = -cv_mem->cv_gamma; + XXvecs[2] = cv_mem->cv_ftempS; - retval = N_VLinearCombinationVectorArray(cv_mem->cv_Ns, - 3, cvals, XXvecs, resS); - if (retval != CV_SUCCESS) return(CV_VECTOROP_ERR); + retval = N_VLinearCombinationVectorArray(cv_mem->cv_Ns, 3, cvals, XXvecs, resS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsFPFunctionSensStg(N_Vector ycorStg, N_Vector resStg, void* cvode_mem) +static int cvNlsFPFunctionSensStg(N_Vector ycorStg, N_Vector resStg, + void* cvode_mem) { - CVodeMem cv_mem; - int retval, is; - N_Vector *ycorS, *resS; - - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsFPFunctionSensStg", MSGCV_NO_MEM); - return(CV_MEM_NULL); + CVodeMem cv_mem; + int retval, is; + N_Vector *ycorS, *resS; + + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* extract sensitivity and residual vectors from the vector wrapper */ ycorS = NV_VECS_SW(ycorStg); resS = NV_VECS_SW(resStg); /* update the sensitivities based on the current correction */ - retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, - ONE, cv_mem->cv_znS[0], - ONE, ycorS, cv_mem->cv_yS); - if (retval != CV_SUCCESS) return(CV_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, + ycorS, cv_mem->cv_yS); + if (retval != CV_SUCCESS) { return (CV_VECTOROP_ERR); } /* evaluate the sensitivity rhs function */ - retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, cv_mem->cv_ftemp, - cv_mem->cv_yS, resS, + retval = cvSensRhsWrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, + cv_mem->cv_ftemp, cv_mem->cv_yS, resS, cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* evaluate sensitivity fixed point function */ - for (is=0; iscv_Ns; is++) { + for (is = 0; is < cv_mem->cv_Ns; is++) + { N_VLinearSum(cv_mem->cv_h, resS[is], -ONE, cv_mem->cv_znS[1][is], resS[is]); N_VScale(cv_mem->cv_rl1, resS[is], resS[is]); } - return(CV_SUCCESS); + return (CV_SUCCESS); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg1.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg1.c index 367374902..c292572b1 100644 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg1.c +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_nls_stg1.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,75 +18,74 @@ #include "sundials/sundials_math.h" /* constant macros */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) /* private functions */ -static int cvNlsResidualSensStg1(N_Vector ycor, N_Vector res, - void* cvode_mem); -static int cvNlsFPFunctionSensStg1(N_Vector ycor, N_Vector res, - void* cvode_mem); +static int cvNlsResidualSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem); +static int cvNlsFPFunctionSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem); -static int cvNlsLSetupSensStg1(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensStg1(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem); static int cvNlsLSolveSensStg1(N_Vector delta, void* cvode_mem); -static int cvNlsConvTestSensStg1(SUNNonlinearSolver NLS, - N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* cvode_mem); +static int cvNlsConvTestSensStg1(SUNNonlinearSolver NLS, N_Vector ycor, + N_Vector del, sunrealtype tol, N_Vector ewt, + void* cvode_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int CVodeSetNonlinearSolverSensStg1(void *cvode_mem, SUNNonlinearSolver NLS) +int CVodeSetNonlinearSolverSensStg1(void* cvode_mem, SUNNonlinearSolver NLS) { CVodeMem cv_mem; int retval; /* Return immediately if CVode memory is NULL */ - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "CVodeSetNonlinearSolverSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* Return immediately if NLS memory is NULL */ - if (NLS == NULL) { - cvProcessError(NULL, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (NLS == NULL) + { + cvProcessError(NULL, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); return (CV_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that sensitivities were initialized */ - if (!(cv_mem->cv_sensi)) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (!(cv_mem->cv_sensi)) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NO_SENSI); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* check that staggered corrector was selected */ - if (cv_mem->cv_ism != CV_STAGGERED1) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (cv_mem->cv_ism != CV_STAGGERED1) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Sensitivity solution method is not CV_STAGGERED1"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* free any existing nonlinear solver */ if ((cv_mem->NLSstg1 != NULL) && (cv_mem->ownNLSstg1)) - retval = SUNNonlinSolFree(cv_mem->NLSstg1); + { + retval = SUNNonlinSolFree(cv_mem->NLSstg1); + } /* set SUNNonlinearSolver pointer */ cv_mem->NLSstg1 = NLS; @@ -96,115 +95,120 @@ int CVodeSetNonlinearSolverSensStg1(void *cvode_mem, SUNNonlinearSolver NLS) cv_mem->ownNLSstg1 = SUNFALSE; /* set the nonlinear system function */ - if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) { + if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_ROOTFIND) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSstg1, cvNlsResidualSensStg1); - } else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) { + } + else if (SUNNonlinSolGetType(NLS) == SUNNONLINEARSOLVER_FIXEDPOINT) + { retval = SUNNonlinSolSetSysFn(cv_mem->NLSstg1, cvNlsFPFunctionSensStg1); - } else { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + } + else + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Invalid nonlinear solver type"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(cv_mem->NLSstg1, cvNlsConvTestSensStg1, cvode_mem); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(cv_mem->NLSstg1, NLS_MAXCOR); - if (retval != CV_SUCCESS) { - cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", - "CVodeSetNonlinearSolverSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(CV_ILL_INPUT); + return (CV_ILL_INPUT); } /* Reset the acnrmScur flag to SUNFALSE (always false for stg1) */ cv_mem->cv_acnrmScur = SUNFALSE; - return(CV_SUCCESS); + return (CV_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ - int cvNlsInitSensStg1(CVodeMem cvode_mem) { int retval; /* set the linear solver setup wrapper function */ if (cvode_mem->cv_lsetup) + { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg1, cvNlsLSetupSensStg1); - else - retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg1, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(cvode_mem->NLSstg1, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (cvode_mem->cv_lsolve) + { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg1, cvNlsLSolveSensStg1); - else - retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg1, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(cvode_mem->NLSstg1, NULL); } - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(cvode_mem->NLSstg1); - if (retval != CV_SUCCESS) { - cvProcessError(cvode_mem, CV_ILL_INPUT, "CVODES", "cvNlsInitSensStg1", + if (retval != CV_SUCCESS) + { + cvProcessError(cvode_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, MSGCV_NLS_INIT_FAIL); - return(CV_NLS_INIT_FAIL); + return (CV_NLS_INIT_FAIL); } /* reset previous iteration count for updating nniS1 */ cvode_mem->nnip = 0; - return(CV_SUCCESS); + return (CV_SUCCESS); } - -static int cvNlsLSetupSensStg1(booleantype jbad, booleantype* jcur, +static int cvNlsLSetupSensStg1(sunbooleantype jbad, sunbooleantype* jcur, void* cvode_mem) { CVodeMem cv_mem; int retval; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSetupSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* if the nonlinear solver marked the Jacobian as bad update convfail */ - if (jbad) - cv_mem->convfail = CV_FAIL_BAD_J; + if (jbad) { cv_mem->convfail = CV_FAIL_BAD_J; } /* setup the linear solver */ retval = cv_mem->cv_lsetup(cv_mem, cv_mem->convfail, cv_mem->cv_y, @@ -217,101 +221,103 @@ static int cvNlsLSetupSensStg1(booleantype jbad, booleantype* jcur, /* update Jacobian status */ *jcur = cv_mem->cv_jcur; - cv_mem->cv_gamrat = ONE; - cv_mem->cv_gammap = cv_mem->cv_gamma; - cv_mem->cv_crate = ONE; - cv_mem->cv_crateS = ONE; - cv_mem->cv_nstlp = cv_mem->cv_nst; + cv_mem->cv_gamrat = ONE; + cv_mem->cv_gammap = cv_mem->cv_gamma; + cv_mem->cv_crate = ONE; + cv_mem->cv_crateS = ONE; + cv_mem->cv_nstlp = cv_mem->cv_nst; - if (retval < 0) return(CV_LSETUP_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSETUP_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsLSolveSensStg1(N_Vector delta, void* cvode_mem) { CVodeMem cv_mem; int retval, is; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsLSolveSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* get index of current sensitivity solve */ is = cv_mem->sens_solve_idx; /* solve the sensitivity linear systems */ - retval = cv_mem->cv_lsolve(cv_mem, delta, cv_mem->cv_ewtS[is], - cv_mem->cv_y, cv_mem->cv_ftemp); + retval = cv_mem->cv_lsolve(cv_mem, delta, cv_mem->cv_ewtS[is], cv_mem->cv_y, + cv_mem->cv_ftemp); - if (retval < 0) return(CV_LSOLVE_FAIL); - if (retval > 0) return(SUN_NLS_CONV_RECVR); + if (retval < 0) { return (CV_LSOLVE_FAIL); } + if (retval > 0) { return (SUN_NLS_CONV_RECVR); } - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsConvTestSensStg1(SUNNonlinearSolver NLS, - N_Vector ycor, N_Vector delta, - realtype tol, N_Vector ewt, void* cvode_mem) + SUNDIALS_MAYBE_UNUSED N_Vector ycor, + N_Vector delta, sunrealtype tol, N_Vector ewt, + void* cvode_mem) { CVodeMem cv_mem; int m, retval; - realtype del; - realtype dcon; + sunrealtype del; + sunrealtype dcon; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsConvTestSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* compute the norm of the state and sensitivity corrections */ del = N_VWrmsNorm(delta, ewt); /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != CV_SUCCESS) return(CV_MEM_NULL); + if (retval != CV_SUCCESS) { return (CV_MEM_NULL); } /* Test for convergence. If m > 0, an estimate of the convergence rate constant is stored in crate, and used in the test. */ - if (m > 0) { - cv_mem->cv_crateS = SUNMAX(CRDOWN * cv_mem->cv_crateS, del/cv_mem->cv_delp); + if (m > 0) + { + cv_mem->cv_crateS = SUNMAX(CRDOWN * cv_mem->cv_crateS, del / cv_mem->cv_delp); } dcon = del * SUNMIN(ONE, cv_mem->cv_crateS) / tol; /* check if nonlinear system was solved successfully */ - if (dcon <= ONE) return(CV_SUCCESS); + if (dcon <= ONE) { return (CV_SUCCESS); } /* check if the iteration seems to be diverging */ - if ((m >= 1) && (del > RDIV*cv_mem->cv_delp)) return(SUN_NLS_CONV_RECVR); + if ((m >= 1) && (del > RDIV * cv_mem->cv_delp)) + { + return (SUN_NLS_CONV_RECVR); + } /* Save norm of correction and loop again */ cv_mem->cv_delp = del; /* Not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } - static int cvNlsResidualSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem) { CVodeMem cv_mem; int retval, is; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsResidualSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* get index of current sensitivity solve */ is = cv_mem->sens_solve_idx; @@ -320,33 +326,32 @@ static int cvNlsResidualSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem) N_VLinearSum(ONE, cv_mem->cv_znS[0][is], ONE, ycor, cv_mem->cv_yS[is]); /* evaluate the sensitivity rhs function */ - retval = cvSensRhs1Wrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, cv_mem->cv_ftemp, - is, cv_mem->cv_yS[is], cv_mem->cv_ftempS[is], - cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); + retval = cvSensRhs1Wrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, + cv_mem->cv_ftemp, is, cv_mem->cv_yS[is], + cv_mem->cv_ftempS[is], cv_mem->cv_vtemp1, + cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* compute the sensitivity resiudal */ N_VLinearSum(cv_mem->cv_rl1, cv_mem->cv_znS[1][is], ONE, ycor, res); N_VLinearSum(-cv_mem->cv_gamma, cv_mem->cv_ftempS[is], ONE, res, res); - return(CV_SUCCESS); + return (CV_SUCCESS); } - static int cvNlsFPFunctionSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem) { CVodeMem cv_mem; int retval, is; - if (cvode_mem == NULL) { - cvProcessError(NULL, CV_MEM_NULL, "CVODES", - "cvNlsFPFunctionSensStg1", MSGCV_NO_MEM); - return(CV_MEM_NULL); + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, MSGCV_NO_MEM); + return (CV_MEM_NULL); } - cv_mem = (CVodeMem) cvode_mem; + cv_mem = (CVodeMem)cvode_mem; /* get index of current sensitivity solve */ is = cv_mem->sens_solve_idx; @@ -355,17 +360,16 @@ static int cvNlsFPFunctionSensStg1(N_Vector ycor, N_Vector res, void* cvode_mem) N_VLinearSum(ONE, cv_mem->cv_znS[0][is], ONE, ycor, cv_mem->cv_yS[is]); /* evaluate the sensitivity rhs function */ - retval = cvSensRhs1Wrapper(cv_mem, cv_mem->cv_tn, - cv_mem->cv_y, cv_mem->cv_ftemp, - is, cv_mem->cv_yS[is], res, + retval = cvSensRhs1Wrapper(cv_mem, cv_mem->cv_tn, cv_mem->cv_y, + cv_mem->cv_ftemp, is, cv_mem->cv_yS[is], res, cv_mem->cv_vtemp1, cv_mem->cv_vtemp2); - if (retval < 0) return(CV_SRHSFUNC_FAIL); - if (retval > 0) return(SRHSFUNC_RECVR); + if (retval < 0) { return (CV_SRHSFUNC_FAIL); } + if (retval > 0) { return (SRHSFUNC_RECVR); } /* evaluate sensitivity fixed point function */ N_VLinearSum(cv_mem->cv_h, res, -ONE, cv_mem->cv_znS[1][is], res); N_VScale(cv_mem->cv_rl1, res, res); - return(CV_SUCCESS); + return (CV_SUCCESS); } diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj.c new file mode 100644 index 000000000..e50682fdd --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj.c @@ -0,0 +1,453 @@ +/* --------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * --------------------------------------------------------------------------- + * Based on CPODES by Radu Serban @ LLNL + * --------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * --------------------------------------------------------------------------- + * Implementation file for projections in CVODE. + * ---------------------------------------------------------------------------*/ + +#include +#include + +#include "cvodes_impl.h" +#include "sundials/sundials_math.h" + +/* Private constants */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ + +#define ONEPSM SUN_RCONST(1.000001) + +/* Private utility function prototypes */ +static int cvProjCreate(CVodeProjMem* proj_mem); +static int cvProjSetDefaults(CVodeProjMem proj_mem); +static int cvAccessProjMem(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVodeProjMem* proj_mem); + +/* =========================================================================== + * Exported Functions - projection initialization + * ===========================================================================*/ + +/* ----------------------------------------------------------------------------- + * CVodeSetProjFn sets a user defined projection function + * ---------------------------------------------------------------------------*/ +int CVodeSetProjFn(void* cvode_mem, CVProjFn pfun) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Check the CVODE memory pointer */ + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_CV_MEM_NULL); + return (CV_MEM_NULL); + } + cv_mem = (CVodeMem)cvode_mem; + + /* Check if the projection function is NULL */ + if (pfun == NULL) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "The projection function is NULL."); + return (CV_ILL_INPUT); + } + + /* Check for compatible method */ + if (cv_mem->cv_lmm != CV_BDF) + { + cvProcessError(cv_mem, CV_ILL_INPUT, __LINE__, __func__, __FILE__, + "Projection is only supported with BDF methods."); + return (CV_ILL_INPUT); + } + + /* Create the projection memory (if necessary) */ + retval = cvProjCreate(&(cv_mem->proj_mem)); + if (retval != CV_SUCCESS) + { + cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_CV_MEM_FAIL); + return (CV_MEM_FAIL); + } + + /* Shortcut to projection memory */ + proj_mem = cv_mem->proj_mem; + + /* User-defined projection */ + proj_mem->internal_proj = SUNFALSE; + + /* Set the projection function */ + proj_mem->pfun = pfun; + + /* Enable projection */ + cv_mem->proj_enabled = SUNTRUE; + + return (CV_SUCCESS); +} + +/* =========================================================================== + * Exported Functions - projection set function + * ===========================================================================*/ + +int CVodeSetProjErrEst(void* cvode_mem, sunbooleantype onoff) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Set projection error flag */ + proj_mem->err_proj = onoff; + + return (CV_SUCCESS); +} + +int CVodeSetProjFrequency(void* cvode_mem, long int freq) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Set projection frequency */ + if (freq < 0) + { + /* Restore default */ + proj_mem->freq = 1; + cv_mem->proj_enabled = SUNTRUE; + } + else if (freq == 0) + { + /* Disable projection */ + proj_mem->freq = 0; + cv_mem->proj_enabled = SUNFALSE; + } + else + { + /* Enable projection at given frequency */ + proj_mem->freq = freq; + cv_mem->proj_enabled = SUNTRUE; + } + + return (CV_SUCCESS); +} + +int CVodeSetMaxNumProjFails(void* cvode_mem, int max_fails) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Set maximum number of projection failures in a step attempt */ + if (max_fails < 1) + { + /* Restore default */ + proj_mem->max_fails = PROJ_MAX_FAILS; + } + else + { + /* Update max number of fails */ + proj_mem->max_fails = max_fails; + } + + return (CV_SUCCESS); +} + +int CVodeSetEpsProj(void* cvode_mem, sunrealtype eps) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Set the projection tolerance */ + if (eps <= ZERO) + { + /* Restore default */ + proj_mem->eps_proj = PROJ_EPS; + } + else + { + /* Update projection tolerance */ + proj_mem->eps_proj = eps; + } + + return (CV_SUCCESS); +} + +int CVodeSetProjFailEta(void* cvode_mem, sunrealtype eta) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Set the step size reduction factor for a projection failure */ + if ((eta <= ZERO) || (eta > ONE)) + { + /* Restore detault */ + proj_mem->eta_pfail = PROJ_FAIL_ETA; + } + else + { + /* Udpate the eta value */ + proj_mem->eta_pfail = PROJ_FAIL_ETA; + } + + return (CV_SUCCESS); +} + +/* =========================================================================== + * Exported Functions - projection get functions + * ===========================================================================*/ + +int CVodeGetNumProjEvals(void* cvode_mem, long int* nproj) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Get number of projection evaluations */ + *nproj = proj_mem->nproj; + + return (CV_SUCCESS); +} + +int CVodeGetNumProjFails(void* cvode_mem, long int* npfails) +{ + int retval; + CVodeMem cv_mem; + CVodeProjMem proj_mem; + + /* Access memory structures */ + retval = cvAccessProjMem(cvode_mem, __func__, &cv_mem, &proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + + /* Get number of projection fails */ + *npfails = proj_mem->npfails; + + return (CV_SUCCESS); +} + +/* =========================================================================== + * Internal Functions + * ===========================================================================*/ + +/* + * cvProjection + * + * For user supplied projection function, use ftemp as temporary storage + * for the current error estimate (acor) and use tempv to store the + * accumulated corection due to projection, acorP (tempv is not touched + * until it is potentially used in cvCompleteStep). + */ + +int cvDoProjection(CVodeMem cv_mem, int* nflagPtr, sunrealtype saved_t, + int* npfailPtr) +{ + int retval; + N_Vector errP; + N_Vector acorP; + CVodeProjMem proj_mem; + + /* Access projection memory */ + if (cv_mem->proj_mem == NULL) + { + cvProcessError(cv_mem, CV_PROJ_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_CV_PROJ_MEM_NULL); + return (CV_PROJ_MEM_NULL); + } + proj_mem = cv_mem->proj_mem; + + /* Initialize return flag to success */ + retval = CV_SUCCESS; + + /* Use tempv to store acorP and, if projecting the error, ftemp to store + errP (recall that in this case we did not allocate vectors to for + acorP and errP). */ + acorP = cv_mem->cv_tempv; + if (proj_mem->err_proj) { errP = cv_mem->cv_ftemp; } + else { errP = NULL; } + + /* Copy acor into errP (if projecting the error) */ + if (proj_mem->err_proj) { N_VScale(ONE, cv_mem->cv_acor, errP); } + + /* Call the user projection function */ + retval = proj_mem->pfun(cv_mem->cv_tn, cv_mem->cv_y, acorP, + proj_mem->eps_proj, errP, cv_mem->cv_user_data); + proj_mem->nproj++; + + /* This is not the first projection anymore */ + proj_mem->first_proj = SUNFALSE; + + /* Check the return value */ + if (retval == CV_SUCCESS) + { + /* Recompute acnrm to be used in error test (if projecting the error) */ + if (proj_mem->err_proj) + { + cv_mem->cv_acnrm = N_VWrmsNorm(errP, cv_mem->cv_ewt); + } + + /* The projection was successful, return now */ + cv_mem->proj_applied = SUNTRUE; + return (CV_SUCCESS); + } + + /* The projection failed, update the return value */ + if (retval < 0) { retval = CV_PROJFUNC_FAIL; } + if (retval > 0) { retval = PROJFUNC_RECVR; } + + /* Increment cumulative failure count and restore zn */ + proj_mem->npfails++; + cvRestore(cv_mem, saved_t); + + /* Return if failed unrecoverably */ + if (retval == CV_PROJFUNC_FAIL) { return (CV_PROJFUNC_FAIL); } + + /* Recoverable failure, increment failure count for this step attempt */ + (*npfailPtr)++; + cv_mem->cv_etamax = ONE; + + /* Check for maximum number of failures or |h| = hmin */ + if ((SUNRabs(cv_mem->cv_h) <= cv_mem->cv_hmin * ONEPSM) || + (*npfailPtr == proj_mem->max_fails)) + { + if (retval == PROJFUNC_RECVR) { return (CV_REPTD_PROJFUNC_ERR); } + } + + /* Reduce step size; return to reattempt the step */ + cv_mem->cv_eta = SUNMAX(proj_mem->eta_pfail, + cv_mem->cv_hmin / SUNRabs(cv_mem->cv_h)); + *nflagPtr = PREV_PROJ_FAIL; + cvRescale(cv_mem); + + return (PREDICT_AGAIN); +} + +int cvProjInit(CVodeProjMem proj_mem) +{ + /* check if projection memory exists */ + if (proj_mem == NULL) { return (CV_PROJ_MEM_NULL); } + + /* reset flags and counters */ + proj_mem->first_proj = SUNTRUE; + proj_mem->nstlprj = 0; + proj_mem->nproj = 0; + proj_mem->npfails = 0; + + return (CV_SUCCESS); +} + +int cvProjFree(CVodeProjMem* proj_mem) +{ + if (*proj_mem == NULL) { return (CV_SUCCESS); } + + free(*proj_mem); + *proj_mem = NULL; + + return (CV_SUCCESS); +} + +/* =========================================================================== + * Utility Functions + * ===========================================================================*/ + +static int cvProjCreate(CVodeProjMem* proj_mem) +{ + int retval; + + /* Allocate projection memory if necessary, otherwise return success */ + if (*proj_mem == NULL) + { + *proj_mem = (CVodeProjMem)malloc(sizeof(struct CVodeProjMemRec)); + if (*proj_mem == NULL) { return (CV_MEM_FAIL); } + + /* Zero out proj_mem */ + memset(*proj_mem, 0, sizeof(struct CVodeProjMemRec)); + + /* Initialize projection variables */ + retval = cvProjSetDefaults(*proj_mem); + if (retval != CV_SUCCESS) { return (retval); } + } + + return (CV_SUCCESS); +} + +static int cvProjSetDefaults(CVodeProjMem proj_mem) +{ + if (proj_mem == NULL) { return (CV_MEM_FAIL); } + + proj_mem->internal_proj = SUNTRUE; + proj_mem->err_proj = SUNTRUE; + proj_mem->first_proj = SUNTRUE; + + proj_mem->freq = 1; + proj_mem->nstlprj = 0; + + proj_mem->max_fails = PROJ_MAX_FAILS; + + proj_mem->pfun = NULL; + + proj_mem->eps_proj = PROJ_EPS; + proj_mem->eta_pfail = PROJ_FAIL_ETA; + + proj_mem->nproj = 0; + proj_mem->npfails = 0; + + return (CV_SUCCESS); +} + +static int cvAccessProjMem(void* cvode_mem, const char* fname, CVodeMem* cv_mem, + CVodeProjMem* proj_mem) +{ + /* Access cvode memory */ + if (cvode_mem == NULL) + { + cvProcessError(NULL, CV_MEM_NULL, __LINE__, fname, __FILE__, MSG_CV_MEM_NULL); + return (CV_MEM_NULL); + } + *cv_mem = (CVodeMem)cvode_mem; + + /* Access projection memory */ + if ((*cv_mem)->proj_mem == NULL) + { + cvProcessError(*cv_mem, CV_PROJ_MEM_NULL, __LINE__, fname, __FILE__, + MSG_CV_PROJ_MEM_NULL); + return (CV_PROJ_MEM_NULL); + } + *proj_mem = (CVodeProjMem)(*cv_mem)->proj_mem; + + return (CV_SUCCESS); +} diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj_impl.h b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj_impl.h new file mode 100644 index 000000000..35290aa2d --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_proj_impl.h @@ -0,0 +1,75 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner @ LLNL + * ----------------------------------------------------------------------------- + * Based on CPODES by Radu Serban @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * Implementation header file for projections in CVODE. + * ---------------------------------------------------------------------------*/ + +#ifndef _CVODE_PROJ_IMPL_H +#define _CVODE_PROJ_IMPL_H + +#include "cvodes/cvodes.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +/* ============================================================================= + * Default Projection Constants + * + * PROJ_MAX_FAILS max nunmber of projection failures in one step attempt + * PROJ_EPS projection solve tolerance + * PROJ_FAIL_ETA maximum step size decrease on projection failure + * ===========================================================================*/ + +#define PROJ_MAX_FAILS 10 +#define PROJ_EPS SUN_RCONST(0.1) +#define PROJ_FAIL_ETA SUN_RCONST(0.25) + +/* ============================================================================= + * Projection Data Structure + * ===========================================================================*/ + +/* ----------------------------------------------------------------------------- + * Types : struct CVodeProjMemRec, CVodeProjMem + * ----------------------------------------------------------------------------- + * The type CVodeProjMem is type pointer to struct CVodeProjMemRec. This + * structure contains data pertaining to the use of projection capabilities. + * ---------------------------------------------------------------------------*/ +typedef struct CVodeProjMemRec +{ + sunbooleantype internal_proj; /* use the internal projection algorithm? */ + sunbooleantype err_proj; /* is error projection enabled? */ + sunbooleantype first_proj; /* is this the first time we project? */ + + long int freq; /* projection frequency */ + long int nstlprj; /* step number of last projection */ + + int max_fails; /* maximum number of projection failures */ + + CVProjFn pfun; /* function to perform projection */ + + sunrealtype eps_proj; /* projection solve tolerance */ + sunrealtype eta_pfail; /* projection failure step reduction factor */ + + long int nproj; /* number of projections performed */ + long int npfails; /* number of projection failures */ + +}* CVodeProjMem; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_spils.c b/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_spils.c deleted file mode 100644 index 0103eef52..000000000 --- a/deps/AMICI/ThirdParty/sundials/src/cvodes/cvodes_spils.c +++ /dev/null @@ -1,107 +0,0 @@ -/*----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - * ----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - * ----------------------------------------------------------------- - * Header file for the deprecated Scaled, Preconditioned Iterative - * Linear Solver interface in CVODES; these routines now just wrap - * the updated CVODES generic linear solver interface in cvodes_ls.h. - * -----------------------------------------------------------------*/ - -#include -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/*================================================================= - CVSSPILS Exported functions (wrappers for equivalent routines in - cvodes_ls.h) - =================================================================*/ - -int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS) -{ return(CVodeSetLinearSolver(cvode_mem, LS, NULL)); } - -int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac) -{ return(CVodeSetEpsLin(cvode_mem, eplifac)); } - -int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, - CVSpilsPrecSolveFn psolve) -{ return(CVodeSetPreconditioner(cvode_mem, pset, psolve)); } - -int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, - CVSpilsJacTimesVecFn jtimes) -{ return(CVodeSetJacTimes(cvode_mem, jtsetup, jtimes)); } - -int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS) -{ return(CVodeGetLinWorkSpace(cvode_mem, lenrwLS, leniwLS)); } - -int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals) -{ return(CVodeGetNumPrecEvals(cvode_mem, npevals)); } - -int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves) -{ return(CVodeGetNumPrecSolves(cvode_mem, npsolves)); } - -int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters) -{ return(CVodeGetNumLinIters(cvode_mem, nliters)); } - -int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails) -{ return(CVodeGetNumLinConvFails(cvode_mem, nlcfails)); } - -int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups) -{ return(CVodeGetNumJTSetupEvals(cvode_mem, njtsetups)); } - -int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals) -{ return(CVodeGetNumJtimesEvals(cvode_mem, njvevals)); } - -int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) -{ return(CVodeGetNumLinRhsEvals(cvode_mem, nfevalsLS)); } - -int CVSpilsGetLastFlag(void *cvode_mem, long int *flag) -{ return(CVodeGetLastLinFlag(cvode_mem, flag)); } - -char *CVSpilsGetReturnFlagName(long int flag) -{ return(CVodeGetLinReturnFlagName(flag)); } - -int CVSpilsSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS) -{ return(CVodeSetLinearSolverB(cvode_mem, which, LS, NULL)); } - -int CVSpilsSetEpsLinB(void *cvode_mem, int which, realtype eplifacB) -{ return(CVodeSetEpsLinB(cvode_mem, which, eplifacB)); } - -int CVSpilsSetPreconditionerB(void *cvode_mem, int which, - CVSpilsPrecSetupFnB psetB, - CVSpilsPrecSolveFnB psolveB) -{ return(CVodeSetPreconditionerB(cvode_mem, which, psetB, psolveB)); } - -int CVSpilsSetPreconditionerBS(void *cvode_mem, int which, - CVSpilsPrecSetupFnBS psetBS, - CVSpilsPrecSolveFnBS psolveBS) -{ return(CVodeSetPreconditionerBS(cvode_mem, which, psetBS, psolveBS)); } - -int CVSpilsSetJacTimesB(void *cvode_mem, int which, - CVSpilsJacTimesSetupFnB jtsetupB, - CVSpilsJacTimesVecFnB jtimesB) -{ return(CVodeSetJacTimesB(cvode_mem, which, jtsetupB, jtimesB)); } - -int CVSpilsSetJacTimesBS(void *cvode_mem, int which, - CVSpilsJacTimesSetupFnBS jtsetupBS, - CVSpilsJacTimesVecFnBS jtimesBS) -{ return(CVodeSetJacTimesBS(cvode_mem, which, jtsetupBS, jtimesBS)); } - - -#ifdef __cplusplus -} -#endif - diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/idas/CMakeLists.txt index 1bc25b48e..a5ed8b473 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/idas/CMakeLists.txt @@ -3,7 +3,7 @@ # Radu Serban, Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -21,7 +21,6 @@ install(CODE "MESSAGE(\"\nInstall IDAS\n\")") set(idas_SOURCES idas.c idaa.c - idas_direct.c idas_io.c idas_ic.c idaa_io.c @@ -30,16 +29,13 @@ set(idas_SOURCES idas_nls.c idas_nls_sim.c idas_nls_stg.c - idas_spils.c ) # Add variable idas_HEADERS with the exported IDAS header files set(idas_HEADERS idas.h idas_bbdpre.h - idas_direct.h idas_ls.h - idas_spils.h ) # Add prefix with complete path to the IDAS header files @@ -53,8 +49,10 @@ sundials_add_library(sundials_idas ${idas_HEADERS} INCLUDE_SUBDIR idas + LINK_LIBRARIES + PUBLIC sundials_core OBJECT_LIBRARIES - sundials_generic_obj + sundials_sunmemsys_obj sundials_nvecserial_obj sundials_sunmatrixband_obj sundials_sunmatrixdense_obj @@ -81,5 +79,5 @@ message(STATUS "Added IDAS module") # Add F2003 module if the interface is enabled if(BUILD_FORTRAN_MODULE_INTERFACE) - add_subdirectory(fmod) + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/LICENSE b/deps/AMICI/ThirdParty/sundials/src/idas/LICENSE index 4ba2c4848..2b12386cc 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/LICENSE +++ b/deps/AMICI/ThirdParty/sundials/src/idas/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2002-2021, Lawrence Livermore National Security and Southern Methodist University. +Copyright (c) 2002-2024, Lawrence Livermore National Security and Southern Methodist University. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/README.md b/deps/AMICI/ThirdParty/sundials/src/idas/README.md index a597e5e1d..db24f4c49 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/README.md +++ b/deps/AMICI/ThirdParty/sundials/src/idas/README.md @@ -1,7 +1,7 @@ # IDAS -### Version 4.8.0 (Sep 2021) +### Version 6.1.1 (Jun 2024) -**Radu Serban, Cosmin Petra, Alan C. Hindmarsh, Cody J. Balos, David J. Gardner, +**Radu Serban, Cosmin Petra, Alan C. Hindmarsh, Cody J. Balos, David J. Gardner, and Carol S. Woodward, Center for Applied Scientific Computing, LLNL** **Daniel R. Reynolds, Department of Mathematics, Southern Methodist University** @@ -26,14 +26,13 @@ nonlinear solver APIs used across SUNDIALS packages. ## Documentation -See the [IDAS User Guide](/doc/idas/idas_guide.pdf) and -[IDAS Examples](/doc/idas/idas_examples.pdf) document for more information -about IDAS usage and the provided example programs respectively. +See the IDAS documentation at [Read the Docs](https://sundials.readthedocs.io/en/latest/idas) +for more information about IDAS usage. ## Installation -For installation instructions see the [INSTALL_GUIDE](/INSTALL_GUIDE.pdf) -or the "Installation Procedure" chapter in the IDAS User Guide. +For installation instructions see the +[SUNDIALS Installation Guide](https://sundials.readthedocs.io/en/latest/Install_link.html). ## Release History @@ -44,11 +43,11 @@ the "SUNDIALS Release History" appendix of the IDAS User Guide. ## References * R. Serban, C. Petra, A. C. Hindmarsh, C. J. Balos, D. J. Gardner, - D. R. Reynolds and C. S. Woodward, "User Documentation for IDAS v4.8.0," - LLNL technical report UCRL-SM-234051, Sep 2021. + D. R. Reynolds and C. S. Woodward, "User Documentation for IDAS v6.1.1," + LLNL technical report UCRL-SM-234051, Jun 2024. -* R. Serban and A.C. Hindmarsh, "Example Programs for IDAS v4.8.0," - LLNL technical report LLNL-TR-437091, Sep 2021. +* R. Serban and A.C. Hindmarsh, "Example Programs for IDAS v6.1.1," + LLNL technical report LLNL-TR-437091, Jun 2024. * A. C. Hindmarsh, P. N. Brown, K. E. Grant, S. L. Lee, R. Serban, D. E. Shumaker, and C. S. Woodward, "SUNDIALS, Suite of Nonlinear and diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idaa.c b/deps/AMICI/ThirdParty/sundials/src/idas/idaa.c index 022228711..803d1efa8 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idaa.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idaa.c @@ -3,7 +3,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,69 +22,70 @@ #include #include +#include #include "idas_impl.h" -#include /*=================================================================*/ /* IDAA Private Constants */ /*=================================================================*/ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define HUNDRED RCONST(100.0) /* real 100.0 */ -#define FUZZ_FACTOR RCONST(1000000.0) /* fuzz factor for IDAAgetY */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWO SUN_RCONST(2.0) /* real 2.0 */ +#define HUNDRED SUN_RCONST(100.0) /* real 100.0 */ +#define FUZZ_FACTOR SUN_RCONST(1000000.0) /* fuzz factor for IDAAgetY */ + +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ +#define IDA_PROFILER IDA_mem->ida_sunctx->profiler /*=================================================================*/ /* Private Functions Prototypes */ /*=================================================================*/ -static CkpntMem IDAAckpntInit(IDAMem IDA_mem); -static CkpntMem IDAAckpntNew(IDAMem IDA_mem); -static void IDAAckpntCopyVectors(IDAMem IDA_mem, CkpntMem ck_mem); -static booleantype IDAAckpntAllocVectors(IDAMem IDA_mem, CkpntMem ck_mem); -static void IDAAckpntDelete(CkpntMem *ck_memPtr); +static IDAckpntMem IDAAckpntInit(IDAMem IDA_mem); +static IDAckpntMem IDAAckpntNew(IDAMem IDA_mem); +static void IDAAckpntCopyVectors(IDAMem IDA_mem, IDAckpntMem ck_mem); +static sunbooleantype IDAAckpntAllocVectors(IDAMem IDA_mem, IDAckpntMem ck_mem); +static void IDAAckpntDelete(IDAckpntMem* ck_memPtr); -static void IDAAbckpbDelete(IDABMem *IDAB_memPtr); +static void IDAAbckpbDelete(IDABMem* IDAB_memPtr); -static booleantype IDAAdataMalloc(IDAMem IDA_mem); +static sunbooleantype IDAAdataMalloc(IDAMem IDA_mem); static void IDAAdataFree(IDAMem IDA_mem); -static int IDAAdataStore(IDAMem IDA_mem, CkpntMem ck_mem); +static int IDAAdataStore(IDAMem IDA_mem, IDAckpntMem ck_mem); -static int IDAAckpntGet(IDAMem IDA_mem, CkpntMem ck_mem); +static int IDAAckpntGet(IDAMem IDA_mem, IDAckpntMem ck_mem); -static booleantype IDAAhermiteMalloc(IDAMem IDA_mem); -static void IDAAhermiteFree(IDAMem IDA_mem); -static int IDAAhermiteStorePnt(IDAMem IDA_mem, DtpntMem d); -static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS); +static sunbooleantype IDAAhermiteMalloc(IDAMem IDA_mem); +static void IDAAhermiteFree(IDAMem IDA_mem); +static int IDAAhermiteStorePnt(IDAMem IDA_mem, IDAdtpntMem d); +static int IDAAhermiteGetY(IDAMem IDA_mem, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS); -static booleantype IDAApolynomialMalloc(IDAMem IDA_mem); -static void IDAApolynomialFree(IDAMem IDA_mem); -static int IDAApolynomialStorePnt(IDAMem IDA_mem, DtpntMem d); -static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS); +static sunbooleantype IDAApolynomialMalloc(IDAMem IDA_mem); +static void IDAApolynomialFree(IDAMem IDA_mem); +static int IDAApolynomialStorePnt(IDAMem IDA_mem, IDAdtpntMem d); +static int IDAApolynomialGetY(IDAMem IDA_mem, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS); -static int IDAAfindIndex(IDAMem ida_mem, realtype t, - long int *indx, booleantype *newpoint); +static int IDAAfindIndex(IDAMem ida_mem, sunrealtype t, long int* indx, + sunbooleantype* newpoint); -static int IDAAres(realtype tt, - N_Vector yyB, N_Vector ypB, - N_Vector resvalB, void *ida_mem); +static int IDAAres(sunrealtype tt, N_Vector yyB, N_Vector ypB, N_Vector resvalB, + void* ida_mem); -static int IDAArhsQ(realtype tt, - N_Vector yyB, N_Vector ypB, - N_Vector rrQB, void *ida_mem); +static int IDAArhsQ(sunrealtype tt, N_Vector yyB, N_Vector ypB, N_Vector rrQB, + void* ida_mem); static int IDAAGettnSolutionYp(IDAMem IDA_mem, N_Vector yp); -static int IDAAGettnSolutionYpS(IDAMem IDA_mem, N_Vector *ypS); - -extern int IDAGetSolution(void *ida_mem, realtype t, N_Vector yret, N_Vector ypret); +static int IDAAGettnSolutionYpS(IDAMem IDA_mem, N_Vector* ypS); +extern int IDAGetSolution(void* ida_mem, sunrealtype t, N_Vector yret, + N_Vector ypret); /*=================================================================*/ /* Exported Functions */ @@ -97,80 +98,95 @@ extern int IDAGetSolution(void *ida_mem, realtype t, N_Vector yret, N_Vector ypr * structure. */ - -int IDAAdjInit(void *ida_mem, long int steps, int interp) +int IDAAdjInit(void* ida_mem, long int steps, int interp) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; /* Check arguments */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAAdjInit", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } IDA_mem = (IDAMem)ida_mem; - if (steps <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAAdjInit", MSGAM_BAD_STEPS); - return(IDA_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + + if (steps <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_STEPS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if ( (interp != IDA_HERMITE) && (interp != IDA_POLYNOMIAL) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAAdjInit", MSGAM_BAD_INTERP); - return(IDA_ILL_INPUT); + if ((interp != IDA_HERMITE) && (interp != IDA_POLYNOMIAL)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_INTERP); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Allocate memory block for IDAadjMem. */ - IDAADJ_mem = (IDAadjMem) malloc(sizeof(struct IDAadjMemRec)); - if (IDAADJ_mem == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDAAdjInit", MSGAM_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAADJ_mem = (IDAadjMem)malloc(sizeof(struct IDAadjMemRec)); + if (IDAADJ_mem == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGAM_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Attach IDAS memory for forward runs */ IDA_mem->ida_adj_mem = IDAADJ_mem; /* Initialization of check points. */ - IDAADJ_mem->ck_mem = NULL; - IDAADJ_mem->ia_nckpnts = 0; + IDAADJ_mem->ck_mem = NULL; + IDAADJ_mem->ia_nckpnts = 0; IDAADJ_mem->ia_ckpntData = NULL; - /* Initialization of interpolation data. */ IDAADJ_mem->ia_interpType = interp; - IDAADJ_mem->ia_nsteps = steps; + IDAADJ_mem->ia_nsteps = steps; /* Last index used in IDAAfindIndex, initailize to invalid value */ IDAADJ_mem->ia_ilast = -1; /* Allocate space for the array of Data Point structures. */ - if (IDAAdataMalloc(IDA_mem) == SUNFALSE) { - free(IDAADJ_mem); IDAADJ_mem = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDAAdjInit", MSGAM_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDAAdataMalloc(IDA_mem) == SUNFALSE) + { + free(IDAADJ_mem); + IDAADJ_mem = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGAM_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Attach functions for the appropriate interpolation module */ - switch(interp) { - + switch (interp) + { case IDA_HERMITE: - IDAADJ_mem->ia_malloc = IDAAhermiteMalloc; - IDAADJ_mem->ia_free = IDAAhermiteFree; - IDAADJ_mem->ia_getY = IDAAhermiteGetY; - IDAADJ_mem->ia_storePnt = IDAAhermiteStorePnt; + IDAADJ_mem->ia_malloc = IDAAhermiteMalloc; + IDAADJ_mem->ia_free = IDAAhermiteFree; + IDAADJ_mem->ia_getY = IDAAhermiteGetY; + IDAADJ_mem->ia_storePnt = IDAAhermiteStorePnt; break; - case IDA_POLYNOMIAL: + case IDA_POLYNOMIAL: - IDAADJ_mem->ia_malloc = IDAApolynomialMalloc; - IDAADJ_mem->ia_free = IDAApolynomialFree; - IDAADJ_mem->ia_getY = IDAApolynomialGetY; - IDAADJ_mem->ia_storePnt = IDAApolynomialStorePnt; + IDAADJ_mem->ia_malloc = IDAApolynomialMalloc; + IDAADJ_mem->ia_free = IDAApolynomialFree; + IDAADJ_mem->ia_getY = IDAApolynomialGetY; + IDAADJ_mem->ia_storePnt = IDAApolynomialStorePnt; break; } - /* The interpolation module has not been initialized yet */ + /* The interpolation module has not been initialized yet */ IDAADJ_mem->ia_mallocDone = SUNFALSE; /* By default we will store but not interpolate sensitivities @@ -186,9 +202,9 @@ int IDAAdjInit(void *ida_mem, long int steps, int interp) IDAADJ_mem->ia_noInterp = SUNFALSE; /* Initialize backward problems. */ - IDAADJ_mem->IDAB_mem = NULL; + IDAADJ_mem->IDAB_mem = NULL; IDAADJ_mem->ia_bckpbCrt = NULL; - IDAADJ_mem->ia_nbckpbs = 0; + IDAADJ_mem->ia_nbckpbs = 0; /* IDASolveF and IDASolveB not called yet. */ IDAADJ_mem->ia_firstIDAFcall = SUNTRUE; @@ -199,10 +215,11 @@ int IDAAdjInit(void *ida_mem, long int steps, int interp) IDAADJ_mem->ia_rootret = SUNFALSE; /* Adjoint module initialized and allocated. */ - IDA_mem->ida_adj = SUNTRUE; + IDA_mem->ida_adj = SUNTRUE; IDA_mem->ida_adjMallocDone = SUNTRUE; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -211,33 +228,39 @@ int IDAAdjInit(void *ida_mem, long int steps, int interp) * IDAAdjReInit reinitializes the IDAS memory structure for ASA */ -int IDAAdjReInit(void *ida_mem) +int IDAAdjReInit(void* ida_mem) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; /* Check arguments */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAAdjReInit", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } IDA_mem = (IDAMem)ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + /* Was ASA previously initialized? */ - if(IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAAdjReInit", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Free all stored checkpoints. */ - while (IDAADJ_mem->ck_mem != NULL) - IDAAckpntDelete(&(IDAADJ_mem->ck_mem)); + while (IDAADJ_mem->ck_mem != NULL) { IDAAckpntDelete(&(IDAADJ_mem->ck_mem)); } - IDAADJ_mem->ck_mem = NULL; - IDAADJ_mem->ia_nckpnts = 0; + IDAADJ_mem->ck_mem = NULL; + IDAADJ_mem->ia_nckpnts = 0; IDAADJ_mem->ia_ckpntData = NULL; /* Flags for tracking the first calls to IDASolveF and IDASolveF. */ @@ -245,7 +268,8 @@ int IDAAdjReInit(void *ida_mem) IDAADJ_mem->ia_tstopIDAFcall = SUNFALSE; IDAADJ_mem->ia_firstIDABcall = SUNTRUE; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -254,22 +278,22 @@ int IDAAdjReInit(void *ida_mem) * IDAAdjFree routine frees the memory allocated by IDAAdjInit. */ - -void IDAAdjFree(void *ida_mem) +void IDAAdjFree(void* ida_mem) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - if (ida_mem == NULL) return; - IDA_mem = (IDAMem) ida_mem; - - if(IDA_mem->ida_adjMallocDone) { + if (ida_mem == NULL) { return; } + IDA_mem = (IDAMem)ida_mem; + if (IDA_mem->ida_adjMallocDone) + { /* Data for adjoint. */ IDAADJ_mem = IDA_mem->ida_adj_mem; /* Delete check points one by one */ - while (IDAADJ_mem->ck_mem != NULL) { + while (IDAADJ_mem->ck_mem != NULL) + { IDAAckpntDelete(&(IDAADJ_mem->ck_mem)); } @@ -277,7 +301,9 @@ void IDAAdjFree(void *ida_mem) /* Free all backward problems. */ while (IDAADJ_mem->IDAB_mem != NULL) - IDAAbckpbDelete( &(IDAADJ_mem->IDAB_mem) ); + { + IDAAbckpbDelete(&(IDAADJ_mem->IDAB_mem)); + } /* Free IDAA memory. */ free(IDAADJ_mem); @@ -292,12 +318,12 @@ void IDAAdjFree(void *ida_mem) * ================================================================= */ -static void IDAAbckpbDelete(IDABMem *IDAB_memPtr) +static void IDAAbckpbDelete(IDABMem* IDAB_memPtr) { IDABMem IDAB_mem = (*IDAB_memPtr); - void * ida_mem; + void* ida_mem; - if (IDAB_mem == NULL) return; + if (IDAB_mem == NULL) { return; } /* Move head to the next element in list. */ *IDAB_memPtr = IDAB_mem->ida_next; @@ -305,14 +331,14 @@ static void IDAAbckpbDelete(IDABMem *IDAB_memPtr) /* IDAB_mem is going to be deallocated. */ /* Free IDAS memory for this backward problem. */ - ida_mem = (void *)IDAB_mem->IDA_mem; + ida_mem = (void*)IDAB_mem->IDA_mem; IDAFree(&ida_mem); /* Free linear solver memory. */ - if (IDAB_mem->ida_lfree != NULL) IDAB_mem->ida_lfree(IDAB_mem); + if (IDAB_mem->ida_lfree != NULL) { IDAB_mem->ida_lfree(IDAB_mem); } /* Free preconditioner memory. */ - if (IDAB_mem->ida_pfree != NULL) IDAB_mem->ida_pfree(IDAB_mem); + if (IDAB_mem->ida_pfree != NULL) { IDAB_mem->ida_pfree(IDAB_mem); } /* Free any workspace vectors. */ N_VDestroy(IDAB_mem->ida_yy); @@ -339,53 +365,72 @@ static void IDAAbckpbDelete(IDABMem *IDAB_memPtr) * ncheckPtr points to the number of check points stored so far. */ -int IDASolveF(void *ida_mem, realtype tout, realtype *tret, - N_Vector yret, N_Vector ypret, int itask, int *ncheckPtr) +int IDASolveF(void* ida_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, + N_Vector ypret, int itask, int* ncheckPtr) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; - CkpntMem tmp; - DtpntMem *dt_mem; + IDAckpntMem tmp; + IDAdtpntMem* dt_mem; long int nstloc; int flag, i; - booleantype allocOK, earlyret; - realtype ttest; + sunbooleantype allocOK, earlyret; + sunrealtype ttest; /* Is the mem OK? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASolveF", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASolveF", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check for yret != NULL */ - if (yret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveF", MSG_YRET_NULL); - return(IDA_ILL_INPUT); + if (yret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check for ypret != NULL */ - if (ypret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveF", MSG_YPRET_NULL); - return(IDA_ILL_INPUT); + if (ypret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YPRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check for tret != NULL */ - if (tret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveF", MSG_TRET_NULL); - return(IDA_ILL_INPUT); + if (tret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check for valid itask */ - if ( (itask != IDA_NORMAL) && (itask != IDA_ONE_STEP) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveF", MSG_BAD_ITASK); - return(IDA_ILL_INPUT); + if ((itask != IDA_NORMAL) && (itask != IDA_ONE_STEP)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* All memory checks done, proceed ... */ @@ -393,9 +438,10 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, dt_mem = IDAADJ_mem->dt_mem; /* If tstop is enabled, store some info */ - if (IDA_mem->ida_tstopset) { + if (IDA_mem->ida_tstopset) + { IDAADJ_mem->ia_tstopIDAFcall = SUNTRUE; - IDAADJ_mem->ia_tstopIDAF = IDA_mem->ida_tstop; + IDAADJ_mem->ia_tstopIDAF = IDA_mem->ida_tstop; } /* On the first step: @@ -405,31 +451,44 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, * - load dt_mem[0] * On subsequent steps, test if taking a new step is necessary. */ - if ( IDAADJ_mem->ia_firstIDAFcall ) { - + if (IDAADJ_mem->ia_firstIDAFcall) + { IDAADJ_mem->ia_tinitial = IDA_mem->ida_tn; - IDAADJ_mem->ck_mem = IDAAckpntInit(IDA_mem); - if (IDAADJ_mem->ck_mem == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDASolveF", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAADJ_mem->ck_mem = IDAAckpntInit(IDA_mem); + if (IDAADJ_mem->ck_mem == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } - if (!IDAADJ_mem->ia_mallocDone) { + if (!IDAADJ_mem->ia_mallocDone) + { /* Do we need to store sensitivities? */ - if (!IDA_mem->ida_sensi) IDAADJ_mem->ia_storeSensi = SUNFALSE; + if (!IDA_mem->ida_sensi) { IDAADJ_mem->ia_storeSensi = SUNFALSE; } /* Allocate space for interpolation data */ allocOK = IDAADJ_mem->ia_malloc(IDA_mem); - if (!allocOK) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDASolveF", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (!allocOK) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Rename phi and, if needed, phiS for use in interpolation */ - for (i=0;iia_Y[i] = IDA_mem->ida_phi[i]; - if (IDAADJ_mem->ia_storeSensi) { - for (i=0;iia_Y[i] = IDA_mem->ida_phi[i]; + } + if (IDAADJ_mem->ia_storeSensi) + { + for (i = 0; i < MXORDP1; i++) + { IDAADJ_mem->ia_YS[i] = IDA_mem->ida_phiS[i]; + } } IDAADJ_mem->ia_mallocDone = SUNTRUE; @@ -439,9 +498,9 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, IDAADJ_mem->ia_storePnt(IDA_mem, dt_mem[0]); IDAADJ_mem->ia_firstIDAFcall = SUNFALSE; - - } else if ( itask == IDA_NORMAL ) { - + } + else if (itask == IDA_NORMAL) + { /* When in normal mode, check if tout was passed or if a previous root was not reported and return an interpolated solution. No changes to ck_mem or dt_mem are needed. */ @@ -453,39 +512,44 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, to the current time tn */ ttest = (IDAADJ_mem->ia_rootret) ? IDAADJ_mem->ia_troot : IDA_mem->ida_tn; - if ((ttest - tout)*IDA_mem->ida_hh >= ZERO) { + if ((ttest - tout) * IDA_mem->ida_hh >= ZERO) + { /* ttest is after tout, interpolate to tout */ - *tret = tout; - flag = IDAGetSolution(IDA_mem, tout, yret, ypret); + *tret = tout; + flag = IDAGetSolution(IDA_mem, tout, yret, ypret); earlyret = SUNTRUE; - } else if (IDAADJ_mem->ia_rootret) { + } + else if (IDAADJ_mem->ia_rootret) + { /* tout is after troot, interpolate to troot */ *tret = IDAADJ_mem->ia_troot; - flag = IDAGetSolution(IDA_mem, IDAADJ_mem->ia_troot, yret, ypret); - flag = IDA_ROOT_RETURN; + flag = IDAGetSolution(IDA_mem, IDAADJ_mem->ia_troot, yret, ypret); + flag = IDA_ROOT_RETURN; IDAADJ_mem->ia_rootret = SUNFALSE; - earlyret = SUNTRUE; + earlyret = SUNTRUE; } /* return if necessary */ - if (earlyret) { - *ncheckPtr = IDAADJ_mem->ia_nckpnts; - IDAADJ_mem->ia_newData = SUNTRUE; + if (earlyret) + { + *ncheckPtr = IDAADJ_mem->ia_nckpnts; + IDAADJ_mem->ia_newData = SUNTRUE; IDAADJ_mem->ia_ckpntData = IDAADJ_mem->ck_mem; - IDAADJ_mem->ia_np = IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps + 1; - return(flag); + IDAADJ_mem->ia_np = IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps + 1; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } - } /* Integrate to tout (in IDA_ONE_STEP mode) while loading check points */ nstloc = 0; - for(;;) { - + for (;;) + { /* Check for too many steps */ - if ( (IDA_mem->ida_mxstep>0) && (nstloc >= IDA_mem->ida_mxstep) ) { - IDAProcessError(IDA_mem, IDA_TOO_MUCH_WORK, "IDAA", "IDASolveF", + if ((IDA_mem->ida_mxstep > 0) && (nstloc >= IDA_mem->ida_mxstep)) + { + IDAProcessError(IDA_mem, IDA_TOO_MUCH_WORK, __LINE__, __func__, __FILE__, MSG_MAX_STEPS, IDA_mem->ida_tn); flag = IDA_TOO_MUCH_WORK; break; @@ -494,24 +558,25 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, /* Perform one step of the integration */ flag = IDASolve(IDA_mem, tout, tret, yret, ypret, IDA_ONE_STEP); - if (flag < 0) break; + if (flag < 0) { break; } nstloc++; /* Test if a new check point is needed */ - if ( IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps == 0 ) { - + if (IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps == 0) + { IDAADJ_mem->ck_mem->ck_t1 = IDA_mem->ida_tn; /* Create a new check point, load it, and append it to the list */ tmp = IDAAckpntNew(IDA_mem); - if (tmp == NULL) { + if (tmp == NULL) + { flag = IDA_MEM_FAIL; break; } - tmp->ck_next = IDAADJ_mem->ck_mem; + tmp->ck_next = IDAADJ_mem->ck_mem; IDAADJ_mem->ck_mem = tmp; IDAADJ_mem->ia_nckpnts++; @@ -520,13 +585,13 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, /* Reset i=0 and load dt_mem[0] */ dt_mem[0]->t = IDAADJ_mem->ck_mem->ck_t0; IDAADJ_mem->ia_storePnt(IDA_mem, dt_mem[0]); - - } else { - + } + else + { /* Load next point in dt_mem */ - dt_mem[IDA_mem->ida_nst%IDAADJ_mem->ia_nsteps]->t = IDA_mem->ida_tn; - IDAADJ_mem->ia_storePnt(IDA_mem, dt_mem[IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps]); - + dt_mem[IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps]->t = IDA_mem->ida_tn; + IDAADJ_mem->ia_storePnt(IDA_mem, + dt_mem[IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps]); } /* Set t1 field of the current ckeck point structure @@ -538,22 +603,23 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, IDAADJ_mem->ia_tfinal = IDA_mem->ida_tn; /* Return if in IDA_ONE_STEP mode */ - if (itask == IDA_ONE_STEP) break; + if (itask == IDA_ONE_STEP) { break; } /* IDA_NORMAL_STEP returns */ /* Return if tout reached */ - if ( (*tret - tout)*IDA_mem->ida_hh >= ZERO ) { - + if ((*tret - tout) * IDA_mem->ida_hh >= ZERO) + { /* If this was a root return, save the root time to return later */ - if (flag == IDA_ROOT_RETURN) { + if (flag == IDA_ROOT_RETURN) + { IDAADJ_mem->ia_rootret = SUNTRUE; IDAADJ_mem->ia_troot = *tret; } /* Get solution value at tout to return now */ *tret = tout; - flag = IDAGetSolution(IDA_mem, tout, yret, ypret); + flag = IDAGetSolution(IDA_mem, tout, yret, ypret); /* Reset tretlast in IDA_mem so that IDAGetQuad and IDAGetSens * evaluate quadratures and/or sensitivities at the proper time */ @@ -563,7 +629,7 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, } /* Return if tstop or a root was found */ - if ((flag == IDA_TSTOP_RETURN) || (flag == IDA_ROOT_RETURN)) break; + if ((flag == IDA_TSTOP_RETURN) || (flag == IDA_ROOT_RETURN)) { break; } } /* end of for(;;) */ @@ -571,23 +637,21 @@ int IDASolveF(void *ida_mem, realtype tout, realtype *tret, *ncheckPtr = IDAADJ_mem->ia_nckpnts; /* Data is available for the last interval */ - IDAADJ_mem->ia_newData = SUNTRUE; + IDAADJ_mem->ia_newData = SUNTRUE; IDAADJ_mem->ia_ckpntData = IDAADJ_mem->ck_mem; - IDAADJ_mem->ia_np = IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps + 1; + IDAADJ_mem->ia_np = IDA_mem->ida_nst % IDAADJ_mem->ia_nsteps + 1; - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } - - - /* * ================================================================= * FUNCTIONS FOR BACKWARD PROBLEMS * ================================================================= */ -int IDACreateB(void *ida_mem, int *which) +int IDACreateB(void* ida_mem, int* which) { IDAMem IDA_mem; void* ida_memB; @@ -595,66 +659,69 @@ int IDACreateB(void *ida_mem, int *which) IDAadjMem IDAADJ_mem; /* Is the mem OK? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDACreateB", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDACreateB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Allocate a new IDABMem struct. */ - new_IDAB_mem = (IDABMem) malloc( sizeof( struct IDABMemRec ) ); - if (new_IDAB_mem == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDACreateB", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + new_IDAB_mem = (IDABMem)malloc(sizeof(struct IDABMemRec)); + if (new_IDAB_mem == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } /* Allocate the IDAMem struct needed by this backward problem. */ - ida_memB = IDACreate(); - if (ida_memB == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAA", "IDACreateB", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + ida_memB = IDACreate(IDA_mem->ida_sunctx); + if (ida_memB == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } /* Save ida_mem in ida_memB as user data. */ IDASetUserData(ida_memB, ida_mem); - /* Set same error output and handler for ida_memB. */ - IDASetErrHandlerFn(ida_memB, IDA_mem->ida_ehfun, IDA_mem->ida_eh_data); - IDASetErrFile(ida_memB, IDA_mem->ida_errfp); - /* Initialize fields in the IDABMem struct. */ - new_IDAB_mem->ida_index = IDAADJ_mem->ia_nbckpbs; - new_IDAB_mem->IDA_mem = (IDAMem) ida_memB; - - new_IDAB_mem->ida_res = NULL; - new_IDAB_mem->ida_resS = NULL; - new_IDAB_mem->ida_rhsQ = NULL; - new_IDAB_mem->ida_rhsQS = NULL; + new_IDAB_mem->ida_index = IDAADJ_mem->ia_nbckpbs; + new_IDAB_mem->IDA_mem = (IDAMem)ida_memB; + new_IDAB_mem->ida_res = NULL; + new_IDAB_mem->ida_resS = NULL; + new_IDAB_mem->ida_rhsQ = NULL; + new_IDAB_mem->ida_rhsQS = NULL; new_IDAB_mem->ida_user_data = NULL; - new_IDAB_mem->ida_lmem = NULL; - new_IDAB_mem->ida_lfree = NULL; - new_IDAB_mem->ida_pmem = NULL; - new_IDAB_mem->ida_pfree = NULL; + new_IDAB_mem->ida_lmem = NULL; + new_IDAB_mem->ida_lfree = NULL; + new_IDAB_mem->ida_pmem = NULL; + new_IDAB_mem->ida_pfree = NULL; - new_IDAB_mem->ida_yy = NULL; - new_IDAB_mem->ida_yp = NULL; + new_IDAB_mem->ida_yy = NULL; + new_IDAB_mem->ida_yp = NULL; - new_IDAB_mem->ida_res_withSensi = SUNFALSE; + new_IDAB_mem->ida_res_withSensi = SUNFALSE; new_IDAB_mem->ida_rhsQ_withSensi = SUNFALSE; /* Attach the new object to the beginning of the linked list IDAADJ_mem->IDAB_mem. */ new_IDAB_mem->ida_next = IDAADJ_mem->IDAB_mem; - IDAADJ_mem->IDAB_mem = new_IDAB_mem; + IDAADJ_mem->IDAB_mem = new_IDAB_mem; /* Return the assigned index. This id is used as identificator and has to be passed to IDAInitB and other ***B functions that set the optional inputs for this @@ -664,61 +731,78 @@ int IDACreateB(void *ida_mem, int *which) /*Increase the counter of the backward problems stored. */ IDAADJ_mem->ia_nbckpbs++; - return(IDA_SUCCESS); - + return (IDA_SUCCESS); } -int IDAInitB(void *ida_mem, int which, IDAResFnB resB, - realtype tB0, N_Vector yyB0, N_Vector ypB0) +int IDAInitB(void* ida_mem, int which, IDAResFnB resB, sunrealtype tB0, + N_Vector yyB0, N_Vector ypB0) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; IDABMem IDAB_mem; - void * ida_memB; + void* ida_memB; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAInitB", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAInitB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the initial time for this backward problem against the adjoint data. */ - if ( (tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal) ) { - IDAProcessError(IDA_mem, IDA_BAD_TB0, "IDAA", "IDAInitB", MSGAM_BAD_TB0); - return(IDA_BAD_TB0); + if ((tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal)) + { + IDAProcessError(IDA_mem, IDA_BAD_TB0, __LINE__, __func__, __FILE__, + MSGAM_BAD_TB0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_TB0); } /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAInitB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Call the IDAInit for this backward problem. */ flag = IDAInit(ida_memB, IDAAres, tB0, yyB0, ypB0); - if (IDA_SUCCESS != flag) return(flag); + if (IDA_SUCCESS != flag) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); + } /* Copy residual function in IDAB_mem. */ - IDAB_mem->ida_res = resB; + IDAB_mem->ida_res = resB; IDAB_mem->ida_res_withSensi = SUNFALSE; /* Initialized the initial time field. */ @@ -730,69 +814,90 @@ int IDAInitB(void *ida_mem, int which, IDAResFnB resB, N_VScale(ONE, yyB0, IDAB_mem->ida_yy); N_VScale(ONE, ypB0, IDAB_mem->ida_yp); - return(flag); - + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } -int IDAInitBS(void *ida_mem, int which, IDAResFnBS resS, - realtype tB0, N_Vector yyB0, N_Vector ypB0) +int IDAInitBS(void* ida_mem, int which, IDAResFnBS resS, sunrealtype tB0, + N_Vector yyB0, N_Vector ypB0) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; IDABMem IDAB_mem; - void * ida_memB; + void* ida_memB; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAInitBS", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAInitBS", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the initial time for this backward problem against the adjoint data. */ - if ( (tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal) ) { - IDAProcessError(IDA_mem, IDA_BAD_TB0, "IDAA", "IDAInitBS", MSGAM_BAD_TB0); - return(IDA_BAD_TB0); + if ((tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal)) + { + IDAProcessError(IDA_mem, IDA_BAD_TB0, __LINE__, __func__, __FILE__, + MSGAM_BAD_TB0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_TB0); } /* Were sensitivities active during the forward integration? */ - if (!IDAADJ_mem->ia_storeSensi) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAInitBS", MSGAM_BAD_SENSI); - return(IDA_ILL_INPUT); + if (!IDAADJ_mem->ia_storeSensi) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAInitBS", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Allocate and set the IDAS object */ flag = IDAInit(ida_memB, IDAAres, tB0, yyB0, ypB0); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); + } /* Copy residual function pointer in IDAB_mem. */ IDAB_mem->ida_res_withSensi = SUNTRUE; - IDAB_mem->ida_resS = resS; + IDAB_mem->ida_resS = resS; /* Allocate space and initialize the yy and yp vectors. */ IDAB_mem->ida_t0 = tB0; @@ -801,368 +906,451 @@ int IDAInitBS(void *ida_mem, int which, IDAResFnBS resS, N_VScale(ONE, yyB0, IDAB_mem->ida_yy); N_VScale(ONE, ypB0, IDAB_mem->ida_yp); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - -int IDAReInitB(void *ida_mem, int which, - realtype tB0, N_Vector yyB0, N_Vector ypB0) +int IDAReInitB(void* ida_mem, int which, sunrealtype tB0, N_Vector yyB0, + N_Vector ypB0) { - IDAadjMem IDAADJ_mem; IDAMem IDA_mem; IDABMem IDAB_mem; - void * ida_memB; + void* ida_memB; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAReInitB", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAReInitB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the initial time for this backward problem against the adjoint data. */ - if ( (tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal) ) { - IDAProcessError(IDA_mem, IDA_BAD_TB0, "IDAA", "IDAReInitB", MSGAM_BAD_TB0); - return(IDA_BAD_TB0); + if ((tB0 < IDAADJ_mem->ia_tinitial) || (tB0 > IDAADJ_mem->ia_tfinal)) + { + IDAProcessError(IDA_mem, IDA_BAD_TB0, __LINE__, __func__, __FILE__, + MSGAM_BAD_TB0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_TB0); } /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAReInitB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; /* Call the IDAReInit for this backward problem. */ flag = IDAReInit(ida_memB, tB0, yyB0, ypB0); - return(flag); + + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } -int IDASStolerancesB(void *ida_mem, int which, - realtype relTolB, realtype absTolB) +int IDASStolerancesB(void* ida_mem, int which, sunrealtype relTolB, + sunrealtype absTolB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASStolerancesB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASStolerancesB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASStolerancesB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Set tolerances and return. */ return IDASStolerances(ida_memB, relTolB, absTolB); - } -int IDASVtolerancesB(void *ida_mem, int which, - realtype relTolB, N_Vector absTolB) + +int IDASVtolerancesB(void* ida_mem, int which, sunrealtype relTolB, + N_Vector absTolB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASVtolerancesB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASVtolerancesB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASVtolerancesB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Set tolerances and return. */ return IDASVtolerances(ida_memB, relTolB, absTolB); } -int IDAQuadSStolerancesB(void *ida_mem, int which, - realtype reltolQB, realtype abstolQB) +int IDAQuadSStolerancesB(void* ida_mem, int which, sunrealtype reltolQB, + sunrealtype abstolQB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAQuadSStolerancesB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAQuadSStolerancesB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAQuadSStolerancesB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; return IDAQuadSStolerances(ida_memB, reltolQB, abstolQB); } - -int IDAQuadSVtolerancesB(void *ida_mem, int which, - realtype reltolQB, N_Vector abstolQB) +int IDAQuadSVtolerancesB(void* ida_mem, int which, sunrealtype reltolQB, + N_Vector abstolQB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAQuadSVtolerancesB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAQuadSVtolerancesB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAQuadSVtolerancesB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; return IDAQuadSVtolerances(ida_memB, reltolQB, abstolQB); } - -int IDAQuadInitB(void *ida_mem, int which, IDAQuadRhsFnB rhsQB, N_Vector yQB0) +int IDAQuadInitB(void* ida_mem, int which, IDAQuadRhsFnB rhsQB, N_Vector yQB0) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAQuadInitB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAQuadInitB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAQuadInitB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; flag = IDAQuadInit(ida_memB, IDAArhsQ, yQB0); - if (IDA_SUCCESS != flag) return flag; + if (IDA_SUCCESS != flag) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); + } IDAB_mem->ida_rhsQ_withSensi = SUNFALSE; - IDAB_mem->ida_rhsQ = rhsQB; + IDAB_mem->ida_rhsQ = rhsQB; - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } - -int IDAQuadInitBS(void *ida_mem, int which, - IDAQuadRhsFnBS rhsQS, N_Vector yQB0) +int IDAQuadInitBS(void* ida_mem, int which, IDAQuadRhsFnBS rhsQS, N_Vector yQB0) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; IDABMem IDAB_mem; - void * ida_memB; + void* ida_memB; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAQuadInitBS", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAQuadInitBS", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAQuadInitBS", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* Get the IDAMem corresponding to this backward problem. */ - ida_memB = (void*) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Allocate and set the IDAS object */ flag = IDAQuadInit(ida_memB, IDAArhsQ, yQB0); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); + } /* Copy RHS function pointer in IDAB_mem and enable quad sensitivities. */ IDAB_mem->ida_rhsQ_withSensi = SUNTRUE; - IDAB_mem->ida_rhsQS = rhsQS; + IDAB_mem->ida_rhsQS = rhsQS; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - -int IDAQuadReInitB(void *ida_mem, int which, N_Vector yQB0) +int IDAQuadReInitB(void* ida_mem, int which, N_Vector yQB0) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + int retval; + void* ida_memB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAQuadInitB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAQuadInitB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAQuadInitB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; - return IDAQuadReInit(ida_memB, yQB0); -} + retval = IDAQuadReInit(ida_memB, yQB0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (retval); +} /* * ---------------------------------------------------------------- @@ -1177,43 +1365,54 @@ int IDAQuadReInitB(void *ida_mem, int which, N_Vector yQB0) * a call to IDACalcIC is NOT necessary (for index-one problems). */ -int IDACalcICB(void *ida_mem, int which, realtype tout1, - N_Vector yy0, N_Vector yp0) +int IDACalcICB(void* ida_mem, int which, sunrealtype tout1, N_Vector yy0, + N_Vector yp0) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDACalcICB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDACalcICB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDACalcICB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* The wrapper for user supplied res function requires ia_bckpbCrt from IDAAdjMem to be set to curent problem. */ @@ -1233,7 +1432,8 @@ int IDACalcICB(void *ida_mem, int which, realtype tout1, /* Set interpolation on in IDAARes. */ IDAADJ_mem->ia_noInterp = SUNFALSE; - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } /* @@ -1247,55 +1447,71 @@ int IDACalcICB(void *ida_mem, int which, realtype tout1, * It calls IDACalcIC for the 'which' backward problem. */ -int IDACalcICBS(void *ida_mem, int which, realtype tout1, - N_Vector yy0, N_Vector yp0, - N_Vector *yyS0, N_Vector *ypS0) +int IDACalcICBS(void* ida_mem, int which, sunrealtype tout1, N_Vector yy0, + N_Vector yp0, N_Vector* yyS0, N_Vector* ypS0) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag, is, retval; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDACalcICBS", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDACalcICBS", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Were sensitivities active during the forward integration? */ - if (!IDAADJ_mem->ia_storeSensi) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDACalcICBS", MSGAM_BAD_SENSI); - return(IDA_ILL_INPUT); + if (!IDAADJ_mem->ia_storeSensi) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDACalcICBS", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Was InitBS called for this problem? */ - if (!IDAB_mem->ida_res_withSensi) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDACalcICBS", MSGAM_NO_INITBS); - return(IDA_ILL_INPUT); + if (!IDAB_mem->ida_res_withSensi) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_NO_INITBS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* The wrapper for user supplied res function requires ia_bckpbCrt from @@ -1309,16 +1525,23 @@ int IDACalcICBS(void *ida_mem, int which, realtype tout1, N_VScale(ONE, yy0, IDAADJ_mem->ia_yyTmp); N_VScale(ONE, yp0, IDAADJ_mem->ia_ypTmp); - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - yyS0, IDAADJ_mem->ia_yySTmp); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, yyS0, + IDAADJ_mem->ia_yySTmp); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - ypS0, IDAADJ_mem->ia_ypSTmp); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, ypS0, + IDAADJ_mem->ia_ypSTmp); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Set noInterp flag to SUNTRUE, so IDAARes will use user provided values for y and y' and will not call the interpolation routine(s). */ @@ -1329,10 +1552,10 @@ int IDACalcICBS(void *ida_mem, int which, realtype tout1, /* Set interpolation on in IDAARes. */ IDAADJ_mem->ia_noInterp = SUNFALSE; - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } - /* * IDASolveB * @@ -1353,40 +1576,53 @@ int IDACalcICBS(void *ida_mem, int which, realtype tout1, * when called in ONE_STEP mode. */ -int IDASolveB(void *ida_mem, realtype tBout, int itaskB) +int IDASolveB(void* ida_mem, sunrealtype tBout, int itaskB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - CkpntMem ck_mem; + IDAckpntMem ck_mem; IDABMem IDAB_mem, tmp_IDAB_mem; - int flag=0, sign; - realtype tfuzz, tBret, tBn; - booleantype gotCkpnt, reachedTBout, isActive; + int flag = 0, sign; + sunrealtype tfuzz, tBret, tBn; + sunbooleantype gotCkpnt, reachedTBout, isActive; /* Is the mem OK? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASolveB", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Is ASA initialized ? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASolveB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; - if ( IDAADJ_mem->ia_nbckpbs == 0 ) { - IDAProcessError(IDA_mem, IDA_NO_BCK, "IDAA", "IDASolveB", MSGAM_NO_BCK); - return(IDA_NO_BCK); + if (IDAADJ_mem->ia_nbckpbs == 0) + { + IDAProcessError(IDA_mem, IDA_NO_BCK, __LINE__, __func__, __FILE__, + MSGAM_NO_BCK); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_BCK); } IDAB_mem = IDAADJ_mem->IDAB_mem; /* Check whether IDASolveF has been called */ - if ( IDAADJ_mem->ia_firstIDAFcall ) { - IDAProcessError(IDA_mem, IDA_NO_FWD, "IDAA", "IDASolveB", MSGAM_NO_FWD); - return(IDA_NO_FWD); + if (IDAADJ_mem->ia_firstIDAFcall) + { + IDAProcessError(IDA_mem, IDA_NO_FWD, __LINE__, __func__, __FILE__, + MSGAM_NO_FWD); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_FWD); } sign = (IDAADJ_mem->ia_tfinal - IDAADJ_mem->ia_tinitial > ZERO) ? 1 : -1; @@ -1395,58 +1631,78 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) * - check that tBout is ahead of tB0 in the backward direction * - check whether we need to interpolate forward sensitivities */ - if (IDAADJ_mem->ia_firstIDABcall) { - + if (IDAADJ_mem->ia_firstIDABcall) + { /* First IDABMem struct. */ tmp_IDAB_mem = IDAB_mem; - while (tmp_IDAB_mem != NULL) { - + while (tmp_IDAB_mem != NULL) + { tBn = tmp_IDAB_mem->IDA_mem->ida_tn; - if ( (sign*(tBn-IDAADJ_mem->ia_tinitial) < ZERO) || (sign*(IDAADJ_mem->ia_tfinal-tBn) < ZERO) ) { - IDAProcessError(IDA_mem, IDA_BAD_TB0, "IDAA", "IDASolveB", + if ((sign * (tBn - IDAADJ_mem->ia_tinitial) < ZERO) || + (sign * (IDAADJ_mem->ia_tfinal - tBn) < ZERO)) + { + IDAProcessError(IDA_mem, IDA_BAD_TB0, __LINE__, __func__, __FILE__, MSGAM_BAD_TB0, tmp_IDAB_mem->ida_index); - return(IDA_BAD_TB0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_TB0); } - if (sign*(tBn-tBout) <= ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveB", MSGAM_BAD_TBOUT, - tmp_IDAB_mem->ida_index); - return(IDA_ILL_INPUT); + if (sign * (tBn - tBout) <= ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_TBOUT, tmp_IDAB_mem->ida_index); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if ( tmp_IDAB_mem->ida_res_withSensi || - tmp_IDAB_mem->ida_rhsQ_withSensi ) + if (tmp_IDAB_mem->ida_res_withSensi || tmp_IDAB_mem->ida_rhsQ_withSensi) + { IDAADJ_mem->ia_interpSensi = SUNTRUE; + } /* Advance in list. */ tmp_IDAB_mem = tmp_IDAB_mem->ida_next; } - if ( IDAADJ_mem->ia_interpSensi && !IDAADJ_mem->ia_storeSensi) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveB", MSGAM_BAD_SENSI); - return(IDA_ILL_INPUT); + if (IDAADJ_mem->ia_interpSensi && !IDAADJ_mem->ia_storeSensi) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDAADJ_mem->ia_firstIDABcall = SUNFALSE; } /* Check for valid itask */ - if ( (itaskB != IDA_NORMAL) && (itaskB != IDA_ONE_STEP) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveB", MSG_BAD_ITASK); - return(IDA_ILL_INPUT); + if ((itaskB != IDA_NORMAL) && (itaskB != IDA_ONE_STEP)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Check if tBout is legal */ - if ( (sign*(tBout-IDAADJ_mem->ia_tinitial) < ZERO) || (sign*(IDAADJ_mem->ia_tfinal-tBout) < ZERO) ) { + if ((sign * (tBout - IDAADJ_mem->ia_tinitial) < ZERO) || + (sign * (IDAADJ_mem->ia_tfinal - tBout) < ZERO)) + { tfuzz = HUNDRED * IDA_mem->ida_uround * - (SUNRabs(IDAADJ_mem->ia_tinitial) + SUNRabs(IDAADJ_mem->ia_tfinal)); - if ( (sign*(tBout-IDAADJ_mem->ia_tinitial) < ZERO) && (SUNRabs(tBout-IDAADJ_mem->ia_tinitial) < tfuzz) ) { + (SUNRabs(IDAADJ_mem->ia_tinitial) + SUNRabs(IDAADJ_mem->ia_tfinal)); + if ((sign * (tBout - IDAADJ_mem->ia_tinitial) < ZERO) && + (SUNRabs(tBout - IDAADJ_mem->ia_tinitial) < tfuzz)) + { tBout = IDAADJ_mem->ia_tinitial; - } else { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASolveB", MSGAM_BAD_TBOUT); - return(IDA_ILL_INPUT); + } + else + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_TBOUT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } } @@ -1458,17 +1714,22 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) gotCkpnt = SUNFALSE; - for(;;) { + for (;;) + { tmp_IDAB_mem = IDAB_mem; - while(tmp_IDAB_mem != NULL) { + while (tmp_IDAB_mem != NULL) + { tBn = tmp_IDAB_mem->IDA_mem->ida_tn; - if ( sign*(tBn-ck_mem->ck_t0) > ZERO ) { + if (sign * (tBn - ck_mem->ck_t0) > ZERO) + { gotCkpnt = SUNTRUE; break; } - if ( (itaskB == IDA_NORMAL) && (tBn == ck_mem->ck_t0) && (sign*(tBout-ck_mem->ck_t0) >= ZERO) ) { + if ((itaskB == IDA_NORMAL) && (tBn == ck_mem->ck_t0) && + (sign * (tBout - ck_mem->ck_t0) >= ZERO)) + { gotCkpnt = SUNTRUE; break; } @@ -1476,40 +1737,47 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) tmp_IDAB_mem = tmp_IDAB_mem->ida_next; } - if (gotCkpnt) break; + if (gotCkpnt) { break; } - if (ck_mem->ck_next == NULL) break; + if (ck_mem->ck_next == NULL) { break; } ck_mem = ck_mem->ck_next; } /* Loop while propagating backward problems */ - for(;;) { - + for (;;) + { /* Store interpolation data if not available. This is the 2nd forward integration pass */ - if (ck_mem != IDAADJ_mem->ia_ckpntData) { - + if (ck_mem != IDAADJ_mem->ia_ckpntData) + { flag = IDAAdataStore(IDA_mem, ck_mem); - if (flag != IDA_SUCCESS) break; + if (flag != IDA_SUCCESS) { break; } } /* Starting with the current check point from above, loop over check points while propagating backward problems */ tmp_IDAB_mem = IDAB_mem; - while (tmp_IDAB_mem != NULL) { - + while (tmp_IDAB_mem != NULL) + { /* Decide if current backward problem is "active" in this check point */ isActive = SUNTRUE; tBn = tmp_IDAB_mem->IDA_mem->ida_tn; - if ( (tBn == ck_mem->ck_t0) && (sign*(tBout-ck_mem->ck_t0) < ZERO ) ) isActive = SUNFALSE; - if ( (tBn == ck_mem->ck_t0) && (itaskB == IDA_ONE_STEP) ) isActive = SUNFALSE; - if ( sign*(tBn - ck_mem->ck_t0) < ZERO ) isActive = SUNFALSE; + if ((tBn == ck_mem->ck_t0) && (sign * (tBout - ck_mem->ck_t0) < ZERO)) + { + isActive = SUNFALSE; + } + if ((tBn == ck_mem->ck_t0) && (itaskB == IDA_ONE_STEP)) + { + isActive = SUNFALSE; + } + if (sign * (tBn - ck_mem->ck_t0) < ZERO) { isActive = SUNFALSE; } - if ( isActive ) { + if (isActive) + { /* Store the address of current backward problem memory * in IDAADJ_mem to be used in the wrapper functions */ IDAADJ_mem->ia_bckpbCrt = tmp_IDAB_mem; @@ -1517,18 +1785,17 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) /* Integrate current backward problem */ IDASetStopTime(tmp_IDAB_mem->IDA_mem, ck_mem->ck_t0); flag = IDASolve(tmp_IDAB_mem->IDA_mem, tBout, &tBret, - tmp_IDAB_mem->ida_yy, tmp_IDAB_mem->ida_yp, - itaskB); + tmp_IDAB_mem->ida_yy, tmp_IDAB_mem->ida_yp, itaskB); /* Set the time at which we will report solution and/or quadratures */ tmp_IDAB_mem->ida_tout = tBret; /* If an error occurred, exit while loop */ - if (flag < 0) break; - - } else { - - flag = IDA_SUCCESS; + if (flag < 0) { break; } + } + else + { + flag = IDA_SUCCESS; tmp_IDAB_mem->ida_tout = tBn; } @@ -1537,38 +1804,42 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) } /* End of while: iteration through backward problems. */ /* If an error occurred, return now */ - if (flag <0) { - IDAProcessError(IDA_mem, flag, "IDAA", "IDASolveB", + if (flag < 0) + { + IDAProcessError(IDA_mem, flag, __LINE__, __func__, __FILE__, MSGAM_BACK_ERROR, tmp_IDAB_mem->ida_index); - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } /* If in IDA_ONE_STEP mode, return now (flag = IDA_SUCCESS) */ - if (itaskB == IDA_ONE_STEP) break; + if (itaskB == IDA_ONE_STEP) { break; } /* If all backward problems have succesfully reached tBout, return now */ reachedTBout = SUNTRUE; tmp_IDAB_mem = IDAB_mem; - while(tmp_IDAB_mem != NULL) { - if ( sign*(tmp_IDAB_mem->ida_tout - tBout) > ZERO ) { + while (tmp_IDAB_mem != NULL) + { + if (sign * (tmp_IDAB_mem->ida_tout - tBout) > ZERO) + { reachedTBout = SUNFALSE; break; } tmp_IDAB_mem = tmp_IDAB_mem->ida_next; } - if ( reachedTBout ) break; + if (reachedTBout) { break; } /* Move check point in linked list to next one */ ck_mem = ck_mem->ck_next; } /* End of loop. */ - return(flag); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (flag); } - /* * IDAGetB * @@ -1576,37 +1847,43 @@ int IDASolveB(void *ida_mem, realtype tBout, int itaskB) * in tret) as that at which IDASolveBreturned the solution. */ -int IDAGetB(void* ida_mem, int which, realtype *tret, - N_Vector yy, N_Vector yp) +int IDAGetB(void* ida_mem, int which, sunrealtype* tret, N_Vector yy, N_Vector yp) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAGetB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } @@ -1615,11 +1892,9 @@ int IDAGetB(void* ida_mem, int which, realtype *tret, N_VScale(ONE, IDAB_mem->ida_yp, yp); *tret = IDAB_mem->ida_tout; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - - /* * IDAGetQuadB * @@ -1628,57 +1903,64 @@ int IDAGetB(void* ida_mem, int which, realtype *tret, * returned the solution. */ -int IDAGetQuadB(void *ida_mem, int which, realtype *tret, N_Vector qB) +int IDAGetQuadB(void* ida_mem, int which, sunrealtype* tret, N_Vector qB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag; long int nstB; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetQuadB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetQuadB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAGetQuadB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* If the integration for this backward problem has not started yet, * simply return the current value of qB (i.e. the final conditions) */ flag = IDAGetNumSteps(ida_memB, &nstB); - if (IDA_SUCCESS != flag) return(flag); + if (IDA_SUCCESS != flag) { return (flag); } - if (nstB == 0) { + if (nstB == 0) + { N_VScale(ONE, IDAB_mem->IDA_mem->ida_phiQ[0], qB); *tret = IDAB_mem->ida_tout; - } else { - flag = IDAGetQuad(ida_memB, tret, qB); } - return(flag); + else { flag = IDAGetQuad(ida_memB, tret, qB); } + return (flag); } /*=================================================================*/ @@ -1692,25 +1974,25 @@ int IDAGetQuadB(void *ida_mem, int which, realtype *tret, N_Vector qB) * information from the initial time. */ -static CkpntMem IDAAckpntInit(IDAMem IDA_mem) +static IDAckpntMem IDAAckpntInit(IDAMem IDA_mem) { - CkpntMem ck_mem; + IDAckpntMem ck_mem; /* Allocate space for ckdata */ - ck_mem = (CkpntMem) malloc(sizeof(struct CkpntMemRec)); - if (NULL==ck_mem) return(NULL); + ck_mem = (IDAckpntMem)malloc(sizeof(struct IDAckpntMemRec)); + if (NULL == ck_mem) { return (NULL); } - ck_mem->ck_t0 = IDA_mem->ida_tn; - ck_mem->ck_nst = 0; - ck_mem->ck_kk = 1; - ck_mem->ck_hh = ZERO; + ck_mem->ck_t0 = IDA_mem->ida_tn; + ck_mem->ck_nst = 0; + ck_mem->ck_kk = 1; + ck_mem->ck_hh = ZERO; /* Test if we need to carry quadratures */ ck_mem->ck_quadr = IDA_mem->ida_quadr && IDA_mem->ida_errconQ; /* Test if we need to carry sensitivities */ ck_mem->ck_sensi = IDA_mem->ida_sensi; - if(ck_mem->ck_sensi) ck_mem->ck_Ns = IDA_mem->ida_Ns; + if (ck_mem->ck_sensi) { ck_mem->ck_Ns = IDA_mem->ida_Ns; } /* Test if we need to carry quadrature sensitivities */ ck_mem->ck_quadr_sensi = IDA_mem->ida_quadr_sensi && IDA_mem->ida_errconQS; @@ -1718,17 +2000,19 @@ static CkpntMem IDAAckpntInit(IDAMem IDA_mem) /* Alloc 3: current order, i.e. 1, + 2. */ ck_mem->ck_phi_alloc = 3; - if (!IDAAckpntAllocVectors(IDA_mem, ck_mem)) { - free(ck_mem); ck_mem = NULL; - return(NULL); + if (!IDAAckpntAllocVectors(IDA_mem, ck_mem)) + { + free(ck_mem); + ck_mem = NULL; + return (NULL); } /* Save phi* vectors from IDA_mem to ck_mem. */ IDAAckpntCopyVectors(IDA_mem, ck_mem); /* Next in list */ - ck_mem->ck_next = NULL; + ck_mem->ck_next = NULL; - return(ck_mem); + return (ck_mem); } /* @@ -1738,34 +2022,35 @@ static CkpntMem IDAAckpntInit(IDAMem IDA_mem) * its data from current values in IDA_mem. */ -static CkpntMem IDAAckpntNew(IDAMem IDA_mem) +static IDAckpntMem IDAAckpntNew(IDAMem IDA_mem) { - CkpntMem ck_mem; + IDAckpntMem ck_mem; int j; /* Allocate space for ckdata */ - ck_mem = (CkpntMem) malloc(sizeof(struct CkpntMemRec)); - if (ck_mem == NULL) return(NULL); - - ck_mem->ck_nst = IDA_mem->ida_nst; - ck_mem->ck_tretlast = IDA_mem->ida_tretlast; - ck_mem->ck_kk = IDA_mem->ida_kk; - ck_mem->ck_kused = IDA_mem->ida_kused; - ck_mem->ck_knew = IDA_mem->ida_knew; - ck_mem->ck_phase = IDA_mem->ida_phase; - ck_mem->ck_ns = IDA_mem->ida_ns; - ck_mem->ck_hh = IDA_mem->ida_hh; - ck_mem->ck_hused = IDA_mem->ida_hused; - ck_mem->ck_rr = IDA_mem->ida_rr; - ck_mem->ck_cj = IDA_mem->ida_cj; - ck_mem->ck_cjlast = IDA_mem->ida_cjlast; - ck_mem->ck_cjold = IDA_mem->ida_cjold; - ck_mem->ck_cjratio = IDA_mem->ida_cjratio; - ck_mem->ck_ss = IDA_mem->ida_ss; - ck_mem->ck_ssS = IDA_mem->ida_ssS; - ck_mem->ck_t0 = IDA_mem->ida_tn; - - for (j=0; jck_nst = IDA_mem->ida_nst; + ck_mem->ck_tretlast = IDA_mem->ida_tretlast; + ck_mem->ck_kk = IDA_mem->ida_kk; + ck_mem->ck_kused = IDA_mem->ida_kused; + ck_mem->ck_knew = IDA_mem->ida_knew; + ck_mem->ck_phase = IDA_mem->ida_phase; + ck_mem->ck_ns = IDA_mem->ida_ns; + ck_mem->ck_hh = IDA_mem->ida_hh; + ck_mem->ck_hused = IDA_mem->ida_hused; + ck_mem->ck_eta = IDA_mem->ida_eta; + ck_mem->ck_cj = IDA_mem->ida_cj; + ck_mem->ck_cjlast = IDA_mem->ida_cjlast; + ck_mem->ck_cjold = IDA_mem->ida_cjold; + ck_mem->ck_cjratio = IDA_mem->ida_cjratio; + ck_mem->ck_ss = IDA_mem->ida_ss; + ck_mem->ck_ssS = IDA_mem->ida_ssS; + ck_mem->ck_t0 = IDA_mem->ida_tn; + + for (j = 0; j < MXORDP1; j++) + { ck_mem->ck_psi[j] = IDA_mem->ida_psi[j]; ck_mem->ck_alpha[j] = IDA_mem->ida_alpha[j]; ck_mem->ck_beta[j] = IDA_mem->ida_beta[j]; @@ -1778,23 +2063,25 @@ static CkpntMem IDAAckpntNew(IDAMem IDA_mem) /* Test if we need to carry sensitivities */ ck_mem->ck_sensi = IDA_mem->ida_sensi; - if(ck_mem->ck_sensi) ck_mem->ck_Ns = IDA_mem->ida_Ns; + if (ck_mem->ck_sensi) { ck_mem->ck_Ns = IDA_mem->ida_Ns; } /* Test if we need to carry quadrature sensitivities */ ck_mem->ck_quadr_sensi = IDA_mem->ida_quadr_sensi && IDA_mem->ida_errconQS; - ck_mem->ck_phi_alloc = (IDA_mem->ida_kk+2 < MXORDP1) ? - IDA_mem->ida_kk+2 : MXORDP1; + ck_mem->ck_phi_alloc = (IDA_mem->ida_kk + 2 < MXORDP1) ? IDA_mem->ida_kk + 2 + : MXORDP1; - if (!IDAAckpntAllocVectors(IDA_mem, ck_mem)) { - free(ck_mem); ck_mem = NULL; - return(NULL); + if (!IDAAckpntAllocVectors(IDA_mem, ck_mem)) + { + free(ck_mem); + ck_mem = NULL; + return (NULL); } /* Save phi* vectors from IDA_mem to ck_mem. */ IDAAckpntCopyVectors(IDA_mem, ck_mem); - return(ck_mem); + return (ck_mem); } /* IDAAckpntDelete @@ -1802,39 +2089,46 @@ static CkpntMem IDAAckpntNew(IDAMem IDA_mem) * This routine deletes the first check point in list. */ -static void IDAAckpntDelete(CkpntMem *ck_memPtr) +static void IDAAckpntDelete(IDAckpntMem* ck_memPtr) { - CkpntMem tmp; + IDAckpntMem tmp; int j; - if (*ck_memPtr != NULL) { + if (*ck_memPtr != NULL) + { /* store head of list */ tmp = *ck_memPtr; /* move head of list */ *ck_memPtr = (*ck_memPtr)->ck_next; /* free N_Vectors in tmp */ - for (j=0; jck_phi_alloc; j++) - N_VDestroy(tmp->ck_phi[j]); + for (j = 0; j < tmp->ck_phi_alloc; j++) { N_VDestroy(tmp->ck_phi[j]); } /* free N_Vectors for quadratures in tmp */ - if (tmp->ck_quadr) { - for (j=0; jck_phi_alloc; j++) - N_VDestroy(tmp->ck_phiQ[j]); + if (tmp->ck_quadr) + { + for (j = 0; j < tmp->ck_phi_alloc; j++) { N_VDestroy(tmp->ck_phiQ[j]); } } /* Free sensitivity related data. */ - if (tmp->ck_sensi) { - for (j=0; jck_phi_alloc; j++) + if (tmp->ck_sensi) + { + for (j = 0; j < tmp->ck_phi_alloc; j++) + { N_VDestroyVectorArray(tmp->ck_phiS[j], tmp->ck_Ns); + } } - if (tmp->ck_quadr_sensi) { - for (j=0; jck_phi_alloc; j++) + if (tmp->ck_quadr_sensi) + { + for (j = 0; j < tmp->ck_phi_alloc; j++) + { N_VDestroyVectorArray(tmp->ck_phiQS[j], tmp->ck_Ns); + } } - free(tmp); tmp=NULL; + free(tmp); + tmp = NULL; } } @@ -1845,79 +2139,109 @@ static void IDAAckpntDelete(CkpntMem *ck_memPtr) * current state of IDAMem. * */ -static booleantype IDAAckpntAllocVectors(IDAMem IDA_mem, CkpntMem ck_mem) +static sunbooleantype IDAAckpntAllocVectors(IDAMem IDA_mem, IDAckpntMem ck_mem) { int j, jj; - for (j=0; jck_phi_alloc; j++) { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { ck_mem->ck_phi[j] = N_VClone(IDA_mem->ida_tempv1); - if(ck_mem->ck_phi[j] == NULL) { - for(jj=0; jjck_phi[jj]); - return(SUNFALSE); + if (ck_mem->ck_phi[j] == NULL) + { + for (jj = 0; jj < j; jj++) { N_VDestroy(ck_mem->ck_phi[jj]); } + return (SUNFALSE); } } /* Do we need to carry quadratures? */ - if(ck_mem->ck_quadr) { - for (j=0; jck_phi_alloc; j++) { + if (ck_mem->ck_quadr) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { ck_mem->ck_phiQ[j] = N_VClone(IDA_mem->ida_eeQ); - if(ck_mem->ck_phiQ[j] == NULL) { - for (jj=0; jjck_phiQ[jj]); + if (ck_mem->ck_phiQ[j] == NULL) + { + for (jj = 0; jj < j; jj++) { N_VDestroy(ck_mem->ck_phiQ[jj]); } - for(jj=0; jjck_phi_alloc; jj++) + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroy(ck_mem->ck_phi[jj]); + } - return(SUNFALSE); + return (SUNFALSE); } } } /* Do we need to carry sensitivities? */ - if(ck_mem->ck_sensi) { - - for (j=0; jck_phi_alloc; j++) { - ck_mem->ck_phiS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (ck_mem->ck_phiS[j] == NULL) { - for (jj=0; jjck_sensi) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { + ck_mem->ck_phiS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + if (ck_mem->ck_phiS[j] == NULL) + { + for (jj = 0; jj < j; jj++) + { N_VDestroyVectorArray(ck_mem->ck_phiS[jj], IDA_mem->ida_Ns); + } if (ck_mem->ck_quadr) - for (jj=0; jjck_phi_alloc; jj++) + { + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroy(ck_mem->ck_phiQ[jj]); + } + } - for (jj=0; jjck_phi_alloc; jj++) + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroy(ck_mem->ck_phi[jj]); + } - return(SUNFALSE); + return (SUNFALSE); } } } /* Do we need to carry quadrature sensitivities? */ - if (ck_mem->ck_quadr_sensi) { - - for (j=0; jck_phi_alloc; j++) { - ck_mem->ck_phiQS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_eeQ); - if (ck_mem->ck_phiQS[j] == NULL) { - - for (jj=0; jjck_quadr_sensi) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { + ck_mem->ck_phiQS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_eeQ); + if (ck_mem->ck_phiQS[j] == NULL) + { + for (jj = 0; jj < j; jj++) + { N_VDestroyVectorArray(ck_mem->ck_phiQS[jj], IDA_mem->ida_Ns); + } - for (jj=0; jjck_phi_alloc; jj++) + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroyVectorArray(ck_mem->ck_phiS[jj], IDA_mem->ida_Ns); + } if (ck_mem->ck_quadr) - for (jj=0; jjck_phi_alloc; jj++) + { + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroy(ck_mem->ck_phiQ[jj]); + } + } - for (jj=0; jjck_phi_alloc; jj++) + for (jj = 0; jj < ck_mem->ck_phi_alloc; jj++) + { N_VDestroy(ck_mem->ck_phi[jj]); + } - return(SUNFALSE); + return (SUNFALSE); } } } - return(SUNTRUE); + return (SUNTRUE); } /* @@ -1926,56 +2250,65 @@ static booleantype IDAAckpntAllocVectors(IDAMem IDA_mem, CkpntMem ck_mem) * Copy phi* vectors from IDAMem in the corresponding vectors from checkpoint * */ -static void IDAAckpntCopyVectors(IDAMem IDA_mem, CkpntMem ck_mem) +static void IDAAckpntCopyVectors(IDAMem IDA_mem, IDAckpntMem ck_mem) { int j, is; /* Save phi* arrays from IDA_mem */ - for (j=0; jck_phi_alloc; j++) - IDA_mem->ida_cvals[j] = ONE; + for (j = 0; j < ck_mem->ck_phi_alloc; j++) { IDA_mem->ida_cvals[j] = ONE; } - (void) N_VScaleVectorArray(ck_mem->ck_phi_alloc, IDA_mem->ida_cvals, - IDA_mem->ida_phi, ck_mem->ck_phi); + (void)N_VScaleVectorArray(ck_mem->ck_phi_alloc, IDA_mem->ida_cvals, + IDA_mem->ida_phi, ck_mem->ck_phi); if (ck_mem->ck_quadr) - (void) N_VScaleVectorArray(ck_mem->ck_phi_alloc, IDA_mem->ida_cvals, - IDA_mem->ida_phiQ, ck_mem->ck_phiQ); - - if (ck_mem->ck_sensi || ck_mem->ck_quadr_sensi) { - for (j=0; jck_phi_alloc; j++) { - for (is=0; isida_Ns; is++) { - IDA_mem->ida_cvals[j*IDA_mem->ida_Ns + is] = ONE; + { + (void)N_VScaleVectorArray(ck_mem->ck_phi_alloc, IDA_mem->ida_cvals, + IDA_mem->ida_phiQ, ck_mem->ck_phiQ); + } + + if (ck_mem->ck_sensi || ck_mem->ck_quadr_sensi) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_cvals[j * IDA_mem->ida_Ns + is] = ONE; } } } - if (ck_mem->ck_sensi) { - for (j=0; jck_phi_alloc; j++) { - for (is=0; isida_Ns; is++) { - IDA_mem->ida_Xvecs[j*IDA_mem->ida_Ns + is] = IDA_mem->ida_phiS[j][is]; - IDA_mem->ida_Zvecs[j*IDA_mem->ida_Ns + is] = ck_mem->ck_phiS[j][is]; + if (ck_mem->ck_sensi) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_Xvecs[j * IDA_mem->ida_Ns + is] = IDA_mem->ida_phiS[j][is]; + IDA_mem->ida_Zvecs[j * IDA_mem->ida_Ns + is] = ck_mem->ck_phiS[j][is]; } } - (void) N_VScaleVectorArray(ck_mem->ck_phi_alloc * IDA_mem->ida_Ns, - IDA_mem->ida_cvals, - IDA_mem->ida_Xvecs, IDA_mem->ida_Zvecs); + (void)N_VScaleVectorArray(ck_mem->ck_phi_alloc * IDA_mem->ida_Ns, + IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Zvecs); } - if(ck_mem->ck_quadr_sensi) { - for (j=0; jck_phi_alloc; j++) { - for (is=0; isida_Ns; is++) { - IDA_mem->ida_Xvecs[j*IDA_mem->ida_Ns + is] = IDA_mem->ida_phiQS[j][is]; - IDA_mem->ida_Zvecs[j*IDA_mem->ida_Ns + is] = ck_mem->ck_phiQS[j][is]; + if (ck_mem->ck_quadr_sensi) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_Xvecs[j * IDA_mem->ida_Ns + is] = IDA_mem->ida_phiQS[j][is]; + IDA_mem->ida_Zvecs[j * IDA_mem->ida_Ns + is] = ck_mem->ck_phiQS[j][is]; } } - (void) N_VScaleVectorArray(ck_mem->ck_phi_alloc * IDA_mem->ida_Ns, - IDA_mem->ida_cvals, - IDA_mem->ida_Xvecs, IDA_mem->ida_Zvecs); + (void)N_VScaleVectorArray(ck_mem->ck_phi_alloc * IDA_mem->ida_Ns, + IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Zvecs); } - } /* @@ -1987,36 +2320,36 @@ static void IDAAckpntCopyVectors(IDAMem IDA_mem, CkpntMem ck_mem) * at any other time. */ -static booleantype IDAAdataMalloc(IDAMem IDA_mem) +static sunbooleantype IDAAdataMalloc(IDAMem IDA_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; + IDAdtpntMem* dt_mem; long int i, j; - IDAADJ_mem = IDA_mem->ida_adj_mem; + IDAADJ_mem = IDA_mem->ida_adj_mem; IDAADJ_mem->dt_mem = NULL; - dt_mem = (DtpntMem *)malloc((IDAADJ_mem->ia_nsteps+1)*sizeof(struct DtpntMemRec *)); - if (dt_mem==NULL) return(SUNFALSE); - - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { + dt_mem = (IDAdtpntMem*)malloc((IDAADJ_mem->ia_nsteps + 1) * + sizeof(struct IDAdtpntMemRec*)); + if (dt_mem == NULL) { return (SUNFALSE); } - dt_mem[i] = (DtpntMem)malloc(sizeof(struct DtpntMemRec)); + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { + dt_mem[i] = (IDAdtpntMem)malloc(sizeof(struct IDAdtpntMemRec)); /* On failure, free any allocated memory and return NULL. */ - if (dt_mem[i] == NULL) { - - for(j=0; jcontent = NULL; } /* Attach the allocated dt_mem to IDAADJ_mem. */ IDAADJ_mem->dt_mem = dt_mem; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -2032,21 +2365,21 @@ static void IDAAdataFree(IDAMem IDA_mem) IDAADJ_mem = IDA_mem->ida_adj_mem; - if (IDAADJ_mem == NULL) return; + if (IDAADJ_mem == NULL) { return; } /* Destroy data points by calling the interpolation's 'free' routine. */ IDAADJ_mem->ia_free(IDA_mem); - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { - free(IDAADJ_mem->dt_mem[i]); - IDAADJ_mem->dt_mem[i] = NULL; + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { + free(IDAADJ_mem->dt_mem[i]); + IDAADJ_mem->dt_mem[i] = NULL; } free(IDAADJ_mem->dt_mem); IDAADJ_mem->dt_mem = NULL; } - /* * IDAAdataStore * @@ -2060,28 +2393,28 @@ static void IDAAdataFree(IDAMem IDA_mem) * - IDA_SUCCESS */ -static int IDAAdataStore(IDAMem IDA_mem, CkpntMem ck_mem) +static int IDAAdataStore(IDAMem IDA_mem, IDAckpntMem ck_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - realtype t; + IDAdtpntMem* dt_mem; + sunrealtype t; long int i; int flag, sign; IDAADJ_mem = IDA_mem->ida_adj_mem; - dt_mem = IDAADJ_mem->dt_mem; + dt_mem = IDAADJ_mem->dt_mem; /* Initialize IDA_mem with data from ck_mem. */ flag = IDAAckpntGet(IDA_mem, ck_mem); - if (flag != IDA_SUCCESS) - return(IDA_REIFWD_FAIL); + if (flag != IDA_SUCCESS) { return (IDA_REIFWD_FAIL); } /* Set first structure in dt_mem[0] */ dt_mem[0]->t = ck_mem->ck_t0; IDAADJ_mem->ia_storePnt(IDA_mem, dt_mem[0]); /* Decide whether TSTOP must be activated */ - if (IDAADJ_mem->ia_tstopIDAFcall) { + if (IDAADJ_mem->ia_tstopIDAFcall) + { IDASetStopTime(IDA_mem, IDAADJ_mem->ia_tstopIDAF); } @@ -2090,23 +2423,23 @@ static int IDAAdataStore(IDAMem IDA_mem, CkpntMem ck_mem) /* Run IDASolve in IDA_ONE_STEP mode to set following structures in dt_mem[i]. */ i = 1; do { - flag = IDASolve(IDA_mem, ck_mem->ck_t1, &t, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDA_ONE_STEP); - if (flag < 0) return(IDA_FWD_FAIL); + if (flag < 0) { return (IDA_FWD_FAIL); } dt_mem[i]->t = t; IDAADJ_mem->ia_storePnt(IDA_mem, dt_mem[i]); i++; - } while ( sign*(ck_mem->ck_t1 - t) > ZERO ); + } + while (sign * (ck_mem->ck_t1 - t) > ZERO); /* New data is now available. */ IDAADJ_mem->ia_ckpntData = ck_mem; - IDAADJ_mem->ia_newData = SUNTRUE; - IDAADJ_mem->ia_np = i; + IDAADJ_mem->ia_newData = SUNTRUE; + IDAADJ_mem->ia_np = i; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -2116,82 +2449,100 @@ static int IDAAdataStore(IDAMem IDA_mem, CkpntMem ck_mem) * the check point ck_mem */ -static int IDAAckpntGet(IDAMem IDA_mem, CkpntMem ck_mem) +static int IDAAckpntGet(IDAMem IDA_mem, IDAckpntMem ck_mem) { int flag, j, is; - if (ck_mem->ck_next == NULL) { - + if (ck_mem->ck_next == NULL) + { /* In this case, we just call the reinitialization routine, * but make sure we use the same initial stepsize as on * the first run. */ IDASetInitStep(IDA_mem, IDA_mem->ida_h0u); - flag = IDAReInit(IDA_mem, ck_mem->ck_t0, ck_mem->ck_phi[0], ck_mem->ck_phi[1]); - if (flag != IDA_SUCCESS) return(flag); + flag = IDAReInit(IDA_mem, ck_mem->ck_t0, ck_mem->ck_phi[0], + ck_mem->ck_phi[1]); + if (flag != IDA_SUCCESS) { return (flag); } - if (ck_mem->ck_quadr) { + if (ck_mem->ck_quadr) + { flag = IDAQuadReInit(IDA_mem, ck_mem->ck_phiQ[0]); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) { return (flag); } } - if (ck_mem->ck_sensi) { - flag = IDASensReInit(IDA_mem, IDA_mem->ida_ism, ck_mem->ck_phiS[0], ck_mem->ck_phiS[1]); - if (flag != IDA_SUCCESS) return(flag); + if (ck_mem->ck_sensi) + { + flag = IDASensReInit(IDA_mem, IDA_mem->ida_ism, ck_mem->ck_phiS[0], + ck_mem->ck_phiS[1]); + if (flag != IDA_SUCCESS) { return (flag); } } - if (ck_mem->ck_quadr_sensi) { + if (ck_mem->ck_quadr_sensi) + { flag = IDAQuadSensReInit(IDA_mem, ck_mem->ck_phiQS[0]); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) { return (flag); } } - - } else { - + } + else + { /* Copy parameters from check point data structure */ - IDA_mem->ida_nst = ck_mem->ck_nst; - IDA_mem->ida_tretlast = ck_mem->ck_tretlast; - IDA_mem->ida_kk = ck_mem->ck_kk; - IDA_mem->ida_kused = ck_mem->ck_kused; - IDA_mem->ida_knew = ck_mem->ck_knew; - IDA_mem->ida_phase = ck_mem->ck_phase; - IDA_mem->ida_ns = ck_mem->ck_ns; - IDA_mem->ida_hh = ck_mem->ck_hh; - IDA_mem->ida_hused = ck_mem->ck_hused; - IDA_mem->ida_rr = ck_mem->ck_rr; - IDA_mem->ida_cj = ck_mem->ck_cj; - IDA_mem->ida_cjlast = ck_mem->ck_cjlast; - IDA_mem->ida_cjold = ck_mem->ck_cjold; - IDA_mem->ida_cjratio = ck_mem->ck_cjratio; - IDA_mem->ida_tn = ck_mem->ck_t0; - IDA_mem->ida_ss = ck_mem->ck_ss; - IDA_mem->ida_ssS = ck_mem->ck_ssS; - + IDA_mem->ida_nst = ck_mem->ck_nst; + IDA_mem->ida_tretlast = ck_mem->ck_tretlast; + IDA_mem->ida_kk = ck_mem->ck_kk; + IDA_mem->ida_kused = ck_mem->ck_kused; + IDA_mem->ida_knew = ck_mem->ck_knew; + IDA_mem->ida_phase = ck_mem->ck_phase; + IDA_mem->ida_ns = ck_mem->ck_ns; + IDA_mem->ida_hh = ck_mem->ck_hh; + IDA_mem->ida_hused = ck_mem->ck_hused; + IDA_mem->ida_eta = ck_mem->ck_eta; + IDA_mem->ida_cj = ck_mem->ck_cj; + IDA_mem->ida_cjlast = ck_mem->ck_cjlast; + IDA_mem->ida_cjold = ck_mem->ck_cjold; + IDA_mem->ida_cjratio = ck_mem->ck_cjratio; + IDA_mem->ida_tn = ck_mem->ck_t0; + IDA_mem->ida_ss = ck_mem->ck_ss; + IDA_mem->ida_ssS = ck_mem->ck_ssS; /* Copy the arrays from check point data structure */ - for (j=0; jck_phi_alloc; j++) + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { N_VScale(ONE, ck_mem->ck_phi[j], IDA_mem->ida_phi[j]); + } - if(ck_mem->ck_quadr) { - for (j=0; jck_phi_alloc; j++) + if (ck_mem->ck_quadr) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { N_VScale(ONE, ck_mem->ck_phiQ[j], IDA_mem->ida_phiQ[j]); + } } - if (ck_mem->ck_sensi) { - for (is=0; isida_Ns; is++) { - for (j=0; jck_phi_alloc; j++) + if (ck_mem->ck_sensi) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { N_VScale(ONE, ck_mem->ck_phiS[j][is], IDA_mem->ida_phiS[j][is]); + } } } - if (ck_mem->ck_quadr_sensi) { - for (is=0; isida_Ns; is++) { - for (j=0; jck_phi_alloc; j++) + if (ck_mem->ck_quadr_sensi) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + for (j = 0; j < ck_mem->ck_phi_alloc; j++) + { N_VScale(ONE, ck_mem->ck_phiQS[j][is], IDA_mem->ida_phiQS[j][is]); + } } } - for (j=0; jida_psi[j] = ck_mem->ck_psi[j]; IDA_mem->ida_alpha[j] = ck_mem->ck_alpha[j]; IDA_mem->ida_beta[j] = ck_mem->ck_beta[j]; @@ -2203,10 +2554,9 @@ static int IDAAckpntGet(IDAMem IDA_mem, CkpntMem ck_mem) IDA_mem->ida_forceSetup = SUNTRUE; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* * ----------------------------------------------------------------- * Functions specific to cubic Hermite interpolation @@ -2222,13 +2572,13 @@ static int IDAAckpntGet(IDAMem IDA_mem, CkpntMem ck_mem) * at any other time. */ -static booleantype IDAAhermiteMalloc(IDAMem IDA_mem) +static sunbooleantype IDAAhermiteMalloc(IDAMem IDA_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - HermiteDataMem content; - long int i, ii=0; - booleantype allocOK; + IDAdtpntMem* dt_mem; + IDAhermiteDataMem content; + long int i, ii = 0; + sunbooleantype allocOK; allocOK = SUNTRUE; @@ -2236,31 +2586,30 @@ static booleantype IDAAhermiteMalloc(IDAMem IDA_mem) /* Allocate space for the vectors yyTmp and ypTmp. */ IDAADJ_mem->ia_yyTmp = N_VClone(IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_yyTmp == NULL) { - return(SUNFALSE); - } + if (IDAADJ_mem->ia_yyTmp == NULL) { return (SUNFALSE); } IDAADJ_mem->ia_ypTmp = N_VClone(IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_ypTmp == NULL) { - return(SUNFALSE); - } + if (IDAADJ_mem->ia_ypTmp == NULL) { return (SUNFALSE); } /* Allocate space for sensitivities temporary vectors. */ - if (IDAADJ_mem->ia_storeSensi) { - - IDAADJ_mem->ia_yySTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_yySTmp == NULL) { + if (IDAADJ_mem->ia_storeSensi) + { + IDAADJ_mem->ia_yySTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + if (IDAADJ_mem->ia_yySTmp == NULL) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - return(SUNFALSE); + return (SUNFALSE); } - IDAADJ_mem->ia_ypSTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_ypSTmp == NULL) { + IDAADJ_mem->ia_ypSTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + if (IDAADJ_mem->ia_ypSTmp == NULL) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); - return(SUNFALSE); - + return (SUNFALSE); } } @@ -2268,89 +2617,100 @@ static booleantype IDAAhermiteMalloc(IDAMem IDA_mem) dt_mem = IDAADJ_mem->dt_mem; - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { - + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { content = NULL; - content = (HermiteDataMem) malloc(sizeof(struct HermiteDataMemRec)); - if (content == NULL) { - ii = i; + content = (IDAhermiteDataMem)malloc(sizeof(struct IDAhermiteDataMemRec)); + if (content == NULL) + { + ii = i; allocOK = SUNFALSE; break; } content->y = N_VClone(IDA_mem->ida_tempv1); - if (content->y == NULL) { - free(content); content = NULL; - ii = i; + if (content->y == NULL) + { + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } content->yd = N_VClone(IDA_mem->ida_tempv1); - if (content->yd == NULL) { + if (content->yd == NULL) + { N_VDestroy(content->y); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - if (IDAADJ_mem->ia_storeSensi) { - + if (IDAADJ_mem->ia_storeSensi) + { content->yS = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (content->yS == NULL) { + if (content->yS == NULL) + { N_VDestroy(content->y); N_VDestroy(content->yd); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } content->ySd = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (content->ySd == NULL) { + if (content->ySd == NULL) + { N_VDestroy(content->y); N_VDestroy(content->yd); N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } } dt_mem[i]->content = content; - } /* If an error occurred, deallocate and return */ - if (!allocOK) { - + if (!allocOK) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDAADJ_mem->ia_ypSTmp, IDA_mem->ida_Ns); } - for (i=0; icontent); + for (i = 0; i < ii; i++) + { + content = (IDAhermiteDataMem)(dt_mem[i]->content); N_VDestroy(content->y); N_VDestroy(content->yd); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); N_VDestroyVectorArray(content->ySd, IDA_mem->ida_Ns); } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } - } - return(allocOK); + return (allocOK); } /* @@ -2362,8 +2722,8 @@ static booleantype IDAAhermiteMalloc(IDAMem IDA_mem) static void IDAAhermiteFree(IDAMem IDA_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - HermiteDataMem content; + IDAdtpntMem* dt_mem; + IDAhermiteDataMem content; long int i; IDAADJ_mem = IDA_mem->ida_adj_mem; @@ -2371,23 +2731,25 @@ static void IDAAhermiteFree(IDAMem IDA_mem) N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDAADJ_mem->ia_ypSTmp, IDA_mem->ida_Ns); } dt_mem = IDAADJ_mem->dt_mem; - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { - - content = (HermiteDataMem) (dt_mem[i]->content); + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { + content = (IDAhermiteDataMem)(dt_mem[i]->content); /* content might be NULL, if IDAAdjInit was called but IDASolveF was not. */ - if(content) { - + if (content) + { N_VDestroy(content->y); N_VDestroy(content->yd); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); N_VDestroyVectorArray(content->ySd, IDA_mem->ida_Ns); } @@ -2405,39 +2767,39 @@ static void IDAAhermiteFree(IDAMem IDA_mem) * Note that the time is already stored. */ -static int IDAAhermiteStorePnt(IDAMem IDA_mem, DtpntMem d) +static int IDAAhermiteStorePnt(IDAMem IDA_mem, IDAdtpntMem d) { IDAadjMem IDAADJ_mem; - HermiteDataMem content; + IDAhermiteDataMem content; int is, retval; IDAADJ_mem = IDA_mem->ida_adj_mem; - content = (HermiteDataMem) d->content; + content = (IDAhermiteDataMem)d->content; /* Load solution(s) */ N_VScale(ONE, IDA_mem->ida_phi[0], content->y); - if (IDAADJ_mem->ia_storeSensi) { - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + if (IDAADJ_mem->ia_storeSensi) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, IDA_mem->ida_phiS[0], content->yS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } /* Load derivative(s). */ IDAAGettnSolutionYp(IDA_mem, content->yd); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { IDAAGettnSolutionYpS(IDA_mem, content->ySd); } - return(0); + return (0); } - /* * IDAAhermiteGetY * @@ -2448,126 +2810,141 @@ static int IDAAhermiteStorePnt(IDAMem IDA_mem, DtpntMem d) * can be directly called by the user through IDAGetAdjY */ -static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS) +static int IDAAhermiteGetY(IDAMem IDA_mem, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - HermiteDataMem content0, content1; + IDAdtpntMem* dt_mem; + IDAhermiteDataMem content0, content1; - realtype t0, t1, delta; - realtype factor1, factor2, factor3; + sunrealtype t0, t1, delta; + sunrealtype factor1, factor2, factor3; N_Vector y0, yd0, y1, yd1; - N_Vector *yS0=NULL, *ySd0=NULL, *yS1, *ySd1; + N_Vector *yS0 = NULL, *ySd0 = NULL, *yS1, *ySd1; int flag, is, NS; long int indx; - booleantype newpoint; + sunbooleantype newpoint; /* local variables for fused vector oerations */ int retval; - realtype cvals[4]; - N_Vector Xvecs[4]; + sunrealtype cvals[4]; + N_Vector Xvecs[4]; N_Vector* XXvecs[4]; IDAADJ_mem = IDA_mem->ida_adj_mem; - dt_mem = IDAADJ_mem->dt_mem; + dt_mem = IDAADJ_mem->dt_mem; /* Local value of Ns */ NS = (IDAADJ_mem->ia_interpSensi && (yyS != NULL)) ? IDA_mem->ida_Ns : 0; /* Get the index in dt_mem */ flag = IDAAfindIndex(IDA_mem, t, &indx, &newpoint); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) { return (flag); } /* If we are beyond the left limit but close enough, then return y at the left limit. */ - if (indx == 0) { - content0 = (HermiteDataMem) (dt_mem[0]->content); - N_VScale(ONE, content0->y, yy); + if (indx == 0) + { + content0 = (IDAhermiteDataMem)(dt_mem[0]->content); + N_VScale(ONE, content0->y, yy); N_VScale(ONE, content0->yd, yp); - if (NS > 0) { - for (is=0; isida_cvals[is] = ONE; + if (NS > 0) + { + for (is = 0; is < NS; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content0->yS, yyS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content0->ySd, ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* Extract stuff from the appropriate data points */ - t0 = dt_mem[indx-1]->t; - t1 = dt_mem[indx]->t; + t0 = dt_mem[indx - 1]->t; + t1 = dt_mem[indx]->t; delta = t1 - t0; - content0 = (HermiteDataMem) (dt_mem[indx-1]->content); - y0 = content0->y; - yd0 = content0->yd; - if (IDAADJ_mem->ia_interpSensi) { + content0 = (IDAhermiteDataMem)(dt_mem[indx - 1]->content); + y0 = content0->y; + yd0 = content0->yd; + if (IDAADJ_mem->ia_interpSensi) + { yS0 = content0->yS; ySd0 = content0->ySd; } - if (newpoint) { - + if (newpoint) + { /* Recompute Y0 and Y1 */ - content1 = (HermiteDataMem) (dt_mem[indx]->content); + content1 = (IDAhermiteDataMem)(dt_mem[indx]->content); y1 = content1->y; yd1 = content1->yd; /* Y1 = delta (yd1 + yd0) - 2 (y1 - y0) */ - cvals[0] = -TWO; Xvecs[0] = y1; - cvals[1] = TWO; Xvecs[1] = y0; - cvals[2] = delta; Xvecs[2] = yd1; - cvals[3] = delta; Xvecs[3] = yd0; + cvals[0] = -TWO; + Xvecs[0] = y1; + cvals[1] = TWO; + Xvecs[1] = y0; + cvals[2] = delta; + Xvecs[2] = yd1; + cvals[3] = delta; + Xvecs[3] = yd0; retval = N_VLinearCombination(4, cvals, Xvecs, IDAADJ_mem->ia_Y[1]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* Y0 = y1 - y0 - delta * yd0 */ - cvals[0] = ONE; Xvecs[0] = y1; - cvals[1] = -ONE; Xvecs[1] = y0; - cvals[2] = -delta; Xvecs[2] = yd0; + cvals[0] = ONE; + Xvecs[0] = y1; + cvals[1] = -ONE; + Xvecs[1] = y0; + cvals[2] = -delta; + Xvecs[2] = yd0; retval = N_VLinearCombination(3, cvals, Xvecs, IDAADJ_mem->ia_Y[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* Recompute YS0 and YS1, if needed */ - if (NS > 0) { - + if (NS > 0) + { yS1 = content1->yS; ySd1 = content1->ySd; /* YS1 = delta (ySd1 + ySd0) - 2 (yS1 - yS0) */ - cvals[0] = -TWO; XXvecs[0] = yS1; - cvals[1] = TWO; XXvecs[1] = yS0; - cvals[2] = delta; XXvecs[2] = ySd1; - cvals[3] = delta; XXvecs[3] = ySd0; - - retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, IDAADJ_mem->ia_YS[1]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + cvals[0] = -TWO; + XXvecs[0] = yS1; + cvals[1] = TWO; + XXvecs[1] = yS0; + cvals[2] = delta; + XXvecs[2] = ySd1; + cvals[3] = delta; + XXvecs[3] = ySd0; + + retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, + IDAADJ_mem->ia_YS[1]); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* YS0 = yS1 - yS0 - delta * ySd0 */ - cvals[0] = ONE; XXvecs[0] = yS1; - cvals[1] = -ONE; XXvecs[1] = yS0; - cvals[2] = -delta; XXvecs[2] = ySd0; - - retval = N_VLinearCombinationVectorArray(NS, 3, cvals, XXvecs, IDAADJ_mem->ia_YS[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); - + cvals[0] = ONE; + XXvecs[0] = yS1; + cvals[1] = -ONE; + XXvecs[1] = yS0; + cvals[2] = -delta; + XXvecs[2] = ySd0; + + retval = N_VLinearCombinationVectorArray(NS, 3, cvals, XXvecs, + IDAADJ_mem->ia_YS[0]); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } - } /* Perform the actual interpolation. */ @@ -2575,10 +2952,10 @@ static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, /* For y. */ factor1 = t - t0; - factor2 = factor1/delta; - factor2 = factor2*factor2; + factor2 = factor1 / delta; + factor2 = factor2 * factor2; - factor3 = factor2*(t-t1)/delta; + factor3 = factor2 * (t - t1) / delta; cvals[0] = ONE; cvals[1] = factor1; @@ -2592,26 +2969,26 @@ static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, Xvecs[3] = IDAADJ_mem->ia_Y[1]; retval = N_VLinearCombination(4, cvals, Xvecs, yy); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* Sensi Interpolation. */ /* yS = yS0 + factor1 ySd0 + factor2 * YS[0] + factor3 YS[1], if needed */ - if (NS > 0) { - + if (NS > 0) + { XXvecs[0] = yS0; XXvecs[1] = ySd0; XXvecs[2] = IDAADJ_mem->ia_YS[0]; XXvecs[3] = IDAADJ_mem->ia_YS[1]; retval = N_VLinearCombinationVectorArray(NS, 4, cvals, XXvecs, yyS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); - + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } /* For y'. */ - factor1 = factor1/delta/delta; /* factor1 = 2(t-t0)/(t1-t0)^2 */ - factor2 = factor1*((3*t-2*t1-t0)/delta); /* factor2 = (t-t0)(3*t-2*t1-t0)/(t1-t0)^3 */ + factor1 = factor1 / delta / delta; /* factor1 = 2(t-t0)/(t1-t0)^2 */ + factor2 = factor1 * ((3 * t - 2 * t1 - t0) / + delta); /* factor2 = (t-t0)(3*t-2*t1-t0)/(t1-t0)^3 */ factor1 *= 2; cvals[0] = ONE; @@ -2624,23 +3001,22 @@ static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, Xvecs[2] = IDAADJ_mem->ia_Y[1]; retval = N_VLinearCombination(3, cvals, Xvecs, yp); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* Sensi interpolation for 1st derivative. */ /* ypS = ySd0 + factor1 YS[0] + factor 2 YS[1], if needed */ - if (NS > 0) { - + if (NS > 0) + { XXvecs[0] = ySd0; XXvecs[1] = IDAADJ_mem->ia_YS[0]; XXvecs[2] = IDAADJ_mem->ia_YS[1]; retval = N_VLinearCombinationVectorArray(NS, 3, cvals, XXvecs, ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); - + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -2661,13 +3037,13 @@ static int IDAAhermiteGetY(IDAMem IDA_mem, realtype t, * data point. */ -static booleantype IDAApolynomialMalloc(IDAMem IDA_mem) +static sunbooleantype IDAApolynomialMalloc(IDAMem IDA_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; - long int i, ii=0; - booleantype allocOK; + IDAdtpntMem* dt_mem; + IDApolynomialDataMem content; + long int i, ii = 0; + sunbooleantype allocOK; allocOK = SUNTRUE; @@ -2675,129 +3051,143 @@ static booleantype IDAApolynomialMalloc(IDAMem IDA_mem) /* Allocate space for the vectors yyTmp and ypTmp */ IDAADJ_mem->ia_yyTmp = N_VClone(IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_yyTmp == NULL) { - return(SUNFALSE); - } + if (IDAADJ_mem->ia_yyTmp == NULL) { return (SUNFALSE); } IDAADJ_mem->ia_ypTmp = N_VClone(IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_ypTmp == NULL) { - return(SUNFALSE); - } - - if (IDAADJ_mem->ia_storeSensi) { - - IDAADJ_mem->ia_yySTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_yySTmp == NULL) { + if (IDAADJ_mem->ia_ypTmp == NULL) { return (SUNFALSE); } + + if (IDAADJ_mem->ia_storeSensi) + { + IDAADJ_mem->ia_yySTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + if (IDAADJ_mem->ia_yySTmp == NULL) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - return(SUNFALSE); + return (SUNFALSE); } - IDAADJ_mem->ia_ypSTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (IDAADJ_mem->ia_ypSTmp == NULL) { + IDAADJ_mem->ia_ypSTmp = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + if (IDAADJ_mem->ia_ypSTmp == NULL) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); - return(SUNFALSE); - + return (SUNFALSE); } } /* Allocate space for the content field of the dt structures */ dt_mem = IDAADJ_mem->dt_mem; - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { - + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { content = NULL; - content = (PolynomialDataMem) malloc(sizeof(struct PolynomialDataMemRec)); - if (content == NULL) { - ii = i; + content = (IDApolynomialDataMem)malloc(sizeof(struct IDApolynomialDataMemRec)); + if (content == NULL) + { + ii = i; allocOK = SUNFALSE; break; } content->y = N_VClone(IDA_mem->ida_tempv1); - if (content->y == NULL) { - free(content); content = NULL; - ii = i; + if (content->y == NULL) + { + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } /* Allocate space for yp also. Needed for the most left point interpolation. */ - if (i == 0) { + if (i == 0) + { content->yd = N_VClone(IDA_mem->ida_tempv1); /* Memory allocation failure ? */ - if (content->yd == NULL) { + if (content->yd == NULL) + { N_VDestroy(content->y); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; } - } else { + } + else + { /* Not the first data point. */ content->yd = NULL; } - if (IDAADJ_mem->ia_storeSensi) { - + if (IDAADJ_mem->ia_storeSensi) + { content->yS = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (content->yS == NULL) { + if (content->yS == NULL) + { N_VDestroy(content->y); - if (content->yd) N_VDestroy(content->yd); - free(content); content = NULL; - ii = i; + if (content->yd) { N_VDestroy(content->yd); } + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; break; } - if (i==0) { + if (i == 0) + { content->ySd = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - if (content->ySd == NULL) { + if (content->ySd == NULL) + { N_VDestroy(content->y); - if (content->yd) N_VDestroy(content->yd); + if (content->yd) { N_VDestroy(content->yd); } N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); - free(content); content = NULL; - ii = i; + free(content); + content = NULL; + ii = i; allocOK = SUNFALSE; } - } else { - content->ySd = NULL; } + else { content->ySd = NULL; } } dt_mem[i]->content = content; } /* If an error occurred, deallocate and return */ - if (!allocOK) { - + if (!allocOK) + { N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - if (IDAADJ_mem->ia_storeSensi) { - - N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); - N_VDestroyVectorArray(IDAADJ_mem->ia_ypSTmp, IDA_mem->ida_Ns); + if (IDAADJ_mem->ia_storeSensi) + { + N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); + N_VDestroyVectorArray(IDAADJ_mem->ia_ypSTmp, IDA_mem->ida_Ns); } - for (i=0; icontent); + for (i = 0; i < ii; i++) + { + content = (IDApolynomialDataMem)(dt_mem[i]->content); N_VDestroy(content->y); - if (content->yd) N_VDestroy(content->yd); - - if (IDAADJ_mem->ia_storeSensi) { + if (content->yd) { N_VDestroy(content->yd); } - N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); + if (IDAADJ_mem->ia_storeSensi) + { + N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); - if (content->ySd) - N_VDestroyVectorArray(content->ySd, IDA_mem->ida_Ns); + if (content->ySd) + { + N_VDestroyVectorArray(content->ySd, IDA_mem->ida_Ns); + } } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } - } - return(allocOK); + return (allocOK); } /* @@ -2809,8 +3199,8 @@ static booleantype IDAApolynomialMalloc(IDAMem IDA_mem) static void IDAApolynomialFree(IDAMem IDA_mem) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + IDAdtpntMem* dt_mem; + IDApolynomialDataMem content; long int i; IDAADJ_mem = IDA_mem->ida_adj_mem; @@ -2818,31 +3208,36 @@ static void IDAApolynomialFree(IDAMem IDA_mem) N_VDestroy(IDAADJ_mem->ia_yyTmp); N_VDestroy(IDAADJ_mem->ia_ypTmp); - if (IDAADJ_mem->ia_storeSensi) { + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(IDAADJ_mem->ia_yySTmp, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDAADJ_mem->ia_ypSTmp, IDA_mem->ida_Ns); } dt_mem = IDAADJ_mem->dt_mem; - for (i=0; i<=IDAADJ_mem->ia_nsteps; i++) { - - content = (PolynomialDataMem) (dt_mem[i]->content); + for (i = 0; i <= IDAADJ_mem->ia_nsteps; i++) + { + content = (IDApolynomialDataMem)(dt_mem[i]->content); /* content might be NULL, if IDAAdjInit was called but IDASolveF was not. */ - if(content) { + if (content) + { N_VDestroy(content->y); - if (content->yd) N_VDestroy(content->yd); - - if (IDAADJ_mem->ia_storeSensi) { + if (content->yd) { N_VDestroy(content->yd); } + if (IDAADJ_mem->ia_storeSensi) + { N_VDestroyVectorArray(content->yS, IDA_mem->ida_Ns); if (content->ySd) + { N_VDestroyVectorArray(content->ySd, IDA_mem->ida_Ns); + } } - free(dt_mem[i]->content); dt_mem[i]->content = NULL; + free(dt_mem[i]->content); + dt_mem[i]->content = NULL; } } } @@ -2858,39 +3253,36 @@ static void IDAApolynomialFree(IDAMem IDA_mem) * in which case content->yp is non-null. */ -static int IDAApolynomialStorePnt(IDAMem IDA_mem, DtpntMem d) +static int IDAApolynomialStorePnt(IDAMem IDA_mem, IDAdtpntMem d) { IDAadjMem IDAADJ_mem; - PolynomialDataMem content; + IDApolynomialDataMem content; int is, retval; IDAADJ_mem = IDA_mem->ida_adj_mem; - content = (PolynomialDataMem) d->content; + content = (IDApolynomialDataMem)d->content; N_VScale(ONE, IDA_mem->ida_phi[0], content->y); /* copy also the derivative for the first data point (in this case content->yp is non-null). */ - if (content->yd) - IDAAGettnSolutionYp(IDA_mem, content->yd); - - if (IDAADJ_mem->ia_storeSensi) { + if (content->yd) { IDAAGettnSolutionYp(IDA_mem, content->yd); } - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + if (IDAADJ_mem->ia_storeSensi) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, IDA_mem->ida_phiS[0], content->yS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* store the derivative if it is the first data point. */ - if(content->ySd) - IDAAGettnSolutionYpS(IDA_mem, content->ySd); + if (content->ySd) { IDAAGettnSolutionYpS(IDA_mem, content->ySd); } } content->order = IDA_mem->ida_kused; - return(0); + return (0); } /* @@ -2902,53 +3294,53 @@ static int IDAApolynomialStorePnt(IDAMem IDA_mem, DtpntMem d) * can be directly called by the user through CVodeGetAdjY. */ -static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS) +static int IDAApolynomialGetY(IDAMem IDA_mem, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS) { IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + IDAdtpntMem* dt_mem; + IDApolynomialDataMem content; int flag, dir, order, i, j, is, NS, retval; long int indx, base; - booleantype newpoint; - realtype delt, factor, Psi, Psiprime; + sunbooleantype newpoint; + sunrealtype delt, factor, Psi, Psiprime; IDAADJ_mem = IDA_mem->ida_adj_mem; - dt_mem = IDAADJ_mem->dt_mem; + dt_mem = IDAADJ_mem->dt_mem; /* Local value of Ns */ NS = (IDAADJ_mem->ia_interpSensi && (yyS != NULL)) ? IDA_mem->ida_Ns : 0; /* Get the index in dt_mem */ flag = IDAAfindIndex(IDA_mem, t, &indx, &newpoint); - if (flag != IDA_SUCCESS) return(flag); + if (flag != IDA_SUCCESS) { return (flag); } /* If we are beyond the left limit but close enough, then return y at the left limit. */ - if (indx == 0) { - content = (PolynomialDataMem) (dt_mem[0]->content); - N_VScale(ONE, content->y, yy); + if (indx == 0) + { + content = (IDApolynomialDataMem)(dt_mem[0]->content); + N_VScale(ONE, content->y, yy); N_VScale(ONE, content->yd, yp); - if (NS > 0) { - for (is=0; isida_cvals[is] = ONE; + if (NS > 0) + { + for (is = 0; is < NS; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content->yS, yyS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content->ySd, ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* Scaling factor */ - delt = SUNRabs(dt_mem[indx]->t - dt_mem[indx-1]->t); + delt = SUNRabs(dt_mem[indx]->t - dt_mem[indx - 1]->t); /* Find the direction of the forward integration */ dir = (IDAADJ_mem->ia_tfinal - IDAADJ_mem->ia_tinitial > ZERO) ? 1 : -1; @@ -2956,62 +3348,78 @@ static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, /* Establish the base point depending on the integration direction. Modify the base if there are not enough points for the current order */ - if (dir == 1) { - base = indx; - content = (PolynomialDataMem) (dt_mem[base]->content); - order = content->order; - if(indx < order) base += order-indx; - } else { - base = indx-1; - content = (PolynomialDataMem) (dt_mem[base]->content); - order = content->order; - if (IDAADJ_mem->ia_np-indx > order) base -= indx+order-IDAADJ_mem->ia_np; + if (dir == 1) + { + base = indx; + content = (IDApolynomialDataMem)(dt_mem[base]->content); + order = content->order; + if (indx < order) { base += order - indx; } + } + else + { + base = indx - 1; + content = (IDApolynomialDataMem)(dt_mem[base]->content); + order = content->order; + if (IDAADJ_mem->ia_np - indx > order) + { + base -= indx + order - IDAADJ_mem->ia_np; + } } /* Recompute Y (divided differences for Newton polynomial) if needed */ - if (newpoint) { - + if (newpoint) + { /* Store 0-th order DD */ - if (dir == 1) { - for(j=0;j<=order;j++) { - IDAADJ_mem->ia_T[j] = dt_mem[base-j]->t; - content = (PolynomialDataMem) (dt_mem[base-j]->content); + if (dir == 1) + { + for (j = 0; j <= order; j++) + { + IDAADJ_mem->ia_T[j] = dt_mem[base - j]->t; + content = (IDApolynomialDataMem)(dt_mem[base - j]->content); N_VScale(ONE, content->y, IDAADJ_mem->ia_Y[j]); - if (NS > 0) { - for (is=0; isida_cvals[is] = ONE; - retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, - content->yS, IDAADJ_mem->ia_YS[j]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (NS > 0) + { + for (is = 0; is < NS; is++) { IDA_mem->ida_cvals[is] = ONE; } + retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content->yS, + IDAADJ_mem->ia_YS[j]); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } } - } else { - for(j=0;j<=order;j++) { - IDAADJ_mem->ia_T[j] = dt_mem[base-1+j]->t; - content = (PolynomialDataMem) (dt_mem[base-1+j]->content); + } + else + { + for (j = 0; j <= order; j++) + { + IDAADJ_mem->ia_T[j] = dt_mem[base - 1 + j]->t; + content = (IDApolynomialDataMem)(dt_mem[base - 1 + j]->content); N_VScale(ONE, content->y, IDAADJ_mem->ia_Y[j]); - if (NS > 0) { - for (is=0; isida_cvals[is] = ONE; - retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, - content->yS, IDAADJ_mem->ia_YS[j]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (NS > 0) + { + for (is = 0; is < NS; is++) { IDA_mem->ida_cvals[is] = ONE; } + retval = N_VScaleVectorArray(NS, IDA_mem->ida_cvals, content->yS, + IDAADJ_mem->ia_YS[j]); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } } } /* Compute higher-order DD */ - for(i=1;i<=order;i++) { - for(j=order;j>=i;j--) { - factor = delt/(IDAADJ_mem->ia_T[j]-IDAADJ_mem->ia_T[j-i]); - N_VLinearSum(factor, IDAADJ_mem->ia_Y[j], -factor, IDAADJ_mem->ia_Y[j-1], IDAADJ_mem->ia_Y[j]); - - for (is=0; isia_YS[j][is], -factor, IDAADJ_mem->ia_YS[j-1][is], IDAADJ_mem->ia_YS[j][is]); - + for (i = 1; i <= order; i++) + { + for (j = order; j >= i; j--) + { + factor = delt / (IDAADJ_mem->ia_T[j] - IDAADJ_mem->ia_T[j - i]); + N_VLinearSum(factor, IDAADJ_mem->ia_Y[j], -factor, + IDAADJ_mem->ia_Y[j - 1], IDAADJ_mem->ia_Y[j]); + + for (is = 0; is < NS; is++) + { + N_VLinearSum(factor, IDAADJ_mem->ia_YS[j][is], -factor, + IDAADJ_mem->ia_YS[j - 1][is], IDAADJ_mem->ia_YS[j][is]); + } } } } @@ -3019,15 +3427,21 @@ static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, /* Perform the actual interpolation for yy using nested multiplications */ IDA_mem->ida_cvals[0] = ONE; - for (i=0; iida_cvals[i+1] = IDA_mem->ida_cvals[i] * (t-IDAADJ_mem->ia_T[i]) / delt; + for (i = 0; i < order; i++) + { + IDA_mem->ida_cvals[i + 1] = IDA_mem->ida_cvals[i] * + (t - IDAADJ_mem->ia_T[i]) / delt; + } - retval = N_VLinearCombination(order+1, IDA_mem->ida_cvals, IDAADJ_mem->ia_Y, yy); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearCombination(order + 1, IDA_mem->ida_cvals, IDAADJ_mem->ia_Y, + yy); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - if (NS > 0) { - retval = N_VLinearCombinationVectorArray(NS, order+1, IDA_mem->ida_cvals, IDAADJ_mem->ia_YS, yyS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (NS > 0) + { + retval = N_VLinearCombinationVectorArray(NS, order + 1, IDA_mem->ida_cvals, + IDAADJ_mem->ia_YS, yyS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } /* Perform the actual interpolation for yp. @@ -3045,27 +3459,31 @@ static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, scaled with delt. */ - Psi = ONE; + Psi = ONE; Psiprime = ZERO; - for(i=1; i<=order; i++) { - factor = (t-IDAADJ_mem->ia_T[i-1])/delt; + for (i = 1; i <= order; i++) + { + factor = (t - IDAADJ_mem->ia_T[i - 1]) / delt; - Psiprime = Psi/delt + factor * Psiprime; - Psi = Psi * factor; + Psiprime = Psi / delt + factor * Psiprime; + Psi = Psi * factor; - IDA_mem->ida_cvals[i-1] = Psiprime; + IDA_mem->ida_cvals[i - 1] = Psiprime; } - retval = N_VLinearCombination(order, IDA_mem->ida_cvals, IDAADJ_mem->ia_Y+1, yp); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearCombination(order, IDA_mem->ida_cvals, IDAADJ_mem->ia_Y + 1, + yp); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - if (NS > 0) { - retval = N_VLinearCombinationVectorArray(NS, order, IDA_mem->ida_cvals, IDAADJ_mem->ia_YS+1, ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (NS > 0) + { + retval = N_VLinearCombinationVectorArray(NS, order, IDA_mem->ida_cvals, + IDAADJ_mem->ia_YS + 1, ypS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -3084,39 +3502,40 @@ static int IDAApolynomialGetY(IDAMem IDA_mem, realtype t, static int IDAAGettnSolutionYp(IDAMem IDA_mem, N_Vector yp) { int j, kord, retval; - realtype C, D, gam; - - if (IDA_mem->ida_nst==0) { + sunrealtype C, D, gam; + if (IDA_mem->ida_nst == 0) + { /* If no integration was done, return the yp supplied by user.*/ N_VScale(ONE, IDA_mem->ida_phi[1], yp); - return(0); + return (0); } /* Compute yp as in IDAGetSolution for this particular case when t=tn. */ kord = IDA_mem->ida_kused; - if(IDA_mem->ida_kused==0) kord=1; + if (IDA_mem->ida_kused == 0) { kord = 1; } - C = ONE; D = ZERO; + C = ONE; + D = ZERO; gam = ZERO; - for (j=1; j <= kord; j++) { - D = D*gam + C/IDA_mem->ida_psi[j-1]; - C = C*gam; - gam = IDA_mem->ida_psi[j-1] / IDA_mem->ida_psi[j]; + for (j = 1; j <= kord; j++) + { + D = D * gam + C / IDA_mem->ida_psi[j - 1]; + C = C * gam; + gam = IDA_mem->ida_psi[j - 1] / IDA_mem->ida_psi[j]; - IDA_mem->ida_dvals[j-1] = D; + IDA_mem->ida_dvals[j - 1] = D; } - retval = N_VLinearCombination(kord, IDA_mem->ida_dvals, - IDA_mem->ida_phi+1, yp); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearCombination(kord, IDA_mem->ida_dvals, IDA_mem->ida_phi + 1, + yp); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(0); + return (0); } - /* * IDAAGettnSolutionYpS * @@ -3124,47 +3543,46 @@ static int IDAAGettnSolutionYp(IDAMem IDA_mem, N_Vector yp) * */ -static int IDAAGettnSolutionYpS(IDAMem IDA_mem, N_Vector *ypS) +static int IDAAGettnSolutionYpS(IDAMem IDA_mem, N_Vector* ypS) { int j, kord, is, retval; - realtype C, D, gam; - - if (IDA_mem->ida_nst==0) { + sunrealtype C, D, gam; + if (IDA_mem->ida_nst == 0) + { /* If no integration was done, return the ypS supplied by user.*/ - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, IDA_mem->ida_phiS[1], ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(0); + return (0); } kord = IDA_mem->ida_kused; - if(IDA_mem->ida_kused==0) kord=1; + if (IDA_mem->ida_kused == 0) { kord = 1; } - C = ONE; D = ZERO; + C = ONE; + D = ZERO; gam = ZERO; - for (j=1; j <= kord; j++) { - D = D*gam + C/IDA_mem->ida_psi[j-1]; - C = C*gam; - gam = IDA_mem->ida_psi[j-1] / IDA_mem->ida_psi[j]; + for (j = 1; j <= kord; j++) + { + D = D * gam + C / IDA_mem->ida_psi[j - 1]; + C = C * gam; + gam = IDA_mem->ida_psi[j - 1] / IDA_mem->ida_psi[j]; - IDA_mem->ida_dvals[j-1] = D; + IDA_mem->ida_dvals[j - 1] = D; } retval = N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, kord, IDA_mem->ida_dvals, - IDA_mem->ida_phiS+1, ypS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + IDA_mem->ida_phiS + 1, ypS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(0); + return (0); } - - /* * IDAAfindIndex * @@ -3178,18 +3596,18 @@ static int IDAAGettnSolutionYpS(IDAMem IDA_mem, N_Vector *ypS) * find indx (t is too far beyond limits). */ -static int IDAAfindIndex(IDAMem ida_mem, realtype t, - long int *indx, booleantype *newpoint) +static int IDAAfindIndex(IDAMem ida_mem, sunrealtype t, long int* indx, + sunbooleantype* newpoint) { IDAadjMem IDAADJ_mem; IDAMem IDA_mem; - DtpntMem *dt_mem; + IDAdtpntMem* dt_mem; int sign; - booleantype to_left, to_right; + sunbooleantype to_left, to_right; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; - dt_mem = IDAADJ_mem->dt_mem; + dt_mem = IDAADJ_mem->dt_mem; *newpoint = SUNFALSE; @@ -3197,63 +3615,67 @@ static int IDAAfindIndex(IDAMem ida_mem, realtype t, sign = (IDAADJ_mem->ia_tfinal - IDAADJ_mem->ia_tinitial > ZERO) ? 1 : -1; /* If this is the first time we use new data */ - if (IDAADJ_mem->ia_newData) { - IDAADJ_mem->ia_ilast = IDAADJ_mem->ia_np-1; - *newpoint = SUNTRUE; - IDAADJ_mem->ia_newData = SUNFALSE; + if (IDAADJ_mem->ia_newData) + { + IDAADJ_mem->ia_ilast = IDAADJ_mem->ia_np - 1; + *newpoint = SUNTRUE; + IDAADJ_mem->ia_newData = SUNFALSE; } /* Search for indx starting from ilast */ - to_left = ( sign*(t - dt_mem[IDAADJ_mem->ia_ilast-1]->t) < ZERO); - to_right = ( sign*(t - dt_mem[IDAADJ_mem->ia_ilast]->t) > ZERO); + to_left = (sign * (t - dt_mem[IDAADJ_mem->ia_ilast - 1]->t) < ZERO); + to_right = (sign * (t - dt_mem[IDAADJ_mem->ia_ilast]->t) > ZERO); - if ( to_left ) { + if (to_left) + { /* look for a new indx to the left */ *newpoint = SUNTRUE; *indx = IDAADJ_mem->ia_ilast; - for(;;) { - if ( *indx == 0 ) break; - if ( sign*(t - dt_mem[*indx-1]->t) <= ZERO ) (*indx)--; - else break; + for (;;) + { + if (*indx == 0) { break; } + if (sign * (t - dt_mem[*indx - 1]->t) <= ZERO) { (*indx)--; } + else { break; } } - if ( *indx == 0 ) - IDAADJ_mem->ia_ilast = 1; - else - IDAADJ_mem->ia_ilast = *indx; + if (*indx == 0) { IDAADJ_mem->ia_ilast = 1; } + else { IDAADJ_mem->ia_ilast = *indx; } - if ( *indx == 0 ) { + if (*indx == 0) + { /* t is beyond leftmost limit. Is it too far? */ - if ( SUNRabs(t - dt_mem[0]->t) > FUZZ_FACTOR * IDA_mem->ida_uround ) { - return(IDA_GETY_BADT); + if (SUNRabs(t - dt_mem[0]->t) > FUZZ_FACTOR * IDA_mem->ida_uround) + { + return (IDA_GETY_BADT); } } - - } else if ( to_right ) { + } + else if (to_right) + { /* look for a new indx to the right */ *newpoint = SUNTRUE; *indx = IDAADJ_mem->ia_ilast; - for(;;) { - if ( sign*(t - dt_mem[*indx]->t) > ZERO) (*indx)++; - else break; + for (;;) + { + if (sign * (t - dt_mem[*indx]->t) > ZERO) { (*indx)++; } + else { break; } } IDAADJ_mem->ia_ilast = *indx; - - } else { + } + else + { /* ilast is still OK */ *indx = IDAADJ_mem->ia_ilast; - } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* * IDAGetAdjY * @@ -3261,22 +3683,23 @@ static int IDAAfindIndex(IDAMem ida_mem, realtype t, * The user must allocate space for y. */ -int IDAGetAdjY(void *ida_mem, realtype t, N_Vector yy, N_Vector yp) +int IDAGetAdjY(void* ida_mem, sunrealtype t, N_Vector yy, N_Vector yp) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetAdjY", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; flag = IDAADJ_mem->ia_getY(IDA_mem, t, yy, yp, NULL, NULL); - return(flag); + return (flag); } /*=================================================================*/ @@ -3290,16 +3713,15 @@ int IDAGetAdjY(void *ida_mem, realtype t, N_Vector yy, N_Vector yp) * the user. */ -static int IDAAres(realtype tt, - N_Vector yyB, N_Vector ypB, N_Vector rrB, - void *ida_mem) +static int IDAAres(sunrealtype tt, N_Vector yyB, N_Vector ypB, N_Vector rrB, + void* ida_mem) { IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; IDAMem IDA_mem; int flag, retval; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; @@ -3307,28 +3729,41 @@ static int IDAAres(realtype tt, IDAB_mem = IDAADJ_mem->ia_bckpbCrt; /* Get forward solution from interpolation. */ - if( IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) - flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + { + flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypSTmp); + } else - flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); + { + flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, + IDAADJ_mem->ia_ypTmp, NULL, NULL); + } - if (flag != IDA_SUCCESS) { - IDAProcessError(IDA_mem, -1, "IDAA", "IDAAres", MSGAM_BAD_TINTERP, tt); - return(-1); + if (flag != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, -1, __LINE__, __func__, __FILE__, + MSGAM_BAD_TINTERP, tt); + return (-1); } } /* Call the user supplied residual. */ - if(IDAB_mem->ida_res_withSensi) { + if (IDAB_mem->ida_res_withSensi) + { retval = IDAB_mem->ida_resS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, - yyB, ypB, - rrB, IDAB_mem->ida_user_data); - }else { - retval = IDAB_mem->ida_res(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, yyB, ypB, rrB, IDAB_mem->ida_user_data); + yyB, ypB, rrB, IDAB_mem->ida_user_data); + } + else + { + retval = IDAB_mem->ida_res(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, rrB, IDAB_mem->ida_user_data); } - return(retval); + return (retval); } /* @@ -3341,16 +3776,15 @@ static int IDAAres(realtype tt, * be of IDAQuadRhsFn type. */ -static int IDAArhsQ(realtype tt, - N_Vector yyB, N_Vector ypB, - N_Vector resvalQB, void *ida_mem) +static int IDAArhsQ(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector resvalQB, void* ida_mem) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; int retval, flag; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; /* Get current backward problem. */ @@ -3359,29 +3793,39 @@ static int IDAArhsQ(realtype tt, retval = IDA_SUCCESS; /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp == SUNFALSE) { - if (IDAADJ_mem->ia_interpSensi) { - flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); - } else { - flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { + if (IDAADJ_mem->ia_interpSensi) + { + flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypSTmp); + } + else + { + flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, + IDAADJ_mem->ia_ypTmp, NULL, NULL); } - if (flag != IDA_SUCCESS) { - IDAProcessError(IDA_mem, -1, "IDAA", "IDAArhsQ", MSGAM_BAD_TINTERP, tt); - return(-1); + if (flag != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, -1, __LINE__, __func__, __FILE__, + MSGAM_BAD_TINTERP, tt); + return (-1); } } /* Call user's adjoint quadrature RHS routine */ - if (IDAB_mem->ida_rhsQ_withSensi) { - retval = IDAB_mem->ida_rhsQS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, - yyB, ypB, - resvalQB, IDAB_mem->ida_user_data); - } else { - retval = IDAB_mem->ida_rhsQ(tt, - IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, - yyB, ypB, - resvalQB, IDAB_mem->ida_user_data); - } - return(retval); + if (IDAB_mem->ida_rhsQ_withSensi) + { + retval = IDAB_mem->ida_rhsQS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, + yyB, ypB, resvalQB, IDAB_mem->ida_user_data); + } + else + { + retval = IDAB_mem->ida_rhsQ(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, resvalQB, IDAB_mem->ida_user_data); + } + return (retval); } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idaa_io.c b/deps/AMICI/ThirdParty/sundials/src/idas/idaa_io.c index 55f23b6cb..0dc65d459 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idaa_io.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idaa_io.c @@ -6,7 +6,7 @@ * Programmer(s): Radu Serban and Cosmin Petra @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,8 +20,7 @@ * ----------------------------------------------------------------- */ - -/* +/* * ================================================================= * IMPORTED HEADER FILES * ================================================================= @@ -29,19 +28,19 @@ #include #include +#include #include "idas_impl.h" -#include -/* +/* * ================================================================= * IDAA PRIVATE CONSTANTS * ================================================================= */ -#define ONE RCONST(1.0) +#define ONE SUN_RCONST(1.0) -/* +/* * ----------------------------------------------------------------- * Optional input functions for ASA * ----------------------------------------------------------------- @@ -55,109 +54,124 @@ * ----------------------------------------------------------------- */ -int IDAAdjSetNoSensi(void *ida_mem) +int IDAAdjSetNoSensi(void* ida_mem) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAAdjSetNoSensi", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAAdjSetNoSensi", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; IDAADJ_mem->ia_storeSensi = SUNFALSE; - - return(IDA_SUCCESS); + + return (IDA_SUCCESS); } -/* +/* * ----------------------------------------------------------------- * Optional input functions for backward integration * ----------------------------------------------------------------- */ -int IDASetNonlinearSolverB(void *ida_mem, int which, SUNNonlinearSolver NLS) +int IDASetNonlinearSolverB(void* ida_mem, int which, SUNNonlinearSolver NLS) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; /* Check if ida_mem exists */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", - "IDASetNonlinearSolverB", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", - "IDASetNonlinearSolverB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", - "IDASetNonlinearSolverB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which' */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if ( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) (IDAB_mem->IDA_mem); + ida_memB = (void*)(IDAB_mem->IDA_mem); - return(IDASetNonlinearSolver(ida_memB, NLS)); + return (IDASetNonlinearSolver(ida_memB, NLS)); } -int IDASetUserDataB(void *ida_mem, int which, void *user_dataB) +int IDASetUserDataB(void* ida_mem, int which, void* user_dataB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetUserDataB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetUserDataB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetUserDataB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } @@ -165,328 +179,384 @@ int IDASetUserDataB(void *ida_mem, int which, void *user_dataB) /* Set user data for this backward problem. */ IDAB_mem->ida_user_data = user_dataB; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } -int IDASetMaxOrdB(void *ida_mem, int which, int maxordB) +int IDASetMaxOrdB(void* ida_mem, int which, int maxordB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetMaxOrdB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetMaxOrdB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetMaxOrdB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; return IDASetMaxOrd(ida_memB, maxordB); } -int IDASetMaxNumStepsB(void *ida_mem, int which, long int mxstepsB) +int IDASetMaxNumStepsB(void* ida_mem, int which, long int mxstepsB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetMaxNumStepsB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetMaxNumStepsB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetMaxNumStepsB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; return IDASetMaxNumSteps(ida_memB, mxstepsB); } -int IDASetInitStepB(void *ida_mem, int which, realtype hinB) +int IDASetInitStepB(void* ida_mem, int which, sunrealtype hinB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetInitStepB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetInitStepB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetInitStepB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetInitStep(ida_memB, hinB); } -int IDASetMaxStepB(void *ida_mem, int which, realtype hmaxB) +int IDASetMaxStepB(void* ida_mem, int which, sunrealtype hmaxB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetMaxStepB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetMaxStepB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetMaxStepB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetMaxStep(ida_memB, hmaxB); } -int IDASetSuppressAlgB(void *ida_mem, int which, booleantype suppressalgB) +int IDASetSuppressAlgB(void* ida_mem, int which, sunbooleantype suppressalgB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetSuppressAlgB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetSuppressAlgB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetSuppressAlgB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetSuppressAlg(ida_memB, suppressalgB); } -int IDASetIdB(void *ida_mem, int which, N_Vector idB) +int IDASetIdB(void* ida_mem, int which, N_Vector idB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetIdB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetIdB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetIdB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetId(ida_memB, idB); } -int IDASetConstraintsB(void *ida_mem, int which, N_Vector constraintsB) +int IDASetConstraintsB(void* ida_mem, int which, N_Vector constraintsB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetConstraintsB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetConstraintsB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetConstraintsB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetConstraints(ida_memB, constraintsB); } + /* * ---------------------------------------------------------------- * Input quadrature functions for ASA * ---------------------------------------------------------------- */ -int IDASetQuadErrConB(void *ida_mem, int which, int errconQB) +int IDASetQuadErrConB(void* ida_mem, int which, int errconQB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDASetQuadErrConB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDASetQuadErrConB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDASetQuadErrConB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; - - return IDASetQuadErrCon(ida_memB, errconQB); + ida_memB = (void*)IDAB_mem->IDA_mem; + return IDASetQuadErrCon(ida_memB, errconQB); } -/* +/* * ----------------------------------------------------------------- * Optional output functions for backward integration * ----------------------------------------------------------------- @@ -495,49 +565,53 @@ int IDASetQuadErrConB(void *ida_mem, int which, int errconQB) /* * IDAGetAdjIDABmem * - * This function returns a (void *) pointer to the IDAS - * memory allocated for the backward problem. This pointer can - * then be used to call any of the IDAGet* IDAS routines to + * This function returns a (void *) pointer to the IDAS + * memory allocated for the backward problem. This pointer can + * then be used to call any of the IDAGet* IDAS routines to * extract optional output for the backward integration phase. */ -void *IDAGetAdjIDABmem(void *ida_mem, int which) +void* IDAGetAdjIDABmem(void* ida_mem, int which) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; - + void* ida_memB; + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, 0, "IDAA", "IDAGetAdjIDABmem", MSGAM_NULL_IDAMEM); - return(NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSGAM_NULL_IDAMEM); + return (NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, 0, "IDAA", "IDAGetAdjIDABmem", MSGAM_NO_ADJ); - return(NULL); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, 0, __LINE__, __func__, __FILE__, MSGAM_NO_ADJ); + return (NULL); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, 0, "IDAA", "IDAGetAdjIDABmem", MSGAM_BAD_WHICH); - return(NULL); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, 0, __LINE__, __func__, __FILE__, MSGAM_BAD_WHICH); + return (NULL); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; - return(ida_memB); + return (ida_memB); } /* @@ -549,44 +623,48 @@ void *IDAGetAdjIDABmem(void *ida_mem, int which) * The user must allocate space for ckpnt (ncheck+1). */ -int IDAGetAdjCheckPointsInfo(void *ida_mem, IDAadjCheckPointRec *ckpnt) +int IDAGetAdjCheckPointsInfo(void* ida_mem, IDAadjCheckPointRec* ckpnt) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - CkpntMem ck_mem; + IDAckpntMem ck_mem; int i; - + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetAdjCheckPointsInfo", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetAdjCheckPointsInfo", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; - i=0; + i = 0; ck_mem = IDAADJ_mem->ck_mem; - while (ck_mem != NULL) { - - ckpnt[i].my_addr = (void *) ck_mem; - ckpnt[i].next_addr = (void *) ck_mem->ck_next; - ckpnt[i].t0 = ck_mem->ck_t0; - ckpnt[i].t1 = ck_mem->ck_t1; - ckpnt[i].nstep = ck_mem->ck_nst; - ckpnt[i].order = ck_mem->ck_kk; - ckpnt[i].step = ck_mem->ck_hh; + while (ck_mem != NULL) + { + ckpnt[i].my_addr = (void*)ck_mem; + ckpnt[i].next_addr = (void*)ck_mem->ck_next; + ckpnt[i].t0 = ck_mem->ck_t0; + ckpnt[i].t1 = ck_mem->ck_t1; + ckpnt[i].nstep = ck_mem->ck_nst; + ckpnt[i].order = ck_mem->ck_kk; + ckpnt[i].step = ck_mem->ck_hh; ck_mem = ck_mem->ck_next; i++; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* IDAGetConsistentICB @@ -598,49 +676,56 @@ int IDAGetAdjCheckPointsInfo(void *ida_mem, IDAadjCheckPointRec *ckpnt) * for 'which' backward problem. */ -int IDAGetConsistentICB(void *ida_mem, int which, N_Vector yyB0_mod, N_Vector ypB0_mod) +int IDAGetConsistentICB(void* ida_mem, int which, N_Vector yyB0_mod, + N_Vector ypB0_mod) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag; - + /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetConsistentICB", MSGAM_NULL_IDAMEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); return IDA_MEM_NULL; } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetConsistentICB", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAGetConsistentICB", MSGAM_BAD_WHICH); - return(IDA_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_BAD_WHICH); + return (IDA_ILL_INPUT); } - + /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; flag = IDAGetConsistentIC(ida_memB, yyB0_mod, ypB0_mod); - return(flag); + return (flag); } - /* * ----------------------------------------------------------------- * Undocumented development user-callable functions @@ -653,130 +738,142 @@ int IDAGetConsistentICB(void *ida_mem, int which, N_Vector yyB0_mod, N_Vector yp * ----------------------------------------------------------------- * Returns the 2 vectors stored for cubic Hermite interpolation at * the data point 'which'. The user must allocate space for yy and - * yd. + * yd. * - * Returns IDA_MEM_NULL if ida_mem is NULL, IDA_ILL_INPUT if the + * Returns IDA_MEM_NULL if ida_mem is NULL, IDA_ILL_INPUT if the * interpolation type previously specified is not IDA_HERMITE or * IDA_SUCCESS otherwise. * */ -int IDAGetAdjDataPointHermite(void *ida_mem, int which, - realtype *t, N_Vector yy, N_Vector yd) +int IDAGetAdjDataPointHermite(void* ida_mem, int which, sunrealtype* t, + N_Vector yy, N_Vector yd) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - HermiteDataMem content; + IDAdtpntMem* dt_mem; + IDAhermiteDataMem content; - /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetAdjDataPointHermite", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + /* Is ida_mem valid? */ + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetAdjDataPointHermite", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; dt_mem = IDAADJ_mem->dt_mem; - if (IDAADJ_mem->ia_interpType != IDA_HERMITE) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAGetAdjDataPointHermite", MSGAM_WRONG_INTERP); - return(IDA_ILL_INPUT); + if (IDAADJ_mem->ia_interpType != IDA_HERMITE) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_WRONG_INTERP); + return (IDA_ILL_INPUT); } - *t = dt_mem[which]->t; - content = (HermiteDataMem) dt_mem[which]->content; + *t = dt_mem[which]->t; + content = (IDAhermiteDataMem)dt_mem[which]->content; - if (yy != NULL) N_VScale(ONE, content->y, yy); - if (yd != NULL) N_VScale(ONE, content->yd, yd); + if (yy != NULL) { N_VScale(ONE, content->y, yy); } + if (yd != NULL) { N_VScale(ONE, content->yd, yd); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* * IDAGetAdjDataPointPolynomial - * + * * Returns the vector stored for polynomial interpolation at the * data point 'which'. The user must allocate space for y. * - * Returns IDA_MEM_NULL if ida_mem is NULL, IDA_ILL_INPUT if the + * Returns IDA_MEM_NULL if ida_mem is NULL, IDA_ILL_INPUT if the * interpolation type previously specified is not IDA_POLYNOMIAL or * IDA_SUCCESS otherwise. */ - -int IDAGetAdjDataPointPolynomial(void *ida_mem, int which, - realtype *t, int *order, N_Vector y) +int IDAGetAdjDataPointPolynomial(void* ida_mem, int which, sunrealtype* t, + int* order, N_Vector y) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - DtpntMem *dt_mem; - PolynomialDataMem content; + IDAdtpntMem* dt_mem; + IDApolynomialDataMem content; /* Is ida_mem valid? */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetAdjDataPointPolynomial", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetAdjDataPointPolynomial", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; dt_mem = IDAADJ_mem->dt_mem; - if (IDAADJ_mem->ia_interpType != IDA_POLYNOMIAL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAA", "IDAGetAdjDataPointPolynomial", MSGAM_WRONG_INTERP); - return(IDA_ILL_INPUT); + if (IDAADJ_mem->ia_interpType != IDA_POLYNOMIAL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGAM_WRONG_INTERP); + return (IDA_ILL_INPUT); } - *t = dt_mem[which]->t; - content = (PolynomialDataMem) dt_mem[which]->content; - - if (y != NULL) N_VScale(ONE, content->y, y); + *t = dt_mem[which]->t; + content = (IDApolynomialDataMem)dt_mem[which]->content; + + if (y != NULL) { N_VScale(ONE, content->y, y); } *order = content->order; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* * IDAGetAdjCurrentCheckPoint - * + * * Returns the address of the 'active' check point. */ -int IDAGetAdjCurrentCheckPoint(void *ida_mem, void **addr) +int IDAGetAdjCurrentCheckPoint(void* ida_mem, void** addr) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAA", "IDAGetAdjCurrentCheckPoint", MSGAM_NULL_IDAMEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSGAM_NULL_IDAMEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_ADJ, "IDAA", "IDAGetAdjCurrentCheckPoint", MSGAM_NO_ADJ); - return(IDA_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_ADJ, __LINE__, __func__, __FILE__, + MSGAM_NO_ADJ); + return (IDA_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; - *addr = (void *) IDAADJ_mem->ia_ckpntData; + *addr = (void*)IDAADJ_mem->ia_ckpntData; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - - - diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas.c index 634a71581..1f3c3b593 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas.c @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -136,41 +136,46 @@ * ================================================================= */ +#include "idas/idas.h" + +#include #include #include -#include #include - -#include "idas_impl.h" #include #include #include +#include "idas_impl.h" +#include "sundials/priv/sundials_errors_impl.h" + /* * ================================================================= * IDAS PRIVATE CONSTANTS * ================================================================= */ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define HALF RCONST(0.5) /* real 0.5 */ -#define QUARTER RCONST(0.25) /* real 0.25 */ -#define TWOTHIRDS RCONST(0.667) /* real 2/3 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define ONEPT5 RCONST(1.5) /* real 1.5 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define FOUR RCONST(4.0) /* real 4.0 */ -#define FIVE RCONST(5.0) /* real 5.0 */ -#define TEN RCONST(10.0) /* real 10.0 */ -#define TWELVE RCONST(12.0) /* real 12.0 */ -#define TWENTY RCONST(20.0) /* real 20.0 */ -#define HUNDRED RCONST(100.0) /* real 100.0 */ -#define PT9 RCONST(0.9) /* real 0.9 */ -#define PT99 RCONST(0.99) /* real 0.99 */ -#define PT1 RCONST(0.1) /* real 0.1 */ -#define PT01 RCONST(0.01) /* real 0.01 */ -#define PT001 RCONST(0.001) /* real 0.001 */ -#define PT0001 RCONST(0.0001) /* real 0.0001 */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define HALF SUN_RCONST(0.5) /* real 0.5 */ +#define TWOTHIRDS SUN_RCONST(0.667) /* real 2/3 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define ONEPT5 SUN_RCONST(1.5) /* real 1.5 */ +#define TWO SUN_RCONST(2.0) /* real 2.0 */ +#define FOUR SUN_RCONST(4.0) /* real 4.0 */ +#define FIVE SUN_RCONST(5.0) /* real 5.0 */ +#define TEN SUN_RCONST(10.0) /* real 10.0 */ +#define TWELVE SUN_RCONST(12.0) /* real 12.0 */ +#define TWENTY SUN_RCONST(20.0) /* real 20.0 */ +#define HUNDRED SUN_RCONST(100.0) /* real 100.0 */ +#define PT9 SUN_RCONST(0.9) /* real 0.9 */ +#define PT99 SUN_RCONST(0.99) /* real 0.99 */ +#define PT1 SUN_RCONST(0.1) /* real 0.1 */ +#define PT01 SUN_RCONST(0.01) /* real 0.01 */ +#define PT001 SUN_RCONST(0.001) /* real 0.001 */ +#define PT0001 SUN_RCONST(0.0001) /* real 0.0001 */ + +/* real 1 + epsilon used in testing if the step size is below its bound */ +#define ONEPSM SUN_RCONST(1.000001) /* * ================================================================= @@ -189,50 +194,49 @@ /* Return values for lower level routines used by IDASolve */ -#define CONTINUE_STEPS +99 +#define CONTINUE_STEPS +99 /* IDACompleteStep constants */ -#define UNSET -1 -#define LOWER +1 -#define RAISE +2 -#define MAINTAIN +3 +#define UNSET -1 +#define LOWER +1 +#define RAISE +2 +#define MAINTAIN +3 /* IDATestError constants */ -#define ERROR_TEST_FAIL +7 +#define ERROR_TEST_FAIL +7 /* * Control constants for lower-level rootfinding functions * ------------------------------------------------------- */ -#define RTFOUND +1 -#define CLOSERT +3 +#define RTFOUND +1 +#define CLOSERT +3 /* * Control constants for sensitivity DQ * ------------------------------------ */ -#define CENTERED1 +1 -#define CENTERED2 +2 -#define FORWARD1 +3 -#define FORWARD2 +4 +#define CENTERED1 +1 +#define CENTERED2 +2 +#define FORWARD1 +3 +#define FORWARD2 +4 /* * Algorithmic constants * --------------------- */ -#define MXNCF 10 /* max number of convergence failures allowed */ -#define MXNEF 10 /* max number of error test failures allowed */ -#define MAXNH 5 /* max. number of h tries in IC calc. */ -#define MAXNJ 4 /* max. number of J tries in IC calc. */ -#define MAXNI 10 /* max. Newton iterations in IC calc. */ -#define EPCON RCONST(0.33) /* Newton convergence test constant */ -#define MAXBACKS 100 /* max backtracks per Newton step in IDACalcIC */ -#define XRATE RCONST(0.25) /* constant for updating Jacobian/preconditioner */ +#define MXNCF 10 /* max number of convergence failures allowed */ +#define MXNEF 10 /* max number of error test failures allowed */ +#define MAXNH 5 /* max. number of h tries in IC calc. */ +#define MAXNJ 4 /* max. number of J tries in IC calc. */ +#define MAXNI 10 /* max. Newton iterations in IC calc. */ +#define EPCON SUN_RCONST(0.33) /* Newton convergence test constant */ +#define MAXBACKS 100 /* max backtracks per Newton step in IDACalcIC */ /* * ================================================================= @@ -240,20 +244,20 @@ * ================================================================= */ -static booleantype IDACheckNvector(N_Vector tmpl); +static sunbooleantype IDACheckNvector(N_Vector tmpl); /* Memory allocation/deallocation */ -static booleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl); +static sunbooleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl); static void IDAFreeVectors(IDAMem IDA_mem); -static booleantype IDAQuadAllocVectors(IDAMem IDA_mem, N_Vector tmpl); +static sunbooleantype IDAQuadAllocVectors(IDAMem IDA_mem, N_Vector tmpl); static void IDAQuadFreeVectors(IDAMem IDA_mem); -static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl); +static sunbooleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl); static void IDASensFreeVectors(IDAMem IDA_mem); -static booleantype IDAQuadSensAllocVectors(IDAMem ida_mem, N_Vector tmpl); +static sunbooleantype IDAQuadSensAllocVectors(IDAMem ida_mem, N_Vector tmpl); static void IDAQuadSensFreeVectors(IDAMem ida_mem); /* Initial setup */ @@ -268,15 +272,18 @@ static int IDAQuadEwtSetSS(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ); static int IDAQuadEwtSetSV(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ); /* Used in IC for sensitivities. */ -int IDASensEwtSet(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); -static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); -static int IDASensEwtSetSS(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); -static int IDASensEwtSetSV(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); - -int IDAQuadSensEwtSet(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS); -static int IDAQuadSensEwtSetEE(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); -static int IDAQuadSensEwtSetSS(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); -static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); +int IDASensEwtSet(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS); +static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS); +static int IDASensEwtSetSS(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS); +static int IDASensEwtSetSV(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS); + +int IDAQuadSensEwtSet(IDAMem IDA_mem, N_Vector* yQScur, N_Vector* weightQS); +static int IDAQuadSensEwtSetEE(IDAMem IDA_mem, N_Vector* yScur, + N_Vector* weightS); +static int IDAQuadSensEwtSetSS(IDAMem IDA_mem, N_Vector* yScur, + N_Vector* weightS); +static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector* yScur, + N_Vector* weightS); /* Main IDAStep function */ @@ -284,14 +291,14 @@ static int IDAStep(IDAMem IDA_mem); /* Function called at beginning of step */ -static void IDASetCoeffs(IDAMem IDA_mem, realtype *ck); +static void IDASetCoeffs(IDAMem IDA_mem, sunrealtype* ck); /* Nonlinear solver functions */ static void IDAPredict(IDAMem IDA_mem); static void IDAQuadPredict(IDAMem IDA_mem); -static void IDASensPredict(IDAMem IDA_mem, N_Vector *yySens, N_Vector *ypSens); -static void IDAQuadSensPredict(IDAMem IDA_mem, N_Vector *yQS, N_Vector *ypQS); +static void IDASensPredict(IDAMem IDA_mem, N_Vector* yySens, N_Vector* ypSens); +static void IDAQuadSensPredict(IDAMem IDA_mem, N_Vector* yQS, N_Vector* ypQS); static int IDANls(IDAMem IDA_mem); static int IDASensNls(IDAMem IDA_mem); @@ -301,46 +308,50 @@ static int IDAQuadSensNls(IDAMem IDA_mem); /* Error test */ -static int IDATestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2); -static int IDAQuadTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2); -static int IDASensTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2); -static int IDAQuadSensTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2); +static int IDATestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2); +static int IDAQuadTestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2); +static int IDASensTestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2); +static int IDAQuadSensTestError(IDAMem IDA_mem, sunrealtype ck, + sunrealtype* err_k, sunrealtype* err_km1, + sunrealtype* err_km2); /* Handling of convergence and/or error test failures */ -static void IDARestore(IDAMem IDA_mem, realtype saved_t); -static int IDAHandleNFlag(IDAMem IDA_mem, int nflag, realtype err_k, realtype err_km1, - long int *ncfnPtr, int *ncfPtr, long int *netfPtr, int *nefPtr); +static void IDARestore(IDAMem IDA_mem, sunrealtype saved_t); +static int IDAHandleNFlag(IDAMem IDA_mem, int nflag, sunrealtype err_k, + sunrealtype err_km1, long int* ncfnPtr, int* ncfPtr, + long int* netfPtr, int* nefPtr); static void IDAReset(IDAMem IDA_mem); /* Function called after a successful step */ -static void IDACompleteStep(IDAMem IDA_mem, realtype err_k, realtype err_km1); +static void IDACompleteStep(IDAMem IDA_mem, sunrealtype err_k, + sunrealtype err_km1); /* Function called to evaluate the solutions y(t) and y'(t) at t. Also used in IDAA */ -int IDAGetSolution(void *ida_mem, realtype t, N_Vector yret, N_Vector ypret); +int IDAGetSolution(void* ida_mem, sunrealtype t, N_Vector yret, N_Vector ypret); /* Stopping tests and failure handling */ -static int IDAStopTest1(IDAMem IDA_mem, realtype tout,realtype *tret, +static int IDAStopTest1(IDAMem IDA_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, N_Vector ypret, int itask); -static int IDAStopTest2(IDAMem IDA_mem, realtype tout, realtype *tret, +static int IDAStopTest2(IDAMem IDA_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, N_Vector ypret, int itask); static int IDAHandleFailure(IDAMem IDA_mem, int sflag); /* Norm functions */ -static realtype IDAQuadWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector xQ, N_Vector wQ); +static sunrealtype IDAQuadWrmsNormUpdate(IDAMem IDA_mem, sunrealtype old_nrm, + N_Vector xQ, N_Vector wQ); -static realtype IDAQuadSensWrmsNorm(IDAMem IDA_mem, N_Vector *xQS, N_Vector *wQS); -static realtype IDAQuadSensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector *xQS, N_Vector *wQS); +static sunrealtype IDAQuadSensWrmsNorm(IDAMem IDA_mem, N_Vector* xQS, + N_Vector* wQS); +static sunrealtype IDAQuadSensWrmsNormUpdate(IDAMem IDA_mem, sunrealtype old_nrm, + N_Vector* xQS, N_Vector* wQS); /* Functions for rootfinding */ @@ -351,25 +362,23 @@ static int IDARootfind(IDAMem IDA_mem); /* Sensitivity residual DQ function */ -static int IDASensRes1DQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, N_Vector resval, - int iS, - N_Vector yyS, N_Vector ypS, N_Vector resvalS, - void *user_dataS, - N_Vector ytemp, N_Vector yptemp, N_Vector restemp); - -static int IDAQuadSensRhsInternalDQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS, - N_Vector rrQ, N_Vector *resvalQS, - void *ida_mem, - N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS); - -static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, - N_Vector yy, N_Vector y, - N_Vector yyS, N_Vector ypS, - N_Vector resvalQ, N_Vector resvalQS, - N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS); +static int IDASensRes1DQ(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector resval, int iS, N_Vector yyS, N_Vector ypS, + N_Vector resvalS, void* user_dataS, N_Vector ytemp, + N_Vector yptemp, N_Vector restemp); + +static int IDAQuadSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS, + N_Vector rrQ, N_Vector* resvalQS, + void* ida_mem, N_Vector yytmp, + N_Vector yptmp, N_Vector tmpQS); + +static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, sunrealtype t, + N_Vector yy, N_Vector y, N_Vector yyS, + N_Vector ypS, N_Vector resvalQ, + N_Vector resvalQS, N_Vector yytmp, + N_Vector yptmp, N_Vector tmpQS); + /* * ================================================================= * EXPORTED FUNCTIONS IMPLEMENTATION @@ -393,22 +402,32 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, * message to standard err and returns NULL. */ -void *IDACreate(void) +void* IDACreate(SUNContext sunctx) { IDAMem IDA_mem; + /* Test inputs */ + if (sunctx == NULL) + { + IDAProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSG_NULL_SUNCTX); + return (NULL); + } + IDA_mem = NULL; - IDA_mem = (IDAMem) malloc(sizeof(struct IDAMemRec)); - if (IDA_mem == NULL) { - IDAProcessError(NULL, 0, "IDAS", "IDACreate", MSG_MEM_FAIL); + IDA_mem = (IDAMem)malloc(sizeof(struct IDAMemRec)); + if (IDA_mem == NULL) + { + IDAProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); return (NULL); } /* Zero out ida_mem */ memset(IDA_mem, 0, sizeof(struct IDAMemRec)); + IDA_mem->ida_sunctx = sunctx; + /* Set unit roundoff in IDA_mem */ - IDA_mem->ida_uround = UNIT_ROUNDOFF; + IDA_mem->ida_uround = SUN_UNIT_ROUNDOFF; /* Set default values for integrator optional inputs */ IDA_mem->ida_res = NULL; @@ -418,12 +437,17 @@ void *IDACreate(void) IDA_mem->ida_user_efun = SUNFALSE; IDA_mem->ida_efun = NULL; IDA_mem->ida_edata = NULL; - IDA_mem->ida_ehfun = IDAErrHandler; - IDA_mem->ida_eh_data = IDA_mem; - IDA_mem->ida_errfp = stderr; IDA_mem->ida_maxord = MAXORD_DEFAULT; IDA_mem->ida_mxstep = MXSTEP_DEFAULT; IDA_mem->ida_hmax_inv = HMAX_INV_DEFAULT; + IDA_mem->ida_hmin = HMIN_DEFAULT; + IDA_mem->ida_eta_max_fx = ETA_MAX_FX_DEFAULT; + IDA_mem->ida_eta_min_fx = ETA_MIN_FX_DEFAULT; + IDA_mem->ida_eta_max = ETA_MAX_DEFAULT; + IDA_mem->ida_eta_low = ETA_LOW_DEFAULT; + IDA_mem->ida_eta_min = ETA_MIN_DEFAULT; + IDA_mem->ida_eta_min_ef = ETA_MIN_EF_DEFAULT; + IDA_mem->ida_eta_cf = ETA_CF_DEFAULT; IDA_mem->ida_hin = ZERO; IDA_mem->ida_epcon = EPCON; IDA_mem->ida_maxnef = MXNEF; @@ -433,56 +457,57 @@ void *IDACreate(void) IDA_mem->ida_constraints = NULL; IDA_mem->ida_constraintsSet = SUNFALSE; IDA_mem->ida_tstopset = SUNFALSE; + IDA_mem->ida_dcj = DCJ_DEFAULT; /* set the saved value maxord_alloc */ IDA_mem->ida_maxord_alloc = MAXORD_DEFAULT; /* Set default values for IC optional inputs */ - IDA_mem->ida_epiccon = PT01 * EPCON; - IDA_mem->ida_maxnh = MAXNH; - IDA_mem->ida_maxnj = MAXNJ; - IDA_mem->ida_maxnit = MAXNI; - IDA_mem->ida_maxbacks = MAXBACKS; - IDA_mem->ida_lsoff = SUNFALSE; - IDA_mem->ida_steptol = SUNRpowerR(IDA_mem->ida_uround, TWOTHIRDS); + IDA_mem->ida_epiccon = PT01 * EPCON; + IDA_mem->ida_maxnh = MAXNH; + IDA_mem->ida_maxnj = MAXNJ; + IDA_mem->ida_maxnit = MAXNI; + IDA_mem->ida_maxbacks = MAXBACKS; + IDA_mem->ida_lsoff = SUNFALSE; + IDA_mem->ida_steptol = SUNRpowerR(IDA_mem->ida_uround, TWOTHIRDS); /* Set default values for quad. optional inputs */ - IDA_mem->ida_quadr = SUNFALSE; - IDA_mem->ida_rhsQ = NULL; - IDA_mem->ida_errconQ = SUNFALSE; - IDA_mem->ida_itolQ = IDA_NN; - IDA_mem->ida_atolQmin0 = SUNTRUE; + IDA_mem->ida_quadr = SUNFALSE; + IDA_mem->ida_rhsQ = NULL; + IDA_mem->ida_errconQ = SUNFALSE; + IDA_mem->ida_itolQ = IDA_NN; + IDA_mem->ida_atolQmin0 = SUNTRUE; /* Set default values for sensi. optional inputs */ - IDA_mem->ida_sensi = SUNFALSE; - IDA_mem->ida_user_dataS = (void *)IDA_mem; - IDA_mem->ida_resS = IDASensResDQ; - IDA_mem->ida_resSDQ = SUNTRUE; - IDA_mem->ida_DQtype = IDA_CENTERED; - IDA_mem->ida_DQrhomax = ZERO; - IDA_mem->ida_p = NULL; - IDA_mem->ida_pbar = NULL; - IDA_mem->ida_plist = NULL; - IDA_mem->ida_errconS = SUNFALSE; - IDA_mem->ida_itolS = IDA_EE; - IDA_mem->ida_atolSmin0 = NULL; - IDA_mem->ida_ism = -1; /* initialize to invalid option */ + IDA_mem->ida_sensi = SUNFALSE; + IDA_mem->ida_user_dataS = (void*)IDA_mem; + IDA_mem->ida_resS = IDASensResDQ; + IDA_mem->ida_resSDQ = SUNTRUE; + IDA_mem->ida_DQtype = IDA_CENTERED; + IDA_mem->ida_DQrhomax = ZERO; + IDA_mem->ida_p = NULL; + IDA_mem->ida_pbar = NULL; + IDA_mem->ida_plist = NULL; + IDA_mem->ida_errconS = SUNFALSE; + IDA_mem->ida_itolS = IDA_EE; + IDA_mem->ida_atolSmin0 = NULL; + IDA_mem->ida_ism = -1; /* initialize to invalid option */ /* Defaults for sensi. quadr. optional inputs. */ - IDA_mem->ida_quadr_sensi = SUNFALSE; - IDA_mem->ida_user_dataQS = (void *)IDA_mem; - IDA_mem->ida_rhsQS = IDAQuadSensRhsInternalDQ; - IDA_mem->ida_rhsQSDQ = SUNTRUE; - IDA_mem->ida_errconQS = SUNFALSE; - IDA_mem->ida_itolQS = IDA_EE; - IDA_mem->ida_atolQSmin0 = NULL; + IDA_mem->ida_quadr_sensi = SUNFALSE; + IDA_mem->ida_user_dataQS = (void*)IDA_mem; + IDA_mem->ida_rhsQS = IDAQuadSensRhsInternalDQ; + IDA_mem->ida_rhsQSDQ = SUNTRUE; + IDA_mem->ida_errconQS = SUNFALSE; + IDA_mem->ida_itolQS = IDA_EE; + IDA_mem->ida_atolQSmin0 = NULL; /* Set defaults for ASA. */ IDA_mem->ida_adj = SUNFALSE; IDA_mem->ida_adj_mem = NULL; /* Initialize lrw and liw */ - IDA_mem->ida_lrw = 25 + 5*MXORDP1; + IDA_mem->ida_lrw = 25 + 5 * MXORDP1; IDA_mem->ida_liw = 38; /* No mallocs have been done yet */ @@ -491,18 +516,18 @@ void *IDACreate(void) IDA_mem->ida_idMallocDone = SUNFALSE; IDA_mem->ida_MallocDone = SUNFALSE; - IDA_mem->ida_VatolQMallocDone = SUNFALSE; - IDA_mem->ida_quadMallocDone = SUNFALSE; + IDA_mem->ida_VatolQMallocDone = SUNFALSE; + IDA_mem->ida_quadMallocDone = SUNFALSE; - IDA_mem->ida_VatolSMallocDone = SUNFALSE; - IDA_mem->ida_SatolSMallocDone = SUNFALSE; - IDA_mem->ida_sensMallocDone = SUNFALSE; + IDA_mem->ida_VatolSMallocDone = SUNFALSE; + IDA_mem->ida_SatolSMallocDone = SUNFALSE; + IDA_mem->ida_sensMallocDone = SUNFALSE; - IDA_mem->ida_VatolQSMallocDone = SUNFALSE; - IDA_mem->ida_SatolQSMallocDone = SUNFALSE; - IDA_mem->ida_quadSensMallocDone = SUNFALSE; + IDA_mem->ida_VatolQSMallocDone = SUNFALSE; + IDA_mem->ida_SatolQSMallocDone = SUNFALSE; + IDA_mem->ida_quadSensMallocDone = SUNFALSE; - IDA_mem->ida_adjMallocDone = SUNFALSE; + IDA_mem->ida_adjMallocDone = SUNFALSE; /* Initialize nonlinear solver variables */ IDA_mem->NLS = NULL; @@ -523,7 +548,7 @@ void *IDACreate(void) IDA_mem->stgMallocDone = SUNFALSE; /* Return pointer to IDA memory block */ - return((void *)IDA_mem); + return ((void*)IDA_mem); } /*-----------------------------------------------------------------*/ @@ -537,53 +562,68 @@ void *IDACreate(void) * error handler function. */ -int IDAInit(void *ida_mem, IDAResFn res, - realtype t0, N_Vector yy0, N_Vector yp0) +int IDAInit(void* ida_mem, IDAResFn res, sunrealtype t0, N_Vector yy0, + N_Vector yp0) { int retval; IDAMem IDA_mem; - booleantype nvectorOK, allocOK; + sunbooleantype nvectorOK, allocOK; sunindextype lrw1, liw1; SUNNonlinearSolver NLS; /* Check ida_mem */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check for legal input parameters */ - if (yy0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInit", MSG_Y0_NULL); - return(IDA_ILL_INPUT); + if (yy0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_Y0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (yp0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInit", MSG_YP0_NULL); - return(IDA_ILL_INPUT); + if (yp0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YP0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (res == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInit", MSG_RES_NULL); - return(IDA_ILL_INPUT); + if (res == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_RES_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Test if all required vector operations are implemented */ nvectorOK = IDACheckNvector(yy0); - if (!nvectorOK) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInit", MSG_BAD_NVECTOR); - return(IDA_ILL_INPUT); + if (!nvectorOK) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_NVECTOR); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Set space requirements for one N_Vector */ - if (yy0->ops->nvspace != NULL) { - N_VSpace(yy0, &lrw1, &liw1); - } else { + if (yy0->ops->nvspace != NULL) { N_VSpace(yy0, &lrw1, &liw1); } + else + { lrw1 = 0; liw1 = 0; } @@ -593,27 +633,32 @@ int IDAInit(void *ida_mem, IDAResFn res, /* Allocate the vectors (using yy0 as a template) */ allocOK = IDAAllocVectors(IDA_mem, yy0); - if (!allocOK) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDAInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (!allocOK) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Allocate temporary work arrays for fused vector ops */ IDA_mem->ida_cvals = NULL; - IDA_mem->ida_cvals = (realtype *) malloc(MXORDP1*sizeof(realtype)); + IDA_mem->ida_cvals = (sunrealtype*)malloc(MXORDP1 * sizeof(sunrealtype)); IDA_mem->ida_Xvecs = NULL; - IDA_mem->ida_Xvecs = (N_Vector *) malloc(MXORDP1*sizeof(N_Vector)); + IDA_mem->ida_Xvecs = (N_Vector*)malloc(MXORDP1 * sizeof(N_Vector)); IDA_mem->ida_Zvecs = NULL; - IDA_mem->ida_Zvecs = (N_Vector *) malloc(MXORDP1*sizeof(N_Vector)); + IDA_mem->ida_Zvecs = (N_Vector*)malloc(MXORDP1 * sizeof(N_Vector)); - if ((IDA_mem->ida_cvals == NULL) || - (IDA_mem->ida_Xvecs == NULL) || - (IDA_mem->ida_Zvecs == NULL)) { + if ((IDA_mem->ida_cvals == NULL) || (IDA_mem->ida_Xvecs == NULL) || + (IDA_mem->ida_Zvecs == NULL)) + { IDAFreeVectors(IDA_mem); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDAInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Input checks complete at this point and history array allocated */ @@ -627,25 +672,30 @@ int IDAInit(void *ida_mem, IDAResFn res, N_VScale(ONE, yp0, IDA_mem->ida_phi[1]); /* create a Newton nonlinear solver object by default */ - NLS = SUNNonlinSol_Newton(yy0); + NLS = SUNNonlinSol_Newton(yy0, IDA_mem->ida_sunctx); /* check that nonlinear solver is non-NULL */ - if (NLS == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDAInit", MSG_MEM_FAIL); + if (NLS == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); IDAFreeVectors(IDA_mem); - return(IDA_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* attach the nonlinear solver to the IDA memory */ retval = IDASetNonlinearSolver(IDA_mem, NLS); /* check that the nonlinear solver was successfully attached */ - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, retval, "IDAS", "IDAInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); IDAFreeVectors(IDA_mem); SUNNonlinSolFree(NLS); - return(IDA_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* set ownership flag */ @@ -653,11 +703,6 @@ int IDAInit(void *ida_mem, IDAResFn res, /* All error checking is complete at this point */ - /* Copy the input parameters into IDA memory block */ - - IDA_mem->ida_res = res; - IDA_mem->ida_tn = t0; - /* Set the linear solver addresses to NULL */ IDA_mem->ida_linit = NULL; @@ -671,11 +716,6 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_forceSetup = SUNFALSE; - /* Initialize the phi array */ - - N_VScale(ONE, yy0, IDA_mem->ida_phi[0]); - N_VScale(ONE, yp0, IDA_mem->ida_phi[1]); - /* Initialize all the counters and other optional output values */ IDA_mem->ida_nst = 0; @@ -683,6 +723,7 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_ncfn = 0; IDA_mem->ida_netf = 0; IDA_mem->ida_nni = 0; + IDA_mem->ida_nnf = 0; IDA_mem->ida_nsetups = 0; IDA_mem->ida_kused = 0; @@ -694,7 +735,7 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_irfnd = 0; /* Initialize counters specific to IC calculation. */ - IDA_mem->ida_nbacktr = 0; + IDA_mem->ida_nbacktr = 0; /* Initialize root-finding variables */ @@ -705,8 +746,8 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_rootdir = NULL; IDA_mem->ida_gfun = NULL; IDA_mem->ida_nrtfn = 0; - IDA_mem->ida_gactive = NULL; - IDA_mem->ida_mxgnull = 1; + IDA_mem->ida_gactive = NULL; + IDA_mem->ida_mxgnull = 1; /* Initial setup not done yet */ @@ -716,7 +757,8 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_MallocDone = SUNTRUE; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -735,41 +777,52 @@ int IDAInit(void *ida_mem, IDAResFn res, * a negative value otherwise. */ -int IDAReInit(void *ida_mem, - realtype t0, N_Vector yy0, N_Vector yp0) +int IDAReInit(void* ida_mem, sunrealtype t0, N_Vector yy0, N_Vector yp0) { IDAMem IDA_mem; /* Check for legal input parameters */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAReInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if problem was malloc'ed */ - if (IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDAReInit", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_MALLOC); } /* Check for legal input parameters */ - if (yy0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAReInit", MSG_Y0_NULL); - return(IDA_ILL_INPUT); + if (yy0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_Y0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (yp0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAReInit", MSG_YP0_NULL); - return(IDA_ILL_INPUT); + if (yp0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YP0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Copy the input parameters into IDA memory block */ - IDA_mem->ida_tn = t0; + IDA_mem->ida_tn = t0; /* Set forceSetup to SUNFALSE */ @@ -787,6 +840,7 @@ int IDAReInit(void *ida_mem, IDA_mem->ida_ncfn = 0; IDA_mem->ida_netf = 0; IDA_mem->ida_nni = 0; + IDA_mem->ida_nnf = 0; IDA_mem->ida_nsetups = 0; IDA_mem->ida_kused = 0; @@ -803,7 +857,8 @@ int IDAReInit(void *ida_mem, /* Problem has been successfully re-initialized */ - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -824,81 +879,95 @@ int IDAReInit(void *ida_mem, * which will be called to set the error weight vector. */ -int IDASStolerances(void *ida_mem, realtype reltol, realtype abstol) +int IDASStolerances(void* ida_mem, sunrealtype reltol, sunrealtype abstol) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASStolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDASStolerances", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + return (IDA_NO_MALLOC); } /* Check inputs */ - if (reltol < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASStolerances", MSG_BAD_RTOL); - return(IDA_ILL_INPUT); + if (reltol < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOL); + return (IDA_ILL_INPUT); } - if (abstol < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASStolerances", MSG_BAD_ATOL); - return(IDA_ILL_INPUT); + if (abstol < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOL); + return (IDA_ILL_INPUT); } /* Copy tolerances into memory */ - IDA_mem->ida_rtol = reltol; - IDA_mem->ida_Satol = abstol; + IDA_mem->ida_rtol = reltol; + IDA_mem->ida_Satol = abstol; IDA_mem->ida_atolmin0 = (abstol == ZERO); IDA_mem->ida_itol = IDA_SS; IDA_mem->ida_user_efun = SUNFALSE; - IDA_mem->ida_efun = IDAEwtSet; - IDA_mem->ida_edata = NULL; /* will be set to ida_mem in InitialSetup */ + IDA_mem->ida_efun = IDAEwtSet; + IDA_mem->ida_edata = NULL; /* will be set to ida_mem in InitialSetup */ - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -int IDASVtolerances(void *ida_mem, realtype reltol, N_Vector abstol) +int IDASVtolerances(void* ida_mem, sunrealtype reltol, N_Vector abstol) { IDAMem IDA_mem; - realtype atolmin; + sunrealtype atolmin; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASVtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDASVtolerances", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + return (IDA_NO_MALLOC); } /* Check inputs */ - if (reltol < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASVtolerances", MSG_BAD_RTOL); - return(IDA_ILL_INPUT); + if (reltol < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOL); + return (IDA_ILL_INPUT); } atolmin = N_VMin(abstol); - if (atolmin < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASVtolerances", MSG_BAD_ATOL); - return(IDA_ILL_INPUT); + if (atolmin < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOL); + return (IDA_ILL_INPUT); } /* Copy tolerances into memory */ - if ( !(IDA_mem->ida_VatolMallocDone) ) { + if (!(IDA_mem->ida_VatolMallocDone)) + { IDA_mem->ida_Vatol = N_VClone(IDA_mem->ida_ewt); IDA_mem->ida_lrw += IDA_mem->ida_lrw1; IDA_mem->ida_liw += IDA_mem->ida_liw1; @@ -912,35 +981,37 @@ int IDASVtolerances(void *ida_mem, realtype reltol, N_Vector abstol) IDA_mem->ida_itol = IDA_SV; IDA_mem->ida_user_efun = SUNFALSE; - IDA_mem->ida_efun = IDAEwtSet; - IDA_mem->ida_edata = NULL; /* will be set to ida_mem in InitialSetup */ + IDA_mem->ida_efun = IDAEwtSet; + IDA_mem->ida_edata = NULL; /* will be set to ida_mem in InitialSetup */ - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -int IDAWFtolerances(void *ida_mem, IDAEwtFn efun) +int IDAWFtolerances(void* ida_mem, IDAEwtFn efun) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAWFtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDAWFtolerances", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + return (IDA_NO_MALLOC); } IDA_mem->ida_itol = IDA_WF; IDA_mem->ida_user_efun = SUNTRUE; - IDA_mem->ida_efun = efun; - IDA_mem->ida_edata = NULL; /* will be set to user_data in InitialSetup */ + IDA_mem->ida_efun = efun; + IDA_mem->ida_edata = NULL; /* will be set to user_data in InitialSetup */ - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -956,19 +1027,22 @@ int IDAWFtolerances(void *ida_mem, IDAEwtFn efun) * a negative value otherwise. */ -int IDAQuadInit(void *ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0) +int IDAQuadInit(void* ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0) { IDAMem IDA_mem; - booleantype allocOK; + sunbooleantype allocOK; sunindextype lrw1Q, liw1Q; int retval; /* Check ida_mem */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Set space requirements for one N_Vector */ N_VSpace(yQ0, &lrw1Q, &liw1Q); @@ -977,16 +1051,23 @@ int IDAQuadInit(void *ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0) /* Allocate the vectors (using yQ0 as a template) */ allocOK = IDAQuadAllocVectors(IDA_mem, yQ0); - if (!allocOK) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDAQuadInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (!allocOK) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Initialize phiQ in the history array */ N_VScale(ONE, yQ0, IDA_mem->ida_phiQ[0]); - retval = N_VConstVectorArray(IDA_mem->ida_maxord, ZERO, IDA_mem->ida_phiQ+1); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VConstVectorArray(IDA_mem->ida_maxord, ZERO, IDA_mem->ida_phiQ + 1); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Copy the input parameters into IDAS state */ IDA_mem->ida_rhsQ = rhsQ; @@ -996,11 +1077,12 @@ int IDAQuadInit(void *ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0) IDA_mem->ida_netfQ = 0; /* Quadrature integration turned ON */ - IDA_mem->ida_quadr = SUNTRUE; + IDA_mem->ida_quadr = SUNTRUE; IDA_mem->ida_quadMallocDone = SUNTRUE; /* Quadrature initialization was successfull */ - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1018,29 +1100,39 @@ int IDAQuadInit(void *ida_mem, IDAQuadRhsFn rhsQ, N_Vector yQ0) * a negative value otherwise. */ -int IDAQuadReInit(void *ida_mem, N_Vector yQ0) +int IDAQuadReInit(void* ida_mem, N_Vector yQ0) { IDAMem IDA_mem; int retval; /* Check ida_mem */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadReInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Ckeck if quadrature was initialized */ - if (IDA_mem->ida_quadMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAQuadReInit", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUAD); } /* Initialize phiQ in the history array */ N_VScale(ONE, yQ0, IDA_mem->ida_phiQ[0]); - retval = N_VConstVectorArray(IDA_mem->ida_maxord, ZERO, IDA_mem->ida_phiQ+1); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VConstVectorArray(IDA_mem->ida_maxord, ZERO, IDA_mem->ida_phiQ + 1); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Initialize counters */ IDA_mem->ida_nrQe = 0; @@ -1050,10 +1142,10 @@ int IDAQuadReInit(void *ida_mem, N_Vector yQ0) IDA_mem->ida_quadr = SUNTRUE; /* Quadrature re-initialization was successfull */ - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - /* * IDAQuadSStolerances * IDAQuadSVtolerances @@ -1069,78 +1161,93 @@ int IDAQuadReInit(void *ida_mem, N_Vector yQ0) * absolute tolerance (a potentially different absolute tolerance * for each vector component). */ -int IDAQuadSStolerances(void *ida_mem, realtype reltolQ, realtype abstolQ) +int IDAQuadSStolerances(void* ida_mem, sunrealtype reltolQ, sunrealtype abstolQ) { IDAMem IDA_mem; /*Check ida mem*/ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSStolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Ckeck if quadrature was initialized */ - if (IDA_mem->ida_quadMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAQuadSStolerances", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQ < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSStolerances", MSG_BAD_RTOLQ); - return(IDA_ILL_INPUT); + if (reltolQ < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOLQ); + return (IDA_ILL_INPUT); } - if (abstolQ < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSStolerances", MSG_BAD_ATOLQ); - return(IDA_ILL_INPUT); + if (abstolQ < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOLQ); + return (IDA_ILL_INPUT); } /* Copy tolerances into memory */ IDA_mem->ida_itolQ = IDA_SS; - IDA_mem->ida_rtolQ = reltolQ; - IDA_mem->ida_SatolQ = abstolQ; + IDA_mem->ida_rtolQ = reltolQ; + IDA_mem->ida_SatolQ = abstolQ; IDA_mem->ida_atolQmin0 = (abstolQ == ZERO); - return (IDA_SUCCESS); } -int IDAQuadSVtolerances(void *ida_mem, realtype reltolQ, N_Vector abstolQ) +int IDAQuadSVtolerances(void* ida_mem, sunrealtype reltolQ, N_Vector abstolQ) { IDAMem IDA_mem; - realtype atolmin; + sunrealtype atolmin; /*Check ida mem*/ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSVtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Ckeck if quadrature was initialized */ - if (IDA_mem->ida_quadMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAQuadSVtolerances", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } /* Test user-supplied tolerances */ - if (reltolQ < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSVtolerances", MSG_BAD_RTOLQ); - return(IDA_ILL_INPUT); + if (reltolQ < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOLQ); + return (IDA_ILL_INPUT); } - if (abstolQ == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSVtolerances", MSG_NULL_ATOLQ); - return(IDA_ILL_INPUT); + if (abstolQ == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_ATOLQ); + return (IDA_ILL_INPUT); } atolmin = N_VMin(abstolQ); - if (atolmin < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSVtolerances", MSG_BAD_ATOLQ); - return(IDA_ILL_INPUT); + if (atolmin < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOLQ); + return (IDA_ILL_INPUT); } /* Copy tolerances into memory */ @@ -1148,7 +1255,8 @@ int IDAQuadSVtolerances(void *ida_mem, realtype reltolQ, N_Vector abstolQ) IDA_mem->ida_rtolQ = reltolQ; /* clone the absolute tolerances vector (if necessary) */ - if (SUNFALSE == IDA_mem->ida_VatolQMallocDone) { + if (SUNFALSE == IDA_mem->ida_VatolQMallocDone) + { IDA_mem->ida_VatolQ = N_VClone(abstolQ); IDA_mem->ida_lrw += IDA_mem->ida_lrw1Q; IDA_mem->ida_liw += IDA_mem->ida_liw1Q; @@ -1158,7 +1266,7 @@ int IDAQuadSVtolerances(void *ida_mem, realtype reltolQ, N_Vector abstolQ) N_VScale(ONE, abstolQ, IDA_mem->ida_VatolQ); IDA_mem->ida_atolQmin0 = (atolmin == ZERO); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1172,54 +1280,71 @@ int IDAQuadSVtolerances(void *ida_mem, realtype reltolQ, N_Vector abstolQ) * a negative value otherwise. */ -int IDASensInit(void *ida_mem, int Ns, int ism, - IDASensResFn fS, - N_Vector *yS0, N_Vector *ypS0) +int IDASensInit(void* ida_mem, int Ns, int ism, IDASensResFn fS, N_Vector* yS0, + N_Vector* ypS0) { IDAMem IDA_mem; - booleantype allocOK; + sunbooleantype allocOK; int is, retval; SUNNonlinearSolver NLS; /* Check ida_mem */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASensInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if Ns is legal */ - if (Ns<=0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensInit", MSG_BAD_NS); - return(IDA_ILL_INPUT); + if (Ns <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_NS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_Ns = Ns; /* Check if ism is legal */ - if ((ism!=IDA_SIMULTANEOUS) && (ism!=IDA_STAGGERED)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensInit", MSG_BAD_ISM); - return(IDA_ILL_INPUT); + if ((ism != IDA_SIMULTANEOUS) && (ism != IDA_STAGGERED)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ISM); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_ism = ism; /* Check if yS0 and ypS0 are non-null */ - if (yS0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensInit", MSG_NULL_YYS0); - return(IDA_ILL_INPUT); + if (yS0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YYS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (ypS0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensInit", MSG_NULL_YPS0); - return(IDA_ILL_INPUT); + if (ypS0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YPS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Store sensitivity RHS-related data */ - if (fS != NULL) { - IDA_mem->ida_resS = fS; - IDA_mem->ida_user_dataS = IDA_mem->ida_user_data; - IDA_mem->ida_resSDQ = SUNFALSE; - } else { + if (fS != NULL) + { + IDA_mem->ida_resS = fS; + IDA_mem->ida_user_dataS = IDA_mem->ida_user_data; + IDA_mem->ida_resSDQ = SUNFALSE; + } + else + { IDA_mem->ida_resS = IDASensResDQ; IDA_mem->ida_user_dataS = ida_mem; IDA_mem->ida_resSDQ = SUNTRUE; @@ -1228,27 +1353,37 @@ int IDASensInit(void *ida_mem, int Ns, int ism, /* Allocate the vectors (using yS0[0] as a template) */ allocOK = IDASensAllocVectors(IDA_mem, yS0[0]); - if (!allocOK) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDASensInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (!allocOK) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Allocate temporary work arrays for fused vector ops */ - if (Ns*MXORDP1 > MXORDP1) { - free(IDA_mem->ida_cvals); IDA_mem->ida_cvals = NULL; - free(IDA_mem->ida_Xvecs); IDA_mem->ida_Xvecs = NULL; - free(IDA_mem->ida_Zvecs); IDA_mem->ida_Zvecs = NULL; - - IDA_mem->ida_cvals = (realtype *) malloc((Ns*MXORDP1)*sizeof(realtype)); - IDA_mem->ida_Xvecs = (N_Vector *) malloc((Ns*MXORDP1)*sizeof(N_Vector)); - IDA_mem->ida_Zvecs = (N_Vector *) malloc((Ns*MXORDP1)*sizeof(N_Vector)); - - if ((IDA_mem->ida_cvals == NULL) || - (IDA_mem->ida_Xvecs == NULL) || - (IDA_mem->ida_Zvecs == NULL)) { + if (Ns * MXORDP1 > MXORDP1) + { + free(IDA_mem->ida_cvals); + IDA_mem->ida_cvals = NULL; + free(IDA_mem->ida_Xvecs); + IDA_mem->ida_Xvecs = NULL; + free(IDA_mem->ida_Zvecs); + IDA_mem->ida_Zvecs = NULL; + + IDA_mem->ida_cvals = + (sunrealtype*)malloc((Ns * MXORDP1) * sizeof(sunrealtype)); + IDA_mem->ida_Xvecs = (N_Vector*)malloc((Ns * MXORDP1) * sizeof(N_Vector)); + IDA_mem->ida_Zvecs = (N_Vector*)malloc((Ns * MXORDP1) * sizeof(N_Vector)); + + if ((IDA_mem->ida_cvals == NULL) || (IDA_mem->ida_Xvecs == NULL) || + (IDA_mem->ida_Zvecs == NULL)) + { IDASensFreeVectors(IDA_mem); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDASensInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } } @@ -1257,14 +1392,22 @@ int IDASensInit(void *ida_mem, int Ns, int ism, -----------------------------------------------*/ /* Initialize the phiS array */ - for (is=0; isida_cvals[is] = ONE; + for (is = 0; is < Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } retval = N_VScaleVectorArray(Ns, IDA_mem->ida_cvals, yS0, IDA_mem->ida_phiS[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - retval = N_VScaleVectorArray(Ns, IDA_mem->ida_cvals, ypS0, IDA_mem->ida_phiS[1]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(Ns, IDA_mem->ida_cvals, ypS0, + IDA_mem->ida_phiS[1]); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Initialize all sensitivity related counters */ IDA_mem->ida_nrSe = 0; @@ -1272,54 +1415,66 @@ int IDASensInit(void *ida_mem, int Ns, int ism, IDA_mem->ida_ncfnS = 0; IDA_mem->ida_netfS = 0; IDA_mem->ida_nniS = 0; + IDA_mem->ida_nnfS = 0; IDA_mem->ida_nsetupsS = 0; /* Set default values for plist and pbar */ - for (is=0; isida_plist[is] = is; - IDA_mem->ida_pbar[is] = ONE; + IDA_mem->ida_pbar[is] = ONE; } /* Sensitivities will be computed */ - IDA_mem->ida_sensi = SUNTRUE; + IDA_mem->ida_sensi = SUNTRUE; IDA_mem->ida_sensMallocDone = SUNTRUE; /* create a Newton nonlinear solver object by default */ if (ism == IDA_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(Ns+1, IDA_mem->ida_delta); + { + NLS = SUNNonlinSol_NewtonSens(Ns + 1, IDA_mem->ida_delta, + IDA_mem->ida_sunctx); + } else - NLS = SUNNonlinSol_NewtonSens(Ns, IDA_mem->ida_delta); + { + NLS = SUNNonlinSol_NewtonSens(Ns, IDA_mem->ida_delta, IDA_mem->ida_sunctx); + } /* check that the nonlinear solver is non-NULL */ - if (NLS == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDASensInit", MSG_MEM_FAIL); + if (NLS == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); IDASensFreeVectors(IDA_mem); - return(IDA_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* attach the nonlinear solver to the IDA memory */ if (ism == IDA_SIMULTANEOUS) + { retval = IDASetNonlinearSolverSensSim(IDA_mem, NLS); - else - retval = IDASetNonlinearSolverSensStg(IDA_mem, NLS); + } + else { retval = IDASetNonlinearSolverSensStg(IDA_mem, NLS); } /* check that the nonlinear solver was successfully attached */ - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, retval, "IDAS", "IDASensInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); IDASensFreeVectors(IDA_mem); SUNNonlinSolFree(NLS); - return(IDA_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* set ownership flag */ - if (ism == IDA_SIMULTANEOUS) - IDA_mem->ownNLSsim = SUNTRUE; - else - IDA_mem->ownNLSstg = SUNTRUE; + if (ism == IDA_SIMULTANEOUS) { IDA_mem->ownNLSsim = SUNTRUE; } + else { IDA_mem->ownNLSstg = SUNTRUE; } /* Sensitivity initialization was successfull */ - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1339,45 +1494,55 @@ int IDASensInit(void *ida_mem, int Ns, int ism, * a negative value otherwise. */ -int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, N_Vector *ypS0) +int IDASensReInit(void* ida_mem, int ism, N_Vector* yS0, N_Vector* ypS0) { IDAMem IDA_mem; int is, retval; SUNNonlinearSolver NLS; /* Check ida_mem */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASensReInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", - "IDASensReInit", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } /* Check if ism is legal */ - if ((ism!=IDA_SIMULTANEOUS) && (ism!=IDA_STAGGERED)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASensReInit", MSG_BAD_ISM); - return(IDA_ILL_INPUT); + if ((ism != IDA_SIMULTANEOUS) && (ism != IDA_STAGGERED)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ISM); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_ism = ism; /* Check if yS0 and ypS0 are non-null */ - if (yS0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASensReInit", MSG_NULL_YYS0); - return(IDA_ILL_INPUT); + if (yS0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YYS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (ypS0 == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASensReInit", MSG_NULL_YPS0); - return(IDA_ILL_INPUT); + if (ypS0 == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YPS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /*----------------------------------------------- @@ -1385,16 +1550,23 @@ int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, N_Vector *ypS0) -----------------------------------------------*/ /* Initialize the phiS array */ - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - yS0, IDA_mem->ida_phiS[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, yS0, + IDA_mem->ida_phiS[0]); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - ypS0, IDA_mem->ida_phiS[1]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, ypS0, + IDA_mem->ida_phiS[1]); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Initialize all sensitivity related counters */ IDA_mem->ida_nrSe = 0; @@ -1402,12 +1574,14 @@ int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, N_Vector *ypS0) IDA_mem->ida_ncfnS = 0; IDA_mem->ida_netfS = 0; IDA_mem->ida_nniS = 0; + IDA_mem->ida_nnfS = 0; IDA_mem->ida_nsetupsS = 0; /* Set default values for plist and pbar */ - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_plist[is] = is; - IDA_mem->ida_pbar[is] = ONE; + IDA_mem->ida_pbar[is] = ONE; } /* Sensitivities will be computed */ @@ -1415,57 +1589,67 @@ int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, N_Vector *ypS0) /* Check if the NLS exists, create the default NLS if needed */ if ((ism == IDA_SIMULTANEOUS && IDA_mem->NLSsim == NULL) || - (ism == IDA_STAGGERED && IDA_mem->NLSstg == NULL)) { - + (ism == IDA_STAGGERED && IDA_mem->NLSstg == NULL)) + { /* create a Newton nonlinear solver object by default */ if (ism == IDA_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(IDA_mem->ida_Ns+1, IDA_mem->ida_delta); + { + NLS = SUNNonlinSol_NewtonSens(IDA_mem->ida_Ns + 1, IDA_mem->ida_delta, + IDA_mem->ida_sunctx); + } else - NLS = SUNNonlinSol_NewtonSens(IDA_mem->ida_Ns, IDA_mem->ida_delta); + { + NLS = SUNNonlinSol_NewtonSens(IDA_mem->ida_Ns, IDA_mem->ida_delta, + IDA_mem->ida_sunctx); + } /* check that the nonlinear solver is non-NULL */ - if (NLS == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASensReInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (NLS == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* attach the nonlinear solver to the IDA memory */ if (ism == IDA_SIMULTANEOUS) + { retval = IDASetNonlinearSolverSensSim(IDA_mem, NLS); - else - retval = IDASetNonlinearSolverSensStg(IDA_mem, NLS); + } + else { retval = IDASetNonlinearSolverSensStg(IDA_mem, NLS); } /* check that the nonlinear solver was successfully attached */ - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, retval, "IDAS", "IDASensReInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, "Setting the nonlinear solver failed"); SUNNonlinSolFree(NLS); - return(IDA_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* set ownership flag */ - if (ism == IDA_SIMULTANEOUS) - IDA_mem->ownNLSsim = SUNTRUE; - else - IDA_mem->ownNLSstg = SUNTRUE; + if (ism == IDA_SIMULTANEOUS) { IDA_mem->ownNLSsim = SUNTRUE; } + else { IDA_mem->ownNLSstg = SUNTRUE; } /* initialize the NLS object, this assumes that the linear solver has already been initialized in IDAInit */ - if (ism == IDA_SIMULTANEOUS) - retval = idaNlsInitSensSim(IDA_mem); - else - retval = idaNlsInitSensStg(IDA_mem); + if (ism == IDA_SIMULTANEOUS) { retval = idaNlsInitSensSim(IDA_mem); } + else { retval = idaNlsInitSensStg(IDA_mem); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, "IDAS", - "IDASensReInit", MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, + MSG_NLS_INIT_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NLS_INIT_FAIL); } } /* Sensitivity re-initialization was successfull */ - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ @@ -1486,43 +1670,53 @@ int IDASensReInit(void *ida_mem, int ism, N_Vector *yS0, N_Vector *ypS0) * should be estimated from those provided for the state variables. */ - -int IDASensSStolerances(void *ida_mem, realtype reltolS, realtype *abstolS) +int IDASensSStolerances(void* ida_mem, sunrealtype reltolS, sunrealtype* abstolS) { IDAMem IDA_mem; int is; /* Check ida_mem pointer */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASensSStolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDASensSStolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Test user-supplied tolerances */ - if (reltolS < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSStolerances", MSG_BAD_RTOLS); - return(IDA_ILL_INPUT); + if (reltolS < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOLS); + return (IDA_ILL_INPUT); } - if (abstolS == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSStolerances", MSG_NULL_ATOLS); - return(IDA_ILL_INPUT); + if (abstolS == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_ATOLS); + return (IDA_ILL_INPUT); } - for (is=0; isida_Ns; is++) - if (abstolS[is] < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSStolerances", MSG_BAD_ATOLS); - return(IDA_ILL_INPUT); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + if (abstolS[is] < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOLS); + return (IDA_ILL_INPUT); } + } /* Copy tolerances into memory */ @@ -1530,163 +1724,200 @@ int IDASensSStolerances(void *ida_mem, realtype reltolS, realtype *abstolS) IDA_mem->ida_rtolS = reltolS; - if ( !(IDA_mem->ida_SatolSMallocDone) ) { + if (!(IDA_mem->ida_SatolSMallocDone)) + { IDA_mem->ida_SatolS = NULL; - IDA_mem->ida_SatolS = (realtype *)malloc(IDA_mem->ida_Ns*sizeof(realtype)); - IDA_mem->ida_atolSmin0 = (booleantype *)malloc(IDA_mem->ida_Ns*sizeof(booleantype)); + IDA_mem->ida_SatolS = + (sunrealtype*)malloc(IDA_mem->ida_Ns * sizeof(sunrealtype)); + IDA_mem->ida_atolSmin0 = + (sunbooleantype*)malloc(IDA_mem->ida_Ns * sizeof(sunbooleantype)); IDA_mem->ida_lrw += IDA_mem->ida_Ns; IDA_mem->ida_SatolSMallocDone = SUNTRUE; } - for (is=0; isida_Ns; is++) { - IDA_mem->ida_SatolS[is] = abstolS[is]; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_SatolS[is] = abstolS[is]; IDA_mem->ida_atolSmin0[is] = (abstolS[is] == ZERO); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -int IDASensSVtolerances(void *ida_mem, realtype reltolS, N_Vector *abstolS) +int IDASensSVtolerances(void* ida_mem, sunrealtype reltolS, N_Vector* abstolS) { IDAMem IDA_mem; int is, retval; - realtype *atolmin; + sunrealtype* atolmin; /* Check ida_mem pointer */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASensSVtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDASensSVtolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Test user-supplied tolerances */ - if (reltolS < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSVtolerances", MSG_BAD_RTOLS); - return(IDA_ILL_INPUT); + if (reltolS < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RTOLS); + return (IDA_ILL_INPUT); } - if (abstolS == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSVtolerances", MSG_NULL_ATOLS); - return(IDA_ILL_INPUT); + if (abstolS == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_ATOLS); + return (IDA_ILL_INPUT); } - atolmin = (realtype *)malloc(IDA_mem->ida_Ns*sizeof(realtype)); - for (is=0; isida_Ns; is++) { + atolmin = (sunrealtype*)malloc(IDA_mem->ida_Ns * sizeof(sunrealtype)); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { atolmin[is] = N_VMin(abstolS[is]); - if (atolmin[is] < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASensSStolerances", MSG_BAD_ATOLS); + if (atolmin[is] < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ATOLS); free(atolmin); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } IDA_mem->ida_itolS = IDA_SV; - IDA_mem->ida_rtolS = reltolS ; + IDA_mem->ida_rtolS = reltolS; - if ( SUNFALSE == IDA_mem->ida_VatolSMallocDone ) { - IDA_mem->ida_VatolS = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_tempv1); - IDA_mem->ida_atolSmin0 = (booleantype *)malloc(IDA_mem->ida_Ns*sizeof(booleantype)); - IDA_mem->ida_lrw += IDA_mem->ida_Ns*IDA_mem->ida_lrw1; - IDA_mem->ida_liw += IDA_mem->ida_Ns*IDA_mem->ida_liw1; + if (SUNFALSE == IDA_mem->ida_VatolSMallocDone) + { + IDA_mem->ida_VatolS = N_VCloneVectorArray(IDA_mem->ida_Ns, + IDA_mem->ida_tempv1); + IDA_mem->ida_atolSmin0 = + (sunbooleantype*)malloc(IDA_mem->ida_Ns * sizeof(sunbooleantype)); + IDA_mem->ida_lrw += IDA_mem->ida_Ns * IDA_mem->ida_lrw1; + IDA_mem->ida_liw += IDA_mem->ida_Ns * IDA_mem->ida_liw1; IDA_mem->ida_VatolSMallocDone = SUNTRUE; } - for (is=0; isida_Ns; is++) { - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_cvals[is] = ONE; IDA_mem->ida_atolSmin0[is] = (atolmin[is] == ZERO); } free(atolmin); - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - abstolS, IDA_mem->ida_VatolS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, abstolS, + IDA_mem->ida_VatolS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } -int IDASensEEtolerances(void *ida_mem) +int IDASensEEtolerances(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASensEEtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDASensEEtolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } IDA_mem->ida_itolS = IDA_EE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -int IDAQuadSensInit(void *ida_mem, IDAQuadSensRhsFn rhsQS, N_Vector *yQS0) +int IDAQuadSensInit(void* ida_mem, IDAQuadSensRhsFn rhsQS, N_Vector* yQS0) { IDAMem IDA_mem; - booleantype allocOK; + sunbooleantype allocOK; int is, retval; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSensInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if sensitivity analysis is active */ - if (!IDA_mem->ida_sensi) { - IDAProcessError(NULL, IDA_NO_SENS, "IDAS", "IDAQuadSensInit", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (!IDA_mem->ida_sensi) + { + IDAProcessError(NULL, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } /* Verifiy yQS0 parameter. */ - if (yQS0==NULL) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", "IDAQuadSensInit", MSG_NULL_YQS0); - return(IDA_ILL_INPUT); + if (yQS0 == NULL) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YQS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Allocate vector needed for quadratures' sensitivities. */ allocOK = IDAQuadSensAllocVectors(IDA_mem, yQS0[0]); - if (!allocOK) { - IDAProcessError(NULL, IDA_MEM_FAIL, "IDAS", "IDAQuadSensInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (!allocOK) + { + IDAProcessError(NULL, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Error checking complete. */ - if (rhsQS == NULL) { + if (rhsQS == NULL) + { IDA_mem->ida_rhsQSDQ = SUNTRUE; - IDA_mem->ida_rhsQS = IDAQuadSensRhsInternalDQ; + IDA_mem->ida_rhsQS = IDAQuadSensRhsInternalDQ; IDA_mem->ida_user_dataQS = ida_mem; - } else { + } + else + { IDA_mem->ida_rhsQSDQ = SUNFALSE; - IDA_mem->ida_rhsQS = rhsQS; + IDA_mem->ida_rhsQS = rhsQS; IDA_mem->ida_user_dataQS = IDA_mem->ida_user_data; } /* Initialize phiQS[0] in the history array */ - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - yQS0, IDA_mem->ida_phiQS[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, yQS0, + IDA_mem->ida_phiQS[0]); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Initialize all sensitivities related counters. */ IDA_mem->ida_nrQSe = 0; @@ -1694,50 +1925,66 @@ int IDAQuadSensInit(void *ida_mem, IDAQuadSensRhsFn rhsQS, N_Vector *yQS0) IDA_mem->ida_netfQS = 0; /* Everything allright, set the flags and return with success. */ - IDA_mem->ida_quadr_sensi = SUNTRUE; + IDA_mem->ida_quadr_sensi = SUNTRUE; IDA_mem->ida_quadSensMallocDone = SUNTRUE; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } -int IDAQuadSensReInit(void *ida_mem, N_Vector *yQS0) +int IDAQuadSensReInit(void* ida_mem, N_Vector* yQS0) { IDAMem IDA_mem; int is, retval; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSensReInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if sensitivity analysis is active */ - if (!IDA_mem->ida_sensi) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAQuadSensReInit", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (!IDA_mem->ida_sensi) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } /* Was sensitivity for quadrature already initialized? */ - if (!IDA_mem->ida_quadSensMallocDone) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAQuadSensReInit", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (!IDA_mem->ida_quadSensMallocDone) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUADSENS); } /* Verifiy yQS0 parameter. */ - if (yQS0==NULL) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", "IDAQuadSensReInit", MSG_NULL_YQS0); - return(IDA_ILL_INPUT); + if (yQS0 == NULL) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_YQS0); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Error checking complete at this point. */ /* Initialize phiQS[0] in the history array */ - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - yQS0, IDA_mem->ida_phiQS[0]); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, yQS0, + IDA_mem->ida_phiQS[0]); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } /* Initialize all sensitivities related counters. */ IDA_mem->ida_nrQSe = 0; @@ -1747,7 +1994,8 @@ int IDAQuadSensReInit(void *ida_mem, N_Vector *yQS0) /* Everything allright, set the flags and return with success. */ IDA_mem->ida_quadr_sensi = SUNTRUE; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -1769,109 +2017,140 @@ int IDAQuadSensReInit(void *ida_mem, N_Vector *yQS0) * specified through a call to one of IDAQuad**tolerances. */ -int IDAQuadSensSStolerances(void *ida_mem, realtype reltolQS, realtype *abstolQS) +int IDAQuadSensSStolerances(void* ida_mem, sunrealtype reltolQS, + sunrealtype* abstolQS) { IDAMem IDA_mem; int is; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSensSStolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Check if sensitivity analysis is active */ - if (!IDA_mem->ida_sensi) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAQuadSensSStolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (!IDA_mem->ida_sensi) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Was sensitivity for quadrature already initialized? */ - if (!IDA_mem->ida_quadSensMallocDone) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAQuadSensSStolerances", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (!IDA_mem->ida_quadSensMallocDone) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } /* Test user-supplied tolerances */ - if (reltolQS < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSStolerances", MSG_BAD_RELTOLQS); - return(IDA_ILL_INPUT); + if (reltolQS < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RELTOLQS); + return (IDA_ILL_INPUT); } - if (abstolQS == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSStolerances", MSG_NULL_ABSTOLQS); - return(IDA_ILL_INPUT); + if (abstolQS == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_ABSTOLQS); + return (IDA_ILL_INPUT); } - for (is=0; isida_Ns; is++) - if (abstolQS[is] < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSStolerances", MSG_BAD_ABSTOLQS); - return(IDA_ILL_INPUT); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + if (abstolQS[is] < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ABSTOLQS); + return (IDA_ILL_INPUT); } + } /* Save data. */ IDA_mem->ida_itolQS = IDA_SS; IDA_mem->ida_rtolQS = reltolQS; - if ( !(IDA_mem->ida_SatolQSMallocDone) ) { - IDA_mem->ida_SatolQS = (realtype *)malloc(IDA_mem->ida_Ns*sizeof(realtype)); - IDA_mem->ida_atolQSmin0 = (booleantype *)malloc(IDA_mem->ida_Ns*sizeof(booleantype)); + if (!(IDA_mem->ida_SatolQSMallocDone)) + { + IDA_mem->ida_SatolQS = + (sunrealtype*)malloc(IDA_mem->ida_Ns * sizeof(sunrealtype)); + IDA_mem->ida_atolQSmin0 = + (sunbooleantype*)malloc(IDA_mem->ida_Ns * sizeof(sunbooleantype)); IDA_mem->ida_lrw += IDA_mem->ida_Ns; IDA_mem->ida_SatolQSMallocDone = SUNTRUE; } - for (is=0; isida_Ns; is++) { - IDA_mem->ida_SatolQS[is] = abstolQS[is]; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_SatolQS[is] = abstolQS[is]; IDA_mem->ida_atolQSmin0[is] = (abstolQS[is] == ZERO); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } -int IDAQuadSensSVtolerances(void *ida_mem, realtype reltolQS, N_Vector *abstolQS) +int IDAQuadSensSVtolerances(void* ida_mem, sunrealtype reltolQS, + N_Vector* abstolQS) { IDAMem IDA_mem; int is, retval; - realtype *atolmin; + sunrealtype* atolmin; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSensSVtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Check if sensitivity analysis is active */ - if (!IDA_mem->ida_sensi) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAQuadSensSVtolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (!IDA_mem->ida_sensi) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Was sensitivity for quadrature already initialized? */ - if (!IDA_mem->ida_quadSensMallocDone) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAQuadSensSVtolerances", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (!IDA_mem->ida_quadSensMallocDone) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } /* Test user-supplied tolerances */ - if (reltolQS < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSVtolerances", MSG_BAD_RELTOLQS); - return(IDA_ILL_INPUT); + if (reltolQS < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_RELTOLQS); + return (IDA_ILL_INPUT); } - if (abstolQS == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSVtolerances", MSG_NULL_ABSTOLQS); - return(IDA_ILL_INPUT); + if (abstolQS == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_ABSTOLQS); + return (IDA_ILL_INPUT); } - atolmin = (realtype *)malloc(IDA_mem->ida_Ns*sizeof(realtype)); - for (is=0; isida_Ns; is++) { + atolmin = (sunrealtype*)malloc(IDA_mem->ida_Ns * sizeof(sunrealtype)); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { atolmin[is] = N_VMin(abstolQS[is]); - if (atolmin[is] < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAQuadSensSVtolerances", MSG_BAD_ABSTOLQS); + if (atolmin[is] < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ABSTOLQS); free(atolmin); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } @@ -1879,52 +2158,60 @@ int IDAQuadSensSVtolerances(void *ida_mem, realtype reltolQS, N_Vector *abstolQS IDA_mem->ida_itolQS = IDA_SV; IDA_mem->ida_rtolQS = reltolQS; - if ( !(IDA_mem->ida_VatolQSMallocDone) ) { + if (!(IDA_mem->ida_VatolQSMallocDone)) + { IDA_mem->ida_VatolQS = N_VCloneVectorArray(IDA_mem->ida_Ns, abstolQS[0]); - IDA_mem->ida_atolQSmin0 = (booleantype *)malloc(IDA_mem->ida_Ns*sizeof(booleantype)); - IDA_mem->ida_lrw += IDA_mem->ida_Ns*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw += IDA_mem->ida_Ns*IDA_mem->ida_liw1Q; + IDA_mem->ida_atolQSmin0 = + (sunbooleantype*)malloc(IDA_mem->ida_Ns * sizeof(sunbooleantype)); + IDA_mem->ida_lrw += IDA_mem->ida_Ns * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw += IDA_mem->ida_Ns * IDA_mem->ida_liw1Q; IDA_mem->ida_VatolQSMallocDone = SUNTRUE; } - for (is=0; isida_Ns; is++) { - IDA_mem->ida_cvals[is] = ONE; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_cvals[is] = ONE; IDA_mem->ida_atolQSmin0[is] = (atolmin[is] == ZERO); } free(atolmin); - retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - abstolQS, IDA_mem->ida_VatolQS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, abstolQS, + IDA_mem->ida_VatolQS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } -int IDAQuadSensEEtolerances(void *ida_mem) +int IDAQuadSensEEtolerances(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAQuadSensEEtolerances", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Check if sensitivity analysis is active */ - if (!IDA_mem->ida_sensi) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAQuadSensEEtolerances", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (!IDA_mem->ida_sensi) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Was sensitivity for quadrature already initialized? */ - if (!IDA_mem->ida_quadSensMallocDone) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAQuadSensEEtolerances", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (!IDA_mem->ida_quadSensMallocDone) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } IDA_mem->ida_itolQS = IDA_EE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1933,23 +2220,23 @@ int IDAQuadSensEEtolerances(void *ida_mem) * IDASensToggleOff deactivates sensitivity calculations. * It does NOT deallocate sensitivity-related memory. */ -int IDASensToggleOff(void *ida_mem) +int IDASensToggleOff(void* ida_mem) { IDAMem IDA_mem; /* Check ida_mem */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASensToggleOff", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Disable sensitivities */ - IDA_mem->ida_sensi = SUNFALSE; + IDA_mem->ida_sensi = SUNFALSE; IDA_mem->ida_quadr_sensi = SUNFALSE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1962,43 +2249,53 @@ int IDASensToggleOff(void *ida_mem) * errors occurred, or a negative value otherwise. */ -int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) +int IDARootInit(void* ida_mem, int nrtfn, IDARootFn g) { IDAMem IDA_mem; int i, nrt; /* Check ida_mem pointer */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDARootInit", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); nrt = (nrtfn < 0) ? 0 : nrtfn; /* If rerunning IDARootInit() with a different number of root functions (changing number of gfun components), then free currently held memory resources */ - if ((nrt != IDA_mem->ida_nrtfn) && (IDA_mem->ida_nrtfn > 0)) { - - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; - free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; - free(IDA_mem->ida_gactive); IDA_mem->ida_gactive = NULL; + if ((nrt != IDA_mem->ida_nrtfn) && (IDA_mem->ida_nrtfn > 0)) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); + IDA_mem->ida_iroots = NULL; + free(IDA_mem->ida_rootdir); + IDA_mem->ida_rootdir = NULL; + free(IDA_mem->ida_gactive); + IDA_mem->ida_gactive = NULL; IDA_mem->ida_lrw -= 3 * (IDA_mem->ida_nrtfn); IDA_mem->ida_liw -= 3 * (IDA_mem->ida_nrtfn); - } /* If IDARootInit() was called with nrtfn == 0, then set ida_nrtfn to zero and ida_gfun to NULL before returning */ - if (nrt == 0) { + if (nrt == 0) + { IDA_mem->ida_nrtfn = nrt; - IDA_mem->ida_gfun = NULL; - return(IDA_SUCCESS); + IDA_mem->ida_gfun = NULL; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* If rerunning IDARootInit() with the same number of root functions @@ -2006,109 +2303,162 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) function argument has changed */ /* If g != NULL then return as currently reserved memory resources will suffice */ - if (nrt == IDA_mem->ida_nrtfn) { - if (g != IDA_mem->ida_gfun) { - if (g == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; - free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; - free(IDA_mem->ida_gactive); IDA_mem->ida_gactive = NULL; - - IDA_mem->ida_lrw -= 3*nrt; - IDA_mem->ida_liw -= 3*nrt; - - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDARootInit", MSG_ROOT_FUNC_NULL); - return(IDA_ILL_INPUT); + if (nrt == IDA_mem->ida_nrtfn) + { + if (g != IDA_mem->ida_gfun) + { + if (g == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); + IDA_mem->ida_iroots = NULL; + free(IDA_mem->ida_rootdir); + IDA_mem->ida_rootdir = NULL; + free(IDA_mem->ida_gactive); + IDA_mem->ida_gactive = NULL; + + IDA_mem->ida_lrw -= 3 * nrt; + IDA_mem->ida_liw -= 3 * nrt; + + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_ROOT_FUNC_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - else { + else + { IDA_mem->ida_gfun = g; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } } - else return(IDA_SUCCESS); + else + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); + } } /* Set variable values in IDA memory block */ IDA_mem->ida_nrtfn = nrt; - if (g == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDARootInit", MSG_ROOT_FUNC_NULL); - return(IDA_ILL_INPUT); + if (g == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_ROOT_FUNC_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - else IDA_mem->ida_gfun = g; + else { IDA_mem->ida_gfun = g; } /* Allocate necessary memory and return */ IDA_mem->ida_glo = NULL; - IDA_mem->ida_glo = (realtype *) malloc(nrt*sizeof(realtype)); - if (IDA_mem->ida_glo == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_glo = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (IDA_mem->ida_glo == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } IDA_mem->ida_ghi = NULL; - IDA_mem->ida_ghi = (realtype *) malloc(nrt*sizeof(realtype)); - if (IDA_mem->ida_ghi == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_ghi = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (IDA_mem->ida_ghi == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } IDA_mem->ida_grout = NULL; - IDA_mem->ida_grout = (realtype *) malloc(nrt*sizeof(realtype)); - if (IDA_mem->ida_grout == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_grout = (sunrealtype*)malloc(nrt * sizeof(sunrealtype)); + if (IDA_mem->ida_grout == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } IDA_mem->ida_iroots = NULL; - IDA_mem->ida_iroots = (int *) malloc(nrt*sizeof(int)); - if (IDA_mem->ida_iroots == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_iroots = (int*)malloc(nrt * sizeof(int)); + if (IDA_mem->ida_iroots == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } IDA_mem->ida_rootdir = NULL; - IDA_mem->ida_rootdir = (int *) malloc(nrt*sizeof(int)); - if (IDA_mem->ida_rootdir == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_rootdir = (int*)malloc(nrt * sizeof(int)); + if (IDA_mem->ida_rootdir == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); + IDA_mem->ida_iroots = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } IDA_mem->ida_gactive = NULL; - IDA_mem->ida_gactive = (booleantype *) malloc(nrt*sizeof(booleantype)); - if (IDA_mem->ida_gactive == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; - free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDA_mem->ida_gactive = (sunbooleantype*)malloc(nrt * sizeof(sunbooleantype)); + if (IDA_mem->ida_gactive == NULL) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); + IDA_mem->ida_iroots = NULL; + free(IDA_mem->ida_rootdir); + IDA_mem->ida_rootdir = NULL; + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_MEM_FAIL); } /* Set default values for rootdir (both directions) */ - for(i=0; iida_rootdir[i] = 0; + for (i = 0; i < nrt; i++) { IDA_mem->ida_rootdir[i] = 0; } /* Set default values for gactive (all active) */ - for(i=0; iida_gactive[i] = SUNTRUE; + for (i = 0; i < nrt; i++) { IDA_mem->ida_gactive[i] = SUNTRUE; } - IDA_mem->ida_lrw += 3*nrt; - IDA_mem->ida_liw += 3*nrt; + IDA_mem->ida_lrw += 3 * nrt; + IDA_mem->ida_liw += 3 * nrt; - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - /* * ----------------------------------------------------------------- * Main solver function @@ -2153,84 +2503,116 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) * IDA_RES_FAIL */ -int IDASolve(void *ida_mem, realtype tout, realtype *tret, - N_Vector yret, N_Vector ypret, int itask) +int IDASolve(void* ida_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, + N_Vector ypret, int itask) { long int nstloc; int sflag, istate, ier, irfndp, ir, is; - realtype tdist, troundoff, ypnorm, rh, nrm; + sunrealtype tdist, troundoff, ypnorm, rh, nrm; IDAMem IDA_mem; - booleantype inactive_roots; + sunbooleantype inactive_roots; /* Check for legal inputs in all cases. */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASolve", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if problem was malloc'ed */ - if (IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDASolve", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_MALLOC); } /* Check for legal arguments */ - if (yret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_YRET_NULL); - return(IDA_ILL_INPUT); + if (yret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_yy = yret; - if (ypret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_YPRET_NULL); - return(IDA_ILL_INPUT); + if (ypret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_YPRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_yp = ypret; - if (tret == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_TRET_NULL); - return(IDA_ILL_INPUT); + if (tret == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if ((itask != IDA_NORMAL) && (itask != IDA_ONE_STEP)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_BAD_ITASK); - return(IDA_ILL_INPUT); + if ((itask != IDA_NORMAL) && (itask != IDA_ONE_STEP)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (itask == IDA_NORMAL) IDA_mem->ida_toutc = tout; + if (itask == IDA_NORMAL) { IDA_mem->ida_toutc = tout; } IDA_mem->ida_taskc = itask; /* Sensitivity-specific tests (if using internal DQ functions) */ - if (IDA_mem->ida_sensi && IDA_mem->ida_resSDQ) { + if (IDA_mem->ida_sensi && IDA_mem->ida_resSDQ) + { /* Make sure we have the right 'user data' */ IDA_mem->ida_user_dataS = ida_mem; /* Test if we have the problem parameters */ - if(IDA_mem->ida_p == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_NULL_P); - return(IDA_ILL_INPUT); + if (IDA_mem->ida_p == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_P); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } } - if (IDA_mem->ida_quadr_sensi && IDA_mem->ida_rhsQSDQ) { + if (IDA_mem->ida_quadr_sensi && IDA_mem->ida_rhsQSDQ) + { IDA_mem->ida_user_dataQS = ida_mem; /* Test if we have the problem parameters */ - if(IDA_mem->ida_p == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_NULL_P); - return(IDA_ILL_INPUT); + if (IDA_mem->ida_p == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NULL_P); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } } - if (IDA_mem->ida_nst == 0) { /* This is the first call */ + if (IDA_mem->ida_nst == 0) + { /* This is the first call */ /* Check inputs to IDA for correctness and consistency */ - if (IDA_mem->ida_SetupDone == SUNFALSE) { + if (IDA_mem->ida_SetupDone == SUNFALSE) + { ier = IDAInitialSetup(IDA_mem); - if (ier != IDA_SUCCESS) return(ier); + if (ier != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (ier); + } IDA_mem->ida_SetupDone = SUNTRUE; } @@ -2239,64 +2621,104 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, Also check for zeros of root function g at and near t0. */ tdist = SUNRabs(tout - IDA_mem->ida_tn); - if (tdist == ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_TOO_CLOSE); - return(IDA_ILL_INPUT); + if (tdist == ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - troundoff = TWO * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout)); - if (tdist < troundoff) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_TOO_CLOSE); - return(IDA_ILL_INPUT); + troundoff = TWO * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout)); + if (tdist < troundoff) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } + /* Set initial h */ + IDA_mem->ida_hh = IDA_mem->ida_hin; - if ( (IDA_mem->ida_hh != ZERO) && ((tout-IDA_mem->ida_tn)*IDA_mem->ida_hh < ZERO) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", MSG_BAD_HINIT); - return(IDA_ILL_INPUT); + if ((IDA_mem->ida_hh != ZERO) && + ((tout - IDA_mem->ida_tn) * IDA_mem->ida_hh < ZERO)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_HINIT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if (IDA_mem->ida_hh == ZERO) { - IDA_mem->ida_hh = PT001*tdist; - ypnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_phi[1], - IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); + if (IDA_mem->ida_hh == ZERO) + { + IDA_mem->ida_hh = PT001 * tdist; + ypnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_phi[1], IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); if (IDA_mem->ida_errconQ) - ypnorm = IDAQuadWrmsNormUpdate(IDA_mem, ypnorm, - IDA_mem->ida_phiQ[1], IDA_mem->ida_ewtQ); + { + ypnorm = IDAQuadWrmsNormUpdate(IDA_mem, ypnorm, IDA_mem->ida_phiQ[1], + IDA_mem->ida_ewtQ); + } if (IDA_mem->ida_errconS) + { ypnorm = IDASensWrmsNormUpdate(IDA_mem, ypnorm, IDA_mem->ida_phiS[1], - IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); + IDA_mem->ida_ewtS, + IDA_mem->ida_suppressalg); + } if (IDA_mem->ida_errconQS) + { ypnorm = IDAQuadSensWrmsNormUpdate(IDA_mem, ypnorm, IDA_mem->ida_phiQS[1], IDA_mem->ida_ewtQS); + } - if (ypnorm > HALF / IDA_mem->ida_hh) IDA_mem->ida_hh = HALF/ypnorm; - if (tout < IDA_mem->ida_tn) IDA_mem->ida_hh = -IDA_mem->ida_hh; + if (ypnorm > HALF / IDA_mem->ida_hh) { IDA_mem->ida_hh = HALF / ypnorm; } + if (tout < IDA_mem->ida_tn) { IDA_mem->ida_hh = -IDA_mem->ida_hh; } } + /* Enforce hmax and hmin */ + rh = SUNRabs(IDA_mem->ida_hh) * IDA_mem->ida_hmax_inv; - if (rh > ONE) IDA_mem->ida_hh /= rh; + if (rh > ONE) { IDA_mem->ida_hh /= rh; } + if (SUNRabs(IDA_mem->ida_hh) < IDA_mem->ida_hmin) + { + IDA_mem->ida_hh *= IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh); + } + + /* Check for approach to tstop */ - if (IDA_mem->ida_tstopset) { - if ( (IDA_mem->ida_tstop - IDA_mem->ida_tn)*IDA_mem->ida_hh <= ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + if (IDA_mem->ida_tstopset) + { + if ((IDA_mem->ida_tstop - IDA_mem->ida_tn) * IDA_mem->ida_hh <= ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); + } + if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop) * + IDA_mem->ida_hh > + ZERO) + { + IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn) * + (ONE - FOUR * IDA_mem->ida_uround); } - if ( (IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) - IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn)*(ONE - FOUR * IDA_mem->ida_uround); } - IDA_mem->ida_h0u = IDA_mem->ida_hh; - IDA_mem->ida_kk = 0; - IDA_mem->ida_kused = 0; /* set in case of an error return before a step */ + IDA_mem->ida_h0u = IDA_mem->ida_hh; + IDA_mem->ida_kk = 0; + IDA_mem->ida_kused = 0; /* set in case of an error return before a step */ /* Check for exact zeros of the root functions at or near t0. */ - if (IDA_mem->ida_nrtfn > 0) { + if (IDA_mem->ida_nrtfn > 0) + { ier = IDARcheck1(IDA_mem); - if (ier == IDA_RTFUNC_FAIL) { - IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDAS", "IDARcheck1", + if (ier == IDA_RTFUNC_FAIL) + { + IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_RTFUNC_FAILED, IDA_mem->ida_tn); - return(IDA_RTFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_RTFUNC_FAIL); } } @@ -2305,104 +2727,142 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, /* set phiQ[1] = hh*yQ' */ if (IDA_mem->ida_quadr) + { N_VScale(IDA_mem->ida_hh, IDA_mem->ida_phiQ[1], IDA_mem->ida_phiQ[1]); + } if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) - for (is=0; isida_Ns; is++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_cvals[is] = IDA_mem->ida_hh; + } + } - if (IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { /* set phiS[1][i] = hh*yS_i' */ ier = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, IDA_mem->ida_phiS[1], IDA_mem->ida_phiS[1]); - if (ier != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (ier != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } } - if (IDA_mem->ida_quadr_sensi) { + if (IDA_mem->ida_quadr_sensi) + { ier = N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, IDA_mem->ida_phiQS[1], IDA_mem->ida_phiQS[1]); - if (ier != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (ier != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } } /* Set the convergence test constants epsNewt and toldel */ IDA_mem->ida_epsNewt = IDA_mem->ida_epcon; - IDA_mem->ida_toldel = PT0001 * IDA_mem->ida_epsNewt; + IDA_mem->ida_toldel = PT0001 * IDA_mem->ida_epsNewt; } /* end of first-call block. */ /* Call lperf function and set nstloc for later performance testing. */ - if (IDA_mem->ida_lperf != NULL) - IDA_mem->ida_lperf(IDA_mem, 0); + if (IDA_mem->ida_lperf != NULL) { IDA_mem->ida_lperf(IDA_mem, 0); } nstloc = 0; /* If not the first call, perform all stopping tests. */ - if (IDA_mem->ida_nst > 0) { - + if (IDA_mem->ida_nst > 0) + { /* First, check for a root in the last step taken, other than the last root found, if any. If itask = IDA_ONE_STEP and y(tn) was not returned because of an intervening root, return y(tn) now. */ - if (IDA_mem->ida_nrtfn > 0) { - + if (IDA_mem->ida_nrtfn > 0) + { irfndp = IDA_mem->ida_irfnd; ier = IDARcheck2(IDA_mem); - if (ier == CLOSERT) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDARcheck2", + if (ier == CLOSERT) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_CLOSE_ROOTS, IDA_mem->ida_tlo); - return(IDA_ILL_INPUT); - } else if (ier == IDA_RTFUNC_FAIL) { - IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDAS", "IDARcheck2", + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); + } + else if (ier == IDA_RTFUNC_FAIL) + { + IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); - return(IDA_RTFUNC_FAIL); - } else if (ier == RTFOUND) { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_RTFUNC_FAIL); + } + else if (ier == RTFOUND) + { IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tlo; - return(IDA_ROOT_RETURN); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ROOT_RETURN); } /* If tn is distinct from tretlast (within roundoff), check remaining interval for roots */ - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if ( SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tretlast) > troundoff ) { + troundoff = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tretlast) > troundoff) + { ier = IDARcheck3(IDA_mem); - if (ier == IDA_SUCCESS) { /* no root found */ + if (ier == IDA_SUCCESS) + { /* no root found */ IDA_mem->ida_irfnd = 0; - if ((irfndp == 1) && (itask == IDA_ONE_STEP)) { + if ((irfndp == 1) && (itask == IDA_ONE_STEP)) + { IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tn; ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - } else if (ier == RTFOUND) { /* a new root was found */ - IDA_mem->ida_irfnd = 1; + } + else if (ier == RTFOUND) + { /* a new root was found */ + IDA_mem->ida_irfnd = 1; IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tlo; - return(IDA_ROOT_RETURN); - } else if (ier == IDA_RTFUNC_FAIL) { /* g failed */ - IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDAS", "IDARcheck3", - MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); - return(IDA_RTFUNC_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ROOT_RETURN); + } + else if (ier == IDA_RTFUNC_FAIL) + { /* g failed */ + IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, __LINE__, __func__, + __FILE__, MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_RTFUNC_FAIL); } } } /* end of root stop check */ - /* Now test for all other stop conditions. */ istate = IDAStopTest1(IDA_mem, tout, tret, yret, ypret, itask); - if (istate != CONTINUE_STEPS) return(istate); + if (istate != CONTINUE_STEPS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (istate); + } } /* Looping point for internal steps. */ - for(;;) { - + for (;;) + { /* Check for too many steps taken. */ - if ( (IDA_mem->ida_mxstep>0) && (nstloc >= IDA_mem->ida_mxstep) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + if ((IDA_mem->ida_mxstep > 0) && (nstloc >= IDA_mem->ida_mxstep)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_MAX_STEPS, IDA_mem->ida_tn); istate = IDA_TOO_MUCH_WORK; *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; @@ -2411,68 +2871,76 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, /* Call lperf to generate warnings of poor performance. */ - if (IDA_mem->ida_lperf != NULL) - IDA_mem->ida_lperf(IDA_mem, 1); + if (IDA_mem->ida_lperf != NULL) { IDA_mem->ida_lperf(IDA_mem, 1); } /* Reset and check ewt, ewtQ, ewtS and ewtQS (if not first call). */ - if (IDA_mem->ida_nst > 0) { - + if (IDA_mem->ida_nst > 0) + { ier = IDA_mem->ida_efun(IDA_mem->ida_phi[0], IDA_mem->ida_ewt, IDA_mem->ida_edata); - if (ier != 0) { - + if (ier != 0) + { if (IDA_mem->ida_itol == IDA_WF) - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_EWT_NOW_FAIL, IDA_mem->ida_tn); + } else - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_EWT_NOW_BAD, IDA_mem->ida_tn); + } istate = IDA_ILL_INPUT; - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; break; - } - if (IDA_mem->ida_quadr && IDA_mem->ida_errconQ) { + if (IDA_mem->ida_quadr && IDA_mem->ida_errconQ) + { ier = IDAQuadEwtSet(IDA_mem, IDA_mem->ida_phiQ[0], IDA_mem->ida_ewtQ); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_EWTQ_NOW_BAD, IDA_mem->ida_tn); istate = IDA_ILL_INPUT; - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; break; } } - if (IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { ier = IDASensEwtSet(IDA_mem, IDA_mem->ida_phiS[0], IDA_mem->ida_ewtS); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_EWTS_NOW_BAD, IDA_mem->ida_tn); istate = IDA_ILL_INPUT; - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; break; } } - if (IDA_mem->ida_quadr_sensi && IDA_mem->ida_errconQS) { - ier = IDAQuadSensEwtSet(IDA_mem, IDA_mem->ida_phiQS[0], IDA_mem->ida_ewtQS); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + if (IDA_mem->ida_quadr_sensi && IDA_mem->ida_errconQS) + { + ier = IDAQuadSensEwtSet(IDA_mem, IDA_mem->ida_phiQS[0], + IDA_mem->ida_ewtQS); + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_EWTQS_NOW_BAD, IDA_mem->ida_tn); istate = IDA_ILL_INPUT; - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tn; break; } } - } /* Check for too much accuracy requested. */ @@ -2480,23 +2948,33 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, nrm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_phi[0], IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); if (IDA_mem->ida_errconQ) + { nrm = IDAQuadWrmsNormUpdate(IDA_mem, nrm, IDA_mem->ida_phiQ[0], IDA_mem->ida_ewtQ); + } if (IDA_mem->ida_errconS) + { nrm = IDASensWrmsNormUpdate(IDA_mem, nrm, IDA_mem->ida_phiS[0], IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); + } if (IDA_mem->ida_errconQS) + { nrm = IDAQuadSensWrmsNormUpdate(IDA_mem, nrm, IDA_mem->ida_phiQS[0], IDA_mem->ida_ewtQS); + } IDA_mem->ida_tolsf = IDA_mem->ida_uround * nrm; - if (IDA_mem->ida_tolsf > ONE) { + if (IDA_mem->ida_tolsf > ONE) + { IDA_mem->ida_tolsf *= TEN; - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASolve", + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_TOO_MUCH_ACC, IDA_mem->ida_tn); istate = IDA_TOO_MUCH_ACC; *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; - if (IDA_mem->ida_nst > 0) ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + if (IDA_mem->ida_nst > 0) + { + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + } break; } @@ -2506,7 +2984,8 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, /* Process all failed-step cases, and exit loop. */ - if (sflag != IDA_SUCCESS) { + if (sflag != IDA_SUCCESS) + { istate = IDAHandleFailure(IDA_mem, sflag); *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); @@ -2516,27 +2995,34 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, nstloc++; /* If tstop is set and was reached, reset IDA_mem->ida_tn = tstop */ - if (IDA_mem->ida_tstopset) { - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (IDA_mem->ida_tstopset) + { + troundoff = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) + { IDA_mem->ida_tn = IDA_mem->ida_tstop; + } } /* After successful step, check for stop conditions; continue or break. */ /* First check for root in the last step taken. */ - if (IDA_mem->ida_nrtfn > 0) { - + if (IDA_mem->ida_nrtfn > 0) + { ier = IDARcheck3(IDA_mem); - if (ier == RTFOUND) { /* A new root was found */ - IDA_mem->ida_irfnd = 1; - istate = IDA_ROOT_RETURN; + if (ier == RTFOUND) + { /* A new root was found */ + IDA_mem->ida_irfnd = 1; + istate = IDA_ROOT_RETURN; IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tlo; break; - } else if (ier == IDA_RTFUNC_FAIL) { /* g failed */ - IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDAS", "IDARcheck3", + } + else if (ier == IDA_RTFUNC_FAIL) + { /* g failed */ + IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); istate = IDA_RTFUNC_FAIL; break; @@ -2547,30 +3033,34 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, * as this may indicate a user error in the implementation * of the root function. */ - if (IDA_mem->ida_nst==1) { + if (IDA_mem->ida_nst == 1) + { inactive_roots = SUNFALSE; - for (ir=0; irida_nrtfn; ir++) { - if (!IDA_mem->ida_gactive[ir]) { + for (ir = 0; ir < IDA_mem->ida_nrtfn; ir++) + { + if (!IDA_mem->ida_gactive[ir]) + { inactive_roots = SUNTRUE; break; } } - if ((IDA_mem->ida_mxgnull > 0) && inactive_roots) { - IDAProcessError(IDA_mem, IDA_WARNING, "IDAS", "IDASolve", + if ((IDA_mem->ida_mxgnull > 0) && inactive_roots) + { + IDAProcessError(IDA_mem, IDA_WARNING, __LINE__, __func__, __FILE__, MSG_INACTIVE_ROOTS); } } - } /* Now check all other stop conditions. */ istate = IDAStopTest2(IDA_mem, tout, tret, yret, ypret, itask); - if (istate != CONTINUE_STEPS) break; + if (istate != CONTINUE_STEPS) { break; } } /* End of step loop */ - return(istate); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (istate); } /* @@ -2596,52 +3086,64 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, * */ -int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) +int IDAGetDky(void* ida_mem, sunrealtype t, int k, N_Vector dky) { IDAMem IDA_mem; - realtype tfuzz, tp, delt, psij_1; + sunrealtype tfuzz, tp, delt, psij_1; int i, j, retval; - realtype cjk [MXORDP1]; - realtype cjk_1[MXORDP1]; + sunrealtype cjk[MXORDP1]; + sunrealtype cjk_1[MXORDP1]; /* Check ida_mem */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetDky", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (dky == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetDky", MSG_NULL_DKY); - return(IDA_BAD_DKY); + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + + if (dky == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } - if ((k < 0) || (k > IDA_mem->ida_kused)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetDky", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kused)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } /* Check t for legality. Here tn - hused is t_{n-1}. */ - tfuzz = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (IDA_mem->ida_hh < ZERO) tfuzz = - tfuzz; + tfuzz = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (IDA_mem->ida_hh < ZERO) { tfuzz = -tfuzz; } tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; - if ((t - tp)*IDA_mem->ida_hh < ZERO) { - IDAProcessError(IDA_mem, IDA_BAD_T, "IDAS", "IDAGetDky", MSG_BAD_T, t, - IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); - return(IDA_BAD_T); + if ((t - tp) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_BAD_T, __LINE__, __func__, __FILE__, MSG_BAD_T, + t, IDA_mem->ida_tn - IDA_mem->ida_hused, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_T); } /* Initialize the c_j^(k) and c_k^(k-1) */ - for(i=0; iida_tn; - - for(i=0; i<=k; i++) { + delt = t - IDA_mem->ida_tn; + for (i = 0; i <= k; i++) + { /* The below reccurence is used to compute the k-th derivative of the solution: c_j^(k) = ( k * c_{j-1}^(k-1) + c_{j-1}^{k} (Delta+psi_{j-1}) ) / psi_j @@ -2656,40 +3158,48 @@ int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) - psij_1 stands for psi[-1]=0 when j=1 for psi[j-2] when j>1 */ - if(i==0) { - + if (i == 0) + { cjk[i] = 1; psij_1 = 0; - }else { + } + else + { /* i i-1 1 c_i^(i) can be always updated since c_i^(i) = ----- -------- ... ----- psi_j psi_{j-1} psi_1 */ - cjk[i] = cjk[i-1]*i / IDA_mem->ida_psi[i-1]; - psij_1 = IDA_mem->ida_psi[i-1]; + cjk[i] = cjk[i - 1] * i / IDA_mem->ida_psi[i - 1]; + psij_1 = IDA_mem->ida_psi[i - 1]; } /* update c_j^(i) */ /*j does not need to go till kused */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) { - - cjk[j] = ( i* cjk_1[j-1] + cjk[j-1] * (delt + psij_1) ) / IDA_mem->ida_psi[j-1]; - psij_1 = IDA_mem->ida_psi[j-1]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) + { + cjk[j] = (i * cjk_1[j - 1] + cjk[j - 1] * (delt + psij_1)) / + IDA_mem->ida_psi[j - 1]; + psij_1 = IDA_mem->ida_psi[j - 1]; } /* save existing c_j^(i)'s */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) cjk_1[j] = cjk[j]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) { cjk_1[j] = cjk[j]; } } /* Compute sum (c_j(t) * phi(t)) */ /* Sum j=k to j<=IDA_mem->ida_kused */ - retval = N_VLinearCombination(IDA_mem->ida_kused-k+1, cjk+k, - IDA_mem->ida_phi+k, dky); - if (retval != IDA_SUCCESS) return(IDA_VECTOROP_ERR); + retval = N_VLinearCombination(IDA_mem->ida_kused - k + 1, cjk + k, + IDA_mem->ida_phi + k, dky); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -2701,19 +3211,26 @@ int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) * This is just a wrapper that calls IDAGetQuadDky with k=0. */ -int IDAGetQuad(void *ida_mem, realtype *ptret, N_Vector yQout) +int IDAGetQuad(void* ida_mem, sunrealtype* ptret, N_Vector yQout) { IDAMem IDA_mem; + int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuad", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } IDA_mem = (IDAMem)ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + *ptret = IDA_mem->ida_tretlast; - return IDAGetQuadDky(ida_mem, IDA_mem->ida_tretlast, 0, yQout); + retval = IDAGetQuadDky(ida_mem, IDA_mem->ida_tretlast, 0, yQout); + + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (retval); } /* @@ -2723,84 +3240,107 @@ int IDAGetQuad(void *ida_mem, realtype *ptret, N_Vector yQout) * derivatives up to the current method order) at any time within * the last integration step (dense output). */ -int IDAGetQuadDky(void *ida_mem, realtype t, int k, N_Vector dkyQ) +int IDAGetQuadDky(void* ida_mem, sunrealtype t, int k, N_Vector dkyQ) { IDAMem IDA_mem; - realtype tfuzz, tp, delt, psij_1; + sunrealtype tfuzz, tp, delt, psij_1; int i, j, retval; - realtype cjk [MXORDP1]; - realtype cjk_1[MXORDP1]; + sunrealtype cjk[MXORDP1]; + sunrealtype cjk_1[MXORDP1]; /* Check ida_mem */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadDky", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Ckeck if quadrature was initialized */ - if (IDA_mem->ida_quadr != SUNTRUE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAGetQuadDky", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadr != SUNTRUE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUAD); } - if (dkyQ == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetQuadDky", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (dkyQ == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } - if ((k < 0) || (k > IDA_mem->ida_kk)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetQuadDky", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kk)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } /* Check t for legality. Here tn - hused is t_{n-1}. */ tfuzz = HUNDRED * IDA_mem->ida_uround * (IDA_mem->ida_tn + IDA_mem->ida_hh); - tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; - if ( (t - tp)*IDA_mem->ida_hh < ZERO) { - IDAProcessError(IDA_mem, IDA_BAD_T, "IDAS", "IDAGetQuadDky", MSG_BAD_T, - t, IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); - return(IDA_BAD_T); + tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; + if ((t - tp) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_BAD_T, __LINE__, __func__, __FILE__, MSG_BAD_T, + t, IDA_mem->ida_tn - IDA_mem->ida_hused, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_T); } /* Initialize the c_j^(k) and c_k^(k-1) */ - for(i=0; iida_tn; - - for(i=0; i<=k; i++) { + delt = t - IDA_mem->ida_tn; - if(i==0) { + for (i = 0; i <= k; i++) + { + if (i == 0) + { cjk[i] = 1; psij_1 = 0; - }else { - cjk[i] = cjk[i-1]*i / IDA_mem->ida_psi[i-1]; - psij_1 = IDA_mem->ida_psi[i-1]; + } + else + { + cjk[i] = cjk[i - 1] * i / IDA_mem->ida_psi[i - 1]; + psij_1 = IDA_mem->ida_psi[i - 1]; } /* update c_j^(i) */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) { - - cjk[j] = ( i* cjk_1[j-1] + cjk[j-1] * (delt + psij_1) ) / IDA_mem->ida_psi[j-1]; - psij_1 = IDA_mem->ida_psi[j-1]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) + { + cjk[j] = (i * cjk_1[j - 1] + cjk[j - 1] * (delt + psij_1)) / + IDA_mem->ida_psi[j - 1]; + psij_1 = IDA_mem->ida_psi[j - 1]; } /* save existing c_j^(i)'s */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) cjk_1[j] = cjk[j]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) { cjk_1[j] = cjk[j]; } } /* Compute sum (c_j(t) * phi(t)) */ - retval = N_VLinearCombination(IDA_mem->ida_kused-k+1, cjk+k, IDA_mem->ida_phiQ+k, dkyQ); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearCombination(IDA_mem->ida_kused - k + 1, cjk + k, + IDA_mem->ida_phiQ + k, dkyQ); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } - /* * IDAGetSens * @@ -2810,36 +3350,51 @@ int IDAGetQuadDky(void *ida_mem, realtype t, int k, N_Vector dkyQ) * is=0, 1, ... ,NS-1. */ -int IDAGetSens(void *ida_mem, realtype *ptret, N_Vector *yySout) +int IDAGetSens(void* ida_mem, sunrealtype* ptret, N_Vector* yySout) { IDAMem IDA_mem; - int is, ierr=0; + int is, ierr = 0; /* Check ida_mem */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSens", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /*Check the parameters */ - if (yySout == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetSens", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (yySout == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } /* are sensitivities enabled? */ - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSens", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } *ptret = IDA_mem->ida_tretlast; - for(is=0; isida_Ns; is++) - if( IDA_SUCCESS != (ierr = IDAGetSensDky1(ida_mem, *ptret, 0, is, yySout[is])) ) break; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + if (IDA_SUCCESS != (ierr = IDAGetSensDky1(ida_mem, *ptret, 0, is, yySout[is]))) + { + break; + } + } - return(ierr); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (ierr); } /* @@ -2850,43 +3405,55 @@ int IDAGetSens(void *ida_mem, realtype *ptret, N_Vector *yySout) * a pointer to N_Vector and must be allocated by the user to hold at * least Ns vectors. */ -int IDAGetSensDky(void *ida_mem, realtype t, int k, N_Vector *dkySout) +int IDAGetSensDky(void* ida_mem, sunrealtype t, int k, N_Vector* dkySout) { - int is, ier=0; + int is, ier = 0; IDAMem IDA_mem; /* Check all inputs for legality */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensDky", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensDky", MSG_NO_SENSI); - return(IDA_NO_SENS); + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } - if (dkySout == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetSensDky", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (dkySout == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } - if ((k < 0) || (k > IDA_mem->ida_kk)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetSensDky", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kk)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { ier = IDAGetSensDky1(ida_mem, t, k, is, dkySout[is]); - if (ier!=IDA_SUCCESS) break; + if (ier != IDA_SUCCESS) { break; } } - return(ier); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (ier); } - /* * IDAGetSens1 * @@ -2895,19 +3462,26 @@ int IDAGetSensDky(void *ida_mem, realtype t, int k, N_Vector *dkySout) * This is just a wrapper that calls IDASensDky1 with k=0. */ -int IDAGetSens1(void *ida_mem, realtype *ptret, int is, N_Vector yySret) +int IDAGetSens1(void* ida_mem, sunrealtype* ptret, int is, N_Vector yySret) { IDAMem IDA_mem; + int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSens1", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); *ptret = IDA_mem->ida_tretlast; - return IDAGetSensDky1(ida_mem, *ptret, 0, is, yySret); + retval = IDAGetSensDky1(ida_mem, *ptret, 0, is, yySret); + + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (retval); } /* @@ -2923,90 +3497,121 @@ int IDAGetSens1(void *ida_mem, realtype *ptret, int is, N_Vector yySret) * function after a successful return from IDASolve with sensitivity * computation enabled. */ -int IDAGetSensDky1(void *ida_mem, realtype t, int k, int is, N_Vector dkyS) +int IDAGetSensDky1(void* ida_mem, sunrealtype t, int k, int is, N_Vector dkyS) { IDAMem IDA_mem; - realtype tfuzz, tp, delt, psij_1; + sunrealtype tfuzz, tp, delt, psij_1; int i, j, retval; - realtype cjk [MXORDP1]; - realtype cjk_1[MXORDP1]; + sunrealtype cjk[MXORDP1]; + sunrealtype cjk_1[MXORDP1]; /* Check all inputs for legality */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensDky1", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensDky1", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } - if (dkyS == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetSensDky1", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (dkyS == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } /* Is the requested sensitivity index valid? */ - if(is<0 || is >= IDA_mem->ida_Ns) { - IDAProcessError(IDA_mem, IDA_BAD_IS, "IDAS", "IDAGetSensDky1", MSG_BAD_IS); + if (is < 0 || is >= IDA_mem->ida_Ns) + { + IDAProcessError(IDA_mem, IDA_BAD_IS, __LINE__, __func__, __FILE__, + MSG_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_IS); } /* Is the requested order valid? */ - if ((k < 0) || (k > IDA_mem->ida_kused)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetSensDky1", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kused)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } /* Check t for legality. Here tn - hused is t_{n-1}. */ - tfuzz = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (IDA_mem->ida_hh < ZERO) tfuzz = - tfuzz; + tfuzz = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (IDA_mem->ida_hh < ZERO) { tfuzz = -tfuzz; } tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; - if ((t - tp)*IDA_mem->ida_hh < ZERO) { - IDAProcessError(IDA_mem, IDA_BAD_T, "IDAS", "IDAGetSensDky1", MSG_BAD_T, - t, IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); - return(IDA_BAD_T); + if ((t - tp) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_BAD_T, __LINE__, __func__, __FILE__, MSG_BAD_T, + t, IDA_mem->ida_tn - IDA_mem->ida_hused, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_T); } /* Initialize the c_j^(k) and c_k^(k-1) */ - for(i=0; iida_tn; - for(i=0; i<=k; i++) { - - if(i==0) { + for (i = 0; i <= k; i++) + { + if (i == 0) + { cjk[i] = 1; psij_1 = 0; - }else { - cjk[i] = cjk[i-1]*i / IDA_mem->ida_psi[i-1]; - psij_1 = IDA_mem->ida_psi[i-1]; + } + else + { + cjk[i] = cjk[i - 1] * i / IDA_mem->ida_psi[i - 1]; + psij_1 = IDA_mem->ida_psi[i - 1]; } /* Update cjk based on the reccurence */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) { - cjk[j] = ( i* cjk_1[j-1] + cjk[j-1] * (delt + psij_1) ) / IDA_mem->ida_psi[j-1]; - psij_1 = IDA_mem->ida_psi[j-1]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) + { + cjk[j] = (i * cjk_1[j - 1] + cjk[j - 1] * (delt + psij_1)) / + IDA_mem->ida_psi[j - 1]; + psij_1 = IDA_mem->ida_psi[j - 1]; } /* Update cjk_1 for the next step */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) cjk_1[j] = cjk[j]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) { cjk_1[j] = cjk[j]; } } /* Compute sum (c_j(t) * phi(t)) */ - for(j=k; j<=IDA_mem->ida_kused; j++) - IDA_mem->ida_Xvecs[j-k] = IDA_mem->ida_phiS[j][is]; + for (j = k; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Xvecs[j - k] = IDA_mem->ida_phiS[j][is]; + } - retval = N_VLinearCombination(IDA_mem->ida_kused-k+1, cjk+k, + retval = N_VLinearCombination(IDA_mem->ida_kused - k + 1, cjk + k, IDA_mem->ida_Xvecs, dkyS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3018,36 +3623,52 @@ int IDAGetSensDky1(void *ida_mem, realtype t, int k, int is, N_Vector dkyS) * is=0, 1, ... ,NS-1. */ -int IDAGetQuadSens(void *ida_mem, realtype *ptret, N_Vector *yyQSout) +int IDAGetQuadSens(void* ida_mem, sunrealtype* ptret, N_Vector* yyQSout) { IDAMem IDA_mem; - int is, ierr=0; + int is, ierr = 0; /* Check ida_mem */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSens", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /*Check the parameters */ - if (yyQSout == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetQuadSens", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (yyQSout == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } /* are sensitivities enabled? */ - if (IDA_mem->ida_quadr_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetQuadSens", MSG_NO_QUADSENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } *ptret = IDA_mem->ida_tretlast; - for(is=0; isida_Ns; is++) - if( IDA_SUCCESS != (ierr = IDAGetQuadSensDky1(ida_mem, *ptret, 0, is, yyQSout[is])) ) break; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + if (IDA_SUCCESS != + (ierr = IDAGetQuadSensDky1(ida_mem, *ptret, 0, is, yyQSout[is]))) + { + break; + } + } - return(ierr); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (ierr); } /* @@ -3058,48 +3679,63 @@ int IDAGetQuadSens(void *ida_mem, realtype *ptret, N_Vector *yyQSout) * a pointer to N_Vector and must be allocated by the user to hold at * least Ns vectors. */ -int IDAGetQuadSensDky(void *ida_mem, realtype t, int k, N_Vector *dkyQSout) +int IDAGetQuadSensDky(void* ida_mem, sunrealtype t, int k, N_Vector* dkyQSout) { - int is, ier=0; + int is, ier = 0; IDAMem IDA_mem; /* Check all inputs for legality */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensDky", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetQuadSensDky", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } - if (IDA_mem->ida_quadr_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensDky", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUADSENS); } - if (dkyQSout == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetQuadSensDky", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (dkyQSout == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } - if ((k < 0) || (k > IDA_mem->ida_kk)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetQuadSensDky", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kk)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { ier = IDAGetQuadSensDky1(ida_mem, t, k, is, dkyQSout[is]); - if (ier!=IDA_SUCCESS) break; + if (ier != IDA_SUCCESS) { break; } } - return(ier); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (ier); } - /* * IDAGetQuadSens1 * @@ -3108,34 +3744,50 @@ int IDAGetQuadSensDky(void *ida_mem, realtype t, int k, N_Vector *dkyQSout) * This is just a wrapper that calls IDASensDky1 with k=0. */ -int IDAGetQuadSens1(void *ida_mem, realtype *ptret, int is, N_Vector yyQSret) +int IDAGetQuadSens1(void* ida_mem, sunrealtype* ptret, int is, N_Vector yyQSret) { IDAMem IDA_mem; + int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSens1", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetQuadSens1", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } - if (IDA_mem->ida_quadr_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSens1", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUADSENS); } - if (yyQSret == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetQuadSens1", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (yyQSret == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } *ptret = IDA_mem->ida_tretlast; - return IDAGetQuadSensDky1(ida_mem, *ptret, 0, is, yyQSret); + retval = IDAGetQuadSensDky1(ida_mem, *ptret, 0, is, yyQSret); + + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (retval); } /* @@ -3151,96 +3803,129 @@ int IDAGetQuadSens1(void *ida_mem, realtype *ptret, int is, N_Vector yyQSret) * function after a successful return from IDASolve with sensitivity * computation enabled. */ -int IDAGetQuadSensDky1(void *ida_mem, realtype t, int k, int is, N_Vector dkyQS) +int IDAGetQuadSensDky1(void* ida_mem, sunrealtype t, int k, int is, N_Vector dkyQS) { IDAMem IDA_mem; - realtype tfuzz, tp, delt, psij_1; + sunrealtype tfuzz, tp, delt, psij_1; int i, j, retval; - realtype cjk [MXORDP1]; - realtype cjk_1[MXORDP1]; + sunrealtype cjk[MXORDP1]; + sunrealtype cjk_1[MXORDP1]; /* Check all inputs for legality */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensDky1", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetQuadSensDky1", MSG_NO_SENSI); - return(IDA_NO_SENS); - } + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - if (IDA_mem->ida_quadr_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensDky1", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_SENS); } + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_QUADSENS); + } - if (dkyQS == NULL) { - IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDAS", "IDAGetQuadSensDky1", MSG_NULL_DKY); - return(IDA_BAD_DKY); + if (dkyQS == NULL) + { + IDAProcessError(IDA_mem, IDA_BAD_DKY, __LINE__, __func__, __FILE__, + MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_DKY); } /* Is the requested sensitivity index valid*/ - if(is<0 || is >= IDA_mem->ida_Ns) { - IDAProcessError(IDA_mem, IDA_BAD_IS, "IDAS", "IDAGetQuadSensDky1", MSG_BAD_IS); + if (is < 0 || is >= IDA_mem->ida_Ns) + { + IDAProcessError(IDA_mem, IDA_BAD_IS, __LINE__, __func__, __FILE__, + MSG_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_IS); } /* Is the requested order valid? */ - if ((k < 0) || (k > IDA_mem->ida_kused)) { - IDAProcessError(IDA_mem, IDA_BAD_K, "IDAS", "IDAGetQuadSensDky1", MSG_BAD_K); - return(IDA_BAD_K); + if ((k < 0) || (k > IDA_mem->ida_kused)) + { + IDAProcessError(IDA_mem, IDA_BAD_K, __LINE__, __func__, __FILE__, MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_K); } /* Check t for legality. Here tn - hused is t_{n-1}. */ - tfuzz = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (IDA_mem->ida_hh < ZERO) tfuzz = - tfuzz; + tfuzz = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (IDA_mem->ida_hh < ZERO) { tfuzz = -tfuzz; } tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; - if ((t - tp)*IDA_mem->ida_hh < ZERO) { - IDAProcessError(IDA_mem, IDA_BAD_T, "IDAS", "IDAGetQuadSensDky1", MSG_BAD_T, - t, IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); - return(IDA_BAD_T); + if ((t - tp) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_BAD_T, __LINE__, __func__, __FILE__, MSG_BAD_T, + t, IDA_mem->ida_tn - IDA_mem->ida_hused, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_BAD_T); } /* Initialize the c_j^(k) and c_k^(k-1) */ - for(i=0; iida_tn; - for(i=0; i<=k; i++) { - - if(i==0) { + for (i = 0; i <= k; i++) + { + if (i == 0) + { cjk[i] = 1; psij_1 = 0; - }else { - cjk[i] = cjk[i-1]*i / IDA_mem->ida_psi[i-1]; - psij_1 = IDA_mem->ida_psi[i-1]; + } + else + { + cjk[i] = cjk[i - 1] * i / IDA_mem->ida_psi[i - 1]; + psij_1 = IDA_mem->ida_psi[i - 1]; } /* Update cjk based on the reccurence */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) { - cjk[j] = ( i* cjk_1[j-1] + cjk[j-1] * (delt + psij_1) ) / IDA_mem->ida_psi[j-1]; - psij_1 = IDA_mem->ida_psi[j-1]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) + { + cjk[j] = (i * cjk_1[j - 1] + cjk[j - 1] * (delt + psij_1)) / + IDA_mem->ida_psi[j - 1]; + psij_1 = IDA_mem->ida_psi[j - 1]; } /* Update cjk_1 for the next step */ - for(j=i+1; j<=IDA_mem->ida_kused-k+i; j++) cjk_1[j] = cjk[j]; + for (j = i + 1; j <= IDA_mem->ida_kused - k + i; j++) { cjk_1[j] = cjk[j]; } } /* Compute sum (c_j(t) * phi(t)) */ - for(j=k; j<=IDA_mem->ida_kused; j++) - IDA_mem->ida_Xvecs[j-k] = IDA_mem->ida_phiQS[j][is]; + for (j = k; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Xvecs[j - k] = IDA_mem->ida_phiQS[j][is]; + } - retval = N_VLinearCombination(IDA_mem->ida_kused-k+1, cjk+k, + retval = N_VLinearCombination(IDA_mem->ida_kused - k + 1, cjk + k, IDA_mem->ida_Xvecs, dkyQS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_VECTOROP_ERR); + } - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3248,20 +3933,24 @@ int IDAGetQuadSensDky1(void *ida_mem, realtype t, int k, int is, N_Vector dkyQS) * * Computes y based on the current prediction and given correction. */ -int IDAComputeY(void *ida_mem, N_Vector ycor, N_Vector y) +int IDAComputeY(void* ida_mem, N_Vector ycor, N_Vector y) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAComputeY", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, ycor, y); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3269,20 +3958,24 @@ int IDAComputeY(void *ida_mem, N_Vector ycor, N_Vector y) * * Computes y' based on the current prediction and given correction. */ -int IDAComputeYp(void *ida_mem, N_Vector ycor, N_Vector yp) +int IDAComputeYp(void* ida_mem, N_Vector ycor, N_Vector yp) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAComputeYp", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, yp); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3290,22 +3983,25 @@ int IDAComputeYp(void *ida_mem, N_Vector ycor, N_Vector yp) * * Computes yS based on the current prediction and given correction. */ -int IDAComputeYSens(void *ida_mem, N_Vector *ycorS, N_Vector *yyS) +int IDAComputeYSens(void* ida_mem, N_Vector* ycorS, N_Vector* yyS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAComputeYSens", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yySpredict, - ONE, ycorS, yyS); + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yySpredict, ONE, + ycorS, yyS); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3313,22 +4009,25 @@ int IDAComputeYSens(void *ida_mem, N_Vector *ycorS, N_Vector *yyS) * * Computes yS' based on the current prediction and given correction. */ -int IDAComputeYpSens(void *ida_mem, N_Vector *ycorS, N_Vector *ypS) +int IDAComputeYpSens(void* ida_mem, N_Vector* ycorS, N_Vector* ypS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAComputeYpSens", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_ypSpredict, + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_ypSpredict, IDA_mem->ida_cj, ycorS, ypS); - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -3346,13 +4045,13 @@ int IDAComputeYpSens(void *ida_mem, N_Vector *ycorS, N_Vector *ypS) * to lfree). */ -void IDAFree(void **ida_mem) +void IDAFree(void** ida_mem) { IDAMem IDA_mem; - if (*ida_mem == NULL) return; + if (*ida_mem == NULL) { return; } - IDA_mem = (IDAMem) (*ida_mem); + IDA_mem = (IDAMem)(*ida_mem); IDAFreeVectors(IDA_mem); @@ -3365,27 +4064,37 @@ void IDAFree(void **ida_mem) IDAAdjFree(IDA_mem); /* if IDA created the NLS object then free it */ - if (IDA_mem->ownNLS) { + if (IDA_mem->ownNLS) + { SUNNonlinSolFree(IDA_mem->NLS); IDA_mem->ownNLS = SUNFALSE; - IDA_mem->NLS = NULL; + IDA_mem->NLS = NULL; } - if (IDA_mem->ida_lfree != NULL) - IDA_mem->ida_lfree(IDA_mem); + if (IDA_mem->ida_lfree != NULL) { IDA_mem->ida_lfree(IDA_mem); } - if (IDA_mem->ida_nrtfn > 0) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; - free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; - free(IDA_mem->ida_gactive); IDA_mem->ida_gactive = NULL; + if (IDA_mem->ida_nrtfn > 0) + { + free(IDA_mem->ida_glo); + IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); + IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); + IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); + IDA_mem->ida_iroots = NULL; + free(IDA_mem->ida_rootdir); + IDA_mem->ida_rootdir = NULL; + free(IDA_mem->ida_gactive); + IDA_mem->ida_gactive = NULL; } - free(IDA_mem->ida_cvals); IDA_mem->ida_cvals = NULL; - free(IDA_mem->ida_Xvecs); IDA_mem->ida_Xvecs = NULL; - free(IDA_mem->ida_Zvecs); IDA_mem->ida_Zvecs = NULL; + free(IDA_mem->ida_cvals); + IDA_mem->ida_cvals = NULL; + free(IDA_mem->ida_Xvecs); + IDA_mem->ida_Xvecs = NULL; + free(IDA_mem->ida_Zvecs); + IDA_mem->ida_Zvecs = NULL; free(*ida_mem); *ida_mem = NULL; @@ -3399,17 +4108,18 @@ void IDAFree(void **ida_mem) * ida_mem returned by IDACreate. */ -void IDAQuadFree(void *ida_mem) +void IDAQuadFree(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem == NULL) return; - IDA_mem = (IDAMem) ida_mem; + if (ida_mem == NULL) { return; } + IDA_mem = (IDAMem)ida_mem; - if(IDA_mem->ida_quadMallocDone) { + if (IDA_mem->ida_quadMallocDone) + { IDAQuadFreeVectors(IDA_mem); IDA_mem->ida_quadMallocDone = SUNFALSE; - IDA_mem->ida_quadr = SUNFALSE; + IDA_mem->ida_quadr = SUNFALSE; } } @@ -3421,48 +4131,60 @@ void IDAQuadFree(void *ida_mem) * ida_mem returned by IDACreate. */ -void IDASensFree(void *ida_mem) +void IDASensFree(void* ida_mem) { IDAMem IDA_mem; /* return immediately if IDA memory is NULL */ - if (ida_mem == NULL) return; - IDA_mem = (IDAMem) ida_mem; + if (ida_mem == NULL) { return; } + IDA_mem = (IDAMem)ida_mem; - if(IDA_mem->ida_sensMallocDone) { + if (IDA_mem->ida_sensMallocDone) + { IDASensFreeVectors(IDA_mem); IDA_mem->ida_sensMallocDone = SUNFALSE; - IDA_mem->ida_sensi = SUNFALSE; + IDA_mem->ida_sensi = SUNFALSE; } /* free any vector wrappers */ - if (IDA_mem->simMallocDone) { - N_VDestroy(IDA_mem->ypredictSim); IDA_mem->ypredictSim = NULL; - N_VDestroy(IDA_mem->ycorSim); IDA_mem->ycorSim = NULL; - N_VDestroy(IDA_mem->ewtSim); IDA_mem->ewtSim = NULL; + if (IDA_mem->simMallocDone) + { + N_VDestroy(IDA_mem->ypredictSim); + IDA_mem->ypredictSim = NULL; + N_VDestroy(IDA_mem->ycorSim); + IDA_mem->ycorSim = NULL; + N_VDestroy(IDA_mem->ewtSim); + IDA_mem->ewtSim = NULL; IDA_mem->simMallocDone = SUNFALSE; } - if (IDA_mem->stgMallocDone) { - N_VDestroy(IDA_mem->ypredictStg); IDA_mem->ypredictStg = NULL; - N_VDestroy(IDA_mem->ycorStg); IDA_mem->ycorStg = NULL; - N_VDestroy(IDA_mem->ewtStg); IDA_mem->ewtStg = NULL; + if (IDA_mem->stgMallocDone) + { + N_VDestroy(IDA_mem->ypredictStg); + IDA_mem->ypredictStg = NULL; + N_VDestroy(IDA_mem->ycorStg); + IDA_mem->ycorStg = NULL; + N_VDestroy(IDA_mem->ewtStg); + IDA_mem->ewtStg = NULL; IDA_mem->stgMallocDone = SUNFALSE; } /* if IDA created the NLS object then free it */ - if (IDA_mem->ownNLSsim) { + if (IDA_mem->ownNLSsim) + { SUNNonlinSolFree(IDA_mem->NLSsim); IDA_mem->ownNLSsim = SUNFALSE; - IDA_mem->NLSsim = NULL; + IDA_mem->NLSsim = NULL; } - if (IDA_mem->ownNLSstg) { + if (IDA_mem->ownNLSstg) + { SUNNonlinSolFree(IDA_mem->NLSstg); IDA_mem->ownNLSstg = SUNFALSE; - IDA_mem->NLSstg = NULL; + IDA_mem->NLSstg = NULL; } /* free min atol array if necessary */ - if (IDA_mem->ida_atolSmin0) { + if (IDA_mem->ida_atolSmin0) + { free(IDA_mem->ida_atolSmin0); IDA_mem->ida_atolSmin0 = NULL; } @@ -3479,17 +4201,19 @@ void IDAQuadSensFree(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem==NULL) return; - IDA_mem = (IDAMem) ida_mem; + if (ida_mem == NULL) { return; } + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadSensMallocDone) { + if (IDA_mem->ida_quadSensMallocDone) + { IDAQuadSensFreeVectors(IDA_mem); - IDA_mem->ida_quadSensMallocDone=SUNFALSE; - IDA_mem->ida_quadr_sensi = SUNFALSE; + IDA_mem->ida_quadSensMallocDone = SUNFALSE; + IDA_mem->ida_quadr_sensi = SUNFALSE; } /* free min atol array if necessary */ - if (IDA_mem->ida_atolQSmin0) { + if (IDA_mem->ida_atolQSmin0) + { free(IDA_mem->ida_atolQSmin0); IDA_mem->ida_atolQSmin0 = NULL; } @@ -3508,22 +4232,18 @@ void IDAQuadSensFree(void* ida_mem) * If any of them is missing it returns SUNFALSE. */ -static booleantype IDACheckNvector(N_Vector tmpl) +static sunbooleantype IDACheckNvector(N_Vector tmpl) { - if ((tmpl->ops->nvclone == NULL) || - (tmpl->ops->nvdestroy == NULL) || - (tmpl->ops->nvlinearsum == NULL) || - (tmpl->ops->nvconst == NULL) || - (tmpl->ops->nvprod == NULL) || - (tmpl->ops->nvscale == NULL) || - (tmpl->ops->nvabs == NULL) || - (tmpl->ops->nvinv == NULL) || - (tmpl->ops->nvaddconst == NULL) || - (tmpl->ops->nvwrmsnorm == NULL) || - (tmpl->ops->nvmin == NULL)) - return(SUNFALSE); - else - return(SUNTRUE); + if ((tmpl->ops->nvclone == NULL) || (tmpl->ops->nvdestroy == NULL) || + (tmpl->ops->nvlinearsum == NULL) || (tmpl->ops->nvconst == NULL) || + (tmpl->ops->nvprod == NULL) || (tmpl->ops->nvscale == NULL) || + (tmpl->ops->nvabs == NULL) || (tmpl->ops->nvinv == NULL) || + (tmpl->ops->nvaddconst == NULL) || (tmpl->ops->nvwrmsnorm == NULL) || + (tmpl->ops->nvmin == NULL)) + { + return (SUNFALSE); + } + else { return (SUNTRUE); } } /* @@ -3545,68 +4265,75 @@ static booleantype IDACheckNvector(N_Vector tmpl) * allocated here. */ -static booleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl) +static sunbooleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl) { int i, j, maxcol; /* Allocate ewt, ee, delta, yypredict, yppredict, savres, tempv1, tempv2, tempv3 */ IDA_mem->ida_ewt = N_VClone(tmpl); - if (IDA_mem->ida_ewt == NULL) return(SUNFALSE); + if (IDA_mem->ida_ewt == NULL) { return (SUNFALSE); } IDA_mem->ida_ee = N_VClone(tmpl); - if (IDA_mem->ida_ee == NULL) { + if (IDA_mem->ida_ee == NULL) + { N_VDestroy(IDA_mem->ida_ewt); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_delta = N_VClone(tmpl); - if (IDA_mem->ida_delta == NULL) { + if (IDA_mem->ida_delta == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_yypredict = N_VClone(tmpl); - if (IDA_mem->ida_yypredict == NULL) { + if (IDA_mem->ida_yypredict == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_yppredict = N_VClone(tmpl); - if (IDA_mem->ida_yppredict == NULL) { + if (IDA_mem->ida_yppredict == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); N_VDestroy(IDA_mem->ida_yypredict); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_savres = N_VClone(tmpl); - if (IDA_mem->ida_savres == NULL) { + if (IDA_mem->ida_savres == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); N_VDestroy(IDA_mem->ida_yypredict); N_VDestroy(IDA_mem->ida_yppredict); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_tempv1 = N_VClone(tmpl); - if (IDA_mem->ida_tempv1 == NULL) { + if (IDA_mem->ida_tempv1 == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); N_VDestroy(IDA_mem->ida_yypredict); N_VDestroy(IDA_mem->ida_yppredict); N_VDestroy(IDA_mem->ida_savres); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_tempv2 = N_VClone(tmpl); - if (IDA_mem->ida_tempv2 == NULL) { + if (IDA_mem->ida_tempv2 == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); @@ -3614,11 +4341,12 @@ static booleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroy(IDA_mem->ida_yppredict); N_VDestroy(IDA_mem->ida_savres); N_VDestroy(IDA_mem->ida_tempv1); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_tempv3 = N_VClone(tmpl); - if (IDA_mem->ida_tempv3 == NULL) { + if (IDA_mem->ida_tempv3 == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); @@ -3627,16 +4355,18 @@ static booleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroy(IDA_mem->ida_savres); N_VDestroy(IDA_mem->ida_tempv1); N_VDestroy(IDA_mem->ida_tempv2); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate phi[0] ... phi[maxord]. Make sure phi[2] and phi[3] are allocated (for use as temporary vectors), regardless of maxord. */ - maxcol = SUNMAX(IDA_mem->ida_maxord,3); - for (j=0; j <= maxcol; j++) { + maxcol = SUNMAX(IDA_mem->ida_maxord, 3); + for (j = 0; j <= maxcol; j++) + { IDA_mem->ida_phi[j] = N_VClone(tmpl); - if (IDA_mem->ida_phi[j] == NULL) { + if (IDA_mem->ida_phi[j] == NULL) + { N_VDestroy(IDA_mem->ida_ewt); N_VDestroy(IDA_mem->ida_ee); N_VDestroy(IDA_mem->ida_delta); @@ -3646,19 +4376,19 @@ static booleantype IDAAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroy(IDA_mem->ida_tempv1); N_VDestroy(IDA_mem->ida_tempv2); N_VDestroy(IDA_mem->ida_tempv3); - for (i=0; i < j; i++) N_VDestroy(IDA_mem->ida_phi[i]); - return(SUNFALSE); + for (i = 0; i < j; i++) { N_VDestroy(IDA_mem->ida_phi[i]); } + return (SUNFALSE); } } /* Update solver workspace lengths */ - IDA_mem->ida_lrw += (maxcol + 10)*IDA_mem->ida_lrw1; - IDA_mem->ida_liw += (maxcol + 10)*IDA_mem->ida_liw1; + IDA_mem->ida_lrw += (maxcol + 10) * IDA_mem->ida_lrw1; + IDA_mem->ida_liw += (maxcol + 10) * IDA_mem->ida_liw1; /* Store the value of maxord used here */ IDA_mem->ida_maxord_alloc = IDA_mem->ida_maxord; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -3671,43 +4401,57 @@ static void IDAFreeVectors(IDAMem IDA_mem) { int j, maxcol; - N_VDestroy(IDA_mem->ida_ewt); IDA_mem->ida_ewt = NULL; - N_VDestroy(IDA_mem->ida_ee); IDA_mem->ida_ee = NULL; - N_VDestroy(IDA_mem->ida_delta); IDA_mem->ida_delta = NULL; - N_VDestroy(IDA_mem->ida_yypredict); IDA_mem->ida_yypredict = NULL; - N_VDestroy(IDA_mem->ida_yppredict); IDA_mem->ida_yppredict = NULL; - N_VDestroy(IDA_mem->ida_savres); IDA_mem->ida_savres = NULL; - N_VDestroy(IDA_mem->ida_tempv1); IDA_mem->ida_tempv1 = NULL; - N_VDestroy(IDA_mem->ida_tempv2); IDA_mem->ida_tempv2 = NULL; - N_VDestroy(IDA_mem->ida_tempv3); IDA_mem->ida_tempv3 = NULL; - maxcol = SUNMAX(IDA_mem->ida_maxord_alloc,3); - for(j=0; j <= maxcol; j++) { + N_VDestroy(IDA_mem->ida_ewt); + IDA_mem->ida_ewt = NULL; + N_VDestroy(IDA_mem->ida_ee); + IDA_mem->ida_ee = NULL; + N_VDestroy(IDA_mem->ida_delta); + IDA_mem->ida_delta = NULL; + N_VDestroy(IDA_mem->ida_yypredict); + IDA_mem->ida_yypredict = NULL; + N_VDestroy(IDA_mem->ida_yppredict); + IDA_mem->ida_yppredict = NULL; + N_VDestroy(IDA_mem->ida_savres); + IDA_mem->ida_savres = NULL; + N_VDestroy(IDA_mem->ida_tempv1); + IDA_mem->ida_tempv1 = NULL; + N_VDestroy(IDA_mem->ida_tempv2); + IDA_mem->ida_tempv2 = NULL; + N_VDestroy(IDA_mem->ida_tempv3); + IDA_mem->ida_tempv3 = NULL; + maxcol = SUNMAX(IDA_mem->ida_maxord_alloc, 3); + for (j = 0; j <= maxcol; j++) + { N_VDestroy(IDA_mem->ida_phi[j]); IDA_mem->ida_phi[j] = NULL; } - IDA_mem->ida_lrw -= (maxcol + 10)*IDA_mem->ida_lrw1; - IDA_mem->ida_liw -= (maxcol + 10)*IDA_mem->ida_liw1; + IDA_mem->ida_lrw -= (maxcol + 10) * IDA_mem->ida_lrw1; + IDA_mem->ida_liw -= (maxcol + 10) * IDA_mem->ida_liw1; - if (IDA_mem->ida_VatolMallocDone) { - N_VDestroy(IDA_mem->ida_Vatol); IDA_mem->ida_Vatol = NULL; + if (IDA_mem->ida_VatolMallocDone) + { + N_VDestroy(IDA_mem->ida_Vatol); + IDA_mem->ida_Vatol = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_lrw1; IDA_mem->ida_liw -= IDA_mem->ida_liw1; } - if (IDA_mem->ida_constraintsMallocDone) { + if (IDA_mem->ida_constraintsMallocDone) + { N_VDestroy(IDA_mem->ida_constraints); IDA_mem->ida_constraints = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_lrw1; IDA_mem->ida_liw -= IDA_mem->ida_liw1; } - if (IDA_mem->ida_idMallocDone) { - N_VDestroy(IDA_mem->ida_id); IDA_mem->ida_id = NULL; + if (IDA_mem->ida_idMallocDone) + { + N_VDestroy(IDA_mem->ida_id); + IDA_mem->ida_id = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_lrw1; IDA_mem->ida_liw -= IDA_mem->ida_liw1; } - } /* @@ -3721,26 +4465,26 @@ static void IDAFreeVectors(IDAMem IDA_mem) * IDAQuadReInit. */ -static booleantype IDAQuadAllocVectors(IDAMem IDA_mem, N_Vector tmpl) +static sunbooleantype IDAQuadAllocVectors(IDAMem IDA_mem, N_Vector tmpl) { int i, j; /* Allocate yyQ */ IDA_mem->ida_yyQ = N_VClone(tmpl); - if (IDA_mem->ida_yyQ == NULL) { - return (SUNFALSE); - } + if (IDA_mem->ida_yyQ == NULL) { return (SUNFALSE); } /* Allocate ypQ */ IDA_mem->ida_ypQ = N_VClone(tmpl); - if (IDA_mem->ida_ypQ == NULL) { + if (IDA_mem->ida_ypQ == NULL) + { N_VDestroy(IDA_mem->ida_yyQ); return (SUNFALSE); } /* Allocate ewtQ */ IDA_mem->ida_ewtQ = N_VClone(tmpl); - if (IDA_mem->ida_ewtQ == NULL) { + if (IDA_mem->ida_ewtQ == NULL) + { N_VDestroy(IDA_mem->ida_yyQ); N_VDestroy(IDA_mem->ida_ypQ); return (SUNFALSE); @@ -3748,33 +4492,34 @@ static booleantype IDAQuadAllocVectors(IDAMem IDA_mem, N_Vector tmpl) /* Allocate eeQ */ IDA_mem->ida_eeQ = N_VClone(tmpl); - if (IDA_mem->ida_eeQ == NULL) { + if (IDA_mem->ida_eeQ == NULL) + { N_VDestroy(IDA_mem->ida_yyQ); N_VDestroy(IDA_mem->ida_ypQ); N_VDestroy(IDA_mem->ida_ewtQ); return (SUNFALSE); } - for (j=0; j <= IDA_mem->ida_maxord; j++) { + for (j = 0; j <= IDA_mem->ida_maxord; j++) + { IDA_mem->ida_phiQ[j] = N_VClone(tmpl); - if (IDA_mem->ida_phiQ[j] == NULL) { + if (IDA_mem->ida_phiQ[j] == NULL) + { N_VDestroy(IDA_mem->ida_yyQ); N_VDestroy(IDA_mem->ida_ypQ); N_VDestroy(IDA_mem->ida_ewtQ); N_VDestroy(IDA_mem->ida_eeQ); - for (i=0; i < j; i++) N_VDestroy(IDA_mem->ida_phiQ[i]); - return(SUNFALSE); + for (i = 0; i < j; i++) { N_VDestroy(IDA_mem->ida_phiQ[i]); } + return (SUNFALSE); } } - IDA_mem->ida_lrw += (IDA_mem->ida_maxord+4)*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw += (IDA_mem->ida_maxord+4)*IDA_mem->ida_liw1Q; + IDA_mem->ida_lrw += (IDA_mem->ida_maxord + 4) * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw += (IDA_mem->ida_maxord + 4) * IDA_mem->ida_liw1Q; - return(SUNTRUE); + return (SUNTRUE); } - - /* * IDAQuadFreeVectors * @@ -3785,20 +4530,27 @@ static void IDAQuadFreeVectors(IDAMem IDA_mem) { int j; - N_VDestroy(IDA_mem->ida_yyQ); IDA_mem->ida_yyQ = NULL; - N_VDestroy(IDA_mem->ida_ypQ); IDA_mem->ida_ypQ = NULL; - N_VDestroy(IDA_mem->ida_ewtQ); IDA_mem->ida_ewtQ = NULL; - N_VDestroy(IDA_mem->ida_eeQ); IDA_mem->ida_eeQ = NULL; - for(j=0; j <= IDA_mem->ida_maxord; j++) { + N_VDestroy(IDA_mem->ida_yyQ); + IDA_mem->ida_yyQ = NULL; + N_VDestroy(IDA_mem->ida_ypQ); + IDA_mem->ida_ypQ = NULL; + N_VDestroy(IDA_mem->ida_ewtQ); + IDA_mem->ida_ewtQ = NULL; + N_VDestroy(IDA_mem->ida_eeQ); + IDA_mem->ida_eeQ = NULL; + for (j = 0; j <= IDA_mem->ida_maxord; j++) + { N_VDestroy(IDA_mem->ida_phiQ[j]); IDA_mem->ida_phiQ[j] = NULL; } - IDA_mem->ida_lrw -= (IDA_mem->ida_maxord+5)*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw -= (IDA_mem->ida_maxord+5)*IDA_mem->ida_liw1Q; + IDA_mem->ida_lrw -= (IDA_mem->ida_maxord + 5) * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw -= (IDA_mem->ida_maxord + 5) * IDA_mem->ida_liw1Q; - if (IDA_mem->ida_VatolQMallocDone) { - N_VDestroy(IDA_mem->ida_VatolQ); IDA_mem->ida_VatolQ = NULL; + if (IDA_mem->ida_VatolQMallocDone) + { + N_VDestroy(IDA_mem->ida_VatolQ); + IDA_mem->ida_VatolQ = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_lrw1Q; IDA_mem->ida_liw -= IDA_mem->ida_liw1Q; } @@ -3812,7 +4564,7 @@ static void IDAQuadFreeVectors(IDAMem IDA_mem) * Allocates space for the N_Vectors, plist, and pbar required for FSA. */ -static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) +static sunbooleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) { int j, maxcol; @@ -3822,63 +4574,68 @@ static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) /* Allocate space for workspace vectors */ IDA_mem->ida_tmpS3 = N_VClone(tmpl); - if (IDA_mem->ida_tmpS3==NULL) { - return(SUNFALSE); - } + if (IDA_mem->ida_tmpS3 == NULL) { return (SUNFALSE); } IDA_mem->ida_ewtS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_ewtS==NULL) { + if (IDA_mem->ida_ewtS == NULL) + { N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_eeS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_eeS==NULL) { + if (IDA_mem->ida_eeS == NULL) + { N_VDestroy(IDA_mem->ida_tmpS3); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_yyS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_yyS==NULL) { + if (IDA_mem->ida_yyS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_ypS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_ypS==NULL) { + if (IDA_mem->ida_ypS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_yySpredict = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_yySpredict==NULL) { + if (IDA_mem->ida_yySpredict == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_ypS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_yyS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_ypSpredict = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_ypSpredict==NULL) { + if (IDA_mem->ida_ypSpredict == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yySpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_yyS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_deltaS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_deltaS==NULL) { + if (IDA_mem->ida_deltaS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_ypSpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_yySpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypS, IDA_mem->ida_Ns); @@ -3886,21 +4643,23 @@ static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_tmpS3); - return(SUNFALSE); + return (SUNFALSE); } /* Update solver workspace lengths */ - IDA_mem->ida_lrw += (5*IDA_mem->ida_Ns+1)*IDA_mem->ida_lrw1; - IDA_mem->ida_liw += (5*IDA_mem->ida_Ns+1)*IDA_mem->ida_liw1; + IDA_mem->ida_lrw += (5 * IDA_mem->ida_Ns + 1) * IDA_mem->ida_lrw1; + IDA_mem->ida_liw += (5 * IDA_mem->ida_Ns + 1) * IDA_mem->ida_liw1; /* Allocate space for phiS */ /* Make sure phiS[2], phiS[3] and phiS[4] are allocated (for use as temporary vectors), regardless of maxord.*/ - maxcol = SUNMAX(IDA_mem->ida_maxord,4); - for (j=0; j <= maxcol; j++) { + maxcol = SUNMAX(IDA_mem->ida_maxord, 4); + for (j = 0; j <= maxcol; j++) + { IDA_mem->ida_phiS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_phiS[j] == NULL) { + if (IDA_mem->ida_phiS[j] == NULL) + { N_VDestroy(IDA_mem->ida_tmpS3); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); @@ -3909,19 +4668,20 @@ static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroyVectorArray(IDA_mem->ida_yySpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypSpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_deltaS, IDA_mem->ida_Ns); - return(SUNFALSE); + return (SUNFALSE); } } /* Update solver workspace lengths */ - IDA_mem->ida_lrw += maxcol*IDA_mem->ida_Ns*IDA_mem->ida_lrw1; - IDA_mem->ida_liw += maxcol*IDA_mem->ida_Ns*IDA_mem->ida_liw1; + IDA_mem->ida_lrw += maxcol * IDA_mem->ida_Ns * IDA_mem->ida_lrw1; + IDA_mem->ida_liw += maxcol * IDA_mem->ida_Ns * IDA_mem->ida_liw1; /* Allocate space for pbar and plist */ IDA_mem->ida_pbar = NULL; - IDA_mem->ida_pbar = (realtype *)malloc(IDA_mem->ida_Ns*sizeof(realtype)); - if (IDA_mem->ida_pbar == NULL) { + IDA_mem->ida_pbar = (sunrealtype*)malloc(IDA_mem->ida_Ns * sizeof(sunrealtype)); + if (IDA_mem->ida_pbar == NULL) + { N_VDestroy(IDA_mem->ida_tmpS3); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); @@ -3930,13 +4690,17 @@ static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroyVectorArray(IDA_mem->ida_yySpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypSpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_deltaS, IDA_mem->ida_Ns); - for (j=0; j<=maxcol; j++) N_VDestroyVectorArray(IDA_mem->ida_phiS[j], IDA_mem->ida_Ns); - return(SUNFALSE); + for (j = 0; j <= maxcol; j++) + { + N_VDestroyVectorArray(IDA_mem->ida_phiS[j], IDA_mem->ida_Ns); + } + return (SUNFALSE); } IDA_mem->ida_plist = NULL; - IDA_mem->ida_plist = (int *)malloc(IDA_mem->ida_Ns*sizeof(int)); - if (IDA_mem->ida_plist == NULL) { + IDA_mem->ida_plist = (int*)malloc(IDA_mem->ida_Ns * sizeof(int)); + if (IDA_mem->ida_plist == NULL) + { N_VDestroy(IDA_mem->ida_tmpS3); N_VDestroyVectorArray(IDA_mem->ida_ewtS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeS, IDA_mem->ida_Ns); @@ -3945,16 +4709,20 @@ static booleantype IDASensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) N_VDestroyVectorArray(IDA_mem->ida_yySpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypSpredict, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_deltaS, IDA_mem->ida_Ns); - for (j=0; j<=maxcol; j++) N_VDestroyVectorArray(IDA_mem->ida_phiS[j], IDA_mem->ida_Ns); - free(IDA_mem->ida_pbar); IDA_mem->ida_pbar = NULL; - return(SUNFALSE); + for (j = 0; j <= maxcol; j++) + { + N_VDestroyVectorArray(IDA_mem->ida_phiS[j], IDA_mem->ida_Ns); + } + free(IDA_mem->ida_pbar); + IDA_mem->ida_pbar = NULL; + return (SUNFALSE); } /* Update solver workspace lengths */ IDA_mem->ida_lrw += IDA_mem->ida_Ns; IDA_mem->ida_liw += IDA_mem->ida_Ns; - return(SUNTRUE); + return (SUNTRUE); } /* @@ -3977,29 +4745,37 @@ static void IDASensFreeVectors(IDAMem IDA_mem) N_VDestroy(IDA_mem->ida_tmpS3); maxcol = SUNMAX(IDA_mem->ida_maxord_alloc, 4); - for (j=0; j<=maxcol; j++) + for (j = 0; j <= maxcol; j++) + { N_VDestroyVectorArray(IDA_mem->ida_phiS[j], IDA_mem->ida_Ns); + } - free(IDA_mem->ida_pbar); IDA_mem->ida_pbar = NULL; - free(IDA_mem->ida_plist); IDA_mem->ida_plist = NULL; + free(IDA_mem->ida_pbar); + IDA_mem->ida_pbar = NULL; + free(IDA_mem->ida_plist); + IDA_mem->ida_plist = NULL; - IDA_mem->ida_lrw -= ( (maxcol+3)*IDA_mem->ida_Ns + 1 ) * IDA_mem->ida_lrw1 + IDA_mem->ida_Ns; - IDA_mem->ida_liw -= ( (maxcol+3)*IDA_mem->ida_Ns + 1 ) * IDA_mem->ida_liw1 + IDA_mem->ida_Ns; + IDA_mem->ida_lrw -= ((maxcol + 3) * IDA_mem->ida_Ns + 1) * IDA_mem->ida_lrw1 + + IDA_mem->ida_Ns; + IDA_mem->ida_liw -= ((maxcol + 3) * IDA_mem->ida_Ns + 1) * IDA_mem->ida_liw1 + + IDA_mem->ida_Ns; - if (IDA_mem->ida_VatolSMallocDone) { + if (IDA_mem->ida_VatolSMallocDone) + { N_VDestroyVectorArray(IDA_mem->ida_VatolS, IDA_mem->ida_Ns); - IDA_mem->ida_lrw -= IDA_mem->ida_Ns*IDA_mem->ida_lrw1; - IDA_mem->ida_liw -= IDA_mem->ida_Ns*IDA_mem->ida_liw1; + IDA_mem->ida_lrw -= IDA_mem->ida_Ns * IDA_mem->ida_lrw1; + IDA_mem->ida_liw -= IDA_mem->ida_Ns * IDA_mem->ida_liw1; IDA_mem->ida_VatolSMallocDone = SUNFALSE; } - if (IDA_mem->ida_SatolSMallocDone) { - free(IDA_mem->ida_SatolS); IDA_mem->ida_SatolS = NULL; + if (IDA_mem->ida_SatolSMallocDone) + { + free(IDA_mem->ida_SatolS); + IDA_mem->ida_SatolS = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_Ns; IDA_mem->ida_SatolSMallocDone = SUNFALSE; } } - /* * IDAQuadSensAllocVectors * @@ -4007,71 +4783,76 @@ static void IDASensFreeVectors(IDAMem IDA_mem) * using the N_Vector 'tmpl' as a template. */ -static booleantype IDAQuadSensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) +static sunbooleantype IDAQuadSensAllocVectors(IDAMem IDA_mem, N_Vector tmpl) { int i, j, maxcol; /* Allocate yQS */ IDA_mem->ida_yyQS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_yyQS == NULL) { - return(SUNFALSE); - } + if (IDA_mem->ida_yyQS == NULL) { return (SUNFALSE); } /* Allocate ewtQS */ IDA_mem->ida_ewtQS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_ewtQS == NULL) { + if (IDA_mem->ida_ewtQS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyQS, IDA_mem->ida_Ns); - return(SUNFALSE); + return (SUNFALSE); } /* Allocate tempvQS */ IDA_mem->ida_tempvQS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_tempvQS == NULL) { + if (IDA_mem->ida_tempvQS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtQS, IDA_mem->ida_Ns); - return(SUNFALSE); + return (SUNFALSE); } - IDA_mem->ida_eeQS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_eeQS == NULL) { + IDA_mem->ida_eeQS = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); + if (IDA_mem->ida_eeQS == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_tempvQS, IDA_mem->ida_Ns); - return(SUNFALSE); + return (SUNFALSE); } IDA_mem->ida_savrhsQ = N_VClone(tmpl); - if (IDA_mem->ida_savrhsQ == NULL) { + if (IDA_mem->ida_savrhsQ == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_tempvQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeQS, IDA_mem->ida_Ns); } - maxcol = SUNMAX(IDA_mem->ida_maxord,4); + maxcol = SUNMAX(IDA_mem->ida_maxord, 4); /* Allocate phiQS */ - for (j=0; j<=maxcol; j++) { + for (j = 0; j <= maxcol; j++) + { IDA_mem->ida_phiQS[j] = N_VCloneVectorArray(IDA_mem->ida_Ns, tmpl); - if (IDA_mem->ida_phiQS[j] == NULL) { + if (IDA_mem->ida_phiQS[j] == NULL) + { N_VDestroyVectorArray(IDA_mem->ida_yyQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ewtQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_tempvQS, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_eeQS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_savrhsQ); - for (i=0; iida_phiQS[i], IDA_mem->ida_Ns); - return(SUNFALSE); + } + return (SUNFALSE); } } /* Update solver workspace lengths */ - IDA_mem->ida_lrw += (maxcol + 5)*IDA_mem->ida_Ns*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw += (maxcol + 5)*IDA_mem->ida_Ns*IDA_mem->ida_liw1Q; + IDA_mem->ida_lrw += (maxcol + 5) * IDA_mem->ida_Ns * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw += (maxcol + 5) * IDA_mem->ida_Ns * IDA_mem->ida_liw1Q; - return(SUNTRUE); + return (SUNTRUE); } - /* * IDAQuadSensFreeVectors * @@ -4090,25 +4871,30 @@ static void IDAQuadSensFreeVectors(IDAMem IDA_mem) N_VDestroyVectorArray(IDA_mem->ida_tempvQS, IDA_mem->ida_Ns); N_VDestroy(IDA_mem->ida_savrhsQ); - for (j=0; j<=maxcol; j++) N_VDestroyVectorArray(IDA_mem->ida_phiQS[j], IDA_mem->ida_Ns); + for (j = 0; j <= maxcol; j++) + { + N_VDestroyVectorArray(IDA_mem->ida_phiQS[j], IDA_mem->ida_Ns); + } - IDA_mem->ida_lrw -= (maxcol + 5)*IDA_mem->ida_Ns*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw -= (maxcol + 5)*IDA_mem->ida_Ns*IDA_mem->ida_liw1Q; + IDA_mem->ida_lrw -= (maxcol + 5) * IDA_mem->ida_Ns * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw -= (maxcol + 5) * IDA_mem->ida_Ns * IDA_mem->ida_liw1Q; - if (IDA_mem->ida_VatolQSMallocDone) { + if (IDA_mem->ida_VatolQSMallocDone) + { N_VDestroyVectorArray(IDA_mem->ida_VatolQS, IDA_mem->ida_Ns); - IDA_mem->ida_lrw -= IDA_mem->ida_Ns*IDA_mem->ida_lrw1Q; - IDA_mem->ida_liw -= IDA_mem->ida_Ns*IDA_mem->ida_liw1Q; + IDA_mem->ida_lrw -= IDA_mem->ida_Ns * IDA_mem->ida_lrw1Q; + IDA_mem->ida_liw -= IDA_mem->ida_Ns * IDA_mem->ida_liw1Q; } - if (IDA_mem->ida_SatolQSMallocDone) { - free(IDA_mem->ida_SatolQS); IDA_mem->ida_SatolQS = NULL; + if (IDA_mem->ida_SatolQSMallocDone) + { + free(IDA_mem->ida_SatolQS); + IDA_mem->ida_SatolQS = NULL; IDA_mem->ida_lrw -= IDA_mem->ida_Ns; } IDA_mem->ida_VatolQSMallocDone = SUNFALSE; IDA_mem->ida_SatolQSMallocDone = SUNFALSE; } - /* * ----------------------------------------------------------------- * Initial setup @@ -4129,107 +4915,123 @@ static void IDAQuadSensFreeVectors(IDAMem IDA_mem) int IDAInitialSetup(IDAMem IDA_mem) { - booleantype conOK; + sunbooleantype conOK; int ier; /* Test for more vector operations, depending on options */ if (IDA_mem->ida_suppressalg) - if (IDA_mem->ida_phi[0]->ops->nvwrmsnormmask == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + { + if (IDA_mem->ida_phi[0]->ops->nvwrmsnormmask == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_NVECTOR); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); + } } /* Test id vector for legality */ - if (IDA_mem->ida_suppressalg && (IDA_mem->ida_id==NULL)){ - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_suppressalg && (IDA_mem->ida_id == NULL)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_MISSING_ID); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Did the user specify tolerances? */ - if (IDA_mem->ida_itol == IDA_NN) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_itol == IDA_NN) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_TOLS); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Set data for efun */ - if (IDA_mem->ida_user_efun) IDA_mem->ida_edata = IDA_mem->ida_user_data; - else IDA_mem->ida_edata = IDA_mem; + if (IDA_mem->ida_user_efun) { IDA_mem->ida_edata = IDA_mem->ida_user_data; } + else { IDA_mem->ida_edata = IDA_mem; } /* Initial error weight vector */ - ier = IDA_mem->ida_efun(IDA_mem->ida_phi[0], IDA_mem->ida_ewt, IDA_mem->ida_edata); - if (ier != 0) { + ier = IDA_mem->ida_efun(IDA_mem->ida_phi[0], IDA_mem->ida_ewt, + IDA_mem->ida_edata); + if (ier != 0) + { if (IDA_mem->ida_itol == IDA_WF) - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_FAIL_EWT); + } else - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_EWT); - return(IDA_ILL_INPUT); + } + return (IDA_ILL_INPUT); } - if (IDA_mem->ida_quadr) { - + if (IDA_mem->ida_quadr) + { /* Evaluate quadrature rhs and set phiQ[1] */ ier = IDA_mem->ida_rhsQ(IDA_mem->ida_tn, IDA_mem->ida_phi[0], IDA_mem->ida_phi[1], IDA_mem->ida_phiQ[1], IDA_mem->ida_user_data); IDA_mem->ida_nrQe++; - if (ier < 0) { - IDAProcessError(IDA_mem, IDA_QRHS_FAIL, "IDAS", "IDAInitialSetup", + if (ier < 0) + { + IDAProcessError(IDA_mem, IDA_QRHS_FAIL, __LINE__, __func__, __FILE__, MSG_QRHSFUNC_FAILED); - return(IDA_QRHS_FAIL); - } else if (ier > 0) { - IDAProcessError(IDA_mem, IDA_FIRST_QRHS_ERR, "IDAS", "IDAInitialSetup", + return (IDA_QRHS_FAIL); + } + else if (ier > 0) + { + IDAProcessError(IDA_mem, IDA_FIRST_QRHS_ERR, __LINE__, __func__, __FILE__, MSG_QRHSFUNC_FIRST); - return(IDA_FIRST_QRHS_ERR); + return (IDA_FIRST_QRHS_ERR); } - if (IDA_mem->ida_errconQ) { - + if (IDA_mem->ida_errconQ) + { /* Did the user specify tolerances? */ - if (IDA_mem->ida_itolQ == IDA_NN) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_itolQ == IDA_NN) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_TOLQ); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Load ewtQ */ ier = IDAQuadEwtSet(IDA_mem, IDA_mem->ida_phiQ[0], IDA_mem->ida_ewtQ); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_EWTQ); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } - } else { - IDA_mem->ida_errconQ = SUNFALSE; } + else { IDA_mem->ida_errconQ = SUNFALSE; } - if (IDA_mem->ida_sensi) { - + if (IDA_mem->ida_sensi) + { /* Did the user specify tolerances? */ - if (IDA_mem->ida_itolS == IDA_NN) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_itolS == IDA_NN) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_TOLS); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Load ewtS */ ier = IDASensEwtSet(IDA_mem, IDA_mem->ida_phiS[0], IDA_mem->ida_ewtS); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_EWTS); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } - } else { - IDA_mem->ida_errconS = SUNFALSE; } + else { IDA_mem->ida_errconS = SUNFALSE; } - if (IDA_mem->ida_quadr_sensi) { - + if (IDA_mem->ida_quadr_sensi) + { /* store the quadrature sensitivity residual. */ ier = IDA_mem->ida_rhsQS(IDA_mem->ida_Ns, IDA_mem->ida_tn, IDA_mem->ida_phi[0], IDA_mem->ida_phi[1], @@ -4238,87 +5040,100 @@ int IDAInitialSetup(IDAMem IDA_mem) IDA_mem->ida_user_dataQS, IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrQSe++; - if (ier < 0) { - IDAProcessError(IDA_mem, IDA_QSRHS_FAIL, "IDAS", "IDAInitialSetup", + if (ier < 0) + { + IDAProcessError(IDA_mem, IDA_QSRHS_FAIL, __LINE__, __func__, __FILE__, MSG_QSRHSFUNC_FAILED); - return(IDA_QRHS_FAIL); - } else if (ier > 0) { - IDAProcessError(IDA_mem, IDA_FIRST_QSRHS_ERR, "IDAS", "IDAInitialSetup", - MSG_QSRHSFUNC_FIRST); - return(IDA_FIRST_QSRHS_ERR); + return (IDA_QRHS_FAIL); + } + else if (ier > 0) + { + IDAProcessError(IDA_mem, IDA_FIRST_QSRHS_ERR, __LINE__, __func__, + __FILE__, MSG_QSRHSFUNC_FIRST); + return (IDA_FIRST_QSRHS_ERR); } /* If using the internal DQ functions, we must have access to fQ * (i.e. quadrature integration must be enabled) and to the problem parameters */ - if (IDA_mem->ida_rhsQSDQ) { - + if (IDA_mem->ida_rhsQSDQ) + { /* Test if quadratures are defined, so we can use fQ */ - if (!IDA_mem->ida_quadr) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (!IDA_mem->ida_quadr) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NULL_RHSQ); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Test if we have the problem parameters */ - if (IDA_mem->ida_p == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_p == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NULL_P); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } - if (IDA_mem->ida_errconQS) { + if (IDA_mem->ida_errconQS) + { /* Did the user specify tolerances? */ - if (IDA_mem->ida_itolQS == IDA_NN) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_itolQS == IDA_NN) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_TOLQS); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* If needed, did the user provide quadrature tolerances? */ - if ( (IDA_mem->ida_itolQS == IDA_EE) && (IDA_mem->ida_itolQ == IDA_NN) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if ((IDA_mem->ida_itolQS == IDA_EE) && (IDA_mem->ida_itolQ == IDA_NN)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_TOLQ); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Load ewtS */ ier = IDAQuadSensEwtSet(IDA_mem, IDA_mem->ida_phiQS[0], IDA_mem->ida_ewtQS); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_EWTQS); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } - } else { - IDA_mem->ida_errconQS = SUNFALSE; } + else { IDA_mem->ida_errconQS = SUNFALSE; } /* Check to see if y0 satisfies constraints. */ - if (IDA_mem->ida_constraintsSet) { - - if (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + if (IDA_mem->ida_constraintsSet) + { + if (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_ISM_CONSTR); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } - conOK = N_VConstrMask(IDA_mem->ida_constraints, IDA_mem->ida_phi[0], IDA_mem->ida_tempv2); - if (!conOK) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAInitialSetup", + conOK = N_VConstrMask(IDA_mem->ida_constraints, IDA_mem->ida_phi[0], + IDA_mem->ida_tempv2); + if (!conOK) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_Y0_FAIL_CONSTR); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } } /* Call linit function if it exists. */ - if (IDA_mem->ida_linit != NULL) { + if (IDA_mem->ida_linit != NULL) + { ier = IDA_mem->ida_linit(IDA_mem); - if (ier != 0) { - IDAProcessError(IDA_mem, IDA_LINIT_FAIL, "IDAS", "IDAInitialSetup", + if (ier != 0) + { + IDAProcessError(IDA_mem, IDA_LINIT_FAIL, __LINE__, __func__, __FILE__, MSG_LINIT_FAIL); - return(IDA_LINIT_FAIL); + return (IDA_LINIT_FAIL); } } @@ -4327,31 +5142,36 @@ int IDAInitialSetup(IDAMem IDA_mem) /* always initialize the DAE NLS in case the user disables sensitivities later */ ier = idaNlsInit(IDA_mem); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, "IDAS", "IDAInitialSetup", + if (ier != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } - if (IDA_mem->NLSsim != NULL) { + if (IDA_mem->NLSsim != NULL) + { ier = idaNlsInitSensSim(IDA_mem); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, "IDAS", "IDAInitialSetup", + if (ier != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } } - if (IDA_mem->NLSstg != NULL) { + if (IDA_mem->NLSstg != NULL) + { ier = idaNlsInitSensStg(IDA_mem); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, "IDAS", "IDAInitialSetup", + if (ier != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_NLS_INIT_FAIL, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -4371,24 +5191,21 @@ int IDAInitialSetup(IDAMem IDA_mem) * All the real work is done in the routines IDAEwtSetSS, IDAEwtSetSV. */ -int IDAEwtSet(N_Vector ycur, N_Vector weight, void *data) +int IDAEwtSet(N_Vector ycur, N_Vector weight, void* data) { IDAMem IDA_mem; int flag = 0; /* data points to IDA_mem here */ - IDA_mem = (IDAMem) data; + IDA_mem = (IDAMem)data; - switch(IDA_mem->ida_itol) { - case IDA_SS: - flag = IDAEwtSetSS(IDA_mem, ycur, weight); - break; - case IDA_SV: - flag = IDAEwtSetSV(IDA_mem, ycur, weight); - break; + switch (IDA_mem->ida_itol) + { + case IDA_SS: flag = IDAEwtSetSS(IDA_mem, ycur, weight); break; + case IDA_SV: flag = IDAEwtSetSV(IDA_mem, ycur, weight); break; } - return(flag); + return (flag); } /* @@ -4406,11 +5223,12 @@ static int IDAEwtSetSS(IDAMem IDA_mem, N_Vector ycur, N_Vector weight) N_VAbs(ycur, IDA_mem->ida_tempv1); N_VScale(IDA_mem->ida_rtol, IDA_mem->ida_tempv1, IDA_mem->ida_tempv1); N_VAddConst(IDA_mem->ida_tempv1, IDA_mem->ida_Satol, IDA_mem->ida_tempv1); - if (IDA_mem->ida_atolmin0) { - if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) return(-1); + if (IDA_mem->ida_atolmin0) + { + if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) { return (-1); } } N_VInv(IDA_mem->ida_tempv1, weight); - return(0); + return (0); } /* @@ -4426,13 +5244,14 @@ static int IDAEwtSetSS(IDAMem IDA_mem, N_Vector ycur, N_Vector weight) static int IDAEwtSetSV(IDAMem IDA_mem, N_Vector ycur, N_Vector weight) { N_VAbs(ycur, IDA_mem->ida_tempv1); - N_VLinearSum(IDA_mem->ida_rtol, IDA_mem->ida_tempv1, - ONE, IDA_mem->ida_Vatol, IDA_mem->ida_tempv1); - if (IDA_mem->ida_atolmin0) { - if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) return(-1); + N_VLinearSum(IDA_mem->ida_rtol, IDA_mem->ida_tempv1, ONE, IDA_mem->ida_Vatol, + IDA_mem->ida_tempv1); + if (IDA_mem->ida_atolmin0) + { + if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) { return (-1); } } N_VInv(IDA_mem->ida_tempv1, weight); - return(0); + return (0); } /* @@ -4442,19 +5261,15 @@ static int IDAEwtSetSV(IDAMem IDA_mem, N_Vector ycur, N_Vector weight) static int IDAQuadEwtSet(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ) { - int flag=0; + int flag = 0; - switch (IDA_mem->ida_itolQ) { - case IDA_SS: - flag = IDAQuadEwtSetSS(IDA_mem, qcur, weightQ); - break; - case IDA_SV: - flag = IDAQuadEwtSetSV(IDA_mem, qcur, weightQ); - break; + switch (IDA_mem->ida_itolQ) + { + case IDA_SS: flag = IDAQuadEwtSetSS(IDA_mem, qcur, weightQ); break; + case IDA_SV: flag = IDAQuadEwtSetSV(IDA_mem, qcur, weightQ); break; } - return(flag); - + return (flag); } /* @@ -4472,12 +5287,13 @@ static int IDAQuadEwtSetSS(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ) N_VAbs(qcur, tempvQ); N_VScale(IDA_mem->ida_rtolQ, tempvQ, tempvQ); N_VAddConst(tempvQ, IDA_mem->ida_SatolQ, tempvQ); - if (IDA_mem->ida_atolQmin0) { - if (N_VMin(tempvQ) <= ZERO) return(-1); + if (IDA_mem->ida_atolQmin0) + { + if (N_VMin(tempvQ) <= ZERO) { return (-1); } } N_VInv(tempvQ, weightQ); - return(0); + return (0); } /* @@ -4494,12 +5310,13 @@ static int IDAQuadEwtSetSV(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ) N_VAbs(qcur, tempvQ); N_VLinearSum(IDA_mem->ida_rtolQ, tempvQ, ONE, IDA_mem->ida_VatolQ, tempvQ); - if (IDA_mem->ida_atolQmin0) { - if (N_VMin(tempvQ) <= ZERO) return(-1); + if (IDA_mem->ida_atolQmin0) + { + if (N_VMin(tempvQ) <= ZERO) { return (-1); } } N_VInv(tempvQ, weightQ); - return(0); + return (0); } /* @@ -4507,24 +5324,18 @@ static int IDAQuadEwtSetSV(IDAMem IDA_mem, N_Vector qcur, N_Vector weightQ) * */ -int IDASensEwtSet(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) +int IDASensEwtSet(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS) { - int flag=0; + int flag = 0; - switch (IDA_mem->ida_itolS) { - case IDA_EE: - flag = IDASensEwtSetEE(IDA_mem, yScur, weightS); - break; - case IDA_SS: - flag = IDASensEwtSetSS(IDA_mem, yScur, weightS); - break; - case IDA_SV: - flag = IDASensEwtSetSV(IDA_mem, yScur, weightS); - break; + switch (IDA_mem->ida_itolS) + { + case IDA_EE: flag = IDASensEwtSetEE(IDA_mem, yScur, weightS); break; + case IDA_SS: flag = IDASensEwtSetSS(IDA_mem, yScur, weightS); break; + case IDA_SV: flag = IDASensEwtSetSV(IDA_mem, yScur, weightS); break; } - return(flag); - + return (flag); } /* @@ -4539,7 +5350,7 @@ int IDASensEwtSet(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) +static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS) { int is; N_Vector pyS; @@ -4548,14 +5359,15 @@ static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) /* Use tempv1 as temporary storage for the scaled sensitivity */ pyS = IDA_mem->ida_tempv1; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(IDA_mem->ida_pbar[is], yScur[is], pyS); flag = IDA_mem->ida_efun(pyS, weightS[is], IDA_mem->ida_edata); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } N_VScale(IDA_mem->ida_pbar[is], weightS[is], weightS[is]); } - return(0); + return (0); } /* @@ -4563,20 +5375,23 @@ static int IDASensEwtSetEE(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int IDASensEwtSetSS(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) +static int IDASensEwtSetSS(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS) { int is; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VAbs(yScur[is], IDA_mem->ida_tempv1); N_VScale(IDA_mem->ida_rtolS, IDA_mem->ida_tempv1, IDA_mem->ida_tempv1); - N_VAddConst(IDA_mem->ida_tempv1, IDA_mem->ida_SatolS[is], IDA_mem->ida_tempv1); - if (IDA_mem->ida_atolSmin0[is]) { - if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) return(-1); + N_VAddConst(IDA_mem->ida_tempv1, IDA_mem->ida_SatolS[is], + IDA_mem->ida_tempv1); + if (IDA_mem->ida_atolSmin0[is]) + { + if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) { return (-1); } } N_VInv(IDA_mem->ida_tempv1, weightS[is]); } - return(0); + return (0); } /* @@ -4584,20 +5399,23 @@ static int IDASensEwtSetSS(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) * */ -static int IDASensEwtSetSV(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) +static int IDASensEwtSetSV(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS) { int is; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VAbs(yScur[is], IDA_mem->ida_tempv1); - N_VLinearSum(IDA_mem->ida_rtolS, IDA_mem->ida_tempv1, ONE, IDA_mem->ida_VatolS[is], IDA_mem->ida_tempv1); - if (IDA_mem->ida_atolSmin0[is]) { - if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) return(-1); + N_VLinearSum(IDA_mem->ida_rtolS, IDA_mem->ida_tempv1, ONE, + IDA_mem->ida_VatolS[is], IDA_mem->ida_tempv1); + if (IDA_mem->ida_atolSmin0[is]) + { + if (N_VMin(IDA_mem->ida_tempv1) <= ZERO) { return (-1); } } N_VInv(IDA_mem->ida_tempv1, weightS[is]); } - return(0); + return (0); } /* @@ -4605,23 +5423,18 @@ static int IDASensEwtSetSV(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS) * */ -int IDAQuadSensEwtSet(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS) +int IDAQuadSensEwtSet(IDAMem IDA_mem, N_Vector* yQScur, N_Vector* weightQS) { - int flag=0; + int flag = 0; - switch (IDA_mem->ida_itolQS) { - case IDA_EE: - flag = IDAQuadSensEwtSetEE(IDA_mem, yQScur, weightQS); - break; - case IDA_SS: - flag = IDAQuadSensEwtSetSS(IDA_mem, yQScur, weightQS); - break; - case IDA_SV: - flag = IDAQuadSensEwtSetSV(IDA_mem, yQScur, weightQS); - break; + switch (IDA_mem->ida_itolQS) + { + case IDA_EE: flag = IDAQuadSensEwtSetEE(IDA_mem, yQScur, weightQS); break; + case IDA_SS: flag = IDAQuadSensEwtSetSS(IDA_mem, yQScur, weightQS); break; + case IDA_SV: flag = IDAQuadSensEwtSetSV(IDA_mem, yQScur, weightQS); break; } - return(flag); + return (flag); } /* @@ -4636,7 +5449,8 @@ int IDAQuadSensEwtSet(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS) * weight vector calculation as the quadrature vector. * */ -static int IDAQuadSensEwtSetEE(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS) +static int IDAQuadSensEwtSetEE(IDAMem IDA_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; N_Vector pyS; @@ -4645,17 +5459,19 @@ static int IDAQuadSensEwtSetEE(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weigh /* Use tempvQS[0] as temporary storage for the scaled sensitivity */ pyS = IDA_mem->ida_tempvQS[0]; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(IDA_mem->ida_pbar[is], yQScur[is], pyS); flag = IDAQuadEwtSet(IDA_mem, pyS, weightQS[is]); - if (flag != 0) return(-1); + if (flag != 0) { return (-1); } N_VScale(IDA_mem->ida_pbar[is], weightQS[is], weightQS[is]); } - return(0); + return (0); } -static int IDAQuadSensEwtSetSS(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS) +static int IDAQuadSensEwtSetSS(IDAMem IDA_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; N_Vector tempvQ; @@ -4663,20 +5479,23 @@ static int IDAQuadSensEwtSetSS(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weigh /* Use ypQ as temporary storage */ tempvQ = IDA_mem->ida_ypQ; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VAbs(yQScur[is], tempvQ); N_VScale(IDA_mem->ida_rtolQS, tempvQ, tempvQ); N_VAddConst(tempvQ, IDA_mem->ida_SatolQS[is], tempvQ); - if (IDA_mem->ida_atolQSmin0[is]) { - if (N_VMin(tempvQ) <= ZERO) return(-1); + if (IDA_mem->ida_atolQSmin0[is]) + { + if (N_VMin(tempvQ) <= ZERO) { return (-1); } } N_VInv(tempvQ, weightQS[is]); } - return(0); + return (0); } -static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weightQS) +static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector* yQScur, + N_Vector* weightQS) { int is; N_Vector tempvQ; @@ -4684,16 +5503,19 @@ static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weigh /* Use ypQ as temporary storage */ tempvQ = IDA_mem->ida_ypQ; - for (is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VAbs(yQScur[is], tempvQ); - N_VLinearSum(IDA_mem->ida_rtolQS, tempvQ, ONE, IDA_mem->ida_VatolQS[is], tempvQ); - if (IDA_mem->ida_atolQSmin0[is]) { - if (N_VMin(tempvQ) <= ZERO) return(-1); + N_VLinearSum(IDA_mem->ida_rtolQS, tempvQ, ONE, IDA_mem->ida_VatolQS[is], + tempvQ); + if (IDA_mem->ida_atolQSmin0[is]) + { + if (N_VMin(tempvQ) <= ZERO) { return (-1); } } N_VInv(tempvQ, weightQS[is]); } - return(0); + return (0); } /* @@ -4719,98 +5541,92 @@ static int IDAQuadSensEwtSetSV(IDAMem IDA_mem, N_Vector *yQScur, N_Vector *weigh * the next step to reach tstop exactly. */ -static int IDAStopTest1(IDAMem IDA_mem, realtype tout, realtype *tret, +static int IDAStopTest1(IDAMem IDA_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, N_Vector ypret, int itask) { int ier; - realtype troundoff; - - switch (itask) { + sunrealtype troundoff; + + if (IDA_mem->ida_tstopset) + { + /* Test for tn past tstop */ + if ((IDA_mem->ida_tn - IDA_mem->ida_tstop) * IDA_mem->ida_hh > ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); + return (IDA_ILL_INPUT); + } - case IDA_NORMAL: + troundoff = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (IDA_mem->ida_tstopset) { - /* Test for tn past tstop, tn = tretlast, tn past tout, tn near tstop. */ - if ( (IDA_mem->ida_tn - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", - MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); + /* Test for tn at tstop */ + if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) + { + /* Ensure tout >= tstop, otherwise check for tout return below */ + if ((tout - IDA_mem->ida_tstop) * IDA_mem->ida_hh >= ZERO || + SUNRabs(tout - IDA_mem->ida_tstop) <= troundoff) + { + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); + if (ier != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); + return (IDA_ILL_INPUT); + } + *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; + IDA_mem->ida_tstopset = SUNFALSE; + return (IDA_TSTOP_RETURN); } } + /* Test for tn approaching tstop */ + else if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop) * + IDA_mem->ida_hh > + ZERO) + { + IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn) * + (ONE - FOUR * IDA_mem->ida_uround); + } + } + + switch (itask) + { + case IDA_NORMAL: /* Test for tout = tretlast, and for tn past tout. */ - if (tout == IDA_mem->ida_tretlast) { + if (tout == IDA_mem->ida_tretlast) + { *tret = IDA_mem->ida_tretlast = tout; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - if ((IDA_mem->ida_tn - tout)*IDA_mem->ida_hh >= ZERO) { + if ((IDA_mem->ida_tn - tout) * IDA_mem->ida_hh >= ZERO) + { ier = IDAGetSolution(IDA_mem, tout, yret, ypret); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_BAD_TOUT, tout); - return(IDA_ILL_INPUT); + if (ier != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_TOUT, tout); + return (IDA_ILL_INPUT); } *tret = IDA_mem->ida_tretlast = tout; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - if (IDA_mem->ida_tstopset) { - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) { - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", - MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); - } - *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; - IDA_mem->ida_tstopset = SUNFALSE; - return(IDA_TSTOP_RETURN); - } - if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) - IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn)*(ONE - FOUR * IDA_mem->ida_uround); - } - - return(CONTINUE_STEPS); + return (CONTINUE_STEPS); case IDA_ONE_STEP: - if (IDA_mem->ida_tstopset) { - /* Test for tn past tstop, tn past tretlast, and tn near tstop. */ - if ((IDA_mem->ida_tn - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", - MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); - } - } - /* Test for tn past tretlast. */ - if ((IDA_mem->ida_tn - IDA_mem->ida_tretlast)*IDA_mem->ida_hh > ZERO) { - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + if ((IDA_mem->ida_tn - IDA_mem->ida_tretlast) * IDA_mem->ida_hh > ZERO) + { + ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - if (IDA_mem->ida_tstopset) { - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) { - ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); - if (ier != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", - MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); - } - *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; - IDA_mem->ida_tstopset = SUNFALSE; - return(IDA_TSTOP_RETURN); - } - if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) - IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn)*(ONE - FOUR * IDA_mem->ida_uround); - } - - return(CONTINUE_STEPS); - + return (CONTINUE_STEPS); } - return(IDA_ILL_INPUT); /* This return should never happen. */ + return (IDA_ILL_INPUT); /* This return should never happen. */ } /* @@ -4835,58 +5651,60 @@ static int IDAStopTest1(IDAMem IDA_mem, realtype tout, realtype *tret, * because the same test was made prior to the step. */ -static int IDAStopTest2(IDAMem IDA_mem, realtype tout, realtype *tret, +static int IDAStopTest2(IDAMem IDA_mem, sunrealtype tout, sunrealtype* tret, N_Vector yret, N_Vector ypret, int itask) { /* int ier; */ - realtype troundoff; - - switch (itask) { - - case IDA_NORMAL: - - /* Test for tn past tout. */ - if ((IDA_mem->ida_tn - tout)*IDA_mem->ida_hh >= ZERO) { - /* ier = */ IDAGetSolution(IDA_mem, tout, yret, ypret); - *tret = IDA_mem->ida_tretlast = tout; - return(IDA_SUCCESS); - } - - if (IDA_mem->ida_tstopset) { - /* Test for tn at tstop and for tn near tstop */ - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) { - /* ier = */ IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); - *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; - IDA_mem->ida_tstopset = SUNFALSE; - return(IDA_TSTOP_RETURN); - } - if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) - IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn)*(ONE - FOUR * IDA_mem->ida_uround); + sunrealtype troundoff; + + if (IDA_mem->ida_tstopset) + { + troundoff = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + + /* Test for tn at tstop */ + if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) + { + /* Ensure tout >= tstop, otherwise check for tout return below */ + if ((tout - IDA_mem->ida_tstop) * IDA_mem->ida_hh >= ZERO || + SUNRabs(tout - IDA_mem->ida_tstop) <= troundoff) + { + /* ier = */ IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); + *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; + IDA_mem->ida_tstopset = SUNFALSE; + return (IDA_TSTOP_RETURN); } + } + /* Test for tn approaching tstop */ + else if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop) * + IDA_mem->ida_hh > + ZERO) + { + IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn) * + (ONE - FOUR * IDA_mem->ida_uround); + } + } - return(CONTINUE_STEPS); + switch (itask) + { + case IDA_NORMAL: - case IDA_ONE_STEP: + /* Test for tn past tout. */ + if ((IDA_mem->ida_tn - tout) * IDA_mem->ida_hh >= ZERO) + { + /* ier = */ IDAGetSolution(IDA_mem, tout, yret, ypret); + *tret = IDA_mem->ida_tretlast = tout; + return (IDA_SUCCESS); + } - if (IDA_mem->ida_tstopset) { - /* Test for tn at tstop and for tn near tstop */ - troundoff = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (SUNRabs(IDA_mem->ida_tn - IDA_mem->ida_tstop) <= troundoff) { - /* ier = */ IDAGetSolution(IDA_mem, IDA_mem->ida_tstop, yret, ypret); - *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tstop; - IDA_mem->ida_tstopset = SUNFALSE; - return(IDA_TSTOP_RETURN); - } - if ((IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) - IDA_mem->ida_hh = (IDA_mem->ida_tstop - IDA_mem->ida_tn)*(ONE - FOUR * IDA_mem->ida_uround); - } + return (CONTINUE_STEPS); - *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; - return(IDA_SUCCESS); + case IDA_ONE_STEP: + *tret = IDA_mem->ida_tretlast = IDA_mem->ida_tn; + return (IDA_SUCCESS); } - return IDA_ILL_INPUT; /* This return should never happen. */ + return IDA_ILL_INPUT; /* This return should never happen. */ } /* @@ -4906,96 +5724,96 @@ static int IDAStopTest2(IDAMem IDA_mem, realtype tout, realtype *tret, static int IDAHandleFailure(IDAMem IDA_mem, int sflag) { /* Depending on sflag, print error message and return error flag */ - switch (sflag) { - - case IDA_ERR_FAIL: - IDAProcessError(IDA_mem, IDA_ERR_FAIL, "IDAS", "IDASolve", - MSG_ERR_FAILS, IDA_mem->ida_tn, IDA_mem->ida_hh); - return(IDA_ERR_FAIL); - - case IDA_CONV_FAIL: - IDAProcessError(IDA_mem, IDA_CONV_FAIL, "IDAS", "IDASolve", - MSG_CONV_FAILS, IDA_mem->ida_tn, IDA_mem->ida_hh); - return(IDA_CONV_FAIL); - - case IDA_LSETUP_FAIL: - IDAProcessError(IDA_mem, IDA_LSETUP_FAIL, "IDAS", "IDASolve", - MSG_SETUP_FAILED, IDA_mem->ida_tn); - return(IDA_LSETUP_FAIL); - - case IDA_LSOLVE_FAIL: - IDAProcessError(IDA_mem, IDA_LSOLVE_FAIL, "IDAS", "IDASolve", - MSG_SOLVE_FAILED, IDA_mem->ida_tn); - return(IDA_LSOLVE_FAIL); - - case IDA_REP_RES_ERR: - IDAProcessError(IDA_mem, IDA_REP_RES_ERR, "IDAS", "IDASolve", - MSG_REP_RES_ERR, IDA_mem->ida_tn); - return(IDA_REP_RES_ERR); - - case IDA_RES_FAIL: - IDAProcessError(IDA_mem, IDA_RES_FAIL, "IDAS", "IDASolve", - MSG_RES_NONRECOV, IDA_mem->ida_tn); - return(IDA_RES_FAIL); - - case IDA_REP_QRHS_ERR: - IDAProcessError(IDA_mem, IDA_REP_QRHS_ERR, "IDAS", "IDASolve", - MSG_QRHSFUNC_REPTD, IDA_mem->ida_tn); - return(IDA_REP_QRHS_ERR); - - case IDA_QRHS_FAIL: - IDAProcessError(IDA_mem, IDA_QRHS_FAIL, "IDAS", "IDASolve", - MSG_QRHSFUNC_FAILED, IDA_mem->ida_tn); - return(IDA_QRHS_FAIL); - - case IDA_REP_SRES_ERR: - IDAProcessError(IDA_mem, IDA_REP_SRES_ERR, "IDAS", "IDASolve", - MSG_SRES_REPTD, IDA_mem->ida_tn); - return(IDA_REP_SRES_ERR); - - case IDA_SRES_FAIL: - IDAProcessError(IDA_mem, IDA_SRES_FAIL, "IDAS", "IDASolve", - MSG_SRES_FAILED, IDA_mem->ida_tn); - return(IDA_SRES_FAIL); - - case IDA_REP_QSRHS_ERR: - IDAProcessError(IDA_mem, IDA_REP_QSRHS_ERR, "IDAS", "IDASolve", - MSG_QSRHSFUNC_REPTD, IDA_mem->ida_tn); - return(IDA_REP_QSRHS_ERR); - - case IDA_QSRHS_FAIL: - IDAProcessError(IDA_mem, IDA_QSRHS_FAIL, "IDAS", "IDASolve", - MSG_QSRHSFUNC_FAILED, IDA_mem->ida_tn); - return(IDA_QSRHS_FAIL); - - case IDA_CONSTR_FAIL: - IDAProcessError(IDA_mem, IDA_CONSTR_FAIL, "IDAS", "IDASolve", - MSG_FAILED_CONSTR, IDA_mem->ida_tn); - return(IDA_CONSTR_FAIL); - - case IDA_MEM_NULL: - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASolve", - MSG_NO_MEM); - return(IDA_MEM_NULL); - - case SUN_NLS_MEM_NULL: - IDAProcessError(IDA_mem, IDA_MEM_NULL, "IDAS", "IDASolve", - MSG_NLS_INPUT_NULL, IDA_mem->ida_tn); - return(IDA_MEM_NULL); - - case IDA_NLS_SETUP_FAIL: - IDAProcessError(IDA_mem, IDA_NLS_SETUP_FAIL, "IDAS", "IDASolve", - MSG_NLS_SETUP_FAILED, IDA_mem->ida_tn); - return(IDA_NLS_SETUP_FAIL); - case IDA_NLS_FAIL: - IDAProcessError(IDA_mem, IDA_NLS_FAIL, "IDA", "IDASolve", - MSG_NLS_FAIL, IDA_mem->ida_tn); - return(IDA_NLS_FAIL); + switch (sflag) + { + case IDA_ERR_FAIL: + IDAProcessError(IDA_mem, IDA_ERR_FAIL, __LINE__, __func__, __FILE__, + MSG_ERR_FAILS, IDA_mem->ida_tn, IDA_mem->ida_hh); + return (IDA_ERR_FAIL); + + case IDA_CONV_FAIL: + IDAProcessError(IDA_mem, IDA_CONV_FAIL, __LINE__, __func__, __FILE__, + MSG_CONV_FAILS, IDA_mem->ida_tn, IDA_mem->ida_hh); + return (IDA_CONV_FAIL); + + case IDA_LSETUP_FAIL: + IDAProcessError(IDA_mem, IDA_LSETUP_FAIL, __LINE__, __func__, __FILE__, + MSG_SETUP_FAILED, IDA_mem->ida_tn); + return (IDA_LSETUP_FAIL); + + case IDA_LSOLVE_FAIL: + IDAProcessError(IDA_mem, IDA_LSOLVE_FAIL, __LINE__, __func__, __FILE__, + MSG_SOLVE_FAILED, IDA_mem->ida_tn); + return (IDA_LSOLVE_FAIL); + + case IDA_REP_RES_ERR: + IDAProcessError(IDA_mem, IDA_REP_RES_ERR, __LINE__, __func__, __FILE__, + MSG_REP_RES_ERR, IDA_mem->ida_tn); + return (IDA_REP_RES_ERR); + + case IDA_RES_FAIL: + IDAProcessError(IDA_mem, IDA_RES_FAIL, __LINE__, __func__, __FILE__, + MSG_RES_NONRECOV, IDA_mem->ida_tn); + return (IDA_RES_FAIL); + + case IDA_REP_QRHS_ERR: + IDAProcessError(IDA_mem, IDA_REP_QRHS_ERR, __LINE__, __func__, __FILE__, + MSG_QRHSFUNC_REPTD, IDA_mem->ida_tn); + return (IDA_REP_QRHS_ERR); + + case IDA_QRHS_FAIL: + IDAProcessError(IDA_mem, IDA_QRHS_FAIL, __LINE__, __func__, __FILE__, + MSG_QRHSFUNC_FAILED, IDA_mem->ida_tn); + return (IDA_QRHS_FAIL); + + case IDA_REP_SRES_ERR: + IDAProcessError(IDA_mem, IDA_REP_SRES_ERR, __LINE__, __func__, __FILE__, + MSG_SRES_REPTD, IDA_mem->ida_tn); + return (IDA_REP_SRES_ERR); + + case IDA_SRES_FAIL: + IDAProcessError(IDA_mem, IDA_SRES_FAIL, __LINE__, __func__, __FILE__, + MSG_SRES_FAILED, IDA_mem->ida_tn); + return (IDA_SRES_FAIL); + + case IDA_REP_QSRHS_ERR: + IDAProcessError(IDA_mem, IDA_REP_QSRHS_ERR, __LINE__, __func__, __FILE__, + MSG_QSRHSFUNC_REPTD, IDA_mem->ida_tn); + return (IDA_REP_QSRHS_ERR); + + case IDA_QSRHS_FAIL: + IDAProcessError(IDA_mem, IDA_QSRHS_FAIL, __LINE__, __func__, __FILE__, + MSG_QSRHSFUNC_FAILED, IDA_mem->ida_tn); + return (IDA_QSRHS_FAIL); + + case IDA_CONSTR_FAIL: + IDAProcessError(IDA_mem, IDA_CONSTR_FAIL, __LINE__, __func__, __FILE__, + MSG_FAILED_CONSTR, IDA_mem->ida_tn); + return (IDA_CONSTR_FAIL); + + case IDA_MEM_NULL: + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + + case SUN_ERR_ARG_CORRUPT: + IDAProcessError(IDA_mem, IDA_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_NLS_INPUT_NULL, IDA_mem->ida_tn); + return (IDA_MEM_NULL); + + case IDA_NLS_SETUP_FAIL: + IDAProcessError(IDA_mem, IDA_NLS_SETUP_FAIL, __LINE__, __func__, __FILE__, + MSG_NLS_SETUP_FAILED, IDA_mem->ida_tn); + return (IDA_NLS_SETUP_FAIL); + case IDA_NLS_FAIL: + IDAProcessError(IDA_mem, IDA_NLS_FAIL, __LINE__, __func__, __FILE__, + MSG_NLS_FAIL, IDA_mem->ida_tn); + return (IDA_NLS_FAIL); } /* This return should never happen */ - IDAProcessError(IDA_mem, IDA_UNRECOGNIZED_ERROR, "IDAS", "IDASolve", - "IDA encountered an unrecognized error. Please report this to the Sundials developers at sundials-users@llnl.gov"); + IDAProcessError(IDA_mem, IDA_UNRECOGNIZED_ERROR, __LINE__, __func__, __FILE__, + "IDA encountered an unrecognized error. Please report this " + "to the Sundials developers at sundials-users@llnl.gov"); return (IDA_UNRECOGNIZED_ERROR); } @@ -5058,38 +5876,45 @@ static int IDAHandleFailure(IDAMem IDA_mem, int sflag) static int IDAStep(IDAMem IDA_mem) { - realtype saved_t, ck; - realtype err_k, err_km1, err_km2; + sunrealtype saved_t, ck; + sunrealtype err_k, err_km1, err_km2; int ncf, nef; int nflag, kflag; int retval; - booleantype sensi_stg, sensi_sim; + sunbooleantype sensi_stg, sensi_sim; /* Are we computing sensitivities with the staggered or simultaneous approach? */ - sensi_stg = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_STAGGERED)); - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_stg = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_STAGGERED)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); saved_t = IDA_mem->ida_tn; ncf = nef = 0; - if (IDA_mem->ida_nst == ZERO){ - IDA_mem->ida_kk = 1; - IDA_mem->ida_kused = 0; - IDA_mem->ida_hused = ZERO; + if (IDA_mem->ida_nst == ZERO) + { + IDA_mem->ida_kk = 1; + IDA_mem->ida_kused = 0; + IDA_mem->ida_hused = ZERO; IDA_mem->ida_psi[0] = IDA_mem->ida_hh; - IDA_mem->ida_cj = ONE/IDA_mem->ida_hh; - IDA_mem->ida_phase = 0; - IDA_mem->ida_ns = 0; + IDA_mem->ida_cj = ONE / IDA_mem->ida_hh; + IDA_mem->ida_phase = 0; + IDA_mem->ida_ns = 0; } /* To prevent 'unintialized variable' warnings */ - err_k = ZERO; + err_k = ZERO; err_km1 = ZERO; err_km2 = ZERO; /* Looping point for attempts to take a step */ - for(;;) { + for (;;) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDAStep", + "start-step-attempt", "step = %li, h = %" RSYM, + IDA_mem->ida_nst, IDA_mem->ida_hh); +#endif /*----------------------- Set method coefficients @@ -5104,9 +5929,12 @@ static int IDAStep(IDAMem IDA_mem) -----------------------------------------------------*/ IDA_mem->ida_tn = IDA_mem->ida_tn + IDA_mem->ida_hh; - if (IDA_mem->ida_tstopset) { - if ((IDA_mem->ida_tn - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) + if (IDA_mem->ida_tstopset) + { + if ((IDA_mem->ida_tn - IDA_mem->ida_tstop) * IDA_mem->ida_hh > ZERO) + { IDA_mem->ida_tn = IDA_mem->ida_tstop; + } } /*----------------------- @@ -5118,47 +5946,51 @@ static int IDAStep(IDAMem IDA_mem) /* Compute predicted values for yyS and ypS (if simultaneous approach) */ if (sensi_sim) + { IDASensPredict(IDA_mem, IDA_mem->ida_yySpredict, IDA_mem->ida_ypSpredict); + } /* Nonlinear system solution */ nflag = IDANls(IDA_mem); /* If NLS was successful, perform error test */ if (nflag == IDA_SUCCESS) + { nflag = IDATestError(IDA_mem, ck, &err_k, &err_km1, &err_km2); + } /* Test for convergence or error test failures */ - if (nflag != IDA_SUCCESS) { - + if (nflag != IDA_SUCCESS) + { /* restore and decide what to do */ IDARestore(IDA_mem, saved_t); - kflag = IDAHandleNFlag(IDA_mem, nflag, err_k, err_km1, - &(IDA_mem->ida_ncfn), &ncf, - &(IDA_mem->ida_netf), &nef); + kflag = IDAHandleNFlag(IDA_mem, nflag, err_k, err_km1, &(IDA_mem->ida_ncfn), + &ncf, &(IDA_mem->ida_netf), &nef); /* exit on nonrecoverable failure */ - if (kflag != PREDICT_AGAIN) return(kflag); + if (kflag != PREDICT_AGAIN) { return (kflag); } /* recoverable error; predict again */ - if(IDA_mem->ida_nst==0) IDAReset(IDA_mem); + if (IDA_mem->ida_nst == 0) { IDAReset(IDA_mem); } continue; - } /*---------------------------- Advance quadrature variables ----------------------------*/ - if (IDA_mem->ida_quadr) { - + if (IDA_mem->ida_quadr) + { nflag = IDAQuadNls(IDA_mem); /* If NLS was successful, perform error test */ if (IDA_mem->ida_errconQ && (nflag == IDA_SUCCESS)) + { nflag = IDAQuadTestError(IDA_mem, ck, &err_k, &err_km1, &err_km2); + } /* Test for convergence or error test failures */ - if (nflag != IDA_SUCCESS) { - + if (nflag != IDA_SUCCESS) + { /* restore and decide what to do */ IDARestore(IDA_mem, saved_t); kflag = IDAHandleNFlag(IDA_mem, nflag, err_k, err_km1, @@ -5166,10 +5998,10 @@ static int IDAStep(IDAMem IDA_mem) &(IDA_mem->ida_netfQ), &nef); /* exit on nonrecoverable failure */ - if (kflag != PREDICT_AGAIN) return(kflag); + if (kflag != PREDICT_AGAIN) { return (kflag); } /* recoverable error; predict again */ - if(IDA_mem->ida_nst==0) IDAReset(IDA_mem); + if (IDA_mem->ida_nst == 0) { IDAReset(IDA_mem); } continue; } } @@ -5177,18 +6009,17 @@ static int IDAStep(IDAMem IDA_mem) /*-------------------------------------------------- Advance sensitivity variables (Staggered approach) --------------------------------------------------*/ - if (sensi_stg) { - + if (sensi_stg) + { /* Evaluate res at converged y, needed for future evaluations of sens. RHS If res() fails recoverably, treat it as a convergence failure and attempt the step again */ - retval = IDA_mem->ida_res(IDA_mem->ida_tn, - IDA_mem->ida_yy, IDA_mem->ida_yp, + retval = IDA_mem->ida_res(IDA_mem->ida_tn, IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_delta, IDA_mem->ida_user_data); - if (retval < 0) return(IDA_RES_FAIL); - if (retval > 0) continue; + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { continue; } /* Compute predicted values for yyS and ypS */ IDASensPredict(IDA_mem, IDA_mem->ida_yySpredict, IDA_mem->ida_ypSpredict); @@ -5198,11 +6029,13 @@ static int IDAStep(IDAMem IDA_mem) /* If NLS was successful, perform error test */ if (IDA_mem->ida_errconS && (nflag == IDA_SUCCESS)) + { nflag = IDASensTestError(IDA_mem, ck, &err_k, &err_km1, &err_km2); + } /* Test for convergence or error test failures */ - if (nflag != IDA_SUCCESS) { - + if (nflag != IDA_SUCCESS) + { /* restore and decide what to do */ IDARestore(IDA_mem, saved_t); kflag = IDAHandleNFlag(IDA_mem, nflag, err_k, err_km1, @@ -5210,10 +6043,10 @@ static int IDAStep(IDAMem IDA_mem) &(IDA_mem->ida_netfQ), &nef); /* exit on nonrecoverable failure */ - if (kflag != PREDICT_AGAIN) return(kflag); + if (kflag != PREDICT_AGAIN) { return (kflag); } /* recoverable error; predict again */ - if(IDA_mem->ida_nst==0) IDAReset(IDA_mem); + if (IDA_mem->ida_nst == 0) { IDAReset(IDA_mem); } continue; } } @@ -5221,17 +6054,19 @@ static int IDAStep(IDAMem IDA_mem) /*------------------------------------------- Advance quadrature sensitivity variables -------------------------------------------*/ - if (IDA_mem->ida_quadr_sensi) { - + if (IDA_mem->ida_quadr_sensi) + { nflag = IDAQuadSensNls(IDA_mem); /* If NLS was successful, perform error test */ if (IDA_mem->ida_errconQS && (nflag == IDA_SUCCESS)) + { nflag = IDAQuadSensTestError(IDA_mem, ck, &err_k, &err_km1, &err_km2); + } /* Test for convergence or error test failures */ - if (nflag != IDA_SUCCESS) { - + if (nflag != IDA_SUCCESS) + { /* restore and decide what to do */ IDARestore(IDA_mem, saved_t); kflag = IDAHandleNFlag(IDA_mem, nflag, err_k, err_km1, @@ -5239,10 +6074,10 @@ static int IDAStep(IDAMem IDA_mem) &(IDA_mem->ida_netfQ), &nef); /* exit on nonrecoverable failure */ - if (kflag != PREDICT_AGAIN) return(kflag); + if (kflag != PREDICT_AGAIN) { return (kflag); } /* recoverable error; predict again */ - if(IDA_mem->ida_nst==0) IDAReset(IDA_mem); + if (IDA_mem->ida_nst == 0) { IDAReset(IDA_mem); } continue; } } @@ -5270,7 +6105,7 @@ static int IDAStep(IDAMem IDA_mem) N_VScale(ck, IDA_mem->ida_ee, IDA_mem->ida_ee); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -5284,45 +6119,53 @@ static int IDAStep(IDAMem IDA_mem) * Also, IDACompleteStep prohibits an order increase until ns = k + 2. */ -static void IDASetCoeffs(IDAMem IDA_mem, realtype *ck) +static void IDASetCoeffs(IDAMem IDA_mem, sunrealtype* ck) { int i, j, is; - realtype temp1, temp2, alpha0, alphas; + sunrealtype temp1, temp2, alpha0, alphas; /* Set coefficients for the current stepsize h */ - if ( (IDA_mem->ida_hh != IDA_mem->ida_hused) || - (IDA_mem->ida_kk != IDA_mem->ida_kused) ) + if ((IDA_mem->ida_hh != IDA_mem->ida_hused) || + (IDA_mem->ida_kk != IDA_mem->ida_kused)) + { IDA_mem->ida_ns = 0; - IDA_mem->ida_ns = SUNMIN(IDA_mem->ida_ns+1, IDA_mem->ida_kused+2); - if (IDA_mem->ida_kk + 1 >= IDA_mem->ida_ns) { - IDA_mem->ida_beta[0] = ONE; + } + IDA_mem->ida_ns = SUNMIN(IDA_mem->ida_ns + 1, IDA_mem->ida_kused + 2); + if (IDA_mem->ida_kk + 1 >= IDA_mem->ida_ns) + { + IDA_mem->ida_beta[0] = ONE; IDA_mem->ida_alpha[0] = ONE; - temp1 = IDA_mem->ida_hh; + temp1 = IDA_mem->ida_hh; IDA_mem->ida_gamma[0] = ZERO; IDA_mem->ida_sigma[0] = ONE; - for(i=1; i<=IDA_mem->ida_kk; i++) { - temp2 = IDA_mem->ida_psi[i-1]; - IDA_mem->ida_psi[i-1] = temp1; - IDA_mem->ida_beta[i] = IDA_mem->ida_beta[i-1] * IDA_mem->ida_psi[i-1] / temp2; - temp1 = temp2 + IDA_mem->ida_hh; + for (i = 1; i <= IDA_mem->ida_kk; i++) + { + temp2 = IDA_mem->ida_psi[i - 1]; + IDA_mem->ida_psi[i - 1] = temp1; + IDA_mem->ida_beta[i] = IDA_mem->ida_beta[i - 1] * + IDA_mem->ida_psi[i - 1] / temp2; + temp1 = temp2 + IDA_mem->ida_hh; IDA_mem->ida_alpha[i] = IDA_mem->ida_hh / temp1; - IDA_mem->ida_sigma[i] = i * IDA_mem->ida_sigma[i-1] * IDA_mem->ida_alpha[i]; - IDA_mem->ida_gamma[i] = IDA_mem->ida_gamma[i-1] + IDA_mem->ida_alpha[i-1] / IDA_mem->ida_hh; - } + IDA_mem->ida_sigma[i] = i * IDA_mem->ida_sigma[i - 1] * + IDA_mem->ida_alpha[i]; + IDA_mem->ida_gamma[i] = IDA_mem->ida_gamma[i - 1] + + IDA_mem->ida_alpha[i - 1] / IDA_mem->ida_hh; + } IDA_mem->ida_psi[IDA_mem->ida_kk] = temp1; } /* compute alphas, alpha0 */ alphas = ZERO; alpha0 = ZERO; - for(i=0; iida_kk; i++) { - alphas = alphas - ONE/(i+1); + for (i = 0; i < IDA_mem->ida_kk; i++) + { + alphas = alphas - ONE / (i + 1); alpha0 = alpha0 - IDA_mem->ida_alpha[i]; } /* compute leading coefficient cj */ IDA_mem->ida_cjlast = IDA_mem->ida_cj; - IDA_mem->ida_cj = -alphas/IDA_mem->ida_hh; + IDA_mem->ida_cj = -alphas / IDA_mem->ida_hh; /* compute variable stepsize error coefficient ck */ @@ -5332,58 +6175,71 @@ static void IDASetCoeffs(IDAMem IDA_mem, realtype *ck) /* change phi to phi-star */ /* Scale i=IDA_mem->ida_ns to i<=IDA_mem->ida_kk */ - if (IDA_mem->ida_ns <= IDA_mem->ida_kk) { - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) - IDA_mem->ida_cvals[i-IDA_mem->ida_ns] = IDA_mem->ida_beta[i]; + if (IDA_mem->ida_ns <= IDA_mem->ida_kk) + { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + IDA_mem->ida_cvals[i - IDA_mem->ida_ns] = IDA_mem->ida_beta[i]; + } - (void) N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, - IDA_mem->ida_cvals, - IDA_mem->ida_phi+IDA_mem->ida_ns, - IDA_mem->ida_phi+IDA_mem->ida_ns); + (void)N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, + IDA_mem->ida_cvals, + IDA_mem->ida_phi + IDA_mem->ida_ns, + IDA_mem->ida_phi + IDA_mem->ida_ns); if (IDA_mem->ida_quadr) - (void) N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, - IDA_mem->ida_cvals, - IDA_mem->ida_phiQ+IDA_mem->ida_ns, - IDA_mem->ida_phiQ+IDA_mem->ida_ns); + { + (void)N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, + IDA_mem->ida_cvals, + IDA_mem->ida_phiQ + IDA_mem->ida_ns, + IDA_mem->ida_phiQ + IDA_mem->ida_ns); + } - if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) { + if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_cvals[j] = IDA_mem->ida_beta[i]; j++; } } } - if (IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiS[i][is]; j++; } } - (void) N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, - IDA_mem->ida_Xvecs); + (void)N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Xvecs); } - if (IDA_mem->ida_quadr_sensi) { + if (IDA_mem->ida_quadr_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiQS[i][is]; j++; } } - (void) N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, - IDA_mem->ida_Xvecs); + (void)N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Xvecs); } } - } /* @@ -5416,146 +6272,168 @@ static void IDASetCoeffs(IDAMem IDA_mem, realtype *ck) static int IDANls(IDAMem IDA_mem) { int retval; - booleantype constraintsPassed, callLSetup, sensi_sim; - realtype temp1, temp2, vnorm; + sunbooleantype constraintsPassed, callLSetup, sensi_sim; + sunrealtype temp1, temp2, vnorm; N_Vector mm, tmp; - long int nni_inc; + long int nni_inc = 0; + long int nnf_inc = 0; /* Are we computing sensitivities with the IDA_SIMULTANEOUS approach? */ - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); callLSetup = SUNFALSE; /* Initialize if the first time called */ - if (IDA_mem->ida_nst == 0){ + if (IDA_mem->ida_nst == 0) + { IDA_mem->ida_cjold = IDA_mem->ida_cj; - IDA_mem->ida_ss = TWENTY; - IDA_mem->ida_ssS = TWENTY; - if (IDA_mem->ida_lsetup) callLSetup = SUNTRUE; + IDA_mem->ida_ss = TWENTY; + IDA_mem->ida_ssS = TWENTY; + if (IDA_mem->ida_lsetup) { callLSetup = SUNTRUE; } } /* Decide if lsetup is to be called */ - if (IDA_mem->ida_lsetup) { + if (IDA_mem->ida_lsetup) + { IDA_mem->ida_cjratio = IDA_mem->ida_cj / IDA_mem->ida_cjold; - temp1 = (ONE - XRATE) / (ONE + XRATE); - temp2 = ONE/temp1; - if (IDA_mem->ida_cjratio < temp1 || IDA_mem->ida_cjratio > temp2) callLSetup = SUNTRUE; - if (IDA_mem->ida_forceSetup) callLSetup = SUNTRUE; - if (IDA_mem->ida_cj != IDA_mem->ida_cjlast) { - IDA_mem->ida_ss = HUNDRED; + temp1 = (ONE - IDA_mem->ida_dcj) / (ONE + IDA_mem->ida_dcj); + temp2 = ONE / temp1; + if (IDA_mem->ida_cjratio < temp1 || IDA_mem->ida_cjratio > temp2) + { + callLSetup = SUNTRUE; + } + if (IDA_mem->ida_forceSetup) { callLSetup = SUNTRUE; } + if (IDA_mem->ida_cj != IDA_mem->ida_cjlast) + { + IDA_mem->ida_ss = HUNDRED; IDA_mem->ida_ssS = HUNDRED; } } /* initial guess for the correction to the predictor */ - if (sensi_sim) - N_VConst(ZERO, IDA_mem->ycorSim); - else - N_VConst(ZERO, IDA_mem->ida_ee); + if (sensi_sim) { N_VConst(ZERO, IDA_mem->ycorSim); } + else { N_VConst(ZERO, IDA_mem->ida_ee); } /* call nonlinear solver setup if it exists */ - if ((IDA_mem->NLS)->ops->setup) { + if ((IDA_mem->NLS)->ops->setup) + { if (sensi_sim) + { retval = SUNNonlinSolSetup(IDA_mem->NLS, IDA_mem->ycorSim, IDA_mem); - else - retval = SUNNonlinSolSetup(IDA_mem->NLS, IDA_mem->ida_ee, IDA_mem); + } + else { retval = SUNNonlinSolSetup(IDA_mem->NLS, IDA_mem->ida_ee, IDA_mem); } - if (retval < 0) return(IDA_NLS_SETUP_FAIL); - if (retval > 0) return(IDA_NLS_SETUP_RECVR); + if (retval < 0) { return (IDA_NLS_SETUP_FAIL); } + if (retval > 0) { return (IDA_NLS_SETUP_RECVR); } } /* solve the nonlinear system */ - if (sensi_sim) { - - retval = SUNNonlinSolSolve(IDA_mem->NLSsim, - IDA_mem->ypredictSim, IDA_mem->ycorSim, - IDA_mem->ewtSim, IDA_mem->ida_epsNewt, - callLSetup, IDA_mem); - - /* increment counter */ - nni_inc = 0; - (void) SUNNonlinSolGetNumIters(IDA_mem->NLSsim, &(nni_inc)); + if (sensi_sim) + { + retval = SUNNonlinSolSolve(IDA_mem->NLSsim, IDA_mem->ypredictSim, + IDA_mem->ycorSim, IDA_mem->ewtSim, + IDA_mem->ida_epsNewt, callLSetup, IDA_mem); + /* increment counters */ + (void)SUNNonlinSolGetNumIters(IDA_mem->NLSsim, &nni_inc); IDA_mem->ida_nni += nni_inc; - } else { - - retval = SUNNonlinSolSolve(IDA_mem->NLS, - IDA_mem->ida_yypredict, IDA_mem->ida_ee, - IDA_mem->ida_ewt, IDA_mem->ida_epsNewt, - callLSetup, IDA_mem); + (void)SUNNonlinSolGetNumConvFails(IDA_mem->NLSsim, &nnf_inc); + IDA_mem->ida_nnf += nnf_inc; + } + else + { + retval = SUNNonlinSolSolve(IDA_mem->NLS, IDA_mem->ida_yypredict, + IDA_mem->ida_ee, IDA_mem->ida_ewt, + IDA_mem->ida_epsNewt, callLSetup, IDA_mem); /* increment counter */ - nni_inc = 0; - (void) SUNNonlinSolGetNumIters(IDA_mem->NLS, &(nni_inc)); + (void)SUNNonlinSolGetNumIters(IDA_mem->NLS, &nni_inc); IDA_mem->ida_nni += nni_inc; + (void)SUNNonlinSolGetNumConvFails(IDA_mem->NLS, &nnf_inc); + IDA_mem->ida_nnf += nnf_inc; } +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDANls", + "nls-return", "flag = %i, iters = %li, fails = %li", + retval, nni_inc, nnf_inc); +#endif + + /* return if nonlinear solver failed */ + if (retval != SUN_SUCCESS) { return (retval); } + /* update the state using the final correction from the nonlinear solver */ - N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, IDA_mem->ida_ee, IDA_mem->ida_yy); - N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, IDA_mem->ida_ee, IDA_mem->ida_yp); + N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, IDA_mem->ida_ee, + IDA_mem->ida_yy); + N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, IDA_mem->ida_ee, + IDA_mem->ida_yp); /* update the sensitivities based on the final correction from the nonlinear solver */ - if (sensi_sim) { - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yySpredict, - ONE, IDA_mem->ida_eeS, IDA_mem->ida_yyS); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_ypSpredict, + if (sensi_sim) + { + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yySpredict, ONE, + IDA_mem->ida_eeS, IDA_mem->ida_yyS); + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_ypSpredict, IDA_mem->ida_cj, IDA_mem->ida_eeS, IDA_mem->ida_ypS); } - /* return if nonlinear solver failed */ - if (retval != IDA_SUCCESS) return(retval); - /* If otherwise successful, check and enforce inequality constraints. */ - if (IDA_mem->ida_constraintsSet) { - + if (IDA_mem->ida_constraintsSet) + { /* shortcut names for temporary work vectors */ mm = IDA_mem->ida_tempv2; tmp = IDA_mem->ida_tempv1; /* Get mask vector mm, set where constraints failed */ - constraintsPassed = N_VConstrMask(IDA_mem->ida_constraints, - IDA_mem->ida_yy, mm); - if (constraintsPassed) return(IDA_SUCCESS); + constraintsPassed = N_VConstrMask(IDA_mem->ida_constraints, IDA_mem->ida_yy, + mm); + if (constraintsPassed) { return (IDA_SUCCESS); } /* Constraints not met */ /* Compute correction to satisfy constraints */ - N_VCompare(ONEPT5, IDA_mem->ida_constraints, tmp); /* a[i] =1 when |c[i]| = 2 */ - N_VProd(tmp, IDA_mem->ida_constraints, tmp); /* a * c */ - N_VDiv(tmp, IDA_mem->ida_ewt, tmp); /* a * c * wt */ + N_VCompare(ONEPT5, IDA_mem->ida_constraints, tmp); /* a[i] =1 when |c[i]| = 2 */ + N_VProd(tmp, IDA_mem->ida_constraints, tmp); /* a * c */ + N_VDiv(tmp, IDA_mem->ida_ewt, tmp); /* a * c * wt */ N_VLinearSum(ONE, IDA_mem->ida_yy, -PT1, tmp, tmp); /* y - 0.1 * a * c * wt */ - N_VProd(tmp, mm, tmp); /* v = mm*(y-.1*a*c*wt) */ + N_VProd(tmp, mm, tmp); /* v = mm*(y-.1*a*c*wt) */ vnorm = IDAWrmsNorm(IDA_mem, tmp, IDA_mem->ida_ewt, SUNFALSE); /* ||v|| */ /* If vector v of constraint corrections is small in norm, correct and accept this step */ - if (vnorm <= IDA_mem->ida_epsNewt) { - N_VLinearSum(ONE, IDA_mem->ida_ee, - -ONE, tmp, IDA_mem->ida_ee); /* ee <- ee - v */ - return(IDA_SUCCESS); + if (vnorm <= IDA_mem->ida_epsNewt) + { + N_VLinearSum(ONE, IDA_mem->ida_ee, -ONE, tmp, + IDA_mem->ida_ee); /* ee <- ee - v */ + return (IDA_SUCCESS); + } + + /* Return with error if |h| == hmin */ + if (SUNRabs(IDA_mem->ida_hh) <= IDA_mem->ida_hmin * ONEPSM) + { + return (IDA_CONSTR_FAIL); } /* Constraints correction is too large, reduce h by computing rr = h'/h */ N_VLinearSum(ONE, IDA_mem->ida_phi[0], -ONE, IDA_mem->ida_yy, tmp); N_VProd(mm, tmp, tmp); - IDA_mem->ida_rr = PT9*N_VMinQuotient(IDA_mem->ida_phi[0], tmp); - IDA_mem->ida_rr = SUNMAX(IDA_mem->ida_rr, PT1); + IDA_mem->ida_eta = PT9 * N_VMinQuotient(IDA_mem->ida_phi[0], tmp); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta, PT1); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); /* Reattempt step with new step size */ - return(IDA_CONSTR_RECVR); + return (IDA_CONSTR_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* * IDAPredict * @@ -5566,14 +6444,13 @@ static void IDAPredict(IDAMem IDA_mem) { int j; - for(j=0; j<=IDA_mem->ida_kk; j++) - IDA_mem->ida_cvals[j] = ONE; + for (j = 0; j <= IDA_mem->ida_kk; j++) { IDA_mem->ida_cvals[j] = ONE; } - (void) N_VLinearCombination(IDA_mem->ida_kk+1, IDA_mem->ida_cvals, - IDA_mem->ida_phi, IDA_mem->ida_yypredict); + (void)N_VLinearCombination(IDA_mem->ida_kk + 1, IDA_mem->ida_cvals, + IDA_mem->ida_phi, IDA_mem->ida_yypredict); - (void) N_VLinearCombination(IDA_mem->ida_kk, IDA_mem->ida_gamma+1, - IDA_mem->ida_phi+1, IDA_mem->ida_yppredict); + (void)N_VLinearCombination(IDA_mem->ida_kk, IDA_mem->ida_gamma + 1, + IDA_mem->ida_phi + 1, IDA_mem->ida_yppredict); } /* @@ -5594,23 +6471,24 @@ static int IDAQuadNls(IDAMem IDA_mem) IDAQuadPredict(IDA_mem); /* Compute correction eeQ */ - retval = IDA_mem->ida_rhsQ(IDA_mem->ida_tn, IDA_mem->ida_yy, - IDA_mem->ida_yp, IDA_mem->ida_eeQ, - IDA_mem->ida_user_data); + retval = IDA_mem->ida_rhsQ(IDA_mem->ida_tn, IDA_mem->ida_yy, IDA_mem->ida_yp, + IDA_mem->ida_eeQ, IDA_mem->ida_user_data); IDA_mem->ida_nrQe++; - if (retval < 0) return(IDA_QRHS_FAIL); - else if (retval > 0) return(IDA_QRHS_RECVR); + if (retval < 0) { return (IDA_QRHS_FAIL); } + else if (retval > 0) { return (IDA_QRHS_RECVR); } if (IDA_mem->ida_quadr_sensi) + { N_VScale(ONE, IDA_mem->ida_eeQ, IDA_mem->ida_savrhsQ); + } N_VLinearSum(ONE, IDA_mem->ida_eeQ, -ONE, IDA_mem->ida_ypQ, IDA_mem->ida_eeQ); - N_VScale(ONE/IDA_mem->ida_cj, IDA_mem->ida_eeQ, IDA_mem->ida_eeQ); + N_VScale(ONE / IDA_mem->ida_cj, IDA_mem->ida_eeQ, IDA_mem->ida_eeQ); /* Apply correction: yyQ = yyQ + eeQ */ N_VLinearSum(ONE, IDA_mem->ida_yyQ, ONE, IDA_mem->ida_eeQ, IDA_mem->ida_yyQ); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -5623,15 +6501,13 @@ static void IDAQuadPredict(IDAMem IDA_mem) { int j; - for(j=0; j<=IDA_mem->ida_kk; j++) - IDA_mem->ida_cvals[j] = ONE; - - (void) N_VLinearCombination(IDA_mem->ida_kk+1, IDA_mem->ida_cvals, - IDA_mem->ida_phiQ, IDA_mem->ida_yyQ); + for (j = 0; j <= IDA_mem->ida_kk; j++) { IDA_mem->ida_cvals[j] = ONE; } - (void) N_VLinearCombination(IDA_mem->ida_kk, IDA_mem->ida_gamma+1, - IDA_mem->ida_phiQ+1, IDA_mem->ida_ypQ); + (void)N_VLinearCombination(IDA_mem->ida_kk + 1, IDA_mem->ida_cvals, + IDA_mem->ida_phiQ, IDA_mem->ida_yyQ); + (void)N_VLinearCombination(IDA_mem->ida_kk, IDA_mem->ida_gamma + 1, + IDA_mem->ida_phiQ + 1, IDA_mem->ida_ypQ); } /* @@ -5644,8 +6520,9 @@ static void IDAQuadPredict(IDAMem IDA_mem) static int IDASensNls(IDAMem IDA_mem) { - booleantype callLSetup; - long int nniS_inc; + sunbooleantype callLSetup; + long int nniS_inc = 0; + long int nnfS_inc = 0; int retval; callLSetup = SUNFALSE; @@ -5654,29 +6531,30 @@ static int IDASensNls(IDAMem IDA_mem) N_VConst(ZERO, IDA_mem->ycorStg); /* solve the nonlinear system */ - retval = SUNNonlinSolSolve(IDA_mem->NLSstg, - IDA_mem->ypredictStg, IDA_mem->ycorStg, - IDA_mem->ewtStg, IDA_mem->ida_epsNewt, - callLSetup, IDA_mem); - - /* increment counter */ - nniS_inc = 0; - (void) SUNNonlinSolGetNumIters(IDA_mem->NLSstg, &(nniS_inc)); + retval = SUNNonlinSolSolve(IDA_mem->NLSstg, IDA_mem->ypredictStg, + IDA_mem->ycorStg, IDA_mem->ewtStg, + IDA_mem->ida_epsNewt, callLSetup, IDA_mem); + + /* increment counters */ + (void)SUNNonlinSolGetNumIters(IDA_mem->NLSstg, &nniS_inc); IDA_mem->ida_nniS += nniS_inc; - /* update using the final correction from the nonlinear solver */ - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yySpredict, - ONE, IDA_mem->ida_eeS, IDA_mem->ida_yyS); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_ypSpredict, - IDA_mem->ida_cj, IDA_mem->ida_eeS, IDA_mem->ida_ypS); + (void)SUNNonlinSolGetNumConvFails(IDA_mem->NLSstg, &nnfS_inc); + IDA_mem->ida_nnfS += nnfS_inc; - if (retval != IDA_SUCCESS) + if (retval != SUN_SUCCESS) + { IDA_mem->ida_ncfnS++; + return (retval); + } - return(retval); + /* update using the final correction from the nonlinear solver */ + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yySpredict, ONE, + IDA_mem->ida_eeS, IDA_mem->ida_yyS); + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_ypSpredict, + IDA_mem->ida_cj, IDA_mem->ida_eeS, IDA_mem->ida_ypS); + return (retval); } /* @@ -5688,21 +6566,19 @@ static int IDASensNls(IDAMem IDA_mem) * When ism=IDA_STAGGERED, yySens = yyS[is] and ypSens = ypS[is] */ -static void IDASensPredict(IDAMem IDA_mem, N_Vector *yySens, N_Vector *ypSens) +static void IDASensPredict(IDAMem IDA_mem, N_Vector* yySens, N_Vector* ypSens) { int j; - for(j=0; j<=IDA_mem->ida_kk; j++) - IDA_mem->ida_cvals[j] = ONE; + for (j = 0; j <= IDA_mem->ida_kk; j++) { IDA_mem->ida_cvals[j] = ONE; } - (void) N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk+1, - IDA_mem->ida_cvals, - IDA_mem->ida_phiS, yySens); - - (void) N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk, - IDA_mem->ida_gamma+1, - IDA_mem->ida_phiS+1, ypSens); + (void)N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk + 1, + IDA_mem->ida_cvals, IDA_mem->ida_phiS, + yySens); + (void)N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk, + IDA_mem->ida_gamma + 1, + IDA_mem->ida_phiS + 1, ypSens); } /* @@ -5718,7 +6594,7 @@ static void IDASensPredict(IDAMem IDA_mem, N_Vector *yySens, N_Vector *ypSens) static int IDAQuadSensNls(IDAMem IDA_mem) { int retval; - N_Vector *ypQS; + N_Vector* ypQS; /* Predict: load yyQS and ypQS for each sensitivity. Store 1st order information in tempvQS. */ @@ -5727,31 +6603,27 @@ static int IDAQuadSensNls(IDAMem IDA_mem) IDAQuadSensPredict(IDA_mem, IDA_mem->ida_yyQS, ypQS); /* Compute correction eeQS */ - retval = IDA_mem->ida_rhsQS(IDA_mem->ida_Ns, IDA_mem->ida_tn, - IDA_mem->ida_yy, IDA_mem->ida_yp, - IDA_mem->ida_yyS, IDA_mem->ida_ypS, + retval = IDA_mem->ida_rhsQS(IDA_mem->ida_Ns, IDA_mem->ida_tn, IDA_mem->ida_yy, + IDA_mem->ida_yp, IDA_mem->ida_yyS, IDA_mem->ida_ypS, IDA_mem->ida_savrhsQ, IDA_mem->ida_eeQS, IDA_mem->ida_user_dataQS, IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrQSe++; - if (retval < 0) return(IDA_QSRHS_FAIL); - else if (retval > 0) return(IDA_QSRHS_RECVR); + if (retval < 0) { return (IDA_QSRHS_FAIL); } + else if (retval > 0) { return (IDA_QSRHS_RECVR); } - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE/IDA_mem->ida_cj, IDA_mem->ida_eeQS, - -ONE/IDA_mem->ida_cj, ypQS, - IDA_mem->ida_eeQS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE / IDA_mem->ida_cj, + IDA_mem->ida_eeQS, -ONE / IDA_mem->ida_cj, + ypQS, IDA_mem->ida_eeQS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } /* Apply correction: yyQS[is] = yyQ[is] + eeQ[is] */ - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yyQS, - ONE, IDA_mem->ida_eeQS, - IDA_mem->ida_yyQS); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yyQS, ONE, + IDA_mem->ida_eeQS, IDA_mem->ida_yyQS); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -5760,24 +6632,21 @@ static int IDAQuadSensNls(IDAMem IDA_mem) * This routine predicts the new value for vectors yyQS and ypQS */ -static void IDAQuadSensPredict(IDAMem IDA_mem, N_Vector *yQS, N_Vector *ypQS) +static void IDAQuadSensPredict(IDAMem IDA_mem, N_Vector* yQS, N_Vector* ypQS) { int j; - for(j=0; j<=IDA_mem->ida_kk; j++) - IDA_mem->ida_cvals[j] = ONE; - - (void) N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk+1, - IDA_mem->ida_cvals, - IDA_mem->ida_phiQS, yQS); + for (j = 0; j <= IDA_mem->ida_kk; j++) { IDA_mem->ida_cvals[j] = ONE; } - (void) N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk, - IDA_mem->ida_gamma+1, - IDA_mem->ida_phiQS+1, ypQS); + (void)N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk + 1, + IDA_mem->ida_cvals, IDA_mem->ida_phiQS, + yQS); + (void)N_VLinearCombinationVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_kk, + IDA_mem->ida_gamma + 1, + IDA_mem->ida_phiQS + 1, ypQS); } - /* * ----------------------------------------------------------------- * Error test @@ -5794,55 +6663,88 @@ static void IDAQuadSensPredict(IDAMem IDA_mem, N_Vector *yQS, N_Vector *ypQS) * IDATestError returns either IDA_SUCCESS or ERROR_TEST_FAIL. */ -static int IDATestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2) +static int IDATestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2) { - realtype enorm_k, enorm_km1, enorm_km2; /* error norms */ - realtype terr_k, terr_km1, terr_km2; /* local truncation error norms */ + sunrealtype enorm_k, enorm_km1, enorm_km2; /* error norms */ + sunrealtype terr_k, terr_km1, terr_km2; /* local truncation error norms */ /* Compute error for order k. */ - enorm_k = IDAWrmsNorm(IDA_mem, IDA_mem->ida_ee, IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); - *err_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enorm_k; - terr_k = (IDA_mem->ida_kk + 1) * (*err_k); + enorm_k = IDAWrmsNorm(IDA_mem, IDA_mem->ida_ee, IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); + *err_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enorm_k; + terr_k = (IDA_mem->ida_kk + 1) * (*err_k); - IDA_mem->ida_knew = IDA_mem->ida_kk; +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDATestError", + "estimate-error-order-k", + "err_k = %" RSYM ", terr_k = %" RSYM, *err_k, terr_k); +#endif - if ( IDA_mem->ida_kk > 1 ) { + IDA_mem->ida_knew = IDA_mem->ida_kk; + if (IDA_mem->ida_kk > 1) + { /* Compute error at order k-1 */ - N_VLinearSum(ONE, IDA_mem->ida_phi[IDA_mem->ida_kk], ONE, IDA_mem->ida_ee, IDA_mem->ida_delta); - enorm_km1 = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delta, - IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); - *err_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 1] * enorm_km1; - terr_km1 = IDA_mem->ida_kk * (*err_km1); - - if ( IDA_mem->ida_kk > 2 ) { + N_VLinearSum(ONE, IDA_mem->ida_phi[IDA_mem->ida_kk], ONE, IDA_mem->ida_ee, + IDA_mem->ida_delta); + enorm_km1 = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delta, IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); + *err_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 1] * enorm_km1; + terr_km1 = IDA_mem->ida_kk * (*err_km1); + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDATestError", + "estimate-error-order-km1", + "err_km1 = %" RSYM ", terr_km1 = %" RSYM, *err_km1, + terr_km1); +#endif + if (IDA_mem->ida_kk > 2) + { /* Compute error at order k-2 */ N_VLinearSum(ONE, IDA_mem->ida_phi[IDA_mem->ida_kk - 1], ONE, IDA_mem->ida_delta, IDA_mem->ida_delta); - enorm_km2 = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delta, - IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); - *err_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 2] * enorm_km2; - terr_km2 = (IDA_mem->ida_kk - 1) * (*err_km2); + enorm_km2 = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delta, IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); + *err_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 2] * enorm_km2; + terr_km2 = (IDA_mem->ida_kk - 1) * (*err_km2); + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDATestError", + "estimate-error-order-km2", + "err_km2 = %" RSYM ", terr_km2 = %" RSYM, *err_km2, + terr_km2); +#endif /* Decrease order if errors are reduced */ if (SUNMAX(terr_km1, terr_km2) <= terr_k) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - - } else { - + } + } + else + { /* Decrease order to 1 if errors are reduced by at least 1/2 */ - if (terr_km1 <= (HALF * terr_k) ) + if (terr_km1 <= (HALF * terr_k)) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - + } } - } +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDATestError", + "new-order", "kk = %i, knew = %i", IDA_mem->ida_kk, + IDA_mem->ida_knew); + + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDATestError", + "error-estimate", "ck_enorm_k = %" RSYM, ck * enorm_k); +#endif + /* Perform error test */ - if (ck * enorm_k > ONE) return(ERROR_TEST_FAIL); - else return(IDA_SUCCESS); + if (ck * enorm_k > ONE) { return (ERROR_TEST_FAIL); } + else { return (IDA_SUCCESS); } } /* @@ -5858,14 +6760,14 @@ static int IDATestError(IDAMem IDA_mem, realtype ck, * The return flag can be either IDA_SUCCESS or ERROR_TEST_FAIL. */ -static int IDAQuadTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2) +static int IDAQuadTestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2) { - realtype enormQ; - realtype errQ_k, errQ_km1, errQ_km2; - realtype terr_k, terr_km1, terr_km2; + sunrealtype enormQ; + sunrealtype errQ_k, errQ_km1, errQ_km2; + sunrealtype terr_k, terr_km1, terr_km2; N_Vector tempv; - booleantype check_for_reduction = SUNFALSE; + sunbooleantype check_for_reduction = SUNFALSE; /* Rename ypQ */ tempv = IDA_mem->ida_ypQ; @@ -5873,59 +6775,65 @@ static int IDAQuadTestError(IDAMem IDA_mem, realtype ck, /* Update error for order k. */ enormQ = N_VWrmsNorm(IDA_mem->ida_eeQ, IDA_mem->ida_ewtQ); errQ_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enormQ; - if (errQ_k > *err_k) { - *err_k = errQ_k; + if (errQ_k > *err_k) + { + *err_k = errQ_k; check_for_reduction = SUNTRUE; } - terr_k = (IDA_mem->ida_kk+1) * (*err_k); - - if ( IDA_mem->ida_kk > 1 ) { + terr_k = (IDA_mem->ida_kk + 1) * (*err_k); + if (IDA_mem->ida_kk > 1) + { /* Update error at order k-1 */ - N_VLinearSum(ONE, IDA_mem->ida_phiQ[IDA_mem->ida_kk], ONE, IDA_mem->ida_eeQ, tempv); - errQ_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk-1] * N_VWrmsNorm(tempv, IDA_mem->ida_ewtQ); - if (errQ_km1 > *err_km1) { - *err_km1 = errQ_km1; + N_VLinearSum(ONE, IDA_mem->ida_phiQ[IDA_mem->ida_kk], ONE, IDA_mem->ida_eeQ, + tempv); + errQ_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 1] * + N_VWrmsNorm(tempv, IDA_mem->ida_ewtQ); + if (errQ_km1 > *err_km1) + { + *err_km1 = errQ_km1; check_for_reduction = SUNTRUE; } terr_km1 = IDA_mem->ida_kk * (*err_km1); /* Has an order decrease already been decided in IDATestError? */ if (IDA_mem->ida_knew != IDA_mem->ida_kk) + { check_for_reduction = SUNFALSE; + } - if (check_for_reduction) { - - if ( IDA_mem->ida_kk > 2 ) { - + if (check_for_reduction) + { + if (IDA_mem->ida_kk > 2) + { /* Update error at order k-2 */ - N_VLinearSum(ONE, IDA_mem->ida_phiQ[IDA_mem->ida_kk-1], ONE, tempv, tempv); - errQ_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk-2] * N_VWrmsNorm(tempv, IDA_mem->ida_ewtQ); - if (errQ_km2 > *err_km2) { - *err_km2 = errQ_km2; - } - terr_km2 = (IDA_mem->ida_kk-1) * (*err_km2); + N_VLinearSum(ONE, IDA_mem->ida_phiQ[IDA_mem->ida_kk - 1], ONE, tempv, + tempv); + errQ_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 2] * + N_VWrmsNorm(tempv, IDA_mem->ida_ewtQ); + if (errQ_km2 > *err_km2) { *err_km2 = errQ_km2; } + terr_km2 = (IDA_mem->ida_kk - 1) * (*err_km2); /* Decrease order if errors are reduced */ if (SUNMAX(terr_km1, terr_km2) <= terr_k) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - - } else { - + } + } + else + { /* Decrease order to 1 if errors are reduced by at least 1/2 */ - if (terr_km1 <= (HALF * terr_k) ) + if (terr_km1 <= (HALF * terr_k)) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - + } } - } - } /* Perform error test */ - if (ck * enormQ > ONE) return(ERROR_TEST_FAIL); - else return(IDA_SUCCESS); - + if (ck * enormQ > ONE) { return (ERROR_TEST_FAIL); } + else { return (IDA_SUCCESS); } } /* @@ -5941,87 +6849,92 @@ static int IDAQuadTestError(IDAMem IDA_mem, realtype ck, * The return flag can be either IDA_SUCCESS or ERROR_TEST_FAIL. */ -static int IDASensTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2) +static int IDASensTestError(IDAMem IDA_mem, sunrealtype ck, sunrealtype* err_k, + sunrealtype* err_km1, sunrealtype* err_km2) { - realtype enormS; - realtype errS_k, errS_km1, errS_km2; - realtype terr_k, terr_km1, terr_km2; - N_Vector *tempv; - booleantype check_for_reduction = SUNFALSE; + sunrealtype enormS; + sunrealtype errS_k, errS_km1, errS_km2; + sunrealtype terr_k, terr_km1, terr_km2; + N_Vector* tempv; + sunbooleantype check_for_reduction = SUNFALSE; int retval; /* Rename deltaS */ tempv = IDA_mem->ida_deltaS; /* Update error for order k. */ - enormS = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_eeS, IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); - errS_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enormS; - if (errS_k > *err_k) { - *err_k = errS_k; + enormS = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_eeS, IDA_mem->ida_ewtS, + IDA_mem->ida_suppressalg); + errS_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enormS; + if (errS_k > *err_k) + { + *err_k = errS_k; check_for_reduction = SUNTRUE; } - terr_k = (IDA_mem->ida_kk+1) * (*err_k); - - if ( IDA_mem->ida_kk > 1 ) { + terr_k = (IDA_mem->ida_kk + 1) * (*err_k); + if (IDA_mem->ida_kk > 1) + { /* Update error at order k-1 */ - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_phiS[IDA_mem->ida_kk], - ONE, IDA_mem->ida_eeS, tempv); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); - - errS_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk-1] * - IDASensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); - - if (errS_km1 > *err_km1) { - *err_km1 = errS_km1; + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, + IDA_mem->ida_phiS[IDA_mem->ida_kk], ONE, + IDA_mem->ida_eeS, tempv); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } + + errS_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 1] * + IDASensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtS, + IDA_mem->ida_suppressalg); + + if (errS_km1 > *err_km1) + { + *err_km1 = errS_km1; check_for_reduction = SUNTRUE; } terr_km1 = IDA_mem->ida_kk * (*err_km1); /* Has an order decrease already been decided in IDATestError? */ if (IDA_mem->ida_knew != IDA_mem->ida_kk) + { check_for_reduction = SUNFALSE; + } - if (check_for_reduction) { - - if ( IDA_mem->ida_kk > 2 ) { - + if (check_for_reduction) + { + if (IDA_mem->ida_kk > 2) + { /* Update error at order k-2 */ - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_phiS[IDA_mem->ida_kk-1], + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, + IDA_mem->ida_phiS[IDA_mem->ida_kk - 1], ONE, tempv, tempv); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - errS_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk-2] * - IDASensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); + errS_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 2] * + IDASensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtS, + IDA_mem->ida_suppressalg); - if (errS_km2 > *err_km2) { - *err_km2 = errS_km2; - } - terr_km2 = (IDA_mem->ida_kk-1) * (*err_km2); + if (errS_km2 > *err_km2) { *err_km2 = errS_km2; } + terr_km2 = (IDA_mem->ida_kk - 1) * (*err_km2); /* Decrease order if errors are reduced */ if (SUNMAX(terr_km1, terr_km2) <= terr_k) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - - } else { - + } + } + else + { /* Decrease order to 1 if errors are reduced by at least 1/2 */ - if (terr_km1 <= (HALF * terr_k) ) + if (terr_km1 <= (HALF * terr_k)) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - + } } - } - } /* Perform error test */ - if (ck * enormS > ONE) return(ERROR_TEST_FAIL); - else return(IDA_SUCCESS); - + if (ck * enormS > ONE) { return (ERROR_TEST_FAIL); } + else { return (IDA_SUCCESS); } } /* @@ -6039,14 +6952,15 @@ static int IDASensTestError(IDAMem IDA_mem, realtype ck, * The return flag can be either IDA_SUCCESS or ERROR_TEST_FAIL. */ -static int IDAQuadSensTestError(IDAMem IDA_mem, realtype ck, - realtype *err_k, realtype *err_km1, realtype *err_km2) +static int IDAQuadSensTestError(IDAMem IDA_mem, sunrealtype ck, + sunrealtype* err_k, sunrealtype* err_km1, + sunrealtype* err_km2) { - realtype enormQS; - realtype errQS_k, errQS_km1, errQS_km2; - realtype terr_k, terr_km1, terr_km2; - N_Vector *tempv; - booleantype check_for_reduction = SUNFALSE; + sunrealtype enormQS; + sunrealtype errQS_k, errQS_km1, errQS_km2; + sunrealtype terr_k, terr_km1, terr_km2; + N_Vector* tempv; + sunbooleantype check_for_reduction = SUNFALSE; int retval; tempv = IDA_mem->ida_yyQS; @@ -6054,66 +6968,75 @@ static int IDAQuadSensTestError(IDAMem IDA_mem, realtype ck, enormQS = IDAQuadSensWrmsNorm(IDA_mem, IDA_mem->ida_eeQS, IDA_mem->ida_ewtQS); errQS_k = IDA_mem->ida_sigma[IDA_mem->ida_kk] * enormQS; - if (errQS_k > *err_k) { - *err_k = errQS_k; + if (errQS_k > *err_k) + { + *err_k = errQS_k; check_for_reduction = SUNTRUE; } - terr_k = (IDA_mem->ida_kk+1) * (*err_k); - - if ( IDA_mem->ida_kk > 1 ) { + terr_k = (IDA_mem->ida_kk + 1) * (*err_k); + if (IDA_mem->ida_kk > 1) + { /* Update error at order k-1 */ - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_phiQS[IDA_mem->ida_kk], - ONE, IDA_mem->ida_eeQS, tempv); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, + IDA_mem->ida_phiQS[IDA_mem->ida_kk], ONE, + IDA_mem->ida_eeQS, tempv); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - errQS_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk-1] * - IDAQuadSensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtQS); + errQS_km1 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 1] * + IDAQuadSensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtQS); - if (errQS_km1 > *err_km1) { - *err_km1 = errQS_km1; + if (errQS_km1 > *err_km1) + { + *err_km1 = errQS_km1; check_for_reduction = SUNTRUE; } terr_km1 = IDA_mem->ida_kk * (*err_km1); /* Has an order decrease already been decided in IDATestError? */ if (IDA_mem->ida_knew != IDA_mem->ida_kk) + { check_for_reduction = SUNFALSE; + } - if (check_for_reduction) { - if ( IDA_mem->ida_kk > 2 ) { - + if (check_for_reduction) + { + if (IDA_mem->ida_kk > 2) + { /* Update error at order k-2 */ - retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_phiQS[IDA_mem->ida_kk-1], + retval = N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, + IDA_mem->ida_phiQS[IDA_mem->ida_kk - 1], ONE, tempv, tempv); - if (retval != IDA_SUCCESS) return (IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - errQS_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk-2] * - IDAQuadSensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtQS); + errQS_km2 = IDA_mem->ida_sigma[IDA_mem->ida_kk - 2] * + IDAQuadSensWrmsNorm(IDA_mem, tempv, IDA_mem->ida_ewtQS); - if (errQS_km2 > *err_km2) { - *err_km2 = errQS_km2; - } - terr_km2 = (IDA_mem->ida_kk-1) * (*err_km2); + if (errQS_km2 > *err_km2) { *err_km2 = errQS_km2; } + terr_km2 = (IDA_mem->ida_kk - 1) * (*err_km2); /* Decrease order if errors are reduced */ if (SUNMAX(terr_km1, terr_km2) <= terr_k) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; - - } else { + } + } + else + { /* Decrease order to 1 if errors are reduced by at least 1/2 */ - if (terr_km1 <= (HALF * terr_k) ) + if (terr_km1 <= (HALF * terr_k)) + { IDA_mem->ida_knew = IDA_mem->ida_kk - 1; + } } } } /* Perform error test */ - if (ck * enormQS > ONE) return(ERROR_TEST_FAIL); - else return(IDA_SUCCESS); + if (ck * enormQS > ONE) { return (ERROR_TEST_FAIL); } + else { return (IDA_SUCCESS); } } + /* * IDARestore * @@ -6121,68 +7044,82 @@ static int IDAQuadSensTestError(IDAMem IDA_mem, realtype ck, * It changes back phi-star to phi (changed in IDASetCoeffs) */ -static void IDARestore(IDAMem IDA_mem, realtype saved_t) +static void IDARestore(IDAMem IDA_mem, sunrealtype saved_t) { int i, j, is; IDA_mem->ida_tn = saved_t; for (i = 1; i <= IDA_mem->ida_kk; i++) - IDA_mem->ida_psi[i-1] = IDA_mem->ida_psi[i] - IDA_mem->ida_hh; - - if (IDA_mem->ida_ns <= IDA_mem->ida_kk) { + { + IDA_mem->ida_psi[i - 1] = IDA_mem->ida_psi[i] - IDA_mem->ida_hh; + } - for(i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) - IDA_mem->ida_cvals[i-IDA_mem->ida_ns] = ONE/IDA_mem->ida_beta[i]; + if (IDA_mem->ida_ns <= IDA_mem->ida_kk) + { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + IDA_mem->ida_cvals[i - IDA_mem->ida_ns] = ONE / IDA_mem->ida_beta[i]; + } - (void) N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, - IDA_mem->ida_cvals, - IDA_mem->ida_phi+IDA_mem->ida_ns, - IDA_mem->ida_phi+IDA_mem->ida_ns); + (void)N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, + IDA_mem->ida_cvals, + IDA_mem->ida_phi + IDA_mem->ida_ns, + IDA_mem->ida_phi + IDA_mem->ida_ns); if (IDA_mem->ida_quadr) - (void) N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, - IDA_mem->ida_cvals, - IDA_mem->ida_phiQ+IDA_mem->ida_ns, - IDA_mem->ida_phiQ+IDA_mem->ida_ns); + { + (void)N_VScaleVectorArray(IDA_mem->ida_kk - IDA_mem->ida_ns + 1, + IDA_mem->ida_cvals, + IDA_mem->ida_phiQ + IDA_mem->ida_ns, + IDA_mem->ida_phiQ + IDA_mem->ida_ns); + } - if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) { + if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { - IDA_mem->ida_cvals[j] = ONE/IDA_mem->ida_beta[i]; + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_cvals[j] = ONE / IDA_mem->ida_beta[i]; j++; } } } - if (IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiS[i][is]; j++; } } - (void) N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, - IDA_mem->ida_Xvecs); + (void)N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Xvecs); } - if (IDA_mem->ida_quadr_sensi) { + if (IDA_mem->ida_quadr_sensi) + { j = 0; - for(i=IDA_mem->ida_ns; i<=IDA_mem->ida_kk; i++) { - for(is=0; isida_Ns; is++) { + for (i = IDA_mem->ida_ns; i <= IDA_mem->ida_kk; i++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiQS[i][is]; j++; } } - (void) N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, - IDA_mem->ida_Xvecs); + (void)N_VScaleVectorArray(j, IDA_mem->ida_cvals, IDA_mem->ida_Xvecs, + IDA_mem->ida_Xvecs); } } - } /* @@ -6233,99 +7170,139 @@ static void IDARestore(IDAMem IDA_mem, realtype saved_t) * IDA_REP_QRHS_ERR */ -static int IDAHandleNFlag(IDAMem IDA_mem, int nflag, realtype err_k, realtype err_km1, - long int *ncfnPtr, int *ncfPtr, long int *netfPtr, int *nefPtr) +static int IDAHandleNFlag(IDAMem IDA_mem, int nflag, sunrealtype err_k, + sunrealtype err_km1, long int* ncfnPtr, int* ncfPtr, + long int* netfPtr, int* nefPtr) { - realtype err_knew; + sunrealtype err_knew; IDA_mem->ida_phase = 1; - if (nflag != ERROR_TEST_FAIL) { - + if (nflag != ERROR_TEST_FAIL) + { /*----------------------- Nonlinear solver failed -----------------------*/ - (*ncfPtr)++; /* local counter for convergence failures */ - (*ncfnPtr)++; /* global counter for convergence failures */ + (*ncfPtr)++; /* local counter for convergence failures */ + (*ncfnPtr)++; /* global counter for convergence failures */ - if (nflag < 0) { /* nonrecoverable failure */ + if (nflag < 0) + { /* nonrecoverable failure */ - if (nflag == IDA_LSOLVE_FAIL) return(IDA_LSOLVE_FAIL); - else if (nflag == IDA_LSETUP_FAIL) return(IDA_LSETUP_FAIL); - else if (nflag == IDA_RES_FAIL) return(IDA_RES_FAIL); - else if (nflag == IDA_QRHS_FAIL) return(IDA_QRHS_FAIL); - else if (nflag == IDA_SRES_FAIL) return(IDA_SRES_FAIL); - else if (nflag == IDA_QSRHS_FAIL) return(IDA_QSRHS_FAIL); - else return(IDA_NLS_FAIL); - - } else { /* recoverable failure */ + if (nflag == IDA_LSOLVE_FAIL) { return (IDA_LSOLVE_FAIL); } + else if (nflag == IDA_LSETUP_FAIL) { return (IDA_LSETUP_FAIL); } + else if (nflag == IDA_RES_FAIL) { return (IDA_RES_FAIL); } + else if (nflag == IDA_CONSTR_FAIL) { return (IDA_CONSTR_FAIL); } + else if (nflag == IDA_QRHS_FAIL) { return (IDA_QRHS_FAIL); } + else if (nflag == IDA_SRES_FAIL) { return (IDA_SRES_FAIL); } + else if (nflag == IDA_QSRHS_FAIL) { return (IDA_QSRHS_FAIL); } + else { return (IDA_NLS_FAIL); } + } + else + { /* recoverable failure */ + + /* Test if there were too many convergence failures or |h| = hmin */ + if ((*ncfPtr == IDA_mem->ida_maxncf) || + (SUNRabs(IDA_mem->ida_hh) <= IDA_mem->ida_hmin * ONEPSM)) + { + if (nflag == IDA_RES_RECVR) { return (IDA_REP_RES_ERR); } + if (nflag == IDA_QRHS_RECVR) { return (IDA_REP_QRHS_ERR); } + if (nflag == IDA_SRES_RECVR) { return (IDA_REP_SRES_ERR); } + if (nflag == IDA_QSRHS_RECVR) { return (IDA_REP_QSRHS_ERR); } + if (nflag == IDA_CONSTR_RECVR) { return (IDA_CONSTR_FAIL); } + return (IDA_CONV_FAIL); + } /* Reduce step size for a new prediction Note that if nflag=IDA_CONSTR_RECVR then rr was already set in IDANls */ - if (nflag != IDA_CONSTR_RECVR) IDA_mem->ida_rr = QUARTER; - IDA_mem->ida_hh *= IDA_mem->ida_rr; + if (nflag != IDA_CONSTR_RECVR) + { + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta_cf, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); + } + IDA_mem->ida_hh *= IDA_mem->ida_eta; - /* Test if there were too many convergence failures */ - if (*ncfPtr < IDA_mem->ida_maxncf) return(PREDICT_AGAIN); - else if (nflag == IDA_RES_RECVR) return(IDA_REP_RES_ERR); - else if (nflag == IDA_QRHS_RECVR) return(IDA_REP_QRHS_ERR); - else if (nflag == IDA_SRES_RECVR) return(IDA_REP_SRES_ERR); - else if (nflag == IDA_QSRHS_RECVR) return(IDA_REP_QSRHS_ERR); - else if (nflag == IDA_CONSTR_RECVR) return(IDA_CONSTR_FAIL); - else return(IDA_CONV_FAIL); + return (PREDICT_AGAIN); } - - } else { - + } + else + { /*----------------- Error Test failed -----------------*/ - (*nefPtr)++; /* local counter for error test failures */ - (*netfPtr)++; /* global counter for error test failures */ - - if (*nefPtr == 1) { + (*nefPtr)++; /* local counter for error test failures */ + (*netfPtr)++; /* global counter for error test failures */ + if (*nefPtr == 1) + { /* On first error test failure, keep current order or lower order by one. Compute new stepsize based on differences of the solution. */ err_knew = (IDA_mem->ida_kk == IDA_mem->ida_knew) ? err_k : err_km1; - IDA_mem->ida_kk = IDA_mem->ida_knew; - IDA_mem->ida_rr = PT9 * SUNRpowerR( TWO * err_knew + PT0001, -ONE/(IDA_mem->ida_kk + 1) ); - IDA_mem->ida_rr = SUNMAX(QUARTER, SUNMIN(PT9,IDA_mem->ida_rr)); - IDA_mem->ida_hh *= IDA_mem->ida_rr; - return(PREDICT_AGAIN); - - } else if (*nefPtr == 2) { + IDA_mem->ida_kk = IDA_mem->ida_knew; + IDA_mem->ida_eta = PT9 * SUNRpowerR(TWO * err_knew + PT0001, + -ONE / (IDA_mem->ida_kk + 1)); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta_min_ef, + SUNMIN(IDA_mem->ida_eta_low, IDA_mem->ida_eta)); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); + IDA_mem->ida_hh *= IDA_mem->ida_eta; + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDAHandleNFlag", + "first-error-test_fail", + "kk = %i, eta = %" RSYM ", h = %" RSYM, + IDA_mem->ida_kk, IDA_mem->ida_eta, IDA_mem->ida_hh); +#endif + return (PREDICT_AGAIN); + } + else if (*nefPtr == 2) + { /* On second error test failure, use current order or decrease order by one. Reduce stepsize by factor of 1/4. */ - IDA_mem->ida_kk = IDA_mem->ida_knew; - IDA_mem->ida_rr = QUARTER; - IDA_mem->ida_hh *= IDA_mem->ida_rr; - return(PREDICT_AGAIN); + IDA_mem->ida_kk = IDA_mem->ida_knew; + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta_min_ef, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); + IDA_mem->ida_hh *= IDA_mem->ida_eta; - } else if (*nefPtr < IDA_mem->ida_maxnef) { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDAHandleNFlag", + "second-error-test-fail", + "kk = %i, eta = %" RSYM ", h = %" RSYM, + IDA_mem->ida_kk, IDA_mem->ida_eta, IDA_mem->ida_hh); +#endif + return (PREDICT_AGAIN); + } + else if (*nefPtr < IDA_mem->ida_maxnef) + { /* On third and subsequent error test failures, set order to 1. Reduce stepsize by factor of 1/4. */ - IDA_mem->ida_kk = 1; - IDA_mem->ida_rr = QUARTER; - IDA_mem->ida_hh *= IDA_mem->ida_rr; - return(PREDICT_AGAIN); - - } else { + IDA_mem->ida_kk = 1; + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta_min_ef, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); + IDA_mem->ida_hh *= IDA_mem->ida_eta; + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDAHandleNFlag", + "error-test-fail", + "kk = %i, eta = %" RSYM ", h = %" RSYM, + IDA_mem->ida_kk, IDA_mem->ida_eta, IDA_mem->ida_hh); +#endif + return (PREDICT_AGAIN); + } + else + { /* Too many error test failures */ - return(IDA_ERR_FAIL); - + return (IDA_ERR_FAIL); } - } - } /* @@ -6341,22 +7318,32 @@ static void IDAReset(IDAMem IDA_mem) IDA_mem->ida_psi[0] = IDA_mem->ida_hh; - N_VScale(IDA_mem->ida_rr, IDA_mem->ida_phi[1], IDA_mem->ida_phi[1]); + N_VScale(IDA_mem->ida_eta, IDA_mem->ida_phi[1], IDA_mem->ida_phi[1]); if (IDA_mem->ida_quadr) - N_VScale(IDA_mem->ida_rr, IDA_mem->ida_phiQ[1], IDA_mem->ida_phiQ[1]); + { + N_VScale(IDA_mem->ida_eta, IDA_mem->ida_phiQ[1], IDA_mem->ida_phiQ[1]); + } if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) - for(is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = IDA_mem->ida_rr; + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + IDA_mem->ida_cvals[is] = IDA_mem->ida_eta; + } + } if (IDA_mem->ida_sensi) - (void) N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - IDA_mem->ida_phiS[1], IDA_mem->ida_phiS[1]); + { + (void)N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, + IDA_mem->ida_phiS[1], IDA_mem->ida_phiS[1]); + } if (IDA_mem->ida_quadr_sensi) - (void) N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - IDA_mem->ida_phiQS[1], IDA_mem->ida_phiQS[1]); + { + (void)N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, + IDA_mem->ida_phiQS[1], IDA_mem->ida_phiQS[1]); + } } /* @@ -6373,22 +7360,24 @@ static void IDAReset(IDAMem IDA_mem) * stepsize and order for the next step, and updates the phi array. */ -static void IDACompleteStep(IDAMem IDA_mem, realtype err_k, realtype err_km1) +static void IDACompleteStep(IDAMem IDA_mem, sunrealtype err_k, sunrealtype err_km1) { int i, j, is, kdiff, action; - realtype terr_k, terr_km1, terr_kp1; - realtype err_knew, err_kp1; - realtype enorm, tmp, hnew; + sunrealtype terr_k, terr_km1, terr_kp1; + sunrealtype err_knew, err_kp1; + sunrealtype enorm, tmp, hnew; N_Vector tempvQ, *tempvS; IDA_mem->ida_nst++; - kdiff = IDA_mem->ida_kk - IDA_mem->ida_kused; + kdiff = IDA_mem->ida_kk - IDA_mem->ida_kused; IDA_mem->ida_kused = IDA_mem->ida_kk; IDA_mem->ida_hused = IDA_mem->ida_hh; - if ( (IDA_mem->ida_knew == IDA_mem->ida_kk - 1) || - (IDA_mem->ida_kk == IDA_mem->ida_maxord) ) + if ((IDA_mem->ida_knew == IDA_mem->ida_kk - 1) || + (IDA_mem->ida_kk == IDA_mem->ida_maxord)) + { IDA_mem->ida_phase = 1; + } /* For the first few steps, until either a step fails, or the order is reduced, or the order reaches its maximum, we raise the order and double @@ -6398,128 +7387,195 @@ static void IDACompleteStep(IDAMem IDA_mem, realtype err_k, realtype err_km1) Note that, after the first step, the order is not increased, as not all of the neccessary information is available yet. */ - if (IDA_mem->ida_phase == 0) { - - if(IDA_mem->ida_nst > 1) { + if (IDA_mem->ida_phase == 0) + { + if (IDA_mem->ida_nst > 1) + { IDA_mem->ida_kk++; hnew = TWO * IDA_mem->ida_hh; - if( (tmp = SUNRabs(hnew) * IDA_mem->ida_hmax_inv) > ONE ) - hnew /= tmp; + if ((tmp = SUNRabs(hnew) * IDA_mem->ida_hmax_inv) > ONE) { hnew /= tmp; } IDA_mem->ida_hh = hnew; } - - } else { - + } + else + { action = UNSET; /* Set action = LOWER/MAINTAIN/RAISE to specify order decision */ - if (IDA_mem->ida_knew == IDA_mem->ida_kk - 1) {action = LOWER; goto takeaction;} - if (IDA_mem->ida_kk == IDA_mem->ida_maxord) {action = MAINTAIN; goto takeaction;} - if ( (IDA_mem->ida_kk + 1 >= IDA_mem->ida_ns ) || - (kdiff == 1)) {action = MAINTAIN; goto takeaction;} + if (IDA_mem->ida_knew == IDA_mem->ida_kk - 1) + { + /* Already decided to reduce the order */ + action = LOWER; + } + else if (IDA_mem->ida_kk == IDA_mem->ida_maxord) + { + /* Already using the maximum order */ + action = MAINTAIN; + } + else if ((IDA_mem->ida_kk + 1 >= IDA_mem->ida_ns) || (kdiff == 1)) + { + /* Step size has not been constant or the order was just raised */ + action = MAINTAIN; + } + else + { + /* Estimate the error at order k+1 */ - /* Estimate the error at order k+1, unless already decided to - reduce order, or already using maximum order, or stepsize has not - been constant, or order was just raised. */ + N_VLinearSum(ONE, IDA_mem->ida_ee, -ONE, + IDA_mem->ida_phi[IDA_mem->ida_kk + 1], IDA_mem->ida_tempv1); + enorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_tempv1, IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); - N_VLinearSum(ONE, IDA_mem->ida_ee, -ONE, - IDA_mem->ida_phi[IDA_mem->ida_kk + 1], IDA_mem->ida_tempv1); - enorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_tempv1, IDA_mem->ida_ewt, - IDA_mem->ida_suppressalg); + if (IDA_mem->ida_errconQ) + { + tempvQ = IDA_mem->ida_ypQ; + N_VLinearSum(ONE, IDA_mem->ida_eeQ, -ONE, + IDA_mem->ida_phiQ[IDA_mem->ida_kk + 1], tempvQ); + enorm = IDAQuadWrmsNormUpdate(IDA_mem, enorm, tempvQ, IDA_mem->ida_ewtQ); + } - if (IDA_mem->ida_errconQ) { - tempvQ = IDA_mem->ida_ypQ; - N_VLinearSum (ONE, IDA_mem->ida_eeQ, -ONE, - IDA_mem->ida_phiQ[IDA_mem->ida_kk+1], tempvQ); - enorm = IDAQuadWrmsNormUpdate(IDA_mem, enorm, tempvQ, IDA_mem->ida_ewtQ); - } + if (IDA_mem->ida_errconS) + { + tempvS = IDA_mem->ida_ypS; - if (IDA_mem->ida_errconS) { - tempvS = IDA_mem->ida_ypS; + (void)N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_eeS, + -ONE, + IDA_mem->ida_phiS[IDA_mem->ida_kk + 1], + tempvS); - (void) N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_eeS, - -ONE, IDA_mem->ida_phiS[IDA_mem->ida_kk+1], - tempvS); + enorm = IDASensWrmsNormUpdate(IDA_mem, enorm, tempvS, IDA_mem->ida_ewtS, + IDA_mem->ida_suppressalg); + } - enorm = IDASensWrmsNormUpdate(IDA_mem, enorm, tempvS, - IDA_mem->ida_ewtS, IDA_mem->ida_suppressalg); - } + if (IDA_mem->ida_errconQS) + { + (void)N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_eeQS, + -ONE, + IDA_mem->ida_phiQS[IDA_mem->ida_kk + 1], + IDA_mem->ida_tempvQS); + + enorm = IDAQuadSensWrmsNormUpdate(IDA_mem, enorm, IDA_mem->ida_tempvQS, + IDA_mem->ida_ewtQS); + } - if (IDA_mem->ida_errconQS) { - (void) N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_eeQS, - -ONE, IDA_mem->ida_phiQS[IDA_mem->ida_kk+1], - IDA_mem->ida_tempvQS); + err_kp1 = enorm / (IDA_mem->ida_kk + 2); - enorm = IDAQuadSensWrmsNormUpdate(IDA_mem, enorm, - IDA_mem->ida_tempvQS, IDA_mem->ida_ewtQS); - } - err_kp1= enorm/(IDA_mem->ida_kk + 2); + /* Choose among orders k-1, k, k+1 using local truncation error norms. */ - /* Choose among orders k-1, k, k+1 using local truncation error norms. */ + terr_k = (IDA_mem->ida_kk + 1) * err_k; + terr_kp1 = (IDA_mem->ida_kk + 2) * err_kp1; - terr_k = (IDA_mem->ida_kk + 1) * err_k; - terr_kp1 = (IDA_mem->ida_kk + 2) * err_kp1; + if (IDA_mem->ida_kk == 1) + { + if (terr_kp1 >= HALF * terr_k) { action = MAINTAIN; } + else { action = RAISE; } - if (IDA_mem->ida_kk == 1) { - if (terr_kp1 >= HALF * terr_k) {action = MAINTAIN; goto takeaction;} - else {action = RAISE; goto takeaction;} - } else { - terr_km1 = IDA_mem->ida_kk * err_km1; - if (terr_km1 <= SUNMIN(terr_k, terr_kp1)) {action = LOWER; goto takeaction;} - else if (terr_kp1 >= terr_k) {action = MAINTAIN; goto takeaction;} - else {action = RAISE; goto takeaction;} +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, + "IDAS::IDACompleteStep", "order-selection-raise", + "terr_k = %" RSYM ", terr_kp1 = %" RSYM, terr_k, + terr_kp1); +#endif + } + else + { + terr_km1 = IDA_mem->ida_kk * err_km1; + if (terr_km1 <= SUNMIN(terr_k, terr_kp1)) { action = LOWER; } + else if (terr_kp1 >= terr_k) { action = MAINTAIN; } + else { action = RAISE; } + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDACompleteStep", + "order-selection-rasie-or-lower", + "terr_km1 = %" RSYM ", terr_k = %" RSYM + ", terr_kp1 = %" RSYM, + terr_km1, terr_k, terr_kp1); +#endif + } } - takeaction: - /* Set the estimated error norm and, on change of order, reset kk. */ - if (action == RAISE) { IDA_mem->ida_kk++; err_knew = err_kp1; } - else if (action == LOWER) { IDA_mem->ida_kk--; err_knew = err_km1; } - else { err_knew = err_k; } - - /* Compute rr = tentative ratio hnew/hh from error norm estimate. - Reduce hh if rr <= 1, double hh if rr >= 2, else leave hh as is. - If hh is reduced, hnew/hh is restricted to be between .5 and .9. */ - - hnew = IDA_mem->ida_hh; - IDA_mem->ida_rr = SUNRpowerR( TWO * err_knew + PT0001, -ONE/(IDA_mem->ida_kk + 1) ); - - if (IDA_mem->ida_rr >= TWO) { - hnew = TWO * IDA_mem->ida_hh; - if( (tmp = SUNRabs(hnew) * IDA_mem->ida_hmax_inv) > ONE ) - hnew /= tmp; - } else if (IDA_mem->ida_rr <= ONE ) { - IDA_mem->ida_rr = SUNMAX(HALF, SUNMIN(PT9,IDA_mem->ida_rr)); - hnew = IDA_mem->ida_hh * IDA_mem->ida_rr; + if (action == RAISE) + { + IDA_mem->ida_kk++; + err_knew = err_kp1; } - - IDA_mem->ida_hh = hnew; + else if (action == LOWER) + { + IDA_mem->ida_kk--; + err_knew = err_km1; + } + else { err_knew = err_k; } + + /* Compute tmp = tentative ratio hnew/hh from error norm estimate. + 1. If eta >= eta_max_fx (default = 2), increase hh to at most eta_max + (default = 2) i.e., double the step size + 2. If eta <= eta_min_fx (default = 1), reduce hh to between eta_min + (default 0.5) and eta_low (default 0.9), + 3. Otherwise leave hh as is i.e., eta = 1. */ + + IDA_mem->ida_eta = ONE; + tmp = SUNRpowerR(TWO * err_knew + PT0001, -ONE / (IDA_mem->ida_kk + 1)); + + if (tmp >= IDA_mem->ida_eta_max_fx) + { + /* Enforce max growth factor bound and max step size */ + IDA_mem->ida_eta = SUNMIN(tmp, IDA_mem->ida_eta_max); + IDA_mem->ida_eta /= SUNMAX(ONE, IDA_mem->ida_eta * SUNRabs(IDA_mem->ida_hh) * + IDA_mem->ida_hmax_inv); + } + else if (tmp <= IDA_mem->ida_eta_min_fx) + { + /* Enforce required reduction factor bound, min reduction bound, and min + step size. Note if eta = eta_min_fx = 1 and ida_eta_low < 1 the step + size is reduced. */ + IDA_mem->ida_eta = SUNMIN(tmp, IDA_mem->ida_eta_low); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta, IDA_mem->ida_eta_min); + IDA_mem->ida_eta = SUNMAX(IDA_mem->ida_eta, + IDA_mem->ida_hmin / SUNRabs(IDA_mem->ida_hh)); + } + IDA_mem->ida_hh *= IDA_mem->ida_eta; + +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_INFO, "IDAS::IDACompleteStep", + "new-step-and-order", + "knew = %i, err_knew = %" RSYM ", eta = %" RSYM + ", hnew = %" RSYM, + IDA_mem->ida_kk, err_knew, IDA_mem->ida_eta, + IDA_mem->ida_hh); +#endif } /* end of phase if block */ /* Save ee for possible order increase on next step */ - if (IDA_mem->ida_kused < IDA_mem->ida_maxord) { + if (IDA_mem->ida_kused < IDA_mem->ida_maxord) + { N_VScale(ONE, IDA_mem->ida_ee, IDA_mem->ida_phi[IDA_mem->ida_kused + 1]); if (IDA_mem->ida_quadr) - N_VScale(ONE, IDA_mem->ida_eeQ, IDA_mem->ida_phiQ[IDA_mem->ida_kused+1]); + { + N_VScale(ONE, IDA_mem->ida_eeQ, IDA_mem->ida_phiQ[IDA_mem->ida_kused + 1]); + } if (IDA_mem->ida_sensi || IDA_mem->ida_quadr_sensi) - for (is=0; isida_Ns; is++) - IDA_mem->ida_cvals[is] = ONE; + { + for (is = 0; is < IDA_mem->ida_Ns; is++) { IDA_mem->ida_cvals[is] = ONE; } + } if (IDA_mem->ida_sensi) - (void) N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - IDA_mem->ida_eeS, - IDA_mem->ida_phiS[IDA_mem->ida_kused+1]); + { + (void)N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, + IDA_mem->ida_eeS, + IDA_mem->ida_phiS[IDA_mem->ida_kused + 1]); + } if (IDA_mem->ida_quadr_sensi) - (void) N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, - IDA_mem->ida_eeQS, - IDA_mem->ida_phiQS[IDA_mem->ida_kused+1]); + { + (void)N_VScaleVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_cvals, + IDA_mem->ida_eeQS, + IDA_mem->ida_phiQS[IDA_mem->ida_kused + 1]); + } } /* Update phi arrays */ @@ -6530,71 +7586,70 @@ static void IDACompleteStep(IDAMem IDA_mem, realtype err_k, realtype err_km1) IDA_mem->ida_Zvecs[0] = IDA_mem->ida_ee; IDA_mem->ida_Xvecs[0] = IDA_mem->ida_phi[IDA_mem->ida_kused]; - for (j=1; j<=IDA_mem->ida_kused; j++) { - IDA_mem->ida_Zvecs[j] = IDA_mem->ida_phi[IDA_mem->ida_kused-j+1]; - IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phi[IDA_mem->ida_kused-j]; + for (j = 1; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Zvecs[j] = IDA_mem->ida_phi[IDA_mem->ida_kused - j + 1]; + IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phi[IDA_mem->ida_kused - j]; } - (void) N_VLinearSumVectorArray(IDA_mem->ida_kused+1, - ONE, IDA_mem->ida_Xvecs, - ONE, IDA_mem->ida_Zvecs, - IDA_mem->ida_Xvecs); - - if (IDA_mem->ida_quadr) { + (void)N_VLinearSumVectorArray(IDA_mem->ida_kused + 1, ONE, IDA_mem->ida_Xvecs, + ONE, IDA_mem->ida_Zvecs, IDA_mem->ida_Xvecs); + if (IDA_mem->ida_quadr) + { IDA_mem->ida_Zvecs[0] = IDA_mem->ida_eeQ; IDA_mem->ida_Xvecs[0] = IDA_mem->ida_phiQ[IDA_mem->ida_kused]; - for (j=1; j<=IDA_mem->ida_kused; j++) { - IDA_mem->ida_Zvecs[j] = IDA_mem->ida_phiQ[IDA_mem->ida_kused-j+1]; - IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiQ[IDA_mem->ida_kused-j]; + for (j = 1; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Zvecs[j] = IDA_mem->ida_phiQ[IDA_mem->ida_kused - j + 1]; + IDA_mem->ida_Xvecs[j] = IDA_mem->ida_phiQ[IDA_mem->ida_kused - j]; } - (void) N_VLinearSumVectorArray(IDA_mem->ida_kused+1, - ONE, IDA_mem->ida_Xvecs, - ONE, IDA_mem->ida_Zvecs, - IDA_mem->ida_Xvecs); + (void)N_VLinearSumVectorArray(IDA_mem->ida_kused + 1, ONE, IDA_mem->ida_Xvecs, + ONE, IDA_mem->ida_Zvecs, IDA_mem->ida_Xvecs); } - if (IDA_mem->ida_sensi) { - - i=0; - for (is=0; isida_Ns; is++) { + if (IDA_mem->ida_sensi) + { + i = 0; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Zvecs[i] = IDA_mem->ida_eeS[is]; IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiS[IDA_mem->ida_kused][is]; i++; - for (j=1; j<=IDA_mem->ida_kused; j++) { - IDA_mem->ida_Zvecs[i] = IDA_mem->ida_phiS[IDA_mem->ida_kused-j+1][is]; - IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiS[IDA_mem->ida_kused-j][is]; + for (j = 1; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Zvecs[i] = IDA_mem->ida_phiS[IDA_mem->ida_kused - j + 1][is]; + IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiS[IDA_mem->ida_kused - j][is]; i++; } } - (void) N_VLinearSumVectorArray(IDA_mem->ida_Ns*(IDA_mem->ida_kused+1), - ONE, IDA_mem->ida_Xvecs, - ONE, IDA_mem->ida_Zvecs, - IDA_mem->ida_Xvecs); + (void)N_VLinearSumVectorArray(IDA_mem->ida_Ns * (IDA_mem->ida_kused + 1), + ONE, IDA_mem->ida_Xvecs, ONE, + IDA_mem->ida_Zvecs, IDA_mem->ida_Xvecs); } - if (IDA_mem->ida_quadr_sensi) { - - i=0; - for (is=0; isida_Ns; is++) { + if (IDA_mem->ida_quadr_sensi) + { + i = 0; + for (is = 0; is < IDA_mem->ida_Ns; is++) + { IDA_mem->ida_Zvecs[i] = IDA_mem->ida_eeQS[is]; IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiQS[IDA_mem->ida_kused][is]; i++; - for (j=1; j<=IDA_mem->ida_kused; j++) { - IDA_mem->ida_Zvecs[i] = IDA_mem->ida_phiQS[IDA_mem->ida_kused-j+1][is]; - IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiQS[IDA_mem->ida_kused-j][is]; + for (j = 1; j <= IDA_mem->ida_kused; j++) + { + IDA_mem->ida_Zvecs[i] = IDA_mem->ida_phiQS[IDA_mem->ida_kused - j + 1][is]; + IDA_mem->ida_Xvecs[i] = IDA_mem->ida_phiQS[IDA_mem->ida_kused - j][is]; i++; } } - (void) N_VLinearSumVectorArray(IDA_mem->ida_Ns*(IDA_mem->ida_kused+1), - ONE, IDA_mem->ida_Xvecs, - ONE, IDA_mem->ida_Zvecs, - IDA_mem->ida_Xvecs); + (void)N_VLinearSumVectorArray(IDA_mem->ida_Ns * (IDA_mem->ida_kused + 1), + ONE, IDA_mem->ida_Xvecs, ONE, + IDA_mem->ida_Zvecs, IDA_mem->ida_Xvecs); } - } /* @@ -6620,59 +7675,64 @@ static void IDACompleteStep(IDAMem IDA_mem, realtype err_k, realtype err_km1) * IDA_BAD_T if t is not within the interval of the last step taken. */ -int IDAGetSolution(void *ida_mem, realtype t, N_Vector yret, N_Vector ypret) +int IDAGetSolution(void* ida_mem, sunrealtype t, N_Vector yret, N_Vector ypret) { IDAMem IDA_mem; - realtype tfuzz, tp, delt, c, d, gam; + sunrealtype tfuzz, tp, delt, c, d, gam; int j, kord, retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSolution", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Check t for legality. Here tn - hused is t_{n-1}. */ - tfuzz = HUNDRED * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); - if (IDA_mem->ida_hh < ZERO) tfuzz = - tfuzz; + tfuzz = HUNDRED * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)); + if (IDA_mem->ida_hh < ZERO) { tfuzz = -tfuzz; } tp = IDA_mem->ida_tn - IDA_mem->ida_hused - tfuzz; - if ((t - tp)*IDA_mem->ida_hh < ZERO) { - IDAProcessError(IDA_mem, IDA_BAD_T, "IDAS", "IDAGetSolution", MSG_BAD_T, t, - IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); - return(IDA_BAD_T); + if ((t - tp) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_BAD_T, __LINE__, __func__, __FILE__, MSG_BAD_T, + t, IDA_mem->ida_tn - IDA_mem->ida_hused, IDA_mem->ida_tn); + return (IDA_BAD_T); } /* Initialize kord = (kused or 1). */ kord = IDA_mem->ida_kused; - if (IDA_mem->ida_kused == 0) kord = 1; + if (IDA_mem->ida_kused == 0) { kord = 1; } /* Accumulate multiples of columns phi[j] into yret and ypret. */ delt = t - IDA_mem->ida_tn; - c = ONE; d = ZERO; - gam = delt / IDA_mem->ida_psi[0]; + c = ONE; + d = ZERO; + gam = delt / IDA_mem->ida_psi[0]; IDA_mem->ida_cvals[0] = c; - for (j=1; j <= kord; j++) { - d = d*gam + c / IDA_mem->ida_psi[j-1]; - c = c*gam; - gam = (delt + IDA_mem->ida_psi[j-1]) / IDA_mem->ida_psi[j]; + for (j = 1; j <= kord; j++) + { + d = d * gam + c / IDA_mem->ida_psi[j - 1]; + c = c * gam; + gam = (delt + IDA_mem->ida_psi[j - 1]) / IDA_mem->ida_psi[j]; - IDA_mem->ida_cvals[j] = c; - IDA_mem->ida_dvals[j-1] = d; + IDA_mem->ida_cvals[j] = c; + IDA_mem->ida_dvals[j - 1] = d; } - retval = N_VLinearCombination(kord+1, IDA_mem->ida_cvals, - IDA_mem->ida_phi, yret); - if (retval != IDA_SUCCESS) return(IDA_VECTOROP_ERR); + retval = N_VLinearCombination(kord + 1, IDA_mem->ida_cvals, IDA_mem->ida_phi, + yret); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - retval = N_VLinearCombination(kord, IDA_mem->ida_dvals, - IDA_mem->ida_phi+1, ypret); - if (retval != IDA_SUCCESS) return(IDA_VECTOROP_ERR); + retval = N_VLinearCombination(kord, IDA_mem->ida_dvals, IDA_mem->ida_phi + 1, + ypret); + if (retval != IDA_SUCCESS) { return (IDA_VECTOROP_ERR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -6694,15 +7754,15 @@ int IDAGetSolution(void *ida_mem, realtype t, N_Vector yret, N_Vector ypret) * mask = suppressalg otherwise. */ -realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, - booleantype mask) +sunrealtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, + sunbooleantype mask) { - realtype nrm; + sunrealtype nrm; - if (mask) nrm = N_VWrmsNormMask(x, w, IDA_mem->ida_id); - else nrm = N_VWrmsNorm(x, w); + if (mask) { nrm = N_VWrmsNormMask(x, w, IDA_mem->ida_id); } + else { nrm = N_VWrmsNorm(x, w); } - return(nrm); + return (nrm); } /* @@ -6719,22 +7779,27 @@ realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, * Declared global for use in the computation of IC for sensitivities. */ -realtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector *xS, N_Vector *wS, - booleantype mask) +sunrealtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector* xS, N_Vector* wS, + sunbooleantype mask) { int is; - realtype nrm; + sunrealtype nrm; if (mask) - (void) N_VWrmsNormMaskVectorArray(IDA_mem->ida_Ns, xS, wS, - IDA_mem->ida_id, IDA_mem->ida_cvals); + { + (void)N_VWrmsNormMaskVectorArray(IDA_mem->ida_Ns, xS, wS, IDA_mem->ida_id, + IDA_mem->ida_cvals); + } else - (void) N_VWrmsNormVectorArray(IDA_mem->ida_Ns, xS, wS, - IDA_mem->ida_cvals); + { + (void)N_VWrmsNormVectorArray(IDA_mem->ida_Ns, xS, wS, IDA_mem->ida_cvals); + } nrm = IDA_mem->ida_cvals[0]; - for (is=1; isida_Ns; is++) - if ( IDA_mem->ida_cvals[is] > nrm ) nrm = IDA_mem->ida_cvals[is]; + for (is = 1; is < IDA_mem->ida_Ns; is++) + { + if (IDA_mem->ida_cvals[is] > nrm) { nrm = IDA_mem->ida_cvals[is]; } + } return (nrm); } @@ -6748,17 +7813,19 @@ realtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector *xS, N_Vector *wS, * max { wrms(xQS[0],wQS[0]) ... wrms(xQS[Ns-1],wQS[Ns-1]) } */ -static realtype IDAQuadSensWrmsNorm(IDAMem IDA_mem, N_Vector *xQS, N_Vector *wQS) +static sunrealtype IDAQuadSensWrmsNorm(IDAMem IDA_mem, N_Vector* xQS, + N_Vector* wQS) { int is; - realtype nrm; + sunrealtype nrm; - (void) N_VWrmsNormVectorArray(IDA_mem->ida_Ns, xQS, wQS, - IDA_mem->ida_cvals); + (void)N_VWrmsNormVectorArray(IDA_mem->ida_Ns, xQS, wQS, IDA_mem->ida_cvals); nrm = IDA_mem->ida_cvals[0]; - for (is=1; isida_Ns; is++) - if ( IDA_mem->ida_cvals[is] > nrm ) nrm = IDA_mem->ida_cvals[is]; + for (is = 1; is < IDA_mem->ida_Ns; is++) + { + if (IDA_mem->ida_cvals[is] > nrm) { nrm = IDA_mem->ida_cvals[is]; } + } return (nrm); } @@ -6769,14 +7836,15 @@ static realtype IDAQuadSensWrmsNorm(IDAMem IDA_mem, N_Vector *xQS, N_Vector *wQS * Updates the norm old_nrm to account for all quadratures. */ -static realtype IDAQuadWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector xQ, N_Vector wQ) +static sunrealtype IDAQuadWrmsNormUpdate(SUNDIALS_MAYBE_UNUSED IDAMem IDA_mem, + sunrealtype old_nrm, N_Vector xQ, + N_Vector wQ) { - realtype qnrm; + sunrealtype qnrm; qnrm = N_VWrmsNorm(xQ, wQ); - if (old_nrm > qnrm) return(old_nrm); - else return(qnrm); + if (old_nrm > qnrm) { return (old_nrm); } + else { return (qnrm); } } /* @@ -6788,25 +7856,24 @@ static realtype IDAQuadWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, * IC for sensitivities, */ -realtype IDASensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector *xS, N_Vector *wS, - booleantype mask) +sunrealtype IDASensWrmsNormUpdate(IDAMem IDA_mem, sunrealtype old_nrm, + N_Vector* xS, N_Vector* wS, sunbooleantype mask) { - realtype snrm; + sunrealtype snrm; snrm = IDASensWrmsNorm(IDA_mem, xS, wS, mask); - if (old_nrm > snrm) return(old_nrm); - else return(snrm); + if (old_nrm > snrm) { return (old_nrm); } + else { return (snrm); } } -static realtype IDAQuadSensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector *xQS, N_Vector *wQS) +static sunrealtype IDAQuadSensWrmsNormUpdate(IDAMem IDA_mem, sunrealtype old_nrm, + N_Vector* xQS, N_Vector* wQS) { - realtype qsnrm; + sunrealtype qsnrm; qsnrm = IDAQuadSensWrmsNorm(IDA_mem, xQS, wQS); - if (old_nrm > qsnrm) return(old_nrm); - else return(qsnrm); + if (old_nrm > qsnrm) { return (old_nrm); } + else { return (qsnrm); } } /* @@ -6830,49 +7897,54 @@ static realtype IDAQuadSensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, static int IDARcheck1(IDAMem IDA_mem) { int i, retval; - realtype smallh, hratio, tplus; - booleantype zroot; + sunrealtype smallh, hratio, tplus; + sunbooleantype zroot; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) - IDA_mem->ida_iroots[i] = 0; - IDA_mem->ida_tlo = IDA_mem->ida_tn; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) { IDA_mem->ida_iroots[i] = 0; } + IDA_mem->ida_tlo = IDA_mem->ida_tn; IDA_mem->ida_ttol = ((SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)) * IDA_mem->ida_uround * HUNDRED); /* Evaluate g at initial t and check for zero values. */ - retval = IDA_mem->ida_gfun(IDA_mem->ida_tlo, IDA_mem->ida_phi[0], IDA_mem->ida_phi[1], - IDA_mem->ida_glo, IDA_mem->ida_user_data); + retval = IDA_mem->ida_gfun(IDA_mem->ida_tlo, IDA_mem->ida_phi[0], + IDA_mem->ida_phi[1], IDA_mem->ida_glo, + IDA_mem->ida_user_data); IDA_mem->ida_nge = 1; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } zroot = SUNFALSE; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if (SUNRabs(IDA_mem->ida_glo[i]) == ZERO) { - zroot = SUNTRUE; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (SUNRabs(IDA_mem->ida_glo[i]) == ZERO) + { + zroot = SUNTRUE; IDA_mem->ida_gactive[i] = SUNFALSE; } } - if (!zroot) return(IDA_SUCCESS); + if (!zroot) { return (IDA_SUCCESS); } /* Some g_i is zero at t0; look at g at t0+(small increment). */ hratio = SUNMAX(IDA_mem->ida_ttol / SUNRabs(IDA_mem->ida_hh), PT1); smallh = hratio * IDA_mem->ida_hh; - tplus = IDA_mem->ida_tlo + smallh; - N_VLinearSum(ONE, IDA_mem->ida_phi[0], smallh, IDA_mem->ida_phi[1], IDA_mem->ida_yy); + tplus = IDA_mem->ida_tlo + smallh; + N_VLinearSum(ONE, IDA_mem->ida_phi[0], smallh, IDA_mem->ida_phi[1], + IDA_mem->ida_yy); retval = IDA_mem->ida_gfun(tplus, IDA_mem->ida_yy, IDA_mem->ida_phi[1], IDA_mem->ida_ghi, IDA_mem->ida_user_data); IDA_mem->ida_nge++; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } /* We check now only the components of g which were exactly 0.0 at t0 * to see if we can 'activate' them. */ - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if (!IDA_mem->ida_gactive[i] && SUNRabs(IDA_mem->ida_ghi[i]) != ZERO) { + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (!IDA_mem->ida_gactive[i] && SUNRabs(IDA_mem->ida_ghi[i]) != ZERO) + { IDA_mem->ida_gactive[i] = SUNTRUE; - IDA_mem->ida_glo[i] = IDA_mem->ida_ghi[i]; + IDA_mem->ida_glo[i] = IDA_mem->ida_ghi[i]; } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -6899,62 +7971,73 @@ static int IDARcheck1(IDAMem IDA_mem) static int IDARcheck2(IDAMem IDA_mem) { int i, retval; - realtype smallh, hratio, tplus; - booleantype zroot; + sunrealtype smallh, hratio, tplus; + sunbooleantype zroot; - if (IDA_mem->ida_irfnd == 0) return(IDA_SUCCESS); + if (IDA_mem->ida_irfnd == 0) { return (IDA_SUCCESS); } - (void) IDAGetSolution(IDA_mem, IDA_mem->ida_tlo, IDA_mem->ida_yy, IDA_mem->ida_yp); + (void)IDAGetSolution(IDA_mem, IDA_mem->ida_tlo, IDA_mem->ida_yy, + IDA_mem->ida_yp); retval = IDA_mem->ida_gfun(IDA_mem->ida_tlo, IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_glo, IDA_mem->ida_user_data); IDA_mem->ida_nge++; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } zroot = SUNFALSE; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) { IDA_mem->ida_iroots[i] = 0; } for (i = 0; i < IDA_mem->ida_nrtfn; i++) - IDA_mem->ida_iroots[i] = 0; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if (!IDA_mem->ida_gactive[i]) continue; - if (SUNRabs(IDA_mem->ida_glo[i]) == ZERO) { - zroot = SUNTRUE; + { + if (!IDA_mem->ida_gactive[i]) { continue; } + if (SUNRabs(IDA_mem->ida_glo[i]) == ZERO) + { + zroot = SUNTRUE; IDA_mem->ida_iroots[i] = 1; } } - if (!zroot) return(IDA_SUCCESS); + if (!zroot) { return (IDA_SUCCESS); } /* One or more g_i has a zero at tlo. Check g at tlo+smallh. */ IDA_mem->ida_ttol = ((SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)) * IDA_mem->ida_uround * HUNDRED); smallh = (IDA_mem->ida_hh > ZERO) ? IDA_mem->ida_ttol : -IDA_mem->ida_ttol; - tplus = IDA_mem->ida_tlo + smallh; - if ( (tplus - IDA_mem->ida_tn)*IDA_mem->ida_hh >= ZERO) { - hratio = smallh/IDA_mem->ida_hh; - N_VLinearSum(ONE, IDA_mem->ida_yy, - hratio, IDA_mem->ida_phi[1], IDA_mem->ida_yy); - } else { - (void) IDAGetSolution(IDA_mem, tplus, IDA_mem->ida_yy, IDA_mem->ida_yp); + tplus = IDA_mem->ida_tlo + smallh; + if ((tplus - IDA_mem->ida_tn) * IDA_mem->ida_hh >= ZERO) + { + hratio = smallh / IDA_mem->ida_hh; + N_VLinearSum(ONE, IDA_mem->ida_yy, hratio, IDA_mem->ida_phi[1], + IDA_mem->ida_yy); + } + else + { + (void)IDAGetSolution(IDA_mem, tplus, IDA_mem->ida_yy, IDA_mem->ida_yp); } retval = IDA_mem->ida_gfun(tplus, IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_ghi, IDA_mem->ida_user_data); IDA_mem->ida_nge++; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } /* Check for close roots (error return), for a new zero at tlo+smallh, and for a g_i that changed from zero to nonzero. */ zroot = SUNFALSE; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if (!IDA_mem->ida_gactive[i]) continue; - if (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) { - if (IDA_mem->ida_iroots[i] == 1) return(CLOSERT); - zroot = SUNTRUE; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (!IDA_mem->ida_gactive[i]) { continue; } + if (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) + { + if (IDA_mem->ida_iroots[i] == 1) { return (CLOSERT); } + zroot = SUNTRUE; IDA_mem->ida_iroots[i] = 1; - } else { + } + else + { if (IDA_mem->ida_iroots[i] == 1) + { IDA_mem->ida_glo[i] = IDA_mem->ida_ghi[i]; + } } } - if (zroot) return(RTFOUND); - return(IDA_SUCCESS); + if (zroot) { return (RTFOUND); } + return (IDA_SUCCESS); } /* @@ -6975,43 +8058,56 @@ static int IDARcheck3(IDAMem IDA_mem) int i, ier, retval; /* Set thi = tn or tout, whichever comes first. */ - if (IDA_mem->ida_taskc == IDA_ONE_STEP) IDA_mem->ida_thi = IDA_mem->ida_tn; - if (IDA_mem->ida_taskc == IDA_NORMAL) { - IDA_mem->ida_thi = ((IDA_mem->ida_toutc - IDA_mem->ida_tn)*IDA_mem->ida_hh >= ZERO) - ? IDA_mem->ida_tn : IDA_mem->ida_toutc; + if (IDA_mem->ida_taskc == IDA_ONE_STEP) + { + IDA_mem->ida_thi = IDA_mem->ida_tn; + } + if (IDA_mem->ida_taskc == IDA_NORMAL) + { + IDA_mem->ida_thi = + ((IDA_mem->ida_toutc - IDA_mem->ida_tn) * IDA_mem->ida_hh >= ZERO) + ? IDA_mem->ida_tn + : IDA_mem->ida_toutc; } /* Get y and y' at thi. */ - (void) IDAGetSolution(IDA_mem, IDA_mem->ida_thi, IDA_mem->ida_yy, IDA_mem->ida_yp); - + (void)IDAGetSolution(IDA_mem, IDA_mem->ida_thi, IDA_mem->ida_yy, + IDA_mem->ida_yp); /* Set ghi = g(thi) and call IDARootfind to search (tlo,thi) for roots. */ - retval = IDA_mem->ida_gfun(IDA_mem->ida_thi, IDA_mem->ida_yy, - IDA_mem->ida_yp, IDA_mem->ida_ghi, - IDA_mem->ida_user_data); + retval = IDA_mem->ida_gfun(IDA_mem->ida_thi, IDA_mem->ida_yy, IDA_mem->ida_yp, + IDA_mem->ida_ghi, IDA_mem->ida_user_data); IDA_mem->ida_nge++; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } IDA_mem->ida_ttol = ((SUNRabs(IDA_mem->ida_tn) + SUNRabs(IDA_mem->ida_hh)) * IDA_mem->ida_uround * HUNDRED); - ier = IDARootfind(IDA_mem); - if (ier == IDA_RTFUNC_FAIL) return(IDA_RTFUNC_FAIL); - for(i=0; iida_nrtfn; i++) { - if(!IDA_mem->ida_gactive[i] && IDA_mem->ida_grout[i] != ZERO) + ier = IDARootfind(IDA_mem); + if (ier == IDA_RTFUNC_FAIL) { return (IDA_RTFUNC_FAIL); } + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (!IDA_mem->ida_gactive[i] && IDA_mem->ida_grout[i] != ZERO) + { IDA_mem->ida_gactive[i] = SUNTRUE; + } } IDA_mem->ida_tlo = IDA_mem->ida_trout; for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_glo[i] = IDA_mem->ida_grout[i]; + } /* If no root found, return IDA_SUCCESS. */ - if (ier == IDA_SUCCESS) return(IDA_SUCCESS); + if (ier == IDA_SUCCESS) { return (IDA_SUCCESS); } /* If a root was found, interpolate to get y(trout) and return. */ - (void) IDAGetSolution(IDA_mem, IDA_mem->ida_trout, IDA_mem->ida_yy, IDA_mem->ida_yp); - return(RTFOUND); + (void)IDAGetSolution(IDA_mem, IDA_mem->ida_trout, IDA_mem->ida_yy, + IDA_mem->ida_yp); + return (RTFOUND); } +#define DIFFERENT_SIGN(a, b) (((a) < 0 && (b) > 0) || ((a) > 0 && (b) < 0)) + /* * IDARootfind * @@ -7092,30 +8188,38 @@ static int IDARcheck3(IDAMem IDA_mem) static int IDARootfind(IDAMem IDA_mem) { - realtype alph, tmid, gfrac, maxfrac, fracint, fracsub; + sunrealtype alph, tmid, gfrac, maxfrac, fracint, fracsub; int i, retval, imax, side, sideprev; - booleantype zroot, sgnchg; + sunbooleantype zroot, sgnchg; imax = 0; /* First check for change in sign in ghi or for a zero in ghi. */ maxfrac = ZERO; - zroot = SUNFALSE; - sgnchg = SUNFALSE; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if(!IDA_mem->ida_gactive[i]) continue; - if (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) { - if(IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) { + zroot = SUNFALSE; + sgnchg = SUNFALSE; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (!IDA_mem->ida_gactive[i]) { continue; } + if (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) + { + if (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) + { zroot = SUNTRUE; } - } else { - if ( (IDA_mem->ida_glo[i] * IDA_mem->ida_ghi[i] < ZERO) && - (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) ) { - gfrac = SUNRabs(IDA_mem->ida_ghi[i] / (IDA_mem->ida_ghi[i] - IDA_mem->ida_glo[i])); - if (gfrac > maxfrac) { - sgnchg = SUNTRUE; + } + else + { + if ((DIFFERENT_SIGN(IDA_mem->ida_glo[i], IDA_mem->ida_ghi[i])) && + (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO)) + { + gfrac = SUNRabs(IDA_mem->ida_ghi[i] / + (IDA_mem->ida_ghi[i] - IDA_mem->ida_glo[i])); + if (gfrac > maxfrac) + { + sgnchg = SUNTRUE; maxfrac = gfrac; - imax = i; + imax = i; } } } @@ -7123,19 +8227,25 @@ static int IDARootfind(IDAMem IDA_mem) /* If no sign change was found, reset trout and grout. Then return IDA_SUCCESS if no zero was found, or set iroots and return RTFOUND. */ - if (!sgnchg) { + if (!sgnchg) + { IDA_mem->ida_trout = IDA_mem->ida_thi; for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_grout[i] = IDA_mem->ida_ghi[i]; - if (!zroot) return(IDA_SUCCESS); - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { + } + if (!zroot) { return (IDA_SUCCESS); } + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_iroots[i] = 0; - if(!IDA_mem->ida_gactive[i]) continue; - if ( (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) && - (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) ) - IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1:1; + if (!IDA_mem->ida_gactive[i]) { continue; } + if ((SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) && + (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO)) + { + IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1 : 1; + } } - return(RTFOUND); + return (RTFOUND); } /* Initialize alph to avoid compiler warning */ @@ -7143,12 +8253,16 @@ static int IDARootfind(IDAMem IDA_mem) /* A sign change was found. Loop to locate nearest root. */ - side = 0; sideprev = -1; - for(;;) { /* Looping point */ + side = 0; + sideprev = -1; + for (;;) + { /* Looping point */ /* If interval size is already less than tolerance ttol, break. */ - if (SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) <= IDA_mem->ida_ttol) - break; + if (SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) <= IDA_mem->ida_ttol) + { + break; + } /* Set weight alph. On the first two passes, set alph = 1. Thereafter, reset alph @@ -7160,75 +8274,91 @@ static int IDARootfind(IDAMem IDA_mem) The next guess tmid is the secant method value if alph = 1, but is closer to tlo if alph < 1, and closer to thi if alph > 1. */ - if (sideprev == side) { - alph = (side == 2) ? alph*TWO : alph*HALF; - } else { - alph = ONE; - } + if (sideprev == side) { alph = (side == 2) ? alph * TWO : alph * HALF; } + else { alph = ONE; } /* Set next root approximation tmid and get g(tmid). If tmid is too close to tlo or thi, adjust it inward, by a fractional distance that is between 0.1 and 0.5. */ - tmid = IDA_mem->ida_thi - (IDA_mem->ida_thi - IDA_mem->ida_tlo) * - IDA_mem->ida_ghi[imax] / (IDA_mem->ida_ghi[imax] - alph*IDA_mem->ida_glo[imax]); - if (SUNRabs(tmid - IDA_mem->ida_tlo) < HALF * IDA_mem->ida_ttol) { + tmid = IDA_mem->ida_thi - + (IDA_mem->ida_thi - IDA_mem->ida_tlo) * IDA_mem->ida_ghi[imax] / + (IDA_mem->ida_ghi[imax] - alph * IDA_mem->ida_glo[imax]); + if (SUNRabs(tmid - IDA_mem->ida_tlo) < HALF * IDA_mem->ida_ttol) + { fracint = SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) / IDA_mem->ida_ttol; - fracsub = (fracint > FIVE) ? PT1 : HALF/fracint; - tmid = IDA_mem->ida_tlo + fracsub*(IDA_mem->ida_thi - IDA_mem->ida_tlo); + fracsub = (fracint > FIVE) ? PT1 : HALF / fracint; + tmid = IDA_mem->ida_tlo + fracsub * (IDA_mem->ida_thi - IDA_mem->ida_tlo); } - if (SUNRabs(IDA_mem->ida_thi - tmid) < HALF * IDA_mem->ida_ttol) { + if (SUNRabs(IDA_mem->ida_thi - tmid) < HALF * IDA_mem->ida_ttol) + { fracint = SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) / IDA_mem->ida_ttol; - fracsub = (fracint > FIVE) ? PT1 : HALF/fracint; - tmid = IDA_mem->ida_thi - fracsub*(IDA_mem->ida_thi - IDA_mem->ida_tlo); + fracsub = (fracint > FIVE) ? PT1 : HALF / fracint; + tmid = IDA_mem->ida_thi - fracsub * (IDA_mem->ida_thi - IDA_mem->ida_tlo); } - (void) IDAGetSolution(IDA_mem, tmid, IDA_mem->ida_yy, IDA_mem->ida_yp); + (void)IDAGetSolution(IDA_mem, tmid, IDA_mem->ida_yy, IDA_mem->ida_yp); retval = IDA_mem->ida_gfun(tmid, IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_grout, IDA_mem->ida_user_data); IDA_mem->ida_nge++; - if (retval != 0) return(IDA_RTFUNC_FAIL); + if (retval != 0) { return (IDA_RTFUNC_FAIL); } /* Check to see in which subinterval g changes sign, and reset imax. Set side = 1 if sign change is on low side, or 2 if on high side. */ - maxfrac = ZERO; - zroot = SUNFALSE; - sgnchg = SUNFALSE; + maxfrac = ZERO; + zroot = SUNFALSE; + sgnchg = SUNFALSE; sideprev = side; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - if(!IDA_mem->ida_gactive[i]) continue; - if (SUNRabs(IDA_mem->ida_grout[i]) == ZERO) { - if(IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + if (!IDA_mem->ida_gactive[i]) { continue; } + if (SUNRabs(IDA_mem->ida_grout[i]) == ZERO) + { + if (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) + { zroot = SUNTRUE; - } else { - if ( (IDA_mem->ida_glo[i] * IDA_mem->ida_grout[i] < ZERO) && - (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) ) { + } + } + else + { + if ((DIFFERENT_SIGN(IDA_mem->ida_glo[i], IDA_mem->ida_grout[i])) && + (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO)) + { gfrac = SUNRabs(IDA_mem->ida_grout[i] / (IDA_mem->ida_grout[i] - IDA_mem->ida_glo[i])); - if (gfrac > maxfrac) { - sgnchg = SUNTRUE; + if (gfrac > maxfrac) + { + sgnchg = SUNTRUE; maxfrac = gfrac; - imax = i; + imax = i; } } } } - if (sgnchg) { + if (sgnchg) + { /* Sign change found in (tlo,tmid); replace thi with tmid. */ IDA_mem->ida_thi = tmid; for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_ghi[i] = IDA_mem->ida_grout[i]; + } side = 1; /* Stop at root thi if converged; otherwise loop. */ if (SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) <= IDA_mem->ida_ttol) + { break; - continue; /* Return to looping point. */ + } + continue; /* Return to looping point. */ } - if (zroot) { + if (zroot) + { /* No sign change in (tlo,tmid), but g = 0 at tmid; return root tmid. */ IDA_mem->ida_thi = tmid; for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_ghi[i] = IDA_mem->ida_grout[i]; + } break; } @@ -7236,28 +8366,37 @@ static int IDARootfind(IDAMem IDA_mem) Sign change must be in (tmid,thi). Replace tlo with tmid. */ IDA_mem->ida_tlo = tmid; for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { IDA_mem->ida_glo[i] = IDA_mem->ida_grout[i]; + } side = 2; /* Stop at root thi if converged; otherwise loop back. */ if (SUNRabs(IDA_mem->ida_thi - IDA_mem->ida_tlo) <= IDA_mem->ida_ttol) + { break; + } } /* End of root-search loop */ /* Reset trout and grout, set iroots, and return RTFOUND. */ IDA_mem->ida_trout = IDA_mem->ida_thi; - for (i = 0; i < IDA_mem->ida_nrtfn; i++) { - IDA_mem->ida_grout[i] = IDA_mem->ida_ghi[i]; + for (i = 0; i < IDA_mem->ida_nrtfn; i++) + { + IDA_mem->ida_grout[i] = IDA_mem->ida_ghi[i]; IDA_mem->ida_iroots[i] = 0; - if(!IDA_mem->ida_gactive[i]) continue; - if ( (SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) && - (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) ) - IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1:1; - if ( (IDA_mem->ida_glo[i] * IDA_mem->ida_ghi[i] < ZERO) && - (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO) ) - IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1:1; - } - return(RTFOUND); + if (!IDA_mem->ida_gactive[i]) { continue; } + if ((SUNRabs(IDA_mem->ida_ghi[i]) == ZERO) && + (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO)) + { + IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1 : 1; + } + if ((DIFFERENT_SIGN(IDA_mem->ida_glo[i], IDA_mem->ida_ghi[i])) && + (IDA_mem->ida_rootdir[i] * IDA_mem->ida_glo[i] <= ZERO)) + { + IDA_mem->ida_iroots[i] = IDA_mem->ida_glo[i] > 0 ? -1 : 1; + } + } + return (RTFOUND); } /* @@ -7277,23 +8416,20 @@ static int IDARootfind(IDAMem IDA_mem) * >0 for a recoverable error. */ -int IDASensResDQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, N_Vector resval, - N_Vector *yyS, N_Vector *ypS, N_Vector *resvalS, - void *user_dataS, - N_Vector ytemp, N_Vector yptemp, N_Vector restemp) +int IDASensResDQ(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector resval, N_Vector* yyS, N_Vector* ypS, + N_Vector* resvalS, void* user_dataS, N_Vector ytemp, + N_Vector yptemp, N_Vector restemp) { int retval, is; - for (is=0; is0 if res has a recoverable error). */ -static int IDASensRes1DQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, N_Vector resval, - int is, - N_Vector yyS, N_Vector ypS, N_Vector resvalS, - void *user_dataS, +static int IDASensRes1DQ(SUNDIALS_MAYBE_UNUSED int Ns, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector resval, int is, N_Vector yyS, + N_Vector ypS, N_Vector resvalS, void* user_dataS, N_Vector ytemp, N_Vector yptemp, N_Vector restemp) { IDAMem IDA_mem; int method; int which; int retval; - realtype psave, pbari; - realtype del , rdel; - realtype Delp, rDelp, r2Delp; - realtype Dely, rDely, r2Dely; - realtype Del , rDel , r2Del ; - realtype norms, ratio; + sunrealtype psave, pbari; + sunrealtype del, rdel; + sunrealtype Delp, rDelp, r2Delp; + sunrealtype Dely, rDely, r2Dely; + sunrealtype Del, rDel, r2Del; + sunrealtype norms, ratio; /* user_dataS points to IDA_mem */ - IDA_mem = (IDAMem) user_dataS; + IDA_mem = (IDAMem)user_dataS; /* Set base perturbation del */ del = SUNRsqrt(SUNMAX(IDA_mem->ida_rtol, IDA_mem->ida_uround)); - rdel = ONE/del; + rdel = ONE / del; pbari = IDA_mem->ida_pbar[is]; @@ -7338,29 +8472,36 @@ static int IDASensRes1DQ(int Ns, realtype t, psave = IDA_mem->ida_p[which]; Delp = pbari * del; - rDelp = ONE/Delp; + rDelp = ONE / Delp; norms = N_VWrmsNorm(yyS, IDA_mem->ida_ewt) * pbari; rDely = SUNMAX(norms, rdel) / pbari; - Dely = ONE/rDely; + Dely = ONE / rDely; - if (IDA_mem->ida_DQrhomax == ZERO) { + if (IDA_mem->ida_DQrhomax == ZERO) + { /* No switching */ - method = (IDA_mem->ida_DQtype==IDA_CENTERED) ? CENTERED1 : FORWARD1; - } else { + method = (IDA_mem->ida_DQtype == IDA_CENTERED) ? CENTERED1 : FORWARD1; + } + else + { /* switch between simultaneous/separate DQ */ ratio = Dely * rDelp; - if ( SUNMAX(ONE/ratio, ratio) <= IDA_mem->ida_DQrhomax ) - method = (IDA_mem->ida_DQtype==IDA_CENTERED) ? CENTERED1 : FORWARD1; + if (SUNMAX(ONE / ratio, ratio) <= IDA_mem->ida_DQrhomax) + { + method = (IDA_mem->ida_DQtype == IDA_CENTERED) ? CENTERED1 : FORWARD1; + } else - method = (IDA_mem->ida_DQtype==IDA_CENTERED) ? CENTERED2 : FORWARD2; + { + method = (IDA_mem->ida_DQtype == IDA_CENTERED) ? CENTERED2 : FORWARD2; + } } - switch (method) { - + switch (method) + { case CENTERED1: - Del = SUNMIN(Dely, Delp); - r2Del = HALF/Del; + Del = SUNMIN(Dely, Delp); + r2Del = HALF / Del; /* Forward perturb y, y' and parameter */ N_VLinearSum(Del, yyS, ONE, yy, ytemp); @@ -7370,7 +8511,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in resvalS */ retval = IDA_mem->ida_res(t, ytemp, yptemp, resvalS, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Backward perturb y, y' and parameter */ N_VLinearSum(-Del, yyS, ONE, yy, ytemp); @@ -7380,7 +8521,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in restemp */ retval = IDA_mem->ida_res(t, ytemp, yptemp, restemp, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Estimate the residual for the i-th sensitivity equation */ N_VLinearSum(r2Del, resvalS, -r2Del, restemp, resvalS); @@ -7389,8 +8530,8 @@ static int IDASensRes1DQ(int Ns, realtype t, case CENTERED2: - r2Delp = HALF/Delp; - r2Dely = HALF/Dely; + r2Delp = HALF / Delp; + r2Dely = HALF / Dely; /* Forward perturb y and y' */ N_VLinearSum(Dely, yyS, ONE, yy, ytemp); @@ -7399,7 +8540,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in resvalS */ retval = IDA_mem->ida_res(t, ytemp, yptemp, resvalS, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Backward perturb y and y' */ N_VLinearSum(-Dely, yyS, ONE, yy, ytemp); @@ -7408,7 +8549,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in restemp */ retval = IDA_mem->ida_res(t, ytemp, yptemp, restemp, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Save the first difference quotient in resvalS */ N_VLinearSum(r2Dely, resvalS, -r2Dely, restemp, resvalS); @@ -7419,7 +8560,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in ytemp */ retval = IDA_mem->ida_res(t, yy, yp, ytemp, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Backward perturb parameter */ IDA_mem->ida_p[which] = psave - Delp; @@ -7427,7 +8568,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in yptemp */ retval = IDA_mem->ida_res(t, yy, yp, yptemp, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Save the second difference quotient in restemp */ N_VLinearSum(r2Delp, ytemp, -r2Delp, yptemp, restemp); @@ -7439,8 +8580,8 @@ static int IDASensRes1DQ(int Ns, realtype t, case FORWARD1: - Del = SUNMIN(Dely, Delp); - rDel = ONE/Del; + Del = SUNMIN(Dely, Delp); + rDel = ONE / Del; /* Forward perturb y, y' and parameter */ N_VLinearSum(Del, yyS, ONE, yy, ytemp); @@ -7450,7 +8591,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in resvalS */ retval = IDA_mem->ida_res(t, ytemp, yptemp, resvalS, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Estimate the residual for the i-th sensitivity equation */ N_VLinearSum(rDel, resvalS, -rDel, resval, resvalS); @@ -7466,7 +8607,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in resvalS */ retval = IDA_mem->ida_res(t, ytemp, yptemp, resvalS, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Save the first difference quotient in resvalS */ N_VLinearSum(rDely, resvalS, -rDely, resval, resvalS); @@ -7477,7 +8618,7 @@ static int IDASensRes1DQ(int Ns, realtype t, /* Save residual in restemp */ retval = IDA_mem->ida_res(t, yy, yp, restemp, IDA_mem->ida_user_data); IDA_mem->ida_nreS++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Save the second difference quotient in restemp */ N_VLinearSum(rDelp, restemp, -rDelp, resval, restemp); @@ -7486,17 +8627,14 @@ static int IDASensRes1DQ(int Ns, realtype t, N_VLinearSum(ONE, resvalS, ONE, restemp, resvalS); break; - } /* Restore original value of parameter */ IDA_mem->ida_p[which] = psave; - return(0); - + return (0); } - /* IDAQuadSensRhsInternalDQ - internal IDAQuadSensRhsFn * * IDAQuadSensRhsInternalDQ computes right hand side of all quadrature @@ -7504,47 +8642,45 @@ static int IDASensRes1DQ(int Ns, realtype t, * done in IDAQuadSensRhs1InternalDQ. */ -static int IDAQuadSensRhsInternalDQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS, - N_Vector rrQ, N_Vector *resvalQS, - void *ida_mem, - N_Vector yytmp, N_Vector yptmp, N_Vector tmpQS) +static int IDAQuadSensRhsInternalDQ(int Ns, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS, + N_Vector rrQ, N_Vector* resvalQS, + void* ida_mem, N_Vector yytmp, + N_Vector yptmp, N_Vector tmpQS) { IDAMem IDA_mem; int is, retval; /* cvode_mem is passed here as user data */ - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - for (is=0; isida_rtol, IDA_mem->ida_uround)); - rdel = ONE/del; + del = SUNRsqrt(SUNMAX(IDA_mem->ida_rtol, IDA_mem->ida_uround)); + rdel = ONE / del; pbari = IDA_mem->ida_pbar[is]; @@ -7553,18 +8689,18 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, psave = IDA_mem->ida_p[which]; Delp = pbari * del; - norms = N_VWrmsNorm(yyS, IDA_mem->ida_ewt) * pbari; + norms = N_VWrmsNorm(yyS, IDA_mem->ida_ewt) * pbari; rDely = SUNMAX(norms, rdel) / pbari; - Dely = ONE/rDely; + Dely = ONE / rDely; - method = (IDA_mem->ida_DQtype==IDA_CENTERED) ? CENTERED1 : FORWARD1; - - switch(method) { + method = (IDA_mem->ida_DQtype == IDA_CENTERED) ? CENTERED1 : FORWARD1; + switch (method) + { case CENTERED1: - Del = SUNMIN(Dely, Delp); - r2Del = HALF/Del; + Del = SUNMIN(Dely, Delp); + r2Del = HALF / Del; N_VLinearSum(ONE, yy, Del, yyS, yytmp); N_VLinearSum(ONE, yp, Del, ypS, yptmp); @@ -7572,7 +8708,7 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, retval = IDA_mem->ida_rhsQ(t, yytmp, yptmp, resvalQS, IDA_mem->ida_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(-Del, yyS, ONE, yy, yytmp); N_VLinearSum(-Del, ypS, ONE, yp, yptmp); @@ -7581,7 +8717,7 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, retval = IDA_mem->ida_rhsQ(t, yytmp, yptmp, tmpQS, IDA_mem->ida_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(r2Del, resvalQS, -r2Del, tmpQS, resvalQS); @@ -7589,8 +8725,8 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, case FORWARD1: - Del = SUNMIN(Dely, Delp); - rdel = ONE/Del; + Del = SUNMIN(Dely, Delp); + rdel = ONE / Del; N_VLinearSum(ONE, yy, Del, yyS, yytmp); N_VLinearSum(ONE, yp, Del, ypS, yptmp); @@ -7598,7 +8734,7 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, retval = IDA_mem->ida_rhsQ(t, yytmp, yptmp, resvalQS, IDA_mem->ida_user_data); nfel++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } N_VLinearSum(rdel, resvalQS, -rdel, resvalQ, resvalQS); @@ -7609,79 +8745,63 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, realtype t, /* Increment counter nrQeS */ IDA_mem->ida_nrQeS += nfel; - return(0); + return (0); } - /* * ================================================================= * IDA error message handling functions * ================================================================= */ -/* - * IDAProcessError is a high level error handling function. - * - If ida_mem==NULL it prints the error message to stderr. - * - Otherwise, it sets up and calls the error handling function - * pointed to by ida_ehfun. - */ - -void IDAProcessError(IDAMem IDA_mem, - int error_code, const char *module, const char *fname, - const char *msgfmt, ...) +void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...) { - va_list ap; - char msg[256]; - - /* Initialize the argument pointer variable + /* We initialize the argument pointer variable before each vsnprintf call to avoid undefined behavior (msgfmt is the last required argument to IDAProcessError) */ - - va_start(ap, msgfmt); + va_list ap; /* Compose the message */ - - vsprintf(msg, msgfmt, ap); - - if (IDA_mem == NULL) { /* We write to stderr */ -#ifndef NO_FPRINTF_OUTPUT - fprintf(stderr, "\n[%s ERROR] %s\n ", module, fname); - fprintf(stderr, "%s\n\n", msg); -#endif - - } else { /* We can call ehfun */ - IDA_mem->ida_ehfun(error_code, module, fname, msg, IDA_mem->ida_eh_data); - } - - /* Finalize argument processing */ + va_start(ap, msgfmt); + size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1; va_end(ap); - return; -} - -/* IDAErrHandler is the default error handling function. - It sends the error message to the stream pointed to by ida_errfp */ + char* msg = (char*)malloc(msglen); -void IDAErrHandler(int error_code, const char *module, - const char *function, char *msg, void *data) -{ - IDAMem IDA_mem; - char err_type[10]; + va_start(ap, msgfmt); + vsnprintf(msg, msglen, msgfmt, ap); + va_end(ap); - /* data points to IDA_mem here */ + do { + if (IDA_mem == NULL) + { + SUNGlobalFallbackErrHandler(line, func, file, msg, error_code); + break; + } - IDA_mem = (IDAMem) data; +/* AMICI: https://github.com/AMICI-dev/AMICI/issues/2550 */ +#ifdef AMICI_SUNLOGGER_WARNINGS + if (error_code == IDA_WARNING) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING + char* file_and_line = sunCombineFileAndLine(line, file); + SUNLogger_QueueMsg(IDA_LOGGER, SUN_LOGLEVEL_WARNING, file_and_line, func, + msg); + free(file_and_line); +#endif + break; + } +#endif - if (error_code == IDA_WARNING) - sprintf(err_type,"WARNING"); - else - sprintf(err_type,"ERROR"); + /* Call the SUNDIALS main error handler */ + SUNHandleErrWithMsg(line, func, file, msg, error_code, IDA_mem->ida_sunctx); -#ifndef NO_FPRINTF_OUTPUT - if (IDA_mem->ida_errfp != NULL) { - fprintf(IDA_mem->ida_errfp,"\n[%s %s] %s\n",module,err_type,function); - fprintf(IDA_mem->ida_errfp," %s\n\n",msg); + /* Clear the last error value */ + (void)SUNContext_GetLastError(IDA_mem->ida_sunctx); } -#endif + while (0); + + free(msg); return; } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre.c index 854455901..25521a90d 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre.c @@ -4,7 +4,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -24,46 +24,44 @@ * ----------------------------------------------------------------- */ +#include #include #include +#include +#include "idas_bbdpre_impl.h" #include "idas_impl.h" #include "idas_ls_impl.h" -#include "idas_bbdpre_impl.h" -#include -#include - -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /* Prototypes of IDABBDPrecSetup and IDABBDPrecSolve */ -static int IDABBDPrecSetup(realtype tt, N_Vector yy, N_Vector yp, - N_Vector rr, realtype c_j, void *prec_data); -static int IDABBDPrecSolve(realtype tt, N_Vector yy, N_Vector yp, +static int IDABBDPrecSetup(sunrealtype tt, N_Vector yy, N_Vector yp, + N_Vector rr, sunrealtype c_j, void* prec_data); +static int IDABBDPrecSolve(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector rvec, N_Vector zvec, - realtype c_j, realtype delta, void *prec_data); + sunrealtype c_j, sunrealtype delta, void* prec_data); /* Prototype for IDABBDPrecFree */ static int IDABBDPrecFree(IDAMem ida_mem); /* Prototype for difference quotient Jacobian calculation routine */ -static int IBBDDQJac(IBBDPrecData pdata, realtype tt, realtype cj, - N_Vector yy, N_Vector yp, N_Vector gref, - N_Vector ytemp, N_Vector yptemp, N_Vector gtemp); +static int IBBDDQJac(IBBDPrecData pdata, sunrealtype tt, sunrealtype cj, + N_Vector yy, N_Vector yp, N_Vector gref, N_Vector ytemp, + N_Vector yptemp, N_Vector gtemp); /* Wrapper functions for adjoint code */ -static int IDAAglocal(sunindextype NlocalB, realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector gvalB, void *user_dataB); +static int IDAAglocal(sunindextype NlocalB, sunrealtype tt, N_Vector yyB, + N_Vector ypB, N_Vector gvalB, void* user_dataB); -static int IDAAgcomm(sunindextype NlocalB, realtype tt, N_Vector yyB, - N_Vector ypB, void *user_dataB); +static int IDAAgcomm(sunindextype NlocalB, sunrealtype tt, N_Vector yyB, + N_Vector ypB, void* user_dataB); /* Prototype for the pfree routine for backward problems. */ static int IDABBDPrecFreeB(IDABMem IDAB_mem); - /*================================================================ PART I - forward problems ================================================================*/ @@ -71,11 +69,9 @@ static int IDABBDPrecFreeB(IDABMem IDAB_mem); /*--------------------------------------------------------------- User-Callable Functions: initialization, reinit and free ---------------------------------------------------------------*/ -int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, - sunindextype mudq, sunindextype mldq, - sunindextype mukeep, sunindextype mlkeep, - realtype dq_rel_yy, - IDABBDLocalFn Gres, IDABBDCommFn Gcomm) +int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, sunindextype mudq, + sunindextype mldq, sunindextype mukeep, sunindextype mlkeep, + sunrealtype dq_rel_yy, IDABBDLocalFn Gres, IDABBDCommFn Gcomm) { IDAMem IDA_mem; IDALsMem idals_mem; @@ -84,136 +80,156 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, long int lrw, liw; int flag; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Test if the LS linear solver interface has been created */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* Test compatibility of NVECTOR package with the BBD preconditioner */ - if(IDA_mem->ida_tempv1->ops->nvgetarraypointer == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_BAD_NVECTOR); - return(IDALS_ILL_INPUT); + if (IDA_mem->ida_tempv1->ops->nvgetarraypointer == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSGBBD_BAD_NVECTOR); + return (IDALS_ILL_INPUT); } /* Allocate data memory. */ pdata = NULL; - pdata = (IBBDPrecData) malloc(sizeof *pdata); - if (pdata == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + pdata = (IBBDPrecData)malloc(sizeof *pdata); + if (pdata == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* Set pointers to glocal and gcomm; load half-bandwidths. */ pdata->ida_mem = IDA_mem; - pdata->glocal = Gres; - pdata->gcomm = Gcomm; - pdata->mudq = SUNMIN(Nlocal-1, SUNMAX(0, mudq)); - pdata->mldq = SUNMIN(Nlocal-1, SUNMAX(0, mldq)); - muk = SUNMIN(Nlocal-1, SUNMAX(0, mukeep)); - mlk = SUNMIN(Nlocal-1, SUNMAX(0, mlkeep)); - pdata->mukeep = muk; - pdata->mlkeep = mlk; + pdata->glocal = Gres; + pdata->gcomm = Gcomm; + pdata->mudq = SUNMIN(Nlocal - 1, SUNMAX(0, mudq)); + pdata->mldq = SUNMIN(Nlocal - 1, SUNMAX(0, mldq)); + muk = SUNMIN(Nlocal - 1, SUNMAX(0, mukeep)); + mlk = SUNMIN(Nlocal - 1, SUNMAX(0, mlkeep)); + pdata->mukeep = muk; + pdata->mlkeep = mlk; /* Set extended upper half-bandwidth for PP (required for pivoting). */ - storage_mu = SUNMIN(Nlocal-1, muk+mlk); + storage_mu = SUNMIN(Nlocal - 1, muk + mlk); /* Allocate memory for preconditioner matrix. */ pdata->PP = NULL; - pdata->PP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu); - if (pdata->PP == NULL) { - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + pdata->PP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu, + IDA_mem->ida_sunctx); + if (pdata->PP == NULL) + { + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* Allocate memory for temporary N_Vectors */ pdata->zlocal = NULL; - pdata->zlocal = N_VNewEmpty_Serial(Nlocal); - if (pdata->zlocal == NULL) { + pdata->zlocal = N_VNewEmpty_Serial(Nlocal, IDA_mem->ida_sunctx); + if (pdata->zlocal == NULL) + { SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } pdata->rlocal = NULL; - pdata->rlocal = N_VNewEmpty_Serial(Nlocal); - if (pdata->rlocal == NULL) { + pdata->rlocal = N_VNewEmpty_Serial(Nlocal, IDA_mem->ida_sunctx); + if (pdata->rlocal == NULL) + { N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } pdata->tempv1 = NULL; pdata->tempv1 = N_VClone(IDA_mem->ida_tempv1); - if (pdata->tempv1 == NULL){ + if (pdata->tempv1 == NULL) + { N_VDestroy(pdata->rlocal); N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } pdata->tempv2 = NULL; pdata->tempv2 = N_VClone(IDA_mem->ida_tempv1); - if (pdata->tempv2 == NULL){ + if (pdata->tempv2 == NULL) + { N_VDestroy(pdata->rlocal); N_VDestroy(pdata->zlocal); N_VDestroy(pdata->tempv1); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } pdata->tempv3 = NULL; pdata->tempv3 = N_VClone(IDA_mem->ida_tempv1); - if (pdata->tempv3 == NULL){ + if (pdata->tempv3 == NULL) + { N_VDestroy(pdata->rlocal); N_VDestroy(pdata->zlocal); N_VDestroy(pdata->tempv1); N_VDestroy(pdata->tempv2); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } pdata->tempv4 = NULL; pdata->tempv4 = N_VClone(IDA_mem->ida_tempv1); - if (pdata->tempv4 == NULL){ + if (pdata->tempv4 == NULL) + { N_VDestroy(pdata->rlocal); N_VDestroy(pdata->zlocal); N_VDestroy(pdata->tempv1); N_VDestroy(pdata->tempv2); N_VDestroy(pdata->tempv3); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->PP); - if (pdata->LS == NULL) { + pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->PP, IDA_mem->ida_sunctx); + if (pdata->LS == NULL) + { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); N_VDestroy(pdata->tempv1); @@ -221,15 +237,17 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, N_VDestroy(pdata->tempv3); N_VDestroy(pdata->tempv4); SUNMatDestroy(pdata->PP); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) { + if (flag != SUN_SUCCESS) + { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); N_VDestroy(pdata->tempv1); @@ -238,15 +256,15 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, N_VDestroy(pdata->tempv4); SUNMatDestroy(pdata->PP); SUNLinSolFree(pdata->LS); - free(pdata); pdata = NULL; - IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASBBDPRE", - "IDABBDPrecInit", MSGBBD_SUNLS_FAIL); - return(IDALS_SUNLS_FAIL); + free(pdata); + pdata = NULL; + IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_SUNLS_FAIL); + return (IDALS_SUNLS_FAIL); } /* Set rel_yy based on input value dq_rel_yy (0 implies default). */ - pdata->rel_yy = (dq_rel_yy > ZERO) ? - dq_rel_yy : SUNRsqrt(IDA_mem->ida_uround); + pdata->rel_yy = (dq_rel_yy > ZERO) ? dq_rel_yy : SUNRsqrt(IDA_mem->ida_uround); /* Store Nlocal to be used in IDABBDPrecSetup */ pdata->n_local = Nlocal; @@ -254,22 +272,26 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, /* Set work space sizes and initialize nge. */ pdata->rpwsize = 0; pdata->ipwsize = 0; - if (IDA_mem->ida_tempv1->ops->nvspace) { + if (IDA_mem->ida_tempv1->ops->nvspace) + { N_VSpace(IDA_mem->ida_tempv1, &lrw1, &liw1); - pdata->rpwsize += 4*lrw1; - pdata->ipwsize += 4*liw1; + pdata->rpwsize += 4 * lrw1; + pdata->ipwsize += 4 * liw1; } - if (pdata->rlocal->ops->nvspace) { + if (pdata->rlocal->ops->nvspace) + { N_VSpace(pdata->rlocal, &lrw1, &liw1); - pdata->rpwsize += 2*lrw1; - pdata->ipwsize += 2*liw1; + pdata->rpwsize += 2 * lrw1; + pdata->ipwsize += 2 * liw1; } - if (pdata->PP->ops->space) { + if (pdata->PP->ops->space) + { flag = SUNMatSpace(pdata->PP, &lrw, &liw); pdata->rpwsize += lrw; pdata->ipwsize += liw; } - if (pdata->LS->ops->space) { + if (pdata->LS->ops->space) + { flag = SUNLinSolSpace(pdata->LS, &lrw, &liw); pdata->rpwsize += lrw; pdata->ipwsize += liw; @@ -277,8 +299,7 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, pdata->nge = 0; /* make sure pdata is free from any previous allocations */ - if (idals_mem->pfree) - idals_mem->pfree(IDA_mem); + if (idals_mem->pfree) { idals_mem->pfree(IDA_mem); } /* Point to the new pdata field in the LS memory */ idals_mem->pdata = pdata; @@ -287,135 +308,133 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, idals_mem->pfree = IDABBDPrecFree; /* Attach preconditioner solve and setup functions */ - flag = IDASetPreconditioner(ida_mem, IDABBDPrecSetup, - IDABBDPrecSolve); + flag = IDASetPreconditioner(ida_mem, IDABBDPrecSetup, IDABBDPrecSolve); - return(flag); + return (flag); } - /*-------------------------------------------------------------*/ -int IDABBDPrecReInit(void *ida_mem, sunindextype mudq, - sunindextype mldq, realtype dq_rel_yy) +int IDABBDPrecReInit(void* ida_mem, sunindextype mudq, sunindextype mldq, + sunrealtype dq_rel_yy) { IDAMem IDA_mem; IDALsMem idals_mem; IBBDPrecData pdata; sunindextype Nlocal; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecReInit", MSGBBD_MEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Test if the LS linear solver interface has been created */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASBBDPRE", - "IDABBDPrecReInit", MSGBBD_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* Test if the preconditioner data is non-NULL */ - if (idals_mem->pdata == NULL) { - IDAProcessError(IDA_mem, IDALS_PMEM_NULL, "IDASBBDPRE", - "IDABBDPrecReInit", MSGBBD_PMEM_NULL); - return(IDALS_PMEM_NULL); + if (idals_mem->pdata == NULL) + { + IDAProcessError(IDA_mem, IDALS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (IDALS_PMEM_NULL); } - pdata = (IBBDPrecData) idals_mem->pdata; + pdata = (IBBDPrecData)idals_mem->pdata; /* Load half-bandwidths. */ - Nlocal = pdata->n_local; - pdata->mudq = SUNMIN(Nlocal-1, SUNMAX(0, mudq)); - pdata->mldq = SUNMIN(Nlocal-1, SUNMAX(0, mldq)); + Nlocal = pdata->n_local; + pdata->mudq = SUNMIN(Nlocal - 1, SUNMAX(0, mudq)); + pdata->mldq = SUNMIN(Nlocal - 1, SUNMAX(0, mldq)); /* Set rel_yy based on input value dq_rel_yy (0 implies default). */ - pdata->rel_yy = (dq_rel_yy > ZERO) ? - dq_rel_yy : SUNRsqrt(IDA_mem->ida_uround); + pdata->rel_yy = (dq_rel_yy > ZERO) ? dq_rel_yy : SUNRsqrt(IDA_mem->ida_uround); /* Re-initialize nge */ pdata->nge = 0; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*-------------------------------------------------------------*/ -int IDABBDPrecGetWorkSpace(void *ida_mem, - long int *lenrwBBDP, - long int *leniwBBDP) +int IDABBDPrecGetWorkSpace(void* ida_mem, long int* lenrwBBDP, long int* leniwBBDP) { IDAMem IDA_mem; IDALsMem idals_mem; IBBDPrecData pdata; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetWorkSpace", MSGBBD_MEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetWorkSpace", MSGBBD_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; - if (idals_mem->pdata == NULL) { - IDAProcessError(IDA_mem, IDALS_PMEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetWorkSpace", MSGBBD_PMEM_NULL); - return(IDALS_PMEM_NULL); + if (idals_mem->pdata == NULL) + { + IDAProcessError(IDA_mem, IDALS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (IDALS_PMEM_NULL); } - pdata = (IBBDPrecData) idals_mem->pdata; + pdata = (IBBDPrecData)idals_mem->pdata; *lenrwBBDP = pdata->rpwsize; *leniwBBDP = pdata->ipwsize; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*-------------------------------------------------------------*/ -int IDABBDPrecGetNumGfnEvals(void *ida_mem, - long int *ngevalsBBDP) +int IDABBDPrecGetNumGfnEvals(void* ida_mem, long int* ngevalsBBDP) { IDAMem IDA_mem; IDALsMem idals_mem; IBBDPrecData pdata; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetNumGfnEvals", MSGBBD_MEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetNumGfnEvals", MSGBBD_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; - if (idals_mem->pdata == NULL) { - IDAProcessError(IDA_mem, IDALS_PMEM_NULL, "IDASBBDPRE", - "IDABBDPrecGetNumGfnEvals", MSGBBD_PMEM_NULL); - return(IDALS_PMEM_NULL); + if (idals_mem->pdata == NULL) + { + IDAProcessError(IDA_mem, IDALS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); + return (IDALS_PMEM_NULL); } - pdata = (IBBDPrecData) idals_mem->pdata; + pdata = (IBBDPrecData)idals_mem->pdata; *ngevalsBBDP = pdata->nge; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - - - /*--------------------------------------------------------------- IDABBDPrecSetup: @@ -449,36 +468,35 @@ int IDABBDPrecGetNumGfnEvals(void *ida_mem, > 0 for a recoverable error (step will be retried), or < 0 for a nonrecoverable error (step fails). ----------------------------------------------------------------*/ -static int IDABBDPrecSetup(realtype tt, N_Vector yy, N_Vector yp, - N_Vector rr, realtype c_j, void *bbd_data) +static int IDABBDPrecSetup(sunrealtype tt, N_Vector yy, N_Vector yp, + SUNDIALS_MAYBE_UNUSED N_Vector rr, sunrealtype c_j, + void* bbd_data) { IBBDPrecData pdata; IDAMem IDA_mem; int retval; - pdata =(IBBDPrecData) bbd_data; + pdata = (IBBDPrecData)bbd_data; - IDA_mem = (IDAMem) pdata->ida_mem; + IDA_mem = (IDAMem)pdata->ida_mem; /* Call IBBDDQJac for a new Jacobian calculation and store in PP. */ retval = SUNMatZero(pdata->PP); - retval = IBBDDQJac(pdata, tt, c_j, yy, yp, pdata->tempv1, - pdata->tempv2, pdata->tempv3, pdata->tempv4); - if (retval < 0) { - IDAProcessError(IDA_mem, -1, "IDASBBDPRE", "IDABBDPrecSetup", + retval = IBBDDQJac(pdata, tt, c_j, yy, yp, pdata->tempv1, pdata->tempv2, + pdata->tempv3, pdata->tempv4); + if (retval < 0) + { + IDAProcessError(IDA_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_FUNC_FAILED); - return(-1); - } - if (retval > 0) { - return(+1); + return (-1); } + if (retval > 0) { return (+1); } /* Do LU factorization of matrix and return error flag */ retval = SUNLinSolSetup_Band(pdata->LS, pdata->PP); - return(retval); + return (retval); } - /*--------------------------------------------------------------- IDABBDPrecSolve @@ -499,42 +517,45 @@ static int IDABBDPrecSetup(realtype tt, N_Vector yy, N_Vector yp, IDABBDPrecSolve returns the value returned from the linear solver object. ---------------------------------------------------------------*/ -static int IDABBDPrecSolve(realtype tt, N_Vector yy, N_Vector yp, - N_Vector rr, N_Vector rvec, N_Vector zvec, - realtype c_j, realtype delta, void *bbd_data) +static int IDABBDPrecSolve(SUNDIALS_MAYBE_UNUSED sunrealtype tt, + SUNDIALS_MAYBE_UNUSED N_Vector yy, + SUNDIALS_MAYBE_UNUSED N_Vector yp, + SUNDIALS_MAYBE_UNUSED N_Vector rr, N_Vector rvec, + N_Vector zvec, SUNDIALS_MAYBE_UNUSED sunrealtype c_j, + SUNDIALS_MAYBE_UNUSED sunrealtype delta, + void* bbd_data) { IBBDPrecData pdata; int retval; - pdata = (IBBDPrecData) bbd_data; + pdata = (IBBDPrecData)bbd_data; /* Attach local data arrays for rvec and zvec to rlocal and zlocal */ N_VSetArrayPointer(N_VGetArrayPointer(rvec), pdata->rlocal); N_VSetArrayPointer(N_VGetArrayPointer(zvec), pdata->zlocal); /* Call banded solver object to do the work */ - retval = SUNLinSolSolve(pdata->LS, pdata->PP, pdata->zlocal, - pdata->rlocal, ZERO); + retval = SUNLinSolSolve(pdata->LS, pdata->PP, pdata->zlocal, pdata->rlocal, + ZERO); /* Detach local data arrays from rlocal and zlocal */ N_VSetArrayPointer(NULL, pdata->rlocal); N_VSetArrayPointer(NULL, pdata->zlocal); - return(retval); + return (retval); } - /*-------------------------------------------------------------*/ static int IDABBDPrecFree(IDAMem IDA_mem) { IDALsMem idals_mem; IBBDPrecData pdata; - if (IDA_mem->ida_lmem == NULL) return(0); - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + if (IDA_mem->ida_lmem == NULL) { return (0); } + idals_mem = (IDALsMem)IDA_mem->ida_lmem; - if (idals_mem->pdata == NULL) return(0); - pdata = (IBBDPrecData) idals_mem->pdata; + if (idals_mem->pdata == NULL) { return (0); } + pdata = (IBBDPrecData)idals_mem->pdata; SUNLinSolFree(pdata->LS); N_VDestroy(pdata->rlocal); @@ -548,10 +569,9 @@ static int IDABBDPrecFree(IDAMem IDA_mem) free(pdata); pdata = NULL; - return(0); + return (0); } - /*--------------------------------------------------------------- IBBDDQJac @@ -570,19 +590,19 @@ static int IDABBDPrecFree(IDAMem IDA_mem) Return values are: 0 (success), > 0 (recoverable error), or < 0 (nonrecoverable error). ----------------------------------------------------------------*/ -static int IBBDDQJac(IBBDPrecData pdata, realtype tt, realtype cj, - N_Vector yy, N_Vector yp, N_Vector gref, - N_Vector ytemp, N_Vector yptemp, N_Vector gtemp) +static int IBBDDQJac(IBBDPrecData pdata, sunrealtype tt, sunrealtype cj, + N_Vector yy, N_Vector yp, N_Vector gref, N_Vector ytemp, + N_Vector yptemp, N_Vector gtemp) { IDAMem IDA_mem; - realtype inc, inc_inv; + sunrealtype inc, inc_inv; int retval; sunindextype group, i, j, width, ngroups, i1, i2; - realtype *ydata, *ypdata, *ytempdata, *yptempdata, *grefdata, *gtempdata; - realtype *cnsdata = NULL, *ewtdata; - realtype *col_j, conj, yj, ypj, ewtj; + sunrealtype *ydata, *ypdata, *ytempdata, *yptempdata, *grefdata, *gtempdata; + sunrealtype *cnsdata = NULL, *ewtdata; + sunrealtype *col_j, conj, yj, ypj, ewtj; - IDA_mem = (IDAMem) pdata->ida_mem; + IDA_mem = (IDAMem)pdata->ida_mem; /* Initialize ytemp and yptemp. */ N_VScale(ONE, yy, ytemp); @@ -594,93 +614,114 @@ static int IBBDDQJac(IBBDPrecData pdata, realtype tt, realtype cj, gtempdata = N_VGetArrayPointer(gtemp); ewtdata = N_VGetArrayPointer(IDA_mem->ida_ewt); if (IDA_mem->ida_constraintsSet) + { cnsdata = N_VGetArrayPointer(IDA_mem->ida_constraints); - ytempdata = N_VGetArrayPointer(ytemp); - yptempdata= N_VGetArrayPointer(yptemp); - grefdata = N_VGetArrayPointer(gref); + } + ytempdata = N_VGetArrayPointer(ytemp); + yptempdata = N_VGetArrayPointer(yptemp); + grefdata = N_VGetArrayPointer(gref); /* Call gcomm and glocal to get base value of G(t,y,y'). */ - if (pdata->gcomm != NULL) { + if (pdata->gcomm != NULL) + { retval = pdata->gcomm(pdata->n_local, tt, yy, yp, IDA_mem->ida_user_data); - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } } - retval = pdata->glocal(pdata->n_local, tt, yy, yp, gref, IDA_mem->ida_user_data); + retval = pdata->glocal(pdata->n_local, tt, yy, yp, gref, + IDA_mem->ida_user_data); pdata->nge++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Set bandwidth and number of column groups for band differencing. */ - width = pdata->mldq + pdata->mudq + 1; + width = pdata->mldq + pdata->mudq + 1; ngroups = SUNMIN(width, pdata->n_local); /* Loop over groups. */ - for(group = 1; group <= ngroups; group++) { - + for (group = 1; group <= ngroups; group++) + { /* Loop over the components in this group. */ - for(j = group-1; j < pdata->n_local; j += width) { - yj = ydata[j]; - ypj = ypdata[j]; + for (j = group - 1; j < pdata->n_local; j += width) + { + yj = ydata[j]; + ypj = ypdata[j]; ewtj = ewtdata[j]; /* Set increment inc to yj based on rel_yy*abs(yj), with adjustments using ypj and ewtj if this is small, and a further adjustment to give it the same sign as hh*ypj. */ inc = pdata->rel_yy * - SUNMAX(SUNRabs(yj), SUNMAX( SUNRabs(IDA_mem->ida_hh*ypj), ONE/ewtj)); - if (IDA_mem->ida_hh*ypj < ZERO) inc = -inc; + SUNMAX(SUNRabs(yj), + SUNMAX(SUNRabs(IDA_mem->ida_hh * ypj), ONE / ewtj)); + if (IDA_mem->ida_hh * ypj < ZERO) { inc = -inc; } inc = (yj + inc) - yj; /* Adjust sign(inc) again if yj has an inequality constraint. */ - if (IDA_mem->ida_constraintsSet) { + if (IDA_mem->ida_constraintsSet) + { conj = cnsdata[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } /* Increment yj and ypj. */ ytempdata[j] += inc; - yptempdata[j] += cj*inc; - + yptempdata[j] += cj * inc; } /* Evaluate G with incremented y and yp arguments. */ - retval = pdata->glocal(pdata->n_local, tt, ytemp, yptemp, - gtemp, IDA_mem->ida_user_data); + retval = pdata->glocal(pdata->n_local, tt, ytemp, yptemp, gtemp, + IDA_mem->ida_user_data); pdata->nge++; - if (retval != 0) return(retval); + if (retval != 0) { return (retval); } /* Loop over components of the group again; restore ytemp and yptemp. */ - for(j = group-1; j < pdata->n_local; j += width) { - yj = ytempdata[j] = ydata[j]; + for (j = group - 1; j < pdata->n_local; j += width) + { + yj = ytempdata[j] = ydata[j]; ypj = yptempdata[j] = ypdata[j]; - ewtj = ewtdata[j]; + ewtj = ewtdata[j]; /* Set increment inc as before .*/ inc = pdata->rel_yy * - SUNMAX(SUNRabs(yj), SUNMAX( SUNRabs(IDA_mem->ida_hh*ypj), ONE/ewtj)); - if (IDA_mem->ida_hh*ypj < ZERO) inc = -inc; + SUNMAX(SUNRabs(yj), + SUNMAX(SUNRabs(IDA_mem->ida_hh * ypj), ONE / ewtj)); + if (IDA_mem->ida_hh * ypj < ZERO) { inc = -inc; } inc = (yj + inc) - yj; - if (IDA_mem->ida_constraintsSet) { + if (IDA_mem->ida_constraintsSet) + { conj = cnsdata[j]; - if (SUNRabs(conj) == ONE) {if ((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if ((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } /* Form difference quotients and load into PP. */ - inc_inv = ONE/inc; - col_j = SUNBandMatrix_Column(pdata->PP,j); - i1 = SUNMAX(0, j-pdata->mukeep); - i2 = SUNMIN(j + pdata->mlkeep, pdata->n_local-1); - for(i = i1; i <= i2; i++) - SM_COLUMN_ELEMENT_B(col_j,i,j) = - inc_inv * (gtempdata[i] - grefdata[i]); + inc_inv = ONE / inc; + col_j = SUNBandMatrix_Column(pdata->PP, j); + i1 = SUNMAX(0, j - pdata->mukeep); + i2 = SUNMIN(j + pdata->mlkeep, pdata->n_local - 1); + for (i = i1; i <= i2; i++) + { + SM_COLUMN_ELEMENT_B(col_j, i, j) = inc_inv * (gtempdata[i] - grefdata[i]); + } } } - return(0); + return (0); } - /*================================================================ PART II - backward problems ================================================================*/ @@ -688,65 +729,69 @@ static int IBBDDQJac(IBBDPrecData pdata, realtype tt, realtype cj, /*--------------------------------------------------------------- User-Callable Functions: initialization, reinit and free ---------------------------------------------------------------*/ -int IDABBDPrecInitB(void *ida_mem, int which, sunindextype NlocalB, - sunindextype mudqB, sunindextype mldqB, - sunindextype mukeepB, sunindextype mlkeepB, - realtype dq_rel_yyB, IDABBDLocalFnB glocalB, - IDABBDCommFnB gcommB) +int IDABBDPrecInitB(void* ida_mem, int which, sunindextype NlocalB, + sunindextype mudqB, sunindextype mldqB, sunindextype mukeepB, + sunindextype mlkeepB, sunrealtype dq_rel_yyB, + IDABBDLocalFnB glocalB, IDABBDCommFnB gcommB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; IDABBDPrecDataB idabbdB_mem; - void *ida_memB; + void* ida_memB; int flag; /* Check if ida_mem is allright. */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecInitB", MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDALS_NO_ADJ, "IDASBBDPRE", - "IDABBDPrecInitB", MSG_LS_NO_ADJ); - return(IDALS_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDALS_NO_ADJ, __LINE__, __func__, __FILE__, + MSG_LS_NO_ADJ); + return (IDALS_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASBBDPRE", - "IDABBDPrecInitB", MSG_LS_BAD_WHICH); - return(IDALS_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_WHICH); + return (IDALS_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* ida_mem corresponding to 'which' problem. */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* Initialize the BBD preconditioner for this backward problem. */ - flag = IDABBDPrecInit(ida_memB, NlocalB, mudqB, mldqB, mukeepB, - mlkeepB, dq_rel_yyB, IDAAglocal, IDAAgcomm); - if (flag != IDA_SUCCESS) return(flag); + flag = IDABBDPrecInit(ida_memB, NlocalB, mudqB, mldqB, mukeepB, mlkeepB, + dq_rel_yyB, IDAAglocal, IDAAgcomm); + if (flag != IDA_SUCCESS) { return (flag); } /* Allocate memory for IDABBDPrecDataB to store the user-provided functions which will be called from the wrappers */ idabbdB_mem = NULL; - idabbdB_mem = (IDABBDPrecDataB) malloc(sizeof(* idabbdB_mem)); - if (idabbdB_mem == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASBBDPRE", - "IDABBDPrecInitB", MSGBBD_MEM_FAIL); - return(IDALS_MEM_FAIL); + idabbdB_mem = (IDABBDPrecDataB)malloc(sizeof(*idabbdB_mem)); + if (idabbdB_mem == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* set pointers to user-provided functions */ @@ -757,68 +802,69 @@ int IDABBDPrecInitB(void *ida_mem, int which, sunindextype NlocalB, IDAB_mem->ida_pmem = idabbdB_mem; IDAB_mem->ida_pfree = IDABBDPrecFreeB; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*-------------------------------------------------------------*/ -int IDABBDPrecReInitB(void *ida_mem, int which, sunindextype mudqB, - sunindextype mldqB, realtype dq_rel_yyB) +int IDABBDPrecReInitB(void* ida_mem, int which, sunindextype mudqB, + sunindextype mldqB, sunrealtype dq_rel_yyB) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDABMem IDAB_mem; - void *ida_memB; + void* ida_memB; int flag; /* Check if ida_mem is allright. */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASBBDPRE", - "IDABBDPrecReInitB", MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Is ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDALS_NO_ADJ, "IDASBBDPRE", - "IDABBDPrecReInitB", MSG_LS_NO_ADJ); - return(IDALS_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDALS_NO_ADJ, __LINE__, __func__, __FILE__, + MSG_LS_NO_ADJ); + return (IDALS_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASBBDPRE", - "IDABBDPrecReInitB", MSG_LS_BAD_WHICH); - return(IDALS_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_WHICH); + return (IDALS_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } /* advance */ IDAB_mem = IDAB_mem->ida_next; } /* ida_mem corresponding to 'which' backward problem. */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; /* ReInitialize the BBD preconditioner for this backward problem. */ flag = IDABBDPrecReInit(ida_memB, mudqB, mldqB, dq_rel_yyB); - return(flag); + return (flag); } - /*-------------------------------------------------------------*/ static int IDABBDPrecFreeB(IDABMem IDAB_mem) { free(IDAB_mem->ida_pmem); IDAB_mem->ida_pmem = NULL; - return(0); + return (0); } - /*---------------------------------------------------------------- Wrapper functions ----------------------------------------------------------------*/ @@ -829,8 +875,8 @@ static int IDABBDPrecFreeB(IDABMem IDAB_mem) This routine interfaces to the IDALocalFnB routine provided by the user. ----------------------------------------------------------------*/ -static int IDAAglocal(sunindextype NlocalB, realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector gvalB, void *ida_mem) +static int IDAAglocal(sunindextype NlocalB, sunrealtype tt, N_Vector yyB, + N_Vector ypB, N_Vector gvalB, void* ida_mem) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; @@ -838,40 +884,40 @@ static int IDAAglocal(sunindextype NlocalB, realtype tt, N_Vector yyB, IDABBDPrecDataB idabbdB_mem; int flag; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; /* Get current backward problem. */ IDAB_mem = IDAADJ_mem->ia_bckpbCrt; /* Get the preconditioner's memory. */ - idabbdB_mem = (IDABBDPrecDataB) IDAB_mem->ida_pmem; + idabbdB_mem = (IDABBDPrecDataB)IDAB_mem->ida_pmem; /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (flag != IDA_SUCCESS) { - IDAProcessError(IDA_mem, -1, "IDASBBDPRE", "IDAAglocal", - MSGBBD_BAD_T); - return(-1); + if (flag != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_BAD_T); + return (-1); } } /* Call user's adjoint LocalFnB function. */ return idabbdB_mem->glocalB(NlocalB, tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, ypB, - gvalB, IDAB_mem->ida_user_data); + IDAADJ_mem->ia_ypTmp, yyB, ypB, gvalB, + IDAB_mem->ida_user_data); } - /*---------------------------------------------------------------- IDAAgcomm This routine interfaces to the IDACommFnB routine provided by the user. ----------------------------------------------------------------*/ -static int IDAAgcomm(sunindextype NlocalB, realtype tt, - N_Vector yyB, N_Vector ypB, void *ida_mem) +static int IDAAgcomm(sunindextype NlocalB, sunrealtype tt, N_Vector yyB, + N_Vector ypB, void* ida_mem) { IDAMem IDA_mem; IDAadjMem IDAADJ_mem; @@ -879,24 +925,25 @@ static int IDAAgcomm(sunindextype NlocalB, realtype tt, IDABBDPrecDataB idabbdB_mem; int flag; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDAADJ_mem = IDA_mem->ida_adj_mem; /* Get current backward problem. */ IDAB_mem = IDAADJ_mem->ia_bckpbCrt; /* Get the preconditioner's memory. */ - idabbdB_mem = (IDABBDPrecDataB) IDAB_mem->ida_pmem; - if (idabbdB_mem->gcommB == NULL) return(0); + idabbdB_mem = (IDABBDPrecDataB)IDAB_mem->ida_pmem; + if (idabbdB_mem->gcommB == NULL) { return (0); } /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { flag = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (flag != IDA_SUCCESS) { - IDAProcessError(IDA_mem, -1, "IDASBBDPRE", "IDAAgcomm", - MSGBBD_BAD_T); - return(-1); + if (flag != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_BAD_T); + return (-1); } } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre_impl.h b/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre_impl.h index b1cef5c00..9f5429d70 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_bbdpre_impl.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,10 +22,10 @@ #define _IDASBBDPRE_IMPL_H #include -#include #include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -35,16 +35,16 @@ extern "C" { * ----------------------------------------------------------------- */ -typedef struct IBBDPrecDataRec { - +typedef struct IBBDPrecDataRec +{ /* passed by user to IDABBDPrecAlloc and used by IDABBDPrecSetup/IDABBDPrecSolve functions */ sunindextype mudq, mldq, mukeep, mlkeep; - realtype rel_yy; + sunrealtype rel_yy; IDABBDLocalFn glocal; IDABBDCommFn gcomm; - /* set by IDABBDPrecSetup and used by IDABBDPrecSetup and + /* set by IDABBDPrecSetup and used by IDABBDPrecSetup and IDABBDPrecSolve functions */ sunindextype n_local; SUNMatrix PP; @@ -62,9 +62,9 @@ typedef struct IBBDPrecDataRec { long int nge; /* pointer to ida_mem */ - void *ida_mem; + void* ida_mem; -} *IBBDPrecData; +}* IBBDPrecData; /* * ----------------------------------------------------------------- @@ -72,14 +72,13 @@ typedef struct IBBDPrecDataRec { * ----------------------------------------------------------------- */ -typedef struct IDABBDPrecDataRecB { - +typedef struct IDABBDPrecDataRecB +{ /* BBD user functions (glocB and cfnB) for backward run */ IDABBDLocalFnB glocalB; - IDABBDCommFnB gcommB; - -} *IDABBDPrecDataB; + IDABBDCommFnB gcommB; +}* IDABBDPrecDataB; /* * ----------------------------------------------------------------- @@ -87,18 +86,23 @@ typedef struct IDABBDPrecDataRecB { * ----------------------------------------------------------------- */ -#define MSGBBD_MEM_NULL "Integrator memory is NULL." -#define MSGBBD_LMEM_NULL "Linear solver memory is NULL. One of the SPILS linear solvers must be attached." +#define MSGBBD_MEM_NULL "Integrator memory is NULL." +#define MSGBBD_LMEM_NULL \ + "Linear solver memory is NULL. One of the SPILS linear solvers must be " \ + "attached." #define MSGBBD_MEM_FAIL "A memory request failed." #define MSGBBD_BAD_NVECTOR "A required vector operation is not implemented." #define MSGBBD_SUNMAT_FAIL "An error arose from a SUNBandMatrix routine." #define MSGBBD_SUNLS_FAIL "An error arose from a SUNBandLinearSolver routine." -#define MSGBBD_PMEM_NULL "BBD peconditioner memory is NULL. IDABBDPrecInit must be called." -#define MSGBBD_FUNC_FAILED "The Glocal or Gcomm routine failed in an unrecoverable manner." - -#define MSGBBD_AMEM_NULL "idaadj_mem = NULL illegal." -#define MSGBBD_PDATAB_NULL "IDABBDPRE memory is NULL for the backward integration." -#define MSGBBD_BAD_T "Bad t for interpolation." +#define MSGBBD_PMEM_NULL \ + "BBD peconditioner memory is NULL. IDABBDPrecInit must be called." +#define MSGBBD_FUNC_FAILED \ + "The Glocal or Gcomm routine failed in an unrecoverable manner." + +#define MSGBBD_AMEM_NULL "idaadj_mem = NULL illegal." +#define MSGBBD_PDATAB_NULL \ + "IDABBDPRE memory is NULL for the backward integration." +#define MSGBBD_BAD_T "Bad t for interpolation." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_direct.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_direct.c deleted file mode 100644 index eb9293cb2..000000000 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_direct.c +++ /dev/null @@ -1,66 +0,0 @@ -/*----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - *----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - *----------------------------------------------------------------- - * Implementation file for the deprecated direct linear solver interface in - * IDA; these routines now just wrap the updated IDA generic - * linear solver interface in idas_ls.h. - *-----------------------------------------------------------------*/ - -#include -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/*================================================================= - Exported Functions (wrappers for equivalent routines in idas_ls.h) - =================================================================*/ - -int IDADlsSetLinearSolver(void *ida_mem, SUNLinearSolver LS, - SUNMatrix A) -{ return(IDASetLinearSolver(ida_mem, LS, A)); } - -int IDADlsSetJacFn(void *ida_mem, IDADlsJacFn jac) -{ return(IDASetJacFn(ida_mem, jac)); } - -int IDADlsGetWorkSpace(void *ida_mem, long int *lenrwLS, - long int *leniwLS) -{ return(IDAGetLinWorkSpace(ida_mem, lenrwLS, leniwLS)); } - -int IDADlsGetNumJacEvals(void *ida_mem, long int *njevals) -{ return(IDAGetNumJacEvals(ida_mem, njevals)); } - -int IDADlsGetNumResEvals(void *ida_mem, long int *nrevalsLS) -{ return(IDAGetNumLinResEvals(ida_mem, nrevalsLS)); } - -int IDADlsGetLastFlag(void *ida_mem, long int *flag) -{ return(IDAGetLastLinFlag(ida_mem, flag)); } - -char *IDADlsGetReturnFlagName(long int flag) -{ return(IDAGetLinReturnFlagName(flag)); } - -int IDADlsSetLinearSolverB(void *ida_mem, int which, - SUNLinearSolver LS, SUNMatrix A) -{ return(IDASetLinearSolverB(ida_mem, which, LS, A)); } - -int IDADlsSetJacFnB(void *ida_mem, int which, IDADlsJacFnB jacB) -{ return(IDASetJacFnB(ida_mem, which, jacB)); } - -int IDADlsSetJacFnBS(void *ida_mem, int which, IDADlsJacFnBS jacBS) -{ return(IDASetJacFnBS(ida_mem, which, jacBS)); } - -#ifdef __cplusplus -} -#endif - diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ic.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ic.c index d0874d298..c2f4d030b 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ic.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ic.c @@ -1,12 +1,8 @@ -/* - * ----------------------------------------------------------------- - * $Revision$ - * $Date$ - * ----------------------------------------------------------------- +/* ----------------------------------------------------------------- * Programmers: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -16,44 +12,44 @@ * SUNDIALS Copyright End * ----------------------------------------------------------------- * This is the implementation file for the IC calculation for IDAS. - * It is independent of the linear solver in use. + * It is independent of the linear solver in use. * ----------------------------------------------------------------- */ #include #include +#include #include "idas_impl.h" -#include /* * ================================================================= - * IDA Constants + * IDA Constants * ================================================================= */ /* Private Constants */ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define HALF RCONST(0.5) /* real 0.5 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define PT99 RCONST(0.99) /* real 0.99 */ -#define PT1 RCONST(0.1) /* real 0.1 */ -#define PT001 RCONST(0.001) /* real 0.001 */ +#define ZERO SUN_RCONST(0.0) /* real 0.0 */ +#define HALF SUN_RCONST(0.5) /* real 0.5 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWO SUN_RCONST(2.0) /* real 2.0 */ +#define PT99 SUN_RCONST(0.99) /* real 0.99 */ +#define PT1 SUN_RCONST(0.1) /* real 0.1 */ +#define PT001 SUN_RCONST(0.001) /* real 0.001 */ /* IDACalcIC control constants */ -#define ICRATEMAX RCONST(0.9) /* max. Newton conv. rate */ -#define ALPHALS RCONST(0.0001) /* alpha in linesearch conv. test */ +#define ICRATEMAX SUN_RCONST(0.9) /* max. Newton conv. rate */ +#define ALPHALS SUN_RCONST(0.0001) /* alpha in linesearch conv. test */ /* Return values for lower level routines used by IDACalcIC */ -#define IC_FAIL_RECOV 1 -#define IC_CONSTR_FAILED 2 -#define IC_LINESRCH_FAILED 3 -#define IC_CONV_FAIL 4 -#define IC_SLOW_CONVRG 5 +#define IC_FAIL_RECOV 1 +#define IC_CONSTR_FAILED 2 +#define IC_LINESRCH_FAILED 3 +#define IC_CONV_FAIL 4 +#define IC_SLOW_CONVRG 5 /* * ================================================================= @@ -62,33 +58,26 @@ */ extern int IDAInitialSetup(IDAMem IDA_mem); -extern realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, - N_Vector w, booleantype mask); -extern realtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector *xS, - N_Vector *wS, booleantype mask); -extern realtype IDASensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector *xS, N_Vector *wS, - booleantype mask); -extern int IDASensEwtSet(IDAMem IDA_mem, N_Vector *yScur, N_Vector *weightS); +extern int IDASensEwtSet(IDAMem IDA_mem, N_Vector* yScur, N_Vector* weightS); static int IDANlsIC(IDAMem IDA_mem); static int IDANewtonIC(IDAMem IDA_mem); -static int IDALineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm); -static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm); -static int IDANewyyp(IDAMem IDA_mem, realtype lambda); +static int IDALineSrch(IDAMem IDA_mem, sunrealtype* delnorm, sunrealtype* fnorm); +static int IDAfnorm(IDAMem IDA_mem, sunrealtype* fnorm); +static int IDANewyyp(IDAMem IDA_mem, sunrealtype lambda); static int IDANewy(IDAMem IDA_mem); static int IDASensNewtonIC(IDAMem IDA_mem); -static int IDASensLineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm); -static int IDASensNewyyp(IDAMem IDA_mem, realtype lambda); -static int IDASensfnorm(IDAMem IDA_mem, realtype *fnorm); +static int IDASensLineSrch(IDAMem IDA_mem, sunrealtype* delnorm, + sunrealtype* fnorm); +static int IDASensNewyyp(IDAMem IDA_mem, sunrealtype lambda); +static int IDASensfnorm(IDAMem IDA_mem, sunrealtype* fnorm); static int IDASensNlsIC(IDAMem IDA_mem); static int IDAICFailFlag(IDAMem IDA_mem, int retval); - /* * ================================================================= * EXPORTED FUNCTIONS IMPLEMENTATION @@ -99,7 +88,7 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval); * ----------------------------------------------------------------- * IDACalcIC * ----------------------------------------------------------------- - * IDACalcIC computes consistent initial conditions, given the + * IDACalcIC computes consistent initial conditions, given the * user's initial guess for unknown components of yy0 and/or yp0. * * The return value is IDA_SUCCESS = 0 if no error occurred. @@ -117,65 +106,85 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval); * IDA_NO_RECOVERY res, lsetup, or lsolve had a recoverable * error, but IDACalcIC could not recover * IDA_CONSTR_FAIL the inequality constraints could not be met - * IDA_LINESEARCH_FAIL if the linesearch failed (either on steptol test + * IDA_LINESEARCH_FAIL the linesearch failed (either on steptol test * or on the maxbacks test) * IDA_CONV_FAIL the Newton iterations failed to converge * ----------------------------------------------------------------- */ -int IDACalcIC(void *ida_mem, int icopt, realtype tout1) +int IDACalcIC(void* ida_mem, int icopt, sunrealtype tout1) { int ewtsetOK; - int ier, nwt, nh, mxnh, icret, retval=0; + int ier, nwt, nh, mxnh, icret, retval = 0; int is; - realtype tdist, troundoff, minid, hic, ypnorm; + sunrealtype tdist, troundoff, minid, hic, ypnorm; IDAMem IDA_mem; - booleantype sensi_stg, sensi_sim; + sunbooleantype sensi_stg, sensi_sim; /* Check if IDA memory exists */ - if(ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDACalcIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); /* Check if problem was malloc'ed */ - - if(IDA_mem->ida_MallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDAS", "IDACalcIC", MSG_NO_MALLOC); - return(IDA_NO_MALLOC); + + if (IDA_mem->ida_MallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_NO_MALLOC); } /* Check inputs to IDA for correctness and consistency */ ier = IDAInitialSetup(IDA_mem); - if(ier != IDA_SUCCESS) return(IDA_ILL_INPUT); + if (ier != IDA_SUCCESS) + { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); + } IDA_mem->ida_SetupDone = SUNTRUE; /* Check legality of input arguments, and set IDA memory copies. */ - if(icopt != IDA_YA_YDP_INIT && icopt != IDA_Y_INIT) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDACalcIC", MSG_IC_BAD_ICOPT); - return(IDA_ILL_INPUT); + if (icopt != IDA_YA_YDP_INIT && icopt != IDA_Y_INIT) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_IC_BAD_ICOPT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } IDA_mem->ida_icopt = icopt; - if(icopt == IDA_YA_YDP_INIT && (IDA_mem->ida_id == NULL)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDACalcIC", MSG_IC_MISSING_ID); - return(IDA_ILL_INPUT); + if (icopt == IDA_YA_YDP_INIT && (IDA_mem->ida_id == NULL)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_IC_MISSING_ID); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - tdist = SUNRabs(tout1 - IDA_mem->ida_tn); - troundoff = TWO * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout1)); - if(tdist < troundoff) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDACalcIC", MSG_IC_TOO_CLOSE); - return(IDA_ILL_INPUT); + tdist = SUNRabs(tout1 - IDA_mem->ida_tn); + troundoff = TWO * IDA_mem->ida_uround * + (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout1)); + if (tdist < troundoff) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_IC_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } /* Are we computing sensitivities? */ - sensi_stg = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_STAGGERED)); - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_stg = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_STAGGERED)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); /* Allocate space and initialize temporary vectors */ @@ -185,18 +194,19 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) N_VScale(ONE, IDA_mem->ida_phi[0], IDA_mem->ida_yy0); N_VScale(ONE, IDA_mem->ida_phi[1], IDA_mem->ida_yp0); - if (IDA_mem->ida_sensi) { - - /* Allocate temporary space required for sensitivity IC: yyS0 and ypS0. */ + if (IDA_mem->ida_sensi) + { + /* Allocate temporary space required for sensitivity IC: yyS0 and ypS0. */ IDA_mem->ida_yyS0 = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_ee); IDA_mem->ida_ypS0 = N_VCloneVectorArray(IDA_mem->ida_Ns, IDA_mem->ida_ee); - + /* Initialize sensitivity vector. */ - for (is=0; isida_Ns; is++) { - N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); - N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); + N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); } - + /* Initialize work space vectors needed for sensitivities. */ IDA_mem->ida_savresS = IDA_mem->ida_phiS[2]; IDA_mem->ida_delnewS = IDA_mem->ida_phiS[3]; @@ -208,21 +218,25 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) IDA_mem->ida_sysindex = 1; IDA_mem->ida_tscale = tdist; - if(icopt == IDA_YA_YDP_INIT) { + if (icopt == IDA_YA_YDP_INIT) + { minid = N_VMin(IDA_mem->ida_id); - if(minid < ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDACalcIC", MSG_IC_BAD_ID); - return(IDA_ILL_INPUT); + if (minid < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_IC_BAD_ID); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_ILL_INPUT); } - if(minid > HALF) IDA_mem->ida_sysindex = 0; + if (minid > HALF) { IDA_mem->ida_sysindex = 0; } } /* Set the test constant in the Newton convergence test */ IDA_mem->ida_epsNewt = IDA_mem->ida_epiccon; - /* Initializations: - cjratio = 1 (for use in direct linear solvers); + /* Initializations: + cjratio = 1 (for use in direct linear solvers); set nbacktr = 0; */ IDA_mem->ida_cjratio = ONE; @@ -230,195 +244,220 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) /* Set hic, hh, cj, and mxnh. */ - hic = PT001*tdist; - ypnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_yp0, IDA_mem->ida_ewt, IDA_mem->ida_suppressalg); + hic = PT001 * tdist; + ypnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_yp0, IDA_mem->ida_ewt, + IDA_mem->ida_suppressalg); - if (sensi_sim) - ypnorm = IDASensWrmsNormUpdate(IDA_mem, ypnorm, IDA_mem->ida_ypS0, IDA_mem->ida_ewtS, SUNFALSE); + if (sensi_sim) + { + ypnorm = IDASensWrmsNormUpdate(IDA_mem, ypnorm, IDA_mem->ida_ypS0, + IDA_mem->ida_ewtS, SUNFALSE); + } - if(ypnorm > HALF/hic) hic = HALF/ypnorm; - if(tout1 < IDA_mem->ida_tn) hic = -hic; + if (ypnorm > HALF / hic) { hic = HALF / ypnorm; } + if (tout1 < IDA_mem->ida_tn) { hic = -hic; } IDA_mem->ida_hh = hic; - if(icopt == IDA_YA_YDP_INIT) { - IDA_mem->ida_cj = ONE/hic; - mxnh = IDA_mem->ida_maxnh; + if (icopt == IDA_YA_YDP_INIT) + { + IDA_mem->ida_cj = ONE / hic; + mxnh = IDA_mem->ida_maxnh; } - else { + else + { IDA_mem->ida_cj = ZERO; - mxnh = 1; + mxnh = 1; } /* Loop over nwt = number of evaluations of ewt vector. */ - for(nwt = 1; nwt <= 2; nwt++) { - + for (nwt = 1; nwt <= 2; nwt++) + { /* Loop over nh = number of h values. */ - for(nh = 1; nh <= mxnh; nh++) { - + for (nh = 1; nh <= mxnh; nh++) + { /* Call the IC nonlinear solver function. */ retval = IDANlsIC(IDA_mem); /* Cut h and loop on recoverable IDA_YA_YDP_INIT failure; else break. */ - if(retval == IDA_SUCCESS) break; + if (retval == IDA_SUCCESS) { break; } IDA_mem->ida_ncfn++; - if(retval < 0) break; - if(nh == mxnh) break; + if (retval < 0) { break; } + if (nh == mxnh) { break; } /* If looping to try again, reset yy0 and yp0 if not converging. */ - if(retval != IC_SLOW_CONVRG) { + if (retval != IC_SLOW_CONVRG) + { N_VScale(ONE, IDA_mem->ida_phi[0], IDA_mem->ida_yy0); N_VScale(ONE, IDA_mem->ida_phi[1], IDA_mem->ida_yp0); - if (sensi_sim) { - + if (sensi_sim) + { /* Reset yyS0 and ypS0. */ /* Copy phiS[0] and phiS[1] into yyS0 and ypS0. */ - for (is=0; isida_Ns; is++) { - N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); - N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); + N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); } } } hic *= PT1; - IDA_mem->ida_cj = ONE/hic; + IDA_mem->ida_cj = ONE / hic; IDA_mem->ida_hh = hic; - } /* End of nh loop */ + } /* End of nh loop */ /* Break on failure */ - if(retval != IDA_SUCCESS) break; - + if (retval != IDA_SUCCESS) { break; } + /* Reset ewt, save yy0, yp0 in phi, and loop. */ - ewtsetOK = IDA_mem->ida_efun(IDA_mem->ida_yy0, IDA_mem->ida_ewt, IDA_mem->ida_edata); - if(ewtsetOK != 0) { - retval = IDA_BAD_EWT; - break; + ewtsetOK = IDA_mem->ida_efun(IDA_mem->ida_yy0, IDA_mem->ida_ewt, + IDA_mem->ida_edata); + if (ewtsetOK != 0) + { + retval = IDA_BAD_EWT; + break; } N_VScale(ONE, IDA_mem->ida_yy0, IDA_mem->ida_phi[0]); N_VScale(ONE, IDA_mem->ida_yp0, IDA_mem->ida_phi[1]); - - if (sensi_sim) { - + + if (sensi_sim) + { /* Reevaluate ewtS. */ ewtsetOK = IDASensEwtSet(IDA_mem, IDA_mem->ida_yyS0, IDA_mem->ida_ewtS); - if(ewtsetOK != 0) { - retval = IDA_BAD_EWT; - break; + if (ewtsetOK != 0) + { + retval = IDA_BAD_EWT; + break; } - + /* Save yyS0 and ypS0. */ - for (is=0; isida_Ns; is++) { - N_VScale(ONE, IDA_mem->ida_yyS0[is], IDA_mem->ida_phiS[0][is]); - N_VScale(ONE, IDA_mem->ida_ypS0[is], IDA_mem->ida_phiS[1][is]); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_yyS0[is], IDA_mem->ida_phiS[0][is]); + N_VScale(ONE, IDA_mem->ida_ypS0[is], IDA_mem->ida_phiS[1][is]); } } - } /* End of nwt loop */ + } /* End of nwt loop */ /* Load the optional outputs. */ - if(icopt == IDA_YA_YDP_INIT) IDA_mem->ida_hused = hic; + if (icopt == IDA_YA_YDP_INIT) { IDA_mem->ida_hused = hic; } /* On any failure, free memory, print error message and return */ - if(retval != IDA_SUCCESS) { + if (retval != IDA_SUCCESS) + { N_VDestroy(IDA_mem->ida_yy0); N_VDestroy(IDA_mem->ida_yp0); - if(IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { N_VDestroyVectorArray(IDA_mem->ida_yyS0, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypS0, IDA_mem->ida_Ns); } icret = IDAICFailFlag(IDA_mem, retval); - return(icret); + + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (icret); } /* Unless using the STAGGERED approach for sensitivities, return now */ - if (!sensi_stg) { - + if (!sensi_stg) + { N_VDestroy(IDA_mem->ida_yy0); N_VDestroy(IDA_mem->ida_yp0); - if(IDA_mem->ida_sensi) { + if (IDA_mem->ida_sensi) + { N_VDestroyVectorArray(IDA_mem->ida_yyS0, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypS0, IDA_mem->ida_Ns); } - return(IDA_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* Find consistent I.C. for sensitivities using a staggered approach */ - - - /* Evaluate res at converged y, needed for future evaluations of sens. RHS - If res() fails recoverably, treat it as a convergence failure and + + /* Evaluate res at converged y, needed for future evaluations of sens. RHS + If res() fails recoverably, treat it as a convergence failure and attempt the step again */ - - retval = IDA_mem->ida_res(IDA_mem->ida_t0, IDA_mem->ida_yy0, - IDA_mem->ida_yp0, IDA_mem->ida_delta, - IDA_mem->ida_user_data); + + retval = IDA_mem->ida_res(IDA_mem->ida_t0, IDA_mem->ida_yy0, IDA_mem->ida_yp0, + IDA_mem->ida_delta, IDA_mem->ida_user_data); IDA_mem->ida_nre++; - if(retval < 0) + if (retval < 0) + { /* res function failed unrecoverably. */ - return(IDA_RES_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_RES_FAIL); + } - if(retval > 0) + if (retval > 0) + { /* res function failed recoverably but no recovery possible. */ - return(IDA_FIRST_RES_FAIL); - + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_FIRST_RES_FAIL); + } + /* Loop over nwt = number of evaluations of ewt vector. */ - for(nwt = 1; nwt <= 2; nwt++) { - + for (nwt = 1; nwt <= 2; nwt++) + { /* Loop over nh = number of h values. */ - for(nh = 1; nh <= mxnh; nh++) { - + for (nh = 1; nh <= mxnh; nh++) + { retval = IDASensNlsIC(IDA_mem); - if(retval == IDA_SUCCESS) break; + if (retval == IDA_SUCCESS) { break; } /* Increment the number of the sensitivity related corrector convergence failures. */ IDA_mem->ida_ncfnS++; - if(retval < 0) break; - if(nh == mxnh) break; + if (retval < 0) { break; } + if (nh == mxnh) { break; } /* If looping to try again, reset yyS0 and ypS0 if not converging. */ - if(retval != IC_SLOW_CONVRG) { - for (is=0; isida_Ns; is++) { - N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); - N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); + if (retval != IC_SLOW_CONVRG) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_phiS[0][is], IDA_mem->ida_yyS0[is]); + N_VScale(ONE, IDA_mem->ida_phiS[1][is], IDA_mem->ida_ypS0[is]); } } hic *= PT1; - IDA_mem->ida_cj = ONE/hic; + IDA_mem->ida_cj = ONE / hic; IDA_mem->ida_hh = hic; - - } /* End of nh loop */ + + } /* End of nh loop */ /* Break on failure */ - if(retval != IDA_SUCCESS) break; + if (retval != IDA_SUCCESS) { break; } - /* Since it was successful, reevaluate ewtS with the new values of yyS0, save - yyS0 and ypS0 in phiS[0] and phiS[1] and loop one more time to check and + /* Since it was successful, reevaluate ewtS with the new values of yyS0, save + yyS0 and ypS0 in phiS[0] and phiS[1] and loop one more time to check and maybe correct the new sensitivities IC with respect to the new weights. */ - + /* Reevaluate ewtS. */ ewtsetOK = IDASensEwtSet(IDA_mem, IDA_mem->ida_yyS0, IDA_mem->ida_ewtS); - if(ewtsetOK != 0) { - retval = IDA_BAD_EWT; - break; + if (ewtsetOK != 0) + { + retval = IDA_BAD_EWT; + break; } /* Save yyS0 and ypS0. */ - for (is=0; isida_Ns; is++) { - N_VScale(ONE, IDA_mem->ida_yyS0[is], IDA_mem->ida_phiS[0][is]); - N_VScale(ONE, IDA_mem->ida_ypS0[is], IDA_mem->ida_phiS[1][is]); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_yyS0[is], IDA_mem->ida_phiS[0][is]); + N_VScale(ONE, IDA_mem->ida_ypS0[is], IDA_mem->ida_phiS[1][is]); } - } /* End of nwt loop */ - + } /* End of nwt loop */ /* Load the optional outputs. */ - if(icopt == IDA_YA_YDP_INIT) IDA_mem->ida_hused = hic; + if (icopt == IDA_YA_YDP_INIT) { IDA_mem->ida_hused = hic; } /* Free temporary space */ N_VDestroy(IDA_mem->ida_yy0); @@ -428,17 +467,17 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) N_VDestroyVectorArray(IDA_mem->ida_yyS0, IDA_mem->ida_Ns); N_VDestroyVectorArray(IDA_mem->ida_ypS0, IDA_mem->ida_Ns); - /* On any failure, print message and return proper flag. */ - if(retval != IDA_SUCCESS) { + if (retval != IDA_SUCCESS) + { icret = IDAICFailFlag(IDA_mem, retval); - return(icret); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (icret); } /* Otherwise return success flag. */ - - return(IDA_SUCCESS); - + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return (IDA_SUCCESS); } /* @@ -451,7 +490,7 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) * ----------------------------------------------------------------- * IDANlsIC * ----------------------------------------------------------------- - * IDANlsIC solves a nonlinear system for consistent initial + * IDANlsIC solves a nonlinear system for consistent initial * conditions. It calls IDANewtonIC to do most of the work. * * The return value is IDA_SUCCESS = 0 if no error occurred. @@ -476,79 +515,82 @@ static int IDANlsIC(IDAMem IDA_mem) { int retval, nj, is; N_Vector tv1, tv2, tv3; - booleantype sensi_sim; + sunbooleantype sensi_sim; /* Are we computing sensitivities with the IDA_SIMULTANEOUS approach? */ - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); tv1 = IDA_mem->ida_ee; tv2 = IDA_mem->ida_tempv2; tv3 = IDA_mem->ida_phi[2]; - + /* Evaluate RHS. */ retval = IDA_mem->ida_res(IDA_mem->ida_t0, IDA_mem->ida_yy0, IDA_mem->ida_yp0, IDA_mem->ida_delta, IDA_mem->ida_user_data); IDA_mem->ida_nre++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IDA_FIRST_RES_FAIL); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IDA_FIRST_RES_FAIL); } /* Save the residual. */ N_VScale(ONE, IDA_mem->ida_delta, IDA_mem->ida_savres); - if(sensi_sim) { - + if (sensi_sim) + { /*Evaluate sensitivity RHS and save it in savresS. */ - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, IDA_mem->ida_yy0, IDA_mem->ida_yp0, - IDA_mem->ida_delta, - IDA_mem->ida_yyS0, IDA_mem->ida_ypS0, - IDA_mem->ida_deltaS, - IDA_mem->ida_user_dataS, - IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, - IDA_mem->ida_tmpS3); + IDA_mem->ida_delta, IDA_mem->ida_yyS0, + IDA_mem->ida_ypS0, IDA_mem->ida_deltaS, + IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, + IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrSe++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IDA_FIRST_RES_FAIL); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IDA_FIRST_RES_FAIL); } - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_deltaS[is], IDA_mem->ida_savresS[is]); + } } /* Loop over nj = number of linear solve Jacobian setups. */ - for(nj = 1; nj <= IDA_mem->ida_maxnj; nj++) { - + for (nj = 1; nj <= IDA_mem->ida_maxnj; nj++) + { /* If there is a setup routine, call it. */ - if(IDA_mem->ida_lsetup) { + if (IDA_mem->ida_lsetup) + { IDA_mem->ida_nsetups++; - retval = IDA_mem->ida_lsetup(IDA_mem, IDA_mem->ida_yy0, - IDA_mem->ida_yp0, IDA_mem->ida_delta, - tv1, tv2, tv3); - if(retval < 0) return(IDA_LSETUP_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + retval = IDA_mem->ida_lsetup(IDA_mem, IDA_mem->ida_yy0, IDA_mem->ida_yp0, + IDA_mem->ida_delta, tv1, tv2, tv3); + if (retval < 0) { return (IDA_LSETUP_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } } /* Call the Newton iteration routine, and return if successful. */ retval = IDANewtonIC(IDA_mem); - if(retval == IDA_SUCCESS) return(IDA_SUCCESS); + if (retval == IDA_SUCCESS) { return (IDA_SUCCESS); } /* If converging slowly and lsetup is nontrivial, retry. */ - if(retval == IC_SLOW_CONVRG && IDA_mem->ida_lsetup) { + if (retval == IC_SLOW_CONVRG && IDA_mem->ida_lsetup) + { N_VScale(ONE, IDA_mem->ida_savres, IDA_mem->ida_delta); - if(sensi_sim) - for(is=0; isida_Ns; is++) + if (sensi_sim) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_savresS[is], IDA_mem->ida_deltaS[is]); + } + } continue; - } else { - return(retval); } + else { return (retval); } - } /* End of nj loop */ + } /* End of nj loop */ /* No convergence after maxnj tries; return with retval=IC_SLOW_CONVRG */ - return(retval); - + return (retval); } /* @@ -567,7 +609,7 @@ static int IDANlsIC(IDAMem IDA_mem) * or on maxbacks test) * IC_CONV_FAIL if the Newton iterations failed to converge * IC_SLOW_CONVRG if the iterations appear to be converging slowly. - * They failed the convergence test, but showed + * They failed the convergence test, but showed * an overall norm reduction (by a factor of < 0.1) * or a convergence rate <= ICRATEMAX). * The error return values (negative) considered non-recoverable are: @@ -579,33 +621,35 @@ static int IDANlsIC(IDAMem IDA_mem) static int IDANewtonIC(IDAMem IDA_mem) { int retval, mnewt, is; - realtype delnorm, fnorm, fnorm0, oldfnrm, rate; - booleantype sensi_sim; + sunrealtype delnorm, fnorm, fnorm0, oldfnrm, rate; + sunbooleantype sensi_sim; /* Are we computing sensitivities with the IDA_SIMULTANEOUS approach? */ - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); /* Set pointer for vector delnew */ IDA_mem->ida_delnew = IDA_mem->ida_phi[2]; /* Call the linear solve function to get the Newton step, delta. */ - retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_delta, - IDA_mem->ida_ewt, IDA_mem->ida_yy0, - IDA_mem->ida_yp0, IDA_mem->ida_savres); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_delta, IDA_mem->ida_ewt, + IDA_mem->ida_yy0, IDA_mem->ida_yp0, + IDA_mem->ida_savres); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } /* Compute the norm of the step. */ fnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delta, IDA_mem->ida_ewt, SUNFALSE); /* Call the lsolve function to get correction vectors deltaS. */ - if (sensi_sim) { - for(is=0;isida_Ns;is++) { + if (sensi_sim) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_deltaS[is], IDA_mem->ida_ewtS[is], IDA_mem->ida_yy0, IDA_mem->ida_yp0, IDA_mem->ida_savres); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } } /* Update the norm of delta. */ fnorm = IDASensWrmsNormUpdate(IDA_mem, fnorm, IDA_mem->ida_deltaS, @@ -613,9 +657,11 @@ static int IDANewtonIC(IDAMem IDA_mem) } /* Test for convergence. Return now if the norm is small. */ - if(IDA_mem->ida_sysindex == 0) + if (IDA_mem->ida_sysindex == 0) + { fnorm *= IDA_mem->ida_tscale * SUNRabs(IDA_mem->ida_cj); - if(fnorm <= IDA_mem->ida_epsNewt) return(IDA_SUCCESS); + } + if (fnorm <= IDA_mem->ida_epsNewt) { return (IDA_SUCCESS); } fnorm0 = fnorm; /* Initialize rate to avoid compiler warning message */ @@ -623,49 +669,52 @@ static int IDANewtonIC(IDAMem IDA_mem) /* Newton iteration loop */ - for(mnewt = 0; mnewt < IDA_mem->ida_maxnit; mnewt++) { - + for (mnewt = 0; mnewt < IDA_mem->ida_maxnit; mnewt++) + { IDA_mem->ida_nni++; delnorm = fnorm; oldfnrm = fnorm; /* Call the Linesearch function and return if it failed. */ retval = IDALineSrch(IDA_mem, &delnorm, &fnorm); - if(retval != IDA_SUCCESS) return(retval); + if (retval != IDA_SUCCESS) { return (retval); } /* Set the observed convergence rate and test for convergence. */ - rate = fnorm/oldfnrm; - if(fnorm <= IDA_mem->ida_epsNewt) return(IDA_SUCCESS); + rate = fnorm / oldfnrm; + if (fnorm <= IDA_mem->ida_epsNewt) { return (IDA_SUCCESS); } /* If not converged, copy new step vector, and loop. */ N_VScale(ONE, IDA_mem->ida_delnew, IDA_mem->ida_delta); - if(sensi_sim) { + if (sensi_sim) + { /* Update the iteration's step for sensitivities. */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_delnewS[is], IDA_mem->ida_deltaS[is]); + } } - } /* End of Newton iteration loop */ + } /* End of Newton iteration loop */ /* Return either IC_SLOW_CONVRG or recoverable fail flag. */ - if(rate <= ICRATEMAX || fnorm < PT1*fnorm0) return(IC_SLOW_CONVRG); - return(IC_CONV_FAIL); + if (rate <= ICRATEMAX || fnorm < PT1 * fnorm0) { return (IC_SLOW_CONVRG); } + return (IC_CONV_FAIL); } /* * ----------------------------------------------------------------- * IDALineSrch * ----------------------------------------------------------------- - * IDALineSrch performs the Linesearch algorithm with the + * IDALineSrch performs the Linesearch algorithm with the * calculation of consistent initial conditions. * - * On entry, yy0 and yp0 are the current values of y and y', the + * On entry, yy0 and yp0 are the current values of y and y', the * Newton step is delta, the current residual vector F is savres, * delnorm is WRMS-norm(delta), and fnorm is the norm of the vector * J-inverse F. * - * On a successful return, yy0, yp0, and savres have been updated, + * On a successful return, yy0, yp0, and savres have been updated, * delnew contains the current value of J-inverse F, and fnorm is * WRMS-norm(delnew). * @@ -681,106 +730,115 @@ static int IDANewtonIC(IDAMem IDA_mem) * ----------------------------------------------------------------- */ -static int IDALineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) +static int IDALineSrch(IDAMem IDA_mem, sunrealtype* delnorm, sunrealtype* fnorm) { - booleantype conOK; + sunbooleantype conOK; int retval, is, nbacks; - realtype f1norm, fnormp, f1normp, ratio, lambda, minlam, slpi; + sunrealtype f1norm, fnormp, f1normp, ratio, lambda, minlam, slpi; N_Vector mc; - booleantype sensi_sim; + sunbooleantype sensi_sim; /* Initialize work space pointers, f1norm, ratio. (Use of mc in constraint check does not conflict with ypnew.) */ - mc = IDA_mem->ida_ee; + mc = IDA_mem->ida_ee; IDA_mem->ida_dtemp = IDA_mem->ida_phi[3]; - IDA_mem->ida_ynew = IDA_mem->ida_tempv2; + IDA_mem->ida_ynew = IDA_mem->ida_tempv2; IDA_mem->ida_ypnew = IDA_mem->ida_ee; - f1norm = (*fnorm)*(*fnorm)*HALF; - ratio = ONE; + f1norm = (*fnorm) * (*fnorm) * HALF; + ratio = ONE; /* If there are constraints, check and reduce step if necessary. */ - if(IDA_mem->ida_constraintsSet) { - + if (IDA_mem->ida_constraintsSet) + { /* Update y and check constraints. */ IDANewy(IDA_mem); - conOK = N_VConstrMask(IDA_mem->ida_constraints, - IDA_mem->ida_ynew, mc); + conOK = N_VConstrMask(IDA_mem->ida_constraints, IDA_mem->ida_ynew, mc); - if(!conOK) { + if (!conOK) + { /* Not satisfied. Compute scaled step to satisfy constraints. */ N_VProd(mc, IDA_mem->ida_delta, IDA_mem->ida_dtemp); - ratio = PT99*N_VMinQuotient(IDA_mem->ida_yy0, IDA_mem->ida_dtemp); + ratio = PT99 * N_VMinQuotient(IDA_mem->ida_yy0, IDA_mem->ida_dtemp); (*delnorm) *= ratio; - if((*delnorm) <= IDA_mem->ida_steptol) - return(IC_CONSTR_FAILED); + if ((*delnorm) <= IDA_mem->ida_steptol) { return (IC_CONSTR_FAILED); } N_VScale(ratio, IDA_mem->ida_delta, IDA_mem->ida_delta); } } /* End of constraints check */ - slpi = -TWO*f1norm*ratio; + slpi = -TWO * f1norm * ratio; minlam = IDA_mem->ida_steptol / (*delnorm); lambda = ONE; nbacks = 0; /* Are we computing sensitivities with the IDA_SIMULTANEOUS approach? */ - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); /* In IDA_Y_INIT case, set ypnew = yp0 (fixed) for linesearch. */ - if(IDA_mem->ida_icopt == IDA_Y_INIT) { + if (IDA_mem->ida_icopt == IDA_Y_INIT) + { N_VScale(ONE, IDA_mem->ida_yp0, IDA_mem->ida_ypnew); /* do the same for sensitivities. */ - if(sensi_sim) { - for(is=0; isida_Ns; is++) + if (sensi_sim) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_ypS0[is], IDA_mem->ida_ypS0new[is]); + } } } /* Loop on linesearch variable lambda. */ - for(;;) { - - if (nbacks == IDA_mem->ida_maxbacks) - return(IC_LINESRCH_FAILED); + for (;;) + { + if (nbacks == IDA_mem->ida_maxbacks) { return (IC_LINESRCH_FAILED); } /* Get new (y,y') = (ynew,ypnew) and norm of new function value. */ IDANewyyp(IDA_mem, lambda); retval = IDAfnorm(IDA_mem, &fnormp); - if(retval != IDA_SUCCESS) return(retval); + if (retval != IDA_SUCCESS) { return (retval); } /* If lsoff option is on, break out. */ - if(IDA_mem->ida_lsoff) break; + if (IDA_mem->ida_lsoff) { break; } /* Do alpha-condition test. */ - f1normp = fnormp*fnormp*HALF; - if(f1normp <= f1norm + ALPHALS*slpi*lambda) break; - if(lambda < minlam) return(IC_LINESRCH_FAILED); + f1normp = fnormp * fnormp * HALF; + if (f1normp <= f1norm + ALPHALS * slpi * lambda) { break; } + if (lambda < minlam) { return (IC_LINESRCH_FAILED); } lambda /= TWO; - IDA_mem->ida_nbacktr++; nbacks++; + IDA_mem->ida_nbacktr++; + nbacks++; - } /* End of breakout linesearch loop */ + } /* End of breakout linesearch loop */ /* Update yy0, yp0. */ N_VScale(ONE, IDA_mem->ida_ynew, IDA_mem->ida_yy0); - if(sensi_sim) { + if (sensi_sim) + { /* Update yyS0 and ypS0. */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_yyS0new[is], IDA_mem->ida_yyS0[is]); + } } - if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { + if (IDA_mem->ida_icopt == IDA_YA_YDP_INIT) + { N_VScale(ONE, IDA_mem->ida_ypnew, IDA_mem->ida_yp0); - - if(sensi_sim) - for(is=0; isida_Ns; is++) - N_VScale(ONE, IDA_mem->ida_ypS0new[is], IDA_mem->ida_ypS0[is]); + if (sensi_sim) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VScale(ONE, IDA_mem->ida_ypS0new[is], IDA_mem->ida_ypS0[is]); + } + } } /* Update fnorm, then return. */ *fnorm = fnormp; - return(IDA_SUCCESS); - + return (IDA_SUCCESS); } /* @@ -788,7 +846,7 @@ static int IDALineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) * IDAfnorm * ----------------------------------------------------------------- * IDAfnorm computes the norm of the current function value, by - * evaluating the DAE residual function, calling the linear + * evaluating the DAE residual function, calling the linear * system solver, and computing a WRMS-norm. * * On return, savres contains the current residual vector F, and @@ -801,7 +859,7 @@ static int IDALineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) * ----------------------------------------------------------------- */ -static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm) +static int IDAfnorm(IDAMem IDA_mem, sunrealtype* fnorm) { int retval, is; @@ -810,8 +868,8 @@ static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm) IDA_mem->ida_ypnew, IDA_mem->ida_delnew, IDA_mem->ida_user_data); IDA_mem->ida_nre++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } N_VScale(ONE, IDA_mem->ida_delnew, IDA_mem->ida_savres); @@ -819,58 +877,55 @@ static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm) retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_delnew, IDA_mem->ida_ewt, IDA_mem->ida_ynew, IDA_mem->ida_ypnew, IDA_mem->ida_savres); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } /* Compute the WRMS-norm. */ *fnorm = IDAWrmsNorm(IDA_mem, IDA_mem->ida_delnew, IDA_mem->ida_ewt, SUNFALSE); - /* Are we computing SENSITIVITIES with the IDA_SIMULTANEOUS approach? */ - if(IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)) { - + if (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)) + { /* Evaluate the residual for sensitivities. */ - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, IDA_mem->ida_ynew, IDA_mem->ida_ypnew, - IDA_mem->ida_savres, - IDA_mem->ida_yyS0new, - IDA_mem->ida_ypS0new, - IDA_mem->ida_delnewS, - IDA_mem->ida_user_dataS, - IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, - IDA_mem->ida_tmpS3); + IDA_mem->ida_savres, IDA_mem->ida_yyS0new, + IDA_mem->ida_ypS0new, IDA_mem->ida_delnewS, + IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, + IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrSe++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } /* Save delnewS in savresS. */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_delnewS[is], IDA_mem->ida_savresS[is]); + } /* Call the linear solve function to get J-inverse deltaS. */ - for(is=0; isida_Ns; is++) { - + for (is = 0; is < IDA_mem->ida_Ns; is++) + { retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_delnewS[is], - IDA_mem->ida_ewtS[is], - IDA_mem->ida_ynew, - IDA_mem->ida_ypnew, - IDA_mem->ida_savres); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + IDA_mem->ida_ewtS[is], IDA_mem->ida_ynew, + IDA_mem->ida_ypnew, IDA_mem->ida_savres); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } } - + /* Include sensitivities in norm. */ *fnorm = IDASensWrmsNormUpdate(IDA_mem, *fnorm, IDA_mem->ida_delnewS, IDA_mem->ida_ewtS, SUNFALSE); } /* Rescale norm if index = 0. */ - if(IDA_mem->ida_sysindex == 0) + if (IDA_mem->ida_sysindex == 0) + { (*fnorm) *= IDA_mem->ida_tscale * SUNRabs(IDA_mem->ida_cj); + } - return(IDA_SUCCESS); - + return (IDA_SUCCESS); } /* @@ -885,36 +940,37 @@ static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm) * ----------------------------------------------------------------- */ -static int IDANewyyp(IDAMem IDA_mem, realtype lambda) +static int IDANewyyp(IDAMem IDA_mem, sunrealtype lambda) { int retval; - + retval = IDA_SUCCESS; /* IDA_YA_YDP_INIT case: ynew = yy0 - lambda*delta where id_i = 0 ypnew = yp0 - cj*lambda*delta where id_i = 1. */ - if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { - + if (IDA_mem->ida_icopt == IDA_YA_YDP_INIT) + { N_VProd(IDA_mem->ida_id, IDA_mem->ida_delta, IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_yp0, -IDA_mem->ida_cj*lambda, + N_VLinearSum(ONE, IDA_mem->ida_yp0, -IDA_mem->ida_cj * lambda, IDA_mem->ida_dtemp, IDA_mem->ida_ypnew); - N_VLinearSum(ONE, IDA_mem->ida_delta, -ONE, - IDA_mem->ida_dtemp, IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_yy0, -lambda, - IDA_mem->ida_dtemp, IDA_mem->ida_ynew); - - }else if(IDA_mem->ida_icopt == IDA_Y_INIT) { - + N_VLinearSum(ONE, IDA_mem->ida_delta, -ONE, IDA_mem->ida_dtemp, + IDA_mem->ida_dtemp); + N_VLinearSum(ONE, IDA_mem->ida_yy0, -lambda, IDA_mem->ida_dtemp, + IDA_mem->ida_ynew); + } + else if (IDA_mem->ida_icopt == IDA_Y_INIT) + { /* IDA_Y_INIT case: ynew = yy0 - lambda*delta. (ypnew = yp0 preset.) */ N_VLinearSum(ONE, IDA_mem->ida_yy0, -lambda, IDA_mem->ida_delta, IDA_mem->ida_ynew); } - if(IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)) + if (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)) + { retval = IDASensNewyyp(IDA_mem, lambda); - - return(retval); + } + return (retval); } /* @@ -931,34 +987,34 @@ static int IDANewyyp(IDAMem IDA_mem, realtype lambda) static int IDANewy(IDAMem IDA_mem) { - /* IDA_YA_YDP_INIT case: ynew = yy0 - delta where id_i = 0. */ - if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { + if (IDA_mem->ida_icopt == IDA_YA_YDP_INIT) + { N_VProd(IDA_mem->ida_id, IDA_mem->ida_delta, IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_delta, -ONE, - IDA_mem->ida_dtemp, IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_yy0, -ONE, - IDA_mem->ida_dtemp, IDA_mem->ida_ynew); - return(IDA_SUCCESS); + N_VLinearSum(ONE, IDA_mem->ida_delta, -ONE, IDA_mem->ida_dtemp, + IDA_mem->ida_dtemp); + N_VLinearSum(ONE, IDA_mem->ida_yy0, -ONE, IDA_mem->ida_dtemp, + IDA_mem->ida_ynew); + return (IDA_SUCCESS); } /* IDA_Y_INIT case: ynew = yy0 - delta. */ N_VLinearSum(ONE, IDA_mem->ida_yy0, -ONE, IDA_mem->ida_delta, IDA_mem->ida_ynew); - return(IDA_SUCCESS); - + return (IDA_SUCCESS); } + /* * ----------------------------------------------------------------- * Sensitivity I.C. functions * ----------------------------------------------------------------- */ -/* +/* * ----------------------------------------------------------------- * IDASensNlsIC * ----------------------------------------------------------------- - * IDASensNlsIC solves nonlinear systems for sensitivities consistent + * IDASensNlsIC solves nonlinear systems for sensitivities consistent * initial conditions. It mainly relies on IDASensNewtonIC. * * The return value is IDA_SUCCESS = 0 if no error occurred. @@ -983,60 +1039,61 @@ static int IDASensNlsIC(IDAMem IDA_mem) int retval; int is, nj; - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, - IDA_mem->ida_yy0, IDA_mem->ida_yp0, - IDA_mem->ida_delta, IDA_mem->ida_yyS0, - IDA_mem->ida_ypS0, - IDA_mem->ida_deltaS, - IDA_mem->ida_user_dataS, + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, IDA_mem->ida_yy0, + IDA_mem->ida_yp0, IDA_mem->ida_delta, + IDA_mem->ida_yyS0, IDA_mem->ida_ypS0, + IDA_mem->ida_deltaS, IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrSe++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IDA_FIRST_RES_FAIL); - + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IDA_FIRST_RES_FAIL); } + /* Save deltaS */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_deltaS[is], IDA_mem->ida_savresS[is]); + } /* Loop over nj = number of linear solve Jacobian setups. */ - for(nj = 1; nj <= 2; nj++) { - + for (nj = 1; nj <= 2; nj++) + { /* Call the Newton iteration routine */ retval = IDASensNewtonIC(IDA_mem); - if(retval == IDA_SUCCESS) return(IDA_SUCCESS); + if (retval == IDA_SUCCESS) { return (IDA_SUCCESS); } - /* If converging slowly and lsetup is nontrivial and this is the first pass, + /* If converging slowly and lsetup is nontrivial and this is the first pass, update Jacobian and retry. */ - if(retval == IC_SLOW_CONVRG && IDA_mem->ida_lsetup && nj==1) { - + if (retval == IC_SLOW_CONVRG && IDA_mem->ida_lsetup && nj == 1) + { /* Restore deltaS. */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_savresS[is], IDA_mem->ida_deltaS[is]); + } IDA_mem->ida_nsetupsS++; retval = IDA_mem->ida_lsetup(IDA_mem, IDA_mem->ida_yy0, IDA_mem->ida_yp0, IDA_mem->ida_delta, IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); - if(retval < 0) return(IDA_LSETUP_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + if (retval < 0) { return (IDA_LSETUP_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } continue; - } else { - return(retval); } + else { return (retval); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* * ----------------------------------------------------------------- * IDASensNewtonIC * ----------------------------------------------------------------- - * IDANewtonIC performs the Newton iteration to solve for - * sensitivities consistent initial conditions. It calls + * IDANewtonIC performs the Newton iteration to solve for + * sensitivities consistent initial conditions. It calls * IDASensLineSrch within each iteration. * On return, savresS contains the current residual vectors. * @@ -1048,7 +1105,7 @@ static int IDASensNlsIC(IDAMem IDA_mem) * or on maxbacks test) * IC_CONV_FAIL if the Newton iterations failed to converge * IC_SLOW_CONVRG if the iterations appear to be converging slowly. - * They failed the convergence test, but showed + * They failed the convergence test, but showed * an overall norm reduction (by a factor of < 0.1) * or a convergence rate <= ICRATEMAX). * The error return values (negative) considered non-recoverable are: @@ -1059,68 +1116,71 @@ static int IDASensNlsIC(IDAMem IDA_mem) static int IDASensNewtonIC(IDAMem IDA_mem) { int retval, is, mnewt; - realtype delnorm, fnorm, fnorm0, oldfnrm, rate; + sunrealtype delnorm, fnorm, fnorm0, oldfnrm, rate; - for(is=0;isida_Ns;is++) { - + for (is = 0; is < IDA_mem->ida_Ns; is++) + { /* Call the linear solve function to get the Newton step, delta. */ retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_deltaS[is], IDA_mem->ida_ewtS[is], IDA_mem->ida_yy0, IDA_mem->ida_yp0, IDA_mem->ida_delta); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); - + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } } - /* Compute the norm of the step and return if it is small enough */ - fnorm = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_deltaS, - IDA_mem->ida_ewtS, SUNFALSE); - if(IDA_mem->ida_sysindex == 0) + /* Compute the norm of the step and return if it is small enough */ + fnorm = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_deltaS, IDA_mem->ida_ewtS, + SUNFALSE); + if (IDA_mem->ida_sysindex == 0) + { fnorm *= IDA_mem->ida_tscale * SUNRabs(IDA_mem->ida_cj); - if(fnorm <= IDA_mem->ida_epsNewt) return(IDA_SUCCESS); + } + if (fnorm <= IDA_mem->ida_epsNewt) { return (IDA_SUCCESS); } fnorm0 = fnorm; rate = ZERO; /* Newton iteration loop */ - for(mnewt = 0; mnewt < IDA_mem->ida_maxnit; mnewt++) { - + for (mnewt = 0; mnewt < IDA_mem->ida_maxnit; mnewt++) + { IDA_mem->ida_nniS++; delnorm = fnorm; oldfnrm = fnorm; - + /* Call the Linesearch function and return if it failed. */ retval = IDASensLineSrch(IDA_mem, &delnorm, &fnorm); - if(retval != IDA_SUCCESS) return(retval); - + if (retval != IDA_SUCCESS) { return (retval); } + /* Set the observed convergence rate and test for convergence. */ - rate = fnorm/oldfnrm; - if(fnorm <= IDA_mem->ida_epsNewt) return(IDA_SUCCESS); - + rate = fnorm / oldfnrm; + if (fnorm <= IDA_mem->ida_epsNewt) { return (IDA_SUCCESS); } + /* If not converged, copy new step vectors, and loop. */ - for(is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_delnewS[is], IDA_mem->ida_deltaS[is]); - - } /* End of Newton iteration loop */ + } + + } /* End of Newton iteration loop */ /* Return either IC_SLOW_CONVRG or recoverable fail flag. */ - if(rate <= ICRATEMAX || fnorm < PT1*fnorm0) return(IC_SLOW_CONVRG); - return(IC_CONV_FAIL); + if (rate <= ICRATEMAX || fnorm < PT1 * fnorm0) { return (IC_SLOW_CONVRG); } + return (IC_CONV_FAIL); } /* * ----------------------------------------------------------------- * IDASensLineSrch * ----------------------------------------------------------------- - * IDASensLineSrch performs the Linesearch algorithm with the + * IDASensLineSrch performs the Linesearch algorithm with the * calculation of consistent initial conditions for sensitivities * systems. * - * On entry, yyS0 and ypS0 contain the current values, the Newton + * On entry, yyS0 and ypS0 contain the current values, the Newton * steps are contained in deltaS, the current residual vectors FS are * savresS, delnorm is sens-WRMS-norm(deltaS), and fnorm is - * max { WRMS-norm( J-inverse FS[is] ) : is=1,2,...,Ns } + * max { WRMS-norm( J-inverse FS[is] ) : is=1,2,...,Ns } * - * On a successful return, yy0, yp0, and savres have been updated, + * On a successful return, yy0, yp0, and savres have been updated, * delnew contains the current values of J-inverse FS, and fnorm is * max { WRMS-norm(delnewS[is]) : is = 1,2,...Ns } * @@ -1136,57 +1196,63 @@ static int IDASensNewtonIC(IDAMem IDA_mem) * ----------------------------------------------------------------- */ -static int IDASensLineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) +static int IDASensLineSrch(IDAMem IDA_mem, sunrealtype* delnorm, + sunrealtype* fnorm) { int is, retval, nbacks; - realtype f1norm, fnormp, f1normp, slpi, minlam; - realtype lambda, ratio; - + sunrealtype f1norm, fnormp, f1normp, slpi, minlam; + sunrealtype lambda, ratio; + /* Set work space pointer. */ IDA_mem->ida_dtemp = IDA_mem->ida_phi[3]; - f1norm = (*fnorm)*(*fnorm)*HALF; - + f1norm = (*fnorm) * (*fnorm) * HALF; + /* Initialize local variables. */ - ratio = ONE; - slpi = -TWO*f1norm*ratio; + ratio = ONE; + slpi = -TWO * f1norm * ratio; minlam = IDA_mem->ida_steptol / (*delnorm); lambda = ONE; nbacks = 0; - for(;;) { - - if (nbacks == IDA_mem->ida_maxbacks) - return(IC_LINESRCH_FAILED); + for (;;) + { + if (nbacks == IDA_mem->ida_maxbacks) { return (IC_LINESRCH_FAILED); } /* Get new iteration in (ySnew, ypSnew). */ IDASensNewyyp(IDA_mem, lambda); /* Get the norm of new function value. */ retval = IDASensfnorm(IDA_mem, &fnormp); - if (retval!=IDA_SUCCESS) return retval; + if (retval != IDA_SUCCESS) { return retval; } /* If lsoff option is on, break out. */ - if(IDA_mem->ida_lsoff) break; + if (IDA_mem->ida_lsoff) { break; } /* Do alpha-condition test. */ - f1normp = fnormp*fnormp*HALF; - if(f1normp <= f1norm + ALPHALS*slpi*lambda) break; - if(lambda < minlam) return(IC_LINESRCH_FAILED); + f1normp = fnormp * fnormp * HALF; + if (f1normp <= f1norm + ALPHALS * slpi * lambda) { break; } + if (lambda < minlam) { return (IC_LINESRCH_FAILED); } lambda /= TWO; - IDA_mem->ida_nbacktr++; nbacks++; + IDA_mem->ida_nbacktr++; + nbacks++; } - + /* Update yyS0, ypS0 and fnorm and return. */ - for(is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_yyS0new[is], IDA_mem->ida_yyS0[is]); } if (IDA_mem->ida_icopt == IDA_YA_YDP_INIT) - for(is=0; isida_Ns; is++) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_ypS0new[is], IDA_mem->ida_ypS0[is]); + } + } *fnorm = fnormp; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1194,7 +1260,7 @@ static int IDASensLineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) * IDASensfnorm * ----------------------------------------------------------------- * IDASensfnorm computes the norm of the current function value, by - * evaluating the sensitivity residual function, calling the linear + * evaluating the sensitivity residual function, calling the linear * system solver, and computing a WRMS-norm. * * On return, savresS contains the current residual vectors FS, and @@ -1207,90 +1273,93 @@ static int IDASensLineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) * ----------------------------------------------------------------- */ -static int IDASensfnorm(IDAMem IDA_mem, realtype *fnorm) +static int IDASensfnorm(IDAMem IDA_mem, sunrealtype* fnorm) { int is, retval; - + /* Get sensitivity residual */ - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, - IDA_mem->ida_yy0, IDA_mem->ida_yp0, - IDA_mem->ida_delta, - IDA_mem->ida_yyS0new, - IDA_mem->ida_ypS0new, - IDA_mem->ida_delnewS, - IDA_mem->ida_user_dataS, + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_t0, IDA_mem->ida_yy0, + IDA_mem->ida_yp0, IDA_mem->ida_delta, + IDA_mem->ida_yyS0new, IDA_mem->ida_ypS0new, + IDA_mem->ida_delnewS, IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); IDA_mem->ida_nrSe++; - if(retval < 0) return(IDA_RES_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); - - for(is=0; isida_Ns; is++) + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } + + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_delnewS[is], IDA_mem->ida_savresS[is]); - + } + /* Call linear solve function */ - for(is=0; isida_Ns; is++) { - + for (is = 0; is < IDA_mem->ida_Ns; is++) + { retval = IDA_mem->ida_lsolve(IDA_mem, IDA_mem->ida_delnewS[is], - IDA_mem->ida_ewtS[is], - IDA_mem->ida_yy0, - IDA_mem->ida_yp0, - IDA_mem->ida_delta); - if(retval < 0) return(IDA_LSOLVE_FAIL); - if(retval > 0) return(IC_FAIL_RECOV); + IDA_mem->ida_ewtS[is], IDA_mem->ida_yy0, + IDA_mem->ida_yp0, IDA_mem->ida_delta); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IC_FAIL_RECOV); } } /* Compute the WRMS-norm; rescale if index = 0. */ - *fnorm = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_delnewS, IDA_mem->ida_ewtS, SUNFALSE); - if(IDA_mem->ida_sysindex == 0) + *fnorm = IDASensWrmsNorm(IDA_mem, IDA_mem->ida_delnewS, IDA_mem->ida_ewtS, + SUNFALSE); + if (IDA_mem->ida_sysindex == 0) + { (*fnorm) *= IDA_mem->ida_tscale * SUNRabs(IDA_mem->ida_cj); + } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* * ----------------------------------------------------------------- * IDASensNewyyp * ----------------------------------------------------------------- - * IDASensNewyyp computes the Newton updates for each of the - * sensitivities systems using the current step vector lambda*delta, + * IDASensNewyyp computes the Newton updates for each of the + * sensitivities systems using the current step vector lambda*delta, * in a manner depending on icopt and the input id vector. * * The return value is always IDA_SUCCESS = 0. * ----------------------------------------------------------------- */ -static int IDASensNewyyp(IDAMem IDA_mem, realtype lambda) +static int IDASensNewyyp(IDAMem IDA_mem, sunrealtype lambda) { int is; - if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { - - /* IDA_YA_YDP_INIT case: + if (IDA_mem->ida_icopt == IDA_YA_YDP_INIT) + { + /* IDA_YA_YDP_INIT case: - ySnew = yS0 - lambda*deltaS where id_i = 0 - - ypSnew = ypS0 - cj*lambda*delta where id_i = 1. */ + - ypSnew = ypS0 - cj*lambda*delta where id_i = 1. */ - for(is=0; isida_Ns; is++) { - + for (is = 0; is < IDA_mem->ida_Ns; is++) + { /* It is ok to use dtemp as temporary vector here. */ N_VProd(IDA_mem->ida_id, IDA_mem->ida_deltaS[is], IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_ypS0[is], -IDA_mem->ida_cj*lambda, + N_VLinearSum(ONE, IDA_mem->ida_ypS0[is], -IDA_mem->ida_cj * lambda, IDA_mem->ida_dtemp, IDA_mem->ida_ypS0new[is]); - N_VLinearSum(ONE, IDA_mem->ida_deltaS[is], -ONE, - IDA_mem->ida_dtemp, IDA_mem->ida_dtemp); - N_VLinearSum(ONE, IDA_mem->ida_yyS0[is], -lambda, - IDA_mem->ida_dtemp, IDA_mem->ida_yyS0new[is]); + N_VLinearSum(ONE, IDA_mem->ida_deltaS[is], -ONE, IDA_mem->ida_dtemp, + IDA_mem->ida_dtemp); + N_VLinearSum(ONE, IDA_mem->ida_yyS0[is], -lambda, IDA_mem->ida_dtemp, + IDA_mem->ida_yyS0new[is]); } /* end loop is */ - }else { - - /* IDA_Y_INIT case: + } + else + { + /* IDA_Y_INIT case: - ySnew = yS0 - lambda*deltaS. (ypnew = yp0 preset.) */ - for(is=0; isida_Ns; is++) - N_VLinearSum(ONE, IDA_mem->ida_yyS0[is], -lambda, - IDA_mem->ida_deltaS[is], IDA_mem->ida_yyS0new[is]); + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + N_VLinearSum(ONE, IDA_mem->ida_yyS0[is], -lambda, IDA_mem->ida_deltaS[is], + IDA_mem->ida_yyS0new[is]); + } } /* end loop is */ - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1304,50 +1373,58 @@ static int IDASensNewyyp(IDAMem IDA_mem, realtype lambda) static int IDAICFailFlag(IDAMem IDA_mem, int retval) { - /* Depending on retval, print error message and return error flag. */ - switch(retval) { - - case IDA_RES_FAIL: - IDAProcessError(IDA_mem, IDA_RES_FAIL, "IDAS", "IDACalcIC", MSG_IC_RES_NONREC); - return(IDA_RES_FAIL); - - case IDA_FIRST_RES_FAIL: - IDAProcessError(IDA_mem, IDA_FIRST_RES_FAIL, "IDAS", "IDACalcIC", MSG_IC_RES_FAIL); - return(IDA_FIRST_RES_FAIL); - - case IDA_LSETUP_FAIL: - IDAProcessError(IDA_mem, IDA_LSETUP_FAIL, "IDAS", "IDACalcIC", MSG_IC_SETUP_FAIL); - return(IDA_LSETUP_FAIL); - - case IDA_LSOLVE_FAIL: - IDAProcessError(IDA_mem, IDA_LSOLVE_FAIL, "IDAS", "IDACalcIC", MSG_IC_SOLVE_FAIL); - return(IDA_LSOLVE_FAIL); - - case IC_FAIL_RECOV: - IDAProcessError(IDA_mem, IDA_NO_RECOVERY, "IDAS", "IDACalcIC", MSG_IC_NO_RECOVERY); - return(IDA_NO_RECOVERY); - - case IC_CONSTR_FAILED: - IDAProcessError(IDA_mem, IDA_CONSTR_FAIL, "IDAS", "IDACalcIC", MSG_IC_FAIL_CONSTR); - return(IDA_CONSTR_FAIL); - - case IC_LINESRCH_FAILED: - IDAProcessError(IDA_mem, IDA_LINESEARCH_FAIL, "IDAS", "IDACalcIC", MSG_IC_FAILED_LINS); - return(IDA_LINESEARCH_FAIL); - - case IC_CONV_FAIL: - IDAProcessError(IDA_mem, IDA_CONV_FAIL, "IDAS", "IDACalcIC", MSG_IC_CONV_FAILED); - return(IDA_CONV_FAIL); - - case IC_SLOW_CONVRG: - IDAProcessError(IDA_mem, IDA_CONV_FAIL, "IDAS", "IDACalcIC", MSG_IC_CONV_FAILED); - return(IDA_CONV_FAIL); - - case IDA_BAD_EWT: - IDAProcessError(IDA_mem, IDA_BAD_EWT, "IDAS", "IDACalcIC", MSG_IC_BAD_EWT); - return(IDA_BAD_EWT); - + switch (retval) + { + case IDA_RES_FAIL: + IDAProcessError(IDA_mem, IDA_RES_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_RES_NONREC); + return (IDA_RES_FAIL); + + case IDA_FIRST_RES_FAIL: + IDAProcessError(IDA_mem, IDA_FIRST_RES_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_RES_FAIL); + return (IDA_FIRST_RES_FAIL); + + case IDA_LSETUP_FAIL: + IDAProcessError(IDA_mem, IDA_LSETUP_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_SETUP_FAIL); + return (IDA_LSETUP_FAIL); + + case IDA_LSOLVE_FAIL: + IDAProcessError(IDA_mem, IDA_LSOLVE_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_SOLVE_FAIL); + return (IDA_LSOLVE_FAIL); + + case IC_FAIL_RECOV: + IDAProcessError(IDA_mem, IDA_NO_RECOVERY, __LINE__, __func__, __FILE__, + MSG_IC_NO_RECOVERY); + return (IDA_NO_RECOVERY); + + case IC_CONSTR_FAILED: + IDAProcessError(IDA_mem, IDA_CONSTR_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_FAIL_CONSTR); + return (IDA_CONSTR_FAIL); + + case IC_LINESRCH_FAILED: + IDAProcessError(IDA_mem, IDA_LINESEARCH_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_FAILED_LINS); + return (IDA_LINESEARCH_FAIL); + + case IC_CONV_FAIL: + IDAProcessError(IDA_mem, IDA_CONV_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_CONV_FAILED); + return (IDA_CONV_FAIL); + + case IC_SLOW_CONVRG: + IDAProcessError(IDA_mem, IDA_CONV_FAIL, __LINE__, __func__, __FILE__, + MSG_IC_CONV_FAILED); + return (IDA_CONV_FAIL); + + case IDA_BAD_EWT: + IDAProcessError(IDA_mem, IDA_BAD_EWT, __LINE__, __func__, __FILE__, + MSG_IC_BAD_EWT); + return (IDA_BAD_EWT); } return -99; } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_impl.h b/deps/AMICI/ThirdParty/sundials/src/idas/idas_impl.h index b4e39a96a..e54b593bc 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_impl.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,25 +20,58 @@ #include -#include "idas/idas.h" +#include +#include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#include "sundials_logger_impl.h" +#include "sundials_macros.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif +#if defined(SUNDIALS_EXTENDED_PRECISION) +#define RSYM ".32Lg" +#define RSYMW "41.32Lg" +#else +#define RSYM ".16g" +#define RSYMW "23.16g" +#endif + +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define IDA_PROFILER IDA_mem->ida_sunctx->profiler +#define IDA_LOGGER IDA_mem->ida_sunctx->logger + /* * ================================================================= * M A I N I N T E G R A T O R M E M O R Y B L O C K * ================================================================= */ - /* Basic IDA constants */ -#define HMAX_INV_DEFAULT RCONST(0.0) /* hmax_inv default value */ -#define MAXORD_DEFAULT 5 /* maxord default value */ -#define MXORDP1 6 /* max. number of N_Vectors in phi */ -#define MXSTEP_DEFAULT 500 /* mxstep default value */ +#define HMAX_INV_DEFAULT SUN_RCONST(0.0) /* hmax_inv default value */ +#define HMIN_DEFAULT SUN_RCONST(0.0) /* hmin default value */ +#define MAXORD_DEFAULT 5 /* maxord default value */ +#define MXORDP1 6 /* max. number of N_Vectors in phi */ +#define MXSTEP_DEFAULT 500 /* mxstep default value */ + +#define ETA_MAX_FX_DEFAULT \ + SUN_RCONST(2.0) /* threshold to increase step size */ +#define ETA_MIN_FX_DEFAULT \ + SUN_RCONST(1.0) /* threshold to decrease step size */ +#define ETA_MAX_DEFAULT SUN_RCONST(2.0) /* max step size increase factor */ +#define ETA_MIN_DEFAULT SUN_RCONST(0.5) /* min step size decrease factor */ +#define ETA_LOW_DEFAULT SUN_RCONST(0.9) /* upper bound on decrease factor */ +#define ETA_MIN_EF_DEFAULT \ + SUN_RCONST(0.25) /* err test fail min decrease factor */ +#define ETA_CF_DEFAULT SUN_RCONST(0.25) /* NLS failure decrease factor */ + +#define DCJ_DEFAULT \ + SUN_RCONST(0.25) /* constant for updating Jacobian/preconditioner */ /* Return values for lower level routines used by IDASolve and functions provided to the nonlinear solver */ @@ -49,16 +82,16 @@ extern "C" { #define IDA_CONSTR_RECVR +5 #define IDA_NLS_SETUP_RECVR +6 -#define IDA_QRHS_RECVR +10 -#define IDA_SRES_RECVR +11 -#define IDA_QSRHS_RECVR +12 +#define IDA_QRHS_RECVR +10 +#define IDA_SRES_RECVR +11 +#define IDA_QSRHS_RECVR +12 /* itol */ -#define IDA_NN 0 -#define IDA_SS 1 -#define IDA_SV 2 -#define IDA_WF 3 -#define IDA_EE 4 +#define IDA_NN 0 +#define IDA_SS 1 +#define IDA_SV 2 +#define IDA_WF 3 +#define IDA_EE 4 /* * ---------------------------------------------------------------- @@ -69,103 +102,105 @@ extern "C" { * ---------------------------------------------------------------- */ -typedef struct IDAMemRec { +typedef struct IDAMemRec +{ + SUNContext ida_sunctx; - realtype ida_uround; /* machine unit roundoff */ + sunrealtype ida_uround; /* machine unit roundoff */ /*-------------------------- Problem Specification Data --------------------------*/ - IDAResFn ida_res; /* F(t,y(t),y'(t))=0; the function F */ - void *ida_user_data; /* user pointer passed to res */ + IDAResFn ida_res; /* F(t,y(t),y'(t))=0; the function F */ + void* ida_user_data; /* user pointer passed to res */ - int ida_itol; /* itol = IDA_SS, IDA_SV, IDA_WF, IDA_NN */ - realtype ida_rtol; /* relative tolerance */ - realtype ida_Satol; /* scalar absolute tolerance */ - N_Vector ida_Vatol; /* vector absolute tolerance */ - booleantype ida_atolmin0; /* flag indicating that min(atol) = 0 */ - booleantype ida_user_efun; /* SUNTRUE if user provides efun */ - IDAEwtFn ida_efun; /* function to set ewt */ - void *ida_edata; /* user pointer passed to efun */ + int ida_itol; /* itol = IDA_SS, IDA_SV, IDA_WF, IDA_NN */ + sunrealtype ida_rtol; /* relative tolerance */ + sunrealtype ida_Satol; /* scalar absolute tolerance */ + N_Vector ida_Vatol; /* vector absolute tolerance */ + sunbooleantype ida_atolmin0; /* flag indicating that min(atol) = 0 */ + sunbooleantype ida_user_efun; /* SUNTRUE if user provides efun */ + IDAEwtFn ida_efun; /* function to set ewt */ + void* ida_edata; /* user pointer passed to efun */ - booleantype ida_constraintsSet; /* constraints vector present: + sunbooleantype ida_constraintsSet; /* constraints vector present: do constraints calc */ - booleantype ida_suppressalg; /* SUNTRUE means suppress algebraic vars + sunbooleantype ida_suppressalg; /* SUNTRUE means suppress algebraic vars in local error tests */ /*----------------------- Quadrature Related Data -----------------------*/ - booleantype ida_quadr; + sunbooleantype ida_quadr; - IDAQuadRhsFn ida_rhsQ; - void *ida_user_dataQ; + IDAQuadRhsFn ida_rhsQ; + void* ida_user_dataQ; - booleantype ida_errconQ; + sunbooleantype ida_errconQ; - int ida_itolQ; - realtype ida_rtolQ; - realtype ida_SatolQ; /* scalar absolute tolerance for quadratures */ - N_Vector ida_VatolQ; /* vector absolute tolerance for quadratures */ - booleantype ida_atolQmin0; /* flag indicating that min(atolQ) = 0 */ + int ida_itolQ; + sunrealtype ida_rtolQ; + sunrealtype ida_SatolQ; /* scalar absolute tolerance for quadratures */ + N_Vector ida_VatolQ; /* vector absolute tolerance for quadratures */ + sunbooleantype ida_atolQmin0; /* flag indicating that min(atolQ) = 0 */ /*------------------------ Sensitivity Related Data ------------------------*/ - booleantype ida_sensi; - int ida_Ns; - int ida_ism; + sunbooleantype ida_sensi; + int ida_Ns; + int ida_ism; - IDASensResFn ida_resS; - void *ida_user_dataS; - booleantype ida_resSDQ; + IDASensResFn ida_resS; + void* ida_user_dataS; + sunbooleantype ida_resSDQ; - realtype *ida_p; - realtype *ida_pbar; - int *ida_plist; - int ida_DQtype; - realtype ida_DQrhomax; + sunrealtype* ida_p; + sunrealtype* ida_pbar; + int* ida_plist; + int ida_DQtype; + sunrealtype ida_DQrhomax; - booleantype ida_errconS; /* SUNTRUE if sensitivities in err. control */ + sunbooleantype ida_errconS; /* SUNTRUE if sensitivities in err. control */ - int ida_itolS; - realtype ida_rtolS; /* relative tolerance for sensitivities */ - realtype *ida_SatolS; /* scalar absolute tolerances for sensi. */ - N_Vector *ida_VatolS; /* vector absolute tolerances for sensi. */ - booleantype *ida_atolSmin0; /* flag indicating that min(atolS[is]) = 0 */ + int ida_itolS; + sunrealtype ida_rtolS; /* relative tolerance for sensitivities */ + sunrealtype* ida_SatolS; /* scalar absolute tolerances for sensi. */ + N_Vector* ida_VatolS; /* vector absolute tolerances for sensi. */ + sunbooleantype* ida_atolSmin0; /* flag indicating that min(atolS[is]) = 0 */ /*----------------------------------- Quadrature Sensitivity Related Data -----------------------------------*/ - booleantype ida_quadr_sensi; /* SUNTRUE if computing sensitivities of quadrs. */ + sunbooleantype ida_quadr_sensi; /* SUNTRUE if computing sensitivities of quadrs. */ - IDAQuadSensRhsFn ida_rhsQS; /* fQS = (dfQ/dy)*yS + (dfQ/dp) */ - void *ida_user_dataQS; /* data pointer passed to fQS */ - booleantype ida_rhsQSDQ; /* SUNTRUE if using internal DQ functions */ + IDAQuadSensRhsFn ida_rhsQS; /* fQS = (dfQ/dy)*yS + (dfQ/dp) */ + void* ida_user_dataQS; /* data pointer passed to fQS */ + sunbooleantype ida_rhsQSDQ; /* SUNTRUE if using internal DQ functions */ - booleantype ida_errconQS; /* SUNTRUE if yQS are considered in err. con. */ + sunbooleantype ida_errconQS; /* SUNTRUE if yQS are considered in err. con. */ int ida_itolQS; - realtype ida_rtolQS; /* relative tolerance for yQS */ - realtype *ida_SatolQS; /* scalar absolute tolerances for yQS */ - N_Vector *ida_VatolQS; /* vector absolute tolerances for yQS */ - booleantype *ida_atolQSmin0; /* flag indicating that min(atolQS[is]) = 0 */ + sunrealtype ida_rtolQS; /* relative tolerance for yQS */ + sunrealtype* ida_SatolQS; /* scalar absolute tolerances for yQS */ + N_Vector* ida_VatolQS; /* vector absolute tolerances for yQS */ + sunbooleantype* ida_atolQSmin0; /* flag indicating that min(atolQS[is]) = 0 */ /*----------------------------------------------- Divided differences array and associated arrays -----------------------------------------------*/ - N_Vector ida_phi[MXORDP1]; /* phi = (maxord+1) arrays of divided differences */ + N_Vector ida_phi[MXORDP1]; /* phi = (maxord+1) arrays of divided differences */ - realtype ida_psi[MXORDP1]; /* differences in t (sums of recent step sizes) */ - realtype ida_alpha[MXORDP1]; /* ratios of current stepsize to psi values */ - realtype ida_beta[MXORDP1]; /* ratios of current to previous product of psi's */ - realtype ida_sigma[MXORDP1]; /* product successive alpha values and factorial */ - realtype ida_gamma[MXORDP1]; /* sum of reciprocals of psi values */ + sunrealtype ida_psi[MXORDP1]; /* differences in t (sums of recent step sizes) */ + sunrealtype ida_alpha[MXORDP1]; /* ratios of current stepsize to psi values */ + sunrealtype ida_beta[MXORDP1]; /* ratios of current to previous product of psi's */ + sunrealtype ida_sigma[MXORDP1]; /* product successive alpha values and factorial */ + sunrealtype ida_gamma[MXORDP1]; /* sum of reciprocals of psi values */ /*------------------------- N_Vectors for integration @@ -191,7 +226,6 @@ typedef struct IDAMemRec { N_Vector ida_delnew; /* work vector for delta in IDACalcIC (= phi[2]) */ N_Vector ida_dtemp; /* work vector in IDACalcIC (= phi[3]) */ - /*---------------------------- Quadrature Related N_Vectors ----------------------------*/ @@ -206,195 +240,198 @@ typedef struct IDAMemRec { Sensitivity Related Vectors ---------------------------*/ - N_Vector *ida_phiS[MXORDP1]; - N_Vector *ida_ewtS; + N_Vector* ida_phiS[MXORDP1]; + N_Vector* ida_ewtS; - N_Vector *ida_eeS; /* cumulative sensitivity corrections */ + N_Vector* ida_eeS; /* cumulative sensitivity corrections */ - N_Vector *ida_yyS; /* allocated and used for: */ - N_Vector *ida_ypS; /* ism = SIMULTANEOUS */ - N_Vector *ida_yySpredict; /* ism = STAGGERED */ - N_Vector *ida_ypSpredict; - N_Vector *ida_deltaS; + N_Vector* ida_yyS; /* allocated and used for: */ + N_Vector* ida_ypS; /* ism = SIMULTANEOUS */ + N_Vector* ida_yySpredict; /* ism = STAGGERED */ + N_Vector* ida_ypSpredict; + N_Vector* ida_deltaS; - N_Vector ida_tmpS1; /* work space vectors | tmpS1 = tempv1 */ - N_Vector ida_tmpS2; /* for resS | tmpS2 = tempv2 */ - N_Vector ida_tmpS3; /* | tmpS3 = allocated */ + N_Vector ida_tmpS1; /* work space vectors | tmpS1 = tempv1 */ + N_Vector ida_tmpS2; /* for resS | tmpS2 = tempv2 */ + N_Vector ida_tmpS3; /* | tmpS3 = allocated */ - N_Vector *ida_savresS; /* work vector in IDACalcIC for stg (= phiS[2]) */ - N_Vector *ida_delnewS; /* work vector in IDACalcIC for stg (= phiS[3]) */ + N_Vector* ida_savresS; /* work vector in IDACalcIC for stg (= phiS[2]) */ + N_Vector* ida_delnewS; /* work vector in IDACalcIC for stg (= phiS[3]) */ - N_Vector *ida_yyS0; /* initial yS, ypS vectors allocated and */ - N_Vector *ida_ypS0; /* deallocated in IDACalcIC function */ + N_Vector* ida_yyS0; /* initial yS, ypS vectors allocated and */ + N_Vector* ida_ypS0; /* deallocated in IDACalcIC function */ - N_Vector *ida_yyS0new; /* work vector in IDASensLineSrch (= phiS[4]) */ - N_Vector *ida_ypS0new; /* work vector in IDASensLineSrch (= eeS) */ + N_Vector* ida_yyS0new; /* work vector in IDASensLineSrch (= phiS[4]) */ + N_Vector* ida_ypS0new; /* work vector in IDASensLineSrch (= eeS) */ /*-------------------------------------- Quadrature Sensitivity Related Vectors --------------------------------------*/ - N_Vector *ida_phiQS[MXORDP1];/* Mod. div. diffs. for quadr. sensitivities */ - N_Vector *ida_ewtQS; /* error weight vectors for sensitivities */ + N_Vector* ida_phiQS[MXORDP1]; /* Mod. div. diffs. for quadr. sensitivities */ + N_Vector* ida_ewtQS; /* error weight vectors for sensitivities */ - N_Vector *ida_eeQS; /* cumulative quadr.sensi.corrections */ + N_Vector* ida_eeQS; /* cumulative quadr.sensi.corrections */ - N_Vector *ida_yyQS; /* Unlike yS, yQS is not allocated by the user */ - N_Vector *ida_tempvQS; /* temporary storage vector (~ tempv) */ - N_Vector ida_savrhsQ; /* saved quadr. rhs (needed for rhsQS calls) */ + N_Vector* ida_yyQS; /* Unlike yS, yQS is not allocated by the user */ + N_Vector* ida_tempvQS; /* temporary storage vector (~ tempv) */ + N_Vector ida_savrhsQ; /* saved quadr. rhs (needed for rhsQS calls) */ /*------------------------------ Variables for use by IDACalcIC ------------------------------*/ - realtype ida_t0; /* initial t */ - N_Vector ida_yy0; /* initial y vector (user-supplied). */ - N_Vector ida_yp0; /* initial y' vector (user-supplied). */ + sunrealtype ida_t0; /* initial t */ + N_Vector ida_yy0; /* initial y vector (user-supplied). */ + N_Vector ida_yp0; /* initial y' vector (user-supplied). */ int ida_icopt; /* IC calculation user option */ - booleantype ida_lsoff; /* IC calculation linesearch turnoff option */ + sunbooleantype ida_lsoff; /* IC calculation linesearch turnoff option */ int ida_maxnh; /* max. number of h tries in IC calculation */ int ida_maxnj; /* max. number of J tries in IC calculation */ int ida_maxnit; /* max. number of Netwon iterations in IC calc. */ int ida_nbacktr; /* number of IC linesearch backtrack operations */ int ida_sysindex; /* computed system index (0 or 1) */ int ida_maxbacks; /* max backtracks per Newton step */ - realtype ida_epiccon; /* IC nonlinear convergence test constant */ - realtype ida_steptol; /* minimum Newton step size in IC calculation */ - realtype ida_tscale; /* time scale factor = abs(tout1 - t0) */ + sunrealtype ida_epiccon; /* IC nonlinear convergence test constant */ + sunrealtype ida_steptol; /* minimum Newton step size in IC calculation */ + sunrealtype ida_tscale; /* time scale factor = abs(tout1 - t0) */ /* Tstop information */ - booleantype ida_tstopset; - realtype ida_tstop; + sunbooleantype ida_tstopset; + sunrealtype ida_tstop; /* Step Data */ - int ida_kk; /* current BDF method order */ - int ida_kused; /* method order used on last successful step */ - int ida_knew; /* order for next step from order decrease decision */ - int ida_phase; /* flag to trigger step doubling in first few steps */ - int ida_ns; /* counts steps at fixed stepsize and order */ - - realtype ida_hin; /* initial step */ - realtype ida_h0u; /* actual initial stepsize */ - realtype ida_hh; /* current step size h */ - realtype ida_hused; /* step size used on last successful step */ - realtype ida_rr; /* rr = hnext / hused */ - realtype ida_tn; /* current internal value of t */ - realtype ida_tretlast; /* value of tret previously returned by IDASolve */ - realtype ida_cj; /* current value of scalar (-alphas/hh) in Jacobian */ - realtype ida_cjlast; /* cj value saved from last successful step */ - realtype ida_cjold; /* cj value saved from last call to lsetup */ - realtype ida_cjratio; /* ratio of cj values: cj/cjold */ - realtype ida_ss; /* scalar used in Newton iteration convergence test */ - realtype ida_oldnrm; /* norm of previous nonlinear solver update */ - realtype ida_epsNewt; /* test constant in Newton convergence test */ - realtype ida_epcon; /* coeficient of the Newton covergence test */ - realtype ida_toldel; /* tolerance in direct test on Newton corrections */ - - realtype ida_ssS; /* scalar ss for staggered sensitivities */ + int ida_kk; /* current BDF method order */ + int ida_kused; /* method order used on last successful step */ + int ida_knew; /* order for next step from order decrease decision */ + int ida_phase; /* flag to trigger step doubling in first few steps */ + int ida_ns; /* counts steps at fixed stepsize and order */ + + sunrealtype ida_hin; /* initial step */ + sunrealtype ida_h0u; /* actual initial stepsize */ + sunrealtype ida_hh; /* current step size h */ + sunrealtype ida_hused; /* step size used on last successful step */ + sunrealtype ida_eta; /* eta = hnext / hused */ + sunrealtype ida_tn; /* current internal value of t */ + sunrealtype ida_tretlast; /* value of tret previously returned by IDASolve */ + sunrealtype ida_cj; /* current value of scalar (-alphas/hh) in Jacobian */ + sunrealtype ida_cjlast; /* cj value saved from last successful step */ + sunrealtype ida_cjold; /* cj value saved from last call to lsetup */ + sunrealtype ida_cjratio; /* ratio of cj values: cj/cjold */ + sunrealtype ida_ss; /* scalar used in Newton iteration convergence test */ + sunrealtype ida_oldnrm; /* norm of previous nonlinear solver update */ + sunrealtype ida_epsNewt; /* test constant in Newton convergence test */ + sunrealtype ida_epcon; /* coeficient of the Newton covergence test */ + sunrealtype ida_toldel; /* tolerance in direct test on Newton corrections */ + + sunrealtype ida_ssS; /* scalar ss for staggered sensitivities */ /*------ Limits ------*/ - int ida_maxncf; /* max numer of convergence failures */ - int ida_maxnef; /* max number of error test failures */ + int ida_maxncf; /* max numer of convergence failures */ + int ida_maxnef; /* max number of error test failures */ - int ida_maxord; /* max value of method order k: */ - int ida_maxord_alloc; /* value of maxord used when allocating memory */ - long int ida_mxstep; /* max number of internal steps for one user call */ - realtype ida_hmax_inv; /* inverse of max. step size hmax (default = 0.0) */ + int ida_maxord; /* max value of method order k: */ + int ida_maxord_alloc; /* value of maxord used when allocating memory */ + long int ida_mxstep; /* max number of internal steps for one user call */ + sunrealtype ida_hmax_inv; /* inverse of max. step size hmax (default = 0.0) */ + sunrealtype ida_hmin; /* min step size hmin (default = 0.0) */ + + sunrealtype ida_eta_max_fx; /* threshold to increase step size */ + sunrealtype ida_eta_min_fx; /* threshold to decrease step size */ + sunrealtype ida_eta_max; /* max step size increase factor */ + sunrealtype ida_eta_min; /* min step size decrease factor */ + sunrealtype ida_eta_low; /* upper bound on decrease factor */ + sunrealtype ida_eta_min_ef; /* eta >= eta_min_ef after an error test failure */ + sunrealtype ida_eta_cf; /* eta on a nonlinear solver convergence failure */ /*-------- Counters --------*/ - long int ida_nst; /* number of internal steps taken */ + long int ida_nst; /* number of internal steps taken */ - long int ida_nre; /* number of function (res) calls */ + long int ida_nre; /* number of function (res) calls */ long int ida_nrQe; long int ida_nrSe; - long int ida_nrQSe; /* number of fQS calls */ + long int ida_nrQSe; /* number of fQS calls */ long int ida_nreS; - long int ida_nrQeS; /* number of fQ calls from sensi DQ */ - + long int ida_nrQeS; /* number of fQ calls from sensi DQ */ - long int ida_ncfn; /* number of corrector convergence failures */ + long int ida_ncfn; /* number of corrector convergence failures */ long int ida_ncfnQ; long int ida_ncfnS; - long int ida_netf; /* number of error test failures */ + long int ida_netf; /* number of error test failures */ long int ida_netfQ; long int ida_netfS; - long int ida_netfQS; /* number of quadr. sensi. error test failures */ + long int ida_netfQS; /* number of quadr. sensi. error test failures */ - long int ida_nni; /* number of Newton iterations performed */ + long int ida_nni; /* number of Newton iterations performed */ long int ida_nniS; - long int ida_nsetups; /* number of lsetup calls */ + long int ida_nnf; /* number of Newton convergence failures */ + long int ida_nnfS; + + long int ida_nsetups; /* number of lsetup calls */ long int ida_nsetupsS; /*------------------ Space requirements ------------------*/ - sunindextype ida_lrw1; /* no. of realtype words in 1 N_Vector */ + sunindextype ida_lrw1; /* no. of sunrealtype words in 1 N_Vector */ sunindextype ida_liw1; /* no. of integer words in 1 N_Vector */ sunindextype ida_lrw1Q; sunindextype ida_liw1Q; - long int ida_lrw; /* number of realtype words in IDA work vectors */ - long int ida_liw; /* no. of integer words in IDA work vectors */ - - realtype ida_tolsf; /* tolerance scale factor (saved value) */ - - /*------------------------------------------- - Error handler function and error ouput file - -------------------------------------------*/ + long int ida_lrw; /* number of sunrealtype words in IDA work vectors */ + long int ida_liw; /* no. of integer words in IDA work vectors */ - IDAErrHandlerFn ida_ehfun; /* Error messages are handled by ehfun */ - void *ida_eh_data; /* dats pointer passed to ehfun */ - FILE *ida_errfp; /* IDA error messages are sent to errfp */ + sunrealtype ida_tolsf; /* tolerance scale factor (saved value) */ /* Flags to verify correct calling sequence */ - booleantype ida_SetupDone; /* set to SUNFALSE by IDAMalloc and IDAReInit + sunbooleantype ida_SetupDone; /* set to SUNFALSE by IDAMalloc and IDAReInit set to SUNTRUE by IDACalcIC or IDASolve */ - booleantype ida_VatolMallocDone; - booleantype ida_constraintsMallocDone; - booleantype ida_idMallocDone; + sunbooleantype ida_VatolMallocDone; + sunbooleantype ida_constraintsMallocDone; + sunbooleantype ida_idMallocDone; - booleantype ida_MallocDone; /* set to SUNFALSE by IDACreate + sunbooleantype ida_MallocDone; /* set to SUNFALSE by IDACreate set to SUNTRUE by IDAMAlloc tested by IDAReInit and IDASolve */ - booleantype ida_VatolQMallocDone; - booleantype ida_quadMallocDone; + sunbooleantype ida_VatolQMallocDone; + sunbooleantype ida_quadMallocDone; - booleantype ida_VatolSMallocDone; - booleantype ida_SatolSMallocDone; - booleantype ida_sensMallocDone; + sunbooleantype ida_VatolSMallocDone; + sunbooleantype ida_SatolSMallocDone; + sunbooleantype ida_sensMallocDone; - booleantype ida_VatolQSMallocDone; - booleantype ida_SatolQSMallocDone; - booleantype ida_quadSensMallocDone; + sunbooleantype ida_VatolQSMallocDone; + sunbooleantype ida_SatolQSMallocDone; + sunbooleantype ida_quadSensMallocDone; /*--------------------- Nonlinear Solver Data ---------------------*/ - SUNNonlinearSolver NLS; /* nonlinear solver object */ - booleantype ownNLS; /* flag indicating NLS ownership */ + SUNNonlinearSolver NLS; /* nonlinear solver object */ + sunbooleantype ownNLS; /* flag indicating NLS ownership */ SUNNonlinearSolver NLSsim; /* nonlinear solver object for DAE+Sens solves with the simultaneous corrector option */ - booleantype ownNLSsim; /* flag indicating NLS ownership */ + sunbooleantype ownNLSsim; /* flag indicating NLS ownership */ SUNNonlinearSolver NLSstg; /* nonlinear solver object for DAE+Sens solves with the staggered corrector option */ - booleantype ownNLSstg; /* flag indicating NLS ownership */ + sunbooleantype ownNLSstg; /* flag indicating NLS ownership */ /* The following vectors are NVector wrappers for use with the simultaneous and staggered corrector methods: @@ -412,10 +449,10 @@ typedef struct IDAMemRec { /* flags indicating if vector wrappers for the simultaneous and staggered correctors have been allocated */ - booleantype simMallocDone; - booleantype stgMallocDone; + sunbooleantype simMallocDone; + sunbooleantype stgMallocDone; - IDAResFn nls_res; /* F(t,y(t),y'(t))=0; used in the nonlinear + IDAResFn nls_res; /* F(t,y(t),y'(t))=0; used in the nonlinear solver */ /*------------------ @@ -424,58 +461,60 @@ typedef struct IDAMemRec { /* Linear Solver functions to be called */ - int (*ida_linit)(struct IDAMemRec *idamem); + int (*ida_linit)(struct IDAMemRec* idamem); - int (*ida_lsetup)(struct IDAMemRec *idamem, N_Vector yyp, - N_Vector ypp, N_Vector resp, - N_Vector tempv1, N_Vector tempv2, N_Vector tempv3); + int (*ida_lsetup)(struct IDAMemRec* idamem, N_Vector yyp, N_Vector ypp, + N_Vector resp, N_Vector tempv1, N_Vector tempv2, + N_Vector tempv3); - int (*ida_lsolve)(struct IDAMemRec *idamem, N_Vector b, N_Vector weight, + int (*ida_lsolve)(struct IDAMemRec* idamem, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector ypcur, N_Vector rescur); - int (*ida_lperf)(struct IDAMemRec *idamem, int perftask); + int (*ida_lperf)(struct IDAMemRec* idamem, int perftask); - int (*ida_lfree)(struct IDAMemRec *idamem); + int (*ida_lfree)(struct IDAMemRec* idamem); /* Linear Solver specific memory */ - void *ida_lmem; + void* ida_lmem; /* linear solver interface structure */ + sunrealtype ida_dcj; /* parameter that determines cj ratio thresholds for calling + * the linear solver setup function */ /* Flag to request a call to the setup routine */ - booleantype ida_forceSetup; + sunbooleantype ida_forceSetup; /* Flag to indicate successful ida_linit call */ - booleantype ida_linitOK; + sunbooleantype ida_linitOK; /*---------------- Rootfinding Data ----------------*/ - IDARootFn ida_gfun; /* Function g for roots sought */ - int ida_nrtfn; /* number of components of g */ - int *ida_iroots; /* array for root information */ - int *ida_rootdir; /* array specifying direction of zero-crossing */ - realtype ida_tlo; /* nearest endpoint of interval in root search */ - realtype ida_thi; /* farthest endpoint of interval in root search */ - realtype ida_trout; /* t return value from rootfinder routine */ - realtype *ida_glo; /* saved array of g values at t = tlo */ - realtype *ida_ghi; /* saved array of g values at t = thi */ - realtype *ida_grout; /* array of g values at t = trout */ - realtype ida_toutc; /* copy of tout (if NORMAL mode) */ - realtype ida_ttol; /* tolerance on root location */ - int ida_taskc; /* copy of parameter itask */ - int ida_irfnd; /* flag showing whether last step had a root */ - long int ida_nge; /* counter for g evaluations */ - booleantype *ida_gactive; /* array with active/inactive event functions */ - int ida_mxgnull; /* number of warning messages about possible g==0 */ + IDARootFn ida_gfun; /* Function g for roots sought */ + int ida_nrtfn; /* number of components of g */ + int* ida_iroots; /* array for root information */ + int* ida_rootdir; /* array specifying direction of zero-crossing */ + sunrealtype ida_tlo; /* nearest endpoint of interval in root search */ + sunrealtype ida_thi; /* farthest endpoint of interval in root search */ + sunrealtype ida_trout; /* t return value from rootfinder routine */ + sunrealtype* ida_glo; /* saved array of g values at t = tlo */ + sunrealtype* ida_ghi; /* saved array of g values at t = thi */ + sunrealtype* ida_grout; /* array of g values at t = trout */ + sunrealtype ida_toutc; /* copy of tout (if NORMAL mode) */ + sunrealtype ida_ttol; /* tolerance on root location */ + int ida_taskc; /* copy of parameter itask */ + int ida_irfnd; /* flag showing whether last step had a root */ + long int ida_nge; /* counter for g evaluations */ + sunbooleantype* ida_gactive; /* array with active/inactive event functions */ + int ida_mxgnull; /* number of warning messages about possible g==0 */ /* Arrays for Fused Vector Operations */ /* scalar arrays */ - realtype* ida_cvals; - realtype ida_dvals[MAXORD_DEFAULT]; + sunrealtype* ida_cvals; + sunrealtype ida_dvals[MAXORD_DEFAULT]; /* vector arrays */ N_Vector* ida_Xvecs; @@ -485,13 +524,13 @@ typedef struct IDAMemRec { Adjoint sensitivity data ------------------------*/ - booleantype ida_adj; /* SUNTRUE if performing ASA */ + sunbooleantype ida_adj; /* SUNTRUE if performing ASA */ - struct IDAadjMemRec *ida_adj_mem; /* Pointer to adjoint memory structure */ + struct IDAadjMemRec* ida_adj_mem; /* Pointer to adjoint memory structure */ - booleantype ida_adjMallocDone; + sunbooleantype ida_adjMallocDone; -} *IDAMem; +}* IDAMem; /* * ================================================================= @@ -505,10 +544,10 @@ typedef struct IDAMemRec { * ----------------------------------------------------------------- */ -typedef struct IDAadjMemRec *IDAadjMem; -typedef struct CkpntMemRec *CkpntMem; -typedef struct DtpntMemRec *DtpntMem; -typedef struct IDABMemRec *IDABMem; +typedef struct IDAadjMemRec* IDAadjMem; +typedef struct IDAckpntMemRec* IDAckpntMem; +typedef struct IDAdtpntMemRec* IDAdtpntMem; +typedef struct IDABMemRec* IDABMem; /* * ----------------------------------------------------------------- @@ -525,89 +564,87 @@ typedef struct IDABMemRec *IDABMem; * ----------------------------------------------------------------- */ -typedef booleantype (*IDAAMMallocFn)(IDAMem IDA_mem); +typedef sunbooleantype (*IDAAMMallocFn)(IDAMem IDA_mem); typedef void (*IDAAMFreeFn)(IDAMem IDA_mem); -typedef int (*IDAAGetYFn)(IDAMem IDA_mem, realtype t, - N_Vector yy, N_Vector yp, - N_Vector *yyS, N_Vector *ypS); -typedef int (*IDAAStorePntFn)(IDAMem IDA_mem, DtpntMem d); +typedef int (*IDAAGetYFn)(IDAMem IDA_mem, sunrealtype t, N_Vector yy, + N_Vector yp, N_Vector* yyS, N_Vector* ypS); +typedef int (*IDAAStorePntFn)(IDAMem IDA_mem, IDAdtpntMem d); /* * ----------------------------------------------------------------- - * Types : struct CkpntMemRec, CkpntMem + * Types : struct IDAckpntMemRec, IDAckpntMem * ----------------------------------------------------------------- - * The type CkpntMem is type pointer to struct CkpntMemRec. + * The type IDAckpntMem is type pointer to struct IDAckpntMemRec. * This structure contains fields to store all information at a * check point that is needed to 'hot' start IDAS. * ----------------------------------------------------------------- */ -struct CkpntMemRec { - +struct IDAckpntMemRec +{ /* Integration limits */ - realtype ck_t0; - realtype ck_t1; + sunrealtype ck_t0; + sunrealtype ck_t1; /* Modified divided difference array */ N_Vector ck_phi[MXORDP1]; /* Do we need to carry quadratures? */ - booleantype ck_quadr; + sunbooleantype ck_quadr; /* Modified divided difference array for quadratures */ N_Vector ck_phiQ[MXORDP1]; /* Do we need to carry sensitivities? */ - booleantype ck_sensi; + sunbooleantype ck_sensi; /* number of sensitivities */ int ck_Ns; /* Modified divided difference array for sensitivities */ - N_Vector *ck_phiS[MXORDP1]; + N_Vector* ck_phiS[MXORDP1]; /* Do we need to carry quadrature sensitivities? */ - booleantype ck_quadr_sensi; + sunbooleantype ck_quadr_sensi; /* Modified divided difference array for quadrature sensitivities */ - N_Vector *ck_phiQS[MXORDP1]; - + N_Vector* ck_phiQS[MXORDP1]; /* Step data */ - long int ck_nst; - realtype ck_tretlast; - int ck_ns; - int ck_kk; - int ck_kused; - int ck_knew; - int ck_phase; - - realtype ck_hh; - realtype ck_hused; - realtype ck_rr; - realtype ck_cj; - realtype ck_cjlast; - realtype ck_cjold; - realtype ck_cjratio; - realtype ck_ss; - realtype ck_ssS; - - realtype ck_psi[MXORDP1]; - realtype ck_alpha[MXORDP1]; - realtype ck_beta[MXORDP1]; - realtype ck_sigma[MXORDP1]; - realtype ck_gamma[MXORDP1]; + long int ck_nst; + sunrealtype ck_tretlast; + int ck_ns; + int ck_kk; + int ck_kused; + int ck_knew; + int ck_phase; + + sunrealtype ck_hh; + sunrealtype ck_hused; + sunrealtype ck_eta; + sunrealtype ck_cj; + sunrealtype ck_cjlast; + sunrealtype ck_cjold; + sunrealtype ck_cjratio; + sunrealtype ck_ss; + sunrealtype ck_ssS; + + sunrealtype ck_psi[MXORDP1]; + sunrealtype ck_alpha[MXORDP1]; + sunrealtype ck_beta[MXORDP1]; + sunrealtype ck_sigma[MXORDP1]; + sunrealtype ck_gamma[MXORDP1]; /* How many phi, phiS, phiQ and phiQS were allocated? */ - int ck_phi_alloc; + int ck_phi_alloc; /* Pointer to next structure in list */ - struct CkpntMemRec *ck_next; + struct IDAckpntMemRec* ck_next; }; /* * ----------------------------------------------------------------- - * Type : struct DtpntMemRec + * Type : struct IDAdtpntMemRec * ----------------------------------------------------------------- * This structure contains fields to store all information at a * data point that is needed to interpolate solution of forward @@ -615,30 +652,33 @@ struct CkpntMemRec { * ----------------------------------------------------------------- */ -struct DtpntMemRec { - realtype t; /* time */ - void *content; /* interpType-dependent content */ +struct IDAdtpntMemRec +{ + sunrealtype t; /* time */ + void* content; /* interpType-dependent content */ }; /* Data for cubic Hermite interpolation */ -typedef struct HermiteDataMemRec { +typedef struct IDAhermiteDataMemRec +{ N_Vector y; N_Vector yd; - N_Vector *yS; - N_Vector *ySd; -} *HermiteDataMem; + N_Vector* yS; + N_Vector* ySd; +}* IDAhermiteDataMem; /* Data for polynomial interpolation */ -typedef struct PolynomialDataMemRec { +typedef struct IDApolynomialDataMemRec +{ N_Vector y; - N_Vector *yS; + N_Vector* yS; /* yd and ySd store the derivative(s) only for the first dt point. NULL otherwise. */ N_Vector yd; - N_Vector *ySd; + N_Vector* ySd; int order; -} *PolynomialDataMem; +}* IDApolynomialDataMem; /* * ----------------------------------------------------------------- @@ -649,59 +689,58 @@ typedef struct PolynomialDataMemRec { * The IDAadjMem struct contains a linked list of IDABMem pointers * ----------------------------------------------------------------- */ -struct IDABMemRec { - +struct IDABMemRec +{ /* Index of this backward problem */ int ida_index; /* Time at which the backward problem is initialized. */ - realtype ida_t0; + sunrealtype ida_t0; /* Memory for this backward problem */ IDAMem IDA_mem; /* Flags to indicate that this backward problem's RHS or quad RHS * require forward sensitivities */ - booleantype ida_res_withSensi; - booleantype ida_rhsQ_withSensi; + sunbooleantype ida_res_withSensi; + sunbooleantype ida_rhsQ_withSensi; /* Residual function for backward run */ - IDAResFnB ida_res; - IDAResFnBS ida_resS; + IDAResFnB ida_res; + IDAResFnBS ida_resS; /* Right hand side quadrature function (fQB) for backward run */ - IDAQuadRhsFnB ida_rhsQ; - IDAQuadRhsFnBS ida_rhsQS; + IDAQuadRhsFnB ida_rhsQ; + IDAQuadRhsFnBS ida_rhsQS; /* User user_data */ - void *ida_user_data; + void* ida_user_data; /* Linear solver's data and functions */ /* Memory block for a linear solver's interface to IDAA */ - void *ida_lmem; + void* ida_lmem; /* Function to free any memory allocated by the linear solver */ int (*ida_lfree)(IDABMem IDAB_mem); /* Memory block for a preconditioner's module interface to IDAA */ - void *ida_pmem; + void* ida_pmem; /* Function to free any memory allocated by the preconditioner module */ int (*ida_pfree)(IDABMem IDAB_mem); /* Time at which to extract solution / quadratures */ - realtype ida_tout; + sunrealtype ida_tout; /* Workspace Nvectors */ N_Vector ida_yy; N_Vector ida_yp; /* Link to next structure in list. */ - struct IDABMemRec *ida_next; + struct IDABMemRec* ida_next; }; - /* * ----------------------------------------------------------------- * Type : struct IDAadjMemRec @@ -712,52 +751,52 @@ struct IDABMemRec { * ----------------------------------------------------------------- */ -struct IDAadjMemRec { - +struct IDAadjMemRec +{ /* -------------------- * Forward problem data * -------------------- */ /* Integration interval */ - realtype ia_tinitial, ia_tfinal; + sunrealtype ia_tinitial, ia_tfinal; /* Flag for first call to IDASolveF */ - booleantype ia_firstIDAFcall; + sunbooleantype ia_firstIDAFcall; /* Flag if IDASolveF was called with TSTOP */ - booleantype ia_tstopIDAFcall; - realtype ia_tstopIDAF; + sunbooleantype ia_tstopIDAFcall; + sunrealtype ia_tstopIDAF; /* Flag if IDASolveF was called in IDA_NORMAL_MODE and encountered a root after tout */ - booleantype ia_rootret; - realtype ia_troot; + sunbooleantype ia_rootret; + sunrealtype ia_troot; /* ---------------------- * Backward problems data * ---------------------- */ /* Storage for backward problems */ - struct IDABMemRec *IDAB_mem; + struct IDABMemRec* IDAB_mem; /* Number of backward problems. */ int ia_nbckpbs; /* Address of current backward problem (iterator). */ - struct IDABMemRec *ia_bckpbCrt; + struct IDABMemRec* ia_bckpbCrt; /* Flag for first call to IDASolveB */ - booleantype ia_firstIDABcall; + sunbooleantype ia_firstIDABcall; /* ---------------- * Check point data * ---------------- */ /* Storage for check point information */ - struct CkpntMemRec *ck_mem; + struct IDAckpntMemRec* ck_mem; /* address of the check point structure for which data is available */ - struct CkpntMemRec *ia_ckpntData; + struct IDAckpntMemRec* ia_ckpntData; /* Number of checkpoints. */ int ia_nckpnts; @@ -773,7 +812,7 @@ struct IDAadjMemRec { long int ia_ilast; /* Storage for data from forward runs */ - struct DtpntMemRec **dt_mem; + struct IDAdtpntMemRec** dt_mem; /* Actual number of data points saved in current dt_mem */ /* Commonly, np = nsteps+1 */ @@ -782,34 +821,31 @@ struct IDAadjMemRec { /* Interpolation type */ int ia_interpType; - /* Functions set by the interpolation module */ IDAAStorePntFn ia_storePnt; /* store a new interpolation point */ - IDAAGetYFn ia_getY; /* interpolate forward solution */ - IDAAMMallocFn ia_malloc; /* allocate new data point */ - IDAAMFreeFn ia_free; /* destroys data point */ + IDAAGetYFn ia_getY; /* interpolate forward solution */ + IDAAMMallocFn ia_malloc; /* allocate new data point */ + IDAAMFreeFn ia_free; /* destroys data point */ /* Flags controlling the interpolation module */ - booleantype ia_mallocDone; /* IM initialized? */ - booleantype ia_newData; /* new data available in dt_mem? */ - booleantype ia_storeSensi; /* store sensitivities? */ - booleantype ia_interpSensi; /* interpolate sensitivities? */ + sunbooleantype ia_mallocDone; /* IM initialized? */ + sunbooleantype ia_newData; /* new data available in dt_mem? */ + sunbooleantype ia_storeSensi; /* store sensitivities? */ + sunbooleantype ia_interpSensi; /* interpolate sensitivities? */ - booleantype ia_noInterp; /* interpolations are temporarly */ - /* disabled ( IDACalcICB ) */ + sunbooleantype ia_noInterp; /* interpolations are temporarly */ + /* disabled ( IDACalcICB ) */ /* Workspace for polynomial interpolation */ - N_Vector ia_Y[MXORDP1]; /* pointers phi[i] */ - N_Vector *ia_YS[MXORDP1]; /* pointers phiS[i] */ - realtype ia_T[MXORDP1]; + N_Vector ia_Y[MXORDP1]; /* pointers phi[i] */ + N_Vector* ia_YS[MXORDP1]; /* pointers phiS[i] */ + sunrealtype ia_T[MXORDP1]; /* Workspace for wrapper functions */ N_Vector ia_yyTmp, ia_ypTmp; N_Vector *ia_yySTmp, *ia_ypSTmp; - }; - /* * ================================================================= * I N T E R F A C E T O L I N E A R S O L V E R S @@ -909,30 +945,29 @@ struct IDAadjMemRec { /* Prototype of internal ewtSet function */ -int IDAEwtSet(N_Vector ycur, N_Vector weight, void *data); +int IDAEwtSet(N_Vector ycur, N_Vector weight, void* data); /* High level error handler */ -void IDAProcessError(IDAMem IDA_mem, - int error_code, const char *module, const char *fname, - const char *msgfmt, ...); +void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...); /* Prototype of internal errHandler function */ -void IDAErrHandler(int error_code, const char *module, const char *function, - char *msg, void *data); +void IDAErrHandler(int error_code, const char* module, const char* function, + char* msg, void* data); /* Norm functions. Also used for IC, so they are global.*/ -realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, - booleantype mask); +sunrealtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, + sunbooleantype mask); -realtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector *xS, N_Vector *wS, - booleantype mask); +sunrealtype IDASensWrmsNorm(IDAMem IDA_mem, N_Vector* xS, N_Vector* wS, + sunbooleantype mask); -realtype IDASensWrmsNormUpdate(IDAMem IDA_mem, realtype old_nrm, - N_Vector *xS, N_Vector *wS, - booleantype mask); +sunrealtype IDASensWrmsNormUpdate(IDAMem IDA_mem, sunrealtype old_nrm, + N_Vector* xS, N_Vector* wS, + sunbooleantype mask); /* Nonlinear solver initialization */ @@ -942,11 +977,10 @@ int idaNlsInitSensStg(IDAMem IDA_mem); /* Prototype for internal sensitivity residual DQ function */ -int IDASensResDQ(int Ns, realtype t, - N_Vector yy, N_Vector yp, N_Vector resval, - N_Vector *yyS, N_Vector *ypS, N_Vector *resvalS, - void *user_dataS, - N_Vector ytemp, N_Vector yptemp, N_Vector restemp); +int IDASensResDQ(int Ns, sunrealtype t, N_Vector yy, N_Vector yp, + N_Vector resval, N_Vector* yyS, N_Vector* ypS, + N_Vector* resvalS, void* user_dataS, N_Vector ytemp, + N_Vector yptemp, N_Vector restemp); /* * ================================================================= @@ -956,42 +990,44 @@ int IDASensResDQ(int Ns, realtype t, #if defined(SUNDIALS_EXTENDED_PRECISION) -#define MSG_TIME "t = %Lg, " -#define MSG_TIME_H "t = %Lg and h = %Lg, " -#define MSG_TIME_INT "t = %Lg is not between tcur - hu = %Lg and tcur = %Lg." -#define MSG_TIME_TOUT "tout = %Lg" +#define MSG_TIME "t = %Lg, " +#define MSG_TIME_H "t = %Lg and h = %Lg, " +#define MSG_TIME_INT "t = %Lg is not between tcur - hu = %Lg and tcur = %Lg." +#define MSG_TIME_TOUT "tout = %Lg" #define MSG_TIME_TSTOP "tstop = %Lg" #elif defined(SUNDIALS_DOUBLE_PRECISION) -#define MSG_TIME "t = %lg, " -#define MSG_TIME_H "t = %lg and h = %lg, " -#define MSG_TIME_INT "t = %lg is not between tcur - hu = %lg and tcur = %lg." -#define MSG_TIME_TOUT "tout = %lg" +#define MSG_TIME "t = %lg, " +#define MSG_TIME_H "t = %lg and h = %lg, " +#define MSG_TIME_INT "t = %lg is not between tcur - hu = %lg and tcur = %lg." +#define MSG_TIME_TOUT "tout = %lg" #define MSG_TIME_TSTOP "tstop = %lg" #else -#define MSG_TIME "t = %g, " -#define MSG_TIME_H "t = %g and h = %g, " -#define MSG_TIME_INT "t = %g is not between tcur - hu = %g and tcur = %g." -#define MSG_TIME_TOUT "tout = %g" +#define MSG_TIME "t = %g, " +#define MSG_TIME_H "t = %g and h = %g, " +#define MSG_TIME_INT "t = %g is not between tcur - hu = %g and tcur = %g." +#define MSG_TIME_TOUT "tout = %g" #define MSG_TIME_TSTOP "tstop = %g" #endif /* General errors */ -#define MSG_MEM_FAIL "A memory request failed." -#define MSG_NO_MEM "ida_mem = NULL illegal." -#define MSG_NO_MALLOC "Attempt to call before IDAMalloc." -#define MSG_BAD_NVECTOR "A required vector operation is not implemented." +#define MSG_MEM_FAIL "A memory request failed." +#define MSG_NULL_SUNCTX "sunctx = NULL illegal." +#define MSG_NO_MEM "ida_mem = NULL illegal." +#define MSG_NO_MALLOC "Attempt to call before IDAMalloc." +#define MSG_BAD_NVECTOR "A required vector operation is not implemented." /* Initialization errors */ -#define MSG_Y0_NULL "y0 = NULL illegal." -#define MSG_YP0_NULL "yp0 = NULL illegal." -#define MSG_BAD_ITOL "Illegal value for itol. The legal values are IDA_SS, IDA_SV, and IDA_WF." +#define MSG_Y0_NULL "y0 = NULL illegal." +#define MSG_YP0_NULL "yp0 = NULL illegal." +#define MSG_BAD_ITOL \ + "Illegal value for itol. The legal values are IDA_SS, IDA_SV, and IDA_WF." #define MSG_RES_NULL "res = NULL illegal." #define MSG_BAD_RTOL "rtol < 0 illegal." #define MSG_ATOL_NULL "atol = NULL illegal." @@ -1003,130 +1039,185 @@ int IDASensResDQ(int Ns, realtype t, #define MSG_FAIL_EWT "The user-provide EwtSet function failed." #define MSG_BAD_EWT "Some initial ewt component = 0.0 illegal." #define MSG_Y0_FAIL_CONSTR "y0 fails to satisfy constraints." -#define MSG_BAD_ISM_CONSTR "Constraints can not be enforced while forward sensitivity is used with simultaneous method." -#define MSG_LSOLVE_NULL "The linear solver's solve routine is NULL." -#define MSG_LINIT_FAIL "The linear solver's init routine failed." -#define MSG_NLS_INIT_FAIL "The nonlinear solver's init routine failed." - -#define MSG_NO_QUAD "Illegal attempt to call before calling IDAQuadInit." -#define MSG_BAD_EWTQ "Initial ewtQ has component(s) equal to zero (illegal)." -#define MSG_BAD_ITOLQ "Illegal value for itolQ. The legal values are IDA_SS and IDA_SV." -#define MSG_NO_TOLQ "No integration tolerances for quadrature variables have been specified." -#define MSG_NULL_ATOLQ "atolQ = NULL illegal." -#define MSG_BAD_RTOLQ "rtolQ < 0 illegal." -#define MSG_BAD_ATOLQ "atolQ has negative component(s) (illegal)." - -#define MSG_NO_SENSI "Illegal attempt to call before calling IDASensInit." -#define MSG_BAD_EWTS "Initial ewtS has component(s) equal to zero (illegal)." -#define MSG_BAD_ITOLS "Illegal value for itolS. The legal values are IDA_SS, IDA_SV, and IDA_EE." -#define MSG_NULL_ATOLS "atolS = NULL illegal." -#define MSG_BAD_RTOLS "rtolS < 0 illegal." -#define MSG_BAD_ATOLS "atolS has negative component(s) (illegal)." -#define MSG_BAD_PBAR "pbar has zero component(s) (illegal)." -#define MSG_BAD_PLIST "plist has negative component(s) (illegal)." -#define MSG_BAD_NS "NS <= 0 illegal." -#define MSG_NULL_YYS0 "yyS0 = NULL illegal." -#define MSG_NULL_YPS0 "ypS0 = NULL illegal." -#define MSG_BAD_ISM "Illegal value for ism. Legal values are: IDA_SIMULTANEOUS and IDA_STAGGERED." -#define MSG_BAD_IS "Illegal value for is." -#define MSG_NULL_DKYA "dkyA = NULL illegal." -#define MSG_BAD_DQTYPE "Illegal value for DQtype. Legal values are: IDA_CENTERED and IDA_FORWARD." -#define MSG_BAD_DQRHO "DQrhomax < 0 illegal." - -#define MSG_NULL_ABSTOLQS "abstolQS = NULL illegal parameter." -#define MSG_BAD_RELTOLQS "reltolQS < 0 illegal parameter." -#define MSG_BAD_ABSTOLQS "abstolQS has negative component(s) (illegal)." -#define MSG_NO_QUADSENSI "Forward sensitivity analysis for quadrature variables was not activated." -#define MSG_NULL_YQS0 "yQS0 = NULL illegal parameter." - +#define MSG_BAD_ISM_CONSTR \ + "Constraints can not be enforced while forward sensitivity is used with " \ + "simultaneous method." +#define MSG_LSOLVE_NULL "The linear solver's solve routine is NULL." +#define MSG_LINIT_FAIL "The linear solver's init routine failed." +#define MSG_NLS_INIT_FAIL "The nonlinear solver's init routine failed." + +#define MSG_NO_QUAD "Illegal attempt to call before calling IDAQuadInit." +#define MSG_BAD_EWTQ "Initial ewtQ has component(s) equal to zero (illegal)." +#define MSG_BAD_ITOLQ \ + "Illegal value for itolQ. The legal values are IDA_SS and IDA_SV." +#define MSG_NO_TOLQ \ + "No integration tolerances for quadrature variables have been specified." +#define MSG_NULL_ATOLQ "atolQ = NULL illegal." +#define MSG_BAD_RTOLQ "rtolQ < 0 illegal." +#define MSG_BAD_ATOLQ "atolQ has negative component(s) (illegal)." + +#define MSG_NO_SENSI "Illegal attempt to call before calling IDASensInit." +#define MSG_BAD_EWTS "Initial ewtS has component(s) equal to zero (illegal)." +#define MSG_BAD_ITOLS \ + "Illegal value for itolS. The legal values are IDA_SS, IDA_SV, and IDA_EE." +#define MSG_NULL_ATOLS "atolS = NULL illegal." +#define MSG_BAD_RTOLS "rtolS < 0 illegal." +#define MSG_BAD_ATOLS "atolS has negative component(s) (illegal)." +#define MSG_BAD_PBAR "pbar has zero component(s) (illegal)." +#define MSG_BAD_PLIST "plist has negative component(s) (illegal)." +#define MSG_BAD_NS "NS <= 0 illegal." +#define MSG_NULL_YYS0 "yyS0 = NULL illegal." +#define MSG_NULL_YPS0 "ypS0 = NULL illegal." +#define MSG_BAD_ISM \ + "Illegal value for ism. Legal values are: IDA_SIMULTANEOUS and " \ + "IDA_STAGGERED." +#define MSG_BAD_IS "Illegal value for is." +#define MSG_NULL_DKYA "dkyA = NULL illegal." +#define MSG_BAD_DQTYPE \ + "Illegal value for DQtype. Legal values are: IDA_CENTERED and IDA_FORWARD." +#define MSG_BAD_DQRHO "DQrhomax < 0 illegal." + +#define MSG_NULL_ABSTOLQS "abstolQS = NULL illegal parameter." +#define MSG_BAD_RELTOLQS "reltolQS < 0 illegal parameter." +#define MSG_BAD_ABSTOLQS "abstolQS has negative component(s) (illegal)." +#define MSG_NO_QUADSENSI \ + "Forward sensitivity analysis for quadrature variables was not activated." +#define MSG_NULL_YQS0 "yQS0 = NULL illegal parameter." /* IDACalcIC error messages */ -#define MSG_IC_BAD_ICOPT "icopt has an illegal value." +#define MSG_IC_BAD_ICOPT "icopt has an illegal value." #define MSG_IC_BAD_MAXBACKS "maxbacks <= 0 illegal." -#define MSG_IC_MISSING_ID "id = NULL conflicts with icopt." -#define MSG_IC_TOO_CLOSE "tout1 too close to t0 to attempt initial condition calculation." -#define MSG_IC_BAD_ID "id has illegal values." -#define MSG_IC_BAD_EWT "Some initial ewt component = 0.0 illegal." -#define MSG_IC_RES_NONREC "The residual function failed unrecoverably. " -#define MSG_IC_RES_FAIL "The residual function failed at the first call. " -#define MSG_IC_SETUP_FAIL "The linear solver setup failed unrecoverably." -#define MSG_IC_SOLVE_FAIL "The linear solver solve failed unrecoverably." -#define MSG_IC_NO_RECOVERY "The residual routine or the linear setup or solve routine had a recoverable error, but IDACalcIC was unable to recover." +#define MSG_IC_MISSING_ID "id = NULL conflicts with icopt." +#define MSG_IC_TOO_CLOSE \ + "tout1 too close to t0 to attempt initial condition calculation." +#define MSG_IC_BAD_ID "id has illegal values." +#define MSG_IC_BAD_EWT "Some initial ewt component = 0.0 illegal." +#define MSG_IC_RES_NONREC "The residual function failed unrecoverably. " +#define MSG_IC_RES_FAIL "The residual function failed at the first call. " +#define MSG_IC_SETUP_FAIL "The linear solver setup failed unrecoverably." +#define MSG_IC_SOLVE_FAIL "The linear solver solve failed unrecoverably." +#define MSG_IC_NO_RECOVERY \ + "The residual routine or the linear setup or solve routine had a " \ + "recoverable error, but IDACalcIC was unable to recover." #define MSG_IC_FAIL_CONSTR "Unable to satisfy the inequality constraints." -#define MSG_IC_FAILED_LINS "The linesearch algorithm failed: step too small or too many backtracks." +#define MSG_IC_FAILED_LINS \ + "The linesearch algorithm failed: step too small or too many backtracks." #define MSG_IC_CONV_FAILED "Newton/Linesearch algorithm failed to converge." /* IDASolve error messages */ -#define MSG_YRET_NULL "yret = NULL illegal." -#define MSG_YPRET_NULL "ypret = NULL illegal." -#define MSG_TRET_NULL "tret = NULL illegal." -#define MSG_BAD_ITASK "itask has an illegal value." -#define MSG_TOO_CLOSE "tout too close to t0 to start integration." -#define MSG_BAD_HINIT "Initial step is not towards tout." -#define MSG_BAD_TSTOP "The value " MSG_TIME_TSTOP " is behind current " MSG_TIME "in the direction of integration." -#define MSG_CLOSE_ROOTS "Root found at and very near " MSG_TIME "." -#define MSG_MAX_STEPS "At " MSG_TIME ", mxstep steps taken before reaching tout." -#define MSG_EWT_NOW_FAIL "At " MSG_TIME "the user-provide EwtSet function failed." -#define MSG_EWT_NOW_BAD "At " MSG_TIME "some ewt component has become <= 0.0." -#define MSG_TOO_MUCH_ACC "At " MSG_TIME "too much accuracy requested." - -#define MSG_BAD_T "Illegal value for t. " MSG_TIME_INT -#define MSG_BAD_TOUT "Trouble interpolating at " MSG_TIME_TOUT ". tout too far back in direction of integration." - -#define MSG_BAD_K "Illegal value for k." -#define MSG_NULL_DKY "dky = NULL illegal." -#define MSG_NULL_DKYP "dkyp = NULL illegal." - -#define MSG_ERR_FAILS "At " MSG_TIME_H "the error test failed repeatedly or with |h| = hmin." -#define MSG_CONV_FAILS "At " MSG_TIME_H "the corrector convergence failed repeatedly or with |h| = hmin." -#define MSG_SETUP_FAILED "At " MSG_TIME "the linear solver setup failed unrecoverably." -#define MSG_SOLVE_FAILED "At " MSG_TIME "the linear solver solve failed unrecoverably." -#define MSG_REP_RES_ERR "At " MSG_TIME "repeated recoverable residual errors." -#define MSG_RES_NONRECOV "At " MSG_TIME "the residual function failed unrecoverably." -#define MSG_FAILED_CONSTR "At " MSG_TIME "unable to satisfy inequality constraints." -#define MSG_RTFUNC_FAILED "At " MSG_TIME ", the rootfinding routine failed in an unrecoverable manner." -#define MSG_NO_ROOT "Rootfinding was not initialized." -#define MSG_INACTIVE_ROOTS "At the end of the first step, there are still some root functions identically 0. This warning will not be issued again." -#define MSG_NLS_INPUT_NULL "At " MSG_TIME ", the nonlinear solver was passed a NULL input." -#define MSG_NLS_SETUP_FAILED "At " MSG_TIME ", the nonlinear solver setup failed unrecoverably." -#define MSG_NLS_FAIL "At " MSG_TIME ", the nonlinear solver failed in an unrecoverable manner." - +#define MSG_YRET_NULL "yret = NULL illegal." +#define MSG_YPRET_NULL "ypret = NULL illegal." +#define MSG_TRET_NULL "tret = NULL illegal." +#define MSG_BAD_ITASK "itask has an illegal value." +#define MSG_TOO_CLOSE "tout too close to t0 to start integration." +#define MSG_BAD_HINIT "Initial step is not towards tout." +#define MSG_BAD_TSTOP \ + "The value " MSG_TIME_TSTOP " is behind current " MSG_TIME \ + "in the direction of integration." +#define MSG_CLOSE_ROOTS "Root found at and very near " MSG_TIME "." +#define MSG_MAX_STEPS \ + "At " MSG_TIME ", mxstep steps taken before reaching tout." +#define MSG_EWT_NOW_FAIL \ + "At " MSG_TIME "the user-provide EwtSet function failed." +#define MSG_EWT_NOW_BAD "At " MSG_TIME "some ewt component has become <= 0.0." +#define MSG_TOO_MUCH_ACC "At " MSG_TIME "too much accuracy requested." + +#define MSG_BAD_K "Illegal value for k." +#define MSG_NULL_DKY "dky = NULL illegal." +#define MSG_NULL_DKYP "dkyp = NULL illegal." +#define MSG_BAD_T "Illegal value for t." MSG_TIME_INT +#define MSG_BAD_TOUT \ + "Trouble interpolating at " MSG_TIME_TOUT \ + ". tout too far back in direction of integration." + +#define MSG_ERR_FAILS \ + "At " MSG_TIME_H "the error test failed repeatedly or with |h| = hmin." +#define MSG_CONV_FAILS \ + "At " MSG_TIME_H \ + "the corrector convergence failed repeatedly or with |h| = hmin." +#define MSG_SETUP_FAILED \ + "At " MSG_TIME "the linear solver setup failed unrecoverably." +#define MSG_SOLVE_FAILED \ + "At " MSG_TIME "the linear solver solve failed unrecoverably." +#define MSG_REP_RES_ERR "At " MSG_TIME "repeated recoverable residual errors." +#define MSG_RES_NONRECOV \ + "At " MSG_TIME "the residual function failed unrecoverably." +#define MSG_FAILED_CONSTR \ + "At " MSG_TIME "unable to satisfy inequality constraints." +#define MSG_RTFUNC_FAILED \ + "At " MSG_TIME ", the rootfinding routine failed in an unrecoverable " \ + "manner." +#define MSG_NO_ROOT "Rootfinding was not initialized." +#define MSG_INACTIVE_ROOTS \ + "At the end of the first step, there are still some root functions " \ + "identically 0. This warning will not be issued again." +#define MSG_NLS_INPUT_NULL \ + "At " MSG_TIME ", the nonlinear solver was passed a NULL input." +#define MSG_NLS_SETUP_FAILED \ + "At " MSG_TIME ", the nonlinear solver setup failed unrecoverably." +#define MSG_NLS_FAIL \ + "At " MSG_TIME ", the nonlinear solver failed in an unrecoverable manner." #define MSG_EWTQ_NOW_BAD "At " MSG_TIME ", a component of ewtQ has become <= 0." -#define MSG_QRHSFUNC_FAILED "At " MSG_TIME ", the quadrature right-hand side routine failed in an unrecoverable manner." -#define MSG_QRHSFUNC_UNREC "At " MSG_TIME ", the quadrature right-hand side failed in a recoverable manner, but no recovery is possible." -#define MSG_QRHSFUNC_REPTD "At " MSG_TIME "repeated recoverable quadrature right-hand side function errors." -#define MSG_QRHSFUNC_FIRST "The quadrature right-hand side routine failed at the first call." - -#define MSG_NULL_P "p = NULL when using internal DQ for sensitivity residual is illegal." +#define MSG_QRHSFUNC_FAILED \ + "At " MSG_TIME ", the quadrature right-hand side routine failed in an " \ + "unrecoverable manner." +#define MSG_QRHSFUNC_UNREC \ + "At " MSG_TIME ", the quadrature right-hand side failed in a recoverable " \ + "manner, but no recovery is possible." +#define MSG_QRHSFUNC_REPTD \ + "At " MSG_TIME \ + "repeated recoverable quadrature right-hand side function errors." +#define MSG_QRHSFUNC_FIRST \ + "The quadrature right-hand side routine failed at the first call." + +#define MSG_NULL_P \ + "p = NULL when using internal DQ for sensitivity residual is illegal." #define MSG_EWTS_NOW_BAD "At " MSG_TIME ", a component of ewtS has become <= 0." -#define MSG_SRES_FAILED "At " MSG_TIME ", the sensitivity residual routine failed in an unrecoverable manner." -#define MSG_SRES_UNREC "At " MSG_TIME ", the sensitivity residual failed in a recoverable manner, but no recovery is possible." -#define MSG_SRES_REPTD "At " MSG_TIME "repeated recoverable sensitivity residual function errors." - -#define MSG_NO_TOLQS "No integration tolerances for quadrature sensitivity variables have been specified." -#define MSG_NULL_RHSQ "IDAS is expected to use DQ to evaluate the RHS of quad. sensi., but quadratures were not initialized." +#define MSG_SRES_FAILED \ + "At " MSG_TIME \ + ", the sensitivity residual routine failed in an unrecoverable manner." +#define MSG_SRES_UNREC \ + "At " MSG_TIME ", the sensitivity residual failed in a recoverable manner, " \ + "but no recovery is possible." +#define MSG_SRES_REPTD \ + "At " MSG_TIME "repeated recoverable sensitivity residual function errors." + +#define MSG_NO_TOLQS \ + "No integration tolerances for quadrature sensitivity variables have been " \ + "specified." +#define MSG_NULL_RHSQ \ + "IDAS is expected to use DQ to evaluate the RHS of quad. sensi., but " \ + "quadratures were not initialized." #define MSG_BAD_EWTQS "Initial ewtQS has component(s) equal to zero (illegal)." -#define MSG_EWTQS_NOW_BAD "At " MSG_TIME ", a component of ewtQS has become <= 0." -#define MSG_QSRHSFUNC_FAILED "At " MSG_TIME ", the sensitivity quadrature right-hand side routine failed in an unrecoverable manner." -#define MSG_QSRHSFUNC_REPTD "At " MSG_TIME "repeated recoverable sensitivity quadrature right-hand side function errors." -#define MSG_QSRHSFUNC_FIRST "The quadrature right-hand side routine failed at the first call." +#define MSG_EWTQS_NOW_BAD \ + "At " MSG_TIME ", a component of ewtQS has become <= 0." +#define MSG_QSRHSFUNC_FAILED \ + "At " MSG_TIME ", the sensitivity quadrature right-hand side routine " \ + "failed in an unrecoverable manner." +#define MSG_QSRHSFUNC_REPTD \ + "At " MSG_TIME "repeated recoverable sensitivity quadrature right-hand " \ + "side function errors." +#define MSG_QSRHSFUNC_FIRST \ + "The quadrature right-hand side routine failed at the first call." /* IDASet* / IDAGet* error messages */ -#define MSG_NEG_MAXORD "maxord<=0 illegal." -#define MSG_BAD_MAXORD "Illegal attempt to increase maximum order." -#define MSG_NEG_HMAX "hmax < 0 illegal." -#define MSG_NEG_EPCON "epcon <= 0.0 illegal." -#define MSG_BAD_CONSTR "Illegal values in constraints vector." -#define MSG_BAD_EPICCON "epiccon <= 0.0 illegal." -#define MSG_BAD_MAXNH "maxnh <= 0 illegal." -#define MSG_BAD_MAXNJ "maxnj <= 0 illegal." -#define MSG_BAD_MAXNIT "maxnit <= 0 illegal." -#define MSG_BAD_STEPTOL "steptol <= 0.0 illegal." - -#define MSG_TOO_LATE "IDAGetConsistentIC can only be called before IDASolve." + +#define MSG_NEG_MAXORD "maxord <= 0 illegal." +#define MSG_BAD_MAXORD "Illegal attempt to increase maximum order." +#define MSG_NEG_HMAX "hmax < 0 illegal." +#define MSG_NEG_HMIN "hmin < 0 illegal." +#define MSG_NEG_EPCON "epcon <= 0.0 illegal." +#define MSG_BAD_CONSTR "Illegal values in constraints vector." +#define MSG_BAD_EPICCON "epiccon <= 0.0 illegal." +#define MSG_BAD_MAXNH "maxnh <= 0 illegal." +#define MSG_BAD_MAXNJ "maxnj <= 0 illegal." +#define MSG_BAD_MAXNIT "maxnit <= 0 illegal." +#define MSG_BAD_STEPTOL "steptol <= 0.0 illegal." + +#define MSG_TOO_LATE "IDAGetConsistentIC can only be called before IDASolve." /* * ================================================================= @@ -1134,23 +1225,31 @@ int IDASensResDQ(int Ns, realtype t, * ================================================================= */ -#define MSGAM_NULL_IDAMEM "ida_mem = NULL illegal." -#define MSGAM_NO_ADJ "Illegal attempt to call before calling IDAadjInit." -#define MSGAM_BAD_INTERP "Illegal value for interp." -#define MSGAM_BAD_STEPS "Steps nonpositive illegal." -#define MSGAM_BAD_WHICH "Illegal value for which." -#define MSGAM_NO_BCK "No backward problems have been defined yet." -#define MSGAM_NO_FWD "Illegal attempt to call before calling IDASolveF." -#define MSGAM_BAD_TB0 "The initial time tB0 is outside the interval over which the forward problem was solved." -#define MSGAM_BAD_SENSI "At least one backward problem requires sensitivities, but they were not stored for interpolation." -#define MSGAM_BAD_ITASKB "Illegal value for itaskB. Legal values are IDA_NORMAL and IDA_ONE_STEP." -#define MSGAM_BAD_TBOUT "The final time tBout is outside the interval over which the forward problem was solved." -#define MSGAM_BACK_ERROR "Error occured while integrating backward problem # %d" -#define MSGAM_BAD_TINTERP "Bad t = %g for interpolation." -#define MSGAM_BAD_T "Bad t for interpolation." -#define MSGAM_WRONG_INTERP "This function cannot be called for the specified interp type." -#define MSGAM_MEM_FAIL "A memory request failed." -#define MSGAM_NO_INITBS "Illegal attempt to call before calling IDAInitBS." +#define MSGAM_NULL_IDAMEM "ida_mem = NULL illegal." +#define MSGAM_NO_ADJ "Illegal attempt to call before calling IDAadjInit." +#define MSGAM_BAD_INTERP "Illegal value for interp." +#define MSGAM_BAD_STEPS "Steps nonpositive illegal." +#define MSGAM_BAD_WHICH "Illegal value for which." +#define MSGAM_NO_BCK "No backward problems have been defined yet." +#define MSGAM_NO_FWD "Illegal attempt to call before calling IDASolveF." +#define MSGAM_BAD_TB0 \ + "The initial time tB0 is outside the interval over which the forward " \ + "problem was solved." +#define MSGAM_BAD_SENSI \ + "At least one backward problem requires sensitivities, but they were not " \ + "stored for interpolation." +#define MSGAM_BAD_ITASKB \ + "Illegal value for itaskB. Legal values are IDA_NORMAL and IDA_ONE_STEP." +#define MSGAM_BAD_TBOUT \ + "The final time tBout is outside the interval over which the forward " \ + "problem was solved." +#define MSGAM_BACK_ERROR "Error occured while integrating backward problem # %d" +#define MSGAM_BAD_TINTERP "Bad t = %g for interpolation." +#define MSGAM_BAD_T "Bad t for interpolation." +#define MSGAM_WRONG_INTERP \ + "This function cannot be called for the specified interp type." +#define MSGAM_MEM_FAIL "A memory request failed." +#define MSGAM_NO_INITBS "Illegal attempt to call before calling IDAInitBS." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_io.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_io.c index e62aae8b6..ffbc13f95 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_io.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_io.c @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban and Cosmin Petra @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,13 +19,14 @@ #include #include "idas_impl.h" -#include "sundials/sundials_types.h" +#include "idas_ls_impl.h" #include "sundials/sundials_math.h" +#include "sundials/sundials_types.h" -#define ZERO RCONST(0.0) -#define HALF RCONST(0.5) -#define ONE RCONST(1.0) -#define TWOPT5 RCONST(2.5) +#define ZERO SUN_RCONST(0.0) +#define HALF SUN_RCONST(0.5) +#define ONE SUN_RCONST(1.0) +#define TWOPT5 SUN_RCONST(2.5) /* * ================================================================= @@ -33,336 +34,532 @@ * ================================================================= */ -int IDASetErrHandlerFn(void *ida_mem, IDAErrHandlerFn ehfun, void *eh_data) +int IDASetDeltaCjLSetup(void* ida_mem, sunrealtype dcj) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetErrHandlerFn", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - IDA_mem->ida_ehfun = ehfun; - IDA_mem->ida_eh_data = eh_data; + if (dcj < ZERO || dcj >= ONE) { IDA_mem->ida_dcj = DCJ_DEFAULT; } + else { IDA_mem->ida_dcj = dcj; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } +/*-----------------------------------------------------------------*/ -int IDASetErrFile(void *ida_mem, FILE *errfp) +int IDASetUserData(void* ida_mem, void* user_data) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetErrFile", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - IDA_mem->ida_errfp = errfp; + IDA_mem->ida_user_data = user_data; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetUserData(void *ida_mem, void *user_data) +int IDASetEtaFixedStepBounds(void* ida_mem, sunrealtype eta_min_fx, + sunrealtype eta_max_fx) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetUserData", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_min_fx >= ZERO && eta_min_fx <= ONE) + { + IDA_mem->ida_eta_min_fx = eta_min_fx; } + else { IDA_mem->ida_eta_min_fx = ETA_MIN_FX_DEFAULT; } - IDA_mem = (IDAMem) ida_mem; + if (eta_max_fx >= ONE) { IDA_mem->ida_eta_max_fx = eta_max_fx; } + else { IDA_mem->ida_eta_max_fx = ETA_MAX_FX_DEFAULT; } - IDA_mem->ida_user_data = user_data; + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetEtaMax(void* ida_mem, sunrealtype eta_max) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_max <= ONE) { IDA_mem->ida_eta_max = ETA_MAX_DEFAULT; } + else { IDA_mem->ida_eta_max = eta_max; } + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetEtaMin(void* ida_mem, sunrealtype eta_min) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_min <= ZERO || eta_min >= ONE) + { + IDA_mem->ida_eta_min = ETA_MIN_DEFAULT; + } + else { IDA_mem->ida_eta_min = eta_min; } + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetEtaLow(void* ida_mem, sunrealtype eta_low) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_low <= ZERO || eta_low >= ONE) + { + IDA_mem->ida_eta_low = ETA_LOW_DEFAULT; + } + else { IDA_mem->ida_eta_low = eta_low; } + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetEtaMinErrFail(void* ida_mem, sunrealtype eta_min_ef) +{ + IDAMem IDA_mem; - return(IDA_SUCCESS); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_min_ef <= ZERO || eta_min_ef >= ONE) + { + IDA_mem->ida_eta_min_ef = ETA_MIN_EF_DEFAULT; + } + else { IDA_mem->ida_eta_min_ef = eta_min_ef; } + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetEtaConvFail(void* ida_mem, sunrealtype eta_cf) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + IDA_mem = (IDAMem)ida_mem; + + /* set allowed value or use default */ + if (eta_cf <= ZERO || eta_cf >= ONE) { IDA_mem->ida_eta_cf = ETA_CF_DEFAULT; } + else { IDA_mem->ida_eta_cf = eta_cf; } + + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxOrd(void *ida_mem, int maxord) +int IDASetMaxOrd(void* ida_mem, int maxord) { IDAMem IDA_mem; int maxord_alloc; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxOrd", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (maxord <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxOrd", MSG_NEG_MAXORD); - return(IDA_ILL_INPUT); + if (maxord <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NEG_MAXORD); + return (IDA_ILL_INPUT); } /* Cannot increase maximum order beyond the value that was used when allocating memory */ maxord_alloc = IDA_mem->ida_maxord_alloc; - if (maxord > maxord_alloc) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxOrd", MSG_BAD_MAXORD); - return(IDA_ILL_INPUT); + if (maxord > maxord_alloc) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_MAXORD); + return (IDA_ILL_INPUT); } - IDA_mem->ida_maxord = SUNMIN(maxord,MAXORD_DEFAULT); + IDA_mem->ida_maxord = SUNMIN(maxord, MAXORD_DEFAULT); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxNumSteps(void *ida_mem, long int mxsteps) +int IDASetMaxNumSteps(void* ida_mem, long int mxsteps) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxNumSteps", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Passing mxsteps=0 sets the default. Passing mxsteps<0 disables the test. */ - if (mxsteps == 0) - IDA_mem->ida_mxstep = MXSTEP_DEFAULT; - else - IDA_mem->ida_mxstep = mxsteps; + if (mxsteps == 0) { IDA_mem->ida_mxstep = MXSTEP_DEFAULT; } + else { IDA_mem->ida_mxstep = mxsteps; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetInitStep(void *ida_mem, realtype hin) +int IDASetInitStep(void* ida_mem, sunrealtype hin) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetInitStep", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_hin = hin; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxStep(void *ida_mem, realtype hmax) +int IDASetMaxStep(void* ida_mem, sunrealtype hmax) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxStep", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (hmax < 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxStep", MSG_NEG_HMAX); - return(IDA_ILL_INPUT); + if (hmax < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NEG_HMAX); + return (IDA_ILL_INPUT); } /* Passing 0 sets hmax = infinity */ - if (hmax == ZERO) { + if (hmax == ZERO) + { IDA_mem->ida_hmax_inv = HMAX_INV_DEFAULT; - return(IDA_SUCCESS); + return (IDA_SUCCESS); + } + + IDA_mem->ida_hmax_inv = ONE / hmax; + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetMinStep(void* ida_mem, sunrealtype hmin) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + + IDA_mem = (IDAMem)ida_mem; + + if (hmin < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NEG_HMIN); + return (IDA_ILL_INPUT); + } + + /* Passing 0 sets hmin = zero */ + if (hmin == ZERO) + { + IDA_mem->ida_hmin = HMIN_DEFAULT; + return (IDA_SUCCESS); } - IDA_mem->ida_hmax_inv = ONE/hmax; + IDA_mem->ida_hmin = hmin; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetStopTime(void *ida_mem, realtype tstop) +int IDASetStopTime(void* ida_mem, sunrealtype tstop) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetStopTime", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* If IDASolve was called at least once, test if tstop is legal * (i.e. if it was not already passed). * If IDASetStopTime is called before the first call to IDASolve, * tstop will be checked in IDASolve. */ - if (IDA_mem->ida_nst > 0) { - - if ( (tstop - IDA_mem->ida_tn) * IDA_mem->ida_hh < ZERO ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASetStopTime", MSG_BAD_TSTOP, tstop, IDA_mem->ida_tn); - return(IDA_ILL_INPUT); + if (IDA_mem->ida_nst > 0) + { + if ((tstop - IDA_mem->ida_tn) * IDA_mem->ida_hh < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_TSTOP, tstop, IDA_mem->ida_tn); + return (IDA_ILL_INPUT); } - } - IDA_mem->ida_tstop = tstop; + IDA_mem->ida_tstop = tstop; IDA_mem->ida_tstopset = SUNTRUE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetNonlinConvCoef(void *ida_mem, realtype epcon) +int IDAClearStopTime(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetNonlinConvCoef", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; + + IDA_mem->ida_tstopset = SUNFALSE; - if (epcon <= ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetNonlinConvCoef", MSG_NEG_EPCON); - return(IDA_ILL_INPUT); + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDASetNonlinConvCoef(void* ida_mem, sunrealtype epcon) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + + IDA_mem = (IDAMem)ida_mem; + + if (epcon <= ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NEG_EPCON); + return (IDA_ILL_INPUT); } IDA_mem->ida_epcon = epcon; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxErrTestFails(void *ida_mem, int maxnef) +int IDASetMaxErrTestFails(void* ida_mem, int maxnef) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxErrTestFails", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_maxnef = maxnef; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxConvFails(void *ida_mem, int maxncf) +int IDASetMaxConvFails(void* ida_mem, int maxncf) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxConvFails", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_maxncf = maxncf; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxNonlinIters(void *ida_mem, int maxcor) +int IDASetMaxNonlinIters(void* ida_mem, int maxcor) { IDAMem IDA_mem; - booleantype sensi_sim; + sunbooleantype sensi_sim; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASetMaxNonlinIters", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Are we computing sensitivities with the simultaneous approach? */ - sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism==IDA_SIMULTANEOUS)); - - if (sensi_sim) { + sensi_sim = (IDA_mem->ida_sensi && (IDA_mem->ida_ism == IDA_SIMULTANEOUS)); + if (sensi_sim) + { /* check that the NLS is non-NULL */ - if (IDA_mem->NLSsim == NULL) { - IDAProcessError(NULL, IDA_MEM_FAIL, "IDAS", - "IDASetMaxNonlinIters", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDA_mem->NLSsim == NULL) + { + IDAProcessError(NULL, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(IDA_mem->NLSsim, maxcor)); - - } else { - + return (SUNNonlinSolSetMaxIters(IDA_mem->NLSsim, maxcor)); + } + else + { /* check that the NLS is non-NULL */ - if (IDA_mem->NLS == NULL) { - IDAProcessError(NULL, IDA_MEM_FAIL, "IDAS", - "IDASetMaxNonlinIters", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDA_mem->NLS == NULL) + { + IDAProcessError(NULL, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(IDA_mem->NLS, maxcor)); + return (SUNNonlinSolSetMaxIters(IDA_mem->NLS, maxcor)); } } /*-----------------------------------------------------------------*/ -int IDASetSuppressAlg(void *ida_mem, booleantype suppressalg) +int IDASetSuppressAlg(void* ida_mem, sunbooleantype suppressalg) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetSuppressAlg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_suppressalg = suppressalg; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetId(void *ida_mem, N_Vector id) +int IDASetId(void* ida_mem, N_Vector id) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetId", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (id == NULL) { - if (IDA_mem->ida_idMallocDone) { + if (id == NULL) + { + if (IDA_mem->ida_idMallocDone) + { N_VDestroy(IDA_mem->ida_id); IDA_mem->ida_lrw -= IDA_mem->ida_lrw1; IDA_mem->ida_liw -= IDA_mem->ida_liw1; } IDA_mem->ida_idMallocDone = SUNFALSE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - if ( !(IDA_mem->ida_idMallocDone) ) { + if (!(IDA_mem->ida_idMallocDone)) + { IDA_mem->ida_id = N_VClone(id); IDA_mem->ida_lrw += IDA_mem->ida_lrw1; IDA_mem->ida_liw += IDA_mem->ida_liw1; @@ -373,54 +570,61 @@ int IDASetId(void *ida_mem, N_Vector id) N_VScale(ONE, id, IDA_mem->ida_id); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetConstraints(void *ida_mem, N_Vector constraints) +int IDASetConstraints(void* ida_mem, N_Vector constraints) { IDAMem IDA_mem; - realtype temptest; + sunrealtype temptest; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetConstraints", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (constraints == NULL) { - if (IDA_mem->ida_constraintsMallocDone) { + if (constraints == NULL) + { + if (IDA_mem->ida_constraintsMallocDone) + { N_VDestroy(IDA_mem->ida_constraints); IDA_mem->ida_lrw -= IDA_mem->ida_lrw1; IDA_mem->ida_liw -= IDA_mem->ida_liw1; } IDA_mem->ida_constraintsMallocDone = SUNFALSE; - IDA_mem->ida_constraintsSet = SUNFALSE; - return(IDA_SUCCESS); + IDA_mem->ida_constraintsSet = SUNFALSE; + return (IDA_SUCCESS); } /* Test if required vector ops. are defined */ - if (constraints->ops->nvdiv == NULL || - constraints->ops->nvmaxnorm == NULL || - constraints->ops->nvcompare == NULL || - constraints->ops->nvconstrmask == NULL || - constraints->ops->nvminquotient == NULL) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetConstraints", MSG_BAD_NVECTOR); - return(IDA_ILL_INPUT); + if (constraints->ops->nvdiv == NULL || constraints->ops->nvmaxnorm == NULL || + constraints->ops->nvcompare == NULL || + constraints->ops->nvconstrmask == NULL || + constraints->ops->nvminquotient == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_NVECTOR); + return (IDA_ILL_INPUT); } /* Check the constraints vector */ temptest = N_VMaxNorm(constraints); - if((temptest > TWOPT5) || (temptest < HALF)){ - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetConstraints", MSG_BAD_CONSTR); - return(IDA_ILL_INPUT); + if ((temptest > TWOPT5) || (temptest < HALF)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_CONSTR); + return (IDA_ILL_INPUT); } - if ( !(IDA_mem->ida_constraintsMallocDone) ) { + if (!(IDA_mem->ida_constraintsMallocDone)) + { IDA_mem->ida_constraints = N_VClone(constraints); IDA_mem->ida_lrw += IDA_mem->ida_lrw1; IDA_mem->ida_liw += IDA_mem->ida_liw1; @@ -433,7 +637,7 @@ int IDASetConstraints(void *ida_mem, N_Vector constraints) IDA_mem->ida_constraintsSet = SUNTRUE; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -443,27 +647,30 @@ int IDASetConstraints(void *ida_mem, N_Vector constraints) * The default is to monitor both crossings. */ -int IDASetRootDirection(void *ida_mem, int *rootdir) +int IDASetRootDirection(void* ida_mem, int* rootdir) { IDAMem IDA_mem; int i, nrt; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetRootDirection", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; nrt = IDA_mem->ida_nrtfn; - if (nrt==0) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", "IDASetRootDirection", MSG_NO_ROOT); - return(IDA_ILL_INPUT); + if (nrt == 0) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_NO_ROOT); + return (IDA_ILL_INPUT); } - for(i=0; iida_rootdir[i] = rootdir[i]; + for (i = 0; i < nrt; i++) { IDA_mem->ida_rootdir[i] = rootdir[i]; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -473,181 +680,200 @@ int IDASetRootDirection(void *ida_mem, int *rootdir) * to be identically zero at the beginning of the integration */ -int IDASetNoInactiveRootWarn(void *ida_mem) +int IDASetNoInactiveRootWarn(void* ida_mem) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetNoInactiveRootWarn", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_mxgnull = 0; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* * ================================================================= * IDA IC optional input functions * ================================================================= */ -int IDASetNonlinConvCoefIC(void *ida_mem, realtype epiccon) +int IDASetNonlinConvCoefIC(void* ida_mem, sunrealtype epiccon) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetNonlinConvCoefIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (epiccon <= ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetNonlinConvCoefIC", MSG_BAD_EPICCON); - return(IDA_ILL_INPUT); + if (epiccon <= ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_EPICCON); + return (IDA_ILL_INPUT); } IDA_mem->ida_epiccon = epiccon; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxNumStepsIC(void *ida_mem, int maxnh) +int IDASetMaxNumStepsIC(void* ida_mem, int maxnh) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxNumStepsIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (maxnh <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxNumStepsIC", MSG_BAD_MAXNH); - return(IDA_ILL_INPUT); + if (maxnh <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_MAXNH); + return (IDA_ILL_INPUT); } IDA_mem->ida_maxnh = maxnh; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxNumJacsIC(void *ida_mem, int maxnj) +int IDASetMaxNumJacsIC(void* ida_mem, int maxnj) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxNumJacsIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (maxnj <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxNumJacsIC", MSG_BAD_MAXNJ); - return(IDA_ILL_INPUT); + if (maxnj <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_MAXNJ); + return (IDA_ILL_INPUT); } IDA_mem->ida_maxnj = maxnj; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxNumItersIC(void *ida_mem, int maxnit) +int IDASetMaxNumItersIC(void* ida_mem, int maxnit) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetMaxNumItersIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (maxnit <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetMaxNumItersIC", MSG_BAD_MAXNIT); - return(IDA_ILL_INPUT); + if (maxnit <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_MAXNIT); + return (IDA_ILL_INPUT); } IDA_mem->ida_maxnit = maxnit; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetMaxBacksIC(void *ida_mem, int maxbacks) +int IDASetMaxBacksIC(void* ida_mem, int maxbacks) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDA", "IDASetMaxBacksIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (maxbacks <= 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASetMaxBacksIC", MSG_IC_BAD_MAXBACKS); - return(IDA_ILL_INPUT); + if (maxbacks <= 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_IC_BAD_MAXBACKS); + return (IDA_ILL_INPUT); } IDA_mem->ida_maxbacks = maxbacks; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetLineSearchOffIC(void *ida_mem, booleantype lsoff) +int IDASetLineSearchOffIC(void* ida_mem, sunbooleantype lsoff) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetLineSearchOffIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_lsoff = lsoff; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetStepToleranceIC(void *ida_mem, realtype steptol) +int IDASetStepToleranceIC(void* ida_mem, sunrealtype steptol) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetStepToleranceIC", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (steptol <= ZERO) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetStepToleranceIC", MSG_BAD_STEPTOL); - return(IDA_ILL_INPUT); + if (steptol <= ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_STEPTOL); + return (IDA_ILL_INPUT); } IDA_mem->ida_steptol = steptol; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -658,19 +884,21 @@ int IDASetStepToleranceIC(void *ida_mem, realtype steptol) /*-----------------------------------------------------------------*/ -int IDASetQuadErrCon(void *ida_mem, booleantype errconQ) +int IDASetQuadErrCon(void* ida_mem, sunbooleantype errconQ) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetQuadErrCon", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadMallocDone == SUNFALSE) { - IDAProcessError(NULL, IDA_NO_QUAD, "IDAS", "IDASetQuadErrCon", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadMallocDone == SUNFALSE) + { + IDAProcessError(NULL, IDA_NO_QUAD, __LINE__, __func__, __FILE__, MSG_NO_QUAD); + return (IDA_NO_QUAD); } IDA_mem->ida_errconQ = errconQ; @@ -684,93 +912,103 @@ int IDASetQuadErrCon(void *ida_mem, booleantype errconQ) * ================================================================= */ -int IDASetSensDQMethod(void *ida_mem, int DQtype, realtype DQrhomax) +int IDASetSensDQMethod(void* ida_mem, int DQtype, sunrealtype DQrhomax) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetSensDQMethod", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if ( (DQtype != IDA_CENTERED) && (DQtype != IDA_FORWARD) ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetSensDQMethod", MSG_BAD_DQTYPE); - return(IDA_ILL_INPUT); + if ((DQtype != IDA_CENTERED) && (DQtype != IDA_FORWARD)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_DQTYPE); + return (IDA_ILL_INPUT); } - if (DQrhomax < ZERO ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDASetSensDQMethod", MSG_BAD_DQRHO); - return(IDA_ILL_INPUT); + if (DQrhomax < ZERO) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_DQRHO); + return (IDA_ILL_INPUT); } - IDA_mem->ida_DQtype = DQtype; + IDA_mem->ida_DQtype = DQtype; IDA_mem->ida_DQrhomax = DQrhomax; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetSensErrCon(void *ida_mem, booleantype errconS) +int IDASetSensErrCon(void* ida_mem, sunbooleantype errconS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetSensErrCon", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_errconS = errconS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDASetSensMaxNonlinIters(void *ida_mem, int maxcorS) +int IDASetSensMaxNonlinIters(void* ida_mem, int maxcorS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASetSensMaxNonlinIters", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* check that the NLS is non-NULL */ - if (IDA_mem->NLSstg == NULL) { - IDAProcessError(NULL, IDA_MEM_FAIL, "IDAS", - "IDASetSensMaxNonlinIters", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDA_mem->NLSstg == NULL) + { + IDAProcessError(NULL, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - return(SUNNonlinSolSetMaxIters(IDA_mem->NLSstg, maxcorS)); + return (SUNNonlinSolSetMaxIters(IDA_mem->NLSstg, maxcorS)); } /*-----------------------------------------------------------------*/ -int IDASetSensParams(void *ida_mem, realtype *p, realtype *pbar, int *plist) +int IDASetSensParams(void* ida_mem, sunrealtype* p, sunrealtype* pbar, int* plist) { IDAMem IDA_mem; int Ns, is; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetSensParams", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDASetSensParams", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } Ns = IDA_mem->ida_Ns; @@ -782,32 +1020,44 @@ int IDASetSensParams(void *ida_mem, realtype *p, realtype *pbar, int *plist) /* pbar */ if (pbar != NULL) - for (is=0; isida_pbar[is] = SUNRabs(pbar[is]); } + } else - for (is=0; isida_pbar[is] = ONE; + { + for (is = 0; is < Ns; is++) { IDA_mem->ida_pbar[is] = ONE; } + } /* plist */ if (plist != NULL) - for (is=0; isida_plist[is] = plist[is]; } + } else - for (is=0; isida_plist[is] = is; + { + for (is = 0; is < Ns; is++) { IDA_mem->ida_plist[is] = is; } + } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -818,31 +1068,36 @@ int IDASetSensParams(void *ida_mem, realtype *p, realtype *pbar, int *plist) * are considered or not in the error control. * ----------------------------------------------------------------- */ -int IDASetQuadSensErrCon(void *ida_mem, booleantype errconQS) +int IDASetQuadSensErrCon(void* ida_mem, sunbooleantype errconQS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetQuadSensErrCon", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was sensitivity initialized? */ - if (IDA_mem->ida_sensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDASetQuadSensErrCon", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } /* Was quadrature sensitivity initialized? */ - if (IDA_mem->ida_quadSensMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDASetQuadSensErrCon", MSG_NO_SENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadSensMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_QUADSENS); } IDA_mem->ida_errconQS = errconQS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -851,403 +1106,427 @@ int IDASetQuadSensErrCon(void *ida_mem, booleantype errconQS) * ================================================================= */ -int IDAGetNumSteps(void *ida_mem, long int *nsteps) +int IDAGetNumSteps(void* ida_mem, long int* nsteps) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumSteps", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nsteps = IDA_mem->ida_nst; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumResEvals(void *ida_mem, long int *nrevals) +int IDAGetNumResEvals(void* ida_mem, long int* nrevals) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumResEvals", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nrevals = IDA_mem->ida_nre; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumLinSolvSetups(void *ida_mem, long int *nlinsetups) +int IDAGetNumLinSolvSetups(void* ida_mem, long int* nlinsetups) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumLinSolvSetups", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nlinsetups = IDA_mem->ida_nsetups; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumErrTestFails(void *ida_mem, long int *netfails) +int IDAGetNumErrTestFails(void* ida_mem, long int* netfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumErrTestFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *netfails = IDA_mem->ida_netf; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumBacktrackOps(void *ida_mem, long int *nbacktracks) +int IDAGetNumBacktrackOps(void* ida_mem, long int* nbacktracks) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumBacktrackOps", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nbacktracks = IDA_mem->ida_nbacktr; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetConsistentIC(void *ida_mem, N_Vector yy0, N_Vector yp0) +int IDAGetConsistentIC(void* ida_mem, N_Vector yy0, N_Vector yp0) { IDAMem IDA_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetConsistentIC", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_kused != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAGetConsistentIC", MSG_TOO_LATE); - return(IDA_ILL_INPUT); + if (IDA_mem->ida_kused != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TOO_LATE); + return (IDA_ILL_INPUT); } - if(yy0 != NULL) N_VScale(ONE, IDA_mem->ida_phi[0], yy0); - if(yp0 != NULL) N_VScale(ONE, IDA_mem->ida_phi[1], yp0); + if (yy0 != NULL) { N_VScale(ONE, IDA_mem->ida_phi[0], yy0); } + if (yp0 != NULL) { N_VScale(ONE, IDA_mem->ida_phi[1], yp0); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetLastOrder(void *ida_mem, int *klast) +int IDAGetLastOrder(void* ida_mem, int* klast) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetLastOrder", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *klast = IDA_mem->ida_kused; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentOrder(void *ida_mem, int *kcur) +int IDAGetCurrentOrder(void* ida_mem, int* kcur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentOrder", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *kcur = IDA_mem->ida_kk; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentCj(void *ida_mem, realtype *cj) +int IDAGetCurrentCj(void* ida_mem, sunrealtype* cj) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentCjRatio", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *cj = IDA_mem->ida_cj; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentY(void *ida_mem, N_Vector *ycur) +int IDAGetCurrentY(void* ida_mem, N_Vector* ycur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentY", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *ycur = IDA_mem->ida_yy; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentYSens(void *ida_mem, N_Vector **yS) +int IDAGetCurrentYSens(void* ida_mem, N_Vector** yS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentYSens", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *yS = IDA_mem->ida_yyS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentYp(void *ida_mem, N_Vector *ypcur) +int IDAGetCurrentYp(void* ida_mem, N_Vector* ypcur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentYp", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *ypcur = IDA_mem->ida_yp; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentYpSens(void *ida_mem, N_Vector **ypS) +int IDAGetCurrentYpSens(void* ida_mem, N_Vector** ypS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentYpSens", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *ypS = IDA_mem->ida_ypS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetActualInitStep(void *ida_mem, realtype *hinused) +int IDAGetActualInitStep(void* ida_mem, sunrealtype* hinused) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetActualInitStep", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *hinused = IDA_mem->ida_h0u; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetLastStep(void *ida_mem, realtype *hlast) +int IDAGetLastStep(void* ida_mem, sunrealtype* hlast) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetLastStep", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *hlast = IDA_mem->ida_hused; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentStep(void *ida_mem, realtype *hcur) +int IDAGetCurrentStep(void* ida_mem, sunrealtype* hcur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentStep", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *hcur = IDA_mem->ida_hh; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetCurrentTime(void *ida_mem, realtype *tcur) +int IDAGetCurrentTime(void* ida_mem, sunrealtype* tcur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetCurrentTime", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *tcur = IDA_mem->ida_tn; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetTolScaleFactor(void *ida_mem, realtype *tolsfact) +int IDAGetTolScaleFactor(void* ida_mem, sunrealtype* tolsfact) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetTolScaleFactor", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *tolsfact = IDA_mem->ida_tolsf; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetErrWeights(void *ida_mem, N_Vector eweight) +int IDAGetErrWeights(void* ida_mem, N_Vector eweight) { IDAMem IDA_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetErrWeights", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; N_VScale(ONE, IDA_mem->ida_ewt, eweight); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetEstLocalErrors(void *ida_mem, N_Vector ele) +int IDAGetEstLocalErrors(void* ida_mem, N_Vector ele) { IDAMem IDA_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetEstLocalErrors", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; N_VScale(ONE, IDA_mem->ida_ee, ele); - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetWorkSpace(void *ida_mem, long int *lenrw, long int *leniw) +int IDAGetWorkSpace(void* ida_mem, long int* lenrw, long int* leniw) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetWorkSpace", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *leniw = IDA_mem->ida_liw; *lenrw = IDA_mem->ida_lrw; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetIntegratorStats(void *ida_mem, long int *nsteps, long int *nrevals, - long int *nlinsetups, long int *netfails, - int *klast, int *kcur, realtype *hinused, realtype *hlast, - realtype *hcur, realtype *tcur) +int IDAGetIntegratorStats(void* ida_mem, long int* nsteps, long int* nrevals, + long int* nlinsetups, long int* netfails, int* klast, + int* kcur, sunrealtype* hinused, sunrealtype* hlast, + sunrealtype* hcur, sunrealtype* tcur) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetIntegratorStats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nsteps = IDA_mem->ida_nst; *nrevals = IDA_mem->ida_nre; @@ -1260,104 +1539,125 @@ int IDAGetIntegratorStats(void *ida_mem, long int *nsteps, long int *nrevals, *hcur = IDA_mem->ida_hh; *tcur = IDA_mem->ida_tn; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumGEvals(void *ida_mem, long int *ngevals) +int IDAGetNumGEvals(void* ida_mem, long int* ngevals) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumGEvals", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *ngevals = IDA_mem->ida_nge; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetRootInfo(void *ida_mem, int *rootsfound) +int IDAGetRootInfo(void* ida_mem, int* rootsfound) { IDAMem IDA_mem; int i, nrt; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetRootInfo", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; nrt = IDA_mem->ida_nrtfn; - for (i=0; iida_iroots[i]; + for (i = 0; i < nrt; i++) { rootsfound[i] = IDA_mem->ida_iroots[i]; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumNonlinSolvIters(void *ida_mem, long int *nniters) +int IDAGetNumNonlinSolvIters(void* ida_mem, long int* nniters) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDAGetNumNonlinSolvIters", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *nniters = IDA_mem->ida_nni; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumNonlinSolvConvFails(void *ida_mem, long int *nncfails) +int IDAGetNumNonlinSolvConvFails(void* ida_mem, long int* nnfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumNonlinSolvConvFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - *nncfails = IDA_mem->ida_ncfn; + *nnfails = IDA_mem->ida_nnf; + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDAGetNonlinSolvStats(void* ida_mem, long int* nniters, long int* nnfails) +{ + IDAMem IDA_mem; - return(IDA_SUCCESS); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + + IDA_mem = (IDAMem)ida_mem; + + *nniters = IDA_mem->ida_nni; + *nnfails = IDA_mem->ida_nnf; + + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNonlinSolvStats(void *ida_mem, long int *nniters, long int *nncfails) +int IDAGetNumStepSolveFails(void* ida_mem, long int* nncfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDAGetNonlinSolvStats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - *nniters = IDA_mem->ida_nni; *nncfails = IDA_mem->ida_ncfn; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /* @@ -1368,99 +1668,109 @@ int IDAGetNonlinSolvStats(void *ida_mem, long int *nniters, long int *nncfails) /*-----------------------------------------------------------------*/ -int IDAGetQuadNumRhsEvals(void *ida_mem, long int *nrQevals) +int IDAGetQuadNumRhsEvals(void* ida_mem, long int* nrQevals) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadNumRhsEvals", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAGetQuadNumRhsEvals", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadr == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } *nrQevals = IDA_mem->ida_nrQe; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadNumErrTestFails(void *ida_mem, long int *nQetfails) +int IDAGetQuadNumErrTestFails(void* ida_mem, long int* nQetfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadNumErrTestFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAGetQuadNumErrTestFails", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadr == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } *nQetfails = IDA_mem->ida_netfQ; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadErrWeights(void *ida_mem, N_Vector eQweight) +int IDAGetQuadErrWeights(void* ida_mem, N_Vector eQweight) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadErrWeights", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAGetQuadErrWeights", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadr == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } - if(IDA_mem->ida_errconQ) - N_VScale(ONE, IDA_mem->ida_ewtQ, eQweight); + if (IDA_mem->ida_errconQ) { N_VScale(ONE, IDA_mem->ida_ewtQ, eQweight); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadStats(void *ida_mem, long int *nrQevals, long int *nQetfails) +int IDAGetQuadStats(void* ida_mem, long int* nrQevals, long int* nQetfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadStats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUAD, "IDAS", "IDAGetQuadStats", MSG_NO_QUAD); - return(IDA_NO_QUAD); + if (IDA_mem->ida_quadr == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUAD, __LINE__, __func__, __FILE__, + MSG_NO_QUAD); + return (IDA_NO_QUAD); } - *nrQevals = IDA_mem->ida_nrQe; + *nrQevals = IDA_mem->ida_nrQe; *nQetfails = IDA_mem->ida_netfQ; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* * ================================================================= * Quadrature FSA optional output functions @@ -1469,103 +1779,117 @@ int IDAGetQuadStats(void *ida_mem, long int *nrQevals, long int *nQetfails) /*-----------------------------------------------------------------*/ -int IDAGetQuadSensNumRhsEvals(void *ida_mem, long int *nrhsQSevals) +int IDAGetQuadSensNumRhsEvals(void* ida_mem, long int* nrhsQSevals) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensNumRhsEvals", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr_sensi == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensNumRhsEvals", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } *nrhsQSevals = IDA_mem->ida_nrQSe; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadSensNumErrTestFails(void *ida_mem, long int *nQSetfails) +int IDAGetQuadSensNumErrTestFails(void* ida_mem, long int* nQSetfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensNumErrTestFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr_sensi == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensNumErrTestFails", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } *nQSetfails = IDA_mem->ida_netfQS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadSensErrWeights(void *ida_mem, N_Vector *eQSweight) +int IDAGetQuadSensErrWeights(void* ida_mem, N_Vector* eQSweight) { IDAMem IDA_mem; int is, Ns; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensErrWeights", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr_sensi == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensErrWeights", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } Ns = IDA_mem->ida_Ns; if (IDA_mem->ida_errconQS) - for (is=0; isida_ewtQS[is], eQSweight[is]); + } + } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetQuadSensStats(void *ida_mem, long int *nrhsQSevals, long int *nQSetfails) +int IDAGetQuadSensStats(void* ida_mem, long int* nrhsQSevals, long int* nQSetfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetQuadSensStats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_quadr_sensi == SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_QUADSENS, "IDAS", "IDAGetQuadSensStats", MSG_NO_QUADSENSI); - return(IDA_NO_QUADSENS); + if (IDA_mem->ida_quadr_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_QUADSENS, __LINE__, __func__, __FILE__, + MSG_NO_QUADSENSI); + return (IDA_NO_QUADSENS); } *nrhsQSevals = IDA_mem->ida_nrQSe; - *nQSetfails = IDA_mem->ida_netfQS; + *nQSetfails = IDA_mem->ida_netfQS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - - /* * ================================================================= * FSA optional output functions @@ -1574,410 +1898,615 @@ int IDAGetQuadSensStats(void *ida_mem, long int *nrhsQSevals, long int *nQSetfai /*-----------------------------------------------------------------*/ -int IDAGetSensConsistentIC(void *ida_mem, N_Vector *yyS0, N_Vector *ypS0) +int IDAGetSensConsistentIC(void* ida_mem, N_Vector* yyS0, N_Vector* ypS0) { IDAMem IDA_mem; int is; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensConsistentIC", MSG_NO_MEM); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensConsistentIC", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } - if (IDA_mem->ida_kused != 0) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "IDAGetSensConsistentIC", MSG_TOO_LATE); - return(IDA_ILL_INPUT); + if (IDA_mem->ida_kused != 0) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_TOO_LATE); + return (IDA_ILL_INPUT); } - if(yyS0 != NULL) { - for (is=0; isida_Ns; is++) + if (yyS0 != NULL) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_phiS[0][is], yyS0[is]); + } } - if(ypS0 != NULL) { - for (is=0; isida_Ns; is++) + if (ypS0 != NULL) + { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_phiS[1][is], ypS0[is]); + } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNumResEvals(void *ida_mem, long int *nrSevals) +int IDAGetSensNumResEvals(void* ida_mem, long int* nrSevals) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGeSensNumResEvals", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensNumResEvals", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } *nrSevals = IDA_mem->ida_nrSe; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetNumResEvalsSens(void *ida_mem, long int *nrevalsS) +int IDAGetNumResEvalsSens(void* ida_mem, long int* nrevalsS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNumResEvalsSens", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetNumResEvalsSens", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } *nrevalsS = IDA_mem->ida_nreS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNumErrTestFails(void *ida_mem, long int *nSetfails) +int IDAGetSensNumErrTestFails(void* ida_mem, long int* nSetfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensNumErrTestFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensNumErrTestFails", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } *nSetfails = IDA_mem->ida_netfS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNumLinSolvSetups(void *ida_mem, long int *nlinsetupsS) +int IDAGetSensNumLinSolvSetups(void* ida_mem, long int* nlinsetupsS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensNumLinSolvSetups", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensNumLinSolvSetups", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } *nlinsetupsS = IDA_mem->ida_nsetupsS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensErrWeights(void *ida_mem, N_Vector_S eSweight) +int IDAGetSensErrWeights(void* ida_mem, N_Vector_S eSweight) { IDAMem IDA_mem; int is; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensErrWeights", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensErrWeights", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } - for (is=0; isida_Ns; is++) + for (is = 0; is < IDA_mem->ida_Ns; is++) + { N_VScale(ONE, IDA_mem->ida_ewtS[is], eSweight[is]); + } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensStats(void *ida_mem, long int *nrSevals, long int *nrevalsS, - long int *nSetfails, long int *nlinsetupsS) +int IDAGetSensStats(void* ida_mem, long int* nrSevals, long int* nrevalsS, + long int* nSetfails, long int* nlinsetupsS) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensStats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensStats", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } - *nrSevals = IDA_mem->ida_nrSe; - *nrevalsS = IDA_mem->ida_nreS; - *nSetfails = IDA_mem->ida_netfS; + *nrSevals = IDA_mem->ida_nrSe; + *nrevalsS = IDA_mem->ida_nreS; + *nSetfails = IDA_mem->ida_netfS; *nlinsetupsS = IDA_mem->ida_nsetupsS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNumNonlinSolvIters(void *ida_mem, long int *nSniters) +int IDAGetSensNumNonlinSolvIters(void* ida_mem, long int* nSniters) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDAGetSensNumNonlinSolvIters", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", - "IDAGetSensNumNonlinSolvIters", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } *nSniters = IDA_mem->ida_nniS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNumNonlinSolvConvFails(void *ida_mem, long int *nSncfails) +int IDAGetSensNumNonlinSolvConvFails(void* ida_mem, long int* nSnfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetSensNumNonlinSolvConvFails", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", "IDAGetSensNumNonlinSolvConvFails", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } - *nSncfails = IDA_mem->ida_ncfnS; + *nSnfails = IDA_mem->ida_nnfS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } /*-----------------------------------------------------------------*/ -int IDAGetSensNonlinSolvStats(void *ida_mem, long int *nSniters, long int *nSncfails) +int IDAGetSensNonlinSolvStats(void* ida_mem, long int* nSniters, + long int* nSnfails) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDAGetSensNonlinSolvstats", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (IDA_mem->ida_sensi==SUNFALSE) { - IDAProcessError(IDA_mem, IDA_NO_SENS, "IDAS", - "IDAGetSensNonlinSolvStats", MSG_NO_SENSI); - return(IDA_NO_SENS); + if (IDA_mem->ida_sensi == SUNFALSE) + { + IDAProcessError(IDA_mem, IDA_NO_SENS, __LINE__, __func__, __FILE__, + MSG_NO_SENSI); + return (IDA_NO_SENS); } - *nSniters = IDA_mem->ida_nniS; - *nSncfails = IDA_mem->ida_ncfnS; + *nSniters = IDA_mem->ida_nniS; + *nSnfails = IDA_mem->ida_nnfS; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } -/* - * ================================================================= - * IDAGetReturnFlagName - * ================================================================= - */ +/*-----------------------------------------------------------------*/ + +int IDAGetNumStepSensSolveFails(void* ida_mem, long int* nSncfails) +{ + IDAMem IDA_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + + IDA_mem = (IDAMem)ida_mem; + + *nSncfails = IDA_mem->ida_ncfn; + return (IDA_SUCCESS); +} -char *IDAGetReturnFlagName(long int flag) +/*-----------------------------------------------------------------*/ + +int IDAGetUserData(void* ida_mem, void** user_data) { - char *name; + IDAMem IDA_mem; - name = (char *)malloc(24*sizeof(char)); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } - switch(flag) { - case IDA_SUCCESS: - sprintf(name,"IDA_SUCCESS"); - break; - case IDA_TSTOP_RETURN: - sprintf(name,"IDA_TSTOP_RETURN"); - break; - case IDA_ROOT_RETURN: - sprintf(name,"IDA_ROOT_RETURN"); - break; - case IDA_TOO_MUCH_WORK: - sprintf(name,"IDA_TOO_MUCH_WORK"); - break; - case IDA_TOO_MUCH_ACC: - sprintf(name,"IDA_TOO_MUCH_ACC"); - break; - case IDA_ERR_FAIL: - sprintf(name,"IDA_ERR_FAIL"); - break; - case IDA_CONV_FAIL: - sprintf(name,"IDA_CONV_FAIL"); - break; - case IDA_LINIT_FAIL: - sprintf(name,"IDA_LINIT_FAIL"); - break; - case IDA_LSETUP_FAIL: - sprintf(name,"IDA_LSETUP_FAIL"); - break; - case IDA_LSOLVE_FAIL: - sprintf(name,"IDA_LSOLVE_FAIL"); - break; - case IDA_CONSTR_FAIL: - sprintf(name,"IDA_CONSTR_FAIL"); - break; - case IDA_RES_FAIL: - sprintf(name,"IDA_RES_FAIL"); - break; - case IDA_FIRST_RES_FAIL: - sprintf(name,"IDA_FIRST_RES_FAIL"); - break; - case IDA_REP_RES_ERR: - sprintf(name,"IDA_REP_RES_ERR"); - break; - case IDA_RTFUNC_FAIL: - sprintf(name,"IDA_RTFUNC_FAIL"); - break; - case IDA_MEM_FAIL: - sprintf(name,"IDA_MEM_FAIL"); - break; - case IDA_MEM_NULL: - sprintf(name,"IDA_MEM_NULL"); - break; - case IDA_ILL_INPUT: - sprintf(name,"IDA_ILL_INPUT"); - break; - case IDA_NO_MALLOC: - sprintf(name,"IDA_NO_MALLOC"); - break; - case IDA_BAD_T: - sprintf(name,"IDA_BAD_T"); - break; - case IDA_BAD_K: - sprintf(name,"IDA_BAD_K"); - break; - case IDA_BAD_DKY: - sprintf(name,"IDA_BAD_DKY"); - break; - case IDA_BAD_EWT: - sprintf(name,"IDA_BAD_EWT"); - break; - case IDA_NO_RECOVERY: - sprintf(name,"IDA_NO_RECOVERY"); - break; - case IDA_LINESEARCH_FAIL: - sprintf(name,"IDA_LINESEARCH_FAIL"); - break; - case IDA_NO_SENS: - sprintf(name,"IDA_NO_SENS"); - break; - case IDA_SRES_FAIL: - sprintf(name, "IDA_SRES_FAIL"); - break; - case IDA_REP_SRES_ERR: - sprintf(name, "IDA_REP_SRES_ERR"); - break; - case IDA_BAD_IS: - sprintf(name,"IDA_BAD_IS"); - break; - case IDA_NO_QUAD: - sprintf(name,"IDA_NO_QUAD"); - break; - case IDA_NO_QUADSENS: - sprintf(name, "IDA_NO_QUADSENS"); - break; - case IDA_QRHS_FAIL: - sprintf(name,"IDA_QRHS_FAIL"); - break; - case IDA_REP_QRHS_ERR: - sprintf(name,"IDA_REP_QRHS_ERR"); - break; - case IDA_QSRHS_FAIL: - sprintf(name, "IDA_QSRHS_FAIL"); - break; - case IDA_REP_QSRHS_ERR: - sprintf(name,"IDA_REP_QSRHS_ERR"); - break; + IDA_mem = (IDAMem)ida_mem; - /* IDAA flags follow below. */ - case IDA_NO_ADJ: - sprintf(name, "IDA_NO_ADJ"); - break; - case IDA_BAD_TB0: - sprintf(name, "IDA_BAD_TB0"); - break; - case IDA_REIFWD_FAIL: - sprintf(name, "IDA_REIFWD_FAIL"); - break; - case IDA_FWD_FAIL: - sprintf(name, "IDA_FWD_FAIL"); - break; - case IDA_GETY_BADT: - sprintf(name, "IDA_GETY_BADT"); - break; - case IDA_NO_BCK: - sprintf(name, "IDA_NO_BCK"); - break; - case IDA_NO_FWD: - sprintf(name,"IDA_NO_FWD"); - break; - case IDA_NLS_SETUP_FAIL: - sprintf(name,"IDA_NLS_SETUP_FAIL"); + *user_data = IDA_mem->ida_user_data; + + return (IDA_SUCCESS); +} + +/*-----------------------------------------------------------------*/ + +int IDAPrintAllStats(void* ida_mem, FILE* outfile, SUNOutputFormat fmt) +{ + IDAMem IDA_mem; + IDALsMem idals_mem; + + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); + } + + IDA_mem = (IDAMem)ida_mem; + + switch (fmt) + { + case SUN_OUTPUTFORMAT_TABLE: + /* step and method stats */ + fprintf(outfile, "Current time = %" RSYM "\n", + IDA_mem->ida_tn); + fprintf(outfile, "Steps = %ld\n", IDA_mem->ida_nst); + fprintf(outfile, "Error test fails = %ld\n", IDA_mem->ida_netf); + fprintf(outfile, "NLS step fails = %ld\n", IDA_mem->ida_ncfn); + fprintf(outfile, "Initial step size = %" RSYM "\n", + IDA_mem->ida_h0u); + fprintf(outfile, "Last step size = %" RSYM "\n", + IDA_mem->ida_hused); + fprintf(outfile, "Current step size = %" RSYM "\n", + IDA_mem->ida_hh); + fprintf(outfile, "Last method order = %d\n", IDA_mem->ida_kused); + fprintf(outfile, "Current method order = %d\n", IDA_mem->ida_kk); + + /* function evaluations */ + fprintf(outfile, "Residual fn evals = %ld\n", IDA_mem->ida_nre); + + /* IC calculation stats */ + fprintf(outfile, "IC linesearch backtrack ops = %d\n", IDA_mem->ida_nbacktr); + + /* nonlinear solver stats */ + fprintf(outfile, "NLS iters = %ld\n", IDA_mem->ida_nni); + fprintf(outfile, "NLS fails = %ld\n", IDA_mem->ida_nnf); + if (IDA_mem->ida_nst > 0) + { + fprintf(outfile, "NLS iters per step = %" RSYM "\n", + (sunrealtype)IDA_mem->ida_nre / (sunrealtype)IDA_mem->ida_nst); + } + + /* linear solver stats */ + fprintf(outfile, "LS setups = %ld\n", + IDA_mem->ida_nsetups); + if (IDA_mem->ida_lmem) + { + idals_mem = (IDALsMem)(IDA_mem->ida_lmem); + fprintf(outfile, "Jac fn evals = %ld\n", idals_mem->nje); + fprintf(outfile, "LS residual fn evals = %ld\n", idals_mem->nreDQ); + fprintf(outfile, "Prec setup evals = %ld\n", idals_mem->npe); + fprintf(outfile, "Prec solves = %ld\n", idals_mem->nps); + fprintf(outfile, "LS iters = %ld\n", idals_mem->nli); + fprintf(outfile, "LS fails = %ld\n", idals_mem->ncfl); + fprintf(outfile, "Jac-times setups = %ld\n", + idals_mem->njtsetup); + fprintf(outfile, "Jac-times evals = %ld\n", + idals_mem->njtimes); + if (IDA_mem->ida_nni > 0) + { + fprintf(outfile, "LS iters per NLS iter = %" RSYM "\n", + (sunrealtype)idals_mem->nli / (sunrealtype)IDA_mem->ida_nni); + fprintf(outfile, "Jac evals per NLS iter = %" RSYM "\n", + (sunrealtype)idals_mem->nje / (sunrealtype)IDA_mem->ida_nni); + fprintf(outfile, "Prec evals per NLS iter = %" RSYM "\n", + (sunrealtype)idals_mem->npe / (sunrealtype)IDA_mem->ida_nni); + } + } + + /* rootfinding stats */ + fprintf(outfile, "Root fn evals = %ld\n", IDA_mem->ida_nge); + + /* quadrature stats */ + if (IDA_mem->ida_quadr) + { + fprintf(outfile, "Quad fn evals = %ld\n", IDA_mem->ida_nrQe); + fprintf(outfile, "Quad error test fails = %ld\n", + IDA_mem->ida_netfQ); + } + + /* sensitivity stats */ + if (IDA_mem->ida_sensi) + { + fprintf(outfile, "Sens fn evals = %ld\n", IDA_mem->ida_nrSe); + fprintf(outfile, "Sens residual fn evals = %ld\n", IDA_mem->ida_nreS); + fprintf(outfile, "Sens error test fails = %ld\n", + IDA_mem->ida_netfS); + if (IDA_mem->ida_ism == IDA_STAGGERED) + { + fprintf(outfile, "Sens NLS iters = %ld\n", + IDA_mem->ida_nniS); + fprintf(outfile, "Sens NLS fails = %ld\n", + IDA_mem->ida_nnfS); + fprintf(outfile, "Sens NLS step fails = %ld\n", + IDA_mem->ida_ncfnS); + } + fprintf(outfile, "Sens LS setups = %ld\n", + IDA_mem->ida_nsetupsS); + } + + /* quadrature-sensitivity stats */ + if (IDA_mem->ida_quadr_sensi) + { + fprintf(outfile, "QuadSens residual evals = %ld\n", + IDA_mem->ida_nrQSe); + fprintf(outfile, "QuadSens error test fails = %ld\n", + IDA_mem->ida_netfQS); + } break; - case IDA_NLS_FAIL: - sprintf(name,"IDA_NLS_FAIL"); + + case SUN_OUTPUTFORMAT_CSV: + /* step and method stats */ + fprintf(outfile, "Time,%" RSYM, IDA_mem->ida_tn); + fprintf(outfile, ",Steps,%ld", IDA_mem->ida_nst); + fprintf(outfile, ",Error test fails,%ld", IDA_mem->ida_netf); + fprintf(outfile, ",NLS step fails,%ld", IDA_mem->ida_ncfn); + fprintf(outfile, ",Initial step size,%" RSYM, IDA_mem->ida_h0u); + fprintf(outfile, ",Last step size,%" RSYM, IDA_mem->ida_hused); + fprintf(outfile, ",Current step size,%" RSYM, IDA_mem->ida_hh); + fprintf(outfile, ",Last method order,%d", IDA_mem->ida_kused); + fprintf(outfile, ",Current method order,%d", IDA_mem->ida_kk); + + /* function evaluations */ + fprintf(outfile, ",Residual fn evals,%ld", IDA_mem->ida_nre); + + /* IC calculation stats */ + fprintf(outfile, ",IC linesearch backtrack ops,%d", IDA_mem->ida_nbacktr); + + /* nonlinear solver stats */ + fprintf(outfile, ",NLS iters,%ld", IDA_mem->ida_nni); + fprintf(outfile, ",NLS fails,%ld", IDA_mem->ida_nnf); + if (IDA_mem->ida_nst > 0) + { + fprintf(outfile, ",NLS iters per step,%" RSYM, + (sunrealtype)IDA_mem->ida_nre / (sunrealtype)IDA_mem->ida_nst); + } + else { fprintf(outfile, ",NLS iters per step,0"); } + + /* linear solver stats */ + fprintf(outfile, ",LS setups,%ld", IDA_mem->ida_nsetups); + if (IDA_mem->ida_lmem) + { + idals_mem = (IDALsMem)(IDA_mem->ida_lmem); + fprintf(outfile, ",Jac fn evals,%ld", idals_mem->nje); + fprintf(outfile, ",LS residual evals,%ld", idals_mem->nreDQ); + fprintf(outfile, ",Prec setup evals,%ld", idals_mem->npe); + fprintf(outfile, ",Prec solves,%ld", idals_mem->nps); + fprintf(outfile, ",LS iters,%ld", idals_mem->nli); + fprintf(outfile, ",LS fails,%ld", idals_mem->ncfl); + fprintf(outfile, ",Jac-times setups,%ld", idals_mem->njtsetup); + fprintf(outfile, ",Jac-times evals,%ld", idals_mem->njtimes); + if (IDA_mem->ida_nni > 0) + { + fprintf(outfile, ",LS iters per NLS iter,%" RSYM, + (sunrealtype)idals_mem->nli / (sunrealtype)IDA_mem->ida_nni); + fprintf(outfile, ",Jac evals per NLS iter,%" RSYM, + (sunrealtype)idals_mem->nje / (sunrealtype)IDA_mem->ida_nni); + fprintf(outfile, ",Prec evals per NLS iter,%" RSYM, + (sunrealtype)idals_mem->npe / (sunrealtype)IDA_mem->ida_nni); + } + else + { + fprintf(outfile, ",LS iters per NLS iter,0"); + fprintf(outfile, ",Jac evals per NLS iter,0"); + fprintf(outfile, ",Prec evals per NLS iter,0"); + } + } + + /* rootfinding stats */ + fprintf(outfile, ",Root fn evals,%ld", IDA_mem->ida_nge); + + /* quadrature stats */ + if (IDA_mem->ida_quadr) + { + fprintf(outfile, ",Quad fn evals,%ld", IDA_mem->ida_nrQe); + fprintf(outfile, ",Quad error test fails,%ld", IDA_mem->ida_netfQ); + } + + /* sensitivity stats */ + if (IDA_mem->ida_sensi) + { + fprintf(outfile, ",Sens fn evals,%ld", IDA_mem->ida_nrSe); + fprintf(outfile, ",Sens residual fn evals,%ld", IDA_mem->ida_nreS); + fprintf(outfile, ",Sens error test fails,%ld", IDA_mem->ida_netfS); + if (IDA_mem->ida_ism == IDA_STAGGERED) + { + fprintf(outfile, ",Sens NLS iters,%ld", IDA_mem->ida_nniS); + fprintf(outfile, ",Sens NLS fails,%ld", IDA_mem->ida_nnfS); + fprintf(outfile, ",Sens NLS step fails,%ld", IDA_mem->ida_ncfnS); + } + fprintf(outfile, ",Sens LS setups,%ld", IDA_mem->ida_nsetupsS); + } + + /* quadrature-sensitivity stats */ + if (IDA_mem->ida_quadr_sensi) + { + fprintf(outfile, ",QuadSens residual evals,%ld", IDA_mem->ida_nrQSe); + fprintf(outfile, ",QuadSens error test fails,%ld", IDA_mem->ida_netfQS); + } + fprintf(outfile, "\n"); break; + default: - sprintf(name,"NONE"); + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, + "Invalid formatting option."); + return (IDA_ILL_INPUT); } - return(name); + return (IDA_SUCCESS); +} + +/* + * ================================================================= + * IDAGetReturnFlagName + * ================================================================= + */ + +char* IDAGetReturnFlagName(long int flag) +{ + char* name; + + name = (char*)malloc(24 * sizeof(char)); + + switch (flag) + { + case IDA_SUCCESS: sprintf(name, "IDA_SUCCESS"); break; + case IDA_TSTOP_RETURN: sprintf(name, "IDA_TSTOP_RETURN"); break; + case IDA_ROOT_RETURN: sprintf(name, "IDA_ROOT_RETURN"); break; + case IDA_TOO_MUCH_WORK: sprintf(name, "IDA_TOO_MUCH_WORK"); break; + case IDA_TOO_MUCH_ACC: sprintf(name, "IDA_TOO_MUCH_ACC"); break; + case IDA_ERR_FAIL: sprintf(name, "IDA_ERR_FAIL"); break; + case IDA_CONV_FAIL: sprintf(name, "IDA_CONV_FAIL"); break; + case IDA_LINIT_FAIL: sprintf(name, "IDA_LINIT_FAIL"); break; + case IDA_LSETUP_FAIL: sprintf(name, "IDA_LSETUP_FAIL"); break; + case IDA_LSOLVE_FAIL: sprintf(name, "IDA_LSOLVE_FAIL"); break; + case IDA_CONSTR_FAIL: sprintf(name, "IDA_CONSTR_FAIL"); break; + case IDA_RES_FAIL: sprintf(name, "IDA_RES_FAIL"); break; + case IDA_FIRST_RES_FAIL: sprintf(name, "IDA_FIRST_RES_FAIL"); break; + case IDA_REP_RES_ERR: sprintf(name, "IDA_REP_RES_ERR"); break; + case IDA_RTFUNC_FAIL: sprintf(name, "IDA_RTFUNC_FAIL"); break; + case IDA_MEM_FAIL: sprintf(name, "IDA_MEM_FAIL"); break; + case IDA_MEM_NULL: sprintf(name, "IDA_MEM_NULL"); break; + case IDA_ILL_INPUT: sprintf(name, "IDA_ILL_INPUT"); break; + case IDA_NO_MALLOC: sprintf(name, "IDA_NO_MALLOC"); break; + case IDA_BAD_T: sprintf(name, "IDA_BAD_T"); break; + case IDA_BAD_K: sprintf(name, "IDA_BAD_K"); break; + case IDA_BAD_DKY: sprintf(name, "IDA_BAD_DKY"); break; + case IDA_BAD_EWT: sprintf(name, "IDA_BAD_EWT"); break; + case IDA_NO_RECOVERY: sprintf(name, "IDA_NO_RECOVERY"); break; + case IDA_LINESEARCH_FAIL: sprintf(name, "IDA_LINESEARCH_FAIL"); break; + case IDA_NO_SENS: sprintf(name, "IDA_NO_SENS"); break; + case IDA_SRES_FAIL: sprintf(name, "IDA_SRES_FAIL"); break; + case IDA_REP_SRES_ERR: sprintf(name, "IDA_REP_SRES_ERR"); break; + case IDA_BAD_IS: sprintf(name, "IDA_BAD_IS"); break; + case IDA_NO_QUAD: sprintf(name, "IDA_NO_QUAD"); break; + case IDA_NO_QUADSENS: sprintf(name, "IDA_NO_QUADSENS"); break; + case IDA_QRHS_FAIL: sprintf(name, "IDA_QRHS_FAIL"); break; + case IDA_REP_QRHS_ERR: sprintf(name, "IDA_REP_QRHS_ERR"); break; + case IDA_QSRHS_FAIL: sprintf(name, "IDA_QSRHS_FAIL"); break; + case IDA_REP_QSRHS_ERR: + sprintf(name, "IDA_REP_QSRHS_ERR"); + break; + + /* IDAA flags follow below. */ + case IDA_NO_ADJ: sprintf(name, "IDA_NO_ADJ"); break; + case IDA_BAD_TB0: sprintf(name, "IDA_BAD_TB0"); break; + case IDA_REIFWD_FAIL: sprintf(name, "IDA_REIFWD_FAIL"); break; + case IDA_FWD_FAIL: sprintf(name, "IDA_FWD_FAIL"); break; + case IDA_GETY_BADT: sprintf(name, "IDA_GETY_BADT"); break; + case IDA_NO_BCK: sprintf(name, "IDA_NO_BCK"); break; + case IDA_NO_FWD: sprintf(name, "IDA_NO_FWD"); break; + case IDA_NLS_SETUP_FAIL: sprintf(name, "IDA_NLS_SETUP_FAIL"); break; + case IDA_NLS_FAIL: sprintf(name, "IDA_NLS_FAIL"); break; + default: sprintf(name, "NONE"); + } + + return (name); } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls.c index 41354095e..088bcbb01 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls.c @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,111 +18,101 @@ #include #include #include - -#include "idas_impl.h" -#include "idas_ls_impl.h" -#include #include +#include #include #include #include -/* constants */ -#define MAX_ITERS 3 /* max. number of attempts to recover in DQ J*v */ -#define ZERO RCONST(0.0) -#define PT25 RCONST(0.25) -#define PT05 RCONST(0.05) -#define PT9 RCONST(0.9) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#include "idas_impl.h" +#include "idas_ls_impl.h" +/* constants */ +#define MAX_ITERS 3 /* max. number of attempts to recover in DQ J*v */ +#define ZERO SUN_RCONST(0.0) +#define PT25 SUN_RCONST(0.25) +#define PT05 SUN_RCONST(0.05) +#define PT9 SUN_RCONST(0.9) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /*================================================================= PRIVATE FUNCTION PROTOTYPES =================================================================*/ -static int idaLsJacBWrapper(realtype tt, realtype c_jB, N_Vector yyB, +static int idaLsJacBWrapper(sunrealtype tt, sunrealtype c_jB, N_Vector yyB, N_Vector ypB, N_Vector rBr, SUNMatrix JacB, - void *ida_mem, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); -static int idaLsJacBSWrapper(realtype tt, realtype c_jB, N_Vector yyB, + void* ida_mem, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B); +static int idaLsJacBSWrapper(sunrealtype tt, sunrealtype c_jB, N_Vector yyB, N_Vector ypB, N_Vector rBr, SUNMatrix JacB, - void *ida_mem, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B); - -static int idaLsPrecSetupB(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *idaadj_mem); -static int idaLsPrecSetupBS(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *idaadj_mem); - -static int idaLsPrecSolveB(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector rvecB, N_Vector zvecB, - realtype c_jB, realtype deltaB, - void *idaadj_mem); -static int idaLsPrecSolveBS(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector rvecB, N_Vector zvecB, - realtype c_jB, realtype deltaB, - void *idaadj_mem); - -static int idaLsJacTimesSetupB(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *idaadj_mem); -static int idaLsJacTimesSetupBS(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - realtype c_jB, void *idaadj_mem); - -static int idaLsJacTimesVecB(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector vB, N_Vector JvB, - realtype c_jB, void *idaadj_mem, - N_Vector tmp1B, N_Vector tmp2B); -static int idaLsJacTimesVecBS(realtype tt, N_Vector yyB, - N_Vector ypB, N_Vector rrB, - N_Vector vB, N_Vector JvB, - realtype c_jB, void *idaadj_mem, + void* ida_mem, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B); + +static int idaLsPrecSetupB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* idaadj_mem); +static int idaLsPrecSetupBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* idaadj_mem); + +static int idaLsPrecSolveB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector rvecB, N_Vector zvecB, + sunrealtype c_jB, sunrealtype deltaB, + void* idaadj_mem); +static int idaLsPrecSolveBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector rvecB, N_Vector zvecB, + sunrealtype c_jB, sunrealtype deltaB, + void* idaadj_mem); + +static int idaLsJacTimesSetupB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* idaadj_mem); +static int idaLsJacTimesSetupBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* idaadj_mem); + +static int idaLsJacTimesVecB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector vB, N_Vector JvB, + sunrealtype c_jB, void* idaadj_mem, N_Vector tmp1B, + N_Vector tmp2B); +static int idaLsJacTimesVecBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector vB, N_Vector JvB, + sunrealtype c_jB, void* idaadj_mem, N_Vector tmp1B, N_Vector tmp2B); - /*================================================================ PART I - forward problems ================================================================*/ - /*--------------------------------------------------------------- IDASetLinearSolver specifies the linear solver ---------------------------------------------------------------*/ -int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) +int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) { - IDAMem IDA_mem; - IDALsMem idals_mem; - int retval, LSType; - booleantype iterative; /* is the solver iterative? */ - booleantype matrixbased; /* is a matrix structure used? */ + IDAMem IDA_mem; + IDALsMem idals_mem; + int retval, LSType; + sunbooleantype iterative; /* is the solver iterative? */ + sunbooleantype matrixbased; /* is a matrix structure used? */ /* Return immediately if any input is NULL */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - "IDASetLinearSolver", MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); - } - if (LS == NULL) { - IDAProcessError(NULL, IDALS_ILL_INPUT, "IDASLS", - "IDASetLinearSolver", + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); + } + if (LS == NULL) + { + IDAProcessError(NULL, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, "LS must be non-NULL"); - return(IDALS_ILL_INPUT); + return (IDALS_ILL_INPUT); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Test if solver is compatible with LS interface */ - if ( (LS->ops->gettype == NULL) || (LS->ops->solve == NULL) ) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetLinearSolver", - "LS object is missing a required operation"); - return(IDALS_ILL_INPUT); + if ((LS->ops->gettype == NULL) || (LS->ops->solve == NULL)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + "LS object is missing a required operation"); + return (IDALS_ILL_INPUT); } /* Retrieve the LS type */ @@ -135,59 +125,65 @@ int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) /* Test if vector is compatible with LS interface */ if (IDA_mem->ida_tempv1->ops->nvconst == NULL || - IDA_mem->ida_tempv1->ops->nvwrmsnorm == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetLinearSolver", MSG_LS_BAD_NVECTOR); - return(IDALS_ILL_INPUT); + IDA_mem->ida_tempv1->ops->nvwrmsnorm == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (IDALS_ILL_INPUT); } /* Ensure that A is NULL when LS is matrix-embedded */ - if ((LSType == SUNLINEARSOLVER_MATRIX_EMBEDDED) && (A != NULL)) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetLinearSolver", - "Incompatible inputs: matrix-embedded LS requires NULL matrix"); - return(IDALS_ILL_INPUT); + if ((LSType == SUNLINEARSOLVER_MATRIX_EMBEDDED) && (A != NULL)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: matrix-embedded LS requires NULL matrix"); + return (IDALS_ILL_INPUT); } /* Check for compatible LS type, matrix and "atimes" support */ - if (iterative) { - - if (IDA_mem->ida_tempv1->ops->nvgetlength == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetLinearSolver", MSG_LS_BAD_NVECTOR); - return(IDALS_ILL_INPUT); + if (iterative) + { + if (IDA_mem->ida_tempv1->ops->nvgetlength == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (IDALS_ILL_INPUT); } - if (LSType != SUNLINEARSOLVER_MATRIX_EMBEDDED) { - if (LS->ops->resid == NULL || LS->ops->numiters == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetLinearSolver", - "Iterative LS object requires 'resid' and 'numiters' routines"); - return(IDALS_ILL_INPUT); + if (LSType != SUNLINEARSOLVER_MATRIX_EMBEDDED) + { + if (LS->ops->resid == NULL || LS->ops->numiters == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Iterative LS object requires 'resid' and 'numiters' routines"); + return (IDALS_ILL_INPUT); } } if (!matrixbased && (LSType != SUNLINEARSOLVER_MATRIX_EMBEDDED) && - (LS->ops->setatimes == NULL)) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetLinearSolver", - "Incompatible inputs: iterative LS must support ATimes routine"); - return(IDALS_ILL_INPUT); + (LS->ops->setatimes == NULL)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: iterative LS must support ATimes routine"); + return (IDALS_ILL_INPUT); } - if (matrixbased && (A == NULL)) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetLinearSolver", - "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); - return(IDALS_ILL_INPUT); + if (matrixbased && (A == NULL)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); + return (IDALS_ILL_INPUT); } - - } else if (A == NULL) { - - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetLinearSolver", + } + else if (A == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, "Incompatible inputs: direct LS requires non-NULL matrix"); - return(IDALS_ILL_INPUT); - + return (IDALS_ILL_INPUT); } /* free any existing system solver attached to IDA */ - if (IDA_mem->ida_lfree) IDA_mem->ida_lfree(IDA_mem); + if (IDA_mem->ida_lfree) { IDA_mem->ida_lfree(IDA_mem); } /* Set four main system linear solver function fields in IDA_mem */ IDA_mem->ida_linit = idaLsInitialize; @@ -200,11 +196,12 @@ int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) /* Allocate memory for IDALsMemRec */ idals_mem = NULL; - idals_mem = (IDALsMem) malloc(sizeof(struct IDALsMemRec)); - if (idals_mem == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASLS", - "IDASetLinearSolver", MSG_LS_MEM_FAIL); - return(IDALS_MEM_FAIL); + idals_mem = (IDALsMem)malloc(sizeof(struct IDALsMemRec)); + if (idals_mem == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + return (IDALS_MEM_FAIL); } memset(idals_mem, 0, sizeof(struct IDALsMemRec)); @@ -217,14 +214,17 @@ int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) /* Set defaults for Jacobian-related fields */ idals_mem->J = A; - if (A != NULL) { - idals_mem->jacDQ = SUNTRUE; - idals_mem->jac = idaLsDQJac; - idals_mem->J_data = IDA_mem; - } else { - idals_mem->jacDQ = SUNFALSE; - idals_mem->jac = NULL; - idals_mem->J_data = NULL; + if (A != NULL) + { + idals_mem->jacDQ = SUNTRUE; + idals_mem->jac = idaLsDQJac; + idals_mem->J_data = IDA_mem; + } + else + { + idals_mem->jacDQ = SUNFALSE; + idals_mem->jac = NULL; + idals_mem->J_data = NULL; } idals_mem->jtimesDQ = SUNTRUE; idals_mem->jtsetup = NULL; @@ -247,289 +247,298 @@ int IDASetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A) idals_mem->last_flag = IDALS_SUCCESS; /* If LS supports ATimes, attach IDALs routine */ - if (LS->ops->setatimes) { + if (LS->ops->setatimes) + { retval = SUNLinSolSetATimes(LS, IDA_mem, idaLsATimes); - if (retval != SUNLS_SUCCESS) { - IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", - "IDASetLinearSolver", + if (retval != SUN_SUCCESS) + { + IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetATimes"); - free(idals_mem); idals_mem = NULL; - return(IDALS_SUNLS_FAIL); + free(idals_mem); + idals_mem = NULL; + return (IDALS_SUNLS_FAIL); } } /* If LS supports preconditioning, initialize pset/psol to NULL */ - if (LS->ops->setpreconditioner) { + if (LS->ops->setpreconditioner) + { retval = SUNLinSolSetPreconditioner(LS, IDA_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) { - IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", - "IDASetLinearSolver", + if (retval != SUN_SUCCESS) + { + IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); - free(idals_mem); idals_mem = NULL; - return(IDALS_SUNLS_FAIL); + free(idals_mem); + idals_mem = NULL; + return (IDALS_SUNLS_FAIL); } } /* Allocate memory for ytemp, yptemp and x */ idals_mem->ytemp = N_VClone(IDA_mem->ida_tempv1); - if (idals_mem->ytemp == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASLS", - "IDASetLinearSolver", MSG_LS_MEM_FAIL); - free(idals_mem); idals_mem = NULL; - return(IDALS_MEM_FAIL); + if (idals_mem->ytemp == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + free(idals_mem); + idals_mem = NULL; + return (IDALS_MEM_FAIL); } idals_mem->yptemp = N_VClone(IDA_mem->ida_tempv1); - if (idals_mem->yptemp == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASLS", - "IDASetLinearSolver", MSG_LS_MEM_FAIL); + if (idals_mem->yptemp == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); N_VDestroy(idals_mem->ytemp); - free(idals_mem); idals_mem = NULL; - return(IDALS_MEM_FAIL); + free(idals_mem); + idals_mem = NULL; + return (IDALS_MEM_FAIL); } idals_mem->x = N_VClone(IDA_mem->ida_tempv1); - if (idals_mem->x == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASLS", - "IDASetLinearSolver", MSG_LS_MEM_FAIL); + if (idals_mem->x == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); N_VDestroy(idals_mem->ytemp); N_VDestroy(idals_mem->yptemp); - free(idals_mem); idals_mem = NULL; - return(IDALS_MEM_FAIL); + free(idals_mem); + idals_mem = NULL; + return (IDALS_MEM_FAIL); } /* For iterative LS, compute sqrtN */ if (iterative) - idals_mem->nrmfac = SUNRsqrt( N_VGetLength(idals_mem->ytemp) ); + { + idals_mem->nrmfac = SUNRsqrt(N_VGetLength(idals_mem->ytemp)); + } - /* For matrix-based LS, enable soltuion scaling */ - if (matrixbased) - idals_mem->scalesol = SUNTRUE; - else - idals_mem->scalesol = SUNFALSE; + /* For matrix-based LS, enable solution scaling */ + if (matrixbased) { idals_mem->scalesol = SUNTRUE; } + else { idals_mem->scalesol = SUNFALSE; } /* Attach linear solver memory to integrator memory */ IDA_mem->ida_lmem = idals_mem; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*=============================================================== - Optional input/output routines + Optional Set routines ===============================================================*/ - /* IDASetJacFn specifies the Jacobian function */ -int IDASetJacFn(void *ida_mem, IDALsJacFn jac) +int IDASetJacFn(void* ida_mem, IDALsJacFn jac) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDALsSetJacFn", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* return with failure if jac cannot be used */ - if ((jac != NULL) && (idals_mem->J == NULL)) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetJacFn", + if ((jac != NULL) && (idals_mem->J == NULL)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, "Jacobian routine cannot be supplied for NULL SUNMatrix"); - return(IDALS_ILL_INPUT); + return (IDALS_ILL_INPUT); } /* set Jacobian routine pointer, and update relevant flags */ - if (jac != NULL) { + if (jac != NULL) + { idals_mem->jacDQ = SUNFALSE; idals_mem->jac = jac; idals_mem->J_data = IDA_mem->ida_user_data; - } else { + } + else + { idals_mem->jacDQ = SUNTRUE; idals_mem->jac = idaLsDQJac; idals_mem->J_data = IDA_mem; } - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetEpsLin specifies the nonlinear -> linear tolerance scale factor */ -int IDASetEpsLin(void *ida_mem, realtype eplifac) +int IDASetEpsLin(void* ida_mem, sunrealtype eplifac) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetEpsLin", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* Check for legal eplifac */ - if (eplifac < ZERO) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetEpsLin", MSG_LS_NEG_EPLIFAC); - return(IDALS_ILL_INPUT); + if (eplifac < ZERO) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_NEG_EPLIFAC); + return (IDALS_ILL_INPUT); } idals_mem->eplifac = (eplifac == ZERO) ? PT05 : eplifac; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetWRMSNormFactor sets or computes the factor to use when converting from the integrator tolerance to the linear solver tolerance (WRMS to L2 norm). */ -int IDASetLSNormFactor(void *ida_mem, realtype nrmfac) +int IDASetLSNormFactor(void* ida_mem, sunrealtype nrmfac) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetLSNormFactor", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } - if (nrmfac > ZERO) { + if (nrmfac > ZERO) + { /* user-provided factor */ idals_mem->nrmfac = nrmfac; - } else if (nrmfac < ZERO) { + } + else if (nrmfac < ZERO) + { /* compute factor for WRMS norm with dot product */ N_VConst(ONE, idals_mem->ytemp); idals_mem->nrmfac = SUNRsqrt(N_VDotProd(idals_mem->ytemp, idals_mem->ytemp)); - } else { + } + else + { /* compute default factor for WRMS norm from vector legnth */ idals_mem->nrmfac = SUNRsqrt(N_VGetLength(idals_mem->ytemp)); } - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetLinearSolutionScaling enables or disables scaling the linear solver solution to account for changes in cj. */ -int IDASetLinearSolutionScaling(void *ida_mem, booleantype onoff) +int IDASetLinearSolutionScaling(void* ida_mem, sunbooleantype onoff) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetLinearSolutionScaling", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* check for valid solver type */ - if (!(idals_mem->matrixbased)) return(IDALS_ILL_INPUT); + if (!(idals_mem->matrixbased)) { return (IDALS_ILL_INPUT); } /* set solution scaling flag */ idals_mem->scalesol = onoff; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetIncrementFactor specifies increment factor for DQ approximations to Jv */ -int IDASetIncrementFactor(void *ida_mem, realtype dqincfac) +int IDASetIncrementFactor(void* ida_mem, sunrealtype dqincfac) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetIncrementFactor", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* Check for legal dqincfac */ - if (dqincfac <= ZERO) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetIncrementFactor", MSG_LS_NEG_DQINCFAC); - return(IDALS_ILL_INPUT); + if (dqincfac <= ZERO) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_NEG_DQINCFAC); + return (IDALS_ILL_INPUT); } idals_mem->dqincfac = dqincfac; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetPreconditioner specifies the user-supplied psetup and psolve routines */ -int IDASetPreconditioner(void *ida_mem, - IDALsPrecSetupFn psetup, +int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn psetup, IDALsPrecSolveFn psolve) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - PSetupFn idals_psetup; - PSolveFn idals_psolve; - int retval; + SUNPSetupFn idals_psetup; + SUNPSolveFn idals_psolve; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetPreconditioner", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* store function pointers for user-supplied routines in IDALs interface */ idals_mem->pset = psetup; idals_mem->psolve = psolve; /* issue error if LS object does not allow user-supplied preconditioning */ - if (idals_mem->LS->ops->setpreconditioner == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetPreconditioner", - "SUNLinearSolver object does not support user-supplied preconditioning"); - return(IDALS_ILL_INPUT); + if (idals_mem->LS->ops->setpreconditioner == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + "SUNLinearSolver object does not support user-supplied " + "preconditioning"); + return (IDALS_ILL_INPUT); } /* notify iterative linear solver to call IDALs interface routines */ idals_psetup = (psetup == NULL) ? NULL : idaLsPSetup; idals_psolve = (psolve == NULL) ? NULL : idaLsPSolve; - retval = SUNLinSolSetPreconditioner(idals_mem->LS, IDA_mem, - idals_psetup, idals_psolve); - if (retval != SUNLS_SUCCESS) { - IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", - "IDASetPreconditioner", + retval = SUNLinSolSetPreconditioner(idals_mem->LS, IDA_mem, idals_psetup, + idals_psolve); + if (retval != SUN_SUCCESS) + { + IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); - return(IDALS_SUNLS_FAIL); + return (IDALS_SUNLS_FAIL); } - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetJacTimes specifies the user-supplied Jacobian-vector product setup and multiply routines */ -int IDASetJacTimes(void *ida_mem, IDALsJacTimesSetupFn jtsetup, +int IDASetJacTimes(void* ida_mem, IDALsJacTimesSetupFn jtsetup, IDALsJacTimesVecFn jtimes) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetJacTimes", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* issue error if LS object does not allow user-supplied ATimes */ - if (idals_mem->LS->ops->setatimes == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetJacTimes", - "SUNLinearSolver object does not support user-supplied ATimes routine"); - return(IDALS_ILL_INPUT); + if (idals_mem->LS->ops->setatimes == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "SUNLinearSolver object does not support user-supplied ATimes routine"); + return (IDALS_ILL_INPUT); } /* store function pointers for user-supplied routines in IDALs interface (NULL jtimes implies use of DQ default) */ - if (jtimes != NULL) { + if (jtimes != NULL) + { idals_mem->jtimesDQ = SUNFALSE; idals_mem->jtsetup = jtsetup; idals_mem->jtimes = jtimes; idals_mem->jt_data = IDA_mem->ida_user_data; - } else { + } + else + { idals_mem->jtimesDQ = SUNTRUE; idals_mem->jtsetup = NULL; idals_mem->jtimes = idaLsDQJtimes; @@ -537,275 +546,288 @@ int IDASetJacTimes(void *ida_mem, IDALsJacTimesSetupFn jtsetup, idals_mem->jt_data = IDA_mem; } - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDASetJacTimesResFn specifies an alternative user-supplied DAE residual function to use in the internal finite difference Jacobian-vector product */ -int IDASetJacTimesResFn(void *ida_mem, IDAResFn jtimesResFn) +int IDASetJacTimesResFn(void* ida_mem, IDAResFn jtimesResFn) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDASetJacTimesResFn", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* check if using internal finite difference approximation */ - if (!(idals_mem->jtimesDQ)) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "IDASetJacTimesResFn", - "Internal finite-difference Jacobian-vector product is disabled."); - return(IDALS_ILL_INPUT); + if (!(idals_mem->jtimesDQ)) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Internal finite-difference Jacobian-vector product is disabled."); + return (IDALS_ILL_INPUT); } /* store function pointers for Res function (NULL implies use DAE Res) */ - if (jtimesResFn != NULL) - idals_mem->jt_res = jtimesResFn; - else - idals_mem->jt_res = IDA_mem->ida_res; + if (jtimesResFn != NULL) { idals_mem->jt_res = jtimesResFn; } + else { idals_mem->jt_res = IDA_mem->ida_res; } + + return (IDALS_SUCCESS); +} + +/*=============================================================== + Optional Get routines + ===============================================================*/ + +int IDAGetJac(void* ida_mem, SUNMatrix* J) +{ + IDAMem IDA_mem; + IDALsMem idals_mem; + int retval; + + /* access IDALsMem structure; set output and return */ + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return retval; } + *J = idals_mem->J; + return IDALS_SUCCESS; +} + +int IDAGetJacCj(void* ida_mem, sunrealtype* cj_J) +{ + IDAMem IDA_mem; + IDALsMem idals_mem; + int retval; - return(IDALS_SUCCESS); + /* access IDALsMem structure; set output and return */ + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return retval; } + *cj_J = IDA_mem->ida_cjold; + return IDALS_SUCCESS; } +int IDAGetJacTime(void* ida_mem, sunrealtype* t_J) +{ + IDAMem IDA_mem; + IDALsMem idals_mem; + int retval; + + /* access IDALsMem structure; set output and return */ + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return retval; } + *t_J = idals_mem->tnlj; + return IDALS_SUCCESS; +} + +int IDAGetJacNumSteps(void* ida_mem, long int* nst_J) +{ + IDAMem IDA_mem; + IDALsMem idals_mem; + int retval; + + /* access IDALsMem structure; set output and return */ + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return retval; } + *nst_J = idals_mem->nstlj; + return IDALS_SUCCESS; +} /* IDAGetLinWorkSpace returns the length of workspace allocated for the IDALS linear solver interface */ -int IDAGetLinWorkSpace(void *ida_mem, long int *lenrwLS, - long int *leniwLS) +int IDAGetLinWorkSpace(void* ida_mem, long int* lenrwLS, long int* leniwLS) { - IDAMem IDA_mem; - IDALsMem idals_mem; + IDAMem IDA_mem; + IDALsMem idals_mem; sunindextype lrw1, liw1; - long int lrw, liw; - int retval; + long int lrw, liw; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetLinWorkSpace", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* start with fixed sizes plus vector/matrix pointers */ *lenrwLS = 3; *leniwLS = 34; /* add N_Vector sizes */ - if (IDA_mem->ida_tempv1->ops->nvspace) { + if (IDA_mem->ida_tempv1->ops->nvspace) + { N_VSpace(IDA_mem->ida_tempv1, &lrw1, &liw1); - *lenrwLS += 3*lrw1; - *leniwLS += 3*liw1; + *lenrwLS += 3 * lrw1; + *leniwLS += 3 * liw1; } /* add LS sizes */ - if (idals_mem->LS->ops->space) { + if (idals_mem->LS->ops->space) + { retval = SUNLinSolSpace(idals_mem->LS, &lrw, &liw); - if (retval == 0) { + if (retval == 0) + { *lenrwLS += lrw; *leniwLS += liw; } } - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumJacEvals returns the number of Jacobian evaluations */ -int IDAGetNumJacEvals(void *ida_mem, long int *njevals) +int IDAGetNumJacEvals(void* ida_mem, long int* njevals) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumJacEvals", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *njevals = idals_mem->nje; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumPrecEvals returns the number of preconditioner evaluations */ -int IDAGetNumPrecEvals(void *ida_mem, long int *npevals) +int IDAGetNumPrecEvals(void* ida_mem, long int* npevals) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumPrecEvals", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *npevals = idals_mem->npe; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumPrecSolves returns the number of preconditioner solves */ -int IDAGetNumPrecSolves(void *ida_mem, long int *npsolves) +int IDAGetNumPrecSolves(void* ida_mem, long int* npsolves) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumPrecSolves", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *npsolves = idals_mem->nps; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumLinIters returns the number of linear iterations */ -int IDAGetNumLinIters(void *ida_mem, long int *nliters) +int IDAGetNumLinIters(void* ida_mem, long int* nliters) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumLinIters", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *nliters = idals_mem->nli; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumLinConvFails returns the number of linear convergence failures */ -int IDAGetNumLinConvFails(void *ida_mem, long int *nlcfails) +int IDAGetNumLinConvFails(void* ida_mem, long int* nlcfails) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumLinConvFails", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *nlcfails = idals_mem->ncfl; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumJTSetupEvals returns the number of calls to the user-supplied Jacobian-vector product setup routine */ -int IDAGetNumJTSetupEvals(void *ida_mem, long int *njtsetups) +int IDAGetNumJTSetupEvals(void* ida_mem, long int* njtsetups) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumJTSetupEvals", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *njtsetups = idals_mem->njtsetup; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumJtimesEvals returns the number of calls to the Jacobian-vector product multiply routine */ -int IDAGetNumJtimesEvals(void *ida_mem, long int *njvevals) +int IDAGetNumJtimesEvals(void* ida_mem, long int* njvevals) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumJtimesEvals", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *njvevals = idals_mem->njtimes; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetNumLinResEvals returns the number of calls to the DAE residual needed for the DQ Jacobian approximation or J*v product approximation */ -int IDAGetNumLinResEvals(void *ida_mem, long int *nrevalsLS) +int IDAGetNumLinResEvals(void* ida_mem, long int* nrevalsLS) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetNumLinResEvals", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *nrevalsLS = idals_mem->nreDQ; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetLastLinFlag returns the last flag set in a IDALS function */ -int IDAGetLastLinFlag(void *ida_mem, long int *flag) +int IDAGetLastLinFlag(void* ida_mem, long int* flag) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure; store output and return */ - retval = idaLs_AccessLMem(ida_mem, "IDAGetLastLinFlag", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } *flag = idals_mem->last_flag; - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* IDAGetLinReturnFlagName translates from the integer error code returned by an IDALs routine to the corresponding string equivalent for that flag */ -char *IDAGetLinReturnFlagName(long int flag) +char* IDAGetLinReturnFlagName(long int flag) { - char *name = (char *)malloc(30*sizeof(char)); - - switch(flag) { - case IDALS_SUCCESS: - sprintf(name,"IDALS_SUCCESS"); - break; - case IDALS_MEM_NULL: - sprintf(name,"IDALS_MEM_NULL"); - break; - case IDALS_LMEM_NULL: - sprintf(name,"IDALS_LMEM_NULL"); - break; - case IDALS_ILL_INPUT: - sprintf(name,"IDALS_ILL_INPUT"); - break; - case IDALS_MEM_FAIL: - sprintf(name,"IDALS_MEM_FAIL"); - break; - case IDALS_PMEM_NULL: - sprintf(name,"IDALS_PMEM_NULL"); - break; - case IDALS_JACFUNC_UNRECVR: - sprintf(name,"IDALS_JACFUNC_UNRECVR"); - break; - case IDALS_JACFUNC_RECVR: - sprintf(name,"IDALS_JACFUNC_RECVR"); - break; - case IDALS_SUNMAT_FAIL: - sprintf(name,"IDALS_SUNMAT_FAIL"); - break; - case IDALS_SUNLS_FAIL: - sprintf(name,"IDALS_SUNLS_FAIL"); - break; - default: - sprintf(name,"NONE"); - } - - return(name); + char* name = (char*)malloc(30 * sizeof(char)); + + switch (flag) + { + case IDALS_SUCCESS: sprintf(name, "IDALS_SUCCESS"); break; + case IDALS_MEM_NULL: sprintf(name, "IDALS_MEM_NULL"); break; + case IDALS_LMEM_NULL: sprintf(name, "IDALS_LMEM_NULL"); break; + case IDALS_ILL_INPUT: sprintf(name, "IDALS_ILL_INPUT"); break; + case IDALS_MEM_FAIL: sprintf(name, "IDALS_MEM_FAIL"); break; + case IDALS_PMEM_NULL: sprintf(name, "IDALS_PMEM_NULL"); break; + case IDALS_JACFUNC_UNRECVR: sprintf(name, "IDALS_JACFUNC_UNRECVR"); break; + case IDALS_JACFUNC_RECVR: sprintf(name, "IDALS_JACFUNC_RECVR"); break; + case IDALS_SUNMAT_FAIL: sprintf(name, "IDALS_SUNMAT_FAIL"); break; + case IDALS_SUNLS_FAIL: sprintf(name, "IDALS_SUNLS_FAIL"); break; + default: sprintf(name, "NONE"); + } + + return (name); } - /*=============================================================== IDASLS Private functions ===============================================================*/ @@ -819,29 +841,26 @@ char *IDAGetLinReturnFlagName(long int flag) the same as the value returned by jtimes -- 0 if successful, nonzero otherwise. ---------------------------------------------------------------*/ -int idaLsATimes(void *ida_mem, N_Vector v, N_Vector z) +int idaLsATimes(void* ida_mem, N_Vector v, N_Vector z) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "idaLsATimes", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* call Jacobian-times-vector product routine (either user-supplied or internal DQ) */ - retval = idals_mem->jtimes(IDA_mem->ida_tn, idals_mem->ycur, - idals_mem->ypcur, idals_mem->rcur, - v, z, IDA_mem->ida_cj, + retval = idals_mem->jtimes(IDA_mem->ida_tn, idals_mem->ycur, idals_mem->ypcur, + idals_mem->rcur, v, z, IDA_mem->ida_cj, idals_mem->jt_data, idals_mem->ytemp, idals_mem->yptemp); idals_mem->njtimes++; - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsPSetup: @@ -852,27 +871,24 @@ int idaLsATimes(void *ida_mem, N_Vector v, N_Vector z) iterative linear solvers guarantee that idaLsPSetup will only be called in the case that the user's psetup routine is non-NULL. ---------------------------------------------------------------*/ -int idaLsPSetup(void *ida_mem) +int idaLsPSetup(void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "idaLsPSetup", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* Call user pset routine to update preconditioner and possibly reset jcur (pass !jbad as update suggestion) */ - retval = idals_mem->pset(IDA_mem->ida_tn, idals_mem->ycur, - idals_mem->ypcur, idals_mem->rcur, - IDA_mem->ida_cj, idals_mem->pdata); + retval = idals_mem->pset(IDA_mem->ida_tn, idals_mem->ycur, idals_mem->ypcur, + idals_mem->rcur, IDA_mem->ida_cj, idals_mem->pdata); idals_mem->npe++; - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsPSolve: @@ -885,27 +901,25 @@ int idaLsPSetup(void *ida_mem) is the only case in which the user's psolve routine is allowed to be NULL. ---------------------------------------------------------------*/ -int idaLsPSolve(void *ida_mem, N_Vector r, N_Vector z, realtype tol, int lr) +int idaLsPSolve(void* ida_mem, N_Vector r, N_Vector z, sunrealtype tol, + SUNDIALS_MAYBE_UNUSED int lr) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "idaLsPSolve", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* call the user-supplied psolve routine, and accumulate count */ - retval = idals_mem->psolve(IDA_mem->ida_tn, idals_mem->ycur, - idals_mem->ypcur, idals_mem->rcur, - r, z, IDA_mem->ida_cj, tol, + retval = idals_mem->psolve(IDA_mem->ida_tn, idals_mem->ycur, idals_mem->ypcur, + idals_mem->rcur, r, z, IDA_mem->ida_cj, tol, idals_mem->pdata); idals_mem->nps++; - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsDQJac: @@ -913,26 +927,28 @@ int idaLsPSolve(void *ida_mem, N_Vector r, N_Vector z, realtype tol, int lr) implementations of the difference quotient Jacobian approximation routines. ---------------------------------------------------------------*/ -int idaLsDQJac(realtype t, realtype c_j, N_Vector y, N_Vector yp, - N_Vector r, SUNMatrix Jac, void *ida_mem, - N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) +int idaLsDQJac(sunrealtype t, sunrealtype c_j, N_Vector y, N_Vector yp, + N_Vector r, SUNMatrix Jac, void* ida_mem, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3) { - int retval; + int retval; IDAMem IDA_mem; - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* access IDAMem structure */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - "idaLsDQJac", MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } /* verify that Jac is non-NULL */ - if (Jac == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASLS", - "idaLsDQJac", MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (Jac == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); } /* Verify that N_Vector supports required operations */ @@ -941,27 +957,31 @@ int idaLsDQJac(realtype t, realtype c_j, N_Vector y, N_Vector yp, IDA_mem->ida_tempv1->ops->nvdestroy == NULL || IDA_mem->ida_tempv1->ops->nvscale == NULL || IDA_mem->ida_tempv1->ops->nvgetarraypointer == NULL || - IDA_mem->ida_tempv1->ops->nvsetarraypointer == NULL) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "idaLsDQJac", MSG_LS_BAD_NVECTOR); - return(IDALS_ILL_INPUT); + IDA_mem->ida_tempv1->ops->nvsetarraypointer == NULL) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_NVECTOR); + return (IDALS_ILL_INPUT); } /* Call the matrix-structure-specific DQ approximation routine */ - if (SUNMatGetID(Jac) == SUNMATRIX_DENSE) { + if (SUNMatGetID(Jac) == SUNMATRIX_DENSE) + { retval = idaLsDenseDQJac(t, c_j, y, yp, r, Jac, IDA_mem, tmp1); - } else if (SUNMatGetID(Jac) == SUNMATRIX_BAND) { + } + else if (SUNMatGetID(Jac) == SUNMATRIX_BAND) + { retval = idaLsBandDQJac(t, c_j, y, yp, r, Jac, IDA_mem, tmp1, tmp2, tmp3); - } else { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDASLS", - "idaLsDQJac", + } + else + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "unrecognized matrix type for idaLsDQJac"); retval = IDA_ILL_INPUT; } - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsDenseDQJac @@ -975,19 +995,18 @@ int idaLsDQJac(realtype t, realtype c_j, N_Vector y, N_Vector yp, actual computation of the jth column of the Jacobian is done with a call to N_VLinearSum. ---------------------------------------------------------------*/ -int idaLsDenseDQJac(realtype tt, realtype c_j, N_Vector yy, - N_Vector yp, N_Vector rr, SUNMatrix Jac, - IDAMem IDA_mem, N_Vector tmp1) +int idaLsDenseDQJac(sunrealtype tt, sunrealtype c_j, N_Vector yy, N_Vector yp, + N_Vector rr, SUNMatrix Jac, IDAMem IDA_mem, N_Vector tmp1) { - realtype inc, inc_inv, yj, ypj, srur, conj; - realtype *y_data, *yp_data, *ewt_data, *cns_data = NULL; + sunrealtype inc, inc_inv, yj, ypj, srur, conj; + sunrealtype *y_data, *yp_data, *ewt_data, *cns_data = NULL; N_Vector rtemp, jthCol; sunindextype j, N; IDALsMem idals_mem; int retval = 0; /* access LsMem interface structure */ - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* access matrix dimension */ N = SUNDenseMatrix_Columns(Jac); @@ -1002,62 +1021,70 @@ int idaLsDenseDQJac(realtype tt, realtype c_j, N_Vector yy, ewt_data = N_VGetArrayPointer(IDA_mem->ida_ewt); y_data = N_VGetArrayPointer(yy); yp_data = N_VGetArrayPointer(yp); - if(IDA_mem->ida_constraintsSet) + if (IDA_mem->ida_constraintsSet) + { cns_data = N_VGetArrayPointer(IDA_mem->ida_constraints); + } srur = SUNRsqrt(IDA_mem->ida_uround); - for (j=0; j < N; j++) { - + for (j = 0; j < N; j++) + { /* Generate the jth col of J(tt,yy,yp) as delta(F)/delta(y_j). */ /* Set data address of jthCol, and save y_j and yp_j values. */ - N_VSetArrayPointer(SUNDenseMatrix_Column(Jac,j), jthCol); - yj = y_data[j]; + N_VSetArrayPointer(SUNDenseMatrix_Column(Jac, j), jthCol); + yj = y_data[j]; ypj = yp_data[j]; /* Set increment inc to y_j based on sqrt(uround)*abs(y_j), with adjustments using yp_j and ewt_j if this is small, and a further adjustment to give it the same sign as hh*yp_j. */ - inc = SUNMAX( srur * SUNMAX( SUNRabs(yj), SUNRabs(IDA_mem->ida_hh*ypj) ), - ONE/ewt_data[j] ); + inc = SUNMAX(srur * SUNMAX(SUNRabs(yj), SUNRabs(IDA_mem->ida_hh * ypj)), + ONE / ewt_data[j]); - if (IDA_mem->ida_hh*ypj < ZERO) inc = -inc; + if (IDA_mem->ida_hh * ypj < ZERO) { inc = -inc; } inc = (yj + inc) - yj; /* Adjust sign(inc) again if y_j has an inequality constraint. */ - if (IDA_mem->ida_constraintsSet) { + if (IDA_mem->ida_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } /* Increment y_j and yp_j, call res, and break on error return. */ y_data[j] += inc; - yp_data[j] += c_j*inc; + yp_data[j] += c_j * inc; retval = IDA_mem->ida_res(tt, yy, yp, rtemp, IDA_mem->ida_user_data); idals_mem->nreDQ++; - if (retval != 0) break; + if (retval != 0) { break; } /* Construct difference quotient in jthCol */ - inc_inv = ONE/inc; + inc_inv = ONE / inc; N_VLinearSum(inc_inv, rtemp, -inc_inv, rr, jthCol); /* reset y_j, yp_j */ - y_data[j] = yj; + y_data[j] = yj; yp_data[j] = ypj; } /* Destroy jthCol vector */ - N_VSetArrayPointer(NULL, jthCol); /* SHOULDN'T BE NEEDED */ + N_VSetArrayPointer(NULL, jthCol); /* SHOULDN'T BE NEEDED */ N_VDestroy(jthCol); - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsBandDQJac @@ -1071,14 +1098,13 @@ int idaLsDenseDQJac(realtype tt, realtype c_j, N_Vector yy, The return value is either IDABAND_SUCCESS = 0, or the nonzero value returned by the res routine, if any. ---------------------------------------------------------------*/ -int idaLsBandDQJac(realtype tt, realtype c_j, N_Vector yy, - N_Vector yp, N_Vector rr, SUNMatrix Jac, - IDAMem IDA_mem, N_Vector tmp1, N_Vector tmp2, - N_Vector tmp3) +int idaLsBandDQJac(sunrealtype tt, sunrealtype c_j, N_Vector yy, N_Vector yp, + N_Vector rr, SUNMatrix Jac, IDAMem IDA_mem, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3) { - realtype inc, inc_inv, yj, ypj, srur, conj, ewtj; - realtype *y_data, *yp_data, *ewt_data, *cns_data = NULL; - realtype *ytemp_data, *yptemp_data, *rtemp_data, *r_data, *col_j; + sunrealtype inc, inc_inv, yj, ypj, srur, conj, ewtj; + sunrealtype *y_data, *yp_data, *ewt_data, *cns_data = NULL; + sunrealtype *ytemp_data, *yptemp_data, *rtemp_data, *r_data, *col_j; N_Vector rtemp, ytemp, yptemp; sunindextype i, j, i1, i2, width, ngroups, group; sunindextype N, mupper, mlower; @@ -1086,17 +1112,17 @@ int idaLsBandDQJac(realtype tt, realtype c_j, N_Vector yy, int retval = 0; /* access LsMem interface structure */ - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* access matrix dimensions */ - N = SUNBandMatrix_Columns(Jac); + N = SUNBandMatrix_Columns(Jac); mupper = SUNBandMatrix_UpperBandwidth(Jac); mlower = SUNBandMatrix_LowerBandwidth(Jac); /* Rename work vectors for use as temporary values of r, y and yp */ - rtemp = tmp1; - ytemp = tmp2; - yptemp= tmp3; + rtemp = tmp1; + ytemp = tmp2; + yptemp = tmp3; /* Obtain pointers to the data for all eight vectors used. */ ewt_data = N_VGetArrayPointer(IDA_mem->ida_ewt); @@ -1107,84 +1133,102 @@ int idaLsBandDQJac(realtype tt, realtype c_j, N_Vector yy, ytemp_data = N_VGetArrayPointer(ytemp); yptemp_data = N_VGetArrayPointer(yptemp); if (IDA_mem->ida_constraintsSet) + { cns_data = N_VGetArrayPointer(IDA_mem->ida_constraints); + } /* Initialize ytemp and yptemp. */ N_VScale(ONE, yy, ytemp); N_VScale(ONE, yp, yptemp); /* Compute miscellaneous values for the Jacobian computation. */ - srur = SUNRsqrt(IDA_mem->ida_uround); - width = mlower + mupper + 1; + srur = SUNRsqrt(IDA_mem->ida_uround); + width = mlower + mupper + 1; ngroups = SUNMIN(width, N); /* Loop over column groups. */ - for (group=1; group <= ngroups; group++) { - + for (group = 1; group <= ngroups; group++) + { /* Increment all yy[j] and yp[j] for j in this group. */ - for (j=group-1; jida_hh*ypj) ), - ONE/ewtj ); - if (IDA_mem->ida_hh*ypj < ZERO) inc = -inc; - inc = (yj + inc) - yj; - - /* Adjust sign(inc) again if yj has an inequality constraint. */ - if (IDA_mem->ida_constraintsSet) { - conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if((yj+inc)*conj <= ZERO) inc = -inc;} + inc = SUNMAX(srur * SUNMAX(SUNRabs(yj), SUNRabs(IDA_mem->ida_hh * ypj)), + ONE / ewtj); + if (IDA_mem->ida_hh * ypj < ZERO) { inc = -inc; } + inc = (yj + inc) - yj; + + /* Adjust sign(inc) again if yj has an inequality constraint. */ + if (IDA_mem->ida_constraintsSet) + { + conj = cns_data[j]; + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } } + } - /* Increment yj and ypj. */ - ytemp_data[j] += inc; - yptemp_data[j] += IDA_mem->ida_cj*inc; + /* Increment yj and ypj. */ + ytemp_data[j] += inc; + yptemp_data[j] += c_j * inc; } /* Call res routine with incremented arguments. */ retval = IDA_mem->ida_res(tt, ytemp, yptemp, rtemp, IDA_mem->ida_user_data); idals_mem->nreDQ++; - if (retval != 0) break; + if (retval != 0) { break; } /* Loop over the indices j in this group again. */ - for (j=group-1; jida_hh*ypj) ), - ONE/ewtj ); - if (IDA_mem->ida_hh*ypj < ZERO) inc = -inc; + inc = SUNMAX(srur * SUNMAX(SUNRabs(yj), SUNRabs(IDA_mem->ida_hh * ypj)), + ONE / ewtj); + if (IDA_mem->ida_hh * ypj < ZERO) { inc = -inc; } inc = (yj + inc) - yj; - if (IDA_mem->ida_constraintsSet) { + if (IDA_mem->ida_constraintsSet) + { conj = cns_data[j]; - if (SUNRabs(conj) == ONE) {if((yj+inc)*conj < ZERO) inc = -inc;} - else if (SUNRabs(conj) == TWO) {if((yj+inc)*conj <= ZERO) inc = -inc;} + if (SUNRabs(conj) == ONE) + { + if ((yj + inc) * conj < ZERO) { inc = -inc; } + } + else if (SUNRabs(conj) == TWO) + { + if ((yj + inc) * conj <= ZERO) { inc = -inc; } + } } /* Load the difference quotient Jacobian elements for column j */ - inc_inv = ONE/inc; - i1 = SUNMAX(0, j-mupper); - i2 = SUNMIN(j+mlower,N-1); - for (i=i1; i<=i2; i++) - SM_COLUMN_ELEMENT_B(col_j,i,j) = inc_inv * (rtemp_data[i]-r_data[i]); + inc_inv = ONE / inc; + i1 = SUNMAX(0, j - mupper); + i2 = SUNMIN(j + mlower, N - 1); + for (i = i1; i <= i2; i++) + { + SM_COLUMN_ELEMENT_B(col_j, i, j) = inc_inv * (rtemp_data[i] - r_data[i]); + } } } - return(retval); + return (retval); } - /*--------------------------------------------------------------- idaLsDQJtimes @@ -1198,57 +1242,56 @@ int idaLsBandDQJac(realtype tt, realtype c_j, N_Vector yy, The return value from the call to res is saved in order to set the return flag from idaLsSolve. ---------------------------------------------------------------*/ -int idaLsDQJtimes(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, - N_Vector v, N_Vector Jv, realtype c_j, - void *ida_mem, N_Vector work1, N_Vector work2) +int idaLsDQJtimes(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, + N_Vector v, N_Vector Jv, sunrealtype c_j, void* ida_mem, + N_Vector work1, N_Vector work2) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDALsMem idals_mem; N_Vector y_tmp, yp_tmp; - realtype sig, siginv; - int iter, retval; + sunrealtype sig, siginv; + int iter, retval; SUNLinearSolver_ID LSID; /* access IDALsMem structure */ - retval = idaLs_AccessLMem(ida_mem, "idaLsDQJtimes", - &IDA_mem, &idals_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMem(ida_mem, __func__, &IDA_mem, &idals_mem); + if (retval != IDALS_SUCCESS) { return (retval); } LSID = SUNLinSolGetID(idals_mem->LS); if (LSID == SUNLINEARSOLVER_SPGMR || LSID == SUNLINEARSOLVER_SPFGMR) + { sig = idals_mem->nrmfac * idals_mem->dqincfac; - else - sig = idals_mem->dqincfac / N_VWrmsNorm(v, IDA_mem->ida_ewt); + } + else { sig = idals_mem->dqincfac / N_VWrmsNorm(v, IDA_mem->ida_ewt); } /* Rename work1 and work2 for readibility */ y_tmp = work1; yp_tmp = work2; - for (iter=0; iterjt_res(tt, y_tmp, yp_tmp, Jv, IDA_mem->ida_user_data); idals_mem->nreDQ++; - if (retval == 0) break; - if (retval < 0) return(-1); + if (retval == 0) { break; } + if (retval < 0) { return (-1); } sig *= PT25; } - if (retval > 0) return(+1); + if (retval > 0) { return (+1); } /* Set Jv to [Jv - rr]/sig and return. */ - siginv = ONE/sig; + siginv = ONE / sig; N_VLinearSum(siginv, Jv, -siginv, rr, Jv); - return(0); + return (0); } - /*--------------------------------------------------------------- idaLsInitialize @@ -1258,53 +1301,52 @@ int idaLsDQJtimes(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, int idaLsInitialize(IDAMem IDA_mem) { IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASLS", - "idaLsInitialize", MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; - + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* Test for valid combinations of matrix & Jacobian routines: */ - if (idals_mem->J == NULL) { - + if (idals_mem->J == NULL) + { /* If SUNMatrix A is NULL: ensure 'jac' function pointer is NULL */ idals_mem->jacDQ = SUNFALSE; idals_mem->jac = NULL; idals_mem->J_data = NULL; - - } else if (idals_mem->jacDQ) { - + } + else if (idals_mem->jacDQ) + { /* If J is non-NULL, and 'jac' is not user-supplied: - if J is dense or band, ensure that our DQ approx. is used - otherwise => error */ retval = 0; - if (idals_mem->J->ops->getid) { - - if ( (SUNMatGetID(idals_mem->J) == SUNMATRIX_DENSE) || - (SUNMatGetID(idals_mem->J) == SUNMATRIX_BAND) ) { + if (idals_mem->J->ops->getid) + { + if ((SUNMatGetID(idals_mem->J) == SUNMATRIX_DENSE) || + (SUNMatGetID(idals_mem->J) == SUNMATRIX_BAND)) + { idals_mem->jac = idaLsDQJac; idals_mem->J_data = IDA_mem; - } else { - retval++; } - - } else { - retval++; + else { retval++; } } - if (retval) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", "idaLsInitialize", - "No Jacobian constructor available for SUNMatrix type"); + else { retval++; } + if (retval) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + "No Jacobian constructor available for SUNMatrix type"); idals_mem->last_flag = IDALS_ILL_INPUT; - return(IDALS_ILL_INPUT); + return (IDALS_ILL_INPUT); } - - } else { - + } + else + { /* If J is non-NULL, and 'jac' is user-supplied, reset J_data pointer (just in case) */ idals_mem->J_data = IDA_mem->ida_user_data; @@ -1314,31 +1356,33 @@ int idaLsInitialize(IDAMem IDA_mem) idaLsInitializeCounters(idals_mem); /* Set Jacobian-related fields, based on jtimesDQ */ - if (idals_mem->jtimesDQ) { + if (idals_mem->jtimesDQ) + { idals_mem->jtsetup = NULL; idals_mem->jtimes = idaLsDQJtimes; idals_mem->jt_data = IDA_mem; - } else { - idals_mem->jt_data = IDA_mem->ida_user_data; } + else { idals_mem->jt_data = IDA_mem->ida_user_data; } /* if J is NULL and psetup is not present, then idaLsSetup does not need to be called, so set the lsetup function to NULL */ - if ( (idals_mem->J == NULL) && (idals_mem->pset == NULL) ) + if ((idals_mem->J == NULL) && (idals_mem->pset == NULL)) + { IDA_mem->ida_lsetup = NULL; + } /* When using a matrix-embedded linear solver disable lsetup call */ - if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) { + if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) + { IDA_mem->ida_lsetup = NULL; idals_mem->scalesol = SUNFALSE; } /* Call LS initialize routine */ idals_mem->last_flag = SUNLinSolInitialize(idals_mem->LS); - return(idals_mem->last_flag); + return (idals_mem->last_flag); } - /*--------------------------------------------------------------- idaLsSetup @@ -1350,20 +1394,22 @@ int idaLsSetup(IDAMem IDA_mem, N_Vector y, N_Vector yp, N_Vector r, N_Vector vt1, N_Vector vt2, N_Vector vt3) { IDALsMem idals_mem; - int retval; + int retval; /* access IDALsMem structure */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASLS", - "idaLsSetup", MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* Immediately return when using matrix-embedded linear solver */ - if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) { + if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_MATRIX_EMBEDDED) + { idals_mem->last_flag = IDALS_SUCCESS; - return(idals_mem->last_flag); + return (idals_mem->last_flag); } /* Set IDALs N_Vector pointers to inputs */ @@ -1371,46 +1417,51 @@ int idaLsSetup(IDAMem IDA_mem, N_Vector y, N_Vector yp, N_Vector r, idals_mem->ypcur = yp; idals_mem->rcur = r; - /* recompute if J if it is non-NULL */ - if (idals_mem->J) { + /* Update values for last jac/pset call */ + idals_mem->nstlj = IDA_mem->ida_nst; + idals_mem->tnlj = IDA_mem->ida_tn; + /* recompute if J if it is non-NULL */ + if (idals_mem->J) + { /* Increment nje counter. */ idals_mem->nje++; /* Clear the linear system matrix if necessary */ - if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_DIRECT) { + if (SUNLinSolGetType(idals_mem->LS) == SUNLINEARSOLVER_DIRECT) + { retval = SUNMatZero(idals_mem->J); - if (retval != 0) { - IDAProcessError(IDA_mem, IDALS_SUNMAT_FAIL, "IDASLS", - "idaLsSetup", MSG_LS_MATZERO_FAILED); + if (retval != 0) + { + IDAProcessError(IDA_mem, IDALS_SUNMAT_FAIL, __LINE__, __func__, + __FILE__, MSG_LS_MATZERO_FAILED); idals_mem->last_flag = IDALS_SUNMAT_FAIL; - return(idals_mem->last_flag); + return (idals_mem->last_flag); } } /* Call Jacobian routine */ - retval = idals_mem->jac(IDA_mem->ida_tn, IDA_mem->ida_cj, y, - yp, r, idals_mem->J, - idals_mem->J_data, vt1, vt2, vt3); - if (retval < 0) { - IDAProcessError(IDA_mem, IDALS_JACFUNC_UNRECVR, "IDASLS", - "idaLsSetup", MSG_LS_JACFUNC_FAILED); + retval = idals_mem->jac(IDA_mem->ida_tn, IDA_mem->ida_cj, y, yp, r, + idals_mem->J, idals_mem->J_data, vt1, vt2, vt3); + if (retval < 0) + { + IDAProcessError(IDA_mem, IDALS_JACFUNC_UNRECVR, __LINE__, __func__, + __FILE__, MSG_LS_JACFUNC_FAILED); idals_mem->last_flag = IDALS_JACFUNC_UNRECVR; - return(-1); + return (-1); } - if (retval > 0) { + if (retval > 0) + { idals_mem->last_flag = IDALS_JACFUNC_RECVR; - return(1); + return (1); } - } /* Call LS setup routine -- the LS will call idaLsPSetup if applicable */ idals_mem->last_flag = SUNLinSolSetup(idals_mem->LS, idals_mem->J); - return(idals_mem->last_flag); + return (idals_mem->last_flag); } - /*--------------------------------------------------------------- idaLsSolve @@ -1421,31 +1472,32 @@ int idaLsSetup(IDAMem IDA_mem, N_Vector y, N_Vector yp, N_Vector r, the result if using a non-NULL SUNMatrix and cjratio does not equal one. ---------------------------------------------------------------*/ -int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, - N_Vector ycur, N_Vector ypcur, N_Vector rescur) +int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, + N_Vector ypcur, N_Vector rescur) { IDALsMem idals_mem; - int nli_inc, retval; - realtype tol, w_mean; + int nli_inc, retval; + sunrealtype tol, w_mean; /* access IDALsMem structure */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASLS", - "idaLsSolve", MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* If the linear solver is iterative: set convergence test constant tol, in terms of the Newton convergence test constant epsNewt and safety factors. The factor nrmfac assures that the convergence test is applied to the WRMS norm of the residual vector, rather than the weighted L2 norm. */ - if (idals_mem->iterative) { + if (idals_mem->iterative) + { tol = idals_mem->nrmfac * idals_mem->eplifac * IDA_mem->ida_epsNewt; - } else { - tol = ZERO; } + else { tol = ZERO; } /* Set vectors ycur, ypcur and rcur for use by the Atimes and Psolve interface routines */ @@ -1454,16 +1506,18 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, idals_mem->rcur = rescur; /* Set scaling vectors for LS to use (if applicable) */ - if (idals_mem->LS->ops->setscalingvectors) { + if (idals_mem->LS->ops->setscalingvectors) + { retval = SUNLinSolSetScalingVectors(idals_mem->LS, weight, weight); - if (retval != SUNLS_SUCCESS) { - IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", "idaLsSolve", + if (retval != SUN_SUCCESS) + { + IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetScalingVectors"); idals_mem->last_flag = IDALS_SUNLS_FAIL; - return(idals_mem->last_flag); + return (idals_mem->last_flag); } - /* If solver is iterative and does not support scaling vectors, update the + /* If solver is iterative and does not support scaling vectors, update the tolerance in an attempt to account for weight vector. We make the following assumptions: 1. w_i = w_mean, for i=0,...,n-1 (i.e. the weights are homogeneous) @@ -1477,12 +1531,12 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, <=> \sum_{i=0}^{n-1} (b - A x_i)^2 < tol^2 / w_mean^2 <=> || b - A x ||_2 < tol / w_mean So we compute w_mean = ||w||_RMS and scale the desired tolerance accordingly. */ - } else if (idals_mem->iterative) { - + } + else if (idals_mem->iterative) + { N_VConst(ONE, idals_mem->x); w_mean = N_VWrmsNorm(weight, idals_mem->x); tol /= w_mean; - } /* Set initial guess x = 0 to LS */ @@ -1490,120 +1544,120 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(idals_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) return(-1); + if (retval != SUN_SUCCESS) { return (-1); } /* If a user-provided jtsetup routine is supplied, call that here */ - if (idals_mem->jtsetup) { - idals_mem->last_flag = idals_mem->jtsetup(IDA_mem->ida_tn, ycur, ypcur, rescur, - IDA_mem->ida_cj, idals_mem->jt_data); + if (idals_mem->jtsetup) + { + idals_mem->last_flag = idals_mem->jtsetup(IDA_mem->ida_tn, ycur, ypcur, + rescur, IDA_mem->ida_cj, + idals_mem->jt_data); idals_mem->njtsetup++; - if (idals_mem->last_flag != 0) { - IDAProcessError(IDA_mem, retval, "IDASLS", - "idaLsSolve", MSG_LS_JTSETUP_FAILED); - return(idals_mem->last_flag); + if (idals_mem->last_flag != 0) + { + IDAProcessError(IDA_mem, retval, __LINE__, __func__, __FILE__, + MSG_LS_JTSETUP_FAILED); + return (idals_mem->last_flag); } } /* Call solver */ - retval = SUNLinSolSolve(idals_mem->LS, idals_mem->J, - idals_mem->x, b, tol); + retval = SUNLinSolSolve(idals_mem->LS, idals_mem->J, idals_mem->x, b, tol); /* Copy appropriate result to b (depending on solver type) */ - if (idals_mem->iterative) { - + if (idals_mem->iterative) + { /* Retrieve solver statistics */ nli_inc = SUNLinSolNumIters(idals_mem->LS); /* Copy x (or preconditioned residual vector if no iterations required) to b */ - if ((nli_inc == 0) && (SUNLinSolGetType(idals_mem->LS) != SUNLINEARSOLVER_MATRIX_EMBEDDED)) + if ((nli_inc == 0) && + (SUNLinSolGetType(idals_mem->LS) != SUNLINEARSOLVER_MATRIX_EMBEDDED)) + { N_VScale(ONE, SUNLinSolResid(idals_mem->LS), b); - else N_VScale(ONE, idals_mem->x, b); + } + else { N_VScale(ONE, idals_mem->x, b); } /* Increment nli counter */ idals_mem->nli += nli_inc; - - } else { - + } + else + { /* Copy x to b */ N_VScale(ONE, idals_mem->x, b); - } /* If using a direct or matrix-iterative solver, scale the correction to account for change in cj */ if (idals_mem->scalesol && (IDA_mem->ida_cjratio != ONE)) - N_VScale(TWO/(ONE + IDA_mem->ida_cjratio), b, b); + { + N_VScale(TWO / (ONE + IDA_mem->ida_cjratio), b, b); + } /* Increment ncfl counter */ - if (retval != SUNLS_SUCCESS) idals_mem->ncfl++; + if (retval != SUN_SUCCESS) { idals_mem->ncfl++; } /* Interpret solver return value */ idals_mem->last_flag = retval; - switch(retval) { - - case SUNLS_SUCCESS: - return(0); - break; + switch (retval) + { + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: case SUNLS_CONV_FAIL: case SUNLS_PSOLVE_FAIL_REC: case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: - case SUNLS_LUFACT_FAIL: - return(1); - break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUNLS_LUFACT_FAIL: return (1); break; + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: - case SUNLS_QRSOL_FAIL: - return(-1); - break; - case SUNLS_PACKAGE_FAIL_UNREC: - IDAProcessError(IDA_mem, SUNLS_PACKAGE_FAIL_UNREC, "IDASLS", - "idaLsSolve", + case SUNLS_QRSOL_FAIL: return (-1); break; + case SUN_ERR_EXT_FAIL: + IDAProcessError(IDA_mem, SUN_ERR_EXT_FAIL, __LINE__, __func__, __FILE__, "Failure in SUNLinSol external package"); - return(-1); + return (-1); break; case SUNLS_PSOLVE_FAIL_UNREC: - IDAProcessError(IDA_mem, SUNLS_PSOLVE_FAIL_UNREC, "IDASLS", - "idaLsSolve", MSG_LS_PSOLVE_FAILED); - return(-1); + IDAProcessError(IDA_mem, SUNLS_PSOLVE_FAIL_UNREC, __LINE__, __func__, + __FILE__, MSG_LS_PSOLVE_FAILED); + return (-1); break; } - return(0); + return (0); } - /*--------------------------------------------------------------- idaLsPerf: accumulates performance statistics information for IDA ---------------------------------------------------------------*/ int idaLsPerf(IDAMem IDA_mem, int perftask) { - IDALsMem idals_mem; - realtype rcfn, rcfl; - long int nstd, nnid; - booleantype lcfn, lcfl; + IDALsMem idals_mem; + sunrealtype rcfn, rcfl; + long int nstd, nnid; + sunbooleantype lcfn, lcfl; /* access IDALsMem structure */ - if (IDA_mem->ida_lmem == NULL) { - IDAProcessError(IDA_mem, IDALS_LMEM_NULL, "IDASLS", - "idaLsPerf", MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); + if (IDA_mem->ida_lmem == NULL) + { + IDAProcessError(IDA_mem, IDALS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); } - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* when perftask == 0, store current performance statistics */ - if (perftask == 0) { + if (perftask == 0) + { idals_mem->nst0 = IDA_mem->ida_nst; idals_mem->nni0 = IDA_mem->ida_nni; idals_mem->ncfn0 = IDA_mem->ida_ncfn; idals_mem->ncfl0 = idals_mem->ncfl; idals_mem->nwarn = 0; - return(0); + return (0); } /* Compute statistics since last call @@ -1615,25 +1669,30 @@ int idaLsPerf(IDAMem IDA_mem, int perftask) */ nstd = IDA_mem->ida_nst - idals_mem->nst0; nnid = IDA_mem->ida_nni - idals_mem->nni0; - if (nstd == 0 || nnid == 0) return(0); + if (nstd == 0 || nnid == 0) { return (0); } - rcfn = ((realtype) (IDA_mem->ida_ncfn - idals_mem->ncfn0)) / ((realtype) nstd); - rcfl = ((realtype) (idals_mem->ncfl - idals_mem->ncfl0)) / ((realtype) nnid); + rcfn = ((sunrealtype)(IDA_mem->ida_ncfn - idals_mem->ncfn0)) / + ((sunrealtype)nstd); + rcfl = ((sunrealtype)(idals_mem->ncfl - idals_mem->ncfl0)) / + ((sunrealtype)nnid); lcfn = (rcfn > PT9); lcfl = (rcfl > PT9); - if (!(lcfn || lcfl)) return(0); + if (!(lcfn || lcfl)) { return (0); } idals_mem->nwarn++; - if (idals_mem->nwarn > 10) return(1); + if (idals_mem->nwarn > 10) { return (1); } if (lcfn) - IDAProcessError(IDA_mem, IDA_WARNING, "IDASLS", "idaLsPerf", + { + IDAProcessError(IDA_mem, IDA_WARNING, __LINE__, __func__, __FILE__, MSG_LS_CFN_WARN, IDA_mem->ida_tn, rcfn); + } if (lcfl) - IDAProcessError(IDA_mem, IDA_WARNING, "IDASLS", "idaLsPerf", + { + IDAProcessError(IDA_mem, IDA_WARNING, __LINE__, __func__, __FILE__, MSG_LS_CFL_WARN, IDA_mem->ida_tn, rcfl); - return(0); + } + return (0); } - /*--------------------------------------------------------------- idaLsFree frees memory associates with the IDALs system solver interface. @@ -1643,20 +1702,23 @@ int idaLsFree(IDAMem IDA_mem) IDALsMem idals_mem; /* Return immediately if IDA_mem or IDA_mem->ida_lmem are NULL */ - if (IDA_mem == NULL) return (IDALS_SUCCESS); - if (IDA_mem->ida_lmem == NULL) return(IDALS_SUCCESS); - idals_mem = (IDALsMem) IDA_mem->ida_lmem; + if (IDA_mem == NULL) { return (IDALS_SUCCESS); } + if (IDA_mem->ida_lmem == NULL) { return (IDALS_SUCCESS); } + idals_mem = (IDALsMem)IDA_mem->ida_lmem; /* Free N_Vector memory */ - if (idals_mem->ytemp) { + if (idals_mem->ytemp) + { N_VDestroy(idals_mem->ytemp); idals_mem->ytemp = NULL; } - if (idals_mem->yptemp) { + if (idals_mem->yptemp) + { N_VDestroy(idals_mem->yptemp); idals_mem->yptemp = NULL; } - if (idals_mem->x) { + if (idals_mem->x) + { N_VDestroy(idals_mem->x); idals_mem->x = NULL; } @@ -1670,15 +1732,14 @@ int idaLsFree(IDAMem IDA_mem) idals_mem->J = NULL; /* Free preconditioner memory (if applicable) */ - if (idals_mem->pfree) idals_mem->pfree(IDA_mem); + if (idals_mem->pfree) { idals_mem->pfree(IDA_mem); } /* free IDALs interface structure */ free(IDA_mem->ida_lmem); - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*--------------------------------------------------------------- idaLsInitializeCounters resets all counters from an IDALsMem structure. @@ -1693,10 +1754,9 @@ int idaLsInitializeCounters(IDALsMem idals_mem) idals_mem->ncfl = 0; idals_mem->njtsetup = 0; idals_mem->njtimes = 0; - return(0); + return (0); } - /*--------------------------------------------------------------- idaLs_AccessLMem @@ -1704,84 +1764,87 @@ int idaLsInitializeCounters(IDALsMem idals_mem) the void* ida_mem pointer. If either is missing it returns IDALS_MEM_NULL or IDALS_LMEM_NULL. ---------------------------------------------------------------*/ -int idaLs_AccessLMem(void* ida_mem, const char* fname, - IDAMem* IDA_mem, IDALsMem* idals_mem) +int idaLs_AccessLMem(void* ida_mem, const char* fname, IDAMem* IDA_mem, + IDALsMem* idals_mem) { - if (ida_mem==NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - fname, MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); - } - *IDA_mem = (IDAMem) ida_mem; - if ((*IDA_mem)->ida_lmem==NULL) { - IDAProcessError(*IDA_mem, IDALS_LMEM_NULL, "IDASLS", - fname, MSG_LS_LMEM_NULL); - return(IDALS_LMEM_NULL); - } - *idals_mem = (IDALsMem) (*IDA_mem)->ida_lmem; - return(IDALS_SUCCESS); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); + } + *IDA_mem = (IDAMem)ida_mem; + if ((*IDA_mem)->ida_lmem == NULL) + { + IDAProcessError(*IDA_mem, IDALS_LMEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEM_NULL); + return (IDALS_LMEM_NULL); + } + *idals_mem = (IDALsMem)(*IDA_mem)->ida_lmem; + return (IDALS_SUCCESS); } - - /*================================================================ PART II - backward problems ================================================================*/ - /*--------------------------------------------------------------- IDASLS Exported functions -- Required ---------------------------------------------------------------*/ /* IDASetLinearSolverB specifies the iterative linear solver for backward integration */ -int IDASetLinearSolverB(void *ida_mem, int which, - SUNLinearSolver LS, SUNMatrix A) +int IDASetLinearSolverB(void* ida_mem, int which, SUNLinearSolver LS, SUNMatrix A) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - IDABMem IDAB_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* Check if ida_mem exists */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - "IDASetLinearSolverB", MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* Was ASA initialized? */ - if (IDA_mem->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(IDA_mem, IDALS_NO_ADJ, "IDASLS", - "IDASetLinearSolverB", MSG_LS_NO_ADJ); - return(IDALS_NO_ADJ); + if (IDA_mem->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(IDA_mem, IDALS_NO_ADJ, __LINE__, __func__, __FILE__, + MSG_LS_NO_ADJ); + return (IDALS_NO_ADJ); } IDAADJ_mem = IDA_mem->ida_adj_mem; /* Check the value of which */ - if ( which >= IDAADJ_mem->ia_nbckpbs ) { - IDAProcessError(IDA_mem, IDALS_ILL_INPUT, "IDASLS", - "IDASetLinearSolverB", MSG_LS_BAD_WHICH); - return(IDALS_ILL_INPUT); + if (which >= IDAADJ_mem->ia_nbckpbs) + { + IDAProcessError(IDA_mem, IDALS_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_LS_BAD_WHICH); + return (IDALS_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to 'which'. */ IDAB_mem = IDAADJ_mem->IDAB_mem; - while (IDAB_mem != NULL) { - if( which == IDAB_mem->ida_index ) break; + while (IDAB_mem != NULL) + { + if (which == IDAB_mem->ida_index) { break; } IDAB_mem = IDAB_mem->ida_next; } /* Get memory for IDALsMemRecB */ idalsB_mem = NULL; - idalsB_mem = (IDALsMemB) malloc(sizeof(struct IDALsMemRecB)); - if (idalsB_mem == NULL) { - IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDASLS", - "IDASetLinearSolverB", MSG_LS_MEM_FAIL); - return(IDALS_MEM_FAIL); + idalsB_mem = (IDALsMemB)malloc(sizeof(struct IDALsMemRecB)); + if (idalsB_mem == NULL) + { + IDAProcessError(IDA_mem, IDALS_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_LS_MEM_FAIL); + return (IDALS_MEM_FAIL); } /* initialize Jacobian and preconditioner functions */ @@ -1798,849 +1861,842 @@ int IDASetLinearSolverB(void *ida_mem, int which, idalsB_mem->P_dataB = NULL; /* free any existing system solver attached to IDAB */ - if (IDAB_mem->ida_lfree) IDAB_mem->ida_lfree(IDAB_mem); + if (IDAB_mem->ida_lfree) { IDAB_mem->ida_lfree(IDAB_mem); } /* Attach lmemB data and lfreeB function. */ IDAB_mem->ida_lmem = idalsB_mem; IDAB_mem->ida_lfree = idaLsFreeB; /* set the linear solver for this backward problem */ - ida_memB = (void *)IDAB_mem->IDA_mem; - retval = IDASetLinearSolver(ida_memB, LS, A); - if (retval != IDALS_SUCCESS) { + ida_memB = (void*)IDAB_mem->IDA_mem; + retval = IDASetLinearSolver(ida_memB, LS, A); + if (retval != IDALS_SUCCESS) + { free(idalsB_mem); idalsB_mem = NULL; } - return(retval); + return (retval); } - /*--------------------------------------------------------------- IDASLS Exported functions -- Optional input/output ---------------------------------------------------------------*/ -int IDASetJacFnB(void *ida_mem, int which, IDALsJacFnB jacB) +int IDASetJacFnB(void* ida_mem, int which, IDALsJacFnB jacB) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - IDABMem IDAB_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetJacFnB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* set jacB function pointer */ idalsB_mem->jacB = jacB; /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void*) IDAB_mem->IDA_mem; - if (jacB != NULL) { - retval = IDASetJacFn(ida_memB, idaLsJacBWrapper); - } else { - retval = IDASetJacFn(ida_memB, NULL); - } + ida_memB = (void*)IDAB_mem->IDA_mem; + if (jacB != NULL) { retval = IDASetJacFn(ida_memB, idaLsJacBWrapper); } + else { retval = IDASetJacFn(ida_memB, NULL); } - return(retval); + return (retval); } - -int IDASetJacFnBS(void *ida_mem, int which, IDALsJacFnBS jacBS) +int IDASetJacFnBS(void* ida_mem, int which, IDALsJacFnBS jacBS) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; - IDABMem IDAB_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetJacFnBS", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* set jacBS function pointer */ idalsB_mem->jacBS = jacBS; /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void*) IDAB_mem->IDA_mem; - if (jacBS != NULL) { - retval = IDASetJacFn(ida_memB, idaLsJacBSWrapper); - } else { - retval = IDASetJacFn(ida_memB, NULL); - } + ida_memB = (void*)IDAB_mem->IDA_mem; + if (jacBS != NULL) { retval = IDASetJacFn(ida_memB, idaLsJacBSWrapper); } + else { retval = IDASetJacFn(ida_memB, NULL); } - return(retval); + return (retval); } - -int IDASetEpsLinB(void *ida_mem, int which, realtype eplifacB) +int IDASetEpsLinB(void* ida_mem, int which, sunrealtype eplifacB) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetEpsLinB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void *) IDAB_mem->IDA_mem; - return(IDASetEpsLin(ida_memB, eplifacB)); + ida_memB = (void*)IDAB_mem->IDA_mem; + return (IDASetEpsLin(ida_memB, eplifacB)); } - -int IDASetLSNormFactorB(void *ida_mem, int which, realtype nrmfacB) +int IDASetLSNormFactorB(void* ida_mem, int which, sunrealtype nrmfacB) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetLSNormFactorB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void *) IDAB_mem->IDA_mem; - return(IDASetLSNormFactor(ida_memB, nrmfacB)); + ida_memB = (void*)IDAB_mem->IDA_mem; + return (IDASetLSNormFactor(ida_memB, nrmfacB)); } - -int IDASetLinearSolutionScalingB(void *ida_mem, int which, booleantype onoffB) +int IDASetLinearSolutionScalingB(void* ida_mem, int which, sunbooleantype onoffB) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetLinearSolutionScalingB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void *) IDAB_mem->IDA_mem; - return(IDASetLinearSolutionScaling(ida_memB, onoffB)); + ida_memB = (void*)IDAB_mem->IDA_mem; + return (IDASetLinearSolutionScaling(ida_memB, onoffB)); } - -int IDASetIncrementFactorB(void *ida_mem, int which, realtype dqincfacB) +int IDASetIncrementFactorB(void* ida_mem, int which, sunrealtype dqincfacB) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + void* ida_memB; + int retval; /* access relevant memory structures */ - retval = idaLs_AccessLMemB(ida_mem, which, "IDASetIncrementFactorB", - &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMemB(ida_mem, which, "IDASetIncrementFactorB", &IDA_mem, + &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void *) IDAB_mem->IDA_mem; - return(IDASetIncrementFactor(ida_memB, dqincfacB)); + ida_memB = (void*)IDAB_mem->IDA_mem; + return (IDASetIncrementFactor(ida_memB, dqincfacB)); } - -int IDASetPreconditionerB(void *ida_mem, int which, - IDALsPrecSetupFnB psetupB, +int IDASetPreconditionerB(void* ida_mem, int which, IDALsPrecSetupFnB psetupB, IDALsPrecSolveFnB psolveB) { - IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; - void *ida_memB; - IDALsMemB idalsB_mem; + IDAadjMem IDAADJ_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; + void* ida_memB; + IDALsMemB idalsB_mem; IDALsPrecSetupFn idals_psetup; IDALsPrecSolveFn idals_psolve; - int retval; + int retval; /* access relevant memory structures */ - retval = idaLs_AccessLMemB(ida_mem, which, "IDASetPreconditionerB", - &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMemB(ida_mem, which, "IDASetPreconditionerB", &IDA_mem, + &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* Set preconditioners for the backward problem. */ idalsB_mem->psetB = psetupB; idalsB_mem->psolveB = psolveB; /* Call the corresponding "set" routine for the backward problem */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; idals_psetup = (psetupB == NULL) ? NULL : idaLsPrecSetupB; idals_psolve = (psolveB == NULL) ? NULL : idaLsPrecSolveB; - return(IDASetPreconditioner(ida_memB, idals_psetup, idals_psolve)); + return (IDASetPreconditioner(ida_memB, idals_psetup, idals_psolve)); } - -int IDASetPreconditionerBS(void *ida_mem, int which, - IDALsPrecSetupFnBS psetupBS, +int IDASetPreconditionerBS(void* ida_mem, int which, IDALsPrecSetupFnBS psetupBS, IDALsPrecSolveFnBS psolveBS) { - IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; - void *ida_memB; - IDALsMemB idalsB_mem; + IDAadjMem IDAADJ_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; + void* ida_memB; + IDALsMemB idalsB_mem; IDALsPrecSetupFn idals_psetup; IDALsPrecSolveFn idals_psolve; - int retval; + int retval; /* access relevant memory structures */ - retval = idaLs_AccessLMemB(ida_mem, which, "IDASetPreconditionerBS", - &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + retval = idaLs_AccessLMemB(ida_mem, which, "IDASetPreconditionerBS", &IDA_mem, + &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + if (retval != IDALS_SUCCESS) { return (retval); } /* Set preconditioners for the backward problem. */ idalsB_mem->psetBS = psetupBS; idalsB_mem->psolveBS = psolveBS; /* Call the corresponding "set" routine for the backward problem */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; idals_psetup = (psetupBS == NULL) ? NULL : idaLsPrecSetupBS; idals_psolve = (psolveBS == NULL) ? NULL : idaLsPrecSolveBS; - return(IDASetPreconditioner(ida_memB, idals_psetup, idals_psolve)); + return (IDASetPreconditioner(ida_memB, idals_psetup, idals_psolve)); } - -int IDASetJacTimesB(void *ida_mem, int which, - IDALsJacTimesSetupFnB jtsetupB, +int IDASetJacTimesB(void* ida_mem, int which, IDALsJacTimesSetupFnB jtsetupB, IDALsJacTimesVecFnB jtimesB) { - IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; - void *ida_memB; - IDALsMemB idalsB_mem; + IDAadjMem IDAADJ_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; + void* ida_memB; + IDALsMemB idalsB_mem; IDALsJacTimesSetupFn idals_jtsetup; - IDALsJacTimesVecFn idals_jtimes; - int retval; + IDALsJacTimesVecFn idals_jtimes; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetJacTimesB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* Set jacobian routines for the backward problem. */ idalsB_mem->jtsetupB = jtsetupB; idalsB_mem->jtimesB = jtimesB; /* Call the corresponding "set" routine for the backward problem */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; idals_jtsetup = (jtsetupB == NULL) ? NULL : idaLsJacTimesSetupB; - idals_jtimes = (jtimesB == NULL) ? NULL : idaLsJacTimesVecB; - return(IDASetJacTimes(ida_memB, idals_jtsetup, idals_jtimes)); + idals_jtimes = (jtimesB == NULL) ? NULL : idaLsJacTimesVecB; + return (IDASetJacTimes(ida_memB, idals_jtsetup, idals_jtimes)); } - -int IDASetJacTimesBS(void *ida_mem, int which, - IDALsJacTimesSetupFnBS jtsetupBS, +int IDASetJacTimesBS(void* ida_mem, int which, IDALsJacTimesSetupFnBS jtsetupBS, IDALsJacTimesVecFnBS jtimesBS) { - IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; - void *ida_memB; - IDALsMemB idalsB_mem; + IDAadjMem IDAADJ_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; + void* ida_memB; + IDALsMemB idalsB_mem; IDALsJacTimesSetupFn idals_jtsetup; - IDALsJacTimesVecFn idals_jtimes; - int retval; + IDALsJacTimesVecFn idals_jtimes; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetJacTimesBS", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* Set jacobian routines for the backward problem. */ idalsB_mem->jtsetupBS = jtsetupBS; idalsB_mem->jtimesBS = jtimesBS; /* Call the corresponding "set" routine for the backward problem */ - ida_memB = (void *) IDAB_mem->IDA_mem; + ida_memB = (void*)IDAB_mem->IDA_mem; idals_jtsetup = (jtsetupBS == NULL) ? NULL : idaLsJacTimesSetupBS; - idals_jtimes = (jtimesBS == NULL) ? NULL : idaLsJacTimesVecBS; - return(IDASetJacTimes(ida_memB, idals_jtsetup, idals_jtimes)); + idals_jtimes = (jtimesBS == NULL) ? NULL : idaLsJacTimesVecBS; + return (IDASetJacTimes(ida_memB, idals_jtsetup, idals_jtimes)); } - -int IDASetJacTimesResFnB(void *ida_mem, int which, IDAResFn jtimesResFn) +int IDASetJacTimesResFnB(void* ida_mem, int which, IDAResFn jtimesResFn) { - IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; - IDALsMemB idalsB_mem; - void *ida_memB; - int retval; + IDAadjMem IDAADJ_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; + IDALsMemB idalsB_mem; + void* ida_memB; + int retval; /* access relevant memory structures */ retval = idaLs_AccessLMemB(ida_mem, which, "IDASetJacTimesResFnB", &IDA_mem, &IDAADJ_mem, &IDAB_mem, &idalsB_mem); - if (retval != IDALS_SUCCESS) return(retval); + if (retval != IDALS_SUCCESS) { return (retval); } /* call corresponding routine for IDAB_mem structure */ - ida_memB = (void *) IDAB_mem->IDA_mem; - return(IDASetJacTimesResFn(ida_memB, jtimesResFn)); + ida_memB = (void*)IDAB_mem->IDA_mem; + return (IDASetJacTimesResFn(ida_memB, jtimesResFn)); } - /*----------------------------------------------------------------- IDASLS Private functions for backwards problems -----------------------------------------------------------------*/ /* idaLsJacBWrapper interfaces to the IDAJacFnB routine provided by the user. idaLsJacBWrapper is of type IDALsJacFn. */ -static int idaLsJacBWrapper(realtype tt, realtype c_jB, N_Vector yyB, +static int idaLsJacBWrapper(sunrealtype tt, sunrealtype c_jB, N_Vector yyB, N_Vector ypB, N_Vector rrB, SUNMatrix JacB, - void *ida_mem, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B) + void* ida_mem, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - int retval; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacBWrapper", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Forward solution from interpolation */ - if (IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacBWrapper", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jacB routine */ - return(idalsB_mem->jacB(tt, c_jB, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, ypB, - rrB, JacB, IDAB_mem->ida_user_data, - tmp1B, tmp2B, tmp3B)); + return (idalsB_mem->jacB(tt, c_jB, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, rrB, JacB, IDAB_mem->ida_user_data, tmp1B, + tmp2B, tmp3B)); } /* idaLsJacBSWrapper interfaces to the IDAJacFnBS routine provided by the user. idaLsJacBSWrapper is of type IDALsJacFn. */ -static int idaLsJacBSWrapper(realtype tt, realtype c_jB, N_Vector yyB, +static int idaLsJacBSWrapper(sunrealtype tt, sunrealtype c_jB, N_Vector yyB, N_Vector ypB, N_Vector rrB, SUNMatrix JacB, - void *ida_mem, N_Vector tmp1B, - N_Vector tmp2B, N_Vector tmp3B) + void* ida_mem, N_Vector tmp1B, N_Vector tmp2B, + N_Vector tmp3B) { IDAadjMem IDAADJ_mem; - IDAMem IDA_mem; - IDABMem IDAB_mem; + IDAMem IDA_mem; + IDABMem IDAB_mem; IDALsMemB idalsB_mem; - int retval; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacBSWrapper", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if(IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + } else + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); + } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacBSWrapper", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jacBS routine */ - return(idalsB_mem->jacBS(tt, c_jB, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, - IDAADJ_mem->ia_ypSTmp, yyB, ypB, rrB, JacB, - IDAB_mem->ida_user_data, tmp1B, tmp2B, tmp3B)); + return (idalsB_mem->jacBS(tt, c_jB, IDAADJ_mem->ia_yyTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypSTmp, yyB, ypB, rrB, JacB, + IDAB_mem->ida_user_data, tmp1B, tmp2B, tmp3B)); } - /* idaLsPrecSetupB interfaces to the IDALsPrecSetupFnB routine provided by the user */ -static int idaLsPrecSetupB(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, realtype c_jB, void *ida_mem) +static int idaLsPrecSetupB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsPrecSetupB", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp==SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsPrecSetupB", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint precondB routine */ - return(idalsB_mem->psetB(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, ypB, rrB, - c_jB, IDAB_mem->ida_user_data)); + return (idalsB_mem->psetB(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, yyB, + ypB, rrB, c_jB, IDAB_mem->ida_user_data)); } - /* idaLsPrecSetupBS interfaces to the IDALsPrecSetupFnBS routine provided by the user */ -static int idaLsPrecSetupBS(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, realtype c_jB, void *ida_mem) +static int idaLsPrecSetupBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsPrecSetupBS", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if(IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + } else + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsPrecSetupBS", MSG_LS_BAD_T); - return(-1); + } + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint precondBS routine */ - return(idalsB_mem->psetBS(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, - IDAADJ_mem->ia_ypSTmp, yyB, ypB, - rrB, c_jB, IDAB_mem->ida_user_data)); + return (idalsB_mem->psetBS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, yyB, + ypB, rrB, c_jB, IDAB_mem->ida_user_data)); } - /* idaLsPrecSolveB interfaces to the IDALsPrecSolveFnB routine provided by the user */ -static int idaLsPrecSolveB(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, N_Vector rvecB, - N_Vector zvecB, realtype c_jB, - realtype deltaB, void *ida_mem) +static int idaLsPrecSolveB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector rvecB, N_Vector zvecB, + sunrealtype c_jB, sunrealtype deltaB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsPrecSolveB", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp==SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsPrecSolveB", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint psolveB routine */ - return(idalsB_mem->psolveB(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, ypB, - rrB, rvecB, zvecB, c_jB, deltaB, - IDAB_mem->ida_user_data)); + return (idalsB_mem->psolveB(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, rrB, rvecB, zvecB, c_jB, deltaB, + IDAB_mem->ida_user_data)); } - /* idaLsPrecSolveBS interfaces to the IDALsPrecSolveFnBS routine provided by the user */ -static int idaLsPrecSolveBS(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, N_Vector rvecB, - N_Vector zvecB, realtype c_jB, - realtype deltaB, void *ida_mem) +static int idaLsPrecSolveBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, N_Vector rvecB, N_Vector zvecB, + sunrealtype c_jB, sunrealtype deltaB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsPrecSolveBS", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if(IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + } else + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsPrecSolveBS", MSG_LS_BAD_T); - return(-1); + } + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint psolveBS routine */ - return(idalsB_mem->psolveBS(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, - IDAADJ_mem->ia_ypSTmp, - yyB, ypB, rrB, rvecB, zvecB, c_jB, - deltaB, IDAB_mem->ida_user_data)); + return (idalsB_mem->psolveBS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, + yyB, ypB, rrB, rvecB, zvecB, c_jB, deltaB, + IDAB_mem->ida_user_data)); } - /* idaLsJacTimesSetupB interfaces to the IDALsJacTimesSetupFnB routine provided by the user */ -static int idaLsJacTimesSetupB(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, realtype c_jB, void *ida_mem) +static int idaLsJacTimesSetupB(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacTimesSetupB", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp==SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacTimesSetupB", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jtsetupB routine */ - return(idalsB_mem->jtsetupB(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, - ypB, rrB, c_jB, IDAB_mem->ida_user_data)); + return (idalsB_mem->jtsetupB(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, rrB, c_jB, IDAB_mem->ida_user_data)); } - /* idaLsJacTimesSetupBS interfaces to the IDALsJacTimesSetupFnBS routine provided by the user */ -static int idaLsJacTimesSetupBS(realtype tt, N_Vector yyB, N_Vector ypB, - N_Vector rrB, realtype c_jB, void *ida_mem) +static int idaLsJacTimesSetupBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, + N_Vector rrB, sunrealtype c_jB, void* ida_mem) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacTimesSetupBS", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if(IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + } else + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacTimesSetupBS", MSG_LS_BAD_T); - return(-1); + } + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jtimesBS routine */ - return(idalsB_mem->jtsetupBS(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, - IDAADJ_mem->ia_ypSTmp, - yyB, ypB, rrB, c_jB, - IDAB_mem->ida_user_data)); + return (idalsB_mem->jtsetupBS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, + yyB, ypB, rrB, c_jB, IDAB_mem->ida_user_data)); } - /* idaLsJacTimesVecB interfaces to the IDALsJacTimesVecFnB routine provided by the user */ -static int idaLsJacTimesVecB(realtype tt, N_Vector yyB, N_Vector ypB, +static int idaLsJacTimesVecB(sunrealtype tt, N_Vector yyB, N_Vector ypB, N_Vector rrB, N_Vector vB, N_Vector JvB, - realtype c_jB, void *ida_mem, - N_Vector tmp1B, N_Vector tmp2B) + sunrealtype c_jB, void* ida_mem, N_Vector tmp1B, + N_Vector tmp2B) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacTimesVecB", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if (IDAADJ_mem->ia_noInterp==SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacTimesVecB", MSG_LS_BAD_T); - return(-1); + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jtimesB routine */ - return(idalsB_mem->jtimesB(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, yyB, - ypB, rrB, vB, JvB, c_jB, - IDAB_mem->ida_user_data, - tmp1B, tmp2B)); + return (idalsB_mem->jtimesB(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + yyB, ypB, rrB, vB, JvB, c_jB, + IDAB_mem->ida_user_data, tmp1B, tmp2B)); } - /* idaLsJacTimesVecBS interfaces to the IDALsJacTimesVecFnBS routine provided by the user */ -static int idaLsJacTimesVecBS(realtype tt, N_Vector yyB, N_Vector ypB, +static int idaLsJacTimesVecBS(sunrealtype tt, N_Vector yyB, N_Vector ypB, N_Vector rrB, N_Vector vB, N_Vector JvB, - realtype c_jB, void *ida_mem, - N_Vector tmp1B, N_Vector tmp2B) + sunrealtype c_jB, void* ida_mem, N_Vector tmp1B, + N_Vector tmp2B) { - IDAMem IDA_mem; + IDAMem IDA_mem; IDAadjMem IDAADJ_mem; IDALsMemB idalsB_mem; - IDABMem IDAB_mem; - int retval; + IDABMem IDAB_mem; + int retval; /* access relevant memory structures */ - IDA_mem = NULL; + IDA_mem = NULL; IDAADJ_mem = NULL; idalsB_mem = NULL; - IDAB_mem = NULL; - retval = idaLs_AccessLMemBCur(ida_mem, "idaLsJacTimesVecBS", &IDA_mem, - &IDAADJ_mem, &IDAB_mem, &idalsB_mem); + IDAB_mem = NULL; + retval = idaLs_AccessLMemBCur(ida_mem, __func__, &IDA_mem, &IDAADJ_mem, + &IDAB_mem, &idalsB_mem); /* Get forward solution from interpolation. */ - if(IDAADJ_mem->ia_noInterp == SUNFALSE) { + if (IDAADJ_mem->ia_noInterp == SUNFALSE) + { if (IDAADJ_mem->ia_interpSensi) + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, + IDAADJ_mem->ia_ypTmp, IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp); + } else + { retval = IDAADJ_mem->ia_getY(IDA_mem, tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, NULL, NULL); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDAB_mem->IDA_mem, -1, "IDASLS", - "idaLsJacTimesVecBS", MSG_LS_BAD_T); - return(-1); + } + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDAB_mem->IDA_mem, -1, __LINE__, __func__, __FILE__, + MSG_LS_BAD_T); + return (-1); } } /* Call user's adjoint jtimesBS routine */ - return(idalsB_mem->jtimesBS(tt, IDAADJ_mem->ia_yyTmp, - IDAADJ_mem->ia_ypTmp, - IDAADJ_mem->ia_yySTmp, - IDAADJ_mem->ia_ypSTmp, - yyB, ypB, rrB, vB, JvB, c_jB, - IDAB_mem->ida_user_data, tmp1B, tmp2B)); + return (idalsB_mem->jtimesBS(tt, IDAADJ_mem->ia_yyTmp, IDAADJ_mem->ia_ypTmp, + IDAADJ_mem->ia_yySTmp, IDAADJ_mem->ia_ypSTmp, + yyB, ypB, rrB, vB, JvB, c_jB, + IDAB_mem->ida_user_data, tmp1B, tmp2B)); } - /* idaLsFreeB frees memory associated with the IDASLS wrapper */ int idaLsFreeB(IDABMem IDAB_mem) { IDALsMemB idalsB_mem; /* Return immediately if IDAB_mem or IDAB_mem->ida_lmem are NULL */ - if (IDAB_mem == NULL) return(IDALS_SUCCESS); - if (IDAB_mem->ida_lmem == NULL) return(IDALS_SUCCESS); - idalsB_mem = (IDALsMemB) IDAB_mem->ida_lmem; + if (IDAB_mem == NULL) { return (IDALS_SUCCESS); } + if (IDAB_mem->ida_lmem == NULL) { return (IDALS_SUCCESS); } + idalsB_mem = (IDALsMemB)IDAB_mem->ida_lmem; /* free IDALsMemB interface structure */ free(idalsB_mem); - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* idaLs_AccessLMemB unpacks the IDA_mem, IDAADJ_mem, IDAB_mem and idalsB_mem structures from the void* ida_mem pointer. If any are missing it returns IDALS_MEM_NULL, IDALS_NO_ADJ, IDAS_ILL_INPUT, or IDALS_LMEMB_NULL. */ -int idaLs_AccessLMemB(void *ida_mem, int which, const char *fname, - IDAMem *IDA_mem, IDAadjMem *IDAADJ_mem, - IDABMem *IDAB_mem, IDALsMemB *idalsB_mem) +int idaLs_AccessLMemB(void* ida_mem, int which, const char* fname, + IDAMem* IDA_mem, IDAadjMem* IDAADJ_mem, IDABMem* IDAB_mem, + IDALsMemB* idalsB_mem) { - /* access IDAMem structure */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - fname, MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } - *IDA_mem = (IDAMem) ida_mem; + *IDA_mem = (IDAMem)ida_mem; /* access IDAadjMem structure */ - if ((*IDA_mem)->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(*IDA_mem, IDALS_NO_ADJ, "IDASLS", - fname, MSG_LS_NO_ADJ); - return(IDALS_NO_ADJ); + if ((*IDA_mem)->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(*IDA_mem, IDALS_NO_ADJ, __LINE__, fname, __FILE__, + MSG_LS_NO_ADJ); + return (IDALS_NO_ADJ); } *IDAADJ_mem = (*IDA_mem)->ida_adj_mem; /* Check the value of which */ - if ( which >= (*IDAADJ_mem)->ia_nbckpbs ) { - IDAProcessError(*IDA_mem, IDALS_ILL_INPUT, "IDASLS", - fname, MSG_LS_BAD_WHICH); - return(IDALS_ILL_INPUT); + if (which >= (*IDAADJ_mem)->ia_nbckpbs) + { + IDAProcessError(*IDA_mem, IDALS_ILL_INPUT, __LINE__, fname, __FILE__, + MSG_LS_BAD_WHICH); + return (IDALS_ILL_INPUT); } /* Find the IDABMem entry in the linked list corresponding to which */ *IDAB_mem = (*IDAADJ_mem)->IDAB_mem; - while ((*IDAB_mem) != NULL) { - if ( which == (*IDAB_mem)->ida_index ) break; + while ((*IDAB_mem) != NULL) + { + if (which == (*IDAB_mem)->ida_index) { break; } *IDAB_mem = (*IDAB_mem)->ida_next; } /* access IDALsMemB structure */ - if ((*IDAB_mem)->ida_lmem == NULL) { - IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, "IDASLS", - fname, MSG_LS_LMEMB_NULL); - return(IDALS_LMEMB_NULL); + if ((*IDAB_mem)->ida_lmem == NULL) + { + IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, __LINE__, __func__, __FILE__, + MSG_LS_LMEMB_NULL); + return (IDALS_LMEMB_NULL); } - *idalsB_mem = (IDALsMemB) ((*IDAB_mem)->ida_lmem); + *idalsB_mem = (IDALsMemB)((*IDAB_mem)->ida_lmem); - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /* idaLs_AccessLMemBCur unpacks the ida_mem, ca_mem, idaB_mem and idalsB_mem structures from the void* ida_mem pointer. If any are missing it returns IDALS_MEM_NULL, IDALS_NO_ADJ, or IDALS_LMEMB_NULL. */ -int idaLs_AccessLMemBCur(void *ida_mem, const char *fname, - IDAMem *IDA_mem, IDAadjMem *IDAADJ_mem, - IDABMem *IDAB_mem, IDALsMemB *idalsB_mem) +int idaLs_AccessLMemBCur(void* ida_mem, const char* fname, IDAMem* IDA_mem, + IDAadjMem* IDAADJ_mem, IDABMem* IDAB_mem, + IDALsMemB* idalsB_mem) { - /* access IDAMem structure */ - if (ida_mem==NULL) { - IDAProcessError(NULL, IDALS_MEM_NULL, "IDASLS", - fname, MSG_LS_IDAMEM_NULL); - return(IDALS_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDALS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_IDAMEM_NULL); + return (IDALS_MEM_NULL); } - *IDA_mem = (IDAMem) ida_mem; + *IDA_mem = (IDAMem)ida_mem; /* access IDAadjMem structure */ - if ((*IDA_mem)->ida_adjMallocDone == SUNFALSE) { - IDAProcessError(*IDA_mem, IDALS_NO_ADJ, "IDASLS", - fname, MSG_LS_NO_ADJ); - return(IDALS_NO_ADJ); + if ((*IDA_mem)->ida_adjMallocDone == SUNFALSE) + { + IDAProcessError(*IDA_mem, IDALS_NO_ADJ, __LINE__, fname, __FILE__, + MSG_LS_NO_ADJ); + return (IDALS_NO_ADJ); } *IDAADJ_mem = (*IDA_mem)->ida_adj_mem; /* get current backward problem */ - if ((*IDAADJ_mem)->ia_bckpbCrt == NULL) { - IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, "IDASLS", - fname, MSG_LS_LMEMB_NULL); - return(IDALS_LMEMB_NULL); + if ((*IDAADJ_mem)->ia_bckpbCrt == NULL) + { + IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEMB_NULL); + return (IDALS_LMEMB_NULL); } *IDAB_mem = (*IDAADJ_mem)->ia_bckpbCrt; /* access IDALsMemB structure */ - if ((*IDAB_mem)->ida_lmem == NULL) { - IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, "IDASLS", - fname, MSG_LS_LMEMB_NULL); - return(IDALS_LMEMB_NULL); + if ((*IDAB_mem)->ida_lmem == NULL) + { + IDAProcessError(*IDA_mem, IDALS_LMEMB_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEMB_NULL); + return (IDALS_LMEMB_NULL); } - *idalsB_mem = (IDALsMemB) ((*IDAB_mem)->ida_lmem); + *idalsB_mem = (IDALsMemB)((*IDAB_mem)->ida_lmem); - return(IDALS_SUCCESS); + return (IDALS_SUCCESS); } - /*--------------------------------------------------------------- EOF ---------------------------------------------------------------*/ diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls_impl.h b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls_impl.h index 41383bcf3..f219cb1d3 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls_impl.h +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_ls_impl.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,9 +19,10 @@ #define _IDASLS_IMPL_H #include + #include "idas_impl.h" -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -32,51 +33,53 @@ extern "C" { structure containing fields that must be accessible by LS module routines. -----------------------------------------------------------------*/ -typedef struct IDALsMemRec { - +typedef struct IDALsMemRec +{ /* Linear solver type information */ - booleantype iterative; /* is the solver iterative? */ - booleantype matrixbased; /* is a matrix structure used? */ + sunbooleantype iterative; /* is the solver iterative? */ + sunbooleantype matrixbased; /* is a matrix structure used? */ /* Jacobian construction & storage */ - booleantype jacDQ; /* SUNTRUE if using internal DQ Jacobian approx. */ + sunbooleantype jacDQ; /* SUNTRUE if using internal DQ Jacobian approx. */ IDALsJacFn jac; /* Jacobian routine to be called */ - void *J_data; /* J_data is passed to jac */ + void* J_data; /* J_data is passed to jac */ /* Linear solver, matrix and vector objects/pointers */ - SUNLinearSolver LS; /* generic linear solver object */ - SUNMatrix J; /* J = dF/dy + cj*dF/dy' */ - N_Vector ytemp; /* temp vector used by IDAAtimesDQ */ - N_Vector yptemp; /* temp vector used by IDAAtimesDQ */ - N_Vector x; /* temp vector used by the solve function */ - N_Vector ycur; /* current y vector in Newton iteration */ - N_Vector ypcur; /* current yp vector in Newton iteration */ - N_Vector rcur; /* rcur = F(tn, ycur, ypcur) */ + SUNLinearSolver LS; /* generic linear solver object */ + SUNMatrix J; /* J = dF/dy + cj*dF/dy' */ + N_Vector ytemp; /* temp vector used by IDAAtimesDQ */ + N_Vector yptemp; /* temp vector used by IDAAtimesDQ */ + N_Vector x; /* temp vector used by the solve function */ + N_Vector ycur; /* current y vector in Newton iteration */ + N_Vector ypcur; /* current yp vector in Newton iteration */ + N_Vector rcur; /* rcur = F(tn, ycur, ypcur) */ /* Matrix-based solver, scale solution to account for change in cj */ - booleantype scalesol; + sunbooleantype scalesol; /* Iterative solver tolerance */ - realtype eplifac; /* nonlinear -> linear tol scaling factor */ - realtype nrmfac; /* integrator -> LS norm conversion factor */ + sunrealtype eplifac; /* nonlinear -> linear tol scaling factor */ + sunrealtype nrmfac; /* integrator -> LS norm conversion factor */ /* Statistics and associated parameters */ - realtype dqincfac; /* dqincfac = optional increment factor in Jv */ - long int nje; /* nje = no. of calls to jac */ - long int npe; /* npe = total number of precond calls */ - long int nli; /* nli = total number of linear iterations */ - long int nps; /* nps = total number of psolve calls */ - long int ncfl; /* ncfl = total number of convergence failures */ - long int nreDQ; /* nreDQ = total number of calls to res */ - long int njtsetup; /* njtsetup = total number of calls to jtsetup */ - long int njtimes; /* njtimes = total number of calls to jtimes */ - long int nst0; /* nst0 = saved nst (for performance monitor) */ - long int nni0; /* nni0 = saved nni (for performance monitor) */ - long int ncfn0; /* ncfn0 = saved ncfn (for performance monitor) */ - long int ncfl0; /* ncfl0 = saved ncfl (for performance monitor) */ - long int nwarn; /* nwarn = no. of warnings (for perf. monitor) */ - - int last_flag; /* last error return flag */ + sunrealtype dqincfac; /* dqincfac = optional increment factor in Jv */ + long int nje; /* nje = no. of calls to jac */ + long int npe; /* npe = total number of precond calls */ + long int nli; /* nli = total number of linear iterations */ + long int nps; /* nps = total number of psolve calls */ + long int ncfl; /* ncfl = total number of convergence failures */ + long int nreDQ; /* nreDQ = total number of calls to res */ + long int njtsetup; /* njtsetup = total number of calls to jtsetup */ + long int njtimes; /* njtimes = total number of calls to jtimes */ + long int nst0; /* nst0 = saved nst (for performance monitor) */ + long int nni0; /* nni0 = saved nni (for performance monitor) */ + long int ncfn0; /* ncfn0 = saved ncfn (for performance monitor) */ + long int ncfl0; /* ncfl0 = saved ncfl (for performance monitor) */ + long int nwarn; /* nwarn = no. of warnings (for perf. monitor) */ + long int nstlj; /* nstlj = nst at last jac/pset call */ + sunrealtype tnlj; /* tnlj = t_n at last jac/pset call */ + + int last_flag; /* last error return flag */ /* Preconditioner computation (a) user-provided: @@ -88,7 +91,7 @@ typedef struct IDALsMemRec { IDALsPrecSetupFn pset; IDALsPrecSolveFn psolve; int (*pfree)(IDAMem IDA_mem); - void *pdata; + void* pdata; /* Jacobian times vector compuation (a) jtimes function provided by the user: @@ -97,58 +100,51 @@ typedef struct IDALsMemRec { (b) internal jtimes - jt_data == ida_mem - jtimesDQ == SUNTRUE */ - booleantype jtimesDQ; + sunbooleantype jtimesDQ; IDALsJacTimesSetupFn jtsetup; IDALsJacTimesVecFn jtimes; IDAResFn jt_res; - void *jt_data; - -} *IDALsMem; + void* jt_data; +}* IDALsMem; /*----------------------------------------------------------------- Prototypes of internal functions -----------------------------------------------------------------*/ /* Interface routines called by system SUNLinearSolver */ -int idaLsATimes(void *ida_mem, N_Vector v, N_Vector z); -int idaLsPSetup(void *ida_mem); -int idaLsPSolve(void *ida_mem, N_Vector r, N_Vector z, - realtype tol, int lr); +int idaLsATimes(void* ida_mem, N_Vector v, N_Vector z); +int idaLsPSetup(void* ida_mem); +int idaLsPSolve(void* ida_mem, N_Vector r, N_Vector z, sunrealtype tol, int lr); /* Difference quotient approximation for Jac times vector */ -int idaLsDQJtimes(realtype tt, N_Vector yy, N_Vector yp, - N_Vector rr, N_Vector v, N_Vector Jv, - realtype c_j, void *data, +int idaLsDQJtimes(sunrealtype tt, N_Vector yy, N_Vector yp, N_Vector rr, + N_Vector v, N_Vector Jv, sunrealtype c_j, void* data, N_Vector work1, N_Vector work2); /* Difference-quotient Jacobian approximation routines */ -int idaLsDQJac(realtype tt, realtype c_j, N_Vector yy, N_Vector yp, - N_Vector rr, SUNMatrix Jac, void *data, - N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); -int idaLsDenseDQJac(realtype tt, realtype c_j, N_Vector yy, - N_Vector yp, N_Vector rr, SUNMatrix Jac, - IDAMem IDA_mem, N_Vector tmp1); -int idaLsBandDQJac(realtype tt, realtype c_j, N_Vector yy, - N_Vector yp, N_Vector rr, SUNMatrix Jac, - IDAMem IDA_mem, N_Vector tmp1, +int idaLsDQJac(sunrealtype tt, sunrealtype c_j, N_Vector yy, N_Vector yp, + N_Vector rr, SUNMatrix Jac, void* data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); +int idaLsDenseDQJac(sunrealtype tt, sunrealtype c_j, N_Vector yy, N_Vector yp, + N_Vector rr, SUNMatrix Jac, IDAMem IDA_mem, N_Vector tmp1); +int idaLsBandDQJac(sunrealtype tt, sunrealtype c_j, N_Vector yy, N_Vector yp, + N_Vector rr, SUNMatrix Jac, IDAMem IDA_mem, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); /* Generic linit/lsetup/lsolve/lperf/lfree interface routines for IDA to call */ int idaLsInitialize(IDAMem IDA_mem); int idaLsSetup(IDAMem IDA_mem, N_Vector y, N_Vector yp, N_Vector r, N_Vector vt1, N_Vector vt2, N_Vector vt3); -int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, - N_Vector ycur, N_Vector ypcur, N_Vector rescur); +int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, + N_Vector ypcur, N_Vector rescur); int idaLsPerf(IDAMem IDA_mem, int perftask); int idaLsFree(IDAMem IDA_mem); - /* Auxilliary functions */ int idaLsInitializeCounters(IDALsMem idals_mem); -int idaLs_AccessLMem(void* ida_mem, const char* fname, - IDAMem* IDA_mem, IDALsMem* idals_mem); - +int idaLs_AccessLMem(void* ida_mem, const char* fname, IDAMem* IDA_mem, + IDALsMem* idals_mem); /*--------------------------------------------------------------- Error and Warning Messages @@ -166,28 +162,37 @@ int idaLs_AccessLMem(void* ida_mem, const char* fname, #endif /* Error Messages */ -#define MSG_LS_IDAMEM_NULL "Integrator memory is NULL." -#define MSG_LS_MEM_FAIL "A memory request failed." -#define MSG_LS_BAD_NVECTOR "A required vector operation is not implemented." -#define MSG_LS_BAD_SIZES "Illegal bandwidth parameter(s). Must have 0 <= ml, mu <= N-1." -#define MSG_LS_BAD_LSTYPE "Incompatible linear solver type." -#define MSG_LS_LMEM_NULL "Linear solver memory is NULL." -#define MSG_LS_BAD_GSTYPE "gstype has an illegal value." -#define MSG_LS_NEG_MAXRS "maxrs < 0 illegal." -#define MSG_LS_NEG_EPLIFAC "eplifac < 0.0 illegal." -#define MSG_LS_NEG_DQINCFAC "dqincfac < 0.0 illegal." -#define MSG_LS_PSET_FAILED "The preconditioner setup routine failed in an unrecoverable manner." -#define MSG_LS_PSOLVE_FAILED "The preconditioner solve routine failed in an unrecoverable manner." -#define MSG_LS_JTSETUP_FAILED "The Jacobian x vector setup routine failed in an unrecoverable manner." -#define MSG_LS_JTIMES_FAILED "The Jacobian x vector routine failed in an unrecoverable manner." -#define MSG_LS_JACFUNC_FAILED "The Jacobian routine failed in an unrecoverable manner." -#define MSG_LS_MATZERO_FAILED "The SUNMatZero routine failed in an unrecoverable manner." +#define MSG_LS_IDAMEM_NULL "Integrator memory is NULL." +#define MSG_LS_MEM_FAIL "A memory request failed." +#define MSG_LS_BAD_NVECTOR "A required vector operation is not implemented." +#define MSG_LS_BAD_SIZES \ + "Illegal bandwidth parameter(s). Must have 0 <= ml, mu <= N-1." +#define MSG_LS_BAD_LSTYPE "Incompatible linear solver type." +#define MSG_LS_LMEM_NULL "Linear solver memory is NULL." +#define MSG_LS_BAD_GSTYPE "gstype has an illegal value." +#define MSG_LS_NEG_MAXRS "maxrs < 0 illegal." +#define MSG_LS_NEG_EPLIFAC "eplifac < 0.0 illegal." +#define MSG_LS_NEG_DQINCFAC "dqincfac < 0.0 illegal." +#define MSG_LS_PSET_FAILED \ + "The preconditioner setup routine failed in an unrecoverable manner." +#define MSG_LS_PSOLVE_FAILED \ + "The preconditioner solve routine failed in an unrecoverable manner." +#define MSG_LS_JTSETUP_FAILED \ + "The Jacobian x vector setup routine failed in an unrecoverable manner." +#define MSG_LS_JTIMES_FAILED \ + "The Jacobian x vector routine failed in an unrecoverable manner." +#define MSG_LS_JACFUNC_FAILED \ + "The Jacobian routine failed in an unrecoverable manner." +#define MSG_LS_MATZERO_FAILED \ + "The SUNMatZero routine failed in an unrecoverable manner." /* Warning Messages */ -#define MSG_LS_WARN "Warning: " MSG_LS_TIME "poor iterative algorithm performance. " -#define MSG_LS_CFN_WARN MSG_LS_WARN "Nonlinear convergence failure rate is " MSG_LS_FRMT -#define MSG_LS_CFL_WARN MSG_LS_WARN "Linear convergence failure rate is " MSG_LS_FRMT - +#define MSG_LS_WARN \ + "Warning: " MSG_LS_TIME "poor iterative algorithm performance. " +#define MSG_LS_CFN_WARN \ + MSG_LS_WARN "Nonlinear convergence failure rate is " MSG_LS_FRMT +#define MSG_LS_CFL_WARN \ + MSG_LS_WARN "Linear convergence failure rate is " MSG_LS_FRMT /*----------------------------------------------------------------- PART II - backward problems @@ -199,45 +204,43 @@ int idaLs_AccessLMem(void* ida_mem, const char* fname, IDASetLinearSolverB attaches such a structure to the lmemB field of IDAadjMem -----------------------------------------------------------------*/ -typedef struct IDALsMemRecB { - - IDALsJacFnB jacB; - IDALsJacFnBS jacBS; - IDALsJacTimesSetupFnB jtsetupB; +typedef struct IDALsMemRecB +{ + IDALsJacFnB jacB; + IDALsJacFnBS jacBS; + IDALsJacTimesSetupFnB jtsetupB; IDALsJacTimesSetupFnBS jtsetupBS; - IDALsJacTimesVecFnB jtimesB; - IDALsJacTimesVecFnBS jtimesBS; - IDALsPrecSetupFnB psetB; - IDALsPrecSetupFnBS psetBS; - IDALsPrecSolveFnB psolveB; - IDALsPrecSolveFnBS psolveBS; - void *P_dataB; - -} *IDALsMemB; + IDALsJacTimesVecFnB jtimesB; + IDALsJacTimesVecFnBS jtimesBS; + IDALsPrecSetupFnB psetB; + IDALsPrecSetupFnBS psetBS; + IDALsPrecSolveFnB psolveB; + IDALsPrecSolveFnBS psolveBS; + void* P_dataB; +}* IDALsMemB; /*----------------------------------------------------------------- Prototypes of internal functions -----------------------------------------------------------------*/ int idaLsFreeB(IDABMem IDAB_mem); -int idaLs_AccessLMemB(void *ida_mem, int which, const char *fname, - IDAMem *IDA_mem, IDAadjMem *IDAADJ_mem, - IDABMem *IDAB_mem, IDALsMemB *idalsB_mem); -int idaLs_AccessLMemBCur(void *ida_mem, const char *fname, - IDAMem *IDA_mem, IDAadjMem *IDAADJ_mem, - IDABMem *IDAB_mem, IDALsMemB *idalsB_mem); - +int idaLs_AccessLMemB(void* ida_mem, int which, const char* fname, + IDAMem* IDA_mem, IDAadjMem* IDAADJ_mem, IDABMem* IDAB_mem, + IDALsMemB* idalsB_mem); +int idaLs_AccessLMemBCur(void* ida_mem, const char* fname, IDAMem* IDA_mem, + IDAadjMem* IDAADJ_mem, IDABMem* IDAB_mem, + IDALsMemB* idalsB_mem); /*----------------------------------------------------------------- Error Messages -----------------------------------------------------------------*/ -#define MSG_LS_CAMEM_NULL "idaadj_mem = NULL illegal." -#define MSG_LS_LMEMB_NULL "Linear solver memory is NULL for the backward integration." -#define MSG_LS_BAD_T "Bad t for interpolation." -#define MSG_LS_BAD_WHICH "Illegal value for which." -#define MSG_LS_NO_ADJ "Illegal attempt to call before calling IDAAdjInit." - +#define MSG_LS_CAMEM_NULL "idaadj_mem = NULL illegal." +#define MSG_LS_LMEMB_NULL \ + "Linear solver memory is NULL for the backward integration." +#define MSG_LS_BAD_T "Bad t for interpolation." +#define MSG_LS_BAD_WHICH "Illegal value for which." +#define MSG_LS_NO_ADJ "Illegal attempt to call before calling IDAAdjInit." #ifdef __cplusplus } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls.c index a48372703..17ba1e6b5 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,67 +18,69 @@ #include "sundials/sundials_math.h" /* constant macros */ -#define PT0001 RCONST(0.0001) /* real 0.0001 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWENTY RCONST(20.0) /* real 20.0 */ +#define PT0001 SUN_RCONST(0.0001) /* real 0.0001 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWENTY SUN_RCONST(20.0) /* real 20.0 */ /* nonlinear solver parameters */ -#define MAXIT 4 /* default max number of nonlinear iterations */ -#define RATEMAX RCONST(0.9) /* max convergence rate used in divergence check */ +#define MAXIT 4 /* default max number of nonlinear iterations */ +#define RATEMAX \ + SUN_RCONST(0.9) /* max convergence rate used in divergence check */ /* private functions passed to nonlinear solver */ static int idaNlsResidual(N_Vector ycor, N_Vector res, void* ida_mem); -static int idaNlsLSetup(booleantype jbad, booleantype* jcur, void* ida_mem); +static int idaNlsLSetup(sunbooleantype jbad, sunbooleantype* jcur, void* ida_mem); static int idaNlsLSolve(N_Vector delta, void* ida_mem); static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem); + sunrealtype tol, N_Vector ewt, void* ida_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int IDASetNonlinearSolver(void *ida_mem, SUNNonlinearSolver NLS) +int IDASetNonlinearSolver(void* ida_mem, SUNNonlinearSolver NLS) { IDAMem IDA_mem; int retval; /* return immediately if IDA memory is NULL */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASetNonlinearSolver", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* return immediately if NLS memory is NULL */ - if (NLS == NULL) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (NLS == NULL) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for allowed nonlinear solver types */ - if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS type must be SUNNONLINEARSOLVER_ROOTFIND"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* free any existing nonlinear solver */ if ((IDA_mem->NLS != NULL) && (IDA_mem->ownNLS)) + { retval = SUNNonlinSolFree(IDA_mem->NLS); + } /* set SUNNonlinearSolver pointer */ IDA_mem->NLS = NLS; @@ -89,90 +91,86 @@ int IDASetNonlinearSolver(void *ida_mem, SUNNonlinearSolver NLS) /* set the nonlinear residual function */ retval = SUNNonlinSolSetSysFn(IDA_mem->NLS, idaNlsResidual); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(IDA_mem->NLS, idaNlsConvTest, ida_mem); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(IDA_mem->NLS, MAXIT); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* Set the nonlinear system RES function */ - if (!(IDA_mem->ida_res)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolver", + if (!(IDA_mem->ida_res)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "The DAE residual function is NULL"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } IDA_mem->nls_res = IDA_mem->ida_res; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /*--------------------------------------------------------------- IDASetNlsResFn: This routine sets an alternative user-supplied DAE residual function to use in the evaluation of nonlinear system functions. ---------------------------------------------------------------*/ -int IDASetNlsResFn(void *ida_mem, IDAResFn res) +int IDASetNlsResFn(void* ida_mem, IDAResFn res) { IDAMem IDA_mem; - if (ida_mem==NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASetNlsResFn", - MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - if (res) - IDA_mem->nls_res = res; - else - IDA_mem->nls_res = IDA_mem->ida_res; + if (res) { IDA_mem->nls_res = res; } + else { IDA_mem->nls_res = IDA_mem->ida_res; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /*--------------------------------------------------------------- IDAGetNonlinearSystemData: This routine provides access to the relevant data needed to compute the nonlinear system function. ---------------------------------------------------------------*/ -int IDAGetNonlinearSystemData(void *ida_mem, realtype *tcur, N_Vector *yypred, - N_Vector *yppred, N_Vector *yyn, N_Vector *ypn, - N_Vector *res, realtype *cj, void **user_data) +int IDAGetNonlinearSystemData(void* ida_mem, sunrealtype* tcur, N_Vector* yypred, + N_Vector* yppred, N_Vector* yyn, N_Vector* ypn, + N_Vector* res, sunrealtype* cj, void** user_data) { IDAMem IDA_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNonlinearSystemData", - MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *tcur = IDA_mem->ida_tn; *yypred = IDA_mem->ida_yypredict; @@ -183,11 +181,9 @@ int IDAGetNonlinearSystemData(void *ida_mem, realtype *tcur, N_Vector *yypred, *cj = IDA_mem->ida_cj; *user_data = IDA_mem->ida_user_data; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ @@ -198,51 +194,57 @@ int idaNlsInit(IDAMem IDA_mem) /* set the linear solver setup wrapper function */ if (IDA_mem->ida_lsetup) + { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLS, idaNlsLSetup); - else - retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLS, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLS, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (IDA_mem->ida_lsolve) + { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLS, idaNlsLSolve); - else - retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLS, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLS, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(IDA_mem->NLS); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInit", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsLSetup(booleantype jbad, booleantype* jcur, void* ida_mem) +static int idaNlsLSetup(SUNDIALS_MAYBE_UNUSED sunbooleantype jbad, + sunbooleantype* jcur, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsLSetup", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_nsetups++; IDA_mem->ida_forceSetup = SUNFALSE; @@ -260,49 +262,49 @@ static int idaNlsLSetup(booleantype jbad, booleantype* jcur, void* ida_mem) IDA_mem->ida_ss = TWENTY; IDA_mem->ida_ssS = TWENTY; - if (retval < 0) return(IDA_LSETUP_FAIL); - if (retval > 0) return(IDA_LSETUP_RECVR); + if (retval < 0) { return (IDA_LSETUP_FAIL); } + if (retval > 0) { return (IDA_LSETUP_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsLSolve(N_Vector delta, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsLSolve", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - retval = IDA_mem->ida_lsolve(IDA_mem, delta, IDA_mem->ida_ewt, - IDA_mem->ida_yy, IDA_mem->ida_yp, - IDA_mem->ida_savres); + retval = IDA_mem->ida_lsolve(IDA_mem, delta, IDA_mem->ida_ewt, IDA_mem->ida_yy, + IDA_mem->ida_yp, IDA_mem->ida_savres); - if (retval < 0) return(IDA_LSOLVE_FAIL); - if (retval > 0) return(IDA_LSOLVE_RECVR); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IDA_LSOLVE_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsResidual(N_Vector ycor, N_Vector res, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsResidual", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* update yy and yp based on the current correction */ N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, ycor, IDA_mem->ida_yy); - N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, IDA_mem->ida_yp); + N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, + IDA_mem->ida_yp); /* evaluate residual */ retval = IDA_mem->nls_res(IDA_mem->ida_tn, IDA_mem->ida_yy, IDA_mem->ida_yp, @@ -314,46 +316,50 @@ static int idaNlsResidual(N_Vector ycor, N_Vector res, void* ida_mem) /* save a copy of the residual vector in savres */ N_VScale(ONE, res, IDA_mem->ida_savres); - if (retval < 0) return(IDA_RES_FAIL); - if (retval > 0) return(IDA_RES_RECVR); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IDA_RES_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem) +static int idaNlsConvTest(SUNNonlinearSolver NLS, + SUNDIALS_MAYBE_UNUSED N_Vector ycor, N_Vector del, + sunrealtype tol, N_Vector ewt, void* ida_mem) { IDAMem IDA_mem; int m, retval; - realtype delnrm; - realtype rate; + sunrealtype delnrm; + sunrealtype rate; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsConvTest", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != IDA_SUCCESS) return(IDA_MEM_NULL); + if (retval != IDA_SUCCESS) { return (IDA_MEM_NULL); } /* test for convergence, first directly, then with rate estimate. */ - if (m == 0){ + if (m == 0) + { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= PT0001 * IDA_mem->ida_toldel) return(SUN_NLS_SUCCESS); - } else { - rate = SUNRpowerR( delnrm/IDA_mem->ida_oldnrm, ONE/m ); - if (rate > RATEMAX) return(SUN_NLS_CONV_RECVR); - IDA_mem->ida_ss = rate/(ONE - rate); + if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_SUCCESS); } + } + else + { + rate = SUNRpowerR(delnrm / IDA_mem->ida_oldnrm, ONE / m); + if (rate > RATEMAX) { return (SUN_NLS_CONV_RECVR); } + IDA_mem->ida_ss = rate / (ONE - rate); } - if (IDA_mem->ida_ss*delnrm <= tol) return(SUN_NLS_SUCCESS); + if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_sim.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_sim.c index 60b30d435..d52718990 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_sim.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_sim.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,84 +19,87 @@ #include "sundials/sundials_nvector_senswrapper.h" /* constant macros */ -#define PT0001 RCONST(0.0001) /* real 0.0001 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWENTY RCONST(20.0) /* real 20.0 */ +#define PT0001 SUN_RCONST(0.0001) /* real 0.0001 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWENTY SUN_RCONST(20.0) /* real 20.0 */ /* nonlinear solver parameters */ -#define MAXIT 4 /* default max number of nonlinear iterations */ -#define RATEMAX RCONST(0.9) /* max convergence rate used in divergence check */ +#define MAXIT 4 /* default max number of nonlinear iterations */ +#define RATEMAX \ + SUN_RCONST(0.9) /* max convergence rate used in divergence check */ /* private functions passed to nonlinear solver */ static int idaNlsResidualSensSim(N_Vector ycor, N_Vector res, void* ida_mem); -static int idaNlsLSetupSensSim(booleantype jbad, booleantype* jcur, +static int idaNlsLSetupSensSim(sunbooleantype jbad, sunbooleantype* jcur, void* ida_mem); static int idaNlsLSolveSensSim(N_Vector delta, void* ida_mem); -static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem); +static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycor, + N_Vector del, sunrealtype tol, N_Vector ewt, + void* ida_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int IDASetNonlinearSolverSensSim(void *ida_mem, SUNNonlinearSolver NLS) +int IDASetNonlinearSolverSensSim(void* ida_mem, SUNNonlinearSolver NLS) { IDAMem IDA_mem; int retval, is; /* return immediately if IDA memory is NULL */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASetNonlinearSolverSensSim", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* return immediately if NLS memory is NULL */ - if (NLS == NULL) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (NLS == NULL) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for allowed nonlinear solver types */ - if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS type must be SUNNONLINEARSOLVER_ROOTFIND"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check that sensitivities were initialized */ - if (!(IDA_mem->ida_sensi)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (!(IDA_mem->ida_sensi)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_SENSI); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check that the simultaneous corrector was selected */ - if (IDA_mem->ida_ism != IDA_SIMULTANEOUS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (IDA_mem->ida_ism != IDA_SIMULTANEOUS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Sensitivity solution method is not IDA_SIMULTANEOUS"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* free any existing nonlinear solver */ if ((IDA_mem->NLSsim != NULL) && (IDA_mem->ownNLSsim)) + { retval = SUNNonlinSolFree(IDA_mem->NLSsim); + } /* set SUNNonlinearSolver pointer */ IDA_mem->NLSsim = NLS; @@ -107,57 +110,63 @@ int IDASetNonlinearSolverSensSim(void *ida_mem, SUNNonlinearSolver NLS) /* set the nonlinear residual function */ retval = SUNNonlinSolSetSysFn(IDA_mem->NLSsim, idaNlsResidualSensSim); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(IDA_mem->NLSsim, idaNlsConvTestSensSim, ida_mem); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(IDA_mem->NLSsim, MAXIT); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* create vector wrappers if necessary */ - if (IDA_mem->simMallocDone == SUNFALSE) { - - IDA_mem->ypredictSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns+1); - if (IDA_mem->ypredictSim == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensSim", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDA_mem->simMallocDone == SUNFALSE) + { + IDA_mem->ypredictSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns + 1, + IDA_mem->ida_sunctx); + if (IDA_mem->ypredictSim == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - IDA_mem->ycorSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns+1); - if (IDA_mem->ycorSim == NULL) { + IDA_mem->ycorSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns + 1, + IDA_mem->ida_sunctx); + if (IDA_mem->ycorSim == NULL) + { N_VDestroy(IDA_mem->ypredictSim); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensSim", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - IDA_mem->ewtSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns+1); - if (IDA_mem->ewtSim == NULL) { + IDA_mem->ewtSim = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns + 1, + IDA_mem->ida_sunctx); + if (IDA_mem->ewtSim == NULL) + { N_VDestroy(IDA_mem->ypredictSim); N_VDestroy(IDA_mem->ycorSim); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensSim", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } IDA_mem->simMallocDone = SUNTRUE; @@ -165,48 +174,48 @@ int IDASetNonlinearSolverSensSim(void *ida_mem, SUNNonlinearSolver NLS) /* attach vectors to vector wrappers */ NV_VEC_SW(IDA_mem->ypredictSim, 0) = IDA_mem->ida_yypredict; - NV_VEC_SW(IDA_mem->ycorSim, 0) = IDA_mem->ida_ee; - NV_VEC_SW(IDA_mem->ewtSim, 0) = IDA_mem->ida_ewt; - - for (is=0; is < IDA_mem->ida_Ns; is++) { - NV_VEC_SW(IDA_mem->ypredictSim, is+1) = IDA_mem->ida_yySpredict[is]; - NV_VEC_SW(IDA_mem->ycorSim, is+1) = IDA_mem->ida_eeS[is]; - NV_VEC_SW(IDA_mem->ewtSim, is+1) = IDA_mem->ida_ewtS[is]; + NV_VEC_SW(IDA_mem->ycorSim, 0) = IDA_mem->ida_ee; + NV_VEC_SW(IDA_mem->ewtSim, 0) = IDA_mem->ida_ewt; + + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + NV_VEC_SW(IDA_mem->ypredictSim, is + 1) = IDA_mem->ida_yySpredict[is]; + NV_VEC_SW(IDA_mem->ycorSim, is + 1) = IDA_mem->ida_eeS[is]; + NV_VEC_SW(IDA_mem->ewtSim, is + 1) = IDA_mem->ida_ewtS[is]; } /* Set the nonlinear system RES function */ - if (!(IDA_mem->ida_res)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensSim", + if (!(IDA_mem->ida_res)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "The DAE residual function is NULL"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } IDA_mem->nls_res = IDA_mem->ida_res; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /*--------------------------------------------------------------- IDAGetNonlinearSystemDataSens: This routine provides access to the relevant data needed to compute the nonlinear system function. ---------------------------------------------------------------*/ -int IDAGetNonlinearSystemDataSens(void *ida_mem, realtype *tcur, - N_Vector **yySpred, N_Vector **ypSpred, - N_Vector **yySn, N_Vector **ypSn, - realtype *cj, void **user_data) +int IDAGetNonlinearSystemDataSens(void* ida_mem, sunrealtype* tcur, + N_Vector** yySpred, N_Vector** ypSpred, + N_Vector** yySn, N_Vector** ypSn, + sunrealtype* cj, void** user_data) { IDAMem IDA_mem; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDAGetNonlinearSystemData", - MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; *tcur = IDA_mem->ida_tn; *yySpred = IDA_mem->ida_yySpredict; @@ -216,10 +225,9 @@ int IDAGetNonlinearSystemDataSens(void *ida_mem, realtype *tcur, *cj = IDA_mem->ida_cj; *user_data = IDA_mem->ida_user_data; - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ @@ -230,53 +238,57 @@ int idaNlsInitSensSim(IDAMem IDA_mem) /* set the linear solver setup wrapper function */ if (IDA_mem->ida_lsetup) + { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSsim, idaNlsLSetupSensSim); - else - retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSsim, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSsim, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSnesSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (IDA_mem->ida_lsolve) + { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSsim, idaNlsLSolveSensSim); - else - retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSsim, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSsim, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSnesSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(IDA_mem->NLSsim); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSnesSim", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsLSetupSensSim(booleantype jbad, booleantype* jcur, - void* ida_mem) +static int idaNlsLSetupSensSim(SUNDIALS_MAYBE_UNUSED sunbooleantype jbad, + sunbooleantype* jcur, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "idaNlsLSetupSensSim", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_nsetups++; IDA_mem->ida_forceSetup = SUNFALSE; @@ -289,60 +301,58 @@ static int idaNlsLSetupSensSim(booleantype jbad, booleantype* jcur, *jcur = SUNTRUE; /* update convergence test constants */ - IDA_mem->ida_cjold = IDA_mem->ida_cj; + IDA_mem->ida_cjold = IDA_mem->ida_cj; IDA_mem->ida_cjratio = ONE; - IDA_mem->ida_ss = TWENTY; - IDA_mem->ida_ssS = TWENTY; + IDA_mem->ida_ss = TWENTY; + IDA_mem->ida_ssS = TWENTY; - if (retval < 0) return(IDA_LSETUP_FAIL); - if (retval > 0) return(IDA_LSETUP_RECVR); + if (retval < 0) { return (IDA_LSETUP_FAIL); } + if (retval > 0) { return (IDA_LSETUP_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsLSolveSensSim(N_Vector deltaSim, void* ida_mem) { IDAMem IDA_mem; int retval, is; N_Vector delta; - N_Vector *deltaS; + N_Vector* deltaS; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "idaNlsLSolveSensSim", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* extract state update vector from the vector wrapper */ - delta = NV_VEC_SW(deltaSim,0); + delta = NV_VEC_SW(deltaSim, 0); /* solve the state linear system */ - retval = IDA_mem->ida_lsolve(IDA_mem, delta, IDA_mem->ida_ewt, - IDA_mem->ida_yy, IDA_mem->ida_yp, - IDA_mem->ida_savres); + retval = IDA_mem->ida_lsolve(IDA_mem, delta, IDA_mem->ida_ewt, IDA_mem->ida_yy, + IDA_mem->ida_yp, IDA_mem->ida_savres); - if (retval < 0) return(IDA_LSOLVE_FAIL); - if (retval > 0) return(IDA_LSOLVE_RECVR); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IDA_LSOLVE_RECVR); } /* extract sensitivity deltas from the vector wrapper */ - deltaS = NV_VECS_SW(deltaSim)+1; + deltaS = NV_VECS_SW(deltaSim) + 1; /* solve the sensitivity linear systems */ - for(is=0; isida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { retval = IDA_mem->ida_lsolve(IDA_mem, deltaS[is], IDA_mem->ida_ewtS[is], IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_savres); - if (retval < 0) return(IDA_LSOLVE_FAIL); - if (retval > 0) return(IDA_LSOLVE_RECVR); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IDA_LSOLVE_RECVR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, void* ida_mem) { IDAMem IDA_mem; @@ -350,20 +360,21 @@ static int idaNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, void* ida_me N_Vector ycor, res; N_Vector *ycorS, *resS; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "idaNlsResidualSensSim", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* extract state and residual vectors from the vector wrapper */ - ycor = NV_VEC_SW(ycorSim,0); - res = NV_VEC_SW(resSim,0); + ycor = NV_VEC_SW(ycorSim, 0); + res = NV_VEC_SW(resSim, 0); /* update yy and yp based on the current correction */ N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, ycor, IDA_mem->ida_yy); - N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, IDA_mem->ida_yp); + N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, + IDA_mem->ida_yp); /* evaluate residual */ retval = IDA_mem->nls_res(IDA_mem->ida_tn, IDA_mem->ida_yy, IDA_mem->ida_yp, @@ -375,71 +386,74 @@ static int idaNlsResidualSensSim(N_Vector ycorSim, N_Vector resSim, void* ida_me /* save a copy of the residual vector in savres */ N_VScale(ONE, res, IDA_mem->ida_savres); - if (retval < 0) return(IDA_RES_FAIL); - if (retval > 0) return(IDA_RES_RECVR); + if (retval < 0) { return (IDA_RES_FAIL); } + if (retval > 0) { return (IDA_RES_RECVR); } /* extract sensitivity and residual vectors from the vector wrapper */ - ycorS = NV_VECS_SW(ycorSim)+1; - resS = NV_VECS_SW(resSim)+1; + ycorS = NV_VECS_SW(ycorSim) + 1; + resS = NV_VECS_SW(resSim) + 1; /* update yS and ypS based on the current correction */ - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yySpredict, - ONE, ycorS, IDA_mem->ida_yyS); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_ypSpredict, + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yySpredict, ONE, + ycorS, IDA_mem->ida_yyS); + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_ypSpredict, IDA_mem->ida_cj, ycorS, IDA_mem->ida_ypS); /* evaluate sens residual */ - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_tn, - IDA_mem->ida_yy, IDA_mem->ida_yp, res, - IDA_mem->ida_yyS, IDA_mem->ida_ypS, resS, - IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, - IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_tn, IDA_mem->ida_yy, + IDA_mem->ida_yp, res, IDA_mem->ida_yyS, + IDA_mem->ida_ypS, resS, IDA_mem->ida_user_dataS, + IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, + IDA_mem->ida_tmpS3); /* increment the number of sens residual evaluations */ IDA_mem->ida_nrSe++; - if (retval < 0) return(IDA_SRES_FAIL); - if (retval > 0) return(IDA_SRES_RECVR); + if (retval < 0) { return (IDA_SRES_FAIL); } + if (retval > 0) { return (IDA_SRES_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem) +static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, + SUNDIALS_MAYBE_UNUSED N_Vector ycor, + N_Vector del, sunrealtype tol, N_Vector ewt, + void* ida_mem) { IDAMem IDA_mem; int m, retval; - realtype delnrm; - realtype rate; + sunrealtype delnrm; + sunrealtype rate; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsConvTestSensSim", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != IDA_SUCCESS) return(IDA_MEM_NULL); + if (retval != IDA_SUCCESS) { return (IDA_MEM_NULL); } /* test for convergence, first directly, then with rate estimate. */ - if (m == 0){ + if (m == 0) + { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= PT0001 * IDA_mem->ida_toldel) return(SUN_NLS_SUCCESS); - } else { - rate = SUNRpowerR( delnrm/IDA_mem->ida_oldnrm, ONE/m ); - if (rate > RATEMAX) return(SUN_NLS_CONV_RECVR); - IDA_mem->ida_ss = rate/(ONE - rate); + if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_SUCCESS); } + } + else + { + rate = SUNRpowerR(delnrm / IDA_mem->ida_oldnrm, ONE / m); + if (rate > RATEMAX) { return (SUN_NLS_CONV_RECVR); } + IDA_mem->ida_ss = rate / (ONE - rate); } - if (IDA_mem->ida_ss*delnrm <= tol) return(SUN_NLS_SUCCESS); + if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_stg.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_stg.c index cf7d0c23d..3e1590c78 100644 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_stg.c +++ b/deps/AMICI/ThirdParty/sundials/src/idas/idas_nls_stg.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,84 +19,87 @@ #include "sundials/sundials_nvector_senswrapper.h" /* constant macros */ -#define PT0001 RCONST(0.0001) /* real 0.0001 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWENTY RCONST(20.0) /* real 20.0 */ +#define PT0001 SUN_RCONST(0.0001) /* real 0.0001 */ +#define ONE SUN_RCONST(1.0) /* real 1.0 */ +#define TWENTY SUN_RCONST(20.0) /* real 20.0 */ /* nonlinear solver parameters */ -#define MAXIT 4 /* default max number of nonlinear iterations */ -#define RATEMAX RCONST(0.9) /* max convergence rate used in divergence check */ +#define MAXIT 4 /* default max number of nonlinear iterations */ +#define RATEMAX \ + SUN_RCONST(0.9) /* max convergence rate used in divergence check */ /* private functions passed to nonlinear solver */ static int idaNlsResidualSensStg(N_Vector ycor, N_Vector res, void* ida_mem); -static int idaNlsLSetupSensStg(booleantype jbad, booleantype* jcur, +static int idaNlsLSetupSensStg(sunbooleantype jbad, sunbooleantype* jcur, void* ida_mem); static int idaNlsLSolveSensStg(N_Vector delta, void* ida_mem); -static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem); +static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycor, + N_Vector del, sunrealtype tol, N_Vector ewt, + void* ida_mem); /* ----------------------------------------------------------------------------- * Exported functions * ---------------------------------------------------------------------------*/ -int IDASetNonlinearSolverSensStg(void *ida_mem, SUNNonlinearSolver NLS) +int IDASetNonlinearSolverSensStg(void* ida_mem, SUNNonlinearSolver NLS) { IDAMem IDA_mem; int retval, is; /* return immediately if IDA memory is NULL */ - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", - "IDASetNonlinearSolverSensStg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* return immediately if NLS memory is NULL */ - if (NLS == NULL) { - IDAProcessError(NULL, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (NLS == NULL) + { + IDAProcessError(NULL, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS must be non-NULL"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for required nonlinear solver functions */ - if ( NLS->ops->gettype == NULL || - NLS->ops->solve == NULL || - NLS->ops->setsysfn == NULL ) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (NLS->ops->gettype == NULL || NLS->ops->solve == NULL || + NLS->ops->setsysfn == NULL) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS does not support required operations"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check for allowed nonlinear solver types */ - if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (SUNNonlinSolGetType(NLS) != SUNNONLINEARSOLVER_ROOTFIND) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "NLS type must be SUNNONLINEARSOLVER_ROOTFIND"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check that sensitivities were initialized */ - if (!(IDA_mem->ida_sensi)) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (!(IDA_mem->ida_sensi)) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NO_SENSI); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* check that the staggered corrector was selected */ - if (IDA_mem->ida_ism != IDA_STAGGERED) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (IDA_mem->ida_ism != IDA_STAGGERED) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Sensitivity solution method is not IDA_STAGGERED"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* free any existing nonlinear solver */ if ((IDA_mem->NLSstg != NULL) && (IDA_mem->ownNLSstg)) + { retval = SUNNonlinSolFree(IDA_mem->NLSstg); + } /* set SUNNonlinearSolver pointer */ IDA_mem->NLSstg = NLS; @@ -107,73 +110,79 @@ int IDASetNonlinearSolverSensStg(void *ida_mem, SUNNonlinearSolver NLS) /* set the nonlinear residual function */ retval = SUNNonlinSolSetSysFn(IDA_mem->NLSstg, idaNlsResidualSensStg); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting nonlinear system function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set convergence test function */ retval = SUNNonlinSolSetConvTestFn(IDA_mem->NLSstg, idaNlsConvTestSensStg, ida_mem); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting convergence test function failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* set max allowed nonlinear iterations */ retval = SUNNonlinSolSetMaxIters(IDA_mem->NLSstg, MAXIT); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", - "IDASetNonlinearSolverSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting maximum number of nonlinear iterations failed"); - return(IDA_ILL_INPUT); + return (IDA_ILL_INPUT); } /* create vector wrappers if necessary */ - if (IDA_mem->stgMallocDone == SUNFALSE) { - - IDA_mem->ypredictStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns); - if (IDA_mem->ypredictStg == NULL) { - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensStg", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + if (IDA_mem->stgMallocDone == SUNFALSE) + { + IDA_mem->ypredictStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns, + IDA_mem->ida_sunctx); + if (IDA_mem->ypredictStg == NULL) + { + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - IDA_mem->ycorStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns); - if (IDA_mem->ycorStg == NULL) { + IDA_mem->ycorStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns, + IDA_mem->ida_sunctx); + if (IDA_mem->ycorStg == NULL) + { N_VDestroy(IDA_mem->ypredictStg); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensStg", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } - IDA_mem->ewtStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns); - if (IDA_mem->ewtStg == NULL) { + IDA_mem->ewtStg = N_VNewEmpty_SensWrapper(IDA_mem->ida_Ns, + IDA_mem->ida_sunctx); + if (IDA_mem->ewtStg == NULL) + { N_VDestroy(IDA_mem->ypredictStg); N_VDestroy(IDA_mem->ycorStg); - IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDAS", - "IDASetNonlinearSolverSensStg", MSG_MEM_FAIL); - return(IDA_MEM_FAIL); + IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); + return (IDA_MEM_FAIL); } IDA_mem->stgMallocDone = SUNTRUE; } /* attach vectors to vector wrappers */ - for (is=0; is < IDA_mem->ida_Ns; is++) { + for (is = 0; is < IDA_mem->ida_Ns; is++) + { NV_VEC_SW(IDA_mem->ypredictStg, is) = IDA_mem->ida_yySpredict[is]; - NV_VEC_SW(IDA_mem->ycorStg, is) = IDA_mem->ida_eeS[is]; - NV_VEC_SW(IDA_mem->ewtStg, is) = IDA_mem->ida_ewtS[is]; + NV_VEC_SW(IDA_mem->ycorStg, is) = IDA_mem->ida_eeS[is]; + NV_VEC_SW(IDA_mem->ewtStg, is) = IDA_mem->ida_ewtS[is]; } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - /* ----------------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------------*/ @@ -184,167 +193,178 @@ int idaNlsInitSensStg(IDAMem IDA_mem) /* set the linear solver setup wrapper function */ if (IDA_mem->ida_lsetup) + { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSstg, idaNlsLSetupSensStg); - else - retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSstg, NULL); + } + else { retval = SUNNonlinSolSetLSetupFn(IDA_mem->NLSstg, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting the linear solver setup function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* set the linear solver solve wrapper function */ if (IDA_mem->ida_lsolve) + { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSstg, idaNlsLSolveSensStg); - else - retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSstg, NULL); + } + else { retval = SUNNonlinSolSetLSolveFn(IDA_mem->NLSstg, NULL); } - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, "Setting linear solver solve function failed"); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } /* initialize nonlinear solver */ retval = SUNNonlinSolInitialize(IDA_mem->NLSstg); - if (retval != IDA_SUCCESS) { - IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDAS", "idaNlsInitSensStg", + if (retval != IDA_SUCCESS) + { + IDAProcessError(IDA_mem, IDA_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NLS_INIT_FAIL); - return(IDA_NLS_INIT_FAIL); + return (IDA_NLS_INIT_FAIL); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsLSetupSensStg(booleantype jbad, booleantype* jcur, - void* ida_mem) +static int idaNlsLSetupSensStg(SUNDIALS_MAYBE_UNUSED sunbooleantype jbad, + sunbooleantype* jcur, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsLSetupSensStg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; IDA_mem->ida_nsetupsS++; - retval = IDA_mem->ida_lsetup(IDA_mem, IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_delta, - IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); + retval = IDA_mem->ida_lsetup(IDA_mem, IDA_mem->ida_yy, IDA_mem->ida_yp, + IDA_mem->ida_delta, IDA_mem->ida_tmpS1, + IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); /* update Jacobian status */ *jcur = SUNTRUE; /* update convergence test constants */ - IDA_mem->ida_cjold = IDA_mem->ida_cj; + IDA_mem->ida_cjold = IDA_mem->ida_cj; IDA_mem->ida_cjratio = ONE; - IDA_mem->ida_ss = TWENTY; - IDA_mem->ida_ssS = TWENTY; + IDA_mem->ida_ss = TWENTY; + IDA_mem->ida_ssS = TWENTY; - if (retval < 0) return(IDA_LSETUP_FAIL); - if (retval > 0) return(IDA_LSETUP_RECVR); + if (retval < 0) { return (IDA_LSETUP_FAIL); } + if (retval > 0) { return (IDA_LSETUP_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsLSolveSensStg(N_Vector deltaStg, void* ida_mem) { IDAMem IDA_mem; int retval, is; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsLSolveSensStg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; - for(is=0;isida_Ns;is++) { - retval = IDA_mem->ida_lsolve(IDA_mem, NV_VEC_SW(deltaStg,is), + for (is = 0; is < IDA_mem->ida_Ns; is++) + { + retval = IDA_mem->ida_lsolve(IDA_mem, NV_VEC_SW(deltaStg, is), IDA_mem->ida_ewtS[is], IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_delta); - if (retval < 0) return(IDA_LSOLVE_FAIL); - if (retval > 0) return(IDA_LSOLVE_RECVR); + if (retval < 0) { return (IDA_LSOLVE_FAIL); } + if (retval > 0) { return (IDA_LSOLVE_RECVR); } } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - static int idaNlsResidualSensStg(N_Vector ycorStg, N_Vector resStg, void* ida_mem) { IDAMem IDA_mem; int retval; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsResidualSensStg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* update yS and ypS based on the current correction */ - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_yySpredict, - ONE, NV_VECS_SW(ycorStg), IDA_mem->ida_yyS); - N_VLinearSumVectorArray(IDA_mem->ida_Ns, - ONE, IDA_mem->ida_ypSpredict, + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_yySpredict, ONE, + NV_VECS_SW(ycorStg), IDA_mem->ida_yyS); + N_VLinearSumVectorArray(IDA_mem->ida_Ns, ONE, IDA_mem->ida_ypSpredict, IDA_mem->ida_cj, NV_VECS_SW(ycorStg), IDA_mem->ida_ypS); /* evaluate sens residual */ - retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_tn, - IDA_mem->ida_yy, IDA_mem->ida_yp, IDA_mem->ida_delta, - IDA_mem->ida_yyS, IDA_mem->ida_ypS, NV_VECS_SW(resStg), - IDA_mem->ida_user_dataS, IDA_mem->ida_tmpS1, - IDA_mem->ida_tmpS2, IDA_mem->ida_tmpS3); + retval = IDA_mem->ida_resS(IDA_mem->ida_Ns, IDA_mem->ida_tn, IDA_mem->ida_yy, + IDA_mem->ida_yp, IDA_mem->ida_delta, + IDA_mem->ida_yyS, IDA_mem->ida_ypS, + NV_VECS_SW(resStg), IDA_mem->ida_user_dataS, + IDA_mem->ida_tmpS1, IDA_mem->ida_tmpS2, + IDA_mem->ida_tmpS3); /* increment the number of sens residual evaluations */ IDA_mem->ida_nrSe++; - if (retval < 0) return(IDA_SRES_FAIL); - if (retval > 0) return(IDA_SRES_RECVR); + if (retval < 0) { return (IDA_SRES_FAIL); } + if (retval > 0) { return (IDA_SRES_RECVR); } - return(IDA_SUCCESS); + return (IDA_SUCCESS); } - -static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, - realtype tol, N_Vector ewt, void* ida_mem) +static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, + SUNDIALS_MAYBE_UNUSED N_Vector ycor, + N_Vector del, sunrealtype tol, N_Vector ewt, + void* ida_mem) { IDAMem IDA_mem; int m, retval; - realtype delnrm; - realtype rate; + sunrealtype delnrm; + sunrealtype rate; - if (ida_mem == NULL) { - IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "idaNlsConvTestSensStg", MSG_NO_MEM); - return(IDA_MEM_NULL); + if (ida_mem == NULL) + { + IDAProcessError(NULL, IDA_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); + return (IDA_MEM_NULL); } - IDA_mem = (IDAMem) ida_mem; + IDA_mem = (IDAMem)ida_mem; /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); /* get the current nonlinear solver iteration count */ retval = SUNNonlinSolGetCurIter(NLS, &m); - if (retval != IDA_SUCCESS) return(IDA_MEM_NULL); + if (retval != IDA_SUCCESS) { return (IDA_MEM_NULL); } /* test for convergence, first directly, then with rate estimate. */ - if (m == 0){ + if (m == 0) + { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= IDA_mem->ida_toldel) return(SUN_NLS_SUCCESS); - } else { - rate = SUNRpowerR( delnrm/IDA_mem->ida_oldnrm, ONE/m ); - if (rate > RATEMAX) return(SUN_NLS_CONV_RECVR); - IDA_mem->ida_ssS = rate/(ONE - rate); + if (delnrm <= IDA_mem->ida_toldel) { return (SUN_SUCCESS); } + } + else + { + rate = SUNRpowerR(delnrm / IDA_mem->ida_oldnrm, ONE / m); + if (rate > RATEMAX) { return (SUN_NLS_CONV_RECVR); } + IDA_mem->ida_ssS = rate / (ONE - rate); } - if (IDA_mem->ida_ssS*delnrm <= tol) return(SUN_NLS_SUCCESS); + if (IDA_mem->ida_ssS * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ - return(SUN_NLS_CONTINUE); + return (SUN_NLS_CONTINUE); } diff --git a/deps/AMICI/ThirdParty/sundials/src/idas/idas_spils.c b/deps/AMICI/ThirdParty/sundials/src/idas/idas_spils.c deleted file mode 100644 index d03e465b8..000000000 --- a/deps/AMICI/ThirdParty/sundials/src/idas/idas_spils.c +++ /dev/null @@ -1,114 +0,0 @@ -/*----------------------------------------------------------------- - * Programmer(s): Daniel R. Reynolds @ SMU - *----------------------------------------------------------------- - * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security - * and Southern Methodist University. - * All rights reserved. - * - * See the top-level LICENSE and NOTICE files for details. - * - * SPDX-License-Identifier: BSD-3-Clause - * SUNDIALS Copyright End - *----------------------------------------------------------------- - * Implementation file for the deprecated Scaled and Preconditioned - * Iterative Linear Solver interface in IDAS; these routines now just - * wrap the updated IDA generic linear solver interface in idas_ls.h. - *-----------------------------------------------------------------*/ - -#include -#include - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -/*================================================================= - Exported Functions (wrappers for equivalent routines in idas_ls.h) - =================================================================*/ - -int IDASpilsSetLinearSolver(void *ida_mem, SUNLinearSolver LS) -{ return(IDASetLinearSolver(ida_mem, LS, NULL)); } - -int IDASpilsSetPreconditioner(void *ida_mem, IDASpilsPrecSetupFn pset, - IDASpilsPrecSolveFn psolve) -{ return(IDASetPreconditioner(ida_mem, pset, psolve)); } - -int IDASpilsSetJacTimes(void *ida_mem, IDASpilsJacTimesSetupFn jtsetup, - IDASpilsJacTimesVecFn jtimes) -{ return(IDASetJacTimes(ida_mem, jtsetup, jtimes)); } - -int IDASpilsSetEpsLin(void *ida_mem, realtype eplifac) -{ return(IDASetEpsLin(ida_mem, eplifac)); } - -int IDASpilsSetIncrementFactor(void *ida_mem, realtype dqincfac) -{ return(IDASetIncrementFactor(ida_mem, dqincfac)); } - -int IDASpilsGetWorkSpace(void *ida_mem, long int *lenrwLS, - long int *leniwLS) -{ return(IDAGetLinWorkSpace(ida_mem, lenrwLS, leniwLS)); } - -int IDASpilsGetNumPrecEvals(void *ida_mem, long int *npevals) -{ return(IDAGetNumPrecEvals(ida_mem, npevals)); } - -int IDASpilsGetNumPrecSolves(void *ida_mem, long int *npsolves) -{ return(IDAGetNumPrecSolves(ida_mem, npsolves)); } - -int IDASpilsGetNumLinIters(void *ida_mem, long int *nliters) -{ return(IDAGetNumLinIters(ida_mem, nliters)); } - -int IDASpilsGetNumConvFails(void *ida_mem, long int *nlcfails) -{ return(IDAGetNumLinConvFails(ida_mem, nlcfails)); } - -int IDASpilsGetNumJTSetupEvals(void *ida_mem, long int *njtsetups) -{ return(IDAGetNumJTSetupEvals(ida_mem, njtsetups)); } - -int IDASpilsGetNumJtimesEvals(void *ida_mem, long int *njvevals) -{ return(IDAGetNumJtimesEvals(ida_mem, njvevals)); } - -int IDASpilsGetNumResEvals(void *ida_mem, long int *nrevalsLS) -{ return(IDAGetNumLinResEvals(ida_mem, nrevalsLS)); } - -int IDASpilsGetLastFlag(void *ida_mem, long int *flag) -{ return(IDAGetLastLinFlag(ida_mem, flag)); } - -char *IDASpilsGetReturnFlagName(long int flag) -{ return(IDAGetLinReturnFlagName(flag)); } - -int IDASpilsSetLinearSolverB(void *ida_mem, int which, - SUNLinearSolver LS) -{ return(IDASetLinearSolverB(ida_mem, which, LS, NULL)); } - -int IDASpilsSetEpsLinB(void *ida_mem, int which, realtype eplifacB) -{ return(IDASetEpsLinB(ida_mem, which, eplifacB)); } - -int IDASpilsSetIncrementFactorB(void *ida_mem, int which, - realtype dqincfacB) -{ return(IDASetIncrementFactorB(ida_mem, which, dqincfacB)); } - -int IDASpilsSetPreconditionerB(void *ida_mem, int which, - IDASpilsPrecSetupFnB psetB, - IDASpilsPrecSolveFnB psolveB) -{ return(IDASetPreconditionerB(ida_mem, which, psetB, psolveB)); } - -int IDASpilsSetPreconditionerBS(void *ida_mem, int which, - IDASpilsPrecSetupFnBS psetBS, - IDASpilsPrecSolveFnBS psolveBS) -{ return(IDASetPreconditionerBS(ida_mem, which, psetBS, psolveBS)); } - -int IDASpilsSetJacTimesB(void *ida_mem, int which, - IDASpilsJacTimesSetupFnB jtsetupB, - IDASpilsJacTimesVecFnB jtimesB) -{ return(IDASetJacTimesB(ida_mem, which, jtsetupB, jtimesB)); } - -int IDASpilsSetJacTimesBS(void *ida_mem, int which, - IDASpilsJacTimesSetupFnBS jtsetupBS, - IDASpilsJacTimesVecFnBS jtimesBS) -{ return(IDASetJacTimesBS(ida_mem, which, jtsetupBS, jtimesBS)); } - - - -#ifdef __cplusplus -} -#endif - diff --git a/deps/AMICI/ThirdParty/sundials/src/nvector/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/nvector/CMakeLists.txt index 9b066fdeb..182a2bc3c 100644 --- a/deps/AMICI/ThirdParty/sundials/src/nvector/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/nvector/CMakeLists.txt @@ -2,7 +2,7 @@ # Programmer(s): Cody J. Balos @ LLNL # ------------------------------------------------------------------------------ # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -68,3 +68,25 @@ endif() if(BUILD_NVECTOR_TRILINOS) add_subdirectory(trilinos) endif() + +if(BUILD_NVECTOR_KOKKOS) + install(CODE "MESSAGE(\"\nInstall NVECTOR_KOKKOS\n\")") + message(STATUS "Added BUILD_NVECTOR_KOKKOS module") + add_library(sundials_nveckokkos INTERFACE) + target_link_libraries(sundials_nveckokkos INTERFACE sundials_core) + if(ENABLE_HIP) + target_link_libraries(sundials_nveckokkos INTERFACE + Kokkos::kokkos hip::device) + else() + target_link_libraries(sundials_nveckokkos INTERFACE + Kokkos::kokkos) + endif() + target_include_directories(sundials_nveckokkos INTERFACE + $ + $ + $ + $) + install(FILES ${PROJECT_SOURCE_DIR}/include/nvector/nvector_kokkos.hpp + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nvector") + set(_SUNDIALS_INSTALLED_COMPONENTS "nveckokkos;${_SUNDIALS_INSTALLED_COMPONENTS}" CACHE INTERNAL "" FORCE) +endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/nvector/serial/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/nvector/serial/CMakeLists.txt index 1c8642259..c8e867daa 100644 --- a/deps/AMICI/ThirdParty/sundials/src/nvector/serial/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/nvector/serial/CMakeLists.txt @@ -2,7 +2,7 @@ # Programmer(s): Radu Serban, Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -24,8 +24,9 @@ sundials_add_library(sundials_nvecserial ${SUNDIALS_SOURCE_DIR}/include/nvector/nvector_serial.h INCLUDE_SUBDIR nvector + LINK_LIBRARIES + PUBLIC sundials_core OBJECT_LIBRARIES - sundials_generic_obj OUTPUT_NAME sundials_nvecserial VERSION @@ -38,22 +39,5 @@ message(STATUS "Added NVECTOR_SERIAL module") # Add F2003 module if the interface is enabled if(BUILD_FORTRAN_MODULE_INTERFACE) - add_subdirectory(fmod) -endif() - -# If FCMIX is enabled, build and install the Fortran77 library -if(BUILD_FORTRAN77_INTERFACE) - sundials_add_library(sundials_fnvecserial - SOURCES - fnvector_serial.c - LINK_LIBRARIES - PRIVATE sundials_nvecserial - OUTPUT_NAME - sundials_fnvecserial - VERSION - ${nveclib_VERSION} - SOVERSION - ${nveclib_SOVERSION} - ) - message(STATUS "Added NVECTOR_SERIAL F77 interface") + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/nvector/serial/nvector_serial.c b/deps/AMICI/ThirdParty/sundials/src/nvector/serial/nvector_serial.c index 0e42f24ad..255aca3fb 100644 --- a/deps/AMICI/ThirdParty/sundials/src/nvector/serial/nvector_serial.c +++ b/deps/AMICI/ThirdParty/sundials/src/nvector/serial/nvector_serial.c @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,33 +20,49 @@ #include #include -#include +#include +#include +#include +#include -#define ZERO RCONST(0.0) -#define HALF RCONST(0.5) -#define ONE RCONST(1.0) -#define ONEPT5 RCONST(1.5) +#include "sundials_macros.h" + +#define ZERO SUN_RCONST(0.0) +#define HALF SUN_RCONST(0.5) +#define ONE SUN_RCONST(1.0) +#define ONEPT5 SUN_RCONST(1.5) /* Private functions for special cases of vector operations */ -static void VCopy_Serial(N_Vector x, N_Vector z); /* z=x */ -static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z); /* z=x+y */ -static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z); /* z=x-y */ -static void VNeg_Serial(N_Vector x, N_Vector z); /* z=-x */ -static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); /* z=c(x+y) */ -static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); /* z=c(x-y) */ -static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); /* z=ax+y */ -static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); /* z=ax-y */ -static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y); /* y <- ax+y */ -static void VScaleBy_Serial(realtype a, N_Vector x); /* x <- ax */ +static void VCopy_Serial(N_Vector x, N_Vector z); /* z=x */ +static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z); /* z=x+y */ +static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z); /* z=x-y */ +static void VNeg_Serial(N_Vector x, N_Vector z); /* z=-x */ +static void VScaleSum_Serial(sunrealtype c, N_Vector x, N_Vector y, + N_Vector z); /* z=c(x+y) */ +static void VScaleDiff_Serial(sunrealtype c, N_Vector x, N_Vector y, + N_Vector z); /* z=c(x-y) */ +static void VLin1_Serial(sunrealtype a, N_Vector x, N_Vector y, + N_Vector z); /* z=ax+y */ +static void VLin2_Serial(sunrealtype a, N_Vector x, N_Vector y, + N_Vector z); /* z=ax-y */ +static void Vaxpy_Serial(sunrealtype a, N_Vector x, N_Vector y); /* y <- ax+y */ +static void VScaleBy_Serial(sunrealtype a, N_Vector x); /* x <- ax */ /* Private functions for special cases of vector array operations */ -static int VSumVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=X+Y */ -static int VDiffVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=X-Y */ -static int VScaleSumVectorArray_Serial(int nvec, realtype c, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=c(X+Y) */ -static int VScaleDiffVectorArray_Serial(int nvec, realtype c, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=c(X-Y) */ -static int VLin1VectorArray_Serial(int nvec, realtype a, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=aX+Y */ -static int VLin2VectorArray_Serial(int nvec, realtype a, N_Vector* X, N_Vector* Y, N_Vector* Z); /* Z=aX-Y */ -static int VaxpyVectorArray_Serial(int nvec, realtype a, N_Vector* X, N_Vector* Y); /* Y <- aX+Y */ +static void VSumVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, + N_Vector* Z); /* Z=X+Y */ +static void VDiffVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, + N_Vector* Z); /* Z=X-Y */ +static void VScaleSumVectorArray_Serial(int nvec, sunrealtype c, N_Vector* X, + N_Vector* Y, N_Vector* Z); /* Z=c(X+Y) */ +static void VScaleDiffVectorArray_Serial(int nvec, sunrealtype c, N_Vector* X, + N_Vector* Y, N_Vector* Z); /* Z=c(X-Y) */ +static void VLin1VectorArray_Serial(int nvec, sunrealtype a, N_Vector* X, + N_Vector* Y, N_Vector* Z); /* Z=aX+Y */ +static void VLin2VectorArray_Serial(int nvec, sunrealtype a, N_Vector* X, + N_Vector* Y, N_Vector* Z); /* Z=aX-Y */ +static void VaxpyVectorArray_Serial(int nvec, sunrealtype a, N_Vector* X, + N_Vector* Y); /* Y <- aX+Y */ /* * ----------------------------------------------------------------- @@ -54,28 +70,22 @@ static int VaxpyVectorArray_Serial(int nvec, realtype a, N_Vector* X, N_Vector* * ----------------------------------------------------------------- */ -/* ---------------------------------------------------------------- - * Returns vector type ID. Used to identify vector implementation - * from abstract N_Vector interface. - */ -N_Vector_ID N_VGetVectorID_Serial(N_Vector v) -{ - return SUNDIALS_NVEC_SERIAL; -} - /* ---------------------------------------------------------------------------- * Function to create a new empty serial vector */ -N_Vector N_VNewEmpty_Serial(sunindextype length) +N_Vector N_VNewEmpty_Serial(sunindextype length, SUNContext sunctx) { + SUNFunctionBegin(sunctx); N_Vector v; N_VectorContent_Serial content; + SUNAssertNull(length >= 0, SUN_ERR_ARG_OUTOFRANGE); + /* Create an empty vector object */ v = NULL; - v = N_VNewEmpty(); - if (v == NULL) return(NULL); + v = N_VNewEmpty(sunctx); + SUNCheckLastErrNull(); /* Attach operations */ @@ -88,6 +98,7 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) v->ops->nvgetarraypointer = N_VGetArrayPointer_Serial; v->ops->nvsetarraypointer = N_VSetArrayPointer_Serial; v->ops->nvgetlength = N_VGetLength_Serial; + v->ops->nvgetlocallength = N_VGetLength_Serial; /* standard vector operations */ v->ops->nvlinearsum = N_VLinearSum_Serial; @@ -123,6 +134,9 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) v->ops->nvwsqrsumlocal = N_VWSqrSumLocal_Serial; v->ops->nvwsqrsummasklocal = N_VWSqrSumMaskLocal_Serial; + /* single buffer reduction operations */ + v->ops->nvdotprodmultilocal = N_VDotProdMulti_Serial; + /* XBraid interface operations */ v->ops->nvbufsize = N_VBufSize_Serial; v->ops->nvbufpack = N_VBufPack_Serial; @@ -134,8 +148,8 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) /* Create content */ content = NULL; - content = (N_VectorContent_Serial) malloc(sizeof *content); - if (content == NULL) { N_VDestroy(v); return(NULL); } + content = (N_VectorContent_Serial)malloc(sizeof *content); + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ v->content = content; @@ -145,136 +159,79 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) content->own_data = SUNFALSE; content->data = NULL; - return(v); + return (v); } /* ---------------------------------------------------------------------------- * Function to create a new serial vector */ -N_Vector N_VNew_Serial(sunindextype length) +N_Vector N_VNew_Serial(sunindextype length, SUNContext sunctx) { + SUNFunctionBegin(sunctx); N_Vector v; - realtype *data; + sunrealtype* data; + + SUNAssertNull(length >= 0, SUN_ERR_ARG_OUTOFRANGE); v = NULL; - v = N_VNewEmpty_Serial(length); - if (v == NULL) return(NULL); + v = N_VNewEmpty_Serial(length, sunctx); + SUNCheckLastErrNull(); /* Create data */ - if (length > 0) { - - /* Allocate memory */ - data = NULL; - data = (realtype *) malloc(length * sizeof(realtype)); - if(data == NULL) { N_VDestroy_Serial(v); return(NULL); } - - /* Attach data */ - NV_OWN_DATA_S(v) = SUNTRUE; - NV_DATA_S(v) = data; - + data = NULL; + if (length > 0) + { + data = (sunrealtype*)malloc(length * sizeof(sunrealtype)); + SUNAssertNull(data, SUN_ERR_MALLOC_FAIL); } - return(v); + /* Attach data */ + NV_OWN_DATA_S(v) = SUNTRUE; + NV_DATA_S(v) = data; + + return (v); } /* ---------------------------------------------------------------------------- * Function to create a serial N_Vector with user data component */ -N_Vector N_VMake_Serial(sunindextype length, realtype *v_data) +N_Vector N_VMake_Serial(sunindextype length, sunrealtype* v_data, + SUNContext sunctx) { + SUNFunctionBegin(sunctx); N_Vector v; + SUNAssertNull(length >= 0, SUN_ERR_ARG_OUTOFRANGE); + v = NULL; - v = N_VNewEmpty_Serial(length); - if (v == NULL) return(NULL); + v = N_VNewEmpty_Serial(length, sunctx); + SUNCheckLastErrNull(); - if (length > 0) { + if (length > 0) + { /* Attach data */ NV_OWN_DATA_S(v) = SUNFALSE; NV_DATA_S(v) = v_data; } - return(v); -} - -/* ---------------------------------------------------------------------------- - * Function to create an array of new serial vectors. - */ - -N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w) -{ - N_Vector* vs; - int j; - - if (count <= 0) return(NULL); - - vs = NULL; - vs = (N_Vector*) malloc(count * sizeof(N_Vector)); - if(vs == NULL) return(NULL); - - for (j = 0; j < count; j++) { - vs[j] = NULL; - vs[j] = N_VClone_Serial(w); - if (vs[j] == NULL) { - N_VDestroyVectorArray_Serial(vs, j-1); - return(NULL); - } - } - - return(vs); + return (v); } -/* ---------------------------------------------------------------------------- - * Function to create an array of new serial vectors with NULL data array. - */ - -N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w) -{ - N_Vector* vs; - int j; - - if (count <= 0) return(NULL); - - vs = NULL; - vs = (N_Vector*) malloc(count * sizeof(N_Vector)); - if(vs == NULL) return(NULL); - - for (j = 0; j < count; j++) { - vs[j] = NULL; - vs[j] = N_VCloneEmpty_Serial(w); - if (vs[j] == NULL) { - N_VDestroyVectorArray_Serial(vs, j-1); - return(NULL); - } - } - - return(vs); -} - -/* ---------------------------------------------------------------------------- - * Function to free an array created with N_VCloneVectorArray_Serial +/* ---------------------------------------------------------------- + * Returns vector type ID. Used to identify vector implementation + * from abstract N_Vector interface. */ - -void N_VDestroyVectorArray_Serial(N_Vector* vs, int count) +N_Vector_ID N_VGetVectorID_Serial(SUNDIALS_MAYBE_UNUSED N_Vector v) { - int j; - - for (j = 0; j < count; j++) N_VDestroy_Serial(vs[j]); - - free(vs); vs = NULL; - - return; + return SUNDIALS_NVEC_SERIAL; } /* ---------------------------------------------------------------------------- * Function to return number of vector elements */ -sunindextype N_VGetLength_Serial(N_Vector v) -{ - return NV_LENGTH_S(v); -} +sunindextype N_VGetLength_Serial(N_Vector v) { return NV_LENGTH_S(v); } /* ---------------------------------------------------------------------------- * Function to print the a serial vector to stdout @@ -282,7 +239,9 @@ sunindextype N_VGetLength_Serial(N_Vector v) void N_VPrint_Serial(N_Vector x) { + SUNFunctionBegin(x->sunctx); N_VPrintFile_Serial(x, stdout); + SUNCheckLastErrVoid(); } /* ---------------------------------------------------------------------------- @@ -292,20 +251,21 @@ void N_VPrint_Serial(N_Vector x) void N_VPrintFile_Serial(N_Vector x, FILE* outfile) { sunindextype i, N; - realtype *xd; + sunrealtype* xd; xd = NULL; N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - for (i = 0; i < N; i++) { + for (i = 0; i < N; i++) + { #if defined(SUNDIALS_EXTENDED_PRECISION) - fprintf(outfile, "%35.32Lg\n", xd[i]); + fprintf(outfile, "%35.32Le\n", xd[i]); #elif defined(SUNDIALS_DOUBLE_PRECISION) - fprintf(outfile, "%19.16g\n", xd[i]); + fprintf(outfile, "%19.16e\n", xd[i]); #else - fprintf(outfile, "%11.8g\n", xd[i]); + fprintf(outfile, "%11.8e\n", xd[i]); #endif } fprintf(outfile, "\n"); @@ -321,23 +281,22 @@ void N_VPrintFile_Serial(N_Vector x, FILE* outfile) N_Vector N_VCloneEmpty_Serial(N_Vector w) { + SUNFunctionBegin(w->sunctx); N_Vector v; N_VectorContent_Serial content; - if (w == NULL) return(NULL); - /* Create vector */ v = NULL; - v = N_VNewEmpty(); - if (v == NULL) return(NULL); + v = N_VNewEmpty(w->sunctx); + SUNCheckLastErrNull(); /* Attach operations */ - if (N_VCopyOps(w, v)) { N_VDestroy(v); return(NULL); } + SUNCheckCallNull(N_VCopyOps(w, v)); /* Create content */ content = NULL; - content = (N_VectorContent_Serial) malloc(sizeof *content); - if (content == NULL) { N_VDestroy(v); return(NULL); } + content = (N_VectorContent_Serial)malloc(sizeof *content); + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ v->content = content; @@ -347,46 +306,47 @@ N_Vector N_VCloneEmpty_Serial(N_Vector w) content->own_data = SUNFALSE; content->data = NULL; - return(v); + return (v); } N_Vector N_VClone_Serial(N_Vector w) { + SUNFunctionBegin(w->sunctx); N_Vector v; - realtype *data; + sunrealtype* data; sunindextype length; v = NULL; v = N_VCloneEmpty_Serial(w); - if (v == NULL) return(NULL); + SUNCheckLastErrNull(); length = NV_LENGTH_S(w); /* Create data */ - if (length > 0) { - - /* Allocate memory */ - data = NULL; - data = (realtype *) malloc(length * sizeof(realtype)); - if(data == NULL) { N_VDestroy_Serial(v); return(NULL); } + data = NULL; + if (length > 0) + { + data = (sunrealtype*)malloc(length * sizeof(sunrealtype)); + SUNAssertNull(data, SUN_ERR_MALLOC_FAIL); /* Attach data */ NV_OWN_DATA_S(v) = SUNTRUE; NV_DATA_S(v) = data; - } - return(v); + return (v); } void N_VDestroy_Serial(N_Vector v) { - if (v == NULL) return; + if (v == NULL) { return; } /* free content */ - if (v->content != NULL) { + if (v->content != NULL) + { /* free data array if it's owned by the vector */ - if (NV_OWN_DATA_S(v) && NV_DATA_S(v) != NULL) { + if (NV_OWN_DATA_S(v) && NV_DATA_S(v) != NULL) + { free(NV_DATA_S(v)); NV_DATA_S(v) = NULL; } @@ -395,61 +355,76 @@ void N_VDestroy_Serial(N_Vector v) } /* free ops and vector */ - if (v->ops != NULL) { free(v->ops); v->ops = NULL; } - free(v); v = NULL; + if (v->ops != NULL) + { + free(v->ops); + v->ops = NULL; + } + free(v); + v = NULL; return; } -void N_VSpace_Serial(N_Vector v, sunindextype *lrw, sunindextype *liw) +void N_VSpace_Serial(N_Vector v, sunindextype* lrw, sunindextype* liw) { + SUNFunctionBegin(v->sunctx); + + SUNAssertVoid(lrw, SUN_ERR_ARG_CORRUPT); + SUNAssertVoid(liw, SUN_ERR_ARG_CORRUPT); + *lrw = NV_LENGTH_S(v); *liw = 1; return; } -realtype *N_VGetArrayPointer_Serial(N_Vector v) +sunrealtype* N_VGetArrayPointer_Serial(N_Vector v) { - return((realtype *) NV_DATA_S(v)); + return ((sunrealtype*)NV_DATA_S(v)); } -void N_VSetArrayPointer_Serial(realtype *v_data, N_Vector v) +void N_VSetArrayPointer_Serial(sunrealtype* v_data, N_Vector v) { - if (NV_LENGTH_S(v) > 0) NV_DATA_S(v) = v_data; + if (NV_LENGTH_S(v) > 0) { NV_DATA_S(v) = v_data; } return; } -void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) +void N_VLinearSum_Serial(sunrealtype a, N_Vector x, sunrealtype b, N_Vector y, + N_Vector z) { sunindextype i, N; - realtype c, *xd, *yd, *zd; + sunrealtype c, *xd, *yd, *zd; N_Vector v1, v2; - booleantype test; + sunbooleantype test; xd = yd = zd = NULL; - if ((b == ONE) && (z == y)) { /* BLAS usage: axpy y <- ax+y */ - Vaxpy_Serial(a,x,y); + if ((b == ONE) && (z == y)) + { /* BLAS usage: axpy y <- ax+y */ + Vaxpy_Serial(a, x, y); return; } - if ((a == ONE) && (z == x)) { /* BLAS usage: axpy x <- by+x */ - Vaxpy_Serial(b,y,x); + if ((a == ONE) && (z == x)) + { /* BLAS usage: axpy x <- by+x */ + Vaxpy_Serial(b, y, x); return; } /* Case: a == b == 1.0 */ - if ((a == ONE) && (b == ONE)) { + if ((a == ONE) && (b == ONE)) + { VSum_Serial(x, y, z); return; } /* Cases: (1) a == 1.0, b = -1.0, (2) a == -1.0, b == 1.0 */ - if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) { + if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) + { v1 = test ? y : x; v2 = test ? x : y; VDiff_Serial(v2, v1, z); @@ -459,7 +434,8 @@ void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vecto /* Cases: (1) a == 1.0, b == other or 0.0, (2) a == other or 0.0, b == 1.0 */ /* if a or b is 0.0, then user should have called N_VScale */ - if ((test = (a == ONE)) || (b == ONE)) { + if ((test = (a == ONE)) || (b == ONE)) + { c = test ? b : a; v1 = test ? y : x; v2 = test ? x : y; @@ -469,8 +445,9 @@ void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vecto /* Cases: (1) a == -1.0, b != 1.0, (2) a != 1.0, b == -1.0 */ - if ((test = (a == -ONE)) || (b == -ONE)) { - c = test ? b : a; + if ((test = (a == -ONE)) || (b == -ONE)) + { + c = test ? b : a; v1 = test ? y : x; v2 = test ? x : y; VLin2_Serial(c, v1, v2, z); @@ -480,14 +457,16 @@ void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vecto /* Case: a == b */ /* catches case both a and b are 0.0 - user should have called N_VConst */ - if (a == b) { + if (a == b) + { VScaleSum_Serial(a, x, y, z); return; } /* Case: a == -b */ - if (a == -b) { + if (a == -b) + { VScaleDiff_Serial(a, x, y, z); return; } @@ -502,23 +481,22 @@ void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vecto yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = (a*xd[i])+(b*yd[i]); + for (i = 0; i < N; i++) { zd[i] = (a * xd[i]) + (b * yd[i]); } return; } -void N_VConst_Serial(realtype c, N_Vector z) +void N_VConst_Serial(sunrealtype c, N_Vector z) { sunindextype i, N; - realtype *zd; + sunrealtype* zd; zd = NULL; N = NV_LENGTH_S(z); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) zd[i] = c; + for (i = 0; i < N; i++) { zd[i] = c; } return; } @@ -526,7 +504,7 @@ void N_VConst_Serial(realtype c, N_Vector z) void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -535,8 +513,7 @@ void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]*yd[i]; + for (i = 0; i < N; i++) { zd[i] = xd[i] * yd[i]; } return; } @@ -544,7 +521,7 @@ void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -553,34 +530,32 @@ void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]/yd[i]; + for (i = 0; i < N; i++) { zd[i] = xd[i] / yd[i]; } return; } -void N_VScale_Serial(realtype c, N_Vector x, N_Vector z) +void N_VScale_Serial(sunrealtype c, N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; - if (z == x) { /* BLAS usage: scale x <- cx */ + if (z == x) + { /* BLAS usage: scale x <- cx */ VScaleBy_Serial(c, x); return; } - if (c == ONE) { - VCopy_Serial(x, z); - } else if (c == -ONE) { - VNeg_Serial(x, z); - } else { + if (c == ONE) { VCopy_Serial(x, z); } + else if (c == -ONE) { VNeg_Serial(x, z); } + else + { N = NV_LENGTH_S(x); xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = c*xd[i]; + for (i = 0; i < N; i++) { zd[i] = c * xd[i]; } } return; @@ -589,7 +564,7 @@ void N_VScale_Serial(realtype c, N_Vector x, N_Vector z) void N_VAbs_Serial(N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; @@ -597,8 +572,7 @@ void N_VAbs_Serial(N_Vector x, N_Vector z) xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = SUNRabs(xd[i]); + for (i = 0; i < N; i++) { zd[i] = SUNRabs(xd[i]); } return; } @@ -606,7 +580,7 @@ void N_VAbs_Serial(N_Vector x, N_Vector z) void N_VInv_Serial(N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; @@ -614,16 +588,15 @@ void N_VInv_Serial(N_Vector x, N_Vector z) xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = ONE/xd[i]; + for (i = 0; i < N; i++) { zd[i] = ONE / xd[i]; } return; } -void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z) +void N_VAddConst_Serial(N_Vector x, sunrealtype b, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; @@ -631,16 +604,15 @@ void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z) xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]+b; + for (i = 0; i < N; i++) { zd[i] = xd[i] + b; } return; } -realtype N_VDotProd_Serial(N_Vector x, N_Vector y) +sunrealtype N_VDotProd_Serial(N_Vector x, N_Vector y) { sunindextype i, N; - realtype sum, *xd, *yd; + sunrealtype sum, *xd, *yd; sum = ZERO; xd = yd = NULL; @@ -649,39 +621,43 @@ realtype N_VDotProd_Serial(N_Vector x, N_Vector y) xd = NV_DATA_S(x); yd = NV_DATA_S(y); - for (i = 0; i < N; i++) - sum += xd[i]*yd[i]; + for (i = 0; i < N; i++) { sum += xd[i] * yd[i]; } - return(sum); + return (sum); } -realtype N_VMaxNorm_Serial(N_Vector x) +sunrealtype N_VMaxNorm_Serial(N_Vector x) { sunindextype i, N; - realtype max, *xd; + sunrealtype max, *xd; max = ZERO; - xd = NULL; + xd = NULL; N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - for (i = 0; i < N; i++) { - if (SUNRabs(xd[i]) > max) max = SUNRabs(xd[i]); + for (i = 0; i < N; i++) + { + if (SUNRabs(xd[i]) > max) { max = SUNRabs(xd[i]); } } - return(max); + return (max); } -realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w) +sunrealtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w) { - return(SUNRsqrt(N_VWSqrSumLocal_Serial(x, w)/(NV_LENGTH_S(x)))); + SUNFunctionBegin(x->sunctx); + sunrealtype norm = N_VWSqrSumLocal_Serial(x, w); + SUNCheckLastErrNoRet(); + norm = SUNRsqrt(norm / NV_LENGTH_S(x)); + return norm; } -realtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w) +sunrealtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w) { sunindextype i, N; - realtype sum, prodi, *xd, *wd; + sunrealtype sum, prodi, *xd, *wd; sum = ZERO; xd = wd = NULL; @@ -690,46 +666,53 @@ realtype N_VWSqrSumLocal_Serial(N_Vector x, N_Vector w) xd = NV_DATA_S(x); wd = NV_DATA_S(w); - for (i = 0; i < N; i++) { - prodi = xd[i]*wd[i]; + for (i = 0; i < N; i++) + { + prodi = xd[i] * wd[i]; sum += SUNSQR(prodi); } - return(sum); + return (sum); } -realtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id) +sunrealtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id) { - return(SUNRsqrt(N_VWSqrSumMaskLocal_Serial(x, w, id) / (NV_LENGTH_S(x)))); + SUNFunctionBegin(x->sunctx); + sunrealtype norm = N_VWSqrSumMaskLocal_Serial(x, w, id); + SUNCheckLastErrNoRet(); + norm = SUNRsqrt(norm / NV_LENGTH_S(x)); + return norm; } -realtype N_VWSqrSumMaskLocal_Serial(N_Vector x, N_Vector w, N_Vector id) +sunrealtype N_VWSqrSumMaskLocal_Serial(N_Vector x, N_Vector w, N_Vector id) { sunindextype i, N; - realtype sum, prodi, *xd, *wd, *idd; + sunrealtype sum, prodi, *xd, *wd, *idd; sum = ZERO; xd = wd = idd = NULL; - N = NV_LENGTH_S(x); + N = NV_LENGTH_S(x); xd = NV_DATA_S(x); wd = NV_DATA_S(w); idd = NV_DATA_S(id); - for (i = 0; i < N; i++) { - if (idd[i] > ZERO) { - prodi = xd[i]*wd[i]; + for (i = 0; i < N; i++) + { + if (idd[i] > ZERO) + { + prodi = xd[i] * wd[i]; sum += SUNSQR(prodi); } } - return(sum); + return (sum); } -realtype N_VMin_Serial(N_Vector x) +sunrealtype N_VMin_Serial(N_Vector x) { sunindextype i, N; - realtype min, *xd; + sunrealtype min, *xd; xd = NULL; @@ -738,17 +721,18 @@ realtype N_VMin_Serial(N_Vector x) min = xd[0]; - for (i = 1; i < N; i++) { - if (xd[i] < min) min = xd[i]; + for (i = 1; i < N; i++) + { + if (xd[i] < min) { min = xd[i]; } } - return(min); + return (min); } -realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w) +sunrealtype N_VWL2Norm_Serial(N_Vector x, N_Vector w) { sunindextype i, N; - realtype sum, prodi, *xd, *wd; + sunrealtype sum, prodi, *xd, *wd; sum = ZERO; xd = wd = NULL; @@ -757,35 +741,35 @@ realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w) xd = NV_DATA_S(x); wd = NV_DATA_S(w); - for (i = 0; i < N; i++) { - prodi = xd[i]*wd[i]; + for (i = 0; i < N; i++) + { + prodi = xd[i] * wd[i]; sum += SUNSQR(prodi); } - return(SUNRsqrt(sum)); + return (SUNRsqrt(sum)); } -realtype N_VL1Norm_Serial(N_Vector x) +sunrealtype N_VL1Norm_Serial(N_Vector x) { sunindextype i, N; - realtype sum, *xd; + sunrealtype sum, *xd; sum = ZERO; - xd = NULL; + xd = NULL; N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - for (i = 0; i= c) ? ONE : ZERO; - } + for (i = 0; i < N; i++) { zd[i] = (SUNRabs(xd[i]) >= c) ? ONE : ZERO; } return; } -booleantype N_VInvTest_Serial(N_Vector x, N_Vector z) +sunbooleantype N_VInvTest_Serial(N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; - booleantype no_zero_found; + sunrealtype *xd, *zd; + sunbooleantype no_zero_found; xd = zd = NULL; @@ -813,22 +795,21 @@ booleantype N_VInvTest_Serial(N_Vector x, N_Vector z) zd = NV_DATA_S(z); no_zero_found = SUNTRUE; - for (i = 0; i < N; i++) { - if (xd[i] == ZERO) - no_zero_found = SUNFALSE; - else - zd[i] = ONE/xd[i]; + for (i = 0; i < N; i++) + { + if (xd[i] == ZERO) { no_zero_found = SUNFALSE; } + else { zd[i] = ONE / xd[i]; } } return no_zero_found; } -booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) +sunbooleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) { sunindextype i, N; - realtype temp; - realtype *cd, *xd, *md; - booleantype test; + sunrealtype temp; + sunrealtype *cd, *xd, *md; + sunbooleantype test; cd = xd = md = NULL; @@ -839,30 +820,28 @@ booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) temp = ZERO; - for (i = 0; i < N; i++) { + for (i = 0; i < N; i++) + { md[i] = ZERO; /* Continue if no constraints were set for the variable */ - if (cd[i] == ZERO) - continue; + if (cd[i] == ZERO) { continue; } /* Check if a set constraint has been violated */ - test = (SUNRabs(cd[i]) > ONEPT5 && xd[i]*cd[i] <= ZERO) || - (SUNRabs(cd[i]) > HALF && xd[i]*cd[i] < ZERO); - if (test) { - temp = md[i] = ONE; - } + test = (SUNRabs(cd[i]) > ONEPT5 && xd[i] * cd[i] <= ZERO) || + (SUNRabs(cd[i]) > HALF && xd[i] * cd[i] < ZERO); + if (test) { temp = md[i] = ONE; } } /* Return false if any constraint was violated */ return (temp == ONE) ? SUNFALSE : SUNTRUE; } -realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom) +sunrealtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom) { - booleantype notEvenOnce; + sunbooleantype notEvenOnce; sunindextype i, N; - realtype *nd, *dd, min; + sunrealtype *nd, *dd, min; nd = dd = NULL; @@ -871,49 +850,58 @@ realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom) dd = NV_DATA_S(denom); notEvenOnce = SUNTRUE; - min = BIG_REAL; - - for (i = 0; i < N; i++) { - if (dd[i] == ZERO) continue; - else { - if (!notEvenOnce) min = SUNMIN(min, nd[i]/dd[i]); - else { - min = nd[i]/dd[i]; + min = SUN_BIG_REAL; + + for (i = 0; i < N; i++) + { + if (dd[i] == ZERO) { continue; } + else + { + if (!notEvenOnce) { min = SUNMIN(min, nd[i] / dd[i]); } + else + { + min = nd[i] / dd[i]; notEvenOnce = SUNFALSE; } } } - return(min); + return (min); } - /* * ----------------------------------------------------------------- * fused vector operations * ----------------------------------------------------------------- */ -int N_VLinearCombination_Serial(int nvec, realtype* c, N_Vector* X, N_Vector z) +SUNErrCode N_VLinearCombination_Serial(int nvec, sunrealtype* c, N_Vector* X, + N_Vector z) { - int i; + SUNFunctionBegin(X[0]->sunctx); + + int i; sunindextype j, N; - realtype* zd=NULL; - realtype* xd=NULL; + sunrealtype* zd = NULL; + sunrealtype* xd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VScale */ - if (nvec == 1) { + if (nvec == 1) + { N_VScale_Serial(c[0], X[0], z); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* should have called N_VLinearSum */ - if (nvec == 2) { + if (nvec == 2) + { N_VLinearSum_Serial(c[0], X[0], c[1], X[1], z); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length and data array */ @@ -923,64 +911,62 @@ int N_VLinearCombination_Serial(int nvec, realtype* c, N_Vector* X, N_Vector z) /* * X[0] += c[i]*X[i], i = 1,...,nvec-1 */ - if ((X[0] == z) && (c[0] == ONE)) { - for (i=1; isunctx); + int i; sunindextype j, N; - realtype* xd=NULL; - realtype* yd=NULL; - realtype* zd=NULL; + sunrealtype* xd = NULL; + sunrealtype* yd = NULL; + sunrealtype* zd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VLinearSum */ - if (nvec == 1) { + if (nvec == 1) + { N_VLinearSum_Serial(a[0], x, ONE, Y[0], Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length and data array */ @@ -990,44 +976,46 @@ int N_VScaleAddMulti_Serial(int nvec, realtype* a, N_Vector x, N_Vector* Y, N_Ve /* * Y[i][j] += a[i] * x[j] */ - if (Y == Z) { - for (i=0; isunctx); + int i; sunindextype j, N; - realtype* xd=NULL; - realtype* yd=NULL; + sunrealtype* xd = NULL; + sunrealtype* yd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VDotProd */ - if (nvec == 1) { + if (nvec == 1) + { dotprods[0] = N_VDotProd_Serial(x, Y[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length and data array */ @@ -1035,98 +1023,119 @@ int N_VDotProdMulti_Serial(int nvec, N_Vector x, N_Vector* Y, realtype* dotprods xd = NV_DATA_S(x); /* compute multiple dot products */ - for (i=0; isunctx); + + int i; sunindextype j, N; - realtype* xd=NULL; - realtype* yd=NULL; - realtype* zd=NULL; - realtype c; - N_Vector* V1; - N_Vector* V2; - booleantype test; + sunrealtype* xd = NULL; + sunrealtype* yd = NULL; + sunrealtype* zd = NULL; + sunrealtype c; + N_Vector* V1; + N_Vector* V2; + sunbooleantype test; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VLinearSum */ - if (nvec == 1) { + if (nvec == 1) + { N_VLinearSum_Serial(a, X[0], b, Y[0], Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* BLAS usage: axpy y <- ax+y */ if ((b == ONE) && (Z == Y)) - return(VaxpyVectorArray_Serial(nvec, a, X, Y)); + { + VaxpyVectorArray_Serial(nvec, a, X, Y); + return SUN_SUCCESS; + } /* BLAS usage: axpy x <- by+x */ if ((a == ONE) && (Z == X)) - return(VaxpyVectorArray_Serial(nvec, b, Y, X)); + { + VaxpyVectorArray_Serial(nvec, b, Y, X); + return SUN_SUCCESS; + } /* Case: a == b == 1.0 */ if ((a == ONE) && (b == ONE)) - return(VSumVectorArray_Serial(nvec, X, Y, Z)); + { + VSumVectorArray_Serial(nvec, X, Y, Z); + return SUN_SUCCESS; + } /* Cases: */ /* (1) a == 1.0, b = -1.0, */ /* (2) a == -1.0, b == 1.0 */ - if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) { + if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) + { V1 = test ? Y : X; V2 = test ? X : Y; - return(VDiffVectorArray_Serial(nvec, V2, V1, Z)); + VDiffVectorArray_Serial(nvec, V2, V1, Z); + return SUN_SUCCESS; } /* Cases: */ /* (1) a == 1.0, b == other or 0.0, */ /* (2) a == other or 0.0, b == 1.0 */ /* if a or b is 0.0, then user should have called N_VScale */ - if ((test = (a == ONE)) || (b == ONE)) { + if ((test = (a == ONE)) || (b == ONE)) + { c = test ? b : a; V1 = test ? Y : X; V2 = test ? X : Y; - return(VLin1VectorArray_Serial(nvec, c, V1, V2, Z)); + VLin1VectorArray_Serial(nvec, c, V1, V2, Z); + return SUN_SUCCESS; } /* Cases: */ /* (1) a == -1.0, b != 1.0, */ /* (2) a != 1.0, b == -1.0 */ - if ((test = (a == -ONE)) || (b == -ONE)) { - c = test ? b : a; + if ((test = (a == -ONE)) || (b == -ONE)) + { + c = test ? b : a; V1 = test ? Y : X; V2 = test ? X : Y; - return(VLin2VectorArray_Serial(nvec, c, V1, V2, Z)); + VLin2VectorArray_Serial(nvec, c, V1, V2, Z); + return SUN_SUCCESS; } /* Case: a == b */ /* catches case both a and b are 0.0 - user should have called N_VConst */ if (a == b) - return(VScaleSumVectorArray_Serial(nvec, a, X, Y, Z)); + { + VScaleSumVectorArray_Serial(nvec, a, X, Y, Z); + return SUN_SUCCESS; + } /* Case: a == -b */ if (a == -b) - return(VScaleDiffVectorArray_Serial(nvec, a, X, Y, Z)); + { + VScaleDiffVectorArray_Serial(nvec, a, X, Y, Z); + return SUN_SUCCESS; + } /* Do all cases not handled above: */ /* (1) a == other, b == 0.0 - user should have called N_VScale */ @@ -1137,33 +1146,35 @@ int N_VLinearSumVectorArray_Serial(int nvec, N = NV_LENGTH_S(Z[0]); /* compute linear sum for each vector pair in vector arrays */ - for (i=0; isunctx); + int i; sunindextype j, N; - realtype* xd=NULL; - realtype* zd=NULL; + sunrealtype* xd = NULL; + sunrealtype* zd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VScale */ - if (nvec == 1) { + if (nvec == 1) + { N_VScale_Serial(c[0], X[0], Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length */ @@ -1172,111 +1183,114 @@ int N_VScaleVectorArray_Serial(int nvec, realtype* c, N_Vector* X, N_Vector* Z) /* * X[i] *= c[i] */ - if (X == Z) { - for (i=0; isunctx); + int i; sunindextype j, N; - realtype* zd=NULL; + sunrealtype* zd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VConst */ - if (nvec == 1) { + if (nvec == 1) + { N_VConst_Serial(c, Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length */ N = NV_LENGTH_S(Z[0]); /* set each vector in the vector array to a constant */ - for (i=0; isunctx); + int i; sunindextype j, N; - realtype* wd=NULL; - realtype* xd=NULL; + sunrealtype* wd = NULL; + sunrealtype* xd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VWrmsNorm */ - if (nvec == 1) { + if (nvec == 1) + { nrm[0] = N_VWrmsNorm_Serial(X[0], W[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length */ N = NV_LENGTH_S(X[0]); /* compute the WRMS norm for each vector in the vector array */ - for (i=0; isunctx); + int i; sunindextype j, N; - realtype* wd=NULL; - realtype* xd=NULL; - realtype* idd=NULL; + sunrealtype* wd = NULL; + sunrealtype* xd = NULL; + sunrealtype* idd = NULL; /* invalid number of vectors */ - if (nvec < 1) return(-1); + SUNAssert(nvec >= 1, SUN_ERR_ARG_OUTOFRANGE); /* should have called N_VWrmsNorm */ - if (nvec == 1) { + if (nvec == 1) + { nrm[0] = N_VWrmsNormMask_Serial(X[0], W[0], id); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* get vector length and mask data array */ @@ -1284,64 +1298,69 @@ int N_VWrmsNormMaskVectorArray_Serial(int nvec, N_Vector* X, N_Vector* W, idd = NV_DATA_S(id); /* compute the WRMS norm for each vector in the vector array */ - for (i=0; i ZERO) - nrm[i] += SUNSQR(xd[j] * wd[j]); + for (j = 0; j < N; j++) + { + if (idd[j] > ZERO) { nrm[i] += SUNSQR(xd[j] * wd[j]); } } - nrm[i] = SUNRsqrt(nrm[i]/N); + nrm[i] = SUNRsqrt(nrm[i] / N); } - return(0); + return SUN_SUCCESS; } - -int N_VScaleAddMultiVectorArray_Serial(int nvec, int nsum, realtype* a, - N_Vector* X, N_Vector** Y, N_Vector** Z) +SUNErrCode N_VScaleAddMultiVectorArray_Serial(int nvec, int nsum, + sunrealtype* a, N_Vector* X, + N_Vector** Y, N_Vector** Z) { - int i, j; + SUNFunctionBegin(X[0]->sunctx); + int i, j; sunindextype k, N; - realtype* xd=NULL; - realtype* yd=NULL; - realtype* zd=NULL; - - int retval; - N_Vector* YY; - N_Vector* ZZ; + sunrealtype* xd = NULL; + sunrealtype* yd = NULL; + sunrealtype* zd = NULL; + N_Vector* YY; + N_Vector* ZZ; /* invalid number of vectors */ - if (nvec < 1) return(-1); - if (nsum < 1) return(-1); + SUNAssert(nvec >= 1 && nsum >= 1, SUN_ERR_ARG_OUTOFRANGE); /* --------------------------- * Special cases for nvec == 1 * --------------------------- */ - if (nvec == 1) { - + if (nvec == 1) + { /* should have called N_VLinearSum */ - if (nsum == 1) { + if (nsum == 1) + { N_VLinearSum_Serial(a[0], X[0], ONE, Y[0][0], Z[0][0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* should have called N_VScaleAddMulti */ - YY = (N_Vector*) malloc(nsum * sizeof(N_Vector)); - ZZ = (N_Vector*) malloc(nsum * sizeof(N_Vector)); + YY = (N_Vector*)malloc(nsum * sizeof(N_Vector)); + SUNAssert(YY, SUN_ERR_MALLOC_FAIL); + ZZ = (N_Vector*)malloc(nsum * sizeof(N_Vector)); + SUNAssert(ZZ, SUN_ERR_MALLOC_FAIL); - for (j=0; jsunctx); + int i; /* vector arrays index in summation [0,nsum) */ + int j; /* vector index in vector array [0,nvec) */ sunindextype k; /* element index in vector [0,N) */ sunindextype N; - realtype* zd=NULL; - realtype* xd=NULL; - - int retval; - realtype* ctmp; - N_Vector* Y; + sunrealtype* zd = NULL; + sunrealtype* xd = NULL; + sunrealtype* ctmp; + N_Vector* Y; /* invalid number of vectors */ - if (nvec < 1) return(-1); - if (nsum < 1) return(-1); + SUNAssert(nvec >= 1 && nsum >= 1, SUN_ERR_ARG_OUTOFRANGE); /* --------------------------- * Special cases for nvec == 1 * --------------------------- */ - if (nvec == 1) { - + if (nvec == 1) + { /* should have called N_VScale */ - if (nsum == 1) { + if (nsum == 1) + { N_VScale_Serial(c[0], X[0][0], Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* should have called N_VLinearSum */ - if (nsum == 2) { + if (nsum == 2) + { N_VLinearSum_Serial(c[0], X[0][0], c[1], X[1][0], Z[0]); - return(0); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* should have called N_VLinearCombination */ - Y = (N_Vector*) malloc(nsum * sizeof(N_Vector)); + Y = (N_Vector*)malloc(nsum * sizeof(N_Vector)); + SUNAssert(Y, SUN_ERR_MALLOC_FAIL); - for (i=0; isunctx); sunindextype i, N; - realtype *xd = NULL; - realtype *bd = NULL; + sunrealtype* xd = NULL; + sunrealtype* bd = NULL; - if (x == NULL || buf == NULL) return(-1); + SUNAssert(buf, SUN_ERR_ARG_CORRUPT); N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - bd = (realtype*) buf; + bd = (sunrealtype*)buf; - for (i = 0; i < N; i++) - bd[i] = xd[i]; + for (i = 0; i < N; i++) { bd[i] = xd[i]; } - return(0); + return SUN_SUCCESS; } - -int N_VBufUnpack_Serial(N_Vector x, void *buf) +SUNErrCode N_VBufUnpack_Serial(N_Vector x, void* buf) { + SUNFunctionBegin(x->sunctx); sunindextype i, N; - realtype *xd = NULL; - realtype *bd = NULL; + sunrealtype* xd = NULL; + sunrealtype* bd = NULL; - if (x == NULL || buf == NULL) return(-1); + SUNAssert(buf, SUN_ERR_ARG_CORRUPT); N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - bd = (realtype*) buf; + bd = (sunrealtype*)buf; - for (i = 0; i < N; i++) - xd[i] = bd[i]; + for (i = 0; i < N; i++) { xd[i] = bd[i]; } - return(0); + return SUN_SUCCESS; } - /* * ----------------------------------------------------------------- * private functions for special cases of vector operations @@ -1592,7 +1607,7 @@ int N_VBufUnpack_Serial(N_Vector x, void *buf) static void VCopy_Serial(N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; @@ -1600,8 +1615,7 @@ static void VCopy_Serial(N_Vector x, N_Vector z) xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]; + for (i = 0; i < N; i++) { zd[i] = xd[i]; } return; } @@ -1609,7 +1623,7 @@ static void VCopy_Serial(N_Vector x, N_Vector z) static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1618,8 +1632,7 @@ static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]+yd[i]; + for (i = 0; i < N; i++) { zd[i] = xd[i] + yd[i]; } return; } @@ -1627,7 +1640,7 @@ static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z) static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1636,8 +1649,7 @@ static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = xd[i]-yd[i]; + for (i = 0; i < N; i++) { zd[i] = xd[i] - yd[i]; } return; } @@ -1645,7 +1657,7 @@ static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z) static void VNeg_Serial(N_Vector x, N_Vector z) { sunindextype i, N; - realtype *xd, *zd; + sunrealtype *xd, *zd; xd = zd = NULL; @@ -1653,16 +1665,15 @@ static void VNeg_Serial(N_Vector x, N_Vector z) xd = NV_DATA_S(x); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = -xd[i]; + for (i = 0; i < N; i++) { zd[i] = -xd[i]; } return; } -static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) +static void VScaleSum_Serial(sunrealtype c, N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1671,16 +1682,15 @@ static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = c*(xd[i]+yd[i]); + for (i = 0; i < N; i++) { zd[i] = c * (xd[i] + yd[i]); } return; } -static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) +static void VScaleDiff_Serial(sunrealtype c, N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1689,16 +1699,15 @@ static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = c*(xd[i]-yd[i]); + for (i = 0; i < N; i++) { zd[i] = c * (xd[i] - yd[i]); } return; } -static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) +static void VLin1_Serial(sunrealtype a, N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1707,16 +1716,15 @@ static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = (a*xd[i])+yd[i]; + for (i = 0; i < N; i++) { zd[i] = (a * xd[i]) + yd[i]; } return; } -static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) +static void VLin2_Serial(sunrealtype a, N_Vector x, N_Vector y, N_Vector z) { sunindextype i, N; - realtype *xd, *yd, *zd; + sunrealtype *xd, *yd, *zd; xd = yd = zd = NULL; @@ -1725,16 +1733,15 @@ static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) yd = NV_DATA_S(y); zd = NV_DATA_S(z); - for (i = 0; i < N; i++) - zd[i] = (a*xd[i])-yd[i]; + for (i = 0; i < N; i++) { zd[i] = (a * xd[i]) - yd[i]; } return; } -static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y) +static void Vaxpy_Serial(sunrealtype a, N_Vector x, N_Vector y) { sunindextype i, N; - realtype *xd, *yd; + sunrealtype *xd, *yd; xd = yd = NULL; @@ -1742,243 +1749,231 @@ static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y) xd = NV_DATA_S(x); yd = NV_DATA_S(y); - if (a == ONE) { - for (i = 0; i < N; i++) - yd[i] += xd[i]; + if (a == ONE) + { + for (i = 0; i < N; i++) { yd[i] += xd[i]; } return; } - if (a == -ONE) { - for (i = 0; i < N; i++) - yd[i] -= xd[i]; + if (a == -ONE) + { + for (i = 0; i < N; i++) { yd[i] -= xd[i]; } return; } - for (i = 0; i < N; i++) - yd[i] += a*xd[i]; + for (i = 0; i < N; i++) { yd[i] += a * xd[i]; } return; } -static void VScaleBy_Serial(realtype a, N_Vector x) +static void VScaleBy_Serial(sunrealtype a, N_Vector x) { sunindextype i, N; - realtype *xd; + sunrealtype* xd; xd = NULL; N = NV_LENGTH_S(x); xd = NV_DATA_S(x); - for (i = 0; i < N; i++) - xd[i] *= a; + for (i = 0; i < N; i++) { xd[i] *= a; } return; } - /* * ----------------------------------------------------------------- * private functions for special cases of vector array operations * ----------------------------------------------------------------- */ -static int VSumVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, N_Vector* Z) +static void VSumVectorArray_Serial(int nvec, N_Vector* X, N_Vector* Y, N_Vector* Z) { - int i; + int i; sunindextype j, N; - realtype* xd=NULL; - realtype* yd=NULL; - realtype* zd=NULL; + sunrealtype* xd = NULL; + sunrealtype* yd = NULL; + sunrealtype* zd = NULL; N = NV_LENGTH_S(X[0]); - for (i=0; iops == NULL) return(-1); - - if (tf) { + if (tf) + { /* enable all fused vector operations */ v->ops->nvlinearcombination = N_VLinearCombination_Serial; v->ops->nvscaleaddmulti = N_VScaleAddMulti_Serial; v->ops->nvdotprodmulti = N_VDotProdMulti_Serial; /* enable all vector array operations */ - v->ops->nvlinearsumvectorarray = N_VLinearSumVectorArray_Serial; - v->ops->nvscalevectorarray = N_VScaleVectorArray_Serial; - v->ops->nvconstvectorarray = N_VConstVectorArray_Serial; - v->ops->nvwrmsnormvectorarray = N_VWrmsNormVectorArray_Serial; - v->ops->nvwrmsnormmaskvectorarray = N_VWrmsNormMaskVectorArray_Serial; - v->ops->nvscaleaddmultivectorarray = N_VScaleAddMultiVectorArray_Serial; - v->ops->nvlinearcombinationvectorarray = N_VLinearCombinationVectorArray_Serial; - } else { + v->ops->nvlinearsumvectorarray = N_VLinearSumVectorArray_Serial; + v->ops->nvscalevectorarray = N_VScaleVectorArray_Serial; + v->ops->nvconstvectorarray = N_VConstVectorArray_Serial; + v->ops->nvwrmsnormvectorarray = N_VWrmsNormVectorArray_Serial; + v->ops->nvwrmsnormmaskvectorarray = N_VWrmsNormMaskVectorArray_Serial; + v->ops->nvscaleaddmultivectorarray = N_VScaleAddMultiVectorArray_Serial; + v->ops->nvlinearcombinationvectorarray = + N_VLinearCombinationVectorArray_Serial; + /* enable single buffer reduction operations */ + v->ops->nvdotprodmultilocal = N_VDotProdMulti_Serial; + } + else + { /* disable all fused vector operations */ v->ops->nvlinearcombination = NULL; v->ops->nvscaleaddmulti = NULL; @@ -1991,189 +1986,75 @@ int N_VEnableFusedOps_Serial(N_Vector v, booleantype tf) v->ops->nvwrmsnormmaskvectorarray = NULL; v->ops->nvscaleaddmultivectorarray = NULL; v->ops->nvlinearcombinationvectorarray = NULL; + /* disable single buffer reduction operations */ + v->ops->nvdotprodmultilocal = NULL; } /* return success */ - return(0); + return SUN_SUCCESS; } - -int N_VEnableLinearCombination_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableLinearCombination_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvlinearcombination = N_VLinearCombination_Serial; - else - v->ops->nvlinearcombination = NULL; - - /* return success */ - return(0); + v->ops->nvlinearcombination = tf ? N_VLinearCombination_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableScaleAddMulti_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableScaleAddMulti_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvscaleaddmulti = N_VScaleAddMulti_Serial; - else - v->ops->nvscaleaddmulti = NULL; - - /* return success */ - return(0); + v->ops->nvscaleaddmulti = tf ? N_VScaleAddMulti_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableDotProdMulti_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableDotProdMulti_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvdotprodmulti = N_VDotProdMulti_Serial; - else - v->ops->nvdotprodmulti = NULL; - - /* return success */ - return(0); + v->ops->nvdotprodmulti = tf ? N_VDotProdMulti_Serial : NULL; + v->ops->nvdotprodmultilocal = tf ? N_VDotProdMulti_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableLinearSumVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableLinearSumVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvlinearsumvectorarray = N_VLinearSumVectorArray_Serial; - else - v->ops->nvlinearsumvectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvlinearsumvectorarray = tf ? N_VLinearSumVectorArray_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableScaleVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableScaleVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvscalevectorarray = N_VScaleVectorArray_Serial; - else - v->ops->nvscalevectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvscalevectorarray = tf ? N_VScaleVectorArray_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableConstVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableConstVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvconstvectorarray = N_VConstVectorArray_Serial; - else - v->ops->nvconstvectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvconstvectorarray = tf ? N_VConstVectorArray_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableWrmsNormVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableWrmsNormVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvwrmsnormvectorarray = N_VWrmsNormVectorArray_Serial; - else - v->ops->nvwrmsnormvectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvwrmsnormvectorarray = tf ? N_VWrmsNormVectorArray_Serial : NULL; + return SUN_SUCCESS; } -int N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvwrmsnormmaskvectorarray = N_VWrmsNormMaskVectorArray_Serial; - else - v->ops->nvwrmsnormmaskvectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvwrmsnormmaskvectorarray = tf ? N_VWrmsNormMaskVectorArray_Serial + : NULL; + return SUN_SUCCESS; } -int N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvscaleaddmultivectorarray = N_VScaleAddMultiVectorArray_Serial; - else - v->ops->nvscaleaddmultivectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvscaleaddmultivectorarray = tf ? N_VScaleAddMultiVectorArray_Serial + : NULL; + return SUN_SUCCESS; } -int N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, booleantype tf) +SUNErrCode N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, + sunbooleantype tf) { - /* check that vector is non-NULL */ - if (v == NULL) return(-1); - - /* check that ops structure is non-NULL */ - if (v->ops == NULL) return(-1); - - /* enable/disable operation */ - if (tf) - v->ops->nvlinearcombinationvectorarray = N_VLinearCombinationVectorArray_Serial; - else - v->ops->nvlinearcombinationvectorarray = NULL; - - /* return success */ - return(0); + v->ops->nvlinearcombinationvectorarray = + tf ? N_VLinearCombinationVectorArray_Serial : NULL; + return SUN_SUCCESS; } diff --git a/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/CMakeLists.txt new file mode 100644 index 000000000..f82df5e16 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/CMakeLists.txt @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------------------ +# Programmer(s): Daniel R. Reynolds @ SMU +# ------------------------------------------------------------------------------ +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# ------------------------------------------------------------------------------ +# controller level CMakeLists.txt for SUNDIALS +# ------------------------------------------------------------------------------ + +# required native matrices +add_subdirectory(imexgus) +add_subdirectory(soderlind) diff --git a/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/CMakeLists.txt new file mode 100644 index 000000000..8bbef68cd --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/CMakeLists.txt @@ -0,0 +1,31 @@ +# --------------------------------------------------------------- +# Programmer(s): Daniel R. Reynolds @ SMU +# --------------------------------------------------------------- +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# --------------------------------------------------------------- + +# Create a library out of the generic sundials modules +sundials_add_library(sundials_sunadaptcontrollerimexgus + SOURCES + sunadaptcontroller_imexgus.c + HEADERS + ${SUNDIALS_SOURCE_DIR}/include/sunadaptcontroller/sunadaptcontroller_imexgus.h + LINK_LIBRARIES + PUBLIC sundials_core + INCLUDE_SUBDIR + sunadaptcontroller + OBJECT_LIB_ONLY +) + +# Add F2003 module if the interface is enabled +if(BUILD_FORTRAN_MODULE_INTERFACE) + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") +endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c new file mode 100644 index 000000000..e4bb23e6d --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c @@ -0,0 +1,234 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This is the implementation file for the SUNAdaptController_ImExGus + * module. + * -----------------------------------------------------------------*/ + +#include +#include + +#include +#include +#include +#include + +#include "sundials_macros.h" + +/* --------------- + * Macro accessors + * --------------- */ + +#define SACIMEXGUS_CONTENT(C) ((SUNAdaptControllerContent_ImExGus)(C->content)) +#define SACIMEXGUS_K1E(C) (SACIMEXGUS_CONTENT(C)->k1e) +#define SACIMEXGUS_K2E(C) (SACIMEXGUS_CONTENT(C)->k2e) +#define SACIMEXGUS_K1I(C) (SACIMEXGUS_CONTENT(C)->k1i) +#define SACIMEXGUS_K2I(C) (SACIMEXGUS_CONTENT(C)->k2i) +#define SACIMEXGUS_BIAS(C) (SACIMEXGUS_CONTENT(C)->bias) +#define SACIMEXGUS_EP(C) (SACIMEXGUS_CONTENT(C)->ep) +#define SACIMEXGUS_HP(C) (SACIMEXGUS_CONTENT(C)->hp) +#define SACIMEXGUS_FIRSTSTEP(C) (SACIMEXGUS_CONTENT(C)->firststep) + +/* ------------------ + * Default parameters + * ------------------ */ + +#define DEFAULT_K1E SUN_RCONST(0.367) +#define DEFAULT_K2E SUN_RCONST(0.268) +#define DEFAULT_K1I SUN_RCONST(0.95) +#define DEFAULT_K2I SUN_RCONST(0.95) +#define DEFAULT_BIAS SUN_RCONST(1.5) +#define TINY SUN_RCONST(1.0e-10) + +/* ----------------------------------------------------------------- + * exported functions + * ----------------------------------------------------------------- */ + +/* ----------------------------------------------------------------- + * Function to create a new ImExGus controller + */ + +SUNAdaptController SUNAdaptController_ImExGus(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + SUNAdaptControllerContent_ImExGus content; + + /* Create an empty controller object */ + C = NULL; + C = SUNAdaptController_NewEmpty(sunctx); + SUNCheckLastErrNull(); + + /* Attach operations */ + C->ops->gettype = SUNAdaptController_GetType_ImExGus; + C->ops->estimatestep = SUNAdaptController_EstimateStep_ImExGus; + C->ops->reset = SUNAdaptController_Reset_ImExGus; + C->ops->setdefaults = SUNAdaptController_SetDefaults_ImExGus; + C->ops->write = SUNAdaptController_Write_ImExGus; + C->ops->seterrorbias = SUNAdaptController_SetErrorBias_ImExGus; + C->ops->updateh = SUNAdaptController_UpdateH_ImExGus; + C->ops->space = SUNAdaptController_Space_ImExGus; + + /* Create content */ + content = NULL; + content = (SUNAdaptControllerContent_ImExGus)malloc(sizeof *content); + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); + + /* Attach content */ + C->content = content; + + /* Fill content with default/reset values */ + SUNCheckCallNull(SUNAdaptController_SetDefaults_ImExGus(C)); + SUNCheckCallNull(SUNAdaptController_Reset_ImExGus(C)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set ImExGus parameters + */ + +SUNErrCode SUNAdaptController_SetParams_ImExGus(SUNAdaptController C, + sunrealtype k1e, sunrealtype k2e, + sunrealtype k1i, sunrealtype k2i) +{ + SUNFunctionBegin(C->sunctx); + SACIMEXGUS_K1E(C) = k1e; + SACIMEXGUS_K2E(C) = k2e; + SACIMEXGUS_K1I(C) = k1i; + SACIMEXGUS_K2I(C) = k2i; + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * implementation of controller operations + * ----------------------------------------------------------------- */ + +SUNAdaptController_Type SUNAdaptController_GetType_ImExGus( + SUNDIALS_MAYBE_UNUSED SUNAdaptController C) +{ + return SUN_ADAPTCONTROLLER_H; +} + +SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew) +{ + SUNFunctionBegin(C->sunctx); + + SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); + + /* order parameter to use */ + const int ord = p + 1; + + /* set usable time-step adaptivity parameters -- first step */ + const sunrealtype k = -SUN_RCONST(1.0) / ord; + const sunrealtype e = SUNMAX(SACIMEXGUS_BIAS(C) * dsm, TINY); + + /* set usable time-step adaptivity parameters -- subsequent steps */ + const sunrealtype k1e = -SACIMEXGUS_K1E(C) / ord; + const sunrealtype k2e = -SACIMEXGUS_K2E(C) / ord; + const sunrealtype k1i = -SACIMEXGUS_K1I(C) / ord; + const sunrealtype k2i = -SACIMEXGUS_K2I(C) / ord; + const sunrealtype e1 = SUNMAX(SACIMEXGUS_BIAS(C) * dsm, TINY); + const sunrealtype e2 = e1 / SUNMAX(SACIMEXGUS_EP(C), TINY); + const sunrealtype hrat = h / SACIMEXGUS_HP(C); + + /* compute estimated time step size, modifying the first step formula */ + if (SACIMEXGUS_FIRSTSTEP(C)) { *hnew = h * SUNRpowerR(e, k); } + else + { + *hnew = h * SUNMIN(hrat * SUNRpowerR(e1, k1i) * SUNRpowerR(e2, k2i), + SUNRpowerR(e1, k1e) * SUNRpowerR(e2, k2e)); + } + + /* return with success */ + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Reset_ImExGus(SUNAdaptController C) +{ + SACIMEXGUS_EP(C) = SUN_RCONST(1.0); + SACIMEXGUS_FIRSTSTEP(C) = SUNTRUE; + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_SetDefaults_ImExGus(SUNAdaptController C) +{ + SUNFunctionBegin(C->sunctx); + SACIMEXGUS_K1E(C) = DEFAULT_K1E; + SACIMEXGUS_K2E(C) = DEFAULT_K2E; + SACIMEXGUS_K1I(C) = DEFAULT_K1I; + SACIMEXGUS_K2I(C) = DEFAULT_K2I; + SACIMEXGUS_BIAS(C) = DEFAULT_BIAS; + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Write_ImExGus(SUNAdaptController C, FILE* fptr) +{ + SUNFunctionBegin(C->sunctx); + SUNAssert(fptr, SUN_ERR_ARG_CORRUPT); + fprintf(fptr, "ImEx Gustafsson SUNAdaptController module:\n"); +#if defined(SUNDIALS_EXTENDED_PRECISION) + fprintf(fptr, " k1e = %32Lg\n", SACIMEXGUS_K1E(C)); + fprintf(fptr, " k2e = %32Lg\n", SACIMEXGUS_K2E(C)); + fprintf(fptr, " k1i = %32Lg\n", SACIMEXGUS_K1I(C)); + fprintf(fptr, " k2i = %32Lg\n", SACIMEXGUS_K2I(C)); + fprintf(fptr, " bias factor = %22Lg\n", SACIMEXGUS_BIAS(C)); + fprintf(fptr, " previous error = %22Lg\n", SACIMEXGUS_EP(C)); + fprintf(fptr, " previous step = %22Lg\n", SACIMEXGUS_HP(C)); +#else + fprintf(fptr, " k1e = %16g\n", SACIMEXGUS_K1E(C)); + fprintf(fptr, " k2e = %16g\n", SACIMEXGUS_K2E(C)); + fprintf(fptr, " k1i = %16g\n", SACIMEXGUS_K1I(C)); + fprintf(fptr, " k2i = %16g\n", SACIMEXGUS_K2I(C)); + fprintf(fptr, " bias factor = %16g\n", SACIMEXGUS_BIAS(C)); + fprintf(fptr, " previous error = %16g\n", SACIMEXGUS_EP(C)); + fprintf(fptr, " previous step = %16g\n", SACIMEXGUS_HP(C)); +#endif + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_SetErrorBias_ImExGus(SUNAdaptController C, + sunrealtype bias) +{ + SUNFunctionBegin(C->sunctx); + /* set allowed value, otherwise set default */ + if (bias <= SUN_RCONST(0.0)) { SACIMEXGUS_BIAS(C) = DEFAULT_BIAS; } + else { SACIMEXGUS_BIAS(C) = bias; } + + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_UpdateH_ImExGus(SUNAdaptController C, + sunrealtype h, sunrealtype dsm) +{ + SUNFunctionBegin(C->sunctx); + SACIMEXGUS_EP(C) = SACIMEXGUS_BIAS(C) * dsm; + SACIMEXGUS_HP(C) = h; + SACIMEXGUS_FIRSTSTEP(C) = SUNFALSE; + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Space_ImExGus(SUNAdaptController C, + long int* lenrw, long int* leniw) +{ + SUNFunctionBegin(C->sunctx); + SUNAssert(lenrw, SUN_ERR_ARG_CORRUPT); + SUNAssert(leniw, SUN_ERR_ARG_CORRUPT); + *lenrw = 7; + *leniw = 1; + return SUN_SUCCESS; +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/CMakeLists.txt new file mode 100644 index 000000000..50cf7330b --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/CMakeLists.txt @@ -0,0 +1,31 @@ +# --------------------------------------------------------------- +# Programmer(s): Daniel R. Reynolds @ SMU +# --------------------------------------------------------------- +# SUNDIALS Copyright Start +# Copyright (c) 2002-2024, Lawrence Livermore National Security +# and Southern Methodist University. +# All rights reserved. +# +# See the top-level LICENSE and NOTICE files for details. +# +# SPDX-License-Identifier: BSD-3-Clause +# SUNDIALS Copyright End +# --------------------------------------------------------------- + +# Create a library out of the generic sundials modules +sundials_add_library(sundials_sunadaptcontrollersoderlind + SOURCES + sunadaptcontroller_soderlind.c + HEADERS + ${SUNDIALS_SOURCE_DIR}/include/sunadaptcontroller/sunadaptcontroller_soderlind.h + LINK_LIBRARIES + PUBLIC sundials_core + INCLUDE_SUBDIR + sunadaptcontroller + OBJECT_LIB_ONLY +) + +# Add F2003 module if the interface is enabled +if(BUILD_FORTRAN_MODULE_INTERFACE) + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") +endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c new file mode 100644 index 000000000..bca88252c --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c @@ -0,0 +1,435 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This is the implementation file for the + * SUNAdaptController_Soderlind module. + * -----------------------------------------------------------------*/ + +#include +#include + +#include +#include +#include +#include + +#include "sundials_macros.h" + +/* --------------- + * Macro accessors + * --------------- */ + +#define SODERLIND_CONTENT(C) ((SUNAdaptControllerContent_Soderlind)(C->content)) +#define SODERLIND_K1(C) (SODERLIND_CONTENT(C)->k1) +#define SODERLIND_K2(C) (SODERLIND_CONTENT(C)->k2) +#define SODERLIND_K3(C) (SODERLIND_CONTENT(C)->k3) +#define SODERLIND_K4(C) (SODERLIND_CONTENT(C)->k4) +#define SODERLIND_K5(C) (SODERLIND_CONTENT(C)->k5) +#define SODERLIND_BIAS(C) (SODERLIND_CONTENT(C)->bias) +#define SODERLIND_EP(C) (SODERLIND_CONTENT(C)->ep) +#define SODERLIND_EPP(C) (SODERLIND_CONTENT(C)->epp) +#define SODERLIND_HP(C) (SODERLIND_CONTENT(C)->hp) +#define SODERLIND_HPP(C) (SODERLIND_CONTENT(C)->hpp) +#define SODERLIND_FIRSTSTEPS(C) (SODERLIND_CONTENT(C)->firststeps) + +/* ------------------ + * Default parameters + * ------------------ */ + +#define DEFAULT_K1 SUN_RCONST(1.25) /* H_{0}321 parameters */ +#define DEFAULT_K2 SUN_RCONST(0.5) +#define DEFAULT_K3 SUN_RCONST(-0.75) +#define DEFAULT_K4 SUN_RCONST(0.25) +#define DEFAULT_K5 SUN_RCONST(0.75) +#define DEFAULT_PID_K1 SUN_RCONST(0.58) /* PID parameters */ +#define DEFAULT_PID_K2 -SUN_RCONST(0.21) +#define DEFAULT_PID_K3 SUN_RCONST(0.1) +#define DEFAULT_PI_K1 SUN_RCONST(0.8) /* PI parameters */ +#define DEFAULT_PI_K2 -SUN_RCONST(0.31) +#define DEFAULT_I_K1 SUN_RCONST(1.0) /* I parameters */ +#define DEFAULT_EXPGUS_K1 SUN_RCONST(0.367) /* Explicit Gustafsson parameters */ +#define DEFAULT_EXPGUS_K2 SUN_RCONST(0.268) +#define DEFAULT_IMPGUS_K1 SUN_RCONST(0.98) /* Implicit Gustafsson parameters */ +#define DEFAULT_IMPGUS_K2 SUN_RCONST(0.95) +#define DEFAULT_BIAS SUN_RCONST(1.5) +#define TINY SUN_RCONST(1.0e-10) + +/* ----------------------------------------------------------------- + * exported functions + * ----------------------------------------------------------------- */ + +/* ----------------------------------------------------------------- + * Function to create a new Soderlind controller + */ + +SUNAdaptController SUNAdaptController_Soderlind(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + SUNAdaptControllerContent_Soderlind content; + + /* Create an empty controller object */ + C = NULL; + C = SUNAdaptController_NewEmpty(sunctx); + SUNCheckLastErrNull(); + + /* Attach operations */ + C->ops->gettype = SUNAdaptController_GetType_Soderlind; + C->ops->estimatestep = SUNAdaptController_EstimateStep_Soderlind; + C->ops->reset = SUNAdaptController_Reset_Soderlind; + C->ops->setdefaults = SUNAdaptController_SetDefaults_Soderlind; + C->ops->write = SUNAdaptController_Write_Soderlind; + C->ops->seterrorbias = SUNAdaptController_SetErrorBias_Soderlind; + C->ops->updateh = SUNAdaptController_UpdateH_Soderlind; + C->ops->space = SUNAdaptController_Space_Soderlind; + + /* Create content */ + content = NULL; + content = (SUNAdaptControllerContent_Soderlind)malloc(sizeof *content); + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); + + /* Attach content */ + C->content = content; + + /* Fill content with default/reset values */ + SUNCheckCallNull(SUNAdaptController_SetDefaults_Soderlind(C)); + SUNCheckCallNull(SUNAdaptController_Reset_Soderlind(C)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set Soderlind parameters + */ + +SUNErrCode SUNAdaptController_SetParams_Soderlind(SUNAdaptController C, + sunrealtype k1, + sunrealtype k2, sunrealtype k3, + sunrealtype k4, sunrealtype k5) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1; + SODERLIND_K2(C) = k2; + SODERLIND_K3(C) = k3; + SODERLIND_K4(C) = k4; + SODERLIND_K5(C) = k5; + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * Function to create a PID controller (subset of Soderlind) + */ + +SUNAdaptController SUNAdaptController_PID(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_PID(C, DEFAULT_PID_K1, + DEFAULT_PID_K2, + DEFAULT_PID_K3)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set PID parameters + */ + +SUNErrCode SUNAdaptController_SetParams_PID(SUNAdaptController C, sunrealtype k1, + sunrealtype k2, sunrealtype k3) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1; + SODERLIND_K2(C) = k2; + SODERLIND_K3(C) = k3; + SODERLIND_K4(C) = SUN_RCONST(0.0); + SODERLIND_K5(C) = SUN_RCONST(0.0); + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * Function to create a PI controller (subset of Soderlind) + */ + +SUNAdaptController SUNAdaptController_PI(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull( + SUNAdaptController_SetParams_PI(C, DEFAULT_PI_K1, DEFAULT_PI_K2)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set PI parameters + */ + +SUNErrCode SUNAdaptController_SetParams_PI(SUNAdaptController C, sunrealtype k1, + sunrealtype k2) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1; + SODERLIND_K2(C) = k2; + SODERLIND_K3(C) = SUN_RCONST(0.0); + SODERLIND_K4(C) = SUN_RCONST(0.0); + SODERLIND_K5(C) = SUN_RCONST(0.0); + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * Function to create an I controller (subset of Soderlind) + */ + +SUNAdaptController SUNAdaptController_I(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_I(C, DEFAULT_I_K1)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set PI parameters + */ + +SUNErrCode SUNAdaptController_SetParams_I(SUNAdaptController C, sunrealtype k1) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1; + SODERLIND_K2(C) = SUN_RCONST(0.0); + SODERLIND_K3(C) = SUN_RCONST(0.0); + SODERLIND_K4(C) = SUN_RCONST(0.0); + SODERLIND_K5(C) = SUN_RCONST(0.0); + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * Function to create an explicit Gustafsson controller + */ + +SUNAdaptController SUNAdaptController_ExpGus(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_ExpGus(C, DEFAULT_EXPGUS_K1, + DEFAULT_EXPGUS_K2)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set explicit Gustafsson parameters + */ + +SUNErrCode SUNAdaptController_SetParams_ExpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1 + k2; + SODERLIND_K2(C) = -k2; + SODERLIND_K3(C) = SUN_RCONST(0.0); + SODERLIND_K4(C) = SUN_RCONST(0.0); + SODERLIND_K5(C) = SUN_RCONST(0.0); + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * Function to create an implicit Gustafsson controller + */ + +SUNAdaptController SUNAdaptController_ImpGus(SUNContext sunctx) +{ + SUNFunctionBegin(sunctx); + + SUNAdaptController C; + C = SUNAdaptController_Soderlind(sunctx); + SUNCheckLastErrNull(); + + SUNCheckCallNull(SUNAdaptController_SetParams_ImpGus(C, DEFAULT_IMPGUS_K1, + DEFAULT_IMPGUS_K2)); + + return (C); +} + +/* ----------------------------------------------------------------- + * Function to set explicit Gustafsson parameters + */ + +SUNErrCode SUNAdaptController_SetParams_ImpGus(SUNAdaptController C, + sunrealtype k1, sunrealtype k2) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = k1 + k2; + SODERLIND_K2(C) = -k2; + SODERLIND_K3(C) = SUN_RCONST(0.0); + SODERLIND_K4(C) = SUN_RCONST(1.0); + SODERLIND_K5(C) = SUN_RCONST(0.0); + return SUN_SUCCESS; +} + +/* ----------------------------------------------------------------- + * implementation of controller operations + * ----------------------------------------------------------------- */ + +SUNAdaptController_Type SUNAdaptController_GetType_Soderlind( + SUNDIALS_MAYBE_UNUSED SUNAdaptController C) +{ + return SUN_ADAPTCONTROLLER_H; +} + +SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, + sunrealtype h, int p, + sunrealtype dsm, + sunrealtype* hnew) +{ + SUNFunctionBegin(C->sunctx); + SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); + + /* order parameter to use */ + const int ord = p + 1; + + /* set usable time-step adaptivity parameters */ + const sunrealtype k1 = -SODERLIND_K1(C) / ord; + const sunrealtype k2 = -SODERLIND_K2(C) / ord; + const sunrealtype k3 = -SODERLIND_K3(C) / ord; + const sunrealtype k4 = SODERLIND_K4(C); + const sunrealtype k5 = SODERLIND_K5(C); + const sunrealtype e1 = SUNMAX(SODERLIND_BIAS(C) * dsm, TINY); + const sunrealtype e2 = SUNMAX(SODERLIND_EP(C), TINY); + const sunrealtype e3 = SUNMAX(SODERLIND_EPP(C), TINY); + const sunrealtype hrat = h / SODERLIND_HP(C); + const sunrealtype hrat2 = SODERLIND_HP(C) / SODERLIND_HPP(C); + + /* compute estimated optimal time step size */ + if (SODERLIND_FIRSTSTEPS(C) < 1) { *hnew = h * SUNRpowerR(e1, k1); } + else if (SODERLIND_FIRSTSTEPS(C) < 2) + { + *hnew = h * SUNRpowerR(e1, k1) * SUNRpowerR(e2, k2) * SUNRpowerR(hrat, k4); + } + else + { + *hnew = h * SUNRpowerR(e1, k1) * SUNRpowerR(e2, k2) * SUNRpowerR(e3, k3) * + SUNRpowerR(hrat, k4) * SUNRpowerR(hrat2, k5); + } + + /* return with success */ + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Reset_Soderlind(SUNAdaptController C) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_EP(C) = SUN_RCONST(1.0); + SODERLIND_EPP(C) = SUN_RCONST(1.0); + SODERLIND_HP(C) = SUN_RCONST(1.0); + SODERLIND_HPP(C) = SUN_RCONST(1.0); + SODERLIND_FIRSTSTEPS(C) = 0; + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_SetDefaults_Soderlind(SUNAdaptController C) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_K1(C) = DEFAULT_K1; + SODERLIND_K2(C) = DEFAULT_K2; + SODERLIND_K3(C) = DEFAULT_K3; + SODERLIND_K4(C) = DEFAULT_K4; + SODERLIND_K5(C) = DEFAULT_K5; + SODERLIND_BIAS(C) = DEFAULT_BIAS; + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Write_Soderlind(SUNAdaptController C, FILE* fptr) +{ + SUNFunctionBegin(C->sunctx); + SUNAssert(fptr, SUN_ERR_ARG_CORRUPT); + fprintf(fptr, "Soderlind SUNAdaptController module:\n"); +#if defined(SUNDIALS_EXTENDED_PRECISION) + fprintf(fptr, " k1 = %32Lg\n", SODERLIND_K1(C)); + fprintf(fptr, " k2 = %32Lg\n", SODERLIND_K2(C)); + fprintf(fptr, " k3 = %32Lg\n", SODERLIND_K3(C)); + fprintf(fptr, " k4 = %32Lg\n", SODERLIND_K4(C)); + fprintf(fptr, " k5 = %32Lg\n", SODERLIND_K5(C)); + fprintf(fptr, " bias factor = %22Lg\n", SODERLIND_BIAS(C)); + fprintf(fptr, " previous error = %22Lg\n", SODERLIND_EP(C)); + fprintf(fptr, " previous-previous error = %22Lg\n", SODERLIND_EPP(C)); + fprintf(fptr, " previous step = %22Lg\n", SODERLIND_HP(C)); + fprintf(fptr, " previous-previous step = %22Lg\n", SODERLIND_HPP(C)); +#else + fprintf(fptr, " k1 = %16g\n", SODERLIND_K1(C)); + fprintf(fptr, " k2 = %16g\n", SODERLIND_K2(C)); + fprintf(fptr, " k3 = %16g\n", SODERLIND_K3(C)); + fprintf(fptr, " k4 = %16g\n", SODERLIND_K4(C)); + fprintf(fptr, " k5 = %16g\n", SODERLIND_K5(C)); + fprintf(fptr, " bias factor = %16g\n", SODERLIND_BIAS(C)); + fprintf(fptr, " previous error = %16g\n", SODERLIND_EP(C)); + fprintf(fptr, " previous-previous error = %16g\n", SODERLIND_EPP(C)); + fprintf(fptr, " previous step = %16g\n", SODERLIND_HP(C)); + fprintf(fptr, " previous-previous step = %16g\n", SODERLIND_HPP(C)); +#endif + fprintf(fptr, " firststeps = %i\n", SODERLIND_FIRSTSTEPS(C)); + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_SetErrorBias_Soderlind(SUNAdaptController C, + sunrealtype bias) +{ + SUNFunctionBegin(C->sunctx); + + /* set allowed value, otherwise set default */ + if (bias <= SUN_RCONST(0.0)) { SODERLIND_BIAS(C) = DEFAULT_BIAS; } + else { SODERLIND_BIAS(C) = bias; } + + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_UpdateH_Soderlind(SUNAdaptController C, + sunrealtype h, sunrealtype dsm) +{ + SUNFunctionBegin(C->sunctx); + SODERLIND_EPP(C) = SODERLIND_EP(C); + SODERLIND_EP(C) = SODERLIND_BIAS(C) * dsm; + SODERLIND_HPP(C) = SODERLIND_HP(C); + SODERLIND_HP(C) = h; + if (SODERLIND_FIRSTSTEPS(C) < 2) { SODERLIND_FIRSTSTEPS(C) += 1; } + return SUN_SUCCESS; +} + +SUNErrCode SUNAdaptController_Space_Soderlind(SUNAdaptController C, + long int* lenrw, long int* leniw) +{ + SUNFunctionBegin(C->sunctx); + SUNAssert(lenrw, SUN_ERR_ARG_CORRUPT); + SUNAssert(leniw, SUN_ERR_ARG_CORRUPT); + *lenrw = 10; + *leniw = 1; + return SUN_SUCCESS; +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/CMakeLists.txt b/deps/AMICI/ThirdParty/sundials/src/sundials/CMakeLists.txt index f4d32ca2c..b8a19e2ff 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/CMakeLists.txt +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/CMakeLists.txt @@ -2,7 +2,7 @@ # Programmer(s): Radu Serban and Cody J. Balos @ LLNL # --------------------------------------------------------------- # SUNDIALS Copyright Start -# Copyright (c) 2002-2021, Lawrence Livermore National Security +# Copyright (c) 2002-2024, Lawrence Livermore National Security # and Southern Methodist University. # All rights reserved. # @@ -21,23 +21,43 @@ install(CODE "MESSAGE(\"\nInstall shared components\n\")") # Add variable sundials_HEADERS with the exported SUNDIALS header files set(sundials_HEADERS + sundials_adaptcontroller.h sundials_band.h + sundials_base.hpp + sundials_context.h + sundials_context.hpp + sundials_convertibleto.hpp + sundials_core.h + sundials_core.hpp sundials_dense.h sundials_direct.h - sundials_fnvector.h + sundials_errors.h sundials_futils.h sundials_iterative.h sundials_linearsolver.h + sundials_linearsolver.hpp + sundials_logger.h sundials_math.h sundials_matrix.h + sundials_matrix.hpp sundials_memory.h - sundials_nonlinearsolver.h + sundials_memory.hpp sundials_mpi_types.h + sundials_nonlinearsolver.h + sundials_nonlinearsolver.hpp sundials_nvector.h + sundials_nvector.hpp + sundials_profiler.h + sundials_profiler.hpp + sundials_types_deprecated.h sundials_types.h sundials_version.h ) +if(ENABLE_MPI) + list(APPEND sundials_HEADERS sundials_mpi_errors.h) +endif() + if(ENABLE_CUDA) list(APPEND sundials_HEADERS sundials_cuda_policies.hpp) endif() @@ -50,11 +70,6 @@ if(ENABLE_SYCL) list(APPEND sundials_HEADERS sundials_sycl_policies.hpp) endif() -# If Blas/Lapack support was enabled, add the Lapack interface headers -if(BUILD_SUNLINSOL_LAPACKBAND OR BUILD_SUNLINSOL_LAPACKDENSE) - list(APPEND sundials_HEADERS sundials_lapack.h) -endif() - # If enabled, add the XBraid interface header if(ENABLE_XBRAID) list(APPEND sundials_HEADERS sundials_xbraid.h) @@ -64,48 +79,89 @@ endif() add_prefix(${SUNDIALS_SOURCE_DIR}/include/sundials/ sundials_HEADERS) set(sundials_SOURCES + sundials_adaptcontroller.c sundials_band.c + sundials_context.c sundials_dense.c sundials_direct.c + sundials_errors.c sundials_futils.c + sundials_hashmap.c sundials_iterative.c sundials_linearsolver.c + sundials_logger.c sundials_math.c sundials_matrix.c sundials_memory.c sundials_nonlinearsolver.c - sundials_nvector.c sundials_nvector_senswrapper.c - sundials_version.c) + sundials_nvector.c + sundials_profiler.c + sundials_version.c + ) + +if(ENABLE_MPI) + list(APPEND sundials_SOURCES sundials_mpi_errors.c) +endif() # Add prefix with complete path to the source files add_prefix(${SUNDIALS_SOURCE_DIR}/src/sundials/ sundials_SOURCES) +if(ENABLE_MPI) + set(_link_mpi_if_needed PUBLIC + MPI::MPI_C + $<$:MPI::MPI_CXX>) +endif() + + +if(SUNDIALS_BUILD_WITH_PROFILING) + if(ENABLE_CALIPER) + set(_link_caliper_if_needed PUBLIC caliper) + endif() + if(ENABLE_ADIAK) + set(_link_adiak_if_needed PUBLIC adiak::adiak ${CMAKE_DL_LIBS}) + endif() +endif() + # Create a library out of the generic sundials modules -sundials_add_library(sundials_generic +sundials_add_library(sundials_core SOURCES ${sundials_SOURCES} HEADERS ${sundials_HEADERS} INCLUDE_SUBDIR sundials + LINK_LIBRARIES + ${_link_mpi_if_needed} OUTPUT_NAME - sundials_generic + sundials_core VERSION ${sundialslib_VERSION} SOVERSION ${sundialslib_SOVERSION} ) +# Install private headers +install(FILES + ${SUNDIALS_SOURCE_DIR}/include/sundials/priv/sundials_context_impl.h + ${SUNDIALS_SOURCE_DIR}/include/sundials/priv/sundials_errors_impl.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sundials/priv") + +if(ENABLE_MPI) + install(FILES + ${SUNDIALS_SOURCE_DIR}/include/sundials/priv/sundials_mpi_errors_impl.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sundials/priv") +endif() + # SUNDIALS_EXPORT macro include(GenerateExportHeader) generate_export_header( - sundials_generic BASE_NAME SUNDIALS + sundials_core BASE_NAME SUNDIALS EXPORT_FILE_NAME "${PROJECT_BINARY_DIR}/include/sundials/sundials_export.h" ) # Add F2003 module if the interface is enabled if(BUILD_FORTRAN_MODULE_INTERFACE) - add_subdirectory(fmod) + add_subdirectory("fmod_int${SUNDIALS_INDEX_SIZE}") endif() diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adaptcontroller.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adaptcontroller.c new file mode 100644 index 000000000..39a56480d --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adaptcontroller.c @@ -0,0 +1,199 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Daniel R. Reynolds @ SMU + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * This is the implementation file for a generic SUNAdaptController + * package. It contains the implementation of the SUNAdaptController + * operations listed in sundials_adaptcontroller.h + * -----------------------------------------------------------------*/ + +#include +#include + +#include "sundials/sundials_errors.h" + +/* ----------------------------------------------------------------- + * Create a new empty SUNAdaptController object + * ----------------------------------------------------------------- */ + +SUNAdaptController SUNAdaptController_NewEmpty(SUNContext sunctx) +{ + SUNAdaptController C; + SUNAdaptController_Ops ops; + + /* a context is required */ + if (sunctx == NULL) { return (NULL); } + + SUNFunctionBegin(sunctx); + + /* create controller object */ + C = NULL; + C = (SUNAdaptController)malloc(sizeof *C); + SUNAssertNull(C, SUN_ERR_MALLOC_FAIL); + + /* create matrix ops structure */ + ops = NULL; + ops = (SUNAdaptController_Ops)malloc(sizeof *ops); + SUNAssertNull(ops, SUN_ERR_MALLOC_FAIL); + + /* initialize operations to NULL */ + ops->gettype = NULL; + ops->destroy = NULL; + ops->reset = NULL; + ops->estimatestep = NULL; + ops->setdefaults = NULL; + ops->write = NULL; + ops->seterrorbias = NULL; + ops->updateh = NULL; + ops->space = NULL; + + /* attach ops and initialize content to NULL */ + C->ops = ops; + C->content = NULL; + C->sunctx = sunctx; + + return (C); +} + +/* ----------------------------------------------------------------- + * Free a generic SUNAdaptController (assumes content is already empty) + * ----------------------------------------------------------------- */ + +void SUNAdaptController_DestroyEmpty(SUNAdaptController C) +{ + if (C == NULL) { return; } + + /* free non-NULL ops structure */ + if (C->ops) { free(C->ops); } + C->ops = NULL; + + /* free overall SUNAdaptController object and return */ + free(C); + return; +} + +/* ----------------------------------------------------------------- + * Required functions in the 'ops' structure for non-NULL controller + * ----------------------------------------------------------------- */ + +SUNAdaptController_Type SUNAdaptController_GetType(SUNAdaptController C) +{ + if (C == NULL) { return SUN_ADAPTCONTROLLER_NONE; } + if (C->ops->gettype) { return C->ops->gettype(C); } + return SUN_ADAPTCONTROLLER_NONE; +} + +/* ----------------------------------------------------------------- + * Optional functions in the 'ops' structure + * ----------------------------------------------------------------- */ + +SUNErrCode SUNAdaptController_Destroy(SUNAdaptController C) +{ + if (C == NULL) { return (SUN_SUCCESS); } + + /* if the destroy operation exists use it */ + if (C->ops) + { + if (C->ops->destroy) { return (C->ops->destroy(C)); } + } + + /* if we reach this point, either ops == NULL or destroy == NULL, + try to cleanup by freeing the content, ops, and matrix */ + if (C->content) + { + free(C->content); + C->content = NULL; + } + if (C->ops) + { + free(C->ops); + C->ops = NULL; + } + free(C); + C = NULL; + + return (SUN_SUCCESS); +} + +SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, + int p, sunrealtype dsm, + sunrealtype* hnew) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); + *hnew = h; /* initialize output with identity */ + if (C->ops->estimatestep) { ier = C->ops->estimatestep(C, h, p, dsm, hnew); } + return (ier); +} + +SUNErrCode SUNAdaptController_Reset(SUNAdaptController C) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + if (C->ops->reset) { ier = C->ops->reset(C); } + return (ier); +} + +SUNErrCode SUNAdaptController_SetDefaults(SUNAdaptController C) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + if (C->ops->setdefaults) { ier = C->ops->setdefaults(C); } + return (ier); +} + +SUNErrCode SUNAdaptController_Write(SUNAdaptController C, FILE* fptr) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + SUNAssert(fptr, SUN_ERR_ARG_CORRUPT); + if (C->ops->write) { ier = C->ops->write(C, fptr); } + return (ier); +} + +SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, sunrealtype bias) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + if (C->ops->seterrorbias) { ier = C->ops->seterrorbias(C, bias); } + return (ier); +} + +SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, + sunrealtype dsm) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + if (C->ops->updateh) { ier = C->ops->updateh(C, h, dsm); } + return (ier); +} + +SUNErrCode SUNAdaptController_Space(SUNAdaptController C, long int* lenrw, + long int* leniw) +{ + SUNErrCode ier = SUN_SUCCESS; + if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } + SUNFunctionBegin(C->sunctx); + SUNAssert(lenrw, SUN_ERR_ARG_CORRUPT); + SUNAssert(leniw, SUN_ERR_ARG_CORRUPT); + *lenrw = 0; /* initialize outputs with identity */ + *leniw = 0; + if (C->ops->space) { ier = C->ops->space(C, lenrw, leniw); } + return (ier); +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adiak_metadata.h b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adiak_metadata.h new file mode 100644 index 000000000..4e7e908a6 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_adiak_metadata.h @@ -0,0 +1,149 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Yu Pan and Cody Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ADIAK_METADATA_H +#define _SUNDIALS_ADIAK_METADATA_H + +#ifdef SUNDIALS_ADIAK_ENABLED +#include + +static void sunAdiakCollectMetadata() +{ + adiak_launchdate(); + adiak_executable(); + adiak_cmdline(); + adiak_clustername(); + + adiak_job_size(); + adiak_num_hosts(); + + adiak_namevalue("c_compiler", 2, NULL, "%s", SUN_C_COMPILER); + adiak_namevalue("c_compiler_version", 2, NULL, "%s", SUN_C_COMPILER_VERSION); + adiak_namevalue("c_compiler_flags", 2, NULL, "%s", SUN_C_COMPILER_FLAGS); + + adiak_namevalue("cxx_compiler", 2, NULL, "%s", SUN_CXX_COMPILER); + adiak_namevalue("cxx_compiler_version", 2, NULL, "%s", + SUN_CXX_COMPILER_VERSION); + adiak_namevalue("cxx_compiler_flags", 2, NULL, "%s", SUN_CXX_COMPILER_FLAGS); + + adiak_namevalue("fortran_compiler", 2, NULL, "%s", SUN_FORTRAN_COMPILER); + adiak_namevalue("fortran_compiler_version", 2, NULL, "%s", + SUN_FORTRAN_COMPILER_VERSION); + adiak_namevalue("fortran_compiler_flags", 2, NULL, "%s", + SUN_FORTRAN_COMPILER_FLAGS); + + adiak_namevalue("sundials_version", 2, NULL, "%s", SUNDIALS_VERSION); + adiak_namevalue("sundials_git_version", 2, NULL, "%s", SUNDIALS_GIT_VERSION); + adiak_namevalue("build_type", 2, NULL, "%s", SUN_BUILD_TYPE); + adiak_namevalue("third_party_libraries", 2, NULL, "%s", SUN_TPL_LIST); +#ifdef SUN_JOB_ID + adiak_namevalue("job_id", 2, NULL, "%s", SUN_JOB_ID); +#endif + adiak_namevalue("job_start_time", 2, NULL, "%s", SUN_JOB_START_TIME); + +#ifdef SUNDIALS_SPACK_VERSION + adiak_namevalue("spack_version", 2, NULL, "%s", SUNDIALS_SPACK_VERSION); +#endif + +#ifdef SUNDIALS_GINKGO_ENABLED + adiak_namevalue("ginkgo_version", 2, NULL, "%s", SUN_GINKGO_VERSION); +#endif + +#ifdef SUNDIALS_HYPRE_ENABLED + adiak_namevalue("hypre_version", 2, NULL, "%s", SUN_HYPRE_VERSION); +#endif + +#ifdef SUNDIALS_KLU_ENABLED + adiak_namevalue("klu_version", 2, NULL, "%s", SUN_KLU_VERSION); +#endif + +#ifdef SUNDIALS_KOKKOS_ENABLED + adiak_namevalue("kokkos_version", 2, NULL, "%s", SUN_KOKKOS_VERSION); +#endif + +#ifdef SUNDIALS_KOKKOS_KERNELS_ENABLED + adiak_namevalue("kokkos_kernels_version", 2, NULL, "%s", + SUN_KOKKOS_KERNELS_VERSION); +#endif + +#ifdef SUNDIALS_BLAS_LAPACK_ENABLED + adiak_namevalue("lapack_version", 2, NULL, "%s", SUN_LAPACK_VERSION); +#endif + +#ifdef SUNDIALS_MAGMA_ENABLED + adiak_namevalue("magma_version", 2, NULL, "%s", SUN_MAGMA_VERSION); +#endif + +#if SUNDIALS_MPI_ENABLED + adiak_namevalue("mpi_c_compiler", 2, NULL, "%s", SUN_MPI_C_COMPILER); + adiak_namevalue("mpi_c_version", 2, NULL, "%s", SUN_MPI_C_VERSION); + + adiak_namevalue("mpi_cxx_compiler", 2, NULL, "%s", SUN_MPI_CXX_COMPILER); + adiak_namevalue("mpi_cxx_version", 2, NULL, "%s", SUN_MPI_CXX_VERSION); + + adiak_namevalue("mpi_fortran_compiler", 2, NULL, "%s", + SUN_MPI_FORTRAN_COMPILER); + adiak_namevalue("mpi_fortran_version", 2, NULL, "%s", SUN_MPI_FORTRAN_VERSION); +#endif + +#ifdef SUNDIALS_ONEMKL_ENABLED + adiak_namevalue("onemkl_version", 2, NULL, "%s", SUN_ONEMKL_VERSION); +#endif + +#ifdef SUNDIALS_OPENMP_ENABLED + adiak_namevalue("openmp_version", 2, NULL, "%s", SUN_OPENMP_VERSION); +#endif + +#ifdef SUNDIALS_PETSC_ENABLED + adiak_namevalue("petsc_version", 2, NULL, "%s", SUN_PETSC_VERSION); +#endif + +#ifdef SUNDIALS_PTHREADS_ENABLED + adiak_namevalue("pthreads_version", 2, NULL, "%s", SUN_PTHREADS_VERSION); +#endif + +#ifdef SUNDIALS_RAJA_ENABLED + adiak_namevalue("raja_version", 2, NULL, "%s", SUN_RAJA_VERSION); +#endif + +#ifdef SUNDIALS_SUPERLUDIST_ENABLED + adiak_namevalue("superludist_version", 2, NULL, "%s", SUN_SUPERLUDIST_VERSION); +#endif + +#ifdef SUNDIALS_SUPERLUMT_ENABLED + adiak_namevalue("superlumt_version", 2, NULL, "%s", SUN_SUPERLUMT_VERSION); +#endif + +#ifdef SUNDIALS_TRILLINOS_ENABLED + adiak_namevalue("trillinos_version", 2, NULL, "%s", SUN_TRILLINOS_VERSION); +#endif + +#ifdef SUNDIALS_XBRAID_ENABLED + adiak_namevalue("xbraid_version", 2, NULL, "%s", SUN_XBRAID_VERSION); +#endif + +#ifdef SUNDIALS_CUDA_ENABLED + adiak_namevalue("cuda_version", 2, NULL, "%s", SUN_CUDA_VERSION); + adiak_namevalue("cuda_compiler", 2, NULL, "%s", SUN_CUDA_COMPILER); + adiak_namevalue("cuda_architectures", 2, NULL, "%s", SUN_CUDA_ARCHITECTURES); +#endif + +#ifdef SUNDIALS_HIP_ENABLED + adiak_namevalue("hip_version", 2, NULL, "%s", SUN_HIP_VERSION); + adiak_namevalue("amdgpu_targets", 2, NULL, "%s", SUN_AMDGPU_TARGETS); +#endif +} +#endif + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_band.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_band.c index 66da9f90d..d5fbcbb6a 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_band.c +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_band.c @@ -1,12 +1,9 @@ /* - * ----------------------------------------------------------------- - * $Revision$ - * $Date$ * ----------------------------------------------------------------- * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,104 +19,109 @@ #include #include - #include #include -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) -#define ROW(i,j,smu) (i-j+smu) +#define ROW(i, j, smu) (i - j + smu) /* * ----------------------------------------------------- - * Functions working on DlsMat + * Functions working on SUNDlsMat * ----------------------------------------------------- */ -sunindextype BandGBTRF(DlsMat A, sunindextype *p) +sunindextype SUNDlsMat_BandGBTRF(SUNDlsMat A, sunindextype* p) { - return(bandGBTRF(A->cols, A->M, A->mu, A->ml, A->s_mu, p)); + return (SUNDlsMat_bandGBTRF(A->cols, A->M, A->mu, A->ml, A->s_mu, p)); } -void BandGBTRS(DlsMat A, sunindextype *p, realtype *b) +void SUNDlsMat_BandGBTRS(SUNDlsMat A, sunindextype* p, sunrealtype* b) { - bandGBTRS(A->cols, A->M, A->s_mu, A->ml, p, b); + SUNDlsMat_bandGBTRS(A->cols, A->M, A->s_mu, A->ml, p, b); } -void BandCopy(DlsMat A, DlsMat B, sunindextype copymu, sunindextype copyml) +void SUNDlsMat_BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, + sunindextype copyml) { - bandCopy(A->cols, B->cols, A->M, A->s_mu, B->s_mu, copymu, copyml); + SUNDlsMat_bandCopy(A->cols, B->cols, A->M, A->s_mu, B->s_mu, copymu, copyml); } -void BandScale(realtype c, DlsMat A) +void SUNDlsMat_BandScale(sunrealtype c, SUNDlsMat A) { - bandScale(c, A->cols, A->M, A->mu, A->ml, A->s_mu); + SUNDlsMat_bandScale(c, A->cols, A->M, A->mu, A->ml, A->s_mu); } -void BandMatvec(DlsMat A, realtype *x, realtype *y) +void SUNDlsMat_BandMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y) { - bandMatvec(A->cols, x, y, A->M, A->mu, A->ml, A->s_mu); + SUNDlsMat_bandMatvec(A->cols, x, y, A->M, A->mu, A->ml, A->s_mu); } /* * ----------------------------------------------------- - * Functions working on realtype** + * Functions working on sunrealtype** * ----------------------------------------------------- */ -sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu, sunindextype *p) +sunindextype SUNDlsMat_bandGBTRF(sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, + sunindextype smu, sunindextype* p) { sunindextype c, r, num_rows; sunindextype i, j, k, l, storage_l, storage_k, last_col_k, last_row_k; - realtype *a_c, *col_k, *diag_k, *sub_diag_k, *col_j, *kptr, *jptr; - realtype max, temp, mult, a_kj; - booleantype swap; + sunrealtype *a_c, *col_k, *diag_k, *sub_diag_k, *col_j, *kptr, *jptr; + sunrealtype max, temp, mult, a_kj; + sunbooleantype swap; /* zero out the first smu - mu rows of the rectangular array a */ num_rows = smu - mu; - if (num_rows > 0) { - for (c=0; c < n; c++) { + if (num_rows > 0) + { + for (c = 0; c < n; c++) + { a_c = a[c]; - for (r=0; r < num_rows; r++) { - a_c[r] = ZERO; - } + for (r = 0; r < num_rows; r++) { a_c[r] = ZERO; } } } /* k = elimination step number */ - for (k=0; k < n-1; k++, p++) { - - col_k = a[k]; - diag_k = col_k + smu; + for (k = 0; k < n - 1; k++, p++) + { + col_k = a[k]; + diag_k = col_k + smu; sub_diag_k = diag_k + 1; - last_row_k = SUNMIN(n-1,k+ml); + last_row_k = SUNMIN(n - 1, k + ml); /* find l = pivot row number */ - l=k; + l = k; max = SUNRabs(*diag_k); - for (i=k+1, kptr=sub_diag_k; i <= last_row_k; i++, kptr++) { - if (SUNRabs(*kptr) > max) { - l=i; - max = SUNRabs(*kptr); + for (i = k + 1, kptr = sub_diag_k; i <= last_row_k; i++, kptr++) + { + if (SUNRabs(*kptr) > max) + { + l = i; + max = SUNRabs(*kptr); } } storage_l = ROW(l, k, smu); - *p = l; - + *p = l; + /* check for zero pivot element */ - if (col_k[storage_l] == ZERO) return(k+1); - + if (col_k[storage_l] == ZERO) { return (k + 1); } + /* swap a(l,k) and a(k,k) if necessary */ - - if ( (swap = (l != k) )) { - temp = col_k[storage_l]; + + if ((swap = (l != k))) + { + temp = col_k[storage_l]; col_k[storage_l] = *diag_k; - *diag_k = temp; + *diag_k = temp; } /* Scale the elements below the diagonal in */ @@ -127,138 +129,145 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty /* a(k,k) holds the pivot element. This scaling */ /* stores the pivot row multipliers -a(i,k)/a(k,k) */ /* in a(i,k), i=k+1, ..., SUNMIN(n-1,k+ml). */ - + mult = -ONE / (*diag_k); - for (i=k+1, kptr = sub_diag_k; i <= last_row_k; i++, kptr++) + for (i = k + 1, kptr = sub_diag_k; i <= last_row_k; i++, kptr++) + { (*kptr) *= mult; + } /* row_i = row_i - [a(i,k)/a(k,k)] row_k, i=k+1, ..., SUNMIN(n-1,k+ml) */ /* row k is the pivot row after swapping with row l. */ /* The computation is done one column at a time, */ /* column j=k+1, ..., SUNMIN(k+smu,n-1). */ - - last_col_k = SUNMIN(k+smu,n-1); - for (j=k+1; j <= last_col_k; j++) { - - col_j = a[j]; - storage_l = ROW(l,j,smu); - storage_k = ROW(k,j,smu); - a_kj = col_j[storage_l]; + + last_col_k = SUNMIN(k + smu, n - 1); + for (j = k + 1; j <= last_col_k; j++) + { + col_j = a[j]; + storage_l = ROW(l, j, smu); + storage_k = ROW(k, j, smu); + a_kj = col_j[storage_l]; /* Swap the elements a(k,j) and a(k,l) if l!=k. */ - - if (swap) { - col_j[storage_l] = col_j[storage_k]; - col_j[storage_k] = a_kj; + + if (swap) + { + col_j[storage_l] = col_j[storage_k]; + col_j[storage_k] = a_kj; } /* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */ /* a_kj = a(k,j), *kptr = - a(i,k)/a(k,k), *jptr = a(i,j) */ - if (a_kj != ZERO) { - for (i=k+1, kptr=sub_diag_k, jptr=col_j+ROW(k+1,j,smu); - i <= last_row_k; - i++, kptr++, jptr++) - (*jptr) += a_kj * (*kptr); + if (a_kj != ZERO) + { + for (i = k + 1, kptr = sub_diag_k, jptr = col_j + ROW(k + 1, j, smu); + i <= last_row_k; i++, kptr++, jptr++) + { + (*jptr) += a_kj * (*kptr); + } } - } + } } - + /* set the last pivot row to be n-1 and check for a zero pivot */ - *p = n-1; - if (a[n-1][smu] == ZERO) return(n); + *p = n - 1; + if (a[n - 1][smu] == ZERO) { return (n); } /* return 0 to indicate success */ - return(0); + return (0); } -void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, sunindextype ml, sunindextype *p, realtype *b) +void SUNDlsMat_bandGBTRS(sunrealtype** a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype* p, sunrealtype* b) { sunindextype k, l, i, first_row_k, last_row_k; - realtype mult, *diag_k; - + sunrealtype mult, *diag_k; + /* Solve Ly = Pb, store solution y in b */ - - for (k=0; k < n-1; k++) { - l = p[k]; + + for (k = 0; k < n - 1; k++) + { + l = p[k]; mult = b[l]; - if (l != k) { + if (l != k) + { b[l] = b[k]; b[k] = mult; } - diag_k = a[k]+smu; - last_row_k = SUNMIN(n-1,k+ml); - for (i=k+1; i <= last_row_k; i++) - b[i] += mult * diag_k[i-k]; + diag_k = a[k] + smu; + last_row_k = SUNMIN(n - 1, k + ml); + for (i = k + 1; i <= last_row_k; i++) { b[i] += mult * diag_k[i - k]; } } - + /* Solve Ux = y, store solution x in b */ - - for (k=n-1; k >= 0; k--) { - diag_k = a[k]+smu; - first_row_k = SUNMAX(0,k-smu); + + for (k = n - 1; k >= 0; k--) + { + diag_k = a[k] + smu; + first_row_k = SUNMAX(0, k - smu); b[k] /= (*diag_k); mult = -b[k]; - for (i=first_row_k; i <= k-1; i++) - b[i] += mult*diag_k[i-k]; + for (i = first_row_k; i <= k - 1; i++) { b[i] += mult * diag_k[i - k]; } } } -void bandCopy(realtype **a, realtype **b, sunindextype n, sunindextype a_smu, sunindextype b_smu, - sunindextype copymu, sunindextype copyml) +void SUNDlsMat_bandCopy(sunrealtype** a, sunrealtype** b, sunindextype n, + sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml) { sunindextype i, j, copySize; - realtype *a_col_j, *b_col_j; + sunrealtype *a_col_j, *b_col_j; copySize = copymu + copyml + 1; - - for (j=0; j < n; j++) { - a_col_j = a[j]+a_smu-copymu; - b_col_j = b[j]+b_smu-copymu; - for (i=0; i < copySize; i++) - b_col_j[i] = a_col_j[i]; + + for (j = 0; j < n; j++) + { + a_col_j = a[j] + a_smu - copymu; + b_col_j = b[j] + b_smu - copymu; + for (i = 0; i < copySize; i++) { b_col_j[i] = a_col_j[i]; } } } -void bandScale(realtype c, realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu) +void SUNDlsMat_bandScale(sunrealtype c, sunrealtype** a, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu) { sunindextype i, j, colSize; - realtype *col_j; + sunrealtype* col_j; colSize = mu + ml + 1; - for(j=0; j < n; j++) { - col_j = a[j]+smu-mu; - for (i=0; i < colSize; i++) - col_j[i] *= c; + for (j = 0; j < n; j++) + { + col_j = a[j] + smu - mu; + for (i = 0; i < colSize; i++) { col_j[i] *= c; } } } -void bandAddIdentity(realtype **a, sunindextype n, sunindextype smu) +void SUNDlsMat_bandAddIdentity(sunrealtype** a, sunindextype n, sunindextype smu) { sunindextype j; - - for(j=0; j < n; j++) - a[j][smu] += ONE; + + for (j = 0; j < n; j++) { a[j][smu] += ONE; } } -void bandMatvec(realtype **a, realtype *x, realtype *y, sunindextype n, - sunindextype mu, sunindextype ml, sunindextype smu) +void SUNDlsMat_bandMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, + sunindextype n, sunindextype mu, sunindextype ml, + sunindextype smu) { sunindextype i, j, is, ie; - realtype *col_j; + sunrealtype* col_j; - for (i=0; i j-mu) ? 0 : j-mu; - ie = (n-1 < j+ml) ? n-1 : j+ml; - for (i=is; i<=ie; i++) - y[i] += col_j[i-j+mu]*x[j]; + for (j = 0; j < n; j++) + { + col_j = a[j] + smu - mu; + is = (0 > j - mu) ? 0 : j - mu; + ie = (n - 1 < j + ml) ? n - 1 : j + ml; + for (i = is; i <= ie; i++) { y[i] += col_j[i - j + mu] * x[j]; } } } - diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_context.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_context.c new file mode 100644 index 000000000..86b0a49c3 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_context.c @@ -0,0 +1,299 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS context class. A context object holds data that all + * SUNDIALS objects in a simulation share. + * ----------------------------------------------------------------*/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "sundials_adiak_metadata.h" +#include "sundials_macros.h" + +SUNErrCode SUNContext_Create(SUNComm comm, SUNContext* sunctx_out) +{ + SUNErrCode err = SUN_SUCCESS; + SUNProfiler profiler = NULL; + SUNLogger logger = NULL; + SUNContext sunctx = NULL; + SUNErrHandler eh = NULL; + + *sunctx_out = NULL; + sunctx = (SUNContext)malloc(sizeof(struct SUNContext_)); + + /* SUNContext_Create cannot assert or log since the SUNContext is not yet + * created */ + if (!sunctx) { return SUN_ERR_MALLOC_FAIL; } + + SUNFunctionBegin(sunctx); + +#ifdef SUNDIALS_ADIAK_ENABLED + adiak_init(&comm); + sunAdiakCollectMetadata(); +#endif + + do { +#if SUNDIALS_LOGGING_LEVEL > 0 +#if SUNDIALS_MPI_ENABLED + err = SUNLogger_CreateFromEnv(comm, &logger); + SUNCheckCallNoRet(err); + if (err) { break; } +#else + err = SUNLogger_CreateFromEnv(SUN_COMM_NULL, &logger); + SUNCheckCallNoRet(err); + if (err) { break; } +#endif +#else + err = SUNLogger_Create(SUN_COMM_NULL, 0, &logger); + SUNCheckCallNoRet(err); + if (err) { break; } + err = SUNLogger_SetErrorFilename(logger, ""); + SUNCheckCallNoRet(err); + if (err) { break; } + err = SUNLogger_SetWarningFilename(logger, ""); + SUNCheckCallNoRet(err); + if (err) { break; } + err = SUNLogger_SetInfoFilename(logger, ""); + SUNCheckCallNoRet(err); + if (err) { break; } + err = SUNLogger_SetDebugFilename(logger, ""); + SUNCheckCallNoRet(err); + if (err) { break; } +#endif + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + err = SUNProfiler_Create(comm, "SUNContext Default", &profiler); + SUNCheckCallNoRet(err); + if (err) { break; } +#endif + + err = SUNErrHandler_Create(SUNLogErrHandlerFn, NULL, &eh); + SUNCheckCallNoRet(err); + if (err) { break; } + + sunctx->logger = logger; + sunctx->own_logger = logger != NULL; + sunctx->profiler = profiler; + sunctx->own_profiler = profiler != NULL; + sunctx->last_err = SUN_SUCCESS; + sunctx->err_handler = eh; + sunctx->comm = comm; + } + while (0); + + if (err) + { +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + SUNCheckCallNoRet(SUNProfiler_Free(&profiler)); +#endif + SUNCheckCallNoRet(SUNLogger_Destroy(&logger)); + free(sunctx); + } + else { *sunctx_out = sunctx; } + + return err; +} + +SUNErrCode SUNContext_GetLastError(SUNContext sunctx) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + SUNErrCode err = sunctx->last_err; + sunctx->last_err = SUN_SUCCESS; + return err; +} + +SUNErrCode SUNContext_PeekLastError(SUNContext sunctx) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + return sunctx->last_err; +} + +SUNErrCode SUNContext_PushErrHandler(SUNContext sunctx, SUNErrHandlerFn err_fn, + void* err_user_data) +{ + if (!sunctx || !err_fn) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + SUNErrHandler new_err_handler = NULL; + if (SUNErrHandler_Create(err_fn, err_user_data, &new_err_handler)) + { + return SUN_ERR_CORRUPT; + } + new_err_handler->previous = sunctx->err_handler; + sunctx->err_handler = new_err_handler; + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_PopErrHandler(SUNContext sunctx) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + if (sunctx->err_handler) + { + SUNErrHandler eh = sunctx->err_handler; + if (sunctx->err_handler->previous) + { + sunctx->err_handler = sunctx->err_handler->previous; + } + else { sunctx->err_handler = NULL; } + SUNErrHandler_Destroy(&eh); + } + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_ClearErrHandlers(SUNContext sunctx) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + while (sunctx->err_handler != NULL) + { + SUNCheckCall(SUNContext_PopErrHandler(sunctx)); + } + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_GetProfiler(SUNContext sunctx, SUNProfiler* profiler) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + +#ifdef SUNDIALS_BUILD_WITH_PROFILING + /* get profiler */ + *profiler = sunctx->profiler; +#else + *profiler = NULL; +#endif + + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_SetProfiler(SUNContext sunctx, SUNProfiler profiler) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + +#ifdef SUNDIALS_BUILD_WITH_PROFILING + /* free any existing profiler */ + if (sunctx->profiler && sunctx->own_profiler) + { + SUNCheckCall(SUNProfiler_Free(&(sunctx->profiler))); + sunctx->profiler = NULL; + } + + /* set profiler */ + sunctx->profiler = profiler; + sunctx->own_profiler = SUNFALSE; +#else + /* silence warnings when profiling is disabled */ + ((void)profiler); +#endif + + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_GetLogger(SUNContext sunctx, SUNLogger* logger) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + + /* get logger */ + *logger = sunctx->logger; + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_SetLogger(SUNContext sunctx, SUNLogger logger) +{ + if (!sunctx) { return SUN_ERR_SUNCTX_CORRUPT; } + + SUNFunctionBegin(sunctx); + + /* free any existing logger */ + if (sunctx->logger && sunctx->own_logger) + { + if (SUNLogger_Destroy(&(sunctx->logger))) { return SUN_ERR_DESTROY_FAIL; } + sunctx->logger = NULL; + } + + /* set logger */ + sunctx->logger = logger; + sunctx->own_logger = SUNFALSE; + + return SUN_SUCCESS; +} + +SUNErrCode SUNContext_Free(SUNContext* sunctx) +{ +#ifdef SUNDIALS_ADIAK_ENABLED + adiak_fini(); +#endif + + if (!sunctx || !(*sunctx)) { return SUN_SUCCESS; } + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + /* Find out where we are printing to */ + FILE* fp = NULL; + char* sunprofiler_print_env = getenv("SUNPROFILER_PRINT"); + fp = NULL; + if (sunprofiler_print_env) + { + if (!strcmp(sunprofiler_print_env, "0")) { fp = NULL; } + else if (!strcmp(sunprofiler_print_env, "1") || + !strcmp(sunprofiler_print_env, "TRUE") || + !strcmp(sunprofiler_print_env, "stdout")) + { + fp = stdout; + } + else { fp = fopen(sunprofiler_print_env, "a"); } + } + + /* Enforce that the profiler is freed before finalizing, + if it is not owned by the sunctx. */ + if ((*sunctx)->profiler) + { + if (fp) { SUNProfiler_Print((*sunctx)->profiler, fp); } + if (fp) { fclose(fp); } + if ((*sunctx)->own_profiler) { SUNProfiler_Free(&(*sunctx)->profiler); } + } +#endif + + if ((*sunctx)->logger && (*sunctx)->own_logger) + { + SUNLogger_Destroy(&(*sunctx)->logger); + } + + SUNContext_ClearErrHandlers(*sunctx); + + free(*sunctx); + *sunctx = NULL; + + return SUN_SUCCESS; +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_debug.h b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_debug.h index 1a380243a..18d3143c3 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_debug.h +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_debug.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,7 +20,7 @@ #include -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif @@ -37,14 +37,14 @@ extern "C" { * Macro which prints error messages in debug mode */ #ifdef SUNDIALS_DEBUG -#define SUNDIALS_DEBUG_ERROR(msg) \ - fprintf(stderr, "ERROR in %s (%s line %d): %s", \ - __func__, __FILE__, __LINE__, msg); +#define SUNDIALS_DEBUG_ERROR(msg) \ + fprintf(stderr, "ERROR in %s (%s line %d): %s", __func__, __FILE__, \ + __LINE__, msg); #else #define SUNDIALS_DEBUG_ERROR(msg) #endif -#ifdef __cplusplus /* wrapper to enable C++ usage */ +#ifdef __cplusplus /* wrapper to enable C++ usage */ } #endif diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_dense.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_dense.c index 108c670ce..ce420fca0 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_dense.c +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_dense.c @@ -1,13 +1,10 @@ /* - * ----------------------------------------------------------------- - * $Revision$ - * $Date$ * ----------------------------------------------------------------- * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,93 +16,98 @@ * This is the implementation file for a generic package of dense * matrix operations. * ----------------------------------------------------------------- - */ + */ #include #include - #include #include -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) +#define TWO SUN_RCONST(2.0) /* * ----------------------------------------------------- - * Functions working on DlsMat + * Functions working on SUNDlsMat * ----------------------------------------------------- */ -sunindextype DenseGETRF(DlsMat A, sunindextype *p) +sunindextype SUNDlsMat_DenseGETRF(SUNDlsMat A, sunindextype* p) { - return(denseGETRF(A->cols, A->M, A->N, p)); + return (SUNDlsMat_denseGETRF(A->cols, A->M, A->N, p)); } -void DenseGETRS(DlsMat A, sunindextype *p, realtype *b) +void SUNDlsMat_DenseGETRS(SUNDlsMat A, sunindextype* p, sunrealtype* b) { - denseGETRS(A->cols, A->N, p, b); + SUNDlsMat_denseGETRS(A->cols, A->N, p, b); } -sunindextype DensePOTRF(DlsMat A) +sunindextype SUNDlsMat_DensePOTRF(SUNDlsMat A) { - return(densePOTRF(A->cols, A->M)); + return (SUNDlsMat_densePOTRF(A->cols, A->M)); } -void DensePOTRS(DlsMat A, realtype *b) +void SUNDlsMat_DensePOTRS(SUNDlsMat A, sunrealtype* b) { - densePOTRS(A->cols, A->M, b); + SUNDlsMat_densePOTRS(A->cols, A->M, b); } -int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk) +int SUNDlsMat_DenseGEQRF(SUNDlsMat A, sunrealtype* beta, sunrealtype* wrk) { - return(denseGEQRF(A->cols, A->M, A->N, beta, wrk)); + return (SUNDlsMat_denseGEQRF(A->cols, A->M, A->N, beta, wrk)); } -int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, realtype *vm, realtype *wrk) +int SUNDlsMat_DenseORMQR(SUNDlsMat A, sunrealtype* beta, sunrealtype* vn, + sunrealtype* vm, sunrealtype* wrk) { - return(denseORMQR(A->cols, A->M, A->N, beta, vn, vm, wrk)); + return (SUNDlsMat_denseORMQR(A->cols, A->M, A->N, beta, vn, vm, wrk)); } -void DenseCopy(DlsMat A, DlsMat B) +void SUNDlsMat_DenseCopy(SUNDlsMat A, SUNDlsMat B) { - denseCopy(A->cols, B->cols, A->M, A->N); + SUNDlsMat_denseCopy(A->cols, B->cols, A->M, A->N); } -void DenseScale(realtype c, DlsMat A) +void SUNDlsMat_DenseScale(sunrealtype c, SUNDlsMat A) { - denseScale(c, A->cols, A->M, A->N); + SUNDlsMat_denseScale(c, A->cols, A->M, A->N); } -void DenseMatvec(DlsMat A, realtype *x, realtype *y) +void SUNDlsMat_DenseMatvec(SUNDlsMat A, sunrealtype* x, sunrealtype* y) { - denseMatvec(A->cols, x, y, A->M, A->N); + SUNDlsMat_denseMatvec(A->cols, x, y, A->M, A->N); } -sunindextype denseGETRF(realtype **a, sunindextype m, sunindextype n, sunindextype *p) +sunindextype SUNDlsMat_denseGETRF(sunrealtype** a, sunindextype m, + sunindextype n, sunindextype* p) { sunindextype i, j, k, l; - realtype *col_j, *col_k; - realtype temp, mult, a_kj; + sunrealtype *col_j, *col_k; + sunrealtype temp, mult, a_kj; /* k-th elimination step number */ - for (k=0; k < n; k++) { - - col_k = a[k]; + for (k = 0; k < n; k++) + { + col_k = a[k]; /* find l = pivot row number */ - l=k; - for (i=k+1; i < m; i++) - if (SUNRabs(col_k[i]) > SUNRabs(col_k[l])) l=i; + l = k; + for (i = k + 1; i < m; i++) + { + if (SUNRabs(col_k[i]) > SUNRabs(col_k[l])) { l = i; } + } p[k] = l; /* check for zero pivot element */ - if (col_k[l] == ZERO) return(k+1); - - /* swap a(k,1:n) and a(l,1:n) if necessary */ - if ( l!= k ) { - for (i=0; i 0; k--) { + for (k = n - 1; k > 0; k--) + { col_k = a[k]; b[k] /= col_k[k]; - for (i=0; i0) { - for(i=j; i 0) + { + for (i = j; i < m; i++) + { + for (k = 0; k < j; k++) + { a_col_k = a[k]; - a_col_j[i] -= a_col_k[i]*a_col_k[j]; + a_col_j[i] -= a_col_k[i] * a_col_k[j]; } } } a_diag = a_col_j[j]; - if (a_diag <= ZERO) return(j+1); + if (a_diag <= ZERO) { return (j + 1); } a_diag = SUNRsqrt(a_diag); - for(i=j; i=0; i--) { + col_j = a[m - 1]; + b[m - 1] /= col_j[m - 1]; + for (i = m - 2; i >= 0; i--) + { col_i = a[i]; - for (j=i+1; j= n) * using Householder reflections. * - * On exit, the elements on and above the diagonal of A contain the n by n - * upper triangular matrix R; the elements below the diagonal, with the array beta, + * On exit, the elements on and above the diagonal of A contain the n by n + * upper triangular matrix R; the elements below the diagonal, with the array beta, * represent the orthogonal matrix Q as a product of elementary reflectors . * * v (of length m) must be provided as workspace. * */ -int denseGEQRF(realtype **a, sunindextype m, sunindextype n, realtype *beta, realtype *v) +int SUNDlsMat_denseGEQRF(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* v) { - realtype ajj, s, mu, v1, v1_2; - realtype *col_j, *col_k; + sunrealtype ajj, s, mu, v1, v1_2; + sunrealtype *col_j, *col_k; sunindextype i, j, k; /* For each column...*/ - for(j=0; j= n. * * v (of length m) must be provided as workspace. */ -int denseORMQR(realtype **a, sunindextype m, sunindextype n, realtype *beta, - realtype *vn, realtype *vm, realtype *v) + +int SUNDlsMat_denseORMQR(sunrealtype** a, sunindextype m, sunindextype n, + sunrealtype* beta, sunrealtype* vn, sunrealtype* vm, + sunrealtype* v) { - realtype *col_j, s; + sunrealtype *col_j, s; sunindextype i, j; /* Initialize vm */ - for(i=0; i=0; j--) { - + for (j = n - 1; j >= 0; j--) + { col_j = a[j]; v[0] = ONE; - s = vm[j]; - for(i=1; i #include - #include #include -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) -DlsMat NewDenseMat(sunindextype M, sunindextype N) +SUNDlsMat SUNDlsMat_NewDenseMat(sunindextype M, sunindextype N) { - DlsMat A; + SUNDlsMat A; sunindextype j; - if ( (M <= 0) || (N <= 0) ) return(NULL); + if ((M <= 0) || (N <= 0)) { return (NULL); } A = NULL; - A = (DlsMat) malloc(sizeof *A); - if (A==NULL) return (NULL); - - A->data = (realtype *) malloc(M * N * sizeof(realtype)); - if (A->data == NULL) { - free(A); A = NULL; - return(NULL); + A = (SUNDlsMat)malloc(sizeof *A); + if (A == NULL) { return (NULL); } + + A->data = (sunrealtype*)malloc(M * N * sizeof(sunrealtype)); + if (A->data == NULL) + { + free(A); + A = NULL; + return (NULL); } - A->cols = (realtype **) malloc(N * sizeof(realtype *)); - if (A->cols == NULL) { - free(A->data); A->data = NULL; - free(A); A = NULL; - return(NULL); + A->cols = (sunrealtype**)malloc(N * sizeof(sunrealtype*)); + if (A->cols == NULL) + { + free(A->data); + A->data = NULL; + free(A); + A = NULL; + return (NULL); } - for (j=0; j < N; j++) A->cols[j] = A->data + j * M; + for (j = 0; j < N; j++) { A->cols[j] = A->data + j * M; } - A->M = M; - A->N = N; - A->ldim = M; - A->ldata = M*N; + A->M = M; + A->N = N; + A->ldim = M; + A->ldata = M * N; A->type = SUNDIALS_DENSE; - return(A); + return (A); } -realtype **newDenseMat(sunindextype m, sunindextype n) +sunrealtype** SUNDlsMat_newDenseMat(sunindextype m, sunindextype n) { sunindextype j; - realtype **a; + sunrealtype** a; - if ( (n <= 0) || (m <= 0) ) return(NULL); + if ((n <= 0) || (m <= 0)) { return (NULL); } a = NULL; - a = (realtype **) malloc(n * sizeof(realtype *)); - if (a == NULL) return(NULL); + a = (sunrealtype**)malloc(n * sizeof(sunrealtype*)); + if (a == NULL) { return (NULL); } a[0] = NULL; - a[0] = (realtype *) malloc(m * n * sizeof(realtype)); - if (a[0] == NULL) { - free(a); a = NULL; - return(NULL); + a[0] = (sunrealtype*)malloc(m * n * sizeof(sunrealtype)); + if (a[0] == NULL) + { + free(a); + a = NULL; + return (NULL); } - for (j=1; j < n; j++) a[j] = a[0] + j * m; + for (j = 1; j < n; j++) { a[j] = a[0] + j * m; } - return(a); + return (a); } - -DlsMat NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, sunindextype smu) +SUNDlsMat SUNDlsMat_NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, + sunindextype smu) { - DlsMat A; + SUNDlsMat A; sunindextype j, colSize; - if (N <= 0) return(NULL); - + if (N <= 0) { return (NULL); } + A = NULL; - A = (DlsMat) malloc(sizeof *A); - if (A == NULL) return (NULL); + A = (SUNDlsMat)malloc(sizeof *A); + if (A == NULL) { return (NULL); } colSize = smu + ml + 1; A->data = NULL; - A->data = (realtype *) malloc(N * colSize * sizeof(realtype)); - if (A->data == NULL) { - free(A); A = NULL; - return(NULL); + A->data = (sunrealtype*)malloc(N * colSize * sizeof(sunrealtype)); + if (A->data == NULL) + { + free(A); + A = NULL; + return (NULL); } A->cols = NULL; - A->cols = (realtype **) malloc(N * sizeof(realtype *)); - if (A->cols == NULL) { + A->cols = (sunrealtype**)malloc(N * sizeof(sunrealtype*)); + if (A->cols == NULL) + { free(A->data); - free(A); A = NULL; - return(NULL); + free(A); + A = NULL; + return (NULL); } - for (j=0; j < N; j++) A->cols[j] = A->data + j * colSize; + for (j = 0; j < N; j++) { A->cols[j] = A->data + j * colSize; } - A->M = N; - A->N = N; - A->mu = mu; - A->ml = ml; - A->s_mu = smu; - A->ldim = colSize; + A->M = N; + A->N = N; + A->mu = mu; + A->ml = ml; + A->s_mu = smu; + A->ldim = colSize; A->ldata = N * colSize; A->type = SUNDIALS_BAND; - return(A); + return (A); } -realtype **newBandMat(sunindextype n, sunindextype smu, sunindextype ml) +sunrealtype** SUNDlsMat_newBandMat(sunindextype n, sunindextype smu, + sunindextype ml) { - realtype **a; + sunrealtype** a; sunindextype j, colSize; - if (n <= 0) return(NULL); + if (n <= 0) { return (NULL); } a = NULL; - a = (realtype **) malloc(n * sizeof(realtype *)); - if (a == NULL) return(NULL); + a = (sunrealtype**)malloc(n * sizeof(sunrealtype*)); + if (a == NULL) { return (NULL); } colSize = smu + ml + 1; - a[0] = NULL; - a[0] = (realtype *) malloc(n * colSize * sizeof(realtype)); - if (a[0] == NULL) { - free(a); a = NULL; - return(NULL); + a[0] = NULL; + a[0] = (sunrealtype*)malloc(n * colSize * sizeof(sunrealtype)); + if (a[0] == NULL) + { + free(a); + a = NULL; + return (NULL); } - for (j=1; j < n; j++) a[j] = a[0] + j * colSize; + for (j = 1; j < n; j++) { a[j] = a[0] + j * colSize; } - return(a); + return (a); } -void DestroyMat(DlsMat A) +void SUNDlsMat_DestroyMat(SUNDlsMat A) { - free(A->data); A->data = NULL; + free(A->data); + A->data = NULL; free(A->cols); - free(A); A = NULL; + free(A); + A = NULL; } -void destroyMat(realtype **a) +void SUNDlsMat_destroyMat(sunrealtype** a) { - free(a[0]); a[0] = NULL; - free(a); a = NULL; + free(a[0]); + a[0] = NULL; + free(a); + a = NULL; } -int *NewIntArray(int N) +int* SUNDlsMat_NewIntArray(int N) { - int *vec; + int* vec; - if (N <= 0) return(NULL); + if (N <= 0) { return (NULL); } vec = NULL; - vec = (int *) malloc(N * sizeof(int)); + vec = (int*)malloc(N * sizeof(int)); - return(vec); + return (vec); } -int *newIntArray(int n) +int* SUNDlsMat_newIntArray(int n) { - int *v; + int* v; - if (n <= 0) return(NULL); + if (n <= 0) { return (NULL); } v = NULL; - v = (int *) malloc(n * sizeof(int)); + v = (int*)malloc(n * sizeof(int)); - return(v); + return (v); } -sunindextype *NewIndexArray(sunindextype N) +sunindextype* SUNDlsMat_NewIndexArray(sunindextype N) { - sunindextype *vec; + sunindextype* vec; - if (N <= 0) return(NULL); + if (N <= 0) { return (NULL); } vec = NULL; - vec = (sunindextype *) malloc(N * sizeof(sunindextype)); + vec = (sunindextype*)malloc(N * sizeof(sunindextype)); - return(vec); + return (vec); } -sunindextype *newIndexArray(sunindextype n) +sunindextype* SUNDlsMat_newIndexArray(sunindextype n) { - sunindextype *v; + sunindextype* v; - if (n <= 0) return(NULL); + if (n <= 0) { return (NULL); } v = NULL; - v = (sunindextype *) malloc(n * sizeof(sunindextype)); + v = (sunindextype*)malloc(n * sizeof(sunindextype)); - return(v); + return (v); } -realtype *NewRealArray(sunindextype N) +sunrealtype* SUNDlsMat_NewRealArray(sunindextype N) { - realtype *vec; + sunrealtype* vec; - if (N <= 0) return(NULL); + if (N <= 0) { return (NULL); } vec = NULL; - vec = (realtype *) malloc(N * sizeof(realtype)); + vec = (sunrealtype*)malloc(N * sizeof(sunrealtype)); - return(vec); + return (vec); } -realtype *newRealArray(sunindextype m) +sunrealtype* SUNDlsMat_newRealArray(sunindextype m) { - realtype *v; + sunrealtype* v; - if (m <= 0) return(NULL); + if (m <= 0) { return (NULL); } v = NULL; - v = (realtype *) malloc(m * sizeof(realtype)); + v = (sunrealtype*)malloc(m * sizeof(sunrealtype)); - return(v); + return (v); } -void DestroyArray(void *V) -{ - free(V); +void SUNDlsMat_DestroyArray(void* V) +{ + free(V); V = NULL; } -void destroyArray(void *v) +void SUNDlsMat_destroyArray(void* v) { - free(v); + free(v); v = NULL; } - -void AddIdentity(DlsMat A) +void SUNDlsMat_AddIdentity(SUNDlsMat A) { sunindextype i; - switch (A->type) { - + switch (A->type) + { case SUNDIALS_DENSE: - for (i=0; iN; i++) A->cols[i][i] += ONE; + for (i = 0; i < A->N; i++) { A->cols[i][i] += ONE; } break; case SUNDIALS_BAND: - for (i=0; iM; i++) A->cols[i][A->s_mu] += ONE; + for (i = 0; i < A->M; i++) { A->cols[i][A->s_mu] += ONE; } break; - } - } - -void SetToZero(DlsMat A) +void SUNDlsMat_SetToZero(SUNDlsMat A) { sunindextype i, j, colSize; - realtype *col_j; - - switch (A->type) { + sunrealtype* col_j; + switch (A->type) + { case SUNDIALS_DENSE: - - for (j=0; jN; j++) { + + for (j = 0; j < A->N; j++) + { col_j = A->cols[j]; - for (i=0; iM; i++) - col_j[i] = ZERO; + for (i = 0; i < A->M; i++) { col_j[i] = ZERO; } } break; @@ -286,70 +299,67 @@ void SetToZero(DlsMat A) case SUNDIALS_BAND: colSize = A->mu + A->ml + 1; - for (j=0; jM; j++) { + for (j = 0; j < A->M; j++) + { col_j = A->cols[j] + A->s_mu - A->mu; - for (i=0; itype) { + sunrealtype** a; + switch (A->type) + { case SUNDIALS_DENSE: fprintf(outfile, "\n"); - for (i=0; i < A->M; i++) { - for (j=0; j < A->N; j++) { + for (i = 0; i < A->M; i++) + { + for (j = 0; j < A->N; j++) + { #if defined(SUNDIALS_EXTENDED_PRECISION) - fprintf(outfile, "%12Lg ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12Lg ", SUNDLS_DENSE_ELEM(A, i, j)); #elif defined(SUNDIALS_DOUBLE_PRECISION) - fprintf(outfile, "%12g ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12g ", SUNDLS_DENSE_ELEM(A, i, j)); #else - fprintf(outfile, "%12g ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12g ", SUNDLS_DENSE_ELEM(A, i, j)); #endif } fprintf(outfile, "\n"); } fprintf(outfile, "\n"); - + break; case SUNDIALS_BAND: a = A->cols; fprintf(outfile, "\n"); - for (i=0; i < A->N; i++) { - start = SUNMAX(0,i-A->ml); - finish = SUNMIN(A->N-1,i+A->mu); - for (j=0; j < start; j++) fprintf(outfile, "%12s ",""); - for (j=start; j <= finish; j++) { + for (i = 0; i < A->N; i++) + { + start = SUNMAX(0, i - A->ml); + finish = SUNMIN(A->N - 1, i + A->mu); + for (j = 0; j < start; j++) { fprintf(outfile, "%12s ", ""); } + for (j = start; j <= finish; j++) + { #if defined(SUNDIALS_EXTENDED_PRECISION) - fprintf(outfile, "%12Lg ", a[j][i-j+A->s_mu]); + fprintf(outfile, "%12Lg ", a[j][i - j + A->s_mu]); #elif defined(SUNDIALS_DOUBLE_PRECISION) - fprintf(outfile, "%12g ", a[j][i-j+A->s_mu]); + fprintf(outfile, "%12g ", a[j][i - j + A->s_mu]); #else - fprintf(outfile, "%12g ", a[j][i-j+A->s_mu]); + fprintf(outfile, "%12g ", a[j][i - j + A->s_mu]); #endif } fprintf(outfile, "\n"); } fprintf(outfile, "\n"); - - break; + break; } - } - - diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_errors.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_errors.c new file mode 100644 index 000000000..acc3a0e5b --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_errors.c @@ -0,0 +1,116 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "sundials_logger_impl.h" +#include "sundials_macros.h" +#include "sundials_utils.h" + +SUNErrCode SUNErrHandler_Create(SUNErrHandlerFn eh_fn, void* eh_data, + SUNErrHandler* eh_out) +{ + SUNErrHandler eh = NULL; + + eh = (SUNErrHandler)malloc(sizeof(struct SUNErrHandler_)); + if (!eh) { return SUN_ERR_MALLOC_FAIL; } + + eh->previous = NULL; + eh->call = eh_fn; + eh->data = eh_data; + + *eh_out = eh; + return SUN_SUCCESS; +} + +void SUNErrHandler_Destroy(SUNErrHandler* eh) +{ + if (!eh || !(*eh)) { return; } + free(*eh); + *eh = NULL; +} + +const char* SUNGetErrMsg(SUNErrCode code) +{ +#define SUN_EXPAND_TO_CASES(name, description) \ + case name: return description; break; + + switch (code) + { + SUN_ERR_CODE_LIST(SUN_EXPAND_TO_CASES) + default: return "unknown error"; + } + + return NULL; +} + +void SUNLogErrHandlerFn(int line, const char* func, const char* file, + const char* msg, SUNErrCode err_code, + SUNDIALS_MAYBE_UNUSED void* err_user_data, + SUNContext sunctx) +{ + char* file_and_line = sunCombineFileAndLine(line, file); + if (msg == NULL) { msg = SUNGetErrMsg(err_code); } + SUNLogger_QueueMsg(sunctx->logger, SUN_LOGLEVEL_ERROR, file_and_line, func, + msg); + free(file_and_line); +} + +void SUNAbortErrHandlerFn(int line, const char* func, const char* file, + SUNDIALS_MAYBE_UNUSED const char* msg, + SUNDIALS_MAYBE_UNUSED SUNErrCode err_code, + SUNDIALS_MAYBE_UNUSED void* err_user_data, + SUNContext sunctx) +{ + char* file_and_line = sunCombineFileAndLine(line, file); + SUNLogger_QueueMsg(sunctx->logger, SUN_LOGLEVEL_ERROR, file_and_line, func, + "SUNAbortErrHandler: Calling abort now, use a different " + "error handler to avoid program termination.\n"); + free(file_and_line); + abort(); +} + +void SUNGlobalFallbackErrHandler(int line, const char* func, const char* file, + const char* msgfmt, SUNErrCode err_code, ...) +{ + va_list ap; + char* log_msg = NULL; + char* file_and_line = NULL; + + va_start(ap, err_code); + + file_and_line = sunCombineFileAndLine(__LINE__, __FILE__); + sunCreateLogMessage(SUN_LOGLEVEL_ERROR, 0, file_and_line, + __func__, "The SUNDIALS SUNContext was corrupt or NULL when an error occurred. As such, error messages have been printed to stderr.", + ap, &log_msg); + fprintf(stderr, "%s", log_msg); + free(log_msg); + free(file_and_line); + + file_and_line = sunCombineFileAndLine(line, file); + if (msgfmt == NULL) { msgfmt = SUNGetErrMsg(err_code); } + sunCreateLogMessage(SUN_LOGLEVEL_ERROR, 0, file_and_line, func, msgfmt, ap, + &log_msg); + fprintf(stderr, "%s", log_msg); + free(log_msg); + free(file_and_line); + + va_end(ap); +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_futils.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_futils.c index 102831a31..3a0d0f27d 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_futils.c +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_futils.c @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,16 +14,35 @@ * SUNDIALS Fortran 2003 interface utility implementations. * -----------------------------------------------------------------*/ +#include +#include +#include #include /* Create a file pointer with the given file name and mode. */ -FILE* SUNDIALSFileOpen(const char* filename, const char* mode) +SUNErrCode SUNDIALSFileOpen(const char* filename, const char* mode, FILE** fp_out) { - return fopen(filename, mode); + SUNErrCode err = SUN_SUCCESS; + FILE* fp = *fp_out; + + if (filename) + { + if (!strcmp(filename, "stdout")) { fp = stdout; } + else if (!strcmp(filename, "stderr")) { fp = stderr; } + else { fp = fopen(filename, mode); } + } + + if (!fp) { err = SUN_ERR_FILE_OPEN; } + + *fp_out = fp; + return err; } /* Close a file pointer with the given file name. */ -void SUNDIALSFileClose(FILE* fp) +SUNErrCode SUNDIALSFileClose(FILE** fp_ptr) { - fclose(fp); + if (!fp_ptr) { return SUN_SUCCESS; } + FILE* fp = *fp_ptr; + if (fp && (fp != stdout) && (fp != stderr)) { fclose(fp); } + return SUN_SUCCESS; } diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap.c new file mode 100644 index 000000000..acf1c12c8 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap.c @@ -0,0 +1,342 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * A simple hashmap implementation for char* keys and + * void* values. Uses linear probing to resolve collisions. + * The values can be anything, but will be freed by + * the hash map upon its destruction. + * -----------------------------------------------------------------*/ + +#include +#include +#include + +#include +#include + +#include "sundials_hashmap_impl.h" +#include "sundials_macros.h" + +static const uint64_t HASH_PRIME = 14695981039346656037U; +static const uint64_t HASH_OFFSET_BASIS = 1099511628211U; + +/* + For a nice discussion on popular hashing algorithms see: + https://softwareengineering.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed/145633#145633 + + This is a 64-bit implementation of the 'a' modification of the + Fowler-Noll-Vo hash (i.e., FNV1-a). + */ +static uint64_t fnv1a_hash(const char* str) +{ + uint64_t hash = HASH_OFFSET_BASIS; + char c; + while ((c = *str++)) { hash = (hash ^ c) * HASH_PRIME; } + return hash; +} + +/* + This function creates a new SUNHashMap object allocated to hold + up to 'max_size' entries. + + **Arguments:** + * ``max_size`` -- the max number of entries in the hashmap + * ``map`` -- on input, a SUNHasMap pointer, on output the SUNHashMap will be + allocated + + **Returns:** + * A SUNErrCode indicating success or a failure + */ +SUNErrCode SUNHashMap_New(int max_size, SUNHashMap* map) +{ + int i; + + if (max_size <= 0) { return SUN_ERR_ARG_OUTOFRANGE; } + + *map = NULL; + *map = (SUNHashMap)malloc(sizeof(**map)); + + if (!map) { return SUN_ERR_MALLOC_FAIL; } + + (*map)->size = 0; + (*map)->max_size = max_size; + + (*map)->buckets = NULL; + (*map)->buckets = + (SUNHashMapKeyValue*)malloc(max_size * sizeof(*((*map)->buckets))); + + if (!(*map)->buckets) + { + free(*map); + return SUN_ERR_MALLOC_FAIL; + } + + /* Initialize all buckets to NULL */ + for (i = 0; i < max_size; i++) { (*map)->buckets[i] = NULL; } + + return SUN_SUCCESS; +} + +/* + This function frees the SUNHashMap object. + + **Arguments:** + * ``map`` -- on input, a SUNHasMap pointer, on output the SUNHashMap will be + deallocated and set to ``NULL`` + * ``freevalue`` -- callback function that should free the value object + + **Returns:** + * A SUNErrCode indicating success or a failure + */ +SUNErrCode SUNHashMap_Destroy(SUNHashMap* map, void (*freevalue)(void* ptr)) +{ + int i; + + if (map == NULL || freevalue == NULL) { return SUN_SUCCESS; } + + for (i = 0; i < (*map)->max_size; i++) + { + if ((*map)->buckets[i] && (*map)->buckets[i]->value) + { + freevalue((*map)->buckets[i]->value); + } + + if ((*map)->buckets[i]) { free((*map)->buckets[i]); } + } + if ((*map)->buckets) { free((*map)->buckets); } + if (*map) { free(*map); } + *map = NULL; + + return SUN_SUCCESS; +} + +/* + This function iterates the map over the range [start, N]. N is either the + index at which ``yieldfn`` indicates the iteration should stop, or the max + entries in the map. + + **Arguments:** + * ``map`` -- the ``SUNHashMap`` object to operate on + * ``start`` -- the start of the iteration range + * ``yieldfn`` -- the callback function to call every iteration + this should return -1 to continue the iteration, or >= 0 to + stop; the first argument is the current index, the second + argument is the current key-value pair, and the final + argument is the same pointer ``ctx`` as the final argument + to SUNHashMapIterate. + * ``ctx`` -- a pointer to pass on to ``yieldfn`` + + **Returns:** + * ``max_size`` -- iterated the whole map + * ``>=0`` -- the index at which the iteration stopped + * ``<-1`` -- an error occurred + */ +int SUNHashMap_Iterate(SUNHashMap map, int start, + int (*yieldfn)(int, SUNHashMapKeyValue, const void*), + const void* ctx) +{ + int i; + + if (map == NULL || yieldfn == NULL) { return (-2); } + + for (i = start; i < map->max_size; i++) + { + int retval = yieldfn(i, map->buckets[i], ctx); + if (retval >= 0) + { + return (retval); /* yieldfn indicates the loop should break */ + } + if (retval < -1) { return (retval); /* error occurred */ } + } + + return (map->max_size); +} + +static int sunHashMapLinearProbeInsert(int idx, SUNHashMapKeyValue kv, + SUNDIALS_MAYBE_UNUSED const void* ctx) +{ + /* find the next open spot */ + if (kv == NULL) { return (idx); /* open spot found at idx */ } + return (-1); /* keep looking */ +} + +/* + This function creates a key-value pair and attempts to insert it into the map. + Will use linear probing if there is a collision. + + **Arguments:** + * ``map`` -- the ``SUNHashMap`` object to operate on + * ``key`` -- the key to store + * ``value`` -- the value associated with the key + + **Returns:** + * ``0`` -- success + * ``-1`` -- an error occurred + * ``-2`` -- the map is full + */ +int SUNHashMap_Insert(SUNHashMap map, const char* key, void* value) +{ + int idx; + int retval; + SUNHashMapKeyValue kvp; + + if (map == NULL || key == NULL || value == NULL) { return (-1); } + + /* We want the index to be in (0, map->max_size) */ + idx = (int)(fnv1a_hash(key) % map->max_size); + + /* Check if the bucket is already filled */ + if (map->buckets[idx] != NULL) + { + /* Find the next open spot */ + retval = SUNHashMap_Iterate(map, idx, sunHashMapLinearProbeInsert, NULL); + if (retval < 0) { return (-1); /* error occurred */ } + if (retval == map->max_size) { return (-2); /* no open entry */ } + + idx = retval; + } + + /* Create the key-value pair */ + kvp = (SUNHashMapKeyValue)malloc(sizeof(*kvp)); + if (kvp == NULL) { return (-1); } + + kvp->key = key; + kvp->value = value; + + /* Insert the key-value pair */ + map->buckets[idx] = kvp; + map->size++; + + return (0); +} + +static int sunHashMapLinearProbeGet(int idx, SUNHashMapKeyValue kv, + const void* key) +{ + /* target key cannot be NULL */ + if (key == NULL) { return (-2); } + + /* find the matching entry */ + if (kv == NULL) { return (-1); /* keep looking since this bucket is empty */ } + if (!strcmp(kv->key, (const char*)key)) + { + return (idx); /* found it at idx */ + } + return (-1); /* keep looking */ +} + +/* + This function gets the value for the given key. + + **Arguments:** + * ``map`` -- the ``SUNHashMap`` object to operate on + * ``key`` -- the key to look up + * ``value`` -- the value associated with the key + + **Returns:** + * ``0`` -- success + * ``-1`` -- an error occurred + * ``-2`` -- key not found + */ +int SUNHashMap_GetValue(SUNHashMap map, const char* key, void** value) +{ + int idx; + int retval; + + if (map == NULL || key == NULL || value == NULL) { return (-1); } + + /* We want the index to be in (0, map->max_size) */ + idx = (int)(fnv1a_hash(key) % map->max_size); + + /* Check if the key exists */ + if (map->buckets[idx] == NULL) { return (-2); } + + /* Check to see if this is a collision */ + if (strcmp(map->buckets[idx]->key, key)) + { + /* Keys did not match, so we have a collision and need to probe */ + retval = SUNHashMap_Iterate(map, idx + 1, sunHashMapLinearProbeGet, key); + if (retval < 0) { return (-1); /* error occurred */ } + if (retval == map->max_size) { return (-2); /* not found */ } + } + + /* Return a reference to the value only */ + *value = map->buckets[idx]->value; + + return (0); +} + +/* + This function allocates a new array the same max_size as the map, + then it sorts map into a new array of key-value pairs leaving + the map unchanged. + + **Arguments:** + * ``map`` -- the ``SUNHashMap`` object to operate on + * ``sorted`` -- pointer to the sorted array of key-value pairs, this + function will allocate the array + * ``compar`` -- comparator function that is passed to the C standard qsort + function + + **Returns:** + * A SUNErrCode indicating success or a failure + */ +SUNErrCode SUNHashMap_Sort(SUNHashMap map, SUNHashMapKeyValue** sorted, + int (*compar)(const void*, const void*)) +{ + int i; + + if (!map || !compar) { return SUN_ERR_ARG_CORRUPT; } + + *sorted = (SUNHashMapKeyValue*)malloc(map->max_size * sizeof(**sorted)); + if (!(*sorted)) { return SUN_ERR_MALLOC_FAIL; } + + /* Copy the buckets into a new array */ + for (i = 0; i < map->max_size; i++) { (*sorted)[i] = map->buckets[i]; } + + qsort(*sorted, map->max_size, sizeof(SUNHashMapKeyValue), compar); + + return SUN_SUCCESS; +} + +/* + This function allocates a new array with just they values of the map. + + **Arguments:** + * ``map`` -- the ``SUNHashMap`` object to operate on + * ``values`` -- pointer to the array of keys + * ``value_size`` -- the size of the values in bytes + + **Returns:** + * A SUNErrCode indicating success or a failure + */ +#if SUNDIALS_MPI_ENABLED +SUNErrCode SUNHashMap_Values(SUNHashMap map, void*** values, size_t value_size) +{ + int i; + int count = 0; + + if (!map) { return SUN_ERR_ARG_CORRUPT; } + + *values = (void**)malloc(map->size * value_size); + if (!values) { return SUN_ERR_MALLOC_FAIL; } + + /* Copy the values into a new array */ + for (i = 0; i < map->max_size; i++) + { + if (map->buckets[i]) { (*values)[count++] = map->buckets[i]->value; } + } + + return SUN_SUCCESS; +} +#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap_impl.h b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap_impl.h new file mode 100644 index 000000000..235947ed7 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_hashmap_impl.h @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * A simple hashmap implementation for char* keys and + * void* values. Uses linear probing to resolve collisions. + * The values can be anything, but will be freed by + * the hash map upon its destruction. + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_HASHMAP_IMPL_H +#define _SUNDIALS_HASHMAP_IMPL_H + +#include +#include + +typedef struct SUNHashMapKeyValue_* SUNHashMapKeyValue; + +struct SUNHashMapKeyValue_ +{ + const char* key; + void* value; +}; + +typedef struct SUNHashMap_* SUNHashMap; + +struct SUNHashMap_ +{ + int size; /* current number of entries */ + int max_size; /* max number of entries */ + SUNHashMapKeyValue* buckets; +}; + +SUNErrCode SUNHashMap_New(int max_size, SUNHashMap* map); +SUNErrCode SUNHashMap_Destroy(SUNHashMap* map, void (*freevalue)(void* ptr)); +int SUNHashMap_Iterate(SUNHashMap map, int start, + int (*yieldfn)(int, SUNHashMapKeyValue, const void*), + const void* ctx); +int SUNHashMap_Insert(SUNHashMap map, const char* key, void* value); +int SUNHashMap_GetValue(SUNHashMap map, const char* key, void** value); +SUNErrCode SUNHashMap_Sort(SUNHashMap map, SUNHashMapKeyValue** sorted, + int (*compar)(const void*, const void*)); + +#if SUNDIALS_MPI_ENABLED +SUNErrCode SUNHashMap_Values(SUNHashMap map, void*** values, size_t value_size); +#endif + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative.c index 6b1055cf4..167c5fce1 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative.c +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative.c @@ -1,13 +1,10 @@ -/* - * ----------------------------------------------------------------- - * $Revision$ - * $Date$ - * ----------------------------------------------------------------- +/* ----------------------------------------------------------------- * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and * Radu Serban @ LLNL + * Shelby Lockhart @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,48 +16,58 @@ * This is the implementation file for the iterative.h header * file. It contains the implementation of functions that may be * useful for many different iterative solvers of A x = b. - * ----------------------------------------------------------------- - */ + * -----------------------------------------------------------------*/ #include +#include +#include -#include -#include +#include "sundials/sundials_errors.h" +#include "sundials_iterative_impl.h" -#define FACTOR RCONST(1000.0) -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) +#define FACTOR SUN_RCONST(1000.0) +#define ZERO SUN_RCONST(0.0) +#define ONE SUN_RCONST(1.0) /* * ----------------------------------------------------------------- - * Function : ModifiedGS + * Function : SUNModifiedGS * ----------------------------------------------------------------- - * This implementation of ModifiedGS is a slight modification of a - * previous modified Gram-Schmidt routine (called mgs) written by + * This implementation of SUNModifiedGS is a slight modification of + * a previous modified Gram-Schmidt routine (called mgs) written by * Milo Dorr. * ----------------------------------------------------------------- */ - -int ModifiedGS(N_Vector *v, realtype **h, int k, int p, - realtype *new_vk_norm) + +SUNErrCode SUNModifiedGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm) { - int i, k_minus_1, i0; - realtype new_norm_2, new_product, vk_norm, temp; - - vk_norm = SUNRsqrt(N_VDotProd(v[k],v[k])); + SUNFunctionBegin(v[0]->sunctx); + + int i, k_minus_1, i0; + sunrealtype new_norm_2, new_product, vk_norm, temp; + + vk_norm = N_VDotProd(v[k], v[k]); + SUNCheckLastErr(); + vk_norm = SUNRsqrt(vk_norm); k_minus_1 = k - 1; - i0 = SUNMAX(k-p, 0); - + i0 = SUNMAX(k - p, 0); + /* Perform modified Gram-Schmidt */ - - for (i=i0; i < k; i++) { + + for (i = i0; i < k; i++) + { h[i][k_minus_1] = N_VDotProd(v[i], v[k]); + SUNCheckLastErr(); N_VLinearSum(ONE, v[k], -h[i][k_minus_1], v[i], v[k]); + SUNCheckLastErr(); } /* Compute the norm of the new vector at v[k] */ - *new_vk_norm = SUNRsqrt(N_VDotProd(v[k], v[k])); + *new_vk_norm = N_VDotProd(v[k], v[k]); + SUNCheckLastErr(); + *new_vk_norm = SUNRsqrt(*new_vk_norm); /* If the norm of the new vector at v[k] is less than FACTOR (== 1000) times unit roundoff times the norm of the @@ -69,144 +76,157 @@ int ModifiedGS(N_Vector *v, realtype **h, int k, int p, by a very small vector length. */ temp = FACTOR * vk_norm; - if ((temp + (*new_vk_norm)) != temp) return(0); - + if ((temp + (*new_vk_norm)) != temp) { return SUN_SUCCESS; } + new_norm_2 = ZERO; - for (i=i0; i < k; i++) { + for (i = i0; i < k; i++) + { new_product = N_VDotProd(v[i], v[k]); + SUNCheckLastErr(); temp = FACTOR * h[i][k_minus_1]; - if ((temp + new_product) == temp) continue; + if ((temp + new_product) == temp) { continue; } h[i][k_minus_1] += new_product; - N_VLinearSum(ONE, v[k],-new_product, v[i], v[k]); + N_VLinearSum(ONE, v[k], -new_product, v[i], v[k]); + SUNCheckLastErr(); new_norm_2 += SUNSQR(new_product); } - if (new_norm_2 != ZERO) { - new_product = SUNSQR(*new_vk_norm) - new_norm_2; + if (new_norm_2 != ZERO) + { + new_product = SUNSQR(*new_vk_norm) - new_norm_2; *new_vk_norm = (new_product > ZERO) ? SUNRsqrt(new_product) : ZERO; } - return(0); + return SUN_SUCCESS; } /* * ----------------------------------------------------------------- - * Function : ClassicalGS + * Function : SUNClassicalGS * ----------------------------------------------------------------- - * This implementation of ClassicalGS was contributed by Homer Walker - * and Peter Brown. + * This implementation of SUNClassicalGS was contributed by Homer + * Walker and Peter Brown. * ----------------------------------------------------------------- */ -int ClassicalGS(N_Vector *v, realtype **h, int k, int p, realtype *new_vk_norm, - realtype *stemp, N_Vector *vtemp) +SUNErrCode SUNClassicalGS(N_Vector* v, sunrealtype** h, int k, int p, + sunrealtype* new_vk_norm, sunrealtype* stemp, + N_Vector* vtemp) { - int i, i0, k_minus_1, retval; - realtype vk_norm; + SUNFunctionBegin(v[0]->sunctx); + int i, i0, k_minus_1; + sunrealtype vk_norm; k_minus_1 = k - 1; - i0 = SUNMAX(k-p,0); + i0 = SUNMAX(k - p, 0); /* Perform Classical Gram-Schmidt */ - retval = N_VDotProdMulti(k-i0+1, v[k], v+i0, stemp); - if (retval != 0) return(-1); + SUNCheckCall(N_VDotProdMulti(k - i0 + 1, v[k], v + i0, stemp)); - vk_norm = SUNRsqrt(stemp[k-i0]); - for (i=k-i0-1; i >= 0; i--) { + vk_norm = SUNRsqrt(stemp[k - i0]); + for (i = k - i0 - 1; i >= 0; i--) + { h[i][k_minus_1] = stemp[i]; - stemp[i+1] = -stemp[i]; - vtemp[i+1] = v[i]; + stemp[i + 1] = -stemp[i]; + vtemp[i + 1] = v[i]; } stemp[0] = ONE; vtemp[0] = v[k]; - retval = N_VLinearCombination(k-i0+1, stemp, vtemp, v[k]); - if (retval != 0) return(-1); + SUNCheckCall(N_VLinearCombination(k - i0 + 1, stemp, vtemp, v[k])); /* Compute the norm of the new vector at v[k] */ *new_vk_norm = SUNRsqrt(N_VDotProd(v[k], v[k])); + SUNCheckLastErr(); /* Reorthogonalize if necessary */ - if ((FACTOR * (*new_vk_norm)) < vk_norm) { - - retval = N_VDotProdMulti(k-i0, v[k], v+i0, stemp+1); - if (retval != 0) return(-1); + if ((FACTOR * (*new_vk_norm)) < vk_norm) + { + SUNCheckCall(N_VDotProdMulti(k - i0, v[k], v + i0, stemp + 1)); stemp[0] = ONE; vtemp[0] = v[k]; - for (i=i0; i < k; i++) { - h[i][k_minus_1] += stemp[i-i0+1]; - stemp[i-i0+1] = -stemp[i-i0+1]; - vtemp[i-i0+1] = v[i-i0]; + for (i = i0; i < k; i++) + { + h[i][k_minus_1] += stemp[i - i0 + 1]; + stemp[i - i0 + 1] = -stemp[i - i0 + 1]; + vtemp[i - i0 + 1] = v[i - i0]; } - retval = N_VLinearCombination(k+1, stemp, vtemp, v[k]); - if (retval != 0) return(-1); + SUNCheckCall(N_VLinearCombination(k + 1, stemp, vtemp, v[k])); - *new_vk_norm = SUNRsqrt(N_VDotProd(v[k],v[k])); + *new_vk_norm = SUNRsqrt(N_VDotProd(v[k], v[k])); + SUNCheckLastErr(); } - return(0); + return SUN_SUCCESS; } /* * ----------------------------------------------------------------- - * Function : QRfact + * Function : SUNQRfact * ----------------------------------------------------------------- - * This implementation of QRfact is a slight modification of a + * This implementation of SUNQRfact is a slight modification of a * previous routine (called qrfact) written by Milo Dorr. * ----------------------------------------------------------------- */ -int QRfact(int n, realtype **h, realtype *q, int job) +int SUNQRfact(int n, sunrealtype** h, sunrealtype* q, int job) { - realtype c, s, temp1, temp2, temp3; - int i, j, k, q_ptr, n_minus_1, code=0; + sunrealtype c, s, temp1, temp2, temp3; + int i, j, k, q_ptr, n_minus_1, code = 0; - switch (job) { + switch (job) + { case 0: /* Compute a new factorization of H */ code = 0; - for (k=0; k < n; k++) { - + for (k = 0; k < n; k++) + { /* Multiply column k by the previous k-1 Givens rotations */ - for (j=0; j < k-1; j++) { - i = 2*j; - temp1 = h[j][k]; - temp2 = h[j+1][k]; - c = q[i]; - s = q[i+1]; - h[j][k] = c*temp1 - s*temp2; - h[j+1][k] = s*temp1 + c*temp2; + for (j = 0; j < k - 1; j++) + { + i = 2 * j; + temp1 = h[j][k]; + temp2 = h[j + 1][k]; + c = q[i]; + s = q[i + 1]; + h[j][k] = c * temp1 - s * temp2; + h[j + 1][k] = s * temp1 + c * temp2; } - + /* Compute the Givens rotation components c and s */ - q_ptr = 2*k; + q_ptr = 2 * k; temp1 = h[k][k]; - temp2 = h[k+1][k]; - if( temp2 == ZERO) { - c = ONE; - s = ZERO; - } else if (SUNRabs(temp2) >= SUNRabs(temp1)) { - temp3 = temp1/temp2; - s = -ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - c = -s*temp3; - } else { - temp3 = temp2/temp1; - c = ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - s = -c*temp3; + temp2 = h[k + 1][k]; + if (temp2 == ZERO) + { + c = ONE; + s = ZERO; + } + else if (SUNRabs(temp2) >= SUNRabs(temp1)) + { + temp3 = temp1 / temp2; + s = -ONE / SUNRsqrt(ONE + SUNSQR(temp3)); + c = -s * temp3; } - q[q_ptr] = c; - q[q_ptr+1] = s; - if( (h[k][k] = c*temp1 - s*temp2) == ZERO) code = k+1; + else + { + temp3 = temp2 / temp1; + c = ONE / SUNRsqrt(ONE + SUNSQR(temp3)); + s = -c * temp3; + } + q[q_ptr] = c; + q[q_ptr + 1] = s; + if ((h[k][k] = c * temp1 - s * temp2) == ZERO) { code = k + 1; } } break; @@ -215,84 +235,441 @@ int QRfact(int n, realtype **h, realtype *q, int job) /* Update the factored H to which a new column has been added */ n_minus_1 = n - 1; - code = 0; - + code = 0; + /* Multiply the new column by the previous n-1 Givens rotations */ - for (k=0; k < n_minus_1; k++) { - i = 2*k; - temp1 = h[k][n_minus_1]; - temp2 = h[k+1][n_minus_1]; - c = q[i]; - s = q[i+1]; - h[k][n_minus_1] = c*temp1 - s*temp2; - h[k+1][n_minus_1] = s*temp1 + c*temp2; + for (k = 0; k < n_minus_1; k++) + { + i = 2 * k; + temp1 = h[k][n_minus_1]; + temp2 = h[k + 1][n_minus_1]; + c = q[i]; + s = q[i + 1]; + h[k][n_minus_1] = c * temp1 - s * temp2; + h[k + 1][n_minus_1] = s * temp1 + c * temp2; } - + /* Compute new Givens rotation and multiply it times the last two - entries in the new column of H. Note that the second entry of + entries in the new column of H. Note that the second entry of this product will be 0, so it is not necessary to compute it. */ temp1 = h[n_minus_1][n_minus_1]; temp2 = h[n][n_minus_1]; - if (temp2 == ZERO) { + if (temp2 == ZERO) + { c = ONE; s = ZERO; - } else if (SUNRabs(temp2) >= SUNRabs(temp1)) { - temp3 = temp1/temp2; - s = -ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - c = -s*temp3; - } else { - temp3 = temp2/temp1; - c = ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - s = -c*temp3; } - q_ptr = 2*n_minus_1; - q[q_ptr] = c; - q[q_ptr+1] = s; - if ((h[n_minus_1][n_minus_1] = c*temp1 - s*temp2) == ZERO) - code = n; + else if (SUNRabs(temp2) >= SUNRabs(temp1)) + { + temp3 = temp1 / temp2; + s = -ONE / SUNRsqrt(ONE + SUNSQR(temp3)); + c = -s * temp3; + } + else + { + temp3 = temp2 / temp1; + c = ONE / SUNRsqrt(ONE + SUNSQR(temp3)); + s = -c * temp3; + } + q_ptr = 2 * n_minus_1; + q[q_ptr] = c; + q[q_ptr + 1] = s; + if ((h[n_minus_1][n_minus_1] = c * temp1 - s * temp2) == ZERO) { code = n; } } - + return (code); } /* * ----------------------------------------------------------------- - * Function : QRsol + * Function : SUNQRsol * ----------------------------------------------------------------- - * This implementation of QRsol is a slight modification of a + * This implementation of SUNQRsol is a slight modification of a * previous routine (called qrsol) written by Milo Dorr. * ----------------------------------------------------------------- */ -int QRsol(int n, realtype **h, realtype *q, realtype *b) +int SUNQRsol(int n, sunrealtype** h, sunrealtype* q, sunrealtype* b) { - realtype c, s, temp1, temp2; - int i, k, q_ptr, code=0; + sunrealtype c, s, temp1, temp2; + int i, k, q_ptr, code = 0; /* Compute Q*b */ - - for (k=0; k < n; k++) { - q_ptr = 2*k; - c = q[q_ptr]; - s = q[q_ptr+1]; - temp1 = b[k]; - temp2 = b[k+1]; - b[k] = c*temp1 - s*temp2; - b[k+1] = s*temp1 + c*temp2; + + for (k = 0; k < n; k++) + { + q_ptr = 2 * k; + c = q[q_ptr]; + s = q[q_ptr + 1]; + temp1 = b[k]; + temp2 = b[k + 1]; + b[k] = c * temp1 - s * temp2; + b[k + 1] = s * temp1 + c * temp2; } /* Solve R*x = Q*b */ - for (k=n-1; k >= 0; k--) { - if (h[k][k] == ZERO) { + for (k = n - 1; k >= 0; k--) + { + if (h[k][k] == ZERO) + { code = k + 1; break; } b[k] /= h[k][k]; - for (i=0; i < k; i++) b[i] -= b[k]*h[i][k]; + for (i = 0; i < k; i++) { b[i] -= b[k] * h[i][k]; } } - + return (code); } + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_MGS + * ----------------------------------------------------------------- + * Implementation of QRAdd to be called in Anderson Acceleration + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_MGS(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + + sunindextype j; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); + for (j = 0; j < m; j++) + { + R[m * mMax + j] = N_VDotProd(Q[j], qrdata->vtemp); + SUNCheckLastErr(); + N_VLinearSum(ONE, qrdata->vtemp, -R[m * mMax + j], Q[j], qrdata->vtemp); + SUNCheckLastErr(); + } + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_ICWY + * ----------------------------------------------------------------- + * Low synchronous implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_ICWY(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + sunindextype j, k; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); /* stores d_fi in temp */ + + if (m > 0) + { + /* T(1:k-1,k-1)^T = Q(:,1:k-1)^T * Q(:,k-1) */ + SUNCheckCall( + N_VDotProdMulti(m, Q[m - 1], Q, qrdata->temp_array + (m - 1) * mMax)); + + /* T(k-1,k-1) = 1.0 */ + qrdata->temp_array[(m - 1) * mMax + (m - 1)] = ONE; + + /* R(1:k-1,k) = Q_k-1^T * df */ + SUNCheckCall(N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax)); + + /* Solve T^T * R(1:k-1,k) = R(1:k-1,k) */ + for (k = 0; k < m; k++) + { + /* Skip setting the diagonal element because it doesn't change */ + for (j = k + 1; j < m; j++) + { + R[m * mMax + j] -= R[m * mMax + k] * qrdata->temp_array[j * mMax + k]; + } + } + /* end */ + + /* Q(:,k-1) = df - Q_k-1 R(1:k-1,k) */ + SUNCheckCall(N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + SUNCheckLastErr(); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + /* Q(:,k) = df / \| df \| */ + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_ICWY_SB + * ----------------------------------------------------------------- + * Low synchronous implementation of QRAdd to be called in + * Anderson Acceleration which utilizes a single buffer reduction. + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_ICWY_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + sunindextype j, k; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); /* stores d_fi in temp */ + + if (m > 0) + { + /* T(1:k-1,k-1)^T = Q(:,1:k-1)^T * Q(:,k-1) */ + SUNCheckCall(N_VDotProdMultiLocal(m, Q[m - 1], Q, + qrdata->temp_array + (m - 1) * mMax)); + + /* R(1:k-1,k) = Q_k-1^T * df */ + /* Put R values at end of temp_array */ + SUNCheckCall(N_VDotProdMultiLocal(m, qrdata->vtemp, Q, + qrdata->temp_array + (m - 1) * mMax + m)); + + SUNCheckCall(N_VDotProdMultiAllReduce(m + m, qrdata->vtemp, + qrdata->temp_array + (m - 1) * mMax)); + + /* Move the last values from temp array into R */ + for (k = 0; k < m; k++) + { + R[m * mMax + k] = qrdata->temp_array[(m - 1) * mMax + m + k]; + } + + /* T(k-1,k-1) = 1.0 */ + qrdata->temp_array[(m - 1) * mMax + (m - 1)] = ONE; + + /* Solve T^T * R(1:k-1,k) = R(1:k-1,k) */ + for (k = 0; k < m; k++) + { + /* Skip setting the diagonal element because it doesn't change */ + for (j = k + 1; j < m; j++) + { + R[m * mMax + j] -= R[m * mMax + k] * qrdata->temp_array[j * mMax + k]; + } + } + /* end */ + + /* Q(:,k-1) = df - Q_k-1 R(1:k-1,k) */ + SUNCheckCall(N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + SUNCheckLastErr(); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + /* Q(:,k) = df / \| df \| */ + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_CGS2 + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_CGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + sunindextype j; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); /* temp = df */ + + if (m > 0) + { + /* s_k = Q_k-1^T df_aa -- update with sdata as a sunrealtype* array */ + SUNCheckCall(N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax)); + + /* y = df - Q_k-1 s_k */ + SUNCheckCall(N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp2); + SUNCheckLastErr(); + + /* z_k = Q_k-1^T y */ + SUNCheckCall(N_VDotProdMulti(m, qrdata->vtemp2, Q, qrdata->temp_array)); + + /* df = y - Q_k-1 z_k */ + SUNCheckCall(N_VLinearCombination(m, qrdata->temp_array, Q, Q[m])); + N_VLinearSum(ONE, qrdata->vtemp2, -ONE, Q[m], qrdata->vtemp); + SUNCheckLastErr(); + + /* R(1:k-1,k) = s_k + z_k */ + for (j = 0; j < m; j++) + { + R[m * mMax + j] = R[m * mMax + j] + qrdata->temp_array[j]; + } + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_DCGS2 + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_DCGS2(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + sunindextype j; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); /* temp = df */ + + if (m > 0) + { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + SUNCheckCall(N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax)); + /* Delayed reorthogonalization */ + if (m > 1) + { + /* s = Q_k-2^T Q(:,k-1) */ + SUNCheckCall(N_VDotProdMulti(m - 1, Q[m - 1], Q, qrdata->temp_array)); + + /* Q(:,k-1) = Q(:,k-1) - Q_k-2 s */ + SUNCheckCall( + N_VLinearCombination(m - 1, qrdata->temp_array, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, Q[m - 1], -ONE, qrdata->vtemp2, Q[m - 1]); + SUNCheckLastErr(); + + /* R(1:k-2,k-1) = R(1:k-2,k-1) + s */ + for (j = 0; j < m - 1; j++) + { + R[(m - 1) * mMax + j] = R[(m - 1) * mMax + j] + qrdata->temp_array[j]; + } + } + + /* df = df - Q(:,k-1) R(1:k-1,k) */ + SUNCheckCall(N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + SUNCheckLastErr(); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_DCGS2_SB + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration which utilizes a single buffer reduction. + * ----------------------------------------------------------------- + */ + +SUNErrCode SUNQRAdd_DCGS2_SB(N_Vector* Q, sunrealtype* R, N_Vector df, int m, + int mMax, void* QRdata) +{ + SUNFunctionBegin(Q[0]->sunctx); + sunindextype j; + SUNQRData qrdata = (SUNQRData)QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + SUNCheckLastErr(); /* temp = df */ + + if (m > 0) + { + if (m == 1) + { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + SUNCheckCall(N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax)); + } + /* Delayed reorthogonalization */ + else if (m > 1) + { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + /* Put R values at beginning of temp array */ + SUNCheckCall(N_VDotProdMultiLocal(m, qrdata->vtemp, Q, qrdata->temp_array)); + + /* s = Q_k-2^T Q(:,k-1) */ + SUNCheckCall( + N_VDotProdMultiLocal(m - 1, Q[m - 1], Q, qrdata->temp_array + m)); + SUNCheckCall( + N_VDotProdMultiAllReduce(m + m - 1, qrdata->vtemp, qrdata->temp_array)); + + /* Move R values to R */ + for (j = 0; j < m; j++) { R[m * mMax + j] = qrdata->temp_array[j]; } + + /* Q(:,k-1) = Q(:,k-1) - Q_k-2 s */ + SUNCheckCall( + N_VLinearCombination(m - 1, qrdata->temp_array + m, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, Q[m - 1], -ONE, qrdata->vtemp2, Q[m - 1]); + SUNCheckLastErr(); + + /* R(1:k-2,k-1) = R(1:k-2,k-1) + s */ + for (j = 0; j < m - 1; j++) + { + R[(m - 1) * mMax + j] = R[(m - 1) * mMax + j] + qrdata->temp_array[m + j]; + } + } + + /* df = df - Q(:,k-1) R(1:k-1,k) */ + SUNCheckCall(N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2)); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + SUNCheckLastErr(); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = N_VDotProd(qrdata->vtemp, qrdata->vtemp); + SUNCheckLastErr(); + R[m * mMax + m] = SUNRsqrt(R[m * mMax + m]); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1 / R[m * mMax + m]), qrdata->vtemp, Q[m]); + SUNCheckLastErr(); + + return SUN_SUCCESS; +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative_impl.h b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative_impl.h new file mode 100644 index 000000000..ea6c17c10 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_iterative_impl.h @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner and Shelby Lockhart @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------------------- + * This is the implementation header file for SUNDIALS functions used by + * different iterative solvers. + * ---------------------------------------------------------------------------*/ + +#ifndef _SUNDIALS_ITERATIVE_IMPL_H +#define _SUNDIALS_ITERATIVE_IMPL_H + +#include + +/* ----------------------------------------------------------------------------- + * Type: SUNQRData + * ----------------------------------------------------------------------------- + * A SUNQRData struct holds temporary workspace vectors and sunrealtype arrays for + * a SUNQRAddFn. The N_Vectors and sunrealtype arrays it contains are created by + * the routine calling a SUNQRAdd function. + * ---------------------------------------------------------------------------*/ + +typedef struct _SUNQRData* SUNQRData; + +struct _SUNQRData +{ + N_Vector vtemp; + N_Vector vtemp2; + sunrealtype* temp_array; +}; + +#endif diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_linearsolver.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_linearsolver.c index 28f5e48a8..9df036dd5 100644 --- a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_linearsolver.c +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_linearsolver.c @@ -4,7 +4,7 @@ * Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2024, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,26 +19,42 @@ * -----------------------------------------------------------------*/ #include -#include +#include +#include +#include + +#include "sundials_iterative_impl.h" +#include "sundials_logger_impl.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) +static SUNProfiler getSUNProfiler(SUNLinearSolver S) +{ + return (S->sunctx->profiler); +} +#endif /* ----------------------------------------------------------------- * Create a new empty SUNLinearSolver object * ----------------------------------------------------------------- */ -SUNLinearSolver SUNLinSolNewEmpty() +SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx) { - SUNLinearSolver LS; + SUNLinearSolver LS; SUNLinearSolver_Ops ops; + if (sunctx == NULL) { return NULL; } + + SUNFunctionBegin(sunctx); + /* create linear solver object */ LS = NULL; - LS = (SUNLinearSolver) malloc(sizeof *LS); - if (LS == NULL) return(NULL); + LS = (SUNLinearSolver)malloc(sizeof *LS); + SUNAssertNull(LS, SUN_ERR_MALLOC_FAIL); /* create linear solver ops structure */ ops = NULL; - ops = (SUNLinearSolver_Ops) malloc(sizeof *ops); - if (ops == NULL) { free(LS); return(NULL); } + ops = (SUNLinearSolver_Ops)malloc(sizeof *ops); + SUNAssertNull(ops, SUN_ERR_MALLOC_FAIL); /* initialize operations to NULL */ ops->gettype = NULL; @@ -57,11 +73,12 @@ SUNLinearSolver SUNLinSolNewEmpty() ops->space = NULL; ops->free = NULL; - /* attach ops and initialize content to NULL */ + /* attach ops and initialize content and context to NULL */ LS->ops = ops; LS->content = NULL; + LS->sunctx = sunctx; - return(LS); + return (LS); } /* ----------------------------------------------------------------- @@ -70,10 +87,10 @@ SUNLinearSolver SUNLinSolNewEmpty() void SUNLinSolFreeEmpty(SUNLinearSolver S) { - if (S == NULL) return; + if (S == NULL) { return; } /* free non-NULL ops structure */ - if (S->ops) free(S->ops); + if (S->ops) { free(S->ops); } S->ops = NULL; /* free overall N_Vector object and return */ @@ -87,132 +104,154 @@ void SUNLinSolFreeEmpty(SUNLinearSolver S) SUNLinearSolver_Type SUNLinSolGetType(SUNLinearSolver S) { - return(S->ops->gettype(S)); + return (S->ops->gettype(S)); } SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S) { - if (S->ops->getid) - return(S->ops->getid(S)); - else - return(SUNLINEARSOLVER_CUSTOM); + if (S->ops->getid) { return (S->ops->getid(S)); } + else { return (SUNLINEARSOLVER_CUSTOM); } } -int SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, - ATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, SUNATimesFn ATimes) { - if (S->ops->setatimes) - return ((int) S->ops->setatimes(S, A_data, ATimes)); - else - return SUNLS_SUCCESS; + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->setatimes) { ier = S->ops->setatimes(S, A_data, ATimes); } + else { ier = SUN_SUCCESS; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } - -int SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, - PSetupFn Pset, PSolveFn Psol) +SUNErrCode SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol) { + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setpreconditioner) - return ((int) S->ops->setpreconditioner(S, P_data, Pset, Psol)); - else - return SUNLS_SUCCESS; + { + ier = S->ops->setpreconditioner(S, P_data, Pset, Psol); + } + else { ier = SUN_SUCCESS; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } -int SUNLinSolSetScalingVectors(SUNLinearSolver S, - N_Vector s1, N_Vector s2) +SUNErrCode SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, N_Vector s2) { - if (S->ops->setscalingvectors) - return ((int) S->ops->setscalingvectors(S, s1, s2)); - else - return SUNLS_SUCCESS; + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->setscalingvectors) { ier = S->ops->setscalingvectors(S, s1, s2); } + else { ier = SUN_SUCCESS; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } -int SUNLinSolSetZeroGuess(SUNLinearSolver S, booleantype onoff) +SUNErrCode SUNLinSolSetZeroGuess(SUNLinearSolver S, sunbooleantype onoff) { - if (S->ops->setzeroguess) - return ((int) S->ops->setzeroguess(S, onoff)); - else - return SUNLS_SUCCESS; + if (S->ops->setzeroguess) { return (S->ops->setzeroguess(S, onoff)); } + else { return SUN_SUCCESS; } } -int SUNLinSolInitialize(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize(SUNLinearSolver S) { - if (S->ops->initialize) - return ((int) S->ops->initialize(S)); - else - return SUNLS_SUCCESS; + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->initialize) { ier = S->ops->initialize(S); } + else { ier = SUN_SUCCESS; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A) { - if (S->ops->setup) - return ((int) S->ops->setup(S, A)); - else - return SUNLS_SUCCESS; + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->setup) { ier = S->ops->setup(S, A); } + else { ier = SUN_SUCCESS; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } -int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, - N_Vector b, realtype tol) +int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol) { - return ((int) S->ops->solve(S, A, x, b, tol)); + SUNErrCode ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + ier = S->ops->solve(S, A, x, b, tol); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (ier); } int SUNLinSolNumIters(SUNLinearSolver S) { - if (S->ops->numiters) - return ((int) S->ops->numiters(S)); - else - return 0; + int result; + if (S->ops->numiters) { result = S->ops->numiters(S); } + else { result = 0; } + return (result); } -realtype SUNLinSolResNorm(SUNLinearSolver S) +sunrealtype SUNLinSolResNorm(SUNLinearSolver S) { - if (S->ops->resnorm) - return ((realtype) S->ops->resnorm(S)); - else - return RCONST(0.0); + sunrealtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->resnorm) { result = S->ops->resnorm(S); } + else { result = SUN_RCONST(0.0); } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (result); } N_Vector SUNLinSolResid(SUNLinearSolver S) { - if (S->ops->resid) - return ((N_Vector) S->ops->resid(S)); - else - return NULL; + N_Vector resid; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + if (S->ops->resid) { resid = S->ops->resid(S); } + else { resid = NULL; } + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return (resid); } sunindextype SUNLinSolLastFlag(SUNLinearSolver S) { - if (S->ops->lastflag) - return ((sunindextype) S->ops->lastflag(S)); - else - return SUNLS_SUCCESS; + if (S->ops->lastflag) { return ((sunindextype)S->ops->lastflag(S)); } + else { return 0; } } -int SUNLinSolSpace(SUNLinearSolver S, long int *lenrwLS, - long int *leniwLS) +SUNErrCode SUNLinSolSpace(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) { - if (S->ops->space) - return ((int) S->ops->space(S, lenrwLS, leniwLS)); - else { + if (S->ops->space) { return (S->ops->space(S, lenrwLS, leniwLS)); } + else + { *lenrwLS = 0; *leniwLS = 0; - return SUNLS_SUCCESS; + return SUN_SUCCESS; } } -int SUNLinSolFree(SUNLinearSolver S) +SUNErrCode SUNLinSolFree(SUNLinearSolver S) { - if (S == NULL) return SUNLS_SUCCESS; + if (S == NULL) { return SUN_SUCCESS; } /* if the free operation exists use it */ if (S->ops) - if (S->ops->free) return(S->ops->free(S)); + { + if (S->ops->free) { return (S->ops->free(S)); } + } /* if we reach this point, either ops == NULL or free == NULL, try to cleanup by freeing the content, ops, and solver */ - if (S->content) { free(S->content); S->content = NULL; } - if (S->ops) { free(S->ops); S->ops = NULL; } - free(S); S = NULL; + if (S->content) + { + free(S->content); + S->content = NULL; + } + if (S->ops) + { + free(S->ops); + S->ops = NULL; + } + free(S); + S = NULL; - return(SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger.c b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger.c new file mode 100644 index 000000000..bc4d6869a --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger.c @@ -0,0 +1,474 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * -----------------------------------------------------------------*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if SUNDIALS_MPI_ENABLED +#include +#endif + +#include "sundials_logger_impl.h" +#include "sundials_macros.h" +#include "sundials_utils.h" + +/* max number of files that can be opened */ +#define SUN_MAX_LOGFILE_HANDLES_ 8 + +void sunCreateLogMessage(SUNLogLevel lvl, int rank, const char* scope, + const char* label, const char* txt, va_list args, + char** log_msg) +{ + char* prefix; + char* formatted_txt; + int msg_length; + + prefix = NULL; + formatted_txt = NULL; + msg_length = 0; + *log_msg = NULL; + + msg_length = sunvasnprintf(&formatted_txt, txt, args); + if (msg_length < 0) + { + fprintf(stderr, "[FATAL LOGGER ERROR] %s\n", "message size too large"); + } + + if (lvl == SUN_LOGLEVEL_DEBUG) { prefix = (char*)"DEBUG"; } + else if (lvl == SUN_LOGLEVEL_WARNING) { prefix = (char*)"WARNING"; } + else if (lvl == SUN_LOGLEVEL_INFO) { prefix = (char*)"INFO"; } + else if (lvl == SUN_LOGLEVEL_ERROR) { prefix = (char*)"ERROR"; } + + msg_length = sunsnprintf(NULL, 0, "[%s][rank %d][%s][%s] %s\n", prefix, rank, + scope, label, formatted_txt); + *log_msg = (char*)malloc(msg_length + 1); + sunsnprintf(*log_msg, msg_length + 1, "[%s][rank %d][%s][%s] %s\n", prefix, + rank, scope, label, formatted_txt); + free(formatted_txt); +} + +#if SUNDIALS_LOGGING_LEVEL > 0 +static FILE* sunOpenLogFile(const char* fname, const char* mode) +{ + FILE* fp = NULL; + + if (fname) + { + if (!strcmp(fname, "stdout")) { fp = stdout; } + else if (!strcmp(fname, "stderr")) { fp = stderr; } + else { fp = fopen(fname, mode); } + } + + return fp; +} +#endif + +static void sunCloseLogFile(void* fp) +{ + if (fp && fp != stdout && fp != stderr) { fclose((FILE*)fp); } +} + +static sunbooleantype sunLoggerIsOutputRank(SUNDIALS_MAYBE_UNUSED SUNLogger logger, + int* rank_ref) +{ + sunbooleantype retval; + +#if SUNDIALS_MPI_ENABLED + int rank = 0; + + if (logger->comm != SUN_COMM_NULL) + { + MPI_Comm_rank(logger->comm, &rank); + + if (logger->output_rank < 0) + { + if (rank_ref) { *rank_ref = rank; } + retval = SUNTRUE; /* output all ranks */ + } + else + { + if (rank_ref) { *rank_ref = rank; } + retval = logger->output_rank == rank; + } + } + else { retval = SUNTRUE; /* output all ranks */ } +#else + if (rank_ref) { *rank_ref = 0; } + retval = SUNTRUE; +#endif + + return retval; +} + +SUNErrCode SUNLogger_Create(SUNComm comm, int output_rank, SUNLogger* logger_ptr) +{ + SUNLogger logger = NULL; + + *logger_ptr = logger = (SUNLogger)malloc(sizeof(struct SUNLogger_)); + if (logger == NULL) { return SUN_ERR_MALLOC_FAIL; } + + /* Attach the comm, duplicating it if MPI is used. */ +#if SUNDIALS_MPI_ENABLED + logger->comm = SUN_COMM_NULL; + if (comm != SUN_COMM_NULL) { MPI_Comm_dup(comm, &logger->comm); } +#else + logger->comm = SUN_COMM_NULL; + if (comm != SUN_COMM_NULL) + { + free(logger); + return SUN_ERR_ARG_CORRUPT; + } +#endif + logger->output_rank = output_rank; + logger->content = NULL; + + /* use default routines */ + logger->queuemsg = NULL; + logger->flush = NULL; + logger->destroy = NULL; + + /* set the output file handles */ + logger->filenames = NULL; + logger->error_fp = stderr; + logger->warning_fp = stdout; + logger->debug_fp = NULL; + logger->info_fp = NULL; + if (sunLoggerIsOutputRank(logger, NULL)) + { + /* We store the FILE* in a hash map so that we can ensure + that we do not open a file twice if the same file is used + for multiple output levels */ + SUNHashMap_New(SUN_MAX_LOGFILE_HANDLES_, &logger->filenames); + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_CreateFromEnv(SUNComm comm, SUNLogger* logger_out) +{ + SUNErrCode err = SUN_SUCCESS; + SUNLogger logger = NULL; + + const char* output_rank_env = getenv("SUNLOGGER_OUTPUT_RANK"); + int output_rank = (output_rank_env) ? atoi(output_rank_env) : 0; + const char* error_fname_env = getenv("SUNLOGGER_ERROR_FILENAME"); + const char* warning_fname_env = getenv("SUNLOGGER_WARNING_FILENAME"); + const char* info_fname_env = getenv("SUNLOGGER_INFO_FILENAME"); + const char* debug_fname_env = getenv("SUNLOGGER_DEBUG_FILENAME"); + + if (SUNLogger_Create(comm, output_rank, &logger)) + { + err = SUN_ERR_CORRUPT; + return err; + } + + do { + err = SUNLogger_SetErrorFilename(logger, error_fname_env); + if (err) { break; } + err = SUNLogger_SetWarningFilename(logger, warning_fname_env); + if (err) { break; } + err = SUNLogger_SetDebugFilename(logger, debug_fname_env); + if (err) { break; } + err = SUNLogger_SetInfoFilename(logger, info_fname_env); + } + while (0); + + if (err) { SUNLogger_Destroy(&logger); } + else { *logger_out = logger; } + + return err; +} + +SUNErrCode SUNLogger_SetErrorFilename(SUNLogger logger, const char* error_filename) +{ + if (!logger) { return SUN_ERR_ARG_CORRUPT; } + + if (!sunLoggerIsOutputRank(logger, NULL)) { return SUN_SUCCESS; } + + if (error_filename && strcmp(error_filename, "")) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_ERROR + FILE* fp = NULL; + if (!SUNHashMap_GetValue(logger->filenames, error_filename, (void*)&fp)) + { + logger->error_fp = fp; + } + else + { + logger->error_fp = sunOpenLogFile(error_filename, "w+"); + if (logger->error_fp) + { + SUNHashMap_Insert(logger->filenames, error_filename, + (void*)logger->error_fp); + } + else { return SUN_ERR_FILE_OPEN; } + } +#endif + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_SetWarningFilename(SUNLogger logger, + const char* warning_filename) +{ + if (!logger) { return SUN_ERR_ARG_CORRUPT; } + + if (!sunLoggerIsOutputRank(logger, NULL)) { return SUN_SUCCESS; } + + if (warning_filename && strcmp(warning_filename, "")) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING + FILE* fp = NULL; + if (!SUNHashMap_GetValue(logger->filenames, warning_filename, (void*)&fp)) + { + logger->warning_fp = fp; + } + else + { + logger->warning_fp = sunOpenLogFile(warning_filename, "w+"); + if (logger->warning_fp) + { + SUNHashMap_Insert(logger->filenames, warning_filename, + (void*)logger->warning_fp); + } + else { return SUN_ERR_FILE_OPEN; } + } +#endif + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_SetInfoFilename(SUNLogger logger, const char* info_filename) +{ + if (!logger) { return SUN_ERR_ARG_CORRUPT; } + + if (!sunLoggerIsOutputRank(logger, NULL)) { return SUN_SUCCESS; } + + if (info_filename && strcmp(info_filename, "")) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO + FILE* fp = NULL; + if (!SUNHashMap_GetValue(logger->filenames, info_filename, (void*)&fp)) + { + logger->info_fp = fp; + } + else + { + logger->info_fp = sunOpenLogFile(info_filename, "w+"); + if (logger->info_fp) + { + SUNHashMap_Insert(logger->filenames, info_filename, + (void*)logger->info_fp); + } + else { return SUN_ERR_FILE_OPEN; } + } +#endif + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_SetDebugFilename(SUNLogger logger, const char* debug_filename) +{ + if (!logger) { return SUN_ERR_ARG_CORRUPT; } + + if (!sunLoggerIsOutputRank(logger, NULL)) { return SUN_SUCCESS; } + + if (debug_filename && strcmp(debug_filename, "")) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG + FILE* fp = NULL; + if (!SUNHashMap_GetValue(logger->filenames, debug_filename, (void*)&fp)) + { + logger->debug_fp = fp; + } + else + { + logger->debug_fp = sunOpenLogFile(debug_filename, "w+"); + if (logger->debug_fp) + { + SUNHashMap_Insert(logger->filenames, debug_filename, + (void*)logger->debug_fp); + } + else { return SUN_ERR_FILE_OPEN; } + } +#endif + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl, + const char* scope, const char* label, + const char* msg_txt, ...) +{ + SUNErrCode retval = SUN_SUCCESS; + +#if SUNDIALS_LOGGING_LEVEL > 0 + { + if (!logger) + { + retval = SUN_ERR_ARG_CORRUPT; + return retval; + } + + va_list args; + va_start(args, msg_txt); + + if (logger->queuemsg) + { + retval = logger->queuemsg(logger, lvl, scope, label, msg_txt, args); + } + else + { + /* Default implementation */ + int rank = 0; + if (sunLoggerIsOutputRank(logger, &rank)) + { + char* log_msg = NULL; + sunCreateLogMessage(lvl, rank, scope, label, msg_txt, args, &log_msg); + + switch (lvl) + { + case (SUN_LOGLEVEL_DEBUG): + if (logger->debug_fp) { fprintf(logger->debug_fp, "%s", log_msg); } + break; + case (SUN_LOGLEVEL_WARNING): + if (logger->warning_fp) + { + fprintf(logger->warning_fp, "%s", log_msg); + } + break; + case (SUN_LOGLEVEL_INFO): + if (logger->info_fp) { fprintf(logger->info_fp, "%s", log_msg); } + break; + case (SUN_LOGLEVEL_ERROR): + if (logger->error_fp) { fprintf(logger->error_fp, "%s", log_msg); } + break; + default: retval = SUN_ERR_UNREACHABLE; + } + + free(log_msg); + } + } + + va_end(args); + } +#else + /* silence warnings when all logging is disabled */ + ((void)logger); + ((void)lvl); + ((void)scope); + ((void)label); + ((void)msg_txt); +#endif + + return retval; +} + +SUNErrCode SUNLogger_Flush(SUNLogger logger, SUNLogLevel lvl) +{ + SUNErrCode retval = SUN_SUCCESS; + + if (!logger) + { + retval = SUN_ERR_ARG_CORRUPT; + return retval; + } + +#if SUNDIALS_LOGGING_LEVEL > 0 + if (logger->flush) { retval = logger->flush(logger, lvl); } + else + { + /* Default implementation */ + if (sunLoggerIsOutputRank(logger, NULL)) + { + switch (lvl) + { + case (SUN_LOGLEVEL_DEBUG): + if (logger->debug_fp) { fflush(logger->debug_fp); } + break; + case (SUN_LOGLEVEL_WARNING): + if (logger->warning_fp) { fflush(logger->warning_fp); } + break; + case (SUN_LOGLEVEL_INFO): + if (logger->info_fp) { fflush(logger->info_fp); } + break; + case (SUN_LOGLEVEL_ERROR): + if (logger->error_fp) { fflush(logger->error_fp); } + break; + case (SUN_LOGLEVEL_ALL): + if (logger->debug_fp) { fflush(logger->debug_fp); } + if (logger->warning_fp) { fflush(logger->warning_fp); } + if (logger->info_fp) { fflush(logger->info_fp); } + if (logger->error_fp) { fflush(logger->error_fp); } + break; + default: retval = SUN_ERR_UNREACHABLE; + } + } + } +#else + /* silence warnings when all logging is disabled */ + ((void)lvl); +#endif + + return retval; +} + +SUNErrCode SUNLogger_GetOutputRank(SUNLogger logger, int* output_rank) +{ + if (!logger) { return SUN_ERR_ARG_CORRUPT; } + *output_rank = logger->output_rank; + return SUN_SUCCESS; +} + +SUNErrCode SUNLogger_Destroy(SUNLogger* logger_ptr) +{ + int retval = 0; + SUNLogger logger = NULL; + + if (!logger_ptr) { return SUN_SUCCESS; } + + logger = *logger_ptr; + + if (logger && logger->destroy) { retval = logger->destroy(logger_ptr); } + else if (logger) + { + /* Default implementation */ + + if (sunLoggerIsOutputRank(logger, NULL)) + { + SUNHashMap_Destroy(&logger->filenames, sunCloseLogFile); + } + +#if SUNDIALS_MPI_ENABLED + if (logger->comm != SUN_COMM_NULL) { MPI_Comm_free(&logger->comm); } +#endif + + free(logger); + logger = NULL; + } + + return retval; +} diff --git a/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger_impl.h b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger_impl.h new file mode 100644 index 000000000..6fbb7cac4 --- /dev/null +++ b/deps/AMICI/ThirdParty/sundials/src/sundials/sundials_logger_impl.h @@ -0,0 +1,84 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2024, Lawrence Livermore National Security + * and Southern Methodist University. + * All rights reserved. + * + * See the top-level LICENSE and NOTICE files for details. + * + * SPDX-License-Identifier: BSD-3-Clause + * SUNDIALS Copyright End + * ----------------------------------------------------------------- + * SUNDIALS logging class implementation. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_LOGGER_IMPL_H +#define _SUNDIALS_LOGGER_IMPL_H + +#include +#include +#include + +#include "sundials_hashmap_impl.h" +#include "sundials_utils.h" + +#define SUNDIALS_LOGGING_ERROR 1 +#define SUNDIALS_LOGGING_WARNING 2 +#define SUNDIALS_LOGGING_INFO 3 +#define SUNDIALS_LOGGING_DEBUG 4 +#if SUNDIALS_LOGGING_LEVEL > SUNDIALS_LOGGING_DEBUG +#define SUNDIALS_LOGGING_EXTRA_DEBUG +#endif + +struct SUNLogger_ +{ + /* MPI information */ + SUNComm comm; + int output_rank; + + /* Ouput files */ + FILE* debug_fp; + FILE* warning_fp; + FILE* info_fp; + FILE* error_fp; + + /* Hashmap used to store filename, FILE* pairs */ + SUNHashMap filenames; + + /* Slic-style format string */ + const char* format; + + /* Content for custom implementations */ + void* content; + + /* Overridable operations */ + SUNErrCode (*queuemsg)(SUNLogger logger, SUNLogLevel lvl, const char* scope, + const char* label, const char* msg_txt, va_list args); + SUNErrCode (*flush)(SUNLogger logger, SUNLogLevel lvl); + SUNErrCode (*destroy)(SUNLogger* logger); +}; + +/* + This function creates a log message string in the correct format. + It allocates the log_msg parameter, which must be freed by the caller. + The format of the log message is: + + [ERROR][rank ][][