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.
 
 
 
 
 
 

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