<jupyter_start><jupyter_text>Square Gradient Theory for MixturesThis notebook has te purpose of showing examples of computing interfacial tension of mixtures and beta != 0.First it's needed to import the necessary modules<jupyter_code>import numpy as np
from phasepy import component, mixture, prsveos
from phasepy.equilibrium import bubblePy
from phasepy.sgt import sgt_mix, msgt_mix
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Then the mixture and EoS are created. The bubble point of the mixture of x1 = 0.3 at 320K is computed. The ```full_output``` option allows to obtain the compositions, densities and equilibrium pressure.<jupyter_code>hexane = component(name = 'n-Hexane', Tc = 507.6, Pc = 30.25, Zc = 0.266, Vc = 371.0, w = 0.301261, 
                ksv = [ 0.81185833, -0.08790848],
                cii = [ 5.03377433e-24, -3.41297789e-21,  9.97008208e-19],
                GC = {'CH3':2, 'CH2':4})

ethanol = component(name = 'Ethanol', Tc = 514.0, Pc = 61.37, Zc = 0.241, Vc = 168.0, w = 0.643558,
                ksv = [1.27092923, 0.0440421 ],
                cii = [ 2.35206942e-24, -1.32498074e-21,  2.31193555e-19],
                GC = {'CH3':1, 'CH2':1, 'OH(P)':1})

mix = mixture(ethanol, hexane)

a12, a21 = np.array([1141.56994427,  125.25729314])
A = np.array([[0, a12], [a21, 0]])
mix.wilson(A)

eos = prsveos(mix, 'mhv_wilson')

T = 320 #K
X = np.array([0.3, 0.7])
P0 = 0.3 #bar
Y0 = np.array([0.7, 0.3])

sol = bubblePy(Y0, P0, X, T, eos, full_output = True)
Y = sol.Y
P = sol.P
vl = sol.v1
vv = sol.v2

#computing the density vector
rhol = X / vl
rhov = Y / vv<jupyter_output><empty_output><jupyter_text>In order to set the beta correction is necessary to create the matrix and then use it with the  ```beta_sgt``` method from the eos. If this step is not done the ```sgt_mix``` or ```msgt_sgt``` function will raise an error as the influence parameter matrix will be singular.<jupyter_code>bij = 0.1
beta = np.array([[0, bij], [bij, 0]])
eos.beta_sgt(beta)<jupyter_output><empty_output><jupyter_text>The first possibility is to solve the BVP iteratively using ortoghonal collocation. The initial interfacial lenght is set to 10 Amstrong and the density profiles are solved, then the interfacial lenght is increased until the calculated interfacial tension doesnt change more than a given tolerance.The initial value can be set as ```'linear'``` or ```'hyperbolic'``` to use a linear or a hyperbolic approximation. Optionally a array can be passed to the argument ```rho0``` or a TensionResult for another calculation, as for example, the density profile computed with beta0 calculation.<jupyter_code>sol = sgt_mix(rhol, rhov, T, P, eos, z0 = 10,  rho0 = 'linear', full_output = True)
sol.tension
sol.rho
sol.z
sol.GPT<jupyter_output><empty_output><jupyter_text>The other option is to used a modified SGT system which includes a temporal variable which help to reach the stationary density profile ignoring the non linearity of the BVP at the first iterations. This type of computation use a fixed value for the interfacial lenght.The initial value options to solve the density profiles are the same as for ```sgt_mix```. In this case the previously computed TensionResult is used as an initial guess.<jupyter_code>solm = msgt_mix(rhol, rhov, T, P, eos, z = 20, rho0 = sol, full_output = True)
solm.tension
print('BVP SGT : ', sol.tension, 'mN/m')
print('Modified BVP SGT : ', solm.tension, 'mN/m')<jupyter_output>BVP SGT :  14.367813285943496 mN/m
Modified BVP SGT :  14.367828523644494 mN/m<jupyter_text>Finally the density profiles can be compared. It can be seen that when a correction to the cross influence parameter just one stationary point across the interface.<jupyter_code>#conver densitites to kmol/m3
rho = sol.rho * 1000
rhom = solm.rho * 1000 

fig = plt.figure(figsize = (5,5))
ax = fig.add_subplot(111)
ax.plot(rho[0], rho[1], '--')
ax.plot(rhom[0], rhom[1], '.')
ax.set_xlabel(r'$\rho_1$ / kmol m$^{-3}$ ')
ax.set_ylabel(r'$\rho_2$ / kmol m$^{-3}$ ')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1177629958117763, 'fraction_numerical': 0.07046070460704607, 'mean_word_length': 4.2387096774193544, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '537685', 'license': 'MIT', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1429, 'n_words': 488, 'path': 'examples/SGT for mixtures and beta != 0.ipynb', 'repo_name': 'tkeskita/phasepy', 'size': '4059'}