Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. #import ipywidgets as widgets
  4. import warnings
  5. warnings.filterwarnings('ignore')
  6. from ipywidgets import widgets, Output
  7. from IPython.display import display
  8. from IPython.html.widgets import *
  9. from IPython.display import clear_output
  10. #fig2, ax2=plt.subplots()
  11. N_dot = 1.6 * 10 ** 14
  12. N = 2 * 10 ** 12
  13. P = 10 ** 5
  14. M0 = 10 ** 4 # ms/Pa
  15. Q = 156000
  16. T=input(r'Do you want to set a temperature? If yes, enter temperature in $^\circ$C. If not, press enter to set temperature to 300 (default). ')
  17. T=int(T)
  18. T+=273
  19. R=8.314
  20. #T=int(T)
  21.  
  22. #G=f(T)
  23. #sub_task_chooser(sub_menu)
  24. #print(sub_menu.options)
  25. #T_slider = widgets.IntSlider(
  26. #value=298,
  27. #min = 273,
  28. #max = 1273,
  29. #step = 1,
  30. #description='T[K]',
  31. #continous_update = True)
  32. def f(T):
  33. T+=273
  34. #T=interact(f, T=widgets.IntSlider(min=0, max=1000, step=1, value=273))
  35. M = M0 * np.exp(-Q/(R*T))
  36. G = M * P
  37. def master(k,n):
  38. t_half = (np.log(2)/(k))**(1 / n)
  39. dt = t_half / 50
  40. t = []
  41. p = 0
  42. tid = dt * n
  43. t_log = []
  44. X = []
  45. x = 0
  46. element = 1
  47. A = []
  48. while x<0.99:
  49. tid=dt*p
  50. x = 1 - np.exp((-k* tid ** n) / 3)
  51. if x<0.99:
  52. t.append(tid)
  53. X.append(x)
  54. if tid!=0:
  55. element = np.log(tid)
  56. t_log.append(element)
  57. a=np.log(np.log(1/(1-x)))
  58. A.append(a)
  59. p+=1
  60. return X,A,t_log,t
  61. def sub_task_chooser(sub):
  62. #x = np.linspace(0,np.pi/2) # x-range
  63. # Switch function
  64. if sub == 1:
  65. jm=(np.pi * N_dot * G ** 3)/3
  66. X, A, t_log, t = master(jm, 4)
  67. plt.plot(t, X)
  68. plt.show()
  69. plt.plot(t_log, A)
  70. plt.show()
  71. D = (G / N_dot) ** 0.25
  72. print('Grain size [m]: '+str(D))
  73. elif sub == 2:
  74. site_sat=(4*np.pi * N * G ** 3)/3
  75. X, A, t_log, t = master(site_sat, 3)
  76. plt.plot(t, X)
  77. plt.show()
  78. plt.plot(t_log, A)
  79. plt.show()
  80. D = (1 / N) ** (1 / 3)
  81. print('Grain size [m]: '+str(D))
  82. elif sub == 3:
  83. r=0
  84. fig, ax1 = plt.subplots()
  85. fig, ax2 = plt.subplots()
  86. for i in range(7):
  87. r = i * 0.1
  88. new_n = 3 * (1 - r)
  89. new_k = (4 * np.pi * N * G ** 3) / (new_n ** 3)
  90. X, A, t_log, t = master(new_k, new_n)
  91. name = 'r=' + str(round(r, 1))
  92. ax1.plot(t, X, label=name)
  93. ax1.legend()
  94. ax2.plot(t_log, A, label=name)
  95. ax2.legend(loc="lower right")
  96. plt.show()
  97. D = (1 / N) ** (1 / 3)
  98. print('Grain size [m]: ' + str(D))
  99. #plt.legend()
  100. #plt.show()
  101.  
  102. #def buttonclicked(value):
  103. #sub_task_chooser(value['new'])
  104. sub_menu = widgets.ToggleButtons(
  105. # {'names':corresponding values,}
  106. options={'Johnson-Mehl':1, 'Constant growth':2, 'Varying growth':3},
  107. value = 1, #default value
  108. description='Model:', #name
  109. button_style='info', #blue buttons
  110. )
  111.  
  112. interact(sub_task_chooser, sub=sub_menu)
  113. #interact(master, T=T_slider)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement