Skip to content

Commit e83a127

Browse files
committed
updated examples
1 parent c161577 commit e83a127

21 files changed

+294
-242
lines changed

examples/beggsBrillPipeline.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@
7373
print("\nPipeline Geometry:")
7474
print(f" Length: 10,000 m (10 km)")
7575
print(f" Diameter: 0.30 m (12 inch)")
76-
print(f" Wall roughness: 50 μm")
76+
print(f" Wall roughness: 50 um")
7777
print(f" Elevation gain: 200 m (uphill)")
7878

7979
print("\nInlet Conditions:")
8080
print(f" Pressure: {inlet_stream.getPressure('bara'):.1f} bara")
81-
print(f" Temperature: {inlet_stream.getTemperature('C'):.1f} °C")
81+
print(f" Temperature: {inlet_stream.getTemperature('C'):.1f} C")
8282
print(f" Mass flow: {inlet_stream.getFlowRate('kg/hr'):.0f} kg/hr")
8383

8484
print("\nOutlet Conditions:")
8585
print(f" Pressure: {outlet_pressure:.2f} bara")
86-
print(f" Temperature: {outlet_temp:.1f} °C")
86+
print(f" Temperature: {outlet_temp:.1f} C")
8787

8888
print("\nPipeline Performance:")
8989
print(f" Pressure drop: {pressure_drop:.2f} bar")
90-
print(f" ΔP per km: {pressure_drop / 10:.2f} bar/km")
91-
print(f" Temp change: {outlet_temp - inlet_stream.getTemperature('C'):.1f} °C")
90+
print(f" dP per km: {pressure_drop / 10:.2f} bar/km")
91+
print(f" Temp change: {outlet_temp - inlet_stream.getTemperature('C'):.1f} C")
9292

9393
# Get flow information from outlet stream
9494
outlet_fluid = outlet_stream.getFluid()

examples/createFluid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
molarMass = [0.20, 0.25, 0.3, 0.36, 0.4]
5454
density = [700.0e-3, 750.0e-3, 810.0e-3, 880.0e-3, 920.0e-3]
5555
fluid5 = addOilFractions(fluid4, charNames, charFlowrate, molarMass, density)
56+
fluid5 = fluid4 # addOilFractions modifies fluid in place
5657
print("phase envelope for fluid 5")
5758
phaseenvelope(fluid5, True)
5859
fluid5.setPressure(10.0, "bara")

examples/ejectorProcess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
sys.stdout.reconfigure(encoding='utf-8')
24
"""
35
Ejector Process Simulation Example
46
@@ -55,7 +57,7 @@
5557
process.run()
5658

5759
# Get results
58-
outlet_stream = ejector.getOutletStream()
60+
outlet_stream = ejector.getMixedStream()
5961
outlet_pressure = outlet_stream.getPressure("bara")
6062
outlet_temperature = outlet_stream.getTemperature("C")
6163
outlet_flow = outlet_stream.getFlowRate("kg/hr")

examples/equationOfState.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
sys.stdout.reconfigure(encoding='utf-8')
24
"""
35
Equation of State Comparison Tutorial
46
======================================
@@ -58,14 +60,14 @@
5860
def create_natural_gas(eos_name):
5961
"""Create a natural gas mixture with specified EoS."""
6062
gas = fluid(eos_name)
61-
gas.addComponent("nitrogen", 2.0, "mol%")
62-
gas.addComponent("CO2", 1.0, "mol%")
63-
gas.addComponent("methane", 88.0, "mol%")
64-
gas.addComponent("ethane", 5.0, "mol%")
65-
gas.addComponent("propane", 2.5, "mol%")
66-
gas.addComponent("i-butane", 0.5, "mol%")
67-
gas.addComponent("n-butane", 0.5, "mol%")
68-
gas.addComponent("n-pentane", 0.5, "mol%")
63+
gas.addComponent("nitrogen", 2.0)
64+
gas.addComponent("CO2", 1.0)
65+
gas.addComponent("methane", 88.0)
66+
gas.addComponent("ethane", 5.0)
67+
gas.addComponent("propane", 2.5)
68+
gas.addComponent("i-butane", 0.5)
69+
gas.addComponent("n-butane", 0.5)
70+
gas.addComponent("n-pentane", 0.5)
6971
gas.setMixingRule("classic")
7072
return gas
7173

@@ -118,9 +120,9 @@ def create_wet_gas(eos_name):
118120
gas = fluid(eos_name)
119121
gas.setMixingRule("classic")
120122

121-
gas.addComponent("methane", 90.0, "mol%")
122-
gas.addComponent("ethane", 5.0, "mol%")
123-
gas.addComponent("water", 5.0, "mol%")
123+
gas.addComponent("methane", 90.0)
124+
gas.addComponent("ethane", 5.0)
125+
gas.addComponent("water", 5.0)
124126
gas.setMultiPhaseCheck(True)
125127
return gas
126128

@@ -235,10 +237,10 @@ def create_wet_gas(eos_name):
235237
for eos in ["srk", "pr", "eos-cg"]:
236238
try:
237239
ccs_gas = fluid(eos)
238-
ccs_gas.addComponent("CO2", 95.0, "mol%")
239-
ccs_gas.addComponent("nitrogen", 3.0, "mol%")
240-
ccs_gas.addComponent("oxygen", 1.0, "mol%")
241-
ccs_gas.addComponent("argon", 1.0, "mol%")
240+
ccs_gas.addComponent("CO2", 95.0)
241+
ccs_gas.addComponent("nitrogen", 3.0)
242+
ccs_gas.addComponent("oxygen", 1.0)
243+
ccs_gas.addComponent("argon", 1.0)
242244
if eos not in ["eos-cg"]:
243245
ccs_gas.setMixingRule("classic")
244246
ccs_gas.setTemperature(25.0, "C")

examples/flareSystem.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
sys.stdout.reconfigure(encoding='utf-8')
24
"""
35
Flare System Simulation Example
46
@@ -74,17 +76,4 @@
7476
print(f" CO2 emissions: {co2_emission:.0f} kg/hr")
7577
print(f" CO2 emissions: {co2_emission * 24 / 1000:.1f} tonnes/day")
7678

77-
# Check capacity utilization
78-
capacity_check = flare.checkCapacity()
79-
if capacity_check.isOverloaded():
80-
print(f"\n⚠️ WARNING: Flare is OVERLOADED!")
81-
print(f" Heat utilization: {capacity_check.getHeatUtilization() * 100:.1f}%")
82-
print(f" Mass utilization: {capacity_check.getMassUtilization() * 100:.1f}%")
83-
else:
84-
print(f"\n✓ Flare is within design capacity")
85-
if not float("nan") == capacity_check.getHeatUtilization():
86-
print(f" Heat utilization: {capacity_check.getHeatUtilization() * 100:.1f}%")
87-
if not float("nan") == capacity_check.getMassUtilization():
88-
print(f" Mass utilization: {capacity_check.getMassUtilization() * 100:.1f}%")
89-
9079
print("=" * 60)

examples/flashCalculations.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
sys.stdout.reconfigure(encoding='utf-8')
24
"""
35
Thermodynamic Flash Calculations Tutorial
46
==========================================
@@ -38,14 +40,14 @@
3840
# =============================================================================
3941
# Using SRK (Soave-Redlich-Kwong) equation of state
4042
natural_gas = fluid("srk")
41-
natural_gas.addComponent("nitrogen", 2.0, "mol%")
42-
natural_gas.addComponent("CO2", 1.5, "mol%")
43-
natural_gas.addComponent("methane", 85.0, "mol%")
44-
natural_gas.addComponent("ethane", 6.0, "mol%")
45-
natural_gas.addComponent("propane", 3.0, "mol%")
46-
natural_gas.addComponent("i-butane", 1.0, "mol%")
47-
natural_gas.addComponent("n-butane", 1.0, "mol%")
48-
natural_gas.addComponent("n-pentane", 0.5, "mol%")
43+
natural_gas.addComponent("nitrogen", 2.0)
44+
natural_gas.addComponent("CO2", 1.5)
45+
natural_gas.addComponent("methane", 85.0)
46+
natural_gas.addComponent("ethane", 6.0)
47+
natural_gas.addComponent("propane", 3.0)
48+
natural_gas.addComponent("i-butane", 1.0)
49+
natural_gas.addComponent("n-butane", 1.0)
50+
natural_gas.addComponent("n-pentane", 0.5)
4951
natural_gas.setMixingRule("classic") # Use standard binary interaction parameters
5052
natural_gas.setMultiPhaseCheck(True) # Enable detection of multiple phases
5153

examples/fluidCreation.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
sys.stdout.reconfigure(encoding='utf-8')
24
"""
35
Fluid Creation Tutorial
46
========================
@@ -54,19 +56,19 @@
5456

5557
# Method A: Mole percent
5658
gas_mol_pct = fluid("pr")
57-
gas_mol_pct.addComponent("methane", 90.0, "mol%")
58-
gas_mol_pct.addComponent("ethane", 7.0, "mol%")
59-
gas_mol_pct.addComponent("propane", 3.0, "mol%")
59+
gas_mol_pct.addComponent("methane", 90.0)
60+
gas_mol_pct.addComponent("ethane", 7.0)
61+
gas_mol_pct.addComponent("propane", 3.0)
6062
gas_mol_pct.setMixingRule("classic")
6163

6264
print("A) Mole percent:")
6365
print(" methane: 90 mol%, ethane: 7 mol%, propane: 3 mol%")
6466

6567
# Method B: Mass (kg)
6668
gas_mass = fluid("pr")
67-
gas_mass.addComponent("methane", 100.0, "kg")
68-
gas_mass.addComponent("ethane", 20.0, "kg")
69-
gas_mass.addComponent("propane", 10.0, "kg")
69+
gas_mass.addComponent("methane", 100.0, "kg/hr")
70+
gas_mass.addComponent("ethane", 20.0, "kg/hr")
71+
gas_mass.addComponent("propane", 10.0, "kg/hr")
7072
gas_mass.setMixingRule("classic")
7173

7274
print("\nB) Mass (kg):")
@@ -128,11 +130,11 @@
128130
print("For undefined components, specify molecular weight and density")
129131

130132
oil = fluid("pr")
131-
oil.addComponent("methane", 30.0, "mol%")
132-
oil.addComponent("n-hexane", 20.0, "mol%")
133+
oil.addComponent("methane", 30.0)
134+
oil.addComponent("n-hexane", 20.0)
133135

134136
# Add a C10 pseudo-component with custom properties
135-
oil.addComponent("C10", 25.0, "mol%")
137+
oil.addComponent("C10", 25.0)
136138

137139
# Add a heavier fraction manually
138140
# Using addPlusFraction for C20+ pseudo-component
@@ -157,14 +159,14 @@
157159

158160
# Create oil with C7+ fraction
159161
oil_plus = fluid("pr")
160-
oil_plus.addComponent("nitrogen", 0.5, "mol%")
161-
oil_plus.addComponent("CO2", 1.5, "mol%")
162-
oil_plus.addComponent("methane", 45.0, "mol%")
163-
oil_plus.addComponent("ethane", 7.0, "mol%")
164-
oil_plus.addComponent("propane", 5.0, "mol%")
165-
oil_plus.addComponent("n-butane", 3.0, "mol%")
166-
oil_plus.addComponent("n-pentane", 3.0, "mol%")
167-
oil_plus.addComponent("n-hexane", 3.0, "mol%")
162+
oil_plus.addComponent("nitrogen", 0.5)
163+
oil_plus.addComponent("CO2", 1.5)
164+
oil_plus.addComponent("methane", 45.0)
165+
oil_plus.addComponent("ethane", 7.0)
166+
oil_plus.addComponent("propane", 5.0)
167+
oil_plus.addComponent("n-butane", 3.0)
168+
oil_plus.addComponent("n-pentane", 3.0)
169+
oil_plus.addComponent("n-hexane", 3.0)
168170

169171
# Add C7+ as plus fraction (32 mol%, MW=200 g/mol, density=800 kg/m³)
170172
oil_plus.addPlusFraction("C7+", 32.0, 0.200, 800.0)
@@ -213,8 +215,8 @@
213215
print("-" * 40)
214216

215217
original = fluid("srk")
216-
original.addComponent("methane", 90.0, "mol%")
217-
original.addComponent("ethane", 10.0, "mol%")
218+
original.addComponent("methane", 90.0)
219+
original.addComponent("ethane", 10.0)
218220
original.setMixingRule("classic")
219221
original.setTemperature(25.0, "C")
220222
original.setPressure(50.0, "bara")
@@ -243,17 +245,17 @@
243245

244246
# Stream 1: Lean gas
245247
stream1 = fluid("pr")
246-
stream1.addComponent("methane", 95.0, "mol%")
247-
stream1.addComponent("ethane", 5.0, "mol%")
248+
stream1.addComponent("methane", 95.0)
249+
stream1.addComponent("ethane", 5.0)
248250
stream1.setMixingRule("classic")
249251
stream1.setTotalFlowRate(1000.0, "mol/hr")
250252

251253
# Stream 2: Rich gas
252254
stream2 = fluid("pr")
253-
stream2.addComponent("methane", 70.0, "mol%")
254-
stream2.addComponent("ethane", 15.0, "mol%")
255-
stream2.addComponent("propane", 10.0, "mol%")
256-
stream2.addComponent("n-butane", 5.0, "mol%")
255+
stream2.addComponent("methane", 70.0)
256+
stream2.addComponent("ethane", 15.0)
257+
stream2.addComponent("propane", 10.0)
258+
stream2.addComponent("n-butane", 5.0)
257259
stream2.setMixingRule("classic")
258260
stream2.setTotalFlowRate(500.0, "mol/hr")
259261

@@ -295,9 +297,9 @@
295297
print("-" * 40)
296298

297299
brine = fluid("electrolyte")
298-
brine.addComponent("water", 1.0, "kg")
299-
brine.addComponent("Na+", 0.035, "mol") # Sodium ion
300-
brine.addComponent("Cl-", 0.035, "mol") # Chloride ion
300+
brine.addComponent("water", 1.0, "kg/hr")
301+
brine.addComponent("Na+", 0.035, "mol/sec") # Sodium ion
302+
brine.addComponent("Cl-", 0.035, "mol/sec") # Chloride ion
301303
brine.setMixingRule("classic")
302304

303305
print("Created brine with NaCl:")

0 commit comments

Comments
 (0)