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

Support instantaneous flow rates in extended network (WEFAC and GEFAC item 3) #4094

Merged
merged 3 commits into from
Feb 14, 2025

Conversation

vkip
Copy link
Member

@vkip vkip commented Jun 5, 2024

No restart support here - will come in a separate PR.

@vkip
Copy link
Member Author

vkip commented Jun 5, 2024

jenkins build this opm-simulators=5410 please

@vkip vkip requested review from bska and GitPaean June 5, 2024 07:43
@vkip
Copy link
Member Author

vkip commented Jun 5, 2024

jenkins build this opm-simulators=5410 please

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.

It is not a lot of code, but I do feel it can be tricky. I left some comments for your consideration.

@@ -205,6 +212,36 @@ void ExtNetwork::update_node(Node node)
this->m_nodes.insert_or_assign(name, std::move(node) );
}

bool ExtNetwork::needs_instantaneous_rates(const Opm::Schedule& schedule, const int report_step) const {
Copy link
Member

Choose a reason for hiding this comment

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

Based on the usage of this function in OPM/opm-simulators#5410, it basically indicates whether we are handling network flow with extended network with "NO" in the item 3 in WEFAC or GEFAC.

Or more simply, we can use true for extended network and use false for standard network and group calculation. If we can introduce a flag to mark whether the network is extended network, we do not need this function anymore. And use_efficiency_in_ext_network will take care whether we will use instantaneous rate.

What do you think? I can understand this part wrong. Please let me know.

Copy link
Member Author

Choose a reason for hiding this comment

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

This function can certainly be skipped, but the intention is to save some computation in opm-simulators in the quite common situation with default value (YES) for all instances of WEFAC/GEFAC with wells/groups in the network.

One complication I see is action handling (i.e., if item3 is updated through actions), will need to ensure the check is performed again in this case. Can have a quick look, or we just drop this for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this now.

@vkip vkip force-pushed the extnet_efficiency branch from 1dfbddd to cae2f0c Compare June 12, 2024 12:36
@GitPaean
Copy link
Member

jenkins build this opm-simulators=5410 please

@vkip vkip marked this pull request as draft June 28, 2024 09:33
@vkip vkip force-pushed the extnet_efficiency branch from a5c4c31 to e1f9c8d Compare January 17, 2025 13:32
@vkip
Copy link
Member Author

vkip commented Jan 17, 2025

jenkins build this opm-simulators=5410 please

@vkip vkip marked this pull request as ready for review January 17, 2025 15:27
@vkip vkip force-pushed the extnet_efficiency branch from e1f9c8d to 9102c16 Compare January 20, 2025 12:25
@vkip
Copy link
Member Author

vkip commented Jan 20, 2025

jenkins build this opm-simulators=5410 please

1 similar comment
@GitPaean
Copy link
Member

jenkins build this opm-simulators=5410 please

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.

It looks generally good to me. I only have some minor comments for you to address.

bool add_gas_lift_gas() const;
const std::optional<std::string>& target_group() const;

void terminal_pressure(double pressure);
void add_gas_lift_gas(bool add_gas);
void as_choke(const std::string& target_group);
void set_efficiency(const double& efficiency);
Copy link
Member

Choose a reason for hiding this comment

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

the reference & here is not necessary.

children.push(branch.downtree_node());
}
}
assert(children.empty());
Copy link
Member

Choose a reason for hiding this comment

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

with while (!children.empty()), the assertion here is not necessary.

std::stack<std::string> children;
children.push(root.get().name());
while (!children.empty()) {
const auto node = children.top();
Copy link
Member

Choose a reason for hiding this comment

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

nittpicking, const auto& node can be used here.

And leaf_nodes.emplace(node) can be used in the code below instead of insert().

double Well::getEfficiencyFactor() const
{
double Well::getEfficiencyFactor(bool network) const {
if (network && (!this->use_efficiency_in_network)) {
Copy link
Member

Choose a reason for hiding this comment

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

(!this->use_efficiency_in_network), the bracket is not necessary with a ! operator when coming to improving the readability.

return this->efficiency_factor;
}

double Well::getSolventFraction() const
{
bool Well::useEfficiencyInNetwork() const {
Copy link
Member

Choose a reason for hiding this comment

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

this function does not look like used.

@@ -517,7 +518,7 @@ class Well {
bool updateWellGuideRate(bool available, double guide_rate, GuideRateTarget guide_phase, double scale_factor);
bool updateWellGuideRate(double guide_rate);
bool updateAvailableForGroupControl(bool available);
bool updateEfficiencyFactor(double efficiency_factor);
bool updateEfficiencyFactor(double efficiency_factor, bool se_efficiency_in_network = true);
Copy link
Member

Choose a reason for hiding this comment

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

The default value for bool se_efficiency_in_network = true is not very useful, since the only usage of the function is for parsing keyword WEFAC, the default behavoir is specified through the definition of the keyword WEFAC.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, updated a test instead.

@@ -235,5 +239,29 @@ std::vector<std::string> ExtNetwork::node_names() const
{
return this->insert_indexed_node_names;
}

std::set<std::string> ExtNetwork::leaf_nodes() const
Copy link
Member

Choose a reason for hiding this comment

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

The function looks correct to me. From the usage in the opm-simulators, it looks like it will be called many times. Ideally, it will be nice if we can save the results somehow to avoid repeating the process.

This can be done in a following up PR if it turns out to be costly and needs to be optimized.

@@ -2038,6 +2052,7 @@ bool Well::cmp_structure(const Well& other) const
&& (this->udq_undefined == other.udq_undefined)
&& (this->getPreferredPhase() == other.getPreferredPhase()) // wellType()
&& (this->getEfficiencyFactor() == other.getEfficiencyFactor())
Copy link
Member

Choose a reason for hiding this comment

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

It does not matter for the current usage since the argument is false by default, but it might be better to compare the value
this->efficiency_factor == other.efficiency_factor now, since the function getEfficiencyFactor() uses use_efficiency_in_network and it is a little more complex function now.

Copy link
Member

Choose a reason for hiding this comment

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

It does not matter for the current usage since the argument is false by default, but it might be better to compare the value this->efficiency_factor == other.efficiency_factor now, since the function getEfficiencyFactor() uses use_efficiency_in_network and it is a little more complex function now.

Arguably, two wells aren't equal if their use_efficiency_in_network differ so I think it actually makes sense to continue to use getEfficiencyFactor() for this criterion.

Copy link
Member

Choose a reason for hiding this comment

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

Sure.

In the current form of the function double getEfficiencyFactor(bool network), it is fine and it is equivalent to compare with the efficiency_factor. But I do feel that it is safer (and slightly faster) to compare with the member variable directly.

In a more general setting, for example, the function double getEfficiencyFactor(bool network) evolves somehow it might not reflect the value of efficiency_factor, then a bug can be introduced. Or we might need to compare both getEfficiencyFactor(true) and getEfficiencyFactor(false).

As said, I think it does not make much difference for the current code, but I do think compare with the member variable itself is safer generally.

@vkip vkip force-pushed the extnet_efficiency branch from 9102c16 to 20734b9 Compare February 14, 2025 09:48
@vkip
Copy link
Member Author

vkip commented Feb 14, 2025

It looks generally good to me. I only have some minor comments for you to address.

Thank you for the review. I have now tried to update accordingly.

@vkip
Copy link
Member Author

vkip commented Feb 14, 2025

jenkins build this opm-simulators=5410 please

@GitPaean
Copy link
Member

Thanks for the update. It looks good to me and I am getting it in now.

@GitPaean GitPaean merged commit 63c3159 into OPM:master Feb 14, 2025
1 check passed
@vkip vkip deleted the extnet_efficiency branch February 17, 2025 08:57
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.

3 participants