28#ifndef OPM_BLACK_OIL_NEWTON_UPDATE_HPP
29#define OPM_BLACK_OIL_NEWTON_UPDATE_HPP
31#include <opm/common/utility/gpuDecorators.hpp>
35#include <opm/material/common/Valgrind.hpp>
45template<
class TypeTag>
50 static constexpr unsigned numEq = getPropValue<TypeTag, Properties::NumEq>();
51 static constexpr bool enableBioeffects = getPropValue<TypeTag, Properties::EnableBioeffects>();
54 template<
class Problem,
class Flu
idSystem,
class PrimaryVariables,
class Update>
55 OPM_HOST_DEVICE
static bool update(
const Problem& problem,
56 const FluidSystem& fluidSystem,
57 unsigned globalDofIdx,
58 PrimaryVariables& nextValue,
59 const PrimaryVariables& currentValue,
64 static constexpr bool enableSolvent =
65 Indices::solventSaturationIdx != std::numeric_limits<unsigned>::max();
66 static constexpr bool enableExtbo =
67 Indices::zFractionIdx != std::numeric_limits<unsigned>::max();
68 static constexpr bool enablePolymer =
69 Indices::polymerConcentrationIdx != std::numeric_limits<unsigned>::max();
70 static constexpr bool enablePolymerWeight =
71 Indices::polymerMoleWeightIdx != std::numeric_limits<unsigned>::max();
72 static constexpr bool enableFullyImplicitThermal =
73 Indices::temperatureIdx != std::numeric_limits<unsigned>::max();
74 static constexpr bool enableFoam =
75 Indices::foamConcentrationIdx != std::numeric_limits<unsigned>::max();
76 static constexpr bool enableBrine =
77 Indices::saltConcentrationIdx != std::numeric_limits<unsigned>::max();
78 static constexpr bool enableMICP = Indices::enableMICP;
80 currentValue.checkDefined();
81 Valgrind::CheckDefined(
update);
89 if (currentValue.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw)
91 if constexpr (Indices::waterSwitchIdx != std::numeric_limits<unsigned>::max()) {
92 deltaSw =
update[Indices::waterSwitchIdx];
96 if (currentValue.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Sg)
98 if constexpr (Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max()) {
99 deltaSg =
update[Indices::compositionSwitchIdx];
103 if (currentValue.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
104 if constexpr (Indices::solventSaturationIdx != std::numeric_limits<unsigned>::max()) {
105 deltaSs =
update[Indices::solventSaturationIdx];
111 Scalar maxSatDelta = std::max(std::abs(deltaSg), std::abs(deltaSo));
112 maxSatDelta = std::max(maxSatDelta, std::abs(deltaSw));
113 maxSatDelta = std::max(maxSatDelta, std::abs(deltaSs));
118 if (maxSatDelta > params.
dsMax_) {
119 satAlpha = params.
dsMax_ / maxSatDelta;
122 for (
unsigned pvIdx = 0; pvIdx <
numEq; ++pvIdx) {
132 if (pvIdx == Indices::pressureSwitchIdx) {
133 if (std::abs(delta) > params.
dpMaxRel_ * currentValue[pvIdx]) {
138 else if (pvIdx == Indices::waterSwitchIdx)
139 if (currentValue.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
144 if (delta > currentValue[ Indices::waterSwitchIdx]) {
145 delta = currentValue[ Indices::waterSwitchIdx];
148 else if (pvIdx == Indices::compositionSwitchIdx) {
154 if (currentValue.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Sg) {
159 if (delta > currentValue[Indices::compositionSwitchIdx]) {
160 delta = currentValue[Indices::compositionSwitchIdx];
164 else if (enableSolvent && pvIdx == Indices::solventSaturationIdx) {
166 if (currentValue.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
171 if (delta > currentValue[Indices::solventSaturationIdx]) {
172 delta = currentValue[Indices::solventSaturationIdx];
176 else if (enableExtbo && pvIdx == Indices::zFractionIdx) {
178 const auto& curr = currentValue[Indices::zFractionIdx];
179 delta = std::clamp(delta, curr -
Scalar{1.0}, curr);
181 else if (enablePolymerWeight && pvIdx == Indices::polymerMoleWeightIdx) {
182 const double sign = delta >= 0. ? 1. : -1.;
185 const Scalar maxMolarWeightChange = 100.0;
186 delta = sign * std::min(std::abs(delta), maxMolarWeightChange);
189 else if (enableFullyImplicitThermal && pvIdx == Indices::temperatureIdx) {
190 const double sign = delta >= 0. ? 1. : -1.;
193 else if (enableBrine && pvIdx == Indices::saltConcentrationIdx &&
195 currentValue.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp)
197 const Scalar maxSaltSaturationChange = 0.1;
198 const Scalar sign = delta >= 0. ? 1. : -1.;
199 delta = sign * std::min(std::abs(delta), maxSaltSaturationChange);
203 nextValue[pvIdx] = currentValue[pvIdx] - delta;
206 if (enableSolvent && pvIdx == Indices::solventSaturationIdx) {
207 if (currentValue.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
208 nextValue[pvIdx] = std::min(std::max(nextValue[pvIdx],
Scalar{0.0}),
Scalar{1.0});
213 if (enableExtbo && pvIdx == Indices::zFractionIdx) {
214 nextValue[pvIdx] = std::min(std::max(nextValue[pvIdx],
Scalar{0.0}),
Scalar{1.0});
218 if (enablePolymer && pvIdx == Indices::polymerConcentrationIdx) {
219 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
222 if (enablePolymerWeight && pvIdx == Indices::polymerMoleWeightIdx) {
223 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
224 const double polymerConcentration = nextValue[Indices::polymerConcentrationIdx];
225 if (polymerConcentration < 1.e-10) {
226 nextValue[pvIdx] = 0.0;
231 if (enableFoam && pvIdx == Indices::foamConcentrationIdx) {
232 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
235 if (enableBrine && pvIdx == Indices::saltConcentrationIdx) {
238 currentValue.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Cs)
240 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
244 currentValue.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp)
246 nextValue[pvIdx] = std::min(nextValue[pvIdx],
Scalar{1.0-1.e-8});
251 if (enableFullyImplicitThermal && pvIdx == Indices::temperatureIdx) {
252 nextValue[pvIdx] = std::clamp(nextValue[pvIdx], params.
tempMin_, params.
tempMax_);
255 if (pvIdx == Indices::pressureSwitchIdx) {
265 if (pvIdx == Indices::microbialConcentrationIdx) {
266 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
268 if (pvIdx == Indices::biofilmVolumeFractionIdx) {
269 nextValue[pvIdx] = std::clamp(nextValue[pvIdx],
271 problem.referencePorosity(globalDofIdx, 0) - 1e-8);
273 if constexpr (enableMICP) {
274 if (pvIdx == Indices::oxygenConcentrationIdx) {
275 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
277 if (pvIdx == Indices::ureaConcentrationIdx) {
278 nextValue[pvIdx] = std::max(nextValue[pvIdx],
Scalar{0.0});
280 if (pvIdx == Indices::calciteVolumeFractionIdx) {
281 nextValue[pvIdx] = std::clamp(nextValue[pvIdx],
Scalar{0.0},
282 problem.referencePorosity(globalDofIdx, 0) - 1e-8);
291 const bool switched = nextValue.adaptPrimaryVariables(
296 nextValue.chopAndNormalizeSaturations();
299 nextValue.checkDefined();
Defines a type tags and some fundamental properties all models.
Declares the properties required by the black oil model.
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
Definition: blackoilnewtonupdate.hpp:47
GetPropType< TypeTag, Properties::Indices > Indices
Definition: blackoilnewtonupdate.hpp:49
static OPM_HOST_DEVICE bool update(const Problem &problem, const FluidSystem &fluidSystem, unsigned globalDofIdx, PrimaryVariables &nextValue, const PrimaryVariables ¤tValue, const Update &update, const BlackoilNewtonParams< Scalar > ¶ms, bool wasSwitched)
Definition: blackoilnewtonupdate.hpp:55
static constexpr unsigned numEq
Definition: blackoilnewtonupdate.hpp:50
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: blackoilnewtonupdate.hpp:48
static constexpr bool enableSaltPrecipitation
Definition: blackoilnewtonupdate.hpp:52
static constexpr bool enableBioeffects
Definition: blackoilnewtonupdate.hpp:51
Struct holding the parameters for BlackoilNewtonMethod.
Definition: blackoilnewtonmethodparams.hpp:74
Scalar waterOnlyThreshold_
Definition: blackoilnewtonmethodparams.hpp:83
Scalar tempMin_
Definition: blackoilnewtonmethodparams.hpp:90
Scalar waterSaturationMax_
Definition: blackoilnewtonmethodparams.hpp:82
Scalar tempMax_
Definition: blackoilnewtonmethodparams.hpp:89
Scalar maxTempChange_
Definition: blackoilnewtonmethodparams.hpp:88
Scalar priVarOscilationThreshold_
Definition: blackoilnewtonmethodparams.hpp:81
Scalar dsMax_
Definition: blackoilnewtonmethodparams.hpp:86
Scalar dpMaxRel_
Definition: blackoilnewtonmethodparams.hpp:85
Scalar pressMin_
Definition: blackoilnewtonmethodparams.hpp:92
Scalar pressMax_
Definition: blackoilnewtonmethodparams.hpp:91
bool projectSaturations_
Definition: blackoilnewtonmethodparams.hpp:87