Initial State Calculator: Refactor Cell Loop

This commit splits out the per-cell initial state derivation to two
separate helper functions, equilibrateCellCentres() and cellLoop().
The latter manages the per-cell assignments to pertinent data
members and calls an arbitrary "equilbration method" that is
provided as a callback and which calculates per-cell phase
pressures, phase saturations and mixing ratios (Rs/Rv).

In turn, the equilibrateCellCentres() uses the cellLoop() to affect
the existing equilibration procedure within a cell using values at
the depths of the cell centres only.
This commit is contained in:
Bård Skaflestad 2020-04-13 12:06:14 +02:00
parent 2696160f56
commit 6292855bd5

View File

@ -1681,11 +1681,9 @@ private:
const Grid& grid, const Grid& grid,
const double grav) const double grav)
{ {
using Opm::UgGridHelpers::cellCenterDepth;
using PhaseSat = Details::PhaseSaturations< using PhaseSat = Details::PhaseSaturations<
MaterialLawManager, FluidSystem, EquilReg, typename RMap::CellId MaterialLawManager, FluidSystem, EquilReg, typename RMap::CellId
>; >;
using CellPos = typename PhaseSat::Position;
auto ptable = Details::PressureTable<FluidSystem, EquilReg>{ grav }; auto ptable = Details::PressureTable<FluidSystem, EquilReg>{ grav };
auto psat = PhaseSat { materialLawManager, this->swatInit_ }; auto psat = PhaseSat { materialLawManager, this->swatInit_ };
@ -1693,14 +1691,6 @@ private:
auto vspan = std::array<double, 2>{}; auto vspan = std::array<double, 2>{};
auto ncell = 0; auto ncell = 0;
const auto oilActive = ptable.oilActive();
const auto gasActive = ptable.gasActive();
const auto watActive = ptable.waterActive();
const auto oilPos = FluidSystem::oilPhaseIdx;
const auto gasPos = FluidSystem::gasPhaseIdx;
const auto watPos = FluidSystem::waterPhaseIdx;
for (const auto& r : reg.activeRegions()) { for (const auto& r : reg.activeRegions()) {
const auto& cells = reg.cells(r); const auto& cells = reg.cells(r);
if (cells.empty()) { if (cells.empty()) {
@ -1720,13 +1710,31 @@ private:
ptable.equilibrate(eqreg, vspan); ptable.equilibrate(eqreg, vspan);
for (const auto& cell : cells) { // Centre-point method
const auto pos = CellPos { this->equilibrateCellCentres(cells, eqreg, grid,
cell, cellCenterDepth(grid, cell) ptable, psat);
}; }
}
const auto saturations = psat.deriveSaturations(pos, eqreg, ptable); template <class CellRange, class EquilibrationMethod>
const auto& pressures = psat.correctedPhasePressures(); void cellLoop(const CellRange& cells,
EquilibrationMethod&& eqmethod)
{
const auto oilPos = FluidSystem::oilPhaseIdx;
const auto gasPos = FluidSystem::gasPhaseIdx;
const auto watPos = FluidSystem::waterPhaseIdx;
const auto oilActive = FluidSystem::phaseIsActive(oilPos);
const auto gasActive = FluidSystem::phaseIsActive(gasPos);
const auto watActive = FluidSystem::phaseIsActive(watPos);
auto pressures = Details::PhaseQuantityValue{};
auto saturations = Details::PhaseQuantityValue{};
auto Rs = 0.0;
auto Rv = 0.0;
for (const auto& cell : cells) {
eqmethod(cell, pressures, saturations, Rs, Rv);
if (oilActive) { if (oilActive) {
this->pp_ [oilPos][cell] = pressures.oil; this->pp_ [oilPos][cell] = pressures.oil;
@ -1744,16 +1752,45 @@ private:
} }
if (oilActive && gasActive) { if (oilActive && gasActive) {
this->rs_[cell] = Rs;
this->rv_[cell] = Rv;
}
}
}
template <class CellRange, class Grid, class PressTable, class PhaseSat>
void equilibrateCellCentres(const CellRange& cells,
const EquilReg& eqreg,
const Grid& grid,
const PressTable& ptable,
PhaseSat& psat)
{
using CellPos = typename PhaseSat::Position;
using CellID = std::remove_cv_t<std::remove_reference_t<
decltype(std::declval<CellPos>().cell)>>;
this->cellLoop(cells, [this, &eqreg, &grid, &ptable, &psat]
(const CellID cell,
Details::PhaseQuantityValue& pressures,
Details::PhaseQuantityValue& saturations,
double& Rs,
double& Rv) -> void
{
const auto pos = CellPos {
cell, UgGridHelpers::cellCenterDepth(grid, cell)
};
saturations = psat.deriveSaturations(pos, eqreg, ptable);
pressures = psat.correctedPhasePressures();
const auto temp = this->temperature_[cell]; const auto temp = this->temperature_[cell];
this->rs_[cell] = (*this->rsFunc_[r]) Rs = eqreg.dissolutionCalculator()
(pos.depth, pressures.oil, temp, saturations.gas); (pos.depth, pressures.oil, temp, saturations.gas);
this->rv_[cell] = (*this->rvFunc_[r]) Rv = eqreg.evaporationCalculator()
(pos.depth, pressures.gas, temp, saturations.oil); (pos.depth, pressures.gas, temp, saturations.oil);
} });
}
}
} }
}; };
} // namespace DeckDependent } // namespace DeckDependent