#4495 Active Cells : Handle active cells for dual porosity models based on PORV

This commit is contained in:
Magne Sjaastad 2019-06-20 15:00:01 +02:00
parent 515b2a4237
commit 7c054c47f2
5 changed files with 62 additions and 32 deletions

View File

@ -58,11 +58,10 @@ std::vector<std::vector<int>> RifActiveCellsReader::activeCellsFromPorvKeyword(c
std::vector<std::vector<int>> activeCellsAllGrids;
// When PORV is used as criteria, make sure all active cells are assigned both
// active matrix state and active fracture state. This will make sure that
// both single porosity models and dual porosity models are initialized with
// the correct bit mask. See documentation in top of ecl_grid.cpp
// Active cell count is always the same size as the number of cells in the grid
// If we have dual porosity, we have to divide by 2
//
// See documentation of active cells in top of ecl_grid.cpp
int porvKeywordCount = ecl_file_get_num_named_kw(ecl_file, PORV_KW);
for (size_t gridIdx = 0; gridIdx < static_cast<size_t>(porvKeywordCount); gridIdx++)
@ -71,24 +70,36 @@ std::vector<std::vector<int>> RifActiveCellsReader::activeCellsFromPorvKeyword(c
RifEclipseOutputFileTools::keywordData(ecl_file, PORV_KW, gridIdx, &porvValues);
std::vector<int> activeCellsOneGrid;
activeCellsOneGrid.resize(porvValues.size());
for (size_t i = 0; i < porvValues.size(); i++)
size_t activeCellCount = porvValues.size();
if (dualPorosity)
{
if (porvValues[i] > 0.0)
activeCellCount /= 2;
}
activeCellsOneGrid.resize(activeCellCount, 0);
for (size_t poreValueIndex = 0; poreValueIndex < porvValues.size(); poreValueIndex++)
{
size_t indexToCell = poreValueIndex;
if (indexToCell >= activeCellCount)
{
if (!dualPorosity || i < porvValues.size() / 2)
indexToCell = poreValueIndex - activeCellCount;
}
if (porvValues[poreValueIndex] > 0.0)
{
if (!dualPorosity || poreValueIndex < porvValues.size() / 2)
{
activeCellsOneGrid[i] = CELL_ACTIVE_MATRIX;
activeCellsOneGrid[indexToCell] = CELL_ACTIVE_MATRIX;
}
else
{
activeCellsOneGrid[i] = CELL_ACTIVE_FRACTURE;
activeCellsOneGrid[indexToCell] += CELL_ACTIVE_FRACTURE;
}
}
else
{
activeCellsOneGrid[i] = 0;
activeCellsOneGrid[indexToCell] = 0;
}
}
@ -97,3 +108,28 @@ std::vector<std::vector<int>> RifActiveCellsReader::activeCellsFromPorvKeyword(c
return activeCellsAllGrids;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifActiveCellsReader::applyActiveCellsToAllGrids(ecl_grid_type* ecl_main_grid,
const std::vector<std::vector<int>>& activeCellsForAllGrids)
{
CAF_ASSERT(ecl_main_grid);
for (int gridIndex = 0; gridIndex < static_cast<int>(activeCellsForAllGrids.size()); gridIndex++)
{
ecl_grid_type* currentGrid = ecl_main_grid;
if (gridIndex > 0)
{
currentGrid = ecl_grid_iget_lgr(ecl_main_grid, gridIndex - 1);
}
auto activeCellsForGrid = activeCellsForAllGrids[gridIndex];
CAF_ASSERT(ecl_grid_get_global_size(currentGrid) == static_cast<int>(activeCellsForGrid.size()));
int* actnum_values = activeCellsForGrid.data();
ecl_grid_reset_actnum(currentGrid, actnum_values);
}
}

View File

@ -33,4 +33,7 @@ public:
static std::vector<std::vector<int>> activeCellsFromActnumKeyword(const ecl_file_type* ecl_file);
static std::vector<std::vector<int>> activeCellsFromPorvKeyword(const ecl_file_type* ecl_file, bool dualPorosity);
static void applyActiveCellsToAllGrids(ecl_grid_type* ecl_main_grid,
const std::vector<std::vector<int>>& activeCellsForAllGrids);
};

View File

@ -401,7 +401,7 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigEclipseCaseData* e
// Read geometry
// Todo: Needs to check existence of file before calling ert, else it will abort
mainEclGrid = loadMainGrid();
mainEclGrid = loadAllGrids();
if (!mainEclGrid)
{
QString errorMessage = QString(" Failed to create a main grid from file\n%1").arg(m_fileName);
@ -2279,30 +2279,21 @@ bool RifReaderEclipseOutput::isEclipseAndSoursimTimeStepsEqual(const QDateTime&
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
ecl_grid_type* RifReaderEclipseOutput::loadMainGrid() const
ecl_grid_type* RifReaderEclipseOutput::loadAllGrids() const
{
ecl_grid_type* mainEclGrid = nullptr;
ecl_grid_type* mainEclGrid = ecl_grid_alloc(RiaStringEncodingTools::toNativeEncoded(m_fileName).data());
if (m_ecl_init_file)
{
if (m_ecl_init_file)
{
ecl_kw_type* actnumFromPorv = RifEclipseOutputFileTools::createActnumFromPorv(m_ecl_init_file);
if (actnumFromPorv)
{
int* actnum_values = ecl_kw_get_int_ptr(actnumFromPorv);
if (actnum_values)
{
mainEclGrid =
ecl_grid_alloc_ext_actnum(RiaStringEncodingTools::toNativeEncoded(m_fileName).data(), actnum_values);
}
// TODO : ecl_grid_alloc() will automatically read ACTNUM from EGRID file, and reading of active cell information can be
// skipped if PORV is available
ecl_kw_free(actnumFromPorv);
}
}
bool isDualPorosity = ecl_grid_dual_grid(mainEclGrid);
auto activeCells = RifActiveCellsReader::activeCellsFromPorvKeyword(m_ecl_init_file, isDualPorosity);
if (!mainEclGrid)
if (!activeCells.empty())
{
mainEclGrid = ecl_grid_alloc(RiaStringEncodingTools::toNativeEncoded(m_fileName).data());
RifActiveCellsReader::applyActiveCellsToAllGrids(mainEclGrid, activeCells);
}
}

View File

@ -88,7 +88,7 @@ public:
// ecl_grid_type* myGrid = loadMainGrid();
// free(myGrid);
//
ecl_grid_type* loadMainGrid() const;
ecl_grid_type* loadAllGrids() const;
private:
bool readActiveCellInfo();

View File

@ -524,7 +524,7 @@ bool RigFlowDiagSolverInterface::ensureStaticDataObjectInstanceCreated()
auto eclOutput = dynamic_cast<const RifReaderEclipseOutput*>(fileReader);
if (eclOutput)
{
ecl_grid_type* mainGrid = eclOutput->loadMainGrid();
ecl_grid_type* mainGrid = eclOutput->loadAllGrids();
if (!mainGrid)
{
return false;