28#ifndef OPM_FLASH_NEWTON_METHOD_HH
29#define OPM_FLASH_NEWTON_METHOD_HH
31#include <opm/common/Exceptions.hpp>
42template <
class TypeTag,
class MyTypeTag>
43struct DiscNewtonMethod;
54template <
class TypeTag>
66 enum { pressure0Idx = Indices::pressure0Idx };
67 enum { z0Idx = Indices::z0Idx };
68 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
70 static constexpr bool waterEnabled = Indices::waterEnabled;
87 PrimaryVariables& nextValue,
88 const PrimaryVariables& currentValue,
89 const EqVector& update,
94 const PrimaryVariables priVarsOld = currentValue;
97 nextValue = priVarsOld;
104 constexpr Scalar max_percent_change = 0.2;
105 constexpr Scalar upper_bound = 1. + max_percent_change;
106 constexpr Scalar lower_bound = 1. - max_percent_change;
107 nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
108 priVarsOld[pressure0Idx] * lower_bound,
109 priVarsOld[pressure0Idx] * upper_bound);
116 std::array<Scalar, numComponents> z{};
117 std::array<Scalar, numComponents> dz{};
119 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
120 z[compIdx] = priVarsOld[z0Idx + compIdx];
121 dz[compIdx] = -update[z0Idx + compIdx];
122 z.back() -= z[compIdx];
123 dz.back() -= dz[compIdx];
128 if constexpr (waterEnabled) {
129 sw = priVarsOld[Indices::water0Idx];
130 dSw = -update[Indices::water0Idx];
133 constexpr Scalar maxAmountChange = 0.2;
135 IntensiveQuantities::compositionFloor,
136 IntensiveQuantities::hydrocarbonFloor,
139 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
140 nextValue[z0Idx + compIdx] = z[compIdx];
142 if constexpr (waterEnabled) {
143 nextValue[Indices::water0Idx] = sw;
A Newton solver specific to the PTFlash model.
Definition: flashnewtonmethod.hh:56
FlashNewtonMethod(Simulator &simulator)
Definition: flashnewtonmethod.hh:76
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables ¤tValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: flashnewtonmethod.hh:86
friend ParentType
Definition: flashnewtonmethod.hh:80
The multi-dimensional Newton method.
Definition: newtonmethod.hh:100
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilmodel.hh:74
Definition: blackoilbioeffectsmodules.hh:45
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
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