U
    	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__ R/home/ubuntu/Home/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    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rt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dhdnh㈵>   c                    s   t }td D ]d d  d        	j  d	j     d d	jd   d     t 	fddtd D  |< q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>npZzerosranger   r   sumr.   Zeqsr   Ralpha_T0dh0dnr%   r/   r#   r   r.   r0   r    eq_setH   s    
.$

 z'Kempers01.get_soret_cov.<locals>.eq_setF+Solution did not converge for composition :, Temperature :N)r   r   Zspecific_volumer   r   r   r   enthalpydmudx_TPr   r9   lenr   successprintdiagonal)r   kinvhh0initial_guessr<   solvedr.   soretkin_contribr   r7   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rt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,   compr!   r   r    
<listcomp>i   s   z+Kempers01.get_soret_com.<locals>.<listcomp>,Tr$   r&   r'   c                    s   t }td D ]d d  d        	j  d	j     d d	jd   d     t 	fddtd D  |< q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*   r+   )Mr.   r/   r0   r   r   r    r1   }   s   z:Kempers01.get_soret_com.<locals>.eq_set.<locals>.<genexpr>r2   r6   rQ   r   r8   r9   r:   r%   r/   r   r;   r    r<   w   s    
.$

 z'Kempers01.get_soret_com.<locals>.eq_setFr=   r>   N)r   r3   arrayr   splitZmole_weightsr   r?   r   r   r   r   r@   r   r9   rA   r   rB   rC   rD   )
r   rE   rG   rH   rI   r<   rJ   r.   rK   rL   r   rR   r    get_soret_comb   s(    
"





zKempers01.get_soret_com)F)F)__name__
__module____qualname__r   r"   rM   rU   __classcell__r   r   r   r    r	      s     
-r	   )__doc__numpyr3   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   