Files
ResInsight/ApplicationLibCode/ReservoirDataModel/ContourMap/RigEclipseContourMapProjection.h
T
Magne Sjaastad ed96d155fc #14007 Contour Map: rebuild projection when cached case data is stale
Reloading a grid file frees and recreates RigEclipseCaseData. The contour map projection caches raw pointers into the case data and previously only refreshed them when reset explicitly via RimReloadCaseTools::updateAll3dViews(). Callers of RimEclipseCase::reloadEclipseGridFile() that bypass updateAll3dViews(), such as RimOpmFlowJob::onCompleted(), left the projection holding dangling pointers that crashed in generateResults/hasResultEntry on the next redraw. The projection now detects that its cached RigEclipseCaseData no longer matches the current case and rebuilds itself before the stale pointers are dereferenced.
2026-06-10 12:33:45 +02:00

106 lines
5.7 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Equinor 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 "RigContourMapCalculator.h"
#include "RigContourMapProjection.h"
#include "RigEclipseResultAddress.h"
#include "RigFloodingSettings.h"
#include "cvfBoundingBox.h"
#include <expected>
#include <set>
#include <string>
class RigActiveCellInfo;
class RigMainGrid;
class RigContourMapGrid;
class RigResultAccessor;
class RigEclipseCaseData;
class RigCaseCellResultsData;
//==================================================================================================
///
///
//==================================================================================================
class RigEclipseContourMapProjection : public RigContourMapProjection
{
public:
RigEclipseContourMapProjection( const RigContourMapGrid* contourMapGrid,
RigEclipseCaseData* eclipseCaseData,
RigCaseCellResultsData* resultData );
virtual ~RigEclipseContourMapProjection();
void generateAndSaveResults( const RigEclipseResultAddress& resultAddress,
RigContourMapCalculator::ResultAggregationType resultAggregation,
int timeStep,
RigFloodingSettings& floodingSettings );
std::vector<double> generateResults( const RigEclipseResultAddress& resultAddress,
RigContourMapCalculator::ResultAggregationType resultAggregation,
int timeStep,
RigFloodingSettings& floodingSettings ) const;
static std::pair<bool, std::vector<double>> generateResults( const RigEclipseContourMapProjection& contourMapProjection,
const RigContourMapGrid& contourMapGrid,
RigCaseCellResultsData& resultData,
const RigEclipseResultAddress& resultAddress,
RigContourMapCalculator::ResultAggregationType resultAggregation,
int timeStep,
RigFloodingSettings& floodingSettings );
void updateRealizationData( RigActiveCellInfo* activeCellInfo, RigCaseCellResultsData* resultData );
// The case data this projection cached its raw pointers from. Used to detect when the owning case has been
// reloaded (RigEclipseCaseData freed and recreated) so the projection can be rebuilt before the stale pointers
// are dereferenced.
const RigEclipseCaseData* eclipseCaseData() const;
std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationType resultAggregation ) override;
bool isCellActive( size_t globalCellIdx ) const override;
protected:
using CellIndexAndResult = RigContourMapProjection::CellIndexAndResult;
std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& bbox ) const override;
size_t kLayer( size_t globalCellIdx ) const override;
size_t kLayers() const override;
double calculateOverlapVolume( size_t globalCellIdx, const cvf::BoundingBox& bbox ) const override;
double calculateRayLengthInCell( size_t globalCellIdx, const cvf::Vec3d& highestPoint, const cvf::Vec3d& lowestPoint ) const override;
double getParameterWeightForCell( size_t cellResultIdx, const std::vector<double>& parameterWeights ) const override;
size_t gridResultIndex( size_t globalCellIdx ) const override;
static std::expected<std::vector<double>, std::string> calculateColumnResult( RigCaseCellResultsData& resultData,
RigContourMapCalculator::ResultAggregationType resultAggregation,
int timeStep,
RigFloodingSettings& floodingSettings );
static std::set<RigEclipseResultAddress> neededResults( RigContourMapCalculator::ResultAggregationType resultAggregation,
RigFloodingSettings& floodingSettings );
protected:
RigEclipseCaseData* m_eclipseCaseData;
RigCaseCellResultsData* m_resultData;
RigMainGrid* m_mainGrid;
RigActiveCellInfo* m_activeCellInfo;
size_t m_kLayers;
bool m_useActiveCellInfo;
};