U
    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__ R/home/ubuntu/Home/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 )w
        Get soret coefficients at current settings
        :return: 1darray: soret coefficients of components
        T&Kempers89 has no kinetic contribution!r   )dvdndhdnh㈵>   c                    s   | j  dj     t}tdd D ]Z   d  d     t fddtdd D  |< q.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r8   r9   hr   r<   r:   r;   r   eq_setD   s    
(&
z'Kempers89.get_soret_cov.<locals>.eq_setc                 S   s   g | ]}d qS r5   r   r   r;   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   r?   )
r   kinVHZH0h0H_molar_idealrG   rB   soretr   rD   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 )r.   Tr/   c                    s    g | ]} j  j |qS r   )r   compmoleweightgetcompindexr   )r   r   r   r"   ]   s   z+Kempers89.get_soret_com.<locals>.<listcomp>r#   r1   r3   r4   c                    s   | j  dj     t}tdd D ]Z   d  d     t fddtdd D  |< q.t| |d < |S )Nr   r   c                    sD   g | ]<}|f    d  |f  d     |  qS r5   r   r6   )Mr8   r9   r:   r;   r   r   r"   m   s     z;Kempers89.get_soret_com.<locals>.eq_set.<locals>.<listcomp>r=   rA   rX   r8   r9   rE   r   rF   r   rG   h   s    
(&
z'Kempers89.get_soret_com.<locals>.eq_setc                 S   s   g | ]}d qS r5   r   rH   r   r   r   r"   s   s     )rI   r*   r+   r   r,   mole_weightsr   rL   r
   r   r	   r   r-   rM   rN   r   r?   )r   rO   _rR   rS   rG   rB   rT   r   rY   r   get_soret_comT   s    
"

zKempers89.get_soret_com)F)F)__name__
__module____qualname__r   r-   rU   r\   __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   