<jupyter_start><jupyter_text>Separator Calculations<jupyter_code>import pandas as pd
import numpy as np
from pvtpy.compositional import Chromatography, Component, properties_df
from pvtpy.units import Pressure, Temperature
properties_df.index
d1 = {
    'comp': ['carbon-dioxide','nitrogen','methane','ethane','propane','isobutane','butane','isopentane','pentane','n-hexane'],
    'mole_fraction':[0.0008,0.0164,0.2840,0.0716,0.1048,0.042,0.042,0.0191,0.01912,0.0405]
}

c7_plus = Component(
    name = 'C7+', 
    molecular_weight=252,
    specific_gravity = 0.8429,
    mole_fraction=0.3597,   
    critical_pressure=140,
    critical_pressure_unit='psi',
    critical_temperature=1279.8,
    critical_temperature_unit='rankine',
    params = {'acentric_factor':0.5067}
)

ch1 = Chromatography()
ch1.from_df(pd.DataFrame(d1),name='comp')
ch1.plus_fraction = c7_plus

ch1.df()['mole_fraction']
ma = ch1.apparent_molecular_weight()
print(f'Aparent Molecular weight {ma}')
rho = 44.794<jupyter_output><empty_output><jupyter_text>Stage 1<jupyter_code>p1 = Pressure(value=400, unit='psi')
t1 = Temperature(value=72, unit='farenheit')

ch1.equilibrium_ratios(p1,t1,method='whitson')
fsh1, phase1 = ch1.flash_calculations(p1,t1)
fsh1.index.name = 'component'
print(fsh1)
print(fsh1[['xi','yi']].sum())
moles_stage1 = ch1.phase_moles(p1,t1)
moles_stage1<jupyter_output><empty_output><jupyter_text>Stage 2<jupyter_code>p2 = Pressure(value=350, unit='psi')
t2 = Temperature(value=72, unit='farenheit')
ch2 = Chromatography()
ch2.from_df(fsh1, mole_fraction='xi')

c7_plus1 = Component(
    name = 'C7+', 
    molecular_weight=252,
    specific_gravity = 0.8429,
    mole_fraction=fsh1.loc['C7+','xi'],   
    critical_pressure=140,
    critical_pressure_unit='psi',
    critical_temperature=1279.8,
    critical_temperature_unit='rankine',
    params = {'acentric_factor':0.5067}
)
ch2.plus_fraction = c7_plus1


ch2.df()['mole_fraction']
moles_stage2 = ch2.phase_moles(p2,t2)
moles_stage2
fsh2, phase2 = ch2.flash_calculations(p2,t2)
fsh2.index.name = 'component'
print(fsh2)
print(fsh2[['xi','yi']].sum())<jupyter_output>mole_fraction        xi        yi          k
component                                                   
carbon-dioxide       0.000592  0.000580  0.001458   2.512167
nitrogen             0.001713  0.001191  0.041154  34.548143
methane              0.069850  0.060335  0.789504  13.085251
ethane               0.063289  0.062753  0.103813   1.654311
propane              0.130747  0.131831  0.048744   0.369743
isobutane            0.056641  0.057287  0.007785   0.135895
butane               0.057502  0.058191  0.005391   0.092649
isopentane           0.026688  0.027029  0.000952   0.035219
pentane              0.026801  0.027145  0.000718   0.026438
n-hexane             0.057142  0.057892  0.000479   0.008281
C7+                  0.509035  0.515766  0.000002   0.000005
xi    1.0
yi    1.0
dtype: float64<jupyter_text>Stage 3<jupyter_code>p3 = Pressure(value=14.7, unit='psi')
t3 = Temperature(value=60, unit='farenheit')
ch3 = Chromatography()
ch3.from_df(fsh2.reset_index(),name = fsh2.index.name, mole_fraction='xi')

c7_plus3 = Component(
    name = 'C7+', 
    molecular_weight=252,
    specific_gravity = 0.8429,
    mole_fraction=fsh2.loc['C7+','xi'],   
    critical_pressure=140,
    critical_pressure_unit='psi',
    critical_temperature=1279.8,
    critical_temperature_unit='rankine',
    params = {'acentric_factor':0.5067}
)
ch3.plus_fraction = c7_plus3


ch3.df()['mole_fraction']
moles_stage3 = ch3.phase_moles(p3,t3)
moles_stage3
fsh3, phase3 = ch3.flash_calculations(p3,t3)
fsh3.index.name = 'component'
print(fsh3)
print(fsh3[['xi','yi']].sum())
moles_stages = [moles_stage1,moles_stage2,moles_stage3]

nl = 1
for i in moles_stages:
    nl *= i['liquid_moles']
    
nv = 1 - nl 

print(f'liquid Moles Stock Tank {nl}\nLiberated Gas Moles {nv}')
ch4 = Chromatography()
ch4.from_df(fsh3.reset_index(),name = fsh3.index.name, mole_fraction='xi')

c7_plus4 = Component(
    name = 'C7+', 
    molecular_weight=252,
    specific_gravity = 0.8429,
    mole_fraction=fsh3.loc['C7+','xi'],   
    critical_pressure=140,
    critical_pressure_unit='psi',
    critical_temperature=1279.8,
    critical_temperature_unit='rankine',
    params = {'acentric_factor':0.5067}
)
ch4.plus_fraction = c7_plus4


ch4.df()['mole_fraction']
ch4.apparent_molecular_weight()
## Separator Functions
from pvtpy.compositional import Stage, SeparatorTest

stage1 = Stage(
    pressure=p1,
    temperature = t1
)

stage2 = Stage(
    pressure=p2,
    temperature = t2
)

stage3 = Stage(
    pressure=p3,
    temperature = t3
)

list_stages = [stage1, stage2, stage3]

sep = SeparatorTest(
    initial_chromatography = ch1,
    stages = list_stages
)

sep.solve()
sep.stages[-1].phase_moles<jupyter_output><empty_output><jupyter_text>Calculate apparent molecular weight of the stock-tank oil from its composition, togive<jupyter_code>sep.stages[-1].chromatography.apparent_molecular_weight()<jupyter_output><empty_output><jupyter_text>Calculate the actual number of moles of the liquid phase at the stock-tank condi-tionsCalculate the total number of moles of the liberated gas<jupyter_code>sep.final_moles()
sep.final_molecular_weight()
rho = 50.920
sep.gas_solubility(rho=50.920)
sep.volumetric_factor(44.794,50.920)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12931517074080986, 'fraction_numerical': 0.11476021645829446, 'mean_word_length': 4.229268292682927, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '321454', 'license': 'MIT', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2097, 'n_words': 326, 'path': 'docs/examples/3-chromatography/3c-Separators.ipynb', 'repo_name': 'scuervo91/pvtpy', 'size': '5359'}