diff --git a/VERSION.txt b/VERSION.txt index 05de19166..9f0adfc11 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.20251017.0 +0.20251022.0 diff --git a/src/sed/sedinstance.cpp b/src/sed/sedinstance.cpp index b402f3045..146297f36 100644 --- a/src/sed/sedinstance.cpp +++ b/src/sed/sedinstance.cpp @@ -67,6 +67,10 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument) } } } + + // Keep track of the issues of all the tasks. + + mTasksIssues = mIssues; } else { addError("The simulation experiment description does not contain any tasks to run."); } @@ -74,6 +78,12 @@ SedInstance::Impl::Impl(const SedDocumentPtr &pDocument) double SedInstance::Impl::run() { + // Reset iourselves. + + removeAllIssues(); + + mIssues = mTasksIssues; + // Run all the tasks associated with this instance unless they have some issues. auto res = 0.0; @@ -84,6 +94,10 @@ double SedInstance::Impl::run() if (task->hasIssues()) { addIssues(task); + + // Reset the issues of the task so that they are not reported again should the instance be run again. + + task->pimpl()->removeAllIssues(); } } } diff --git a/src/sed/sedinstance_p.h b/src/sed/sedinstance_p.h index 4b5dbc183..7260ac1ea 100644 --- a/src/sed/sedinstance_p.h +++ b/src/sed/sedinstance_p.h @@ -26,6 +26,7 @@ class SedInstance::Impl: public Logger::Impl { public: SedInstanceTaskPtrs mTasks; + IssuePtrs mTasksIssues; static SedInstancePtr create(const SedDocumentPtr &pDocument); diff --git a/src/sed/sedinstancetask.cpp b/src/sed/sedinstancetask.cpp index 387611acb..2c551f755 100644 --- a/src/sed/sedinstancetask.cpp +++ b/src/sed/sedinstancetask.cpp @@ -161,9 +161,17 @@ void SedInstanceTask::Impl::initialise() #else mRuntime->initialiseVariablesForDifferentialModel()(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); #endif + } else { +#ifdef __EMSCRIPTEN__ + mRuntime->initialiseVariablesForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); +#else + mRuntime->initialiseVariablesForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraic); +#endif + } - applyChanges(); + applyChanges(); + if (mSedUniformTimeCourse != nullptr) { #ifdef __EMSCRIPTEN__ mRuntime->computeComputedConstantsForDifferentialModel(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); mRuntime->computeRates(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); @@ -174,14 +182,6 @@ void SedInstanceTask::Impl::initialise() mRuntime->computeVariablesForDifferentialModel()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); #endif } else { -#ifdef __EMSCRIPTEN__ - mRuntime->initialiseVariablesForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); -#else - mRuntime->initialiseVariablesForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraic); -#endif - - applyChanges(); - #ifdef __EMSCRIPTEN__ mRuntime->computeComputedConstantsForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); mRuntime->computeVariablesForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); @@ -219,7 +219,7 @@ double SedInstanceTask::Impl::run() auto startTime = std::chrono::high_resolution_clock::now(); // (Re)initialise our model. - // Note: reinitialise our model in case we are running our model multiple times. + // Note: reinitialise our model because we initialised it when we created the instance task. initialise(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 104d9383b..d304bd2b8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,7 +38,7 @@ include(api/sed/tests.cmake) include(api/solver/tests.cmake) include(api/version/tests.cmake) -include(misc/compiler/tests.cmake) +include(misc/tests.cmake) include(support/cellml/tests.cmake) include(support/combine/tests.cmake) @@ -170,7 +170,9 @@ include_directories(${CMAKE_SOURCE_DIR}/src/misc foreach(TEST ${TESTS}) if(LIBOPENCOR_UNIT_TESTING) - if(NOT "${${TEST}_CATEGORY}" STREQUAL "") + if("${${TEST}_CATEGORY}" STREQUAL "") + set(TEST_CATEGORY) + else() set(TEST_CATEGORY "${${TEST}_CATEGORY}_") endif() diff --git a/tests/misc/compiler/tests.cpp b/tests/misc/compilertests.cpp similarity index 100% rename from tests/misc/compiler/tests.cpp rename to tests/misc/compilertests.cpp diff --git a/tests/misc/failingsimulationtests.cpp b/tests/misc/failingsimulationtests.cpp new file mode 100644 index 000000000..73edd599d --- /dev/null +++ b/tests/misc/failingsimulationtests.cpp @@ -0,0 +1,47 @@ +/* +Copyright libOpenCOR contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "tests/utils.h" + +#include + +TEST(FailingSimulationTest, basic) +{ + // Default simulation. + + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("../misc/res/tt04.omex")); + auto document = libOpenCOR::SedDocument::create(file); + auto instance = document->instantiate(); + + EXPECT_NE(instance->run(), 0.0); + EXPECT_FALSE(instance->hasIssues()); + + // Set the value of `membrane.test` to zero and rerun the simulation. + + auto model = document->model(0); + + model->addChange(libOpenCOR::SedChangeAttribute::create("membrane", "test", "0.0")); + + EXPECT_EQ(instance->run(), 0.0); + EXPECT_TRUE(instance->hasIssues()); + + // Remove all changes and rerun the simulation. + + model->removeAllChanges(); + + EXPECT_NE(instance->run(), 0.0); + EXPECT_FALSE(instance->hasIssues()); +} diff --git a/tests/misc/res/tt04.omex b/tests/misc/res/tt04.omex new file mode 100644 index 000000000..6ee337ac9 Binary files /dev/null and b/tests/misc/res/tt04.omex differ diff --git a/tests/misc/compiler/tests.cmake b/tests/misc/tests.cmake similarity index 81% rename from tests/misc/compiler/tests.cmake rename to tests/misc/tests.cmake index 30f88984a..5336fe44d 100644 --- a/tests/misc/compiler/tests.cmake +++ b/tests/misc/tests.cmake @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(TEST compiler) +set(TEST misc) list(APPEND TESTS ${TEST}) -set(${TEST}_CATEGORY misc) +set(${TEST}_CATEGORY) set(${TEST}_SOURCE_FILES - ${CMAKE_CURRENT_LIST_DIR}/tests.cpp + ${CMAKE_CURRENT_LIST_DIR}/compilertests.cpp + ${CMAKE_CURRENT_LIST_DIR}/failingsimulationtests.cpp )