Skip to content

Refactor DeferredLogger as a mutable pointer into GroupStateHelper#6705

Merged
atgeirr merged 26 commits intoOPM:masterfrom
hakonhagland:deflog
Jan 16, 2026
Merged

Refactor DeferredLogger as a mutable pointer into GroupStateHelper#6705
atgeirr merged 26 commits intoOPM:masterfrom
hakonhagland:deflog

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

Refactor DeferredLogger usage in the GroupStateHelper class by integrating it as a mutable member of GroupStateHelper with RAII-based scoped setup. This simplifies method signatures throughout the codebase by removing the need to pass DeferredLogger& to every method that needs logging.

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

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

jenkins build this please

1 similar comment
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 2, 2026

i'd be careful about doing this change. the passing of loggers is, while annoying, a feature. there are some spots where we need multiple loggers in flight to handle recursive stuff for wells et al, and there is no guarantee all these cases are exercised in the test suite.

@hakonhagland
Copy link
Copy Markdown
Contributor Author

there are some spots where we need multiple loggers in flight to handle recursive stuff for wells

@akva2 Can you show an example?

@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 5, 2026

I'm sorry, I can't really pinpoint it, and it's a bit hard to look for. The fact that you have already changed this stuff in previous PRs makes it even harder to track. I just remember there has been PRs and there has been code where a def_logger and a local_def_logger was used to fix such issues. If you are confident that it's okay, it's probably okay, it was just a heads up that you really need to make sure you don't end up reintroducing these issues.

const Parallel::Communication& comm() const { return this->comm_; }

/// @brief Get the deferred logger
/// @throws assertion failure if no logger has been set via setupScopedDeferredLogger()
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.

Not strictly true, I suggest making it true: instead of assert() make it a regular if and throw.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct, I have updated the PR with a commit to address this. I also added two commits to address the recursive creation of temporary loggers that @akva2 made me aware of and he has approved those. Does this look ok to you?

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

i'd be careful about doing this change. the passing of loggers is, while annoying, a feature. there are some spots where we need multiple loggers in flight to handle recursive stuff for wells et al, and there is no guarantee all these cases are exercised in the test suite.

@akva2 Indeed, I found a place at https://github.com/OPM/opm-simulators/blob/master/opm/simulators/wells/BlackoilWellModel_impl.hpp#L1832. I will have to think about this, so I will put the PR in draft state to avoid merging for now.

@hakonhagland hakonhagland marked this pull request as draft January 6, 2026 05:33
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

there are some spots where we need multiple loggers in flight to handle recursive stuff for wells

@akva2 See the last two commits: This should work now. You can now push as many deferred loggers as you want. We could consider cleaning up method calls where both groupStateHelper and deferredLogger are passed such that we only pass groupStateHelper (no need to pass both) in a follow-up PR, see e.g. https://github.com/OPM/opm-simulators/blob/master/opm/simulators/wells/BlackoilWellModel_impl.hpp#L1832

@hakonhagland hakonhagland marked this pull request as ready for review January 6, 2026 13:47
@hakonhagland hakonhagland requested review from akva2 and atgeirr January 6, 2026 13:47
Copy link
Copy Markdown
Member

@akva2 akva2 left a comment

Choose a reason for hiding this comment

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

This is kinda hard to review in terms of regressions and/or change behavior, but the principles seems fine to me.

Comment thread opm/simulators/wells/GroupStateHelper.hpp Outdated
Comment thread opm/simulators/wells/GroupStateHelper.hpp
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

Introduce a RAII-based mechanism for binding a DeferredLogger pointer to
GroupStateHelper, enabling cleaner method signatures by avoiding repeated
parameter passing.

Changes:
- Add ScopedDeferredLoggerGuard nested class with move semantics
- Add setupScopedDeferredLogger() factory method and deferredLogger() accessor
- Add mutable DeferredLogger* member (logical constness for logging)
- GuideRateHandler now delegates to GroupStateHelper for logger access
- Remove setLogger() calls from BlackoilWellModel_impl.hpp

This is a first step toward simplifying the DeferredLogger parameter
threading throughout the blackoil well model module.
Use GroupStateHelper's stored deferred logger instead of passing it
as a parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
…rod()

Use GroupStateHelper's stored deferred logger instead of passing it
as a parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
Use GroupStateHelper's stored deferred logger instead of passing it
as a parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
…et()

Use GroupStateHelper's stored deferred logger instead of passing it as a
parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
…ctor()

Use GroupStateHelper's stored deferred logger instead of passing it as a
parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
…ucer()

Use GroupStateHelper's stored deferred logger instead of passing it as a
parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
…ells()

Use GroupStateHelper's stored deferred logger instead of passing it as a
parameter. This simplifies the method signature and call sites.

Part of the DeferredLogger refactoring series for GroupStateHelper.
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

@akva2 The jenkins build reports an error that seems unrelated to this PR: CUDA ERROR (code = 35, CUDA driver version is insufficient for CUDA runtime version). Any ideas?

@akva2
Copy link
Copy Markdown
Member

akva2 commented Jan 10, 2026 via email

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

We need the move constructor in ScopedLoggerGuard since pushLogger()
returns it by value.
Clarify why ScopedLoggerGuard needs to store a pointer to
GroupStateHelper (and cannot store a reference)
Reduce scope of logger guard to log messages before the calls
to OpmLog::debug() on rank 0 at the end of getWellConvergence().
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

…eter

Methods that receive GroupStateHelper can obtain the DeferredLogger via
groupStateHelper.deferredLogger(), making the separate parameter redundant.
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

When looping over well container some ranks may never enter the
loop, so logger guard needs to be created outside the loop
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

Don't create extra deferred loggers that do not match
the logger in groupStateHelper
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@hakonhagland
Copy link
Copy Markdown
Contributor Author

@akva2 and @atgeirr I have updated the PR with commits after private discussion with @atgeirr. Please have a look again and let me know if anything can be improved.

@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

Use groupStateHelper logger instead of creating an explicit logger.
@hakonhagland
Copy link
Copy Markdown
Contributor Author

jenkins build this please

@atgeirr
Copy link
Copy Markdown
Member

atgeirr commented Jan 16, 2026

I think this is good now, merging!

@atgeirr atgeirr merged commit cdc61ce into OPM:master Jan 16, 2026
2 checks passed
@hakonhagland hakonhagland deleted the deflog branch March 16, 2026 09:03
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