From 41e6a260160090db0e27ffb1f12ba716e9ae2f42 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 29 Oct 2025 23:56:37 +1300 Subject: [PATCH 1/7] New version. --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 7062ff153..c2ba9d207 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.20251027.0 +0.20251030.0 From b7c80b751a8477d392efc09e5e62c4109df334fd Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 28 Oct 2025 14:57:14 +1300 Subject: [PATCH 2/7] C++: use brace initialisation. This is the preferred way to initialise variables in C++11 and later, this for consistency and safety. --- cmake/base64encoder.cpp | 6 +- extern/nanobind/src/implicit.cpp | 12 +- src/api/libopencor/file.h | 4 +- src/api/libopencor/sedanalysis.h | 4 +- src/api/libopencor/sedchangeattribute.h | 2 +- src/api/libopencor/seddocument.h | 2 +- src/api/libopencor/sedmodel.h | 6 +- src/api/libopencor/sedonestep.h | 4 +- src/api/libopencor/sedrepeatedtask.h | 4 +- src/api/libopencor/sedsteadystate.h | 4 +- src/api/libopencor/sedtask.h | 4 +- src/api/libopencor/seduniformtimecourse.h | 4 +- src/api/libopencor/solvercvode.h | 2 +- src/api/libopencor/solverforwardeuler.h | 2 +- .../libopencor/solverfourthorderrungekutta.h | 2 +- src/api/libopencor/solverheun.h | 2 +- src/api/libopencor/solverkinsol.h | 2 +- .../libopencor/solversecondorderrungekutta.h | 2 +- src/bindings/javascript/file.cpp | 12 +- src/file/file.cpp | 14 +- src/file/file_p.h | 8 +- src/file/filemanager.cpp | 16 +- src/logger/logger.cpp | 6 +- src/misc/compiler.cpp | 78 +-- src/misc/utils.cpp | 146 +++--- src/misc/utils.h | 4 +- src/sed/sedabstracttask.cpp | 2 +- src/sed/sedanalysis.cpp | 2 +- src/sed/sedchangeattribute.cpp | 28 +- src/sed/seddocument.cpp | 60 +-- src/sed/seddocument_p.h | 6 +- src/sed/sedinstance.cpp | 10 +- src/sed/sedinstancetask.cpp | 52 +- src/sed/sedinstancetask_p.h | 12 +- src/sed/sedmodel.cpp | 22 +- src/sed/sedonestep.cpp | 2 +- src/sed/sedonestep_p.h | 2 +- src/sed/sedrepeatedtask.cpp | 2 +- src/sed/sedsimulation.cpp | 4 +- src/sed/sedsteadystate.cpp | 2 +- src/sed/sedtask.cpp | 2 +- src/sed/seduniformtimecourse.cpp | 2 +- src/sed/seduniformtimecourse_p.h | 8 +- src/solver/solver.cpp | 6 +- src/solver/solvercvode.cpp | 24 +- src/solver/solvercvode_p.h | 72 +-- src/solver/solverforwardeuler.cpp | 8 +- src/solver/solverfourthorderrungekutta.cpp | 24 +- src/solver/solverfourthorderrungekutta_p.h | 8 +- src/solver/solverheun.cpp | 14 +- src/solver/solverheun_p.h | 4 +- src/solver/solverkinsol.cpp | 38 +- src/solver/solverkinsol_p.h | 18 +- src/solver/solverode_p.h | 12 +- src/solver/solverodefixedstep.cpp | 10 +- src/solver/solverodefixedstep_p.h | 4 +- src/solver/solversecondorderrungekutta.cpp | 14 +- src/solver/solversecondorderrungekutta_p.h | 2 +- src/support/cellml/cellmlfile.cpp | 10 +- src/support/cellml/cellmlfileruntime.cpp | 32 +- src/support/cellml/cellmlfileruntime_p.h | 18 +- src/support/combine/combinearchive.cpp | 20 +- src/support/sedml/sedmlfile.cpp | 64 +-- src/version.cpp | 30 +- src/version.in.h | 4 +- tests/api/file/basictests.cpp | 44 +- tests/api/file/childtests.cpp | 8 +- tests/api/file/typetests.cpp | 36 +- tests/api/sed/basictests.cpp | 86 ++-- tests/api/sed/coveragetests.cpp | 160 +++--- tests/api/sed/instancetests.cpp | 144 +++--- tests/api/sed/serialisetests.cpp | 216 ++++---- tests/api/solver/basictests.cpp | 52 +- tests/api/solver/coveragetests.cpp | 20 +- tests/api/solver/cvodetests.cpp | 486 +++++++++--------- tests/api/solver/forwardeulertests.cpp | 46 +- .../api/solver/fourthorderrungekuttatests.cpp | 46 +- tests/api/solver/heuntests.cpp | 46 +- tests/api/solver/kinsoltests.cpp | 118 ++--- tests/api/solver/odemodel.cpp | 10 +- .../api/solver/secondorderrungekuttatests.cpp | 46 +- tests/api/version/tests.cpp | 30 +- tests/install/src/main.cpp | 32 +- tests/misc/compilertests.cpp | 50 +- tests/support/cellml/runtimetests.cpp | 16 +- tests/utils.cpp | 22 +- tests/utils.in.h | 62 +-- 87 files changed, 1391 insertions(+), 1391 deletions(-) diff --git a/cmake/base64encoder.cpp b/cmake/base64encoder.cpp index 344874f85..ded91827e 100644 --- a/cmake/base64encoder.cpp +++ b/cmake/base64encoder.cpp @@ -30,8 +30,8 @@ int main(int pArgC, char *pArgV[]) return 1; } - std::uintmax_t fileSize = std::filesystem::file_size(pArgV[1]); - char *buffer = new char[fileSize]; + std::uintmax_t fileSize {std::filesystem::file_size(pArgV[1])}; + char *buffer {new char[fileSize]}; std::ifstream file(pArgV[1], std::ios::binary); file.read(buffer, fileSize); @@ -44,7 +44,7 @@ int main(int pArgC, char *pArgV[]) file.close(); - char *base64 = new char[modp_b64_encode_len(fileSize)]; + char *base64 {new char[modp_b64_encode_len(fileSize)]}; modp_b64_encode(base64, buffer, fileSize); diff --git a/extern/nanobind/src/implicit.cpp b/extern/nanobind/src/implicit.cpp index 10702a06a..dff87bddb 100644 --- a/extern/nanobind/src/implicit.cpp +++ b/extern/nanobind/src/implicit.cpp @@ -15,13 +15,13 @@ NAMESPACE_BEGIN(detail) void implicitly_convertible(const std::type_info *src, const std::type_info *dst) noexcept { - nb_internals *internals_ = internals; - type_data *t = nb_type_c2p(internals_, dst); + nb_internals *internals_ {internals}; + type_data *t {nb_type_c2p(internals_, dst)}; check(t, "nanobind::detail::implicitly_convertible(src=%s, dst=%s): " "destination type unknown!", type_name(src), type_name(dst)); lock_internals guard(internals_); - size_t size = 0; + size_t size {0}; if (t->flags & (uint32_t) type_flags::has_implicit_conversions) { while (t->implicit.cpp && t->implicit.cpp[size]) @@ -45,13 +45,13 @@ void implicitly_convertible(const std::type_info *src, void implicitly_convertible(bool (*predicate)(PyTypeObject *, PyObject *, cleanup_list *), const std::type_info *dst) noexcept { - nb_internals *internals_ = internals; - type_data *t = nb_type_c2p(internals_, dst); + nb_internals *internals_ {internals}; + type_data *t {nb_type_c2p(internals_, dst)}; check(t, "nanobind::detail::implicitly_convertible(src=, dst=%s): " "destination type unknown!", type_name(dst)); lock_internals guard(internals_); - size_t size = 0; + size_t size {0}; if (t->flags & (uint32_t) type_flags::has_implicit_conversions) { while (t->implicit.py && t->implicit.py[size]) diff --git a/src/api/libopencor/file.h b/src/api/libopencor/file.h index bdac98688..d0758c5f0 100644 --- a/src/api/libopencor/file.h +++ b/src/api/libopencor/file.h @@ -79,8 +79,8 @@ class LIBOPENCOR_EXPORT File: public Logger * Factory method to create a @ref File object: * * ``` - * auto localFile = libOpenCOR::File::create("/some/path/file.txt"); - * auto remoteFile = libOpenCOR::File::create("https://some.domain.com/file.txt"); + * auto localFile {libOpenCOR::File::create("/some/path/file.txt")}; + * auto remoteFile {libOpenCOR::File::create("https://some.domain.com/file.txt")}; * ``` * * Note: if there is already a @ref File object for the given file name or URL then we return it after having reset diff --git a/src/api/libopencor/sedanalysis.h b/src/api/libopencor/sedanalysis.h index 7bed3b0c9..323a307d2 100644 --- a/src/api/libopencor/sedanalysis.h +++ b/src/api/libopencor/sedanalysis.h @@ -50,8 +50,8 @@ class LIBOPENCOR_EXPORT SedAnalysis: public SedSimulation * Factory method to create a @ref SedAnalysis object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto simulation = libOpenCOR::SedAnalysis::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto simulation {libOpenCOR::SedAnalysis::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedAnalysis object is to belong. diff --git a/src/api/libopencor/sedchangeattribute.h b/src/api/libopencor/sedchangeattribute.h index 4b005bafa..7c6c98eff 100644 --- a/src/api/libopencor/sedchangeattribute.h +++ b/src/api/libopencor/sedchangeattribute.h @@ -50,7 +50,7 @@ class LIBOPENCOR_EXPORT SedChangeAttribute: public SedChange * Factory method to create a @ref SedChangeAttribute object: * * ``` - * auto simulation = libOpenCOR::SedChangeAttribute::create(component, variable, newValue); + * auto simulation {libOpenCOR::SedChangeAttribute::create(component, variable, newValue)}; * ``` * * @param pComponentName The name of the component, as a @c std::string, where the target is located. diff --git a/src/api/libopencor/seddocument.h b/src/api/libopencor/seddocument.h index a79daac22..128fcb96b 100644 --- a/src/api/libopencor/seddocument.h +++ b/src/api/libopencor/seddocument.h @@ -53,7 +53,7 @@ class LIBOPENCOR_EXPORT SedDocument: public Logger * Factory method to create a @ref SedDocument object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); + * auto document {libOpenCOR::SedDocument::create()}; * ``` * * @param pFile The @ref File, if any, used to initialise this @ref SedDocument object. diff --git a/src/api/libopencor/sedmodel.h b/src/api/libopencor/sedmodel.h index 8ba648c2f..b5ebda12f 100644 --- a/src/api/libopencor/sedmodel.h +++ b/src/api/libopencor/sedmodel.h @@ -53,9 +53,9 @@ class LIBOPENCOR_EXPORT SedModel: public SedBase * Factory method to create a @ref SedModel object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto file = libOpenCOR::File::create("/some/path/file.txt"); - * auto model = libOpenCOR::SedModel::create(document, file); + * auto document {libOpenCOR::SedDocument::create()}; + * auto file {libOpenCOR::File::create("/some/path/file.txt")}; + * auto model {libOpenCOR::SedModel::create(document, file)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedModel object is to belong. diff --git a/src/api/libopencor/sedonestep.h b/src/api/libopencor/sedonestep.h index b37e60bdc..2e9f08888 100644 --- a/src/api/libopencor/sedonestep.h +++ b/src/api/libopencor/sedonestep.h @@ -49,8 +49,8 @@ class LIBOPENCOR_EXPORT SedOneStep: public SedSimulation * Factory method to create a @ref SedOneStep object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto simulation = libOpenCOR::SedOneStep::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto simulation {libOpenCOR::SedOneStep::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedOneStep object is to belong. diff --git a/src/api/libopencor/sedrepeatedtask.h b/src/api/libopencor/sedrepeatedtask.h index fc51479dd..2d35e86a6 100644 --- a/src/api/libopencor/sedrepeatedtask.h +++ b/src/api/libopencor/sedrepeatedtask.h @@ -47,8 +47,8 @@ class LIBOPENCOR_EXPORT SedRepeatedTask: public SedAbstractTask * Factory method to create a @ref SedRepeatedTask object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto task = libOpenCOR::SedRepeatedTask::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto task {libOpenCOR::SedRepeatedTask::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedRepeatedTask object is to belong. diff --git a/src/api/libopencor/sedsteadystate.h b/src/api/libopencor/sedsteadystate.h index abb202313..63ab07ca9 100644 --- a/src/api/libopencor/sedsteadystate.h +++ b/src/api/libopencor/sedsteadystate.h @@ -50,8 +50,8 @@ class LIBOPENCOR_EXPORT SedSteadyState: public SedSimulation * Factory method to create a @ref SedSteadyState object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto simulation = libOpenCOR::SedSteadyState::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto simulation {libOpenCOR::SedSteadyState::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedSteadyState object is to belong. diff --git a/src/api/libopencor/sedtask.h b/src/api/libopencor/sedtask.h index f6c8114e5..ffef663fc 100644 --- a/src/api/libopencor/sedtask.h +++ b/src/api/libopencor/sedtask.h @@ -49,8 +49,8 @@ class LIBOPENCOR_EXPORT SedTask: public SedAbstractTask * Factory method to create a @ref SedTask object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto task = libOpenCOR::SedTask::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto task {libOpenCOR::SedTask::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedTask object is to belong. diff --git a/src/api/libopencor/seduniformtimecourse.h b/src/api/libopencor/seduniformtimecourse.h index e76a45522..69050bccc 100644 --- a/src/api/libopencor/seduniformtimecourse.h +++ b/src/api/libopencor/seduniformtimecourse.h @@ -50,8 +50,8 @@ class LIBOPENCOR_EXPORT SedUniformTimeCourse: public SedSimulation * Factory method to create a @ref SedUniformTimeCourse object: * * ``` - * auto document = libOpenCOR::SedDocument::create(); - * auto simulation = libOpenCOR::SedUniformTimeCourse::create(document); + * auto document {libOpenCOR::SedDocument::create()}; + * auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; * ``` * * @param pDocument The @ref SedDocument object to which the @ref SedUniformTimeCourse object is to diff --git a/src/api/libopencor/solvercvode.h b/src/api/libopencor/solvercvode.h index 4049672dc..d63b2b15f 100644 --- a/src/api/libopencor/solvercvode.h +++ b/src/api/libopencor/solvercvode.h @@ -99,7 +99,7 @@ class LIBOPENCOR_EXPORT SolverCvode: public SolverOde * Factory method to create a @ref SolverCvode object: * * ``` - * auto solver = libOpenCOR::SolverCvode::create(); + * auto solver {libOpenCOR::SolverCvode::create()}; * ``` * * @return A smart pointer to a @ref SolverCvode object. diff --git a/src/api/libopencor/solverforwardeuler.h b/src/api/libopencor/solverforwardeuler.h index 5a1b20855..2f898f08f 100644 --- a/src/api/libopencor/solverforwardeuler.h +++ b/src/api/libopencor/solverforwardeuler.h @@ -47,7 +47,7 @@ class LIBOPENCOR_EXPORT SolverForwardEuler: public SolverOdeFixedStep * Factory method to create a @ref SolverForwardEuler object: * * ``` - * auto solver = libOpenCOR::SolverForwardEuler::create(); + * auto solver {libOpenCOR::SolverForwardEuler::create()}; * ``` * * @return A smart pointer to a @ref SolverForwardEuler object. diff --git a/src/api/libopencor/solverfourthorderrungekutta.h b/src/api/libopencor/solverfourthorderrungekutta.h index f6ebbed60..db77201cc 100644 --- a/src/api/libopencor/solverfourthorderrungekutta.h +++ b/src/api/libopencor/solverfourthorderrungekutta.h @@ -47,7 +47,7 @@ class LIBOPENCOR_EXPORT SolverFourthOrderRungeKutta: public SolverOdeFixedStep * Factory method to create a @ref SolverFourthOrderRungeKutta object: * * ``` - * auto solver = libOpenCOR::SolverFourthOrderRungeKutta::create(); + * auto solver {libOpenCOR::SolverFourthOrderRungeKutta::create()}; * ``` * * @return A smart pointer to a @ref SolverFourthOrderRungeKutta object. diff --git a/src/api/libopencor/solverheun.h b/src/api/libopencor/solverheun.h index 3eecea6fd..a3146b5a6 100644 --- a/src/api/libopencor/solverheun.h +++ b/src/api/libopencor/solverheun.h @@ -47,7 +47,7 @@ class LIBOPENCOR_EXPORT SolverHeun: public SolverOdeFixedStep * Factory method to create a @ref SolverHeun object: * * ``` - * auto solver = libOpenCOR::SolverHeun::create(); + * auto solver {libOpenCOR::SolverHeun::create()}; * ``` * * @return A smart pointer to a @ref SolverHeun object. diff --git a/src/api/libopencor/solverkinsol.h b/src/api/libopencor/solverkinsol.h index b3f8351b0..13473bce3 100644 --- a/src/api/libopencor/solverkinsol.h +++ b/src/api/libopencor/solverkinsol.h @@ -62,7 +62,7 @@ class LIBOPENCOR_EXPORT SolverKinsol: public SolverNla * Factory method to create a @ref SolverKinsol object: * * ``` - * auto solver = libOpenCOR::SolverKinsol::create(); + * auto solver {libOpenCOR::SolverKinsol::create()}; * ``` * * @return A smart pointer to a @ref SolverKinsol object. diff --git a/src/api/libopencor/solversecondorderrungekutta.h b/src/api/libopencor/solversecondorderrungekutta.h index ddda02017..60454d02e 100644 --- a/src/api/libopencor/solversecondorderrungekutta.h +++ b/src/api/libopencor/solversecondorderrungekutta.h @@ -47,7 +47,7 @@ class LIBOPENCOR_EXPORT SolverSecondOrderRungeKutta: public SolverOdeFixedStep * Factory method to create a @ref SolverSecondOrderRungeKutta object: * * ``` - * auto solver = libOpenCOR::SolverSecondOrderRungeKutta::create(); + * auto solver {libOpenCOR::SolverSecondOrderRungeKutta::create()}; * ``` * * @return A smart pointer to a @ref SolverSecondOrderRungeKutta object. diff --git a/src/bindings/javascript/file.cpp b/src/bindings/javascript/file.cpp index 86f6d47e9..ead40d950 100644 --- a/src/bindings/javascript/file.cpp +++ b/src/bindings/javascript/file.cpp @@ -32,17 +32,17 @@ void fileApi() .property("fileName", &libOpenCOR::File::fileName) .property("url", &libOpenCOR::File::url) .property("path", &libOpenCOR::File::path) - .function("contents", emscripten::optional_override([](libOpenCOR::FilePtr &pThis) { - auto contents = pThis->contents(); - auto view = emscripten::typed_memory_view(contents.size(), contents.data()); - auto res = emscripten::val::global("Uint8Array").new_(contents.size()); + .function("contents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis) { + auto contents {pThis->contents()}; + auto view {emscripten::typed_memory_view(contents.size(), contents.data())}; + auto res {emscripten::val::global("Uint8Array").new_(contents.size())}; res.call("set", view); return res; })) - .function("setContents", emscripten::optional_override([](libOpenCOR::FilePtr &pThis, uintptr_t pContents, size_t pSize) { - auto contents = reinterpret_cast(pContents); + .function("setContents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis, uintptr_t pContents, size_t pSize) { + auto contents {reinterpret_cast(pContents)}; pThis->setContents(libOpenCOR::UnsignedChars(contents, contents + pSize)); })) diff --git a/src/file/file.cpp b/src/file/file.cpp index 736948135..b978cb8a2 100644 --- a/src/file/file.cpp +++ b/src/file/file.cpp @@ -27,7 +27,7 @@ File::Impl::Impl(const std::string &pFileNameOrUrl, bool pRetrieveContents) { // Check whether we are dealing with a local file or a URL. - auto [isLocalFile, fileNameOrUrl] = retrieveFileInfo(decodeUrl(pFileNameOrUrl)); + auto [isLocalFile, fileNameOrUrl] {retrieveFileInfo(decodeUrl(pFileNameOrUrl))}; if (isLocalFile) { mFilePath = stringToPath(fileNameOrUrl); @@ -40,7 +40,7 @@ File::Impl::Impl(const std::string &pFileNameOrUrl, bool pRetrieveContents) if (mFilePath.empty()) { if (pRetrieveContents) { - auto [res, filePath] = downloadFile(mUrl); + auto [res, filePath] {downloadFile(mUrl)}; if (res) { mFilePath = filePath; @@ -258,11 +258,11 @@ FilePtr File::create(const std::string &pFileNameOrUrl, bool pRetrieveContents) // Check whether the given file name or URL is already managed and if so then return it otherwise create, manage, // and return a new file object. - auto fileManager = FileManager::instance(); + auto fileManager {FileManager::instance()}; #ifdef __EMSCRIPTEN__ - auto file = fileManager.fileFromFileNameOrUrl(pFileNameOrUrl); + auto file {fileManager.fileFromFileNameOrUrl(pFileNameOrUrl)}; #else - auto file = fileManager.file(pFileNameOrUrl); + auto file {fileManager.file(pFileNameOrUrl)}; #endif if (file != nullptr) { @@ -270,9 +270,9 @@ FilePtr File::create(const std::string &pFileNameOrUrl, bool pRetrieveContents) } #ifdef __EMSCRIPTEN__ - auto res = FilePtr {new File {pFileNameOrUrl, false}}; + auto res {FilePtr {new File {pFileNameOrUrl, false}}}; #else - auto res = FilePtr {new File {pFileNameOrUrl, pRetrieveContents}}; + auto res {FilePtr {new File {pFileNameOrUrl, pRetrieveContents}}}; #endif res->pimpl()->checkType(res); diff --git a/src/file/file_p.h b/src/file/file_p.h index 79d5d7b78..dbfd69665 100644 --- a/src/file/file_p.h +++ b/src/file/file_p.h @@ -31,15 +31,15 @@ namespace libOpenCOR { class File::Impl: public Logger::Impl { public: - Type mType = Type::UNKNOWN_FILE; + Type mType {Type::UNKNOWN_FILE}; std::filesystem::path mFilePath; std::string mUrl; - bool mTypeChecked = false; + bool mTypeChecked {false}; - bool mRetrieveContents = true; - bool mContentsRetrieved = false; + bool mRetrieveContents {true}; + bool mContentsRetrieved {false}; UnsignedChars mContents; CellmlFilePtr mCellmlFile; diff --git a/src/file/filemanager.cpp b/src/file/filemanager.cpp index 89597ea65..8a3c45d43 100644 --- a/src/file/filemanager.cpp +++ b/src/file/filemanager.cpp @@ -47,7 +47,7 @@ void FileManager::Impl::unmanage(File *pFile) while (!files.empty()) { // Retrieve the file at the top of the stack. - File *file = files.top(); + auto *file {files.top()}; files.pop(); @@ -59,7 +59,7 @@ void FileManager::Impl::unmanage(File *pFile) // Unmanage the current file. - auto iter = std::ranges::find(mFiles, file); + auto iter {std::ranges::find(mFiles, file)}; if (iter != mFiles.cend()) { mFiles.erase(iter); @@ -109,17 +109,17 @@ FilePtr FileManager::Impl::file(const std::string &pFileNameOrUrl) const #endif { #if __clang_major__ < 16 - auto [tIsLocalFile, tFileNameOrUrl] = retrieveFileInfo(pFileNameOrUrl); - auto isLocalFile = tIsLocalFile; - auto fileNameOrUrl = tFileNameOrUrl; + auto [tIsLocalFile, tFileNameOrUrl] {retrieveFileInfo(pFileNameOrUrl)}; + auto isLocalFile {tIsLocalFile}; + auto fileNameOrUrl {tFileNameOrUrl}; #else - auto [isLocalFile, fileNameOrUrl] = retrieveFileInfo(pFileNameOrUrl); + auto [isLocalFile, fileNameOrUrl] {retrieveFileInfo(pFileNameOrUrl)}; #endif - auto res = std::ranges::find_if(mFiles, [&](const auto &file) { + auto res {std::ranges::find_if(mFiles, [&](const auto &file) { return isLocalFile ? file->fileName() == fileNameOrUrl : file->url() == fileNameOrUrl; - }); + })}; if (res != mFiles.end()) { return (*res)->shared_from_this(); diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index af9776cec..0b8b70b91 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -99,8 +99,8 @@ void Logger::Impl::addIssues(const LoggerPtr &pLogger) void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger) { - for (size_t i = 0; i < pLogger->issueCount(); ++i) { - auto issue = pLogger->issue(i); + for (size_t i {0}; i < pLogger->issueCount(); ++i) { + auto issue {pLogger->issue(i)}; addIssue((issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR : Issue::Type::WARNING, @@ -110,7 +110,7 @@ void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger) void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription) { - auto issue = IssuePtr {new Issue {pType, pDescription}}; + auto issue {IssuePtr {new Issue {pType, pDescription}}}; mIssues.push_back(issue); if (pType == Issue::Type::ERROR) { diff --git a/src/misc/compiler.cpp b/src/misc/compiler.cpp index ff07a31ed..fd2cff5d1 100644 --- a/src/misc/compiler.cpp +++ b/src/misc/compiler.cpp @@ -77,12 +77,12 @@ bool Compiler::Impl::compile(const std::string &pCode) // Create a diagnostics engine. - auto diagnosticOptions = llvm::IntrusiveRefCntPtr(std::make_unique()); + auto diagnosticOptions {llvm::IntrusiveRefCntPtr(std::make_unique())}; std::string diagnostics; llvm::raw_string_ostream outputStream(diagnostics); - auto diagnosticsEngine = llvm::IntrusiveRefCntPtr(std::make_unique(llvm::IntrusiveRefCntPtr(std::make_unique()), - &*diagnosticOptions, - std::make_unique(outputStream, &*diagnosticOptions).release())); + auto diagnosticsEngine {llvm::IntrusiveRefCntPtr(std::make_unique(llvm::IntrusiveRefCntPtr(std::make_unique()), + &*diagnosticOptions, + std::make_unique(outputStream, &*diagnosticOptions).release()))}; diagnosticsEngine->setWarningsAsErrors(true); @@ -94,12 +94,12 @@ bool Compiler::Impl::compile(const std::string &pCode) // Get a compilation object to which we pass some arguments. - static constexpr auto DUMMY_FILE_NAME = "dummy.c"; - static const std::vector COMPILATION_ARGUMENTS = {"clang", "-fsyntax-only", - "-O3", - "-fno-math-errno", - "-fno-stack-protector", - DUMMY_FILE_NAME}; + static constexpr auto DUMMY_FILE_NAME {"dummy.c"}; + static const std::vector COMPILATION_ARGUMENTS {{"clang", "-fsyntax-only", + "-O3", + "-fno-math-errno", + "-fno-stack-protector", + DUMMY_FILE_NAME}}; std::unique_ptr compilation(driver.BuildCompilation(COMPILATION_ARGUMENTS)); @@ -113,7 +113,7 @@ bool Compiler::Impl::compile(const std::string &pCode) // The compilation object should have one command, so if it doesn't then something went wrong. - clang::driver::JobList &jobs = compilation->getJobs(); + clang::driver::JobList &jobs {compilation->getJobs()}; #ifndef CODE_COVERAGE_ENABLED if ((jobs.size() != 1) || !llvm::isa(*jobs.begin())) { @@ -125,10 +125,10 @@ bool Compiler::Impl::compile(const std::string &pCode) // Retrieve the command and make sure that its name is "clang". - auto &command = llvm::cast(*jobs.begin()); + auto &command {llvm::cast(*jobs.begin())}; #ifndef CODE_COVERAGE_ENABLED - static constexpr auto CLANG = "clang"; + static constexpr auto CLANG {"clang"}; if (strcmp(command.getCreator().getName(), CLANG) != 0) { addError(std::string("The command name must be 'clang' while it is '").append(command.getCreator().getName()).append("'.")); @@ -140,12 +140,12 @@ bool Compiler::Impl::compile(const std::string &pCode) // Prevent the Clang driver from asking cc1 to leak memory, this by removing -disable-free from the command // arguments. - auto commandArguments = command.getArguments(); + auto commandArguments {command.getArguments()}; #ifdef CODE_COVERAGE_ENABLED commandArguments.erase(find(commandArguments, llvm::StringRef("-disable-free"))); #else - auto *commandArgument = find(commandArguments, llvm::StringRef("-disable-free")); + auto *commandArgument {find(commandArguments, llvm::StringRef("-disable-free"))}; if (commandArgument != commandArguments.end()) { commandArguments.erase(commandArgument); @@ -154,7 +154,7 @@ bool Compiler::Impl::compile(const std::string &pCode) // Create a compiler instance. - auto compilerInstance = std::make_unique(); + auto compilerInstance {std::make_unique()}; compilerInstance->setDiagnostics(diagnosticsEngine.get()); compilerInstance->setVerboseOutputStream(llvm::nulls()); @@ -178,7 +178,7 @@ bool Compiler::Impl::compile(const std::string &pCode) // Map our code to a memory buffer. - auto code = R"(// Arithmetic operators. + auto code {R"(// Arithmetic operators. extern double pow(double, double); extern double sqrt(double); @@ -212,23 +212,23 @@ extern double atanh(double); #define INFINITY (__builtin_inf()) #define NAN (__builtin_nan("")) -)" + pCode; +)" + pCode}; compilerInstance->getInvocation().getPreprocessorOpts().addRemappedFile(DUMMY_FILE_NAME, llvm::MemoryBuffer::getMemBuffer(code).release()); // Compile the given code, resulting in an LLVM bitcode module. - auto llvmContext = std::make_unique(); - auto codeGenAction = std::make_unique(llvmContext.get()); + auto llvmContext {std::make_unique()}; + auto codeGenAction {std::make_unique(llvmContext.get())}; if (!compilerInstance->ExecuteAction(*codeGenAction)) { addError("The given code could not be compiled."); - static constexpr auto ERROR = ": error: "; - static auto ERROR_LENGTH = strlen(ERROR); - static constexpr auto NOTE = ": note: "; - static auto NOTE_LENGTH = strlen(NOTE); + static constexpr auto ERROR {": error: "}; + static auto ERROR_LENGTH {strlen(ERROR)}; + static constexpr auto NOTE {": note: "}; + static auto NOTE_LENGTH {strlen(NOTE)}; std::istringstream input(diagnostics); std::string line; @@ -236,16 +236,16 @@ extern double atanh(double); std::getline(input, line); while (!input.eof()) { - std::string error = line.substr(line.find(ERROR) + ERROR_LENGTH) + ":"; + std::string error {line.substr(line.find(ERROR) + ERROR_LENGTH) + ":"}; error[0] = static_cast(std::toupper(error[0])); std::getline(input, line); - bool hasErrorDetails = false; + auto hasErrorDetails {false}; while (!input.eof()) { - const auto notePos = line.find(NOTE); + const auto notePos {line.find(NOTE)}; if (notePos != std::string::npos) { if (hasErrorDetails) { @@ -274,7 +274,7 @@ extern double atanh(double); // Retrieve the LLVM module. - auto module = codeGenAction->takeModule(); + auto module {codeGenAction->takeModule()}; #ifndef CODE_COVERAGE_ENABLED if (module == nullptr) { @@ -293,7 +293,7 @@ extern double atanh(double); // Look up the target. std::string error; - auto target = llvm::TargetRegistry::lookupTarget(module->getTargetTriple(), error); + auto target {llvm::TargetRegistry::lookupTarget(module->getTargetTriple(), error)}; if (target == nullptr) { error[0] = static_cast(tolower(error[0])); @@ -305,10 +305,10 @@ extern double atanh(double); // Create a target machine. - auto targetMachine = std::unique_ptr(target->createTargetMachine(module->getTargetTriple(), - "generic", "", - llvm::TargetOptions(), - llvm::Reloc::Static)); + auto targetMachine {std::unique_ptr(target->createTargetMachine(module->getTargetTriple(), + "generic", "", + llvm::TargetOptions(), + llvm::Reloc::Static))}; if (targetMachine == nullptr) { addError("A target machine could not be created."); @@ -344,7 +344,7 @@ extern double atanh(double); #else // Create an ORC-based JIT and keep track of it. - auto lljit = llvm::orc::LLJITBuilder().create(); + auto lljit {llvm::orc::LLJITBuilder().create()}; # ifndef CODE_COVERAGE_ENABLED if (!lljit) { @@ -358,7 +358,7 @@ extern double atanh(double); // Make sure that we can find various mathematical functions in the standard C library. - auto dynamicLibrarySearchGenerator = llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(mLljit->getDataLayout().getGlobalPrefix()); + auto dynamicLibrarySearchGenerator {llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(mLljit->getDataLayout().getGlobalPrefix())}; # ifndef CODE_COVERAGE_ENABLED if (!dynamicLibrarySearchGenerator) { @@ -372,7 +372,7 @@ extern double atanh(double); // Add our LLVM bitcode module to our ORC-based JIT. - auto threadSafeModule = llvm::orc::ThreadSafeModule(std::move(module), std::move(llvmContext)); + auto threadSafeModule {llvm::orc::ThreadSafeModule(std::move(module), std::move(llvmContext))}; # ifdef CODE_COVERAGE_ENABLED const bool res = @@ -397,9 +397,9 @@ bool Compiler::Impl::addFunction(const std::string &pName, void *pFunction) // Add the given function to our ORC-based JIT. Note that we assume that we have a valid ORC-based JIT, function // name, and function. - const bool res = !mLljit->getMainJITDylib().define(llvm::orc::absoluteSymbols({ + const bool res {!mLljit->getMainJITDylib().define(llvm::orc::absoluteSymbols({ {mLljit->mangleAndIntern(pName), llvm::JITEvaluatedSymbol(llvm::pointerToJITTargetAddress(pFunction), llvm::JITSymbolFlags::Exported)}, - })); + }))}; # ifndef CODE_COVERAGE_ENABLED if (!res) { @@ -415,7 +415,7 @@ void *Compiler::Impl::function(const std::string &pName) const // Return the address of the requested function. Note that we assume that we have a valid ORC-based JIT and function // name. - auto symbol = mLljit->lookup(pName); + auto symbol {mLljit->lookup(pName)}; if (symbol) { return reinterpret_cast(symbol->getValue()); // NOLINT diff --git a/src/misc/utils.cpp b/src/misc/utils.cpp index b400b3c2e..d90b22a22 100644 --- a/src/misc/utils.cpp +++ b/src/misc/utils.cpp @@ -63,21 +63,21 @@ void printIssues(const LoggerPtr &pLogger) void printHexDump(const UnsignedChars &pBytes) { - static constexpr auto BYTES_PER_LINE = 16; - static constexpr auto ADDRESS_WIDTH = 8; - static constexpr auto FIRST_ASCII_CHARACTER = 32; - static constexpr auto LAST_ASCII_CHARACTER = 126; + static constexpr auto BYTES_PER_LINE {16}; + static constexpr auto ADDRESS_WIDTH {8}; + static constexpr auto FIRST_ASCII_CHARACTER {32}; + static constexpr auto LAST_ASCII_CHARACTER {126}; std::cout << "---[BYTES]---[BEGIN]\n"; - for (size_t i = 0; i < pBytes.size(); i += BYTES_PER_LINE) { + for (size_t i {0}; i < pBytes.size(); i += BYTES_PER_LINE) { // Print the offset. std::cout << std::hex << std::setfill('0') << std::setw(ADDRESS_WIDTH) << i << " "; // Print hex bytes. - for (size_t j = 0; j < BYTES_PER_LINE; ++j) { + for (size_t j {0}; j < BYTES_PER_LINE; ++j) { if (i + j < pBytes.size()) { std::cout << std::hex << std::setfill('0') << std::setw(2) << static_cast(pBytes[i + j]); } else { @@ -97,10 +97,10 @@ void printHexDump(const UnsignedChars &pBytes) // Print the ASCII representation. - const size_t bytesOnThisLine = (pBytes.size() - i < BYTES_PER_LINE) ? (pBytes.size() - i) : BYTES_PER_LINE; + const size_t bytesOnThisLine {(pBytes.size() - i < BYTES_PER_LINE) ? (pBytes.size() - i) : BYTES_PER_LINE}; - for (size_t j = 0; j < bytesOnThisLine; ++j) { - auto byte = pBytes[i + j]; + for (size_t j {0}; j < bytesOnThisLine; ++j) { + auto byte {pBytes[i + j]}; if (byte >= FIRST_ASCII_CHARACTER && byte <= LAST_ASCII_CHARACTER) { std::cout << static_cast(byte); @@ -109,7 +109,7 @@ void printHexDump(const UnsignedChars &pBytes) } } - for (size_t j = bytesOnThisLine; j < BYTES_PER_LINE; ++j) { + for (size_t j {bytesOnThisLine}; j < BYTES_PER_LINE; ++j) { std::cout << " "; } @@ -126,10 +126,10 @@ void printArray(const std::string &pName, const Doubles &pDoubles) std::cout << "---[ARRAY]---[" << pName << "]---[BEGIN]\n"; if (!pDoubles.empty()) { - const auto arraySize = pDoubles.size(); - const auto indexWidth = static_cast(log10(static_cast(arraySize - 1))) + 1; + const auto arraySize {pDoubles.size()}; + const auto indexWidth {static_cast(log10(static_cast(arraySize - 1))) + 1}; - for (size_t i = 0; i < arraySize; ++i) { + for (size_t i {0}; i < arraySize; ++i) { std::cout << "[" << std::setfill('0') << std::setw(indexWidth) << i << "] " << pDoubles[i] << "\n"; } } @@ -140,7 +140,7 @@ void printArray(const std::string &pName, const Doubles &pDoubles) bool fuzzyCompare(double pNb1, double pNb2) { - static constexpr double ONE_TRILLION = 1000000000000.0; + static constexpr double ONE_TRILLION {1000000000000.0}; return std::fabs(pNb1 - pNb2) * ONE_TRILLION <= std::fmin(std::fabs(pNb1), std::fabs(pNb2)); } @@ -161,11 +161,11 @@ std::string encodeUrl(const std::string &pUrl) std::string decodeUrl(const std::string &pUrl) { - static constexpr auto BASE_16 = 16; + static constexpr auto BASE_16 {16}; std::string res; - for (size_t i = 0; i < pUrl.size(); ++i) { + for (size_t i {0}; i < pUrl.size(); ++i) { if ((pUrl[i] == '%') && (i + 2 < pUrl.size()) && (std::isxdigit(pUrl[i + 1]) != 0) && (std::isxdigit(pUrl[i + 2]) != 0)) { res += static_cast(std::stoi(pUrl.substr(i + 1, 2), nullptr, BASE_16)); @@ -181,9 +181,9 @@ std::string decodeUrl(const std::string &pUrl) #ifdef BUILDING_USING_MSVC std::string forwardSlashPath(const std::string &pPath) { - static constexpr auto BACKSLASH = "\\\\"; - static const auto BACKSLASH_REGEX = std::regex(BACKSLASH); - static constexpr auto FORWARD_SLASH = "/"; + static constexpr auto BACKSLASH {"\\\\"}; + static const auto BACKSLASH_REGEX {std::regex(BACKSLASH)}; + static constexpr auto FORWARD_SLASH {"/"}; return std::regex_replace(pPath, BACKSLASH_REGEX, FORWARD_SLASH); } @@ -196,7 +196,7 @@ std::filesystem::path stringToPath(const std::string &pString) std::string pathToString(const std::filesystem::path &pPath) { - auto path = pPath; + auto path {pPath}; #if defined(BUILDING_USING_MSVC) return std::wstring_convert>().to_bytes(path.make_preferred().wstring()); @@ -221,29 +221,29 @@ std::string canonicalFileName(const std::string &pFileName) // return "/". So, we prepend a dummy folder to pFileName and then remove it from the result of // std::filesystem::weakly_canonical(). - static constexpr auto FORWARD_SLASH = "/"; + static constexpr auto FORWARD_SLASH {"/"}; - auto fileExists = std::filesystem::exists(pFileName); - auto currentPath = std::filesystem::current_path(); + auto fileExists {std::filesystem::exists(pFileName)}; + auto currentPath {std::filesystem::current_path()}; if (!fileExists) { std::filesystem::current_path(FORWARD_SLASH); } #ifdef __EMSCRIPTEN__ - static constexpr auto DUMMY_FOLDER = "/dummy"; + static constexpr auto DUMMY_FOLDER {"/dummy"}; - auto res = pFileName; + auto res {pFileName}; res = DUMMY_FOLDER + std::string(res.starts_with(FORWARD_SLASH) ? "" : FORWARD_SLASH) + res; res = pathToString(std::filesystem::weakly_canonical(stringToPath(res))); res.erase(0, strlen(DUMMY_FOLDER)); #else - auto filePath = stringToPath(pFileName); - auto res = pathToString(fileExists ? - std::filesystem::canonical(filePath) : - std::filesystem::weakly_canonical(filePath)); + auto filePath {stringToPath(pFileName)}; + auto res {pathToString(fileExists ? + std::filesystem::canonical(filePath) : + std::filesystem::weakly_canonical(filePath))}; #endif #if defined(BUILDING_USING_MSVC) @@ -257,7 +257,7 @@ std::string canonicalFileName(const std::string &pFileName) // added (at the beginning of the file name) by std::filesystem::weakly_canonical(). if (!fileExists && !pFileName.starts_with(FORWARD_SLASH)) { - static const auto FORWARD_SLASH_LENGTH = strlen(FORWARD_SLASH); + static const auto FORWARD_SLASH_LENGTH {strlen(FORWARD_SLASH)}; res.erase(0, FORWARD_SLASH_LENGTH); } @@ -278,20 +278,20 @@ std::tuple retrieveFileInfo(const std::string &pFileNameOrUrl // Note: a URL represents a local file when used with the "file" scheme. #ifdef BUILDING_ON_WINDOWS - static constexpr auto FILE_SCHEME = "file:///"; + static constexpr auto FILE_SCHEME {"file:///"}; #else - static constexpr auto FILE_SCHEME = "file://"; + static constexpr auto FILE_SCHEME {"file://"}; #endif - static auto FILE_SCHEME_LENGTH = strlen(FILE_SCHEME); - static constexpr auto HTTP_SCHEME = "http://"; - static auto HTTP_SCHEME_LENGTH = strlen(HTTP_SCHEME); - static constexpr auto HTTPS_SCHEME = "https://"; - static auto HTTPS_SCHEME_LENGTH = strlen(HTTPS_SCHEME); + static auto FILE_SCHEME_LENGTH {strlen(FILE_SCHEME)}; + static constexpr auto HTTP_SCHEME {"http://"}; + static auto HTTP_SCHEME_LENGTH {strlen(HTTP_SCHEME)}; + static constexpr auto HTTPS_SCHEME {"https://"}; + static auto HTTPS_SCHEME_LENGTH {strlen(HTTPS_SCHEME)}; - auto res = pFileNameOrUrl; - size_t schemeLength = 0; - auto requiresHttpScheme = false; - auto requiresHttpsScheme = false; + auto res {pFileNameOrUrl}; + size_t schemeLength {0}; + auto requiresHttpScheme {false}; + auto requiresHttpsScheme {false}; if (pFileNameOrUrl.starts_with(FILE_SCHEME)) { schemeLength = FILE_SCHEME_LENGTH; @@ -322,7 +322,7 @@ namespace { std::filesystem::path canonicalPath(const std::string &pPath) { - auto [isLocalPath, path] = retrieveFileInfo(pPath); + auto [isLocalPath, path] {retrieveFileInfo(pPath)}; return stringToPath(path); } @@ -336,12 +336,12 @@ std::string relativePath(const std::string &pPath, const std::string &pBasePath) std::string urlPath(const std::string &pPath) { - auto [isLocalPath, path] = retrieveFileInfo(pPath); + auto [isLocalPath, path] {retrieveFileInfo(pPath)}; if (isLocalPath && stringToPath(path).is_absolute()) { - static const std::string FILE_SCHEME = "file://"; + static const std::string FILE_SCHEME {"file://"}; #ifdef BUILDING_USING_MSVC - static constexpr auto FORWARD_SLASH = "/"; + static constexpr auto FORWARD_SLASH {"/"}; return FILE_SCHEME + FORWARD_SLASH + forwardSlashPath(path); #else @@ -365,8 +365,8 @@ void getTimeOfDay(TimeVal &pTimeVal) { // Based off https://stackoverflow.com/a/58162122. - const auto duration = std::chrono::system_clock::now().time_since_epoch(); - const auto seconds = std::chrono::duration_cast(duration); + const auto duration {std::chrono::system_clock::now().time_since_epoch()}; + const auto seconds {std::chrono::duration_cast(duration)}; pTimeVal.seconds = static_cast(seconds.count()); pTimeVal.microeconds = static_cast(std::chrono::duration_cast(duration - seconds).count()); @@ -383,30 +383,30 @@ std::filesystem::path uniqueFilePath() // Note: ATTEMPTS_MIN is equal to 62x62x62 where 62 is the number of characters in LETTERS. # ifndef CODE_COVERAGE_ENABLED - static constexpr uint64_t ATTEMPTS_MIN = 238328U; - static constexpr uint64_t MAX_ATTEMPTS = (ATTEMPTS_MIN < TMP_MAX) ? TMP_MAX : ATTEMPTS_MIN; + static constexpr uint64_t ATTEMPTS_MIN {238328U}; + static constexpr uint64_t MAX_ATTEMPTS {(ATTEMPTS_MIN < TMP_MAX) ? TMP_MAX : ATTEMPTS_MIN}; # endif // Get some more or less random data. - static const std::string LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - static const uint64_t LETTERS_SIZE = LETTERS.size(); + static const std::string LETTERS {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}; + static const uint64_t LETTERS_SIZE {LETTERS.size()}; - static auto testFile = pathToString(std::filesystem::temp_directory_path() / "libOpenCOR_XXXXXX.tmp"); + static auto testFile {pathToString(std::filesystem::temp_directory_path() / "libOpenCOR_XXXXXX.tmp")}; - static const size_t XXXXXX_POS = testFile.size() - 6 - 4; - static constexpr uint64_t MICROSECONDS_SHIFT = 16U; - static constexpr uint64_t PID_SHIFT = 32U; + static const size_t XXXXXX_POS {testFile.size() - 6 - 4}; + static constexpr uint64_t MICROSECONDS_SHIFT {16U}; + static constexpr uint64_t PID_SHIFT {32U}; # ifndef CODE_COVERAGE_ENABLED - static constexpr uint64_t VALUE_SHIFT = 7777U; + static constexpr uint64_t VALUE_SHIFT {7777U}; # endif - static constexpr uint64_t XXXXXX_POS_SHIFT = 6U; + static constexpr uint64_t XXXXXX_POS_SHIFT {6U}; TimeVal timeVal; getTimeOfDay(timeVal); - auto value = (timeVal.microeconds << MICROSECONDS_SHIFT) ^ timeVal.seconds; + auto value {(timeVal.microeconds << MICROSECONDS_SHIFT) ^ timeVal.seconds}; # ifdef BUILDING_USING_MSVC value ^= static_cast(_getpid()) << PID_SHIFT; @@ -417,11 +417,11 @@ std::filesystem::path uniqueFilePath() std::string res; # ifndef CODE_COVERAGE_ENABLED - for (uint64_t attempt = 0; attempt < MAX_ATTEMPTS; value += VALUE_SHIFT, ++attempt) { + for (uint64_t attempt {0}; attempt < MAX_ATTEMPTS; value += VALUE_SHIFT, ++attempt) { # endif - uint64_t val = value; + uint64_t val {value}; - for (uint64_t i = 0; i < XXXXXX_POS_SHIFT; ++i) { + for (uint64_t i {0}; i < XXXXXX_POS_SHIFT; ++i) { testFile[XXXXXX_POS + i] = LETTERS[val % LETTERS_SIZE]; val /= LETTERS_SIZE; } @@ -442,7 +442,7 @@ std::filesystem::path uniqueFilePath() size_t curlWriteFunction(char *pData, size_t pSize, size_t pDataSize, void *pUserData) { - const auto realDataSize = pSize * pDataSize; + const auto realDataSize {pSize * pDataSize}; static_cast(pUserData)->write(pData, static_cast(realDataSize)); @@ -453,7 +453,7 @@ size_t curlWriteFunction(char *pData, size_t pSize, size_t pDataSize, void *pUse std::tuple downloadFile(const std::string &pUrl) { - auto filePath = uniqueFilePath(); + auto filePath {uniqueFilePath()}; std::ofstream file(filePath, std::ios_base::binary); # ifndef CODE_COVERAGE_ENABLED @@ -464,8 +464,8 @@ std::tuple downloadFile(const std::string &pUrl) curl_global_init(CURL_GLOBAL_DEFAULT); - auto res = false; - auto *curl = curl_easy_init(); + auto res {false}; + auto *curl {curl_easy_init()}; curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); @@ -474,9 +474,9 @@ std::tuple downloadFile(const std::string &pUrl) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteFunction); if (curl_easy_perform(curl) == CURLE_OK) { - static constexpr int64_t HTTP_OK = 200; + static constexpr int64_t HTTP_OK {200}; - int64_t responseCode = 0; + int64_t responseCode {0}; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode); @@ -507,7 +507,7 @@ UnsignedChars fileContents(const std::filesystem::path &pFilePath) return {}; } - const auto fileSize = std::filesystem::file_size(pFilePath); + const auto fileSize {std::filesystem::file_size(pFilePath)}; UnsignedChars contents(fileSize); file.read(reinterpret_cast(&contents[0]), static_cast(fileSize)); // NOLINT @@ -537,11 +537,11 @@ std::string toString(bool pBoolean) bool isInt(const std::string &pString) { - static const auto INT_REGEX = std::regex("^([-+]?[1-9][0-9]*([eE][+]?[0-9]+)?|0)$"); + static const auto INT_REGEX {std::regex("^([-+]?[1-9][0-9]*([eE][+]?[0-9]+)?|0)$")}; if (std::regex_match(pString, INT_REGEX)) { std::istringstream iss(pString); - int res = 0; + int res {0}; iss >> res; @@ -554,7 +554,7 @@ bool isInt(const std::string &pString) int toInt(const std::string &pString) { std::istringstream iss(pString); - int res = 0; + int res {0}; iss >> res; @@ -581,7 +581,7 @@ std::string toString(size_t pNumber) bool isDouble(const std::string &pString) { - static const auto DOUBLE_REGEX = std::regex("^[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)?$"); + static const auto DOUBLE_REGEX {std::regex("^[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)?$")}; return std::regex_match(pString, DOUBLE_REGEX); } @@ -593,7 +593,7 @@ double toDouble(const std::string &pString) } std::istringstream iss(pString); - double res = NAN; + double res {NAN}; iss >> res; diff --git a/src/misc/utils.h b/src/misc/utils.h index 816031073..b31263da7 100644 --- a/src/misc/utils.h +++ b/src/misc/utils.h @@ -36,9 +36,9 @@ limitations under the License. namespace libOpenCOR { -static const std::string LIBOPENCOR_NAMESPACE = "https://opencor.ws/libopencor"; +static const std::string LIBOPENCOR_NAMESPACE {"https://opencor.ws/libopencor"}; -static const auto NAN = std::numeric_limits::quiet_NaN(); +static const auto NAN {std::numeric_limits::quiet_NaN()}; using StringStringMap = std::map; diff --git a/src/sed/sedabstracttask.cpp b/src/sed/sedabstracttask.cpp index a48328127..d02dacf82 100644 --- a/src/sed/sedabstracttask.cpp +++ b/src/sed/sedabstracttask.cpp @@ -19,7 +19,7 @@ limitations under the License. namespace libOpenCOR { -static constexpr auto ID_PREFIX = "task"; +static constexpr auto ID_PREFIX {"task"}; SedAbstractTask::Impl::Impl(const SedDocumentPtr &pDocument) : SedBase::Impl(pDocument->pimpl()->uniqueId(ID_PREFIX)) diff --git a/src/sed/sedanalysis.cpp b/src/sed/sedanalysis.cpp index f244e416e..f7637c224 100644 --- a/src/sed/sedanalysis.cpp +++ b/src/sed/sedanalysis.cpp @@ -27,7 +27,7 @@ SedAnalysis::Impl::Impl(const SedDocumentPtr &pDocument) void SedAnalysis::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("analysis")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("analysis"))}; SedSimulation::Impl::serialise(node); diff --git a/src/sed/sedchangeattribute.cpp b/src/sed/sedchangeattribute.cpp index d7569caaa..9b969b0b3 100644 --- a/src/sed/sedchangeattribute.cpp +++ b/src/sed/sedchangeattribute.cpp @@ -76,7 +76,7 @@ void SedChangeAttribute::Impl::setNewValue(const std::string &pNewValue) void SedChangeAttribute::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("changeAttribute")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("changeAttribute"))}; SedChange::Impl::serialise(node); @@ -88,21 +88,21 @@ void SedChangeAttribute::Impl::serialise(xmlNodePtr pNode) const void SedChangeAttribute::Impl::apply(const SedInstanceTaskPtr &pInstanceTask, const libcellml::AnalyserModelPtr &pAnalyserModel) { - auto *instanceTaskPimpl = pInstanceTask->pimpl(); - auto changeName = name(mComponentName, mVariableName); + auto *instanceTaskPimpl {pInstanceTask->pimpl()}; + auto changeName {name(mComponentName, mVariableName)}; if (instanceTaskPimpl->voiName() == changeName) { - auto voiVariable = pAnalyserModel->voi()->variable(); - auto voiComponent = owningComponent(voiVariable); + auto voiVariable {pAnalyserModel->voi()->variable()}; + auto voiComponent {owningComponent(voiVariable)}; addWarning(std::string("The variable of integration '").append(voiVariable->name()).append("' in component '").append(voiComponent->name()).append("'cannot be changed. Only state variables and constants can be changed.")); return; } - auto isParameterSet = false; + auto isParameterSet {false}; - for (size_t i = 0; i < pAnalyserModel->stateCount(); ++i) { + for (size_t i {0}; i < pAnalyserModel->stateCount(); ++i) { if (instanceTaskPimpl->stateName(i) == changeName) { instanceTaskPimpl->mStates[i] = toDouble(newValue()); // NOLINT @@ -113,7 +113,7 @@ void SedChangeAttribute::Impl::apply(const SedInstanceTaskPtr &pInstanceTask, } if (!isParameterSet) { - for (size_t i = 0; i < pAnalyserModel->constantCount(); ++i) { + for (size_t i {0}; i < pAnalyserModel->constantCount(); ++i) { if (instanceTaskPimpl->constantName(i) == changeName) { instanceTaskPimpl->mConstants[i] = toDouble(newValue()); // NOLINT @@ -125,10 +125,10 @@ void SedChangeAttribute::Impl::apply(const SedInstanceTaskPtr &pInstanceTask, } if (!isParameterSet) { - for (size_t i = 0; i < pAnalyserModel->computedConstantCount(); ++i) { + for (size_t i {0}; i < pAnalyserModel->computedConstantCount(); ++i) { if (instanceTaskPimpl->computedConstantName(i) == changeName) { - auto computedConstantVariable = pAnalyserModel->computedConstants()[i]->variable(); - auto computedConstantComponent = owningComponent(computedConstantVariable); + auto computedConstantVariable {pAnalyserModel->computedConstants()[i]->variable()}; + auto computedConstantComponent {owningComponent(computedConstantVariable)}; addWarning(std::string("The computed constant '").append(computedConstantVariable->name()).append("' in component '").append(computedConstantComponent->name()).append("' cannot be changed. Only state variables and constants can be changed.")); @@ -140,10 +140,10 @@ void SedChangeAttribute::Impl::apply(const SedInstanceTaskPtr &pInstanceTask, } if (!isParameterSet) { - for (size_t i = 0; i < pAnalyserModel->algebraicCount(); ++i) { + for (size_t i {0}; i < pAnalyserModel->algebraicCount(); ++i) { if (instanceTaskPimpl->algebraicName(i) == changeName) { - auto algebraicVariable = pAnalyserModel->algebraic()[i]->variable(); - auto algebraicComponent = owningComponent(algebraicVariable); + auto algebraicVariable {pAnalyserModel->algebraic()[i]->variable()}; + auto algebraicComponent {owningComponent(algebraicVariable)}; addWarning(std::string("The algebraic variable '").append(algebraicVariable->name()).append("' in component '").append(algebraicComponent->name()).append("' cannot be changed. Only state variables and constants can be changed.")); diff --git a/src/sed/seddocument.cpp b/src/sed/seddocument.cpp index 6d6eb8efd..c6ce98c96 100644 --- a/src/sed/seddocument.cpp +++ b/src/sed/seddocument.cpp @@ -30,12 +30,12 @@ namespace libOpenCOR { std::string SedDocument::Impl::uniqueId(const std::string &pPrefix) { - size_t counter = 0; + size_t counter {0}; std::stringstream stream; stream << pPrefix << ++counter; - auto res = stream.str(); + auto res {stream.str()}; while (mIds.contains(res)) { stream.str({}); @@ -63,7 +63,7 @@ void SedDocument::Impl::initialise(const SedDocumentPtr &pOwner, const FilePtr & // for __EMSCRIPTEN__. Could it be an issue with llvm-cov not properly handling C++ directives within a switch // statement? - auto fileType = pFile->type(); + auto fileType {pFile->type()}; if (fileType == File::Type::CELLML_FILE) { initialiseFromCellmlFile(pOwner, pFile); @@ -87,7 +87,7 @@ void SedDocument::Impl::initialiseFromCellmlFile(const SedDocumentPtr &pOwner, c void SedDocument::Impl::initialiseFromSedmlFile(const SedDocumentPtr &pOwner, const FilePtr &pFile) { - auto sedmlFile = pFile->pimpl()->mSedmlFile; + auto sedmlFile {pFile->pimpl()->mSedmlFile}; sedmlFile->populateDocument(pOwner); @@ -96,12 +96,12 @@ void SedDocument::Impl::initialiseFromSedmlFile(const SedDocumentPtr &pOwner, co void SedDocument::Impl::initialiseFromCombineArchive(const SedDocumentPtr &pOwner, const FilePtr &pFile) { - auto masterFile = pFile->pimpl()->mCombineArchive->masterFile(); + auto masterFile {pFile->pimpl()->mCombineArchive->masterFile()}; if (masterFile == nullptr) { addError("A simulation experiment description cannot be created using a COMBINE archive with no master file."); } else { - auto masterFileType = masterFile->type(); + auto masterFileType {masterFile->type()}; if (masterFileType == File::Type::CELLML_FILE) { initialiseFromCellmlFile(pOwner, masterFile); @@ -124,8 +124,8 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const { // Serialise our SED-ML document. - auto *doc = xmlNewDoc(toConstXmlCharPtr("1.0")); - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("sedML")); + auto *doc {xmlNewDoc(toConstXmlCharPtr("1.0"))}; + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("sedML"))}; serialise(node); @@ -135,7 +135,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const /*---GRY--- if (!mDataDescriptions.empty()) { - auto *sedListOfDataDescriptions = xmlNewNode(nullptr, toConstXmlCharPtr("listOfDataDescriptions")); + auto *sedListOfDataDescriptions {xmlNewNode(nullptr, toConstXmlCharPtr("listOfDataDescriptions"))}; xmlAddChild(node, sedListOfDataDescriptions); @@ -148,7 +148,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const // Add the models, if any, to our SED-ML document. if (!mModels.empty()) { - auto *sedListOfModels = xmlNewNode(nullptr, toConstXmlCharPtr("listOfModels")); + auto *sedListOfModels {xmlNewNode(nullptr, toConstXmlCharPtr("listOfModels"))}; xmlAddChild(node, sedListOfModels); @@ -161,7 +161,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const // Add the simulations, if any, to our SED-ML document. if (!mSimulations.empty()) { - auto *sedListOfSimulations = xmlNewNode(nullptr, toConstXmlCharPtr("listOfSimulations")); + auto *sedListOfSimulations {xmlNewNode(nullptr, toConstXmlCharPtr("listOfSimulations"))}; for (const auto &simulation : mSimulations) { simulation->pimpl()->serialise(sedListOfSimulations); @@ -173,7 +173,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const // Add the tasks, if any, to our SED-ML document. if (!mTasks.empty()) { - auto *sedListOfTasks = xmlNewNode(nullptr, toConstXmlCharPtr("listOfTasks")); + auto *sedListOfTasks {xmlNewNode(nullptr, toConstXmlCharPtr("listOfTasks"))}; for (const auto &task : mTasks) { task->pimpl()->serialise(sedListOfTasks); @@ -186,7 +186,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const /*---GRY--- if (!mDataGenerators.empty()) { - auto *sedListOfDataGenerators = xmlNewNode(nullptr, toConstXmlCharPtr("listOfDataGenerators")); + auto *sedListOfDataGenerators {xmlNewNode(nullptr, toConstXmlCharPtr("listOfDataGenerators"))}; for (const auto &dataGenerator : mDataGenerators) { dataGenerator->pimpl()->serialise(sedListOfDataGenerators); @@ -200,7 +200,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const /*---GRY--- if (!mOutputs.empty()) { - auto *sedListOfOutputs = xmlNewNode(nullptr, toConstXmlCharPtr("listOfOutputs")); + auto *sedListOfOutputs {xmlNewNode(nullptr, toConstXmlCharPtr("listOfOutputs"))}; for (const auto &output : mOutputs) { output->pimpl()->serialise(sedListOfOutputs); @@ -214,7 +214,7 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const /*---GRY--- if (!mStyles.empty()) { - auto *sedListOfStyles = xmlNewNode(nullptr, toConstXmlCharPtr("listOfStyles")); + auto *sedListOfStyles {xmlNewNode(nullptr, toConstXmlCharPtr("listOfStyles"))}; for (const auto &style : mStyles) { style->pimpl()->serialise(sedListOfStyles); @@ -226,8 +226,8 @@ std::string SedDocument::Impl::serialise(const std::string &pBasePath) const // Convert our SED-ML document to a string and return it. - xmlChar *buffer = nullptr; - int size = 0; + xmlChar *buffer {nullptr}; + int size {0}; xmlDocDumpFormatMemoryEnc(doc, &buffer, &size, "UTF-8", 1); @@ -271,9 +271,9 @@ bool SedDocument::Impl::addModel(const SedModelPtr &pModel) return false; } - auto model = std::ranges::find_if(mModels, [&](const auto &m) { + auto model {std::ranges::find_if(mModels, [&](const auto &m) { return m == pModel; - }); + })}; if (model != mModels.end()) { return false; @@ -286,9 +286,9 @@ bool SedDocument::Impl::addModel(const SedModelPtr &pModel) bool SedDocument::Impl::removeModel(const SedModelPtr &pModel) { - auto model = std::ranges::find_if(mModels, [&](const auto &m) { + auto model {std::ranges::find_if(mModels, [&](const auto &m) { return m == pModel; - }); + })}; if (model != mModels.end()) { mIds.erase((*model)->pimpl()->mId); @@ -343,9 +343,9 @@ bool SedDocument::Impl::addSimulation(const SedSimulationPtr &pSimulation) return false; } - auto simulation = std::ranges::find_if(mSimulations, [&](const auto &s) { + auto simulation {std::ranges::find_if(mSimulations, [&](const auto &s) { return s == pSimulation; - }); + })}; if (simulation != mSimulations.end()) { return false; @@ -358,9 +358,9 @@ bool SedDocument::Impl::addSimulation(const SedSimulationPtr &pSimulation) bool SedDocument::Impl::removeSimulation(const SedSimulationPtr &pSimulation) { - auto simulation = std::ranges::find_if(mSimulations, [&](const auto &s) { + auto simulation {std::ranges::find_if(mSimulations, [&](const auto &s) { return s == pSimulation; - }); + })}; if (simulation != mSimulations.end()) { mIds.erase((*simulation)->pimpl()->mId); @@ -415,9 +415,9 @@ bool SedDocument::Impl::addTask(const SedAbstractTaskPtr &pTask) return false; } - auto task = std::ranges::find_if(mTasks, [&](const auto &t) { + auto task {std::ranges::find_if(mTasks, [&](const auto &t) { return t == pTask; - }); + })}; if (task != mTasks.end()) { return false; @@ -430,9 +430,9 @@ bool SedDocument::Impl::addTask(const SedAbstractTaskPtr &pTask) bool SedDocument::Impl::removeTask(const SedAbstractTaskPtr &pTask) { - auto task = std::ranges::find_if(mTasks, [&](const auto &t) { + auto task {std::ranges::find_if(mTasks, [&](const auto &t) { return t == pTask; - }); + })}; if (task != mTasks.end()) { mIds.erase((*task)->pimpl()->mId); @@ -479,7 +479,7 @@ const SedDocument::Impl *SedDocument::pimpl() const SedDocumentPtr SedDocument::create(const FilePtr &pFile) { - auto res = SedDocumentPtr {new SedDocument {}}; + auto res {SedDocumentPtr {new SedDocument {}}}; res->pimpl()->initialise(res, pFile); diff --git a/src/sed/seddocument_p.h b/src/sed/seddocument_p.h index bc273cdfb..fe8b355fb 100644 --- a/src/sed/seddocument_p.h +++ b/src/sed/seddocument_p.h @@ -27,9 +27,9 @@ namespace libOpenCOR { class SedDocument::Impl: public Logger::Impl { public: - std::string mXmlns = "http://sed-ml.org/sed-ml/level1/version4"; - size_t mLevel = 1; - size_t mVersion = 4; + std::string mXmlns {"http://sed-ml.org/sed-ml/level1/version4"}; + size_t mLevel {1}; + size_t mVersion {4}; std::unordered_set mIds; diff --git a/src/sed/sedinstance.cpp b/src/sed/sedinstance.cpp index 146297f36..1fd5e5cf1 100644 --- a/src/sed/sedinstance.cpp +++ b/src/sed/sedinstance.cpp @@ -37,11 +37,11 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument) if (pDocument->hasTasks()) { // Make sure that all the tasks are valid. - auto tasks = pDocument->tasks(); - auto tasksValid = true; + auto tasks {pDocument->tasks()}; + auto tasksValid {true}; for (const auto &task : tasks) { - auto *taskPimpl = task->pimpl(); + auto *taskPimpl {task->pimpl()}; taskPimpl->removeAllIssues(); @@ -58,7 +58,7 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument) if (tasksValid) { for (const auto &task : tasks) { - auto taskInstance = SedInstanceTask::Impl::create(task); + auto taskInstance {SedInstanceTask::Impl::create(task)}; mTasks.push_back(taskInstance); @@ -86,7 +86,7 @@ double SedInstance::Impl::run() // Run all the tasks associated with this instance unless they have some issues. - auto res = 0.0; + auto res {0.0}; for (const auto &task : mTasks) { if (!task->hasIssues()) { diff --git a/src/sed/sedinstancetask.cpp b/src/sed/sedinstancetask.cpp index 2c551f755..c7540bffc 100644 --- a/src/sed/sedinstancetask.cpp +++ b/src/sed/sedinstancetask.cpp @@ -27,7 +27,7 @@ namespace libOpenCOR { SedInstanceTaskPtr SedInstanceTask::Impl::create(const SedAbstractTaskPtr &pTask) { - auto res = SedInstanceTaskPtr {new SedInstanceTask {pTask}}; + auto res {SedInstanceTaskPtr {new SedInstanceTask {pTask}}}; res->pimpl()->mOwner = res; @@ -49,7 +49,7 @@ SedInstanceTask::Impl::Impl(const SedAbstractTaskPtr &pTask) //---GRY--- AT THIS STAGE, WE ONLY SUPPORT SedTask TASKS, HENCE WE ASSERT (FOR NOW) THAT pTask IS INDEED A SedTask // OBJECT. - auto task = std::dynamic_pointer_cast(pTask); + auto task {std::dynamic_pointer_cast(pTask)}; ASSERT_NE(task, nullptr); @@ -57,15 +57,15 @@ SedInstanceTask::Impl::Impl(const SedAbstractTaskPtr &pTask) mModel = task->pimpl()->mModel; - auto cellmlFile = mModel->pimpl()->mFile->pimpl()->mCellmlFile; - auto cellmlFileType = cellmlFile->type(); + auto cellmlFile {mModel->pimpl()->mFile->pimpl()->mCellmlFile}; + auto cellmlFileType {cellmlFile->type()}; mDifferentialModel = (cellmlFileType == libcellml::AnalyserModel::Type::ODE) || (cellmlFileType == libcellml::AnalyserModel::Type::DAE); mSimulation = task->pimpl()->mSimulation; - auto odeSolver = mSimulation->odeSolver(); - auto nlaSolver = mSimulation->nlaSolver(); + auto odeSolver {mSimulation->odeSolver()}; + auto nlaSolver {mSimulation->nlaSolver()}; mOdeSolver = (odeSolver != nullptr) ? std::dynamic_pointer_cast(odeSolver->pimpl()->duplicate()) : nullptr; mNlaSolver = (nlaSolver != nullptr) ? std::dynamic_pointer_cast(nlaSolver->pimpl()->duplicate()) : nullptr; @@ -111,20 +111,20 @@ void SedInstanceTask::Impl::trackResults(size_t pIndex) { mResults.voi[pIndex] = mVoi; - for (size_t i = 0; i < mAnalyserModel->stateCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->stateCount(); ++i) { mResults.states[i][pIndex] = mStates[i]; // NOLINT mResults.rates[i][pIndex] = mRates[i]; // NOLINT } - for (size_t i = 0; i < mAnalyserModel->constantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->constantCount(); ++i) { mResults.constants[i][pIndex] = mConstants[i]; // NOLINT } - for (size_t i = 0; i < mAnalyserModel->computedConstantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->computedConstantCount(); ++i) { mResults.computedConstants[i][pIndex] = mComputedConstants[i]; // NOLINT } - for (size_t i = 0; i < mAnalyserModel->algebraicCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->algebraicCount(); ++i) { mResults.algebraic[i][pIndex] = mAlgebraic[i]; // NOLINT } } @@ -133,9 +133,9 @@ void SedInstanceTask::Impl::applyChanges() { for (const auto &change : mModel->changes()) { //---GRY--- AT THIS STAGE, WE ONLY SUPPORT ChangeAttribute CHANGES, HENCE WE ASSERT (FOR NOW) THAT change IS - // INDEED A SedChnageAttribute OBJECT. + // INDEED A SedChangeAttribute OBJECT. - auto changeAttribute = std::dynamic_pointer_cast(change); + auto changeAttribute {std::dynamic_pointer_cast(change)}; ASSERT_NE(changeAttribute, nullptr); @@ -216,7 +216,7 @@ double SedInstanceTask::Impl::run() { // Start our timer. - auto startTime = std::chrono::high_resolution_clock::now(); + auto startTime {std::chrono::high_resolution_clock::now()}; // (Re)initialise our model. // Note: reinitialise our model because we initialised it when we created the instance task. @@ -228,39 +228,39 @@ double SedInstanceTask::Impl::run() if (mDifferentialModel) { // Initialise our results structure. - auto resultsSize = static_cast(mSedUniformTimeCourse->pimpl()->mNumberOfSteps) + 1; + auto resultsSize {static_cast(mSedUniformTimeCourse->pimpl()->mNumberOfSteps) + 1}; mResults.voi.resize(resultsSize, NAN); - for (size_t i = 0; i < mAnalyserModel->stateCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->stateCount(); ++i) { mResults.states[i].resize(resultsSize, NAN); mResults.rates[i].resize(resultsSize, NAN); } - for (size_t i = 0; i < mAnalyserModel->constantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->constantCount(); ++i) { mResults.constants[i].resize(resultsSize, NAN); } - for (size_t i = 0; i < mAnalyserModel->computedConstantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->computedConstantCount(); ++i) { mResults.computedConstants[i].resize(resultsSize, NAN); } - for (size_t i = 0; i < mAnalyserModel->algebraicCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->algebraicCount(); ++i) { mResults.algebraic[i].resize(resultsSize, NAN); } // Track our initial results. - size_t index = 0; + size_t index {0}; trackResults(index); // Compute the differential model. - auto voiStart = mVoi; - auto voiEnd = mSedUniformTimeCourse->pimpl()->mOutputEndTime; - auto voiInterval = (voiEnd - mVoi) / mSedUniformTimeCourse->pimpl()->mNumberOfSteps; - size_t voiCounter = 0; + auto voiStart {mVoi}; + auto voiEnd {mSedUniformTimeCourse->pimpl()->mOutputEndTime}; + auto voiInterval {(voiEnd - mVoi) / mSedUniformTimeCourse->pimpl()->mNumberOfSteps}; + size_t voiCounter {0}; while (!fuzzyCompare(mVoi, voiEnd)) { if (!mOdeSolver->pimpl()->solve(mVoi, std::min(voiStart + static_cast(++voiCounter) * voiInterval, voiEnd))) { @@ -294,15 +294,15 @@ double SedInstanceTask::Impl::run() } else { // Track our results. - for (size_t i = 0; i < mAnalyserModel->constantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->constantCount(); ++i) { mResults.constants[i].resize(1, mConstants[i]); // NOLINT } - for (size_t i = 0; i < mAnalyserModel->computedConstantCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->computedConstantCount(); ++i) { mResults.computedConstants[i].resize(1, mComputedConstants[i]); // NOLINT } - for (size_t i = 0; i < mAnalyserModel->algebraicCount(); ++i) { + for (size_t i {0}; i < mAnalyserModel->algebraicCount(); ++i) { mResults.algebraic[i].resize(1, mAlgebraic[i]); // NOLINT } } diff --git a/src/sed/sedinstancetask_p.h b/src/sed/sedinstancetask_p.h index ac41b223e..5e547624b 100644 --- a/src/sed/sedinstancetask_p.h +++ b/src/sed/sedinstancetask_p.h @@ -50,12 +50,12 @@ class SedInstanceTask::Impl: public Logger::Impl SolverOdePtr mOdeSolver; SolverNlaPtr mNlaSolver; - double mVoi = 0.0; - double *mStates = nullptr; - double *mRates = nullptr; - double *mConstants = nullptr; - double *mComputedConstants = nullptr; - double *mAlgebraic = nullptr; + double mVoi {0.0}; + double *mStates {nullptr}; + double *mRates {nullptr}; + double *mConstants {nullptr}; + double *mComputedConstants {nullptr}; + double *mAlgebraic {nullptr}; Doubles mStateDoubles; Doubles mRateDoubles; diff --git a/src/sed/sedmodel.cpp b/src/sed/sedmodel.cpp index a724369e3..33b7cd916 100644 --- a/src/sed/sedmodel.cpp +++ b/src/sed/sedmodel.cpp @@ -25,7 +25,7 @@ limitations under the License. namespace libOpenCOR { -static constexpr auto ID_PREFIX = "model"; +static constexpr auto ID_PREFIX {"model"}; SedModel::Impl::Impl(const SedDocumentPtr &pDocument, const FilePtr &pFile) : SedBase::Impl(pDocument->pimpl()->uniqueId(ID_PREFIX)) @@ -100,9 +100,9 @@ bool SedModel::Impl::addChange(const SedChangePtr &pChange) return false; } - auto change = std::ranges::find_if(mChanges, [&](const auto &c) { + auto change {std::ranges::find_if(mChanges, [&](const auto &c) { return c == pChange; - }); + })}; if (change != mChanges.end()) { return false; @@ -115,9 +115,9 @@ bool SedModel::Impl::addChange(const SedChangePtr &pChange) bool SedModel::Impl::removeChange(const SedChangePtr &pChange) { - auto change = std::ranges::find_if(mChanges, [&](const auto &c) { + auto change {std::ranges::find_if(mChanges, [&](const auto &c) { return c == pChange; - }); + })}; if (change != mChanges.end()) { mChanges.erase(change); @@ -148,18 +148,18 @@ void SedModel::Impl::setBasePath(const std::string &pBasePath) void SedModel::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("model")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("model"))}; SedBase::Impl::serialise(node); xmlNewProp(node, toConstXmlCharPtr("language"), toConstXmlCharPtr("urn:sedml:language:cellml")); - auto source = mBasePath.empty() ? - urlPath(mFile->path()) : + auto source {mBasePath.empty() ? + urlPath(mFile->path()) : #ifdef BUILDING_USING_MSVC - forwardSlashPath(relativePath(mFile->path(), mBasePath)); + forwardSlashPath(relativePath(mFile->path(), mBasePath))}; #else - relativePath(mFile->path(), mBasePath); + relativePath(mFile->path(), mBasePath)}; #endif xmlNewProp(node, toConstXmlCharPtr("source"), toConstXmlCharPtr(source)); @@ -169,7 +169,7 @@ void SedModel::Impl::serialise(xmlNodePtr pNode) const // Add the changes, if any, to our SED-ML model. if (!mChanges.empty()) { - auto *sedListOfChangeNodes = xmlNewNode(nullptr, toConstXmlCharPtr("listOfChanges")); + auto *sedListOfChangeNodes {xmlNewNode(nullptr, toConstXmlCharPtr("listOfChanges"))}; xmlAddChild(node, sedListOfChangeNodes); diff --git a/src/sed/sedonestep.cpp b/src/sed/sedonestep.cpp index 8199d61d2..1dc15fd14 100644 --- a/src/sed/sedonestep.cpp +++ b/src/sed/sedonestep.cpp @@ -37,7 +37,7 @@ void SedOneStep::Impl::setStep(double pStep) void SedOneStep::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("oneStep")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("oneStep"))}; SedSimulation::Impl::serialise(node); diff --git a/src/sed/sedonestep_p.h b/src/sed/sedonestep_p.h index 5a4984684..2c93fb916 100644 --- a/src/sed/sedonestep_p.h +++ b/src/sed/sedonestep_p.h @@ -25,7 +25,7 @@ namespace libOpenCOR { class SedOneStep::Impl: public SedSimulation::Impl { public: - double mStep = 1.0; + double mStep {1.0}; explicit Impl(const SedDocumentPtr &pDocument); diff --git a/src/sed/sedrepeatedtask.cpp b/src/sed/sedrepeatedtask.cpp index 534ca1905..76309d31b 100644 --- a/src/sed/sedrepeatedtask.cpp +++ b/src/sed/sedrepeatedtask.cpp @@ -35,7 +35,7 @@ bool SedRepeatedTask::Impl::isValid() /*---GRY--- void SedRepeatedTask::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("repeatedTask")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("repeatedTask"))}; SedAbstractTask::Impl::serialise(node); diff --git a/src/sed/sedsimulation.cpp b/src/sed/sedsimulation.cpp index 6792c5957..7a45906f2 100644 --- a/src/sed/sedsimulation.cpp +++ b/src/sed/sedsimulation.cpp @@ -23,7 +23,7 @@ limitations under the License. namespace libOpenCOR { -static constexpr auto ID_PREFIX = "simulation"; +static constexpr auto ID_PREFIX {"simulation"}; SedSimulation::Impl::Impl(const SedDocumentPtr &pDocument) : SedBase::Impl(pDocument->pimpl()->uniqueId(ID_PREFIX)) @@ -32,7 +32,7 @@ SedSimulation::Impl::Impl(const SedDocumentPtr &pDocument) bool SedSimulation::Impl::isValid(const SedModelPtr &pModel) { - auto modelType = pModel->pimpl()->mFile->pimpl()->mCellmlFile->type(); + auto modelType {pModel->pimpl()->mFile->pimpl()->mCellmlFile->type()}; if ((modelType == libcellml::AnalyserModel::Type::ODE) && (mOdeSolver == nullptr)) { addError(std::string("Simulation '").append(mId).append("' is to be used with model '").append(pModel->pimpl()->mId).append("' which requires an ODE solver but none is provided.")); diff --git a/src/sed/sedsteadystate.cpp b/src/sed/sedsteadystate.cpp index 197a9a61d..8d5b25af1 100644 --- a/src/sed/sedsteadystate.cpp +++ b/src/sed/sedsteadystate.cpp @@ -27,7 +27,7 @@ SedSteadyState::Impl::Impl(const SedDocumentPtr &pDocument) void SedSteadyState::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("steadyState")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("steadyState"))}; SedSimulation::Impl::serialise(node); diff --git a/src/sed/sedtask.cpp b/src/sed/sedtask.cpp index 5d527d3e5..47e147b92 100644 --- a/src/sed/sedtask.cpp +++ b/src/sed/sedtask.cpp @@ -92,7 +92,7 @@ void SedTask::Impl::setSimulation(const SedSimulationPtr &pSimulation) void SedTask::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("task")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("task"))}; SedAbstractTask::Impl::serialise(node); diff --git a/src/sed/seduniformtimecourse.cpp b/src/sed/seduniformtimecourse.cpp index 4542ac075..fdd718b7c 100644 --- a/src/sed/seduniformtimecourse.cpp +++ b/src/sed/seduniformtimecourse.cpp @@ -67,7 +67,7 @@ void SedUniformTimeCourse::Impl::setNumberOfSteps(int pNumberOfSteps) void SedUniformTimeCourse::Impl::serialise(xmlNodePtr pNode) const { - auto *node = xmlNewNode(nullptr, toConstXmlCharPtr("uniformTimeCourse")); + auto *node {xmlNewNode(nullptr, toConstXmlCharPtr("uniformTimeCourse"))}; SedSimulation::Impl::serialise(node); diff --git a/src/sed/seduniformtimecourse_p.h b/src/sed/seduniformtimecourse_p.h index 081416037..baf77020c 100644 --- a/src/sed/seduniformtimecourse_p.h +++ b/src/sed/seduniformtimecourse_p.h @@ -25,10 +25,10 @@ namespace libOpenCOR { class SedUniformTimeCourse::Impl: public SedSimulation::Impl { public: - double mInitialTime = 0.0; - double mOutputStartTime = 0.0; - double mOutputEndTime = 1000.0; - int mNumberOfSteps = 1000; + double mInitialTime {0.0}; + double mOutputStartTime {0.0}; + double mOutputEndTime {1000.0}; + int mNumberOfSteps {1000}; explicit Impl(const SedDocumentPtr &pDocument); diff --git a/src/solver/solver.cpp b/src/solver/solver.cpp index 96ef06e20..a363f0620 100644 --- a/src/solver/solver.cpp +++ b/src/solver/solver.cpp @@ -38,7 +38,7 @@ void Solver::Impl::serialise(xmlNodePtr pNode, bool pNlaAlgorithm) const { // Solver information. - auto *algorithmNode = xmlNewNode(nullptr, toConstXmlCharPtr(pNlaAlgorithm ? "nlaAlgorithm" : "algorithm")); + auto *algorithmNode {xmlNewNode(nullptr, toConstXmlCharPtr(pNlaAlgorithm ? "nlaAlgorithm" : "algorithm"))}; if (pNlaAlgorithm) { xmlSetNs(algorithmNode, xmlNewNs(algorithmNode, toConstXmlCharPtr(LIBOPENCOR_NAMESPACE), nullptr)); @@ -50,12 +50,12 @@ void Solver::Impl::serialise(xmlNodePtr pNode, bool pNlaAlgorithm) const // Solver properties information. - auto *propertiesNode = xmlNewNode(nullptr, toConstXmlCharPtr("listOfAlgorithmParameters")); + auto *propertiesNode {xmlNewNode(nullptr, toConstXmlCharPtr("listOfAlgorithmParameters"))}; xmlAddChild(algorithmNode, propertiesNode); for (auto const &property : properties()) { - auto *propertyNode = xmlNewNode(nullptr, toConstXmlCharPtr("algorithmParameter")); + auto *propertyNode {xmlNewNode(nullptr, toConstXmlCharPtr("algorithmParameter"))}; xmlNewProp(propertyNode, toConstXmlCharPtr("kisaoID"), toConstXmlCharPtr(property.first)); xmlNewProp(propertyNode, toConstXmlCharPtr("value"), toConstXmlCharPtr(property.second)); diff --git a/src/solver/solvercvode.cpp b/src/solver/solvercvode.cpp index 01dacfd94..2978de459 100644 --- a/src/solver/solvercvode.cpp +++ b/src/solver/solvercvode.cpp @@ -104,7 +104,7 @@ void errorHandler(int pLine, const char *pFunction, const char *pFile, const cha int rhsFunction(double pVoi, N_Vector pStates, N_Vector pRates, void *pUserData) { - auto *userData = static_cast(pUserData); + auto *userData {static_cast(pUserData)}; #ifdef __EMSCRIPTEN__ userData->runtime->computeRates(pVoi, N_VGetArrayPointer_Serial(pStates), N_VGetArrayPointer_Serial(pRates), @@ -133,10 +133,10 @@ SolverCvode::Impl::~Impl() void SolverCvode::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) { - for (unsigned int i = 0; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { - auto *algorithmParameter = pAlgorithm->getAlgorithmParameter(i); - auto kisaoId = algorithmParameter->getKisaoID(); - auto value = algorithmParameter->getValue(); + for (unsigned int i {0}; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { + auto *algorithmParameter {pAlgorithm->getAlgorithmParameter(i)}; + auto kisaoId {algorithmParameter->getKisaoID()}; + auto value {algorithmParameter->getValue()}; if (kisaoId == "KISAO:0000467") { mMaximumStep = toDouble(value); @@ -250,8 +250,8 @@ void SolverCvode::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) SolverPtr SolverCvode::Impl::duplicate() { - auto solver = SolverCvode::create(); - auto *solverPimpl = solver->pimpl(); + auto solver {SolverCvode::create()}; + auto *solverPimpl {solver->pimpl()}; solverPimpl->mMaximumStep = mMaximumStep; solverPimpl->mMaximumNumberOfSteps = mMaximumNumberOfSteps; @@ -329,7 +329,7 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d if (mIterationType == IterationType::NEWTON) { // We are dealing with a Newton iteration type, so we need a linear solver. - bool needUpperAndLowerHalfBandwidths = false; + bool needUpperAndLowerHalfBandwidths {false}; if (mLinearSolver == LinearSolver::BANDED) { // We are dealing with a banded linear solver, so we need both an upper and a lower half-bandwidth. @@ -617,8 +617,8 @@ bool SolverCvode::Impl::solve(double &pVoi, double pVoiEnd) // compute them ourselves. To do so, we keep track of the old state values (in mRates, to save memory) and // then update mRates once we have the new state values. - auto *oldStates = mRates; - auto oneOverdVoi = 1.0 / (pVoiEnd - pVoi); + auto *oldStates {mRates}; + auto oneOverdVoi {1.0 / (pVoiEnd - pVoi)}; std::copy(mStates, mStates + mSize, oldStates); // NOLINT @@ -628,11 +628,11 @@ bool SolverCvode::Impl::solve(double &pVoi, double pVoiEnd) ASSERT_EQ(CVodeSetStopTime(mSolver, pVoiEnd), CV_SUCCESS); } - auto res = CVode(mSolver, pVoiEnd, mStatesVector, &pVoi, CV_NORMAL); + auto res {CVode(mSolver, pVoiEnd, mStatesVector, &pVoi, CV_NORMAL)}; // Compute the rate values. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mRates[i] = oneOverdVoi * (mStates[i] - oldStates[i]); // NOLINT } diff --git a/src/solver/solvercvode_p.h b/src/solver/solvercvode_p.h index 365989b94..fc64ab4fa 100644 --- a/src/solver/solvercvode_p.h +++ b/src/solver/solvercvode_p.h @@ -29,9 +29,9 @@ namespace libOpenCOR { struct SolverCvodeUserData { - double *constants = nullptr; - double *computedConstants = nullptr; - double *algebraic = nullptr; + double *constants {nullptr}; + double *computedConstants {nullptr}; + double *algebraic {nullptr}; CellmlFileRuntimePtr runtime; }; @@ -41,39 +41,39 @@ class SolverCvode::Impl: public SolverOde::Impl public: std::string mErrorMessage; - static constexpr auto DEFAULT_MAXIMUM_STEP = 0.0; - static constexpr auto DEFAULT_MAXIMUM_NUMBER_OF_STEPS = 500; - static constexpr auto DEFAULT_INTEGRATION_METHOD = IntegrationMethod::BDF; - static constexpr auto DEFAULT_ITERATION_TYPE = IterationType::NEWTON; - static constexpr auto DEFAULT_LINEAR_SOLVER = LinearSolver::DENSE; - static constexpr auto DEFAULT_PRECONDITIONER = Preconditioner::BANDED; - static constexpr auto DEFAULT_UPPER_HALF_BANDWIDTH = 0; - static constexpr auto DEFAULT_LOWER_HALF_BANDWIDTH = 0; - static constexpr auto DEFAULT_RELATIVE_TOLERANCE = 1e-07; - static constexpr auto DEFAULT_ABSOLUTE_TOLERANCE = 1e-07; - static constexpr auto DEFAULT_INTERPOLATE_SOLUTION = true; - - double mMaximumStep = DEFAULT_MAXIMUM_STEP; - int mMaximumNumberOfSteps = DEFAULT_MAXIMUM_NUMBER_OF_STEPS; - IntegrationMethod mIntegrationMethod = DEFAULT_INTEGRATION_METHOD; - IterationType mIterationType = DEFAULT_ITERATION_TYPE; - LinearSolver mLinearSolver = DEFAULT_LINEAR_SOLVER; - Preconditioner mPreconditioner = DEFAULT_PRECONDITIONER; - int mUpperHalfBandwidth = DEFAULT_UPPER_HALF_BANDWIDTH; - int mLowerHalfBandwidth = DEFAULT_LOWER_HALF_BANDWIDTH; - double mRelativeTolerance = DEFAULT_RELATIVE_TOLERANCE; - double mAbsoluteTolerance = DEFAULT_ABSOLUTE_TOLERANCE; - bool mInterpolateSolution = DEFAULT_INTERPOLATE_SOLUTION; - - SUNContext mSunContext = nullptr; - - void *mSolver = nullptr; - - N_Vector mStatesVector = nullptr; - - SUNMatrix mSunMatrix = nullptr; - SUNLinearSolver mSunLinearSolver = nullptr; - SUNNonlinearSolver mSunNonLinearSolver = nullptr; + static constexpr auto DEFAULT_MAXIMUM_STEP {0.0}; + static constexpr auto DEFAULT_MAXIMUM_NUMBER_OF_STEPS {500}; + static constexpr auto DEFAULT_INTEGRATION_METHOD {IntegrationMethod::BDF}; + static constexpr auto DEFAULT_ITERATION_TYPE {IterationType::NEWTON}; + static constexpr auto DEFAULT_LINEAR_SOLVER {LinearSolver::DENSE}; + static constexpr auto DEFAULT_PRECONDITIONER {Preconditioner::BANDED}; + static constexpr auto DEFAULT_UPPER_HALF_BANDWIDTH {0}; + static constexpr auto DEFAULT_LOWER_HALF_BANDWIDTH {0}; + static constexpr auto DEFAULT_RELATIVE_TOLERANCE {1e-07}; + static constexpr auto DEFAULT_ABSOLUTE_TOLERANCE {1e-07}; + static constexpr auto DEFAULT_INTERPOLATE_SOLUTION {true}; + + double mMaximumStep {DEFAULT_MAXIMUM_STEP}; + int mMaximumNumberOfSteps {DEFAULT_MAXIMUM_NUMBER_OF_STEPS}; + IntegrationMethod mIntegrationMethod {DEFAULT_INTEGRATION_METHOD}; + IterationType mIterationType {DEFAULT_ITERATION_TYPE}; + LinearSolver mLinearSolver {DEFAULT_LINEAR_SOLVER}; + Preconditioner mPreconditioner {DEFAULT_PRECONDITIONER}; + int mUpperHalfBandwidth {DEFAULT_UPPER_HALF_BANDWIDTH}; + int mLowerHalfBandwidth {DEFAULT_LOWER_HALF_BANDWIDTH}; + double mRelativeTolerance {DEFAULT_RELATIVE_TOLERANCE}; + double mAbsoluteTolerance {DEFAULT_ABSOLUTE_TOLERANCE}; + bool mInterpolateSolution {DEFAULT_INTERPOLATE_SOLUTION}; + + SUNContext mSunContext {nullptr}; + + void *mSolver {nullptr}; + + N_Vector mStatesVector {nullptr}; + + SUNMatrix mSunMatrix {nullptr}; + SUNLinearSolver mSunLinearSolver {nullptr}; + SUNNonlinearSolver mSunNonLinearSolver {nullptr}; SolverCvodeUserData mUserData; diff --git a/src/solver/solverforwardeuler.cpp b/src/solver/solverforwardeuler.cpp index ed12d8732..9ce3bcd23 100644 --- a/src/solver/solverforwardeuler.cpp +++ b/src/solver/solverforwardeuler.cpp @@ -48,9 +48,9 @@ bool SolverForwardEuler::Impl::solve(double &pVoi, double pVoiEnd) // We compute the following: // Y_n+1 = Y_n + h * f(t_n, Y_n) - const auto voiStart = pVoi; - size_t voiCounter = 0; - auto realStep = mStep; + const auto voiStart {pVoi}; + size_t voiCounter {0}; + auto realStep {mStep}; while (!fuzzyCompare(pVoi, pVoiEnd)) { // Check that the step is correct. @@ -65,7 +65,7 @@ bool SolverForwardEuler::Impl::solve(double &pVoi, double pVoiEnd) // Compute Y_n+1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mStates[i] += realStep * mRates[i]; // NOLINT } diff --git a/src/solver/solverfourthorderrungekutta.cpp b/src/solver/solverfourthorderrungekutta.cpp index 138f11238..8fbbdfdbc 100644 --- a/src/solver/solverfourthorderrungekutta.cpp +++ b/src/solver/solverfourthorderrungekutta.cpp @@ -69,15 +69,15 @@ bool SolverFourthOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Y_n+1 = Y_n + h / 6 * (k1 + 2 * k2 + 2 * k3 + k4) // Note that k4 doesn't need to be tracked since it is used only once. - static const auto TWO = 2.0; - static const auto HALF = 0.5; - static const auto ONE_SIXTH = 1.0 / 6.0; + static const auto TWO {2.0}; + static const auto HALF {0.5}; + static const auto ONE_SIXTH {1.0 / 6.0}; - const auto voiStart = pVoi; - size_t voiCounter = 0; - auto realStep = mStep; - auto realHalfStep = HALF * realStep; - auto realOneSixthStep = ONE_SIXTH * realStep; + const auto voiStart {pVoi}; + size_t voiCounter {0}; + auto realStep {mStep}; + auto realHalfStep {HALF * realStep}; + auto realOneSixthStep {ONE_SIXTH * realStep}; while (!fuzzyCompare(pVoi, pVoiEnd)) { // Check that the step is correct. @@ -94,7 +94,7 @@ bool SolverFourthOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute k1 and Y_n + h / 2 * k1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mK1[i] = mRates[i]; // NOLINT mYk[i] = mStates[i] + realHalfStep * mK1[i]; // NOLINT } @@ -105,7 +105,7 @@ bool SolverFourthOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute k2 and Y_n + h / 2 * k2. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mK2[i] = mRates[i]; // NOLINT mYk[i] = mStates[i] + realHalfStep * mK2[i]; // NOLINT } @@ -116,7 +116,7 @@ bool SolverFourthOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute k3 and Y_n + h * k3. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mK3[i] = mRates[i]; // NOLINT mYk[i] = mStates[i] + realStep * mK3[i]; // NOLINT } @@ -127,7 +127,7 @@ bool SolverFourthOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute Y_n+1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mStates[i] += realOneSixthStep * (mK1[i] + TWO * mK2[i] + TWO * mK3[i] + mRates[i]); // NOLINT } diff --git a/src/solver/solverfourthorderrungekutta_p.h b/src/solver/solverfourthorderrungekutta_p.h index 06c22181e..dcfbbfee5 100644 --- a/src/solver/solverfourthorderrungekutta_p.h +++ b/src/solver/solverfourthorderrungekutta_p.h @@ -25,10 +25,10 @@ namespace libOpenCOR { class SolverFourthOrderRungeKutta::Impl: public SolverOdeFixedStep::Impl { public: - double *mK1 = nullptr; - double *mK2 = nullptr; - double *mK3 = nullptr; - double *mYk = nullptr; + double *mK1 {nullptr}; + double *mK2 {nullptr}; + double *mK3 {nullptr}; + double *mYk {nullptr}; Doubles mK1Doubles; Doubles mK2Doubles; diff --git a/src/solver/solverheun.cpp b/src/solver/solverheun.cpp index 5748db2cd..54a3f3a13 100644 --- a/src/solver/solverheun.cpp +++ b/src/solver/solverheun.cpp @@ -61,12 +61,12 @@ bool SolverHeun::Impl::solve(double &pVoi, double pVoiEnd) // k = f(t_n, Y_n) // Y_n+1 = Y_n + h / 2 * ( f(t_n, Y_n) + f(t_n + h, Y_n + h * k) ) - static const auto HALF = 0.5; + static const auto HALF {0.5}; - const auto voiStart = pVoi; - size_t voiCounter = 0; - auto realStep = mStep; - auto realHalfStep = HALF * realStep; + const auto voiStart {pVoi}; + size_t voiCounter {0}; + auto realStep {mStep}; + auto realHalfStep {HALF * realStep}; while (!fuzzyCompare(pVoi, pVoiEnd)) { // Check that the step is correct. @@ -82,7 +82,7 @@ bool SolverHeun::Impl::solve(double &pVoi, double pVoiEnd) // Compute k and Y_n + h * k. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mK[i] = mRates[i]; // NOLINT mYk[i] = mStates[i] + realStep * mK[i]; // NOLINT } @@ -93,7 +93,7 @@ bool SolverHeun::Impl::solve(double &pVoi, double pVoiEnd) // Compute Y_n+1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mStates[i] += realHalfStep * (mK[i] + mRates[i]); // NOLINT } diff --git a/src/solver/solverheun_p.h b/src/solver/solverheun_p.h index 14e6603fd..2a424a369 100644 --- a/src/solver/solverheun_p.h +++ b/src/solver/solverheun_p.h @@ -25,8 +25,8 @@ namespace libOpenCOR { class SolverHeun::Impl: public SolverOdeFixedStep::Impl { public: - double *mK = nullptr; - double *mYk = nullptr; + double *mK {nullptr}; + double *mYk {nullptr}; Doubles mKDoubles; Doubles mYkDoubles; diff --git a/src/solver/solverkinsol.cpp b/src/solver/solverkinsol.cpp index 1cd3736e3..7634d458a 100644 --- a/src/solver/solverkinsol.cpp +++ b/src/solver/solverkinsol.cpp @@ -73,25 +73,25 @@ void errorHandler(int pLine, const char *pFunction, const char *pFile, const cha #endif #ifdef __EMSCRIPTEN__ -static constexpr auto MAX_SIZE_T = std::numeric_limits::max(); -static constexpr auto MAX_INTPTR_T = std::numeric_limits::max(); +static constexpr auto MAX_SIZE_T {std::numeric_limits::max()}; +static constexpr auto MAX_INTPTR_T {std::numeric_limits::max()}; #endif struct SolverKinsolUserData { #ifdef __EMSCRIPTEN__ - intptr_t wasmInstanceFunctionsId = MAX_INTPTR_T; - size_t computeObjectiveFunctionIndex = MAX_SIZE_T; + intptr_t wasmInstanceFunctionsId {MAX_INTPTR_T}; + size_t computeObjectiveFunctionIndex {MAX_SIZE_T}; #else - SolverNla::ComputeObjectiveFunction computeObjectiveFunction = nullptr; + SolverNla::ComputeObjectiveFunction computeObjectiveFunction {nullptr}; #endif - void *userData = nullptr; + void *userData {nullptr}; }; int computeObjectiveFunction(N_Vector pU, N_Vector pF, void *pUserData) { - auto *userData = static_cast(pUserData); + auto *userData {static_cast(pUserData)}; #ifdef __EMSCRIPTEN__ // clang-format off @@ -116,10 +116,10 @@ SolverKinsol::Impl::Impl() void SolverKinsol::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) { - for (unsigned int i = 0; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { - auto *algorithmParameter = pAlgorithm->getAlgorithmParameter(i); - auto kisaoId = algorithmParameter->getKisaoID(); - auto value = algorithmParameter->getValue(); + for (unsigned int i {0}; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { + auto *algorithmParameter {pAlgorithm->getAlgorithmParameter(i)}; + auto kisaoId {algorithmParameter->getKisaoID()}; + auto value {algorithmParameter->getValue()}; if (kisaoId == "KISAO:0000486") { mMaximumNumberOfIterations = toInt(value); @@ -169,8 +169,8 @@ void SolverKinsol::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) SolverPtr SolverKinsol::Impl::duplicate() { - auto solver = SolverKinsol::create(); - auto *solverPimpl = solver->pimpl(); + auto solver {SolverKinsol::create()}; + auto *solverPimpl {solver->pimpl()}; solverPimpl->mMaximumNumberOfIterations = mMaximumNumberOfIterations; solverPimpl->mLinearSolver = mLinearSolver; @@ -273,13 +273,13 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio // Create our SUNDIALS context. - SUNContext context = nullptr; + SUNContext context {nullptr}; ASSERT_EQ(SUNContext_Create(SUN_COMM_NULL, &context), 0); // Create our KINSOL solver. - auto *solver = KINCreate(context); + auto *solver {KINCreate(context)}; ASSERT_NE(solver, nullptr); @@ -292,8 +292,8 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio // Initialise our KINSOL solver. - auto *u = N_VMake_Serial(static_cast(pN), pU, context); - auto *ones = N_VNew_Serial(static_cast(pN), context); + auto *u {N_VMake_Serial(static_cast(pN), pU, context)}; + auto *ones {N_VNew_Serial(static_cast(pN), context)}; ASSERT_NE(u, nullptr); ASSERT_NE(ones, nullptr); @@ -304,8 +304,8 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio // Set our linear solver. - SUNMatrix sunMatrix = nullptr; - SUNLinearSolver sunLinearSolver = nullptr; + SUNMatrix sunMatrix {nullptr}; + SUNLinearSolver sunLinearSolver {nullptr}; if (mLinearSolver == LinearSolver::DENSE) { sunMatrix = SUNDenseMatrix(static_cast(pN), static_cast(pN), context); diff --git a/src/solver/solverkinsol_p.h b/src/solver/solverkinsol_p.h index 06f366f5c..9fae7c566 100644 --- a/src/solver/solverkinsol_p.h +++ b/src/solver/solverkinsol_p.h @@ -27,15 +27,15 @@ class SolverKinsol::Impl: public SolverNla::Impl public: std::string mErrorMessage; - static constexpr auto DEFAULT_MAXIMUM_NUMBER_OF_ITERATIONS = 200; - static constexpr auto DEFAULT_LINEAR_SOLVER = LinearSolver::DENSE; - static constexpr auto DEFAULT_UPPER_HALF_BANDWIDTH = 0; - static constexpr auto DEFAULT_LOWER_HALF_BANDWIDTH = 0; - - int mMaximumNumberOfIterations = DEFAULT_MAXIMUM_NUMBER_OF_ITERATIONS; - LinearSolver mLinearSolver = DEFAULT_LINEAR_SOLVER; - int mUpperHalfBandwidth = DEFAULT_UPPER_HALF_BANDWIDTH; - int mLowerHalfBandwidth = DEFAULT_LOWER_HALF_BANDWIDTH; + static constexpr auto DEFAULT_MAXIMUM_NUMBER_OF_ITERATIONS {200}; + static constexpr auto DEFAULT_LINEAR_SOLVER {LinearSolver::DENSE}; + static constexpr auto DEFAULT_UPPER_HALF_BANDWIDTH {0}; + static constexpr auto DEFAULT_LOWER_HALF_BANDWIDTH {0}; + + int mMaximumNumberOfIterations {DEFAULT_MAXIMUM_NUMBER_OF_ITERATIONS}; + LinearSolver mLinearSolver {DEFAULT_LINEAR_SOLVER}; + int mUpperHalfBandwidth {DEFAULT_UPPER_HALF_BANDWIDTH}; + int mLowerHalfBandwidth {DEFAULT_LOWER_HALF_BANDWIDTH}; explicit Impl(); diff --git a/src/solver/solverode_p.h b/src/solver/solverode_p.h index 0725be743..6363723a4 100644 --- a/src/solver/solverode_p.h +++ b/src/solver/solverode_p.h @@ -27,13 +27,13 @@ namespace libOpenCOR { class SolverOde::Impl: public Solver::Impl { public: - size_t mSize = 0; + size_t mSize {0}; - double *mStates = nullptr; - double *mRates = nullptr; - double *mConstants = nullptr; - double *mComputedConstants = nullptr; - double *mAlgebraic = nullptr; + double *mStates {nullptr}; + double *mRates {nullptr}; + double *mConstants {nullptr}; + double *mComputedConstants {nullptr}; + double *mAlgebraic {nullptr}; CellmlFileRuntimePtr mRuntime; diff --git a/src/solver/solverodefixedstep.cpp b/src/solver/solverodefixedstep.cpp index 2f1460011..2539f44fd 100644 --- a/src/solver/solverodefixedstep.cpp +++ b/src/solver/solverodefixedstep.cpp @@ -31,10 +31,10 @@ SolverOdeFixedStep::Impl::Impl(const std::string &pId, const std::string &pName) void SolverOdeFixedStep::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) { - for (unsigned int i = 0; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { - auto *algorithmParameter = pAlgorithm->getAlgorithmParameter(i); - auto kisaoId = algorithmParameter->getKisaoID(); - auto value = algorithmParameter->getValue(); + for (unsigned int i {0}; i < pAlgorithm->getNumAlgorithmParameters(); ++i) { + auto *algorithmParameter {pAlgorithm->getAlgorithmParameter(i)}; + auto kisaoId {algorithmParameter->getKisaoID()}; + auto value {algorithmParameter->getValue()}; if (kisaoId == "KISAO:0000483") { mStep = toDouble(value); @@ -52,7 +52,7 @@ void SolverOdeFixedStep::Impl::populate(libsedml::SedAlgorithm *pAlgorithm) SolverPtr SolverOdeFixedStep::Impl::duplicate(const SolverOdeFixedStepPtr &pSolver) const { - auto *solverPimpl = pSolver->pimpl(); + auto *solverPimpl {pSolver->pimpl()}; solverPimpl->mStep = mStep; diff --git a/src/solver/solverodefixedstep_p.h b/src/solver/solverodefixedstep_p.h index 0a279cd4a..470099163 100644 --- a/src/solver/solverodefixedstep_p.h +++ b/src/solver/solverodefixedstep_p.h @@ -27,9 +27,9 @@ class SolverOdeFixedStep::Impl: public SolverOde::Impl public: using SolverOde::Impl::duplicate; - static constexpr auto DEFAULT_STEP = 1.0; + static constexpr auto DEFAULT_STEP {1.0}; - double mStep = DEFAULT_STEP; + double mStep {DEFAULT_STEP}; explicit Impl(const std::string &pId, const std::string &pName); diff --git a/src/solver/solversecondorderrungekutta.cpp b/src/solver/solversecondorderrungekutta.cpp index f1a6fb1ea..cf80bfd87 100644 --- a/src/solver/solversecondorderrungekutta.cpp +++ b/src/solver/solversecondorderrungekutta.cpp @@ -61,12 +61,12 @@ bool SolverSecondOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Y_n+1 = Y_n + h * k2 // Note that k1 and k2 don't need to be tracked since they are used only once. - static const auto HALF = 0.5; + static const auto HALF {0.5}; - const auto voiStart = pVoi; - size_t voiCounter = 0; - auto realStep = mStep; - auto realHalfStep = HALF * realStep; + const auto voiStart {pVoi}; + size_t voiCounter {0}; + auto realStep {mStep}; + auto realHalfStep {HALF * realStep}; while (!fuzzyCompare(pVoi, pVoiEnd)) { // Check that the step is correct. @@ -82,7 +82,7 @@ bool SolverSecondOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute Y_n + h / 2 * k1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mYk[i] = mStates[i] + realHalfStep * mRates[i]; // NOLINT } @@ -92,7 +92,7 @@ bool SolverSecondOrderRungeKutta::Impl::solve(double &pVoi, double pVoiEnd) // Compute Y_n+1. - for (size_t i = 0; i < mSize; ++i) { + for (size_t i {0}; i < mSize; ++i) { mStates[i] += realStep * mRates[i]; // NOLINT } diff --git a/src/solver/solversecondorderrungekutta_p.h b/src/solver/solversecondorderrungekutta_p.h index dfbe5d8ed..7a2570fa1 100644 --- a/src/solver/solversecondorderrungekutta_p.h +++ b/src/solver/solversecondorderrungekutta_p.h @@ -25,7 +25,7 @@ namespace libOpenCOR { class SolverSecondOrderRungeKutta::Impl: public SolverOdeFixedStep::Impl { public: - double *mYk = nullptr; + double *mYk {nullptr}; Doubles mYkDoubles; diff --git a/src/support/cellml/cellmlfile.cpp b/src/support/cellml/cellmlfile.cpp index 866ad360e..e6faacbd4 100644 --- a/src/support/cellml/cellmlfile.cpp +++ b/src/support/cellml/cellmlfile.cpp @@ -34,7 +34,7 @@ CellmlFile::Impl::Impl(const FilePtr &pFile, const libcellml::ModelPtr &pModel, // Resolve imports and flatten the model, if needed and possible. if (mModel->hasUnresolvedImports()) { - auto importer = libcellml::Importer::create(pStrict); + auto importer {libcellml::Importer::create(pStrict)}; if (importer->resolveImports(mModel, pathToString(stringToPath(pFile->path()).parent_path()))) { mModel = importer->flattenModel(mModel); @@ -61,7 +61,7 @@ void CellmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) const { // Add a model. - auto model = SedModel::create(pDocument, mFile.lock()); + auto model {SedModel::create(pDocument, mFile.lock())}; pDocument->addModel(model); @@ -69,7 +69,7 @@ void CellmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) const // of an algebraic or NLA model. SedSimulationPtr simulation; - auto type = mAnalyserModel->type(); + auto type {mAnalyserModel->type()}; if ((type == libcellml::AnalyserModel::Type::ODE) || (type == libcellml::AnalyserModel::Type::DAE)) { @@ -154,8 +154,8 @@ CellmlFilePtr CellmlFile::create(const FilePtr &pFile) // Try to parse the file contents as a CellML file, be it a CellML 1.x or a CellML 2.0 file. - auto parser = libcellml::Parser::create(false); - auto model = parser->parseModel(toString(pFile->contents())); + auto parser {libcellml::Parser::create(false)}; + auto model {parser->parseModel(toString(pFile->contents()))}; if (parser->errorCount() == 0) { return CellmlFilePtr {new CellmlFile {pFile, model, false}}; diff --git a/src/support/cellml/cellmlfileruntime.cpp b/src/support/cellml/cellmlfileruntime.cpp index edd149af1..15d3776f2 100644 --- a/src/support/cellml/cellmlfileruntime.cpp +++ b/src/support/cellml/cellmlfileruntime.cpp @@ -131,7 +131,7 @@ intptr_t instantiateWebAssemblyModule(UnsignedChars pWasmModule, bool pDifferent for (let name in wasmInstance.exports) { if (name.startsWith("objectiveFunction")) { - const objectiveFunctionIndex = parseInt(name.replace("objectiveFunction", "")); + const objectiveFunctionIndex = parseInt(name.replace("objectiveFunction", ""), 10); wasmInstanceFunctions.objectiveFunctions[objectiveFunctionIndex] = wasmInstance.exports[name]; } @@ -166,7 +166,7 @@ intptr_t instantiateWebAssemblyModule(UnsignedChars pWasmModule, bool pDifferent CellmlFileRuntime::Impl::Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaPtr &pNlaSolver) { - auto cellmlFileAnalyser = pCellmlFile->analyser(); + auto cellmlFileAnalyser {pCellmlFile->analyser()}; if (cellmlFileAnalyser->errorCount() != 0) { addIssues(cellmlFileAnalyser); @@ -179,14 +179,14 @@ CellmlFileRuntime::Impl::Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaP // Determine the type of the model. - auto cellmlFileType = pCellmlFile->type(); - auto differentialModel = (cellmlFileType == libcellml::AnalyserModel::Type::ODE) - || (cellmlFileType == libcellml::AnalyserModel::Type::DAE); + auto cellmlFileType {pCellmlFile->type()}; + auto differentialModel {(cellmlFileType == libcellml::AnalyserModel::Type::ODE) + || (cellmlFileType == libcellml::AnalyserModel::Type::DAE)}; // Generate some code for the given CellML file. - auto generator = libcellml::Generator::create(); - auto generatorProfile = libcellml::GeneratorProfile::create(); + auto generator {libcellml::Generator::create()}; + auto generatorProfile {libcellml::GeneratorProfile::create()}; generatorProfile->setOriginCommentString(""); generatorProfile->setImplementationHeaderString(""); @@ -210,7 +210,7 @@ CellmlFileRuntime::Impl::Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaP generatorProfile->setImplementationCreateExternalsArrayMethodString(""); generatorProfile->setImplementationDeleteArrayMethodString(""); - static constexpr auto WITH_EXTERNAL_VARIABLES = false; + static constexpr auto WITH_EXTERNAL_VARIABLES {false}; #ifdef __EMSCRIPTEN__ // Allocate the memory needed by our objective functions on the heap rather than on the stack. @@ -311,17 +311,17 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl #ifdef __EMSCRIPTEN__ // Export our various objective functions. - auto implementationCode = generator->implementationCode(pCellmlFile->analyserModel()); + auto implementationCode {generator->implementationCode(pCellmlFile->analyserModel())}; if (pNlaSolver != nullptr) { std::vector handledNlaSystemIndices; for (const auto &equation : pCellmlFile->analyserModel()->equations()) { if (equation->type() == libcellml::AnalyserEquation::Type::NLA) { - auto nlaSystemIndex = equation->nlaSystemIndex(); + auto nlaSystemIndex {equation->nlaSystemIndex()}; if (std::find(handledNlaSystemIndices.begin(), handledNlaSystemIndices.end(), nlaSystemIndex) == handledNlaSystemIndices.end()) { - auto objectiveFunctionName = std::string("objectiveFunction").append(std::to_string(nlaSystemIndex)); + auto objectiveFunctionName {std::string("objectiveFunction").append(std::to_string(nlaSystemIndex))}; implementationCode.insert(implementationCode.find("void " + objectiveFunctionName), exportJavaScriptName(objectiveFunctionName)); @@ -348,15 +348,15 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl // Instantiate the WebAssembly module. - auto wasmInstanceFunctionsId = instantiateWebAssemblyModule(mWasmModule, differentialModel, - cellmlFileType == libcellml::AnalyserModel::Type::ODE, - cellmlFileType == libcellml::AnalyserModel::Type::ALGEBRAIC, - pNlaSolver != nullptr); + auto wasmInstanceFunctionsId {instantiateWebAssemblyModule(mWasmModule, differentialModel, + cellmlFileType == libcellml::AnalyserModel::Type::ODE, + cellmlFileType == libcellml::AnalyserModel::Type::ALGEBRAIC, + pNlaSolver != nullptr)}; if (wasmInstanceFunctionsId < 0) { // An error occurred and the error message pointer is the negative of the returned value. - auto errorMessagePtr = reinterpret_cast(-wasmInstanceFunctionsId); + auto errorMessagePtr {reinterpret_cast(-wasmInstanceFunctionsId)}; std::string jsErrorMessage(errorMessagePtr); free(errorMessagePtr); diff --git a/src/support/cellml/cellmlfileruntime_p.h b/src/support/cellml/cellmlfileruntime_p.h index 5ee0b2ed1..a19939b06 100644 --- a/src/support/cellml/cellmlfileruntime_p.h +++ b/src/support/cellml/cellmlfileruntime_p.h @@ -26,21 +26,21 @@ namespace libOpenCOR { class CellmlFileRuntime::Impl: public Logger::Impl { public: - CompilerPtr mCompiler = nullptr; + CompilerPtr mCompiler {nullptr}; std::string mNlaSolverAddress; #ifdef __EMSCRIPTEN__ UnsignedChars mWasmModule; - intptr_t mWasmInstanceFunctionsId = 0; + intptr_t mWasmInstanceFunctionsId {0}; #endif #ifndef __EMSCRIPTEN__ - InitialiseVariablesForAlgebraicModel mInitialiseVariablesForAlgebraicModel = nullptr; - InitialiseVariablesForDifferentialModel mInitialiseVariablesForDifferentialModel = nullptr; - ComputeComputedConstantsForAlgebraicModel mComputeComputedConstantsForAlgebraicModel = nullptr; - ComputeComputedConstantsForDifferentialModel mComputeComputedConstantsForDifferentialModel = nullptr; - ComputeRates mComputeRates = nullptr; - ComputeVariablesForAlgebraicModel mComputeVariablesForAlgebraicModel = nullptr; - ComputeVariablesForDifferentialModel mComputeVariablesForDifferentialModel = nullptr; + InitialiseVariablesForAlgebraicModel mInitialiseVariablesForAlgebraicModel {nullptr}; + InitialiseVariablesForDifferentialModel mInitialiseVariablesForDifferentialModel {nullptr}; + ComputeComputedConstantsForAlgebraicModel mComputeComputedConstantsForAlgebraicModel {nullptr}; + ComputeComputedConstantsForDifferentialModel mComputeComputedConstantsForDifferentialModel {nullptr}; + ComputeRates mComputeRates {nullptr}; + ComputeVariablesForAlgebraicModel mComputeVariablesForAlgebraicModel {nullptr}; + ComputeVariablesForDifferentialModel mComputeVariablesForDifferentialModel {nullptr}; #endif explicit Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaPtr &pNlaSolver); diff --git a/src/support/combine/combinearchive.cpp b/src/support/combine/combinearchive.cpp index e3add0cba..7836e7755 100644 --- a/src/support/combine/combinearchive.cpp +++ b/src/support/combine/combinearchive.cpp @@ -33,10 +33,10 @@ CombineArchive::Impl::Impl(const FilePtr &pFile, libcombine::CombineArchive *pAr { // Extract all the files contained in the COMBINE archive. - for (int i = 0; i < mArchive->getNumEntries(); ++i) { - const auto *entry = mArchive->getEntry(i); - auto location = entry->getLocation(); - auto file = File::create(mArchiveLocation + location); + for (int i {0}; i < mArchive->getNumEntries(); ++i) { + const auto *entry {mArchive->getEntry(i)}; + auto location {entry->getLocation()}; + auto file {File::create(mArchiveLocation + location)}; file->setContents(mArchive->extractEntryToBuffer(location)); @@ -145,16 +145,16 @@ CombineArchivePtr CombineArchive::create(const FilePtr &pFile) // used by a ZIP file (we ignore empty and spanned ZIP files). Indeed, libCOMBINE may crash depending on the // file contents that is given to it. - static const auto LS8 = 8U; - static const auto LS16 = 16U; - static const auto LS24 = 24U; - static const auto ZIP_MAGIC_NUMBER = 0x04034b50; + static const auto LS8 {8U}; + static const auto LS16 {16U}; + static const auto LS24 {24U}; + static const auto ZIP_MAGIC_NUMBER {0x04034b50}; - auto fileContents = pFile->contents(); + auto fileContents {pFile->contents()}; if ((fileContents.size() > 4) && (fileContents[0] + (fileContents[1] << LS8) + (fileContents[2] << LS16) + (fileContents[3] << LS24) == ZIP_MAGIC_NUMBER)) { - auto *archive = new libcombine::CombineArchive {}; + auto *archive {new libcombine::CombineArchive {}}; archive->initializeFromBuffer(fileContents); diff --git a/src/support/sedml/sedmlfile.cpp b/src/support/sedml/sedmlfile.cpp index 69cc9ad97..05d299e13 100644 --- a/src/support/sedml/sedmlfile.cpp +++ b/src/support/sedml/sedmlfile.cpp @@ -73,18 +73,18 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) removeAllIssues(); - auto fileManager = FileManager::instance(); - - for (unsigned int i = 0; i < mDocument->getNumModels(); ++i) { - auto source = mDocument->getModel(i)->getSource(); - auto [isLocalFile, fileNameOrUrl] = retrieveFileInfo(source); - auto modelSource = (isLocalFile && stringToPath(fileNameOrUrl).is_relative()) ? - mLocation + fileNameOrUrl : - fileNameOrUrl; + auto fileManager {FileManager::instance()}; + + for (unsigned int i {0}; i < mDocument->getNumModels(); ++i) { + auto source {mDocument->getModel(i)->getSource()}; + auto [isLocalFile, fileNameOrUrl] {retrieveFileInfo(source)}; + auto modelSource {(isLocalFile && stringToPath(fileNameOrUrl).is_relative()) ? + mLocation + fileNameOrUrl : + fileNameOrUrl}; #ifdef __EMSCRIPTEN__ - auto file = fileManager.fileFromFileNameOrUrl(modelSource); + auto file {fileManager.fileFromFileNameOrUrl(modelSource)}; #else - auto file = fileManager.file(modelSource); + auto file {fileManager.file(modelSource)}; #endif SedModelPtr model; @@ -98,31 +98,31 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) model->setId(mDocument->getModel(i)->getId()); - for (unsigned int j = 0; j < mDocument->getModel(i)->getNumChanges(); ++j) { - auto *change = mDocument->getModel(i)->getChange(j); + for (unsigned int j {0}; j < mDocument->getModel(i)->getNumChanges(); ++j) { + auto *change {mDocument->getModel(i)->getChange(j)}; if (change->isSedChangeAttribute()) { - static const std::string TARGET_START = "/cellml:model/cellml:component[@name='"; - static const std::string TARGET_MIDDLE = "']/cellml:variable[@name='"; - static const std::string TARGET_END = "']"; + static const std::string TARGET_START {"/cellml:model/cellml:component[@name='"}; + static const std::string TARGET_MIDDLE {"']/cellml:variable[@name='"}; + static const std::string TARGET_END {"']"}; - auto *changeAttribute = reinterpret_cast(change); - auto target = changeAttribute->getTarget(); + auto *changeAttribute {reinterpret_cast(change)}; + auto target {changeAttribute->getTarget()}; std::string componentName; std::string variableName; - auto newValue = changeAttribute->getNewValue(); + auto newValue {changeAttribute->getNewValue()}; if (target.starts_with(TARGET_START)) { target.erase(0, TARGET_START.length()); - auto targetMiddlePos = target.find(TARGET_MIDDLE); + auto targetMiddlePos {target.find(TARGET_MIDDLE)}; if (targetMiddlePos != std::string::npos) { componentName = target.substr(0, targetMiddlePos); target.erase(0, targetMiddlePos + TARGET_MIDDLE.length()); - auto targetEndPos = target.find(TARGET_END); + auto targetEndPos {target.find(TARGET_END)}; if (targetEndPos != std::string::npos) { variableName = target.substr(0, targetEndPos); @@ -137,7 +137,7 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) } } - auto canAddChange = true; + auto canAddChange {true}; if (componentName.empty() || variableName.empty()) { canAddChange = false; @@ -165,13 +165,13 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) // Populate the simulations. - for (unsigned int i = 0; i < mDocument->getNumSimulations(); ++i) { - auto *sedSimulation = mDocument->getSimulation(i); + for (unsigned int i {0}; i < mDocument->getNumSimulations(); ++i) { + auto *sedSimulation {mDocument->getSimulation(i)}; SedSimulationPtr simulation; if (sedSimulation->isSedUniformTimeCourse()) { - auto *sedUniformTimeCourse = reinterpret_cast(sedSimulation); - auto uniformTimeCourse = SedUniformTimeCourse::create(pDocument); + auto *sedUniformTimeCourse {reinterpret_cast(sedSimulation)}; + auto uniformTimeCourse {SedUniformTimeCourse::create(pDocument)}; uniformTimeCourse->setInitialTime(sedUniformTimeCourse->getInitialTime()); uniformTimeCourse->setOutputStartTime(sedUniformTimeCourse->getOutputStartTime()); @@ -180,8 +180,8 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) simulation = uniformTimeCourse; } else if (sedSimulation->isSedOneStep()) { - auto *sedOneStep = reinterpret_cast(sedSimulation); - auto oneStep = SedOneStep::create(pDocument); + auto *sedOneStep {reinterpret_cast(sedSimulation)}; + auto oneStep {SedOneStep::create(pDocument)}; oneStep->setStep(sedOneStep->getStep()); @@ -198,10 +198,10 @@ void SedmlFile::Impl::populateDocument(const SedDocumentPtr &pDocument) // Populate the simulation's algorithm. - auto *sedAlgorithm = sedSimulation->getAlgorithm(); - auto kisaoId = sedAlgorithm->getKisaoID(); - SolverOdePtr odeSolver = nullptr; - SolverNlaPtr nlaSolver = nullptr; + auto *sedAlgorithm {sedSimulation->getAlgorithm()}; + auto kisaoId {sedAlgorithm->getKisaoID()}; + SolverOdePtr odeSolver {nullptr}; + SolverNlaPtr nlaSolver {nullptr}; if (kisaoId == "KISAO:0000019") { odeSolver = SolverCvode::create(); @@ -289,7 +289,7 @@ SedmlFilePtr SedmlFile::create(const FilePtr &pFile) // Try to retrieve a SED-ML document. - auto *document = libsedml::readSedMLFromString(toString(pFile->contents()).c_str()); + auto *document {libsedml::readSedMLFromString(toString(pFile->contents()).c_str())}; // A non-SED-ML file results in our SED-ML document having at least one error. That error may be the result of a // malformed XML file (e.g., an HTML file is an XML-like file but not actually an XML file or a COMBINE archive diff --git a/src/version.cpp b/src/version.cpp index ac4f11a4a..03ab86593 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -49,23 +49,23 @@ limitations under the License. namespace libOpenCOR { -static constexpr unsigned int MAJOR_10 = 1048576; -static constexpr unsigned int MAJOR_01 = 65536; -static constexpr unsigned int MINOR_10 = 4096; -static constexpr unsigned int MINOR_01 = 256; -static constexpr unsigned int PATCH_10 = 16; -static constexpr unsigned int PATCH_01 = 1; +static constexpr unsigned int MAJOR_10 {1048576}; +static constexpr unsigned int MAJOR_01 {65536}; +static constexpr unsigned int MINOR_10 {4096}; +static constexpr unsigned int MINOR_01 {256}; +static constexpr unsigned int PATCH_10 {16}; +static constexpr unsigned int PATCH_01 {1}; unsigned int firstDigit(unsigned int pTwoDigitNumber) { - static constexpr double ONE_TENTH = 0.1; + static constexpr double ONE_TENTH {0.1}; return static_cast(std::floor(ONE_TENTH * pTwoDigitNumber)); } unsigned int secondDigit(unsigned int pTwoDigitNumber) { - static constexpr unsigned int TEN = 10; + static constexpr unsigned int TEN {10}; return pTwoDigitNumber % TEN; } @@ -148,13 +148,13 @@ std::string llvmVersionString() unsigned int sundialsVersion() { - static constexpr int MAJOR = 65536; - static constexpr int MINOR = 256; - static constexpr int LABEL_SIZE = 10; + static constexpr int MAJOR {65536}; + static constexpr int MINOR {256}; + static constexpr int LABEL_SIZE {10}; - int major = 0; - int minor = 0; - int patch = 0; + int major {0}; + int minor {0}; + int patch {0}; std::array label {""}; SUNDIALSGetVersionNumber(&major, &minor, &patch, label.data(), LABEL_SIZE); @@ -164,7 +164,7 @@ unsigned int sundialsVersion() std::string sundialsVersionString() { - static constexpr int VERSION_SIZE = 25; + static constexpr int VERSION_SIZE {25}; std::array version {""}; diff --git a/src/version.in.h b/src/version.in.h index 2ac744caf..fd455dab8 100644 --- a/src/version.in.h +++ b/src/version.in.h @@ -19,9 +19,9 @@ limitations under the License. namespace libOpenCOR { // clang-format off -static constexpr auto LIBOPENCOR_VERSION = @LIBOPENCOR_VERSION@; +static constexpr auto LIBOPENCOR_VERSION {@LIBOPENCOR_VERSION@}; // clang-format on -static constexpr auto LIBOPENCOR_VERSION_STRING = "@LIBOPENCOR_VERSION_STRING@"; +static constexpr auto LIBOPENCOR_VERSION_STRING {"@LIBOPENCOR_VERSION_STRING@"}; unsigned int firstDigit(unsigned int pTwoDigitNumber); unsigned int secondDigit(unsigned int pTwoDigitNumber); diff --git a/tests/api/file/basictests.cpp b/tests/api/file/basictests.cpp index 4abf091df..79108e1d6 100644 --- a/tests/api/file/basictests.cpp +++ b/tests/api/file/basictests.cpp @@ -19,17 +19,17 @@ limitations under the License. #include #include -static const libOpenCOR::ExpectedIssues EXPECTED_NO_ISSUES = {}; -static const libOpenCOR::ExpectedIssues EXPECTED_NON_EXISTING_FILE_ISSUES = { +static const libOpenCOR::ExpectedIssues EXPECTED_NO_ISSUES {}; +static const libOpenCOR::ExpectedIssues EXPECTED_NON_EXISTING_FILE_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The file does not exist."}, -}; -static const libOpenCOR::ExpectedIssues EXPECTED_UNKNOWN_FILE_ISSUES = { +}}; +static const libOpenCOR::ExpectedIssues EXPECTED_UNKNOWN_FILE_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The file is not a CellML file, a SED-ML file, or a COMBINE archive."}, -}; +}}; TEST(BasicFileTest, localFile) { - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); EXPECT_EQ(file->fileName(), libOpenCOR::LOCAL_FILE); @@ -41,11 +41,11 @@ TEST(BasicFileTest, localFile) TEST(BasicSedTest, existingRelativeLocalFile) { - auto origDir = std::filesystem::current_path(); + auto origDir {std::filesystem::current_path()}; std::filesystem::current_path(libOpenCOR::resourcePath()); - auto file = libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE)}; EXPECT_FALSE(file->contents().empty()); EXPECT_EQ_ISSUES(file, EXPECTED_NO_ISSUES); @@ -56,9 +56,9 @@ TEST(BasicSedTest, existingRelativeLocalFile) TEST(BasicFileTest, nonExistingRelativeLocalFile) { #ifdef BUILDING_ON_WINDOWS - auto file = libOpenCOR::File::create(R"(some\.\relative\..\..\path\.\..\dir\file.txt)"); + auto file {libOpenCOR::File::create(R"(some\.\relative\..\..\path\.\..\dir\file.txt)")}; #else - auto file = libOpenCOR::File::create("some/relative/../../path/../dir/file.txt"); + auto file {libOpenCOR::File::create("some/relative/../../path/../dir/file.txt")}; #endif EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); @@ -80,9 +80,9 @@ TEST(BasicFileTest, nonExistingRelativeLocalFile) TEST(BasicFileTest, urlBasedLocalFile) { #ifdef BUILDING_ON_WINDOWS - auto file = libOpenCOR::File::create("file:///P:/some/path/file.txt"); + auto file {libOpenCOR::File::create("file:///P:/some/path/file.txt")}; #else - auto file = libOpenCOR::File::create("file:///some/path/file.txt"); + auto file {libOpenCOR::File::create("file:///some/path/file.txt")}; #endif EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); @@ -95,7 +95,7 @@ TEST(BasicFileTest, urlBasedLocalFile) TEST(BasicFileTest, remoteFile) { - auto file = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); EXPECT_NE(file->fileName(), ""); @@ -106,7 +106,7 @@ TEST(BasicFileTest, remoteFile) TEST(BasicFileTest, encodedRemoteFile) { - auto file = libOpenCOR::File::create(libOpenCOR::ENCODED_REMOTE_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::ENCODED_REMOTE_FILE)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); EXPECT_NE(file->fileName(), ""); @@ -117,7 +117,7 @@ TEST(BasicFileTest, encodedRemoteFile) TEST(BasicFileTest, localVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->fileName(), libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); @@ -126,7 +126,7 @@ TEST(BasicFileTest, localVirtualFile) EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, EXPECTED_NO_ISSUES); - auto someUnknownContents = libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS); + auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS)}; file->setContents(someUnknownContents); @@ -137,7 +137,7 @@ TEST(BasicFileTest, localVirtualFile) TEST(BasicFileTest, remoteVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::UNKNOWN_REMOTE_FILE, false); + auto file {libOpenCOR::File::create(libOpenCOR::UNKNOWN_REMOTE_FILE, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); #ifdef BUILDING_USING_MSVC @@ -150,7 +150,7 @@ TEST(BasicFileTest, remoteVirtualFile) EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, EXPECTED_NO_ISSUES); - auto someUnknownContents = libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS); + auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS)}; file->setContents(someUnknownContents); @@ -161,7 +161,7 @@ TEST(BasicFileTest, remoteVirtualFile) TEST(BasicFileTest, fileManager) { - auto fileManager = libOpenCOR::FileManager::instance(); + auto fileManager {libOpenCOR::FileManager::instance()}; EXPECT_FALSE(fileManager.hasFiles()); EXPECT_EQ(fileManager.fileCount(), 0); @@ -169,8 +169,8 @@ TEST(BasicFileTest, fileManager) EXPECT_EQ(fileManager.file(0), nullptr); EXPECT_EQ(fileManager.file(libOpenCOR::LOCAL_FILE), nullptr); - auto localFile = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - auto sameFileManager = libOpenCOR::FileManager::instance(); + auto localFile {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto sameFileManager {libOpenCOR::FileManager::instance()}; EXPECT_TRUE(sameFileManager.hasFiles()); EXPECT_EQ(sameFileManager.fileCount(), 1); @@ -178,7 +178,7 @@ TEST(BasicFileTest, fileManager) EXPECT_EQ(fileManager.file(0), localFile); EXPECT_EQ(sameFileManager.file(libOpenCOR::LOCAL_FILE), localFile); - auto remoteFile = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); + auto remoteFile {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; EXPECT_TRUE(fileManager.hasFiles()); EXPECT_EQ(fileManager.fileCount(), 2); diff --git a/tests/api/file/childtests.cpp b/tests/api/file/childtests.cpp index e3f080686..e1953b688 100644 --- a/tests/api/file/childtests.cpp +++ b/tests/api/file/childtests.cpp @@ -24,15 +24,15 @@ namespace { void doTestDataset(const std::string &pNumber, const std::vector &pSpecificChildFileNames) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/file/dataset_" + pNumber + ".omex")); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/file/dataset_" + pNumber + ".omex"))}; EXPECT_TRUE(file->hasChildFiles()); EXPECT_EQ(file->childFileCount(), pSpecificChildFileNames.size() + 1); EXPECT_EQ(file->childFileNames().size(), pSpecificChildFileNames.size() + 1); EXPECT_EQ(file->childFiles().size(), pSpecificChildFileNames.size() + 1); - size_t index = std::numeric_limits::max(); - auto simulationFile = file->childFile("simulation.json"); + size_t index {std::numeric_limits::max()}; + auto simulationFile {file->childFile("simulation.json")}; EXPECT_NE(file->childFile(++index), nullptr); EXPECT_NE(simulationFile, nullptr); @@ -52,7 +52,7 @@ void doTestDataset(const std::string &pNumber, const std::vector &p TEST(ChildFileTest, noChildFiles) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; EXPECT_FALSE(file->hasChildFiles()); EXPECT_EQ(file->childFileCount(), 0); diff --git a/tests/api/file/typetests.cpp b/tests/api/file/typetests.cpp index 06f8b67b0..e0ede46ea 100644 --- a/tests/api/file/typetests.cpp +++ b/tests/api/file/typetests.cpp @@ -18,17 +18,17 @@ limitations under the License. #include -static const libOpenCOR::ExpectedIssues EXPECTED_UNKNOWN_FILE_ISSUES = { +static const libOpenCOR::ExpectedIssues EXPECTED_UNKNOWN_FILE_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The file is not a CellML file, a SED-ML file, or a COMBINE archive."}, -}; +}}; TEST(TypeFileTest, irretrievableFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The file does not exist."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); EXPECT_EQ_ISSUES(file, EXPECTED_ISSUES); @@ -36,7 +36,7 @@ TEST(TypeFileTest, irretrievableFile) TEST(TypeFileTest, unknownFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, EXPECTED_UNKNOWN_FILE_ISSUES); @@ -44,7 +44,7 @@ TEST(TypeFileTest, unknownFile) TEST(TypeFileTest, sbmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SBML_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SBML_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, EXPECTED_UNKNOWN_FILE_ISSUES); @@ -52,56 +52,56 @@ TEST(TypeFileTest, sbmlFile) TEST(TypeFileTest, errorSedmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_SEDML_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_SEDML_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, cellml1xFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_1_X_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_1_X_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } TEST(TypeFileTest, sedml1xFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_1_X_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_1_X_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, combine1xArchive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_1_X_ARCHIVE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_1_X_ARCHIVE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::COMBINE_ARCHIVE); } TEST(TypeFileTest, cellml2File) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } TEST(TypeFileTest, sedml2File) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, combine2Archive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE)); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::COMBINE_ARCHIVE); } TEST(TypeFileTest, unknownVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); @@ -114,7 +114,7 @@ TEST(TypeFileTest, unknownVirtualFile) TEST(TypeFileTest, cellmlVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE), false); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE), false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); @@ -126,7 +126,7 @@ TEST(TypeFileTest, cellmlVirtualFile) TEST(TypeFileTest, sedmlVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE), false); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE), false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); @@ -138,7 +138,7 @@ TEST(TypeFileTest, sedmlVirtualFile) TEST(TypeFileTest, combineVirtualArchive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE), false); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE), false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); diff --git a/tests/api/sed/basictests.cpp b/tests/api/sed/basictests.cpp index ee0a5b1f5..95c687df4 100644 --- a/tests/api/sed/basictests.cpp +++ b/tests/api/sed/basictests.cpp @@ -20,39 +20,39 @@ limitations under the License. TEST(BasicSedTest, noFile) { - auto document = libOpenCOR::SedDocument::create(); + auto document {libOpenCOR::SedDocument::create()}; EXPECT_FALSE(document->hasIssues()); } TEST(BasicSedTest, unknownFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using an unknown file."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } TEST(BasicSedTest, cellmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); } TEST(BasicSedTest, sedmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_TRUE(document->hasIssues()); - auto neededFile = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto neededFile {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; document = libOpenCOR::SedDocument::create(file); @@ -61,12 +61,12 @@ TEST(BasicSedTest, sedmlFile) TEST(BasicSedTest, sedmlFileWithAbsoluteCellmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/absolute_cellml_file.sedml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/absolute_cellml_file.sedml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_TRUE(document->hasIssues()); - auto neededFile = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto neededFile {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; document = libOpenCOR::SedDocument::create(file); @@ -75,12 +75,12 @@ TEST(BasicSedTest, sedmlFileWithAbsoluteCellmlFile) TEST(BasicSedTest, sedmlFileWithRemoteCellmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/remote_cellml_file.sedml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/remote_cellml_file.sedml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_TRUE(document->hasIssues()); - auto neededFile = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); + auto neededFile {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; document = libOpenCOR::SedDocument::create(file); @@ -89,60 +89,60 @@ TEST(BasicSedTest, sedmlFileWithRemoteCellmlFile) TEST(BasicSedTest, combineArchive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); } TEST(BasicSedTest, combineArchiveWithNoManifestFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using a COMBINE archive with no master file."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/no_manifest_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/no_manifest_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } TEST(BasicSedTest, combineArchiveWithNoMasterFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using a COMBINE archive with no master file."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/no_master_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/no_master_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } TEST(BasicSedTest, combineArchiveWithUnknownDirectCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using a COMBINE archive with an unknown master file (only CellML and SED-ML master files are supported)."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_direct_cellml_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_direct_cellml_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } TEST(BasicSedTest, combineArchiveWithUnknownIndirectCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "Task 'task1' requires a model of CellML type."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_indirect_cellml_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_indirect_cellml_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); @@ -151,24 +151,24 @@ TEST(BasicSedTest, combineArchiveWithUnknownIndirectCellmlFile) TEST(BasicSedTest, combineArchiveWithUnknownSedmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using a COMBINE archive with an unknown master file (only CellML and SED-ML master files are supported)."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_sedml_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unknown_sedml_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } TEST(BasicSedTest, irretrievableFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using an irretrievable file."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } diff --git a/tests/api/sed/coveragetests.cpp b/tests/api/sed/coveragetests.cpp index 7a380df95..fec6c24f3 100644 --- a/tests/api/sed/coveragetests.cpp +++ b/tests/api/sed/coveragetests.cpp @@ -20,30 +20,30 @@ limitations under the License. #include -static const auto NoDoubles = std::vector {}; +static const auto NoDoubles {std::vector {}}; TEST(CoverageSedTest, initialise) { - static const std::string expectedSerialisation = R"( + static const std::string expectedSerialisation {R"( -)"; +)"}; - auto document = libOpenCOR::SedDocument::create(); + auto document {libOpenCOR::SedDocument::create()}; EXPECT_EQ(document->serialise(), expectedSerialisation); } TEST(CoverageSedTest, models) { - auto document = libOpenCOR::SedDocument::create(); + auto document {libOpenCOR::SedDocument::create()}; EXPECT_FALSE(document->hasModels()); EXPECT_EQ(document->modelCount(), 0); EXPECT_EQ(document->models().size(), 0); EXPECT_FALSE(document->addModel(nullptr)); - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - auto model = libOpenCOR::SedModel::create(document, file); + auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto model {libOpenCOR::SedModel::create(document, file)}; EXPECT_EQ(model->file(), file); @@ -75,7 +75,7 @@ TEST(CoverageSedTest, models) EXPECT_FALSE(model->addChange(nullptr)); EXPECT_FALSE(model->removeAllChanges()); - auto changeAttribute = libOpenCOR::SedChangeAttribute::create("component", "variable", "newValue"); + auto changeAttribute {libOpenCOR::SedChangeAttribute::create("component", "variable", "newValue")}; EXPECT_TRUE(model->addChange(changeAttribute)); @@ -151,8 +151,8 @@ std::string sedChangesExpectedSerialisation(const std::string &pSource, const st TEST(CoverageSedTest, changes) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/sed_changes.omex")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/sed_changes.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); EXPECT_EQ(document->serialise(), sedChangesExpectedSerialisation(file->childFile(1)->path(), R"( @@ -161,7 +161,7 @@ TEST(CoverageSedTest, changes) )")); - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_1 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_1 {{ {libOpenCOR::Issue::Type::ERROR, "The component and variable names could not be retrieved for the change of type 'changeAttribute' and of target 'invalidTarget'."}, {libOpenCOR::Issue::Type::ERROR, "The new value 'invalidNewValue' for the change of type 'changeAttribute' is not a valid double value."}, {libOpenCOR::Issue::Type::ERROR, "The component and variable names could not be retrieved for the change of type 'changeAttribute' and of target '/cellml:model/cellml:component[@name=''."}, @@ -169,7 +169,7 @@ TEST(CoverageSedTest, changes) {libOpenCOR::Issue::Type::ERROR, "The component and variable names could not be retrieved for the change of type 'changeAttribute' and of target '/cellml:model/cellml:component[@name='componentName']/cellml:variable[@name=''."}, {libOpenCOR::Issue::Type::ERROR, "The component and variable names could not be retrieved for the change of type 'changeAttribute' and of target '/cellml:model/cellml:component[@name='componentName']/cellml:variable[@name='variableName'."}, {libOpenCOR::Issue::Type::ERROR, "The component and variable names could not be retrieved for the change of type 'changeAttribute' and of target '/cellml:model/cellml:component[@name='componentName']/cellml:variable[@name='variableName']Invalid'."}, - }; + }}; file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/invalid_sed_changes.omex")); document = libOpenCOR::SedDocument::create(file); @@ -179,12 +179,12 @@ TEST(CoverageSedTest, changes) )")); - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_2 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_2 {{ {libOpenCOR::Issue::Type::WARNING, "Only changes of type 'changeAttribute' are currently supported. The change of type 'addXML' has been ignored."}, {libOpenCOR::Issue::Type::WARNING, "Only changes of type 'changeAttribute' are currently supported. The change of type 'changeXML' has been ignored."}, {libOpenCOR::Issue::Type::WARNING, "Only changes of type 'changeAttribute' are currently supported. The change of type 'removeXML' has been ignored."}, {libOpenCOR::Issue::Type::WARNING, "Only changes of type 'changeAttribute' are currently supported. The change of type 'computeChange' has been ignored."}, - }; + }}; file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unsupported_sed_changes.omex")); document = libOpenCOR::SedDocument::create(file); @@ -195,17 +195,17 @@ TEST(CoverageSedTest, changes) TEST(CoverageSedTest, simulations) { - auto document = libOpenCOR::SedDocument::create(); + auto document {libOpenCOR::SedDocument::create()}; EXPECT_FALSE(document->hasSimulations()); EXPECT_EQ(document->simulationCount(), 0); EXPECT_EQ(document->simulations().size(), 0); EXPECT_FALSE(document->addSimulation(nullptr)); - auto uniformTimeCourse = libOpenCOR::SedUniformTimeCourse::create(document); - auto oneStep = libOpenCOR::SedOneStep::create(document); - auto steadyState = libOpenCOR::SedSteadyState::create(document); - auto analysis = libOpenCOR::SedAnalysis::create(document); + auto uniformTimeCourse {libOpenCOR::SedUniformTimeCourse::create(document)}; + auto oneStep {libOpenCOR::SedOneStep::create(document)}; + auto steadyState {libOpenCOR::SedSteadyState::create(document)}; + auto analysis {libOpenCOR::SedAnalysis::create(document)}; EXPECT_TRUE(document->addSimulation(uniformTimeCourse)); EXPECT_TRUE(document->addSimulation(oneStep)); @@ -267,17 +267,17 @@ std::string sedTaskExpectedSerialisation(bool pWithProperties) TEST(CoverageSedTest, tasks) { - auto document = libOpenCOR::SedDocument::create(); + auto document {libOpenCOR::SedDocument::create()}; EXPECT_FALSE(document->hasTasks()); EXPECT_EQ(document->taskCount(), 0); EXPECT_EQ(document->tasks().size(), 0); EXPECT_FALSE(document->addTask(nullptr)); - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto model = libOpenCOR::SedModel::create(document, file); - auto simulation = libOpenCOR::SedUniformTimeCourse::create(document); - auto task = libOpenCOR::SedTask::create(document, model, simulation); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto model {libOpenCOR::SedModel::create(document, file)}; + auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; + auto task {libOpenCOR::SedTask::create(document, model, simulation)}; EXPECT_EQ(task->model(), model); EXPECT_EQ(task->simulation(), simulation); @@ -301,12 +301,12 @@ TEST(CoverageSedTest, tasks) EXPECT_EQ(document->serialise(), sedTaskExpectedSerialisation(false)); - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "Task 'task1' requires a model."}, {libOpenCOR::Issue::Type::ERROR, "Task 'task1' requires a simulation."}, - }; + }}; - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); @@ -326,12 +326,12 @@ TEST(CoverageSedTest, tasks) TEST(CoverageSedTest, odeSolver) { - auto document = libOpenCOR::SedDocument::create(); - auto simulation = libOpenCOR::SedUniformTimeCourse::create(document); + auto document {libOpenCOR::SedDocument::create()}; + auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; EXPECT_EQ(simulation->odeSolver(), nullptr); - auto solver = libOpenCOR::SolverCvode::create(); + auto solver {libOpenCOR::SolverCvode::create()}; simulation->setOdeSolver(solver); @@ -344,12 +344,12 @@ TEST(CoverageSedTest, odeSolver) TEST(CoverageSedTest, nlaSolver) { - auto document = libOpenCOR::SedDocument::create(); - auto simulation = libOpenCOR::SedUniformTimeCourse::create(document); + auto document {libOpenCOR::SedDocument::create()}; + auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; EXPECT_EQ(simulation->nlaSolver(), nullptr); - auto solver = libOpenCOR::SolverKinsol::create(); + auto solver {libOpenCOR::SolverKinsol::create()}; simulation->setNlaSolver(solver); @@ -362,20 +362,20 @@ TEST(CoverageSedTest, nlaSolver) TEST(CoverageSedTest, sedBase) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = libOpenCOR::SedOneStep::create(document); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {libOpenCOR::SedOneStep::create(document)}; EXPECT_EQ(simulation->id(), "simulation2"); } TEST(CoverageSedTest, sedOneStep) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = libOpenCOR::SedOneStep::create(document); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {libOpenCOR::SedOneStep::create(document)}; - static const auto STEP = 1.23; + static const auto STEP {1.23}; EXPECT_EQ(simulation->step(), 1.0); @@ -386,14 +386,14 @@ TEST(CoverageSedTest, sedOneStep) TEST(CoverageSedTest, sedUniformTimeCourse) { - static const auto INITIAL_TIME = 1.23; - static const auto OUTPUT_START_TIME = 4.56; - static const auto OUTPUT_END_TIME = 7.89; - static const auto NUMBER_OF_STEPS = 10; + static const auto INITIAL_TIME {1.23}; + static const auto OUTPUT_START_TIME {4.56}; + static const auto OUTPUT_END_TIME {7.89}; + static const auto NUMBER_OF_STEPS {10}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = libOpenCOR::SedUniformTimeCourse::create(document); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; EXPECT_EQ(simulation->initialTime(), 0.0); EXPECT_EQ(simulation->outputStartTime(), 0.0); @@ -413,20 +413,20 @@ TEST(CoverageSedTest, sedUniformTimeCourse) TEST(CoverageSedTest, sedInstanceAndSedInstanceTaskDifferentialModel) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to -1. It must be between 0 and 3."}, - }; - static const auto UPPER_HALF_BANDWIDTH = -1; + }}; + static const auto UPPER_HALF_BANDWIDTH {-1}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto solver = std::dynamic_pointer_cast(document->simulations()[0]->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto solver {std::dynamic_pointer_cast(document->simulations()[0]->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); solver->setUpperHalfBandwidth(UPPER_HALF_BANDWIDTH); - auto instance = document->instantiate(); - auto instanceTask = instance->tasks()[0]; + auto instance {document->instantiate()}; + auto instanceTask {instance->tasks()[0]}; EXPECT_EQ(instance->hasTasks(), true); EXPECT_EQ(instance->taskCount(), 1); @@ -484,11 +484,11 @@ TEST(CoverageSedTest, sedInstanceAndSedInstanceTaskDifferentialModel) TEST(CoverageSedTest, sedInstanceAndSedInstanceTaskNonDifferentialModel) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; - auto instance = document->instantiate(); - auto instanceTask = instance->tasks()[0]; + auto instance {document->instantiate()}; + auto instanceTask {instance->tasks()[0]}; EXPECT_EQ(instanceTask->voi(), NoDoubles); EXPECT_EQ(instanceTask->voiName(), ""); @@ -507,7 +507,7 @@ TEST(CoverageSedTest, sedInstanceAndSedInstanceTaskNonDifferentialModel) TEST(CoverageSedTest, sedDocument) { - auto file = libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_CELLML_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_CELLML_FILE)}; libOpenCOR::SedDocument::create(file); file = libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_SEDML_FILE); @@ -521,12 +521,12 @@ TEST(CoverageSedTest, solver) { // Get the duplicate() method of different solvers to be covered. - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; document->simulations()[0]->setOdeSolver(libOpenCOR::SolverForwardEuler::create()); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); @@ -559,10 +559,10 @@ TEST(CoverageSedTest, solver) TEST(CoverageSedTest, math) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/math.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); - auto instanceTask = instance->tasks()[0]; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/math.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; + auto instanceTask {instance->tasks()[0]}; EXPECT_EQ(instanceTask->constantCount(), 0); EXPECT_EQ(instanceTask->computedConstantCount(), 37); @@ -570,19 +570,19 @@ TEST(CoverageSedTest, math) instance->run(); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({243.0, 3.0, 7.0, 20.085536923187668, 1.0986122886681098, 0.47712125471966244, 4.0, 3.0, 3.0, 5.0, - 3.0, 0.14112000805986721, -0.98999249660044542, -0.1425465430742778, -1.0101086659079939, - 7.0861673957371867, -7.0152525514345339, 10.017874927409903, 10.067661995777765, - 0.99505475368673046, 0.099327927419433207, 0.099821569668822732, 1.0049698233136892, - 0.30469265401539747, 1.266103672779499, 1.2490457723982544, 1.2309594173407747, - 0.33983690945412193, 0.32175055439664219, 1.8184464592320668, 1.7627471740390861, - 0.30951960420311175, 1.8738202425274144, 0.32745015023725843, 0.34657359027997264, - std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, - 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, - 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, - 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, - 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001}); + static const auto COMPUTED_CONSTANT_VALUES {std::vector({243.0, 3.0, 7.0, 20.085536923187668, 1.0986122886681098, 0.47712125471966244, 4.0, 3.0, 3.0, 5.0, + 3.0, 0.14112000805986721, -0.98999249660044542, -0.1425465430742778, -1.0101086659079939, + 7.0861673957371867, -7.0152525514345339, 10.017874927409903, 10.067661995777765, + 0.99505475368673046, 0.099327927419433207, 0.099821569668822732, 1.0049698233136892, + 0.30469265401539747, 1.266103672779499, 1.2490457723982544, 1.2309594173407747, + 0.33983690945412193, 0.32175055439664219, 1.8184464592320668, 1.7627471740390861, + 0.30951960420311175, 1.8738202425274144, 0.32745015023725843, 0.34657359027997264, + std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, + 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, + 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, + 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001, + 0.0000001, 0.0000001, 0.0000001, 0.0000001, 0.0000001})}; EXPECT_EQ_VALUES(instanceTask, 0, {}, {}, {}, {}, {}, {}, COMPUTED_CONSTANT_VALUES, COMPUTED_CONSTANT_ABS_TOLS, {}, {}); } diff --git a/tests/api/sed/instancetests.cpp b/tests/api/sed/instancetests.cpp index f08f1c537..4969f6357 100644 --- a/tests/api/sed/instancetests.cpp +++ b/tests/api/sed/instancetests.cpp @@ -20,78 +20,78 @@ limitations under the License. TEST(InstanceSedTest, noFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The simulation experiment description does not contain any tasks to run."}, - }; + }}; - auto document = libOpenCOR::SedDocument::create(); - auto instance = document->instantiate(); + auto document {libOpenCOR::SedDocument::create()}; + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, invalidCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The CellML file is invalid."}, {libOpenCOR::Issue::Type::ERROR, "Equation 'x+y+z' in component 'my_component' is not an equality statement (i.e. LHS = RHS)."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_CELLML_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_CELLML_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, overconstrainedCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The CellML file is overconstrained."}, {libOpenCOR::Issue::Type::ERROR, "Variable 'x' in component 'my_component' is computed more than once."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/overconstrained.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/overconstrained.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, underconstrainedCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The CellML file is underconstrained."}, {libOpenCOR::Issue::Type::ERROR, "The type of variable 'x' in component 'my_component' is unknown."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/underconstrained.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/underconstrained.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, unsuitablyConstrainedCellmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The CellML file is unsuitably constrained."}, {libOpenCOR::Issue::Type::ERROR, "Variable 'y' in component 'my_component' is computed more than once."}, {libOpenCOR::Issue::Type::ERROR, "The type of variable 'x' in component 'my_component' is unknown."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unsuitably_constrained.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/unsuitably_constrained.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, algebraicModel) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/algebraic.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/algebraic.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; instance->run(); @@ -100,7 +100,7 @@ TEST(InstanceSedTest, algebraicModel) TEST(InstanceSedTest, odeModel) { - const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ #ifdef BUILDING_ON_INTEL {libOpenCOR::Issue::Type::ERROR, "At t = 0.00140013827899996, mxstep steps taken before reaching tout."}, #else @@ -112,19 +112,19 @@ TEST(InstanceSedTest, odeModel) # endif }, #endif - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; - static const auto NOK_MAXIMUM_NUMBER_OF_STEPS = 10; + static const auto NOK_MAXIMUM_NUMBER_OF_STEPS {10}; - auto cvode = std::dynamic_pointer_cast(simulation->odeSolver()); + auto cvode {std::dynamic_pointer_cast(simulation->odeSolver())}; cvode->setMaximumNumberOfSteps(NOK_MAXIMUM_NUMBER_OF_STEPS); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_FALSE(instance->hasIssues()); @@ -132,7 +132,7 @@ TEST(InstanceSedTest, odeModel) EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); - static const auto OK_MAXIMUM_NUMBER_OF_STEPS = 500; + static const auto OK_MAXIMUM_NUMBER_OF_STEPS {500}; cvode->setMaximumNumberOfSteps(OK_MAXIMUM_NUMBER_OF_STEPS); @@ -145,35 +145,35 @@ TEST(InstanceSedTest, odeModel) TEST(InstanceSedTest, odeModelWithNoOdeSolver) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "Simulation 'simulation1' is to be used with model 'model1' which requires an ODE solver but none is provided."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; document->simulations()[0]->setOdeSolver(nullptr); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, nlaModel) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to -1. It must be between 0 and 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto kinsol = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto kinsol {std::dynamic_pointer_cast(simulation->nlaSolver())}; kinsol->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); kinsol->setUpperHalfBandwidth(-1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); @@ -186,35 +186,35 @@ TEST(InstanceSedTest, nlaModel) TEST(InstanceSedTest, nlaModelWithNoNlaSolver) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "Simulation 'simulation1' is to be used with model 'model1' which requires an NLA solver but none is provided."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; document->simulations()[0]->setNlaSolver(nullptr); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, daeModel) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to -1. It must be between 0 and 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto kinsol = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto kinsol {std::dynamic_pointer_cast(simulation->nlaSolver())}; kinsol->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); kinsol->setUpperHalfBandwidth(-1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); @@ -233,28 +233,28 @@ TEST(InstanceSedTest, daeModel) TEST(InstanceSedTest, daeModelWithNoOdeOrNlaSolver) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "Simulation 'simulation1' is to be used with model 'model1' which requires an ODE solver but none is provided."}, {libOpenCOR::Issue::Type::ERROR, "Simulation 'simulation1' is to be used with model 'model1' which requires an NLA solver but none is provided."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; simulation->setOdeSolver(nullptr); simulation->setNlaSolver(nullptr); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(InstanceSedTest, combineArchive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE)); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; instance->run(); @@ -263,9 +263,9 @@ TEST(InstanceSedTest, combineArchive) TEST(InstanceSedTest, combineArchiveWithCellmlFileAsMasterFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/cellml_file_as_master_file.omex")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/cellml_file_as_master_file.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; EXPECT_FALSE(instance->hasIssues()); } diff --git a/tests/api/sed/serialisetests.cpp b/tests/api/sed/serialisetests.cpp index 1f1c3d82a..862ae3f9b 100644 --- a/tests/api/sed/serialisetests.cpp +++ b/tests/api/sed/serialisetests.cpp @@ -22,11 +22,11 @@ namespace { std::string cvodeExpectedSerialisation(const std::string &pSource, const std::map &pParameters = {}) { - auto integrationMethod = pParameters.find("KISAO:0000475"); - auto iterationType = pParameters.find("KISAO:0000476"); - auto linearSolver = pParameters.find("KISAO:0000477"); - auto preconditioner = pParameters.find("KISAO:0000478"); - auto interpolateSolution = pParameters.find("KISAO:0000481"); + auto integrationMethod {pParameters.find("KISAO:0000475")}; + auto iterationType {pParameters.find("KISAO:0000476")}; + auto linearSolver {pParameters.find("KISAO:0000477")}; + auto preconditioner {pParameters.find("KISAO:0000478")}; + auto interpolateSolution {pParameters.find("KISAO:0000481")}; return std::string(R"( @@ -73,7 +73,7 @@ std::string cvodeExpectedSerialisation(const std::string &pSource, const std::ma std::string kinsolExpectedSerialisation(const std::map &pParameters = {}) { - auto linearSolver = pParameters.find("KISAO:0000477"); + auto linearSolver {pParameters.find("KISAO:0000477")}; return std::string(R"( @@ -105,19 +105,19 @@ std::string kinsolExpectedSerialisation(const std::map TEST(SerialiseSedTest, localCellmlFileWithBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), cvodeExpectedSerialisation("cellml_2.cellml")); } TEST(SerialiseSedTest, localCellmlFileWithoutBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::CELLML_CONTENTS)); - auto document = libOpenCOR::SedDocument::create(file); + auto document {libOpenCOR::SedDocument::create(file)}; #ifdef BUILDING_USING_MSVC EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation("file:///P:/some/path/file.txt")); @@ -128,50 +128,50 @@ TEST(SerialiseSedTest, localCellmlFileWithoutBasePath) TEST(SerialiseSedTest, relativeLocalCellmlFileWithBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(std::string(libOpenCOR::RESOURCE_LOCATION).append("/../..")), cvodeExpectedSerialisation("tests/res/cellml_2.cellml")); } TEST(SerialiseSedTest, relativeLocalCellmlFileWithoutBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE); + auto file {libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE)}; file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::CELLML_CONTENTS)); - auto document = libOpenCOR::SedDocument::create(file); + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation("cellml_2.cellml")); } TEST(SerialiseSedTest, remoteCellmlFileWithBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::REMOTE_BASE_PATH), cvodeExpectedSerialisation("cellml_2.cellml")); } TEST(SerialiseSedTest, remoteCellmlFileWithoutBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation("https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml")); } TEST(SerialiseSedTest, relativeRemoteCellmlFileWithBasePath) { - auto file = libOpenCOR::File::create(libOpenCOR::REMOTE_FILE); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(std::string(libOpenCOR::REMOTE_BASE_PATH).append("/../..")), cvodeExpectedSerialisation("tests/res/cellml_2.cellml")); } TEST(SerialiseSedTest, daeModel) { - static const std::string expectedSerialisation = R"( + static const std::string expectedSerialisation {R"( @@ -207,25 +207,25 @@ TEST(SerialiseSedTest, daeModel) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), expectedSerialisation); } TEST(SerialiseSedTest, nlaModel) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), kinsolExpectedSerialisation()); } TEST(SerialiseSedTest, algebraicModel) { - static const std::string expectedSerialisation = R"( + static const std::string expectedSerialisation {R"( @@ -237,10 +237,10 @@ TEST(SerialiseSedTest, algebraicModel) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/algebraic.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/algebraic.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), expectedSerialisation); } @@ -278,16 +278,16 @@ std::string sedChangeExpectedSerialisation(const std::string &pComponent, const TEST(SerialiseSedTest, modelWithChanges) { - auto changeAttribute = libOpenCOR::SedChangeAttribute::create("component", "variable", "123.456789"); + auto changeAttribute {libOpenCOR::SedChangeAttribute::create("component", "variable", "123.456789")}; EXPECT_EQ(changeAttribute->target(), "/cellml:model/cellml:component[@name='component']/cellml:variable[@name='variable']"); EXPECT_EQ(changeAttribute->componentName(), "component"); EXPECT_EQ(changeAttribute->variableName(), "variable"); EXPECT_EQ(changeAttribute->newValue(), "123.456789"); - auto document = libOpenCOR::SedDocument::create(); - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - auto model = libOpenCOR::SedModel::create(document, file); + auto document {libOpenCOR::SedDocument::create()}; + auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto model {libOpenCOR::SedModel::create(document, file)}; EXPECT_TRUE(model->addChange(changeAttribute)); EXPECT_TRUE(document->addModel(model)); @@ -308,7 +308,7 @@ TEST(SerialiseSedTest, modelWithChanges) TEST(SerialiseSedTest, fixedStepOdeSolver) { - static const std::string expectedSerialisation = R"( + static const std::string expectedSerialisation {R"( @@ -326,11 +326,11 @@ TEST(SerialiseSedTest, fixedStepOdeSolver) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; simulation->setOdeSolver(libOpenCOR::SolverForwardEuler::create()); @@ -339,10 +339,10 @@ TEST(SerialiseSedTest, fixedStepOdeSolver) TEST(SerialiseSedTest, cvodeSolverWithAdamsMoultonInterationMethod) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setIntegrationMethod(libOpenCOR::SolverCvode::IntegrationMethod::ADAMS_MOULTON); @@ -351,10 +351,10 @@ TEST(SerialiseSedTest, cvodeSolverWithAdamsMoultonInterationMethod) TEST(SerialiseSedTest, cvodeSolverWithFunctionalIterationType) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setIterationType(libOpenCOR::SolverCvode::IterationType::FUNCTIONAL); @@ -363,10 +363,10 @@ TEST(SerialiseSedTest, cvodeSolverWithFunctionalIterationType) TEST(SerialiseSedTest, cvodeSolverWithBandedLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); @@ -375,10 +375,10 @@ TEST(SerialiseSedTest, cvodeSolverWithBandedLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithDiagonalLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::DIAGONAL); @@ -387,10 +387,10 @@ TEST(SerialiseSedTest, cvodeSolverWithDiagonalLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithGmresLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::GMRES); @@ -399,10 +399,10 @@ TEST(SerialiseSedTest, cvodeSolverWithGmresLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithBicgstabLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BICGSTAB); @@ -411,10 +411,10 @@ TEST(SerialiseSedTest, cvodeSolverWithBicgstabLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithTfqmrLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::TFQMR); @@ -423,10 +423,10 @@ TEST(SerialiseSedTest, cvodeSolverWithTfqmrLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithNoPreconditioner) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setPreconditioner(libOpenCOR::SolverCvode::Preconditioner::NO); @@ -435,10 +435,10 @@ TEST(SerialiseSedTest, cvodeSolverWithNoPreconditioner) TEST(SerialiseSedTest, cvodeSolverWithNoInterpolateSolution) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setInterpolateSolution(false); @@ -447,10 +447,10 @@ TEST(SerialiseSedTest, cvodeSolverWithNoInterpolateSolution) TEST(SerialiseSedTest, kinsolWithBandedLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); @@ -459,10 +459,10 @@ TEST(SerialiseSedTest, kinsolWithBandedLinearSolver) TEST(SerialiseSedTest, kinsolWithGmresLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::GMRES); @@ -471,10 +471,10 @@ TEST(SerialiseSedTest, kinsolWithGmresLinearSolver) TEST(SerialiseSedTest, kinsolWithBicgstabLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BICGSTAB); @@ -483,10 +483,10 @@ TEST(SerialiseSedTest, kinsolWithBicgstabLinearSolver) TEST(SerialiseSedTest, kinsolWithTfmqrLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = document->simulations()[0]; - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/nla.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {document->simulations()[0]}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::TFQMR); @@ -495,7 +495,7 @@ TEST(SerialiseSedTest, kinsolWithTfmqrLinearSolver) TEST(SerialiseSedTest, oneStepSimulation) { - static const std::string expectedSerialisation = R"( + static const std::string expectedSerialisation {R"( @@ -507,14 +507,14 @@ TEST(SerialiseSedTest, oneStepSimulation) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; document->removeSimulation(document->simulations()[0]); - auto simulation = libOpenCOR::SedOneStep::create(document); + auto simulation {libOpenCOR::SedOneStep::create(document)}; document->addSimulation(simulation); @@ -523,10 +523,10 @@ TEST(SerialiseSedTest, oneStepSimulation) TEST(SerialiseSedTest, sedmlFile) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::WARNING, "The model 'cellml_2.cellml' could not be found in the file manager. It has been automatically added to it."}, - }; - static const std::string expectedSerialisation = R"( + }}; + static const std::string expectedSerialisation {R"( @@ -554,10 +554,10 @@ TEST(SerialiseSedTest, sedmlFile) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE)); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), expectedSerialisation); @@ -565,7 +565,7 @@ TEST(SerialiseSedTest, sedmlFile) TEST(SerialiseSedTest, sedSimulation) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::WARNING, "The solver 'KISAO:1234567' is not recognised. The CVODE solver will be used instead."}, {libOpenCOR::Issue::Type::WARNING, "The parameter 'KISAO:1234567' is not recognised. It will be ignored."}, {libOpenCOR::Issue::Type::WARNING, "The step ('KISAO:0000483') cannot be equal to '-1.23'. It must be greater or equal to 0. A step of 1 will be used instead."}, @@ -606,8 +606,8 @@ TEST(SerialiseSedTest, sedSimulation) {libOpenCOR::Issue::Type::WARNING, "The upper half-bandwidth ('KISAO:0000479') cannot be equal to '1234567890123'. It must be greater or equal to 0. An upper half-bandwidth of 0 will be used instead."}, {libOpenCOR::Issue::Type::WARNING, "The lower half-bandwidth ('KISAO:0000480') cannot be equal to '1234567890123'. It must be greater or equal to 0. A lower half-bandwidth of 0 will be used instead."}, {libOpenCOR::Issue::Type::WARNING, "The linear solver ('KISAO:0000477') cannot be equal to 'Unknown'. It must be equal to 'Dense', 'Banded', 'GMRES', 'BiCGStab', or 'TFQMR'. A Dense linear solver will be used instead."}, - }; - static const std::string expectedSerialisation = R"( + }}; + static const std::string expectedSerialisation {R"( @@ -843,10 +843,10 @@ TEST(SerialiseSedTest, sedSimulation) -)"; +)"}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/simulations.sedml")); - auto document = libOpenCOR::SedDocument::create(file); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/simulations.sedml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; // EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), expectedSerialisation); diff --git a/tests/api/solver/basictests.cpp b/tests/api/solver/basictests.cpp index 56dff73e2..b3fa90f85 100644 --- a/tests/api/solver/basictests.cpp +++ b/tests/api/solver/basictests.cpp @@ -20,19 +20,19 @@ limitations under the License. TEST(BasicSolverTest, SolverCvode) { - static const auto MAXIMUM_STEP = 1.23; - static const auto MAXIMUM_NUMBER_OF_STEPS = 123; - static const auto INTEGRATION_METHOD = libOpenCOR::SolverCvode::IntegrationMethod::ADAMS_MOULTON; - static const auto ITERATION_TYPE = libOpenCOR::SolverCvode::IterationType::FUNCTIONAL; - static const auto LINEAR_SOLVER = libOpenCOR::SolverCvode::LinearSolver::GMRES; - static const auto PRECONDITIONER = libOpenCOR::SolverCvode::Preconditioner::NO; - static const auto UPPER_HALF_BANDWIDTH = 3; - static const auto LOWER_HALF_BANDWIDTH = 5; - static const auto RELATIVE_TOLERANCE = 1.23e-5; - static const auto ABSOLUTE_TOLERANCE = 3.45e-7; - static const auto INTERPOLATE_SOLUTION = false; - - auto solver = libOpenCOR::SolverCvode::create(); + static const auto MAXIMUM_STEP {1.23}; + static const auto MAXIMUM_NUMBER_OF_STEPS {123}; + static const auto INTEGRATION_METHOD {libOpenCOR::SolverCvode::IntegrationMethod::ADAMS_MOULTON}; + static const auto ITERATION_TYPE {libOpenCOR::SolverCvode::IterationType::FUNCTIONAL}; + static const auto LINEAR_SOLVER {libOpenCOR::SolverCvode::LinearSolver::GMRES}; + static const auto PRECONDITIONER {libOpenCOR::SolverCvode::Preconditioner::NO}; + static const auto UPPER_HALF_BANDWIDTH {3}; + static const auto LOWER_HALF_BANDWIDTH {5}; + static const auto RELATIVE_TOLERANCE {1.23e-5}; + static const auto ABSOLUTE_TOLERANCE {3.45e-7}; + static const auto INTERPOLATE_SOLUTION {false}; + + auto solver {libOpenCOR::SolverCvode::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::ODE); EXPECT_EQ(solver->id(), "KISAO:0000019"); @@ -77,9 +77,9 @@ TEST(BasicSolverTest, SolverCvode) TEST(BasicSolverTest, SolverForwardEuler) { - static const auto STEP = 0.123; + static const auto STEP {0.123}; - auto solver = libOpenCOR::SolverForwardEuler::create(); + auto solver {libOpenCOR::SolverForwardEuler::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::ODE); EXPECT_EQ(solver->id(), "KISAO:0000030"); @@ -94,9 +94,9 @@ TEST(BasicSolverTest, SolverForwardEuler) TEST(BasicSolverTest, SolverFourthOrderRungeKutta) { - static const auto STEP = 0.123; + static const auto STEP {0.123}; - auto solver = libOpenCOR::SolverFourthOrderRungeKutta::create(); + auto solver {libOpenCOR::SolverFourthOrderRungeKutta::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::ODE); EXPECT_EQ(solver->id(), "KISAO:0000032"); @@ -111,9 +111,9 @@ TEST(BasicSolverTest, SolverFourthOrderRungeKutta) TEST(BasicSolverTest, SolverHeun) { - static const auto STEP = 0.123; + static const auto STEP {0.123}; - auto solver = libOpenCOR::SolverHeun::create(); + auto solver {libOpenCOR::SolverHeun::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::ODE); EXPECT_EQ(solver->id(), "KISAO:0000301"); @@ -128,12 +128,12 @@ TEST(BasicSolverTest, SolverHeun) TEST(BasicSolverTest, SolverKinsol) { - static const auto MAXIMUM_NUMBER_OF_ITERATIONS = 123; - static const auto LINEAR_SOLVER = libOpenCOR::SolverKinsol::LinearSolver::GMRES; - static const auto UPPER_HALF_BANDWIDTH = 3; - static const auto LOWER_HALF_BANDWIDTH = 5; + static const auto MAXIMUM_NUMBER_OF_ITERATIONS {123}; + static const auto LINEAR_SOLVER {libOpenCOR::SolverKinsol::LinearSolver::GMRES}; + static const auto UPPER_HALF_BANDWIDTH {3}; + static const auto LOWER_HALF_BANDWIDTH {5}; - auto solver = libOpenCOR::SolverKinsol::create(); + auto solver {libOpenCOR::SolverKinsol::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::NLA); EXPECT_EQ(solver->id(), "KISAO:0000282"); @@ -157,9 +157,9 @@ TEST(BasicSolverTest, SolverKinsol) TEST(BasicSolverTest, SolverSecondOrderRungeKutta) { - static const auto STEP = 0.123; + static const auto STEP {0.123}; - auto solver = libOpenCOR::SolverSecondOrderRungeKutta::create(); + auto solver {libOpenCOR::SolverSecondOrderRungeKutta::create()}; EXPECT_EQ(solver->type(), libOpenCOR::Solver::Type::ODE); EXPECT_EQ(solver->id(), "KISAO:0000381"); diff --git a/tests/api/solver/coveragetests.cpp b/tests/api/solver/coveragetests.cpp index 5eb17d862..860687f6c 100644 --- a/tests/api/solver/coveragetests.cpp +++ b/tests/api/solver/coveragetests.cpp @@ -22,16 +22,16 @@ limitations under the License. TEST(CoverageSolverTest, odeChanges) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::WARNING, "The variable of integration 'time' in component 'environment'cannot be changed. Only state variables and constants can be changed."}, {libOpenCOR::Issue::Type::WARNING, "The variable 'membrane' in component 'X'could not be found and therefore could not be changed."}, {libOpenCOR::Issue::Type::WARNING, "The computed constant 'E_Na' in component 'sodium_channel' cannot be changed. Only state variables and constants can be changed."}, {libOpenCOR::Issue::Type::WARNING, "The algebraic variable 'i_Stim' in component 'membrane' cannot be changed. Only state variables and constants can be changed."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode_sed_changes.omex")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode_sed_changes.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; instance->run(); @@ -61,15 +61,15 @@ TEST(CoverageSolverTest, algebraicChanges) // • y = -356/27 = -13.185185185185185 // • z = -760/27 = -28.148148148148145 - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/algebraic_sed_changes.omex")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/algebraic_sed_changes.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; instance->run(); - static const auto ABS_TOL = 1e-05; + static const auto ABS_TOL {1e-05}; - auto instanceTask = instance->tasks()[0]; + auto instanceTask {instance->tasks()[0]}; EXPECT_EQ(instanceTask->stateCount(), 0); EXPECT_EQ(instanceTask->rateCount(), 0); diff --git a/tests/api/solver/cvodetests.cpp b/tests/api/solver/cvodetests.cpp index 0e75258b0..275b2eef8 100644 --- a/tests/api/solver/cvodetests.cpp +++ b/tests/api/solver/cvodetests.cpp @@ -18,175 +18,175 @@ limitations under the License. TEST(CvodeSolverTest, maximumStepValueWithInvalidNumber) { - static const auto RELATIVE_TOLERANCE = -1.234; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto RELATIVE_TOLERANCE {-1.234}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The maximum step cannot be equal to -1.234. It must be greater or equal to 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setMaximumStep(RELATIVE_TOLERANCE); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, maximumNumberOfStepsValueWithInvalidNumber) { - static const auto MAXIMUM_NUMBER_OF_STEPS = 0; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto MAXIMUM_NUMBER_OF_STEPS {0}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The maximum number of steps cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setMaximumNumberOfSteps(MAXIMUM_NUMBER_OF_STEPS); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, bandedLinearSolverAndUpperHalfBandwidthValueWithNumberTooSmall) { - static const auto UPPER_HALF_BANDWIDTH = -1; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto UPPER_HALF_BANDWIDTH {-1}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to -1. It must be between 0 and 3."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); solver->setUpperHalfBandwidth(UPPER_HALF_BANDWIDTH); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, bandedLinearSolverAndUpperHalfBandwidthValueWithNumberTooBig) { - static const auto UPPER_HALF_BANDWIDTH = 4; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto UPPER_HALF_BANDWIDTH {4}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to 4. It must be between 0 and 3."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); solver->setUpperHalfBandwidth(UPPER_HALF_BANDWIDTH); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, bandedLinearSolverAndLowerHalfBandwidthValueWithNumberTooSmall) { - static const auto LOWER_HALF_BANDWIDTH = -1; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto LOWER_HALF_BANDWIDTH {-1}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The lower half-bandwidth cannot be equal to -1. It must be between 0 and 3."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); solver->setLowerHalfBandwidth(LOWER_HALF_BANDWIDTH); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, bandedLinearSolverAndLowerHalfBandwidthValueWithNumberTooBig) { - static const auto LOWER_HALF_BANDWIDTH = 4; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto LOWER_HALF_BANDWIDTH {4}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The lower half-bandwidth cannot be equal to 4. It must be between 0 and 3."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); solver->setLowerHalfBandwidth(LOWER_HALF_BANDWIDTH); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, relativeToleranceValueWithInvalidNumber) { - static const auto RELATIVE_TOLERANCE = -1.234; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto RELATIVE_TOLERANCE {-1.234}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The relative tolerance cannot be equal to -1.234. It must be greater or equal to 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setRelativeTolerance(RELATIVE_TOLERANCE); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, absoluteToleranceValueWithInvalidNumber) { - static const auto RELATIVE_TOLERANCE = -1.234; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto ABSOLUTE_TOLERANCE {-1.234}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The absolute tolerance cannot be equal to -1.234. It must be greater or equal to 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; - solver->setAbsoluteTolerance(RELATIVE_TOLERANCE); + solver->setAbsoluteTolerance(ABSOLUTE_TOLERANCE); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(CvodeSolverTest, solve) { - static const auto STATE_VALUES = std::vector({-63.886, 0.135007, 0.984333, 0.740973}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.726, -0.128192, -0.05091, 0.098649}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.00001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.9819, -823.517, 789.779, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.0001, 0.001, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); + static const auto STATE_VALUES {std::vector({-63.886, 0.135007, 0.984333, 0.740973})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.726, -0.128192, -0.05091, 0.098649})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.000001, 0.00001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.9819, -823.517, 789.779, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.0001, 0.001, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; OdeModel::run(document, STATE_VALUES, STATE_ABS_TOLS, @@ -198,21 +198,21 @@ TEST(CvodeSolverTest, solve) TEST(CvodeSolverTest, solveWithoutInterpolateSolution) { - static const auto STATE_VALUES = std::vector({-63.886395, 0.135008, 0.984334, 0.740972}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.725709, -0.128194, -0.050903, 0.098651}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.982019, -823.51695, 789.77946, 3.969916, 0.114985, 0.00287, 0.967348, 0.541337, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.000001, 0.00001, 0.00001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.886395, 0.135008, 0.984334, 0.740972})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.725709, -0.128194, -0.050903, 0.098651})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.982019, -823.51695, 789.77946, 3.969916, 0.114985, 0.00287, 0.967348, 0.541337, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.000001, 0.00001, 0.00001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setInterpolateSolution(false); @@ -226,21 +226,21 @@ TEST(CvodeSolverTest, solveWithoutInterpolateSolution) TEST(CvodeSolverTest, solveWithAdamsMoultonIntegrationMethod) { - static const auto STATE_VALUES = std::vector({-63.89, 0.13501, 0.98434, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.01, 0.00001, 0.00001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.726, -0.12820, -0.0509, 0.0987}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.0001, 0.0001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.98, -823.52, 789.78, 3.97, 0.1149, 0.002869, 0.96735, 0.5413, 0.05625}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.01, 0.01, 0.01, 0.01, 0.0001, 0.000001, 0.00001, 0.0001, 0.00001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.89, 0.13501, 0.98434, 0.74097})}; + static const auto STATE_ABS_TOLS {std::vector({0.01, 0.00001, 0.00001, 0.00001})}; + static const auto RATE_VALUES {std::vector({49.726, -0.12820, -0.0509, 0.0987})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.0001, 0.0001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.98, -823.52, 789.78, 3.97, 0.1149, 0.002869, 0.96735, 0.5413, 0.05625})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.01, 0.01, 0.01, 0.01, 0.0001, 0.000001, 0.00001, 0.0001, 0.00001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setIntegrationMethod(libOpenCOR::SolverCvode::IntegrationMethod::ADAMS_MOULTON); @@ -254,21 +254,21 @@ TEST(CvodeSolverTest, solveWithAdamsMoultonIntegrationMethod) TEST(CvodeSolverTest, solveWithFunctionalIterationType) { - static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.984334, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.726, -0.12819, -0.05090, 0.09865}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.982, -823.52, 789.78, 3.9699, 0.11499, 0.00287, 0.96735, 0.54134, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.886, 0.13501, 0.984334, 0.74097})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.000001, 0.00001})}; + static const auto RATE_VALUES {std::vector({49.726, -0.12819, -0.05090, 0.09865})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.00001, 0.00001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.982, -823.52, 789.78, 3.9699, 0.11499, 0.00287, 0.96735, 0.54134, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.001, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setIterationType(libOpenCOR::SolverCvode::IterationType::FUNCTIONAL); @@ -282,21 +282,21 @@ TEST(CvodeSolverTest, solveWithFunctionalIterationType) TEST(CvodeSolverTest, solveWithBandedLinearSolver) { - static const auto STATE_VALUES = std::vector({-54.958, 0.11472, 0.97137, 0.756967}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.000001}); - static const auto RATE_VALUES = std::vector({47.20, -0.10208, -0.09298, 0.06298}); - static const auto RATE_ABS_TOLS = std::vector({0.01, 0.00001, 0.00001, 0.00001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -13.304, -791.43, 757.5, 3.1534, 0.18883, 0.004484, 0.92385, 0.4547, 0.062887}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.1, 0.0001, 0.00001, 0.000001, 0.00001, 0.0001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-54.958, 0.11472, 0.97137, 0.756967})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.00001, 0.000001})}; + static const auto RATE_VALUES {std::vector({47.20, -0.10208, -0.09298, 0.06298})}; + static const auto RATE_ABS_TOLS {std::vector({0.01, 0.00001, 0.00001, 0.00001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -13.304, -791.43, 757.5, 3.1534, 0.18883, 0.004484, 0.92385, 0.4547, 0.062887})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.001, 0.01, 0.1, 0.0001, 0.00001, 0.000001, 0.00001, 0.0001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BANDED); @@ -310,21 +310,21 @@ TEST(CvodeSolverTest, solveWithBandedLinearSolver) TEST(CvodeSolverTest, solveWithDiagonalLinearSolver) { - static const auto STATE_VALUES = std::vector({-63.887, 0.13501, 0.984334, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.725, -0.1282, -0.05090, 0.09865}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.0001, 0.00001, 0.00001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.98, -823.52, 789.78, 3.9699, 0.11498, 0.00287, 0.96735, 0.54134, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.01, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.887, 0.13501, 0.984334, 0.74097})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.000001, 0.00001})}; + static const auto RATE_VALUES {std::vector({49.725, -0.1282, -0.05090, 0.09865})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.0001, 0.00001, 0.00001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.98, -823.52, 789.78, 3.9699, 0.11498, 0.00287, 0.96735, 0.54134, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.01, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::DIAGONAL); @@ -338,21 +338,21 @@ TEST(CvodeSolverTest, solveWithDiagonalLinearSolver) TEST(CvodeSolverTest, solveWithGmresLinearSolver) { - static const auto STATE_VALUES = std::vector({9.518468, 0.367366, 0.01612, 0.491145}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({-0.864067, 0.064354, 0.001718, -0.052716}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, 6.03944, -5.198281, 0.022996, 0.112958, 6.787605, 0.112665, 0.018857, 0.032306, 0.140794}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({9.518468, 0.367366, 0.01612, 0.491145})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({-0.864067, 0.064354, 0.001718, -0.052716})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, 6.03944, -5.198281, 0.022996, 0.112958, 6.787605, 0.112665, 0.018857, 0.032306, 0.140794})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::GMRES); @@ -366,21 +366,21 @@ TEST(CvodeSolverTest, solveWithGmresLinearSolver) TEST(CvodeSolverTest, solveWithBicgstabLinearSolver) { - static const auto STATE_VALUES = std::vector({9.518406, 0.36737, 0.016121, 0.491141}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({-0.864079, 0.064354, 0.001718, -0.052715}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, 6.039422, -5.198258, 0.022996, 0.112959, 6.787581, 0.112665, 0.018857, 0.032306, 0.140793}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({9.518406, 0.36737, 0.016121, 0.491141})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({-0.864079, 0.064354, 0.001718, -0.052715})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, 6.039422, -5.198258, 0.022996, 0.112959, 6.787581, 0.112665, 0.018857, 0.032306, 0.140793})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BICGSTAB); @@ -394,21 +394,21 @@ TEST(CvodeSolverTest, solveWithBicgstabLinearSolver) TEST(CvodeSolverTest, solveWithTfqmrLinearSolver) { - static const auto STATE_VALUES = std::vector({9.5181, 0.367396, 0.016121, 0.491122}); - static const auto STATE_ABS_TOLS = std::vector({0.0001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({-0.86414, 0.064349, 0.001718, -0.052712}); - static const auto RATE_ABS_TOLS = std::vector({0.00001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, 6.03933, -5.1981, 0.023001, 0.112961, 6.78747, 0.112663, 0.018857, 0.032307, 0.140793}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.00001, 0.0001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({9.5181, 0.367396, 0.016121, 0.491122})}; + static const auto STATE_ABS_TOLS {std::vector({0.0001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({-0.86414, 0.064349, 0.001718, -0.052712})}; + static const auto RATE_ABS_TOLS {std::vector({0.00001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, 6.03933, -5.1981, 0.023001, 0.112961, 6.78747, 0.112663, 0.018857, 0.032307, 0.140793})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.00001, 0.0001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::TFQMR); @@ -422,21 +422,21 @@ TEST(CvodeSolverTest, solveWithTfqmrLinearSolver) TEST(CvodeSolverTest, solveWithGmresLinearSolverAndNoPreconditioner) { - static const auto STATE_VALUES = std::vector({-63.887, 0.13501, 0.984334, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.726, -0.12819, -0.05090, 0.09865}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.982, -823.517, 789.779, 3.9699, 0.11498, 0.00287, 0.96734, 0.54134, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.001, 0.001, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.887, 0.13501, 0.984334, 0.74097})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.000001, 0.00001})}; + static const auto RATE_VALUES {std::vector({49.726, -0.12819, -0.05090, 0.09865})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.00001, 0.00001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.982, -823.517, 789.779, 3.9699, 0.11498, 0.00287, 0.96734, 0.54134, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.001, 0.001, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::GMRES); solver->setPreconditioner(libOpenCOR::SolverCvode::Preconditioner::NO); @@ -451,21 +451,21 @@ TEST(CvodeSolverTest, solveWithGmresLinearSolverAndNoPreconditioner) TEST(CvodeSolverTest, solveWithBicgstabLinearSolverAndNoPreconditioner) { - static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.984333, 0.740972}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.725, -0.12819, -0.0509, 0.098649}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.0001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.9819, -823.52, 789.779, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.0001, 0.01, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.886, 0.13501, 0.984333, 0.740972})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.725, -0.12819, -0.0509, 0.098649})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.0001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.9819, -823.52, 789.779, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.0001, 0.01, 0.001, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::BICGSTAB); solver->setPreconditioner(libOpenCOR::SolverCvode::Preconditioner::NO); @@ -480,21 +480,21 @@ TEST(CvodeSolverTest, solveWithBicgstabLinearSolverAndNoPreconditioner) TEST(CvodeSolverTest, solveWithTfqmrLinearSolverAndNoPreconditioner) { - static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.98433, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.726, -0.12819, -0.05090, 0.09865}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.982, -823.52, 789.78, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001}); - - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->odeSolver()); + static const auto STATE_VALUES {std::vector({-63.886, 0.13501, 0.98433, 0.74097})}; + static const auto STATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.00001, 0.00001})}; + static const auto RATE_VALUES {std::vector({49.726, -0.12819, -0.05090, 0.09865})}; + static const auto RATE_ABS_TOLS {std::vector({0.001, 0.00001, 0.00001, 0.00001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.982, -823.52, 789.78, 3.9699, 0.11499, 0.00287, 0.96735, 0.54133, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.001, 0.01, 0.01, 0.0001, 0.00001, 0.00001, 0.00001, 0.00001, 0.000001})}; + + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->odeSolver())}; solver->setLinearSolver(libOpenCOR::SolverCvode::LinearSolver::TFQMR); solver->setPreconditioner(libOpenCOR::SolverCvode::Preconditioner::NO); diff --git a/tests/api/solver/forwardeulertests.cpp b/tests/api/solver/forwardeulertests.cpp index 77307b7f2..0f57cb4bc 100644 --- a/tests/api/solver/forwardeulertests.cpp +++ b/tests/api/solver/forwardeulertests.cpp @@ -18,43 +18,43 @@ limitations under the License. TEST(ForwardEulerSolverTest, stepValueWithInvalidNumber) { - static const auto STEP = 0.0; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto STEP {0.0}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The step cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverForwardEuler::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverForwardEuler::create()}; solver->setStep(STEP); simulation->setOdeSolver(solver); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(ForwardEulerSolverTest, solve) { - static const auto STEP = 0.0123; - static const auto STATE_VALUES = std::vector({-63.787727, 0.134748, 0.984255, 0.741178}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.73577, -0.127963, -0.051257, 0.098331}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.952418, -823.361177, 789.590304, 3.960664, 0.115617, 0.002884, 0.967035, 0.54037, 0.056315}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.00001, 0.000001}); + static const auto STEP {0.0123}; + static const auto STATE_VALUES {std::vector({-63.787727, 0.134748, 0.984255, 0.741178})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.73577, -0.127963, -0.051257, 0.098331})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.952418, -823.361177, 789.590304, 3.960664, 0.115617, 0.002884, 0.967035, 0.54037, 0.056315})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.00001, 0.000001})}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverForwardEuler::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverForwardEuler::create()}; solver->setStep(STEP); diff --git a/tests/api/solver/fourthorderrungekuttatests.cpp b/tests/api/solver/fourthorderrungekuttatests.cpp index c0de99eaf..d7c0fda95 100644 --- a/tests/api/solver/fourthorderrungekuttatests.cpp +++ b/tests/api/solver/fourthorderrungekuttatests.cpp @@ -18,43 +18,43 @@ limitations under the License. TEST(FourthOrderRungeKuttaSolverTest, stepValueWithInvalidNumber) { - static const auto STEP = 0.0; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto STEP {0.0}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The step cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverFourthOrderRungeKutta::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverFourthOrderRungeKutta::create()}; solver->setStep(STEP); simulation->setOdeSolver(solver); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(FourthOrderRungeKuttaSolverTest, solve) { - static const auto STEP = 0.0123; - static const auto STATE_VALUES = std::vector({-63.821233, 0.134844, 0.984267, 0.741105}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.702735, -0.127922, -0.051225, 0.098266}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.96247, -823.402257, 789.661995, 3.963806, 0.115402, 0.002879, 0.967141, 0.540698, 0.056292}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001}); + static const auto STEP {0.0123}; + static const auto STATE_VALUES {std::vector({-63.821233, 0.134844, 0.984267, 0.741105})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.702735, -0.127922, -0.051225, 0.098266})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.96247, -823.402257, 789.661995, 3.963806, 0.115402, 0.002879, 0.967141, 0.540698, 0.056292})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.00001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001})}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverFourthOrderRungeKutta::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverFourthOrderRungeKutta::create()}; solver->setStep(STEP); diff --git a/tests/api/solver/heuntests.cpp b/tests/api/solver/heuntests.cpp index 9bb9d50ae..fb09b57e0 100644 --- a/tests/api/solver/heuntests.cpp +++ b/tests/api/solver/heuntests.cpp @@ -18,43 +18,43 @@ limitations under the License. TEST(HeunSolverTest, stepValueWithInvalidNumber) { - static const auto STEP = 0.0; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto STEP {0.0}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The step cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverHeun::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverHeun::create()}; solver->setStep(STEP); simulation->setOdeSolver(solver); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(HeunSolverTest, solve) { - static const auto STEP = 0.0123; - static const auto STATE_VALUES = std::vector({-63.691259, 0.134516, 0.984133, 0.74137}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.66942, -0.127532, -0.051693, 0.097711}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.923478, -823.166811, 789.421406, 3.951622, 0.116239, 0.002898, 0.966726, 0.539425, 0.056383}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001}); + static const auto STEP {0.0123}; + static const auto STATE_VALUES {std::vector({-63.691259, 0.134516, 0.984133, 0.74137})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.66942, -0.127532, -0.051693, 0.097711})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.923478, -823.166811, 789.421406, 3.951622, 0.116239, 0.002898, 0.966726, 0.539425, 0.056383})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001})}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverHeun::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverHeun::create()}; solver->setStep(STEP); diff --git a/tests/api/solver/kinsoltests.cpp b/tests/api/solver/kinsoltests.cpp index 997331a7d..c2cead6db 100644 --- a/tests/api/solver/kinsoltests.cpp +++ b/tests/api/solver/kinsoltests.cpp @@ -20,99 +20,99 @@ limitations under the License. TEST(KinsolSolverTest, maximumNumberOfIterationsValueWithInvalidNumber) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The maximum number of iterations cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setMaximumNumberOfIterations(0); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(KinsolSolverTest, bandedLinearSolverAndUpperHalfBandwidthValueWithNumberTooSmall) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to -1. It must be between 0 and 2."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); solver->setUpperHalfBandwidth(-1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(KinsolSolverTest, bandedLinearSolverAndUpperHalfBandwidthValueWithNumberTooBig) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The upper half-bandwidth cannot be equal to 1. It must be between 0 and 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); solver->setUpperHalfBandwidth(1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(KinsolSolverTest, bandedLinearSolverAndLowerHalfBandwidthValueWithNumberTooSmall) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The lower half-bandwidth cannot be equal to -1. It must be between 0 and 2."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); solver->setLowerHalfBandwidth(-1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(KinsolSolverTest, bandedLinearSolverAndLowerHalfBandwidthValueWithNumberTooBig) { - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The lower half-bandwidth cannot be equal to 1. It must be between 0 and 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); solver->setLowerHalfBandwidth(1); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } -static const auto ABS_TOL = 1e-05; +static const auto ABS_TOL {1e-05}; namespace { @@ -145,9 +145,9 @@ void expectNla2Solution(const libOpenCOR::SedInstanceTaskPtr &pInstanceTask) TEST(KinsolSolverTest, solve) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto instance = document->instantiate(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; instance->run(); @@ -156,16 +156,16 @@ TEST(KinsolSolverTest, solve) TEST(KinsolSolverTest, solveWithBandedLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BANDED); solver->setUpperHalfBandwidth(2); solver->setLowerHalfBandwidth(2); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); @@ -174,14 +174,14 @@ TEST(KinsolSolverTest, solveWithBandedLinearSolver) TEST(KinsolSolverTest, solveWithGmresLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::GMRES); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); @@ -190,14 +190,14 @@ TEST(KinsolSolverTest, solveWithGmresLinearSolver) TEST(KinsolSolverTest, solveWithBicgstabLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla2.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::BICGSTAB); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); @@ -206,14 +206,14 @@ TEST(KinsolSolverTest, solveWithBicgstabLinearSolver) TEST(KinsolSolverTest, solveWithTfqmrLinearSolver) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = std::dynamic_pointer_cast(simulation->nlaSolver()); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/nla1.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {std::dynamic_pointer_cast(simulation->nlaSolver())}; solver->setLinearSolver(libOpenCOR::SolverKinsol::LinearSolver::TFQMR); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); diff --git a/tests/api/solver/odemodel.cpp b/tests/api/solver/odemodel.cpp index aaccd56e6..33dba869b 100644 --- a/tests/api/solver/odemodel.cpp +++ b/tests/api/solver/odemodel.cpp @@ -25,19 +25,19 @@ void run(const libOpenCOR::SedDocumentPtr &pDocument, const libOpenCOR::Doubles &pComputedConstantValues, const libOpenCOR::Doubles &pComputedConstantAbsTols, const libOpenCOR::Doubles &pAlgebraicValues, const libOpenCOR::Doubles &pAlgebraicAbsTols) { - static const auto OUTPUT_END_TIME = 50.0; - static const auto NUMBER_OF_STEPS = 50000; + static const auto OUTPUT_END_TIME {50.0}; + static const auto NUMBER_OF_STEPS {50000}; - auto simulation = std::dynamic_pointer_cast(pDocument->simulations()[0]); + auto simulation {std::dynamic_pointer_cast(pDocument->simulations()[0])}; simulation->setOutputEndTime(OUTPUT_END_TIME); simulation->setNumberOfSteps(NUMBER_OF_STEPS); - auto instance = pDocument->instantiate(); + auto instance {pDocument->instantiate()}; instance->run(); - auto instanceTask = instance->tasks()[0]; + auto instanceTask {instance->tasks()[0]}; EXPECT_EQ_VALUES(instanceTask, 13000, pStateValues, pStateAbsTols, diff --git a/tests/api/solver/secondorderrungekuttatests.cpp b/tests/api/solver/secondorderrungekuttatests.cpp index d35df4ce5..d951e33fb 100644 --- a/tests/api/solver/secondorderrungekuttatests.cpp +++ b/tests/api/solver/secondorderrungekuttatests.cpp @@ -18,43 +18,43 @@ limitations under the License. TEST(SecondOrderRungeKuttaSolverTest, stepValueWithInvalidNumber) { - static const auto STEP = 0.0; - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + static const auto STEP {0.0}; + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{ {libOpenCOR::Issue::Type::ERROR, "The step cannot be equal to 0. It must be greater than 0."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverSecondOrderRungeKutta::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverSecondOrderRungeKutta::create()}; solver->setStep(STEP); simulation->setOdeSolver(solver); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); } TEST(SecondOrderRungeKuttaSolverTest, solve) { - static const auto STEP = 0.0123; - static const auto STATE_VALUES = std::vector({-63.886525, 0.135009, 0.984334, 0.740971}); - static const auto STATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.725722, -0.128194, -0.050903, 0.098651}); - static const auto RATE_ABS_TOLS = std::vector({0.000001, 0.000001, 0.000001, 0.000001}); - static const auto CONSTANT_VALUES = std::vector({1.0, 0.0, 0.3, 120.0, 36.0}); - static const auto CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0, 0.0, 0.0}); - static const auto COMPUTED_CONSTANT_VALUES = std::vector({-10.613, -115.0, 12.0}); - static const auto COMPUTED_CONSTANT_ABS_TOLS = std::vector({0.0, 0.0, 0.0}); - static const auto ALGEBRAIC_VALUES = std::vector({0.0, -15.982058, -823.516942, 789.779614, 3.969929, 0.114985, 0.00287, 0.967348, 0.541338, 0.056246}); - static const auto ALGEBRAIC_ABS_TOLS = std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001}); + static const auto STEP {0.0123}; + static const auto STATE_VALUES {std::vector({-63.886525, 0.135009, 0.984334, 0.740971})}; + static const auto STATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto RATE_VALUES {std::vector({49.725722, -0.128194, -0.050903, 0.098651})}; + static const auto RATE_ABS_TOLS {std::vector({0.000001, 0.000001, 0.000001, 0.000001})}; + static const auto CONSTANT_VALUES {std::vector({1.0, 0.0, 0.3, 120.0, 36.0})}; + static const auto CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0, 0.0, 0.0})}; + static const auto COMPUTED_CONSTANT_VALUES {std::vector({-10.613, -115.0, 12.0})}; + static const auto COMPUTED_CONSTANT_ABS_TOLS {std::vector({0.0, 0.0, 0.0})}; + static const auto ALGEBRAIC_VALUES {std::vector({0.0, -15.982058, -823.516942, 789.779614, 3.969929, 0.114985, 0.00287, 0.967348, 0.541338, 0.056246})}; + static const auto ALGEBRAIC_ABS_TOLS {std::vector({0.0, 0.000001, 0.000001, 0.000001, 0.000001, 0.000001, 0.00001, 0.000001, 0.000001, 0.000001})}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml")); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); - auto solver = libOpenCOR::SolverSecondOrderRungeKutta::create(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode.cellml"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; + auto solver {libOpenCOR::SolverSecondOrderRungeKutta::create()}; solver->setStep(STEP); diff --git a/tests/api/version/tests.cpp b/tests/api/version/tests.cpp index 15c5b2493..1d5b870fc 100644 --- a/tests/api/version/tests.cpp +++ b/tests/api/version/tests.cpp @@ -24,10 +24,10 @@ limitations under the License. TEST(VersionTest, libOpenCOR) { - static const uint64_t TEN_BILLION = 10000000000; - static const uint64_t TEN_THOUSAND = 10000; - static const uint64_t HUNDRED = 100; - static const uint64_t TEN = 10; + static const uint64_t TEN_BILLION {10000000000}; + static const uint64_t TEN_THOUSAND {10000}; + static const uint64_t HUNDRED {100}; + static const uint64_t TEN {10}; std::ifstream versionFile("../../VERSION.txt"); std::string versionString; @@ -40,17 +40,17 @@ TEST(VersionTest, libOpenCOR) ASSERT_TRUE(std::regex_match(versionString, match, versionRegex)); - const uint64_t majorVersion = static_cast(std::stoi(match[1])); - const uint64_t year = static_cast(std::stoi(match[2].str().substr(0, 4))); - const uint64_t month = static_cast(std::stoi(match[2].str().substr(4, 2))); - const uint64_t day = static_cast(std::stoi(match[2].str().substr(6, 2))); - const uint64_t patchVersion = static_cast(std::stoi(match[3])); - uint64_t version = 0; - auto number = TEN_BILLION * majorVersion - + HUNDRED * (TEN_THOUSAND * year + HUNDRED * month + day) - + patchVersion; - - for (int i = 0; number != 0; i += 4) { + const auto majorVersion {static_cast(std::stoi(match[1]))}; + const auto year {static_cast(std::stoi(match[2].str().substr(0, 4)))}; + const auto month {static_cast(std::stoi(match[2].str().substr(4, 2)))}; + const auto day {static_cast(std::stoi(match[2].str().substr(6, 2)))}; + const auto patchVersion {static_cast(std::stoi(match[3]))}; + uint64_t version {0}; + auto number {TEN_BILLION * majorVersion + + HUNDRED * (TEN_THOUSAND * year + HUNDRED * month + day) + + patchVersion}; + + for (int i {0}; number != 0; i += 4) { version |= (number % TEN) << i; // NOLINT number /= TEN; } diff --git a/tests/install/src/main.cpp b/tests/install/src/main.cpp index 0735a673c..6c38c5292 100644 --- a/tests/install/src/main.cpp +++ b/tests/install/src/main.cpp @@ -12,18 +12,18 @@ int main() // Load a COMBINE archive from GitHub and output some information about it. - auto file = libOpenCOR::File::create("https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex"); - auto document = libOpenCOR::SedDocument::create(file); - auto simulation = std::dynamic_pointer_cast(document->simulations()[0]); + auto file {libOpenCOR::File::create("https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex")}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto simulation {std::dynamic_pointer_cast(document->simulations()[0])}; simulation->setOutputEndTime(5.0); simulation->setNumberOfSteps(500); - auto instance = document->instantiate(); + auto instance {document->instantiate()}; instance->run(); - auto instanceTask = instance->tasks()[0]; + auto instanceTask {instance->tasks()[0]}; std::cout << "\n"; std::cout << "---[ File information ]---\n"; @@ -42,48 +42,48 @@ int main() std::cout << "\n"; std::cout << instanceTask->voiName() << " (" << instanceTask->voiUnit() << ")"; - for (size_t i = 0; i < instanceTask->stateCount(); ++i) { + for (size_t i {0}; i < instanceTask->stateCount(); ++i) { std::cout << "," << instanceTask->stateName(i) << " (" << instanceTask->stateUnit(i) << ")"; } - for (size_t i = 0; i < instanceTask->rateCount(); ++i) { + for (size_t i {0}; i < instanceTask->rateCount(); ++i) { std::cout << "," << instanceTask->rateName(i) << " (" << instanceTask->rateUnit(i) << ")"; } - for (size_t i = 0; i < instanceTask->constantCount(); ++i) { + for (size_t i {0}; i < instanceTask->constantCount(); ++i) { std::cout << "," << instanceTask->constantName(i) << " (" << instanceTask->constantUnit(i) << ")"; } - for (size_t i = 0; i < instanceTask->computedConstantCount(); ++i) { + for (size_t i {0}; i < instanceTask->computedConstantCount(); ++i) { std::cout << "," << instanceTask->computedConstantName(i) << " (" << instanceTask->computedConstantUnit(i) << ")"; } - for (size_t i = 0; i < instanceTask->algebraicCount(); ++i) { + for (size_t i {0}; i < instanceTask->algebraicCount(); ++i) { std::cout << "," << instanceTask->algebraicName(i) << " (" << instanceTask->algebraicUnit(i) << ")"; } std::cout << "\n"; - for (size_t j = 0; j < instanceTask->voi().size(); ++j) { + for (size_t j {0}; j < instanceTask->voi().size(); ++j) { std::cout << instanceTask->voi()[j]; - for (size_t i = 0; i < instanceTask->stateCount(); ++i) { + for (size_t i {0}; i < instanceTask->stateCount(); ++i) { std::cout << "," << instanceTask->state(i)[j]; } - for (size_t i = 0; i < instanceTask->rateCount(); ++i) { + for (size_t i {0}; i < instanceTask->rateCount(); ++i) { std::cout << "," << instanceTask->rate(i)[j]; } - for (size_t i = 0; i < instanceTask->constantCount(); ++i) { + for (size_t i {0}; i < instanceTask->constantCount(); ++i) { std::cout << "," << instanceTask->constant(i)[j]; } - for (size_t i = 0; i < instanceTask->computedConstantCount(); ++i) { + for (size_t i {0}; i < instanceTask->computedConstantCount(); ++i) { std::cout << "," << instanceTask->computedConstant(i)[j]; } - for (size_t i = 0; i < instanceTask->algebraicCount(); ++i) { + for (size_t i {0}; i < instanceTask->algebraicCount(); ++i) { std::cout << "," << instanceTask->algebraic(i)[j]; } diff --git a/tests/misc/compilertests.cpp b/tests/misc/compilertests.cpp index 81aedc091..3c01d529b 100644 --- a/tests/misc/compilertests.cpp +++ b/tests/misc/compilertests.cpp @@ -37,53 +37,53 @@ TEST_F(CompilerTest, basic) { // Add "void" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_01 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_01 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\nvoid\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("void")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_01); // Add an identifier to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_02 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_02 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Variable has incomplete type 'void':\nvoid function\n ^"}, {libOpenCOR::Issue::Type::ERROR, "Expected ';' after top level declarator:\nvoid function\n ^\n ;"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("void function")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_02); // Add a "(" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_03 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_03 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected parameter declarator:\nvoid function(\n ^"}, {libOpenCOR::Issue::Type::ERROR, "Expected ')' to match this '(':\nvoid function(\n ^"}, {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\nvoid function(\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("void function(")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_03); // Add a ")" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_04 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_04 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\nvoid function()\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("void function()")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_04); // Add a "{" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_05 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_05 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected '}':\nvoid function() {\n ^\nto match this '{':\nvoid function() {\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("void function() {")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_05); @@ -99,42 +99,42 @@ TEST_F(CompilerTest, basic) // Make the function a double function. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_06 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_06 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Non-void function does not return a value:\ndouble function() {}\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double function() {}")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_06); // Add "return" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_07 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_07 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected expression:\ndouble function() { return\n ^"}, {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\ndouble function() { return\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double function() { return")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_07); // Add "3.0" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_08 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_08 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected ';' after return statement:\ndouble function() { return 3.0\n ^\n ;"}, {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\ndouble function() { return 3.0\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_08); // Add ";" to our string. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_09 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_09 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected '}':\ndouble function() { return 3.0;\n ^\nto match this '{':\ndouble function() { return 3.0;\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0;")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_09); @@ -147,21 +147,21 @@ TEST_F(CompilerTest, basic) // Use an invalid function name. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_10 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_10 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\ndouble .function() { return 3.0; }\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double .function() { return 3.0; }")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_10); // Return an invalid statement. - static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_11 = { + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_11 {{ {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, {libOpenCOR::Issue::Type::ERROR, "Expected expression:\ndouble function() { return 3.0+*-/a; }\n ^"}, {libOpenCOR::Issue::Type::ERROR, "Use of undeclared identifier 'a':\ndouble function() { return 3.0+*-/a; }\n ^"}, - }; + }}; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0+*-/a; }")); EXPECT_EQ_ISSUES(mCompiler, EXPECTED_ISSUES_11); @@ -189,9 +189,9 @@ TEST_F(CompilerTest, severalParameters) TEST_F(CompilerTest, math) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("misc/math.cellml")); - auto cellmlFile = libOpenCOR::CellmlFile::create(file); - auto cellmlFileRuntime = cellmlFile->runtime(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("misc/math.cellml"))}; + auto cellmlFile {libOpenCOR::CellmlFile::create(file)}; + auto cellmlFileRuntime {cellmlFile->runtime()}; EXPECT_FALSE(cellmlFileRuntime->hasIssues()); } diff --git a/tests/support/cellml/runtimetests.cpp b/tests/support/cellml/runtimetests.cpp index e84b8c651..629edc03f 100644 --- a/tests/support/cellml/runtimetests.cpp +++ b/tests/support/cellml/runtimetests.cpp @@ -22,23 +22,23 @@ limitations under the License. TEST(RuntimeCellmlTest, validRuntime) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); - auto cellmlFile = libOpenCOR::CellmlFile::create(file); - auto cellmlFileRuntime = cellmlFile->runtime(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto cellmlFile {libOpenCOR::CellmlFile::create(file)}; + auto cellmlFileRuntime {cellmlFile->runtime()}; EXPECT_FALSE(cellmlFileRuntime->hasIssues()); } TEST(RuntimeCellmlTest, invalidRuntimeBecauseOfAnalysisIssues) { - static const libOpenCOR::ExpectedIssues expectedIssues = { + static const libOpenCOR::ExpectedIssues expectedIssues {{ {libOpenCOR::Issue::Type::WARNING, "The units in 'x = 1.0' in component 'my_component' are not equivalent. 'x' is in 'volt' (i.e. 'ampere^-1 x kilogram x metre^2 x second^-3') while '1.0' is 'dimensionless'."}, {libOpenCOR::Issue::Type::ERROR, "Variable 'x' in component 'my_component' is computed more than once."}, - }; + }}; - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("support/cellml/model_with_analysis_issues.cellml")); - auto cellmlFile = libOpenCOR::CellmlFile::create(file); - auto cellmlFileRuntime = cellmlFile->runtime(); + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("support/cellml/model_with_analysis_issues.cellml"))}; + auto cellmlFile {libOpenCOR::CellmlFile::create(file)}; + auto cellmlFileRuntime {cellmlFile->runtime()}; EXPECT_EQ_ISSUES(cellmlFileRuntime, expectedIssues); } diff --git a/tests/utils.cpp b/tests/utils.cpp index da21c8726..8cb7f795a 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -28,11 +28,11 @@ namespace libOpenCOR { void expectEqualIssues(const LoggerPtr &pLogger, const ExpectedIssues &pExpectedIssues) { - auto issues = pLogger->issues(); + auto issues {pLogger->issues()}; EXPECT_EQ(issues.size(), pExpectedIssues.size()); - for (size_t i = 0; i < issues.size(); ++i) { + for (size_t i {0}; i < issues.size(); ++i) { EXPECT_EQ(issues[i]->type(), pExpectedIssues[i].type); EXPECT_EQ(issues[i]->description(), pExpectedIssues[i].description); @@ -66,23 +66,23 @@ void expectEqualValues(const SedInstanceTaskPtr &pInstanceTask, size_t pIndex, const Doubles &pComputedConstantValues, const Doubles &pComputedConstantAbsTols, const Doubles &pAlgebraicValues, const Doubles &pAlgebraicAbsTols) { - for (size_t i = 0; i < pInstanceTask->stateCount(); ++i) { + for (size_t i {0}; i < pInstanceTask->stateCount(); ++i) { expectEqualValue(pInstanceTask->state(i)[pIndex], pStateValues[i], pStateAbsTols[i]); } - for (size_t i = 0; i < pInstanceTask->rateCount(); ++i) { + for (size_t i {0}; i < pInstanceTask->rateCount(); ++i) { expectEqualValue(pInstanceTask->rate(i)[pIndex], pRateValues[i], pRateAbsTols[i]); } - for (size_t i = 0; i < pInstanceTask->constantCount(); ++i) { + for (size_t i {0}; i < pInstanceTask->constantCount(); ++i) { expectEqualValue(pInstanceTask->constant(i)[pIndex], pConstantValues[i], pConstantAbsTols[i]); } - for (size_t i = 0; i < pInstanceTask->computedConstantCount(); ++i) { + for (size_t i {0}; i < pInstanceTask->computedConstantCount(); ++i) { expectEqualValue(pInstanceTask->computedConstant(i)[pIndex], pComputedConstantValues[i], pComputedConstantAbsTols[i]); } - for (size_t i = 0; i < pInstanceTask->algebraicCount(); ++i) { + for (size_t i {0}; i < pInstanceTask->algebraicCount(); ++i) { expectEqualValue(pInstanceTask->algebraic(i)[pIndex], pAlgebraicValues[i], pAlgebraicAbsTols[i]); } } @@ -94,9 +94,9 @@ std::string resourcePath(const std::string &pResourceRelativePath) std::string textFileContents(const std::string &pFileName) { - static const auto CRLF_REGEX = std::regex("\\r\\n"); + static const auto CRLF_REGEX {std::regex("\\r\\n")}; - auto res = toString(fileContents(pFileName)); + auto res {toString(fileContents(pFileName))}; // To retrieve a file contents as bytes will, on Windows, result in LF characters being converted to CR+LF, so // convert them back since we expect LF. @@ -111,8 +111,8 @@ UnsignedChars charArrayToUnsignedChars(const char *pContents) UnsignedChars base64Decode(const char *pContents) { - char *buffer = new char[modp_b64_decode_len(strlen(pContents))]; - const size_t length = modp_b64_decode(buffer, pContents, strlen(pContents)); + char *buffer {new char[modp_b64_decode_len(strlen(pContents))]}; + const size_t length {modp_b64_decode(buffer, pContents, strlen(pContents))}; UnsignedChars res(buffer, buffer + length); // NOLINT delete[] buffer; diff --git a/tests/utils.in.h b/tests/utils.in.h index be4ddb929..355bbf0e2 100644 --- a/tests/utils.in.h +++ b/tests/utils.in.h @@ -30,43 +30,43 @@ limitations under the License. namespace libOpenCOR { -static constexpr auto RESOURCE_LOCATION = "@RESOURCE_LOCATION@"; - -static constexpr auto UNKNOWN_FILE = "unknown_file.txt"; -static constexpr auto SBML_FILE = "sbml.sbml"; -static constexpr auto ERROR_CELLML_FILE = "error.cellml"; -static constexpr auto ERROR_SEDML_FILE = "error.sedml"; -static constexpr auto CELLML_1_X_FILE = "cellml_1_x.cellml"; -static constexpr auto SEDML_1_X_FILE = "cellml_1_x.sedml"; -static constexpr auto COMBINE_1_X_ARCHIVE = "cellml_1_x.omex"; -static constexpr auto CELLML_2_FILE = "cellml_2.cellml"; -static constexpr auto SEDML_2_FILE = "cellml_2.sedml"; -static constexpr auto COMBINE_2_ARCHIVE = "cellml_2.omex"; -static constexpr auto IRRETRIEVABLE_FILE = "irretrievable_file.txt"; +static constexpr auto RESOURCE_LOCATION {"@RESOURCE_LOCATION@"}; + +static constexpr auto UNKNOWN_FILE {"unknown_file.txt"}; +static constexpr auto SBML_FILE {"sbml.sbml"}; +static constexpr auto ERROR_CELLML_FILE {"error.cellml"}; +static constexpr auto ERROR_SEDML_FILE {"error.sedml"}; +static constexpr auto CELLML_1_X_FILE {"cellml_1_x.cellml"}; +static constexpr auto SEDML_1_X_FILE {"cellml_1_x.sedml"}; +static constexpr auto COMBINE_1_X_ARCHIVE {"cellml_1_x.omex"}; +static constexpr auto CELLML_2_FILE {"cellml_2.cellml"}; +static constexpr auto SEDML_2_FILE {"cellml_2.sedml"}; +static constexpr auto COMBINE_2_ARCHIVE {"cellml_2.omex"}; +static constexpr auto IRRETRIEVABLE_FILE {"irretrievable_file.txt"}; #ifdef BUILDING_ON_WINDOWS -static constexpr auto LOCAL_FILE = R"(P:\some\path\file.txt)"; +static constexpr auto LOCAL_FILE {R"(P:\some\path\file.txt)"}; #else -static constexpr auto LOCAL_FILE = "/some/path/file.txt"; +static constexpr auto LOCAL_FILE {"/some/path/file.txt"}; #endif // Note: the three following URLs use http rather than https to help with coverage testing. -static constexpr auto HTTP_REMOTE_CELLML_FILE = "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"; -static constexpr auto HTTP_REMOTE_SEDML_FILE = "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml"; -static constexpr auto HTTP_REMOTE_COMBINE_ARCHIVE = "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex"; -static constexpr auto REMOTE_BASE_PATH = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res"; -static constexpr auto REMOTE_FILE = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"; -static constexpr auto ENCODED_REMOTE_FILE = "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml"; -static constexpr auto NON_ENCODED_REMOTE_FILE = "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml"; -static constexpr auto UNKNOWN_REMOTE_FILE = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt"; -static constexpr auto IRRETRIEVABLE_REMOTE_FILE = "https://some.domain.com/irretrievable_file.txt"; - -static constexpr auto UNKNOWN_CONTENTS = "Some unknown contents..."; -static constexpr auto CELLML_CONTENTS = "@CELLML_CONTENTS_C@"; -static constexpr auto ERROR_CELLML_CONTENTS = "@ERROR_CELLML_CONTENTS_C@"; -static constexpr auto WARNING_CELLML_CONTENTS = "@WARNING_CELLML_CONTENTS_C@"; -static constexpr auto SEDML_CONTENTS = "@SEDML_CONTENTS_C@"; -static constexpr auto BASE64_COMBINE_ARCHIVE_CONTENTS = "@BASE64_COMBINE_ARCHIVE_CONTENTS@"; +static constexpr auto HTTP_REMOTE_CELLML_FILE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"}; +static constexpr auto HTTP_REMOTE_SEDML_FILE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml"}; +static constexpr auto HTTP_REMOTE_COMBINE_ARCHIVE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex"}; +static constexpr auto REMOTE_BASE_PATH {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res"}; +static constexpr auto REMOTE_FILE {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"}; +static constexpr auto ENCODED_REMOTE_FILE {"https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml"}; +static constexpr auto NON_ENCODED_REMOTE_FILE {"https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml"}; +static constexpr auto UNKNOWN_REMOTE_FILE {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt"}; +static constexpr auto IRRETRIEVABLE_REMOTE_FILE {"https://some.domain.com/irretrievable_file.txt"}; + +static constexpr auto UNKNOWN_CONTENTS {"Some unknown contents..."}; +static constexpr auto CELLML_CONTENTS {"@CELLML_CONTENTS_C@"}; +static constexpr auto ERROR_CELLML_CONTENTS {"@ERROR_CELLML_CONTENTS_C@"}; +static constexpr auto WARNING_CELLML_CONTENTS {"@WARNING_CELLML_CONTENTS_C@"}; +static constexpr auto SEDML_CONTENTS {"@SEDML_CONTENTS_C@"}; +static constexpr auto BASE64_COMBINE_ARCHIVE_CONTENTS {"@BASE64_COMBINE_ARCHIVE_CONTENTS@"}; typedef struct { From 538d3e55e924b9fd3321e19b195e8aecdc84709e Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 29 Oct 2025 11:44:46 +1300 Subject: [PATCH 3/7] Utils: flush things. --- src/misc/utils.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/misc/utils.cpp b/src/misc/utils.cpp index d90b22a22..7dc1c498e 100644 --- a/src/misc/utils.cpp +++ b/src/misc/utils.cpp @@ -59,6 +59,8 @@ void printIssues(const LoggerPtr &pLogger) } std::cout << "---[ISSUES]---[END]\n"; + + std::cout.flush(); } void printHexDump(const UnsignedChars &pBytes) @@ -119,6 +121,8 @@ void printHexDump(const UnsignedChars &pBytes) std::cout << std::dec; std::cout << "---[BYTES]---[END]\n"; + + std::cout.flush(); } void printArray(const std::string &pName, const Doubles &pDoubles) @@ -135,6 +139,8 @@ void printArray(const std::string &pName, const Doubles &pDoubles) } std::cout << "---[ARRAY]---[" << pName << "]---[END]\n"; + + std::cout.flush(); } #endif From ef630a6b80117b31fa7f61e66c3c2c0c7e2ec758 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 29 Oct 2025 11:46:05 +1300 Subject: [PATCH 4/7] Utils: added an optional header to `printIssues()`. --- src/misc/utils.cpp | 8 ++++++-- src/misc/utils.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/misc/utils.cpp b/src/misc/utils.cpp index 7dc1c498e..54ef0a833 100644 --- a/src/misc/utils.cpp +++ b/src/misc/utils.cpp @@ -50,9 +50,13 @@ limitations under the License. namespace libOpenCOR { #ifndef CODE_COVERAGE_ENABLED -void printIssues(const LoggerPtr &pLogger) +void printIssues(const LoggerPtr &pLogger, const std::string &pHeader) { - std::cout << "---[ISSUES]---[BEGIN]\n"; + std::cout << "---[ISSUES]---[BEGIN]"; + + if (!pHeader.empty()) { + std::cout << "---[" << pHeader << "]\n"; + } for (auto &issue : pLogger->issues()) { std::cout << ((issue->type() == Issue::Type::ERROR) ? "ERROR" : "WARNING") << ": " << issue->description() << "\n"; diff --git a/src/misc/utils.h b/src/misc/utils.h index b31263da7..38dcec0b3 100644 --- a/src/misc/utils.h +++ b/src/misc/utils.h @@ -71,7 +71,7 @@ using StringStringMap = std::map; #endif #ifndef CODE_COVERAGE_ENABLED -void LIBOPENCOR_UNIT_TESTING_EXPORT printIssues(const LoggerPtr &pLogger); +void LIBOPENCOR_UNIT_TESTING_EXPORT printIssues(const LoggerPtr &pLogger, const std::string &pHeader = ""); void LIBOPENCOR_UNIT_TESTING_EXPORT printHexDump(const UnsignedChars &pBytes); void LIBOPENCOR_UNIT_TESTING_EXPORT printArray(const std::string &pName, const Doubles &pDoubles); #endif From b6c16845c6dfdea4341c1bde7e0158a96d5e9163 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 29 Oct 2025 20:02:45 +1300 Subject: [PATCH 5/7] KINSOL: make sure that our input vector doesn't contain any `Inf` or `NaN` values. --- src/misc/utils.cpp | 5 + src/misc/utils.h | 7 + src/solver/solverkinsol.cpp | 28 +- tests/api/sed/coveragetests.cpp | 13 + tests/misc/utils.cpp | 8 + .../kinsol_with_inf_and_or_nan_values.cellml | 308 ++++++++++++++++++ 6 files changed, 362 insertions(+), 7 deletions(-) create mode 100644 tests/res/api/sed/kinsol_with_inf_and_or_nan_values.cellml diff --git a/src/misc/utils.cpp b/src/misc/utils.cpp index 54ef0a833..232336a92 100644 --- a/src/misc/utils.cpp +++ b/src/misc/utils.cpp @@ -535,6 +535,11 @@ std::string nlaSolverAddress(SolverNla *pNlaSolver) return oss.str(); } +bool isInfOrNan(double pNumber) +{ + return std::isinf(pNumber) || std::isnan(pNumber); +} + bool toBool(const std::string &pString) { return pString == "true"; diff --git a/src/misc/utils.h b/src/misc/utils.h index 38dcec0b3..7b9513862 100644 --- a/src/misc/utils.h +++ b/src/misc/utils.h @@ -30,6 +30,10 @@ limitations under the License. #include #include +#ifdef INF +# undef INF +#endif + #ifdef NAN # undef NAN #endif @@ -38,6 +42,7 @@ namespace libOpenCOR { static const std::string LIBOPENCOR_NAMESPACE {"https://opencor.ws/libopencor"}; +static const auto INF {std::numeric_limits::infinity()}; static const auto NAN {std::numeric_limits::quiet_NaN()}; using StringStringMap = std::map; @@ -105,6 +110,8 @@ UnsignedChars LIBOPENCOR_UNIT_TESTING_EXPORT fileContents(const std::filesystem: std::string nlaSolverAddress(SolverNla *pNlaSolver); +bool LIBOPENCOR_UNIT_TESTING_EXPORT isInfOrNan(double pNumber); + bool toBool(const std::string &pString); std::string toString(bool pBoolean); diff --git a/src/solver/solverkinsol.cpp b/src/solver/solverkinsol.cpp index 7634d458a..90bcee29e 100644 --- a/src/solver/solverkinsol.cpp +++ b/src/solver/solverkinsol.cpp @@ -87,12 +87,23 @@ struct SolverKinsolUserData #endif void *userData {nullptr}; + bool infOrNanFound {false}; }; int computeObjectiveFunction(N_Vector pU, N_Vector pF, void *pUserData) { + // Make sure that our input vector doesn't contain any Inf or NaN values. + auto *userData {static_cast(pUserData)}; + for (sunindextype i = 0; i < NV_LENGTH_S(pU); ++i) { + if (isInfOrNan(NV_Ith_S(pU, i))) { + userData->infOrNanFound = true; + + return -1; + } + } + #ifdef __EMSCRIPTEN__ // clang-format off EM_ASM({ @@ -357,10 +368,7 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio // Solve the model. -#ifndef CODE_COVERAGE_ENABLED - auto res = -#endif - KINSol(solver, u, KIN_LINESEARCH, ones, ones); + auto res = KINSol(solver, u, KIN_LINESEARCH, ones, ones); // Release some memory. @@ -377,13 +385,19 @@ bool SolverKinsol::Impl::solve(ComputeObjectiveFunction pComputeObjectiveFunctio // Check whether everything went fine. -#ifndef CODE_COVERAGE_ENABLED if (res < KIN_SUCCESS) { - addError(mErrorMessage); +#ifndef CODE_COVERAGE_ENABLED + if (userData.infOrNanFound) { +#endif + addError("The input vector contains some Inf and/or NaN values."); +#ifndef CODE_COVERAGE_ENABLED + } else { + addError(mErrorMessage); + } +#endif return false; } -#endif return true; } diff --git a/tests/api/sed/coveragetests.cpp b/tests/api/sed/coveragetests.cpp index fec6c24f3..e21b7d8c4 100644 --- a/tests/api/sed/coveragetests.cpp +++ b/tests/api/sed/coveragetests.cpp @@ -586,3 +586,16 @@ TEST(CoverageSedTest, math) EXPECT_EQ_VALUES(instanceTask, 0, {}, {}, {}, {}, {}, {}, COMPUTED_CONSTANT_VALUES, COMPUTED_CONSTANT_ABS_TOLS, {}, {}); } + +TEST(CoverageSedTest, KinsolWithInfAndOrNanValues) +{ + static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES = { + {libOpenCOR::Issue::Type::ERROR, "The input vector contains some Inf and/or NaN values."}, + }; + + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/kinsol_with_inf_and_or_nan_values.cellml")); + auto document = libOpenCOR::SedDocument::create(file); + auto instance = document->instantiate(); + + EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES); +} diff --git a/tests/misc/utils.cpp b/tests/misc/utils.cpp index 457358ccf..b3d765341 100644 --- a/tests/misc/utils.cpp +++ b/tests/misc/utils.cpp @@ -33,3 +33,11 @@ TEST(UtilsTest, decodeUrl) EXPECT_EQ(libOpenCOR::decodeUrl("%XX"), "%XX"); EXPECT_EQ(libOpenCOR::decodeUrl("%2X"), "%2X"); } + +TEST(UtilsTest, isInfOrNan) +{ + EXPECT_FALSE(libOpenCOR::isInfOrNan(0.0)); + EXPECT_TRUE(libOpenCOR::isInfOrNan(libOpenCOR::INF)); + EXPECT_TRUE(libOpenCOR::isInfOrNan(-libOpenCOR::INF)); + EXPECT_TRUE(libOpenCOR::isInfOrNan(libOpenCOR::NAN)); +} diff --git a/tests/res/api/sed/kinsol_with_inf_and_or_nan_values.cellml b/tests/res/api/sed/kinsol_with_inf_and_or_nan_values.cellml new file mode 100644 index 000000000..8f2ce9171 --- /dev/null +++ b/tests/res/api/sed/kinsol_with_inf_and_or_nan_values.cellml @@ -0,0 +1,308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + t + + q_1 + + v_q_1 + + + + + + + + + t + + q_2 + + v_q_2 + + + + + + + + + t + + q_3 + + v_q_3 + + + + + + + + + t + + q_4 + + v_q_4 + + + + + + + u_q_1 + + + RT + + + + + K_q_1 + q_1 + + + + + + + + + u_q_2 + + + RT + + + + + K_q_2 + q_2 + + + + + + + + + u_q_3 + + + RT + + + + + K_q_3 + q_3 + + + + + + + + + u_q_4 + + + RT + + + + + K_q_4 + q_4 + + + + + + + + + v_Re_c + + + kappa_r + + + + + + + u_f_Re_c + RT + + + + + + + u_r_Re_c + RT + + + + + + + + + + + u_1 + u_q_1 + + + + + + u_2 + u_q_2 + + + + + + u_3 + + + + + u_4 + + u_r_Re_c + + + + + + + u_3 + u_q_3 + + + + + + u_4 + u_q_4 + + + + + + u_f_Re_c + + + u_1 + u_2 + + + + + + + v_q_1 + + + v_r_1 + + + + + + + v_q_2 + + + v_r_1 + + + + + + + v_q_3 + v_r_2 + + + + + + v_q_4 + v_r_2 + + + + + + v_r_1 + v_Re_c + + + + + + v_r_2 + v_Re_c + + + + From cad976fd4f3a47cfb7b9c0fe0fd2ccadba7f94af Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 30 Oct 2025 00:28:11 +1300 Subject: [PATCH 6/7] CI: use `ubuntu-22.04` rather than `macos-15`. Indeed, there are few `macos-15` runners, so better use `ubuntu-22.04` whenever possible. --- .github/workflows/ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25fdba0c5..f0f827808 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -184,7 +184,7 @@ jobs: install_uninstall_and_package: ON use_install_prefix: ON - name: 'JavaScript bindings' - os: macos-15 + os: ubuntu-22.04 build_type: Release code_analysis: OFF code_coverage: OFF @@ -251,7 +251,7 @@ jobs: context: PATH=$GITHUB_WORKSPACE:$PATH target: check_code_formatting - name: 'JavaScript code formatting' - os: macos-15 + os: ubuntu-22.04 build_type: Release code_analysis: OFF code_coverage: OFF @@ -376,10 +376,13 @@ jobs: sudo mv clang-tidy /usr/local/bin - name: Install Emscripten if: ${{ matrix.javascript_support == 'ON' }} - run: brew install --overwrite emscripten + uses: mymindstorm/setup-emsdk@v14 - name: Install Biome if: ${{ matrix.target == 'javascript_check_code_formatting' }} - run: brew install --overwrite biome + run: | + curl -L https://github.com/biomejs/biome/releases/latest/download/biome-linux-x64 -o biome + chmod +x biome + mv biome /usr/local/bin - name: Install uv if: ${{ matrix.documentation == 'ON' || matrix.python_support == 'ON' || matrix.target == 'python_check_code_formatting' }} uses: astral-sh/setup-uv@v6 From 8b82716c70d558086b7b28634cd9ba0cfd952a13 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 30 Oct 2025 00:48:38 +1300 Subject: [PATCH 7/7] JavaScript formatting. --- tests/bindings/javascript/res/index.html | 54 ++++++++++++------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/bindings/javascript/res/index.html b/tests/bindings/javascript/res/index.html index 83ebcca98..a4b0c673e 100644 --- a/tests/bindings/javascript/res/index.html +++ b/tests/bindings/javascript/res/index.html @@ -164,33 +164,33 @@