26#ifndef OPM_FLASH_COMPOSITION_STEP_HH
27#define OPM_FLASH_COMPOSITION_STEP_HH
40template <
class Scalar, std::
size_t numComponents>
43 Scalar excessSum = 0.0;
45 zc = std::max(zc - compositionFloor, Scalar{0});
49 const Scalar excessTotal = 1 - numComponents * compositionFloor;
51 zc = compositionFloor + excessTotal * zc / excessSum;
56template <
class Scalar, std::
size_t numComponents>
58 const std::array<Scalar, numComponents>& z,
59 const Scalar otherShare,
60 const std::array<Scalar, numComponents>& otherZ)
62 Scalar change = std::abs(otherShare - share);
63 for (std::size_t compIdx = 0; compIdx < numComponents; ++compIdx) {
64 change = std::max(std::abs(otherShare * otherZ[compIdx] - share * z[compIdx]), change);
73template <
class Scalar, std::
size_t numComponents>
76 const std::array<Scalar, numComponents>& newZ,
77 const Scalar newShare,
78 const Scalar compositionFloor,
79 const Scalar hydrocarbonFloor,
80 const Scalar maxAmountChange)
82 const Scalar share = std::max(1 - sw, hydrocarbonFloor);
83 std::array<Scalar, numComponents> startZ = z;
85 const Scalar startShare = std::max(1 - std::clamp(sw, Scalar{0}, Scalar{1}),
91 const Scalar scale = offset < maxAmountChange ? (maxAmountChange - offset) / length
94 const Scalar finalShare = startShare + scale * (newShare - startShare);
95 for (std::size_t compIdx = 0; compIdx < numComponents; ++compIdx) {
96 const Scalar startAmount = startShare * startZ[compIdx];
97 const Scalar newAmount = newShare * newZ[compIdx];
98 z[compIdx] = (startAmount + scale * (newAmount - startAmount)) / finalShare;
138template <
class Scalar, std::
size_t numComponents>
141 const std::array<Scalar, numComponents>& dz,
143 const Scalar compositionFloor,
144 const Scalar hydrocarbonFloor,
145 const Scalar maxAmountChange)
147 const Scalar hydrocarbonShare = std::max(1 - sw, hydrocarbonFloor);
148 const Scalar dHydrocarbonShare = -dSw;
152 Scalar maxChange = std::abs(dHydrocarbonShare);
153 for (std::size_t compIdx = 0; compIdx < numComponents; ++compIdx) {
154 const Scalar dAmount = hydrocarbonShare * dz[compIdx] + z[compIdx] * dHydrocarbonShare;
155 maxChange = std::max(std::abs(dAmount), maxChange);
157 const Scalar alpha = maxChange > maxAmountChange ? maxAmountChange / maxChange : 1.0;
159 const Scalar newSw = std::clamp(sw + alpha * dSw, Scalar{0}, Scalar{1});
160 const Scalar newHydrocarbonShare = std::max(1 - newSw, hydrocarbonFloor);
165 const bool vanished = newHydrocarbonShare <= hydrocarbonFloor;
166 const Scalar zStepScale = vanished ? Scalar{0}
167 : alpha * hydrocarbonShare / newHydrocarbonShare;
168 std::array<Scalar, numComponents> newZ{};
169 for (std::size_t compIdx = 0; compIdx < numComponents; ++compIdx) {
170 newZ[compIdx] = z[compIdx] + zStepScale * dz[compIdx];
176 newHydrocarbonShare, newZ);
177 if (change <= maxAmountChange) {
183 compositionFloor, hydrocarbonFloor, maxAmountChange);
Scalar largestAmountChange(const Scalar share, const std::array< Scalar, numComponents > &z, const Scalar otherShare, const std::array< Scalar, numComponents > &otherZ)
Largest change of the hydrocarbon share h or of an amount h z between two states.
Definition: flashcompositionstep.hh:57
void shortenStep(std::array< Scalar, numComponents > &z, Scalar &sw, const std::array< Scalar, numComponents > &newZ, const Scalar newShare, const Scalar compositionFloor, const Scalar hydrocarbonFloor, const Scalar maxAmountChange)
Definition: flashcompositionstep.hh:74
void keepCompositionFloor(std::array< Scalar, numComponents > &z, const Scalar compositionFloor)
Definition: flashcompositionstep.hh:41
Definition: blackoilbioeffectsmodules.hh:45
void applyFlashCompositionStep(std::array< Scalar, numComponents > &z, Scalar &sw, const std::array< Scalar, numComponents > &dz, const Scalar dSw, const Scalar compositionFloor, const Scalar hydrocarbonFloor, const Scalar maxAmountChange)
Applies a Newton step to the overall composition and the water saturation.
Definition: flashcompositionstep.hh:139