85 PrimaryVariables& nextValue,
86 const PrimaryVariables& currentValue,
87 const EqVector& update,
91 nextValue = currentValue;
98 constexpr Scalar max_percent_change = 0.2;
99 constexpr Scalar upper_bound = 1. + max_percent_change;
100 constexpr Scalar lower_bound = 1. - max_percent_change;
101 nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
102 currentValue[pressure0Idx] * lower_bound,
103 currentValue[pressure0Idx] * upper_bound);
109 Scalar maxDeltaZ = 0.0;
110 Scalar sumDeltaZ = 0.0;
111 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
112 maxDeltaZ = std::max(std::abs(update[z0Idx + compIdx]), maxDeltaZ);
113 sumDeltaZ += update[z0Idx + compIdx];
115 maxDeltaZ = std::max(std::abs(sumDeltaZ), maxDeltaZ);
121 constexpr Scalar deltaz_limit = 0.2;
122 if (maxDeltaZ > deltaz_limit) {
123 const Scalar alpha = deltaz_limit / maxDeltaZ;
124 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
125 nextValue[z0Idx + compIdx] = currentValue[z0Idx + compIdx] - alpha * update[z0Idx + compIdx];
130 constexpr Scalar tol = 1e-8;
131 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
132 nextValue[z0Idx + compIdx] = std::clamp(nextValue[z0Idx + compIdx], tol, 1-tol);
135 if constexpr (waterEnabled) {
137 constexpr Scalar dSwMax = 0.2;
138 if (update[Indices::water0Idx] > dSwMax) {
139 nextValue[Indices::water0Idx] = currentValue[Indices::water0Idx] - dSwMax;