diff --git a/CHANGELOG.md b/CHANGELOG.md index f79f229a3..3dec56bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] ### Added +- [#157](https://github.com/equinor/flownet/pull/157) Adds a new 'time-weighted average open perforation location' perforation strategy called `time_avg_open_location`. - [#115](https://github.com/equinor/flownet/pull/150) Adds this changelog. - [#146](https://github.com/equinor/flownet/pull/146) Added about page to documentation with logo of industry and research institute partners. - [#138](https://github.com/equinor/flownet/pull/138) Print message to terminal when the schedule is being generated instead of utter silence. diff --git a/src/flownet/data/from_flow.py b/src/flownet/data/from_flow.py index 1ade88e7c..38312d587 100644 --- a/src/flownet/data/from_flow.py +++ b/src/flownet/data/from_flow.py @@ -1,6 +1,7 @@ import warnings from pathlib import Path from typing import Union, List +import datetime import numpy as np import pandas as pd @@ -42,6 +43,7 @@ def __init__( self._perforation_handling_strategy: str = perforation_handling_strategy + # pylint: disable=too-many-branches def _coordinates(self) -> pd.DataFrame: """ Function to extract well coordinates from an Flow simulation. @@ -69,6 +71,46 @@ def multi_xyz_append(append_obj_list): elif self._perforation_handling_strategy == "multiple": xyz = [global_conns] coord_append = multi_xyz_append + elif self._perforation_handling_strategy == "time_avg_open_location": + connection_open_time = {} + + for i, conn_status in enumerate(self._wells[well_name]): + time = datetime.datetime.strptime( + str(conn_status.simulationTime()), "%Y-%m-%d %H:%M:%S" + ) + if i == 0: + prev_time = time + + for connection in conn_status.globalConnections(): + if connection.ijk() not in connection_open_time: + connection_open_time[connection.ijk()] = 0.0 + elif connection.isOpen(): + connection_open_time[connection.ijk()] += ( + time - prev_time + ).total_seconds() + else: + connection_open_time[connection.ijk()] += 0.0 + + prev_time = time + + xyz_values = np.zeros((1, 3), dtype=np.float64) + total_open_time = sum(connection_open_time.values()) + + if total_open_time > 0: + for connection, open_time in connection_open_time.items(): + xyz_values += np.multiply( + np.array(self._grid.get_xyz(ijk=connection)), + open_time / total_open_time, + ) + else: + for connection, open_time in connection_open_time.items(): + xyz_values += np.divide( + np.array(self._grid.get_xyz(ijk=connection)), + len(connection_open_time.items()), + ) + + xyz = tuple(*xyz_values) + else: raise Exception( f"perforation strategy {self._perforation_handling_strategy} unknown" diff --git a/tests/test_one_dimensional.py b/tests/test_one_dimensional.py index 4fdb9b70c..0df8fc23b 100644 --- a/tests/test_one_dimensional.py +++ b/tests/test_one_dimensional.py @@ -4,8 +4,7 @@ def test_one_dimensional(tmp_path: pathlib.Path) -> None: - """Single one dimensional flow Model example - """ + """Single one dimensional flow Model example""" n_grid_cells = 10 model_cross_section_area = 40 # m^2