112 void update(
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
114 ParentType::update(elemCtx, dofIdx, timeIdx);
115 EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
117 const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
118 const auto& problem = elemCtx.problem();
127 ComponentVector z(0.);
129 Evaluation lastZ = 1.0;
130 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
131 z[compIdx] = priVars.makeEvaluation(z0Idx + compIdx, timeIdx);
134 z[numComponents - 1] = lastZ;
136 Evaluation sumz = 0.0;
137 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
138 z[compIdx] = max(z[compIdx], 1e-8);
144 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
145 fluidState_.setMoleFraction(compIdx, z[compIdx]);
148 Evaluation p = priVars.makeEvaluation(pressure0Idx, timeIdx);
149 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
150 fluidState_.setPressure(phaseIdx, p);
154 const auto* hint = elemCtx.thermodynamicHint(dofIdx, timeIdx);
156 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
157 const Evaluation& Ktmp = hint->fluidState().K(compIdx);
158 fluidState_.setKvalue(compIdx, Ktmp);
160 const Evaluation& Ltmp = hint->fluidState().L();
161 fluidState_.setLvalue(Ltmp);
163 else if (timeIdx == 0 && elemCtx.thermodynamicHint(dofIdx, 1)) {
165 const auto& hint2 = elemCtx.thermodynamicHint(dofIdx, 1);
166 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
167 const Evaluation& Ktmp = hint2->fluidState().K(compIdx);
168 fluidState_.setKvalue(compIdx, Ktmp);
170 const Evaluation& Ltmp = hint2->fluidState().L();
171 fluidState_.setLvalue(Ltmp);
174 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
175 const Evaluation Ktmp = fluidState_.wilsonK_(compIdx);
176 fluidState_.setKvalue(compIdx, Ktmp);
178 const Evaluation& Ltmp = -1.0;
179 fluidState_.setLvalue(Ltmp);
185 if (flashVerbosity >= 1) {
186 const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
187 std::cout <<
" updating the intensive quantities for Cell " << spatialIdx << std::endl;
189 const auto& eos_type = problem.getEosType();
190 FlashSolver::solve(fluidState_, flashTwoPhaseMethod, flashTolerance, eos_type, flashVerbosity);
192 if (flashVerbosity >= 5) {
194 const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
195 std::cout <<
" \n After flash solve for cell " << spatialIdx << std::endl;
196 ComponentVector x, y;
197 for (
unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
198 x[comp_idx] = fluidState_.moleFraction(FluidSystem::oilPhaseIdx, comp_idx);
199 y[comp_idx] = fluidState_.moleFraction(FluidSystem::gasPhaseIdx, comp_idx);
201 for (
unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
202 std::cout <<
" x for component: " << comp_idx <<
" is:" << std::endl;
203 std::cout << x[comp_idx] << std::endl;
205 std::cout <<
" y for component: " << comp_idx <<
"is:" << std::endl;
206 std::cout << y[comp_idx] << std::endl;
208 const Evaluation& L = fluidState_.L();
209 std::cout <<
" L is:" << std::endl;
210 std::cout << L << std::endl;
214 typename FluidSystem::template ParameterCache<Evaluation> paramCache(eos_type);
215 paramCache.updatePhase(fluidState_, FluidSystem::oilPhaseIdx);
217 const Scalar R = Opm::Constants<Scalar>::R;
218 const Evaluation Z_L = (paramCache.molarVolume(FluidSystem::oilPhaseIdx) *
219 fluidState_.pressure(FluidSystem::oilPhaseIdx)) /
220 (R * fluidState_.temperature(FluidSystem::oilPhaseIdx));
221 paramCache.updatePhase(fluidState_, FluidSystem::gasPhaseIdx);
222 const Evaluation Z_V = (paramCache.molarVolume(FluidSystem::gasPhaseIdx) *
223 fluidState_.pressure(FluidSystem::gasPhaseIdx)) /
224 (R * fluidState_.temperature(FluidSystem::gasPhaseIdx));
228 if constexpr (waterEnabled) {
229 Sw = priVars.makeEvaluation(water0Idx, timeIdx);
231 const Evaluation L = fluidState_.L();
232 Evaluation So = max((1 - Sw) * (L * Z_L / ( L * Z_L + (1 - L) * Z_V)), 0.0);
233 Evaluation Sg = max(1 - So - Sw, 0.0);
234 const Scalar sumS = getValue(So) + getValue(Sg) + getValue(Sw);
238 fluidState_.setSaturation(FluidSystem::oilPhaseIdx, So);
239 fluidState_.setSaturation(FluidSystem::gasPhaseIdx, Sg);
240 if constexpr (waterEnabled) {
242 fluidState_.setSaturation(FluidSystem::waterPhaseIdx, Sw);
245 fluidState_.setCompressFactor(FluidSystem::oilPhaseIdx, Z_L);
246 fluidState_.setCompressFactor(FluidSystem::gasPhaseIdx, Z_V);
249 if (flashVerbosity >= 5) {
250 std::cout <<
"So = " << So << std::endl;
251 std::cout <<
"Sg = " << Sg << std::endl;
252 std::cout <<
"Z_L = " << Z_L << std::endl;
253 std::cout <<
"Z_V = " << Z_V << std::endl;
259 const MaterialLawParams& materialParams = problem.materialLawParams(elemCtx, dofIdx, timeIdx);
262 MaterialLaw::relativePermeabilities(relativePermeability_,
263 materialParams, fluidState_);
264 Valgrind::CheckDefined(relativePermeability_);
267 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
268 if (phaseIdx ==
static_cast<unsigned int>(FluidSystem::oilPhaseIdx) ||
269 phaseIdx ==
static_cast<unsigned int>(FluidSystem::gasPhaseIdx))
271 paramCache.updatePhase(fluidState_, phaseIdx);
274 const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
276 fluidState_.setViscosity(phaseIdx, mu);
278 mobility_[phaseIdx] = relativePermeability_[phaseIdx] / mu;
279 Valgrind::CheckDefined(mobility_[phaseIdx]);
281 const Evaluation& rho = FluidSystem::density(fluidState_, paramCache, phaseIdx);
282 fluidState_.setDensity(phaseIdx, rho);
290 porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
291 Valgrind::CheckDefined(porosity_);
294 intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
297 FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
300 EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
303 DiffusionIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);