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.
 
 
 
 
 
 

299 lines
15 KiB

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