|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626 |
- subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect
-
- Use GeoElements_FluidModule
- USE CMudPropertiesVariables
- USE MudSystemVARIABLES
- USE Pump_VARIABLES
- !USE CHOKEVARIABLES
- !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
- !use CManifolds
- use CDrillWatchVariables
- !use CHOKEVARIABLES
- !use CChokeManifoldVariables
- use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
- USE sROP_Other_Variables
- USE sROP_Variables
- Use KickVariables
- Use CShoeVariables
-
-
- implicit none
-
- integer i,ii,AddLocation
- !===========================================================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 (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 (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. ShoeDepth < Ann_Mud_Backhead_X%Array(imud) .and. ShoeDepth >= Ann_Mud_Forehead_X%Array(imud) ) then
- !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline)
- Ann_MudDischarged_Volume%Array(imud)= Ann_MudDischarged_Volume%Array(imud)-((Qlost/60.0d0)*DeltaT_Mudline) !(gal)
- if (Ann_MudDischarged_Volume%Array(imud) < 0.0) then
- !write(*,*) 'mud is removed by shoe lost, imud=' , imud
- call RemoveAnnulusMudArrays(imud)
- imud= imud-1
- cycle
- endif
-
- 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 Pump_VARIABLES
- !USE CHOKEVARIABLES
- !USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
- !use CManifolds
- use CDrillWatchVariables
- !use CHOKEVARIABLES
- !use CChokeManifoldVariables
- use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
- USE sROP_Other_Variables
- USE sROP_Variables
- Use KickVariables
- USE 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)= (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)= 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 * 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 Pump_VARIABLES
- !!USE CHOKEVARIABLES
- !!USE CDataDisplayConsoleVariables , StandPipePressureDataDisplay=>StandPipePressure
- !!use CManifolds
- !use CDrillWatchVariables
- !!use CHOKEVARIABLES
- !!use CChokeManifoldVariables
- !use CTanksVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity
- !USE sROP_Other_Variables
- !USE sROP_Variables
- !Use KickVariables
- !USE 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
|