Ver a proveniência

MudSystem and StudentStation DS Added

najafi
mahmood19227 há 1 ano
ascendente
cometimento
2e6cf9bebf
36 ficheiros alterados com 3226 adições e 3374 eliminações
  1. +2
    -2
      CSharp/OperationScenarios/Permissions/CIrIbopPermission.f90
  2. +2
    -2
      CSharp/OperationScenarios/Permissions/CIrSafetyValvePermission.f90
  3. +3
    -3
      CSharp/OperationScenarios/UnitySignals/CBucketEnum.f90
  4. +6
    -6
      CSharp/OperationScenarios/UnitySignals/CHeadEnum.f90
  5. +12
    -12
      CSharp/Problems/CGaugesProblemsVariables.f90
  6. +0
    -98
      CSharp/StudentStation/CStudentStation.f90
  7. +13
    -8
      CSharp/StudentStation/CStudentStationVariables.f90
  8. +1
    -1
      Data Structures.txt
  9. +52
    -61
      Equipments/MudSystem/Circulation_Code_Select.f90
  10. +114
    -117
      Equipments/MudSystem/Deallocate_Normal_Circulation.f90
  11. +26
    -26
      Equipments/MudSystem/Disconnecting_Pipe.f90
  12. +131
    -131
      Equipments/MudSystem/Elements_Creation.f90
  13. +59
    -59
      Equipments/MudSystem/FillingWell_By_BellNipple.f90
  14. +36
    -37
      Equipments/MudSystem/Kick_Expansion_and_Contraction.f90
  15. +48
    -48
      Equipments/MudSystem/Kick_Influx.f90
  16. +404
    -409
      Equipments/MudSystem/Kick_Migration.f90
  17. +352
    -363
      Equipments/MudSystem/MudSystem.f90
  18. +3
    -3
      Equipments/MudSystem/MudSystemMain.f90
  19. +176
    -176
      Equipments/MudSystem/MudSystemStartup.f90
  20. +150
    -170
      Equipments/MudSystem/MudSystem_Variables.f90
  21. +142
    -144
      Equipments/MudSystem/Plot_Final_Mud_Elements.f90
  22. +543
    -543
      Equipments/MudSystem/Pump_and_Trip_In.f90
  23. +483
    -486
      Equipments/MudSystem/Trip_Out_andPump.f90
  24. +175
    -175
      Equipments/MudSystem/Utube1_and_Trip_In.f90
  25. +164
    -164
      Equipments/MudSystem/Utube2_and_Trip_In.f90
  26. +1
    -1
      Equipments/Pumps/Pumps_Inputs.f90
  27. +2
    -2
      Equipments/Pumps/Pumps_Outputs.f90
  28. +13
    -13
      FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90
  29. +1
    -1
      FluidFlow/Fluid_Flow_Solver.f90
  30. +44
    -44
      FluidFlow/Horizontal_and_String_Pressure_Distribution.f90
  31. +60
    -60
      FluidFlow/Well_Pressure_Data_Transfer.f90
  32. +1
    -1
      FluidFlow/kick/Formation_Information.f90
  33. +4
    -4
      FluidFlow/kick/Gas_Kick_Calculator.f90
  34. +1
    -1
      Rop/JetImpactForce.f90
  35. +2
    -2
      Rop/ROP_MainCalculation.f90
  36. +0
    -1
      SimulationCore2.vfproj

+ 2
- 2
CSharp/OperationScenarios/Permissions/CIrIbopPermission.f90 Ver ficheiro

@@ -5,7 +5,7 @@ module CIrIbopPermission
subroutine Evaluate_IrIbopPermission()
use TD_DrillStemComponents
use CStudentStationVariables, only: FillupHeadInstallation
use CStudentStationVariables!, only: StudentStation%FillupHeadInstallation
implicit none
@@ -20,7 +20,7 @@ module CIrIbopPermission
Get_NearFloorConnection() >= 3 .and. Get_NearFloorConnection() <= 10 .and.&
Get_JointConnectionPossible() == .false. .and.&
Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.&
FillupHeadInstallation == .false.) then
StudentStation%FillupHeadInstallation == .false.) then
call Set_IrIbopPermission(.true.)
return


+ 2
- 2
CSharp/OperationScenarios/Permissions/CIrSafetyValvePermission.f90 Ver ficheiro

@@ -5,7 +5,7 @@ module CIrSafetyValvePermission
subroutine Evaluate_IrSafetyValvePermission()
use TD_DrillStemComponents
use CStudentStationVariables, only: FillupHeadInstallation
use CStudentStationVariables!!, only: StudentStation%FillupHeadInstallation
implicit none
@@ -23,7 +23,7 @@ module CIrSafetyValvePermission
(Get_NearFloorConnection() >= 3.0 .and. Get_NearFloorConnection() <= 10.0) .and.&
Get_JointConnectionPossible() == .false. .and.&
Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.&
FillupHeadInstallation == .false.) then
StudentStation%FillupHeadInstallation == .false.) then
call Set_IrSafetyValvePermission(.true.)
return


+ 3
- 3
CSharp/OperationScenarios/UnitySignals/CBucketEnum.f90 Ver ficheiro

@@ -4,7 +4,7 @@ module CBucketEnum
contains
subroutine Evaluate_MudBucket()
use CStudentStationVariables, only: MudBoxInstallation
use CStudentStationVariables!, only: StudentStation%MudBoxInstallation
implicit none
@@ -25,9 +25,9 @@ module CBucketEnum
if (Get_MudBucket() == MUD_BUCKET_INSTALL) then
MudBoxInstallation = .true.
StudentStation%MudBoxInstallation = .true.
else if (Get_MudBucket() == MUD_BUCKET_REMOVE) then
MudBoxInstallation = .false.
StudentStation%MudBoxInstallation = .false.
endif
end subroutine


+ 6
- 6
CSharp/OperationScenarios/UnitySignals/CHeadEnum.f90 Ver ficheiro

@@ -4,7 +4,7 @@ module CHeadEnum
contains
subroutine Evaluate_FillupHead()
use CStudentStationVariables, only: FillupHeadInstallation
use CStudentStationVariables!, only: StudentStation%FillupHeadInstallation
implicit none
@@ -27,9 +27,9 @@ module CHeadEnum
if (Get_FillupHead() == FILLUP_HEAD_INSTALL) then
FillupHeadInstallation = .true.
StudentStation%FillupHeadInstallation = .true.
else if (Get_FillupHead() == FILLUP_HEAD_REMOVE) then
FillupHeadInstallation = .false.
StudentStation%FillupHeadInstallation = .false.
endif
end subroutine
@@ -37,7 +37,7 @@ module CHeadEnum
! subroutine Subscribe_FillupHead()
! use CStudentStationVariables
! implicit none
! call OnFillupHeadInstallationPress%Add(ButtonPress_FillupHeadInstallation)
! call OnStudentStation%FillupHeadInstallationPress%Add(ButtonPress_StudentStation%FillupHeadInstallation)
! call OnFillupHeadRemovePress%Add(ButtonPress_FillupHeadRemove)
! end subroutine
@@ -50,7 +50,7 @@ module CHeadEnum
if (Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
print*, 'ButtonPress_FillupHeadInstallation=TopDrive'
print*, 'ButtonPress_StudentStation%FillupHeadInstallation=TopDrive'
#endif


@@ -72,7 +72,7 @@ module CHeadEnum
if (Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
print*, 'ButtonPress_FillupHeadInstallation=Kelly'
print*, 'ButtonPress_StudentStation%FillupHeadInstallation=Kelly'
#endif




+ 12
- 12
CSharp/Problems/CGaugesProblemsVariables.f90 Ver ficheiro

@@ -210,8 +210,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(StandPipePressurePtr)) call StandPipePressurePtr(status)
if(status == Clear_StatusType) StandPipePressure_DataDisplayMalf = 0
if(status == Executed_StatusType) StandPipePressure_DataDisplayMalf = 1
if(status == Clear_StatusType) MudSystem%StandPipePressure_DataDisplayMalf = 0
if(status == Executed_StatusType) MudSystem%StandPipePressure_DataDisplayMalf = 1
endsubroutine
subroutine ChangeCasingPressure(status)
@@ -254,8 +254,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(TripTankPtr)) call TripTankPtr(status)
if(status == Clear_StatusType) TripTankPressure_DataDisplayMalf = 0
if(status == Executed_StatusType) TripTankPressure_DataDisplayMalf = 1
if(status == Clear_StatusType) MudSystem%TripTankPressure_DataDisplayMalf = 0
if(status == Executed_StatusType) MudSystem%TripTankPressure_DataDisplayMalf = 1
endsubroutine
subroutine ChangePitGainLoss(status)
@@ -263,8 +263,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(PitGainLossPtr)) call PitGainLossPtr(status)
if(status == Clear_StatusType) PitGainLossGaugeMalf = 0
if(status == Executed_StatusType) PitGainLossGaugeMalf = 1
if(status == Clear_StatusType) MudSystem%PitGainLossGaugeMalf = 0
if(status == Executed_StatusType) MudSystem%PitGainLossGaugeMalf = 1
endsubroutine
subroutine ChangeMudTankVolume(status)
@@ -341,8 +341,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(StandPipe1Ptr)) call StandPipe1Ptr(status)
if(status == Clear_StatusType) StandPipeGauge1Malf = 0
if(status == Executed_StatusType) StandPipeGauge1Malf = 1
if(status == Clear_StatusType) MudSystem%StandPipeGauge1Malf = 0
if(status == Executed_StatusType) MudSystem%StandPipeGauge1Malf = 1
endsubroutine
subroutine ChangeStandPipe2(status)
@@ -350,8 +350,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(StandPipe2Ptr)) call StandPipe2Ptr(status)
if(status == Clear_StatusType) StandPipeGauge2Malf = 0
if(status == Executed_StatusType) StandPipeGauge2Malf = 1
if(status == Clear_StatusType) MudSystem%StandPipeGauge2Malf = 0
if(status == Executed_StatusType) MudSystem%StandPipeGauge2Malf = 1
endsubroutine
subroutine ChangeDrillPipePressure(status)
@@ -359,8 +359,8 @@ module CGaugesProblemsVariables
implicit none
integer, intent (in) :: status
! if(associated(DrillPipePressurePtr)) call DrillPipePressurePtr(status)
if(status == Clear_StatusType) DrillPipePressureMalf = 0
if(status == Executed_StatusType) DrillPipePressureMalf = 1
if(status == Clear_StatusType) MudSystem%DrillPipePressureMalf = 0
if(status == Executed_StatusType) MudSystem%DrillPipePressureMalf = 1
endsubroutine
subroutine ChangeChokePosition(status)


+ 0
- 98
CSharp/StudentStation/CStudentStation.f90 Ver ficheiro

@@ -1,98 +0,0 @@
module CStudentStation
use CStudentStationVariables
use CManifolds
implicit none
public
contains
! Input routines
subroutine SetFillupHeadInstallation(v)
!DEC$ ATTRIBUTES DLLEXPORT :: SetFillupHeadInstallation
!DEC$ ATTRIBUTES ALIAS: 'SetFillupHeadInstallation' :: SetFillupHeadInstallation
implicit none
logical, intent(in) :: v
FillupHeadInstallation = v
if(v)then
call OnFillupHeadInstallationPress%RunAll()
else
call OnFillupHeadRemovePress%RunAll()
endif
#ifdef deb
print*, 'FillupHeadInstallation=', FillupHeadInstallation
#endif
end subroutine

subroutine SetMudBoxInstallation(v)
!DEC$ ATTRIBUTES DLLEXPORT :: SetMudBoxInstallation
!DEC$ ATTRIBUTES ALIAS: 'SetMudBoxInstallation' :: SetMudBoxInstallation
implicit none
logical, intent(in) :: v
MudBoxInstallation = v
if(v)then
call OnMudBoxInstallationPress%RunAll()
else
call OnMudBoxRemovePress%RunAll()
endif
#ifdef deb
print*, 'MudBoxInstallation=', MudBoxInstallation
#endif
end subroutine


subroutine SetTapSelector(v)
!DEC$ ATTRIBUTES DLLEXPORT :: SetTapSelector
!DEC$ ATTRIBUTES ALIAS: 'SetTapSelector' :: SetTapSelector
implicit none
logical, intent(in) :: v
TapSelector = v
#ifdef deb
print*, 'TapSelector=', TapSelector
#endif
end subroutine
subroutine SetPitGainLossZero(v)
!DEC$ ATTRIBUTES DLLEXPORT :: SetPitGainLossZero
!DEC$ ATTRIBUTES ALIAS: 'SetPitGainLossZero' :: SetPitGainLossZero
implicit none
logical, intent(in) :: v
PitGainLossZero = v
#ifdef deb
print*, 'PitGainLossZero=', PitGainLossZero
#endif
end subroutine
! Output routines
logical function GetFillupHeadInstallation()
!DEC$ ATTRIBUTES DLLEXPORT :: GetFillupHeadInstallation
!DEC$ ATTRIBUTES ALIAS: 'GetFillupHeadInstallation' :: GetFillupHeadInstallation
implicit none
GetFillupHeadInstallation = FillupHeadInstallation
!GetFillupHeadInstallation = .true.
end function

logical function GetMudBoxInstallation()
!DEC$ ATTRIBUTES DLLEXPORT :: GetMudBoxInstallation
!DEC$ ATTRIBUTES ALIAS: 'GetMudBoxInstallation' :: GetMudBoxInstallation
implicit none
GetMudBoxInstallation = MudBoxInstallation
!GetMudBoxInstallation = .true.
end function
!logical function GetTapSelector()
!!DEC$ ATTRIBUTES DLLEXPORT :: GetTapSelector
!!DEC$ ATTRIBUTES ALIAS: 'GetTapSelector' :: GetTapSelector
! implicit none
! GetTapSelector = TapSelector
!end function

end module CStudentStation

+ 13
- 8
CSharp/StudentStation/CStudentStationVariables.f90 Ver ficheiro

@@ -4,17 +4,22 @@ module CStudentStationVariables
public
! Input vars
logical :: FillupHeadInstallation
type(VoidEventHandlerCollection) :: OnFillupHeadInstallationPress
type(VoidEventHandlerCollection) :: OnFillupHeadRemovePress
type StudentStationType
logical :: FillupHeadInstallation
logical :: PitGainLossZero
logical :: MudBoxInstallation
logical :: TapSelector
end type StudentStationType
type(StudentStationType)::StudentStation
! type(VoidEventHandlerCollection) :: OnStudentStation%FillupHeadInstallationPress
! type(VoidEventHandlerCollection) :: OnFillupHeadRemovePress
logical :: MudBoxInstallation
type(VoidEventHandlerCollection) :: OnMudBoxInstallationPress
type(VoidEventHandlerCollection) :: OnMudBoxRemovePress
! type(VoidEventHandlerCollection) :: OnMudBoxInstallationPress
! type(VoidEventHandlerCollection) ::

logical :: TapSelector
logical :: PitGainLossZero
! Output vars
contains

+ 1
- 1
Data Structures.txt Ver ficheiro

@@ -89,5 +89,5 @@ Equipments:
AirDrivenPump
AirPumpLine
CHOOKE (previously exists)
MudSystem:.........
MudSystem:

+ 52
- 61
Equipments/MudSystem/Circulation_Code_Select.f90 Ver ficheiro

@@ -15,11 +15,11 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver
implicit none
Integer i
Integer i,KickNumber
!NewInfluxNumber = NoGasPocket
MudSystemDotFlow_timeCounter= MudSystemDotFlow_timeCounter+1
MudSystem%Flow_timeCounter= MudSystem%Flow_timeCounter+1
!if (ChokePanelStrokeResetSwitch == 1) then
! Flow_timeCounter= 0
@@ -35,7 +35,7 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver
!===================================================================
MudSystemDotiLoc= 1 ! will be changed in KickFlux and Migration or Pump and TripIn (save OP Mud data)
MudSystem%iLoc= 1 ! will be changed in KickFlux and Migration or Pump and TripIn (save OP Mud data)
!KickMigration_2SideBit= .false.
Call Set_FlowPipeDisconnect(.false.)
Call Set_FlowKellyDisconnect(.false.)
@@ -60,99 +60,90 @@ subroutine CirculationCodeSelect ! is called in subroutine Fluid_Flow_Solver
IF ( MudSystemDotNewInfluxNumber > 0 ) THEN
IF ( MudSystem%NewInfluxNumber > 0 ) THEN
!write(*,*) 'KickOffBottom , ROP=' , KickOffBottom , Rate_of_Penetration
call Kick_Migration
endif
! ============================ must be after migration ==============================

DO MudSystemDotKickNumber= MudSystemDotNewInfluxNumber-NoGasPocket+1 , MudSystemDotNewInfluxNumber
DO KickNumber= MudSystem%NewInfluxNumber-NoGasPocket+1 , MudSystem%NewInfluxNumber
! FINDING NEW KICK LOCATIONS:
MudSystemDotAnn_KickLoc= 0
MudSystemDotOp_KickLoc= 0
MudSystemDotChokeLine_KickLoc= 0
MudSystem%Ann_KickLoc= 0
MudSystem%Op_KickLoc= 0
MudSystem%ChokeLine_KickLoc= 0
do i = 1, Ann_MudOrKick%Length ()
if (Ann_MudOrKick%Array(i) == MudSystemDotKickNumber) then
MudSystemDotAnn_KickLoc = i
do i = 1, MudSystem%Ann_MudOrKick%Length ()
if (MudSystem%Ann_MudOrKick%Array(i) == KickNumber) then
MudSystem%Ann_KickLoc = i
exit
endif
end do

do i = 1, Op_MudOrKick%Length ()
if (Op_MudOrKick%Array(i) == MudSystemDotKickNumber) then
MudSystemDotOp_KickLoc = i
do i = 1, MudSystem%Op_MudOrKick%Length ()
if (MudSystem%Op_MudOrKick%Array(i) == KickNumber) then
MudSystem%Op_KickLoc = i
exit
endif
end do
do i = 1, ChokeLine_MudOrKick%Length ()
if (ChokeLine_MudOrKick%Array(i) == MudSystemDotKickNumber) then
MudSystemDotChokeLine_KickLoc = i
do i = 1, MudSystem%ChokeLine_MudOrKick%Length ()
if (MudSystem%ChokeLine_MudOrKick%Array(i) == KickNumber) then
MudSystem%ChokeLine_KickLoc = i
exit
endif
end do
! ============================ must be after migration-end ===========================
! ============================ must be after migration-end ===========================
IF (ALLOCATED(GasPocketWeight%Array) .and. MudSystemDotKickNumber == MudSystemDotNewInfluxNumber .AND. NOT(KickOffBottom) .AND. WellHeadIsOpen) THEN
IF (ALLOCATED(GasPocketWeight%Array) .and. KickNumber == MudSystem%NewInfluxNumber .AND. NOT(KickOffBottom) .AND. MudSystem%WellHeadIsOpen) THEN

cycle
ELSE IF (ALLOCATED(GasPocketWeight%Array)) THEN
if (((GasPocketDeltaVol%Array(MudSystemDotNewInfluxNumber - MudSystemDotKickNumber + 1) > 0.0 .AND. WellHeadIsOpen) .or. MudSystemDotKickexpansion_DueToMudLost) ) call Kick_Expansion
cycle
ELSE IF (ALLOCATED(GasPocketWeight%Array)) THEN
if ((GasPocketDeltaVol%Array(MudSystemDotNewInfluxNumber - MudSystemDotKickNumber + 1) < 0.0 ) .OR. WellHeadIsOpen == .FALSE.) CALL Kick_Contraction
if (((GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - KickNumber + 1) > 0.0 .AND. MudSystem%WellHeadIsOpen) .or. MudSystem%Kickexpansion_DueToMudLost) ) call Kick_Expansion
if ((GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - KickNumber + 1) < 0.0 ) .OR. MudSystem%WellHeadIsOpen == .FALSE.) CALL Kick_Contraction

ENDIF
ENDDO
ENDIF
ENDDO
MudSystem%KickNumber = KickNumber
MudSystem%LostInTripOutIsDone= .false.
if( MudSystem%DeltaVolumeOp >= 0.0 .and. Get_KellyConnection()==KELLY_CONNECTION_STRING) then
!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
call Pump_and_TripIn
elseif (MudSystem%DeltaVolumeOp < 0.0) then
! when we have Utube and tripping out simultaneously, it uses "TripOut_and_Pump" subroutine, and then Utube code is done
! "Utube" and "Pump_and_TripIn" subroutines, not to be used simultaneously because "Utube" code supports trip in
call TripOut_and_Pump
endif
MudSystemDotLostInTripOutIsDone= .false.
if( MudSystemDotDeltaVolumeOp >= 0.0 .and. Get_KellyConnection()==KELLY_CONNECTION_STRING) then
!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
call Pump_and_TripIn
elseif (MudSystemDotDeltaVolumeOp < 0.0) then
! when we have Utube and tripping out simultaneously, it uses "TripOut_and_Pump" subroutine, and then Utube code is done
! "Utube" and "Pump_and_TripIn" subroutines, not to be used simultaneously because "Utube" code supports trip in
call TripOut_and_Pump
endif
WellOutletDensity= Ann_Density%Last() ! (ppg) used in MudSystem
MudSystem%WellOutletDensity= MudSystem%Ann_Density%Last() ! (ppg) used in MudSystem
if (MUD(4)%Q > 0.) then ! ( j4 > 0 ) ! THIS CIRCULATION CODE IS JUST FOR LINE J4, AND NOT NEEDED FOR LINE J18
call ChokeLineMud
endif
if (MUD(4)%Q > 0.) then ! ( j4 > 0 ) ! THIS CIRCULATION CODE IS JUST FOR LINE J4, AND NOT NEEDED FOR LINE J18
call ChokeLineMud
endif
call Choke_GasSound
!WRITE(*,*) 'CIRCU-Ann_Saved_MudDischarged_Volume' , Ann_Saved_MudDischarged_Volume
call Choke_GasSound
! ****Utube is called in Plot Subroutine****
!WRITE(*,*) 'CIRCU-Ann_Saved_MudDischarged_Volume' , Ann_Saved_MudDischarged_Volume
Call Instructor_CirculationMud_Edit
!****Utube is called in Plot Subroutine****
Call Instructor_CirculationMud_Edit
call PlotFinalMudElements
MudChecked= .true.
MudSystemDotUtubePossibility= .true.

!WRITE(*,*) '***********************************************************************'


call PlotFinalMudElements
MudSystem%MudChecked= .true.
MudSystem%UtubePossibility= .true.
!WRITE(*,*) '***********************************************************************'
end subroutine CirculationCodeSelect

+ 114
- 117
Equipments/MudSystem/Deallocate_Normal_Circulation.f90 Ver ficheiro

@@ -3,99 +3,96 @@ subroutine DEALLOCATE_ARRAYS_NormalCirculation() ! is called in module Fluid
implicit none


if(allocated(MudSystemDotXstart_PipeSection)) deallocate(MudSystemDotXstart_PipeSection)
if(allocated(MudSystemDotXend_PipeSection)) deallocate(MudSystemDotXend_PipeSection)
if(allocated(MudSystemDotPipeSection_VolumeCapacity)) deallocate(MudSystemDotPipeSection_VolumeCapacity)
if(allocated(MudSystemDotArea_PipeSectionFt)) deallocate(MudSystemDotArea_PipeSectionFt)
if(allocated(MudSystemDotOD_PipeSectionInch)) deallocate(MudSystemDotOD_PipeSectionInch)
if(allocated(MudSystemDotID_PipeSectionInch)) deallocate(MudSystemDotID_PipeSectionInch)
if(allocated(MudSystemDotXstart_OpSection)) deallocate(MudSystemDotXstart_OpSection)
if(allocated(MudSystemDotXend_OpSection)) deallocate(MudSystemDotXend_OpSection)
if(allocated(MudSystemDotArea_OpSectionFt)) deallocate(MudSystemDotArea_OpSectionFt)
if(allocated(MudSystemDotOD_OpSectionInch)) deallocate(MudSystemDotOD_OpSectionInch)
if(allocated(MudSystemDotID_OpSectionInch)) deallocate(MudSystemDotID_OpSectionInch)
if(allocated(MudSystemDotOpSection_VolumeCapacity)) deallocate(MudSystemDotOpSection_VolumeCapacity)
if(allocated(MudSystemDotGeoTypeOp)) deallocate(MudSystemDotGeoTypeOp)
if(allocated(MudSystemDotGeoType)) deallocate(MudSystemDotGeoType)
if(allocated(MudSystem%Xstart_PipeSection)) deallocate(MudSystem%Xstart_PipeSection)
if(allocated(MudSystem%Xend_PipeSection)) deallocate(MudSystem%Xend_PipeSection)
if(allocated(MudSystem%PipeSection_VolumeCapacity)) deallocate(MudSystem%PipeSection_VolumeCapacity)
if(allocated(MudSystem%Area_PipeSectionFt)) deallocate(MudSystem%Area_PipeSectionFt)
if(allocated(MudSystem%OD_PipeSectionInch)) deallocate(MudSystem%OD_PipeSectionInch)
if(allocated(MudSystem%ID_PipeSectionInch)) deallocate(MudSystem%ID_PipeSectionInch)
if(allocated(MudSystem%Xstart_OpSection)) deallocate(MudSystem%Xstart_OpSection)
if(allocated(MudSystem%Xend_OpSection)) deallocate(MudSystem%Xend_OpSection)
if(allocated(MudSystem%Area_OpSectionFt)) deallocate(MudSystem%Area_OpSectionFt)
if(allocated(MudSystem%OD_OpSectionInch)) deallocate(MudSystem%OD_OpSectionInch)
if(allocated(MudSystem%ID_OpSectionInch)) deallocate(MudSystem%ID_OpSectionInch)
if(allocated(MudSystem%OpSection_VolumeCapacity)) deallocate(MudSystem%OpSection_VolumeCapacity)
if(allocated(MudSystem%GeoTypeOp)) deallocate(MudSystem%GeoTypeOp)
if(allocated(MudSystem%GeoType)) deallocate(MudSystem%GeoType)


call MudSystemDotHz_MudDischarged_Volume%Empty()
call MudSystemDotHz_Mud_Backhead_X%Empty()
call Hz_Mud_Backhead_section%Empty()
call MudSystemDotHz_Mud_Forehead_X%Empty()
call Hz_Mud_Forehead_section%Empty()
call MudSystemDotHz_Density%Empty()
call MudSystemDotHz_RemainedVolume_in_LastSection%Empty()
call MudSystemDotHz_EmptyVolume_inBackheadLocation%Empty()
call Hz_MudOrKick%Empty()
call MudSystem%Hz_MudDischarged_Volume%Empty()
call MudSystem%Hz_Mud_Backhead_X%Empty()
call MudSystem%Hz_Mud_Backhead_section%Empty()
call MudSystem%Hz_Mud_Forehead_X%Empty()
call MudSystem%Hz_Mud_Forehead_section%Empty()
call MudSystem%Hz_Density%Empty()
call MudSystem%Hz_RemainedVolume_in_LastSection%Empty()
call MudSystem%Hz_EmptyVolume_inBackheadLocation%Empty()
call MudSystem%Hz_MudOrKick%Empty()
call MudSystemDotSt_MudDischarged_Volume%Empty()
call MudSystemDotSt_Mud_Backhead_X%Empty()
call St_Mud_Backhead_section%Empty()
call MudSystemDotSt_Mud_Forehead_X%Empty()
call St_Mud_Forehead_section%Empty()
call St_Density%Empty()
call MudSystemDotSt_RemainedVolume_in_LastSection%Empty()
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Empty()
call St_MudOrKick%Empty()
call MudSystem%St_MudDischarged_Volume%Empty()
call MudSystem%St_Mud_Backhead_X%Empty()
call MudSystem%St_Mud_Backhead_section%Empty()
call MudSystem%St_Mud_Forehead_X%Empty()
call MudSystem%St_Mud_Forehead_section%Empty()
call MudSystem%St_Density%Empty()
call MudSystem%St_RemainedVolume_in_LastSection%Empty()
call MudSystem%St_EmptyVolume_inBackheadLocation%Empty()
call MudSystem%St_MudOrKick%Empty()
call MudSystemDotAnn_MudDischarged_Volume%Empty()
call Ann_Mud_Backhead_X%Empty()
call Ann_Mud_Backhead_section%Empty()
call Ann_Mud_Forehead_X%Empty()
call Ann_Mud_Forehead_section%Empty()
call Ann_Density%Empty()
call Ann_RemainedVolume_in_LastSection%Empty()
call Ann_EmptyVolume_inBackheadLocation%Empty()
call Ann_MudOrKick%Empty()
call Ann_CuttingMud%Empty()
call MudSystem%Ann_MudDischarged_Volume%Empty()
call MudSystem%Ann_Mud_Backhead_X%Empty()
call MudSystem%Ann_Mud_Backhead_section%Empty()
call MudSystem%Ann_Mud_Forehead_X%Empty()
call MudSystem%Ann_Mud_Forehead_section%Empty()
call MudSystem%Ann_Density%Empty()
call MudSystem%Ann_RemainedVolume_in_LastSection%Empty()
call MudSystem%Ann_EmptyVolume_inBackheadLocation%Empty()
call MudSystem%Ann_MudOrKick%Empty()
call MudSystem%Ann_CuttingMud%Empty()
call MudSystemDotOp_MudDischarged_Volume%Empty()
call MudSystemDotOp_Mud_Backhead_X%Empty()
call Op_Mud_Backhead_section%Empty()
call MudSystemDotOp_Mud_Forehead_X%Empty()
call Op_Mud_Forehead_section%Empty()
call MudSystemDotOp_Density%Empty()
call MudSystemDotOp_RemainedVolume_in_LastSection%Empty()
call MudSystemDotOp_EmptyVolume_inBackheadLocation%Empty()
call Op_MudOrKick%Empty()
call MudSystem%Op_MudDischarged_Volume%Empty()
call MudSystem%Op_Mud_Backhead_X%Empty()
call MudSystem%Op_Mud_Backhead_section%Empty()
call MudSystem%Op_Mud_Forehead_X%Empty()
call MudSystem%Op_Mud_Forehead_section%Empty()
call MudSystem%Op_Density%Empty()
call MudSystem%Op_RemainedVolume_in_LastSection%Empty()
call MudSystem%Op_EmptyVolume_inBackheadLocation%Empty()
call MudSystem%Op_MudOrKick%Empty()

call MudSystemDotChokeLine_MudDischarged_Volume%Empty()
call MudSystemDotChokeLine_Mud_Backhead_X%Empty()
call ChokeLine_Mud_Backhead_section%Empty()
call MudSystemDotChokeLine_Mud_Forehead_X%Empty()
call ChokeLine_Mud_Forehead_section%Empty()
call MudSystemDotChokeLine_Density%Empty()
call MudSystemDotChokeLine_RemainedVolume_in_LastSection%Empty()
call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%Empty()
call ChokeLine_MudOrKick%Empty()
call MudSystem%ChokeLine_MudDischarged_Volume%Empty()
call MudSystem%ChokeLine_Mud_Backhead_X%Empty()
call MudSystem%ChokeLine_Mud_Backhead_section%Empty()
call MudSystem%ChokeLine_Mud_Forehead_X%Empty()
call MudSystem%ChokeLine_Mud_Forehead_section%Empty()
call MudSystem%ChokeLine_Density%Empty()
call MudSystem%ChokeLine_RemainedVolume_in_LastSection%Empty()
call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Empty()
call MudSystem%ChokeLine_MudOrKick%Empty()
call Xend_MudElement%Empty()
call Xstart_MudElement%Empty()
call TVDend_MudElement%Empty()
call TVDstart_MudElement%Empty()
call Density_MudElement%Empty()
call MudGeoType%Empty()
call PipeID_MudElement%Empty()
call PipeOD_MudElement%Empty()
call MudType_MudElement%Empty()
call MudSystem%Xend_MudElement%Empty()
call MudSystem%Xstart_MudElement%Empty()
call MudSystem%TVDend_MudElement%Empty()
call MudSystem%TVDstart_MudElement%Empty()
call MudSystem%Density_MudElement%Empty()
call MudSystem%MudGeoType%Empty()
call MudSystem%PipeID_MudElement%Empty()
call MudSystem%PipeOD_MudElement%Empty()
call MudSystem%MudType_MudElement%Empty()
call Xend_OpMudElement%Empty()
call Xstart_OpMudElement%Empty()
call TVDend_OpMudElement%Empty()
call TVDstart_OPMudElement%Empty()
call Density_OpMudElement%Empty()
call PipeID_OpMudElement%Empty()
call PipeOD_OpMudElement%Empty()
call MudTypeOp_MudElement%Empty()

call MudSystem%Xend_OpMudElement%Empty()
call MudSystem%Xstart_OpMudElement%Empty()
call MudSystem%TVDend_OpMudElement%Empty()
call MudSystem%TVDstart_OpMudElement%Empty()
call MudSystem%Density_OpMudElement%Empty()
call MudSystem%PipeID_OpMudElement%Empty()
call MudSystem%PipeOD_OpMudElement%Empty()
call MudSystem%MudTypeOp_MudElement%Empty()
end subroutine
@@ -107,16 +104,16 @@ subroutine RemoveAnnulusMudArrays(ilocal)
INTEGER :: ilocal
call MudSystemDotAnn_MudDischarged_Volume%Remove (ilocal)
call Ann_Mud_Backhead_X%Remove (ilocal)
call Ann_Mud_Backhead_section%Remove (ilocal)
call Ann_Mud_Forehead_X%Remove (ilocal)
call Ann_Mud_Forehead_section%Remove (ilocal)
call Ann_Density%Remove (ilocal)
call Ann_RemainedVolume_in_LastSection%Remove (ilocal)
call Ann_EmptyVolume_inBackheadLocation%Remove (ilocal)
call Ann_MudOrKick%Remove (ilocal)
call Ann_CuttingMud%Remove (ilocal)
call MudSystem%Ann_MudDischarged_Volume%Remove (ilocal)
call MudSystem%Ann_Mud_Backhead_X%Remove (ilocal)
call MudSystem%Ann_Mud_Backhead_section%Remove (ilocal)
call MudSystem%Ann_Mud_Forehead_X%Remove (ilocal)
call MudSystem%Ann_Mud_Forehead_section%Remove (ilocal)
call MudSystem%Ann_Density%Remove (ilocal)
call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (ilocal)
call MudSystem%Ann_MudOrKick%Remove (ilocal)
call MudSystem%Ann_CuttingMud%Remove (ilocal)
@@ -130,15 +127,15 @@ subroutine RemoveStringMudArrays(ilocal)
INTEGER :: ilocal
call MudSystemDotSt_MudDischarged_Volume%Remove (ilocal)
call MudSystemDotSt_Mud_Backhead_X%Remove (ilocal)
call St_Mud_Backhead_section%Remove (ilocal)
call MudSystemDotSt_Mud_Forehead_X%Remove (ilocal)
call St_Mud_Forehead_section%Remove (ilocal)
call St_Density%Remove (ilocal)
call MudSystemDotSt_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Remove (ilocal)
call St_MudOrKick%Remove (ilocal)
call MudSystem%St_MudDischarged_Volume%Remove (ilocal)
call MudSystem%St_Mud_Backhead_X%Remove (ilocal)
call MudSystem%St_Mud_Backhead_section%Remove (ilocal)
call MudSystem%St_Mud_Forehead_X%Remove (ilocal)
call MudSystem%St_Mud_Forehead_section%Remove (ilocal)
call MudSystem%St_Density%Remove (ilocal)
call MudSystem%St_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystem%St_EmptyVolume_inBackheadLocation%Remove (ilocal)
call MudSystem%St_MudOrKick%Remove (ilocal)
@@ -152,15 +149,15 @@ subroutine RemoveOpMudArrays(ilocal)
INTEGER :: ilocal
call MudSystemDotOp_MudDischarged_Volume%Remove (ilocal)
call MudSystemDotOp_Mud_Backhead_X%Remove (ilocal)
call Op_Mud_Backhead_section%Remove (ilocal)
call MudSystemDotOp_Mud_Forehead_X%Remove (ilocal)
call Op_Mud_Forehead_section%Remove (ilocal)
call MudSystemDotOp_Density%Remove (ilocal)
call MudSystemDotOp_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystemDotOp_EmptyVolume_inBackheadLocation%Remove (ilocal)
call Op_MudOrKick%Remove (ilocal)
call MudSystem%Op_MudDischarged_Volume%Remove (ilocal)
call MudSystem%Op_Mud_Backhead_X%Remove (ilocal)
call MudSystem%Op_Mud_Backhead_section%Remove (ilocal)
call MudSystem%Op_Mud_Forehead_X%Remove (ilocal)
call MudSystem%Op_Mud_Forehead_section%Remove (ilocal)
call MudSystem%Op_Density%Remove (ilocal)
call MudSystem%Op_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (ilocal)
call MudSystem%Op_MudOrKick%Remove (ilocal)
@@ -173,15 +170,15 @@ subroutine RemoveHzMudArrays(ilocal)
INTEGER :: ilocal
call MudSystemDotHz_MudDischarged_Volume%Remove (ilocal)
call MudSystemDotHz_Mud_Backhead_X%Remove (ilocal)
call Hz_Mud_Backhead_section%Remove (ilocal)
call MudSystemDotHz_Mud_Forehead_X%Remove (ilocal)
call Hz_Mud_Forehead_section%Remove (ilocal)
call MudSystemDotHz_Density%Remove (ilocal)
call MudSystemDotHz_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystemDotHz_EmptyVolume_inBackheadLocation%Remove (ilocal)
call Hz_MudOrKick%Remove (ilocal)
call MudSystem%Hz_MudDischarged_Volume%Remove (ilocal)
call MudSystem%Hz_Mud_Backhead_X%Remove (ilocal)
call MudSystem%Hz_Mud_Backhead_section%Remove (ilocal)
call MudSystem%Hz_Mud_Forehead_X%Remove (ilocal)
call MudSystem%Hz_Mud_Forehead_section%Remove (ilocal)
call MudSystem%Hz_Density%Remove (ilocal)
call MudSystem%Hz_RemainedVolume_in_LastSection%Remove (ilocal)
call MudSystem%Hz_EmptyVolume_inBackheadLocation%Remove (ilocal)
call MudSystem%Hz_MudOrKick%Remove (ilocal)


+ 26
- 26
Equipments/MudSystem/Disconnecting_Pipe.f90 Ver ficheiro

@@ -21,7 +21,7 @@ subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect
!TD_RemoveVolume= TD_RemoveVolume* 7.48051948 ! ft^3 to gal

ExcessMudVolume= sum(MudSystemDotSt_MudDischarged_Volume%Array(:)) - sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts))
ExcessMudVolume= sum(MudSystem%St_MudDischarged_Volume%Array(:)) - sum(MudSystem%PipeSection_VolumeCapacity(2:F_StringIntervalCounts))
! ======if(ExcessMudVolume <= 0.) No Modification Needed Because Removed Pipe was Empty=====
@@ -31,9 +31,9 @@ subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect
if (ExcessMudVolume > 0.) then
if ( Manifold%Valve(53)%Status == .true. ) then
MudBucketVolume= ExcessMudVolume
MudSystem%MudBucketVolume= ExcessMudVolume
else
MudBucketVolume= 0.0
MudSystem%MudBucketVolume= 0.0
endif
@@ -62,36 +62,36 @@ subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect
ExcessMudVolume_Remained= ExcessMudVolume ! ft^3 to gal
MudSystemDotimud=1
imud=1
Do
if(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) < ExcessMudVolume_Remained) then
ExcessMudVolume_Remained= ExcessMudVolume_Remained- MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)
call MudSystemDotSt_MudDischarged_Volume%Remove (MudSystemDotimud)
call MudSystemDotSt_Mud_Backhead_X%Remove (MudSystemDotimud)
call St_Mud_Backhead_section%Remove (MudSystemDotimud)
call MudSystemDotSt_Mud_Forehead_X%Remove (MudSystemDotimud)
call St_Mud_Forehead_section%Remove (MudSystemDotimud)
call St_Density%Remove (MudSystemDotimud)
call MudSystemDotSt_RemainedVolume_in_LastSection%Remove (MudSystemDotimud)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud)
call St_MudOrKick%Remove (MudSystemDotimud)
if(MudSystem%St_MudDischarged_Volume%Array(imud) < ExcessMudVolume_Remained) then
ExcessMudVolume_Remained= ExcessMudVolume_Remained- MudSystem%St_MudDischarged_Volume%Array(imud)
call MudSystem%St_MudDischarged_Volume%Remove (imud)
call MudSystem%St_Mud_Backhead_X%Remove (imud)
call MudSystem%St_Mud_Backhead_section%Remove (imud)
call MudSystem%St_Mud_Forehead_X%Remove (imud)
call MudSystem%St_Mud_Forehead_section%Remove (imud)
call MudSystem%St_Density%Remove (imud)
call MudSystem%St_RemainedVolume_in_LastSection%Remove (imud)
call MudSystem%St_EmptyVolume_inBackheadLocation%Remove (imud)
call MudSystem%St_MudOrKick%Remove (imud)
elseif(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) > ExcessMudVolume_Remained) then
MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- ExcessMudVolume_Remained
elseif(MudSystem%St_MudDischarged_Volume%Array(imud) > ExcessMudVolume_Remained) then
MudSystem%St_MudDischarged_Volume%Array(imud)= MudSystem%St_MudDischarged_Volume%Array(imud)- ExcessMudVolume_Remained
exit
else !(St_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained)
call MudSystemDotSt_MudDischarged_Volume%Remove (MudSystemDotimud)
call MudSystemDotSt_Mud_Backhead_X%Remove (MudSystemDotimud)
call St_Mud_Backhead_section%Remove (MudSystemDotimud)
call MudSystemDotSt_Mud_Forehead_X%Remove (MudSystemDotimud)
call St_Mud_Forehead_section%Remove (MudSystemDotimud)
call St_Density%Remove (MudSystemDotimud)
call MudSystemDotSt_RemainedVolume_in_LastSection%Remove (MudSystemDotimud)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Remove (MudSystemDotimud)
call St_MudOrKick%Remove (MudSystemDotimud)
call MudSystem%St_MudDischarged_Volume%Remove (imud)
call MudSystem%St_Mud_Backhead_X%Remove (imud)
call MudSystem%St_Mud_Backhead_section%Remove (imud)
call MudSystem%St_Mud_Forehead_X%Remove (imud)
call MudSystem%St_Mud_Forehead_section%Remove (imud)
call MudSystem%St_Density%Remove (imud)
call MudSystem%St_RemainedVolume_in_LastSection%Remove (imud)
call MudSystem%St_EmptyVolume_inBackheadLocation%Remove (imud)
call MudSystem%St_MudOrKick%Remove (imud)
exit
endif


+ 131
- 131
Equipments/MudSystem/Elements_Creation.f90 Ver ficheiro

@@ -19,53 +19,53 @@ subroutine ElementsCreation ! is called in subroutine Fluid_Flow_Solver
implicit none
integer jelement, jmud, jsection,ielement,i
integer jopelement,jopmud,jopsection
integer jopelement,jopmud,jopsection,iisection,isection,OpSection
!===========================================================WELL============================================================
!===========================================================WELL============================================================

if(allocated(MudSystemDotXstart_PipeSection)) deallocate(MudSystemDotXstart_PipeSection)
if(allocated(MudSystemDotXend_PipeSection)) deallocate(MudSystemDotXend_PipeSection)
if(allocated(MudSystemDotPipeSection_VolumeCapacity)) deallocate(MudSystemDotPipeSection_VolumeCapacity)
if(allocated(MudSystemDotArea_PipeSectionFt)) deallocate(MudSystemDotArea_PipeSectionFt)
if(allocated(MudSystemDotGeoType)) deallocate(MudSystemDotGeoType)
if(allocated(MudSystemDotOD_PipeSectionInch)) deallocate(MudSystemDotOD_PipeSectionInch)
if(allocated(MudSystemDotID_PipeSectionInch)) deallocate(MudSystemDotID_PipeSectionInch)
if(allocated(MudSystemDotAngle_PipeSection)) deallocate(MudSystemDotAngle_PipeSection)
if(allocated(MudSystemDotXstart_OpSection)) deallocate(MudSystemDotXstart_OpSection)
if(allocated(MudSystemDotXend_OpSection)) deallocate(MudSystemDotXend_OpSection)
if(allocated(MudSystemDotOpSection_VolumeCapacity)) deallocate(MudSystemDotOpSection_VolumeCapacity)
if(allocated(MudSystemDotArea_OpSectionFt)) deallocate(MudSystemDotArea_OpSectionFt)
if(allocated(MudSystemDotGeoTypeOp)) deallocate(MudSystemDotGeoTypeOp)
if(allocated(MudSystemDotOD_OpSectionInch)) deallocate(MudSystemDotOD_OpSectionInch)
if(allocated(MudSystemDotID_OpSectionInch)) deallocate(MudSystemDotID_OpSectionInch)
if(allocated(MudSystemDotAngle_OpSection)) deallocate(MudSystemDotAngle_OpSection)
if(allocated(MudSystem%Xstart_PipeSection)) deallocate(MudSystem%Xstart_PipeSection)
if(allocated(MudSystem%Xend_PipeSection)) deallocate(MudSystem%Xend_PipeSection)
if(allocated(MudSystem%PipeSection_VolumeCapacity)) deallocate(MudSystem%PipeSection_VolumeCapacity)
if(allocated(MudSystem%Area_PipeSectionFt)) deallocate(MudSystem%Area_PipeSectionFt)
if(allocated(MudSystem%GeoType)) deallocate(MudSystem%GeoType)
if(allocated(MudSystem%OD_PipeSectionInch)) deallocate(MudSystem%OD_PipeSectionInch)
if(allocated(MudSystem%ID_PipeSectionInch)) deallocate(MudSystem%ID_PipeSectionInch)
if(allocated(MudSystem%Angle_PipeSection)) deallocate(MudSystem%Angle_PipeSection)
if(allocated(MudSystem%Xstart_OpSection)) deallocate(MudSystem%Xstart_OpSection)
if(allocated(MudSystem%Xend_OpSection)) deallocate(MudSystem%Xend_OpSection)
if(allocated(MudSystem%OpSection_VolumeCapacity)) deallocate(MudSystem%OpSection_VolumeCapacity)
if(allocated(MudSystem%Area_OpSectionFt)) deallocate(MudSystem%Area_OpSectionFt)
if(allocated(MudSystem%GeoTypeOp)) deallocate(MudSystem%GeoTypeOp)
if(allocated(MudSystem%OD_OpSectionInch)) deallocate(MudSystem%OD_OpSectionInch)
if(allocated(MudSystem%ID_OpSectionInch)) deallocate(MudSystem%ID_OpSectionInch)
if(allocated(MudSystem%Angle_OpSection)) deallocate(MudSystem%Angle_OpSection)


ALLOCATE (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotXend_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts) &
,MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotArea_PipeSectionFt(F_StringIntervalCounts+F_AnnulusIntervalCounts), &
MudSystemDotGeoType(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotOD_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystemDotID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts))
ALLOCATE (MudSystem%Xstart_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystem%Xend_PipeSection(F_StringIntervalCounts+F_AnnulusIntervalCounts) &
,MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystem%Area_PipeSectionFt(F_StringIntervalCounts+F_AnnulusIntervalCounts), &
MudSystem%GeoType(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystem%OD_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts),MudSystem%ID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts))


ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts) &
,MudSystemDotOpSection_VolumeCapacity(F_BottomHoleIntervalCounts),MudSystemDotArea_OpSectionFt(F_BottomHoleIntervalCounts), &
MudSystemDotGeoTypeOp(F_BottomHoleIntervalCounts),MudSystemDotOD_OpSectionInch(F_BottomHoleIntervalCounts),MudSystemDotID_OpSectionInch(F_BottomHoleIntervalCounts))
ALLOCATE (MudSystem%Xstart_OpSection(F_BottomHoleIntervalCounts),MudSystem%Xend_OpSection(F_BottomHoleIntervalCounts) &
,MudSystem%OpSection_VolumeCapacity(F_BottomHoleIntervalCounts),MudSystem%Area_OpSectionFt(F_BottomHoleIntervalCounts), &
MudSystem%GeoTypeOp(F_BottomHoleIntervalCounts),MudSystem%OD_OpSectionInch(F_BottomHoleIntervalCounts),MudSystem%ID_OpSectionInch(F_BottomHoleIntervalCounts))

MudSystemDotOpSection=0
MudSystemDotisection=0
MudSystem%OpSection=0
MudSystem%isection=0

DO MudSystemDotiisection=1, F_IntervalsTotalCounts
IF (F_Interval(MudSystemDotiisection)%GeoType == 1) THEN
MudSystemDotOpSection= MudSystemDotOpSection+1
MudSystemDotXstart_OpSection(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%StartDepth)
MudSystemDotXend_OpSection(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%EndDepth)
MudSystemDotArea_OpSectionFt(MudSystemDotOpSection)= PII*((F_Interval(MudSystemDotiisection)%OD/12.0d0)**2-(F_Interval(MudSystemDotiisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
MudSystemDotOD_OpSectionInch(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%OD)
MudSystemDotID_OpSectionInch(MudSystemDotOpSection)= (F_Interval(MudSystemDotiisection)%ID) !REAL(F_Interval(iisection)%Volume)
MudSystemDotGeoTypeOp(MudSystemDotOpSection)= F_Interval(MudSystemDotiisection)%GeoType ! niaz nist ehtemalan
DO iisection=1, F_IntervalsTotalCounts
IF (F_Interval(iisection)%GeoType == 1) THEN
MudSystem%OpSection= MudSystem%OpSection+1
MudSystem%Xstart_OpSection(MudSystem%OpSection)= (F_Interval(iisection)%StartDepth)
MudSystem%Xend_OpSection(MudSystem%OpSection)= (F_Interval(iisection)%EndDepth)
MudSystem%Area_OpSectionFt(MudSystem%OpSection)= PII*((F_Interval(iisection)%OD/12.0d0)**2-(F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
MudSystem%OD_OpSectionInch(MudSystem%OpSection)= (F_Interval(iisection)%OD)
MudSystem%ID_OpSectionInch(MudSystem%OpSection)= (F_Interval(iisection)%ID) !REAL(F_Interval(iisection)%Volume)
MudSystem%GeoTypeOp(MudSystem%OpSection)= F_Interval(iisection)%GeoType ! niaz nist ehtemalan
!Angle_OpSection(OpSection)= F_Interval(iisection)%Angle
!write(*,*) 'iisection=' , iisection
!write(*,*) 'StartDepth=' , F_Interval(iisection)%StartDepth
@@ -73,17 +73,17 @@ ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotX
!write(*,*) 'OD=' , F_Interval(iisection)%OD
!write(*,*) 'ID=' , F_Interval(iisection)%ID
ELSE
MudSystemDotisection= MudSystemDotisection+1
MudSystemDotXstart_PipeSection(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%StartDepth)
MudSystem%isection= MudSystem%isection+1
MudSystem%Xstart_PipeSection(MudSystem%isection)= (F_Interval(iisection)%StartDepth)
!write(*,*) 'F_Interval(iisection)%StartDepth=' , F_Interval(iisection)%StartDepth
MudSystemDotXend_PipeSection(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%EndDepth)
MudSystem%Xend_PipeSection(MudSystem%isection)= (F_Interval(iisection)%EndDepth)
!write(*,*) 'F_Interval(iisection)%EndDepth=' , F_Interval(iisection)%EndDepth
MudSystemDotOD_PipeSectionInch(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%OD)
MudSystemDotArea_PipeSectionFt(MudSystemDotisection)= PII*((F_Interval(MudSystemDotiisection)%OD/12.0d0)**2-(F_Interval(MudSystemDotiisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
MudSystemDotID_PipeSectionInch(MudSystemDotisection)= (F_Interval(MudSystemDotiisection)%ID)
MudSystem%OD_PipeSectionInch(MudSystem%isection)= (F_Interval(iisection)%OD)
MudSystem%Area_PipeSectionFt(MudSystem%isection)= PII*((F_Interval(iisection)%OD/12.0d0)**2-(F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2)
MudSystem%ID_PipeSectionInch(MudSystem%isection)= (F_Interval(iisection)%ID)
!PipeSection_VolumeCapacity(isection)= Area_PipeSectionFt(isection)* ABS(Xend_PipeSection(isection)-Xstart_PipeSection(isection))* 7.48051948 !REAL(F_Interval(iisection)%Volume) ! (gal)
MudSystemDotGeoType(MudSystemDotisection)= F_Interval(MudSystemDotiisection)%GeoType
MudSystem%GeoType(MudSystem%isection)= F_Interval(iisection)%GeoType
!Angle_PipeSection(isection)= F_Interval(iisection)%Angle
ENDIF
@@ -91,107 +91,107 @@ ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotX


call Xstart_MudElement%Empty()
call Xstart_MudElement%Add(MudSystemDotXstart_PipeSection(1))
call MudSystem%Xstart_MudElement%Empty()
call MudSystem%Xstart_MudElement%Add(MudSystem%Xstart_PipeSection(1))
call Xstart_OpMudElement%Empty()
call Xstart_OpMudElement%Add(MudSystemDotXstart_OpSection(1))
call MudSystem%Xstart_OpMudElement%Empty()
call MudSystem%Xstart_OpMudElement%Add(MudSystem%Xstart_OpSection(1))
call TVDstart_MudElement%Empty()
call TVD_Calculator(MudSystemDotXstart_PipeSection(1),MudSystemDotMudCircVerticalDepth)
call TVDstart_MudElement%Add(MudSystemDotMudCircVerticalDepth)
call MudSystem%TVDstart_MudElement%Empty()
call TVD_Calculator(MudSystem%Xstart_PipeSection(1),MudSystem%MudCircVerticalDepth)
call MudSystem%TVDstart_MudElement%Add(MudSystem%MudCircVerticalDepth)
call TVDstart_OPMudElement%Empty()
call TVD_Calculator(MudSystemDotXstart_OpSection(1),MudSystemDotMudCircVerticalDepth)
call TVDstart_OPMudElement%Add(MudSystemDotMudCircVerticalDepth)
call MudSystem%TVDstart_OpMudElement%Empty()
call TVD_Calculator(MudSystem%Xstart_OpSection(1),MudSystem%MudCircVerticalDepth)
call MudSystem%TVDstart_OpMudElement%Add(MudSystem%MudCircVerticalDepth)
MudSystemDotNoPipeSections= MudSystemDotisection ! sections in string and annulus(GeoType 0 & 2)
MudSystem%NoPipeSections= MudSystem%isection ! sections in string and annulus(GeoType 0 & 2)

DO MudSystemDotOpSection= 1,F_BottomHoleIntervalCounts
MudSystemDotOpSection_VolumeCapacity(MudSystemDotOpSection)= MudSystemDotArea_OpSectionFt(MudSystemDotOpSection)* ABS(MudSystemDotXend_OpSection(MudSystemDotOpSection)-MudSystemDotXstart_OpSection(MudSystemDotOpSection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume)
DO OpSection= 1,F_BottomHoleIntervalCounts
MudSystem%OpSection_VolumeCapacity(OpSection)= MudSystem%Area_OpSectionFt(OpSection)* ABS(MudSystem%Xend_OpSection(OpSection)-MudSystem%Xstart_OpSection(OpSection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume)
ENDDO
DO MudSystemDotisection= 1,MudSystemDotNoPipeSections
MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)= MudSystemDotArea_PipeSectionFt(MudSystemDotisection)* ABS(MudSystemDotXend_PipeSection(MudSystemDotisection)-MudSystemDotXstart_PipeSection(MudSystemDotisection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume) ! (gal)
MudSystem%OpSection=OpSection
DO isection= 1,MudSystem%NoPipeSections
MudSystem%PipeSection_VolumeCapacity(isection)= MudSystem%Area_PipeSectionFt(isection)* ABS(MudSystem%Xend_PipeSection(isection)-MudSystem%Xstart_PipeSection(isection))* 7.48051948d0 !REAL(F_Interval(iisection)%Volume) ! (gal)
ENDDO
MudSystem%isection = isection
!types: Mud= 0 Kick=1

!===========================================
if (MudSystemDotFirstMudSet==0) then
call MudSystemDotHz_MudDischarged_Volume%AddToFirst(MudSystemDotPipeSection_VolumeCapacity(1)) !startup initial
call MudSystemDotHz_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(1))
call Hz_Mud_Backhead_section%AddToFirst (1)
call MudSystemDotHz_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(1))
call Hz_Mud_Forehead_section%AddToFirst (1)
call MudSystemDotHz_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystemDotHz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotHz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call Hz_MudOrKick%AddToFirst (0)
if (MudSystem%FirstMudSet==0) then
call MudSystem%Hz_MudDischarged_Volume%AddToFirst(MudSystem%PipeSection_VolumeCapacity(1)) !startup initial
call MudSystem%Hz_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(1))
call MudSystem%Hz_Mud_Backhead_section%AddToFirst (1)
call MudSystem%Hz_Mud_Forehead_X%AddToFirst (MudSystem%Xend_PipeSection(1))
call MudSystem%Hz_Mud_Forehead_section%AddToFirst (1)
call MudSystem%Hz_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%Hz_MudOrKick%AddToFirst (0)
call MudSystemDotSt_MudDischarged_Volume%AddToFirst(sum(MudSystemDotPipeSection_VolumeCapacity(2:F_StringIntervalCounts))) !startup initial
call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
call St_Mud_Backhead_section%AddToFirst (2)
call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
call St_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call St_MudOrKick%AddToFirst (0)
call MudSystem%St_MudDischarged_Volume%AddToFirst(sum(MudSystem%PipeSection_VolumeCapacity(2:F_StringIntervalCounts))) !startup initial
call MudSystem%St_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(2))
call MudSystem%St_Mud_Backhead_section%AddToFirst (2)
call MudSystem%St_Mud_Forehead_X%AddToFirst (MudSystem%Xend_PipeSection(F_StringIntervalCounts))
call MudSystem%St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
call MudSystem%St_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%St_MudOrKick%AddToFirst (0)
call MudSystemDotAnn_MudDischarged_Volume%AddToFirst(sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)))
call Ann_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1))
call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
call Ann_Mud_Forehead_X%AddToFirst (MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections))
call Ann_Mud_Forehead_section%AddToFirst (MudSystemDotNoPipeSections)
call Ann_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call Ann_MudOrKick%AddToFirst (0)
call Ann_CuttingMud%AddToFirst (0)
call MudSystem%Ann_MudDischarged_Volume%AddToFirst(sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections)))
call MudSystem%Ann_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_PipeSection(F_StringIntervalCounts+1))
call MudSystem%Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1)
call MudSystem%Ann_Mud_Forehead_X%AddToFirst (MudSystem%Xend_PipeSection(MudSystem%NoPipeSections))
call MudSystem%Ann_Mud_Forehead_section%AddToFirst (MudSystem%NoPipeSections)
call MudSystem%Ann_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%Ann_MudOrKick%AddToFirst (0)
call MudSystem%Ann_CuttingMud%AddToFirst (0)
MudSystemDotOldPosition= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
MudSystem%OldPosition= MudSystem%Xend_PipeSection(F_StringIntervalCounts)
MudSystemDotOldAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
MudSystem%OldAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections))
call MudSystemDotChokeLine_MudDischarged_Volume%AddToFirst(MudSystemDotChokeLine_VolumeCapacity)
call MudSystemDotChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
call ChokeLine_Mud_Backhead_section%AddToFirst (1)
call MudSystemDotChokeLine_Mud_Forehead_X%AddToFirst (BopStackSpecification%ChokeLineLength)
call ChokeLine_Mud_Forehead_section%AddToFirst (1)
call MudSystemDotChokeLine_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystemDotChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call ChokeLine_MudOrKick%AddToFirst (0)
call MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst(MudSystem%ChokeLine_VolumeCapacity)
call MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0)
call MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1)
call MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (BopStackSpecification%ChokeLineLength)
call MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1)
call MudSystem%ChokeLine_Density%AddToFirst (MudProperties%ActiveDensity) ! initial(ppg)
call MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%ChokeLine_MudOrKick%AddToFirst (0)

call MudSystemDotOp_MudDischarged_Volume%AddToFirst (sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)))
call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_OpSection(1))
call Op_Mud_Backhead_section%AddToFirst (1)
call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts))
call Op_Mud_Forehead_section%AddToFirst (F_BottomHoleIntervalCounts)
call MudSystemDotOp_Density%AddToFirst (MudProperties%ActiveDensity)
call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call Op_MudOrKick%AddToFirst (0)
call MudSystem%Op_MudDischarged_Volume%AddToFirst (sum(MudSystem%OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)))
call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_OpSection(1))
call MudSystem%Op_Mud_Backhead_section%AddToFirst (1)
call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Xend_OpSection(F_BottomHoleIntervalCounts))
call MudSystem%Op_Mud_Forehead_section%AddToFirst (F_BottomHoleIntervalCounts)
call MudSystem%Op_Density%AddToFirst (MudProperties%ActiveDensity)
call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%Op_MudOrKick%AddToFirst (0)
!F_StringIntervalCountsOld= F_StringIntervalCounts ! is used for adding new pipe to string
MudSystemDotF_StringIntervalCounts_Old= F_StringIntervalCounts ! is used for adding new pipe to string
MudSystem%F_StringIntervalCounts_Old= F_StringIntervalCounts ! is used for adding new pipe to string
MudSystemDotFirstMudSet= 1
MudSystem%FirstMudSet= 1
endif

@@ -201,16 +201,16 @@ ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotX
!DeltaVolumeOp < 0 : Trip out


MudSystemDotDeltaVolumeOp= ((MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition)*PII*((MudSystemDotOD_PipeSectionInch(F_StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in)
MudSystemDotDeltaVolumeOp = INT(MudSystemDotDeltaVolumeOp * 100000.d0) / 100000.d0
MudSystem%DeltaVolumeOp= ((MudSystem%Xend_PipeSection(F_StringIntervalCounts)-MudSystem%OldPosition)*PII*((MudSystem%OD_PipeSectionInch(F_StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in)
MudSystem%DeltaVolumeOp = INT(MudSystem%DeltaVolumeOp * 100000.d0) / 100000.d0
MudSystemDotDeltaVolumePipe= ((MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition)*PII*((MudSystemDotID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal
MudSystemDotDeltaVolumePipe = INT(MudSystemDotDeltaVolumePipe * 100000.d0) / 100000.d0
MudSystem%DeltaVolumePipe= ((MudSystem%Xend_PipeSection(F_StringIntervalCounts)-MudSystem%OldPosition)*PII*((MudSystem%ID_PipeSectionInch(F_StringIntervalCounts+F_AnnulusIntervalCounts)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal
MudSystem%DeltaVolumePipe = INT(MudSystem%DeltaVolumePipe * 100000.d0) / 100000.d0
!DeltaVolumeAnnulusCapacity= ((Xend_PipeSection(F_StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal
DrillStringSpeed = (MudSystemDotXend_PipeSection(F_StringIntervalCounts)-MudSystemDotOldPosition) / 0.1
DrillStringSpeed = (MudSystem%Xend_PipeSection(F_StringIntervalCounts)-MudSystem%OldPosition) / 0.1
MudSystemDotDeltaVolumeAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) - MudSystemDotOldAnnulusCapacity
MudSystem%DeltaVolumeAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections)) - MudSystem%OldAnnulusCapacity
!write(*,*) 'DeltaVolumeAnnulusCapacity= ' , DeltaVolumeAnnulusCapacity
@@ -224,32 +224,32 @@ ALLOCATE (MudSystemDotXstart_OpSection(F_BottomHoleIntervalCounts),MudSystemDotX
MudSystemDotOldAnnulusCapacity= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections))
MudSystem%OldAnnulusCapacity= sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections))

MudSystemDotOldPosition= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
MudSystem%OldPosition= MudSystem%Xend_PipeSection(F_StringIntervalCounts)
! Needed for trip in or out:
if (MudSystemDotHz_Mud_Backhead_X%Length() == 0) then
if (MudSystem%Hz_Mud_Backhead_X%Length() == 0) then
CALL ErrorStop('Hz_Mud_Backhead_X Length is 0')
endif
MudSystemDotHz_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(1)
Hz_Mud_Backhead_section%Array(1)= 1
MudSystem%Hz_Mud_Backhead_X%Array(1)= MudSystem%Xstart_PipeSection(1)
MudSystem%Hz_Mud_Backhead_section%Array(1)= 1
MudSystemDotAddedElementsToString = F_StringIntervalCounts - MudSystemDotF_StringIntervalCounts_Old
MudSystemDotSt_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(2)
St_Mud_Backhead_section%Array(1)= 2
Ann_Mud_Backhead_X%Array(1)= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)
Ann_Mud_Backhead_section%Array(1)= F_StringIntervalCounts+1
MudSystemDotOp_Mud_Backhead_X%Array(1)= MudSystemDotXstart_OpSection(1)
Op_Mud_Backhead_section%Array(1)= 1
MudSystemDotChokeLine_Mud_Backhead_X%Array(1)= 0.
ChokeLine_Mud_Backhead_section%Array(1)= 1
MudSystem%AddedElementsToString = F_StringIntervalCounts - MudSystem%F_StringIntervalCounts_Old
MudSystem%St_Mud_Backhead_X%Array(1)= MudSystem%Xstart_PipeSection(2)
MudSystem%St_Mud_Backhead_section%Array(1)= 2
MudSystem%Ann_Mud_Backhead_X%Array(1)= MudSystem%Xstart_PipeSection(F_StringIntervalCounts+1)
MudSystem%Ann_Mud_Backhead_section%Array(1)= F_StringIntervalCounts+1
MudSystem%Op_Mud_Backhead_X%Array(1)= MudSystem%Xstart_OpSection(1)
MudSystem%Op_Mud_Backhead_section%Array(1)= 1
MudSystem%ChokeLine_Mud_Backhead_X%Array(1)= 0.
MudSystem%ChokeLine_Mud_Backhead_section%Array(1)= 1
MudSystemDotF_StringIntervalCounts_Old= F_StringIntervalCounts
MudSystem%F_StringIntervalCounts_Old= F_StringIntervalCounts
!write(*,*) 'Xstart_PipeSection(2)' , Xstart_PipeSection(2)
!write(*,*) 'Xend_PipeSection(1)' , Xend_PipeSection(1)



+ 59
- 59
Equipments/MudSystem/FillingWell_By_BellNipple.f90 Ver ficheiro

@@ -26,7 +26,7 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo
if (Ann_MudOrKick%Last() == 104) then ! Last Element is air we must observe: Ann_Mud_Forehead_X%Last()=0.0
if (MudSystem%Ann_MudOrKick%Last() == 104) then ! Last Element is air we must observe: Ann_Mud_Forehead_X%Last()=0.0
write(*,*) 'FillingWell_By_BellNipple-Last Element is air'
@@ -35,40 +35,40 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo
FillingDensity= BellNippleDensity
FillingDensity= MudSystem%BellNippleDensity
!****************************
if ( MudSystemDotAnn_MudDischarged_Volume%Last() > (((MUD(8)%Q+MUD(10)%Q)/60.)*DeltaT_Mudline)) then ! air baghi mimune
if ( MudSystem%Ann_MudDischarged_Volume%Last() > (((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline)) then ! air baghi mimune
kloc= MudSystemDotAnn_MudDischarged_Volume%Length()-1
kloc= MudSystem%Ann_MudDischarged_Volume%Length()-1
deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*DeltaT_Mudline
deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length()) - deltaV
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length()) - deltaV
!========================ANNULUS ENTRANCE====================
if (ABS(Ann_Density%Array(kloc) - FillingDensity) >= MudSystemDotDensityMixTol) then ! new mud is pumped
call Ann_Density%AddTo (kloc, FillingDensity)
call MudSystemDotAnn_MudDischarged_Volume%AddTo (kloc, 0.0d0)
call Ann_Mud_Forehead_X%AddTo (kloc, 0.0d0)
call Ann_Mud_Forehead_section%AddTo (kloc, 1)
call Ann_Mud_Backhead_X%AddTo (kloc, 0.0d0)
call Ann_Mud_Backhead_section%AddTo (kloc, MudSystemDotNoPipeSections)
call Ann_RemainedVolume_in_LastSection%AddTo (kloc, 0.0d0)
call Ann_EmptyVolume_inBackheadLocation%AddTo (kloc, 0.0d0)
call Ann_MudOrKick%AddTo (kloc, 0)
call Ann_CuttingMud%AddTo (kloc,0)
if (ABS(MudSystem%Ann_Density%Array(kloc) - FillingDensity) >= MudSystem%DensityMixTol) then ! new mud is pumped
call MudSystem%Ann_Density%AddTo (kloc, FillingDensity)
call MudSystem%Ann_MudDischarged_Volume%AddTo (kloc, 0.0d0)
call MudSystem%Ann_Mud_Forehead_X%AddTo (kloc, 0.0d0)
call MudSystem%Ann_Mud_Forehead_section%AddTo (kloc, 1)
call MudSystem%Ann_Mud_Backhead_X%AddTo (kloc, 0.0d0)
call MudSystem%Ann_Mud_Backhead_section%AddTo (kloc, MudSystem%NoPipeSections)
call MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (kloc, 0.0d0)
call MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (kloc, 0.0d0)
call MudSystem%Ann_MudOrKick%AddTo (kloc, 0)
call MudSystem%Ann_CuttingMud%AddTo (kloc,0)
!AnnulusSuctionDensity_Old= Hz_Density_Utube
endif
!========================ANNULUS====================

MudSystemDotAnn_MudDischarged_Volume%Array(kloc)= MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+ deltaV !(gal)
MudSystem%Ann_MudDischarged_Volume%Array(kloc)= MudSystem%Ann_MudDischarged_Volume%Array(kloc)+ deltaV !(gal)
@@ -77,37 +77,37 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo
kloc= MudSystemDotAnn_MudDischarged_Volume%Length()-1
kloc= MudSystem%Ann_MudDischarged_Volume%Length()-1
deltaV= MudSystemDotAnn_MudDischarged_Volume%Last()
deltaV= MudSystem%Ann_MudDischarged_Volume%Last()
if (ABS(Ann_Density%Array(kloc)-FillingDensity)< MudSystemDotDensityMixTol .and. Ann_CuttingMud%Array(kloc)==0) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)< 42.) ) then ! 1-Pockets are Merged
Ann_Density%Array(kloc)= (Ann_Density%Array(kloc)*MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+deltaV)
MudSystemDotAnn_MudDischarged_Volume%Array(kloc)= MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+deltaV
Ann_Mud_Forehead_X%Array(kloc)= MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)
Ann_Mud_Forehead_section%Array(kloc)= MudSystemDotNoPipeSections
if (ABS(MudSystem%Ann_Density%Array(kloc)-FillingDensity)< MudSystem%DensityMixTol .and. MudSystem%Ann_CuttingMud%Array(kloc)==0) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)< 42.) ) then ! 1-Pockets are Merged
MudSystem%Ann_Density%Array(kloc)= (MudSystem%Ann_Density%Array(kloc)*MudSystem%Ann_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV)
MudSystem%Ann_MudDischarged_Volume%Array(kloc)= MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV
MudSystem%Ann_Mud_Forehead_X%Array(kloc)= MudSystem%Xend_PipeSection(MudSystem%NoPipeSections)
MudSystem%Ann_Mud_Forehead_section%Array(kloc)= MudSystem%NoPipeSections
!Ann_Mud_Backhead_X%Array(kloc)= no change
!Ann_Mud_Backhead_section%Array(kloc)= no change
Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0)
Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0)
MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0)
MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0)
call MudSystemDotAnn_MudDischarged_Volume%Remove (kloc+1)
call Ann_Mud_Backhead_X%Remove (kloc+1)
call Ann_Mud_Backhead_section%Remove (kloc+1)
call Ann_Mud_Forehead_X%Remove (kloc+1)
call Ann_Mud_Forehead_section%Remove (kloc+1)
call Ann_Density%Remove (kloc+1)
call Ann_RemainedVolume_in_LastSection%Remove (kloc+1)
call Ann_EmptyVolume_inBackheadLocation%Remove (kloc+1)
call Ann_MudOrKick%Remove (kloc+1)
call Ann_CuttingMud%Remove (kloc+1)
call MudSystem%Ann_MudDischarged_Volume%Remove (kloc+1)
call MudSystem%Ann_Mud_Backhead_X%Remove (kloc+1)
call MudSystem%Ann_Mud_Backhead_section%Remove (kloc+1)
call MudSystem%Ann_Mud_Forehead_X%Remove (kloc+1)
call MudSystem%Ann_Mud_Forehead_section%Remove (kloc+1)
call MudSystem%Ann_Density%Remove (kloc+1)
call MudSystem%Ann_RemainedVolume_in_LastSection%Remove (kloc+1)
call MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (kloc+1)
call MudSystem%Ann_MudOrKick%Remove (kloc+1)
call MudSystem%Ann_CuttingMud%Remove (kloc+1)
else ! 2-Merging conditions are not meeted, so new pocket== air is replaced with filling mud
Ann_Density%Array(kloc+1) =FillingDensity
Ann_MudOrKick%Array(kloc+1)= 0
MudSystem%Ann_Density%Array(kloc+1) =FillingDensity
MudSystem%Ann_MudOrKick%Array(kloc+1)= 0
endif

@@ -129,9 +129,9 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo
!write(*,*) '*Ann_MudOrKick%Last()=' , Ann_MudOrKick%Last()
deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*DeltaT_Mudline
deltaV= ((MUD(8)%Q+MUD(10)%Q)/60.)*MudSystem%DeltaT_Mudline
kloc= MudSystemDotAnn_MudDischarged_Volume%Length()
kloc= MudSystem%Ann_MudDischarged_Volume%Length()

@@ -139,37 +139,37 @@ subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCo
!========================ANNULUS ENTRANCE====================
if (ABS(Ann_Density%Last() - FillingDensity) >= MudSystemDotDensityMixTol .or. Ann_CuttingMud%Last()==1) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)>42.) ) then ! new mud is pumped
Xposition= Ann_Mud_Forehead_X%Last()
SectionPosition= Ann_Mud_Forehead_section%Last()
call Ann_Density%Add (FillingDensity)
call MudSystemDotAnn_MudDischarged_Volume%Add (0.0d0)
call Ann_Mud_Forehead_X%Add (Xposition)
call Ann_Mud_Forehead_section%Add (SectionPosition)
call Ann_Mud_Backhead_X%Add (Xposition)
call Ann_Mud_Backhead_section%Add (SectionPosition)
call Ann_RemainedVolume_in_LastSection%Add (0.0d0)
call Ann_EmptyVolume_inBackheadLocation%Add (0.0d0)
call Ann_MudOrKick%Add (0)
call Ann_CuttingMud%Add (0)
if (ABS(MudSystem%Ann_Density%Last() - FillingDensity) >= MudSystem%DensityMixTol .or. MudSystem%Ann_CuttingMud%Last()==1) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)>42.) ) then ! new mud is pumped
Xposition= MudSystem%Ann_Mud_Forehead_X%Last()
SectionPosition= MudSystem%Ann_Mud_Forehead_section%Last()
call MudSystem%Ann_Density%Add (FillingDensity)
call MudSystem%Ann_MudDischarged_Volume%Add (0.0d0)
call MudSystem%Ann_Mud_Forehead_X%Add (Xposition)
call MudSystem%Ann_Mud_Forehead_section%Add (SectionPosition)
call MudSystem%Ann_Mud_Backhead_X%Add (Xposition)
call MudSystem%Ann_Mud_Backhead_section%Add (SectionPosition)
call MudSystem%Ann_RemainedVolume_in_LastSection%Add (0.0d0)
call MudSystem%Ann_EmptyVolume_inBackheadLocation%Add (0.0d0)
call MudSystem%Ann_MudOrKick%Add (0)
call MudSystem%Ann_CuttingMud%Add (0)
!AnnulusSuctionDensity_Old= Hz_Density_Utube
!endif
!========================ANNULUS====================

MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())+ deltaV !(gal)
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())+ deltaV !(gal)
else ! Merged with last Mud
Ann_Density%Array(kloc)= (Ann_Density%Array(kloc)*MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+deltaV)
MudSystemDotAnn_MudDischarged_Volume%Array(kloc)= MudSystemDotAnn_MudDischarged_Volume%Array(kloc)+deltaV
MudSystem%Ann_Density%Array(kloc)= (MudSystem%Ann_Density%Array(kloc)*MudSystem%Ann_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV)
MudSystem%Ann_MudDischarged_Volume%Array(kloc)= MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV
!Ann_Mud_Forehead_X%Array(kloc)= Xend_PipeSection(NoPipeSections)
!Ann_Mud_Forehead_section%Array(kloc)= NoPipeSections
!Ann_Mud_Backhead_X%Array(kloc)= no change
!Ann_Mud_Backhead_section%Array(kloc)= no change
Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0)
Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0)
MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0)
MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0)
endif


+ 36
- 37
Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 Ver ficheiro

@@ -12,25 +12,24 @@ subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect
USE KickVARIABLES

implicit none
real(8) ExpansionVolume
!write(*,*) 'Kick Expansion'
implicit none
real(8) ExpansionVolume

!write(*,*) 'Kick Expansion'
ExpansionVolume= GasPocketDeltaVol%Array(MudSystemDotNewInfluxNumber - MudSystemDotKickNumber + 1) * 7.48
ExpansionVolume= GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - MudSystem%KickNumber + 1) * 7.48

IF ( MudSystemDotKickexpansion_DueToMudLost ) ExpansionVolume = ((MudSystemDotQlost/60.0d0)*DeltaT_Mudline)
IF ( MudSystem%Kickexpansion_DueToMudLost ) ExpansionVolume = ((MudSystem%Qlost/60.0d0)*MudSystem%DeltaT_Mudline)


!============================== kick zire mate bashad ==============================

if (MudSystemDotOp_KickLoc > 0 .and. MudSystemDotAnn_KickLoc==0) then ! .and. Op_KickLoc /= Op_MudOrKick%Length ()) then
if (MudSystem%Op_KickLoc > 0 .and. MudSystem%Ann_KickLoc==0) then ! .and. Op_KickLoc /= Op_MudOrKick%Length ()) then
!write(*,*) 'expansion (1)'

MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc)+ ExpansionVolume
MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)+ ExpansionVolume

!if (MUD(4)%Q > 0.) then
@@ -58,14 +57,14 @@ IF ( MudSystemDotKickexpansion_DueToMudLost ) ExpansionVolume = ((MudSystemDot
!============================= foreheade dar fazaye annulus bashad ===========================
! agar kick be entehaye annulus reside bashe, expansion ra emaal nemikonim
if (MudSystemDotAnn_KickLoc > 0) then ! .and. Ann_KickLoc /= Ann_MudOrKick%Length ()) then
if (MudSystem%Ann_KickLoc > 0) then ! .and. Ann_KickLoc /= Ann_MudOrKick%Length ()) then
!write(*,*) 'expansion (2)'

!if ( sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc)) + ExpansionVolume > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then ! agar khast az mate rad kone
! ExpansionVolume= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc))
!endif
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc)+ ExpansionVolume
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)+ ExpansionVolume
!if (MUD(4)%Q > 0.) then
!
@@ -95,9 +94,9 @@ IF ( MudSystemDotKickexpansion_DueToMudLost ) ExpansionVolume = ((MudSystemDot
!=============================== foreheade dar choke line bashad =============================
if (MudSystemDotChokeLine_KickLoc > 0 .and. MudSystemDotAnn_KickLoc==0) then
if (MudSystem%ChokeLine_KickLoc > 0 .and. MudSystem%Ann_KickLoc==0) then
MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotChokeLine_KickLoc)= MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotChokeLine_KickLoc)+ ExpansionVolume
MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)= MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)+ ExpansionVolume
endif
@@ -152,12 +151,12 @@ subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect
!write(*,*) 'Kick Contraction'

!MUD(2)%Q= MPumps%Total_Pump_GPM
StringFlowRate= MUD(2)%Q
AnnulusFlowRate= MUD(2)%Q
MudSystem%StringFlowRate= MUD(2)%Q
MudSystem%AnnulusFlowRate= MUD(2)%Q
if (MudSystemDotNewPipeFilling == 0) then
MudSystemDotStringFlowRate= 0.
MudSystemDotAnnulusFlowRate= 0.
if (MudSystem%NewPipeFilling == 0) then
MudSystem%StringFlowRate= 0.
MudSystem%AnnulusFlowRate= 0.
endif
@@ -165,10 +164,10 @@ subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect

!if (WellHeadIsOpen) then
ContractionVolume= - GasPocketDeltaVol%Array(MudSystemDotNewInfluxNumber - MudSystemDotKickNumber + 1) * 7.48
ContractionVolume= - GasPocketDeltaVol%Array(MudSystem%NewInfluxNumber - MudSystem%KickNumber + 1) * 7.48
!else
!ContractionVolume = (StringFlowRate/60.0d0)*DeltaT_Mudline + DeltaVolumePipe
if (MudSystemDotKickNumber == 1 .and. WellHeadIsOpen==.false.) ContractionVolume = ContractionVolume + (MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline + MudSystemDotDeltaVolumePipe
!ContractionVolume = (MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline + DeltaVolumePipe
if (MudSystem%KickNumber == 1 .and. MudSystem%WellHeadIsOpen==.false.) ContractionVolume = ContractionVolume + (MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline + MudSystem%DeltaVolumePipe
!endif
@@ -176,43 +175,43 @@ subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect
! pump mud is added in "pump&TripIn" code
IF (MudSystemDotOp_KickLoc > 0 .and. MudSystemDotAnn_KickLoc == 0) then ! All of kick is under bit (iloc == 1)
IF (MudSystem%Op_KickLoc > 0 .and. MudSystem%Ann_KickLoc == 0) then ! All of kick is under bit (iloc == 1)
MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_KickLoc) - ( ContractionVolume )
MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc)= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_KickLoc) - ( ContractionVolume )
ELSE IF (MudSystemDotOp_KickLoc == 0 .AND. MudSystemDotAnn_KickLoc > 0 .AND. MudSystemDotChokeLine_KickLoc == 0) THEN ! All of kick is an Annulus (iloc == 1)
ELSE IF (MudSystem%Op_KickLoc == 0 .AND. MudSystem%Ann_KickLoc > 0 .AND. MudSystem%ChokeLine_KickLoc == 0) THEN ! All of kick is an Annulus (iloc == 1)
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_KickLoc) - ( ContractionVolume )
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_KickLoc) - ( ContractionVolume )
ELSE IF (MudSystemDotAnn_KickLoc == 0 .AND. MudSystemDotChokeLine_KickLoc > 0) THEN ! kick is in chokeline only
ELSE IF (MudSystem%Ann_KickLoc == 0 .AND. MudSystem%ChokeLine_KickLoc > 0) THEN ! kick is in chokeline only
MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotChokeLine_KickLoc)= MudSystemDotChokeLine_MudDischarged_Volume%Array(MudSystemDotChokeLine_KickLoc) - ( ContractionVolume )
MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc)= MudSystem%ChokeLine_MudDischarged_Volume%Array(MudSystem%ChokeLine_KickLoc) - ( ContractionVolume )
ELSE IF (MudSystemDotOp_KickLoc > 0 .AND. MudSystemDotAnn_KickLoc > 0) THEN ! Kick is around bit (iloc==2)
ELSE IF (MudSystem%Op_KickLoc > 0 .AND. MudSystem%Ann_KickLoc > 0) THEN ! Kick is around bit (iloc==2)
if (MudSystemDotAnn_MudDischarged_Volume%Array(1) > ContractionVolume ) then
if (MudSystem%Ann_MudDischarged_Volume%Array(1) > ContractionVolume ) then
MudSystemDotAnn_MudDischarged_Volume%Array(1)= MudSystemDotAnn_MudDischarged_Volume%Array(1) - ( ContractionVolume )
MudSystem%Ann_MudDischarged_Volume%Array(1)= MudSystem%Ann_MudDischarged_Volume%Array(1) - ( ContractionVolume )
elseif (MudSystemDotOp_MudDischarged_Volume%Last() > ContractionVolume ) then
elseif (MudSystem%Op_MudDischarged_Volume%Last() > ContractionVolume ) then
MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_MudDischarged_Volume%Length())= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotOp_MudDischarged_Volume%Length()) - ( ContractionVolume )
MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_MudDischarged_Volume%Length())= MudSystem%Op_MudDischarged_Volume%Array(MudSystem%Op_MudDischarged_Volume%Length()) - ( ContractionVolume )
else
Call ErrorStop ('kick contraction error 1')
endif
ELSE IF (MudSystemDotAnn_KickLoc > 0 .AND. MudSystemDotChokeLine_KickLoc > 0) THEN
ELSE IF (MudSystem%Ann_KickLoc > 0 .AND. MudSystem%ChokeLine_KickLoc > 0) THEN
if (MudSystemDotChokeLine_MudDischarged_Volume%Array(1) > ContractionVolume ) then
if (MudSystem%ChokeLine_MudDischarged_Volume%Array(1) > ContractionVolume ) then
MudSystemDotChokeLine_MudDischarged_Volume%Array(1) = MudSystemDotChokeLine_MudDischarged_Volume%Array(1) - ( ContractionVolume )
MudSystem%ChokeLine_MudDischarged_Volume%Array(1) = MudSystem%ChokeLine_MudDischarged_Volume%Array(1) - ( ContractionVolume )
elseif (MudSystemDotAnn_MudDischarged_Volume%Last() > ContractionVolume ) then
elseif (MudSystem%Ann_MudDischarged_Volume%Last() > ContractionVolume ) then
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length()) - ( ContractionVolume )
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length()) - ( ContractionVolume )
else
Call ErrorStop ('kick contraction error 2')


+ 48
- 48
Equipments/MudSystem/Kick_Influx.f90 Ver ficheiro

@@ -22,27 +22,27 @@ subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect

!=================== Bottom Hole Kick Influx ENTRANCE(due to Kick) ===================
MudSystemDotKick_Density= 2
MudSystemDotNewInflux_Density= MudSystemDotKick_Density
MudSystem%Kick_Density= 2
MudSystem%NewInflux_Density= MudSystem%Kick_Density
if ( MudSystemDotNewInfluxElementCreated==0 ) then ! new kick is pumped- (it is set to zero in sheykh subroutine after a new kick influx)
call MudSystemDotOp_Density%AddToFirst (MudSystemDotNewInflux_Density)
call MudSystemDotOp_MudDischarged_Volume%AddToFirst (0.0d0)
call MudSystemDotOp_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_OpSection(1))
call Op_Mud_Forehead_section%AddToFirst (1)
call MudSystemDotOp_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_OpSection(1))
call Op_Mud_Backhead_section%AddToFirst (1)
call MudSystemDotOp_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotOp_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call Op_MudOrKick%AddToFirst (MudSystemDotNewInfluxNumber) ! KickNumber= NewInfluxNumber
if ( MudSystem%NewInfluxElementCreated==0 ) then ! new kick is pumped- (it is set to zero in sheykh subroutine after a new kick influx)
call MudSystem%Op_Density%AddToFirst (MudSystem%NewInflux_Density)
call MudSystem%Op_MudDischarged_Volume%AddToFirst (0.0d0)
call MudSystem%Op_Mud_Forehead_X%AddToFirst (MudSystem%Xstart_OpSection(1))
call MudSystem%Op_Mud_Forehead_section%AddToFirst (1)
call MudSystem%Op_Mud_Backhead_X%AddToFirst (MudSystem%Xstart_OpSection(1))
call MudSystem%Op_Mud_Backhead_section%AddToFirst (1)
call MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call MudSystem%Op_MudOrKick%AddToFirst (MudSystem%NewInfluxNumber) ! KickNumber= NewInfluxNumber
MudSystemDotNewInfluxElementCreated= 1
MudSystem%NewInfluxElementCreated= 1
endif

MudSystemDotOp_MudDischarged_Volume%Array(1)= MudSystemDotOp_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.0d0)*DeltaT_Mudline) !(gal) due to KickFlux
MudSystem%Op_MudDischarged_Volume%Array(1)= MudSystem%Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal) due to KickFlux
!write(*,*) 'kick volume ok=' , Op_MudDischarged_Volume%Array(1)

@@ -79,13 +79,13 @@ subroutine Instructor_CirculationMud_Edit ! is called in subroutine Circulat


if ( DownHole%AnnDrillMud == .true. .and. (Rate_of_Penetration>0. .and. MudSystemDotDeltaVolumeOp>0.0) ) then
if ( DownHole%AnnDrillMud == .true. .and. (Rate_of_Penetration>0. .and. MudSystem%DeltaVolumeOp>0.0) ) then
do MudSystemDotimud= 1, Ann_Density%Length()
do imud= 1, MudSystem%Ann_Density%Length()
if ( Ann_MudOrKick%Array(MudSystemDotimud) == 0 ) then
Ann_Density%Array(MudSystemDotimud)= (St_Density%Last() * MudSystemDotAnnulusFlowRate + 141.4296E-4*Rate_of_Penetration*Diameter_of_Bit**2)/(MudSystemDotAnnulusFlowRate+6.7995E-4*Rate_of_Penetration*Diameter_of_Bit**2)
Ann_CuttingMud%Array(MudSystemDotimud)= 1
if ( MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then
MudSystem%Ann_Density%Array(imud)= (MudSystem%St_Density%Last() * MudSystem%AnnulusFlowRate + 141.4296E-4*Rate_of_Penetration*Diameter_of_Bit**2)/(MudSystem%AnnulusFlowRate+6.7995E-4*Rate_of_Penetration*Diameter_of_Bit**2)
MudSystem%Ann_CuttingMud%Array(imud)= 1
endif
enddo
@@ -95,18 +95,18 @@ subroutine Instructor_CirculationMud_Edit ! is called in subroutine Circulat
if ( DownHole%AnnCirculateMud == .true. ) then
do MudSystemDotimud= 1, Ann_Density%Length()
do imud= 1, MudSystem%Ann_Density%Length()
if ( Ann_MudOrKick%Array(MudSystemDotimud) == 0 ) then
Ann_Density%Array(MudSystemDotimud)= ActiveTankDensity
Ann_CuttingMud%Array(MudSystemDotimud)= 0
if ( MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then
MudSystem%Ann_Density%Array(imud)= MudSystem%ActiveTankDensity
MudSystem%Ann_CuttingMud%Array(imud)= 0
endif
enddo
do MudSystemDotimud= 1, St_Density%Length()
do imud= 1, MudSystem%St_Density%Length()
St_Density%Array(MudSystemDotimud)= ActiveTankDensity
MudSystem%St_Density%Array(imud)= MudSystem%ActiveTankDensity
enddo
@@ -138,28 +138,28 @@ subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect

implicit none
MudSystemDotShoeLost= .false.
MudSystemDotKickexpansion_DueToMudLost= .false.
MudSystem%ShoeLost= .false.
MudSystem%Kickexpansion_DueToMudLost= .false.
MudSystemDotShoeMudPressure= PressureGauges(5)
MudSystem%ShoeMudPressure= PressureGauges(5)
MudSystemDotUGBOSuccessionCounter = MudSystemDotUGBOSuccessionCounter + 1
MudSystem%UGBOSuccessionCounter = MudSystem%UGBOSuccessionCounter + 1
!write(*,*) 'check point 1'
if (Shoe%InactiveFracture == .FALSE. .AND. ((MudSystemDotShoeMudPressure >= MudSystemDotFormationLostPressure) .or. MudSystemDotShoeFractured )) then
if (Shoe%InactiveFracture == .FALSE. .AND. ((MudSystem%ShoeMudPressure >= MudSystem%FormationLostPressure) .or. MudSystem%ShoeFractured )) then
!write(*,*) 'check point 2 ,UGBOSuccessionCounter' , UGBOSuccessionCounter
! if ShoeFractured changed to true , then time counter is not needed more
if ( MudSystemDotUGBOSuccessionCounter /= MudSystemDotUGBOSuccessionCounterOld+1 .and. MudSystemDotShoeFractured==.false. ) then
MudSystemDotUGBOSuccessionCounter = 0 ! also in starup
MudSystemDotUGBOSuccessionCounterOld = 0 ! also in starup
if ( MudSystem%UGBOSuccessionCounter /= MudSystem%UGBOSuccessionCounterOld+1 .and. MudSystem%ShoeFractured==.false. ) then
MudSystem%UGBOSuccessionCounter = 0 ! also in starup
MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup
return
else
MudSystemDotUGBOSuccessionCounterOld= MudSystemDotUGBOSuccessionCounter
MudSystem%UGBOSuccessionCounterOld= MudSystem%UGBOSuccessionCounter
endif

if ( MudSystemDotUGBOSuccessionCounter < 10 .and. MudSystemDotShoeFractured==.false.) then
if ( MudSystem%UGBOSuccessionCounter < 10 .and. MudSystem%ShoeFractured==.false.) then
return
endif
@@ -167,30 +167,30 @@ subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect
MudSystemDotShoeFractured= .true.
MudSystem%ShoeFractured= .true.
MudSystemDotShoeMudViscosity= MAX(MudSystemDotShoeMudViscosity, 12.d0)
MudSystem%ShoeMudViscosity= MAX(MudSystem%ShoeMudViscosity, 12.d0)
!write(*,*) 'ShoeMudDensity , ShoeMudViscosity' , ShoeMudDensity , ShoeMudViscosity
MudSystemDotShoeLostCoef = 10.**(-8) * 1.15741d0 * 7.08d0 * 1000000.d0 * 1.d0 * MudSystemDotShoeMudDensity / &
(MudSystemDotShoeMudViscosity * LOG(10000.d0))
MudSystem%ShoeLostCoef = 10.**(-8) * 1.15741d0 * 7.08d0 * 1000000.d0 * 1.d0 * MudSystem%ShoeMudDensity / &
(MudSystem%ShoeMudViscosity * LOG(10000.d0))
!write(*,*) 'lost parameters 1' , ShoeMudPressure , FormationLostPressure
MudSystemDotQlost = MAX( (MudSystemDotShoeLostCoef * (MudSystemDotShoeMudPressure - (MudSystemDotFormationLostPressure/2.0))) , 0.d0 )
if (MudSystemDotQlost > 0.0) then
MudSystemDotShoeLost= .true.
MudSystem%Qlost = MAX( (MudSystem%ShoeLostCoef * (MudSystem%ShoeMudPressure - (MudSystem%FormationLostPressure/2.0))) , 0.d0 )
if (MudSystem%Qlost > 0.0) then
MudSystem%ShoeLost= .true.
else
MudSystemDotShoeLost= .false.
MudSystem%ShoeLost= .false.
endif
!write(*,*) 'Qlost=' , Qlost, ShoeMudPressure, FormationLostPressure
call Activate_UndergroundBlowout()
do MudSystemDotimud= 1, Ann_Mud_Forehead_X%Length()
do imud= 1, MudSystem%Ann_Mud_Forehead_X%Length()

IF ( MudSystemDotShoeLost .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(MudSystemDotimud) .and. Shoe%ShoeDepth >= Ann_Mud_Forehead_X%Array(MudSystemDotimud) &
.and. Ann_MudOrKick%Array(MudSystemDotimud) == 0 .and. WellHeadIsOpen == .FALSE. ) then
IF ( MudSystem%ShoeLost .and. Shoe%ShoeDepth < MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= MudSystem%Ann_Mud_Forehead_X%Array(imud) &
.and. MudSystem%Ann_MudOrKick%Array(imud) == 0 .and. MudSystem%WellHeadIsOpen == .FALSE. ) then
MudSystemDotKickexpansion_DueToMudLost= .true.
MudSystem%Kickexpansion_DueToMudLost= .true.
write(*,*) 'Kickexpansion_DueToMudLost'
EXIT
@@ -204,7 +204,7 @@ subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect
endif
if (UndergroundBlowout == .false.) MudSystemDotShoeLost= .false.
if (UndergroundBlowout == .false.) MudSystem%ShoeLost= .false.


+ 404
- 409
Equipments/MudSystem/Kick_Migration.f90
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 352
- 363
Equipments/MudSystem/MudSystem.f90
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 3
- 3
Equipments/MudSystem/MudSystemMain.f90 Ver ficheiro

@@ -5,7 +5,7 @@ module MudSystemMain
! subroutine MudSystem_Setup()
! ! use CSimulationVariables
! use MudSystem
! use MudSystemModule
! implicit none
! call SetupMudSystem()
! call OnSimulationStop%Add(MudSystem_Stop)
@@ -27,7 +27,7 @@ module MudSystemMain
end subroutine MudSystem_Start
subroutine MudSystem_Step
use MudSystem
use MudSystemModule
use CManifolds
implicit none
!print* , 'MudSystem_Step'
@@ -41,7 +41,7 @@ module MudSystemMain

! subroutine MudSystemMainBody
! ! use CSimulationVariables
! use MudSystem
! use MudSystemModule
! implicit none
! INTEGER :: MudDuration


+ 176
- 176
Equipments/MudSystem/MudSystemStartup.f90 Ver ficheiro

@@ -20,88 +20,88 @@
!Pump2BlownStarted = .FALSE.
!Pump3BlownStarted = .FALSE.
MudSystemDotPump1BlownCount = 0
MudSystemDotPump2BlownCount = 0
MudSystemDotPump3BlownCount = 0
MudSystem%Pump1BlownCount = 0
MudSystem%Pump2BlownCount = 0
MudSystem%Pump3BlownCount = 0
MudSystemDotDeltaWellCap=0.
MudSystemDotWellCapOld = 0.
MudSystemDotAnnCapOld=0.
MudSystemDotDeltaAnnCap=0.
MudSystem%DeltaWellCap=0.
MudSystem%WellCapOld = 0.
MudSystem%AnnCapOld=0.
MudSystem%DeltaAnnCap=0.
MPumps%Total_Stroke_Counter_For_Plot = 0.0

DeltaT_Mudline=0.1 !second
MudSystem%DeltaT_Mudline=0.1 !second
Call Set_FlowKellyDisconnect(.false.)
Call Set_FlowPipeDisconnect(.false.)
!HZ_ADD= 0.d0
MudSystemDotFlow_timeCounter= 0
MudSystemDotMudSys_timeCounter= 0
MudSystemDotFluidFlowCounter = 0
MudSystem%Flow_timeCounter= 0
MudSystem%MudSys_timeCounter= 0
MudSystem%FluidFlowCounter = 0
!========================================================================
! MUD CIRCULATION STARTUP
!========================================================================
MudSystemDotFormationLostPressure= Shoe%LeakOff * Shoe%ShoeDepth
MudSystemDotShoeFractured= .false.
MudSystem%FormationLostPressure= Shoe%LeakOff * Shoe%ShoeDepth
MudSystem%ShoeFractured= .false.
MudSystemDotUGBOSuccessionCounter = 0 ! also in starup
MudSystemDotUGBOSuccessionCounterOld = 0 ! also in starup
MudSystem%UGBOSuccessionCounter = 0 ! also in starup
MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup
MudSystemDotChokeLineFlowRate= 0.0
MudSystemDotStringFlowRate= 0.0
MudSystemDotAnnulusFlowRate= 0.0
MudSystem%ChokeLineFlowRate= 0.0
MudSystem%StringFlowRate= 0.0
MudSystem%AnnulusFlowRate= 0.0
MudVolume_InjectedFromAnn= 0.D0
MudSystemDotMudVolume_InjectedToBH= 0.D0
MudSystem%MudVolume_InjectedFromAnn= 0.D0
MudSystem%MudVolume_InjectedToBH= 0.D0
MudSystemDotDensityMixTol= 0.1 !(ppg)
MudSystemDotCuttingDensityMixTol= 0.5
MudSystemDotNewPipeFilling= 1
MudSystemDotUtubeFilling= 1
MudSystemDotUtubeEmptyVolume= 0.0
MudSystem%DensityMixTol= 0.1 !(ppg)
MudSystem%CuttingDensityMixTol= 0.5
MudSystem%NewPipeFilling= 1
MudSystem%UtubeFilling= 1
MudSystem%UtubeEmptyVolume= 0.0
MudSystemDotUtubeMode1Activated= .false.
MudSystemDotUtubeMode2Activated= .false.
MudSystemDotUtubePossibility= .false.
MudSystem%UtubeMode1Activated= .false.
MudSystem%UtubeMode2Activated= .false.
MudSystem%UtubePossibility= .false.
!KickMigration_2SideBit = .FALSE.
MudSystemDotKickDx= (Reservoir%AutoMigrationRate/3600.)*DeltaT_Mudline !AutoMigrationRate (ft/h)= ft per DeltaT_Mudline
MudSystem%KickDx= (Reservoir%AutoMigrationRate/3600.)*MudSystem%DeltaT_Mudline !AutoMigrationRate (ft/h)= ft per DeltaT_Mudline

MudSystemDotNewInfluxElementCreated= 0
MudSystemDotNewInfluxNumber= 0
MudSystem%NewInfluxElementCreated= 0
MudSystem%NewInfluxNumber= 0
!KickVolumeinAnnulus= 0.0
MudSystemDotKickDeltaVinAnnulus= 0.0
MudSystem%KickDeltaVinAnnulus= 0.0
GasKickPumpFlowRate= 0.0
MudSystemDotFirstMudSet= 0
MudSystemDotFirstSetUtube1=0
MudSystemDotFirstSetUtube2=0
MudSystemDotSuctionMud=1
MudSystemDotImudCount= 1
MudSystemDotimud=1
MudSystemDotiLoc= 1 ! for Kick
Suction_Density_MudSystem= MudProperties%ActiveDensity
SuctionDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
StringDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
AnnulusSuctionDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
ChokeLineDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
MudSystem%FirstMudSet= 0
MudSystem%FirstSetUtube1=0
MudSystem%FirstSetUtube2=0
MudSystem%SuctionMud=1
MudSystem%ImudCount= 1
imud=1
MudSystem%iLoc= 1 ! for Kick
MudSystem%Suction_Density_MudSystem= MudProperties%ActiveDensity
MudSystem%SuctionDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
MudSystem%StringDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
MudSystem%AnnulusSuctionDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
MudSystem%ChokeLineDensity_Old= MudProperties%ActiveDensity ! initial(ppg)
MudSystemDotTotalAddedVolume= 0.
MudSystem%TotalAddedVolume= 0.


MudSystemDotxx=0.
MudSystem%xx=0.


@@ -134,121 +134,121 @@ MudSystemDotFluidFlowCounter = 0
!MPumps%Total_Pump_GPM=10. ! Initial Value
MUD%Q=0. ! Initial Value
Q_flow32=0.
Q_flow33=0.
Q_flow34=0.
Q_flow35=0.
MudSystem%Q_flow32=0.
MudSystem%Q_flow33=0.
MudSystem%Q_flow34=0.
MudSystem%Q_flow35=0.
DeltaT_Mudline=0.1 !second
MudSystem%DeltaT_Mudline=0.1 !second
GasKickPumpFlowRate= 0.
BellNippleVolume= 0.
BellNippleDensity= 0.
MudBucketVolume= 0.
MudBucketDensity= 0.
BellNippleDumpVolume= 0.
MudSystem%BellNippleVolume= 0.
MudSystem%BellNippleDensity= 0.
MudSystem%MudBucketVolume= 0.
MudSystem%MudBucketDensity= 0.
MudSystem%BellNippleDumpVolume= 0.
!BellNippleDumpRate= 0.
!BellNippleToPitsRate= 0.0
MudChecked= .true.
MudSystem%MudChecked= .true.
condition32Final= .TRUE.
condition33Final= .TRUE.
condition34Final= .TRUE.
MudSystem%condition32Final= .TRUE.
MudSystem%condition33Final= .TRUE.
MudSystem%condition34Final= .TRUE.
PressureGauge75= 0.0
PressureGauge76 = 0.0
MudSystem%PressureGauge75= 0.0
MudSystem%PressureGauge76 = 0.0

!!======================================================================
!! TRIP TANK
!!======================================================================
TripTank_MinVol_Allowded= 50.*42. !(bbl to gal, initial value)
TripTank_MaxVol_Allowded= 50. *42. !(bbl to gal, initial value)
MudSystem%TripTank_MinVol_Allowded= 50.*42. !(bbl to gal, initial value)
MudSystem%TripTank_MaxVol_Allowded= 50. *42. !(bbl to gal, initial value)
ActiveTankFloorArea= (MudProperties%ActiveTotalTankCapacityGal) / (7.48051948*100./12.) ! (ft^2) - Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3
TripTankFloorArea= (50.*42.) / (7.48051948*100./12.) ! (ft^2) - 50.*42.=Trip Tank Capacity in BBl*42= Gal , Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3
MudSystem%ActiveTankFloorArea= (MudProperties%ActiveTotalTankCapacityGal) / (7.48051948*100./12.) ! (ft^2) - Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3
MudSystem%TripTankFloorArea= (50.*42.) / (7.48051948*100./12.) ! (ft^2) - 50.*42.=Trip Tank Capacity in BBl*42= Gal , Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3



TripTank_Vol= MudProperties%InitialTripTankMudVolumeGal !(gal)
TripTank_Dens= 1.
MudSystem%TripTank_Vol= MudProperties%InitialTripTankMudVolumeGal !(gal)
MudSystem%TripTank_Dens= 1.
DataDisplayConsole%TripTankGauge=0.



ReturnToTrip_Q= 1.
ActiveToTrip_Q= 1.
MudSystem%ReturnToTrip_Q= 1.
MudSystem%ActiveToTrip_Q= 1.


TripTankPump_Q= .8
MudSystem%TripTankPump_Q= .8


ReturnToTrip_Dens=1.0 ! ppg(lbm/gal)
ActiveToTrip_Dens=1.0
MudSystem%ReturnToTrip_Dens=1.0 ! ppg(lbm/gal)
MudSystem%ActiveToTrip_Dens=1.0

!!======================================================================
!! MUD VOLUME TOTALIZER
!!======================================================================

Mp1Density= 0.0 !(VALVE82)
Mp2Density= 0.0 !(VALVE83)
Mp3Density= 0.0 !(VALVE84)
MudSystem%Mp1Density= 0.0 !(VALVE82)
MudSystem%Mp2Density= 0.0 !(VALVE83)
MudSystem%Mp3Density= 0.0 !(VALVE84)


ReserveTankVolume= MudProperties%ReserveMudVolumeGal ! initial volume (gal)
ReserveTankDensity= MudProperties%ReserveDensity ! initial
MudSystem%ReserveTankVolume= MudProperties%ReserveMudVolumeGal ! initial volume (gal)
MudSystem%ReserveTankDensity= MudProperties%ReserveDensity ! initial



CementTankVolumeCalc= Tank%CementTankVolume !movaghat--- initial volume (gal)
CementTankDensityCalc= Tank%CementTankDensity !movaghat--- initial
MudSystem%CementTankVolumeCalc= Tank%CementTankVolume !movaghat--- initial volume (gal)
MudSystem%CementTankDensityCalc= Tank%CementTankDensity !movaghat--- initial

PumpsDumpVolume=0.0
PumpsDumpFlowRate= 0.0
MudSystem%PumpsDumpVolume=0.0
MudSystem%PumpsDumpFlowRate= 0.0


ActiveTankVolume= MudProperties%ActiveMudVolumeGal ! initial volume (gal)
RefrencePitVolume= ActiveTankVolume/42. !(bbl)
RefrencePitVolume_DrillWatch= ActiveTankVolume/42. !(bbl)
MudSystem%ActiveTankVolume= MudProperties%ActiveMudVolumeGal ! initial volume (gal)
MudSystem%RefrencePitVolume= MudSystem%ActiveTankVolume/42. !(bbl)
MudSystem%RefrencePitVolume_DrillWatch= MudSystem%ActiveTankVolume/42. !(bbl)

MVT_MinVol_Allowded= 0.
MVT_MaxVol_Allowded= 0.
MudSystem%MVT_MinVol_Allowded= 0.
MudSystem%MVT_MaxVol_Allowded= 0.

MudTank1_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
MudTank2_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
MudTank3_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
ActiveTankSettled= MudProperties%ActiveSettledContentsGal ! (gal)
MudTank4_vol= MudProperties%InitialTripTankMudVolumeGal ! (gal)
MudSystem%MudTank1_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
MudSystem%MudTank2_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
MudSystem%MudTank3_vol= MudProperties%ActiveMudVolumeGal/3. ! (gal)
MudSystem%ActiveTankSettled= MudProperties%ActiveSettledContentsGal ! (gal)
MudSystem%MudTank4_vol= MudProperties%InitialTripTankMudVolumeGal ! (gal)

TripTankVolumeCalc= MudProperties%InitialTripTankMudVolumeGal ! initial volume (gal)
ActiveTankDensity= MudProperties%ActiveDensity ! initial(ppg)
TripTankDensityCalc= Tank%TripTankDensity ! initial(ppg)
MudSystem%TripTankVolumeCalc= MudProperties%InitialTripTankMudVolumeGal ! initial volume (gal)
MudSystem%ActiveTankDensity= MudProperties%ActiveDensity ! initial(ppg)
MudSystem%TripTankDensityCalc= Tank%TripTankDensity ! initial(ppg)

ChokeManifoldDumpVolume= 0.0
MudSystem%ChokeManifoldDumpVolume= 0.0

PitGainLossZero= 0.
PitGainLossZero_Old= PitGainLossZero
MVTCoarseKnob_Old= DataDisplayConsole%MVTCoarseKnob
MVTFineKnob_Old= DataDisplayConsole%MVTFineKnob
FirstSet_Time= .true.
MudSystem%PitGainLossZero= 0.
MudSystem%PitGainLossZero_Old= MudSystem%PitGainLossZero
MudSystem%MVTCoarseKnob_Old= DataDisplayConsole%MVTCoarseKnob
MudSystem%MVTFineKnob_Old= DataDisplayConsole%MVTFineKnob
MudSystem%FirstSet_Time= .true.



PedalMeter= MudProperties%PedalFlowMeter !1600. !(gpm)
ReturnFlowRate=0.
MudSystem%PedalMeter= MudProperties%PedalFlowMeter !1600. !(gpm)
MudSystem%ReturnFlowRate=0.



TotalStrokes1MFFI =0.
TotalStrokes2MFFI =0.
MudSystem%TotalStrokes1MFFI =0.
MudSystem%TotalStrokes2MFFI =0.

TotalStrokesPump1=0.
TotalStrokesPump2=0.
GraphTotalStrokes=0.
MudSystem%TotalStrokesPump1=0.
MudSystem%TotalStrokesPump2=0.
MudSystem%GraphTotalStrokes=0.
Choke%TotalStrokes1 =0.
@@ -284,71 +284,71 @@ INTEGER I
! MUDLINE MINOR LOSSES INPUT
!===========================================================================
NO_MudMinors=4
MudSystem%NO_MudMinors=4

ALLOCATE (MudMinors(NO_MudMinors,4))
ALLOCATE (MudSystem%MudMinors(MudSystem%NO_MudMinors,4))

! ID(INCH) LF CV NOTE(BAR) DESCRIPTION
MudMinors(1,1)= PumpsSpecification%MudPump1Output
MudMinors(1,2:4)= (/1.5*8., 0., 0./) !elbow (MLnumber=1,,PumpsToString)
MudMinors(2,1)= PumpsSpecification%MudPump1Output
MudMinors(2,2:4)= (/1.5*6., 0., 0./) !elbow (MLnumber=2,,STGaugeToString)
MudMinors(3,1:4)= (/0., 0., 0., 0./) !elbow (MLnumber=3,,WellToPits)
MudMinors(4,1)= BopStackSpecification%ChokeLineId
MudMinors(4,2:4)= (/1.5*7., 0., 0./) !elbow (MLnumber=4,,WellToChokeManifold)
MudSystem%MudMinors(1,1)= PumpsSpecification%MudPump1Output
MudSystem%MudMinors(1,2:4)= (/1.5*8., 0., 0./) !elbow (MLnumber=1,,PumpsToString)
MudSystem%MudMinors(2,1)= PumpsSpecification%MudPump1Output
MudSystem%MudMinors(2,2:4)= (/1.5*6., 0., 0./) !elbow (MLnumber=2,,STGaugeToString)
MudSystem%MudMinors(3,1:4)= (/0., 0., 0., 0./) !elbow (MLnumber=3,,WellToPits)
MudSystem%MudMinors(4,1)= BopStackSpecification%ChokeLineId
MudSystem%MudMinors(4,2:4)= (/1.5*7., 0., 0./) !elbow (MLnumber=4,,WellToChokeManifold)


ALLOCATE (MINORDIAMETER_MUDLINE(NO_MudMinors),AREAMINOR_MUDLINE(NO_MudMinors),LF_MUDLINE(NO_MudMinors),CV_MUDLINE(NO_MudMinors) &
,NOTE_MUDLINE(NO_MudMinors))
ALLOCATE (MudSystem%MINORDIAMETER_MUDLINE(MudSystem%NO_MudMinors),MudSystem%AREAMINOR_MUDLINE(MudSystem%NO_MudMinors),MudSystem%LF_MUDLINE(MudSystem%NO_MudMinors),MudSystem%CV_MUDLINE(MudSystem%NO_MudMinors) &
,MudSystem%NOTE_MUDLINE(MudSystem%NO_MudMinors))



DO I=1,NO_MudMinors
MINORDIAMETER_MUDLINE(I)=MudMinors(I,1)
LF_MUDLINE(I)=MudMinors(I,2)
CV_MUDLINE(I)=MudMinors(I,3)
NOTE_MUDLINE(I)=MudMinors(I,4)
DO I=1,MudSystem%NO_MudMinors
MudSystem%MINORDIAMETER_MUDLINE(I)=MudSystem%MudMinors(I,1)
MudSystem%LF_MUDLINE(I)=MudSystem%MudMinors(I,2)
MudSystem%CV_MUDLINE(I)=MudSystem%MudMinors(I,3)
MudSystem%NOTE_MUDLINE(I)=MudSystem%MudMinors(I,4)
AREAMINOR_MUDLINE(I)=PII*(MINORDIAMETER_MUDLINE(I)*0.0254)**2/4. !D(in), AREA(m^2)
MudSystem%AREAMINOR_MUDLINE(I)=PII*(MudSystem%MINORDIAMETER_MUDLINE(I)*0.0254)**2/4. !D(in), AREA(m^2)
ENDDO
!===========================================================================
! MUDLINE PIPNING LOSSES INPUT
!===========================================================================
NO_PIPINGSMUDLINE=4
MudSystem%NO_PIPINGSMUDLINE=4

ALLOCATE (PIPINGS_MUDLINE(NO_PIPINGSMUDLINE,3))
ALLOCATE (MudSystem%PIPINGS_MUDLINE(MudSystem%NO_PIPINGSMUDLINE,3))

! ID(INCH) L(FEET) ROUGHNESS(MM)=e DESCRIPTION
PIPINGS_MUDLINE(1,1)= PumpsSpecification%MudPump1Output
PIPINGS_MUDLINE(1,2:3)= (/265., 0.03/) !(MLnumber=1,,PumpsToString)
PIPINGS_MUDLINE(2,1)= PumpsSpecification%MudPump1Output
PIPINGS_MUDLINE(2,2:3)= (/100., 0.03/) !(MLnumber=2,,STGaugeToString)
PIPINGS_MUDLINE(3,1:3)= (/0., 0., 0./) !(MLnumber=3,,WellToPits)
PIPINGS_MUDLINE(4,1)= BopStackSpecification%ChokeLineId
PIPINGS_MUDLINE(4,2)= BopStackSpecification%ChokeLineLength
PIPINGS_MUDLINE(4,3)= 0.03 !(MLnumber=4,,WellToChokeManifold)
MudSystem%PIPINGS_MUDLINE(1,1)= PumpsSpecification%MudPump1Output
MudSystem%PIPINGS_MUDLINE(1,2:3)= (/265., 0.03/) !(MLnumber=1,,PumpsToString)
MudSystem%PIPINGS_MUDLINE(2,1)= PumpsSpecification%MudPump1Output
MudSystem%PIPINGS_MUDLINE(2,2:3)= (/100., 0.03/) !(MLnumber=2,,STGaugeToString)
MudSystem%PIPINGS_MUDLINE(3,1:3)= (/0., 0., 0./) !(MLnumber=3,,WellToPits)
MudSystem%PIPINGS_MUDLINE(4,1)= BopStackSpecification%ChokeLineId
MudSystem%PIPINGS_MUDLINE(4,2)= BopStackSpecification%ChokeLineLength
MudSystem%PIPINGS_MUDLINE(4,3)= 0.03 !(MLnumber=4,,WellToChokeManifold)

MudSystemDotArea_ChokeLineFt= PII*((BopStackSpecification%ChokeLineId/12.)**2)/4. !D(in), AREA(ft^2)
MudSystemDotChokeLine_VolumeCapacity= MudSystemDotArea_ChokeLineFt* BopStackSpecification%ChokeLineLength* 7.48051948 ! (gal)
MudSystem%Area_ChokeLineFt= PII*((BopStackSpecification%ChokeLineId/12.)**2)/4. !D(in), AREA(ft^2)
MudSystem%ChokeLine_VolumeCapacity= MudSystem%Area_ChokeLineFt* BopStackSpecification%ChokeLineLength* 7.48051948 ! (gal)

ALLOCATE (DIAM_MUDLINE_INCH(NO_PIPINGSMUDLINE), &
AREA_MUDLINE(NO_PIPINGSMUDLINE),LENGT_MUDLINE(NO_PIPINGSMUDLINE),ROUGHNESS_MUDLINE(NO_PIPINGSMUDLINE),RELROUGH_MUDLINE(NO_PIPINGSMUDLINE))
ALLOCATE (MudSystem%DIAM_MUDLINE_INCH(MudSystem%NO_PIPINGSMUDLINE), &
MudSystem%AREA_MUDLINE(MudSystem%NO_PIPINGSMUDLINE),MudSystem%LENGT_MUDLINE(MudSystem%NO_PIPINGSMUDLINE),MudSystem%ROUGHNESS_MUDLINE(MudSystem%NO_PIPINGSMUDLINE),MudSystem%RELROUGH_MUDLINE(MudSystem%NO_PIPINGSMUDLINE))


DO I=1,NO_PIPINGSMUDLINE
DIAM_MUDLINE_INCH(I)=PIPINGS_MUDLINE(I,1)
LENGT_MUDLINE(I)=PIPINGS_MUDLINE(I,2)
ROUGHNESS_MUDLINE(I)=PIPINGS_MUDLINE(I,3)
DO I=1,MudSystem%NO_PIPINGSMUDLINE
MudSystem%DIAM_MUDLINE_INCH(I)=MudSystem%PIPINGS_MUDLINE(I,1)
MudSystem%LENGT_MUDLINE(I)=MudSystem%PIPINGS_MUDLINE(I,2)
MudSystem%ROUGHNESS_MUDLINE(I)=MudSystem%PIPINGS_MUDLINE(I,3)
AREA_MUDLINE(I)=PII*(DIAM_MUDLINE_INCH(I)*0.0254)**2/4 !D(in), AREA(m^2)
RELROUGH_MUDLINE(I)=ROUGHNESS_MUDLINE(I)/(DIAM_MUDLINE_INCH(I)*25.4) !e/D
MudSystem%AREA_MUDLINE(I)=PII*(MudSystem%DIAM_MUDLINE_INCH(I)*0.0254)**2/4 !D(in), AREA(m^2)
MudSystem%RELROUGH_MUDLINE(I)=MudSystem%ROUGHNESS_MUDLINE(I)/(MudSystem%DIAM_MUDLINE_INCH(I)*25.4) !e/D
!DIAM_MUDLINE_MM(I)=DIAM_MUDLINE_MM(I)*.001 ! (m)
LENGT_MUDLINE(I)=LENGT_MUDLINE(I)*.3048 ! (m)
MudSystem%LENGT_MUDLINE(I)=MudSystem%LENGT_MUDLINE(I)*.3048 ! (m)
ENDDO


@@ -357,11 +357,11 @@ ENDDO
!===========================================================================

! Height are in (meter)
Pumps_Height= 0.
STpipeGauge_Height= 2. !(m)
Pits_Height= 1. !(m)
ChokeManifold_Height= 1.*0.3048 !(ft to meter)
WellChokeExit_Height= BopStackSpecification%GroundLevel-BopStackSpecification%KillHeight
MudSystem%Pumps_Height= 0.
MudSystem%STpipeGauge_Height= 2. !(m)
MudSystem%Pits_Height= 1. !(m)
MudSystem%ChokeManifold_Height= 1.*0.3048 !(ft to meter)
MudSystem%WellChokeExit_Height= BopStackSpecification%GroundLevel-BopStackSpecification%KillHeight



@@ -389,40 +389,40 @@ WellChokeExit_Height= BopStackSpecification%GroundLevel-BopStackSpecification%Ki
!===============================PIPE LOSS===================================
MUD(MLnumber)%Re_MUDline=MUD(MLnumber)%Q*6.30902e-5*DIAM_MUDLINE_INCH(MLnumber)*0.0254/(AREA_MUDLINE(MLnumber)*MUD(MLnumber)%nu) !<<<<<< nu: DOROST SHAVAD.ALAN DAR STARTUP SET SHODE
MUD(MLnumber)%Re_MUDline=MUD(MLnumber)%Q*6.30902e-5*MudSystem%DIAM_MUDLINE_INCH(MLnumber)*0.0254/(MudSystem%AREA_MUDLINE(MLnumber)*MUD(MLnumber)%nu) !<<<<<< nu: DOROST SHAVAD.ALAN DAR STARTUP SET SHODE
!write(*,*) 'MUD(MLnumber)%Re_MUDline=' , MUD(MLnumber)%Re_MUDline
! Q*6.30902e-5 for (gpm) to (m^3/sec)
if ( MUD(MLnumber)%Re_MUDline<Re_cr) then
MUD(MLnumber)%fric=64/ MUD(MLnumber)%Re_MUDline
else

MUD(MLnumber)%fric=1/(-1.8*log10((RELROUGH_MUDLINE(MLnumber)/3.7)**1.11+6.9/ MUD(MLnumber)%Re_MUDline))**2
MUD(MLnumber)%fric=1/(-1.8*log10((MudSystem%RELROUGH_MUDLINE(MLnumber)/3.7)**1.11+6.9/ MUD(MLnumber)%Re_MUDline))**2
endif

MUD(MLnumber)%fricloss=((MUD(MLnumber)%fric*(wdens*MUD(MLnumber)%Mud_SG*LENGT_MUDLINE(MLnumber)*(MUD(MLnumber)%Q*6.30902e-5/AREA_MUDLINE(MLnumber))**2))/(2*DIAM_MUDLINE_INCH(MLnumber)*0.0254))/6895
MUD(MLnumber)%fricloss=((MUD(MLnumber)%fric*(wdens*MUD(MLnumber)%Mud_SG*MudSystem%LENGT_MUDLINE(MLnumber)*(MUD(MLnumber)%Q*6.30902e-5/MudSystem%AREA_MUDLINE(MLnumber))**2))/(2*MudSystem%DIAM_MUDLINE_INCH(MLnumber)*0.0254))/6895


!==============================MINOR LOSS===================================

if (LF_MUDLINE(MLnumber)/=0) then
MUD(MLnumber)%minlosspa_MUDLINE=LF_MUDLINE(MLnumber)*wdens*MUD(MLnumber)%Mud_SG*(MUD(MLnumber)%Q*6.30902e-5/AREAMINOR_MUDLINE(MLnumber))**2/2 !(Pa)
if (MudSystem%LF_MUDLINE(MLnumber)/=0) then
MUD(MLnumber)%minlosspa_MUDLINE=MudSystem%LF_MUDLINE(MLnumber)*wdens*MUD(MLnumber)%Mud_SG*(MUD(MLnumber)%Q*6.30902e-5/MudSystem%AREAMINOR_MUDLINE(MLnumber))**2/2 !(Pa)
MUD(MLnumber)%minloss_MUDLINE= MUD(MLnumber)%minlosspa_MUDLINE/6895 !(psi)
elseif (CV_MUDLINE(MLnumber)/=0) then
MUD(MLnumber)%minlosspa_MUDLINE=1000*MUD(MLnumber)%Mud_SG*((11.7*MUD(MLnumber)%Q*6.30902e-5*3600)/(CV_MUDLINE(MLnumber)))**2 !(pa)
elseif (MudSystem%CV_MUDLINE(MLnumber)/=0) then
MUD(MLnumber)%minlosspa_MUDLINE=1000*MUD(MLnumber)%Mud_SG*((11.7*MUD(MLnumber)%Q*6.30902e-5*3600)/(MudSystem%CV_MUDLINE(MLnumber)))**2 !(pa)
MUD(MLnumber)%minloss_MUDLINE= MUD(MLnumber)%minlosspa_MUDLINE/6895 !(psi)
else
MUD(MLnumber)%minlosspa_MUDLINE=NOTE_MUDLINE(MLnumber)*1e5 !(pa)
MUD(MLnumber)%minlosspa_MUDLINE=MudSystem%NOTE_MUDLINE(MLnumber)*1e5 !(pa)
MUD(MLnumber)%minloss_MUDLINE= MUD(MLnumber)%minlosspa_MUDLINE/6895 !(psi)
endif

!==========================STATIC & KINETIC LOSS=============================

String_Height= 50.*0.3048 !<<<<<<<<<<<<<<< (foot) to (meter). az khanom tarmigh
MUD(1)%static_loss=(String_Height- Pumps_Height)*0.0 !(MLnumber=1,,PumpsToString)
MUD(2)%static_loss=(String_Height- STpipeGauge_Height)*MUD(2)%Mud_SG*wdens*gravity/6895 ! (psi) (MLnumber=2,,STGaugeToString)
MudSystem%String_Height= 50.*0.3048 !<<<<<<<<<<<<<<< (foot) to (meter). az khanom tarmigh
MUD(1)%static_loss=(MudSystem%String_Height- MudSystem%Pumps_Height)*0.0 !(MLnumber=1,,PumpsToString)
MUD(2)%static_loss=(MudSystem%String_Height- MudSystem%STpipeGauge_Height)*MUD(2)%Mud_SG*wdens*gravity/6895 ! (psi) (MLnumber=2,,STGaugeToString)
MUD(3)%static_loss=0. !(MLnumber=1,,WellToPits)
MUD(4)%static_loss=(ChokeManifold_Height- WellChokeExit_Height)*MUD(4)%Mud_SG*wdens*gravity/6895 !(MLnumber=4,,WellToChokeManifold)
MUD(4)%static_loss=(MudSystem%ChokeManifold_Height- MudSystem%WellChokeExit_Height)*MUD(4)%Mud_SG*wdens*gravity/6895 !(MLnumber=4,,WellToChokeManifold)



@@ -447,28 +447,28 @@ implicit none
!===========================================================================
! RAMLINE MINOR LOSSES INPUT
!===========================================================================
if (allocated(MudMinors)) DEALLOCATE (MudMinors)
if (allocated(MudSystem%MudMinors)) DEALLOCATE (MudSystem%MudMinors)
!===========================================================================
! RAMLINE PIPNING LOSSES INPUT
!===========================================================================
if (allocated(MINORDIAMETER_MUDLINE)) DEALLOCATE (MINORDIAMETER_MUDLINE)
if (allocated(AREAMINOR_MUDLINE)) DEALLOCATE (AREAMINOR_MUDLINE)
if (allocated(LF_MUDLINE)) DEALLOCATE (LF_MUDLINE)
if (allocated(CV_MUDLINE)) DEALLOCATE (CV_MUDLINE)
if (allocated(NOTE_MUDLINE)) DEALLOCATE (NOTE_MUDLINE)
if (allocated(MudSystem%MINORDIAMETER_MUDLINE)) DEALLOCATE (MudSystem%MINORDIAMETER_MUDLINE)
if (allocated(MudSystem%AREAMINOR_MUDLINE)) DEALLOCATE (MudSystem%AREAMINOR_MUDLINE)
if (allocated(MudSystem%LF_MUDLINE)) DEALLOCATE (MudSystem%LF_MUDLINE)
if (allocated(MudSystem%CV_MUDLINE)) DEALLOCATE (MudSystem%CV_MUDLINE)
if (allocated(MudSystem%NOTE_MUDLINE)) DEALLOCATE (MudSystem%NOTE_MUDLINE)
!===========================================================================
! ANNULAR MINOR LOSSES INPUT
!===========================================================================
if (allocated(PIPINGS_MUDLINE)) DEALLOCATE (PIPINGS_MUDLINE)
if (allocated(MudSystem%PIPINGS_MUDLINE)) DEALLOCATE (MudSystem%PIPINGS_MUDLINE)
!===========================================================================
! ANNULAR PIPNING LOSSES INPUT
!===========================================================================
if (allocated(DIAM_MUDLINE_INCH)) DEALLOCATE (DIAM_MUDLINE_INCH)
if (allocated(AREA_MUDLINE)) DEALLOCATE (AREA_MUDLINE)
if (allocated(LENGT_MUDLINE)) DEALLOCATE (LENGT_MUDLINE)
if (allocated(ROUGHNESS_MUDLINE)) DEALLOCATE (ROUGHNESS_MUDLINE)
if (allocated(RELROUGH_MUDLINE)) DEALLOCATE (RELROUGH_MUDLINE)
if (allocated(MudSystem%DIAM_MUDLINE_INCH)) DEALLOCATE (MudSystem%DIAM_MUDLINE_INCH)
if (allocated(MudSystem%AREA_MUDLINE)) DEALLOCATE (MudSystem%AREA_MUDLINE)
if (allocated(MudSystem%LENGT_MUDLINE)) DEALLOCATE (MudSystem%LENGT_MUDLINE)
if (allocated(MudSystem%ROUGHNESS_MUDLINE)) DEALLOCATE (MudSystem%ROUGHNESS_MUDLINE)
if (allocated(MudSystem%RELROUGH_MUDLINE)) DEALLOCATE (MudSystem%RELROUGH_MUDLINE)
END


+ 150
- 170
Equipments/MudSystem/MudSystem_Variables.f90 Ver ficheiro

@@ -17,165 +17,152 @@ USE CReservoirVariables
IMPLICIT NONE

integer, parameter :: BlownThreshold = 10

! temporary varibales for solving pressure jerks -- 1399-11-09
integer MudSystemDotPump1BlownCount, MudSystemDotPump2BlownCount, MudSystemDotPump3BlownCount

!integer Pump1BlownInTimeStep, Pump2BlownInTimeStep, Pump3BlownInTimeStep
!logical Pump1BlownStarted, Pump2BlownStarted, Pump3BlownStarted
!integer, parameter :: BlownThresholdInSecond = 5

real(8) MudSystemDottotal_add,MudSystemDottotal_injected
real(8) MudSystemDotDeltaWellCap,MudSystemDotWellCapOld,MudSystemDotAnnCapOld,MudSystemDotDeltaAnnCap

!========================================================================
! KICK VARIABLES
!========================================================================
REAL(8) MudSystemDotKickDeltaVinAnnulus, MudSystemDotKickVolumeinAnnulus
REAL(8) MudSystemDotKick_Forehead_X,MudSystemDotKick_RemainedVolume_in_LastSection,MudSystemDotBackheadX,MudSystemDotKickDv,MudSystemDotKickDx,MudSystemDotMinKickDv,MudSystemDotOld_KickBackHead_X,MudSystemDotKick_Density
INTEGER MudSystemDotNewInfluxElementCreated,MudSystemDotKick_Forehead_section,MudSystemDotMudSection,MudSystemDotOp_KickLoc,MudSystemDotAnn_KickLoc,MudSystemDotFirstSetKickMigration,MudSystemDotOld_KickBackHead_Section
Integer MudSystemDotiLoc,MudSystemDotChokeLine_KickLoc,MudSystemDotKickNumber,MudSystemDotNewInfluxNumber,MudSystemDotSoundGasThroughChoke

LOGICAL MudSystemDotDrillingMode
!real(8) HZ_ADD
integer MudSystemDotFlow_timeCounter,MudSystemDotMudSys_timeCounter,MudSystemDotFluidFlowCounter
!========================================================================
! MUD CIRCULATION
!========================================================================
REAL(8), ALLOCATABLE:: MudSystemDotXstart_PipeSection(:),MudSystemDotXend_PipeSection(:),MudSystemDotPipeSection_VolumeCapacity(:),MudSystemDotArea_PipeSectionFt(:),MudSystemDotOD_PipeSectionInch(:),MudSystemDotID_PipeSectionInch(:),MudSystemDotAngle_PipeSection(:)
REAL(8), ALLOCATABLE:: MudSystemDotXstart_OpSection(:),MudSystemDotXend_OpSection(:),MudSystemDotArea_OpSectionFt(:),MudSystemDotOD_OpSectionInch(:),MudSystemDotID_OpSectionInch(:),MudSystemDotOpSection_VolumeCapacity(:),MudSystemDotGeoTypeOp(:),MudSystemDotAngle_OpSection(:)
REAL(8), ALLOCATABLE:: MudSystemDotTDXstart_MudElementArray(:) , MudSystemDotTDXend_MudElementArray(:) , MudSystemDotTDDensity_MudElementArray(:)

INTEGER, ALLOCATABLE:: MudSystemDotGeoType(:)
real(8) MudSystemDotStMudVolumeSum,MudSystemDotSt_MudSaved_Density,MudSystemDotSt_Saved_MudDischarged_Volume,MudSystemDotSt_Saved_MudDischarged_Volume_Final,MudSystemDotMudVolume_InjectedToBH,MudSystemDotMudVolume_Injec2tedFromAnn
real MudSystemDotBitMudDensity
REAL(8) MudSystemDotxx,MudSystemDotNewVolume,MudSystemDotUtubeEmptyVolume,MudSystemDotNe2wDensity, MudSystemDotMudCircVerticalDepth
! ,TrueMinValue
REAL MudSystemDotDirectionCoef
INTEGER MudSystemDotisection,MudSystemDotOpSection,MudSystemDotimud,MudSystemDotSuctionMud,MudSystemDotNoStringMudElements,MudSystemDotImudCount,MudSystemDotNoCasingMudElements,MudSystemDotNoHorizontalMudElements,MudSystemDotAddedElementsToString
Integer MudSystemDotTDNoHorizontalMudElements, MudSystemDotTDNoStringMudElements, MudSystemDotTDNoCasingMudElements
Integer MudSystemDotistring,MudSystemDoticasing,MudSystemDotiisection,MudSystemDotNoPipeSections,MudSystemDotFirstMudSet
INTEGER MudSystemDotNoBottomHoleMudElements,MudSystemDotNoStringMudElementsForPlot,MudSystemDotF_StringIntervalCounts_Old
INTEGER MudSystemDotFirstSetUtube1,MudSystemDotFirstSetUtube2,MudSystemDotFirstAdded,MudSystemDotNewPipeFilling,MudSystemDotHz_MudOrKick_Utube,MudSystemDotUtubeFilling,MudSystemDottotalLength
REAL(8) MudSystemDotDeltaVolumeOp,MudSystemDotDeltaVTemp,MudSystemDotOldPosition,MudSystemDotStringFlowRate,MudSystemDotStringFlowRateFinal,MudSystemDotAnnulusFlowRateFinal,MudSystemDotTD_RemoveVolume_Remained,MudSystemDotDeltaVolumePipe,MudSystemDotDeltaVolumeAnnulusCapacity
REAL MudSystemDotAnnulusFlowRate,MudSystemDotChokeLineFlowRate
Logical:: MudSystemDotUtubePossibility,MudSystemDotMudIsChanged,MudSystemDotAddedPipe,MudSystemDotUtubeMode1Activated,MudSystemDotUtubeMode2Activated,MudSystemDotWellisNOTFull,MudSystemDotChokeLineNOTFull
Logical:: MudSystemDotShoeLost,MudSystemDotShoeFractured,MudSystemDotKickexpansion_DueToMudLost,MudSystemDotLostInTripOutIsDone
Integer MudSystemDotUGBOSuccessionCounter, MudSystemDotUGBOSuccessionCounterOld
REAL(8) MudSystemDotArea_ChokeLineFt, MudSystemDotChokeLine_VolumeCapacity,MudSystemDotTotalAddedVolume,MudSystemDotLackageMudVolumeAfterFilling, MudSystemDotLackageMudVolume, MudSystemDotNewInflux_Density
real(8) MudSystemDotDensityMixTol,MudSystemDotHz_Density_Utube,MudSystemDotCuttingDensityMixTol,MudSystemDotOp_Kick_Saved_Volume,MudSystemDotOp_MudSaved_Density,MudSystemDotOp_KickSaved_Density,MudSystemDotOp_Saved_MudDischarged_Volume,MudSystemDotOpMudVolumeSum,MudSystemDotOp_NeededVolume_ToFill
real(8) MudSystemDotChoke_Kick_Saved_Volume,MudSystemDotChoke_Saved_MudDischarged_Volume,MudSystemDotChoke_KickSaved_Density,MudSystemDotChoke_MudSaved_Density,MudSystemDotChokeMudVolumeSum
integer MudSystemDotSaved_Op_MudOrKick,MudSystemDotSaved_Ann_MudOrKick,MudSystemDotSaved_Choke_MudOrKick
real(8) MudSystemDotChoke_Saved_MudDischarged_Volume_Final,MudSystemDotChoke_Kick_Saved_Volume_Final
real(8) MudSystemDotQlost,MudSystemDotFormationLostPressure,MudSystemDotShoeMudPressure,MudSystemDotShoeLostCoef, MudSystemDotShoeMudViscosity, MudSystemDotShoeMudDensity ,MudSystemDotOldAnnulusCapacity
logical:: MudSystemDotAnn_to_Choke_2mud
real(8) MudSystemDotAnnMudVolumeSum,MudSystemDotAnn_MudSaved_Density,MudSystemDotAnn_KickSaved_Density,MudSystemDotAnn_Saved_MudDischarged_Volume,MudSystemDotAnn_Kick_Saved_Volume,MudSystemDotAnn_Saved_MudDischarged_Volume_Final, MudSystemDotAnn_Kick_Saved_Volume_Final
type(DynamicDoubleArrayType) :: MudSystemDotHz_MudDischarged_Volume,MudSystemDotHz_Mud_Backhead_X,MudSystemDotHz_Mud_Forehead_X,MudSystemDotHz_Density,MudSystemDotHz_RemainedVolume_in_LastSection,MudSystemDotHz_EmptyVolume_inBackheadLocation, &
MudSystemDotOp_MudDischarged_Volume,MudSystemDotOp_Mud_Backhead_X,MudSystemDotOp_Mud_Forehead_X,MudSystemDotOp_Density,MudSystemDotOp_RemainedVolume_in_LastSection,MudSystemDotOp_EmptyVolume_inBackheadLocation

type(DynamicDoubleArrayType) :: MudSystemDotChokeLine_MudDischarged_Volume,MudSystemDotChokeLine_Mud_Backhead_X,MudSystemDotChokeLine_Mud_Forehead_X,MudSystemDotChokeLine_Density,MudSystemDotChokeLine_RemainedVolume_in_LastSection, &
MudSystemDotChokeLine_EmptyVolume_inBackheadLocation


type(DynamicDoubleArrayType) :: MudSystemDotSt_MudDischarged_Volume,MudSystemDotSt_Mud_Backhead_X,MudSystemDotSt_Mud_Forehead_X,St_Density,MudSystemDotSt_RemainedVolume_in_LastSection, &
MudSystemDotSt_EmptyVolume_inBackheadLocation,MudSystemDotAnn_MudDischarged_Volume,Ann_Mud_Backhead_X,Ann_Mud_Forehead_X, &
Ann_Density,Ann_RemainedVolume_in_LastSection,Ann_EmptyVolume_inBackheadLocation
type(DynamicIntegerArrayType) :: St_Mud_Backhead_section,St_Mud_Forehead_section,Ann_Mud_Backhead_section,Ann_Mud_Forehead_section,MudGeoType,Hz_Mud_Backhead_section,Hz_Mud_Forehead_section, &
Op_Mud_Backhead_section,Op_Mud_Forehead_section,Hz_MudOrKick,St_MudOrKick,Ann_MudOrKick,Op_MudOrKick,ChokeLine_MudOrKick,MudTypeOp_MudElement,MudType_MudElement

type(DynamicIntegerArrayType) :: ChokeLine_Mud_Backhead_section,ChokeLine_Mud_Forehead_section,Ann_CuttingMud

type(DynamicDoubleArrayType) :: Xend_MudElement,Xstart_MudElement,Density_MudElement,PipeID_MudElement,PipeOD_MudElement,Angle_MudElement, &
Xstart_OpMudElement,Xend_OpMudElement,Density_OpMudElement,PipeID_OpMudElement,PipeOD_OpMudElement!,Angle_OpMudElement
type(DynamicDoubleArrayType) :: TVDstart_MudElement, TVDend_MudElement, TVDstart_OpMudElement, TVDend_OpMudElement
type(CFluid), allocatable :: StringMudElement(:), CasingMudElement(:)


real(8) PressureGauge75,PressureGauge76

!========================================================================
! MALFUNCTION VARIABLES
!========================================================================
INTEGER StandPipeGauge1Malf, StandPipeGauge2Malf, StandPipePressure_DataDisplayMalf,StandPipePressureChokeMalf,DrillPipePressureMalf
integer TripTankPressure_DataDisplayMalf,PitGainLossGaugeMalf,ReturnMudFlowGaugeMalf,MudTanksVolumeGaugeMalf



!========================================================================
! TRIP TANK VARIABLES
!========================================================================
logical condition32Final,condition33Final,condition34Final

REAL(8) TripTank_Vol,TripTank_Dens,ReturnToTrip_Q,ActiveToTrip_Q,TripTankPump_Q,ReturnToTrip_Dens,ActiveToTrip_Dens,ReturnToTrip_deltaV,ActiveToTrip_deltaV
REAL(8) MassFlowRate_ReturnToTrip,MassFlowRate_ActiveToTrip,TripTankPump_deltaV,MassFlowRate_TripTankPump,NetMassFlux_tripTank
REAL(8) TripTank_MinVol_Allowded,TripTank_MaxVol_Allowded


!!======================================================================
!! MUD VOLUME TOTALIZER
!!======================================================================
REAL(8) RefrencePitVolume_DrillWatch ! for DrillWatch
REAL(8) MudTank1_vol,MudTank2_vol,MudTank3_vol,MudTank4_vol
REAL(8) MVT_MinVol_Allowded,MVT_MaxVol_Allowded,MudTanksVolume
REAL(8) PitGainLossZero,MVTCoarse,MVTFine,RefrencePitVolume,PitGainLossZero_Old,MVTCoarseKnob_Old,MVTFineKnob_Old
REAL(8) ActiveTankDensity,TripTankDensityCalc,SuctionDensity_Old,AnnulusSuctionDensity_Old,StringDensity_Old,ChokeLineDensity_Old,ChokeManifoldDumpVolume
LOGICAL FirstSet_Time
!!======================================================================
!! MUD FLOW-FILL INDICATOR
!!======================================================================

REAL(8) TotalStrokes1MFFI,TotalStrokes2MFFI,TotalStrokesPump1,TotalStrokesPump2,GraphTotalStrokes
REAL(8) PedalMeter,ReturnFlowRate,ReturnFlowPercent,MFFI_MinPercent_Allowded,MFFI_MaxPercent_Allowded
REAL(8) TotalFillStrokes1MFFI,TotalFillStrokes2MFFI,TotalFilledStrokesBy1MFFI,TotalFilledStrokesBy2MFFI,TotalFilledStrokesBy1and2MFFI

!=================================================================================


!============================================================================
! MUD & ENVIRONMENT VARIABLES
!============================================================================
REAL:: SG=1.12,WDENS=1000,GRAVITY=9.81,RE_CR=2000!,NU=9e-6
!specific gravity of liquid
!water density(kg/m^3)


PARAMETER PII=3.14159265
INTEGER NO_MudMinors,NO_PIPINGSMUDLINE
REAL(8) Pumps_Height,String_Height,STpipeGauge_Height,Pits_Height,ChokeManifold_Height,WellChokeExit_Height
REAL(8) STGauge_Pressure,String_Input_Pressure,Well_Output_Pressure,Pressure_BeforeChokes,Pressure_AfterChokes
REAL(8) OpenArea32,OpenArea33,OpenArea34,OpenArea35,deltaPchoke,WellOutletDensity,ChokeOutletDensity
REAL Q_flow32,Q_flow33,Q_flow34,Q_flow35
REAL(8) DeltaT_Mudline,ActiveTankVolume,ReserveTankVolume,CementTankVolumeCalc,ActiveTankSettled,ActiveTankFloorArea,TripTankFloorArea
REAL(8) TripTankVolumeCalc,BellNippleDensity,BellNippleVolume,MudBucketDensity,MudBucketVolume,BellNippleDumpVolume
REAL(8) ReserveTankDensity,CementTankDensityCalc,Mp1Density,Mp2Density,Mp3Density,PumpsDumpVolume
real PumpsDumpFlowRate
REAL(8) Density_Ch
real(8) Suction_Density_MudSystem,Suction_Density_PumpsToWell,CompressedMudDensity
Logical WellToPitsOpen,WellToChokeManifoldOpen,MudChecked,WellHeadIsOpen
logical Pump1OffFailure,Pump2OffFailure,Pump3OffFailure,ChokeLineGaugeToTanks,WellToChokeLineGauge



REAL,ALLOCATABLE:: MudMinors(:,:),AREA_MUDLINE(:),MINORDIAMETER_MUDLINE(:),NOTE_MUDLINE(:),AREAMINOR_MUDLINE(:),LF_MUDLINE(:),CV_MUDLINE(:)
REAL,ALLOCATABLE:: DIAM_MUDLINE_INCH(:),LENGT_MUDLINE(:),ROUGHNESS_MUDLINE(:),RELROUGH_MUDLINE(:),PIPINGS_MUDLINE(:,:)
REAL:: SG=1.12,WDENS=1000,GRAVITY=9.81,RE_CR=2000!,NU=9e-6
!specific gravity of liquid
!water density(kg/m^3)
PARAMETER PII=3.14159265
integer imud

type::MudSystemType
! temporary varibales for solving pressure jerks -- 1399-11-09
integer Pump1BlownCount, Pump2BlownCount, Pump3BlownCount

!integer Pump1BlownInTimeStep, Pump2BlownInTimeStep, Pump3BlownInTimeStep
!logical Pump1BlownStarted, Pump2BlownStarted, Pump3BlownStarted
!integer, parameter :: BlownThresholdInSecond = 5

real(8) total_add,total_injected
real(8) DeltaWellCap,WellCapOld,AnnCapOld,DeltaAnnCap

!========================================================================
! KICK VARIABLES
!========================================================================
REAL(8) KickDeltaVinAnnulus, KickVolumeinAnnulus
REAL(8) Kick_Forehead_X,Kick_RemainedVolume_in_LastSection,BackheadX,KickDv,KickDx,MinKickDv,Old_KickBackHead_X,Kick_Density
INTEGER NewInfluxElementCreated,Kick_Forehead_section,MudSection,Op_KickLoc,Ann_KickLoc,FirstSetKickMigration,Old_KickBackHead_Section
Integer iLoc,ChokeLine_KickLoc,KickNumber,NewInfluxNumber,SoundGasThroughChoke

LOGICAL DrillingMode
!real(8) HZ_ADD
integer Flow_timeCounter,MudSys_timeCounter,FluidFlowCounter
!========================================================================
! MUD CIRCULATION
!========================================================================
REAL(8), ALLOCATABLE:: Xstart_PipeSection(:),Xend_PipeSection(:),PipeSection_VolumeCapacity(:),Area_PipeSectionFt(:),OD_PipeSectionInch(:),ID_PipeSectionInch(:),Angle_PipeSection(:)
REAL(8), ALLOCATABLE:: Xstart_OpSection(:),Xend_OpSection(:),Area_OpSectionFt(:),OD_OpSectionInch(:),ID_OpSectionInch(:),OpSection_VolumeCapacity(:),GeoTypeOp(:),Angle_OpSection(:)
REAL(8), ALLOCATABLE:: TDXstart_MudElementArray(:) , TDXend_MudElementArray(:) , TDDensity_MudElementArray(:)

INTEGER, ALLOCATABLE:: GeoType(:)
real(8) StMudVolumeSum,St_MudSaved_Density,St_Saved_MudDischarged_Volume,St_Saved_MudDischarged_Volume_Final,MudVolume_InjectedToBH,MudVolume_InjectedFromAnn
real BitMudDensity
REAL(8) xx,NewVolume,UtubeEmptyVolume,NewDensity, MudCircVerticalDepth,TrueMinValue

REAL DirectionCoef
INTEGER isection,OpSection,SuctionMud,NoStringMudElements,ImudCount,NoCasingMudElements,NoHorizontalMudElements,AddedElementsToString
Integer TDNoHorizontalMudElements, TDNoStringMudElements, TDNoCasingMudElements
Integer istring,icasing,NoPipeSections,FirstMudSet
INTEGER NoBottomHoleMudElements,NoStringMudElementsForPlot,F_StringIntervalCounts_Old
INTEGER FirstSetUtube1,FirstSetUtube2,FirstAdded,NewPipeFilling,Hz_MudOrKick_Utube,UtubeFilling,totalLength
REAL(8) DeltaVolumeOp,DeltaVTemp,OldPosition,StringFlowRate,StringFlowRateFinal,AnnulusFlowRateFinal,TD_RemoveVolume_Remained,DeltaVolumePipe,DeltaVolumeAnnulusCapacity
REAL AnnulusFlowRate,ChokeLineFlowRate
Logical:: UtubePossibility,MudIsChanged,AddedPipe,UtubeMode1Activated,UtubeMode2Activated,WellisNOTFull,ChokeLineNOTFull
Logical:: ShoeLost,ShoeFractured,Kickexpansion_DueToMudLost,LostInTripOutIsDone
Integer UGBOSuccessionCounter, UGBOSuccessionCounterOld
REAL(8) Area_ChokeLineFt, ChokeLine_VolumeCapacity,TotalAddedVolume,LackageMudVolumeAfterFilling, LackageMudVolume, NewInflux_Density
real(8) DensityMixTol,Hz_Density_Utube,CuttingDensityMixTol,Op_Kick_Saved_Volume,Op_MudSaved_Density,Op_KickSaved_Density,Op_Saved_MudDischarged_Volume,OpMudVolumeSum,Op_NeededVolume_ToFill
real(8) Choke_Kick_Saved_Volume,Choke_Saved_MudDischarged_Volume,Choke_KickSaved_Density,Choke_MudSaved_Density,ChokeMudVolumeSum
integer Saved_Op_MudOrKick,Saved_Ann_MudOrKick,Saved_Choke_MudOrKick
real(8) Choke_Saved_MudDischarged_Volume_Final,Choke_Kick_Saved_Volume_Final
real(8) Qlost,FormationLostPressure,ShoeMudPressure,ShoeLostCoef, ShoeMudViscosity, ShoeMudDensity ,OldAnnulusCapacity
logical:: Ann_to_Choke_2mud
real(8) AnnMudVolumeSum,Ann_MudSaved_Density,Ann_KickSaved_Density,Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume,Ann_Saved_MudDischarged_Volume_Final, Ann_Kick_Saved_Volume_Final
type(DynamicDoubleArrayType) :: Hz_MudDischarged_Volume,Hz_Mud_Backhead_X,Hz_Mud_Forehead_X,Hz_Density,Hz_RemainedVolume_in_LastSection,Hz_EmptyVolume_inBackheadLocation, &
Op_MudDischarged_Volume,Op_Mud_Backhead_X,Op_Mud_Forehead_X,Op_Density,Op_RemainedVolume_in_LastSection,Op_EmptyVolume_inBackheadLocation

type(DynamicDoubleArrayType) :: ChokeLine_MudDischarged_Volume,ChokeLine_Mud_Backhead_X,ChokeLine_Mud_Forehead_X,ChokeLine_Density,ChokeLine_RemainedVolume_in_LastSection, &
ChokeLine_EmptyVolume_inBackheadLocation


type(DynamicDoubleArrayType) :: St_MudDischarged_Volume,St_Mud_Backhead_X,St_Mud_Forehead_X,St_Density,St_RemainedVolume_in_LastSection, &
St_EmptyVolume_inBackheadLocation,Ann_MudDischarged_Volume,Ann_Mud_Backhead_X,Ann_Mud_Forehead_X, &
Ann_Density,Ann_RemainedVolume_in_LastSection,Ann_EmptyVolume_inBackheadLocation
type(DynamicIntegerArrayType) :: St_Mud_Backhead_section,St_Mud_Forehead_section,Ann_Mud_Backhead_section,Ann_Mud_Forehead_section,MudGeoType,Hz_Mud_Backhead_section,Hz_Mud_Forehead_section, &
Op_Mud_Backhead_section,Op_Mud_Forehead_section,Hz_MudOrKick,St_MudOrKick,Ann_MudOrKick,Op_MudOrKick,ChokeLine_MudOrKick,MudTypeOp_MudElement,MudType_MudElement

type(DynamicIntegerArrayType) :: ChokeLine_Mud_Backhead_section,ChokeLine_Mud_Forehead_section,Ann_CuttingMud

type(DynamicDoubleArrayType) :: Xend_MudElement,Xstart_MudElement,Density_MudElement,PipeID_MudElement,PipeOD_MudElement,Angle_MudElement, &
Xstart_OpMudElement,Xend_OpMudElement,Density_OpMudElement,PipeID_OpMudElement,PipeOD_OpMudElement!,Angle_OpMudElement
type(DynamicDoubleArrayType) :: TVDstart_MudElement, TVDend_MudElement, TVDstart_OpMudElement, TVDend_OpMudElement
type(CFluid), allocatable :: StringMudElement(:), CasingMudElement(:)


real(8) PressureGauge75,PressureGauge76

!========================================================================
! MALFUNCTION VARIABLES
!========================================================================
INTEGER StandPipeGauge1Malf, StandPipeGauge2Malf, StandPipePressure_DataDisplayMalf,StandPipePressureChokeMalf,DrillPipePressureMalf
integer TripTankPressure_DataDisplayMalf,PitGainLossGaugeMalf,ReturnMudFlowGaugeMalf,MudTanksVolumeGaugeMalf

!========================================================================
! TRIP TANK VARIABLES
!========================================================================
logical condition32Final,condition33Final,condition34Final
REAL(8) TripTank_Vol,TripTank_Dens,ReturnToTrip_Q,ActiveToTrip_Q,TripTankPump_Q,ReturnToTrip_Dens,ActiveToTrip_Dens,ReturnToTrip_deltaV,ActiveToTrip_deltaV
REAL(8) MassFlowRate_ReturnToTrip,MassFlowRate_ActiveToTrip,TripTankPump_deltaV,MassFlowRate_TripTankPump,NetMassFlux_tripTank
REAL(8) TripTank_MinVol_Allowded,TripTank_MaxVol_Allowded

!!======================================================================
!! MUD VOLUME TOTALIZER
!!======================================================================
REAL(8) RefrencePitVolume_DrillWatch ! for DrillWatch
REAL(8) MudTank1_vol,MudTank2_vol,MudTank3_vol,MudTank4_vol
REAL(8) MVT_MinVol_Allowded,MVT_MaxVol_Allowded,MudTanksVolume
REAL(8) PitGainLossZero,MVTCoarse,MVTFine,RefrencePitVolume,PitGainLossZero_Old,MVTCoarseKnob_Old,MVTFineKnob_Old
REAL(8) ActiveTankDensity,TripTankDensityCalc,SuctionDensity_Old,AnnulusSuctionDensity_Old,StringDensity_Old,ChokeLineDensity_Old,ChokeManifoldDumpVolume
LOGICAL FirstSet_Time

!!======================================================================
!! MUD FLOW-FILL INDICATOR
!!======================================================================
REAL(8) TotalStrokes1MFFI,TotalStrokes2MFFI,TotalStrokesPump1,TotalStrokesPump2,GraphTotalStrokes
REAL(8) PedalMeter,ReturnFlowRate,ReturnFlowPercent,MFFI_MinPercent_Allowded,MFFI_MaxPercent_Allowded
REAL(8) TotalFillStrokes1MFFI,TotalFillStrokes2MFFI,TotalFilledStrokesBy1MFFI,TotalFilledStrokesBy2MFFI,TotalFilledStrokesBy1and2MFFI

!============================================================================
! MUD & ENVIRONMENT VARIABLES
!============================================================================
INTEGER NO_MudMinors,NO_PIPINGSMUDLINE
REAL(8) Pumps_Height,String_Height,STpipeGauge_Height,Pits_Height,ChokeManifold_Height,WellChokeExit_Height
REAL(8) STGauge_Pressure,String_Input_Pressure,Well_Output_Pressure,Pressure_BeforeChokes,Pressure_AfterChokes
REAL(8) OpenArea32,OpenArea33,OpenArea34,OpenArea35,deltaPchoke,WellOutletDensity,ChokeOutletDensity
REAL Q_flow32,Q_flow33,Q_flow34,Q_flow35
REAL(8) DeltaT_Mudline,ActiveTankVolume,ReserveTankVolume,CementTankVolumeCalc,ActiveTankSettled,ActiveTankFloorArea,TripTankFloorArea
REAL(8) TripTankVolumeCalc,BellNippleDensity,BellNippleVolume,MudBucketDensity,MudBucketVolume,BellNippleDumpVolume
REAL(8) ReserveTankDensity,CementTankDensityCalc,Mp1Density,Mp2Density,Mp3Density,PumpsDumpVolume
real PumpsDumpFlowRate
REAL(8) Density_Ch
real(8) Suction_Density_MudSystem,Suction_Density_PumpsToWell,CompressedMudDensity
Logical WellToPitsOpen,WellToChokeManifoldOpen,MudChecked,WellHeadIsOpen
logical Pump1OffFailure,Pump2OffFailure,Pump3OffFailure,ChokeLineGaugeToTanks,WellToChokeLineGauge
REAL,ALLOCATABLE:: MudMinors(:,:),AREA_MUDLINE(:),MINORDIAMETER_MUDLINE(:),NOTE_MUDLINE(:),AREAMINOR_MUDLINE(:),LF_MUDLINE(:),CV_MUDLINE(:)
REAL,ALLOCATABLE:: DIAM_MUDLINE_INCH(:),LENGT_MUDLINE(:),ROUGHNESS_MUDLINE(:),RELROUGH_MUDLINE(:),PIPINGS_MUDLINE(:,:)
end type MudSystemType
type(MudSystemType)::MudSystem
TYPE, PUBLIC :: MUD_TypeVars

REAL Q,nu,Mud_Density,Mud_SG
REAL minlosspa_MUDLINE,minloss_MUDLINE ! MINORS
REAL Re_MUDline,fric,fricloss,static_loss,total_loss ! MUDLINE

REAL Q,nu,Mud_Density,Mud_SG
REAL minlosspa_MUDLINE,minloss_MUDLINE ! MINORS
REAL Re_MUDline,fric,fricloss,static_loss,total_loss ! MUDLINE
END TYPE MUD_TypeVars

TYPE(MUD_TypeVars), DIMENSION(1:10) :: MUD
!MUD(1)%Q : -------------
@@ -187,23 +174,16 @@ logical Pump1OffFailure,Pump2OffFailure,Pump3OffFailure,ChokeLineGaugeToTanks,We
!MUD(7)%Q : WellToBellNipple
!MUD(8)%Q : BellNippleToWell-NonFullWell
!MUD(9)%Q : StandPipeManifoldToChokeManifold-Through ChokeLine
!MUD(10)%Q : PumpsToWell_KillLine
!MUD(10)%Q : PumpsToWell_KillLine

TYPE, PUBLIC :: MUD_TypeVars2D
!! MINORS
!REAL,ALLOCATABLE:: minlosspa_MUDLINE(:,:),minloss_MUDLINE(:,:)
!! MUDLINE
!REAL,ALLOCATABLE:: Re_MUDline(:,:),fric(:,:),fricloss(:,:)
END TYPE MUD_TypeVars2D
TYPE(MUD_TypeVars2D) :: MUDS
! TYPE, PUBLIC :: MUD_TypeVars2D
! !! MINORS
! !REAL,ALLOCATABLE:: minlosspa_MUDLINE(:,:),minloss_MUDLINE(:,:)
! !! MUDLINE
! !REAL,ALLOCATABLE:: Re_MUDline(:,:),fric(:,:),fricloss(:,:)
! END TYPE MUD_TypeVars2D
! TYPE(MUD_TypeVars2D) :: MUDS

END MODULE



+ 142
- 144
Equipments/MudSystem/Plot_Final_Mud_Elements.f90 Ver ficheiro

@@ -31,31 +31,29 @@ subroutine PlotFinalMudElements ! is called in subroutine CirculationCodeSel
if (ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then
write(*,*) 'well cap=' , sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) + sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
MudSystemDotDeltaWellCap= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) + sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - MudSystemDotWellCapOld
MudSystemDotWellCapOld= sum(MudSystemDotPipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystemDotNoPipeSections)) + sum(MudSystemDotOpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
write(*,*) 'cap_reset,DeltaWellCap=' , MudSystemDotDeltaWellCap
write(*,*) 'well cap=' , sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
MudSystem%DeltaWellCap= sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - MudSystem%WellCapOld
MudSystem%WellCapOld= sum(MudSystem%PipeSection_VolumeCapacity(F_StringIntervalCounts+1:MudSystem%NoPipeSections)) + sum(MudSystem%OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts))
write(*,*) 'cap_reset,DeltaWellCap=' , MudSystem%DeltaWellCap
endif

!========================ANNULUS END=================
if ((Ann_Mud_Forehead_X%Last() - BopStackSpecification%AboveAnnularHeight) > 0.8 .or. Ann_Density%Last()==0.0) then ! for Line (BellNippleToWell-NonFullWell)
MudSystemDotWellisNOTFull= .true.
if ((MudSystem%Ann_Mud_Forehead_X%Last() - BopStackSpecification%AboveAnnularHeight) > 0.8 .or. MudSystem%Ann_Density%Last()==0.0) then ! for Line (BellNippleToWell-NonFullWell)
MudSystem%WellisNOTFull= .true.
else
MudSystemDotWellisNOTFull= .false.
MudSystem%WellisNOTFull= .false.
endif

!WRITE(*,*) 'Ann_Mud_Forehead_X%Last() , KillHeight', Ann_Mud_Forehead_X%Last() , KillHeight
if ((Ann_Mud_Forehead_X%Last() - BopStackSpecification%KillHeight)>0.8 .or. Ann_Density%Last()==0.0) then ! for Line j4 , WellToChokeManifold(Through 26)
MudSystemDotChokeLineNOTFull= .true.
if ((MudSystem%Ann_Mud_Forehead_X%Last() - BopStackSpecification%KillHeight)>0.8 .or. MudSystem%Ann_Density%Last()==0.0) then ! for Line j4 , WellToChokeManifold(Through 26)
MudSystem%ChokeLineNOTFull= .true.
else
MudSystemDotChokeLineNOTFull= .false.
MudSystem%ChokeLineNOTFull= .false.
endif



!=========================================================
jmud= 1
@@ -64,33 +62,33 @@ endif

call Xend_MudElement%Empty()
call TVDend_MudElement%Empty()
call Density_MudElement%Empty()
call MudGeoType%Empty()
call PipeID_MudElement%Empty()
call PipeOD_MudElement%Empty()
call MudSystem%Xend_MudElement%Empty()
call MudSystem%TVDend_MudElement%Empty()
call MudSystem%Density_MudElement%Empty()
call MudSystem%MudGeoType%Empty()
call MudSystem%PipeID_MudElement%Empty()
call MudSystem%PipeOD_MudElement%Empty()
!call Angle_MudElement%Empty()
call MudType_MudElement%Empty()
call MudSystem%MudType_MudElement%Empty()

DO WHILE(jmud <= MudSystemDotHz_Mud_Forehead_X%Length() .and. jsection<=1)
DO WHILE(jmud <= MudSystem%Hz_Mud_Forehead_X%Length() .and. jsection<=1)
jelement= jelement+1
TrueMinValue= min(MudSystemDotHz_Mud_Forehead_X%Array(jmud), MudSystemDotXend_PipeSection(jsection))
MudSystem%TrueMinValue= min(MudSystem%Hz_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(jsection))

call Xend_MudElement%Add(TrueMinValue)
call TVD_Calculator(TrueMinValue,MudSystemDotMudCircVerticalDepth)
call TVDend_MudElement%Add(MudSystemDotMudCircVerticalDepth)
call Density_MudElement%Add(MudSystemDotHz_Density%Array(jmud))
call PipeID_MudElement%Add(MudSystemDotID_PipeSectionInch(jsection))
call PipeOD_MudElement%Add(MudSystemDotOD_PipeSectionInch(jsection))
call MudSystem%Xend_MudElement%Add(MudSystem%TrueMinValue)
call TVD_Calculator(MudSystem%TrueMinValue,MudSystem%MudCircVerticalDepth)
call MudSystem%TVDend_MudElement%Add(MudSystem%MudCircVerticalDepth)
call MudSystem%Density_MudElement%Add(MudSystem%Hz_Density%Array(jmud))
call MudSystem%PipeID_MudElement%Add(MudSystem%ID_PipeSectionInch(jsection))
call MudSystem%PipeOD_MudElement%Add(MudSystem%OD_PipeSectionInch(jsection))
!call Angle_MudElement%Add(Angle_PipeSection(jsection))
call MudType_MudElement%Add(Hz_MudOrKick%Array(jmud))
call MudSystem%MudType_MudElement%Add(MudSystem%Hz_MudOrKick%Array(jmud))
if (Xend_MudElement%Array(jelement)== MudSystemDotHz_Mud_Forehead_X%Array(jmud)) then
if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%Hz_Mud_Forehead_X%Array(jmud)) then
jmud= jmud+1
else
jsection= jsection+1
@@ -98,7 +96,7 @@ endif
ENDDO
MudSystemDotNoHorizontalMudElements= jelement
MudSystem%NoHorizontalMudElements= jelement

@@ -106,22 +104,22 @@ endif
jmud= 1
jsection= 2
DO WHILE(jmud <= MudSystemDotSt_Mud_Forehead_X%Length() .and. jsection<=F_StringIntervalCounts)
DO WHILE(jmud <= MudSystem%St_Mud_Forehead_X%Length() .and. jsection<=F_StringIntervalCounts)
jelement= jelement+1
TrueMinValue= min(MudSystemDotSt_Mud_Forehead_X%Array(jmud), MudSystemDotXend_PipeSection(jsection))
MudSystem%TrueMinValue= min(MudSystem%St_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(jsection))

call Xend_MudElement%Add(TrueMinValue)
call TVD_Calculator(TrueMinValue,MudSystemDotMudCircVerticalDepth)
call TVDend_MudElement%Add(MudSystemDotMudCircVerticalDepth)
call Density_MudElement%Add(St_Density%Array(jmud))
call PipeID_MudElement%Add(MudSystemDotID_PipeSectionInch(jsection))
call PipeOD_MudElement%Add(MudSystemDotOD_PipeSectionInch(jsection))
call MudSystem%Xend_MudElement%Add(MudSystem%TrueMinValue)
call TVD_Calculator(MudSystem%TrueMinValue,MudSystem%MudCircVerticalDepth)
call MudSystem%TVDend_MudElement%Add(MudSystem%MudCircVerticalDepth)
call MudSystem%Density_MudElement%Add(MudSystem%St_Density%Array(jmud))
call MudSystem%PipeID_MudElement%Add(MudSystem%ID_PipeSectionInch(jsection))
call MudSystem%PipeOD_MudElement%Add(MudSystem%OD_PipeSectionInch(jsection))
!call Angle_MudElement%Add(Angle_PipeSection(jsection))
call MudType_MudElement%Add(St_MudOrKick%Array(jmud))
call MudSystem%MudType_MudElement%Add(MudSystem%St_MudOrKick%Array(jmud))
if (Xend_MudElement%Array(jelement)== MudSystemDotSt_Mud_Forehead_X%Array(jmud)) then
if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%St_Mud_Forehead_X%Array(jmud)) then
jmud= jmud+1
else
jsection= jsection+1
@@ -129,7 +127,7 @@ endif
ENDDO

MudSystemDotNoStringMudElements= jelement- MudSystemDotNoHorizontalMudElements
MudSystem%NoStringMudElements= jelement- MudSystem%NoHorizontalMudElements

@@ -137,22 +135,22 @@ endif
jmud= 1
jsection= F_StringIntervalCounts+1
DO WHILE(jmud<= Ann_Mud_Forehead_X%Length() .and. jsection<=MudSystemDotNoPipeSections)
DO WHILE(jmud<= MudSystem%Ann_Mud_Forehead_X%Length() .and. jsection<=MudSystem%NoPipeSections)
jelement= jelement+1
TrueMinValue= max(Ann_Mud_Forehead_X%Array(jmud), MudSystemDotXend_PipeSection(jsection))
MudSystem%TrueMinValue= max(MudSystem%Ann_Mud_Forehead_X%Array(jmud), MudSystem%Xend_PipeSection(jsection))

call Xend_MudElement%Add(TrueMinValue)
call TVD_Calculator(TrueMinValue,MudSystemDotMudCircVerticalDepth)
call TVDend_MudElement%Add(MudSystemDotMudCircVerticalDepth)
call Density_MudElement%Add(Ann_Density%Array(jmud))
call PipeID_MudElement%Add(MudSystemDotID_PipeSectionInch(jsection))
call PipeOD_MudElement%Add(MudSystemDotOD_PipeSectionInch(jsection))
call MudSystem%Xend_MudElement%Add(MudSystem%TrueMinValue)
call TVD_Calculator(MudSystem%TrueMinValue,MudSystem%MudCircVerticalDepth)
call MudSystem%TVDend_MudElement%Add(MudSystem%MudCircVerticalDepth)
call MudSystem%Density_MudElement%Add(MudSystem%Ann_Density%Array(jmud))
call MudSystem%PipeID_MudElement%Add(MudSystem%ID_PipeSectionInch(jsection))
call MudSystem%PipeOD_MudElement%Add(MudSystem%OD_PipeSectionInch(jsection))
!call Angle_MudElement%Add(Angle_PipeSection(jsection))
call MudType_MudElement%Add(Ann_MudOrKick%Array(jmud))
call MudSystem%MudType_MudElement%Add(MudSystem%Ann_MudOrKick%Array(jmud))
if (Xend_MudElement%Array(jelement)== Ann_Mud_Forehead_X%Array(jmud)) then
if (MudSystem%Xend_MudElement%Array(jelement)== MudSystem%Ann_Mud_Forehead_X%Array(jmud)) then
jmud= jmud+1
else
jsection= jsection+1
@@ -160,41 +158,41 @@ endif
ENDDO
do i= 2, Xend_MudElement%Length()
if ( i== MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements+1) then
call Xstart_MudElement%Add (Ann_Mud_Backhead_X%Array(1)) ! start of annulus
call TVD_Calculator(Ann_Mud_Backhead_X%Array(1),MudSystemDotMudCircVerticalDepth)
call TVDstart_MudElement%Add(MudSystemDotMudCircVerticalDepth)
elseif ( i== MudSystemDotNoHorizontalMudElements+1 ) then
call Xstart_MudElement%Add (MudSystemDotSt_Mud_Backhead_X%Array(1)) ! start of stirng
call TVD_Calculator(MudSystemDotSt_Mud_Backhead_X%Array(1),MudSystemDotMudCircVerticalDepth)
call TVDstart_MudElement%Add(MudSystemDotMudCircVerticalDepth)
do i= 2, MudSystem%Xend_MudElement%Length()
if ( i== MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements+1) then
call MudSystem%Xstart_MudElement%Add (MudSystem%Ann_Mud_Backhead_X%Array(1)) ! start of annulus
call TVD_Calculator(MudSystem%Ann_Mud_Backhead_X%Array(1),MudSystem%MudCircVerticalDepth)
call MudSystem%TVDstart_MudElement%Add(MudSystem%MudCircVerticalDepth)
elseif ( i== MudSystem%NoHorizontalMudElements+1 ) then
call MudSystem%Xstart_MudElement%Add (MudSystem%St_Mud_Backhead_X%Array(1)) ! start of stirng
call TVD_Calculator(MudSystem%St_Mud_Backhead_X%Array(1),MudSystem%MudCircVerticalDepth)
call MudSystem%TVDstart_MudElement%Add(MudSystem%MudCircVerticalDepth)
else
call Xstart_MudElement%Add(Xend_MudElement%Array(i-1)) ! normal calculation
call TVDstart_MudElement%Add(TVDend_MudElement%Array(i-1)) ! normal calculation
call MudSystem%Xstart_MudElement%Add(MudSystem%Xend_MudElement%Array(i-1)) ! normal calculation
call MudSystem%TVDstart_MudElement%Add(MudSystem%TVDend_MudElement%Array(i-1)) ! normal calculation
endif
enddo

MudSystemDotNoCasingMudElements = jelement- MudSystemDotNoStringMudElements- MudSystemDotNoHorizontalMudElements
MudSystem%NoCasingMudElements = jelement- MudSystem%NoStringMudElements- MudSystem%NoHorizontalMudElements
!=========================For Torque and Drag========================
if (allocated(MudSystemDotTDXstart_MudElementArray)) deallocate(MudSystemDotTDXstart_MudElementArray)
allocate(MudSystemDotTDXstart_MudElementArray(MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements+MudSystemDotNoCasingMudElements))
if (allocated(MudSystemDotTDXend_MudElementArray)) deallocate(MudSystemDotTDXend_MudElementArray)
allocate(MudSystemDotTDXend_MudElementArray(MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements+MudSystemDotNoCasingMudElements))
if (allocated(MudSystemDotTDDensity_MudElementArray)) deallocate(MudSystemDotTDDensity_MudElementArray)
allocate(MudSystemDotTDDensity_MudElementArray(MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements+MudSystemDotNoCasingMudElements))
if (allocated(MudSystem%TDXstart_MudElementArray)) deallocate(MudSystem%TDXstart_MudElementArray)
allocate(MudSystem%TDXstart_MudElementArray(MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements+MudSystem%NoCasingMudElements))
if (allocated(MudSystem%TDXend_MudElementArray)) deallocate(MudSystem%TDXend_MudElementArray)
allocate(MudSystem%TDXend_MudElementArray(MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements+MudSystem%NoCasingMudElements))
if (allocated(MudSystem%TDDensity_MudElementArray)) deallocate(MudSystem%TDDensity_MudElementArray)
allocate(MudSystem%TDDensity_MudElementArray(MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements+MudSystem%NoCasingMudElements))
MudSystemDotTDNoHorizontalMudElements= MudSystemDotNoHorizontalMudElements
MudSystemDotTDNoStringMudElements= MudSystemDotNoStringMudElements
MudSystemDotTDNoCasingMudElements= MudSystemDotNoCasingMudElements
MudSystem%TDNoHorizontalMudElements= MudSystem%NoHorizontalMudElements
MudSystem%TDNoStringMudElements= MudSystem%NoStringMudElements
MudSystem%TDNoCasingMudElements= MudSystem%NoCasingMudElements

MudSystemDotTDXstart_MudElementArray(:) = Xstart_MudElement%Array(:)
MudSystemDotTDXend_MudElementArray(:) = Xend_MudElement%Array(:)
MudSystemDotTDDensity_MudElementArray(:) = Density_MudElement%Array(:)
MudSystem%TDXstart_MudElementArray(:) = MudSystem%Xstart_MudElement%Array(:)
MudSystem%TDXend_MudElementArray(:) = MudSystem%Xend_MudElement%Array(:)
MudSystem%TDDensity_MudElementArray(:) = MudSystem%Density_MudElement%Array(:)
!=====================================================================
@@ -212,31 +210,31 @@ endif
jopelement= 0 ! number of final mud elements

call Xend_OpMudElement%Empty()
call TVDend_OpMudElement%Empty()
call Density_OpMudElement%Empty()
call PipeID_OpMudElement%Empty()
call PipeOD_OpMudElement%Empty()
call MudSystem%Xend_OpMudElement%Empty()
call MudSystem%TVDend_OpMudElement%Empty()
call MudSystem%Density_OpMudElement%Empty()
call MudSystem%PipeID_OpMudElement%Empty()
call MudSystem%PipeOD_OpMudElement%Empty()
!call Angle_OpMudElement%Empty()
call MudTypeOp_MudElement%Empty()
call MudSystem%MudTypeOp_MudElement%Empty()

DO WHILE(jopmud<= MudSystemDotOp_Mud_Forehead_X%Length() .and. jopsection<=F_BottomHoleIntervalCounts)
DO WHILE(jopmud<= MudSystem%Op_Mud_Forehead_X%Length() .and. jopsection<=F_BottomHoleIntervalCounts)
jopelement= jopelement+1
TrueMinValue= max(MudSystemDotOp_Mud_Forehead_X%Array(jopmud), MudSystemDotXend_OpSection(jopsection))
call Xend_OpMudElement%Add(TrueMinValue)
call TVD_Calculator(TrueMinValue,MudSystemDotMudCircVerticalDepth)
call TVDend_OpMudElement%Add(MudSystemDotMudCircVerticalDepth)
call Density_OpMudElement%Add(MudSystemDotOp_Density%Array(jopmud))
call PipeID_OpMudElement%Add(MudSystemDotID_OpSectionInch(jopsection))
call PipeOD_OpMudElement%Add(MudSystemDotOD_OpSectionInch(jopsection))
MudSystem%TrueMinValue= max(MudSystem%Op_Mud_Forehead_X%Array(jopmud), MudSystem%Xend_OpSection(jopsection))
call MudSystem%Xend_OpMudElement%Add(MudSystem%TrueMinValue)
call TVD_Calculator(MudSystem%TrueMinValue,MudSystem%MudCircVerticalDepth)
call MudSystem%TVDend_OpMudElement%Add(MudSystem%MudCircVerticalDepth)
call MudSystem%Density_OpMudElement%Add(MudSystem%Op_Density%Array(jopmud))
call MudSystem%PipeID_OpMudElement%Add(MudSystem%ID_OpSectionInch(jopsection))
call MudSystem%PipeOD_OpMudElement%Add(MudSystem%OD_OpSectionInch(jopsection))
!call Angle_MudElement%Add(Angle_PipeSection(jopsection))
call MudTypeOp_MudElement%Add(Op_MudOrKick%Array(jopmud))
call MudSystem%MudTypeOp_MudElement%Add(MudSystem%Op_MudOrKick%Array(jopmud))
if (Xend_OpMudElement%Array(jopelement)== MudSystemDotOp_Mud_Forehead_X%Array(jopmud)) then
if (MudSystem%Xend_OpMudElement%Array(jopelement)== MudSystem%Op_Mud_Forehead_X%Array(jopmud)) then
jopmud= jopmud+1
else
jopsection= jopsection+1
@@ -244,34 +242,34 @@ endif
ENDDO
do i= 2, Xend_OpMudElement%Length()
call Xstart_OpMudElement%Add(Xend_OpMudElement%Array(i-1))
call TVDstart_OpMudElement%Add(TVDend_OpMudElement%Array(i-1))
do i= 2, MudSystem%Xend_OpMudElement%Length()
call MudSystem%Xstart_OpMudElement%Add(MudSystem%Xend_OpMudElement%Array(i-1))
call MudSystem%TVDstart_OpMudElement%Add(MudSystem%TVDend_OpMudElement%Array(i-1))
enddo

MudSystemDotNoBottomHoleMudElements = jopelement
MudSystem%NoBottomHoleMudElements = jopelement
!================================================================
if(allocated(StringMudElement)) deallocate(StringMudElement)
allocate(StringMudElement(MudSystemDotNoStringMudElements))
if(allocated(MudSystem%StringMudElement)) deallocate(MudSystem%StringMudElement)
allocate(MudSystem%StringMudElement(MudSystem%NoStringMudElements))
if(allocated(CasingMudElement)) deallocate(CasingMudElement)
allocate(CasingMudElement(MudSystemDotNoCasingMudElements+MudSystemDotNoBottomHoleMudElements))
if(allocated(MudSystem%CasingMudElement)) deallocate(MudSystem%CasingMudElement)
allocate(MudSystem%CasingMudElement(MudSystem%NoCasingMudElements+MudSystem%NoBottomHoleMudElements))
MudSystemDotistring=0
MudSystemDoticasing=0
MudSystem%istring=0
MudSystem%icasing=0
MudSystemDotBitMudDensity= Density_MudElement%Array(MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements) ! (for ROP module)
MudSystem%BitMudDensity= MudSystem%Density_MudElement%Array(MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements) ! (for ROP module)
!================================================================
!============================ UTUBE =============================
!IF (UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadIsOpen) THEN
IF (MudSystemDotUtubePossibility== .true. .and. TD_FluidStringConnectionMode==0 .and. WellHeadIsOpen .AND. NoGasPocket == 0) THEN
IF (MudSystem%UtubePossibility== .true. .and. TD_FluidStringConnectionMode==0 .and. MudSystem%WellHeadIsOpen .AND. NoGasPocket == 0) THEN
CALL WellPressureDataTransfer
!WRITE (*,*) ' U-Tube Done 1'
CALL Utube
@@ -294,17 +292,17 @@ endif
!enddo
IF (ANY(IEEE_Is_NaN(MudSystemDotOp_MudDischarged_Volume%Array(:))) .OR. ANY(MudSystemDotOp_MudDischarged_Volume%Array(:) <= 0.0)) THEN
do i = 1 , Op_MudOrKick%Length()
write(*,555) i,'Op_Volume(i), type=' ,MudSystemDotOp_MudDischarged_Volume%Array(i) , Op_MudOrKick%Array(i) , MudSystemDotOp_Density%Array(i)
IF (ANY(IEEE_Is_NaN(MudSystem%Op_MudDischarged_Volume%Array(:))) .OR. ANY(MudSystem%Op_MudDischarged_Volume%Array(:) <= 0.0)) THEN
do i = 1 , MudSystem%Op_MudOrKick%Length()
write(*,555) i,'Op_Volume(i), type=' ,MudSystem%Op_MudDischarged_Volume%Array(i) , MudSystem%Op_MudOrKick%Array(i) , MudSystem%Op_Density%Array(i)
end do
call ErrorStop('NaN in Op Volume-Plot or Op Volume <=0')
END IF
IF (ANY(IEEE_Is_NaN(MudSystemDotAnn_MudDischarged_Volume%Array(:))) .OR. ANY(MudSystemDotAnn_MudDischarged_Volume%Array(:) <= 0.0)) THEN
do i = 1 , Ann_MudOrKick%Length()
write(*,555) i,'Ann_Volume(i), type=' ,MudSystemDotAnn_MudDischarged_Volume%Array(i) , Ann_MudOrKick%Array(i) , Ann_Density%Array(i)
IF (ANY(IEEE_Is_NaN(MudSystem%Ann_MudDischarged_Volume%Array(:))) .OR. ANY(MudSystem%Ann_MudDischarged_Volume%Array(:) <= 0.0)) THEN
do i = 1 , MudSystem%Ann_MudOrKick%Length()
write(*,555) i,'Ann_Volume(i), type=' ,MudSystem%Ann_MudDischarged_Volume%Array(i) , MudSystem%Ann_MudOrKick%Array(i) , MudSystem%Ann_Density%Array(i)
end do
call ErrorStop('NaN in Ann Volume-Plot or Ann Volume <=0')
END IF
@@ -318,74 +316,74 @@ endif
555 FORMAT(I3,5X,A42,(f12.5),5X,I3,5X,(f12.5))
MudSystemDotNoStringMudElementsForPlot= MudSystemDotNoStringMudElements
MudSystem%NoStringMudElementsForPlot= MudSystem%NoStringMudElements
! 1-Horizontal Mud Elements are not shown
!write(*,333) 'Horiz:', 1,'Xstart\=', Xstart_MudElement%Array(1), 'Xend=' , Xend_MudElement%Array(1), 'Density=' , Density_MudElement%Array(1), 'MudType=' , MudType_MudElement%Array(1)

do i=MudSystemDotNoHorizontalMudElements+1, MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements ! 2-string elements
if (Xend_MudElement%Array(i) <= 0.0) then
MudSystemDotNoStringMudElementsForPlot= MudSystemDotNoStringMudElementsForPlot-1
do i=MudSystem%NoHorizontalMudElements+1, MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements ! 2-string elements
if (MudSystem%Xend_MudElement%Array(i) <= 0.0) then
MudSystem%NoStringMudElementsForPlot= MudSystem%NoStringMudElementsForPlot-1
cycle
endif
MudSystemDotistring= MudSystemDotistring+1
StringMudElement(MudSystemDotistring)%StartMd = Xstart_MudElement%Array(i)
StringMudElement(MudSystemDotistring)%EndMd = Xend_MudElement%Array(i)
MudSystem%istring= MudSystem%istring+1
MudSystem%StringMudElement(MudSystem%istring)%StartMd = MudSystem%Xstart_MudElement%Array(i)
MudSystem%StringMudElement(MudSystem%istring)%EndMd = MudSystem%Xend_MudElement%Array(i)
!StringMudElement(istring)%Id = PipeID_MudElement%Array(i)
!StringMudElement(istring)%Od = PipeOD_MudElement%Array(i)
StringMudElement(MudSystemDotistring)%Density = Density_MudElement%Array(i)
MudSystem%StringMudElement(MudSystem%istring)%Density = MudSystem%Density_MudElement%Array(i)

if (MudType_MudElement%Array(i) == 104) then
MudType_MudElement%Array(i)= 4 ! air
elseif (MudType_MudElement%Array(i) > 0 .and. MudType_MudElement%Array(i) < 100) then ! all kicks
MudType_MudElement%Array(i)= 1 ! gas kick
if (MudSystem%MudType_MudElement%Array(i) == 104) then
MudSystem%MudType_MudElement%Array(i)= 4 ! air
elseif (MudSystem%MudType_MudElement%Array(i) > 0 .and. MudSystem%MudType_MudElement%Array(i) < 100) then ! all kicks
MudSystem%MudType_MudElement%Array(i)= 1 ! gas kick
endif

StringMudElement(MudSystemDotistring)%MudType = MudType_MudElement%Array(i)
MudSystem%StringMudElement(MudSystem%istring)%MudType = MudSystem%MudType_MudElement%Array(i)
!write(*,333) 'STRING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i)
enddo

do i=Xend_MudElement%Length(), MudSystemDotNoHorizontalMudElements+MudSystemDotNoStringMudElements+1 , -1 ! 3-casing elements
MudSystemDoticasing= MudSystemDoticasing+1
CasingMudElement(MudSystemDoticasing)%StartMd = Xend_MudElement%Array(i)
CasingMudElement(MudSystemDoticasing)%EndMd = Xstart_MudElement%Array(i)
do i=MudSystem%Xend_MudElement%Length(), MudSystem%NoHorizontalMudElements+MudSystem%NoStringMudElements+1 , -1 ! 3-casing elements
MudSystem%icasing= MudSystem%icasing+1
MudSystem%CasingMudElement(MudSystem%icasing)%StartMd = MudSystem%Xend_MudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%EndMd = MudSystem%Xstart_MudElement%Array(i)
!CasingMudElement(icasing)%Id = PipeID_MudElement%Array(i)
!CasingMudElement(icasing)%Od = PipeOD_MudElement%Array(i)
!write(*,333) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i)
!call Log_1(temp1)
!write(*,444) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i)
CasingMudElement(MudSystemDoticasing)%Density = Density_MudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%Density = MudSystem%Density_MudElement%Array(i)
if (MudType_MudElement%Array(i) == 104) then
MudType_MudElement%Array(i)= 4 ! air
elseif (MudType_MudElement%Array(i) > 0 .and. MudType_MudElement%Array(i) < 100) then
MudType_MudElement%Array(i)= 1 ! gas kick
if (MudSystem%MudType_MudElement%Array(i) == 104) then
MudSystem%MudType_MudElement%Array(i)= 4 ! air
elseif (MudSystem%MudType_MudElement%Array(i) > 0 .and. MudSystem%MudType_MudElement%Array(i) < 100) then
MudSystem%MudType_MudElement%Array(i)= 1 ! gas kick
endif
CasingMudElement(MudSystemDoticasing)%MudType = MudType_MudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%MudType = MudSystem%MudType_MudElement%Array(i)
enddo
do i= MudSystemDotNoBottomHoleMudElements, 1 , -1 ! 4-open hole elements
MudSystemDoticasing= MudSystemDoticasing+1
CasingMudElement(MudSystemDoticasing)%StartMd = Xend_OpMudElement%Array(i)
CasingMudElement(MudSystemDoticasing)%EndMd = Xstart_OpMudElement%Array(i)
do i= MudSystem%NoBottomHoleMudElements, 1 , -1 ! 4-open hole elements
MudSystem%icasing= MudSystem%icasing+1
MudSystem%CasingMudElement(MudSystem%icasing)%StartMd = MudSystem%Xend_OpMudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%EndMd = MudSystem%Xstart_OpMudElement%Array(i)
!CasingMudElement(icasing)%Id = PipeID_OpMudElement%Array(i)
!CasingMudElement(icasing)%Od = PipeOD_OpMudElement%Array(i)
!write(*,333) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'Density=' , Density_OpMudElement%Array(i), 'MudType=' , MudTypeOp_MudElement%Array(i)
!call Log_1(temp2)
!write(*,444) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i)
CasingMudElement(MudSystemDoticasing)%Density = Density_OpMudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%Density = MudSystem%Density_OpMudElement%Array(i)
if (MudTypeOp_MudElement%Array(i) == 104) then
MudTypeOp_MudElement%Array(i)= 4 ! air
elseif (MudTypeOp_MudElement%Array(i) > 0 .and. MudTypeOp_MudElement%Array(i) < 100) then
MudTypeOp_MudElement%Array(i)= 1 ! gas kick
if (MudSystem%MudTypeOp_MudElement%Array(i) == 104) then
MudSystem%MudTypeOp_MudElement%Array(i)= 4 ! air
elseif (MudSystem%MudTypeOp_MudElement%Array(i) > 0 .and. MudSystem%MudTypeOp_MudElement%Array(i) < 100) then
MudSystem%MudTypeOp_MudElement%Array(i)= 1 ! gas kick
endif
CasingMudElement(MudSystemDoticasing)%MudType = MudTypeOp_MudElement%Array(i)
MudSystem%CasingMudElement(MudSystem%icasing)%MudType = MudSystem%MudTypeOp_MudElement%Array(i)
enddo

@@ -398,8 +396,8 @@ endif
! shomare gozari be tartib HZ mud, ST mud, Casing
! shomare gzari OpenHole jodagane ast az 1
call SetStringFluids(MudSystemDotNoStringMudElementsForPlot, StringMudElement) !for data display in string
call SetAnnalusFluids(MudSystemDotNoCasingMudElements+MudSystemDotNoBottomHoleMudElements, CasingMudElement) !for data display in casing
call SetStringFluids(MudSystem%NoStringMudElementsForPlot, MudSystem%StringMudElement) !for data display in string
call SetAnnalusFluids(MudSystem%NoCasingMudElements+MudSystem%NoBottomHoleMudElements, MudSystem%CasingMudElement) !for data display in casing


!===========================================================================================================================


+ 543
- 543
Equipments/MudSystem/Pump_and_Trip_In.f90
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 483
- 486
Equipments/MudSystem/Trip_Out_andPump.f90
A apresentação das diferenças no ficheiro foi suprimida por ser demasiado grande
Ver ficheiro


+ 175
- 175
Equipments/MudSystem/Utube1_and_Trip_In.f90 Ver ficheiro

@@ -16,22 +16,22 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect
write(*,*) 'Utube1 code'
!===========================================================WELL============================================================
!===========================================================WELL============================================================
MudSystemDotUtubeMode1Activated= .true.
MudSystem%UtubeMode1Activated= .true.
!write(*,*) 'QUTubeInput=' , QUTubeInput
!Qinput=5000.
MudSystemDotStringFlowRate= QUTubeInput ! (gpm)
MudSystemDotAnnulusFlowRate= QUTubeInput
MudSystemDotStringFlowRateFinal= MudSystemDotStringFlowRate
MudSystemDotAnnulusFlowRateFinal= MudSystemDotAnnulusFlowRate
MudSystem%StringFlowRate= QUTubeInput ! (gpm)
MudSystem%AnnulusFlowRate= QUTubeInput
MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate
MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate
!===========================================
if (MudSystemDotFirstSetUtube1==0) then
if (MudSystem%FirstSetUtube1==0) then
! call St_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval(1:F_StringIntervalCounts)%Volume))) !startup initial
! call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
! call St_Mud_Backhead_section%AddToFirst (1)
! call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts))
! call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
! call St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
! call MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
!
@@ -46,10 +46,10 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect
!Hz_Density%Array(:)= 0.0 !commented
!Hz_MudOrKick%Array(:)= 104 !commented
MudSystemDotHz_Density_Utube= 0.0
MudSystemDotHz_MudOrKick_Utube= 104
MudSystem%Hz_Density_Utube= 0.0
MudSystem%Hz_MudOrKick_Utube= 104
MudSystemDotFirstSetUtube1= 1
MudSystem%FirstSetUtube1= 1
endif

@@ -77,7 +77,7 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect

!commented
! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.)*DeltaT_Mudline) !(gal)
! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.)*DeltaT_Mudline) !(gal)
!
!imud=0
! do while (imud < Hz_Mud_Forehead_X%Length())
@@ -152,80 +152,80 @@ SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect
!========================Horizontal PIPE END=================
!========================STRING ENTRANCE=================
!write(*,*) 'a) St_Density%Length()=' , St_Density%Length()
!write(*,*) 'a) MudSystem%St_Density%Length()=' , MudSystem%St_Density%Length()
if (ABS(St_Density%First() - MudSystemDotHz_Density_Utube) >= MudSystemDotDensityMixTol) then ! new mud is pumped
call St_Density%AddToFirst (MudSystemDotHz_Density_Utube)
call MudSystemDotSt_MudDischarged_Volume%AddToFirst (0.0d0)
call MudSystemDotSt_Mud_Forehead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
call St_Mud_Forehead_section%AddToFirst (2)
call MudSystemDotSt_Mud_Backhead_X%AddToFirst (MudSystemDotXstart_PipeSection(2))
call St_Mud_Backhead_section%AddToFirst (2)
call MudSystemDotSt_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
call St_MudOrKick%AddToFirst (MudSystemDotHz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104
if (ABS(MudSystem%St_Density%First() - MudSystem%Hz_Density_Utube) >= MudSystem%DensityMixTol) then ! new mud is pumped
call MudSystem%St_Density%AddToFirst (MudSystem%Hz_Density_Utube)
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 (MudSystem%Hz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104
!StringDensity_Old= Hz_Density_Utube
endif
!write(*,*) 'b) St_Density%Length()=' , St_Density%Length()
!write(*,*) 'b) St_Density%Array(1)=' , St_Density%Array(1)
!write(*,*) 'b) MudSystem%St_Density%Length()=' , MudSystem%St_Density%Length()
!write(*,*) 'b) MudSystem%St_Density%Array(1)=' , MudSystem%St_Density%Array(1)
!write(*,*) 'b) St_MudOrKick%Array(1)=' , St_MudOrKick%Array(1)

!========================STRING=================
!WRITE (*,*) 'Utube1 StringFlowRate', StringFlowRate
MudSystemDotSt_MudDischarged_Volume%Array(1)= MudSystemDotSt_MudDischarged_Volume%Array(1)+ ((MudSystemDotStringFlowRate/60.d0)*DeltaT_Mudline) !(gal)
!WRITE (*,*) 'Utube1 MudSystem%StringFlowRate', MudSystem%StringFlowRate
MudSystem%St_MudDischarged_Volume%Array(1)= MudSystem%St_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.d0)*MudSystem%DeltaT_Mudline) !(gal)
MudSystemDotimud=0
do while (MudSystemDotimud < MudSystemDotSt_Mud_Forehead_X%Length())
MudSystemDotimud = MudSystemDotimud + 1
imud=0
do while (imud < MudSystem%St_Mud_Forehead_X%Length())
imud = imud + 1
if (MudSystemDotimud> 1) then
MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud-1)
St_Mud_Backhead_section%Array(MudSystemDotimud)= St_Mud_Forehead_section%Array(MudSystemDotimud-1)
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
MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud)))
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
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(St_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud))* &
MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
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 ( MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
St_Mud_Forehead_section%Array(MudSystemDotimud)= St_Mud_Backhead_section%Array(MudSystemDotimud)
MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud))
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
MudSystemDotisection= St_Mud_Backhead_section%Array(MudSystemDotimud)+1
MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection > F_StringIntervalCounts) then ! last pipe section(string exit) F_StringIntervalCounts includes Horizontal line
MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(F_StringIntervalCounts)
St_Mud_Forehead_section%Array(MudSystemDotimud)= F_StringIntervalCounts
if (MudSystem%isection > F_StringIntervalCounts) then ! last pipe section(string exit) F_StringIntervalCounts includes Horizontal line
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_StringIntervalCounts)
MudSystem%St_Mud_Forehead_section%Array(imud)= F_StringIntervalCounts
if (MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string
call RemoveStringMudArrays(MudSystemDotimud)
if (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
call RemoveStringMudArrays(imud)
endif
exit
endif
MudSystemDotxx= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
St_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection)
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
MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection+ 1
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
@@ -259,60 +259,60 @@ MudSystemDotimud=0
!============================= Bottom Hole ==============================
!Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux
MudSystemDotimud=0
do while (MudSystemDotimud < MudSystemDotOp_Mud_Forehead_X%Length())
MudSystemDotimud = MudSystemDotimud + 1
imud=0
do while (imud < MudSystem%Op_Mud_Forehead_X%Length())
imud = imud + 1
if (MudSystemDotimud> 1) then
MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud-1)
Op_Mud_Backhead_section%Array(MudSystemDotimud)= Op_Mud_Forehead_section%Array(MudSystemDotimud-1)
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
MudSystemDotDirectionCoef= (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud)))
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
MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud))* &
MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
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 ( MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
Op_Mud_Forehead_section%Array(MudSystemDotimud)= Op_Mud_Backhead_section%Array(MudSystemDotimud)
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud))
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.48 is for gal to ft^3
else
MudSystemDotisection= Op_Mud_Backhead_section%Array(MudSystemDotimud)+1
MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
if( MudSystemDotimud==1) MudSystemDotKickDeltaVinAnnulus= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud) ! Kick enters Annulus space
MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)
Op_Mud_Forehead_section%Array(MudSystemDotimud)= F_BottomHoleIntervalCounts
if (MudSystem%isection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
if( imud==1) MudSystem%KickDeltaVinAnnulus= MudSystem%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_BottomHoleIntervalCounts)
MudSystem%Op_Mud_Forehead_section%Array(imud)= F_BottomHoleIntervalCounts
if (MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveOpMudArrays(MudSystemDotimud)
if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveOpMudArrays(imud)
endif
exit
endif
MudSystemDotxx= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
Op_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_OpSection(MudSystemDotisection)- MudSystemDotXstart_OpSection(MudSystemDotisection)))+ MudSystemDotXstart_OpSection(MudSystemDotisection)
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
MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection+ 1
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

@@ -321,13 +321,13 @@ MudSystemDotimud=0
endif
if (MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)== MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)) then
MudSystemDottotalLength = MudSystemDotOp_MudDischarged_Volume%Length()
do while(MudSystemDotimud < MudSystemDottotalLength)
if (MudSystem%Op_Mud_Forehead_X%Array(imud)== MudSystem%Xend_OpSection(F_BottomHoleIntervalCounts)) then
MudSystem%totalLength = MudSystem%Op_MudDischarged_Volume%Length()
do while(imud < MudSystem%totalLength)
!imud = imud + 1
call RemoveOpMudArrays(MudSystemDottotalLength)
MudSystemDottotalLength = MudSystemDottotalLength - 1
call RemoveOpMudArrays(MudSystem%totalLength)
MudSystem%totalLength = MudSystem%totalLength - 1

enddo
@@ -352,81 +352,81 @@ MudSystemDotimud=0
! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2)
!========================Bottom Hole END=================
if (MudSystemDotiLoc == 1) then
MudSystemDotMudSection= F_StringIntervalCounts+1
MudSystemDotBackheadX= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)
elseif (MudSystemDotiLoc == 2) then
MudSystemDotMudSection= MudSystemDotKick_Forehead_section
MudSystemDotBackheadX= MudSystemDotKick_Forehead_X
if (MudSystem%iLoc == 1) then
MudSystem%MudSection= F_StringIntervalCounts+1
MudSystem%BackheadX= MudSystem%Xstart_PipeSection(F_StringIntervalCounts+1)
elseif (MudSystem%iLoc == 2) then
MudSystem%MudSection= MudSystem%Kick_Forehead_section
MudSystem%BackheadX= MudSystem%Kick_Forehead_X
endif
!========================ANNULUS ENTRANCE====================
!write(*,*) 'iloc=====' , iLoc
if ((ABS(AnnulusSuctionDensity_Old - St_Density%Last()) >= MudSystemDotDensityMixTol) .OR. (MudSystemDotDeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(MudSystemDotiLoc)-St_Density%Last())>=MudSystemDotDensityMixTol .and. MudSystemDotAnnulusFlowRate/=0.0d0) ) then ! new mud is pumped
call Ann_Density%AddTo (MudSystemDotiLoc,St_Density%Last())
call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,0.0d0)
call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0)
call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0)
call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0)
call Ann_CuttingMud%AddTo (MudSystemDotiLoc,0)
if ((ABS(MudSystem%AnnulusSuctionDensity_Old - MudSystem%St_Density%Last()) >= MudSystem%DensityMixTol) .OR. (MudSystem%DeltaVolumeOp == 0.0 .and. ABS(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%St_Density%Last())>=MudSystem%DensityMixTol .and. MudSystem%AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped
call MudSystem%Ann_Density%AddTo (MudSystem%iLoc,MudSystem%St_Density%Last())
call MudSystem%Ann_MudDischarged_Volume%AddTo (MudSystem%iLoc,0.0d0)
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)
AnnulusSuctionDensity_Old= St_Density%Last()
MudSystem%AnnulusSuctionDensity_Old= MudSystem%St_Density%Last()
MudSystemDotMudIsChanged= .true.
MudSystem%MudIsChanged= .true.
endif

MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+ ((MudSystemDotAnnulusFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)= MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%iLoc)+ ((MudSystem%AnnulusFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal)
!========================Tripping In====================
!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
if (MudSystemDotDeltaVolumeOp > 0.0 .and. MudSystemDotMudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen)
if (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen)
!write(*,*) 'Tripping In'
NewDensity= (St_Density%Last()*((MudSystemDotAnnulusFlowRate/60.)*DeltaT_Mudline)+MudSystemDotOp_Density%Last()*MudSystemDotDeltaVolumeOp)/(((MudSystemDotAnnulusFlowRate/60.0d0)*DeltaT_Mudline)+MudSystemDotDeltaVolumeOp)
MudSystemDotNewVolume= ((MudSystemDotAnnulusFlowRate/60.)*DeltaT_Mudline)+MudSystemDotDeltaVolumeOp
MudSystem%NewDensity= (MudSystem%St_Density%Last()*((MudSystem%AnnulusFlowRate/60.)*MudSystem%DeltaT_Mudline)+MudSystem%Op_Density%Last()*MudSystem%DeltaVolumeOp)/(((MudSystem%AnnulusFlowRate/60.0d0)*MudSystem%DeltaT_Mudline)+MudSystem%DeltaVolumeOp)
MudSystem%NewVolume= ((MudSystem%AnnulusFlowRate/60.)*MudSystem%DeltaT_Mudline)+MudSystem%DeltaVolumeOp
!write(*,*) 'Ann_MudDischarged_Volume%Array(1)=', Ann_MudDischarged_Volume%Array(1), 'NewVolume=', NewVolume
if (abs(Ann_Density%Array(MudSystemDotiLoc)-NewDensity)< MudSystemDotDensityMixTol) then ! 1-Pockets are Merged - (ROP is 0)
Ann_Density%Array(MudSystemDotiLoc)= (Ann_Density%Array(MudSystemDotiLoc)*MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+NewDensity*MudSystemDotNewVolume)/(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotNewVolume)
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)+MudSystemDotDeltaVolumeOp
Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0)
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0)
if (abs(MudSystem%Ann_Density%Array(MudSystem%iLoc)-MudSystem%NewDensity)< MudSystem%DensityMixTol) then ! 1-Pockets are Merged - (ROP is 0)
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%DeltaVolumeOp
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
call Ann_Density%AddTo (MudSystemDotiLoc,NewDensity)
call MudSystemDotAnn_MudDischarged_Volume%AddTo (MudSystemDotiLoc,MudSystemDotNewVolume)
call Ann_Mud_Forehead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
call Ann_Mud_Forehead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
call Ann_Mud_Backhead_X%AddTo (MudSystemDotiLoc,MudSystemDotBackheadX)
call Ann_Mud_Backhead_section%AddTo (MudSystemDotiLoc,MudSystemDotMudSection)
call Ann_RemainedVolume_in_LastSection%AddTo (MudSystemDotiLoc,0.0d0)
call Ann_EmptyVolume_inBackheadLocation%AddTo (MudSystemDotiLoc,0.0d0)
call Ann_MudOrKick%AddTo (MudSystemDotiLoc,0)
call Ann_CuttingMud%AddTo (MudSystemDotiLoc,0)
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)
endif
elseif (MudSystemDotDeltaVolumeOp > 0.0 .and. MudSystemDotMudIsChanged== .true. .and. Rate_of_Penetration==0.) then
Ann_Density%Array(MudSystemDotiLoc)= NewDensity
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotiLoc)= MudSystemDotNewVolume
Ann_Mud_Forehead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
Ann_Mud_Forehead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
Ann_Mud_Backhead_X%Array(MudSystemDotiLoc)= MudSystemDotBackheadX
Ann_Mud_Backhead_section%Array(MudSystemDotiLoc)= MudSystemDotMudSection
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotiLoc)= (0.0d0)
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotiLoc)= (0.0d0)
elseif (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .true. .and. Rate_of_Penetration==0.) then
MudSystem%Ann_Density%Array(MudSystem%iLoc)= MudSystem%NewDensity
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)
endif

@@ -435,27 +435,27 @@ MudSystemDotimud=0
!======================== ANNULUS ====================
MudSystemDotMudIsChanged= .false.
MudSystem%MudIsChanged= .false.
MudSystemDotimud= 0
imud= 0

do while (MudSystemDotimud < Ann_Mud_Forehead_X%Length())
MudSystemDotimud = MudSystemDotimud + 1
do while (imud < MudSystem%Ann_Mud_Forehead_X%Length())
imud = imud + 1
if (MudSystemDotimud> 1) then
Ann_Mud_Backhead_X%Array(MudSystemDotimud)= Ann_Mud_Forehead_X%Array(MudSystemDotimud-1)
Ann_Mud_Backhead_section%Array(MudSystemDotimud)= Ann_Mud_Forehead_section%Array(MudSystemDotimud-1)
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
! <<< Fracture Shoe Lost
IF ( MudSystemDotShoeLost .and. MudSystemDotLostInTripOutIsDone== .false. .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(MudSystemDotimud) .and. Shoe%ShoeDepth >= Ann_Mud_Forehead_X%Array(MudSystemDotimud) ) then
IF ( MudSystem%ShoeLost .and. MudSystem%LostInTripOutIsDone== .false. .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)
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)-((MudSystemDotQlost/60.0d0)*DeltaT_Mudline) !(gal)
if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) < 0.0) then
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(MudSystemDotimud)
MudSystemDotimud= MudSystemDotimud-1
call RemoveAnnulusMudArrays(imud)
imud= imud-1
cycle
endif
ENDIF
@@ -468,48 +468,48 @@ MudSystemDotimud= 0
MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud)))
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
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_PipeSection(Ann_Mud_Backhead_section%Array(MudSystemDotimud))- Ann_Mud_Backhead_X%Array(MudSystemDotimud))* &
MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
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 ( MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) <= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
Ann_Mud_Forehead_section%Array(MudSystemDotimud)= Ann_Mud_Backhead_section%Array(MudSystemDotimud)
Ann_Mud_Forehead_X%Array(MudSystemDotimud)= Ann_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Ann_Mud_Backhead_section%Array(MudSystemDotimud))
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
MudSystemDotisection= Ann_Mud_Backhead_section%Array(MudSystemDotimud)+1
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection > MudSystemDotNoPipeSections) then ! last pipe section(well exit)
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
Ann_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections)
Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotNoPipeSections
if (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 (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveAnnulusMudArrays(MudSystemDotimud)
if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveAnnulusMudArrays(imud)
endif
exit
endif
MudSystemDotxx= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
Ann_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
Ann_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_PipeSection(MudSystemDotisection)- MudSystemDotXstart_PipeSection(MudSystemDotisection)))+ MudSystemDotXstart_PipeSection(MudSystemDotisection)
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
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection+ 1
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

@@ -521,8 +521,8 @@ MudSystemDotimud= 0
!========================ANNULUS END=================
!if ( WellisNOTFull == .false. ) then
! write(*,*) 'AnnulusFlowRate==' , AnnulusFlowRate
! call Set_FlowRate(real(100.*min(AnnulusFlowRate,PedalMeter)/(PedalMeter/10.), 8))
! write(*,*) 'MudSystem%AnnulusFlowRate==' , MudSystem%AnnulusFlowRate
! call Set_FlowRate(real(100.*min(MudSystem%AnnulusFlowRate,PedalMeter)/(PedalMeter/10.), 8))
!
!
!endif


+ 164
- 164
Equipments/MudSystem/Utube2_and_Trip_In.f90 Ver ficheiro

@@ -16,22 +16,22 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect
!===========================================================WELL============================================================
!===========================================================WELL============================================================
MudSystemDotUtubeMode2Activated= .true.
MudSystem%UtubeMode2Activated= .true.
write(*,*) 'QUtubeOutput=' , QUtubeOutput
!QUTubeInput=5000.
MudSystemDotStringFlowRate= QUtubeOutput ! (gpm)
MudSystemDotAnnulusFlowRate= QUtubeOutput
MudSystemDotStringFlowRateFinal= MudSystemDotStringFlowRate
MudSystemDotAnnulusFlowRateFinal= MudSystemDotAnnulusFlowRate
MudSystem%StringFlowRate= QUtubeOutput ! (gpm)
MudSystem%AnnulusFlowRate= QUtubeOutput
MudSystem%StringFlowRateFinal= MudSystem%StringFlowRate
MudSystem%AnnulusFlowRateFinal= MudSystem%AnnulusFlowRate
!===========================================
if (MudSystemDotFirstSetUtube2==0) then
if (MudSystem%FirstSetUtube2==0) then
! call St_MudDischarged_Volume%AddToFirst (REAL(sum(F_Interval(1:F_StringIntervalCounts)%Volume))) !startup initial
! call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1))
! call St_Mud_Backhead_section%AddToFirst (1)
! call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts))
! call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts)
! call St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
! call MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg)
! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0)
! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0)
!
@@ -46,10 +46,10 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect
!Hz_Density%Array(:)= 0.0
!Hz_MudOrKick%Array(:)= 104
MudSystemDotHz_Density_Utube= 0.0
MudSystemDotHz_MudOrKick_Utube= 104
MudSystem%Hz_Density_Utube= 0.0
MudSystem%Hz_MudOrKick_Utube= 104
MudSystemDotFirstSetUtube2= 1
MudSystem%FirstSetUtube2= 1
endif

@@ -79,7 +79,7 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect
!commented

! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((StringFlowRate/60.)*DeltaT_Mudline) !(gal)
! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((MudSystem%StringFlowRate/60.)*DeltaT_Mudline) !(gal)
!
!imud=0
! do while (imud < Hz_Mud_Forehead_X%Length())
@@ -154,90 +154,90 @@ SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect

!========================ANNULUS ENTRANCE====================
if (ABS(AnnulusSuctionDensity_Old - MudSystemDotHz_Density_Utube) >= MudSystemDotDensityMixTol ) then ! new mud is pumped
call Ann_Density%Add (MudSystemDotHz_Density_Utube)
call MudSystemDotAnn_MudDischarged_Volume%Add (0.0d0)
call Ann_Mud_Forehead_X%Add (MudSystemDotXend_PipeSection(MudSystemDotNoPipeSections))
call Ann_Mud_Forehead_section%Add (MudSystemDotNoPipeSections)
call Ann_Mud_Backhead_X%Add (MudSystemDotXstart_PipeSection(MudSystemDotNoPipeSections))
call Ann_Mud_Backhead_section%Add (MudSystemDotNoPipeSections)
call Ann_RemainedVolume_in_LastSection%Add (0.0d0)
call Ann_EmptyVolume_inBackheadLocation%Add (0.0d0)
call Ann_MudOrKick%Add (MudSystemDotHz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104
call Ann_CuttingMud%Add (0)
if (ABS(MudSystem%AnnulusSuctionDensity_Old - MudSystem%Hz_Density_Utube) >= MudSystem%DensityMixTol ) then ! new mud is pumped
call MudSystem%Ann_Density%Add (MudSystem%Hz_Density_Utube)
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 (MudSystem%Hz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104
call MudSystem%Ann_CuttingMud%Add (0)
AnnulusSuctionDensity_Old= MudSystemDotHz_Density_Utube
MudSystem%AnnulusSuctionDensity_Old= MudSystem%Hz_Density_Utube
endif
!========================ANNULUS====================

MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotAnn_MudDischarged_Volume%Length())= MudSystemDotAnn_MudDischarged_Volume%Last()+ ((MudSystemDotAnnulusFlowRate/60.)*DeltaT_Mudline) !(gal)
MudSystem%Ann_MudDischarged_Volume%Array(MudSystem%Ann_MudDischarged_Volume%Length())= MudSystem%Ann_MudDischarged_Volume%Last()+ ((MudSystem%AnnulusFlowRate/60.)*MudSystem%DeltaT_Mudline) !(gal)
MudSystemDotimud= Ann_Mud_Forehead_X%Length() + 1
imud= MudSystem%Ann_Mud_Forehead_X%Length() + 1

do while (MudSystemDotimud > 1)
MudSystemDotimud = MudSystemDotimud - 1
do while (imud > 1)
imud = imud - 1
if (MudSystemDotimud< Ann_Mud_Forehead_X%Length()) then
Ann_Mud_Forehead_X%Array(MudSystemDotimud)= Ann_Mud_Backhead_X%Array(MudSystemDotimud+1)
Ann_Mud_Forehead_section%Array(MudSystemDotimud)= Ann_Mud_Backhead_section%Array(MudSystemDotimud+1)
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 ( MudSystemDotShoeLost .and. MudSystemDotLostInTripOutIsDone== .false. .and. Shoe%ShoeDepth < Ann_Mud_Backhead_X%Array(MudSystemDotimud) .and. Shoe%ShoeDepth >= Ann_Mud_Forehead_X%Array(MudSystemDotimud) ) then
IF ( MudSystem%ShoeLost .and. MudSystem%LostInTripOutIsDone== .false. .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)
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)-((MudSystemDotQlost/60.0d0)*DeltaT_Mudline) !(gal)
if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) < 0.0) then
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(MudSystemDotimud)
MudSystemDotimud= MudSystemDotimud-1
call RemoveAnnulusMudArrays(imud)
imud= imud-1
cycle
endif
ENDIF
! Fracture Shoe Lost >>>
MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud)))
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
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (Ann_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotXstart_PipeSection(Ann_Mud_Forehead_section%Array(MudSystemDotimud)))* &
MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotimud)) !(ft^3)
Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
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 ( MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud) <= Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
Ann_Mud_Backhead_section%Array(MudSystemDotimud)= Ann_Mud_Forehead_section%Array(MudSystemDotimud)
Ann_Mud_Backhead_X%Array(MudSystemDotimud)= Ann_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotDirectionCoef*(MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(Ann_Mud_Forehead_section%Array(MudSystemDotimud))
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
MudSystemDotisection= Ann_Mud_Forehead_section%Array(MudSystemDotimud)-1
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection < F_StringIntervalCounts+1) then ! last pipe section(well exit) F_StringIntervalCounts+1 is the first section in Annulus
MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)- Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
Ann_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotXstart_PipeSection(F_StringIntervalCounts+1)
Ann_Mud_Backhead_section%Array(MudSystemDotimud)= F_StringIntervalCounts+1
if (MudSystem%isection < F_StringIntervalCounts+1) then ! last pipe section(well exit) F_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_StringIntervalCounts+1)
MudSystem%Ann_Mud_Backhead_section%Array(imud)= F_StringIntervalCounts+1
if (MudSystemDotAnn_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveAnnulusMudArrays(MudSystemDotimud)
if (MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveAnnulusMudArrays(imud)
endif
exit
endif
MudSystemDotxx= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
Ann_Mud_Backhead_section%Array(MudSystemDotimud)= MudSystemDotisection
Ann_Mud_Backhead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXstart_PipeSection(MudSystemDotisection)- MudSystemDotXend_PipeSection(MudSystemDotisection)))+ MudSystemDotXend_PipeSection(MudSystemDotisection)
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
Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= Ann_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection- 1
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
@@ -271,60 +271,60 @@ MudSystemDotimud= Ann_Mud_Forehead_X%Length() + 1
!============================= Bottom Hole ==============================
!Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux
MudSystemDotimud=0
do while (MudSystemDotimud < MudSystemDotOp_Mud_Forehead_X%Length())
MudSystemDotimud = MudSystemDotimud + 1
imud=0
do while (imud < MudSystem%Op_Mud_Forehead_X%Length())
imud = imud + 1
if (MudSystemDotimud> 1) then
MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud-1)
Op_Mud_Backhead_section%Array(MudSystemDotimud)= Op_Mud_Forehead_section%Array(MudSystemDotimud-1)
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
MudSystemDotDirectionCoef= (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))-MudSystemDotXstart_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud)))
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
MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotXend_OpSection(Op_Mud_Backhead_section%Array(MudSystemDotimud))- MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud))* &
MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
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 ( MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
Op_Mud_Forehead_section%Array(MudSystemDotimud)= Op_Mud_Backhead_section%Array(MudSystemDotimud)
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotOp_Mud_Backhead_X%Array(MudSystemDotimud)+ MudSystemDotDirectionCoef*(MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_OpSectionFt(Op_Mud_Backhead_section%Array(MudSystemDotimud))
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
MudSystemDotisection= Op_Mud_Backhead_section%Array(MudSystemDotimud)+1
MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
if( MudSystemDotimud==1) MudSystemDotKickDeltaVinAnnulus= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud) ! Kick enters Annulus space
MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)
Op_Mud_Forehead_section%Array(MudSystemDotimud)= F_BottomHoleIntervalCounts
if (MudSystem%isection > F_BottomHoleIntervalCounts) then ! last pipe section(well exit)
if( imud==1) MudSystem%KickDeltaVinAnnulus= MudSystem%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_BottomHoleIntervalCounts)
MudSystem%Op_Mud_Forehead_section%Array(imud)= F_BottomHoleIntervalCounts
if (MudSystemDotOp_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveOpMudArrays(MudSystemDotimud)
if (MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well
call RemoveOpMudArrays(imud)
endif
exit
endif
MudSystemDotxx= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%OpSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
Op_Mud_Forehead_section%Array(MudSystemDotimud)= MudSystemDotisection
MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXend_OpSection(MudSystemDotisection)- MudSystemDotXstart_OpSection(MudSystemDotisection)))+ MudSystemDotXstart_OpSection(MudSystemDotisection)
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
MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotOp_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotOpSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection+ 1
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

@@ -332,13 +332,13 @@ MudSystemDotimud=0
endif
if (MudSystemDotOp_Mud_Forehead_X%Array(MudSystemDotimud)== MudSystemDotXend_OpSection(F_BottomHoleIntervalCounts)) then
MudSystemDottotalLength = MudSystemDotOp_MudDischarged_Volume%Length()
do while(MudSystemDotimud < MudSystemDottotalLength)
if (MudSystem%Op_Mud_Forehead_X%Array(imud)== MudSystem%Xend_OpSection(F_BottomHoleIntervalCounts)) then
MudSystem%totalLength = MudSystem%Op_MudDischarged_Volume%Length()
do while(imud < MudSystem%totalLength)
!imud = imud + 1
call RemoveOpMudArrays(MudSystemDottotalLength)
MudSystemDottotalLength = MudSystemDottotalLength - 1
call RemoveOpMudArrays(MudSystem%totalLength)
MudSystem%totalLength = MudSystem%totalLength - 1

enddo
@@ -375,70 +375,70 @@ MudSystemDotimud=0
!========================STRING ENTRANCE=================
if ((ABS(St_Density%Last() - Ann_Density%First()) >= MudSystemDotDensityMixTol) .OR. (MudSystemDotDeltaVolumeOp == 0.0 .and. St_Density%Last() /= Ann_Density%Array(1) .and. MudSystemDotStringFlowRate/=0.0d0)) then ! new mud is pumped
if ((ABS(MudSystem%St_Density%Last() - MudSystem%Ann_Density%First()) >= MudSystem%DensityMixTol) .OR. (MudSystem%DeltaVolumeOp == 0.0 .and. MudSystem%St_Density%Last() /= MudSystem%Ann_Density%Array(1) .and. MudSystem%StringFlowRate/=0.0d0)) then ! new mud is pumped

!if ((ABS(StringDensity_Old - Ann_Density%First()) >= DensityMixTol) .OR. (DeltaVolumeOp == 0.0 .and. St_Density%Last() /= Ann_Density%Array(1) .and. StringFlowRate/=0.0d0)) then ! new mud is pumped
call St_Density%Add (Ann_Density%First())
call MudSystemDotSt_MudDischarged_Volume%Add (0.0d0)
call MudSystemDotSt_Mud_Forehead_X%Add (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
call St_Mud_Forehead_section%Add (F_StringIntervalCounts)
call MudSystemDotSt_Mud_Backhead_X%Add (MudSystemDotXstart_PipeSection(F_StringIntervalCounts))
call St_Mud_Backhead_section%Add (F_StringIntervalCounts)
call MudSystemDotSt_RemainedVolume_in_LastSection%Add (0.0d0)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Add (0.0d0)
call St_MudOrKick%Add (0)
!if ((ABS(StringDensity_Old - Ann_Density%First()) >= DensityMixTol) .OR. (DeltaVolumeOp == 0.0 .and. MudSystem%St_Density%Last() /= Ann_Density%Array(1) .and. MudSystem%StringFlowRate/=0.0d0)) then ! new mud is pumped
call MudSystem%St_Density%Add (MudSystem%Ann_Density%First())
call MudSystem%St_MudDischarged_Volume%Add (0.0d0)
call MudSystem%St_Mud_Forehead_X%Add (MudSystem%Xend_PipeSection(F_StringIntervalCounts))
call MudSystem%St_Mud_Forehead_section%Add (F_StringIntervalCounts)
call MudSystem%St_Mud_Backhead_X%Add (MudSystem%Xstart_PipeSection(F_StringIntervalCounts))
call MudSystem%St_Mud_Backhead_section%Add (F_StringIntervalCounts)
call MudSystem%St_RemainedVolume_in_LastSection%Add (0.0d0)
call MudSystem%St_EmptyVolume_inBackheadLocation%Add (0.0d0)
call MudSystem%St_MudOrKick%Add (0)
!StringDensity_Old= Ann_Density%First()
MudSystemDotMudIsChanged= .true.
MudSystem%MudIsChanged= .true.
endif

MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotSt_MudDischarged_Volume%Length())= MudSystemDotSt_MudDischarged_Volume%Last()+ ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline) !(gal)
MudSystem%St_MudDischarged_Volume%Array(MudSystem%St_MudDischarged_Volume%Length())= MudSystem%St_MudDischarged_Volume%Last()+ ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline) !(gal)

!========================Tripping In====================
!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp
write(*,*) 'DeltaVolumeOp=' , MudSystemDotDeltaVolumeOp
if (MudSystemDotDeltaVolumeOp > 0.0 .and. MudSystemDotMudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen)
write(*,*) 'DeltaVolumeOp=' , MudSystem%DeltaVolumeOp
if (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen)
!write(*,*) 'Tripping In'
NewDensity= (Ann_Density%First()*((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline)+MudSystemDotOp_Density%Last()*MudSystemDotDeltaVolumeOp)/(((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline)+MudSystemDotDeltaVolumeOp)
MudSystemDotNewVolume= ((MudSystemDotStringFlowRate/60.0d0)*DeltaT_Mudline)+MudSystemDotDeltaVolumeOp
MudSystem%NewDensity= (MudSystem%Ann_Density%First()*((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline)+MudSystem%Op_Density%Last()*MudSystem%DeltaVolumeOp)/(((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline)+MudSystem%DeltaVolumeOp)
MudSystem%NewVolume= ((MudSystem%StringFlowRate/60.0d0)*MudSystem%DeltaT_Mudline)+MudSystem%DeltaVolumeOp

!write(*,*) 'St_MudDischarged_Volume%Last()=', St_MudDischarged_Volume%Last(), 'NewVolume=', NewVolume

if (abs(St_Density%Last()-NewDensity)< MudSystemDotDensityMixTol) then ! .OR. (St_MudDischarged_Volume%Last()< 42.) ) then !+ NewVolume)< 42.) then ! 1-Pockets are Merged
St_Density%Array(St_Density%Length())= (St_Density%Last()*MudSystemDotSt_MudDischarged_Volume%Last()+NewDensity*MudSystemDotNewVolume)/(MudSystemDotSt_MudDischarged_Volume%Last()+MudSystemDotNewVolume)
MudSystemDotSt_MudDischarged_Volume%Array(St_Density%Length())= MudSystemDotSt_MudDischarged_Volume%Last()+MudSystemDotDeltaVolumeOp
MudSystemDotSt_Mud_Forehead_X%Array(St_Density%Length())= (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
St_Mud_Forehead_section%Array(St_Density%Length())= (F_StringIntervalCounts)
MudSystemDotSt_Mud_Backhead_X%Array(St_Density%Length())= (MudSystemDotXstart_PipeSection(F_StringIntervalCounts))
St_Mud_Backhead_section%Array(St_Density%Length())= (F_StringIntervalCounts)
MudSystemDotSt_RemainedVolume_in_LastSection%Array(St_Density%Length())= (0.0d0)
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(St_Density%Length())= (0.0d0)
if (abs(MudSystem%St_Density%Last()-MudSystem%NewDensity)< MudSystem%DensityMixTol) then ! .OR. (St_MudDischarged_Volume%Last()< 42.) ) then !+ NewVolume)< 42.) then ! 1-Pockets are Merged
MudSystem%St_Density%Array(MudSystem%St_Density%Length())= (MudSystem%St_Density%Last()*MudSystem%St_MudDischarged_Volume%Last()+MudSystem%NewDensity*MudSystem%NewVolume)/(MudSystem%St_MudDischarged_Volume%Last()+MudSystem%NewVolume)
MudSystem%St_MudDischarged_Volume%Array(MudSystem%St_Density%Length())= MudSystem%St_MudDischarged_Volume%Last()+MudSystem%DeltaVolumeOp
MudSystem%St_Mud_Forehead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xend_PipeSection(F_StringIntervalCounts))
MudSystem%St_Mud_Forehead_section%Array(MudSystem%St_Density%Length())= (F_StringIntervalCounts)
MudSystem%St_Mud_Backhead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xstart_PipeSection(F_StringIntervalCounts))
MudSystem%St_Mud_Backhead_section%Array(MudSystem%St_Density%Length())= (F_StringIntervalCounts)
MudSystem%St_RemainedVolume_in_LastSection%Array(MudSystem%St_Density%Length())= (0.0d0)
MudSystem%St_EmptyVolume_inBackheadLocation%Array(MudSystem%St_Density%Length())= (0.0d0)
else ! 2-Merging conditions are not meeted, so new pocket
call St_Density%Add (NewDensity)
call MudSystemDotSt_MudDischarged_Volume%Add (MudSystemDotNewVolume)
call MudSystemDotSt_Mud_Forehead_X%Add (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
call St_Mud_Forehead_section%Add (F_StringIntervalCounts)
call MudSystemDotSt_Mud_Backhead_X%Add (MudSystemDotXstart_PipeSection(F_StringIntervalCounts))
call St_Mud_Backhead_section%Add (F_StringIntervalCounts)
call MudSystemDotSt_RemainedVolume_in_LastSection%Add (0.0d0)
call MudSystemDotSt_EmptyVolume_inBackheadLocation%Add (0.0d0)
call St_MudOrKick%Add (0)
call MudSystem%St_Density%Add (MudSystem%NewDensity)
call MudSystem%St_MudDischarged_Volume%Add (MudSystem%NewVolume)
call MudSystem%St_Mud_Forehead_X%Add (MudSystem%Xend_PipeSection(F_StringIntervalCounts))
call MudSystem%St_Mud_Forehead_section%Add (F_StringIntervalCounts)
call MudSystem%St_Mud_Backhead_X%Add (MudSystem%Xstart_PipeSection(F_StringIntervalCounts))
call MudSystem%St_Mud_Backhead_section%Add (F_StringIntervalCounts)
call MudSystem%St_RemainedVolume_in_LastSection%Add (0.0d0)
call MudSystem%St_EmptyVolume_inBackheadLocation%Add (0.0d0)
call MudSystem%St_MudOrKick%Add (0)
endif

elseif (MudSystemDotDeltaVolumeOp > 0.0 .and. MudSystemDotMudIsChanged== .true.) then
St_Density%Array(St_Density%Length())= NewDensity
MudSystemDotSt_MudDischarged_Volume%Array(St_Density%Length())= MudSystemDotNewVolume
MudSystemDotSt_Mud_Forehead_X%Array(St_Density%Length())= (MudSystemDotXend_PipeSection(F_StringIntervalCounts))
St_Mud_Forehead_section%Array(St_Density%Length())= (F_StringIntervalCounts)
MudSystemDotSt_Mud_Backhead_X%Array(St_Density%Length())= (MudSystemDotXstart_PipeSection(F_StringIntervalCounts))
St_Mud_Backhead_section%Array(St_Density%Length())= (F_StringIntervalCounts)
MudSystemDotSt_RemainedVolume_in_LastSection%Array(St_Density%Length())= (0.0d0)
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(St_Density%Length())= (0.0d0)
elseif (MudSystem%DeltaVolumeOp > 0.0 .and. MudSystem%MudIsChanged== .true.) then
MudSystem%St_Density%Array(MudSystem%St_Density%Length())= MudSystem%NewDensity
MudSystem%St_MudDischarged_Volume%Array(MudSystem%St_Density%Length())= MudSystem%NewVolume
MudSystem%St_Mud_Forehead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xend_PipeSection(F_StringIntervalCounts))
MudSystem%St_Mud_Forehead_section%Array(MudSystem%St_Density%Length())= (F_StringIntervalCounts)
MudSystem%St_Mud_Backhead_X%Array(MudSystem%St_Density%Length())= (MudSystem%Xstart_PipeSection(F_StringIntervalCounts))
MudSystem%St_Mud_Backhead_section%Array(MudSystem%St_Density%Length())= (F_StringIntervalCounts)
MudSystem%St_RemainedVolume_in_LastSection%Array(MudSystem%St_Density%Length())= (0.0d0)
MudSystem%St_EmptyVolume_inBackheadLocation%Array(MudSystem%St_Density%Length())= (0.0d0)
endif
@@ -447,60 +447,60 @@ write(*,*) 'DeltaVolumeOp=' , MudSystemDotDeltaVolumeOp
!======================== STRING ====================
MudSystemDotMudIsChanged= .false.
MudSystem%MudIsChanged= .false.
MudSystemDotimud= MudSystemDotSt_Mud_Forehead_X%Length() + 1
imud= MudSystem%St_Mud_Forehead_X%Length() + 1

do while (MudSystemDotimud > 1)
MudSystemDotimud = MudSystemDotimud - 1
do while (imud > 1)
imud = imud - 1
if (MudSystemDotimud< MudSystemDotSt_Mud_Forehead_X%Length()) then
MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud+1)
St_Mud_Forehead_section%Array(MudSystemDotimud)= St_Mud_Backhead_section%Array(MudSystemDotimud+1)
if (imud< MudSystem%St_Mud_Forehead_X%Length()) then
MudSystem%St_Mud_Forehead_X%Array(imud)= MudSystem%St_Mud_Backhead_X%Array(imud+1)
MudSystem%St_Mud_Forehead_section%Array(imud)= MudSystem%St_Mud_Backhead_section%Array(imud+1)
endif
MudSystemDotDirectionCoef= (MudSystemDotXend_PipeSection(St_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Forehead_section%Array(MudSystemDotimud))) &
/ ABS(MudSystemDotXend_PipeSection(St_Mud_Forehead_section%Array(MudSystemDotimud))-MudSystemDotXstart_PipeSection(St_Mud_Forehead_section%Array(MudSystemDotimud)))
MudSystem%DirectionCoef= (MudSystem%Xend_PipeSection(MudSystem%St_Mud_Forehead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Forehead_section%Array(imud))) &
/ ABS(MudSystem%Xend_PipeSection(MudSystem%St_Mud_Forehead_section%Array(imud))-MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Forehead_section%Array(imud)))
! +1 for string , -1 for annulus
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotDirectionCoef* (MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotXstart_PipeSection(St_Mud_Forehead_section%Array(MudSystemDotimud)))* &
MudSystemDotArea_PipeSectionFt(St_Mud_Backhead_section%Array(MudSystemDotimud)) !(ft^3)
MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)* 7.48051948d0 ! ft^3 to gal
MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= MudSystem%DirectionCoef* (MudSystem%St_Mud_Forehead_X%Array(imud)- MudSystem%Xstart_PipeSection(MudSystem%St_Mud_Forehead_section%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 ( MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud) <= MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)) then
St_Mud_Backhead_section%Array(MudSystemDotimud)= St_Mud_Forehead_section%Array(MudSystemDotimud)
MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotSt_Mud_Forehead_X%Array(MudSystemDotimud)- MudSystemDotDirectionCoef*(MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)/7.48051948d0)/MudSystemDotArea_PipeSectionFt(St_Mud_Forehead_section%Array(MudSystemDotimud))
if ( MudSystem%St_MudDischarged_Volume%Array(imud) <= MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then
MudSystem%St_Mud_Backhead_section%Array(imud)= MudSystem%St_Mud_Forehead_section%Array(imud)
MudSystem%St_Mud_Backhead_X%Array(imud)= MudSystem%St_Mud_Forehead_X%Array(imud)- MudSystem%DirectionCoef*(MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/MudSystem%Area_PipeSectionFt(MudSystem%St_Mud_Forehead_section%Array(imud))
! 7.48051948 is for gal to ft^3
else
MudSystemDotisection= St_Mud_Backhead_section%Array(MudSystemDotimud)-1
MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_EmptyVolume_inBackheadLocation%Array(MudSystemDotimud)
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 (MudSystemDotisection < 1) then ! last pipe section(string exit)
MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)= MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)- MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)
MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= MudSystemDotXstart_PipeSection(2)
St_Mud_Backhead_section%Array(MudSystemDotimud)= 2
if (MudSystem%isection < 1) 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_Backhead_X%Array(imud)= MudSystem%Xstart_PipeSection(2)
MudSystem%St_Mud_Backhead_section%Array(imud)= 2
if (MudSystemDotSt_MudDischarged_Volume%Array(MudSystemDotimud)<= 0.0d0) then ! imud is completely exited form the string
call RemoveStringMudArrays(MudSystemDotimud)
if (MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string
call RemoveStringMudArrays(imud)
endif
exit
endif
MudSystemDotxx= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)/ MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection) !(gal)
MudSystem%xx= MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ MudSystem%PipeSection_VolumeCapacity(MudSystem%isection) !(gal)
if (MudSystemDotxx<= 1.0) then
St_Mud_Backhead_section%Array(MudSystemDotimud)= MudSystemDotisection
MudSystemDotSt_Mud_Backhead_X%Array(MudSystemDotimud)= (MudSystemDotxx * (MudSystemDotXstart_PipeSection(MudSystemDotisection)- MudSystemDotXend_PipeSection(MudSystemDotisection)))+ MudSystemDotXend_PipeSection(MudSystemDotisection)
if (MudSystem%xx<= 1.0) then
MudSystem%St_Mud_Backhead_section%Array(imud)= MudSystem%isection
MudSystem%St_Mud_Backhead_X%Array(imud)= (MudSystem%xx * (MudSystem%Xstart_PipeSection(MudSystem%isection)- MudSystem%Xend_PipeSection(MudSystem%isection)))+ MudSystem%Xend_PipeSection(MudSystem%isection)
exit
else
MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)= MudSystemDotSt_RemainedVolume_in_LastSection%Array(MudSystemDotimud)- MudSystemDotPipeSection_VolumeCapacity(MudSystemDotisection)
MudSystemDotisection= MudSystemDotisection- 1
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



+ 1
- 1
Equipments/Pumps/Pumps_Inputs.f90 Ver ficheiro

@@ -2,7 +2,7 @@ subroutine Pumps_Inputs
Use CDrillingConsoleVariables
Use Pumps_VARIABLES
Use MudSystem
use MudSystemModule
IMPLICIT NONE


+ 2
- 2
Equipments/Pumps/Pumps_Outputs.f90 Ver ficheiro

@@ -3,9 +3,9 @@ subroutine Pumps_Outputs
Use CDataDisplayConsoleVariables
Use CSimulationVariables
Use Pumps_VARIABLES
Use MudSystem
use MudSystemModule
Use CDrillWatchVariables
Use CSounds
IMPLICIT NONE


+ 13
- 13
FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 Ver ficheiro

@@ -15,7 +15,7 @@ SUBROUTINE PressureAnnAndOHDistribution
USE CMudPropertiesVariables
USE TD_WellGeometry
USE CReservoirVariables
USE MudSystem
use MudSystemModule
USE CHOKEVARIABLES
USE CChokeManifoldVariables
USE VARIABLES
@@ -42,24 +42,24 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we
j = OpenholeFirstEl - 1
!!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to external sources like pump and tripping
!WRITE (*,*) 'StringFlowRate', StringFlowRate
!WRITE (*,*) 'MudSystem%StringFlowRate', MudSystem%StringFlowRate
FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = (ClingingFactor * FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%Area + FlowEl(StringFirstEl)%Area) * DrillStringSpeed * ConvMintoSec * Convft3toUSgal ! flowrate in annulus due to tripping
FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate + REAL(MudSystemDotMudVolume_InjectedToBH) * ConvMintoSec / dt ! flowrate in annulus due to pump
FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate + REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt ! flowrate in annulus due to pump
!WRITE (*,*) 'Drillstring speed (ft/s)' , FlowEl(j)%FlowRate
!IF (NoWellToChokeEl > 0) THEN ! flowrate in choke line
! FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 : NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%FlowRate = AnnulusFlowRate + (DeltaVolumePipe * ConvMinToSec / dt)
! FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 : NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%FlowRate = MudSystem%AnnulusFlowRate + (DeltaVolumePipe * ConvMinToSec / dt)
!END IF
IF (MudSystemDotShoeFractured) THEN ! reduction of flowrate due to formation fracture and lost circulation
IF (MudSystem%ShoeFractured) THEN ! reduction of flowrate due to formation fracture and lost circulation
!WRITE (*,*) ' SHoe fractured', PressureGauges(5), FlowEl(ShoeFlowElNo)%FlowRate
IF (ShoeFlowElNo > AnnulusLastEl) THEN ! shoe is in openhole
FlowEl(ShoeFlowElNo : NumbEl)%FlowRate = - MudSystemDotQlost
FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate - MudSystemDotQlost
FlowEl(ShoeFlowElNo : NumbEl)%FlowRate = - MudSystem%Qlost
FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate = FlowEl(AnnulusFirstEl : OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost
ELSE ! shoe is in annulus
FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate - MudSystemDotQlost
FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : OpenholeFirstEl - 1)%FlowRate - MudSystem%Qlost
END IF
END IF
@@ -141,14 +141,14 @@ IF (WellHeadOpen .OR. NoGasPocket == 0) THEN !! (mud circulation is normal we

IF (FlowEl(OpenholeFirstEl - 1)%FlowRate < 0.0) THEN
WRITE (*,*) ' Negative choke flowrate'
FlowEl(OpenholeFirstEl - 1)%FlowRate = MAX((REAL(MudSystemDotMudVolume_InjectedToBH) * ConvMintoSec / dt) , 10.0)
FlowEl(OpenholeFirstEl - 1)%FlowRate = MAX((REAL(MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt) , 10.0)
END IF
!Kchoke = ChokeDensity / ((2. * 89158.0) * (0.26 * 0.61 * TotalOpenChokeArea)**2)
deltaPchoke = (Kchoke * FlowEl(OpenholeFirstEl - 1)%FlowRate * ABS(FlowEl(OpenholeFirstEl - 1)%FlowRate)) * 1.d0
MudSystem%deltaPchoke = (Kchoke * FlowEl(OpenholeFirstEl - 1)%FlowRate * ABS(FlowEl(OpenholeFirstEl - 1)%FlowRate)) * 1.d0
!WRITE (*,*) '**deltaPchoke , Kchoke, choke flowrate' , deltaPchoke , Kchoke, FlowEl(i)%FlowRate
!WRITE (*,*) '**TotalOpenChokeArea , Total Open Choke Area Percent' , TotalOpenChokeArea , TotalOpenChokeArea / 4.0 * ChokeAreaFullyOpen
IF (deltaPchoke < 0.d0) deltaPchoke = 0.d0
BackPressure = REAL(deltaPchoke)
IF (MudSystem%deltaPchoke < 0.d0) MudSystem%deltaPchoke = 0.d0
BackPressure = REAL(MudSystem%deltaPchoke)
!WRITE (*,*) ' Choke inlet FlowRate, Density, pressure' , FlowEl(j)%FlowRate, FlowEl(j)%Density, FlowEl(j)%StartPress
!WRITE (*,*) ' Choke outlet Density' , FlowEl(i)%Density
!WRITE (*,*) ' deltaPchoke , choke flowrate' , deltaPchoke , FlowEl(i)%FlowRate
@@ -319,7 +319,7 @@ END IF
!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!IF (ChokeKroneckerDelta == 1) THEN
! WRITE (*,*) ' ChokeLine flowrate' , FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%FlowRate , stringflowrate
! WRITE (*,*) ' ChokeLine flowrate' , FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%FlowRate , MudSystem%StringFlowRate
! !i = NoHorizontalEl + NoStringEl + NoAnnulusEl
! !j = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl
! !WRITE (*,*) ' Well Outlet and Chokeline Outlet Pressure' , FlowEl(i)%EndPress, FlowEl(j)%EndPress


+ 1
- 1
FluidFlow/Fluid_Flow_Solver.f90 Ver ficheiro

@@ -21,7 +21,7 @@ subroutine Fluid_Flow_Solver
!WRITE (*,*) ' fluid flow pointer 2'
MudSystemDotFluidFlowCounter = MudSystemDotFluidFlowCounter + 1
MudSystem%FluidFlowCounter = MudSystem%FluidFlowCounter + 1
call CirculationCodeSelect


+ 44
- 44
FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 Ver ficheiro

@@ -48,14 +48,14 @@ SUBROUTINE PressureHorizAndStringDistribution
BitPressLoss = 0.0
WellHeadWasOpen = WellHeadOpen
WellToChokeManifoldWasOpen = WellToChokeManifoldOpen
WellToChokeManifoldWasOpen = MudSystem%WellToChokeManifoldOpen
KickWasExitingThroughChoke = .FALSE.
IF (MudSystemDotUtubeMode1Activated .OR. FloatValveWasOpen == .FALSE.) THEN ! Horizontal line flow rate
IF (MudSystem%UtubeMode1Activated .OR. FloatValveWasOpen == .FALSE.) THEN ! Horizontal line flow rate
FlowEl(1 : NoHorizontalEl)%FlowRate = 0.0
ELSE ! connection and line is open
FlowEl(1 : NoHorizontalEl)%FlowRate = MudSystemDotStringFlowRate ! pump flow rate [gpm]
FlowEl(1 : NoHorizontalEl)%FlowRate = MudSystem%StringFlowRate ! pump flow rate [gpm]
END IF
!WRITE (*,*) 'a)A/B P Bit', StaticHeadOnBit , FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff)
@@ -87,15 +87,15 @@ SUBROUTINE PressureHorizAndStringDistribution
ELSE ! No gas pocket, wellhead is closed and mud is compressed based on volume pumped into annulus
AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * AnnMudVol)
AnnCompressedMudVol = AnnCompressedMudVol + REAL(MudSystemDotAnn_Saved_MudDischarged_Volume_Final) !!!!!!!!!
AnnCompressedMudVol = MAX((AnnCompressedMudVol - REAL(MudSystemDotQlost / ConvMinToSec / dt)) , 0.0)
AnnCompressedMudVol = AnnCompressedMudVol + REAL(MudSystem%Ann_Saved_MudDischarged_Volume_Final) !!!!!!!!!
AnnCompressedMudVol = MAX((AnnCompressedMudVol - REAL(MudSystem%Qlost / ConvMinToSec / dt)) , 0.0)
AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol)
END IF
IF (FloatValveIn == .FALSE. .OR. NoGasPocket == 0 .OR. (FloatValveWasOpen .AND. REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open
IF (FloatValveIn == .FALSE. .OR. NoGasPocket == 0 .OR. (FloatValveWasOpen .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open
FloatValveOpen = .TRUE.
FlowEl(StringFirstEl : StringLastEl)%FlowRate = REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final) / dt * ConvMinToSec !StringFlowRate ! String flow rate pump flow rate [gpm]
FlowEl(StringFirstEl : StringLastEl)%FlowRate = REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) / dt * ConvMinToSec !MudSystem%StringFlowRate ! String flow rate pump flow rate [gpm]
!!!!!!!!!!!!!!! Calculating frictional pressure loss
IF (WellHeadOpen) THEN
@@ -114,41 +114,41 @@ SUBROUTINE PressureHorizAndStringDistribution
!IF (ABS(MudVolume_InjectedToBH - St_Saved_MudDischarged_Volume_Final)> PumpMinDischargedVol) WRITE (*,*) 'Injected to BH & St Saved Mud', MudVolume_InjectedToBH , St_Saved_MudDischarged_Volume_Final
IF (BitTotallyPluged) THEN
MudSystemDotMudVolume_InjectedToBH = 0.d0
StCompressedMudVol = StCompressedMudVol + REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final)
MudSystem%MudVolume_InjectedToBH = 0.d0
StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final)
StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility
ELSE IF (WellHeadOpen .OR. NoGasPocket > 0) THEN
IF (REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN
IF (REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN
MudSystemDotMudVolume_InjectedToBH = MudSystemDotSt_Saved_MudDischarged_Volume_Final
MudSystem%MudVolume_InjectedToBH = MudSystem%St_Saved_MudDischarged_Volume_Final
!WRITE (*,*) 'MudVolume_InjectedToBH,BitTrue', MudVolume_InjectedToBH
!IF (BitTrue .AND. UtubeMode1Activated == .FALSE.) THEN
IF (BitTrue) THEN
BitPressLoss = KBit * (MudSystemDotMudVolume_InjectedToBH * ConvMinToSec / dt)**2
BitPressLoss = KBit * (MudSystem%MudVolume_InjectedToBH * ConvMinToSec / dt)**2
!WRITE (*,*) 'BitPressLoss', BitPressLoss
END IF
StCompressedMudVol = BitPressLoss / StDeltaPtoDeltaVCompressibility
ELSE
MudSystemDotMudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility + SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
/ StDeltaPtoDeltaVCompressibility ) * 1.d0))
MudSystemDotMudVolume_InjectedToBH = MIN(MudSystemDotMudVolume_InjectedToBH , StCompressedMudVol)
StCompressedMudVol = StCompressedMudVol - MudSystemDotMudVolume_InjectedToBH
MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol)
StCompressedMudVol = StCompressedMudVol - MudSystem%MudVolume_InjectedToBH
END IF
StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol)
ELSE ! IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN
StCompressedMudVol = StCompressedMudVol + REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final)
StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final)
StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility
MudSystemDotMudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
/ (StDeltaPtoDeltaVCompressibility + AnnDeltaPtoDeltaVCompressibility)) * 1.d0)
MudSystemDotMudVolume_InjectedToBH = MIN(MudSystemDotMudVolume_InjectedToBH , StCompressedMudVol)
StCompressedMudVol = StCompressedMudVol - REAL(MudSystemDotMudVolume_InjectedToBH)
MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol)
StCompressedMudVol = StCompressedMudVol - REAL(MudSystem%MudVolume_InjectedToBH)
StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol)
FlowEl(AnnulusFirstEl : NumbEl)%StartPress = FlowEl(AnnulusFirstEl : NumbEl)%StartPress + StDeltaPDueToCompressibility
FlowEl(AnnulusFirstEl : NumbEl)%EndPress = FlowEl(AnnulusFirstEl : NumbEl)%EndPress + StDeltaPDueToCompressibility
@@ -182,14 +182,14 @@ SUBROUTINE PressureHorizAndStringDistribution
!!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open and remains open
ELSE IF (REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final) < PumpMinDischargedVol) THEN ! NoGasPocket > 0
ELSE IF (REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) < PumpMinDischargedVol) THEN ! NoGasPocket > 0
FloatValveOpen = FloatValveWasOpen ! remains in its former status
IF (FloatValveOpen) THEN
PressAboveFloatValve = MAX(FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(StringFirstEl)%Density * FlowEl(StringFirstEl)%StartTVD)
ELSE
PressAboveFloatValve = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + StDeltaPDueToCompressibility
MudSystemDotMudVolume_InjectedToBH = 0.d0
MudSystem%MudVolume_InjectedToBH = 0.d0
END IF
@@ -204,12 +204,12 @@ SUBROUTINE PressureHorizAndStringDistribution
END IF
IF (FloatValveOpen) THEN
MudSystemDotMudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) &
/ StDeltaPtoDeltaVCompressibility ) * 1.d0)
MudSystemDotMudVolume_InjectedToBH = MIN(MudSystemDotMudVolume_InjectedToBH , StCompressedMudVol)
MudSystem%MudVolume_InjectedToBH = MIN(MudSystem%MudVolume_InjectedToBH , StCompressedMudVol)
!WRITE (*,*) 'MudVolume_InjectedToBH (No Pump)', MudVolume_InjectedToBH
StCompressedMudVol = StCompressedMudVol - MudSystemDotMudVolume_InjectedToBH
StCompressedMudVol = StCompressedMudVol - MudSystem%MudVolume_InjectedToBH
StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol)
!WRITE (*,*) 'StDeltaPDueToCompressibility(No Pump)', StDeltaPDueToCompressibility
@@ -251,11 +251,11 @@ SUBROUTINE PressureHorizAndStringDistribution
!WRITE (*,*) ' AnnCompressedMudVol, AnnDeltaPDueToCompressibility',AnnCompressedMudVol, AnnDeltaPDueToCompressibility
!!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open (close) and maybe remains open (close) or maybe closed
ELSE IF(FloatValveWasOpen == .FALSE. .AND. REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN
ELSE IF(FloatValveWasOpen == .FALSE. .AND. REAL(MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN
FloatValveOpen = .FALSE.
MudSystemDotMudVolume_InjectedToBH = 0.d0
MudSystem%MudVolume_InjectedToBH = 0.d0
StCompressedMudVol = StCompressedMudVol + REAL(MudSystemDotSt_Saved_MudDischarged_Volume_Final)
StCompressedMudVol = StCompressedMudVol + REAL(MudSystem%St_Saved_MudDischarged_Volume_Final)
StDeltaPDueToCompressibility = StCompressedMudVol * StDeltaPtoDeltaVCompressibility
PressAboveFloatValve = SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) + StDeltaPDueToCompressibility

@@ -284,7 +284,7 @@ SUBROUTINE PressureHorizAndStringDistribution
END IF
IF ((MudSystemDotUtubePossibility == .TRUE. .AND. Get_KellyConnection() /= KELLY_CONNECTION_STRING) .OR. MudSystemDotNewPipeFilling == 0) THEN
IF ((MudSystem%UtubePossibility == .TRUE. .AND. Get_KellyConnection() /= KELLY_CONNECTION_STRING) .OR. MudSystem%NewPipeFilling == 0) THEN
FlowEl(NoHorizontalEl)%EndPress = 0.0
ELSE IF (WellHeadOpen == .FALSE.) THEN
FlowEl(NoHorizontalEl)%EndPress = FlowEl(StringFirstEl)%StartPress - 0.052 * FlowEl(NoHorizontalEl)%Density * FlowEl(StringFirstEl)%StartTVD
@@ -335,32 +335,32 @@ SUBROUTINE PressureHorizAndStringDistribution
!END IF

IF (MudSystemDotUtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadOpen) THEN
MudSystemDotMudVolume_InjectedToBH = 0.d0
MudVolume_InjectedFromAnn = 0.d0
IF (MudSystem%UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadOpen) THEN
MudSystem%MudVolume_InjectedToBH = 0.d0
MudSystem%MudVolume_InjectedFromAnn = 0.d0
!ELSE
!
! IF (FloatValveOpen .AND. WellHeadOpen .AND. NoGasPocket == 0) THEN
! MudVolume_InjectedToBH = MAX( 0.d0 , REAL((StDeltaPDueToCompressibility - FloatValveMinOpenPressure) / StDeltaPtoDeltaVCompressibility) * 1.d0)
! !MudVolume_InjectedFromAnn = Ann_Saved_MudDischarged_Volume_Final !REAL((AnnDeltaPDueToCompressibility - BackPressure) / AnnDeltaPtoDeltaVCompressibility) * 1.d0
! !MudSystem%MudVolume_InjectedFromAnn = Ann_Saved_MudDischarged_Volume_Final !REAL((AnnDeltaPDueToCompressibility - BackPressure) / AnnDeltaPtoDeltaVCompressibility) * 1.d0
! !WRITE (*,*) 'Pressure above/under bit', FlowEl(NoHorizontalEl + NoStringEl)%EndPress, FlowEl(1 + NoHorizontalEl + NoStringEl)%StartPress
! IF (MudVolume_InjectedToBH <= 0) MudVolume_InjectedToBH = 0.d0
! !IF (MudVolume_InjectedFromAnn <= 0) MudVolume_InjectedFromAnn = 0.d0
! !IF (MudSystem%MudVolume_InjectedFromAnn <= 0) MudSystem%MudVolume_InjectedFromAnn = 0.d0
! ELSE IF (FloatValveOpen .AND. WellHeadOpen == .FALSE. .AND. NoGasPocket == 0) THEN
! MudVolume_InjectedToBH = MAX( 0.d0 , REAL((PressAboveFloatValve + StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - PressBelowFloatValve - FloatValveMinOpenPressure) &
! / (StDeltaPtoDeltaVCompressibility - AnnDeltaPtoDeltaVCompressibility)) * 1.d0)
! MudVolume_InjectedFromAnn = 0.d0
! MudSystem%MudVolume_InjectedFromAnn = 0.d0
! ELSE IF (FloatValveOpen .AND. WellHeadOpen .AND. NoGasPocket > 0) THEN
! MudVolume_InjectedToBH = MAX( 0.d0 , REAL((PressAboveFloatValve + StDeltaPDueToCompressibility - PressBelowFloatValve - FloatValveMinOpenPressure) / StDeltaPtoDeltaVCompressibility) * 1.d0)
! ! MudVolume_InjectedFromAnn = REAL(Ann_Saved_MudDischarged_Volume_Final) * 1.d0
! ! MudSystem%MudVolume_InjectedFromAnn = REAL(Ann_Saved_MudDischarged_Volume_Final) * 1.d0
! ELSE IF (FloatValveOpen .AND. WellHeadOpen == .FALSE. .AND. NoGasPocket > 0) THEN
! MudVolume_InjectedToBH = MAX( 0.d0 , REAL((PressAboveFloatValve + StDeltaPDueToCompressibility - AnnDeltaPDueToCompressibility - PressBelowFloatValve - FloatValveMinOpenPressure) &
! / (StDeltaPtoDeltaVCompressibility - AnnDeltaPtoDeltaVCompressibility)) * 1.d0)
! MudVolume_InjectedFromAnn = 0.d0
! MudSystem%MudVolume_InjectedFromAnn = 0.d0
! END IF
!StCompressedMudVol = MAX(StCompressedMudVol - REAL(MudVolume_InjectedToBH) , 0.0)
!AnnCompressedMudVol = MAX(AnnCompressedMudVol - REAL(MudVolume_InjectedFromAnn) , 0.0)
!AnnCompressedMudVol = MAX(AnnCompressedMudVol - REAL(MudSystem%MudVolume_InjectedFromAnn) , 0.0)
!StDeltaPDueToCompressibility = StCompressedMudVol / (MudCompressibility * StMudVol)
!AnnDeltaPDueToCompressibility = AnnCompressedMudVol / (MudCompressibility * AnnMudVol)
END IF
@@ -370,9 +370,9 @@ SUBROUTINE PressureHorizAndStringDistribution
!MudVolume_InjectedToBH = St_Saved_MudDischarged_Volume_Final
!WRITE (*,*) 'CompMudVol, DeltaP, MudVolumeInjected'
!WRITE (*,*) StCompressedMudVol, StDeltaPDueToCompressibility, REAL(MudVolume_InjectedToBH)
!WRITE (*,*) AnnCompressedMudVol, AnnDeltaPDueToCompressibility, REAL(MudVolume_InjectedFromAnn)
!WRITE (*,*) AnnCompressedMudVol, AnnDeltaPDueToCompressibility, REAL(MudSystem%MudVolume_InjectedFromAnn)
!WRITE (*,*) 'Press above/Below Float valve ', FlowEl(NoHorizontalEl + NoStringEl)%EndPress , FlowEl(NoHorizontalEl + NoStringEl + 1)%StartPress
!write(*,*) 'MudVolume_InjectedFromAnn***=' , MudVolume_InjectedFromAnn, Ann_Saved_MudDischarged_Volume_Final
!write(*,*) 'MudSystem%MudVolume_InjectedFromAnn***=' , MudSystem%MudVolume_InjectedFromAnn, Ann_Saved_MudDischarged_Volume_Final
110 FORMAT (I6 , 4X , F6.2 , 7X , F4.2 , 3X , F4.1 , 2X , F4.2)
@@ -394,7 +394,7 @@ SUBROUTINE PressureHorizAndStringDistribution
i = i + 1
IF (i > NoHorizontalEl) EXIT
END DO
CALL PumpPressureDelay%AddToFirst(REAL(FlowEl(i)%StartPress - 0.052 * (STpipeGauge_Height / Convfttom) * FlowEl(i)%Density + (FlowEl(i)%StartX + 170) * FlowEl(i)%dPdLFric))
CALL PumpPressureDelay%AddToFirst(REAL(FlowEl(i)%StartPress - 0.052 * (MudSystem%STpipeGauge_Height / Convfttom) * FlowEl(i)%Density + (FlowEl(i)%StartX + 170) * FlowEl(i)%dPdLFric))
CALL PumpPressureDelay%Remove(PressureTimeStepDelay(1) + 1)
!IF (ANY(PUMP(:)%PowerFailMalf == 1)) PumpPressureDelay%Array(1 : PressureTimeStepDelay(1) / 2) = 0.0 !seyyed goft vaghti pumpfailure mishavad feshar dasti 0 nashavad, be in dalil in khat comment shod.
@@ -426,7 +426,7 @@ SUBROUTINE PressureHorizAndStringDistribution
!!! in normal mode changes in choke position immidiately observes in casing pressure
!! but when pumps off due to failure, casing pressure will drop after a delay time
IF (WellToChokeManifoldOpen .OR. WellToChokeLineGauge) THEN
IF (MudSystem%WellToChokeManifoldOpen .OR. MudSystem%WellToChokeLineGauge) THEN
!WRITE (*,*) 'Here 1'
CALL CasingPressureDelay%AddToFirst(FlowEl(NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl)%EndPress)
CALL CasingPressureDelay%Remove(PressureTimeStepDelay(1) + 1)
@@ -538,8 +538,8 @@ SUBROUTINE PressureHorizAndStringDistribution
!IF (PressureGauges(5) >= FormationLostPressure) WRITE (*,*) 'Near Shoe Flowrate', FlowEl(ShoeFlowElNo)%FlowRate
MudSystemDotShoeMudViscosity = FlowEl(ShoeFlowElNo)%MuEff
MudSystemDotShoeMudDensity = FlowEl(ShoeFlowElNo)%Density
MudSystem%ShoeMudViscosity = FlowEl(ShoeFlowElNo)%MuEff
MudSystem%ShoeMudDensity = FlowEl(ShoeFlowElNo)%Density
!WRITE (*,*) 'Drillstring speed (ft/s)' , DrillStringSpeed
!WRITE (*,*) 'shoe mud speed ', FlowEl(ShoeFlowElNo - 1)%vel
@@ -584,7 +584,7 @@ SUBROUTINE PressureHorizAndStringDistribution
!WRITE (*,*) ' Kick Iteration', KickIteration
!WRITE (*,*) ' Kchoke, Q =', Kchoke, FlowEl(j)%Flowrate !, REAL((DeltaVolumePipe * ConvMinToSec / dt) + StringFlowRate)
!WRITE (*,*) ' Kchoke, Q =', Kchoke, FlowEl(j)%Flowrate !, REAL((DeltaVolumePipe * ConvMinToSec / dt) + MudSystem%StringFlowRate)
!DO l = NoHorizontalEl + NoStringEl + 1 , NumbEl
! WRITE (*,*) 'El No, Fric Press Loss, density , Q', l, FlowEl(l)%FricPressLoss, FlowEl(l)%StaticPressDiff, FlowEl(l)%Density, FlowEl(l)%Flowrate
!END DO


+ 60
- 60
FluidFlow/Well_Pressure_Data_Transfer.f90 Ver ficheiro

@@ -15,7 +15,7 @@ SUBROUTINE WellPressureDataTransfer
!! which causes acceleration or decceleration of flow
USE FricPressDropVars
USE MudSystem
use MudSystemModule
USE MudSystemVARIABLES
USE GeoElements_FluidModule
USE Fluid_Flow_Startup_Vars
@@ -74,7 +74,7 @@ SUBROUTINE WellPressureDataTransfer
ChokeKroneckerDelta = 0

IF (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen == .FALSE.) THEN
IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
WellHeadOpen = .FALSE.
!WRITE (*,*) ' Well Head is closed '
@@ -82,18 +82,18 @@ SUBROUTINE WellPressureDataTransfer
WellHeadOpen = .TRUE.
END IF
IF (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
!WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NoHorizontalEl = MudSystemDotNoHorizontalMudElements
NoStringEl = MudSystemDotNoStringMudElements
NoAnnulusEl = MudSystemDotNoCasingMudElements
NoHorizontalEl = MudSystem%NoHorizontalMudElements
NoStringEl = MudSystem%NoStringMudElements
NoAnnulusEl = MudSystem%NoCasingMudElements
NoWellToChokeEl = 0
IF (ChokeKroneckerDelta == 1) NoWellToChokeEl = MudSystemDotChokeLine_Density%Length()
NoOpenHoleEl = MudSystemDotNoBottomHoleMudElements
IF (ChokeKroneckerDelta == 1) NoWellToChokeEl = MudSystem%ChokeLine_Density%Length()
NoOpenHoleEl = MudSystem%NoBottomHoleMudElements
NumbEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWellToChokeEl + NoOpenHoleEl
!WRITE (*,*) 'H, S, A, Ch, O', NoHorizontalEl , NoStringEl , NoAnnulusEl , NoWellToChokeEl , NoOpenHoleEl
IF(ALLOCATED(FlowEl)) DEALLOCATE(FlowEl)
@@ -103,21 +103,21 @@ SUBROUTINE WellPressureDataTransfer
!!!!!!!!!!!!!!!!!!!!!!! Horizontal line
!WRITE (*,*) 'H', NoHorizontalEl
DO i = 1 , NoHorizontalEl
FlowEl(i)%StartX = Xstart_MudElement%Array(i)
FlowEl(i)%EndX = Xend_MudElement%Array(i)
FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i)
FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i)
FlowEl(i)%StartTVD = 0.d0
FlowEl(i)%EndTVD = 0.d0
FlowEl(i)%Id = 0.0
FlowEl(i)%Od = PipeOD_MudElement%Array(i)
FlowEl(i)%density = Density_MudElement%Array(i)
FlowEl(i)%Od = MudSystem%PipeOD_MudElement%Array(i)
FlowEl(i)%density = MudSystem%Density_MudElement%Array(i)
FlowEl(i)%Dhyd = FlowEl(i)%Od
FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
FlowEl(i)%DepthDiff = 0.d0
FlowEl(i)%Volume = PI / 4.0 * FlowEl(i)%Od**2 * REAL(FlowEl(i)%Length) / Convfttoinch**2
IF (MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
IF (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = 0
ELSE IF (MudType_MudElement%Array(i) == 4) THEN
ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN
FlowEl(i)%MaterialType = 4
ELSE
FlowEl(i)%MaterialType = 1
@@ -139,19 +139,19 @@ SUBROUTINE WellPressureDataTransfer
StringLastEl = NoHorizontalEl + NoStringEl
DO i = NoHorizontalEl + 1 , NoHorizontalEl + NoStringEl
!WRITE (*,*) 'ST , i' , i
FlowEl(i)%StartX = Xstart_MudElement%Array(i)
FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i)
!WRITE (*,*) 'StartX', FlowEl(i)%StartX
FlowEl(i)%EndX = Xend_MudElement%Array(i)
FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i)
!WRITE (*,*) 'EndX', FlowEl(i)%EndX
FlowEl(i)%StartTVD = TVDstart_MudElement%Array(i)
FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i)
!WRITE (*,*) 'StartTVD', FlowEl(i)%StartTVD
FlowEl(i)%EndTVD = TVDend_MudElement%Array(i)
FlowEl(i)%EndTVD = MudSystem%TVDend_MudElement%Array(i)
!WRITE (*,*) 'EndTVD', FlowEl(i)%EndTVD
FlowEl(i)%Id = 0.0
!WRITE (*,*) 'Id', FlowEl(i)%Id
FlowEl(i)%Od = PipeOD_MudElement%Array(i)
FlowEl(i)%Od = MudSystem%PipeOD_MudElement%Array(i)
!WRITE (*,*) 'Od', FlowEl(i)%Od
FlowEl(i)%Density = Density_MudElement%Array(i)
FlowEl(i)%Density = MudSystem%Density_MudElement%Array(i)
!WRITE (*,*) 'Density', FlowEl(i)%Density
@@ -162,9 +162,9 @@ SUBROUTINE WellPressureDataTransfer
!WRITE (*,*) 'DepthDiff', FlowEl(i)%DepthDiff
FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
IF (MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
IF (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = 0
ELSE IF (MudType_MudElement%Array(i) == 4) THEN
ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN
FlowEl(i)%MaterialType = 4
ELSE
FlowEl(i)%MaterialType = 1
@@ -190,22 +190,22 @@ SUBROUTINE WellPressureDataTransfer
AnnulusFirstEl = NoHorizontalEl + NoStringEl + 1
AnnulusLastEl = NoHorizontalEl + NoStringEl + NoAnnulusEl
DO i = NoHorizontalEl + NoStringEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl
FlowEl(i)%StartX = Xstart_MudElement%Array(i)
FlowEl(i)%EndX = Xend_MudElement%Array(i)
FlowEl(i)%StartTVD = TVDstart_MudElement%Array(i)
FlowEl(i)%EndTVD = TVDend_MudElement%Array(i)
FlowEl(i)%Id = PipeID_MudElement%Array(i)
FlowEl(i)%Od = PipeOD_MudElement%Array(i)
FlowEl(i)%Density = Density_MudElement%Array(i)
FlowEl(i)%StartX = MudSystem%Xstart_MudElement%Array(i)
FlowEl(i)%EndX = MudSystem%Xend_MudElement%Array(i)
FlowEl(i)%StartTVD = MudSystem%TVDstart_MudElement%Array(i)
FlowEl(i)%EndTVD = MudSystem%TVDend_MudElement%Array(i)
FlowEl(i)%Id = MudSystem%PipeID_MudElement%Array(i)
FlowEl(i)%Od = MudSystem%PipeOD_MudElement%Array(i)
FlowEl(i)%Density = MudSystem%Density_MudElement%Array(i)
FlowEl(i)%Dhyd = FlowEl(i)%Od - FlowEl(i)%Id
FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
FlowEl(i)%Area = PI / 4.0 * (FlowEl(i)%Od**2 - FlowEl(i)%Id**2) / Convfttoinch**2
FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
IF (MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
IF (MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = 0
ELSE IF (MudType_MudElement%Array(i) == 4) THEN
ELSE IF (MudSystem%MudType_MudElement%Array(i) == 4) THEN
FlowEl(i)%MaterialType = 4
ELSE
FlowEl(i)%MaterialType = 1
@@ -230,21 +230,21 @@ SUBROUTINE WellPressureDataTransfer
!ChokeLastEl = OpenholeFirstEl - 1
j = 1
DO i = NoHorizontalEl + NoStringEl + NoAnnulusEl + 1 , NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl
FlowEl(i)%StartX = MudSystemDotChokeLine_Mud_Backhead_X%Array(j)
FlowEl(i)%EndX = MudSystemDotChokeLine_Mud_Forehead_X%Array(j)
FlowEl(i)%StartX = MudSystem%ChokeLine_Mud_Backhead_X%Array(j)
FlowEl(i)%EndX = MudSystem%ChokeLine_Mud_Forehead_X%Array(j)
FlowEl(i)%StartTVD = 0.d0
FlowEl(i)%EndTVD = 0.d0
FlowEl(i)%Id = 0.0
FlowEl(i)%Od = BopStackSpecification%ChokeLineId
FlowEl(i)%density = MudSystemDotChokeLine_Density%Array(j)
FlowEl(i)%density = MudSystem%ChokeLine_Density%Array(j)
FlowEl(i)%Dhyd = FlowEl(i)%Od
FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
FlowEl(i)%DepthDiff = 0.d0
FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
IF (ChokeLine_MudOrKick%Array(j) == 0 .OR. ChokeLine_MudOrKick%Array(j) == 4) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = ChokeLine_MudOrKick%Array(j)
IF (MudSystem%ChokeLine_MudOrKick%Array(j) == 0 .OR. MudSystem%ChokeLine_MudOrKick%Array(j) == 4) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = MudSystem%ChokeLine_MudOrKick%Array(j)
ELSE
FlowEl(i)%MaterialType = 1
END IF
@@ -266,23 +266,23 @@ SUBROUTINE WellPressureDataTransfer
OpenholeFirstEl = NoHorizontalEl + NoStringEl + NoAnnulusEl + NoWelltoChokeEl + 1
j = 1
DO i = OpenholeFirstEl , NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl
FlowEl(i)%StartX = Xstart_OpMudElement%Array(j)
FlowEl(i)%EndX = Xend_OpMudElement%Array(j)
FlowEl(i)%StartTVD = TVDstart_OpMudElement%Array(j)
FlowEl(i)%EndTVD = TVDend_OpMudElement%Array(j)
FlowEl(i)%StartX = MudSystem%Xstart_OpMudElement%Array(j)
FlowEl(i)%EndX = MudSystem%Xend_OpMudElement%Array(j)
FlowEl(i)%StartTVD = MudSystem%TVDstart_OpMudElement%Array(j)
FlowEl(i)%EndTVD = MudSystem%TVDend_OpMudElement%Array(j)
FlowEl(i)%Id = 0.0
FlowEl(i)%Od = PipeOD_OpMudElement%Array(j)
FlowEl(i)%density = Density_OpMudElement%Array(j)
FlowEl(i)%MaterialType = MudTypeOP_MudElement%Array(j) ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%Od = MudSystem%PipeOD_OpMudElement%Array(j)
FlowEl(i)%density = MudSystem%Density_OpMudElement%Array(j)
FlowEl(i)%MaterialType = MudSystem%MudTypeOp_MudElement%Array(j) ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%Dhyd = FlowEl(i)%Od
FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX)
FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD)
FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2
FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length)
IF (MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
IF (MudSystem%MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air
FlowEl(i)%MaterialType = 0
ELSE IF (MudTypeOp_MudElement%Array(j) == 4) THEN
ELSE IF (MudSystem%MudTypeOp_MudElement%Array(j) == 4) THEN
FlowEl(i)%MaterialType = 4
ELSE
FlowEl(i)%MaterialType = 1
@@ -341,24 +341,24 @@ SUBROUTINE WellPressureDataTransfer
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
OpenArea32 = ((ChokeManifold%LeftManualChoke * (1.0 - ManChoke1Plug * REAL(ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * ManChoke1Washout) * Choke%ChokeAreaFullyOpen
OpenArea33 = CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen
OpenArea34 = CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen
OpenArea35 = ((ChokeManifold%RightManualChoke * (1.0 - ManChoke2Plug * REAL(ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * ManChoke2Washout) * Choke%ChokeAreaFullyOpen
MudSystem%OpenArea32 = ((ChokeManifold%LeftManualChoke * (1.0 - ManChoke1Plug * REAL(ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * ManChoke1Washout) * Choke%ChokeAreaFullyOpen
MudSystem%OpenArea33 = CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen
MudSystem%OpenArea34 = CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen
MudSystem%OpenArea35 = ((ChokeManifold%RightManualChoke * (1.0 - ManChoke2Plug * REAL(ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * ManChoke2Washout) * Choke%ChokeAreaFullyOpen
!write(*,*) 'OpenArea32=' , OpenArea32, active32, ManChoke1Plug, ManualChoke1PluggedPercent, ManChoke1Washout
!write(*,*) 'OpenArea33=' , OpenArea33, active33
!write(*,*) 'OpenArea34=' , OpenArea34, active34, !HydraulicChoke2PluggedPercent
!write(*,*) 'OpenArea35=' , OpenArea35, active35, ManChoke2Plug, ManualChoke2PluggedPercent, ManChoke2Washout
InstantaneousTotalOpenChokeArea = OpenArea32 * active32 + OpenArea33 * active33 + OpenArea34 * active34 + OpenArea35 * active35 + ChokeBypassArea * active29
InstantaneousTotalOpenChokeArea = MudSystem%OpenArea32 * active32 + MudSystem%OpenArea33 * active33 + MudSystem%OpenArea34 * active34 + MudSystem%OpenArea35 * active35 + ChokeBypassArea * active29
OldTotalOpenChokeArea = TotalOpenChokeArea
!WRITE (*,*) 'Instantaneous / Old TotalOpenChokeArea', InstantaneousTotalOpenChokeArea, OldTotalOpenChokeArea
IF (OldTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen
IF (InstantaneousTotalOpenChokeArea <= 0.01 * Choke%ChokeAreaFullyOpen) THEN
WellToChokeManifoldOpen = .FALSE.
MudSystem%WellToChokeManifoldOpen = .FALSE.
OldTotalOpenChokeArea = 0.01 * Choke%ChokeAreaFullyOpen
!WRITE (*,*) ' Choke Controler Here 2'
ELSE IF (InstantaneousTotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen .OR. WelltoPitsOpen) THEN
ELSE IF (InstantaneousTotalOpenChokeArea > 0.5 * Choke%ChokeAreaFullyOpen .OR. MudSystem%WellToPitsOpen) THEN
! mud flows through well to bell nipple, or choke is rather open
TotalOpenChokeArea = InstantaneousTotalOpenChokeArea
!WRITE (*,*) ' Choke Controler Here 1'
@@ -386,7 +386,7 @@ SUBROUTINE WellPressureDataTransfer
ChokeKroneckerDelta = 0
!WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
!WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
IF (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen == .FALSE.) THEN
IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN
!WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen
!WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen
@@ -396,21 +396,21 @@ SUBROUTINE WellPressureDataTransfer
WellHeadOpen = .TRUE.
END IF
IF (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
IF (MudSystem%WellToPitsOpen == .FALSE. .AND. MudSystem%WellToChokeManifoldOpen) ChokeKroneckerDelta = 1
!WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen
!WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, WellToChokeManifoldWasOpen
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

IF (NoGasPocket > 0) THEN
!IF (NoWelltoChokeEl > 0 .AND. (FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .OR. KickWasExitingThroughChoke) .AND. WellHeadOpen) THEN
IF (MudSystemDotChoke_Kick_Saved_Volume_Final > 0.d0) THEN
IF (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0) THEN
!WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', Choke_Kick_Saved_Volume_Final, (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)
ExitMass = REAL(MudSystemDotChoke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(NoGasPocket)
ExitMass = REAL(MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(NoGasPocket)
!IF (NoGasPocket > 1) ExitMass = ExitMass + (SUM(GasPocketDeltaVol%Array(1 : NoGasPocket - 1)) / GasPocketNewVol%Array(NoGasPocket)) * GasPocketWeight%Array(NoGasPocket)
!WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, StringFlowRate * dt / ConvMinToSec
!WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, MudSystem%StringFlowRate * dt / ConvMinToSec
IF (FlowEl(OpenholeFirstEl - 1)%MaterialType /= 1) THEN
CALL RemoveGasPocket(NoGasPocket)
WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', MudSystemDotChoke_Kick_Saved_Volume_Final
WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', MudSystem%Choke_Kick_Saved_Volume_Final
END IF
END IF
@@ -604,9 +604,9 @@ SUBROUTINE GasPocketFlowElementTransformer
i = OpenholeFirstEl - 1
!WRITE (*,*) 'MaterialType, NoWelltoChokeEl', FlowEl(i)%MaterialType , NoWelltoChokeEl
!IF (NoWelltoChokeEl > 0 .AND. FlowEl(OpenholeFirstEl - 1)%MaterialType == 1 .AND. WellHeadOpen) THEN ! kick is last element in choke line and does not exit.
IF (MudSystemDotChoke_Kick_Saved_Volume_Final > 0.d0 .AND. WellHeadOpen) THEN
IF (MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. WellHeadOpen) THEN
WRITE (*,*) 'Kick is exiting through the choke'
!ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + StringFlowRate) / ConvMinToSec * dt
!ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + MudSystem%StringFlowRate) / ConvMinToSec * dt
GasPocketWeight%Array(NoGasPocket) = GasPocketweight%Array(NoGasPocket) - ExitMass
IF (GasPocketWeight%Array(NoGasPocket) > 0.0) THEN
GasPocketOldPress%Array(NoGasPocket) = GasPocketWeight%Array(NoGasPocket) * GasType(KickGasType)%GasConstant * &


+ 1
- 1
FluidFlow/kick/Formation_Information.f90 Ver ficheiro

@@ -76,7 +76,7 @@ SUBROUTINE FormationInformationCalculator
end if
!PermeabilityExposedHeight = KickFormLength * FormationPermeability
DownHole%PermeabilityExposedHeight = MudSystemDotFluidFlowCounter - MudSystemDotMudSys_timeCounter
DownHole%PermeabilityExposedHeight = MudSystem%FluidFlowCounter - MudSystem%MudSys_timeCounter
!====================================================
! Reservoir Data
!====================================================


+ 4
- 4
FluidFlow/kick/Gas_Kick_Calculator.f90 Ver ficheiro

@@ -399,9 +399,9 @@ SUBROUTINE NewGasKick
WRITE (*,*) ' New Influx 1'
NoGasPocket = 1
MudSystemDotNewInfluxNumber = MudSystemDotNewInfluxNumber + 1
MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1
MudSystemDotNewInfluxElementCreated = 0
MudSystem%NewInfluxElementCreated = 0
KickOffBottom = .FALSE.

@@ -477,9 +477,9 @@ SUBROUTINE NewGasKick
NoGasPocket = NoGasPocket + 1
MudSystemDotNewInfluxNumber = MudSystemDotNewInfluxNumber + 1
MudSystem%NewInfluxNumber = MudSystem%NewInfluxNumber + 1
MudSystemDotNewInfluxElementCreated = 0
MudSystem%NewInfluxElementCreated = 0
KickOffBottom = .FALSE.

CALL GasPocketOldPress%AddToFirst((BottomHolePress + StandardPress) * 1.d0)


+ 1
- 1
Rop/JetImpactForce.f90 Ver ficheiro

@@ -15,7 +15,7 @@ subroutine JetImpactForce
Bit_Flowrate = MudSystemDotStringFlowRateFinal ![gpm]
Bit_Flowrate = MudSystem%StringFlowRateFinal ![gpm]
!print*, 'Bit_Flowrate=' , Bit_Flowrate
!check :: Mud_Density [ppg] ??????????


+ 2
- 2
Rop/ROP_MainCalculation.f90 Ver ficheiro

@@ -84,12 +84,12 @@ subroutine ROP_MainCalculation
Critical_Weight_on_Bit = (Formation%Formations(FormationNumber)%ThresholdWeight/5.d0)-(.06d0*(Formation%Formations(FormationNumber)%ThresholdWeight-10.d0)) ! unit : [klb/in] (Typical Range: 0 to 10 ----> 0.6 to 2)
!IF (ALLOCATED(FlowEl)) THEN
! Mud_Viscosity = FlowEl(NoHorizontalEl + NoStringEl)%mueff !13.5 [cP]
Mud_Density = MudSystemDotBitMudDensity ! [ppg]
Mud_Density = MudSystem%BitMudDensity ! [ppg]
!ELSE
Mud_Viscosity = 13.5 ! [cP]
!Mud_Density = 9.2 ! [ppg]
!END IF
Mud_Flowrate = MudSystemDotStringFlowRateFinal ! [gpm]
Mud_Flowrate = MudSystem%StringFlowRateFinal ! [gpm]
Reynolds_Number = Mud_Flowrate*Mud_Density/(Mud_Viscosity*Number_of_Bit_Nozzles*Diameter_of_Bit_Nozzle) ! unit : [dimensionless] (Typical Range: 0.1 to 1000.0)
! $$$$$**$$$$$**$$$$$**$$$$$**$$$$ End of Variable Initialization $$$$$**$$$$$**$$$$$**$$$$$**$$$$$


+ 0
- 1
SimulationCore2.vfproj Ver ficheiro

@@ -230,7 +230,6 @@
<File RelativePath=".\CSharp\Simulation\CSimulationVariables.f90"/>
<File RelativePath=".\CSharp\Simulation\CSounds.f90"/></Filter>
<Filter Name="StudentStation">
<File RelativePath=".\CSharp\StudentStation\CStudentStation.f90"/>
<File RelativePath=".\CSharp\StudentStation\CStudentStationVariables.f90"/></Filter>
<Filter Name="Warnings">
<File RelativePath=".\CSharp\Warnings\CWarnings.f90"/>


Carregando…
Cancelar
Guardar