mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-26 07:38:44 -06:00
Derived cases were pooled through an m_inUse flag on RimDeltaSummaryCase. Every regeneration marked all cases not in use, which also severed their source references and cleared their caches, then handed them back out one by one and deleted whatever was left over. The flag conflated pool bookkeeping with owning the source references, allSummaryCases() hid the not-in-use cases from the rest of the project, and cases taken from the pool were pushed straight into m_cases without connecting nameChanged, so a renamed source case never propagated to the derived case. Replace the pooling with desiredSourceCasePairs(), a pure computation of the source case pairs the ensemble should have, and rebuildDerivedCases(), which diffs that against the existing derived cases keyed on the source case pointer pair. Matching cases are reused, missing ones are created, and surplus ones are detached and returned to the caller instead of being deleted in place. Keying on the pointer pair makes the rebuild idempotent, also right after project load where the derived cases arrive from XML with their sources already resolved. Add the protected RimSummaryEnsemble::addCaseWithoutDependencyUpdate(), used both by addCase() and by the rebuild, so a derived case gets nameChanged connected without triggering the dependent-ensemble notification that the rebuild is already performing itself. Remove setAllCasesNotInUse(), firstCaseNotInUse(), deleteCasesNoInUse(), RimDeltaSummaryCase::setInUse()/isInUse() and the m_inUse field, and add clearSourceCases() for the one thing setInUse(false) was actually needed for. Old project files keep loading, unknown XML keywords are skipped. The activeOnly parameter of allDerivedCases() is gone and RimDeltaSummaryEnsemble no longer overrides allSummaryCases().
116 lines
4.8 KiB
C++
116 lines
4.8 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2016 Statoil ASA
|
|
//
|
|
// 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.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
#pragma once
|
|
|
|
#include "RifSummaryReaderInterface.h"
|
|
|
|
#include "RimSummaryCase.h"
|
|
|
|
#include "cafPdmField.h"
|
|
#include "cafPdmObject.h"
|
|
#include "cafPdmPtrField.h"
|
|
|
|
#include <memory>
|
|
|
|
class RifEclipseSummaryAddress;
|
|
|
|
//==================================================================================================
|
|
///
|
|
//==================================================================================================
|
|
enum class DerivedSummaryOperator
|
|
{
|
|
DERIVED_OPERATOR_SUB,
|
|
DERIVED_OPERATOR_ADD
|
|
};
|
|
|
|
//==================================================================================================
|
|
//
|
|
//==================================================================================================
|
|
class RimDeltaSummaryCase : public RimSummaryCase, public RifSummaryReaderInterface
|
|
{
|
|
CAF_PDM_HEADER_INIT;
|
|
|
|
public:
|
|
enum class FixedTimeStepMode
|
|
{
|
|
FIXED_TIME_STEP_NONE,
|
|
FIXED_TIME_STEP_CASE_1,
|
|
FIXED_TIME_STEP_CASE_2
|
|
};
|
|
|
|
public:
|
|
RimDeltaSummaryCase();
|
|
|
|
void setSummaryCases( RimSummaryCase* sumCase1, RimSummaryCase* sumCase2 );
|
|
void clearSourceCases();
|
|
void setOperator( DerivedSummaryOperator oper );
|
|
void setFixedTimeSteps( int fixedTimeStepCase1, int fixedTimeStepCase2 );
|
|
|
|
bool needsCalculation( const RifEclipseSummaryAddress& address ) const;
|
|
|
|
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
|
|
|
|
std::vector<time_t> timeSteps( const RifEclipseSummaryAddress& resultAddress ) const override;
|
|
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
|
|
RiaDefines::EclipseUnitSystem unitSystem() const override;
|
|
|
|
static std::pair<std::vector<time_t>, std::vector<double>> calculateDerivedValues( RifSummaryReaderInterface* reader1,
|
|
int fixedTimeStepCase1,
|
|
RifSummaryReaderInterface* reader2,
|
|
int fixedTimeStepCase2,
|
|
DerivedSummaryOperator m_operator,
|
|
const RifEclipseSummaryAddress& address,
|
|
bool includeIncompleteCurves );
|
|
|
|
void createSummaryReaderInterface() override;
|
|
RifSummaryReaderInterface* summaryReader() override;
|
|
|
|
void updateDisplayNameFromCases();
|
|
|
|
RimSummaryCase* summaryCase1() const;
|
|
RimSummaryCase* summaryCase2() const;
|
|
|
|
protected:
|
|
QString caseName() const override;
|
|
size_t keywordCount() const override;
|
|
|
|
private:
|
|
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
|
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
|
|
|
|
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
|
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
|
|
|
void calculate( const RifEclipseSummaryAddress& address ) const;
|
|
void clearData( const RifEclipseSummaryAddress& address ) const;
|
|
|
|
void clearCache();
|
|
|
|
private:
|
|
caf::PdmPtrField<RimSummaryCase*> m_summaryCase1;
|
|
caf::PdmPtrField<RimSummaryCase*> m_summaryCase2;
|
|
|
|
caf::PdmField<caf::AppEnum<DerivedSummaryOperator>> m_operator;
|
|
|
|
caf::PdmField<caf::AppEnum<FixedTimeStepMode>> m_useFixedTimeStep;
|
|
caf::PdmField<int> m_fixedTimeStepIndex;
|
|
|
|
// Local cache considered mutable
|
|
mutable std::map<RifEclipseSummaryAddress, std::pair<std::vector<time_t>, std::vector<double>>> m_dataCache;
|
|
};
|