Advertisement
Guest User

opdracht 2 handleiding

a guest
Feb 23rd, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.56 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Nov 8 11:02:26 2017
  4.  
  5.  
  6. Viskotter simulation file
  7. Version 1.0G
  8. J. Rodrigues Monteiro, based on matlab code from P. de Vos
  9. Delft University of Technology
  10. 3ME / MTT / SDPO / ME
  11.  
  12. History:
  13. 20171108: initial python version JRM
  14. 20200108: simps integration EU
  15. no graphing endpoits... EU
  16. """
  17. import numpy as np
  18. import math
  19. import matplotlib.pyplot as plt
  20. import time
  21.  
  22. from scipy import integrate
  23.  
  24. # ----------- parameters for simulation --------------------------------------
  25.  
  26. tmax = 36000 # simulation time [s]
  27. dt = 1 # timestep [s]
  28.  
  29. # fuel properties
  30. LHV = 42700 # Lower Heating Value [kJ/kg]
  31. print('fuel properties loaded')
  32.  
  33. # water properties
  34. rho_sw = 1024 # density of seawater [kg/m3]
  35. print('water properties loaded')
  36.  
  37. # ship data
  38. m_ship = 358000 # ship mass [kg]
  39. c1 = 1500 # resistance coefficient c1 in R = c1*vs^2
  40. v_s0 = 6.5430 # ship design speed [m/s]
  41. t = 0.1600 # thrust deduction factor[-]
  42. w = 0.2000 # wake factor [-]
  43. print('ship data loaded')
  44.  
  45. # propellor data
  46. D_p = 3.53 # diameter of propellor [m]
  47. K_T_a = -0.3821 # factor a in K_T = a*J + b [-]
  48. K_T_b = 0.2885 # factor b in K_T = a*J + b [-]
  49. K_Q_a = -0.03346 # factor a in K_Q = a*J + b [-]
  50. K_Q_b = 0.0308 # factor b in K_Q = a*J + b [-]
  51. eta_R = 1.0100 # relative rotative efficiency [-]
  52. print('propellor data loaded')
  53.  
  54. # engine data
  55. m_f_nom = 1.314762 # nominal fuel injection [g]
  56. eta_e = 0.3800 # nominal engine efficiency [-]
  57. i = 6 # number of cylinders [-]
  58. k_es = 2 # k-factor for engines based on nr.of strokes per cycle
  59. P_b = np.zeros(tmax) # engine power [kW]
  60. P_b[0] = 960 # Nominal engine power [kW]
  61. M_b = np.zeros(tmax) # engine torque [Nm]
  62. M_b[0] = P_b[0]*1000/2/math.pi/(900/60) # ([P_b*1000/2/math.pi/n_eng_nom])
  63. print('engine data loaded')
  64.  
  65. # gearbox data
  66. eta_TRM = 0.9500 # transmission efficiency [-]
  67. i_gb = 4.2100 # gearbox ratio [-]
  68. I_tot = 200 # total mass of inertia of propulsion system [kg*m^2]
  69. print('gearbox data loaded')
  70.  
  71. # initial values
  72. in_p = 3.2830 # initial rpm
  73. iv_t_control = np.array([0, 0.1*tmax, 0.2*tmax, 0.5*tmax,
  74. 0.6*tmax, 0.7*tmax, tmax])
  75. X_parms = np.array([0.85, 0.85, 0.3, 0.4, 0.4, 1, 1]) # % maximum fuelrack
  76. Y_parms = np.array([1, 1, 1, 1, 1, 1, 1]) # disturbance factor
  77.  
  78. # simulation control parameters
  79. xvals = np.linspace(0, tmax-1, tmax)
  80. ov_X_set = np.interp(xvals, iv_t_control, X_parms)
  81. ov_Y_set = np.interp(xvals, iv_t_control, Y_parms)
  82.  
  83. # --------- Start van de funtie definities
  84.  
  85. def R_schip(snelheid_schip):
  86. global Y, c1
  87. weerstand = Y * c1 * snelheid_schip**2
  88. return weerstand
  89.  
  90.  
  91. # -------- Make arrays -------------------------------------------------------
  92.  
  93. # Time
  94. mytime = np.linspace(0, tmax-1, tmax)
  95. # Velocity of the ship [m/s]
  96. v_s = np.zeros(tmax)
  97. v_s[0] = v_s0
  98. # Distance traveled [m]
  99. s = np.zeros(tmax)
  100. # Advance velocity [m/s]
  101. v_a = np.zeros(tmax)
  102. v_a[0] = (1-w) * v_s0
  103. # Rpm propellor [Hz]
  104. n_p = np.zeros(tmax)
  105. n_p[0] = in_p
  106. # Rpm diesel engine [Hz]
  107. n_e = np.zeros(tmax)
  108. n_e[0] = 900/60 # Nominal engine speed in rotations per second [Hz]
  109. # Resistance [N]
  110. R = np.zeros(tmax)
  111. Y = ov_Y_set[0]
  112. R[0] = R_schip(v_s0)
  113. # Acceleration ship [m/s^2]
  114. sum_a = np.zeros(tmax)
  115. # Acceleration propellor[1/s^2]
  116. sum_dnpdt = np.zeros(tmax)
  117. m_flux_f = np.zeros(tmax)
  118. out_fc = np.zeros(tmax)
  119.  
  120. M_Trm = np.zeros(tmax) # M_B * i_gb * eta_TRM
  121. KT = np.zeros(tmax) # Thrust coefficient [-]
  122. KQ = np.zeros(tmax) # Torque coefficient [-]
  123. Rsp = np.zeros(tmax) # Resistance propelled situation [N]
  124. F_prop = np.zeros(tmax) # Thrust power [N]
  125. M_prop = np.zeros(tmax) # Torque [Nm]
  126. P_O = np.zeros(tmax) # Open water propellor power
  127. P_p = np.zeros(tmax) # Propellor power [kW]
  128. P_b = np.zeros(tmax) # Engine brake power [kW]
  129. P_T = np.zeros(tmax) # Thrust power [kW]
  130. P_E = np.zeros(tmax) # Engine power [kW]
  131. J = np.zeros(tmax) # Advance ratio [-]
  132.  
  133.  
  134. # ------------- Run simulation -----------------------------------------------
  135. start = time.perf_counter()
  136.  
  137. for k in range(tmax-1):
  138. # advance ratio
  139. J[k+1] = ((v_a[k] / n_p[k]) / D_p)
  140. # Thrust and torque
  141. F_prop[k] = ((((J[k+1] * K_T_a) + K_T_b) *
  142. n_p[k] ** 2) * rho_sw * D_p ** 4)
  143. M_prop[k] = (((((J[k+1] * K_Q_a) + K_Q_b) *
  144. n_p[k] ** 2) * rho_sw * D_p ** 5) / eta_R)
  145. KT[k+1] = J[k+1] * K_T_a + K_T_b
  146. KQ[k+1] = J[k+1] * K_Q_a + K_Q_b
  147. P_O[k+1] = ((((J[k+1] * K_Q_a) + K_Q_b) *
  148. n_p[k] ** 2) * rho_sw * D_p ** 5) * n_p[k] * 2 * math.pi
  149. P_p[k+1] = M_prop[k] * n_p[k] * 2 * math.pi
  150. # Calculate acceleration from resulting force --> ship speed & tr.distance
  151. sum_a[k+1] = ((F_prop[k] - (R[k] / (1-t)))/m_ship)
  152. #v_s_new = (np.trapz(sum_a[k:k+2], dx=0.01)) + v_s[k]
  153. v_s[k+1] = integrate.simps(sum_a[:k+2])+v_s0
  154. #v_s[k+1] = v_s_new
  155. Rsp[k+1] = R[k] / (1-t)
  156. # Traveled distance
  157. s[k+1] = s[k] + v_s[k+1] * dt
  158. # Advance velocity
  159. v_a[k+1] = v_s[k+1] * (1 - w)
  160. P_T[k+1] = F_prop[k] * v_a[k+1]
  161. # Resistance
  162. Y = ov_Y_set[k]
  163. R[k+1] = R_schip( v_s[k+1])
  164. P_E[k+1] = v_s[k+1] * R[k+1]
  165. # Calculate acceleration from resulting force --> propellor np
  166. sum_dnpdt[k+1] = ((M_b[k] * i_gb * eta_TRM) - M_prop[k])/(2*math.pi*I_tot)
  167. np_new = integrate.simps(sum_dnpdt[k:k+2], dx=0.01) + n_p[k]
  168. n_p[k+1] = np_new
  169. # Engine speed
  170. n_e[k+1] = n_p[k+1] * i_gb
  171. # Fuel rack
  172. X = ov_X_set[k]
  173. m_flux_f[k+1] = (X * m_f_nom * n_e[k+1]) * i / k_es
  174. # Fuel consumption
  175. out_fc[k+1] = (integrate.simps(m_flux_f[k:k+2]))+out_fc[k]
  176. Q_f = X * m_f_nom * LHV
  177. W_e = Q_f * eta_e
  178. # Brake power
  179. P_b[k+1] = (W_e * n_e[k+1] * i) / k_es
  180. # Engine torque
  181. M_b[k+1] = P_b[k+1] / (2 * math.pi * n_e[k+1])
  182. M_Trm[k+1] = M_b[k+1] * i_gb * eta_TRM
  183.  
  184.  
  185. # EU just to be sure
  186. v_s[0]=v_s0
  187. v_s[1]=v_s0
  188. # -------------- Plot Figure -------------------------------------------------
  189.  
  190. # create figure with four subplots
  191. fig = plt.figure(figsize=(10, 10))
  192. ax1 = fig.add_subplot(4, 1, 1) # fig.add_subplot(#rows, #cols, #plot)
  193. ax1.plot(mytime[1:tmax-2], v_s[1:tmax-2])
  194. ax1.set(title='Ship Propulsion Output',
  195. ylabel='Ship speed [m/s]',
  196. xlabel='Time [s]')
  197. ax1.grid()
  198. ax2 = fig.add_subplot(4, 1, 2)
  199. ax2.plot(mytime[1:tmax-2], s[1:tmax-2])
  200. ax2.set(ylabel='Distance traveled [m]',
  201. xlabel='Time [s]')
  202. ax2.grid()
  203. ax3 = fig.add_subplot(4, 1, 3)
  204. ax3.plot(mytime[1:tmax-2], out_fc[1:tmax-2])
  205. ax3.set(ylabel='Fuel consumed [g]',
  206. xlabel='Time [s]')
  207. ax3.grid()
  208. ax4 = fig.add_subplot(4, 1, 4)
  209. ax4.plot(mytime[1:tmax-2], ov_X_set[1:tmax-2])
  210. ax4.set(ylabel='Fuel rack [%]',
  211. xlabel='Time [s]')
  212. ax4.grid()
  213. fig.tight_layout()
  214.  
  215. fig.savefig('test_plot1.svg')
  216. fig.savefig('test_plot1.png')
  217. print(time.perf_counter()-start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement