B
    R_Z                 @   sd   d Z ddlmZmZmZ ddlmZ ddlZddl	m
Z
 ddlZddlZddlZG dd deZdS )a  
Author: Vegard G. Jervell
Date: December 2020
Purpose: Implementation of L. J. T. M. KempersXX' model for prediction of Soret-coefficients in multicomponent
        liquid mixtures, derived in "A thermodynamic theory of the Soret effect in a multicomponent liquid",
        Journal of Chemical Physics, 1989.
        doi : http://dx.doi.org/10.1063/1.456321
Requires: numpy, scipy, pandas, ThermoPack
Note: pandas is used to get ideal-gas state enthalpies from the file 'ideal_gas_enthalpies.xlsx'. It should
    be possible to aquire these from ThermoPack, thereby removing the need for a separate data-file of
    standard-state enthalpies.
    )cubiccpa
lee_kesler)KempersN)rootc                   sB   e Zd Zddgdddf fdd	Zdd Zd	d
 Zdd Z  ZS )Mod_Kempers89g      ?i,  g     j@   c          
      sZ   t  j||||||d | j| j| j| jdkrVtd|	|| j| j| j  dS )a  
        :param comps (str): Comma separated list of components, as per ThermoPack convention
        :param x (array-like): list of component mole fractions
        :param eos (ThermoPack): Initialized equation of state, with same components as Kempers
        :param temp (float): Temperature [K]
        :param pres (float): Pressure [Pa]
        :param phase (int): Phase identifier to be used by ThermoPack
        )xtemppresphaser   zXThis model may work poorly for phases other than liquid,
 ThermoPack predicted phase is N)
super__init__eosguess_phaser
   r   r	   warningswarnget_phase_type)selfcompsr   r	   r
   r   r   )	__class__ Y/Users/vegardjervell/Documents/7_semester/irrev_prosjekt_renskriv/models/modKempers89_.pyr      s    	zMod_Kempers89.__init__c                s:   t jt}t|d  t fdd| j	dD S )z
        Get ideal-gas standard state enthalpies from 'ideal_gas_enthalpies.xlsx'
        :return: 1darray: standard state enthalpies of components
        z/ideal_gas_enthalpies.xlsxc                s(   g | ] } j  d  |k j d qS )Compr   )locvaluesflatten).0comp)datar   r   
<listcomp>.   s    z9Mod_Kempers89.get_standard_enthalpies.<locals>.<listcomp>,)
ospathdirname__file__pd
read_excelnparrayr   split)r   	file_pathr   )r   r   get_standard_enthalpies'   s    z%Mod_Kempers89.get_standard_enthalpiesc                s   j d j jjjjjdd\}j jjjjjdd\}j jjdjddd\}}|  t	j  fdd}t
|d	d
 t D j}|j }|S )zw
        Get soret coefficients at current settings
        :return: 1darray: soret coefficients of components
        r   T)dvdn)dhdngh㈵>   c                s   | j  dj     t}xltdd D ]Z   d  d     t fddtdd D  |< q0W t| |d < |S )Nr   r   c                sD   g | ]<}|f    d  |f  d     |  qS )r   r   )r   j)NdmudxdxdTivr   r   r    F   s    z?Mod_Kempers89.get_soret_cov.<locals>.eq_set.<locals>.<listcomp>)r	   r(   zerosrangesum)alphaeqs)r1   r2   hr   r5   )r3   r4   r   eq_setA   s    
(2z+Mod_Kempers89.get_soret_cov.<locals>.eq_setc             S   s   g | ]}d qS )r   r   )r   r4   r   r   r   r    L   s    z/Mod_Kempers89.get_soret_cov.<locals>.<listcomp>)r   set_tminspecific_volumer
   r   r	   r   enthalpydmudx_TPlenr   r7   )r   VHH0h0r<   r9   soretr   )r1   r2   r;   r   r5   r   get_soret_cov0   s    ""

zMod_Kempers89.get_soret_covc                s   t fddjdD   _jjjjj	j
dd\}jjjdj	ddd\}}|  tj	 fdd	}t|d
d tD j	}|j }|S )zw
        Get soret coefficients at current settings
        :return: 1darray: soret coefficients of components
        c                s    g | ]} j  j |qS r   )r   compmoleweightgetcompindex)r   r   )r   r   r   r    V   s   z/Mod_Kempers89.get_soret_com.<locals>.<listcomp>r!   T)r.   gh㈵>r/   c                s   | j  dj     t}xltdd D ]Z   d  d     t fddtdd D  |< q0W t| |d < |S )Nr   r   c                sD   g | ]<}|f    d  |f  d     |  qS )r   r   )r   r0   )Mr1   r2   r3   r4   r   r   r    g   s    z?Mod_Kempers89.get_soret_com.<locals>.eq_set.<locals>.<listcomp>)r	   r(   r6   r7   r8   )r9   r:   )rJ   r1   r2   r;   r   )r3   r4   r   r<   b   s    
(2z+Mod_Kempers89.get_soret_com.<locals>.eq_setc             S   s   g | ]}d qS )r   r   )r   r4   r   r   r   r    m   s    )r(   r)   r   r*   mole_weightsr   r?   r
   r   r	   r   r@   rA   r   r7   )r   _rE   r<   r9   rF   r   )rJ   r1   r2   r;   r   r   get_soret_comQ   s    "

zMod_Kempers89.get_soret_com)__name__
__module____qualname__r   r,   rG   rM   __classcell__r   r   )r   r   r      s   	!r   )__doc__pycThermopack.pyctpr   r   r   models.kempersr   numpyr(   scipy.optimizer   pandasr&   r   r"   r   r   r   r   r   <module>   s   