-
Notifications
You must be signed in to change notification settings - Fork 122
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
Conversation
jenkins build this please |
jenkins build this failure_report please |
bedbcba
to
8c38541
Compare
jenkins build this failure_report please |
1 similar comment
jenkins build this failure_report please |
Thanks for the request. I will try to begin reviewing it tomorrow. |
There are some warnings need to be fixed, but it can be done after the reviewing is done. |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8c38541
to
1a4ba55
Compare
jenkins build this please |
fmt::format("The maximum of {} outer network iterations is reached. Stop iteration. Caused by:" | ||
"{}" | ||
"{}" | ||
"{}" |
There was a problem hiding this comment.
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."; |
There was a problem hiding this comment.
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.
I will close this now and instead focus on getting #6100 in. |
This decouples the group/well constraint check and the network update. The motivation was to get better output to user and .DBG file.