PVT Analysis of a Reservoir Oil¶
In this tutorial you will take a reservoir oil from its laboratory PVT report to a process flowsheet. You enter the reported composition with its C7+ fraction and the tests the laboratory ran, let the PVT Analysis tool split the C7+ into pseudocomponents, and compare the simulated tests with the measured ones. Then you fit the equation of state to the data, write black-oil tables for a reservoir simulator, and send the fluid to a flowsheet that repeats one of the laboratory's separator tests with valves, coolers and separators.
What you will learn
- What a PVT report measures: the bubble point, the constant composition expansion, the differential liberation and the separator tests
- How the C7+ fraction of a reported composition becomes pseudocomponents of a cubic equation of state
- How to read the deviations between the simulated and the measured tests, and how the weights decide what a fit improves
- Why a fit with fewer variables can be the better one, and what a correlation alert means
- How the fluid goes on to a reservoir simulator (black-oil tables) and to a DWSIM flowsheet
Prerequisites
- Completed the Beginner Track, above all Simple Flash Drum
- DWSIM 10.3.0 or later
- The PVT Analysis tool is part of the Patreon edition (Premium and Premium+). Its window opens in every edition, and running, fitting and exporting need membership level 2.
Process Overview¶
A reservoir oil is sampled at the bottom of a well, or recombined from the gas and oil of a test separator, and sent to a laboratory. The laboratory reports its composition up to C6 as single components and lumps the rest as one C7+ fraction with a molar mass and a specific gravity. It then runs a set of standard tests at the reservoir temperature:
- Bubble point: the pressure at which the first bubble of gas appears in the oil. Above it the oil is a single liquid; below it gas comes out of solution.
- Constant composition expansion (CCE): the oil is expanded in a cell without removing anything, and the volume of the cell is reported relative to its volume at the bubble point.
- Differential liberation (DLE): the oil is taken down in pressure steps, and at each step the gas that came out of solution is removed. This is how the oil behaves in the reservoir once the gas moves away from it. The report gives the solution gas-oil ratio Rs (standard volume of gas still dissolved per volume of oil at stock tank conditions), the oil formation volume factor Bo (volume of oil at the pressure and temperature of the step per volume of stock tank oil), the oil density and the gas compressibility factor Z.
- Separator test: the oil at its bubble point is flashed through one or more separators to a stock tank, the way a production facility does it, and the report gives the gas-oil ratio (GOR) of each stage, the Bo and the density of the stock tank oil.
A cubic equation of state predicts these tests from the composition. The C7+ fraction is the weak point, because it holds hundreds of compounds that the laboratory didn't analyze one by one: the tool splits it with a distribution of molar mass, estimates the critical properties of each fraction from its molar mass and specific gravity, and lumps the fractions into a few pseudocomponents. The prediction is usually within a few percent, and a fit of a few multipliers of the heavy fractions closes most of the gap.
graph LR
R["PVT report<br/>composition and tests"] --> S["PVT study"]
S --> C["Characterization<br/>C7+ split in 5 pseudocomponents"]
C --> E["Simulated tests"]
E -- deviations --> F["Fit<br/>multipliers of the heavy fractions"]
F --> C
E --> B["Black-oil tables<br/>(reservoir simulator)"]
E --> FS["DWSIM flowsheet<br/>compounds, package, stream"]
Key Design Parameters¶
The data are the example report of chapter 6 of Whitson and Brulé (2000), a black oil at 220 °F.
| Parameter | Value |
|---|---|
| Composition, mole % | CO2 0.91, N2 0.16, C1 36.47, C2 9.67, C3 6.95, i-C4 1.44, n-C4 3.93, i-C5 1.44, n-C5 1.41, C6 4.33, C7+ 33.29 |
| C7+ fraction | molar mass 218 g/mol, specific gravity 0.8515 |
| Reservoir temperature | 104.44 °C (220 °F) |
| Measured bubble point | 181.66 bar (2620 psig) |
| Equation of state | Peng-Robinson with volume translation |
| Characterization | gamma distribution of molar mass (shape 1, lowest molar mass 90 g/mol), split up to C30+, lumped in 5 pseudocomponents |
| Standard conditions of the report | 15.56 °C (60 °F) and 1.0101 bar (14.65 psia) |
Step-by-Step in the Classic UI¶
1. Open the PVT Analysis window¶
File > New Chemical Process Model: you don't need to add any compound yet, because the tool adds its own when it sends the fluid to the flowsheet. Close the wizard, and set the unit system to one that shows pressures in bar and temperatures in °C. Then open Tools > PVT Analysis. The inputs are on the left: the fluid and its characterization, the composition, the experiments with their measured data, and the fit. The results are on the right, in the Summary, Fluid, Experiments and Log tabs.
Load the study instead of typing it
The report has 99 measured values. You can type them as described below, or press Load study... and open examples/saved/pvt_analysis.dwpvt, which holds the same study (with the fit of step 8 already done).
2. The fluid and its characterization¶
In Fluid and characterization, set:
| Property | Value |
|---|---|
| Study name | Reservoir oil |
| Equation of state | Peng-Robinson |
| Reservoir temperature | 104.444 °C |
| Heavy end | C7+ |
| Heavy end amount | 33.29 |
| Heavy end molar mass | 218 g/mol |
| Heavy end specific gravity | 0.8515 |
| Distribution shape | 1 (exponential) |
| Lowest molar mass of the distribution | 90 g/mol |
| Last carbon number of the split | 30 |
| Pseudocomponents of the heavy end | 5 |
| Methane interaction constant | 0.18 |
The distribution shape and its lowest molar mass describe how the C7+ moles spread over the carbon numbers; a shape of 1, the exponential distribution, is the usual starting point for a black oil. The tool splits the fraction into single carbon numbers up to C30+ and then lumps them in five pseudocomponents, which is enough for the phase behavior and keeps the flowsheet light. The methane interaction constant sets the binary interaction parameters between methane and each heavy fraction (the modified Chueh-Prausnitz rule), and the fit of step 8 adjusts them.
3. The composition¶
In Composition, enter the amounts of the defined components in mole percent: CO2 0.91, N2 0.16, C1 36.47, C2 9.67, C3 6.95, i-C4 1.44, n-C4 3.93, i-C5 1.44, n-C5 1.41, C6 4.33. The C7+ amount is the heavy end amount of step 2, and the amounts are normalized, so any basis works.

4. The experiments and their measured data¶
The window works in the units of the flowsheet, and the report is in field units: a gauge pressure in psig becomes an absolute pressure in bar as (psig + 14.696) × 0.0689476, and a gas-oil ratio in scf/bbl becomes Sm³/Sm³ when you multiply it by 0.1781. Add four experiments with Add:
Bubble point (Saturation pressure): measured saturation pressure 181.66 bar, and density at saturation 656.2 kg/m³ (the report gives the specific volume, 0.02441 ft³/lbm).
CCE (Constant composition expansion): 23 pressures from 345.75 to 33.56 bar with the relative volume of the cell. A few of the rows:
| Pressure, bar | 345.75 | 276.80 | 207.86 | 181.66 | 166.56 | 145.11 | 118.09 | 90.09 | 58.24 | 33.56 |
|---|---|---|---|---|---|---|---|---|---|---|
| Relative volume | 0.9639 | 0.9771 | 0.9929 | 1.0000 | 1.0350 | 1.1040 | 1.2426 | 1.5012 | 2.1623 | 3.7226 |
DLE (Differential liberation): ten stages from 163.04 to 11.98 bar and a last stage at the standard pressure. The report's volumes are given per volume of residual oil, the oil left at the end at 15.56 °C. The last step of the test, though, is a bleed down to atmospheric pressure, not one equilibrium stage, so Rs and Bo carry the uncertainty of that residual oil. The tool also takes the same data on the volume at the bubble point, as the oil volume over the volume at the bubble point and the gas removed per volume at the bubble point, and those are the columns the fit uses:
| Pressure, bar | Rs, Sm³/Sm³ | Bo | Oil density, kg/m³ | Gas Z |
|---|---|---|---|---|
| 181.66 | 152.1 | 1.600 | 656.2 | |
| 163.04 | 135.9 | 1.554 | 665.5 | 0.846 |
| 145.80 | 121.8 | 1.515 | 673.1 | 0.851 |
| 128.57 | 109.0 | 1.479 | 680.8 | 0.859 |
| 111.33 | 96.9 | 1.445 | 688.9 | 0.872 |
| 94.09 | 85.3 | 1.412 | 696.9 | 0.887 |
| 76.86 | 74.1 | 1.382 | 704.4 | 0.903 |
| 59.62 | 63.1 | 1.351 | 712.1 | 0.922 |
| 42.38 | 52.0 | 1.320 | 719.8 | 0.941 |
| 25.15 | 39.7 | 1.283 | 729.1 | 0.965 |
| 11.98 | 28.0 | 1.244 | 738.2 | 0.984 |
| 1.01 | 0 | 1.075 | 789.2 |
The residual oil has 35.1 °API, a density of 848.5 kg/m³ at 15.56 °C.
Separator 100 psig (Separator test): a separator at 7.908 bar and 23.89 °C, and the stock tank at 1.01325 bar and 23.89 °C. The laboratory measured a GOR of 120.4 Sm³/Sm³ in the separator and 16.4 Sm³/Sm³ in the tank, 136.8 Sm³/Sm³ in total, a Bo of 1.474 and a stock tank oil of 40.7 °API, 820.9 kg/m³.
5. The weights¶
The fit minimizes the sum of the squared deviations, each one taken as a fraction of the largest measured value of its column and multiplied by the weight of its quantity. Set these weights in the Measured quantity grid of the fit:
| Quantity | Weight | Why |
|---|---|---|
| Saturation pressure | 5 | the single most important number of a black oil, and it is one value against dozens of points of the other tests |
| Densities (at saturation, oil density of the DLE, residual oil, stock tank oil) | 3 | they are what the volume translation can fix, and they set the volumes a reservoir simulator computes |
| Rs and Bo of the DLE | 0 | they repeat the volumes of the DLE on the residual oil basis; the volumes on the bubble point basis are fitted instead |
| everything else | 1 |
6. Run the experiments untuned¶
Press Run. The tool characterizes the fluid and simulates the four experiments in well under a second. The Fluid tab shows the five pseudocomponents and the Summary tab the deviations:
| Pseudocomponent | Mole fraction | Molar mass, g/mol | Specific gravity | Tc, K | Pc, bar | Acentric factor |
|---|---|---|---|---|---|---|
| C7-11 | 0.1402 | 121.8 | 0.7758 | 599.4 | 27.94 | 0.392 |
| C12-15 | 0.0683 | 186.0 | 0.8279 | 696.5 | 20.30 | 0.586 |
| C16-21 | 0.0599 | 253.4 | 0.8604 | 765.7 | 15.71 | 0.766 |
| C22-29 | 0.0376 | 347.9 | 0.8917 | 836.1 | 12.00 | 0.971 |
| C30+ | 0.0269 | 540.0 | 0.9338 | 931.1 | 8.36 | 1.236 |
The untuned bubble point is 174.6 bar, 3.9 % below the measured 181.66 bar. The other tests are already within a few percent:
| Experiment | Quantity | Points | Average deviation, % |
|---|---|---|---|
| Bubble point | saturation pressure | 1 | 3.87 |
| Bubble point | density at saturation | 1 | 0.96 |
| CCE | relative volume | 23 | 0.54 |
| DLE | oil density | 12 | 1.00 |
| DLE | gas Z | 10 | 2.02 |
| DLE | oil volume over the volume at the bubble point | 11 | 1.58 |
| DLE | gas removed per volume at the bubble point | 11 | 4.81 |
| Separator 100 psig | total GOR | 1 | 1.89 |
| Separator 100 psig | stock tank oil density | 1 | 0.28 |
On the Experiments tab, choose the DLE and the oil density. The simulated oil is too dense at low pressure and too light near the bubble point, and the measured points sit on both sides of the line:

7. Fit three variables, and read the alerts¶
The Fit to the measured data grid lists the variables the tool can adjust. Three are checked by default: the multiplier of the methane interaction parameters, the multiplier of the volume translation of the heavy fractions, and the multiplier of their critical temperature. Press Fit. The fit takes 7 iterations and lowers the objective from 0.1065 to 0.0684, with the multipliers at 1.342, 0.847 and 0.989. The Log tab, though, shows three alerts: each pair of variables is correlated, with coefficients of -0.98, -0.99 and 0.99. This means the data fix a combination of the three variables, not each one: another set of values would fit almost as well, and the fitted numbers don't have a meaning of their own.
8. Fit two variables¶
Uncheck the Tc multiplier and press Fit again. The fit takes 4 iterations and reaches an objective of 0.0686, practically the same as with three variables, and now there isn't any alert. The methane interaction multiplier is 1.226 and the volume translation multiplier 0.922. With two variables, each one has a job: the interaction parameters move the bubble point, and the volume translation moves the densities.

| Experiment | Quantity | Before the fit, % | After the fit, % |
|---|---|---|---|
| Bubble point | saturation pressure | 3.87 | 0.44 |
| Bubble point | density at saturation | 0.96 | 1.36 |
| CCE | relative volume | 0.54 | 0.37 |
| DLE | oil density | 1.00 | 0.74 |
| DLE | gas Z | 2.02 | 2.03 |
| DLE | oil volume over the volume at the bubble point | 1.58 | 1.56 |
| DLE | gas removed per volume at the bubble point | 4.81 | 5.05 |
| Separator 100 psig | total GOR | 1.89 | 2.80 |
| Separator 100 psig | stock tank oil density | 0.28 | 1.13 |
The fitted bubble point is 180.9 bar, 0.44 % below the measured one. The fit paid for it with a little of the separator test: the total GOR and the stock tank density moved away from the laboratory by about 1 %. That is the weight of 5 on the bubble point at work, and it is a choice you can change (see the exercises).

The Fluid tab now shows the fitted fluid, with the volume translations of the heavy fractions scaled by 0.922:

9. Black-oil tables for a reservoir simulator¶
A black-oil reservoir simulator doesn't use a composition. It reads tables of Rs, Bo and the oil viscosity against pressure, computed with the separator stages of the surface facility. Press Export... > Black-oil tables (Eclipse keywords)... and save the file. The tool takes the stages of the first separator test of the study, so the table follows the oil through the 100 psig separator and the stock tank:
| Pressure, bar | Rs, Sm³/Sm³ | Bo | Oil viscosity, cP |
|---|---|---|---|
| 10.0 | 8.19 | 1.0946 | 0.832 |
| 44.2 | 35.32 | 1.1863 | 0.616 |
| 78.3 | 57.06 | 1.2504 | 0.502 |
| 112.5 | 80.04 | 1.3161 | 0.417 |
| 146.7 | 105.14 | 1.3868 | 0.349 |
| 180.9 | 132.96 | 1.4643 | 0.295 |
The file holds the DENSITY, PVTW, PVTO and PVTG keywords: the stock tank oil at 811.6 kg/m³, the gas at 1.0244 kg/m³ and the water from the steam tables. The oil viscosity comes from the Lohrenz-Bray-Clark correlation, which this tutorial doesn't fit; the Case Library case fits it to the measured viscosities of the report.
10. Send the fluid to the flowsheet and repeat the separator test¶
Press Send to flowsheet. The tool adds the ten defined components from the DWSIM database and the five pseudocomponents with their fitted constants, creates a Peng-Robinson property package tagged PVT Analysis with every interaction parameter of the fluid, and adds a stream PVT fluid at the reservoir temperature and the bubble point.
Set the stream to 100 mol/s at 104.44 °C and 185.86 bar, 5 bar above the fitted bubble point, so that it is the single-phase reservoir oil. Then build the separator test with ordinary unit operations:
| Tag | Unit operation | Specification |
|---|---|---|
| LV-100 | Valve | outlet pressure 7.908 bar (100 psig) |
| E-100 | Cooler | outlet temperature 23.89 °C (75 °F) |
| V-100 | Gas-Liquid Separator | separator gas and separator oil |
| LV-200 | Valve | outlet pressure 1.01325 bar |
| E-200 | Heater | outlet temperature 23.89 °C; the oil cools when it flashes, and the laboratory holds the tank at 75 °F |
| V-200 | Gas-Liquid Separator | tank gas and tank oil |
| E-300 | Cooler | outlet temperature 15.56 °C (60 °F), where the stock tank oil volume is reported |

The flowsheet solves in 0.3 s. Read the gas-oil ratios as the standard volume of each gas over the volume of the stock tank oil:
| Laboratory | PVT tool | Flowsheet | |
|---|---|---|---|
| Separator GOR, Sm³/Sm³ of tank oil | 120.4 | 118.9 | 118.9 |
| Tank GOR, Sm³/Sm³ of tank oil | 16.4 | 14.1 | 14.1 |
| Total GOR, Sm³/Sm³ | 136.8 | 133.0 | 133.0 |
| Stock tank oil, kg/m³ | 820.9 | 811.6 | 811.7 |
The flowsheet gives the same numbers as the tool, because the property package carries the same equation, components and interaction parameters, and DWSIM's flash finds the same equilibrium as the tool's. The separator feed has a vapor fraction of 0.495 and the tank feed 0.116.
Results and Validation¶
Expected results
Untuned, the characterized fluid has a bubble point of 174.6 bar against the measured 181.66 bar (3.9 % low). The fit of the methane interaction and volume translation multipliers (1.226 and 0.922) brings it to 180.9 bar (0.44 % low), with the densities within about 1.4 % and the total GOR of the 100 psig separator test at 133.0 Sm³/Sm³ against 136.8. The flowsheet repeats the separator test with the same GORs as the tool.
The study is a smaller version of the one in the Reservoir oil from a PVT report to a two-stage separation case of the Case Library (cases/separation-processes/reservoir-oil-pvt-two-stage-separation). That case takes all four separator tests of the report, the oil viscosity of the differential liberation and a minimum miscibility pressure with CO2, and fits three variables; its README reports a bubble point 0.8 % low and a total GOR of 133.5 Sm³/Sm³ for the same separator test. The numbers of this page come from the Python script below.
Automating This Tutorial¶
Files in this repository
- Python script:
examples/reservoir/01_pvt_analysis.py - Pre-built flowsheet:
examples/saved/pvt_analysis.dwxmz, with the studypvt_analysis.dwpvtnext to it (the PVT Analysis window opens it with the flowsheet) and the black-oil tablespvt_analysis.inc
The script needs DWSIM Plus: set DWSIM_PATRON_KEY to your Patreon key, or run it where the Plus license is activated. It builds the study from the report in its own units, runs it untuned, fits three and then two variables, writes the black-oil tables, sends the fluid to a new flowsheet and builds the separator test, in about 4 s. If DWSIM_SAVE_TO is set to a file name, it saves the flowsheet there with the study and the tables next to it.
import json
import os
import sys
import tempfile
import time
import pythonnet
pythonnet.load("netfx") # DWSIM is a .NET Framework application
import clr # noqa: E402
DWSIM_BIN = os.environ.get("DWSIM_BIN")
if not DWSIM_BIN:
raise SystemExit("Set DWSIM_BIN to the DWSIM installation folder before running.")
for sub in ("", "unitops", "ppacks", "extenders"):
sys.path.append(os.path.join(DWSIM_BIN, sub))
for a in ("DWSIM.Automation", "DWSIM.Automation.FluentAPI", "DWSIM.Interfaces", "DWSIM.GlobalSettings",
"DWSIM.Extensions.PVT"):
clr.AddReference(a)
from System.Collections.Generic import List # noqa: E402
from DWSIM.Automation.FluentAPI import Flowsheet, License, Q # noqa: E402
from DWSIM.Extensions.PVT import Col, PvtStudy, RegressionOptions, RegressionParameter, RegressionVariable # noqa: E402
from DWSIM.Extensions.PVT.Dwsim import PvtSession # noqa: E402
from DWSIM.GlobalSettings import Settings # noqa: E402
# --- license ---------------------------------------------------------------------------------------------------------
if not License.IsActivated:
key = os.environ.get("DWSIM_PATRON_KEY")
if not key or not License.CheckLicense(key):
raise SystemExit("The PVT Analysis tool is part of DWSIM Plus: set DWSIM_PATRON_KEY to your Patreon key.")
Settings.InspectorEnabled = False
# --- 1. The laboratory report, in its own units ------------------------------------------------------------------------
PSI = 6894.757293 # Pa per psi
ATM_PSI = 14.696 # gauge pressures of the report are over one atmosphere
STD_PSIA = 14.65 # the report measures gas volumes at 14.65 psia and 60 F
SCF_BBL = 0.028316846592 / 0.158987294928 # scf/bbl to Sm3/Sm3
def pa(psig):
return (psig + ATM_PSI) * PSI
def kelvin(f):
return (f + 459.67) / 1.8
def api_density(api):
return 141.5 / (131.5 + api) * 999.012
RESERVOIR_T_F = 220.0
BUBBLE_POINT_PSIG = 2620.0
COMPOSITION = {"CO2": 0.91, "N2": 0.16, "C1": 36.47, "C2": 9.67, "C3": 6.95, "i-C4": 1.44, "n-C4": 3.93,
"i-C5": 1.44, "n-C5": 1.41, "C6": 4.33} # mole %
C7PLUS = {"amount": 33.29, "molar_mass": 218.0, "specific_gravity": 0.8515}
SPECIFIC_VOLUME_AT_PSAT = 0.02441 # ft3/lbm
# constant composition expansion: pressure (psig), volume over the volume at the bubble point
CCE = [(5000, 0.9639), (4500, 0.9703), (4000, 0.9771), (3500, 0.9846), (3000, 0.9929), (2900, 0.9946),
(2800, 0.9964), (2700, 0.9983), (2620, 1.0000), (2605, 1.0022), (2591, 1.0041), (2516, 1.0154),
(2401, 1.0350), (2253, 1.0645), (2090, 1.1040), (1897, 1.1633), (1698, 1.2426), (1477, 1.3618),
(1292, 1.5012), (1040, 1.7802), (830, 2.1623), (640, 2.7513), (472, 3.7226)]
# differential liberation: pressure (psig), solution gas-oil ratio (scf/bbl), relative oil volume (bbl/bbl of residual
# oil), oil density (g/cm3), gas Z; the last row is the residual oil at 60 F
DLE = [(2620, 854, 1.600, 0.6562, None), (2350, 763, 1.554, 0.6655, 0.846), (2100, 684, 1.515, 0.6731, 0.851),
(1850, 612, 1.479, 0.6808, 0.859), (1600, 544, 1.445, 0.6889, 0.872), (1350, 479, 1.412, 0.6969, 0.887),
(1100, 416, 1.382, 0.7044, 0.903), (850, 354, 1.351, 0.7121, 0.922), (600, 292, 1.320, 0.7198, 0.941),
(350, 223, 1.283, 0.7291, 0.965), (159, 157, 1.244, 0.7382, 0.984), (0, 0, 1.075, 0.7892, None)]
RESIDUAL_OIL_API = 35.1
# separator test: separator at 100 psig and 75 F, stock tank at 0 psig and 75 F; gas-oil ratios in scf per barrel of
# stock tank oil, formation volume factor in bbl of bubble point oil per bbl of stock tank oil
SEPARATOR = {"p_psig": (100, 0), "t_F": (75, 75), "gor": (676, 92), "api": 40.7, "bo": 1.474}
# --- 2. The PVT study --------------------------------------------------------------------------------------------------
NAN = float("nan")
dle_p = [pa(r[0]) for r in DLE]
study = {
"Version": 1, "Name": "Reservoir oil", "Temperature": kelvin(RESERVOIR_T_F),
"Notes": "Example report of SPE Monograph 20 (Whitson and Brule, 2000), chapter 6",
"Composition": [{"Name": n, "Amount": x} for n, x in COMPOSITION.items()],
"HeavyEnd": {"Name": "C7+", "Amount": C7PLUS["amount"], "MolarMass": C7PLUS["molar_mass"],
"SpecificGravity": C7PLUS["specific_gravity"]},
# Peng-Robinson; C7+ split by a gamma distribution of molar mass up to C30+ and lumped in five pseudocomponents
"Characterization": {"Equation": "PengRobinson", "Shape": 1.0, "Bound": 90.0, "LastCarbonNumber": 30,
"Groups": 5, "VolumeShift": "MatchSpecificGravity", "NonHydrocarbonInteractions": True,
"MethaneInteractionA": 0.18},
"Standard": {"Temperature": kelvin(60.0), "Pressure": STD_PSIA * PSI},
"Experiments": [
{"Name": "Bubble point", "Kind": "Saturation",
"Measured": {"Kind": "saturation", "Columns": {},
"Values": {"saturation_pressure": pa(BUBBLE_POINT_PSIG),
"saturation_density": 16.01846337 / SPECIFIC_VOLUME_AT_PSAT}},
"Weights": {"saturation_pressure": 5.0, "saturation_density": 3.0}},
{"Name": "CCE", "Kind": "ConstantCompositionExpansion", "Pressures": [pa(p) for p, v in CCE],
"Measured": {"Kind": "cce", "Values": {}, "Columns": {"relative_volume": [v for p, v in CCE]}}},
# the stages of the liberation; the last one is a bleed to atmospheric pressure, so the volumes on the
# residual oil (Rs, Bo) are shown, not fitted, and the same data enter on the bubble point volume instead
{"Name": "DLE", "Kind": "DifferentialLiberation", "Pressures": dle_p[1:-1] + [STD_PSIA * PSI],
"Measured": {"Kind": "dle", "Values": {"residual_oil_density": api_density(RESIDUAL_OIL_API)},
"Columns": {"rs": [r[1] * SCF_BBL for r in DLE], "bo": [r[2] for r in DLE],
"oil_density": [r[3] * 1000.0 for r in DLE],
"gas_z": [NAN if r[4] is None else r[4] for r in DLE],
"oil_relative_volume": [r[2] / DLE[0][2] for r in DLE[:-1]] + [NAN],
"gas_removed": [(DLE[0][1] - r[1]) * SCF_BBL / DLE[0][2] for r in DLE[:-1]] + [NAN]}},
"Weights": {"rs": 0.0, "bo": 0.0, "residual_oil_density": 3.0, "oil_density": 3.0}},
{"Name": "Separator 100 psig", "Kind": "SeparatorTest",
"Pressures": [pa(p) for p in SEPARATOR["p_psig"]], "StageTemperatures": [kelvin(t) for t in SEPARATOR["t_F"]],
"Measured": {"Kind": "separator",
"Values": {"bo": SEPARATOR["bo"], "stock_tank_density": api_density(SEPARATOR["api"]),
"total_gor": sum(SEPARATOR["gor"]) * SCF_BBL},
"Columns": {"gor": [g * SCF_BBL for g in SEPARATOR["gor"]]}},
"Weights": {"stock_tank_density": 3.0}},
]}
fs = Flowsheet.Create("Reservoir oil")
session = PvtSession(fs.Inner)
path = os.path.join(tempfile.gettempdir(), "rs01_study.dwpvt")
with open(path, "w", encoding="utf-8") as f:
f.write(json.dumps(study).replace("NaN", '"NaN"'))
session.Load(path)
def summary(title):
print("\n" + title)
print("%-20s %-22s %6s %7s %11s %11s" % ("Experiment", "Quantity", "Points", "Weight", "Average %", "Largest %"))
for d in session.Summary():
if d.Weight > 0:
print("%-20s %-22s %6d %7.1f %11.2f %11.2f" % (d.Experiment, d.Quantity, d.Points, d.Weight,
100 * d.Average, 100 * d.Largest))
def result(name):
i = [e.Name for e in session.Study.Experiments].index(name)
return session.Results[i]
# --- 3. The lab tests with the characterized fluid, before any fit ---------------------------------------------------
start = time.time()
session.Run()
fluid = session.Fluid
print("Fluid: %d components, %s" % (fluid.Components.Count, ", ".join(c.Name for c in fluid.Components)))
for c in fluid.Components:
if c.IsFraction:
print(" %-8s x %.4f M %6.1f SG %.4f Tc %6.1f K Pc %5.2f bar omega %.3f" % (
c.Name, fluid.Composition[fluid.IndexOf(c.Name)], 1000 * c.MolarMass, c.SpecificGravity, c.CriticalTemperature,
c.CriticalPressure / 1e5, c.AcentricFactor))
psat0 = result("Bubble point").Values[Col.SaturationPressure]
print("Untuned bubble point: %.1f bar (measured %.1f bar), experiments simulated in %.2f s" % (psat0 / 1e5, pa(BUBBLE_POINT_PSIG) / 1e5,
time.time() - start))
summary("Deviations before the fit (fraction of the largest measured value of each column):")
# --- 4. Fit: first the three default variables, then without the one the data can't tell apart -------------------
def fit(parameters):
start = time.time()
variables = List[RegressionVariable]()
for p in parameters:
variables.Add(RegressionVariable.Default(p))
session.RunFit(variables, RegressionOptions(), False)
f = session.Fit
print("\nFit of %s in %.1f s, %d iterations, objective %.4f -> %.4f" % (
", ".join(str(p) for p in parameters), time.time() - start, f.Iterations, f.InitialObjective, f.Objective))
for v in f.Variables:
print(" %-26s %.3f (limits %.2f to %.2f)" % (v.Parameter, v.Initial, v.Lower, v.Upper))
for alert in f.Alerts:
print(" alert:", alert)
fit([RegressionParameter.MethaneInteractionScale, RegressionParameter.VolumeShift, RegressionParameter.CriticalTemperature])
fit([RegressionParameter.MethaneInteractionScale, RegressionParameter.VolumeShift])
psat = result("Bubble point").Values[Col.SaturationPressure]
print("Fitted bubble point: %.1f bar" % (psat / 1e5))
summary("Deviations after the fit:")
dle = result("DLE")
print("\nDifferential liberation after the fit:")
print("%10s %12s %12s %12s %12s" % ("P, bar", "Bo calc", "Bo lab", "rho calc", "rho lab"))
for k in range(len(DLE)):
print("%10.1f %12.3f %12.3f %12.1f %12.1f" % (dle[Col.Pressure][k] / 1e5, dle[Col.Bo][k], DLE[k][2],
dle[Col.OilDensity][k], DLE[k][3] * 1000))
sep = result("Separator 100 psig")
print("Separator test: total GOR %.1f Sm3/Sm3 (lab %.1f), Bo %.3f (lab %.3f), tank oil %.1f kg/m3 (lab %.1f)" % (
sep.Values[Col.TotalGor], sum(SEPARATOR["gor"]) * SCF_BBL, sep.Values[Col.Bo], SEPARATOR["bo"],
sep.Values[Col.StockTankDensity], api_density(SEPARATOR["api"])))
# --- 5. Black-oil tables for a reservoir simulator -------------------------------------------------------------------
out = os.environ.get("DWSIM_SAVE_TO")
inc = os.path.splitext(out)[0] + ".inc" if out else os.path.join(tempfile.gettempdir(), "rs01_blackoil.inc")
tables = session.ExportBlackOil(inc)
print("\nBlack-oil tables (separator stages of the test): bubble point %.1f bar, tank oil %.1f kg/m3, gas %.4f kg/m3" % (
tables.SaturationPressure / 1e5, tables.OilDensity, tables.GasDensity))
print("%10s %12s %10s %12s" % ("P, bar", "Rs, Sm3/Sm3", "Bo", "mu oil, cP"))
for r in tables.Oil:
print("%10.1f %12.2f %10.4f %12.3f" % (r.Pressure[0] / 1e5, r.Rs, r.Bo[0], r.Viscosity[0] * 1000))
for note in tables.Notes:
print(" note:", note)
# --- 6. The fluid in a flowsheet: the separator test with unit operations ---------------------------------------------
applied = session.SendToFlowsheet()
for note in applied.Notes:
print("note:", note)
feed_tag = applied.Stream.GraphicObject.Tag
feed = fs.MaterialStream(feed_tag).At(Q.Kelvin(kelvin(RESERVOIR_T_F)), Q.Pascal(psat + 5e5)).WithMolarFlow(Q.MolPerSecond(100.0))
print("Flowsheet: compounds %s; package '%s'" % (", ".join(applied.Compounds), applied.Package.Tag))
p1, p_tank = [pa(p) for p in SEPARATOR["p_psig"]]
t1, t_tank = [kelvin(t) for t in SEPARATOR["t_F"]]
s1, s2 = fs.AddMaterialStream("to-cooler"), fs.AddMaterialStream("separator-feed")
fs.AddValve("LV-100").WithOutletPressure(Q.Pascal(p1)).ConnectFeed(feed).ConnectProduct(s1)
fs.AddCooler("E-100").WithOutletTemperature(Q.Kelvin(t1)).ConnectFeed(s1).ConnectProduct(s2)
gas1, oil1 = fs.AddMaterialStream("separator-gas"), fs.AddMaterialStream("separator-oil")
fs.AddSeparator("V-100").ConnectFeed(s2).ConnectProduct(gas1, 0).ConnectProduct(oil1, 1)
s3, s4 = fs.AddMaterialStream("to-heater"), fs.AddMaterialStream("tank-feed")
fs.AddValve("LV-200").WithOutletPressure(Q.Pascal(p_tank)).ConnectFeed(oil1).ConnectProduct(s3)
fs.AddHeater("E-200").WithOutletTemperature(Q.Kelvin(t_tank)).ConnectFeed(s3).ConnectProduct(s4)
gas2, oil2 = fs.AddMaterialStream("tank-gas"), fs.AddMaterialStream("tank-oil")
fs.AddSeparator("V-200").ConnectFeed(s4).ConnectProduct(gas2, 0).ConnectProduct(oil2, 1)
sto = fs.AddMaterialStream("stock-tank-oil")
fs.AddCooler("E-300").WithOutletTemperature(Q.Kelvin(kelvin(60.0))).ConnectFeed(oil2).ConnectProduct(sto)
start = time.time()
errors = fs.TrySolve()
print("\nFlowsheet solved in %.1f s, %d error(s)" % (time.time() - start, errors.Count))
for e in errors:
print(" ", e.GetBaseException().Message)
def density(s):
return s.Object.Phases[0].Properties.density # kg/m3 of the whole stream
gas_molar_volume = session.Study.Standard.GasMolarVolume # m3 of gas per mol at the standard conditions
sto_volume = sto.MassFlowKgPerSecond / density(sto)
gor1 = gas1.MolarFlowMolPerSecond * gas_molar_volume / sto_volume
gor2 = gas2.MolarFlowMolPerSecond * gas_molar_volume / sto_volume
print("%-36s %10s %10s %10s" % ("", "lab", "tool", "flowsheet"))
print("%-36s %10.1f %10.1f %10.1f" % ("Separator GOR, Sm3/Sm3 of tank oil", SEPARATOR["gor"][0] * SCF_BBL,
sep[Col.Gor][0], gor1))
print("%-36s %10.1f %10.1f %10.1f" % ("Tank GOR, Sm3/Sm3 of tank oil", SEPARATOR["gor"][1] * SCF_BBL,
sep[Col.Gor][1], gor2))
print("%-36s %10.1f %10.1f %10.1f" % ("Total GOR, Sm3/Sm3", sum(SEPARATOR["gor"]) * SCF_BBL,
sep.Values[Col.TotalGor], gor1 + gor2))
print("%-36s %10.1f %10.1f %10.1f" % ("Stock tank oil, kg/m3", api_density(SEPARATOR["api"]),
sep.Values[Col.StockTankDensity], density(sto)))
print("Vapour fraction of the separator feed %.4f, of the tank feed %.4f" % (s2.VaporFraction, s4.VaporFraction))
fs.OrthogonalLayout(True)
if out:
fs.Save(out)
session.Save(os.path.splitext(out)[0] + ".dwpvt") # the PVT Analysis window opens the study next to the flowsheet
print("Saved", os.path.basename(out), "with", os.path.basename(os.path.splitext(out)[0] + ".dwpvt"),
"and", os.path.basename(inc))
Exercises
- Give the saturation pressure a weight of 1 and fit the two variables again. How far does the bubble point move from the measured value, and what happens to the GOR of the separator test?
- Set the pseudocomponents of the heavy end to 0, which keeps every carbon number up to C30+, and run the study untuned. How much do the deviations change, and how many components would the flowsheet have?
- Add the separator test at 50 psig from the report: a GOR of 131.2 Sm³/Sm³ in the separator and 7.3 Sm³/Sm³ in the tank, a Bo of 1.481 and 40.5 °API. Does the fit change?
- Change the equation of state to Soave-Redlich-Kwong and run the study untuned. Which equation gives the better densities before the volume translation is fitted?
Further Reading¶
- C. H. Whitson and M. R. Brulé. (2000). Phase Behavior. SPE Monograph Volume 20. Society of Petroleum Engineers
- K. S. Pedersen, P. L. Christensen and J. A. Shaikh. (2015). Phase Behavior of Petroleum Reservoir Fluids, 2nd ed. CRC Press
- W. D. McCain Jr. (1990). The Properties of Petroleum Fluids, 2nd ed. PennWell
- DWSIM User Guide: PVT Analysis
Next Steps¶
You now know how to enter a PVT report, characterize a C7+ fraction, fit an equation of state with as few variables as the data can fix, and take the fluid to a reservoir simulator and to a flowsheet. Continue with From the Reservoir to the Plant, where a reservoir model and a DWSIM surface network run together, or open the Reservoir oil from a PVT report to a two-stage separation case of the Case Library to see the full study with the viscosity and the minimum miscibility pressure.