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.

1 jaar geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. BOP_timeCounter= BOP_timeCounter + 1
  11. write(*,*) 'BOP_timeCounter=' , BOP_timeCounter
  12. AirSupplyPressureGauge= (1 - AirSupplyPressureGaugeMalf)* (1 - RigAirMalf) *120. !psi
  13. if (pram_reg < 2300.) then
  14. ShearIsNotAllowed= 1
  15. else
  16. 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. ODDrillpipe_inAnnular= TD_AnnularPreventerDiam * 12.0 ! ft to inch
  26. ODDrillpipe_inPipeRam1= TD_UpperRamDiam * 12.0
  27. ODDrillpipe_inShearRam= TD_BlindRamDiam * 12.0
  28. ODDrillpipe_inPipeRam2= TD_LowerRamDiam * 12.0
  29. !IDshearBopFinal
  30. !IDPipeRam1Final
  31. !IDPipeRam2Final
  32. !IDAnnularFinal
  33. OpenArea_shearBop= PI*(IDshearBopFinal**2-ODDrillpipe_inShearRam**2)/4.0d0 !D(in), AREA(in^2)
  34. OpenArea_PipeRam1= PI*(IDPipeRam1Final**2-ODDrillpipe_inPipeRam1**2)/4.0d0 !D(in), AREA(in^2)
  35. OpenArea_PipeRam2= PI*(IDPipeRam2Final**2-ODDrillpipe_inPipeRam2**2)/4.0d0 !D(in), AREA(in^2)
  36. OpenArea_Annular= PI*(IDAnnularFinal**2-ODDrillpipe_inAnnular**2)/4.0d0 !D(in), AREA(in^2)
  37. MinimumOpenArea_InBOP= min(OpenArea_shearBop,OpenArea_PipeRam1,OpenArea_PipeRam2,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. WellBorePressure=5000.
  46. if (ODDrillpipe_inAnnular>0.) then
  47. if (ODDrillpipe_inAnnular>0. .and. ODDrillpipe_inAnnular<=1.99) then
  48. acoef=-0.2673
  49. bcoef=994.3
  50. const=77
  51. elseif (ODDrillpipe_inAnnular>1.99 .and. ODDrillpipe_inAnnular<=2.375) then
  52. acoef=-0.2539
  53. bcoef=994.3
  54. const=73.15
  55. elseif (ODDrillpipe_inAnnular>2.375 .and. ODDrillpipe_inAnnular<=2.875) then
  56. acoef=-0.2005
  57. bcoef=745.9
  58. const=57.75
  59. elseif (ODDrillpipe_inAnnular>2.875 .and. ODDrillpipe_inAnnular<=3.5) then
  60. acoef=-0.1871
  61. bcoef=696.1
  62. const=53.9
  63. elseif (ODDrillpipe_inAnnular>3.5 .and. ODDrillpipe_inAnnular<=5) then
  64. acoef=-0.1733
  65. bcoef=647
  66. const=50
  67. elseif (ODDrillpipe_inAnnular>5 .and. ODDrillpipe_inAnnular<=10) then
  68. acoef=-0.1604
  69. bcoef=596.7
  70. const=46.2
  71. endif
  72. AnnularSealingPressure= max((acoef*WellBorePressure+bcoef), const) !(psi)
  73. else !CSO(COMPLETE SHUT OFF) ODDrillpipe_inAnnular=0
  74. AnnularSealingPressure= 1150. !(psi)
  75. endif
  76. !=====================================================================
  77. ! BYPASS POSITION
  78. !=====================================================================
  79. if(ByePassValve == -1.0 .and. AirMasterValve==1) then
  80. ByPassOld= -1.0
  81. !write(*,*) 'ByePassValve to -1' ,ByePassValve
  82. elseif(ByePassValve == 1.0 .and. AirMasterValve==1) then
  83. ByPassOld= 1.0
  84. !write(*,*) 'ByePassValve to 1=' ,ByePassValve
  85. endif
  86. !write(*,*) 'ByePassValve,ByPassOld=' ,ByePassValve,ByPassOld
  87. !=====================================================================
  88. !WRITE(*,*) 'AnnularRegulatorSetControl====' , AnnularRegulatorSetControl
  89. Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously
  90. if (Annular_closed==1) then
  91. if (FirstSet==1) then ! code start
  92. Pannular_reg= Pannular_regset
  93. endif
  94. if (FirstSet==0) then ! durig run, but annular is not closing or opening
  95. Pannular_reg= min(p_acc,Pannular_regset)
  96. endif
  97. endif
  98. !===================================================================
  99. ! Annular Preventer Pressure Rise On Tooljoint
  100. !===================================================================
  101. if ( Annular_Situation_forTD == 1 .and. TD_AnnularFillingFinal==0.0 ) then ! Annular_Situation_forTD= 1 ! closed - for TD code
  102. AnnPressureRise= .true.
  103. elseif ( Annular_Situation_forTD == 0 ) then
  104. AnnPressureRise= .false.
  105. endif
  106. if (AnnPressureRise == .true.) then
  107. Pannular_reg= 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 (FirstSet== 1) then
  112. !new= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.)
  113. CALL Pannular_regDelay%AddToFirst( (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.) )
  114. CALL Pannular_regDelay%Remove(Pannular_regDelay%Length())
  115. AnnularPressureGauge= 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 Pannular_regDelay%AddToFirst( (1 - AnnularPressureGaugeMalf) * Pannular_reg)
  121. CALL Pannular_regDelay%Remove(Pannular_regDelay%Length())
  122. AnnularPressureGauge= 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 (p_acc<AIR_PUMPON .and. airp_switch==0) then
  130. airp_switch=1
  131. endif
  132. if (p_acc>AIR_PUMPOFF .and. airp_switch==1) then
  133. airp_switch=0
  134. call SetSoundKoomeyAirPump(airp_switch)
  135. endif
  136. if (p_acc<ELECTRIC_PUMPON .and. elecp_switch==0) then
  137. elecp_switch=1
  138. endif
  139. if (p_acc>ELECTRIC_PUMPOFF .and. elecp_switch==1) then
  140. elecp_switch=0
  141. endif
  142. !write(*,*) 'airp_switch,elecp_switch=' , airp_switch,elecp_switch
  143. !================CHARGING BOTTLES=======================
  144. if (airp_switch==1 .or. elecp_switch==1) then
  145. if (Annular_closed==1 .and. 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 (p_acc>acc_ChargedPressure) then
  149. p_acc=acc_ChargedPressure
  150. if (AnnularLeakMalf== 0) then
  151. !finished_Annular=1
  152. RAM(1)%Bottles_Charged_MalfActive= .false.
  153. else
  154. finished_Annular=0
  155. RAM(1)%Bottles_Charged_MalfActive= .true.
  156. !fvr=fvr-2.5
  157. endif
  158. if (UpperRamsLeakMalf== 0) then
  159. !finished_pipe1=1
  160. RAM(2)%Bottles_Charged_MalfActive= .false.
  161. else
  162. finished_pipe1=0
  163. RAM(2)%Bottles_Charged_MalfActive= .true.
  164. !fvr=fvr-2.5
  165. endif
  166. if (LowerRamsLeakMalf== 0) then
  167. !finished_pipe2=1
  168. RAM(3)%Bottles_Charged_MalfActive= .false.
  169. else
  170. finished_pipe2=0
  171. RAM(3)%Bottles_Charged_MalfActive= .true.
  172. !fvr=fvr-2.5
  173. endif
  174. if (MiddleRamsLeakMalf== 0) then
  175. !finished_shear=1
  176. RAM(4)%Bottles_Charged_MalfActive= .false.
  177. else
  178. finished_shear=0
  179. RAM(4)%Bottles_Charged_MalfActive= .true.
  180. !fvr=fvr-2.5
  181. endif
  182. finished_KillLine=1
  183. finished_ChokeLine=1
  184. if (AnnularLeakMalf== 0 .and. UpperRamsLeakMalf== 0 .and. LowerRamsLeakMalf== 0 .and. MiddleRamsLeakMalf== 0) then
  185. elecp_switch=0
  186. airp_switch=0
  187. endif
  188. endif
  189. endif
  190. endif
  191. !=======================================================
  192. if (elecp_switch==1 .and. AccPupmsFailMalf==0) then !on position
  193. deltav_elecp=QELECTRIC_PUMP*DeltaT_BOP/60. !QELECTRIC_PUMP(gpm), deltav_elecp(gal), DeltaT_BOP(0.1 sec)
  194. SoundKoomeyElectricPump= .True.
  195. else
  196. deltav_elecp=0
  197. SoundKoomeyElectricPump= .false.
  198. endif
  199. !call SetSoundKoomeyElectricPump(SoundKoomeyElectricPump)
  200. if (airp_switch==1 .and. 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 (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(ByPassOld== -1.0) then ! (OPEN POSITION)
  207. !old=pram_reg
  208. !new=p_acc- MAXVAL(RAM%loss_before)
  209. !difference= new-old
  210. PressureDifference= p_acc- MAXVAL(RAM%loss_before) - pram_reg
  211. if (ABS(PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 300. psi
  212. pram_reg= pram_reg + (PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20.
  213. else
  214. pram_reg= 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 (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. PressureDifference= prams_regset - pram_reg
  224. !write(*,*) 'PressureDifference, prams_regset , pram_reg=' , PressureDifference, prams_regset , pram_reg
  225. if (ABS(PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 200. ! psi in starup
  226. pram_reg= pram_reg + (PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. in startup
  227. else
  228. pram_reg= prams_regset
  229. endif
  230. !write(*,*) 'pram_reg=' , pram_reg
  231. !endif ! if (RamsFirstSet==1) then
  232. endif
  233. endif
  234. MiddleRamsStatus = IDshearBop
  235. UpperRamsStatus = IDPipeRam1
  236. LowerRamsStatus = IDPipeRam2
  237. AnnularStatus = IDAnnular
  238. AccumulatorPressureGauge = (1 - AccumulatorPressureGaugeMalf) * p_acc
  239. ManifoldPressureGauge= (1 - ManifoldPressureGaugeMalf) * 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