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.
 
 
 
 
 
 

1176 lines
73 KiB

  1. subroutine Kick_Migration ! is called in subroutine CirculationCodeSelect
  2. Use GeoElements_FluidModule
  3. USE CMudPropertiesVariables
  4. USE MudSystemVARIABLES
  5. USE Pumps_VARIABLES
  6. use CDrillWatchVariables
  7. !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  8. USE sROP_Other_Variables
  9. USE sROP_Variables
  10. USE CReservoirVariables
  11. USE KickVARIABLES
  12. implicit none
  13. integer jelement, jmud, jsection,ielement,i,kickNumber
  14. integer jopelement,jopmud,jopsection,CuttingValue
  15. !MUD(2)%Q= MPumps%Total_Pump_GPM
  16. !MudSystem%StringFlowRate= MUD(2)%Q
  17. !MudSystem%AnnulusFlowRate= MUD(2)%Q
  18. !
  19. !if (NewPipeFilling == 0) then
  20. ! MudSystem%StringFlowRate= 0.
  21. ! MudSystem%AnnulusFlowRate= 0.
  22. !endif
  23. !StringFlowRateFinal= MudSystem%StringFlowRate
  24. !AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate
  25. !write(*,*) 'MUD(2)%Q=====' , MUD(2)%Q
  26. !write(*,*) 'Kick Migration,NewInfluxNumber:' , NewInfluxNumber
  27. !FirstSetKickMigration
  28. !write(*,*) 'NewInfluxNumber=' , NewInfluxNumber
  29. DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber
  30. !write(*,*) 'KickNumber=' , KickNumber
  31. if (KickFlux .AND. NOT(KickOffBottom) .and. KickNumber == MudSystem%NewInfluxNumber) cycle
  32. if ( KickNumber == MudSystem%Ann_MudOrKick%Last() ) cycle ! when the last element in Annulus is kick, Migration is not called
  33. !write(*,*) 'Migration will be done for,KickNumber=' ,KickNumber
  34. !=================== Bottom Hole ENTRANCE(due to Kick) ===================
  35. !KickDx= (AutoMigrationRate/60.)*DeltaT_Mudline !3600 (ft/min)= 6 ft set in start up
  36. MudSystem%Op_KickLoc= 0
  37. MudSystem%Ann_KickLoc= 0
  38. MudSystem%ChokeLine_KickLoc= 0
  39. do i = 1, MudSystem%Op_MudOrKick%Length ()
  40. if (MudSystem%Op_MudOrKick%Array(i) == KickNumber) then
  41. MudSystem%Op_KickLoc = i
  42. exit
  43. endif
  44. end do
  45. do i = 1, MudSystem%Ann_MudOrKick%Length ()
  46. if (MudSystem%Ann_MudOrKick%Array(i) == KickNumber) then
  47. MudSystem%Ann_KickLoc = i
  48. exit
  49. endif
  50. end do
  51. do i = 1, MudSystem%ChokeLine_MudOrKick%Length ()
  52. if (MudSystem%ChokeLine_MudOrKick%Array(i) == KickNumber) then
  53. MudSystem%ChokeLine_KickLoc = i
  54. exit
  55. endif
  56. end do
  57. !write(*,*) 'Op_KickLoc=' , Op_KickLoc
  58. !write(*,*) 'Ann_KickLoc=' , Ann_KickLoc
  59. !!write(*,*) 'ChokeLine_KickLoc=' , ChokeLine_KickLoc
  60. !
  61. !
  62. !write(*,*) 'Op_MudOrKick%Length ()=' , Op_MudOrKick%Length ()
  63. !
  64. !
  65. !============================== foreheade kick be mate reside bashad *3 ==============================
  66. if (MudSystem%Op_KickLoc == MudSystem%Op_MudOrKick%Length () .and. MudSystem%Ann_KickLoc==0 ) then
  67. !write(*,*) '****3'
  68. MudSystem%iLoc= 2
  69. MudSystem%KickDv= MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Forehead_section%Array(MudSystem%Op_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal
  70. MudSystem%MinKickDv= min( MudSystem%KickDv,MudSystem%Ann_MudDischarged_Volume%Array (1), MudSystem%Op_MudDischarged_Volume%Last () )
  71. MudSystem%NewDensity= MudSystem%Ann_Density%Array (1)
  72. MudSystem%NewVolume= MudSystem%MinKickDv
  73. if ( MudSystem%MinKickDv == MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) ham baghi mimund
  74. MudSystem%Ann_MudDischarged_Volume%Array (1)= MudSystem%Ann_MudDischarged_Volume%Array (1) - MudSystem%MinKickDv
  75. call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_Density%Last())
  76. call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%MinKickDv)
  77. call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1))
  78. call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1)
  79. call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1))
  80. call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1)
  81. call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  82. call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  83. call MudSystem%Ann_MudOrKick%AddToFirst (KickNumber)
  84. call MudSystem%Ann_CuttingMud%AddToFirst (0)
  85. MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv
  86. ! backheade kick zire mate bashad
  87. if (MudSystem%Op_KickLoc > 1) then
  88. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  89. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  90. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  91. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  92. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  93. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  94. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  95. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  96. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  97. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  98. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  99. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  100. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  101. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  102. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  103. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  104. endif
  105. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-1===============================
  106. !write(*,*) '****3-1'
  107. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  108. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  109. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  110. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  111. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  112. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  113. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  114. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  115. call MudSystem%Op_MudOrKick%AddToFirst (0)
  116. endif
  117. elseif ( MudSystem%MinKickDv == MudSystem%Ann_MudDischarged_Volume%Array (1) ) then ! eleman bala sari baghi nemimund
  118. MudSystem%Ann_Density%Array(1)= MudSystem%Op_Density%Last()
  119. MudSystem%Ann_MudOrKick%Array(1)= KickNumber
  120. MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv
  121. ! backheade kick zire mate bashad
  122. if (MudSystem%Op_KickLoc > 1) then
  123. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  124. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  125. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  126. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  127. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  128. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  129. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  130. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  131. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  132. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  133. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  134. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  135. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  136. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  137. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  138. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  139. endif
  140. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-2===============================
  141. !write(*,*) '****3-2'
  142. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  143. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  144. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  145. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  146. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  147. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  148. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  149. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  150. call MudSystem%Op_MudOrKick%AddToFirst (0)
  151. endif
  152. !
  153. elseif ( MudSystem%MinKickDv == MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick hazf mishod
  154. MudSystem%Ann_MudDischarged_Volume%Array (1)= MudSystem%Ann_MudDischarged_Volume%Array (1) - MudSystem%MinKickDv
  155. call MudSystem%Ann_Density%AddToFirst (MudSystem%Op_Density%Last())
  156. call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%MinKickDv)
  157. call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1))
  158. call MudSystem%Ann_Mud_Forehead_section%AddToFirst (F_Counts%StringIntervalCounts+1)
  159. call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_Counts%StringIntervalCounts+1))
  160. call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_Counts%StringIntervalCounts+1)
  161. call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  162. call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  163. call MudSystem%Ann_MudOrKick%AddToFirst (KickNumber)
  164. call MudSystem%Ann_CuttingMud%AddToFirst (0)
  165. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  166. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  167. call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc)
  168. call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc)
  169. call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc)
  170. call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc)
  171. call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc)
  172. call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc)
  173. call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc)
  174. call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc)
  175. call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc)
  176. ! backheade kick zire mate bashad
  177. if (MudSystem%Op_KickLoc > 1) then
  178. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  179. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  180. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  181. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  182. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  183. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  184. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  185. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  186. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  187. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  188. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  189. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  190. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  191. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  192. endif
  193. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-3===============================
  194. !write(*,*) '****3-3'
  195. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  196. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  197. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  198. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  199. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  200. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  201. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  202. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  203. call MudSystem%Op_MudOrKick%AddToFirst (0)
  204. endif
  205. endif
  206. endif
  207. !========================================================================================
  208. !============================== foreheade kick be mate reside bashad *3 with pump ==============================
  209. ! if (Op_KickLoc == Op_MudOrKick%Length () .and. Ann_KickLoc==0 .and. MudSystem%AnnulusFlowRate /= 0.0 ) then
  210. ! write(*,*) '****3 with pump'
  211. !
  212. ! KickMigration_2SideBit= .true.
  213. ! !iloc= 2
  214. !
  215. ! !KickDv= Area_OpSectionFt(Op_Mud_Forehead_section%Array(Op_KickLoc)) * KickDx * 7.48051948 ! ft^3 to gal
  216. !
  217. !!farz mikonam baraye in yek iteration kick az OP hazf nemishavad va hajme aan bishtar az pump flow ast
  218. !
  219. ! KickDv= ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)
  220. !
  221. ! call Ann_Density%AddToFirst (Kick_Density)
  222. ! call Ann_MudDischarged_Volume%AddToFirst (KickDv)
  223. ! call Ann_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(F_Counts%StringIntervalCounts+1))
  224. ! call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
  225. ! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1))
  226. ! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  227. ! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  228. ! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  229. ! call Ann_MudOrKick%AddToFirst (KickNumber)
  230. ! call Ann_CuttingMud%AddToFirst (0)
  231. !
  232. ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv
  233. !
  234. ! !
  235. ! !if ( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad
  236. ! !
  237. ! ! KickDv= ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)
  238. !
  239. !
  240. !
  241. ! ! BackHead:
  242. ! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then
  243. !
  244. !
  245. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  246. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  247. !
  248. ! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last())
  249. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,KickDv)
  250. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  251. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  252. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  253. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  254. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  255. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  256. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  257. !
  258. !
  259. ! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  260. !
  261. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + KickDv
  262. !
  263. ! endif
  264. !
  265. !
  266. !
  267. !
  268. ! endif
  269. !========================================================================================
  270. !============================= tamame kick zire mate bashad *1 ================================
  271. if ( MudSystem%Op_KickLoc>0 .and. MudSystem%Op_KickLoc < MudSystem%Op_MudOrKick%Length () ) then
  272. !write(*,*) '****1'
  273. !iloc= 1
  274. MudSystem%KickDv= MudSystem%Area_OpSectionFt(MudSystem%Op_Mud_Forehead_section%Array(MudSystem%Op_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal
  275. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  276. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  277. if ( MudSystem%KickDv < MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1) ) then !eleman bala sari baghi mimund
  278. !write(*,*) 'cond 11111111111111'
  279. MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1) - MudSystem%KickDv
  280. MudSystem%NewDensity= MudSystem%Op_Density%Array (MudSystem%Op_KickLoc+1)
  281. MudSystem%NewVolume= MudSystem%KickDv
  282. else !KickDv > Op_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund
  283. ! write(*,*) 'cond 22222222222222222'
  284. MudSystem%KickDv= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc+1)
  285. MudSystem%NewVolume= MudSystem%KickDv
  286. MudSystem%NewDensity= MudSystem%Op_Density%Array (MudSystem%Op_KickLoc+1)
  287. call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc+1)
  288. call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc+1)
  289. call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc+1)
  290. call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc+1)
  291. call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc+1)
  292. call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc+1)
  293. call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc+1)
  294. call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc+1)
  295. call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc+1)
  296. endif
  297. ! backheade kick zire mate bashad
  298. if (MudSystem%Op_KickLoc > 1) then
  299. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  300. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  301. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  302. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  303. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  304. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  305. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  306. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  307. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  308. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  309. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  310. else !Op_Density%Array (Op_KickLoc-1) == MudSystem%NewDensity
  311. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  312. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  313. endif
  314. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-1===============================
  315. !write(*,*) '****5-1'
  316. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  317. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  318. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  319. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  320. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  321. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  322. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  323. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  324. call MudSystem%Op_MudOrKick%AddToFirst (0)
  325. endif
  326. endif
  327. !========================================================================================
  328. !write(*,*) 'a) density and cutting:' , Ann_Density%Length() , Ann_CuttingMud%Length()
  329. !=========================== tamame kick balaye mate bashad *2 ==================================
  330. if ( MudSystem%Ann_KickLoc > 0 .and. MudSystem%Op_KickLoc==0 ) then
  331. !write(*,*) '****2'
  332. !iloc= 1
  333. MudSystem%KickDv= MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%Ann_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal
  334. MudSystem%NewDensity= MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc+1)
  335. MudSystem%NewVolume= MudSystem%KickDv
  336. CuttingValue= MudSystem%Ann_CuttingMud%Array (MudSystem%Ann_KickLoc+1)
  337. if ( MudSystem%KickDv < MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) ) then !eleman bala sari baghi mimund
  338. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%KickDv
  339. else !KickDv > Ann_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund
  340. MudSystem%KickDv= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)
  341. MudSystem%NewVolume= MudSystem%KickDv
  342. call MudSystem%Ann_MudDischarged_Volume%Remove (MudSystem%Ann_KickLoc+1)
  343. call MudSystem%Ann_Mud_Backhead_X%Remove (MudSystem%Ann_KickLoc+1)
  344. call MudSystem%Ann_Mud_Backhead_section%Remove (MudSystem%Ann_KickLoc+1)
  345. call MudSystem%Ann_Mud_Forehead_X%Remove (MudSystem%Ann_KickLoc+1)
  346. call MudSystem%Ann_Mud_Forehead_section%Remove (MudSystem%Ann_KickLoc+1)
  347. call MudSystem%Ann_Density%Remove (MudSystem%Ann_KickLoc+1)
  348. call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (MudSystem%Ann_KickLoc+1)
  349. call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (MudSystem%Ann_KickLoc+1)
  350. call MudSystem%Ann_MudOrKick%Remove (MudSystem%Ann_KickLoc+1)
  351. call MudSystem%Ann_CuttingMud%Remove (MudSystem%Ann_KickLoc+1)
  352. endif
  353. ! backheade kick balaye mate bashad
  354. if (MudSystem%Ann_KickLoc > 1) then
  355. !if ( Ann_Density%Array (Ann_KickLoc-1) /= MudSystem%NewDensity ) then
  356. if ( ABS(MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  357. MudSystem%Old_KickBackHead_X= MudSystem%Ann_Mud_Backhead_X%Array (MudSystem%Ann_KickLoc)
  358. MudSystem%Old_KickBackHead_Section= MudSystem%Ann_Mud_Backhead_section%Array (MudSystem%Ann_KickLoc)
  359. call MudSystem%Ann_Density%AddTo (MudSystem%Ann_KickLoc,MudSystem%NewDensity)
  360. call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%Ann_KickLoc,MudSystem%NewVolume)
  361. call MudSystem%Ann_Mud_Forehead_X%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_X)
  362. call MudSystem%Ann_Mud_Forehead_section%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_Section)
  363. call MudSystem%Ann_Mud_Backhead_X%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_X)
  364. call MudSystem%Ann_Mud_Backhead_section%AddTo (MudSystem%Ann_KickLoc,MudSystem%Old_KickBackHead_Section)
  365. call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (MudSystem%Ann_KickLoc,0.0d0)
  366. call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Ann_KickLoc,0.0d0)
  367. call MudSystem%Ann_MudOrKick%AddTo (MudSystem%Ann_KickLoc,0)
  368. call MudSystem%Ann_CuttingMud%AddTo (MudSystem%Ann_KickLoc,0)
  369. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  370. MudSystem%Ann_Density%Array(MudSystem%Ann_KickLoc-1)= (MudSystem%Ann_Density%Array(MudSystem%Ann_KickLoc-1)*MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)+MudSystem%NewVolume)
  371. MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc-1) + MudSystem%NewVolume
  372. endif
  373. else !if Ann_KickLoc == 1 *6 ===============================
  374. !write(*,*) '****6'
  375. MudSystem%Old_KickBackHead_X= MudSystem%Ann_Mud_Backhead_X%Array (MudSystem%Ann_KickLoc)
  376. MudSystem%Old_KickBackHead_Section= MudSystem%Ann_Mud_Backhead_section%Array (MudSystem%Ann_KickLoc)
  377. call MudSystem%Ann_Density%AddToFirst (MudSystem%NewDensity)
  378. call MudSystem%Ann_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  379. call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  380. call MudSystem%Ann_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  381. call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  382. call MudSystem%Ann_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  383. call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  384. call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  385. call MudSystem%Ann_MudOrKick%AddToFirst (0)
  386. call MudSystem%Ann_CuttingMud%AddToFirst (CuttingValue)
  387. endif
  388. endif
  389. !========================================================================================
  390. !============================== kick 2 tarafe mate bashad *4 ==============================
  391. if ( MudSystem%Ann_KickLoc > 0 .and. MudSystem%Op_KickLoc > 0 ) then
  392. !write(*,*) '****4'
  393. MudSystem%iLoc= 2
  394. MudSystem%KickDv= MudSystem%Area_PipeSectionFt(MudSystem%Ann_Mud_Forehead_section%Array(MudSystem%Ann_KickLoc)) * MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal
  395. MudSystem%MinKickDv= min( MudSystem%KickDv,MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1), MudSystem%Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick
  396. MudSystem%NewDensity= MudSystem%Ann_Density%Array (MudSystem%Ann_KickLoc+1)
  397. MudSystem%NewVolume= MudSystem%MinKickDv
  398. if ( MudSystem%MinKickDv == MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund
  399. !write(*,*) '****4----1'
  400. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%MinKickDv
  401. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1
  402. MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv ! Op_KickLoc= last
  403. ! backheade kick zire mate bashad
  404. if ( MudSystem%Op_KickLoc>1) then
  405. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  406. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  407. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  408. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  409. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  410. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  411. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  412. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  413. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  414. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  415. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  416. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  417. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  418. else ! merge
  419. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  420. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  421. endif
  422. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  423. !write(*,*) '****5-2'
  424. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  425. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  426. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  427. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  428. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  429. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  430. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  431. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  432. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  433. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  434. call MudSystem%Op_MudOrKick%AddToFirst (0)
  435. endif
  436. elseif ( MudSystem%MinKickDv == MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund
  437. !write(*,*) '****4----2'
  438. call MudSystem%Ann_MudDischarged_Volume%Remove (MudSystem%Ann_KickLoc+1)
  439. call MudSystem%Ann_Mud_Backhead_X%Remove (MudSystem%Ann_KickLoc+1)
  440. call MudSystem%Ann_Mud_Backhead_section%Remove (MudSystem%Ann_KickLoc+1)
  441. call MudSystem%Ann_Mud_Forehead_X%Remove (MudSystem%Ann_KickLoc+1)
  442. call MudSystem%Ann_Mud_Forehead_section%Remove (MudSystem%Ann_KickLoc+1)
  443. call MudSystem%Ann_Density%Remove (MudSystem%Ann_KickLoc+1)
  444. call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (MudSystem%Ann_KickLoc+1)
  445. call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (MudSystem%Ann_KickLoc+1)
  446. call MudSystem%Ann_MudOrKick%Remove (MudSystem%Ann_KickLoc+1)
  447. call MudSystem%Ann_CuttingMud%Remove (MudSystem%Ann_KickLoc+1)
  448. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1
  449. MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array (MudSystem%Op_KickLoc) - MudSystem%MinKickDv ! Op_KickLoc= last
  450. ! backheade kick zire mate bashad
  451. if (MudSystem%Op_KickLoc > 1) then
  452. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  453. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  454. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  455. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  456. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  457. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  458. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  459. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  460. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  461. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  462. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  463. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  464. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  465. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  466. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  467. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  468. endif
  469. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  470. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  471. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  472. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  473. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  474. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  475. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  476. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  477. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  478. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  479. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  480. call MudSystem%Op_MudOrKick%AddToFirst (0)
  481. endif
  482. elseif ( MudSystem%MinKickDv == MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod
  483. !write(*,*) '****4----3'
  484. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc+1) - MudSystem%MinKickDv
  485. MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array (MudSystem%Ann_KickLoc) + MudSystem%MinKickDv ! Ann_KickLoc= 1
  486. MudSystem%Old_KickBackHead_X= MudSystem%Op_Mud_Backhead_X%Array (MudSystem%Op_KickLoc)
  487. MudSystem%Old_KickBackHead_Section= MudSystem%Op_Mud_Backhead_section%Array (MudSystem%Op_KickLoc)
  488. call MudSystem%Op_MudDischarged_Volume%Remove (MudSystem%Op_KickLoc) ! Op_KickLoc= last
  489. call MudSystem%Op_Mud_Backhead_X%Remove (MudSystem%Op_KickLoc)
  490. call MudSystem%Op_Mud_Backhead_section%Remove (MudSystem%Op_KickLoc)
  491. call MudSystem%Op_Mud_Forehead_X%Remove (MudSystem%Op_KickLoc)
  492. call MudSystem%Op_Mud_Forehead_section%Remove (MudSystem%Op_KickLoc)
  493. call MudSystem%Op_Density%Remove (MudSystem%Op_KickLoc)
  494. call MudSystem%Op_RemainedVolume_in_LastSection%Remove (MudSystem%Op_KickLoc)
  495. call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (MudSystem%Op_KickLoc)
  496. call MudSystem%Op_MudOrKick%Remove (MudSystem%Op_KickLoc)
  497. ! backheade kick zire mate bashad
  498. if (MudSystem%Op_KickLoc > 1) then
  499. !if ( Op_Density%Array (Op_KickLoc-1) /= MudSystem%NewDensity ) then
  500. if ( ABS(MudSystem%Op_Density%Array (MudSystem%Op_KickLoc-1) - MudSystem%NewDensity) >= MudSystem%DensityMixTol ) then
  501. call MudSystem%Op_Density%AddTo (MudSystem%Op_KickLoc,MudSystem%NewDensity)
  502. call MudSystem%Op_MudDischarged_Volume%AddTo (MudSystem%Op_KickLoc,MudSystem%NewVolume)
  503. call MudSystem%Op_Mud_Forehead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  504. call MudSystem%Op_Mud_Forehead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  505. call MudSystem%Op_Mud_Backhead_X%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_X)
  506. call MudSystem%Op_Mud_Backhead_section%AddTo (MudSystem%Op_KickLoc,MudSystem%Old_KickBackHead_Section)
  507. call MudSystem%Op_RemainedVolume_in_LastSection%AddTo (MudSystem%Op_KickLoc,0.0d0)
  508. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (MudSystem%Op_KickLoc,0.0d0)
  509. call MudSystem%Op_MudOrKick%AddTo (MudSystem%Op_KickLoc,0)
  510. else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  511. MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)= (MudSystem%Op_Density%Array(MudSystem%Op_KickLoc-1)*MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)+MudSystem%NewVolume)
  512. MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc-1) + MudSystem%NewVolume
  513. endif
  514. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  515. call MudSystem%Op_Density%AddToFirst (MudSystem%NewDensity)
  516. call MudSystem%Op_MudDischarged_Volume%AddToFirst (MudSystem%NewVolume)
  517. call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  518. call MudSystem%Op_Mud_Forehead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  519. call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Old_KickBackHead_X)
  520. call MudSystem%Op_Mud_Backhead_section%AddToFirst (MudSystem%Old_KickBackHead_Section)
  521. call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  522. call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  523. call MudSystem%Op_MudOrKick%AddToFirst (0)
  524. endif
  525. MudSystem%iLoc= 1 ! ok
  526. endif
  527. endif
  528. !========================================================================================
  529. !============================== kick 2 tarafe mate bashad *4 with pump ==============================
  530. !
  531. !if ( Ann_KickLoc > 0 .and. Op_KickLoc > 0 .and. MudSystem%AnnulusFlowRate /= 0.0 ) then
  532. ! write(*,*) '****4 with pump'
  533. !
  534. ! KickMigration_2SideBit= .true.
  535. !
  536. ! !iloc= 2
  537. !
  538. ! KickDv= Area_PipeSectionFt(Ann_Mud_Forehead_section%Array(Ann_KickLoc)) * KickDx * 7.48051948d0 ! ft^3 to gal
  539. ! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick
  540. !
  541. !
  542. ! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick
  543. ! !
  544. ! !MudSystem%NewDensity= Ann_Density%Array (Ann_KickLoc+1)
  545. ! !NewVolume= MinKickDv
  546. !
  547. !
  548. ! if ( ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad---tu in halat aslan kari be elemane balaiye kick tuye Ann nadarim
  549. ! !WRITE(*,*) '*****sorate pump bishtar az kick*******'
  550. ! MinKickDv= ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) ! dar asl maxKickDv ast
  551. !
  552. !
  553. !
  554. !
  555. !
  556. !
  557. !
  558. !
  559. ! if ( Op_MudDischarged_Volume%Last () > MinKickDv ) then !eleman paeeni(kick) dar OP baghi mimund
  560. !
  561. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1
  562. !
  563. ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last
  564. !
  565. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  566. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  567. ! ! backheade kick zire mate bashad
  568. ! if ( Op_KickLoc>1) then
  569. !
  570. ! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then
  571. !
  572. !
  573. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  574. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  575. !
  576. ! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last())
  577. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv)
  578. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  579. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  580. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  581. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  582. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  583. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  584. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  585. !
  586. !
  587. ! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  588. !
  589. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume
  590. !
  591. ! endif
  592. !
  593. ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  594. ! write(*,*) '****5-2 with pump'
  595. !
  596. !
  597. ! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  598. ! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  599. !
  600. !
  601. ! call Op_Density%AddToFirst MudSystem%St_Density%Last())
  602. ! call Op_MudDischarged_Volume%AddToFirst (MinKickDv)
  603. ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X)
  604. ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section)
  605. ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X)
  606. ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section)
  607. ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  608. ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  609. ! call Op_MudOrKick%AddToFirst (0)
  610. !
  611. ! endif
  612. !
  613. ! elseif ( Op_MudDischarged_Volume%Last () <= MinKickDv ) then !eleman paeeni(kick) dar OP baghi nemimund yani kick az OP kamel kharej mishod
  614. !
  615. ! MinKickDv= Op_MudDischarged_Volume%Last ()
  616. !
  617. !
  618. ! write(*,*) '****4----3 with pump a'
  619. !
  620. !
  621. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) + ((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)-MinKickDv
  622. !
  623. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1
  624. !
  625. ! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last
  626. ! call Op_Mud_Backhead_X%Remove (Op_KickLoc)
  627. ! call Op_Mud_Backhead_section%Remove (Op_KickLoc)
  628. ! call Op_Mud_Forehead_X%Remove (Op_KickLoc)
  629. ! call Op_Mud_Forehead_section%Remove (Op_KickLoc)
  630. ! call Op_Density%Remove (Op_KickLoc)
  631. ! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc)
  632. ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc)
  633. ! call Op_MudOrKick%Remove (Op_KickLoc)
  634. !
  635. !
  636. ! ! backheade kick zire mate bashad
  637. ! if (Op_KickLoc > 1) then
  638. !
  639. ! if ( Op_Density%Array (Op_KickLoc-1) /=MudSystem%St_Density%Last() ) then
  640. !
  641. !
  642. ! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  643. ! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  644. !
  645. ! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last())
  646. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv)
  647. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  648. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  649. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  650. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  651. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  652. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  653. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  654. !
  655. !
  656. !
  657. ! else !Op_Density%Array (imudKick-1) == MudSystem%NewDensity
  658. !
  659. !
  660. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + MinKickDv
  661. !
  662. ! endif
  663. !
  664. ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  665. !
  666. !
  667. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  668. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  669. !
  670. !
  671. ! call Op_Density%AddToFirst MudSystem%St_Density%Last())
  672. ! call Op_MudDischarged_Volume%AddToFirst (MinKickDv)
  673. ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X)
  674. ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section)
  675. ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X)
  676. ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section)
  677. ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  678. ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  679. ! call Op_MudOrKick%AddToFirst (0)
  680. !
  681. ! endif
  682. !
  683. !
  684. ! endif ! ende 2 halat ke kick tuye Op baghi bemune ya namune- dar halati ke ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) ! sorate pump bishtar az kick bashad
  685. !
  686. !
  687. !
  688. !
  689. ! else !if( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) then ! sorate pump kamtar az kick bashad
  690. ! !WRITE(*,*) '*****sorate pump kamtar az kick*******'
  691. !
  692. !
  693. !
  694. !
  695. ! MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick
  696. !
  697. !
  698. !
  699. ! !write(*,*) 'MinKickDv=' , MinKickDv
  700. !
  701. !
  702. ! if ( MinKickDv == KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund
  703. ! !write(*,*) '****4----1 with pump'
  704. ! !write(*,*) MudSystem%St_Density%Last()=' ,MudSystem%St_Density%Last()
  705. ! !write(*,*) '((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)=' , ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)
  706. ! !write(*,*) 'Ann_Density%Array(Ann_KickLoc+1)=' , Ann_Density%Array(Ann_KickLoc+1)
  707. ! !write(*,*) '(MinKickDv-((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline))=' , (MinKickDv-((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline))
  708. !
  709. !
  710. ! MudSystem%NewDensity= MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) &
  711. ! / (((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + (MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)))
  712. ! NewVolume= MinKickDv
  713. !
  714. !
  715. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - (MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))
  716. !
  717. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1
  718. !
  719. ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last
  720. !
  721. !
  722. ! ! backheade kick zire mate bashad
  723. ! if ( Op_KickLoc>1) then
  724. !
  725. !
  726. !
  727. ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then
  728. !
  729. !
  730. !
  731. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  732. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  733. !
  734. ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity)
  735. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume)
  736. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  737. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  738. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  739. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  740. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  741. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  742. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  743. !
  744. !
  745. ! else !Merge Condition
  746. !
  747. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume
  748. ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / &
  749. ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume)
  750. !
  751. !
  752. ! endif
  753. !
  754. ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  755. ! write(*,*) '****5-2 with pump'
  756. !
  757. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  758. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  759. !
  760. !
  761. ! call Op_Density%AddToFirst (MudSystem%NewDensity)
  762. ! call Op_MudDischarged_Volume%AddToFirst (NewVolume)
  763. ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X)
  764. ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section)
  765. ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X)
  766. ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section)
  767. ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  768. ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  769. ! call Op_MudOrKick%AddToFirst (0)
  770. !
  771. ! endif
  772. !
  773. !
  774. !
  775. ! elseif ( MinKickDv == Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund
  776. ! write(*,*) '****4----2 with pump'
  777. !
  778. ! MudSystem%NewDensity= MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) &
  779. ! / (((MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_MudDischarged_Volume%Array (Ann_KickLoc+1))
  780. ! NewVolume= MinKickDv
  781. !
  782. ! call RemoveAnnulusMudArrays(Ann_KickLoc+1)
  783. !
  784. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1
  785. !
  786. ! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last
  787. !
  788. ! ! backheade kick zire mate bashad
  789. ! if (Op_KickLoc > 1) then
  790. !
  791. ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then
  792. !
  793. ! !
  794. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  795. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  796. !
  797. ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity)
  798. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume)
  799. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  800. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  801. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  802. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  803. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  804. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  805. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  806. !
  807. !
  808. ! else !Merge Condition
  809. !
  810. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume
  811. ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / &
  812. ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume)
  813. !
  814. !
  815. !
  816. ! endif
  817. !
  818. ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  819. !
  820. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  821. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  822. !
  823. !
  824. ! call Op_Density%AddToFirst (MudSystem%NewDensity)
  825. ! call Op_MudDischarged_Volume%AddToFirst (NewVolume)
  826. ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X)
  827. ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section)
  828. ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X)
  829. ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section)
  830. ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  831. ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  832. ! call Op_MudOrKick%AddToFirst (0)
  833. !
  834. ! endif
  835. !
  836. !
  837. ! elseif ( MinKickDv == Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod
  838. ! write(*,*) '****4----3 with pump b'
  839. !
  840. ! MudSystem%NewDensity=MudSystem%St_Density%Last()
  841. ! NewVolume= MinKickDv
  842. !
  843. !
  844. ! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc)
  845. ! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc)
  846. !
  847. !
  848. ! !Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - MinKickDv farz kardam dast be elemane balaee nazanam
  849. !
  850. ! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1
  851. ! !write(*,*) 'pointer 1'
  852. ! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last
  853. ! call Op_Mud_Backhead_X%Remove (Op_KickLoc)
  854. ! call Op_Mud_Backhead_section%Remove (Op_KickLoc)
  855. ! call Op_Mud_Forehead_X%Remove (Op_KickLoc)
  856. ! call Op_Mud_Forehead_section%Remove (Op_KickLoc)
  857. ! call Op_Density%Remove (Op_KickLoc)
  858. ! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc)
  859. ! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc)
  860. ! call Op_MudOrKick%Remove (Op_KickLoc)
  861. !
  862. ! !write(*,*) 'pointer 2'
  863. !
  864. ! ! backheade kick zire mate bashad
  865. ! if (Op_KickLoc > 1) then
  866. !
  867. ! if ( ABS(Op_Density%Array (Op_KickLoc-1) - MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then
  868. ! !write(*,*) 'pointer 3'
  869. !
  870. !
  871. !
  872. !
  873. ! call Op_Density%AddTo (Op_KickLoc,MudSystem%NewDensity)
  874. ! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume)
  875. ! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  876. ! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  877. ! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X)
  878. ! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section)
  879. ! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0)
  880. ! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0)
  881. ! call Op_MudOrKick%AddTo (Op_KickLoc,0)
  882. !
  883. ! !write(*,*) 'pointer 4'
  884. !
  885. ! else !Merge Condition
  886. !
  887. ! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume
  888. ! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*MudSystem%NewDensity) / &
  889. ! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume)
  890. !
  891. ! endif
  892. !
  893. ! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  894. ! !write(*,*) 'pointer 5'
  895. !
  896. !
  897. ! !write(*,*) 'pointer 6'
  898. !
  899. !
  900. ! call Op_Density%AddToFirst (MudSystem%NewDensity)
  901. ! call Op_MudDischarged_Volume%AddToFirst (NewVolume)
  902. ! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X)
  903. ! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section)
  904. ! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X)
  905. ! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section)
  906. ! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  907. ! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  908. ! call Op_MudOrKick%AddToFirst (0)
  909. ! !write(*,*) 'pointer 7'
  910. !
  911. ! endif
  912. !
  913. !
  914. ! endif
  915. !
  916. !
  917. !
  918. ! endif !( ((MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) ! sorate pump kamtar az kick bashad
  919. !
  920. !
  921. !
  922. !
  923. ! endif
  924. !========================================================================================
  925. ENDDO ! KickNumber= 1, NewInfluxNumber
  926. MudSystem%KickNumber = kickNumber
  927. !write(*,*) 'c)Ann_MudDischarged_Volume%Array(:)=' , sum(Ann_MudDischarged_Volume%Array(:))
  928. end subroutine Kick_Migration