2014-09-23 08:04:57 -05:00
/////////////////////////////////////////////////////////////////////////////////
2013-05-24 04:07:59 -05:00
//
2014-09-23 08:04:57 -05:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2013-05-24 04:07:59 -05:00
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
# include "RiaSocketCommand.h"
2014-08-08 01:37:56 -05:00
# include "RiaSocketDataTransfer.h"
2013-05-24 04:07:59 -05:00
# include "RiaSocketServer.h"
# include "RiaSocketTools.h"
# include "RigCaseCellResultsData.h"
2017-01-10 02:51:39 -06:00
# include "RigEclipseCaseData.h"
2017-01-09 12:04:45 -06:00
# include "RigMainGrid.h"
2015-09-25 08:57:43 -05:00
# include "RigResultAccessor.h"
# include "RigResultAccessorFactory.h"
2014-08-08 01:37:56 -05:00
# include "RigResultModifier.h"
# include "RigResultModifierFactory.h"
2017-08-21 02:11:37 -05:00
# include "RigEclipseResultInfo.h"
2013-05-24 04:07:59 -05:00
2015-09-25 08:57:43 -05:00
# include "RimEclipseCase.h"
# include "RimEclipseCellColors.h"
2015-06-25 06:14:04 -05:00
# include "RimEclipseInputCase.h"
# include "RimEclipseInputProperty.h"
# include "RimEclipseInputPropertyCollection.h"
2017-02-24 04:07:15 -06:00
# include "RimEclipseView.h"
2014-08-08 01:37:56 -05:00
# include "RimReservoirCellResultsStorage.h"
2017-08-03 07:35:46 -05:00
# include "RimGeoMechView.h"
# include "RimGeoMechCase.h"
2014-08-08 01:37:56 -05:00
# include "RiuMainWindow.h"
# include "RiuProcessMonitor.h"
2017-08-03 07:35:46 -05:00
# include "RiuSelectionManager.h"
2015-09-25 08:57:43 -05:00
# include <QErrorMessage>
2013-05-24 04:07:59 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaGetActiveCellProperty : public RiaSocketCommand
{
public :
static QString commandName ( ) { return QString ( " GetActiveCellProperty " ) ; }
virtual bool interpretCommand ( RiaSocketServer * server , const QList < QByteArray > & args , QDataStream & socketStream )
{
2015-05-15 01:40:27 -05:00
RimEclipseCase * rimCase = RiaSocketTools : : findCaseFromArgs ( server , args ) ;
2013-05-24 04:07:59 -05:00
QString propertyName = args [ 2 ] ;
QString porosityModelName = args [ 3 ] ;
2017-08-11 07:05:59 -05:00
RiaDefines : : PorosityModelType porosityModelEnum = RiaDefines : : MATRIX_MODEL ;
2013-05-24 04:07:59 -05:00
if ( porosityModelName = = " Fracture " )
{
2017-08-11 07:05:59 -05:00
porosityModelEnum = RiaDefines : : FRACTURE_MODEL ;
2013-05-24 04:07:59 -05:00
}
// Find the requested data
size_t scalarResultIndex = cvf : : UNDEFINED_SIZE_T ;
std : : vector < std : : vector < double > > * scalarResultFrames = NULL ;
if ( rimCase & & rimCase - > results ( porosityModelEnum ) )
{
scalarResultIndex = rimCase - > results ( porosityModelEnum ) - > findOrLoadScalarResult ( propertyName ) ;
if ( scalarResultIndex ! = cvf : : UNDEFINED_SIZE_T )
{
scalarResultFrames = & ( rimCase - > results ( porosityModelEnum ) - > cellResults ( ) - > cellScalarResults ( scalarResultIndex ) ) ;
}
}
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 ) ) ;
}
// Write data back : timeStepCount, bytesPrTimestep, dataForTimestep0 ... dataForTimestepN
if ( scalarResultFrames = = NULL )
{
// No data available
socketStream < < ( quint64 ) 0 < < ( quint64 ) 0 ;
}
else
{
// Create a list of all the requested timesteps
std : : vector < size_t > requestedTimesteps ;
if ( args . size ( ) < = 4 )
{
// Select all
for ( size_t tsIdx = 0 ; tsIdx < scalarResultFrames - > size ( ) ; + + 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: riGetActiveCellProperty : \n " ) + RiaSocketServer : : tr ( " An error occured while interpreting the requested timesteps. " ) ) ;
}
}
// First write timestep count
quint64 timestepCount = ( quint64 ) requestedTimesteps . size ( ) ;
socketStream < < timestepCount ;
// then the byte-size of the result values in one timestep
2017-03-15 03:10:16 -05:00
const RigActiveCellInfo * activeInfo = rimCase - > eclipseCaseData ( ) - > activeCellInfo ( porosityModelEnum ) ;
2014-08-08 03:27:29 -05:00
size_t timestepResultCount = activeInfo - > reservoirActiveCellCount ( ) ;
2013-05-24 04:07:59 -05:00
quint64 timestepByteCount = ( quint64 ) ( timestepResultCount * sizeof ( double ) ) ;
socketStream < < timestepByteCount ;
// Then write the data.
2014-04-24 00:40:29 -05:00
size_t valueCount = RiaSocketDataTransfer : : maximumValueCountInBlock ( ) ;
2014-04-15 06:40:53 -05:00
std : : vector < double > values ( valueCount ) ;
size_t valueIndex = 0 ;
2013-05-24 04:07:59 -05:00
2014-08-08 03:45:52 -05:00
size_t reservoirCellCount = activeInfo - > reservoirCellCount ( ) ;
2013-05-24 04:07:59 -05:00
for ( size_t tIdx = 0 ; tIdx < requestedTimesteps . size ( ) ; + + tIdx )
{
2014-06-11 05:06:15 -05:00
std : : vector < double > & doubleValues = scalarResultFrames - > at ( requestedTimesteps [ tIdx ] ) ;
2014-08-08 03:45:52 -05:00
for ( size_t gcIdx = 0 ; gcIdx < reservoirCellCount ; + + gcIdx )
2013-05-24 04:07:59 -05:00
{
size_t resultIdx = activeInfo - > cellResultIndex ( gcIdx ) ;
2014-06-11 05:06:15 -05:00
if ( resultIdx = = cvf : : UNDEFINED_SIZE_T ) continue ;
if ( resultIdx < doubleValues . size ( ) )
2013-05-24 04:07:59 -05:00
{
2014-08-08 03:27:29 -05:00
if ( doubleValues . size ( ) = = activeInfo - > reservoirCellCount ( ) )
2013-05-24 04:07:59 -05:00
{
2014-06-11 05:06:15 -05:00
// When reading data from input text files, result data is read for all grid cells
// Read out values from data vector using global cell index instead of active cell result index
// When data is written back to ResInsight using RiaSetActiveCellProperty, the resulting
// data vector will have activeCellCount data values, which is potentially smaller
// than total number of cells
values [ valueIndex ] = doubleValues [ gcIdx ] ;
2013-05-24 04:07:59 -05:00
}
else
{
2014-06-11 05:06:15 -05:00
values [ valueIndex ] = doubleValues [ resultIdx ] ;
2014-04-15 06:40:53 -05:00
}
2014-06-11 05:06:15 -05:00
}
else
{
values [ valueIndex ] = HUGE_VAL ;
}
2014-04-15 06:40:53 -05:00
2014-06-11 05:06:15 -05:00
valueIndex + + ;
if ( valueIndex > = valueCount )
{
if ( ! RiaSocketTools : : writeBlockData ( server , server - > currentClient ( ) , ( const char * ) values . data ( ) , valueIndex * sizeof ( double ) ) )
2014-04-15 06:40:53 -05:00
{
2014-06-11 05:06:15 -05:00
return false ;
2013-05-24 04:07:59 -05:00
}
2014-06-11 05:06:15 -05:00
valueIndex = 0 ;
2013-05-24 04:07:59 -05:00
}
}
}
2014-04-15 06:40:53 -05:00
// Write remaining data
if ( ! RiaSocketTools : : writeBlockData ( server , server - > currentClient ( ) , ( const char * ) values . data ( ) , valueIndex * sizeof ( double ) ) )
2013-05-24 04:07:59 -05:00
{
2014-04-15 06:40:53 -05:00
return false ;
2013-05-24 04:07:59 -05:00
}
2014-04-15 06:40:53 -05:00
}
2013-05-24 04:07:59 -05:00
return true ;
}
} ;
static bool RiaGetActiveCellProperty_init = RiaSocketCommandFactory : : instance ( ) - > registerCreator < RiaGetActiveCellProperty > ( RiaGetActiveCellProperty : : commandName ( ) ) ;
2013-05-24 05:02:52 -05:00
2013-05-27 05:22:05 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaGetGridProperty : public RiaSocketCommand
{
public :
static QString commandName ( ) { return QString ( " GetGridProperty " ) ; }
virtual bool interpretCommand ( RiaSocketServer * server , const QList < QByteArray > & args , QDataStream & socketStream )
{
2013-05-28 02:20:09 -05:00
int caseId = args [ 1 ] . toInt ( ) ;
int gridIdx = args [ 2 ] . toInt ( ) ;
QString propertyName = args [ 3 ] ;
2013-05-27 05:22:05 -05:00
QString porosityModelName = args [ 4 ] ;
2013-05-28 02:20:09 -05:00
2015-05-15 01:40:27 -05:00
RimEclipseCase * rimCase = server - > findReservoir ( caseId ) ;
2013-05-28 02:20:09 -05:00
if ( rimCase = = NULL )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " Could not find the case with ID: \" %1 \" " ) . arg ( caseId ) ) ;
// No data available
socketStream < < ( quint64 ) 0 < < ( quint64 ) 0 < < ( quint64 ) 0 < < ( quint64 ) 0 ;
return true ;
}
2013-05-27 05:22:05 -05:00
2017-08-11 07:05:59 -05:00
RiaDefines : : PorosityModelType porosityModelEnum = RiaDefines : : MATRIX_MODEL ;
2013-05-27 05:22:05 -05:00
if ( porosityModelName = = " Fracture " )
{
2017-08-11 07:05:59 -05:00
porosityModelEnum = RiaDefines : : FRACTURE_MODEL ;
2013-05-27 05:22:05 -05:00
}
size_t scalarResultIndex = cvf : : UNDEFINED_SIZE_T ;
2017-03-15 03:10:16 -05:00
if ( gridIdx < 0 | | rimCase - > eclipseCaseData ( ) - > gridCount ( ) < = ( size_t ) gridIdx )
2013-05-27 05:22:05 -05:00
{
server - > errorMessageDialog ( ) - > showMessage ( " ResInsight SocketServer: riGetGridProperty : \n "
" The gridIndex \" " + QString : : number ( gridIdx ) + " \" does not point to an existing grid. " ) ;
}
else
{
// Find the requested data
if ( rimCase & & rimCase - > results ( porosityModelEnum ) )
{
scalarResultIndex = rimCase - > results ( porosityModelEnum ) - > findOrLoadScalarResult ( propertyName ) ;
}
}
2013-08-12 03:04:30 -05:00
if ( scalarResultIndex = = cvf : : UNDEFINED_SIZE_T )
2013-05-27 05:22:05 -05:00
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " Could not find the %1 model property named: \" %2 \" " ) . arg ( porosityModelName ) . arg ( propertyName ) ) ;
// No data available
socketStream < < ( quint64 ) 0 < < ( quint64 ) 0 < < ( quint64 ) 0 < < ( quint64 ) 0 ;
return true ;
}
2013-08-12 03:04:30 -05:00
2013-05-28 02:20:09 -05:00
// Create a list of all the requested time steps
2013-05-27 05:22:05 -05:00
std : : vector < size_t > requestedTimesteps ;
2013-05-28 02:20:09 -05:00
if ( args . size ( ) < = 5 )
2013-05-27 05:22:05 -05:00
{
// Select all
2013-08-12 03:04:30 -05:00
for ( size_t tsIdx = 0 ; tsIdx < rimCase - > results ( porosityModelEnum ) - > cellResults ( ) - > timeStepCount ( scalarResultIndex ) ; + + tsIdx )
2013-05-27 05:22:05 -05:00
{
requestedTimesteps . push_back ( tsIdx ) ;
}
}
else
{
bool timeStepReadError = false ;
2013-05-28 02:20:09 -05:00
for ( int argIdx = 5 ; argIdx < args . size ( ) ; + + argIdx )
2013-05-27 05:22:05 -05:00
{
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 occured while interpreting the requested timesteps. " ) ) ;
}
}
2017-03-15 03:10:16 -05:00
RigGridBase * rigGrid = rimCase - > eclipseCaseData ( ) - > grid ( gridIdx ) ;
2013-05-27 05:22:05 -05:00
quint64 cellCountI = ( quint64 ) rigGrid - > cellCountI ( ) ;
quint64 cellCountJ = ( quint64 ) rigGrid - > cellCountJ ( ) ;
quint64 cellCountK = ( quint64 ) rigGrid - > cellCountK ( ) ;
socketStream < < cellCountI ;
socketStream < < cellCountJ ;
socketStream < < cellCountK ;
2013-05-28 02:20:09 -05:00
// Write time step count
2013-05-27 05:22:05 -05:00
quint64 timestepCount = ( quint64 ) requestedTimesteps . size ( ) ;
socketStream < < timestepCount ;
2014-04-03 04:56:01 -05:00
for ( size_t tsIdx = 0 ; tsIdx < timestepCount ; tsIdx + + )
2013-05-27 05:22:05 -05:00
{
2017-03-15 03:10:16 -05:00
cvf : : ref < RigResultAccessor > resultAccessor = RigResultAccessorFactory : : createFromUiResultName ( rimCase - > eclipseCaseData ( ) , gridIdx , porosityModelEnum , requestedTimesteps [ tsIdx ] , propertyName ) ;
2014-08-09 07:46:27 -05:00
if ( resultAccessor . isNull ( ) )
2013-05-27 05:22:05 -05:00
{
2014-04-03 04:56:01 -05:00
continue ;
2013-08-12 03:04:30 -05:00
}
2013-05-27 05:22:05 -05:00
2014-04-24 00:40:29 -05:00
size_t valueCount = RiaSocketDataTransfer : : maximumValueCountInBlock ( ) ;
2014-04-15 06:40:53 -05:00
std : : vector < double > values ( valueCount ) ;
size_t valueIndex = 0 ;
2014-04-03 04:56:01 -05:00
for ( size_t cellIdx = 0 ; cellIdx < rigGrid - > cellCount ( ) ; cellIdx + + )
2013-08-12 03:04:30 -05:00
{
2014-08-09 07:46:27 -05:00
double cellValue = resultAccessor - > cellScalar ( cellIdx ) ;
2014-04-03 04:56:01 -05:00
if ( cellValue = = HUGE_VAL )
2014-04-01 06:02:52 -05:00
{
2014-04-03 04:56:01 -05:00
cellValue = 0.0 ;
2013-08-12 10:04:31 -05:00
}
2014-04-15 06:40:53 -05:00
values [ valueIndex + + ] = cellValue ;
if ( valueIndex > = valueCount )
{
if ( ! RiaSocketTools : : writeBlockData ( server , server - > currentClient ( ) , ( const char * ) values . data ( ) , valueIndex * sizeof ( double ) ) )
{
return false ;
}
valueIndex = 0 ;
}
2013-05-27 05:22:05 -05:00
}
2013-05-28 02:20:09 -05:00
2014-04-15 06:40:53 -05:00
// Write remaining data
if ( ! RiaSocketTools : : writeBlockData ( server , server - > currentClient ( ) , ( const char * ) values . data ( ) , valueIndex * sizeof ( double ) ) )
{
return false ;
}
2014-04-03 04:56:01 -05:00
}
2014-04-01 06:02:52 -05:00
2013-05-27 05:22:05 -05:00
return true ;
}
} ;
static bool RiaGetGridProperty_init = RiaSocketCommandFactory : : instance ( ) - > registerCreator < RiaGetGridProperty > ( RiaGetGridProperty : : commandName ( ) ) ;
2013-05-24 05:02:52 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaSetActiveCellProperty : public RiaSocketCommand
{
public :
RiaSetActiveCellProperty ( ) :
m_currentReservoir ( NULL ) ,
m_scalarResultsToAdd ( NULL ) ,
m_currentScalarIndex ( cvf : : UNDEFINED_SIZE_T ) ,
m_timeStepCountToRead ( 0 ) ,
m_bytesPerTimeStepToRead ( 0 ) ,
2013-05-26 05:07:42 -05:00
m_currentTimeStepNumberToRead ( 0 ) ,
2013-05-24 05:02:52 -05:00
m_invalidActiveCellCountDetected ( false ) ,
2017-08-11 07:05:59 -05:00
m_porosityModelEnum ( RiaDefines : : MATRIX_MODEL )
2013-05-24 05:02:52 -05:00
{ }
static QString commandName ( ) { return QString ( " SetActiveCellProperty " ) ; }
virtual bool interpretCommand ( RiaSocketServer * server , const QList < QByteArray > & args , QDataStream & socketStream )
{
2015-05-15 01:40:27 -05:00
RimEclipseCase * rimCase = RiaSocketTools : : findCaseFromArgs ( server , args ) ;
2013-05-24 05:02:52 -05:00
QString propertyName = args [ 2 ] ;
QString porosityModelName = args [ 3 ] ;
if ( porosityModelName = = " Fracture " )
{
2017-08-11 07:05:59 -05:00
m_porosityModelEnum = RiaDefines : : FRACTURE_MODEL ;
2013-05-24 05:02:52 -05:00
}
// 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 ( m_porosityModelEnum ) )
{
2017-06-13 08:41:52 -05:00
scalarResultIndex = rimCase - > results ( m_porosityModelEnum ) - > findOrLoadScalarResult ( RiaDefines : : GENERATED , propertyName ) ;
2013-05-24 05:02:52 -05:00
if ( scalarResultIndex = = cvf : : UNDEFINED_SIZE_T )
{
2017-06-13 08:41:52 -05:00
scalarResultIndex = rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > addEmptyScalarResult ( RiaDefines : : GENERATED , propertyName , true ) ;
2017-08-21 02:11:37 -05:00
size_t scalarResWithMostTimeSteps = cvf : : UNDEFINED_SIZE_T ;
rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > maxTimeStepCount ( & scalarResWithMostTimeSteps ) ;
const std : : vector < RigEclipseTimeStepInfo > timeStepInfos = rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > timeStepInfos ( scalarResWithMostTimeSteps ) ;
rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > setTimeStepInfos ( scalarResultIndex , timeStepInfos ) ;
2013-05-24 05:02:52 -05:00
}
if ( scalarResultIndex ! = cvf : : UNDEFINED_SIZE_T )
{
scalarResultFrames = & ( rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > cellScalarResults ( scalarResultIndex ) ) ;
2014-08-28 02:54:34 -05:00
size_t timeStepCount = rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > maxTimeStepCount ( ) ;
scalarResultFrames - > resize ( timeStepCount ) ;
2013-05-24 05:02:52 -05:00
m_currentScalarIndex = scalarResultIndex ;
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 ;
}
2013-05-28 09:02:00 -05:00
// If we have not read the header and there are data enough: Read it.
// Do nothing if we have not enough data
if ( m_timeStepCountToRead = = 0 | | m_bytesPerTimeStepToRead = = 0 )
{
if ( server - > currentClient ( ) - > bytesAvailable ( ) < ( int ) sizeof ( quint64 ) * 2 ) return true ;
socketStream > > m_timeStepCountToRead ;
socketStream > > m_bytesPerTimeStepToRead ;
}
// std::cout << "RiaSetActiveCellProperty: " << propertyName.data() << " timeStepCount " << m_timeStepCountToRead << " bytesPerTimeStep " << m_bytesPerTimeStepToRead;
2013-05-24 05:02:52 -05:00
// Create a list of all the requested timesteps
m_requestedTimesteps . clear ( ) ;
if ( args . size ( ) < = 4 )
{
// Select all
2013-05-28 09:02:00 -05:00
for ( size_t tsIdx = 0 ; tsIdx < m_timeStepCountToRead ; + + tsIdx )
2013-05-24 05:02:52 -05:00
{
m_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 )
{
m_requestedTimesteps . push_back ( tsIdx ) ;
}
else
{
timeStepReadError = true ;
}
}
if ( timeStepReadError )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: riGetActiveCellProperty : \n " ) + RiaSocketServer : : tr ( " An error occured while interpreting the requested timesteps. " ) ) ;
}
}
2013-05-26 05:07:42 -05:00
if ( ! m_requestedTimesteps . size ( ) )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " No time steps specified " ) . arg ( porosityModelName ) . arg ( propertyName ) ) ;
return true ;
}
2013-05-24 05:02:52 -05:00
m_currentReservoir = rimCase ;
m_scalarResultsToAdd = scalarResultFrames ;
if ( server - > currentClient ( ) - > bytesAvailable ( ) )
{
return this - > interpretMore ( server , server - > currentClient ( ) ) ;
}
return false ;
}
virtual bool interpretMore ( RiaSocketServer * server , QTcpSocket * currentClient )
{
2013-05-28 09:02:00 -05:00
// std::cout << "RiaSetActiveCellProperty, interpretMore: scalarIndex : " << m_currentScalarIndex;
2013-05-24 05:02:52 -05:00
if ( m_invalidActiveCellCountDetected ) return true ;
2013-10-04 07:26:02 -05:00
// If nothing should be read, or we already have read everything, do nothing
2013-05-24 05:02:52 -05:00
2013-10-04 07:26:02 -05:00
if ( ( m_timeStepCountToRead = = 0 ) | | ( m_currentTimeStepNumberToRead > = m_timeStepCountToRead ) ) return true ;
if ( ! currentClient - > bytesAvailable ( ) ) return false ;
2013-05-24 05:02:52 -05:00
2013-05-26 05:07:42 -05:00
if ( m_timeStepCountToRead ! = m_requestedTimesteps . size ( ) )
{
CVF_ASSERT ( false ) ;
}
2013-05-24 05:02:52 -05:00
// 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 ) ;
2017-03-15 03:10:16 -05:00
RigActiveCellInfo * activeCellInfo = m_currentReservoir - > eclipseCaseData ( ) - > activeCellInfo ( m_porosityModelEnum ) ;
2013-05-27 05:22:05 -05:00
2014-08-08 03:45:52 -05:00
size_t activeCellCountReservoir = activeCellInfo - > reservoirActiveCellCount ( ) ;
2014-08-08 03:27:29 -05:00
size_t totalCellCount = activeCellInfo - > reservoirCellCount ( ) ;
2014-08-08 03:45:52 -05:00
size_t reservoirCellResultCount = activeCellInfo - > reservoirCellResultCount ( ) ;
2013-05-27 05:22:05 -05:00
2014-08-08 03:45:52 -05:00
bool isCoarseningActive = reservoirCellResultCount ! = activeCellCountReservoir ;
2013-05-24 05:02:52 -05:00
2014-08-08 03:45:52 -05:00
if ( cellCountFromOctave ! = activeCellCountReservoir )
2013-05-24 05:02:52 -05:00
{
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 "
" Octave: " + QString : : number ( cellCountFromOctave ) + " \n "
2014-08-08 03:45:52 -05:00
" " + m_currentReservoir - > caseUserDescription ( ) + " : Active cell count: " + QString : : number ( activeCellCountReservoir ) + " Total cell count: " + QString : : number ( totalCellCount ) ) ;
2013-05-24 05:02:52 -05:00
cellCountFromOctave = 0 ;
m_invalidActiveCellCountDetected = true ;
currentClient - > abort ( ) ;
return true ;
}
// Make sure the size of the retreiving container is correct.
// If it is, this is noops
2015-06-29 10:03:22 -05:00
{
size_t maxRequestedTimeStepIdx = cvf : : UNDEFINED_SIZE_T ;
for ( size_t tIdx = 0 ; tIdx < m_timeStepCountToRead ; + + tIdx )
{
size_t tsId = m_requestedTimesteps [ tIdx ] ;
if ( maxRequestedTimeStepIdx = = cvf : : UNDEFINED_SIZE_T | | tsId > maxRequestedTimeStepIdx )
{
maxRequestedTimeStepIdx = tsId ;
}
}
if ( maxRequestedTimeStepIdx ! = cvf : : UNDEFINED_SIZE_T
& & m_scalarResultsToAdd - > size ( ) < = maxRequestedTimeStepIdx )
{
m_scalarResultsToAdd - > resize ( maxRequestedTimeStepIdx + 1 ) ;
}
}
2013-05-26 05:07:42 -05:00
2013-05-24 05:02:52 -05:00
for ( size_t tIdx = 0 ; tIdx < m_timeStepCountToRead ; + + tIdx )
{
2013-05-26 05:07:42 -05:00
size_t tsId = m_requestedTimesteps [ tIdx ] ;
2014-08-08 03:45:52 -05:00
m_scalarResultsToAdd - > at ( tsId ) . resize ( reservoirCellResultCount , HUGE_VAL ) ;
2013-05-26 05:07:42 -05:00
}
std : : vector < double > readBuffer ;
double * internalMatrixData = NULL ;
2013-05-26 05:16:32 -05:00
if ( isCoarseningActive )
2013-05-26 05:07:42 -05:00
{
readBuffer . resize ( cellCountFromOctave , HUGE_VAL ) ;
internalMatrixData = readBuffer . data ( ) ;
2013-05-24 05:02:52 -05:00
}
2013-10-04 07:26:02 -05:00
QDataStream socketStream ( currentClient ) ;
socketStream . setVersion ( riOctavePlugin : : qtDataStreamVersion ) ;
2013-05-24 05:02:52 -05:00
// Read available complete timestepdata
2013-05-26 05:16:32 -05:00
2013-05-26 05:07:42 -05:00
while ( ( currentClient - > bytesAvailable ( ) > = ( int ) m_bytesPerTimeStepToRead ) & & ( m_currentTimeStepNumberToRead < m_timeStepCountToRead ) )
2013-05-24 05:02:52 -05:00
{
2013-05-26 05:16:32 -05:00
if ( ! isCoarseningActive )
2013-05-26 05:07:42 -05:00
{
internalMatrixData = m_scalarResultsToAdd - > at ( m_requestedTimesteps [ m_currentTimeStepNumberToRead ] ) . data ( ) ;
}
2013-05-24 05:02:52 -05:00
2014-04-15 06:40:53 -05:00
QStringList errorMessages ;
if ( ! RiaSocketDataTransfer : : readBlockDataFromSocket ( currentClient , ( char * ) ( internalMatrixData ) , m_bytesPerTimeStepToRead , errorMessages ) )
2013-05-24 05:02:52 -05:00
{
2014-04-15 06:40:53 -05:00
for ( int i = 0 ; i < errorMessages . size ( ) ; i + + )
{
server - > errorMessageDialog ( ) - > showMessage ( errorMessages [ i ] ) ;
}
2013-05-24 05:02:52 -05:00
2014-04-15 06:40:53 -05:00
currentClient - > abort ( ) ;
return true ;
2013-05-24 05:02:52 -05:00
}
2014-04-15 06:40:53 -05:00
2013-05-26 05:07:42 -05:00
// Map data from active to result index based container ( Coarsening is active)
2013-05-26 05:16:32 -05:00
if ( isCoarseningActive )
2013-05-26 05:07:42 -05:00
{
size_t acIdx = 0 ;
2013-05-26 05:16:32 -05:00
for ( size_t gcIdx = 0 ; gcIdx < totalCellCount ; + + gcIdx )
2013-05-26 05:07:42 -05:00
{
if ( activeCellInfo - > isActive ( gcIdx ) )
{
m_scalarResultsToAdd - > at ( m_requestedTimesteps [ m_currentTimeStepNumberToRead ] ) [ activeCellInfo - > cellResultIndex ( gcIdx ) ] = readBuffer [ acIdx ] ;
+ + acIdx ;
}
}
}
2013-05-24 05:02:52 -05:00
2013-05-26 05:07:42 -05:00
+ + m_currentTimeStepNumberToRead ;
2013-05-24 05:02:52 -05:00
}
2013-05-28 09:02:00 -05:00
2013-05-24 05:02:52 -05:00
// If we have read all the data, refresh the views
2013-05-26 05:16:32 -05:00
2013-05-26 05:07:42 -05:00
if ( m_currentTimeStepNumberToRead = = m_timeStepCountToRead )
2013-05-24 05:02:52 -05:00
{
if ( m_currentReservoir ! = NULL )
{
// Create a new input property if we have an input reservoir
2015-06-25 04:50:13 -05:00
RimEclipseInputCase * inputRes = dynamic_cast < RimEclipseInputCase * > ( m_currentReservoir ) ;
2013-05-24 05:02:52 -05:00
if ( inputRes )
{
2017-03-06 04:19:15 -06:00
RimEclipseInputProperty * inputProperty = inputRes - > m_inputPropertyCollection - > findInputProperty ( m_currentPropertyName ) ;
2013-05-24 05:02:52 -05:00
if ( ! inputProperty )
{
2015-06-25 04:51:59 -05:00
inputProperty = new RimEclipseInputProperty ;
2013-05-24 05:02:52 -05:00
inputProperty - > resultName = m_currentPropertyName ;
inputProperty - > eclipseKeyword = " " ;
inputProperty - > fileName = " " ;
inputRes - > m_inputPropertyCollection - > inputProperties . push_back ( inputProperty ) ;
2015-08-13 14:28:09 -05:00
inputRes - > m_inputPropertyCollection ( ) - > updateConnectedEditors ( ) ;
2013-05-24 05:02:52 -05:00
}
2015-06-25 04:51:59 -05:00
inputProperty - > resolvedState = RimEclipseInputProperty : : RESOLVED_NOT_SAVED ;
2013-05-24 05:02:52 -05:00
}
if ( m_currentScalarIndex ! = cvf : : UNDEFINED_SIZE_T & &
2017-03-15 03:10:16 -05:00
m_currentReservoir - > eclipseCaseData ( ) & &
m_currentReservoir - > eclipseCaseData ( ) - > results ( m_porosityModelEnum ) )
2013-05-24 05:02:52 -05:00
{
2014-10-27 02:00:23 -05:00
// Adjust the result data if only one time step is requested so the result behaves like a static result
if ( m_requestedTimesteps . size ( ) = = 1 & & m_currentScalarIndex ! = cvf : : UNDEFINED_SIZE_T )
{
std : : vector < std : : vector < double > > * scalarResultFrames = NULL ;
scalarResultFrames = & ( m_currentReservoir - > results ( m_porosityModelEnum ) - > cellResults ( ) - > cellScalarResults ( m_currentScalarIndex ) ) ;
size_t lastIndexWithDataPresent = cvf : : UNDEFINED_SIZE_T ;
for ( size_t i = 0 ; i < scalarResultFrames - > size ( ) ; i + + )
{
if ( ( * scalarResultFrames ) [ i ] . size ( ) > 0 )
{
lastIndexWithDataPresent = i ;
}
}
if ( lastIndexWithDataPresent = = 0 )
{
scalarResultFrames - > resize ( 1 ) ;
}
}
2017-03-15 03:10:16 -05:00
m_currentReservoir - > eclipseCaseData ( ) - > results ( m_porosityModelEnum ) - > recalculateStatistics ( m_currentScalarIndex ) ;
2013-05-24 05:02:52 -05:00
}
for ( size_t i = 0 ; i < m_currentReservoir - > reservoirViews . size ( ) ; + + i )
{
if ( m_currentReservoir - > reservoirViews [ i ] )
{
2013-09-13 02:23:13 -05:00
// As new result might have been introduced, update all editors connected
m_currentReservoir - > reservoirViews [ i ] - > cellResult - > updateConnectedEditors ( ) ;
// It is usually not needed to create new display model, but if any derived geometry based on generated data (from Octave)
// a full display model rebuild is required
m_currentReservoir - > reservoirViews [ i ] - > scheduleCreateDisplayModelAndRedraw ( ) ;
2013-05-24 05:02:52 -05:00
}
}
}
return true ;
}
return false ;
}
private :
2015-05-15 01:40:27 -05:00
RimEclipseCase * m_currentReservoir ;
2013-05-24 05:02:52 -05:00
std : : vector < std : : vector < double > > * m_scalarResultsToAdd ;
size_t m_currentScalarIndex ;
QString m_currentPropertyName ;
std : : vector < size_t > m_requestedTimesteps ;
2017-08-11 07:05:59 -05:00
RiaDefines : : PorosityModelType m_porosityModelEnum ;
2013-05-24 05:02:52 -05:00
quint64 m_timeStepCountToRead ;
quint64 m_bytesPerTimeStepToRead ;
2013-05-26 05:07:42 -05:00
size_t m_currentTimeStepNumberToRead ;
2013-05-24 05:02:52 -05:00
bool m_invalidActiveCellCountDetected ;
} ;
static bool RiaSetActiveCellProperty_init = RiaSocketCommandFactory : : instance ( ) - > registerCreator < RiaSetActiveCellProperty > ( RiaSetActiveCellProperty : : commandName ( ) ) ;
2013-10-08 07:18:23 -05:00
2013-05-28 03:43:32 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaSetGridProperty : public RiaSocketCommand
{
public :
RiaSetGridProperty ( ) :
m_currentReservoir ( NULL ) ,
m_scalarResultsToAdd ( NULL ) ,
m_currentGridIndex ( cvf : : UNDEFINED_SIZE_T ) ,
m_currentScalarIndex ( cvf : : UNDEFINED_SIZE_T ) ,
m_timeStepCountToRead ( 0 ) ,
m_bytesPerTimeStepToRead ( 0 ) ,
m_currentTimeStepNumberToRead ( 0 ) ,
m_invalidDataDetected ( false ) ,
2017-08-11 07:05:59 -05:00
m_porosityModelEnum ( RiaDefines : : MATRIX_MODEL )
2013-05-28 04:11:32 -05:00
{ }
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
static QString commandName ( ) { return QString ( " SetGridProperty " ) ; }
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
virtual bool interpretCommand ( RiaSocketServer * server , const QList < QByteArray > & args , QDataStream & socketStream )
{
int caseId = args [ 1 ] . toInt ( ) ;
2015-05-15 01:40:27 -05:00
RimEclipseCase * rimCase = server - > findReservoir ( caseId ) ;
2013-05-28 04:11:32 -05:00
if ( ! rimCase )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " Could not find the case with ID : \" %1 \" " ) . arg ( caseId ) ) ;
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
return true ;
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
m_currentGridIndex = args [ 2 ] . toInt ( ) ;
QString propertyName = args [ 3 ] ;
QString porosityModelName = args [ 4 ] ;
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
if ( porosityModelName = = " Fracture " )
{
2017-08-11 07:05:59 -05:00
m_porosityModelEnum = RiaDefines : : FRACTURE_MODEL ;
2013-05-28 04:11:32 -05:00
}
2013-05-28 03:43:32 -05:00
2017-03-15 03:10:16 -05:00
RigGridBase * grid = rimCase - > eclipseCaseData ( ) - > grid ( m_currentGridIndex ) ;
2013-05-28 04:11:32 -05:00
if ( ! grid )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " Could not find the grid index : %1 " ) . arg ( m_currentGridIndex ) ) ;
return true ;
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
// Read header
2013-10-04 07:26:02 -05:00
if ( server - > currentClient ( ) - > bytesAvailable ( ) < ( int ) sizeof ( quint64 ) * 5 )
{
return true ;
}
2013-05-28 04:11:32 -05:00
quint64 cellCountI = 0 ;
quint64 cellCountJ = 0 ;
quint64 cellCountK = 0 ;
socketStream > > cellCountI ;
socketStream > > cellCountJ ;
socketStream > > cellCountK ;
if ( grid - > cellCountI ( ) ! = cellCountI | |
grid - > cellCountJ ( ) ! = cellCountJ | |
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 ;
}
socketStream > > m_timeStepCountToRead ;
socketStream > > m_bytesPerTimeStepToRead ;
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 " ) ;
2013-10-04 07:26:02 -05:00
return true ;
2013-05-28 04:11:32 -05:00
}
size_t scalarResultIndex = cvf : : UNDEFINED_SIZE_T ;
std : : vector < std : : vector < double > > * scalarResultFrames = NULL ;
if ( rimCase & & rimCase - > results ( m_porosityModelEnum ) )
{
2017-06-13 08:41:52 -05:00
scalarResultIndex = rimCase - > results ( m_porosityModelEnum ) - > findOrLoadScalarResult ( RiaDefines : : GENERATED , propertyName ) ;
2013-05-28 04:11:32 -05:00
if ( scalarResultIndex = = cvf : : UNDEFINED_SIZE_T )
{
2017-06-13 08:41:52 -05:00
scalarResultIndex = rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > addEmptyScalarResult ( RiaDefines : : GENERATED , propertyName , true ) ;
2013-05-28 04:11:32 -05:00
}
if ( scalarResultIndex ! = cvf : : UNDEFINED_SIZE_T )
{
scalarResultFrames = & ( rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > cellScalarResults ( scalarResultIndex ) ) ;
2014-08-28 02:54:34 -05:00
size_t timeStepCount = rimCase - > results ( m_porosityModelEnum ) - > cellResults ( ) - > maxTimeStepCount ( ) ;
scalarResultFrames - > resize ( timeStepCount ) ;
2013-05-28 04:11:32 -05:00
m_currentScalarIndex = scalarResultIndex ;
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
m_requestedTimesteps . clear ( ) ;
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 ) ;
if ( conversionOk )
{
m_requestedTimesteps . push_back ( tsIdx ) ;
}
else
{
timeStepReadError = true ;
}
}
if ( timeStepReadError )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: riGetActiveCellProperty : \n " ) + RiaSocketServer : : tr ( " An error occured while interpreting the requested timesteps. " ) ) ;
2013-10-04 07:26:02 -05:00
return true ;
2013-05-28 04:11:32 -05:00
}
}
if ( ! m_requestedTimesteps . size ( ) )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " No time steps specified " ) . arg ( porosityModelName ) . arg ( propertyName ) ) ;
return true ;
}
m_currentReservoir = rimCase ;
m_scalarResultsToAdd = scalarResultFrames ;
if ( server - > currentClient ( ) - > bytesAvailable ( ) )
{
return this - > interpretMore ( server , server - > currentClient ( ) ) ;
}
return false ;
}
virtual bool interpretMore ( RiaSocketServer * server , QTcpSocket * currentClient )
{
2013-10-04 07:26:02 -05:00
if ( m_invalidDataDetected ) {
RiuMainWindow : : instance ( ) - > processMonitor ( ) - > addStringToLog ( " [ResInsight SocketServer] > True \n " ) ;
return true ;
}
2013-05-28 04:11:32 -05:00
2013-10-04 07:26:02 -05:00
// If nothing should be read, or we already have read everything, do nothing
if ( ( m_timeStepCountToRead = = 0 ) | | ( m_currentTimeStepNumberToRead > = m_timeStepCountToRead ) ) return true ;
if ( ! currentClient - > bytesAvailable ( ) ) return false ;
2013-05-28 04:11:32 -05:00
2017-03-15 03:10:16 -05:00
RigGridBase * grid = m_currentReservoir - > eclipseCaseData ( ) - > grid ( m_currentGridIndex ) ;
2013-05-28 04:11:32 -05:00
if ( ! grid )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) +
RiaSocketServer : : tr ( " No grid found " ) + " : \" " + m_currentReservoir - > caseUserDescription ( ) + " \" \n " ) ;
m_invalidDataDetected = true ;
2013-10-04 07:26:02 -05:00
currentClient - > abort ( ) ; // Hmmm... should we not let the server handle this ?
2013-05-28 04:11:32 -05:00
return true ;
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
if ( m_timeStepCountToRead ! = m_requestedTimesteps . size ( ) )
{
CVF_ASSERT ( false ) ;
}
2013-05-28 03:43:32 -05:00
2013-10-04 07:26:02 -05:00
// Check if a complete timestep is available, return and wait for readyRead() if not
2013-05-28 04:11:32 -05:00
if ( currentClient - > bytesAvailable ( ) < ( int ) m_bytesPerTimeStepToRead ) return false ;
size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof ( double ) ;
2013-08-12 03:04:30 -05:00
if ( cellCountFromOctave ! = grid - > cellCount ( ) )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) +
RiaSocketServer : : tr ( " Mismatch between expected and received data. Expected : %1, Received : %2 " ) . arg ( grid - > cellCount ( ) ) . arg ( cellCountFromOctave ) ) ;
2013-05-28 04:11:32 -05:00
2013-08-12 03:04:30 -05:00
m_invalidDataDetected = true ;
currentClient - > abort ( ) ;
return true ;
}
2013-05-28 04:11:32 -05:00
2015-06-29 10:03:22 -05:00
// Resize the timestep container
{
size_t maxRequestedTimeStepIdx = cvf : : UNDEFINED_SIZE_T ;
for ( size_t tIdx = 0 ; tIdx < m_timeStepCountToRead ; + + tIdx )
{
size_t tsId = m_requestedTimesteps [ tIdx ] ;
if ( maxRequestedTimeStepIdx = = cvf : : UNDEFINED_SIZE_T | | tsId > maxRequestedTimeStepIdx )
{
maxRequestedTimeStepIdx = tsId ;
}
}
if ( maxRequestedTimeStepIdx ! = cvf : : UNDEFINED_SIZE_T
& & m_scalarResultsToAdd - > size ( ) < = maxRequestedTimeStepIdx )
{
m_scalarResultsToAdd - > resize ( maxRequestedTimeStepIdx + 1 ) ;
}
}
2013-05-28 04:11:32 -05:00
for ( size_t tIdx = 0 ; tIdx < m_timeStepCountToRead ; + + tIdx )
{
size_t tsId = m_requestedTimesteps [ tIdx ] ;
2013-08-12 03:04:30 -05:00
// Result data is stored in an array containing all cells for all grids
// The size of this array must match the test in RigCaseCellResultsData::isUsingGlobalActiveIndex(),
// as it is used to determine if we have data for active cells or all cells
// See RigCaseCellResultsData::isUsingGlobalActiveIndex()
2015-11-24 07:21:02 -06:00
size_t totalNumberOfCellsIncludingLgrCells = grid - > mainGrid ( ) - > globalCellArray ( ) . size ( ) ;
2013-08-12 03:04:30 -05:00
m_scalarResultsToAdd - > at ( tsId ) . resize ( totalNumberOfCellsIncludingLgrCells , HUGE_VAL ) ;
2013-05-28 04:11:32 -05:00
}
2013-05-28 03:43:32 -05:00
2013-10-04 07:26:02 -05:00
while ( ( currentClient - > bytesAvailable ( ) > = ( int ) m_bytesPerTimeStepToRead ) & & ( m_currentTimeStepNumberToRead < m_timeStepCountToRead ) )
2013-05-28 04:11:32 -05:00
{
// Read a single time step with data
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
std : : vector < double > doubleValues ( cellCountFromOctave ) ;
2013-05-28 03:43:32 -05:00
2014-04-15 06:40:53 -05:00
QStringList errorMessages ;
if ( ! RiaSocketDataTransfer : : readBlockDataFromSocket ( currentClient , ( char * ) ( doubleValues . data ( ) ) , m_bytesPerTimeStepToRead , errorMessages ) )
{
for ( int i = 0 ; i < errorMessages . size ( ) ; i + + )
{
server - > errorMessageDialog ( ) - > showMessage ( errorMessages [ i ] ) ;
}
currentClient - > abort ( ) ;
return true ;
}
2013-05-28 03:43:32 -05:00
2017-03-15 03:10:16 -05:00
cvf : : ref < RigResultModifier > resultModifier = RigResultModifierFactory : : createResultModifier ( m_currentReservoir - > eclipseCaseData ( ) , grid - > gridIndex ( ) , m_porosityModelEnum , m_requestedTimesteps [ m_currentTimeStepNumberToRead ] , m_currentScalarIndex ) ;
2014-08-08 01:37:56 -05:00
if ( ! resultModifier . isNull ( ) )
2013-05-28 04:11:32 -05:00
{
2013-08-12 03:04:30 -05:00
for ( size_t cellIdx = 0 ; static_cast < size_t > ( cellIdx ) < cellCountFromOctave ; cellIdx + + )
2013-05-28 04:11:32 -05:00
{
2014-08-08 01:37:56 -05:00
resultModifier - > setCellScalar ( cellIdx , doubleValues [ cellIdx ] ) ;
2013-05-28 04:11:32 -05:00
}
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
+ + m_currentTimeStepNumberToRead ;
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
// If we have read all the data, refresh the views
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
if ( m_currentTimeStepNumberToRead = = m_timeStepCountToRead )
{
if ( m_currentReservoir ! = NULL )
{
// Create a new input property if we have an input reservoir
2015-06-25 04:50:13 -05:00
RimEclipseInputCase * inputRes = dynamic_cast < RimEclipseInputCase * > ( m_currentReservoir ) ;
2013-05-28 04:11:32 -05:00
if ( inputRes )
{
2017-03-06 04:19:15 -06:00
RimEclipseInputProperty * inputProperty = inputRes - > m_inputPropertyCollection - > findInputProperty ( m_currentPropertyName ) ;
2013-05-28 04:11:32 -05:00
if ( ! inputProperty )
{
2015-06-25 04:51:59 -05:00
inputProperty = new RimEclipseInputProperty ;
2013-05-28 04:11:32 -05:00
inputProperty - > resultName = m_currentPropertyName ;
inputProperty - > eclipseKeyword = " " ;
inputProperty - > fileName = " " ;
inputRes - > m_inputPropertyCollection - > inputProperties . push_back ( inputProperty ) ;
2015-08-13 14:28:09 -05:00
inputRes - > m_inputPropertyCollection ( ) - > updateConnectedEditors ( ) ;
2013-05-28 04:11:32 -05:00
}
2015-06-25 04:51:59 -05:00
inputProperty - > resolvedState = RimEclipseInputProperty : : RESOLVED_NOT_SAVED ;
2013-05-28 04:11:32 -05:00
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
if ( m_currentScalarIndex ! = cvf : : UNDEFINED_SIZE_T & &
2017-03-15 03:10:16 -05:00
m_currentReservoir - > eclipseCaseData ( ) & &
m_currentReservoir - > eclipseCaseData ( ) - > results ( m_porosityModelEnum ) )
2013-05-28 04:11:32 -05:00
{
2014-10-27 02:00:23 -05:00
// Adjust the result data if only one time step is requested so the result behaves like a static result
if ( m_requestedTimesteps . size ( ) = = 1 & & m_currentScalarIndex ! = cvf : : UNDEFINED_SIZE_T )
{
std : : vector < std : : vector < double > > * scalarResultFrames = NULL ;
scalarResultFrames = & ( m_currentReservoir - > results ( m_porosityModelEnum ) - > cellResults ( ) - > cellScalarResults ( m_currentScalarIndex ) ) ;
size_t lastIndexWithDataPresent = cvf : : UNDEFINED_SIZE_T ;
for ( size_t i = 0 ; i < scalarResultFrames - > size ( ) ; i + + )
{
if ( ( * scalarResultFrames ) [ i ] . size ( ) > 0 )
{
lastIndexWithDataPresent = i ;
}
}
if ( lastIndexWithDataPresent = = 0 )
{
scalarResultFrames - > resize ( 1 ) ;
}
}
2017-03-15 03:10:16 -05:00
m_currentReservoir - > eclipseCaseData ( ) - > results ( m_porosityModelEnum ) - > recalculateStatistics ( m_currentScalarIndex ) ;
2013-05-28 04:11:32 -05:00
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
for ( size_t i = 0 ; i < m_currentReservoir - > reservoirViews . size ( ) ; + + i )
{
if ( m_currentReservoir - > reservoirViews [ i ] )
{
2013-09-12 01:11:56 -05:00
// As new result might have been introduced, update all editors connected
m_currentReservoir - > reservoirViews [ i ] - > cellResult - > updateConnectedEditors ( ) ;
// It is usually not needed to create new display model, but if any derived geometry based on generated data (from Octave)
// a full display model rebuild is required
m_currentReservoir - > reservoirViews [ i ] - > scheduleCreateDisplayModelAndRedraw ( ) ;
2013-05-28 04:11:32 -05:00
}
}
}
2013-05-28 03:43:32 -05:00
2013-05-28 04:11:32 -05:00
return true ;
}
2013-05-28 03:43:32 -05:00
2013-10-04 07:26:02 -05:00
2013-05-28 04:11:32 -05:00
return false ;
}
2013-05-28 03:43:32 -05:00
private :
2015-05-15 01:40:27 -05:00
RimEclipseCase * m_currentReservoir ;
2013-05-28 03:43:32 -05:00
std : : vector < std : : vector < double > > * m_scalarResultsToAdd ;
size_t m_currentGridIndex ;
size_t m_currentScalarIndex ;
QString m_currentPropertyName ;
std : : vector < size_t > m_requestedTimesteps ;
2017-08-11 07:05:59 -05:00
RiaDefines : : PorosityModelType m_porosityModelEnum ;
2013-05-28 03:43:32 -05:00
quint64 m_timeStepCountToRead ;
quint64 m_bytesPerTimeStepToRead ;
size_t m_currentTimeStepNumberToRead ;
bool m_invalidDataDetected ;
} ;
static bool RiaSetGridProperty_init = RiaSocketCommandFactory : : instance ( ) - > registerCreator < RiaSetGridProperty > ( RiaSetGridProperty : : commandName ( ) ) ;
2013-08-30 08:26:35 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaGetPropertyNames : public RiaSocketCommand
{
public :
static QString commandName ( ) { return QString ( " GetPropertyNames " ) ; }
virtual bool interpretCommand ( RiaSocketServer * server , const QList < QByteArray > & args , QDataStream & socketStream )
{
int caseId = args [ 1 ] . toInt ( ) ;
2015-05-15 01:40:27 -05:00
RimEclipseCase * rimCase = server - > findReservoir ( caseId ) ;
2013-08-30 08:26:35 -05:00
if ( ! rimCase )
{
server - > errorMessageDialog ( ) - > showMessage ( RiaSocketServer : : tr ( " ResInsight SocketServer: \n " ) + RiaSocketServer : : tr ( " Could not find the case with ID : \" %1 \" " ) . arg ( caseId ) ) ;
return true ;
}
QString porosityModelName = args [ 2 ] ;
2017-08-11 07:05:59 -05:00
RiaDefines : : PorosityModelType porosityModelEnum = RiaDefines : : MATRIX_MODEL ;
2013-08-30 08:26:35 -05:00
if ( porosityModelName = = " Fracture " )
{
2017-08-11 07:05:59 -05:00
porosityModelEnum = RiaDefines : : FRACTURE_MODEL ;
2013-08-30 08:26:35 -05:00
}
std : : vector < QString > propNames ;
std : : vector < QString > propTypes ;
2017-03-15 03:10:16 -05:00
RigCaseCellResultsData * results = rimCase - > eclipseCaseData ( ) - > results ( porosityModelEnum ) ;
2013-08-30 08:26:35 -05:00
2017-06-13 08:41:52 -05:00
std : : vector < RiaDefines : : ResultCatType > resTypes ;
2013-08-30 08:26:35 -05:00
std : : vector < QString > resTypeNames ;
2017-06-13 08:41:52 -05:00
resTypes . push_back ( RiaDefines : : DYNAMIC_NATIVE ) ;
2013-08-30 08:26:35 -05:00
resTypeNames . push_back ( " DynamicNative " ) ;
2017-08-14 03:47:44 -05:00
resTypes . push_back ( RiaDefines : : SOURSIMRL ) ;
2017-07-07 06:31:14 -05:00
resTypeNames . push_back ( " SourSimRL " ) ;
2017-06-13 08:41:52 -05:00
resTypes . push_back ( RiaDefines : : STATIC_NATIVE ) ;
2013-08-30 08:26:35 -05:00
resTypeNames . push_back ( " StaticNative " ) ;
2017-06-13 08:41:52 -05:00
resTypes . push_back ( RiaDefines : : GENERATED ) ;
2013-08-30 08:26:35 -05:00
resTypeNames . push_back ( " Generated " ) ;
2017-06-13 08:41:52 -05:00
resTypes . push_back ( RiaDefines : : INPUT_PROPERTY ) ;
2013-08-30 08:26:35 -05:00
resTypeNames . push_back ( " Input " ) ;
for ( size_t rtIdx = 0 ; rtIdx < resTypes . size ( ) ; + + rtIdx )
{
2017-06-13 08:41:52 -05:00
RiaDefines : : ResultCatType resType = resTypes [ rtIdx ] ;
2013-08-30 08:26:35 -05:00
QStringList names = results - > resultNames ( resType ) ;
for ( int pnIdx = 0 ; pnIdx < names . size ( ) ; + + pnIdx ) {
propNames . push_back ( names [ pnIdx ] ) ;
propTypes . push_back ( resTypeNames [ rtIdx ] ) ;
}
}
quint64 byteCount = sizeof ( quint64 ) ;
quint64 propCount = propNames . size ( ) ;
for ( size_t rtIdx = 0 ; rtIdx < propCount ; rtIdx + + )
{
byteCount + = propNames [ rtIdx ] . size ( ) * sizeof ( QChar ) ;
byteCount + = propTypes [ rtIdx ] . size ( ) * sizeof ( QChar ) ;
}
socketStream < < byteCount ;
socketStream < < propCount ;
for ( size_t rtIdx = 0 ; rtIdx < propCount ; rtIdx + + )
{
socketStream < < propNames [ rtIdx ] ;
socketStream < < propTypes [ rtIdx ] ;
}
return true ;
}
} ;
static bool RiaGetPropertyNames_init = RiaSocketCommandFactory : : instance ( ) - > registerCreator < RiaGetPropertyNames > ( RiaGetPropertyNames : : commandName ( ) ) ;
2017-08-03 07:35:46 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 ] ;
2017-08-14 03:47:44 -05:00
RiaDefines : : PorosityModelType porosityModel = RiaDefines : : MATRIX_MODEL ;
2017-08-03 07:35:46 -05:00
if ( args . size ( ) > 1 )
{
QString prorosityModelString = args [ 3 ] ;
if ( prorosityModelString . toUpper ( ) = = " FRACTURE " )
{
2017-08-14 03:47:44 -05:00
porosityModel = RiaDefines : : FRACTURE_MODEL ;
2017-08-03 07:35:46 -05:00
}
}
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 ( ) ) ;