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

Update PYACTION keyword #459

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions parts/chapters/subsections/12.3/PYACTION.fodt
Original file line number Diff line number Diff line change
Expand Up @@ -4534,10 +4534,10 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
<text:p text:style-name="P19313">UNLIMITED: <text:s/>If this option is selected then the action is run at the end of every time step.</text:p>
</text:list-item>
<text:list-item>
<text:p text:style-name="P19321">FIRST_TRUE: <text:s/>This option forces the action to be run at the end of every time step until the script returns a value of True. Note that this option is only supported for back compatibility with the deprecated run() function style Python scripts.</text:p>
<text:p text:style-name="P19321">FIRST_TRUE: <text:s/>This option forces the action to be run at the end of every time step until the script returns a value of True.</text:p>
</text:list-item>
</text:list>
<text:p text:style-name="P4982">Note that the FIRST_TRUE option is only supported for back compatibility when using run() function style Python scripts.</text:p>
<text:p text:style-name="P4982">Note that the FIRST_TRUE option is only supported for back compatibility when using the deprecated run() function style Python scripts.</text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1862.D4" office:value-type="string">
<text:p text:style-name="P9085">SINGLE</text:p>
Expand Down Expand Up @@ -4601,11 +4601,11 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
</table:table>
<text:p text:style-name="P14805">Table <text:sequence text:ref-name="refTable602" text:name="Table" text:formula="ooow:Table+1" style:num-format="1">12.60</text:sequence>: PYACTION Keyword Description</text:p>
<text:p text:style-name="P12176"/>
<text:p text:style-name="P12176">The <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword is a result of combining two programming languages, the interactive Python interpreter and OPM Flow’s source code language C++. When combing two languages one extends and embeds one into the other. When extending Python with C++ the functionality implemented in C++ is made available to Python applications, when embedding Python in C++ one can call Python functions from within C++. The <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword is based on embedding a Python interpreter in the C++ OPM Flow simulator, but the Python code actually run as part of the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword is based on wrapping C++ objects in Python, that is extending Python.</text:p>
<text:p text:style-name="P12176">The <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword is a result of combining two programming languages, the interactive Python interpreter and OPM Flow’s source code language C++. When combing two languages one extends and embeds one into the other.<text:s/>When extending Python with C++ the functionality implemented in C++ is made available to Python applications, when embedding Python in C++ one can call Python functions from within C++. The <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword is based on embedding a Python interpreter in the C++ OPM Flow simulator, such that Python code is run from within the simulator.</text:p>
<text:p text:style-name="P12176">Note that to use the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword OPM Flow must be built with embedded python enabled in opm-common/CMakeLists.txt. <text:s/></text:p>
<text:p text:style-name="P16914">option(OPM_ENABLE_EMBEDDED_PYTHON &quot;Enable embedded python?&quot; ON) </text:p>
<text:p text:style-name="P14405"/>
<text:p text:style-name="P12181">In order to fully benefit from the power of the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword one should familiarize oneself with the Python wrapper classes for the various OPM Flow C++ classes. These classes are essential to share the <text:s/>simulator state with the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> script. <text:s/>That is, the function provides the interface between the two programming languages. </text:p>
<text:p text:style-name="P12181">In order to fully benefit from the power of the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keyword one should familiarize oneself with the Python wrapper classes for the various OPM Flow C++ classes. These classes are essential to share the <text:s/>simulator state with the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> script.<text:s/>That is, the function provides the interface between the two programming languages. </text:p>
<text:p text:style-name="_40_TextBody"><text:soft-page-break/><text:span text:style-name="T4328">To learn more about these classes you can use the pydoc utility, </text:span>for example,<text:span text:style-name="T4328"> to learn more about the SummaryState class, </text:span>in a Linux terminal one would<text:span text:style-name="T4328"> issue the </text:span>following bash <text:span text:style-name="T4328">command:</text:span></text:p>
<text:p text:style-name="P16914">bash% pydoc opm.io.sim.SummaryState </text:p>
<text:p text:style-name="P14405"/>
Expand Down Expand Up @@ -4696,7 +4696,8 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
<text:p text:style-name="_40_Code"><text:span text:style-name="Source_20_Text"/></text:p>
<text:p text:style-name="_40_Code"><text:span text:style-name="Source_20_Text">schedule.insert_keywords(kw)</text:span></text:p>
<text:p text:style-name="_40_Code"><text:span text:style-name="Source_20_Text"/></text:p>
<text:p text:style-name="Table_20_Contents">Which can be used to insert various keywords where kw is a string defining the keyword and associated records. This has been tested with the <text:a xlink:href="#__RefHeading___Toc146746_4203985108">GCONPROD</text:a>, <text:a xlink:href="#__RefHeading___Toc99847_2023071304">MULTX</text:a>/Y/Z, <text:a xlink:href="#__RefHeading___Toc323446_1841740821">NEXTSTEP</text:a>, <text:a xlink:href="#__RefHeading___Toc146754_4203985108">WCONPROD</text:a>, <text:a xlink:href="#__RefHeading___Toc48856_327352552">WEFAC</text:a> and <text:a xlink:href="#__RefHeading___Toc268461_1366622701">WELOPEN</text:a> keywords. </text:p>
<text:p text:style-name="Table_20_Contents">Which can be used to insert various keywords where kw is a string defining the keyword and associated records. This has been tested with the <text:a xlink:href="#__RefHeading___Toc99877_2023071304">BOX</text:a>, <text:a xlink:href="#__RefHeading___Toc316604_3519154785">COMPSEGS</text:a>, <text:a xlink:href="#__RefHeading___Toc99883_2023071304">ENDBOX</text:a>, <text:a xlink:href="#__RefHeading___Toc627737_1466963378">EXIT</text:a>, <text:a xlink:href="#__RefHeading___Toc71850_2267116897">FIELD</text:a>, <text:a xlink:href="#__RefHeading___Toc134874_2055188184">GCONINJE</text:a>, <text:a xlink:href="#__RefHeading___Toc146746_4203985108">GCONPROD</text:a>, <text:a xlink:href="#__RefHeading___Toc188037_2026549522">GCONSUMP</text:a>, <text:a xlink:href="#__RefHeading___Toc118321_1596574740">GRUPTREE</text:a>, <text:a xlink:href="#__RefHeading___Toc70639_2267116897">METRIC</text:a>, <text:a xlink:href="#__RefHeading___Toc99847_2023071304">MULTX</text:a>/Y/Z, <text:a xlink:href="#__RefHeading___Toc323446_1841740821">NEXTSTEP</text:a>, <text:a xlink:href="#__RefHeading___Toc146750_4203985108">WCONINJE</text:a>, <text:a xlink:href="#__RefHeading___Toc146754_4203985108">WCONPROD</text:a>, <text:a xlink:href="#__RefHeading___Toc134884_2055188184">WECON</text:a>, <text:a xlink:href="#__RefHeading___Toc48856_327352552">WEFAC</text:a>, <text:a xlink:href="#__RefHeading___Toc268461_1366622701">WELOPEN</text:a>, <text:a xlink:href="#__RefHeading___Toc97661_3261743917">WELSEGS</text:a>, <text:a xlink:href="#__RefHeading___Toc268463_1366622701">WELSPECS</text:a>, <text:a xlink:href="#__RefHeading___Toc134888_2055188184">WELTARG</text:a>, <text:a xlink:href="#__RefHeading___Toc121641_2412586160">WGRUPCON</text:a>, <text:a xlink:href="#__RefHeading___Toc1091865_4263943340">WSEGVALV</text:a> and <text:a xlink:href="#__RefHeading___Toc121925_2556401936">WTEST</text:a> keywords. </text:p>
<text:p text:style-name="Table_20_Contents">The parsing strictness for the <text:a xlink:href="#__RefHeading___Toc152227_2992482751">ACTIONX</text:a> and <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> keywords can be set using the --action-parsing-strictness command line option. If the default option --action-parsing-strictness="normal" has been set then OPM Flow will only apply keywords that have been tested, whereas if the option --action-parsing-strictness="low" has been set then OPM Flow will attempt to apply all keywords (however the simulation results may be incorrect).</text:p>
<text:p text:style-name="Table_20_Contents">Adding additional call points to the opm.io.sched.Schedule instance in order to update the Schedule object in more ways is an obvious candidate for improving the <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> functionality.</text:p>
</table:table-cell>
</table:table-row>
Expand Down Expand Up @@ -4735,7 +4736,7 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
<text:p text:style-name="P14805">Table <text:sequence text:ref-name="refTable603" text:name="Table" text:formula="ooow:Table+1" style:num-format="1">12.61</text:sequence>: <text:a xlink:href="#__RefHeading___Toc393199_4211536922">PYACTION</text:a> Module Script Definition</text:p>
<text:p text:style-name="P14805"/>
<text:p text:style-name="P12186">See also the <text:a xlink:href="#__RefHeading___Toc403208_1898124664">PYINPUT</text:a> and <text:a xlink:href="#__RefHeading___Toc403206_1898124664">PYEND</text:a> keywords in the <text:a xlink:href="#__RefHeading___Toc38674_784232322">GRID</text:a><text:note text:id="ftn313" text:note-class="footnote"><text:note-citation>313</text:note-citation><text:note-body>
<text:p text:style-name="P16670">Note <text:a xlink:href="#__RefHeading___Toc403208_1898124664">PYINPUT</text:a> and <text:a xlink:href="#__RefHeading___Toc403206_1898124664">PYEND</text:a> can be used in the <text:a xlink:href="#__RefHeading___Toc38674_784232322">GRID</text:a>, <text:a xlink:href="#__RefHeading___Toc40641_784232322">EDIT</text:a>, <text:a xlink:href="#__RefHeading___Toc39329_784232322">PROPS</text:a>, <text:a xlink:href="#__RefHeading___Toc43947_784232322">SOLUTION</text:a>, <text:a xlink:href="#__RefHeading___Toc43949_784232322">SUMMARY</text:a> and <text:a xlink:href="#__RefHeading___Toc43945_784232322">SCHEDULE</text:a> sections, but is described in the <text:a xlink:href="#__RefHeading___Toc38674_784232322">GRID</text:a> section.</text:p></text:note-body></text:note> section which are also part of OPM Flow’s Python scripting facility, that process standard Python commands that can be used to manipulate and define the simulators input parameters during processing of the input deck. <text:s/>The main purpose of the facility is to script the construction of the various keywords. </text:p>
<text:p text:style-name="P16670">Note the <text:a xlink:href="#__RefHeading___Toc403208_1898124664">PYINPUT</text:a> and <text:a xlink:href="#__RefHeading___Toc403206_1898124664">PYEND</text:a> keywords can be used in the <text:a xlink:href="#__RefHeading___Toc38674_784232322">GRID</text:a>, <text:a xlink:href="#__RefHeading___Toc40641_784232322">EDIT</text:a>, <text:a xlink:href="#__RefHeading___Toc39329_784232322">PROPS</text:a>, <text:a xlink:href="#__RefHeading___Toc43947_784232322">SOLUTION</text:a>, <text:a xlink:href="#__RefHeading___Toc43949_784232322">SUMMARY</text:a> and <text:a xlink:href="#__RefHeading___Toc43945_784232322">SCHEDULE</text:a> sections, but are described in the <text:a xlink:href="#__RefHeading___Toc38674_784232322">GRID</text:a> section.</text:p></text:note-body></text:note> section which are also part of OPM Flow’s Python scripting facility, that process standard Python commands that can be used to manipulate and define the simulators input parameters during processing of the input deck. <text:s/>The main purpose of the facility is to script the construction of the various keywords. </text:p>
<text:h text:style-name="P18345" text:outline-level="4" text:is-list-header="true"><text:bookmark-start text:name="__RefHeading___Toc716663_3964674244"/>Examples<text:bookmark-end text:name="__RefHeading___Toc716663_3964674244"/></text:h>
<text:p text:style-name="_40_TextBody">The first example checks if well OP01 has a water cut greater than 0.8 and if so then the well is shut in. In the input deck we would have:</text:p>
<text:p text:style-name="_40_Example">-- </text:p>
Expand Down Expand Up @@ -4767,7 +4768,7 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
<text:p text:style-name="_40_Code"><text:s text:c="4"/>executed = true</text:p>
<text:p text:style-name="_40_Code"/>
<text:p text:style-name="_40_TextBody">Note how the &apos;executed&apos; variable is used to ensure that the action is only executed once the first time the water cut is greater than 0.8.</text:p>
<text:p text:style-name="_40_TextBody">The next example is based on the first example from the <text:a xlink:href="#__RefHeading___Toc152227_2992482751">ACTIONX</text:a> keyword (<text:a xlink:type="simple" xlink:href="#12.3.6.ACTIONX – Define ACTION Conditions and Command Processing|outline" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link"><text:bookmark-ref text:reference-format="text" text:ref-name="__RefHeading___Toc152227_2992482751">ACTIONX – Define Action Conditions and Command Processing</text:bookmark-ref></text:a>). The Python script first checks if the field’s water production is greater than 30,000 stb/d, and if not returns control back to the simulator. If the field water production is greater than 30, 000 stb/d then the script uses a Python variable count to keep track of the number of times the script has been executed, and then sorts the wells from high water cut to low, via the wct_list variable, and then shuts in the worst offending well. If a well is shut-in the count variable is increased by one and control is passed back to the simulator. The script is executed as maximum of ten times.</text:p>
<text:p text:style-name="_40_TextBody">The next example is based on the first example from the <text:a xlink:href="#__RefHeading___Toc152227_2992482751">ACTIONX</text:a> keyword (<text:a xlink:type="simple" xlink:href="#12.3.6.ACTIONX – Define ACTION Conditions and Command Processing|outline" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link"><text:bookmark-ref text:reference-format="text" text:ref-name="__RefHeading___Toc152227_2992482751">ACTIONX – Define Action Conditions and Command Processing</text:bookmark-ref></text:a>). The Python script first checks if the field’s water production is greater than 30,000 stb/d, and if not returns control back to the simulator. If the field water production is greater than 30,000 stb/d then the script uses a Python variable count to keep track of the number of times the script has been executed, and then sorts the wells from high water cut to low, via the wct_list variable, and then shuts in the worst offending well. If a well is shut-in the count variable is increased by one and control is passed back to the simulator. The script is executed as maximum of ten times.</text:p>
<text:p text:style-name="_40_Example">-- </text:p>
<text:p text:style-name="_40_Example">-- <text:s text:c="6"/>START OF PYACTION SECTION</text:p>
<text:p text:style-name="_40_Example">-- </text:p>
Expand All @@ -4791,7 +4792,7 @@ Updated with AFR/TSA Rev-D comments and new keywords.</dc:description><meta:init
<text:p text:style-name="_40_Code"><text:s text:c="4"/>execution_counter = 0</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="4"/>setup_done = True</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="0"/></text:p>
<text:p text:style-name="_40_Code"><text:s text:c="0"/>if (execution_counter &lt; 10 and summary_state[&quot;FWPR&quot;] &gt;= 3000):</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="0"/>if (execution_counter &lt; 10 and summary_state[&quot;FWPR&quot;] &gt;= 30000):</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="4"/>#</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="4"/># Get Sorted Well List</text:p>
<text:p text:style-name="_40_Code"><text:s text:c="4"/>#</text:p>
Expand Down