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.

Well_Pressure_Data_Transfer.f90 38 KiB

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