28#ifndef OPM_FLASH_NEWTON_METHOD_HH
29#define OPM_FLASH_NEWTON_METHOD_HH
31#include <opm/common/Exceptions.hpp>
41template <
class TypeTag,
class MyTypeTag>
42struct DiscNewtonMethod;
53template <
class TypeTag>
64 enum { pressure0Idx = Indices::pressure0Idx };
65 enum { z0Idx = Indices::z0Idx };
66 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
68 static constexpr bool waterEnabled = Indices::waterEnabled;
85 PrimaryVariables& nextValue,
86 const PrimaryVariables& currentValue,
87 const EqVector& update,
92 const PrimaryVariables priVarsOld = currentValue;
95 nextValue = priVarsOld;
102 constexpr Scalar max_percent_change = 0.2;
103 constexpr Scalar upper_bound = 1. + max_percent_change;
104 constexpr Scalar lower_bound = 1. - max_percent_change;
105 nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
106 priVarsOld[pressure0Idx] * lower_bound,
107 priVarsOld[pressure0Idx] * upper_bound);
113 Scalar maxDeltaZ = 0.0;
114 Scalar sumDeltaZ = 0.0;
115 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
116 maxDeltaZ = std::max(std::abs(update[z0Idx + compIdx]), maxDeltaZ);
117 sumDeltaZ += update[z0Idx + compIdx];
119 maxDeltaZ = std::max(std::abs(sumDeltaZ), maxDeltaZ);
125 constexpr Scalar deltaz_limit = 0.2;
126 if (maxDeltaZ > deltaz_limit) {
127 const Scalar alpha = deltaz_limit / maxDeltaZ;
128 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
129 nextValue[z0Idx + compIdx] = priVarsOld[z0Idx + compIdx] - alpha * update[z0Idx + compIdx];
134 constexpr Scalar tol = 1e-8;
135 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
136 nextValue[z0Idx + compIdx] = std::clamp(nextValue[z0Idx + compIdx], tol, 1-tol);
139 if constexpr (waterEnabled) {
141 constexpr Scalar dSwMax = 0.2;
142 if (update[Indices::water0Idx] > dSwMax) {
143 nextValue[Indices::water0Idx] = priVarsOld[Indices::water0Idx] - dSwMax;
A Newton solver specific to the PTFlash model.
Definition: flashnewtonmethod.hh:55
FlashNewtonMethod(Simulator &simulator)
Definition: flashnewtonmethod.hh:74
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables ¤tValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition: flashnewtonmethod.hh:84
friend ParentType
Definition: flashnewtonmethod.hh:78
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