Added getCellCenters

p4#: 21688
This commit is contained in:
Magne Sjaastad 2013-05-22 08:11:39 +02:00
parent 8a6234690c
commit 4b7ff209f6
4 changed files with 203 additions and 2 deletions

View File

@ -256,8 +256,13 @@ void RigReservoirBuilderMock::populateReservoir(RigCaseData* eclipseCase)
}
// Add grid coarsening for main grid
eclipseCase->mainGrid()->addCoarseningBox(1, 2, 1, 3, 1, 4);
eclipseCase->mainGrid()->addCoarseningBox(3, 4, 4, 5, 5, 6);
if (cellDimension().x() > 4 &&
cellDimension().y() > 5 &&
cellDimension().z() > 6)
{
eclipseCase->mainGrid()->addCoarseningBox(1, 2, 1, 3, 1, 4);
eclipseCase->mainGrid()->addCoarseningBox(3, 4, 4, 5, 5, 6);
}
}

View File

@ -32,6 +32,8 @@
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include <QTcpSocket>
class RiaGetTimeStepDates : public RiaSocketCommand
{
@ -318,3 +320,58 @@ public:
};
static bool RiaGetCoarseningInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCoarseningInfo>(RiaGetCoarseningInfo::commandName());
class RiaGetCellCenters : public RiaSocketCommand
{
public:
static QString commandName () { return QString("GetCellCenters"); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{
int argCaseGroupId = -1;
size_t argGridIndex = 0;
if (args.size() == 2)
{
argGridIndex = args[1].toInt();
}
else if (args.size() == 3)
{
argCaseGroupId = args[1].toInt();
argGridIndex = args[2].toUInt();
}
RimCase* rimCase = server->findReservoir(argCaseGroupId);
if (!rimCase || !rimCase->reservoirData() || (argGridIndex >= rimCase->reservoirData()->gridCount()) )
{
// No data available
socketStream << (quint64)0 << (quint64)0 ;
return true;
}
RigGridBase* rigGrid = rimCase->reservoirData()->grid(argGridIndex);
quint64 cellCount = (quint64)rigGrid->cellCount();
std::vector<double> cellCenterValues(cellCount * 3);
for (size_t i = 0; i < cellCount; i++)
{
cvf::Vec3d center = rigGrid->cell(i).center();
cellCenterValues[i * 3 + 0] = center.x();
cellCenterValues[i * 3 + 1] = center.y();
cellCenterValues[i * 3 + 2] = center.z();
}
socketStream << cellCount;
quint64 byteCount = cellCount * 3 * sizeof(double);
socketStream << byteCount;
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
return true;
}
};
static bool RiaGetCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCenters>(RiaGetCellCenters::commandName());

View File

@ -13,6 +13,7 @@ set(CPP_SOURCES
riGetTimeStepDays.cpp
riGetGridDimensions.cpp
riGetCoarseningInfo.cpp
riGetCellCenters.cpp
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@ -115,6 +116,7 @@ else()
"${CMAKE_CURRENT_BINARY_DIR}/riGetTimeStepDays.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetGridDimensions.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCoarseningInfo.oct"
"${CMAKE_CURRENT_BINARY_DIR}/riGetCellCenters.oct"
SOURCES ${CPP_SOURCES}
)

View File

@ -0,0 +1,137 @@
#include <QtNetwork>
#include <octave/oct.h>
#include "riSettings.h"
void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex)
{
QString serverName = hostName;
quint16 serverPort = port;
const int timeout = riOctavePlugin::timeOutMilliSecs;
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("GetCellCenters %1 %2").arg(caseId).arg(gridIndex);
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)(2 * sizeof(quint64)))
{
if (!socket.waitForReadyRead(timeout))
{
error((("Wating for header: ") + socket.errorString()).toLatin1().data());
return;
}
}
// Read timestep count and blocksize
quint64 cellCount;
quint64 byteCount;
socketStream >> cellCount;
socketStream >> byteCount;
dim_vector dv (1, 1);
dv(0) = 3;
dv(1) = cellCount;
cellCenterValues.resize(dv);
if (!(byteCount && cellCount))
{
error ("Could not find the requested data in ResInsight");
return;
}
// Wait for available data for each column, then read data for each column
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(timeout))
{
error((("Waiting for data: ") + socket.errorString()).toLatin1().data());
return;
}
OCTAVE_QUIT;
}
quint64 bytesRead = 0;
double* internalMatrixData = cellCenterValues.fortran_vec();
bytesRead = socket.read((char*)(internalMatrixData), byteCount);
if (byteCount != bytesRead)
{
error("Could not read binary double data properly from socket");
octave_stdout << "Cell count: " << cellCount << std::endl;
}
return;
}
DEFUN_DLD (riGetCellCenters, args, nargout,
"Usage:\n"
"\n"
" riGetActiveCellInfo([CaseId], GridIndex )\n"
"\n"
"This function returns the UTM coordinates (X, Y, Z) of the center point of all the cells in the grid.\n"
"If the CaseId is not defined, ResInsights Current Case is used.\n"
)
{
int nargin = args.length ();
if (nargin > 2)
{
error("riGetCellCenters: Too many arguments. CaseId is optional input argument.\n");
print_usage();
}
else if (nargout < 1)
{
error("riGetCellCenters: Missing output argument.\n");
print_usage();
}
else
{
NDArray cellCenterValues;
qint32 caseId = -1;
quint32 gridIndex = 0;
if (nargin == 1)
{
gridIndex = args(0).uint_value();
}
else if (nargin == 2)
{
unsigned int argCaseId = args(0).uint_value();
caseId = argCaseId;
gridIndex = args(1).uint_value();
}
getCellCenters(cellCenterValues, "127.0.0.1", 40001, caseId, gridIndex);
return octave_value(cellCenterValues);
}
return octave_value();
}