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.

Utube2_and_Trip_In.f90 33 KiB

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