82 PrimaryVariables& nextValue,
83 const PrimaryVariables& currentValue,
84 const EqVector& update,
88 nextValue = currentValue;
95 Scalar sumSatDelta = 0.0;
96 Scalar maxSatDelta = 0.0;
97 for (
unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
98 if (!currentValue.phaseIsPresent(phaseIdx)) {
102 maxSatDelta = std::max(std::abs(update[switch0Idx + phaseIdx]),
104 sumSatDelta += update[switch0Idx + phaseIdx];
106 maxSatDelta = std::max(std::abs(-sumSatDelta), maxSatDelta);
108 if (maxSatDelta > 0.2) {
109 const Scalar alpha = 0.2 / maxSatDelta;
110 for (
unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
111 if (!currentValue.phaseIsPresent(phaseIdx)) {
115 nextValue[switch0Idx + phaseIdx] =
116 currentValue[switch0Idx + phaseIdx] -
117 alpha * update[switch0Idx + phaseIdx];
122 nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
123 currentValue[pressure0Idx] * 0.8,
124 currentValue[pressure0Idx] * 1.2);