90 const auto& gridView = simulator.gridView();
91 const auto& comm = gridView.comm();
92 for (
const auto& reg : rmap_.activeRegions()) {
93 numRegions = std::max(numRegions, reg);
95 numRegions = comm.max(numRegions);
96 for (
int reg = 1; reg <= numRegions ; ++ reg) {
98 attr_.insert(reg, Attributes());
102 for (
int reg = 1; reg <= numRegions ; ++ reg) {
103 auto& ra = attr_.attributes(reg);
110 std::unordered_map<RegionId, Attributes> attributes_pv;
113 std::unordered_map<RegionId, Attributes> attributes_hpv;
115 for (
int reg = 1; reg <= numRegions ; ++ reg) {
116 attributes_pv.insert({reg, Attributes()});
117 attributes_hpv.insert({reg, Attributes()});
120 ElementContext elemCtx( simulator );
122 OPM_BEGIN_PARALLEL_TRY_CATCH();
123 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
124 elemCtx.updatePrimaryStencil(elem);
125 elemCtx.updatePrimaryIntensiveQuantities(0);
126 const unsigned cellIdx = elemCtx.globalSpaceIndex(0, 0);
127 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
128 const auto& fs = intQuants.fluidState();
130 const double pv_cell =
131 simulator.model().dofTotalVolume(cellIdx)
132 * intQuants.porosity().value();
135 double hydrocarbon = 1.0;
136 const auto& pu = phaseUsage_;
138 hydrocarbon -= fs.saturation(FluidSystem::waterPhaseIdx).value();
141 const int reg = rmap_.region(cellIdx);
145 const double hydrocarbonPV = pv_cell*hydrocarbon;
146 if (hydrocarbonPV > 0.) {
147 auto& attr = attributes_hpv[reg];
148 attr.pv += hydrocarbonPV;
150 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * hydrocarbonPV;
153 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * hydrocarbonPV;
158 auto& attr = attributes_pv[reg];
161 attr.pressure += fs.pressure(FluidSystem::oilPhaseIdx).value() * pv_cell;
163 attr.pressure += fs.pressure(FluidSystem::gasPhaseIdx).value() * pv_cell;
166 attr.pressure += fs.pressure(FluidSystem::waterPhaseIdx).value() * pv_cell;
170 OPM_END_PARALLEL_TRY_CATCH(
"AverageRegionalPressure::defineState(): ", simulator.vanguard().grid().comm());
172 for (
int reg = 1; reg <= numRegions ; ++ reg) {
173 auto& ra = attr_.attributes(reg);
174 const double hpv_sum = comm.sum(attributes_hpv[reg].pv);
177 const auto& attri_hpv = attributes_hpv[reg];
178 const double p_hpv_sum = comm.sum(attri_hpv.pressure);
179 ra.pressure = p_hpv_sum / hpv_sum;
182 const auto& attri_pv = attributes_pv[reg];
183 const double pv_sum = comm.sum(attri_pv.pv);
186 const double p_pv_sum = comm.sum(attri_pv.pressure);
187 ra.pressure = p_pv_sum / pv_sum;