Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 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. #366 for 0.1 (HR) ,1,50,1200
  11. #158 for 2 (HR) ,1,50,1200
  12. #values
  13. '''
  14. Defining constants
  15. '''
  16. D0= 20 #[micron]
  17. K0= 10**10
  18. n= 0.5
  19. Q= 221000
  20. R = 8.314
  21. HR= 2 #input. vary 0.1 - 2.0
  22. CR= 1 #input
  23. t_iso = 50 #input
  24. T_isoC = 1200 #input. vary 900-1400 [Celsius]
  25. '''
  26. Creating sliders
  27. '''
  28. T_slider = widgets.IntSlider(
  29. value=573,
  30. min = 273,
  31. max = 1273,
  32. step = 5,
  33. description='Temp[K]',
  34. continous_update = False)
  35. CR_slider = widgets.FloatSlider(
  36. value=0.1,
  37. min = 0.1,
  38. max = 2,
  39. step = 0.019,
  40. description=r'CR[K/s]',
  41. continous_update = False)
  42. HR_slider = widgets.FloatSlider(
  43. value=0.1,
  44. min = 0.1,
  45. max = 2,
  46. step = 0.019,
  47. description=r'HR[K/s]',
  48. continous_update = False)
  49. t_slider = widgets.IntSlider(
  50. value=50,
  51. min = 1,
  52. max = 100,
  53. step = 1,
  54. description=r't$_{iso}$[s]',
  55. continous_update = False)
  56. def funk1(HR, CR, t_iso, T_isoC):
  57. delta_T = T_iso - 298.15
  58. delta_t = delta_T/(100*HR) #100 steps with equal length for heating
  59. dirta_t = delta_T/(100*CR) #100 steps with equal length for cooling
  60. sum_before_iso = 0 #Eventually the integral from 0 to t_1
  61. sum_after_iso = -np.exp(-Q/(R*T_iso))*dirta_t #Eventually the integral from t_2 to t_3
  62. for i in range(0,101):
  63. T_before = 298.15 + HR*delta_t*i
  64. sum_i = np.exp(-Q/(R*T_before))*delta_t - np.exp(-Q/(R*298.15))*delta_t
  65. sum_before_iso += sum_i
  66. T_after = T_iso - CR*dirta_t*i
  67. Sum_i = np.exp(-Q/(R*T_after))*dirta_t - np.exp(-Q/(R*298.15))*delta_t
  68. sum_after_iso += Sum_i
  69. a = D0
  70. b = K0*sum_before_iso
  71. c = K0*t_iso*(np.exp(-Q/(R*T_iso)) - np.exp(-Q/(R*298.15)))
  72. d = K0*sum_after_iso
  73. D = (a**(1/n)+b+c+d)**n
  74. print(a,b,c,d)
  75. print(D)
  76. def sub_task_chooser(sub):
  77. T_iso = T_isoC + 273.15 #[Kelvin]
  78. delta_T = T_iso - 298.15
  79. delta_t = delta_T/(100*HR) #100 steps with equal length for heating
  80. dirta_t = delta_T/(100*CR) #100 steps with equal length for cooling
  81. if sub == 1:###HR
  82. #HR = input('k')
  83. dirta_t = delta_T/(100*CR)
  84. T_slider = widgets.IntSlider(
  85. value=900,
  86. min = 900,
  87. max = 1400,
  88. step = 5,
  89. description=r'T$_{iso}$[K]',
  90. continous_update = False)
  91. CR_slider = widgets.FloatSlider(
  92. value=0.1,
  93. min = 0.1,
  94. max = 2,
  95. step = 0.019,
  96. description=r'CR[K/s]',
  97. continous_update = False)
  98. t_slider = widgets.IntSlider(
  99. value=50,
  100. min = 1,
  101. max = 100,
  102. step = 1,
  103. description=r't$_{iso}$[s]',
  104. continous_update = False)
  105. return T_slider, CR_slider, t_slider
  106. elif sub == 2:###CR
  107. #CR = input('Choose CR')
  108. #delta_t= delta_T/(100*HR)
  109. T_slider = widgets.IntSlider(
  110. value=900,
  111. min = 900,
  112. max = 1400,
  113. step = 5,
  114. description=r'T$_{iso}$[K]',
  115. continous_update = False)
  116. HR_slider = widgets.FloatSlider(
  117. value=0.1,
  118. min = 0.1,
  119. max = 2,
  120. step = 0.019,
  121. description=r'HR[K/s]',
  122. continous_update = False)
  123. t_slider = widgets.IntSlider(
  124. value=50,
  125. min = 1,
  126. max = 100,
  127. step = 1,
  128. description=r't$_{iso}$[s]',
  129. continous_update = False)
  130. return T_slider, HR_slider, t_slider
  131. elif sub == 3:###T_iso
  132. #delta_t= delta_T/(100*HR)
  133. #dirta_t = delta_T/(100*CR)
  134. CR_slider = widgets.FloatSlider(
  135. value=0.1,
  136. min = 0.1,
  137. max = 2,
  138. step = 0.019,
  139. description=r'CR[K/s]',
  140. continous_update = False)
  141. HR_slider = widgets.FloatSlider(
  142. value=0.1,
  143. min = 0.1,
  144. max = 2,
  145. step = 0.019,
  146. description=r'HR[K/s]',
  147. continous_update = False)
  148. t_slider = widgets.IntSlider(
  149. value=50,
  150. min = 1,
  151. max = 100,
  152. step = 1,
  153. description=r't$_{iso}$[s]',
  154. continous_update = False)
  155. return CR_slider, HR_slider, t_slider
  156. elif sub == 4:###t_iso
  157. T_slider = widgets.IntSlider(
  158. value=900,
  159. min = 900,
  160. max = 1400,
  161. step = 5,
  162. description=r'T$_{iso}$[K]',
  163. continous_update = False)
  164. CR_slider = widgets.FloatSlider(
  165. value=0.1,
  166. min = 0.1,
  167. max = 2,
  168. step = 0.019,
  169. description=r'CR[K/s]',
  170. continous_update = False)
  171. HR_slider = widgets.FloatSlider(
  172. value=0.1,
  173. min = 0.1,
  174. max = 2,
  175. step = 0.019,
  176. description=r'HR[K/s]',
  177. continous_update = False)
  178. #delta_t= delta_T/(100*HR)
  179. #dirta_t = delta_T/(100*CR)
  180. return T_slider, CR_slider, HR_slider
  181. sub_menu = widgets.ToggleButtons(
  182. # {'names':corresponding values,}
  183. options={'HR':1, 'CR':2, 'T_iso':3, 't_iso':4},
  184. value = 1, #default value
  185. description='Input parameter:', #name
  186. button_style='info', #blue buttons
  187. )
  188. def f(T):
  189. return T
  190. interact(sub_task_chooser, sub=sub_menu)
  191. interact(f, T=CR_slider)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement