Advertisement
Guest User

ENG1811 - Part 1A

a guest
May 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. %
  6. % Purpose: The aim of this file is to simulate the biofuel model
  7. %
  8. % Inputs:
  9. % data_set_to_use (integer) Set id for system constants needed for simulation
  10. % array_time (array) An array of uniformly distributed time
  11. % instances
  12. % init_bacteria_amount The initial amount of bacteria
  13. % alpha_b Value of the parameter alpha_b which is the
  14. % production rate of biofuel
  15. % alpha_p Value of the parameter alpha_p whihc is the
  16. % production rate of efflux pumps
  17. %
  18. % Outputs:
  19. % array_bateriaAmount (array) Amount of Bacteria
  20. % array_sensor (array) Sensor output
  21. % array_pump (array) Number of efflux pumps
  22. % array_biofuelInt (array) Amount of biofuel inside bacteria
  23. % array_biofuelExt (array) Amount of biofuel outside of bacteria
  24.  
  25. """
  26.  
  27. import biofuel_system_parameter_sets as bsps
  28. import numpy as np
  29.  
  30.  
  31. def sim_biofuel(data_set_to_use, time_array, init_bacteria_amount, alpha_b, alpha_p):
  32.  
  33. # BEGIN - DO NOT REMOVE
  34. # Note: Please do not remove this
  35. sys_para = bsps.biofuel_system_parameter_sets(data_set_to_use)
  36. ALPHA_N = sys_para['ALPHA_N' ] # Growth rate (1/h)
  37. ALPHA_R = sys_para['ALPHA_R' ] # Basal repressor production rate (1/h)
  38. BETA_R = sys_para['BETA_R'] # Repressor degradation rate (1/h)
  39. BETA_P = sys_para['BETA_P'] # Pump degradation rate (1/h)
  40. DELTA_N = sys_para['DELTA_N'] # Biofuel toxicity coefficient (1/(Mh))
  41. DELTA_B = sys_para['DELTA_B'] # Biofuel export rate per pump (1/(Mh))
  42. GAMMA_P = sys_para['GAMMA_P'] # Pump toxicity threshold
  43. GAMMA_I = sys_para['GAMMA_I'] # Inducer saturation threshold (M)
  44. GAMMA_R = sys_para['GAMMA_R'] # Repressor saturation threshold
  45. K_R = sys_para['K_R'] # Repressor activation constant (h)
  46. K_P = sys_para['K_P'] # Pump activation constant (1/h)
  47. K_B = sys_para['K_B'] # Repressor deactivation constant (1/M)
  48. V = sys_para['V'] # Ratio of intra to extracellular volume
  49. I = sys_para['I'] # Amount of inducer
  50. # The above lines set the following constants:
  51. # ALPHA_N ALPHA_R BETA_R BETA_P DELTA_N DELTA_B GAMMA_P GAMMA_I
  52. # GAMMA_R K_R K_P K_B V I
  53. # END - DO NOT REMOVE
  54.  
  55. # You should put your work below this line
  56.  
  57. # Initialising output arrays
  58. array_bacteriaAmount = np.zeros_like(time_array)
  59. array_sensor = np.zeros_like(time_array)
  60. array_pump = np.zeros_like(time_array)
  61. array_biofuelInt = np.zeros_like(time_array)
  62. array_biofuelExt = np.zeros_like(time_array)
  63.  
  64. array_bacteriaAmount[0] = init_bacteria_amount
  65.  
  66. # Initialising time increment (DELTA) for use in calculations, increment should be constant across all of time_array
  67. dt = time_array[1] - time_array[0]
  68. # For loop to populate output arrays according to time_array, (time = index of time)
  69. for time in range(len(time_array) - 1):
  70. # Calculation for Amount of bacteria array
  71. array_bacteriaAmount[time + 1] = array_bacteriaAmount[time] +\
  72. (ALPHA_N * (1 - array_bacteriaAmount[time]) - DELTA_N * array_biofuelInt[time]
  73. - (ALPHA_N * array_pump[time])/(array_pump[time] + GAMMA_P)) * \
  74. array_bacteriaAmount[time] * dt
  75.  
  76. # Calculation for sensor output array
  77. array_sensor[time + 1] = array_sensor[time] + (ALPHA_R + K_R * (I/(I + GAMMA_I)) - BETA_R * array_sensor[time])\
  78. * dt
  79.  
  80. # Calculation for pump array
  81. array_pump[time + 1] = array_pump[time] +\
  82. (alpha_p + K_P * (1 / ((array_sensor[time] / (1 + K_B * array_biofuelInt[time])) +
  83. GAMMA_R)) - BETA_P * array_pump[time]) * dt
  84.  
  85. # Calculation for biofuel intake
  86. array_biofuelInt[time + 1] = array_biofuelInt[time] + (alpha_b*array_bacteriaAmount[time] - DELTA_B *
  87. array_pump[time] * array_biofuelInt[time]) * dt
  88.  
  89. # Calculation for biofuel Extracted
  90. array_biofuelExt[time + 1] = array_biofuelExt[time] + \
  91. (V * DELTA_B * array_bacteriaAmount[time] * array_biofuelInt[time]
  92. * array_bacteriaAmount[time + 1]) * dt
  93. return array_bacteriaAmount, array_sensor, array_pump, array_biofuelInt, array_biofuelExt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement