Skip to content

Commit ed24281

Browse files
author
Lisa Julia Nebel
committed
Improve documentation for the 'start flow from python' a bit (according to Atgeirrs wishes from last 5.7.2024)
1 parent 614782e commit ed24281

4 files changed

Lines changed: 76 additions & 16 deletions

File tree

python/sphinx_docs/docs/embedded.rst renamed to python/sphinx_docs/docs/embedded-python.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
OPM Embedded Python Documentation
2-
=================================
1+
Run Python embedded in OPM Flow
2+
===============================
33

4-
The PYACTION keyword is a flow specific keyword which allows for executing embedded Python
4+
The PYACTION keyword is a Flow specific keyword which allows for executing embedded Python
55
code in the SCHEDULE section. The embedded Python code will then be executed at the end of each successful timestep.
66

77
The PYACTION keyword is inspired
@@ -15,7 +15,8 @@ conditions can be evaluated and changes applied.
1515

1616
In order to enable the PYACTION keyword:
1717

18-
1. OPM flow must be compiled with the cmake switches -DOPM ENABLE EMBEDDED PYTHON=ON and -DOPM ENABLE PYTHON=ON, the default is to build with these switches set to OFF.
18+
1. OPM Flow must be compiled with the cmake switches -DOPM ENABLE EMBEDDED PYTHON=ON and -DOPM ENABLE PYTHON=ON, the default is to build with these switches set to OFF.
19+
You can also change these settings in the CMakeLists.txt of opm-common.
1920

2021
2. The keyword PYACTION must be added to the SCHEDULE section:
2122

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Run OPM Flow from Python
2+
========================
3+
4+
To run OPM from Python, you need to:
5+
6+
1. Compile Flow with python support:
7+
8+
- Add the cmake flags -DOPM_ENABLE_PYTHON=ON and -DOPM_INSTALL_PYTHON=ON.
9+
- Optionally add prefix -DCMAKE_INSTALL_PREFIX=/opt/opm to install outside the standard directories.
10+
- Optionally specify python binary -DPython3_EXECUTABLE=/home/user/miniconda3/envs/rkt/bin/python3 if you don't want to use the system python, e.g. use a python from pyenv or from a conda environment.
11+
12+
Sample compilation on linux:
13+
14+
.. code-block:: bash
15+
16+
#! /bin/bash
17+
18+
flags="-DPython3_EXECUTABLE=/home/hakon/miniconda3/envs/rkt/bin/python3 -DOPM_ENABLE_PYTHON=ON -DOPM_INSTALL_PYTHON=ON -DCMAKE_INSTALL_PREFIX=/opt/opm"
19+
for repo in opm-common opm-grid opm-models opm-simulators
20+
do
21+
cd "$repo"
22+
mkdir -p build
23+
cd build
24+
cmake $flags ..
25+
make -j8
26+
sudo make install
27+
cd ..
28+
cd ..
29+
done
30+
31+
2. Now you should be able to use the module from a Python script.
32+
33+
If you installed in a non-standard directory by specifying -DCMAKE_INSTALL_PREFIX you may need to set the PYTHONPATH environment variable before running your Python script, for example:
34+
35+
.. code-block:: bash
36+
37+
PYTHONPATH=/opt/opm/lib/python3.11/site-packages python3 spe1case1.py
38+
39+
Here, spe1case1.py could be:
40+
41+
.. code-block:: python
42+
43+
import os
44+
from opm.simulators import BlackOilSimulator
45+
from opm.io.parser import Parser
46+
from opm.io.ecl_state import EclipseState
47+
from opm.io.schedule import Schedule
48+
from opm.io.summary import SummaryConfig
49+
50+
os.chdir("SPE1CASE1")
51+
deck = Parser().parse('SPE1CASE1.DATA')
52+
state = EclipseState(deck)
53+
schedule = Schedule( deck, state )
54+
summary_config = SummaryConfig(deck, state, schedule)
55+
56+
sim = BlackOilSimulator(deck, state, schedule, summary_config)
57+
sim.step_init()
58+
sim.step()
59+
poro = sim.get_porosity()
60+
poro = poro *.95
61+
sim.set_porosity(poro)
62+
sim.step()
63+
sim.step_cleanup()

python/sphinx_docs/docs/index.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ Welcome to the Python documentation for OPM Flow!
22
=================================================
33

44
There are two Python APIs within OPM Flow:
5-
- running flow from Python code using the Python bindings
6-
- running a Python script embedded in a simulation
75

6+
- running Flow from Python code using the Python bindings (see :doc:`flow-in-python`)
7+
- running a Python script embedded in a simulation (see :doc:`embedded-python`)
8+
9+
10+
Contents
11+
========
812
.. toctree::
913
:maxdepth: 1
10-
:caption: Contents:
1114

12-
introduction
15+
flow-in-python
16+
embedded-python
1317
common
1418
simulators
15-
embedded
1619

1720
Indices and tables
1821
==================

python/sphinx_docs/docs/introduction.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)