Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the network iteration code #6095

Closed
wants to merge 1 commit into from

Conversation

totto82
Copy link
Member

@totto82 totto82 commented Mar 19, 2025

This decouples the group/well constraint check and the network update. The motivation was to get better output to user and .DBG file.

@totto82
Copy link
Member Author

totto82 commented Mar 19, 2025

jenkins build this please

@totto82
Copy link
Member Author

totto82 commented Mar 19, 2025

jenkins build this failure_report please

@totto82
Copy link
Member Author

totto82 commented Mar 20, 2025

jenkins build this failure_report please

1 similar comment
@totto82
Copy link
Member Author

totto82 commented Mar 20, 2025

jenkins build this failure_report please

@totto82 totto82 requested a review from GitPaean March 20, 2025 09:34
@GitPaean
Copy link
Member

Thanks for the request. I will try to begin reviewing it tomorrow.

@GitPaean
Copy link
Member

GitPaean commented Mar 24, 2025

There are some warnings need to be fixed, but it can be done after the reviewing is done.

Copy link
Member

@GitPaean GitPaean left a comment

Choose a reason for hiding this comment

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

As far as I can see, this is a refactoring process without changing the computing algorithms, including moving code around while introducing some adjustment.

It looks general fine, and I left some comments to address.

const auto& summaryState = simulator_.vanguard().summaryState();
std::vector<Scalar> pot(this->numPhases(), 0.0);
const Group& fieldGroup = this->schedule().getGroup("FIELD", reportStepIdx);
Copy link
Member

Choose a reason for hiding this comment

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

I do not think the renaming the reportStepIdx and local_deferredLogger should be part of this PR.

And I think when possible, using reportStepIdx might be less confusing. But I acknowledge there is many usage of episodeIdx in this file.

bool updateWellControlsAndNetworkIteration(const bool mandatory_network_balance,
const int network_update_iteration,
const double dt,
bool& well_group_control_changed,
Copy link
Member

Choose a reason for hiding this comment

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

Although it is not a big thing, I do not see we need to change the interface of this function. The original form is more compact and without introducing new modified argument.

const int episodeIdx = simulator_.episodeIndex();
const auto& comm = simulator_.vanguard().grid().comm();
this->updateAndCommunicateGroupData(episodeIdx, iterationIdx, param_.nupcol_group_rate_tolerance_, deferred_logger);
bool more_inner_network_update = updateNetwork(mandatory_network_balance, network_update_iteration, deferred_logger);
Copy link
Member

Choose a reason for hiding this comment

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

const before bool.

const int iterationIdx = simulator_.model().newtonMethod().numIterations();
const int episodeIdx = simulator_.episodeIndex();
const auto& comm = simulator_.vanguard().grid().comm();
this->updateAndCommunicateGroupData(episodeIdx, iterationIdx, param_.nupcol_group_rate_tolerance_, deferred_logger);
Copy link
Member

Choose a reason for hiding this comment

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

In the original code, this communication is done after

       if (!this->wellsActive() && !network.active()) {
            return {false, false};
        }

Do you think it is potentially introducing some extra communications?

const std::string network_str = more_inner_network_update? "": "Network did not converge.";
const std::string gaslift_str = alq_updated? "": "Gaslift optimization oscillates.";
const std::string wg_str = well_group_control_changed? "": "Group/well controls oscillates.";
bool output_to_info = !this->shouldBalanceNetwork(episodeIdx, iterationIdx + 1) && more_inner_network_update;
Copy link
Member

Choose a reason for hiding this comment

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

const before bool.

return {more_network_update, well_group_control_changed};
// but after certain number of the iterations, we terminate
const std::size_t max_iteration = param_.network_max_outer_iterations_;
if (network_update_iteration + 1 == max_iteration) {
Copy link
Member

@GitPaean GitPaean Mar 25, 2025

Choose a reason for hiding this comment

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

I like the original way that this type of process is in the general iteration workflow. Basically we reach the maximum allowed number of iterations, then we do some process. It is part of the processing of the iteration process.

The code in the current way is putting this process inside the iteration function itself, it is harder to follow.

If you want to keep the function updateWellControlsAndNetwork tider, you can wrap this process in a separate function.

Copy link
Member Author

@totto82 totto82 Mar 27, 2025

Choose a reason for hiding this comment

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

The motivation for this refactoring is to allow for more fine-grained checks for convergence of the outer network iterations as well as more informative output. See PR #6100 which part of the same issue is addressed. That is also why I would like to move the iteration workflow inside the function.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the response. I see you want to output the information regarding more_inner_network_update and alq_updated. That should be okay if you want to get them from the function updateWellControlsAndNetworkIteration() for outputting purpose.

In my idea is that

        while (do_network_update) {
             if (network_update_iteration > maximum_iteration) {
                   output message
                   break;
             }
            do_network_update = updateWellControlsAndNetworkIteration();
            ++network_update_iteration;
        }

In its current form from this PR, inside the function updateWellControlsAndNetworkIteration(network_update_iteration), we update things (do the iteration first), then oh, ++network_update_iteration > maximum_iteration, we should not do the future iterations anymore, let us output some messages, then return false. I do think deciding no more iteration within the **Iteration() function itself is less clear, and the **Iteration() function get unnecessary length and complication.

@totto82
Copy link
Member Author

totto82 commented Mar 27, 2025

jenkins build this please

fmt::format("The maximum of {} outer network iterations is reached. Stop iteration. Caused by:"
"{}"
"{}"
"{}"
Copy link
Member

@GitPaean GitPaean Mar 28, 2025

Choose a reason for hiding this comment

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

I think you can use concatenations here, Caused by:{}{}{}{}"

// only output to terminal if we are at the last newton iterations where we try to balance the network.
// the network is not yet balanced
const std::string network_str = more_inner_network_update? "": "Network did not converge.";
const std::string gaslift_str = alq_updated? "": "Gaslift optimization oscillates.";
Copy link
Member

Choose a reason for hiding this comment

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

For those strings, You might want a space at the beginning, so the causes are not output without a space between them.

@totto82
Copy link
Member Author

totto82 commented Apr 2, 2025

I will close this now and instead focus on getting #6100 in.

@totto82 totto82 closed this Apr 2, 2025
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.

2 participants