Octave interface: SetActiveCellProperty: Now working according to spec.

Not tested for Coarce Cells yet.
p4#: 21723
This commit is contained in:
Jacob Støren 2013-05-26 12:07:42 +02:00
parent f509e1803f
commit 1aa8857f4d
5 changed files with 102 additions and 31 deletions

View File

@ -91,7 +91,11 @@ void RigCaseCellResultsData::minMaxCellScalarValues(size_t scalarResultIndex, si
max = -HUGE_VAL;
CVF_ASSERT(scalarResultIndex < resultCount());
CVF_ASSERT(timeStepIndex < m_cellScalarResults[scalarResultIndex].size() );
if (timeStepIndex >= m_cellScalarResults[scalarResultIndex].size())
{
return;
}
if (scalarResultIndex >= m_maxMinValuesPrTs.size())
{

View File

@ -92,13 +92,13 @@ public:
m_reservoirResultValues(reservoirResultValues),
m_activeCellInfo(activeCellInfo)
{
CVF_ASSERT(reservoirResultValues != NULL);
CVF_ASSERT(grid != NULL);
}
virtual double cellScalar(size_t gridLocalCellIndex) const
{
if (m_reservoirResultValues->size() == 0 ) return HUGE_VAL;
if (m_reservoirResultValues == NULL || m_reservoirResultValues->size() == 0 ) return HUGE_VAL;
size_t globalGridCellIndex = m_grid->globalGridCellIndex(gridLocalCellIndex);
size_t resultValueIndex = m_activeCellInfo->cellResultIndex(globalGridCellIndex);
@ -117,7 +117,7 @@ public:
size_t globalGridCellIndex = m_grid->globalGridCellIndex(gridLocalCellIndex);
size_t resultValueIndex = m_activeCellInfo->cellResultIndex(globalGridCellIndex);
CVF_TIGHT_ASSERT(resultValueIndex < m_reservoirResultValues->size());
CVF_TIGHT_ASSERT(m_reservoirResultValues != NULL && resultValueIndex < m_reservoirResultValues->size());
(*m_reservoirResultValues)[resultValueIndex] = scalarValue;
}
@ -151,12 +151,12 @@ cvf::ref<cvf::StructGridScalarDataAccess> RigGridScalarDataAccessFactory::create
}
std::vector< std::vector<double> >& scalarSetResults = eclipseCase->results(porosityModel)->cellScalarResults(scalarSetIndex);
if (timeStepIndex >= scalarSetResults.size())
{
return NULL;
}
std::vector<double>* resultValues = &(scalarSetResults[timeStepIndex]);
std::vector<double>* resultValues = NULL;
if (timeStepIndex < scalarSetResults.size())
{
resultValues = &(scalarSetResults[timeStepIndex]);
}
bool useGlobalActiveIndex = eclipseCase->results(porosityModel)->isUsingGlobalActiveIndex(scalarSetIndex);
if (useGlobalActiveIndex)

View File

@ -207,7 +207,7 @@ public:
m_currentScalarIndex(cvf::UNDEFINED_SIZE_T),
m_timeStepCountToRead(0),
m_bytesPerTimeStepToRead(0),
m_currentTimeStepToRead(0),
m_currentTimeStepNumberToRead(0),
m_invalidActiveCellCountDetected(false),
m_porosityModelEnum(RifReaderInterface::MATRIX_RESULTS)
{}
@ -233,7 +233,7 @@ public:
if (rimCase && rimCase->results(m_porosityModelEnum))
{
scalarResultIndex = rimCase->results(m_porosityModelEnum)->findOrLoadScalarResult(propertyName);
scalarResultIndex = rimCase->results(m_porosityModelEnum)->findOrLoadScalarResult(RimDefines::GENERATED, propertyName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
@ -292,6 +292,24 @@ public:
}
if (! m_requestedTimesteps.size())
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("No time steps specified").arg(porosityModelName).arg(propertyName));
return true;
}
// Resize the result container to be able to receive timesteps at the specified timestep idices
std::vector<size_t>::iterator maxTimeStepIt = std::max_element(m_requestedTimesteps.begin(), m_requestedTimesteps.end());
CVF_ASSERT(maxTimeStepIt != m_requestedTimesteps.end());
size_t maxTimeStepIdx = (*maxTimeStepIt);
if (scalarResultFrames->size() <= maxTimeStepIdx)
{
scalarResultFrames->resize(maxTimeStepIdx+1);
}
m_currentReservoir = rimCase;
m_scalarResultsToAdd = scalarResultFrames;
@ -323,19 +341,26 @@ public:
socketStream >> m_bytesPerTimeStepToRead;
}
if (m_timeStepCountToRead != m_requestedTimesteps.size())
{
CVF_ASSERT(false);
}
// If nothing should be read, or we already have read everything, do nothing
if ((m_timeStepCountToRead == 0) || (m_currentTimeStepToRead >= m_timeStepCountToRead) ) return true;
if ((m_timeStepCountToRead == 0) || (m_currentTimeStepNumberToRead >= m_timeStepCountToRead) ) return true;
// Check if a complete timestep is available, return and whait for readyRead() if not
if (currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return false;
size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double);
size_t gridActiveCellCount = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum)->globalActiveCellCount();
size_t gridTotalCellCount = m_currentReservoir->reservoirData()->mainGrid()->cellCount();
RigActiveCellInfo* activeCellInfo = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum);
size_t gridActiveCellCount = activeCellInfo->globalActiveCellCount();
size_t gridTotalCellCount = activeCellInfo->globalCellCount();
size_t cellResultCount = activeCellInfo->globalCellResultCount();
if (cellCountFromOctave != gridActiveCellCount && cellCountFromOctave != gridTotalCellCount)
if (cellCountFromOctave != gridActiveCellCount )
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("The number of cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n"
@ -351,17 +376,30 @@ public:
// Make sure the size of the retreiving container is correct.
// If it is, this is noops
m_scalarResultsToAdd->resize(m_timeStepCountToRead);
for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx)
{
m_scalarResultsToAdd->at(tIdx).resize(cellCountFromOctave, HUGE_VAL);
size_t tsId = m_requestedTimesteps[tIdx];
m_scalarResultsToAdd->at(tsId).resize(cellResultCount, HUGE_VAL);
}
std::vector<double> readBuffer;
double * internalMatrixData = NULL;
if (cellResultCount != gridActiveCellCount)
{
readBuffer.resize(cellCountFromOctave, HUGE_VAL);
internalMatrixData = readBuffer.data();
}
// Read available complete timestepdata
while ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepToRead < m_timeStepCountToRead))
while ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepNumberToRead < m_timeStepCountToRead))
{
qint64 bytesRead = 0;
double * internalMatrixData = m_scalarResultsToAdd->at(m_currentTimeStepToRead).data();
if (cellResultCount == gridActiveCellCount)
{
internalMatrixData = m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead]).data();
}
#if 1 // Use raw data transfer. Faster.
bytesRead = currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead);
@ -373,6 +411,19 @@ public:
if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double);
}
#endif
// Map data from active to result index based container ( Coarsening is active)
if (cellResultCount != gridActiveCellCount)
{
size_t acIdx = 0;
for (size_t gcIdx = 0; gcIdx < gridTotalCellCount; ++gcIdx)
{
if (activeCellInfo->isActive(gcIdx))
{
m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead])[activeCellInfo->cellResultIndex(gcIdx)] = readBuffer[acIdx];
++acIdx;
}
}
}
if ((int)m_bytesPerTimeStepToRead != bytesRead)
{
@ -380,11 +431,11 @@ public:
RiaSocketServer::tr("Could not read binary double data properly from socket"));
}
++m_currentTimeStepToRead;
++m_currentTimeStepNumberToRead;
}
// If we have read all the data, refresh the views
if (m_currentTimeStepToRead == m_timeStepCountToRead)
if (m_currentTimeStepNumberToRead == m_timeStepCountToRead)
{
if (m_currentReservoir != NULL)
{
@ -440,7 +491,7 @@ private:
quint64 m_timeStepCountToRead;
quint64 m_bytesPerTimeStepToRead;
size_t m_currentTimeStepToRead;
size_t m_currentTimeStepNumberToRead;
bool m_invalidActiveCellCountDetected;
};

View File

@ -56,15 +56,10 @@ private slots:
void slotNewClientConnection();
void slotCurrentClientDisconnected();
void slotReadyRead();
private:
void readCommandFromOctave();
void readPropertyDataFromOctave();
void handleClientConnection( QTcpSocket* clientToHandle);
void terminateCurrentConnection();
void readCommandFromOctave();
private:
QTcpServer* m_tcpServer;

View File

@ -105,7 +105,7 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout,
if (nargin > 5)
{
error("riGetActiveCellProperty: Too many arguments.\n");
error("riSetActiveCellProperty: Too many arguments.\n");
print_usage();
return octave_value_list ();
}
@ -120,6 +120,15 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout,
return octave_value_list ();
}
dim_vector mxDims = propertyFrames.dims();
if (mxDims.length() != 2)
{
error("riSetActiveCellProperty: The supplied Data Matrix must have two dimensions: NumActiveCells*numTimesteps");
print_usage();
return octave_value_list ();
}
std::vector<int> argIndices;
argIndices.push_back(0);
argIndices.push_back(1);
@ -157,7 +166,7 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout,
// Check if we have more arguments than we should
if (nargin > lastArgumentIndex + 1)
{
error("riGetActiveCellProperty: Unexpected argument after the PorosityModel.\n");
error("riSetActiveCellProperty: Unexpected argument after the PorosityModel.\n");
print_usage();
return octave_value_list ();
}
@ -173,9 +182,21 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout,
if (argIndices[3] >= 0) requestedTimeSteps = args(argIndices[3]).int32_array_value();
if (argIndices[4] >= 0) porosityModel = args(argIndices[4]).string_value();
if (requestedTimeSteps.length())
{
int timeStepCount = mxDims.elem(1);
if (requestedTimeSteps.length() != timeStepCount)
{
error("riSetActiveCellProperty: The number of timesteps in the input matrix must match the number of timesteps in the TimeStepIndices array.");
print_usage();
return octave_value_list ();
}
}
if (porosityModel != "Matrix" && porosityModel != "Fracture")
{
error("riGetActiveCellProperty: The value for \"PorosityModel\" is unknown. Please use either \"Matrix\" or \"Fracture\"\n");
error("riSetActiveCellProperty: The value for \"PorosityModel\" is unknown. Please use either \"Matrix\" or \"Fracture\"\n");
print_usage();
return octave_value_list ();
}