A case in an ensemble can have fewer time steps than the case defining the time step axis of a statistics case. The time step index was used to index m_cellScalarResults directly, reading past the end of the vector in Release where CAF_ASSERT is a no-op.
The map size of the sample grid was recomputed from the expanded bounding box and the sample spacing stored in the project file. The expanded bounding box is an exact multiple of the sample spacing, but after the limited precision of the project file the division can land just above a whole number of cells, and the map size gets one extra cell. The cache files were then rejected, and the ensemble statistics recomputed.
Store the map size in the project file, and use it directly when the sample grid is restored from the cache.
Identify the input grids of the cache validity key by file path, size and modification time, so that the cache is also invalidated when a grid file is modified in place. Label and count the primary case and the ensemble cases, so that a primary case can not be mistaken for the first ensemble case.
A refinement level with a single reconstructed LGR keeps the bare level name (LGR_NHG_L2). A level with several LGRs now numbers all of them with 1-based suffixes (LGR_NHG_L4_1 .. LGR_NHG_L4_N) instead of leaving the first one without a suffix.
All unnamed critical regions map to the same implicit name, so a single process wide lock was shared by summary import, geometry generation, grid bounding box computation and NNC merging. Unrelated parallel loops therefore serialized against each other.
Give each region a critical_section_ name describing what it protects. The two regions guarding RifOpmCommonEclipseSummary::sm_createdEsmryFileCount deliberately share one name, as they protect the same counter.
totalNumberOfConnections was declared, listed in the reduction clause and used to size otherConnections, but it was never incremented. The counting was lost when the loop body was moved into extractConnectionsForFace, so the call has always been reserve( size() + 0 ), which RigConnectionContainer::reserve turns into a no-op.
The reserve was also called by every thread on the shared container without synchronization. Removing it eliminates that data race. The explicit barrier is redundant as well, since the omp for construct has no nowait clause and therefore already synchronizes before the merge.
Simulators for two-phase gas/water models may report only SWAT. In this case no SGAS result entry was created, so SGAS was missing from the result list and TERNARY fell back to computing SOIL = 1 - SWAT, presenting the gas saturation as oil saturation.
Add RigSgasResultCalculator that creates a placeholder SGAS entry when the model has gas and water but no oil phase, SWAT is present and SGAS is missing. SGAS is then computed as SGAS = 1 - SWAT. The computation is dispatched from findOrLoadKnownScalarResult() and findOrLoadKnownScalarResultForTimeStep() the same way as SOIL.
The equivalent logic in RigCaseCellResultsData::testAndComputeSgasForTimeStep() was only reachable from RigSoilResultCalculator, which never runs for models without an oil phase. This function is replaced by computeSgasForTimeStep() delegating to the new calculator, and the unreachable call in RigSoilResultCalculator is removed.
findOrLoadKnownScalarResultForTimeStep asserted when the reader failed to
load a result. A result listed in the meta data that cannot be read from
file is a run-time condition, not a programming error, and aborted the
application in builds with asserts enabled.
Report the failing result name and time step through RiaLogging instead.
Add BinningMode (Linear/Logarithmic) and OutOfRangeHandling (Exclude/Include in
Boundary Bins) to RigHistogramCalculator, with defaulted constructor arguments so
existing callers are unaffected. All four histogram plot data sources get shared
options for binning mode and an optional user-defined bin range through new PDM
fields on RimHistogramDataSource.
The grid statistics data source computes non-default histograms through a new
non-caching RigStatisticsDataCache::computeHistogram() pass-through, leaving the
cached statistics used by the 3D overlay and the P10/P90/mean annotation lines
untouched.
Selecting logarithmic binning enables logarithmic scale on the plot X axis once,
via a new signal handled by RimHistogramCurve.
Also fix the bin index computation to use uniform bins of width range/nBins,
consistent with calculatePercentil() and the bin edges drawn by the plots. The
previous divisor (nBins - 1) shifted counts by up to one bin width relative to
the drawn bars and slightly biased histogram-based percentile estimates.
A new contour map created from the right-click menu on a case used a hardcoded SOIL result, resulting in an empty view when SOIL was not present in the case. Use the cell result of an existing view for the same case if one is available, and otherwise fall back to RigCaseCellResultsData::defaultResult(), which verifies that the result exists before selecting it. Completion Type is a category result and is now excluded as a default result for both 3d views and contour maps.
RigAllGridCellsResultAccessor bounds checked the cell index with an assert that is compiled out in release builds, and then called std::vector::at(), which throws. RimGridCalculation::getActiveCellValues() calls the accessor from an OpenMP loop, using active cell indices from the destination case to read results from the source case, so an index beyond the source result vector threw an exception that could not escape the parallel region and called std::terminate. Return undefined for an out of range index instead, and guard against a null result accessor.
computeRiTransComponent() checks the transmissibility index and the neighbor
cell permeability index for cvf::UNDEFINED_SIZE_T, but not the permeability
index of the cell itself. The transmissibility and permeability results are
indexed independently, so a defined transmissibility index does not imply a
defined permeability index. For a case where transmissibility is stored per
cell and permeability per active cell, an inactive cell passes the
transmissibility check and then indexes the permeability vector with
UNDEFINED_SIZE_T.
Check the permeability index of the cell before use, matching the guard in
computeNncCombRiTrans().
Remove 95 cvf include lines that the including file does not use. Found by
extracting the symbols declared by every VizFwk header, including symbols they
re-export, and flagging includes where none of those symbols appear anywhere in
the file. Each removal is verified by a full build.
Most of them are cvfVector3.h and cvfObject.h, left behind as the files they
were once needed by changed.
pch.h is left untouched. It includes cvfObject.h and cvfVector3.h on purpose, so
that the files using the precompiled header do not have to.
Note that a clean build after removing an include does not prove the include was
unnecessary, only that the declarations still arrive some other way. That path
can differ between platforms and with RESINSIGHT_ENABLE_UNITY_BUILD, so this
needs a CI round on Linux as well.
Migrate all assert macros in ApplicationLibCode to CAF_ASSERT and remove every
use of cvfAssert.h.
CVF_ASSERT is replaced one to one. CVF_TIGHT_ASSERT is also replaced by
CAF_ASSERT, which is semantically exact: CVF_ENABLE_TIGHT_ASSERTS is 1 only
under _DEBUG, and that is what CAF_ASSERT now does. The two CVF_FAIL_MSG sites
become CAF_ASSERT( false && "message" ), preserving the message with the idiom
already used elsewhere in the code base.
Counts before and after: CVF_ASSERT 1044 to 0, CVF_TIGHT_ASSERT 66 to 0,
CVF_FAIL_MSG 2 to 0, cvfAssert.h references 154 to 0.
Include handling: files that included cvfAssert.h directly now include
cafAssert.h instead, includes left dead by the migration are removed, and files
that were relying on cvfAssert.h transitively get an explicit cafAssert.h. Files
that reach cafAssert.h through another caf header are left unchanged; a missing
include here is a compile error, not a silently disabled assert.
ResultStatisticsCache links only LibCore and therefore had no path to
cafAssert.h. Add the cafPdmCore directory as a private include path rather than
linking the library, since cafAssert.h is header only.
Note that this stops these asserts from firing in Release and RelWithDebInfo,
where CVF_ASSERT was previously active.
* Use guarded pointer for delayed plot updates
The cached result definition can be deleted before the delayed update is
executed, causing a crash in the PVT and relative permeability plot panels.
* Guard against fracture definition without conductivity result
The list of conductivity result names is empty for some fracture
definitions, causing an out of range access when computing statistics.
* Guard against missing data source in custom VFP plot
The data source of a VFP table can be null, and the VFP tables are not
available until the data has been imported.
* Recompute well cell arrays when the grids change
computeWellCellsPrGrid() returned early whenever the arrays had been computed once, so the
size check below it was unreachable and a stale array was kept when the grids changed. The
too-short array triggered an assert in RivReservoirViewPartMgr::computeNativeVisibility.
Return early only when the cached arrays still match the current set of grids.
* Guard against missing GUI application when applying style sheet
RiaGuiApplication::instance() does a dynamic_cast and returns null outside a GUI context. The
assert guarding this is compiled out in release, so the null pointer was dereferenced.
* Guard against missing case in flow characteristics plot field change
The case field can be set to nothing from the UI. RimEclipseResultCase::defaultFlowDiagSolution()
and reservoirViews() were then called on a null pointer.
* Guard against missing case and out of range time steps when updating flow characteristics plot
onLoadDataAndUpdate() dereferenced the case without checking, although the same function handles
a missing case further down. The time step indices come from the flow diagnostics solution, and
were used to index arrays sized by the number of case time steps without a range check.
The gap intersection inserted when the well path leaves the grid was pushed to
the result vector before the cell it follows, leaving the intersections
unsorted. This produced a non-increasing Length column in the exported WELSEGS
table.
RigWellPath::interpolatedVectorValuesAlongWellPath indexed vectorValuesAlongWellPath.at( vxIdx - 1 ) when no measured depths were present, causing an out of range exception and terminate. Return cvf::Vec3d::UNDEFINED for empty geometry, matching tangentAlongWellPath. RimWellPathFracture keeps the zero anchor position when the point is undefined.
RigCaseCellResultsData and RigFemPartResultsCollection held a raw pointer to RigFormationNames owned by a unique_ptr in RimFormationNames. Reloading or deleting the formation names left the case data with a dangling pointer. Store a copy instead, as RigFormationNames is a small value type with no identity.
The sign of the projected formation direction vector flips with the fracture
direction normal, which follows the well drilling direction, while the fracture
azimuth defining the dip rotation in RimFracture::transformMatrix() is only
defined mod 180 degrees. Canonicalize the formation direction against the
fracture azimuth direction before computing the dip, so a positive dip means
the formation descends toward the azimuth direction.
Restore std::abs() in calculateFormationDipFromHorizontal() so the StimPlan
model formation dip (BedDipDeg in the Asymmetric FRK export) keeps the
non-negative convention from #8877.
The depth-related geometry results (DEPTH/DX/DY/DZ/TOPS/BOTTOM) are derived
purely from the shared grid geometry and were computed independently for the
matrix and fracture porosity models. For dual-porosity cases this recomputed the
identical per-cell geometry twice.
Replace the per-model computeDepthRelatedResults() with a single static routine
that traverses the shared main grid once, computing each cell's geometry a single
time and writing it to every porosity model in which the cell is active. The
per-property already-computed guards and the temporary-grid recompute path are
preserved, so the stored values are unchanged. All six matrix+fracture call sites
now go through a thin RigEclipseCaseData::computeDepthRelatedResults() wrapper.
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.
RigMainGrid::findIntersectingCells is const and lazily builds the mutable m_cellSearchTree without synchronization, yet it is called from many multi-threaded (OpenMP) query paths. When two threads race the isNull check, both build a new tree and the cvf::ref reassignment deletes the first tree while it is still being built, leading to a use-after-free and a segfault deep in AABBTree::buildTree (BoundingBox::addValid reading a dangling leaf box).
Serialize building of the cell search tree with a mutex, both in computeCachedData (which nulls and rebuilds the tree) and in the lazy build in findIntersectingCells. The query also keeps a local reference to the tree so it stays alive if another thread rebuilds m_cellSearchTree during the read-only intersection query.
The leaf-node cap that selects between the optimized and the
non-optimized cell search tree construction used cellCount(), which
only counts main grid cells and excludes LGR cells. The non-optimized
buildCellSearchTree() iterates totalCellCount() (main grid plus all LGR
cells) and creates one leaf per cell, so a grid with few main cells but
many LGR cells could be routed into that path and exhaust memory,
crashing while building the AABB tree.
Base the threshold on totalCellCount() so LGR-inflated grids are routed
to the optimized aggregating path and the leaf count stays bounded.
calculateWellPipeStaticCenterline dereferenced eclipseView->eclipseCase()
without checking for null. When the view has no eclipse case (or no case
data), calling eclipseCaseData() on the null RimEclipseCase segfaulted
during a timestep frame change that redraws simulation well pipes.
Add the same null guard already used by the sibling method
RimSimWellInView::wellHeadTopBottomPosition, returning early so no pipe
geometry is produced when there is no case data.
computeFaultDistances faked a nearest-point query with cvf::BoundingBoxTree,
which only supports box overlap: it grew a cell-sized box until it overlapped a
fault face. For cells far from any fault this did many full tree traversals and
then brute-forced the distance to a large, over-collected candidate set, and the
answer was only approximate. This was slow on grids with ~10 million cells.
The metric is the distance from each cell center to the nearest fault face
center, which is exactly a nearest-point search. Replace the bounding-box tree
and the grow-the-box loop with a nanoflann KD-tree built over the fault face
centers and a single nearest-neighbor query per active cell. A zero-copy adaptor
reads the existing std::vector<cvf::Vec3d> directly. The OpenMP loop is retained
since nanoflann queries are read-only. The result is O(F log F) build plus
O(N log F) queries, the full grid-node array copy is gone, and distances are now
exact rather than approximate.
Add nanoflann as a vcpkg dependency, wired in like Clipper2 as an imported
target.
Refs: https://github.com/OPM/ResInsight/issues/14128
The Completion Type result was registered only as a dynamic result, which
requires simulation time steps. Loading only grid geometry (e.g. a ROFF grid)
therefore made the result unavailable, since there are no time steps to compute
it for.
Register and compute a STATIC_NATIVE variant of Completion Type in addition to
the existing DYNAMIC_NATIVE one, computed as a single time-step-independent
frame. The shared per-frame computation is factored out of
computeCompletionTypeForTimeStep so both variants reuse it. The virtual
perforation transmissibilities already handle the no-restart case by clamping to
a single frame, so the static result can be computed at calc time step 0.
The legend/category predicates and the completion-type result clearing are
broadened to recognise the static variant so it renders with the same discrete
named-category legend as the dynamic one.
RigCombMultResultAccessor::cellFaceScalar called oppositeFace() with the
face passed from the picked selection. A plain cell pick leaves the face
as NO_FACE, which has no opposite and tripped CVF_ASSERT(false) in
oppositeFace, crashing the application.
Guard against a non-directional face and return 1.0, consistent with the
no-change-in-MULT-factor convention already used in nativeMultScalar.
A file-based well path whose source file is missing has a null wellPathGeometry(). Add null checks at the remaining call sites that dereferenced it without one, so operations on such a well path no longer crash:
- RimWellPathGroup: skip geometry merging for a child with no geometry (grouping runs on import and project load).
- RimWellPathFracture::computeFractureDirectionNormal: return undefined when geometry is missing.
- RivWellPathPartMgr: extend the existing well path null checks to also require geometry in the attribute, well measurement, and valve append paths.
- RimCompletionCellIntersectionCalc, RicExportLgrFeature, RicCreateMultipleWellPathLaterals, RigLasFileExporter, RiuWellPathComponentPlotItem: guard the geometry before use.
Sites that were already guarded or only reachable through guarded paths were left unchanged.
Gate the derived oil volume cell result behind the new 'oil-volume-result'
experimental feature instead of RiaApplication::enableDevelopmentFeatures().
In the ROFF file reader, drop the enableDevelopmentFeatures() gates around the
grid dimension, timing and array diagnostics and log them at debug level instead,
so the output is available without RESINSIGHT_DEVEL but stays quiet in normal
runs.
The existing FAULTDIST result always considered every fault in the main
grid. Users with many faults need to compute distance fields against a
named subset, so this adds a Fault Distance Results collection under
each view's Faults node. Each entry holds a multiselect of faults and a
name (FAULTDIST1, FAULTDIST2, ...) and publishes the result into the
Generated cell-result category.
The per-cell BVH-based distance loop was extracted from
RigFaultDistanceResultCalculator into a reusable utility that accepts
the subset of faults to include; the original all-faults entry point
delegates to the same utility and keeps the static-native FAULTDIST
behavior unchanged.
* CMake: Remove dead CODE_HEADER_FILES variable
* CMake: Remove dead COMMAND_CODE_HEADER_FILES and COMMAND_MOC_SOURCE_FILES
* CMake: Remove dead MOC_SOURCE_FILES and FORM_FILES_CPP references
* CMake: Remove dead HEADER_FILES reference
* CMake: Delete unused CustomPCH.cmake superseded by target_precompile_headers
isFaceNormalsOutwards lazily computes whether cell face normals point outward
and caches the answer in m_isFaceNormalsOutwardsComputed. setFlipAxis was
mirroring the node coordinates without resetting that cache, so any consumer
that had triggered the lazy computation before the user toggled Flip X/Y kept
the pre-flip answer. The well-path/cell intersection in
RigEclipseWellLogExtractor::calculateIntersection then inverted the
entering/leaving flag the wrong way, causing the proper-pair filter in
populateReturnArrays to discard every intermediate cell along a perforation
interval - only the start and end cells survived through the
well-starts/ends-inside-a-cell fallback.
Reset m_isFaceNormalsOutwardsComputed when the flip state actually changes.
Add unit tests covering all four combinations of Flip X / Flip Y for both the
data-level node mirroring and the well-path/cell intersection (freshly-built
grid and interactive-toggle scenarios).
Move the QMessageBox-displaying helper out of the logging utility into a
dedicated UI class. RiaLogging.h no longer pulls QMessageBox/QWidget into
the ~270 files that include it. Behavior is preserved: showError displays
the dialog when running interactively (and not under regression tests),
then forwards the text to RiaLogging::error.