Skip to content

Move reservoir coupling methods to a separate class#7066

Draft
hakonhagland wants to merge 3 commits into
OPM:masterfrom
hakonhagland:refact_rescoup_bow
Draft

Move reservoir coupling methods to a separate class#7066
hakonhagland wants to merge 3 commits into
OPM:masterfrom
hakonhagland:refact_rescoup_bow

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

Builds on #7065

Extracts the reservoir-coupling flow methods from BlackoilWellModel<TypeTag> into a new templated helper class BlackoilWellModelRescoup<TypeTag>, modelled as has-a on BlackoilWellModel. Motivation: BlackoilWellModel_impl.hpp had ~160 LOC of rescoup-specific code interleaved with the rest of the file, and upcoming rescoup-network work will roughly double that footprint, this gives those additions a clean target file. No behavior change.

Moved to the wrapper

  • receiveGroupConstraintsFromMaster()
  • receiveSlaveGroupData()
  • rescoupSyncSummaryData()
  • sendMasterGroupConstraintsToSlaves()
  • sendSlaveGroupDataToMaster()
  • setupRescoupScopedLogger(): renamed to setupScopedLogger since the class name already carries the Rescoup prefix.

Stayed on BlackoilWellModel

The rescoup mode-query API stays on BlackoilWellModel: isReservoirCouplingMaster/Slave, isReservoirCouplingMasterGroup, reservoirCouplingMaster/Slave, setReservoirCouplingMaster/Slave, and the rescoup() proxy accessor. These are read-only mode queries used widely by call sites that should not have to bounce through the wrapper to ask "are we in master mode?".

Other changes

  • Adds a public guideRateHandler() accessor on BlackoilWellModel so the wrapper can construct RescoupConstraintsCalculator and RescoupReceiveGroupConstraints without friend access.
  • Adds the two new headers to CMakeLists_files.cmake (PUBLIC_HEADER_FILES, alongside the existing BlackoilWellModelNetwork.hpp entries).

Files

File Change
opm/simulators/wells/BlackoilWellModelRescoup.hpp new (110 lines) — class declaration with doxygen for each method
opm/simulators/wells/BlackoilWellModelRescoup_impl.hpp new (165 lines) — method definitions
opm/simulators/wells/BlackoilWellModel.hpp +25 / −19 (include, guideRateHandler() accessor, rescoupHelper_ member; removed 6 flow-method declarations)
opm/simulators/wells/BlackoilWellModel_impl.hpp +13 / −150 (delegated inline #ifdef blocks and rescoupSyncSummaryData call to wrapper; deleted moved method bodies)
CMakeLists_files.cmake +2 (new headers)

Follow-up

This refactor unblocks the planned reservoir-coupling network PR series: those additions can land directly into BlackoilWellModelRescoup instead of growing BlackoilWellModel_impl.hpp further.

Store a reference to BlackoilModelParameters in the generic well
model base class so that the base no longer needs to receive
individual parameter fields as method arguments.

Drop the now-redundant arguments from three call paths:

  - tol_nupcol from updateAndCommunicateGroupData (7 call sites)
  - max_number_of_group_switch from checkGroupHigherConstraints
  - handle_ms_well from initFromRestartFile and prepareDeserialize

The base class reads the corresponding fields directly from the
stored param_ reference. The reference is passed from the derived
BlackoilWellModel constructor; its target (the derived class's
const param_ member) is fully constructed by the time any base
class method dereferences it.
Store a reference to the simulator's NewtonIterationContext in the
generic well model base class, and expose it through a new
iterationContext() accessor on the base.

The address of the iteration context is stable for the lifetime of
the simulator (it lives as a member of the problem object), and it
is mutated in-place during NLDD local solves, so a stored reference
correctly observes both global and local-solve state.

Drop the now-redundant iterCtx parameter from three method
signatures:

  - BlackoilWellModelGeneric::updateAndCommunicateGroupData
  - BlackoilWellModelNetworkGeneric::shouldBalance
  - BlackoilWellModelNetworkGeneric::willBalanceOnNextIteration

The implementations read iter_ctx_ directly (or, for the network
class, via well_model_.iterationContext()). On the caller side,
several local `simulator_.problem().iterationContext()` lookups
become unused after the parameter drops and are removed.
Extract the reservoir-coupling methods from BlackoilWellModel<TypeTag>
into a new templated helper class BlackoilWellModelRescoup<TypeTag>,
modelled as has-a on BlackoilWellModel.

Moved methods: receiveGroupConstraintsFromMaster,
receiveSlaveGroupData, rescoupSyncSummaryData,
sendMasterGroupConstraintsToSlaves, sendSlaveGroupDataToMaster,
plus setupRescoupScopedLogger (renamed to setupScopedLogger).

The rescoup mode-query API (isReservoirCouplingMaster/Slave,
reservoirCouplingMaster/Slave, setReservoirCouplingMaster/Slave)
stays on BlackoilWellModel — read-only callers should not have to
bounce through the wrapper.

Also adds a public guideRateHandler() accessor so the wrapper can
construct the underlying Rescoup* helpers without friend access.

No behaviour change.  BlackoilWellModel_impl.hpp had ~160 LOC of
rescoup-specific code that upcoming rescoup-network work would
roughly double; this gives those additions a clean target file.
@hakonhagland hakonhagland added the manual:irrelevant This PR is a minor fix and should not appear in the manual label May 19, 2026
@hakonhagland hakonhagland marked this pull request as draft May 19, 2026 14:52
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

Putting this in draft mode until #7065 has been merged

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

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant