mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1675 Selected cell interface for Octave
This commit is contained in:
@@ -38,9 +38,12 @@
|
||||
#include "RimEclipseInputPropertyCollection.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimReservoirCellResultsStorage.h"
|
||||
#include "RimGeoMechView.h"
|
||||
#include "RimGeoMechCase.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuProcessMonitor.h"
|
||||
#include "RiuSelectionManager.h"
|
||||
|
||||
#include <QErrorMessage>
|
||||
|
||||
@@ -1152,3 +1155,163 @@ public:
|
||||
};
|
||||
|
||||
static bool RiaGetPropertyNames_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetPropertyNames>(RiaGetPropertyNames::commandName());
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaGetGridPropertyForSelectedCells: public RiaSocketCommand
|
||||
{
|
||||
public:
|
||||
static QString commandName() { return QString("GetGridPropertyForSelectedCells"); }
|
||||
|
||||
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
|
||||
{
|
||||
RimEclipseCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
|
||||
if (!rimCase) return true;
|
||||
|
||||
QString propertyName = args[2];
|
||||
|
||||
RifReaderInterface::PorosityModelResultType porosityModel = RifReaderInterface::MATRIX_RESULTS;
|
||||
|
||||
if (args.size() > 1)
|
||||
{
|
||||
QString prorosityModelString = args[3];
|
||||
if (prorosityModelString.toUpper() == "FRACTURE")
|
||||
{
|
||||
porosityModel = RifReaderInterface::FRACTURE_RESULTS;
|
||||
}
|
||||
}
|
||||
|
||||
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
|
||||
if (rimCase && rimCase->results(porosityModel))
|
||||
{
|
||||
scalarResultIndex = rimCase->results(porosityModel)->findOrLoadScalarResult(propertyName);
|
||||
}
|
||||
|
||||
std::vector<size_t> requestedTimesteps;
|
||||
if (args.size() < 5)
|
||||
{
|
||||
// Select all
|
||||
for (size_t tsIdx = 0; tsIdx < rimCase->results(porosityModel)->cellResults()->timeStepCount(scalarResultIndex); ++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: riGetGridProperty : \n")
|
||||
+ RiaSocketServer::tr("An error occurred while interpreting the requested time steps."));
|
||||
}
|
||||
|
||||
}
|
||||
if (!(rimCase && rimCase->eclipseCaseData() && rimCase->eclipseCaseData()->mainGrid()) )
|
||||
{
|
||||
// No data available
|
||||
socketStream << (quint64)0 << (quint64)0 ;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector< std::pair<size_t, size_t> > selectedCells = getSelectedCellsForCase(rimCase);
|
||||
|
||||
// First write column count
|
||||
quint64 timestepCount = (quint64)requestedTimesteps.size();
|
||||
socketStream << timestepCount;
|
||||
|
||||
// then the byte-size of the size of one column
|
||||
quint64 timestepByteCount = (quint64)(selectedCells.size()*sizeof(double));
|
||||
socketStream << timestepByteCount;
|
||||
|
||||
size_t valueCount = RiaSocketDataTransfer::maximumValueCountInBlock();
|
||||
std::vector<double> values(valueCount);
|
||||
size_t valueIndex = 0;
|
||||
|
||||
for (size_t timeStep : requestedTimesteps)
|
||||
{
|
||||
const std::vector<double>& scalarResults = rimCase->results(porosityModel)->cellResults()->cellScalarResults(scalarResultIndex, timeStep);
|
||||
|
||||
|
||||
for (const std::pair<size_t, size_t> selectedCell : selectedCells)
|
||||
{
|
||||
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createFromUiResultName(rimCase->eclipseCaseData(), selectedCell.first, porosityModel, timeStep, propertyName);
|
||||
if (resultAccessor.isNull())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
values[valueIndex] = resultAccessor->cellScalar(selectedCell.second);
|
||||
|
||||
valueIndex++;
|
||||
if (valueIndex >= valueCount)
|
||||
{
|
||||
if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
valueIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write remaining data
|
||||
if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::vector< std::pair<size_t, size_t> > getSelectedCellsForCase(const RimCase* reservoirCase)
|
||||
{
|
||||
std::vector<RiuSelectionItem*> items;
|
||||
RiuSelectionManager::instance()->selectedItems(items);
|
||||
|
||||
std::vector< std::pair<size_t, size_t> > selectedCells;
|
||||
|
||||
for (const RiuSelectionItem* item : items)
|
||||
{
|
||||
if (item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT)
|
||||
{
|
||||
const RiuEclipseSelectionItem* eclipseItem = static_cast<const RiuEclipseSelectionItem*>(item);
|
||||
|
||||
if (eclipseItem->m_view->eclipseCase()->caseId == reservoirCase->caseId)
|
||||
{
|
||||
selectedCells.push_back(std::make_pair(eclipseItem->m_gridIndex, eclipseItem->m_cellIndex));
|
||||
}
|
||||
}
|
||||
else if (item->type() == RiuSelectionItem::GEOMECH_SELECTION_OBJECT)
|
||||
{
|
||||
const RiuGeoMechSelectionItem* geomechItem = static_cast<const RiuGeoMechSelectionItem*>(item);
|
||||
|
||||
if (geomechItem->m_view->geoMechCase()->caseId == reservoirCase->caseId)
|
||||
{
|
||||
selectedCells.push_back(std::make_pair(geomechItem->m_gridIndex, geomechItem->m_cellIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return selectedCells;
|
||||
}
|
||||
};
|
||||
|
||||
static bool RiaGetGridPropertyForSelectedCells_init = RiaSocketCommandFactory::instance()->registerCreator<RiaGetGridPropertyForSelectedCells>(RiaGetGridPropertyForSelectedCells::commandName());
|
||||
|
||||
Reference in New Issue
Block a user