Skip to content

Reservoir Coupling: Fix sync of group data to only occur on first substep#6704

Merged
blattms merged 2 commits into
OPM:masterfrom
hakonhagland:rc_fix_sync
Jan 19, 2026
Merged

Reservoir Coupling: Fix sync of group data to only occur on first substep#6704
blattms merged 2 commits into
OPM:masterfrom
hakonhagland:rc_fix_sync

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

The master-slave group data synchronization code in BlackoilWellModel::beginTimeStep() was executing on every internal substep within a larger "sync" timestep (as assigned by the master process so as not to overshoot any slave
report dates). This is incorrect because:

  1. The SubStepIteration loop typically splits a sync timestep into multiple smaller internal substeps for numerical stability. And/or a timestep might be chopped in case of convergence problems.
  2. After the first internal substep, master and slaves are at different simulation times and cannot exchange data correctly
  3. Repeated sync attempts would cause deadlocks or incorrect data

This fix adds an isFirstSubstepOfSyncTimestep() flag to track whether we are at the start of a coordinated "sync" timestep. The flag is:

  • Set to true before each SubStepIteration::run() call
  • Cleared to false after the first runSubStep_() returns.

@hakonhagland hakonhagland added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Dec 26, 2025
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this serial please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this serial please

1 similar comment
@blattms
Copy link
Copy Markdown
Member

blattms commented Jan 8, 2026

jenkins build this serial please

Copy link
Copy Markdown
Member

@blattms blattms left a comment

Choose a reason for hiding this comment

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

Approved.
Just running jenkins again as the data is gone already.

The master-slave synchronization code in beginTimeStep() was executing
on every internal substep within a "sync" timestep. This is incorrect
because:

1. The SubStepIteration loop typically splits a sync timestep into
   multiple smaller internal substeps for numerical stability
2. After the first internal substep, master and slaves are at different
   simulation times and cannot exchange data correctly
3. Repeated sync attempts would cause deadlocks or incorrect data

This fix adds an isFirstSubstepOfSyncTimestep flag to track whether we
are at the start of a coordinated "sync" timestep. The flag is:
- Set to true before each SubStepIteration::run() call
- Cleared to false after the first runSubStep_() returns
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

1 similar comment
@blattms
Copy link
Copy Markdown
Member

blattms commented Jan 19, 2026

jenkins build this please

/// @return Reference to the potentials data for the specified group
const Potentials& getSlaveGroupPotentials(const std::string &master_group_name) const;

/// @brief Check if this is the first substep of within a "sync" timestep.
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.

-of

std::size_t slave_idx, const std::vector<ProductionGroupTarget>& production_targets
) const;

/// @brief Set whether this is the first substep of within a "sync" timestep.
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.

-of

/// Injection data for each slave group (map key: master group name)
std::map<std::string, std::vector<SlaveGroupInjectionData>> slave_group_injection_data_;

/// Flag to track if this is the first substep of within a "sync" timestep.
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.

-of

/// @return MPI communicator handle for communication with the master process
MPI_Comm getSlaveMasterComm() const { return this->slave_.getMasterComm(); }

/// @brief Check if this is the first substep of within a "sync" timestep.
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.

-of

/// @note Must be called before the master attempts to receive injection data
void sendInjectionDataToMaster(const std::vector<SlaveGroupInjectionData> &injection_data) const;

/// @brief Set whether this is the first substep of within a "sync" timestep.
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.

-of


/// Reference to the parent ReservoirCouplingSlave object
ReservoirCouplingSlave<Scalar> &slave_;
// Flag to track if this is the first substep of within a "sync" timestep.
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.

-of

current_time + current_step_length, step_end_time
);
// Mark this as the first substep of the "sync" timestep. This flag controls
// whether master-slave data exchange should occur in beginTimeStep() in the well model..
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.

-.

current_time + timestep, step_end_time
);
// Mark this as the first substep of the "sync" timestep. This flag controls
// whether master-slave data exchange should occur in beginTimeStep() in the well model..
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.

-.

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

@akva2 Thanks for the review, I have added a commit to address the comments.

@blattms blattms merged commit 1bc2fd8 into OPM:master Jan 19, 2026
2 checks passed
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.

3 participants