from plotting import kin_dataplotter, plot_alpha_t0, dataplotter
from models.kineticgas import KineticGas
from pycThermopack.pyctp import cubic, cpa, pcsaft, extended_csp
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gs
import time
from models.kempers01 import Kempers01
from models.kempers89 import Kempers89
import sanity_check
import matplotlib.gridspec as gs
import pandas as pd
import warnings

mixtures = ['NC10,NC5', 'NC12,NC6', 'NC12,NC7', 'NC12,NC8']

for mix in mixtures:
    eos = cubic.cubic()
    eos.init(mix, 'VdW')
    for x in np.linspace(0.1,0.9,10):
        print(mix, x, eos.two_phase_tpflash(298,1e5, [x, 1-x]))



#print(eos.enthalpy(298,1e5,[0.3,0.7],1))
#print(eos.enthalpy(298,1e-5,[0.3,0.7],1))

plotter = dataplotter.DataPlotter('Kempers01', no_h0=True, mode='cov', exp=True, points=25)
plotter.cold_gases()

#plotter = kin_dataplotter.DataPlotter('Kempers01', points=25)
#plotter.cold_gases()

def plot_model():
    print('Plotting Model')
    eos = cpa.cpa()
    eos.init('ETOH,H2O')
    plotter = dataplotter.DataPlotter('Kempers01', mode='com', points=30)
    plotter.etoh_h2o_c(eos, 'SRK_CPA')

def plot_kinetic():
    print('Plotting Kinetic')
    eos = cpa.cpa()
    eos.init('ETOH,H2O')
    kin_plotter = kin_dataplotter.DataPlotter('Kempers01', kin=False, points=30, mode='com')
    kin_plotter.etoh_h2o_c(eos, 'kin')

def check_propanol_flash():
    eos = cpa.cpa()
    eos.init('H2O,PROP1OL', 'SRK')

    eos = cubic.cubic()
    eos.init('H2O,PROP1OL', 'SRK')

    x_line = np.linspace(0.01,0.99, 15)
    for x in x_line:
        print(x, eos.two_phase_tpflash(298, 1e5, [x, 1-x]))

def plot_all():
    t0 = time.process_time()
    warnings.filterwarnings('ignore')
    eos_keys = ['VdW', 'SRK', 'PR', 'PT', 'SW']
    for model, no_h0 in zip(['Kempers89'], [True]):
        for mode in ['com', 'cov']:
            print('Plotting for', model, ', mode=', mode, ', no_h0=', no_h0, sep='')
            plotter = dataplotter.DataPlotter(model, mode=mode, points=50, no_h0=no_h0)

            for key in eos_keys:
                print('plotting Toluene_hexane for', key)
                eos = cubic.cubic()
                eos.init('TOLU,NC6', key)
                plotter.toluene_n_hexane_T(eos, eos_name=key)
                plotter.toluene_n_hexane_c(eos, eos_name=key)

            print('Plotting CPA')
            eos = cpa.cpa()
            eos.init('ETOH,H2O', 'SRK')
            plotter.etoh_h2o_T(eos, eos_name='SRK_CPA')
            plotter.etoh_h2o_c(eos, eos_name='SRK_CPA')
            print('Plotting n-alkanes')
            plotter.n_alkanes()
            print('Plotting cold_gases')
            plotter.cold_gases()
            print('Plotting 298-files')
            plotter.plot_298()

            for key in eos_keys:
                print('Plotting ETOH_H2O for', key)
                eos = cubic.cubic()
                eos.init('ETOH,H2O', key)
                plotter.etoh_h2o_T(eos, eos_name=key, ylim=(-50,50))
                plotter.etoh_h2o_c(eos, eos_name=key, ylim=(-50,50))

            print('Plotting Propanol')
            plotter.propanol_h2o()

    t1 = time.process_time()
    print('All plots took', t1 - t0, 'seconds')
    print('Which is approx.', (t1 - t0)/60, 'minutes')
