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.
 
 
 
 
 
 

724 lines
39 KiB

  1. SUBROUTINE WellPressureDataTransfer
  2. !! This subroutine calculates pressure distribution in well
  3. !! We divide well hydraulic system to 4 zones. 1- pump to string zone; this zone is horizontal
  4. !! 2- string zone; this zone includes drill pipes and collars and is vertical or neraly vertical
  5. !! 3- annulus zone; this zone includes annulus space between string and openhole or casing
  6. !! 4- Openhole zone; this zone includes spaces under bit to bottom of the wellbore
  7. !! The last two zone includes annulus space and open hole, are influenced by kicks and have crucial role in
  8. !! computing pressure distribution because reference point (back pressure in well head open condition
  9. !! and bottomhole pressure in well head closed condition) are in one of them. because of this, pressure
  10. !! distribution calculates in two subroutines : PressureAnnAndOHDistribution and PressurePumptoBitDistribution
  11. !! pressure change through well consist of pressure change due to friction, change of elevation and acceleration
  12. !! frictional pressure drop calculated by subroutine Sub_Press_Drop_Calculator
  13. !! This subroutine includes hydrostatic pressure and later will include effect of corss-section area change
  14. !! which causes acceleration or decceleration of flow
  15. USE FricPressDropVarsModule
  16. use MudSystemModule
  17. USE MudSystemVARIABLES
  18. use SimulationVariables !@@@
  19. USE GeoElements_FluidModule
  20. USE Fluid_Flow_Startup_Vars
  21. use KickVARIABLESModule
  22. ! USE CMudPropertiesVariables
  23. ! USE CBopStackVariables
  24. ! USE sROP_Variables
  25. ! USE CHOKEVARIABLES
  26. ! use CChokeManifoldVariables
  27. ! use SimulationVariables
  28. ! USE CBitProblemsVariables
  29. ! USE CChokeProblemsVariables
  30. ! USE CStringConfigurationVariables
  31. ! use CDataDisplayConsole
  32. IMPLICIT NONE
  33. INTEGER :: i , j
  34. REAL :: InstantaneousTotalOpenChokeArea , VolumeDensityProduct
  35. KickVARIABLES%ChokeIsClosing = .FALSE.
  36. data%State%FricPressDrop%Kchoke = 0.0
  37. data%State%FricPressDrop%KBit = 0.0
  38. !!!!!!!!!!!!!!!! bit is present
  39. BitTrue = data%Configuration%StringConfiguration%StringConfigurations(1)%ComponentType == Bit_ComponentType ! Bit_ComponentType = 0
  40. BitCd = 0.98
  41. BitNozzDia = 32.0 * data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! nozzle diameter in 1/32 in
  42. BitNozzleArea = 7.6699E-4 * BitNozzDia**2
  43. BitNozzleNum = data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo - data%State%FricPressDrop%BitJetsPlugged * data%problems%BitProblems%PlugJetsCount
  44. BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * data%State%FricPressDrop%BitJetsWashedOut * data%problems%BitProblems%JetWashoutCount * BitNozzleArea
  45. IF (BitNozzleNum == 0) THEN
  46. data%State%FricPressDrop%BitTotallyPluged = .TRUE.
  47. ELSE
  48. data%State%FricPressDrop%BitTotallyPluged = .FALSE.
  49. END IF
  50. data%State%FricPressDrop%FloatValveIn = data%Configuration%StringConfiguration%BitDefinition%FloatValve
  51. !FloatValveOpen = .TRUE.
  52. !IF (JetWashoutCount > 0 .OR. PlugJetsCount > 0) THEN
  53. ! WRITE (*,*) 'PlugJetsCount' , PlugJetsCount
  54. ! WRITE (*,*) 'JetWashoutCount', JetWashoutCount
  55. !END IF
  56. !WRITE (*,*) 'BitNozzleNum', BitNozzleNum
  57. !WRITE (*,*) 'BitTotNozzArea', BitTotNozzArea
  58. !WRITE (*,*) 'Float Valve??', BitDefinition%FloatValve
  59. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  60. IF(ALLOCATED(KickVARIABLES%GasPocketFlowEl)) DEALLOCATE(KickVARIABLES%GasPocketFlowEl)
  61. !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed )
  62. KickVARIABLES%ChokeKroneckerDelta = 0
  63. IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
  64. KickVARIABLES%WellHeadOpen = .FALSE.
  65. !WRITE (*,*) ' Well Head is closed '
  66. ELSE
  67. KickVARIABLES%WellHeadOpen = .TRUE.
  68. END IF
  69. IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1
  70. !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
  71. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  72. data%State%FricPressDrop%NoHorizontalEl = data%State%MudSystem%NoHorizontalMudElements
  73. data%State%FricPressDrop%NoStringEl = data%State%MudSystem%NoStringMudElements
  74. data%State%FricPressDrop%NoAnnulusEl = data%State%MudSystem%NoCasingMudElements
  75. data%State%FricPressDrop%NoWellToChokeEl = 0
  76. IF (KickVARIABLES%ChokeKroneckerDelta == 1) data%State%FricPressDrop%NoWellToChokeEl = data%State%MudSystem%ChokeLine_Density%Length()
  77. data%State%FricPressDrop%NoOpenHoleEl = data%State%MudSystem%NoBottomHoleMudElements
  78. data%State%FricPressDrop%NumbEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWellToChokeEl + data%State%FricPressDrop%NoOpenHoleEl
  79. IF(ALLOCATED(FlowEl)) DEALLOCATE(FlowEl)
  80. ALLOCATE(FlowEl(data%State%FricPressDrop%NumbEl))
  81. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Transfering Data from module:MudSystemVARIABLES to module:FricPressDropVars to calculate Pressure distribution in flow path
  82. !!!!!!!!!!!!!!!!!!!!!!! Horizontal line
  83. !WRITE (*,*) 'H', NoHorizontalEl
  84. DO i = 1 , data%State%FricPressDrop%NoHorizontalEl
  85. ! WRITE (*,*) 'H , i' , i
  86. FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i)
  87. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  88. FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i)
  89. !WRITE (*,*) 'Endx', FlowEl(i)%EndX
  90. FlowEl(i)%StartTVD = 0.d0
  91. FlowEl(i)%EndTVD = 0.d0
  92. FlowEl(i)%Id = 0.0
  93. FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i)
  94. FlowEl(i)%density = data%State%MudSystem%Density_MudElement%Array(i)
  95. FlowEl(i)%Dhyd = FlowEl(i)%Od
  96. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  97. FlowEl(i)%DepthDiff = 0.d0
  98. FlowEl(i)%Volume = PI / 4.0 * FlowEl(i)%Od**2 * REAL(FlowEl(i)%Length) / Convfttoinch**2
  99. IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  100. FlowEl(i)%MaterialType = 0
  101. ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN
  102. FlowEl(i)%MaterialType = 4
  103. ELSE
  104. FlowEl(i)%MaterialType = 1
  105. END IF
  106. FlowEl(i)%dPdLgrav = 0.0
  107. FlowEl(i)%StaticPressDiff = 0.0
  108. END DO
  109. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  110. !!!!!!!!!!!!!!!!!!!!!!!!! String
  111. data%State%FricPressDrop%StringFirstEl = data%State%FricPressDrop%NoHorizontalEl + 1
  112. data%State%FricPressDrop%StringLastEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl
  113. DO i = data%State%FricPressDrop%NoHorizontalEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl
  114. ! WRITE (*,*) 'ST , i' , i
  115. FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i)
  116. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  117. FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i)
  118. !WRITE (*,*) 'Endx', FlowEl(i)%EndX
  119. FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_MudElement%Array(i)
  120. !WRITE (*,*) 'StartTVD', FlowEl(i)%StartTVD
  121. FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_MudElement%Array(i)
  122. !WRITE (*,*) 'EndTVD', FlowEl(i)%EndTVD
  123. FlowEl(i)%Id = 0.0
  124. !WRITE (*,*) 'Id', FlowEl(i)%Id
  125. FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i)
  126. !WRITE (*,*) 'Od', FlowEl(i)%Od
  127. FlowEl(i)%Density = data%State%MudSystem%Density_MudElement%Array(i)
  128. !WRITE (*,*) 'Density', FlowEl(i)%Density
  129. FlowEl(i)%Dhyd = FlowEl(i)%Od
  130. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  131. !WRITE (*,*) 'Length', FlowEl(i)%Length
  132. FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
  133. !WRITE (*,*) 'DepthDiff', FlowEl(i)%DepthDiff
  134. FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
  135. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  136. IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  137. FlowEl(i)%MaterialType = 0
  138. ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN
  139. FlowEl(i)%MaterialType = 4
  140. ELSE
  141. FlowEl(i)%MaterialType = 1
  142. END IF
  143. IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN
  144. FlowEl(i)%dPdLgrav = 0.0
  145. ELSE
  146. FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%Density
  147. END IF
  148. FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff)
  149. END DO
  150. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  151. !!!!!!!!!!!!!!!!!!!!!!!!!!!! Annulus
  152. data%State%FricPressDrop%AnnulusFirstEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + 1
  153. data%State%FricPressDrop%AnnulusLastEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl
  154. DO i = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl
  155. ! WRITE (*,*) 'AN , i' , i
  156. FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i)
  157. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  158. FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i)
  159. !WRITE (*,*) 'Endx', FlowEl(i)%EndX
  160. FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_MudElement%Array(i)
  161. FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_MudElement%Array(i)
  162. FlowEl(i)%Id = data%State%MudSystem%PipeID_MudElement%Array(i)
  163. FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i)
  164. FlowEl(i)%Density = data%State%MudSystem%Density_MudElement%Array(i)
  165. FlowEl(i)%Dhyd = FlowEl(i)%Od - FlowEl(i)%Id
  166. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  167. FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
  168. FlowEl(i)%Area = PI / 4.0 * (FlowEl(i)%Od**2 - FlowEl(i)%Id**2) / Convfttoinch**2
  169. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  170. IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  171. FlowEl(i)%MaterialType = 0
  172. ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN
  173. FlowEl(i)%MaterialType = 4
  174. ELSE
  175. FlowEl(i)%MaterialType = 1
  176. END IF
  177. IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN
  178. FlowEl(i)%dPdLgrav = 0.0
  179. ELSE
  180. FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density
  181. END IF
  182. FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff)
  183. END DO
  184. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  185. !!!!!!!!!!!!!!! Well to choke manifold path
  186. j = 1
  187. DO i = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWelltoChokeEl
  188. ! WRITE (*,*) 'CH , i' , i
  189. FlowEl(i)%StartX = data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(j)
  190. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  191. FlowEl(i)%EndX = data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(j)
  192. !WRITE (*,*) 'Endx', FlowEl(i)%EndX
  193. FlowEl(i)%StartTVD = 0.d0
  194. FlowEl(i)%EndTVD = 0.d0
  195. FlowEl(i)%Id = 0.0
  196. FlowEl(i)%Od = data%Configuration%BopStack%ChokeLineId
  197. FlowEl(i)%density = data%State%MudSystem%ChokeLine_Density%Array(j)
  198. FlowEl(i)%Dhyd = FlowEl(i)%Od
  199. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  200. FlowEl(i)%DepthDiff = 0.d0
  201. FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
  202. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  203. IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(j) == 0 .OR. data%State%MudSystem%ChokeLine_MudOrKick%Array(j) == 4) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  204. FlowEl(i)%MaterialType = data%State%MudSystem%ChokeLine_MudOrKick%Array(j)
  205. ELSE
  206. FlowEl(i)%MaterialType = 1
  207. END IF
  208. FlowEl(i)%dPdLgrav = 0.0
  209. FlowEl(i)%StaticPressDiff = 0.0
  210. !WRITE (*,*) 'Ch density, length, Type' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  211. j = j + 1
  212. END DO
  213. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  214. !!!!!!!!!!!!!!! Open Hole
  215. data%State%FricPressDrop%OpenholeFirstEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWelltoChokeEl + 1
  216. j = 1
  217. DO i = data%State%FricPressDrop%OpenholeFirstEl , data%State%FricPressDrop%NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl
  218. ! WRITE (*,*) 'OP , i' , i
  219. FlowEl(i)%StartX = data%State%MudSystem%Xstart_OpMudElement%Array(j)
  220. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  221. FlowEl(i)%EndX = data%State%MudSystem%Xend_OpMudElement%Array(j)
  222. !WRITE (*,*) 'Endx', FlowEl(i)%EndX
  223. FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_OpMudElement%Array(j)
  224. FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_OpMudElement%Array(j)
  225. FlowEl(i)%Id = 0.0
  226. FlowEl(i)%Od = data%State%MudSystem%PipeOD_OpMudElement%Array(j)
  227. FlowEl(i)%density = data%State%MudSystem%Density_OpMudElement%Array(j)
  228. FlowEl(i)%MaterialType = data%State%MudSystem%MudTypeOp_MudElement%Array(j) ! = 0 for mud, = 1 for gas kick, = 4 for air
  229. FlowEl(i)%Dhyd = FlowEl(i)%Od
  230. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  231. FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
  232. FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
  233. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  234. IF (data%State%MudSystem%MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  235. FlowEl(i)%MaterialType = 0
  236. ELSE IF (data%State%MudSystem%MudTypeOp_MudElement%Array(j) == 4) THEN
  237. FlowEl(i)%MaterialType = 4
  238. ELSE
  239. FlowEl(i)%MaterialType = 1
  240. END IF
  241. j = j + 1
  242. IF (FlowEl(i)%MaterialType == 1) THEN
  243. FlowEl(i)%dPdLgrav = 0.0
  244. ELSE
  245. FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density
  246. END IF
  247. FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff)
  248. !WRITE (*,*) 'O density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  249. END DO
  250. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  251. !!!!!!!!!!!!!!!!!! Mud Element Viscosity Calculation
  252. DO i = 1 , data%State%FricPressDrop%NumbEl
  253. IF (FlowEl(i)%MaterialType /= 0) CYCLE
  254. IF (FlowEl(i)%density < 8.33) THEN
  255. WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%StringFirstEl , data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%OpenHoleFirstEl
  256. WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type'
  257. DO j = 1 , data%State%FricPressDrop%NumbEl
  258. WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType
  259. END DO
  260. CALL ErrorStop('Density below water density (8.33)', i)
  261. CYCLE
  262. END IF
  263. FlowEl(i)%Theta600 = Theta600Refrence + 11.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence)
  264. FlowEl(i)%Theta300 = Theta300Refrence + 6.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence)
  265. !WRITE (*,*) 'i, Theta600, Theta600', i, FlowEl(i)%Theta600, FlowEl(i)%Theta300
  266. END DO
  267. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  268. FlowEl(:)%FlowRate = 0.0
  269. FlowEl(:)%StartPress = 0.0
  270. FlowEl(:)%EndPress = 0.0
  271. !WRITE (*,*) 'NoGasPocket=' , SIZE(GasPocketWeight%Array)
  272. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  273. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  274. data%State%MudSystem%OpenArea32 = ((data%Equipments%ChokeManifold%LeftManualChoke * (1.0 - data%State%FricPressDrop%ManChoke1Plug * REAL(data%problems%ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke1Washout) * data%State%Choke%ChokeAreaFullyOpen
  275. data%State%MudSystem%OpenArea33 = data%State%CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen
  276. data%State%MudSystem%OpenArea34 = data%State%CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen
  277. data%State%MudSystem%OpenArea35 = ((data%Equipments%ChokeManifold%RightManualChoke * (1.0 - data%State%FricPressDrop%ManChoke2Plug * REAL(data%problems%ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke2Washout) * data%State%Choke%ChokeAreaFullyOpen
  278. !write(*,*) 'OpenArea32=' , OpenArea32, active32, ManChoke1Plug, ManualChoke1PluggedPercent, ManChoke1Washout
  279. !write(*,*) 'OpenArea33=' , OpenArea33, active33
  280. !write(*,*) 'OpenArea34=' , OpenArea34, active34, !HydraulicChoke2PluggedPercent
  281. !write(*,*) 'OpenArea35=' , OpenArea35, active35, ManChoke2Plug, ManualChoke2PluggedPercent, ManChoke2Washout
  282. InstantaneousTotalOpenChokeArea = data%State%MudSystem%OpenArea32 * active32 + data%State%MudSystem%OpenArea33 * active33 + data%State%MudSystem%OpenArea34 * active34 + data%State%MudSystem%OpenArea35 * active35 + data%State%FricPressDrop%ChokeBypassArea * active29
  283. data%State%FricPressDrop%OldTotalOpenChokeArea = data%State%FricPressDrop%TotalOpenChokeArea
  284. !WRITE (*,*) 'Instantaneous / Old TotalOpenChokeArea', InstantaneousTotalOpenChokeArea, OldTotalOpenChokeArea
  285. IF (data%State%FricPressDrop%OldTotalOpenChokeArea <= 0.01 * data%State%Choke%ChokeAreaFullyOpen) data%State%FricPressDrop%OldTotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen
  286. IF (InstantaneousTotalOpenChokeArea <= 0.01 * data%State%Choke%ChokeAreaFullyOpen) THEN
  287. data%State%MudSystem%WellToChokeManifoldOpen = .FALSE.
  288. data%State%FricPressDrop%OldTotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen
  289. !WRITE (*,*) ' Choke Controler Here 2'
  290. ELSE IF (InstantaneousTotalOpenChokeArea > 0.5 * data%State%Choke%ChokeAreaFullyOpen .OR. data%State%MudSystem%WellToPitsOpen) THEN
  291. ! mud flows through well to bell nipple, or choke is rather open
  292. data%State%FricPressDrop%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea
  293. !WRITE (*,*) ' Choke Controler Here 1'
  294. ELSE
  295. IF (InstantaneousTotalOpenChokeArea > data%State%FricPressDrop%OldTotalOpenChokeArea) THEN
  296. data%State%FricPressDrop%TotalOpenChokeArea = MIN(1.1 * data%State%FricPressDrop%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea)
  297. WRITE (*,*) ' Choke is opening' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea
  298. ELSE IF (InstantaneousTotalOpenChokeArea < data%State%FricPressDrop%OldTotalOpenChokeArea) THEN
  299. data%State%FricPressDrop%TotalOpenChokeArea = MAX(0.9 * data%State%FricPressDrop%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea)
  300. WRITE (*,*) ' Choke is closing' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea
  301. ELSE
  302. data%State%FricPressDrop%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea
  303. END IF
  304. END IF
  305. !WRITE (*,*) 'TotalOpenChokeArea=', TotalOpenChokeArea
  306. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  307. !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed )
  308. KickVARIABLES%ChokeKroneckerDelta = 0
  309. !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
  310. !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
  311. IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
  312. !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
  313. !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
  314. KickVARIABLES%WellHeadOpen = .FALSE.
  315. !WRITE (*,*) ' Well Head is closed '
  316. ELSE
  317. KickVARIABLES%WellHeadOpen = .TRUE.
  318. END IF
  319. IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1
  320. !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
  321. !WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, KickVARIABLES%WellToChokeManifoldWasOpen
  322. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  323. IF (KickVARIABLES%NoGasPocket > 0) THEN
  324. IF (data%State%MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0) THEN
  325. !WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', Choke_Kick_Saved_Volume_Final, (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)
  326. KickVARIABLES%ExitMass = REAL(data%State%MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket)
  327. !IF (NoGasPocket > 1) ExitMass = ExitMass + (SUM(GasPocketDeltaVol%Array(1 : NoGasPocket - 1)) / GasPocketNewVol%Array(NoGasPocket)) * GasPocketWeight%Array(NoGasPocket)
  328. !WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, data%State%MudSystem%StringFlowRate * dt / ConvMinToSec
  329. IF (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%MaterialType /= 1) THEN
  330. CALL RemoveGasPocket(KickVARIABLES%NoGasPocket)
  331. WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', data%State%MudSystem%Choke_Kick_Saved_Volume_Final
  332. END IF
  333. END IF
  334. !NoGasPocket = SIZE(GasPocketWeight%Array)
  335. IF (KickVARIABLES%NoGasPocket > 0) CALL GasPocketFlowElementTransformer
  336. END IF
  337. IF (data%State%FricPressDrop%NoWelltoChokeEl > 0) THEN
  338. KickVARIABLES%OldChokeDensity = KickVARIABLES%ChokeDensity
  339. VolumeDensityProduct = 0.0
  340. Do i = data%State%FricPressDrop%AnnulusLastEl + 1 , data%State%FricPressDrop%OpenholeFirstEl - 1
  341. VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , KickVARIABLES%ChokeMinDensity)) * FlowEl(i)%Volume)
  342. End Do
  343. KickVARIABLES%ChokeDensity = VolumeDensityProduct / SUM(FlowEl(data%State%FricPressDrop%AnnulusLastEl + 1 : data%State%FricPressDrop%OpenholeFirstEl - 1)%Volume)
  344. !WRITE (*,*) 'ChokeDensity=', KickVARIABLES%ChokeDensity
  345. data%State%FricPressDrop%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * data%State%FricPressDrop%TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte
  346. END IF
  347. IF (data%State%FricPressDrop%BitTotallyPluged == .FALSE.) THEN
  348. data%State%FricPressDrop%KBit = FlowEl(data%State%FricPressDrop%StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2
  349. END IF
  350. END SUBROUTINE WellPressureDataTransfer
  351. SUBROUTINE GasPocketFlowElementTransformer
  352. !! This Subroutine makes relationship between fluid flow elements and gas pocket elements
  353. !! The main variable of this subroutine is GasPocketFlowEl
  354. !! For each gas pocket, GasPocketFlowEl has a row, which columns are numbers of flow elements which are contains that gas pocket
  355. !! For example, if we have two gas pockets and they are in (7,8) and (12,3,4) flow elements respectively,
  356. !! GasPocketFlowEl(1,:) = [12 , 3 , 4] and GasPocketFlowEl(2,:) = [7 , 8 , 0]
  357. USE FricPressDropVarsModule
  358. USE MudSystemVARIABLES
  359. use SimulationVariables !@@@
  360. USE GeoElements_FluidModule
  361. USE Fluid_Flow_Startup_Vars
  362. use KickVARIABLESModule
  363. USE CMudPropertiesVariables
  364. USE CBopStackVariables
  365. USE CDownHoleVariables
  366. USE CError
  367. IMPLICIT NONE
  368. INTEGER :: i , j , k
  369. REAL :: PressureCorrection
  370. PressureCorrection = 1.0
  371. ALLOCATE(KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1))
  372. KickVARIABLES%GasPocketFlowEl(:,:) = 0
  373. !WRITE (*,*) 'NoGasPocket=' , NoGasPocket
  374. i = 1
  375. j = 1
  376. DO k = data%State%FricPressDrop%OpenholeFirstEl , data%State%FricPressDrop%NumbEl
  377. IF (FlowEl(k)%MaterialType == 1) THEN
  378. IF (j > 1) THEN
  379. IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN
  380. i = i + 1
  381. j = 1
  382. END IF
  383. END IF
  384. IF (SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) < j) THEN
  385. ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)))
  386. KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl
  387. DEALLOCATE(KickVARIABLES%GasPocketFlowEl)
  388. ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1))
  389. KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl
  390. KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0
  391. DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl)
  392. END IF
  393. KickVARIABLES%GasPocketFlowEl(i , j) = k
  394. j = j + 1
  395. END IF
  396. END DO
  397. !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl
  398. DO k = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%OpenholeFirstEl - 1
  399. IF (FlowEl(k)%MaterialType == 1) THEN
  400. IF (j > 1) THEN
  401. IF (k == data%State%FricPressDrop%AnnulusFirstEl .AND. KickVARIABLES%GasPocketFlowEl(i , j - 1) == data%State%FricPressDrop%NumbEl) THEN
  402. !WRITE (*,*) 'Kick is Around Bit'
  403. ELSE IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN
  404. i = i + 1
  405. j = 1
  406. !WRITE (*,*) 'i, j, k', i, j, k, FlowEl(k)%MaterialType
  407. END IF
  408. END IF
  409. IF (j > SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) THEN
  410. ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)))
  411. KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl
  412. DEALLOCATE(KickVARIABLES%GasPocketFlowEl)
  413. ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1))
  414. KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl
  415. KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0
  416. DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl)
  417. END IF
  418. IF (i > KickVARIABLES%NoGasPocket) THEN
  419. WRITE (*,*) 'GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl
  420. WRITE (*,*) 'i , j , k', i, j, k
  421. WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%StringFirstEl , data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%OpenHoleFirstEl
  422. WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type'
  423. DO j = 1 , data%State%FricPressDrop%NumbEl
  424. WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType
  425. END DO
  426. CALL ErrorStop('Error in calculating GasPocketFlowEl')
  427. END IF
  428. KickVARIABLES%GasPocketFlowEl(i , j) = k
  429. !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl
  430. j = j + 1
  431. END IF
  432. !IF (i > NoGasPocket) CALL ErrorStop('Error in GasPocketFlowEl' , i)
  433. END DO
  434. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  435. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  436. GasPocketModifiedVol%Array(:) = 0.d0
  437. DO i = 1 , KickVARIABLES%NoGasPocket
  438. !WRITE(*,*) 'GasPocketFlowEl Data' , i , GasPocketFlowEl(: , i)
  439. DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)
  440. IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Volume
  441. END DO
  442. END DO
  443. i = data%State%FricPressDrop%AnnulusLastEl
  444. j = data%State%FricPressDrop%OpenholeFirstEl - 1
  445. GasPocketOldVol%Array(:) = GasPocketModifiedVol%Array(:)
  446. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  447. !WRITE (*,*) ' GasPocketweight%Array(1)', GasPocketweight%Array(1)
  448. IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickVARIABLES%KickmdotBCoef)
  449. GasPocketDensity%Array(:) = (GasPocketweight%Array(:) / GasPocketModifiedVol%Array(:)) / convft3toUSgal ! [lbm/ft^3 to ppg]
  450. DO i = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1)
  451. DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)
  452. IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i)
  453. END DO
  454. END DO
  455. !WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1)
  456. data%Equipments%DownHole%InfluxRate = MAX(((KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0)
  457. !WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate
  458. i = data%State%FricPressDrop%OpenholeFirstEl - 1
  459. IF (data%State%MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. KickVARIABLES%WellHeadOpen) THEN
  460. WRITE (*,*) 'Kick is exiting through the choke'
  461. !KickVARIABLES%ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + data%State%MudSystem%StringFlowRate) / ConvMinToSec * dt
  462. GasPocketWeight%Array(KickVARIABLES%NoGasPocket) = GasPocketweight%Array(KickVARIABLES%NoGasPocket) - KickVARIABLES%ExitMass
  463. IF (GasPocketWeight%Array(KickVARIABLES%NoGasPocket) > 0.0) THEN
  464. GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) = GasPocketWeight%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * &
  465. GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket)
  466. GasPocketDensity%Array(KickVARIABLES%NoGasPocket) = (GasPocketweight%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket)) / convft3toUSgal
  467. GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:)
  468. ELSE ! gas pocket is escaped from the well completely
  469. WRITE (*,*) ' Last Pocket Removed'
  470. WRITE (*,*) ' GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl
  471. CALL RemoveGasPocket(KickVARIABLES%NoGasPocket)
  472. !WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl
  473. END IF
  474. ELSE IF (KickVARIABLES%NoGasPocket == 1 .OR. KickVARIABLES%WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed
  475. GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:))
  476. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  477. GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:)
  478. ELSE ! Many gas pocket is in the well and well head is closed
  479. 103 FORMAT (2I, 4X, (F9.3), 5X, (F9.3))
  480. GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket)
  481. GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * &
  482. GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket)
  483. !WRITE (*,*) 'Mid'
  484. DO WHILE (ABS(PressureCorrection * 10.0) > KickConvergenceTolerance)
  485. DO j = KickVARIABLES%NoGasPocket - 1 , 1 , -1
  486. CALL KickFunctionsCalculator(GasPocketNewPress%Array(j) , j , 5)
  487. GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * &
  488. GasPocketNewTemp%Array(j) * GasPocketWeight%Array(j) / GasPocketNewPress%Array(j)
  489. !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal)
  490. END DO
  491. PressureCorrection = (SUM(GasPocketNewVol%Array(:)) - SUM(GasPocketOldVol%Array(:))) / SUM(GasPocketNewVol%Array(:) / GasPocketNewPress%Array(:))
  492. GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + PressureCorrection
  493. GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * &
  494. GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket)
  495. j = KickVARIABLES%NoGasPocket
  496. !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal)
  497. END DO
  498. !WRITE (*,*) 'Pressure Correction = ', PressureCorrection
  499. WRITE (*,*) 'After'
  500. DO i = 1 , KickVARIABLES%NoGasPocket
  501. WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal))
  502. END DO
  503. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  504. END IF
  505. IF (KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) == 0) THEN
  506. CALL RemoveGasPocket(1)
  507. !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl
  508. WRITE (*,*) 'First Pocket Removed'
  509. !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl
  510. END IF
  511. data%Equipments%DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0
  512. !WRITE (*,*) ' Gas Kick Pressure (psi) = ' , GasPocketOldPress(1) , INT((GasPocketNewVol(1) / GasPocketOldVol(1)) * 1000.d0) / 1000.d0
  513. !WRITE (*,*) ' b) GasPocketNewVol (ft^3) = ' , GasPocketOldVol(1)
  514. END SUBROUTINE
  515. SUBROUTINE RemoveGasPocket(ilocal)
  516. use KickVARIABLESModule
  517. USE MudSystemVARIABLES
  518. use SimulationVariables !@@@
  519. IMPLICIT NONE
  520. INTEGER :: ilocal
  521. DEALLOCATE(KickVARIABLES%KickJacobian , KickVARIABLES%OldKickJacobian , KickVARIABLES%KickVandPFunction , KickVARIABLES%KickUnknownVector , KickVARIABLES%KickCorrectionVector)
  522. WRITE (*,*) 'Gas Pocket Will be Removed', ilocal
  523. call GasPocketOldPress%Remove(ilocal)
  524. call GasPocketNewPress%Remove(ilocal)
  525. call GasPocketOldTemp%Remove(ilocal)
  526. call GasPocketNewTemp%Remove(ilocal)
  527. call GasPocketOldVol%Remove(ilocal)
  528. call GasPocketNewVol%Remove(ilocal)
  529. call GasPocketDeltaVol%Remove(ilocal)
  530. call GasPocketFlowInduced%Remove(ilocal)
  531. call GasPocketModifiedVol%Remove(ilocal)
  532. call GasPocketWeight%Remove(ilocal)
  533. call GasPocketDensity%Remove(ilocal)
  534. call GasPocketCompressibility%Remove(ilocal)
  535. KickVARIABLES%NoGasPocket = KickVARIABLES%NoGasPocket - 1
  536. IF (KickVARIABLES%NoGasPocket > 0) THEN
  537. ALLOCATE(KickVARIABLES%KickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%OldKickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickVandPFunction(2 * KickVARIABLES%NoGasPocket))
  538. ALLOCATE(KickVARIABLES%KickUnknownVector(2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickCorrectionVector(2 * KickVARIABLES%NoGasPocket))
  539. IF (ALLOCATED(KickVARIABLES%GasPocketFlowEl)) THEN
  540. ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(KickVARIABLES%NoGasPocket , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)))
  541. KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl(1 : KickVARIABLES%NoGasPocket , :)
  542. DEALLOCATE(KickVARIABLES%GasPocketFlowEl)
  543. ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)))
  544. KickVARIABLES%GasPocketFlowEl = KickVARIABLES%tempGasPocketFlowEl
  545. DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl)
  546. END IF
  547. ELSE ! NoGasPocket = 0
  548. CALL GasPocketOldPress%Empty
  549. CALL GasPocketNewPress%Empty
  550. CALL GasPocketOldTemp%Empty
  551. CALL GasPocketNewTemp%Empty
  552. CALL GasPocketOldVol%Empty
  553. CALL GasPocketNewVol%Empty
  554. CALL GasPocketDeltaVol%Empty
  555. CALL GasPocketFlowInduced%Empty
  556. CALL GasPocketModifiedVol%Empty
  557. CALL GasPocketWeight%Empty
  558. CALL GasPocketDensity%Empty
  559. data%Equipments%DownHole%InfluxRate = 0.0
  560. data%Equipments%DownHole%KickVolume = 0.0
  561. END IF
  562. !WRITE (*,*) 'Gas Pocket Removed', NoGasPocket + 1, ALLOCATED(GasPocketWeight%Array)
  563. END SUBROUTINE