import numpy as np
from computational_thermodynamics import equilibrium


# Physical parameters
T = 360 #K
P = 2 * 0.101325 #MPa

# The feed composition consists of A, B, C, D, and I (an inert). In this example, 
# all components are present in equal amounts in the feed
z = np.array([0.2, 0.2, 0.2, 0.2, 0.2]) 


#Load the equilibria module
Equi = equilibrium.Equilibria()


#Run calculation
(lagrange, nt, x) = Equi.optimize_equilibrium(T,P,z)

# lagrange (numpy.ndarray) - Lagrange multipliers (see pdf document)
# nt (float) - Total number of moles at equilibrium
# x (numpy.ndarray) -  Mole fractions of all 15 components


#Display results
print("Lagrange multipliers:")
print(lagrange)
print("\n\nnt = " + str(nt) + " moles\n\n")
print("Mole fractions\n")
compounds = ["A","B","C","D","I","A2","AB","AC","AD","B2","BC","BD","C2","CD","D2"]
print ("{:<10} {:<15}".format("Compound", "Mole Fraction"))
print("---------------------------------------")
for i in range(0,np.size(x)):
    print ("{:<10} {:<15}".format(compounds[i], x[i]))
    
print ("{:<10} {:<15}".format("Sum", np.sum(x)))