mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added riGetActiveCellCenters
p4#: 21691
This commit is contained in:
parent
f0d315c55e
commit
e4bc6c9339
@ -375,3 +375,96 @@ public:
|
||||
};
|
||||
|
||||
static bool RiaGetCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCenters>(RiaGetCellCenters::commandName());
|
||||
|
||||
|
||||
class RiaGetActiveCellCenters : public RiaSocketCommand
|
||||
{
|
||||
public:
|
||||
static QString commandName () { return QString("GetActiveCellCenters"); }
|
||||
|
||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||
{
|
||||
int argCaseGroupId = -1;
|
||||
size_t argGridIndex = 0;
|
||||
QString porosityModelName;
|
||||
|
||||
if (args.size() == 2)
|
||||
{
|
||||
argGridIndex = args[1].toInt();
|
||||
}
|
||||
else if (args.size() == 3)
|
||||
{
|
||||
bool numberConversionOk = false;
|
||||
int tmpValue = args[2].toInt(&numberConversionOk);
|
||||
if (numberConversionOk)
|
||||
{
|
||||
// Two arguments, caseID and gridIndex
|
||||
argCaseGroupId = args[1].toInt();
|
||||
argGridIndex = args[2].toUInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Two arguments, gridIndex and porosity model
|
||||
argGridIndex = args[1].toUInt();
|
||||
porosityModelName = args[2];
|
||||
}
|
||||
}
|
||||
else if (args.size() > 3)
|
||||
{
|
||||
// Two arguments, caseID and gridIndex
|
||||
argCaseGroupId = args[1].toInt();
|
||||
argGridIndex = args[2].toUInt();
|
||||
porosityModelName = args[3];
|
||||
}
|
||||
|
||||
RifReaderInterface::PorosityModelResultType porosityModelEnum = RifReaderInterface::MATRIX_RESULTS;
|
||||
if (porosityModelName.toUpper() == "FRACTURE")
|
||||
{
|
||||
porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS;
|
||||
}
|
||||
|
||||
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
||||
if (!rimCase || !rimCase->reservoirData() || (argGridIndex >= rimCase->reservoirData()->gridCount()) )
|
||||
{
|
||||
// No data available
|
||||
socketStream << (quint64)0 << (quint64)0 ;
|
||||
return true;
|
||||
}
|
||||
|
||||
RigActiveCellInfo* actCellInfo = rimCase->reservoirData()->activeCellInfo(porosityModelEnum);
|
||||
|
||||
RigGridBase* rigGrid = rimCase->reservoirData()->grid(argGridIndex);
|
||||
|
||||
std::vector<double> cellCenterValues(rigGrid->cellCount() * 3);
|
||||
|
||||
size_t cellCenterIndex = 0;
|
||||
for (size_t localGridCellIdx = 0; localGridCellIdx < rigGrid->cellCount(); localGridCellIdx++)
|
||||
{
|
||||
size_t globalCellIdx = rigGrid->globalGridCellIndex(localGridCellIdx);
|
||||
if (!actCellInfo->isActive(globalCellIdx)) continue;
|
||||
|
||||
RigCell& c = rigGrid->cell(localGridCellIdx);
|
||||
cvf::Vec3d center = c.center();
|
||||
|
||||
cellCenterValues[cellCenterIndex * 3 + 0] = center.x();
|
||||
cellCenterValues[cellCenterIndex * 3 + 1] = center.y();
|
||||
cellCenterValues[cellCenterIndex * 3 + 2] = center.z();
|
||||
|
||||
cellCenterIndex++;
|
||||
}
|
||||
|
||||
quint64 activeCellCount = cellCenterIndex;
|
||||
cellCenterValues.resize(cellCenterIndex * 3);
|
||||
|
||||
socketStream << activeCellCount;
|
||||
quint64 byteCount = activeCellCount * 3 * sizeof(double);
|
||||
socketStream << byteCount;
|
||||
|
||||
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static bool RiaGetActiveCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellCenters>(RiaGetActiveCellCenters::commandName());
|
||||
|
@ -14,6 +14,7 @@ set(CPP_SOURCES
|
||||
riGetGridDimensions.cpp
|
||||
riGetCoarseningInfo.cpp
|
||||
riGetCellCenters.cpp
|
||||
riGetActiveCellCenters.cpp
|
||||
)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
@ -117,6 +118,7 @@ else()
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetGridDimensions.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCoarseningInfo.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetCellCenters.oct"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/riGetActiveCellCenters.oct"
|
||||
|
||||
SOURCES ${CPP_SOURCES}
|
||||
)
|
||||
|
163
OctavePlugin/riGetActiveCellCenters.cpp
Normal file
163
OctavePlugin/riGetActiveCellCenters.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
#include <QtNetwork>
|
||||
#include <octave/oct.h>
|
||||
|
||||
#include "riSettings.h"
|
||||
|
||||
|
||||
void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex, const QString& porosityModel)
|
||||
{
|
||||
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("GetActiveCellCenters %1 %2 %3").arg(caseId).arg(gridIndex).arg(porosityModel);
|
||||
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 activeCellCount;
|
||||
quint64 byteCount;
|
||||
|
||||
socketStream >> activeCellCount;
|
||||
socketStream >> byteCount;
|
||||
|
||||
dim_vector dv (1, 1);
|
||||
dv(0) = 3;
|
||||
dv(1) = activeCellCount;
|
||||
|
||||
cellCenterValues.resize(dv);
|
||||
|
||||
if (!(byteCount && activeCellCount))
|
||||
{
|
||||
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 << "Active cell count: " << activeCellCount << std::endl;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEFUN_DLD (riGetActiveCellCenters, args, nargout,
|
||||
"Usage:\n"
|
||||
"\n"
|
||||
" riGetActiveCellCenters([CaseId], GridIndex, [PorosityModel = “Matrix”|”Fracture”] )\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, ResInsight’s Current Case is used.\n"
|
||||
)
|
||||
{
|
||||
|
||||
if (nargout < 1)
|
||||
{
|
||||
error("riGetActiveCellCenters: Missing output argument.\n");
|
||||
print_usage();
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
||||
int nargin = args.length ();
|
||||
if (nargin < 1)
|
||||
{
|
||||
error("riGetActiveCellCenters: Too few arguments. The grid index argument is required.\n");
|
||||
print_usage();
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
||||
if (nargin > 3)
|
||||
{
|
||||
error("riGetActiveCellCenters: Too many arguments.\n");
|
||||
print_usage();
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
||||
qint32 caseId = -1;
|
||||
quint32 gridIndex = 0;
|
||||
std::string porosityModel = "Matrix";
|
||||
|
||||
if (nargin == 1)
|
||||
{
|
||||
gridIndex = args(0).uint_value();
|
||||
}
|
||||
else if (nargin == 2)
|
||||
{
|
||||
if (args(0).is_numeric_type() && args(1).is_numeric_type())
|
||||
{
|
||||
caseId = args(0).uint_value();
|
||||
gridIndex = args(1).uint_value();
|
||||
}
|
||||
else
|
||||
{
|
||||
gridIndex = args(0).uint_value();
|
||||
porosityModel = args(1).string_value();
|
||||
}
|
||||
}
|
||||
else if (nargin == 3)
|
||||
{
|
||||
caseId = args(0).uint_value();
|
||||
gridIndex = args(1).uint_value();
|
||||
porosityModel = args(2).string_value();
|
||||
}
|
||||
|
||||
if (porosityModel != "Matrix" && porosityModel != "Fracture")
|
||||
{
|
||||
error("riGetActiveCellProperty: The value for \"PorosityModel\" is unknown. Please use either \"Matrix\" or \"Fracture\"\n");
|
||||
print_usage();
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
||||
NDArray cellCenterValues;
|
||||
getActiveCellCenters(cellCenterValues, "127.0.0.1", 40001, caseId, gridIndex, porosityModel.c_str());
|
||||
|
||||
return octave_value(cellCenterValues);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16
|
||||
DEFUN_DLD (riGetCellCenters, args, nargout,
|
||||
"Usage:\n"
|
||||
"\n"
|
||||
" riGetActiveCellInfo([CaseId], GridIndex )\n"
|
||||
" riGetCellCenters([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, ResInsight’s Current Case is used.\n"
|
||||
|
Loading…
Reference in New Issue
Block a user