U
    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__ V/home/ubuntu/Home/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 )w
        Get soret coefficients at current settings
        :return: 1darray: soret coefficients of components
        r   T)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#   F   s     z?Mod_Kempers89.get_soret_cov.<locals>.eq_set.<locals>.<listcomp>r	   r+   zerosrangesumalphaeqsr9   r:   hr   r=   r;   r<   r   eq_setA   s    
(&
z+Mod_Kempers89.get_soret_cov.<locals>.eq_setc                 S   s   g | ]}d qS r6   r   r   r<   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   r@   )r   VHH0h0rH   rC   soretr   rE   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 )r0   c                    s    g | ]} j  j |qS r   )r   compmoleweightgetcompindexr   )r   r   r   r#   V   s   z/Mod_Kempers89.get_soret_com.<locals>.<listcomp>r$   Tr2   r4   r5   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 r6   r   r7   )Mr9   r:   r;   r<   r   r   r#   g   s     z?Mod_Kempers89.get_soret_com.<locals>.eq_set.<locals>.<listcomp>r>   rB   rW   r9   r:   rF   r   rG   r   rH   b   s    
(&
z+Mod_Kempers89.get_soret_com.<locals>.eq_setc                 S   s   g | ]}d qS r6   r   rI   r   r   r   r#   m   s     )r+   r,   r   r-   mole_weightsr   rL   r
   r   r	   r   rM   rN   r   r@   )r   _rR   rH   rC   rS   r   rX   r   get_soret_comQ   s    
"

zMod_Kempers89.get_soret_com)__name__
__module____qualname__r   r/   rT   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   