Simulation Core
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

1178 righe
83 KiB

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