20#ifndef OPM_REGIONAVERAGECALCULATOR_HPP_HEADER_INCLUDED
21#define OPM_REGIONAVERAGECALCULATOR_HPP_HEADER_INCLUDED
28#include <dune/grid/common/gridenums.hh>
29#include <dune/grid/common/rangegenerators.hh>
33#include <unordered_map>
46 namespace RegionAverageCalculator {
59 template <
class Flu
idSystem,
class Region>
62 using Scalar =
typename FluidSystem::Scalar;
74 , attr_ (rmap_, Attributes())
82 template <
typename ElementContext,
class Simulator>
86 const auto& gridView = simulator.
gridView();
87 const auto& comm = gridView.comm();
88 for (
const auto& reg : rmap_.activeRegions()) {
89 numRegions = std::max(numRegions, reg);
91 numRegions = comm.max(numRegions);
92 for (
int reg = 1; reg <= numRegions ; ++ reg) {
94 attr_.insert(reg, Attributes());
98 for (
int reg = 1; reg <= numRegions ; ++ reg) {
99 auto& ra = attr_.attributes(reg);
106 std::unordered_map<RegionId, Attributes> attributes_pv;
109 std::unordered_map<RegionId, Attributes> attributes_hpv;
111 for (
int reg = 1; reg <= numRegions ; ++ reg) {
112 attributes_pv.insert({reg, Attributes()});
113 attributes_hpv.insert({reg, Attributes()});
116 ElementContext elemCtx( simulator );
119 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
120 elemCtx.updatePrimaryStencil(elem);
121 elemCtx.updatePrimaryIntensiveQuantities(0);
122 const unsigned cellIdx = elemCtx.globalSpaceIndex(0, 0);
123 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
124 const auto& fs = intQuants.fluidState();
127 simulator.
model().dofTotalVolume(cellIdx)
128 * intQuants.porosity().value();
132 const auto& pu = phaseUsage_;
134 hydrocarbon -= fs.saturation(FluidSystem::waterPhaseIdx).value();
137 const int reg = rmap_.region(cellIdx);
141 const Scalar hydrocarbonPV = pv_cell*hydrocarbon;
142 if (hydrocarbonPV > 0.) {
143 auto& attr = attributes_hpv[reg];
144 attr.pv += hydrocarbonPV;
146 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
149 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
154 auto& attr = attributes_pv[reg];
157 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * pv_cell;
159 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * pv_cell;
162 attr.pressure += fs.pressure(FluidSystem::waterPhaseIdx).value() * pv_cell;
168 for (
int reg = 1; reg <= numRegions ; ++ reg) {
169 auto& ra = attr_.attributes(reg);
170 const Scalar hpv_sum = comm.sum(attributes_hpv[reg].pv);
173 const auto& attri_hpv = attributes_hpv[reg];
174 const Scalar p_hpv_sum = comm.sum(attri_hpv.pressure);
175 ra.pressure = p_hpv_sum / hpv_sum;
178 const auto& attri_pv = attributes_pv[reg];
179 const Scalar pv_sum = comm.sum(attri_pv.pv);
182 const Scalar p_pv_sum = comm.sum(attri_pv.pressure);
183 ra.pressure = p_pv_sum / pv_sum;
206 int num_active_regions = 0;
207 for (
const auto& attr : attr_.attributes()) {
208 const auto& value = *attr.second;
209 const auto& ra = value.attr_;
211 num_active_regions ++;
213 return pressure / num_active_regions;
216 const auto& ra = attr_.attributes(r);
230 const RegionMapping<Region> rmap_;
246 RegionAttributeHelpers::RegionAttributes<RegionId, Attributes> attr_;
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:192
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:158
Definition: RegionAverageCalculator.hpp:60
typename FluidSystem::Scalar Scalar
Definition: RegionAverageCalculator.hpp:62
AverageRegionalPressure(const PhaseUsage &phaseUsage, const Region ®ion)
Definition: RegionAverageCalculator.hpp:70
void defineState(const Simulator &simulator)
Definition: RegionAverageCalculator.hpp:83
RegionMapping< Region >::RegionId RegionId
Definition: RegionAverageCalculator.hpp:194
Scalar pressure(const RegionId r) const
Definition: RegionAverageCalculator.hpp:201
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:92
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:260
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:272
Model & model()
Return the physical model used in the simulation.
Definition: simulator.hh:278
bool water(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:309
bool oil(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:322
bool gas(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:335
Definition: blackoilboundaryratevector.hh:37
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
int RegionId
Definition: WellConstraints.hpp:37
Definition: BlackoilPhases.hpp:46