Simple Drilling Simulation Using Python
Before you start
Make sure your python OpenLab client and credentials are up to date (see our tutorial on how to do this).
Create a new default well configuration in the web client and name it "Offshore Inclined".
Initialize and Authenticate Account
We use the default keyring method which uses our stored credentials (see our tutorial for instructions on this or the other methods if having problems).
import openlab
session = openlab.http_client()
You should see a print out confirming you have been authenticated.
Simulation Initialization
There are several mandatory and optional initialization parameters as listed below (subject to change):
Mandatory:
- Configuration name (must be a pre-existing configuration created in the web client)
- Simulation Name (Whatever you wish to call the simulation)
- Initial Bit Depth (in meters)
Optional:
- Influx Model
- Timestep Interval (Default = 1)
We will only use the 3 mandatory parameters for now:
config_name = "Offshore Inclined"
sim_name = "Drill From Python"
initial_bit_depth = 2500
Now, we can initialize and create the simulation:
sim = session.create_simulation(config_name, sim_name, initial_bit_depth)
If you navigate to the web client, you should now see a simulation called "Drill From Python" has been created in the "Simulations" tab, and is awaiting setpoints.
In order to actually drill and advance the wellbore, we initialize with the following 4 setpoints (Make note that all numeric values must be sent in SI units) :
sim.setpoints.RPM = 0 #Hz
sim.setpoints.DesiredROP = 0.02 #m/s
sim.setpoints.TopOfStringVelocity = 0.02
sim.setpoints.FlowRateIn = 2500 / 60000 #60000 is to convert l/min to m^3/s
Advance/Run the Simulation
In order to advance and step the simulation, a setpoint must be sent to the OpenLab server with one mandatory setpoint -> timestep. We do this using a for
loop:
simulation_time = 300 # seconds
for i in range(1, simulation_time + 1):
sim.step(i)
You can watch and verify the simulation is running by clicking on the simulation in the web page.
Ending the Simulation
To end a simulation through the API, a new setpoint must be sent containing the value of ShouldComplete = True
. This is done automatically for you in the python client by calling the Simulation class's stop() method:
sim.stop()
Note: When running a simulation script (i.e. not interactively in the shell), the default OpenLab session behaviour is to automatically end all initialized simulations. To toggle this feature, you can use the end_simulation_on_exiting
flag of the openlab.Simulation
class. Or in our case:
sim.end_simulation_on_exiting = True/False