|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366 |
- subroutine TripOut_and_Pump ! is called in subroutine CirculationCodeSelect
-
- Use GeoElements_FluidModule
- USE CMudPropertiesVariables
- USE MudSystemVARIABLES
- USE Pump_VARIABLES
- !USE CHOKEVARIABLES
- !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
- !use CManifolds
- use CDrillWatchVariables
- !use CHOKEVARIABLES
- !use CChokeManifoldVariables
- use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
- USE sROP_Other_Variables
- USE sROP_Variables
- Use KickVariables
- Use CShoeVariables
-
- implicit none
-
- integer i,ii,AddLocation, iloc_edited, iloc_changedTo2
- Real(8) ExcessMudVolume_Remained,SavedDensityForOp
-
- !===========================================================WELL============================================================
- !===========================================================WELL============================================================
-
- StringFlowRate= MUD(2)%Q
- AnnulusFlowRate= MUD(2)%Q
- !write(*,*) 'MUD(2)%Q=====' , MUD(2)%Q
-
-
- write(*,*) 'Trip Out'
-
- ! write(*,*) 'check point 1=='
- !
- !
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !
- ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !write(*,*) '==check point 1'
-
- !========================Horizontal PIPE ENTRANCE=================
-
- if (ABS(SuctionDensity_Old - Suction_Density_MudSystem) >= DensityMixTol) then ! new mud is pumped
-
- call Hz_Density%AddToFirst (Suction_Density_MudSystem)
- call Hz_MudDischarged_Volume%AddToFirst (0.0d0)
- call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1))
- call Hz_Mud_Forehead_section%AddToFirst (1)
- call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
- call Hz_Mud_Backhead_section%AddToFirst (1)
- call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call Hz_MudOrKick%AddToFirst (0)
-
- SuctionDensity_Old= Suction_Density_MudSystem
- endif
-
- !========================Horizontal PIPE STRING=================
-
- Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
-
-
- total_add = total_add + ((StringFlowRate/60.0d0)*DeltaT_Mudline)
-
-
- if (ChokePanelStrokeResetSwitch == 1) then
- total_add= 0.
- endif
-
- !write(*,*) ' total decrease(add to HZ)=' , total_add
- !write(*,*) ' add to HZ=' , ((StringFlowRate/60.0d0)*DeltaT_Mudline)
-
-
-
- imud=0
- do while (imud < Hz_Mud_Forehead_X%Length())
- imud = imud + 1
-
- if (imud> 1) then
- Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1)
- Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1)
- endif
-
-
- DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) &
- / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud)))
- ! +1 for string , -1 for annulus
-
-
- Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* &
- Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3)
- Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
-
- if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then
- Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud)
- Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud))
-
- else
-
-
- isection= Hz_Mud_Backhead_section%Array(imud)+1
- Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection > 1) then ! (horizontal pipe exit)
- Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud)
- Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1)
- Hz_Mud_Forehead_section%Array(imud)= 1
-
- if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
- call RemoveHzMudArrays(imud)
- endif
-
- exit
- endif
-
- xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
-
- if (xx<= 1.0) then
- Hz_Mud_Forehead_section%Array(imud)= isection
- Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
- exit
- else
- Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
- isection= isection+ 1
-
- endif
-
- enddo
-
- endif
-
- enddo
- !========================Horizontal PIPE END=================
-
-
-
- !========================Utube1 Air Element Removing=================
-
- !if (UtubeMode1Activated== .true.) then ! StringUpdate == .true.
- !
- ! StringDensity_Old= St_Density%Array(2)
- !
- ! UtubeMode1Activated= .false.
- !endif
-
- !========================Utube1 Air Element Removing=================
-
-
- !========================Utube2 Removing from Annulus=================
-
- if (UtubeMode2Activated== .true.) then ! StringUpdate == .true.
- TotalAddedVolume=0.
-
- if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist
- call RemoveAnnulusMudArrays(Ann_MudOrKick%Length())
- endif
-
- UtubeMode2Activated= .false.
- endif
-
-
- !========================Utube2 Removing from Annulus End=================
-
- !========================New Pipe Filling=================
-
- if (AddedElementsToString > 0) then ! StringUpdate == .true.
-
- !NoPipeAdded= F_StringIntervalCounts - F_StringIntervalCountsOld
-
-
- NewPipeFilling=0
-
- IF (St_MudOrKick%First() == 104) then
- St_MudDischarged_Volume%Array(1) = St_MudDischarged_Volume%Array(1) + sum(PipeSection_VolumeCapacity(2:1+AddedElementsToString)) ! new pipe is filled by air
- else
- call St_Density%AddToFirst (0.d0)
- call St_MudDischarged_Volume%AddToFirst (sum(PipeSection_VolumeCapacity(2:1+AddedElementsToString)))
- call St_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(2))
- call St_Mud_Forehead_section%AddToFirst (2)
- call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(2))
- call St_Mud_Backhead_section%AddToFirst (2)
- call St_RemainedVolume_in_LastSection%AddToFirst (0.d0)
- call St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0)
- call St_MudOrKick%AddToFirst (104)
- endif
-
- endif
-
- !F_StringIntervalCountsOld= F_StringIntervalCounts
-
-
-
- if (NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe)
-
-
- LackageMudVolume= St_MudDischarged_Volume%Array(1) ! = Air element
-
-
- !write(*,*) 'LackageMudVolume=' , LackageMudVolume
-
-
-
- if (ABS(St_Density%Array(2) - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped
- call St_Density%AddTo (2,Hz_Density%Last())
- call St_MudDischarged_Volume%AddTo (2,0.d0)
- call St_Mud_Forehead_X%AddTo (2,Xstart_PipeSection(2))
- call St_Mud_Forehead_section%AddTo (2 , 2)
- call St_Mud_Backhead_X%AddTo (2,Xstart_PipeSection(2))
- call St_Mud_Backhead_section%AddTo (2 ,2)
- call St_RemainedVolume_in_LastSection%AddTo (2,0.d0)
- call St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0)
- call St_MudOrKick%AddTo (2,0)
-
- !StringDensity_Old= Hz_Density%Last()
- endif
-
-
- St_MudDischarged_Volume%Array(2)= St_MudDischarged_Volume%Array(2)+ min( ((StringFlowRate/60.0d0)*DeltaT_Mudline), LackageMudVolume) !(gal)
-
- St_MudDischarged_Volume%Array(1)= St_MudDischarged_Volume%Array(1)- min( ((StringFlowRate/60.0d0)*DeltaT_Mudline), LackageMudVolume) ! air(gal)
-
- !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:))
-
- LackageMudVolumeAfterFilling= St_MudDischarged_Volume%Array(1) ! last time it should be zero
-
-
-
- if (LackageMudVolumeAfterFilling == 0.) then
- NewPipeFilling= 1
- call RemoveStringMudArrays(1)
- St_Mud_Backhead_X%Array(1) = Xstart_PipeSection(2)
- St_Mud_Backhead_section%Array(1) = 2
- endif
-
- endif
-
- !========================New Pipe Filling End=================
-
-
- if (NewPipeFilling == 0) then
- StringFlowRate= 0.
- AnnulusFlowRate= 0.
- endif
-
- StringFlowRateFinal= StringFlowRate
- AnnulusFlowRateFinal= AnnulusFlowRate
-
-
- !========================STRING ENTRANCE=================
- if (StringFlowRateFinal > 0.0 .and. ABS(St_Density%First() - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped
- !if (ABS(StringDensity_Old - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped
- call St_Density%AddToFirst (Hz_Density%Last())
- call St_MudDischarged_Volume%AddToFirst (0.0d0)
- call St_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(2))
- call St_Mud_Forehead_section%AddToFirst (2)
- call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(2))
- call St_Mud_Backhead_section%AddToFirst (2)
- call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call St_MudOrKick%AddToFirst (0)
-
- !StringDensity_Old= Hz_Density%Last()
- endif
- St_MudDischarged_Volume%Array(1)= St_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
-
- !=============== save String Mud data===========
- StMudVolumeSum= 0.d0
- !St_MudSaved_Density= 0.d0
- St_Saved_MudDischarged_Volume= 0.d0
- !Saved_St_MudOrKick= 0
- !Ann_to_Choke_2mud= .false.
-
- do imud=1, St_MudDischarged_Volume%Length()
-
- StMudVolumeSum= StMudVolumeSum + St_MudDischarged_Volume%Array(imud)
-
- if ( StMudVolumeSum > sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) ) then
-
- !IF (St_MudOrKick%Array(imud) == 0) THEN
- St_MudSaved_Density = St_Density%Array(imud)
- St_Saved_MudDischarged_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts))
- !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
- ! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! Saved_St_MudOrKick= St_MudOrKick%Array (imud)
- ! St_KickSaved_Density= St_Density%Array(imud)
- !END IF
-
- do ii= imud + 1, St_MudDischarged_Volume%Length()
- !IF (St_MudOrKick%Array(ii) == 0) THEN
- St_MudSaved_Density = ((St_MudSaved_Density * St_Saved_MudDischarged_Volume) + (St_Density%Array(ii) * St_MudDischarged_Volume%Array(ii))) / (St_Saved_MudDischarged_Volume + St_MudDischarged_Volume%Array(ii))
- St_Saved_MudDischarged_Volume = St_Saved_MudDischarged_Volume + St_MudDischarged_Volume%Array(ii)
-
- !ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR
- ! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii)
- ! Saved_St_MudOrKick= St_MudOrKick%Array (ii)
- ! St_KickSaved_Density= St_Density%Array(ii)
- !END IF
- enddo
-
-
- !WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume
- exit ! exits do
-
- endif
-
- enddo
- St_Saved_MudDischarged_Volume_Final= St_Saved_MudDischarged_Volume
-
- IF (WellHeadIsOpen) MudVolume_InjectedToBH = St_Saved_MudDischarged_Volume_Final
-
- !======================================================================
-
-
- !========================STRING=================
-
- imud=0
- do while (imud < St_Mud_Forehead_X%Length())
- imud = imud + 1
-
- if (imud> 1) then
- St_Mud_Backhead_X%Array(imud)= St_Mud_Forehead_X%Array(imud-1)
- St_Mud_Backhead_section%Array(imud)= St_Mud_Forehead_section%Array(imud-1)
- endif
-
- DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) &
- / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud)))
- ! +1 for string , -1 for annulus
-
-
- St_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))- St_Mud_Backhead_X%Array(imud))* &
- Area_PipeSectionFt(St_Mud_Backhead_section%Array(imud)) !(ft^3)
- St_EmptyVolume_inBackheadLocation%Array(imud)= St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
- if ( St_MudDischarged_Volume%Array(imud) <= St_EmptyVolume_inBackheadLocation%Array(imud)) then
- St_Mud_Forehead_section%Array(imud)= St_Mud_Backhead_section%Array(imud)
- St_Mud_Forehead_X%Array(imud)= St_Mud_Backhead_X%Array(imud)+ DirectionCoef*(St_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(St_Mud_Backhead_section%Array(imud))
- ! 7.48 is for gal to ft^3
-
- else
-
- isection= St_Mud_Backhead_section%Array(imud)+1
- St_RemainedVolume_in_LastSection%Array(imud)= St_MudDischarged_Volume%Array(imud)- St_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection > F_StringIntervalCounts) then ! last pipe section(string exit)
- St_MudDischarged_Volume%Array(imud)= St_MudDischarged_Volume%Array(imud)- St_RemainedVolume_in_LastSection%Array(imud)
- St_Mud_Forehead_X%Array(imud)= Xend_PipeSection(F_StringIntervalCounts)
- St_Mud_Forehead_section%Array(imud)= F_StringIntervalCounts
-
- if (St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
- call RemoveStringMudArrays(imud)
- endif
-
- exit
- endif
-
- xx= St_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
-
- if (xx<= 1.0) then
- St_Mud_Forehead_section%Array(imud)= isection
- St_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
- exit
- else
- St_RemainedVolume_in_LastSection%Array(imud)= St_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
- isection= isection+ 1
-
-
- endif
-
- enddo
-
- endif
-
- enddo
- !========================STRING END=================
-
- !write(*,*) ' a before=='
- !
- ! do imud=1, Op_MudDischarged_Volume%Length()
- ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
- ! enddo
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !
- ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !write(*,*) '==== a before'
-
- iloc_changedTo2 = 0
-
- IF (Op_MudOrKick%Last() /= 0 .and. Op_MudOrKick%Last()==Ann_MudOrKick%First()) then
- iLoc=2 ! it may be 1,2,3 or more, all of them are kick
- iloc_changedTo2= 1
- endif
-
-
-
- iloc_edited= 0
- !write(*,*) sum(Op_MudDischarged_Volume%Array(:)) , ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) , Ann_MudDischarged_Volume%First() , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
- if (iloc==2 .and. sum(Op_MudDischarged_Volume%Array(:))+((AnnulusFlowRate/60.d0)*DeltaT_Mudline)+Ann_MudDischarged_Volume%First() < sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then
- iloc = 1
- iloc_edited = 1
- !write(*,*) 'hellooooooo'
- endif
-
-
- !write(*,*) 'ann-cap:' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1 :F_StringIntervalCounts+F_AnnulusIntervalCounts) )
-
-
- !write(*,*) 'iloc====' , iloc
- !MudVolume_InjectedToBH
-
-
- !=============================Add PumpFlowRate to Bottom Hole ==============================
- !if ( AnnulusFlowRate>0.0 ) then
- if ( MudVolume_InjectedToBH > 0.0 ) then
-
-
- if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the
- AddLocation= Op_Density%Length()-iloc+1+1 ! well, thus pumped mud should be placed above the kick
- else
- AddLocation= Op_Density%Length()+1
- endif
- !write(*,*) 'AddLocation====' , AddLocation
- if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0')
-
-
- if ( ABS(St_Density%Last() - Op_Density%Array(AddLocation-1)) >= DensityMixTol ) then
- !write(*,*) 'new pocket**'
- !write(*,*) 'St_Density%Last()=' , St_Density%Last()
- !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1)
-
-
- call Op_Density% AddTo (AddLocation,St_Density%Last())
- !call Op_MudDischarged_Volume%AddTo (AddLocation,((AnnulusFlowRate/60.d0)*DeltaT_Mudline))
- call Op_MudDischarged_Volume%AddTo (AddLocation,MudVolume_InjectedToBH)
- call Op_Mud_Forehead_X%AddTo (AddLocation,Xstart_OpSection(1))
- call Op_Mud_Forehead_section%AddTo (AddLocation,1)
- call Op_Mud_Backhead_X%AddTo (AddLocation,Xstart_OpSection(1))
- call Op_Mud_Backhead_section%AddTo (AddLocation,1)
- call Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0)
- call Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0)
- call Op_MudOrKick%AddTo (AddLocation,0)
- else
- !write(*,*) 'merge**'
- !write(*,*) 'density before=' , Op_Density%Array(AddLocation-1)
- !write(*,*) 'St_Density%Last() for mix=' , St_Density%Last()
-
- !Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)+St_Density%Last()*((AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((AnnulusFlowRate/60.d0)*DeltaT_Mudline))
- !Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)
-
- Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)+St_Density%Last()*MudVolume_InjectedToBH)/(Op_MudDischarged_Volume%Array(AddLocation-1)+MudVolume_InjectedToBH)
- Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + MudVolume_InjectedToBH
- !write(*,*) 'density after=' , Op_Density%Array(AddLocation-1)
-
- endif
-
- endif
- !=======================Add PumpFlowRate to Bottom Hole- End ==============================
-
- !write(*,*) 'pump added-before add to ann=='
- !
- ! do imud=1, Op_MudDischarged_Volume%Length()
- ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
- ! enddo
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !
- ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !
- !write(*,*) 'pump added====before add to ann'
-
-
- !=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick
- OpMudVolumeSum= 0.d0
- !Op_MudSaved_Density= 0.d0
- !Op_KickSaved_Density= 0.d0
- Op_Saved_MudDischarged_Volume= 0.d0
- Op_Kick_Saved_Volume= 0.d0
- Saved_Op_MudOrKick= 0
- Op_NeededVolume_ToFill= 0.d0
-
-
-
-
- do imud=1, Op_MudDischarged_Volume%Length()
-
- OpMudVolumeSum= OpMudVolumeSum + Op_MudDischarged_Volume%Array(imud)
-
- if ( OpMudVolumeSum > sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then !1st mode
-
- IF (Op_MudOrKick%Array(imud) == 0) THEN
- Op_MudSaved_Density = Op_Density%Array(imud)
- Op_Saved_MudDischarged_Volume = OpMudVolumeSum - sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
- ELSE
-
- Op_Kick_Saved_Volume = OpMudVolumeSum - sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
- Saved_Op_MudOrKick= Op_MudOrKick%Array (imud)
- Op_KickSaved_Density= Op_Density%Array(imud)
- iloc= 2
- iloc_changedTo2= 2
- END IF
-
- do ii= imud + 1, Op_MudDischarged_Volume%Length()
- IF (Op_MudOrKick%Array(ii) == 0) THEN
- Op_MudSaved_Density = ((Op_MudSaved_Density * Op_Saved_MudDischarged_Volume) + (Op_Density%Array(ii) * Op_MudDischarged_Volume%Array(ii))) / (Op_Saved_MudDischarged_Volume + Op_MudDischarged_Volume%Array(ii))
- Op_Saved_MudDischarged_Volume = Op_Saved_MudDischarged_Volume + Op_MudDischarged_Volume%Array(ii)
- ELSE
- Op_Kick_Saved_Volume = Op_Kick_Saved_Volume + Op_MudDischarged_Volume%Array(ii)
- Saved_Op_MudOrKick= Op_MudOrKick%Array (ii)
- Op_KickSaved_Density= Op_Density%Array(ii)
- iloc= 2
- iloc_changedTo2= 3
- END IF
- enddo
-
- exit ! exits do
-
- endif
-
- enddo
-
- if ( sum(Op_MudDischarged_Volume%Array(:)) < sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then !2nd & 3rd mode
-
- Op_NeededVolume_ToFill= sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - sum(Op_MudDischarged_Volume%Array(:))
- endif
-
-
- !
- !write(*,*) 'Op_NeededVolume_ToFill=' , Op_NeededVolume_ToFill
- !write(*,*) 'Op_Saved_MudDischarged_Volume=' , Op_Saved_MudDischarged_Volume
- !write(*,*) 'Op_Kick_Saved_Volume=' , Op_Kick_Saved_Volume
- !
- !write(*,*) 'op cap=' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
- !write(*,*) ' op sum mud=' , sum(Op_MudDischarged_Volume%Array(:))
-
-
-
-
-
- !======================================================================
-
-
-
-
- !========================Tripping Out- 1st & 3rd Mode====================
-
-
-
- if ( (Op_Kick_Saved_Volume > 0.0 .or. Op_Saved_MudDischarged_Volume> 0.0) .or. & ! 1st Mode-Pump flow is more than trip out so fluid Level in Annulus Increases
- (Op_NeededVolume_ToFill < ABS(DeltaVolumeAnnulusCapacity)) ) then !3rd Mode-fluid Level in Annulus Increases
-
-
- !if ( Op_Kick_Saved_Volume > 0.0 .or. Op_Saved_MudDischarged_Volume> 0.0 ) write(*,*) 'trip out 1st mode'
-
- if ( Op_NeededVolume_ToFill > 0.0 .and. Op_NeededVolume_ToFill < ABS(DeltaVolumeAnnulusCapacity) ) then
- ! write(*,*) 'trip out 3rd mode'
-
- NewVolume= 0.d0 ! for condition iloc=1
-
- SavedDensityForOp= Ann_Density%Array(1)
-
- ExcessMudVolume_Remained= Op_NeededVolume_ToFill
-
-
- imud=1
-
- Do
-
- if(Ann_MudDischarged_Volume%Array(imud) < ExcessMudVolume_Remained) then
- ExcessMudVolume_Remained= ExcessMudVolume_Remained- Ann_MudDischarged_Volume%Array(imud)
- call Ann_MudDischarged_Volume%Remove (imud)
- call Ann_Mud_Backhead_X%Remove (imud)
- call Ann_Mud_Backhead_section%Remove (imud)
- call Ann_Mud_Forehead_X%Remove (imud)
- call Ann_Mud_Forehead_section%Remove (imud)
- call Ann_Density%Remove (imud)
- call Ann_RemainedVolume_in_LastSection%Remove (imud)
- call Ann_EmptyVolume_inBackheadLocation%Remove (imud)
- call Ann_MudOrKick%Remove (imud)
-
- elseif(Ann_MudDischarged_Volume%Array(imud) > ExcessMudVolume_Remained) then
- Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- ExcessMudVolume_Remained
- exit
-
- else !(Ann_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained)
- call Ann_MudDischarged_Volume%Remove (imud)
- call Ann_Mud_Backhead_X%Remove (imud)
- call Ann_Mud_Backhead_section%Remove (imud)
- call Ann_Mud_Forehead_X%Remove (imud)
- call Ann_Mud_Forehead_section%Remove (imud)
- call Ann_Density%Remove (imud)
- call Ann_RemainedVolume_in_LastSection%Remove (imud)
- call Ann_EmptyVolume_inBackheadLocation%Remove (imud)
- call Ann_MudOrKick%Remove (imud)
- exit
-
- endif
-
- enddo
-
-
- !write(*,*) 'Op_NeededVolume_ToFill=' ,Op_NeededVolume_ToFill
- !write(*,*) 'ABS(DeltaVolumeAnnulusCapacity)=' ,ABS(DeltaVolumeAnnulusCapacity)
- !write(*,*) 'Op_MudOrKick%Last()=' ,Op_MudOrKick%Last()
- !write(*,*) 'iloc=' ,iloc
- !write(*,*) 'iloc_edited=' ,iloc_edited
-
-
- endif
-
-
- ! (AnnulusFlowRate/60.)*DeltaT_Mudline) - DeltaVolumeOp will be added to annulus
-
- !if (iLoc == 1) then
- MudSection= F_StringIntervalCounts+1
- BackheadX= Xstart_PipeSection(F_StringIntervalCounts+1)
- !elseif (iLoc == 2) then
- ! MudSection= Kick_Forehead_section
- ! BackheadX= Kick_Forehead_X
- !endif
-
- !========================ANNULUS ENTRANCE====================
- !if (KickMigration_2SideBit == .FALSE.) then
- ! if ( ABS(AnnulusSuctionDensity_Old - St_Density%Last()) >= DensityMixTol ) then ! new mud is pumped
- ! call Ann_Density%AddTo (iLoc,St_Density%Last())
- ! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0)
- ! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
- ! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
- ! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
- ! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
- ! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
- ! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
- ! call Ann_MudOrKick%AddTo (iLoc,0)
- ! call Ann_CuttingMud%AddTo (iLoc,0)
- !
- ! AnnulusSuctionDensity_Old= St_Density%Last()
- !
- ! MudIsChanged= .true.
- ! endif
- !
- ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((AnnulusFlowRate/60.0d0)*DeltaT_Mudline) - ((2-iloc)*ABS(DeltaVolumePipe)) !(gal)
- !
- !endif
-
-
-
-
- Ann_Mud_Backhead_section%Array(1)= MudSection !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe)
- Ann_Mud_Backhead_X%Array(1)= BackheadX
-
-
-
- !iloc=1 : (2-iloc)=1 normal
- !iloc=2 : (2-iloc)=0 kick influx or migration is in annulus
-
- !========================Same to Tripping In====================
-
- !write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume
-
-
- if (Op_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then !1st Mode
- write(*,*) 'Kick influx enters Annulus'
- call Ann_Density%AddToFirst (Op_KickSaved_Density)
- call Ann_MudDischarged_Volume%AddToFirst (Op_Kick_Saved_Volume)
- call Ann_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1))
- call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1)
- call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1))
- call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
- call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call Ann_MudOrKick%AddToFirst (Saved_Op_MudOrKick) !<<<<<<<<
- call Ann_CuttingMud%AddToFirst (0)
- elseif (Op_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() /= 0) then
- Ann_MudDischarged_Volume%Array(1)= Ann_MudDischarged_Volume%Array(1) + Op_Kick_Saved_Volume
- endif
-
-
-
- if ( Op_NeededVolume_ToFill > 0.0 .and. (Op_NeededVolume_ToFill < ABS(DeltaVolumeAnnulusCapacity)) .and. Op_MudOrKick%Last() == 0 .and. (iloc==2 .or. iloc_edited==1)) then !3rd Mode
- !write(*,*) 'checkpoint 0'
- !! for avoid kick separation -Op_MudOrKick%Last() == 0: because of pump
- NewVolume= ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) ! =volume that should be added to iloc=2 in Ann
- call RemoveOpMudArrays(Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann in %%1 section
- if ( Ann_MudDischarged_Volume%Array(1) > ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) ) then! 1st in Ann = kick ,, we expect: ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)= OpMudVolLast
- Ann_MudDischarged_Volume%Array(1)= Ann_MudDischarged_Volume%Array(1) - ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)
- Op_MudDischarged_Volume%Array(Op_Density%Length())= Op_MudDischarged_Volume%Array(Op_Density%Length())+ ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) ! kick
- else
- call RemoveAnnulusMudArrays(1) !kick is removed
- iloc= 1
- Op_MudDischarged_Volume%Array(Op_Density%Length())= Op_MudDischarged_Volume%Array(Op_Density%Length())+ ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)
- write(*,*) 'little expand'
- ! including a little expand
- endif
- endif
-
- if (Op_Saved_MudDischarged_Volume> 0.0) then !1st Mode
- NewDensity= Op_MudSaved_Density
- !write(*,*) 'iloc,...' , iloc,((AnnulusFlowRate/60.d0)*DeltaT_Mudline),Op_Saved_MudDischarged_Volume
- if (iloc==1) then
- !write(*,*) 'checkpoint 1'
- NewVolume= Op_Saved_MudDischarged_Volume
- elseif (real(((AnnulusFlowRate/60.d0)*DeltaT_Mudline)) - real(Op_Saved_MudDischarged_Volume) > 0.d0 ) then ! for avoid kick separation
- !write(*,*) 'checkpoint 2'
- NewVolume= ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) !- Op_Saved_MudDischarged_Volume
- call RemoveOpMudArrays(Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann
- if ( Ann_MudDischarged_Volume%Array(1) > (((AnnulusFlowRate/60.d0)*DeltaT_Mudline) - Op_Saved_MudDischarged_Volume) ) then! 1st in Ann = kick
- Ann_MudDischarged_Volume%Array(1)= Ann_MudDischarged_Volume%Array(1) - (((AnnulusFlowRate/60.d0)*DeltaT_Mudline) - Op_Saved_MudDischarged_Volume)
- Op_MudDischarged_Volume%Array(Op_Density%Length())= Op_MudDischarged_Volume%Array(Op_Density%Length())+ (((AnnulusFlowRate/60.d0)*DeltaT_Mudline) - Op_Saved_MudDischarged_Volume) !kick
- else
- call RemoveAnnulusMudArrays(1) !kick is removed
- iloc =1
- Op_MudDischarged_Volume%Array(Op_Density%Length())= Op_MudDischarged_Volume%Array(Op_Density%Length())+ (((AnnulusFlowRate/60.d0)*DeltaT_Mudline) - Op_Saved_MudDischarged_Volume)
- write(*,*) 'little expand'
-
- ! including a little expand
- endif
-
-
- else ! iloc==2 , ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) == Op_Saved_MudDischarged_Volume
- !write(*,*) 'checkpoint 3'
- NewVolume= Op_Saved_MudDischarged_Volume ! it is normal mode
- endif
-
-
- endif
-
- !write(*,*) 'NewVolume=' ,NewVolume
-
-
- if( Ann_Density%Length() == 1 .and. iloc ==2 ) then
-
- write(*,*) '***errorb****=='
-
- write(*,*) 'iloc_edited=' , iloc_edited
- write(*,*) 'iloc_changedTo2=' , iloc_changedTo2
-
- write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
-
- WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume
-
- do imud=1, Op_MudDischarged_Volume%Length()
- write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
- enddo
-
- do imud=1, Ann_MudDischarged_Volume%Length()
- write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- enddo
-
-
-
- write(*,*) '==***errorb****'
- endif
-
-
-
-
-
- if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(iLoc)-NewDensity)< DensityMixTol) & !%%1 section
- .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(iLoc)==1 .and. abs(Ann_Density%Array(iLoc)-NewDensity)< CuttingDensityMixTol) &
- .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(iLoc)==0 .and. Ann_MudDischarged_Volume%Array(iLoc) < 42.) ) then ! 1-Pockets are Merged
- !write(*,*) '%%1 section a)'
- Ann_Density%Array(iLoc)= (Ann_Density%Array(iLoc)*Ann_MudDischarged_Volume%Array(iLoc)+NewDensity*NewVolume)/(Ann_MudDischarged_Volume%Array(iLoc)+NewVolume)
- Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+NewVolume
- Ann_Mud_Forehead_X%Array(iLoc)= BackheadX
- Ann_Mud_Forehead_section%Array(iLoc)= MudSection
- Ann_Mud_Backhead_X%Array(iLoc)= BackheadX
- Ann_Mud_Backhead_section%Array(iLoc)= MudSection
- Ann_RemainedVolume_in_LastSection%Array(iLoc)= (0.0d0)
- Ann_EmptyVolume_inBackheadLocation%Array(iLoc)= (0.0d0)
- else ! 2-Merging conditions are not meeted, so new pocket
- !write(*,*) '%%1 section b)'
-
- call Ann_Density%AddTo (iLoc,NewDensity)
- call Ann_MudDischarged_Volume%AddTo (iLoc,NewVolume)
- call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
- call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
- call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
- call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
- call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
- call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
- call Ann_MudOrKick%AddTo (iLoc,0)
- call Ann_CuttingMud%AddTo (iLoc,0)
- !write(*,*) 'd) annLength=' , Ann_Density%Length()
-
- endif
-
-
-
-
- !========================Same to Tripping In - End====================
-
- !write(*,*) 'b)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
-
- !write(*,*) 'no======2'
- !
- ! do imud=1, Op_MudDischarged_Volume%Length()
- ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
- ! enddo
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !
- !
- ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !write(*,*) '2======no'
-
- !=============== save Ann Mud data to transfer to the ChokeLine enterance
- AnnMudVolumeSum= 0.d0
- !Ann_MudSaved_Density= 0.d0
- !Ann_KickSaved_Density= 0.d0
- Ann_Saved_MudDischarged_Volume= 0.d0
- Ann_Kick_Saved_Volume= 0.d0
- Saved_Ann_MudOrKick= 0
- Ann_to_Choke_2mud= .false.
-
-
-
-
- do imud=1, Ann_MudDischarged_Volume%Length()
-
- AnnMudVolumeSum= AnnMudVolumeSum + Ann_MudDischarged_Volume%Array(imud)
-
- if ( AnnMudVolumeSum > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then
-
- IF (Ann_MudOrKick%Array(imud) == 0) THEN
- Ann_MudSaved_Density = Ann_Density%Array(imud)
- Ann_Saved_MudDischarged_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ELSEIF (Ann_MudOrKick%Array(imud) > 0 .AND. Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR
- Ann_Kick_Saved_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- Saved_Ann_MudOrKick= Ann_MudOrKick%Array (imud)
- Ann_KickSaved_Density= Ann_Density%Array(imud)
- END IF
-
- do ii= imud + 1, Ann_MudDischarged_Volume%Length()
- IF (Ann_MudOrKick%Array(ii) == 0) THEN
- Ann_MudSaved_Density = ((Ann_MudSaved_Density * Ann_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * Ann_MudDischarged_Volume%Array(ii))) / (Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii))
- Ann_Saved_MudDischarged_Volume = Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii)
- Ann_to_Choke_2mud= .true.
- ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR
- Ann_Kick_Saved_Volume = Ann_Kick_Saved_Volume + Ann_MudDischarged_Volume%Array(ii)
- Saved_Ann_MudOrKick= Ann_MudOrKick%Array (ii)
- Ann_KickSaved_Density= Ann_Density%Array(ii)
- END IF
- enddo
-
- exit ! exits do
-
- endif
-
- enddo
-
- Ann_Saved_MudDischarged_Volume_Final= Ann_Saved_MudDischarged_Volume
- Ann_Kick_Saved_Volume_Final= Ann_Kick_Saved_Volume
- !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- !write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
-
- IF (WellHeadIsOpen) MudVolume_InjectedFromAnn = Ann_Saved_MudDischarged_Volume_Final-((Qlost/60.0d0)*DeltaT_Mudline)
- !NoGasPocket
- !write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume
-
- !======================================================================
-
-
- !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume
- !======================== Annulus ====================
-
- !MudIsChanged= .false.
-
- imud= 0
-
- do while (imud < Ann_Mud_Forehead_X%Length())
- imud = imud + 1
-
- if (imud> 1) then
- Ann_Mud_Backhead_X%Array(imud)= Ann_Mud_Forehead_X%Array(imud-1)
- Ann_Mud_Backhead_section%Array(imud)= Ann_Mud_Forehead_section%Array(imud-1)
- endif
-
- ! write(*,*) 'imud==' , imud
- !write(*,*) '***)Ann_Mud_Backhead_section(imud)= ' , Ann_Mud_Backhead_section%Array(imud), Ann_density%Array(imud)
-
-
- DirectionCoef= (Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Backhead_section%Array(imud))) &
- / ABS(Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Backhead_section%Array(imud)))
- ! +1 for string , -1 for annulus
-
-
- Ann_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Ann_Mud_Backhead_section%Array(imud))- Ann_Mud_Backhead_X%Array(imud))* &
- Area_PipeSectionFt(Ann_Mud_Backhead_section%Array(imud)) !(ft^3)
- Ann_EmptyVolume_inBackheadLocation%Array(imud)= Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
-
- if ( Ann_MudDischarged_Volume%Array(imud) <= Ann_EmptyVolume_inBackheadLocation%Array(imud)) then
- Ann_Mud_Forehead_section%Array(imud)= Ann_Mud_Backhead_section%Array(imud)
- Ann_Mud_Forehead_X%Array(imud)= Ann_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(Ann_Mud_Backhead_section%Array(imud))
- ! 7.48 is for gal to ft^3
-
- else
-
- isection= Ann_Mud_Backhead_section%Array(imud)+1
- Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection > NoPipeSections) then ! last pipe section(well exit)
- Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_RemainedVolume_in_LastSection%Array(imud)
- Ann_Mud_Forehead_X%Array(imud)= Xend_PipeSection(NoPipeSections)
- Ann_Mud_Forehead_section%Array(imud)= NoPipeSections
-
- if (Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
- call RemoveAnnulusMudArrays(imud)
- endif
-
- exit
- endif
-
- xx= Ann_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
-
- if (xx<= 1.0) then
- Ann_Mud_Forehead_section%Array(imud)= isection
- Ann_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection)
- exit
- else
- Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
- isection= isection+ 1
-
- endif
-
- enddo
-
- endif
-
- enddo
-
- if (Ann_Mud_Forehead_X%Last() < Xend_PipeSection(NoPipeSections)) then
- Ann_Mud_Forehead_X%Array(Ann_Mud_Forehead_X%Length()) = Xend_PipeSection(NoPipeSections) ! for error preventing
- endif
-
- !========================ANNULUS END=================
-
-
-
- !*************************************************************************************************************************
-
- !========================Tripping Out- 2nd Mode====================
-
-
- elseif ( Op_NeededVolume_ToFill > ABS(DeltaVolumeAnnulusCapacity) ) then !pump is off or Pump flow is less than trip out so fluid Level in Annulus decreases
- !write(*,*) 'trip out 2nd mode'
-
-
- SavedDensityForOp= Ann_Density%Array(1)
- !========================ANNULUS ENTRANCE====================
-
- ! <<< SIMILAR TO UTUBE 2 >>>
- if ( Ann_Density%Last() /= 0.0 ) then ! new mud is pumped
- call Ann_Density%Add (0.0d0)
- call Ann_MudDischarged_Volume%Add (0.0d0)
- call Ann_Mud_Forehead_X%Add (Xend_PipeSection(NoPipeSections))
- call Ann_Mud_Forehead_section%Add (NoPipeSections)
- call Ann_Mud_Backhead_X%Add (Xstart_PipeSection(NoPipeSections))
- call Ann_Mud_Backhead_section%Add (NoPipeSections)
- call Ann_RemainedVolume_in_LastSection%Add (0.0d0)
- call Ann_EmptyVolume_inBackheadLocation%Add (0.0d0)
- call Ann_MudOrKick%Add (104)
- call Ann_CuttingMud%Add (0)
-
- !AnnulusSuctionDensity_Old= Hz_Density%Last()
- endif
-
- Ann_Mud_Forehead_section%Array(Ann_Mud_Forehead_section%Length())= NoPipeSections !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe)
- Ann_Mud_Forehead_X%Array(Ann_Mud_Forehead_X%Length())= Xend_PipeSection(NoPipeSections)
-
-
- Ann_MudDischarged_Volume%Array(Ann_MudDischarged_Volume%Length())= Ann_MudDischarged_Volume%Last()+ (Op_NeededVolume_ToFill - ABS(DeltaVolumeAnnulusCapacity)) ! Op_NeededVolume_ToFill !ABS(DeltaVolumePipe) - ((AnnulusFlowRate/60.)*DeltaT_Mudline) !(gal)
-
- !===================================================================
-
-
-
- if ( (iloc==2 .or. iloc_edited==1) .and. Op_MudOrKick%Last()==0 ) then ! for avoid kick separation
- !write(*,*) 'here mud should be removed from Op last'
-
- if (abs(Ann_Density%Array(iloc)-Op_Density%Last())< DensityMixTol) then
-
- Ann_Density%Array(iLoc)= (Ann_Density%Array(iLoc)*Ann_MudDischarged_Volume%Array(iLoc)+Op_Density%Last()*Op_MudDischarged_Volume%Last())/(Ann_MudDischarged_Volume%Array(iLoc)+Op_MudDischarged_Volume%Last())
- Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+Op_MudDischarged_Volume%Last() ! OP_Last is mud(effect of pump added mud)
- Ann_Mud_Forehead_X%Array(iLoc)= BackheadX
- Ann_Mud_Forehead_section%Array(iLoc)= MudSection
- Ann_Mud_Backhead_X%Array(iLoc)= BackheadX
- Ann_Mud_Backhead_section%Array(iLoc)= MudSection
- Ann_RemainedVolume_in_LastSection%Array(iLoc)= (0.0d0)
- Ann_EmptyVolume_inBackheadLocation%Array(iLoc)= (0.0d0)
- !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- else ! 2-Merging conditions are not meeted, so new pocket
- call Ann_Density%AddTo (iLoc,Op_Density%Last())
- call Ann_MudDischarged_Volume%AddTo (iLoc,Op_MudDischarged_Volume%Last())
- call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX)
- call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection)
- call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX)
- call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection)
- call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0)
- call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0)
- call Ann_MudOrKick%AddTo (iLoc,0)
- call Ann_CuttingMud%AddTo (iLoc,0)
- endif
-
- Op_NeededVolume_ToFill= Op_NeededVolume_ToFill + Op_MudDischarged_Volume%Last() ! OP_Last is mud(effect of pump added mud)
-
- call RemoveOpMudArrays(Op_MudOrKick%Length())
-
-
- endif
- !===================================================================
-
-
- !=============== save Ann Mud data to transfer to the ChokeLine enterance
- !AnnMudVolumeSum= 0.d0
- !!Ann_MudSaved_Density= 0.d0
- !!Ann_KickSaved_Density= 0.d0
- Ann_Saved_MudDischarged_Volume= 0.d0
- Ann_Kick_Saved_Volume= 0.d0
- !Saved_Ann_MudOrKick= 0
- !Ann_to_Choke_2mud= .false.
-
-
-
-
- !do imud=1, Ann_MudDischarged_Volume%Length()
- !
- ! AnnMudVolumeSum= AnnMudVolumeSum + Ann_MudDischarged_Volume%Array(imud)
- !
- ! if ( AnnMudVolumeSum > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then
- !
- ! IF (Ann_MudOrKick%Array(imud) == 0) THEN
- ! Ann_MudSaved_Density = Ann_Density%Array(imud)
- ! Ann_Saved_MudDischarged_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! ELSEIF (Ann_MudOrKick%Array(imud) > 0 .AND. Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR
- ! Ann_Kick_Saved_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (imud)
- ! Ann_KickSaved_Density= Ann_Density%Array(imud)
- ! END IF
- !
- ! do ii= imud + 1, Ann_MudDischarged_Volume%Length()
- ! IF (Ann_MudOrKick%Array(ii) == 0) THEN
- ! Ann_MudSaved_Density = ((Ann_MudSaved_Density * Ann_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * Ann_MudDischarged_Volume%Array(ii))) / (Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii))
- ! Ann_Saved_MudDischarged_Volume = Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii)
- ! Ann_to_Choke_2mud= .true.
- ! ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR
- ! Ann_Kick_Saved_Volume = Ann_Kick_Saved_Volume + Ann_MudDischarged_Volume%Array(ii)
- ! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (ii)
- ! Ann_KickSaved_Density= Ann_Density%Array(ii)
- ! END IF
- ! enddo
- !
- ! exit ! exits do
- !
- ! endif
- !
- !enddo
-
-
- ! write(*,*) 'check point 2=='
- !
- !
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !
- ! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- ! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !write(*,*) '==check point 2'
-
-
-
-
-
- Ann_Saved_MudDischarged_Volume_Final= Ann_Saved_MudDischarged_Volume
- Ann_Kick_Saved_Volume_Final= Ann_Kick_Saved_Volume
- !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- !write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
-
- !write(*,*) 'Ann_Saved_MudDischarged_Volume_Final=' , Ann_Saved_MudDischarged_Volume_Final
-
-
-
- IF (WellHeadIsOpen) MudVolume_InjectedFromAnn = Ann_Saved_MudDischarged_Volume_Final-((Qlost/60.0d0)*DeltaT_Mudline)
- !! NoGasPocket > 0 .AND.
-
- !write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume
-
-
- !======================================================================
-
- !========================ANNULUS====================
- ! <<< SIMILAR TO UTUBE 2 >>>
-
- !write(*,*) Ann_MudOrKick%Last(), 'DeltaVolumePipe , after volume=' ,ABS(DeltaVolumePipe), Ann_MudDischarged_Volume%Last()
- imud= Ann_Mud_Forehead_X%Length() + 1
-
- do while (imud > 1)
- imud = imud - 1
-
- if (imud< Ann_Mud_Forehead_X%Length()) then
- Ann_Mud_Forehead_X%Array(imud)= Ann_Mud_Backhead_X%Array(imud+1)
- Ann_Mud_Forehead_section%Array(imud)= Ann_Mud_Backhead_section%Array(imud+1)
- endif
-
-
- ! <<< Fracture Shoe Lost
- IF ( ShoeLost .and. ShoeDepth < Ann_Mud_Backhead_X%Array(imud) .and. ShoeDepth >= Ann_Mud_Forehead_X%Array(imud) ) then
- !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline)
- Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)-((Qlost/60.0d0)*DeltaT_Mudline) !(gal)
- if (Ann_MudDischarged_Volume%Array(imud) < 0.0) then
- !write(*,*) 'mud is removed by shoe lost, imud=' , imud
- call RemoveAnnulusMudArrays(imud)
- imud= imud-1
- cycle
- endif
- LostInTripOutIsDone= .true.
- ENDIF
- ! Fracture Shoe Lost >>>
-
-
-
-
-
-
-
-
- !write(*,*) 'a)imud,Ann_Mud_Forehead_section=',imud,Ann_Mud_Forehead_section%Array(imud)
-
- DirectionCoef= (Xend_PipeSection(Ann_Mud_Forehead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud))) &
- / ABS(Xend_PipeSection(Ann_Mud_Forehead_section%Array(imud))-Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud)))
- ! +1 for string , -1 for annulus
-
- !write(*,*) 'b)imud,Forehead_X,Xstart_PipeSection=',imud,Ann_Mud_Forehead_X%Array(imud),Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud))
-
- Ann_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Ann_Mud_Forehead_X%Array(imud)- Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud)))* &
- Area_PipeSectionFt(Ann_Mud_Forehead_section%Array(imud)) !(ft^3)
- Ann_EmptyVolume_inBackheadLocation%Array(imud)= Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
- if ( Ann_MudDischarged_Volume%Array(imud) <= Ann_EmptyVolume_inBackheadLocation%Array(imud)) then
- Ann_Mud_Backhead_section%Array(imud)= Ann_Mud_Forehead_section%Array(imud)
- Ann_Mud_Backhead_X%Array(imud)= Ann_Mud_Forehead_X%Array(imud)- DirectionCoef*(Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_PipeSectionFt(Ann_Mud_Forehead_section%Array(imud))
- ! 7.48051948 is for gal to ft^3
- else
- isection= Ann_Mud_Forehead_section%Array(imud)-1
- Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection < F_StringIntervalCounts+1) then ! last pipe section(well exit) F_StringIntervalCounts+1 is the first section in Annulus
- Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)- Ann_RemainedVolume_in_LastSection%Array(imud)
- Ann_Mud_Backhead_X%Array(imud)= Xstart_PipeSection(F_StringIntervalCounts+1)
- Ann_Mud_Backhead_section%Array(imud)= F_StringIntervalCounts+1
-
- if (Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
- call RemoveAnnulusMudArrays(imud)
- endif
-
- exit
- endif
-
- xx= Ann_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal)
-
- if (xx<= 1.0) then
- Ann_Mud_Backhead_section%Array(imud)= isection
- Ann_Mud_Backhead_X%Array(imud)= (xx * (Xstart_PipeSection(isection)- Xend_PipeSection(isection)))+ Xend_PipeSection(isection)
- exit
- else
- Ann_RemainedVolume_in_LastSection%Array(imud)= Ann_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection)
- isection= isection- 1
-
-
- endif
-
- enddo
-
- endif
-
- enddo
- !========================ANNULUS END=================
-
- endif ! end of 1st &3rd & 2nd Mode
-
-
- !*************************************************************************************************************************
-
-
-
-
-
-
- !======================== Bottom Hole Entrance ==========================
- !if (iloc == 1) then
- if ( Op_NeededVolume_ToFill > 0.0 ) then ! it is needed for 2nd & 3rd mode
- !write(*,*) 'op add for 2nd & 3rd mode done'
-
-
-
- if ( ABS(Op_Density%Last() - SavedDensityForOp ) >= DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Last()>42.) ) then ! 1-Merging conditions are not meeted, so new pocket
-
- call Op_Density%Add (SavedDensityForOp)
- call Op_MudDischarged_Volume%Add (Op_NeededVolume_ToFill)
- call Op_Mud_Forehead_X%Add (0.0d0)
- call Op_Mud_Forehead_section%Add (1)
- call Op_Mud_Backhead_X%Add (0.0d0)
- call Op_Mud_Backhead_section%Add (1)
- call Op_RemainedVolume_in_LastSection%Add (0.0d0)
- call Op_EmptyVolume_inBackheadLocation%Add (0.0d0)
- call Op_MudOrKick%Add (Ann_MudOrKick%Array(1))
- else ! 2-Pockets are Merged
-
- Op_Density%Array (Op_Density%Length())= (SavedDensityForOp*Op_NeededVolume_ToFill+Op_Density%Last()*Op_MudDischarged_Volume%Last())/(Op_MudDischarged_Volume%Last()+Op_NeededVolume_ToFill)
- Op_MudDischarged_Volume%Array (Op_Density%Length())= Op_MudDischarged_Volume%Array (Op_Density%Length()) + Op_NeededVolume_ToFill
- Op_RemainedVolume_in_LastSection%Array (Op_Density%Length())= 0.0
- Op_EmptyVolume_inBackheadLocation%Array (Op_Density%Length())= 0.0
-
- endif
-
- endif
-
-
-
-
- !============================= Bottom Hole ==============================
-
- imud=0
- do while (imud < Op_Mud_Forehead_X%Length())
- imud = imud + 1
-
- if (imud> 1) then
- Op_Mud_Backhead_X%Array(imud)= Op_Mud_Forehead_X%Array(imud-1)
- Op_Mud_Backhead_section%Array(imud)= Op_Mud_Forehead_section%Array(imud-1)
- endif
-
- DirectionCoef= (Xend_OpSection(Op_Mud_Backhead_section%Array(imud))-Xstart_OpSection(Op_Mud_Backhead_section%Array(imud))) &
- / ABS(Xend_OpSection(Op_Mud_Backhead_section%Array(imud))-Xstart_OpSection(Op_Mud_Backhead_section%Array(imud)))
- ! +1 for string , -1 for annulus
-
-
-
- Op_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_OpSection(Op_Mud_Backhead_section%Array(imud))- Op_Mud_Backhead_X%Array(imud))* &
- Area_OpSectionFt(Op_Mud_Backhead_section%Array(imud)) !(ft^3)
- Op_EmptyVolume_inBackheadLocation%Array(imud)= Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
-
- if ( Op_MudDischarged_Volume%Array(imud) <= Op_EmptyVolume_inBackheadLocation%Array(imud)) then
- Op_Mud_Forehead_section%Array(imud)= Op_Mud_Backhead_section%Array(imud)
- Op_Mud_Forehead_X%Array(imud)= Op_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_OpSectionFt(Op_Mud_Backhead_section%Array(imud))
- ! 7.48051948 is for gal to ft^3
-
- else
-
- isection= Op_Mud_Backhead_section%Array(imud)+1
- Op_RemainedVolume_in_LastSection%Array(imud)= Op_MudDischarged_Volume%Array(imud)- Op_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
- !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space
- Op_MudDischarged_Volume%Array(imud)= Op_MudDischarged_Volume%Array(imud)- Op_RemainedVolume_in_LastSection%Array(imud)
- Op_Mud_Forehead_X%Array(imud)= Xend_OpSection(F_BottomHoleIntervalCounts)
- Op_Mud_Forehead_section%Array(imud)= F_BottomHoleIntervalCounts
-
- if (Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
- call Op_MudDischarged_Volume%Remove (imud)
- call Op_Mud_Backhead_X%Remove (imud)
- call Op_Mud_Backhead_section%Remove (imud)
- call Op_Mud_Forehead_X%Remove (imud)
- call Op_Mud_Forehead_section%Remove (imud)
- call Op_Density%Remove (imud)
- call Op_RemainedVolume_in_LastSection%Remove (imud)
- call Op_EmptyVolume_inBackheadLocation%Remove (imud)
- call Op_MudOrKick%Remove (imud)
-
- endif
-
- exit
- endif
-
- xx= Op_RemainedVolume_in_LastSection%Array(imud)/ OpSection_VolumeCapacity(isection) !(gal)
-
- if (xx<= 1.0) then
- Op_Mud_Forehead_section%Array(imud)= isection
- Op_Mud_Forehead_X%Array(imud)= (xx * (Xend_OpSection(isection)- Xstart_OpSection(isection)))+ Xstart_OpSection(isection)
- exit
- else
- Op_RemainedVolume_in_LastSection%Array(imud)= Op_RemainedVolume_in_LastSection%Array(imud)- OpSection_VolumeCapacity(isection)
- isection= isection+ 1
-
- endif
-
- enddo
-
- endif
-
- enddo
-
-
-
- !========================Bottom Hole END=================
- ! write(*,*) 'after sorting=='
- !!!
- ! do imud=1, Op_MudDischarged_Volume%Length()
- ! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud)
- ! enddo
- !
- ! do imud=1, Ann_MudDischarged_Volume%Length()
- ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud)
- ! enddo
- !!!
- !! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- !! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:))
- !!!
- !!!
- !write(*,*) '==after sorting'
-
- !=========================================================
-
-
- total_injected = total_injected + MudVolume_InjectedFromAnn
-
- if (ChokePanelStrokeResetSwitch == 1) then
- total_injected= 0.
- endif
- !write(*,*) ' MudVolume_InjectedFromAnn =' , MudVolume_InjectedFromAnn
-
- !write(*,*) ' total injected-tripout =' , total_injected
- !write(*,*) ' injected-tripout =' , MudVolume_InjectedFromAnn
-
-
-
-
-
-
-
- end subroutine TripOut_and_Pump
-
-
-
|