Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

304 rivejä
18 KiB

  1. module BOP
  2. contains
  3. subroutine BopStack_Init
  4. call BOP_StartUp
  5. end subroutine BopStack_Init
  6. subroutine BopStack_Step
  7. use SimulationVariables
  8. use CBopControlPanel
  9. use BopVariables
  10. use SimulationVariables !@
  11. ! USE CEquipmentsConstants
  12. use CSounds
  13. implicit none
  14. data%State%BopStackInput%BOP_timeCounter= data%State%BopStackInput%BOP_timeCounter + 1
  15. write(*,*) 'BOP_timeCounter=' , data%State%BopStackInput%BOP_timeCounter
  16. data%Equipments%BopControlPanel%AirSupplyPressureGauge= (1 - data%State%BopStackAcc%AirSupplyPressureGaugeMalf)* (1 - data%State%BopStackAcc%RigAirMalf) *120. !psi
  17. if (data%State%BopStackAcc%pram_reg < 2300.) then
  18. data%State%ShearRAM%ShearIsNotAllowed= 1
  19. else
  20. data%State%ShearRAM%ShearIsNotAllowed= 0
  21. endif
  22. !write(*,*) 'ShearIsNotAllowed=' , ShearIsNotAllowed
  23. !TD_AnnularFillingFinal ! (0.0 to 1.0) percentage filled by tool joint
  24. !======================================================================
  25. ! MAIN BODY OF PROGRAM
  26. ! PURPOSE: BOP Control
  27. !======================================================================
  28. !=== Instantaneous Pipe Diameters in Each Ram (Input from TD Module):==
  29. data%State%Annular%ODDrillpipe_inAnnular= data%State%TD_BOP%AnnularPreventerDiam * 12.0 ! ft to inch
  30. data%State%PipeRam1%ODDrillpipe_in= data%State%TD_BOP%UpperRamDiam * 12.0
  31. data%State%ShearRAM%ODDrillpipe_inShearRam= data%State%TD_BOP%BlindRamDiam * 12.0
  32. data%State%PipeRam2%ODDrillpipe_in= data%State%TD_BOP%LowerRamDiam * 12.0
  33. !IDshearBopFinal
  34. !IDPipeRam1Final
  35. !IDPipeRam2Final
  36. !IDAnnularFinal
  37. data%State%ShearRAM%OpenArea_shearBop= PI*(data%State%ShearRAM%IDshearBopFinal**2-data%State%ShearRAM%ODDrillpipe_inShearRam**2)/4.0d0 !D(in), AREA(in^2)
  38. data%State%ShearRAM%OpenArea_PipeRam1= PI*(data%State%ShearRAM%IDPipeRam1Final**2-data%State%PipeRam1%ODDrillpipe_in**2)/4.0d0 !D(in), AREA(in^2)
  39. data%State%ShearRAM%OpenArea_PipeRam2= PI*(data%State%ShearRAM%IDPipeRam2Final**2-data%State%PipeRam2%ODDrillpipe_in**2)/4.0d0 !D(in), AREA(in^2)
  40. data%State%ShearRAM%OpenArea_Annular= PI*(data%State%ShearRAM%IDAnnularFinal**2-data%State%Annular%ODDrillpipe_inAnnular**2)/4.0d0 !D(in), AREA(in^2)
  41. data%State%ShearRAM%MinimumOpenArea_InBOP= min(data%State%ShearRAM%OpenArea_shearBop,data%State%ShearRAM%OpenArea_PipeRam1,data%State%ShearRAM%OpenArea_PipeRam2,data%State%ShearRAM%OpenArea_Annular)
  42. !TD_BOPConnectionPossibility(j) = 0 or 1
  43. !!!AnnularPreventerDiam = TD_BOPConnectionPossibility(1) >> used in Annular code
  44. !!!UpperRamDiam = TD_BOPConnectionPossibility(2) >> used in PipeRam1 code
  45. !!!BlindRamDiam = TD_BOPConnectionPossibility(3) >> used in ShearRam code
  46. !!!LowerRamDiam = TD_BOPConnectionPossibility(4) >> used in PipeRam2 code
  47. !=====================================================================
  48. !============SEALING PRESSURES TO BE SET IN ANNULAR REGULATOR==========
  49. data%State%AnnularComputational%WellBorePressure=5000.
  50. if (data%State%Annular%ODDrillpipe_inAnnular>0.) then
  51. if (data%State%Annular%ODDrillpipe_inAnnular>0. .and. data%State%Annular%ODDrillpipe_inAnnular<=1.99) then
  52. data%State%AnnularComputational%acoef=-0.2673
  53. data%State%AnnularComputational%Bcoef=994.3
  54. data%State%AnnularComputational%const=77
  55. elseif (data%State%Annular%ODDrillpipe_inAnnular>1.99 .and. data%State%Annular%ODDrillpipe_inAnnular<=2.375) then
  56. data%State%AnnularComputational%acoef=-0.2539
  57. data%State%AnnularComputational%Bcoef=994.3
  58. data%State%AnnularComputational%const=73.15
  59. elseif (data%State%Annular%ODDrillpipe_inAnnular>2.375 .and. data%State%Annular%ODDrillpipe_inAnnular<=2.875) then
  60. data%State%AnnularComputational%acoef=-0.2005
  61. data%State%AnnularComputational%Bcoef=745.9
  62. data%State%AnnularComputational%const=57.75
  63. elseif (data%State%Annular%ODDrillpipe_inAnnular>2.875 .and. data%State%Annular%ODDrillpipe_inAnnular<=3.5) then
  64. data%State%AnnularComputational%acoef=-0.1871
  65. data%State%AnnularComputational%Bcoef=696.1
  66. data%State%AnnularComputational%const=53.9
  67. elseif (data%State%Annular%ODDrillpipe_inAnnular>3.5 .and. data%State%Annular%ODDrillpipe_inAnnular<=5) then
  68. data%State%AnnularComputational%acoef=-0.1733
  69. data%State%AnnularComputational%Bcoef=647
  70. data%State%AnnularComputational%const=50
  71. elseif (data%State%Annular%ODDrillpipe_inAnnular>5 .and. data%State%Annular%ODDrillpipe_inAnnular<=10) then
  72. data%State%AnnularComputational%acoef=-0.1604
  73. data%State%AnnularComputational%Bcoef=596.7
  74. data%State%AnnularComputational%const=46.2
  75. endif
  76. data%State%AnnularComputational%AnnularSealingPressure= max((data%State%AnnularComputational%acoef*data%State%AnnularComputational%WellBorePressure+data%State%AnnularComputational%Bcoef), data%State%AnnularComputational%const) !(psi)
  77. else !CSO(COMPLETE SHUT OFF) ODDrillpipe_inAnnular=0
  78. data%State%AnnularComputational%AnnularSealingPressure= 1150. !(psi)
  79. endif
  80. !=====================================================================
  81. ! BYPASS POSITION
  82. !=====================================================================
  83. if(data%Equipments%BopControlPanel%ByePassValve == -1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then
  84. data%State%BopStackAcc%ByPassOld= -1.0
  85. !write(*,*) 'ByePassValve to -1' ,ByePassValve
  86. elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then
  87. data%State%BopStackAcc%ByPassOld= 1.0
  88. !write(*,*) 'ByePassValve to 1=' ,ByePassValve
  89. endif
  90. !write(*,*) 'ByePassValve,ByPassOld=' ,ByePassValve,ByPassOld
  91. !=====================================================================
  92. !WRITE(*,*) 'AnnularRegulatorSetControl====' , AnnularRegulatorSetControl
  93. data%State%Annular%Pannular_regset=min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously
  94. if (data%State%Annular%Annular_closed==1) then
  95. if (data%State%Annular%FirstSet==1) then ! code start
  96. data%State%Annular%Pannular_reg= data%State%Annular%Pannular_regset
  97. endif
  98. if (data%State%Annular%FirstSet==0) then ! durig run, but annular is not closing or opening
  99. data%State%Annular%Pannular_reg= min(data%State%RamLine%P_ACC,data%State%Annular%Pannular_regset)
  100. endif
  101. endif
  102. !===================================================================
  103. ! Annular Preventer Pressure Rise On Tooljoint
  104. !===================================================================
  105. if ( data%State%Annular%Annular_Situation_forTD == 1 .and. data%State%TD_BOP%AnnularFillingFinal==0.0 ) then ! Annular_Situation_forTD= 1 ! closed - for TD code
  106. data%State%AnnularComputational%AnnPressureRise= .true.
  107. elseif ( data%State%Annular%Annular_Situation_forTD == 0 ) then
  108. data%State%AnnularComputational%AnnPressureRise= .false.
  109. endif
  110. if (data%State%AnnularComputational%AnnPressureRise == .true.) then
  111. data%State%Annular%Pannular_reg= data%State%Annular%Pannular_reg + 200. * data%State%TD_BOP%AnnularFillingFinal ! 200 psi pressure rise when 100% of AnnPreventer is filled by tool joint
  112. !TD_AnnularFillingFinal ! (0.0 to 1.0) percentage filled by tool joint
  113. endif
  114. !===================================================================
  115. if (data%State%Annular%FirstSet== 1) then
  116. !new= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.)
  117. CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) )
  118. CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length())
  119. data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last()
  120. !AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.)
  121. !write(*,*) 'set 1' , AnnularPressureGauge
  122. else !FirstSet== 0
  123. !new= (1 - AnnularPressureGaugeMalf) * Pannular_reg
  124. CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * data%State%Annular%Pannular_reg)
  125. CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length())
  126. data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last()
  127. !AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * Pannular_reg
  128. !write(*,*) 'set 0' , AnnularPressureGauge
  129. endif
  130. !===================================================
  131. ! AIR OPERATED PUMP CODE- START
  132. !===================================================
  133. if (data%State%RamLine%P_ACC<data%State%Pumps%AIR_ON .and. data%State%RamLine%AIRP_SWITCH==0) then
  134. data%State%RamLine%AIRP_SWITCH=1
  135. endif
  136. if (data%State%RamLine%P_ACC>data%State%Pumps%AIR_OFF .and. data%State%RamLine%AIRP_SWITCH==1) then
  137. data%State%RamLine%AIRP_SWITCH=0
  138. call SetSoundKoomeyAirPump(data%State%RamLine%AIRP_SWITCH)
  139. endif
  140. if (data%State%RamLine%P_ACC<data%State%Pumps%ELECTRIC_ON .and. data%State%RamLine%ELECP_SWITCH==0) then
  141. data%State%RamLine%ELECP_SWITCH=1
  142. endif
  143. if (data%State%RamLine%P_ACC>data%State%Pumps%ELECTRIC_OFF .and. data%State%RamLine%ELECP_SWITCH==1) then
  144. data%State%RamLine%ELECP_SWITCH=0
  145. endif
  146. !write(*,*) 'airp_switch,elecp_switch=' , airp_switch,elecp_switch
  147. !================CHARGING BOTTLES=======================
  148. if (data%State%RamLine%AIRP_SWITCH==1 .or. data%State%RamLine%ELECP_SWITCH==1) then
  149. if (data%State%Annular%Annular_closed==1 .and. data%State%RamLine%ShearBop_closed==1 .and. data%State%PipeRam1%closed==1 .and. data%State%PipeRam2%closed==1 .and. data%State%ChokeLine%closed==1 .and. data%State%KillLine%closed==1) then
  150. call pumps_charge_bottle()
  151. ! increases volume and pressure in the bottles
  152. if (data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_ChargedPressure) then
  153. data%State%RamLine%P_ACC=data%State%BopStackAcc%acc_ChargedPressure
  154. if (data%State%Annular%AnnularLeakMalf== 0) then
  155. !finished_Annular=1
  156. data%State%RAM(1)%Bottles_Charged_MalfActive= .false.
  157. else
  158. data%State%Annular%finished_Annular=0
  159. data%State%RAM(1)%Bottles_Charged_MalfActive= .true.
  160. !fvr=fvr-2.5
  161. endif
  162. if (data%State%PipeRam1%UpperRamsLeakMalf== 0) then
  163. !finished_pipe1=1
  164. data%State%RAM(2)%Bottles_Charged_MalfActive= .false.
  165. else
  166. data%State%PipeRam1%finished=0
  167. data%State%RAM(2)%Bottles_Charged_MalfActive= .true.
  168. !fvr=fvr-2.5
  169. endif
  170. if (data%State%PipeRam2%LowerRamsLeakMalf== 0) then
  171. !finished_pipe2=1
  172. data%State%RAM(3)%Bottles_Charged_MalfActive= .false.
  173. else
  174. data%State%PipeRam2%finished=0
  175. data%State%RAM(3)%Bottles_Charged_MalfActive= .true.
  176. !fvr=fvr-2.5
  177. endif
  178. if (data%State%ShearRAM%MiddleRamsLeakMalf== 0) then
  179. !finished_shear=1
  180. data%State%RAM(4)%Bottles_Charged_MalfActive= .false.
  181. else
  182. data%State%RamLine%FINISHED_shear=0
  183. data%State%RAM(4)%Bottles_Charged_MalfActive= .true.
  184. !fvr=fvr-2.5
  185. endif
  186. data%State%KillLine%finished=1
  187. data%State%ChokeLine%finished=1
  188. if (data%State%Annular%AnnularLeakMalf== 0 .and. data%State%PipeRam1%UpperRamsLeakMalf== 0 .and. data%State%PipeRam2%LowerRamsLeakMalf== 0 .and. data%State%ShearRAM%MiddleRamsLeakMalf== 0) then
  189. data%State%RamLine%ELECP_SWITCH=0
  190. data%State%RamLine%AIRP_SWITCH=0
  191. endif
  192. endif
  193. endif
  194. endif
  195. !=======================================================
  196. if (data%State%RamLine%ELECP_SWITCH==1 .and. data%State%BopStackAcc%AccPupmsFailMalf==0) then !on position
  197. data%State%Pumps%DELTAV_ELECP=data%State%Pumps%QELECTRIC*data%State%RamLine%DeltaT_BOP/60. !QELECTRIC_PUMP(gpm), deltav_elecp(gal), DeltaT_BOP(0.1 sec)
  198. data%State%Pumps%SoundKoomeyElectric= .True.
  199. else
  200. data%State%Pumps%DELTAV_ELECP=0
  201. data%State%Pumps%SoundKoomeyElectric= .false.
  202. endif
  203. !call SetSoundKoomeyElectricPump(SoundKoomeyElectricPump)
  204. if (data%State%RamLine%AIRP_SWITCH==1 .and. data%State%BopStackAcc%AccPupmsFailMalf==0) then !on position
  205. call airpump_code() !ramtype=2
  206. end if ! if (airp_switch==1) then !on position
  207. !===============AIR OPERATED PUMP CODE- END================
  208. if (data%State%RamLine%ShearBop_closed==1 .and. data%State%PipeRam1%closed==1 .and. data%State%PipeRam2%closed==1 .and. data%State%ChokeLine%closed==1 .and. data%State%KillLine%closed==1) then
  209. !write(*,*) ' All Rams are closed'
  210. if(data%State%BopStackAcc%ByPassOld== -1.0) then ! (OPEN POSITION)
  211. !old=pram_reg
  212. !new=p_acc- MAXVAL(data%State%RAM%loss_before)
  213. !difference= new-old
  214. data%State%BopStackAcc%PressureDifference= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) - data%State%BopStackAcc%pram_reg
  215. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 300. psi
  216. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  217. else
  218. data%State%BopStackAcc%pram_reg= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) ! mishe khate paeen ye shart gozasht ke pacc=3000 shod, in adad dige kam nashe
  219. endif
  220. elseif (data%State%BopStackAcc%ByPassOld== 1.0) then ! (CLOSE POSITION)
  221. !pram_reg= prams_regset
  222. !if (RamsFirstSet==1) then
  223. !write(*,*) 'bypass CLOSE POSITION'
  224. !old=pram_reg
  225. !new=prams_regset
  226. !difference= new-old
  227. data%State%BopStackAcc%PressureDifference= data%State%BopStackAcc%PRAMS_REGSET - data%State%BopStackAcc%pram_reg
  228. !write(*,*) 'PressureDifference, prams_regset , pram_reg=' , PressureDifference, prams_regset , pram_reg
  229. if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 200. ! psi in starup
  230. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. in startup
  231. else
  232. data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%PRAMS_REGSET
  233. endif
  234. !write(*,*) 'pram_reg=' , pram_reg
  235. !endif ! if (RamsFirstSet==1) then
  236. endif
  237. endif
  238. data%Equipments%BopControlPanel%MiddleRamsStatus = data%State%ShearRAM%IDshearBop
  239. data%Equipments%BopControlPanel%UpperRamsStatus = data%State%PipeRam1%ID
  240. data%Equipments%BopControlPanel%LowerRamsStatus = data%State%PipeRam2%ID
  241. data%Equipments%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular
  242. data%Equipments%BopControlPanel%AccumulatorPressureGauge = (1 - data%State%BopStackAcc%AccumulatorPressureGaugeMalf) * data%State%RamLine%P_ACC
  243. data%Equipments%BopControlPanel%ManifoldPressureGauge= (1 - data%State%BopStackAcc%ManifoldPressureGaugeMalf) * data%State%BopStackAcc%pram_reg
  244. !AnnularPressureGauge=Pannular_reg
  245. !
  246. ! WRITE(60,60) data%State%RAM(2)%time,data%State%RAM(2)%Q,data%State%RAM(2)%vdis_tot,p_acc, &
  247. ! pram_reg,Pannular_reg,data%State%RAM(2)%p_bop,IDshearBop, &
  248. ! IDPipeRam1,IDPipeRam2,IDAnnular
  249. !60 FORMAT(11(f18.5))
  250. !WRITE(*,*) 'IDAnnular=' , IDAnnular
  251. !write(*,*) 'elecp_switch=' , elecp_switch
  252. !call sleepqq(100)
  253. end subroutine BopStack_Step
  254. end module BOP