From db35b75975d5675699fc6e8aae8e9b2aabee8c7a Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 31 Mar 2015 12:11:57 +0200 Subject: [PATCH 1/2] summary output: use the EclipseState to determine the deck unit system seems like the guy who added EclipseState::getDeckUnitSystem() suffers from dementia... --- opm/core/io/eclipse/EclipseWriter.cpp | 45 ++++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 86593e12..9ec7b285 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -734,7 +734,7 @@ public: PhaseUsage uses, BlackoilPhases::PhaseIndex phase, WellType type, - bool useFieldUnits) + UnitSystem::UnitType unitType) : WellReport(summary, eclipseState, well, @@ -742,7 +742,7 @@ public: phase, type, 'R', - handleUnit_(phase, useFieldUnits)) + handleUnit_(phase, unitType)) { } @@ -770,27 +770,31 @@ public: } private: - const std::string handleUnit_(BlackoilPhases::PhaseIndex phase, bool useField) { + const std::string handleUnit_(BlackoilPhases::PhaseIndex phase, UnitSystem::UnitType unitType) { using namespace Opm::unit; if (phase == BlackoilPhases::Liquid || phase == BlackoilPhases::Aqua) { - if (useField) { + if (unitType == UnitSystem::UNIT_TYPE_METRIC) { unitName_ = "STB/DAY"; targetRateToSiConversionFactor_ = stb/day; // m^3/s -> STB/day } - else { + else if (unitType == UnitSystem::UNIT_TYPE_FIELD) { unitName_ = "SM3/DAY"; targetRateToSiConversionFactor_ = cubic(meter)/day; // m^3/s -> m^3/day } + else + OPM_THROW(std::logic_error, "Deck uses unexpected unit system"); } else if (phase == BlackoilPhases::Vapour) { - if (useField) { + if (unitType == UnitSystem::UNIT_TYPE_METRIC) { unitName_ = "MSCF/DAY"; targetRateToSiConversionFactor_ = 1000*cubic(feet)/day; // m^3/s -> MSCF^3/day } - else { + else if (unitType == UnitSystem::UNIT_TYPE_FIELD) { unitName_ = "SM3/DAY"; targetRateToSiConversionFactor_ = cubic(meter)/day; // m^3/s -> m^3/day } + else + OPM_THROW(std::logic_error, "Deck uses unexpected unit system"); } else OPM_THROW(std::logic_error, @@ -812,7 +816,7 @@ public: PhaseUsage uses, BlackoilPhases::PhaseIndex phase, WellType type, - bool useFieldUnits) + UnitSystem::UnitType unitType) : WellReport(summary, eclipseState, well, @@ -820,7 +824,7 @@ public: phase, type, 'T', - handleUnit_(phase, useFieldUnits)) + handleUnit_(phase, unitType)) // nothing produced when the reporting starts , total_(0.) { } @@ -860,27 +864,31 @@ public: } private: - const std::string handleUnit_(BlackoilPhases::PhaseIndex phase, bool useField) { + const std::string handleUnit_(BlackoilPhases::PhaseIndex phase, UnitSystem::UnitType unitType) { using namespace Opm::unit; if (phase == BlackoilPhases::Liquid || phase == BlackoilPhases::Aqua) { - if (useField) { + if (unitType == UnitSystem::UNIT_TYPE_METRIC) { unitName_ = "STB/DAY"; targetRateToSiConversionFactor_ = stb/day; // m^3/s -> STB/day } - else { + else if (unitType == UnitSystem::UNIT_TYPE_FIELD) { unitName_ = "SM3/DAY"; targetRateToSiConversionFactor_ = cubic(meter)/day; // m^3/s -> m^3/day } + else + OPM_THROW(std::logic_error, "Deck uses unexpected unit system"); } else if (phase == BlackoilPhases::Vapour) { - if (useField) { + if (unitType == UnitSystem::UNIT_TYPE_METRIC) { unitName_ = "MSCF/DAY"; targetRateToSiConversionFactor_ = 1000*cubic(feet)/day; // m^3/s -> MSCF^3/day } - else { + else if (unitType == UnitSystem::UNIT_TYPE_FIELD) { unitName_ = "SM3/DAY"; targetRateToSiConversionFactor_ = cubic(meter)/day; // m^3/s -> m^3/day } + else + OPM_THROW(std::logic_error, "Deck uses unexpected unit system"); } else OPM_THROW(std::logic_error, @@ -991,7 +999,8 @@ void Summary::addAllWells(Opm::DeckConstPtr deck, const PhaseUsage& uses) { eclipseState_ = eclipseState; - bool useFieldUnits = !deck->hasKeyword("METRIC"); + std::shared_ptr unitsystem = eclipseState_->getDeckUnitSystem(); + auto deckUnitType = unitsystem->getType(); // TODO: Only create report variables that are requested with keywords // (e.g. "WOPR") in the input files, and only for those wells that are @@ -1018,7 +1027,7 @@ void Summary::addAllWells(Opm::DeckConstPtr deck, uses, ertPhaseIdx, wellType, - useFieldUnits))); + deckUnitType))); // W{O,G,W}{I,P}T addWell(std::unique_ptr ( new WellTotal(*this, @@ -1027,7 +1036,7 @@ void Summary::addAllWells(Opm::DeckConstPtr deck, uses, ertPhaseIdx, wellType, - useFieldUnits))); + deckUnitType))); } } } @@ -1050,7 +1059,7 @@ void Summary::addAllWells(Opm::DeckConstPtr deck, uses, ertPhaseIdx, WELL_TYPES[0], - useFieldUnits))); + deckUnitType))); } } } // end namespace EclipseWriterDetails From 28bde4290f482ad4879ddbc49ef09745661e1fde Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 31 Mar 2015 12:12:02 +0200 Subject: [PATCH 2/2] do not pass the deck to the output writers anymore I'd prefer to pass it for consistency reasons (because basically every other class which takes an EclipseState object also requires a deck object), but some people seem to have a very strong option about this... --- opm/core/io/OutputWriter.cpp | 6 +----- opm/core/io/OutputWriter.hpp | 2 -- opm/core/io/eclipse/EclipseWriter.cpp | 12 ++++-------- opm/core/io/eclipse/EclipseWriter.hpp | 2 -- opm/core/simulator/SimulatorOutput.cpp | 3 +-- opm/core/simulator/SimulatorOutput.hpp | 6 +----- tests/test_EclipseWriteRFTHandler.cpp | 1 - tests/test_EclipseWriter.cpp | 1 - tests/test_writenumwells.cpp | 1 - 9 files changed, 7 insertions(+), 27 deletions(-) diff --git a/opm/core/io/OutputWriter.cpp b/opm/core/io/OutputWriter.cpp index 11b574bc..1431ad46 100644 --- a/opm/core/io/OutputWriter.cpp +++ b/opm/core/io/OutputWriter.cpp @@ -47,12 +47,10 @@ private: /// Psuedo-constructor, can appear in template template unique_ptr create (const ParameterGroup& params, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid) { return unique_ptr (new Format (params, - deck, eclipseState, phaseUsage, grid->number_of_cells, @@ -67,7 +65,6 @@ create (const ParameterGroup& params, /// to the list below! typedef map (*)( const ParameterGroup&, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr )> map_t; @@ -79,7 +76,6 @@ map_t FORMATS = { unique_ptr OutputWriter::create (const ParameterGroup& params, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid) { @@ -97,7 +93,7 @@ OutputWriter::create (const ParameterGroup& params, // invoke the constructor for the type if we found the keyword // and put the pointer to this writer onto the list if (params.getDefault (name, false)) { - list->push_front (it->second (params, deck, eclipseState, phaseUsage, grid)); + list->push_front (it->second (params, eclipseState, phaseUsage, grid)); } } diff --git a/opm/core/io/OutputWriter.hpp b/opm/core/io/OutputWriter.hpp index ccfec23d..27f4dd3b 100644 --- a/opm/core/io/OutputWriter.hpp +++ b/opm/core/io/OutputWriter.hpp @@ -21,7 +21,6 @@ #define OPM_OUTPUT_WRITER_HPP #include // unique_ptr, shared_ptr -#include #include struct UnstructuredGrid; @@ -108,7 +107,6 @@ public: */ static std::unique_ptr create (const parameter::ParameterGroup& params, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid); diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 9ec7b285..e835a359 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -449,8 +449,7 @@ public: // on the classes defined in the following. // add rate variables for each of the well in the input file - void addAllWells(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, + void addAllWells(Opm::EclipseStateConstPtr eclipseState, const PhaseUsage& uses); void writeTimeStep(int writeStepIdx, const SimulatorTimerInterface& timer, @@ -994,8 +993,7 @@ void Summary::writeTimeStep(int writeStepIdx, ecl_sum_fwrite(ertHandle()); } -void Summary::addAllWells(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, +void Summary::addAllWells(Opm::EclipseStateConstPtr eclipseState, const PhaseUsage& uses) { eclipseState_ = eclipseState; @@ -1174,7 +1172,7 @@ void EclipseWriter::writeInit(const SimulatorTimerInterface &timer) eclGrid->getNX(), eclGrid->getNY(), eclGrid->getNZ())); - summary_->addAllWells(deck_, eclipseState_, phaseUsage_); + summary_->addAllWells(eclipseState_, phaseUsage_); } // implementation of the writeTimeStep method @@ -1341,13 +1339,11 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer, EclipseWriter::EclipseWriter(const parameter::ParameterGroup& params, - Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclipseState, const Opm::PhaseUsage &phaseUsage, int numCells, const int* compressedToCartesianCellIdx) - : deck_(deck) - , eclipseState_(eclipseState) + : eclipseState_(eclipseState) , numCells_(numCells) , compressedToCartesianCellIdx_(compressedToCartesianCellIdx) , gridToEclipseIdx_(numCells, int(-1) ) diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index 7dd03e4c..0c1e3d77 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -65,7 +65,6 @@ public: * binary files using ERT. */ EclipseWriter(const parameter::ParameterGroup& params, - Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclipseState, const Opm::PhaseUsage &phaseUsage, int numCells, @@ -107,7 +106,6 @@ public: static ert_ecl_unit_enum convertUnitTypeErtEclUnitEnum(UnitSystem::UnitType unit); private: - Opm::DeckConstPtr deck_; Opm::EclipseStateConstPtr eclipseState_; int numCells_; std::array cartesianSize_; diff --git a/opm/core/simulator/SimulatorOutput.cpp b/opm/core/simulator/SimulatorOutput.cpp index 4e833b8d..40606c30 100644 --- a/opm/core/simulator/SimulatorOutput.cpp +++ b/opm/core/simulator/SimulatorOutput.cpp @@ -30,7 +30,6 @@ using namespace Opm; SimulatorOutputBase::SimulatorOutputBase ( const parameter::ParameterGroup& params, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid, @@ -46,7 +45,7 @@ SimulatorOutputBase::SimulatorOutputBase ( // process parameters into a writer. we don't setup a new chain in // every timestep! - , writer_ (std::move (OutputWriter::create (params, deck, eclipseState, phaseUsage, grid))) + , writer_ (std::move (OutputWriter::create (params, eclipseState, phaseUsage, grid))) // always start from the first timestep , next_ (0) { diff --git a/opm/core/simulator/SimulatorOutput.hpp b/opm/core/simulator/SimulatorOutput.hpp index 8b9acea7..6b0ce5a0 100644 --- a/opm/core/simulator/SimulatorOutput.hpp +++ b/opm/core/simulator/SimulatorOutput.hpp @@ -56,7 +56,6 @@ protected: * need to pick them up from the object members. */ SimulatorOutputBase (const parameter::ParameterGroup& p, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid, @@ -146,7 +145,6 @@ private: template struct SimulatorOutput : public SimulatorOutputBase { SimulatorOutput (const parameter::ParameterGroup& params, - std::shared_ptr deck, std::shared_ptr eclipseState, const Opm::PhaseUsage &phaseUsage, std::shared_ptr grid, @@ -155,7 +153,7 @@ struct SimulatorOutput : public SimulatorOutputBase { std::shared_ptr wellState, std::shared_ptr sim) // send all other parameters to base class - : SimulatorOutputBase (params, deck, eclipseState, phaseUsage, + : SimulatorOutputBase (params, eclipseState, phaseUsage, grid, timer, state, wellState) // store reference to simulator in derived class @@ -171,7 +169,6 @@ struct SimulatorOutput : public SimulatorOutputBase { * the arguments passed exceeds the lifetime of this object. */ SimulatorOutput (const parameter::ParameterGroup& params, - const Deck& deck, const EclipseState& eclipseState, const Opm::PhaseUsage &phaseUsage, const UnstructuredGrid& grid, @@ -181,7 +178,6 @@ struct SimulatorOutput : public SimulatorOutputBase { Simulator& sim) // send all other parameters to base class : SimulatorOutputBase (params, - share_obj (deck), share_obj (eclipseState), phaseUsage, share_obj (grid), diff --git a/tests/test_EclipseWriteRFTHandler.cpp b/tests/test_EclipseWriteRFTHandler.cpp index 41eb18d3..d557574a 100755 --- a/tests/test_EclipseWriteRFTHandler.cpp +++ b/tests/test_EclipseWriteRFTHandler.cpp @@ -136,7 +136,6 @@ std::shared_ptr createEclipseWriter(std::shared_ptrc_grid(); std::shared_ptr eclipseWriter = std::make_shared(params, - deck, eclipseState, phaseUsage, ourFinerUnstructuredGrid.number_of_cells, diff --git a/tests/test_EclipseWriter.cpp b/tests/test_EclipseWriter.cpp index 255d4219..0dd9635d 100644 --- a/tests/test_EclipseWriter.cpp +++ b/tests/test_EclipseWriter.cpp @@ -85,7 +85,6 @@ void createEclipseWriter(const char *deckString) Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); eclWriter.reset(new Opm::EclipseWriter(params, - deck, eclipseState, phaseUsage, ourFinerUnstructuredGrid.number_of_cells, diff --git a/tests/test_writenumwells.cpp b/tests/test_writenumwells.cpp index 2a7c1715..7fb16bcd 100644 --- a/tests/test_writenumwells.cpp +++ b/tests/test_writenumwells.cpp @@ -151,7 +151,6 @@ Opm::EclipseWriterPtr createEclipseWriter(Opm::DeckConstPtr deck, const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck); Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(params, - deck, eclipseState, phaseUsage, eclipseState->getEclipseGrid()->getCartesianSize(),