subroutine TripOut_and_Pump ! is called in subroutine CirculationCodeSelect Use GeoElements_FluidModule USE CMudPropertiesVariables USE MudSystemVARIABLES USE Pumps_VARIABLES !USE CHOKEVARIABLES !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure !use CManifolds use CDrillWatchVariables !use CHOKEVARIABLES !use CChokeManifoldVariables !use CTanksVariables, TripTankVolume2 => DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables Use KickVariables Use CShoeVariables use CError implicit none integer i,ii,AddLocation, iloc_edited, iloc_changedTo2 Real(8) ExcessMudVolume_Remained,SavedDensityForOp !===========================================================WELL============================================================ !===========================================================WELL============================================================ MudSystemDotStringFlowRate= MUD(2)%Q MudSystemDotAnnulusFlowRate= 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) >= MudSystemDotDensityMixTol) then ! new mud is pumped call MudSystemDotHz_Density%AddToFirst (Suction_Density_MudSystem) call MudSystemDotHz_MudDischarged_Volume%AddToFirst (0.0d0) call MudSystemDotHz_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(1)) call Hz_Mud_Forehead_section%AddToFirst (1) call MudSystemDotHz_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(1)) call Hz_Mud_Backhead_section%AddToFirst (1) call MudSystemDotHz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) call MudSystemDotHz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) call Hz_MudOrKick%AddToFirst (0) SuctionDensity_Old= Suction_Density_MudSystem endif !========================Horizontal PIPE STRING================= MudSystemDotHz_MudDischarged_Volume%Array(1)= MudSystemDotHz_MudDischarged_Volume%Array(1)+ ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) !(gal) MudSystemDottotal_add = MudSystemDottotal_add + ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then MudSystemDottotal_add= 0. endif !write(*,*) ' total decrease(add to HZ)=' , total_add !write(*,*) ' add to HZ=' , ((StringFlowRate/60.0d0)*DeltaT_Mudline) MudSystemDotimud=0 do while (MudSystemDotimud < MudSystemDotHz_Mud_Forehead_X%Length()) MudSystemDotimud = MudSystemDotimud + 1 if (MudSystemDotimud> 1) then MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud-1) Hz_Mud_Backhead_section%Array(MudSystemDotimud)= Hz_Mud_Forehead_section%Array(MudSystemDotimud-1) endif MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))) & / ABS(MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))) ! +1 for string , -1 for annulus MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(Hz_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud))* & MudSystemDotArea_PipeSectionFt(Hz_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3) MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal if ( MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then Hz_Mud_Forehead_section%Array(MudSystemDotimud)= Hz_Mud_Backhead_section%Array(MudSystemDotimud) MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotHz_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Hz_Mud_Backhead_section%Array(MudSystemDotimud)) else MudSystemDotisection= Hz_Mud_Backhead_section%Array(MudSystemDotimud)+1 MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotHz_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud) do if (MudSystemDotisection > 1) then ! (horizontal pipe exit) MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud) MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(1) Hz_Mud_Forehead_section%Array(MudSystemDotimud)= 1 if (MudSystemDotHz_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string call RemoveHzMudArrays(MudSystemDotimud) endif exit endif MudSystemDotxx= MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal) if (MudSystemDotxx<= 1.0) then Hz_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection MudSystemDotHz_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection) exit else MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotHz_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) MudSystemDotisection= MudSystemDotisection+ 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 (MudSystemDotUtubeMode2Activated== .true.) then ! StringUpdate == .true. MudSystemDotTotalAddedVolume=0. if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist call RemoveAnnulusMudArrays(Ann_MudOrKick%Length()) endif MudSystemDotUtubeMode2Activated= .false. endif !========================Utube2 Removing from Annulus End================= !========================New Pipe Filling================= if (MudSystemDotAddedElementsToString > 0) then ! StringUpdate == .true. !NoPipeAdded= F_StringIntervalCounts - F_StringIntervalCountsOld MudSystemDotNewPipeFilling=0 IF (St_MudOrKick%First() == 104) then MudSystemDotSt_MudDischarged_Volume%Array(1) = MudSystemDotSt_MudDischarged_Volume%Array(1) + sum(MudSystemDotPipeSection_VolumeCapacity(2:1+MudSystemDotAddedElementsToString)) ! new pipe is filled by air else call St_Density%AddToFirst (0.d0) call MudSystemDotSt_MudDischarged_Volume%AddToFirst (sum(MudSystemDotPipeSection_VolumeCapacity(2:1+MudSystemDotAddedElementsToString))) call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(2)) call St_Mud_Forehead_section%AddToFirst (2) call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2)) call St_Mud_Backhead_section%AddToFirst (2) call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.d0) call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.d0) call St_MudOrKick%AddToFirst (104) endif endif !F_StringIntervalCountsOld= F_StringIntervalCounts if (MudSystemDotNewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe) MudSystemDotLackageMudVolume= MudSystemDotSt_MudDischarged_Volume%Array(1) ! = Air element !write(*,*) 'LackageMudVolume=' , LackageMudVolume if (ABS(St_Density%Array(2) - MudSystemDotHz_Density%Last()) >= MudSystemDotDensityMixTol) then ! new mud is pumped call St_Density%AddTo (2,MudSystemDotHz_Density%Last()) call MudSystemDotSt_MudDischarged_Volume%AddTo (2,0.d0) call MudSystemDotSt_Mud_Forehead_X%AddTo (2,MudSystemDotXstart_PipeSection(2)) call St_Mud_Forehead_section%AddTo (2 , 2) call MudSystemDotSt_Mud_Backhead_X%AddTo (2,MudSystemDotXstart_PipeSection(2)) call St_Mud_Backhead_section%AddTo (2 ,2) call MudSystemDotSt_RemainedVolume_in_LastSection%AddTo (2,0.d0) call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddTo (2,0.d0) call St_MudOrKick%AddTo (2,0) !StringDensity_Old= Hz_Density%Last() endif MudSystemDotSt_MudDischarged_Volume%Array(2)= MudSystemDotSt_MudDischarged_Volume%Array(2)+ min( ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline), MudSystemDotLackageMudVolume) !(gal) MudSystemDotSt_MudDischarged_Volume%Array(1)= MudSystemDotSt_MudDischarged_Volume%Array(1)- min( ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline), MudSystemDotLackageMudVolume) ! air(gal) !LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:)) MudSystemDotLackageMudVolumeAfterFilling= MudSystemDotSt_MudDischarged_Volume%Array(1) ! last time it should be zero if (MudSystemDotLackageMudVolumeAfterFilling == 0.) then MudSystemDotNewPipeFilling= 1 call RemoveStringMudArrays(1) MudSystemDotSt_Mud_Backhead_X%Array(1) = MudSystemDotXstart_PipeSection(2) St_Mud_Backhead_section%Array(1) = 2 endif endif !========================New Pipe Filling End================= if (MudSystemDotNewPipeFilling == 0) then MudSystemDotStringFlowRate= 0. MudSystemDotAnnulusFlowRate= 0. endif MudSystemDotStringFlowRateFinal= MudSystemDotStringFlowRate MudSystemDotAnnulusFlowRateFinal= MudSystemDotAnnulusFlowRate !========================STRING ENTRANCE================= if (MudSystemDotStringFlowRateFinal > 0.0 .and. ABS(St_Density%First() - MudSystemDotHz_Density%Last()) >= MudSystemDotDensityMixTol) then ! new mud is pumped !if (ABS(StringDensity_Old - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped call St_Density%AddToFirst (MudSystemDotHz_Density%Last()) call MudSystemDotSt_MudDischarged_Volume%AddToFirst (0.0d0) call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(2)) call St_Mud_Forehead_section%AddToFirst (2) call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2)) call St_Mud_Backhead_section%AddToFirst (2) call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.0d0) call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) call St_MudOrKick%AddToFirst (0) !StringDensity_Old= Hz_Density%Last() endif MudSystemDotSt_MudDischarged_Volume%Array(1)= MudSystemDotSt_MudDischarged_Volume%Array(1)+ ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) !(gal) !=============== save String Mud data=========== MudSystemDotStMudVolumeSum= 0.d0 !St_MudSaved_Density= 0.d0 MudSystemDotSt_Saved_MudDischarged_Volume= 0.d0 !Saved_St_MudOrKick= 0 !Ann_to_Choke_2mud= .false. do MudSystemDotimud=1, MudSystemDotSt_MudDischarged_Volume%Length() MudSystemDotStMudVolumeSum= MudSystemDotStMudVolumeSum + MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) if ( MudSystemDotStMudVolumeSum > sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts)) ) then !IF (St_MudOrKick%Array(imud) == 0) THEN MudSystemDotSt_MudSaved_Density = St_Density%Array(MudSystemDotimud) MudSystemDotSt_Saved_MudDischarged_Volume = MudSystemDotStMudVolumeSum - sum(MudSystemDotPipeSection_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= MudSystemDotimud + 1, MudSystemDotSt_MudDischarged_Volume%Length() !IF (St_MudOrKick%Array(ii) == 0) THEN MudSystemDotSt_MudSaved_Density = ((MudSystemDotSt_MudSaved_Density * MudSystemDotSt_Saved_MudDischarged_Volume) + (St_Density%Array(ii) * MudSystemDotSt_MudDischarged_Volume%Array(ii))) / (MudSystemDotSt_Saved_MudDischarged_Volume + MudSystemDotSt_MudDischarged_Volume%Array(ii)) MudSystemDotSt_Saved_MudDischarged_Volume = MudSystemDotSt_Saved_MudDischarged_Volume + MudSystemDotSt_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 MudSystemDotSt_Saved_MudDischarged_Volume_Final= MudSystemDotSt_Saved_MudDischarged_Volume IF (WellHeadIsOpen) MudSystemDotMudVolume_InjectedToBH = MudSystemDotSt_Saved_MudDischarged_Volume_Final !====================================================================== !========================STRING================= MudSystemDotimud=0 do while (MudSystemDotimud < MudSystemDotSt_Mud_Forehead_X%Length()) MudSystemDotimud = MudSystemDotimud + 1 if (MudSystemDotimud> 1) then MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud-1) St_Mud_Backhead_section%Array(MudSystemDotimud)= St_Mud_Forehead_section%Array(MudSystemDotimud-1) endif MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))) & / ABS(MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))) ! +1 for string , -1 for annulus MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud))* & MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3) MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal if ( MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then St_Mud_Forehead_section%Array(MudSystemDotimud)= St_Mud_Backhead_section%Array(MudSystemDotimud) MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud)) ! 7.48 is for gal to ft^3 else MudSystemDotisection= St_Mud_Backhead_section%Array(MudSystemDotimud)+1 MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud) do if (MudSystemDotisection > F_StringIntervalCounts) then ! last pipe section(string exit) MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud) MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(F_StringIntervalCounts) St_Mud_Forehead_section%Array(MudSystemDotimud)= F_StringIntervalCounts if (MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string call RemoveStringMudArrays(MudSystemDotimud) endif exit endif MudSystemDotxx= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal) if (MudSystemDotxx<= 1.0) then St_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection) exit else MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) MudSystemDotisection= MudSystemDotisection+ 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 MudSystemDotiLoc=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 (MudSystemDotiLoc==2 .and. sum(MudSystemDotOp_MudDischarged_Volume%Array(:))+((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline)+MudSystemDotAnn_MudDischarged_Volume%First() < sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then MudSystemDotiLoc = 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 ( MudSystemDotMudVolume_InjectedToBH > 0.0 ) then if (KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the AddLocation= MudSystemDotOp_Density%Length()-MudSystemDotiLoc+1+1 ! well, thus pumped mud should be placed above the kick else AddLocation= MudSystemDotOp_Density%Length()+1 endif !write(*,*) 'AddLocation====' , AddLocation if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0') if ( ABS(St_Density%Last() - MudSystemDotOp_Density%Array(AddLocation-1)) >= MudSystemDotDensityMixTol ) then !write(*,*) 'new pocket**' !write(*,*) 'St_Density%Last()=' , St_Density%Last() !write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1) call MudSystemDotOp_Density% AddTo (AddLocation,St_Density%Last()) !call Op_MudDischarged_Volume%AddTo (AddLocation,((AnnulusFlowRate/60.d0)*DeltaT_Mudline)) call MudSystemDotOp_MudDischarged_Volume%AddTo (AddLocation,MudSystemDotMudVolume_InjectedToBH) call MudSystemDotOp_Mud_Forehead_X%AddTo (AddLocation,MudSystemDotXstart_OpSection(1)) call Op_Mud_Forehead_section%AddTo (AddLocation,1) call MudSystemDotOp_Mud_Backhead_X%AddTo (AddLocation,MudSystemDotXstart_OpSection(1)) call Op_Mud_Backhead_section%AddTo (AddLocation,1) call MudSystemDotOp_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0) call MudSystemDotOp_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) MudSystemDotOp_Density%Array(AddLocation-1)= (MudSystemDotOp_Density%Array(AddLocation-1)*MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)+St_Density%Last()*MudSystemDotMudVolume_InjectedToBH)/(MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)+MudSystemDotMudVolume_InjectedToBH) MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1)= MudSystemDotOp_MudDischarged_Volume%Array(AddLocation-1) + MudSystemDotMudVolume_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 MudSystemDotOpMudVolumeSum= 0.d0 !Op_MudSaved_Density= 0.d0 !Op_KickSaved_Density= 0.d0 MudSystemDotOp_Saved_MudDischarged_Volume= 0.d0 MudSystemDotOp_Kick_Saved_Volume= 0.d0 MudSystemDotSaved_Op_MudOrKick= 0 MudSystemDotOp_NeededVolume_ToFill= 0.d0 do MudSystemDotimud=1, MudSystemDotOp_MudDischarged_Volume%Length() MudSystemDotOpMudVolumeSum= MudSystemDotOpMudVolumeSum + MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud) if ( MudSystemDotOpMudVolumeSum > sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then !1st mode IF (Op_MudOrKick%Array(MudSystemDotimud) == 0) THEN MudSystemDotOp_MudSaved_Density = MudSystemDotOp_Density%Array(MudSystemDotimud) MudSystemDotOp_Saved_MudDischarged_Volume = MudSystemDotOpMudVolumeSum - sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ELSE MudSystemDotOp_Kick_Saved_Volume = MudSystemDotOpMudVolumeSum - sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) MudSystemDotSaved_Op_MudOrKick= Op_MudOrKick%Array (MudSystemDotimud) MudSystemDotOp_KickSaved_Density= MudSystemDotOp_Density%Array(MudSystemDotimud) MudSystemDotiLoc= 2 iloc_changedTo2= 2 END IF do ii= MudSystemDotimud + 1, MudSystemDotOp_MudDischarged_Volume%Length() IF (Op_MudOrKick%Array(ii) == 0) THEN MudSystemDotOp_MudSaved_Density = ((MudSystemDotOp_MudSaved_Density * MudSystemDotOp_Saved_MudDischarged_Volume) + (MudSystemDotOp_Density%Array(ii) * MudSystemDotOp_MudDischarged_Volume%Array(ii))) / (MudSystemDotOp_Saved_MudDischarged_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii)) MudSystemDotOp_Saved_MudDischarged_Volume = MudSystemDotOp_Saved_MudDischarged_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii) ELSE MudSystemDotOp_Kick_Saved_Volume = MudSystemDotOp_Kick_Saved_Volume + MudSystemDotOp_MudDischarged_Volume%Array(ii) MudSystemDotSaved_Op_MudOrKick= Op_MudOrKick%Array (ii) MudSystemDotOp_KickSaved_Density= MudSystemDotOp_Density%Array(ii) MudSystemDotiLoc= 2 iloc_changedTo2= 3 END IF enddo exit ! exits do endif enddo if ( sum(MudSystemDotOp_MudDischarged_Volume%Array(:)) < sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then !2nd & 3rd mode MudSystemDotOp_NeededVolume_ToFill= sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - sum(MudSystemDotOp_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 ( (MudSystemDotOp_Kick_Saved_Volume > 0.0 .or. MudSystemDotOp_Saved_MudDischarged_Volume> 0.0) .or. & ! 1st Mode-Pump flow is more than trip out so fluid Level in Annulus Increases (MudSystemDotOp_NeededVolume_ToFill < ABS(MudSystemDotDeltaVolumeAnnulusCapacity)) ) 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 ( MudSystemDotOp_NeededVolume_ToFill > 0.0 .and. MudSystemDotOp_NeededVolume_ToFill < ABS(MudSystemDotDeltaVolumeAnnulusCapacity) ) then ! write(*,*) 'trip out 3rd mode' MudSystemDotNewVolume= 0.d0 ! for condition iloc=1 SavedDensityForOp= Ann_Density%Array(1) ExcessMudVolume_Remained= MudSystemDotOp_NeededVolume_ToFill MudSystemDotimud=1 Do if(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) < ExcessMudVolume_Remained) then ExcessMudVolume_Remained= ExcessMudVolume_Remained- MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) call MudSystemDotAnn_MudDischarged_Volume%Remove (MudSystemDotimud) call Ann_Mud_Backhead_X%Remove (MudSystemDotimud) call Ann_Mud_Backhead_section%Remove (MudSystemDotimud) call Ann_Mud_Forehead_X%Remove (MudSystemDotimud) call Ann_Mud_Forehead_section%Remove (MudSystemDotimud) call Ann_Density%Remove (MudSystemDotimud) call Ann_RemainedVolume_in_LastSection%Remove (MudSystemDotimud) call Ann_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud) call Ann_MudOrKick%Remove (MudSystemDotimud) elseif(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) > ExcessMudVolume_Remained) then MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- ExcessMudVolume_Remained exit else !(Ann_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained) call MudSystemDotAnn_MudDischarged_Volume%Remove (MudSystemDotimud) call Ann_Mud_Backhead_X%Remove (MudSystemDotimud) call Ann_Mud_Backhead_section%Remove (MudSystemDotimud) call Ann_Mud_Forehead_X%Remove (MudSystemDotimud) call Ann_Mud_Forehead_section%Remove (MudSystemDotimud) call Ann_Density%Remove (MudSystemDotimud) call Ann_RemainedVolume_in_LastSection%Remove (MudSystemDotimud) call Ann_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud) call Ann_MudOrKick%Remove (MudSystemDotimud) 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 MudSystemDotMudSection= F_StringIntervalCounts+1 MudSystemDotBackheadX= MudSystemDotXstart_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)= MudSystemDotMudSection !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)= MudSystemDotBackheadX !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 (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then !1st Mode write(*,*) 'Kick influx enters Annulus' call Ann_Density%AddToFirst (MudSystemDotOp_KickSaved_Density) call MudSystemDotAnn_MudDischarged_Volume%AddToFirst (MudSystemDotOp_Kick_Saved_Volume) call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)) call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1) call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_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 (MudSystemDotSaved_Op_MudOrKick) !<<<<<<<< call Ann_CuttingMud%AddToFirst (0) elseif (MudSystemDotOp_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() /= 0) then MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) + MudSystemDotOp_Kick_Saved_Volume endif if ( MudSystemDotOp_NeededVolume_ToFill > 0.0 .and. (MudSystemDotOp_NeededVolume_ToFill < ABS(MudSystemDotDeltaVolumeAnnulusCapacity)) .and. Op_MudOrKick%Last() == 0 .and. (MudSystemDotiLoc==2 .or. iloc_edited==1)) then !3rd Mode !write(*,*) 'checkpoint 0' !! for avoid kick separation -Op_MudOrKick%Last() == 0: because of pump MudSystemDotNewVolume= ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) ! =volume that should be added to iloc=2 in Ann call RemoveOpMudArrays(MudSystemDotOp_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann in %%1 section if ( MudSystemDotAnn_MudDischarged_Volume%Array(1) > ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) ) then! 1st in Ann = kick ,, we expect: ((AnnulusFlowRate/60.d0)*DeltaT_Mudline)= OpMudVolLast MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) - ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) ! kick else call RemoveAnnulusMudArrays(1) !kick is removed MudSystemDotiLoc= 1 MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) write(*,*) 'little expand' ! including a little expand endif endif if (MudSystemDotOp_Saved_MudDischarged_Volume> 0.0) then !1st Mode NewDensity= MudSystemDotOp_MudSaved_Density !write(*,*) 'iloc,...' , iloc,((AnnulusFlowRate/60.d0)*DeltaT_Mudline),Op_Saved_MudDischarged_Volume if (MudSystemDotiLoc==1) then !write(*,*) 'checkpoint 1' MudSystemDotNewVolume= MudSystemDotOp_Saved_MudDischarged_Volume elseif (real(((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline)) - real(MudSystemDotOp_Saved_MudDischarged_Volume) > 0.d0 ) then ! for avoid kick separation !write(*,*) 'checkpoint 2' MudSystemDotNewVolume= ((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) !- Op_Saved_MudDischarged_Volume call RemoveOpMudArrays(MudSystemDotOp_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann if ( MudSystemDotAnn_MudDischarged_Volume%Array(1) > (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume) ) then! 1st in Ann = kick MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) - (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume) MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_Saved_MudDischarged_Volume) !kick else call RemoveAnnulusMudArrays(1) !kick is removed MudSystemDotiLoc =1 MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_Density%Length())+ (((MudSystemDotAnnulusFlowRate/60.d0)*DeltaT_Mudline) - MudSystemDotOp_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' MudSystemDotNewVolume= MudSystemDotOp_Saved_MudDischarged_Volume ! it is normal mode endif endif !write(*,*) 'NewVolume=' ,NewVolume if( Ann_Density%Length() == 1 .and. MudSystemDotiLoc ==2 ) then write(*,*) '***errorb****==' write(*,*) 'iloc_edited=' , iloc_edited write(*,*) 'iloc_changedTo2=' , iloc_changedTo2 write(*,*) 'Op_Capacity===' , sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',MudSystemDotOp_Saved_MudDischarged_Volume, MudSystemDotOp_Kick_Saved_Volume do MudSystemDotimud=1, MudSystemDotOp_MudDischarged_Volume%Length() write(*,*) 'Op:', MudSystemDotimud, MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud), MudSystemDotOp_Density%Array(MudSystemDotimud) ,Op_MudOrKick%Array(MudSystemDotimud) enddo do MudSystemDotimud=1, MudSystemDotAnn_MudDischarged_Volume%Length() write(*,*) 'Ann:', MudSystemDotimud, MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud), Ann_Density%Array(MudSystemDotimud) ,Ann_MudOrKick%Array(MudSystemDotimud) enddo write(*,*) '==***errorb****' endif if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotDensityMixTol) & !%%1 section .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==1 .and. abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotCuttingDensityMixTol) & .or. (Rate_of_Penetration>0. .and. Ann_CuttingMud%Array(MudSystemDotiLoc)==0 .and. MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc) < 42.) ) then ! 1-Pockets are Merged !write(*,*) '%%1 section a)' Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume) MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0) Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0) else ! 2-Merging conditions are not meeted, so new pocket !write(*,*) '%%1 section b)' call Ann_Density%AddTo (MudSystemDotiLoc,NewDensity) call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotNewVolume) call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX) call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection) call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX) call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection) call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0) call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0) call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0) call Ann_CuttingMud%AddTo (MudSystemDotiLoc,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 MudSystemDotAnnMudVolumeSum= 0.d0 !Ann_MudSaved_Density= 0.d0 !Ann_KickSaved_Density= 0.d0 MudSystemDotAnn_Saved_MudDischarged_Volume= 0.d0 MudSystemDotAnn_Kick_Saved_Volume= 0.d0 MudSystemDotSaved_Ann_MudOrKick= 0 MudSystemDotAnn_to_Choke_2mud= .false. do MudSystemDotimud=1, MudSystemDotAnn_MudDischarged_Volume%Length() MudSystemDotAnnMudVolumeSum= MudSystemDotAnnMudVolumeSum + MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) if ( MudSystemDotAnnMudVolumeSum > sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) ) then IF (Ann_MudOrKick%Array(MudSystemDotimud) == 0) THEN MudSystemDotAnn_MudSaved_Density = Ann_Density%Array(MudSystemDotimud) MudSystemDotAnn_Saved_MudDischarged_Volume = MudSystemDotAnnMudVolumeSum - sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) ELSEIF (Ann_MudOrKick%Array(MudSystemDotimud) > 0 .AND. Ann_MudOrKick%Array(MudSystemDotimud) <100) THEN ! 104= AIR MudSystemDotAnn_Kick_Saved_Volume = MudSystemDotAnnMudVolumeSum - sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) MudSystemDotSaved_Ann_MudOrKick= Ann_MudOrKick%Array (MudSystemDotimud) MudSystemDotAnn_KickSaved_Density= Ann_Density%Array(MudSystemDotimud) END IF do ii= MudSystemDotimud + 1, MudSystemDotAnn_MudDischarged_Volume%Length() IF (Ann_MudOrKick%Array(ii) == 0) THEN MudSystemDotAnn_MudSaved_Density = ((MudSystemDotAnn_MudSaved_Density * MudSystemDotAnn_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * MudSystemDotAnn_MudDischarged_Volume%Array(ii))) / (MudSystemDotAnn_Saved_MudDischarged_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii)) MudSystemDotAnn_Saved_MudDischarged_Volume = MudSystemDotAnn_Saved_MudDischarged_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii) MudSystemDotAnn_to_Choke_2mud= .true. ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR MudSystemDotAnn_Kick_Saved_Volume = MudSystemDotAnn_Kick_Saved_Volume + MudSystemDotAnn_MudDischarged_Volume%Array(ii) MudSystemDotSaved_Ann_MudOrKick= Ann_MudOrKick%Array (ii) MudSystemDotAnn_KickSaved_Density= Ann_Density%Array(ii) END IF enddo exit ! exits do endif enddo MudSystemDotAnn_Saved_MudDischarged_Volume_Final= MudSystemDotAnn_Saved_MudDischarged_Volume MudSystemDotAnn_Kick_Saved_Volume_Final= MudSystemDotAnn_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 = MudSystemDotAnn_Saved_MudDischarged_Volume_Final-((MudSystemDotQlost/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. MudSystemDotimud= 0 do while (MudSystemDotimud < Ann_Mud_Forehead_X%Length()) MudSystemDotimud = MudSystemDotimud + 1 if (MudSystemDotimud> 1) then Ann_Mud_Backhead_X%Array(MudSystemDotimud)= Ann_Mud_Forehead_X%Array(MudSystemDotimud-1) Ann_Mud_Backhead_section%Array(MudSystemDotimud)= Ann_Mud_Forehead_section%Array(MudSystemDotimud-1) endif ! write(*,*) 'imud==' , imud !write(*,*) '***)Ann_Mud_Backhead_section(imud)= ' , Ann_Mud_Backhead_section%Array(imud), Ann_density%Array(imud) MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))) & / ABS(MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))) ! +1 for string , -1 for annulus Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))- Ann_Mud_Backhead_X%Array(MudSystemDotimud))* & MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3) Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal if ( MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) <= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then Ann_Mud_Forehead_section%Array(MudSystemDotimud)= Ann_Mud_Backhead_section%Array(MudSystemDotimud) Ann_Mud_Forehead_X%Array(MudSystemDotimud)= Ann_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud)) ! 7.48 is for gal to ft^3 else MudSystemDotisection= Ann_Mud_Backhead_section%Array(MudSystemDotimud)+1 Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud) do if (MudSystemDotisection > MudSystemDotNoPipeSections) then ! last pipe section(well exit) MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud) Ann_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections) Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotNoPipeSections if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well call RemoveAnnulusMudArrays(MudSystemDotimud) endif exit endif MudSystemDotxx= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal) if (MudSystemDotxx<= 1.0) then Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection Ann_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection) exit else Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) MudSystemDotisection= MudSystemDotisection+ 1 endif enddo endif enddo if (Ann_Mud_Forehead_X%Last() < MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)) then Ann_Mud_Forehead_X%Array(Ann_Mud_Forehead_X%Length()) = MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections) ! for error preventing endif !========================ANNULUS END================= !************************************************************************************************************************* !========================Tripping Out- 2nd Mode==================== elseif ( MudSystemDotOp_NeededVolume_ToFill > ABS(MudSystemDotDeltaVolumeAnnulusCapacity) ) 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 MudSystemDotAnn_MudDischarged_Volume%Add (0.0d0) call Ann_Mud_Forehead_X%Add (MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)) call Ann_Mud_Forehead_section%Add (MudSystemDotNoPipeSections) call Ann_Mud_Backhead_X%Add (MudSystemDotXstart_PipeSection(MudSystemDotNoPipeSections)) call Ann_Mud_Backhead_section%Add (MudSystemDotNoPipeSections) 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())= MudSystemDotNoPipeSections !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())= MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections) MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())= MudSystemDotAnn_MudDischarged_Volume%Last()+ (MudSystemDotOp_NeededVolume_ToFill - ABS(MudSystemDotDeltaVolumeAnnulusCapacity)) ! Op_NeededVolume_ToFill !ABS(DeltaVolumePipe) - ((AnnulusFlowRate/60.)*DeltaT_Mudline) !(gal) !=================================================================== if ( (MudSystemDotiLoc==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(MudSystemDotiLoc)-MudSystemDotOp_Density%Last())< MudSystemDotDensityMixTol) then Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotOp_Density%Last()*MudSystemDotOp_MudDischarged_Volume%Last())/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotOp_MudDischarged_Volume%Last()) MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotOp_MudDischarged_Volume%Last() ! OP_Last is mud(effect of pump added mud) Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0) Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (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 (MudSystemDotiLoc,MudSystemDotOp_Density%Last()) call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotOp_MudDischarged_Volume%Last()) call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX) call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection) call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX) call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection) call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0) call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0) call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0) call Ann_CuttingMud%AddTo (MudSystemDotiLoc,0) endif MudSystemDotOp_NeededVolume_ToFill= MudSystemDotOp_NeededVolume_ToFill + MudSystemDotOp_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 MudSystemDotAnn_Saved_MudDischarged_Volume= 0.d0 MudSystemDotAnn_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' MudSystemDotAnn_Saved_MudDischarged_Volume_Final= MudSystemDotAnn_Saved_MudDischarged_Volume MudSystemDotAnn_Kick_Saved_Volume_Final= MudSystemDotAnn_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 = MudSystemDotAnn_Saved_MudDischarged_Volume_Final-((MudSystemDotQlost/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() MudSystemDotimud= Ann_Mud_Forehead_X%Length() + 1 do while (MudSystemDotimud > 1) MudSystemDotimud = MudSystemDotimud - 1 if (MudSystemDotimud< Ann_Mud_Forehead_X%Length()) then Ann_Mud_Forehead_X%Array(MudSystemDotimud)= Ann_Mud_Backhead_X%Array(MudSystemDotimud+1) Ann_Mud_Forehead_section%Array(MudSystemDotimud)= Ann_Mud_Backhead_section%Array(MudSystemDotimud+1) endif ! <<< Fracture Shoe Lost IF ( MudSystemDotShoeLost .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(MudSystemDotimud) .and. Shoe%ShoeDepth >= Ann_Mud_Forehead_X%Array(MudSystemDotimud) ) then !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)-((MudSystemDotQlost/60.0d0)*DeltaT_Mudline) !(gal) if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) < 0.0) then !write(*,*) 'mud is removed by shoe lost, imud=' , imud call RemoveAnnulusMudArrays(MudSystemDotimud) MudSystemDotimud= MudSystemDotimud-1 cycle endif MudSystemDotLostInTripOutIsDone= .true. ENDIF ! Fracture Shoe Lost >>> !write(*,*) 'a)imud,Ann_Mud_Forehead_section=',imud,Ann_Mud_Forehead_section%Array(imud) MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))) & / ABS(MudSystemDotXend_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))) ! +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(MudSystemDotimud)= MudSystemDotDirectionCoef* (Ann_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud)))* & MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotimud)) !(ft^3) Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal if ( MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) <= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then Ann_Mud_Backhead_section%Array(MudSystemDotimud)= Ann_Mud_Forehead_section%Array(MudSystemDotimud) Ann_Mud_Backhead_X%Array(MudSystemDotimud)= Ann_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotDirectionCoef*(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotimud)) ! 7.48051948 is for gal to ft^3 else MudSystemDotisection= Ann_Mud_Forehead_section%Array(MudSystemDotimud)-1 Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud) do if (MudSystemDotisection < F_StringIntervalCounts+1) then ! last pipe section(well exit) F_StringIntervalCounts+1 is the first section in Annulus MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud) Ann_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1) Ann_Mud_Backhead_section%Array(MudSystemDotimud)= F_StringIntervalCounts+1 if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well call RemoveAnnulusMudArrays(MudSystemDotimud) endif exit endif MudSystemDotxx= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal) if (MudSystemDotxx<= 1.0) then Ann_Mud_Backhead_section%Array(MudSystemDotimud)= MudSystemDotisection Ann_Mud_Backhead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXstart_PipeSection(MudSystemDotisection)- MudSystemDotXend_PipeSection(MudSystemDotisection)))+ MudSystemDotXend_PipeSection(MudSystemDotisection) exit else Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) MudSystemDotisection= MudSystemDotisection- 1 endif enddo endif enddo !========================ANNULUS END================= endif ! end of 1st &3rd & 2nd Mode !************************************************************************************************************************* !======================== Bottom Hole Entrance ========================== !if (iloc == 1) then if ( MudSystemDotOp_NeededVolume_ToFill > 0.0 ) then ! it is needed for 2nd & 3rd mode !write(*,*) 'op add for 2nd & 3rd mode done' if ( ABS(MudSystemDotOp_Density%Last() - SavedDensityForOp ) >= MudSystemDotDensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Last()>42.) ) then ! 1-Merging conditions are not meeted, so new pocket call MudSystemDotOp_Density%Add (SavedDensityForOp) call MudSystemDotOp_MudDischarged_Volume%Add (MudSystemDotOp_NeededVolume_ToFill) call MudSystemDotOp_Mud_Forehead_X%Add (0.0d0) call Op_Mud_Forehead_section%Add (1) call MudSystemDotOp_Mud_Backhead_X%Add (0.0d0) call Op_Mud_Backhead_section%Add (1) call MudSystemDotOp_RemainedVolume_in_LastSection%Add (0.0d0) call MudSystemDotOp_EmptyVolume_inBackheadLocation%Add (0.0d0) call Op_MudOrKick%Add (Ann_MudOrKick%Array(1)) else ! 2-Pockets are Merged MudSystemDotOp_Density%Array (MudSystemDotOp_Density%Length())= (SavedDensityForOp*MudSystemDotOp_NeededVolume_ToFill+MudSystemDotOp_Density%Last()*MudSystemDotOp_MudDischarged_Volume%Last())/(MudSystemDotOp_MudDischarged_Volume%Last()+MudSystemDotOp_NeededVolume_ToFill) MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_Density%Length())= MudSystemDotOp_MudDischarged_Volume%Array (MudSystemDotOp_Density%Length()) + MudSystemDotOp_NeededVolume_ToFill MudSystemDotOp_RemainedVolume_in_LastSection%Array (MudSystemDotOp_Density%Length())= 0.0 MudSystemDotOp_EmptyVolume_inBackheadLocation%Array (MudSystemDotOp_Density%Length())= 0.0 endif endif !============================= Bottom Hole ============================== MudSystemDotimud=0 do while (MudSystemDotimud < MudSystemDotOp_Mud_Forehead_X%Length()) MudSystemDotimud = MudSystemDotimud + 1 if (MudSystemDotimud> 1) then MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud-1) Op_Mud_Backhead_section%Array(MudSystemDotimud)= Op_Mud_Forehead_section%Array(MudSystemDotimud-1) endif MudSystemDotDirectionCoef= (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))) & / ABS(MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))) ! +1 for string , -1 for annulus MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud))* & MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3) MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal if ( MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then Op_Mud_Forehead_section%Array(MudSystemDotimud)= Op_Mud_Backhead_section%Array(MudSystemDotimud) MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud)) ! 7.48051948 is for gal to ft^3 else MudSystemDotisection= Op_Mud_Backhead_section%Array(MudSystemDotimud)+1 MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud) do if (MudSystemDotisection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit) !if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud) MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts) Op_Mud_Forehead_section%Array(MudSystemDotimud)= F_BottomHoleIntervalCounts if (MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well call MudSystemDotOp_MudDischarged_Volume%Remove (MudSystemDotimud) call MudSystemDotOp_Mud_Backhead_X%Remove (MudSystemDotimud) call Op_Mud_Backhead_section%Remove (MudSystemDotimud) call MudSystemDotOp_Mud_Forehead_X%Remove (MudSystemDotimud) call Op_Mud_Forehead_section%Remove (MudSystemDotimud) call MudSystemDotOp_Density%Remove (MudSystemDotimud) call MudSystemDotOp_RemainedVolume_in_LastSection%Remove (MudSystemDotimud) call MudSystemDotOp_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud) call Op_MudOrKick%Remove (MudSystemDotimud) endif exit endif MudSystemDotxx= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection) !(gal) if (MudSystemDotxx<= 1.0) then Op_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_OpSection(MudSystemDotisection)- MudSystemDotXstart_OpSection(MudSystemDotisection)))+ MudSystemDotXstart_OpSection(MudSystemDotisection) exit else MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection) MudSystemDotisection= MudSystemDotisection+ 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' !========================================================= MudSystemDottotal_injected = MudSystemDottotal_injected + MudVolume_InjectedFromAnn if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then MudSystemDottotal_injected= 0. endif !write(*,*) ' MudVolume_InjectedFromAnn =' , MudVolume_InjectedFromAnn !write(*,*) ' total injected-tripout =' , total_injected !write(*,*) ' injected-tripout =' , MudVolume_InjectedFromAnn end subroutine TripOut_and_Pump