2013-05-22 02:54:39 -05:00
|
|
|
|
#include <QtNetwork>
|
2014-04-03 03:41:27 -05:00
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
2013-05-22 02:54:39 -05:00
|
|
|
|
#include <octave/oct.h>
|
|
|
|
|
|
|
|
|
|
#include "riSettings.h"
|
2014-04-15 07:16:35 -05:00
|
|
|
|
#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration
|
2013-05-22 02:54:39 -05:00
|
|
|
|
|
|
|
|
|
|
2013-05-24 02:54:32 -05:00
|
|
|
|
void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel)
|
2013-05-22 02:54:39 -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))
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Connection: %s",socket.errorString().toLatin1().data());
|
2013-05-22 02:54:39 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create command and send it:
|
|
|
|
|
|
2013-05-24 02:54:32 -05:00
|
|
|
|
QString command = QString("GetActiveCellCenters %1 %2").arg(caseId).arg(porosityModel);
|
2013-05-22 02:54:39 -05:00
|
|
|
|
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)))
|
|
|
|
|
{
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for header: %s",socket.errorString().toLatin1().data());
|
2013-05-22 02:54:39 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read timestep count and blocksize
|
|
|
|
|
|
|
|
|
|
quint64 activeCellCount;
|
|
|
|
|
quint64 byteCount;
|
|
|
|
|
|
|
|
|
|
socketStream >> activeCellCount;
|
|
|
|
|
socketStream >> byteCount;
|
|
|
|
|
|
|
|
|
|
if (!(byteCount && activeCellCount))
|
|
|
|
|
{
|
|
|
|
|
error ("Could not find the requested data in ResInsight");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 01:48:36 -05:00
|
|
|
|
dim_vector dv;
|
|
|
|
|
dv.resize(2);
|
|
|
|
|
dv(0) = activeCellCount;
|
|
|
|
|
dv(1) = 3;
|
|
|
|
|
|
|
|
|
|
cellCenterValues.resize(dv);
|
|
|
|
|
|
2014-04-03 03:41:27 -05:00
|
|
|
|
double* internalMatrixData = cellCenterValues.fortran_vec();
|
|
|
|
|
QStringList errorMessages;
|
2014-04-15 07:16:35 -05:00
|
|
|
|
|
|
|
|
|
if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages))
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
2014-04-03 03:41:27 -05:00
|
|
|
|
for (int i = 0; i < errorMessages.size(); i++)
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("%s",errorMessages[i].toLatin1().data());
|
2013-05-22 02:54:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 03:41:27 -05:00
|
|
|
|
OCTAVE_QUIT;
|
2013-05-22 02:54:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN_DLD (riGetActiveCellCenters, args, nargout,
|
|
|
|
|
"Usage:\n"
|
|
|
|
|
"\n"
|
2013-05-24 02:54:32 -05:00
|
|
|
|
" riGetActiveCellCenters([CaseId], [PorosityModel = <20>Matrix<69>|<7C>Fracture<72>] )\n"
|
2013-05-22 02:54:39 -05:00
|
|
|
|
"\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<68>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 ();
|
2013-05-24 02:54:32 -05:00
|
|
|
|
if (nargin > 2)
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
|
|
|
|
error("riGetActiveCellCenters: Too many arguments.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
return octave_value_list ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint32 caseId = -1;
|
|
|
|
|
std::string porosityModel = "Matrix";
|
|
|
|
|
|
|
|
|
|
if (nargin == 1)
|
|
|
|
|
{
|
2019-01-15 00:28:50 -06:00
|
|
|
|
if (riOctavePlugin::isOctaveValueNumeric(args(0)))
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
|
|
|
|
caseId = args(0).uint_value();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-24 02:54:32 -05:00
|
|
|
|
porosityModel = args(0).string_value();
|
2013-05-22 02:54:39 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-24 02:54:32 -05:00
|
|
|
|
else if (nargin == 2)
|
2013-05-22 02:54:39 -05:00
|
|
|
|
{
|
2019-01-15 00:28:50 -06:00
|
|
|
|
if (riOctavePlugin::isOctaveValueNumeric(args(0)))
|
2013-05-24 02:54:32 -05:00
|
|
|
|
{
|
|
|
|
|
caseId = args(0).uint_value();
|
|
|
|
|
porosityModel = args(1).string_value();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
caseId = args(1).uint_value();
|
|
|
|
|
porosityModel = args(0).string_value();
|
|
|
|
|
}
|
2013-05-22 02:54:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2013-05-24 02:54:32 -05:00
|
|
|
|
getActiveCellCenters(cellCenterValues, "127.0.0.1", 40001, caseId, porosityModel.c_str());
|
2013-05-22 02:54:39 -05:00
|
|
|
|
|
|
|
|
|
return octave_value(cellCenterValues);
|
|
|
|
|
}
|
|
|
|
|
|