Example Code

The Pipesim Python Toolkit includes example scripts that cover all of its available methods, classes and properties. The scripts demonstrate the features and usage, which is indicated in the name of the script. They are located in the Pipesim installation folder, under Development Tools/Python Toolkit.

Along with the example scripts there are also several Case Studies. These are designed to demonstration potential use cases for the Pipesim Python Toolkit with more in depth code and and scripting. The case studies are located in the Pipesim installation folder, under Case Studies/Python Toolkit.

Before running the scripts or case studies, it is necessary to copy the Case Studies and Development Tools folders from the Program Files location into your Documents home folder. This is because the typical security settings for Windows limit read and write access in Program Files.

Example Scripts

The following example scripts are included with the Pipesim Python Toolkit.

ScriptDescription
add_and_delete.pyAdd and delete model components.
add_well.pyCreate a new model and add a well.
advanced_get_set_gaslift_tuning_factor.pyUpdate gas lift tuning factor.
advanced_get_set_tubing_head_temperature.pyUpdate tubing head temperature in advanced well.
advanced_get_set_wellstream.pyUpdate wellstream in advanced well.
advanced_well_concentric.pyCreate a new model with advanced well in concentric tubing configuration.
advanced_well_dual_string.pyCreate a new model with advanced well in dual string configuration.
advanced_well_set_type.pySet well type to advanced and change tubing configuration.
advanced_well_single_string.pyCreate a new model with advanced well in single string configuration.
advanced_well_tail_pipe.pyAdd tail pipe to advanced well.
check_model_components.pyOpen the Oil Network case study and review the model components.
connect_disconnect.pyConnect and disconnect model component connections.
connections.pyDisplay model connections.
convert.pyConvert a junction into a well or source.
copy_well.pyCopy (duplicate) a well.
create_black_oil_fluid.pyCreate a black oil fluid.
create_compositional_fluid.pyCreate a compositional fluid and set emulsion viscosity properties.
create_GIS_network.pyCreate a network model with GIS coordinates.
create_network.pyCreate a network model.
create_well_from_template.pyCreate a well from a template.
describe.pyDisplay engineering units for parameters.
elevation.pyGet the elevations of GIS locations.
elevations.pyGet the elevations of a list of GIS locations.
excel_macros_functions.xlsxExcel workbook with macros, functions and logging.
export_parameters.pyExport model component parameters.
find.pyFind model components.
generate_engine_files.pyGenerate engine files for network and PT profile studies.
get_OneSubsea_multiphase_booster_results.pyGet simulation results for OneSubsea multiphase booster.
get_completion_ipr_points.pyGet a list of pressure, rate points for completion ipr model.
get_esp_curve_results.pyGet ESP pump curve results.
get_set_annulus_flow.pyUpdate of annulus flow in flowline.
get_set_batch_update.pyPerform a batch update on component parameters.
get_set_black_oil.pyUpdate black oil fluid parameters.
get_set_coating_table.pyUpdate pipe coating parameters.
get_set_completion_test_points.pyUpdate completion test point parameters.
get_set_composite_ipr.pyUpdate composite IPR.
get_set_corrosion_model.pyUpdate corrosion model values.
get_set_distributed_completion_properties.pyUpdate distributed completion values.
get_set_erosion_corrosion_risk_limits.pyUpdate erosion corrosion risk limits values.
get_set_esp_motor_and_cable.pyUpdate esp motor and cable values.
get_set_flow_control_valve_generic.pyUpdate flow control valve values in generic mode.
get_set_flow_control_valve_specific.pyUpdate flow control valve values in specific mode.
get_set_flow_correlations.pyUpdate global and local flow correlations.
get_set_fluid_composition.pyUpdate fluid composition.
get_set_geometry.pyUpdate flowline profile.
get_set_geothermal_profile.pyUpdate geothermal profile.
get_set_local_corrosion_model.pyUpdate global/local corrosion model settings.
get_set_mfl_fluid.pyUpdate MFL fluid properties and emulsion viscosity settings.
get_set_nodal_sim_inlet_conditions.pyUpdate inlet conditions for a nodal analysis simulation.
get_set_nodal_sim_sensitivites.pyUpdate sensitivities for a nodal analysis simulation.
get_set_oil_well_ipr.pyUpdate inflow performance relationship on a well completion.
get_set_pq_curve.pyUpdate a source PQ relationship curve.
get_set_pvt_fluid.pyUpdate PVT fluid properties.
get_set_relative_permeability_data.pyUpdate relative permeability data on Darcy completion.
get_set_simulation_settings.pyUpdate the simulation settings.
get_set_study_conditions.pyUpdate study conditions.
get_set_study_constraints.pyUpdate study constraints.
get_set_trilinear_ipr.pyAdd a horizontal completion with trilinear IPR and run simulation.
get_set_well_heat_transfer.pyGet or set heat transfer table values.
get_set_value.pyUpdate a single parameter.
get_set_values.pyUpdate many parameters.
get_set_vfp_tables_conditions.pyUpdate vfp tables simulation parameters.
get_set_well_trajectory.pyUpdate a well trajectory.
get_set_wellstream_outlet.pyUpdate wellstream outlet.
get_set_blackoil_mix_viscosity_table.pyUpdate blackoil user defined mix viscosity table.
get_set_mfl_mix_viscosity_table.pyUpdate MFL user defined mix viscosity table.
get_set_compositional_mix_viscosity_table.pyUpdate compositional fluid user defined mix viscosity table.
get_set_userdefined_metocean.pyUpdate user defined metocean data
get_set_user_viscosity_table.pyUpdate blackoil user defined viscosity table
get_set_using_component.pyGet or set values using the find_component_objects method in Model class
get_spot_report_results.pyGet spot report results from simulation.
gldiagnosticssim_run_simulation.pyPerform a Gas lift diagnostics simulation.
multiprocessing_run_simulation_parallel.pyRun simulations in parallel using multiprocessing.
multiprocessing_run_simulation_seq.pyRun simulations sequentially using multiprocessing.
network_opt_sim_apply_results.pyPerform a network optimizer simulation and apply the results to the model.
network_opt_sim.pyPerform a network optimizer simulation.
networksim.pyPerform a network simulation.
networksim_async.pyPerform a network simulation as a background task.
new.pyCreate a new Pipesim model.
nodal_sim_multipoint.pyPerform a nodal analysis simulation with multipointing.
nodal_sim_run_simulation.pyPerform a nodal analysis simulation with custom conditions and show plot.
nodal_sim_run_simulation_sensitivities.pyPerform a nodal analysis simulation with sensitivities.
open_ui.pyOpen the Pipesim model in the UI.
open_close.pyOpen and close a Pipesim model.
open_close_eu.pyOpen and close a Pipesim model with alternative units.
open_save.pyOpen and save a Pipesim model.
ptprofilesim_calc_custom_variable.pyPerform a PT Profile simulation with custom variable.
ptprofilesim_calc_outlet_pressure.pyPerform a PT Profile simulation with a specified outlet pressure.
ptprofilesim_sensitivity.pyPerform a PT Profile simulation sensitivity study.
ptprofilesim_multipoint.pyPerform a PT Profile simulation using multipointing.
read_catalog.pyUpdate an ESP from the catalog.
run_all.pyRun all the examples.
systemanalysis_sensitivity_customvariable.pyPerform a System analysis simulation with sensitivity and custom variable.
systemanalysissim_run_simulation.pyPerform a System analysis simulation.
systemperformance_concentric_tubing.pyPerform a System performance operation for concentric tubing.
systemperformance_dual_string.pyPerform a System performance operation for dual string.
systemperformance_flowcontrolvalve_result.pyPerform a System performance operation and check result of flowcontrolvalve.
validation_model.pyValidates the model for possible issues.
validation_network_opt_sim.pyValidates the model and optimization task for possible issues.
validation_networksim.pyValidates the model and networksim task for possible issues.
validation_nodal_sim.pyValidates the model and nodal analysis task for possible issues.
validation_ptprofile_sim.pyValidates the model and PT profile task for possible issues.
validation_system_performance.pyValidates the model and system performance task for possible issues.
vfp_tables_simulation_with_sensitivities.pyPerform a vfp tables simulation with sensitivities.
well_calibration.pyPerform well calibration task.
well_calibration_publish.pyPublish well calibration results to the model.
well_calibration_reset_boundary_conditions.pyReset boundary conditions for well calibration test data.
well_calibration_set_calibration_parameters.pyGet and set calibration parameters for well calibration.
well_calibration_add_delete_test.pyAnd and delete well test data for well calibration.
well_export.pyExport a well to a new Pipesim model.
well_export_all.pyExport all the wells to individual Pipesim models.
well_import.pyImport a well into the Pipesim model.
well_import_all.pyImport multiple wells from a specified folder.
wellperformancecurvessim_run_simulation.pyPerform a Well performance curves simulation.
worker_thread_test.xlsxExcel workbook with xl_worker_thread, xl_main_thread macros.

Case Studies

The following Case Studies are included with the Pipesim Python Toolkit.

Case StudyComplexityDescription
Build Network ModelComplexBuilds a network model from data in an Excel workbook.
Choke ManagerSimpleUses Excel as a simple interface for updating choke parameters.
Daily ProductionSimpleRuns simulations for each day of production data.
Excel TemplateSimpleTemplate. Uses Excel as a simple interface to Pipesim model.
Export Flowline GeometriesSimpleExports the flowline geometries from a model.
FCV SensitivityComplexPerform multiple advanced well simulations for different flow control valve positions.
Gas Lift DiagnosticsModerateUses Excel as a simple interface for running Gas Lift Diagnostics.
Gas Lift OptimizerComplexUses Excel as a simple interface for gas lift optimizer network.
Gas Lift PerformanceSimpleUses Excel as a simple interface for running Gas Lift Performance.
GIS Model ConversionComplexConverts junctions into model components after a GIS shape file import.
InjectionPoint managerSimpleUses Excel as a simple interface for updating injection point parameters.
Merge NetworksComplexUses Excel as an interface to call merge networks script.
Network OptimizerComplexUses Excel as a simple interface for network optimizer for all control types (ESP, PCP, Gas Lift & Choke).
Network SimulationModerateUses Excel as a simple interface for network simulations.
Nodal AnalysisComplexUses Excel as a simple interface for nodal analysis simulations.
PT Profile SimulationModerateUses Excel as a simple interface for PT Profile simulations.
Slug Catcher SizingModeratePerforms multiple simulations for a slug catcher sizing study.
SpotReport managerSimpleUses Excel as a simple interface for updating spot report parameters.
System AnalysisModerateUses Excel as a simple interface for running system analysis.
VFP simulationModeratePerform multiple VFP tables generation based on individually predefined parameters.
Well CalibrationModerateUses Excel as a simple interface for well calibration.
Well Model ManagementSimpleImports and exports individual well models from a network model.

Build Network Model

The data for a Pipesim model can come from many different sources. Typically this is available in a database, or in a document such as Excel workbook.

In this case study the model data has been provided in a formatted Excel workbook. The script reads the workbook and automatically builds the Pipesim model from the data. The user can update the parameterization, add or remove model components, and change the specified parameters in the workbook without needing to edit the script. The final model is opened in the Pipesim UI for verification and review.

Choke manager

Pipesim network model may contains many chokes in wells and network. In user interface user must edit choke parameters one by one. Excel can be used as a simple interface to control parameters of all choke at one table.

This case study demonstrates how to read list of chokes from model, get current parameters and update values.

Daily Production

Pipesim is sometimes used for production allocation and product metering verification. In these situations some of the production data is used as the boundaries in the Pipesim model, with the remaining data compared to the Pipesim simulation results.

The case study takes field data and runs the Pipesim model using these as boundary conditions. The Pipesim results are provided to compare with the field flow rates. This will highlight discrepancies in meter allocation, model calibration, or differences due to flow assurance issues.

Excel Template

Template of Excel-Pipesim link. The case study demonstrates how to get model description.

Export Flowline Geometries

The GIS feature in Pipesim provides elevation data capture from online data sources. After capturing the elevation data the profile is often needed in other documents such as reports and calculations.

FCV Sensitivity

This case study uses Excel as an interface for performing advanced well simulations. Current well operation conditions can be received from the System performance task. Simulation will be performed for different FCV positions within a user defined range and results are reported in separate tables for each combination. The user can control the workflow for selecting the best combination of FCV positions.

Gas Lift Diagnostics

Gas Lift Diagnostcs is one of the important features in Pipesim that allows engineers and operators analyze the impact of various production operation conditions on the performance and status of Gas Lift valves installed in the well.

The case study demonstrates how to check whether you can open (connect to) the model, set simulation conditions and run the Gas Lift Diagnostcs task. Once the task is completed, the status of each gas lift valve in displayed, in addition to the gas rate passing through each valve.

Gas Lift Optimizer

Excel can be used as simplified user interface for running Pipesim gas lift network optimizer simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model.

Boundary conditions, Initial conditions, Dual strings, Local constraints & Optimization parameters can be updated, simulations performed, and the results reviewed.

Gas Lift Performance

PIPEISIM provide a powerful simulation capability to model well performance with Gas Lift system installation. Based on casing injection pressure, gas density and hydraulic calculations, PIPIESIM will identify the operating valves and calculate well production flow rate at different surface gas lift injection rates.

The case study simplifies modeling the Gas Lift performance simuation and allows changing boundary conditions and Gas Lift rates, running well performance and then plotting the Gas Lift performance curve in Excel.

GIS Model Conversion

Pipesim can import GIS shape files to automatically lay out the flowlines and junctions. After import, the junctions can be converted to the equipment that exists in the field, such as well, sources and sinks.

This case study takes a Pipesim model file created from a shape file import and uses Excel data to do a search and replace on the model components. The components are matched against the latitude and longitude of the junctions.

The script is run from the desktop or through an interative Python window. While it reads the Excel workbook, it demonstrates that scripts do not need to be embedded in order to interact with Excel.

InjectionPoint manager

Pipesim network model may contains many injection points in both wells and network. In user interface user must edit injection point parameters (fluid, rate, temperature) one by one. Excel can be used as a simple interface to control parameters of all injection points at one table.

This case study demonstrates how to read list of injection points from model, get current parameters and update values.

Network Optimizer

Excel can be used as simplified user interface for running Pipesim network optimizer simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model.

Boundary conditions, Initial conditions, Local constraints & Optimization parameters can be updated, simulations performed, and the results reviewed.

Network Simulation

Excel can be used as simplified user interface for running Pipesim network simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model. Boundary conditions and equipment data can be updated, simulations performed, and the results reviewed.

This case study uses Excel as an interface for performing network simulations. The boundary conditions and specific equipment data is exposed for user updates. The simulation can be run and results retrieved for analysis.

Nodal Analysis

Excel can be used as simplified user interface for running Pipesim nodal analysis simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model. Boundary conditions and equipment data can be updated, simulations performed, and the results reviewed.

This case study uses Excel as an interface for performing batch nodal analysis simulations. The boundary conditions is exposed for user updates, the simulation run and results retrieved for visualization and analysis.

PT Profile Simulation

Excel can be used as simplified user interface for running Pipesim PT profile simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model. Boundary conditions and equipment data can be updated, simulations performed, and the results reviewed.

This case study uses Excel as an interface for performing PT Profile simulations. The boundary conditions is exposed for user updates, the simulation run and results retrieved for analysis.

Slug Catcher Sizing Study

Pipesim is often used on projects during the concept and front end engineering design (FEED) phases for equipment sizing.

In this use case, a parametric study is performed on a Pipesim model to determine the size of a slug catcher at an onshore receiving facility. It varies the flow correlation, Equation of State and liquid / gas ratio for pigging and ramp up scenarios. It is based on the paper presented at Pipeline Simulation Interest Group, PSIG1603.

SpotReport manager

Pipesim network model may contains many spot reports with different options. Excel can be used as a simple interface to control parameters of all reports at one table.

This case study demonstrates how to read list of spotreport from model, get current options and update values.

System Analysis

This case study uses Excel as an interface for running Pipesim system analysis simulations. Pertinent data can be exposed and updated without danger of the user damaging the underlying Pipesim model. Boundary conditions can be updated, simulations performed, and oil rate given different operation condidtion is estimated.

VFP simulation

This case study uses Excel as an interface for performing VFP tables generation. Current well operation conditions can be received from Network simulation task. Table template allows to setup VFP task parameters for all wells simultaneously or specify unique parameters for each well. The ready VFP tables are stored in temporary folder specified by user.

Well Calibration

Excel can be used as simplified user interface for running Pipesim well calibration task. Well test data and calibration parameters can be exposed and updated without danger of the user damaging the underlying Pipesim model.

This case study demonstrates how to extract well test data and related calibration parameters from the model, add a new test, and run a simulation. The calibration results can be published back to the model.

Well Model Management

A use case for model management is to model wells individually and to import them into a single Pipesim file for a network simulation. It allows you to maintain individual well models, while being able to easily run a single large network simulation.

This case study provides an Excel interface for managing the well models. It will export all the wells in a Pipesim model to individual files and import them again on the click of a button. The well names in the model are also listed.