Skip to content

Commit

Permalink
#10648 Refactor summary reader: return std::vector<double> instead of…
Browse files Browse the repository at this point in the history
… taking ptr.
  • Loading branch information
kriben committed Oct 2, 2023
1 parent 263e39b commit d177491
Show file tree
Hide file tree
Showing 49 changed files with 204 additions and 249 deletions.
11 changes: 6 additions & 5 deletions ApplicationLibCode/Application/RiaSummaryCurveDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ void RiaSummaryCurveDefinition::setIdentifierText( SummaryCategory category, con
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaSummaryCurveDefinition::resultValues( const RiaSummaryCurveDefinition& curveDefinition, gsl::not_null<std::vector<double>*> values )
std::vector<double> RiaSummaryCurveDefinition::resultValues( const RiaSummaryCurveDefinition& curveDefinition )
{
if ( !curveDefinition.summaryAddressY().isValid() ) return;
if ( !curveDefinition.summaryCaseY() ) return;
if ( !curveDefinition.summaryAddressY().isValid() ) return {};
if ( !curveDefinition.summaryCaseY() ) return {};

RifSummaryReaderInterface* reader = curveDefinition.summaryCaseY()->summaryReader();
if ( !reader ) return;
if ( !reader ) return {};

reader->values( curveDefinition.summaryAddressY(), values );
auto [isOk, values] = reader->values( curveDefinition.summaryAddressY() );
return values;
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/Application/RiaSummaryCurveDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RiaSummaryCurveDefinition
bool operator<( const RiaSummaryCurveDefinition& other ) const;

// TODO: Consider moving to a separate tools class
static void resultValues( const RiaSummaryCurveDefinition& curveDefinition, gsl::not_null<std::vector<double>*> values );
static std::vector<double> resultValues( const RiaSummaryCurveDefinition& curveDefinition );
static std::vector<time_t> timeSteps( const RiaSummaryCurveDefinition& curveDefinition );

QString curveDefinitionText() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ void RicExportFractureCompletionsImpl::getWellPressuresAndInitialProductionTimeS

if ( summaryCase && summaryCase->summaryReader() )
{
std::vector<double> values;
if ( summaryCase->summaryReader()->values( wbhpPressureAddress, &values ) )
auto [isOk, values] = summaryCase->summaryReader()->values( wbhpPressureAddress );
if ( isOk )
{
std::vector<time_t> summaryTimeSteps = summaryCase->summaryReader()->timeSteps( wbhpPressureAddress );
CVF_ASSERT( values.size() == summaryTimeSteps.size() );
Expand Down
13 changes: 8 additions & 5 deletions ApplicationLibCode/FileInterface/RifColumnBasedUserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,31 @@ bool RifColumnBasedUserData::parse( const QString& data, QString* errorText )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifColumnBasedUserData::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifColumnBasedUserData::values( const RifEclipseSummaryAddress& resultAddress ) const
{
std::vector<double> values;

auto search = m_mapFromAddressToResultIndex.find( resultAddress );

if ( search != m_mapFromAddressToResultIndex.end() )
{
std::pair<size_t, size_t> tableColIndices = search->second;

const Column* ci = m_parser->columnInfo( tableColIndices.first, tableColIndices.second );
if ( !ci ) return false;
if ( !ci ) return { false, {} };

if ( !ci->values.empty() )
{
values->reserve( ci->values.size() );
values.reserve( ci->values.size() );

for ( const auto& v : ci->values )
{
values->push_back( v );
values.push_back( v );
}
}
}

return true;
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifColumnBasedUserData.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RifColumnBasedUserData : public RifSummaryReaderInterface

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;

bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;

std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
Expand Down
13 changes: 7 additions & 6 deletions ApplicationLibCode/FileInterface/RifCsvSummaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,26 @@ RifCsvSummaryReader::~RifCsvSummaryReader()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvSummaryReader::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifCsvSummaryReader::values( const RifEclipseSummaryAddress& resultAddress ) const
{
std::vector<double> values;

auto search = m_mapFromAddressToResultIndex.find( resultAddress );
if ( search != m_mapFromAddressToResultIndex.end() )
{
size_t columnIndex = search->second;

const Column* ci = m_parser->columnInfo( columnIndex );
if ( !ci ) return false;
if ( !ci ) return { false, {} };

values->clear();
values->reserve( ci->values.size() );
values.reserve( ci->values.size() );
for ( double val : ci->values )
{
values->push_back( val );
values.push_back( val );
}
}

return true;
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifCsvSummaryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RifCsvSummaryReader : public RifSummaryReaderInterface

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;

bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;

std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;

Expand Down
14 changes: 7 additions & 7 deletions ApplicationLibCode/FileInterface/RifCsvUserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ bool RifCsvUserData::parse( const QString& fileName, const AsciiDataParseOptions
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvUserData::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifCsvUserData::values( const RifEclipseSummaryAddress& resultAddress ) const
{
auto search = m_mapFromAddressToResultIndex.find( resultAddress );
std::vector<double> values;
auto search = m_mapFromAddressToResultIndex.find( resultAddress );
if ( search != m_mapFromAddressToResultIndex.end() )
{
size_t columnIndex = search->second;

const Column* ci = m_parser->columnInfo( columnIndex );
if ( !ci ) return false;
if ( !ci ) return { false, {} };

values->clear();
values->reserve( ci->values.size() );
values.reserve( ci->values.size() );
for ( double val : ci->values )
{
values->push_back( val );
values.push_back( val );
}
}

return true;
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifCsvUserData.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RifCsvUserData : public RifSummaryReaderInterface

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;

bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;

std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;

Expand Down
14 changes: 8 additions & 6 deletions ApplicationLibCode/FileInterface/RifDerivedEnsembleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ std::vector<time_t> RifDerivedEnsembleReader::timeSteps( const RifEclipseSummary
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifDerivedEnsembleReader::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifDerivedEnsembleReader::values( const RifEclipseSummaryAddress& resultAddress ) const
{
if ( !resultAddress.isValid() ) return false;
if ( !resultAddress.isValid() ) return { false, {} };

if ( m_derivedCase->needsCalculation( resultAddress ) )
{
m_derivedCase->calculate( resultAddress );
}

auto dataValues = m_derivedCase->values( resultAddress );
values->clear();
values->reserve( dataValues.size() );

std::vector<double> values;
values.reserve( dataValues.size() );
for ( auto val : dataValues )
values->push_back( val );
return true;
values.push_back( val );
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions ApplicationLibCode/FileInterface/RifDerivedEnsembleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class RifDerivedEnsembleReader : public RifSummaryReaderInterface
RifSummaryReaderInterface* sourceSummaryReader1,
RifSummaryReaderInterface* sourceSummaryReader2 );

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;

private:
RimDerivedSummaryCase* m_derivedCase;
Expand Down
16 changes: 7 additions & 9 deletions ApplicationLibCode/FileInterface/RifEclEclipseSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,17 @@ RifEclipseSummaryAddress addressFromErtSmSpecNode( const ecl::smspec_node& ertSu
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifEclEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress ) const
{
CVF_ASSERT( values );
if ( m_timeSteps.empty() ) return { true, {} };

if ( m_timeSteps.empty() ) return true;

values->clear();
values->reserve( m_timeSteps.size() );
std::vector<double> values;
values.reserve( m_timeSteps.size() );

if ( m_ecl_SmSpec )
{
int variableIndex = indexFromAddress( resultAddress );
if ( variableIndex < 0 ) return false;
if ( variableIndex < 0 ) return { false, {} };

const ecl::smspec_node& ertSumVarNode = ecl_smspec_iget_node_w_node_index( m_ecl_SmSpec, variableIndex );
int paramsIndex = ertSumVarNode.get_params_index();
Expand All @@ -279,12 +277,12 @@ bool RifEclEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress
{
int dataSize = double_vector_size( dataValues );
const double* dataPtr = double_vector_get_const_ptr( dataValues );
values->insert( values->end(), dataPtr, dataPtr + dataSize );
values.insert( values.end(), dataPtr, dataPtr + dataSize );
double_vector_free( dataValues );
}
}

return true;
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions ApplicationLibCode/FileInterface/RifEclEclipseSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class RifEclEclipseSummary : public RifSummaryReaderInterface

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;

bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;

private:
int indexFromAddress( const RifEclipseSummaryAddress& resultAddress ) const;
Expand Down
9 changes: 5 additions & 4 deletions ApplicationLibCode/FileInterface/RifKeywordVectorUserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,18 @@ bool RifKeywordVectorUserData::parse( const QString& data, const QString& custom
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifKeywordVectorUserData::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifKeywordVectorUserData::values( const RifEclipseSummaryAddress& resultAddress ) const
{
auto search = m_mapFromAddressToVectorIndex.find( resultAddress );
if ( search == m_mapFromAddressToVectorIndex.end() ) return false;
if ( search == m_mapFromAddressToVectorIndex.end() ) return { false, {} };

std::vector<double> values;
for ( const auto& v : m_parser->keywordBasedVectors()[search->second].values )
{
values->push_back( v );
values.push_back( v );
}

return true;
return { true, values };
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RifKeywordVectorUserData : public RifSummaryReaderInterface

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;

bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;

std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ std::vector<time_t> RifMultipleSummaryReaders::timeSteps( const RifEclipseSummar
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifMultipleSummaryReaders::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifMultipleSummaryReaders::values( const RifEclipseSummaryAddress& resultAddress ) const
{
for ( const auto& r : m_readers )
{
if ( r->hasAddress( resultAddress ) ) return r->values( resultAddress, values );
if ( r->hasAddress( resultAddress ) ) return r->values( resultAddress );
}

return false;
return { false, {} };
}

//--------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions ApplicationLibCode/FileInterface/RifMultipleSummaryReaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class RifMultipleSummaryReaders : public RifSummaryReaderInterface
void addReader( RifSummaryReaderInterface* reader );
void removeReader( RifSummaryReaderInterface* reader );

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;

void rebuildMetaData();

Expand Down
13 changes: 7 additions & 6 deletions ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,27 @@ std::vector<time_t> RifOpmCommonEclipseSummary::timeSteps( const RifEclipseSumma
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifOpmCommonEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const
std::pair<bool, std::vector<double>> RifOpmCommonEclipseSummary::values( const RifEclipseSummaryAddress& resultAddress ) const
{
auto it = m_summaryAddressToKeywordMap.find( resultAddress );
if ( it != m_summaryAddressToKeywordMap.end() )
{
auto keyword = it->second;
std::vector<double> values;
auto keyword = it->second;
if ( m_enhancedReader )
{
auto fileValues = m_enhancedReader->get( keyword );
values->insert( values->begin(), fileValues.begin(), fileValues.end() );
values.insert( values.begin(), fileValues.begin(), fileValues.end() );
}
else if ( m_standardReader )
{
auto fileValues = m_standardReader->get( keyword );
values->insert( values->begin(), fileValues.begin(), fileValues.end() );
values.insert( values.begin(), fileValues.begin(), fileValues.end() );
}
return true;
return { true, values };
}

return false;
return { false, {} };
}

//--------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions ApplicationLibCode/FileInterface/RifOpmCommonSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class RifOpmCommonEclipseSummary : public RifSummaryReaderInterface

bool open( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );

std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
bool values( const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;

private:
void buildMetaData();
Expand Down
Loading

0 comments on commit d177491

Please sign in to comment.