Simulation Core
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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