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.

Pump_and_Trip_In.f90 105 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
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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  1. subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect
  2. Use GeoElements_FluidModule
  3. USE CMudPropertiesVariables
  4. USE MudSystemVARIABLES
  5. use SimulationVariables !@@@
  6. use SimulationVariables
  7. USE CHOKEVARIABLES
  8. !use ConfigurationVariables !@
  9. !use CDataDisplayConsole
  10. !@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure
  11. !use CManifolds
  12. use SimulationVariables !@
  13. USE CHOKEVARIABLES
  14. !use ConfigurationVariables !@
  15. !use CChokeManifoldVariables
  16. use SimulationVariables
  17. !use CTanks
  18. !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  19. USE sROP_Other_Variables
  20. USE sROP_Variables
  21. use KickVARIABLESModule
  22. Use CShoeVariables
  23. use CError
  24. implicit none
  25. integer i,ii,AddLocation
  26. !===========================================================WELL============================================================
  27. !===========================================================WELL============================================================
  28. data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q
  29. data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q
  30. !write(*,*) 'Trip In'
  31. !========================Horizontal PIPE ENTRANCE=================
  32. if (ABS(data%State%MudSystem%SuctionDensity_Old - data%State%MudSystem%Suction_Density_MudSystem) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped
  33. call data%State%MudSystem%Hz_Density%AddToFirst (data%State%MudSystem%Suction_Density_MudSystem)
  34. call data%State%MudSystem%Hz_MudDischarged_Volume%AddToFirst (0.0d0)
  35. call data%State%MudSystem%Hz_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1))
  36. call data%State%MudSystem%Hz_Mud_Forehead_section%AddToFirst (1)
  37. call data%State%MudSystem%Hz_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1))
  38. call data%State%MudSystem%Hz_Mud_Backhead_section%AddToFirst (1)
  39. call data%State%MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  40. call data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  41. call data%State%MudSystem%Hz_MudOrKick%AddToFirst (0)
  42. data%State%MudSystem%SuctionDensity_Old= data%State%MudSystem%Suction_Density_MudSystem
  43. endif
  44. !========================Horizontal PIPE STRING=================
  45. data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal)
  46. data%State%MudSystem%total_add = data%State%MudSystem%total_add + ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline)
  47. if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  48. data%State%MudSystem%total_add= 0.
  49. endif
  50. !write(*,*) ' total decrease(add to HZ)=' , total_add
  51. !write(*,*) ' add to HZ=' , ((data%State%MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline)
  52. imud=0
  53. do while (imud < data%State%MudSystem%Hz_Mud_Forehead_X%Length())
  54. imud = imud + 1
  55. if (imud> 1) then
  56. data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud-1)
  57. data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud-1)
  58. endif
  59. data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))) &
  60. / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)))
  61. ! +1 for string , -1 for annulus
  62. data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud))* &
  63. data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)) !(ft^3)
  64. data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  65. if ( data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)) then
  66. data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)
  67. data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))
  68. else
  69. data%State%MudSystem%isection= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)+1
  70. data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)
  71. do
  72. if (data%State%MudSystem%isection > 1) then ! (horizontal pipe exit)
  73. data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)
  74. data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(1)
  75. data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= 1
  76. if (data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
  77. call RemoveHzMudArrays(imud)
  78. endif
  79. exit
  80. endif
  81. data%State%MudSystem%xx= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal)
  82. if (data%State%MudSystem%xx<= 1.0) then
  83. data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection
  84. data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)
  85. exit
  86. else
  87. data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection)
  88. data%State%MudSystem%isection= data%State%MudSystem%isection+ 1
  89. endif
  90. enddo
  91. endif
  92. enddo
  93. !========================Horizontal PIPE END=================
  94. !========================Utube1 Air Element Removing=================
  95. !if (UtubeMode1Activated== .true.) then ! StringUpdate == .true.
  96. !
  97. !
  98. ! !StringDensity_Old=data%State%MudSystem%St_Density%Array(2)
  99. !
  100. ! write(*,*) 'StringDensity_Old=' , StringDensity_Old
  101. !
  102. ! UtubeMode1Activated= .false.
  103. !endif
  104. !========================Utube1 Air Element Removing End=================
  105. !!========================Utube2 Removing from Annulus================= not needed 97.04.26
  106. !
  107. ! if (UtubeMode2Activated== .true.) then ! StringUpdate == .true.
  108. !
  109. ! if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist
  110. ! call RemoveAnnulusMudArrays(Ann_MudOrKick%Length())
  111. ! endif
  112. !
  113. ! UtubeMode2Activated= .false.
  114. ! endif
  115. !
  116. !
  117. !!========================Utube2 Removing from Annulus End=================
  118. !========================New Pipe Filling=================
  119. !if (F_StringIntervalCounts > F_StringIntervalCountsOld) then ! StringUpdate == .true.
  120. if (data%State%MudSystem%AddedElementsToString > 0) then ! StringUpdate == .true.
  121. !NoPipeAdded= data%State%F_Counts%StringIntervalCounts - F_StringIntervalCountsOld
  122. data%State%MudSystem%NewPipeFilling=0
  123. IF (data%State%MudSystem%St_MudOrKick%First() == 104) then
  124. data%State%MudSystem%St_MudDischarged_Volume%Array(1) = data%State%MudSystem%St_MudDischarged_Volume%Array(1) + sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString)) ! new pipe is filled by air
  125. else
  126. call data%State%MudSystem%St_Density%AddToFirst (0.d0)
  127. call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString)))
  128. call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2))
  129. call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2)
  130. call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2))
  131. call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2)
  132. call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.d0)
  133. call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0)
  134. call data%State%MudSystem%St_MudOrKick%AddToFirst (104)
  135. endif
  136. endif
  137. !F_StringIntervalCountsOld= F_StringIntervalCounts
  138. if (data%State%MudSystem%NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe)
  139. data%State%MudSystem%LackageMudVolume= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! = Air element
  140. write(*,*) 'LackageMudVolume=' , data%State%MudSystem%LackageMudVolume
  141. if (ABS(data%State%MudSystem%St_Density%Array(2) - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped
  142. call data%State%MudSystem%St_Density%AddTo (2,data%State%MudSystem%Hz_Density%Last())
  143. call data%State%MudSystem%St_MudDischarged_Volume%AddTo (2, 0.d0)
  144. call data%State%MudSystem%St_Mud_Forehead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2))
  145. call data%State%MudSystem%St_Mud_Forehead_section%AddTo (2 , 2)
  146. call data%State%MudSystem%St_Mud_Backhead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2))
  147. call data%State%MudSystem%St_Mud_Backhead_section%AddTo (2 ,2)
  148. call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddTo (2,0.d0)
  149. call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0)
  150. call data%State%MudSystem%St_MudOrKick%AddTo (2,0)
  151. !StringDensity_Old= Hz_Density%Last()
  152. endif
  153. data%State%MudSystem%St_MudDischarged_Volume%Array(2)= data%State%MudSystem%St_MudDischarged_Volume%Array(2)+ min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) !(gal)
  154. data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)- min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) ! air(gal)
  155. !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:))
  156. data%State%MudSystem%LackageMudVolumeAfterFilling= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! last time it should be zero
  157. if (data%State%MudSystem%LackageMudVolumeAfterFilling == 0.) then
  158. data%State%MudSystem%NewPipeFilling= 1
  159. call RemoveStringMudArrays(1)
  160. data%State%MudSystem%St_Mud_Backhead_X%Array(1) = data%State%MudSystem%Xstart_PipeSection(2)
  161. data%State%MudSystem%St_Mud_Backhead_section%Array(1) = 2
  162. endif
  163. endif
  164. !========================New Pipe Filling End=================
  165. if (data%State%MudSystem%NewPipeFilling == 0) then
  166. data%State%MudSystem%StringFlowRate= 0.
  167. data%State%MudSystem%AnnulusFlowRate= 0.
  168. endif
  169. data%State%MudSystem%StringFlowRateFinal= data%State%MudSystem%StringFlowRate
  170. data%State%MudSystem%AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate
  171. !========================STRING ENTRANCE=================
  172. if (data%State%MudSystem%StringFlowRateFinal > 0.0 .and. ABS(data%State%MudSystem%St_Density%First() - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped
  173. call data%State%MudSystem%St_Density%AddToFirst (data%State%MudSystem%Hz_Density%Last())
  174. call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0)
  175. call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2))
  176. call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2)
  177. call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2))
  178. call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2)
  179. call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  180. call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  181. call data%State%MudSystem%St_MudOrKick%AddToFirst (0)
  182. !StringDensity_Old= Hz_Density%Last()
  183. endif
  184. data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal)
  185. !=============== save String Mud data===========
  186. data%State%MudSystem%StMudVolumeSum= 0.d0
  187. !St_MudSaved_Density= 0.d0
  188. data%State%MudSystem%St_Saved_MudDischarged_Volume= 0.d0
  189. !Saved_St_MudOrKick= 0
  190. !Ann_to_Choke_2mud= .false.
  191. do imud=1, data%State%MudSystem%St_MudDischarged_Volume%Length()
  192. data%State%MudSystem%StMudVolumeSum = data%State%MudSystem%StMudVolumeSum + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)
  193. if ( data%State%MudSystem%StMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) ) then
  194. !IF (St_MudOrKick%Array(imud) == 0) THEN
  195. data%State%MudSystem%St_MudSaved_Density =data%State%MudSystem%St_Density%Array(imud)
  196. data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%StMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts))
  197. !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  198. ! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  199. ! Saved_St_MudOrKick= St_MudOrKick%Array (imud)
  200. ! St_KickSaved_Density=data%State%MudSystem%St_Density%Array(imud)
  201. !END IF
  202. do ii= imud + 1, data%State%MudSystem%St_MudDischarged_Volume%Length()
  203. !IF (St_MudOrKick%Array(ii) == 0) THEN
  204. data%State%MudSystem%St_MudSaved_Density = ((data%State%MudSystem%St_MudSaved_Density * data%State%MudSystem%St_Saved_MudDischarged_Volume) + (data%State%MudSystem%St_Density%Array(ii) * data%State%MudSystem%St_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii))
  205. data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii)
  206. !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  207. ! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii)
  208. ! Saved_St_MudOrKick= St_MudOrKick%Array (ii)
  209. ! St_KickSaved_Density=data%State%MudSystem%St_Density%Array(ii)
  210. !END IF
  211. enddo
  212. !WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume
  213. exit ! exits do
  214. endif
  215. enddo
  216. data%State%MudSystem%St_Saved_MudDischarged_Volume_Final = data%State%MudSystem%St_Saved_MudDischarged_Volume
  217. IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedToBH = data%State%MudSystem%St_Saved_MudDischarged_Volume_Final
  218. !======================================================================
  219. !========================STRING=================
  220. imud=0
  221. do while (imud < data%State%MudSystem%St_Mud_Forehead_X%Length())
  222. imud = imud + 1
  223. if (imud> 1) then
  224. data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%St_Mud_Forehead_X%Array(imud-1)
  225. data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%St_Mud_Forehead_section%Array(imud-1)
  226. endif
  227. data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) &
  228. / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)))
  229. ! +1 for string , -1 for annulus
  230. data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))- data%State%MudSystem%St_Mud_Backhead_X%Array(imud))* &
  231. data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3)
  232. data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  233. !write(*,*) 'St_Mud_Backhead_section%Array(1)=' , St_Mud_Backhead_section%Array(1)
  234. !write(*,*) 'Xend_PipeSection(St_Mud_Backhead_section%Array(1))=' , Xend_PipeSection(St_Mud_Backhead_section%Array(1))
  235. !
  236. !write(*,*) 'St_EmptyVolume_inBackheadLocation%Array(1)=' , St_EmptyVolume_inBackheadLocation%Array(1)
  237. !write(*,*) 'St_Mud_Backhead_X%Array(1)=' , St_Mud_Backhead_X%Array(1)
  238. if ( data%State%MudSystem%St_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then
  239. data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)
  240. data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%St_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))
  241. ! 7.48 is for gal to ft^3
  242. else
  243. data%State%MudSystem%isection= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)+1
  244. data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)
  245. do
  246. if (data%State%MudSystem%isection > data%State%F_Counts%StringIntervalCounts) then ! last pipe section(string exit) data%State%F_Counts%StringIntervalCounts includes Horizontal line
  247. data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)
  248. data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)
  249. data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts
  250. if (data%State%MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
  251. call RemoveStringMudArrays(imud)
  252. endif
  253. exit
  254. endif
  255. data%State%MudSystem%xx= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal)
  256. if (data%State%MudSystem%xx<= 1.0) then
  257. data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection
  258. data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)
  259. exit
  260. else
  261. data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection)
  262. data%State%MudSystem%isection= data%State%MudSystem%isection+ 1
  263. endif
  264. enddo
  265. endif
  266. enddo
  267. !write(*,*) ' a before=='
  268. !
  269. ! do imud=1, Op_MudDischarged_Volume%Length()
  270. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  271. ! enddo
  272. !
  273. ! do imud=1, Ann_MudDischarged_Volume%Length()
  274. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  275. ! enddo
  276. !
  277. !write(*,*) '==== a before'
  278. !write(*,*) ' iloc (a): ' , iloc
  279. !========================STRING END=================
  280. IF (data%State%MudSystem%Op_MudOrKick%Last() /= 0 .and. data%State%MudSystem%Op_MudOrKick%Last()==data%State%MudSystem%Ann_MudOrKick%First()) data%State%MudSystem%iLoc=2 ! it may be 1,2,3 or more, all of them are kick
  281. !write(*,*) ' iloc (b): ' , iloc
  282. !=============================Add PumpFlowRate to Bottom Hole ==============================
  283. !if ( data%State%MudSystem%AnnulusFlowRate>0.0 ) then
  284. if ( data%State%MudSystem%MudVolume_InjectedToBH > 0.0 ) then
  285. if (KickVARIABLES%KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the
  286. AddLocation= data%State%MudSystem%Op_Density%Length()-data%State%MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick
  287. else
  288. AddLocation= data%State%MudSystem%Op_Density%Length()+1
  289. endif
  290. !write(*,*) 'AddLocation====' , AddLocation
  291. if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0')
  292. if ( ABS(data%State%MudSystem%St_Density%Last() - data%State%MudSystem%Op_Density%Array(AddLocation-1)) >= data%State%MudSystem%DensityMixTol ) then
  293. !write(*,*) 'new pocket**'
  294. !write(*,*) data%State%MudSystem%St_Density%Last()=' ,data%State%MudSystem%St_Density%Last()
  295. !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1)
  296. call data%State%MudSystem%Op_Density% AddTo (AddLocation,data%State%MudSystem%St_Density%Last())
  297. !call Op_MudDischarged_Volume%AddTo (AddLocation,((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))
  298. call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (AddLocation,data%State%MudSystem%MudVolume_InjectedToBH)
  299. call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1))
  300. call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (AddLocation,1)
  301. call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1))
  302. call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (AddLocation,1)
  303. call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0)
  304. call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0)
  305. call data%State%MudSystem%Op_MudOrKick%AddTo (AddLocation,0)
  306. else
  307. !write(*,*) 'merge**'
  308. !write(*,*) 'density before=' , Op_Density%Array(AddLocation-1)
  309. !write(*,*) data%State%MudSystem%St_Density%Last() for mix=' ,data%State%MudSystem%St_Density%Last()
  310. !Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))
  311. !Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)
  312. data%State%MudSystem%Op_Density%Array(AddLocation-1)= (data%State%MudSystem%Op_Density%Array(AddLocation-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%St_Density%Last()*data%State%MudSystem%MudVolume_InjectedToBH)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%MudVolume_InjectedToBH)
  313. data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1) + data%State%MudSystem%MudVolume_InjectedToBH
  314. !write(*,*) 'density after=' , Op_Density%Array(AddLocation-1)
  315. endif
  316. endif
  317. !=======================Add PumpFlowRate to Bottom Hole- End ==============================
  318. !=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick
  319. data%State%MudSystem%OpMudVolumeSum= 0.d0
  320. !Op_MudSaved_Density= 0.d0
  321. !Op_KickSaved_Density= 0.d0
  322. data%State%MudSystem%Op_Saved_MudDischarged_Volume= 0.d0
  323. data%State%MudSystem%Op_Kick_Saved_Volume= 0.d0
  324. data%State%MudSystem%Saved_Op_MudOrKick= 0
  325. !write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
  326. !write(*,*) 'Op_MudDischarged_Volume%Length()===' , Op_MudDischarged_Volume%Length()
  327. !
  328. do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length()
  329. !write(*,*) 'imud, Op_MudDischarged_Volume%Array(imud)=' , imud,Op_MudDischarged_Volume%Array(imud)
  330. data%State%MudSystem%OpMudVolumeSum= data%State%MudSystem%OpMudVolumeSum + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)
  331. if ( data%State%MudSystem%OpMudVolumeSum > sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) ) then
  332. IF (data%State%MudSystem%Op_MudOrKick%Array(imud) == 0) THEN
  333. data%State%MudSystem%Op_MudSaved_Density = data%State%MudSystem%Op_Density%Array(imud)
  334. data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts))
  335. ELSE
  336. data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts))
  337. !write(*,*) 'cond 1- Op_MudOrKick%Array (imud),Op_Density%Array(imud):' ,Op_MudOrKick%Array (imud),Op_Density%Array(imud)
  338. data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (imud)
  339. data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(imud)
  340. data%State%MudSystem%iLoc= 2
  341. END IF
  342. do ii= imud + 1, data%State%MudSystem%Op_MudDischarged_Volume%Length()
  343. IF (data%State%MudSystem%Op_MudOrKick%Array(ii) == 0) THEN
  344. data%State%MudSystem%Op_MudSaved_Density = ((data%State%MudSystem%Op_MudSaved_Density * data%State%MudSystem%Op_Saved_MudDischarged_Volume) + (data%State%MudSystem%Op_Density%Array(ii) * data%State%MudSystem%Op_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii))
  345. data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii)
  346. ELSE
  347. data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%Op_Kick_Saved_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii)
  348. !write(*,*) 'cond 2- Op_MudOrKick%Array (ii),Op_Density%Array(ii):' ,Op_MudOrKick%Array (ii),Op_Density%Array(ii)
  349. data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (ii)
  350. data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(ii)
  351. data%State%MudSystem%iLoc= 2
  352. END IF
  353. enddo
  354. exit ! exits do
  355. endif
  356. enddo
  357. !WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume
  358. !write(*,*) ' iloc (c): ' , iloc
  359. !======================================================================
  360. !======================================================================
  361. !if (iLoc == 1) then
  362. data%State%MudSystem%MudSection= data%State%F_Counts%StringIntervalCounts+1
  363. data%State%MudSystem%BackheadX= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)
  364. !elseif (iLoc == 2) then
  365. ! MudSection= Kick_Forehead_section
  366. ! BackheadX= Kick_Forehead_X
  367. !endif
  368. !========================ANNULUS ENTRANCE====================
  369. !if (KickMigration_2SideBit == .FALSE.) then ! because its effect is applied in Migration Code
  370. ! !write(*,*) 'iloc=====' , iLoc bejaye data%State%ROP_Bit%RateOfPenetration ==0. in bude: DeltaVolumeOp == 0.0
  371. ! if (ABS(AnnulusSuctionDensity_OldMudSystem%St_Density%Last()) >= DensityMixTol .OR. (DeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(iLoc)data%State%MudSystem%St_Density%Last())>=DensityMixTol .and. data%State%MudSystem%AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped
  372. ! call Ann_Density%AddTo (iLocMudSystem%St_Density%Last())
  373. ! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0)
  374. ! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
  375. ! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
  376. ! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
  377. ! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
  378. ! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
  379. ! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
  380. ! call Ann_MudOrKick%AddTo (iLoc,0)
  381. ! call Ann_CuttingMud%AddTo (iLoc,0)
  382. ! !write(*,*) 'c) annLength=' , Ann_Density%Length()
  383. !
  384. ! AnnulusSuctionDensity_Old=data%State%MudSystem%St_Density%Last()
  385. !
  386. ! MudIsChanged= .true.
  387. ! endif
  388. !
  389. ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) !(gal)
  390. !
  391. !endif
  392. data%State%MudSystem%Ann_Mud_Backhead_section%Array(1)= data%State%MudSystem%MudSection !it is needed to be updated for a condition that one pipe is removed from Annulus due to trip out
  393. data%State%MudSystem%Ann_Mud_Backhead_X%Array(1)= data%State%MudSystem%BackheadX
  394. ! write(*,*) 'zero)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
  395. !
  396. !
  397. !write(*,*) 'pump added-before add to ann=='
  398. !
  399. ! do imud=1, Op_MudDischarged_Volume%Length()
  400. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  401. ! enddo
  402. !
  403. ! do imud=1, Ann_MudDischarged_Volume%Length()
  404. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  405. ! enddo
  406. !
  407. !write(*,*) '====pump added-before add to ann'
  408. !========================Tripping In====================
  409. !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
  410. if (data%State%ROP_Bit%RateOfPenetration==0.) then ! .and. Op_MudOrKick%Last() == 0) then ! trip in mode(loole paeen) Mud
  411. !write(*,*) 'Tripping In'
  412. !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  413. !if ( MudIsChanged== .true. ) then
  414. ! call RemoveAnnulusMudArrays(iLoc)
  415. !endif
  416. if (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0) then
  417. write(*,*) 'Kick influx enters Annulus'
  418. call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_KickSaved_Density)
  419. call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Op_Kick_Saved_Volume)
  420. call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1))
  421. call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1)
  422. call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1))
  423. call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1)
  424. call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  425. call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  426. call data%State%MudSystem%Ann_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Op_MudOrKick) !<<<<<<<<
  427. call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0)
  428. elseif (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() /= 0) then
  429. data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) + data%State%MudSystem%Op_Kick_Saved_Volume
  430. endif
  431. if (data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then
  432. data%State%MudSystem%NewDensity= data%State%MudSystem%Op_MudSaved_Density
  433. data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume
  434. !write(*,*) 'NewVolume=' , NewVolume
  435. !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  436. if ((data%State%ROP_Bit%RateOfPenetration==0 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) &
  437. .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol) &
  438. .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged
  439. data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume)
  440. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume
  441. data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  442. data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  443. data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  444. data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  445. data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0)
  446. data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0)
  447. !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  448. else ! 2-Merging conditions are not meeted, so new pocket
  449. call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity)
  450. call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume)
  451. call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  452. call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  453. call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  454. call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  455. call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0)
  456. call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0)
  457. call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0)
  458. call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0)
  459. !write(*,*) 'd) annLength=' , Ann_Density%Length()
  460. !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  461. endif
  462. endif
  463. endif
  464. !========================Tripping In - End====================
  465. !========================Drilling Mode========================
  466. if (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%DeltaVolumeOp>0.0) then ! trip in mode(loole paeen) DrillingMode== .true.
  467. !write(*,*) 'Drilling Mode'
  468. !if ( MudIsChanged== .true. ) then
  469. ! call RemoveAnnulusMudArrays(iLoc)
  470. !endif
  471. !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  472. !data%State%MudSystem%NewDensity= data%State%MudSystem%St_Density%Last() * data%State%MudSystem%AnnulusFlowRate + 141.4296E-4*data%State%ROP_Bit%RateOfPenetration*data%State%ROP_Spec%DiameterOfBit**2)/(data%State%MudSystem%AnnulusFlowRate+6.7995E-4*data%State%ROP_Bit%RateOfPenetration*Diameter_of_Bit**2)
  473. data%State%MudSystem%NewDensity=data%State%MudSystem%St_Density%Last()
  474. !NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp
  475. !!! Density in ppg, flow rate in gpm, ROP in ft/s, bit diameter in inch
  476. do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length()
  477. if ( data%State%MudSystem%Op_MudOrKick%Array(imud) == 0 ) then
  478. data%State%MudSystem%Op_Density%Array(imud)= data%State%MudSystem%NewDensity
  479. endif
  480. enddo
  481. if (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0) then
  482. write(*,*) 'Kick influx enters Annulus first time'
  483. !write(*,*) 'Saved_Op_MudOrKick=',Saved_Op_MudOrKick
  484. call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_KickSaved_Density)
  485. call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Op_Kick_Saved_Volume)
  486. call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1))
  487. call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1)
  488. call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1))
  489. call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1)
  490. call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  491. call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  492. call data%State%MudSystem%Ann_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Op_MudOrKick) !<<<<<<<<
  493. call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0)
  494. elseif (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() /= 0) then
  495. data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) + data%State%MudSystem%Op_Kick_Saved_Volume
  496. endif
  497. if (data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then
  498. !write(*,*) 'Op_Saved_Mud added'
  499. data%State%MudSystem%NewDensity= data%State%MudSystem%NewDensity !(drilling density)
  500. data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%DeltaVolumeOp ! (DeltaVolumeOp: for Cuttings Volume)
  501. !write(*,*) 'NewVolume=' , NewVolume
  502. !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  503. if ( (data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol ) &
  504. .or. (data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged
  505. data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume)
  506. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume
  507. data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  508. data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  509. data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  510. data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  511. data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0)
  512. data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0)
  513. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)= 1
  514. !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  515. else ! 2-Merging conditions are not meeted, so new pocket
  516. !write(*,*) 'before e) ', iloc, Ann_Density%Array(iLoc),data%State%MudSystem%NewDensity
  517. !write(*,*) 'before e) Ann_MudDischarged_Volume%Array(iLoc)=' , Ann_MudDischarged_Volume%Array(iLoc)
  518. call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity)
  519. call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume)
  520. call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  521. call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  522. call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  523. call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  524. call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0)
  525. call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0)
  526. call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0)
  527. call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,1) ! 1= cutting 0= mud
  528. !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
  529. !write(*,*) 'e) annLength=' , Ann_Density%Length()
  530. endif
  531. endif
  532. endif
  533. !===================================================================
  534. !write(*,*) 'after add to ann=='
  535. !
  536. ! do imud=1, Op_MudDischarged_Volume%Length()
  537. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  538. ! enddo
  539. !
  540. ! do imud=1, Ann_MudDischarged_Volume%Length()
  541. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  542. ! enddo
  543. !
  544. !write(*,*) '==after add to ann'
  545. data%State%MudSystem%NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume
  546. if (data%State%MudSystem%iLoc==2 .and. data%State%MudSystem%Op_MudOrKick%Last()==0 .and. data%State%MudSystem%NewVolume > 0.d0 ) then ! for avoid kick separation
  547. !write(*,*) 'avoid kick separation'
  548. data%State%MudSystem%NewDensity= data%State%MudSystem%Op_MudSaved_Density
  549. call RemoveOpMudArrays(data%State%MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann
  550. if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline)- data%State%MudSystem%Op_Saved_MudDischarged_Volume) then! 1st in Ann = kick
  551. !write(*,*) 'mode1'
  552. data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) -data%State%MudSystem%Op_Saved_MudDischarged_Volume)
  553. data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) !kick
  554. else
  555. call RemoveAnnulusMudArrays(1) !kick is removed
  556. data%State%MudSystem%iLoc= 1
  557. data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume)
  558. !write(*,*) 'mode2'
  559. ! including a little expand
  560. endif
  561. if ((data%State%ROP_Bit%RateOfPenetration==0 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) &
  562. .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol) &
  563. .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged
  564. data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume)
  565. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume
  566. data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  567. data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  568. data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX
  569. data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection
  570. data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0)
  571. data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0)
  572. else ! 2-Merging conditions are not meeted, so new pocket
  573. call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity)
  574. call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume)
  575. call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  576. call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  577. call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX)
  578. call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection)
  579. call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0)
  580. call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0)
  581. call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0)
  582. call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0)
  583. !write(*,*) 'd) annLength=' , Ann_Density%Length()
  584. endif
  585. endif
  586. !===================================================================
  587. if( data%State%MudSystem%Op_MudOrKick%Last() == 1 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0 ) then
  588. write(*,*) '***error2****=='
  589. write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , data%State%MudSystem%Op_Kick_Saved_Volume,data%State%MudSystem%Op_Saved_MudDischarged_Volume
  590. write(*,*) 'after add to ann=='
  591. do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length()
  592. write(*,*) 'Op:', imud, data%State%MudSystem%Op_MudDischarged_Volume%Array(imud), data%State%MudSystem%Op_Density%Array(imud) ,data%State%MudSystem%Op_MudOrKick%Array(imud)
  593. enddo
  594. do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length()
  595. write(*,*) 'Ann:', imud, data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud), data%State%MudSystem%Ann_Density%Array(imud) ,data%State%MudSystem%Ann_MudOrKick%Array(imud)
  596. enddo
  597. write(*,*) '==after add to ann'
  598. write(*,*) 'NewVolume,Op_MudOrKick%Last=' , data%State%MudSystem%NewVolume,data%State%MudSystem%Op_MudOrKick%Last()
  599. write(*,*) '==***error2****'
  600. endif
  601. !=============== save Ann Mud data to transfer to the ChokeLine enterance
  602. data%State%MudSystem%AnnMudVolumeSum= 0.d0
  603. !Ann_MudSaved_Density= 0.d0
  604. !Ann_KickSaved_Density= 0.d0
  605. data%State%MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0
  606. data%State%MudSystem%Ann_Kick_Saved_Volume= 0.d0
  607. data%State%MudSystem%Saved_Ann_MudOrKick= 0
  608. data%State%MudSystem%Ann_to_Choke_2mud= .false.
  609. do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length()
  610. data%State%MudSystem%AnnMudVolumeSum= data%State%MudSystem%AnnMudVolumeSum + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)
  611. if ( data%State%MudSystem%AnnMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) ) then
  612. IF (data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0) THEN
  613. data%State%MudSystem%Ann_MudSaved_Density = data%State%MudSystem%Ann_Density%Array(imud)
  614. data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections))
  615. ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(imud) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  616. data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections))
  617. data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (imud)
  618. data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(imud)
  619. END IF
  620. do ii= imud + 1, data%State%MudSystem%Ann_MudDischarged_Volume%Length()
  621. IF (data%State%MudSystem%Ann_MudOrKick%Array(ii) == 0) THEN
  622. data%State%MudSystem%Ann_MudSaved_Density = ((data%State%MudSystem%Ann_MudSaved_Density * data%State%MudSystem%Ann_Saved_MudDischarged_Volume) + (data%State%MudSystem%Ann_Density%Array(ii) * data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii))
  623. data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii)
  624. data%State%MudSystem%Ann_to_Choke_2mud= .true.
  625. ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(ii) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR
  626. data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%Ann_Kick_Saved_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii)
  627. data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (ii)
  628. data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(ii)
  629. END IF
  630. enddo
  631. !WRITE (*,*) 'Ann_Saved_Mud_Volume, Ann_Kick_Saved_Volume', Ann_Saved_MudDischarged_Volume, Ann_Kick_Saved_Volume
  632. exit
  633. endif
  634. enddo
  635. data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Ann_Saved_MudDischarged_Volume !+ Ann_Kick_Saved_Volume
  636. data%State%MudSystem%Ann_Kick_Saved_Volume_Final= data%State%MudSystem%Ann_Kick_Saved_Volume
  637. IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedFromAnn = data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final -((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline)
  638. !WRITE (*,*) 'data%State%MudSystem%MudVolume_InjectedFromAnn=', data%State%MudSystem%MudVolume_InjectedFromAnn
  639. !======================================================================
  640. !write(*,*) 'c)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
  641. !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  642. !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume
  643. data%State%MudSystem%total_injected = data%State%MudSystem%total_injected + data%State%MudSystem%MudVolume_InjectedFromAnn
  644. if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
  645. data%State%MudSystem%total_injected= 0.
  646. endif
  647. !write(*,*) ' total injected-tripin =' , total_injected
  648. !write(*,*) 'injected-tripin =' , data%State%MudSystem%MudVolume_InjectedFromAnn
  649. !======================== Annulus ====================
  650. !MudIsChanged= .false.
  651. imud= 0
  652. do while (imud < data%State%MudSystem%Ann_Mud_Forehead_X%Length())
  653. imud = imud + 1
  654. if (imud> 1) then
  655. data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud-1)
  656. data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud-1)
  657. endif
  658. ! <<< Fracture Shoe Lost
  659. IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then
  660. !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline)
  661. data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal)
  662. if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then
  663. !write(*,*) 'mud is removed by shoe lost, imud=' , imud
  664. call RemoveAnnulusMudArrays(imud)
  665. imud= imud-1
  666. cycle
  667. endif
  668. ENDIF
  669. ! Fracture Shoe Lost >>>
  670. data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) &
  671. / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)))
  672. ! +1 for string , -1 for annulus
  673. data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud))* &
  674. data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3)
  675. data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  676. if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then
  677. data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)
  678. data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))
  679. ! 7.48 is for gal to ft^3
  680. else
  681. data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)+1
  682. data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)
  683. do
  684. if (data%State%MudSystem%isection > data%State%MudSystem%NoPipeSections) then ! last pipe section(well exit)
  685. data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)
  686. data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)
  687. data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%NoPipeSections
  688. if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
  689. !write(*,*) 'remove******'
  690. call RemoveAnnulusMudArrays(imud)
  691. endif
  692. exit
  693. endif
  694. data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal)
  695. if (data%State%MudSystem%xx<= 1.0) then
  696. data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection
  697. data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)
  698. exit
  699. else
  700. data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection)
  701. data%State%MudSystem%isection= data%State%MudSystem%isection+ 1
  702. endif
  703. enddo
  704. endif
  705. ! write(*,*) 'imud=' , imud
  706. !write(*,*) 'Pinter4 **Ann_Length()=' , Ann_Mud_Forehead_X%Length()
  707. ! write(*,*) 'Ann_Density%Array (imud)=' , Ann_Density%Array (imud)
  708. !
  709. !
  710. !write(*,*) imud,'Ann_Mud_Forehead_X%Array(imud)=' , Ann_Mud_Forehead_X%Array(imud)
  711. !if (Ann_Mud_Forehead_X%Array(imud) < Xend_PipeSection(NoPipeSections)) then
  712. ! Ann_Mud_Forehead_X%Array(imud) = Xend_PipeSection(NoPipeSections) ! for error preventing
  713. !endif
  714. !write(*,*) imud, 'Ann_MudDischarged_Volume%Array(imud)=' , Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud)
  715. enddo
  716. if (data%State%MudSystem%Ann_Mud_Forehead_X%Last() < data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) then
  717. data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%Ann_Mud_Forehead_X%Length()) = data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) ! for error preventing
  718. endif
  719. !========================ANNULUS END=================
  720. !write(*,*) 'sum(Ann_MudDischarged_Volume%Array())=' , sum(Ann_MudDischarged_Volume%Array(:))
  721. !=========================================================
  722. !write(*,*) 'before======2'
  723. !
  724. ! do imud=1, Op_MudDischarged_Volume%Length()
  725. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  726. ! enddo
  727. !write(*,*) '2======before'
  728. !========================Bottom Hole=================
  729. imud=0
  730. do while (imud < data%State%MudSystem%Op_Mud_Forehead_X%Length())
  731. imud = imud + 1
  732. if (imud> 1) then
  733. data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_X%Array(imud-1)
  734. data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_section%Array(imud-1)
  735. endif
  736. !write(*,*) 'imud**=' , imud
  737. data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) &
  738. / ABS(data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)))
  739. ! +1 for string , -1 for annulus
  740. data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Op_Mud_Backhead_X%Array(imud))* &
  741. data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3)
  742. data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  743. !write(*,*) ' Op_EmptyVolume_inBackheadLocation%Array(1) =' , Op_EmptyVolume_inBackheadLocation%Array(1)
  744. if ( data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(1) < 0.0) CALL ErrorStop1 ('Negative Empty volume')
  745. if ( data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then
  746. data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)
  747. data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))
  748. ! 7.48 is for gal to ft^3
  749. else
  750. data%State%MudSystem%isection= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)+1
  751. data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)
  752. do
  753. if (data%State%MudSystem%isection > data%State%F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit)
  754. !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space
  755. data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)
  756. data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)
  757. data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%F_Counts%BottomHoleIntervalCounts
  758. if (data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
  759. call RemoveOpMudArrays(imud)
  760. endif
  761. exit
  762. endif
  763. data%State%MudSystem%xx= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) !(gal)
  764. if (data%State%MudSystem%xx<= 1.0) then
  765. data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection
  766. data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)
  767. exit
  768. else
  769. data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection)
  770. data%State%MudSystem%isection= data%State%MudSystem%isection+ 1
  771. endif
  772. enddo
  773. endif
  774. ! for OP remove:
  775. if (data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)== data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then
  776. data%State%MudSystem%totalLength = data%State%MudSystem%Op_MudDischarged_Volume%Length()
  777. do while(imud < data%State%MudSystem%totalLength)
  778. !imud = imud + 1
  779. call RemoveOpMudArrays(data%State%MudSystem%totalLength)
  780. data%State%MudSystem%totalLength = data%State%MudSystem%totalLength - 1
  781. enddo
  782. exit !
  783. endif
  784. !if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then
  785. ! totalLength = Op_MudDischarged_Volume%Length()
  786. ! do while(imud <= totalLength)
  787. !
  788. ! imud = imud + 1
  789. ! call RemoveOpMudArrays(imud)
  790. ! totalLength = totalLength - 1
  791. !
  792. !
  793. ! enddo
  794. !
  795. ! exit !
  796. !
  797. !endif
  798. enddo
  799. !write(*,*) 'OpSection_VolumeCapacity sum=' , sum(OpSection_VolumeCapacity(:))
  800. !========================Bottom Hole END=================
  801. !write(*,*) 'after sorting=='
  802. !
  803. ! do imud=1, Op_MudDischarged_Volume%Length()
  804. ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
  805. ! enddo
  806. !
  807. ! do imud=1, Ann_MudDischarged_Volume%Length()
  808. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  809. ! enddo
  810. !
  811. ! !
  812. ! !do imud=1, st_MudDischarged_Volume%Length()
  813. ! ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
  814. ! !enddo
  815. !
  816. !write(*,*) '==after sorting'
  817. ! write(*,*) 'after sorting st=='
  818. !
  819. ! do imud=1, st_MudDischarged_Volume%Length()
  820. ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)data%State%MudSystem%St_Density%Array(imud)
  821. ! enddo
  822. !
  823. !write(*,*) '==after sorting st'
  824. !write(*,*) '**Ann_Kick_Saved_Final,Mud_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn
  825. end subroutine Pump_and_TripIn
  826. subroutine ChokeLineMud ! is called in subroutine CirculationCodeSelect
  827. Use GeoElements_FluidModule
  828. USE CMudPropertiesVariables
  829. USE MudSystemVARIABLES
  830. use SimulationVariables !@@@
  831. use SimulationVariables
  832. USE CHOKEVARIABLES
  833. !use ConfigurationVariables !@
  834. !use CDataDisplayConsole
  835. !@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure
  836. !use CManifolds
  837. use SimulationVariables !@
  838. USE CHOKEVARIABLES
  839. !use ConfigurationVariables !@
  840. !use CChokeManifoldVariables
  841. use SimulationVariables
  842. !use CTanks
  843. !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity
  844. USE sROP_Other_Variables
  845. USE sROP_Variables
  846. use KickVARIABLESModule
  847. use PressureDisplayVARIABLESModule
  848. Use CError
  849. Use , intrinsic :: IEEE_Arithmetic
  850. implicit none
  851. integer i,ii,error_occured
  852. error_occured = 0
  853. !write(*,*) 'begining chokeline=='
  854. !write(*,*) 'Ann last:', Ann_MudDischarged_Volume%Last(), Ann_Density%Last() ,Ann_MudOrKick%Last()
  855. !
  856. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  857. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  858. !enddo
  859. !write(*,*) 'Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn
  860. !write(*,*) 'begining chokeline=='
  861. data%State%MudSystem%ChokeLineFlowRate = data%State%MUD(4)%Q
  862. !WRITE (*,*) 'data%State%MUD(4)%Q', data%State%MUD(4)%Q
  863. if (data%State%MudSystem%NewPipeFilling == 0) then ! .or. UtubeFilling==0) then
  864. data%State%MudSystem%ChokeLineFlowRate= 0.
  865. endif
  866. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2
  867. if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
  868. write(*,*) 'error_location is 1'
  869. error_occured = 1
  870. endif
  871. enddo
  872. !
  873. !do imud=1, st_MudDischarged_Volume%Length()
  874. ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
  875. !enddo
  876. !========================CHOKE LINE ENTRANCE=================
  877. !if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume-((Qlost/60.0d0)*DeltaT_Mudline) ) == 0.0 ) then
  878. if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( data%State%MudSystem%MudVolume_InjectedFromAnn ) <= 1.0e-5 ) then
  879. !WRITE (*,*) 'only kick enters to chokeline, Casing pressure = ', PressureGauges(2)
  880. if (data%State%MudSystem%ChokeLine_MudOrKick%First() == 0) then
  881. call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_KickSaved_Density)
  882. call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.d0)
  883. call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  884. call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1)
  885. call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  886. call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1)
  887. call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  888. call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  889. call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Ann_MudOrKick)
  890. data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_KickSaved_Density
  891. endif
  892. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ data%State%MudSystem%Ann_Kick_Saved_Volume !(gal)
  893. endif
  894. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2
  895. if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
  896. write(*,*) 'error_location is 2'
  897. error_occured = 1
  898. endif
  899. enddo
  900. !if ( Ann_Kick_Saved_Volume == 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 ) then
  901. if ( data%State%MudSystem%Ann_Kick_Saved_Volume <= 1.0e-5 .and. data%State%MudSystem%MudVolume_InjectedFromAnn > 1.0e-5 ) then
  902. !WRITE (*,*) 'only mud enters to chokeline'
  903. if ((data%State%MudSystem%Ann_to_Choke_2mud == .false. .and. ABS(data%State%MudSystem%ChokeLineDensity_Old - data%State%MudSystem%Ann_MudSaved_Density) >= data%State%MudSystem%DensityMixTol) .or. data%State%MudSystem%ChokeLine_MudOrKick%First() /= 0) then ! new mud is pumped
  904. call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_MudSaved_Density)
  905. call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.0d0)
  906. call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  907. call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1)
  908. call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  909. call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1)
  910. call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  911. call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  912. call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (0)
  913. data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_MudSaved_Density
  914. endif
  915. !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
  916. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ (data%State%MudSystem%MudVolume_InjectedFromAnn) !(gal)
  917. endif
  918. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2
  919. if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
  920. write(*,*) 'error_location is 3'
  921. error_occured = 1
  922. endif
  923. enddo
  924. !if ( Ann_Kick_Saved_Volume > 0.0 .and. (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() /= 0 ) then
  925. if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. (data%State%MudSystem%MudVolume_InjectedFromAnn) > 1.0e-5 .and. data%State%MudSystem%ChokeLine_MudOrKick%First() /= 0 ) then
  926. WRITE (*,*) 'Kick Enters Choke line Last Time'
  927. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ data%State%MudSystem%Ann_Kick_Saved_Volume !(gal)
  928. call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_MudSaved_Density)
  929. !call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) )
  930. call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (data%State%MudSystem%MudVolume_InjectedFromAnn)
  931. call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  932. call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1)
  933. call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  934. call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1)
  935. call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  936. call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  937. call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (0)
  938. data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_MudSaved_Density
  939. !ELSE if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() == 0 ) then
  940. ELSE if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( data%State%MudSystem%MudVolume_InjectedFromAnn ) > 1.0e-5 .and. data%State%MudSystem%ChokeLine_MudOrKick%First() == 0 ) then
  941. WRITE (*,*) 'Kick Enters Choke line First Time'
  942. !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
  943. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ ( data%State%MudSystem%MudVolume_InjectedFromAnn ) !(gal)
  944. call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_KickSaved_Density)
  945. call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Ann_Kick_Saved_Volume)
  946. call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
  947. call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1)
  948. call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
  949. call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1)
  950. call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
  951. call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
  952. call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Ann_MudOrKick)
  953. data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_KickSaved_Density
  954. endif
  955. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2
  956. if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
  957. write(*,*) 'error_location is 4'
  958. error_occured = 1
  959. endif
  960. enddo
  961. if (error_occured == 1) then
  962. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()
  963. write(*,*) 'ChokeLine:', imud, data%State%MudSystem%ChokeLine_Density%Array(imud) ,data%State%MudSystem%ChokeLine_MudOrKick%Array(imud)
  964. enddo
  965. endif
  966. !==========================================================
  967. !
  968. !write(*,*) 'after add chokeline=='
  969. !
  970. ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
  971. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  972. ! enddo
  973. !
  974. !write(*,*) 'after add chokeline=='
  975. !
  976. !
  977. !=============== save Choke Mud data==========================
  978. data%State%MudSystem%ChokeMudVolumeSum= 0.d0
  979. !Ann_MudSaved_Density= 0.d0
  980. !Ann_KickSaved_Density= 0.d0
  981. data%State%MudSystem%Choke_Saved_MudDischarged_Volume= 0.d0
  982. data%State%MudSystem%Choke_Kick_Saved_Volume= 0.d0
  983. data%State%MudSystem%Saved_Choke_MudOrKick= 0
  984. do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()
  985. data%State%MudSystem%ChokeMudVolumeSum= data%State%MudSystem%ChokeMudVolumeSum + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)
  986. if ( data%State%MudSystem%ChokeMudVolumeSum > data%State%MudSystem%ChokeLine_VolumeCapacity ) then
  987. IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) == 0) THEN
  988. data%State%MudSystem%Choke_MudSaved_Density = data%State%MudSystem%ChokeLine_Density%Array(imud)
  989. data%State%MudSystem%Choke_Saved_MudDischarged_Volume = data%State%MudSystem%ChokeMudVolumeSum - data%State%MudSystem%ChokeLine_VolumeCapacity
  990. ELSEIF (data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) > 0 .AND. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) <100) THEN ! 104= AIR
  991. data%State%MudSystem%Choke_Kick_Saved_Volume = data%State%MudSystem%ChokeMudVolumeSum - data%State%MudSystem%ChokeLine_VolumeCapacity
  992. data%State%MudSystem%Saved_Choke_MudOrKick= data%State%MudSystem%ChokeLine_MudOrKick%Array (imud)
  993. data%State%MudSystem%Choke_KickSaved_Density= data%State%MudSystem%ChokeLine_Density%Array(imud)
  994. END IF
  995. do ii= imud + 1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()
  996. IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) == 0) THEN
  997. data%State%MudSystem%Choke_MudSaved_Density = ((data%State%MudSystem%Choke_MudSaved_Density * data%State%MudSystem%Choke_Saved_MudDischarged_Volume) + (data%State%MudSystem%ChokeLine_Density%Array(ii) * data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Choke_Saved_MudDischarged_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii))
  998. data%State%MudSystem%Choke_Saved_MudDischarged_Volume = data%State%MudSystem%Choke_Saved_MudDischarged_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii)
  999. ELSEIF (data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) > 0 .AND. data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) <100) THEN ! 104= AIR
  1000. data%State%MudSystem%Choke_Kick_Saved_Volume = data%State%MudSystem%Choke_Kick_Saved_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii)
  1001. data%State%MudSystem%Saved_Choke_MudOrKick= data%State%MudSystem%ChokeLine_MudOrKick%Array (ii)
  1002. data%State%MudSystem%Choke_KickSaved_Density= data%State%MudSystem%ChokeLine_Density%Array(ii)
  1003. END IF
  1004. enddo
  1005. !WRITE (*,*) 'Choke_Saved_Mud_Volume, Choke_Kick_Saved_Volume', Choke_Saved_MudDischarged_Volume, Choke_Kick_Saved_Volume
  1006. exit ! exits do
  1007. endif
  1008. enddo
  1009. data%State%MudSystem%Choke_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Choke_Saved_MudDischarged_Volume !+ Choke_Kick_Saved_Volume
  1010. data%State%MudSystem%Choke_Kick_Saved_Volume_Final= data%State%MudSystem%Choke_Kick_Saved_Volume
  1011. !======================================================================
  1012. !
  1013. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1014. ! write(*,*) 'a)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1015. !enddo
  1016. !write(*,*) 'choke_Mud sum=' , sum(ChokeLine_MudDischarged_Volume%Array(:))
  1017. !write(*,*) 'choke_cap=' , ChokeLine_VolumeCapacity
  1018. !write(*,*) 'Choke_Saved_Mud=' , Choke_Saved_MudDischarged_Volume_Final
  1019. !write(*,*) 'Choke_Saved_Kick=' , Choke_Kick_Saved_Volume_Final
  1020. !========================Choke Line=================
  1021. imud=0
  1022. do while (imud < data%State%MudSystem%ChokeLine_Mud_Forehead_X%Length())
  1023. imud = imud + 1
  1024. if (imud> 1) then
  1025. data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud-1)
  1026. data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud-1)
  1027. endif
  1028. !DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) &
  1029. ! / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud)))
  1030. ! +1 for string , -1 for annulus
  1031. data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= (data%Configuration%BopStack%ChokeLineLength- data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud))* data%State%MudSystem%Area_ChokeLineFt !(ft^3)
  1032. data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
  1033. if ( data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)) then
  1034. data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)
  1035. data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)+ (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_ChokeLineFt
  1036. ! 7.48 is for gal to ft^3
  1037. else
  1038. data%State%MudSystem%isection= data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)+1
  1039. data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)
  1040. do
  1041. if (data%State%MudSystem%isection > 1) then ! last pipe section(Chokeline exit)
  1042. data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)
  1043. data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%Configuration%BopStack%ChokeLineLength
  1044. data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= 1
  1045. if (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
  1046. call data%State%MudSystem%ChokeLine_MudDischarged_Volume%Remove (imud)
  1047. call data%State%MudSystem%ChokeLine_Mud_Backhead_X%Remove (imud)
  1048. call data%State%MudSystem%ChokeLine_Mud_Backhead_section%Remove (imud)
  1049. call data%State%MudSystem%ChokeLine_Mud_Forehead_X%Remove (imud)
  1050. call data%State%MudSystem%ChokeLine_Mud_Forehead_section%Remove (imud)
  1051. call data%State%MudSystem%ChokeLine_Density%Remove (imud)
  1052. call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Remove (imud)
  1053. call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Remove (imud)
  1054. call data%State%MudSystem%ChokeLine_MudOrKick%Remove (imud)
  1055. endif
  1056. exit
  1057. endif
  1058. data%State%MudSystem%xx= data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%ChokeLine_VolumeCapacity !(gal)
  1059. if (data%State%MudSystem%xx<= 1.0) then
  1060. data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection
  1061. data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%State%MudSystem%xx * data%Configuration%BopStack%ChokeLineLength
  1062. exit
  1063. else
  1064. data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%ChokeLine_VolumeCapacity
  1065. data%State%MudSystem%isection= data%State%MudSystem%isection+ 1
  1066. endif
  1067. enddo
  1068. endif
  1069. enddo
  1070. !========================Choke Line END=================
  1071. !do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1072. ! write(*,*) 'b)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1073. !enddo
  1074. data%State%MudSystem%ChokeOutletDensity= data%State%MudSystem%ChokeLine_Density%Last() ! used in MudSystem
  1075. do i=1, data%State%MudSystem%ChokeLine_MudOrKick%Length()
  1076. !write(*,555) i,'Choke_Volume(i), type=' ,ChokeLine_MudDischarged_Volume%Array(i),ChokeLine_MudOrKick%Array(i)
  1077. IF (IEEE_Is_NaN(data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Choke Volume-Plot')
  1078. IF (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Choke Volume= <=0' , data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i))
  1079. enddo
  1080. 555 FORMAT(I3,5X,A42,(f12.5),5X,I3)
  1081. !write(*,*) 'after sorting chokeline=='
  1082. !IF (ANY(ChokeLine_MudOrKick%Array(:) > 0)) THEN
  1083. ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
  1084. ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
  1085. ! enddo
  1086. !END IF
  1087. !do imud=1, Ann_MudDischarged_Volume%Length()
  1088. ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
  1089. !enddo
  1090. !
  1091. !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
  1092. ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
  1093. !write(*,*) '==after sorting chokeline'
  1094. end subroutine ChokeLineMud
  1095. subroutine Choke_GasSound ! is called in subroutine CirculationCodeSelect
  1096. use CSounds
  1097. !Use GeoElements_FluidModule
  1098. !USE CMudPropertiesVariables
  1099. USE MudSystemVARIABLES
  1100. use SimulationVariables !@@@
  1101. !use ConfigurationVariables
  1102. !USE CHOKEVARIABLES
  1103. !use ConfigurationVariables !@
  1104. !!use CDataDisplayConsole
  1105. !@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure
  1106. !!use CManifolds
  1107. !use ConfigurationVariables !@
  1108. !USE CHOKEVARIABLES
  1109. !use ConfigurationVariables !@
  1110. !!use CChokeManifoldVariables
  1111. use SimulationVariables
  1112. !use CTanks
  1113. !@use ConfigurationVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
  1114. !USE sROP_Other_Variables
  1115. !USE sROP_Variables
  1116. !use KickVARIABLESModule
  1117. !use PressureDisplayVARIABLESModule
  1118. !Use CError
  1119. !Use , intrinsic :: IEEE_Arithmetic
  1120. if ( data%State%MudSystem%ChokeLine_MudOrKick%Last() > 0 .AND. data%State%MudSystem%WellToChokeManifoldOpen == .true.) then
  1121. !WellToChokeManifoldWasOpen
  1122. data%State%MudSystem%SoundGasThroughChoke = 100 !100:chon dar adadhaye kamtar az 100 seda ghaat mishavad. eslah shavad.5.8.98 !int (min(ChokeLineFlowRate/2. , 100.))
  1123. print* , 'SoundGasThroughChoke1=', data%State%MudSystem%SoundGasThroughChoke
  1124. !WRITE (*,*) 'WellToChokeManifoldWasOpen-Sound', WellToChokeManifoldWasOpen
  1125. WRITE (*,*) 'WellToChokeManifoldOpen', data%State%MudSystem%WellToChokeManifoldOpen
  1126. else
  1127. data%State%MudSystem%SoundGasThroughChoke = 0
  1128. print* , 'SoundGasThroughChoke2=', data%State%MudSystem%SoundGasThroughChoke
  1129. endif
  1130. !print* , 'SoundGasThroughChoke3=', SoundGasThroughChoke
  1131. call SetSoundGasThroughChoke(data%State%MudSystem%SoundGasThroughChoke)
  1132. end subroutine Choke_GasSound