From af6d92d64eb5c0f0d42ccb092f43593064725212 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 13:02:52 +0200 Subject: [PATCH] Added flag to control how to do IO with sockets --- .../Application/RiaPreferences.cpp | 2 + ApplicationCode/Application/RiaPreferences.h | 2 + .../SocketInterface/RiaGeometryCommands.cpp | 68 ++++++++++++++----- .../RiaPropertyDataCommands.cpp | 61 +++++++++++++---- 4 files changed, 103 insertions(+), 30 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 19454642f1..bd065e418c 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -59,6 +59,8 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&autocomputeSOIL, "autocomputeSOIL", true, "SOIL", "", "SOIL = 1.0 - SGAS - SWAT", ""); CAF_PDM_InitField(&autocomputeDepthRelatedProperties,"autocomputeDepth", true, "DEPTH related properties", "", "DEPTH, DX, DY, DZ, TOP, BOTTOM", ""); + + CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 0f87fecc17..f877efdbb4 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -59,6 +59,8 @@ public: // Pdm Fields caf::PdmField autocomputeDepthRelatedProperties; + caf::PdmField useStreamTransfer; + protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 2ec5878cb6..413f4791bc 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -34,6 +34,8 @@ #include "RigCaseCellResultsData.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -241,32 +243,66 @@ public: // dv(3) = 8; // dv(4) = 3; - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + cvf::Timer timer; + + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + cvf::Vec3d cornerVerts[8]; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + socketStream << cornerVerts[cornerIndexMapping][coordIdx]; + } } } } } } + else + { + std::vector cellCornerValues(doubleValueCount); + cvf::Vec3d cornerVerts[8]; + quint64 coordCount = 0; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) + { + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + { + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + } + } + } + } + } + server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + } + + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); return true; } diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index f31218d7e3..4fa6a4f841 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -40,6 +40,8 @@ #include "Rim3dOverlayInfoConfig.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -305,30 +307,61 @@ public: socketStream << timestepCount; size_t valueIdx = 0; - - std::vector values(rigGrid->cellCount()); + cvf::Timer timer; - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cellValue = 0.0; + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + + socketStream << cellValue; + } + } + } + else + { + + std::vector values(rigGrid->cellCount()); + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + { + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) + { + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + values[valueIdx++] = cellValue; } - values[cellIdx] = cellValue; } server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); } + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); + return true; } };