<jupyter_start><jupyter_text><jupyter_code>#@title Calculation of solubility of gases in water
#@markdown This notebook gives demonsitrations of soubility calculations in water
#@markdown <br><br>This document is part of the module ["Introduction to Gas Processing using NeqSim in Colab"](https://colab.research.google.com/github/EvenSol/NeqSim-Colab/blob/master/notebooks/examples_of_NeqSim_in_Colab.ipynb#scrollTo=_eRtkQnHpL70).
%%capture
!pip install --upgrade -q gspread
!pip install neqsim
import neqsim
from neqsim.thermo.thermoTools import *
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import math
%matplotlib inline
#@title Solubility of gases in water
#@markdown This video gives an intriduction to behavour of gases as function of pressure and temperature
from IPython.display import YouTubeVideo
YouTubeVideo('OCD4Dr3kmmA', width=600, height=400)<jupyter_output><empty_output><jupyter_text>Calcultion of solubility of gases in pure waterIn the following example we calculate gas solubility in pure water as function of pressure and temperature<jupyter_code>componentName = "methane" #@param ["methane", "ethane", "propane", "CO2", "nitrogen", "oxygen"]
temperature = 45.0   #@param {type:"number"}
minPressure = 1.0  #@param {type:"number"}
maxPressure = 150.0  #@param {type:"number"}
eosname = "CPA-SRK-EoS" #@param ["srk", "pr", "CPA-SRK-EoS"]
R = 8.314 # J/mol/K

# Creating a fluid in neqsim
fluid1 = fluid(eosname) #create a fluid using the SRK-EoS
fluid1.addComponent(componentName, 1.0) #adding 1 mole to the fluid
fluid1.addComponent("water", 1.0) #adding 1 mole to the fluid
fluid1.init(0);
fluid1.autoSelectMixingRule();

def gassol(pressure, temperature):
    fluid1.setPressure(pressure)
    fluid1.setTemperature(temperature+273.15)
    TPflash(fluid1)
    return fluid1.getPhase('aqueous').getComponent(componentName).getNumberOfMolesInPhase()/(fluid1.getPhase('aqueous').getComponent("water").getNumberOfMolesInPhase()*fluid1.getPhase('aqueous').getComponent("water").getMolarMass())

pressure = np.arange(minPressure, maxPressure, int((maxPressure-minPressure)/10.0)+1.0)
gassolubuility = [gassol(P,temperature) for P in pressure]

plt.plot(pressure, gassolubuility)
plt.xlabel('Pressure [bar]')
plt.ylabel('mole fraction [mol/kg water]')<jupyter_output><empty_output><jupyter_text>Calcultion of solubility of gases in salt waterIn the following example we calculate gas solubility in pure water as function of pressure and temperature. Sea water will contain salts in various amounts.<jupyter_code>temperature = 45.0   #@param {type:"number"}
minPressure = 1.0  #@param {type:"number"}
maxPressure = 150.0  #@param {type:"number"}
componentName = "methane" #@param ["methane", "ethane", "propane", "CO2", "nitrogen"]
ion1 = "Na+" #@param ["Na+", "Ca++"]
grperkgIon1 = 10.0 #@param {type:"number"}
ion2 = "Cl-" #@param ["Cl-", "CO3--"]
grperkgIon2 = 10.0 #@param {type:"number"}
eosname = "Electrolyte-CPA-EoS" #@param ["Electrolyte-CPA-EoS","Electrolyte-ScRK-EoS"]
R = 8.314 # J/mol/K

# Creating a fluid in neqsim
fluid1 = fluid(eosname) #create a fluid using the SRK-EoS
fluid1.addComponent(componentName, 1.0, 'kg/sec') #adding 100 mole to the fluid
fluid1.addComponent("water", 1.0, 'kg/sec') #adding 1 mole to the fluid
fluid1.addComponent(ion1, grperkgIon1/1000.0, 'kg/sec') #adding 1 mole to the fluiuidd
fluid1.addComponent(ion2, grperkgIon2/1000.0, 'kg/sec') #adding 1 mole to the fl
fluid1.autoSelectMixingRule();
#fluid1.setMultiPhaseCheck(True)

def gassol(pressure, temperature):
    fluid1.setPressure(pressure)
    fluid1.setTemperature(temperature+273.15)
    TPflash(fluid1)
    return fluid1.getPhase('aqueous').getComponent(componentName).getNumberOfMolesInPhase()/(fluid1.getPhase('aqueous').getComponent("water").getNumberOfMolesInPhase()*fluid1.getPhase('aqueous').getComponent("water").getMolarMass())

pressure = np.arange(minPressure, maxPressure, int((maxPressure-minPressure)/10.0)+1.0)
gassolubuility = [gassol(P,temperature) for P in pressure]

plt.plot(pressure, gassolubuility)
plt.xlabel('Pressure [bara]')
plt.ylabel('mole fraction [mol/kg water]')<jupyter_output><empty_output><jupyter_text>Calculation of Henrys Constant of gases in solvents<jupyter_code>temperature = 25.0   #@param {type:"number"}
pressure = 1.0  #@param {type:"number"}

# Creating a fluid in neqsim
fluid1 = fluid("Electrolyte-CPA-EoS")
fluid1.addComponent("CO2", 11.0, "kg/sec") 
fluid1.addComponent("MEG", 0.5, "kg/sec")
fluid1.addComponent("MDEA", 100.0, "kg/sec")

fluid1.setMixingRule(10)
fluid1.setMultiPhaseCheck(True)
fluid1.setTemperature(temperature, "C")
fluid1.setPressure(pressure, "bara")

TPflash(fluid1)

print("Henrys constant CO2 ", fluid1.getPhase("gas").getComponent("CO2").getx()*pressure/fluid1.getPhase("aqueous").getComponent("CO2").getx(), "bar")

printFrame(fluid1)<jupyter_output>Henrys constant CO2  1111.5060563481486 bar
                     0           1                            2                            3 4 5                6
0                            total                          gas                      aqueous                     
1                  CO2  2.27804E-1                    9.9999E-1                   8.99671E-4      [mole fraction]
2                  MEG  7.34202E-3                   1.94167E-6                   9.49889E-3      [mole fraction]
3                 MDEA  7.64854E-1                   8.14394E-6                   9.89601E-1      [mole fraction]
4                                                                                                                
5              Density                                 1.7842E0                    1.02021E3             [kg/m^3]
6        PhaseFraction                               2.27111E-1                   7.72889E-1      [mole fraction]
7            MolarMass   1.01624E2          [...]
{'fraction_non_alphanumeric': 0.12346730245231607, 'fraction_numerical': 0.04887602179836512, 'mean_word_length': 3.3439349112426036, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '358318', 'license': 'Apache-2.0', 'n_tokens_mistral': 2169, 'n_tokens_neox': 1918, 'n_words': 446, 'path': 'notebooks/thermodynamics/solubility_of_gases_in_water.ipynb', 'repo_name': 'EvenSol/testneqsim', 'size': '5872'}