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