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.
 
 
 
 
 
 

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