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.
 
 
 
 
 
 

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