|
- subroutine Pump_and_TripIn ! 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
- !===========================================================WELL============================================================
- !===========================================================WELL============================================================
-
- StringFlowRate= MUD(2)%Q
- AnnulusFlowRate= MUD(2)%Q
-
-
- !write(*,*) 'Trip In'
-
-
- !========================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 (ChokeControlPanel%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)
- !
- ! write(*,*) 'StringDensity_Old=' , StringDensity_Old
- !
- ! UtubeMode1Activated= .false.
- !endif
-
- !========================Utube1 Air Element Removing End=================
-
- !!========================Utube2 Removing from Annulus================= not needed 97.04.26
- !
- ! if (UtubeMode2Activated== .true.) then ! StringUpdate == .true.
- !
- ! 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 (F_StringIntervalCounts > F_StringIntervalCountsOld) then ! StringUpdate == .true.
- 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
- 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
-
-
- !write(*,*) 'St_Mud_Backhead_section%Array(1)=' , St_Mud_Backhead_section%Array(1)
- !write(*,*) 'Xend_PipeSection(St_Mud_Backhead_section%Array(1))=' , Xend_PipeSection(St_Mud_Backhead_section%Array(1))
- !
- !write(*,*) 'St_EmptyVolume_inBackheadLocation%Array(1)=' , St_EmptyVolume_inBackheadLocation%Array(1)
- !write(*,*) 'St_Mud_Backhead_X%Array(1)=' , St_Mud_Backhead_X%Array(1)
-
-
- 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) F_StringIntervalCounts includes Horizontal line
- 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
-
-
- !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(*,*) '==== a before'
-
-
-
-
- !write(*,*) ' iloc (a): ' , iloc
-
- !========================STRING END=================
-
- IF (Op_MudOrKick%Last() /= 0 .and. Op_MudOrKick%Last()==Ann_MudOrKick%First()) iLoc=2 ! it may be 1,2,3 or more, all of them are kick
- !write(*,*) ' iloc (b): ' , iloc
-
- !=============================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 ==============================
-
-
-
-
- !=============== 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
-
-
-
- !write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
- !write(*,*) 'Op_MudDischarged_Volume%Length()===' , Op_MudDischarged_Volume%Length()
- !
-
- do imud=1, Op_MudDischarged_Volume%Length()
- !write(*,*) 'imud, Op_MudDischarged_Volume%Array(imud)=' , imud,Op_MudDischarged_Volume%Array(imud)
-
- OpMudVolumeSum= OpMudVolumeSum + Op_MudDischarged_Volume%Array(imud)
-
- if ( OpMudVolumeSum > sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) ) then
-
- 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))
- !write(*,*) 'cond 1- Op_MudOrKick%Array (imud),Op_Density%Array(imud):' ,Op_MudOrKick%Array (imud),Op_Density%Array(imud)
- Saved_Op_MudOrKick= Op_MudOrKick%Array (imud)
- Op_KickSaved_Density= Op_Density%Array(imud)
- iloc= 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)
- !write(*,*) 'cond 2- Op_MudOrKick%Array (ii),Op_Density%Array(ii):' ,Op_MudOrKick%Array (ii),Op_Density%Array(ii)
- Saved_Op_MudOrKick= Op_MudOrKick%Array (ii)
- Op_KickSaved_Density= Op_Density%Array(ii)
- iloc= 2
- END IF
- enddo
-
- exit ! exits do
-
- endif
-
- enddo
- !WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume
- !write(*,*) ' iloc (c): ' , iloc
-
- !======================================================================
-
- !======================================================================
-
-
-
-
-
- !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 ! because its effect is applied in Migration Code
- ! !write(*,*) 'iloc=====' , iLoc bejaye Rate_of_Penetration ==0. in bude: DeltaVolumeOp == 0.0
- ! if (ABS(AnnulusSuctionDensity_Old-St_Density%Last()) >= DensityMixTol .OR. (DeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(iLoc)-St_Density%Last())>=DensityMixTol .and. AnnulusFlowRate/=0.0d0) ) 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)
- ! !write(*,*) 'c) annLength=' , Ann_Density%Length()
- !
- ! AnnulusSuctionDensity_Old= St_Density%Last()
- !
- ! MudIsChanged= .true.
- ! endif
- !
- ! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) !(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
- Ann_Mud_Backhead_X%Array(1)= BackheadX
-
-
-
- ! write(*,*) 'zero)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
- !
- !
- !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(*,*) '====pump added-before add to ann'
-
-
-
- !========================Tripping In====================
-
- !write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
- if (Rate_of_Penetration==0.) then ! .and. Op_MudOrKick%Last() == 0) then ! trip in mode(loole paeen) Mud
-
- !write(*,*) 'Tripping In'
- !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- !if ( MudIsChanged== .true. ) then
- ! call RemoveAnnulusMudArrays(iLoc)
- !endif
-
-
- if (Op_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then
- 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_Saved_MudDischarged_Volume> 0.0) then
- NewDensity= Op_MudSaved_Density
- NewVolume= Op_Saved_MudDischarged_Volume
- !write(*,*) 'NewVolume=' , NewVolume
- !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
-
-
- if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(iLoc)-NewDensity)< DensityMixTol) &
- .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
-
- 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)
- !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,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()
- !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- endif
- endif
-
- endif
-
- !========================Tripping In - End====================
-
- !========================Drilling Mode========================
-
- if (Rate_of_Penetration>0. .and. DeltaVolumeOp>0.0) then ! trip in mode(loole paeen) DrillingMode== .true.
- !write(*,*) 'Drilling Mode'
-
- !if ( MudIsChanged== .true. ) then
- ! call RemoveAnnulusMudArrays(iLoc)
- !endif
- !write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
-
- !NewDensity= (St_Density%Last() * AnnulusFlowRate + 141.4296E-4*Rate_of_Penetration*Diameter_of_Bit**2)/(AnnulusFlowRate+6.7995E-4*Rate_of_Penetration*Diameter_of_Bit**2)
-
- NewDensity= St_Density%Last()
-
-
- !NewVolume= ((AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp
- !!! Density in ppg, flow rate in gpm, ROP in ft/s, bit diameter in inch
-
-
- do imud=1, Op_MudDischarged_Volume%Length()
- if ( Op_MudOrKick%Array(imud) == 0 ) then
- Op_Density%Array(imud)= NewDensity
-
- endif
- enddo
-
-
-
- if (Op_Kick_Saved_Volume > 0.0 .and. Ann_MudOrKick%First() == 0) then
- write(*,*) 'Kick influx enters Annulus first time'
- !write(*,*) 'Saved_Op_MudOrKick=',Saved_Op_MudOrKick
- 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_Saved_MudDischarged_Volume> 0.0) then
- !write(*,*) 'Op_Saved_Mud added'
- NewDensity= NewDensity !(drilling density)
- NewVolume= Op_Saved_MudDischarged_Volume + DeltaVolumeOp ! (DeltaVolumeOp: for Cuttings Volume)
- !write(*,*) 'NewVolume=' , NewVolume
- !write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- if ( (Ann_CuttingMud%Array(iloc)==1 .and. abs(Ann_Density%Array(iLoc)-NewDensity)< CuttingDensityMixTol ) &
- .or. (Ann_CuttingMud%Array(iLoc)==0 .and. Ann_MudDischarged_Volume%Array(iLoc) < 42.) ) then ! 1-Pockets are Merged
-
- 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)
- Ann_CuttingMud%Array(iLoc)= 1
- !write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- else ! 2-Merging conditions are not meeted, so new pocket
- !write(*,*) 'before e) ', iloc, Ann_Density%Array(iLoc),NewDensity
- !write(*,*) 'before e) Ann_MudDischarged_Volume%Array(iLoc)=' , Ann_MudDischarged_Volume%Array(iLoc)
-
-
- 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,1) ! 1= cutting 0= mud
- !write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1)
-
- !write(*,*) 'e) annLength=' , Ann_Density%Length()
-
-
- endif
-
-
- endif
-
- endif
- !===================================================================
-
- !write(*,*) 'after 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(*,*) '==after add to ann'
-
- NewVolume= ((AnnulusFlowRate/60.d0)*DeltaT_Mudline) - Op_Saved_MudDischarged_Volume
-
- if (iloc==2 .and. Op_MudOrKick%Last()==0 .and. NewVolume > 0.d0 ) then ! for avoid kick separation
- !write(*,*) 'avoid kick separation'
-
-
- NewDensity= Op_MudSaved_Density
-
- 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
- !write(*,*) 'mode1'
- 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(*,*) 'mode2'
-
- ! including a little expand
- endif
-
-
- if ((Rate_of_Penetration==0 .and. abs(Ann_Density%Array(iLoc)-NewDensity)< DensityMixTol) &
- .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
-
- 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
- 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
-
-
- endif
- !===================================================================
- if( Op_MudOrKick%Last() == 1 .and. Ann_MudOrKick%First() == 0 ) then
-
- write(*,*) '***error2****=='
-
- write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume
-
-
- write(*,*) 'after 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(*,*) '==after add to ann'
-
- write(*,*) 'NewVolume,Op_MudOrKick%Last=' , NewVolume,Op_MudOrKick%Last()
- write(*,*) '==***error2****'
-
- 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
-
-
- !WRITE (*,*) 'Ann_Saved_Mud_Volume, Ann_Kick_Saved_Volume', Ann_Saved_MudDischarged_Volume, Ann_Kick_Saved_Volume
- exit
-
- endif
-
- enddo
- Ann_Saved_MudDischarged_Volume_Final= Ann_Saved_MudDischarged_Volume !+ Ann_Kick_Saved_Volume
- Ann_Kick_Saved_Volume_Final= Ann_Kick_Saved_Volume
- IF (WellHeadIsOpen) MudVolume_InjectedFromAnn = Ann_Saved_MudDischarged_Volume_Final -((Qlost/60.0d0)*DeltaT_Mudline)
- !WRITE (*,*) 'MudVolume_InjectedFromAnn=', MudVolume_InjectedFromAnn
- !======================================================================
-
- !write(*,*) 'c)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:))
- !write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections))
- !write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume
-
- total_injected = total_injected + MudVolume_InjectedFromAnn
-
- if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
- total_injected= 0.
- endif
-
- !write(*,*) ' total injected-tripin =' , total_injected
- !write(*,*) 'injected-tripin =' , MudVolume_InjectedFromAnn
-
-
-
-
-
- !======================== 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
-
-
-
- ! <<< Fracture Shoe Lost
- IF ( ShoeLost .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(imud) .and. Shoe%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
-
- ENDIF
- ! Fracture Shoe Lost >>>
-
-
- 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
- !write(*,*) 'remove******'
- 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
- ! write(*,*) 'imud=' , imud
- !write(*,*) 'Pinter4 **Ann_Length()=' , Ann_Mud_Forehead_X%Length()
- ! write(*,*) 'Ann_Density%Array (imud)=' , Ann_Density%Array (imud)
- !
- !
- !write(*,*) imud,'Ann_Mud_Forehead_X%Array(imud)=' , Ann_Mud_Forehead_X%Array(imud)
-
- !if (Ann_Mud_Forehead_X%Array(imud) < Xend_PipeSection(NoPipeSections)) then
- ! Ann_Mud_Forehead_X%Array(imud) = Xend_PipeSection(NoPipeSections) ! for error preventing
- !endif
-
- !write(*,*) imud, 'Ann_MudDischarged_Volume%Array(imud)=' , Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud)
-
-
- 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=================
- !write(*,*) 'sum(Ann_MudDischarged_Volume%Array())=' , sum(Ann_MudDischarged_Volume%Array(:))
-
- !=========================================================
-
-
- !write(*,*) 'before======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
- !write(*,*) '2======before'
-
-
- !========================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
- !write(*,*) 'imud**=' , imud
- 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
- !write(*,*) ' Op_EmptyVolume_inBackheadLocation%Array(1) =' , Op_EmptyVolume_inBackheadLocation%Array(1)
- if ( Op_EmptyVolume_inBackheadLocation%Array(1) < 0.0) CALL ErrorStop1 ('Negative Empty volume')
-
- 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.48 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 RemoveOpMudArrays(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
- ! for OP remove:
-
- if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(F_BottomHoleIntervalCounts)) then
- totalLength = Op_MudDischarged_Volume%Length()
- do while(imud < totalLength)
-
- !imud = imud + 1
- call RemoveOpMudArrays(totalLength)
- totalLength = totalLength - 1
-
-
- enddo
-
- exit !
-
- endif
-
-
-
-
- !if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(F_BottomHoleIntervalCounts)) then
- ! totalLength = Op_MudDischarged_Volume%Length()
- ! do while(imud <= totalLength)
- !
- ! imud = imud + 1
- ! call RemoveOpMudArrays(imud)
- ! totalLength = totalLength - 1
- !
- !
- ! enddo
- !
- ! exit !
- !
- !endif
-
- enddo
-
- !write(*,*) 'OpSection_VolumeCapacity sum=' , sum(OpSection_VolumeCapacity(:))
-
-
-
- !========================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
- !
- ! !
- ! !do imud=1, st_MudDischarged_Volume%Length()
- ! ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
- ! !enddo
- !
- !write(*,*) '==after sorting'
-
-
- ! write(*,*) 'after sorting st=='
- !
- ! do imud=1, st_MudDischarged_Volume%Length()
- ! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud),St_Density%Array(imud)
- ! enddo
- !
- !write(*,*) '==after sorting st'
-
-
-
-
- !write(*,*) '**Ann_Kick_Saved_Final,Mud_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn
-
- end subroutine Pump_and_TripIn
-
-
-
-
-
-
-
-
-
-
-
- subroutine ChokeLineMud ! 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 PressureDisplayVARIABLES
- Use CError
- Use , intrinsic :: IEEE_Arithmetic
-
-
- implicit none
-
- integer i,ii,error_occured
-
- error_occured = 0
-
-
-
-
- !write(*,*) 'begining chokeline=='
- !write(*,*) 'Ann last:', Ann_MudDischarged_Volume%Last(), Ann_Density%Last() ,Ann_MudOrKick%Last()
- !
- !do imud=1, ChokeLine_MudDischarged_Volume%Length()
- ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- !enddo
-
-
-
- !write(*,*) 'Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,MudVolume_InjectedFromAnn
-
- !write(*,*) 'begining chokeline=='
-
-
-
-
-
-
-
- ChokeLineFlowRate = MUD(4)%Q
- !WRITE (*,*) 'MUD(4)%Q', MUD(4)%Q
-
-
- if (NewPipeFilling == 0) then ! .or. UtubeFilling==0) then
- ChokeLineFlowRate= 0.
- endif
-
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()-2
- if ( ChokeLine_MudOrKick%Array(imud) ==1 .and. ChokeLine_MudOrKick%Array(imud+1) ==0 .and. ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
- write(*,*) 'error_location is 1'
- error_occured = 1
- endif
- enddo
-
-
-
- !
- !do imud=1, st_MudDischarged_Volume%Length()
- ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)
- !enddo
-
-
- !========================CHOKE LINE ENTRANCE=================
-
- !if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume-((Qlost/60.0d0)*DeltaT_Mudline) ) == 0.0 ) then
- if ( Ann_Kick_Saved_Volume > 1.0e-5 .and. ( MudVolume_InjectedFromAnn ) <= 1.0e-5 ) then
-
- !WRITE (*,*) 'only kick enters to chokeline, Casing pressure = ', PressureGauges(2)
-
- if (ChokeLine_MudOrKick%First() == 0) then
- call ChokeLine_Density%AddToFirst (Ann_KickSaved_Density)
- call ChokeLine_MudDischarged_Volume%AddToFirst (0.d0)
- call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Forehead_section%AddToFirst (1)
- call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Backhead_section%AddToFirst (1)
- call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call ChokeLine_MudOrKick%AddToFirst (Saved_Ann_MudOrKick)
-
- ChokeLineDensity_Old= Ann_KickSaved_Density
-
- endif
-
- ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ Ann_Kick_Saved_Volume !(gal)
-
- endif
-
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()-2
- if ( ChokeLine_MudOrKick%Array(imud) ==1 .and. ChokeLine_MudOrKick%Array(imud+1) ==0 .and. ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
- write(*,*) 'error_location is 2'
-
- error_occured = 1
-
- endif
- enddo
-
-
-
- !if ( Ann_Kick_Saved_Volume == 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 ) then
- if ( Ann_Kick_Saved_Volume <= 1.0e-5 .and. MudVolume_InjectedFromAnn > 1.0e-5 ) then
-
- !WRITE (*,*) 'only mud enters to chokeline'
-
-
- if ((Ann_to_Choke_2mud == .false. .and. ABS(ChokeLineDensity_Old - Ann_MudSaved_Density) >= DensityMixTol) .or. ChokeLine_MudOrKick%First() /= 0) then ! new mud is pumped
- call ChokeLine_Density%AddToFirst (Ann_MudSaved_Density)
- call ChokeLine_MudDischarged_Volume%AddToFirst (0.0d0)
- call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Forehead_section%AddToFirst (1)
- call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Backhead_section%AddToFirst (1)
- call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call ChokeLine_MudOrKick%AddToFirst (0)
-
- ChokeLineDensity_Old= Ann_MudSaved_Density
- endif
-
- !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
- ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (MudVolume_InjectedFromAnn) !(gal)
-
-
-
- endif
-
-
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()-2
- if ( ChokeLine_MudOrKick%Array(imud) ==1 .and. ChokeLine_MudOrKick%Array(imud+1) ==0 .and. ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
- write(*,*) 'error_location is 3'
- error_occured = 1
-
- endif
- enddo
-
-
- !if ( Ann_Kick_Saved_Volume > 0.0 .and. (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() /= 0 ) then
- if ( Ann_Kick_Saved_Volume > 1.0e-5 .and. (MudVolume_InjectedFromAnn) > 1.0e-5 .and. ChokeLine_MudOrKick%First() /= 0 ) then
-
- WRITE (*,*) 'Kick Enters Choke line Last Time'
-
- ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ Ann_Kick_Saved_Volume !(gal)
-
-
-
- call ChokeLine_Density%AddToFirst (Ann_MudSaved_Density)
- !call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) )
- call ChokeLine_MudDischarged_Volume%AddToFirst (MudVolume_InjectedFromAnn)
- call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Forehead_section%AddToFirst (1)
- call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Backhead_section%AddToFirst (1)
- call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call ChokeLine_MudOrKick%AddToFirst (0)
-
- ChokeLineDensity_Old= Ann_MudSaved_Density
-
-
-
-
-
- !ELSE if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() == 0 ) then
- ELSE if ( Ann_Kick_Saved_Volume > 1.0e-5 .and. ( MudVolume_InjectedFromAnn ) > 1.0e-5 .and. ChokeLine_MudOrKick%First() == 0 ) then
- WRITE (*,*) 'Kick Enters Choke line First Time'
-
-
-
- !ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal)
- ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( MudVolume_InjectedFromAnn ) !(gal)
-
-
-
-
- call ChokeLine_Density%AddToFirst (Ann_KickSaved_Density)
- call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Kick_Saved_Volume)
- call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Forehead_section%AddToFirst (1)
- call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
- call ChokeLine_Mud_Backhead_section%AddToFirst (1)
- call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
- call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
- call ChokeLine_MudOrKick%AddToFirst (Saved_Ann_MudOrKick)
-
- ChokeLineDensity_Old= Ann_KickSaved_Density
-
-
- endif
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()-2
- if ( ChokeLine_MudOrKick%Array(imud) ==1 .and. ChokeLine_MudOrKick%Array(imud+1) ==0 .and. ChokeLine_MudOrKick%Array(imud+2) ==1 ) then
- write(*,*) 'error_location is 4'
- error_occured = 1
-
- endif
- enddo
-
- if (error_occured == 1) then
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()
- write(*,*) 'ChokeLine:', imud, ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- enddo
-
- endif
-
-
- !==========================================================
-
- !
- !write(*,*) 'after add chokeline=='
- !
- ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
- ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- ! enddo
- !
- !write(*,*) 'after add chokeline=='
- !
- !
-
-
- !=============== save Choke Mud data==========================
- ChokeMudVolumeSum= 0.d0
- !Ann_MudSaved_Density= 0.d0
- !Ann_KickSaved_Density= 0.d0
- Choke_Saved_MudDischarged_Volume= 0.d0
- Choke_Kick_Saved_Volume= 0.d0
- Saved_Choke_MudOrKick= 0
-
-
-
-
- do imud=1, ChokeLine_MudDischarged_Volume%Length()
-
- ChokeMudVolumeSum= ChokeMudVolumeSum + ChokeLine_MudDischarged_Volume%Array(imud)
-
- if ( ChokeMudVolumeSum > ChokeLine_VolumeCapacity ) then
-
- IF (ChokeLine_MudOrKick%Array(imud) == 0) THEN
- Choke_MudSaved_Density = ChokeLine_Density%Array(imud)
- Choke_Saved_MudDischarged_Volume = ChokeMudVolumeSum - ChokeLine_VolumeCapacity
- ELSEIF (ChokeLine_MudOrKick%Array(imud) > 0 .AND. ChokeLine_MudOrKick%Array(imud) <100) THEN ! 104= AIR
- Choke_Kick_Saved_Volume = ChokeMudVolumeSum - ChokeLine_VolumeCapacity
- Saved_Choke_MudOrKick= ChokeLine_MudOrKick%Array (imud)
- Choke_KickSaved_Density= ChokeLine_Density%Array(imud)
- END IF
-
- do ii= imud + 1, ChokeLine_MudDischarged_Volume%Length()
-
- IF (ChokeLine_MudOrKick%Array(ii) == 0) THEN
- Choke_MudSaved_Density = ((Choke_MudSaved_Density * Choke_Saved_MudDischarged_Volume) + (ChokeLine_Density%Array(ii) * ChokeLine_MudDischarged_Volume%Array(ii))) / (Choke_Saved_MudDischarged_Volume + ChokeLine_MudDischarged_Volume%Array(ii))
- Choke_Saved_MudDischarged_Volume = Choke_Saved_MudDischarged_Volume + ChokeLine_MudDischarged_Volume%Array(ii)
- ELSEIF (ChokeLine_MudOrKick%Array(ii) > 0 .AND. ChokeLine_MudOrKick%Array(ii) <100) THEN ! 104= AIR
- Choke_Kick_Saved_Volume = Choke_Kick_Saved_Volume + ChokeLine_MudDischarged_Volume%Array(ii)
- Saved_Choke_MudOrKick= ChokeLine_MudOrKick%Array (ii)
- Choke_KickSaved_Density= ChokeLine_Density%Array(ii)
- END IF
- enddo
-
-
- !WRITE (*,*) 'Choke_Saved_Mud_Volume, Choke_Kick_Saved_Volume', Choke_Saved_MudDischarged_Volume, Choke_Kick_Saved_Volume
- exit ! exits do
-
- endif
-
- enddo
- Choke_Saved_MudDischarged_Volume_Final= Choke_Saved_MudDischarged_Volume !+ Choke_Kick_Saved_Volume
- Choke_Kick_Saved_Volume_Final= Choke_Kick_Saved_Volume
- !======================================================================
-
-
- !
- !do imud=1, ChokeLine_MudDischarged_Volume%Length()
- ! write(*,*) 'a)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- !enddo
-
-
- !write(*,*) 'choke_Mud sum=' , sum(ChokeLine_MudDischarged_Volume%Array(:))
- !write(*,*) 'choke_cap=' , ChokeLine_VolumeCapacity
- !write(*,*) 'Choke_Saved_Mud=' , Choke_Saved_MudDischarged_Volume_Final
- !write(*,*) 'Choke_Saved_Kick=' , Choke_Kick_Saved_Volume_Final
-
-
-
- !========================Choke Line=================
-
- imud=0
- do while (imud < ChokeLine_Mud_Forehead_X%Length())
- imud = imud + 1
-
- if (imud> 1) then
- ChokeLine_Mud_Backhead_X%Array(imud)= ChokeLine_Mud_Forehead_X%Array(imud-1)
- ChokeLine_Mud_Backhead_section%Array(imud)= ChokeLine_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
-
-
- ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= (BopStackSpecification%ChokeLineLength- ChokeLine_Mud_Backhead_X%Array(imud))* Area_ChokeLineFt !(ft^3)
-
- ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal
-
- if ( ChokeLine_MudDischarged_Volume%Array(imud) <= ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)) then
- ChokeLine_Mud_Forehead_section%Array(imud)= ChokeLine_Mud_Backhead_section%Array(imud)
- ChokeLine_Mud_Forehead_X%Array(imud)= ChokeLine_Mud_Backhead_X%Array(imud)+ (ChokeLine_MudDischarged_Volume%Array(imud)/7.48051948d0)/Area_ChokeLineFt
- ! 7.48 is for gal to ft^3
-
- else
-
- isection= ChokeLine_Mud_Backhead_section%Array(imud)+1
- ChokeLine_RemainedVolume_in_LastSection%Array(imud)= ChokeLine_MudDischarged_Volume%Array(imud)- ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)
-
- do
- if (isection > 1) then ! last pipe section(Chokeline exit)
- ChokeLine_MudDischarged_Volume%Array(imud)= ChokeLine_MudDischarged_Volume%Array(imud)- ChokeLine_RemainedVolume_in_LastSection%Array(imud)
- ChokeLine_Mud_Forehead_X%Array(imud)= BopStackSpecification%ChokeLineLength
- ChokeLine_Mud_Forehead_section%Array(imud)= 1
- if (ChokeLine_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
- call ChokeLine_MudDischarged_Volume%Remove (imud)
- call ChokeLine_Mud_Backhead_X%Remove (imud)
- call ChokeLine_Mud_Backhead_section%Remove (imud)
- call ChokeLine_Mud_Forehead_X%Remove (imud)
- call ChokeLine_Mud_Forehead_section%Remove (imud)
- call ChokeLine_Density%Remove (imud)
- call ChokeLine_RemainedVolume_in_LastSection%Remove (imud)
- call ChokeLine_EmptyVolume_inBackheadLocation%Remove (imud)
- call ChokeLine_MudOrKick%Remove (imud)
-
- endif
- exit
- endif
-
- xx= ChokeLine_RemainedVolume_in_LastSection%Array(imud)/ ChokeLine_VolumeCapacity !(gal)
-
- if (xx<= 1.0) then
- ChokeLine_Mud_Forehead_section%Array(imud)= isection
- ChokeLine_Mud_Forehead_X%Array(imud)= xx * BopStackSpecification%ChokeLineLength
- exit
- else
- ChokeLine_RemainedVolume_in_LastSection%Array(imud)= ChokeLine_RemainedVolume_in_LastSection%Array(imud)- ChokeLine_VolumeCapacity
- isection= isection+ 1
-
-
- endif
-
- enddo
-
- endif
-
- enddo
- !========================Choke Line END=================
-
- !do imud=1, ChokeLine_MudDischarged_Volume%Length()
- ! write(*,*) 'b)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- !enddo
-
- ChokeOutletDensity= ChokeLine_Density%Last() ! used in MudSystem
-
-
-
-
-
- do i=1, ChokeLine_MudOrKick%Length()
- !write(*,555) i,'Choke_Volume(i), type=' ,ChokeLine_MudDischarged_Volume%Array(i),ChokeLine_MudOrKick%Array(i)
-
- IF (IEEE_Is_NaN(ChokeLine_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Choke Volume-Plot')
- IF (ChokeLine_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Choke Volume= <=0' , ChokeLine_MudDischarged_Volume%Array(i))
- enddo
-
- 555 FORMAT(I3,5X,A42,(f12.5),5X,I3)
-
-
- !write(*,*) 'after sorting chokeline=='
- !IF (ANY(ChokeLine_MudOrKick%Array(:) > 0)) THEN
- ! do imud=1, ChokeLine_MudDischarged_Volume%Length()
- ! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud)
- ! enddo
- !END IF
-
-
- !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 chokeline'
-
-
- end subroutine ChokeLineMud
-
-
-
-
-
- subroutine Choke_GasSound ! is called in subroutine CirculationCodeSelect
-
-
- use CSounds
- !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 => TripTankVolume, TripTankDensity2 => TripTankDensity
- !USE sROP_Other_Variables
- !USE sROP_Variables
- !Use KickVariables
- !USE PressureDisplayVARIABLES
- !Use CError
- !Use , intrinsic :: IEEE_Arithmetic
-
-
-
-
-
- if ( ChokeLine_MudOrKick%Last() > 0 .AND. WellToChokeManifoldOpen == .true.) then
- !WellToChokeManifoldWasOpen
-
- SoundGasThroughChoke = 100 !100:chon dar adadhaye kamtar az 100 seda ghaat mishavad. eslah shavad.5.8.98 !int (min(ChokeLineFlowRate/2. , 100.))
- print* , 'SoundGasThroughChoke1=', SoundGasThroughChoke
- !WRITE (*,*) 'WellToChokeManifoldWasOpen-Sound', WellToChokeManifoldWasOpen
- WRITE (*,*) 'WellToChokeManifoldOpen', WellToChokeManifoldOpen
- else
- SoundGasThroughChoke = 0
- print* , 'SoundGasThroughChoke2=', SoundGasThroughChoke
- endif
- !print* , 'SoundGasThroughChoke3=', SoundGasThroughChoke
-
-
-
- call SetSoundGasThroughChoke(SoundGasThroughChoke)
-
-
- end subroutine Choke_GasSound
|