76class OutputCompositionalModule :
public GenericOutputBlackoilModule<GetPropType<TypeTag, Properties::FluidSystem>>
84 using BaseType = GenericOutputBlackoilModule<FluidSystem>;
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>
95 OutputCompositionalModule(
const Simulator& simulator,
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(),
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);
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),
267 elemCtx.simulator().episodeIndex(),
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();
342 this->interRegionFlows_.compress();
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_;
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
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