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.
 
 
 
 
 
 

1180 lines
80 KiB

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