From 041d72721a1db2c3ba2652109ca43a864729a49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Tue, 18 Jan 2022 17:53:14 +0100 Subject: [PATCH 1/3] Call getter for sectionDependentScalar. --- src/libcadet/model/StirredTankModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcadet/model/StirredTankModel.cpp b/src/libcadet/model/StirredTankModel.cpp index 3e6cf83a8..d5882c9dc 100644 --- a/src/libcadet/model/StirredTankModel.cpp +++ b/src/libcadet/model/StirredTankModel.cpp @@ -420,7 +420,7 @@ void CSTRModel::notifyDiscontinuousSectionTransition(double t, unsigned int secI { if (_flowRateFilter.size() > 1) { - _curFlowRateFilter = _flowRateFilter[secIdx]; + _curFlowRateFilter = getSectionDependentScalar(_flowRateFilter, secIdx); } else if (_flowRateFilter.size() == 1) { From 926a7638256e6c32f707277e2397b50c20bc8653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Wed, 19 Jan 2022 11:39:48 +0100 Subject: [PATCH 2/3] Simplify notifyDiscontinuousSectionTransition --- src/libcadet/model/StirredTankModel.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libcadet/model/StirredTankModel.cpp b/src/libcadet/model/StirredTankModel.cpp index d5882c9dc..874d81a10 100644 --- a/src/libcadet/model/StirredTankModel.cpp +++ b/src/libcadet/model/StirredTankModel.cpp @@ -418,14 +418,7 @@ void CSTRModel::useAnalyticJacobian(const bool analyticJac) void CSTRModel::notifyDiscontinuousSectionTransition(double t, unsigned int secIdx, const ConstSimulationState& simState, const AdJacobianParams& adJac) { - if (_flowRateFilter.size() > 1) - { - _curFlowRateFilter = getSectionDependentScalar(_flowRateFilter, secIdx); - } - else if (_flowRateFilter.size() == 1) - { - _curFlowRateFilter = _flowRateFilter[0]; - } + _curFlowRateFilter = getSectionDependentScalar(_flowRateFilter, secIdx); } void CSTRModel::reportSolution(ISolutionRecorder& recorder, double const* const solution) const From 0f7defba4e7e4d12750af58ff629bd1e4ccad7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Wed, 9 Feb 2022 16:19:29 +0100 Subject: [PATCH 3/3] Check if USER_SOLUTION_TIMES exceed section times --- include/common/Driver.hpp | 8 ++++---- src/libcadet/SimulatorImpl.cpp | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/common/Driver.hpp b/include/common/Driver.hpp index fb4244f99..dc2692128 100644 --- a/include/common/Driver.hpp +++ b/include/common/Driver.hpp @@ -253,23 +253,23 @@ class Driver // Configure main solver parameters pp.pushScope("solver"); - _sim->configure(pp); - + // Configure section times std::vector secTimes; std::vector secCont; extractSectionTimes(pp, secTimes, secCont); + _sim->setSectionTimes(secTimes, secCont); + _sim->configure(pp); pp.popScope(); // solver scope + // Create and configure model pp.pushScope("model"); - // Create and configure model cadet::IModelSystem* model = _builder->createSystem(pp); // Hand model over to simulator _sim->initializeModel(*model); - _sim->setSectionTimes(secTimes, secCont); // Specify initial values if (pp.exists("INIT_STATE_Y")) diff --git a/src/libcadet/SimulatorImpl.cpp b/src/libcadet/SimulatorImpl.cpp index 515a6072b..308e07512 100644 --- a/src/libcadet/SimulatorImpl.cpp +++ b/src/libcadet/SimulatorImpl.cpp @@ -1490,6 +1490,11 @@ namespace cadet if (paramProvider.exists("USER_SOLUTION_TIMES")) _solutionTimes = paramProvider.getDoubleArray("USER_SOLUTION_TIMES"); + if (static_cast(_solutionTimes.back()) > static_cast(_sectionTimes.back())) + { + throw InvalidParameterException("USER_SOLUTION_TIMES exceed section times"); + } + if (paramProvider.exists("CONSISTENT_INIT_MODE")) _consistentInitMode = toConsistentInitialization(paramProvider.getInt("CONSISTENT_INIT_MODE"));