mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added block write to socket tools
This commit is contained in:
parent
7a07b2926e
commit
e5248683f0
@ -61,6 +61,7 @@ RiaPreferences::RiaPreferences(void)
|
|||||||
|
|
||||||
CAF_PDM_InitField(&readFaultData, "readFaultData", true, "Read fault data", "", "", "");
|
CAF_PDM_InitField(&readFaultData, "readFaultData", true, "Read fault data", "", "", "");
|
||||||
CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", "");
|
CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", "");
|
||||||
|
CAF_PDM_InitField(&blockSize, "blockSize", 10000, "blockSize", "", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -61,6 +61,7 @@ public: // Pdm Fields
|
|||||||
caf::PdmField<bool> readFaultData;
|
caf::PdmField<bool> readFaultData;
|
||||||
|
|
||||||
caf::PdmField<bool> useStreamTransfer;
|
caf::PdmField<bool> useStreamTransfer;
|
||||||
|
caf::PdmField<int> blockSize;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
|
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
|
||||||
|
@ -16,9 +16,12 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RiaStdInclude.h"
|
#include "RiaStdInclude.h"
|
||||||
|
|
||||||
#include "RiaSocketCommand.h"
|
#include "RiaSocketCommand.h"
|
||||||
#include "RiaSocketServer.h"
|
#include "RiaSocketServer.h"
|
||||||
#include "RiaSocketTools.h"
|
#include "RiaSocketTools.h"
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
#include "RiaPreferences.h"
|
||||||
|
|
||||||
#include "RimReservoirView.h"
|
#include "RimReservoirView.h"
|
||||||
#include "RimResultSlot.h"
|
#include "RimResultSlot.h"
|
||||||
@ -28,8 +31,8 @@
|
|||||||
#include "RimWellCollection.h"
|
#include "RimWellCollection.h"
|
||||||
#include "Rim3dOverlayInfoConfig.h"
|
#include "Rim3dOverlayInfoConfig.h"
|
||||||
#include "RimReservoirCellResultsCacher.h"
|
#include "RimReservoirCellResultsCacher.h"
|
||||||
|
|
||||||
#include "RimCase.h"
|
#include "RimCase.h"
|
||||||
|
|
||||||
#include "RigCaseData.h"
|
#include "RigCaseData.h"
|
||||||
#include "RigCaseCellResultsData.h"
|
#include "RigCaseCellResultsData.h"
|
||||||
|
|
||||||
@ -37,6 +40,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
/// OBSOLETE, to be deleted
|
/// OBSOLETE, to be deleted
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -133,7 +137,8 @@ public:
|
|||||||
for (size_t tIdx = 0; tIdx < columnCount; ++tIdx)
|
for (size_t tIdx = 0; tIdx < columnCount; ++tIdx)
|
||||||
{
|
{
|
||||||
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
||||||
server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount);
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo[tIdx].data(), timestepByteCount);
|
||||||
|
|
||||||
#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well
|
#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well
|
||||||
for (size_t cIdx = 0; cIdx < activeCellInfo[tIdx].size(); ++cIdx)
|
for (size_t cIdx = 0; cIdx < activeCellInfo[tIdx].size(); ++cIdx)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "RiaPreferences.h"
|
#include "RiaPreferences.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -108,7 +109,7 @@ public:
|
|||||||
|
|
||||||
CVF_ASSERT(coordCount == doubleValueCount);
|
CVF_ASSERT(coordCount == doubleValueCount);
|
||||||
|
|
||||||
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -181,7 +182,7 @@ public:
|
|||||||
quint64 byteCount = doubleValueCount * sizeof(double);
|
quint64 byteCount = doubleValueCount * sizeof(double);
|
||||||
socketStream << byteCount;
|
socketStream << byteCount;
|
||||||
|
|
||||||
server->currentClient()->write((const char *)cellCenterValues.data(), byteCount);
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -296,7 +297,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server->currentClient()->write((const char *)cellCornerValues.data(), byteCount);
|
|
||||||
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
double totalTimeMS = timer.time() * 1000.0;
|
double totalTimeMS = timer.time() * 1000.0;
|
||||||
@ -381,7 +383,7 @@ public:
|
|||||||
quint64 byteCount = doubleValueCount * sizeof(double);
|
quint64 byteCount = doubleValueCount * sizeof(double);
|
||||||
socketStream << byteCount;
|
socketStream << byteCount;
|
||||||
|
|
||||||
server->currentClient()->write((const char *)cellCornerValues.data(), byteCount);
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,6 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<double> values(rigGrid->cellCount());
|
|
||||||
for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++)
|
for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++)
|
||||||
{
|
{
|
||||||
cvf::ref<cvf::StructGridScalarDataAccess> cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex);
|
cvf::ref<cvf::StructGridScalarDataAccess> cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex);
|
||||||
@ -343,6 +342,7 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<double> values(rigGrid->cellCount());
|
||||||
for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++)
|
for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++)
|
||||||
{
|
{
|
||||||
double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx);
|
double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx);
|
||||||
@ -352,9 +352,8 @@ public:
|
|||||||
}
|
}
|
||||||
values[valueIdx++] = cellValue;
|
values[valueIdx++] = cellValue;
|
||||||
}
|
}
|
||||||
|
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double totalTimeMS = timer.time() * 1000.0;
|
double totalTimeMS = timer.time() * 1000.0;
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RiaStdInclude.h"
|
#include "RiaStdInclude.h"
|
||||||
|
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
#include "RiaPreferences.h"
|
||||||
|
|
||||||
#include "RiaSocketTools.h"
|
#include "RiaSocketTools.h"
|
||||||
#include "RiaSocketServer.h"
|
#include "RiaSocketServer.h"
|
||||||
#include "RimCase.h"
|
#include "RimCase.h"
|
||||||
@ -34,6 +38,8 @@
|
|||||||
|
|
||||||
#include "RimInputPropertyCollection.h"
|
#include "RimInputPropertyCollection.h"
|
||||||
|
|
||||||
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@ -98,4 +104,45 @@ void RiaSocketTools::getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QStri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite)
|
||||||
|
{
|
||||||
|
cvf::Timer timer;
|
||||||
|
|
||||||
|
quint64 bytesWritten = 0;
|
||||||
|
int blockCount = 0;
|
||||||
|
|
||||||
|
quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize();
|
||||||
|
|
||||||
|
while (bytesWritten < bytesToWrite)
|
||||||
|
{
|
||||||
|
quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize);
|
||||||
|
|
||||||
|
quint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite);
|
||||||
|
if (actuallyBytesWritten == -1)
|
||||||
|
{
|
||||||
|
if (server)
|
||||||
|
{
|
||||||
|
QString errorMessage = "Error detected when writing data, error string from socket : \n" + socket->errorString();
|
||||||
|
|
||||||
|
server->errorMessageDialog()->showMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesWritten += actuallyBytesWritten;
|
||||||
|
|
||||||
|
blockCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server)
|
||||||
|
{
|
||||||
|
double totalTimeMS = timer.time() * 1000.0;
|
||||||
|
QString resultInfo = QString("Total time '%1 ms'\nTotal bytes written . %2\nNumber of blocks : %3\nBlock size : %4").arg(totalTimeMS).arg(bytesWritten).arg(blockCount).arg(maxBlockSize);
|
||||||
|
|
||||||
|
server->errorMessageDialog()->showMessage(resultInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
class RimCase;
|
class RimCase;
|
||||||
class RiaSocketServer;
|
class RiaSocketServer;
|
||||||
|
class QTcpSocket;
|
||||||
|
|
||||||
#define PMonLog( MessageString ) RiuMainWindow::instance()->processMonitor()->addStringToLog( MessageString );
|
#define PMonLog( MessageString ) RiuMainWindow::instance()->processMonitor()->addStringToLog( MessageString );
|
||||||
|
|
||||||
@ -25,4 +26,6 @@ class RiaSocketTools
|
|||||||
public:
|
public:
|
||||||
static RimCase* findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args);
|
static RimCase* findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args);
|
||||||
static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);
|
static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);
|
||||||
|
|
||||||
|
static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user