110 GetPropType<TypeTag, Properties::EquilGrid>,
111 GetPropType<TypeTag, Properties::GridView>,
112 GetPropType<TypeTag, Properties::ElementMapper>,
113 GetPropType<TypeTag, Properties::Scalar>>
123 using Element =
typename GridView::template Codim<0>::Entity;
125 using ElementIterator =
typename GridView::template Codim<0>::Iterator;
128 typedef Dune::MultipleCodimMultipleGeomTypeMapper< GridView > VertexMapper;
137 static void registerParameters()
139 OutputModule::registerParameters();
141 Parameters::Register<Parameters::EnableAsyncEclOutput>
142 (
"Write the ECL-formated results in a non-blocking way "
143 "(i.e., using a separate thread).");
144 Parameters::Register<Parameters::EnableEsmry>
145 (
"Write ESMRY file for fast loading of summary data.");
152 :
BaseType(simulator.vanguard().schedule(),
153 simulator.vanguard().eclState(),
154 simulator.vanguard().summaryConfig(),
155 simulator.vanguard().grid(),
156 ((simulator.vanguard().grid().comm().rank() == 0)
157 ? &simulator.vanguard().equilGrid()
159 simulator.vanguard().gridView(),
160 simulator.vanguard().cartesianIndexMapper(),
161 ((simulator.vanguard().grid().comm().rank() == 0)
162 ? &simulator.vanguard().equilCartesianIndexMapper()
164 Parameters::Get<Parameters::EnableAsyncEclOutput>(),
165 Parameters::Get<Parameters::EnableEsmry>())
166 , simulator_(simulator)
169 if (this->simulator_.vanguard().grid().comm().size() > 1) {
170 auto smryCfg = (this->simulator_.vanguard().grid().comm().rank() == 0)
171 ? this->eclIO_->finalSummaryConfig()
174 eclBroadcast(this->simulator_.vanguard().grid().comm(),
smryCfg);
176 this->outputModule_ = std::make_unique<OutputModule>
177 (simulator,
smryCfg, this->collectOnIORank_);
182 this->outputModule_ = std::make_unique<OutputModule>
183 (simulator, this->eclIO_->finalSummaryConfig(),
this->collectOnIORank_);
186 this->rank_ = this->simulator_.vanguard().grid().comm().rank();
188 this->simulator_.vanguard().eclState().computeFipRegionStatistics();
194 const EquilGrid& globalGrid()
const
196 return simulator_.vanguard().equilGrid();
205 const int reportStepNum = simulator_.episodeIndex() + 1;
225 if (reportStepNum == 0)
228 const Scalar
curTime = simulator_.time() + simulator_.timeStepSize();
230 simulator_.executionTimer().realTimeElapsed() +
231 simulator_.setupTimer().realTimeElapsed() +
232 simulator_.vanguard().setupTime();
234 const auto localWellData = simulator_.problem().wellModel().wellData();
235 const auto localWBP = simulator_.problem().wellModel().wellBlockAveragePressures();
237 .groupAndNetworkData(reportStepNum);
239 const auto localAquiferData = simulator_.problem().aquiferModel().aquiferData();
241 this->prepareLocalCellData(
isSubStep, reportStepNum);
243 if (this->outputModule_->needInterfaceFluxes(
isSubStep)) {
244 this->captureLocalFluxData();
247 if (this->collectOnIORank_.isParallel()) {
248 OPM_BEGIN_PARALLEL_TRY_CATCH()
250 std::map<std::pair<std::string,int>,
double>
dummy;
251 this->collectOnIORank_.collect({},
252 outputModule_->getBlockData(),
259 this->outputModule_->getInterRegFlows(),
263 if (this->collectOnIORank_.isIORank()) {
264 auto&
iregFlows = this->collectOnIORank_.globalInterRegFlows();
267 throw std::runtime_error {
268 "Inconsistent inter-region flow "
269 "region set names in parallel"
276 OPM_END_PARALLEL_TRY_CATCH(
"Collect to I/O rank: ",
277 this->simulator_.vanguard().grid().comm());
282 std::map<std::string, std::vector<double>>
regionData;
290 if (this->collectOnIORank_.isIORank()){
299 if (this->sub_step_report_.total_newton_iterations != 0) {
300 miscSummaryData[
"NEWTON"] = this->sub_step_report_.total_newton_iterations;
302 if (this->sub_step_report_.total_linear_iterations != 0) {
303 miscSummaryData[
"MLINEARS"] = this->sub_step_report_.total_linear_iterations;
305 if (this->sub_step_report_.total_newton_iterations != 0) {
306 miscSummaryData[
"NLINEARS"] =
static_cast<float>(this->sub_step_report_.total_linear_iterations) / this->sub_step_report_.total_newton_iterations;
308 if (this->sub_step_report_.min_linear_iterations != std::numeric_limits<unsigned int>::max()) {
309 miscSummaryData[
"NLINSMIN"] = this->sub_step_report_.min_linear_iterations;
311 if (this->sub_step_report_.max_linear_iterations != 0) {
312 miscSummaryData[
"NLINSMAX"] = this->sub_step_report_.max_linear_iterations;
314 if (this->simulation_report_.success.total_linear_iterations != 0) {
315 miscSummaryData[
"MSUMLINS"] = this->simulation_report_.success.total_linear_iterations;
317 if (this->simulation_report_.success.total_newton_iterations != 0) {
318 miscSummaryData[
"MSUMNEWT"] = this->simulation_report_.success.total_newton_iterations;
324 const auto&
blockData = this->collectOnIORank_.isParallel()
325 ? this->collectOnIORank_.globalBlockData()
326 : this->outputModule_->getBlockData();
328 const auto&
interRegFlows = this->collectOnIORank_.isParallel()
329 ? this->collectOnIORank_.globalInterRegFlows()
330 : this->outputModule_->getInterRegFlows();
332 this->evalSummary(reportStepNum,
342 this->outputModule_->initialInplace(),
344 this->summaryState(),
352 const auto& gridView = simulator_.vanguard().gridView();
354 countLocalInteriorCellsGridView(gridView);
356 this->outputModule_->
360#pragma omp parallel for
363 const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, 0);
364 const auto totVolume = simulator_.model().dofTotalVolume(dofIdx);
366 this->outputModule_->updateFluidInPlace(dofIdx, intQuants,
totVolume);
371 outputModule_->calc_initial_inplace(simulator_.gridView().comm());
374 const auto& fip = simulator_.vanguard().eclState().getEclipseConfig().fip();
375 if (fip.output(FIPConfig::OutputField::FIELD) ||
376 fip.output(FIPConfig::OutputField::RESV))
380 boost::posix_time::from_time_t(simulator_.vanguard().schedule().getStartTime());
382 if (this->collectOnIORank_.isIORank()) {
383 inplace_ = outputModule_->initialInplace();
385 outputModule_->outputFipAndResvLog(inplace_, 0, 0.0,
start_time,
386 false, simulator_.gridView().comm());
395 if ((
rstep > 0) && (this->collectOnIORank_.isIORank())) {
396 const auto&
rpt = this->schedule_[
rstep-1].rpt_config.get();
397 if (
rpt.contains(
"WELLS") &&
rpt.at(
"WELLS") > 0) {
398 outputModule_->outputTimeStamp(
"WELLS",
402 outputModule_->outputProdLog(
rstep - 1,
rpt.at(
"WELLS") > 1);
403 outputModule_->outputInjLog(
rstep - 1,
rpt.at(
"WELLS") > 1);
404 outputModule_->outputCumLog(
rstep - 1,
rpt.at(
"WELLS") > 1);
405 outputModule_->outputMSWLog(
rstep - 1);
408 outputModule_->outputFipAndResvLog(inplace_,
413 simulator_.gridView().comm());
424 const int reportStepNum = simulator_.episodeIndex() + 1;
425 this->prepareLocalCellData(
isSubStep, reportStepNum);
426 this->outputModule_->outputErrorLog(simulator_.gridView().comm());
429 auto localWellData = simulator_.problem().wellModel().wellData();
431 .groupAndNetworkData(reportStepNum);
436 const bool isFlowsn = this->outputModule_->getFlows().hasFlowsn();
437 auto flowsn = this->outputModule_->getFlows().getFlowsn();
439 const bool isFloresn = this->outputModule_->getFlows().hasFloresn();
440 auto floresn = this->outputModule_->getFlows().getFloresn();
442 if (!
isSubStep || Parameters::Get<Parameters::EnableWriteAllSolutions>()) {
451 simulator_.gridView().comm());
454 if (this->collectOnIORank_.isParallel() ||
455 this->collectOnIORank_.doesNeedReordering())
463 this->outputModule_->getBlockData(),
464 this->outputModule_->getExtraBlockData(),
473 if (this->collectOnIORank_.isIORank()) {
474 this->outputModule_->assignGlobalFieldsToSolution(this->collectOnIORank_.globalCellData());
477 this->outputModule_->assignGlobalFieldsToSolution(
localCellData);
480 if (this->collectOnIORank_.isIORank()) {
481 const Scalar
curTime = simulator_.time() + simulator_.timeStepSize();
482 const Scalar
nextStepSize = simulator_.problem().nextTimeStepSize();
484 if (Parameters::Get<Parameters::EnableWriteAllSolutions>()) {
495 this->summaryState(),
496 this->simulator_.problem().thresholdPressure().getRestartVector(),
498 Parameters::Get<Parameters::EclOutputDoublePrecision>(),
506 const auto enablePCHysteresis = simulator_.problem().materialLawManager()->enablePCHysteresis();
509 const auto oilActive = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
510 const auto gasActive = FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
511 const auto waterActive = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
512 const auto enableSwatinit = simulator_.vanguard().eclState().fieldProps().has_double(
"SWATINIT");
515 {
"PRESSURE", UnitSystem::measure::pressure},
516 {
"SWAT", UnitSystem::measure::identity, waterActive},
517 {
"SGAS", UnitSystem::measure::identity, gasActive},
518 {
"TEMP", UnitSystem::measure::temperature, enableEnergy},
519 {
"SSOLVENT", UnitSystem::measure::identity, enableSolvent},
521 {
"RS", UnitSystem::measure::gas_oil_ratio, FluidSystem::enableDissolvedGas()},
522 {
"RV", UnitSystem::measure::oil_gas_ratio, FluidSystem::enableVaporizedOil()},
523 {
"RVW", UnitSystem::measure::oil_gas_ratio, FluidSystem::enableVaporizedWater()},
524 {
"RSW", UnitSystem::measure::gas_oil_ratio, FluidSystem::enableDissolvedGasInWater()},
529 {
"SOMAX", UnitSystem::measure::identity,
531 || simulator_.problem().vapparsActive(simulator_.episodeIndex())},
533 {
"SOMIN", UnitSystem::measure::identity,
enablePCHysteresis && oilActive && gasActive},
534 {
"SWHY1", UnitSystem::measure::identity,
enablePCHysteresis && oilActive && waterActive},
541 const auto&
tracers = simulator_.vanguard().eclState().tracer();
545 ((
tracer.phase == Phase::GAS) && FluidSystem::enableDissolvedGas()) ||
546 ((
tracer.phase == Phase::OIL) && FluidSystem::enableVaporizedOil());
553 const auto&
inputThpres = eclState().getSimulationConfig().getThresholdPressure();
554 const std::vector<RestartKey>
extraKeys {
555 {
"OPMEXTRA", UnitSystem::measure::identity,
false},
556 {
"THRESHPR", UnitSystem::measure::pressure,
inputThpres.active()},
559 const auto& gridView = this->simulator_.vanguard().gridView();
571 loadParallelRestartSolution(this->eclIO_.get(),
576 const auto globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
580 this->simulator_.problem().readSolutionFromOutputModule(0,
true);
581 ElementContext elemCtx(this->simulator_);
583 elemCtx.updatePrimaryStencil(
elem);
584 elemCtx.updatePrimaryIntensiveQuantities(0);
586 this->outputModule_->updateFluidInPlace(elemCtx);
589 this->outputModule_->calc_initial_inplace(this->simulator_.gridView().comm());
598 .eclState().getInitConfig().getRestartStep();
609 loadParallelRestart(this->eclIO_.get(),
611 this->summaryState(),
615 const auto globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
616 this->outputModule_->setRestart(
restartValues.solution, elemIdx, globalIdx);
619 auto&
tracer_model = simulator_.problem().tracerModel();
628 const auto globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
645 const auto globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
660 const_cast<Simulator&
>(this->simulator_)
661 .problem().thresholdPressure()
665 restartTimeStepSize_ =
restartValues.getExtra(
"OPMEXTRA")[0];
666 if (restartTimeStepSize_ <= 0) {
667 restartTimeStepSize_ = std::numeric_limits<double>::max();
671 this->simulator_.problem().wellModel()
675 this->simulator_.problem().mutableAquiferModel()
686 this->outputModule_->calc_initial_inplace(this->simulator_.gridView().comm());
688 if (this->collectOnIORank_.isIORank()) {
689 this->inplace_ = this->outputModule_->initialInplace();
694 {
return *outputModule_; }
697 {
return *outputModule_; }
699 Scalar restartTimeStepSize()
const
700 {
return restartTimeStepSize_; }
702 template <
class Serializer>
709 static bool enableEclOutput_()
711 static bool enable = Parameters::Get<Parameters::EnableEclOutput>();
715 const EclipseState& eclState()
const
716 {
return simulator_.vanguard().eclState(); }
719 {
return simulator_.vanguard().summaryState(); }
721 Action::State& actionState()
722 {
return simulator_.vanguard().actionState(); }
725 {
return simulator_.vanguard().udqState(); }
728 {
return simulator_.vanguard().schedule(); }
730 void prepareLocalCellData(
const bool isSubStep,
731 const int reportStepNum)
735 if (this->outputModule_->localDataValid()) {
739 const auto& gridView = simulator_.vanguard().gridView();
740 const bool log = this->collectOnIORank_.isIORank();
743 countLocalInteriorCellsGridView(gridView);
744 this->outputModule_->
746 isSubStep && !Parameters::Get<Parameters::EnableWriteAllSolutions>(),
749 ElementContext elemCtx(simulator_);
751 OPM_BEGIN_PARALLEL_TRY_CATCH();
756 this->outputModule_->prepareDensityAccumulation();
757 this->outputModule_->setupExtractors(
isSubStep, reportStepNum);
759 elemCtx.updatePrimaryStencil(
elem);
760 elemCtx.updatePrimaryIntensiveQuantities(0);
762 this->outputModule_->processElement(elemCtx);
763 this->outputModule_->processElementBlockData(elemCtx);
765 this->outputModule_->clearExtractors();
767 this->outputModule_->accumulateDensityParallel();
774#pragma omp parallel for
777 const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, 0);
778 const auto totVolume = simulator_.model().dofTotalVolume(dofIdx);
780 this->outputModule_->updateFluidInPlace(dofIdx, intQuants,
totVolume);
784 this->outputModule_->validateLocalData();
786 OPM_END_PARALLEL_TRY_CATCH(
"EclWriter::prepareLocalCellData() failed: ",
787 this->simulator_.vanguard().grid().comm());
790 void captureLocalFluxData()
794 const auto& gridView = this->simulator_.vanguard().gridView();
797 auto elemCtx = ElementContext { this->simulator_ };
799 const auto elemMapper = ElementMapper { gridView, Dune::mcmgElementLayout() };
800 const auto activeIndex = [&
elemMapper](
const Element&
e)
805 const auto cartesianIndex = [
this](
const int elemIndex)
807 return this->cartMapper_.cartesianIndex(
elemIndex);
810 this->outputModule_->initializeFluxData();
812 OPM_BEGIN_PARALLEL_TRY_CATCH();
815 elemCtx.updateStencil(
elem);
816 elemCtx.updateIntensiveQuantities(
timeIdx);
817 elemCtx.updateExtensiveQuantities(
timeIdx);
819 this->outputModule_->processFluxes(elemCtx, activeIndex, cartesianIndex);
822 OPM_END_PARALLEL_TRY_CATCH(
"EclWriter::captureLocalFluxData() failed: ",
823 this->simulator_.vanguard().grid().comm())
825 this->outputModule_->finalizeFluxData();
828 Simulator& simulator_;
830 Scalar restartTimeStepSize_;