27#ifndef OPM_OUTPUT_COMPOSITIONAL_MODULE_HPP
28#define OPM_OUTPUT_COMPOSITIONAL_MODULE_HPP
30#include <dune/grid/common/gridenums.hh>
32#include <opm/simulators/utils/moduleVersion.hpp>
34#include <opm/common/Exceptions.hpp>
35#include <opm/common/ErrorMacros.hpp>
36#include <opm/common/TimingMacros.hpp>
37#include <opm/common/OpmLog/OpmLog.hpp>
39#include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
41#include <opm/material/common/Valgrind.hpp>
65template <
class TypeTag>
74template <
class TypeTag>
75class OutputCompositionalModule :
public GenericOutputBlackoilModule<GetPropType<TypeTag, Properties::FluidSystem>>
83 using BaseType = GenericOutputBlackoilModule<FluidSystem>;
86 enum { numPhases = FluidSystem::numPhases };
87 enum { numComponents = FluidSystem::numComponents };
88 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
89 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
90 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
93 template <
class CollectDataToIORankType>
94 OutputCompositionalModule(
const Simulator& simulator,
95 const SummaryConfig& smryCfg,
96 const CollectDataToIORankType& collectToIORank)
97 : BaseType(simulator.vanguard().eclState(),
98 simulator.vanguard().schedule(),
100 simulator.vanguard().summaryState(),
102 [
this](
const int idx)
103 {
return simulator_.problem().eclWriter().collectOnIORank().localIdxToGlobalIdx(idx); },
104 simulator.vanguard().grid().comm(),
115 , simulator_(simulator)
117 for (
auto& region_pair : this->regions_) {
118 this->createLocalRegion_(region_pair.second);
121 auto isCartIdxOnThisRank = [&collectToIORank](
const int idx) {
122 return collectToIORank.isCartIdxOnThisRank(idx);
125 this->setupBlockData(isCartIdxOnThisRank);
128 const std::string msg =
"The output code does not support --owner-cells-first=false.";
129 if (collectToIORank.isIORank()) {
132 OPM_THROW_NOLOG(std::runtime_error, msg);
135 if (smryCfg.match(
"[FB]PP[OGW]") || smryCfg.match(
"RPP[OGW]*")) {
136 auto rset = this->eclState_.fieldProps().fip_regions();
137 rset.push_back(
"PVTNUM");
142 this->regionAvgDensity_
143 .emplace(this->simulator_.gridView().comm(),
144 FluidSystem::numPhases, rset,
145 [fp = std::cref(this->eclState_.fieldProps())]
146 (
const std::string& rsetName) ->
decltype(
auto)
147 { return fp.get().get_int(rsetName); });
157 const unsigned reportStepNum,
160 const bool isRestart)
166 auto rstKeywords = this->schedule_.rst_keywords(reportStepNum);
167 this->compC_.allocate(bufferSize, rstKeywords);
169 this->doAllocBuffers(bufferSize, reportStepNum, substep, log, isRestart,
172 std::move(rstKeywords));
175 void assignToSolution(data::Solution& sol)
177 this->compC_.outputRestart(sol, this->saturation_[oilPhaseIdx]);
190 auto extractors = std::array{
191 Entry{PhaseEntry{&this->saturation_,
192 [](
const unsigned phase,
const ExtractContext& ectx)
193 {
return getValue(ectx.fs.saturation(phase)); }}
195 Entry{ScalarEntry{&this->fluidPressure_,
196 [](
const ExtractContext& ectx)
198 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
200 return getValue(ectx.fs.pressure(oilPhaseIdx));
202 else if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
204 return getValue(ectx.fs.pressure(gasPhaseIdx));
208 return getValue(ectx.fs.pressure(waterPhaseIdx));
212 Entry{ScalarEntry{&this->temperature_,
213 [](
const ExtractContext& ectx)
214 {
return getValue(ectx.fs.temperature(oilPhaseIdx)); }}
216 Entry{[&compC = this->compC_](
const ExtractContext& ectx)
218 compC.assignMoleFractions(ectx.globalDofIdx,
219 [&fs = ectx.fs](
const unsigned compIdx)
220 { return getValue(fs.moleFraction(compIdx)); });
222 if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
223 compC.assignGasFractions(ectx.globalDofIdx,
224 [&fs = ectx.fs](
const unsigned compIdx)
225 { return getValue(fs.moleFraction(gasPhaseIdx, compIdx)); });
228 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
229 compC.assignOilFractions(ectx.globalDofIdx,
230 [&fs = ectx.fs](
const unsigned compIdx)
231 { return getValue(fs.moleFraction(oilPhaseIdx, compIdx)); });
233 }, this->compC_.allocated()
242 { this->extractors_.clear(); }
256 for (
unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(0); ++dofIdx) {
257 const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, 0);
258 const auto& fs = intQuants.fluidState();
261 elemCtx.globalSpaceIndex(dofIdx, 0),
263 elemCtx.simulator().episodeIndex(),
273 void processElementFlows(
const ElementContext& )
275 OPM_TIMEBLOCK_LOCAL(processElementBlockData, Subsystem::Output);
280 void processElementBlockData(
const ElementContext& )
282 OPM_TIMEBLOCK_LOCAL(processElementBlockData, Subsystem::Output);
283 if (!std::is_same<Discretization, EcfvDiscretization<TypeTag>>::value)
315 template <
class ActiveIndex,
class CartesianIndex>
330 this->interRegionFlows_.clear();
338 this->interRegionFlows_.compress();
346 return this->interRegionFlows_;
349 void updateFluidInPlace(
const unsigned ,
350 const IntensiveQuantities& ,
357 bool isDefunctParallelWell(
const std::string& wname)
const override
359 if (simulator_.gridView().comm().size() == 1)
361 const auto& parallelWells = simulator_.vanguard().parallelWells();
362 std::pair<std::string, bool> value {wname,
true};
363 auto candidate = std::lower_bound(parallelWells.begin(), parallelWells.end(), value);
364 return candidate == parallelWells.end() || *candidate != value;
367 bool isOwnedByCurrentRank(
const std::string& wname)
const override
372 return ! this->isDefunctParallelWell(wname);
375 bool isOnCurrentRank(
const std::string& wname)
const override
380 return ! this->isDefunctParallelWell(wname);
383 void createLocalRegion_(std::vector<int>& region)
385 std::size_t elemIdx = 0;
386 for (
const auto& elem : elements(simulator_.gridView())) {
387 if (elem.partitionType() != Dune::InteriorEntity) {
395 const Simulator& simulator_;
396 CompositionalContainer<FluidSystem> compC_;
397 std::vector<typename Extractor::Entry> extractors_;
Output module for the results black oil model writing in ECL binary format.
Helper class for grid instantiation of ECL file-format using problems.
Output module for the results black oil model writing in ECL binary format.
Declares the properties required by the black oil model.
The base class for the element-centered finite-volume discretization scheme.
Definition ecfvdiscretization.hh:160
void assignToSolution(data::Solution &sol)
Move all buffers to data::Solution.
Definition GenericOutputBlackoilModule.cpp:310
Inter-region flow accumulation maps for all region definition arrays.
Definition InterRegFlows.hpp:179
void clearExtractors()
Clear list of active element-level data extractors.
Definition OutputCompositionalModule.hpp:241
void initializeFluxData()
Prepare for capturing connection fluxes, particularly to account for inter-region flows.
Definition OutputCompositionalModule.hpp:326
void setupExtractors(const bool, const std::size_t)
Setup list of active element-level data extractors.
Definition OutputCompositionalModule.hpp:182
void finalizeFluxData()
Finalize capturing connection fluxes.
Definition OutputCompositionalModule.hpp:336
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quanties relevant for an element.
Definition OutputCompositionalModule.hpp:248
void allocBuffers(const unsigned bufferSize, const unsigned reportStepNum, const bool substep, const bool log, const bool isRestart)
Allocate memory for the scalar fields we would like to write to ECL output files.
Definition OutputCompositionalModule.hpp:156
void processFluxes(const ElementContext &, ActiveIndex &&, CartesianIndex &&)
Capture connection fluxes, particularly to account for inter-region flows.
Definition OutputCompositionalModule.hpp:316
const InterRegFlowMap & getInterRegFlows() const
Get read-only access to collection of inter-region flows.
Definition OutputCompositionalModule.hpp:344
Defines the common properties required by the porous medium multi-phase models.
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
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
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016....
Definition moduleVersion.cpp:34
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
This file provides the infrastructure to retrieve run-time parameters.
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:187
The Opm property system, traits with inheritance.