Simulation Core
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

775 rindas
37 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 FricPressDropVars
  16. use MudSystemModule
  17. USE MudSystemVARIABLES
  18. USE GeoElements_FluidModule
  19. USE Fluid_Flow_Startup_Vars
  20. USE KickVariables
  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. IMPLICIT NONE
  32. INTEGER :: i , j
  33. REAL :: InstantaneousTotalOpenChokeArea , VolumeDensityProduct
  34. ChokeIsClosing = .FALSE.
  35. Kchoke = 0.0
  36. KBit = 0.0
  37. !!!!!!!!!!!!!!!! bit is present
  38. BitTrue = StringConfiguration%StringConfigurations(1)%ComponentType == Bit_ComponentType ! Bit_ComponentType = 0
  39. BitCd = 0.98
  40. BitNozzDia = 32.0 * StringConfiguration%BitDefinition%BitNozzleSize ! nozzle diameter in 1/32 in
  41. BitNozzleArea = 7.6699E-4 * BitNozzDia**2
  42. BitNozzleNum = StringConfiguration%BitDefinition%BitNozzleNo - BitJetsPlugged * BitProblems%PlugJetsCount
  43. BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * BitJetsWashedOut * BitProblems%JetWashoutCount * BitNozzleArea
  44. IF (BitNozzleNum == 0) THEN
  45. BitTotallyPluged = .TRUE.
  46. ELSE
  47. BitTotallyPluged = .FALSE.
  48. END IF
  49. FloatValveIn = StringConfiguration%BitDefinition%FloatValve
  50. !FloatValveOpen = .TRUE.
  51. !IF (JetWashoutCount > 0 .OR. PlugJetsCount > 0) THEN
  52. ! WRITE (*,*) 'PlugJetsCount' , PlugJetsCount
  53. ! WRITE (*,*) 'JetWashoutCount', JetWashoutCount
  54. !END IF
  55. !WRITE (*,*) 'BitNozzleNum', BitNozzleNum
  56. !WRITE (*,*) 'BitTotNozzArea', BitTotNozzArea
  57. !WRITE (*,*) 'Float Valve??', BitDefinition%FloatValve
  58. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  59. IF(ALLOCATED(GasPocketFlowEl)) DEALLOCATE(GasPocketFlowEl)
  60. !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed )
  61. ChokeKroneckerDelta = 0
  62. IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
  63. WellHeadOpen = .FALSE.
  64. !WRITE (*,*) ' Well Head is closed '
  65. ELSE
  66. WellHeadOpen = .TRUE.
  67. END IF
  68. IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
  69. !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
  70. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  71. NoHorizontalEl = MudSystem%NoHorizontalMudElements
  72. NoStringEl = MudSystem%NoStringMudElements
  73. NoAnnulusEl = MudSystem%NoCasingMudElements
  74. NoWellToChokeEl = 0
  75. IF (ChokeKroneckerDelta == 1) NoWellToChokeEl = MudSystem%ChokeLine_Density%Length()
  76. NoOpenHoleEl = MudSystem%NoBottomHoleMudElements
  77. NumbEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl + NoOpenHoleEl
  78. !WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl
  79. IF(ALLOCATED(FlowEl)) DEALLOCATE(FlowEl)
  80. ALLOCATE(FlowEl(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 , 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. !WRITE (*,*) 'H density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  106. END DO
  107. !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600
  108. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  109. !!!!!!!!!!!!!!!!!!!!!!!!! String
  110. !WRITE (*,*) 'S', NoStringEl
  111. StringFirstEl = NoHorizontalEl + 1
  112. StringLastEl = NoHorizontalEl + NoStringEl
  113. DO i = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl
  114. !WRITE (*,*) 'ST , i' , i
  115. FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i)
  116. !WRITE (*,*) 'StartX', FlowEl(i)%StartX
  117. FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i)
  118. !WRITE (*,*) 'EndX', FlowEl(i)%EndX
  119. FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i)
  120. !WRITE (*,*) 'StartTVD', FlowEl(i)%StartTVD
  121. FlowEl(i)%EndTVD = 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 = MudSystem%PipeOD_MudElement%Array(i)
  126. !WRITE (*,*) 'Od', FlowEl(i)%Od
  127. FlowEl(i)%Density = 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 (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 (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. !WRITE (*,*) 'S density, length, DeltaPStatic' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%StaticPressDiff, FlowEl(i)%MaterialType
  150. END DO
  151. !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600
  152. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  153. !!!!!!!!!!!!!!!!!!!!!!!!!!!! Annulus
  154. !WRITE (*,*) 'A', NoAnnulusEl
  155. AnnulusFirstEl = NoHorizontalEl + NoStringEl + 1
  156. AnnulusLastEl = NoHorizontalEl + NoStringEl + NoAnnulusEl
  157. DO i = NoHorizontalEl + NoStringEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl
  158. FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i)
  159. FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i)
  160. FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i)
  161. FlowEl(i)%EndTVD = MudSystem%TVDend_MudElement%Array(i)
  162. FlowEl(i)%Id = MudSystem%PipeID_MudElement%Array(i)
  163. FlowEl(i)%Od = MudSystem%PipeOD_MudElement%Array(i)
  164. FlowEl(i)%Density = 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 (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 (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. !WRITE (*,*) 'A density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  184. END DO
  185. !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600
  186. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  187. !!!!!!!!!!!!!!! Well to choke manifold path
  188. !ChokeFirstEl = AnnulusLastEl + 1
  189. !ChokeLastEl = OpenholeFirstEl - 1
  190. j = 1
  191. DO i = NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl
  192. FlowEl(i)%StartX = MudSystem%ChokeLine_Mud_Backhead_X%Array(j)
  193. FlowEl(i)%EndX = MudSystem%ChokeLine_Mud_Forehead_X%Array(j)
  194. FlowEl(i)%StartTVD = 0.d0
  195. FlowEl(i)%EndTVD = 0.d0
  196. FlowEl(i)%Id = 0.0
  197. FlowEl(i)%Od = BopStackSpecification%ChokeLineId
  198. FlowEl(i)%density = MudSystem%ChokeLine_Density%Array(j)
  199. FlowEl(i)%Dhyd = FlowEl(i)%Od
  200. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  201. FlowEl(i)%DepthDiff = 0.d0
  202. FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
  203. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  204. 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
  205. FlowEl(i)%MaterialType = MudSystem%ChokeLine_MudOrKick%Array(j)
  206. ELSE
  207. FlowEl(i)%MaterialType = 1
  208. END IF
  209. FlowEl(i)%dPdLgrav = 0.0
  210. FlowEl(i)%StaticPressDiff = 0.0
  211. !WRITE (*,*) 'Ch density, length, Type' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  212. j = j + 1
  213. END DO
  214. !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600
  215. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  216. !!!!!!!!!!!!!!! Open Hole
  217. OpenholeFirstEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + 1
  218. j = 1
  219. DO i = OpenholeFirstEl , NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl
  220. FlowEl(i)%StartX = MudSystem%Xstart_OpMudElement%Array(j)
  221. FlowEl(i)%EndX = MudSystem%Xend_OpMudElement%Array(j)
  222. FlowEl(i)%StartTVD = MudSystem%TVDstart_OpMudElement%Array(j)
  223. FlowEl(i)%EndTVD = MudSystem%TVDend_OpMudElement%Array(j)
  224. FlowEl(i)%Id = 0.0
  225. FlowEl(i)%Od = MudSystem%PipeOD_OpMudElement%Array(j)
  226. FlowEl(i)%density = MudSystem%Density_OpMudElement%Array(j)
  227. FlowEl(i)%MaterialType = MudSystem%MudTypeOp_MudElement%Array(j) ! = 0 for mud, = 1 for gas kick, = 4 for air
  228. FlowEl(i)%Dhyd = FlowEl(i)%Od
  229. FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
  230. FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
  231. FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
  232. FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
  233. IF (MudSystem%MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
  234. FlowEl(i)%MaterialType = 0
  235. ELSE IF (MudSystem%MudTypeOp_MudElement%Array(j) == 4) THEN
  236. FlowEl(i)%MaterialType = 4
  237. ELSE
  238. FlowEl(i)%MaterialType = 1
  239. END IF
  240. j = j + 1
  241. IF (FlowEl(i)%MaterialType == 1) THEN
  242. FlowEl(i)%dPdLgrav = 0.0
  243. ELSE
  244. FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density
  245. END IF
  246. FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff)
  247. !WRITE (*,*) 'O density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType
  248. END DO
  249. !WRITE (*,*) 'inlet and outlet mud theta600' , FlowEl(1)%Theta600 , FlowEl(NumbEl)%Theta600
  250. !DO i = NoHorizontalEl + 1, NoHorizontalEl + NoStringEl
  251. ! WRITE (*,*) 'element No, Start , Length, DeltaPSt', i, FlowEl(i)%StartX, FlowEl(i)%Length, FlowEl(i)%StaticPressDiff
  252. !END DO
  253. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  254. !!!!!!!!!!!!!!!!!! Mud Element Viscosity Calculation
  255. DO i = 1 , NumbEl
  256. IF (FlowEl(i)%MaterialType /= 0) CYCLE
  257. IF (FlowEl(i)%density < 8.33) THEN
  258. WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl
  259. WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type'
  260. DO j = 1 , NumbEl
  261. WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType
  262. END DO
  263. CALL ErrorStop('Density below water density (8.33)', i)
  264. CYCLE
  265. END IF
  266. FlowEl(i)%Theta600 = Theta600Refrence + 11.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence)
  267. FlowEl(i)%Theta300 = Theta300Refrence + 6.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence)
  268. !WRITE (*,*) 'i, Theta600, Theta600', i, FlowEl(i)%Theta600, FlowEl(i)%Theta300
  269. END DO
  270. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  271. FlowEl(:)%FlowRate = 0.0
  272. FlowEl(:)%StartPress = 0.0
  273. FlowEl(:)%EndPress = 0.0
  274. !WRITE (*,*) 'NoGasPocket=' , SIZE(GasPocketWeight%Array)
  275. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  276. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  277. MudSystem%OpenArea32 = ((ChokeManifold%LeftManualChoke * (1.0 - ManChoke1Plug * REAL(ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * ManChoke1Washout) * Choke%ChokeAreaFullyOpen
  278. MudSystem%OpenArea33 = CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen
  279. MudSystem%OpenArea34 = CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen
  280. MudSystem%OpenArea35 = ((ChokeManifold%RightManualChoke * (1.0 - ManChoke2Plug * REAL(ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * ManChoke2Washout) * Choke%ChokeAreaFullyOpen
  281. !write(*,*) 'OpenArea32=' , OpenArea32, active32, ManChoke1Plug, ManualChoke1PluggedPercent, ManChoke1Washout
  282. !write(*,*) 'OpenArea33=' , OpenArea33, active33
  283. !write(*,*) 'OpenArea34=' , OpenArea34, active34, !HydraulicChoke2PluggedPercent
  284. !write(*,*) 'OpenArea35=' , OpenArea35, active35, ManChoke2Plug, ManualChoke2PluggedPercent, ManChoke2Washout
  285. InstantaneousTotalOpenChokeArea = MudSystem%OpenArea32 * active32 + MudSystem%OpenArea33 * active33 + MudSystem%OpenArea34 * active34 + MudSystem%OpenArea35 * active35 + ChokeBypassArea * active29
  286. OldTotalOpenChokeArea = TotalOpenChokeArea
  287. !WRITE (*,*) 'Instantaneous / Old TotalOpenChokeArea', InstantaneousTotalOpenChokeArea, OldTotalOpenChokeArea
  288. IF (OldTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen
  289. IF (InstantaneousTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) THEN
  290. MudSystem%WellToChokeManifoldOpen = .FALSE.
  291. OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen
  292. !WRITE (*,*) ' Choke Controler Here 2'
  293. ELSE IF (InstantaneousTotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen .OR. MudSystem%WellToPitsOpen) THEN
  294. ! mud flows through well to bell nipple, or choke is rather open
  295. TotalOpenChokeArea = InstantaneousTotalOpenChokeArea
  296. !WRITE (*,*) ' Choke Controler Here 1'
  297. ELSE
  298. IF (InstantaneousTotalOpenChokeArea > OldTotalOpenChokeArea) THEN
  299. TotalOpenChokeArea = MIN(1.1 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea)
  300. WRITE (*,*) ' Choke is opening' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea
  301. ELSE IF (InstantaneousTotalOpenChokeArea < OldTotalOpenChokeArea) THEN
  302. TotalOpenChokeArea = MAX(0.9 * OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea)
  303. WRITE (*,*) ' Choke is closing' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea
  304. !ExitMass = 0.1 * ExitMass ! for decreasing mass exit due to expansion
  305. ELSE
  306. TotalOpenChokeArea = InstantaneousTotalOpenChokeArea
  307. END IF
  308. END IF
  309. !WRITE (*,*) 'TotalOpenChokeArea=', TotalOpenChokeArea
  310. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  311. !!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed )
  312. ChokeKroneckerDelta = 0
  313. !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
  314. !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
  315. IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
  316. !WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
  317. !WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
  318. WellHeadOpen = .FALSE.
  319. !WRITE (*,*) ' Well Head is closed '
  320. ELSE
  321. WellHeadOpen = .TRUE.
  322. END IF
  323. IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
  324. !WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
  325. !WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, WellToChokeManifoldWasOpen
  326. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  327. IF (NoGasPocket > 0) THEN
  328. !IF (NoWelltoChokeEl > 0 .AND. (FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .OR. KickWasExitingThroughChoke) .AND. WellHeadOpen) THEN
  329. IF (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0) THEN
  330. !WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', Choke_Kick_Saved_Volume_Final, (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)
  331. ExitMass = REAL(MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(NoGasPocket)
  332. !IF (NoGasPocket > 1) ExitMass = ExitMass + (SUM(GasPocketDeltaVol%Array(1 : NoGasPocket - 1)) / GasPocketNewVol%Array(NoGasPocket)) * GasPocketWeight%Array(NoGasPocket)
  333. !WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, MudSystem%StringFlowRate * dt / ConvMinToSec
  334. IF (FlowEl(OpenholeFirstEl - 1)%MaterialType /= 1) THEN
  335. CALL RemoveGasPocket(NoGasPocket)
  336. WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', MudSystem%Choke_Kick_Saved_Volume_Final
  337. END IF
  338. END IF
  339. !NoGasPocket = SIZE(GasPocketWeight%Array)
  340. IF (NoGasPocket > 0) CALL GasPocketFlowElementTransformer
  341. END IF
  342. IF (NoWelltoChokeEl > 0) THEN
  343. OldChokeDensity = ChokeDensity
  344. !ChokeDensity = SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Density * FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume) / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume)
  345. !ChokeDensity = MAX(ChokeDensity , ChokeMinDensity)
  346. VolumeDensityProduct = 0.0
  347. Do i = AnnulusLastEl + 1 , OpenholeFirstEl - 1
  348. VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , ChokeMinDensity)) * FlowEl(i)%Volume)
  349. End Do
  350. ChokeDensity = VolumeDensityProduct / SUM(FlowEl(AnnulusLastEl + 1 : OpenholeFirstEl - 1)%Volume)
  351. !IF ((ChokeDensity - OldChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN
  352. ! ChokeDensity = OldChokeDensity + (MaxChokeDensityChange * dt / Convmintosec)
  353. !ELSE IF ((OldChokeDensity - ChokeDensity) > (MaxChokeDensityChange * dt / Convmintosec)) THEN
  354. ! ChokeDensity = OldChokeDensity - (MaxChokeDensityChange * dt / Convmintosec)
  355. !END IF
  356. !WRITE (*,*) 'ChokeDensity=', ChokeDensity
  357. Kchoke = (ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte
  358. END IF
  359. IF (BitTotallyPluged == .FALSE.) THEN
  360. KBit = FlowEl(StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2
  361. END IF
  362. END SUBROUTINE WellPressureDataTransfer
  363. SUBROUTINE GasPocketFlowElementTransformer
  364. !! This Subroutine makes relationship between fluid flow elements and gas pocket elements
  365. !! The main variable of this subroutine is GasPocketFlowEl
  366. !! For each gas pocket, GasPocketFlowEl has a row, which columns are numbers of flow elements which are contains that gas pocket
  367. !! For example, if we have two gas pockets and they are in (7,8) and (12,3,4) flow elements respectively,
  368. !! GasPocketFlowEl(1,:) = [12 , 3 , 4] and GasPocketFlowEl(2,:) = [7 , 8 , 0]
  369. USE FricPressDropVars
  370. USE MudSystemVARIABLES
  371. USE GeoElements_FluidModule
  372. USE Fluid_Flow_Startup_Vars
  373. USE KickVariables
  374. USE CMudPropertiesVariables
  375. USE CBopStackVariables
  376. USE CDownHoleVariables
  377. USE CError
  378. IMPLICIT NONE
  379. INTEGER :: i , j , k
  380. REAL :: PressureCorrection
  381. PressureCorrection = 1.0
  382. ALLOCATE(GasPocketFlowEl(NoGasPocket , 1))
  383. GasPocketFlowEl(:,:) = 0
  384. !WRITE (*,*) 'NoGasPocket=' , NoGasPocket
  385. i = 1
  386. j = 1
  387. DO k = OpenholeFirstEl , NumbEl
  388. IF (FlowEl(k)%MaterialType == 1) THEN
  389. IF (j > 1) THEN
  390. IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN
  391. i = i + 1
  392. j = 1
  393. END IF
  394. END IF
  395. IF (SIZE(GasPocketFlowEl , dim = 2) < j) THEN
  396. ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2)))
  397. tempGasPocketFlowEl = GasPocketFlowEl
  398. DEALLOCATE(GasPocketFlowEl)
  399. ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1))
  400. GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl
  401. GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0
  402. DEALLOCATE(tempGasPocketFlowEl)
  403. END IF
  404. GasPocketFlowEl(i , j) = k
  405. j = j + 1
  406. END IF
  407. END DO
  408. !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl
  409. DO k = AnnulusFirstEl , OpenholeFirstEl - 1
  410. IF (FlowEl(k)%MaterialType == 1) THEN
  411. IF (j > 1) THEN
  412. IF (k == AnnulusFirstEl .AND. GasPocketFlowEl(i , j - 1) == NumbEl) THEN
  413. !WRITE (*,*) 'Kick is Around Bit'
  414. ELSE IF (GasPocketFlowEl(i , j - 1) /= k - 1) THEN
  415. i = i + 1
  416. j = 1
  417. !WRITE (*,*) 'i, j, k', i, j, k, FlowEl(k)%MaterialType
  418. END IF
  419. END IF
  420. IF (j > SIZE(GasPocketFlowEl , dim = 2)) THEN
  421. ALLOCATE(tempGasPocketFlowEl(SIZE(GasPocketFlowEl , dim = 1) , SIZE(GasPocketFlowEl , dim = 2)))
  422. tempGasPocketFlowEl = GasPocketFlowEl
  423. DEALLOCATE(GasPocketFlowEl)
  424. ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2) + 1))
  425. GasPocketFlowEl(: , 1 : SIZE(tempGasPocketFlowEl , dim = 2)) = tempGasPocketFlowEl
  426. GasPocketFlowEl(: , SIZE(GasPocketFlowEl , dim = 2)) = 0
  427. DEALLOCATE(tempGasPocketFlowEl)
  428. END IF
  429. IF (i > NoGasPocket) THEN
  430. WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl
  431. WRITE (*,*) 'i , j , k', i, j, k
  432. WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , StringFirstEl , AnnulusFirstEl , NoWellToChokeEl , OpenHoleFirstEl
  433. WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type'
  434. DO j = 1 , NumbEl
  435. WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType
  436. END DO
  437. !WRITE (*,*) 'Op Last: Volume(gal), Type', NumbEl, FlowEl(NumbEl)%Volume * ConvFt3ToUSgal , FlowEl(NumbEl)%MaterialType
  438. !WRITE (*,*) 'Ann First: Volume(gal), Type', AnnulusFirstEl, FlowEl(AnnulusFirstEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusFirstEl)%MaterialType
  439. !IF (ChokeKroneckerDelta == 1) THEN
  440. ! WRITE (*,*) 'Ann Last: Volume(gal), Type', AnnulusLastEl, FlowEl(AnnulusLastEl)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl)%MaterialType
  441. ! WRITE (*,*) 'Ch First: Volume(gal), Type', AnnulusLastEl + 1 , FlowEl(AnnulusLastEl + 1)%Volume * ConvFt3ToUSgal , FlowEl(AnnulusLastEl + 1)%MaterialType
  442. !END IF
  443. CALL ErrorStop('Error in calculating GasPocketFlowEl')
  444. END IF
  445. GasPocketFlowEl(i , j) = k
  446. !WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl
  447. j = j + 1
  448. END IF
  449. !IF (i > NoGasPocket) CALL ErrorStop('Error in GasPocketFlowEl' , i)
  450. END DO
  451. !i = SIZE(GasPocketFlowEl , dim = 1)
  452. !j = SIZE(GasPocketFlowEl , dim = 2)
  453. !WRITE(*,*) 'GasPocketFlowEl Data' , GasPocketFlowEl
  454. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  455. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  456. GasPocketModifiedVol%Array(:) = 0.d0
  457. DO i = 1 , NoGasPocket
  458. !WRITE(*,*) 'GasPocketFlowEl Data' , i , GasPocketFlowEl(: , i)
  459. DO j = 1 , SIZE(GasPocketFlowEl , dim = 2)
  460. IF (GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(GasPocketFlowEl(i , j))%Volume
  461. END DO
  462. END DO
  463. i = AnnulusLastEl
  464. j = OpenholeFirstEl - 1
  465. !WRITE (*,*) ' b) GasPocketModifiedVol (ft3)=', GasPocketModifiedVol(1)
  466. !WRITE (*,*) ' b) GasPocketModifiedVol (gal)=' , GasPocketModifiedVol(1) * 7.48
  467. !IF (NoWelltoChokeEl > 0 .AND. ANY(FlowEl(i : j)%MaterialType == 1) .AND. FlowEl(j)%MaterialType == 0) THEN
  468. ! BehindKickMudDensity = FlowEl(GasPocketFlowEl(NoGasPocket , 1) - 1)%Density
  469. ! FrontKickMudDensity = FlowEl(MAXVAL(GasPocketFlowEl(NoGasPocket , :)) + 1)%Density
  470. ! KickVolBeforeChoke = REAL(GasPocketModifiedVol%Array(NoGasPocket))
  471. ! WRITE (*,*) 'BehindKickMudDensity', BehindKickMudDensity
  472. ! WRITE (*,*) 'FrontKickMudDensity' , FrontKickMudDensity
  473. ! WRITE (*,*) 'KickVolBeforeChoke', KickVolBeforeChoke
  474. !END IF
  475. GasPocketOldVol%Array(:) = GasPocketModifiedVol%Array(:)
  476. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  477. !WRITE (*,*) ' GasPocketweight%Array(1)', GasPocketweight%Array(1)
  478. IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickmdotBCoef)
  479. GasPocketDensity%Array(:) = (GasPocketweight%Array(:) / GasPocketModifiedVol%Array(:)) / convft3toUSgal ! [lbm/ft^3 to ppg]
  480. DO i = 1 , SIZE(GasPocketFlowEl , dim = 1)
  481. DO j = 1 , SIZE(GasPocketFlowEl , dim = 2)
  482. IF (GasPocketFlowEl(i , j) > 0) FlowEl(GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i)
  483. END DO
  484. END DO
  485. !WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1)
  486. DownHole%InfluxRate = MAX(((KickmdotACoef * (KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0)
  487. !WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate
  488. i = OpenholeFirstEl - 1
  489. !WRITE (*,*) 'MaterialType, NoWelltoChokeEl', FlowEl(i)%MaterialType , NoWelltoChokeEl
  490. !IF (NoWelltoChokeEl > 0 .AND. FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. WellHeadOpen) THEN ! kick is last element in choke line and does not exit.
  491. IF (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. WellHeadOpen) THEN
  492. WRITE (*,*) 'Kick is exiting through the choke'
  493. !ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + MudSystem%StringFlowRate) / ConvMinToSec * dt
  494. GasPocketWeight%Array(NoGasPocket) = GasPocketweight%Array(NoGasPocket) - ExitMass
  495. IF (GasPocketWeight%Array(NoGasPocket) > 0.0) THEN
  496. GasPocketOldPress%Array(NoGasPocket) = GasPocketWeight%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * &
  497. GasPocketCompressibility%Array(NoGasPocket) * GasPocketNewTemp%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)
  498. GasPocketDensity%Array(NoGasPocket) = (GasPocketweight%Array(NoGasPocket) / GasPocketModifiedVol%Array(NoGasPocket)) / convft3toUSgal
  499. GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:)
  500. !FlowEl(i)%Density = GasPocketDensity%Array(NoGasPocket) ! for choke pressure drop calculation
  501. !WRITE (*,*) 'kick weight, pressure & density', GasPocketWeight%Array(NoGasPocket), GasPocketOldPress%Array(NoGasPocket), FlowEl(i)%Density
  502. ELSE ! gas pocket is escaped from the well completely
  503. WRITE (*,*) ' Last Pocket Removed'
  504. WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl
  505. CALL RemoveGasPocket(NoGasPocket)
  506. !WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl
  507. END IF
  508. ELSE IF (NoGasPocket == 1 .OR. WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed
  509. !WRITE (*,*) ' Gas Kick Pressure (psi) (before) = ' , GasPocketNewPress(1)
  510. !DO j = 1 , NoGasPocket
  511. GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:))
  512. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  513. GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:)
  514. !WRITE (*,*) ' Gas Kick Pressure (psi) (after) = ' , GasPocketOldPress(1), REAL(GasPocketNewVol(1) / GasPocketOldVol(1))
  515. !END DO
  516. ELSE ! Many gas pocket is in the well and well head is closed
  517. 103 FORMAT (2I, 4X, (F9.3), 5X, (F9.3))
  518. !WRITE (*,*) 'Before 0'
  519. !DO i = 1 , NoGasPocket
  520. ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL(GasPocketNewVol%Array(i) * Convft3toUSgal), REAL(GasPocketOldVol%Array(i) * Convft3toUSgal)
  521. !END DO
  522. GasPocketNewPress%Array(NoGasPocket) = GasPocketOldPress%Array(NoGasPocket)
  523. GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * &
  524. GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket)
  525. !GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:))
  526. !GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  527. !WRITE (*,*) 'Before 1'
  528. !DO i = 1 , NoGasPocket
  529. ! WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal))
  530. !END DO
  531. !WRITE (*,*) 'Mid'
  532. DO WHILE (ABS(PressureCorrection * 10.0) > KickConvergenceTolerance)
  533. DO j = NoGasPocket - 1 , 1 , -1
  534. CALL KickFunctionsCalculator(GasPocketNewPress%Array(j) , j , 5)
  535. GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * GasType(KickGasType)%GasConstant * &
  536. GasPocketNewTemp%Array(j) * GasPocketWeight%Array(j) / GasPocketNewPress%Array(j)
  537. !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal)
  538. END DO
  539. PressureCorrection = (SUM(GasPocketNewVol%Array(:)) - SUM(GasPocketOldVol%Array(:))) / SUM(GasPocketNewVol%Array(:) / GasPocketNewPress%Array(:))
  540. GasPocketNewPress%Array(NoGasPocket) = GasPocketNewPress%Array(NoGasPocket) + PressureCorrection
  541. GasPocketNewVol%Array(NoGasPocket) = GasPocketCompressibility%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * &
  542. GasPocketNewTemp%Array(NoGasPocket) * GasPocketWeight%Array(NoGasPocket) / GasPocketNewPress%Array(NoGasPocket)
  543. j = NoGasPocket
  544. !WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal)
  545. END DO
  546. !WRITE (*,*) 'Pressure Correction = ', PressureCorrection
  547. WRITE (*,*) 'After'
  548. DO i = 1 , NoGasPocket
  549. WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal))
  550. END DO
  551. GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:)
  552. END IF
  553. IF (GasPocketFlowEl(NoGasPocket , 1) == 0) THEN
  554. CALL RemoveGasPocket(1)
  555. !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl
  556. WRITE (*,*) 'First Pocket Removed'
  557. !WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl
  558. END IF
  559. DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0
  560. !WRITE (*,*) ' Gas Kick Pressure (psi) = ' , GasPocketOldPress(1) , INT((GasPocketNewVol(1) / GasPocketOldVol(1)) * 1000.d0) / 1000.d0
  561. !WRITE (*,*) ' b) GasPocketNewVol (ft^3) = ' , GasPocketOldVol(1)
  562. END SUBROUTINE
  563. SUBROUTINE RemoveGasPocket(ilocal)
  564. USE KickVARIABLES
  565. USE MudSystemVARIABLES
  566. IMPLICIT NONE
  567. INTEGER :: ilocal
  568. DEALLOCATE(KickJacobian , OldKickJacobian , KickVandPFunction , KickUnknownVector , KickCorrectionVector)
  569. WRITE (*,*) 'Gas Pocket Will be Removed', ilocal
  570. call GasPocketOldPress%Remove(ilocal)
  571. call GasPocketNewPress%Remove(ilocal)
  572. call GasPocketOldTemp%Remove(ilocal)
  573. call GasPocketNewTemp%Remove(ilocal)
  574. call GasPocketOldVol%Remove(ilocal)
  575. call GasPocketNewVol%Remove(ilocal)
  576. call GasPocketDeltaVol%Remove(ilocal)
  577. call GasPocketFlowInduced%Remove(ilocal)
  578. call GasPocketModifiedVol%Remove(ilocal)
  579. call GasPocketWeight%Remove(ilocal)
  580. call GasPocketDensity%Remove(ilocal)
  581. call GasPocketCompressibility%Remove(ilocal)
  582. NoGasPocket = NoGasPocket - 1
  583. IF (NoGasPocket > 0) THEN
  584. ALLOCATE(KickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , OldKickJacobian(2 * NoGasPocket , 2 * NoGasPocket) , KickVandPFunction(2 * NoGasPocket))
  585. ALLOCATE(KickUnknownVector(2 * NoGasPocket) , KickCorrectionVector(2 * NoGasPocket))
  586. IF (ALLOCATED(GasPocketFlowEl)) THEN
  587. ALLOCATE(tempGasPocketFlowEl(NoGasPocket , SIZE(GasPocketFlowEl , dim = 2)))
  588. tempGasPocketFlowEl = GasPocketFlowEl(1 : NoGasPocket , :)
  589. DEALLOCATE(GasPocketFlowEl)
  590. ALLOCATE(GasPocketFlowEl(SIZE(tempGasPocketFlowEl , dim = 1) , SIZE(tempGasPocketFlowEl , dim = 2)))
  591. GasPocketFlowEl = tempGasPocketFlowEl
  592. DEALLOCATE(tempGasPocketFlowEl)
  593. END IF
  594. ELSE ! NoGasPocket = 0
  595. CALL GasPocketOldPress%Empty
  596. CALL GasPocketNewPress%Empty
  597. CALL GasPocketOldTemp%Empty
  598. CALL GasPocketNewTemp%Empty
  599. CALL GasPocketOldVol%Empty
  600. CALL GasPocketNewVol%Empty
  601. CALL GasPocketDeltaVol%Empty
  602. CALL GasPocketFlowInduced%Empty
  603. CALL GasPocketModifiedVol%Empty
  604. CALL GasPocketWeight%Empty
  605. CALL GasPocketDensity%Empty
  606. DownHole%InfluxRate = 0.0
  607. DownHole%KickVolume = 0.0
  608. END IF
  609. !WRITE (*,*) 'Gas Pocket Removed', NoGasPocket + 1, ALLOCATED(GasPocketWeight%Array)
  610. END SUBROUTINE