Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. import warnings
  2. warnings.filterwarnings('ignore')
  3. from ipywidgets import widgets, Output
  4. from IPython.display import display
  5. from IPython.html.widgets import *
  6. from IPython.display import clear_output
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. from matplotlib.pyplot import figure as fig
  10. %matplotlib inline
  11. from matplotlib.widgets import Slider
  12.  
  13. def RecrystallisationKinetics(T, mode): #This is the function which calculates and plots the recrysallisation kinetics, with temperature and mode/ situation as input
  14. Avrami = [] #List of Avrami values
  15. tA = [] #The time for the Avrami values
  16. XA = 0 #The Avrami plot values
  17. Pd = 10**5 #Stored deformation energy
  18. M0 = 10**4 #Mobility of the moving boundary of the recrystallized grains (constant) [m/(s*Pa)]
  19. Q = 156000 # #Activation energy [J/mol]
  20. N = 2 * 10**12 #Nucleii per unit volume [1/m^3]
  21. Ndot = 1.6 * 10**14 #Nucleation frequency [1/(m^3*s)]
  22. R = 8.314 #The ideal gas constant [J/(mol*K)]
  23. M = M0 * np.exp(-Q/(R * T)) #The temperature deƄendent mobility of the recrystallized grains [m/(s*Pa)]
  24. G = M * Pd #The growth rate [m/s]
  25. Xl = [] #List of values for the fraction
  26. X = 0 #Fraction recrystallized material
  27. r = 0 #Parameter for the varying growth rate case
  28. if mode == "Johnson": #For the Johnson-Mehl case
  29. D = (G / Ndot)**(1 / 4) #The grain size [m]
  30. k = (1 / 3) * np.pi * Ndot * G**3 #k is a parameter where the fraction of recrysallized grains is on the form : X=1-exp(-kt^n)
  31. n = 4 #As k, n is a parameter in the Avrami solution
  32. dt = ((np.log(2) / (k))**(1 / n))/ 500 #dt is the time increment [s]
  33. t = [] #t is a list of the time values
  34. i = 0 #i is used for making time values in the while loop by multiplying by dt
  35. while X < 0.99: #The fraction can't be higher than 1, so we want it to stop before that
  36. i += 1
  37. t.append(dt*i) #Makes a list of time values
  38. X = 1 - np.exp(-(1 / 3) * np.pi * Ndot * G**3 * float(t[i - 1])**4)
  39. XA=np.log(np.log(1 / (1 - X)))
  40. tA.append(np.log(t[i - 1]))
  41. Avrami.append(XA)
  42. Xl.append(X)
  43.  
  44. plt.plot(t, Xl, label = 'Fraction recrystallized material') #Plot of the fraction recrysallized material
  45. plt.title('Fraction recrystallized material, Johnson-Mehl case')
  46. plt.xlabel('Time [s]')
  47. plt.ylabel('Fraction [-]')
  48. plt.legend(loc = "best")
  49. plt.show()
  50.  
  51. plt.plot(tA, Avrami, label='ln(ln(1/1-X(t))') #The Avrami plot
  52. plt.title('Avrami plot')
  53. plt.xlabel('ln(t) [ln(s)]')
  54. plt.ylabel('ln(ln(1/1-X(t))')
  55. plt.legend(loc = "best")
  56. plt.show()
  57.  
  58. elif mode=="SiteSatC": #For the constant growth case
  59. D=(1/N)**(1/3)
  60. k=(4/3)*np.pi*N*G**3
  61. n=3
  62. dt =((np.log(2)/k)**(1/n))/500
  63. t=[]
  64. i=0
  65. while X<0.99:
  66. i+=1
  67. t.append(dt*i)
  68. X=1-np.exp(-(4/3)*np.pi*N*G**3*float(t[i-1])**3)
  69. XA=np.log(np.log(1/(1-X)))
  70. Xl.append(X)
  71. tA.append(np.log(t[i-1]))
  72. Avrami.append(XA)
  73.  
  74. plt.plot(t, Xl, label = 'Fraction recrystallized material')
  75. plt.title('Fraction recrystallized material, Site saturation with constant growth rate')
  76. plt.xlabel('Time [s]')
  77. plt.ylabel('Fraction [-]')
  78. plt.legend(loc = "best")
  79. plt.show()
  80.  
  81. plt.plot(tA, Avrami, label='ln(ln(1/1-X(t))')
  82. plt.title('Avrami plot, constant growth rate')
  83. plt.xlabel('ln(t) [ln(s)]')
  84. plt.ylabel('ln(ln(1/1-X(t))')
  85. plt.legend(loc = "best")
  86. plt.show()
  87.  
  88. elif mode=="SiteSatVarying": #For the varying growth rate case
  89. D=(1/N)**(1/3)
  90. n=3*(1-r) #Here n depends on r
  91. k=(4/3)*np.pi*N*G**3*(1/(1-r)**3)
  92. dt= ((np.log(2)/k)**(1/n))/500
  93. i=0
  94. t=[]
  95. for l in range (6): #We want to print a graph for each r, from 0-0.6
  96. i=0 #Here we reset the values from last iteration
  97. t=[]
  98. Xl=[]
  99. tA=[]
  100. Avrami=[]
  101. X=0
  102. XA=0
  103. while X<0.99:
  104. i+=1
  105. t.append(dt*i)
  106. X=1-np.exp((-4 * np.pi * N * G**3 * float(t[i-1]**(3*(1-r))))/(3* (1-r)**3))
  107. XA=np.log(np.log(1/(1-X)))
  108. Xl.append(X)
  109. tA.append(np.log(t[i-1]))
  110. Avrami.append(XA)
  111. plt.plot(t, Xl, label = 'Fraction recrystallized material')
  112. plt.title('Fraction recrystallized material, (r=' + str(round(r,1))+")")
  113. plt.xlabel('Time [s]')
  114. plt.ylabel('Fraction [-]')
  115. plt.legend(loc = "best")
  116. plt.show()
  117.  
  118. plt.plot(tA, Avrami, label='ln(ln(1/1-X(t))')
  119. plt.title('Avrami plot')
  120. plt.xlabel('ln(t) [ln(s)]')
  121. plt.ylabel('ln(ln(1/1-X(t))')
  122. plt.legend(loc = "best")
  123. plt.show()
  124.  
  125. r+=0.1 #r increases by 0.1 for each iteration
  126. else:
  127. print("Unknown mode.") #If the mode isn't recognised, the function will print this
  128.  
  129. print("The grain size is "+str(D)+"m") #Printing the calculated grain size
  130.  
  131. T=float(input("Choose temperature: ")) #Input for temperature [K]
  132.  
  133. def sub_task_chooser(sub): #Code for making buttons
  134. x = np.linspace(0,np.pi/2) # x-range
  135.  
  136. # Switch function
  137. if sub == 1:
  138. mode="Johnson"
  139. elif sub == 2:
  140. mode="SiteSatC"
  141. elif sub == 3:
  142. mode="SiteSatVarying"
  143. RecrystallisationKinetics(T, mode)
  144.  
  145.  
  146. # Menu toggle buttons
  147. sub_menu = widgets.ToggleButtons(
  148. # {'names':corresponding values,}
  149. options={'Johnson-Mehl':1, 'Constant growth rate':2, 'Varying growth rate':3},
  150. value = 1, #default value
  151. description='Choose case:', #name
  152. button_style='info', #blue buttons
  153. )
  154. interact(sub_task_chooser, sub=sub_menu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement