mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
SocketServer: GetActiveCellInfo moved to new regime
p4#: 21649
This commit is contained in:
parent
a63b2caae5
commit
6173381652
@ -371,6 +371,13 @@ public:
|
||||
}
|
||||
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 true;
|
||||
}
|
||||
|
||||
|
||||
// Write data back to octave: I, J, K dimensions
|
||||
|
||||
size_t iCount = 0;
|
||||
@ -391,6 +398,173 @@ public:
|
||||
};
|
||||
|
||||
static bool RiaGetMainGridDimensions_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetMainGridDimensions>(RiaGetMainGridDimensions::commandName());
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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>& coarseBoxIdx)
|
||||
{
|
||||
gridNumber.clear();
|
||||
cellI.clear();
|
||||
cellJ.clear();
|
||||
cellK.clear();
|
||||
parentGridNumber.clear();
|
||||
hostCellI.clear();
|
||||
hostCellJ.clear();
|
||||
hostCellK.clear();
|
||||
coarseBoxIdx.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);
|
||||
coarseBoxIdx.reserve(numMatrixModelActiveCells);
|
||||
|
||||
const std::vector<RigCell>& globalCells = reservoirCase->reservoirData()->mainGrid()->cells();
|
||||
|
||||
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
|
||||
|
||||
// TODO: Handle coarse box concept
|
||||
coarseBoxIdx.push_back(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class RiaGetActiveCellInfo: public RiaSocketCommand
|
||||
{
|
||||
public:
|
||||
static QString commandName () { return QString("GetActiveCellInfo"); }
|
||||
|
||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||
{
|
||||
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 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 bool RiaGetActiveCellInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellInfo>(RiaGetActiveCellInfo::commandName());
|
||||
|
||||
|
||||
|
||||
|
||||
@ -598,9 +772,8 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
|
||||
bool isGetProperty = args[0] == "GetProperty"; // GetProperty [casename/index] PropertyName
|
||||
bool isSetProperty = args[0] == "SetProperty"; // SetProperty [casename/index] PropertyName
|
||||
bool isGetCellInfo = args[0] == "GetActiveCellInfo"; // GetActiveCellInfo [casename/index]
|
||||
|
||||
if (!(isGetProperty || isSetProperty || isGetCellInfo ))
|
||||
if (!(isGetProperty || isSetProperty ))
|
||||
{
|
||||
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
|
||||
terminateCurrentConnection();
|
||||
@ -625,13 +798,7 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
propertyName = args[2];
|
||||
}
|
||||
}
|
||||
else if (isGetCellInfo )
|
||||
{
|
||||
if (args.size() > 1)
|
||||
{
|
||||
caseId = args[1].toInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rimCase = this->findReservoir(caseId);
|
||||
|
||||
@ -724,63 +891,7 @@ void RiaSocketServer::readCommandFromOctave()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isGetCellInfo)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
m_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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -982,83 +1093,3 @@ void RiaSocketServer::slotReadyRead()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::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>& coarseBoxIdx)
|
||||
{
|
||||
gridNumber.clear();
|
||||
cellI.clear();
|
||||
cellJ.clear();
|
||||
cellK.clear();
|
||||
parentGridNumber.clear();
|
||||
hostCellI.clear();
|
||||
hostCellJ.clear();
|
||||
hostCellK.clear();
|
||||
coarseBoxIdx.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);
|
||||
coarseBoxIdx.reserve(numMatrixModelActiveCells);
|
||||
|
||||
const std::vector<RigCell>& globalCells = reservoirCase->reservoirData()->mainGrid()->cells();
|
||||
|
||||
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
|
||||
|
||||
// TODO: Handle coarse box concept
|
||||
coarseBoxIdx.push_back(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
~RiaSocketServer();
|
||||
unsigned short serverPort();
|
||||
RimCase* findReservoir(int caseId);
|
||||
QErrorMessage* errorMessageDialog() { return m_errorMessageDialog; }
|
||||
QTcpSocket* currentClient() { return m_currentClient; }
|
||||
|
||||
private slots:
|
||||
void slotNewClientConnection();
|
||||
@ -59,18 +61,6 @@ private:
|
||||
void handleClientConnection( QTcpSocket* clientToHandle);
|
||||
void terminateCurrentConnection();
|
||||
|
||||
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>& coarseBoxIdx);
|
||||
|
||||
private:
|
||||
QTcpServer* m_tcpServer;
|
||||
QErrorMessage* m_errorMessageDialog;
|
||||
|
Loading…
Reference in New Issue
Block a user