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.
 
 
 
 
 
 

1181 lines
72 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
  14. integer jopelement,jopmud,jopsection,CuttingValue
  15. !MUD(2)%Q= MPumps%Total_Pump_GPM
  16. !StringFlowRate= MUD(2)%Q
  17. !AnnulusFlowRate= MUD(2)%Q
  18. !
  19. !if (NewPipeFilling == 0) then
  20. ! StringFlowRate= 0.
  21. ! AnnulusFlowRate= 0.
  22. !endif
  23. !StringFlowRateFinal= StringFlowRate
  24. !AnnulusFlowRateFinal= AnnulusFlowRate
  25. !write(*,*) 'MUD(2)%Q=====' , MUD(2)%Q
  26. !write(*,*) 'Kick Migration,NewInfluxNumber:' , NewInfluxNumber
  27. !FirstSetKickMigration
  28. !write(*,*) 'NewInfluxNumber=' , NewInfluxNumber
  29. DO MudSystemDotKickNumber= MudSystemDotNewInfluxNumber-NoGasPocket+1 , MudSystemDotNewInfluxNumber
  30. !write(*,*) 'KickNumber=' , KickNumber
  31. if (KickFlux .AND. NOT(KickOffBottom) .and. MudSystemDotKickNumber == MudSystemDotNewInfluxNumber) cycle
  32. if ( MudSystemDotKickNumber == 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. MudSystemDotOp_KickLoc= 0
  37. MudSystemDotAnn_KickLoc= 0
  38. MudSystemDotChokeLine_KickLoc= 0
  39. do i = 1, Op_MudOrKick%Length ()
  40. if (Op_MudOrKick%Array(i) == MudSystemDotKickNumber) then
  41. MudSystemDotOp_KickLoc = i
  42. exit
  43. endif
  44. end do
  45. do i = 1, Ann_MudOrKick%Length ()
  46. if (Ann_MudOrKick%Array(i) == MudSystemDotKickNumber) then
  47. MudSystemDotAnn_KickLoc = i
  48. exit
  49. endif
  50. end do
  51. do i = 1, ChokeLine_MudOrKick%Length ()
  52. if (ChokeLine_MudOrKick%Array(i) == MudSystemDotKickNumber) then
  53. MudSystemDotChokeLine_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 (MudSystemDotOp_KickLoc == Op_MudOrKick%Length () .and. MudSystemDotAnn_KickLoc==0 ) then
  67. !write(*,*) '****3'
  68. MudSystemDotiLoc= 2
  69. MudSystemDotKickDv= MudSystemDotArea_OpSectionFt(Op_Mud_Forehead_section%Array(MudSystemDotOp_KickLoc)) * MudSystemDotKickDx * 7.48051948d0 ! ft^3 to gal
  70. MudSystemDotMinKickDv= min( MudSystemDotKickDv,MudSystemDotAnn_MudDischarged_Volume%Array (1), MudSystemDotOp_MudDischarged_Volume%Last () )
  71. NewDensity= Ann_Density%Array (1)
  72. MudSystemDotNewVolume= MudSystemDotMinKickDv
  73. if ( MudSystemDotMinKickDv == MudSystemDotKickDv ) then !eleman bala sari baghi mimund, paeeni(kick) ham baghi mimund
  74. MudSystemDotAnn_MudDischarged_Volume%Array (1)= MudSystemDotAnn_MudDischarged_Volume%Array (1) - MudSystemDotMinKickDv
  75. call Ann_Density%AddToFirst (MudSystemDotOp_Density%Last())
  76. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotMinKickDv)
  77. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  78. call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
  79. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  80. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  81. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  82. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  83. call Ann_MudOrKick%AddToFirst (MudSystemDotKickNumber)
  84. call Ann_CuttingMud%AddToFirst (0)
  85. MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc) - MudSystemDotMinKickDv
  86. ! backheade kick zire mate bashad
  87. if (MudSystemDotOp_KickLoc > 1) then
  88. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  89. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  90. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  91. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  92. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  93. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  94. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  95. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  96. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  97. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  98. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  99. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  100. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  101. else !Op_Density%Array (imudKick-1) == NewDensity
  102. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  103. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  104. endif
  105. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-1===============================
  106. !write(*,*) '****3-1'
  107. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  108. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  109. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  110. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  111. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  112. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  113. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  114. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  115. call Op_MudOrKick%AddToFirst (0)
  116. endif
  117. elseif ( MudSystemDotMinKickDv == MudSystemDotAnn_MudDischarged_Volume%Array (1) ) then ! eleman bala sari baghi nemimund
  118. Ann_Density%Array(1)= MudSystemDotOp_Density%Last()
  119. Ann_MudOrKick%Array(1)= MudSystemDotKickNumber
  120. MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc) - MudSystemDotMinKickDv
  121. ! backheade kick zire mate bashad
  122. if (MudSystemDotOp_KickLoc > 1) then
  123. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  124. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  125. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  126. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  127. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  128. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  129. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  130. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  131. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  132. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  133. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  134. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  135. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  136. else !Op_Density%Array (imudKick-1) == NewDensity
  137. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  138. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  139. endif
  140. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-2===============================
  141. !write(*,*) '****3-2'
  142. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  143. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  144. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  145. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  146. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  147. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  148. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  149. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  150. call Op_MudOrKick%AddToFirst (0)
  151. endif
  152. !
  153. elseif ( MudSystemDotMinKickDv == MudSystemDotOp_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick hazf mishod
  154. MudSystemDotAnn_MudDischarged_Volume%Array (1)= MudSystemDotAnn_MudDischarged_Volume%Array (1) - MudSystemDotMinKickDv
  155. call Ann_Density%AddToFirst (MudSystemDotOp_Density%Last())
  156. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotMinKickDv)
  157. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  158. call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
  159. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
  160. call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
  161. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  162. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  163. call Ann_MudOrKick%AddToFirst (MudSystemDotKickNumber)
  164. call Ann_CuttingMud%AddToFirst (0)
  165. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  166. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  167. call MudSystemDotOp_MudDischarged_Volume%Remove (MudSystemDotOp_KickLoc)
  168. call MudSystemDotOp_Mud_Backhead_X%Remove (MudSystemDotOp_KickLoc)
  169. call Op_Mud_Backhead_section%Remove (MudSystemDotOp_KickLoc)
  170. call MudSystemDotOp_Mud_Forehead_X%Remove (MudSystemDotOp_KickLoc)
  171. call Op_Mud_Forehead_section%Remove (MudSystemDotOp_KickLoc)
  172. call MudSystemDotOp_Density%Remove (MudSystemDotOp_KickLoc)
  173. call MudSystemDotOp_RemainedVolume_in_LastSection%Remove (MudSystemDotOp_KickLoc)
  174. call MudSystemDotOp_EmptyVolume_inBackheadLocation%Remove (MudSystemDotOp_KickLoc)
  175. call Op_MudOrKick%Remove (MudSystemDotOp_KickLoc)
  176. ! backheade kick zire mate bashad
  177. if (MudSystemDotOp_KickLoc > 1) then
  178. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  179. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  180. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  181. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  182. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  183. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  184. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  185. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  186. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  187. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  188. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  189. else !Op_Density%Array (imudKick-1) == NewDensity
  190. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  191. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  192. endif
  193. else !if Op_KickLoc == 1 (*****Migration Start*****) *3-3===============================
  194. !write(*,*) '****3-3'
  195. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  196. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  197. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  198. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  199. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  200. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  201. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  202. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  203. call 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. 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= ((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_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 ( ((AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad
  236. ! !
  237. ! ! KickDv= ((AnnulusFlowRate/60.)*DeltaT_Mudline)
  238. !
  239. !
  240. !
  241. ! ! BackHead:
  242. ! if ( Op_Density%Array (Op_KickLoc-1) /= 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_KickLoc,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) == 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 ( MudSystemDotOp_KickLoc>0 .and. MudSystemDotOp_KickLoc < Op_MudOrKick%Length () ) then
  272. !write(*,*) '****1'
  273. !iloc= 1
  274. MudSystemDotKickDv= MudSystemDotArea_OpSectionFt(Op_Mud_Forehead_section%Array(MudSystemDotOp_KickLoc)) * MudSystemDotKickDx * 7.48051948d0 ! ft^3 to gal
  275. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  276. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  277. if ( MudSystemDotKickDv < MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc+1) ) then !eleman bala sari baghi mimund
  278. !write(*,*) 'cond 11111111111111'
  279. MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc+1)= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc+1) - MudSystemDotKickDv
  280. NewDensity= MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc+1)
  281. MudSystemDotNewVolume= MudSystemDotKickDv
  282. else !KickDv > Op_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund
  283. ! write(*,*) 'cond 22222222222222222'
  284. MudSystemDotKickDv= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc+1)
  285. MudSystemDotNewVolume= MudSystemDotKickDv
  286. NewDensity= MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc+1)
  287. call MudSystemDotOp_MudDischarged_Volume%Remove (MudSystemDotOp_KickLoc+1)
  288. call MudSystemDotOp_Mud_Backhead_X%Remove (MudSystemDotOp_KickLoc+1)
  289. call Op_Mud_Backhead_section%Remove (MudSystemDotOp_KickLoc+1)
  290. call MudSystemDotOp_Mud_Forehead_X%Remove (MudSystemDotOp_KickLoc+1)
  291. call Op_Mud_Forehead_section%Remove (MudSystemDotOp_KickLoc+1)
  292. call MudSystemDotOp_Density%Remove (MudSystemDotOp_KickLoc+1)
  293. call MudSystemDotOp_RemainedVolume_in_LastSection%Remove (MudSystemDotOp_KickLoc+1)
  294. call MudSystemDotOp_EmptyVolume_inBackheadLocation%Remove (MudSystemDotOp_KickLoc+1)
  295. call Op_MudOrKick%Remove (MudSystemDotOp_KickLoc+1)
  296. endif
  297. ! backheade kick zire mate bashad
  298. if (MudSystemDotOp_KickLoc > 1) then
  299. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  300. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  301. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  302. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  303. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  304. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  305. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  306. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  307. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  308. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  309. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  310. else !Op_Density%Array (Op_KickLoc-1) == NewDensity
  311. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  312. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  313. endif
  314. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-1===============================
  315. !write(*,*) '****5-1'
  316. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  317. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  318. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  319. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  320. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  321. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  322. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  323. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  324. call 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 ( MudSystemDotAnn_KickLoc > 0 .and. MudSystemDotOp_KickLoc==0 ) then
  331. !write(*,*) '****2'
  332. !iloc= 1
  333. MudSystemDotKickDv= MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotAnn_KickLoc)) * MudSystemDotKickDx * 7.48051948d0 ! ft^3 to gal
  334. NewDensity= Ann_Density%Array (MudSystemDotAnn_KickLoc+1)
  335. MudSystemDotNewVolume= MudSystemDotKickDv
  336. CuttingValue= Ann_CuttingMud%Array (MudSystemDotAnn_KickLoc+1)
  337. if ( MudSystemDotKickDv < MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1) ) then !eleman bala sari baghi mimund
  338. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1) - MudSystemDotKickDv
  339. else !KickDv > Ann_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund
  340. MudSystemDotKickDv= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1)
  341. MudSystemDotNewVolume= MudSystemDotKickDv
  342. call MudSystemDotAnn_MudDischarged_Volume%Remove (MudSystemDotAnn_KickLoc+1)
  343. call Ann_Mud_Backhead_X%Remove (MudSystemDotAnn_KickLoc+1)
  344. call Ann_Mud_Backhead_section%Remove (MudSystemDotAnn_KickLoc+1)
  345. call Ann_Mud_Forehead_X%Remove (MudSystemDotAnn_KickLoc+1)
  346. call Ann_Mud_Forehead_section%Remove (MudSystemDotAnn_KickLoc+1)
  347. call Ann_Density%Remove (MudSystemDotAnn_KickLoc+1)
  348. call Ann_RemainedVolume_in_LastSection%Remove (MudSystemDotAnn_KickLoc+1)
  349. call Ann_EmptyVolume_inBackheadLocation%Remove (MudSystemDotAnn_KickLoc+1)
  350. call Ann_MudOrKick%Remove (MudSystemDotAnn_KickLoc+1)
  351. call Ann_CuttingMud%Remove (MudSystemDotAnn_KickLoc+1)
  352. endif
  353. ! backheade kick balaye mate bashad
  354. if (MudSystemDotAnn_KickLoc > 1) then
  355. !if ( Ann_Density%Array (Ann_KickLoc-1) /= NewDensity ) then
  356. if ( ABS(Ann_Density%Array (MudSystemDotAnn_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  357. MudSystemDotOld_KickBackHead_X= Ann_Mud_Backhead_X%Array (MudSystemDotAnn_KickLoc)
  358. MudSystemDotOld_KickBackHead_Section= Ann_Mud_Backhead_section%Array (MudSystemDotAnn_KickLoc)
  359. call Ann_Density%AddTo (MudSystemDotAnn_KickLoc,NewDensity)
  360. call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotAnn_KickLoc,MudSystemDotNewVolume)
  361. call Ann_Mud_Forehead_X%AddTo (MudSystemDotAnn_KickLoc,MudSystemDotOld_KickBackHead_X)
  362. call Ann_Mud_Forehead_section%AddTo (MudSystemDotAnn_KickLoc,MudSystemDotOld_KickBackHead_Section)
  363. call Ann_Mud_Backhead_X%AddTo (MudSystemDotAnn_KickLoc,MudSystemDotOld_KickBackHead_X)
  364. call Ann_Mud_Backhead_section%AddTo (MudSystemDotAnn_KickLoc,MudSystemDotOld_KickBackHead_Section)
  365. call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotAnn_KickLoc,0.0d0)
  366. call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotAnn_KickLoc,0.0d0)
  367. call Ann_MudOrKick%AddTo (MudSystemDotAnn_KickLoc,0)
  368. call Ann_CuttingMud%AddTo (MudSystemDotAnn_KickLoc,0)
  369. else !Op_Density%Array (imudKick-1) == NewDensity
  370. Ann_Density%Array(MudSystemDotAnn_KickLoc-1)= (Ann_Density%Array(MudSystemDotAnn_KickLoc-1)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc-1)+MudSystemDotNewVolume)
  371. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc-1)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc-1) + MudSystemDotNewVolume
  372. endif
  373. else !if Ann_KickLoc == 1 *6 ===============================
  374. !write(*,*) '****6'
  375. MudSystemDotOld_KickBackHead_X= Ann_Mud_Backhead_X%Array (MudSystemDotAnn_KickLoc)
  376. MudSystemDotOld_KickBackHead_Section= Ann_Mud_Backhead_section%Array (MudSystemDotAnn_KickLoc)
  377. call Ann_Density%AddToFirst (NewDensity)
  378. call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  379. call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  380. call Ann_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  381. call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  382. call Ann_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  383. call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  384. call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  385. call Ann_MudOrKick%AddToFirst (0)
  386. call Ann_CuttingMud%AddToFirst (CuttingValue)
  387. endif
  388. endif
  389. !========================================================================================
  390. !============================== kick 2 tarafe mate bashad *4 ==============================
  391. if ( MudSystemDotAnn_KickLoc > 0 .and. MudSystemDotOp_KickLoc > 0 ) then
  392. !write(*,*) '****4'
  393. MudSystemDotiLoc= 2
  394. MudSystemDotKickDv= MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotAnn_KickLoc)) * MudSystemDotKickDx * 7.48051948d0 ! ft^3 to gal
  395. MudSystemDotMinKickDv= min( MudSystemDotKickDv,MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1), MudSystemDotOp_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick
  396. NewDensity= Ann_Density%Array (MudSystemDotAnn_KickLoc+1)
  397. MudSystemDotNewVolume= MudSystemDotMinKickDv
  398. if ( MudSystemDotMinKickDv == MudSystemDotKickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund
  399. !write(*,*) '****4----1'
  400. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1) - MudSystemDotMinKickDv
  401. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc) + MudSystemDotMinKickDv ! Ann_KickLoc= 1
  402. MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc) - MudSystemDotMinKickDv ! Op_KickLoc= last
  403. ! backheade kick zire mate bashad
  404. if ( MudSystemDotOp_KickLoc>1) then
  405. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  406. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  407. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  408. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  409. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  410. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  411. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  412. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  413. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  414. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  415. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  416. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  417. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  418. else ! merge
  419. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  420. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  421. endif
  422. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  423. !write(*,*) '****5-2'
  424. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  425. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  426. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  427. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  428. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  429. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  430. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  431. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  432. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  433. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  434. call Op_MudOrKick%AddToFirst (0)
  435. endif
  436. elseif ( MudSystemDotMinKickDv == MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1) ) then ! eleman bala sari baghi nemimund
  437. !write(*,*) '****4----2'
  438. call MudSystemDotAnn_MudDischarged_Volume%Remove (MudSystemDotAnn_KickLoc+1)
  439. call Ann_Mud_Backhead_X%Remove (MudSystemDotAnn_KickLoc+1)
  440. call Ann_Mud_Backhead_section%Remove (MudSystemDotAnn_KickLoc+1)
  441. call Ann_Mud_Forehead_X%Remove (MudSystemDotAnn_KickLoc+1)
  442. call Ann_Mud_Forehead_section%Remove (MudSystemDotAnn_KickLoc+1)
  443. call Ann_Density%Remove (MudSystemDotAnn_KickLoc+1)
  444. call Ann_RemainedVolume_in_LastSection%Remove (MudSystemDotAnn_KickLoc+1)
  445. call Ann_EmptyVolume_inBackheadLocation%Remove (MudSystemDotAnn_KickLoc+1)
  446. call Ann_MudOrKick%Remove (MudSystemDotAnn_KickLoc+1)
  447. call Ann_CuttingMud%Remove (MudSystemDotAnn_KickLoc+1)
  448. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc) + MudSystemDotMinKickDv ! Ann_KickLoc= 1
  449. MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_KickLoc) - MudSystemDotMinKickDv ! Op_KickLoc= last
  450. ! backheade kick zire mate bashad
  451. if (MudSystemDotOp_KickLoc > 1) then
  452. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  453. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  454. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  455. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  456. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  457. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  458. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  459. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  460. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  461. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  462. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  463. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  464. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  465. else !Op_Density%Array (imudKick-1) == NewDensity
  466. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  467. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  468. endif
  469. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  470. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  471. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  472. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  473. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  474. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  475. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  476. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  477. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  478. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  479. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  480. call Op_MudOrKick%AddToFirst (0)
  481. endif
  482. elseif ( MudSystemDotMinKickDv == MudSystemDotOp_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod
  483. !write(*,*) '****4----3'
  484. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc+1) - MudSystemDotMinKickDv
  485. MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc)= MudSystemDotAnn_MudDischarged_Volume%Array (MudSystemDotAnn_KickLoc) + MudSystemDotMinKickDv ! Ann_KickLoc= 1
  486. MudSystemDotOld_KickBackHead_X= MudSystemDotOp_Mud_Backhead_X%Array (MudSystemDotOp_KickLoc)
  487. MudSystemDotOld_KickBackHead_Section= Op_Mud_Backhead_section%Array (MudSystemDotOp_KickLoc)
  488. call MudSystemDotOp_MudDischarged_Volume%Remove (MudSystemDotOp_KickLoc) ! Op_KickLoc= last
  489. call MudSystemDotOp_Mud_Backhead_X%Remove (MudSystemDotOp_KickLoc)
  490. call Op_Mud_Backhead_section%Remove (MudSystemDotOp_KickLoc)
  491. call MudSystemDotOp_Mud_Forehead_X%Remove (MudSystemDotOp_KickLoc)
  492. call Op_Mud_Forehead_section%Remove (MudSystemDotOp_KickLoc)
  493. call MudSystemDotOp_Density%Remove (MudSystemDotOp_KickLoc)
  494. call MudSystemDotOp_RemainedVolume_in_LastSection%Remove (MudSystemDotOp_KickLoc)
  495. call MudSystemDotOp_EmptyVolume_inBackheadLocation%Remove (MudSystemDotOp_KickLoc)
  496. call Op_MudOrKick%Remove (MudSystemDotOp_KickLoc)
  497. ! backheade kick zire mate bashad
  498. if (MudSystemDotOp_KickLoc > 1) then
  499. !if ( Op_Density%Array (Op_KickLoc-1) /= NewDensity ) then
  500. if ( ABS(MudSystemDotOp_Density%Array (MudSystemDotOp_KickLoc-1) - NewDensity) >= MudSystemDotDensityMixTol ) then
  501. call MudSystemDotOp_Density%AddTo (MudSystemDotOp_KickLoc,NewDensity)
  502. call MudSystemDotOp_MudDischarged_Volume%AddTo (MudSystemDotOp_KickLoc,MudSystemDotNewVolume)
  503. call MudSystemDotOp_Mud_Forehead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  504. call Op_Mud_Forehead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  505. call MudSystemDotOp_Mud_Backhead_X%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_X)
  506. call Op_Mud_Backhead_section%AddTo (MudSystemDotOp_KickLoc,MudSystemDotOld_KickBackHead_Section)
  507. call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  508. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotOp_KickLoc,0.0d0)
  509. call Op_MudOrKick%AddTo (MudSystemDotOp_KickLoc,0)
  510. else !Op_Density%Array (imudKick-1) == NewDensity
  511. MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)= (MudSystemDotOp_Density%Array(MudSystemDotOp_KickLoc-1)*MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)+MudSystemDotNewVolume)
  512. MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc-1) + MudSystemDotNewVolume
  513. endif
  514. else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2===============================
  515. call MudSystemDotOp_Density%AddToFirst (NewDensity)
  516. call MudSystemDotOp_MudDischarged_Volume%AddToFirst (MudSystemDotNewVolume)
  517. call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  518. call Op_Mud_Forehead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  519. call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotOld_KickBackHead_X)
  520. call Op_Mud_Backhead_section%AddToFirst (MudSystemDotOld_KickBackHead_Section)
  521. call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  522. call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  523. call Op_MudOrKick%AddToFirst (0)
  524. endif
  525. MudSystemDotiLoc= 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. 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. ! !NewDensity= Ann_Density%Array (Ann_KickLoc+1)
  545. ! !NewVolume= MinKickDv
  546. !
  547. !
  548. ! if ( ((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= ((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) /= 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_KickLoc,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) == 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 (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) + ((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) /= 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_KickLoc,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) == 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 (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 ((AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) ! sorate pump bishtar az kick bashad
  685. !
  686. !
  687. !
  688. !
  689. ! else !if( ((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(*,*) 'St_Density%Last()=' , St_Density%Last()
  705. ! !write(*,*) '((AnnulusFlowRate/60.)*DeltaT_Mudline)=' , ((AnnulusFlowRate/60.)*DeltaT_Mudline)
  706. ! !write(*,*) 'Ann_Density%Array(Ann_KickLoc+1)=' , Ann_Density%Array(Ann_KickLoc+1)
  707. ! !write(*,*) '(MinKickDv-((AnnulusFlowRate/60.)*DeltaT_Mudline))=' , (MinKickDv-((AnnulusFlowRate/60.)*DeltaT_Mudline))
  708. !
  709. !
  710. ! NewDensity= (St_Density%Last()*((AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) &
  711. ! / (((AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + (MinKickDv-((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-((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) - 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,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*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 (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. ! NewDensity= (St_Density%Last()*((AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) &
  779. ! / (((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) - 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,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*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 (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. ! NewDensity= 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) - 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,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*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 (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 !( ((AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) ! sorate pump kamtar az kick bashad
  919. !
  920. !
  921. !
  922. !
  923. ! endif
  924. !========================================================================================
  925. ENDDO ! KickNumber= 1, NewInfluxNumber
  926. !write(*,*) 'c)Ann_MudDischarged_Volume%Array(:)=' , sum(Ann_MudDischarged_Volume%Array(:))
  927. end subroutine Kick_Migration