Skip to content

Infer Action Dimensions From Restart File Information - #5308

Merged
bska merged 2 commits into
OPM:masterfrom
bska:infer-rst-actdims-from-file
Aug 25, 2026
Merged

Infer Action Dimensions From Restart File Information#5308
bska merged 2 commits into
OPM:masterfrom
bska:infer-rst-actdims-from-file

Conversation

@bska

@bska bska commented Aug 23, 2026

Copy link
Copy Markdown
Member

PRs #2651 and #2663 added a Runspec argument to the restart loader as a means of inferring the maximum number of actions, the number of conditions per action and other essential pieces of information needed to correctly interpret the *ACT and *ACN restart file arrays. While this practice has served us well in the interim, it's strictly speaking somewhat fragile. A restarted simulation run is allowed to increase these dimensions compared to the base run and in that case we'd be basing our offsets on out-of-bounds values.

This commit switches to loading the base run's action dimensions directly from the pertinent INTEHEAD array items which, in turn, enables removing the Runspec argument to RstState::load(). We still need the run's number of tabulated PVT regions in order to correctly load the oil vaporisation properties, but I want to push the scattering to the client side at some point in the future. For now we add a new overload of RstState::load() function that takes the number of PVT regions as an optional<int>–defaulting to nullopt which we treat as a single PVT region–and make the overload taking the Runspec argument call the other overload. The Runspec overload will be marked "deprecated" once all downstream users have been converted to the new overload.

The one compromise that we have to add here is a floating-point based derivation of each actions "start" time. We would previously infer this from the Runspec argument's START value, but this is no longer available. Instead we use a calculation based on the RstHeader's sim_time() and the SimTim element of DOUBHEAD. Other derivations may be possible, but this appears sufficiently accurate for now.

@bska bska added the manual:bugfix This PR is a bug fix and should be noted in the manual label Aug 23, 2026
@bska

bska commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

@bska

bska commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes restart loading more robust by deriving ACTIONX-related dimensions (and some other restart metadata) directly from restart header arrays instead of relying on Runspec, and it introduces a new RstState::load() overload that only needs an optional PVT-table count.

Changes:

  • Update restart header/state loading to infer ACTIONX dimensions and start-time information from INTEHEAD/DOUBHEAD, enabling removal of the Runspec dependency in the primary RstState::load() path.
  • Extend INTEHEAD/LOGIHEAD vector item definitions and header parsing to include ACTIONX sizing fields and a temperature flag.
  • Adjust restart-related tests and minor related refactors/cleanup (including initialization and formatting tweaks).

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_rst.cpp Update RstHeader construction to no longer require Runspec.
tests/test_InteHEAD.cpp Update RstHeader construction in tests to match new API.
tests/test_AggregateWellData.cpp Update RstHeader construction in tests to match new API.
opm/output/eclipse/VectorItems/logihead.hpp Add explicit LOGIHEAD indices for temperature flags.
opm/output/eclipse/VectorItems/intehead.hpp Add explicit INTEHEAD indices for ACTIONX sizing fields.
opm/output/eclipse/LogiHEAD.cpp Use named LOGIHEAD indices instead of numeric literals for TEMP flags.
opm/output/eclipse/InteHEAD.hpp Remove variousUDQ_ACTIONXParam() from public interface.
opm/output/eclipse/InteHEAD.cpp Fold ACTIONX-related INTEHEAD sizing values into actionParam() and simplify MAXSPRLINE calculation.
opm/output/eclipse/CreateInteHead.cpp Stop calling removed variousUDQ_ACTIONXParam().
opm/io/eclipse/rst/well.cpp Switch tracer/temperature handling to be restart-header driven and modernize extraction logic.
opm/io/eclipse/rst/state.hpp Add new RstState::load() overload and remove Runspec dependency from action restoration helpers.
opm/io/eclipse/rst/state.cpp Implement new load() overload and refactor ACTIONX restore logic to use header-derived sizing.
opm/io/eclipse/rst/header.hpp Remove stored Runspec from RstHeader; add ACTIONX sizing + inferred start-time fields.
opm/io/eclipse/rst/header.cpp Populate new header fields, including inferred start times from DOUBHEAD.
opm/input/eclipse/Schedule/OilVaporizationProperties.hpp Minor formatting and default-initialization cleanup for members.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread opm/io/eclipse/rst/state.cpp
Comment thread opm/io/eclipse/rst/header.cpp Outdated
Comment thread opm/io/eclipse/rst/well.cpp Outdated
Comment thread opm/output/eclipse/VectorItems/intehead.hpp Outdated
@bska
bska force-pushed the infer-rst-actdims-from-file branch from 340db33 to 90246d9 Compare August 24, 2026 12:07
@bska
bska requested a lite review from Copilot August 24, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Comment thread opm/io/eclipse/rst/well.cpp
Comment thread opm/io/eclipse/rst/header.cpp Outdated
@bska
bska force-pushed the infer-rst-actdims-from-file branch from 90246d9 to 15a7ede Compare August 24, 2026 15:10
@bska
bska requested a lite review from Copilot August 24, 2026 15:12
@bska

bska commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

opm/io/eclipse/rst/state.cpp:784

  • Action/condition array dimensions are now taken from restart header fields (action_*_size, max_action_conditions) and immediately used to compute subspan() sizes and indexed in RstAction::Condition::valid() / RstAction construction. If any of these header values are 0/negative or inconsistent with the expected condition sizes, this can lead to UB/out-of-bounds reads before any exception is thrown (e.g. Condition::valid() indexes iacn[...] without a size check). Add sanity checks (>= expected minimums and consistent with VectorItems::{IACN,SACN,ZACN}::ConditionSize) and fail fast with a clear error if the restart header is malformed/unsupported.
    const auto iacn_cond_size = static_cast<std::size_t>(this->header.action_iacn_size);
    const auto sacn_cond_size = static_cast<std::size_t>(this->header.action_sacn_size);
    const auto zacn_cond_size = static_cast<std::size_t>(this->header.action_zacn_size);

    const auto iacn_action_size = this->header.max_action_conditions * iacn_cond_size;
    const auto sacn_action_size = this->header.max_action_conditions * sacn_cond_size;
    const auto zacn_action_size = this->header.max_action_conditions * zacn_cond_size;

Comment thread opm/io/eclipse/rst/state.cpp Outdated
Comment thread opm/io/eclipse/rst/well.cpp
@bska
bska force-pushed the infer-rst-actdims-from-file branch from 1239089 to 9819373 Compare August 25, 2026 08:23
@bska
bska requested a lite review from Copilot August 25, 2026 08:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@bska

bska commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

Very good. In that case, I'll mark this PR as "ready for review" by a human reviewer.

@bska
bska marked this pull request as ready for review August 25, 2026 08:37
@bska

bska commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

@akva2 akva2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread opm/io/eclipse/rst/header.cpp Outdated
Comment thread opm/io/eclipse/rst/state.cpp Outdated
PRs OPM#2651 and OPM#2663 added a "Runspec" argument to the restart loader
as a means of inferring the maximum number of actions, the number of
conditions per action and other essential pieces of information
needed to correctly interpret the *ACT and *ACN restart file arrays.
While this practice has served us well in the interim, it's strictly
speaking somewhat fragile.  A restarted simulation run is allowed to
increase these dimensions compared to the base run and in that case
we'd be basing our offsets on out-of-bounds values.

This commit switches to loading the base run's action dimensions
directly from the pertinent INTEHEAD array items which, in turn,
enables removing the Runspec argument to RstState::load().  We still
need the run's number of tabulated PVT regions in order to correctly
load the oil vaporisation properties, but I want to push the
scattering to the client side at some point in the future.  For now
we add a new overload of RstState::load() function that takes the
number of PVT regions as an optional<int>--defaulting to nullopt
which we treat as a single PVT region--and make the overload taking
the Runspec argument call the other overload.  The Runspec overload
will be marked "deprecated" once all downstream users have been
converted to the new overload.

The one compromise that we have to add here is a floating-point
based derivation of each actions "start" time.  We would previously
infer this from the Runspec argument's START value, but this is no
longer available.  Instead we use a calculation based on the
RstHeader's "sim_time()" and the SimTim element of DOUBHEAD.  Other
derivations may be possible, but this appears sufficiently accurate
for now.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@bska
bska force-pushed the infer-rst-actdims-from-file branch from 9819373 to 42b8012 Compare August 25, 2026 09:15
@bska

bska commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

jenkins build this please

@bska

bska commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

PR approved and build check is green. I'll merge into master.

@bska
bska merged commit 64ae0e4 into OPM:master Aug 25, 2026
2 checks passed
@bska
bska deleted the infer-rst-actdims-from-file branch August 25, 2026 09:47
bska added a commit to OPM/opm-simulators that referenced this pull request Aug 26, 2026
PR OPM/opm-common#5308 added an overload of RstState::load() that
does not require a "Runspec" argument.  While we do have such an
object here the restart file loading mechanism should not depend on
the dimensions set in the restarted run.  Restarted runs may
increase such dimensions, e.g., the number of actions or conditions
per action, so it's better to not provide those values in any way.

We still pass the run's number of PVT tables as an argument to
load().  This will be subject to future removal once load() supports
this mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:bugfix This PR is a bug fix and should be noted in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants