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