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.

Kick_Migration.f90 73 KiB

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