Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1.  
  2. c2--567--1--------2--------3---------4---------5---------6---------772
  3. c
  4. program fcodebungy
  5. c
  6. c copyright Tatsuki Oda (2009.05.01)
  7. c
  8. implicit double precision (a-h,o-z)
  9. implicit integer (i-n)
  10. c
  11. parameter (nx=1000)
  12. c
  13. integer i,j,nstep
  14. integer method
  15.  
  16. double precision,external :: fa,fv
  17.  
  18. double precision xk1,xk2,xk3,xk4,xl1,xl2,xl3,xl4,t1,t
  19.  
  20. dimension z(nx),v(nx),f(nx), ek(nx), ev(nx), et(nx)
  21. c
  22. c2--567--1--------2--------3---------4---------5---------6---------772
  23. c
  24. c for file-open
  25. open(unit=18,file='energy.xy')
  26.  
  27. c for input
  28. open(unit=11,file='f-data.in')
  29.  
  30. c for output
  31. open(unit=16,file='bungy.xy')
  32. c
  33. c
  34. c2--567--1--------2--------3---------4---------5---------6---------772
  35. c
  36. c
  37. c for data input
  38. c
  39. c input-data with (11)
  40. c
  41. read(11,*) nstep ! number of steps
  42. read(11,*) dt ! Delta t
  43. read(11,*) am ! mass of particle
  44. read(11,*) ak0 ! force constant (k) of spring
  45. read(11,*) alength ! length of spring
  46. read(11,*) height ! height of stage
  47. read(11,*) gamma ! friction of resistance
  48. read(11,*) method ! algorithm of solving
  49. c method =0 velret
  50. c =1 Runge-Kutta (2th)
  51. c =2 Runge-Kutta (4th)
  52. c
  53. g=9.80d0 ! acceleratio of gravity
  54. c
  55. c
  56. write(06,*)' Finish to read the data, now !'
  57. c
  58. c2--567--1--------2--------3---------4---------5---------6---------772
  59. c
  60. c
  61. c for initial conditions
  62. c
  63. z(1)=height
  64. v(1)=0.0d0 ! free diving
  65. f(1)=-am*g
  66. c
  67. hml=height-alength
  68. c
  69. c for solving the equation of motion
  70. c
  71. if(method.eq.0)then
  72.  
  73. z(2)=z(1)+v(1)*dt+f(1)*dt**2*0.5d0/am
  74. v(2)=v(1)+f(1)*dt/am
  75.  
  76. do i=2,nstep
  77. if(z(i).gt.hml)then
  78. ak=0.0d0
  79. else
  80. ak=ak0
  81. endif
  82. f(i)=-am*g-ak*(z(i)-hml)
  83. eta=gamma*dt/(2.0d0*am)
  84. etap1=eta+1.0d0
  85. z(i+1)=2.0d0*z(i)/etap1-
  86. & z(i-1)*(1.0d0-eta)/etap1+
  87. & f(i)*dt**2/am/etap1
  88. v(i)=(z(i+1)-z(i-1))/(2.0d0*dt)
  89.  
  90. ek(i)=am*v(i)**2*0.5d0
  91. ev(i)=am*g*z(i)+ak*(z(i)-hml)**2*0.5d0
  92. et(i)=ek(i)+ev(i)
  93. enddo
  94.  
  95.  
  96. elseif(method.eq.1) then
  97. do i=1, nstep
  98. t = dt*(i-1)
  99. t1 = t + dt * 0.5d0
  100. vi=v(i)
  101. zi=z(i)
  102. xk1=dt*fa(t,vi,zi,am,g,ak0,hml,gamma)
  103. xl1=dt*fv(t,vi,zi,am,g,ak0,hml,gamma)
  104. xk2=dt*fa(t1,vi+xk1*0.5d0,zi+xl1*0.5d0,am,g,ak0,hml,gamma)
  105. xl2=dt*fv(t1,vi+xk1*0.5d0,zi+xl1*0.5d0,am,g,ak0,hml,gamma)
  106. xk3=dt*fa(t,vi*xk2*0.5d0,zi+xl2*0.5d0,am,g,ak0,hml,gamma)
  107. xl3=dt*fv(t,vi*xk2*0.5d0,zi+xl2*0.5d0,am,g,ak0,hml,gamma)
  108. xk4=dt*fa(t,vi*xk3,zi+xl3,am,g,ak0,hml,gamma)
  109. xl4=dt*fv(t,vi*xk3,zi+xl3,am,g,ak0,hml,gamma)
  110.  
  111. v(i+1)=vi+(xk1+xk2*2d0+xk3*2d0+xk4)/6d0
  112. z(i+1)=zi+(xl1+xl2*2d0+xl3*2d0+xl4)/6d0
  113.  
  114. if(z(i).gt.hml) then
  115. ak = 0d0
  116. else
  117. ak = ak0
  118. endif
  119.  
  120. ek(i)=am*v(i)**2*0.5d0
  121. ev(i)=am*g*z(i)+ak*(z(i)-hml)**2*0.5d0
  122. et(i)=ek(i)+ev(i)
  123.  
  124. enddo
  125. endif
  126. c
  127. c
  128. c for output of solutions
  129.  
  130.  
  131.  
  132. write(16,800)(i,dt*dble(i-1),z(i),v(i),f(i),i=1,nstep)
  133. 800 format(i5,4e22.12)
  134.  
  135. write(18,900)(i,dt*dble(i-1),ek(i),ev(i),et(i),i=1,nstep)
  136. 900 format(i5,4e22.12)
  137.  
  138.  
  139. if(abs(gamma).lt.1d-9) then
  140. etave = 0d0
  141. etvar = 0d0
  142. do i=1, nstep
  143. etave = etave + et(i)
  144. enddo
  145. etvar = etvar/nstep
  146. do i=1, nstep
  147. etvar = etvar + (et(i)-etave)**2
  148. enddo
  149. etvar = etvar/nstep
  150. write(06,950) etave, etvar
  151. 950 format('energy average : ', e15.6, ' variance :', e15.6)
  152. endif
  153.  
  154.  
  155. 999 continue
  156.  
  157. write(06,*)' Finish the execution, now !'
  158. c
  159. stop
  160. end
  161.  
  162. c ------------- first function program -------------------
  163.  
  164. double precision function fa(t,v,z,am,g,ak0,hml,gamma)
  165. c
  166. c copyright Tatsuki Oda (2009.05.01)
  167. c
  168. implicit double precision (a-h,o-z)
  169. implicit integer (i-n)
  170. c
  171. if(z.gt.hml) then
  172. ak = 0d0
  173. else
  174. ak = ak0
  175. endif
  176. fa = -g-(ak*(z-hml)+gamma*v)/am
  177. c
  178. return
  179. end
  180.  
  181. c---------------end of function program --------------------
  182.  
  183. c---------------second function program --------------------
  184. double precision function fv(t,v,z,am,g,ak0,hml,gamma)
  185. c
  186. c copyright Tatsuki Oda (2009.05.01)
  187. c
  188. implicit double precision (a-h,o-z)
  189. implicit integer (i-n)
  190. c
  191. fv=v
  192. c
  193. return
  194. end
  195.  
  196. c--------------end of second function program --------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement