EclipseWriter: pass an EclipseState to it and use it where possible

This commit is contained in:
Andreas Lauser
2014-07-16 14:18:57 +02:00
parent 65a1bd6722
commit dc5fc64e98
7 changed files with 60 additions and 76 deletions

View File

@@ -47,13 +47,14 @@ private:
/// Psuedo-constructor, can appear in template
template <typename Format> unique_ptr <OutputWriter>
create (const ParameterGroup& params,
std::shared_ptr <const Deck> parser,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> grid) {
return unique_ptr <OutputWriter> (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 char*, unique_ptr <OutputWriter> (*)(
const ParameterGroup&,
std::shared_ptr <const Deck>,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid>)> map_t;
map_t FORMATS = {
{ "output_ecl", &create <EclipseWriter> },
@@ -74,7 +76,8 @@ map_t FORMATS = {
unique_ptr <OutputWriter>
OutputWriter::create (const ParameterGroup& params,
std::shared_ptr <const Deck> parser,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> 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 <bool> (name, false)) {
list->push_front (it->second (params, parser, grid));
list->push_front (it->second (params, deck, eclipseState, grid));
}
}

View File

@@ -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 <OutputWriter>
create (const parameter::ParameterGroup& params,
std::shared_ptr <const Deck> parser,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> grid);
};

View File

@@ -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<RUNSPECSection>(deck);
auto gridSection = std::make_shared<GRIDSection>(deck);
eclGrid_ = std::make_shared<Opm::EclipseGrid>(runspecSection, gridSection);
// compute the ACTNUM field
int numCartesianCells = eclGrid_->getCartesianSize();
std::vector<int> 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<float> poro_kw(PORO_KW, dataField);
Keyword<float> 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);
}

View File

@@ -24,6 +24,7 @@
#include <opm/core/io/OutputWriter.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <string>
@@ -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<int, 3> cartesianSize_;
const int* compressedToCartesianCellIdx_;

View File

@@ -31,8 +31,8 @@ using namespace Opm;
SimulatorOutputBase::SimulatorOutputBase (
const parameter::ParameterGroup& params,
std::shared_ptr <const Deck> parser,
std::shared_ptr <const TimeMap> timeMap,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> grid,
std::shared_ptr <const SimulatorTimer> timer,
std::shared_ptr <const SimulatorState> 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) {

View File

@@ -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 <const Deck> parser,
std::shared_ptr <const TimeMap> timeMap,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> grid,
std::shared_ptr <const SimulatorTimer> timer,
std::shared_ptr <const SimulatorState> state,
@@ -143,15 +144,15 @@ private:
template <typename Simulator>
struct SimulatorOutput : public SimulatorOutputBase {
SimulatorOutput (const parameter::ParameterGroup& params,
std::shared_ptr <const Deck> parser,
std::shared_ptr <const TimeMap> timeMap,
std::shared_ptr <const Deck> deck,
std::shared_ptr <const EclipseState> eclipseState,
std::shared_ptr <const UnstructuredGrid> grid,
std::shared_ptr <const SimulatorTimer> timer,
std::shared_ptr <const SimulatorState> state,
std::shared_ptr <const WellState> wellState,
std::shared_ptr <Simulator> 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),