B
    9^z                 @   s   d dl Zd dlmZ d dl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 ZdddZdd	 Zd
d Zdd Zdd ZdS )    N)t_star_funcc          
   C   s0   t jt jt j t| dtt j|     S )N   )c	T0_jominy	Ti_jominysserfnpsqrta_jominy)xt r   K/Users/vegardjervell/Documents/6_semester/matmod/matmod11V4/jominy_stick.pyT_func   s    r   Fc          	   C   sx   ddt tj|   }|dkrHtjtjtj tt j| |dd  S tjtjtj tt j| |dd  d S d S )N   r   Fr   )axesi  )	r	   r
   r   r   r   r   r   r   	tensordot)r   r   celciusa1r   r   r   T_func_vectorized   s    (r   c           	      s  t jtjtjtjdt tjtjtj	} t
 }t| dd}t
 }tdt |jdt|| dddd	 d
}|t fddttD  }td  fdd|D }tjddgd}d}d}	xxt|D ]j\}
}|	dkrtj| |
|| tt|dd dd |d7 }d}	qtj| |
|| d |d7 }|	d7 }	qW tjddd tjddd tjddd td tjd dd! d S )"N)stepT)r   zCaluculating T(x,t) in z points (all displayed) took    s )sepgffffff?c                s   g | ]}|t   qS r   )len).0i)x_listr   r   
<listcomp>'   s    zplot_Tt.<locals>.<listcomp>YlOrRd_rc                s   g | ]} |qS r   r   )r   r   )cmapr   r   r    )   s          )figsizer      r   mm:)colorlabel	linestyler   )r)   ziTemperature as a function of time at different position on a Jominy stick, distance between lines is 5mm.   )fontsizezTime [s]u   Temperature [℃]logzupper right)locr-   ) r	   aranger   Tt_x_min_jominyTt_x_max_jominyTt_x_step_jominylogspacet_min_jominyt_max_jominyt_points_jominytimeprocess_timer   printproductshaperoundarrayranger   cmget_cmappltfigurezipplotstrtitlexlabelylabelxscalelegend)t_listt0Ztemp_curvest1	max_colorcolor_range
color_listfigcountlabel_counterZtemp_curves_valuesr   r   )r"   r   r   plot_Tt   s4    &$

&
rU   c             C   sR   |t jk s|t jkrtd | dtt j  dt	|t j t jt j    S )NuD   Du har prøvd å finne t, for en temperatur utenfor (Ti,T0) i Jominyr   r   )
r   r   r   warningswarnr	   r
   r   r   Zerfinv)r   Tr   r   r   find_tE   s    
rY   c                s   t |}t |t |d gf}t| |}t  fdd|D  }t j||}dt| }t jj	
|d}t ||S )Nc                s   g | ]}|k | k qS r   r   )r   r   )t_endt_startr   r   r    R   s    z%scheil_integrator.<locals>.<listcomp>r   r   )r	   diffconcatenater>   r   	transposemamasked_arrayr   MaskedArrayfilleddot)r   rL   r\   r[   dttempsmask	integrandr   )r[   r\   r   scheil_integratorM   s    

ri   c        	      C   s  t  } ttjtjtj}t|tj	d }t|tj
d }tt|d t|d tj}t||||}ddtj |tj   }t  }tdt|dt||  ddd	d
 tjddgd}t|| tjdd td tjddd tjddd tjddd d S )Nr#   r   r   rZ   zCalculating X(x) in z points took r&   r   r   )r   r$   )r%   both)whichr.   zMDegree of transformation completion as a function of position on Jominy stickr,   )r-   zDistance from cold end [mm]u+   Fraction of transformation completion [–])r8   r9   r	   r4   r   Xx_x_minXx_x_maxXx_x_pointsrY   Teqr   log10jominy_scheil_integrand_pointsri   Xcnr:   r   r=   rB   rC   rE   gridrJ   rG   rH   rI   )	rM   Zx_liner\   r[   rL   IXrN   rR   r   r   r   plot_XxZ   s     $"
rw   )F)numpyr	   matplotlib.pyplotpyplotrB   Zmatplotlib.cmr@   c_curvesr   	constantsr   Zscipy.specialspecialr   rV   r8   r   r   rU   rY   ri   rw   r   r   r   r   <module>   s   
	)