B
    	hÚ_9  ã               @   st   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lm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
        mixtures, derived in "A comprehensive thermodynamic theory of the Soret effect in a multicomponent gas,
        liquid, or solid", 2001, Journal of Chemical Physics
        doi : http://dx.doi.org/10.1063/1.1398315
Requires : numpy, scipy, ThermoPack, KineticGas
Note : KineticGas is only 2-component compatible, replacing the KineticGas module with a module capable of predicting
        thermal diffusion coefficients for multicomponent ideal-gas mixtures will make this module multicomponent-compatible.
é    N)Úgas_constant)Úcubic)Úcpa)ÚKempers)Úroot)ÚAlpha_T0_empirical)Ú
KineticGasc                   sL   e Zd Zddgddddddf‡ fdd	„	Zd
d„ Zddd„Zddd„Z‡  ZS )Ú	Kempers01g      à?i,  g     jø@é   FZwheightsé   c
       
         sV   t ƒ j||||||d || _|r8|| _t||d| _n|	| _t|| j||	d| _dS )aÚ  
        :param comps (str): comma separated list of components
                :param eos (ThermoPack): Initialized equation of state, with same components as Kempers
        :param x (1darray): list of mole fractions
        :param temp (float > 0): Temperature [K]
        :param pres (float > 0): Pressure [Pa]
        :param phase: Phase of mixture, used for calculating dmudn_TP, see thermo.thermopack for phase identifiers
        :param alpha_t0_empirical (bool): True if using empirical alpha_T0 values
        :param alpha_t0_method (str): what method to use for empirical alpha_T0 values (see Alpha_T0_empirical)
        :param alpha_t0_N (int > 0): Order of approximation when using analytical alpha_T0 values
        )ÚxÚtempÚpresÚphase)Úmethod)Ú
mole_fracsÚNN)	ÚsuperÚ__init__Úalpha_T0_empiricalÚalpha_T0_methodr   Úkinetic_gasÚ
alpha_T0_Nr   Úeos)
ÚselfÚcompsr   r   r   r   r   Zalpha_t0_empiricalZalpha_t0_methodZ
alpha_t0_N)Ú	__class__© úU/Users/vegardjervell/Documents/7_semester/irrev_prosjekt_renskriv/models/kempers01.pyr      s    zKempers01.__init__c             C   s<   | j rt| j| j| jd| _nt| j| j| j| jd| _d S )N)r   r   )r   r   )	r   r   r   r   r   r   r   r   r   )r   r   r   r   Úreset_alpha_t0.   s    zKempers01.reset_alpha_t0c                s  t ‰ˆjjˆjˆjˆjˆjdd\}‰ˆjjˆjˆjˆjˆjdd\}‰ˆjjˆjdˆjddd\}‰ˆ ¡ ‰ˆj	 
ˆj¡‰ˆˆj }tˆjƒ‰ ‡ ‡‡‡‡‡‡‡fdd„}t||ƒ}|jdkrÐtd	ˆjd
ˆjƒ |j}|ˆj }	|dkrˆˆ ˆjˆ ¡   }
|	|
fS |	S dS )z
        Get soret coefficients at current settings, center of volume frame of reference
        :return: (ndarray) soret coefficients
        T)Údvdn)Údhdngñhãˆµøä>é   c                sä   t  ˆ¡}x´tˆd ƒD ]¤‰ˆd ˆd  ˆd  ˆˆ ˆˆ  ˆˆ   ˆˆ	j ˆˆ dˆ	jˆ   ˆˆ  ˆd dˆ	jd   ˆd     t‡ ‡‡‡‡	fdd„tˆd ƒD ƒƒ |ˆ< qW tˆ	jdˆ	j  ˆ  ƒ|ˆd < |S )Nr
   éÿÿÿÿc             3   sV   | ]N}ˆˆ|f ˆˆ  ˆd |f ˆd    ˆj |  dˆj |   ˆ |  V  qdS )r#   r
   N)r   )Ú.0Új)ÚalphaÚdmudxr    Úir   r   r   ú	<genexpr>N   s   z:Kempers01.get_soret_cov.<locals>.eq_set.<locals>.<genexpr>)ÚnpÚzerosÚranger   r   Úsum)r&   Úeqs)r   ÚRÚalpha_T0Údh0dnr!   r'   r    r   )r&   r(   r   Úeq_setH   s    
ˆ z'Kempers01.get_soret_cov.<locals>.eq_setFz+Solution did not converge for composition :z, Temperature :N)r   r   Zspecific_volumer   r   r   r   ÚenthalpyÚdmudx_TPr   r0   Úlenr   ÚsuccessÚprintÚdiagonal)r   ÚkinÚvÚhÚh0Úinitial_guessr2   Úsolvedr&   ÚsoretÚkin_contribr   )r   r/   r0   r1   r!   r'   r    r   r   Úget_soret_cov5   s$    ""





zKempers01.get_soret_covc       
         s  t ‰t ‡fdd„ˆj d¡D ƒ¡ ‰ ˆ_ˆjjˆjˆj	ˆj
ˆjdd\}‰ˆjjˆjdˆj
ddd\}‰ˆ ¡ ‰ˆj ˆj¡‰ˆˆj }tˆj
ƒ‰‡ ‡‡‡‡‡‡‡fdd	„}t||ƒ}|jd
krÔtdˆj
dˆjƒ |j
}|ˆj }|dkrˆˆ ˆj
ˆ ¡   }	||	fS |S dS )z
        Get soret coefficients at current settings, center of mass frame of reference
        :return: (ndarray) soret coefficients
        c                s    g | ]}ˆ j  ˆ j  |¡¡‘qS r   )r   ZcompmoleweightZgetcompindex)r$   Úcomp)r   r   r   ú
<listcomp>i   s   z+Kempers01.get_soret_com.<locals>.<listcomp>ú,T)r!   gñhãˆµøä>r"   c                sä   t  ˆ¡}x´tˆd ƒD ]¤‰ˆd ˆd  ˆd  ˆˆ ˆˆ  ˆˆ   ˆˆ	j ˆˆ dˆ	jˆ   ˆˆ  ˆd dˆ	jd   ˆd     t‡‡ ‡‡‡	fdd„tˆd ƒD ƒƒ |ˆ< qW tˆ	jdˆ	j  ˆ  ƒ|ˆd < |S )Nr
   r#   c             3   sV   | ]N}ˆˆ|f ˆ ˆ  ˆd |f ˆ d    ˆj |  dˆj |   ˆ|  V  qdS )r#   r
   N)r   )r$   r%   )ÚMr&   r'   r(   r   r   r   r)   ~   s   z:Kempers01.get_soret_com.<locals>.eq_set.<locals>.<genexpr>)r*   r+   r,   r   r   r-   )r&   r.   )rE   r   r/   r0   r1   r!   r'   r   )r&   r(   r   r2   w   s    
v z'Kempers01.get_soret_com.<locals>.eq_setFz+Solution did not converge for composition :z, Temperature :N)r   r*   Úarrayr   ÚsplitZmole_weightsr   r3   r   r   r   r   r4   r   r0   r5   r   r6   r7   r8   )
r   r9   r;   r<   r=   r2   r>   r&   r?   r@   r   )rE   r   r/   r0   r1   r!   r'   r   r   Úget_soret_comb   s&    "





zKempers01.get_soret_com)F)F)Ú__name__Ú
__module__Ú__qualname__r   r   rA   rH   Ú__classcell__r   r   )r   r   r	      s
   
-r	   )Ú__doc__Únumpyr*   Zscipy.constantsr   ÚpycThermopack.pyctpr   r   Zmodels.kempersr   Zscipy.optimizer   Zmodels.alpha_t0_empiricalr   Úmodels.kineticgasr   r	   r   r   r   r   Ú<module>   s   