Skip to content

Commit

Permalink
Select none, all cases or a grid case group to apply a calculation
Browse files Browse the repository at this point in the history
This will enable the use of expressions var_a = sum(x) on a grid case group
  • Loading branch information
magnesj committed Jan 22, 2024
1 parent d618389 commit e2e861e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
71 changes: 51 additions & 20 deletions ApplicationLibCode/ProjectDataModel/RimGridCalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
#include "RigResultAccessorFactory.h"
#include "RigStatisticsMath.h"

#include "RimCaseCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCaseTools.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseResultAddress.h"
#include "RimEclipseStatisticsCase.h"
#include "RimEclipseView.h"
#include "RimGridCalculationCollection.h"
#include "RimGridCalculationVariable.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimReloadCaseTools.h"
#include "RimResultSelectionUi.h"
Expand All @@ -67,6 +71,14 @@ void caf::AppEnum<RimGridCalculation::DefaultValueType>::setUp()
addItem( RimGridCalculation::DefaultValueType::USER_DEFINED, "USER_DEFINED", "User Defined Custom Value" );
setDefault( RimGridCalculation::DefaultValueType::POSITIVE_INFINITY );
}
template <>
void caf::AppEnum<RimGridCalculation::AdditionalCasesType>::setUp()
{
addItem( RimGridCalculation::AdditionalCasesType::NONE, "NONE", "None" );
addItem( RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP, "GRID_CASE_GROUP", "Case Group" );
addItem( RimGridCalculation::AdditionalCasesType::ALL_CASES, "NONE", "All Cases" );
setDefault( RimGridCalculation::AdditionalCasesType::NONE );
}
}; // namespace caf

//--------------------------------------------------------------------------------------------------
Expand All @@ -79,7 +91,12 @@ RimGridCalculation::RimGridCalculation()
CAF_PDM_InitFieldNoDefault( &m_defaultValueType, "DefaultValueType", "Non-visible Cell Value" );
CAF_PDM_InitField( &m_defaultValue, "DefaultValue", 0.0, "Custom Value" );
CAF_PDM_InitFieldNoDefault( &m_destinationCase, "DestinationCase", "Destination Case" );
CAF_PDM_InitField( &m_applyToAllCases, "AllDestinationCase", false, "Apply to All Cases" );

CAF_PDM_InitField( &m_applyToAllCases_OBSOLETE, "AllDestinationCase", false, "Apply to All Cases" );
m_applyToAllCases_OBSOLETE.xmlCapability()->setIOWritable( false );

CAF_PDM_InitFieldNoDefault( &m_additionalCasesType, "AdditionalCasesType", "Apply To Additional Cases" );
CAF_PDM_InitFieldNoDefault( &m_additionalCaseGroup, "AdditionalCaseGroup", "Case Group" );

CAF_PDM_InitFieldNoDefault( &m_nonVisibleResultAddress, "NonVisibleResultAddress", "" );
m_nonVisibleResultAddress = new RimEclipseResultAddress;
Expand All @@ -102,7 +119,7 @@ RimGridCalculation::RimGridCalculation()
//--------------------------------------------------------------------------------------------------
bool RimGridCalculation::preCalculate() const
{
if ( RiaGuiApplication::isRunning() && m_applyToAllCases() )
if ( RiaGuiApplication::isRunning() && m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::NONE )
{
const QString cacheKey = "GridCalculatorMessage";

Expand Down Expand Up @@ -222,17 +239,18 @@ bool RimGridCalculation::calculate()
//--------------------------------------------------------------------------------------------------
std::vector<RimEclipseCase*> RimGridCalculation::outputEclipseCases() const
{
if ( m_applyToAllCases )
if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::ALL_CASES )
{
// Find all Eclipse cases suitable for grid calculations. This includes all single grid cases and source cases in a grid case group.
// Exclude the statistics cases, as it is not possible to use them in a grid calculations.
//
// Note that data read from file can be released from memory when statistics for a time step is calculated. See
// RimEclipseStatisticsCaseEvaluator::evaluateForResults()

return RimEclipseCaseTools::allEclipseGridCases();
}

if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP )
{
if ( m_additionalCaseGroup() ) return m_additionalCaseGroup->reservoirs.childrenByType();
}

return { m_destinationCase };
}

Expand Down Expand Up @@ -287,12 +305,9 @@ void RimGridCalculation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrder

uiOrdering.add( &m_destinationCase );

uiOrdering.add( &m_applyToAllCases );
if ( !allSourceCasesAreEqualToDestinationCase() )
{
m_applyToAllCases = false;
}
m_applyToAllCases.uiCapability()->setUiReadOnly( !allSourceCasesAreEqualToDestinationCase() );
uiOrdering.add( &m_additionalCasesType );
uiOrdering.add( &m_additionalCaseGroup );
m_additionalCaseGroup.uiCapability()->setUiHidden( m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP );

caf::PdmUiGroup* filterGroup = uiOrdering.addNewGroup( "Cell Filter" );
filterGroup->setCollapsedByDefault();
Expand Down Expand Up @@ -339,8 +354,8 @@ QList<caf::PdmOptionItemInfo> RimGridCalculation::calculateValueOptions( const c
}
else
{
// If no input cases are defined, use the destination case to determine the grid size. This will enable use of expressions with
// no input cases like "calculation := 1.0"
// If no input cases are defined, use the destination case to determine the grid size. This will enable use of expressions
// with no input cases like "calculation := 1.0"
firstEclipseCase = m_destinationCase();
}

Expand Down Expand Up @@ -391,6 +406,20 @@ QList<caf::PdmOptionItemInfo> RimGridCalculation::calculateValueOptions( const c
}
}
}
else if ( &m_additionalCaseGroup == fieldNeedingOptions )
{
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );

RimProject* proj = RimProject::current();
if ( proj->activeOilField() && proj->activeOilField()->analysisModels() )
{
auto analysisModels = proj->activeOilField()->analysisModels();
for ( RimIdenticalGridCaseGroup* cg : analysisModels->caseGroups() )
{
options.push_back( caf::PdmOptionItemInfo( cg->name(), cg, false, cg->uiIconProvider() ) );
}
}
}

return options;
}
Expand All @@ -410,6 +439,8 @@ void RimGridCalculation::initAfterRead()
if ( m_destinationCase == nullptr ) m_destinationCase = gridVar->eclipseCase();
}
}

if ( m_applyToAllCases_OBSOLETE ) m_additionalCasesType = RimGridCalculation::AdditionalCasesType::ALL_CASES;
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -561,8 +592,8 @@ std::vector<double> RimGridCalculation::getDataForResult( const QString&
auto rigCaseCellResultsData = eclipseCaseData->results( porosityModel );
if ( !rigCaseCellResultsData->findOrLoadKnownScalarResultForTimeStep( resAddr, timeStepToUse ) ) return {};

// Active cell info must always be retrieved from the destination case, as the returned vector must be of the same size as number of
// active cells in the destination case. Active cells can be different between source and destination case.
// Active cell info must always be retrieved from the destination case, as the returned vector must be of the same size as
// number of active cells in the destination case. Active cells can be different between source and destination case.
auto activeCellInfoDestination = destinationCase->eclipseCaseData()->activeCellInfo( porosityModel );
auto activeReservoirCells = activeCellInfoDestination->activeReservoirCellIndices();

Expand Down Expand Up @@ -972,9 +1003,9 @@ void RimGridCalculation::findAndEvaluateDependentCalculations( const std::vector
{
if ( dependentCalc == this ) continue;

// Propagate the settings for this calculation to the dependent calculation. This will allow changes on top level calculation to be
// propagated to dependent calculations automatically. Do not trigger findAndEvaluateDependentCalculations() recursively, as all
// dependent calculations are traversed in this function.
// Propagate the settings for this calculation to the dependent calculation. This will allow changes on top level
// calculation to be propagated to dependent calculations automatically. Do not trigger
// findAndEvaluateDependentCalculations() recursively, as all dependent calculations are traversed in this function.

bool evaluateDependentCalculations = false;
dependentCalc->calculateForCases( calculationCases, inputValueVisibilityFilter, timeSteps, evaluateDependentCalculations );
Expand Down
14 changes: 13 additions & 1 deletion ApplicationLibCode/ProjectDataModel/RimGridCalculation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RimEclipseCase;
class RimGridView;
class RigEclipseResultAddress;
class RimEclipseResultAddress;
class RimCaseCollection;

//==================================================================================================
///
Expand All @@ -50,6 +51,13 @@ class RimGridCalculation : public RimUserDefinedCalculation
USER_DEFINED
};

enum class AdditionalCasesType
{
NONE,
GRID_CASE_GROUP,
ALL_CASES
};

RimGridCalculation();

bool preCalculate() const override;
Expand Down Expand Up @@ -136,11 +144,15 @@ class RimGridCalculation : public RimUserDefinedCalculation
caf::PdmField<caf::AppEnum<DefaultValueType>> m_defaultValueType;
caf::PdmField<double> m_defaultValue;
caf::PdmPtrField<RimEclipseCase*> m_destinationCase;
caf::PdmField<bool> m_applyToAllCases;

caf::PdmField<caf::AppEnum<AdditionalCasesType>> m_additionalCasesType;
caf::PdmPtrField<RimCaseCollection*> m_additionalCaseGroup;

caf::PdmField<std::vector<int>> m_selectedTimeSteps;

caf::PdmProxyValueField<QString> m_nonVisibleResultText;
caf::PdmChildField<RimEclipseResultAddress*> m_nonVisibleResultAddress;
caf::PdmField<bool> m_editNonVisibleResultAddress;

caf::PdmField<bool> m_applyToAllCases_OBSOLETE;
};

0 comments on commit e2e861e

Please sign in to comment.