mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
#8370: Create summary addresses and handle unknown vectors when setting summary values
This commit is contained in:
1 parent
36f649b8ad
commit
038dabc77b
4 files changed
+64
-4
No files matched your search
@@ -303,6 +303,10 @@ void RimFileSummaryCase::openAndAttachAdditionalReader()
|
||||
auto isValid = opmCommonReader->open( additionalSummaryFilePath, includeRestartFiles, nullptr );
|
||||
if ( isValid )
|
||||
{
|
||||
// The additional file is small, and the addresses are required to read values also when the addresses of the case are not
|
||||
// created (e.g. realizations in an ensemble)
|
||||
opmCommonReader->createAddressesIfRequired();
|
||||
|
||||
m_additionalSummaryReaderId = opmCommonReader->serialNumber();
|
||||
m_multiSummaryReader->addReader( std::move( opmCommonReader ) );
|
||||
}
|
||||
@@ -361,6 +365,11 @@ std::expected<void, QString>
|
||||
|
||||
auto address = RifEclipseSummaryAddress::fromEclipseTextAddressParseErrorTokens( keyword );
|
||||
auto fileReader = m_multiSummaryReader->findReader( m_fileSummaryReaderId );
|
||||
if ( fileReader )
|
||||
{
|
||||
// Addresses are created lazily, and can be missing for realizations in an ensemble
|
||||
fileReader->createAddressesIfRequired();
|
||||
}
|
||||
if ( fileReader && fileReader->hasAddress( address ) )
|
||||
{
|
||||
QString errorMsg = QString( "Cannot set summary values for '%1' because the vector comes from the source summary file. "
|
||||
@@ -433,31 +442,67 @@ std::expected<void, QString>
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimFileSummaryCase::additionalSummaryFilePath() const
|
||||
{
|
||||
return m_additionalSummaryFilePath().path();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Attach an existing file with user-defined summary vectors. Used when the case is recreated, e.g. when
|
||||
/// an ensemble is defined by a file set and the cases are not stored in the project file.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFileSummaryCase::setAdditionalSummaryFilePath( const QString& filePath )
|
||||
{
|
||||
if ( filePath.isEmpty() || !QFile::exists( filePath ) ) return;
|
||||
|
||||
m_additionalSummaryFilePath = filePath;
|
||||
|
||||
if ( m_multiSummaryReader )
|
||||
{
|
||||
m_multiSummaryReader->removeReader( m_additionalSummaryReaderId );
|
||||
openAndAttachAdditionalReader();
|
||||
|
||||
// Addresses are created lazily for realizations in an ensemble, only refresh if already created
|
||||
if ( !m_multiSummaryReader->allResultAddresses().empty() )
|
||||
{
|
||||
m_multiSummaryReader->createAndSetAddresses();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimFileSummaryCase::onProjectBeingSaved()
|
||||
{
|
||||
// If additional data is stored in temp folder, copy to project folder and remove file in temp folder
|
||||
// If additional data is stored in temp folder, copy to project folder and remove file in temp folder. The project file is not written
|
||||
// yet, so additionalSummaryDataFilePath() would still point to the temp folder on the first save.
|
||||
const QString projectFileName = RimProject::current() ? RimProject::current()->fileName() : QString();
|
||||
if ( projectFileName.isEmpty() ) return;
|
||||
|
||||
auto existingFilePath = m_additionalSummaryFilePath().path();
|
||||
if ( QFile::exists( existingFilePath ) )
|
||||
{
|
||||
auto currentFilePath = additionalSummaryDataFilePath();
|
||||
auto currentFilePath = QFileInfo( projectFileName ).dir().absoluteFilePath( QFileInfo( existingFilePath ).fileName() );
|
||||
if ( existingFilePath != currentFilePath )
|
||||
{
|
||||
if ( m_multiSummaryReader ) m_multiSummaryReader->removeReader( m_additionalSummaryReaderId );
|
||||
|
||||
if ( QFile::copy( existingFilePath, currentFilePath ) )
|
||||
{
|
||||
QFile::remove( existingFilePath );
|
||||
m_additionalSummaryFilePath = currentFilePath;
|
||||
|
||||
openAndAttachAdditionalReader();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString txt = "Error when copying temporary file to " + currentFilePath;
|
||||
RiaLogging::error( txt.toStdString() );
|
||||
}
|
||||
|
||||
if ( m_multiSummaryReader ) openAndAttachAdditionalReader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ public:
|
||||
std::expected<void, QString> setSummaryData( const std::string& keyword, const std::string& unit, const std::vector<float>& values );
|
||||
void onProjectBeingSaved();
|
||||
|
||||
QString additionalSummaryFilePath() const;
|
||||
void setAdditionalSummaryFilePath( const QString& filePath );
|
||||
|
||||
static std::unique_ptr<RifSummaryReaderInterface> findRelatedFilesAndCreateReader( const QString& headerFileName,
|
||||
bool lookForRestartFiles,
|
||||
RifEnsembleImportConfig ensembleImportState,
|
||||
|
||||
Reference in new issue
Block a user