Test for ijk dimention match before reading data

Whitespace fixup
p4#: 21749
This commit is contained in:
Magne Sjaastad 2013-05-28 11:11:32 +02:00
parent 3b05c59b55
commit 408795c0fc

View File

@ -51,7 +51,6 @@ public:
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{ {
RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args); RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
QString propertyName = args[2]; QString propertyName = args[2];
@ -679,277 +678,296 @@ public:
m_currentTimeStepNumberToRead(0), m_currentTimeStepNumberToRead(0),
m_invalidDataDetected(false), m_invalidDataDetected(false),
m_porosityModelEnum(RifReaderInterface::MATRIX_RESULTS) m_porosityModelEnum(RifReaderInterface::MATRIX_RESULTS)
{} {}
static QString commandName () { return QString("SetGridProperty"); } static QString commandName () { return QString("SetGridProperty"); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{ {
int caseId = args[1].toInt(); int caseId = args[1].toInt();
RimCase* rimCase = server->findReservoir(caseId); RimCase* rimCase = server->findReservoir(caseId);
if (!rimCase) if (!rimCase)
{ {
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID : \"%1\"").arg(caseId)); server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID : \"%1\"").arg(caseId));
return true; return true;
} }
m_currentGridIndex = args[2].toInt(); m_currentGridIndex = args[2].toInt();
QString propertyName = args[3]; QString propertyName = args[3];
QString porosityModelName = args[4]; QString porosityModelName = args[4];
if (porosityModelName == "Fracture") if (porosityModelName == "Fracture")
{ {
m_porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS; m_porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS;
} }
// Find the requested data, Or create a set if we are setting data and it is not found RigGridBase* grid = rimCase->reservoirData()->grid(m_currentGridIndex);
if (server->currentClient()->bytesAvailable() < (int)sizeof(quint64)*5) return true; if (!grid)
{
quint64 cellCountI = 0; server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the grid index : %1").arg(m_currentGridIndex));
quint64 cellCountJ = 0; return true;
quint64 cellCountK = 0; }
socketStream >> cellCountI;
socketStream >> cellCountJ;
socketStream >> cellCountK;
socketStream >> m_timeStepCountToRead;
socketStream >> m_bytesPerTimeStepToRead;
// Read header
if (server->currentClient()->bytesAvailable() < (int)sizeof(quint64)*5) return true;
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; quint64 cellCountI = 0;
std::vector< std::vector<double> >* scalarResultFrames = NULL; quint64 cellCountJ = 0;
quint64 cellCountK = 0;
socketStream >> cellCountI;
socketStream >> cellCountJ;
socketStream >> cellCountK;
if (rimCase && rimCase->results(m_porosityModelEnum)) if (grid->cellCountI() != cellCountI ||
{ grid->cellCountJ() != cellCountJ ||
scalarResultIndex = rimCase->results(m_porosityModelEnum)->findOrLoadScalarResult(RimDefines::GENERATED, propertyName); grid->cellCountK() != cellCountK)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Destination grid size do not match incoming grid size for grid index : %1").arg(m_currentGridIndex));
return true;
}
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) socketStream >> m_timeStepCountToRead;
{ socketStream >> m_bytesPerTimeStepToRead;
scalarResultIndex = rimCase->results(m_porosityModelEnum)->cellResults()->addEmptyScalarResult(RimDefines::GENERATED, propertyName, true);
}
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T) if (m_timeStepCountToRead == 0 || m_bytesPerTimeStepToRead == 0)
{ {
scalarResultFrames = &(rimCase->results(m_porosityModelEnum)->cellResults()->cellScalarResults(scalarResultIndex)); server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
m_currentScalarIndex = scalarResultIndex; RiaSocketServer::tr("Zero data to read for ") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n");
m_currentPropertyName = propertyName; }
}
}
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));
return true;
}
// Create a list of all the requested timesteps size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
std::vector< std::vector<double> >* scalarResultFrames = NULL;
m_requestedTimesteps.clear(); if (rimCase && rimCase->results(m_porosityModelEnum))
{
scalarResultIndex = rimCase->results(m_porosityModelEnum)->findOrLoadScalarResult(RimDefines::GENERATED, propertyName);
if (args.size() <= 5) if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{ {
// Select all scalarResultIndex = rimCase->results(m_porosityModelEnum)->cellResults()->addEmptyScalarResult(RimDefines::GENERATED, propertyName, true);
for (size_t tsIdx = 0; tsIdx < m_timeStepCountToRead; ++tsIdx) }
{
m_requestedTimesteps.push_back(tsIdx);
}
}
else
{
bool timeStepReadError = false;
for (int argIdx = 5; argIdx < args.size(); ++argIdx)
{
bool conversionOk = false;
int tsIdx = args[argIdx].toInt(&conversionOk);
if (conversionOk) if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{ {
m_requestedTimesteps.push_back(tsIdx); scalarResultFrames = &(rimCase->results(m_porosityModelEnum)->cellResults()->cellScalarResults(scalarResultIndex));
} m_currentScalarIndex = scalarResultIndex;
else m_currentPropertyName = propertyName;
{ }
timeStepReadError = true; }
}
}
if (timeStepReadError) if (scalarResultFrames == NULL)
{ {
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetActiveCellProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps.")); server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the %1 model property named: \"%2\"").arg(porosityModelName).arg(propertyName));
} return true;
}
} // Create a list of all the requested timesteps
if (! m_requestedTimesteps.size()) m_requestedTimesteps.clear();
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("No time steps specified").arg(porosityModelName).arg(propertyName));
return true; if (args.size() <= 5)
} {
// Select all
for (size_t tsIdx = 0; tsIdx < m_timeStepCountToRead; ++tsIdx)
{
m_requestedTimesteps.push_back(tsIdx);
}
}
else
{
bool timeStepReadError = false;
for (int argIdx = 5; argIdx < args.size(); ++argIdx)
{
bool conversionOk = false;
int tsIdx = args[argIdx].toInt(&conversionOk);
// Resize the result container to be able to receive time steps at the specified time step indices if (conversionOk)
{
m_requestedTimesteps.push_back(tsIdx);
}
else
{
timeStepReadError = true;
}
}
std::vector<size_t>::iterator maxTimeStepIt = std::max_element(m_requestedTimesteps.begin(), m_requestedTimesteps.end()); if (timeStepReadError)
CVF_ASSERT(maxTimeStepIt != m_requestedTimesteps.end()); {
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetActiveCellProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps."));
}
size_t maxTimeStepIdx = (*maxTimeStepIt); }
if (scalarResultFrames->size() <= maxTimeStepIdx)
{
scalarResultFrames->resize(maxTimeStepIdx+1);
}
m_currentReservoir = rimCase; if (! m_requestedTimesteps.size())
m_scalarResultsToAdd = scalarResultFrames; {
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("No time steps specified").arg(porosityModelName).arg(propertyName));
if (server->currentClient()->bytesAvailable()) return true;
{ }
return this->interpretMore(server, server->currentClient());
}
return false; // Resize the result container to be able to receive time steps at the specified time step indices
}
virtual bool interpretMore(RiaSocketServer* server, QTcpSocket* currentClient) std::vector<size_t>::iterator maxTimeStepIt = std::max_element(m_requestedTimesteps.begin(), m_requestedTimesteps.end());
{ CVF_ASSERT(maxTimeStepIt != m_requestedTimesteps.end());
if (m_invalidDataDetected) return true;
if (!currentClient->bytesAvailable()) return false; size_t maxTimeStepIdx = (*maxTimeStepIt);
if (scalarResultFrames->size() <= maxTimeStepIdx)
{
scalarResultFrames->resize(maxTimeStepIdx+1);
}
QDataStream socketStream(currentClient); m_currentReservoir = rimCase;
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion); m_scalarResultsToAdd = scalarResultFrames;
RigGridBase* grid = m_currentReservoir->reservoirData()->grid(m_currentGridIndex); if (server->currentClient()->bytesAvailable())
if (!grid) {
{ return this->interpretMore(server, server->currentClient());
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + }
RiaSocketServer::tr("No grid found") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n");
m_invalidDataDetected = true; return false;
currentClient->abort(); }
return true; virtual bool interpretMore(RiaSocketServer* server, QTcpSocket* currentClient)
} {
if (m_invalidDataDetected) return true;
// If we have not read the header and there are data enough: Read it. if (!currentClient->bytesAvailable()) return false;
// Do nothing if we have not enough data
if (m_timeStepCountToRead == 0 || m_bytesPerTimeStepToRead == 0) QDataStream socketStream(currentClient);
{ socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("Zero data to read for ") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n");
m_invalidDataDetected = true; RigGridBase* grid = m_currentReservoir->reservoirData()->grid(m_currentGridIndex);
currentClient->abort(); if (!grid)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("No grid found") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n");
return true; m_invalidDataDetected = true;
} currentClient->abort();
if (m_timeStepCountToRead != m_requestedTimesteps.size()) return true;
{ }
CVF_ASSERT(false);
}
// If nothing should be read, or we already have read everything, do nothing // Do nothing if we have not enough data
if (m_timeStepCountToRead == 0 || m_bytesPerTimeStepToRead == 0)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("Zero data to read for ") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n");
if ((m_timeStepCountToRead == 0) || (m_currentTimeStepNumberToRead >= m_timeStepCountToRead) ) return true; m_invalidDataDetected = true;
currentClient->abort();
// Check if a complete timestep is available, return and whait for readyRead() if not return true;
if (currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return false; }
size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double); if (m_timeStepCountToRead != m_requestedTimesteps.size())
{
CVF_ASSERT(false);
}
RigActiveCellInfo* activeCellInfo = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum); // If nothing should be read, or we already have read everything, do nothing
size_t globalCellResultCount = activeCellInfo->globalCellResultCount();
// Make sure the size of the retreiving container is correct. if ((m_timeStepCountToRead == 0) || (m_currentTimeStepNumberToRead >= m_timeStepCountToRead) ) return true;
// If it is, this is noops
for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx) // Check if a complete timestep is available, return and whait for readyRead() if not
{ if (currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return false;
size_t tsId = m_requestedTimesteps[tIdx];
m_scalarResultsToAdd->at(tsId).resize(globalCellResultCount, HUGE_VAL);
}
if ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepNumberToRead < m_timeStepCountToRead)) size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double);
{
// Read a single time step with data
std::vector<double> doubleValues(cellCountFromOctave); RigActiveCellInfo* activeCellInfo = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum);
size_t globalCellResultCount = activeCellInfo->globalCellResultCount();
qint64 bytesRead = currentClient->read((char*)(doubleValues.data()), m_bytesPerTimeStepToRead); // Make sure the size of the retreiving container is correct.
size_t doubleValueIndex = 0; // If it is, this is noops
for (size_t k = 0; k < grid->cellCountK(); k++) for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx)
{ {
for (size_t j = 0; j < grid->cellCountJ(); j++) size_t tsId = m_requestedTimesteps[tIdx];
{ m_scalarResultsToAdd->at(tsId).resize(globalCellResultCount, HUGE_VAL);
for (size_t i = 0; i < grid->cellCountI(); i++) }
{
size_t localCellIndex = grid->cellIndexFromIJK(i,j,k);
size_t gcIdx = grid->globalGridCellIndex(localCellIndex);
size_t resultIdx = activeCellInfo->cellResultIndex(gcIdx); if ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepNumberToRead < m_timeStepCountToRead))
{
// Read a single time step with data
if (resultIdx < m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead]).size()) std::vector<double> doubleValues(cellCountFromOctave);
{
m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead])[resultIdx] = doubleValues[doubleValueIndex];
}
doubleValueIndex++; qint64 bytesRead = currentClient->read((char*)(doubleValues.data()), m_bytesPerTimeStepToRead);
} size_t doubleValueIndex = 0;
}
}
++m_currentTimeStepNumberToRead; for (size_t k = 0; k < grid->cellCountK(); k++)
} {
for (size_t j = 0; j < grid->cellCountJ(); j++)
{
for (size_t i = 0; i < grid->cellCountI(); i++)
{
size_t localCellIndex = grid->cellIndexFromIJK(i,j,k);
size_t gcIdx = grid->globalGridCellIndex(localCellIndex);
// If we have read all the data, refresh the views size_t resultIdx = activeCellInfo->cellResultIndex(gcIdx);
if (m_currentTimeStepNumberToRead == m_timeStepCountToRead) if (resultIdx < m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead]).size())
{ {
if (m_currentReservoir != NULL) m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead])[resultIdx] = doubleValues[doubleValueIndex];
{ }
// Create a new input property if we have an input reservoir
RimInputCase* inputRes = dynamic_cast<RimInputCase*>(m_currentReservoir);
if (inputRes)
{
RimInputProperty* inputProperty = NULL;
inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName);
if (!inputProperty)
{
inputProperty = new RimInputProperty;
inputProperty->resultName = m_currentPropertyName;
inputProperty->eclipseKeyword = "";
inputProperty->fileName = "";
inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty);
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
treeModel->updateUiSubTree(inputRes->m_inputPropertyCollection());
}
inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED;
}
if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T && doubleValueIndex++;
m_currentReservoir->reservoirData() && }
m_currentReservoir->reservoirData()->results(m_porosityModelEnum) ) }
{ }
m_currentReservoir->reservoirData()->results(m_porosityModelEnum)->recalculateMinMax(m_currentScalarIndex);
}
for (size_t i = 0; i < m_currentReservoir->reservoirViews.size(); ++i) ++m_currentTimeStepNumberToRead;
{ }
if (m_currentReservoir->reservoirViews[i])
{
m_currentReservoir->reservoirViews[i]->updateCurrentTimeStepAndRedraw();
}
}
}
return true; // If we have read all the data, refresh the views
}
return false; if (m_currentTimeStepNumberToRead == m_timeStepCountToRead)
} {
if (m_currentReservoir != NULL)
{
// Create a new input property if we have an input reservoir
RimInputCase* inputRes = dynamic_cast<RimInputCase*>(m_currentReservoir);
if (inputRes)
{
RimInputProperty* inputProperty = NULL;
inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName);
if (!inputProperty)
{
inputProperty = new RimInputProperty;
inputProperty->resultName = m_currentPropertyName;
inputProperty->eclipseKeyword = "";
inputProperty->fileName = "";
inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty);
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
treeModel->updateUiSubTree(inputRes->m_inputPropertyCollection());
}
inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED;
}
if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T &&
m_currentReservoir->reservoirData() &&
m_currentReservoir->reservoirData()->results(m_porosityModelEnum) )
{
m_currentReservoir->reservoirData()->results(m_porosityModelEnum)->recalculateMinMax(m_currentScalarIndex);
}
for (size_t i = 0; i < m_currentReservoir->reservoirViews.size(); ++i)
{
if (m_currentReservoir->reservoirViews[i])
{
m_currentReservoir->reservoirViews[i]->updateCurrentTimeStepAndRedraw();
}
}
}
return true;
}
return false;
}
private: private:
RimCase* m_currentReservoir; RimCase* m_currentReservoir;