mirror of
https://github.com/OPM/ResInsight.git
synced 2026-09-03 20:53:13 -05:00
Moved socket commands into files grouped by case info, geometry, project info and property data
p4#: 21712
This commit is contained in:
@@ -50,7 +50,11 @@ set( USER_INTERFACE_FILES
|
|||||||
|
|
||||||
set( SOCKET_INTERFACE_FILES
|
set( SOCKET_INTERFACE_FILES
|
||||||
SocketInterface/RiaSocketServer.cpp
|
SocketInterface/RiaSocketServer.cpp
|
||||||
SocketInterface/RiaSocketCommands.cpp
|
SocketInterface/RiaProjectInfoCommands.cpp
|
||||||
|
SocketInterface/RiaCaseInfoCommands.cpp
|
||||||
|
SocketInterface/RiaGeometryCommands.cpp
|
||||||
|
SocketInterface/RiaPropertyDataCommands.cpp
|
||||||
|
SocketInterface/RiaSocketTools.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,550 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RiaStdInclude.h"
|
||||||
|
#include "RiaSocketCommand.h"
|
||||||
|
#include "RiaSocketServer.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
|
#include "RimReservoirView.h"
|
||||||
|
#include "RimResultSlot.h"
|
||||||
|
#include "RimCellEdgeResultSlot.h"
|
||||||
|
#include "RimCellRangeFilterCollection.h"
|
||||||
|
#include "RimCellPropertyFilterCollection.h"
|
||||||
|
#include "RimWellCollection.h"
|
||||||
|
#include "Rim3dOverlayInfoConfig.h"
|
||||||
|
#include "RimReservoirCellResultsCacher.h"
|
||||||
|
|
||||||
|
#include "RimCase.h"
|
||||||
|
#include "RigCaseData.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
|
|
||||||
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// OBSOLETE, to be deleted
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetMainGridDimensions: public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetMainGridDimensions"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
|
||||||
|
RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
|
||||||
|
if (!rimCase) return true;
|
||||||
|
|
||||||
|
// Write data back to octave: I, J, K dimensions
|
||||||
|
|
||||||
|
size_t iCount = 0;
|
||||||
|
size_t jCount = 0;
|
||||||
|
size_t kCount = 0;
|
||||||
|
|
||||||
|
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
iCount = rimCase->reservoirData()->mainGrid()->cellCountI();
|
||||||
|
jCount = rimCase->reservoirData()->mainGrid()->cellCountJ();
|
||||||
|
kCount = rimCase->reservoirData()->mainGrid()->cellCountK();
|
||||||
|
}
|
||||||
|
|
||||||
|
socketStream << (quint64)iCount << (quint64)jCount << (quint64)kCount;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetMainGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetMainGridDimensions>(RiaGetMainGridDimensions::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetActiveCellInfo: public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetActiveCellInfo"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
|
||||||
|
if (!rimCase) return true;
|
||||||
|
|
||||||
|
RifReaderInterface::PorosityModelResultType porosityModel = RifReaderInterface::MATRIX_RESULTS;
|
||||||
|
|
||||||
|
if (args.size() > 2)
|
||||||
|
{
|
||||||
|
QString prorosityModelString = args[2];
|
||||||
|
if (prorosityModelString.toUpper() == "FRACTURE")
|
||||||
|
{
|
||||||
|
porosityModel = RifReaderInterface::FRACTURE_RESULTS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write data back to octave: columnCount, bytesPrTimestep, GridNr I J K ParentGridNr PI PJ PK CoarseBoxIdx
|
||||||
|
|
||||||
|
caf::FixedArray<std::vector<qint32>, 9> activeCellInfo;
|
||||||
|
if (!(rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid()) )
|
||||||
|
{
|
||||||
|
// No data available
|
||||||
|
socketStream << (quint64)0 << (quint64)0 ;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateMatrixModelActiveCellInfo(rimCase, porosityModel,
|
||||||
|
activeCellInfo[0],
|
||||||
|
activeCellInfo[1],
|
||||||
|
activeCellInfo[2],
|
||||||
|
activeCellInfo[3],
|
||||||
|
activeCellInfo[4],
|
||||||
|
activeCellInfo[5],
|
||||||
|
activeCellInfo[6],
|
||||||
|
activeCellInfo[7],
|
||||||
|
activeCellInfo[8]);
|
||||||
|
|
||||||
|
// First write column count
|
||||||
|
quint64 columnCount = (quint64)9;
|
||||||
|
socketStream << columnCount;
|
||||||
|
|
||||||
|
// then the byte-size of the size of one column
|
||||||
|
size_t timestepResultCount = activeCellInfo[0].size();
|
||||||
|
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(qint32));
|
||||||
|
socketStream << timestepByteCount;
|
||||||
|
|
||||||
|
// Then write the data.
|
||||||
|
|
||||||
|
for (size_t tIdx = 0; tIdx < columnCount; ++tIdx)
|
||||||
|
{
|
||||||
|
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
||||||
|
server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount);
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
socketStream << activeCellInfo[tIdx][cIdx];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void calculateMatrixModelActiveCellInfo(RimCase* reservoirCase, RifReaderInterface::PorosityModelResultType porosityModel, std::vector<qint32>& gridNumber, std::vector<qint32>& cellI, std::vector<qint32>& cellJ, std::vector<qint32>& cellK, std::vector<qint32>& parentGridNumber, std::vector<qint32>& hostCellI, std::vector<qint32>& hostCellJ, std::vector<qint32>& hostCellK, std::vector<qint32>& globalCoarseningBoxIdx)
|
||||||
|
{
|
||||||
|
gridNumber.clear();
|
||||||
|
cellI.clear();
|
||||||
|
cellJ.clear();
|
||||||
|
cellK.clear();
|
||||||
|
parentGridNumber.clear();
|
||||||
|
hostCellI.clear();
|
||||||
|
hostCellJ.clear();
|
||||||
|
hostCellK.clear();
|
||||||
|
globalCoarseningBoxIdx.clear();
|
||||||
|
|
||||||
|
if (!reservoirCase || !reservoirCase->reservoirData() || !reservoirCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RigActiveCellInfo* actCellInfo = reservoirCase->reservoirData()->activeCellInfo(porosityModel);
|
||||||
|
size_t numMatrixModelActiveCells = actCellInfo->globalActiveCellCount();
|
||||||
|
|
||||||
|
gridNumber.reserve(numMatrixModelActiveCells);
|
||||||
|
cellI.reserve(numMatrixModelActiveCells);
|
||||||
|
cellJ.reserve(numMatrixModelActiveCells);
|
||||||
|
cellK.reserve(numMatrixModelActiveCells);
|
||||||
|
parentGridNumber.reserve(numMatrixModelActiveCells);
|
||||||
|
hostCellI.reserve(numMatrixModelActiveCells);
|
||||||
|
hostCellJ.reserve(numMatrixModelActiveCells);
|
||||||
|
hostCellK.reserve(numMatrixModelActiveCells);
|
||||||
|
globalCoarseningBoxIdx.reserve(numMatrixModelActiveCells);
|
||||||
|
|
||||||
|
const std::vector<RigCell>& globalCells = reservoirCase->reservoirData()->mainGrid()->cells();
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<size_t> globalCoarseningBoxIndexStart;
|
||||||
|
{
|
||||||
|
size_t globalCoarseningBoxCount = 0;
|
||||||
|
|
||||||
|
for (size_t gridIdx = 0; gridIdx < reservoirCase->reservoirData()->gridCount(); gridIdx++)
|
||||||
|
{
|
||||||
|
globalCoarseningBoxIndexStart.push_back(globalCoarseningBoxCount);
|
||||||
|
|
||||||
|
RigGridBase* grid = reservoirCase->reservoirData()->grid(gridIdx);
|
||||||
|
|
||||||
|
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
||||||
|
globalCoarseningBoxCount += localCoarseningBoxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (size_t cIdx = 0; cIdx < globalCells.size(); ++cIdx)
|
||||||
|
{
|
||||||
|
if (actCellInfo->isActive(cIdx))
|
||||||
|
{
|
||||||
|
RigGridBase* grid = globalCells[cIdx].hostGrid();
|
||||||
|
CVF_ASSERT(grid != NULL);
|
||||||
|
size_t cellIndex = globalCells[cIdx].cellIndex();
|
||||||
|
|
||||||
|
size_t i, j, k;
|
||||||
|
grid->ijkFromCellIndex(cellIndex, &i, &j, &k);
|
||||||
|
|
||||||
|
size_t pi, pj, pk;
|
||||||
|
RigGridBase* parentGrid = NULL;
|
||||||
|
|
||||||
|
if (grid->isMainGrid())
|
||||||
|
{
|
||||||
|
pi = i;
|
||||||
|
pj = j;
|
||||||
|
pk = k;
|
||||||
|
parentGrid = grid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t parentCellIdx = globalCells[cIdx].parentCellIndex();
|
||||||
|
parentGrid = (static_cast<RigLocalGrid*>(grid))->parentGrid();
|
||||||
|
CVF_ASSERT(parentGrid != NULL);
|
||||||
|
parentGrid->ijkFromCellIndex(parentCellIdx, &pi, &pj, &pk);
|
||||||
|
}
|
||||||
|
|
||||||
|
gridNumber.push_back(static_cast<qint32>(grid->gridIndex()));
|
||||||
|
cellI.push_back(static_cast<qint32>(i + 1)); // NB: 1-based index in Octave
|
||||||
|
cellJ.push_back(static_cast<qint32>(j + 1)); // NB: 1-based index in Octave
|
||||||
|
cellK.push_back(static_cast<qint32>(k + 1)); // NB: 1-based index in Octave
|
||||||
|
|
||||||
|
parentGridNumber.push_back(static_cast<qint32>(parentGrid->gridIndex()));
|
||||||
|
hostCellI.push_back(static_cast<qint32>(pi + 1)); // NB: 1-based index in Octave
|
||||||
|
hostCellJ.push_back(static_cast<qint32>(pj + 1)); // NB: 1-based index in Octave
|
||||||
|
hostCellK.push_back(static_cast<qint32>(pk + 1)); // NB: 1-based index in Octave
|
||||||
|
|
||||||
|
size_t coarseningIdx = globalCells[cIdx].coarseningBoxIndex();
|
||||||
|
if (coarseningIdx != cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
size_t globalCoarseningIdx = globalCoarseningBoxIndexStart[grid->gridIndex()] + coarseningIdx;
|
||||||
|
|
||||||
|
globalCoarseningBoxIdx.push_back(static_cast<qint32>(globalCoarseningIdx + 1)); // NB: 1-based index in Octave
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
globalCoarseningBoxIdx.push_back(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetActiveCellInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellInfo>(RiaGetActiveCellInfo::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetCoarseningInfo : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetCoarseningInfo"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
int argCaseGroupId = -1;
|
||||||
|
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
argCaseGroupId = args[1].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
||||||
|
if (!rimCase || !rimCase->reservoirData() || !rimCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
quint64 byteCount = 0;
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write data back to octave: I1, I2, J1, J2, K1, K2 for all coarsening boxes
|
||||||
|
|
||||||
|
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
size_t globalCoarseningBoxCount = 0;
|
||||||
|
|
||||||
|
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
|
||||||
|
{
|
||||||
|
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
|
||||||
|
|
||||||
|
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
||||||
|
globalCoarseningBoxCount += localCoarseningBoxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint64 byteCount = globalCoarseningBoxCount * 6 * sizeof(qint32);
|
||||||
|
socketStream << byteCount;
|
||||||
|
|
||||||
|
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
|
||||||
|
{
|
||||||
|
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
|
||||||
|
|
||||||
|
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
||||||
|
for (size_t boxIdx = 0; boxIdx < localCoarseningBoxCount; boxIdx++)
|
||||||
|
{
|
||||||
|
size_t i1, i2, j1, j2, k1, k2;
|
||||||
|
grid->coarseningBox(boxIdx, &i1, &i2, &j1, &j2, &k1, &k2);
|
||||||
|
|
||||||
|
// Write 1-based coordinates for coarsening box
|
||||||
|
socketStream << static_cast<qint32>(i1 + 1);
|
||||||
|
socketStream << static_cast<qint32>(i2 + 1);
|
||||||
|
socketStream << static_cast<qint32>(j1 + 1);
|
||||||
|
socketStream << static_cast<qint32>(j2 + 1);
|
||||||
|
socketStream << static_cast<qint32>(k1 + 1);
|
||||||
|
socketStream << static_cast<qint32>(k2 + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetCoarseningInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCoarseningInfo>(RiaGetCoarseningInfo::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetGridDimensions : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetGridDimensions"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
int argCaseGroupId = -1;
|
||||||
|
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
argCaseGroupId = args[1].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
||||||
|
if (!rimCase || !rimCase->reservoirData() || !rimCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
quint64 byteCount = 0;
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write data back to octave: I, J, K dimensions
|
||||||
|
|
||||||
|
|
||||||
|
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
||||||
|
{
|
||||||
|
std::vector<RigGridBase*> grids;
|
||||||
|
rimCase->reservoirData()->allGrids(&grids);
|
||||||
|
|
||||||
|
quint64 byteCount = grids.size() * 3 * sizeof(quint64);
|
||||||
|
socketStream << byteCount;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < grids.size(); i++)
|
||||||
|
{
|
||||||
|
size_t iCount = 0;
|
||||||
|
size_t jCount = 0;
|
||||||
|
size_t kCount = 0;
|
||||||
|
|
||||||
|
iCount = grids[i]->cellCountI();
|
||||||
|
jCount = grids[i]->cellCountJ();
|
||||||
|
kCount = grids[i]->cellCountK();
|
||||||
|
|
||||||
|
socketStream << (quint64)iCount << (quint64)jCount << (quint64)kCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetGridDimensions>(RiaGetGridDimensions::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetTimeStepDates : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetTimeStepDates"); }
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
int argCaseGroupId = -1;
|
||||||
|
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
argCaseGroupId = args[1].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
||||||
|
|
||||||
|
bool canFetchData = true;
|
||||||
|
|
||||||
|
if (!rimCase || !rimCase->reservoirData())
|
||||||
|
{
|
||||||
|
canFetchData = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
|
||||||
|
if (rimCase && rimCase->reservoirData())
|
||||||
|
{
|
||||||
|
rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
|
||||||
|
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
canFetchData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did not find any result to fetch data from, return zero data found
|
||||||
|
if (!canFetchData)
|
||||||
|
{
|
||||||
|
quint64 timeStepCount = 0;
|
||||||
|
quint64 byteCount = sizeof(quint64);
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << timeStepCount;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<QDateTime> timeStepDates = rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
||||||
|
|
||||||
|
quint64 timeStepCount = timeStepDates.size();
|
||||||
|
quint64 byteCount = sizeof(quint64) + 6 * timeStepCount * sizeof(qint32);
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << timeStepCount;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < timeStepCount; i++)
|
||||||
|
{
|
||||||
|
qint32 intValue = 0;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].date().year();
|
||||||
|
socketStream << intValue;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].date().month();
|
||||||
|
socketStream << intValue;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].date().day();
|
||||||
|
socketStream << intValue;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].time().hour();
|
||||||
|
socketStream << intValue;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].time().minute();
|
||||||
|
socketStream << intValue;
|
||||||
|
|
||||||
|
intValue = timeStepDates[i].time().second();
|
||||||
|
socketStream << intValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetTimeStepDates_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetTimeStepDates>(RiaGetTimeStepDates::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetTimeStepDays : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetTimeStepDays"); }
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
int argCaseGroupId = -1;
|
||||||
|
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
argCaseGroupId = args[1].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
||||||
|
|
||||||
|
bool canFetchData = true;
|
||||||
|
|
||||||
|
if (!rimCase || !rimCase->reservoirData())
|
||||||
|
{
|
||||||
|
canFetchData = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
|
||||||
|
if (rimCase && rimCase->reservoirData())
|
||||||
|
{
|
||||||
|
rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
|
||||||
|
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
canFetchData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did not find any result to fetch data from, return zero data found
|
||||||
|
if (!canFetchData)
|
||||||
|
{
|
||||||
|
quint64 timeStepCount = 0;
|
||||||
|
quint64 byteCount = sizeof(quint64);
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << timeStepCount;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<QDateTime> timeStepDates = rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
||||||
|
|
||||||
|
quint64 timeStepCount = timeStepDates.size();
|
||||||
|
quint64 byteCount = sizeof(quint64) + timeStepCount * sizeof(qint32);
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << timeStepCount;
|
||||||
|
|
||||||
|
if (timeStepCount > 0)
|
||||||
|
{
|
||||||
|
double secondsInADay = 24 * 60 * 60;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < timeStepCount; i++)
|
||||||
|
{
|
||||||
|
double secondsDiff = timeStepDates[0].secsTo(timeStepDates[i]);
|
||||||
|
|
||||||
|
double decimalDaysDiff = secondsDiff / secondsInADay;
|
||||||
|
|
||||||
|
socketStream << decimalDaysDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetTimeStepDays_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetTimeStepDays>(RiaGetTimeStepDays::commandName());
|
||||||
|
|
||||||
+14
-288
@@ -16,8 +16,8 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RiaStdInclude.h"
|
#include "RiaStdInclude.h"
|
||||||
#include "RiaSocketServer.h"
|
|
||||||
#include "RiaSocketCommand.h"
|
#include "RiaSocketCommand.h"
|
||||||
|
#include "RiaSocketServer.h"
|
||||||
|
|
||||||
#include "RimReservoirView.h"
|
#include "RimReservoirView.h"
|
||||||
#include "RimResultSlot.h"
|
#include "RimResultSlot.h"
|
||||||
@@ -35,293 +35,9 @@
|
|||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
|
||||||
class RiaGetTimeStepDates : public RiaSocketCommand
|
//--------------------------------------------------------------------------------------------------
|
||||||
{
|
///
|
||||||
public:
|
//--------------------------------------------------------------------------------------------------
|
||||||
static QString commandName () { return QString("GetTimeStepDates"); }
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
int argCaseGroupId = -1;
|
|
||||||
|
|
||||||
if (args.size() == 2)
|
|
||||||
{
|
|
||||||
argCaseGroupId = args[1].toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
|
||||||
|
|
||||||
bool canFetchData = true;
|
|
||||||
|
|
||||||
if (!rimCase || !rimCase->reservoirData())
|
|
||||||
{
|
|
||||||
canFetchData = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
|
|
||||||
if (rimCase && rimCase->reservoirData())
|
|
||||||
{
|
|
||||||
rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
|
|
||||||
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
canFetchData = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did not find any result to fetch data from, return zero data found
|
|
||||||
if (!canFetchData)
|
|
||||||
{
|
|
||||||
quint64 timeStepCount = 0;
|
|
||||||
quint64 byteCount = sizeof(quint64);
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << timeStepCount;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<QDateTime> timeStepDates = rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
|
||||||
|
|
||||||
quint64 timeStepCount = timeStepDates.size();
|
|
||||||
quint64 byteCount = sizeof(quint64) + 6 * timeStepCount * sizeof(qint32);
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << timeStepCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < timeStepCount; i++)
|
|
||||||
{
|
|
||||||
qint32 intValue = 0;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].date().year();
|
|
||||||
socketStream << intValue;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].date().month();
|
|
||||||
socketStream << intValue;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].date().day();
|
|
||||||
socketStream << intValue;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].time().hour();
|
|
||||||
socketStream << intValue;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].time().minute();
|
|
||||||
socketStream << intValue;
|
|
||||||
|
|
||||||
intValue = timeStepDates[i].time().second();
|
|
||||||
socketStream << intValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetTimeStepDates_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetTimeStepDates>(RiaGetTimeStepDates::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetTimeStepDays : public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetTimeStepDays"); }
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
int argCaseGroupId = -1;
|
|
||||||
|
|
||||||
if (args.size() == 2)
|
|
||||||
{
|
|
||||||
argCaseGroupId = args[1].toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
|
||||||
|
|
||||||
bool canFetchData = true;
|
|
||||||
|
|
||||||
if (!rimCase || !rimCase->reservoirData())
|
|
||||||
{
|
|
||||||
canFetchData = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
|
|
||||||
if (rimCase && rimCase->reservoirData())
|
|
||||||
{
|
|
||||||
rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
|
|
||||||
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
canFetchData = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did not find any result to fetch data from, return zero data found
|
|
||||||
if (!canFetchData)
|
|
||||||
{
|
|
||||||
quint64 timeStepCount = 0;
|
|
||||||
quint64 byteCount = sizeof(quint64);
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << timeStepCount;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<QDateTime> timeStepDates = rimCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
|
|
||||||
|
|
||||||
quint64 timeStepCount = timeStepDates.size();
|
|
||||||
quint64 byteCount = sizeof(quint64) + timeStepCount * sizeof(qint32);
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << timeStepCount;
|
|
||||||
|
|
||||||
if (timeStepCount > 0)
|
|
||||||
{
|
|
||||||
double secondsInADay = 24 * 60 * 60;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < timeStepCount; i++)
|
|
||||||
{
|
|
||||||
double secondsDiff = timeStepDates[0].secsTo(timeStepDates[i]);
|
|
||||||
|
|
||||||
double decimalDaysDiff = secondsDiff / secondsInADay;
|
|
||||||
|
|
||||||
socketStream << decimalDaysDiff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetTimeStepDays_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetTimeStepDays>(RiaGetTimeStepDays::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetGridDimensions : public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetGridDimensions"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
int argCaseGroupId = -1;
|
|
||||||
|
|
||||||
if (args.size() == 2)
|
|
||||||
{
|
|
||||||
argCaseGroupId = args[1].toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
|
||||||
if (!rimCase || !rimCase->reservoirData() || !rimCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
quint64 byteCount = 0;
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data back to octave: I, J, K dimensions
|
|
||||||
|
|
||||||
|
|
||||||
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
std::vector<RigGridBase*> grids;
|
|
||||||
rimCase->reservoirData()->allGrids(&grids);
|
|
||||||
|
|
||||||
quint64 byteCount = grids.size() * 3 * sizeof(quint64);
|
|
||||||
socketStream << byteCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < grids.size(); i++)
|
|
||||||
{
|
|
||||||
size_t iCount = 0;
|
|
||||||
size_t jCount = 0;
|
|
||||||
size_t kCount = 0;
|
|
||||||
|
|
||||||
iCount = grids[i]->cellCountI();
|
|
||||||
jCount = grids[i]->cellCountJ();
|
|
||||||
kCount = grids[i]->cellCountK();
|
|
||||||
|
|
||||||
socketStream << (quint64)iCount << (quint64)jCount << (quint64)kCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetGridDimensions>(RiaGetGridDimensions::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetCoarseningInfo : public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetCoarseningInfo"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
int argCaseGroupId = -1;
|
|
||||||
|
|
||||||
if (args.size() == 2)
|
|
||||||
{
|
|
||||||
argCaseGroupId = args[1].toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
RimCase* rimCase = server->findReservoir(argCaseGroupId);
|
|
||||||
if (!rimCase || !rimCase->reservoirData() || !rimCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
quint64 byteCount = 0;
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data back to octave: I1, I2, J1, J2, K1, K2 for all coarsening boxes
|
|
||||||
|
|
||||||
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
size_t globalCoarseningBoxCount = 0;
|
|
||||||
|
|
||||||
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
|
|
||||||
{
|
|
||||||
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
|
|
||||||
|
|
||||||
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
|
||||||
globalCoarseningBoxCount += localCoarseningBoxCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 byteCount = globalCoarseningBoxCount * 6 * sizeof(qint32);
|
|
||||||
socketStream << byteCount;
|
|
||||||
|
|
||||||
for (size_t gridIdx = 0; gridIdx < rimCase->reservoirData()->gridCount(); gridIdx++)
|
|
||||||
{
|
|
||||||
RigGridBase* grid = rimCase->reservoirData()->grid(gridIdx);
|
|
||||||
|
|
||||||
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
|
||||||
for (size_t boxIdx = 0; boxIdx < localCoarseningBoxCount; boxIdx++)
|
|
||||||
{
|
|
||||||
size_t i1, i2, j1, j2, k1, k2;
|
|
||||||
grid->coarseningBox(boxIdx, &i1, &i2, &j1, &j2, &k1, &k2);
|
|
||||||
|
|
||||||
// Write 1-based coordinates for coarsening box
|
|
||||||
socketStream << static_cast<qint32>(i1 + 1);
|
|
||||||
socketStream << static_cast<qint32>(i2 + 1);
|
|
||||||
socketStream << static_cast<qint32>(j1 + 1);
|
|
||||||
socketStream << static_cast<qint32>(j2 + 1);
|
|
||||||
socketStream << static_cast<qint32>(k1 + 1);
|
|
||||||
socketStream << static_cast<qint32>(k2 + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetCoarseningInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCoarseningInfo>(RiaGetCoarseningInfo::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetCellCenters : public RiaSocketCommand
|
class RiaGetCellCenters : public RiaSocketCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -409,6 +125,9 @@ public:
|
|||||||
static bool RiaGetCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCenters>(RiaGetCellCenters::commandName());
|
static bool RiaGetCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCenters>(RiaGetCellCenters::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
class RiaGetActiveCellCenters : public RiaSocketCommand
|
class RiaGetActiveCellCenters : public RiaSocketCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -510,6 +229,9 @@ static bool RiaGetActiveCellCenters_init = RiaSocketCommandFactory::instance()->
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
class RiaGetCellCorners : public RiaSocketCommand
|
class RiaGetCellCorners : public RiaSocketCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -599,6 +321,10 @@ public:
|
|||||||
static bool RiaGetCellCorners_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCorners>(RiaGetCellCorners::commandName());
|
static bool RiaGetCellCorners_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCellCorners>(RiaGetCellCorners::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
class RiaGetActiveCellCorners : public RiaSocketCommand
|
class RiaGetActiveCellCorners : public RiaSocketCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RiaStdInclude.h"
|
||||||
|
#include "RiaSocketCommand.h"
|
||||||
|
#include "RiaSocketServer.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
|
#include "RimReservoirView.h"
|
||||||
|
#include "RimResultSlot.h"
|
||||||
|
#include "RimCellEdgeResultSlot.h"
|
||||||
|
#include "RimCellRangeFilterCollection.h"
|
||||||
|
#include "RimCellPropertyFilterCollection.h"
|
||||||
|
#include "RimWellCollection.h"
|
||||||
|
#include "Rim3dOverlayInfoConfig.h"
|
||||||
|
#include "RimReservoirCellResultsCacher.h"
|
||||||
|
|
||||||
|
#include "RimCase.h"
|
||||||
|
#include "RigCaseData.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
|
#include "RiuMainWindow.h"
|
||||||
|
#include "RiaApplication.h"
|
||||||
|
#include "RimProject.h"
|
||||||
|
#include "RimIdenticalGridCaseGroup.h"
|
||||||
|
#include "RimCaseCollection.h"
|
||||||
|
#include "RimScriptCollection.h"
|
||||||
|
#include "RimWellPathCollection.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void getCaseInfoFromCases(std::vector<RimCase*>& cases, std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<QString> &caseTypes, std::vector<qint64>& caseGroupIds)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < cases.size(); i++)
|
||||||
|
{
|
||||||
|
RimCase* rimCase = cases[i];
|
||||||
|
|
||||||
|
qint64 caseId = -1;
|
||||||
|
QString caseName;
|
||||||
|
QString caseType;
|
||||||
|
qint64 caseGroupId = -1;
|
||||||
|
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||||
|
|
||||||
|
caseIds.push_back(rimCase->caseId);
|
||||||
|
caseNames.push_back(rimCase->caseUserDescription);
|
||||||
|
caseTypes.push_back(caseType);
|
||||||
|
caseGroupIds.push_back(caseGroupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetCurrentCase : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetCurrentCase"); }
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
qint64 caseId = -1;
|
||||||
|
QString caseName;
|
||||||
|
QString caseType;
|
||||||
|
qint64 caseGroupId = -1;
|
||||||
|
|
||||||
|
RimCase* rimCase = server->findReservoir(caseId);
|
||||||
|
|
||||||
|
if (rimCase)
|
||||||
|
{
|
||||||
|
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint64 byteCount = 2*sizeof(qint64);
|
||||||
|
byteCount += caseName.size()*sizeof(QChar);
|
||||||
|
byteCount += caseType.size()*sizeof(QChar);
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
|
||||||
|
socketStream << caseId;
|
||||||
|
socketStream << caseName;
|
||||||
|
socketStream << caseType;
|
||||||
|
socketStream << caseGroupId;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetCurrentCase_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCurrentCase>(RiaGetCurrentCase::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetSelectedCases: public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetSelectedCases"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
RiuMainWindow* ruiMainWindow = RiuMainWindow::instance();
|
||||||
|
if (ruiMainWindow)
|
||||||
|
{
|
||||||
|
std::vector<RimCase*> cases;
|
||||||
|
ruiMainWindow->selectedCases(cases);
|
||||||
|
|
||||||
|
std::vector<qint64> caseIds;
|
||||||
|
std::vector<QString> caseNames;
|
||||||
|
std::vector<QString> caseTypes;
|
||||||
|
std::vector<qint64> caseGroupIds;
|
||||||
|
|
||||||
|
getCaseInfoFromCases(cases, caseIds, caseNames, caseTypes, caseGroupIds);
|
||||||
|
|
||||||
|
quint64 byteCount = sizeof(quint64);
|
||||||
|
quint64 selectionCount = caseIds.size();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < selectionCount; i++)
|
||||||
|
{
|
||||||
|
byteCount += 2*sizeof(qint64);
|
||||||
|
byteCount += caseNames[i].size() * sizeof(QChar);
|
||||||
|
byteCount += caseTypes[i].size() * sizeof(QChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << selectionCount;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < selectionCount; i++)
|
||||||
|
{
|
||||||
|
socketStream << caseIds[i];
|
||||||
|
socketStream << caseNames[i];
|
||||||
|
socketStream << caseTypes[i];
|
||||||
|
socketStream << caseGroupIds[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetSelectedCases_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetSelectedCases>(RiaGetSelectedCases::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetCaseGroups : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetCaseGroups"); }
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
if (RiaApplication::instance()->project())
|
||||||
|
{
|
||||||
|
std::vector<QString> groupNames;
|
||||||
|
std::vector<qint64> groupIds;
|
||||||
|
|
||||||
|
size_t caseGroupCount = RiaApplication::instance()->project()->caseGroups().size();
|
||||||
|
quint64 byteCount = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < caseGroupCount; i++)
|
||||||
|
{
|
||||||
|
RimIdenticalGridCaseGroup* cg = RiaApplication::instance()->project()->caseGroups()[i];
|
||||||
|
|
||||||
|
QString caseGroupName = cg->name;
|
||||||
|
qint64 caseGroupId = cg->groupId;
|
||||||
|
|
||||||
|
byteCount += caseGroupName.size() * sizeof(QChar);
|
||||||
|
byteCount += sizeof(qint64);
|
||||||
|
|
||||||
|
groupNames.push_back(caseGroupName);
|
||||||
|
groupIds.push_back(caseGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
socketStream << (quint64)byteCount;
|
||||||
|
socketStream << (quint64)caseGroupCount;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < caseGroupCount; i++)
|
||||||
|
{
|
||||||
|
socketStream << groupNames[i];
|
||||||
|
socketStream << groupIds[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ERROR
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetCaseGroups_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCaseGroups>(RiaGetCaseGroups::commandName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetCases : public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetCases"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
int argCaseGroupId = -1;
|
||||||
|
|
||||||
|
if (args.size() == 2)
|
||||||
|
{
|
||||||
|
argCaseGroupId = args[1].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RiaApplication::instance()->project())
|
||||||
|
{
|
||||||
|
RimProject* proj = RiaApplication::instance()->project();
|
||||||
|
|
||||||
|
std::vector<RimCase*> cases;
|
||||||
|
if (argCaseGroupId == -1)
|
||||||
|
{
|
||||||
|
proj->allCases(cases);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RimIdenticalGridCaseGroup* caseGroup = NULL;
|
||||||
|
for (size_t i = 0; i < RiaApplication::instance()->project()->caseGroups().size(); i++)
|
||||||
|
{
|
||||||
|
RimIdenticalGridCaseGroup* cg = RiaApplication::instance()->project()->caseGroups()[i];
|
||||||
|
|
||||||
|
if (argCaseGroupId == cg->groupId())
|
||||||
|
{
|
||||||
|
caseGroup = cg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caseGroup)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < caseGroup->statisticsCaseCollection()->reservoirs.size(); i++)
|
||||||
|
{
|
||||||
|
cases.push_back(caseGroup->statisticsCaseCollection()->reservoirs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < caseGroup->caseCollection()->reservoirs.size(); i++)
|
||||||
|
{
|
||||||
|
cases.push_back(caseGroup->caseCollection()->reservoirs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<qint64> caseIds;
|
||||||
|
std::vector<QString> caseNames;
|
||||||
|
std::vector<QString> caseTypes;
|
||||||
|
std::vector<qint64> caseGroupIds;
|
||||||
|
|
||||||
|
getCaseInfoFromCases(cases, caseIds, caseNames, caseTypes, caseGroupIds);
|
||||||
|
|
||||||
|
quint64 byteCount = sizeof(quint64);
|
||||||
|
quint64 caseCount = caseIds.size();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < caseCount; i++)
|
||||||
|
{
|
||||||
|
byteCount += 2*sizeof(qint64);
|
||||||
|
byteCount += caseNames[i].size() * sizeof(QChar);
|
||||||
|
byteCount += caseTypes[i].size() * sizeof(QChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
socketStream << byteCount;
|
||||||
|
socketStream << caseCount;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < caseCount; i++)
|
||||||
|
{
|
||||||
|
socketStream << caseIds[i];
|
||||||
|
socketStream << caseNames[i];
|
||||||
|
socketStream << caseTypes[i];
|
||||||
|
socketStream << caseGroupIds[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetCases_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCases>(RiaGetCases::commandName());
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RiaStdInclude.h"
|
||||||
|
#include "RiaSocketCommand.h"
|
||||||
|
#include "RiaSocketServer.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
|
#include "RimReservoirView.h"
|
||||||
|
#include "RimResultSlot.h"
|
||||||
|
#include "RimCellEdgeResultSlot.h"
|
||||||
|
#include "RimCellRangeFilterCollection.h"
|
||||||
|
#include "RimCellPropertyFilterCollection.h"
|
||||||
|
#include "RimWellCollection.h"
|
||||||
|
#include "Rim3dOverlayInfoConfig.h"
|
||||||
|
#include "RimReservoirCellResultsCacher.h"
|
||||||
|
|
||||||
|
#include "RimCase.h"
|
||||||
|
#include "RigCaseData.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaGetActiveCellProperty: public RiaSocketCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString commandName () { return QString("GetActiveCellProperty"); }
|
||||||
|
|
||||||
|
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||||
|
{
|
||||||
|
|
||||||
|
RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
|
||||||
|
|
||||||
|
QString propertyName = args[2];
|
||||||
|
QString porosityModelName = args[3];
|
||||||
|
|
||||||
|
RifReaderInterface::PorosityModelResultType porosityModelEnum = RifReaderInterface::MATRIX_RESULTS;
|
||||||
|
if (porosityModelName == "Fracture")
|
||||||
|
{
|
||||||
|
porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the requested data
|
||||||
|
|
||||||
|
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
||||||
|
std::vector< std::vector<double> >* scalarResultFrames = NULL;
|
||||||
|
|
||||||
|
if (rimCase && rimCase->results(porosityModelEnum))
|
||||||
|
{
|
||||||
|
scalarResultIndex = rimCase->results(porosityModelEnum)->findOrLoadScalarResult(propertyName);
|
||||||
|
|
||||||
|
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
scalarResultFrames = &(rimCase->results(porosityModelEnum)->cellResults()->cellScalarResults(scalarResultIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scalarResultFrames == NULL)
|
||||||
|
{
|
||||||
|
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the %1 model property named: \"%2\"").arg(porosityModelName).arg(propertyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write data back : timeStepCount, bytesPrTimestep, dataForTimestep0 ... dataForTimestepN
|
||||||
|
|
||||||
|
if ( scalarResultFrames == NULL)
|
||||||
|
{
|
||||||
|
// No data available
|
||||||
|
socketStream << (quint64)0 << (quint64)0 ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create a list of all the requested timesteps
|
||||||
|
|
||||||
|
std::vector<size_t> requestedTimesteps;
|
||||||
|
|
||||||
|
if (args.size() <= 4)
|
||||||
|
{
|
||||||
|
// Select all
|
||||||
|
for (size_t tsIdx = 0; tsIdx < scalarResultFrames->size(); ++tsIdx)
|
||||||
|
{
|
||||||
|
requestedTimesteps.push_back(tsIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool timeStepReadError = false;
|
||||||
|
for (int argIdx = 4; argIdx < args.size(); ++argIdx)
|
||||||
|
{
|
||||||
|
bool conversionOk = false;
|
||||||
|
int tsIdx = args[argIdx].toInt(&conversionOk);
|
||||||
|
|
||||||
|
if (conversionOk)
|
||||||
|
{
|
||||||
|
requestedTimesteps.push_back(tsIdx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timeStepReadError = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeStepReadError)
|
||||||
|
{
|
||||||
|
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetActiveCellProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps."));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// First write timestep count
|
||||||
|
quint64 timestepCount = (quint64)requestedTimesteps.size();
|
||||||
|
socketStream << timestepCount;
|
||||||
|
|
||||||
|
// then the byte-size of the result values in one timestep
|
||||||
|
|
||||||
|
const RigActiveCellInfo* activeInfo = rimCase->reservoirData()->activeCellInfo(porosityModelEnum);
|
||||||
|
size_t timestepResultCount = activeInfo->globalActiveCellCount();
|
||||||
|
|
||||||
|
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
|
||||||
|
socketStream << timestepByteCount ;
|
||||||
|
|
||||||
|
// Then write the data.
|
||||||
|
|
||||||
|
size_t globalCellCount = activeInfo->globalCellCount();
|
||||||
|
for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx)
|
||||||
|
{
|
||||||
|
for (size_t gcIdx = 0; gcIdx < globalCellCount; ++gcIdx)
|
||||||
|
{
|
||||||
|
size_t resultIdx = activeInfo->cellResultIndex(gcIdx);
|
||||||
|
if (resultIdx != cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
if (resultIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size())
|
||||||
|
{
|
||||||
|
socketStream << scalarResultFrames->at(requestedTimesteps[tIdx])[resultIdx];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
socketStream << HUGE_VAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
// This aproach is faster but does not handle coarsening
|
||||||
|
size_t timestepResultCount = scalarResultFrames->front().size();
|
||||||
|
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
|
||||||
|
socketStream << timestepByteCount ;
|
||||||
|
|
||||||
|
// Then write the data.
|
||||||
|
|
||||||
|
for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx)
|
||||||
|
{
|
||||||
|
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
||||||
|
server->currentClient()->write((const char *)scalarResultFrames->at(requestedTimesteps[tIdx]).data(), timestepByteCount); // Raw print of data. Fast but no platform conversion
|
||||||
|
#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well
|
||||||
|
for (size_t cIdx = 0; cIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size(); ++cIdx)
|
||||||
|
{
|
||||||
|
socketStream << scalarResultFrames->at(tIdx)[cIdx];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool RiaGetActiveCellProperty_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellProperty>(RiaGetActiveCellProperty::commandName());
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
/// Socket commands, to be moved into a separate file
|
/// Socket commands, to be moved into a separate file
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class RiaSocketServer;
|
||||||
|
|
||||||
class RiaSocketCommand
|
class RiaSocketCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,5 +36,4 @@ public:
|
|||||||
#include "cafFactory.h"
|
#include "cafFactory.h"
|
||||||
typedef caf::Factory<RiaSocketCommand, QString> RiaSocketCommandFactory;
|
typedef caf::Factory<RiaSocketCommand, QString> RiaSocketCommandFactory;
|
||||||
|
|
||||||
void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,679 +57,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RimCase * findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args )
|
|
||||||
{
|
|
||||||
|
|
||||||
RimCase* rimCase = NULL;
|
|
||||||
int caseId = -1;
|
|
||||||
|
|
||||||
if (args.size() > 1)
|
|
||||||
{
|
|
||||||
caseId = args[1].toInt();
|
|
||||||
}
|
|
||||||
rimCase = server->findReservoir(caseId);
|
|
||||||
|
|
||||||
if (rimCase == NULL)
|
|
||||||
{
|
|
||||||
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the Case with CaseId : \"%1\"").arg(caseId));
|
|
||||||
}
|
|
||||||
return rimCase;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId)
|
|
||||||
{
|
|
||||||
CVF_ASSERT(rimCase);
|
|
||||||
|
|
||||||
caseId = rimCase->caseId;
|
|
||||||
caseName = rimCase->caseUserDescription;
|
|
||||||
|
|
||||||
RimCaseCollection* caseCollection = rimCase->parentCaseCollection();
|
|
||||||
if (caseCollection)
|
|
||||||
{
|
|
||||||
caseGroupId = caseCollection->parentCaseGroup()->groupId;
|
|
||||||
|
|
||||||
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
|
|
||||||
{
|
|
||||||
caseType = "StatisticsCase";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
caseType = "SourceCase";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
caseGroupId = -1;
|
|
||||||
|
|
||||||
if (dynamic_cast<RimInputCase*>(rimCase))
|
|
||||||
{
|
|
||||||
caseType = "InputCase";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
caseType = "ResultCase";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RiaGetCurrentCase: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetCurrentCase"); }
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
qint64 caseId = -1;
|
|
||||||
QString caseName;
|
|
||||||
QString caseType;
|
|
||||||
qint64 caseGroupId = -1;
|
|
||||||
|
|
||||||
RimCase* rimCase = server->findReservoir(caseId);
|
|
||||||
|
|
||||||
if (rimCase)
|
|
||||||
{
|
|
||||||
getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 byteCount = 2*sizeof(qint64);
|
|
||||||
byteCount += caseName.size()*sizeof(QChar);
|
|
||||||
byteCount += caseType.size()*sizeof(QChar);
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
|
|
||||||
socketStream << caseId;
|
|
||||||
socketStream << caseName;
|
|
||||||
socketStream << caseType;
|
|
||||||
socketStream << caseGroupId;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetCurrentCase_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCurrentCase>(RiaGetCurrentCase::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetCaseGroups: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetCaseGroups"); }
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
if (RiaApplication::instance()->project())
|
|
||||||
{
|
|
||||||
std::vector<QString> groupNames;
|
|
||||||
std::vector<qint64> groupIds;
|
|
||||||
|
|
||||||
size_t caseGroupCount = RiaApplication::instance()->project()->caseGroups().size();
|
|
||||||
quint64 byteCount = 0;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < caseGroupCount; i++)
|
|
||||||
{
|
|
||||||
RimIdenticalGridCaseGroup* cg = RiaApplication::instance()->project()->caseGroups()[i];
|
|
||||||
|
|
||||||
QString caseGroupName = cg->name;
|
|
||||||
qint64 caseGroupId = cg->groupId;
|
|
||||||
|
|
||||||
byteCount += caseGroupName.size() * sizeof(QChar);
|
|
||||||
byteCount += sizeof(qint64);
|
|
||||||
|
|
||||||
groupNames.push_back(caseGroupName);
|
|
||||||
groupIds.push_back(caseGroupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
socketStream << (quint64)byteCount;
|
|
||||||
socketStream << (quint64)caseGroupCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < caseGroupCount; i++)
|
|
||||||
{
|
|
||||||
socketStream << groupNames[i];
|
|
||||||
socketStream << groupIds[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ERROR
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetCaseGroups_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCaseGroups>(RiaGetCaseGroups::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void getCaseInfoFromCases(std::vector<RimCase*>& cases, std::vector<qint64>& caseIds, std::vector<QString>& caseNames, std::vector<QString> &caseTypes, std::vector<qint64>& caseGroupIds)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < cases.size(); i++)
|
|
||||||
{
|
|
||||||
RimCase* rimCase = cases[i];
|
|
||||||
|
|
||||||
qint64 caseId = -1;
|
|
||||||
QString caseName;
|
|
||||||
QString caseType;
|
|
||||||
qint64 caseGroupId = -1;
|
|
||||||
getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
|
||||||
|
|
||||||
caseIds.push_back(rimCase->caseId);
|
|
||||||
caseNames.push_back(rimCase->caseUserDescription);
|
|
||||||
caseTypes.push_back(caseType);
|
|
||||||
caseGroupIds.push_back(caseGroupId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetSelectedCases: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetSelectedCases"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
RiuMainWindow* ruiMainWindow = RiuMainWindow::instance();
|
|
||||||
if (ruiMainWindow)
|
|
||||||
{
|
|
||||||
std::vector<RimCase*> cases;
|
|
||||||
ruiMainWindow->selectedCases(cases);
|
|
||||||
|
|
||||||
std::vector<qint64> caseIds;
|
|
||||||
std::vector<QString> caseNames;
|
|
||||||
std::vector<QString> caseTypes;
|
|
||||||
std::vector<qint64> caseGroupIds;
|
|
||||||
|
|
||||||
getCaseInfoFromCases(cases, caseIds, caseNames, caseTypes, caseGroupIds);
|
|
||||||
|
|
||||||
quint64 byteCount = sizeof(quint64);
|
|
||||||
quint64 selectionCount = caseIds.size();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < selectionCount; i++)
|
|
||||||
{
|
|
||||||
byteCount += 2*sizeof(qint64);
|
|
||||||
byteCount += caseNames[i].size() * sizeof(QChar);
|
|
||||||
byteCount += caseTypes[i].size() * sizeof(QChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << selectionCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < selectionCount; i++)
|
|
||||||
{
|
|
||||||
socketStream << caseIds[i];
|
|
||||||
socketStream << caseNames[i];
|
|
||||||
socketStream << caseTypes[i];
|
|
||||||
socketStream << caseGroupIds[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetSelectedCases_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetSelectedCases>(RiaGetSelectedCases::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetCases: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetCases"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
int argCaseGroupId = -1;
|
|
||||||
|
|
||||||
if (args.size() == 2)
|
|
||||||
{
|
|
||||||
argCaseGroupId = args[1].toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RiaApplication::instance()->project())
|
|
||||||
{
|
|
||||||
RimProject* proj = RiaApplication::instance()->project();
|
|
||||||
|
|
||||||
std::vector<RimCase*> cases;
|
|
||||||
if (argCaseGroupId == -1)
|
|
||||||
{
|
|
||||||
proj->allCases(cases);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RimIdenticalGridCaseGroup* caseGroup = NULL;
|
|
||||||
for (size_t i = 0; i < RiaApplication::instance()->project()->caseGroups().size(); i++)
|
|
||||||
{
|
|
||||||
RimIdenticalGridCaseGroup* cg = RiaApplication::instance()->project()->caseGroups()[i];
|
|
||||||
|
|
||||||
if (argCaseGroupId == cg->groupId())
|
|
||||||
{
|
|
||||||
caseGroup = cg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (caseGroup)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < caseGroup->statisticsCaseCollection()->reservoirs.size(); i++)
|
|
||||||
{
|
|
||||||
cases.push_back(caseGroup->statisticsCaseCollection()->reservoirs[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < caseGroup->caseCollection()->reservoirs.size(); i++)
|
|
||||||
{
|
|
||||||
cases.push_back(caseGroup->caseCollection()->reservoirs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<qint64> caseIds;
|
|
||||||
std::vector<QString> caseNames;
|
|
||||||
std::vector<QString> caseTypes;
|
|
||||||
std::vector<qint64> caseGroupIds;
|
|
||||||
|
|
||||||
getCaseInfoFromCases(cases, caseIds, caseNames, caseTypes, caseGroupIds);
|
|
||||||
|
|
||||||
quint64 byteCount = sizeof(quint64);
|
|
||||||
quint64 caseCount = caseIds.size();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < caseCount; i++)
|
|
||||||
{
|
|
||||||
byteCount += 2*sizeof(qint64);
|
|
||||||
byteCount += caseNames[i].size() * sizeof(QChar);
|
|
||||||
byteCount += caseTypes[i].size() * sizeof(QChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
socketStream << byteCount;
|
|
||||||
socketStream << caseCount;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < caseCount; i++)
|
|
||||||
{
|
|
||||||
socketStream << caseIds[i];
|
|
||||||
socketStream << caseNames[i];
|
|
||||||
socketStream << caseTypes[i];
|
|
||||||
socketStream << caseGroupIds[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetCases_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetCases>(RiaGetCases::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetMainGridDimensions: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetMainGridDimensions"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
|
|
||||||
RimCase* rimCase = findCaseFromArgs(server, args);
|
|
||||||
if (!rimCase) return true;
|
|
||||||
|
|
||||||
// Write data back to octave: I, J, K dimensions
|
|
||||||
|
|
||||||
size_t iCount = 0;
|
|
||||||
size_t jCount = 0;
|
|
||||||
size_t kCount = 0;
|
|
||||||
|
|
||||||
if (rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
iCount = rimCase->reservoirData()->mainGrid()->cellCountI();
|
|
||||||
jCount = rimCase->reservoirData()->mainGrid()->cellCountJ();
|
|
||||||
kCount = rimCase->reservoirData()->mainGrid()->cellCountK();
|
|
||||||
}
|
|
||||||
|
|
||||||
socketStream << (quint64)iCount << (quint64)jCount << (quint64)kCount;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetMainGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetMainGridDimensions>(RiaGetMainGridDimensions::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class RiaGetActiveCellInfo: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetActiveCellInfo"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
RimCase* rimCase = findCaseFromArgs(server, args);
|
|
||||||
if (!rimCase) return true;
|
|
||||||
|
|
||||||
RifReaderInterface::PorosityModelResultType porosityModel = RifReaderInterface::MATRIX_RESULTS;
|
|
||||||
|
|
||||||
if (args.size() > 2)
|
|
||||||
{
|
|
||||||
QString prorosityModelString = args[2];
|
|
||||||
if (prorosityModelString.toUpper() == "FRACTURE")
|
|
||||||
{
|
|
||||||
porosityModel = RifReaderInterface::FRACTURE_RESULTS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data back to octave: columnCount, bytesPrTimestep, GridNr I J K ParentGridNr PI PJ PK CoarseBoxIdx
|
|
||||||
|
|
||||||
caf::FixedArray<std::vector<qint32>, 9> activeCellInfo;
|
|
||||||
if (!(rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid()) )
|
|
||||||
{
|
|
||||||
// No data available
|
|
||||||
socketStream << (quint64)0 << (quint64)0 ;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
calculateMatrixModelActiveCellInfo(rimCase, porosityModel,
|
|
||||||
activeCellInfo[0],
|
|
||||||
activeCellInfo[1],
|
|
||||||
activeCellInfo[2],
|
|
||||||
activeCellInfo[3],
|
|
||||||
activeCellInfo[4],
|
|
||||||
activeCellInfo[5],
|
|
||||||
activeCellInfo[6],
|
|
||||||
activeCellInfo[7],
|
|
||||||
activeCellInfo[8]);
|
|
||||||
|
|
||||||
// First write column count
|
|
||||||
quint64 columnCount = (quint64)9;
|
|
||||||
socketStream << columnCount;
|
|
||||||
|
|
||||||
// then the byte-size of the size of one column
|
|
||||||
size_t timestepResultCount = activeCellInfo[0].size();
|
|
||||||
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(qint32));
|
|
||||||
socketStream << timestepByteCount;
|
|
||||||
|
|
||||||
// Then write the data.
|
|
||||||
|
|
||||||
for (size_t tIdx = 0; tIdx < columnCount; ++tIdx)
|
|
||||||
{
|
|
||||||
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
|
||||||
server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount);
|
|
||||||
#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)
|
|
||||||
{
|
|
||||||
socketStream << activeCellInfo[tIdx][cIdx];
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void calculateMatrixModelActiveCellInfo(RimCase* reservoirCase, RifReaderInterface::PorosityModelResultType porosityModel, std::vector<qint32>& gridNumber, std::vector<qint32>& cellI, std::vector<qint32>& cellJ, std::vector<qint32>& cellK, std::vector<qint32>& parentGridNumber, std::vector<qint32>& hostCellI, std::vector<qint32>& hostCellJ, std::vector<qint32>& hostCellK, std::vector<qint32>& globalCoarseningBoxIdx)
|
|
||||||
{
|
|
||||||
gridNumber.clear();
|
|
||||||
cellI.clear();
|
|
||||||
cellJ.clear();
|
|
||||||
cellK.clear();
|
|
||||||
parentGridNumber.clear();
|
|
||||||
hostCellI.clear();
|
|
||||||
hostCellJ.clear();
|
|
||||||
hostCellK.clear();
|
|
||||||
globalCoarseningBoxIdx.clear();
|
|
||||||
|
|
||||||
if (!reservoirCase || !reservoirCase->reservoirData() || !reservoirCase->reservoirData()->mainGrid())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RigActiveCellInfo* actCellInfo = reservoirCase->reservoirData()->activeCellInfo(porosityModel);
|
|
||||||
size_t numMatrixModelActiveCells = actCellInfo->globalActiveCellCount();
|
|
||||||
|
|
||||||
gridNumber.reserve(numMatrixModelActiveCells);
|
|
||||||
cellI.reserve(numMatrixModelActiveCells);
|
|
||||||
cellJ.reserve(numMatrixModelActiveCells);
|
|
||||||
cellK.reserve(numMatrixModelActiveCells);
|
|
||||||
parentGridNumber.reserve(numMatrixModelActiveCells);
|
|
||||||
hostCellI.reserve(numMatrixModelActiveCells);
|
|
||||||
hostCellJ.reserve(numMatrixModelActiveCells);
|
|
||||||
hostCellK.reserve(numMatrixModelActiveCells);
|
|
||||||
globalCoarseningBoxIdx.reserve(numMatrixModelActiveCells);
|
|
||||||
|
|
||||||
const std::vector<RigCell>& globalCells = reservoirCase->reservoirData()->mainGrid()->cells();
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<size_t> globalCoarseningBoxIndexStart;
|
|
||||||
{
|
|
||||||
size_t globalCoarseningBoxCount = 0;
|
|
||||||
|
|
||||||
for (size_t gridIdx = 0; gridIdx < reservoirCase->reservoirData()->gridCount(); gridIdx++)
|
|
||||||
{
|
|
||||||
globalCoarseningBoxIndexStart.push_back(globalCoarseningBoxCount);
|
|
||||||
|
|
||||||
RigGridBase* grid = reservoirCase->reservoirData()->grid(gridIdx);
|
|
||||||
|
|
||||||
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
|
||||||
globalCoarseningBoxCount += localCoarseningBoxCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t cIdx = 0; cIdx < globalCells.size(); ++cIdx)
|
|
||||||
{
|
|
||||||
if (actCellInfo->isActive(cIdx))
|
|
||||||
{
|
|
||||||
RigGridBase* grid = globalCells[cIdx].hostGrid();
|
|
||||||
CVF_ASSERT(grid != NULL);
|
|
||||||
size_t cellIndex = globalCells[cIdx].cellIndex();
|
|
||||||
|
|
||||||
size_t i, j, k;
|
|
||||||
grid->ijkFromCellIndex(cellIndex, &i, &j, &k);
|
|
||||||
|
|
||||||
size_t pi, pj, pk;
|
|
||||||
RigGridBase* parentGrid = NULL;
|
|
||||||
|
|
||||||
if (grid->isMainGrid())
|
|
||||||
{
|
|
||||||
pi = i;
|
|
||||||
pj = j;
|
|
||||||
pk = k;
|
|
||||||
parentGrid = grid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t parentCellIdx = globalCells[cIdx].parentCellIndex();
|
|
||||||
parentGrid = (static_cast<RigLocalGrid*>(grid))->parentGrid();
|
|
||||||
CVF_ASSERT(parentGrid != NULL);
|
|
||||||
parentGrid->ijkFromCellIndex(parentCellIdx, &pi, &pj, &pk);
|
|
||||||
}
|
|
||||||
|
|
||||||
gridNumber.push_back(static_cast<qint32>(grid->gridIndex()));
|
|
||||||
cellI.push_back(static_cast<qint32>(i + 1)); // NB: 1-based index in Octave
|
|
||||||
cellJ.push_back(static_cast<qint32>(j + 1)); // NB: 1-based index in Octave
|
|
||||||
cellK.push_back(static_cast<qint32>(k + 1)); // NB: 1-based index in Octave
|
|
||||||
|
|
||||||
parentGridNumber.push_back(static_cast<qint32>(parentGrid->gridIndex()));
|
|
||||||
hostCellI.push_back(static_cast<qint32>(pi + 1)); // NB: 1-based index in Octave
|
|
||||||
hostCellJ.push_back(static_cast<qint32>(pj + 1)); // NB: 1-based index in Octave
|
|
||||||
hostCellK.push_back(static_cast<qint32>(pk + 1)); // NB: 1-based index in Octave
|
|
||||||
|
|
||||||
size_t coarseningIdx = globalCells[cIdx].coarseningBoxIndex();
|
|
||||||
if (coarseningIdx != cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
size_t globalCoarseningIdx = globalCoarseningBoxIndexStart[grid->gridIndex()] + coarseningIdx;
|
|
||||||
|
|
||||||
globalCoarseningBoxIdx.push_back(static_cast<qint32>(globalCoarseningIdx + 1)); // NB: 1-based index in Octave
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
globalCoarseningBoxIdx.push_back(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetActiveCellInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellInfo>(RiaGetActiveCellInfo::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
class RiaGetActiveCellProperty: public RiaSocketCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static QString commandName () { return QString("GetActiveCellProperty"); }
|
|
||||||
|
|
||||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
|
||||||
{
|
|
||||||
|
|
||||||
RimCase* rimCase = findCaseFromArgs(server, args);
|
|
||||||
|
|
||||||
QString propertyName = args[2];
|
|
||||||
QString porosityModelName = args[3];
|
|
||||||
|
|
||||||
RifReaderInterface::PorosityModelResultType porosityModelEnum = RifReaderInterface::MATRIX_RESULTS;
|
|
||||||
if (porosityModelName == "Fracture")
|
|
||||||
{
|
|
||||||
porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the requested data
|
|
||||||
|
|
||||||
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
|
||||||
std::vector< std::vector<double> >* scalarResultFrames = NULL;
|
|
||||||
|
|
||||||
if (rimCase && rimCase->results(porosityModelEnum))
|
|
||||||
{
|
|
||||||
scalarResultIndex = rimCase->results(porosityModelEnum)->findOrLoadScalarResult(propertyName);
|
|
||||||
|
|
||||||
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
scalarResultFrames = &(rimCase->results(porosityModelEnum)->cellResults()->cellScalarResults(scalarResultIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scalarResultFrames == NULL)
|
|
||||||
{
|
|
||||||
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the %1 model property named: \"%2\"").arg(porosityModelName).arg(propertyName));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data back : timeStepCount, bytesPrTimestep, dataForTimestep0 ... dataForTimestepN
|
|
||||||
|
|
||||||
if ( scalarResultFrames == NULL)
|
|
||||||
{
|
|
||||||
// No data available
|
|
||||||
socketStream << (quint64)0 << (quint64)0 ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Create a list of all the requested timesteps
|
|
||||||
|
|
||||||
std::vector<size_t> requestedTimesteps;
|
|
||||||
|
|
||||||
if (args.size() <= 4)
|
|
||||||
{
|
|
||||||
// Select all
|
|
||||||
for (size_t tsIdx = 0; tsIdx < scalarResultFrames->size(); ++tsIdx)
|
|
||||||
{
|
|
||||||
requestedTimesteps.push_back(tsIdx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool timeStepReadError = false;
|
|
||||||
for (int argIdx = 4; argIdx < args.size(); ++argIdx)
|
|
||||||
{
|
|
||||||
bool conversionOk = false;
|
|
||||||
int tsIdx = args[argIdx].toInt(&conversionOk);
|
|
||||||
|
|
||||||
if (conversionOk)
|
|
||||||
{
|
|
||||||
requestedTimesteps.push_back(tsIdx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
timeStepReadError = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeStepReadError)
|
|
||||||
{
|
|
||||||
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetActiveCellProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps."));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// First write timestep count
|
|
||||||
quint64 timestepCount = (quint64)requestedTimesteps.size();
|
|
||||||
socketStream << timestepCount;
|
|
||||||
|
|
||||||
// then the byte-size of the result values in one timestep
|
|
||||||
|
|
||||||
const RigActiveCellInfo* activeInfo = rimCase->reservoirData()->activeCellInfo(porosityModelEnum);
|
|
||||||
size_t timestepResultCount = activeInfo->globalActiveCellCount();
|
|
||||||
|
|
||||||
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
|
|
||||||
socketStream << timestepByteCount ;
|
|
||||||
|
|
||||||
// Then write the data.
|
|
||||||
|
|
||||||
size_t globalCellCount = activeInfo->globalCellCount();
|
|
||||||
for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx)
|
|
||||||
{
|
|
||||||
for (size_t gcIdx = 0; gcIdx < globalCellCount; ++gcIdx)
|
|
||||||
{
|
|
||||||
size_t resultIdx = activeInfo->cellResultIndex(gcIdx);
|
|
||||||
if (resultIdx != cvf::UNDEFINED_SIZE_T)
|
|
||||||
{
|
|
||||||
if (resultIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size())
|
|
||||||
{
|
|
||||||
socketStream << scalarResultFrames->at(requestedTimesteps[tIdx])[resultIdx];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
socketStream << HUGE_VAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
// This aproach is faster but does not handle coarsening
|
|
||||||
size_t timestepResultCount = scalarResultFrames->front().size();
|
|
||||||
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
|
|
||||||
socketStream << timestepByteCount ;
|
|
||||||
|
|
||||||
// Then write the data.
|
|
||||||
|
|
||||||
for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx)
|
|
||||||
{
|
|
||||||
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
|
|
||||||
server->currentClient()->write((const char *)scalarResultFrames->at(requestedTimesteps[tIdx]).data(), timestepByteCount); // Raw print of data. Fast but no platform conversion
|
|
||||||
#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well
|
|
||||||
for (size_t cIdx = 0; cIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size(); ++cIdx)
|
|
||||||
{
|
|
||||||
socketStream << scalarResultFrames->at(tIdx)[cIdx];
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool RiaGetActiveCellProperty_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellProperty>(RiaGetActiveCellProperty::commandName());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RiaStdInclude.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
#include "RiaSocketServer.h"
|
||||||
|
#include "RimCase.h"
|
||||||
|
#include "RimCaseCollection.h"
|
||||||
|
#include "RimIdenticalGridCaseGroup.h"
|
||||||
|
#include "RimInputCase.h"
|
||||||
|
|
||||||
|
#include "RimReservoirView.h"
|
||||||
|
#include "RimResultSlot.h"
|
||||||
|
#include "RimCellEdgeResultSlot.h"
|
||||||
|
#include "RimCellRangeFilterCollection.h"
|
||||||
|
#include "RimCellPropertyFilterCollection.h"
|
||||||
|
#include "RimWellCollection.h"
|
||||||
|
#include "Rim3dOverlayInfoConfig.h"
|
||||||
|
#include "RimReservoirCellResultsCacher.h"
|
||||||
|
|
||||||
|
#include "RimInputPropertyCollection.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RimCase* RiaSocketTools::findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args)
|
||||||
|
{
|
||||||
|
RimCase* rimCase = NULL;
|
||||||
|
int caseId = -1;
|
||||||
|
|
||||||
|
if (args.size() > 1)
|
||||||
|
{
|
||||||
|
caseId = args[1].toInt();
|
||||||
|
}
|
||||||
|
rimCase = server->findReservoir(caseId);
|
||||||
|
|
||||||
|
if (rimCase == NULL)
|
||||||
|
{
|
||||||
|
// TODO: Display error message a different place to avoid socket comm to be halted.
|
||||||
|
//server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the Case with CaseId : \"%1\"").arg(caseId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rimCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaSocketTools::getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId)
|
||||||
|
{
|
||||||
|
CVF_ASSERT(rimCase);
|
||||||
|
|
||||||
|
caseId = rimCase->caseId;
|
||||||
|
caseName = rimCase->caseUserDescription;
|
||||||
|
|
||||||
|
RimCaseCollection* caseCollection = rimCase->parentCaseCollection();
|
||||||
|
if (caseCollection)
|
||||||
|
{
|
||||||
|
caseGroupId = caseCollection->parentCaseGroup()->groupId;
|
||||||
|
|
||||||
|
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
|
||||||
|
{
|
||||||
|
caseType = "StatisticsCase";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
caseType = "SourceCase";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
caseGroupId = -1;
|
||||||
|
|
||||||
|
if (dynamic_cast<RimInputCase*>(rimCase))
|
||||||
|
{
|
||||||
|
caseType = "InputCase";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
caseType = "ResultCase";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||||
|
//
|
||||||
|
// ResInsight is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class RimCase;
|
||||||
|
class RiaSocketServer;
|
||||||
|
|
||||||
|
|
||||||
|
class RiaSocketTools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static RimCase* findCaseFromArgs(RiaSocketServer* server, const QList<QByteArray>& args);
|
||||||
|
static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user