Simulation Core
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

714 líneas
38 KiB

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