|
| 1 | +################################################################################# |
| 2 | + Driving a reservoir simulation with Pygeos |
| 3 | +################################################################################# |
| 4 | + |
| 5 | + |
| 6 | +**Context** |
| 7 | + |
| 8 | +In this example, we will use pygeos to control a CompositionalMultiphaseFVM solver throughout a GEOS simulation. |
| 9 | +The goal is to reproduce the same results as if the simulation was launched directly through the XML file. |
| 10 | + |
| 11 | +For the rest of this example, every part highlighting Python snippets will represent what is used to control pygeos and |
| 12 | +how it is linked to the XML file. |
| 13 | + |
| 14 | +The example python script for this documentation is the following: |
| 15 | + |
| 16 | +.. code-block:: console |
| 17 | +
|
| 18 | + pygeos-tools/examples/solvers/reservoir_modeling.py |
| 19 | +
|
| 20 | +
|
| 21 | +------------------------------------------------------------------ |
| 22 | + XML file and initialization of Solver object |
| 23 | +------------------------------------------------------------------ |
| 24 | + |
| 25 | + |
| 26 | +The xml input file for the test case is located at: |
| 27 | + |
| 28 | +.. code-block:: console |
| 29 | +
|
| 30 | + /path/to/your/GEOS/src/inputFiles/compositionalMultiphaseFlow/2ph_cap_1d_ihu.xml |
| 31 | +
|
| 32 | +
|
| 33 | +After setting up the MPI communication and parsing all the args, we can set the XML object that has parsed our XML file. |
| 34 | + |
| 35 | +.. code-block:: python |
| 36 | +
|
| 37 | + xmlfile = args.xml |
| 38 | + xml = XML( xmlfile ) |
| 39 | +
|
| 40 | +
|
| 41 | +**Solver** |
| 42 | + |
| 43 | +The simulation is performed using the GEOS general-purpose multiphase flow solver. |
| 44 | +The solver can be found in the ``Solvers`` block. |
| 45 | + |
| 46 | +.. code-block:: xml |
| 47 | +
|
| 48 | + <Solvers gravityVector="{0.38268, 0., -0.92388}"> |
| 49 | +
|
| 50 | + <CompositionalMultiphaseFVM |
| 51 | + name="compflow" |
| 52 | + logLevel="1" |
| 53 | + discretization="fluidTPFA" |
| 54 | + targetRegions="{ Region1 }" |
| 55 | + temperature="297.15"> |
| 56 | +
|
| 57 | + <NonlinearSolverParameters |
| 58 | + newtonTol="5e-4" |
| 59 | + lineSearchAction="None" |
| 60 | + newtonMaxIter="15"/> |
| 61 | +
|
| 62 | + <LinearSolverParameters |
| 63 | + directParallel="0"/> |
| 64 | +
|
| 65 | + </CompositionalMultiphaseFVM> |
| 66 | +
|
| 67 | + </Solvers> |
| 68 | +
|
| 69 | +
|
| 70 | +The important thing to note here is the solver type ``CompositionalMultiphaseFVM``. |
| 71 | +Because we are dealing with a flow solver, which is not coupled, we can use the ``ReservoirSolver`` class to pilot the simulation. |
| 72 | + |
| 73 | +.. code-block:: python |
| 74 | +
|
| 75 | + solver = ReservoirSolver( "CompositionalMultiphaseFVM" ) |
| 76 | + solver.initialize( rank=rank, xml=xml ) |
| 77 | + solver.applyInitialConditions() |
| 78 | +
|
| 79 | +
|
| 80 | +**Events** |
| 81 | + |
| 82 | +To trigger the timestepping of the solver and the different outputs to perform, the "Events" block is the following: |
| 83 | + |
| 84 | +.. code-block:: xml |
| 85 | +
|
| 86 | + <Events |
| 87 | + maxTime="1.0368e8"> |
| 88 | +
|
| 89 | + <PeriodicEvent |
| 90 | + name="outputs" |
| 91 | + timeFrequency="1.728e6" |
| 92 | + target="/Outputs/vtkOutput"/> |
| 93 | +
|
| 94 | + <PeriodicEvent |
| 95 | + name="solverApplications1" |
| 96 | + forceDt="1.728e6" |
| 97 | + target="/Solvers/compflow"/> |
| 98 | +
|
| 99 | + <PeriodicEvent |
| 100 | + name="restarts" |
| 101 | + timeFrequency="3e7" |
| 102 | + targetExactTimestep="0" |
| 103 | + target="/Outputs/restartOutput"/> |
| 104 | +
|
| 105 | + </Events> |
| 106 | +
|
| 107 | +
|
| 108 | +The first attribute to use is ``maxTime`` which will be the limit for the simulation. |
| 109 | +The ``solverApplications1`` event targets the ``CompositionalMultiphaseFVM`` solver that we are using. |
| 110 | +This block contains a ``forceDt`` attribute that will be used later to choose as the timestep of the simulation. |
| 111 | + |
| 112 | +.. code-block:: python |
| 113 | +
|
| 114 | + solver.setDtFromTimeVariable( "forceDt" ) # solver.dt = 1.728e6 |
| 115 | + solver.setMaxTime( solver.getTimeVariables()[ "maxTime" ] ) # solver.maxTime = 1.0368e8 |
| 116 | +
|
| 117 | +
|
| 118 | +The "outputs" event triggers the output of the vtk files. The attribute "timeFrequency" has the same value as "forceDt" |
| 119 | +so we can use the same timestep for the solver and the outputs. |
| 120 | +To start, we will set the time to 0.0 and trigger one output of the vtk files. |
| 121 | + |
| 122 | +.. code-block:: python |
| 123 | +
|
| 124 | + time = 0.0 |
| 125 | + solver.outputVtk( time ) |
| 126 | +
|
| 127 | +
|
| 128 | +------------------------------------------------------------------ |
| 129 | + Iterations process and simulation end |
| 130 | +------------------------------------------------------------------ |
| 131 | + |
| 132 | +The iterative process organizes the execution of the solver at each timestep while not exceeding the maxTime of the simulation. |
| 133 | +Once done, the simulation is ended by calling the ``cleanup`` method. |
| 134 | + |
| 135 | +.. code-block:: python |
| 136 | +
|
| 137 | + while time < solver.maxTime: |
| 138 | + solver.execute( time ) |
| 139 | + solver.outputVtk( time ) |
| 140 | + time += solver.dt |
| 141 | + solver.cleanup( time ) |
| 142 | +
|
| 143 | +
|
| 144 | +More complex timestepping strategies can be implemented by modifying the timestep duration and the outputs. |
| 145 | + |
| 146 | + |
| 147 | +------------------------------------------------------------------ |
| 148 | + How to run that script |
| 149 | +------------------------------------------------------------------ |
| 150 | + |
| 151 | +Using the same python used to build your GEOS installation with, run this command: |
| 152 | + |
| 153 | +.. code-block:: console |
| 154 | +
|
| 155 | + python pygeos-tools/examples/solvers/reservoir_modeling.py |
| 156 | + --xml /path/to/your/GEOS/src/inputFiles/compositionalMultiphaseFlow/2ph_cap_1d_ihu.xml |
| 157 | +
|
| 158 | +
|
| 159 | +------------------------------------------------------------------ |
| 160 | + To go further |
| 161 | +------------------------------------------------------------------ |
| 162 | + |
| 163 | + |
| 164 | +**Feedback on this example** |
| 165 | + |
| 166 | +For any feedback on this example, please submit a `GitHub issue on the project's GitHub page <https://github.com/GEOS-DEV/geosPythonPackages/issues>`_. |
0 commit comments