2012-05-18 02:45:23 -05:00
|
|
|
|
#include <QtNetwork>
|
2014-04-03 04:09:42 -05:00
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
|
#include <octave/oct.h>
|
2013-05-15 08:23:45 -05:00
|
|
|
|
#include "riSettings.h"
|
2014-04-15 07:03:41 -05:00
|
|
|
|
#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration
|
2013-05-15 08:23:45 -05:00
|
|
|
|
|
|
|
|
|
void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, quint16 port, const qint64& caseId, const QString& porosityModel)
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
|
|
|
|
QString serverName = hostName;
|
|
|
|
|
quint16 serverPort = port;
|
|
|
|
|
|
|
|
|
|
QTcpSocket socket;
|
|
|
|
|
socket.connectToHost(serverName, serverPort);
|
|
|
|
|
|
2013-08-12 04:38:09 -05:00
|
|
|
|
if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs))
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Connection: %s",socket.errorString().toLatin1().data());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create command and send it:
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
QString command = QString("GetActiveCellInfo %1 %2").arg(caseId).arg(porosityModel);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
QByteArray cmdBytes = command.toLatin1();
|
|
|
|
|
|
|
|
|
|
QDataStream socketStream(&socket);
|
2013-05-22 02:18:57 -05:00
|
|
|
|
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
|
|
socketStream << (qint64)(cmdBytes.size());
|
|
|
|
|
socket.write(cmdBytes);
|
|
|
|
|
|
|
|
|
|
// Get response. First wait for the header
|
|
|
|
|
|
|
|
|
|
while (socket.bytesAvailable() < (int)(2*sizeof(quint64)))
|
|
|
|
|
{
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for header: %s",socket.errorString().toLatin1().data());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read timestep count and blocksize
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
quint64 columnCount;
|
2014-04-03 04:09:42 -05:00
|
|
|
|
quint64 byteCountForOneTimestep;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
size_t activeCellCount;
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
socketStream >> columnCount;
|
2014-04-03 04:09:42 -05:00
|
|
|
|
socketStream >> byteCountForOneTimestep;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
2014-04-03 04:09:42 -05:00
|
|
|
|
activeCellCount = byteCountForOneTimestep / sizeof(qint32);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
2013-04-03 02:24:33 -05:00
|
|
|
|
dim_vector dv (2, 1);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
dv(0) = activeCellCount;
|
2013-05-15 08:23:45 -05:00
|
|
|
|
dv(1) = columnCount;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
activeCellInfo.resize(dv);
|
|
|
|
|
|
2014-04-03 04:09:42 -05:00
|
|
|
|
if (!(byteCountForOneTimestep && columnCount))
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
|
|
|
|
error ("Could not find the requested data in ResInsight");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 04:09:42 -05:00
|
|
|
|
qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data();
|
|
|
|
|
QStringList errorMessages;
|
2014-04-15 07:03:41 -05:00
|
|
|
|
if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages))
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2014-04-03 04:09:42 -05:00
|
|
|
|
for (int i = 0; i < errorMessages.size(); i++)
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("%s",errorMessages[i].toLatin1().data());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCTAVE_QUIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString tmp = QString("riGetActiveCellInfo : Read active cell info");
|
2013-05-15 08:23:45 -05:00
|
|
|
|
if (caseId < 0)
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2013-05-15 08:23:45 -05:00
|
|
|
|
tmp += QString(" from current case.");
|
2012-05-18 02:45:23 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-15 08:23:45 -05:00
|
|
|
|
tmp += QString(" from caseID: %1.").arg(caseId);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
octave_stdout << tmp.toStdString() << " Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN_DLD (riGetActiveCellInfo, args, nargout,
|
|
|
|
|
"Usage:\n"
|
|
|
|
|
"\n"
|
2013-05-15 08:23:45 -05:00
|
|
|
|
" riGetActiveCellInfo([CaseId], [PorosityModel = <20>Matrix<69>|<7C>Fracture<72>] )\n"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
"\n"
|
2013-05-15 08:23:45 -05:00
|
|
|
|
"This function returns a two dimensional matrix containing grid and IJK information\n"
|
|
|
|
|
"for each of the active cells in the requested case.\n"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
"The columns contain the following information:\n"
|
2013-05-15 08:23:45 -05:00
|
|
|
|
"[GridIdx, I, J, K, ParentGridIdx, PI, PJ, PK, CoarseBoxIdx]\n"
|
|
|
|
|
" GridIdx : The index of the grid the cell resides in. (Main grid has index 0)\n"
|
|
|
|
|
" I, J, K : 1-based index address of the cell in the grid.\n"
|
|
|
|
|
" ParentGridIdx : The index to the grid that this cell's grid is residing in.\n"
|
|
|
|
|
" PI, PJ, PK : 1-based address of the parent grid cell that this cell is a part of.\n"
|
|
|
|
|
" CoarseBoxIdx : Coarsening box index, -1 if none.\n"
|
|
|
|
|
"If the CaseId is not defined, ResInsight<68>s Current Case is used. If PorosityModel is not defined, <20>Matrix<69> is used.\n"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
int nargin = args.length ();
|
2013-05-15 08:23:45 -05:00
|
|
|
|
if (nargin > 2)
|
2012-05-18 02:45:23 -05:00
|
|
|
|
{
|
2013-05-15 08:23:45 -05:00
|
|
|
|
error("riGetActiveCellInfo: Too many arguments. CaseId and PorosityModel are optional input arguments.\n");
|
2012-05-18 02:45:23 -05:00
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else if (nargout < 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetActiveCellInfo: Missing output argument.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int32NDArray propertyFrames;
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
qint64 caseId = -1;
|
|
|
|
|
QString porosityModel = "Matrix";
|
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
|
if (nargin > 0)
|
2013-05-15 08:23:45 -05:00
|
|
|
|
{
|
2019-01-15 00:28:50 -06:00
|
|
|
|
if (riOctavePlugin::isOctaveValueNumeric(args(0)))
|
2013-05-15 08:23:45 -05:00
|
|
|
|
{
|
|
|
|
|
unsigned int argCaseId = args(0).uint_value();
|
|
|
|
|
caseId = argCaseId;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
porosityModel = args(0).char_matrix_value().row_as_string(0).c_str();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nargin > 1)
|
|
|
|
|
{
|
2019-01-15 00:28:50 -06:00
|
|
|
|
if (riOctavePlugin::isOctaveValueNumeric(args(1)))
|
2013-05-15 08:23:45 -05:00
|
|
|
|
{
|
|
|
|
|
unsigned int argCaseId = args(1).uint_value();
|
|
|
|
|
caseId = argCaseId;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
porosityModel = args(1).char_matrix_value().row_as_string(0).c_str();
|
|
|
|
|
}
|
2013-09-27 09:25:40 -05:00
|
|
|
|
}
|
2013-05-15 08:23:45 -05:00
|
|
|
|
|
|
|
|
|
getActiveCellInfo(propertyFrames, "127.0.0.1", 40001, caseId, porosityModel);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
|
|
return octave_value(propertyFrames);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-15 08:23:45 -05:00
|
|
|
|
return octave_value();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
}
|
|
|
|
|
|