# Import packages here:

import math as m
import numpy as np
from IPython.display import Image
import matplotlib.pyplot as plt

# Properties of Materials (engineeringtoolbox.com, Cengel, Tian)

# Conductivity
Kair = 0.026  # w/mk
Kptfe = 0.25  # w/mk
Kcf = 0.8  # transverse conductivity 0.5 -0.8 w/mk

# Fluid Properties

rhoLox = 1141  # kg/m^3
TLox = -183  # *C

# Latent Heat of Evaporation
heOxy = 214000  # j/kg


# Layer Dimensions:

r1 = 0.0381  # meters (1.5")
r2 = 0.0396  # m
r3 = 0.0399  # m
r4 = 0.0446  # m
r5 = 0.0449  # m
L = 0.13081  # meters (5.15")

# Environmental Properties:

Ts = 38  # *C
T1 = -183  #*C

"""
Explanation: Heat and Mass Transfer Analysis of Liquid Oxygen Boil-Off due to Conduction through Composite Layers.
Objective:
Determine a rough estimate of the time it takes for a 3" diameter 5.15" long cylinder of liquid oxygen to boil off on a hot summer day in Brothers, OR (T~38C).
Assumptions:


The temperature of the outermost carbon fiber layer is equal to the ambient air temperature ($T_s = T_{inf}$).


The temperature of the innermost (PTFE) layer is equal to the liquid oxygen (LOX) temperature ($T_1 = T_{lox}$).


The Nomex Honecomb layer is considered to be composed of mostly air.


Convection and radiation effects are neglected.


Material properties are constant.
End of explanation
"""


Rptfe = m.log(r2/r1)/(2*m.pi*L*Kptfe)
Rcf1 = m.log(r3/r2)/(2*m.pi*L*Kcf)
Rair = m.log(r4/r3)/(2*m.pi*L*Kair)
Rcf2 = m.log(r5/r4)/(2*m.pi*L*Kcf)

Rtot = Rptfe + Rcf1 + Rair + Rcf2 

print('Total Thermal Resistance equals: ', "%.2f" % Rtot, 'K/W')

#Heat transfer rate: 
Qrate = (Ts - T1)/Rtot

print('Calculated Heat Transfer rate equals: ',"%.2f" % Qrate, 'W')

"""
Explanation: Heat Transfer Rate
The following analysis was performed using steady heat conduction analysis of multilayered cylinders (Cengel, pg 156). The heat transfer rate is given by:
$$\dot{Q} = \frac{T_s -T_1}{R_{total}}$$
where $R_{total}$ is the total thermal resistance expressed as:
$$R_{total} = R_{PTFE} + R_{CF1} + R_{Air}+ R_{CF2}$$
where: 
$$R_{material} = (\frac{ln(r_{outer} / r_{inner})}{2\piL*K_{material}})$$
End of explanation
"""


EvapRate = Qrate/heOxy
print ('The rate of evaporation is', "%.6f" % EvapRate, 'kg/s')

"""
Explanation: Evaporation Rate
The energy balance on a thin layer of liquid at the surface is expressed by: (Cengel, pg. 841)
$$\dot{Q}{transferred} = \dot{Q}{latent, absorbed}$$ or  $$\dot{Q} = \dot{m}v*h{e, oxygen}$$
where $\dot{m}_v$ is the rate of evaportation. Solving for $\dot{m}_v$ gives us:
$$\dot{m}v = \frac{\dot{Q}}{h{e, oxygen}}$$
End of explanation
"""


VLox = m.pi*(r1)**2*L
mLox = rhoLox*VLox
print('The mass of the liquid oxygen in tank is: ', "%.2f" % mLox, 'kg')

"""
Explanation: Time for total Evaporation
The mass of liquid oxygen is given by: $$m = \rho_{LOX}V$$ where $$V = \pir1^2*L$$
End of explanation
"""


Tboiloff = mLox/EvapRate/60
print('%.2f' % Tboiloff, 'minutes' )

"""
Explanation: Finally, the amount of time that it takes for all 0.68kg of LOX to boil off is:
End of explanation
"""


