Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pylab as pl
  3. rho=1100.
  4. heat_cap=4000.
  5. kond=.5
  6. T_top = 20
  7. T_bot =8
  8.  
  9. len_model=2.
  10.  
  11. del_t=1000
  12. ncells=101
  13. del_x=len_model/(ncells-1)
  14.  
  15. #constant that includes all fixed values
  16. D=kond*del_t/(heat_cap*rho*del_x**2)
  17.  
  18. A=np.zeros([ncells,ncells])
  19.  
  20. Tmpt=np.repeat(8,ncells)
  21. Tmpt[0]=20.
  22.  
  23. Tmpt = 20-np.arrange(101)*(20-8)/100
  24.  
  25. for cell in range(ncells):
  26. if (cell==ncells-1)or(cell==0):
  27. A[cell,cell]=1
  28. else:
  29. A[cell,cell]=-2*D+1
  30. A[cell,cell-1]=D
  31. A[cell,cell+1]=D
  32.  
  33. time_vals = np.arrange(501)
  34. surf_temp = 17 + np.sin(np.pi*2*time_vals/100) *5
  35.  
  36.  
  37. fig1=pl.figure(1)
  38. sp1 = fig1.add_subplot(1,1,1)
  39. fig2 =pl.figure(2)
  40. sp2 = fig2.add_subplot(1,1,1)
  41. # make an array of depths where temps are calculated
  42. #tpmt is old rod data, update surface temperature
  43. x = np.arange(ncells) * del_x
  44. #0,8,16,40
  45. depth8=[]
  46. for time in range(1001):
  47. time = ttime/2
  48. Tmpt_old = Tmpt.copy()
  49. Tmpt_old[0] =np.interp(time,time_vals,surf_temp)
  50. depth8.append(Tmpt_old[5])
  51. Tmpt = np.dot(A,Tmpt_old)
  52. if time%100==0:
  53. sp1.plot(Tmpt,x)
  54.  
  55. sp2.plot(depth8)
  56. pl.show()
  57.  
  58. '''
  59. One additional item that you may need to use...
  60. if you need to interpolate across a 1-D array, numpy
  61. has a piecewise linear interpolation function which
  62. linearly connect point in a dataset and uses this to estimate
  63. 'y' values from 'x' values
  64. '''
  65. x= np.linspace(0,100,21)
  66. y= np.sqrt(x)
  67. #the value y2 (at x=25) is calculated by interplating from the x and y arrays
  68. y2= np.interp(25,x,y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement