From dc5fc64e98efb3d25d05e4fd3a53bcd71c5926fe Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 16 Jul 2014 14:18:57 +0200 Subject: [PATCH] EclipseWriter: pass an EclipseState to it and use it where possible --- opm/core/io/OutputWriter.cpp | 15 ++++---- opm/core/io/OutputWriter.hpp | 10 +++--- opm/core/io/eclipse/EclipseWriter.cpp | 50 +++++++++----------------- opm/core/io/eclipse/EclipseWriter.hpp | 6 ++-- opm/core/simulator/SimulatorOutput.cpp | 7 ++-- opm/core/simulator/SimulatorOutput.hpp | 19 +++++----- tests/test_EclipseWriter.cpp | 29 +++++++-------- 7 files changed, 60 insertions(+), 76 deletions(-) diff --git a/opm/core/io/OutputWriter.cpp b/opm/core/io/OutputWriter.cpp index 6ee41081..1fe7da43 100644 --- a/opm/core/io/OutputWriter.cpp +++ b/opm/core/io/OutputWriter.cpp @@ -47,13 +47,14 @@ private: /// Psuedo-constructor, can appear in template template unique_ptr create (const ParameterGroup& params, - std::shared_ptr parser, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid) { return unique_ptr (new Format (params, - parser, + deck, + eclipseState, grid->number_of_cells, - grid->global_cell, - grid->cartdims)); + grid->global_cell)); } /// Map between keyword in configuration and the corresponding @@ -65,6 +66,7 @@ create (const ParameterGroup& params, typedef map (*)( const ParameterGroup&, std::shared_ptr , + std::shared_ptr eclipseState, std::shared_ptr )> map_t; map_t FORMATS = { { "output_ecl", &create }, @@ -74,7 +76,8 @@ map_t FORMATS = { unique_ptr OutputWriter::create (const ParameterGroup& params, - std::shared_ptr parser, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid) { // allocate a list which will be filled with writers. this list // is initially empty (no output). @@ -90,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, parser, grid)); + list->push_front (it->second (params, deck, eclipseState, grid)); } } diff --git a/opm/core/io/OutputWriter.hpp b/opm/core/io/OutputWriter.hpp index df3759bc..1d3fbda5 100644 --- a/opm/core/io/OutputWriter.hpp +++ b/opm/core/io/OutputWriter.hpp @@ -28,6 +28,7 @@ namespace Opm { // forward declaration class Deck; +class EclipseState; namespace parameter { class ParameterGroup; } class SimulatorState; class SimulatorTimer; @@ -95,9 +96,9 @@ public: * multiplexer of applicable output formats based on the * desired configuration values. * - * @param parser Input deck used to set up the simulation. The lifetime - * of this object must exceed the lifetime of the writer - * that is returned. + * @param deck Input deck used to set up the simulation. + * + * @param eclipseState The internalized input deck. * * @return Pointer to a multiplexer to all applicable output formats. * @@ -105,7 +106,8 @@ public: */ static std::unique_ptr create (const parameter::ParameterGroup& params, - std::shared_ptr parser, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid); }; diff --git a/opm/core/io/eclipse/EclipseWriter.cpp b/opm/core/io/eclipse/EclipseWriter.cpp index 81d65108..a7f0293e 100644 --- a/opm/core/io/eclipse/EclipseWriter.cpp +++ b/opm/core/io/eclipse/EclipseWriter.cpp @@ -477,37 +477,20 @@ public: void writeHeader(int numCells, const int* compressedToCartesianCellIdx, const SimulatorTimer& timer, - Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclipseState, const PhaseUsage uses) { - auto dataField = getAllSiDoubles(deck->getKeyword(PORO_KW)); + auto dataField = eclipseState->getDoubleGridProperty("PORO")->getData(); restrictToActiveCells(dataField, numCells, compressedToCartesianCellIdx); - auto runspecSection = std::make_shared(deck); - auto gridSection = std::make_shared(deck); - eclGrid_ = std::make_shared(runspecSection, gridSection); - - // compute the ACTNUM field - int numCartesianCells = eclGrid_->getCartesianSize(); - std::vector actnumData(numCartesianCells, 1); - if (compressedToCartesianCellIdx) { - // if we have a compressed-to-Cartesian map, we activate only those cells - // which appear in that map - std::fill(actnumData.begin(), actnumData.end(), 0); - for (int cellIdx = 0; cellIdx < numCells; ++cellIdx) { - int cartesianCellIdx = compressedToCartesianCellIdx[cellIdx]; - actnumData[cartesianCellIdx] = 1; - } - } - - eclGrid_->resetACTNUM(&actnumData[0]); + auto eclGrid = eclipseState->getEclipseGrid(); // finally, write the grid to disk - eclGrid_->fwriteEGRID(egridFileName_.ertHandle()); + eclGrid->fwriteEGRID(egridFileName_.ertHandle()); - Keyword poro_kw(PORO_KW, dataField); + Keyword poro_kw("PORO", dataField); ecl_init_file_fwrite_header(ertHandle(), - eclGrid_->c_ptr(), + eclGrid->c_ptr(), poro_kw.ertHandle(), ertPhaseMask(uses), timer.currentPosixTime()); @@ -522,13 +505,9 @@ public: fortio_type *ertHandle() const { return ertHandle_; } - Opm::EclipseGridConstPtr eclipseGrid() const - { return eclGrid_; } - private: fortio_type *ertHandle_; FileName egridFileName_; - Opm::EclipseGridPtr eclGrid_; }; /** @@ -849,7 +828,7 @@ void EclipseWriter::writeInit(const SimulatorTimer &timer) fortio.writeHeader(numCells_, compressedToCartesianCellIdx_, timer, - deck_, + eclipseState_, phaseUsage_); if (deck_->hasKeyword("PERMX")) { @@ -870,7 +849,7 @@ void EclipseWriter::writeInit(const SimulatorTimer &timer) /* Create summary object (could not do it at construction time, since it requires knowledge of the start time). */ - auto eclGrid = fortio.eclipseGrid(); + auto eclGrid = eclipseState_->getEclipseGrid(); summary_.reset(new EclipseWriterDetails::Summary(outputDir_, baseName_, timer, @@ -953,16 +932,19 @@ void EclipseWriter::writeTimeStep(const SimulatorTimer& timer, EclipseWriter::EclipseWriter(const parameter::ParameterGroup& params, Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclipseState, int numCells, - const int* compressedToCartesianCellIdx, - const int* cartesianSize) - : deck_ (deck) + const int* compressedToCartesianCellIdx) + : deck_(deck) + , eclipseState_(eclipseState) , numCells_(numCells) , compressedToCartesianCellIdx_(compressedToCartesianCellIdx) , phaseUsage_(phaseUsageFromDeck(deck_)) { - for (int i = 0; i < 3; ++i) - cartesianSize_[i] = cartesianSize[i]; + const auto eclGrid = eclipseState->getEclipseGrid(); + cartesianSize_[0] = eclGrid->getNX(); + cartesianSize_[1] = eclGrid->getNY(); + cartesianSize_[2] = eclGrid->getNZ(); init(params); } diff --git a/opm/core/io/eclipse/EclipseWriter.hpp b/opm/core/io/eclipse/EclipseWriter.hpp index ef9f0d96..fbaa8600 100644 --- a/opm/core/io/eclipse/EclipseWriter.hpp +++ b/opm/core/io/eclipse/EclipseWriter.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -64,9 +65,9 @@ public: */ EclipseWriter(const parameter::ParameterGroup& params, Opm::DeckConstPtr deck, + Opm::EclipseStateConstPtr eclipseState, int numCells, - const int* compressedToCartesianCellIdx, - const int* cartesianSize); + const int* compressedToCartesianCellIdx); /** * We need a destructor in the compilation unit to avoid the @@ -99,6 +100,7 @@ public: private: Opm::DeckConstPtr deck_; + Opm::EclipseStateConstPtr eclipseState_; int numCells_; std::array cartesianSize_; const int* compressedToCartesianCellIdx_; diff --git a/opm/core/simulator/SimulatorOutput.cpp b/opm/core/simulator/SimulatorOutput.cpp index 250046da..68ca9b88 100644 --- a/opm/core/simulator/SimulatorOutput.cpp +++ b/opm/core/simulator/SimulatorOutput.cpp @@ -31,8 +31,8 @@ using namespace Opm; SimulatorOutputBase::SimulatorOutputBase ( const parameter::ParameterGroup& params, - std::shared_ptr parser, - std::shared_ptr timeMap, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid, std::shared_ptr timer, std::shared_ptr state, @@ -41,13 +41,12 @@ SimulatorOutputBase::SimulatorOutputBase ( // store all parameters passed into the object, making them curried // parameters to the writeOutput function. : timer_ (timer ) - , timeMap_ (timeMap ) , reservoirState_ (state ) , wellState_ (wellState) // process parameters into a writer. we don't setup a new chain in // every timestep! - , writer_ (std::move (OutputWriter::create (params, parser, grid))) + , writer_ (std::move (OutputWriter::create (params, deck, eclipseState, grid))) // always start from the first timestep , next_ (0) { diff --git a/opm/core/simulator/SimulatorOutput.hpp b/opm/core/simulator/SimulatorOutput.hpp index b276ac57..912555ab 100644 --- a/opm/core/simulator/SimulatorOutput.hpp +++ b/opm/core/simulator/SimulatorOutput.hpp @@ -33,6 +33,7 @@ namespace Opm { // forward definitions class Deck; +class EclipseState; class OutputWriter; namespace parameter { class ParameterGroup; } class SimulatorState; @@ -54,8 +55,8 @@ protected: * need to pick them up from the object members. */ SimulatorOutputBase (const parameter::ParameterGroup& p, - std::shared_ptr parser, - std::shared_ptr timeMap, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid, std::shared_ptr timer, std::shared_ptr state, @@ -143,15 +144,15 @@ private: template struct SimulatorOutput : public SimulatorOutputBase { SimulatorOutput (const parameter::ParameterGroup& params, - std::shared_ptr parser, - std::shared_ptr timeMap, + std::shared_ptr deck, + std::shared_ptr eclipseState, std::shared_ptr grid, std::shared_ptr timer, std::shared_ptr state, std::shared_ptr wellState, std::shared_ptr sim) // send all other parameters to base class - : SimulatorOutputBase (params, parser, timeMap, + : SimulatorOutputBase (params, deck, eclipseState, grid, timer, state, wellState) // store reference to simulator in derived class @@ -167,8 +168,8 @@ struct SimulatorOutput : public SimulatorOutputBase { * the arguments passed exceeds the lifetime of this object. */ SimulatorOutput (const parameter::ParameterGroup& params, - const Deck& parser, - const TimeMap& timeMap, + const Deck& deck, + const EclipseState& eclipseState, const UnstructuredGrid& grid, const SimulatorTimer& timer, const SimulatorState& state, @@ -176,8 +177,8 @@ struct SimulatorOutput : public SimulatorOutputBase { Simulator& sim) // send all other parameters to base class : SimulatorOutputBase (params, - share_obj (parser), - share_obj (timeMap), + share_obj (deck), + share_obj (eclipseState), share_obj (grid), share_obj (timer), share_obj (state), diff --git a/tests/test_EclipseWriter.cpp b/tests/test_EclipseWriter.cpp index 5a529669..b436c8c0 100644 --- a/tests/test_EclipseWriter.cpp +++ b/tests/test_EclipseWriter.cpp @@ -48,7 +48,7 @@ std::shared_ptr eclWriter; std::shared_ptr simTimer; std::shared_ptr deck; -std::shared_ptr eclGrid; +std::shared_ptr eclipseState; std::shared_ptr ourFineGridManagerPtr; std::shared_ptr blackoilState; std::shared_ptr wellState; @@ -61,29 +61,16 @@ void createEclipseWriter(const char *deckString) Opm::parameter::ParameterGroup params; params.insertParameter("deck_filename", "foo.data"); - auto runspecSection = std::make_shared(deck); - auto gridSection = std::make_shared(deck); - eclGrid.reset(new Opm::EclipseGrid(runspecSection, gridSection)); + eclipseState.reset(new Opm::EclipseState(deck)); + auto eclGrid = eclipseState->getEclipseGrid(); BOOST_CHECK(eclGrid->getNX() == 3); BOOST_CHECK(eclGrid->getNY() == 3); BOOST_CHECK(eclGrid->getNZ() == 3); BOOST_CHECK(eclGrid->getCartesianSize() == 3*3*3); - std::array cartSize; - cartSize[0] = eclGrid->getNX(); - cartSize[1] = eclGrid->getNY(); - cartSize[2] = eclGrid->getNZ(); - simTimer.reset(new Opm::SimulatorTimer()); - Opm::TimeMapConstPtr timeMap(new Opm::TimeMap(deck)); - simTimer->init(timeMap); - - eclWriter.reset(new Opm::EclipseWriter(params, - deck, - eclGrid->getCartesianSize(), - 0, - &cartSize[0])); + simTimer->init(eclipseState->getSchedule()->getTimeMap()); // also create an UnstructuredGrid (required to create a BlackoilState) Opm::EclipseGridConstPtr constEclGrid(eclGrid); @@ -96,6 +83,12 @@ void createEclipseWriter(const char *deckString) BOOST_CHECK(ourFinerUnstructuredGrid.number_of_cells == 3*3*3); + eclWriter.reset(new Opm::EclipseWriter(params, + deck, + eclipseState, + ourFinerUnstructuredGrid.number_of_cells, + 0)); + // this check is disabled so far, because UnstructuredGrid uses some weird definition // of the term "face". For this grid, "number_of_faces" is 108 which is // 2*6*numCells... @@ -213,6 +206,8 @@ void checkEgridFile() // use ERT directly to inspect the EGRID file produced by EclipseWriter auto egridFile = fortio_open_reader("FOO.EGRID", /*isFormated=*/0, ECL_ENDIAN_FLIP); + auto eclGrid = eclipseState->getEclipseGrid(); + ecl_kw_type *eclKeyword; // yes, that's an assignment! while ((eclKeyword = ecl_kw_fread_alloc(egridFile))) {