B
    ยXฺ_ค  ใ               @   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                   sF   e Zd Zddgdddf fdd	Zdd Zdd
dZdddZ  ZS )ฺ	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   zWThis 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__ฉ ๚U/Users/vegardjervell/Documents/7_semester/irrev_prosjekt_renskriv/models/kempers89.pyr      s    	z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 )ZCompr   )ฺlocฺvaluesฺflatten)ฺ.0ฺcomp)ฺdatar   r   ๚
<listcomp>.   s    z5Kempers89.get_standard_enthalpies.<locals>.<listcomp>๚,)
ฺosฺpathฺdirnameฺ__file__ฺpdฺ
read_excelฺnpฺarrayr   ฺsplit)r   Z	file_pathr   )r   r   ฺget_standard_enthalpies'   s    z!Kempers89.get_standard_enthalpiesFc       
         sเ   |dkrt d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
        Tz&Kempers89 has no kinetic contribution!r   )ฺdvdn)ฺdhdng๑hใต๘ไ>้   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   I   s    z;Kempers89.get_soret_cov.<locals>.eq_set.<locals>.<listcomp>)r	   r'   ฺzerosฺrangeฺsum)ฺalphaฺeqs)r/   r0   ฺhr   r3   )r1   r2   r   ฺeq_setD   s    
(2z'Kempers89.get_soret_cov.<locals>.eq_setc             S   s   g | ]}d qS )r   r   )r   r2   r   r   r   r   O   s    z+Kempers89.get_soret_cov.<locals>.<listcomp>)ฺ
ValueErrorr   ฺset_tminฺspecific_volumer
   r   r	   r   ฺenthalpyr*   ฺdmudx_TPฺlenr   r5   )
r   ฺkinฺVฺHZH0ฺh0ฺH_molar_idealr:   r7   ฺsoretr   )r/   r0   r9   r   r3   r   ฺget_soret_cov0   s    ""

zKempers89.get_soret_covc                sุ   |dkrt d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
        Tz&Kempers89 has no kinetic contribution!c                s    g | ]} j   j  |กกqS r   )r   ฺcompmoleweightฺgetcompindex)r   r   )r   r   r   r   ]   s   z+Kempers89.get_soret_com.<locals>.<listcomp>r    )r,   g๑hใต๘ไ>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   r.   )ฺMr/   r0   r1   r2   r   r   r   m   s    z;Kempers89.get_soret_com.<locals>.eq_set.<locals>.<listcomp>)r	   r'   r4   r5   r6   )r7   r8   )rJ   r/   r0   r9   r   )r1   r2   r   r:   h   s    
(2z'Kempers89.get_soret_com.<locals>.eq_setc             S   s   g | ]}d qS )r   r   )r   r2   r   r   r   r   s   s    )r;   r'   r(   r   r)   ฺmole_weightsr   r>   r
   r   r	   r   r*   r?   r@   r   r5   )r   rA   ฺ_rD   rE   r:   r7   rF   r   )rJ   r/   r0   r9   r   r   ฺget_soret_comT   s    "

zKempers89.get_soret_com)F)F)ฺ__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   