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> 58 #include <type_traits> 66 template <
class TypeTag>
67 class EcfvDiscretization;
75 template <
class TypeTag>
87 enum { numPhases = FluidSystem::numPhases };
88 enum { numComponents = FluidSystem::numComponents };
89 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
90 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
91 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
94 template <
class CollectDataToIORankType>
96 const SummaryConfig& smryCfg,
97 const CollectDataToIORankType& collectToIORank)
98 :
BaseType(simulator.vanguard().eclState(),
99 simulator.vanguard().schedule(),
101 simulator.vanguard().summaryState(),
103 [
this](
const int idx)
104 {
return simulator_.problem().eclWriter().collectOnIORank().localIdxToGlobalIdx(idx); },
105 [&collectToIORank](
const int idx)
106 {
return collectToIORank.isCartIdxOnThisRank(idx); },
107 simulator.vanguard().grid().comm(),
108 getPropValue<TypeTag, Properties::EnergyModuleType>() == EnergyModules::FullyImplicitThermal,
109 getPropValue<TypeTag, Properties::EnergyModuleType>() == EnergyModules::ConstantTemperature,
110 getPropValue<TypeTag, Properties::EnableMech>(),
111 getPropValue<TypeTag, Properties::EnableSolvent>(),
112 getPropValue<TypeTag, Properties::EnablePolymer>(),
113 getPropValue<TypeTag, Properties::EnableFoam>(),
114 getPropValue<TypeTag, Properties::EnableBrine>(),
115 getPropValue<TypeTag, Properties::EnableSaltPrecipitation>(),
116 getPropValue<TypeTag, Properties::EnableExtbo>(),
117 getPropValue<TypeTag, Properties::EnableBioeffects>(),
118 getPropValue<TypeTag, Properties::EnableGeochemistry>())
119 , simulator_(simulator)
121 for (
auto& region_pair : this->regions_) {
122 this->createLocalRegion_(region_pair.second);
125 auto isCartIdxOnThisRank = [&collectToIORank](
const int idx) {
126 return collectToIORank.isCartIdxOnThisRank(idx);
129 this->setupBlockData(isCartIdxOnThisRank);
131 if (! Parameters::Get<Parameters::OwnerCellsFirst>()) {
132 const std::string msg =
"The output code does not support --owner-cells-first=false.";
133 if (collectToIORank.isIORank()) {
136 OPM_THROW_NOLOG(std::runtime_error, msg);
139 if (smryCfg.match(
"[FB]PP[OGW]") || smryCfg.match(
"RPP[OGW]*")) {
140 auto rset = this->eclState_.fieldProps().fip_regions();
141 rset.push_back(
"PVTNUM");
146 this->regionAvgDensity_
147 .emplace(this->simulator_.gridView().comm(),
148 FluidSystem::numPhases, rset,
149 [fp = std::cref(this->eclState_.fieldProps())]
150 (
const std::string& rsetName) -> decltype(
auto)
151 {
return fp.get().get_int(rsetName); });
161 const unsigned reportStepNum,
164 const bool isRestart)
170 auto rstKeywords = this->schedule_.rst_keywords(reportStepNum);
171 this->compC_.allocate(bufferSize, rstKeywords);
173 this->doAllocBuffers(bufferSize, reportStepNum, substep, log, isRestart,
176 std::move(rstKeywords));
179 void assignToSolution(data::Solution& sol)
181 this->compC_.outputRestart(sol, this->saturation_[oilPhaseIdx]);
194 auto extractors = std::array{
195 Entry{PhaseEntry{&this->saturation_,
196 [](
const unsigned phase,
const ExtractContext& ectx)
197 {
return getValue(ectx.fs.saturation(phase)); }}
199 Entry{ScalarEntry{&this->fluidPressure_,
200 [](
const ExtractContext& ectx)
202 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
204 return getValue(ectx.fs.pressure(oilPhaseIdx));
206 else if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
208 return getValue(ectx.fs.pressure(gasPhaseIdx));
212 return getValue(ectx.fs.pressure(waterPhaseIdx));
216 Entry{ScalarEntry{&this->temperature_,
217 [](
const ExtractContext& ectx)
218 {
return getValue(ectx.fs.temperature(oilPhaseIdx)); }}
220 Entry{[&compC = this->compC_](
const ExtractContext& ectx)
222 compC.assignMoleFractions(ectx.globalDofIdx,
223 [&fs = ectx.fs](
const unsigned compIdx)
224 { return getValue(fs.moleFraction(compIdx)); });
226 if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
227 compC.assignGasFractions(ectx.globalDofIdx,
228 [&fs = ectx.fs](
const unsigned compIdx)
229 { return getValue(fs.moleFraction(gasPhaseIdx, compIdx)); });
232 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
233 compC.assignOilFractions(ectx.globalDofIdx,
234 [&fs = ectx.fs](
const unsigned compIdx)
235 { return getValue(fs.moleFraction(oilPhaseIdx, compIdx)); });
237 }, this->compC_.allocated()
246 { this->extractors_.clear(); }
260 for (
unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(0); ++dofIdx) {
261 const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, 0);
262 const auto& fs = intQuants.fluidState();
265 elemCtx.globalSpaceIndex(dofIdx, 0),
277 void processElementFlows(
const ElementContext& )
279 OPM_TIMEBLOCK_LOCAL(processElementBlockData, Subsystem::Output);
284 void processElementBlockData(
const ElementContext& )
286 OPM_TIMEBLOCK_LOCAL(processElementBlockData, Subsystem::Output);
287 if (!std::is_same<Discretization, EcfvDiscretization<TypeTag>>::value)
319 template <
class ActiveIndex,
class CartesianIndex>
334 this->interRegionFlows_.
clear();
350 return this->interRegionFlows_;
353 void updateFluidInPlace(
const unsigned ,
354 const IntensiveQuantities& ,
361 bool isDefunctParallelWell(
const std::string& wname)
const override 363 if (simulator_.gridView().comm().size() == 1)
365 const auto& parallelWells = simulator_.vanguard().parallelWells();
366 std::pair<std::string, bool> value {wname,
true};
367 auto candidate = std::lower_bound(parallelWells.begin(), parallelWells.end(), value);
368 return candidate == parallelWells.end() || *candidate != value;
371 bool isOwnedByCurrentRank(
const std::string& wname)
const override 376 return ! this->isDefunctParallelWell(wname);
379 bool isOnCurrentRank(
const std::string& wname)
const override 384 return ! this->isDefunctParallelWell(wname);
387 void createLocalRegion_(std::vector<int>& region)
389 std::size_t elemIdx = 0;
390 for (
const auto& elem : elements(simulator_.gridView())) {
391 if (elem.partitionType() != Dune::InteriorEntity) {
399 const Simulator& simulator_;
400 CompositionalContainer<FluidSystem> compC_;
401 std::vector<typename Extractor::Entry> extractors_;
406 #endif // OPM_OUTPUT_COMPOSITIONAL_MODULE_HPP Output module for the results black oil model writing in ECL binary format.
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
void finalizeFluxData()
Finalize capturing connection fluxes.
Definition: OutputCompositionalModule.hpp:340
The base class for the element-centered finite-volume discretization scheme.
Definition: fvbasegradientcalculator.hh:42
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016...
Definition: moduleVersion.cpp:34
Helper class for grid instantiation of ECL file-format using problems.
This file provides the infrastructure to retrieve run-time parameters.
Output module for the results black oil model writing in ECL binary format.
const InterRegFlowMap & getInterRegFlows() const
Get read-only access to collection of inter-region flows.
Definition: OutputCompositionalModule.hpp:348
Defines the common properties required by the porous medium multi-phase models.
void clearExtractors()
Clear list of active element-level data extractors.
Definition: OutputCompositionalModule.hpp:245
void compress()
Form CSR adjacency matrix representation of input graph from connections established in previous call...
Definition: InterRegFlows.cpp:164
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Declares the properties required by the black oil model.
Definition: GenericOutputBlackoilModule.hpp:78
Inter-region flow accumulation maps for all region definition arrays.
Definition: InterRegFlows.hpp:178
void setupExtractors(const bool, const std::size_t)
Setup list of active element-level data extractors.
Definition: OutputCompositionalModule.hpp:186
void clear()
Clear all internal buffers, but preserve allocated capacity.
Definition: InterRegFlows.cpp:171
void initializeFluxData()
Prepare for capturing connection fluxes, particularly to account for inter-region flows...
Definition: OutputCompositionalModule.hpp:330
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quanties relevant for an element.
Definition: OutputCompositionalModule.hpp:252
Output module for the results black oil model writing in ECL binary format.
Definition: OutputCompositionalModule.hpp:76
The Opm property system, traits with inheritance.
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:160
void processFluxes(const ElementContext &, ActiveIndex &&, CartesianIndex &&)
Capture connection fluxes, particularly to account for inter-region flows.
Definition: OutputCompositionalModule.hpp:320
void assignToSolution(data::Solution &sol)
Move all buffers to data::Solution.
Definition: GenericOutputBlackoilModule.cpp:316
Contains the classes required to extend the black-oil model by energy.