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 64 KiB

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