SocketServer: Moved GetProperty command to new regime.

p4#: 21654
This commit is contained in:
Jacob Støren 2013-05-16 13:29:38 +02:00
parent 86a53980a4
commit bb0c4c37c1
2 changed files with 184 additions and 151 deletions

View File

@ -66,6 +66,25 @@ public:
typedef caf::Factory<RiaSocketCommand, QString> RiaSocketCommandFactory;
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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -362,21 +381,8 @@ public:
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;
}
RimCase* rimCase = findCaseFromArgs(server, args);
if (!rimCase) return true;
// Write data back to octave: I, J, K dimensions
@ -398,10 +404,82 @@ 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)
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>& coarseBoxIdx)
{
gridNumber.clear();
cellI.clear();
@ -478,93 +556,84 @@ void calculateMatrixModelActiveCellInfo(RimCase* reservoirCase, RifReaderInterfa
}
}
};
static bool RiaGetActiveCellInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellInfo>(RiaGetActiveCellInfo::commandName());
class RiaGetActiveCellInfo: public RiaSocketCommand
class RiaGetProperty: public RiaSocketCommand
{
public:
static QString commandName () { return QString("GetActiveCellInfo"); }
static QString commandName () { return QString("GetProperty"); }
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)
RimCase* rimCase = findCaseFromArgs(server, args);
if (!rimCase) return true;
QString propertyName = args[2];
// Find the requested data, Or create a set if we are setting data and it is not found
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
std::vector< std::vector<double> >* scalarResultFrames = NULL;
if (rimCase && rimCase->results(RifReaderInterface::MATRIX_RESULTS))
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the Case with CaseId : \"%1\"").arg(caseId));
return true;
scalarResultIndex = rimCase->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResult(propertyName);
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{
scalarResultFrames = &(rimCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->cellScalarResults(scalarResultIndex));
}
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
if (scalarResultFrames == NULL)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the property named: \"%1\"").arg(propertyName));
}
caf::FixedArray<std::vector<qint32>, 9> activeCellInfo;
if (!(rimCase && rimCase->reservoirData() && rimCase->reservoirData()->mainGrid()) )
// Write data back : timeStepCount, bytesPrTimestep, dataForTimestep0 ... dataForTimestepN
if ( scalarResultFrames == NULL)
{
// No data available
socketStream << (quint64)0 << (quint64)0 ;
return true;
}
else
{
// First write timestep count
quint64 timestepCount = (quint64)scalarResultFrames->size();
socketStream << timestepCount;
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));
// then the byte-size of the result values in one timestep
size_t timestepResultCount = scalarResultFrames->front().size();
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
socketStream << timestepByteCount ;
// Then write the data.
for (size_t tIdx = 0; tIdx < columnCount; ++tIdx)
for (size_t tIdx = 0; tIdx < scalarResultFrames->size(); ++tIdx)
{
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount);
server->currentClient()->write((const char *)scalarResultFrames->at(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 < activeCellInfo[tIdx].size(); ++cIdx)
for (size_t cIdx = 0; cIdx < scalarResultFrames->at(tIdx).size(); ++cIdx)
{
socketStream << activeCellInfo[tIdx][cIdx];
socketStream << scalarResultFrames->at(tIdx)[cIdx];
}
#endif
}
}
return true;
}
};
static bool RiaGetActiveCellInfo_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetActiveCellInfo>(RiaGetActiveCellInfo::commandName());
static bool RiaGetProperty_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetProperty>(RiaGetProperty::commandName());
@ -770,10 +839,9 @@ void RiaSocketServer::readCommandFromOctave()
// Todo: When all commands are into new shape, do the "unknown command" error output here.
bool isGetProperty = args[0] == "GetProperty"; // GetProperty [casename/index] PropertyName
bool isSetProperty = args[0] == "SetProperty"; // SetProperty [casename/index] PropertyName
if (!(isGetProperty || isSetProperty ))
if (!( isSetProperty ))
{
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
terminateCurrentConnection();
@ -786,7 +854,7 @@ void RiaSocketServer::readCommandFromOctave()
// Find the correct arguments
if (isGetProperty || isSetProperty)
if (isSetProperty)
{
if (args.size() == 2)
{
@ -809,7 +877,7 @@ void RiaSocketServer::readCommandFromOctave()
return;
}
if (isGetProperty || isSetProperty)
if (isSetProperty)
{
// Find the requested data, Or create a set if we are setting data and it is not found
@ -839,42 +907,7 @@ void RiaSocketServer::readCommandFromOctave()
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Could not find the property named: \"%1\"").arg(propertyName));
}
if (isGetProperty )
{
// Write data back : timeStepCount, bytesPrTimestep, dataForTimestep0 ... dataForTimestepN
if ( scalarResultFrames == NULL)
{
// No data available
socketStream << (quint64)0 << (quint64)0 ;
}
else
{
// First write timestep count
quint64 timestepCount = (quint64)scalarResultFrames->size();
socketStream << timestepCount;
// then the byte-size of the result values in one timestep
size_t timestepResultCount = scalarResultFrames->front().size();
quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double));
socketStream << timestepByteCount ;
// Then write the data.
for (size_t tIdx = 0; tIdx < scalarResultFrames->size(); ++tIdx)
{
#if 1 // Write data as raw bytes, fast but does not handle byteswapping
m_currentClient->write((const char *)scalarResultFrames->at(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(tIdx).size(); ++cIdx)
{
socketStream << scalarResultFrames->at(tIdx)[cIdx];
}
#endif
}
}
}
else // Set property
// Set property
{
m_readState = ReadingPropertyData;

View File

@ -98,7 +98,7 @@ void getEclipseProperty(Matrix& propertyFrames, const QString &hostName, quint16
QString tmp = QString("riGetActiveCellProperty : Read %1").arg(propertyName);
if (caseName.isEmpty())
if (caseName == "-1")
{
tmp += QString(" from active case.");
}
@ -141,7 +141,7 @@ DEFUN_DLD (riGetActiveCellProperty, args, nargout,
if (nargin > 1)
getEclipseProperty(propertyFrames, "127.0.0.1", 40001, args(0).char_matrix_value().row_as_string(0).c_str(), args(1).char_matrix_value().row_as_string(0).c_str());
else
getEclipseProperty(propertyFrames, "127.0.0.1", 40001, "", args(0).char_matrix_value().row_as_string(0).c_str());
getEclipseProperty(propertyFrames, "127.0.0.1", 40001, "-1", args(0).char_matrix_value().row_as_string(0).c_str());
return octave_value(propertyFrames);
}