# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ### Past Exam Question
#
# The level of toluene (a flammable and volatile hydrocarbon) in a storage tank may fluctuate between h=10 cm and h=400 cm from the topof the tank. Since it is difficultto see inside the tank, an open-end manometer witheither water ormercury as the manometer fluid is to be used to determine the toluene levelin the tank. One leg of the manometer is attached to the tankat Y=500 cm from the top. Air at atmospheric pressure is maintained over the tank contents. Consider a case when the toluene level in the tank is 150 cm below the top(h=150cm).  In this case,the manometer fluid level in the open arm is at the height of the point where the manometer connects to the tank. 

# ![problem%201.png](attachment:problem%201.png)

# #### Constants:
#
# Gravitational constant is 9.81 m/s^2
#
# Density of toluene is 0.866 g/cm3
#
# Density of water is 1 g/cm3
#
# Density of mercury is 13.6 g/cm3

# a) What manometer reading,R(cm), would be observed if the manometer fluid is mercury? 
#
# b) If the manometer fluid is water instead of mercury, what would be the value of R (cm)? 
#
# c) Based on your answer in part (a) and (b), which manometer fluid should be used, and why? Your answer should not exceed 3 sentences. 

# ### Solution:
#
# a)
#
# 1. Identify that the hydrostatic pressure at the level of the toluene-mercury interface is the same.
# $$P_{t} = P_{m}$$
# 2. Write out the equation for both $P_{t}$ and $P_{m}$ by following the general formula $p = \rho gh$.
#
# $$P_{t} = \rho_{t}g(Y-h+R)$$
#
# $$P_{t} = \rho_{m}gR$$
#
# $$\rho_{m}gR = \rho_{t}g(Y-h+R)$$
#
# $$R = \frac{y-h}{\frac{\rho_{m}}{\rho{t}}-1}$$
#
# 3. Solve for R

Y = 500
h = 150
rho_t = 0.866
rho_m = 13.6
R = (Y-h)/((rho_m/rho_t)-1)
R

# b) Similar procedure as part a) except replace mecury with water.

rho_w = 1
R = (Y-h)/((rho_w/rho_t)-1)
R

# c) Mecury should be used since the height if using water would be 2.261m which would overflow the tube. 

# ### Mass Balance Question
#
# Consider an ammonia absorption column. An inlet gas stream (O) composed of Ammonia (NH3) andN2is fed to the bottom at a total mass flow rate $F_{O}= 1000 kg/hr$.  The massfraction of NH3 in the inlet gas stream is $w_{AO}$, which corresponds to ammoniamole fraction of $x_{AO}=0.13$. The inlet gas stream flows upward in the column in continuous contact with a liquid stream flowing down the column.  Pure liquid solvent(S)is fed to the top of the column at $F_{S}=1000 kg/hr$, absorbing ammoniafrom the gas stream.  Theoutletliquid stream(L)withdrawn at the base of the columnis the solventcontainingdissolvedammonia(at a massfraction of wAL),but no N2.  The outlet gas stream (G) emerging from the top containsresidual NH3(at a mass faction of $w_{AG}$) in mixture with N2. 
#
# The massfractions  of  NH3in  the  exiting  gas  and  liquid  streamsare  related bythe  following empirical formula: $w_{AG}= 2w_{AL}$. 
#
# The molecular weight of Ammonia (NH3) is $MW_{A}=17 g/mol$ and N2 is $MW_{N}= 28 g/mol$.

# a) Complete the process flow diagram using thetemplate in thenext page. Toearn full  points,  you must  identify  each  process  stream bylabelingeachwith the appropriate mass flow rate ($F_{O}$, $F_{G}$, $F_{S}$, $F_{L}$). Please also indicate the ammonia mole fraction inthe inlet gas stream ($x_{AO}$) and the ammonia mass fractions in the remaining streams ($w_{AG}$, $w_{AS}$, $w_{AL}$).You must alsoindicate known quantities (HINT: there are two known quantities for mass flow rate and two for ammonia composition)
#
# b) Perform a degrees of freedom analysis.
#
# c) Determine the mass fraction of ammonia in the inlet gas stream ($w_{AO}$).  To help with the conversion, you may consider a total amount basis of $n_{TO}$=100 mol in theinlet gas (where nAOand nNOare  moles  of  ammonia  and  nitrogen  gas  in  the  inlet  gas, respectively)to determine the corresponding total mass $m_{TO} = m_{AO}+ m_{NO}$ of the inlet gas.  
#
# d) Write down the total mass balance and the species mass balancesin terms of mass flow rates ($F_{O}$, $F_{G}$, $F_{S}$, $F_{L}$)and ammonia mass fractions($w_{AO}$, $w_{AG}$, $w_{AS}$, $w_{AL}$).  Use symbols only, do not substitute values.
#
# e) Calculate  the  flow  rates  (kg/hr)  and  compositions  (in  massfractions)  of  the exiting gas and liquid streams.

# ### Solutions
#
# a)
#
# ![problem%202.png](attachment:problem%202.png)

# b) Degree of Freedom Analysis
#
# $$Unknowns = 4$$
#
# $$Specie Balance = 3$$
#
# $$Ratio = 1$$
#
# $$DOF = 4-3-1 = 0$$

# c) 
#
# 1. Assume basis of 100 moles of inlet gas
#
# $$n_{TI} = 100 mol$$
#
# 2. Calculate mole of each specie using mole fraction and then calculating the mass of of each specie using molecular weight.
#
# For each specie i, the mole is equal to its mole fraction to the total mole amount.
# $$n_{iO} = x_{iO}n_{TO}$$
#
# $$m_{iO} = n_{iO}MW_{i}$$
#
# where i is ammonia or N2 in this the context of this problem
#
# 3. Calculate mass fraction of ammonia in relation to basis assumed
#
# $$m_{TO} = \sum_{i=0}^{n} m_{iO} $$
# $$w_{iO} = m_{iO}/m_{TO}$$

n_TO = 100
x_AO = 0.13
x_NO = 1-x_AO
MW_A = 17
MW_N = 28
n_AO = x_AO*n_TO
n_NO = x_NO*n_TO
m_AO = n_AO*MW_A
m_NO = n_NO*MW_N
print(m_AO,m_NO)
m_TO = m_AO+m_NO
w_AO = m_AO/m_TO
print(w_AO)

# d) 
#
# Overall balance:  $F_{O}+F_{S}= F_{G}+ F_{L}$
#
# NH3 balance: $w_{AO}F_{O}+ w_{AS}F_{S} = w_{AG}F_{G}+ w_{AL}F_{L}$
#
# Solventbalance: $F_{S}= (1-w_{AL})F_{L}$
#
# N2 balance: $(1-w_{AO}) F_{O}= (1-w_{AG})F_{G}$

# e)
#
# 1. Write out balance for each specie.
#
# Ammonia balance: 
#
# $$w_{AO}F_{O}=2w_{AL}(2F_{O}–F_{L})+ w_{AL}F_{L}$$
#
# $$w_{AO}F_{O}= w_{AL}(4F_{O}–F_{L}) $$
#
# We call this equation 1.
#
# Solvent balance:
# $$F_{S}= F_{O}= (1-w_{AL})F_{L}$$
#
# $$F_{L}= \frac{F_{O}}{1-w_{AL}}$$
#
# We call this equation 2.
#
# 2. Write out equation in terms of $w_{AL}$ only.
#
# substitute 2 into 1
#
# $$w_{AO}F_{O}= w_{AL}\left(4F_{O}–\frac{F_{O}}{(1-w_{AL})}\right)$$
#
# $$w_{AL}^{2}4F_{O} –(w_{AO}F_{O}+4F_{O} -w_{AL}F_{O}) w_{AL}+ w_{AO}F_{O}= 0$$
#
# $$4000 w_{AL}^{2}–3083w_{AL}+ 83= 0$$

# +
# Solve the quadratic equation ax**2 + bx + c = 0
import cmath

a = 4000
b = -3083
c = 83

# calculate the discriminant
d = (b**2) - (4*a*c)

# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)

print('The solution are {0} and {1}'.format(sol1,sol2))
# -

# Choose $w_{AL} = 0.0279$ since the other value does not make sense as $w_{AG}= 2w_{AL} > 1$
#
# Solve for the rest of the variables

StarcoderdataJupyterScriptsDedupFiltered