From dedd7d3ad0ec882d819c73a08a7a2bbe48477b72 Mon Sep 17 00:00:00 2001 From: Jan Breuer Date: Thu, 19 Dec 2024 16:06:29 +0100 Subject: [PATCH] Fix nBin check --- .../model/reaction/CrystallizationReaction.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/libcadet/model/reaction/CrystallizationReaction.cpp b/src/libcadet/model/reaction/CrystallizationReaction.cpp index 0aa303059..49ae9ddb3 100644 --- a/src/libcadet/model/reaction/CrystallizationReaction.cpp +++ b/src/libcadet/model/reaction/CrystallizationReaction.cpp @@ -470,16 +470,9 @@ class CrystallizationReaction : public IDynamicReactionModel { readScalarParameterOrArray(_bins, paramProvider, "CRY_BINS", 1); - if (_usePBM) - { - if (_bins.size() != _nBins + 2) - throw InvalidParameterException("Expected CRY_BINS to have " + std::to_string(_nBins + 2) + " elements (got " + std::to_string(_bins.size()) + ")"); - } - else - { + if (_bins.size() != _nBins + 1) throw InvalidParameterException("Expected CRY_BINS to have " + std::to_string(_nBins + 1) + " elements (got " + std::to_string(_bins.size()) + ")"); - } registerParam1DArray(_parameters, _bins, [=](bool multi, unsigned int idx) { return makeParamId(hashString("CRY_BINS"), unitOpIdx, CompIndep, ParTypeIndep, BoundStateIndep, idx, SectionIndep); }); @@ -992,9 +985,8 @@ class CrystallizationReaction : public IDynamicReactionModel const StateType sParam = (cadet_likely(y[0] / y[_nComp - 1] - 1.0 > 0)) ? y[0] / y[_nComp - 1] - 1.0 : 0.0; // s = (c_0 - c_eq) / c_eq = c_0 / c_eq - 1, rewrite it to zero if s drops below 0 const ParamType massDensityShapeFactor = static_cast(_nucleiMassDensity) * static_cast(_volShapeFactor); - const ResidualType k_g_times_s_g = static_cast(_growthRateConstant) * pow(sParam, static_cast(_g)); + k_g_times_s_g = static_cast(_growthRateConstant) * pow(sParam, static_cast(_g)); - ResidualType MParam = 0.0; ResidualType substrateConversion = 0.0; for (int i = 0; i < _nBins; ++i) @@ -1012,7 +1004,6 @@ class CrystallizationReaction : public IDynamicReactionModel // mass balance res[0] -= factor * massDensityShapeFactor * (B_0 * x_c_3 + substrateConversion); - ResidualType v_g = 0.0; // growth flux reconstruction switch (_growthSchemeOrder) @@ -1065,6 +1056,11 @@ class CrystallizationReaction : public IDynamicReactionModel StateType const* const yCrystal = y; ResidualType* const resCrystal = res; + // define and initialize mass balance and its discretization related parameters + ResidualType MParam = 0.0; + ResidualType v_g = 0.0; + ResidualType k_g_times_s_g = 0.0; + // define aggregation/fragmentation related local parameters ResidualType source = 0.0; ResidualType sink = 0.0;