You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/sphinx_docs/docs/embedded-python.rst
+115Lines changed: 115 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,3 +54,118 @@ In order to enable the PYACTION keyword:
54
54
- ``current_report_step``: This is an integer for the report step we are currently working on. Observe that the PYACTION is called for every simulator timestep, i.e. it will typically be called multiple times with the same value for the report step argument.
55
55
56
56
- ``current_summary_state``: An instance of the `SummaryState <common.html#opm.io.sim.SummaryState>`_ class — this is where the current summary results of the simulator are stored. The `SummaryState <common.html#opm.io.sim.SummaryState>`_ class has methods to get hold of well, group, and general variables.
57
+
58
+
59
+
Stateful behavior using Python classes
60
+
--------------------------------------
61
+
62
+
In the below code snippet, we use a ``WellController`` class to manage production wells by tracking their status and simulation timing.
63
+
We create one instance of the WellController and use its internal state across multiple timesteps and PYACTION calls.
64
+
65
+
.. code-block:: python
66
+
67
+
import opm_embedded
68
+
from datetime import datetime, timedelta
69
+
70
+
# Check if the setup has already been done to avoid reinitialization
71
+
if'setup_done'notinlocals():
72
+
# Target oil production rate in standard units (e.g., stb/day)
73
+
OIL_RATE_TARGET=8000
74
+
# Minimum time in days between opening new wells
75
+
MIN_DAYS_BETWEEN_OPENINGS=50
76
+
77
+
classWellController:
78
+
"""
79
+
A controller to manage the opening of production wells based on
80
+
oil rate targets and elapsed simulation time.
81
+
82
+
Attributes:
83
+
closed_wells (list[str]): List of wells yet to be opened.
84
+
last_opening_time (datetime): Simulation time of the last well opening.
85
+
Initially, this is set to the simulation start time.
86
+
"""
87
+
def__init__(self, well_names, start_time):
88
+
"""
89
+
Initialize the WellController.
90
+
91
+
Args:
92
+
well_names (list[str]): Names of wells to be controlled.
93
+
start_time (datetime): Simulation start time.
94
+
"""
95
+
self.closed_wells =list(well_names)
96
+
self.last_opening_time = start_time
97
+
98
+
defupdate(self, current_oil_rate, current_time):
99
+
"""
100
+
Evaluate the current oil production and determine whether to open
101
+
a new well based on the target rate and time since the last opening.
Use this code snippet with the example `MSW-3D-TWO-PRODUCERS <https://github.com/OPM/opm-tests/blob/master/msw/MSW-3D-TWO-PRODUCERS.DATA>`_ by saving the file as ``wellcontroller.py`` at the same location as ``MSW-3D-TWO-PRODUCERS.DATA`` and adding
164
+
165
+
.. code-block:: none
166
+
167
+
PYACTION
168
+
WELLCONTROLLER UNLIMITED /
169
+
'wellcontroller.py' /
170
+
171
+
to the ``SCHEDULE`` section of ``MSW-3D-TWO-PRODUCERS.DATA``.
0 commit comments