Revert back code so that output grid is not recreated unsafely

Readded necessary parameters for this
This commit is contained in:
Kjell W. Kongsvik 2016-04-29 10:14:06 +02:00
parent 9c78c11972
commit db87f24ebb
7 changed files with 46 additions and 37 deletions

View File

@ -52,7 +52,9 @@ create (const ParameterGroup& params,
const Opm::PhaseUsage &phaseUsage,
std::shared_ptr <const UnstructuredGrid> grid) {
return unique_ptr <OutputWriter> (new Format (eclipseState,
phaseUsage));
phaseUsage,
grid->number_of_cells,
grid->global_cell));
}
/// Map between keyword in configuration and the corresponding

View File

@ -69,7 +69,9 @@ public:
* binary files using ERT.
*/
EclipseWriter(Opm::EclipseStateConstPtr eclipseState,
const Opm::PhaseUsage &phaseUsage);
const Opm::PhaseUsage &phaseUsage,
int numCells,
const int* compressedToCartesianCellIdx);
/**
* We need a destructor in the compilation unit to avoid the
@ -111,7 +113,7 @@ private:
Opm::EclipseStateConstPtr eclipseState_;
int numCells_;
std::array<int, 3> cartesianSize_;
std::vector<int> compressedToCartesianCellIdx_;
const int* compressedToCartesianCellIdx_;
std::vector< int > gridToEclipseIdx_;
double deckToSiPressure_;
double deckToSiTemperatureFactor_;

View File

@ -1178,7 +1178,7 @@ void EclipseWriter::writeInit(const SimulatorTimerInterface &timer)
EclipseWriterDetails::Init fortio(outputDir_, baseName_, /*stepIdx=*/0, eclipseState_->getIOConfigConst());
fortio.writeHeader(numCells_,
compressedToCartesianCellIdx_.data(),
compressedToCartesianCellIdx_,
timer,
eclipseState_,
phaseUsage_);
@ -1367,7 +1367,7 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer,
//Write RFT data for current timestep to RFT file
std::shared_ptr<EclipseWriterDetails::EclipseWriteRFTHandler> eclipseWriteRFTHandler = std::make_shared<EclipseWriterDetails::EclipseWriteRFTHandler>(
compressedToCartesianCellIdx_.data(),
compressedToCartesianCellIdx_,
numCells_,
eclipseState_->getInputGrid()->getCartesianSize());
@ -1416,8 +1416,13 @@ void EclipseWriter::writeTimeStep(const SimulatorTimerInterface& timer,
EclipseWriter::EclipseWriter(Opm::EclipseStateConstPtr eclipseState,
const Opm::PhaseUsage &phaseUsage)
const Opm::PhaseUsage &phaseUsage,
int numCells,
const int* compressedToCartesianCellIdx)
: eclipseState_(eclipseState)
, numCells_(numCells)
, compressedToCartesianCellIdx_(compressedToCartesianCellIdx)
, gridToEclipseIdx_(numCells, int(-1) )
, phaseUsage_(phaseUsage)
{
const auto eclGrid = eclipseState->getInputGrid();
@ -1425,25 +1430,12 @@ EclipseWriter::EclipseWriter(Opm::EclipseStateConstPtr eclipseState,
cartesianSize_[1] = eclGrid->getNY();
cartesianSize_[2] = eclGrid->getNZ();
numCells_ = eclGrid->getNumActive();
gridToEclipseIdx_ = std::vector<int>(numCells_, int(-1) );
//TODO
//This should be calculated in EclipseGrid
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr = std::make_shared<Opm::GridManager>(eclipseState->getInputGrid());
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
auto compressedToCartesianCellIdx__ = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid);
for(int i=0;i<numCells_;i++) {
compressedToCartesianCellIdx_.push_back(compressedToCartesianCellIdx__[i]);
}
if( compressedToCartesianCellIdx_.size()>0 ) {
if( compressedToCartesianCellIdx ) {
// if compressedToCartesianCellIdx available then
// compute mapping to eclipse order
std::map< int , int > indexMap;
for (int cellIdx = 0; cellIdx < numCells_; ++cellIdx) {
int cartesianCellIdx = compressedToCartesianCellIdx_[cellIdx];
for (int cellIdx = 0; cellIdx < numCells; ++cellIdx) {
int cartesianCellIdx = compressedToCartesianCellIdx[cellIdx];
indexMap[ cartesianCellIdx ] = cellIdx;
}
@ -1453,8 +1445,8 @@ EclipseWriter::EclipseWriter(Opm::EclipseStateConstPtr eclipseState,
}
}
else {
// if not compressedToCartesianCellIdx_ was given use identity
for (int cellIdx = 0; cellIdx < numCells_; ++cellIdx) {
// if not compressedToCartesianCellIdx was given use identity
for (int cellIdx = 0; cellIdx < numCells; ++cellIdx) {
gridToEclipseIdx_[ cellIdx ] = cellIdx;
}
}

View File

@ -125,13 +125,18 @@ std::shared_ptr<Opm::BlackoilState> createBlackoilState(int timeStepIdx, std::sh
std::shared_ptr<Opm::EclipseWriter> createEclipseWriter(std::shared_ptr<const Opm::Deck> deck,
std::shared_ptr<Opm::EclipseState> eclipseState,
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr)
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr,
const int * compressedToCartesianCellIdx)
{
Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
std::shared_ptr<Opm::EclipseWriter> eclipseWriter = std::make_shared<Opm::EclipseWriter>(eclipseState,
phaseUsage);
phaseUsage,
ourFinerUnstructuredGrid.number_of_cells,
compressedToCartesianCellIdx);
return eclipseWriter;
}
@ -155,10 +160,13 @@ BOOST_AUTO_TEST_CASE(test_EclipseWriterRFTHandler)
simulatorTimer->init(eclipseState->getSchedule()->getTimeMap());
std::shared_ptr<Opm::GridManager> ourFineGridManagerPtr = std::make_shared<Opm::GridManager>(eclipseState->getInputGrid());
const UnstructuredGrid &ourFinerUnstructuredGrid = *ourFineGridManagerPtr->c_grid();
const int* compressedToCartesianCellIdx = Opm::UgGridHelpers::globalCell(ourFinerUnstructuredGrid);
std::shared_ptr<Opm::EclipseWriter> eclipseWriter = createEclipseWriter(deck,
eclipseState,
ourFineGridManagerPtr);
ourFineGridManagerPtr,
compressedToCartesianCellIdx);
eclipseWriter->writeInit(*simulatorTimer);

View File

@ -68,7 +68,6 @@ void createEclipseWriter(const char *deckString)
eclipseState.reset(new Opm::EclipseState(deck , parseContext));
auto eclGrid = eclipseState->getInputGrid();
BOOST_CHECK(eclGrid->getNX() == 3);
BOOST_CHECK(eclGrid->getNY() == 3);
BOOST_CHECK(eclGrid->getNZ() == 3);
@ -91,7 +90,9 @@ void createEclipseWriter(const char *deckString)
Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
eclWriter.reset(new Opm::EclipseWriter(eclipseState,
phaseUsage));
phaseUsage,
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
@ -182,7 +183,8 @@ void getErtData(ecl_kw_type *eclKeyword, std::vector<int> &data)
std::copy(ertData, ertData + kwSize, data.begin());
}
void compareErtData(const std::vector<double> &src, const std::vector<double> &dst, double tolerance) {
void compareErtData(const std::vector<double> &src, const std::vector<double> &dst, double tolerance)
{
BOOST_CHECK_EQUAL(src.size(), dst.size());
if (src.size() != dst.size())
return;
@ -191,14 +193,14 @@ void compareErtData(const std::vector<double> &src, const std::vector<double> &d
BOOST_CHECK_CLOSE(src[i], dst[i], tolerance);
}
void compareErtData(const std::vector<int> &src, const std::vector<int> &dst) {
void compareErtData(const std::vector<int> &src, const std::vector<int> &dst)
{
BOOST_CHECK_EQUAL(src.size(), dst.size());
if (src.size() != dst.size())
return;
for (size_t i = 0; i < src.size(); ++i)
BOOST_CHECK_EQUAL(src[i], dst[i]);
}
void checkEgridFile()

View File

@ -204,7 +204,9 @@ Opm::EclipseWriterPtr createEclipseWriter(Opm::DeckConstPtr deck,
const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(eclipseState,
phaseUsage));
phaseUsage,
eclipseState->getInputGrid()->getCartesianSize(),
0));
return eclWriter;
}

View File

@ -151,7 +151,9 @@ Opm::EclipseWriterPtr createEclipseWriter(Opm::DeckConstPtr deck,
const Opm::PhaseUsage phaseUsage = Opm::phaseUsageFromDeck(deck);
Opm::EclipseWriterPtr eclWriter(new Opm::EclipseWriter(eclipseState,
phaseUsage));
phaseUsage,
eclipseState->getInputGrid()->getCartesianSize(),
0));
return eclWriter;
}
@ -168,7 +170,6 @@ BOOST_AUTO_TEST_CASE(EclipseWriteRestartWellInfo)
Opm::ParseContext parseContext;
Opm::DeckConstPtr deck = createDeck(eclipse_data_filename);
Opm::EclipseStatePtr eclipseState(new Opm::EclipseState(deck , parseContext));
Opm::EclipseWriterPtr eclipseWriter = createEclipseWriter(deck, eclipseState);
std::shared_ptr<Opm::SimulatorTimer> simTimer( new Opm::SimulatorTimer() );
@ -182,8 +183,8 @@ BOOST_AUTO_TEST_CASE(EclipseWriteRestartWellInfo)
int countTimeStep = eclipseState->getSchedule()->getTimeMap()->numTimesteps();
for(int timestep=0; timestep <= countTimeStep; ++timestep) {
simTimer->setCurrentStepNum(timestep);
for(int timestep=0; timestep <= countTimeStep; ++timestep){
simTimer->setCurrentStepNum(timestep);
eclipseWriter->writeTimeStep(*simTimer, *blackoilState, *wellState, false);
}