Simulation Core
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

536 行
37 KiB

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