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.
 
 
 
 
 
 

1627 lines
92 KiB

  1. subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect
  2. Use GeoElements_FluidModule
  3. USE CMudPropertiesVariables
  4. USE MudSystemVARIABLES
  5. USE Pumps_VARIABLES
  6. !USE CHOKEVARIABLES
  7. !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
  8. !use CManifolds
  9. use CDrillWatchVariables
  10. !use CHOKEVARIABLES
  11. !use CChokeManifoldVariables
  12. !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  13. USE sROP_Other_Variables
  14. USE sROP_Variables
  15. Use KickVariables
  16. Use CShoeVariables
  17. use CError
  18. implicit none
  19. integer i,ii,AddLocation
  20. !===========================================================WELL============================================================
  21. !===========================================================WELL============================================================
  22. MudSystemDotStringFlowRate= MUD(2)%Q
  23. MudSystemDotAnnulusFlowRate= MUD(2)%Q
  24. !write(*,*) 'Trip In'
  25. !========================Horizontal PIPE ENTRANCE=================
  26. if (ABS(SuctionDensity_Old - Suction_Density_MudSystem) >= MudSystemDotDensityMixTol) then ! new mud is pumped
  27. call MudSystemDotHz_Density%AddToFirst (Suction_Density_MudSystem)
  28. call MudSystemDotHz_MudDischarged_Volume%AddToFirst (0.0d0)
  29. call MudSystemDotHz_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(1))
  30. call Hz_Mud_Forehead_section%AddToFirst (1)
  31. call MudSystemDotHz_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(1))
  32. call Hz_Mud_Backhead_section%AddToFirst (1)
  33. call MudSystemDotHz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  34. call MudSystemDotHz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  35. call Hz_MudOrKick%AddToFirst (0)
  36. SuctionDensity_Old= Suction_Density_MudSystem
  37. endif
  38. !========================Horizontal PIPE STRING=================
  39. MudSystemDotHz_MudDischarged_Volume%Array(1)= MudSystemDotHz_MudDischarged_Volume%Array(1)+ ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
  40. MudSystemDottotal_add = MudSystemDottotal_add + ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline)
  41. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  42. MudSystemDottotal_add= 0.
  43. endif
  44. !write(*,*) ' total decrease(add to HZ)=' , total_add
  45. !write(*,*) ' add to HZ=' , ((StringFlowRate/60.0d0)*DeltaT_Mudline)
  46. MudSystemDotimud=0
  47. do while (MudSystemDotimud < MudSystemDotHz_Mud_Forehead_X%Length())
  48. MudSystemDotimud = MudSystemDotimud + 1
  49. if (MudSystemDotimud> 1) then
  50. MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud-1)
  51. Hz_Mud_Backhead_section%Array(MudSystemDotimud)= Hz_Mud_Forehead_section%Array(MudSystemDotimud-1)
  52. endif
  53. MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))) &
  54. / ABS(MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud)))
  55. ! +1 for string , -1 for annulus
  56. MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud))* &
  57. MudSystemDotArea_PipeSectionFt(Hz_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
  58. MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
  59. if ( MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
  60. Hz_Mud_Forehead_section%Array(MudSystemDotimud)= Hz_Mud_Backhead_section%Array(MudSystemDotimud)
  61. MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Hz_Mud_Backhead_section%Array(MudSystemDotimud))
  62. else
  63. MudSystemDotisection= Hz_Mud_Backhead_section%Array(MudSystemDotimud)+1
  64. MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
  65. do
  66. if (MudSystemDotisection > 1) then ! (horizontal pipe exit)
  67. MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
  68. MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(1)
  69. Hz_Mud_Forehead_section%Array(MudSystemDotimud)= 1
  70. if (MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string
  71. call RemoveHzMudArrays(MudSystemDotimud)
  72. endif
  73. exit
  74. endif
  75. MudSystemDotxx= MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
  76. if (MudSystemDotxx<= 1.0) then
  77. Hz_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
  78. MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection)
  79. exit
  80. else
  81. MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
  82. MudSystemDotisection= MudSystemDotisection+ 1
  83. endif
  84. enddo
  85. endif
  86. enddo
  87. !========================Horizontal PIPE END=================
  88. !========================Utube1 Air Element Removing=================
  89. !if (UtubeMode1Activated== .true.) then ! StringUpdate == .true.
  90. !
  91. !
  92. ! !StringDensity_Old= St_Density%Array(2)
  93. !
  94. ! write(*,*) 'StringDensity_Old=' , StringDensity_Old
  95. !
  96. ! UtubeMode1Activated= .false.
  97. !endif
  98. !========================Utube1 Air Element Removing End=================
  99. !!========================Utube2 Removing from Annulus================= not needed 97.04.26
  100. !
  101. ! if (UtubeMode2Activated== .true.) then ! StringUpdate == .true.
  102. !
  103. ! if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist
  104. ! call RemoveAnnulusMudArrays(Ann_MudOrKick%Length())
  105. ! endif
  106. !
  107. ! UtubeMode2Activated= .false.
  108. ! endif
  109. !
  110. !
  111. !!========================Utube2 Removing from Annulus End=================
  112. !========================New Pipe Filling=================
  113. !if (F_StringIntervalCounts > F_StringIntervalCountsOld) then ! StringUpdate == .true.
  114. if (MudSystemDotAddedElementsToString > 0) then ! StringUpdate == .true.
  115. !NoPipeAdded= F_StringIntervalCounts - F_StringIntervalCountsOld
  116. MudSystemDotNewPipeFilling=0
  117. IF (St_MudOrKick%First() == 104) then
  118. MudSystemDotSt_MudDischarged_Volume%Array(1) = MudSystemDotSt_MudDischarged_Volume%Array(1) + sum(MudSystemDotPipeSection_VolumeCapacity(2:1+MudSystemDotAddedElementsToString)) ! new pipe is filled by air
  119. else
  120. call St_Density%AddToFirst (0.d0)
  121. call MudSystemDotSt_MudDischarged_Volume%AddToFirst (sum(MudSystemDotPipeSection_VolumeCapacity(2:1+MudSystemDotAddedElementsToString)))
  122. call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
  123. call St_Mud_Forehead_section%AddToFirst (2)
  124. call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
  125. call St_Mud_Backhead_section%AddToFirst (2)
  126. call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.d0)
  127. call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.d0)
  128. call St_MudOrKick%AddToFirst (104)
  129. endif
  130. endif
  131. !F_StringIntervalCountsOld= F_StringIntervalCounts
  132. if (MudSystemDotNewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe)
  133. MudSystemDotLackageMudVolume= MudSystemDotSt_MudDischarged_Volume%Array(1) ! = Air element
  134. write(*,*) 'LackageMudVolume=' , MudSystemDotLackageMudVolume
  135. if (ABS(St_Density%Array(2) - MudSystemDotHz_Density%Last()) >= MudSystemDotDensityMixTol) then ! new mud is pumped
  136. call St_Density%AddTo (2,MudSystemDotHz_Density%Last())
  137. call MudSystemDotSt_MudDischarged_Volume%AddTo (2, 0.d0)
  138. call MudSystemDotSt_Mud_Forehead_X%AddTo (2,MudSystemDotXstart_PipeSection(2))
  139. call St_Mud_Forehead_section%AddTo (2 , 2)
  140. call MudSystemDotSt_Mud_Backhead_X%AddTo (2,MudSystemDotXstart_PipeSection(2))
  141. call St_Mud_Backhead_section%AddTo (2 ,2)
  142. call MudSystemDotSt_RemainedVolume_in_LastSection%AddTo (2,0.d0)
  143. call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddTo (2,0.d0)
  144. call St_MudOrKick%AddTo (2,0)
  145. !StringDensity_Old= Hz_Density%Last()
  146. endif
  147. MudSystemDotSt_MudDischarged_Volume%Array(2)= MudSystemDotSt_MudDischarged_Volume%Array(2)+ min( ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline), MudSystemDotLackageMudVolume) !(gal)
  148. MudSystemDotSt_MudDischarged_Volume%Array(1)= MudSystemDotSt_MudDischarged_Volume%Array(1)- min( ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline), MudSystemDotLackageMudVolume) ! air(gal)
  149. !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:))
  150. MudSystemDotLackageMudVolumeAfterFilling= MudSystemDotSt_MudDischarged_Volume%Array(1) ! last time it should be zero
  151. if (MudSystemDotLackageMudVolumeAfterFilling == 0.) then
  152. MudSystemDotNewPipeFilling= 1
  153. call RemoveStringMudArrays(1)
  154. MudSystemDotSt_Mud_Backhead_X%Array(1) = MudSystemDotXstart_PipeSection(2)
  155. St_Mud_Backhead_section%Array(1) = 2
  156. endif
  157. endif
  158. !========================New Pipe Filling End=================
  159. if (MudSystemDotNewPipeFilling == 0) then
  160. MudSystemDotStringFlowRate= 0.
  161. MudSystemDotAnnulusFlowRate= 0.
  162. endif
  163. MudSystemDotStringFlowRateFinal= MudSystemDotStringFlowRate
  164. MudSystemDotAnnulusFlowRateFinal= MudSystemDotAnnulusFlowRate
  165. !========================STRING ENTRANCE=================
  166. if (MudSystemDotStringFlowRateFinal > 0.0 .and. ABS(St_Density%First() - MudSystemDotHz_Density%Last()) >= MudSystemDotDensityMixTol) then ! new mud is pumped
  167. call St_Density%AddToFirst (MudSystemDotHz_Density%Last())
  168. call MudSystemDotSt_MudDischarged_Volume%AddToFirst (0.0d0)
  169. call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
  170. call St_Mud_Forehead_section%AddToFirst (2)
  171. call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
  172. call St_Mud_Backhead_section%AddToFirst (2)
  173. call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  174. call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  175. call St_MudOrKick%AddToFirst (0)
  176. !StringDensity_Old= Hz_Density%Last()
  177. endif
  178. MudSystemDotSt_MudDischarged_Volume%Array(1)= MudSystemDotSt_MudDischarged_Volume%Array(1)+ ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
  179. !=============== save String Mud data===========
  180. MudSystemDotStMudVolumeSum= 0.d0
  181. !St_MudSaved_Density= 0.d0
  182. MudSystemDotSt_Saved_MudDischarged_Volume= 0.d0
  183. !Saved_St_MudOrKick= 0
  184. !Ann_to_Choke_2mud= .false.
  185. do MudSystemDotimud=1, MudSystemDotSt_MudDischarged_Volume%Length()
  186. MudSystemDotStMudVolumeSum = MudSystemDotStMudVolumeSum + MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)
  187. if ( MudSystemDotStMudVolumeSum > sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts)) ) then
  188. !IF (St_MudOrKick%Array(imud) == 0) THEN
  189. MudSystemDotSt_MudSaved_Density = St_Density%Array(MudSystemDotimud)
  190. MudSystemDotSt_Saved_MudDischarged_Volume = MudSystemDotStMudVolumeSum - sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts))
  191. !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  192. ! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  193. ! Saved_St_MudOrKick= St_MudOrKick%Array (imud)
  194. ! St_KickSaved_Density= St_Density%Array(imud)
  195. !END IF
  196. do ii= MudSystemDotimud + 1, MudSystemDotSt_MudDischarged_Volume%Length()
  197. !IF (St_MudOrKick%Array(ii) == 0) THEN
  198. MudSystemDotSt_MudSaved_Density = ((MudSystemDotSt_MudSaved_Density * MudSystemDotSt_Saved_MudDischarged_Volume) + (St_Density%Array(ii) * MudSystemDotSt_MudDischarged_Volume%Array(ii))) / (MudSystemDotSt_Saved_MudDischarged_Volume + MudSystemDotSt_MudDischarged_Volume%Array(ii))
  199. MudSystemDotSt_Saved_MudDischarged_Volume = MudSystemDotSt_Saved_MudDischarged_Volume + MudSystemDotSt_MudDischarged_Volume%Array(ii)
  200. !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  201. ! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii)
  202. ! Saved_St_MudOrKick= St_MudOrKick%Array (ii)
  203. ! St_KickSaved_Density= St_Density%Array(ii)
  204. !END IF
  205. enddo
  206. !WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume
  207. exit ! exits do
  208. endif
  209. enddo
  210. MudSystemDotSt_Saved_MudDischarged_Volume_Final = MudSystemDotSt_Saved_MudDischarged_Volume
  211. IF (WellHeadIsOpen) MudSystemDotMudVolume_InjectedToBH = MudSystemDotSt_Saved_MudDischarged_Volume_Final
  212. !======================================================================
  213. !========================STRING=================
  214. MudSystemDotimud=0
  215. do while (MudSystemDotimud < MudSystemDotSt_Mud_Forehead_X%Length())
  216. MudSystemDotimud = MudSystemDotimud + 1
  217. if (MudSystemDotimud> 1) then
  218. MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud-1)
  219. St_Mud_Backhead_section%Array(MudSystemDotimud)= St_Mud_Forehead_section%Array(MudSystemDotimud-1)
  220. endif
  221. MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))) &
  222. / ABS(MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud)))
  223. ! +1 for string , -1 for annulus
  224. MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud))* &
  225. MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
  226. MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
  227. !write(*,*) 'St_Mud_Backhead_section%Array(1)=' , St_Mud_Backhead_section%Array(1)
  228. !write(*,*) 'Xend_PipeSection(St_Mud_Backhead_section%Array(1))=' , Xend_PipeSection(St_Mud_Backhead_section%Array(1))
  229. !
  230. !write(*,*) 'St_EmptyVolume_inBackheadLocation%Array(1)=' , St_EmptyVolume_inBackheadLocation%Array(1)
  231. !write(*,*) 'St_Mud_Backhead_X%Array(1)=' , St_Mud_Backhead_X%Array(1)
  232. if ( MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
  233. St_Mud_Forehead_section%Array(MudSystemDotimud)= St_Mud_Backhead_section%Array(MudSystemDotimud)
  234. MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud))
  235. ! 7.48 is for gal to ft^3
  236. else
  237. MudSystemDotisection= St_Mud_Backhead_section%Array(MudSystemDotimud)+1
  238. MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
  239. do
  240. if (MudSystemDotisection > F_StringIntervalCounts) then ! last pipe section(string exit) F_StringIntervalCounts includes Horizontal line
  241. MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
  242. MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
  243. St_Mud_Forehead_section%Array(MudSystemDotimud)= F_StringIntervalCounts
  244. if (MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string
  245. call RemoveStringMudArrays(MudSystemDotimud)
  246. endif
  247. exit
  248. endif
  249. MudSystemDotxx= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
  250. if (MudSystemDotxx<= 1.0) then
  251. St_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
  252. MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection)
  253. exit
  254. else
  255. MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
  256. MudSystemDotisection= MudSystemDotisection+ 1
  257. endif
  258. enddo
  259. endif
  260. enddo
  261. !write(*,*) ' a before=='
  262. !
  263. ! do imud=1, Op_MudDischarged_Volume%Length()
  264. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  265. ! enddo
  266. !
  267. ! do imud=1, Ann_MudDischarged_Volume%Length()
  268. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  269. ! enddo
  270. !
  271. !write(*,*) '==== a before'
  272. !write(*,*) ' iloc (a): ' , iloc
  273. !========================STRING END=================
  274. IF (Op_MudOrKick%Last() /= 0 .and. Op_MudOrKick%Last()==Ann_MudOrKick%First()) MudSystemDotiLoc=2 ! it may be 1,2,3 or more, all of them are kick
  275. !write(*,*) ' iloc (b): ' , iloc
  276. !=============================Add PumpFlowRate to Bottom Hole ==============================
  277. !if ( AnnulusFlowRate>0.0 ) then
  278. if ( MudSystemDotMudVolume_InjectedToBH > 0.0 ) then
  279. if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the
  280. AddLocation= MudSystemDotOp_Density%Length()-MudSystemDotiLoc+1+1 ! well, thus pumped mud should be placed above the kick
  281. else
  282. AddLocation= MudSystemDotOp_Density%Length()+1
  283. endif
  284. !write(*,*) 'AddLocation====' , AddLocation
  285. if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0')
  286. if ( ABS(St_Density%Last() - MudSystemDotOp_Density%Array(AddLocation-1)) >= MudSystemDotDensityMixTol ) then
  287. !write(*,*) 'new pocket**'
  288. !write(*,*) 'St_Density%Last()=' , St_Density%Last()
  289. !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1)
  290. call MudSystemDotOp_Density% AddTo (AddLocation,St_Density%Last())
  291. !call Op_MudDischarged_Volume%AddTo (AddLocation,((AnnulusFlowRate/60.d0)*DeltaT_Mudline))
  292. call MudSystemDotOp_MudDischarged_Volume%AddTo (AddLocation,MudSystemDotMudVolume_InjectedToBH)
  293. call MudSystemDotOp_Mud_Forehead_X%AddTo (AddLocation,MudSystemDotXstart_OpSection(1))
  294. call Op_Mud_Forehead_section%AddTo (AddLocation,1)
  295. call MudSystemDotOp_Mud_Backhead_X%AddTo (AddLocation,MudSystemDotXstart_OpSection(1))
  296. call Op_Mud_Backhead_section%AddTo (AddLocation,1)
  297. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0)
  298. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0)
  299. call Op_MudOrKick%AddTo (AddLocation,0)
  300. else
  301. !write(*,*) 'merge**'
  302. !write(*,*) 'density before=' , Op_Density%Array(AddLocation-1)
  303. !write(*,*) 'St_Density%Last() for mix=' , St_Density%Last()
  304. !Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)+St_Density%Last()*((AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((AnnulusFlowRate/60.d0)*DeltaT_Mudline))
  305. !Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)
  306. MudSystemDotOp_Density%Array(AddLocation-1)= (MudSystemDotOp_Density%Array(AddLocation-1)*MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)+St_Density%Last()*MudSystemDotMudVolume_InjectedToBH)/(MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)+MudSystemDotMudVolume_InjectedToBH)
  307. MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)= MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1) + MudSystemDotMudVolume_InjectedToBH
  308. !write(*,*) 'density after=' , Op_Density%Array(AddLocation-1)
  309. endif
  310. endif
  311. !=======================Add PumpFlowRate to Bottom Hole- End ==============================
  312. !=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick
  313. MudSystemDotOpMudVolumeSum= 0.d0
  314. !Op_MudSaved_Density= 0.d0
  315. !Op_KickSaved_Density= 0.d0
  316. MudSystemDotOp_Saved_MudDischarged_Volume= 0.d0
  317. MudSystemDotOp_Kick_Saved_Volume= 0.d0
  318. MudSystemDotSaved_Op_MudOrKick= 0
  319. !write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  320. !write(*,*) 'Op_MudDischarged_Volume%Length()===' , Op_MudDischarged_Volume%Length()
  321. !
  322. do MudSystemDotimud=1, MudSystemDotOp_MudDischarged_Volume%Length()
  323. !write(*,*) 'imud, Op_MudDischarged_Volume%Array(imud)=' , imud,Op_MudDischarged_Volume%Array(imud)
  324. MudSystemDotOpMudVolumeSum= MudSystemDotOpMudVolumeSum + MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)
  325. if ( MudSystemDotOpMudVolumeSum > sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then
  326. IF (Op_MudOrKick%Array(MudSystemDotimud) == 0) THEN
  327. MudSystemDotOp_MudSaved_Density = MudSystemDotOp_Density%Array(MudSystemDotimud)
  328. MudSystemDotOp_Saved_MudDischarged_Volume = MudSystemDotOpMudVolumeSum - sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  329. ELSE
  330. MudSystemDotOp_Kick_Saved_Volume = MudSystemDotOpMudVolumeSum - sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  331. !write(*,*) 'cond 1- Op_MudOrKick%Array (imud),Op_Density%Array(imud):' ,Op_MudOrKick%Array (imud),Op_Density%Array(imud)
  332. MudSystemDotSaved_Op_MudOrKick= Op_MudOrKick%Array (MudSystemDotimud)
  333. MudSystemDotOp_KickSaved_Density= MudSystemDotOp_Density%Array(MudSystemDotimud)
  334. MudSystemDotiLoc= 2
  335. END IF
  336. do ii= MudSystemDotimud + 1, MudSystemDotOp_MudDischarged_Volume%Length()
  337. IF (Op_MudOrKick%Array(ii) == 0) THEN
  338. MudSystemDotOp_MudSaved_Density = ((MudSystemDotOp_MudSaved_Density * MudSystemDotOp_Saved_MudDischarged_Volume) + (MudSystemDotOp_Density%Array(ii) * MudSystemDotOp_MudDischarged_Volume%Array(ii))) / (MudSystemDotOp_Saved_MudDischarged_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii))
  339. MudSystemDotOp_Saved_MudDischarged_Volume = MudSystemDotOp_Saved_MudDischarged_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii)
  340. ELSE
  341. MudSystemDotOp_Kick_Saved_Volume = MudSystemDotOp_Kick_Saved_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii)
  342. !write(*,*) 'cond 2- Op_MudOrKick%Array (ii),Op_Density%Array(ii):' ,Op_MudOrKick%Array (ii),Op_Density%Array(ii)
  343. MudSystemDotSaved_Op_MudOrKick= Op_MudOrKick%Array (ii)
  344. MudSystemDotOp_KickSaved_Density= MudSystemDotOp_Density%Array(ii)
  345. MudSystemDotiLoc= 2
  346. END IF
  347. enddo
  348. exit ! exits do
  349. endif
  350. enddo
  351. !WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume
  352. !write(*,*) ' iloc (c): ' , iloc
  353. !======================================================================
  354. !======================================================================
  355. !if (iLoc == 1) then
  356. MudSystemDotMudSection= F_StringIntervalCounts+1
  357. MudSystemDotBackheadX= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)
  358. !elseif (iLoc == 2) then
  359. ! MudSection= Kick_Forehead_section
  360. ! BackheadX= Kick_Forehead_X
  361. !endif
  362. !========================ANNULUS ENTRANCE====================
  363. !if (KickMigration_2SideBit == .FALSE.) then ! because its effect is applied in Migration Code
  364. ! !write(*,*) 'iloc=====' , iLoc bejaye Rate_of_Penetration ==0. in bude: DeltaVolumeOp == 0.0
  365. ! 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
  366. ! call Ann_Density%AddTo (iLoc,St_Density%Last())
  367. ! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0)
  368. ! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
  369. ! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
  370. ! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
  371. ! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
  372. ! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
  373. ! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
  374. ! call Ann_MudOrKick%AddTo (iLoc,0)
  375. ! call Ann_CuttingMud%AddTo (iLoc,0)
  376. ! !write(*,*) 'c) annLength=' , Ann_Density%Length()
  377. !
  378. ! AnnulusSuctionDensity_Old= St_Density%Last()
  379. !
  380. ! MudIsChanged= .true.
  381. ! endif
  382. !
  383. ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) !(gal)
  384. !
  385. !endif
  386. Ann_Mud_Backhead_section%Array(1)= MudSystemDotMudSection !it is needed to be updated for a condition that one pipe is removed from Annulus due to trip out
  387. Ann_Mud_Backhead_X%Array(1)= MudSystemDotBackheadX
  388. ! write(*,*) 'zero)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
  389. !
  390. !
  391. !write(*,*) 'pump added-before add to ann=='
  392. !
  393. ! do imud=1, Op_MudDischarged_Volume%Length()
  394. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  395. ! enddo
  396. !
  397. ! do imud=1, Ann_MudDischarged_Volume%Length()
  398. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  399. ! enddo
  400. !
  401. !write(*,*) '====pump added-before add to ann'
  402. !========================Tripping In====================
  403. !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
  404. if (Rate_of_Penetration==0.) then ! .and. Op_MudOrKick%Last() == 0) then ! trip in mode(loole paeen) Mud
  405. !write(*,*) 'Tripping In'
  406. !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  407. !if ( MudIsChanged== .true. ) then
  408. ! call RemoveAnnulusMudArrays(iLoc)
  409. !endif
  410. if (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then
  411. write(*,*) 'Kick influx enters Annulus'
  412. call Ann_Density%AddToFirst (MudSystemDotOp_KickSaved_Density)
  413. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotOp_Kick_Saved_Volume)
  414. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  415. call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
  416. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  417. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  418. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  419. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  420. call Ann_MudOrKick%AddToFirst (MudSystemDotSaved_Op_MudOrKick) !<<<<<<<<
  421. call Ann_CuttingMud%AddToFirst (0)
  422. elseif (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() /= 0) then
  423. MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) + MudSystemDotOp_Kick_Saved_Volume
  424. endif
  425. if (MudSystemDotOp_Saved_MudDischarged_Volume> 0.0) then
  426. NewDensity= MudSystemDotOp_MudSaved_Density
  427. MudSystemDotNewVolume= MudSystemDotOp_Saved_MudDischarged_Volume
  428. !write(*,*) 'NewVolume=' , NewVolume
  429. !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  430. if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotDensityMixTol) &
  431. .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==1 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotCuttingDensityMixTol) &
  432. .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==0 .and. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc) < 42.) ) then ! 1-Pockets are Merged
  433. Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume)
  434. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume
  435. Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  436. Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  437. Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  438. Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  439. Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0)
  440. Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0)
  441. !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  442. else ! 2-Merging conditions are not meeted, so new pocket
  443. call Ann_Density%AddTo (MudSystemDotiLoc,NewDensity)
  444. call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotNewVolume)
  445. call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  446. call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  447. call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  448. call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  449. call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0)
  450. call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0)
  451. call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0)
  452. call Ann_CuttingMud%AddTo (MudSystemDotiLoc,0)
  453. !write(*,*) 'd) annLength=' , Ann_Density%Length()
  454. !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  455. endif
  456. endif
  457. endif
  458. !========================Tripping In - End====================
  459. !========================Drilling Mode========================
  460. if (Rate_of_Penetration>0. .and. MudSystemDotDeltaVolumeOp>0.0) then ! trip in mode(loole paeen) DrillingMode== .true.
  461. !write(*,*) 'Drilling Mode'
  462. !if ( MudIsChanged== .true. ) then
  463. ! call RemoveAnnulusMudArrays(iLoc)
  464. !endif
  465. !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  466. !NewDensity= (St_Density%Last() * AnnulusFlowRate + 141.4296E-4*Rate_of_Penetration*Diameter_of_Bit**2)/(AnnulusFlowRate+6.7995E-4*Rate_of_Penetration*Diameter_of_Bit**2)
  467. NewDensity= St_Density%Last()
  468. !NewVolume= ((AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp
  469. !!! Density in ppg, flow rate in gpm, ROP in ft/s, bit diameter in inch
  470. do MudSystemDotimud=1, MudSystemDotOp_MudDischarged_Volume%Length()
  471. if ( Op_MudOrKick%Array(MudSystemDotimud) == 0 ) then
  472. MudSystemDotOp_Density%Array(MudSystemDotimud)= NewDensity
  473. endif
  474. enddo
  475. if (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then
  476. write(*,*) 'Kick influx enters Annulus first time'
  477. !write(*,*) 'Saved_Op_MudOrKick=',Saved_Op_MudOrKick
  478. call Ann_Density%AddToFirst (MudSystemDotOp_KickSaved_Density)
  479. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotOp_Kick_Saved_Volume)
  480. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  481. call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
  482. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  483. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  484. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  485. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  486. call Ann_MudOrKick%AddToFirst (MudSystemDotSaved_Op_MudOrKick) !<<<<<<<<
  487. call Ann_CuttingMud%AddToFirst (0)
  488. elseif (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() /= 0) then
  489. MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) + MudSystemDotOp_Kick_Saved_Volume
  490. endif
  491. if (MudSystemDotOp_Saved_MudDischarged_Volume> 0.0) then
  492. !write(*,*) 'Op_Saved_Mud added'
  493. NewDensity= NewDensity !(drilling density)
  494. MudSystemDotNewVolume= MudSystemDotOp_Saved_MudDischarged_Volume + MudSystemDotDeltaVolumeOp ! (DeltaVolumeOp: for Cuttings Volume)
  495. !write(*,*) 'NewVolume=' , NewVolume
  496. !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  497. if ( (Ann_CuttingMud%Array(MudSystemDotiLoc)==1 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotCuttingDensityMixTol ) &
  498. .or. (Ann_CuttingMud%Array(MudSystemDotiLoc)==0 .and. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc) < 42.) ) then ! 1-Pockets are Merged
  499. Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume)
  500. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume
  501. Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  502. Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  503. Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  504. Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  505. Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0)
  506. Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0)
  507. Ann_CuttingMud%Array(MudSystemDotiLoc)= 1
  508. !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  509. else ! 2-Merging conditions are not meeted, so new pocket
  510. !write(*,*) 'before e) ', iloc, Ann_Density%Array(iLoc),NewDensity
  511. !write(*,*) 'before e) Ann_MudDischarged_Volume%Array(iLoc)=' , Ann_MudDischarged_Volume%Array(iLoc)
  512. call Ann_Density%AddTo (MudSystemDotiLoc,NewDensity)
  513. call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotNewVolume)
  514. call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  515. call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  516. call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  517. call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  518. call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0)
  519. call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0)
  520. call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0)
  521. call Ann_CuttingMud%AddTo (MudSystemDotiLoc,1) ! 1= cutting 0= mud
  522. !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  523. !write(*,*) 'e) annLength=' , Ann_Density%Length()
  524. endif
  525. endif
  526. endif
  527. !===================================================================
  528. !write(*,*) 'after add to ann=='
  529. !
  530. ! do imud=1, Op_MudDischarged_Volume%Length()
  531. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  532. ! enddo
  533. !
  534. ! do imud=1, Ann_MudDischarged_Volume%Length()
  535. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  536. ! enddo
  537. !
  538. !write(*,*) '==after add to ann'
  539. MudSystemDotNewVolume= ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume
  540. if (MudSystemDotiLoc==2 .and. Op_MudOrKick%Last()==0 .and. MudSystemDotNewVolume > 0.d0 ) then ! for avoid kick separation
  541. !write(*,*) 'avoid kick separation'
  542. NewDensity= MudSystemDotOp_MudSaved_Density
  543. call RemoveOpMudArrays(MudSystemDotOp_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann
  544. if ( MudSystemDotAnn_MudDischarged_Volume%Array(1) > ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline)- MudSystemDotOp_Saved_MudDischarged_Volume) then! 1st in Ann = kick
  545. !write(*,*) 'mode1'
  546. MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) - (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) -MudSystemDotOp_Saved_MudDischarged_Volume)
  547. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume) !kick
  548. else
  549. call RemoveAnnulusMudArrays(1) !kick is removed
  550. MudSystemDotiLoc= 1
  551. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume)
  552. !write(*,*) 'mode2'
  553. ! including a little expand
  554. endif
  555. if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotDensityMixTol) &
  556. .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==1 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotCuttingDensityMixTol) &
  557. .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==0 .and. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc) < 42.) ) then ! 1-Pockets are Merged
  558. Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume)
  559. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume
  560. Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  561. Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  562. Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
  563. Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
  564. Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0)
  565. Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0)
  566. else ! 2-Merging conditions are not meeted, so new pocket
  567. call Ann_Density%AddTo (MudSystemDotiLoc,NewDensity)
  568. call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotNewVolume)
  569. call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  570. call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  571. call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
  572. call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
  573. call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0)
  574. call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0)
  575. call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0)
  576. call Ann_CuttingMud%AddTo (MudSystemDotiLoc,0)
  577. !write(*,*) 'd) annLength=' , Ann_Density%Length()
  578. endif
  579. endif
  580. !===================================================================
  581. if( Op_MudOrKick%Last() == 1 .and. Ann_MudOrKick%First() == 0 ) then
  582. write(*,*) '***error2****=='
  583. write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , MudSystemDotOp_Kick_Saved_Volume,MudSystemDotOp_Saved_MudDischarged_Volume
  584. write(*,*) 'after add to ann=='
  585. do MudSystemDotimud=1, MudSystemDotOp_MudDischarged_Volume%Length()
  586. write(*,*) 'Op:', MudSystemDotimud, MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud), MudSystemDotOp_Density%Array(MudSystemDotimud) ,Op_MudOrKick%Array(MudSystemDotimud)
  587. enddo
  588. do MudSystemDotimud=1, MudSystemDotAnn_MudDischarged_Volume%Length()
  589. write(*,*) 'Ann:', MudSystemDotimud, MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud), Ann_Density%Array(MudSystemDotimud) ,Ann_MudOrKick%Array(MudSystemDotimud)
  590. enddo
  591. write(*,*) '==after add to ann'
  592. write(*,*) 'NewVolume,Op_MudOrKick%Last=' , MudSystemDotNewVolume,Op_MudOrKick%Last()
  593. write(*,*) '==***error2****'
  594. endif
  595. !=============== save Ann Mud data to transfer to the ChokeLine enterance
  596. MudSystemDotAnnMudVolumeSum= 0.d0
  597. !Ann_MudSaved_Density= 0.d0
  598. !Ann_KickSaved_Density= 0.d0
  599. MudSystemDotAnn_Saved_MudDischarged_Volume= 0.d0
  600. MudSystemDotAnn_Kick_Saved_Volume= 0.d0
  601. MudSystemDotSaved_Ann_MudOrKick= 0
  602. MudSystemDotAnn_to_Choke_2mud= .false.
  603. do MudSystemDotimud=1, MudSystemDotAnn_MudDischarged_Volume%Length()
  604. MudSystemDotAnnMudVolumeSum= MudSystemDotAnnMudVolumeSum + MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)
  605. if ( MudSystemDotAnnMudVolumeSum > sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) ) then
  606. IF (Ann_MudOrKick%Array(MudSystemDotimud) == 0) THEN
  607. MudSystemDotAnn_MudSaved_Density = Ann_Density%Array(MudSystemDotimud)
  608. MudSystemDotAnn_Saved_MudDischarged_Volume = MudSystemDotAnnMudVolumeSum - sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
  609. ELSEIF (Ann_MudOrKick%Array(MudSystemDotimud) > 0 .AND. Ann_MudOrKick%Array(MudSystemDotimud) <100) THEN ! 104= AIR
  610. MudSystemDotAnn_Kick_Saved_Volume = MudSystemDotAnnMudVolumeSum - sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
  611. MudSystemDotSaved_Ann_MudOrKick= Ann_MudOrKick%Array (MudSystemDotimud)
  612. MudSystemDotAnn_KickSaved_Density= Ann_Density%Array(MudSystemDotimud)
  613. END IF
  614. do ii= MudSystemDotimud + 1, MudSystemDotAnn_MudDischarged_Volume%Length()
  615. IF (Ann_MudOrKick%Array(ii) == 0) THEN
  616. MudSystemDotAnn_MudSaved_Density = ((MudSystemDotAnn_MudSaved_Density * MudSystemDotAnn_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * MudSystemDotAnn_MudDischarged_Volume%Array(ii))) / (MudSystemDotAnn_Saved_MudDischarged_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii))
  617. MudSystemDotAnn_Saved_MudDischarged_Volume = MudSystemDotAnn_Saved_MudDischarged_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii)
  618. MudSystemDotAnn_to_Choke_2mud= .true.
  619. ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR
  620. MudSystemDotAnn_Kick_Saved_Volume = MudSystemDotAnn_Kick_Saved_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii)
  621. MudSystemDotSaved_Ann_MudOrKick= Ann_MudOrKick%Array (ii)
  622. MudSystemDotAnn_KickSaved_Density= Ann_Density%Array(ii)
  623. END IF
  624. enddo
  625. !WRITE (*,*) 'Ann_Saved_Mud_Volume, Ann_Kick_Saved_Volume', Ann_Saved_MudDischarged_Volume, Ann_Kick_Saved_Volume
  626. exit
  627. endif
  628. enddo
  629. MudSystemDotAnn_Saved_MudDischarged_Volume_Final= MudSystemDotAnn_Saved_MudDischarged_Volume !+ Ann_Kick_Saved_Volume
  630. MudSystemDotAnn_Kick_Saved_Volume_Final= MudSystemDotAnn_Kick_Saved_Volume
  631. IF (WellHeadIsOpen) MudVolume_InjectedFromAnn = MudSystemDotAnn_Saved_MudDischarged_Volume_Final -((MudSystemDotQlost/60.0d0)*DeltaT_Mudline)
  632. !WRITE (*,*) 'MudVolume_InjectedFromAnn=', MudVolume_InjectedFromAnn
  633. !======================================================================
  634. !write(*,*) 'c)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
  635. !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  636. !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume
  637. MudSystemDottotal_injected = MudSystemDottotal_injected + MudVolume_InjectedFromAnn
  638. if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  639. MudSystemDottotal_injected= 0.
  640. endif
  641. !write(*,*) ' total injected-tripin =' , total_injected
  642. !write(*,*) 'injected-tripin =' , MudVolume_InjectedFromAnn
  643. !======================== Annulus ====================
  644. !MudIsChanged= .false.
  645. MudSystemDotimud= 0
  646. do while (MudSystemDotimud < Ann_Mud_Forehead_X%Length())
  647. MudSystemDotimud = MudSystemDotimud + 1
  648. if (MudSystemDotimud> 1) then
  649. Ann_Mud_Backhead_X%Array(MudSystemDotimud)= Ann_Mud_Forehead_X%Array(MudSystemDotimud-1)
  650. Ann_Mud_Backhead_section%Array(MudSystemDotimud)= Ann_Mud_Forehead_section%Array(MudSystemDotimud-1)
  651. endif
  652. ! <<< Fracture Shoe Lost
  653. IF ( MudSystemDotShoeLost .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(MudSystemDotimud) .and. Shoe%ShoeDepth >= Ann_Mud_Forehead_X%Array(MudSystemDotimud) ) then
  654. !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline)
  655. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)-((MudSystemDotQlost/60.0d0)*DeltaT_Mudline) !(gal)
  656. if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) < 0.0) then
  657. !write(*,*) 'mud is removed by shoe lost, imud=' , imud
  658. call RemoveAnnulusMudArrays(MudSystemDotimud)
  659. MudSystemDotimud= MudSystemDotimud-1
  660. cycle
  661. endif
  662. ENDIF
  663. ! Fracture Shoe Lost >>>
  664. MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))) &
  665. / ABS(MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud)))
  666. ! +1 for string , -1 for annulus
  667. Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))- Ann_Mud_Backhead_X%Array(MudSystemDotimud))* &
  668. MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
  669. Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
  670. if ( MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) <= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
  671. Ann_Mud_Forehead_section%Array(MudSystemDotimud)= Ann_Mud_Backhead_section%Array(MudSystemDotimud)
  672. Ann_Mud_Forehead_X%Array(MudSystemDotimud)= Ann_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud))
  673. ! 7.48 is for gal to ft^3
  674. else
  675. MudSystemDotisection= Ann_Mud_Backhead_section%Array(MudSystemDotimud)+1
  676. Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
  677. do
  678. if (MudSystemDotisection > MudSystemDotNoPipeSections) then ! last pipe section(well exit)
  679. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
  680. Ann_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)
  681. Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotNoPipeSections
  682. if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
  683. !write(*,*) 'remove******'
  684. call RemoveAnnulusMudArrays(MudSystemDotimud)
  685. endif
  686. exit
  687. endif
  688. MudSystemDotxx= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
  689. if (MudSystemDotxx<= 1.0) then
  690. Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
  691. Ann_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection)
  692. exit
  693. else
  694. Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
  695. MudSystemDotisection= MudSystemDotisection+ 1
  696. endif
  697. enddo
  698. endif
  699. ! write(*,*) 'imud=' , imud
  700. !write(*,*) 'Pinter4 **Ann_Length()=' , Ann_Mud_Forehead_X%Length()
  701. ! write(*,*) 'Ann_Density%Array (imud)=' , Ann_Density%Array (imud)
  702. !
  703. !
  704. !write(*,*) imud,'Ann_Mud_Forehead_X%Array(imud)=' , Ann_Mud_Forehead_X%Array(imud)
  705. !if (Ann_Mud_Forehead_X%Array(imud) < Xend_PipeSection(NoPipeSections)) then
  706. ! Ann_Mud_Forehead_X%Array(imud) = Xend_PipeSection(NoPipeSections) ! for error preventing
  707. !endif
  708. !write(*,*) imud, 'Ann_MudDischarged_Volume%Array(imud)=' , Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud)
  709. enddo
  710. if (Ann_Mud_Forehead_X%Last() < MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)) then
  711. Ann_Mud_Forehead_X%Array(Ann_Mud_Forehead_X%Length()) = MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections) ! for error preventing
  712. endif
  713. !========================ANNULUS END=================
  714. !write(*,*) 'sum(Ann_MudDischarged_Volume%Array())=' , sum(Ann_MudDischarged_Volume%Array(:))
  715. !=========================================================
  716. !write(*,*) 'before======2'
  717. !
  718. ! do imud=1, Op_MudDischarged_Volume%Length()
  719. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  720. ! enddo
  721. !write(*,*) '2======before'
  722. !========================Bottom Hole=================
  723. MudSystemDotimud=0
  724. do while (MudSystemDotimud < MudSystemDotOp_Mud_Forehead_X%Length())
  725. MudSystemDotimud = MudSystemDotimud + 1
  726. if (MudSystemDotimud> 1) then
  727. MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud-1)
  728. Op_Mud_Backhead_section%Array(MudSystemDotimud)= Op_Mud_Forehead_section%Array(MudSystemDotimud-1)
  729. endif
  730. !write(*,*) 'imud**=' , imud
  731. MudSystemDotDirectionCoef= (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))) &
  732. / ABS(MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud)))
  733. ! +1 for string , -1 for annulus
  734. MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud))* &
  735. MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
  736. MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
  737. !write(*,*) ' Op_EmptyVolume_inBackheadLocation%Array(1) =' , Op_EmptyVolume_inBackheadLocation%Array(1)
  738. if ( MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(1) < 0.0) CALL ErrorStop1 ('Negative Empty volume')
  739. if ( MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
  740. Op_Mud_Forehead_section%Array(MudSystemDotimud)= Op_Mud_Backhead_section%Array(MudSystemDotimud)
  741. 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))
  742. ! 7.48 is for gal to ft^3
  743. else
  744. MudSystemDotisection= Op_Mud_Backhead_section%Array(MudSystemDotimud)+1
  745. MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
  746. do
  747. if (MudSystemDotisection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
  748. !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space
  749. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
  750. MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)
  751. Op_Mud_Forehead_section%Array(MudSystemDotimud)= F_BottomHoleIntervalCounts
  752. if (MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
  753. call RemoveOpMudArrays(MudSystemDotimud)
  754. endif
  755. exit
  756. endif
  757. MudSystemDotxx= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection) !(gal)
  758. if (MudSystemDotxx<= 1.0) then
  759. Op_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
  760. MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_OpSection(MudSystemDotisection)- MudSystemDotXstart_OpSection(MudSystemDotisection)))+ MudSystemDotXstart_OpSection(MudSystemDotisection)
  761. exit
  762. else
  763. MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection)
  764. MudSystemDotisection= MudSystemDotisection+ 1
  765. endif
  766. enddo
  767. endif
  768. ! for OP remove:
  769. if (MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)== MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)) then
  770. MudSystemDottotalLength = MudSystemDotOp_MudDischarged_Volume%Length()
  771. do while(MudSystemDotimud < MudSystemDottotalLength)
  772. !imud = imud + 1
  773. call RemoveOpMudArrays(MudSystemDottotalLength)
  774. MudSystemDottotalLength = MudSystemDottotalLength - 1
  775. enddo
  776. exit !
  777. endif
  778. !if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(F_BottomHoleIntervalCounts)) then
  779. ! totalLength = Op_MudDischarged_Volume%Length()
  780. ! do while(imud <= totalLength)
  781. !
  782. ! imud = imud + 1
  783. ! call RemoveOpMudArrays(imud)
  784. ! totalLength = totalLength - 1
  785. !
  786. !
  787. ! enddo
  788. !
  789. ! exit !
  790. !
  791. !endif
  792. enddo
  793. !write(*,*) 'OpSection_VolumeCapacity sum=' , sum(OpSection_VolumeCapacity(:))
  794. !========================Bottom Hole END=================
  795. !write(*,*) 'after sorting=='
  796. !
  797. ! do imud=1, Op_MudDischarged_Volume%Length()
  798. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  799. ! enddo
  800. !
  801. ! do imud=1, Ann_MudDischarged_Volume%Length()
  802. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  803. ! enddo
  804. !
  805. ! !
  806. ! !do imud=1, st_MudDischarged_Volume%Length()
  807. ! ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
  808. ! !enddo
  809. !
  810. !write(*,*) '==after sorting'
  811. ! write(*,*) 'after sorting st=='
  812. !
  813. ! do imud=1, st_MudDischarged_Volume%Length()
  814. ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud),St_Density%Array(imud)
  815. ! enddo
  816. !
  817. !write(*,*) '==after sorting st'
  818. !write(*,*) '**Ann_Kick_Saved_Final,Mud_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn
  819. end subroutine Pump_and_TripIn
  820. subroutine ChokeLineMud ! is called in subroutine CirculationCodeSelect
  821. Use GeoElements_FluidModule
  822. USE CMudPropertiesVariables
  823. USE MudSystemVARIABLES
  824. USE Pumps_VARIABLES
  825. !USE CHOKEVARIABLES
  826. !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
  827. !use CManifolds
  828. use CDrillWatchVariables
  829. !use CHOKEVARIABLES
  830. !use CChokeManifoldVariables
  831. !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  832. USE sROP_Other_Variables
  833. USE sROP_Variables
  834. Use KickVariables
  835. USE PressureDisplayVARIABLES
  836. Use CError
  837. Use , intrinsic :: IEEE_Arithmetic
  838. implicit none
  839. integer i,ii,error_occured
  840. error_occured = 0
  841. !write(*,*) 'begining chokeline=='
  842. !write(*,*) 'Ann last:', Ann_MudDischarged_Volume%Last(), Ann_Density%Last() ,Ann_MudOrKick%Last()
  843. !
  844. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  845. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  846. !enddo
  847. !write(*,*) 'Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn
  848. !write(*,*) 'begining chokeline=='
  849. MudSystemDotChokeLineFlowRate = MUD(4)%Q
  850. !WRITE (*,*) 'MUD(4)%Q', MUD(4)%Q
  851. if (MudSystemDotNewPipeFilling == 0) then ! .or. UtubeFilling==0) then
  852. MudSystemDotChokeLineFlowRate= 0.
  853. endif
  854. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()-2
  855. if ( ChokeLine_MudOrKick%Array(MudSystemDotimud) ==1 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+1) ==0 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+2) ==1 ) then
  856. write(*,*) 'error_location is 1'
  857. error_occured = 1
  858. endif
  859. enddo
  860. !
  861. !do imud=1, st_MudDischarged_Volume%Length()
  862. ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
  863. !enddo
  864. !========================CHOKE LINE ENTRANCE=================
  865. !if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume-((Qlost/60.0d0)*DeltaT_Mudline) ) == 0.0 ) then
  866. if ( MudSystemDotAnn_Kick_Saved_Volume > 1.0e-5 .and. ( MudVolume_InjectedFromAnn ) <= 1.0e-5 ) then
  867. !WRITE (*,*) 'only kick enters to chokeline, Casing pressure = ', PressureGauges(2)
  868. if (ChokeLine_MudOrKick%First() == 0) then
  869. call MudSystemDotChokeLine_Density%AddToFirst (MudSystemDotAnn_KickSaved_Density)
  870. call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst (0.d0)
  871. call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  872. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  873. call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  874. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  875. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  876. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  877. call ChokeLine_MudOrKick%AddToFirst (MudSystemDotSaved_Ann_MudOrKick)
  878. ChokeLineDensity_Old= MudSystemDotAnn_KickSaved_Density
  879. endif
  880. MudSystemDotChokeLine_MudDischarged_Volume%Array(1)= MudSystemDotChokeLine_MudDischarged_Volume%Array(1)+ MudSystemDotAnn_Kick_Saved_Volume !(gal)
  881. endif
  882. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()-2
  883. if ( ChokeLine_MudOrKick%Array(MudSystemDotimud) ==1 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+1) ==0 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+2) ==1 ) then
  884. write(*,*) 'error_location is 2'
  885. error_occured = 1
  886. endif
  887. enddo
  888. !if ( Ann_Kick_Saved_Volume == 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 ) then
  889. if ( MudSystemDotAnn_Kick_Saved_Volume <= 1.0e-5 .and. MudVolume_InjectedFromAnn > 1.0e-5 ) then
  890. !WRITE (*,*) 'only mud enters to chokeline'
  891. if ((MudSystemDotAnn_to_Choke_2mud == .false. .and. ABS(ChokeLineDensity_Old - MudSystemDotAnn_MudSaved_Density) >= MudSystemDotDensityMixTol) .or. ChokeLine_MudOrKick%First() /= 0) then ! new mud is pumped
  892. call MudSystemDotChokeLine_Density%AddToFirst (MudSystemDotAnn_MudSaved_Density)
  893. call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst (0.0d0)
  894. call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  895. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  896. call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  897. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  898. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  899. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  900. call ChokeLine_MudOrKick%AddToFirst (0)
  901. ChokeLineDensity_Old= MudSystemDotAnn_MudSaved_Density
  902. endif
  903. !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
  904. MudSystemDotChokeLine_MudDischarged_Volume%Array(1)= MudSystemDotChokeLine_MudDischarged_Volume%Array(1)+ (MudVolume_InjectedFromAnn) !(gal)
  905. endif
  906. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()-2
  907. if ( ChokeLine_MudOrKick%Array(MudSystemDotimud) ==1 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+1) ==0 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+2) ==1 ) then
  908. write(*,*) 'error_location is 3'
  909. error_occured = 1
  910. endif
  911. enddo
  912. !if ( Ann_Kick_Saved_Volume > 0.0 .and. (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() /= 0 ) then
  913. if ( MudSystemDotAnn_Kick_Saved_Volume > 1.0e-5 .and. (MudVolume_InjectedFromAnn) > 1.0e-5 .and. ChokeLine_MudOrKick%First() /= 0 ) then
  914. WRITE (*,*) 'Kick Enters Choke line Last Time'
  915. MudSystemDotChokeLine_MudDischarged_Volume%Array(1)= MudSystemDotChokeLine_MudDischarged_Volume%Array(1)+ MudSystemDotAnn_Kick_Saved_Volume !(gal)
  916. call MudSystemDotChokeLine_Density%AddToFirst (MudSystemDotAnn_MudSaved_Density)
  917. !call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) )
  918. call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst (MudVolume_InjectedFromAnn)
  919. call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  920. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  921. call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  922. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  923. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  924. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  925. call ChokeLine_MudOrKick%AddToFirst (0)
  926. ChokeLineDensity_Old= MudSystemDotAnn_MudSaved_Density
  927. !ELSE if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() == 0 ) then
  928. ELSE if ( MudSystemDotAnn_Kick_Saved_Volume > 1.0e-5 .and. ( MudVolume_InjectedFromAnn ) > 1.0e-5 .and. ChokeLine_MudOrKick%First() == 0 ) then
  929. WRITE (*,*) 'Kick Enters Choke line First Time'
  930. !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
  931. MudSystemDotChokeLine_MudDischarged_Volume%Array(1)= MudSystemDotChokeLine_MudDischarged_Volume%Array(1)+ ( MudVolume_InjectedFromAnn ) !(gal)
  932. call MudSystemDotChokeLine_Density%AddToFirst (MudSystemDotAnn_KickSaved_Density)
  933. call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst (MudSystemDotAnn_Kick_Saved_Volume)
  934. call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  935. call ChokeLine_Mud_Forehead_section%AddToFirst (1)
  936. call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  937. call ChokeLine_Mud_Backhead_section%AddToFirst (1)
  938. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  939. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  940. call ChokeLine_MudOrKick%AddToFirst (MudSystemDotSaved_Ann_MudOrKick)
  941. ChokeLineDensity_Old= MudSystemDotAnn_KickSaved_Density
  942. endif
  943. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()-2
  944. if ( ChokeLine_MudOrKick%Array(MudSystemDotimud) ==1 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+1) ==0 .and. ChokeLine_MudOrKick%Array(MudSystemDotimud+2) ==1 ) then
  945. write(*,*) 'error_location is 4'
  946. error_occured = 1
  947. endif
  948. enddo
  949. if (error_occured == 1) then
  950. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()
  951. write(*,*) 'ChokeLine:', MudSystemDotimud, MudSystemDotChokeLine_Density%Array(MudSystemDotimud) ,ChokeLine_MudOrKick%Array(MudSystemDotimud)
  952. enddo
  953. endif
  954. !==========================================================
  955. !
  956. !write(*,*) 'after add chokeline=='
  957. !
  958. ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
  959. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  960. ! enddo
  961. !
  962. !write(*,*) 'after add chokeline=='
  963. !
  964. !
  965. !=============== save Choke Mud data==========================
  966. MudSystemDotChokeMudVolumeSum= 0.d0
  967. !Ann_MudSaved_Density= 0.d0
  968. !Ann_KickSaved_Density= 0.d0
  969. MudSystemDotChoke_Saved_MudDischarged_Volume= 0.d0
  970. MudSystemDotChoke_Kick_Saved_Volume= 0.d0
  971. MudSystemDotSaved_Choke_MudOrKick= 0
  972. do MudSystemDotimud=1, MudSystemDotChokeLine_MudDischarged_Volume%Length()
  973. MudSystemDotChokeMudVolumeSum= MudSystemDotChokeMudVolumeSum + MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)
  974. if ( MudSystemDotChokeMudVolumeSum > MudSystemDotChokeLine_VolumeCapacity ) then
  975. IF (ChokeLine_MudOrKick%Array(MudSystemDotimud) == 0) THEN
  976. MudSystemDotChoke_MudSaved_Density = MudSystemDotChokeLine_Density%Array(MudSystemDotimud)
  977. MudSystemDotChoke_Saved_MudDischarged_Volume = MudSystemDotChokeMudVolumeSum - MudSystemDotChokeLine_VolumeCapacity
  978. ELSEIF (ChokeLine_MudOrKick%Array(MudSystemDotimud) > 0 .AND. ChokeLine_MudOrKick%Array(MudSystemDotimud) <100) THEN ! 104= AIR
  979. MudSystemDotChoke_Kick_Saved_Volume = MudSystemDotChokeMudVolumeSum - MudSystemDotChokeLine_VolumeCapacity
  980. MudSystemDotSaved_Choke_MudOrKick= ChokeLine_MudOrKick%Array (MudSystemDotimud)
  981. MudSystemDotChoke_KickSaved_Density= MudSystemDotChokeLine_Density%Array(MudSystemDotimud)
  982. END IF
  983. do ii= MudSystemDotimud + 1, MudSystemDotChokeLine_MudDischarged_Volume%Length()
  984. IF (ChokeLine_MudOrKick%Array(ii) == 0) THEN
  985. MudSystemDotChoke_MudSaved_Density = ((MudSystemDotChoke_MudSaved_Density * MudSystemDotChoke_Saved_MudDischarged_Volume) + (MudSystemDotChokeLine_Density%Array(ii) * MudSystemDotChokeLine_MudDischarged_Volume%Array(ii))) / (MudSystemDotChoke_Saved_MudDischarged_Volume + MudSystemDotChokeLine_MudDischarged_Volume%Array(ii))
  986. MudSystemDotChoke_Saved_MudDischarged_Volume = MudSystemDotChoke_Saved_MudDischarged_Volume + MudSystemDotChokeLine_MudDischarged_Volume%Array(ii)
  987. ELSEIF (ChokeLine_MudOrKick%Array(ii) > 0 .AND. ChokeLine_MudOrKick%Array(ii) <100) THEN ! 104= AIR
  988. MudSystemDotChoke_Kick_Saved_Volume = MudSystemDotChoke_Kick_Saved_Volume + MudSystemDotChokeLine_MudDischarged_Volume%Array(ii)
  989. MudSystemDotSaved_Choke_MudOrKick= ChokeLine_MudOrKick%Array (ii)
  990. MudSystemDotChoke_KickSaved_Density= MudSystemDotChokeLine_Density%Array(ii)
  991. END IF
  992. enddo
  993. !WRITE (*,*) 'Choke_Saved_Mud_Volume, Choke_Kick_Saved_Volume', Choke_Saved_MudDischarged_Volume, Choke_Kick_Saved_Volume
  994. exit ! exits do
  995. endif
  996. enddo
  997. MudSystemDotChoke_Saved_MudDischarged_Volume_Final= MudSystemDotChoke_Saved_MudDischarged_Volume !+ Choke_Kick_Saved_Volume
  998. MudSystemDotChoke_Kick_Saved_Volume_Final= MudSystemDotChoke_Kick_Saved_Volume
  999. !======================================================================
  1000. !
  1001. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1002. ! write(*,*) 'a)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1003. !enddo
  1004. !write(*,*) 'choke_Mud sum=' , sum(ChokeLine_MudDischarged_Volume%Array(:))
  1005. !write(*,*) 'choke_cap=' , ChokeLine_VolumeCapacity
  1006. !write(*,*) 'Choke_Saved_Mud=' , Choke_Saved_MudDischarged_Volume_Final
  1007. !write(*,*) 'Choke_Saved_Kick=' , Choke_Kick_Saved_Volume_Final
  1008. !========================Choke Line=================
  1009. MudSystemDotimud=0
  1010. do while (MudSystemDotimud < MudSystemDotChokeLine_Mud_Forehead_X%Length())
  1011. MudSystemDotimud = MudSystemDotimud + 1
  1012. if (MudSystemDotimud> 1) then
  1013. MudSystemDotChokeLine_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotChokeLine_Mud_Forehead_X%Array(MudSystemDotimud-1)
  1014. ChokeLine_Mud_Backhead_section%Array(MudSystemDotimud)= ChokeLine_Mud_Forehead_section%Array(MudSystemDotimud-1)
  1015. endif
  1016. !DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) &
  1017. ! / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud)))
  1018. ! +1 for string , -1 for annulus
  1019. MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= (BopStackSpecification%ChokeLineLength- MudSystemDotChokeLine_Mud_Backhead_X%Array(MudSystemDotimud))* MudSystemDotArea_ChokeLineFt !(ft^3)
  1020. MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
  1021. if ( MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
  1022. ChokeLine_Mud_Forehead_section%Array(MudSystemDotimud)= ChokeLine_Mud_Backhead_section%Array(MudSystemDotimud)
  1023. MudSystemDotChokeLine_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotChokeLine_Mud_Backhead_X%Array(MudSystemDotimud)+ (MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_ChokeLineFt
  1024. ! 7.48 is for gal to ft^3
  1025. else
  1026. MudSystemDotisection= ChokeLine_Mud_Backhead_section%Array(MudSystemDotimud)+1
  1027. MudSystemDotChokeLine_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
  1028. do
  1029. if (MudSystemDotisection > 1) then ! last pipe section(Chokeline exit)
  1030. MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotChokeLine_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
  1031. MudSystemDotChokeLine_Mud_Forehead_X%Array(MudSystemDotimud)= BopStackSpecification%ChokeLineLength
  1032. ChokeLine_Mud_Forehead_section%Array(MudSystemDotimud)= 1
  1033. if (MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string
  1034. call MudSystemDotChokeLine_MudDischarged_Volume%Remove (MudSystemDotimud)
  1035. call MudSystemDotChokeLine_Mud_Backhead_X%Remove (MudSystemDotimud)
  1036. call ChokeLine_Mud_Backhead_section%Remove (MudSystemDotimud)
  1037. call MudSystemDotChokeLine_Mud_Forehead_X%Remove (MudSystemDotimud)
  1038. call ChokeLine_Mud_Forehead_section%Remove (MudSystemDotimud)
  1039. call MudSystemDotChokeLine_Density%Remove (MudSystemDotimud)
  1040. call MudSystemDotChokeLine_RemainedVolume_in_LastSection%Remove (MudSystemDotimud)
  1041. call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud)
  1042. call ChokeLine_MudOrKick%Remove (MudSystemDotimud)
  1043. endif
  1044. exit
  1045. endif
  1046. MudSystemDotxx= MudSystemDotChokeLine_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotChokeLine_VolumeCapacity !(gal)
  1047. if (MudSystemDotxx<= 1.0) then
  1048. ChokeLine_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
  1049. MudSystemDotChokeLine_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotxx * BopStackSpecification%ChokeLineLength
  1050. exit
  1051. else
  1052. MudSystemDotChokeLine_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotChokeLine_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotChokeLine_VolumeCapacity
  1053. MudSystemDotisection= MudSystemDotisection+ 1
  1054. endif
  1055. enddo
  1056. endif
  1057. enddo
  1058. !========================Choke Line END=================
  1059. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1060. ! write(*,*) 'b)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1061. !enddo
  1062. ChokeOutletDensity= MudSystemDotChokeLine_Density%Last() ! used in MudSystem
  1063. do i=1, ChokeLine_MudOrKick%Length()
  1064. !write(*,555) i,'Choke_Volume(i), type=' ,ChokeLine_MudDischarged_Volume%Array(i),ChokeLine_MudOrKick%Array(i)
  1065. IF (IEEE_Is_NaN(MudSystemDotChokeLine_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Choke Volume-Plot')
  1066. IF (MudSystemDotChokeLine_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Choke Volume= <=0' , MudSystemDotChokeLine_MudDischarged_Volume%Array(i))
  1067. enddo
  1068. 555 FORMAT(I3,5X,A42,(f12.5),5X,I3)
  1069. !write(*,*) 'after sorting chokeline=='
  1070. !IF (ANY(ChokeLine_MudOrKick%Array(:) > 0)) THEN
  1071. ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1072. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1073. ! enddo
  1074. !END IF
  1075. !do imud=1, Ann_MudDischarged_Volume%Length()
  1076. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  1077. !enddo
  1078. !
  1079. !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  1080. ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
  1081. !write(*,*) '==after sorting chokeline'
  1082. end subroutine ChokeLineMud
  1083. subroutine Choke_GasSound ! is called in subroutine CirculationCodeSelect
  1084. use CSounds
  1085. !Use GeoElements_FluidModule
  1086. !USE CMudPropertiesVariables
  1087. USE MudSystemVARIABLES
  1088. !USE Pumps_VARIABLES
  1089. !!USE CHOKEVARIABLES
  1090. !!USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
  1091. !!use CManifolds
  1092. !use CDrillWatchVariables
  1093. !!use CHOKEVARIABLES
  1094. !!use CChokeManifoldVariables
  1095. !use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
  1096. !USE sROP_Other_Variables
  1097. !USE sROP_Variables
  1098. !Use KickVariables
  1099. !USE PressureDisplayVARIABLES
  1100. !Use CError
  1101. !Use , intrinsic :: IEEE_Arithmetic
  1102. if ( ChokeLine_MudOrKick%Last() > 0 .AND. WellToChokeManifoldOpen == .true.) then
  1103. !WellToChokeManifoldWasOpen
  1104. MudSystemDotSoundGasThroughChoke = 100 !100:chon dar adadhaye kamtar az 100 seda ghaat mishavad. eslah shavad.5.8.98 !int (min(ChokeLineFlowRate/2. , 100.))
  1105. print* , 'SoundGasThroughChoke1=', MudSystemDotSoundGasThroughChoke
  1106. !WRITE (*,*) 'WellToChokeManifoldWasOpen-Sound', WellToChokeManifoldWasOpen
  1107. WRITE (*,*) 'WellToChokeManifoldOpen', WellToChokeManifoldOpen
  1108. else
  1109. MudSystemDotSoundGasThroughChoke = 0
  1110. print* , 'SoundGasThroughChoke2=', MudSystemDotSoundGasThroughChoke
  1111. endif
  1112. !print* , 'SoundGasThroughChoke3=', SoundGasThroughChoke
  1113. call SetSoundGasThroughChoke(MudSystemDotSoundGasThroughChoke)
  1114. end subroutine Choke_GasSound