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.
 
 
 
 
 
 

732 lines
36 KiB

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