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.

Utube1_and_Trip_In.f90 29 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect string to annulus
  2. Use UTUBEVARS
  3. Use GeoElements_FluidModule
  4. USE CMudPropertiesVariables
  5. USE MudSystemVARIABLES
  6. USE Pump_VARIABLES
  7. USE sROP_Variables
  8. use CDrillWatchVariables
  9. use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
  10. Use CShoeVariables
  11. Use CUnityOutputs
  12. implicit none
  13. write(*,*) 'Utube1 code'
  14. !===========================================================WELL============================================================
  15. !===========================================================WELL============================================================
  16. UtubeMode1Activated= .true.
  17. !write(*,*) 'QUTubeInput=' , QUTubeInput
  18. !Qinput=5000.
  19. StringFlowRate= QUTubeInput ! (gpm)
  20. AnnulusFlowRate= QUTubeInput
  21. StringFlowRateFinal= StringFlowRate
  22. AnnulusFlowRateFinal= AnnulusFlowRate
  23. !===========================================
  24. if (FirstSetUtube1==0) then
  25. ! call St_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval(1:F_StringIntervalCounts)%Volume))) !startup initial
  26. ! call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
  27. ! call St_Mud_Backhead_section%AddToFirst (1)
  28. ! call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts))
  29. ! call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
  30. ! call St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
  31. ! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  32. ! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  33. !
  34. ! call Ann_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval((F_StringIntervalCounts+F_BottomHoleIntervalCounts+1):F_IntervalsTotalCounts)%Volume))) !startup initial
  35. ! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1))
  36. ! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  37. ! call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections))
  38. ! call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections)
  39. ! call Ann_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
  40. ! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  41. ! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  42. !Hz_Density%Array(:)= 0.0 !commented
  43. !Hz_MudOrKick%Array(:)= 104 !commented
  44. Hz_Density_Utube= 0.0
  45. Hz_MudOrKick_Utube= 104
  46. FirstSetUtube1= 1
  47. endif
  48. !========================Horizontal PIPE ENTRANCE=================
  49. !if (SuctionDensity_Old >= (ActiveDensity+0.05) .or. SuctionDensity_Old <= (ActiveDensity-0.05)) then ! new mud is pumped
  50. ! !ImudCount= ImudCount+1
  51. ! !SuctionMud= ImudCount
  52. ! call Hz_Density%AddToFirst (REAL(ActiveDensity)) !ActiveDensity : badan in moteghayer bayad avaz beshe
  53. ! call Hz_MudDischarged_Volume%AddToFirst (0.0d0)
  54. ! call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1))
  55. ! call Hz_Mud_Forehead_section%AddToFirst (1)
  56. ! call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
  57. ! call Hz_Mud_Backhead_section%AddToFirst (1)
  58. ! call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  59. ! call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  60. ! call Hz_MudOrKick%AddToFirst (0)
  61. !
  62. ! SuctionDensity_Old= ActiveDensity
  63. !endif
  64. !========================Horizontal PIPE STRING=================
  65. !commented
  66. ! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.)*DeltaT_Mudline) !(gal)
  67. !
  68. !imud=0
  69. ! do while (imud < Hz_Mud_Forehead_X%Length())
  70. ! imud = imud + 1
  71. !
  72. ! if (imud> 1) then
  73. ! Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1)
  74. ! Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1)
  75. ! endif
  76. !
  77. !
  78. ! DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) &
  79. ! / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud)))
  80. ! ! +1 for string , -1 for annulus
  81. !
  82. !
  83. ! Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* &
  84. ! Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3)
  85. ! Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948 ! ft^3 to gal
  86. !
  87. !
  88. ! if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then
  89. ! Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud)
  90. ! Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud))
  91. ! ! 7.48 is for gal to ft^3
  92. ! else
  93. !
  94. ! isection= Hz_Mud_Backhead_section%Array(imud)+1
  95. ! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud)
  96. !
  97. ! do
  98. ! if (isection > 1) then ! (horizontal pipe exit)
  99. ! Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud)
  100. ! Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1)
  101. ! Hz_Mud_Forehead_section%Array(imud)= 1
  102. ! if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
  103. ! call Hz_MudDischarged_Volume%Remove (imud)
  104. ! call Hz_Mud_Backhead_X%Remove (imud)
  105. ! call Hz_Mud_Backhead_section%Remove (imud)
  106. ! call Hz_Mud_Forehead_X%Remove (imud)
  107. ! call Hz_Mud_Forehead_section%Remove (imud)
  108. ! call Hz_Density%Remove (imud)
  109. ! call Hz_RemainedVolume_in_LastSection%Remove (imud)
  110. ! call Hz_EmptyVolume_inBackheadLocation%Remove (imud)
  111. ! call Hz_MudOrKick%Remove (imud)
  112. !
  113. ! endif
  114. ! exit
  115. ! endif
  116. !
  117. ! xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
  118. !
  119. ! if (xx<= 1.0) then
  120. ! Hz_Mud_Forehead_section%Array(imud)= isection
  121. ! Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
  122. ! exit
  123. ! else
  124. ! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
  125. ! isection= isection+ 1
  126. !
  127. !
  128. ! endif
  129. !
  130. ! enddo
  131. !
  132. ! endif
  133. !
  134. ! enddo
  135. !commented
  136. !========================Horizontal PIPE END=================
  137. !========================STRING ENTRANCE=================
  138. !write(*,*) 'a) St_Density%Length()=' , St_Density%Length()
  139. if (ABS(St_Density%First() - Hz_Density_Utube) >= DensityMixTol) then ! new mud is pumped
  140. call St_Density%AddToFirst (Hz_Density_Utube)
  141. call St_MudDischarged_Volume%AddToFirst (0.0d0)
  142. call St_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(2))
  143. call St_Mud_Forehead_section%AddToFirst (2)
  144. call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(2))
  145. call St_Mud_Backhead_section%AddToFirst (2)
  146. call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  147. call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  148. call St_MudOrKick%AddToFirst (Hz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104
  149. !StringDensity_Old= Hz_Density_Utube
  150. endif
  151. !write(*,*) 'b) St_Density%Length()=' , St_Density%Length()
  152. !write(*,*) 'b) St_Density%Array(1)=' , St_Density%Array(1)
  153. !write(*,*) 'b) St_MudOrKick%Array(1)=' , St_MudOrKick%Array(1)
  154. !========================STRING=================
  155. !WRITE (*,*) 'Utube1 StringFlowRate', StringFlowRate
  156. St_MudDischarged_Volume%Array(1)= St_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.d0)*DeltaT_Mudline) !(gal)
  157. imud=0
  158. do while (imud < St_Mud_Forehead_X%Length())
  159. imud = imud + 1
  160. if (imud> 1) then
  161. St_Mud_Backhead_X%Array(imud)= St_Mud_Forehead_X%Array(imud-1)
  162. St_Mud_Backhead_section%Array(imud)= St_Mud_Forehead_section%Array(imud-1)
  163. endif
  164. DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) &
  165. / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud)))
  166. ! +1 for string , -1 for annulus
  167. St_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))- St_Mud_Backhead_X%Array(imud))* &
  168. Area_PipeSectionFt(St_Mud_Backhead_section%Array(imud)) !(ft^3)
  169. St_EmptyVolume_inBackheadLocation%Array(imud)= St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  170. if ( St_MudDischarged_Volume%Array(imud) <= St_EmptyVolume_inBackheadLocation%Array(imud)) then
  171. St_Mud_Forehead_section%Array(imud)= St_Mud_Backhead_section%Array(imud)
  172. St_Mud_Forehead_X%Array(imud)= St_Mud_Backhead_X%Array(imud)+ DirectionCoef*(St_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(St_Mud_Backhead_section%Array(imud))
  173. ! 7.48 is for gal to ft^3
  174. else
  175. isection= St_Mud_Backhead_section%Array(imud)+1
  176. St_RemainedVolume_in_LastSection%Array(imud)= St_MudDischarged_Volume%Array(imud)- St_EmptyVolume_inBackheadLocation%Array(imud)
  177. do
  178. if (isection > F_StringIntervalCounts) then ! last pipe section(string exit) F_StringIntervalCounts includes Horizontal line
  179. St_MudDischarged_Volume%Array(imud)= St_MudDischarged_Volume%Array(imud)- St_RemainedVolume_in_LastSection%Array(imud)
  180. St_Mud_Forehead_X%Array(imud)= Xend_PipeSection(F_StringIntervalCounts)
  181. St_Mud_Forehead_section%Array(imud)= F_StringIntervalCounts
  182. if (St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
  183. call RemoveStringMudArrays(imud)
  184. endif
  185. exit
  186. endif
  187. xx= St_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
  188. if (xx<= 1.0) then
  189. St_Mud_Forehead_section%Array(imud)= isection
  190. St_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
  191. exit
  192. else
  193. St_RemainedVolume_in_LastSection%Array(imud)= St_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
  194. isection= isection+ 1
  195. endif
  196. enddo
  197. endif
  198. enddo
  199. !========================STRING END=================
  200. !========================== tripping in for OP remove ===============================
  201. !if (DeltaVolumeOp>0. .and. DeltaVolumeOp< Op_MudDischarged_Volume%Last()) then
  202. ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length())= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()) - DeltaVolumeOp
  203. !else
  204. ! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1)= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1) - (DeltaVolumeOp-Op_MudDischarged_Volume%Last())
  205. !
  206. ! call Op_MudDischarged_Volume%Remove (Op_MudDischarged_Volume%Length())
  207. ! call Op_Mud_Backhead_X%Remove (Op_MudDischarged_Volume%Length())
  208. ! call Op_Mud_Backhead_section%Remove (Op_MudDischarged_Volume%Length())
  209. ! call Op_Mud_Forehead_X%Remove (Op_MudDischarged_Volume%Length())
  210. ! call Op_Mud_Forehead_section%Remove (Op_MudDischarged_Volume%Length())
  211. ! call Op_Density%Remove (Op_MudDischarged_Volume%Length())
  212. ! call Op_RemainedVolume_in_LastSection%Remove (Op_MudDischarged_Volume%Length())
  213. ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_MudDischarged_Volume%Length())
  214. ! call Op_MudOrKick%Remove (Op_MudDischarged_Volume%Length())
  215. !endif
  216. !
  217. !============================= Bottom Hole ==============================
  218. !Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux
  219. imud=0
  220. do while (imud < Op_Mud_Forehead_X%Length())
  221. imud = imud + 1
  222. if (imud> 1) then
  223. Op_Mud_Backhead_X%Array(imud)= Op_Mud_Forehead_X%Array(imud-1)
  224. Op_Mud_Backhead_section%Array(imud)= Op_Mud_Forehead_section%Array(imud-1)
  225. endif
  226. DirectionCoef= (Xend_OpSection(Op_Mud_Backhead_section%Array(imud))-Xstart_OpSection(Op_Mud_Backhead_section%Array(imud))) &
  227. / ABS(Xend_OpSection(Op_Mud_Backhead_section%Array(imud))-Xstart_OpSection(Op_Mud_Backhead_section%Array(imud)))
  228. ! +1 for string , -1 for annulus
  229. Op_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_OpSection(Op_Mud_Backhead_section%Array(imud))- Op_Mud_Backhead_X%Array(imud))* &
  230. Area_OpSectionFt(Op_Mud_Backhead_section%Array(imud)) !(ft^3)
  231. Op_EmptyVolume_inBackheadLocation%Array(imud)= Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  232. if ( Op_MudDischarged_Volume%Array(imud) <= Op_EmptyVolume_inBackheadLocation%Array(imud)) then
  233. Op_Mud_Forehead_section%Array(imud)= Op_Mud_Backhead_section%Array(imud)
  234. Op_Mud_Forehead_X%Array(imud)= Op_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_OpSectionFt(Op_Mud_Backhead_section%Array(imud))
  235. ! 7.48 is for gal to ft^3
  236. else
  237. isection= Op_Mud_Backhead_section%Array(imud)+1
  238. Op_RemainedVolume_in_LastSection%Array(imud)= Op_MudDischarged_Volume%Array(imud)- Op_EmptyVolume_inBackheadLocation%Array(imud)
  239. do
  240. if (isection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
  241. if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space
  242. Op_MudDischarged_Volume%Array(imud)= Op_MudDischarged_Volume%Array(imud)- Op_RemainedVolume_in_LastSection%Array(imud)
  243. Op_Mud_Forehead_X%Array(imud)= Xend_OpSection(F_BottomHoleIntervalCounts)
  244. Op_Mud_Forehead_section%Array(imud)= F_BottomHoleIntervalCounts
  245. if (Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
  246. call RemoveOpMudArrays(imud)
  247. endif
  248. exit
  249. endif
  250. xx= Op_RemainedVolume_in_LastSection%Array(imud)/ OpSection_VolumeCapacity(isection) !(gal)
  251. if (xx<= 1.0) then
  252. Op_Mud_Forehead_section%Array(imud)= isection
  253. Op_Mud_Forehead_X%Array(imud)= (xx * (Xend_OpSection(isection)- Xstart_OpSection(isection)))+ Xstart_OpSection(isection)
  254. exit
  255. else
  256. Op_RemainedVolume_in_LastSection%Array(imud)= Op_RemainedVolume_in_LastSection%Array(imud)- OpSection_VolumeCapacity(isection)
  257. isection= isection+ 1
  258. endif
  259. enddo
  260. endif
  261. if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(F_BottomHoleIntervalCounts)) then
  262. totalLength = Op_MudDischarged_Volume%Length()
  263. do while(imud < totalLength)
  264. !imud = imud + 1
  265. call RemoveOpMudArrays(totalLength)
  266. totalLength = totalLength - 1
  267. enddo
  268. exit !
  269. endif
  270. !WRITE(*,*) imud,'Op_MudDischarged_Volume%Array(imud)' , Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud)
  271. enddo
  272. !write(*,*) 'Op_Mud_Forehead_X%Length()' , Op_Mud_Forehead_X%Length()
  273. !
  274. ! WRITE(*,*) 'Xend_PipeSection(F_StringIntervalCounts)' , Xend_PipeSection(F_StringIntervalCounts)
  275. ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(1)' , Op_Mud_Backhead_X%Array(1)
  276. ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(1)' , Op_Mud_Forehead_X%Array(1)
  277. ! WRITE(*,*) 'Op_Mud_Backhead_X%Array(2)' , Op_Mud_Backhead_X%Array(2)
  278. ! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2)
  279. !========================Bottom Hole END=================
  280. if (iLoc == 1) then
  281. MudSection= F_StringIntervalCounts+1
  282. BackheadX= Xstart_PipeSection(F_StringIntervalCounts+1)
  283. elseif (iLoc == 2) then
  284. MudSection= Kick_Forehead_section
  285. BackheadX= Kick_Forehead_X
  286. endif
  287. !========================ANNULUS ENTRANCE====================
  288. !write(*,*) 'iloc=====' , iLoc
  289. if ((ABS(AnnulusSuctionDensity_Old - St_Density%Last()) >= DensityMixTol) .OR. (DeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(iLoc)-St_Density%Last())>=DensityMixTol .and. AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped
  290. call Ann_Density%AddTo (iLoc,St_Density%Last())
  291. call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0)
  292. call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
  293. call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
  294. call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
  295. call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
  296. call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
  297. call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
  298. call Ann_MudOrKick%AddTo (iLoc,0)
  299. call Ann_CuttingMud%AddTo (iloc,0)
  300. AnnulusSuctionDensity_Old= St_Density%Last()
  301. MudIsChanged= .true.
  302. endif
  303. Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((AnnulusFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
  304. !========================Tripping In====================
  305. !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
  306. if (DeltaVolumeOp > 0.0 .and. MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen)
  307. !write(*,*) 'Tripping In'
  308. NewDensity= (St_Density%Last()*((AnnulusFlowRate/60.)*DeltaT_Mudline)+Op_Density%Last()*DeltaVolumeOp)/(((AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp)
  309. NewVolume= ((AnnulusFlowRate/60.)*DeltaT_Mudline)+DeltaVolumeOp
  310. !write(*,*) 'Ann_MudDischarged_Volume%Array(1)=', Ann_MudDischarged_Volume%Array(1), 'NewVolume=', NewVolume
  311. if (abs(Ann_Density%Array(iLoc)-NewDensity)< DensityMixTol) then ! 1-Pockets are Merged - (ROP is 0)
  312. Ann_Density%Array(iLoc)= (Ann_Density%Array(iLoc)*Ann_MudDischarged_Volume%Array(iLoc)+NewDensity*NewVolume)/(Ann_MudDischarged_Volume%Array(iLoc)+NewVolume)
  313. Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+DeltaVolumeOp
  314. Ann_Mud_Forehead_X%Array(iLoc)= BackheadX
  315. Ann_Mud_Forehead_section%Array(iLoc)= MudSection
  316. Ann_Mud_Backhead_X%Array(iLoc)= BackheadX
  317. Ann_Mud_Backhead_section%Array(iLoc)= MudSection
  318. Ann_RemainedVolume_in_LastSection%Array(iLoc)= (0.0d0)
  319. Ann_EmptyVolume_inBackheadLocation%Array(iLoc)= (0.0d0)
  320. else ! 2-Merging conditions are not meeted, so new pocket
  321. call Ann_Density%AddTo (iLoc,NewDensity)
  322. call Ann_MudDischarged_Volume%AddTo (iLoc,NewVolume)
  323. call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
  324. call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
  325. call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
  326. call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
  327. call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
  328. call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
  329. call Ann_MudOrKick%AddTo (iLoc,0)
  330. call Ann_CuttingMud%AddTo (iLoc,0)
  331. endif
  332. elseif (DeltaVolumeOp > 0.0 .and. MudIsChanged== .true. .and. Rate_of_Penetration==0.) then
  333. Ann_Density%Array(iLoc)= NewDensity
  334. Ann_MudDischarged_Volume%Array(iLoc)= NewVolume
  335. Ann_Mud_Forehead_X%Array(iLoc)= BackheadX
  336. Ann_Mud_Forehead_section%Array(iLoc)= MudSection
  337. Ann_Mud_Backhead_X%Array(iLoc)= BackheadX
  338. Ann_Mud_Backhead_section%Array(iLoc)= MudSection
  339. Ann_RemainedVolume_in_LastSection%Array(iLoc)= (0.0d0)
  340. Ann_EmptyVolume_inBackheadLocation%Array(iLoc)= (0.0d0)
  341. endif
  342. !========================Tripping In - End====================
  343. !======================== ANNULUS ====================
  344. MudIsChanged= .false.
  345. imud= 0
  346. do while (imud < Ann_Mud_Forehead_X%Length())
  347. imud = imud + 1
  348. if (imud> 1) then
  349. Ann_Mud_Backhead_X%Array(imud)= Ann_Mud_Forehead_X%Array(imud-1)
  350. Ann_Mud_Backhead_section%Array(imud)= Ann_Mud_Forehead_section%Array(imud-1)
  351. endif
  352. ! <<< Fracture Shoe Lost
  353. IF ( ShoeLost .and. LostInTripOutIsDone== .false. .and. ShoeDepth < Ann_Mud_Backhead_X%Array(imud) .and. ShoeDepth >= Ann_Mud_Forehead_X%Array(imud) ) then
  354. !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline)
  355. Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)-((Qlost/60.0d0)*DeltaT_Mudline) !(gal)
  356. if (Ann_MudDischarged_Volume%Array(imud) < 0.0) then
  357. !write(*,*) 'mud is removed by shoe lost, imud=' , imud
  358. call RemoveAnnulusMudArrays(imud)
  359. imud= imud-1
  360. cycle
  361. endif
  362. ENDIF
  363. ! Fracture Shoe Lost >>>
  364. DirectionCoef= (Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Backhead_section%Array(imud))) &
  365. / ABS(Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Backhead_section%Array(imud)))
  366. ! +1 for string , -1 for annulus
  367. Ann_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))- Ann_Mud_Backhead_X%Array(imud))* &
  368. Area_PipeSectionFt(Ann_Mud_Backhead_section%Array(imud)) !(ft^3)
  369. Ann_EmptyVolume_inBackheadLocation%Array(imud)= Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  370. if ( Ann_MudDischarged_Volume%Array(imud) <= Ann_EmptyVolume_inBackheadLocation%Array(imud)) then
  371. Ann_Mud_Forehead_section%Array(imud)= Ann_Mud_Backhead_section%Array(imud)
  372. Ann_Mud_Forehead_X%Array(imud)= Ann_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(Ann_Mud_Backhead_section%Array(imud))
  373. ! 7.48 is for gal to ft^3
  374. else
  375. isection= Ann_Mud_Backhead_section%Array(imud)+1
  376. Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_EmptyVolume_inBackheadLocation%Array(imud)
  377. do
  378. if (isection > NoPipeSections) then ! last pipe section(well exit)
  379. Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_RemainedVolume_in_LastSection%Array(imud)
  380. Ann_Mud_Forehead_X%Array(imud)= Xend_PipeSection(NoPipeSections)
  381. Ann_Mud_Forehead_section%Array(imud)= NoPipeSections
  382. if (Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
  383. call RemoveAnnulusMudArrays(imud)
  384. endif
  385. exit
  386. endif
  387. xx= Ann_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
  388. if (xx<= 1.0) then
  389. Ann_Mud_Forehead_section%Array(imud)= isection
  390. Ann_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
  391. exit
  392. else
  393. Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
  394. isection= isection+ 1
  395. endif
  396. enddo
  397. endif
  398. enddo
  399. !========================ANNULUS END=================
  400. !if ( WellisNOTFull == .false. ) then
  401. ! write(*,*) 'AnnulusFlowRate==' , AnnulusFlowRate
  402. ! call Set_FlowRate(real(100.*min(AnnulusFlowRate,PedalMeter)/(PedalMeter/10.), 8))
  403. !
  404. !
  405. !endif
  406. end subroutine Utube1_and_TripIn