Added GetCoarseningInfo

Added coarse cells to mock model with results
p4#: 21686
This commit is contained in:
Magne Sjaastad 2013-05-21 21:03:05 +02:00
parent 9df895ddc7
commit 8a6234690c
8 changed files with 252 additions and 21 deletions

View File

@ -1042,21 +1042,7 @@ void RifReaderEclipseOutput::transferCoarseningInfo(const ecl_grid_type* eclGrid
size_t k1 = static_cast<size_t>(ecl_coarse_cell_get_k1(coarse_cell));
size_t k2 = static_cast<size_t>(ecl_coarse_cell_get_k2(coarse_cell));
size_t coarseningBoxIdx = grid->addCoarseningBox(i1, i2, j1, j2, k1, k2);
for (size_t k = k1; k <= k2; k++)
{
for (size_t j = j1; j <= j2; j++)
{
for (size_t i = i1; i <= i2; i++)
{
size_t cellIdx = grid->cellIndexFromIJK(i, j, k);
RigCell c = grid->cell(cellIdx);
c.setCoarseningBoxIndex(coarseningBoxIdx);
}
}
}
grid->addCoarseningBox(i1, i2, j1, j2, k1, k2);
}
}

View File

@ -472,7 +472,25 @@ size_t RigGridBase::addCoarseningBox(size_t i1, size_t i2, size_t j1, size_t j2,
m_coarseningBoxInfo.push_back(box);
return m_coarseningBoxInfo.size() - 1;
size_t coarseningBoxIndex = m_coarseningBoxInfo.size() - 1;
for (size_t k = k1; k <= k2; k++)
{
for (size_t j = j1; j <= j2; j++)
{
for (size_t i = i1; i <= i2; i++)
{
size_t cellIdx = this->cellIndexFromIJK(i, j, k);
RigCell& c = this->cell(cellIdx);
CVF_ASSERT(c.coarseningBoxIndex() == cvf::UNDEFINED_SIZE_T);
c.setCoarseningBoxIndex(coarseningBoxIndex);
}
}
}
return coarseningBoxIndex;
}
//--------------------------------------------------------------------------------------------------

View File

@ -65,7 +65,9 @@ public:
bool isMainGrid() const;
RigMainGrid* mainGrid() const { return m_mainGrid; }
size_t coarseningBoxCount() const { return m_coarseningBoxInfo.size(); }
size_t addCoarseningBox(size_t i1, size_t i2, size_t j1, size_t j2, size_t k1, size_t k2);
void coarseningBox(size_t coarseningBoxIndex, size_t* i1, size_t* i2, size_t* j1, size_t* j2, size_t* k1, size_t* k2) const;
protected:

View File

@ -254,6 +254,10 @@ void RigReservoirBuilderMock::populateReservoir(RigCaseData* eclipseCase)
{
activeCellInfo->setCellResultIndex(i, i);
}
// Add grid coarsening for main grid
eclipseCase->mainGrid()->addCoarseningBox(1, 2, 1, 3, 1, 4);
eclipseCase->mainGrid()->addCoarseningBox(3, 4, 4, 5, 5, 6);
}

View File

@ -247,3 +247,74 @@ public:
};
static bool RiaGetGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetGridDimensions>(RiaGetGridDimensions::commandName());
class RiaGetCoarseningInfo : public RiaSocketCommand
{
public:
static QString commandName () { return QString("GetCoarseningInfo"); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{
int argCaseGroupId = -1;
if (args.size() == 2)
{
argCaseGroupId = args[1].toInt();
}
RimCase* rimCase = server->findReservoir(argCaseGroupId);
if (!rimCase || !rimCase->reservoirData() || !rimCase->reservoirData()->mainGrid())
{
quint64 byteCount = 0;
socketStream << byteCount;
return true;
}
// Write data back to octave: I1, I2, J1, J2, K1, K2 for all coarsening boxes
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
{
size_t globalCoarseningBoxCount = 0;
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
{
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
globalCoarseningBoxCount += localCoarseningBoxCount;
}
quint64 byteCount = globalCoarseningBoxCount * 6 * sizeof(qint32);
socketStream << byteCount;
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
{
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
for (size_t boxIdx = 0; boxIdx < localCoarseningBoxCount; boxIdx++)
{
size_t i1, i2, j1, j2, k1, k2;
grid->coarseningBox(boxIdx, &i1, &i2, &j1, &j2, &k1, &k2);
// Write 1-based coordinates for coarsening box
socketStream << static_cast<qint32>(i1 + 1);
socketStream << static_cast<qint32>(i2 + 1);
socketStream << static_cast<qint32>(j1 + 1);
socketStream << static_cast<qint32>(j2 + 1);
socketStream << static_cast<qint32>(k1 + 1);
socketStream << static_cast<qint32>(k2 + 1);
}
}
}
return true;
}
};
static bool RiaGetCoarseningInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCoarseningInfo>(RiaGetCoarseningInfo::commandName());

View File

@ -52,6 +52,7 @@
#include "RigCaseCellResultsData.h"
#include "cafFactory.h"
#include "RigGridBase.h"
@ -469,7 +470,7 @@ public:
return true;
}
static void calculateMatrixModelActiveCellInfo(RimCase* reservoirCase, RifReaderInterface::PorosityModelResultType porosityModel, std::vector<qint32>& gridNumber, std::vector<qint32>& cellI, std::vector<qint32>& cellJ, std::vector<qint32>& cellK, std::vector<qint32>& parentGridNumber, std::vector<qint32>& hostCellI, std::vector<qint32>& hostCellJ, std::vector<qint32>& hostCellK, std::vector<qint32>& coarseBoxIdx)
static void calculateMatrixModelActiveCellInfo(RimCase* reservoirCase, RifReaderInterface::PorosityModelResultType porosityModel, std::vector<qint32>& gridNumber, std::vector<qint32>& cellI, std::vector<qint32>& cellJ, std::vector<qint32>& cellK, std::vector<qint32>& parentGridNumber, std::vector<qint32>& hostCellI, std::vector<qint32>& hostCellJ, std::vector<qint32>& hostCellK, std::vector<qint32>& globalCoarseningBoxIdx)
{
gridNumber.clear();
cellI.clear();
@ -479,7 +480,7 @@ public:
hostCellI.clear();
hostCellJ.clear();
hostCellK.clear();
coarseBoxIdx.clear();
globalCoarseningBoxIdx.clear();
if (!reservoirCase || !reservoirCase->reservoirData() || !reservoirCase->reservoirData()->mainGrid())
{
@ -497,10 +498,28 @@ public:
hostCellI.reserve(numMatrixModelActiveCells);
hostCellJ.reserve(numMatrixModelActiveCells);
hostCellK.reserve(numMatrixModelActiveCells);
coarseBoxIdx.reserve(numMatrixModelActiveCells);
globalCoarseningBoxIdx.reserve(numMatrixModelActiveCells);
const std::vector<RigCell>& globalCells = reservoirCase->reservoirData()->mainGrid()->cells();
std::vector<size_t> globalCoarseningBoxIndexStart;
{
size_t globalCoarseningBoxCount = 0;
for (size_t gridIdx = 0; gridIdx < reservoirCase->reservoirData()->gridCount(); gridIdx++)
{
globalCoarseningBoxIndexStart.push_back(globalCoarseningBoxCount);
RigGridBase* grid = reservoirCase->reservoirData()->grid(gridIdx);
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
globalCoarseningBoxCount += localCoarseningBoxCount;
}
}
for (size_t cIdx = 0; cIdx < globalCells.size(); ++cIdx)
{
if (actCellInfo->isActive(cIdx))
@ -543,11 +562,13 @@ public:
size_t coarseningIdx = globalCells[cIdx].coarseningBoxIndex();
if (coarseningIdx != cvf::UNDEFINED_SIZE_T)
{
coarseBoxIdx.push_back(static_cast<qint32>(coarseningIdx));
size_t globalCoarseningIdx = globalCoarseningBoxIndexStart[grid->gridIndex()] + coarseningIdx;
globalCoarseningBoxIdx.push_back(static_cast<qint32>(globalCoarseningIdx + 1)); // NB: 1-based index in Octave
}
else
{
coarseBoxIdx.push_back(-1);
globalCoarseningBoxIdx.push_back(-1);
}
}
}

View File

@ -12,6 +12,7 @@ set(CPP_SOURCES
riGetTimeStepDates.cpp
riGetTimeStepDays.cpp
riGetGridDimensions.cpp
riGetCoarseningInfo.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@ -113,6 +114,7 @@ else()
"${CMAKE_CURRENT_BINARY_DIR}/riGetTimeStepDates.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetTimeStepDays.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetGridDimensions.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCoarseningInfo.oct"
SOURCES ${CPP_SOURCES}
)

View File

@ -0,0 +1,127 @@
#include <QtNetwork>
#include <octave/oct.h>
#include "riSettings.h"
void getCoarseningInfo(int32NDArray& coarseningInfo, const QString &hostName, quint16 port, const qint64& caseId)
{
QString serverName = hostName;
quint16 serverPort = port;
const int Timeout = 5 * 1000;
QTcpSocket socket;
socket.connectToHost(serverName, serverPort);
if (!socket.waitForConnected(Timeout))
{
error((("Connection: ") + socket.errorString()).toLatin1().data());
return;
}
// Create command and send it:
QString command = QString("GetCoarseningInfo %1").arg(caseId);
QByteArray cmdBytes = command.toLatin1();
QDataStream socketStream(&socket);
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
socketStream << (qint64)(cmdBytes.size());
socket.write(cmdBytes);
// Get response. First wait for the header
while (socket.bytesAvailable() < (int)(sizeof(quint64)))
{
if (!socket.waitForReadyRead(Timeout))
{
error((("Waiting for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
quint64 byteCount;
socketStream >> byteCount;
quint64 boxCount = byteCount / (6 * sizeof(qint32));
dim_vector dv (1, 1);
dv(0) = 6;
dv(1) = boxCount;
coarseningInfo.resize(dv);
for (size_t i = 0; i < boxCount; i++)
{
qint32 i1;
qint32 i2;
qint32 j1;
qint32 j2;
qint32 k1;
qint32 k2;
socketStream >> i1;
socketStream >> i2;
socketStream >> j1;
socketStream >> j2;
socketStream >> k1;
socketStream >> k2;
coarseningInfo(0, i) = i1;
coarseningInfo(1, i) = i2;
coarseningInfo(2, i) = j1;
coarseningInfo(3, i) = j2;
coarseningInfo(4, i) = k1;
coarseningInfo(5, i) = k2;
}
return;
}
DEFUN_DLD (riGetCoarseningInfo, args, nargout,
"Usage:\n"
"\n"
" riGetCoarseningInfo([CaseId])\n"
"\n"
"This function returns all the coarse box definitions used in the grid.\n"
"The columns contain the following information:\n"
"[I1, I2, J1, J2, K1, K2]: 1-based index addresses of the min and max corners of the coarsening box.\n"
"If the CaseId is not defined, ResInsights Current Case is used.\n"
)
{
int nargin = args.length ();
if (nargin > 1)
{
error("riGetCoarseningInfo: Too many arguments. Only the name or index of the case is valid input.\n");
print_usage();
}
else if (nargout < 1)
{
error("riGetCoarseningInfo: Missing output argument.\n");
print_usage();
}
else
{
qint64 caseId = -1;
if (nargin > 0)
{
if (args(0).is_numeric_type())
{
unsigned int argCaseId = args(0).uint_value();
caseId = argCaseId;
}
}
int32NDArray coarseningInfo;
getCoarseningInfo(coarseningInfo, "127.0.0.1", 40001, caseId);
return octave_value(coarseningInfo);
}
return octave_value_list ();
}