[bugfix] Prevent accessing undefined variables for brine.

It seems like currentValue.primaryVarsMeaningBrine() will return an
uninitialized variable if enableSaltPrecipitation is false. This can
lead to undefined behavior especially in a parallel run. Hence we
also check whether salt precipitation is is enabled and do nothing
otherwise.
This commit is contained in:
Markus Blatt 2022-04-20 16:39:03 +02:00
parent 292a4cc517
commit fc0907b78d

View File

@ -348,7 +348,9 @@ protected:
const double sign = delta >= 0. ? 1. : -1.;
delta = sign * std::min(std::abs(delta), maxTempChange_);
}
else if (enableBrine && pvIdx == Indices::saltConcentrationIdx && currentValue.primaryVarsMeaningBrine() == PrimaryVariables::Sp) {
else if (enableBrine && pvIdx == Indices::saltConcentrationIdx &&
enableSaltPrecipitation &&
currentValue.primaryVarsMeaningBrine() == PrimaryVariables::Sp) {
const double maxSaltSaturationChange = 0.1;
const double sign = delta >= 0. ? 1. : -1.;
delta = sign * std::min(std::abs(delta), maxSaltSaturationChange);