Skip to content

Builder + immutable SparseTable-backed UniformXTabulated2DFunction - #7477

Draft
havahol wants to merge 1 commit into
OPM:masterfrom
havahol:uniformXTabulated2DFunction-builder
Draft

havahol wants to merge 1 commit into
OPM:masterfrom
havahol:uniformXTabulated2DFunction-builder

Conversation

@havahol

@havahol havahol commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR splits UniformXTabulated2DFunction into an append-only UniformXTabulated2DFunctionBuilder and an immutable, SparseTable-backed evaluation type, and migrates every call site over to the new split. It targets CPU-work only, and is behaviour preserving.

This PR builds on the four PRs that moved SparseTable/IteratorRange from opm-grid into opm-common (see [1-4]), and is prep work for GPU-porting UniformXTabulated2DFunction and LiveOilPvt in a later PR, the same way Tabulated1DFunction/BrineCo2Pvt were ported. With this PR, porting UniformXTabulated2DFunction to GPU becomes easier as SparseTable is already GPU-ready, in contrast to the std::vector<std::vector<SamplePoint>> data structure originally used.

This PR should be reviewed together with OPM/opm-common#5411

Changes

opm-common

  • New opm/material/common/UniformXTabulated2DFunctionBuilder.hpp: carries the old append logic (appendXPos/appendSamplePoint) plus the plain accessors needed by the four PVT classes' initEnd()-style derivation code (xAt/yAt/valueAt/numX/numY). build() && is rvalue-qualified (move-only) and flattens the appended columns into a SparseTable<SamplePoint>, then returns the immutable type via a private constructor.
  • Rewrote opm/material/common/UniformXTabulated2DFunction.hpp: samples_ is now a SparseTable<SamplePoint> (default std::vector storage, not GPU-templated yet) instead of std::vector<std::vector<SamplePoint>>. Dropped appendXPos/appendSamplePoint and the old (xPos, yPos, samples) constructor (no external callers); kept the default constructor for .resize(n, Policy) call sites and the operator==/accessors.
  • opm/common/utility/IteratorRange.hpp: added front()/back() to iterator_range and mutable_iterator_range — needed for SparseTable-backed row access (yMin/yMax/applies), mirrors the "behaves like a vector of vectors" contract SparseTable already documents.
  • Migrated LiveOilPvt, WetGasPvt, DryHumidGasPvt, WetHumidGasPvt: each gets Builder-typed private members for tables that are appended across multiple methods (initFromState, extendPvt*Table_, and the standalone setSaturated* setters used by the manual-PVT-setup path in examples/problems/reservoirproblem.hh), finalized via .build() at the top of initEnd(). Tables built entirely within one function scope (DryHumidGasPvt/WetHumidGasPvt's RWGSALT-derived saturatedWaterVaporizationSaltFactorTable_) use a local Builder instead of a persistent member. WetHumidGasPvt repeats the pattern twice (RvSat and RvwSat pairs).
  • tests/material/test_2dtables.cpp: table-construction helpers build via UniformXTabulated2DFunctionBuilder and return std::move(tab).build().

opm-simulators

  • opm/simulators/flow/FlowGenericProblem_impl.hpp: rock-compaction tables (rockCompPoroMultWc_/rockCompTransMultWc_) built via a local Builder per region, then .build().
  • opm/models/blackoil/blackoilextboparams.cpp: all 10 EXTBO tables (X_, Y_, PBUB_RS_, PBUB_RV_, VISCO_, VISCG_, BO_, BG_, RS_, RV_) built via local Builders, finalized per-region right after that region's construction loop (verified no cross-region reads of an already-finalized table).

Verify

  • ctest -R 2dtables (opm-common) — passes, 14 cases.
  • eclblackoilpvt (opm-common) — passes, 8 cases. Exercises LiveOilPvt/WetGasPvt/ DryHumidGasPvt/WetHumidGasPvt via the ECL-deck initFromState/extendPvt*Table_/ initEnd path (PVTO/PVTG/PVTGW keywords).
  • opmcommon and opmsimulators libraries build clean (no new warnings attributable to these changes).
  • reservoir_blackoil_ecfv/reservoir_blackoil_vcfv (opm-simulators) — pass, including the reference-result checksum comparison. These exercise examples/problems/reservoirproblem.hh, the only external caller of LiveOilPvt's standalone setSaturatedOilFormationVolumeFactor/ setSaturatedOilViscosity append path (as opposed to the ECL-deck initFromState path), end to end.
  • RockTableTests (opm-common) — passes.
  • No serialization/restart or operator== dependency on the touched PVT classes was found in opm-simulators, so this has no restart-format implications.

Stacked dependencies

…ctionBuilder

Follows the opm-common split of UniformXTabulated2DFunction into an append-only
Builder and an immutable SparseTable-backed evaluation type. Rock-compaction tables in FlowGenericProblem_impl.hpp
and the 10 EXTBO tables in blackoilextboparams.cpp now build via a local
UniformXTabulated2DFunctionBuilder and finalize with .build(). CPU-only,
behavior-preserving.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@havahol
havahol force-pushed the uniformXTabulated2DFunction-builder branch from 59a4469 to 9792c64 Compare October 2, 2026 11:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant